Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Testing if a gdb convenience variable is defined

Tags:

gdb

Is there a way to test if a convenience variable has been set in gdb?

For example:

(gdb) if $_exitcode == 0
 >quit
 >end
Invalid type combination in equality test.
(gdb) p $_exitcode
$1 = void

$_exitcode is void because it is not set until the program terminates. The closest available construct is init-if-undefined, but this would require setting the variable to some sentinel value and testing against that.

like image 849
Matt Joiner Avatar asked Sep 19 '10 04:09

Matt Joiner


2 Answers

Since normal process exit code is somewhere in between 0 and 255, I suggest following:

init-if-undefined $_exitcode = -1
if ($_exitcode != -1)
  quit
end
like image 179
l0ki Avatar answered Oct 10 '22 04:10

l0ki


Im having the same problem.. you can't check if a variable has been set or not as far as I know in GDB.. you could run it through python, probably, and have the whole script run that way, but I am unsure of it the python scripts in GDB are persistent or running all the time. You could do something like..

init-if-undefined $_exitcode = 1
if $_exitcode == 0
quit
end
end
like image 40
user650649 Avatar answered Oct 10 '22 04:10

user650649