llvm.org GIT mirror llvm / 7ff141c
llvm-dwarfdump: support dumping UUIDs of Mach-O binaries. This is a feature supported by Darwin dwarfdump. UUIDs are used to associate executables with their .dSYM bundles. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@313165 91177308-0d34-0410-b5e6-96231b3b80d8 Adrian Prantl 2 years ago
10 changed file(s) with 465 addition(s) and 15 deletion(s). Raw diff Collapse all Expand all
115115 enum DIDumpTypeCounter {
116116 DIDT_ID_Null = 0,
117117 #define HANDLE_DWARF_SECTION(ENUM_NAME, ELF_NAME, CMDLINE_NAME) \
118 DIDT_ID##ENUM_NAME,
118 DIDT_ID_##ENUM_NAME,
119119 #include "llvm/BinaryFormat/Dwarf.def"
120120 #undef HANDLE_DWARF_SECTION
121 DIDT_ID_Count,
122 };
123 static_assert(DIDT_ID_Count <= 64, "section types overflow storage");
121 DIDT_ID_UUID,
122 DIDT_ID_Count
123 };
124 static_assert(DIDT_ID_Count <= 64, "section types overflow storage");
124125
125126 /// Selects which debug sections get dumped.
126127 enum DIDumpType : uint64_t {
127128 DIDT_Null,
128129 DIDT_All = ~0ULL,
129130 #define HANDLE_DWARF_SECTION(ENUM_NAME, ELF_NAME, CMDLINE_NAME) \
130 DIDT_##ENUM_NAME = 1 << (DIDT_ID##ENUM_NAME - 1),
131 DIDT_##ENUM_NAME = 1 << (DIDT_ID_##ENUM_NAME - 1),
131132 #include "llvm/BinaryFormat/Dwarf.def"
132133 #undef HANDLE_DWARF_SECTION
134 DIDT_UUID = 1 << (DIDT_ID_UUID - 1),
133135 };
134136
135137 /// Container for dump options that control which debug information will be
265265
266266 // This trait is used for UUIDs. It reads and writes them matching otool's
267267 // formatting style.
268 using uuid_t = uint8_t[16];
268 using uuid_t = raw_ostream::uuid_t;
269269
270270 template <> struct ScalarTraits {
271271 static void output(const uuid_t &Val, void *, raw_ostream &Out);
211211
212212 /// Output \p N in hexadecimal, without any prefix or padding.
213213 raw_ostream &write_hex(unsigned long long N);
214
215 /// Output a formatted UUID with dash separators.
216 using uuid_t = uint8_t[16];
217 raw_ostream &write_uuid(const uuid_t UUID);
214218
215219 /// Output \p Str, turning '\\', '\t', '\n', '"', and anything that doesn't
216220 /// satisfy std::isprint into an escape sequence.
7979 Accel.dump(OS);
8080 }
8181
82 /// Dump the UUID load command.
83 static void dumpUUID(raw_ostream &OS, const ObjectFile &Obj) {
84 auto *MachO = dyn_cast(&Obj);
85 if (!MachO)
86 return;
87 for (auto LC : MachO->load_commands()) {
88 raw_ostream::uuid_t UUID;
89 if (LC.C.cmd == MachO::LC_UUID) {
90 if (LC.C.cmdsize < sizeof(UUID) + sizeof(LC.C)) {
91 OS << "error: UUID load command is too short.\n";
92 return;
93 }
94 OS << "UUID: ";
95 memcpy(&UUID, LC.Ptr+sizeof(LC.C), sizeof(UUID));
96 OS.write_uuid(UUID);
97 OS << ' ' << MachO->getFileFormatName();
98 OS << ' ' << MachO->getFileName() << '\n';
99 }
100 }
101 }
102
82103 static void
83104 dumpDWARFv5StringOffsetsSection(raw_ostream &OS, StringRef SectionName,
84105 const DWARFObject &Obj,
201222 void DWARFContext::dump(raw_ostream &OS, DIDumpOptions DumpOpts) {
202223 uint64_t DumpType = DumpOpts.DumpType;
203224 bool DumpEH = DumpOpts.DumpEH;
225
226 const auto *ObjFile = DObj->getFile();
227 if (!(DumpType & DIDT_UUID) || DumpType == DIDT_All)
228 outs() << ObjFile->getFileName() << ":\tfile format "
229 << ObjFile->getFileFormatName() << "\n\n";
230 if (DumpType & DIDT_UUID)
231 dumpUUID(OS, *ObjFile);
204232
205233 if (DumpType & DIDT_DebugAbbrev) {
206234 OS << ".debug_abbrev contents:\n";
5454 bool ScalarTraits::mustQuote(StringRef S) { return needsQuotes(S); }
5555
5656 void ScalarTraits::output(const uuid_t &Val, void *, raw_ostream &Out) {
57 for (int Idx = 0; Idx < 16; ++Idx) {
58 Out << format("%02" PRIX32, Val[Idx]);
59 if (Idx == 3 || Idx == 5 || Idx == 7 || Idx == 9)
60 Out << "-";
61 }
57 Out.write_uuid(Val);
6258 }
6359
6460 StringRef ScalarTraits::input(StringRef Scalar, void *, uuid_t &Val) {
138138 return *this;
139139 }
140140
141 raw_ostream &raw_ostream::write_uuid(const uuid_t UUID) {
142 for (int Idx = 0; Idx < 16; ++Idx) {
143 *this << format("%02" PRIX32, UUID[Idx]);
144 if (Idx == 3 || Idx == 5 || Idx == 7 || Idx == 9)
145 *this << "-";
146 }
147 return *this;
148 }
149
150
141151 raw_ostream &raw_ostream::write_escaped(StringRef Str,
142152 bool UseHexEscapes) {
143153 for (unsigned char c : Str) {
0 config.suffixes = ['.test', '.ll', '.s', '.yaml']
0 # RUN: yaml2obj %s | llvm-dwarfdump -u - | FileCheck %s
1 # RUN: yaml2obj %s | llvm-dwarfdump --uuid - | FileCheck %s
2 # CHECK: UUID: E5874E6F-946F-317B-B348-56FAEE59D8D1 Mach-O 64-bit x86-64
3 --- !mach-o
4 FileHeader:
5 magic: 0xFEEDFACF
6 cputype: 0x01000007
7 cpusubtype: 0x80000003
8 filetype: 0x00000002
9 ncmds: 14
10 sizeofcmds: 728
11 flags: 0x00200085
12 reserved: 0x00000000
13 LoadCommands:
14 - cmd: LC_SEGMENT_64
15 cmdsize: 72
16 segname: __PAGEZERO
17 vmaddr: 0
18 vmsize: 4294967296
19 fileoff: 0
20 filesize: 0
21 maxprot: 0
22 initprot: 0
23 nsects: 0
24 flags: 0
25 - cmd: LC_SEGMENT_64
26 cmdsize: 232
27 segname: __TEXT
28 vmaddr: 4294967296
29 vmsize: 4096
30 fileoff: 0
31 filesize: 4096
32 maxprot: 7
33 initprot: 5
34 nsects: 2
35 flags: 0
36 Sections:
37 - sectname: __text
38 segname: __TEXT
39 addr: 0x0000000100000FB0
40 size: 8
41 offset: 0x00000FB0
42 align: 0
43 reloff: 0x00000000
44 nreloc: 0
45 flags: 0x80000400
46 reserved1: 0x00000000
47 reserved2: 0x00000000
48 reserved3: 0x00000000
49 - sectname: __unwind_info
50 segname: __TEXT
51 addr: 0x0000000100000FB8
52 size: 72
53 offset: 0x00000FB8
54 align: 2
55 reloff: 0x00000000
56 nreloc: 0
57 flags: 0x00000000
58 reserved1: 0x00000000
59 reserved2: 0x00000000
60 reserved3: 0x00000000
61 - cmd: LC_SEGMENT_64
62 cmdsize: 72
63 segname: __LINKEDIT
64 vmaddr: 4294971392
65 vmsize: 4096
66 fileoff: 4096
67 filesize: 152
68 maxprot: 7
69 initprot: 1
70 nsects: 0
71 flags: 0
72 - cmd: LC_DYLD_INFO_ONLY
73 cmdsize: 48
74 rebase_off: 0
75 rebase_size: 0
76 bind_off: 0
77 bind_size: 0
78 weak_bind_off: 0
79 weak_bind_size: 0
80 lazy_bind_off: 0
81 lazy_bind_size: 0
82 export_off: 4096
83 export_size: 48
84 - cmd: LC_SYMTAB
85 cmdsize: 24
86 symoff: 4152
87 nsyms: 3
88 stroff: 4200
89 strsize: 48
90 - cmd: LC_DYSYMTAB
91 cmdsize: 80
92 ilocalsym: 0
93 nlocalsym: 0
94 iextdefsym: 0
95 nextdefsym: 2
96 iundefsym: 2
97 nundefsym: 1
98 tocoff: 0
99 ntoc: 0
100 modtaboff: 0
101 nmodtab: 0
102 extrefsymoff: 0
103 nextrefsyms: 0
104 indirectsymoff: 0
105 nindirectsyms: 0
106 extreloff: 0
107 nextrel: 0
108 locreloff: 0
109 nlocrel: 0
110 - cmd: LC_LOAD_DYLINKER
111 cmdsize: 32
112 name: 12
113 PayloadString: /usr/lib/dyld
114 ZeroPadBytes: 7
115 - cmd: LC_UUID
116 cmdsize: 24
117 uuid: E5874E6F-946F-317B-B348-56FAEE59D8D1
118 - cmd: LC_VERSION_MIN_MACOSX
119 cmdsize: 16
120 version: 658688
121 sdk: 658688
122 - cmd: LC_SOURCE_VERSION
123 cmdsize: 16
124 version: 0
125 - cmd: LC_MAIN
126 cmdsize: 24
127 entryoff: 4016
128 stacksize: 0
129 - cmd: LC_LOAD_DYLIB
130 cmdsize: 56
131 dylib:
132 name: 24
133 timestamp: 2
134 current_version: 81985536
135 compatibility_version: 65536
136 PayloadString: /usr/lib/libSystem.B.dylib
137 ZeroPadBytes: 6
138 - cmd: LC_FUNCTION_STARTS
139 cmdsize: 16
140 dataoff: 4144
141 datasize: 8
142 - cmd: LC_DATA_IN_CODE
143 cmdsize: 16
144 dataoff: 4152
145 datasize: 0
146 LinkEditData:
147 ExportTrie:
148 TerminalSize: 0
149 NodeOffset: 0
150 Name: ''
151 Flags: 0x0000000000000000
152 Address: 0x0000000000000000
153 Other: 0x0000000000000000
154 ImportName: ''
155 Children:
156 - TerminalSize: 0
157 NodeOffset: 5
158 Name: _
159 Flags: 0x0000000000000000
160 Address: 0x0000000000000000
161 Other: 0x0000000000000000
162 ImportName: ''
163 Children:
164 - TerminalSize: 2
165 NodeOffset: 33
166 Name: _mh_execute_header
167 Flags: 0x0000000000000000
168 Address: 0x0000000000000000
169 Other: 0x0000000000000000
170 ImportName: ''
171 - TerminalSize: 3
172 NodeOffset: 37
173 Name: main
174 Flags: 0x0000000000000000
175 Address: 0x0000000000000FB0
176 Other: 0x0000000000000000
177 ImportName: ''
178 NameList:
179 - n_strx: 2
180 n_type: 0x0F
181 n_sect: 1
182 n_desc: 16
183 n_value: 4294967296
184 - n_strx: 22
185 n_type: 0x0F
186 n_sect: 1
187 n_desc: 0
188 n_value: 4294971312
189 - n_strx: 28
190 n_type: 0x01
191 n_sect: 0
192 n_desc: 256
193 n_value: 0
194 StringTable:
195 - ' '
196 - __mh_execute_header
197 - _main
198 - dyld_stub_binder
199 - ''
200 - ''
201 - ''
202 ...
0 # RUN: yaml2obj %s | llvm-dwarfdump --uuid - | FileCheck %s
1 # CHECK: UUID: 229E6146-A7AB-3BA0-8B17-DD5125D3AFEF Mach-O 32-bit i386
2 --- !mach-o
3 FileHeader:
4 magic: 0xFEEDFACE
5 cputype: 0x00000007
6 cpusubtype: 0x00000003
7 filetype: 0x00000002
8 ncmds: 14
9 sizeofcmds: 648
10 flags: 0x01200085
11 LoadCommands:
12 - cmd: LC_SEGMENT
13 cmdsize: 56
14 segname: __PAGEZERO
15 vmaddr: 0
16 vmsize: 4096
17 fileoff: 0
18 filesize: 0
19 maxprot: 0
20 initprot: 0
21 nsects: 0
22 flags: 0
23 - cmd: LC_SEGMENT
24 cmdsize: 192
25 segname: __TEXT
26 vmaddr: 4096
27 vmsize: 4096
28 fileoff: 0
29 filesize: 4096
30 maxprot: 7
31 initprot: 5
32 nsects: 2
33 flags: 0
34 Sections:
35 - sectname: __text
36 segname: __TEXT
37 addr: 0x0000000000001FB1
38 size: 7
39 offset: 0x00000FB1
40 align: 0
41 reloff: 0x00000000
42 nreloc: 0
43 flags: 0x80000400
44 reserved1: 0x00000000
45 reserved2: 0x00000000
46 reserved3: 0x00000000
47 - sectname: __unwind_info
48 segname: __TEXT
49 addr: 0x0000000000001FB8
50 size: 72
51 offset: 0x00000FB8
52 align: 2
53 reloff: 0x00000000
54 nreloc: 0
55 flags: 0x00000000
56 reserved1: 0x00000000
57 reserved2: 0x00000000
58 reserved3: 0x00000000
59 - cmd: LC_SEGMENT
60 cmdsize: 56
61 segname: __LINKEDIT
62 vmaddr: 8192
63 vmsize: 4096
64 fileoff: 4096
65 filesize: 132
66 maxprot: 7
67 initprot: 1
68 nsects: 0
69 flags: 0
70 - cmd: LC_DYLD_INFO_ONLY
71 cmdsize: 48
72 rebase_off: 0
73 rebase_size: 0
74 bind_off: 0
75 bind_size: 0
76 weak_bind_off: 0
77 weak_bind_size: 0
78 lazy_bind_off: 0
79 lazy_bind_size: 0
80 export_off: 4096
81 export_size: 44
82 - cmd: LC_SYMTAB
83 cmdsize: 24
84 symoff: 4144
85 nsyms: 3
86 stroff: 4180
87 strsize: 48
88 - cmd: LC_DYSYMTAB
89 cmdsize: 80
90 ilocalsym: 0
91 nlocalsym: 0
92 iextdefsym: 0
93 nextdefsym: 2
94 iundefsym: 2
95 nundefsym: 1
96 tocoff: 0
97 ntoc: 0
98 modtaboff: 0
99 nmodtab: 0
100 extrefsymoff: 0
101 nextrefsyms: 0
102 indirectsymoff: 0
103 nindirectsyms: 0
104 extreloff: 0
105 nextrel: 0
106 locreloff: 0
107 nlocrel: 0
108 - cmd: LC_LOAD_DYLINKER
109 cmdsize: 28
110 name: 12
111 PayloadString: /usr/lib/dyld
112 ZeroPadBytes: 3
113 - cmd: LC_UUID
114 cmdsize: 24
115 uuid: 229E6146-A7AB-3BA0-8B17-DD5125D3AFEF
116 - cmd: LC_VERSION_MIN_MACOSX
117 cmdsize: 16
118 version: 658688
119 sdk: 658688
120 - cmd: LC_SOURCE_VERSION
121 cmdsize: 16
122 version: 0
123 - cmd: LC_MAIN
124 cmdsize: 24
125 entryoff: 4017
126 stacksize: 0
127 - cmd: LC_LOAD_DYLIB
128 cmdsize: 52
129 dylib:
130 name: 24
131 timestamp: 2
132 current_version: 81985536
133 compatibility_version: 65536
134 PayloadString: /usr/lib/libSystem.B.dylib
135 ZeroPadBytes: 2
136 - cmd: LC_FUNCTION_STARTS
137 cmdsize: 16
138 dataoff: 4140
139 datasize: 4
140 - cmd: LC_DATA_IN_CODE
141 cmdsize: 16
142 dataoff: 4144
143 datasize: 0
144 LinkEditData:
145 ExportTrie:
146 TerminalSize: 0
147 NodeOffset: 0
148 Name: ''
149 Flags: 0x0000000000000000
150 Address: 0x0000000000000000
151 Other: 0x0000000000000000
152 ImportName: ''
153 Children:
154 - TerminalSize: 0
155 NodeOffset: 5
156 Name: _
157 Flags: 0x0000000000000000
158 Address: 0x0000000000000000
159 Other: 0x0000000000000000
160 ImportName: ''
161 Children:
162 - TerminalSize: 2
163 NodeOffset: 33
164 Name: _mh_execute_header
165 Flags: 0x0000000000000000
166 Address: 0x0000000000000000
167 Other: 0x0000000000000000
168 ImportName: ''
169 - TerminalSize: 3
170 NodeOffset: 37
171 Name: main
172 Flags: 0x0000000000000000
173 Address: 0x0000000000000FB1
174 Other: 0x0000000000000000
175 ImportName: ''
176 NameList:
177 - n_strx: 2
178 n_type: 0x0F
179 n_sect: 1
180 n_desc: 16
181 n_value: 4096
182 - n_strx: 22
183 n_type: 0x0F
184 n_sect: 1
185 n_desc: 0
186 n_value: 8113
187 - n_strx: 28
188 n_type: 0x01
189 n_sect: 0
190 n_desc: 256
191 n_value: 0
192 StringTable:
193 - ' '
194 - __mh_execute_header
195 - _main
196 - dyld_stub_binder
197 - ''
198 - ''
199 - ''
200 ...
5959 cat(SectionCategory));
6060 #include "llvm/BinaryFormat/Dwarf.def"
6161 #undef HANDLE_DWARF_SECTION
62 static opt DumpUUID("uuid", desc("Show the UUID for each architecture"),
63 cat(DwarfDumpCategory));
64 static alias DumpUUIDAlias("u", desc("Alias for -uuid"), aliasopt(DumpUUID));
6265
6366 static opt
6467 SummarizeTypes("summarize-types",
9396 std::unique_ptr DICtx = DWARFContext::create(Obj);
9497 logAllUnhandledErrors(DICtx->loadRegisterInfo(Obj), errs(),
9598 Filename.str() + ": ");
96
97 outs() << Filename.str() << ":\tfile format " << Obj.getFileFormatName()
98 << "\n\n";
99
99 // The UUID dump already contains all the same information.
100 if (!(DumpType & DIDT_UUID) || DumpType == DIDT_All)
101 outs() << Filename << ":\tfile format " << Obj.getFileFormatName()
102 << "\n\n";
100103
101104 // Dump the complete DWARF structure.
102105 DICtx->dump(outs(), GetDumpOpts());
224227 DumpType |= DIDT_##ENUM_NAME;
225228 #include "llvm/BinaryFormat/Dwarf.def"
226229 #undef HANDLE_DWARF_SECTION
230 if (DumpUUID)
231 DumpType |= DIDT_UUID;
227232 if (DumpAll)
228233 DumpType = DIDT_All;
229234 if (DumpType == DIDT_Null) {