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