jgarzik/moxiebox — pull request #13 by atgreen (2014-12-29 04:41:47+00:00)
Title: Add GDB support.

This PR adds gdb support to moxiebox.
Once configured with --enable-gdb, a new command line option (-g ) causes sandbox to wait for a moxie gdb connection on the given port. Here's an example of debugging the 'basic' test from the moxiebox testsuite...

$ ../src/sandbox -e ./basic -g 9999
ep 00001000
ro 00000f6c-00001536 elf0
ro 00001538-00001540 elf1
rw 00001640-00001ab4 elf2
rw 00002ab4-00012ab4 stack
ro 00013ab4-00013b74 mapdesc

[green@localhost tests]$ moxie-elf-gdb basic
GNU gdb (GDB) 7.8.50.20141227-cvs
Copyright (C) 2014 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "--host=x86_64-unknown-linux-gnu --target=moxie-elf".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
.
Find the GDB manual and other documentation resources online at:
.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from basic...done.
(gdb) target remote localhost:9999
Remote debugging using localhost:9999
0x00001000 in __start ()
(gdb) b main
Breakpoint 1 at 0x14c8
(gdb) c
Continuing.

Breakpoint 1, 0x000014c8 in main ()
(gdb) x/4i $pc
=> 0x14c8 :	xor	$r5, $r5
0x14ca :	mov	$r4, $r5
0x14cc :	lda.l	$r3, 0x1644
0x14d2 :	lda.l	$r2, 0x1648
(gdb) si
0x000014ca in main ()
(gdb) display/4i $pc
1: x/4i $pc
=> 0x14ca :	mov	$r4, $r5
0x14cc :	lda.l	$r3, 0x1644
0x14d2 :	lda.l	$r2, 0x1648
0x14d8 :	ldi.l	$r1, 0x10000
(gdb) si
s0x000014cc in main ()
1: x/4i $pc
=> 0x14cc :	lda.l	$r3, 0x1644
0x14d2 :	lda.l	$r2, 0x1648
0x14d8 :	ldi.l	$r1, 0x10000
0x14de :	mov	$r0, $r5
(gdb) si
0x000014d2 in main ()
1: x/4i $pc
=> 0x14d2 :	lda.l	$r2, 0x1648
0x14d8 :	ldi.l	$r1, 0x10000
0x14de :	mov	$r0, $r5
0x14e0 :	jsra	0x11b0
(gdb) b mmap
Breakpoint 2 at 0x11b0
(gdb) c
Continuing.

Breakpoint 2, 0x000011b0 in mmap ()
1: x/4i $pc
=> 0x11b0 :	swi	0x5a
0x11b6 :	ret
0x11b8 :	dec	$sp, 0x18
0x11ba :	xor	$r3, $r3
(gdb) where
#0 0x000011b0 in mmap ()
#1 0x000014e6 in main ()
(gdb)