Fri Jan 18 07:34:40 2013 UTC ()
Print the frame pointer for each level and don't print the registers
within the frame by default. Provide a '/f' flag to get the full trace.

Discussed with matt@


(skrll)
diff -r1.27 -r1.28 src/sys/arch/arm/arm/db_trace.c

cvs diff -r1.27 -r1.28 src/sys/arch/arm/arm/db_trace.c (expand / switch to unified diff)

--- src/sys/arch/arm/arm/db_trace.c 2012/12/31 08:57:27 1.27
+++ src/sys/arch/arm/arm/db_trace.c 2013/01/18 07:34:39 1.28
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: db_trace.c,v 1.27 2012/12/31 08:57:27 skrll Exp $ */ 1/* $NetBSD: db_trace.c,v 1.28 2013/01/18 07:34:39 skrll Exp $ */
2 2
3/*  3/*
4 * Copyright (c) 2000, 2001 Ben Harris 4 * Copyright (c) 2000, 2001 Ben Harris
5 * Copyright (c) 1996 Scott K. Stevens 5 * Copyright (c) 1996 Scott K. Stevens
6 * 6 *
7 * Mach Operating System 7 * Mach Operating System
8 * Copyright (c) 1991,1990 Carnegie Mellon University 8 * Copyright (c) 1991,1990 Carnegie Mellon University
9 * All Rights Reserved. 9 * All Rights Reserved.
10 *  10 *
11 * Permission to use, copy, modify and distribute this software and its 11 * Permission to use, copy, modify and distribute this software and its
12 * documentation is hereby granted, provided that both the copyright 12 * documentation is hereby granted, provided that both the copyright
13 * notice and this permission notice appear in all copies of the 13 * notice and this permission notice appear in all copies of the
14 * software, derivative works or modified versions, and any portions 14 * software, derivative works or modified versions, and any portions
@@ -21,27 +21,27 @@ @@ -21,27 +21,27 @@
21 * Carnegie Mellon requests users of this software to return to 21 * Carnegie Mellon requests users of this software to return to
22 *  22 *
23 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU 23 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
24 * School of Computer Science 24 * School of Computer Science
25 * Carnegie Mellon University 25 * Carnegie Mellon University
26 * Pittsburgh PA 15213-3890 26 * Pittsburgh PA 15213-3890
27 *  27 *
28 * any improvements or extensions that they make and grant Carnegie the 28 * any improvements or extensions that they make and grant Carnegie the
29 * rights to redistribute these changes. 29 * rights to redistribute these changes.
30 */ 30 */
31 31
32#include <sys/param.h> 32#include <sys/param.h>
33 33
34__KERNEL_RCSID(0, "$NetBSD: db_trace.c,v 1.27 2012/12/31 08:57:27 skrll Exp $"); 34__KERNEL_RCSID(0, "$NetBSD: db_trace.c,v 1.28 2013/01/18 07:34:39 skrll Exp $");
35 35
36#include <sys/proc.h> 36#include <sys/proc.h>
37#include <arm/armreg.h> 37#include <arm/armreg.h>
38#include <arm/cpufunc.h> 38#include <arm/cpufunc.h>
39#include <arm/pcb.h> 39#include <arm/pcb.h>
40#include <machine/db_machdep.h> 40#include <machine/db_machdep.h>
41#include <machine/vmparam.h> 41#include <machine/vmparam.h>
42 42
43#include <ddb/db_access.h> 43#include <ddb/db_access.h>
44#include <ddb/db_interface.h> 44#include <ddb/db_interface.h>
45#include <ddb/db_sym.h> 45#include <ddb/db_sym.h>
46#include <ddb/db_proc.h> 46#include <ddb/db_proc.h>
47#include <ddb/db_output.h> 47#include <ddb/db_output.h>
@@ -81,39 +81,42 @@ __KERNEL_RCSID(0, "$NetBSD: db_trace.c,v @@ -81,39 +81,42 @@ __KERNEL_RCSID(0, "$NetBSD: db_trace.c,v
81#define FR_RSP (-2) 81#define FR_RSP (-2)
82#define FR_RFP (-3) 82#define FR_RFP (-3)
83 83
84void 84void
85db_stack_trace_print(db_expr_t addr, bool have_addr, 85db_stack_trace_print(db_expr_t addr, bool have_addr,
86 db_expr_t count, const char *modif, 86 db_expr_t count, const char *modif,
87 void (*pr)(const char *, ...)) 87 void (*pr)(const char *, ...))
88{ 88{
89 uint32_t *frame, *lastframe; 89 uint32_t *frame, *lastframe;
90 const char *cp = modif; 90 const char *cp = modif;
91 char c; 91 char c;
92 bool kernel_only = true; 92 bool kernel_only = true;
93 bool trace_thread = false; 93 bool trace_thread = false;
 94 bool trace_full = false;
94 bool lwpaddr = false; 95 bool lwpaddr = false;
95 db_addr_t scp, pc; 96 db_addr_t scp, pc;
96 int scp_offset; 97 int scp_offset;
97 98
98 while ((c = *cp++) != 0) { 99 while ((c = *cp++) != 0) {
99 if (c == 'a') { 100 if (c == 'a') {
100 lwpaddr = true; 101 lwpaddr = true;
101 trace_thread = true; 102 trace_thread = true;
102 } 103 }
103 if (c == 'u') 104 if (c == 'u')
104 kernel_only = false; 105 kernel_only = false;
105 if (c == 't') 106 if (c == 't')
106 trace_thread = true; 107 trace_thread = true;
 108 if (c == 'f')
 109 trace_full = true;
107 } 110 }
108 111
109 if (!have_addr) 112 if (!have_addr)
110 frame = (uint32_t *)(DDB_REGS->tf_r11); 113 frame = (uint32_t *)(DDB_REGS->tf_r11);
111 else { 114 else {
112 if (trace_thread) { 115 if (trace_thread) {
113 struct pcb *pcb; 116 struct pcb *pcb;
114 proc_t p; 117 proc_t p;
115 lwp_t l; 118 lwp_t l;
116 119
117 if (lwpaddr) { 120 if (lwpaddr) {
118 db_read_bytes(addr, sizeof(l), 121 db_read_bytes(addr, sizeof(l),
119 (char *)&l); 122 (char *)&l);
@@ -165,72 +168,76 @@ db_stack_trace_print(db_expr_t addr, boo @@ -165,72 +168,76 @@ db_stack_trace_print(db_expr_t addr, boo
165 168
166 while (count-- && frame != NULL) { 169 while (count-- && frame != NULL) {
167 uint32_t savecode; 170 uint32_t savecode;
168 int r; 171 int r;
169 uint32_t *rp; 172 uint32_t *rp;
170 const char *sep; 173 const char *sep;
171 174
172#ifdef __PROG26 175#ifdef __PROG26
173 scp = frame[FR_SCP] & R15_PC; 176 scp = frame[FR_SCP] & R15_PC;
174#else 177#else
175 scp = frame[FR_SCP]; 178 scp = frame[FR_SCP];
176#endif 179#endif
177 lastframe = frame; 180 lastframe = frame;
 181 (*pr)("%p: ", frame);
178#ifndef _KERNEL 182#ifndef _KERNEL
179 uint32_t frameb[4]; 183 uint32_t frameb[4];
180 db_read_bytes((db_addr_t)(frame - 3), sizeof(frameb), 184 db_read_bytes((db_addr_t)(frame - 3), sizeof(frameb),
181 (char *)frameb); 185 (char *)frameb);
182 frame = frameb + 3; 186 frame = frameb + 3;
183#endif 187#endif
184 
185 db_printsym(pc, DB_STGY_PROC, pr); 188 db_printsym(pc, DB_STGY_PROC, pr);
186 (*pr)("\n\t"); 189 if (trace_full) {
 190 (*pr)("\n\t");
187#ifdef __PROG26 191#ifdef __PROG26
188 (*pr)("pc =0x%08x rlv=0x%08x (", pc, frame[FR_RLV] & R15_PC); 192 (*pr)("pc =0x%08x rlv=0x%08x (", pc,
189 db_printsym(frame[FR_RLV] & R15_PC, DB_STGY_PROC, pr); 193 frame[FR_RLV] & R15_PC);
190 (*pr)(")\n"); 194 db_printsym(frame[FR_RLV] & R15_PC, DB_STGY_PROC, pr);
 195 (*pr)(")\n");
191#else 196#else
192 (*pr)("pc =0x%08x rlv=0x%08x (", pc, frame[FR_RLV]); 197 (*pr)("pc =0x%08x rlv=0x%08x (", pc, frame[FR_RLV]);
193 db_printsym(frame[FR_RLV], DB_STGY_PROC, pr); 198 db_printsym(frame[FR_RLV], DB_STGY_PROC, pr);
194 (*pr)(")\n"); 199 (*pr)(")\n");
195#endif 200#endif
196 (*pr)("\trsp=0x%08x rfp=0x%08x", frame[FR_RSP], frame[FR_RFP]); 201 (*pr)("\trsp=0x%08x rfp=0x%08x", frame[FR_RSP],
 202 frame[FR_RFP]);
 203 }
197 204
198#ifndef _KERNEL 205#ifndef _KERNEL
199 db_read_bytes((db_addr_t)((uint32_t *)scp + scp_offset), 206 db_read_bytes((db_addr_t)((uint32_t *)scp + scp_offset),
200 sizeof(savecode), (void *)&savecode); 207 sizeof(savecode), (void *)&savecode);
201#else 208#else
202 if ((scp & 3) == 0) { 209 if ((scp & 3) == 0) {
203 savecode = ((uint32_t *)scp)[scp_offset]; 210 savecode = ((uint32_t *)scp)[scp_offset];
204 } else { 211 } else {
205 savecode = 0; 212 savecode = 0;
206 } 213 }
207#endif 214#endif
208 if ((savecode & 0x0e100000) == 0x08000000) { 215 if (trace_full &&
 216 (savecode & 0x0e100000) == 0x08000000) {
209 /* Looks like an STM */ 217 /* Looks like an STM */
210 rp = frame - 4; 218 rp = frame - 4;
211 sep = "\n\t"; 219 sep = "\n\t";
212 for (r = 10; r >= 0; r--) { 220 for (r = 10; r >= 0; r--) {
213 if (savecode & (1 << r)) { 221 if (savecode & (1 << r)) {
214 (*pr)("%sr%d=0x%08x", 222 (*pr)("%sr%d=0x%08x",
215 sep, r, *rp--); 223 sep, r, *rp--);
216 sep = (frame - rp) % 4 == 2 ? 224 sep = (frame - rp) % 4 == 2 ?
217 "\n\t" : " "; 225 "\n\t" : " ";
218 } 226 }
219 } 227 }
220 } 228 }
221 229
222 (*pr)("\n"); 230 (*pr)("\n");
223 
224 /* 231 /*
225 * Switch to next frame up 232 * Switch to next frame up
226 */ 233 */
227 if (frame[FR_RFP] == 0) 234 if (frame[FR_RFP] == 0)
228 break; /* Top of stack */ 235 break; /* Top of stack */
229#ifdef __PROG26 236#ifdef __PROG26
230 pc = frame[FR_RLV] & R15_PC; 237 pc = frame[FR_RLV] & R15_PC;
231#else 238#else
232 pc = frame[FR_RLV]; 239 pc = frame[FR_RLV];
233#endif 240#endif
234  241
235 frame = (uint32_t *)(frame[FR_RFP]); 242 frame = (uint32_t *)(frame[FR_RFP]);
236 243