MINOR: debug: add a new "debug dev sym" command in expert mode
authorWilly Tarreau <w@1wt.eu>
Tue, 4 May 2021 16:40:50 +0000 (18:40 +0200)
committerWilly Tarreau <w@1wt.eu>
Wed, 5 May 2021 05:58:01 +0000 (07:58 +0200)
This command attempts to resolve a pointer to a symbol name. This is
convenient during development as it's easier to get such pointers live
than by issuing a debugger or calling addr2line.

(cherry picked from commit 48129be18afd17688bced0bba8c0d98e2b85ef39)
[wt: backported as sometimes useful when debugging in field;
     s/_HA_ATOMIC_INC/_HA_ATOMIC_ADD(,1)/]
Signed-off-by: Willy Tarreau <w@1wt.eu>

src/debug.c

index 36c822c..1a5f1ea 100644 (file)
@@ -474,6 +474,27 @@ static int debug_parse_cli_hex(char **args, char *payload, struct appctx *appctx
        return cli_msg(appctx, LOG_INFO, trash.area);
 }
 
+/* parse a "debug dev sym <addr>" command. It always returns 1. */
+static int debug_parse_cli_sym(char **args, char *payload, struct appctx *appctx, void *private)
+{
+       unsigned long addr;
+
+       if (!cli_has_level(appctx, ACCESS_LVL_ADMIN))
+               return 1;
+
+       if (!*args[3])
+               return cli_err(appctx, "Missing memory address to be resolved.\n");
+
+       _HA_ATOMIC_ADD(&debug_commands_issued, 1);
+
+       addr = strtoul(args[3], NULL, 0);
+       chunk_printf(&trash, "%#lx resolves to ", addr);
+       resolve_sym_name(&trash, NULL, (const void *)addr);
+       chunk_appendf(&trash, "\n");
+
+       return cli_msg(appctx, LOG_INFO, trash.area);
+}
+
 /* parse a "debug dev tkill" command. It always returns 1. */
 static int debug_parse_cli_tkill(char **args, char *payload, struct appctx *appctx, void *private)
 {
@@ -918,6 +939,7 @@ static struct cli_kw_list cli_kws = {{ },{
 #endif
        {{ "debug", "dev", "panic", NULL }, "debug dev panic             : immediately trigger a panic",     debug_parse_cli_panic, NULL, NULL, NULL, ACCESS_EXPERT },
        {{ "debug", "dev", "stream",NULL }, "debug dev stream ...        : show/manipulate stream flags",    debug_parse_cli_stream,NULL, NULL, NULL, ACCESS_EXPERT },
+       {{ "debug", "dev", "sym",   NULL }, "debug dev sym <addr>        : resolve symbol address",          debug_parse_cli_sym,   NULL, NULL, NULL, ACCESS_EXPERT },
        {{ "debug", "dev", "tkill", NULL }, "debug dev tkill [thr] [sig] : send signal to thread",           debug_parse_cli_tkill, NULL, NULL, NULL, ACCESS_EXPERT },
        {{ "debug", "dev", "write", NULL }, "debug dev write [size]      : write that many bytes",           debug_parse_cli_write, NULL, NULL, NULL, ACCESS_EXPERT },
        {{ "show", "threads", NULL, NULL }, "show threads   : show some threads debugging information",  NULL, cli_io_handler_show_threads, NULL },