Lines Matching refs:baton
36 struct baton { struct
93 static void scan_macho_load_commands(struct baton *baton) { in scan_macho_load_commands() argument
98 baton->compact_unwind_start = 0; in scan_macho_load_commands()
100 uint32_t *magic = (uint32_t *)baton->mach_header_start; in scan_macho_load_commands()
111 uint8_t *offset = baton->mach_header_start; in scan_macho_load_commands()
121 baton->addr_size = 8; in scan_macho_load_commands()
123 baton->addr_size = 4; in scan_macho_load_commands()
125 baton->cputype = mh.cputype; in scan_macho_load_commands()
173 baton->text_segment_vmaddr = segment_vmaddr; in scan_macho_load_commands()
174 baton->text_segment_file_offset = segment_offset; in scan_macho_load_commands()
187 baton->compact_unwind_start = in scan_macho_load_commands()
188 baton->mach_header_start + sect.offset; in scan_macho_load_commands()
193 baton->compact_unwind_start = in scan_macho_load_commands()
194 baton->mach_header_start + sect.offset; in scan_macho_load_commands()
202 baton->eh_section_file_address = sect.addr; in scan_macho_load_commands()
207 baton->eh_section_file_address = sect.addr; in scan_macho_load_commands()
215 baton->text_section_vmaddr = sect.addr; in scan_macho_load_commands()
216 baton->text_section_file_offset = sect.offset; in scan_macho_load_commands()
221 baton->text_section_vmaddr = sect.addr; in scan_macho_load_commands()
251 (char *)(baton->mach_header_start + symtab_cmd.stroff); in scan_macho_load_commands()
252 uint8_t *local_syms = baton->mach_header_start + symtab_cmd.symoff + in scan_macho_load_commands()
255 uint8_t *exported_syms = baton->mach_header_start + symtab_cmd.symoff + in scan_macho_load_commands()
263 baton->symbols = (struct symbol *)malloc( in scan_macho_load_commands()
265 baton->symbols_count = 0; in scan_macho_load_commands()
287 nlist.n_value != 0 && nlist.n_value != baton->text_segment_vmaddr) { in scan_macho_load_commands()
288 baton->symbols[baton->symbols_count].file_address = nlist.n_value; in scan_macho_load_commands()
289 if (baton->cputype == CPU_TYPE_ARM) in scan_macho_load_commands()
290 baton->symbols[baton->symbols_count].file_address = in scan_macho_load_commands()
291 baton->symbols[baton->symbols_count].file_address & ~1; in scan_macho_load_commands()
292 baton->symbols[baton->symbols_count].name = in scan_macho_load_commands()
294 baton->symbols_count++; in scan_macho_load_commands()
317 nlist.n_value != 0 && nlist.n_value != baton->text_segment_vmaddr) { in scan_macho_load_commands()
318 baton->symbols[baton->symbols_count].file_address = nlist.n_value; in scan_macho_load_commands()
319 if (baton->cputype == CPU_TYPE_ARM) in scan_macho_load_commands()
320 baton->symbols[baton->symbols_count].file_address = in scan_macho_load_commands()
321 baton->symbols[baton->symbols_count].file_address & ~1; in scan_macho_load_commands()
322 baton->symbols[baton->symbols_count].name = in scan_macho_load_commands()
324 baton->symbols_count++; in scan_macho_load_commands()
328 qsort(baton->symbols, baton->symbols_count, sizeof(struct symbol), in scan_macho_load_commands()
338 baton->mach_header_start + function_starts_cmd.dataoff; in scan_macho_load_commands()
348 baton->function_start_addresses = in scan_macho_load_commands()
350 baton->function_start_addresses_count = count; in scan_macho_load_commands()
353 baton->mach_header_start + function_starts_cmd.dataoff; in scan_macho_load_commands()
354 uint64_t current_pc = baton->text_segment_vmaddr; in scan_macho_load_commands()
360 baton->function_start_addresses[i++] = current_pc; in scan_macho_load_commands()
374 for (int i = 0; i < baton->function_start_addresses_count; i++) { in scan_macho_load_commands()
376 search_key.file_address = baton->function_start_addresses[i]; in scan_macho_load_commands()
377 if (baton->cputype == CPU_TYPE_ARM) in scan_macho_load_commands()
380 bsearch(&search_key, baton->symbols, baton->symbols_count, in scan_macho_load_commands()
386 baton->symbols = (struct symbol *)realloc( in scan_macho_load_commands()
387 baton->symbols, sizeof(struct symbol) * in scan_macho_load_commands()
388 (baton->symbols_count + unnamed_functions_to_add)); in scan_macho_load_commands()
392 for (int i = 0; i < baton->function_start_addresses_count; i++) { in scan_macho_load_commands()
394 search_key.file_address = baton->function_start_addresses[i]; in scan_macho_load_commands()
395 if (baton->cputype == CPU_TYPE_ARM) in scan_macho_load_commands()
398 bsearch(&search_key, baton->symbols, baton->symbols_count, in scan_macho_load_commands()
403 baton->symbols[baton->symbols_count + number_symbols_added].file_address = in scan_macho_load_commands()
404 baton->function_start_addresses[i]; in scan_macho_load_commands()
405 baton->symbols[baton->symbols_count + number_symbols_added].name = name; in scan_macho_load_commands()
409 baton->symbols_count += number_symbols_added; in scan_macho_load_commands()
410 qsort(baton->symbols, baton->symbols_count, sizeof(struct symbol), in scan_macho_load_commands()
427 void print_encoding_x86_64(struct baton baton, uint8_t *function_start, in print_encoding_x86_64() argument
634 dwarf_offset, dwarf_offset + baton.eh_section_file_address); in print_encoding_x86_64()
643 void print_encoding_i386(struct baton baton, uint8_t *function_start, in print_encoding_i386() argument
850 dwarf_offset, dwarf_offset + baton.eh_section_file_address); in print_encoding_i386()
859 void print_encoding_arm64(struct baton baton, uint8_t *function_start, in print_encoding_arm64() argument
955 dwarf_offset, dwarf_offset + baton.eh_section_file_address); in print_encoding_arm64()
964 void print_encoding_armv7(struct baton baton, uint8_t *function_start, in print_encoding_armv7() argument
1093 dwarf_offset, dwarf_offset + baton.eh_section_file_address); in print_encoding_armv7()
1102 void print_encoding(struct baton baton, uint8_t *function_start, in print_encoding() argument
1105 if (baton.cputype == CPU_TYPE_X86_64) { in print_encoding()
1106 print_encoding_x86_64(baton, function_start, encoding); in print_encoding()
1107 } else if (baton.cputype == CPU_TYPE_I386) { in print_encoding()
1108 print_encoding_i386(baton, function_start, encoding); in print_encoding()
1109 } else if (baton.cputype == CPU_TYPE_ARM64 || baton.cputype == CPU_TYPE_ARM64_32) { in print_encoding()
1110 print_encoding_arm64(baton, function_start, encoding); in print_encoding()
1111 } else if (baton.cputype == CPU_TYPE_ARM) { in print_encoding()
1112 print_encoding_armv7(baton, function_start, encoding); in print_encoding()
1118 void print_function_encoding(struct baton baton, uint32_t idx, in print_function_encoding() argument
1129 uint64_t file_address = baton.first_level_index_entry.functionOffset + in print_function_encoding()
1130 entry_func_offset + baton.text_segment_vmaddr; in print_function_encoding()
1132 if (baton.cputype == CPU_TYPE_ARM) in print_function_encoding()
1140 for (int i = 0; i < baton.symbols_count; i++) { in print_function_encoding()
1141 if (i == baton.symbols_count - 1 && in print_function_encoding()
1142 baton.symbols[i].file_address <= file_address) { in print_function_encoding()
1143 symbol = &(baton.symbols[i]); in print_function_encoding()
1146 if (baton.symbols[i].file_address <= file_address && in print_function_encoding()
1147 baton.symbols[i + 1].file_address > file_address) { in print_function_encoding()
1148 symbol = &(baton.symbols[i]); in print_function_encoding()
1171 print_encoding(baton, baton.mach_header_start + in print_function_encoding()
1172 baton.first_level_index_entry.functionOffset + in print_function_encoding()
1173 baton.text_section_file_offset + entry_func_offset, in print_function_encoding()
1180 entry_func_offset + baton.first_level_index_entry.functionOffset; in print_function_encoding()
1185 uint32_t high = (baton.lsda_array_end - baton.lsda_array_start) / in print_function_encoding()
1192 (baton.lsda_array_start + in print_function_encoding()
1199 (mid_lsda_entry_addr - baton.lsda_array_start) / in print_function_encoding()
1225 void print_second_level_index_regular(struct baton baton) { in print_second_level_index_regular() argument
1227 baton.compact_unwind_start + in print_second_level_index_regular()
1228 baton.first_level_index_entry.secondLevelPagesSectionOffset + in print_second_level_index_regular()
1229 baton.regular_second_level_page_header.entryPageOffset; in print_second_level_index_regular()
1230 uint32_t entries_count = baton.regular_second_level_page_header.entryCount; in print_second_level_index_regular()
1248 print_function_encoding(baton, idx, encoding, (uint32_t)-1, in print_second_level_index_regular()
1250 baton.first_level_index_entry.functionOffset); in print_second_level_index_regular()
1256 void print_second_level_index_compressed(struct baton baton) { in print_second_level_index_compressed() argument
1258 baton.compact_unwind_start + in print_second_level_index_compressed()
1259 baton.first_level_index_entry.secondLevelPagesSectionOffset; in print_second_level_index_compressed()
1261 this_index + baton.compressed_second_level_page_header.entryPageOffset; in print_second_level_index_compressed()
1264 idx < baton.compressed_second_level_page_header.entryCount; idx++) { in print_second_level_index_compressed()
1274 if (entry_encoding_index < baton.unwind_header.commonEncodingsArrayCount) { in print_second_level_index_compressed()
1277 *((uint32_t *)(baton.compact_unwind_start + in print_second_level_index_compressed()
1278 baton.unwind_header.commonEncodingsArraySectionOffset + in print_second_level_index_compressed()
1283 entry_encoding_index - baton.unwind_header.commonEncodingsArrayCount; in print_second_level_index_compressed()
1285 baton.compressed_second_level_page_header in print_second_level_index_compressed()
1290 print_function_encoding(baton, idx, encoding, entry_encoding_index, in print_second_level_index_compressed()
1295 void print_second_level_index(struct baton baton) { in print_second_level_index() argument
1297 baton.compact_unwind_start + in print_second_level_index()
1298 baton.first_level_index_entry.secondLevelPagesSectionOffset; in print_second_level_index()
1306 baton.current_index_table_number, header.entryPageOffset, in print_second_level_index()
1308 baton.regular_second_level_page_header = header; in print_second_level_index()
1309 print_second_level_index_regular(baton); in print_second_level_index()
1318 baton.current_index_table_number, header.entryPageOffset, in print_second_level_index()
1321 baton.compressed_second_level_page_header = header; in print_second_level_index()
1322 print_second_level_index_compressed(baton); in print_second_level_index()
1326 void print_index_sections(struct baton baton) { in print_index_sections() argument
1328 baton.compact_unwind_start + baton.unwind_header.indexSectionOffset; in print_index_sections()
1329 uint32_t index_count = baton.unwind_header.indexCount; in print_index_sections()
1335 baton.current_index_table_number = cur_idx; in print_index_sections()
1352 baton.lsda_array_start = in print_index_sections()
1353 baton.compact_unwind_start + index_entry.lsdaIndexArraySectionOffset; in print_index_sections()
1354 baton.lsda_array_end = baton.compact_unwind_start + in print_index_sections()
1357 uint8_t *lsda_entry_offset = baton.lsda_array_start; in print_index_sections()
1359 while (lsda_entry_offset < baton.lsda_array_end) { in print_index_sections()
1364 baton.first_level_index_entry.functionOffset + in print_index_sections()
1365 lsda_entry.functionOffset + baton.text_segment_vmaddr; in print_index_sections()
1367 lsda_entry.lsdaOffset + baton.text_segment_vmaddr; in print_index_sections()
1380 baton.first_level_index_entry = index_entry; in print_index_sections()
1381 print_second_level_index(baton); in print_index_sections()
1410 struct baton baton; in main() local
1411 baton.mach_header_start = file_mem; in main()
1412 baton.symbols = NULL; in main()
1413 baton.symbols_count = 0; in main()
1414 baton.function_start_addresses = NULL; in main()
1415 baton.function_start_addresses_count = 0; in main()
1417 scan_macho_load_commands(&baton); in main()
1419 if (baton.compact_unwind_start == NULL) { in main()
1425 memcpy(&header, baton.compact_unwind_start, in main()
1440 baton.compact_unwind_start + header.commonEncodingsArraySectionOffset; in main()
1445 print_encoding(baton, NULL, encoding); in main()
1452 baton.compact_unwind_start + header.personalityArraySectionOffset; in main()
1455 int32_t pers_delta = *((int32_t *)(baton.compact_unwind_start + in main()
1460 pers_idx, pers_delta, baton.text_segment_vmaddr + pers_delta); in main()
1467 baton.unwind_header = header; in main()
1469 print_index_sections(baton); in main()