Debugging with GDB: Convenience Funs

Next: Registers, Previous: Convenience Vars, Up: Data [Contents][Index]

### 10.12 Convenience Functions

GDB also supplies some convenience functions. These have a syntax similar to convenience variables. A convenience function can be used in an expression just like an ordinary function; however, a convenience function is implemented internally to GDB.

These functions do not require GDB to be configured with `Python` support, which means that they are always available.

`$_isvoid (expr)`

  Return one if the expression expr is `void`. Otherwise it returns zero.

  A `void` expression is an expression where the type of the result is `void`. For example, you can examine a convenience variable (see Convenience Variables) to check whether it is `void`:

      (gdb) print $_exitcode
      $1 = void
      (gdb) print $_isvoid ($_exitcode)
      $2 = 1
      (gdb) run
      Starting program: ./a.out
      [Inferior 1 (process 29572) exited normally]
      (gdb) print $_exitcode
      $3 = 0
      (gdb) print $_isvoid ($_exitcode)
      $4 = 0

  In the example above, we used `$_isvoid` to check whether `$_exitcode` is `void` before and after the execution of the program being debugged. Before the execution there is no exit code to be examined, therefore `$_exitcode` is `void`. After the execution the program being debugged returned zero, therefore `$_exitcode` is zero, which means that it is not `void` anymore.

  The `void` expression can also be a call of a function from the program being debugged. For example, given the following function:

      void
      foo (void)
      {
      }

  The result of calling it inside GDB is `void`:

      (gdb) print foo ()
      $1 = void
      (gdb) print $_isvoid (foo ())
      $2 = 1
      (gdb) set $v = foo ()
      (gdb) print $v
      $3 = void
      (gdb) print $_isvoid ($v)
      $4 = 1

These functions require GDB to be configured with `Python` support.

`$_memeq(buf1, buf2, length)`

  Returns one if the length bytes at the addresses given by buf1 and buf2 are equal. Otherwise it returns zero.

`$_regex(str, regex)`

  Returns one if the string str matches the regular expression regex. Otherwise it returns zero. The syntax of the regular expression is that specified by `Python`’s regular expression support.

`$_streq(str1, str2)`

  Returns one if the strings str1 and str2 are equal. Otherwise it returns zero.

`$_strlen(str)`

  Returns the length of string str.

GDB provides the ability to list and get help on convenience functions.

`help function`

  Print a list of all convenience functions.

Next: Registers, Previous: Convenience Vars, Up: Data [Contents][Index]