Lines Matching refs:baton

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