xmon support for symbol lookup

olof at austin.ibm.com olof at austin.ibm.com
Thu Feb 26 12:59:00 EST 2004


Paul,

Thanks for your feedback, see below.

On Thu, 26 Feb 2004, Paul Mackerras wrote:

> Hopefully you mean "la <address>" and "ls <symbol>", at least that is
> what the code seems to implement.

Ack, yes. Helptext has been updated to clarify too.

Whitespace weirdness was partially because I was tring to follow the weird
existing style of ppc-dis.c. The space/tab-issue was cut-n-paste garbage.
All that has been fixed.

I also consolidated some of the static char arrays to use one global
instead to save some BSS.


Actually, I can push everything but the "ls" functionality soonish
if it'll take a while to get the kallsyms change into mainline.


-Olof

Olof Johansson                                        Office: 4E002/905
Linux on Power Development                            IBM Systems Group
Email: olof at austin.ibm.com                          Phone: 512-838-9858
All opinions are my own and not those of IBM


>
> > ===== arch/ppc64/xmon/ppc-dis.c 1.1 vs edited =====
> > --- 1.1/arch/ppc64/xmon/ppc-dis.c	Thu Feb 14 06:14:36 2002
> > +++ edited/arch/ppc64/xmon/ppc-dis.c	Wed Feb 25 11:22:49 2004
>
> Someone needs to update ppc-dis.c and ppc-opc.c with a more recent
> version from the BFD library.  The one we have seems to be missing
> some power4 instructions, and also seems to have a 32-bit assumption
> here:
>
> > +		  } else if ((operand->flags & PPC_OPERAND_ABSOLUTE) != 0)
> >  		    print_address (value & 0xffffffff);
>
> I don't like this bit, though:
>
> > +      if (addr) {
> > +          char namebuf[128];
> > +	  const char *name;
> > +	  char *modname;
> > +	  long size, offset;
> > +
> > +          name = kallsyms_lookup(addr, &size, &offset, &modname, namebuf);
> > +          if (name) {
> > +              if(modname)
> > +		      fprintf(out, "\t# [%s]%s+0x%lx", modname, name, offset);
> > +	      else
> > +	              fprintf(out, "\t# %s+0x%lx", name, offset);
> > +	  }
> > +      }
>
> This should be put in the print_address function.  (With correct
> indentation. :)  If we minimize the changes we make to ppc_dis.c, it
> makes it easier to update it from the BFD version as we go along.
>
> And here it looks like you are sometimes using 8 spaces to indent, and
> sometimes a tab:
>
> > +void
> > +symbol_lookup(void)
> > +{
> > +        int type = inchar();
> > +        unsigned long addr;
> > +        static char tmp[64];
> > +
> > +        switch (type) {
> > +	case 'a':
> > +		if (scanhex(&addr)) {
>
> It would be good if you could use tabs everywhere.
>
> Regards,
> Paul.
>
-------------- next part --------------
===== arch/ppc64/xmon/xmon.c 1.34 vs edited =====
--- 1.34/arch/ppc64/xmon/xmon.c	Sat Feb 14 06:40:59 2004
+++ edited/arch/ppc64/xmon/xmon.c	Wed Feb 25 19:53:15 2004
@@ -50,6 +50,7 @@
 static unsigned long nidump = 16;
 static unsigned long ncsum = 4096;
 static int termch;
+static char tmpstr[128];
 
 static u_int bus_error_jmp[100];
 #define setjmp xmon_setjmp
@@ -115,6 +116,7 @@
 static void csum(void);
 static void bootcmds(void);
 void dump_segments(void);
+void symbol_lookup(void);
 
 static void debug_trace(void);
 
@@ -160,6 +162,8 @@
   dd	dump double values\n\
   e	print exception information\n\
   f	flush cache\n\
+  la	lookup symbol+offset of specified address\n\
+  ls	lookup address of specified symbol\n\
   m	examine/change memory\n\
   mm	move a block of memory\n\
   ms	set a block of memory\n\
@@ -537,6 +541,9 @@
 		case 'd':
 			dump();
 			break;
+		case 'l':
+			symbol_lookup();
+			break;
 		case 'r':
 			if (excp != NULL)
 				prregs(excp);	/* print regs */
@@ -1641,9 +1648,22 @@
 void
 print_address(unsigned long addr)
 {
-	printf("0x%lx", addr);
+	const char *name;
+	char *modname;
+	long size, offset;
+
+	name = kallsyms_lookup(addr, &size, &offset, &modname, tmpstr);
+
+	if (name) {
+		if (modname)
+			printf("0x%lx\t# [%s]%s+0x%lx", addr, modname, name, offset);
+		else
+			printf("0x%lx\t# %s+0x%lx", addr, name, offset);
+	} else
+		printf("0x%lx", addr);
 }
 
+
 /*
  * Memory operations - move, set, print differences
  */
@@ -1822,8 +1842,33 @@
 		return 0;
 	}
 
+	/* skip leading "0x" if any */
+
+	if (c == '0') {
+		c = inchar();
+		if (c == 'x')
+			c = inchar();
+	} else if (c == '$') {
+		int i;
+		for (i=0; i<63; i++) {
+			c = inchar();
+			if (isspace(c)) {
+				termch = c;
+				break;
+			}
+			tmpstr[i] = c;
+		}
+		tmpstr[i++] = 0;
+		*vp = kallsyms_lookupname(tmpstr);
+		if (!(*vp)) {
+			printf("unknown symbol '%s'\n", tmpstr);
+			return 0;
+		}
+		return 1;
+	}
+	
 	d = hexdigit(c);
-	if( d == EOF ){
+	if (d == EOF) {
 		termch = c;
 		return 0;
 	}
@@ -1832,7 +1877,7 @@
 		v = (v << 4) + d;
 		c = inchar();
 		d = hexdigit(c);
-	} while( d != EOF );
+	} while (d != EOF);
 	termch = c;
 	*vp = v;
 	return 1;
@@ -1907,19 +1952,53 @@
 	lineptr = str;
 }
 
+
+void
+symbol_lookup(void)
+{
+	int type = inchar();
+	unsigned long addr;
+	static char tmp[64];
+
+	switch (type) {
+	case 'a':
+		if (scanhex(&addr)) {
+			printf("%lx: ", addr);
+			xmon_print_symbol("%s\n", addr);
+		}
+		termch = 0;
+		break;
+	case 's':
+		getstring(tmp, 64);
+		if (setjmp(bus_error_jmp) == 0) {
+			__debugger_fault_handler = handle_fault;
+			sync();
+			addr = kallsyms_lookupname(tmp);
+			if (addr) 
+				printf("%s: %lx\n", tmp, addr);
+			else
+				printf("Symbol '%s' not found.\n", tmp);
+			sync();
+		}
+		__debugger_fault_handler = 0;
+		termch = 0;
+		break;
+	}
+}
+
+
 /* xmon version of __print_symbol */
 void __xmon_print_symbol(const char *fmt, unsigned long address)
 {
 	char *modname;
 	const char *name;
 	unsigned long offset, size;
-	char namebuf[128];
 
 	if (setjmp(bus_error_jmp) == 0) {
 		__debugger_fault_handler = handle_fault;
 		sync();
 		name = kallsyms_lookup(address, &size, &offset, &modname,
-				       namebuf);
+				       tmpstr);
 		sync();
 		/* wait a little while to see if we get a machine check */
 		__delay(200);


More information about the Linuxppc64-dev mailing list