using $argc for variable number of args functions
Dan Nicolaescu
dann@ics.uci.edu
Mon Nov 21 01:17:00 GMT 2005
If one wants to use $args to implement a variable number of arguments
function a lot of code needs to be written.
For example a function that prints the values of some variables that
could be used like:
p var1
pr
pr var1
pr var1 var2 var3
etc etc
The pr function would have to be written like:
(I hope I am not missing something that would allow some simplification)
define pr
if $argc == 0
debug_print ($)
end
if $argc == 1
debug_print ($arg0)
end
if $argc == 2
debug_print ($arg0)
debug_print ($arg1)
end
if $argc == 3
debug_print ($arg0)
debug_print ($arg1)
debug_print ($arg3)
end
... etc etc
It would be nice if a "shift" command would be available to shift the
positional arguments, the same way as it is done in shells. Then the
above function could be written like:
define pr
if $argc == 0
debug_print ($)
end
while $argc > 0
debug_print ($arg0)
shift
end
end
I don't know if the above is even possible in gdb...
Thanks
--dan
More information about the Gdb
mailing list