Reading a macro value using trace32

2.1k views Asked by At

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?

2

There are 2 answers

0
dev15 On

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?

0
Holger On

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)