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

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
miaowei
Member
Member
Posts: 84
Joined: Wed Dec 18, 2013 9:10 am

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

Post 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).
miaowei
Member
Member
Posts: 84
Joined: Wed Dec 18, 2013 9:10 am

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

Post by miaowei »

ok, i think this command should be :
info symbol 0xc0304000
User avatar
iansjack
Member
Member
Posts: 4706
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

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

Post 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.
glauxosdever
Member
Member
Posts: 501
Joined: Wed Jun 17, 2015 9:40 am
Libera.chat IRC: glauxosdever
Location: Athens, Greece

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

Post 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
Post Reply