[PATCH] D34668: llvm-nm: Add suport for symbol demangling (-C/--demangle)

Sam Clegg via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 29 10:11:18 PDT 2017


On Tue, Jun 27, 2017 at 5:35 PM, Rafael Avila de Espindola
<rafael.espindola at gmail.com> wrote:
> Sam Clegg via Phabricator <reviews at reviews.llvm.org> writes:
>> +static Optional<std::string> demangle(StringRef Name, bool StripUnderscore) {
>> +  if (StripUnderscore && Name.size() > 0 && Name[0] == '_')
>> +    Name = Name.substr(1);
>> +
>> +  if (Name.size() < 2 || !Name.startswith("_Z"))
>> +    return None;
>
> I don't think you need the .size() checks. It is safe to just use startswith.

I'm checking for >2 so this checking more than just startswith its
checking there is something more.. but maybe that is overkill

>
>
>> @@ -724,6 +745,12 @@
>>    for (SymbolListT::iterator I = SymbolList.begin(), E = SymbolList.end();
>>         I != E; ++I) {
>>      uint32_t SymFlags;
>> +    std::string Name = I->Name.str();
>> +    MachOObjectFile *MachO = dyn_cast<MachOObjectFile>(&Obj);
>> +    if (Demangle) {
>> +      if (Optional<std::string> Opt = demangle(I->Name, MachO != nullptr))
>
> You can just use isa<MachOObjectFile>(Obj).

The MachO object itself is needed further down in this function.

>
> LGTM with that.
>
> Cheers,
> Rafael


More information about the llvm-commits mailing list