Skip to content

Commit f75b908

Browse files
committed
fixup! move GetPreferredAsanModule into common header and use it from InstrumentationRuntime
1 parent a14ed13 commit f75b908

File tree

5 files changed

+72
-20
lines changed

5 files changed

+72
-20
lines changed

lldb/source/Plugins/InstrumentationRuntime/Utility/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
add_lldb_library(lldbPluginInstrumentationRuntimeUtility
22
ReportRetriever.cpp
3+
Utility.cpp
34

45
LINK_LIBS
56
lldbBreakpoint

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "ReportRetriever.h"
10+
#include "Utility.h"
1011

1112
#include "lldb/Breakpoint/StoppointCallbackContext.h"
1213
#include "lldb/Core/Debugger.h"
@@ -82,6 +83,12 @@ ReportRetriever::RetrieveReportData(const ProcessSP process_sp) {
8283
options.SetAutoApplyFixIts(false);
8384
options.SetLanguage(eLanguageTypeObjC_plus_plus);
8485

86+
if (auto m = GetPreferredSanitizerModule(process_sp->GetTarget())) {
87+
SymbolContextList sc_list;
88+
sc_list.Append(SymbolContext(std::move(m)));
89+
options.SetPreferredSymbolContexts(std::move(sc_list));
90+
}
91+
8592
ValueObjectSP return_value_sp;
8693
ExecutionContext exe_ctx;
8794
frame_sp->CalculateExecutionContext(exe_ctx);
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
//===-- Utility.cpp -------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#include "Utility.h"
10+
11+
#include "lldb/Core/Module.h"
12+
#include "lldb/Target/Target.h"
13+
14+
namespace lldb_private {
15+
16+
///< On Darwin, if LLDB loaded libclang_rt, it's coming from a locally built
17+
///< compiler-rt, and we should prefer it in favour of the system sanitizers.
18+
///< This helper searches the target for such a dylib. Returns nullptr if no
19+
///< such dylib was found.
20+
lldb::ModuleSP GetPreferredSanitizerModule(const Target &target) {
21+
lldb::ModuleSP module;
22+
llvm::Regex pattern(R"(libclang_rt\.(asan|tsan|ubsan)_.*_dynamic\.dylib)");
23+
target.GetImages().ForEach([&](const lldb::ModuleSP &m) {
24+
if (pattern.match(m->GetFileSpec().GetFilename().GetStringRef())) {
25+
module = m;
26+
return false;
27+
}
28+
29+
return true;
30+
});
31+
32+
return module;
33+
}
34+
35+
} // namespace lldb_private
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//===-- Utility.h -----------------------------------------------*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef LLDB_SOURCE_PLUGINS_INSTRUMENTATIONRUNTIME_UTILITY_UTILITY_H
10+
#define LLDB_SOURCE_PLUGINS_INSTRUMENTATIONRUNTIME_UTILITY_UTILITY_H
11+
12+
#include "lldb/lldb-forward.h"
13+
14+
namespace lldb_private {
15+
16+
class Target;
17+
18+
///< On Darwin, if LLDB loaded libclang_rt, it's coming from a locally built
19+
///< compiler-rt, and we should prefer it in favour of the system sanitizers
20+
///< when running InstrumentationRuntime utility expressions that use symbols
21+
///< from the sanitizer libraries. This helper searches the target for such a
22+
///< dylib. Returns nullptr if no such dylib was found.
23+
lldb::ModuleSP GetPreferredSanitizerModule(const Target &target);
24+
25+
} // namespace lldb_private
26+
27+
#endif // LLDB_SOURCE_PLUGINS_INSTRUMENTATIONRUNTIME_UTILITY_UTILITY_H

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

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "lldb/Symbol/SymbolContext.h"
1212
#include "lldb/Target/MemoryHistory.h"
1313

14+
#include "Plugins/InstrumentationRuntime/Utility/Utility.h"
1415
#include "Plugins/Process/Utility/HistoryThread.h"
1516
#include "lldb/Core/Debugger.h"
1617
#include "lldb/Core/Module.h"
@@ -62,25 +63,6 @@ MemoryHistoryASan::MemoryHistoryASan(const ProcessSP &process_sp) {
6263
m_process_wp = process_sp;
6364
}
6465

65-
///< On Darwin, if LLDB loaded libclang_rt, it's coming from a locally built
66-
///< compiler-rt, and we should prefer it in favour of the system sanitizers.
67-
///< This helper searches the target for such a dylib. Returns nullptr if no
68-
///< such dylib was found.
69-
static ModuleSP GetPreferredAsanModule(const Target &target) {
70-
ModuleSP module;
71-
llvm::Regex pattern(R"(libclang_rt\.asan_.*_dynamic\.dylib)");
72-
target.GetImages().ForEach([&](const lldb::ModuleSP &m) {
73-
if (pattern.match(m->GetFileSpec().GetFilename().GetStringRef())) {
74-
module = m;
75-
return false;
76-
}
77-
78-
return true;
79-
});
80-
81-
return module;
82-
}
83-
8466
const char *memory_history_asan_command_prefix = R"(
8567
extern "C"
8668
{
@@ -194,7 +176,7 @@ HistoryThreads MemoryHistoryASan::GetHistoryThreads(lldb::addr_t address) {
194176
options.SetAutoApplyFixIts(false);
195177
options.SetLanguage(eLanguageTypeObjC_plus_plus);
196178

197-
if (auto m = GetPreferredAsanModule(process_sp->GetTarget())) {
179+
if (auto m = GetPreferredSanitizerModule(process_sp->GetTarget())) {
198180
SymbolContextList sc_list;
199181
sc_list.Append(SymbolContext(std::move(m)));
200182
options.SetPreferredSymbolContexts(std::move(sc_list));

0 commit comments

Comments
 (0)