hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/kernel/debug/kdb/kdb_bt.c
....@@ -21,22 +21,18 @@
2121
2222 static void kdb_show_stack(struct task_struct *p, void *addr)
2323 {
24
- int old_lvl = console_loglevel;
25
- console_loglevel = CONSOLE_LOGLEVEL_MOTORMOUTH;
2624 kdb_trap_printk++;
27
- kdb_set_current_task(p);
28
- if (addr) {
29
- show_stack((struct task_struct *)p, addr);
30
- } else if (kdb_current_regs) {
31
-#ifdef CONFIG_X86
32
- show_stack(p, &kdb_current_regs->sp);
33
-#else
34
- show_stack(p, NULL);
35
-#endif
25
+
26
+ if (!addr && kdb_task_has_cpu(p)) {
27
+ int old_lvl = console_loglevel;
28
+
29
+ console_loglevel = CONSOLE_LOGLEVEL_MOTORMOUTH;
30
+ kdb_dump_stack_on_cpu(kdb_process_cpu(p));
31
+ console_loglevel = old_lvl;
3632 } else {
37
- show_stack(p, NULL);
33
+ show_stack(p, addr, KERN_EMERG);
3834 }
39
- console_loglevel = old_lvl;
35
+
4036 kdb_trap_printk--;
4137 }
4238
....@@ -78,12 +74,12 @@
7874 */
7975
8076 static int
81
-kdb_bt1(struct task_struct *p, unsigned long mask,
82
- int argcount, int btaprompt)
77
+kdb_bt1(struct task_struct *p, unsigned long mask, bool btaprompt)
8378 {
84
- char buffer[2];
85
- if (kdb_getarea(buffer[0], (unsigned long)p) ||
86
- kdb_getarea(buffer[0], (unsigned long)(p+1)-1))
79
+ char ch;
80
+
81
+ if (kdb_getarea(ch, (unsigned long)p) ||
82
+ kdb_getarea(ch, (unsigned long)(p+1)-1))
8783 return KDB_BADADDR;
8884 if (!kdb_task_state(p, mask))
8985 return 0;
....@@ -91,22 +87,46 @@
9187 kdb_ps1(p);
9288 kdb_show_stack(p, NULL);
9389 if (btaprompt) {
94
- kdb_getstr(buffer, sizeof(buffer),
95
- "Enter <q> to end, <cr> to continue:");
96
- if (buffer[0] == 'q') {
97
- kdb_printf("\n");
90
+ kdb_printf("Enter <q> to end, <cr> or <space> to continue:");
91
+ do {
92
+ ch = kdb_getchar();
93
+ } while (!strchr("\r\n q", ch));
94
+ kdb_printf("\n");
95
+
96
+ /* reset the pager */
97
+ kdb_nextline = 1;
98
+
99
+ if (ch == 'q')
98100 return 1;
99
- }
100101 }
101102 touch_nmi_watchdog();
102103 return 0;
104
+}
105
+
106
+static void
107
+kdb_bt_cpu(unsigned long cpu)
108
+{
109
+ struct task_struct *kdb_tsk;
110
+
111
+ if (cpu >= num_possible_cpus() || !cpu_online(cpu)) {
112
+ kdb_printf("WARNING: no process for cpu %ld\n", cpu);
113
+ return;
114
+ }
115
+
116
+ /* If a CPU failed to round up we could be here */
117
+ kdb_tsk = KDB_TSK(cpu);
118
+ if (!kdb_tsk) {
119
+ kdb_printf("WARNING: no task for cpu %ld\n", cpu);
120
+ return;
121
+ }
122
+
123
+ kdb_bt1(kdb_tsk, ~0UL, false);
103124 }
104125
105126 int
106127 kdb_bt(int argc, const char **argv)
107128 {
108129 int diag;
109
- int argcount = 5;
110130 int btaprompt = 1;
111131 int nextarg;
112132 unsigned long addr;
....@@ -125,18 +145,18 @@
125145 /* Run the active tasks first */
126146 for_each_online_cpu(cpu) {
127147 p = kdb_curr_task(cpu);
128
- if (kdb_bt1(p, mask, argcount, btaprompt))
148
+ if (kdb_bt1(p, mask, btaprompt))
129149 return 0;
130150 }
131151 /* Now the inactive tasks */
132
- kdb_do_each_thread(g, p) {
152
+ for_each_process_thread(g, p) {
133153 if (KDB_FLAG(CMD_INTERRUPT))
134154 return 0;
135155 if (task_curr(p))
136156 continue;
137
- if (kdb_bt1(p, mask, argcount, btaprompt))
157
+ if (kdb_bt1(p, mask, btaprompt))
138158 return 0;
139
- } kdb_while_each_thread(g, p);
159
+ }
140160 } else if (strcmp(argv[0], "btp") == 0) {
141161 struct task_struct *p;
142162 unsigned long pid;
....@@ -146,10 +166,8 @@
146166 if (diag)
147167 return diag;
148168 p = find_task_by_pid_ns(pid, &init_pid_ns);
149
- if (p) {
150
- kdb_set_current_task(p);
151
- return kdb_bt1(p, ~0UL, argcount, 0);
152
- }
169
+ if (p)
170
+ return kdb_bt1(p, ~0UL, false);
153171 kdb_printf("No process with pid == %ld found\n", pid);
154172 return 0;
155173 } else if (strcmp(argv[0], "btt") == 0) {
....@@ -158,12 +176,9 @@
158176 diag = kdbgetularg((char *)argv[1], &addr);
159177 if (diag)
160178 return diag;
161
- kdb_set_current_task((struct task_struct *)addr);
162
- return kdb_bt1((struct task_struct *)addr, ~0UL, argcount, 0);
179
+ return kdb_bt1((struct task_struct *)addr, ~0UL, false);
163180 } else if (strcmp(argv[0], "btc") == 0) {
164181 unsigned long cpu = ~0;
165
- struct task_struct *save_current_task = kdb_current_task;
166
- char buf[80];
167182 if (argc > 1)
168183 return KDB_ARGCOUNT;
169184 if (argc == 1) {
....@@ -171,35 +186,21 @@
171186 if (diag)
172187 return diag;
173188 }
174
- /* Recursive use of kdb_parse, do not use argv after
175
- * this point */
176
- argv = NULL;
177189 if (cpu != ~0) {
178
- if (cpu >= num_possible_cpus() || !cpu_online(cpu)) {
179
- kdb_printf("no process for cpu %ld\n", cpu);
180
- return 0;
190
+ kdb_bt_cpu(cpu);
191
+ } else {
192
+ /*
193
+ * Recursive use of kdb_parse, do not use argv after
194
+ * this point.
195
+ */
196
+ argv = NULL;
197
+ kdb_printf("btc: cpu status: ");
198
+ kdb_parse("cpu\n");
199
+ for_each_online_cpu(cpu) {
200
+ kdb_bt_cpu(cpu);
201
+ touch_nmi_watchdog();
181202 }
182
- sprintf(buf, "btt 0x%px\n", KDB_TSK(cpu));
183
- kdb_parse(buf);
184
- return 0;
185203 }
186
- kdb_printf("btc: cpu status: ");
187
- kdb_parse("cpu\n");
188
- for_each_online_cpu(cpu) {
189
- void *kdb_tsk = KDB_TSK(cpu);
190
-
191
- /* If a CPU failed to round up we could be here */
192
- if (!kdb_tsk) {
193
- kdb_printf("WARNING: no task for cpu %ld\n",
194
- cpu);
195
- continue;
196
- }
197
-
198
- sprintf(buf, "btt 0x%px\n", kdb_tsk);
199
- kdb_parse(buf);
200
- touch_nmi_watchdog();
201
- }
202
- kdb_set_current_task(save_current_task);
203204 return 0;
204205 } else {
205206 if (argc) {
....@@ -211,7 +212,7 @@
211212 kdb_show_stack(kdb_current_task, (void *)addr);
212213 return 0;
213214 } else {
214
- return kdb_bt1(kdb_current_task, ~0UL, argcount, 0);
215
+ return kdb_bt1(kdb_current_task, ~0UL, false);
215216 }
216217 }
217218