how can I view a variable name from a given address from t32 cmm script? - trace32

how can I view a variable name from a given address from t32 cmm script ?
I have address and want to log the name of the variable from T32 loaded dump or elf ?

You can get the variable name by the address with PRACTICE function sYmbol.Name(<addr>).
E.g.: If variable "myvar" is at address D:0x100 you can get the name again from the address with
PRINT sYmbol.Name(D:0x100)
or assign it to a macro like this
&name=sYmbol.Name(D:0x100)

Related

Assign a struct element to other cmm local variable

I'am using cmm scripts and i want to assign a struct element to other cmm mocal variable like that
&Intermidiate = Debug_Log[0].Name
But i had always the Error as it is shown in the pictureError
structure element assignes to local cmm variable
Debug_Log[0].Name is a HLL expression. Those expressions are only valid for TRACE32 commands starting with Var..
To use the value of a HLL expression with any other command, wrap it in the function VAR.VALUE(<hllexpr>). E.g. like this:
&Intermidiate=Var.VALUE(Debug_Log[0].Name)

Set a variable to address of frame in gdb?

I need to set a local variable to the address of a particular frame obtained through backtrace. Is this possible? I haven't been able to find a way to do it.
Okay, here's a way to do it:
Select the frame you're interested in with f *n*,
then get the address from the instruction pointer: set $lal=$rip.
Enjoy.

gdb print symbol at address relative to base address

I found a suspicious deadlock at address myfile.exe+0x144c7 (from list of threads in ProcessExplorer). Now, I want to know which function it is.
info symbol addr
requires that addr is absolute. Is there a command that takes the relative address given by ProcessExplorer. I can add 0x400000 but it would be better if GDB could do it for me.
gdb accepts an expression for the symbol address, so you can do something like this:
info symbol 0x40000000 + 0x144c7
If you check "info variables" (or use nm on the executable) there's probably a symbolic name for the text segment containing your code, so you can also do something like:
info symbol _init + 0x144c7
Note that symbol might not work as expected if your problem is in a DLL or other text segment.

How to know which file a specific function is in with gdb?

Anyone knows how to know which file a specific function is in with gdb?
there is also info func which accepts a regular expression.
(gdb) info func ^bp1$
All functions matching regular expression "^bp1$":
File test.c:
void bp1();
Assuming the function name is someFunc, first find the address of the function:
info address someFunc
And assuming you got the adress someAddress, use list with that address:
list *someAddress
Example from a gdb session:
(gdb) info address main
Symbol "main" is a function at address 0x406159.
(gdb) list *0x406159
0x406159 is in main (../src/staapp-test.cpp:221).

gdb\bfd: get child variable address or size or offset

I'm using gdb and libbfd to retrieve global variables information from an elf file and show it.
I can get the following data from libbfd: Global Variable name, address and size.
I retrieve the type of the variables and its children using gdb and gdb\MI (ptype, whatis, -var-create & -var-list-children).
How can I get the address\size\offset from parent of all the children?
e.g
type = struct {\n"
unsigned char count;\n"
unsigned char time;\n
}\n
If a variable A of this type is in address 0x000100, I want to show that A.count is in 0x000100 with size 0x1 and A.time is in 0x000101 with size 0x1.
EDIT:
I've read that gdb can read the DWARF info, but I can't figure out how can I get this information from gdb.
Here's what I did eventually.
To get the size, I used:
p sizeof(A.time)
and to get the address I used:
p /a &A.time
NOTE: This only applies for variable of a size bigger then 1 byte.
To be able to get bitfields size and offset in bits, I had to recompile GDB according to the suggestion offered in nabble: Address of bitfield element bug?