Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reading a macro value using trace32

I have used C code in Trace32 and I want to read the value of C macro in Trace32. How to do that? Will the macro value be stored in some register?

eg:

#define DEST_ADD = 0xE432;
address = htonl(DEST_ADD);

How do I read the value of macro: DEST_ADD in Trace32?

like image 262
user7478398 Avatar asked Mar 10 '26 22:03

user7478398


2 Answers

Macros are usually replaced by their content by the preprocessor. So the compiler does no longer "see" the macro names and thus, can't create debug information for it in the ELF file. As a result any debugger can't know the macros' names.

However, some compilers support the generation of debug information for preprocessor macros. E.g. if you use GCC with debug level 3 (gcc -g3), the compiler creates a section called ".debug_macro" in your ELF file.

If your ELF contains the ".debug_macro" section, you have to tell TRACE32 to consider this section when loading the ELF, by using the option "/MACRO". So you load your ELF e.g with

 Data.LOAD.Elf * /MACRO

You can then see all your preprocessor macros in the sYmbol.List.MACRO window or use any of them in the Var.WATCH window, or access them with the Var.VALUE() function or print them with the Var.PRINT command. E.g.:

 Var.Watch UINT32_MAX
 Var.PRINT UINT32_MAX
 PRINT %Decimal Var.VALUE(UINT32_MAX)
like image 71
Holger Avatar answered Mar 13 '26 18:03

Holger


The C preprocessor will replace macros in your code with their values, so there's a good chance the macro doesn't exist anymore in the resulting object file. However you can just print the value of the variable instead:

Var.PRINT <variable>

You might also want to have a look at this: How to check if a macro exists in an object file in C?

like image 39
dev15 Avatar answered Mar 13 '26 16:03

dev15



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!