Plan 9 from Bell Labs’s /usr/web/sources/contrib/uriel/changes/2005/1106/15

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


64-bit fixes.
 [rsc] --rw-rw-r-- M 451989 glenda sys 5885 Nov  6 11:07 sys/src/cmd/ktrace.c
	/n/sourcesdump/2005/1106/plan9/sys/src/cmd/ktrace.c:4,13 - 
	/n/sourcesdump/2005/1107/plan9/sys/src/cmd/ktrace.c:4,13
	  #include <mach.h>
	  #include <ctype.h>
	  
	- static	int	rtrace(ulong, ulong, ulong);
	- static	int	ctrace(ulong, ulong, ulong);
	- static	int	i386trace(ulong, ulong, ulong);
	- static	ulong	getval(ulong);
	+ static	int	rtrace(uvlong, uvlong, uvlong);
	+ static	int	ctrace(uvlong, uvlong, uvlong);
	+ static	int	i386trace(uvlong, uvlong, uvlong);
	+ static	uvlong	getval(uvlong);
	  static	void	inithdr(int);
	  static	void	fatal(char*, ...);
	  static	void	readstack(void);
	/n/sourcesdump/2005/1106/plan9/sys/src/cmd/ktrace.c:25,31 - 
	/n/sourcesdump/2005/1107/plan9/sys/src/cmd/ktrace.c:25,31
	  }
	  
	  static void
	- printaddr(char *addr, ulong pc)
	+ printaddr(char *addr, uvlong pc)
	  {
	  	int i;
	  	char *p;
	/n/sourcesdump/2005/1106/plan9/sys/src/cmd/ktrace.c:42,48 - 
	/n/sourcesdump/2005/1107/plan9/sys/src/cmd/ktrace.c:42,48
	  			if(!isxdigit(addr[i]))
	  				break;
	  		if(i == 8){
	- 			print("src(0x%.8lux); // 0x%s\n", pc, addr);
	+ 			print("src(0x%.8llux); // 0x%s\n", pc, addr);
	  			return;
	  		}
	  	}
	/n/sourcesdump/2005/1106/plan9/sys/src/cmd/ktrace.c:49,66 - 
	/n/sourcesdump/2005/1107/plan9/sys/src/cmd/ktrace.c:49,66
	  
	  	if(p=strchr(addr, '+')){
	  		*p++ = 0;
	- 		print("src(0x%.8lux); // %s+0x%s\n", pc, addr, p);
	+ 		print("src(0x%.8llux); // %s+0x%s\n", pc, addr, p);
	  	}else
	- 		print("src(0x%.8lux); // %s\n", pc, addr);
	+ 		print("src(0x%.8llux); // %s\n", pc, addr);
	  }
	  
	- static void (*fmt)(char*, ulong) = printaddr;
	+ static void (*fmt)(char*, uvlong) = printaddr;
	  
	  void
	  main(int argc, char *argv[])
	  {
	- 	int (*t)(ulong, ulong, ulong);
	- 	ulong pc, sp, link;
	+ 	int (*t)(uvlong, uvlong, uvlong);
	+ 	uvlong pc, sp, link;
	  	int fd;
	  
	  	ARGBEGIN{
	/n/sourcesdump/2005/1106/plan9/sys/src/cmd/ktrace.c:76,82 - 
	/n/sourcesdump/2005/1107/plan9/sys/src/cmd/ktrace.c:76,82
	  	switch(argc){
	  	case 4:
	  		t = rtrace;
	- 		link = strtoul(argv[3], 0, 16);
	+ 		link = strtoull(argv[3], 0, 16);
	  		break;
	  	case 3:
	  		break;
	/n/sourcesdump/2005/1106/plan9/sys/src/cmd/ktrace.c:83,90 - 
	/n/sourcesdump/2005/1107/plan9/sys/src/cmd/ktrace.c:83,90
	  	default:
	  		usage();
	  	}
	- 	pc = strtoul(argv[1], 0, 16);
	- 	sp = strtoul(argv[2], 0, 16);
	+ 	pc = strtoull(argv[1], 0, 16);
	+ 	sp = strtoull(argv[2], 0, 16);
	  	if(!interactive)
	  		readstack();
	  
	/n/sourcesdump/2005/1106/plan9/sys/src/cmd/ktrace.c:135,145 - 
	/n/sourcesdump/2005/1107/plan9/sys/src/cmd/ktrace.c:135,145
	  }
	  
	  static int
	- rtrace(ulong pc, ulong sp, ulong link)
	+ rtrace(uvlong pc, uvlong sp, uvlong link)
	  {
	  	Symbol s, f;
	  	char buf[128];
	- 	ulong oldpc;
	+ 	uvlong oldpc;
	  	int i;
	  
	  	i = 0;
	/n/sourcesdump/2005/1106/plan9/sys/src/cmd/ktrace.c:175,187 - 
	/n/sourcesdump/2005/1107/plan9/sys/src/cmd/ktrace.c:175,187
	  }
	  
	  static int
	- ctrace(ulong pc, ulong sp, ulong link)
	+ ctrace(uvlong pc, uvlong sp, uvlong link)
	  {
	  	Symbol s;
	  	char buf[128];
	  	int found;
	- 	ulong opc;
	- 	long moved, j;
	+ 	uvlong opc, moved;
	+ 	long j;
	  
	  	USED(link);
	  	j = 0;
	/n/sourcesdump/2005/1106/plan9/sys/src/cmd/ktrace.c:188,195 - 
	/n/sourcesdump/2005/1107/plan9/sys/src/cmd/ktrace.c:188,195
	  	opc = 0;
	  	while(pc && opc != pc) {
	  		moved = pc2sp(pc);
	- 		if (moved == -1){
	- 			print("pc2sp(%.8lux) = -1 %r\n", pc);
	+ 		if (moved == ~0){
	+ 			print("pc2sp(%.8llux) = -1 %r\n", pc);
	  			break;
	  		}
	  		found = findsym(pc, CTEXT, &s);
	/n/sourcesdump/2005/1106/plan9/sys/src/cmd/ktrace.c:213,222 - 
	/n/sourcesdump/2005/1107/plan9/sys/src/cmd/ktrace.c:213,222
	  }
	  
	  static int
	- i386trace(ulong pc, ulong sp, ulong link)
	+ i386trace(uvlong pc, uvlong sp, uvlong link)
	  {
	  	int i;
	- 	ulong osp;
	+ 	uvlong osp;
	  	Symbol s, f;
	  	char buf[128];
	  
	/n/sourcesdump/2005/1106/plan9/sys/src/cmd/ktrace.c:228,256 - 
	/n/sourcesdump/2005/1107/plan9/sys/src/cmd/ktrace.c:228,261
	  		symoff(buf, sizeof buf, pc, CANY);
	  		fmt(buf, pc);
	  
	+ //XXX		s.value &= ~(uintptr)0;
	  		if(pc != s.value) {	/* not at first instruction */
	  			if(findlocal(&s, FRAMENAME, &f) == 0)
	  				break;
	  			sp += f.value-mach->szaddr;
	  		}else if(strcmp(s.name, "forkret") == 0){
	- 			print("//passing interrupt frame; last pc found at sp=%lux\n", osp);
	+ //XXX
	+ 			print("//passing interrupt frame; last pc found at sp=%llux\n", osp);
	+ 
	  			sp +=  15 * mach->szaddr;		/* pop interrupt frame */
	  		}
	  
	  		pc = getval(sp);
	+ //XXX
	  		if(pc == 0 && strcmp(s.name, "forkret") == 0){
	  			sp += 3 * mach->szaddr;			/* pop iret eip, cs, eflags */
	- 			print("//guessing call through invalid pointer, try again at sp=%lux\n", sp);
	+ 			print("//guessing call through invalid pointer, try again at sp=%llux\n", sp);
	  			s.name = "";
	  			pc = getval(sp);
	  		}
	  		if(pc == 0) {
	- 			print("//didn't find pc at sp=%lux, last pc found at sp=%lux\n", sp, osp);
	+ 			print("//didn't find pc at sp=%llux, last pc found at sp=%llux\n", sp, osp);
	  			break;
	  		}
	  		osp = sp;
	  
	  		sp += mach->szaddr;
	+ //XXX
	  		if(strcmp(s.name, "forkret") == 0)
	  			sp += 2 * mach->szaddr;			/* pop iret cs, eflags */
	  
	/n/sourcesdump/2005/1106/plan9/sys/src/cmd/ktrace.c:261,271 - 
	/n/sourcesdump/2005/1107/plan9/sys/src/cmd/ktrace.c:266,276
	  }
	  
	  int naddr;
	- ulong addr[1024];
	- ulong val[1024];
	+ uvlong addr[1024];
	+ uvlong val[1024];
	  
	  static void
	- putval(ulong a, ulong v)
	+ putval(uvlong a, uvlong v)
	  {
	  	if(naddr < nelem(addr)){
	  		addr[naddr] = a;
	/n/sourcesdump/2005/1106/plan9/sys/src/cmd/ktrace.c:289,313 - 
	/n/sourcesdump/2005/1107/plan9/sys/src/cmd/ktrace.c:294,318
	  		for(i=0; i<nf; i++){
	  			if(p=strchr(f[i], '=')){
	  				*p++ = 0;
	- 				putval(strtoul(f[i], 0, 16), strtoul(p, 0, 16));
	+ 				putval(strtoull(f[i], 0, 16), strtoull(p, 0, 16));
	  			}
	  		}
	  	}
	  }
	  
	- static ulong
	- getval(ulong a)
	+ static uvlong
	+ getval(uvlong a)
	  {
	  	char buf[256];
	  	int i, n;
	  
	  	if(interactive){
	- 		print("// data at 0x%8.8lux? ", a);
	+ 		print("// data at 0x%8.8llux? ", a);
	  		n = read(0, buf, sizeof(buf)-1);
	  		if(n <= 0)
	  			return 0;
	  		buf[n] = '\0';
	- 		return strtoul(buf, 0, 16);
	+ 		return strtoull(buf, 0, 16);
	  	}else{
	  		for(i=0; i<naddr; i++)
	  			if(addr[i] == a)


Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to webmaster@9p.io.