[OpenBIOS] PATCH: Implement Forth source debugger for OpenBIOS

Mark Cave-Ayland mark.cave-ayland at siriusit.co.uk
Sat Oct 31 12:02:01 CET 2009


Hi all,

Whilst spending some time working on debugging SPARC64 support with 
Qemu/OpenBIOS, it became readily apparent that progress was being 
hampered by the lack of debugging facilities in OpenBIOS (see 
http://lists.openbios.org/pipermail/openbios/2009-August/003949.html). 
Hence I've been working on adding a source debugger to OpenBIOS which 
should enable developers to step/trace through Forth words in order to 
locate bugs in the lower level Forth OpenBIOS code.

The attached patch implements a Forth Source Debugger based upon the 
IEEE-1275 specification; it is not a comprehensive implementation but 
has already proved to be very useful in my tests here. A sample session 
using the debugger goes something like this:


Welcome to OpenBIOS v1.0 built on Oct 31 2009 10:09
   Type 'help' for detailed information

[unix] Booting default not supported.

0 > : bar ." test " ;  ok
0 > debug bar
Stepper keys: <space>/<enter> Up Down Trace Rstack Forth
  ok
0 > bar
: bar  ( Empty )
0xf7e11f0c: (")
: (")  ( Empty )
0xf7dfd928: r>  ( f7e11f0c )
0xf7dfd92c: dup  ( f7e11f0c f7e11f0c )
0xf7dfd930: 2  ( f7e11f0c f7e11f0c 2 )
0xf7dfd934: cells  ( f7e11f0c f7e11f0c 8 )
0xf7dfd938: +  ( f7e11f0c f7e11f14 )
0xf7dfd93c: over  ( f7e11f0c f7e11f14 f7e11f0c )
0xf7dfd940: cell+  ( f7e11f0c f7e11f14 f7e11f10 )
0xf7dfd944: @  ( f7e11f0c f7e11f14 5 )
0xf7dfd948: rot  ( f7e11f14 5 f7e11f0c )
0xf7dfd94c: over  ( f7e11f14 5 f7e11f0c 5 )
0xf7dfd950: +  ( f7e11f14 5 f7e11f11 )
0xf7dfd954: aligned  ( f7e11f14 5 f7e11f14 )
0xf7dfd958: cell+  ( f7e11f14 5 f7e11f18 )
0xf7dfd95c: >r  ( f7e11f14 5 )
0xf7dfd960: (semis)
[ Finished (") ]  ( f7e11f14 5 )
0xf7e11f1c: type test  ( Empty )
0xf7e11f20: (semis)
[ Finished bar ]  ok
0 > bar
: bar  ( Empty )
0xf7e11f0c: (")
: (")  ( Empty )
0xf7dfd928: r>
[ Up to bar ]  ( f7e11f14 5 )
0xf7e11f1c: type test  ( Empty )
0xf7e11f20: (semis)
[ Finished bar ]  ok
0 >


As eluded to in earlier posts to the list, my initial attempts at adding 
debug support were focused on storing additional information in the 
rstack. Unfortunately this created extra problems in debugging some of 
the more interesting Forth words, since they would manipulate the return 
stack and cause the debugger to get confused.

My final implementation works in a much more simple way; when the debug 
word is invoked with the name of the word to debug, the start and end 
addresses of the word are added to a debug linked list. Then in the 
next() function, we iterate through the linked list to see if the 
current PC lies within one of the functions within. If this is the case, 
we enter the source debugger in step/trace mode as appropriate.

Having given the patch a reasonably good test here, I'm quite pleased 
with the additional functionality it provides. The only minor downsides 
I can see are that the patch adds extra work in docol(), semis() and 
next() in order to update the debug linked list. I've tried to wrap most 
of the complexity in conditional while() statements so that it is only 
invoked while the debugger is active, and so should have a minimal 
impact on normal runtime performance (which seems to be the case here).

Please test the patch and let me know if it requires extra work in order 
for it to be considered ready for committing to the OpenBIOS SVN repository.


ATB,

Mark.

-- 
Mark Cave-Ayland - Senior Technical Architect
PostgreSQL - PostGIS
Sirius Corporation plc - control through freedom
http://www.siriusit.co.uk
t: +44 870 608 0063

Sirius Labs: http://www.siriusit.co.uk/labs
-------------- next part --------------
A non-text attachment was scrubbed...
Name: openbios-add-debug.patch
Type: text/x-diff
Size: 15380 bytes
Desc: not available
URL: <http://lists.openbios.org/pipermail/openbios/attachments/20091031/c02788c6/attachment.bin>


More information about the OpenBIOS mailing list