changeset 2955:a0b770fab355

Add scripts/os9.gdb and list2crc.pl for gdb debugging Some gdb commands to facilitate debugging with gdb (on XRoar). Uses GVIM as external code viewer. Example: mkdir lst make PORTS=coco1 LISTDIR=$PWD/lst cd lst for f in *.lst; do ../scripts/list2crc.pl $f; done m6809-gdb (gdb) source ../scripts/os9.gdb (gdb) tar rem :65520 (gdb) os9_mwhere (print current module, update source viewer) (gdb) os9_mdir (list all registered modules and their entry points) (gdb) hbreak *0xa243 (set breakpoint on entry of SHELL) (gdb) cont (gdb) b9 0x56 (set a breakpoint at offset 0x56 in SHELL) (gdb) cont
author Tormod Volden <debian.tormod@gmail.com>
date Sun, 09 Feb 2014 21:44:25 +0100
parents 43588191b624
children 34edacfd1142
files scripts/list2crc.pl scripts/os9.gdb
diffstat 2 files changed, 136 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/scripts/list2crc.pl	Sun Feb 09 21:44:25 2014 +0100
@@ -0,0 +1,39 @@
+#!/usr/bin/perl
+
+# Copyright 2014  Tormod Volden
+#
+# Digests assembly listings generated by lwasm, and stores the
+# module body listing in a file named by the module CRC.
+# Example: for f in *.lst; do ../scripts/list2crc.pl $f; done
+
+open(CRCFILE, ">", "crc.tmp") or die "cannot create crc.tmp: $!";
+
+while (<>) {
+	($hoffset, $opbytes, $filepath, $lineno,  $label, $opcode, $operand, $comment) =
+		( $_ =~ /^(\w+) (\w+)\s+\((.*)\):(\d+) (\S+)?\s+(\w+)\s*(\S+)?\s*(.*)?/ );
+
+	# print $hoffset, "\t", $opcode, "\t", $comment, "\n";
+	if (lc($opcode) eq "mod") {
+		$in_module = 1;
+	}
+
+	if (lc($opcode) eq "emod") {
+		die "double emod" if $found_emod;
+		$found_emod = 1;
+		$crc = $opbytes;
+		$in_module = 0;
+	}
+
+#	if ($in_module && $hoffset) {
+#		$offset = hex($hoffset);
+#		print CRCFILE "$offset\t$filepath\t$lineno\n";
+#	}
+	if ($in_module) {
+		print CRCFILE $_
+	}
+}
+close(CRCFILE);
+if ($crc) {
+	print "writing $crc.crc\n";
+	rename "crc.tmp", $crc . ".crc";
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/scripts/os9.gdb	Sun Feb 09 21:44:25 2014 +0100
@@ -0,0 +1,97 @@
+# gdb scripts for NitrOS-9 (or OS-9)
+# Copyright 2014  Tormod Volden
+
+# os9_mdir prints out registered modules, like os9 mdir command
+
+# pretty-print of registers on every halt,
+# and update external source code window
+define hook-stop
+	printf "S=%04x X=%04x Y=%04x U=%04x A=%02x B=%02x CC=%02x PC=%04x ", $s, $x, $y, $u, $a, $b, $cc , $pc
+	os9_mwhere
+end
+
+# print name of module at given address
+define os9_mname
+	set $mname = (char*)$arg0 + *((int*)$arg0 + 2)
+	while 1
+		if (*$mname < 0x80)
+			printf "%c", *$mname
+		else
+			printf "%c", *$mname-0x80
+			loop_break
+		end
+		set $mname += 1
+	end
+end
+
+# print details of module at given address
+define os9_mident
+	set $m = (int*)$arg0
+	set $msize = *($m + 1)
+	set $mtype = *((char*) $m + 6)
+	set $mexec = *(int*)((char*) $m + 9)
+	printf "%04x %4x %2X ", $m, $msize, $mtype
+	os9_mname $m
+	if ($mtype & 0xf)
+		printf "\t[exec %04x] ", (char*)$m + $mexec
+	end
+	printf "\n"
+end
+
+# list all registered modules
+define os9_mdir
+	printf "addr size ty name\n"
+	set $mt = 0x300
+	while ($mt < 0x400)
+		if ((int*)*$mt)
+			os9_mident (int*)*$mt
+		end
+		set $mt += 4
+	end
+end
+
+# finds module at given address, sets $mstart
+define os9_mwhich
+	set $pc_reg = $arg0
+	set $mt = 0x300
+	while ($mt < 0x400)
+		if ((int*)*$mt)
+			set $mstart = (int*)*$mt
+			set $mend = (char*)$mstart + *($mstart + 1)
+			if ($pc_reg >= $mstart && $pc_reg < $mend)
+				loop_break
+			end
+		end
+		set $mt += 4
+	end
+	if ($mt == 0x400)
+		set $mstart = 0
+	end
+end
+
+
+# Look up source code line for given address.
+# Requires assembly list files named by CRC in current directory
+# and "gvim" to display listing and highlight line.
+define os9_mwhere
+	if ($argc == 1)
+		set $pc_reg = $arg0
+	else
+		set $pc_reg = $pc
+	end
+	os9_mwhich $pc_reg
+	if ($mstart)
+		printf "inside "
+		os9_mname $mstart
+		printf "\n"
+		eval "!gvim --remote %02X%02X%02X.crc && gvim --remote-send \":set cursorline<CR>\" && gvim --remote-send \"/^%04X<CR>\"", *((char*)$mend-3), *((char*)$mend-2), *((char*)$mend-1), (char*)$pc_reg - (char*)$mstart
+	else
+		printf "no module\n"
+	end
+end
+
+# Set breakpoint in current module, at given offset
+define b9
+	os9_mwhich $pc
+	eval "hbreak *0x%x", (int)$mstart + $arg0
+end