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