Skip to content

Commit 0317605

Browse files
committed
[lldb][Language] Pass SymbolNameFitsToLanguage parameter by const-ref (llvm#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 (cherry picked from commit 0f4dc93)
1 parent a4d76da commit 0317605

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
@@ -326,7 +326,9 @@ class Language : public PluginInterface {
326326
///
327327
/// This function should only return true if there is a high confidence
328328
/// that the name actually belongs to this language.
329-
virtual bool SymbolNameFitsToLanguage(Mangled name) const { return false; }
329+
virtual bool SymbolNameFitsToLanguage(const Mangled &name) const {
330+
return false;
331+
}
330332

331333
/// An individual data formatter may apply to several types and cross language
332334
/// 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
@@ -102,7 +102,7 @@ CPlusPlusLanguage::GetFunctionNameInfo(ConstString name) const {
102102
return {func_name_type, ConstString(basename)};
103103
}
104104

105-
bool CPlusPlusLanguage::SymbolNameFitsToLanguage(Mangled mangled) const {
105+
bool CPlusPlusLanguage::SymbolNameFitsToLanguage(const Mangled &mangled) const {
106106
auto mangling_scheme =
107107
Mangled::GetManglingScheme(mangled.GetMangledName().GetStringRef());
108108
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)