Thanks. The choice of gcc was somewhat arbitrary so clang could work too. I actually fiddle a bit with lldb before this.
From your description, it sounds like I'd really ought to removing optimizations (with -O0 from what's suggested here).
For variables, local variables can be optimized out (something I recall seeing in gdb without -O0) but all global variables are still kept, right? (At least, the ELF has names and addresses.)