Skip to content

Commit 91e90cf

Browse files
committed
lldb/Instrumentation: NFC-ish use GetFrameCodeAddressForSymbolication()
A couple of our Instrumentation runtimes were gathering backtraces, storing it in a StructuredData array and later creating a HistoryThread using this data. By deafult HistoryThread will consider the history PCs as return addresses and thus will substract 1 from them to go to the call address. This is usually correct, but it's also wasteful as when we gather the backtraces ourselves, we have much better information to decide how to backtrace and symbolicate. This patch uses the new GetFrameCodeAddressForSymbolication() to gather the PCs that should be used for symbolication and configures the HistoryThread to just use those PCs as-is. (The MTC plugin was actaully applying a -1 itself and then the HistoryThread would do it again, so this actaully fixes a bug there.) rdar://77027680 Differential Revision: https://reviews.llvm.org/D101094
1 parent 18a8527 commit 91e90cf

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

lldb/source/Plugins/InstrumentationRuntime/MainThreadChecker/InstrumentationRuntimeMainThreadChecker.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -127,19 +127,14 @@ InstrumentationRuntimeMainThreadChecker::RetrieveReportData(
127127
StackFrameSP responsible_frame;
128128
for (unsigned I = 0; I < thread_sp->GetStackFrameCount(); ++I) {
129129
StackFrameSP frame = thread_sp->GetStackFrameAtIndex(I);
130-
Address addr = frame->GetFrameCodeAddress();
130+
Address addr = frame->GetFrameCodeAddressForSymbolication();
131131
if (addr.GetModule() == runtime_module_sp) // Skip PCs from the runtime.
132132
continue;
133133

134134
// The first non-runtime frame is responsible for the bug.
135135
if (!responsible_frame)
136136
responsible_frame = frame;
137137

138-
// First frame in stacktrace should point to a real PC, not return address.
139-
if (I != 0 && trace->GetSize() == 0) {
140-
addr.Slide(-1);
141-
}
142-
143138
lldb::addr_t PC = addr.GetLoadAddress(&target);
144139
trace->AddItem(StructuredData::ObjectSP(new StructuredData::Integer(PC)));
145140
}
@@ -271,8 +266,11 @@ InstrumentationRuntimeMainThreadChecker::GetBacktracesFromExtendedStopInfo(
271266
info->GetObjectForDotSeparatedPath("tid");
272267
tid_t tid = thread_id_obj ? thread_id_obj->GetIntegerValue() : 0;
273268

274-
HistoryThread *history_thread = new HistoryThread(*process_sp, tid, PCs);
275-
ThreadSP new_thread_sp(history_thread);
269+
// We gather symbolication addresses above, so no need for HistoryThread to
270+
// try to infer the call addresses.
271+
bool pcs_are_call_addresses = true;
272+
ThreadSP new_thread_sp = std::make_shared<HistoryThread>(
273+
*process_sp, tid, PCs, pcs_are_call_addresses);
276274

277275
// Save this in the Process' ExtendedThreadList so a strong pointer retains
278276
// the object

lldb/source/Plugins/InstrumentationRuntime/UBSan/InstrumentationRuntimeUBSan.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,8 @@ StructuredData::ObjectSP InstrumentationRuntimeUBSan::RetrieveReportData(
150150
StructuredData::Array *trace = new StructuredData::Array();
151151
auto trace_sp = StructuredData::ObjectSP(trace);
152152
for (unsigned I = 0; I < thread_sp->GetStackFrameCount(); ++I) {
153-
const Address FCA =
154-
thread_sp->GetStackFrameAtIndex(I)->GetFrameCodeAddress();
153+
const Address FCA = thread_sp->GetStackFrameAtIndex(I)
154+
->GetFrameCodeAddressForSymbolication();
155155
if (FCA.GetModule() == runtime_module_sp) // Skip PCs from the runtime.
156156
continue;
157157

@@ -324,8 +324,11 @@ InstrumentationRuntimeUBSan::GetBacktracesFromExtendedStopInfo(
324324
info->GetObjectForDotSeparatedPath("tid");
325325
tid_t tid = thread_id_obj ? thread_id_obj->GetIntegerValue() : 0;
326326

327-
HistoryThread *history_thread = new HistoryThread(*process_sp, tid, PCs);
328-
ThreadSP new_thread_sp(history_thread);
327+
// We gather symbolication addresses above, so no need for HistoryThread to
328+
// try to infer the call addresses.
329+
bool pcs_are_call_addresses = true;
330+
ThreadSP new_thread_sp = std::make_shared<HistoryThread>(
331+
*process_sp, tid, PCs, pcs_are_call_addresses);
329332
std::string stop_reason_description = GetStopReasonDescription(info);
330333
new_thread_sp->SetName(stop_reason_description.c_str());
331334

0 commit comments

Comments
 (0)