1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
|
// 386 support
defn acidinit() // Called after all the init modules are loaded
{
bplist = {};
bpfmt = 'b';
srcpath = {
"./",
"/sys/src/libc/port/",
"/sys/src/libc/9sys/",
"/sys/src/libc/386/"
};
srcfiles = {}; // list of loaded files
srctext = {}; // the text of the files
}
defn linkreg(addr)
{
return {};
}
defn stk() // trace
{
_stk({"PC", *PC, "SP", *SP}, 0);
}
defn lstk() // trace with locals
{
_stk({"PC", *PC, "SP", *SP}, 1);
}
defn gpr() // print general(hah hah!) purpose registers
{
print("AX\t", *AX, " BX\t", *BX, " CX\t", *CX, " DX\t", *DX, "\n");
print("DI\t", *DI, " SI\t", *SI, " BP\t", *BP, "\n");
}
defn spr() // print special processor registers
{
local pc;
local cause;
pc = *PC;
print("PC\t", pc, " ", fmt(pc, 'a'), " ");
pfl(pc);
print("SP\t", *SP, " ECODE ", *ECODE, " EFLAG ", *EFLAGS, "\n");
print("CS\t", *CS, " DS\t ", *DS, " SS\t", *SS, "\n");
print("GS\t", *GS, " FS\t ", *FS, " ES\t", *ES, "\n");
cause = *TRAP;
print("TRAP\t", cause, " ", reason(cause), "\n");
}
defn regs() // print all registers
{
spr();
gpr();
}
defn mmregs()
{
print("MM0\t", *MM0, " MM1\t", *MM1, "\n");
print("MM2\t", *MM2, " MM3\t", *MM3, "\n");
print("MM4\t", *MM4, " MM5\t", *MM5, "\n");
print("MM6\t", *MM6, " MM7\t", *MM7, "\n");
}
defn pfixstop(pid)
{
if *fmt(*PC-1, 'b') == 0xCC then {
// Linux stops us after the breakpoint, not at it
*PC = *PC-1;
}
}
defn pstop(pid)
{
local l;
local pc;
local why;
pc = *PC;
// FIgure out why we stopped.
if *fmt(pc, 'b') == 0xCC then {
why = "breakpoint";
// fix up instruction for print; will put back later
*pc = @pc;
} else if *(pc-2\x) == 0x80CD then {
pc = pc-2;
why = "system call";
} else
why = "stopped";
if printstopped then {
print(pid,": ", why, "\t");
print(fmt(pc, 'a'), "\t", *fmt(pc, 'i'), "\n");
}
if why == "breakpoint" then
*fmt(pc, bpfmt) = bpinst;
if printstopped && notes then {
if notes[0] != "sys: breakpoint" then {
print("Notes pending:\n");
l = notes;
while l do {
print("\t", head l, "\n");
l = tail l;
}
}
}
}
aggr Ureg
{
'U' 0 di;
'U' 4 si;
'U' 8 bp;
'U' 12 nsp;
'U' 16 bx;
'U' 20 dx;
'U' 24 cx;
'U' 28 ax;
'U' 32 gs;
'U' 36 fs;
'U' 40 es;
'U' 44 ds;
'U' 48 trap;
'U' 52 ecode;
'U' 56 pc;
'U' 60 cs;
'U' 64 flags;
{
'U' 68 usp;
'U' 68 sp;
};
'U' 72 ss;
};
defn
Ureg(addr) {
complex Ureg addr;
print(" di ", addr.di, "\n");
print(" si ", addr.si, "\n");
print(" bp ", addr.bp, "\n");
print(" nsp ", addr.nsp, "\n");
print(" bx ", addr.bx, "\n");
print(" dx ", addr.dx, "\n");
print(" cx ", addr.cx, "\n");
print(" ax ", addr.ax, "\n");
print(" gs ", addr.gs, "\n");
print(" fs ", addr.fs, "\n");
print(" es ", addr.es, "\n");
print(" ds ", addr.ds, "\n");
print(" trap ", addr.trap, "\n");
print(" ecode ", addr.ecode, "\n");
print(" pc ", addr.pc, "\n");
print(" cs ", addr.cs, "\n");
print(" flags ", addr.flags, "\n");
print(" sp ", addr.sp, "\n");
print(" ss ", addr.ss, "\n");
};
sizeofUreg = 76;
aggr Linkdebug
{
'X' 0 version;
'X' 4 map;
};
aggr Linkmap
{
'X' 0 addr;
'X' 4 name;
'X' 8 dynsect;
'X' 12 next;
'X' 16 prev;
};
defn
linkdebug()
{
local a;
if !havesymbol("_DYNAMIC") then
return 0;
a = _DYNAMIC;
while *a != 0 do {
if *a == 21 then // 21 == DT_DEBUG
return *(a+4);
a = a+8;
}
return 0;
}
defn
dynamicmap()
{
if systype == "linux" || systype == "freebsd" then {
local r, m, n;
r = linkdebug();
if r then {
complex Linkdebug r;
m = r.map;
n = 0;
while m != 0 && n < 100 do {
complex Linkmap m;
if m.name && *(m.name\b) && access(*(m.name\s)) then
print("textfile({\"", *(m.name\s), "\", ", m.addr\X, "});\n");
m = m.next;
n = n+1;
}
}
}
}
defn
acidmap()
{
// dynamicmap();
acidtypes();
}
print(acidfile);
|