This is the mail archive of the gdb@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

using $argc for variable number of args functions


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]