[Lldb-commits] [lldb] [lldb] Fix source line annotations for libsanitizers traces (PR #154247)

Michael Buch via lldb-commits lldb-commits at lists.llvm.org
Tue Aug 19 03:22:58 PDT 2025


================
@@ -176,10 +170,23 @@ HistoryThreads MemoryHistoryASan::GetHistoryThreads(lldb::addr_t address) {
   options.SetAutoApplyFixIts(false);
   options.SetLanguage(eLanguageTypeObjC_plus_plus);
 
-  if (auto m = GetPreferredAsanModule(process_sp->GetTarget())) {
-    SymbolContextList sc_list;
-    sc_list.Append(SymbolContext(std::move(m)));
-    options.SetPreferredSymbolContexts(std::move(sc_list));
+  // The ASan compiler-rt runtime already massages the return addresses into
+  // call addresses, so we don't want LLDB's unwinder to try to locate the
+  // previous instruction again as this might lead to us reporting a different
+  // line.
+  auto pc_type = TracePCType::Calls;
+
+  if (process_sp->GetTarget().GetArchitecture().GetTriple().isOSDarwin()) {
+    if (auto m = GetPreferredAsanModule(process_sp->GetTarget())) {
+      SymbolContextList sc_list;
+      sc_list.Append(SymbolContext(std::move(m)));
+      options.SetPreferredSymbolContexts(std::move(sc_list));
+    } else {
+      // Darwin, but not ASan compiler-rt implies libsanitizers which collects
+      // return addresses.  It also discards a few non-user frames at the top of
+      // the stack.
+      pc_type = TracePCType::ReturnsNoZerothFrame;
+    }
----------------
Michael137 wrote:

Should we invert this like so?
```suggestion
  if (auto m = GetPreferredAsanModule(process_sp->GetTarget())) {
      SymbolContextList sc_list;
      sc_list.Append(SymbolContext(std::move(m)));
      options.SetPreferredSymbolContexts(std::move(sc_list));
  } else if (process_sp->GetTarget().GetArchitecture().GetTriple().isOSDarwin()) {
      // Darwin, but not ASan compiler-rt implies libsanitizers which collects
      // return addresses.  It also discards a few non-user frames at the top of
      // the stack.
      pc_type = TracePCType::ReturnsNoZerothFrame;
  }
```
In case `GetPreferredAsanModule` does something on non-Darwin platforms in the future?

https://github.com/llvm/llvm-project/pull/154247


More information about the lldb-commits mailing list