2 * stab-dump: Dump JOS kernel symbol table
5 * http://sources.redhat.com/gdb/onlinedocs/stabs_toc.html
7 * Luiz Fernando N. Capitulino
8 * <lcapitulino@gmail.com
17 #include <sys/types.h>
23 uint32_t n_strx
; // index into string table of name
24 uint8_t n_type
; // type of symbol
25 uint8_t n_other
; // misc info (usually empty)
26 uint16_t n_desc
; // description field
27 uintptr_t n_value
; // value of symbol
30 int main(int argc
, char *argv
[])
37 struct Stab
*stab
, *estab
;
40 printf("usage: %s < file >\n", argv
[0]);
44 fd
= open(argv
[1], O_RDONLY
);
50 memset(&buf
, 0, sizeof(buf
));
51 err
= fstat(fd
, &buf
);
57 header
= (Elf32_Ehdr
*) mmap(NULL
, buf
.st_size
, PROT_READ
,
59 if (header
== MAP_FAILED
) {
66 * Get .stabstr and .stab
68 * XXX: The code makes the following assumptions:
70 * 1 .stabstr is the first SHT_STRTAB section
71 * 2 .stab section is the section that comes before .stabstr
73 * This looks like hardcoded info for me, since we're couting
74 * on the format of our kernel binary image. But I don't know
75 * how to make this right.
77 sh
= (Elf32_Shdr
*) ((void *) header
+ header
->e_shoff
);
78 esh
= sh
+ header
->e_shnum
;
79 for (; sh
< esh
; sh
++)
80 if (sh
->sh_type
== SHT_STRTAB
) {
81 stabstr
= (char *) ((void *) header
+ sh
->sh_offset
);
86 stab
= (struct Stab
*) ((void *) header
+ sh
->sh_offset
);
87 estab
= stab
+ sh
->sh_size
/ sh
->sh_entsize
;
88 for (; stab
< estab
; stab
++)
89 if (stab
->n_type
== 0x24) {
92 printf("%#x ", stab
->n_value
);
94 /* Stab format for functions is:
98 * But we're only interested in func_name
100 for (p
= stab
->n_strx
+ stabstr
; *p
!= ':'; p
++)
105 munmap(header
, buf
.st_size
);