Thread: Find program code's address at runtime

  1. #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.

  2. #2
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    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.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Client-server system with input from separate program
    By robot-ic in forum Networking/Device Communication
    Replies: 3
    Last Post: 01-16-2009, 03:30 PM
  2. Shell output into program during runtime
    By evilkillerfiggi in forum Linux Programming
    Replies: 3
    Last Post: 08-03-2006, 10:50 AM
  3. Replies: 4
    Last Post: 08-15-2002, 11:35 AM
  4. Im so lost at . .
    By hermit in forum C Programming
    Replies: 18
    Last Post: 05-15-2002, 01:26 AM
  5. doubly linked lists
    By cworld in forum C++ Programming
    Replies: 2
    Last Post: 04-21-2002, 09:33 AM

Tags for this Thread