Avoid calling demangler for non-C++ symbols on Linux

Bogus demangler warnings should be suppressed on both Mac and Linux
platforms, so there is no reason to keep this filter behind __APPLE__ gate.

Bug: chromium:1062556
Change-Id: Idf28db0b527c3cd6dd91510fcf7d9040aaa64694
Reviewed-on: https://chromium-review.googlesource.com/c/breakpad/breakpad/+/2210684
Reviewed-by: Mark Mentovai <mark@chromium.org>
This commit is contained in:
Mikhail Borisov 2020-05-26 21:44:01 +03:00 committed by Mark Mentovai
parent 2ffe116322
commit f2679262ac

View file

@ -79,17 +79,12 @@ class CPPLanguage: public Language {
demangled->clear();
return kDontDemangle;
#else
#if defined(__APPLE__)
// Mac C++ symbols can have up to 4 underscores, followed by a "Z".
// Non-C++ symbols are not coded that way, but may have leading underscores.
// Attempting to demangle non-C++ symbols with the C++ demangler would print
// warnings and fail, so return kDontDemangle for these.
size_t i = mangled.find_first_not_of('_');
if (i == 0 || i == string::npos || i > 4 || mangled[i] != 'Z') {
if (!IsMangledName(mangled)) {
demangled->clear();
return kDontDemangle;
}
#endif
int status;
char* demangled_c =
@ -109,6 +104,21 @@ class CPPLanguage: public Language {
}
return result;
#endif
}
private:
static bool IsMangledName(const string &name) {
// NOTE: For proper cross-compilation support, this should depend on target
// binary's platform, not current build platform.
#if defined(__APPLE__)
// Mac C++ symbols can have up to 4 underscores, followed by a "Z".
// Non-C++ symbols are not coded that way, but may have leading underscores.
size_t i = name.find_first_not_of('_');
return i > 0 && i != string::npos && i <= 4 && name[i] == 'Z';
#else
// Linux C++ symbols always start with "_Z".
return name.size() > 2 && name[0] == '_' && name[1] == 'Z';
#endif
}
};