blob: 16b7b1d8cd2cfc75a7edc736ef6188634bd07e44 [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
13#include <signal.h>
14#include <time.h>
15#include <stdio.h>
Willy Tarreau6bdf3e92019-05-20 14:25:05 +020016#include <stdlib.h>
Willy Tarreau4e2b6462019-05-16 17:44:30 +020017
Willy Tarreau5cf64dd2019-05-17 10:36:08 +020018#include <common/buf.h>
Willy Tarreau4e2b6462019-05-16 17:44:30 +020019#include <common/config.h>
20#include <common/debug.h>
21#include <common/hathreads.h>
22#include <common/initcall.h>
23#include <common/standard.h>
24
25#include <types/global.h>
26
27#include <proto/cli.h>
28#include <proto/fd.h>
Willy Tarreau4856b362019-08-21 14:16:02 +020029#include <proto/hlua.h>
Willy Tarreau4e2b6462019-05-16 17:44:30 +020030#include <proto/stream_interface.h>
31#include <proto/task.h>
32
Willy Tarreau445b2b72019-07-31 19:20:39 +020033/* mask of threads still having to dump, used to respect ordering. Only used
34 * when USE_THREAD_DUMP is set.
35 */
36volatile unsigned long threads_to_dump = 0;
37
Willy Tarreau5cf64dd2019-05-17 10:36:08 +020038/* Dumps to the buffer some known information for the desired thread, and
39 * optionally extra info for the current thread. The dump will be appended to
40 * the buffer, so the caller is responsible for preliminary initializing it.
41 * The calling thread ID needs to be passed in <calling_tid> to display a star
Willy Tarreaue6a02fa2019-05-22 07:06:44 +020042 * in front of the calling thread's line (usually it's tid). Any stuck thread
43 * is also prefixed with a '>'.
Willy Tarreau4e2b6462019-05-16 17:44:30 +020044 */
Willy Tarreau5cf64dd2019-05-17 10:36:08 +020045void ha_thread_dump(struct buffer *buf, int thr, int calling_tid)
Willy Tarreau4e2b6462019-05-16 17:44:30 +020046{
47 unsigned long thr_bit = 1UL << thr;
Willy Tarreau9c8800a2019-05-20 20:52:20 +020048 unsigned long long p = thread_info[thr].prev_cpu_time;
49 unsigned long long n = now_cpu_time_thread(&thread_info[thr]);
Willy Tarreaue6a02fa2019-05-22 07:06:44 +020050 int stuck = !!(thread_info[thr].flags & TI_FL_STUCK);
Willy Tarreau4e2b6462019-05-16 17:44:30 +020051
Willy Tarreau5cf64dd2019-05-17 10:36:08 +020052 chunk_appendf(buf,
Willy Tarreaue6a02fa2019-05-22 07:06:44 +020053 "%c%cThread %-2u: act=%d glob=%d wq=%d rq=%d tl=%d tlsz=%d rqsz=%d\n"
54 " stuck=%d fdcache=%d prof=%d",
55 (thr == calling_tid) ? '*' : ' ', stuck ? '>' : ' ', thr + 1,
Olivier Houchardcfbb3e62019-05-29 19:22:43 +020056 thread_has_tasks(),
Willy Tarreau4e2b6462019-05-16 17:44:30 +020057 !!(global_tasks_mask & thr_bit),
58 !eb_is_empty(&task_per_thread[thr].timers),
59 !eb_is_empty(&task_per_thread[thr].rqueue),
60 !LIST_ISEMPTY(&task_per_thread[thr].task_list),
61 task_per_thread[thr].task_list_size,
62 task_per_thread[thr].rqueue_size,
Willy Tarreaue6a02fa2019-05-22 07:06:44 +020063 stuck,
Willy Tarreau4e2b6462019-05-16 17:44:30 +020064 !!(fd_cache_mask & thr_bit),
65 !!(task_profiling_mask & thr_bit));
66
Willy Tarreau5cf64dd2019-05-17 10:36:08 +020067 chunk_appendf(buf,
Willy Tarreau4e2b6462019-05-16 17:44:30 +020068 " harmless=%d wantrdv=%d",
69 !!(threads_harmless_mask & thr_bit),
70 !!(threads_want_rdv_mask & thr_bit));
Willy Tarreau4e2b6462019-05-16 17:44:30 +020071
Willy Tarreau5cf64dd2019-05-17 10:36:08 +020072 chunk_appendf(buf, "\n");
Willy Tarreau9c8800a2019-05-20 20:52:20 +020073 chunk_appendf(buf, " cpu_ns: poll=%llu now=%llu diff=%llu\n", p, n, n-p);
Willy Tarreau4e2b6462019-05-16 17:44:30 +020074
75 /* this is the end of what we can dump from outside the thread */
76
77 if (thr != tid)
78 return;
79
Willy Tarreau5cf64dd2019-05-17 10:36:08 +020080 chunk_appendf(buf, " curr_task=");
81 ha_task_dump(buf, curr_task, " ");
Willy Tarreau4e2b6462019-05-16 17:44:30 +020082}
83
84
Willy Tarreau5cf64dd2019-05-17 10:36:08 +020085/* dumps into the buffer some information related to task <task> (which may
Willy Tarreau4e2b6462019-05-16 17:44:30 +020086 * either be a task or a tasklet, and prepend each line except the first one
Willy Tarreau5cf64dd2019-05-17 10:36:08 +020087 * with <pfx>. The buffer is only appended and the first output starts by the
88 * pointer itself. The caller is responsible for making sure the task is not
89 * going to vanish during the dump.
Willy Tarreau4e2b6462019-05-16 17:44:30 +020090 */
Willy Tarreau5cf64dd2019-05-17 10:36:08 +020091void ha_task_dump(struct buffer *buf, const struct task *task, const char *pfx)
Willy Tarreau4e2b6462019-05-16 17:44:30 +020092{
Willy Tarreau578ea8b2019-05-22 09:43:09 +020093 const struct stream *s = NULL;
Willy Tarreau3a761682019-08-21 14:12:19 +020094 const struct appctx __maybe_unused *appctx = NULL;
Willy Tarreau4856b362019-08-21 14:16:02 +020095 struct hlua __maybe_unused *hlua = NULL;
Willy Tarreau578ea8b2019-05-22 09:43:09 +020096
Willy Tarreau14a1ab72019-05-17 10:34:25 +020097 if (!task) {
Willy Tarreau5cf64dd2019-05-17 10:36:08 +020098 chunk_appendf(buf, "0\n");
Willy Tarreau231ec392019-05-17 10:39:47 +020099 return;
100 }
101
Willy Tarreau20db9112019-05-17 14:14:35 +0200102 if (TASK_IS_TASKLET(task))
103 chunk_appendf(buf,
104 "%p (tasklet) calls=%u\n",
105 task,
106 task->calls);
107 else
108 chunk_appendf(buf,
109 "%p (task) calls=%u last=%llu%s\n",
110 task,
111 task->calls,
112 task->call_date ? (unsigned long long)(now_mono_time() - task->call_date) : 0,
113 task->call_date ? " ns ago" : "");
Willy Tarreau4e2b6462019-05-16 17:44:30 +0200114
Willy Tarreau5cf64dd2019-05-17 10:36:08 +0200115 chunk_appendf(buf, "%s"
Willy Tarreaud4f00f72020-03-03 07:04:42 +0100116 " fct=%p=main%s%ld (%s) ctx=%p",
Willy Tarreau4e2b6462019-05-16 17:44:30 +0200117 pfx,
Willy Tarreau14a1ab72019-05-17 10:34:25 +0200118 task->process,
Willy Tarreaud4f00f72020-03-03 07:04:42 +0100119 ((void *)task->process - (void *)main) < 0 ? "" : "+",
120 (long)((void *)task->process - (void *)main),
Willy Tarreau14a1ab72019-05-17 10:34:25 +0200121 task->process == process_stream ? "process_stream" :
122 task->process == task_run_applet ? "task_run_applet" :
123 task->process == si_cs_io_cb ? "si_cs_io_cb" :
Willy Tarreau4856b362019-08-21 14:16:02 +0200124#ifdef USE_LUA
125 task->process == hlua_process_task ? "hlua_process_task" :
126#endif
Willy Tarreau4e2b6462019-05-16 17:44:30 +0200127 "?",
Willy Tarreau14a1ab72019-05-17 10:34:25 +0200128 task->context);
Willy Tarreau578ea8b2019-05-22 09:43:09 +0200129
Willy Tarreau3a761682019-08-21 14:12:19 +0200130 if (task->process == task_run_applet && (appctx = task->context))
131 chunk_appendf(buf, "(%s)\n", appctx->applet->name);
132 else
133 chunk_appendf(buf, "\n");
134
Willy Tarreau578ea8b2019-05-22 09:43:09 +0200135 if (task->process == process_stream && task->context)
136 s = (struct stream *)task->context;
137 else if (task->process == task_run_applet && task->context)
138 s = si_strm(((struct appctx *)task->context)->owner);
139 else if (task->process == si_cs_io_cb && task->context)
140 s = si_strm((struct stream_interface *)task->context);
141
142 if (s)
143 stream_dump(buf, s, pfx, '\n');
Willy Tarreau4856b362019-08-21 14:16:02 +0200144
145#ifdef USE_LUA
146 hlua = NULL;
147 if (s && (hlua = s->hlua)) {
148 chunk_appendf(buf, "%sCurrent executing Lua from a stream analyser -- ", pfx);
149 }
150 else if (task->process == hlua_process_task && (hlua = task->context)) {
151 chunk_appendf(buf, "%sCurrent executing a Lua task -- ", pfx);
152 }
153 else if (task->process == task_run_applet && (appctx = task->context) &&
154 (appctx->applet->fct == hlua_applet_tcp_fct && (hlua = appctx->ctx.hlua_apptcp.hlua))) {
155 chunk_appendf(buf, "%sCurrent executing a Lua TCP service -- ", pfx);
156 }
157 else if (task->process == task_run_applet && (appctx = task->context) &&
158 (appctx->applet->fct == hlua_applet_http_fct && (hlua = appctx->ctx.hlua_apphttp.hlua))) {
159 chunk_appendf(buf, "%sCurrent executing a Lua HTTP service -- ", pfx);
160 }
161
162 if (hlua) {
163 luaL_traceback(hlua->T, hlua->T, NULL, 0);
164 if (!append_prefixed_str(buf, lua_tostring(hlua->T, -1), pfx, '\n', 1))
165 b_putchr(buf, '\n');
166 }
167#endif
Willy Tarreau4e2b6462019-05-16 17:44:30 +0200168}
169
Willy Tarreau4e2b6462019-05-16 17:44:30 +0200170/* This function dumps all profiling settings. It returns 0 if the output
171 * buffer is full and it needs to be called again, otherwise non-zero.
172 */
173static int cli_io_handler_show_threads(struct appctx *appctx)
174{
175 struct stream_interface *si = appctx->owner;
176 int thr;
177
178 if (unlikely(si_ic(si)->flags & (CF_WRITE_ERROR|CF_SHUTW)))
179 return 1;
180
181 if (appctx->st0)
182 thr = appctx->st1;
183 else
184 thr = 0;
185
Willy Tarreau5cf64dd2019-05-17 10:36:08 +0200186 chunk_reset(&trash);
Willy Tarreauc7091d82019-05-17 10:08:49 +0200187 ha_thread_dump_all_to_trash();
Willy Tarreau5cf64dd2019-05-17 10:36:08 +0200188
189 if (ci_putchk(si_ic(si), &trash) == -1) {
190 /* failed, try again */
191 si_rx_room_blk(si);
192 appctx->st1 = thr;
193 return 0;
194 }
Willy Tarreau4e2b6462019-05-16 17:44:30 +0200195 return 1;
196}
197
Willy Tarreau56131ca2019-05-20 13:48:29 +0200198/* dumps a state of all threads into the trash and on fd #2, then aborts. */
199void ha_panic()
200{
201 chunk_reset(&trash);
Willy Tarreaua9f9fc92019-05-20 17:45:35 +0200202 chunk_appendf(&trash, "Thread %u is about to kill the process.\n", tid + 1);
Willy Tarreau56131ca2019-05-20 13:48:29 +0200203 ha_thread_dump_all_to_trash();
Tim Duesterhusdda11552019-06-12 20:47:30 +0200204 shut_your_big_mouth_gcc(write(2, trash.area, trash.data));
Willy Tarreau56131ca2019-05-20 13:48:29 +0200205 for (;;)
206 abort();
207}
208
Willy Tarreau6bdf3e92019-05-20 14:25:05 +0200209#if defined(DEBUG_DEV)
210/* parse a "debug dev exit" command. It always returns 1, though it should never return. */
211static int debug_parse_cli_exit(char **args, char *payload, struct appctx *appctx, void *private)
212{
213 int code = atoi(args[3]);
214
215 if (!cli_has_level(appctx, ACCESS_LVL_ADMIN))
216 return 1;
217
218 exit(code);
219 return 1;
220}
221
222/* parse a "debug dev close" command. It always returns 1. */
223static int debug_parse_cli_close(char **args, char *payload, struct appctx *appctx, void *private)
224{
225 int fd;
226
227 if (!cli_has_level(appctx, ACCESS_LVL_ADMIN))
228 return 1;
229
230 if (!*args[3]) {
231 appctx->ctx.cli.msg = "Missing file descriptor number.\n";
232 goto reterr;
233 }
234
235 fd = atoi(args[3]);
236 if (fd < 0 || fd >= global.maxsock) {
237 appctx->ctx.cli.msg = "File descriptor out of range.\n";
238 goto reterr;
239 }
240
241 if (!fdtab[fd].owner) {
242 appctx->ctx.cli.msg = "File descriptor was already closed.\n";
243 goto retinfo;
244 }
245
246 fd_delete(fd);
247 return 1;
248 retinfo:
249 appctx->ctx.cli.severity = LOG_INFO;
250 appctx->st0 = CLI_ST_PRINT;
251 return 1;
252 reterr:
253 appctx->ctx.cli.severity = LOG_ERR;
254 appctx->st0 = CLI_ST_PRINT;
255 return 1;
256}
257
258/* parse a "debug dev delay" command. It always returns 1. */
259static int debug_parse_cli_delay(char **args, char *payload, struct appctx *appctx, void *private)
260{
261 int delay = atoi(args[3]);
262
263 if (!cli_has_level(appctx, ACCESS_LVL_ADMIN))
264 return 1;
265
266 usleep((long)delay * 1000);
267 return 1;
268}
269
270/* parse a "debug dev log" command. It always returns 1. */
271static int debug_parse_cli_log(char **args, char *payload, struct appctx *appctx, void *private)
272{
273 int arg;
274
275 if (!cli_has_level(appctx, ACCESS_LVL_ADMIN))
276 return 1;
277
278 chunk_reset(&trash);
279 for (arg = 3; *args[arg]; arg++) {
280 if (arg > 3)
281 chunk_strcat(&trash, " ");
282 chunk_strcat(&trash, args[arg]);
283 }
284
285 send_log(NULL, LOG_INFO, "%s\n", trash.area);
286 return 1;
287}
288
289/* parse a "debug dev loop" command. It always returns 1. */
290static int debug_parse_cli_loop(char **args, char *payload, struct appctx *appctx, void *private)
291{
292 struct timeval deadline, curr;
293 int loop = atoi(args[3]);
294
295 if (!cli_has_level(appctx, ACCESS_LVL_ADMIN))
296 return 1;
297
298 gettimeofday(&curr, NULL);
299 tv_ms_add(&deadline, &curr, loop);
300
301 while (tv_ms_cmp(&curr, &deadline) < 0)
302 gettimeofday(&curr, NULL);
303
304 return 1;
305}
306
307/* parse a "debug dev panic" command. It always returns 1, though it should never return. */
308static int debug_parse_cli_panic(char **args, char *payload, struct appctx *appctx, void *private)
309{
310 if (!cli_has_level(appctx, ACCESS_LVL_ADMIN))
311 return 1;
312
313 ha_panic();
314 return 1;
315}
316
317/* parse a "debug dev exec" command. It always returns 1. */
318static int debug_parse_cli_exec(char **args, char *payload, struct appctx *appctx, void *private)
319{
320 FILE *f;
321 int arg;
322
323 if (!cli_has_level(appctx, ACCESS_LVL_ADMIN))
324 return 1;
325
326 chunk_reset(&trash);
327 for (arg = 3; *args[arg]; arg++) {
328 if (arg > 3)
329 chunk_strcat(&trash, " ");
330 chunk_strcat(&trash, args[arg]);
331 }
332
333 f = popen(trash.area, "re");
334 if (!f) {
335 appctx->ctx.cli.severity = LOG_ERR;
336 appctx->ctx.cli.msg = "Failed to execute command.\n";
337 appctx->st0 = CLI_ST_PRINT;
338 return 1;
339 }
340
341 chunk_reset(&trash);
342 while (1) {
343 size_t ret = fread(trash.area + trash.data, 1, trash.size - 20 - trash.data, f);
344 if (!ret)
345 break;
346 trash.data += ret;
347 if (trash.data + 20 == trash.size) {
348 chunk_strcat(&trash, "\n[[[TRUNCATED]]]\n");
349 break;
350 }
351 }
352
353 fclose(f);
354 trash.area[trash.data] = 0;
355 appctx->ctx.cli.severity = LOG_INFO;
356 appctx->ctx.cli.msg = trash.area;
357 appctx->st0 = CLI_ST_PRINT;
358 return 1;
359}
360
361/* parse a "debug dev hex" command. It always returns 1. */
362static int debug_parse_cli_hex(char **args, char *payload, struct appctx *appctx, void *private)
363{
364 unsigned long start, len;
365
366 if (!cli_has_level(appctx, ACCESS_LVL_ADMIN))
367 return 1;
368
369 if (!*args[3]) {
370 appctx->ctx.cli.msg = "Missing memory address to dump from.\n";
371 goto reterr;
372 }
373
374 start = strtoul(args[3], NULL, 0);
375 if (!start) {
376 appctx->ctx.cli.msg = "Will not dump from NULL address.\n";
377 goto reterr;
378 }
379
380 /* by default, dump ~128 till next block of 16 */
381 len = strtoul(args[4], NULL, 0);
382 if (!len)
383 len = ((start + 128) & -16) - start;
384
385 chunk_reset(&trash);
Willy Tarreau37101052019-05-20 16:48:20 +0200386 dump_hex(&trash, " ", (const void *)start, len, 1);
Willy Tarreau6bdf3e92019-05-20 14:25:05 +0200387 trash.area[trash.data] = 0;
388 appctx->ctx.cli.severity = LOG_INFO;
389 appctx->ctx.cli.msg = trash.area;
390 appctx->st0 = CLI_ST_PRINT;
391 return 1;
392 reterr:
393 appctx->ctx.cli.severity = LOG_ERR;
394 appctx->st0 = CLI_ST_PRINT;
395 return 1;
396}
397
398/* parse a "debug dev tkill" command. It always returns 1. */
399static int debug_parse_cli_tkill(char **args, char *payload, struct appctx *appctx, void *private)
400{
401 int thr = 0;
402 int sig = SIGABRT;
403
404 if (!cli_has_level(appctx, ACCESS_LVL_ADMIN))
405 return 1;
406
407 if (*args[3])
408 thr = atoi(args[3]);
409
410 if (thr < 0 || thr > global.nbthread) {
411 appctx->ctx.cli.severity = LOG_ERR;
412 appctx->ctx.cli.msg = "Thread number out of range (use 0 for current).\n";
413 appctx->st0 = CLI_ST_PRINT;
414 return 1;
415 }
416
417 if (*args[4])
418 sig = atoi(args[4]);
419
Willy Tarreau6bdf3e92019-05-20 14:25:05 +0200420 if (thr)
Willy Tarreaufade80d2019-05-22 08:46:59 +0200421 ha_tkill(thr - 1, sig);
Willy Tarreau6bdf3e92019-05-20 14:25:05 +0200422 else
Willy Tarreau6bdf3e92019-05-20 14:25:05 +0200423 raise(sig);
424 return 1;
425}
426
427#endif
428
Willy Tarreauc7091d82019-05-17 10:08:49 +0200429#ifndef USE_THREAD_DUMP
430
431/* This function dumps all threads' state to the trash. This version is the
432 * most basic one, which doesn't inspect other threads.
433 */
434void ha_thread_dump_all_to_trash()
435{
436 unsigned int thr;
437
438 for (thr = 0; thr < global.nbthread; thr++)
439 ha_thread_dump(&trash, thr, tid);
440}
441
442#else /* below USE_THREAD_DUMP is set */
443
Willy Tarreauddd85332019-05-22 06:28:54 +0200444/* The signal to trigger a debug dump on a thread is SIGURG. It has the benefit
445 * of not stopping gdb by default, so that issuing "show threads" in a process
446 * being debugged has no adverse effect.
447 */
448#define DEBUGSIG SIGURG
Willy Tarreauc7091d82019-05-17 10:08:49 +0200449
Willy Tarreauc7091d82019-05-17 10:08:49 +0200450/* ID of the thread requesting the dump */
451static unsigned int thread_dump_tid;
452
453/* points to the buffer where the dump functions should write. It must
454 * have already been initialized by the requester. Nothing is done if
455 * it's NULL.
456 */
457struct buffer *thread_dump_buffer = NULL;
458
459void ha_thread_dump_all_to_trash()
460{
Willy Tarreauc7091d82019-05-17 10:08:49 +0200461 unsigned long old;
462
463 while (1) {
464 old = 0;
465 if (HA_ATOMIC_CAS(&threads_to_dump, &old, all_threads_mask))
466 break;
467 ha_thread_relax();
468 }
469
470 thread_dump_buffer = &trash;
471 thread_dump_tid = tid;
Willy Tarreaufade80d2019-05-22 08:46:59 +0200472 ha_tkillall(DEBUGSIG);
Willy Tarreauc7091d82019-05-17 10:08:49 +0200473}
474
475/* handles DEBUGSIG to dump the state of the thread it's working on */
476void debug_handler(int sig, siginfo_t *si, void *arg)
477{
Willy Tarreaubce97b42020-03-03 08:31:34 +0100478 /* first, let's check it's really for us and that we didn't just get
479 * a spurious DEBUGSIG.
480 */
481 if (!(threads_to_dump & tid_bit))
482 return;
483
Willy Tarreauc7091d82019-05-17 10:08:49 +0200484 /* There are 4 phases in the dump process:
485 * 1- wait for our turn, i.e. when all lower bits are gone.
486 * 2- perform the action if our bit is set
487 * 3- remove our bit to let the next one go, unless we're
Willy Tarreauda767ea2019-07-31 19:15:45 +0200488 * the last one and have to put them all as a signal
489 * 4- wait out bit to re-appear, then clear it and quit.
Willy Tarreauc7091d82019-05-17 10:08:49 +0200490 */
491
492 /* wait for all previous threads to finish first */
493 while (threads_to_dump & (tid_bit - 1))
494 ha_thread_relax();
495
496 /* dump if needed */
497 if (threads_to_dump & tid_bit) {
498 if (thread_dump_buffer)
499 ha_thread_dump(thread_dump_buffer, tid, thread_dump_tid);
500 if ((threads_to_dump & all_threads_mask) == tid_bit) {
501 /* last one */
Willy Tarreauda767ea2019-07-31 19:15:45 +0200502 HA_ATOMIC_STORE(&threads_to_dump, all_threads_mask);
Willy Tarreauc7091d82019-05-17 10:08:49 +0200503 thread_dump_buffer = NULL;
504 }
505 else
506 HA_ATOMIC_AND(&threads_to_dump, ~tid_bit);
507 }
508
509 /* now wait for all others to finish dumping. The last one will set all
Willy Tarreauda767ea2019-07-31 19:15:45 +0200510 * bits again to broadcast the leaving condition so we'll see ourselves
511 * present again. This way the threads_to_dump variable never passes to
512 * zero until all visitors have stopped waiting.
Willy Tarreauc7091d82019-05-17 10:08:49 +0200513 */
Willy Tarreauda767ea2019-07-31 19:15:45 +0200514 while (!(threads_to_dump & tid_bit))
515 ha_thread_relax();
516 HA_ATOMIC_AND(&threads_to_dump, ~tid_bit);
Willy Tarreaue6a02fa2019-05-22 07:06:44 +0200517
518 /* mark the current thread as stuck to detect it upon next invocation
519 * if it didn't move.
520 */
521 if (!((threads_harmless_mask|sleeping_thread_mask) & tid_bit))
522 ti->flags |= TI_FL_STUCK;
Willy Tarreauc7091d82019-05-17 10:08:49 +0200523}
524
525static int init_debug_per_thread()
526{
527 sigset_t set;
528
529 /* unblock the DEBUGSIG signal we intend to use */
530 sigemptyset(&set);
531 sigaddset(&set, DEBUGSIG);
532 ha_sigmask(SIG_UNBLOCK, &set, NULL);
533 return 1;
534}
535
536static int init_debug()
537{
538 struct sigaction sa;
539
540 sa.sa_handler = NULL;
541 sa.sa_sigaction = debug_handler;
542 sigemptyset(&sa.sa_mask);
543 sa.sa_flags = SA_SIGINFO;
544 sigaction(DEBUGSIG, &sa, NULL);
545 return 0;
546}
547
548REGISTER_POST_CHECK(init_debug);
549REGISTER_PER_THREAD_INIT(init_debug_per_thread);
550
551#endif /* USE_THREAD_DUMP */
552
Willy Tarreau4e2b6462019-05-16 17:44:30 +0200553/* register cli keywords */
554static struct cli_kw_list cli_kws = {{ },{
Willy Tarreau6bdf3e92019-05-20 14:25:05 +0200555#if defined(DEBUG_DEV)
556 {{ "debug", "dev", "close", NULL }, "debug dev close <fd> : close this file descriptor", debug_parse_cli_close, NULL },
557 {{ "debug", "dev", "delay", NULL }, "debug dev delay [ms] : sleep this long", debug_parse_cli_delay, NULL },
558 {{ "debug", "dev", "exec", NULL }, "debug dev exec [cmd] ... : show this command's output", debug_parse_cli_exec, NULL },
559 {{ "debug", "dev", "exit", NULL }, "debug dev exit [code] : immediately exit the process", debug_parse_cli_exit, NULL },
560 {{ "debug", "dev", "hex", NULL }, "debug dev hex <addr> [len]: dump a memory area", debug_parse_cli_hex, NULL },
561 {{ "debug", "dev", "log", NULL }, "debug dev log [msg] ... : send this msg to global logs", debug_parse_cli_log, NULL },
562 {{ "debug", "dev", "loop", NULL }, "debug dev loop [ms] : loop this long", debug_parse_cli_loop, NULL },
563 {{ "debug", "dev", "panic", NULL }, "debug dev panic : immediately trigger a panic", debug_parse_cli_panic, NULL },
564 {{ "debug", "dev", "tkill", NULL }, "debug dev tkill [thr] [sig] : send signal to thread", debug_parse_cli_tkill, NULL },
565#endif
Willy Tarreau4e2b6462019-05-16 17:44:30 +0200566 { { "show", "threads", NULL }, "show threads : show some threads debugging information", NULL, cli_io_handler_show_threads, NULL },
567 {{},}
568}};
569
570INITCALL1(STG_REGISTER, cli_register_kw, &cli_kws);