blob: 1a1301c4faaf26309a46eaf4c34be7049f354539 [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 Tarreau78a7cb62019-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 Tarreaua37cb182019-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"
Olivier Houchard305d5ab2019-07-24 18:07:06 +020054 " stuck=%d prof=%d",
Willy Tarreaue6a02fa2019-05-22 07:06:44 +020055 (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),
Olivier Houchardff1e9f32019-09-20 17:18:35 +020060 !MT_LIST_ISEMPTY(&task_per_thread[thr].task_list),
Willy Tarreau4e2b6462019-05-16 17:44:30 +020061 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 !!(task_profiling_mask & thr_bit));
65
Willy Tarreau5cf64dd2019-05-17 10:36:08 +020066 chunk_appendf(buf,
Willy Tarreau4e2b6462019-05-16 17:44:30 +020067 " harmless=%d wantrdv=%d",
68 !!(threads_harmless_mask & thr_bit),
69 !!(threads_want_rdv_mask & thr_bit));
Willy Tarreau4e2b6462019-05-16 17:44:30 +020070
Willy Tarreau5cf64dd2019-05-17 10:36:08 +020071 chunk_appendf(buf, "\n");
Willy Tarreau9c8800a2019-05-20 20:52:20 +020072 chunk_appendf(buf, " cpu_ns: poll=%llu now=%llu diff=%llu\n", p, n, n-p);
Willy Tarreau4e2b6462019-05-16 17:44:30 +020073
74 /* this is the end of what we can dump from outside the thread */
75
76 if (thr != tid)
77 return;
78
Willy Tarreau5cf64dd2019-05-17 10:36:08 +020079 chunk_appendf(buf, " curr_task=");
Willy Tarreaud022e9c2019-09-24 08:25:15 +020080 ha_task_dump(buf, sched->current, " ");
Willy Tarreau4e2b6462019-05-16 17:44:30 +020081}
82
83
Willy Tarreau5cf64dd2019-05-17 10:36:08 +020084/* dumps into the buffer some information related to task <task> (which may
Willy Tarreau4e2b6462019-05-16 17:44:30 +020085 * either be a task or a tasklet, and prepend each line except the first one
Willy Tarreau5cf64dd2019-05-17 10:36:08 +020086 * with <pfx>. The buffer is only appended and the first output starts by the
87 * pointer itself. The caller is responsible for making sure the task is not
88 * going to vanish during the dump.
Willy Tarreau4e2b6462019-05-16 17:44:30 +020089 */
Willy Tarreau5cf64dd2019-05-17 10:36:08 +020090void ha_task_dump(struct buffer *buf, const struct task *task, const char *pfx)
Willy Tarreau4e2b6462019-05-16 17:44:30 +020091{
Willy Tarreau578ea8b2019-05-22 09:43:09 +020092 const struct stream *s = NULL;
Willy Tarreaua512b022019-08-21 14:12:19 +020093 const struct appctx __maybe_unused *appctx = NULL;
Willy Tarreau78a7cb62019-08-21 14:16:02 +020094 struct hlua __maybe_unused *hlua = NULL;
Willy Tarreau578ea8b2019-05-22 09:43:09 +020095
Willy Tarreau14a1ab72019-05-17 10:34:25 +020096 if (!task) {
Willy Tarreau5cf64dd2019-05-17 10:36:08 +020097 chunk_appendf(buf, "0\n");
Willy Tarreau231ec392019-05-17 10:39:47 +020098 return;
99 }
100
Willy Tarreau20db9112019-05-17 14:14:35 +0200101 if (TASK_IS_TASKLET(task))
102 chunk_appendf(buf,
103 "%p (tasklet) calls=%u\n",
104 task,
105 task->calls);
106 else
107 chunk_appendf(buf,
108 "%p (task) calls=%u last=%llu%s\n",
109 task,
110 task->calls,
111 task->call_date ? (unsigned long long)(now_mono_time() - task->call_date) : 0,
112 task->call_date ? " ns ago" : "");
Willy Tarreau4e2b6462019-05-16 17:44:30 +0200113
Willy Tarreau5cf64dd2019-05-17 10:36:08 +0200114 chunk_appendf(buf, "%s"
Willy Tarreaua512b022019-08-21 14:12:19 +0200115 " fct=%p (%s) ctx=%p",
Willy Tarreau4e2b6462019-05-16 17:44:30 +0200116 pfx,
Willy Tarreau14a1ab72019-05-17 10:34:25 +0200117 task->process,
118 task->process == process_stream ? "process_stream" :
119 task->process == task_run_applet ? "task_run_applet" :
120 task->process == si_cs_io_cb ? "si_cs_io_cb" :
Willy Tarreau78a7cb62019-08-21 14:16:02 +0200121#ifdef USE_LUA
122 task->process == hlua_process_task ? "hlua_process_task" :
123#endif
Willy Tarreau4e2b6462019-05-16 17:44:30 +0200124 "?",
Willy Tarreau14a1ab72019-05-17 10:34:25 +0200125 task->context);
Willy Tarreau578ea8b2019-05-22 09:43:09 +0200126
Willy Tarreaua512b022019-08-21 14:12:19 +0200127 if (task->process == task_run_applet && (appctx = task->context))
128 chunk_appendf(buf, "(%s)\n", appctx->applet->name);
129 else
130 chunk_appendf(buf, "\n");
131
Willy Tarreau578ea8b2019-05-22 09:43:09 +0200132 if (task->process == process_stream && task->context)
133 s = (struct stream *)task->context;
134 else if (task->process == task_run_applet && task->context)
135 s = si_strm(((struct appctx *)task->context)->owner);
136 else if (task->process == si_cs_io_cb && task->context)
137 s = si_strm((struct stream_interface *)task->context);
138
139 if (s)
140 stream_dump(buf, s, pfx, '\n');
Willy Tarreau78a7cb62019-08-21 14:16:02 +0200141
142#ifdef USE_LUA
143 hlua = NULL;
144 if (s && (hlua = s->hlua)) {
145 chunk_appendf(buf, "%sCurrent executing Lua from a stream analyser -- ", pfx);
146 }
147 else if (task->process == hlua_process_task && (hlua = task->context)) {
148 chunk_appendf(buf, "%sCurrent executing a Lua task -- ", pfx);
149 }
150 else if (task->process == task_run_applet && (appctx = task->context) &&
151 (appctx->applet->fct == hlua_applet_tcp_fct && (hlua = appctx->ctx.hlua_apptcp.hlua))) {
152 chunk_appendf(buf, "%sCurrent executing a Lua TCP service -- ", pfx);
153 }
154 else if (task->process == task_run_applet && (appctx = task->context) &&
155 (appctx->applet->fct == hlua_applet_http_fct && (hlua = appctx->ctx.hlua_apphttp.hlua))) {
156 chunk_appendf(buf, "%sCurrent executing a Lua HTTP service -- ", pfx);
157 }
158
159 if (hlua) {
160 luaL_traceback(hlua->T, hlua->T, NULL, 0);
161 if (!append_prefixed_str(buf, lua_tostring(hlua->T, -1), pfx, '\n', 1))
162 b_putchr(buf, '\n');
163 }
164#endif
Willy Tarreau4e2b6462019-05-16 17:44:30 +0200165}
166
Willy Tarreau4e2b6462019-05-16 17:44:30 +0200167/* This function dumps all profiling settings. It returns 0 if the output
168 * buffer is full and it needs to be called again, otherwise non-zero.
169 */
170static int cli_io_handler_show_threads(struct appctx *appctx)
171{
172 struct stream_interface *si = appctx->owner;
173 int thr;
174
175 if (unlikely(si_ic(si)->flags & (CF_WRITE_ERROR|CF_SHUTW)))
176 return 1;
177
178 if (appctx->st0)
179 thr = appctx->st1;
180 else
181 thr = 0;
182
Willy Tarreau5cf64dd2019-05-17 10:36:08 +0200183 chunk_reset(&trash);
Willy Tarreauc7091d82019-05-17 10:08:49 +0200184 ha_thread_dump_all_to_trash();
Willy Tarreau5cf64dd2019-05-17 10:36:08 +0200185
186 if (ci_putchk(si_ic(si), &trash) == -1) {
187 /* failed, try again */
188 si_rx_room_blk(si);
189 appctx->st1 = thr;
190 return 0;
191 }
Willy Tarreau4e2b6462019-05-16 17:44:30 +0200192 return 1;
193}
194
Willy Tarreau56131ca2019-05-20 13:48:29 +0200195/* dumps a state of all threads into the trash and on fd #2, then aborts. */
196void ha_panic()
197{
198 chunk_reset(&trash);
Willy Tarreaua9f9fc92019-05-20 17:45:35 +0200199 chunk_appendf(&trash, "Thread %u is about to kill the process.\n", tid + 1);
Willy Tarreau56131ca2019-05-20 13:48:29 +0200200 ha_thread_dump_all_to_trash();
Tim Duesterhusdda11552019-06-12 20:47:30 +0200201 shut_your_big_mouth_gcc(write(2, trash.area, trash.data));
Willy Tarreau56131ca2019-05-20 13:48:29 +0200202 for (;;)
203 abort();
204}
205
Willy Tarreau6bdf3e92019-05-20 14:25:05 +0200206#if defined(DEBUG_DEV)
207/* parse a "debug dev exit" command. It always returns 1, though it should never return. */
208static int debug_parse_cli_exit(char **args, char *payload, struct appctx *appctx, void *private)
209{
210 int code = atoi(args[3]);
211
212 if (!cli_has_level(appctx, ACCESS_LVL_ADMIN))
213 return 1;
214
215 exit(code);
216 return 1;
217}
218
219/* parse a "debug dev close" command. It always returns 1. */
220static int debug_parse_cli_close(char **args, char *payload, struct appctx *appctx, void *private)
221{
222 int fd;
223
224 if (!cli_has_level(appctx, ACCESS_LVL_ADMIN))
225 return 1;
226
Willy Tarreau9d008692019-08-09 11:21:01 +0200227 if (!*args[3])
228 return cli_err(appctx, "Missing file descriptor number.\n");
Willy Tarreau6bdf3e92019-05-20 14:25:05 +0200229
230 fd = atoi(args[3]);
Willy Tarreau9d008692019-08-09 11:21:01 +0200231 if (fd < 0 || fd >= global.maxsock)
232 return cli_err(appctx, "File descriptor out of range.\n");
Willy Tarreau6bdf3e92019-05-20 14:25:05 +0200233
Willy Tarreau9d008692019-08-09 11:21:01 +0200234 if (!fdtab[fd].owner)
235 return cli_msg(appctx, LOG_INFO, "File descriptor was already closed.\n");
Willy Tarreau6bdf3e92019-05-20 14:25:05 +0200236
237 fd_delete(fd);
238 return 1;
Willy Tarreau6bdf3e92019-05-20 14:25:05 +0200239}
240
241/* parse a "debug dev delay" command. It always returns 1. */
242static int debug_parse_cli_delay(char **args, char *payload, struct appctx *appctx, void *private)
243{
244 int delay = atoi(args[3]);
245
246 if (!cli_has_level(appctx, ACCESS_LVL_ADMIN))
247 return 1;
248
249 usleep((long)delay * 1000);
250 return 1;
251}
252
253/* parse a "debug dev log" command. It always returns 1. */
254static int debug_parse_cli_log(char **args, char *payload, struct appctx *appctx, void *private)
255{
256 int arg;
257
258 if (!cli_has_level(appctx, ACCESS_LVL_ADMIN))
259 return 1;
260
261 chunk_reset(&trash);
262 for (arg = 3; *args[arg]; arg++) {
263 if (arg > 3)
264 chunk_strcat(&trash, " ");
265 chunk_strcat(&trash, args[arg]);
266 }
267
268 send_log(NULL, LOG_INFO, "%s\n", trash.area);
269 return 1;
270}
271
272/* parse a "debug dev loop" command. It always returns 1. */
273static int debug_parse_cli_loop(char **args, char *payload, struct appctx *appctx, void *private)
274{
275 struct timeval deadline, curr;
276 int loop = atoi(args[3]);
277
278 if (!cli_has_level(appctx, ACCESS_LVL_ADMIN))
279 return 1;
280
281 gettimeofday(&curr, NULL);
282 tv_ms_add(&deadline, &curr, loop);
283
284 while (tv_ms_cmp(&curr, &deadline) < 0)
285 gettimeofday(&curr, NULL);
286
287 return 1;
288}
289
290/* parse a "debug dev panic" command. It always returns 1, though it should never return. */
291static int debug_parse_cli_panic(char **args, char *payload, struct appctx *appctx, void *private)
292{
293 if (!cli_has_level(appctx, ACCESS_LVL_ADMIN))
294 return 1;
295
296 ha_panic();
297 return 1;
298}
299
300/* parse a "debug dev exec" command. It always returns 1. */
301static int debug_parse_cli_exec(char **args, char *payload, struct appctx *appctx, void *private)
302{
303 FILE *f;
304 int arg;
305
306 if (!cli_has_level(appctx, ACCESS_LVL_ADMIN))
307 return 1;
308
309 chunk_reset(&trash);
310 for (arg = 3; *args[arg]; arg++) {
311 if (arg > 3)
312 chunk_strcat(&trash, " ");
313 chunk_strcat(&trash, args[arg]);
314 }
315
316 f = popen(trash.area, "re");
Willy Tarreau9d008692019-08-09 11:21:01 +0200317 if (!f)
318 return cli_err(appctx, "Failed to execute command.\n");
Willy Tarreau6bdf3e92019-05-20 14:25:05 +0200319
320 chunk_reset(&trash);
321 while (1) {
322 size_t ret = fread(trash.area + trash.data, 1, trash.size - 20 - trash.data, f);
323 if (!ret)
324 break;
325 trash.data += ret;
326 if (trash.data + 20 == trash.size) {
327 chunk_strcat(&trash, "\n[[[TRUNCATED]]]\n");
328 break;
329 }
330 }
331
332 fclose(f);
333 trash.area[trash.data] = 0;
Willy Tarreau9d008692019-08-09 11:21:01 +0200334 return cli_msg(appctx, LOG_INFO, trash.area);
Willy Tarreau6bdf3e92019-05-20 14:25:05 +0200335}
336
337/* parse a "debug dev hex" command. It always returns 1. */
338static int debug_parse_cli_hex(char **args, char *payload, struct appctx *appctx, void *private)
339{
340 unsigned long start, len;
341
342 if (!cli_has_level(appctx, ACCESS_LVL_ADMIN))
343 return 1;
344
Willy Tarreau9d008692019-08-09 11:21:01 +0200345 if (!*args[3])
346 return cli_err(appctx, "Missing memory address to dump from.\n");
Willy Tarreau6bdf3e92019-05-20 14:25:05 +0200347
348 start = strtoul(args[3], NULL, 0);
Willy Tarreau9d008692019-08-09 11:21:01 +0200349 if (!start)
350 return cli_err(appctx, "Will not dump from NULL address.\n");
Willy Tarreau6bdf3e92019-05-20 14:25:05 +0200351
352 /* by default, dump ~128 till next block of 16 */
353 len = strtoul(args[4], NULL, 0);
354 if (!len)
355 len = ((start + 128) & -16) - start;
356
357 chunk_reset(&trash);
Willy Tarreau37101052019-05-20 16:48:20 +0200358 dump_hex(&trash, " ", (const void *)start, len, 1);
Willy Tarreau6bdf3e92019-05-20 14:25:05 +0200359 trash.area[trash.data] = 0;
Willy Tarreau9d008692019-08-09 11:21:01 +0200360 return cli_msg(appctx, LOG_INFO, trash.area);
Willy Tarreau6bdf3e92019-05-20 14:25:05 +0200361}
362
363/* parse a "debug dev tkill" command. It always returns 1. */
364static int debug_parse_cli_tkill(char **args, char *payload, struct appctx *appctx, void *private)
365{
366 int thr = 0;
367 int sig = SIGABRT;
368
369 if (!cli_has_level(appctx, ACCESS_LVL_ADMIN))
370 return 1;
371
372 if (*args[3])
373 thr = atoi(args[3]);
374
Willy Tarreau9d008692019-08-09 11:21:01 +0200375 if (thr < 0 || thr > global.nbthread)
376 return cli_err(appctx, "Thread number out of range (use 0 for current).\n");
Willy Tarreau6bdf3e92019-05-20 14:25:05 +0200377
378 if (*args[4])
379 sig = atoi(args[4]);
380
Willy Tarreau6bdf3e92019-05-20 14:25:05 +0200381 if (thr)
Willy Tarreaufade80d2019-05-22 08:46:59 +0200382 ha_tkill(thr - 1, sig);
Willy Tarreau6bdf3e92019-05-20 14:25:05 +0200383 else
Willy Tarreau6bdf3e92019-05-20 14:25:05 +0200384 raise(sig);
385 return 1;
386}
387
388#endif
389
Willy Tarreauc7091d82019-05-17 10:08:49 +0200390#ifndef USE_THREAD_DUMP
391
392/* This function dumps all threads' state to the trash. This version is the
393 * most basic one, which doesn't inspect other threads.
394 */
395void ha_thread_dump_all_to_trash()
396{
397 unsigned int thr;
398
399 for (thr = 0; thr < global.nbthread; thr++)
400 ha_thread_dump(&trash, thr, tid);
401}
402
403#else /* below USE_THREAD_DUMP is set */
404
Willy Tarreauddd85332019-05-22 06:28:54 +0200405/* The signal to trigger a debug dump on a thread is SIGURG. It has the benefit
406 * of not stopping gdb by default, so that issuing "show threads" in a process
407 * being debugged has no adverse effect.
408 */
409#define DEBUGSIG SIGURG
Willy Tarreauc7091d82019-05-17 10:08:49 +0200410
Willy Tarreauc7091d82019-05-17 10:08:49 +0200411/* ID of the thread requesting the dump */
412static unsigned int thread_dump_tid;
413
414/* points to the buffer where the dump functions should write. It must
415 * have already been initialized by the requester. Nothing is done if
416 * it's NULL.
417 */
418struct buffer *thread_dump_buffer = NULL;
419
420void ha_thread_dump_all_to_trash()
421{
Willy Tarreauc7091d82019-05-17 10:08:49 +0200422 unsigned long old;
423
424 while (1) {
425 old = 0;
426 if (HA_ATOMIC_CAS(&threads_to_dump, &old, all_threads_mask))
427 break;
428 ha_thread_relax();
429 }
430
431 thread_dump_buffer = &trash;
432 thread_dump_tid = tid;
Willy Tarreaufade80d2019-05-22 08:46:59 +0200433 ha_tkillall(DEBUGSIG);
Willy Tarreauc7091d82019-05-17 10:08:49 +0200434}
435
436/* handles DEBUGSIG to dump the state of the thread it's working on */
437void debug_handler(int sig, siginfo_t *si, void *arg)
438{
439 /* There are 4 phases in the dump process:
440 * 1- wait for our turn, i.e. when all lower bits are gone.
441 * 2- perform the action if our bit is set
442 * 3- remove our bit to let the next one go, unless we're
Willy Tarreauc0773622019-07-31 19:15:45 +0200443 * the last one and have to put them all as a signal
444 * 4- wait out bit to re-appear, then clear it and quit.
Willy Tarreauc7091d82019-05-17 10:08:49 +0200445 */
446
447 /* wait for all previous threads to finish first */
448 while (threads_to_dump & (tid_bit - 1))
449 ha_thread_relax();
450
451 /* dump if needed */
452 if (threads_to_dump & tid_bit) {
453 if (thread_dump_buffer)
454 ha_thread_dump(thread_dump_buffer, tid, thread_dump_tid);
455 if ((threads_to_dump & all_threads_mask) == tid_bit) {
456 /* last one */
Willy Tarreauc0773622019-07-31 19:15:45 +0200457 HA_ATOMIC_STORE(&threads_to_dump, all_threads_mask);
Willy Tarreauc7091d82019-05-17 10:08:49 +0200458 thread_dump_buffer = NULL;
459 }
460 else
461 HA_ATOMIC_AND(&threads_to_dump, ~tid_bit);
462 }
463
464 /* now wait for all others to finish dumping. The last one will set all
Willy Tarreauc0773622019-07-31 19:15:45 +0200465 * bits again to broadcast the leaving condition so we'll see ourselves
466 * present again. This way the threads_to_dump variable never passes to
467 * zero until all visitors have stopped waiting.
Willy Tarreauc7091d82019-05-17 10:08:49 +0200468 */
Willy Tarreauc0773622019-07-31 19:15:45 +0200469 while (!(threads_to_dump & tid_bit))
470 ha_thread_relax();
471 HA_ATOMIC_AND(&threads_to_dump, ~tid_bit);
Willy Tarreaue6a02fa2019-05-22 07:06:44 +0200472
473 /* mark the current thread as stuck to detect it upon next invocation
474 * if it didn't move.
475 */
476 if (!((threads_harmless_mask|sleeping_thread_mask) & tid_bit))
477 ti->flags |= TI_FL_STUCK;
Willy Tarreauc7091d82019-05-17 10:08:49 +0200478}
479
480static int init_debug_per_thread()
481{
482 sigset_t set;
483
484 /* unblock the DEBUGSIG signal we intend to use */
485 sigemptyset(&set);
486 sigaddset(&set, DEBUGSIG);
487 ha_sigmask(SIG_UNBLOCK, &set, NULL);
488 return 1;
489}
490
491static int init_debug()
492{
493 struct sigaction sa;
494
495 sa.sa_handler = NULL;
496 sa.sa_sigaction = debug_handler;
497 sigemptyset(&sa.sa_mask);
498 sa.sa_flags = SA_SIGINFO;
499 sigaction(DEBUGSIG, &sa, NULL);
500 return 0;
501}
502
503REGISTER_POST_CHECK(init_debug);
504REGISTER_PER_THREAD_INIT(init_debug_per_thread);
505
506#endif /* USE_THREAD_DUMP */
507
Willy Tarreau4e2b6462019-05-16 17:44:30 +0200508/* register cli keywords */
509static struct cli_kw_list cli_kws = {{ },{
Willy Tarreau6bdf3e92019-05-20 14:25:05 +0200510#if defined(DEBUG_DEV)
511 {{ "debug", "dev", "close", NULL }, "debug dev close <fd> : close this file descriptor", debug_parse_cli_close, NULL },
512 {{ "debug", "dev", "delay", NULL }, "debug dev delay [ms] : sleep this long", debug_parse_cli_delay, NULL },
513 {{ "debug", "dev", "exec", NULL }, "debug dev exec [cmd] ... : show this command's output", debug_parse_cli_exec, NULL },
514 {{ "debug", "dev", "exit", NULL }, "debug dev exit [code] : immediately exit the process", debug_parse_cli_exit, NULL },
515 {{ "debug", "dev", "hex", NULL }, "debug dev hex <addr> [len]: dump a memory area", debug_parse_cli_hex, NULL },
516 {{ "debug", "dev", "log", NULL }, "debug dev log [msg] ... : send this msg to global logs", debug_parse_cli_log, NULL },
517 {{ "debug", "dev", "loop", NULL }, "debug dev loop [ms] : loop this long", debug_parse_cli_loop, NULL },
518 {{ "debug", "dev", "panic", NULL }, "debug dev panic : immediately trigger a panic", debug_parse_cli_panic, NULL },
519 {{ "debug", "dev", "tkill", NULL }, "debug dev tkill [thr] [sig] : send signal to thread", debug_parse_cli_tkill, NULL },
520#endif
Willy Tarreau4e2b6462019-05-16 17:44:30 +0200521 { { "show", "threads", NULL }, "show threads : show some threads debugging information", NULL, cli_io_handler_show_threads, NULL },
522 {{},}
523}};
524
525INITCALL1(STG_REGISTER, cli_register_kw, &cli_kws);