Skip to content

Commit 3ddde4c

Browse files
committed
[lldb][Format] Introduce new frame-format variables for function parts (llvm#131836)
Adds new frame-format variables and implements them in the CPlusPlusLanguage plugin. We use the `DemangledNameInfo` type to retrieve the necessary part of the demangled name. llvm#131836 (cherry picked from commit 8b91b44)
1 parent 268253b commit 3ddde4c

20 files changed

+717
-30
lines changed

lldb/include/lldb/Core/FormatEntity.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,13 @@ struct Entry {
8888
FunctionNameWithArgs,
8989
FunctionNameNoArgs,
9090
FunctionMangledName,
91+
FunctionScope,
92+
FunctionBasename,
93+
FunctionTemplateArguments,
94+
FunctionFormattedArguments,
95+
FunctionReturnLeft,
96+
FunctionReturnRight,
97+
FunctionQualifiers,
9198
FunctionAddrOffset,
9299
FunctionAddrOffsetConcrete,
93100
FunctionLineOffset,

lldb/include/lldb/Symbol/SymbolContext.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -313,8 +313,7 @@ class SymbolContext {
313313
/// mangling preference. If this object represents an inlined function,
314314
/// returns the name of the inlined function. Returns nullptr if no function
315315
/// name could be determined.
316-
const char *GetPossiblyInlinedFunctionName(
317-
Mangled::NamePreference mangling_preference) const;
316+
Mangled GetPossiblyInlinedFunctionName() const;
318317

319318
// Member variables
320319
lldb::TargetSP target_sp; ///< The Target for a given query

lldb/include/lldb/Target/Language.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <set>
1616
#include <vector>
1717

18+
#include "lldb/Core/FormatEntity.h"
1819
#include "lldb/Core/Highlighter.h"
1920
#include "lldb/Core/PluginInterface.h"
2021
#include "lldb/DataFormatters/DumpValueObjectOptions.h"
@@ -275,6 +276,13 @@ class Language : public PluginInterface {
275276
FunctionNameRepresentation representation,
276277
Stream &s);
277278

279+
virtual bool HandleFrameFormatVariable(const SymbolContext &sc,
280+
const ExecutionContext *exe_ctx,
281+
FormatEntity::Entry::Type type,
282+
Stream &s) {
283+
return false;
284+
}
285+
278286
virtual ConstString
279287
GetDemangledFunctionNameWithoutArguments(Mangled mangled) const {
280288
if (ConstString demangled = mangled.GetDemangledName())

lldb/source/Core/FormatEntity.cpp

Lines changed: 50 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,15 @@ constexpr Definition g_function_child_entries[] = {
122122
Definition("pc-offset", EntryType::FunctionPCOffset),
123123
Definition("initial-function", EntryType::FunctionInitial),
124124
Definition("changed", EntryType::FunctionChanged),
125-
Definition("is-optimized", EntryType::FunctionIsOptimized)};
125+
Definition("is-optimized", EntryType::FunctionIsOptimized),
126+
Definition("scope", EntryType::FunctionScope),
127+
Definition("basename", EntryType::FunctionBasename),
128+
Definition("template-arguments", EntryType::FunctionTemplateArguments),
129+
Definition("formatted-arguments", EntryType::FunctionFormattedArguments),
130+
Definition("return-left", EntryType::FunctionReturnLeft),
131+
Definition("return-right", EntryType::FunctionReturnRight),
132+
Definition("qualifiers", EntryType::FunctionQualifiers),
133+
};
126134

127135
constexpr Definition g_line_child_entries[] = {
128136
Entry::DefinitionWithChildren("file", EntryType::LineEntryFile,
@@ -353,6 +361,13 @@ const char *FormatEntity::Entry::TypeToCString(Type t) {
353361
ENUM_TO_CSTR(FunctionNameWithArgs);
354362
ENUM_TO_CSTR(FunctionNameNoArgs);
355363
ENUM_TO_CSTR(FunctionMangledName);
364+
ENUM_TO_CSTR(FunctionScope);
365+
ENUM_TO_CSTR(FunctionBasename);
366+
ENUM_TO_CSTR(FunctionTemplateArguments);
367+
ENUM_TO_CSTR(FunctionFormattedArguments);
368+
ENUM_TO_CSTR(FunctionReturnLeft);
369+
ENUM_TO_CSTR(FunctionReturnRight);
370+
ENUM_TO_CSTR(FunctionQualifiers);
356371
ENUM_TO_CSTR(FunctionAddrOffset);
357372
ENUM_TO_CSTR(FunctionAddrOffsetConcrete);
358373
ENUM_TO_CSTR(FunctionLineOffset);
@@ -1167,8 +1182,9 @@ static bool PrintFunctionNameWithArgs(Stream &s,
11671182
ExecutionContextScope *exe_scope =
11681183
exe_ctx ? exe_ctx->GetBestExecutionContextScope() : nullptr;
11691184

1170-
const char *cstr =
1171-
sc.GetPossiblyInlinedFunctionName(Mangled::ePreferDemangled);
1185+
const char *cstr = sc.GetPossiblyInlinedFunctionName()
1186+
.GetName(Mangled::ePreferDemangled)
1187+
.AsCString();
11721188
if (!cstr)
11731189
return false;
11741190

@@ -1186,7 +1202,8 @@ static bool PrintFunctionNameWithArgs(Stream &s,
11861202
return true;
11871203
}
11881204

1189-
static bool HandleFunctionNameWithArgs(Stream &s,const ExecutionContext *exe_ctx,
1205+
static bool HandleFunctionNameWithArgs(Stream &s,
1206+
const ExecutionContext *exe_ctx,
11901207
const SymbolContext &sc) {
11911208
Language *language_plugin = nullptr;
11921209
bool language_plugin_handled = false;
@@ -1719,8 +1736,9 @@ bool FormatEntity::Format(const Entry &entry, Stream &s,
17191736
return true;
17201737
}
17211738

1722-
const char *name = sc->GetPossiblyInlinedFunctionName(
1723-
Mangled::NamePreference::ePreferDemangled);
1739+
const char *name = sc->GetPossiblyInlinedFunctionName()
1740+
.GetName(Mangled::NamePreference::ePreferDemangled)
1741+
.AsCString();
17241742
if (!name)
17251743
return false;
17261744

@@ -1751,8 +1769,10 @@ bool FormatEntity::Format(const Entry &entry, Stream &s,
17511769
return true;
17521770
}
17531771

1754-
const char *name = sc->GetPossiblyInlinedFunctionName(
1755-
Mangled::NamePreference::ePreferDemangledWithoutArguments);
1772+
const char *name =
1773+
sc->GetPossiblyInlinedFunctionName()
1774+
.GetName(Mangled::NamePreference::ePreferDemangledWithoutArguments)
1775+
.AsCString();
17561776
if (!name)
17571777
return false;
17581778

@@ -1761,19 +1781,38 @@ bool FormatEntity::Format(const Entry &entry, Stream &s,
17611781
return true;
17621782
}
17631783

1784+
case Entry::Type::FunctionScope:
1785+
case Entry::Type::FunctionBasename:
1786+
case Entry::Type::FunctionTemplateArguments:
1787+
case Entry::Type::FunctionFormattedArguments:
1788+
case Entry::Type::FunctionReturnRight:
1789+
case Entry::Type::FunctionReturnLeft:
1790+
case Entry::Type::FunctionQualifiers: {
1791+
if (!sc->function)
1792+
return false;
1793+
1794+
Language *language_plugin =
1795+
Language::FindPlugin(sc->function->GetLanguage());
1796+
if (!language_plugin)
1797+
return false;
1798+
1799+
return language_plugin->HandleFrameFormatVariable(*sc, exe_ctx, entry.type,
1800+
s);
1801+
}
1802+
17641803
case Entry::Type::FunctionNameWithArgs: {
17651804
if (!sc)
17661805
return false;
17671806

17681807
return HandleFunctionNameWithArgs(s, exe_ctx, *sc);
17691808
}
1770-
17711809
case Entry::Type::FunctionMangledName: {
17721810
if (!sc)
17731811
return false;
17741812

1775-
const char *name = sc->GetPossiblyInlinedFunctionName(
1776-
Mangled::NamePreference::ePreferMangled);
1813+
const char *name = sc->GetPossiblyInlinedFunctionName()
1814+
.GetName(Mangled::NamePreference::ePreferMangled)
1815+
.AsCString();
17771816
if (!name)
17781817
return false;
17791818

0 commit comments

Comments
 (0)