Skip to content

Commit 8cf7c19

Browse files
committed
[lldb] Introduce new frame-format variables for function parts
1 parent a0bb78d commit 8cf7c19

18 files changed

+910
-37
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);
@@ -1218,6 +1232,65 @@ static bool PrintFunctionNameWithArgs(Stream &s,
12181232
return true;
12191233
}
12201234

1235+
static bool FormatFunctionNameWithArgs(Stream &s, const SymbolContext *sc,
1236+
const ExecutionContext *exe_ctx) {
1237+
if (!sc)
1238+
return false;
1239+
1240+
Language *language_plugin = nullptr;
1241+
bool language_plugin_handled = false;
1242+
StreamString ss;
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+
language_plugin_handled = language_plugin->GetFunctionDisplayName(
1250+
sc, exe_ctx, Language::FunctionNameRepresentation::eNameWithArgs, ss);
1251+
1252+
if (language_plugin_handled) {
1253+
s << ss.GetString();
1254+
return true;
1255+
}
1256+
1257+
if (sc->function)
1258+
return PrintFunctionNameWithArgs(s, exe_ctx, *sc);
1259+
1260+
if (!sc->symbol)
1261+
return false;
1262+
1263+
const char *cstr = sc->symbol->GetName().AsCString(nullptr);
1264+
if (!cstr)
1265+
return false;
1266+
1267+
s.PutCString(cstr);
1268+
return true;
1269+
}
1270+
1271+
static bool FormatFunctionNameForLanguage(Stream &s, const SymbolContext *sc,
1272+
const ExecutionContext *exe_ctx) {
1273+
if (!sc)
1274+
return false;
1275+
1276+
Language *language_plugin = nullptr;
1277+
if (sc->function)
1278+
language_plugin = Language::FindPlugin(sc->function->GetLanguage());
1279+
else if (sc->symbol)
1280+
language_plugin = Language::FindPlugin(sc->symbol->GetLanguage());
1281+
1282+
if (!language_plugin)
1283+
return false;
1284+
1285+
const auto *format = language_plugin->GetFrameFormat();
1286+
if (!format)
1287+
return false;
1288+
1289+
return FormatEntity::Format(*format, s, sc, exe_ctx, /*addr=*/nullptr,
1290+
/*valobj=*/nullptr, /*function_changed=*/false,
1291+
/*initial_function=*/false);
1292+
}
1293+
12211294
bool FormatEntity::FormatStringRef(const llvm::StringRef &format_str, Stream &s,
12221295
const SymbolContext *sc,
12231296
const ExecutionContext *exe_ctx,
@@ -1775,41 +1848,34 @@ bool FormatEntity::Format(const Entry &entry, Stream &s,
17751848
}
17761849
return false;
17771850

1778-
case Entry::Type::FunctionNameWithArgs: {
1851+
case Entry::Type::FunctionScope:
1852+
case Entry::Type::FunctionBasename:
1853+
case Entry::Type::FunctionTemplateArguments:
1854+
case Entry::Type::FunctionArguments:
1855+
case Entry::Type::FunctionReturnRight:
1856+
case Entry::Type::FunctionReturnLeft:
1857+
case Entry::Type::FunctionQualifiers: {
17791858
if (!sc)
17801859
return false;
17811860

1782-
Language *language_plugin = nullptr;
1783-
bool language_plugin_handled = false;
1784-
StreamString ss;
1785-
if (sc->function)
1786-
language_plugin = Language::FindPlugin(sc->function->GetLanguage());
1787-
else if (sc->symbol)
1788-
language_plugin = Language::FindPlugin(sc->symbol->GetLanguage());
1789-
1790-
if (language_plugin)
1791-
language_plugin_handled = language_plugin->GetFunctionDisplayName(
1792-
sc, exe_ctx, Language::FunctionNameRepresentation::eNameWithArgs, ss);
1793-
1794-
if (language_plugin_handled) {
1795-
s << ss.GetString();
1796-
return true;
1797-
}
1798-
1799-
if (sc->function)
1800-
return PrintFunctionNameWithArgs(s, exe_ctx, *sc);
1801-
1802-
if (!sc->symbol)
1861+
if (!sc->function)
18031862
return false;
18041863

1805-
const char *cstr = sc->symbol->GetName().AsCString(nullptr);
1806-
if (!cstr)
1864+
Language *language_plugin =
1865+
Language::FindPlugin(sc->function->GetLanguage());
1866+
if (!language_plugin)
18071867
return false;
18081868

1809-
s.PutCString(cstr);
1810-
return true;
1869+
return language_plugin->HandleFrameFormatVariable(*sc, exe_ctx, entry.type,
1870+
s);
18111871
}
18121872

1873+
case Entry::Type::FunctionNameWithArgs: {
1874+
if (FormatFunctionNameForLanguage(s, sc, exe_ctx))
1875+
return true;
1876+
1877+
return FormatFunctionNameWithArgs(s, sc, exe_ctx);
1878+
}
18131879
case Entry::Type::FunctionMangledName: {
18141880
if (!sc)
18151881
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)