Quote:
Originally Posted by vijayabcdef
Thanks Mr Graham and Mr Reuti,
I want to get whats there in those array elements in run time Just like GDB and Valgrind pointing to particular variable or function in case of any fault. That indicates me we may be able to read what variables are there in process address space when it is running. similarly can we know address of arrays and number of elements in it.
Hope that this will clarify my requirement.
yours vijay
|
Your requirement was quite clear from the beginning. valgrind doesn't (to my knowledge...?) tell you the types of variables etc. and gdb does exactly what I said before - it uses debugging information to find the source files the program uses and (I believe) a program called addr2line (see `man 1 addr2line') to tell what line of the program it is.
At run-time, variables in C don't have "types" - they are simply memory addresses you use
as if they were certain types. These addresses are known as "symbols" in the ELF file you run. You can take the address of variables you're interested in or even parse the ELF file to find the symbols, but finding the
type of them at run-time
will require you to find the source/header file and parse it.
Go with another method, like ta0kira suggests.