[PATCH] D34668: llvm-nm: Add suport for symbol demangling (-C/--demangle)
Rafael Avila de Espindola via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 27 14:45:14 PDT 2017
> +static Optional<std::string> demangle(StringRef Name) {
> + bool TryDemangle = false;
> + bool StripLeadingChar = false;
> +
> + if (Name.size() > 2 && Name.startswith("_Z")) {
> + TryDemangle = true;
> + } else if (Name.size() > 3 && Name.startswith("__Z")) {
> + // Mach-O symbols contain an extra leaving underscore which itaniumDemangle
> + // doesn't handle so we have to strip it off here.
> + TryDemangle = true;
> + StripLeadingChar = true;
> + }
This will also demangle __Z* on ELF, which is incorrect. You probably
want to check if the file is MachO.
> + if (TryDemangle) {
> + int Status;
> + const char* NameStr = Name.str().c_str() + (StripLeadingChar ? 1 : 0);
> + char *Undecorated = itaniumDemangle(NameStr, nullptr, nullptr, &Status);
> + if (Status == 0) {
> + std::string Result(Undecorated);
> + free(Undecorated);
Can you used a std::unique_ptr?
Thanks,
Rafael
More information about the llvm-commits
mailing list