Skip to content

Commit 1f8d451

Browse files
committed
[lldb/API] Hoist some of SBFrame Swift logic to lldb_private::StackFrame (NFC)
This patch moves the logic for IsSwiftThunk and GetLanguageSpecificData from SBFrame to the lldb_private::StackFrame class so it can be re-used elsewhere. Signed-off-by: Med Ismail Bennani <[email protected]>
1 parent a0eef8f commit 1f8d451

File tree

3 files changed

+51
-21
lines changed

3 files changed

+51
-21
lines changed

lldb/include/lldb/Target/StackFrame.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,16 @@ class StackFrame : public ExecutionContextScope,
412412
/// system implementation details this way.
413413
bool IsHidden();
414414

415+
/// Query whether this frame is a Swift Thunk.
416+
bool IsSwiftThunk();
417+
418+
/// Get this frame language specific data.
419+
///
420+
/// \return
421+
/// The StructuredDataImpl object containing the language specific data. Can
422+
/// be null.
423+
StructuredDataImpl *GetLanguageSpecificData();
424+
415425
/// Get the frame's demangled name.
416426
///
417427
/// /// \return

lldb/source/API/SBFrame.cpp

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,6 @@
5656

5757
#include "llvm/Support/PrettyStackTrace.h"
5858

59-
// BEGIN SWIFT
60-
#include "lldb/Target/LanguageRuntime.h"
61-
#ifdef LLDB_ENABLE_SWIFT
62-
#include "Plugins/LanguageRuntime/Swift/SwiftLanguageRuntime.h"
63-
#endif
64-
// END SWIFT
65-
6659
using namespace lldb;
6760
using namespace lldb_private;
6861

@@ -1249,13 +1242,10 @@ lldb::LanguageType SBFrame::GuessLanguage() const {
12491242
lldb::SBStructuredData SBFrame::GetLanguageSpecificData() const {
12501243
std::unique_lock<std::recursive_mutex> lock;
12511244
ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
1252-
auto *process = exe_ctx.GetProcessPtr();
12531245
auto *frame = exe_ctx.GetFramePtr();
1254-
if (process && frame)
1255-
if (auto *runtime = process->GetLanguageRuntime(
1256-
frame->GuessLanguage().AsLanguageType()))
1257-
if (auto *data = runtime->GetLanguageSpecificData(*frame))
1258-
return SBStructuredData(*data);
1246+
if (frame)
1247+
if (StructuredDataImpl *data = frame->GetLanguageSpecificData())
1248+
return SBStructuredData(*data);
12591249

12601250
return {};
12611251
}
@@ -1276,14 +1266,7 @@ bool SBFrame::IsSwiftThunk() const {
12761266
frame = exe_ctx.GetFramePtr();
12771267
if (!frame)
12781268
return false;
1279-
SymbolContext sc;
1280-
sc = frame->GetSymbolContext(eSymbolContextSymbol);
1281-
if (!sc.symbol)
1282-
return false;
1283-
auto *runtime = process->GetLanguageRuntime(eLanguageTypeSwift);
1284-
if (!runtime)
1285-
return false;
1286-
return runtime->IsSymbolARuntimeThunk(*sc.symbol);
1269+
return frame->IsSwiftThunk();
12871270
}
12881271
// END SWIFT
12891272

lldb/source/Target/StackFrame.cpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@
3434
#include "lldb/ValueObject/ValueObjectMemory.h"
3535
#include "lldb/ValueObject/ValueObjectVariable.h"
3636

37+
#include "lldb/Target/LanguageRuntime.h"
38+
#ifdef LLDB_ENABLE_SWIFT
39+
#include "Plugins/LanguageRuntime/Swift/SwiftLanguageRuntime.h"
40+
#endif
41+
3742
#include "lldb/lldb-enumerations.h"
3843

3944
#include <memory>
@@ -1215,6 +1220,38 @@ bool StackFrame::IsHidden() {
12151220
return false;
12161221
}
12171222

1223+
bool StackFrame::IsSwiftThunk() {
1224+
ThreadSP thread_sp = GetThread();
1225+
if (!thread_sp)
1226+
return false;
1227+
ProcessSP process_sp = thread_sp->GetProcess();
1228+
if (!process_sp)
1229+
return false;
1230+
1231+
SymbolContext sc = GetSymbolContext(eSymbolContextSymbol);
1232+
if (!sc.symbol)
1233+
return false;
1234+
auto *runtime = process_sp->GetLanguageRuntime(eLanguageTypeSwift);
1235+
if (!runtime)
1236+
return false;
1237+
return runtime->IsSymbolARuntimeThunk(*sc.symbol);
1238+
}
1239+
1240+
StructuredDataImpl *StackFrame::GetLanguageSpecificData() {
1241+
ThreadSP thread_sp = GetThread();
1242+
if (!thread_sp)
1243+
return {};
1244+
ProcessSP process_sp = thread_sp->GetProcess();
1245+
if (!process_sp)
1246+
return {};
1247+
1248+
if (auto *runtime =
1249+
process_sp->GetLanguageRuntime(GuessLanguage().AsLanguageType()))
1250+
if (auto *data = runtime->GetLanguageSpecificData(*this))
1251+
return data;
1252+
return {};
1253+
}
1254+
12181255
const char *StackFrame::GetFunctionName() {
12191256
const char *name = nullptr;
12201257
SymbolContext sc = GetSymbolContext(

0 commit comments

Comments
 (0)