Skip to content

Commit cfaee62

Browse files
authored
Merge pull request swiftlang#9610 from medismailben/stable/20240723
2 parents b8bc0d7 + 1f8d451 commit cfaee62

File tree

3 files changed

+122
-73
lines changed

3 files changed

+122
-73
lines changed

lldb/include/lldb/Target/StackFrame.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,28 @@ 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+
425+
/// Get the frame's demangled name.
426+
///
427+
/// /// \return
428+
/// A C-String containing the function demangled name. Can be null.
429+
const char *GetFunctionName();
430+
431+
/// Get the frame's demangled display name.
432+
///
433+
/// /// \return
434+
/// A C-String containing the function demangled display name. Can be null.
435+
const char *GetDisplayFunctionName();
436+
415437
/// Query this frame to find what frame it is in this Thread's
416438
/// StackFrameList.
417439
///

lldb/source/API/SBFrame.cpp

Lines changed: 10 additions & 73 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

@@ -1182,12 +1175,8 @@ bool SBFrame::IsInlined() const {
11821175
Process::StopLocker stop_locker;
11831176
if (stop_locker.TryLock(&process->GetRunLock())) {
11841177
frame = exe_ctx.GetFramePtr();
1185-
if (frame) {
1186-
1187-
Block *block = frame->GetSymbolContext(eSymbolContextBlock).block;
1188-
if (block)
1189-
return block->GetContainingInlinedBlock() != nullptr;
1190-
}
1178+
if (frame)
1179+
return frame->IsInlined();
11911180
}
11921181
}
11931182
return false;
@@ -1253,13 +1242,10 @@ lldb::LanguageType SBFrame::GuessLanguage() const {
12531242
lldb::SBStructuredData SBFrame::GetLanguageSpecificData() const {
12541243
std::unique_lock<std::recursive_mutex> lock;
12551244
ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
1256-
auto *process = exe_ctx.GetProcessPtr();
12571245
auto *frame = exe_ctx.GetFramePtr();
1258-
if (process && frame)
1259-
if (auto *runtime = process->GetLanguageRuntime(
1260-
frame->GuessLanguage().AsLanguageType()))
1261-
if (auto *data = runtime->GetLanguageSpecificData(*frame))
1262-
return SBStructuredData(*data);
1246+
if (frame)
1247+
if (StructuredDataImpl *data = frame->GetLanguageSpecificData())
1248+
return SBStructuredData(*data);
12631249

12641250
return {};
12651251
}
@@ -1280,14 +1266,7 @@ bool SBFrame::IsSwiftThunk() const {
12801266
frame = exe_ctx.GetFramePtr();
12811267
if (!frame)
12821268
return false;
1283-
SymbolContext sc;
1284-
sc = frame->GetSymbolContext(eSymbolContextSymbol);
1285-
if (!sc.symbol)
1286-
return false;
1287-
auto *runtime = process->GetLanguageRuntime(eLanguageTypeSwift);
1288-
if (!runtime)
1289-
return false;
1290-
return runtime->IsSymbolARuntimeThunk(*sc.symbol);
1269+
return frame->IsSwiftThunk();
12911270
}
12921271
// END SWIFT
12931272

@@ -1305,29 +1284,8 @@ const char *SBFrame::GetFunctionName() const {
13051284
Process::StopLocker stop_locker;
13061285
if (stop_locker.TryLock(&process->GetRunLock())) {
13071286
frame = exe_ctx.GetFramePtr();
1308-
if (frame) {
1309-
SymbolContext sc(frame->GetSymbolContext(eSymbolContextFunction |
1310-
eSymbolContextBlock |
1311-
eSymbolContextSymbol));
1312-
if (sc.block) {
1313-
Block *inlined_block = sc.block->GetContainingInlinedBlock();
1314-
if (inlined_block) {
1315-
const InlineFunctionInfo *inlined_info =
1316-
inlined_block->GetInlinedFunctionInfo();
1317-
name = inlined_info->GetName().AsCString();
1318-
}
1319-
}
1320-
1321-
if (name == nullptr) {
1322-
if (sc.function)
1323-
name = sc.function->GetName().GetCString();
1324-
}
1325-
1326-
if (name == nullptr) {
1327-
if (sc.symbol)
1328-
name = sc.symbol->GetName().GetCString();
1329-
}
1330-
}
1287+
if (frame)
1288+
return frame->GetFunctionName();
13311289
}
13321290
}
13331291
return name;
@@ -1348,29 +1306,8 @@ const char *SBFrame::GetDisplayFunctionName() {
13481306
Process::StopLocker stop_locker;
13491307
if (stop_locker.TryLock(&process->GetRunLock())) {
13501308
frame = exe_ctx.GetFramePtr();
1351-
if (frame) {
1352-
SymbolContext sc(frame->GetSymbolContext(eSymbolContextFunction |
1353-
eSymbolContextBlock |
1354-
eSymbolContextSymbol));
1355-
if (sc.block) {
1356-
Block *inlined_block = sc.block->GetContainingInlinedBlock();
1357-
if (inlined_block) {
1358-
const InlineFunctionInfo *inlined_info =
1359-
inlined_block->GetInlinedFunctionInfo();
1360-
name = inlined_info->GetDisplayName().AsCString();
1361-
}
1362-
}
1363-
1364-
if (name == nullptr) {
1365-
if (sc.function)
1366-
name = sc.function->GetDisplayName().GetCString();
1367-
}
1368-
1369-
if (name == nullptr) {
1370-
if (sc.symbol)
1371-
name = sc.symbol->GetDisplayName().GetCString();
1372-
}
1373-
}
1309+
if (frame)
1310+
return frame->GetDisplayFunctionName();
13741311
}
13751312
}
13761313
return name;

lldb/source/Target/StackFrame.cpp

Lines changed: 90 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,91 @@ 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+
1255+
const char *StackFrame::GetFunctionName() {
1256+
const char *name = nullptr;
1257+
SymbolContext sc = GetSymbolContext(
1258+
eSymbolContextFunction | eSymbolContextBlock | eSymbolContextSymbol);
1259+
if (sc.block) {
1260+
Block *inlined_block = sc.block->GetContainingInlinedBlock();
1261+
if (inlined_block) {
1262+
const InlineFunctionInfo *inlined_info =
1263+
inlined_block->GetInlinedFunctionInfo();
1264+
if (inlined_info)
1265+
name = inlined_info->GetName().AsCString();
1266+
}
1267+
}
1268+
1269+
if (name == nullptr) {
1270+
if (sc.function)
1271+
name = sc.function->GetName().GetCString();
1272+
}
1273+
1274+
if (name == nullptr) {
1275+
if (sc.symbol)
1276+
name = sc.symbol->GetName().GetCString();
1277+
}
1278+
1279+
return name;
1280+
}
1281+
1282+
const char *StackFrame::GetDisplayFunctionName() {
1283+
const char *name = nullptr;
1284+
SymbolContext sc = GetSymbolContext(
1285+
eSymbolContextFunction | eSymbolContextBlock | eSymbolContextSymbol);
1286+
if (sc.block) {
1287+
Block *inlined_block = sc.block->GetContainingInlinedBlock();
1288+
if (inlined_block) {
1289+
const InlineFunctionInfo *inlined_info =
1290+
inlined_block->GetInlinedFunctionInfo();
1291+
if (inlined_info)
1292+
name = inlined_info->GetDisplayName().AsCString();
1293+
}
1294+
}
1295+
1296+
if (name == nullptr) {
1297+
if (sc.function)
1298+
name = sc.function->GetDisplayName().GetCString();
1299+
}
1300+
1301+
if (name == nullptr) {
1302+
if (sc.symbol)
1303+
name = sc.symbol->GetDisplayName().GetCString();
1304+
}
1305+
return name;
1306+
}
1307+
12181308
SourceLanguage StackFrame::GetLanguage() {
12191309
CompileUnit *cu = GetSymbolContext(eSymbolContextCompUnit).comp_unit;
12201310
if (cu)

0 commit comments

Comments
 (0)