[RFC] Alternate approach to keeping convenience variables

Andrew STUBBS andrew.stubbs@st.com
Tue Jan 24 11:44:00 GMT 2006


Jim Blandy wrote:
> The $trace_frame variable is set to -1 when GDB starts, which
> indicates that there's no trace frame selected.  I think it would be a
> little more helpful for the variables to always exist: you can write
> user-defined commands that give a reasonable error message, for
> example.  GDB doesn't have any way (?) to check whether a convenience
> variable has been initialized yet.

A newly created convenience variable has the value 'void'. (A variable 
is created the first time it is referenced, even as an rvalue.) 
Therefore, if it is 'void' it can be considered uninitialised.

This is how the 'init-if-undefined' command works.

The only way (I know of) to set it back to 'void', once assigned another 
value, is to assign the value of another uninitialised variable, which I 
would consider as copying the undefined status as well as the value 'void'.

So an example GDB script fragment to check a variable might look like this:

set $temp = $trace_frame
init-if-undefined $temp = 99999
if $temp == 99999

Copying the value to $temp ensures that the original variable 
$trace_frame remains undamaged.

HTH

Andrew Stubbs



More information about the Gdb-patches mailing list