Skip to content

Commit 0f4dc93

Browse files
authored
[lldb][Language] Pass SymbolNameFitsToLanguage parameter by const-ref (#167684)
We've been seeing (rare) crashes from both `CPlusPlusLanguage::SymbolNameFitsToLanguage` and `ObjCLanguage::SymbolNameFitsToLanguage` when we try to read contents of the `ConstString`s of the `Mangled` parameter. I'm not entirely sure how that can happen (current theory is corrupted stack somehow which overwrites `ConstString::m_string` to an invalid pointer) but I'm not able to confirm that. One thing these crashes had in common is that they operate on the `Mangled` object we copied into `SymbolNameFitsToLanguage` by value. While I can't see off the top why that would cause it to contain unintiailized/corrupt `ConstString`s, the class is sufficiently large enough to probably pass it by `const &` anyway. This is what this patch does. rdar://164519648
1 parent c5eb7eb commit 0f4dc93

File tree

5 files changed

+7
-5
lines changed

5 files changed

+7
-5
lines changed

lldb/include/lldb/Target/Language.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,9 @@ class Language : public PluginInterface {
318318
///
319319
/// This function should only return true if there is a high confidence
320320
/// that the name actually belongs to this language.
321-
virtual bool SymbolNameFitsToLanguage(Mangled name) const { return false; }
321+
virtual bool SymbolNameFitsToLanguage(const Mangled &name) const {
322+
return false;
323+
}
322324

323325
/// An individual data formatter may apply to several types and cross language
324326
/// boundaries. Each of those languages may want to customize the display of

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ CPlusPlusLanguage::GetFunctionNameInfo(ConstString name) const {
103103
return {func_name_type, ConstString(basename)};
104104
}
105105

106-
bool CPlusPlusLanguage::SymbolNameFitsToLanguage(Mangled mangled) const {
106+
bool CPlusPlusLanguage::SymbolNameFitsToLanguage(const Mangled &mangled) const {
107107
auto mangling_scheme =
108108
Mangled::GetManglingScheme(mangled.GetMangledName().GetStringRef());
109109
return mangling_scheme == Mangled::eManglingSchemeItanium ||

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ class CPlusPlusLanguage : public Language {
9292

9393
static llvm::StringRef GetPluginNameStatic() { return "cplusplus"; }
9494

95-
bool SymbolNameFitsToLanguage(Mangled mangled) const override;
95+
bool SymbolNameFitsToLanguage(const Mangled &mangled) const override;
9696

9797
bool DemangledNameContainsPath(llvm::StringRef path,
9898
ConstString demangled) const override;

lldb/source/Plugins/Language/ObjC/ObjCLanguage.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ ObjCLanguage::GetFunctionNameInfo(ConstString name) const {
235235
return {func_name_type, std::nullopt};
236236
}
237237

238-
bool ObjCLanguage::SymbolNameFitsToLanguage(Mangled mangled) const {
238+
bool ObjCLanguage::SymbolNameFitsToLanguage(const Mangled &mangled) const {
239239
ConstString demangled_name = mangled.GetDemangledName();
240240
if (!demangled_name)
241241
return false;

lldb/source/Plugins/Language/ObjC/ObjCLanguage.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ class ObjCLanguage : public Language {
145145
std::pair<lldb::FunctionNameType, std::optional<ConstString>>
146146
GetFunctionNameInfo(ConstString name) const override;
147147

148-
bool SymbolNameFitsToLanguage(Mangled mangled) const override;
148+
bool SymbolNameFitsToLanguage(const Mangled &mangled) const override;
149149

150150
lldb::TypeCategoryImplSP GetFormatters() override;
151151

0 commit comments

Comments
 (0)