Skip to content

Commit 32ec465

Browse files
committed
[lldb] Refactor GetPreferredAsanModule() to also return the HistoryPCType
1 parent d87f634 commit 32ec465

File tree

4 files changed

+23
-23
lines changed

4 files changed

+23
-23
lines changed

lldb/source/Plugins/InstrumentationRuntime/Utility/ReportRetriever.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ ReportRetriever::RetrieveReportData(const ProcessSP process_sp) {
8383
options.SetAutoApplyFixIts(false);
8484
options.SetLanguage(eLanguageTypeObjC_plus_plus);
8585

86-
if (auto m = GetPreferredAsanModule(process_sp->GetTarget())) {
86+
if (auto [m, _] = GetPreferredAsanModule(process_sp->GetTarget()); m) {
8787
SymbolContextList sc_list;
8888
sc_list.Append(SymbolContext(std::move(m)));
8989
options.SetPreferredSymbolContexts(std::move(sc_list));

lldb/source/Plugins/InstrumentationRuntime/Utility/Utility.cpp

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@
1313

1414
namespace lldb_private {
1515

16-
lldb::ModuleSP GetPreferredAsanModule(const Target &target) {
17-
// Currently only supported on Darwin.
16+
std::tuple<lldb::ModuleSP, HistoryPCType>
17+
GetPreferredAsanModule(const Target &target) {
18+
// Currently only Darwin provides ASan runtime support as part of the OS
19+
// (libsanitizers).
1820
if (!target.GetArchitecture().GetTriple().isOSDarwin())
19-
return nullptr;
21+
return {nullptr, HistoryPCType::Calls};
2022

2123
lldb::ModuleSP module;
2224
llvm::Regex pattern(R"(libclang_rt\.asan_.*_dynamic\.dylib)");
@@ -29,7 +31,16 @@ lldb::ModuleSP GetPreferredAsanModule(const Target &target) {
2931
return IterationAction::Continue;
3032
});
3133

32-
return module;
34+
// `Calls` - The ASan compiler-rt runtime already massages the return
35+
// addresses into call addresses, so we don't want LLDB's unwinder to try to
36+
// locate the previous instruction again as this might lead to us reporting
37+
// a different line.
38+
// `ReturnsNoZerothFrame` - Darwin, but not ASan compiler-rt implies
39+
// libsanitizers which collects return addresses. It also discards a few
40+
// non-user frames at the top of the stack.
41+
auto pc_type =
42+
(module ? HistoryPCType::Calls : HistoryPCType::ReturnsNoZerothFrame);
43+
return {module, pc_type};
3344
}
3445

3546
} // namespace lldb_private

lldb/source/Plugins/InstrumentationRuntime/Utility/Utility.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,20 @@
99
#ifndef LLDB_SOURCE_PLUGINS_INSTRUMENTATIONRUNTIME_UTILITY_UTILITY_H
1010
#define LLDB_SOURCE_PLUGINS_INSTRUMENTATIONRUNTIME_UTILITY_UTILITY_H
1111

12+
#include <tuple>
13+
1214
#include "lldb/lldb-forward.h"
15+
#include "lldb/lldb-private-enumerations.h"
1316

1417
namespace lldb_private {
1518

16-
class Target;
17-
1819
/// On Darwin, if LLDB loaded libclang_rt, it's coming from a locally built
1920
/// compiler-rt, and we should prefer it in favour of the system sanitizers
2021
/// when running InstrumentationRuntime utility expressions that use symbols
2122
/// from the sanitizer libraries. This helper searches the target for such a
2223
/// dylib. Returns nullptr if no such dylib was found.
23-
lldb::ModuleSP GetPreferredAsanModule(const Target &target);
24+
std::tuple<lldb::ModuleSP, HistoryPCType>
25+
GetPreferredAsanModule(const Target &target);
2426

2527
} // namespace lldb_private
2628

lldb/source/Plugins/MemoryHistory/asan/MemoryHistoryASan.cpp

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -170,24 +170,11 @@ HistoryThreads MemoryHistoryASan::GetHistoryThreads(lldb::addr_t address) {
170170
options.SetAutoApplyFixIts(false);
171171
options.SetLanguage(eLanguageTypeObjC_plus_plus);
172172

173-
// The ASan compiler-rt runtime already massages the return addresses into
174-
// call addresses, so we don't want LLDB's unwinder to try to locate the
175-
// previous instruction again as this might lead to us reporting a different
176-
// line.
177-
auto pc_type = HistoryPCType::Calls;
178-
179-
if (auto m = GetPreferredAsanModule(process_sp->GetTarget())) {
173+
auto [m, pc_type] = GetPreferredAsanModule(process_sp->GetTarget());
174+
if (m) {
180175
SymbolContextList sc_list;
181176
sc_list.Append(SymbolContext(std::move(m)));
182177
options.SetPreferredSymbolContexts(std::move(sc_list));
183-
} else if (process_sp->GetTarget()
184-
.GetArchitecture()
185-
.GetTriple()
186-
.isOSDarwin()) {
187-
// Darwin, but not ASan compiler-rt implies libsanitizers which collects
188-
// return addresses. It also discards a few non-user frames at the top of
189-
// the stack.
190-
pc_type = HistoryPCType::ReturnsNoZerothFrame;
191178
}
192179

193180
ExpressionResults expr_result = UserExpression::Evaluate(

0 commit comments

Comments
 (0)