1

How can I define a gdb convenience function with optional args? I've tried below, which doesn't work:

(gdb) define v
Type commands for definition of "v".
End with a line saying just "end".
>if $argc == 1
 >echo 1
 >else if $argc == 2
 >echo 2
 >else
 >echo neither
 >end
>end
(gdb) v
neither(gdb) v 1
1Undefined command: "else".  Try "help".
(gdb) v 2
1Undefined command: "else".  Try "help".

1 Answer 1

1

I've tried below, which doesn't work:

It doesn't work because there is no else in the GDB scripting language.

You can work around this with:

define v
  if $argc == 1
    echo 1
  end
  if $argc == 2
    echo 2
  end
  if $argc < 1 || 2 < $argc 
    echo neither
  end
end

but you'll probably get better results by deferring to the embedded Python.

Sign up to request clarification or add additional context in comments.

1 Comment

From what I can see, there is else, but no else if.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.