I'm stuck because of a combination of:
Even with its many limitations, you might still find this useful. It must be better than inserting 'cputs' everywhere!
Everything here describes the set up for Linux only. I see no reason it shouldn't work just as well (or just as badly!) on Windows.
BREAKPOINT;
inserted into a legOS application drops into gdb).
BREAKPOINT (e.g., as the result of the Prgm key being
pressed), or as the result of a breakpoint inserted by gdb.
jsr @@0x0c at the breakpoint
address. (See here for an alternate way of
inserting a breakpoint, suggested by Markus L. Noga).
tar xf
gdblegos.tar. This tar file doesn't overwrite any standard
legOS files. This installs the file rcx-stub.c in
$LEGOS_ROOT/kernel, rcx-stub.h in
$LEGOS_ROOT/include and gdbsrv.py in
$LEGOS_ROOT.
DBG_HOST_PORT and
DBG_TARGET_PORT in rcx-stub.h, then rebuild the
kernel.
Prepare your application for debugging.
Then modify the application Makefile .o.c rule to read:COPTDBG =-g -fno-builtin CFLAGSDBG=$(COPTDBG) $(CWARN) $(CINC)
%.o: %.c $(CC) $(CFLAGSDBG) -c $*.c -o $*.o
**BUG** Turning off the optimizer causes compile errors when
calling motor_a_dir legOS functions. I think this is
something to do with inline directives. Running gdb with the optimizer
is not a disaster, but it can get confusing.
debugInit() near the top
of main. This initializes the debugger, and sets up lnp
handlers,
This displays the relocation address on the LCD (0xb054 on my version of the kernel). Fortunately, you only need to this after a kernel change.// Print out start address. Used to find offset for generating coff // files. #include <unistd.h> #include <conio.h> int main(int argc, char *argv[]) { cputw((int)main); return 0; }
**BUG** There must be an easier way to get the relocation address than this!
You need to replace# Put this line somewhere near the top COFFFLAGS=-T$(LEGOS_ROOT)boot/legOS.lds -relax -L$(LEGOS_ROOT)/lib \ -Ttext <EDITME> --oformat coff-h8300 # Modify the .ds1.o rule to produce a coff file as well. %.ds1: %.o $(DOBJECTS) $(DYNAMIC_LDS) $(LD) $(DLDFLAGS) $*.o $(DOBJECTS) $(LIBS) -o $*.ds1 -Ttext $(BASE1) $(LD) $(COFFFLAGS) $*.o $(DOBJECTS) $(LIBS) -o $*.coff
<EDITME> with the relocation
address discovered earlier. This should produce a .coff file, in
addition to the usual .lx file.
Note the --target line.GNU gdb 4.17 Copyright 1998 Free Software Foundation, Inc. GDB is free software, covered by the GNU General Public License, and you are welcome to change it and/or distribute copies of it under certain conditions. Type "show copying" to see the conditions. There is absolutely no warranty for GDB. Type "show warranty" for details. This GDB was configured as "--host=i686-pc-linux-gnu --target=h8300-hitachi-hms"... (gdb)
BREAKPOINT; at interesting
points in your program.
BREAKPOINT; as the result of a key press. I
like to to this from a separate task like this:
Every time the Prgm key is pressed, gdb drops into a breakpoint.wakeup_t KeyCheck(wakeup_t data) { if (dkey == KEY_PRGM) { return 1; } return 0; } int waitForKey(int argc, char** argv) { int kv; while (1) { if ((kv = wait_event(KeyCheck, 0))) { if (kv == 1) { BREAKPOINT; } } } } int main(int argc, char **argv) { debugInit(); execi(waitForKey, 0, 0, PRIO_NORMAL, DEFAULT_STACK_SIZE); ... }
BREAKPOINT; in your
application, and that it is getting executed. There's no way for gdb
to interrupt a running legOS program, so you must co-operate with gdb
to get its attention.
BREAKPOINT; are fine, its
just those inserted at run time by gdb that fail. I'm sure this is
caused by the debug stub code. What's needed is a better understanding
of how gdb inserts & restores breakpoints.
inline
functions in the kernel. A solution might be to wrap these inside
normal functions built into the kernel.