You need to log in to create posts and topics.

debugging global and local variables

When debugging is started, the global variables of the source code can be displayed and read in the 
mcu-monitor under the "Watch" tab, as far as I know. Is it possible to also display and read local
variables in the mcu-monitor? That would greatly simplify debugging the source code.

 

Hi.

It is not possible to debug local variables.

That's the point. Perhaps, by using the right arguments during compilation, the local variables could be 
included in the hex or elf file and thus made visible in the MCU monitor. I don't know how much effort
that would entail, but it might be worth considering.
The development team might find this implementation interesting. I think it would definitely be interesting
for the user.

I don't think that using different arguments during compilation would help.
and I don't see a solution for this.

Possible solution:
I've created a tool using vibe-coding (vscode, Python, Claude Sonnet 4.5) that does the following:

### Technical Workflow

```
1. GUI (main_window.py)
↓ (run_build)

2. Build Engine (build_visible.py)

├─→ Pass 1: run_cli_compile()
│ └─→ Arduino-CLI compiles WITHOUT keep_syms
│ ├─→ Creates .o files (Object files: compiled machine code + symbol table, not yet linked)
│ └─→ Creates .elf binary (executable firmware with linked symbols)

├─→ Symbol Extraction (generate_keep_syms.py)
│ ├─→ nm_globals_obj(): Global variables from .o (BEFORE linker optimization!)
│ ├─→ nm_all_symbols(): Local static variables from .elf (AFTER linker)
│ └─→ Optional: extract_dwarf_variables(): DWARF analysis (local variables)

├─→ Generate keep_syms code
│ └─→ generate_keep_code_inline(): C code as string

├─→ Embed in .ino
│ └─→ embed_keep_syms_in_ino(): Between marker comments

├─→ Pass 2: run_cli_compile()
│ └─→ Arduino-CLI compiles WITH keep_syms
│ └─→ Linker keeps all variables

└─→ Copy artifacts
├─→ <Sketch>/Blink.elf
├─→ <Sketch>/Blink.hex
├─→ <Sketch>/Blink.ino.elf
├─→ <Sketch>/Blink.ino.hex
└─→ <Sketch>/build_Blink/...

The hex and elf files, containing all variables and symbols, are now available and can be manually loaded as firmware (hex files) onto the mega328-109. The problem is that when "debugging" is performed, the loaded firmware isn't used; instead, it's recompiled. This overwrites the hex file. If there were a way to use the loaded firmware during "debugging" without recompiling, it might work. Therefore, during "debugging," it would be necessary to determine whether firmware has been manually loaded and then ask whether "debugging" should be performed with or without compilation. With the modified hex and elf files, the MCU monitor would then likely display the desired variables.

I have attached the complete description of the program as an appendix. Try to upload app_en.txt --> not allowed to upload file

Thanks for the solution, but not sure how this method can help.

For example, often local variables are just optimized out so they don't really exist.

In any case did you check tat there is actually information about local variables?
Can you share some output containing this information using some simple example?

 

The hex and elf files, containing all variables and symbols, are now available and can be manually loaded as firmware (hex files) onto the mega328-109. The problem is that when "debugging" is performed, the loaded firmware isn't used; instead, it's recompiled. This overwrites the hex file. If there were a way to use the loaded firmware during "debugging" without recompiling, it might work.

For something like this you can create a new compiler that uses your python script and use it instead of Arduino compiler.

 

I have attached the complete description of the program as an appendix. Try to upload app_en.txt --> not allowed to upload file

I will have a look, but for text you can use a "blockquote" like this one above.

 

EDIT:
Local static variables should be working as they are permanent.