Skip to content

Commit 9c7701f

Browse files
authored
[lldb/API] Hoist some of SBFrame logic to lldb_private::StackFrame (NFC) (#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]>
1 parent b3134fa commit 9c7701f

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
@@ -408,6 +408,18 @@ class StackFrame : public ExecutionContextScope,
408408
/// system implementation details this way.
409409
bool IsHidden();
410410

411+
/// Get the frame's demangled name.
412+
///
413+
/// /// \return
414+
/// A C-String containing the function demangled name. Can be null.
415+
const char *GetFunctionName();
416+
417+
/// Get the frame's demangled display name.
418+
///
419+
/// /// \return
420+
/// A C-String containing the function demangled display name. Can be null.
421+
const char *GetDisplayFunctionName();
422+
411423
/// Query this frame to find what frame it is in this Thread's
412424
/// StackFrameList.
413425
///

lldb/source/API/SBFrame.cpp

Lines changed: 6 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1173,12 +1173,8 @@ bool SBFrame::IsInlined() const {
11731173
Process::StopLocker stop_locker;
11741174
if (stop_locker.TryLock(&process->GetRunLock())) {
11751175
frame = exe_ctx.GetFramePtr();
1176-
if (frame) {
1177-
1178-
Block *block = frame->GetSymbolContext(eSymbolContextBlock).block;
1179-
if (block)
1180-
return block->GetContainingInlinedBlock() != nullptr;
1181-
}
1176+
if (frame)
1177+
return frame->IsInlined();
11821178
}
11831179
}
11841180
return false;
@@ -1255,29 +1251,8 @@ const char *SBFrame::GetFunctionName() const {
12551251
Process::StopLocker stop_locker;
12561252
if (stop_locker.TryLock(&process->GetRunLock())) {
12571253
frame = exe_ctx.GetFramePtr();
1258-
if (frame) {
1259-
SymbolContext sc(frame->GetSymbolContext(eSymbolContextFunction |
1260-
eSymbolContextBlock |
1261-
eSymbolContextSymbol));
1262-
if (sc.block) {
1263-
Block *inlined_block = sc.block->GetContainingInlinedBlock();
1264-
if (inlined_block) {
1265-
const InlineFunctionInfo *inlined_info =
1266-
inlined_block->GetInlinedFunctionInfo();
1267-
name = inlined_info->GetName().AsCString();
1268-
}
1269-
}
1270-
1271-
if (name == nullptr) {
1272-
if (sc.function)
1273-
name = sc.function->GetName().GetCString();
1274-
}
1275-
1276-
if (name == nullptr) {
1277-
if (sc.symbol)
1278-
name = sc.symbol->GetName().GetCString();
1279-
}
1280-
}
1254+
if (frame)
1255+
return frame->GetFunctionName();
12811256
}
12821257
}
12831258
return name;
@@ -1298,29 +1273,8 @@ const char *SBFrame::GetDisplayFunctionName() {
12981273
Process::StopLocker stop_locker;
12991274
if (stop_locker.TryLock(&process->GetRunLock())) {
13001275
frame = exe_ctx.GetFramePtr();
1301-
if (frame) {
1302-
SymbolContext sc(frame->GetSymbolContext(eSymbolContextFunction |
1303-
eSymbolContextBlock |
1304-
eSymbolContextSymbol));
1305-
if (sc.block) {
1306-
Block *inlined_block = sc.block->GetContainingInlinedBlock();
1307-
if (inlined_block) {
1308-
const InlineFunctionInfo *inlined_info =
1309-
inlined_block->GetInlinedFunctionInfo();
1310-
name = inlined_info->GetDisplayName().AsCString();
1311-
}
1312-
}
1313-
1314-
if (name == nullptr) {
1315-
if (sc.function)
1316-
name = sc.function->GetDisplayName().GetCString();
1317-
}
1318-
1319-
if (name == nullptr) {
1320-
if (sc.symbol)
1321-
name = sc.symbol->GetDisplayName().GetCString();
1322-
}
1323-
}
1276+
if (frame)
1277+
return frame->GetDisplayFunctionName();
13241278
}
13251279
}
13261280
return name;

lldb/source/Target/StackFrame.cpp

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1230,6 +1230,57 @@ bool StackFrame::IsHidden() {
12301230
return false;
12311231
}
12321232

1233+
const char *StackFrame::GetFunctionName() {
1234+
const char *name = nullptr;
1235+
SymbolContext sc = GetSymbolContext(
1236+
eSymbolContextFunction | eSymbolContextBlock | eSymbolContextSymbol);
1237+
if (sc.block) {
1238+
Block *inlined_block = sc.block->GetContainingInlinedBlock();
1239+
if (inlined_block) {
1240+
const InlineFunctionInfo *inlined_info =
1241+
inlined_block->GetInlinedFunctionInfo();
1242+
name = inlined_info->GetName().AsCString();
1243+
}
1244+
}
1245+
1246+
if (name == nullptr) {
1247+
if (sc.function)
1248+
name = sc.function->GetName().GetCString();
1249+
}
1250+
1251+
if (name == nullptr) {
1252+
if (sc.symbol)
1253+
name = sc.symbol->GetName().GetCString();
1254+
}
1255+
1256+
return name;
1257+
}
1258+
1259+
const char *StackFrame::GetDisplayFunctionName() {
1260+
const char *name = nullptr;
1261+
SymbolContext sc = GetSymbolContext(
1262+
eSymbolContextFunction | eSymbolContextBlock | eSymbolContextSymbol);
1263+
if (sc.block) {
1264+
Block *inlined_block = sc.block->GetContainingInlinedBlock();
1265+
if (inlined_block) {
1266+
const InlineFunctionInfo *inlined_info =
1267+
inlined_block->GetInlinedFunctionInfo();
1268+
name = inlined_info->GetDisplayName().AsCString();
1269+
}
1270+
}
1271+
1272+
if (name == nullptr) {
1273+
if (sc.function)
1274+
name = sc.function->GetDisplayName().GetCString();
1275+
}
1276+
1277+
if (name == nullptr) {
1278+
if (sc.symbol)
1279+
name = sc.symbol->GetDisplayName().GetCString();
1280+
}
1281+
return name;
1282+
}
1283+
12331284
SourceLanguage StackFrame::GetLanguage() {
12341285
CompileUnit *cu = GetSymbolContext(eSymbolContextCompUnit).comp_unit;
12351286
if (cu)

0 commit comments

Comments
 (0)