Willy Tarreau | 4e2b646 | 2019-05-16 17:44:30 +0200 | [diff] [blame] | 1 | /* |
| 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 Tarreau | f5b4e06 | 2020-03-03 15:40:23 +0100 | [diff] [blame] | 13 | |
Willy Tarreau | 5be7c19 | 2022-01-24 20:26:09 +0100 | [diff] [blame] | 14 | #include <errno.h> |
Willy Tarreau | 368bff4 | 2019-12-06 17:18:28 +0100 | [diff] [blame] | 15 | #include <fcntl.h> |
Willy Tarreau | 4e2b646 | 2019-05-16 17:44:30 +0200 | [diff] [blame] | 16 | #include <signal.h> |
| 17 | #include <time.h> |
| 18 | #include <stdio.h> |
Willy Tarreau | 6bdf3e9 | 2019-05-20 14:25:05 +0200 | [diff] [blame] | 19 | #include <stdlib.h> |
Willy Tarreau | aeed4a8 | 2020-06-04 22:01:04 +0200 | [diff] [blame] | 20 | #include <syslog.h> |
Willy Tarreau | 5be7c19 | 2022-01-24 20:26:09 +0100 | [diff] [blame] | 21 | #include <sys/stat.h> |
Willy Tarreau | 368bff4 | 2019-12-06 17:18:28 +0100 | [diff] [blame] | 22 | #include <sys/types.h> |
| 23 | #include <sys/wait.h> |
Willy Tarreau | 5be7c19 | 2022-01-24 20:26:09 +0100 | [diff] [blame] | 24 | #include <unistd.h> |
| 25 | #ifdef USE_EPOLL |
| 26 | #include <sys/epoll.h> |
| 27 | #endif |
Willy Tarreau | 4e2b646 | 2019-05-16 17:44:30 +0200 | [diff] [blame] | 28 | |
Willy Tarreau | 4c7e4b7 | 2020-05-27 12:58:42 +0200 | [diff] [blame] | 29 | #include <haproxy/api.h> |
Willy Tarreau | 8dabda7 | 2020-05-27 17:22:10 +0200 | [diff] [blame] | 30 | #include <haproxy/buf.h> |
Willy Tarreau | 83487a8 | 2020-06-04 20:19:54 +0200 | [diff] [blame] | 31 | #include <haproxy/cli.h> |
Willy Tarreau | 5554264 | 2021-10-08 09:33:24 +0200 | [diff] [blame] | 32 | #include <haproxy/clock.h> |
Willy Tarreau | 2a83d60 | 2020-05-27 16:58:08 +0200 | [diff] [blame] | 33 | #include <haproxy/debug.h> |
Willy Tarreau | b255105 | 2020-06-09 09:07:15 +0200 | [diff] [blame] | 34 | #include <haproxy/fd.h> |
| 35 | #include <haproxy/global.h> |
Willy Tarreau | 8641605 | 2020-06-04 09:20:54 +0200 | [diff] [blame] | 36 | #include <haproxy/hlua.h> |
Willy Tarreau | b7fc4c4 | 2021-10-06 18:56:42 +0200 | [diff] [blame] | 37 | #include <haproxy/http_ana.h> |
Willy Tarreau | aeed4a8 | 2020-06-04 22:01:04 +0200 | [diff] [blame] | 38 | #include <haproxy/log.h> |
Willy Tarreau | b255105 | 2020-06-09 09:07:15 +0200 | [diff] [blame] | 39 | #include <haproxy/net_helper.h> |
Willy Tarreau | 5e539c9 | 2020-06-04 20:45:39 +0200 | [diff] [blame] | 40 | #include <haproxy/stream_interface.h> |
Willy Tarreau | cea0e1b | 2020-06-04 17:25:40 +0200 | [diff] [blame] | 41 | #include <haproxy/task.h> |
Willy Tarreau | 3f567e4 | 2020-05-28 15:29:19 +0200 | [diff] [blame] | 42 | #include <haproxy/thread.h> |
Willy Tarreau | 5554264 | 2021-10-08 09:33:24 +0200 | [diff] [blame] | 43 | #include <haproxy/time.h> |
Willy Tarreau | 48fbcae | 2020-06-03 18:09:46 +0200 | [diff] [blame] | 44 | #include <haproxy/tools.h> |
Willy Tarreau | b255105 | 2020-06-09 09:07:15 +0200 | [diff] [blame] | 45 | #include <import/ist.h> |
Willy Tarreau | 4e2b646 | 2019-05-16 17:44:30 +0200 | [diff] [blame] | 46 | |
Willy Tarreau | 4e2b646 | 2019-05-16 17:44:30 +0200 | [diff] [blame] | 47 | |
Willy Tarreau | a37cb18 | 2019-07-31 19:20:39 +0200 | [diff] [blame] | 48 | /* mask of threads still having to dump, used to respect ordering. Only used |
| 49 | * when USE_THREAD_DUMP is set. |
| 50 | */ |
| 51 | volatile unsigned long threads_to_dump = 0; |
Willy Tarreau | 9b01370 | 2019-10-24 18:18:02 +0200 | [diff] [blame] | 52 | unsigned int debug_commands_issued = 0; |
Willy Tarreau | a37cb18 | 2019-07-31 19:20:39 +0200 | [diff] [blame] | 53 | |
Willy Tarreau | 123fc97 | 2021-01-22 13:52:41 +0100 | [diff] [blame] | 54 | /* dumps a backtrace of the current thread that is appended to buffer <buf>. |
| 55 | * Lines are prefixed with the string <prefix> which may be empty (used for |
| 56 | * indenting). It is recommended to use this at a function's tail so that |
Willy Tarreau | 2bfce7e | 2021-01-22 14:48:34 +0100 | [diff] [blame] | 57 | * the function does not appear in the call stack. The <dump> argument |
| 58 | * indicates what dump state to start from, and should usually be zero. It |
| 59 | * may be among the following values: |
| 60 | * - 0: search usual callers before step 1, or directly jump to 2 |
| 61 | * - 1: skip usual callers before step 2 |
| 62 | * - 2: dump until polling loop, scheduler, or main() (excluded) |
| 63 | * - 3: end |
| 64 | * - 4-7: like 0 but stops *after* main. |
Willy Tarreau | 123fc97 | 2021-01-22 13:52:41 +0100 | [diff] [blame] | 65 | */ |
Willy Tarreau | 2bfce7e | 2021-01-22 14:48:34 +0100 | [diff] [blame] | 66 | void ha_dump_backtrace(struct buffer *buf, const char *prefix, int dump) |
Willy Tarreau | 123fc97 | 2021-01-22 13:52:41 +0100 | [diff] [blame] | 67 | { |
| 68 | struct buffer bak; |
| 69 | char pfx2[100]; |
| 70 | void *callers[100]; |
| 71 | int j, nptrs; |
| 72 | const void *addr; |
Willy Tarreau | 123fc97 | 2021-01-22 13:52:41 +0100 | [diff] [blame] | 73 | |
| 74 | nptrs = my_backtrace(callers, sizeof(callers)/sizeof(*callers)); |
| 75 | if (!nptrs) |
| 76 | return; |
| 77 | |
| 78 | if (snprintf(pfx2, sizeof(pfx2), "%s| ", prefix) > sizeof(pfx2)) |
| 79 | pfx2[0] = 0; |
| 80 | |
| 81 | /* The call backtrace_symbols_fd(callers, nptrs, STDOUT_FILENO would |
| 82 | * produce similar output to the following: |
| 83 | */ |
| 84 | chunk_appendf(buf, "%scall trace(%d):\n", prefix, nptrs); |
Willy Tarreau | 2bfce7e | 2021-01-22 14:48:34 +0100 | [diff] [blame] | 85 | for (j = 0; (j < nptrs || (dump & 3) < 2); j++) { |
| 86 | if (j == nptrs && !(dump & 3)) { |
Willy Tarreau | 123fc97 | 2021-01-22 13:52:41 +0100 | [diff] [blame] | 87 | /* we failed to spot the starting point of the |
| 88 | * dump, let's start over dumping everything we |
| 89 | * have. |
| 90 | */ |
Willy Tarreau | 2bfce7e | 2021-01-22 14:48:34 +0100 | [diff] [blame] | 91 | dump += 2; |
Willy Tarreau | 123fc97 | 2021-01-22 13:52:41 +0100 | [diff] [blame] | 92 | j = 0; |
| 93 | } |
| 94 | bak = *buf; |
| 95 | dump_addr_and_bytes(buf, pfx2, callers[j], 8); |
| 96 | addr = resolve_sym_name(buf, ": ", callers[j]); |
Willy Tarreau | 2bfce7e | 2021-01-22 14:48:34 +0100 | [diff] [blame] | 97 | if ((dump & 3) == 0) { |
Willy Tarreau | 123fc97 | 2021-01-22 13:52:41 +0100 | [diff] [blame] | 98 | /* dump not started, will start *after* |
Willy Tarreau | a8459b2 | 2021-01-22 14:12:27 +0100 | [diff] [blame] | 99 | * ha_thread_dump_all_to_trash, ha_panic and ha_backtrace_to_stderr |
Willy Tarreau | 123fc97 | 2021-01-22 13:52:41 +0100 | [diff] [blame] | 100 | */ |
Willy Tarreau | a8459b2 | 2021-01-22 14:12:27 +0100 | [diff] [blame] | 101 | if (addr == ha_thread_dump_all_to_trash || addr == ha_panic || |
| 102 | addr == ha_backtrace_to_stderr) |
Willy Tarreau | 2bfce7e | 2021-01-22 14:48:34 +0100 | [diff] [blame] | 103 | dump++; |
Willy Tarreau | 123fc97 | 2021-01-22 13:52:41 +0100 | [diff] [blame] | 104 | *buf = bak; |
| 105 | continue; |
| 106 | } |
| 107 | |
Willy Tarreau | 2bfce7e | 2021-01-22 14:48:34 +0100 | [diff] [blame] | 108 | if ((dump & 3) == 1) { |
Willy Tarreau | 123fc97 | 2021-01-22 13:52:41 +0100 | [diff] [blame] | 109 | /* starting */ |
Willy Tarreau | a8459b2 | 2021-01-22 14:12:27 +0100 | [diff] [blame] | 110 | if (addr == ha_thread_dump_all_to_trash || addr == ha_panic || |
| 111 | addr == ha_backtrace_to_stderr) { |
Willy Tarreau | 123fc97 | 2021-01-22 13:52:41 +0100 | [diff] [blame] | 112 | *buf = bak; |
| 113 | continue; |
| 114 | } |
Willy Tarreau | 2bfce7e | 2021-01-22 14:48:34 +0100 | [diff] [blame] | 115 | dump++; |
Willy Tarreau | 123fc97 | 2021-01-22 13:52:41 +0100 | [diff] [blame] | 116 | } |
| 117 | |
Willy Tarreau | 2bfce7e | 2021-01-22 14:48:34 +0100 | [diff] [blame] | 118 | if ((dump & 3) == 2) { |
| 119 | /* still dumping */ |
| 120 | if (dump == 6) { |
| 121 | /* we only stop *after* main and we must send the LF */ |
| 122 | if (addr == main) { |
| 123 | j = nptrs; |
| 124 | dump++; |
| 125 | } |
| 126 | } |
| 127 | else if (addr == run_poll_loop || addr == main || addr == run_tasks_from_lists) { |
| 128 | dump++; |
Willy Tarreau | 123fc97 | 2021-01-22 13:52:41 +0100 | [diff] [blame] | 129 | *buf = bak; |
| 130 | break; |
| 131 | } |
| 132 | } |
| 133 | /* OK, line dumped */ |
| 134 | chunk_appendf(buf, "\n"); |
| 135 | } |
| 136 | } |
| 137 | |
Willy Tarreau | a8459b2 | 2021-01-22 14:12:27 +0100 | [diff] [blame] | 138 | /* dump a backtrace of current thread's stack to stderr. */ |
| 139 | void ha_backtrace_to_stderr() |
| 140 | { |
| 141 | char area[2048]; |
| 142 | struct buffer b = b_make(area, sizeof(area), 0, 0); |
| 143 | |
Willy Tarreau | 2bfce7e | 2021-01-22 14:48:34 +0100 | [diff] [blame] | 144 | ha_dump_backtrace(&b, " ", 4); |
Willy Tarreau | a8459b2 | 2021-01-22 14:12:27 +0100 | [diff] [blame] | 145 | if (b.data) |
Willy Tarreau | 2cbe2e7 | 2021-01-22 15:58:26 +0100 | [diff] [blame] | 146 | DISGUISE(write(2, b.area, b.data)); |
Willy Tarreau | a8459b2 | 2021-01-22 14:12:27 +0100 | [diff] [blame] | 147 | } |
| 148 | |
Willy Tarreau | 5cf64dd | 2019-05-17 10:36:08 +0200 | [diff] [blame] | 149 | /* Dumps to the buffer some known information for the desired thread, and |
| 150 | * optionally extra info for the current thread. The dump will be appended to |
| 151 | * the buffer, so the caller is responsible for preliminary initializing it. |
| 152 | * The calling thread ID needs to be passed in <calling_tid> to display a star |
Willy Tarreau | e6a02fa | 2019-05-22 07:06:44 +0200 | [diff] [blame] | 153 | * in front of the calling thread's line (usually it's tid). Any stuck thread |
| 154 | * is also prefixed with a '>'. |
Willy Tarreau | 4e2b646 | 2019-05-16 17:44:30 +0200 | [diff] [blame] | 155 | */ |
Willy Tarreau | 5cf64dd | 2019-05-17 10:36:08 +0200 | [diff] [blame] | 156 | void ha_thread_dump(struct buffer *buf, int thr, int calling_tid) |
Willy Tarreau | 4e2b646 | 2019-05-16 17:44:30 +0200 | [diff] [blame] | 157 | { |
| 158 | unsigned long thr_bit = 1UL << thr; |
Willy Tarreau | 45c38e2 | 2021-09-30 18:28:49 +0200 | [diff] [blame] | 159 | unsigned long long p = ha_thread_ctx[thr].prev_cpu_time; |
Willy Tarreau | 2169498 | 2021-10-08 15:09:17 +0200 | [diff] [blame] | 160 | unsigned long long n = now_cpu_time_thread(thr); |
Willy Tarreau | a0b9953 | 2021-09-30 18:48:37 +0200 | [diff] [blame] | 161 | int stuck = !!(ha_thread_ctx[thr].flags & TH_FL_STUCK); |
Willy Tarreau | 4e2b646 | 2019-05-16 17:44:30 +0200 | [diff] [blame] | 162 | |
Willy Tarreau | 5cf64dd | 2019-05-17 10:36:08 +0200 | [diff] [blame] | 163 | chunk_appendf(buf, |
Willy Tarreau | f0e5da2 | 2020-05-01 12:26:03 +0200 | [diff] [blame] | 164 | "%c%cThread %-2u: id=0x%llx act=%d glob=%d wq=%d rq=%d tl=%d tlsz=%d rqsz=%d\n" |
Willy Tarreau | a3870b7 | 2021-09-13 19:24:47 +0200 | [diff] [blame] | 165 | " %2u/%-2u stuck=%d prof=%d", |
Willy Tarreau | e6a02fa | 2019-05-22 07:06:44 +0200 | [diff] [blame] | 166 | (thr == calling_tid) ? '*' : ' ', stuck ? '>' : ' ', thr + 1, |
Willy Tarreau | ff64d3b | 2020-05-01 11:28:49 +0200 | [diff] [blame] | 167 | ha_get_pthread_id(thr), |
Olivier Houchard | cfbb3e6 | 2019-05-29 19:22:43 +0200 | [diff] [blame] | 168 | thread_has_tasks(), |
Willy Tarreau | 4e2b646 | 2019-05-16 17:44:30 +0200 | [diff] [blame] | 169 | !!(global_tasks_mask & thr_bit), |
Willy Tarreau | 1a9c922 | 2021-10-01 11:30:33 +0200 | [diff] [blame] | 170 | !eb_is_empty(&ha_thread_ctx[thr].timers), |
| 171 | !eb_is_empty(&ha_thread_ctx[thr].rqueue), |
| 172 | !(LIST_ISEMPTY(&ha_thread_ctx[thr].tasklets[TL_URGENT]) && |
| 173 | LIST_ISEMPTY(&ha_thread_ctx[thr].tasklets[TL_NORMAL]) && |
| 174 | LIST_ISEMPTY(&ha_thread_ctx[thr].tasklets[TL_BULK]) && |
| 175 | MT_LIST_ISEMPTY(&ha_thread_ctx[thr].shared_tasklet_list)), |
| 176 | ha_thread_ctx[thr].tasks_in_list, |
| 177 | ha_thread_ctx[thr].rq_total, |
Willy Tarreau | a3870b7 | 2021-09-13 19:24:47 +0200 | [diff] [blame] | 178 | ha_thread_info[thr].tg->tgid, ha_thread_info[thr].ltid + 1, |
Willy Tarreau | e6a02fa | 2019-05-22 07:06:44 +0200 | [diff] [blame] | 179 | stuck, |
Willy Tarreau | 4e2b646 | 2019-05-16 17:44:30 +0200 | [diff] [blame] | 180 | !!(task_profiling_mask & thr_bit)); |
| 181 | |
Willy Tarreau | 5cf64dd | 2019-05-17 10:36:08 +0200 | [diff] [blame] | 182 | chunk_appendf(buf, |
Willy Tarreau | 4e2b646 | 2019-05-16 17:44:30 +0200 | [diff] [blame] | 183 | " harmless=%d wantrdv=%d", |
| 184 | !!(threads_harmless_mask & thr_bit), |
| 185 | !!(threads_want_rdv_mask & thr_bit)); |
Willy Tarreau | 4e2b646 | 2019-05-16 17:44:30 +0200 | [diff] [blame] | 186 | |
Willy Tarreau | 5cf64dd | 2019-05-17 10:36:08 +0200 | [diff] [blame] | 187 | chunk_appendf(buf, "\n"); |
Willy Tarreau | 9c8800a | 2019-05-20 20:52:20 +0200 | [diff] [blame] | 188 | chunk_appendf(buf, " cpu_ns: poll=%llu now=%llu diff=%llu\n", p, n, n-p); |
Willy Tarreau | 4e2b646 | 2019-05-16 17:44:30 +0200 | [diff] [blame] | 189 | |
Willy Tarreau | a3870b7 | 2021-09-13 19:24:47 +0200 | [diff] [blame] | 190 | /* this is the end of what we can dump from outside the current thread */ |
Willy Tarreau | 4e2b646 | 2019-05-16 17:44:30 +0200 | [diff] [blame] | 191 | |
| 192 | if (thr != tid) |
| 193 | return; |
| 194 | |
Willy Tarreau | 5cf64dd | 2019-05-17 10:36:08 +0200 | [diff] [blame] | 195 | chunk_appendf(buf, " curr_task="); |
Willy Tarreau | 1a9c922 | 2021-10-01 11:30:33 +0200 | [diff] [blame] | 196 | ha_task_dump(buf, th_ctx->current, " "); |
Willy Tarreau | f5b4e06 | 2020-03-03 15:40:23 +0100 | [diff] [blame] | 197 | |
Willy Tarreau | f5b4e06 | 2020-03-03 15:40:23 +0100 | [diff] [blame] | 198 | if (stuck) { |
| 199 | /* We only emit the backtrace for stuck threads in order not to |
| 200 | * waste precious output buffer space with non-interesting data. |
Willy Tarreau | 123fc97 | 2021-01-22 13:52:41 +0100 | [diff] [blame] | 201 | * Please leave this as the last instruction in this function |
| 202 | * so that the compiler uses tail merging and the current |
| 203 | * function does not appear in the stack. |
Willy Tarreau | f5b4e06 | 2020-03-03 15:40:23 +0100 | [diff] [blame] | 204 | */ |
Willy Tarreau | 2bfce7e | 2021-01-22 14:48:34 +0100 | [diff] [blame] | 205 | ha_dump_backtrace(buf, " ", 0); |
Willy Tarreau | f5b4e06 | 2020-03-03 15:40:23 +0100 | [diff] [blame] | 206 | } |
Willy Tarreau | 4e2b646 | 2019-05-16 17:44:30 +0200 | [diff] [blame] | 207 | } |
| 208 | |
| 209 | |
Willy Tarreau | 5cf64dd | 2019-05-17 10:36:08 +0200 | [diff] [blame] | 210 | /* dumps into the buffer some information related to task <task> (which may |
Willy Tarreau | 4e2b646 | 2019-05-16 17:44:30 +0200 | [diff] [blame] | 211 | * either be a task or a tasklet, and prepend each line except the first one |
Willy Tarreau | 5cf64dd | 2019-05-17 10:36:08 +0200 | [diff] [blame] | 212 | * with <pfx>. The buffer is only appended and the first output starts by the |
| 213 | * pointer itself. The caller is responsible for making sure the task is not |
| 214 | * going to vanish during the dump. |
Willy Tarreau | 4e2b646 | 2019-05-16 17:44:30 +0200 | [diff] [blame] | 215 | */ |
Willy Tarreau | 5cf64dd | 2019-05-17 10:36:08 +0200 | [diff] [blame] | 216 | void ha_task_dump(struct buffer *buf, const struct task *task, const char *pfx) |
Willy Tarreau | 4e2b646 | 2019-05-16 17:44:30 +0200 | [diff] [blame] | 217 | { |
Willy Tarreau | 578ea8b | 2019-05-22 09:43:09 +0200 | [diff] [blame] | 218 | const struct stream *s = NULL; |
Willy Tarreau | a512b02 | 2019-08-21 14:12:19 +0200 | [diff] [blame] | 219 | const struct appctx __maybe_unused *appctx = NULL; |
Willy Tarreau | 78a7cb6 | 2019-08-21 14:16:02 +0200 | [diff] [blame] | 220 | struct hlua __maybe_unused *hlua = NULL; |
Willy Tarreau | 578ea8b | 2019-05-22 09:43:09 +0200 | [diff] [blame] | 221 | |
Willy Tarreau | 14a1ab7 | 2019-05-17 10:34:25 +0200 | [diff] [blame] | 222 | if (!task) { |
Willy Tarreau | 5cf64dd | 2019-05-17 10:36:08 +0200 | [diff] [blame] | 223 | chunk_appendf(buf, "0\n"); |
Willy Tarreau | 231ec39 | 2019-05-17 10:39:47 +0200 | [diff] [blame] | 224 | return; |
| 225 | } |
| 226 | |
Willy Tarreau | 20db911 | 2019-05-17 14:14:35 +0200 | [diff] [blame] | 227 | if (TASK_IS_TASKLET(task)) |
| 228 | chunk_appendf(buf, |
| 229 | "%p (tasklet) calls=%u\n", |
| 230 | task, |
| 231 | task->calls); |
| 232 | else |
| 233 | chunk_appendf(buf, |
| 234 | "%p (task) calls=%u last=%llu%s\n", |
| 235 | task, |
| 236 | task->calls, |
| 237 | task->call_date ? (unsigned long long)(now_mono_time() - task->call_date) : 0, |
| 238 | task->call_date ? " ns ago" : ""); |
Willy Tarreau | 4e2b646 | 2019-05-16 17:44:30 +0200 | [diff] [blame] | 239 | |
Willy Tarreau | 2e89b09 | 2020-03-03 17:13:02 +0100 | [diff] [blame] | 240 | chunk_appendf(buf, "%s fct=%p(", pfx, task->process); |
| 241 | resolve_sym_name(buf, NULL, task->process); |
| 242 | chunk_appendf(buf,") ctx=%p", task->context); |
Willy Tarreau | 578ea8b | 2019-05-22 09:43:09 +0200 | [diff] [blame] | 243 | |
Willy Tarreau | a512b02 | 2019-08-21 14:12:19 +0200 | [diff] [blame] | 244 | if (task->process == task_run_applet && (appctx = task->context)) |
| 245 | chunk_appendf(buf, "(%s)\n", appctx->applet->name); |
| 246 | else |
| 247 | chunk_appendf(buf, "\n"); |
| 248 | |
Willy Tarreau | 578ea8b | 2019-05-22 09:43:09 +0200 | [diff] [blame] | 249 | if (task->process == process_stream && task->context) |
| 250 | s = (struct stream *)task->context; |
| 251 | else if (task->process == task_run_applet && task->context) |
Christopher Faulet | 86e1c33 | 2021-12-20 17:09:39 +0100 | [diff] [blame] | 252 | s = si_strm(cs_si(((struct appctx *)task->context)->owner)); |
Willy Tarreau | 578ea8b | 2019-05-22 09:43:09 +0200 | [diff] [blame] | 253 | else if (task->process == si_cs_io_cb && task->context) |
| 254 | s = si_strm((struct stream_interface *)task->context); |
| 255 | |
| 256 | if (s) |
| 257 | stream_dump(buf, s, pfx, '\n'); |
Willy Tarreau | 78a7cb6 | 2019-08-21 14:16:02 +0200 | [diff] [blame] | 258 | |
| 259 | #ifdef USE_LUA |
| 260 | hlua = NULL; |
| 261 | if (s && (hlua = s->hlua)) { |
| 262 | chunk_appendf(buf, "%sCurrent executing Lua from a stream analyser -- ", pfx); |
| 263 | } |
| 264 | else if (task->process == hlua_process_task && (hlua = task->context)) { |
| 265 | chunk_appendf(buf, "%sCurrent executing a Lua task -- ", pfx); |
| 266 | } |
| 267 | else if (task->process == task_run_applet && (appctx = task->context) && |
| 268 | (appctx->applet->fct == hlua_applet_tcp_fct && (hlua = appctx->ctx.hlua_apptcp.hlua))) { |
| 269 | chunk_appendf(buf, "%sCurrent executing a Lua TCP service -- ", pfx); |
| 270 | } |
| 271 | else if (task->process == task_run_applet && (appctx = task->context) && |
| 272 | (appctx->applet->fct == hlua_applet_http_fct && (hlua = appctx->ctx.hlua_apphttp.hlua))) { |
| 273 | chunk_appendf(buf, "%sCurrent executing a Lua HTTP service -- ", pfx); |
| 274 | } |
| 275 | |
Christopher Faulet | 471425f | 2020-07-24 19:08:05 +0200 | [diff] [blame] | 276 | if (hlua && hlua->T) { |
Christopher Faulet | cc2c4f8 | 2021-03-24 14:52:24 +0100 | [diff] [blame] | 277 | chunk_appendf(buf, "stack traceback:\n "); |
| 278 | append_prefixed_str(buf, hlua_traceback(hlua->T, "\n "), pfx, '\n', 0); |
| 279 | b_putchr(buf, '\n'); |
Willy Tarreau | 78a7cb6 | 2019-08-21 14:16:02 +0200 | [diff] [blame] | 280 | } |
Christopher Faulet | 471425f | 2020-07-24 19:08:05 +0200 | [diff] [blame] | 281 | else |
| 282 | b_putchr(buf, '\n'); |
Willy Tarreau | 78a7cb6 | 2019-08-21 14:16:02 +0200 | [diff] [blame] | 283 | #endif |
Willy Tarreau | 4e2b646 | 2019-05-16 17:44:30 +0200 | [diff] [blame] | 284 | } |
| 285 | |
Willy Tarreau | 4e2b646 | 2019-05-16 17:44:30 +0200 | [diff] [blame] | 286 | /* This function dumps all profiling settings. It returns 0 if the output |
| 287 | * buffer is full and it needs to be called again, otherwise non-zero. |
| 288 | */ |
| 289 | static int cli_io_handler_show_threads(struct appctx *appctx) |
| 290 | { |
Christopher Faulet | 86e1c33 | 2021-12-20 17:09:39 +0100 | [diff] [blame] | 291 | struct stream_interface *si = cs_si(appctx->owner); |
Willy Tarreau | 4e2b646 | 2019-05-16 17:44:30 +0200 | [diff] [blame] | 292 | int thr; |
| 293 | |
| 294 | if (unlikely(si_ic(si)->flags & (CF_WRITE_ERROR|CF_SHUTW))) |
| 295 | return 1; |
| 296 | |
| 297 | if (appctx->st0) |
| 298 | thr = appctx->st1; |
| 299 | else |
| 300 | thr = 0; |
| 301 | |
Willy Tarreau | 5cf64dd | 2019-05-17 10:36:08 +0200 | [diff] [blame] | 302 | chunk_reset(&trash); |
Willy Tarreau | c7091d8 | 2019-05-17 10:08:49 +0200 | [diff] [blame] | 303 | ha_thread_dump_all_to_trash(); |
Willy Tarreau | 5cf64dd | 2019-05-17 10:36:08 +0200 | [diff] [blame] | 304 | |
| 305 | if (ci_putchk(si_ic(si), &trash) == -1) { |
| 306 | /* failed, try again */ |
| 307 | si_rx_room_blk(si); |
| 308 | appctx->st1 = thr; |
| 309 | return 0; |
| 310 | } |
Willy Tarreau | 4e2b646 | 2019-05-16 17:44:30 +0200 | [diff] [blame] | 311 | return 1; |
| 312 | } |
| 313 | |
Willy Tarreau | 6ab7b21 | 2021-12-28 09:57:10 +0100 | [diff] [blame] | 314 | #if defined(HA_HAVE_DUMP_LIBS) |
| 315 | /* parse a "show libs" command. It returns 1 if it emits anything otherwise zero. */ |
| 316 | static int debug_parse_cli_show_libs(char **args, char *payload, struct appctx *appctx, void *private) |
| 317 | { |
| 318 | if (!cli_has_level(appctx, ACCESS_LVL_OPER)) |
| 319 | return 1; |
| 320 | |
| 321 | chunk_reset(&trash); |
| 322 | if (dump_libs(&trash, 1)) |
| 323 | return cli_msg(appctx, LOG_INFO, trash.area); |
| 324 | else |
| 325 | return 0; |
| 326 | } |
| 327 | #endif |
| 328 | |
Willy Tarreau | 56131ca | 2019-05-20 13:48:29 +0200 | [diff] [blame] | 329 | /* dumps a state of all threads into the trash and on fd #2, then aborts. */ |
| 330 | void ha_panic() |
| 331 | { |
| 332 | chunk_reset(&trash); |
Willy Tarreau | a9f9fc9 | 2019-05-20 17:45:35 +0200 | [diff] [blame] | 333 | chunk_appendf(&trash, "Thread %u is about to kill the process.\n", tid + 1); |
Willy Tarreau | 56131ca | 2019-05-20 13:48:29 +0200 | [diff] [blame] | 334 | ha_thread_dump_all_to_trash(); |
Willy Tarreau | 2e8ab6b | 2020-03-14 11:03:20 +0100 | [diff] [blame] | 335 | DISGUISE(write(2, trash.area, trash.data)); |
Willy Tarreau | 56131ca | 2019-05-20 13:48:29 +0200 | [diff] [blame] | 336 | for (;;) |
| 337 | abort(); |
| 338 | } |
| 339 | |
Willy Tarreau | 6bdf3e9 | 2019-05-20 14:25:05 +0200 | [diff] [blame] | 340 | /* parse a "debug dev exit" command. It always returns 1, though it should never return. */ |
| 341 | static int debug_parse_cli_exit(char **args, char *payload, struct appctx *appctx, void *private) |
| 342 | { |
| 343 | int code = atoi(args[3]); |
| 344 | |
| 345 | if (!cli_has_level(appctx, ACCESS_LVL_ADMIN)) |
| 346 | return 1; |
| 347 | |
Willy Tarreau | 4781b15 | 2021-04-06 13:53:36 +0200 | [diff] [blame] | 348 | _HA_ATOMIC_INC(&debug_commands_issued); |
Willy Tarreau | 6bdf3e9 | 2019-05-20 14:25:05 +0200 | [diff] [blame] | 349 | exit(code); |
| 350 | return 1; |
| 351 | } |
| 352 | |
Willy Tarreau | 5baf4fe | 2021-01-22 14:15:46 +0100 | [diff] [blame] | 353 | /* parse a "debug dev bug" command. It always returns 1, though it should never return. |
| 354 | * Note: we make sure not to make the function static so that it appears in the trace. |
| 355 | */ |
| 356 | int debug_parse_cli_bug(char **args, char *payload, struct appctx *appctx, void *private) |
| 357 | { |
| 358 | if (!cli_has_level(appctx, ACCESS_LVL_ADMIN)) |
| 359 | return 1; |
| 360 | |
Willy Tarreau | 4781b15 | 2021-04-06 13:53:36 +0200 | [diff] [blame] | 361 | _HA_ATOMIC_INC(&debug_commands_issued); |
Willy Tarreau | 5baf4fe | 2021-01-22 14:15:46 +0100 | [diff] [blame] | 362 | BUG_ON(one > zero); |
| 363 | return 1; |
| 364 | } |
| 365 | |
Willy Tarreau | 6bdf3e9 | 2019-05-20 14:25:05 +0200 | [diff] [blame] | 366 | /* parse a "debug dev close" command. It always returns 1. */ |
| 367 | static int debug_parse_cli_close(char **args, char *payload, struct appctx *appctx, void *private) |
| 368 | { |
| 369 | int fd; |
| 370 | |
| 371 | if (!cli_has_level(appctx, ACCESS_LVL_ADMIN)) |
| 372 | return 1; |
| 373 | |
Willy Tarreau | 9d00869 | 2019-08-09 11:21:01 +0200 | [diff] [blame] | 374 | if (!*args[3]) |
| 375 | return cli_err(appctx, "Missing file descriptor number.\n"); |
Willy Tarreau | 6bdf3e9 | 2019-05-20 14:25:05 +0200 | [diff] [blame] | 376 | |
| 377 | fd = atoi(args[3]); |
Willy Tarreau | 9d00869 | 2019-08-09 11:21:01 +0200 | [diff] [blame] | 378 | if (fd < 0 || fd >= global.maxsock) |
| 379 | return cli_err(appctx, "File descriptor out of range.\n"); |
Willy Tarreau | 6bdf3e9 | 2019-05-20 14:25:05 +0200 | [diff] [blame] | 380 | |
Willy Tarreau | 9d00869 | 2019-08-09 11:21:01 +0200 | [diff] [blame] | 381 | if (!fdtab[fd].owner) |
| 382 | return cli_msg(appctx, LOG_INFO, "File descriptor was already closed.\n"); |
Willy Tarreau | 6bdf3e9 | 2019-05-20 14:25:05 +0200 | [diff] [blame] | 383 | |
Willy Tarreau | 4781b15 | 2021-04-06 13:53:36 +0200 | [diff] [blame] | 384 | _HA_ATOMIC_INC(&debug_commands_issued); |
Willy Tarreau | 6bdf3e9 | 2019-05-20 14:25:05 +0200 | [diff] [blame] | 385 | fd_delete(fd); |
| 386 | return 1; |
Willy Tarreau | 6bdf3e9 | 2019-05-20 14:25:05 +0200 | [diff] [blame] | 387 | } |
| 388 | |
| 389 | /* parse a "debug dev delay" command. It always returns 1. */ |
| 390 | static int debug_parse_cli_delay(char **args, char *payload, struct appctx *appctx, void *private) |
| 391 | { |
| 392 | int delay = atoi(args[3]); |
| 393 | |
| 394 | if (!cli_has_level(appctx, ACCESS_LVL_ADMIN)) |
| 395 | return 1; |
| 396 | |
Willy Tarreau | 4781b15 | 2021-04-06 13:53:36 +0200 | [diff] [blame] | 397 | _HA_ATOMIC_INC(&debug_commands_issued); |
Willy Tarreau | 6bdf3e9 | 2019-05-20 14:25:05 +0200 | [diff] [blame] | 398 | usleep((long)delay * 1000); |
| 399 | return 1; |
| 400 | } |
| 401 | |
| 402 | /* parse a "debug dev log" command. It always returns 1. */ |
| 403 | static int debug_parse_cli_log(char **args, char *payload, struct appctx *appctx, void *private) |
| 404 | { |
| 405 | int arg; |
| 406 | |
| 407 | if (!cli_has_level(appctx, ACCESS_LVL_ADMIN)) |
| 408 | return 1; |
| 409 | |
Willy Tarreau | 4781b15 | 2021-04-06 13:53:36 +0200 | [diff] [blame] | 410 | _HA_ATOMIC_INC(&debug_commands_issued); |
Willy Tarreau | 6bdf3e9 | 2019-05-20 14:25:05 +0200 | [diff] [blame] | 411 | chunk_reset(&trash); |
| 412 | for (arg = 3; *args[arg]; arg++) { |
| 413 | if (arg > 3) |
| 414 | chunk_strcat(&trash, " "); |
| 415 | chunk_strcat(&trash, args[arg]); |
| 416 | } |
| 417 | |
| 418 | send_log(NULL, LOG_INFO, "%s\n", trash.area); |
| 419 | return 1; |
| 420 | } |
| 421 | |
| 422 | /* parse a "debug dev loop" command. It always returns 1. */ |
| 423 | static int debug_parse_cli_loop(char **args, char *payload, struct appctx *appctx, void *private) |
| 424 | { |
| 425 | struct timeval deadline, curr; |
| 426 | int loop = atoi(args[3]); |
| 427 | |
| 428 | if (!cli_has_level(appctx, ACCESS_LVL_ADMIN)) |
| 429 | return 1; |
| 430 | |
Willy Tarreau | 4781b15 | 2021-04-06 13:53:36 +0200 | [diff] [blame] | 431 | _HA_ATOMIC_INC(&debug_commands_issued); |
Willy Tarreau | 6bdf3e9 | 2019-05-20 14:25:05 +0200 | [diff] [blame] | 432 | gettimeofday(&curr, NULL); |
| 433 | tv_ms_add(&deadline, &curr, loop); |
| 434 | |
| 435 | while (tv_ms_cmp(&curr, &deadline) < 0) |
| 436 | gettimeofday(&curr, NULL); |
| 437 | |
| 438 | return 1; |
| 439 | } |
| 440 | |
| 441 | /* parse a "debug dev panic" command. It always returns 1, though it should never return. */ |
| 442 | static int debug_parse_cli_panic(char **args, char *payload, struct appctx *appctx, void *private) |
| 443 | { |
| 444 | if (!cli_has_level(appctx, ACCESS_LVL_ADMIN)) |
| 445 | return 1; |
| 446 | |
Willy Tarreau | 4781b15 | 2021-04-06 13:53:36 +0200 | [diff] [blame] | 447 | _HA_ATOMIC_INC(&debug_commands_issued); |
Willy Tarreau | 6bdf3e9 | 2019-05-20 14:25:05 +0200 | [diff] [blame] | 448 | ha_panic(); |
| 449 | return 1; |
| 450 | } |
| 451 | |
| 452 | /* parse a "debug dev exec" command. It always returns 1. */ |
Willy Tarreau | b24ab22 | 2019-10-24 18:03:39 +0200 | [diff] [blame] | 453 | #if defined(DEBUG_DEV) |
Willy Tarreau | 6bdf3e9 | 2019-05-20 14:25:05 +0200 | [diff] [blame] | 454 | static int debug_parse_cli_exec(char **args, char *payload, struct appctx *appctx, void *private) |
| 455 | { |
Willy Tarreau | 368bff4 | 2019-12-06 17:18:28 +0100 | [diff] [blame] | 456 | int pipefd[2]; |
Willy Tarreau | 6bdf3e9 | 2019-05-20 14:25:05 +0200 | [diff] [blame] | 457 | int arg; |
Willy Tarreau | 368bff4 | 2019-12-06 17:18:28 +0100 | [diff] [blame] | 458 | int pid; |
Willy Tarreau | 6bdf3e9 | 2019-05-20 14:25:05 +0200 | [diff] [blame] | 459 | |
| 460 | if (!cli_has_level(appctx, ACCESS_LVL_ADMIN)) |
| 461 | return 1; |
| 462 | |
Willy Tarreau | 4781b15 | 2021-04-06 13:53:36 +0200 | [diff] [blame] | 463 | _HA_ATOMIC_INC(&debug_commands_issued); |
Willy Tarreau | 6bdf3e9 | 2019-05-20 14:25:05 +0200 | [diff] [blame] | 464 | chunk_reset(&trash); |
| 465 | for (arg = 3; *args[arg]; arg++) { |
| 466 | if (arg > 3) |
| 467 | chunk_strcat(&trash, " "); |
| 468 | chunk_strcat(&trash, args[arg]); |
| 469 | } |
| 470 | |
Willy Tarreau | 368bff4 | 2019-12-06 17:18:28 +0100 | [diff] [blame] | 471 | thread_isolate(); |
| 472 | if (pipe(pipefd) < 0) |
| 473 | goto fail_pipe; |
Willy Tarreau | 6bdf3e9 | 2019-05-20 14:25:05 +0200 | [diff] [blame] | 474 | |
Willy Tarreau | 368bff4 | 2019-12-06 17:18:28 +0100 | [diff] [blame] | 475 | if (fcntl(pipefd[0], F_SETFD, fcntl(pipefd[0], F_GETFD, FD_CLOEXEC) | FD_CLOEXEC) == -1) |
| 476 | goto fail_fcntl; |
| 477 | |
| 478 | if (fcntl(pipefd[1], F_SETFD, fcntl(pipefd[1], F_GETFD, FD_CLOEXEC) | FD_CLOEXEC) == -1) |
| 479 | goto fail_fcntl; |
| 480 | |
| 481 | pid = fork(); |
| 482 | |
| 483 | if (pid < 0) |
| 484 | goto fail_fork; |
| 485 | else if (pid == 0) { |
| 486 | /* child */ |
| 487 | char *cmd[4] = { "/bin/sh", "-c", 0, 0 }; |
| 488 | |
| 489 | close(0); |
| 490 | dup2(pipefd[1], 1); |
| 491 | dup2(pipefd[1], 2); |
| 492 | |
| 493 | cmd[2] = trash.area; |
| 494 | execvp(cmd[0], cmd); |
| 495 | printf("execvp() failed\n"); |
| 496 | exit(1); |
| 497 | } |
| 498 | |
| 499 | /* parent */ |
| 500 | thread_release(); |
| 501 | close(pipefd[1]); |
Willy Tarreau | 6bdf3e9 | 2019-05-20 14:25:05 +0200 | [diff] [blame] | 502 | chunk_reset(&trash); |
| 503 | while (1) { |
Willy Tarreau | 368bff4 | 2019-12-06 17:18:28 +0100 | [diff] [blame] | 504 | size_t ret = read(pipefd[0], trash.area + trash.data, trash.size - 20 - trash.data); |
| 505 | if (ret <= 0) |
Willy Tarreau | 6bdf3e9 | 2019-05-20 14:25:05 +0200 | [diff] [blame] | 506 | break; |
| 507 | trash.data += ret; |
| 508 | if (trash.data + 20 == trash.size) { |
| 509 | chunk_strcat(&trash, "\n[[[TRUNCATED]]]\n"); |
| 510 | break; |
| 511 | } |
| 512 | } |
Willy Tarreau | 368bff4 | 2019-12-06 17:18:28 +0100 | [diff] [blame] | 513 | close(pipefd[0]); |
| 514 | waitpid(pid, NULL, WNOHANG); |
Willy Tarreau | 6bdf3e9 | 2019-05-20 14:25:05 +0200 | [diff] [blame] | 515 | trash.area[trash.data] = 0; |
Willy Tarreau | 9d00869 | 2019-08-09 11:21:01 +0200 | [diff] [blame] | 516 | return cli_msg(appctx, LOG_INFO, trash.area); |
Willy Tarreau | 368bff4 | 2019-12-06 17:18:28 +0100 | [diff] [blame] | 517 | |
| 518 | fail_fork: |
| 519 | fail_fcntl: |
| 520 | close(pipefd[0]); |
| 521 | close(pipefd[1]); |
| 522 | fail_pipe: |
| 523 | thread_release(); |
| 524 | return cli_err(appctx, "Failed to execute command.\n"); |
Willy Tarreau | 6bdf3e9 | 2019-05-20 14:25:05 +0200 | [diff] [blame] | 525 | } |
Willy Tarreau | b24ab22 | 2019-10-24 18:03:39 +0200 | [diff] [blame] | 526 | #endif |
Willy Tarreau | 6bdf3e9 | 2019-05-20 14:25:05 +0200 | [diff] [blame] | 527 | |
| 528 | /* parse a "debug dev hex" command. It always returns 1. */ |
| 529 | static int debug_parse_cli_hex(char **args, char *payload, struct appctx *appctx, void *private) |
| 530 | { |
| 531 | unsigned long start, len; |
| 532 | |
| 533 | if (!cli_has_level(appctx, ACCESS_LVL_ADMIN)) |
| 534 | return 1; |
| 535 | |
Willy Tarreau | 9d00869 | 2019-08-09 11:21:01 +0200 | [diff] [blame] | 536 | if (!*args[3]) |
| 537 | return cli_err(appctx, "Missing memory address to dump from.\n"); |
Willy Tarreau | 6bdf3e9 | 2019-05-20 14:25:05 +0200 | [diff] [blame] | 538 | |
| 539 | start = strtoul(args[3], NULL, 0); |
Willy Tarreau | 9d00869 | 2019-08-09 11:21:01 +0200 | [diff] [blame] | 540 | if (!start) |
| 541 | return cli_err(appctx, "Will not dump from NULL address.\n"); |
Willy Tarreau | 6bdf3e9 | 2019-05-20 14:25:05 +0200 | [diff] [blame] | 542 | |
Willy Tarreau | 4781b15 | 2021-04-06 13:53:36 +0200 | [diff] [blame] | 543 | _HA_ATOMIC_INC(&debug_commands_issued); |
Willy Tarreau | 9b01370 | 2019-10-24 18:18:02 +0200 | [diff] [blame] | 544 | |
Willy Tarreau | 6bdf3e9 | 2019-05-20 14:25:05 +0200 | [diff] [blame] | 545 | /* by default, dump ~128 till next block of 16 */ |
| 546 | len = strtoul(args[4], NULL, 0); |
| 547 | if (!len) |
| 548 | len = ((start + 128) & -16) - start; |
| 549 | |
| 550 | chunk_reset(&trash); |
Willy Tarreau | 3710105 | 2019-05-20 16:48:20 +0200 | [diff] [blame] | 551 | dump_hex(&trash, " ", (const void *)start, len, 1); |
Willy Tarreau | 6bdf3e9 | 2019-05-20 14:25:05 +0200 | [diff] [blame] | 552 | trash.area[trash.data] = 0; |
Willy Tarreau | 9d00869 | 2019-08-09 11:21:01 +0200 | [diff] [blame] | 553 | return cli_msg(appctx, LOG_INFO, trash.area); |
Willy Tarreau | 6bdf3e9 | 2019-05-20 14:25:05 +0200 | [diff] [blame] | 554 | } |
| 555 | |
Willy Tarreau | 48129be | 2021-05-04 18:40:50 +0200 | [diff] [blame] | 556 | /* parse a "debug dev sym <addr>" command. It always returns 1. */ |
| 557 | static int debug_parse_cli_sym(char **args, char *payload, struct appctx *appctx, void *private) |
| 558 | { |
| 559 | unsigned long addr; |
| 560 | |
| 561 | if (!cli_has_level(appctx, ACCESS_LVL_ADMIN)) |
| 562 | return 1; |
| 563 | |
| 564 | if (!*args[3]) |
| 565 | return cli_err(appctx, "Missing memory address to be resolved.\n"); |
| 566 | |
| 567 | _HA_ATOMIC_INC(&debug_commands_issued); |
| 568 | |
| 569 | addr = strtoul(args[3], NULL, 0); |
| 570 | chunk_printf(&trash, "%#lx resolves to ", addr); |
| 571 | resolve_sym_name(&trash, NULL, (const void *)addr); |
| 572 | chunk_appendf(&trash, "\n"); |
| 573 | |
| 574 | return cli_msg(appctx, LOG_INFO, trash.area); |
| 575 | } |
| 576 | |
Willy Tarreau | 6bdf3e9 | 2019-05-20 14:25:05 +0200 | [diff] [blame] | 577 | /* parse a "debug dev tkill" command. It always returns 1. */ |
| 578 | static int debug_parse_cli_tkill(char **args, char *payload, struct appctx *appctx, void *private) |
| 579 | { |
| 580 | int thr = 0; |
| 581 | int sig = SIGABRT; |
| 582 | |
| 583 | if (!cli_has_level(appctx, ACCESS_LVL_ADMIN)) |
| 584 | return 1; |
| 585 | |
| 586 | if (*args[3]) |
| 587 | thr = atoi(args[3]); |
| 588 | |
Willy Tarreau | 9d00869 | 2019-08-09 11:21:01 +0200 | [diff] [blame] | 589 | if (thr < 0 || thr > global.nbthread) |
| 590 | return cli_err(appctx, "Thread number out of range (use 0 for current).\n"); |
Willy Tarreau | 6bdf3e9 | 2019-05-20 14:25:05 +0200 | [diff] [blame] | 591 | |
| 592 | if (*args[4]) |
| 593 | sig = atoi(args[4]); |
| 594 | |
Willy Tarreau | 4781b15 | 2021-04-06 13:53:36 +0200 | [diff] [blame] | 595 | _HA_ATOMIC_INC(&debug_commands_issued); |
Willy Tarreau | 6bdf3e9 | 2019-05-20 14:25:05 +0200 | [diff] [blame] | 596 | if (thr) |
Willy Tarreau | fade80d | 2019-05-22 08:46:59 +0200 | [diff] [blame] | 597 | ha_tkill(thr - 1, sig); |
Willy Tarreau | 6bdf3e9 | 2019-05-20 14:25:05 +0200 | [diff] [blame] | 598 | else |
Willy Tarreau | 6bdf3e9 | 2019-05-20 14:25:05 +0200 | [diff] [blame] | 599 | raise(sig); |
| 600 | return 1; |
| 601 | } |
| 602 | |
Willy Tarreau | 6cbe62b | 2020-03-05 17:16:24 +0100 | [diff] [blame] | 603 | /* parse a "debug dev write" command. It always returns 1. */ |
| 604 | static int debug_parse_cli_write(char **args, char *payload, struct appctx *appctx, void *private) |
| 605 | { |
| 606 | unsigned long len; |
| 607 | |
| 608 | if (!*args[3]) |
| 609 | return cli_err(appctx, "Missing output size.\n"); |
| 610 | |
| 611 | len = strtoul(args[3], NULL, 0); |
| 612 | if (len >= trash.size) |
| 613 | return cli_err(appctx, "Output too large, must be <tune.bufsize.\n"); |
| 614 | |
Willy Tarreau | 4781b15 | 2021-04-06 13:53:36 +0200 | [diff] [blame] | 615 | _HA_ATOMIC_INC(&debug_commands_issued); |
Willy Tarreau | 6cbe62b | 2020-03-05 17:16:24 +0100 | [diff] [blame] | 616 | |
| 617 | chunk_reset(&trash); |
| 618 | trash.data = len; |
| 619 | memset(trash.area, '.', trash.data); |
| 620 | trash.area[trash.data] = 0; |
| 621 | for (len = 64; len < trash.data; len += 64) |
| 622 | trash.area[len] = '\n'; |
| 623 | return cli_msg(appctx, LOG_INFO, trash.area); |
| 624 | } |
| 625 | |
Willy Tarreau | 68680bb | 2019-10-23 17:23:25 +0200 | [diff] [blame] | 626 | /* parse a "debug dev stream" command */ |
| 627 | /* |
| 628 | * debug dev stream [strm=<ptr>] [strm.f[{+-=}<flags>]] [txn.f[{+-=}<flags>]] \ |
| 629 | * [req.f[{+-=}<flags>]] [res.f[{+-=}<flags>]] \ |
| 630 | * [sif.f[{+-=<flags>]] [sib.f[{+-=<flags>]] \ |
| 631 | * [sif.s[=<state>]] [sib.s[=<state>]] |
| 632 | */ |
| 633 | static int debug_parse_cli_stream(char **args, char *payload, struct appctx *appctx, void *private) |
| 634 | { |
Christopher Faulet | 86e1c33 | 2021-12-20 17:09:39 +0100 | [diff] [blame] | 635 | struct stream *s = si_strm(cs_si(appctx->owner)); |
Willy Tarreau | 68680bb | 2019-10-23 17:23:25 +0200 | [diff] [blame] | 636 | int arg; |
| 637 | void *ptr; |
| 638 | int size; |
| 639 | const char *word, *end; |
| 640 | struct ist name; |
| 641 | char *msg = NULL; |
| 642 | char *endarg; |
| 643 | unsigned long long old, new; |
| 644 | |
| 645 | if (!cli_has_level(appctx, ACCESS_LVL_ADMIN)) |
| 646 | return 1; |
| 647 | |
| 648 | ptr = NULL; size = 0; |
| 649 | |
| 650 | if (!*args[3]) { |
| 651 | return cli_err(appctx, |
| 652 | "Usage: debug dev stream { <obj> <op> <value> | wake }*\n" |
| 653 | " <obj> = {strm | strm.f | sif.f | sif.s | sif.x | sib.f | sib.s | sib.x |\n" |
| 654 | " txn.f | req.f | req.r | req.w | res.f | res.r | res.w}\n" |
| 655 | " <op> = {'' (show) | '=' (assign) | '^' (xor) | '+' (or) | '-' (andnot)}\n" |
| 656 | " <value> = 'now' | 64-bit dec/hex integer (0x prefix supported)\n" |
| 657 | " 'wake' wakes the stream asssigned to 'strm' (default: current)\n" |
| 658 | ); |
| 659 | } |
| 660 | |
Willy Tarreau | 4781b15 | 2021-04-06 13:53:36 +0200 | [diff] [blame] | 661 | _HA_ATOMIC_INC(&debug_commands_issued); |
Willy Tarreau | 68680bb | 2019-10-23 17:23:25 +0200 | [diff] [blame] | 662 | for (arg = 3; *args[arg]; arg++) { |
| 663 | old = 0; |
| 664 | end = word = args[arg]; |
| 665 | while (*end && *end != '=' && *end != '^' && *end != '+' && *end != '-') |
| 666 | end++; |
| 667 | name = ist2(word, end - word); |
| 668 | if (isteq(name, ist("strm"))) { |
Willy Tarreau | b2fee04 | 2019-10-25 10:06:55 +0200 | [diff] [blame] | 669 | ptr = (!s || !may_access(s)) ? NULL : &s; size = sizeof(s); |
Willy Tarreau | 68680bb | 2019-10-23 17:23:25 +0200 | [diff] [blame] | 670 | } else if (isteq(name, ist("strm.f"))) { |
Willy Tarreau | b2fee04 | 2019-10-25 10:06:55 +0200 | [diff] [blame] | 671 | ptr = (!s || !may_access(s)) ? NULL : &s->flags; size = sizeof(s->flags); |
Willy Tarreau | 68680bb | 2019-10-23 17:23:25 +0200 | [diff] [blame] | 672 | } else if (isteq(name, ist("txn.f"))) { |
Willy Tarreau | b2fee04 | 2019-10-25 10:06:55 +0200 | [diff] [blame] | 673 | ptr = (!s || !may_access(s)) ? NULL : &s->txn->flags; size = sizeof(s->txn->flags); |
Willy Tarreau | 68680bb | 2019-10-23 17:23:25 +0200 | [diff] [blame] | 674 | } else if (isteq(name, ist("req.f"))) { |
Willy Tarreau | b2fee04 | 2019-10-25 10:06:55 +0200 | [diff] [blame] | 675 | ptr = (!s || !may_access(s)) ? NULL : &s->req.flags; size = sizeof(s->req.flags); |
Willy Tarreau | 68680bb | 2019-10-23 17:23:25 +0200 | [diff] [blame] | 676 | } else if (isteq(name, ist("res.f"))) { |
Willy Tarreau | b2fee04 | 2019-10-25 10:06:55 +0200 | [diff] [blame] | 677 | ptr = (!s || !may_access(s)) ? NULL : &s->res.flags; size = sizeof(s->res.flags); |
Willy Tarreau | 68680bb | 2019-10-23 17:23:25 +0200 | [diff] [blame] | 678 | } else if (isteq(name, ist("req.r"))) { |
Willy Tarreau | b2fee04 | 2019-10-25 10:06:55 +0200 | [diff] [blame] | 679 | ptr = (!s || !may_access(s)) ? NULL : &s->req.rex; size = sizeof(s->req.rex); |
Willy Tarreau | 68680bb | 2019-10-23 17:23:25 +0200 | [diff] [blame] | 680 | } else if (isteq(name, ist("res.r"))) { |
Willy Tarreau | b2fee04 | 2019-10-25 10:06:55 +0200 | [diff] [blame] | 681 | ptr = (!s || !may_access(s)) ? NULL : &s->res.rex; size = sizeof(s->res.rex); |
Willy Tarreau | 68680bb | 2019-10-23 17:23:25 +0200 | [diff] [blame] | 682 | } else if (isteq(name, ist("req.w"))) { |
Willy Tarreau | b2fee04 | 2019-10-25 10:06:55 +0200 | [diff] [blame] | 683 | ptr = (!s || !may_access(s)) ? NULL : &s->req.wex; size = sizeof(s->req.wex); |
Willy Tarreau | 68680bb | 2019-10-23 17:23:25 +0200 | [diff] [blame] | 684 | } else if (isteq(name, ist("res.w"))) { |
Willy Tarreau | b2fee04 | 2019-10-25 10:06:55 +0200 | [diff] [blame] | 685 | ptr = (!s || !may_access(s)) ? NULL : &s->res.wex; size = sizeof(s->res.wex); |
Willy Tarreau | 68680bb | 2019-10-23 17:23:25 +0200 | [diff] [blame] | 686 | } else if (isteq(name, ist("sif.f"))) { |
Christopher Faulet | 5d3c8aa | 2021-12-23 13:38:12 +0100 | [diff] [blame^] | 687 | ptr = (!s || !may_access(s)) ? NULL : &cs_si(s->csf)->flags; size = sizeof(cs_si(s->csf)->flags); |
Willy Tarreau | 68680bb | 2019-10-23 17:23:25 +0200 | [diff] [blame] | 688 | } else if (isteq(name, ist("sib.f"))) { |
Christopher Faulet | 5d3c8aa | 2021-12-23 13:38:12 +0100 | [diff] [blame^] | 689 | ptr = (!s || !may_access(s)) ? NULL : &cs_si(s->csb)->flags; size = sizeof(cs_si(s->csb)->flags); |
Willy Tarreau | 68680bb | 2019-10-23 17:23:25 +0200 | [diff] [blame] | 690 | } else if (isteq(name, ist("sif.x"))) { |
Christopher Faulet | 5d3c8aa | 2021-12-23 13:38:12 +0100 | [diff] [blame^] | 691 | ptr = (!s || !may_access(s)) ? NULL : &cs_si(s->csf)->exp; size = sizeof(cs_si(s->csf)->exp); |
Willy Tarreau | 68680bb | 2019-10-23 17:23:25 +0200 | [diff] [blame] | 692 | } else if (isteq(name, ist("sib.x"))) { |
Christopher Faulet | 5d3c8aa | 2021-12-23 13:38:12 +0100 | [diff] [blame^] | 693 | ptr = (!s || !may_access(s)) ? NULL : &cs_si(s->csb)->exp; size = sizeof(cs_si(s->csb)->exp); |
Willy Tarreau | 68680bb | 2019-10-23 17:23:25 +0200 | [diff] [blame] | 694 | } else if (isteq(name, ist("sif.s"))) { |
Christopher Faulet | 5d3c8aa | 2021-12-23 13:38:12 +0100 | [diff] [blame^] | 695 | ptr = (!s || !may_access(s)) ? NULL : &cs_si(s->csf)->state; size = sizeof(cs_si(s->csf)->state); |
Willy Tarreau | 68680bb | 2019-10-23 17:23:25 +0200 | [diff] [blame] | 696 | } else if (isteq(name, ist("sib.s"))) { |
Christopher Faulet | 5d3c8aa | 2021-12-23 13:38:12 +0100 | [diff] [blame^] | 697 | ptr = (!s || !may_access(s)) ? NULL : &cs_si(s->csf)->state; size = sizeof(cs_si(s->csb)->state); |
Willy Tarreau | 68680bb | 2019-10-23 17:23:25 +0200 | [diff] [blame] | 698 | } else if (isteq(name, ist("wake"))) { |
Willy Tarreau | 2b5520d | 2019-10-24 18:28:23 +0200 | [diff] [blame] | 699 | if (s && may_access(s) && may_access((void *)s + sizeof(*s) - 1)) |
Willy Tarreau | 68680bb | 2019-10-23 17:23:25 +0200 | [diff] [blame] | 700 | task_wakeup(s->task, TASK_WOKEN_TIMER|TASK_WOKEN_IO|TASK_WOKEN_MSG); |
| 701 | continue; |
| 702 | } else |
| 703 | return cli_dynerr(appctx, memprintf(&msg, "Unsupported field name: '%s'.\n", word)); |
| 704 | |
| 705 | /* read previous value */ |
Willy Tarreau | 2b5520d | 2019-10-24 18:28:23 +0200 | [diff] [blame] | 706 | if ((s || ptr == &s) && ptr && may_access(ptr) && may_access(ptr + size - 1)) { |
Willy Tarreau | 68680bb | 2019-10-23 17:23:25 +0200 | [diff] [blame] | 707 | if (size == 8) |
| 708 | old = read_u64(ptr); |
| 709 | else if (size == 4) |
| 710 | old = read_u32(ptr); |
| 711 | else if (size == 2) |
| 712 | old = read_u16(ptr); |
| 713 | else |
| 714 | old = *(const uint8_t *)ptr; |
Willy Tarreau | 2b5520d | 2019-10-24 18:28:23 +0200 | [diff] [blame] | 715 | } else { |
| 716 | memprintf(&msg, |
| 717 | "%sSkipping inaccessible pointer %p for field '%.*s'.\n", |
| 718 | msg ? msg : "", ptr, (int)(end - word), word); |
| 719 | continue; |
Willy Tarreau | 68680bb | 2019-10-23 17:23:25 +0200 | [diff] [blame] | 720 | } |
| 721 | |
| 722 | /* parse the new value . */ |
| 723 | new = strtoll(end + 1, &endarg, 0); |
| 724 | if (end[1] && *endarg) { |
| 725 | if (strcmp(end + 1, "now") == 0) |
| 726 | new = now_ms; |
| 727 | else { |
| 728 | memprintf(&msg, |
| 729 | "%sIgnoring unparsable value '%s' for field '%.*s'.\n", |
| 730 | msg ? msg : "", end + 1, (int)(end - word), word); |
| 731 | continue; |
| 732 | } |
| 733 | } |
| 734 | |
| 735 | switch (*end) { |
| 736 | case '\0': /* show */ |
| 737 | memprintf(&msg, "%s%.*s=%#llx ", msg ? msg : "", (int)(end - word), word, old); |
| 738 | new = old; // do not change the value |
| 739 | break; |
| 740 | |
| 741 | case '=': /* set */ |
| 742 | break; |
| 743 | |
| 744 | case '^': /* XOR */ |
| 745 | new = old ^ new; |
| 746 | break; |
| 747 | |
| 748 | case '+': /* OR */ |
| 749 | new = old | new; |
| 750 | break; |
| 751 | |
| 752 | case '-': /* AND NOT */ |
| 753 | new = old & ~new; |
| 754 | break; |
| 755 | |
| 756 | default: |
| 757 | break; |
| 758 | } |
| 759 | |
| 760 | /* write the new value */ |
Willy Tarreau | 2b5520d | 2019-10-24 18:28:23 +0200 | [diff] [blame] | 761 | if (new != old) { |
Willy Tarreau | 68680bb | 2019-10-23 17:23:25 +0200 | [diff] [blame] | 762 | if (size == 8) |
| 763 | write_u64(ptr, new); |
| 764 | else if (size == 4) |
| 765 | write_u32(ptr, new); |
| 766 | else if (size == 2) |
| 767 | write_u16(ptr, new); |
| 768 | else |
| 769 | *(uint8_t *)ptr = new; |
| 770 | } |
| 771 | } |
| 772 | |
| 773 | if (msg && *msg) |
| 774 | return cli_dynmsg(appctx, LOG_INFO, msg); |
| 775 | return 1; |
| 776 | } |
| 777 | |
Willy Tarreau | 144f84a | 2021-03-02 16:09:26 +0100 | [diff] [blame] | 778 | static struct task *debug_task_handler(struct task *t, void *ctx, unsigned int state) |
Willy Tarreau | a5a4479 | 2020-11-29 17:12:15 +0100 | [diff] [blame] | 779 | { |
| 780 | unsigned long *tctx = ctx; // [0] = #tasks, [1] = inter, [2+] = { tl | (tsk+1) } |
| 781 | unsigned long inter = tctx[1]; |
| 782 | unsigned long rnd; |
| 783 | |
| 784 | t->expire = tick_add(now_ms, inter); |
| 785 | |
| 786 | /* half of the calls will wake up another entry */ |
Willy Tarreau | 06e69b5 | 2021-03-02 14:01:35 +0100 | [diff] [blame] | 787 | rnd = statistical_prng(); |
Willy Tarreau | a5a4479 | 2020-11-29 17:12:15 +0100 | [diff] [blame] | 788 | if (rnd & 1) { |
| 789 | rnd >>= 1; |
| 790 | rnd %= tctx[0]; |
| 791 | rnd = tctx[rnd + 2]; |
| 792 | |
| 793 | if (rnd & 1) |
| 794 | task_wakeup((struct task *)(rnd - 1), TASK_WOKEN_MSG); |
| 795 | else |
| 796 | tasklet_wakeup((struct tasklet *)rnd); |
| 797 | } |
| 798 | return t; |
| 799 | } |
| 800 | |
Willy Tarreau | 144f84a | 2021-03-02 16:09:26 +0100 | [diff] [blame] | 801 | static struct task *debug_tasklet_handler(struct task *t, void *ctx, unsigned int state) |
Willy Tarreau | a5a4479 | 2020-11-29 17:12:15 +0100 | [diff] [blame] | 802 | { |
| 803 | unsigned long *tctx = ctx; // [0] = #tasks, [1] = inter, [2+] = { tl | (tsk+1) } |
| 804 | unsigned long rnd; |
| 805 | int i; |
| 806 | |
| 807 | /* wake up two random entries */ |
| 808 | for (i = 0; i < 2; i++) { |
Willy Tarreau | 06e69b5 | 2021-03-02 14:01:35 +0100 | [diff] [blame] | 809 | rnd = statistical_prng() % tctx[0]; |
Willy Tarreau | a5a4479 | 2020-11-29 17:12:15 +0100 | [diff] [blame] | 810 | rnd = tctx[rnd + 2]; |
| 811 | |
| 812 | if (rnd & 1) |
| 813 | task_wakeup((struct task *)(rnd - 1), TASK_WOKEN_MSG); |
| 814 | else |
| 815 | tasklet_wakeup((struct tasklet *)rnd); |
| 816 | } |
| 817 | return t; |
| 818 | } |
| 819 | |
| 820 | /* parse a "debug dev sched" command |
| 821 | * debug dev sched {task|tasklet} [count=<count>] [mask=<mask>] [single=<single>] [inter=<inter>] |
| 822 | */ |
| 823 | static int debug_parse_cli_sched(char **args, char *payload, struct appctx *appctx, void *private) |
| 824 | { |
| 825 | int arg; |
| 826 | void *ptr; |
| 827 | int size; |
| 828 | const char *word, *end; |
| 829 | struct ist name; |
| 830 | char *msg = NULL; |
| 831 | char *endarg; |
| 832 | unsigned long long new; |
| 833 | unsigned long count = 0; |
| 834 | unsigned long thrid = 0; |
| 835 | unsigned int inter = 0; |
| 836 | unsigned long mask, tmask; |
| 837 | unsigned long i; |
| 838 | int mode = 0; // 0 = tasklet; 1 = task |
| 839 | int single = 0; |
| 840 | unsigned long *tctx; // [0] = #tasks, [1] = inter, [2+] = { tl | (tsk+1) } |
| 841 | |
| 842 | if (!cli_has_level(appctx, ACCESS_LVL_ADMIN)) |
| 843 | return 1; |
| 844 | |
| 845 | ptr = NULL; size = 0; |
| 846 | mask = all_threads_mask; |
| 847 | |
| 848 | if (strcmp(args[3], "task") != 0 && strcmp(args[3], "tasklet") != 0) { |
| 849 | return cli_err(appctx, |
| 850 | "Usage: debug dev sched {task|tasklet} { <obj> = <value> }*\n" |
| 851 | " <obj> = {count | mask | inter | single }\n" |
| 852 | " <value> = 64-bit dec/hex integer (0x prefix supported)\n" |
| 853 | ); |
| 854 | } |
| 855 | |
| 856 | mode = strcmp(args[3], "task") == 0; |
| 857 | |
Willy Tarreau | 4781b15 | 2021-04-06 13:53:36 +0200 | [diff] [blame] | 858 | _HA_ATOMIC_INC(&debug_commands_issued); |
Willy Tarreau | a5a4479 | 2020-11-29 17:12:15 +0100 | [diff] [blame] | 859 | for (arg = 4; *args[arg]; arg++) { |
| 860 | end = word = args[arg]; |
| 861 | while (*end && *end != '=' && *end != '^' && *end != '+' && *end != '-') |
| 862 | end++; |
| 863 | name = ist2(word, end - word); |
| 864 | if (isteq(name, ist("count"))) { |
| 865 | ptr = &count; size = sizeof(count); |
| 866 | } else if (isteq(name, ist("mask"))) { |
| 867 | ptr = &mask; size = sizeof(mask); |
| 868 | } else if (isteq(name, ist("tid"))) { |
| 869 | ptr = &thrid; size = sizeof(thrid); |
| 870 | } else if (isteq(name, ist("inter"))) { |
| 871 | ptr = &inter; size = sizeof(inter); |
| 872 | } else if (isteq(name, ist("single"))) { |
| 873 | ptr = &single; size = sizeof(single); |
| 874 | } else |
| 875 | return cli_dynerr(appctx, memprintf(&msg, "Unsupported setting: '%s'.\n", word)); |
| 876 | |
| 877 | /* parse the new value . */ |
| 878 | new = strtoll(end + 1, &endarg, 0); |
| 879 | if (end[1] && *endarg) { |
| 880 | memprintf(&msg, |
| 881 | "%sIgnoring unparsable value '%s' for field '%.*s'.\n", |
| 882 | msg ? msg : "", end + 1, (int)(end - word), word); |
| 883 | continue; |
| 884 | } |
| 885 | |
| 886 | /* write the new value */ |
| 887 | if (size == 8) |
| 888 | write_u64(ptr, new); |
| 889 | else if (size == 4) |
| 890 | write_u32(ptr, new); |
| 891 | else if (size == 2) |
| 892 | write_u16(ptr, new); |
| 893 | else |
| 894 | *(uint8_t *)ptr = new; |
| 895 | } |
| 896 | |
| 897 | tctx = calloc(sizeof(*tctx), count + 2); |
| 898 | if (!tctx) |
| 899 | goto fail; |
| 900 | |
| 901 | tctx[0] = (unsigned long)count; |
| 902 | tctx[1] = (unsigned long)inter; |
| 903 | |
| 904 | mask &= all_threads_mask; |
| 905 | if (!mask) |
| 906 | mask = tid_bit; |
| 907 | |
| 908 | tmask = 0; |
| 909 | for (i = 0; i < count; i++) { |
| 910 | if (single || mode == 0) { |
| 911 | /* look for next bit matching a bit in mask or loop back to zero */ |
| 912 | for (tmask <<= 1; !(mask & tmask); ) { |
| 913 | if (!(mask & -tmask)) |
| 914 | tmask = 1; |
| 915 | else |
| 916 | tmask <<= 1; |
| 917 | } |
| 918 | } else { |
| 919 | /* multi-threaded task */ |
| 920 | tmask = mask; |
| 921 | } |
| 922 | |
| 923 | /* now, if poly or mask was set, tmask corresponds to the |
| 924 | * valid thread mask to use, otherwise it remains zero. |
| 925 | */ |
| 926 | //printf("%lu: mode=%d mask=%#lx\n", i, mode, tmask); |
| 927 | if (mode == 0) { |
| 928 | struct tasklet *tl = tasklet_new(); |
| 929 | |
| 930 | if (!tl) |
| 931 | goto fail; |
| 932 | |
| 933 | if (tmask) |
| 934 | tl->tid = my_ffsl(tmask) - 1; |
| 935 | tl->process = debug_tasklet_handler; |
| 936 | tl->context = tctx; |
| 937 | tctx[i + 2] = (unsigned long)tl; |
| 938 | } else { |
| 939 | struct task *task = task_new(tmask ? tmask : tid_bit); |
| 940 | |
| 941 | if (!task) |
| 942 | goto fail; |
| 943 | |
| 944 | task->process = debug_task_handler; |
| 945 | task->context = tctx; |
| 946 | tctx[i + 2] = (unsigned long)task + 1; |
| 947 | } |
| 948 | } |
| 949 | |
| 950 | /* start the tasks and tasklets */ |
| 951 | for (i = 0; i < count; i++) { |
| 952 | unsigned long ctx = tctx[i + 2]; |
| 953 | |
| 954 | if (ctx & 1) |
| 955 | task_wakeup((struct task *)(ctx - 1), TASK_WOKEN_INIT); |
| 956 | else |
| 957 | tasklet_wakeup((struct tasklet *)ctx); |
| 958 | } |
| 959 | |
| 960 | if (msg && *msg) |
| 961 | return cli_dynmsg(appctx, LOG_INFO, msg); |
| 962 | return 1; |
| 963 | |
| 964 | fail: |
| 965 | /* free partially allocated entries */ |
| 966 | for (i = 0; tctx && i < count; i++) { |
| 967 | unsigned long ctx = tctx[i + 2]; |
| 968 | |
| 969 | if (!ctx) |
| 970 | break; |
| 971 | |
| 972 | if (ctx & 1) |
| 973 | task_destroy((struct task *)(ctx - 1)); |
| 974 | else |
| 975 | tasklet_free((struct tasklet *)ctx); |
| 976 | } |
| 977 | |
| 978 | free(tctx); |
| 979 | return cli_err(appctx, "Not enough memory"); |
| 980 | } |
| 981 | |
Willy Tarreau | 5be7c19 | 2022-01-24 20:26:09 +0100 | [diff] [blame] | 982 | /* CLI parser for the "debug dev fd" command. The current FD to restart from is |
| 983 | * stored in i0. |
| 984 | */ |
| 985 | static int debug_parse_cli_fd(char **args, char *payload, struct appctx *appctx, void *private) |
| 986 | { |
| 987 | if (!cli_has_level(appctx, ACCESS_LVL_OPER)) |
| 988 | return 1; |
| 989 | |
| 990 | /* start at fd #0 */ |
| 991 | appctx->ctx.cli.i0 = 0; |
| 992 | return 0; |
| 993 | } |
| 994 | |
| 995 | /* CLI I/O handler for the "debug dev fd" command. Dumps all FDs that are |
| 996 | * accessible from the process but not known from fdtab. The FD number to |
| 997 | * restart from is stored in i0. |
| 998 | */ |
| 999 | static int debug_iohandler_fd(struct appctx *appctx) |
| 1000 | { |
| 1001 | struct stream_interface *si = appctx->owner; |
| 1002 | struct sockaddr_storage sa; |
| 1003 | struct stat statbuf; |
| 1004 | socklen_t salen, vlen; |
| 1005 | int ret1, ret2, port; |
| 1006 | char *addrstr; |
| 1007 | int ret = 1; |
| 1008 | int i, fd; |
| 1009 | |
| 1010 | if (unlikely(si_ic(si)->flags & (CF_WRITE_ERROR|CF_SHUTW))) |
| 1011 | goto end; |
| 1012 | |
| 1013 | chunk_reset(&trash); |
| 1014 | |
| 1015 | thread_isolate(); |
| 1016 | |
| 1017 | /* we have two inner loops here, one for the proxy, the other one for |
| 1018 | * the buffer. |
| 1019 | */ |
| 1020 | for (fd = appctx->ctx.cli.i0; fd < global.maxsock; fd++) { |
| 1021 | /* check for FD's existence */ |
| 1022 | ret1 = fcntl(fd, F_GETFD, 0); |
| 1023 | if (ret1 == -1) |
| 1024 | continue; // not known to the process |
| 1025 | if (fdtab[fd].owner) |
| 1026 | continue; // well-known |
| 1027 | |
| 1028 | /* OK we're seeing an orphan let's try to retrieve as much |
| 1029 | * information as possible about it. |
| 1030 | */ |
| 1031 | chunk_printf(&trash, "%5d", fd); |
| 1032 | |
| 1033 | if (fstat(fd, &statbuf) != -1) { |
| 1034 | chunk_appendf(&trash, " type=%s mod=%04o dev=%#llx siz=%#llx uid=%lld gid=%lld fs=%#llx ino=%#llx", |
| 1035 | isatty(fd) ? "tty.": |
| 1036 | S_ISREG(statbuf.st_mode) ? "file": |
| 1037 | S_ISDIR(statbuf.st_mode) ? "dir.": |
| 1038 | S_ISCHR(statbuf.st_mode) ? "chr.": |
| 1039 | S_ISBLK(statbuf.st_mode) ? "blk.": |
| 1040 | S_ISFIFO(statbuf.st_mode) ? "pipe": |
| 1041 | S_ISLNK(statbuf.st_mode) ? "link": |
| 1042 | S_ISSOCK(statbuf.st_mode) ? "sock": |
| 1043 | #ifdef USE_EPOLL |
| 1044 | epoll_wait(fd, NULL, 0, 0) != -1 || errno != EBADF ? "epol": |
| 1045 | #endif |
| 1046 | "????", |
| 1047 | (uint)statbuf.st_mode & 07777, |
| 1048 | |
| 1049 | (ullong)statbuf.st_rdev, |
| 1050 | (ullong)statbuf.st_size, |
| 1051 | (ullong)statbuf.st_uid, |
| 1052 | (ullong)statbuf.st_gid, |
| 1053 | |
| 1054 | (ullong)statbuf.st_dev, |
| 1055 | (ullong)statbuf.st_ino); |
| 1056 | } |
| 1057 | |
| 1058 | chunk_appendf(&trash, " getfd=%s+%#x", |
| 1059 | (ret1 & FD_CLOEXEC) ? "cloex" : "", |
| 1060 | ret1 &~ FD_CLOEXEC); |
| 1061 | |
| 1062 | /* FD options */ |
| 1063 | ret2 = fcntl(fd, F_GETFL, 0); |
| 1064 | if (ret2) { |
| 1065 | chunk_appendf(&trash, " getfl=%s", |
| 1066 | (ret1 & 3) >= 2 ? "O_RDWR" : |
| 1067 | (ret1 & 1) ? "O_WRONLY" : "O_RDONLY"); |
| 1068 | |
| 1069 | for (i = 2; i < 32; i++) { |
| 1070 | if (!(ret2 & (1UL << i))) |
| 1071 | continue; |
| 1072 | switch (1UL << i) { |
| 1073 | case O_CREAT: chunk_appendf(&trash, ",O_CREAT"); break; |
| 1074 | case O_EXCL: chunk_appendf(&trash, ",O_EXCL"); break; |
| 1075 | case O_NOCTTY: chunk_appendf(&trash, ",O_NOCTTY"); break; |
| 1076 | case O_TRUNC: chunk_appendf(&trash, ",O_TRUNC"); break; |
| 1077 | case O_APPEND: chunk_appendf(&trash, ",O_APPEND"); break; |
Willy Tarreau | 410942b | 2022-01-25 14:51:53 +0100 | [diff] [blame] | 1078 | #ifdef O_ASYNC |
Willy Tarreau | 5be7c19 | 2022-01-24 20:26:09 +0100 | [diff] [blame] | 1079 | case O_ASYNC: chunk_appendf(&trash, ",O_ASYNC"); break; |
Willy Tarreau | 410942b | 2022-01-25 14:51:53 +0100 | [diff] [blame] | 1080 | #endif |
Willy Tarreau | 5be7c19 | 2022-01-24 20:26:09 +0100 | [diff] [blame] | 1081 | #ifdef O_DIRECT |
| 1082 | case O_DIRECT: chunk_appendf(&trash, ",O_DIRECT"); break; |
| 1083 | #endif |
| 1084 | #ifdef O_NOATIME |
| 1085 | case O_NOATIME: chunk_appendf(&trash, ",O_NOATIME"); break; |
| 1086 | #endif |
| 1087 | } |
| 1088 | } |
| 1089 | } |
| 1090 | |
| 1091 | vlen = sizeof(ret2); |
| 1092 | ret1 = getsockopt(fd, SOL_SOCKET, SO_TYPE, &ret2, &vlen); |
| 1093 | if (ret1 != -1) |
| 1094 | chunk_appendf(&trash, " so_type=%d", ret2); |
| 1095 | |
| 1096 | vlen = sizeof(ret2); |
| 1097 | ret1 = getsockopt(fd, SOL_SOCKET, SO_ACCEPTCONN, &ret2, &vlen); |
| 1098 | if (ret1 != -1) |
| 1099 | chunk_appendf(&trash, " so_accept=%d", ret2); |
| 1100 | |
| 1101 | vlen = sizeof(ret2); |
| 1102 | ret1 = getsockopt(fd, SOL_SOCKET, SO_ERROR, &ret2, &vlen); |
| 1103 | if (ret1 != -1) |
| 1104 | chunk_appendf(&trash, " so_error=%d", ret2); |
| 1105 | |
| 1106 | salen = sizeof(sa); |
| 1107 | if (getsockname(fd, (struct sockaddr *)&sa, &salen) != -1) { |
| 1108 | if (sa.ss_family == AF_INET) |
| 1109 | port = ntohs(((const struct sockaddr_in *)&sa)->sin_port); |
| 1110 | else if (sa.ss_family == AF_INET6) |
| 1111 | port = ntohs(((const struct sockaddr_in6 *)&sa)->sin6_port); |
| 1112 | else |
| 1113 | port = 0; |
| 1114 | addrstr = sa2str(&sa, port, 0); |
| 1115 | chunk_appendf(&trash, " laddr=%s", addrstr); |
| 1116 | free(addrstr); |
| 1117 | } |
| 1118 | |
| 1119 | salen = sizeof(sa); |
| 1120 | if (getpeername(fd, (struct sockaddr *)&sa, &salen) != -1) { |
| 1121 | if (sa.ss_family == AF_INET) |
| 1122 | port = ntohs(((const struct sockaddr_in *)&sa)->sin_port); |
| 1123 | else if (sa.ss_family == AF_INET6) |
| 1124 | port = ntohs(((const struct sockaddr_in6 *)&sa)->sin6_port); |
| 1125 | else |
| 1126 | port = 0; |
| 1127 | addrstr = sa2str(&sa, port, 0); |
| 1128 | chunk_appendf(&trash, " raddr=%s", addrstr); |
| 1129 | free(addrstr); |
| 1130 | } |
| 1131 | |
| 1132 | chunk_appendf(&trash, "\n"); |
| 1133 | |
| 1134 | if (ci_putchk(si_ic(si), &trash) == -1) { |
| 1135 | si_rx_room_blk(si); |
| 1136 | appctx->ctx.cli.i0 = fd; |
| 1137 | ret = 0; |
| 1138 | break; |
| 1139 | } |
| 1140 | } |
| 1141 | |
| 1142 | thread_release(); |
| 1143 | end: |
| 1144 | return ret; |
| 1145 | } |
| 1146 | |
Willy Tarreau | a6026a0 | 2020-07-02 09:14:48 +0200 | [diff] [blame] | 1147 | #if defined(DEBUG_MEM_STATS) |
| 1148 | /* CLI parser for the "debug dev memstats" command */ |
| 1149 | static int debug_parse_cli_memstats(char **args, char *payload, struct appctx *appctx, void *private) |
| 1150 | { |
| 1151 | extern __attribute__((__weak__)) struct mem_stats __start_mem_stats; |
| 1152 | extern __attribute__((__weak__)) struct mem_stats __stop_mem_stats; |
| 1153 | |
| 1154 | if (!cli_has_level(appctx, ACCESS_LVL_OPER)) |
| 1155 | return 1; |
| 1156 | |
| 1157 | if (strcmp(args[3], "reset") == 0) { |
| 1158 | struct mem_stats *ptr; |
| 1159 | |
| 1160 | if (!cli_has_level(appctx, ACCESS_LVL_ADMIN)) |
| 1161 | return 1; |
| 1162 | |
| 1163 | for (ptr = &__start_mem_stats; ptr < &__stop_mem_stats; ptr++) { |
| 1164 | _HA_ATOMIC_STORE(&ptr->calls, 0); |
| 1165 | _HA_ATOMIC_STORE(&ptr->size, 0); |
| 1166 | } |
| 1167 | return 1; |
| 1168 | } |
| 1169 | |
| 1170 | if (strcmp(args[3], "all") == 0) |
| 1171 | appctx->ctx.cli.i0 = 1; |
| 1172 | |
| 1173 | /* otherwise proceed with the dump from p0 to p1 */ |
| 1174 | appctx->ctx.cli.p0 = &__start_mem_stats; |
| 1175 | appctx->ctx.cli.p1 = &__stop_mem_stats; |
| 1176 | return 0; |
| 1177 | } |
| 1178 | |
| 1179 | /* CLI I/O handler for the "debug dev memstats" command. Dumps all mem_stats |
| 1180 | * structs referenced by pointers located between p0 and p1. Dumps all entries |
| 1181 | * if i0 > 0, otherwise only non-zero calls. |
| 1182 | */ |
| 1183 | static int debug_iohandler_memstats(struct appctx *appctx) |
| 1184 | { |
Christopher Faulet | 86e1c33 | 2021-12-20 17:09:39 +0100 | [diff] [blame] | 1185 | struct stream_interface *si = cs_si(appctx->owner); |
Willy Tarreau | a6026a0 | 2020-07-02 09:14:48 +0200 | [diff] [blame] | 1186 | struct mem_stats *ptr = appctx->ctx.cli.p0; |
| 1187 | int ret = 1; |
| 1188 | |
| 1189 | if (unlikely(si_ic(si)->flags & (CF_WRITE_ERROR|CF_SHUTW))) |
| 1190 | goto end; |
| 1191 | |
| 1192 | chunk_reset(&trash); |
| 1193 | |
| 1194 | /* we have two inner loops here, one for the proxy, the other one for |
| 1195 | * the buffer. |
| 1196 | */ |
| 1197 | for (ptr = appctx->ctx.cli.p0; ptr != appctx->ctx.cli.p1; ptr++) { |
| 1198 | const char *type; |
| 1199 | const char *name; |
| 1200 | const char *p; |
| 1201 | |
| 1202 | if (!ptr->size && !ptr->calls && !appctx->ctx.cli.i0) |
| 1203 | continue; |
| 1204 | |
| 1205 | /* basename only */ |
| 1206 | for (p = name = ptr->file; *p; p++) { |
| 1207 | if (*p == '/') |
| 1208 | name = p + 1; |
| 1209 | } |
| 1210 | |
| 1211 | switch (ptr->type) { |
| 1212 | case MEM_STATS_TYPE_CALLOC: type = "CALLOC"; break; |
| 1213 | case MEM_STATS_TYPE_FREE: type = "FREE"; break; |
| 1214 | case MEM_STATS_TYPE_MALLOC: type = "MALLOC"; break; |
| 1215 | case MEM_STATS_TYPE_REALLOC: type = "REALLOC"; break; |
| 1216 | case MEM_STATS_TYPE_STRDUP: type = "STRDUP"; break; |
| 1217 | default: type = "UNSET"; break; |
| 1218 | } |
| 1219 | |
| 1220 | //chunk_printf(&trash, |
| 1221 | // "%20s:%-5d %7s size: %12lu calls: %9lu size/call: %6lu\n", |
| 1222 | // name, ptr->line, type, |
| 1223 | // (unsigned long)ptr->size, (unsigned long)ptr->calls, |
| 1224 | // (unsigned long)(ptr->calls ? (ptr->size / ptr->calls) : 0)); |
| 1225 | |
| 1226 | chunk_printf(&trash, "%s:%d", name, ptr->line); |
| 1227 | while (trash.data < 25) |
| 1228 | trash.area[trash.data++] = ' '; |
| 1229 | chunk_appendf(&trash, "%7s size: %12lu calls: %9lu size/call: %6lu\n", |
| 1230 | type, |
| 1231 | (unsigned long)ptr->size, (unsigned long)ptr->calls, |
| 1232 | (unsigned long)(ptr->calls ? (ptr->size / ptr->calls) : 0)); |
| 1233 | |
| 1234 | if (ci_putchk(si_ic(si), &trash) == -1) { |
| 1235 | si_rx_room_blk(si); |
| 1236 | appctx->ctx.cli.p0 = ptr; |
| 1237 | ret = 0; |
| 1238 | break; |
| 1239 | } |
| 1240 | } |
| 1241 | |
| 1242 | end: |
| 1243 | return ret; |
| 1244 | } |
| 1245 | |
| 1246 | #endif |
| 1247 | |
Willy Tarreau | c7091d8 | 2019-05-17 10:08:49 +0200 | [diff] [blame] | 1248 | #ifndef USE_THREAD_DUMP |
| 1249 | |
| 1250 | /* This function dumps all threads' state to the trash. This version is the |
| 1251 | * most basic one, which doesn't inspect other threads. |
| 1252 | */ |
| 1253 | void ha_thread_dump_all_to_trash() |
| 1254 | { |
| 1255 | unsigned int thr; |
| 1256 | |
| 1257 | for (thr = 0; thr < global.nbthread; thr++) |
| 1258 | ha_thread_dump(&trash, thr, tid); |
| 1259 | } |
| 1260 | |
| 1261 | #else /* below USE_THREAD_DUMP is set */ |
| 1262 | |
Willy Tarreau | c7091d8 | 2019-05-17 10:08:49 +0200 | [diff] [blame] | 1263 | /* ID of the thread requesting the dump */ |
| 1264 | static unsigned int thread_dump_tid; |
| 1265 | |
| 1266 | /* points to the buffer where the dump functions should write. It must |
| 1267 | * have already been initialized by the requester. Nothing is done if |
| 1268 | * it's NULL. |
| 1269 | */ |
| 1270 | struct buffer *thread_dump_buffer = NULL; |
| 1271 | |
| 1272 | void ha_thread_dump_all_to_trash() |
| 1273 | { |
Willy Tarreau | c7091d8 | 2019-05-17 10:08:49 +0200 | [diff] [blame] | 1274 | unsigned long old; |
| 1275 | |
| 1276 | while (1) { |
| 1277 | old = 0; |
| 1278 | if (HA_ATOMIC_CAS(&threads_to_dump, &old, all_threads_mask)) |
| 1279 | break; |
| 1280 | ha_thread_relax(); |
| 1281 | } |
| 1282 | |
| 1283 | thread_dump_buffer = &trash; |
| 1284 | thread_dump_tid = tid; |
Willy Tarreau | fade80d | 2019-05-22 08:46:59 +0200 | [diff] [blame] | 1285 | ha_tkillall(DEBUGSIG); |
Willy Tarreau | c7091d8 | 2019-05-17 10:08:49 +0200 | [diff] [blame] | 1286 | } |
| 1287 | |
| 1288 | /* handles DEBUGSIG to dump the state of the thread it's working on */ |
| 1289 | void debug_handler(int sig, siginfo_t *si, void *arg) |
| 1290 | { |
Willy Tarreau | 82aafc4 | 2020-03-03 08:31:34 +0100 | [diff] [blame] | 1291 | /* first, let's check it's really for us and that we didn't just get |
| 1292 | * a spurious DEBUGSIG. |
| 1293 | */ |
| 1294 | if (!(threads_to_dump & tid_bit)) |
| 1295 | return; |
| 1296 | |
Willy Tarreau | c7091d8 | 2019-05-17 10:08:49 +0200 | [diff] [blame] | 1297 | /* There are 4 phases in the dump process: |
| 1298 | * 1- wait for our turn, i.e. when all lower bits are gone. |
| 1299 | * 2- perform the action if our bit is set |
| 1300 | * 3- remove our bit to let the next one go, unless we're |
Willy Tarreau | c077362 | 2019-07-31 19:15:45 +0200 | [diff] [blame] | 1301 | * the last one and have to put them all as a signal |
| 1302 | * 4- wait out bit to re-appear, then clear it and quit. |
Willy Tarreau | c7091d8 | 2019-05-17 10:08:49 +0200 | [diff] [blame] | 1303 | */ |
| 1304 | |
| 1305 | /* wait for all previous threads to finish first */ |
| 1306 | while (threads_to_dump & (tid_bit - 1)) |
| 1307 | ha_thread_relax(); |
| 1308 | |
| 1309 | /* dump if needed */ |
| 1310 | if (threads_to_dump & tid_bit) { |
| 1311 | if (thread_dump_buffer) |
| 1312 | ha_thread_dump(thread_dump_buffer, tid, thread_dump_tid); |
| 1313 | if ((threads_to_dump & all_threads_mask) == tid_bit) { |
| 1314 | /* last one */ |
Willy Tarreau | c077362 | 2019-07-31 19:15:45 +0200 | [diff] [blame] | 1315 | HA_ATOMIC_STORE(&threads_to_dump, all_threads_mask); |
Willy Tarreau | c7091d8 | 2019-05-17 10:08:49 +0200 | [diff] [blame] | 1316 | thread_dump_buffer = NULL; |
| 1317 | } |
| 1318 | else |
| 1319 | HA_ATOMIC_AND(&threads_to_dump, ~tid_bit); |
| 1320 | } |
| 1321 | |
| 1322 | /* now wait for all others to finish dumping. The last one will set all |
Willy Tarreau | c077362 | 2019-07-31 19:15:45 +0200 | [diff] [blame] | 1323 | * bits again to broadcast the leaving condition so we'll see ourselves |
| 1324 | * present again. This way the threads_to_dump variable never passes to |
| 1325 | * zero until all visitors have stopped waiting. |
Willy Tarreau | c7091d8 | 2019-05-17 10:08:49 +0200 | [diff] [blame] | 1326 | */ |
Willy Tarreau | c077362 | 2019-07-31 19:15:45 +0200 | [diff] [blame] | 1327 | while (!(threads_to_dump & tid_bit)) |
| 1328 | ha_thread_relax(); |
| 1329 | HA_ATOMIC_AND(&threads_to_dump, ~tid_bit); |
Willy Tarreau | e6a02fa | 2019-05-22 07:06:44 +0200 | [diff] [blame] | 1330 | |
| 1331 | /* mark the current thread as stuck to detect it upon next invocation |
| 1332 | * if it didn't move. |
| 1333 | */ |
| 1334 | if (!((threads_harmless_mask|sleeping_thread_mask) & tid_bit)) |
Willy Tarreau | a0b9953 | 2021-09-30 18:48:37 +0200 | [diff] [blame] | 1335 | th_ctx->flags |= TH_FL_STUCK; |
Willy Tarreau | c7091d8 | 2019-05-17 10:08:49 +0200 | [diff] [blame] | 1336 | } |
| 1337 | |
| 1338 | static int init_debug_per_thread() |
| 1339 | { |
| 1340 | sigset_t set; |
| 1341 | |
| 1342 | /* unblock the DEBUGSIG signal we intend to use */ |
| 1343 | sigemptyset(&set); |
| 1344 | sigaddset(&set, DEBUGSIG); |
| 1345 | ha_sigmask(SIG_UNBLOCK, &set, NULL); |
| 1346 | return 1; |
| 1347 | } |
| 1348 | |
| 1349 | static int init_debug() |
| 1350 | { |
| 1351 | struct sigaction sa; |
Willy Tarreau | 2f1227e | 2021-01-22 12:12:29 +0100 | [diff] [blame] | 1352 | void *callers[1]; |
Willy Tarreau | c7091d8 | 2019-05-17 10:08:49 +0200 | [diff] [blame] | 1353 | |
Willy Tarreau | 0214b45 | 2020-03-04 06:01:40 +0100 | [diff] [blame] | 1354 | /* calling backtrace() will access libgcc at runtime. We don't want to |
| 1355 | * do it after the chroot, so let's perform a first call to have it |
| 1356 | * ready in memory for later use. |
| 1357 | */ |
Willy Tarreau | 13faf16 | 2020-03-04 07:44:06 +0100 | [diff] [blame] | 1358 | my_backtrace(callers, sizeof(callers)/sizeof(*callers)); |
Willy Tarreau | c7091d8 | 2019-05-17 10:08:49 +0200 | [diff] [blame] | 1359 | sa.sa_handler = NULL; |
| 1360 | sa.sa_sigaction = debug_handler; |
| 1361 | sigemptyset(&sa.sa_mask); |
| 1362 | sa.sa_flags = SA_SIGINFO; |
| 1363 | sigaction(DEBUGSIG, &sa, NULL); |
Christopher Faulet | fc633b6 | 2020-11-06 15:24:23 +0100 | [diff] [blame] | 1364 | return ERR_NONE; |
Willy Tarreau | c7091d8 | 2019-05-17 10:08:49 +0200 | [diff] [blame] | 1365 | } |
| 1366 | |
| 1367 | REGISTER_POST_CHECK(init_debug); |
| 1368 | REGISTER_PER_THREAD_INIT(init_debug_per_thread); |
| 1369 | |
| 1370 | #endif /* USE_THREAD_DUMP */ |
| 1371 | |
Willy Tarreau | 4e2b646 | 2019-05-16 17:44:30 +0200 | [diff] [blame] | 1372 | /* register cli keywords */ |
| 1373 | static struct cli_kw_list cli_kws = {{ },{ |
Willy Tarreau | b205bfd | 2021-05-07 11:38:37 +0200 | [diff] [blame] | 1374 | {{ "debug", "dev", "bug", NULL }, "debug dev bug : call BUG_ON() and crash", debug_parse_cli_bug, NULL, NULL, NULL, ACCESS_EXPERT }, |
| 1375 | {{ "debug", "dev", "close", NULL }, "debug dev close <fd> : close this file descriptor", debug_parse_cli_close, NULL, NULL, NULL, ACCESS_EXPERT }, |
| 1376 | {{ "debug", "dev", "delay", NULL }, "debug dev delay [ms] : sleep this long", debug_parse_cli_delay, NULL, NULL, NULL, ACCESS_EXPERT }, |
Willy Tarreau | 6bdf3e9 | 2019-05-20 14:25:05 +0200 | [diff] [blame] | 1377 | #if defined(DEBUG_DEV) |
Willy Tarreau | b205bfd | 2021-05-07 11:38:37 +0200 | [diff] [blame] | 1378 | {{ "debug", "dev", "exec", NULL }, "debug dev exec [cmd] ... : show this command's output", debug_parse_cli_exec, NULL, NULL, NULL, ACCESS_EXPERT }, |
Willy Tarreau | 6bdf3e9 | 2019-05-20 14:25:05 +0200 | [diff] [blame] | 1379 | #endif |
Willy Tarreau | 5be7c19 | 2022-01-24 20:26:09 +0100 | [diff] [blame] | 1380 | {{ "debug", "dev", "fd", NULL }, "debug dev fd : scan for rogue/unhandled FDs", debug_parse_cli_fd, debug_iohandler_fd, NULL, NULL, ACCESS_EXPERT }, |
Willy Tarreau | b205bfd | 2021-05-07 11:38:37 +0200 | [diff] [blame] | 1381 | {{ "debug", "dev", "exit", NULL }, "debug dev exit [code] : immediately exit the process", debug_parse_cli_exit, NULL, NULL, NULL, ACCESS_EXPERT }, |
| 1382 | {{ "debug", "dev", "hex", NULL }, "debug dev hex <addr> [len] : dump a memory area", debug_parse_cli_hex, NULL, NULL, NULL, ACCESS_EXPERT }, |
| 1383 | {{ "debug", "dev", "log", NULL }, "debug dev log [msg] ... : send this msg to global logs", debug_parse_cli_log, NULL, NULL, NULL, ACCESS_EXPERT }, |
| 1384 | {{ "debug", "dev", "loop", NULL }, "debug dev loop [ms] : loop this long", debug_parse_cli_loop, NULL, NULL, NULL, ACCESS_EXPERT }, |
Willy Tarreau | a6026a0 | 2020-07-02 09:14:48 +0200 | [diff] [blame] | 1385 | #if defined(DEBUG_MEM_STATS) |
Willy Tarreau | b205bfd | 2021-05-07 11:38:37 +0200 | [diff] [blame] | 1386 | {{ "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 Tarreau | a6026a0 | 2020-07-02 09:14:48 +0200 | [diff] [blame] | 1387 | #endif |
Willy Tarreau | b205bfd | 2021-05-07 11:38:37 +0200 | [diff] [blame] | 1388 | {{ "debug", "dev", "panic", NULL }, "debug dev panic : immediately trigger a panic", debug_parse_cli_panic, NULL, NULL, NULL, ACCESS_EXPERT }, |
| 1389 | {{ "debug", "dev", "sched", NULL }, "debug dev sched {task|tasklet} [k=v]* : stress the scheduler", debug_parse_cli_sched, NULL, NULL, NULL, ACCESS_EXPERT }, |
| 1390 | {{ "debug", "dev", "stream",NULL }, "debug dev stream [k=v]* : show/manipulate stream flags", debug_parse_cli_stream,NULL, NULL, NULL, ACCESS_EXPERT }, |
| 1391 | {{ "debug", "dev", "sym", NULL }, "debug dev sym <addr> : resolve symbol address", debug_parse_cli_sym, NULL, NULL, NULL, ACCESS_EXPERT }, |
| 1392 | {{ "debug", "dev", "tkill", NULL }, "debug dev tkill [thr] [sig] : send signal to thread", debug_parse_cli_tkill, NULL, NULL, NULL, ACCESS_EXPERT }, |
| 1393 | {{ "debug", "dev", "write", NULL }, "debug dev write [size] : write that many bytes in return", debug_parse_cli_write, NULL, NULL, NULL, ACCESS_EXPERT }, |
Willy Tarreau | 6ab7b21 | 2021-12-28 09:57:10 +0100 | [diff] [blame] | 1394 | #if defined(HA_HAVE_DUMP_LIBS) |
| 1395 | {{ "show", "libs", NULL, NULL }, "show libs : show loaded object files and libraries", debug_parse_cli_show_libs, NULL, NULL }, |
| 1396 | #endif |
Willy Tarreau | b205bfd | 2021-05-07 11:38:37 +0200 | [diff] [blame] | 1397 | {{ "show", "threads", NULL, NULL }, "show threads : show some threads debugging information", NULL, cli_io_handler_show_threads, NULL }, |
Willy Tarreau | 4e2b646 | 2019-05-16 17:44:30 +0200 | [diff] [blame] | 1398 | {{},} |
| 1399 | }}; |
| 1400 | |
| 1401 | INITCALL1(STG_REGISTER, cli_register_kw, &cli_kws); |