]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
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:47:29 +0000 (07:47 +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.

src/debug.c

index 53f98ced768d7c6980b71c0fe300af43101903ce..f53f1fa3f638ecd6aabad2abfef19029de9e3804 100644 (file)
@@ -528,6 +528,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_INC(&debug_commands_issued);
+
+       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)
 {
@@ -1176,6 +1197,7 @@ static struct cli_kw_list cli_kws = {{ },{
        {{ "debug", "dev", "panic", NULL }, "debug dev panic             : immediately trigger a panic",     debug_parse_cli_panic, NULL, NULL, NULL, ACCESS_EXPERT },
        {{ "debug", "dev", "sched", NULL }, "debug dev sched ...         : stress the scheduler",            debug_parse_cli_sched, 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 },