patch-2.1.104 linux/scripts/ksymoops.cc

Next file: linux/COPYING
Previous file: linux/net/wanrouter/wanmain.c
Back to the patch index
Back to the overall index

diff -u --recursive --new-file v2.1.103/linux/scripts/ksymoops.cc linux/scripts/ksymoops.cc
@@ -26,6 +26,9 @@
 // command-line argument, and redirect the oops-log into stdin.  Out
 // will come the EIP and call-trace in symbolic form.
 
+// Changed by Andreas Schwab <schwab@issan.informatik.uni-dortmund.de>
+// adapted to Linux/m68k
+
 //////////////////////////////////////////////////////////////////////////////
 
 // BUGS:
@@ -39,8 +42,9 @@
 #include <stdlib.h>
 #include <unistd.h>
 #include <ctype.h>
+#include <a.out.h>
 
-inline int strnequ(char const* x, char const* y, size_t n) { return (::strncmp(x, y, n) == 0); }
+inline int strnequ(char const* x, char const* y, size_t n) { return (strncmp(x, y, n) == 0); }
 
 const int code_size = 20;
 
@@ -149,32 +153,34 @@
     /* This is a hack to avoid using gcc.  We create an object file by
        concatenating objfile_head, the twenty bytes of code, and
        objfile_tail.  */
-    unsigned char objfile_head[] = {
-	0x07, 0x01, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00,
-	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-	0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
+    static struct exec objfile_head = {
+	OMAGIC, code_size + 4, 0, 0, sizeof (struct nlist) * 3, 0, 0, 0
     };
-    unsigned char objfile_tail[] = {
-	0x00, 0x90, 0x90, 0x90,
-	0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
-	0x00, 0x00, 0x00, 0x00, 0x13, 0x00, 0x00, 0x00,
-	0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-	0x25, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00,
-	0x00, 0x00, 0x00, 0x00, 0x2a, 0x00, 0x00, 0x00,
-	'g',  'c',  'c',  '2',  '_',  'c',  'o',  'm',  
-	'p',  'i',  'l',  'e',  'd',  '.',  '\0', '_',  
-	'E',  'I',  'P',  '\0', '\0', '\0', '\0', '\0',
-	'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
-	'\0', '\0', '\0', '\0', '\0', '\0'
+    static struct {
+	unsigned char tail[4];
+	struct nlist syms[3];
+	unsigned long strsize;
+	char strings[42];
+    } objfile_tail = {
+#ifdef i386
+	{ 0x00, 0x90, 0x90, 0x90 },
+#endif
+#ifdef mc68000
+	{ 0x00, 0x00, 0x00, 0x00 },
+#endif
+	{ { (char *) 4, N_TEXT, 0, 0, 0 },
+	  { (char *) 19, N_TEXT, 0, 0, 0 },
+	  { (char *) 37, N_TEXT | N_EXT, 0, 0, 0 } },
+	42,
+	"gcc2_compiled.\0___gnu_compiled_c\0_EIP\0"
     };
     char const* objdump_command = "objdump -d oops_decode.o";
     char const* objfile_name = &objdump_command[11];
     ofstream objfile_stream(objfile_name);
 
-    objfile_stream.write(objfile_head, sizeof(objfile_head));
+    objfile_stream.write((char *) &objfile_head, sizeof(objfile_head));
     objfile_stream.write(code, code_size);
-    objfile_stream.write(objfile_tail, sizeof(objfile_tail));
+    objfile_stream.write((char *) &objfile_tail, sizeof(objfile_tail));
     objfile_stream.close();
     
     FILE* objdump_FILE = popen(objdump_command, "r");
@@ -197,8 +203,8 @@
 	    memset(newbuf, '\0', sizeof(newbuf));
 	    ostrstream ost(newbuf, sizeof(newbuf));
 	    ost.width(8);
-	    ost << offset;
-	    ost << " <_EIP+" << offset << ">: " << &buf[6] << ends;
+	    ost << hex << offset;
+	    ost << " <_EIP+" << hex << offset << ">: " << &buf[6] << ends;
 	    strcpy(buf, newbuf);
 	}
 	if (!strnequ(&buf[9], "<_EIP", 5))
@@ -233,6 +239,7 @@
 	    bp++;
 	if (!isxdigit(*bp)) {
 	    cout << bp_0;
+#ifdef i386
 	} else if (*bp_1 == 'j' || strnequ(bp_1, "call", 4)) { // a jump or call insn
 	    long rel_addr = strtol(bp, 0, 16);
 	    ksym = find(eip_addr + rel_addr);
@@ -241,6 +248,21 @@
 		cout << bp_0 << *ksym << endl;
 	    } else
 		cout << bp_0;
+#endif
+#ifdef mc68000
+	} else if ((bp_1[0] == 'b' && bp_1[4] == ' ' && strchr("swl", bp_1[3]))
+		   || (bp_1[0] == 'd' && bp_1[1] == 'b')) {
+	    // a branch or decr-and-branch insn
+	    if (bp_1[0] == 'd') // skip register
+		while (*bp && *bp++ != ',');
+	    long rel_addr = strtoul(bp, 0, 16);
+	    ksym = find(eip_addr + rel_addr);
+	    if (ksym) {
+		*bp++ = '\0';
+		cout << bp_0 << *ksym << endl;
+	    } else
+	      cout << bp_0;
+#endif
 	} else {
 	    cout << bp_0;
 	}
@@ -308,6 +330,7 @@
 	if (cin.eof())
 	    break;
 	cin.get(c);	/* swallow newline */
+#ifdef i386
 	if (strstr(buffer, "EIP:") && names.valid()) {
 	    oops_column =  strstr(buffer, "EIP:");
 	    if (sscanf(oops_column+13, "[<%x>]", &eip_addr) != 1) {
@@ -321,6 +344,22 @@
 	    else
 		cout << ::hex << eip_addr << " cannot be resolved" << endl;
 	}
+#endif
+#ifdef mc68000
+	if (strstr(buffer, "PC:") && names.valid()) {
+	    oops_column =  strstr(buffer, "PC:");
+	    if (sscanf(oops_column+4, "[<%x>]", &eip_addr) != 1) {
+	    	cout << "Cannot read pc address from PC: line.  Is this a valid oops file?" << endl;
+		exit(1);
+	    }
+	    cout << ">>PC: ";
+	    KSym* ksym = names.find(eip_addr);
+	    if (ksym)
+		cout << *ksym << endl;
+	    else
+		cout << ::hex << eip_addr << " cannot be resolved" << endl;
+	}
+#endif
 	else if (oops_column && strstr(oops_column, "[<") && names.valid()) {
 	    unsigned long address;
 	    while (strstr(oops_column, "[<")) {
@@ -356,6 +395,9 @@
 		    ++p;
 		if (sscanf(p, "%x", &c) != 1)
 		    break;
+#ifdef mc68000
+		*cp++ = c >> 8;
+#endif
 		*cp++ = c;
 	    	while (*p && *p++ != ' ')
 		    ;


FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen, slshen@lbl.gov