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