How to read variables optimized out in GDB?
1–10 of 24 posts
Re: How to read variables optimized out in GDB?
#2So you can do similar tricks in LLDB, Visual Studio, and many others.
Re: How to read variables optimized out in GDB?
#3Re: How to read variables optimized out in GDB?
#4Re: How to read variables optimized out in GDB?
#5Re: How to read variables optimized out in GDB?
#6This 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.
Re: How to read variables optimized out in GDB?
#7This 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.
Re: How to read variables optimized out in GDB?
#8This 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.
I haven't looked at DWARF for ages. Can it describe the situation that a variable is valid (in some register) in the beginning of a function, but then goes "out of scope " in the middle of the function?
Re: How to read variables optimized out in GDB?
#9This 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.
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 execution of the callee. By the next instruction (at +54) there's no guarantee that %rsi contains the correct value, thus it's best reported as optimised out. The author is handily stopped at a point in time between the two instructions displayed above (in a lower stack frame), where the correct value happens to be in %rsi, but this is not guaranteed to be always true.Re: How to read variables optimized out in GDB?
#10Sometimes, 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 value of v to stick around any longer than until the comparison with 500 has been made.Even though the syntactic scope of "int v" tells you that v is valid for the rest of the function body, and indeed it is while you are writing the source code, an optimizing compiler can and should make use of the fact that you are not actually using it anymore.