Skip to content

Commit 311809c

Browse files
tromeycuviper
authored andcommitted
Add Rust support to Mangled
This adds Rust support to Mangled. I am not completely certain that this is needed (or alternatively that it does enough, maybe Mangled::GuessLanguage needs a Rust case). This should be checked before attempting to upstream.
1 parent cf62c6b commit 311809c

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

lldb/source/Core/Mangled.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,35 @@ get_demangled_name_without_arguments(ConstString mangled,
124124
return g_last_mangled;
125125
}
126126

127+
static void remove_rust_hash(char *str) {
128+
char *iter = str + strlen(str) - 1;
129+
size_t hashcount = 0;
130+
while (true) {
131+
if (iter == str) {
132+
// Hit the start of the string too early.
133+
return;
134+
}
135+
if ((*iter >= '0' && *iter <= '9') ||
136+
(*iter >= 'a' && *iter <= 'f')) {
137+
++hashcount;
138+
--iter;
139+
if (hashcount > 16) {
140+
// Too many hash chars.
141+
return;
142+
}
143+
} else {
144+
// Not a hash char.
145+
break;
146+
}
147+
}
148+
if (*iter != 'h' || hashcount < 5 || str + 2 >= iter ||
149+
iter[-1] != ':' || iter[-2] != ':') {
150+
return;
151+
}
152+
iter[-2] = '\0';
153+
}
154+
155+
127156
#pragma mark Mangled
128157
//----------------------------------------------------------------------
129158
// Default constructor
@@ -387,6 +416,11 @@ Mangled::GetDemangledName(lldb::LanguageType language) const {
387416
break;
388417
case eManglingSchemeItanium: {
389418
demangled_name = GetItaniumDemangledStr(mangled_name);
419+
420+
if (language == lldb::eLanguageTypeRust) {
421+
remove_rust_hash(demangled_name);
422+
}
423+
390424
break;
391425
}
392426
case eManglingSchemeNone:

0 commit comments

Comments
 (0)