0

I'm debuging with gdb and need to define some helper commands. Basically I want my customized command to operate differently depending on the number of args given.

So I have to test whether $arg* is given, see the code below:

define pgdir

    set $pgdir = $arg0

    if ($arg1) {
        // show the corresponding PDE
    } else {
        // show the whole page directory
    }

end

Is it possible to test whether a variable is void?

3 Answers 3

1

You can use the convenience function $_isvoid(). It returns 1 if the variable is void.

(gdb) set $v = 1
(gdb) print $_isvoid($v)
$1 = 0
(gdb) print $_isvoid($v2)
$2 = 1
0

gdb supports $argc which per the manual expands out to something from 0..10, so in your case it would probably be

define pgdir
  if $argc == 2
    ...
  else
    ...
  end
end
1
  • Thanks thrig, could you please tell me how I can test a variable is void except the answer I just posted?
    – z.h.
    Jan 6, 2019 at 16:01
0

As for my problem, there is a $argc variable so that I can do this:

define pgdir

    set $pgdir = $arg0

    if ($argc == 1) {
        // show the corresponding PDE
    } else {
        // show the whole page directory
    }

end

As for the question how to test whether a variable is void, I thought of a tricky and inelegant way: test whether the variable is equal to a variable with void value.

define func

    if ($var_to_test == $var_that_no_one_is_like_to_use_so_that_it_is_void)
        // do something

end

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .