Index: llvm/test/tools/llvm-cxxfilt/simple.test =================================================================== --- llvm/test/tools/llvm-cxxfilt/simple.test +++ llvm/test/tools/llvm-cxxfilt/simple.test @@ -1,4 +1,6 @@ RUN: llvm-cxxfilt _Z1fi abc | FileCheck %s +RUN: llvm-cxxfilt "Mangled _Z1fi and _Z3foov in string." | FileCheck %s --check-prefix=CHECK-STRING CHECK: f(int) CHECK-NEXT: abc +CHECK-STRING: Mangled f(int) and foo() in string. Index: llvm/test/tools/llvm-cxxfilt/types.test =================================================================== --- llvm/test/tools/llvm-cxxfilt/types.test +++ llvm/test/tools/llvm-cxxfilt/types.test @@ -1,5 +1,6 @@ RUN: llvm-cxxfilt -t f i | FileCheck %s +RUN: llvm-cxxfilt -t "f i" | FileCheck %s --check-prefix="CHECK-STRING" CHECK: float CHECK-NEXT: int - +CHECK-STRING: float int Index: llvm/tools/llvm-cxxfilt/llvm-cxxfilt.cpp =================================================================== --- llvm/tools/llvm-cxxfilt/llvm-cxxfilt.cpp +++ llvm/tools/llvm-cxxfilt/llvm-cxxfilt.cpp @@ -6,6 +6,9 @@ // //===----------------------------------------------------------------------===// +#include "llvm/ADT/SmallVector.h" +#include "llvm/ADT/StringExtras.h" +#include "llvm/ADT/StringRef.h" #include "llvm/Demangle/Demangle.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/InitLLVM.h" @@ -51,7 +54,7 @@ static cl::list Decorated(cl::Positional, cl::desc(""), 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; const char *Decorated = Mangled.c_str(); @@ -72,10 +75,24 @@ Undecorated = itaniumDemangle(Decorated + 6, nullptr, nullptr, &Status); } - OS << (Undecorated ? Undecorated : Mangled) << '\n'; - OS.flush(); - + std::string Result(Undecorated ? Undecorated : Mangled); free(Undecorated); + return Result; +} + +// Split 'Mangled' and demangle each word. +// The result is reconstructed and output to 'OS'. +static void demangleLine(llvm::raw_ostream &OS, const std::string &Mangled) { + SmallVector Words; + SplitString(Mangled, Words); + std::string Result; + for (auto Word : Words) + Result += demangle(OS, Word) + ' '; + // Remove the trailing space character. + if (Result.back() == ' ') + Result.pop_back(); + OS << Result << '\n'; + OS.flush(); } int main(int argc, char **argv) { @@ -85,10 +102,10 @@ if (Decorated.empty()) for (std::string Mangled; std::getline(std::cin, Mangled);) - demangle(llvm::outs(), Mangled); + demangleLine(llvm::outs(), Mangled); else for (const auto &Symbol : Decorated) - demangle(llvm::outs(), Symbol); + demangleLine(llvm::outs(), Symbol); return EXIT_SUCCESS; }