-
Notifications
You must be signed in to change notification settings - Fork 353
[BoundsSafety][LLDB] Implement instrumentation plugin for -fbounds-safety soft traps #11835
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BoundsSafety][LLDB] Implement instrumentation plugin for -fbounds-safety soft traps #11835
Conversation
f7206d3 to
a15e413
Compare
|
@swift-ci test |
|
@swift-ci test llvm |
a15e413 to
c8af09b
Compare
|
@swift-ci test |
|
@swift-ci test llvm |
|
Windows failure looks completely unrelated to this PR: likely caused by swiftlang/swift-docc#1331. Looks like swiftlang/swift-docc#1352 is out to revert this change. |
|
@swift-ci please test windows platform |
lldb/source/Plugins/InstrumentationRuntime/BoundsSafety/InstrumentationRuntimeBoundsSafety.cpp
Outdated
Show resolved
Hide resolved
lldb/source/Plugins/InstrumentationRuntime/BoundsSafety/InstrumentationRuntimeBoundsSafety.cpp
Outdated
Show resolved
Hide resolved
lldb/source/Plugins/InstrumentationRuntime/BoundsSafety/InstrumentationRuntimeBoundsSafety.cpp
Outdated
Show resolved
Hide resolved
lldb/source/Plugins/InstrumentationRuntime/BoundsSafety/InstrumentationRuntimeBoundsSafety.cpp
Show resolved
Hide resolved
lldb/source/Plugins/InstrumentationRuntime/BoundsSafety/InstrumentationRuntimeBoundsSafety.cpp
Show resolved
Hide resolved
lldb/source/Plugins/InstrumentationRuntime/BoundsSafety/InstrumentationRuntimeBoundsSafety.h
Show resolved
Hide resolved
lldb/source/Plugins/InstrumentationRuntime/BoundsSafety/InstrumentationRuntimeBoundsSafety.cpp
Outdated
Show resolved
Hide resolved
lldb/source/Plugins/InstrumentationRuntime/BoundsSafety/InstrumentationRuntimeBoundsSafety.cpp
Outdated
Show resolved
Hide resolved
lldb/source/Plugins/InstrumentationRuntime/BoundsSafety/InstrumentationRuntimeBoundsSafety.cpp
Outdated
Show resolved
Hide resolved
lldb/source/Plugins/InstrumentationRuntime/BoundsSafety/InstrumentationRuntimeBoundsSafety.cpp
Show resolved
Hide resolved
lldb/test/API/lang/BoundsSafety/soft_trap/TestBoundsSafetyInstrumentationPlugin.py
Outdated
Show resolved
Hide resolved
lldb/test/API/lang/BoundsSafety/soft_trap/TestBoundsSafetyInstrumentationPlugin.py
Outdated
Show resolved
Hide resolved
lldb/test/API/lang/BoundsSafety/soft_trap/TestBoundsSafetyInstrumentationPlugin.py
Outdated
Show resolved
Hide resolved
This patch adds `LLDBLog::InstrumentationRuntime` as a log channel to provide an appropriate channel for instrumentation runtime plugins as previously one did not exist. A small use of the channel is added to illustrate its use. The logging added is not intended to be comprehensive. This is primarily motivated by an `-fbounds-safety` instrumentation plugin (swiftlang#11835). rdar://164920875
a1e85fe to
795052d
Compare
|
@swift-ci test |
|
I've squash the feedback commits into the relevant commit and I've kicked off PR testing. |
Ok that makes sense. I naively thought we'd be able to share the logic which recognizes the stop reason in the no-debug-info case. But sounds like for
Sounds good to me! |
|
@swift-ci test windows platform |
|
So the windows build is failing because the api tests don't pass there. The assert where the stop reason is checked fails. The stop reason is supposed to be |
…fety soft traps This patch implements an instrumentation plugin for the `-fbounds-safety` soft trap mode first implemented in swiftlang#11645 (rdar://158088757). 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
795052d to
d061ddb
Compare
|
@swift-ci test |
|
@swift-ci please test Windows platform |
|
@charles-zablit has been working on LLDB's Windows support. Mind giving this a try on your Windows machine once you have a free second? |
JDevlieghere
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I discussed this with Dan offline. The plugin can go upstream, only the tests depend on having bounds safety support. You can configure LLDB to use a different compiler than the in-tree one, which provides path to landing this upstream.
I'm approving this so we can merge this PR before the branches lock later today. I spotted some minor issues which we can address when landing this upstream.
…supports -fbounds-safety This patch makes it possible to detect in LLDB shell and API tests if `-fbounds-safety` is supported by the compiler used for testing. The motivation behind this is to allow upstreaming swiftlang#11835 but with the tests disabled in upstream because the full implementation of -fbounds-safety isn't available in Clang yet. For shell tests when -fbounds-safety is available the `clang-bounds-safety` feature is available which means tests can be annotated with `# REQUIRES: clang-bounds-safety`. API tests that need -fbounds-safety support in the compiler can use the new `@skipUnlessBoundsSafety` decorator. rdar://165225507
…fety 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
…supports -fbounds-safety This patch makes it possible to detect in LLDB shell and API tests if `-fbounds-safety` is supported by the compiler used for testing. The motivation behind this is to allow upstreaming swiftlang#11835 but with the tests disabled in upstream because the full implementation of -fbounds-safety isn't available in Clang yet. For shell tests when -fbounds-safety is available the `clang-bounds-safety` feature is available which means tests can be annotated with `# REQUIRES: clang-bounds-safety`. API tests that need -fbounds-safety support in the compiler can use the new `@skipUnlessBoundsSafety` decorator. rdar://165225507
…fety 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
…fety 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
…supports -fbounds-safety (#169112) This patch makes it possible to detect in LLDB shell and API tests if `-fbounds-safety` is supported by the compiler used for testing. The motivation behind this is to allow upstreaming swiftlang#11835 but with the tests disabled in upstream because the full implementation of -fbounds-safety isn't available in Clang yet. For shell tests when -fbounds-safety is available the `clang-bounds-safety` feature is available which means tests can be annotated with `# REQUIRES: clang-bounds-safety`. API tests that need -fbounds-safety support in the compiler can use the new `@skipUnlessBoundsSafety` decorator. rdar://165225507
…d in tests supports -fbounds-safety (#169112) This patch makes it possible to detect in LLDB shell and API tests if `-fbounds-safety` is supported by the compiler used for testing. The motivation behind this is to allow upstreaming swiftlang/llvm-project#11835 but with the tests disabled in upstream because the full implementation of -fbounds-safety isn't available in Clang yet. For shell tests when -fbounds-safety is available the `clang-bounds-safety` feature is available which means tests can be annotated with `# REQUIRES: clang-bounds-safety`. API tests that need -fbounds-safety support in the compiler can use the new `@skipUnlessBoundsSafety` decorator. rdar://165225507
…fety 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
This patch adds `LLDBLog::InstrumentationRuntime` as a log channel to provide an appropriate channel for instrumentation runtime plugins as previously one did not exist. A small use of the channel is added to illustrate its use. The logging added is not intended to be comprehensive. This is primarily motivated by an `-fbounds-safety` instrumentation plugin (swiftlang/llvm-project#11835). rdar://164920875 Signed-off-by: Hafidz Muzakky <[email protected]>
…supports -fbounds-safety (#169112) This patch makes it possible to detect in LLDB shell and API tests if `-fbounds-safety` is supported by the compiler used for testing. The motivation behind this is to allow upstreaming swiftlang/llvm-project#11835 but with the tests disabled in upstream because the full implementation of -fbounds-safety isn't available in Clang yet. For shell tests when -fbounds-safety is available the `clang-bounds-safety` feature is available which means tests can be annotated with `# REQUIRES: clang-bounds-safety`. API tests that need -fbounds-safety support in the compiler can use the new `@skipUnlessBoundsSafety` decorator. rdar://165225507 Signed-off-by: Hafidz Muzakky <[email protected]>
This patch adds `LLDBLog::InstrumentationRuntime` as a log channel to provide an appropriate channel for instrumentation runtime plugins as previously one did not exist. A small use of the channel is added to illustrate its use. The logging added is not intended to be comprehensive. This is primarily motivated by an `-fbounds-safety` instrumentation plugin (swiftlang#11835). rdar://164920875
…supports -fbounds-safety (llvm#169112) This patch makes it possible to detect in LLDB shell and API tests if `-fbounds-safety` is supported by the compiler used for testing. The motivation behind this is to allow upstreaming swiftlang#11835 but with the tests disabled in upstream because the full implementation of -fbounds-safety isn't available in Clang yet. For shell tests when -fbounds-safety is available the `clang-bounds-safety` feature is available which means tests can be annotated with `# REQUIRES: clang-bounds-safety`. API tests that need -fbounds-safety support in the compiler can use the new `@skipUnlessBoundsSafety` decorator. rdar://165225507
This patch adds `LLDBLog::InstrumentationRuntime` as a log channel to provide an appropriate channel for instrumentation runtime plugins as previously one did not exist. A small use of the channel is added to illustrate its use. The logging added is not intended to be comprehensive. This is primarily motivated by an `-fbounds-safety` instrumentation plugin (swiftlang#11835). rdar://164920875
…supports -fbounds-safety (llvm#169112) This patch makes it possible to detect in LLDB shell and API tests if `-fbounds-safety` is supported by the compiler used for testing. The motivation behind this is to allow upstreaming swiftlang#11835 but with the tests disabled in upstream because the full implementation of -fbounds-safety isn't available in Clang yet. For shell tests when -fbounds-safety is available the `clang-bounds-safety` feature is available which means tests can be annotated with `# REQUIRES: clang-bounds-safety`. API tests that need -fbounds-safety support in the compiler can use the new `@skipUnlessBoundsSafety` decorator. rdar://165225507
This patch implements an instrumentation plugin for the
-fbounds-safetysoft trap mode first implemented in#11645 (rdar://158088757).
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:
extracted from the artificial frame in the debug info (similar to
-fbounds-safety hard traps).
occurred.
When debug info is not available:
call-with-strsoft trap mode the soft trap reason isread from the first argument register.
call-minimalsoft trap mode the stop reason is adjustedto note its a bounds check failure but does not give further
information because none is available.
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