Electronics > Microcontrollers

Stupid debugging of macro values

(1/3) > >>

T3sl4co1l:
Obvious solution: echo macro values during compilation.

I...don't know that GCC can do this??

Dumb solution: echo it into the program somewhere.

What if you're not debug printf()-ing?  Don't want to drop in a whole pile of code to do that?  Just see the raw values wherever they are?

For example, on AVR, you assign constants, they'll be split into LDI instructions or whatever, you can't search on the exact value.  Maybe what variable it's saved to.  If you do low optimization and look at the listing interspersed with code, you can find that, still gotta sort out what the ASM is doing though.

Easier then: just save it to a variable in the first place, and force it to be put somewhere easy to find.


--- Code: ---#define INTEN_SLOPE /* some long expressions */
...
const uint16_t check_values[] __attribute__((used)) PROGMEM = {
INTEN_SLOPE,
INTEN_OFFS,
INTEN_ADCMIN,
INTEN_ADCMAX
};

--- End code ---

Just toss in an array of the values, of course... The attribute prevents it from being optimized out (-O3, -lto), no need to declare it extern, etc.  It shows up in the objdump -h -S listing towards the top (with the other PROGMEM stuff).


--- Code: ---...
000002da <check_values>:
     2da: a6 02 20 ae 10 52 f8 b1                             .. ..R..
...

--- End code ---

I, at least, have .lss generated all the time so this is a convenient place to find it.  If you want to find the object itself of course you can extract/dump it by name in the usual way, etc.

Tim

SiliconWizard:
GCC has the -E option to output the result of preprocessing on a given source file.
The downside is that it does full preprocessing, thus outputting the content of all include files as well.

newbrain:
I checked whether #warning could be of any help - as it's not part of the standard I just vaguely remembered of its existence.

But nope, it echoes exactly what follows it on the line, not its expansion.

ejeffrey:
gcc -dM -E

Runs the preprocessor only and outputs all defined macros.

Nominal Animal:
Running
    gcc ...options... -dM -E ...sources...
outputs only the macro definitions; a #define Name Value per macro.  Piping the output through sort makes it easier to find specific definitions; I've also used awk to recursively expand the definitions.

You can also use
    #pragma message string
during compilation.  For example:
    #define  STRINGIFY_(msg)  #msg
    #define  STRINGIFY(msg)  STRINGIFY_(msg)
    #pragma message "INTEN_SLOPE=\"" STRINGIFY(INTEN_SLOPE) "\"."
will output something like
    source.c:LINE: note: #pragma message: INTEN_SLOPE="expanded-value".
during compilation.

Navigation

[0] Message Index

[#] Next page

There was an error while thanking
Thanking...
Go to full version