Changeset 40eab9f in mainline
- Timestamp:
- 2023-11-03T18:47:41Z (14 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)
- Files:
-
- 15 edited
Legend:
- Unmodified
- Added
- Removed
-
abi/include/abi/sysinfo.h
rdcd8214 r40eab9f 37 37 #define _ABI_SYSINFO_H_ 38 38 39 #include <_bits/size_t.h> 39 40 #include <stdbool.h> 40 41 #include <abi/proc/task.h> -
kernel/generic/include/debug/line.h
rdcd8214 r40eab9f 33 33 #include <stddef.h> 34 34 #include <stdint.h> 35 #include <debug/sections.h> 35 36 36 37 struct debug_line_program_header { … … 103 104 } 104 105 105 extern bool debug_line_get_address_info( uintptr_t addr, int op_index, const char **file, const char **dir, int *line, int *col);106 extern bool debug_line_get_address_info(debug_sections_t *scs, uintptr_t addr, int op_index, const char **file, const char **dir, int *line, int *col); 106 107 107 108 #endif /* DWARFS_LINE_H_ */ -
kernel/generic/include/debug/sections.h
rdcd8214 r40eab9f 33 33 #include <stddef.h> 34 34 35 extern const void *debug_aranges; 36 extern size_t debug_aranges_size; 35 typedef struct { 36 const void *debug_aranges; 37 size_t debug_aranges_size; 37 38 38 externconst void *debug_info;39 externsize_t debug_info_size;39 const void *debug_info; 40 size_t debug_info_size; 40 41 41 externconst void *debug_abbrev;42 externsize_t debug_abbrev_size;42 const void *debug_abbrev; 43 size_t debug_abbrev_size; 43 44 44 externconst void *debug_line;45 externsize_t debug_line_size;45 const void *debug_line; 46 size_t debug_line_size; 46 47 47 externconst char *debug_str;48 externsize_t debug_str_size;48 const char *debug_str; 49 size_t debug_str_size; 49 50 50 externconst char *debug_line_str;51 externsize_t debug_line_str_size;51 const char *debug_line_str; 52 size_t debug_line_str_size; 52 53 53 externconst void *debug_rnglists;54 externsize_t debug_rnglists_size;54 const void *debug_rnglists; 55 size_t debug_rnglists_size; 55 56 56 externconst void *eh_frame_hdr;57 externsize_t eh_frame_hdr_size;57 const void *eh_frame_hdr; 58 size_t eh_frame_hdr_size; 58 59 59 externconst void *eh_frame;60 externsize_t eh_frame_size;60 const void *eh_frame; 61 size_t eh_frame_size; 61 62 62 externconst elf_symbol_t *symtab;63 externsize_t symtab_size;63 const elf_symbol_t *symtab; 64 size_t symtab_size; 64 65 65 extern const char *strtab; 66 extern size_t strtab_size; 66 const char *strtab; 67 size_t strtab_size; 68 } debug_sections_t; 69 70 extern debug_sections_t kernel_sections; 71 72 debug_sections_t get_debug_sections(const void *elf, size_t elf_size); 67 73 68 74 #endif /* DEBUG_SECTIONS_H_ */ -
kernel/generic/include/proc/program.h
rdcd8214 r40eab9f 56 56 57 57 extern errno_t program_create(as_t *, uspace_addr_t, char *, program_t *); 58 extern errno_t program_create_from_image(void *, char *, program_t *);58 extern errno_t program_create_from_image(void *, size_t, char *, program_t *); 59 59 extern errno_t program_create_loader(program_t *, char *); 60 60 extern void program_ready(program_t *); -
kernel/generic/include/proc/task.h
rdcd8214 r40eab9f 36 36 #define KERN_TASK_H_ 37 37 38 #include <cpu.h> 39 #include <ipc/ipc.h> 40 #include <ipc/event.h> 41 #include <ipc/kbox.h> 42 #include <synch/spinlock.h> 43 #include <synch/mutex.h> 38 #include <abi/proc/task.h> 39 #include <abi/sysinfo.h> 44 40 #include <adt/list.h> 45 41 #include <adt/odict.h> 46 #include <security/perm.h> 42 #include <arch/context.h> 43 #include <arch/cpu.h> 44 #include <arch/fpu_context.h> 47 45 #include <arch/proc/task.h> 48 46 #include <arch/proc/thread.h> 49 #include <arch/context.h> 50 #include <arch/fpu_context.h> 51 #include <arch/cpu.h> 47 #include <arch.h> 48 #include <cap/cap.h> 49 #include <cpu.h> 50 #include <debug/sections.h> 51 #include <ipc/event.h> 52 #include <ipc/ipc.h> 53 #include <ipc/kbox.h> 54 #include <mm/as.h> 52 55 #include <mm/tlb.h> 53 56 #include <proc/scheduler.h> 57 #include <security/perm.h> 58 #include <synch/mutex.h> 59 #include <synch/spinlock.h> 54 60 #include <udebug/udebug.h> 55 #include <mm/as.h>56 #include <abi/proc/task.h>57 #include <abi/sysinfo.h>58 #include <arch.h>59 #include <cap/cap.h>60 61 61 62 #define TASK CURRENT->task … … 131 132 uint64_t ucycles; 132 133 uint64_t kcycles; 134 135 debug_sections_t *debug_sections; 133 136 } task_t; 134 137 -
kernel/generic/include/symtab.h
rdcd8214 r40eab9f 36 36 #define KERN_SYMTAB_H_ 37 37 38 #include <stdbool.h> 38 39 #include <typedefs.h> 40 #include <debug/sections.h> 39 41 40 42 extern void symtab_print_search(const char *); … … 42 44 extern const char *symtab_fmt_name_lookup(uintptr_t); 43 45 extern errno_t symtab_addr_lookup(const char *, uintptr_t *); 44 extern const char *symtab_name_lookup(uintptr_t, uintptr_t * );46 extern const char *symtab_name_lookup(uintptr_t, uintptr_t *, debug_sections_t *); 45 47 46 48 #endif -
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; -
kernel/generic/src/debug/sections.c
rdcd8214 r40eab9f 29 29 #include <debug/sections.h> 30 30 #include <debug/register.h> 31 #include <debug.h> 31 32 32 33 #include <stdio.h> 33 34 #include <str.h> 34 35 35 const void *debug_aranges = NULL; 36 size_t debug_aranges_size = 0; 36 #define DEBUGF dummy_printf 37 37 38 const void *debug_info = NULL; 39 size_t debug_info_size = 0; 40 41 const void *debug_abbrev = NULL; 42 size_t debug_abbrev_size = 0; 43 44 const void *debug_line = NULL; 45 size_t debug_line_size = 0; 46 47 const char *debug_str = NULL; 48 size_t debug_str_size = 0; 49 50 const char *debug_line_str = NULL; 51 size_t debug_line_str_size = 0; 52 53 const void *debug_rnglists = NULL; 54 size_t debug_rnglists_size = 0; 55 56 // TODO: get this from the program image 57 const void *eh_frame_hdr = NULL; 58 size_t eh_frame_hdr_size = 0; 59 60 const void *eh_frame = NULL; 61 size_t eh_frame_size = 0; 62 63 const elf_symbol_t *symtab = NULL; 64 size_t symtab_size = 0; 65 66 const char *strtab = NULL; 67 size_t strtab_size = 0; 38 debug_sections_t kernel_sections; 68 39 69 40 struct section_manifest { … … 73 44 }; 74 45 75 #define section(name) { "." #name, (const void **)&name, &name##_size } 46 static void _check_string_section(const char *section, size_t *section_size) 47 { 48 while (*section_size > 0 && section[*section_size - 1] != 0) { 49 (*section_size)--; 50 } 51 } 76 52 77 static const struct section_manifest manifest[] = { 78 section(debug_aranges), 79 section(debug_info), 80 section(debug_abbrev), 81 section(debug_line), 82 section(debug_str), 83 section(debug_line_str), 84 section(debug_rnglists), 85 section(eh_frame_hdr), 86 section(eh_frame), 87 section(symtab), 88 section(strtab), 89 }; 53 debug_sections_t get_debug_sections(const void *elf, size_t elf_size) 54 { 55 debug_sections_t out = { }; 90 56 91 # undef section57 #define section(name) { "." #name, (const void **)&out.name, &out.name##_size } 92 58 93 static const size_t manifest_len = sizeof(manifest) / sizeof(struct section_manifest); 59 const struct section_manifest manifest[] = { 60 section(debug_aranges), 61 section(debug_info), 62 section(debug_abbrev), 63 section(debug_line), 64 section(debug_str), 65 section(debug_line_str), 66 section(debug_rnglists), 67 section(eh_frame_hdr), 68 section(eh_frame), 69 section(symtab), 70 section(strtab), 71 }; 94 72 95 void register_debug_data(const void *data, size_t data_size) 96 { 97 const void *data_end = data + data_size;73 const size_t manifest_len = sizeof(manifest) / sizeof(struct section_manifest); 74 75 const void *data_end = elf + elf_size; 98 76 99 77 /* … … 103 81 */ 104 82 105 if ( data_size < sizeof(elf_header_t)) {83 if (elf_size < sizeof(elf_header_t)) { 106 84 printf("bad debug data: too short\n"); 107 return ;85 return out; 108 86 } 109 87 110 if (((uintptr_t) data) % 8 != 0) {88 if (((uintptr_t) elf) % 8 != 0) { 111 89 printf("bad debug data: unaligned input\n"); 112 return ;90 return out; 113 91 } 114 92 115 const elf_header_t *hdr = data;93 const elf_header_t *hdr = elf; 116 94 117 95 if (hdr->e_ident[0] != ELFMAG0 || hdr->e_ident[1] != ELFMAG1 || 118 96 hdr->e_ident[2] != ELFMAG2 || hdr->e_ident[3] != ELFMAG3) { 119 97 printf("bad debug data: wrong ELF magic bytes\n"); 120 return ;98 return out; 121 99 } 122 100 123 101 if (hdr->e_shentsize != sizeof(elf_section_header_t)) { 124 102 printf("bad debug data: wrong e_shentsize\n"); 125 return ;103 return out; 126 104 } 127 105 128 106 /* Get section header table. */ 129 const elf_section_header_t *shdr = data+ hdr->e_shoff;107 const elf_section_header_t *shdr = elf + hdr->e_shoff; 130 108 size_t shdr_len = hdr->e_shnum; 131 109 132 110 if ((void *) &shdr[shdr_len] > data_end) { 133 111 printf("bad debug data: truncated section header table\n"); 134 return ;112 return out; 135 113 } 136 114 137 115 if (hdr->e_shstrndx >= shdr_len) { 138 116 printf("bad debug data: string table index out of range\n"); 139 return ;117 return out; 140 118 } 141 119 142 120 /* Get data on section name string table. */ 143 121 const elf_section_header_t *shstr = &shdr[hdr->e_shstrndx]; 144 const char *shstrtab = data+ shstr->sh_offset;122 const char *shstrtab = elf + shstr->sh_offset; 145 123 size_t shstrtab_size = shstr->sh_size; 146 124 147 125 if ((void *) shstrtab + shstrtab_size > data_end) { 148 126 printf("bad debug data: truncated string table\n"); 149 return ;127 return out; 150 128 } 151 129 152 130 /* Check NUL-terminator. */ 153 while (shstrtab_size > 0 && shstrtab[shstrtab_size - 1] != 0) { 154 shstrtab_size--; 155 } 131 _check_string_section(shstrtab, &shstrtab_size); 156 132 157 133 if (shstrtab_size == 0) { 158 134 printf("bad debug data: empty or non-null-terminated string table\n"); 159 return ;135 return out; 160 136 } 161 137 … … 167 143 if (shdr[i].sh_name >= shstrtab_size) { 168 144 printf("bad debug data: string table index out of range\n"); 169 return;145 continue; 170 146 } 171 147 … … 174 150 size_t size = shdr[i].sh_size; 175 151 176 printf("section '%s': offset %zd (%zd bytes)\n", name, offset, size);152 DEBUGF("section '%s': offset %zd (%zd bytes)\n", name, offset, size); 177 153 178 if ( data+ offset + size > data_end) {154 if (elf + offset + size > data_end) { 179 155 printf("bad debug data: truncated section %s\n", name); 180 156 continue; … … 183 159 for (size_t i = 0; i < manifest_len; i++) { 184 160 if (str_cmp(manifest[i].name, name) == 0) { 185 *manifest[i].address_field = data+ offset;161 *manifest[i].address_field = elf + offset; 186 162 *manifest[i].size_field = size; 187 163 break; … … 191 167 192 168 /* Check NUL-terminator in .strtab, .debug_str and .debug_line_str */ 193 while (strtab_size > 0 && strtab[strtab_size - 1] != 0) {194 strtab_size--;195 }169 _check_string_section(out.strtab, &out.strtab_size); 170 _check_string_section(out.debug_str, &out.debug_str_size); 171 _check_string_section(out.debug_line_str, &out.debug_line_str_size); 196 172 197 while (debug_str_size > 0 && debug_str[debug_str_size - 1] != 0) { 198 debug_str_size--; 199 } 173 return out; 174 } 200 175 201 while (debug_line_str_size > 0 && debug_str[debug_line_str_size - 1] != 0) { 202 debug_line_str_size--; 203 }176 void register_debug_data(const void *elf, size_t elf_size) 177 { 178 kernel_sections = get_debug_sections(elf, elf_size); 204 179 } -
kernel/generic/src/debug/stacktrace.c
rdcd8214 r40eab9f 60 60 int column = 0; 61 61 62 /* 63 * If this isn't the first frame, move pc back by one byte to read the 64 * position of the call instruction, not the return address. 65 */ 66 pc = cnt == 1 ? ctx->pc : ctx->pc - 1; 67 62 68 if (ops->symbol_resolve && 63 ops->symbol_resolve( ctx->pc, 0, &symbol, &symbol_addr, &file_name, &dir_name, &line, &column)) {69 ops->symbol_resolve(pc, 0, &symbol, &symbol_addr, &file_name, &dir_name, &line, &column)) { 64 70 65 71 if (symbol == NULL) … … 130 136 { 131 137 *symbol_addr = 0; 132 *symbol = symtab_name_lookup(addr, symbol_addr );138 *symbol = symtab_name_lookup(addr, symbol_addr, &kernel_sections); 133 139 134 return debug_line_get_address_info(addr, op_index, filename, dirname, line, column) || *symbol_addr != 0; 140 return debug_line_get_address_info(&kernel_sections, addr, op_index, filename, dirname, line, column) || *symbol_addr != 0; 141 } 142 143 static bool 144 resolve_uspace_address(uintptr_t addr, int op_index, 145 const char **symbol, uintptr_t *symbol_addr, 146 const char **filename, const char **dirname, 147 int *line, int *column) 148 { 149 if (TASK->debug_sections == NULL) 150 return false; 151 152 debug_sections_t *scs = TASK->debug_sections; 153 154 *symbol_addr = 0; 155 *symbol = symtab_name_lookup(addr, symbol_addr, scs); 156 157 return debug_line_get_address_info(scs, addr, op_index, filename, dirname, line, column) || *symbol_addr != 0; 135 158 } 136 159 … … 146 169 .frame_pointer_prev = uspace_frame_pointer_prev, 147 170 .return_address_get = uspace_return_address_get, 148 .symbol_resolve = NULL171 .symbol_resolve = resolve_uspace_address, 149 172 }; 150 173 -
kernel/generic/src/debug/symtab.c
rdcd8214 r40eab9f 36 36 */ 37 37 38 #include <abi/elf.h> 39 #include <byteorder.h> 40 #include <console/prompt.h> 41 #include <debug/sections.h> 42 #include <errno.h> 43 #include <proc/task.h> 44 #include <stdio.h> 45 #include <str.h> 38 46 #include <symtab.h> 39 #include <byteorder.h>40 #include <str.h>41 #include <stdio.h>42 47 #include <typedefs.h> 43 #include <errno.h> 44 #include <console/prompt.h> 45 46 #include <abi/elf.h> 47 #include <debug/sections.h> 48 49 static inline size_t symtab_len() 50 { 51 return symtab_size / sizeof(elf_symbol_t); 52 } 53 54 static inline const char *symtab_entry_name(int entry) 55 { 56 size_t index = symtab[entry].st_name; 57 58 if (index >= strtab_size) 59 return NULL; 60 61 return strtab + index; 62 } 63 64 static inline size_t symtab_next(size_t i) 65 { 66 for (; i < symtab_len(); i++) { 67 const char *name = symtab_entry_name(i); 68 int st_bind = elf_st_bind(symtab[i].st_info); 69 int st_type = elf_st_type(symtab[i].st_info); 48 49 static inline const char *symtab_entry_name(debug_sections_t *scs, int entry) 50 { 51 size_t index = scs->symtab[entry].st_name; 52 53 if (index >= scs->strtab_size) 54 return NULL; 55 56 return scs->strtab + index; 57 } 58 59 static inline size_t symtab_next(debug_sections_t *scs, size_t i) 60 { 61 size_t symtab_len = scs->symtab_size / sizeof(elf_symbol_t); 62 63 for (; i < symtab_len; i++) { 64 const char *name = symtab_entry_name(scs, i); 65 int st_bind = elf_st_bind(scs->symtab[i].st_info); 66 int st_type = elf_st_type(scs->symtab[i].st_info); 70 67 71 68 if (st_bind == STB_LOCAL) … … 82 79 } 83 80 84 const char *symtab_name_lookup(uintptr_t addr, uintptr_t *symbol_addr) 85 { 81 const char *symtab_name_lookup(uintptr_t addr, uintptr_t *symbol_addr, debug_sections_t *scs) 82 { 83 const elf_symbol_t *symtab = scs->symtab; 84 size_t symtab_len = scs->symtab_size / sizeof(elf_symbol_t); 85 const char *strtab = scs->strtab; 86 size_t strtab_size = scs->strtab_size; 87 86 88 if (symtab == NULL || strtab == NULL) 87 89 return NULL; … … 90 92 uintptr_t closest_symbol_name = 0; 91 93 92 for (size_t i = symtab_next( 0); i < symtab_len(); i = symtab_next(i + 1)) {94 for (size_t i = symtab_next(scs, 0); i < symtab_len; i = symtab_next(scs, i + 1)) { 93 95 if (symtab[i].st_value > addr) 94 96 continue; … … 132 134 const char *symtab_fmt_name_lookup(uintptr_t addr) 133 135 { 134 const char *name = symtab_name_lookup(addr, NULL );136 const char *name = symtab_name_lookup(addr, NULL, &kernel_sections); 135 137 if (name == NULL) 136 138 name = "<unknown>"; … … 150 152 errno_t symtab_addr_lookup(const char *name, uintptr_t *addr) 151 153 { 152 for (size_t i = symtab_next(0); i < symtab_len(); i = symtab_next(i + 1)) { 153 if (str_cmp(name, symtab_entry_name(i)) == 0) { 154 *addr = symtab[i].st_value; 154 debug_sections_t *scs = &kernel_sections; 155 size_t symtab_len = scs->symtab_size / sizeof(elf_symbol_t); 156 157 for (size_t i = symtab_next(scs, 0); i < symtab_len; i = symtab_next(scs, i + 1)) { 158 if (str_cmp(name, symtab_entry_name(scs, i)) == 0) { 159 *addr = scs->symtab[i].st_value; 155 160 return EOK; 156 161 } … … 163 168 void symtab_print_search(const char *name) 164 169 { 165 if (symtab == NULL || strtab == NULL) { 170 debug_sections_t *scs = &kernel_sections; 171 size_t symtab_len = scs->symtab_size / sizeof(elf_symbol_t); 172 173 if (scs->symtab == NULL || scs->strtab == NULL) { 166 174 printf("No symbol information available.\n"); 167 175 return; … … 170 178 size_t namelen = str_length(name); 171 179 172 for (size_t i = symtab_next( 0); i < symtab_len(); i = symtab_next(i + 1)) {173 const char *n = symtab_entry_name( i);180 for (size_t i = symtab_next(scs, 0); i < symtab_len; i = symtab_next(scs, i + 1)) { 181 const char *n = symtab_entry_name(scs, i); 174 182 175 183 if (str_lcmp(name, n, namelen) == 0) { 176 printf("%p: %s\n", (void *) s ymtab[i].st_value, n);184 printf("%p: %s\n", (void *) scs->symtab[i].st_value, n); 177 185 } 178 186 } … … 182 190 const char *symtab_hints_enum(const char *input, const char **help, void **ctx) 183 191 { 184 if (symtab == NULL || strtab == NULL) 192 debug_sections_t *scs = &kernel_sections; 193 size_t symtab_len = scs->symtab_size / sizeof(elf_symbol_t); 194 195 if (scs->symtab == NULL || scs->strtab == NULL) 185 196 return NULL; 186 197 … … 189 200 190 201 size_t len = str_length(input); 191 for (size_t i = symtab_next( (size_t) *ctx); i < symtab_len(); i = symtab_next(i + 1)) {192 const char *curname = symtab_entry_name( i);202 for (size_t i = symtab_next(scs, (size_t) *ctx); i < symtab_len; i = symtab_next(scs, i + 1)) { 203 const char *curname = symtab_entry_name(scs, i); 193 204 194 205 if (str_lcmp(input, curname, len) == 0) { -
kernel/generic/src/debug/util.c
rdcd8214 r40eab9f 33 33 #include <debug/names.h> 34 34 35 /*36 * These declarations cause global definitions for the functions to be emitted37 * in this compilation unit, so if the compiler decides not to inline some of38 * them, only one external copy exists. See C99 inline rules.39 */40 extern inline uint8_t read_byte(const uint8_t **, const uint8_t *);41 extern inline uint16_t read_uint16(const uint8_t **, const uint8_t *);42 extern inline uint32_t read_uint24(const uint8_t **, const uint8_t *);43 extern inline uint32_t read_uint32(const uint8_t **, const uint8_t *);44 extern inline uint64_t read_uint64(const uint8_t **, const uint8_t *);45 extern inline uint64_t read_uint(const uint8_t **, const uint8_t *, unsigned);46 extern inline uint64_t read_uleb128(const uint8_t **, const uint8_t *);47 extern inline int64_t read_sleb128(const uint8_t **, const uint8_t *);48 extern inline void skip_leb128(const uint8_t **, const uint8_t *);49 extern inline uint64_t read_initial_length(const uint8_t **, const uint8_t *, unsigned *);50 extern inline const char *read_string(const uint8_t **, const uint8_t *);51 extern inline void skip_string(const uint8_t **, const uint8_t *);52 extern inline void safe_increment(const uint8_t **, const uint8_t *, ptrdiff_t);53 54 extern inline void skip_format(const uint8_t **, const uint8_t *, unsigned);55 extern inline void skip_formatted_entry(const uint8_t **, const uint8_t *,56 const uint8_t *, const uint8_t *, unsigned);57 extern inline void skip_formatted_list(const uint8_t **, const uint8_t *,58 unsigned, const uint8_t *, const uint8_t *, unsigned);59 60 35 bool skip_data(unsigned form, const uint8_t **const data, 61 36 const uint8_t *data_end, unsigned width) … … 159 134 } 160 135 161 void print_formatted_list( const char *name,136 void print_formatted_list(debug_sections_t *scs, const char *name, 162 137 const uint8_t *data, const uint8_t *const data_end, 163 138 const uint8_t *format, const uint8_t *format_end, … … 175 150 176 151 DEBUGF("%s:%s:", dw_lnct_name(lnct), dw_form_name(form)); 177 print_formed_data( form, &data, data_end, width);152 print_formed_data(scs, form, &data, data_end, width); 178 153 DEBUGF("\n"); 179 154 } … … 196 171 } 197 172 198 void print_formed_data( unsigned form, const uint8_t **const data,173 void print_formed_data(debug_sections_t *scs, unsigned form, const uint8_t **const data, 199 174 const uint8_t *data_end, unsigned width) 200 175 { … … 210 185 case DW_FORM_strp_sup: 211 186 offset = read_uint(data, data_end, width); 212 if (offset >= debug_str_size)187 if (offset >= scs->debug_str_size) 213 188 DEBUGF("<out of range>"); 214 189 else 215 DEBUGF("\"%s\"", debug_str + offset);190 DEBUGF("\"%s\"", scs->debug_str + offset); 216 191 break; 217 192 218 193 case DW_FORM_line_strp: 219 194 offset = read_uint(data, data_end, width); 220 if (offset >= debug_line_str_size)195 if (offset >= scs->debug_line_str_size) 221 196 DEBUGF("<out of range>"); 222 197 else 223 DEBUGF("\"%s\"", debug_line_str + offset);198 DEBUGF("\"%s\"", scs->debug_line_str + offset); 224 199 break; 225 200 -
kernel/generic/src/debug/util.h
rdcd8214 r40eab9f 33 33 #include <stdint.h> 34 34 #include <debug/constants.h> 35 #include <debug/sections.h> 35 36 #include <debug.h> 36 37 … … 39 40 extern bool skip_data(unsigned, const uint8_t **const, const uint8_t *, unsigned); 40 41 extern void print_format(const char *, const uint8_t *, const uint8_t *); 41 extern void print_formatted_list( const char *, const uint8_t *, const uint8_t*,42 const uint8_t *, const uint8_t *, unsigned);42 extern void print_formatted_list(debug_sections_t *, const char *, 43 const uint8_t *, const uint8_t *, const uint8_t *, const uint8_t *, unsigned); 43 44 44 45 extern void print_block(const uint8_t **, const uint8_t *, unsigned); 45 extern void print_formed_data( unsigned, const uint8_t **const, const uint8_t *, unsigned);46 47 inline uint8_t read_byte(const uint8_t **data, const uint8_t *data_end)46 extern void print_formed_data(debug_sections_t *scs, unsigned, const uint8_t **const, const uint8_t *, unsigned); 47 48 static inline uint8_t read_byte(const uint8_t **data, const uint8_t *data_end) 48 49 { 49 50 if (*data >= data_end) { … … 67 68 } __attribute__((packed)); 68 69 69 inline uint16_t read_uint16(const uint8_t **data, const uint8_t *data_end)70 static inline uint16_t read_uint16(const uint8_t **data, const uint8_t *data_end) 70 71 { 71 72 if (*data + 2 > data_end) { … … 80 81 } 81 82 82 inline uint32_t read_uint24(const uint8_t **data, const uint8_t *data_end)83 static inline uint32_t read_uint24(const uint8_t **data, const uint8_t *data_end) 83 84 { 84 85 if (*data + 3 > data_end) { … … 98 99 } 99 100 100 inline uint32_t read_uint32(const uint8_t **data, const uint8_t *data_end)101 static inline uint32_t read_uint32(const uint8_t **data, const uint8_t *data_end) 101 102 { 102 103 if (*data + 4 > data_end) { … … 111 112 } 112 113 113 inline uint64_t read_uint64(const uint8_t **data, const uint8_t *data_end)114 static inline uint64_t read_uint64(const uint8_t **data, const uint8_t *data_end) 114 115 { 115 116 if (*data + 8 > data_end) { … … 124 125 } 125 126 126 inline uint64_t read_uint(const uint8_t **data, const uint8_t *data_end, unsigned bytes)127 static inline uint64_t read_uint(const uint8_t **data, const uint8_t *data_end, unsigned bytes) 127 128 { 128 129 switch (bytes) { … … 140 141 } 141 142 142 inline uint64_t read_uleb128(const uint8_t **data, const uint8_t *data_end)143 static inline uint64_t read_uleb128(const uint8_t **data, const uint8_t *data_end) 143 144 { 144 145 uint64_t result = 0; … … 157 158 } 158 159 159 inline int64_t read_sleb128(const uint8_t **data, const uint8_t *data_end)160 static inline int64_t read_sleb128(const uint8_t **data, const uint8_t *data_end) 160 161 { 161 162 uint64_t result = 0; … … 179 180 } 180 181 181 inline void skip_leb128(const uint8_t **data, const uint8_t *data_end)182 static inline void skip_leb128(const uint8_t **data, const uint8_t *data_end) 182 183 { 183 184 while (*data < data_end) { … … 188 189 } 189 190 190 inline uint64_t read_initial_length(const uint8_t **data, const uint8_t *data_end, unsigned *width)191 static inline uint64_t read_initial_length(const uint8_t **data, const uint8_t *data_end, unsigned *width) 191 192 { 192 193 uint32_t initial = read_uint32(data, data_end); … … 200 201 } 201 202 202 inline const char *read_string(const uint8_t **data, const uint8_t *data_end)203 static inline const char *read_string(const uint8_t **data, const uint8_t *data_end) 203 204 { 204 205 const char *start = (const char *) *data; … … 218 219 } 219 220 220 inline void skip_string(const uint8_t **data, const uint8_t *data_end)221 static inline void skip_string(const uint8_t **data, const uint8_t *data_end) 221 222 { 222 223 (void) read_string(data, data_end); 223 224 } 224 225 225 inline void safe_increment(const uint8_t **data,226 static inline void safe_increment(const uint8_t **data, 226 227 const uint8_t *data_end, ptrdiff_t increment) 227 228 { … … 235 236 } 236 237 237 inline void skip_format(const uint8_t **data, const uint8_t *const data_end,238 static inline void skip_format(const uint8_t **data, const uint8_t *const data_end, 238 239 unsigned count) 239 240 { … … 244 245 } 245 246 246 inline void skip_formatted_entry(const uint8_t **data, const uint8_t *const data_end,247 static inline void skip_formatted_entry(const uint8_t **data, const uint8_t *const data_end, 247 248 const uint8_t *format, const uint8_t *format_end, unsigned width) 248 249 { … … 256 257 } 257 258 258 inline void skip_formatted_list(const uint8_t **data, const uint8_t *const data_end,259 static inline void skip_formatted_list(const uint8_t **data, const uint8_t *const data_end, 259 260 unsigned count, const uint8_t *format, const uint8_t *format_end, 260 261 unsigned width) -
kernel/generic/src/main/kinit.c
rdcd8214 r40eab9f 268 268 } 269 269 270 errno_t rc = program_create_from_image((void *) page, namebuf,270 errno_t rc = program_create_from_image((void *) page, init.tasks[i].size, namebuf, 271 271 &programs[i]); 272 272 -
kernel/generic/src/proc/program.c
rdcd8214 r40eab9f 143 143 * 144 144 */ 145 errno_t program_create_from_image(void *image_addr, char *name, program_t *prg)145 errno_t program_create_from_image(void *image_addr, size_t image_size, char *name, program_t *prg) 146 146 { 147 147 as_t *as = as_create(0); … … 157 157 } 158 158 159 returnprogram_create(as, ((elf_header_t *) image_addr)->e_entry,159 errno_t rc = program_create(as, ((elf_header_t *) image_addr)->e_entry, 160 160 name, prg); 161 162 if (rc == EOK) { 163 prg->task->debug_sections = calloc(1, sizeof(debug_sections_t)); 164 if (prg->task->debug_sections != NULL) 165 *prg->task->debug_sections = get_debug_sections(image_addr, image_size); 166 } 167 168 return rc; 161 169 } 162 170 -
kernel/generic/src/proc/task.c
rdcd8214 r40eab9f 225 225 task->answerbox.active = true; 226 226 227 task->debug_sections = NULL; 228 227 229 #ifdef CONFIG_UDEBUG 228 230 /* Init debugging stuff */
Note:
See TracChangeset
for help on using the changeset viewer.