Skip to content

Commit 5b6b0c9

Browse files
committed
[lldb/API] Hoist some of SBFrame logic to lldb_private::StackFrame (NFC) (llvm#116298)
This patch moves some of the logic implemented in the SBFrame APIs to the lldb_private::StackFrame class so it can be re-used elsewhere. Signed-off-by: Med Ismail Bennani <[email protected]> (cherry picked from commit 9c7701f)
1 parent fec1308 commit 5b6b0c9

File tree

3 files changed

+69
-52
lines changed

3 files changed

+69
-52
lines changed

lldb/include/lldb/Target/StackFrame.h

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

415+
/// Get the frame's demangled name.
416+
///
417+
/// /// \return
418+
/// A C-String containing the function demangled name. Can be null.
419+
const char *GetFunctionName();
420+
421+
/// Get the frame's demangled display name.
422+
///
423+
/// /// \return
424+
/// A C-String containing the function demangled display name. Can be null.
425+
const char *GetDisplayFunctionName();
426+
415427
/// Query this frame to find what frame it is in this Thread's
416428
/// StackFrameList.
417429
///

lldb/source/API/SBFrame.cpp

Lines changed: 6 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1182,12 +1182,8 @@ bool SBFrame::IsInlined() const {
11821182
Process::StopLocker stop_locker;
11831183
if (stop_locker.TryLock(&process->GetRunLock())) {
11841184
frame = exe_ctx.GetFramePtr();
1185-
if (frame) {
1186-
1187-
Block *block = frame->GetSymbolContext(eSymbolContextBlock).block;
1188-
if (block)
1189-
return block->GetContainingInlinedBlock() != nullptr;
1190-
}
1185+
if (frame)
1186+
return frame->IsInlined();
11911187
}
11921188
}
11931189
return false;
@@ -1305,29 +1301,8 @@ const char *SBFrame::GetFunctionName() const {
13051301
Process::StopLocker stop_locker;
13061302
if (stop_locker.TryLock(&process->GetRunLock())) {
13071303
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-
}
1304+
if (frame)
1305+
return frame->GetFunctionName();
13311306
}
13321307
}
13331308
return name;
@@ -1348,29 +1323,8 @@ const char *SBFrame::GetDisplayFunctionName() {
13481323
Process::StopLocker stop_locker;
13491324
if (stop_locker.TryLock(&process->GetRunLock())) {
13501325
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-
}
1326+
if (frame)
1327+
return frame->GetDisplayFunctionName();
13741328
}
13751329
}
13761330
return name;

lldb/source/Target/StackFrame.cpp

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1215,6 +1215,57 @@ bool StackFrame::IsHidden() {
12151215
return false;
12161216
}
12171217

1218+
const char *StackFrame::GetFunctionName() {
1219+
const char *name = nullptr;
1220+
SymbolContext sc = GetSymbolContext(
1221+
eSymbolContextFunction | eSymbolContextBlock | eSymbolContextSymbol);
1222+
if (sc.block) {
1223+
Block *inlined_block = sc.block->GetContainingInlinedBlock();
1224+
if (inlined_block) {
1225+
const InlineFunctionInfo *inlined_info =
1226+
inlined_block->GetInlinedFunctionInfo();
1227+
name = inlined_info->GetName().AsCString();
1228+
}
1229+
}
1230+
1231+
if (name == nullptr) {
1232+
if (sc.function)
1233+
name = sc.function->GetName().GetCString();
1234+
}
1235+
1236+
if (name == nullptr) {
1237+
if (sc.symbol)
1238+
name = sc.symbol->GetName().GetCString();
1239+
}
1240+
1241+
return name;
1242+
}
1243+
1244+
const char *StackFrame::GetDisplayFunctionName() {
1245+
const char *name = nullptr;
1246+
SymbolContext sc = GetSymbolContext(
1247+
eSymbolContextFunction | eSymbolContextBlock | eSymbolContextSymbol);
1248+
if (sc.block) {
1249+
Block *inlined_block = sc.block->GetContainingInlinedBlock();
1250+
if (inlined_block) {
1251+
const InlineFunctionInfo *inlined_info =
1252+
inlined_block->GetInlinedFunctionInfo();
1253+
name = inlined_info->GetDisplayName().AsCString();
1254+
}
1255+
}
1256+
1257+
if (name == nullptr) {
1258+
if (sc.function)
1259+
name = sc.function->GetDisplayName().GetCString();
1260+
}
1261+
1262+
if (name == nullptr) {
1263+
if (sc.symbol)
1264+
name = sc.symbol->GetDisplayName().GetCString();
1265+
}
1266+
return name;
1267+
}
1268+
12181269
SourceLanguage StackFrame::GetLanguage() {
12191270
CompileUnit *cu = GetSymbolContext(eSymbolContextCompUnit).comp_unit;
12201271
if (cu)

0 commit comments

Comments
 (0)