Lines Matching refs:baton

79 struct baton {
136 static void scan_macho_load_commands(struct baton *baton) {
141 baton->compact_unwind_start = 0;
143 uint32_t *magic = (uint32_t *)baton->mach_header_start;
154 uint8_t *offset = baton->mach_header_start;
164 baton->addr_size = 8;
166 baton->addr_size = 4;
168 baton->cputype = mh.cputype;
216 baton->text_segment_vmaddr = segment_vmaddr;
217 baton->text_segment_file_offset = segment_offset;
230 baton->compact_unwind_start =
231 baton->mach_header_start + sect.offset;
236 baton->compact_unwind_start =
237 baton->mach_header_start + sect.offset;
245 baton->eh_section_file_address = sect.addr;
250 baton->eh_section_file_address = sect.addr;
258 baton->text_section_vmaddr = sect.addr;
259 baton->text_section_file_offset = sect.offset;
264 baton->text_section_vmaddr = sect.addr;
294 (char *)(baton->mach_header_start + symtab_cmd.stroff);
295 uint8_t *local_syms = baton->mach_header_start + symtab_cmd.symoff +
298 uint8_t *exported_syms = baton->mach_header_start + symtab_cmd.symoff +
306 baton->symbols = (struct symbol *)malloc(
308 baton->symbols_count = 0;
330 nlist.n_value != 0 && nlist.n_value != baton->text_segment_vmaddr) {
331 baton->symbols[baton->symbols_count].file_address = nlist.n_value;
332 if (baton->cputype == CPU_TYPE_ARM)
333 baton->symbols[baton->symbols_count].file_address =
334 baton->symbols[baton->symbols_count].file_address & ~1;
335 baton->symbols[baton->symbols_count].name =
337 baton->symbols_count++;
360 nlist.n_value != 0 && nlist.n_value != baton->text_segment_vmaddr) {
361 baton->symbols[baton->symbols_count].file_address = nlist.n_value;
362 if (baton->cputype == CPU_TYPE_ARM)
363 baton->symbols[baton->symbols_count].file_address =
364 baton->symbols[baton->symbols_count].file_address & ~1;
365 baton->symbols[baton->symbols_count].name =
367 baton->symbols_count++;
371 qsort(baton->symbols, baton->symbols_count, sizeof(struct symbol),
381 baton->mach_header_start + function_starts_cmd.dataoff;
391 baton->function_start_addresses =
393 baton->function_start_addresses_count = count;
396 baton->mach_header_start + function_starts_cmd.dataoff;
397 uint64_t current_pc = baton->text_segment_vmaddr;
403 baton->function_start_addresses[i++] = current_pc;
417 for (int i = 0; i < baton->function_start_addresses_count; i++) {
419 search_key.file_address = baton->function_start_addresses[i];
420 if (baton->cputype == CPU_TYPE_ARM)
423 bsearch(&search_key, baton->symbols, baton->symbols_count,
429 baton->symbols = (struct symbol *)realloc(
430 baton->symbols, sizeof(struct symbol) *
431 (baton->symbols_count + unnamed_functions_to_add));
435 for (int i = 0; i < baton->function_start_addresses_count; i++) {
437 search_key.file_address = baton->function_start_addresses[i];
438 if (baton->cputype == CPU_TYPE_ARM)
441 bsearch(&search_key, baton->symbols, baton->symbols_count,
446 baton->symbols[baton->symbols_count + number_symbols_added].file_address =
447 baton->function_start_addresses[i];
448 baton->symbols[baton->symbols_count + number_symbols_added].name = name;
452 baton->symbols_count += number_symbols_added;
453 qsort(baton->symbols, baton->symbols_count, sizeof(struct symbol),
457 // for (int i = 0; i < baton->function_start_addresses_count; i++)
459 // printf ("0x%012llx\n", baton->function_start_addresses[i]);
463 // for (int i = 0; i < baton->symbols_count; i++)
465 // printf ("0x%012llx %s\n", baton->symbols[i].file_address,
466 // baton->symbols[i].name);
470 void print_encoding_x86_64(struct baton baton, uint8_t *function_start,
677 dwarf_offset, dwarf_offset + baton.eh_section_file_address);
686 void print_encoding_i386(struct baton baton, uint8_t *function_start,
893 dwarf_offset, dwarf_offset + baton.eh_section_file_address);
902 void print_encoding_arm64(struct baton baton, uint8_t *function_start,
998 dwarf_offset, dwarf_offset + baton.eh_section_file_address);
1007 void print_encoding_armv7(struct baton baton, uint8_t *function_start,
1136 dwarf_offset, dwarf_offset + baton.eh_section_file_address);
1145 void print_encoding(struct baton baton, uint8_t *function_start,
1148 if (baton.cputype == CPU_TYPE_X86_64) {
1149 print_encoding_x86_64(baton, function_start, encoding);
1150 } else if (baton.cputype == CPU_TYPE_I386) {
1151 print_encoding_i386(baton, function_start, encoding);
1152 } else if (baton.cputype == CPU_TYPE_ARM64 || baton.cputype == CPU_TYPE_ARM64_32) {
1153 print_encoding_arm64(baton, function_start, encoding);
1154 } else if (baton.cputype == CPU_TYPE_ARM) {
1155 print_encoding_armv7(baton, function_start, encoding);
1161 void print_function_encoding(struct baton baton, uint32_t idx,
1172 uint64_t file_address = baton.first_level_index_entry.functionOffset +
1173 entry_func_offset + baton.text_segment_vmaddr;
1175 if (baton.cputype == CPU_TYPE_ARM)
1183 for (int i = 0; i < baton.symbols_count; i++) {
1184 if (i == baton.symbols_count - 1 &&
1185 baton.symbols[i].file_address <= file_address) {
1186 symbol = &(baton.symbols[i]);
1189 if (baton.symbols[i].file_address <= file_address &&
1190 baton.symbols[i + 1].file_address > file_address) {
1191 symbol = &(baton.symbols[i]);
1214 print_encoding(baton, baton.mach_header_start +
1215 baton.first_level_index_entry.functionOffset +
1216 baton.text_section_file_offset + entry_func_offset,
1223 entry_func_offset + baton.first_level_index_entry.functionOffset;
1228 uint32_t high = (baton.lsda_array_end - baton.lsda_array_start) /
1235 (baton.lsda_array_start +
1242 (mid_lsda_entry_addr - baton.lsda_array_start) /
1268 void print_second_level_index_regular(struct baton baton) {
1270 baton.compact_unwind_start +
1271 baton.first_level_index_entry.secondLevelPagesSectionOffset +
1272 baton.regular_second_level_page_header.entryPageOffset;
1273 uint32_t entries_count = baton.regular_second_level_page_header.entryCount;
1291 print_function_encoding(baton, idx, encoding, (uint32_t)-1,
1293 baton.first_level_index_entry.functionOffset);
1299 void print_second_level_index_compressed(struct baton baton) {
1301 baton.compact_unwind_start +
1302 baton.first_level_index_entry.secondLevelPagesSectionOffset;
1304 this_index + baton.compressed_second_level_page_header.entryPageOffset;
1307 idx < baton.compressed_second_level_page_header.entryCount; idx++) {
1317 if (entry_encoding_index < baton.unwind_header.commonEncodingsArrayCount) {
1320 *((uint32_t *)(baton.compact_unwind_start +
1321 baton.unwind_header.commonEncodingsArraySectionOffset +
1326 entry_encoding_index - baton.unwind_header.commonEncodingsArrayCount;
1328 baton.compressed_second_level_page_header
1333 print_function_encoding(baton, idx, encoding, entry_encoding_index,
1338 void print_second_level_index(struct baton baton) {
1340 baton.compact_unwind_start +
1341 baton.first_level_index_entry.secondLevelPagesSectionOffset;
1349 baton.current_index_table_number, header.entryPageOffset,
1351 baton.regular_second_level_page_header = header;
1352 print_second_level_index_regular(baton);
1361 baton.current_index_table_number, header.entryPageOffset,
1364 baton.compressed_second_level_page_header = header;
1365 print_second_level_index_compressed(baton);
1369 void print_index_sections(struct baton baton) {
1371 baton.compact_unwind_start + baton.unwind_header.indexSectionOffset;
1372 uint32_t index_count = baton.unwind_header.indexCount;
1378 baton.current_index_table_number = cur_idx;
1395 baton.lsda_array_start =
1396 baton.compact_unwind_start + index_entry.lsdaIndexArraySectionOffset;
1397 baton.lsda_array_end = baton.compact_unwind_start +
1400 uint8_t *lsda_entry_offset = baton.lsda_array_start;
1402 while (lsda_entry_offset < baton.lsda_array_end) {
1407 baton.first_level_index_entry.functionOffset +
1408 lsda_entry.functionOffset + baton.text_segment_vmaddr;
1410 lsda_entry.lsdaOffset + baton.text_segment_vmaddr;
1423 baton.first_level_index_entry = index_entry;
1424 print_second_level_index(baton);
1453 struct baton baton;
1454 baton.mach_header_start = file_mem;
1455 baton.symbols = NULL;
1456 baton.symbols_count = 0;
1457 baton.function_start_addresses = NULL;
1458 baton.function_start_addresses_count = 0;
1460 scan_macho_load_commands(&baton);
1462 if (baton.compact_unwind_start == NULL) {
1468 memcpy(&header, baton.compact_unwind_start,
1483 baton.compact_unwind_start + header.commonEncodingsArraySectionOffset;
1488 print_encoding(baton, NULL, encoding);
1495 baton.compact_unwind_start + header.personalityArraySectionOffset;
1498 int32_t pers_delta = *((int32_t *)(baton.compact_unwind_start +
1503 pers_idx, pers_delta, baton.text_segment_vmaddr + pers_delta);
1510 baton.unwind_header = header;
1512 print_index_sections(baton);