summaryrefslogtreecommitdiffstats
path: root/llvm
diff options
context:
space:
mode:
Diffstat (limited to 'llvm')
-rw-r--r--llvm/include/llvm/Demangle/Demangle.h4
-rw-r--r--llvm/lib/Demangle/MicrosoftDemangle.cpp35
-rw-r--r--llvm/tools/llvm-undname/llvm-undname.cpp10
3 files changed, 46 insertions, 3 deletions
diff --git a/llvm/include/llvm/Demangle/Demangle.h b/llvm/include/llvm/Demangle/Demangle.h
index df7753f23b8..27340b77aa2 100644
--- a/llvm/include/llvm/Demangle/Demangle.h
+++ b/llvm/include/llvm/Demangle/Demangle.h
@@ -27,8 +27,10 @@ enum : int {
char *itaniumDemangle(const char *mangled_name, char *buf, size_t *n,
int *status);
+
+enum MSDemangleFlags { MSDF_None = 0, MSDF_DumpBackrefs = 1 << 0 };
char *microsoftDemangle(const char *mangled_name, char *buf, size_t *n,
- int *status);
+ int *status, MSDemangleFlags Flags = MSDF_None);
/// "Partial" demangler. This supports demangling a string into an AST
/// (typically an intermediate stage in itaniumDemangle) and querying certain
diff --git a/llvm/lib/Demangle/MicrosoftDemangle.cpp b/llvm/lib/Demangle/MicrosoftDemangle.cpp
index 04575818422..9cf7c4bb127 100644
--- a/llvm/lib/Demangle/MicrosoftDemangle.cpp
+++ b/llvm/lib/Demangle/MicrosoftDemangle.cpp
@@ -878,6 +878,8 @@ public:
// True if an error occurred.
bool Error = false;
+ void dumpBackReferences();
+
private:
Type *demangleVariableEncoding(StringView &MangledName);
Type *demangleFunctionEncoding(StringView &MangledName);
@@ -2046,12 +2048,43 @@ void Demangler::output(const Symbol *S, OutputStream &OS) {
Type::outputPost(OS, *S->SymbolType);
}
+void Demangler::dumpBackReferences() {
+ printf("%d function parameter backreferences\n",
+ (int)FunctionParamBackRefCount);
+
+ // Create an output stream so we can render each type.
+ OutputStream OS = OutputStream::create(nullptr, 0, 1024);
+ for (size_t I = 0; I < FunctionParamBackRefCount; ++I) {
+ OS.setCurrentPosition(0);
+
+ Type *T = FunctionParamBackRefs[I];
+ Type::outputPre(OS, *T);
+ Type::outputPost(OS, *T);
+
+ printf(" [%d] - %*s\n", (int)I, (int)OS.getCurrentPosition(),
+ OS.getBuffer());
+ }
+ std::free(OS.getBuffer());
+
+ if (FunctionParamBackRefCount > 0)
+ printf("\n");
+ printf("%d name backreferences\n", (int)BackRefCount);
+ for (size_t I = 0; I < BackRefCount; ++I) {
+ printf(" [%d] - %*s\n", (int)I, (int)BackReferences[I].size(),
+ BackReferences[I].begin());
+ }
+ if (BackRefCount > 0)
+ printf("\n");
+}
+
char *llvm::microsoftDemangle(const char *MangledName, char *Buf, size_t *N,
- int *Status) {
+ int *Status, MSDemangleFlags Flags) {
Demangler D;
StringView Name{MangledName};
Symbol *S = D.parse(Name);
+ if (Flags & MSDF_DumpBackrefs)
+ D.dumpBackReferences();
OutputStream OS = OutputStream::create(Buf, N, 1024);
if (D.Error) {
OS << MangledName;
diff --git a/llvm/tools/llvm-undname/llvm-undname.cpp b/llvm/tools/llvm-undname/llvm-undname.cpp
index 2124ec16945..31d0590af2d 100644
--- a/llvm/tools/llvm-undname/llvm-undname.cpp
+++ b/llvm/tools/llvm-undname/llvm-undname.cpp
@@ -26,12 +26,20 @@
using namespace llvm;
+cl::opt<bool> DumpBackReferences("backrefs", cl::Optional,
+ cl::desc("dump backreferences"), cl::Hidden,
+ cl::init(false));
cl::list<std::string> Symbols(cl::Positional, cl::desc("<input symbols>"),
cl::ZeroOrMore);
static void demangle(const std::string &S) {
int Status;
- char *ResultBuf = microsoftDemangle(S.c_str(), nullptr, nullptr, &Status);
+ MSDemangleFlags Flags = MSDF_None;
+ if (DumpBackReferences)
+ Flags = MSDemangleFlags(Flags | MSDF_DumpBackrefs);
+
+ char *ResultBuf =
+ microsoftDemangle(S.c_str(), nullptr, nullptr, &Status, Flags);
if (Status == llvm::demangle_success) {
outs() << ResultBuf << "\n";
outs().flush();
OpenPOWER on IntegriCloud