C Board  

Go Back   C Board > General Programming Boards > C Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 07-01-2009, 09:52 AM   #1
Registered User
 
Join Date: Jul 2009
Posts: 1
Talking Find program code's address at runtime

When I use gdb to debug a program written in C, the command disassemble shows the codes and their addresses in the code memory segmentation. Is it possible to know those memory addresses at runtime? I am using Ubuntu OS. Thank you.
wakandan is offline   Reply With Quote
Old 07-01-2009, 11:26 AM   #2
Senior software engineer
 
brewbuck's Avatar
 
Join Date: Mar 2007
Location: Portland, OR
Posts: 5,381
Quote:
Originally Posted by wakandan View Post
When I use gdb to debug a program written in C, the command disassemble shows the codes and their addresses in the code memory segmentation. Is it possible to know those memory addresses at runtime? I am using Ubuntu OS. Thank you.
Not portably. You can take the address of a function, but it's not guaranteed that the address you get is actually the address of the code which implements the function (although in practice it usually is).

The question is, WHAT code? Are you interested in the address of a particular function, or the base address of the entire code segment? On most operating systems/binary formats, the code segment load address is fixed at link time and cannot change. So there is no need to determine it at runtime.
__________________
"Congratulations on your purchase. To begin using your quantum computer, set the power switch to both off and on simultaneously." -- raftpeople@slashdot
brewbuck is offline   Reply With Quote
Reply

Tags
address, code, disassemble

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Client-server system with input from separate program robot-ic Networking/Device Communication 3 01-16-2009 03:30 PM
Shell output into program during runtime evilkillerfiggi Linux Programming 3 08-03-2006 10:50 AM
Help with Program, I'm a newbie and I can't find the problem Lyuokdea C++ Programming 4 08-15-2002 11:35 AM
Im so lost at . . hermit C Programming 18 05-15-2002 01:26 AM
doubly linked lists cworld C++ Programming 2 04-21-2002 09:33 AM


All times are GMT -6. The time now is 04:07 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22