Author: labath Date: Wed Dec 12 04:35:25 2018 New Revision: 348924 URL: http://llvm.org/viewvc/llvm-project?rev=348924&view=rev Log: lldb-test: Add ability to dump subsections
Previously, lldb-test would only print top-level sections. However, in lldb, sections can contain other sections. This teaches lldb-test to print nested sections too. Added: lldb/trunk/lit/Modules/MachO/ lldb/trunk/lit/Modules/MachO/subsections.yaml Modified: lldb/trunk/tools/lldb-test/lldb-test.cpp Added: lldb/trunk/lit/Modules/MachO/subsections.yaml URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/lit/Modules/MachO/subsections.yaml?rev=348924&view=auto ============================================================================== --- lldb/trunk/lit/Modules/MachO/subsections.yaml (added) +++ lldb/trunk/lit/Modules/MachO/subsections.yaml Wed Dec 12 04:35:25 2018 @@ -0,0 +1,106 @@ +# RUN: yaml2obj %s > %t +# RUN: lldb-test object-file %t | FileCheck %s + +#CHECK: Showing 2 sections +#CHECK-NEXT: Index: 0 +#CHECK-NEXT: Name: __PAGEZERO +#CHECK-NEXT: Type: container +#CHECK-NEXT: VM size: 4294967296 +#CHECK-NEXT: File size: 0 +#CHECK-NEXT: There are no subsections +# +#CHECK: Index: 1 +#CHECK-NEXT: Name: __TEXT +#CHECK-NEXT: Type: container +#CHECK-NEXT: VM size: 4096 +#CHECK-NEXT: File size: 4096 +#CHECK-NEXT: Showing 3 subsections +#CHECK-NEXT: Index: 0 +#CHECK-NEXT: Name: __text +#CHECK-NEXT: Type: code +#CHECK-NEXT: VM size: 22 +#CHECK-NEXT: File size: 22 +# +#CHECK: Index: 1 +#CHECK-NEXT: Name: __unwind_info +#CHECK-NEXT: Type: compact-unwind +#CHECK-NEXT: VM size: 76 +#CHECK-NEXT: File size: 76 +# +#CHECK: Index: 2 +#CHECK-NEXT: Name: __eh_frame +#CHECK-NEXT: Type: eh-frame +#CHECK-NEXT: VM size: 104 +#CHECK-NEXT: File size: 104 + +--- !mach-o +FileHeader: + magic: 0xFEEDFACF + cputype: 0x01000007 + cpusubtype: 0x00000003 + filetype: 0x00000002 + ncmds: 12 + sizeofcmds: 728 + flags: 0x00000085 + reserved: 0x00000000 +LoadCommands: + - cmd: LC_SEGMENT_64 + cmdsize: 72 + segname: __PAGEZERO + vmaddr: 0 + vmsize: 4294967296 + fileoff: 0 + filesize: 0 + maxprot: 0 + initprot: 0 + nsects: 0 + flags: 0 + - cmd: LC_SEGMENT_64 + cmdsize: 312 + segname: __TEXT + vmaddr: 4294967296 + vmsize: 4096 + fileoff: 0 + filesize: 4096 + maxprot: 7 + initprot: 5 + nsects: 3 + flags: 0 + Sections: + - sectname: __text + segname: __TEXT + addr: 0x0000000100000F30 + size: 22 + offset: 0x00000F30 + align: 4 + reloff: 0x00000000 + nreloc: 0 + flags: 0x80000400 + reserved1: 0x00000000 + reserved2: 0x00000000 + reserved3: 0x00000000 + - sectname: __unwind_info + segname: __TEXT + addr: 0x0000000100000F48 + size: 76 + offset: 0x00000F48 + align: 2 + reloff: 0x00000000 + nreloc: 0 + flags: 0x00000000 + reserved1: 0x00000000 + reserved2: 0x00000000 + reserved3: 0x00000000 + - sectname: __eh_frame + segname: __TEXT + addr: 0x0000000100000F98 + size: 104 + offset: 0x00000F98 + align: 3 + reloff: 0x00000000 + nreloc: 0 + flags: 0x0000000B + reserved1: 0x00000000 + reserved2: 0x00000000 + reserved3: 0x00000000 +... Modified: lldb/trunk/tools/lldb-test/lldb-test.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-test/lldb-test.cpp?rev=348924&r1=348923&r2=348924&view=diff ============================================================================== --- lldb/trunk/tools/lldb-test/lldb-test.cpp (original) +++ lldb/trunk/tools/lldb-test/lldb-test.cpp Wed Dec 12 04:35:25 2018 @@ -718,6 +718,37 @@ int opts::symbols::dumpSymbols(Debugger return HadErrors; } +static void dumpSectionList(LinePrinter &Printer, const SectionList &List, bool is_subsection) { + size_t Count = List.GetNumSections(0); + if (Count == 0) { + Printer.formatLine("There are no {0}sections", is_subsection ? "sub" : ""); + return; + } + Printer.formatLine("Showing {0} {1}sections", Count, + is_subsection ? "sub" : ""); + for (size_t I = 0; I < Count; ++I) { + auto S = List.GetSectionAtIndex(I); + assert(S); + AutoIndent Indent(Printer, 2); + Printer.formatLine("Index: {0}", I); + Printer.formatLine("Name: {0}", S->GetName().GetStringRef()); + Printer.formatLine("Type: {0}", S->GetTypeAsCString()); + Printer.formatLine("VM size: {0}", S->GetByteSize()); + Printer.formatLine("File size: {0}", S->GetFileSize()); + + if (opts::object::SectionContents) { + DataExtractor Data; + S->GetSectionData(Data); + ArrayRef<uint8_t> Bytes = {Data.GetDataStart(), Data.GetDataEnd()}; + Printer.formatBinary("Data: ", Bytes, 0); + } + + if (S->GetType() == eSectionTypeContainer) + dumpSectionList(Printer, S->GetChildren(), true); + Printer.NewLine(); + } +} + static int dumpObjectFiles(Debugger &Dbg) { LinePrinter Printer(4, llvm::outs()); @@ -753,26 +784,7 @@ static int dumpObjectFiles(Debugger &Dbg Printer.formatLine("Type: {0}", ObjectPtr->GetType()); Printer.formatLine("Strata: {0}", ObjectPtr->GetStrata()); - size_t Count = Sections->GetNumSections(0); - Printer.formatLine("Showing {0} sections", Count); - for (size_t I = 0; I < Count; ++I) { - AutoIndent Indent(Printer, 2); - auto S = Sections->GetSectionAtIndex(I); - assert(S); - Printer.formatLine("Index: {0}", I); - Printer.formatLine("Name: {0}", S->GetName().GetStringRef()); - Printer.formatLine("Type: {0}", S->GetTypeAsCString()); - Printer.formatLine("VM size: {0}", S->GetByteSize()); - Printer.formatLine("File size: {0}", S->GetFileSize()); - - if (opts::object::SectionContents) { - DataExtractor Data; - S->GetSectionData(Data); - ArrayRef<uint8_t> Bytes = {Data.GetDataStart(), Data.GetDataEnd()}; - Printer.formatBinary("Data: ", Bytes, 0); - } - Printer.NewLine(); - } + dumpSectionList(Printer, *Sections, /*is_subsection*/ false); if (opts::object::SectionDependentModules) { // A non-empty section list ensures a valid object file. _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits