summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPavel Labath <pavel@labath.sk>2018-12-12 12:35:25 +0000
committerPavel Labath <pavel@labath.sk>2018-12-12 12:35:25 +0000
commit280d2e8179eb4510349b97b57474356a4782c463 (patch)
treefff20369ed8ab1bbc5888061278f6fff498aefb5
parentbe77a9846dff41262c1fdef0d533611d8f0ad8e2 (diff)
downloadbcm5719-llvm-280d2e8179eb4510349b97b57474356a4782c463.tar.gz
bcm5719-llvm-280d2e8179eb4510349b97b57474356a4782c463.zip
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. llvm-svn: 348924
-rw-r--r--lldb/lit/Modules/MachO/subsections.yaml106
-rw-r--r--lldb/tools/lldb-test/lldb-test.cpp52
2 files changed, 138 insertions, 20 deletions
diff --git a/lldb/lit/Modules/MachO/subsections.yaml b/lldb/lit/Modules/MachO/subsections.yaml
new file mode 100644
index 00000000000..9c8a79ee818
--- /dev/null
+++ b/lldb/lit/Modules/MachO/subsections.yaml
@@ -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
+...
diff --git a/lldb/tools/lldb-test/lldb-test.cpp b/lldb/tools/lldb-test/lldb-test.cpp
index 49677e8da3a..08ad0158fc3 100644
--- a/lldb/tools/lldb-test/lldb-test.cpp
+++ b/lldb/tools/lldb-test/lldb-test.cpp
@@ -718,6 +718,37 @@ int opts::symbols::dumpSymbols(Debugger &Dbg) {
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.
OpenPOWER on IntegriCloud