modified the demangle for the xcoff label symbol.
Details
- Reviewers
jhenderson hubert.reinterpretcast Esme sfertile - Group Reviewers
Restricted Project - Commits
- rGf51b25a4b97a: [AIX] demangle xcoff label symbol for llvm-nm
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
Similar to the comment on the size patch, I think you want a drastically simpler test, which has just enough symbols to exercise the new demangling code (e.g. something that doesn't get demangled, something that has a dot, something that doesn't have a dot, and something that has an empty name). At the moment, it is hard to spot what's actually important in the test.
llvm/tools/llvm-nm/llvm-nm.cpp | ||
---|---|---|
619–620 | Rather than have all these boolean parameters to change the behaviour of the function, I think you probably want separate demangleMachO and demangleXCOFF functions. They would do the stuff specific to their format, before calling the common demangle function. Rough outline: static Optional<std::string> demangleMachO(StringRef Name) { // if name not empty, drop front of Name. return demangle(Name); } static Optional<std::string> demangleXCOFF(StringRef Name) { bool HasDot = /* ... */; // if HasDot and name not empty, drop front of Name. Optional<std::string> Demangled = demangle(Name); if (!Demangled) return None; return "." + *Demangled; } static Optional<std::string> demangle(StringRef Name) { // common stuff } // When calling... MachOObjectFile *MachO = dyn_cast<MachOObjectFile>(&Obj); if (Demangle) { function_ref<Optional<std::string> DemangleFn; if (MachO) DemangleFn = demangleMachO; else if(dyn_cast<XCOFFObejctFile>(&Obj)) DemangleFn = demangleXCOFF; else DemangleFn = demangle; if (Optional<std::string> Opt = DemangleFn(S.Name) Name = *Opt; } | |
623 | Consider using StringRef::drop_front instead, as it's a little more descriptive - probably only if you agree with my suggested refactor above (and then do it for the Mach-O case too). | |
632 | S = "." + S; seems much clearer. |
llvm/test/tools/llvm-nm/XCOFF/demangle.test | ||
---|---|---|
2 | ||
llvm/tools/llvm-nm/llvm-nm.cpp | ||
636 | Nit: delete blank line at start of function. | |
637 | Can XCOFF symbols have an empty name? If so, you need a test case for this. If not, you don't need a Name.empty() check (but you might want some sort of assertion instead). | |
742–747 | This is okay for now, but I think an llvm::function_ref would be better overall, as it allows in the future for other demangle options that take different argument sets. I also, personally, find the function_ref signature easier to read than a function pointer. |
llvm/test/tools/llvm-nm/XCOFF/demangle.test | ||
---|---|---|
18 | I'd suggest doing one of the following:
This will prevent this line accidentally matching another symbol with a name. It will also ensure the demangling output looks right on other lines. | |
21 | This test is purely about demangling functionality. Aside from having a single test-case where a symbol isn't demangled, I don't think you need all these other cases that don't demangle. Similarly, you can omit most of the test cases where demangling does occur, as long as you have one per code path. I think the following set of test cases is all you should have - ignore the other symbols (or more preferably just rebase this patch on top of @Esme's yaml2obj work, so that you can use yaml2obj to generate exactly the right set of symbols):
| |
32 | Why's this line here? |
llvm/test/tools/llvm-nm/XCOFF/demangle.test | ||
---|---|---|
18 | there is no symbol value in the test . it is symbol address. | |
21 |
|
llvm/test/tools/llvm-nm/XCOFF/demangle.test | ||
---|---|---|
21 | sorry , It should be
|
llvm/test/tools/llvm-nm/XCOFF/demangle.test | ||
---|---|---|
18 | "Symbol value" and "symbol address" are usually synonyms in other file formats. llvm-nm by default dumps three columns, "symbol value/address" being the first, and is the one I was referring to. | |
21 |
Then add support for it? I can't imagine it would be hard to do. Alternatively, does it fail if you explicitly do something like Name: ''? I believe that's how we provide empty names in cases in other formats. | |
llvm/test/tools/llvm-nm/XCOFF/demangle_sym_name.test | ||
2 ↗ | (On Diff #392505) | Simplify the name. |
3 ↗ | (On Diff #392505) | I'd recommend adding --match-full-lines here too, to show that the name demangling has worked properly, and doesn't print some trailing string/garbage after the demangled name. |
LGTM, with two minor suggestions remaining.
llvm/test/tools/llvm-nm/XCOFF/demangle_sym_name.test | ||
---|---|---|
1 ↗ | (On Diff #394887) | Nit: follow existing practice in the other tests in llvm-nm, but I prefer - instead of _ as separators, as they are easier to test, e.g. demangle-sym-name.test. Or you could just shorten it to demangle.test, since there's only one thing that is mangled (I assume?). |
llvm/tools/llvm-nm/llvm-nm.cpp | ||
636–639 | I think I'd find this marginally easier to follow if it was flipped, and the else removed, as per the inline edit. |