blob: f9eccad3e28bdb54fe1c742667e3b278ecda4e1d [file] [log] [blame]
Willy Tarreau4e2b6462019-05-16 17:44:30 +02001/*
2 * Process debugging functions.
3 *
4 * Copyright 2000-2019 Willy Tarreau <willy@haproxy.org>.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
10 *
11 */
12
Willy Tarreauf5b4e062020-03-03 15:40:23 +010013
Willy Tarreau476252b2022-01-24 20:26:09 +010014#include <errno.h>
Willy Tarreau368bff42019-12-06 17:18:28 +010015#include <fcntl.h>
Willy Tarreau4e2b6462019-05-16 17:44:30 +020016#include <signal.h>
17#include <time.h>
18#include <stdio.h>
Willy Tarreau6bdf3e92019-05-20 14:25:05 +020019#include <stdlib.h>
Willy Tarreauaeed4a82020-06-04 22:01:04 +020020#include <syslog.h>
Willy Tarreau476252b2022-01-24 20:26:09 +010021#include <sys/stat.h>
Willy Tarreau368bff42019-12-06 17:18:28 +010022#include <sys/types.h>
23#include <sys/wait.h>
Willy Tarreau476252b2022-01-24 20:26:09 +010024#include <unistd.h>
25#ifdef USE_EPOLL
26#include <sys/epoll.h>
27#endif
Willy Tarreau4e2b6462019-05-16 17:44:30 +020028
Willy Tarreau4c7e4b72020-05-27 12:58:42 +020029#include <haproxy/api.h>
Willy Tarreau8dabda72020-05-27 17:22:10 +020030#include <haproxy/buf.h>
Willy Tarreau83487a82020-06-04 20:19:54 +020031#include <haproxy/cli.h>
Willy Tarreau2a83d602020-05-27 16:58:08 +020032#include <haproxy/debug.h>
Willy Tarreaub2551052020-06-09 09:07:15 +020033#include <haproxy/fd.h>
34#include <haproxy/global.h>
Willy Tarreau86416052020-06-04 09:20:54 +020035#include <haproxy/hlua.h>
Willy Tarreauaeed4a82020-06-04 22:01:04 +020036#include <haproxy/log.h>
Willy Tarreaub2551052020-06-09 09:07:15 +020037#include <haproxy/net_helper.h>
Willy Tarreau5e539c92020-06-04 20:45:39 +020038#include <haproxy/stream_interface.h>
Willy Tarreaucea0e1b2020-06-04 17:25:40 +020039#include <haproxy/task.h>
Willy Tarreau3f567e42020-05-28 15:29:19 +020040#include <haproxy/thread.h>
Willy Tarreau48fbcae2020-06-03 18:09:46 +020041#include <haproxy/tools.h>
Willy Tarreaub2551052020-06-09 09:07:15 +020042#include <import/ist.h>
Willy Tarreau4e2b6462019-05-16 17:44:30 +020043
Willy Tarreau4e2b6462019-05-16 17:44:30 +020044
Willy Tarreaua37cb182019-07-31 19:20:39 +020045/* mask of threads still having to dump, used to respect ordering. Only used
46 * when USE_THREAD_DUMP is set.
47 */
48volatile unsigned long threads_to_dump = 0;
Willy Tarreau9b013702019-10-24 18:18:02 +020049unsigned int debug_commands_issued = 0;
Willy Tarreaua37cb182019-07-31 19:20:39 +020050
Willy Tarreau123fc972021-01-22 13:52:41 +010051/* dumps a backtrace of the current thread that is appended to buffer <buf>.
52 * Lines are prefixed with the string <prefix> which may be empty (used for
53 * indenting). It is recommended to use this at a function's tail so that
Willy Tarreau2bfce7e2021-01-22 14:48:34 +010054 * the function does not appear in the call stack. The <dump> argument
55 * indicates what dump state to start from, and should usually be zero. It
56 * may be among the following values:
57 * - 0: search usual callers before step 1, or directly jump to 2
58 * - 1: skip usual callers before step 2
59 * - 2: dump until polling loop, scheduler, or main() (excluded)
60 * - 3: end
61 * - 4-7: like 0 but stops *after* main.
Willy Tarreau123fc972021-01-22 13:52:41 +010062 */
Willy Tarreau2bfce7e2021-01-22 14:48:34 +010063void ha_dump_backtrace(struct buffer *buf, const char *prefix, int dump)
Willy Tarreau123fc972021-01-22 13:52:41 +010064{
65 struct buffer bak;
66 char pfx2[100];
67 void *callers[100];
68 int j, nptrs;
69 const void *addr;
Willy Tarreau123fc972021-01-22 13:52:41 +010070
71 nptrs = my_backtrace(callers, sizeof(callers)/sizeof(*callers));
72 if (!nptrs)
73 return;
74
75 if (snprintf(pfx2, sizeof(pfx2), "%s| ", prefix) > sizeof(pfx2))
76 pfx2[0] = 0;
77
78 /* The call backtrace_symbols_fd(callers, nptrs, STDOUT_FILENO would
79 * produce similar output to the following:
80 */
81 chunk_appendf(buf, "%scall trace(%d):\n", prefix, nptrs);
Willy Tarreau2bfce7e2021-01-22 14:48:34 +010082 for (j = 0; (j < nptrs || (dump & 3) < 2); j++) {
83 if (j == nptrs && !(dump & 3)) {
Willy Tarreau123fc972021-01-22 13:52:41 +010084 /* we failed to spot the starting point of the
85 * dump, let's start over dumping everything we
86 * have.
87 */
Willy Tarreau2bfce7e2021-01-22 14:48:34 +010088 dump += 2;
Willy Tarreau123fc972021-01-22 13:52:41 +010089 j = 0;
90 }
91 bak = *buf;
92 dump_addr_and_bytes(buf, pfx2, callers[j], 8);
93 addr = resolve_sym_name(buf, ": ", callers[j]);
Willy Tarreau2bfce7e2021-01-22 14:48:34 +010094 if ((dump & 3) == 0) {
Willy Tarreau123fc972021-01-22 13:52:41 +010095 /* dump not started, will start *after*
Willy Tarreaua8459b22021-01-22 14:12:27 +010096 * ha_thread_dump_all_to_trash, ha_panic and ha_backtrace_to_stderr
Willy Tarreau123fc972021-01-22 13:52:41 +010097 */
Willy Tarreaua8459b22021-01-22 14:12:27 +010098 if (addr == ha_thread_dump_all_to_trash || addr == ha_panic ||
99 addr == ha_backtrace_to_stderr)
Willy Tarreau2bfce7e2021-01-22 14:48:34 +0100100 dump++;
Willy Tarreau123fc972021-01-22 13:52:41 +0100101 *buf = bak;
102 continue;
103 }
104
Willy Tarreau2bfce7e2021-01-22 14:48:34 +0100105 if ((dump & 3) == 1) {
Willy Tarreau123fc972021-01-22 13:52:41 +0100106 /* starting */
Willy Tarreaua8459b22021-01-22 14:12:27 +0100107 if (addr == ha_thread_dump_all_to_trash || addr == ha_panic ||
108 addr == ha_backtrace_to_stderr) {
Willy Tarreau123fc972021-01-22 13:52:41 +0100109 *buf = bak;
110 continue;
111 }
Willy Tarreau2bfce7e2021-01-22 14:48:34 +0100112 dump++;
Willy Tarreau123fc972021-01-22 13:52:41 +0100113 }
114
Willy Tarreau2bfce7e2021-01-22 14:48:34 +0100115 if ((dump & 3) == 2) {
116 /* still dumping */
117 if (dump == 6) {
118 /* we only stop *after* main and we must send the LF */
119 if (addr == main) {
120 j = nptrs;
121 dump++;
122 }
123 }
124 else if (addr == run_poll_loop || addr == main || addr == run_tasks_from_lists) {
125 dump++;
Willy Tarreau123fc972021-01-22 13:52:41 +0100126 *buf = bak;
127 break;
128 }
129 }
130 /* OK, line dumped */
131 chunk_appendf(buf, "\n");
132 }
133}
134
Willy Tarreaua8459b22021-01-22 14:12:27 +0100135/* dump a backtrace of current thread's stack to stderr. */
136void ha_backtrace_to_stderr()
137{
138 char area[2048];
139 struct buffer b = b_make(area, sizeof(area), 0, 0);
140
Willy Tarreau2bfce7e2021-01-22 14:48:34 +0100141 ha_dump_backtrace(&b, " ", 4);
Willy Tarreaua8459b22021-01-22 14:12:27 +0100142 if (b.data)
Willy Tarreau2cbe2e72021-01-22 15:58:26 +0100143 DISGUISE(write(2, b.area, b.data));
Willy Tarreaua8459b22021-01-22 14:12:27 +0100144}
145
Willy Tarreau5cf64dd2019-05-17 10:36:08 +0200146/* Dumps to the buffer some known information for the desired thread, and
147 * optionally extra info for the current thread. The dump will be appended to
148 * the buffer, so the caller is responsible for preliminary initializing it.
149 * The calling thread ID needs to be passed in <calling_tid> to display a star
Willy Tarreaue6a02fa2019-05-22 07:06:44 +0200150 * in front of the calling thread's line (usually it's tid). Any stuck thread
151 * is also prefixed with a '>'.
Willy Tarreau4e2b6462019-05-16 17:44:30 +0200152 */
Willy Tarreau5cf64dd2019-05-17 10:36:08 +0200153void ha_thread_dump(struct buffer *buf, int thr, int calling_tid)
Willy Tarreau4e2b6462019-05-16 17:44:30 +0200154{
155 unsigned long thr_bit = 1UL << thr;
David Carliera92c5ce2019-09-13 05:03:12 +0100156 unsigned long long p = ha_thread_info[thr].prev_cpu_time;
157 unsigned long long n = now_cpu_time_thread(&ha_thread_info[thr]);
158 int stuck = !!(ha_thread_info[thr].flags & TI_FL_STUCK);
Willy Tarreau4e2b6462019-05-16 17:44:30 +0200159
Willy Tarreau5cf64dd2019-05-17 10:36:08 +0200160 chunk_appendf(buf,
Willy Tarreauf0e5da22020-05-01 12:26:03 +0200161 "%c%cThread %-2u: id=0x%llx act=%d glob=%d wq=%d rq=%d tl=%d tlsz=%d rqsz=%d\n"
Olivier Houchard305d5ab2019-07-24 18:07:06 +0200162 " stuck=%d prof=%d",
Willy Tarreaue6a02fa2019-05-22 07:06:44 +0200163 (thr == calling_tid) ? '*' : ' ', stuck ? '>' : ' ', thr + 1,
Willy Tarreauff64d3b2020-05-01 11:28:49 +0200164 ha_get_pthread_id(thr),
Olivier Houchardcfbb3e62019-05-29 19:22:43 +0200165 thread_has_tasks(),
Willy Tarreau4e2b6462019-05-16 17:44:30 +0200166 !!(global_tasks_mask & thr_bit),
167 !eb_is_empty(&task_per_thread[thr].timers),
168 !eb_is_empty(&task_per_thread[thr].rqueue),
Willy Tarreaua62917b2020-01-30 18:37:28 +0100169 !(LIST_ISEMPTY(&task_per_thread[thr].tasklets[TL_URGENT]) &&
170 LIST_ISEMPTY(&task_per_thread[thr].tasklets[TL_NORMAL]) &&
171 LIST_ISEMPTY(&task_per_thread[thr].tasklets[TL_BULK]) &&
172 MT_LIST_ISEMPTY(&task_per_thread[thr].shared_tasklet_list)),
Willy Tarreau1f3b1412021-02-24 14:13:40 +0100173 task_per_thread[thr].tasks_in_list,
Willy Tarreau9c7b8082021-02-24 15:10:07 +0100174 task_per_thread[thr].rq_total,
Willy Tarreaue6a02fa2019-05-22 07:06:44 +0200175 stuck,
Willy Tarreau4e2b6462019-05-16 17:44:30 +0200176 !!(task_profiling_mask & thr_bit));
177
Willy Tarreau5cf64dd2019-05-17 10:36:08 +0200178 chunk_appendf(buf,
Willy Tarreau4e2b6462019-05-16 17:44:30 +0200179 " harmless=%d wantrdv=%d",
180 !!(threads_harmless_mask & thr_bit),
181 !!(threads_want_rdv_mask & thr_bit));
Willy Tarreau4e2b6462019-05-16 17:44:30 +0200182
Willy Tarreau5cf64dd2019-05-17 10:36:08 +0200183 chunk_appendf(buf, "\n");
Willy Tarreau9c8800a2019-05-20 20:52:20 +0200184 chunk_appendf(buf, " cpu_ns: poll=%llu now=%llu diff=%llu\n", p, n, n-p);
Willy Tarreau4e2b6462019-05-16 17:44:30 +0200185
186 /* this is the end of what we can dump from outside the thread */
187
188 if (thr != tid)
189 return;
190
Willy Tarreau5cf64dd2019-05-17 10:36:08 +0200191 chunk_appendf(buf, " curr_task=");
Willy Tarreaud022e9c2019-09-24 08:25:15 +0200192 ha_task_dump(buf, sched->current, " ");
Willy Tarreauf5b4e062020-03-03 15:40:23 +0100193
Willy Tarreauf5b4e062020-03-03 15:40:23 +0100194 if (stuck) {
195 /* We only emit the backtrace for stuck threads in order not to
196 * waste precious output buffer space with non-interesting data.
Willy Tarreau123fc972021-01-22 13:52:41 +0100197 * Please leave this as the last instruction in this function
198 * so that the compiler uses tail merging and the current
199 * function does not appear in the stack.
Willy Tarreauf5b4e062020-03-03 15:40:23 +0100200 */
Willy Tarreau2bfce7e2021-01-22 14:48:34 +0100201 ha_dump_backtrace(buf, " ", 0);
Willy Tarreauf5b4e062020-03-03 15:40:23 +0100202 }
Willy Tarreau4e2b6462019-05-16 17:44:30 +0200203}
204
205
Willy Tarreau5cf64dd2019-05-17 10:36:08 +0200206/* dumps into the buffer some information related to task <task> (which may
Willy Tarreau4e2b6462019-05-16 17:44:30 +0200207 * either be a task or a tasklet, and prepend each line except the first one
Willy Tarreau5cf64dd2019-05-17 10:36:08 +0200208 * with <pfx>. The buffer is only appended and the first output starts by the
209 * pointer itself. The caller is responsible for making sure the task is not
210 * going to vanish during the dump.
Willy Tarreau4e2b6462019-05-16 17:44:30 +0200211 */
Willy Tarreau5cf64dd2019-05-17 10:36:08 +0200212void ha_task_dump(struct buffer *buf, const struct task *task, const char *pfx)
Willy Tarreau4e2b6462019-05-16 17:44:30 +0200213{
Willy Tarreau578ea8b2019-05-22 09:43:09 +0200214 const struct stream *s = NULL;
Willy Tarreaua512b022019-08-21 14:12:19 +0200215 const struct appctx __maybe_unused *appctx = NULL;
Willy Tarreau78a7cb62019-08-21 14:16:02 +0200216 struct hlua __maybe_unused *hlua = NULL;
Willy Tarreau578ea8b2019-05-22 09:43:09 +0200217
Willy Tarreau14a1ab72019-05-17 10:34:25 +0200218 if (!task) {
Willy Tarreau5cf64dd2019-05-17 10:36:08 +0200219 chunk_appendf(buf, "0\n");
Willy Tarreau231ec392019-05-17 10:39:47 +0200220 return;
221 }
222
Willy Tarreau20db9112019-05-17 14:14:35 +0200223 if (TASK_IS_TASKLET(task))
224 chunk_appendf(buf,
225 "%p (tasklet) calls=%u\n",
226 task,
227 task->calls);
228 else
229 chunk_appendf(buf,
230 "%p (task) calls=%u last=%llu%s\n",
231 task,
232 task->calls,
233 task->call_date ? (unsigned long long)(now_mono_time() - task->call_date) : 0,
234 task->call_date ? " ns ago" : "");
Willy Tarreau4e2b6462019-05-16 17:44:30 +0200235
Willy Tarreau2e89b092020-03-03 17:13:02 +0100236 chunk_appendf(buf, "%s fct=%p(", pfx, task->process);
237 resolve_sym_name(buf, NULL, task->process);
238 chunk_appendf(buf,") ctx=%p", task->context);
Willy Tarreau578ea8b2019-05-22 09:43:09 +0200239
Willy Tarreaua512b022019-08-21 14:12:19 +0200240 if (task->process == task_run_applet && (appctx = task->context))
241 chunk_appendf(buf, "(%s)\n", appctx->applet->name);
242 else
243 chunk_appendf(buf, "\n");
244
Willy Tarreau578ea8b2019-05-22 09:43:09 +0200245 if (task->process == process_stream && task->context)
246 s = (struct stream *)task->context;
247 else if (task->process == task_run_applet && task->context)
248 s = si_strm(((struct appctx *)task->context)->owner);
249 else if (task->process == si_cs_io_cb && task->context)
250 s = si_strm((struct stream_interface *)task->context);
251
252 if (s)
253 stream_dump(buf, s, pfx, '\n');
Willy Tarreau78a7cb62019-08-21 14:16:02 +0200254
255#ifdef USE_LUA
256 hlua = NULL;
257 if (s && (hlua = s->hlua)) {
258 chunk_appendf(buf, "%sCurrent executing Lua from a stream analyser -- ", pfx);
259 }
260 else if (task->process == hlua_process_task && (hlua = task->context)) {
261 chunk_appendf(buf, "%sCurrent executing a Lua task -- ", pfx);
262 }
263 else if (task->process == task_run_applet && (appctx = task->context) &&
264 (appctx->applet->fct == hlua_applet_tcp_fct && (hlua = appctx->ctx.hlua_apptcp.hlua))) {
265 chunk_appendf(buf, "%sCurrent executing a Lua TCP service -- ", pfx);
266 }
267 else if (task->process == task_run_applet && (appctx = task->context) &&
268 (appctx->applet->fct == hlua_applet_http_fct && (hlua = appctx->ctx.hlua_apphttp.hlua))) {
269 chunk_appendf(buf, "%sCurrent executing a Lua HTTP service -- ", pfx);
270 }
271
Christopher Faulet471425f2020-07-24 19:08:05 +0200272 if (hlua && hlua->T) {
Christopher Fauletcc2c4f82021-03-24 14:52:24 +0100273 chunk_appendf(buf, "stack traceback:\n ");
274 append_prefixed_str(buf, hlua_traceback(hlua->T, "\n "), pfx, '\n', 0);
275 b_putchr(buf, '\n');
Willy Tarreau78a7cb62019-08-21 14:16:02 +0200276 }
Christopher Faulet471425f2020-07-24 19:08:05 +0200277 else
278 b_putchr(buf, '\n');
Willy Tarreau78a7cb62019-08-21 14:16:02 +0200279#endif
Willy Tarreau4e2b6462019-05-16 17:44:30 +0200280}
281
Willy Tarreau4e2b6462019-05-16 17:44:30 +0200282/* This function dumps all profiling settings. It returns 0 if the output
283 * buffer is full and it needs to be called again, otherwise non-zero.
284 */
285static int cli_io_handler_show_threads(struct appctx *appctx)
286{
287 struct stream_interface *si = appctx->owner;
288 int thr;
289
290 if (unlikely(si_ic(si)->flags & (CF_WRITE_ERROR|CF_SHUTW)))
291 return 1;
292
293 if (appctx->st0)
294 thr = appctx->st1;
295 else
296 thr = 0;
297
Willy Tarreau5cf64dd2019-05-17 10:36:08 +0200298 chunk_reset(&trash);
Willy Tarreauc7091d82019-05-17 10:08:49 +0200299 ha_thread_dump_all_to_trash();
Willy Tarreau5cf64dd2019-05-17 10:36:08 +0200300
301 if (ci_putchk(si_ic(si), &trash) == -1) {
302 /* failed, try again */
303 si_rx_room_blk(si);
304 appctx->st1 = thr;
305 return 0;
306 }
Willy Tarreau4e2b6462019-05-16 17:44:30 +0200307 return 1;
308}
309
Willy Tarreau37857332021-12-28 09:57:10 +0100310#if defined(HA_HAVE_DUMP_LIBS)
311/* parse a "show libs" command. It returns 1 if it emits anything otherwise zero. */
312static int debug_parse_cli_show_libs(char **args, char *payload, struct appctx *appctx, void *private)
313{
314 if (!cli_has_level(appctx, ACCESS_LVL_OPER))
315 return 1;
316
317 chunk_reset(&trash);
318 if (dump_libs(&trash, 1))
319 return cli_msg(appctx, LOG_INFO, trash.area);
320 else
321 return 0;
322}
323#endif
324
Willy Tarreau56131ca2019-05-20 13:48:29 +0200325/* dumps a state of all threads into the trash and on fd #2, then aborts. */
326void ha_panic()
327{
328 chunk_reset(&trash);
Willy Tarreaua9f9fc92019-05-20 17:45:35 +0200329 chunk_appendf(&trash, "Thread %u is about to kill the process.\n", tid + 1);
Willy Tarreau56131ca2019-05-20 13:48:29 +0200330 ha_thread_dump_all_to_trash();
Willy Tarreau2e8ab6b2020-03-14 11:03:20 +0100331 DISGUISE(write(2, trash.area, trash.data));
Willy Tarreau56131ca2019-05-20 13:48:29 +0200332 for (;;)
333 abort();
334}
335
Willy Tarreau6bdf3e92019-05-20 14:25:05 +0200336/* parse a "debug dev exit" command. It always returns 1, though it should never return. */
337static int debug_parse_cli_exit(char **args, char *payload, struct appctx *appctx, void *private)
338{
339 int code = atoi(args[3]);
340
341 if (!cli_has_level(appctx, ACCESS_LVL_ADMIN))
342 return 1;
343
Willy Tarreau4781b152021-04-06 13:53:36 +0200344 _HA_ATOMIC_INC(&debug_commands_issued);
Willy Tarreau6bdf3e92019-05-20 14:25:05 +0200345 exit(code);
346 return 1;
347}
348
Willy Tarreau5baf4fe2021-01-22 14:15:46 +0100349/* parse a "debug dev bug" command. It always returns 1, though it should never return.
350 * Note: we make sure not to make the function static so that it appears in the trace.
351 */
352int debug_parse_cli_bug(char **args, char *payload, struct appctx *appctx, void *private)
353{
354 if (!cli_has_level(appctx, ACCESS_LVL_ADMIN))
355 return 1;
356
Willy Tarreau4781b152021-04-06 13:53:36 +0200357 _HA_ATOMIC_INC(&debug_commands_issued);
Willy Tarreau5baf4fe2021-01-22 14:15:46 +0100358 BUG_ON(one > zero);
359 return 1;
360}
361
Willy Tarreau6bdf3e92019-05-20 14:25:05 +0200362/* parse a "debug dev close" command. It always returns 1. */
363static int debug_parse_cli_close(char **args, char *payload, struct appctx *appctx, void *private)
364{
365 int fd;
366
367 if (!cli_has_level(appctx, ACCESS_LVL_ADMIN))
368 return 1;
369
Willy Tarreau9d008692019-08-09 11:21:01 +0200370 if (!*args[3])
371 return cli_err(appctx, "Missing file descriptor number.\n");
Willy Tarreau6bdf3e92019-05-20 14:25:05 +0200372
373 fd = atoi(args[3]);
Willy Tarreau9d008692019-08-09 11:21:01 +0200374 if (fd < 0 || fd >= global.maxsock)
375 return cli_err(appctx, "File descriptor out of range.\n");
Willy Tarreau6bdf3e92019-05-20 14:25:05 +0200376
Willy Tarreau9d008692019-08-09 11:21:01 +0200377 if (!fdtab[fd].owner)
378 return cli_msg(appctx, LOG_INFO, "File descriptor was already closed.\n");
Willy Tarreau6bdf3e92019-05-20 14:25:05 +0200379
Willy Tarreau4781b152021-04-06 13:53:36 +0200380 _HA_ATOMIC_INC(&debug_commands_issued);
Willy Tarreau6bdf3e92019-05-20 14:25:05 +0200381 fd_delete(fd);
382 return 1;
Willy Tarreau6bdf3e92019-05-20 14:25:05 +0200383}
384
385/* parse a "debug dev delay" command. It always returns 1. */
386static int debug_parse_cli_delay(char **args, char *payload, struct appctx *appctx, void *private)
387{
388 int delay = atoi(args[3]);
389
390 if (!cli_has_level(appctx, ACCESS_LVL_ADMIN))
391 return 1;
392
Willy Tarreau4781b152021-04-06 13:53:36 +0200393 _HA_ATOMIC_INC(&debug_commands_issued);
Willy Tarreau6bdf3e92019-05-20 14:25:05 +0200394 usleep((long)delay * 1000);
395 return 1;
396}
397
398/* parse a "debug dev log" command. It always returns 1. */
399static int debug_parse_cli_log(char **args, char *payload, struct appctx *appctx, void *private)
400{
401 int arg;
402
403 if (!cli_has_level(appctx, ACCESS_LVL_ADMIN))
404 return 1;
405
Willy Tarreau4781b152021-04-06 13:53:36 +0200406 _HA_ATOMIC_INC(&debug_commands_issued);
Willy Tarreau6bdf3e92019-05-20 14:25:05 +0200407 chunk_reset(&trash);
408 for (arg = 3; *args[arg]; arg++) {
409 if (arg > 3)
410 chunk_strcat(&trash, " ");
411 chunk_strcat(&trash, args[arg]);
412 }
413
414 send_log(NULL, LOG_INFO, "%s\n", trash.area);
415 return 1;
416}
417
418/* parse a "debug dev loop" command. It always returns 1. */
419static int debug_parse_cli_loop(char **args, char *payload, struct appctx *appctx, void *private)
420{
421 struct timeval deadline, curr;
422 int loop = atoi(args[3]);
423
424 if (!cli_has_level(appctx, ACCESS_LVL_ADMIN))
425 return 1;
426
Willy Tarreau4781b152021-04-06 13:53:36 +0200427 _HA_ATOMIC_INC(&debug_commands_issued);
Willy Tarreau6bdf3e92019-05-20 14:25:05 +0200428 gettimeofday(&curr, NULL);
429 tv_ms_add(&deadline, &curr, loop);
430
431 while (tv_ms_cmp(&curr, &deadline) < 0)
432 gettimeofday(&curr, NULL);
433
434 return 1;
435}
436
437/* parse a "debug dev panic" command. It always returns 1, though it should never return. */
438static int debug_parse_cli_panic(char **args, char *payload, struct appctx *appctx, void *private)
439{
440 if (!cli_has_level(appctx, ACCESS_LVL_ADMIN))
441 return 1;
442
Willy Tarreau4781b152021-04-06 13:53:36 +0200443 _HA_ATOMIC_INC(&debug_commands_issued);
Willy Tarreau6bdf3e92019-05-20 14:25:05 +0200444 ha_panic();
445 return 1;
446}
447
448/* parse a "debug dev exec" command. It always returns 1. */
Willy Tarreaub24ab222019-10-24 18:03:39 +0200449#if defined(DEBUG_DEV)
Willy Tarreau6bdf3e92019-05-20 14:25:05 +0200450static int debug_parse_cli_exec(char **args, char *payload, struct appctx *appctx, void *private)
451{
Willy Tarreau368bff42019-12-06 17:18:28 +0100452 int pipefd[2];
Willy Tarreau6bdf3e92019-05-20 14:25:05 +0200453 int arg;
Willy Tarreau368bff42019-12-06 17:18:28 +0100454 int pid;
Willy Tarreau6bdf3e92019-05-20 14:25:05 +0200455
456 if (!cli_has_level(appctx, ACCESS_LVL_ADMIN))
457 return 1;
458
Willy Tarreau4781b152021-04-06 13:53:36 +0200459 _HA_ATOMIC_INC(&debug_commands_issued);
Willy Tarreau6bdf3e92019-05-20 14:25:05 +0200460 chunk_reset(&trash);
461 for (arg = 3; *args[arg]; arg++) {
462 if (arg > 3)
463 chunk_strcat(&trash, " ");
464 chunk_strcat(&trash, args[arg]);
465 }
466
Willy Tarreau368bff42019-12-06 17:18:28 +0100467 thread_isolate();
468 if (pipe(pipefd) < 0)
469 goto fail_pipe;
Willy Tarreau6bdf3e92019-05-20 14:25:05 +0200470
Willy Tarreau368bff42019-12-06 17:18:28 +0100471 if (fcntl(pipefd[0], F_SETFD, fcntl(pipefd[0], F_GETFD, FD_CLOEXEC) | FD_CLOEXEC) == -1)
472 goto fail_fcntl;
473
474 if (fcntl(pipefd[1], F_SETFD, fcntl(pipefd[1], F_GETFD, FD_CLOEXEC) | FD_CLOEXEC) == -1)
475 goto fail_fcntl;
476
477 pid = fork();
478
479 if (pid < 0)
480 goto fail_fork;
481 else if (pid == 0) {
482 /* child */
483 char *cmd[4] = { "/bin/sh", "-c", 0, 0 };
484
485 close(0);
486 dup2(pipefd[1], 1);
487 dup2(pipefd[1], 2);
488
489 cmd[2] = trash.area;
490 execvp(cmd[0], cmd);
491 printf("execvp() failed\n");
492 exit(1);
493 }
494
495 /* parent */
496 thread_release();
497 close(pipefd[1]);
Willy Tarreau6bdf3e92019-05-20 14:25:05 +0200498 chunk_reset(&trash);
499 while (1) {
Willy Tarreau368bff42019-12-06 17:18:28 +0100500 size_t ret = read(pipefd[0], trash.area + trash.data, trash.size - 20 - trash.data);
501 if (ret <= 0)
Willy Tarreau6bdf3e92019-05-20 14:25:05 +0200502 break;
503 trash.data += ret;
504 if (trash.data + 20 == trash.size) {
505 chunk_strcat(&trash, "\n[[[TRUNCATED]]]\n");
506 break;
507 }
508 }
Willy Tarreau368bff42019-12-06 17:18:28 +0100509 close(pipefd[0]);
510 waitpid(pid, NULL, WNOHANG);
Willy Tarreau6bdf3e92019-05-20 14:25:05 +0200511 trash.area[trash.data] = 0;
Willy Tarreau9d008692019-08-09 11:21:01 +0200512 return cli_msg(appctx, LOG_INFO, trash.area);
Willy Tarreau368bff42019-12-06 17:18:28 +0100513
514 fail_fork:
515 fail_fcntl:
516 close(pipefd[0]);
517 close(pipefd[1]);
518 fail_pipe:
519 thread_release();
520 return cli_err(appctx, "Failed to execute command.\n");
Willy Tarreau6bdf3e92019-05-20 14:25:05 +0200521}
Willy Tarreaub24ab222019-10-24 18:03:39 +0200522#endif
Willy Tarreau6bdf3e92019-05-20 14:25:05 +0200523
524/* parse a "debug dev hex" command. It always returns 1. */
525static int debug_parse_cli_hex(char **args, char *payload, struct appctx *appctx, void *private)
526{
527 unsigned long start, len;
528
529 if (!cli_has_level(appctx, ACCESS_LVL_ADMIN))
530 return 1;
531
Willy Tarreau9d008692019-08-09 11:21:01 +0200532 if (!*args[3])
533 return cli_err(appctx, "Missing memory address to dump from.\n");
Willy Tarreau6bdf3e92019-05-20 14:25:05 +0200534
535 start = strtoul(args[3], NULL, 0);
Willy Tarreau9d008692019-08-09 11:21:01 +0200536 if (!start)
537 return cli_err(appctx, "Will not dump from NULL address.\n");
Willy Tarreau6bdf3e92019-05-20 14:25:05 +0200538
Willy Tarreau4781b152021-04-06 13:53:36 +0200539 _HA_ATOMIC_INC(&debug_commands_issued);
Willy Tarreau9b013702019-10-24 18:18:02 +0200540
Willy Tarreau6bdf3e92019-05-20 14:25:05 +0200541 /* by default, dump ~128 till next block of 16 */
542 len = strtoul(args[4], NULL, 0);
543 if (!len)
544 len = ((start + 128) & -16) - start;
545
546 chunk_reset(&trash);
Willy Tarreau37101052019-05-20 16:48:20 +0200547 dump_hex(&trash, " ", (const void *)start, len, 1);
Willy Tarreau6bdf3e92019-05-20 14:25:05 +0200548 trash.area[trash.data] = 0;
Willy Tarreau9d008692019-08-09 11:21:01 +0200549 return cli_msg(appctx, LOG_INFO, trash.area);
Willy Tarreau6bdf3e92019-05-20 14:25:05 +0200550}
551
Willy Tarreau48129be2021-05-04 18:40:50 +0200552/* parse a "debug dev sym <addr>" command. It always returns 1. */
553static int debug_parse_cli_sym(char **args, char *payload, struct appctx *appctx, void *private)
554{
555 unsigned long addr;
556
557 if (!cli_has_level(appctx, ACCESS_LVL_ADMIN))
558 return 1;
559
560 if (!*args[3])
561 return cli_err(appctx, "Missing memory address to be resolved.\n");
562
563 _HA_ATOMIC_INC(&debug_commands_issued);
564
565 addr = strtoul(args[3], NULL, 0);
566 chunk_printf(&trash, "%#lx resolves to ", addr);
567 resolve_sym_name(&trash, NULL, (const void *)addr);
568 chunk_appendf(&trash, "\n");
569
570 return cli_msg(appctx, LOG_INFO, trash.area);
571}
572
Willy Tarreau6bdf3e92019-05-20 14:25:05 +0200573/* parse a "debug dev tkill" command. It always returns 1. */
574static int debug_parse_cli_tkill(char **args, char *payload, struct appctx *appctx, void *private)
575{
576 int thr = 0;
577 int sig = SIGABRT;
578
579 if (!cli_has_level(appctx, ACCESS_LVL_ADMIN))
580 return 1;
581
582 if (*args[3])
583 thr = atoi(args[3]);
584
Willy Tarreau9d008692019-08-09 11:21:01 +0200585 if (thr < 0 || thr > global.nbthread)
586 return cli_err(appctx, "Thread number out of range (use 0 for current).\n");
Willy Tarreau6bdf3e92019-05-20 14:25:05 +0200587
588 if (*args[4])
589 sig = atoi(args[4]);
590
Willy Tarreau4781b152021-04-06 13:53:36 +0200591 _HA_ATOMIC_INC(&debug_commands_issued);
Willy Tarreau6bdf3e92019-05-20 14:25:05 +0200592 if (thr)
Willy Tarreaufade80d2019-05-22 08:46:59 +0200593 ha_tkill(thr - 1, sig);
Willy Tarreau6bdf3e92019-05-20 14:25:05 +0200594 else
Willy Tarreau6bdf3e92019-05-20 14:25:05 +0200595 raise(sig);
596 return 1;
597}
598
Willy Tarreau6cbe62b2020-03-05 17:16:24 +0100599/* parse a "debug dev write" command. It always returns 1. */
600static int debug_parse_cli_write(char **args, char *payload, struct appctx *appctx, void *private)
601{
602 unsigned long len;
603
604 if (!*args[3])
605 return cli_err(appctx, "Missing output size.\n");
606
607 len = strtoul(args[3], NULL, 0);
608 if (len >= trash.size)
609 return cli_err(appctx, "Output too large, must be <tune.bufsize.\n");
610
Willy Tarreau4781b152021-04-06 13:53:36 +0200611 _HA_ATOMIC_INC(&debug_commands_issued);
Willy Tarreau6cbe62b2020-03-05 17:16:24 +0100612
613 chunk_reset(&trash);
614 trash.data = len;
615 memset(trash.area, '.', trash.data);
616 trash.area[trash.data] = 0;
617 for (len = 64; len < trash.data; len += 64)
618 trash.area[len] = '\n';
619 return cli_msg(appctx, LOG_INFO, trash.area);
620}
621
Willy Tarreau68680bb2019-10-23 17:23:25 +0200622/* parse a "debug dev stream" command */
623/*
624 * debug dev stream [strm=<ptr>] [strm.f[{+-=}<flags>]] [txn.f[{+-=}<flags>]] \
625 * [req.f[{+-=}<flags>]] [res.f[{+-=}<flags>]] \
626 * [sif.f[{+-=<flags>]] [sib.f[{+-=<flags>]] \
627 * [sif.s[=<state>]] [sib.s[=<state>]]
628 */
629static int debug_parse_cli_stream(char **args, char *payload, struct appctx *appctx, void *private)
630{
631 struct stream *s = si_strm(appctx->owner);
632 int arg;
633 void *ptr;
634 int size;
635 const char *word, *end;
636 struct ist name;
637 char *msg = NULL;
638 char *endarg;
639 unsigned long long old, new;
640
641 if (!cli_has_level(appctx, ACCESS_LVL_ADMIN))
642 return 1;
643
644 ptr = NULL; size = 0;
645
646 if (!*args[3]) {
647 return cli_err(appctx,
648 "Usage: debug dev stream { <obj> <op> <value> | wake }*\n"
649 " <obj> = {strm | strm.f | sif.f | sif.s | sif.x | sib.f | sib.s | sib.x |\n"
650 " txn.f | req.f | req.r | req.w | res.f | res.r | res.w}\n"
651 " <op> = {'' (show) | '=' (assign) | '^' (xor) | '+' (or) | '-' (andnot)}\n"
652 " <value> = 'now' | 64-bit dec/hex integer (0x prefix supported)\n"
653 " 'wake' wakes the stream asssigned to 'strm' (default: current)\n"
654 );
655 }
656
Willy Tarreau4781b152021-04-06 13:53:36 +0200657 _HA_ATOMIC_INC(&debug_commands_issued);
Willy Tarreau68680bb2019-10-23 17:23:25 +0200658 for (arg = 3; *args[arg]; arg++) {
659 old = 0;
660 end = word = args[arg];
661 while (*end && *end != '=' && *end != '^' && *end != '+' && *end != '-')
662 end++;
663 name = ist2(word, end - word);
664 if (isteq(name, ist("strm"))) {
Willy Tarreaub2fee042019-10-25 10:06:55 +0200665 ptr = (!s || !may_access(s)) ? NULL : &s; size = sizeof(s);
Willy Tarreau68680bb2019-10-23 17:23:25 +0200666 } else if (isteq(name, ist("strm.f"))) {
Willy Tarreaub2fee042019-10-25 10:06:55 +0200667 ptr = (!s || !may_access(s)) ? NULL : &s->flags; size = sizeof(s->flags);
Willy Tarreau68680bb2019-10-23 17:23:25 +0200668 } else if (isteq(name, ist("txn.f"))) {
Willy Tarreaub2fee042019-10-25 10:06:55 +0200669 ptr = (!s || !may_access(s)) ? NULL : &s->txn->flags; size = sizeof(s->txn->flags);
Willy Tarreau68680bb2019-10-23 17:23:25 +0200670 } else if (isteq(name, ist("req.f"))) {
Willy Tarreaub2fee042019-10-25 10:06:55 +0200671 ptr = (!s || !may_access(s)) ? NULL : &s->req.flags; size = sizeof(s->req.flags);
Willy Tarreau68680bb2019-10-23 17:23:25 +0200672 } else if (isteq(name, ist("res.f"))) {
Willy Tarreaub2fee042019-10-25 10:06:55 +0200673 ptr = (!s || !may_access(s)) ? NULL : &s->res.flags; size = sizeof(s->res.flags);
Willy Tarreau68680bb2019-10-23 17:23:25 +0200674 } else if (isteq(name, ist("req.r"))) {
Willy Tarreaub2fee042019-10-25 10:06:55 +0200675 ptr = (!s || !may_access(s)) ? NULL : &s->req.rex; size = sizeof(s->req.rex);
Willy Tarreau68680bb2019-10-23 17:23:25 +0200676 } else if (isteq(name, ist("res.r"))) {
Willy Tarreaub2fee042019-10-25 10:06:55 +0200677 ptr = (!s || !may_access(s)) ? NULL : &s->res.rex; size = sizeof(s->res.rex);
Willy Tarreau68680bb2019-10-23 17:23:25 +0200678 } else if (isteq(name, ist("req.w"))) {
Willy Tarreaub2fee042019-10-25 10:06:55 +0200679 ptr = (!s || !may_access(s)) ? NULL : &s->req.wex; size = sizeof(s->req.wex);
Willy Tarreau68680bb2019-10-23 17:23:25 +0200680 } else if (isteq(name, ist("res.w"))) {
Willy Tarreaub2fee042019-10-25 10:06:55 +0200681 ptr = (!s || !may_access(s)) ? NULL : &s->res.wex; size = sizeof(s->res.wex);
Willy Tarreau68680bb2019-10-23 17:23:25 +0200682 } else if (isteq(name, ist("sif.f"))) {
Willy Tarreaub2fee042019-10-25 10:06:55 +0200683 ptr = (!s || !may_access(s)) ? NULL : &s->si[0].flags; size = sizeof(s->si[0].flags);
Willy Tarreau68680bb2019-10-23 17:23:25 +0200684 } else if (isteq(name, ist("sib.f"))) {
Willy Tarreaub2fee042019-10-25 10:06:55 +0200685 ptr = (!s || !may_access(s)) ? NULL : &s->si[1].flags; size = sizeof(s->si[1].flags);
Willy Tarreau68680bb2019-10-23 17:23:25 +0200686 } else if (isteq(name, ist("sif.x"))) {
Willy Tarreaub2fee042019-10-25 10:06:55 +0200687 ptr = (!s || !may_access(s)) ? NULL : &s->si[0].exp; size = sizeof(s->si[0].exp);
Willy Tarreau68680bb2019-10-23 17:23:25 +0200688 } else if (isteq(name, ist("sib.x"))) {
Willy Tarreaub2fee042019-10-25 10:06:55 +0200689 ptr = (!s || !may_access(s)) ? NULL : &s->si[1].exp; size = sizeof(s->si[1].exp);
Willy Tarreau68680bb2019-10-23 17:23:25 +0200690 } else if (isteq(name, ist("sif.s"))) {
Willy Tarreaub2fee042019-10-25 10:06:55 +0200691 ptr = (!s || !may_access(s)) ? NULL : &s->si[0].state; size = sizeof(s->si[0].state);
Willy Tarreau68680bb2019-10-23 17:23:25 +0200692 } else if (isteq(name, ist("sib.s"))) {
Willy Tarreaub2fee042019-10-25 10:06:55 +0200693 ptr = (!s || !may_access(s)) ? NULL : &s->si[1].state; size = sizeof(s->si[1].state);
Willy Tarreau68680bb2019-10-23 17:23:25 +0200694 } else if (isteq(name, ist("wake"))) {
Willy Tarreau2b5520d2019-10-24 18:28:23 +0200695 if (s && may_access(s) && may_access((void *)s + sizeof(*s) - 1))
Willy Tarreau68680bb2019-10-23 17:23:25 +0200696 task_wakeup(s->task, TASK_WOKEN_TIMER|TASK_WOKEN_IO|TASK_WOKEN_MSG);
697 continue;
698 } else
699 return cli_dynerr(appctx, memprintf(&msg, "Unsupported field name: '%s'.\n", word));
700
701 /* read previous value */
Willy Tarreau2b5520d2019-10-24 18:28:23 +0200702 if ((s || ptr == &s) && ptr && may_access(ptr) && may_access(ptr + size - 1)) {
Willy Tarreau68680bb2019-10-23 17:23:25 +0200703 if (size == 8)
704 old = read_u64(ptr);
705 else if (size == 4)
706 old = read_u32(ptr);
707 else if (size == 2)
708 old = read_u16(ptr);
709 else
710 old = *(const uint8_t *)ptr;
Willy Tarreau2b5520d2019-10-24 18:28:23 +0200711 } else {
712 memprintf(&msg,
713 "%sSkipping inaccessible pointer %p for field '%.*s'.\n",
714 msg ? msg : "", ptr, (int)(end - word), word);
715 continue;
Willy Tarreau68680bb2019-10-23 17:23:25 +0200716 }
717
718 /* parse the new value . */
719 new = strtoll(end + 1, &endarg, 0);
720 if (end[1] && *endarg) {
721 if (strcmp(end + 1, "now") == 0)
722 new = now_ms;
723 else {
724 memprintf(&msg,
725 "%sIgnoring unparsable value '%s' for field '%.*s'.\n",
726 msg ? msg : "", end + 1, (int)(end - word), word);
727 continue;
728 }
729 }
730
731 switch (*end) {
732 case '\0': /* show */
733 memprintf(&msg, "%s%.*s=%#llx ", msg ? msg : "", (int)(end - word), word, old);
734 new = old; // do not change the value
735 break;
736
737 case '=': /* set */
738 break;
739
740 case '^': /* XOR */
741 new = old ^ new;
742 break;
743
744 case '+': /* OR */
745 new = old | new;
746 break;
747
748 case '-': /* AND NOT */
749 new = old & ~new;
750 break;
751
752 default:
753 break;
754 }
755
756 /* write the new value */
Willy Tarreau2b5520d2019-10-24 18:28:23 +0200757 if (new != old) {
Willy Tarreau68680bb2019-10-23 17:23:25 +0200758 if (size == 8)
759 write_u64(ptr, new);
760 else if (size == 4)
761 write_u32(ptr, new);
762 else if (size == 2)
763 write_u16(ptr, new);
764 else
765 *(uint8_t *)ptr = new;
766 }
767 }
768
769 if (msg && *msg)
770 return cli_dynmsg(appctx, LOG_INFO, msg);
771 return 1;
772}
773
Willy Tarreau144f84a2021-03-02 16:09:26 +0100774static struct task *debug_task_handler(struct task *t, void *ctx, unsigned int state)
Willy Tarreaua5a44792020-11-29 17:12:15 +0100775{
776 unsigned long *tctx = ctx; // [0] = #tasks, [1] = inter, [2+] = { tl | (tsk+1) }
777 unsigned long inter = tctx[1];
778 unsigned long rnd;
779
780 t->expire = tick_add(now_ms, inter);
781
782 /* half of the calls will wake up another entry */
Willy Tarreau06e69b52021-03-02 14:01:35 +0100783 rnd = statistical_prng();
Willy Tarreaua5a44792020-11-29 17:12:15 +0100784 if (rnd & 1) {
785 rnd >>= 1;
786 rnd %= tctx[0];
787 rnd = tctx[rnd + 2];
788
789 if (rnd & 1)
790 task_wakeup((struct task *)(rnd - 1), TASK_WOKEN_MSG);
791 else
792 tasklet_wakeup((struct tasklet *)rnd);
793 }
794 return t;
795}
796
Willy Tarreau144f84a2021-03-02 16:09:26 +0100797static struct task *debug_tasklet_handler(struct task *t, void *ctx, unsigned int state)
Willy Tarreaua5a44792020-11-29 17:12:15 +0100798{
799 unsigned long *tctx = ctx; // [0] = #tasks, [1] = inter, [2+] = { tl | (tsk+1) }
800 unsigned long rnd;
801 int i;
802
803 /* wake up two random entries */
804 for (i = 0; i < 2; i++) {
Willy Tarreau06e69b52021-03-02 14:01:35 +0100805 rnd = statistical_prng() % tctx[0];
Willy Tarreaua5a44792020-11-29 17:12:15 +0100806 rnd = tctx[rnd + 2];
807
808 if (rnd & 1)
809 task_wakeup((struct task *)(rnd - 1), TASK_WOKEN_MSG);
810 else
811 tasklet_wakeup((struct tasklet *)rnd);
812 }
813 return t;
814}
815
816/* parse a "debug dev sched" command
817 * debug dev sched {task|tasklet} [count=<count>] [mask=<mask>] [single=<single>] [inter=<inter>]
818 */
819static int debug_parse_cli_sched(char **args, char *payload, struct appctx *appctx, void *private)
820{
821 int arg;
822 void *ptr;
823 int size;
824 const char *word, *end;
825 struct ist name;
826 char *msg = NULL;
827 char *endarg;
828 unsigned long long new;
829 unsigned long count = 0;
830 unsigned long thrid = 0;
831 unsigned int inter = 0;
832 unsigned long mask, tmask;
833 unsigned long i;
834 int mode = 0; // 0 = tasklet; 1 = task
835 int single = 0;
836 unsigned long *tctx; // [0] = #tasks, [1] = inter, [2+] = { tl | (tsk+1) }
837
838 if (!cli_has_level(appctx, ACCESS_LVL_ADMIN))
839 return 1;
840
841 ptr = NULL; size = 0;
842 mask = all_threads_mask;
843
844 if (strcmp(args[3], "task") != 0 && strcmp(args[3], "tasklet") != 0) {
845 return cli_err(appctx,
846 "Usage: debug dev sched {task|tasklet} { <obj> = <value> }*\n"
847 " <obj> = {count | mask | inter | single }\n"
848 " <value> = 64-bit dec/hex integer (0x prefix supported)\n"
849 );
850 }
851
852 mode = strcmp(args[3], "task") == 0;
853
Willy Tarreau4781b152021-04-06 13:53:36 +0200854 _HA_ATOMIC_INC(&debug_commands_issued);
Willy Tarreaua5a44792020-11-29 17:12:15 +0100855 for (arg = 4; *args[arg]; arg++) {
856 end = word = args[arg];
857 while (*end && *end != '=' && *end != '^' && *end != '+' && *end != '-')
858 end++;
859 name = ist2(word, end - word);
860 if (isteq(name, ist("count"))) {
861 ptr = &count; size = sizeof(count);
862 } else if (isteq(name, ist("mask"))) {
863 ptr = &mask; size = sizeof(mask);
864 } else if (isteq(name, ist("tid"))) {
865 ptr = &thrid; size = sizeof(thrid);
866 } else if (isteq(name, ist("inter"))) {
867 ptr = &inter; size = sizeof(inter);
868 } else if (isteq(name, ist("single"))) {
869 ptr = &single; size = sizeof(single);
870 } else
871 return cli_dynerr(appctx, memprintf(&msg, "Unsupported setting: '%s'.\n", word));
872
873 /* parse the new value . */
874 new = strtoll(end + 1, &endarg, 0);
875 if (end[1] && *endarg) {
876 memprintf(&msg,
877 "%sIgnoring unparsable value '%s' for field '%.*s'.\n",
878 msg ? msg : "", end + 1, (int)(end - word), word);
879 continue;
880 }
881
882 /* write the new value */
883 if (size == 8)
884 write_u64(ptr, new);
885 else if (size == 4)
886 write_u32(ptr, new);
887 else if (size == 2)
888 write_u16(ptr, new);
889 else
890 *(uint8_t *)ptr = new;
891 }
892
893 tctx = calloc(sizeof(*tctx), count + 2);
894 if (!tctx)
895 goto fail;
896
897 tctx[0] = (unsigned long)count;
898 tctx[1] = (unsigned long)inter;
899
900 mask &= all_threads_mask;
901 if (!mask)
902 mask = tid_bit;
903
904 tmask = 0;
905 for (i = 0; i < count; i++) {
906 if (single || mode == 0) {
907 /* look for next bit matching a bit in mask or loop back to zero */
908 for (tmask <<= 1; !(mask & tmask); ) {
909 if (!(mask & -tmask))
910 tmask = 1;
911 else
912 tmask <<= 1;
913 }
914 } else {
915 /* multi-threaded task */
916 tmask = mask;
917 }
918
919 /* now, if poly or mask was set, tmask corresponds to the
920 * valid thread mask to use, otherwise it remains zero.
921 */
922 //printf("%lu: mode=%d mask=%#lx\n", i, mode, tmask);
923 if (mode == 0) {
924 struct tasklet *tl = tasklet_new();
925
926 if (!tl)
927 goto fail;
928
929 if (tmask)
930 tl->tid = my_ffsl(tmask) - 1;
931 tl->process = debug_tasklet_handler;
932 tl->context = tctx;
933 tctx[i + 2] = (unsigned long)tl;
934 } else {
935 struct task *task = task_new(tmask ? tmask : tid_bit);
936
937 if (!task)
938 goto fail;
939
940 task->process = debug_task_handler;
941 task->context = tctx;
942 tctx[i + 2] = (unsigned long)task + 1;
943 }
944 }
945
946 /* start the tasks and tasklets */
947 for (i = 0; i < count; i++) {
948 unsigned long ctx = tctx[i + 2];
949
950 if (ctx & 1)
951 task_wakeup((struct task *)(ctx - 1), TASK_WOKEN_INIT);
952 else
953 tasklet_wakeup((struct tasklet *)ctx);
954 }
955
956 if (msg && *msg)
957 return cli_dynmsg(appctx, LOG_INFO, msg);
958 return 1;
959
960 fail:
961 /* free partially allocated entries */
962 for (i = 0; tctx && i < count; i++) {
963 unsigned long ctx = tctx[i + 2];
964
965 if (!ctx)
966 break;
967
968 if (ctx & 1)
969 task_destroy((struct task *)(ctx - 1));
970 else
971 tasklet_free((struct tasklet *)ctx);
972 }
973
974 free(tctx);
975 return cli_err(appctx, "Not enough memory");
976}
977
Willy Tarreau476252b2022-01-24 20:26:09 +0100978/* CLI parser for the "debug dev fd" command. The current FD to restart from is
979 * stored in i0.
980 */
981static int debug_parse_cli_fd(char **args, char *payload, struct appctx *appctx, void *private)
982{
983 if (!cli_has_level(appctx, ACCESS_LVL_OPER))
984 return 1;
985
986 /* start at fd #0 */
987 appctx->ctx.cli.i0 = 0;
988 return 0;
989}
990
991/* CLI I/O handler for the "debug dev fd" command. Dumps all FDs that are
992 * accessible from the process but not known from fdtab. The FD number to
993 * restart from is stored in i0.
994 */
995static int debug_iohandler_fd(struct appctx *appctx)
996{
997 struct stream_interface *si = appctx->owner;
998 struct sockaddr_storage sa;
999 struct stat statbuf;
1000 socklen_t salen, vlen;
1001 int ret1, ret2, port;
1002 char *addrstr;
1003 int ret = 1;
1004 int i, fd;
1005
1006 if (unlikely(si_ic(si)->flags & (CF_WRITE_ERROR|CF_SHUTW)))
1007 goto end;
1008
1009 chunk_reset(&trash);
1010
1011 thread_isolate();
1012
1013 /* we have two inner loops here, one for the proxy, the other one for
1014 * the buffer.
1015 */
1016 for (fd = appctx->ctx.cli.i0; fd < global.maxsock; fd++) {
1017 /* check for FD's existence */
1018 ret1 = fcntl(fd, F_GETFD, 0);
1019 if (ret1 == -1)
1020 continue; // not known to the process
1021 if (fdtab[fd].owner)
1022 continue; // well-known
1023
1024 /* OK we're seeing an orphan let's try to retrieve as much
1025 * information as possible about it.
1026 */
1027 chunk_printf(&trash, "%5d", fd);
1028
1029 if (fstat(fd, &statbuf) != -1) {
1030 chunk_appendf(&trash, " type=%s mod=%04o dev=%#llx siz=%#llx uid=%lld gid=%lld fs=%#llx ino=%#llx",
1031 isatty(fd) ? "tty.":
1032 S_ISREG(statbuf.st_mode) ? "file":
1033 S_ISDIR(statbuf.st_mode) ? "dir.":
1034 S_ISCHR(statbuf.st_mode) ? "chr.":
1035 S_ISBLK(statbuf.st_mode) ? "blk.":
1036 S_ISFIFO(statbuf.st_mode) ? "pipe":
1037 S_ISLNK(statbuf.st_mode) ? "link":
1038 S_ISSOCK(statbuf.st_mode) ? "sock":
1039#ifdef USE_EPOLL
1040 epoll_wait(fd, NULL, 0, 0) != -1 || errno != EBADF ? "epol":
1041#endif
1042 "????",
1043 (uint)statbuf.st_mode & 07777,
1044
1045 (ullong)statbuf.st_rdev,
1046 (ullong)statbuf.st_size,
1047 (ullong)statbuf.st_uid,
1048 (ullong)statbuf.st_gid,
1049
1050 (ullong)statbuf.st_dev,
1051 (ullong)statbuf.st_ino);
1052 }
1053
1054 chunk_appendf(&trash, " getfd=%s+%#x",
1055 (ret1 & FD_CLOEXEC) ? "cloex" : "",
1056 ret1 &~ FD_CLOEXEC);
1057
1058 /* FD options */
1059 ret2 = fcntl(fd, F_GETFL, 0);
1060 if (ret2) {
1061 chunk_appendf(&trash, " getfl=%s",
1062 (ret1 & 3) >= 2 ? "O_RDWR" :
1063 (ret1 & 1) ? "O_WRONLY" : "O_RDONLY");
1064
1065 for (i = 2; i < 32; i++) {
1066 if (!(ret2 & (1UL << i)))
1067 continue;
1068 switch (1UL << i) {
1069 case O_CREAT: chunk_appendf(&trash, ",O_CREAT"); break;
1070 case O_EXCL: chunk_appendf(&trash, ",O_EXCL"); break;
1071 case O_NOCTTY: chunk_appendf(&trash, ",O_NOCTTY"); break;
1072 case O_TRUNC: chunk_appendf(&trash, ",O_TRUNC"); break;
1073 case O_APPEND: chunk_appendf(&trash, ",O_APPEND"); break;
Willy Tarreauc899f0f2022-01-25 14:51:53 +01001074#ifdef O_ASYNC
Willy Tarreau476252b2022-01-24 20:26:09 +01001075 case O_ASYNC: chunk_appendf(&trash, ",O_ASYNC"); break;
Willy Tarreauc899f0f2022-01-25 14:51:53 +01001076#endif
Willy Tarreau476252b2022-01-24 20:26:09 +01001077#ifdef O_DIRECT
1078 case O_DIRECT: chunk_appendf(&trash, ",O_DIRECT"); break;
1079#endif
1080#ifdef O_NOATIME
1081 case O_NOATIME: chunk_appendf(&trash, ",O_NOATIME"); break;
1082#endif
1083 }
1084 }
1085 }
1086
1087 vlen = sizeof(ret2);
1088 ret1 = getsockopt(fd, SOL_SOCKET, SO_TYPE, &ret2, &vlen);
1089 if (ret1 != -1)
1090 chunk_appendf(&trash, " so_type=%d", ret2);
1091
1092 vlen = sizeof(ret2);
1093 ret1 = getsockopt(fd, SOL_SOCKET, SO_ACCEPTCONN, &ret2, &vlen);
1094 if (ret1 != -1)
1095 chunk_appendf(&trash, " so_accept=%d", ret2);
1096
1097 vlen = sizeof(ret2);
1098 ret1 = getsockopt(fd, SOL_SOCKET, SO_ERROR, &ret2, &vlen);
1099 if (ret1 != -1)
1100 chunk_appendf(&trash, " so_error=%d", ret2);
1101
1102 salen = sizeof(sa);
1103 if (getsockname(fd, (struct sockaddr *)&sa, &salen) != -1) {
1104 if (sa.ss_family == AF_INET)
1105 port = ntohs(((const struct sockaddr_in *)&sa)->sin_port);
1106 else if (sa.ss_family == AF_INET6)
1107 port = ntohs(((const struct sockaddr_in6 *)&sa)->sin6_port);
1108 else
1109 port = 0;
1110 addrstr = sa2str(&sa, port, 0);
1111 chunk_appendf(&trash, " laddr=%s", addrstr);
1112 free(addrstr);
1113 }
1114
1115 salen = sizeof(sa);
1116 if (getpeername(fd, (struct sockaddr *)&sa, &salen) != -1) {
1117 if (sa.ss_family == AF_INET)
1118 port = ntohs(((const struct sockaddr_in *)&sa)->sin_port);
1119 else if (sa.ss_family == AF_INET6)
1120 port = ntohs(((const struct sockaddr_in6 *)&sa)->sin6_port);
1121 else
1122 port = 0;
1123 addrstr = sa2str(&sa, port, 0);
1124 chunk_appendf(&trash, " raddr=%s", addrstr);
1125 free(addrstr);
1126 }
1127
1128 chunk_appendf(&trash, "\n");
1129
1130 if (ci_putchk(si_ic(si), &trash) == -1) {
1131 si_rx_room_blk(si);
1132 appctx->ctx.cli.i0 = fd;
1133 ret = 0;
1134 break;
1135 }
1136 }
1137
1138 thread_release();
1139 end:
1140 return ret;
1141}
1142
Willy Tarreaua6026a02020-07-02 09:14:48 +02001143#if defined(DEBUG_MEM_STATS)
1144/* CLI parser for the "debug dev memstats" command */
1145static int debug_parse_cli_memstats(char **args, char *payload, struct appctx *appctx, void *private)
1146{
1147 extern __attribute__((__weak__)) struct mem_stats __start_mem_stats;
1148 extern __attribute__((__weak__)) struct mem_stats __stop_mem_stats;
1149
1150 if (!cli_has_level(appctx, ACCESS_LVL_OPER))
1151 return 1;
1152
1153 if (strcmp(args[3], "reset") == 0) {
1154 struct mem_stats *ptr;
1155
1156 if (!cli_has_level(appctx, ACCESS_LVL_ADMIN))
1157 return 1;
1158
1159 for (ptr = &__start_mem_stats; ptr < &__stop_mem_stats; ptr++) {
1160 _HA_ATOMIC_STORE(&ptr->calls, 0);
1161 _HA_ATOMIC_STORE(&ptr->size, 0);
1162 }
1163 return 1;
1164 }
1165
1166 if (strcmp(args[3], "all") == 0)
1167 appctx->ctx.cli.i0 = 1;
1168
1169 /* otherwise proceed with the dump from p0 to p1 */
1170 appctx->ctx.cli.p0 = &__start_mem_stats;
1171 appctx->ctx.cli.p1 = &__stop_mem_stats;
1172 return 0;
1173}
1174
1175/* CLI I/O handler for the "debug dev memstats" command. Dumps all mem_stats
1176 * structs referenced by pointers located between p0 and p1. Dumps all entries
1177 * if i0 > 0, otherwise only non-zero calls.
1178 */
1179static int debug_iohandler_memstats(struct appctx *appctx)
1180{
1181 struct stream_interface *si = appctx->owner;
1182 struct mem_stats *ptr = appctx->ctx.cli.p0;
1183 int ret = 1;
1184
1185 if (unlikely(si_ic(si)->flags & (CF_WRITE_ERROR|CF_SHUTW)))
1186 goto end;
1187
1188 chunk_reset(&trash);
1189
1190 /* we have two inner loops here, one for the proxy, the other one for
1191 * the buffer.
1192 */
1193 for (ptr = appctx->ctx.cli.p0; ptr != appctx->ctx.cli.p1; ptr++) {
1194 const char *type;
1195 const char *name;
1196 const char *p;
1197
1198 if (!ptr->size && !ptr->calls && !appctx->ctx.cli.i0)
1199 continue;
1200
1201 /* basename only */
1202 for (p = name = ptr->file; *p; p++) {
1203 if (*p == '/')
1204 name = p + 1;
1205 }
1206
1207 switch (ptr->type) {
1208 case MEM_STATS_TYPE_CALLOC: type = "CALLOC"; break;
1209 case MEM_STATS_TYPE_FREE: type = "FREE"; break;
1210 case MEM_STATS_TYPE_MALLOC: type = "MALLOC"; break;
1211 case MEM_STATS_TYPE_REALLOC: type = "REALLOC"; break;
1212 case MEM_STATS_TYPE_STRDUP: type = "STRDUP"; break;
1213 default: type = "UNSET"; break;
1214 }
1215
1216 //chunk_printf(&trash,
1217 // "%20s:%-5d %7s size: %12lu calls: %9lu size/call: %6lu\n",
1218 // name, ptr->line, type,
1219 // (unsigned long)ptr->size, (unsigned long)ptr->calls,
1220 // (unsigned long)(ptr->calls ? (ptr->size / ptr->calls) : 0));
1221
1222 chunk_printf(&trash, "%s:%d", name, ptr->line);
1223 while (trash.data < 25)
1224 trash.area[trash.data++] = ' ';
1225 chunk_appendf(&trash, "%7s size: %12lu calls: %9lu size/call: %6lu\n",
1226 type,
1227 (unsigned long)ptr->size, (unsigned long)ptr->calls,
1228 (unsigned long)(ptr->calls ? (ptr->size / ptr->calls) : 0));
1229
1230 if (ci_putchk(si_ic(si), &trash) == -1) {
1231 si_rx_room_blk(si);
1232 appctx->ctx.cli.p0 = ptr;
1233 ret = 0;
1234 break;
1235 }
1236 }
1237
1238 end:
1239 return ret;
1240}
1241
1242#endif
1243
Willy Tarreauc7091d82019-05-17 10:08:49 +02001244#ifndef USE_THREAD_DUMP
1245
1246/* This function dumps all threads' state to the trash. This version is the
1247 * most basic one, which doesn't inspect other threads.
1248 */
1249void ha_thread_dump_all_to_trash()
1250{
1251 unsigned int thr;
1252
1253 for (thr = 0; thr < global.nbthread; thr++)
1254 ha_thread_dump(&trash, thr, tid);
1255}
1256
1257#else /* below USE_THREAD_DUMP is set */
1258
Willy Tarreauc7091d82019-05-17 10:08:49 +02001259/* ID of the thread requesting the dump */
1260static unsigned int thread_dump_tid;
1261
1262/* points to the buffer where the dump functions should write. It must
1263 * have already been initialized by the requester. Nothing is done if
1264 * it's NULL.
1265 */
1266struct buffer *thread_dump_buffer = NULL;
1267
1268void ha_thread_dump_all_to_trash()
1269{
Willy Tarreauc7091d82019-05-17 10:08:49 +02001270 unsigned long old;
1271
1272 while (1) {
1273 old = 0;
1274 if (HA_ATOMIC_CAS(&threads_to_dump, &old, all_threads_mask))
1275 break;
1276 ha_thread_relax();
1277 }
1278
1279 thread_dump_buffer = &trash;
1280 thread_dump_tid = tid;
Willy Tarreaufade80d2019-05-22 08:46:59 +02001281 ha_tkillall(DEBUGSIG);
Willy Tarreauc7091d82019-05-17 10:08:49 +02001282}
1283
1284/* handles DEBUGSIG to dump the state of the thread it's working on */
1285void debug_handler(int sig, siginfo_t *si, void *arg)
1286{
Willy Tarreau82aafc42020-03-03 08:31:34 +01001287 /* first, let's check it's really for us and that we didn't just get
1288 * a spurious DEBUGSIG.
1289 */
1290 if (!(threads_to_dump & tid_bit))
1291 return;
1292
Willy Tarreauc7091d82019-05-17 10:08:49 +02001293 /* There are 4 phases in the dump process:
1294 * 1- wait for our turn, i.e. when all lower bits are gone.
1295 * 2- perform the action if our bit is set
1296 * 3- remove our bit to let the next one go, unless we're
Willy Tarreauc0773622019-07-31 19:15:45 +02001297 * the last one and have to put them all as a signal
1298 * 4- wait out bit to re-appear, then clear it and quit.
Willy Tarreauc7091d82019-05-17 10:08:49 +02001299 */
1300
1301 /* wait for all previous threads to finish first */
1302 while (threads_to_dump & (tid_bit - 1))
1303 ha_thread_relax();
1304
1305 /* dump if needed */
1306 if (threads_to_dump & tid_bit) {
1307 if (thread_dump_buffer)
1308 ha_thread_dump(thread_dump_buffer, tid, thread_dump_tid);
1309 if ((threads_to_dump & all_threads_mask) == tid_bit) {
1310 /* last one */
Willy Tarreauc0773622019-07-31 19:15:45 +02001311 HA_ATOMIC_STORE(&threads_to_dump, all_threads_mask);
Willy Tarreauc7091d82019-05-17 10:08:49 +02001312 thread_dump_buffer = NULL;
1313 }
1314 else
1315 HA_ATOMIC_AND(&threads_to_dump, ~tid_bit);
1316 }
1317
1318 /* now wait for all others to finish dumping. The last one will set all
Willy Tarreauc0773622019-07-31 19:15:45 +02001319 * bits again to broadcast the leaving condition so we'll see ourselves
1320 * present again. This way the threads_to_dump variable never passes to
1321 * zero until all visitors have stopped waiting.
Willy Tarreauc7091d82019-05-17 10:08:49 +02001322 */
Willy Tarreauc0773622019-07-31 19:15:45 +02001323 while (!(threads_to_dump & tid_bit))
1324 ha_thread_relax();
1325 HA_ATOMIC_AND(&threads_to_dump, ~tid_bit);
Willy Tarreaue6a02fa2019-05-22 07:06:44 +02001326
1327 /* mark the current thread as stuck to detect it upon next invocation
1328 * if it didn't move.
1329 */
1330 if (!((threads_harmless_mask|sleeping_thread_mask) & tid_bit))
1331 ti->flags |= TI_FL_STUCK;
Willy Tarreauc7091d82019-05-17 10:08:49 +02001332}
1333
1334static int init_debug_per_thread()
1335{
1336 sigset_t set;
1337
1338 /* unblock the DEBUGSIG signal we intend to use */
1339 sigemptyset(&set);
1340 sigaddset(&set, DEBUGSIG);
1341 ha_sigmask(SIG_UNBLOCK, &set, NULL);
1342 return 1;
1343}
1344
1345static int init_debug()
1346{
1347 struct sigaction sa;
Willy Tarreau2f1227e2021-01-22 12:12:29 +01001348 void *callers[1];
Willy Tarreauc7091d82019-05-17 10:08:49 +02001349
Willy Tarreau0214b452020-03-04 06:01:40 +01001350 /* calling backtrace() will access libgcc at runtime. We don't want to
1351 * do it after the chroot, so let's perform a first call to have it
1352 * ready in memory for later use.
1353 */
Willy Tarreau13faf162020-03-04 07:44:06 +01001354 my_backtrace(callers, sizeof(callers)/sizeof(*callers));
Willy Tarreauc7091d82019-05-17 10:08:49 +02001355 sa.sa_handler = NULL;
1356 sa.sa_sigaction = debug_handler;
1357 sigemptyset(&sa.sa_mask);
1358 sa.sa_flags = SA_SIGINFO;
1359 sigaction(DEBUGSIG, &sa, NULL);
Christopher Fauletfc633b62020-11-06 15:24:23 +01001360 return ERR_NONE;
Willy Tarreauc7091d82019-05-17 10:08:49 +02001361}
1362
1363REGISTER_POST_CHECK(init_debug);
1364REGISTER_PER_THREAD_INIT(init_debug_per_thread);
1365
1366#endif /* USE_THREAD_DUMP */
1367
Willy Tarreau4e2b6462019-05-16 17:44:30 +02001368/* register cli keywords */
1369static struct cli_kw_list cli_kws = {{ },{
Willy Tarreaub205bfd2021-05-07 11:38:37 +02001370 {{ "debug", "dev", "bug", NULL }, "debug dev bug : call BUG_ON() and crash", debug_parse_cli_bug, NULL, NULL, NULL, ACCESS_EXPERT },
1371 {{ "debug", "dev", "close", NULL }, "debug dev close <fd> : close this file descriptor", debug_parse_cli_close, NULL, NULL, NULL, ACCESS_EXPERT },
1372 {{ "debug", "dev", "delay", NULL }, "debug dev delay [ms] : sleep this long", debug_parse_cli_delay, NULL, NULL, NULL, ACCESS_EXPERT },
Willy Tarreau6bdf3e92019-05-20 14:25:05 +02001373#if defined(DEBUG_DEV)
Willy Tarreaub205bfd2021-05-07 11:38:37 +02001374 {{ "debug", "dev", "exec", NULL }, "debug dev exec [cmd] ... : show this command's output", debug_parse_cli_exec, NULL, NULL, NULL, ACCESS_EXPERT },
Willy Tarreau6bdf3e92019-05-20 14:25:05 +02001375#endif
Willy Tarreau476252b2022-01-24 20:26:09 +01001376 {{ "debug", "dev", "fd", NULL }, "debug dev fd : scan for rogue/unhandled FDs", debug_parse_cli_fd, debug_iohandler_fd, NULL, NULL, ACCESS_EXPERT },
Willy Tarreaub205bfd2021-05-07 11:38:37 +02001377 {{ "debug", "dev", "exit", NULL }, "debug dev exit [code] : immediately exit the process", debug_parse_cli_exit, NULL, NULL, NULL, ACCESS_EXPERT },
1378 {{ "debug", "dev", "hex", NULL }, "debug dev hex <addr> [len] : dump a memory area", debug_parse_cli_hex, NULL, NULL, NULL, ACCESS_EXPERT },
1379 {{ "debug", "dev", "log", NULL }, "debug dev log [msg] ... : send this msg to global logs", debug_parse_cli_log, NULL, NULL, NULL, ACCESS_EXPERT },
1380 {{ "debug", "dev", "loop", NULL }, "debug dev loop [ms] : loop this long", debug_parse_cli_loop, NULL, NULL, NULL, ACCESS_EXPERT },
Willy Tarreaua6026a02020-07-02 09:14:48 +02001381#if defined(DEBUG_MEM_STATS)
Willy Tarreaub205bfd2021-05-07 11:38:37 +02001382 {{ "debug", "dev", "memstats", NULL }, "debug dev memstats [reset|all] : dump/reset memory statistics", debug_parse_cli_memstats, debug_iohandler_memstats, NULL, NULL, ACCESS_EXPERT },
Willy Tarreaua6026a02020-07-02 09:14:48 +02001383#endif
Willy Tarreaub205bfd2021-05-07 11:38:37 +02001384 {{ "debug", "dev", "panic", NULL }, "debug dev panic : immediately trigger a panic", debug_parse_cli_panic, NULL, NULL, NULL, ACCESS_EXPERT },
1385 {{ "debug", "dev", "sched", NULL }, "debug dev sched {task|tasklet} [k=v]* : stress the scheduler", debug_parse_cli_sched, NULL, NULL, NULL, ACCESS_EXPERT },
1386 {{ "debug", "dev", "stream",NULL }, "debug dev stream [k=v]* : show/manipulate stream flags", debug_parse_cli_stream,NULL, NULL, NULL, ACCESS_EXPERT },
1387 {{ "debug", "dev", "sym", NULL }, "debug dev sym <addr> : resolve symbol address", debug_parse_cli_sym, NULL, NULL, NULL, ACCESS_EXPERT },
1388 {{ "debug", "dev", "tkill", NULL }, "debug dev tkill [thr] [sig] : send signal to thread", debug_parse_cli_tkill, NULL, NULL, NULL, ACCESS_EXPERT },
1389 {{ "debug", "dev", "write", NULL }, "debug dev write [size] : write that many bytes in return", debug_parse_cli_write, NULL, NULL, NULL, ACCESS_EXPERT },
Willy Tarreau37857332021-12-28 09:57:10 +01001390#if defined(HA_HAVE_DUMP_LIBS)
1391 {{ "show", "libs", NULL, NULL }, "show libs : show loaded object files and libraries", debug_parse_cli_show_libs, NULL, NULL },
1392#endif
Willy Tarreaub205bfd2021-05-07 11:38:37 +02001393 {{ "show", "threads", NULL, NULL }, "show threads : show some threads debugging information", NULL, cli_io_handler_show_threads, NULL },
Willy Tarreau4e2b6462019-05-16 17:44:30 +02001394 {{},}
1395}};
1396
1397INITCALL1(STG_REGISTER, cli_register_kw, &cli_kws);