Changeset 40eab9f in mainline for kernel/generic/src/debug/line.c
- Timestamp:
- 2023-11-03T18:47:41Z (15 months ago)
- Branches:
- master, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- b1397ab
- Parents:
- dcd8214
- git-author:
- Jiří Zárevúcky <zarevucky.jiri@…> (2023-11-03 18:46:22)
- git-committer:
- Jiří Zárevúcky <zarevucky.jiri@…> (2023-11-03 18:47:41)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/src/debug/line.c
rdcd8214 r40eab9f 297 297 } 298 298 299 static void debug_line_program_header_parse( const uint8_t *data, const uint8_t *data_end, struct debug_line_program_header *hdr)299 static void debug_line_program_header_parse(debug_sections_t *scs, const uint8_t *data, const uint8_t *data_end, struct debug_line_program_header *hdr) 300 300 { 301 301 const uint8_t *unit_start = data; … … 378 378 hdr->v5.directories_end = data; 379 379 380 print_formatted_list( "directories", hdr->v5.directories, hdr->v5.directories_end,380 print_formatted_list(scs, "directories", hdr->v5.directories, hdr->v5.directories_end, 381 381 hdr->v5.directory_entry_format, hdr->v5.directory_entry_format_end, width); 382 382 … … 397 397 hdr->v5.file_names_end = data; 398 398 399 print_formatted_list( "file_names", hdr->v5.file_names, hdr->v5.file_names_end,399 print_formatted_list(scs, "file_names", hdr->v5.file_names, hdr->v5.file_names_end, 400 400 hdr->v5.file_name_entry_format, hdr->v5.file_name_entry_format_end, width); 401 401 } … … 463 463 } 464 464 465 static const char *get_file_name_v5( struct debug_line_program_header *hdr, int file, int *dir)465 static const char *get_file_name_v5(debug_sections_t *scs, struct debug_line_program_header *hdr, int file, int *dir) 466 466 { 467 467 // DWARF5 has dynamic layout for file information, which is why … … 493 493 if (form == DW_FORM_line_strp) { 494 494 uint64_t offset = read_uint(&fns, fns_end, hdr->width); 495 if (offset < debug_line_str_size) {496 filename = debug_line_str + offset;495 if (offset < scs->debug_line_str_size) { 496 filename = scs->debug_line_str + offset; 497 497 } 498 498 continue; … … 527 527 } 528 528 529 static const char *get_file_name( struct debug_line_program_header *hdr, int file, int *dir)529 static const char *get_file_name(debug_sections_t *scs, struct debug_line_program_header *hdr, int file, int *dir) 530 530 { 531 531 switch (hdr->version) { … … 534 534 return get_file_name_v3(hdr, file, dir); 535 535 case 5: 536 return get_file_name_v5( hdr, file, dir);536 return get_file_name_v5(scs, hdr, file, dir); 537 537 default: 538 538 return NULL; … … 558 558 } 559 559 560 static const char *get_dir_name_v5( struct debug_line_program_header *hdr, int dir)560 static const char *get_dir_name_v5(debug_sections_t *scs, struct debug_line_program_header *hdr, int dir) 561 561 { 562 562 // TODO: basically a copypaste of get_file_name(). Try to deduplicate it. … … 587 587 if (form == DW_FORM_line_strp) { 588 588 uint64_t offset = read_uint(&fns, fns_end, hdr->width); 589 if (offset < debug_line_str_size) {590 filename = debug_line_str + offset;589 if (offset < scs->debug_line_str_size) { 590 filename = scs->debug_line_str + offset; 591 591 } 592 592 continue; … … 604 604 } 605 605 606 static const char *get_dir_name( struct debug_line_program_header *hdr, int dir)606 static const char *get_dir_name(debug_sections_t *scs, struct debug_line_program_header *hdr, int dir) 607 607 { 608 608 switch (hdr->version) { … … 611 611 return get_dir_name_v3(hdr, dir); 612 612 case 5: 613 return get_dir_name_v5( hdr, dir);613 return get_dir_name_v5(scs, hdr, dir); 614 614 default: 615 615 return NULL; … … 617 617 } 618 618 619 static const uint8_t *find_line_program( uintptr_t addr)619 static const uint8_t *find_line_program(debug_sections_t *scs, uintptr_t addr) 620 620 { 621 621 // TODO: use .debug_aranges to find the data quickly … … 625 625 const uint8_t *closest_prog = NULL; 626 626 627 const uint8_t *debug_line_ptr = debug_line;628 const uint8_t *const debug_line_end = debug_line +debug_line_size;627 const uint8_t *debug_line_ptr = scs->debug_line; 628 const uint8_t *const debug_line_end = scs->debug_line + scs->debug_line_size; 629 629 630 630 while (debug_line_ptr < debug_line_end) { … … 633 633 // Parse header 634 634 struct debug_line_program_header hdr = { }; 635 debug_line_program_header_parse( prog, debug_line_end, &hdr);635 debug_line_program_header_parse(scs, prog, debug_line_end, &hdr); 636 636 assert(hdr.unit_end > debug_line_ptr); 637 637 assert(hdr.unit_end <= debug_line_end); … … 678 678 debug_line_program_advance(&lp); 679 679 680 if (!lp.truncated) { 681 // We check for the last address before addr, because addr 682 // is a return address and we want the call instruction. 683 if (lp.address >= addr && lp.op_advance >= op_index) { 684 if (!first) { 685 *file = last_file; 686 *line = last_line; 687 *column = last_column; 688 return true; 689 } 690 680 if (lp.truncated) 681 continue; 682 683 /* 684 * Return previous entry when we pass the target address, because 685 * the address may not be aligned perfectly on instruction boundary. 686 */ 687 if (lp.address > addr || (lp.address == addr && lp.op_advance > op_index)) { 688 if (first) { 691 689 // First address is already too large, skip to the next sequence. 692 690 debug_line_program_skip_to_sequence_end(&lp); 693 } 694 695 last_file = lp.file; 696 last_line = lp.line; 697 last_column = lp.column; 698 } 691 continue; 692 } 693 694 *file = last_file; 695 *line = last_line; 696 *column = last_column; 697 return true; 698 } 699 700 last_file = lp.file; 701 last_line = lp.line; 702 last_column = lp.column; 699 703 } 700 704 … … 702 706 } 703 707 704 bool debug_line_get_address_info( uintptr_t addr, int op_index, const char **file_name, const char **dir_name, int *line, int *column)705 { 706 const uint8_t *data = find_line_program( addr);708 bool debug_line_get_address_info(debug_sections_t *scs, uintptr_t addr, int op_index, const char **file_name, const char **dir_name, int *line, int *column) 709 { 710 const uint8_t *data = find_line_program(scs, addr); 707 711 if (data == NULL) { 708 712 return false; 709 713 } 710 714 711 const uint8_t *const debug_line_end = debug_line +debug_line_size;715 const uint8_t *const debug_line_end = scs->debug_line + scs->debug_line_size; 712 716 713 717 struct debug_line_program_header hdr = { }; 714 debug_line_program_header_parse( data, debug_line_end, &hdr);718 debug_line_program_header_parse(scs, data, debug_line_end, &hdr); 715 719 assert(hdr.unit_end > data); 716 720 assert(hdr.unit_end <= debug_line_end); … … 727 731 728 732 if (file >= 0) 729 *file_name = get_file_name( &hdr, file, &dir);733 *file_name = get_file_name(scs, &hdr, file, &dir); 730 734 731 735 if (dir >= 0) 732 *dir_name = get_dir_name( &hdr, dir);736 *dir_name = get_dir_name(scs, &hdr, dir); 733 737 734 738 return true;
Note:
See TracChangeset
for help on using the changeset viewer.