This isn't something limited to GDB but I've always wondered why no one seems to have bothered to come up with a solution after all these years so that it can actually know that the variable is in a register at that point.
Having spent some time looking at DWARF data closely, I get the impression that there is an insane amount of information generated and the format can handle way way more complex scenarios than a simple "X is in register Y" - they got a full state machine and all in there. But the tools available.. simply do not consume it? I'm not entirely sure what the disconnect is.
How to read variables optimized out in GDB?
21–24 of 24 posts
Re: How to read variables optimized out in GDB?
#22This is "How to read variables optimized out in GDB sometimes ", lest you might be misled to think that the value you are looking for is always hanging around somewhere. Sometimes, it's just gone, literally optimized out completely. Consider this piece of code: bool foo(void) { int v = some_system_call(); bool b = v > 500; some_function(b); ... /\* rest of code not using v \*/ } There is no reason for the original va…
The article actually suggests using the record command in that case.
Re: How to read variables optimized out in GDB?
#23https://github.com/rurban/binutils-gdb/commits/users/rurban/...
Re: How to read variables optimized out in GDB?
#24This isn't something limited to GDB but I've always wondered why no one seems to have bothered to come up with a solution after all these years so that it can actually know that the variable is in a register at that point.
Assuming you're referring to the articles first example, I suspect optimised-out is the correct outcome in that situation. The program is stopped at the start of one function, and the author is looking one stack frame up at this code: 0x0000564ab5d178c4 : callq *%rax => 0x0000564ab5d178c6 : mov %rbp,%rdi %rsi indeed hasn't been clobbered when the call executes, but it becomes liable to be clobbered during the executi…