14 #include <linux/types.h>
15 #include <linux/sched.h>
18 #include <linux/stddef.h>
20 #include <linux/ptrace.h>
21 #include <linux/module.h>
27 #include <linux/slab.h>
43 kdb_printf(
"kdbgetsymval: symname=%s, symtab=%p\n", symname,
45 memset(symtab, 0,
sizeof(*symtab));
50 "symtab->sym_start=0x%lx\n",
60 static char *kdb_name_table[100];
85 unsigned long symbolsize = 0;
91 kdb_printf(
"kdbnearsym: addr=0x%lx, symtab=%p\n", addr, symtab);
92 memset(symtab, 0,
sizeof(*symtab));
98 kdb_printf(
"kdbnearsym: addr=0x%lx cannot kmalloc knt1\n",
103 (
char **)(&symtab->
mod_name), knt1);
104 if (offset > 8*1024*1024) {
106 addr = offset = symbolsize = 0;
126 if (kdb_name_table[i] &&
127 strcmp(kdb_name_table[i], knt1) == 0)
132 memcpy(kdb_name_table, kdb_name_table+1,
133 sizeof(kdb_name_table[0]) *
137 knt1 = kdb_name_table[
i];
138 memcpy(kdb_name_table+i, kdb_name_table+i+1,
139 sizeof(kdb_name_table[0]) *
143 kdb_name_table[
i] = knt1;
151 kdb_printf(
"kdbnearsym: returns %d symtab->sym_start=0x%lx, "
152 "symtab->mod_name=%p, symtab->sym_name=%p (%s)\n", ret,
165 if (kdb_name_table[i]) {
167 kdb_name_table[
i] =
NULL;
189 int prefix_len =
strlen(prefix_name), prev_len = 0;
193 while ((name = kdb_walk_kallsyms(&pos))) {
194 if (
strncmp(name, prefix_name, prefix_len) == 0) {
198 prev_len =
min_t(
int, max_len-1,
200 memcpy(ks_namebuf_prev, ks_namebuf, prev_len);
201 ks_namebuf_prev[prev_len] =
'\0';
204 for (i = 0; i < prev_len; i++) {
205 if (ks_namebuf[i] != ks_namebuf_prev[i]) {
207 ks_namebuf_prev[
i] =
'\0';
213 if (prev_len > prefix_len)
214 memcpy(prefix_name, ks_namebuf_prev, prev_len+1);
230 int prefix_len =
strlen(prefix_name);
237 while ((name = kdb_walk_kallsyms(&pos))) {
238 if (
strncmp(name, prefix_name, prefix_len) == 0) {
268 if (!(symtab_p2->
sym_name || (punc & KDB_SP_VALUE)))
270 if (punc & KDB_SP_SPACEB)
272 if (punc & KDB_SP_VALUE)
275 if (punc & KDB_SP_VALUE)
277 if (punc & KDB_SP_PAREN)
284 if (punc & KDB_SP_SYMSIZE)
287 if (punc & KDB_SP_PAREN)
290 if (punc & KDB_SP_SPACEA)
292 if (punc & KDB_SP_NEWLINE)
331 kdb_printf(
"kdb_getarea: Bad address 0x%lx\n", addr);
356 kdb_printf(
"kdb_putarea: Bad address 0x%lx\n", addr);
377 static int kdb_getphys(
void *
res,
unsigned long addr,
size_t size)
414 diag = kdb_getphys(&w1, addr,
sizeof(w1));
419 diag = kdb_getphys(&w2, addr,
sizeof(w2));
424 diag = kdb_getphys(&w4, addr,
sizeof(w4));
429 if (size <=
sizeof(*word)) {
430 diag = kdb_getphys(&w8, addr,
sizeof(w8));
438 kdb_printf(
"kdb_getphysword: bad width %ld\n", (
long) size);
478 if (size <=
sizeof(*word)) {
487 kdb_printf(
"kdb_getword: bad width %ld\n", (
long) size);
523 if (size <=
sizeof(word)) {
531 kdb_printf(
"kdb_putword: bad width %ld\n", (
long) size);
556 #define UNRUNNABLE (1UL << (8*sizeof(unsigned long) - 1))
557 #define RUNNING (1UL << (8*sizeof(unsigned long) - 2))
558 #define IDLE (1UL << (8*sizeof(unsigned long) - 3))
559 #define DAEMON (1UL << (8*sizeof(unsigned long) - 4))
630 cpu = kdb_process_cpu(p);
631 state = (p->
state == 0) ?
'R' :
632 (p->
state < 0) ?
'U' :
639 if (is_idle_task(p)) {
642 if (!kdb_task_has_cpu(p) ||
kgdb_info[
cpu].irq_depth == 1) {
646 }
else if (!p->
mm && state ==
'S') {
680 KDB_SP_VALUE|KDB_SP_SYMSIZE|KDB_SP_NEWLINE);
706 #define dah_overhead ALIGN(sizeof(struct debug_alloc_header), dah_align)
708 static u64 debug_alloc_pool_aligned[256*1024/
dah_align];
709 static char *debug_alloc_pool = (
char *)debug_alloc_pool_aligned;
710 static u32 dah_first, dah_first_call = 1, dah_used, dah_used_max;
722 static int get_dap_lock(
void)
725 static int dap_locked = -1;
732 if (spin_trylock(&dap_lock)) {
747 unsigned int rem, h_offset;
750 if (!get_dap_lock()) {
755 if (dah_first_call) {
760 prev = best = bestprev =
NULL;
762 if (h->
size >= size && (!best || h->
size < best->
size)) {
781 h_offset = ((
char *)best - debug_alloc_pool) +
787 h_offset = best->
next;
788 best->
caller = __builtin_return_address(0);
789 dah_used += best->
size;
790 dah_used_max =
max(dah_used, dah_used_max);
792 bestprev->
next = h_offset;
794 dah_first = h_offset;
799 spin_unlock(&dap_lock);
806 unsigned int h_offset;
809 if ((
char *)p < debug_alloc_pool ||
810 (
char *)p >= debug_alloc_pool +
sizeof(debug_alloc_pool_aligned)) {
814 if (!get_dap_lock()) {
823 h_offset = (
char *)h - debug_alloc_pool;
824 if (h_offset < dah_first) {
826 dah_first = h_offset;
829 unsigned int prev_offset;
833 if (!prev->
next || prev->
next > h_offset)
836 (debug_alloc_pool + prev->
next);
838 prev_offset = (
char *)prev - debug_alloc_pool;
844 h_offset = prev_offset;
847 prev->
next = h_offset;
853 (debug_alloc_pool + h->
next);
859 spin_unlock(&dap_lock);
870 static int debug_kusage_one_time;
872 static int debug_kusage_one_time = 1;
874 if (!get_dap_lock()) {
879 if (dah_first == 0 &&
883 if (!debug_kusage_one_time)
885 debug_kusage_one_time = 0;
886 kdb_printf(
"%s: debug_kmalloc memory leak dah_first %d\n",
887 __func__, dah_first);
890 kdb_printf(
"%s: h_used %p size %d\n", __func__, h_used,
896 kdb_printf(
"%s: h_used %p size %d caller %p\n",
897 __func__, h_used, h_used->
size, h_used->
caller);
899 (debug_alloc_pool + h_free->
next);
900 }
while (h_free->
next);
903 if ((
char *)h_used - debug_alloc_pool !=
904 sizeof(debug_alloc_pool_aligned))
905 kdb_printf(
"%s: h_used %p size %d caller %p\n",
906 __func__, h_used, h_used->
size, h_used->
caller);
908 spin_unlock(&dap_lock);
915 static int kdb_flags_stack[4], kdb_flags_index;
920 kdb_flags_stack[kdb_flags_index++] =
kdb_flags;
925 BUG_ON(kdb_flags_index <= 0);
926 kdb_flags = kdb_flags_stack[--kdb_flags_index];