mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-26 04:32:44 +01:00
[llvm-cxxfilt] Split and demangle stdin input
Summary: Originally, llvm-cxxfilt would treat a line as a single mangled item to be demangled. If a mangled name appears in the middle of that string, that name would not be demangled. GNU c++filt splits and demangles every word in a string that is piped to it via stdin. Prior to this patch llvm-cxxfilt would never split strings piped to it. This patch replicates the GNU behavior and splits strings that are piped to it via stdin. This fixes PR39990 Reviewers: compnerd, jhenderson, davide Reviewed By: compnerd, jhenderson Subscribers: erik.pilkington, jhenderson, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D57350 llvm-svn: 353743
This commit is contained in:
parent
65cb57c3b0
commit
1aa268c431
@ -1,4 +1,10 @@
|
|||||||
RUN: llvm-cxxfilt _Z1fi abc | FileCheck %s
|
RUN: llvm-cxxfilt _Z1fi abc | FileCheck %s
|
||||||
|
RUN: echo "Mangled _Z1fi and _Z3foov in string." | llvm-cxxfilt \
|
||||||
|
RUN: | FileCheck %s --check-prefix=CHECK-STRING
|
||||||
|
RUN: llvm-cxxfilt "CLI remains mangled _Z1fi" \
|
||||||
|
RUN: | FileCheck %s --check-prefix=CHECK-MANGLED
|
||||||
|
|
||||||
CHECK: f(int)
|
CHECK: f(int)
|
||||||
CHECK-NEXT: abc
|
CHECK-NEXT: abc
|
||||||
|
CHECK-STRING: Mangled f(int) and foo() in string.
|
||||||
|
CHECK-MANGLED: CLI remains mangled _Z1fi
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
RUN: llvm-cxxfilt -t f i | FileCheck %s
|
RUN: llvm-cxxfilt -t f i | FileCheck %s
|
||||||
|
RUN: echo "f i" | llvm-cxxfilt -t | FileCheck %s --check-prefix="CHECK-STRING"
|
||||||
|
|
||||||
CHECK: float
|
CHECK: float
|
||||||
CHECK-NEXT: int
|
CHECK-NEXT: int
|
||||||
|
CHECK-STRING: float int
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
//
|
//
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
|
#include "llvm/ADT/StringExtras.h"
|
||||||
#include "llvm/Demangle/Demangle.h"
|
#include "llvm/Demangle/Demangle.h"
|
||||||
#include "llvm/Support/CommandLine.h"
|
#include "llvm/Support/CommandLine.h"
|
||||||
#include "llvm/Support/InitLLVM.h"
|
#include "llvm/Support/InitLLVM.h"
|
||||||
@ -51,7 +52,7 @@ static cl::alias TypesShort("t", cl::desc("alias for --types"),
|
|||||||
static cl::list<std::string>
|
static cl::list<std::string>
|
||||||
Decorated(cl::Positional, cl::desc("<mangled>"), cl::ZeroOrMore);
|
Decorated(cl::Positional, cl::desc("<mangled>"), cl::ZeroOrMore);
|
||||||
|
|
||||||
static void demangle(llvm::raw_ostream &OS, const std::string &Mangled) {
|
static std::string demangle(llvm::raw_ostream &OS, const std::string &Mangled) {
|
||||||
int Status;
|
int Status;
|
||||||
|
|
||||||
const char *Decorated = Mangled.c_str();
|
const char *Decorated = Mangled.c_str();
|
||||||
@ -72,10 +73,28 @@ static void demangle(llvm::raw_ostream &OS, const std::string &Mangled) {
|
|||||||
Undecorated = itaniumDemangle(Decorated + 6, nullptr, nullptr, &Status);
|
Undecorated = itaniumDemangle(Decorated + 6, nullptr, nullptr, &Status);
|
||||||
}
|
}
|
||||||
|
|
||||||
OS << (Undecorated ? Undecorated : Mangled) << '\n';
|
std::string Result(Undecorated ? Undecorated : Mangled);
|
||||||
OS.flush();
|
|
||||||
|
|
||||||
free(Undecorated);
|
free(Undecorated);
|
||||||
|
return Result;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If 'Split' is true, then 'Mangled' is broken into individual words and each
|
||||||
|
// word is demangled. Otherwise, the entire string is treated as a single
|
||||||
|
// mangled item. The result is output to 'OS'.
|
||||||
|
static void demangleLine(llvm::raw_ostream &OS, StringRef Mangled, bool Split) {
|
||||||
|
std::string Result;
|
||||||
|
if (Split) {
|
||||||
|
SmallVector<StringRef, 16> Words;
|
||||||
|
SplitString(Mangled, Words);
|
||||||
|
for (auto Word : Words)
|
||||||
|
Result += demangle(OS, Word) + ' ';
|
||||||
|
// Remove the trailing space character.
|
||||||
|
if (Result.back() == ' ')
|
||||||
|
Result.pop_back();
|
||||||
|
} else
|
||||||
|
Result = demangle(OS, Mangled);
|
||||||
|
OS << Result << '\n';
|
||||||
|
OS.flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
@ -85,10 +104,10 @@ int main(int argc, char **argv) {
|
|||||||
|
|
||||||
if (Decorated.empty())
|
if (Decorated.empty())
|
||||||
for (std::string Mangled; std::getline(std::cin, Mangled);)
|
for (std::string Mangled; std::getline(std::cin, Mangled);)
|
||||||
demangle(llvm::outs(), Mangled);
|
demangleLine(llvm::outs(), Mangled, true);
|
||||||
else
|
else
|
||||||
for (const auto &Symbol : Decorated)
|
for (const auto &Symbol : Decorated)
|
||||||
demangle(llvm::outs(), Symbol);
|
demangleLine(llvm::outs(), Symbol, false);
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user