c - How to find compiled variable/function address from debug symbols -


i found following post (how generate gcc debug symbol outside build target?) on how split compiled file , debugging symbols.

however, cannot find useful information in debugging file.

for example,

my helloworld code is:

#include<stdio.h>  int main(void) {      int a;     = 5;     printf("the memory address of is: %p\n", (void*) &a);     return 0; } 

i ran gcc -g -o hello hello.c

objcopy --only-keep-debug hello hello.debug gdb -s main.debug -e main 

in gdb, tried won't give me information on a, cannot find address, cannot find main function address

for example :

(gdb) info variables defined variables:  non-debugging symbols: 0x0000000000400618  _io_stdin_used 0x0000000000400710  __frame_end__ 0x0000000000600e3c  __init_array_end 0x0000000000600e3c  __init_array_start 0x0000000000600e40  __ctor_list__ 0x0000000000600e48  __ctor_end__ 0x0000000000600e50  __dtor_list__ 0x0000000000600e58  __dtor_end__ 0x0000000000600e60  __jcr_end__ 0x0000000000600e60  __jcr_list__ 0x0000000000600e68  _dynamic 0x0000000000601000  _global_offset_table_ 0x0000000000601028  __data_start 0x0000000000601028  data_start 0x0000000000601030  __dso_handle 0x0000000000601038  __bss_start 0x0000000000601038  _edata 0x0000000000601038  completed.6603 0x0000000000601040  dtor_idx.6605 0x0000000000601048  _end 

am doing wrong? understanding debug file incorrectly? there way find out address of compiled variable/function saved debugging information?

int a stack variable not have fixed address unless in call specific function. furthermore, each call function allocate own variable.

when "debugging symbols" mean functions , global variables. local variable not "symbol" in context. in fact, if compile optimisations enabled int a optimised register variable not have address @ all, unless forced written memory doing some_function(&a) or similar.

you can find address of main writing print main in gdb. because functions implicitly converted pointers in c when appear in value context, , gdb's print uses c semantics.


Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -