Changeset 40eab9f in mainline for kernel/generic/src/debug/symtab.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/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) {
Note:
See TracChangeset
for help on using the changeset viewer.