Skip to content

Commit 51480ef

Browse files
committed
[lldb] Introduce HistoryPCType enum
Introduce and adopt `HistoryPCType` enum to replace `pcs_are_call_addresses` bool to make handling of history back traces more clear and allow for extension of behavior. This change is a mechanical refactoring and preservers current behavior: ``` pcs_are_call_addresses: false -> HistoryPCType::Returns (default) true -> HistoryPCType::Calls ``` rdar://157596927
1 parent ef50227 commit 51480ef

File tree

9 files changed

+23
-25
lines changed

9 files changed

+23
-25
lines changed

lldb/include/lldb/lldb-private-enumerations.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,8 @@ enum class IterationAction {
248248
Stop,
249249
};
250250

251+
enum class HistoryPCType { Returns, ReturnsNoZerothFrame, Calls };
252+
251253
inline std::string GetStatDescription(lldb_private::StatisticKind K) {
252254
switch (K) {
253255
case StatisticKind::ExpressionSuccessful:

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -266,9 +266,9 @@ InstrumentationRuntimeMainThreadChecker::GetBacktracesFromExtendedStopInfo(
266266

267267
// We gather symbolication addresses above, so no need for HistoryThread to
268268
// try to infer the call addresses.
269-
bool pcs_are_call_addresses = true;
270-
ThreadSP new_thread_sp = std::make_shared<HistoryThread>(
271-
*process_sp, tid, PCs, pcs_are_call_addresses);
269+
auto pc_type = HistoryPCType::Calls;
270+
ThreadSP new_thread_sp =
271+
std::make_shared<HistoryThread>(*process_sp, tid, PCs, pc_type);
272272

273273
// Save this in the Process' ExtendedThreadList so a strong pointer retains
274274
// the object

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -324,9 +324,9 @@ InstrumentationRuntimeUBSan::GetBacktracesFromExtendedStopInfo(
324324

325325
// We gather symbolication addresses above, so no need for HistoryThread to
326326
// try to infer the call addresses.
327-
bool pcs_are_call_addresses = true;
328-
ThreadSP new_thread_sp = std::make_shared<HistoryThread>(
329-
*process_sp, tid, PCs, pcs_are_call_addresses);
327+
auto pc_type = HistoryPCType::Calls;
328+
ThreadSP new_thread_sp =
329+
std::make_shared<HistoryThread>(*process_sp, tid, PCs, pc_type);
330330
std::string stop_reason_description = GetStopReasonDescription(info);
331331
new_thread_sp->SetName(stop_reason_description.c_str());
332332

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,9 @@ static void CreateHistoryThreadFromValueObject(ProcessSP process_sp,
131131
// The ASAN runtime already massages the return addresses into call
132132
// addresses, we don't want LLDB's unwinder to try to locate the previous
133133
// instruction again as this might lead to us reporting a different line.
134-
bool pcs_are_call_addresses = true;
134+
auto pc_type = HistoryPCType::Calls;
135135
HistoryThread *history_thread =
136-
new HistoryThread(*process_sp, tid, pcs, pcs_are_call_addresses);
136+
new HistoryThread(*process_sp, tid, pcs, pc_type);
137137
ThreadSP new_thread_sp(history_thread);
138138
std::ostringstream thread_name_with_number;
139139
thread_name_with_number << thread_name << " Thread " << tid;

lldb/source/Plugins/Process/Utility/HistoryThread.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,12 @@ using namespace lldb_private;
2727

2828
HistoryThread::HistoryThread(lldb_private::Process &process, lldb::tid_t tid,
2929
std::vector<lldb::addr_t> pcs,
30-
bool pcs_are_call_addresses)
30+
HistoryPCType pc_type)
3131
: Thread(process, tid, true), m_framelist_mutex(), m_framelist(),
3232
m_pcs(pcs), m_extended_unwind_token(LLDB_INVALID_ADDRESS), m_queue_name(),
3333
m_thread_name(), m_originating_unique_thread_id(tid),
3434
m_queue_id(LLDB_INVALID_QUEUE_ID) {
35-
m_unwinder_up =
36-
std::make_unique<HistoryUnwind>(*this, pcs, pcs_are_call_addresses);
35+
m_unwinder_up = std::make_unique<HistoryUnwind>(*this, pcs, pc_type);
3736
Log *log = GetLog(LLDBLog::Object);
3837
LLDB_LOGF(log, "%p HistoryThread::HistoryThread", static_cast<void *>(this));
3938
}

lldb/source/Plugins/Process/Utility/HistoryThread.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@ namespace lldb_private {
2727
/// process execution
2828
///
2929
/// This subclass of Thread is used to provide a backtrace from earlier in
30-
/// process execution. It is given a backtrace list of pc addresses and it
31-
/// will create stack frames for them.
30+
/// process execution. It is given a backtrace list of pcs (return or call
31+
/// addresses) and it will create stack frames for them.
3232

3333
class HistoryThread : public lldb_private::Thread {
3434
public:
3535
HistoryThread(lldb_private::Process &process, lldb::tid_t tid,
3636
std::vector<lldb::addr_t> pcs,
37-
bool pcs_are_call_addresses = false);
37+
HistoryPCType pc_type = HistoryPCType::Returns);
3838

3939
~HistoryThread() override;
4040

lldb/source/Plugins/Process/Utility/HistoryUnwind.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,8 @@ using namespace lldb_private;
2424
// Constructor
2525

2626
HistoryUnwind::HistoryUnwind(Thread &thread, std::vector<lldb::addr_t> pcs,
27-
bool pcs_are_call_addresses)
28-
: Unwind(thread), m_pcs(pcs),
29-
m_pcs_are_call_addresses(pcs_are_call_addresses) {}
27+
HistoryPCType pc_type)
28+
: Unwind(thread), m_pcs(pcs), m_pc_type(pc_type) {}
3029

3130
// Destructor
3231

@@ -61,7 +60,7 @@ bool HistoryUnwind::DoGetFrameInfoAtIndex(uint32_t frame_idx, lldb::addr_t &cfa,
6160
if (frame_idx < m_pcs.size()) {
6261
cfa = frame_idx;
6362
pc = m_pcs[frame_idx];
64-
if (m_pcs_are_call_addresses)
63+
if (m_pc_type == HistoryPCType::Calls)
6564
behaves_like_zeroth_frame = true;
6665
else
6766
behaves_like_zeroth_frame = (frame_idx == 0);

lldb/source/Plugins/Process/Utility/HistoryUnwind.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ namespace lldb_private {
1919
class HistoryUnwind : public lldb_private::Unwind {
2020
public:
2121
HistoryUnwind(Thread &thread, std::vector<lldb::addr_t> pcs,
22-
bool pcs_are_call_addresses = false);
22+
HistoryPCType pc_type = HistoryPCType::Returns);
2323

2424
~HistoryUnwind() override;
2525

@@ -36,9 +36,7 @@ class HistoryUnwind : public lldb_private::Unwind {
3636

3737
private:
3838
std::vector<lldb::addr_t> m_pcs;
39-
/// This boolean indicates that the PCs in the non-0 frames are call
40-
/// addresses and not return addresses.
41-
bool m_pcs_are_call_addresses;
39+
HistoryPCType m_pc_type;
4240
};
4341

4442
} // namespace lldb_private

lldb/source/Plugins/SystemRuntime/MacOSX/SystemRuntimeMacOSX.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -544,9 +544,9 @@ ThreadSP SystemRuntimeMacOSX::GetExtendedBacktraceThread(ThreadSP real_thread,
544544
if (!thread_extended_info->ForEach(extract_frame_pc))
545545
return {};
546546

547-
originating_thread_sp =
548-
std::make_shared<HistoryThread>(*m_process, real_thread->GetIndexID(),
549-
app_specific_backtrace_pcs, true);
547+
originating_thread_sp = std::make_shared<HistoryThread>(
548+
*m_process, real_thread->GetIndexID(), app_specific_backtrace_pcs,
549+
HistoryPCType::Calls);
550550
originating_thread_sp->SetQueueName(type.AsCString());
551551
}
552552
return originating_thread_sp;

0 commit comments

Comments
 (0)