51 | # | #{FILENAMES.map{|fn|' | ' + fn.sub(/\.json/, '')} * ''}
52 | #)
53 | #end
54 |
55 | puts %Q(#{FILENAMES.map{|fn|fn.sub(/\.json/, '')} * "\t"})
56 |
57 | all_types.sort_by{|name, _|name == '???' ? '~~~' : name.upcase}.each do |name, _|
58 | tr = "#{name}"
59 | all_infos.each do |types|
60 | info = types[name]
61 | if !info
62 | tr += "\t???"
63 | next
64 | end
65 |
66 | case info[0]
67 | when 'base'
68 | tr += "\t#{info[1]} (basic)"
69 | when 'struct'
70 | tr += "\t#{info[1]} (struct)"
71 | when 'typedef'
72 | real = info
73 | while real && real[0] == 'typedef'
74 | real = types[real[1] =~ /(\*|\[\])$/ ? 'intptr_t' : real[1]]
75 | end
76 | if real
77 | size = real[1]
78 | else
79 | size = '???'
80 | end
81 | tr += "\t#{size} (#{info[1]})"
82 | end
83 | end
84 | puts tr
85 | end
86 |
87 |
--------------------------------------------------------------------------------
/mach-o/fat.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
3 | *
4 | * @APPLE_LICENSE_HEADER_START@
5 | *
6 | * This file contains Original Code and/or Modifications of Original Code
7 | * as defined in and that are subject to the Apple Public Source License
8 | * Version 2.0 (the 'License'). You may not use this file except in
9 | * compliance with the License. Please obtain a copy of the License at
10 | * http://www.opensource.apple.com/apsl/ and read it before using this
11 | * file.
12 | *
13 | * The Original Code and all software distributed under the License are
14 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 | * Please see the License for the specific language governing rights and
19 | * limitations under the License.
20 | *
21 | * @APPLE_LICENSE_HEADER_END@
22 | */
23 | #ifndef _MACH_O_FAT_H_
24 | #define _MACH_O_FAT_H_
25 | /*
26 | * This header file describes the structures of the file format for "fat"
27 | * architecture specific file (wrapper design). At the begining of the file
28 | * there is one fat_header structure followed by a number of fat_arch
29 | * structures. For each architecture in the file, specified by a pair of
30 | * cputype and cpusubtype, the fat_header describes the file offset, file
31 | * size and alignment in the file of the architecture specific member.
32 | * The padded bytes in the file to place each member on it's specific alignment
33 | * are defined to be read as zeros and can be left as "holes" if the file system
34 | * can support them as long as they read as zeros.
35 | *
36 | * All structures defined here are always written and read to/from disk
37 | * in big-endian order.
38 | */
39 |
40 | /*
41 | * is needed here for the cpu_type_t and cpu_subtype_t types
42 | * and contains the constants for the possible values of these types.
43 | */
44 | #include
45 | #include
46 | //#include
47 |
48 | #define FAT_MAGIC 0xcafebabe
49 | #define FAT_CIGAM 0xbebafeca /* NXSwapLong(FAT_MAGIC) */
50 |
51 | struct fat_header {
52 | uint32_t magic; /* FAT_MAGIC */
53 | uint32_t nfat_arch; /* number of structs that follow */
54 | };
55 |
56 | struct fat_arch {
57 | cpu_type_t cputype; /* cpu specifier (int) */
58 | cpu_subtype_t cpusubtype; /* machine specifier (int) */
59 | uint32_t offset; /* file offset to this object file */
60 | uint32_t size; /* size of this object file */
61 | uint32_t align; /* alignment as a power of 2 */
62 | };
63 |
64 | #endif /* _MACH_O_FAT_H_ */
65 |
--------------------------------------------------------------------------------
/mach/vm_prot.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved.
3 | *
4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5 | *
6 | * This file contains Original Code and/or Modifications of Original Code
7 | * as defined in and that are subject to the Apple Public Source License
8 | * Version 2.0 (the 'License'). You may not use this file except in
9 | * compliance with the License. The rights granted to you under the License
10 | * may not be used to create, or enable the creation or redistribution of,
11 | * unlawful or unlicensed copies of an Apple operating system, or to
12 | * circumvent, violate, or enable the circumvention or violation of, any
13 | * terms of an Apple operating system software license agreement.
14 | *
15 | * Please obtain a copy of the License at
16 | * http://www.opensource.apple.com/apsl/ and read it before using this file.
17 | *
18 | * The Original Code and all software distributed under the License are
19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 | * Please see the License for the specific language governing rights and
24 | * limitations under the License.
25 | *
26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27 | */
28 | /*
29 | * @OSF_COPYRIGHT@
30 | */
31 | /*
32 | * Mach Operating System
33 | * Copyright (c) 1991,1990,1989,1988,1987 Carnegie Mellon University
34 | * All Rights Reserved.
35 | *
36 | * Permission to use, copy, modify and distribute this software and its
37 | * documentation is hereby granted, provided that both the copyright
38 | * notice and this permission notice appear in all copies of the
39 | * software, derivative works or modified versions, and any portions
40 | * thereof, and that both notices appear in supporting documentation.
41 | *
42 | * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
43 | * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
44 | * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
45 | *
46 | * Carnegie Mellon requests users of this software to return to
47 | *
48 | * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
49 | * School of Computer Science
50 | * Carnegie Mellon University
51 | * Pittsburgh PA 15213-3890
52 | *
53 | * any improvements or extensions that they make and grant Carnegie Mellon
54 | * the rights to redistribute these changes.
55 | */
56 | /*
57 | */
58 | /*
59 | * File: mach/vm_prot.h
60 | * Author: Avadis Tevanian, Jr., Michael Wayne Young
61 | *
62 | * Virtual memory protection definitions.
63 | *
64 | */
65 |
66 | #ifndef _MACH_VM_PROT_H_
67 | #define _MACH_VM_PROT_H_
68 |
69 | /*
70 | * Types defined:
71 | *
72 | * vm_prot_t VM protection values.
73 | */
74 |
75 | typedef int vm_prot_t;
76 |
77 | /*
78 | * Protection values, defined as bits within the vm_prot_t type
79 | */
80 |
81 | #define VM_PROT_NONE ((vm_prot_t) 0x00)
82 |
83 | #define VM_PROT_READ ((vm_prot_t) 0x01) /* read permission */
84 | #define VM_PROT_WRITE ((vm_prot_t) 0x02) /* write permission */
85 | #define VM_PROT_EXECUTE ((vm_prot_t) 0x04) /* execute permission */
86 |
87 | /*
88 | * The default protection for newly-created virtual memory
89 | */
90 |
91 | #define VM_PROT_DEFAULT (VM_PROT_READ|VM_PROT_WRITE)
92 |
93 | /*
94 | * The maximum privileges possible, for parameter checking.
95 | */
96 |
97 | #define VM_PROT_ALL (VM_PROT_READ|VM_PROT_WRITE|VM_PROT_EXECUTE)
98 |
99 | /*
100 | * An invalid protection value.
101 | * Used only by memory_object_lock_request to indicate no change
102 | * to page locks. Using -1 here is a bad idea because it
103 | * looks like VM_PROT_ALL and then some.
104 | */
105 |
106 | #define VM_PROT_NO_CHANGE ((vm_prot_t) 0x08)
107 |
108 | /*
109 | * When a caller finds that he cannot obtain write permission on a
110 | * mapped entry, the following flag can be used. The entry will
111 | * be made "needs copy" effectively copying the object (using COW),
112 | * and write permission will be added to the maximum protections
113 | * for the associated entry.
114 | */
115 |
116 | #define VM_PROT_COPY ((vm_prot_t) 0x10)
117 |
118 |
119 | /*
120 | * Another invalid protection value.
121 | * Used only by memory_object_data_request upon an object
122 | * which has specified a copy_call copy strategy. It is used
123 | * when the kernel wants a page belonging to a copy of the
124 | * object, and is only asking the object as a result of
125 | * following a shadow chain. This solves the race between pages
126 | * being pushed up by the memory manager and the kernel
127 | * walking down the shadow chain.
128 | */
129 |
130 | #define VM_PROT_WANTS_COPY ((vm_prot_t) 0x10)
131 |
132 |
133 | #endif /* _MACH_VM_PROT_H_ */
134 |
--------------------------------------------------------------------------------
/binary.cc:
--------------------------------------------------------------------------------
1 | #include "binary.h"
2 |
3 | #include
4 | #include
5 | #include
6 | #include
7 | #include
8 | #include
9 | #include
10 | #include
11 | #include
12 | #include
13 |
14 | #include
15 |
16 | #define Elf_Ehdr Elf64_Ehdr
17 | #define Elf_Shdr Elf64_Shdr
18 |
19 | Binary::Binary(int fd, char* p, size_t sz, size_t msz)
20 | : head(NULL),
21 | size(sz),
22 | mapped_head(p),
23 | mapped_size(msz),
24 | debug_info(NULL),
25 | debug_abbrev(NULL),
26 | debug_str(NULL),
27 | debug_info_len(0),
28 | debug_abbrev_len(0),
29 | debug_str_len(0),
30 | is_zipped(false),
31 | reduced_size(0),
32 | fd_(fd) {
33 | }
34 |
35 | static bool isDwarfZip(char* p) {
36 | return !strncmp(p, "\xdfZIP", 4);
37 | }
38 |
39 | template
40 | struct Elf {};
41 | template <>
42 | struct Elf<32> {
43 | typedef Elf32_Ehdr Ehdr;
44 | typedef Elf32_Shdr Shdr;
45 | };
46 | template <>
47 | struct Elf<64> {
48 | typedef Elf64_Ehdr Ehdr;
49 | typedef Elf64_Shdr Shdr;
50 | };
51 |
52 | template
53 | class ELFBinary : public Binary {
54 | public:
55 | typedef typename Elf::Ehdr Elf_Ehdr;
56 | typedef typename Elf::Shdr Elf_Shdr;
57 |
58 | explicit ELFBinary(const char* filename,
59 | int fd, char* p, size_t sz, size_t msz)
60 | : Binary(fd, p, sz, msz) {
61 | reduced_size = 0;
62 | if (isDwarfZip(p)) {
63 | is_zipped = true;
64 | reduced_size = *(uint32_t*)(p + 4);
65 | p += 8;
66 | }
67 |
68 | head = p;
69 |
70 | Elf_Ehdr* ehdr = (Elf_Ehdr*)p;
71 | if (!ehdr->e_shoff || !ehdr->e_shnum)
72 | err(1, "no section header: %s", filename);
73 | if (!ehdr->e_shstrndx)
74 | err(1, "no section name: %s", filename);
75 |
76 | Elf_Shdr* shdr = (Elf_Shdr*)(p + ehdr->e_shoff - reduced_size);
77 | const char* shstr = (const char*)(p + shdr[ehdr->e_shstrndx].sh_offset);
78 | shstr -= reduced_size;
79 | bool debug_info_seen = false;
80 | for (int i = 0; i < ehdr->e_shnum; i++) {
81 | Elf_Shdr* sec = shdr + i;
82 | const char* pos = p + sec->sh_offset;
83 | if (debug_info_seen)
84 | pos -= reduced_size;
85 | size_t sz = sec->sh_size;
86 | if (!strcmp(shstr + sec->sh_name, ".debug_info")) {
87 | debug_info = pos;
88 | debug_info_len = sz - reduced_size;
89 | debug_info_seen = true;
90 | } else if (!strcmp(shstr + sec->sh_name, ".debug_abbrev")) {
91 | debug_abbrev = pos;
92 | debug_abbrev_len = sz;
93 | } else if (!strcmp(shstr + sec->sh_name, ".debug_str")) {
94 | debug_str = pos;
95 | debug_str_len = sz;
96 | }
97 | }
98 |
99 | if (!debug_info || !debug_abbrev || !debug_str)
100 | err(1, "no debug info: %s", filename);
101 | }
102 |
103 | ~ELFBinary() {
104 | munmap(head, mapped_size);
105 | close(fd_);
106 | }
107 |
108 | static int getELFBit(const char* p) {
109 | if (strncmp(p, ELFMAG, SELFMAG))
110 | return 0;
111 | if (p[EI_CLASS] == ELFCLASS64)
112 | return 64;
113 | if (p[EI_CLASS] == ELFCLASS32)
114 | return 32;
115 | err(1, "Unknown ELF class");
116 | }
117 | };
118 |
119 | #if 0
120 |
121 | #include
122 |
123 | class MachOBinary : public Binary {
124 | public:
125 | explicit MachOBinary(const char* filename,
126 | int fd, char* p, size_t sz, size_t msz)
127 | : Binary(fd, p, sz, msz) {
128 | reduced_size = 0;
129 | if (isDwarfZip(p)) {
130 | is_zipped = true;
131 | reduced_size = *(uint32_t*)(p + 4);
132 | p += 8;
133 | }
134 |
135 | head = p;
136 |
137 | mach_header* header = reinterpret_cast(p);
138 | p += sizeof(mach_header_64);
139 | struct load_command* cmds_ptr = reinterpret_cast(p);
140 |
141 | for (uint32_t i = 0; i < header->ncmds; i++) {
142 | switch (cmds_ptr->cmd) {
143 | case LC_SEGMENT_64: {
144 | segment_command_64* segment =
145 | reinterpret_cast(cmds_ptr);
146 |
147 | section_64* sections = reinterpret_cast(
148 | reinterpret_cast(cmds_ptr) + sizeof(segment_command_64));
149 |
150 | for (uint32_t j = 0; j < segment->nsects; j++) {
151 | const section_64& sec = sections[j];
152 | if (strcmp(sec.segname, "__DWARF"))
153 | continue;
154 | const char* pos = head + sec.offset;
155 | size_t sz = sec.size;
156 | if (!strcmp(sec.sectname, "__debug_info")) {
157 | debug_info = pos;
158 | debug_info_len = sz;
159 | } else if (!strcmp(sec.sectname, "__debug_abbrev")) {
160 | debug_abbrev = pos;
161 | debug_abbrev_len = sz;
162 | } else if (!strcmp(sec.sectname, "__debug_str")) {
163 | debug_str = pos;
164 | debug_str_len = sz;
165 | }
166 | }
167 |
168 | break;
169 | }
170 | }
171 |
172 | cmds_ptr = reinterpret_cast(
173 | reinterpret_cast(cmds_ptr) + cmds_ptr->cmdsize);
174 | }
175 |
176 | if (!debug_info || !debug_abbrev || !debug_str)
177 | err(1, "no debug info: %s", filename);
178 | }
179 |
180 | static bool isMachO(const char* p) {
181 | const mach_header* header = reinterpret_cast(p);
182 | if (header->magic == MH_MAGIC_64) {
183 | return true;
184 | }
185 | if (header->magic == MH_MAGIC) {
186 | err(1, "non 64bit Mach-O isn't supported yet");
187 | }
188 | return false;
189 | }
190 | };
191 |
192 | #endif
193 |
194 | Binary* readBinary(const char* filename) {
195 | int fd = open(filename, O_RDONLY);
196 | if (fd < 0)
197 | err(1, "open failed: %s", filename);
198 |
199 | size_t size = lseek(fd, 0, SEEK_END);
200 | if (size < 8 + 16)
201 | err(1, "too small file: %s", filename);
202 |
203 | size_t mapped_size = (size + 0xfff) & ~0xfff;
204 |
205 | char* p = (char*)mmap(NULL, mapped_size,
206 | PROT_READ, MAP_SHARED,
207 | fd, 0);
208 | if (p == MAP_FAILED)
209 | err(1, "mmap failed: %s", filename);
210 |
211 | char* header = p;
212 | if (isDwarfZip(header)) {
213 | header += 8;
214 | }
215 | int elf_bit = ELFBinary<32>::getELFBit(header);
216 | if (elf_bit) {
217 | if (elf_bit == 32)
218 | return new ELFBinary<32>(filename, fd, p, size, mapped_size);
219 | else
220 | return new ELFBinary<64>(filename, fd, p, size, mapped_size);
221 | #if 0
222 | } else if (MachOBinary::isMachO(header)) {
223 | return new MachOBinary(filename, fd, p, size, mapped_size);
224 | #endif
225 | }
226 | err(1, "unknown file format: %s", filename);
227 | }
228 |
--------------------------------------------------------------------------------
/scanner.cc:
--------------------------------------------------------------------------------
1 | #include "scanner.h"
2 |
3 | #include
4 | #include
5 | #include
6 | #include
7 | #include
8 |
9 | #include
10 |
11 | #include "binary.h"
12 |
13 | using namespace std;
14 |
15 | struct Attr {
16 | uint16_t name;
17 | uint8_t form;
18 | };
19 |
20 | struct Abbrev {
21 | uint16_t tag;
22 | bool has_children;
23 | vector attrs;
24 | };
25 |
26 | static uint64_t uleb128(const uint8_t*& p) {
27 | uint64_t r = 0;
28 | int s = 0;
29 | do {
30 | r |= (uint64_t)(*p & 0x7f) << s;
31 | s += 7;
32 | } while (*p++ >= 0x80);
33 | return r;
34 | }
35 |
36 | static int64_t sleb128(const uint8_t*& p) {
37 | int64_t r = 0;
38 | int s = 0;
39 | for (;;) {
40 | uint8_t b = *p++;
41 | if (b < 0x80) {
42 | if (b & 0x40) {
43 | r -= (0x80 - b) << s;
44 | }
45 | else {
46 | r |= (b & 0x3f) << s;
47 | }
48 | break;
49 | }
50 | r |= (b & 0x7f) << s;
51 | s += 7;
52 | }
53 | return r;
54 | }
55 |
56 | template
57 | static void bug(const char* fmt, T v) {
58 | fprintf(stderr, fmt, v);
59 | abort();
60 | }
61 |
62 | Scanner::Scanner(Binary* binary)
63 | : binary_(binary) {
64 | }
65 |
66 | static void parseAbbrev(const uint8_t* p, vector* abbrevs) {
67 | while (true) {
68 | uint64_t number = uleb128(p);
69 | if (!number)
70 | break;
71 |
72 | abbrevs->resize(number + 1);
73 | Abbrev* abbrev = &(*abbrevs)[number];
74 | abbrev->tag = uleb128(p);
75 | abbrev->has_children = *p++;
76 | while (true) {
77 | Attr attr;
78 | attr.name = uleb128(p);
79 | attr.form = *p++;
80 | //printf("abbrev attr parsed: %x %x\n", attr.name, attr.form);
81 | if (!attr.name)
82 | break;
83 | abbrev->attrs.push_back(attr);
84 | }
85 | //printf("abbrev parsed: %d %d %d\n",
86 | // abbrev->tag, abbrev->has_children, (int)abbrev->attrs.size());
87 | }
88 | }
89 |
90 | void Scanner::run() {
91 | const uint8_t* dinfo_start = (const uint8_t*)binary_->debug_info;
92 | const uint8_t* dinfo = (const uint8_t*)binary_->debug_info;
93 | const uint8_t* dabbrev = (const uint8_t*)binary_->debug_abbrev;
94 | // const char* dstr = binary_->debug_str;
95 | const uint8_t* dinfo_end = dinfo + binary_->debug_info_len;
96 |
97 | vector abbrevs;
98 | const uint8_t* p = dinfo;
99 |
100 | while (p + sizeof(CU) < dinfo_end) {
101 | CU* cu = (CU*)p;
102 | if (cu->length == 0 || cu->length == 0xffffffff) {
103 | bug("unimplemented cu length: %x\n", cu->length);
104 | }
105 |
106 | const uint8_t* cu_end = p + cu->length + 4;
107 |
108 | onCU(cu, p - dinfo_start);
109 | p += sizeof(CU);
110 |
111 | abbrevs.clear();
112 | parseAbbrev(dabbrev + cu->abbrev_offset, &abbrevs);
113 | //printf("COME abbrevs=%d abbrev_offset=%d\n",
114 | // (int)abbrevs.size(), (int)cu->abbrev_offset);
115 |
116 | int depth = 0;
117 |
118 | while (p < cu_end) {
119 | const uint8_t* abb_p = p;
120 | uint64_t abbrev_number = uleb128(p);
121 | //printf("abbrev_number: %d\n", (int)abbrev_number);
122 | assert(abbrev_number < abbrevs.size());
123 |
124 | if (abbrev_number == 0) {
125 | depth--;
126 | if (depth == 0)
127 | break;
128 | continue;
129 | }
130 |
131 | assert(p < cu_end);
132 |
133 | const Abbrev& abbrev = abbrevs[abbrev_number];
134 | if (abbrev.has_children)
135 | depth++;
136 |
137 | bool will_care = onAbbrev(abbrev.tag, abbrev_number,
138 | abb_p - dinfo_start);
139 |
140 | for (size_t i = 0; i < abbrev.attrs.size(); i++) {
141 | const uint8_t* attr_p = p;
142 | const Attr attr = abbrev.attrs[i];
143 | uint64_t value = 0xffffffffffffffff;
144 | //printf("name=%x form=%x\n", attr.name, attr.form);
145 |
146 | switch (attr.form) {
147 | case DW_FORM_addr:
148 | case DW_FORM_ref_addr:
149 | if (binary_->is_zipped && cu->ptrsize == 8) {
150 | value = sleb128(p);
151 | } else {
152 | value = (cu->ptrsize == 8 ? *(uint64_t*)p :
153 | cu->ptrsize == 4 ? *(uint32_t*)p :
154 | cu->ptrsize == 2 ? *(uint16_t*)p :
155 | (bug("Unknown ptrsize: %d\n", cu->ptrsize), 0));
156 | p += cu->ptrsize;
157 | }
158 | break;
159 |
160 | case DW_FORM_block1: {
161 | value = (uint64_t)p;
162 | uint8_t size = *p++;
163 | p += size;
164 | break;
165 | }
166 |
167 | case DW_FORM_block2: {
168 | value = (uint64_t)p;
169 | uint16_t size = *(uint16_t*)p;
170 | p += 2;
171 | p += size;
172 | break;
173 | }
174 |
175 | case DW_FORM_block4: {
176 | value = (uint64_t)p;
177 | uint32_t size = *(uint32_t*)p;
178 | p += 4;
179 | p += size;
180 | break;
181 | }
182 |
183 | case DW_FORM_block:
184 | case DW_FORM_exprloc: {
185 | value = (uint64_t)p;
186 | uint64_t size = uleb128(p);
187 | p += size;
188 | break;
189 | }
190 |
191 | case DW_FORM_data1:
192 | case DW_FORM_ref1:
193 | case DW_FORM_flag:
194 | value = *p++;
195 | break;
196 |
197 | case DW_FORM_data2:
198 | case DW_FORM_ref2:
199 | value = *(uint16_t*)p;
200 | p += 2;
201 | break;
202 |
203 | case DW_FORM_strp:
204 | case DW_FORM_data4:
205 | case DW_FORM_ref4:
206 | case DW_FORM_sec_offset:
207 | // TODO: Consider offset_size for DW_FORM_strp
208 | if (binary_->is_zipped) {
209 | value = sleb128(p);
210 | } else {
211 | value = *(uint32_t*)p;
212 | p += 4;
213 | }
214 | break;
215 |
216 | case DW_FORM_data8:
217 | case DW_FORM_ref8:
218 | value = *(uint64_t*)p;
219 | p += 8;
220 | break;
221 |
222 | case DW_FORM_string:
223 | value = (uint64_t)p;
224 | p += strlen((char*)p) + 1;
225 | break;
226 |
227 | case DW_FORM_sdata:
228 | value = (uint64_t)sleb128(p);
229 | break;
230 |
231 | case DW_FORM_udata:
232 | value = (uint64_t)uleb128(p);
233 | break;
234 |
235 | case DW_FORM_flag_present:
236 | break;
237 |
238 | case DW_FORM_ref_udata:
239 | case DW_FORM_indirect:
240 | case DW_FORM_ref_sig8:
241 |
242 | default:
243 | bug("Unknown DW_FORM: %x\n", attr.form);
244 | }
245 |
246 | if (will_care)
247 | onAttr(attr.name, attr.form, value, attr_p - dinfo_start);
248 | }
249 | if (will_care)
250 | onAbbrevDone();
251 | }
252 |
253 | if (!binary_->is_zipped)
254 | assert(p == cu_end);
255 | }
256 |
257 | assert(p == dinfo_end);
258 | }
259 |
--------------------------------------------------------------------------------
/mach/machine.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2000-2007 Apple Computer, Inc. All rights reserved.
3 | *
4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5 | *
6 | * This file contains Original Code and/or Modifications of Original Code
7 | * as defined in and that are subject to the Apple Public Source License
8 | * Version 2.0 (the 'License'). You may not use this file except in
9 | * compliance with the License. The rights granted to you under the License
10 | * may not be used to create, or enable the creation or redistribution of,
11 | * unlawful or unlicensed copies of an Apple operating system, or to
12 | * circumvent, violate, or enable the circumvention or violation of, any
13 | * terms of an Apple operating system software license agreement.
14 | *
15 | * Please obtain a copy of the License at
16 | * http://www.opensource.apple.com/apsl/ and read it before using this file.
17 | *
18 | * The Original Code and all software distributed under the License are
19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 | * Please see the License for the specific language governing rights and
24 | * limitations under the License.
25 | *
26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27 | */
28 | /*
29 | * Mach Operating System
30 | * Copyright (c) 1991,1990,1989,1988,1987 Carnegie Mellon University
31 | * All Rights Reserved.
32 | *
33 | * Permission to use, copy, modify and distribute this software and its
34 | * documentation is hereby granted, provided that both the copyright
35 | * notice and this permission notice appear in all copies of the
36 | * software, derivative works or modified versions, and any portions
37 | * thereof, and that both notices appear in supporting documentation.
38 | *
39 | * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
40 | * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
41 | * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
42 | *
43 | * Carnegie Mellon requests users of this software to return to
44 | *
45 | * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
46 | * School of Computer Science
47 | * Carnegie Mellon University
48 | * Pittsburgh PA 15213-3890
49 | *
50 | * any improvements or extensions that they make and grant Carnegie Mellon
51 | * the rights to redistribute these changes.
52 | */
53 | /* File: machine.h
54 | * Author: Avadis Tevanian, Jr.
55 | * Date: 1986
56 | *
57 | * Machine independent machine abstraction.
58 | */
59 |
60 | #ifndef _MACH_MACHINE_H_
61 | #define _MACH_MACHINE_H_
62 |
63 | #include
64 | //#include
65 | //#include
66 |
67 | typedef uint32_t integer_t;
68 |
69 | typedef integer_t cpu_type_t;
70 | typedef integer_t cpu_subtype_t;
71 | typedef integer_t cpu_threadtype_t;
72 |
73 | #define CPU_STATE_MAX 4
74 |
75 | #define CPU_STATE_USER 0
76 | #define CPU_STATE_SYSTEM 1
77 | #define CPU_STATE_IDLE 2
78 | #define CPU_STATE_NICE 3
79 |
80 |
81 |
82 | /*
83 | * Capability bits used in the definition of cpu_type.
84 | */
85 | #define CPU_ARCH_MASK 0xff000000 /* mask for architecture bits */
86 | #define CPU_ARCH_ABI64 0x01000000 /* 64 bit ABI */
87 |
88 | /*
89 | * Machine types known by all.
90 | */
91 |
92 | #define CPU_TYPE_ANY ((cpu_type_t) -1)
93 |
94 | #define CPU_TYPE_VAX ((cpu_type_t) 1)
95 | /* skip ((cpu_type_t) 2) */
96 | /* skip ((cpu_type_t) 3) */
97 | /* skip ((cpu_type_t) 4) */
98 | /* skip ((cpu_type_t) 5) */
99 | #define CPU_TYPE_MC680x0 ((cpu_type_t) 6)
100 | #define CPU_TYPE_X86 ((cpu_type_t) 7)
101 | #define CPU_TYPE_I386 CPU_TYPE_X86 /* compatibility */
102 | #define CPU_TYPE_X86_64 (CPU_TYPE_X86 | CPU_ARCH_ABI64)
103 |
104 | /* skip CPU_TYPE_MIPS ((cpu_type_t) 8) */
105 | /* skip ((cpu_type_t) 9) */
106 | #define CPU_TYPE_MC98000 ((cpu_type_t) 10)
107 | #define CPU_TYPE_HPPA ((cpu_type_t) 11)
108 | #define CPU_TYPE_ARM ((cpu_type_t) 12)
109 | #define CPU_TYPE_MC88000 ((cpu_type_t) 13)
110 | #define CPU_TYPE_SPARC ((cpu_type_t) 14)
111 | #define CPU_TYPE_I860 ((cpu_type_t) 15)
112 | /* skip CPU_TYPE_ALPHA ((cpu_type_t) 16) */
113 | /* skip ((cpu_type_t) 17) */
114 | #define CPU_TYPE_POWERPC ((cpu_type_t) 18)
115 | #define CPU_TYPE_POWERPC64 (CPU_TYPE_POWERPC | CPU_ARCH_ABI64)
116 |
117 | /*
118 | * Machine subtypes (these are defined here, instead of in a machine
119 | * dependent directory, so that any program can get all definitions
120 | * regardless of where is it compiled).
121 | */
122 |
123 | /*
124 | * Capability bits used in the definition of cpu_subtype.
125 | */
126 | #define CPU_SUBTYPE_MASK 0xff000000 /* mask for feature flags */
127 | #define CPU_SUBTYPE_LIB64 0x80000000 /* 64 bit libraries */
128 |
129 |
130 | /*
131 | * Object files that are hand-crafted to run on any
132 | * implementation of an architecture are tagged with
133 | * CPU_SUBTYPE_MULTIPLE. This functions essentially the same as
134 | * the "ALL" subtype of an architecture except that it allows us
135 | * to easily find object files that may need to be modified
136 | * whenever a new implementation of an architecture comes out.
137 | *
138 | * It is the responsibility of the implementor to make sure the
139 | * software handles unsupported implementations elegantly.
140 | */
141 | #define CPU_SUBTYPE_MULTIPLE ((cpu_subtype_t) -1)
142 | #define CPU_SUBTYPE_LITTLE_ENDIAN ((cpu_subtype_t) 0)
143 | #define CPU_SUBTYPE_BIG_ENDIAN ((cpu_subtype_t) 1)
144 |
145 | /*
146 | * Machine threadtypes.
147 | * This is none - not defined - for most machine types/subtypes.
148 | */
149 | #define CPU_THREADTYPE_NONE ((cpu_threadtype_t) 0)
150 |
151 | /*
152 | * VAX subtypes (these do *not* necessary conform to the actual cpu
153 | * ID assigned by DEC available via the SID register).
154 | */
155 |
156 | #define CPU_SUBTYPE_VAX_ALL ((cpu_subtype_t) 0)
157 | #define CPU_SUBTYPE_VAX780 ((cpu_subtype_t) 1)
158 | #define CPU_SUBTYPE_VAX785 ((cpu_subtype_t) 2)
159 | #define CPU_SUBTYPE_VAX750 ((cpu_subtype_t) 3)
160 | #define CPU_SUBTYPE_VAX730 ((cpu_subtype_t) 4)
161 | #define CPU_SUBTYPE_UVAXI ((cpu_subtype_t) 5)
162 | #define CPU_SUBTYPE_UVAXII ((cpu_subtype_t) 6)
163 | #define CPU_SUBTYPE_VAX8200 ((cpu_subtype_t) 7)
164 | #define CPU_SUBTYPE_VAX8500 ((cpu_subtype_t) 8)
165 | #define CPU_SUBTYPE_VAX8600 ((cpu_subtype_t) 9)
166 | #define CPU_SUBTYPE_VAX8650 ((cpu_subtype_t) 10)
167 | #define CPU_SUBTYPE_VAX8800 ((cpu_subtype_t) 11)
168 | #define CPU_SUBTYPE_UVAXIII ((cpu_subtype_t) 12)
169 |
170 | /*
171 | * 680x0 subtypes
172 | *
173 | * The subtype definitions here are unusual for historical reasons.
174 | * NeXT used to consider 68030 code as generic 68000 code. For
175 | * backwards compatability:
176 | *
177 | * CPU_SUBTYPE_MC68030 symbol has been preserved for source code
178 | * compatability.
179 | *
180 | * CPU_SUBTYPE_MC680x0_ALL has been defined to be the same
181 | * subtype as CPU_SUBTYPE_MC68030 for binary comatability.
182 | *
183 | * CPU_SUBTYPE_MC68030_ONLY has been added to allow new object
184 | * files to be tagged as containing 68030-specific instructions.
185 | */
186 |
187 | #define CPU_SUBTYPE_MC680x0_ALL ((cpu_subtype_t) 1)
188 | #define CPU_SUBTYPE_MC68030 ((cpu_subtype_t) 1) /* compat */
189 | #define CPU_SUBTYPE_MC68040 ((cpu_subtype_t) 2)
190 | #define CPU_SUBTYPE_MC68030_ONLY ((cpu_subtype_t) 3)
191 |
192 | /*
193 | * I386 subtypes
194 | */
195 |
196 | #define CPU_SUBTYPE_INTEL(f, m) ((cpu_subtype_t) (f) + ((m) << 4))
197 |
198 | #define CPU_SUBTYPE_I386_ALL CPU_SUBTYPE_INTEL(3, 0)
199 | #define CPU_SUBTYPE_386 CPU_SUBTYPE_INTEL(3, 0)
200 | #define CPU_SUBTYPE_486 CPU_SUBTYPE_INTEL(4, 0)
201 | #define CPU_SUBTYPE_486SX CPU_SUBTYPE_INTEL(4, 8) // 8 << 4 = 128
202 | #define CPU_SUBTYPE_586 CPU_SUBTYPE_INTEL(5, 0)
203 | #define CPU_SUBTYPE_PENT CPU_SUBTYPE_INTEL(5, 0)
204 | #define CPU_SUBTYPE_PENTPRO CPU_SUBTYPE_INTEL(6, 1)
205 | #define CPU_SUBTYPE_PENTII_M3 CPU_SUBTYPE_INTEL(6, 3)
206 | #define CPU_SUBTYPE_PENTII_M5 CPU_SUBTYPE_INTEL(6, 5)
207 | #define CPU_SUBTYPE_CELERON CPU_SUBTYPE_INTEL(7, 6)
208 | #define CPU_SUBTYPE_CELERON_MOBILE CPU_SUBTYPE_INTEL(7, 7)
209 | #define CPU_SUBTYPE_PENTIUM_3 CPU_SUBTYPE_INTEL(8, 0)
210 | #define CPU_SUBTYPE_PENTIUM_3_M CPU_SUBTYPE_INTEL(8, 1)
211 | #define CPU_SUBTYPE_PENTIUM_3_XEON CPU_SUBTYPE_INTEL(8, 2)
212 | #define CPU_SUBTYPE_PENTIUM_M CPU_SUBTYPE_INTEL(9, 0)
213 | #define CPU_SUBTYPE_PENTIUM_4 CPU_SUBTYPE_INTEL(10, 0)
214 | #define CPU_SUBTYPE_PENTIUM_4_M CPU_SUBTYPE_INTEL(10, 1)
215 | #define CPU_SUBTYPE_ITANIUM CPU_SUBTYPE_INTEL(11, 0)
216 | #define CPU_SUBTYPE_ITANIUM_2 CPU_SUBTYPE_INTEL(11, 1)
217 | #define CPU_SUBTYPE_XEON CPU_SUBTYPE_INTEL(12, 0)
218 | #define CPU_SUBTYPE_XEON_MP CPU_SUBTYPE_INTEL(12, 1)
219 |
220 | #define CPU_SUBTYPE_INTEL_FAMILY(x) ((x) & 15)
221 | #define CPU_SUBTYPE_INTEL_FAMILY_MAX 15
222 |
223 | #define CPU_SUBTYPE_INTEL_MODEL(x) ((x) >> 4)
224 | #define CPU_SUBTYPE_INTEL_MODEL_ALL 0
225 |
226 | /*
227 | * X86 subtypes.
228 | */
229 |
230 | #define CPU_SUBTYPE_X86_ALL ((cpu_subtype_t)3)
231 | #define CPU_SUBTYPE_X86_64_ALL ((cpu_subtype_t)3)
232 | #define CPU_SUBTYPE_X86_ARCH1 ((cpu_subtype_t)4)
233 |
234 |
235 | #define CPU_THREADTYPE_INTEL_HTT ((cpu_threadtype_t) 1)
236 |
237 | /*
238 | * Mips subtypes.
239 | */
240 |
241 | #define CPU_SUBTYPE_MIPS_ALL ((cpu_subtype_t) 0)
242 | #define CPU_SUBTYPE_MIPS_R2300 ((cpu_subtype_t) 1)
243 | #define CPU_SUBTYPE_MIPS_R2600 ((cpu_subtype_t) 2)
244 | #define CPU_SUBTYPE_MIPS_R2800 ((cpu_subtype_t) 3)
245 | #define CPU_SUBTYPE_MIPS_R2000a ((cpu_subtype_t) 4) /* pmax */
246 | #define CPU_SUBTYPE_MIPS_R2000 ((cpu_subtype_t) 5)
247 | #define CPU_SUBTYPE_MIPS_R3000a ((cpu_subtype_t) 6) /* 3max */
248 | #define CPU_SUBTYPE_MIPS_R3000 ((cpu_subtype_t) 7)
249 |
250 | /*
251 | * MC98000 (PowerPC) subtypes
252 | */
253 | #define CPU_SUBTYPE_MC98000_ALL ((cpu_subtype_t) 0)
254 | #define CPU_SUBTYPE_MC98601 ((cpu_subtype_t) 1)
255 |
256 | /*
257 | * HPPA subtypes for Hewlett-Packard HP-PA family of
258 | * risc processors. Port by NeXT to 700 series.
259 | */
260 |
261 | #define CPU_SUBTYPE_HPPA_ALL ((cpu_subtype_t) 0)
262 | #define CPU_SUBTYPE_HPPA_7100 ((cpu_subtype_t) 0) /* compat */
263 | #define CPU_SUBTYPE_HPPA_7100LC ((cpu_subtype_t) 1)
264 |
265 | /*
266 | * MC88000 subtypes.
267 | */
268 | #define CPU_SUBTYPE_MC88000_ALL ((cpu_subtype_t) 0)
269 | #define CPU_SUBTYPE_MC88100 ((cpu_subtype_t) 1)
270 | #define CPU_SUBTYPE_MC88110 ((cpu_subtype_t) 2)
271 |
272 | /*
273 | * SPARC subtypes
274 | */
275 | #define CPU_SUBTYPE_SPARC_ALL ((cpu_subtype_t) 0)
276 |
277 | /*
278 | * I860 subtypes
279 | */
280 | #define CPU_SUBTYPE_I860_ALL ((cpu_subtype_t) 0)
281 | #define CPU_SUBTYPE_I860_860 ((cpu_subtype_t) 1)
282 |
283 | /*
284 | * PowerPC subtypes
285 | */
286 | #define CPU_SUBTYPE_POWERPC_ALL ((cpu_subtype_t) 0)
287 | #define CPU_SUBTYPE_POWERPC_601 ((cpu_subtype_t) 1)
288 | #define CPU_SUBTYPE_POWERPC_602 ((cpu_subtype_t) 2)
289 | #define CPU_SUBTYPE_POWERPC_603 ((cpu_subtype_t) 3)
290 | #define CPU_SUBTYPE_POWERPC_603e ((cpu_subtype_t) 4)
291 | #define CPU_SUBTYPE_POWERPC_603ev ((cpu_subtype_t) 5)
292 | #define CPU_SUBTYPE_POWERPC_604 ((cpu_subtype_t) 6)
293 | #define CPU_SUBTYPE_POWERPC_604e ((cpu_subtype_t) 7)
294 | #define CPU_SUBTYPE_POWERPC_620 ((cpu_subtype_t) 8)
295 | #define CPU_SUBTYPE_POWERPC_750 ((cpu_subtype_t) 9)
296 | #define CPU_SUBTYPE_POWERPC_7400 ((cpu_subtype_t) 10)
297 | #define CPU_SUBTYPE_POWERPC_7450 ((cpu_subtype_t) 11)
298 | #define CPU_SUBTYPE_POWERPC_970 ((cpu_subtype_t) 100)
299 |
300 | /*
301 | * ARM subtypes
302 | */
303 | #define CPU_SUBTYPE_ARM_ALL ((cpu_subtype_t) 0)
304 | #define CPU_SUBTYPE_ARM_V4T ((cpu_subtype_t) 5)
305 | #define CPU_SUBTYPE_ARM_V6 ((cpu_subtype_t) 6)
306 | #define CPU_SUBTYPE_ARM_V5TEJ ((cpu_subtype_t) 7)
307 | #define CPU_SUBTYPE_ARM_XSCALE ((cpu_subtype_t) 8)
308 | #define CPU_SUBTYPE_ARM_V7 ((cpu_subtype_t) 9)
309 |
310 | /*
311 | * CPU families (sysctl hw.cpufamily)
312 | *
313 | * These are meant to identify the CPU's marketing name - an
314 | * application can map these to (possibly) localized strings.
315 | * NB: the encodings of the CPU families are intentionally arbitrary.
316 | * There is no ordering, and you should never try to deduce whether
317 | * or not some feature is available based on the family.
318 | * Use feature flags (eg, hw.optional.altivec) to test for optional
319 | * functionality.
320 | */
321 | #define CPUFAMILY_UNKNOWN 0
322 | #define CPUFAMILY_POWERPC_G3 0xcee41549
323 | #define CPUFAMILY_POWERPC_G4 0x77c184ae
324 | #define CPUFAMILY_POWERPC_G5 0xed76d8aa
325 | #define CPUFAMILY_INTEL_6_13 0xaa33392b
326 | #define CPUFAMILY_INTEL_6_14 0x73d67300 /* "Intel Core Solo" and "Intel Core Duo" (32-bit Pentium-M with SSE3) */
327 | #define CPUFAMILY_INTEL_6_15 0x426f69ef /* "Intel Core 2 Duo" */
328 | #define CPUFAMILY_INTEL_6_23 0x78ea4fbc /* Penryn */
329 | #define CPUFAMILY_INTEL_6_26 0x6b5a4cd2 /* Nehalem */
330 | #define CPUFAMILY_ARM_9 0xe73283ae
331 | #define CPUFAMILY_ARM_11 0x8ff620d8
332 | #define CPUFAMILY_ARM_XSCALE 0x53b005f5
333 | #define CPUFAMILY_ARM_13 0x0cc90e64
334 |
335 | #define CPUFAMILY_INTEL_YONAH CPUFAMILY_INTEL_6_14
336 | #define CPUFAMILY_INTEL_MEROM CPUFAMILY_INTEL_6_15
337 | #define CPUFAMILY_INTEL_PENRYN CPUFAMILY_INTEL_6_23
338 | #define CPUFAMILY_INTEL_NEHALEM CPUFAMILY_INTEL_6_26
339 |
340 | #define CPUFAMILY_INTEL_CORE CPUFAMILY_INTEL_6_14
341 | #define CPUFAMILY_INTEL_CORE2 CPUFAMILY_INTEL_6_15
342 |
343 | #endif /* _MACH_MACHINE_H_ */
344 |
--------------------------------------------------------------------------------
/dump_debug_info.cc:
--------------------------------------------------------------------------------
1 | #define __STDC_FORMAT_MACROS
2 | #include
3 | #include
4 | #include
5 | #include
6 | #include
7 | #include
8 | #include
9 | #include
10 | #include
11 | #include
12 | #include
13 | #include
14 | #include
15 | #include
16 |
17 | #include |