Page 1 of 1

how to locate a function by a constant address value?(in gdb

Posted: Sun May 01, 2016 9:41 pm
by miaowei
i am debugging my kernel with bochs ( gdb-stub enabled).
sometimes, the kernel trapped into 'page_fault" and gdb's command [bt] didn't work any more.

so, i want to locate the function who caused this time page-fault.
i can get the illegal address within my kernel by reading CR2, i can get the instuction address at that time by reading eip.
but how can i locate the function(in source code) with gdb. is there exist a command like :
locate 0xc0304000
?
(assume i know instruction in 0xc0304000 caused this time page-error).

Re: how to locate a function by a constant address value?(in

Posted: Sun May 01, 2016 9:54 pm
by miaowei
ok, i think this command should be :
info symbol 0xc0304000

Re: how to locate a function by a constant address value?(in

Posted: Sun May 01, 2016 11:58 pm
by iansjack
Use the option to produce a link map when linking your kernel. This will list all symbols and their addresses. You can then see which function a particular address belongs to.

Re: how to locate a function by a constant address value?(in

Posted: Mon May 02, 2016 2:02 am
by glauxosdever
Hi,


You can also compile/link the kernel with the -g option, which adds as many debugging symbols as possible. Then, run objdump -d /your/kernel/file, which will show the address of each instruction in text sections. If this somehow doesn't happen in text sections, you can try to pass the -D option to objdump, which will disassemble all sections in the binary.

Also, you can try to redirect the output to another file, so you can inspect the instructions more closely, not to mention that the result will probably not fit in the terminal scroll-back.

Hope this helps. :)


Regards,
glauxosdever