Skip to content
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

[LLDB] ASanLibsanitizers Use sanitizers_address_on_report breakpoint #84583

Merged

Conversation

usama54321
Copy link
Member

symbol

This patch puts the default breakpoint on the
sanitizers_address_on_report symbol, and uses the old symbol as a backup if the default case is not found

rdar://123911522

@usama54321 usama54321 requested a review from yln March 8, 2024 23:31
@llvmbot llvmbot added the lldb label Mar 8, 2024
@llvmbot
Copy link
Collaborator

llvmbot commented Mar 8, 2024

@llvm/pr-subscribers-lldb

Author: Usama Hameed (usama54321)

Changes

symbol

This patch puts the default breakpoint on the
sanitizers_address_on_report symbol, and uses the old symbol as a backup if the default case is not found

rdar://123911522


Full diff: https://github.com/llvm/llvm-project/pull/84583.diff

1 Files Affected:

  • (modified) lldb/source/Plugins/InstrumentationRuntime/ASanLibsanitizers/InstrumentationRuntimeASanLibsanitizers.cpp (+10-2)
diff --git a/lldb/source/Plugins/InstrumentationRuntime/ASanLibsanitizers/InstrumentationRuntimeASanLibsanitizers.cpp b/lldb/source/Plugins/InstrumentationRuntime/ASanLibsanitizers/InstrumentationRuntimeASanLibsanitizers.cpp
index d84cd36d7ce17b..e095d3e6b2e339 100644
--- a/lldb/source/Plugins/InstrumentationRuntime/ASanLibsanitizers/InstrumentationRuntimeASanLibsanitizers.cpp
+++ b/lldb/source/Plugins/InstrumentationRuntime/ASanLibsanitizers/InstrumentationRuntimeASanLibsanitizers.cpp
@@ -90,9 +90,17 @@ void InstrumentationRuntimeASanLibsanitizers::Activate() {
   if (!process_sp)
     return;
 
+  lldb::ModuleSP module_sp = GetRuntimeModuleSP();
+
   Breakpoint *breakpoint = ReportRetriever::SetupBreakpoint(
-      GetRuntimeModuleSP(), process_sp,
-      ConstString("_Z22raise_sanitizers_error23sanitizer_error_context"));
+      module_sp, process_sp,
+      ConstString("_sanitizers_address_on_report"));
+
+  if (!breakpoint) {
+    breakpoint = ReportRetriever::SetupBreakpoint(
+        module_sp, process_sp,
+        ConstString("_Z22raise_sanitizers_error23sanitizer_error_context"));
+  }
 
   if (!breakpoint)
     return;

Copy link

github-actions bot commented Mar 8, 2024

✅ With the latest revision this PR passed the C/C++ code formatter.

@usama54321 usama54321 force-pushed the asan-libsanitizers-change-breakpoint-symbol branch from aa8f732 to fbe0844 Compare March 8, 2024 23:56
Copy link
Collaborator

@yln yln left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@jimingham
Copy link
Collaborator

ReportRetriever::SetupBreakpoint is a weird way to set a breakpoint. This is somewhat off topic, but do you know why it was done this way? You could set it by symbol & module and then you'd have something that survives rebuilds of the module, or you could set it by Address, in which case it would survive re-running, but instead it converts the Address to an addr_t - the most fragile way to set a breakpoint - and uses that...

This came up because you could (if this weren't done so oddly) handle this by having a list of candidate functions, and make a single breakpoint with all those names...

@yln
Copy link
Collaborator

yln commented Mar 9, 2024

@jimingham, thanks for the review and feedback on how to improve the code. Are you okay with us addressing this in a follow-up?

do you know why it was done this way?

I don't think we do. I think we just copied what was done in the old ASan plugin. My guess for the original code is that there was no specific reason other than "it worked". I definitely want to follow your guidance and improve this if it has benefits (and it seems easy to do).

survives rebuilds

I think we are fine for rebuilds. The module we are setting the breakpoint in is the ASan runtime, which doesn't get rebuilt.

This came up because you could (if this weren't done so oddly) handle this by having a list of candidate functions, and make a single breakpoint with all those names...

@usama54321 please add a FIXME/TODO in the code and file a radar to improve this (you can assign it to me)

@yln yln requested a review from jimingham March 9, 2024 00:38
@jimingham
Copy link
Collaborator

I have no problem with doing this in stages, what needs doing right now and cleanups to follow.

@jimingham
Copy link
Collaborator

@jimingham, thanks for the review and feedback on how to improve the code. Are you okay with us addressing this in a follow-up?

do you know why it was done this way?

I don't think we do. I think we just copied what was done in the old ASan plugin. My guess for the original code is that there was no specific reason other than "it worked". I definitely want to follow your guidance and improve this if it has benefits (and it seems easy to do).

survives rebuilds

I think we are fine for rebuilds. The module we are setting the breakpoint in is the ASan runtime, which doesn't get rebuilt.

Unless you happen to be working on the asan runtime...

This came up because you could (if this weren't done so oddly) handle this by having a list of candidate functions, and make a single breakpoint with all those names...

@usama54321 please add a FIXME/TODO in the code and file a radar to improve this (you can assign it to me)

Copy link
Collaborator

@jimingham jimingham left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

breakpoint symbol

This patch puts the default breakpoint on the
sanitizers_address_on_report symbol, and uses the old symbol as a
backup if the default case is not found

rdar://123911522
@usama54321 usama54321 force-pushed the asan-libsanitizers-change-breakpoint-symbol branch from fbe0844 to 3b16e50 Compare March 11, 2024 18:41
@usama54321 usama54321 merged commit 08a9207 into llvm:main Mar 11, 2024
4 checks passed
usama54321 added a commit to usama54321/apple-llvm-project that referenced this pull request Mar 13, 2024
llvm#84583)

symbol

This patch puts the default breakpoint on the
sanitizers_address_on_report symbol, and uses the old symbol as a backup
if the default case is not found

rdar://123911522
usama54321 added a commit to apple/llvm-project that referenced this pull request Mar 13, 2024
llvm#84583)

symbol

This patch puts the default breakpoint on the
sanitizers_address_on_report symbol, and uses the old symbol as a backup
if the default case is not found

rdar://123911522
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants