Skip to content

Commit 77e2d36

Browse files
committed
[lldb] Introduce new frame-format variables for function parts
1 parent c68dab5 commit 77e2d36

18 files changed

+764
-53
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+
FunctionArguments,
95+
FunctionReturnLeft,
96+
FunctionReturnRight,
97+
FunctionQualifiers,
9198
FunctionAddrOffset,
9299
FunctionAddrOffsetConcrete,
93100
FunctionLineOffset,

lldb/include/lldb/Core/PluginManager.h

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,10 @@ class PluginManager {
141141
GetOperatingSystemCreateCallbackForPluginName(llvm::StringRef name);
142142

143143
// Language
144-
static bool RegisterPlugin(llvm::StringRef name, llvm::StringRef description,
145-
LanguageCreateInstance create_callback);
144+
static bool
145+
RegisterPlugin(llvm::StringRef name, llvm::StringRef description,
146+
LanguageCreateInstance create_callback,
147+
DebuggerInitializeCallback debugger_init_callback = nullptr);
146148

147149
static bool UnregisterPlugin(LanguageCreateInstance create_callback);
148150

@@ -613,6 +615,14 @@ class PluginManager {
613615
static bool CreateSettingForStructuredDataPlugin(
614616
Debugger &debugger, const lldb::OptionValuePropertiesSP &properties_sp,
615617
llvm::StringRef description, bool is_global_property);
618+
619+
static lldb::OptionValuePropertiesSP
620+
GetSettingForCPlusPlusLanguagePlugin(Debugger &debugger,
621+
llvm::StringRef setting_name);
622+
623+
static bool CreateSettingForCPlusPlusLanguagePlugin(
624+
Debugger &debugger, const lldb::OptionValuePropertiesSP &properties_sp,
625+
llvm::StringRef description, bool is_global_property);
616626
};
617627

618628
} // namespace lldb_private

lldb/include/lldb/Target/Language.h

Lines changed: 10 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"
@@ -273,6 +274,13 @@ class Language : public PluginInterface {
273274
FunctionNameRepresentation representation,
274275
Stream &s);
275276

277+
virtual bool HandleFrameFormatVariable(const SymbolContext &sc,
278+
const ExecutionContext *exe_ctx,
279+
FormatEntity::Entry::Type type,
280+
Stream &s) {
281+
return false;
282+
}
283+
276284
virtual ConstString
277285
GetDemangledFunctionNameWithoutArguments(Mangled mangled) const {
278286
if (ConstString demangled = mangled.GetDemangledName())
@@ -389,6 +397,8 @@ class Language : public PluginInterface {
389397
/// Python uses \b except. Defaults to \b catch.
390398
virtual llvm::StringRef GetCatchKeyword() const { return "catch"; }
391399

400+
virtual const FormatEntity::Entry *GetFrameFormat() const { return nullptr; }
401+
392402
protected:
393403
// Classes that inherit from Language can see and modify these
394404

lldb/source/Core/FormatEntity.cpp

Lines changed: 93 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,14 @@ 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("arguments", EntryType::FunctionArguments),
130+
Definition("return-left", EntryType::FunctionReturnLeft),
131+
Definition("return-right", EntryType::FunctionReturnRight),
132+
Definition("qualifiers", EntryType::FunctionQualifiers)};
126133

127134
constexpr Definition g_line_child_entries[] = {
128135
Entry::DefinitionWithChildren("file", EntryType::LineEntryFile,
@@ -352,6 +359,13 @@ const char *FormatEntity::Entry::TypeToCString(Type t) {
352359
ENUM_TO_CSTR(FunctionNameWithArgs);
353360
ENUM_TO_CSTR(FunctionNameNoArgs);
354361
ENUM_TO_CSTR(FunctionMangledName);
362+
ENUM_TO_CSTR(FunctionScope);
363+
ENUM_TO_CSTR(FunctionBasename);
364+
ENUM_TO_CSTR(FunctionTemplateArguments);
365+
ENUM_TO_CSTR(FunctionArguments);
366+
ENUM_TO_CSTR(FunctionReturnLeft);
367+
ENUM_TO_CSTR(FunctionReturnRight);
368+
ENUM_TO_CSTR(FunctionQualifiers);
355369
ENUM_TO_CSTR(FunctionAddrOffset);
356370
ENUM_TO_CSTR(FunctionAddrOffsetConcrete);
357371
ENUM_TO_CSTR(FunctionLineOffset);
@@ -1184,6 +1198,65 @@ static bool PrintFunctionNameWithArgs(Stream &s,
11841198
return true;
11851199
}
11861200

1201+
static bool FormatFunctionNameWithArgs(Stream &s, const SymbolContext *sc,
1202+
const ExecutionContext *exe_ctx) {
1203+
if (!sc)
1204+
return false;
1205+
1206+
Language *language_plugin = nullptr;
1207+
bool language_plugin_handled = false;
1208+
StreamString ss;
1209+
if (sc->function)
1210+
language_plugin = Language::FindPlugin(sc->function->GetLanguage());
1211+
else if (sc->symbol)
1212+
language_plugin = Language::FindPlugin(sc->symbol->GetLanguage());
1213+
1214+
if (language_plugin)
1215+
language_plugin_handled = language_plugin->GetFunctionDisplayName(
1216+
sc, exe_ctx, Language::FunctionNameRepresentation::eNameWithArgs, ss);
1217+
1218+
if (language_plugin_handled) {
1219+
s << ss.GetString();
1220+
return true;
1221+
}
1222+
1223+
if (sc->function)
1224+
return PrintFunctionNameWithArgs(s, exe_ctx, *sc);
1225+
1226+
if (!sc->symbol)
1227+
return false;
1228+
1229+
const char *cstr = sc->symbol->GetName().AsCString(nullptr);
1230+
if (!cstr)
1231+
return false;
1232+
1233+
s.PutCString(cstr);
1234+
return true;
1235+
}
1236+
1237+
static bool FormatFunctionNameForLanguage(Stream &s, const SymbolContext *sc,
1238+
const ExecutionContext *exe_ctx) {
1239+
if (!sc)
1240+
return false;
1241+
1242+
Language *language_plugin = nullptr;
1243+
if (sc->function)
1244+
language_plugin = Language::FindPlugin(sc->function->GetLanguage());
1245+
else if (sc->symbol)
1246+
language_plugin = Language::FindPlugin(sc->symbol->GetLanguage());
1247+
1248+
if (!language_plugin)
1249+
return false;
1250+
1251+
const auto *format = language_plugin->GetFrameFormat();
1252+
if (!format)
1253+
return false;
1254+
1255+
return FormatEntity::Format(*format, s, sc, exe_ctx, /*addr=*/nullptr,
1256+
/*valobj=*/nullptr, /*function_changed=*/false,
1257+
/*initial_function=*/false);
1258+
}
1259+
11871260
bool FormatEntity::FormatStringRef(const llvm::StringRef &format_str, Stream &s,
11881261
const SymbolContext *sc,
11891262
const ExecutionContext *exe_ctx,
@@ -1734,41 +1807,34 @@ bool FormatEntity::Format(const Entry &entry, Stream &s,
17341807
return true;
17351808
}
17361809

1737-
case Entry::Type::FunctionNameWithArgs: {
1810+
case Entry::Type::FunctionScope:
1811+
case Entry::Type::FunctionBasename:
1812+
case Entry::Type::FunctionTemplateArguments:
1813+
case Entry::Type::FunctionArguments:
1814+
case Entry::Type::FunctionReturnRight:
1815+
case Entry::Type::FunctionReturnLeft:
1816+
case Entry::Type::FunctionQualifiers: {
17381817
if (!sc)
17391818
return false;
17401819

1741-
Language *language_plugin = nullptr;
1742-
bool language_plugin_handled = false;
1743-
StreamString ss;
1744-
if (sc->function)
1745-
language_plugin = Language::FindPlugin(sc->function->GetLanguage());
1746-
else if (sc->symbol)
1747-
language_plugin = Language::FindPlugin(sc->symbol->GetLanguage());
1748-
1749-
if (language_plugin)
1750-
language_plugin_handled = language_plugin->GetFunctionDisplayName(
1751-
sc, exe_ctx, Language::FunctionNameRepresentation::eNameWithArgs, ss);
1752-
1753-
if (language_plugin_handled) {
1754-
s << ss.GetString();
1755-
return true;
1756-
}
1757-
1758-
if (sc->function)
1759-
return PrintFunctionNameWithArgs(s, exe_ctx, *sc);
1760-
1761-
if (!sc->symbol)
1820+
if (!sc->function)
17621821
return false;
17631822

1764-
const char *cstr = sc->symbol->GetName().AsCString(nullptr);
1765-
if (!cstr)
1823+
Language *language_plugin =
1824+
Language::FindPlugin(sc->function->GetLanguage());
1825+
if (!language_plugin)
17661826
return false;
17671827

1768-
s.PutCString(cstr);
1769-
return true;
1828+
return language_plugin->HandleFrameFormatVariable(*sc, exe_ctx, entry.type,
1829+
s);
17701830
}
17711831

1832+
case Entry::Type::FunctionNameWithArgs: {
1833+
if (FormatFunctionNameForLanguage(s, sc, exe_ctx))
1834+
return true;
1835+
1836+
return FormatFunctionNameWithArgs(s, sc, exe_ctx);
1837+
}
17721838
case Entry::Type::FunctionMangledName: {
17731839
if (!sc)
17741840
return false;

lldb/source/Core/PluginManager.cpp

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -564,11 +564,12 @@ static LanguageInstances &GetLanguageInstances() {
564564
return g_instances;
565565
}
566566

567-
bool PluginManager::RegisterPlugin(llvm::StringRef name,
568-
llvm::StringRef description,
569-
LanguageCreateInstance create_callback) {
570-
return GetLanguageInstances().RegisterPlugin(name, description,
571-
create_callback);
567+
bool PluginManager::RegisterPlugin(
568+
llvm::StringRef name, llvm::StringRef description,
569+
LanguageCreateInstance create_callback,
570+
DebuggerInitializeCallback debugger_init_callback) {
571+
return GetLanguageInstances().RegisterPlugin(
572+
name, description, create_callback, debugger_init_callback);
572573
}
573574

574575
bool PluginManager::UnregisterPlugin(LanguageCreateInstance create_callback) {
@@ -1682,6 +1683,7 @@ void PluginManager::DebuggerInitialize(Debugger &debugger) {
16821683
GetStructuredDataPluginInstances().PerformDebuggerCallback(debugger);
16831684
GetTracePluginInstances().PerformDebuggerCallback(debugger);
16841685
GetScriptedInterfaceInstances().PerformDebuggerCallback(debugger);
1686+
GetLanguageInstances().PerformDebuggerCallback(debugger);
16851687
}
16861688

16871689
// This is the preferred new way to register plugin specific settings. e.g.
@@ -1810,6 +1812,7 @@ static constexpr llvm::StringLiteral kSymbolLocatorPluginName("symbol-locator");
18101812
static constexpr llvm::StringLiteral kJITLoaderPluginName("jit-loader");
18111813
static constexpr llvm::StringLiteral
18121814
kStructuredDataPluginName("structured-data");
1815+
static constexpr llvm::StringLiteral kCPlusPlusLanguagePlugin("cplusplus");
18131816

18141817
lldb::OptionValuePropertiesSP
18151818
PluginManager::GetSettingForDynamicLoaderPlugin(Debugger &debugger,
@@ -1967,3 +1970,17 @@ bool PluginManager::CreateSettingForStructuredDataPlugin(
19671970
"Settings for structured data plug-ins",
19681971
properties_sp, description, is_global_property);
19691972
}
1973+
1974+
lldb::OptionValuePropertiesSP
1975+
PluginManager::GetSettingForCPlusPlusLanguagePlugin(
1976+
Debugger &debugger, llvm::StringRef setting_name) {
1977+
return GetSettingForPlugin(debugger, setting_name, kCPlusPlusLanguagePlugin);
1978+
}
1979+
1980+
bool PluginManager::CreateSettingForCPlusPlusLanguagePlugin(
1981+
Debugger &debugger, const lldb::OptionValuePropertiesSP &properties_sp,
1982+
llvm::StringRef description, bool is_global_property) {
1983+
return CreateSettingForPlugin(debugger, kCPlusPlusLanguagePlugin,
1984+
"Settings for CPlusPlus language plug-ins",
1985+
properties_sp, description, is_global_property);
1986+
}

lldb/source/Plugins/Language/CPlusPlus/CMakeLists.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
lldb_tablegen(LanguageCPlusPlusProperties.inc -gen-lldb-property-defs
2+
SOURCE LanguageCPlusPlusProperties.td
3+
TARGET LLDBPluginLanguageCPlusPlusPropertiesGen)
4+
5+
lldb_tablegen(LanguageCPlusPlusPropertiesEnum.inc -gen-lldb-property-enum-defs
6+
SOURCE LanguageCPlusPlusProperties.td
7+
TARGET LLDBPluginLanguageCPlusPlusPropertiesEnumGen)
8+
19
add_lldb_library(lldbPluginCPlusPlusLanguage PLUGIN
210
BlockPointer.cpp
311
Coroutines.cpp
@@ -41,3 +49,7 @@ add_lldb_library(lldbPluginCPlusPlusLanguage PLUGIN
4149
LINK_COMPONENTS
4250
Support
4351
)
52+
53+
add_dependencies(lldbPluginCPlusPlusLanguage
54+
LLDBPluginLanguageCPlusPlusPropertiesGen
55+
LLDBPluginLanguageCPlusPlusPropertiesEnumGen)

0 commit comments

Comments
 (0)