Warning: Attempt to read property "date" on null in /usr/local/www/websvn.planix.org/blame.php on line 247

Warning: Attempt to read property "msg" on null in /usr/local/www/websvn.planix.org/blame.php on line 247
WebSVN – planix.SVN – Blame – /os/branches/planix-v0/sys/src/cmd/ki/symbols.c – Rev 2

Subversion Repositories planix.SVN

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 - 1
#include <u.h>
2
#include <libc.h>
3
#include <bio.h>
4
#include <mach.h>
5
#define Extern extern
6
#include "sparc.h"
7
 
8
#define	STRINGSZ	128
9
 
10
/*
11
 *	print the value of dot as file:line
12
 */
13
void
14
printsource(long dot)
15
{
16
	char str[STRINGSZ];
17
 
18
	if (fileline(str, STRINGSZ, dot))
19
		Bprint(bioout, "%s", str);
20
}
21
 
22
void
23
printlocals(Symbol *fn, ulong fp)
24
{
25
	int i;
26
	Symbol s;
27
 
28
	s = *fn;
29
	for (i = 0; localsym(&s, i); i++) {
30
		if (s.class != CAUTO)
31
			continue;
32
		Bprint(bioout, "\t%s=#%lux\n", s.name, getmem_4(fp-s.value));
33
	}
34
}
35
 
36
void
37
printparams(Symbol *fn, ulong fp)
38
{
39
	int i;
40
	Symbol s;
41
	int first;
42
 
43
	fp += mach->szreg;			/* skip saved pc */
44
	s = *fn;
45
	for (first = i = 0; localsym(&s, i); i++) {
46
		if (s.class != CPARAM)
47
			continue;
48
		if (first++)
49
			Bprint(bioout, ", ");
50
		Bprint(bioout, "%s=#%lux", s.name, getmem_4(fp+s.value));
51
	}
52
	Bprint(bioout, ") ");
53
}
54
 
55
#define STARTSYM	"_main"
56
#define	FRAMENAME	".frame"
57
 
58
void
59
stktrace(int modif)
60
{
61
	ulong pc, sp;
62
	Symbol s, f;
63
	int i;
64
	char buf[512];
65
 
66
	pc = reg.pc;
67
	sp = reg.r[1];
68
	i = 0;
69
	while (findsym(pc, CTEXT, &s)) {
70
		if(strcmp(STARTSYM, s.name) == 0) {
71
			Bprint(bioout, "%s() at #%llux\n", s.name, s.value);
72
			break;
73
		}
74
		if (pc == s.value)	/* at first instruction */
75
			f.value = 0;
76
		else if (findlocal(&s, FRAMENAME, &f) == 0)
77
			break;
78
		if (s.type == 'L' || s.type == 'l' || pc <= s.value+4)
79
			pc = reg.r[15];
80
		else pc = getmem_4(sp);
81
		sp += f.value;
82
		Bprint(bioout, "%s(", s.name);
83
		printparams(&s, sp);
84
		printsource(s.value);
85
		Bprint(bioout, " called from ");
86
		symoff(buf, sizeof(buf), pc-8, CTEXT);
87
		Bprint(bioout, buf);
88
		printsource(pc-8);
89
		Bprint(bioout, "\n");
90
		if(modif == 'C')
91
			printlocals(&s, sp);
92
		if(++i > 40){
93
			Bprint(bioout, "(trace truncated)\n");
94
			break;
95
		}
96
	}
97
}