Skip to content

Commit 52e45a7

Browse files
authored
[lldb][Language] Change GetFunctionDisplayName to take SymbolContext by reference (llvm#135536)
Both the `CPlusPlusLanguage` plugins and the Swift language plugin already assume the `sc != nullptr`. And all `FormatEntity` callsites of `GetFunctionDisplayName` already check for nullptr before passing `sc`. This patch makes this pre-condition explicit by changing the parameter to `const SymbolContext &`. This will help with some upcoming changes in this area.
1 parent cbe8f3a commit 52e45a7

File tree

5 files changed

+12
-13
lines changed

5 files changed

+12
-13
lines changed

lldb/include/lldb/Target/Language.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ class Language : public PluginInterface {
268268
// the reference has never been assigned
269269
virtual bool IsUninitializedReference(ValueObject &valobj);
270270

271-
virtual bool GetFunctionDisplayName(const SymbolContext *sc,
271+
virtual bool GetFunctionDisplayName(const SymbolContext &sc,
272272
const ExecutionContext *exe_ctx,
273273
FunctionNameRepresentation representation,
274274
Stream &s);

lldb/source/Core/FormatEntity.cpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -1719,7 +1719,7 @@ bool FormatEntity::Format(const Entry &entry, Stream &s,
17191719

17201720
if (language_plugin)
17211721
language_plugin_handled = language_plugin->GetFunctionDisplayName(
1722-
sc, exe_ctx, Language::FunctionNameRepresentation::eName, ss);
1722+
*sc, exe_ctx, Language::FunctionNameRepresentation::eName, ss);
17231723

17241724
if (language_plugin_handled) {
17251725
s << ss.GetString();
@@ -1754,7 +1754,7 @@ bool FormatEntity::Format(const Entry &entry, Stream &s,
17541754

17551755
if (language_plugin)
17561756
language_plugin_handled = language_plugin->GetFunctionDisplayName(
1757-
sc, exe_ctx, Language::FunctionNameRepresentation::eNameWithNoArgs,
1757+
*sc, exe_ctx, Language::FunctionNameRepresentation::eNameWithNoArgs,
17581758
ss);
17591759

17601760
if (language_plugin_handled) {
@@ -1789,7 +1789,8 @@ bool FormatEntity::Format(const Entry &entry, Stream &s,
17891789

17901790
if (language_plugin)
17911791
language_plugin_handled = language_plugin->GetFunctionDisplayName(
1792-
sc, exe_ctx, Language::FunctionNameRepresentation::eNameWithArgs, ss);
1792+
*sc, exe_ctx, Language::FunctionNameRepresentation::eNameWithArgs,
1793+
ss);
17931794

17941795
if (language_plugin_handled) {
17951796
s << ss.GetString();

lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp

+5-7
Original file line numberDiff line numberDiff line change
@@ -1757,20 +1757,18 @@ static bool PrintFunctionNameWithArgs(Stream &s,
17571757
}
17581758

17591759
bool CPlusPlusLanguage::GetFunctionDisplayName(
1760-
const SymbolContext *sc, const ExecutionContext *exe_ctx,
1760+
const SymbolContext &sc, const ExecutionContext *exe_ctx,
17611761
FunctionNameRepresentation representation, Stream &s) {
17621762
switch (representation) {
17631763
case FunctionNameRepresentation::eNameWithArgs: {
1764-
assert(sc);
1765-
17661764
// Print the function name with arguments in it
1767-
if (sc->function)
1768-
return PrintFunctionNameWithArgs(s, exe_ctx, *sc);
1765+
if (sc.function)
1766+
return PrintFunctionNameWithArgs(s, exe_ctx, sc);
17691767

1770-
if (!sc->symbol)
1768+
if (!sc.symbol)
17711769
return false;
17721770

1773-
const char *cstr = sc->symbol->GetName().AsCString(nullptr);
1771+
const char *cstr = sc.symbol->GetName().AsCString(nullptr);
17741772
if (!cstr)
17751773
return false;
17761774

lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ class CPlusPlusLanguage : public Language {
138138
ConstString
139139
GetDemangledFunctionNameWithoutArguments(Mangled mangled) const override;
140140

141-
bool GetFunctionDisplayName(const SymbolContext *sc,
141+
bool GetFunctionDisplayName(const SymbolContext &sc,
142142
const ExecutionContext *exe_ctx,
143143
FunctionNameRepresentation representation,
144144
Stream &s) override;

lldb/source/Target/Language.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,7 @@ bool Language::IsNilReference(ValueObject &valobj) { return false; }
510510

511511
bool Language::IsUninitializedReference(ValueObject &valobj) { return false; }
512512

513-
bool Language::GetFunctionDisplayName(const SymbolContext *sc,
513+
bool Language::GetFunctionDisplayName(const SymbolContext &sc,
514514
const ExecutionContext *exe_ctx,
515515
FunctionNameRepresentation representation,
516516
Stream &s) {

0 commit comments

Comments
 (0)