Commit 0759d807 authored by Stephen Zhang's avatar Stephen Zhang Committed by Daniel Thompson

kdb: kdb_support: Fix debugging information problem

There are several common patterns.

0:
        kdb_printf("...",...);

which is the normal one.

1:
        kdb_printf("%s: "...,__func__,...)

We could improve '1' to this :

        #define kdb_func_printf(format, args...) \
                kdb_printf("%s: " format, __func__, ## args)

2:
        if(KDB_DEBUG(AR))
                kdb_printf("%s "...,__func__,...);

We could improve '2' to this :
        #define kdb_dbg_printf(mask, format, args...) \
                do { \
                        if (KDB_DEBUG(mask)) \
                                kdb_func_printf(format, ## args); \
                } while (0)

In addition, we changed the format code of size_t to %zu.
Signed-off-by: default avatarStephen Zhang <stephenzhangzsd@gmail.com>
Link: https://lore.kernel.org/r/1612440429-6391-1-git-send-email-stephenzhangzsd@gmail.comReviewed-by: default avatarDouglas Anderson <dianders@chromium.org>
[daniel.thompson@linaro.org: Minor typo and line length fixes in the
patch description]
Signed-off-by: default avatarDaniel Thompson <daniel.thompson@linaro.org>
parent cbd026e1
...@@ -254,4 +254,14 @@ extern char kdb_prompt_str[]; ...@@ -254,4 +254,14 @@ extern char kdb_prompt_str[];
#define KDB_WORD_SIZE ((int)sizeof(unsigned long)) #define KDB_WORD_SIZE ((int)sizeof(unsigned long))
#endif /* CONFIG_KGDB_KDB */ #endif /* CONFIG_KGDB_KDB */
#define kdb_func_printf(format, args...) \
kdb_printf("%s: " format, __func__, ## args)
#define kdb_dbg_printf(mask, format, args...) \
do { \
if (KDB_DEBUG(mask)) \
kdb_func_printf(format, ## args); \
} while (0)
#endif /* !_KDBPRIVATE_H */ #endif /* !_KDBPRIVATE_H */
...@@ -39,20 +39,15 @@ ...@@ -39,20 +39,15 @@
*/ */
int kdbgetsymval(const char *symname, kdb_symtab_t *symtab) int kdbgetsymval(const char *symname, kdb_symtab_t *symtab)
{ {
if (KDB_DEBUG(AR)) kdb_dbg_printf(AR, "symname=%s, symtab=%px\n", symname, symtab);
kdb_printf("kdbgetsymval: symname=%s, symtab=%px\n", symname,
symtab);
memset(symtab, 0, sizeof(*symtab)); memset(symtab, 0, sizeof(*symtab));
symtab->sym_start = kallsyms_lookup_name(symname); symtab->sym_start = kallsyms_lookup_name(symname);
if (symtab->sym_start) { if (symtab->sym_start) {
if (KDB_DEBUG(AR)) kdb_dbg_printf(AR, "returns 1, symtab->sym_start=0x%lx\n",
kdb_printf("kdbgetsymval: returns 1, "
"symtab->sym_start=0x%lx\n",
symtab->sym_start); symtab->sym_start);
return 1; return 1;
} }
if (KDB_DEBUG(AR)) kdb_dbg_printf(AR, "returns 0\n");
kdb_printf("kdbgetsymval: returns 0\n");
return 0; return 0;
} }
EXPORT_SYMBOL(kdbgetsymval); EXPORT_SYMBOL(kdbgetsymval);
...@@ -87,16 +82,14 @@ int kdbnearsym(unsigned long addr, kdb_symtab_t *symtab) ...@@ -87,16 +82,14 @@ int kdbnearsym(unsigned long addr, kdb_symtab_t *symtab)
#define knt1_size 128 /* must be >= kallsyms table size */ #define knt1_size 128 /* must be >= kallsyms table size */
char *knt1 = NULL; char *knt1 = NULL;
if (KDB_DEBUG(AR)) kdb_dbg_printf(AR, "addr=0x%lx, symtab=%px\n", addr, symtab);
kdb_printf("kdbnearsym: addr=0x%lx, symtab=%px\n", addr, symtab);
memset(symtab, 0, sizeof(*symtab)); memset(symtab, 0, sizeof(*symtab));
if (addr < 4096) if (addr < 4096)
goto out; goto out;
knt1 = debug_kmalloc(knt1_size, GFP_ATOMIC); knt1 = debug_kmalloc(knt1_size, GFP_ATOMIC);
if (!knt1) { if (!knt1) {
kdb_printf("kdbnearsym: addr=0x%lx cannot kmalloc knt1\n", kdb_func_printf("addr=0x%lx cannot kmalloc knt1\n", addr);
addr);
goto out; goto out;
} }
symtab->sym_name = kallsyms_lookup(addr, &symbolsize , &offset, symtab->sym_name = kallsyms_lookup(addr, &symbolsize , &offset,
...@@ -147,11 +140,8 @@ int kdbnearsym(unsigned long addr, kdb_symtab_t *symtab) ...@@ -147,11 +140,8 @@ int kdbnearsym(unsigned long addr, kdb_symtab_t *symtab)
if (symtab->mod_name == NULL) if (symtab->mod_name == NULL)
symtab->mod_name = "kernel"; symtab->mod_name = "kernel";
if (KDB_DEBUG(AR)) kdb_dbg_printf(AR, "returns %d symtab->sym_start=0x%lx, symtab->mod_name=%px, symtab->sym_name=%px (%s)\n",
kdb_printf("kdbnearsym: returns %d symtab->sym_start=0x%lx, " ret, symtab->sym_start, symtab->mod_name, symtab->sym_name, symtab->sym_name);
"symtab->mod_name=%px, symtab->sym_name=%px (%s)\n", ret,
symtab->sym_start, symtab->mod_name, symtab->sym_name,
symtab->sym_name);
out: out:
debug_kfree(knt1); debug_kfree(knt1);
...@@ -328,7 +318,7 @@ int kdb_getarea_size(void *res, unsigned long addr, size_t size) ...@@ -328,7 +318,7 @@ int kdb_getarea_size(void *res, unsigned long addr, size_t size)
int ret = copy_from_kernel_nofault((char *)res, (char *)addr, size); int ret = copy_from_kernel_nofault((char *)res, (char *)addr, size);
if (ret) { if (ret) {
if (!KDB_STATE(SUPPRESS)) { if (!KDB_STATE(SUPPRESS)) {
kdb_printf("kdb_getarea: Bad address 0x%lx\n", addr); kdb_func_printf("Bad address 0x%lx\n", addr);
KDB_STATE_SET(SUPPRESS); KDB_STATE_SET(SUPPRESS);
} }
ret = KDB_BADADDR; ret = KDB_BADADDR;
...@@ -353,7 +343,7 @@ int kdb_putarea_size(unsigned long addr, void *res, size_t size) ...@@ -353,7 +343,7 @@ int kdb_putarea_size(unsigned long addr, void *res, size_t size)
int ret = copy_from_kernel_nofault((char *)addr, (char *)res, size); int ret = copy_from_kernel_nofault((char *)addr, (char *)res, size);
if (ret) { if (ret) {
if (!KDB_STATE(SUPPRESS)) { if (!KDB_STATE(SUPPRESS)) {
kdb_printf("kdb_putarea: Bad address 0x%lx\n", addr); kdb_func_printf("Bad address 0x%lx\n", addr);
KDB_STATE_SET(SUPPRESS); KDB_STATE_SET(SUPPRESS);
} }
ret = KDB_BADADDR; ret = KDB_BADADDR;
...@@ -435,7 +425,7 @@ int kdb_getphysword(unsigned long *word, unsigned long addr, size_t size) ...@@ -435,7 +425,7 @@ int kdb_getphysword(unsigned long *word, unsigned long addr, size_t size)
fallthrough; fallthrough;
default: default:
diag = KDB_BADWIDTH; diag = KDB_BADWIDTH;
kdb_printf("kdb_getphysword: bad width %ld\n", (long) size); kdb_func_printf("bad width %zu\n", size);
} }
return diag; return diag;
} }
...@@ -484,7 +474,7 @@ int kdb_getword(unsigned long *word, unsigned long addr, size_t size) ...@@ -484,7 +474,7 @@ int kdb_getword(unsigned long *word, unsigned long addr, size_t size)
fallthrough; fallthrough;
default: default:
diag = KDB_BADWIDTH; diag = KDB_BADWIDTH;
kdb_printf("kdb_getword: bad width %ld\n", (long) size); kdb_func_printf("bad width %zu\n", size);
} }
return diag; return diag;
} }
...@@ -528,7 +518,7 @@ int kdb_putword(unsigned long addr, unsigned long word, size_t size) ...@@ -528,7 +518,7 @@ int kdb_putword(unsigned long addr, unsigned long word, size_t size)
fallthrough; fallthrough;
default: default:
diag = KDB_BADWIDTH; diag = KDB_BADWIDTH;
kdb_printf("kdb_putword: bad width %ld\n", (long) size); kdb_func_printf("bad width %zu\n", size);
} }
return diag; return diag;
} }
...@@ -602,8 +592,7 @@ unsigned long kdb_task_state_string(const char *s) ...@@ -602,8 +592,7 @@ unsigned long kdb_task_state_string(const char *s)
res = ~0UL; res = ~0UL;
break; break;
default: default:
kdb_printf("%s: unknown flag '%c' ignored\n", kdb_func_printf("unknown flag '%c' ignored\n", *s);
__func__, *s);
break; break;
} }
++s; ++s;
...@@ -884,18 +873,16 @@ void debug_kusage(void) ...@@ -884,18 +873,16 @@ void debug_kusage(void)
if (!debug_kusage_one_time) if (!debug_kusage_one_time)
goto out; goto out;
debug_kusage_one_time = 0; debug_kusage_one_time = 0;
kdb_printf("%s: debug_kmalloc memory leak dah_first %d\n", kdb_func_printf("debug_kmalloc memory leak dah_first %d\n", dah_first);
__func__, dah_first);
if (dah_first) { if (dah_first) {
h_used = (struct debug_alloc_header *)debug_alloc_pool; h_used = (struct debug_alloc_header *)debug_alloc_pool;
kdb_printf("%s: h_used %px size %d\n", __func__, h_used, kdb_func_printf("h_used %px size %d\n", h_used, h_used->size);
h_used->size);
} }
do { do {
h_used = (struct debug_alloc_header *) h_used = (struct debug_alloc_header *)
((char *)h_free + dah_overhead + h_free->size); ((char *)h_free + dah_overhead + h_free->size);
kdb_printf("%s: h_used %px size %d caller %px\n", kdb_func_printf("h_used %px size %d caller %px\n",
__func__, h_used, h_used->size, h_used->caller); h_used, h_used->size, h_used->caller);
h_free = (struct debug_alloc_header *) h_free = (struct debug_alloc_header *)
(debug_alloc_pool + h_free->next); (debug_alloc_pool + h_free->next);
} while (h_free->next); } while (h_free->next);
...@@ -903,8 +890,8 @@ void debug_kusage(void) ...@@ -903,8 +890,8 @@ void debug_kusage(void)
((char *)h_free + dah_overhead + h_free->size); ((char *)h_free + dah_overhead + h_free->size);
if ((char *)h_used - debug_alloc_pool != if ((char *)h_used - debug_alloc_pool !=
sizeof(debug_alloc_pool_aligned)) sizeof(debug_alloc_pool_aligned))
kdb_printf("%s: h_used %px size %d caller %px\n", kdb_func_printf("h_used %px size %d caller %px\n",
__func__, h_used, h_used->size, h_used->caller); h_used, h_used->size, h_used->caller);
out: out:
spin_unlock(&dap_lock); spin_unlock(&dap_lock);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment