Finding out Function addresses from gcc

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
gommo

Finding out Function addresses from gcc

Post by gommo »

I'm compiling my kernel as a flat binary file using gcc and would like to know if there is a setting to output a debug file or something where I can find out the function addresses for all my functions??

I'd like to add breakpoints in bfe2(bochs) but I need to know the function addresses etc..

Thanks
HOS

Re:Finding out Function addresses from gcc

Post by HOS »

I use the -Map mapfile option for ld which does what you want. I am not sure if this option will work as a gcc parameter or not. If not, you can easily seperate your build steps into a gcc -c command and a ld command.
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re:Finding out Function addresses from gcc

Post by Solar »

objdump -d a.out | grep "^[^ ]"
Every good solution is obvious once you've found it.
User avatar
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Re:Finding out Function addresses from gcc

Post by Candy »

I use the -Map mapfile option for ld which does what you want. I am not sure if this option will work as a gcc parameter or not. If not, you can easily seperate your build steps into a gcc -c command and a ld command.
I use that too, but I parse the map file to only give me things I'm interested in:

cat kernel.*.Map | grep " 0x00000000" | sort | less

Not that sure about the grep, but it's something like this.
srthb

Re:Finding out Function addresses from gcc

Post by srthb »

gcc -g !
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:Finding out Function addresses from gcc

Post by Pype.Clicker »

srthb wrote: gcc -g !
The CodePoet strikes again with Yet Another Useful Comment ...
the '-g' flag in GCC turns on internal debugging information. It is certainly necessary if you wish 'objdump -d' to work, for instance (afaik), but it will not provide *you* the information until you have a GDB-compliant debugger ... and i doubt bochs or any other virtual PC can go that far ...
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re:Finding out Function addresses from gcc

Post by Solar »

Pype.Clicker wrote: The '-g' flag in GCC turns on internal debugging information. It is certainly necessary if you wish 'objdump -d' to work, for instance (afaik)...
objdump always works, even with stripped executables. -g just adds additional information (like, variable names), but all functions with external linkage are required to keep their symbol names anyway (or you couldn't link to them).
...but it will not provide *you* the information until you have a GDB-compliant debugger...
Little to do with GDB. External linkage symbols are defined by ELF (or whatever format you use), and the rest by the debugging format you chose (e.g. DWARF). Either are well defined, and understood by several other debuggers.

Just to be correct. (Hi Candy! ;-) )
Every good solution is obvious once you've found it.
Post Reply