Skip to content

Commit 3930daf

Browse files
committed
[BoundsSafety][LLDB] Implement instrumentation plugin for -fbounds-safety soft traps
This patch tries to upstream code landed downstream in swiftlang#11835. This patch implements an instrumentation plugin for the `-fbounds-safety` soft trap mode first implemented in swiftlang#11645 (rdar://158088757). That functionality isn't supported in upstream Clang yet, however the instrumented plugin can be compiled without issue so this patch tries to upstream it. The included tests are all disabled when the clang used for testing doesn't support `-fbounds-safety`. This means the tests will be skipped. However, it's fairly easy to point LLDB at a clang that does support `-fbounds-safety. I've done this and confirmed the tests pass. To use a custom clang the following can be done: * For API tests set the `LLDB_TEST_COMPILER` CMake cache variable to point to appropriate compiler. * For shell tests applying a patch like this can be used to set the appropriate compiler: ``` --- a/lldb/test/Shell/helper/toolchain.py +++ b/lldb/test/Shell/helper/toolchain.py @@ -271,6 +271,7 @@ def use_support_substitutions(config): if config.lldb_lit_tools_dir: additional_tool_dirs.append(config.lldb_lit_tools_dir) + config.environment['CLANG'] = '/path/to/clang' llvm_config.use_clang( ``` The current implementation of -fbounds-safety traps works by emitting calls to runtime functions intended to log the occurrence of a soft trap. While the user could just set a breakpoint of these functions the instrumentation plugin sets it automatically and provides several additional features: When debug info is available: * It adjusts the stop reason to be the reason for trapping. This is extracted from the artificial frame in the debug info (similar to -fbounds-safety hard traps). * It adjusts the selected frame to be the frame where the soft trap occurred. When debug info is not available: * For the `call-with-str` soft trap mode the soft trap reason is read from the first argument register. * For the `call-minimal` soft trap mode the stop reason is adjusted to note its a bounds check failure but does not give further information because none is available. * In this situation the selected frame is not adjusted because in this mode the user will be looking at assembly and adjusting the frame makes things confusing. This patch includes shell and api tests. The shell tests seemed like the best way to test behavior when debug info is missing because those tests make it easy to disable building with debug info completely. rdar://163230807
1 parent 6c62b52 commit 3930daf

22 files changed

+1081
-0
lines changed

lldb/include/lldb/lldb-enumerations.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,7 @@ enum InstrumentationRuntimeType {
542542
eInstrumentationRuntimeTypeMainThreadChecker = 0x0003,
543543
eInstrumentationRuntimeTypeSwiftRuntimeReporting = 0x0004,
544544
eInstrumentationRuntimeTypeLibsanitizersAsan = 0x0005,
545+
eInstrumentationRuntimeTypeBoundsSafety = 0x0006,
545546
eNumInstrumentationRuntimeTypes
546547
};
547548

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
add_lldb_library(lldbPluginInstrumentationRuntimeBoundsSafety PLUGIN
2+
InstrumentationRuntimeBoundsSafety.cpp
3+
4+
LINK_LIBS
5+
lldbBreakpoint
6+
lldbCore
7+
lldbSymbol
8+
lldbTarget
9+
lldbPluginInstrumentationRuntimeUtility
10+
11+
CLANG_LIBS
12+
clangCodeGen
13+
)

0 commit comments

Comments
 (0)