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