0

So, I've been doing a lot of assembly work lately and I've found it tedious having to keep typing x/d $eax, x/d $ecx, x/t ... and so on. I edited my .gdbinit to have:

define showall
printf "Value:\n"
print $arg0
printf "Hex:\n"
x/x $arg0
printf "Decimal:\n"
x/d $arg0
print "Character:\n"
x/c $arg0
... and so on.

The problem I encountered was, when the printing for x/d or other formats which failed, the script would stop and would not execute the rest of the statements to display the other formats (if it is able to do so).

An example of the problem:

gdb someFile
showall $eax
...
:Value can't be converted to an integer.
*stops and doesn't continue to display x/c*

Is there a way to tell the script to continue, even if it isn't able to display the format?

1 Answer 1

2

I don't think there's a way to make GDB command file interpretation not stop at the first error but you can use Python scripting to do what you want.

Save this to examine-all-formats.py:

def examine_all(v):
    gdb.write('Value:\n%s\n' % v)
    try:
        v0 = int(v)
    except ValueError:
        pass
    else:
        gdb.write('Hex:\n0x%x\n'
                  'Decimal:\n%d\n'
                  % (v0, v0))
    try:
        c = chr(v)
    except ValueError:
        pass
    else:
        gdb.write('Character:\n'
                  '%r\n' % (c,))

class ExamineAll(gdb.Command):
    def __init__(self):
        super(ExamineAll, self).__init__('examine-all', gdb.COMMAND_DATA, gdb.COMPLETE_SYMBOL)

    def invoke(self, args, from_tty):
        for i in gdb.string_to_argv(args):
            examine_all(gdb.parse_and_eval(i))

ExamineAll()

Then run:

$ gdb -q -x examine-all-formats.py
(gdb) file /bin/true
Reading symbols from /usr/bin/true...Reading symbols from /usr/lib/debug/usr/bin/true.debug...done.
done.
(gdb) start
Temporary breakpoint 1 at 0x4014c0: file true.c, line 59.
Starting program: /usr/bin/true 


(gdb) examine-all argc
Value:
1
Hex:
0x1
Decimal:
1
Character:
'\x01'
(gdb) examine-all $eax
Value:
1532708112
Hex:
0x5b5b4510
Decimal:
1532708112
Sign up to request clarification or add additional context in comments.

Comments

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.