LEFT | RIGHT |
1 // Copyright 2009 The Go Authors. All rights reserved. | 1 // Copyright 2009 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 #include "runtime.h" | 5 #include "runtime.h" |
6 #include "arch_GOARCH.h" | 6 #include "arch_GOARCH.h" |
7 #include "malloc.h" | 7 #include "malloc.h" |
8 #include "funcdata.h" | 8 #include "funcdata.h" |
9 | 9 |
10 void runtime·sigpanic(void); | 10 void runtime·sigpanic(void); |
11 | |
12 static String unknown = { (uint8*)"?", 1 }; | |
13 | 11 |
14 int32 | 12 int32 |
15 runtime·gentraceback(uintptr pc0, uintptr sp0, uintptr lr0, G *gp, int32 skip, u
intptr *pcbuf, int32 max, void (*callback)(Stkframe*, void*), void *v, bool prin
tall) | 13 runtime·gentraceback(uintptr pc0, uintptr sp0, uintptr lr0, G *gp, int32 skip, u
intptr *pcbuf, int32 max, void (*callback)(Stkframe*, void*), void *v, bool prin
tall) |
16 { | 14 { |
17 int32 i, n, nprint, line; | 15 int32 i, n, nprint, line; |
18 uintptr x, tracepc; | 16 uintptr x, tracepc; |
19 bool waspanic, printing; | 17 bool waspanic, printing; |
20 Func *f, *flr; | 18 Func *f, *flr; |
21 Stkframe frame; | 19 Stkframe frame; |
22 Stktop *stk; | 20 Stktop *stk; |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 frame.lr = x; | 186 frame.lr = x; |
189 } | 187 } |
190 } | 188 } |
191 ········ | 189 ········ |
192 if(pcbuf == nil && callback == nil) | 190 if(pcbuf == nil && callback == nil) |
193 n = nprint; | 191 n = nprint; |
194 | 192 |
195 return n;··············· | 193 return n;··············· |
196 } | 194 } |
197 | 195 |
198 static void | 196 void |
199 printcreatedby(G *gp) | 197 runtime·printcreatedby(G *gp) |
200 { | 198 { |
201 int32 line; | 199 int32 line; |
202 uintptr pc, tracepc; | 200 uintptr pc, tracepc; |
203 Func *f; | 201 Func *f; |
204 String file; | 202 String file; |
205 | 203 |
206 » if((pc = gp->gopc) != 0 && (f = runtime·findfunc(pc)) != nil | 204 » // Show what created goroutine, except main goroutine (goid 1). |
207 » » && runtime·showframe(f, gp) && gp->goid != 1) { | 205 » if((pc = gp->gopc) != 0 && (f = runtime·findfunc(pc)) != nil && |
| 206 » » runtime·showframe(f, gp) && gp->goid != 1) { |
208 runtime·printf("created by %s\n", runtime·funcname(f)); | 207 runtime·printf("created by %s\n", runtime·funcname(f)); |
209 tracepc = pc; // back up to CALL instruction for funcline. | 208 tracepc = pc; // back up to CALL instruction for funcline. |
210 if(pc > f->entry) | 209 if(pc > f->entry) |
211 » » » tracepc -= sizeof(uintptr); | 210 » » » tracepc -= PCQuantum; |
212 line = runtime·funcline(f, tracepc, &file); | 211 line = runtime·funcline(f, tracepc, &file); |
213 runtime·printf("\t%S:%d", file, line); | 212 runtime·printf("\t%S:%d", file, line); |
214 if(pc > f->entry) | 213 if(pc > f->entry) |
215 runtime·printf(" +%p", (uintptr)(pc - f->entry)); | 214 runtime·printf(" +%p", (uintptr)(pc - f->entry)); |
216 runtime·printf("\n"); | 215 runtime·printf("\n"); |
217 } | 216 } |
218 } | 217 } |
219 | 218 |
220 void | 219 void |
221 runtime·traceback(uintptr pc, uintptr sp, uintptr lr, G *gp) | 220 runtime·traceback(uintptr pc, uintptr sp, uintptr lr, G *gp) |
222 { | 221 { |
223 if(gp->status == Gsyscall) { | 222 if(gp->status == Gsyscall) { |
224 // Override signal registers if blocked in system call. | 223 // Override signal registers if blocked in system call. |
225 » » pc = gp->gcpc; | 224 » » pc = gp->syscallpc; |
226 » » sp = gp->gcsp; | 225 » » sp = gp->syscallsp; |
227 lr = 0; | 226 lr = 0; |
228 } | 227 } |
229 | 228 |
230 // Print traceback. By default, omits runtime frames. | 229 // Print traceback. By default, omits runtime frames. |
231 // If that means we print nothing at all, repeat forcing all frames prin
ted. | 230 // If that means we print nothing at all, repeat forcing all frames prin
ted. |
232 if(runtime·gentraceback(pc, sp, lr, gp, 0, nil, 100, nil, nil, false) ==
0) | 231 if(runtime·gentraceback(pc, sp, lr, gp, 0, nil, 100, nil, nil, false) ==
0) |
233 runtime·gentraceback(pc, sp, lr, gp, 0, nil, 100, nil, nil, true
); | 232 runtime·gentraceback(pc, sp, lr, gp, 0, nil, 100, nil, nil, true
); |
234 » printcreatedby(gp); | 233 » runtime·printcreatedby(gp); |
235 } | 234 } |
236 | 235 |
237 // func caller(n int) (pc uintptr, file string, line int, ok bool) | 236 // func caller(n int) (pc uintptr, file string, line int, ok bool) |
238 int32 | 237 int32 |
239 runtime·callers(int32 skip, uintptr *pcbuf, int32 m) | 238 runtime·callers(int32 skip, uintptr *pcbuf, int32 m) |
240 { | 239 { |
241 uintptr pc, sp; | 240 uintptr pc, sp; |
242 ········ | 241 ········ |
243 sp = runtime·getcallersp(&skip); | 242 sp = runtime·getcallersp(&skip); |
244 pc = (uintptr)runtime·getcallerpc(&skip); | 243 pc = (uintptr)runtime·getcallerpc(&skip); |
245 | 244 |
246 return runtime·gentraceback(pc, sp, 0, g, skip, pcbuf, m, nil, nil, fals
e); | 245 return runtime·gentraceback(pc, sp, 0, g, skip, pcbuf, m, nil, nil, fals
e); |
247 } | 246 } |
LEFT | RIGHT |