Search code examples
cdebuggingstaticiar

Static variable cannot be found by name when debugging


I have a static variable in one of my compilation units, which is compiled with no optimizations:

static __no_init enum_type status;

I'm trying to watch this variable in the debugger, but I cannot find it. Stepping through the functions which update status I can see expected values to be written to a particular memory address, 0xFB9F8.

However, that memory address seems to have no name. Here's what the linker map shows:

NEAR_N
  Relative segment, address: 000FB9F8 - 000FB9F8 (0x1 bytes), align: 0
  Segment part 3.             Intra module refs:   function1
                                                   function2

Indeed, function1, function2 etc. are function which access that variable.

How do I make that variable visible in the debugger?


Solution

  • I found the solution when the question was already half-written, so I decided to post it with a self-answer.

    Anyway, there is a setting in the linker options which does just what I need and is unsurprisingly called "Module-local symbols":

    enter image description here

    Setting it to "Include all" makes static variables available to the debugger.