This patch adds support for dumping the .debug_str section to obj2yaml.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
llvm/test/tools/obj2yaml/ELF/DWARF/debug-str.yaml | ||
---|---|---|
29 | I'd add a short comment for each of these sub-cases to make it clear what they want to test. | |
34 | I think you have SHDR TYPE FLAGS ADDRALIGN ENTSIZE prefixes in each of the sub cases. | |
56 | Probably you need a test showing that by default we don't print "Sections:" with the YAML below. | |
llvm/tools/obj2yaml/elf2yaml.cpp | ||
213 | Perhaps it would be easier to read it when there is no CommonProperties variable, if (RawSec->Type != ELF::SHT_PROGBITS || !RawSec->Link.empty() || RawSec->Info || (uint64_t)RawSec->AddressAlign != 1 || RawSec->Address) return true; if (SecName == "debug_str") return !(RawSec->EntSize && (uint64_t)*RawSec->EntSize == 1) || RawSec->Flags.getValueOr(ELFYAML::ELF_SHF(0)) != ELFYAML::ELF_SHF(ELF::SHF_MERGE | ELF::SHF_STRINGS); return RawSec->EntSize || RawSec->Flags; |
llvm/tools/obj2yaml/elf2yaml.cpp | ||
---|---|---|
418 | I'd probably expect to see that dumpDebugStrings returns an error too, btw.
|
llvm/test/tools/obj2yaml/ELF/DWARF/debug-str.yaml | ||
---|---|---|
27 | ||
56 | Seems like adding this to the BASIC case above would be enough, right? You just need to show that when the object has default header properties, it doesn't add it to "Sections" too. | |
llvm/tools/obj2yaml/elf2yaml.cpp | ||
418 | .debug_str is not an ELF SHT_STRTAB and doesn't require a leading null-byte by the standard. It does require a trailing null byte (since the contents is a series of null terminated strings). As dumpDebugStrings already exists, this change should just work with its current behaviour, and a separate patch should address error handling, if needed. |
llvm/test/tools/obj2yaml/ELF/DWARF/debug-str.yaml | ||
---|---|---|
56 | Yes, seems the first YAML and this one can be merged. |
Address comments.
It looks like FileCheck isn't happy when I put the BASIC: checking labels before the COMMON: labels, so I adjust the order a little.
Thanks for reviewing!
llvm/test/tools/obj2yaml/ELF/DWARF/debug-str.yaml | ||
---|---|---|
56 | I merged them into the first YAML. | |
llvm/tools/obj2yaml/elf2yaml.cpp | ||
418 | Yes, I think I want to do it in a follow-up patch. I've fixed the behavior for llvm-dwarfdump recently and it seems that we can refactor it to reuse the parser in lib/DebugInfo. |
llvm/test/tools/obj2yaml/ELF/DWARF/debug-str.yaml | ||
---|---|---|
14 | Here and in each other case, rather than having to put leading 0s in every value, you could switch to FileCheck numeric variables. I think the invocation is something like: # RUN: FIleCheck ... -D#%x,ADDRALIGN=1 ... # COMMON-NEXT: AddressAlign: 0x[[#%.16x, ADDRALIGN]] | |
llvm/tools/obj2yaml/elf2yaml.cpp | ||
209 | I'm struggling with this code. Under what circumstances can RawSec->EntSize by None here? Similar question for the Flags below. |
Update.
llvm/tools/obj2yaml/elf2yaml.cpp | ||
---|---|---|
209 | I check it because EntSize and Flags are Optional values. It seems that you are right, I cannot create a test case that make them None. Could you please tell me why they cannot be None here? |
llvm/tools/obj2yaml/elf2yaml.cpp | ||
---|---|---|
209 | Well. I haven't debugged this, but I *think* they can be None. Looking on the code, we have: Error ELFDumper<ELFT>::dumpCommonSection(const Elf_Shdr *Shdr, ELFYAML::Section &S) { ... if (Shdr->sh_entsize != getDefaultShEntSize<ELFT>(S.Type)) S.EntSize = static_cast<llvm::yaml::Hex64>(Shdr->sh_entsize); So i'd expect to have None value when sh_entsize == 0. Isn't it true? |
llvm/tools/obj2yaml/elf2yaml.cpp | ||
---|---|---|
209 | So yes, I've debugged this and it is possible to get None for EntSize when sh_entsize == 0. --- !ELF FileHeader: Class: ELFCLASS64 Data: ELFDATA2LSB Type: ET_EXEC Sections: - Name: .debug_str Type: SHT_PROGBITS EntSize: 0 Size: 10 ShFlags: 0 When there are no flags, we have 'None` for Flags. |
Check the optional value.
llvm/tools/obj2yaml/elf2yaml.cpp | ||
---|---|---|
209 | Thank you @grimar . I reproduce it using the YAML provided by you with a slight modification. --- !ELF FileHeader: Class: ELFCLASS64 Data: ELFDATA2LSB Type: ET_EXEC Sections: - Name: .debug_str Type: SHT_PROGBITS AddressAlign: 1 Flags: [] Because the default value of AddressAlign is 0. If we don't specify it, this function will return in the first if branch and it will not reach the second if branch where the optional value is dereferenced. if (RawSec->Type != ELF::SHT_PROGBITS || !RawSec->Link.empty() || RawSec->Info || RawSec->AddressAlign != 1 || RawSec->Address) ^~~~~~~~~~~~~~~~~~~~~~~~~ return true; |
I modified the getDefaultShEntSize() function in this revision. If the section name is '.debug_str', the default value of sh_entsize is 1 rather than 0.
llvm/tools/obj2yaml/elf2yaml.cpp | ||
---|---|---|
209 | I mark this as done since this comment is not applied here ... |
llvm/tools/obj2yaml/elf2yaml.cpp | ||
---|---|---|
213 | I'm not sure casting this here is the clearest of things. I'd actually make it more explicit and check it doesn't equal 0 (if the (bool) is even required). |
LGTM, with suggestion.
llvm/tools/obj2yaml/elf2yaml.cpp | ||
---|---|---|
213 | It may be best to introduce a helper variable so that we don't repeat RawSec->Flags.getValueOr(ELFYAML::ELF_SHF(0)) twice. |
Here and in each other case, rather than having to put leading 0s in every value, you could switch to FileCheck numeric variables. I think the invocation is something like: