I'm currently using GDB to debug my assembly programs. I have setup my .gdbinit with defines to dump and display things so it's all clear as I step through the program.
What I can't do, and would love to do, is expand the flags into what they exactly, instead of 0x0202 for instance.. I woul like to see "zf=1 of=0 df=2...etc". Any idea how to do this?
thanks,
mywyoo
GDB
Re:GDB
no hehe..
With a little playing, I learned you can do bitwise manipulations with your user defined commands in gdb, so if it's any use to people using gdb that want to step through their assembly programs and see info each step, try this, put the following code in a file and run gdb -x file file_to_debug, or put it in gdb.ini (in windows) and .gdbinit in unix, it isn't turbo debugger, but it works
sample output:
Ok, I'm happy now.. I think I just may have my environment setup the way I like it and can begin writing an OS to play with =)
With a little playing, I learned you can do bitwise manipulations with your user defined commands in gdb, so if it's any use to people using gdb that want to step through their assembly programs and see info each step, try this, put the following code in a file and run gdb -x file file_to_debug, or put it in gdb.ini (in windows) and .gdbinit in unix, it isn't turbo debugger, but it works
Code: Select all
#
# disass _start
#
# I do this because I have a nop after _start, since gdb doesn't
#
# disass _start
#
# I do this because I have a nop after _start, since gdb doesn't
# like a breakpoint at _start
#
# b *_start+1
#
#
# expand EFLAGS per flag (the ones I want)
#
define show_flags
set $cf = ( $eflags & 0x1 )
set $pf = (( $eflags >> 2) & 0x1 )
set $af = (( $eflags >> 4) & 0x1 )
set $zf = (( $eflags >> 6) & 0x1 )
set $sf = (( $eflags >> 7) & 0x1 )
set $tf = (( $eflags >> 8) & 0x1 )
set $if = (( $eflags >> 9) & 0x1 )
set $df = (( $eflags >> 10) & 0x1 )
set $of = (( $eflags >> 11) & 0x1 )
printf "of=%d, df=%d, if=%d, tf=%d, sf=%d, zf=%d, af=%d, pf=%d, cf=%d\n", \
$of,$df,$if,$tf,$sf,$zf,$af,$pf,$cf
end
#
# step through instructions and display information
#
define s
si
printf "\n--------------------------------------------------------------------------------\n"
printf "Registers:\n"
printf "%%eax=0x%08x, %%ebx=0x%08x, %%ecx=0x%08x, %%edx=0x%08x\n", $eax, $ebx, $ecx, $edx
printf "%%esp=0x%08x, %%ebp=0x%08x, %%esi=0x%08x, %%edi=0x%08x\n", $esp, $ebp, $esi, $edi
printf "%%eip=0x%08x\n", $eip
printf "--------------------------------------------------------------------------------\n"
printf "Flags:\n"
show_flags
printf "--------------------------------------------------------------------------------\n"
printf "Stack (10 words):\n"
set $c = 36
while ( $c >= 0 )
x/x $sp+$c
set $c-=4
end
set $c = 36
printf "--------------------------------------------------------------------------------\n"
disass $pc $pc+10
end
sample output:
Code: Select all
(gdb) b *_start+1
Breakpoint 1 at 0x8048075
(gdb) r
Starting program: /usr/home/rayg/code/pgu/factorial
Breakpoint 1, 0x08048075 in _start ()
(gdb) s
0x08048076 in _start ()
--------------------------------------------------------------------------------
Registers:
%eax=0x00000000, %ebx=0x00000000, %ecx=0x00000000, %edx=0x00000000
%esp=0xbfbffb00, %ebp=0x00000000, %esi=0x00000000, %edi=0x00000000
%eip=0x08048076
--------------------------------------------------------------------------------
Flags:
of=0, df=0, if=1, tf=0, sf=0, zf=0, af=0, pf=0, cf=0
--------------------------------------------------------------------------------
Stack (10 words):
0xbfbffb24: 0xbfbffd38
0xbfbffb20: 0xbfbffd23
0xbfbffb1c: 0xbfbffcfe
0xbfbffb18: 0xbfbffc47
0xbfbffb14: 0xbfbffc35
0xbfbffb10: 0xbfbffc2a
0xbfbffb0c: 0xbfbffc06
0xbfbffb08: 0x00000000
0xbfbffb04: 0xbfbffbe4
0xbfbffb00: 0x00000001
--------------------------------------------------------------------------------
Dump of assembler code from 0x8048076 to 0x8048080:
0x8048076 <_start+2>: push $0x4
0x8048078 <_start+4>: call 0x8048089 <factorial>
0x804807d <_start+9>: pop %ebx
0x804807e <_start+10>: mov %eax,%ebx
End of assembler dump.
(gdb)