(ddd.info)GDB Argument Commands


Next: Commands with Other Debuggers Prev: GDB Simple Commands Up: Defining Commands
Enter node , (file) or (file)node

10.5.2 Defining Argument Commands using GDB
-------------------------------------------

If you want to pass arguments to user-defined commands, you can enable
the `()' toggle button in the Command Editor.  Enabling `()' has two
effects:

   * While recording commands, all references to the argument field are
     taken _symbolically_ instead of literally.  The argument field
     value is frozen to `$arg0', which is how GDB denotes the argument
     of a user-defined command.  When GDB executes the command, it will
     replace `$arg0' by the current command argument.

   * When assigning a button to the command, the command will be
     suffixed by the current contents of the argument field.

   While defining a command, you can toggle the `()' button as you wish
to switch between using the argument field symbolically and literally.

   As an example, let us define a command `contuntil' that will set a
breakpoint in the given argument and continue execution.

  1. Enter `contuntil' in the `Command' field.

  2. Enable the `()' toggle button.

  3. Now click on `Record' to start recording.  Note that the contents
     of the argument field change to `$arg0'.

  4. Click on `Break at ()' to create a breakpoint.  Note that the
     recorded breakpoint command refers to `$arg0'.

  5. Click on `Cont' to continue execution.

  6. Click on `End' to end recording.  Note that the argument field is
     restored to its original value.

  7. Finally, click on one of the `Button' locations.  This creates a
     `Contuntil ()' button where `()' will be replaced by the current
     contents of the argument field--and thus passed to the `contuntil'
     command.

  8. You can now either use the `Contuntil ()' button or enter a
     `contuntil' command at the GDB prompt.  (If you plan to use the
     command frequently, you may wish to define a `cu' command, which
     again calls `contuntil' with its argument.  This is a nice
     exercise.)

   There is a little drawback with argument commands: a user-defined
command in GDB has no means to access the argument list as a whole; only
the first argument (up to whitespace) is processed.  This may change in
future GDB releases.


automatically generated by info2www version 1.2.2.9