mirror of
https://github.com/RPCS3/llvm.git
synced 2024-12-03 17:32:59 +00:00
[llvm-undname Add an option to dump back references.
This is useful for understanding how our demangler processes back references and for investigating issues related to back references. But it's a feature only useful for debugging the demangling process itself, so I'm marking it hidden. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@338609 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
5999ebb85c
commit
39fff69697
@ -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
|
||||
|
@ -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;
|
||||
|
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user