Willy Tarreau | 4e2b646 | 2019-05-16 17:44:30 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Process debugging functions. |
| 3 | * |
| 4 | * Copyright 2000-2019 Willy Tarreau <willy@haproxy.org>. |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU General Public License |
| 8 | * as published by the Free Software Foundation; either version |
| 9 | * 2 of the License, or (at your option) any later version. |
| 10 | * |
| 11 | */ |
| 12 | |
Willy Tarreau | f5b4e06 | 2020-03-03 15:40:23 +0100 | [diff] [blame] | 13 | |
Willy Tarreau | 5be7c19 | 2022-01-24 20:26:09 +0100 | [diff] [blame] | 14 | #include <errno.h> |
Willy Tarreau | 368bff4 | 2019-12-06 17:18:28 +0100 | [diff] [blame] | 15 | #include <fcntl.h> |
Willy Tarreau | 4e2b646 | 2019-05-16 17:44:30 +0200 | [diff] [blame] | 16 | #include <signal.h> |
| 17 | #include <time.h> |
| 18 | #include <stdio.h> |
Willy Tarreau | 6bdf3e9 | 2019-05-20 14:25:05 +0200 | [diff] [blame] | 19 | #include <stdlib.h> |
Willy Tarreau | aeed4a8 | 2020-06-04 22:01:04 +0200 | [diff] [blame] | 20 | #include <syslog.h> |
Willy Tarreau | 5be7c19 | 2022-01-24 20:26:09 +0100 | [diff] [blame] | 21 | #include <sys/stat.h> |
Willy Tarreau | 368bff4 | 2019-12-06 17:18:28 +0100 | [diff] [blame] | 22 | #include <sys/types.h> |
| 23 | #include <sys/wait.h> |
Willy Tarreau | 5be7c19 | 2022-01-24 20:26:09 +0100 | [diff] [blame] | 24 | #include <unistd.h> |
| 25 | #ifdef USE_EPOLL |
| 26 | #include <sys/epoll.h> |
| 27 | #endif |
Willy Tarreau | 4e2b646 | 2019-05-16 17:44:30 +0200 | [diff] [blame] | 28 | |
Willy Tarreau | 4c7e4b7 | 2020-05-27 12:58:42 +0200 | [diff] [blame] | 29 | #include <haproxy/api.h> |
Christopher Faulet | 6b0a0fb | 2022-04-04 11:29:28 +0200 | [diff] [blame] | 30 | #include <haproxy/applet.h> |
Willy Tarreau | 8dabda7 | 2020-05-27 17:22:10 +0200 | [diff] [blame] | 31 | #include <haproxy/buf.h> |
Willy Tarreau | 83487a8 | 2020-06-04 20:19:54 +0200 | [diff] [blame] | 32 | #include <haproxy/cli.h> |
Willy Tarreau | 5554264 | 2021-10-08 09:33:24 +0200 | [diff] [blame] | 33 | #include <haproxy/clock.h> |
Willy Tarreau | 2a83d60 | 2020-05-27 16:58:08 +0200 | [diff] [blame] | 34 | #include <haproxy/debug.h> |
Willy Tarreau | b255105 | 2020-06-09 09:07:15 +0200 | [diff] [blame] | 35 | #include <haproxy/fd.h> |
| 36 | #include <haproxy/global.h> |
Willy Tarreau | 8641605 | 2020-06-04 09:20:54 +0200 | [diff] [blame] | 37 | #include <haproxy/hlua.h> |
Willy Tarreau | b7fc4c4 | 2021-10-06 18:56:42 +0200 | [diff] [blame] | 38 | #include <haproxy/http_ana.h> |
Willy Tarreau | aeed4a8 | 2020-06-04 22:01:04 +0200 | [diff] [blame] | 39 | #include <haproxy/log.h> |
Willy Tarreau | b255105 | 2020-06-09 09:07:15 +0200 | [diff] [blame] | 40 | #include <haproxy/net_helper.h> |
Willy Tarreau | 5edca2f | 2022-05-27 09:25:10 +0200 | [diff] [blame] | 41 | #include <haproxy/sc_strm.h> |
Willy Tarreau | cb086c6 | 2022-05-27 09:47:12 +0200 | [diff] [blame] | 42 | #include <haproxy/stconn.h> |
Willy Tarreau | cea0e1b | 2020-06-04 17:25:40 +0200 | [diff] [blame] | 43 | #include <haproxy/task.h> |
Willy Tarreau | 3f567e4 | 2020-05-28 15:29:19 +0200 | [diff] [blame] | 44 | #include <haproxy/thread.h> |
Willy Tarreau | 5554264 | 2021-10-08 09:33:24 +0200 | [diff] [blame] | 45 | #include <haproxy/time.h> |
Willy Tarreau | 48fbcae | 2020-06-03 18:09:46 +0200 | [diff] [blame] | 46 | #include <haproxy/tools.h> |
Willy Tarreau | b255105 | 2020-06-09 09:07:15 +0200 | [diff] [blame] | 47 | #include <import/ist.h> |
Willy Tarreau | 4e2b646 | 2019-05-16 17:44:30 +0200 | [diff] [blame] | 48 | |
Willy Tarreau | 4e2b646 | 2019-05-16 17:44:30 +0200 | [diff] [blame] | 49 | |
Willy Tarreau | f0c86dd | 2022-07-15 13:14:03 +0200 | [diff] [blame] | 50 | /* The dump state is made of: |
| 51 | * - num_thread on the lowest 15 bits |
| 52 | * - a SYNC flag on bit 15 (waiting for sync start) |
| 53 | * - number of participating threads on bits 16-30 |
| 54 | * Initiating a dump consists in setting it to SYNC and incrementing the |
| 55 | * num_thread part when entering the function. The first thread periodically |
| 56 | * recounts active threads and compares it to the ready ones, and clears SYNC |
| 57 | * and sets the number of participants to the value found, which serves as a |
| 58 | * start signal. A thread finished dumping looks up the TID of the next active |
| 59 | * thread after it and writes it in the lowest part. If there's none, it sets |
| 60 | * the thread counter to the number of participants and resets that part, |
| 61 | * which serves as an end-of-dump signal. All threads decrement the num_thread |
| 62 | * part. Then all threads wait for the value to reach zero. Only used when |
| 63 | * USE_THREAD_DUMP is set. |
Willy Tarreau | a37cb18 | 2019-07-31 19:20:39 +0200 | [diff] [blame] | 64 | */ |
Willy Tarreau | f0c86dd | 2022-07-15 13:14:03 +0200 | [diff] [blame] | 65 | #define THREAD_DUMP_TMASK 0x00007FFFU |
| 66 | #define THREAD_DUMP_FSYNC 0x00008000U |
| 67 | #define THREAD_DUMP_PMASK 0x7FFF0000U |
| 68 | |
Willy Tarreau | 89ed89e | 2022-07-01 21:18:03 +0200 | [diff] [blame] | 69 | volatile unsigned int thread_dump_state = 0; |
Willy Tarreau | 55433f9 | 2022-07-15 12:48:58 +0200 | [diff] [blame] | 70 | unsigned int panic_started = 0; |
Willy Tarreau | 9b01370 | 2019-10-24 18:18:02 +0200 | [diff] [blame] | 71 | unsigned int debug_commands_issued = 0; |
Willy Tarreau | a37cb18 | 2019-07-31 19:20:39 +0200 | [diff] [blame] | 72 | |
Willy Tarreau | 123fc97 | 2021-01-22 13:52:41 +0100 | [diff] [blame] | 73 | /* dumps a backtrace of the current thread that is appended to buffer <buf>. |
| 74 | * Lines are prefixed with the string <prefix> which may be empty (used for |
| 75 | * 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] | 76 | * the function does not appear in the call stack. The <dump> argument |
| 77 | * indicates what dump state to start from, and should usually be zero. It |
| 78 | * may be among the following values: |
| 79 | * - 0: search usual callers before step 1, or directly jump to 2 |
| 80 | * - 1: skip usual callers before step 2 |
| 81 | * - 2: dump until polling loop, scheduler, or main() (excluded) |
| 82 | * - 3: end |
| 83 | * - 4-7: like 0 but stops *after* main. |
Willy Tarreau | 123fc97 | 2021-01-22 13:52:41 +0100 | [diff] [blame] | 84 | */ |
Willy Tarreau | 2bfce7e | 2021-01-22 14:48:34 +0100 | [diff] [blame] | 85 | void ha_dump_backtrace(struct buffer *buf, const char *prefix, int dump) |
Willy Tarreau | 123fc97 | 2021-01-22 13:52:41 +0100 | [diff] [blame] | 86 | { |
| 87 | struct buffer bak; |
| 88 | char pfx2[100]; |
| 89 | void *callers[100]; |
| 90 | int j, nptrs; |
| 91 | const void *addr; |
Willy Tarreau | 123fc97 | 2021-01-22 13:52:41 +0100 | [diff] [blame] | 92 | |
| 93 | nptrs = my_backtrace(callers, sizeof(callers)/sizeof(*callers)); |
| 94 | if (!nptrs) |
| 95 | return; |
| 96 | |
| 97 | if (snprintf(pfx2, sizeof(pfx2), "%s| ", prefix) > sizeof(pfx2)) |
| 98 | pfx2[0] = 0; |
| 99 | |
| 100 | /* The call backtrace_symbols_fd(callers, nptrs, STDOUT_FILENO would |
| 101 | * produce similar output to the following: |
| 102 | */ |
| 103 | chunk_appendf(buf, "%scall trace(%d):\n", prefix, nptrs); |
Willy Tarreau | 2bfce7e | 2021-01-22 14:48:34 +0100 | [diff] [blame] | 104 | for (j = 0; (j < nptrs || (dump & 3) < 2); j++) { |
| 105 | if (j == nptrs && !(dump & 3)) { |
Willy Tarreau | 123fc97 | 2021-01-22 13:52:41 +0100 | [diff] [blame] | 106 | /* we failed to spot the starting point of the |
| 107 | * dump, let's start over dumping everything we |
| 108 | * have. |
| 109 | */ |
Willy Tarreau | 2bfce7e | 2021-01-22 14:48:34 +0100 | [diff] [blame] | 110 | dump += 2; |
Willy Tarreau | 123fc97 | 2021-01-22 13:52:41 +0100 | [diff] [blame] | 111 | j = 0; |
| 112 | } |
| 113 | bak = *buf; |
| 114 | dump_addr_and_bytes(buf, pfx2, callers[j], 8); |
| 115 | addr = resolve_sym_name(buf, ": ", callers[j]); |
Willy Tarreau | 2bfce7e | 2021-01-22 14:48:34 +0100 | [diff] [blame] | 116 | if ((dump & 3) == 0) { |
Willy Tarreau | 123fc97 | 2021-01-22 13:52:41 +0100 | [diff] [blame] | 117 | /* dump not started, will start *after* |
Willy Tarreau | a8459b2 | 2021-01-22 14:12:27 +0100 | [diff] [blame] | 118 | * 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] | 119 | */ |
Willy Tarreau | a8459b2 | 2021-01-22 14:12:27 +0100 | [diff] [blame] | 120 | if (addr == ha_thread_dump_all_to_trash || addr == ha_panic || |
| 121 | addr == ha_backtrace_to_stderr) |
Willy Tarreau | 2bfce7e | 2021-01-22 14:48:34 +0100 | [diff] [blame] | 122 | dump++; |
Willy Tarreau | 123fc97 | 2021-01-22 13:52:41 +0100 | [diff] [blame] | 123 | *buf = bak; |
| 124 | continue; |
| 125 | } |
| 126 | |
Willy Tarreau | 2bfce7e | 2021-01-22 14:48:34 +0100 | [diff] [blame] | 127 | if ((dump & 3) == 1) { |
Willy Tarreau | 123fc97 | 2021-01-22 13:52:41 +0100 | [diff] [blame] | 128 | /* starting */ |
Willy Tarreau | a8459b2 | 2021-01-22 14:12:27 +0100 | [diff] [blame] | 129 | if (addr == ha_thread_dump_all_to_trash || addr == ha_panic || |
| 130 | addr == ha_backtrace_to_stderr) { |
Willy Tarreau | 123fc97 | 2021-01-22 13:52:41 +0100 | [diff] [blame] | 131 | *buf = bak; |
| 132 | continue; |
| 133 | } |
Willy Tarreau | 2bfce7e | 2021-01-22 14:48:34 +0100 | [diff] [blame] | 134 | dump++; |
Willy Tarreau | 123fc97 | 2021-01-22 13:52:41 +0100 | [diff] [blame] | 135 | } |
| 136 | |
Willy Tarreau | 2bfce7e | 2021-01-22 14:48:34 +0100 | [diff] [blame] | 137 | if ((dump & 3) == 2) { |
| 138 | /* still dumping */ |
| 139 | if (dump == 6) { |
| 140 | /* we only stop *after* main and we must send the LF */ |
| 141 | if (addr == main) { |
| 142 | j = nptrs; |
| 143 | dump++; |
| 144 | } |
| 145 | } |
| 146 | else if (addr == run_poll_loop || addr == main || addr == run_tasks_from_lists) { |
| 147 | dump++; |
Willy Tarreau | 123fc97 | 2021-01-22 13:52:41 +0100 | [diff] [blame] | 148 | *buf = bak; |
| 149 | break; |
| 150 | } |
| 151 | } |
| 152 | /* OK, line dumped */ |
| 153 | chunk_appendf(buf, "\n"); |
| 154 | } |
| 155 | } |
| 156 | |
Willy Tarreau | a8459b2 | 2021-01-22 14:12:27 +0100 | [diff] [blame] | 157 | /* dump a backtrace of current thread's stack to stderr. */ |
Willy Tarreau | 7831e02 | 2022-05-06 15:16:19 +0200 | [diff] [blame] | 158 | void ha_backtrace_to_stderr(void) |
Willy Tarreau | a8459b2 | 2021-01-22 14:12:27 +0100 | [diff] [blame] | 159 | { |
| 160 | char area[2048]; |
| 161 | struct buffer b = b_make(area, sizeof(area), 0, 0); |
| 162 | |
Willy Tarreau | 2bfce7e | 2021-01-22 14:48:34 +0100 | [diff] [blame] | 163 | ha_dump_backtrace(&b, " ", 4); |
Willy Tarreau | a8459b2 | 2021-01-22 14:12:27 +0100 | [diff] [blame] | 164 | if (b.data) |
Willy Tarreau | 2cbe2e7 | 2021-01-22 15:58:26 +0100 | [diff] [blame] | 165 | DISGUISE(write(2, b.area, b.data)); |
Willy Tarreau | a8459b2 | 2021-01-22 14:12:27 +0100 | [diff] [blame] | 166 | } |
| 167 | |
Willy Tarreau | 5cf64dd | 2019-05-17 10:36:08 +0200 | [diff] [blame] | 168 | /* Dumps to the buffer some known information for the desired thread, and |
| 169 | * optionally extra info for the current thread. The dump will be appended to |
| 170 | * the buffer, so the caller is responsible for preliminary initializing it. |
| 171 | * 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] | 172 | * in front of the calling thread's line (usually it's tid). Any stuck thread |
| 173 | * is also prefixed with a '>'. |
Willy Tarreau | bdcd325 | 2022-06-22 09:19:46 +0200 | [diff] [blame] | 174 | * It must be called under thread isolation. |
Willy Tarreau | 4e2b646 | 2019-05-16 17:44:30 +0200 | [diff] [blame] | 175 | */ |
Willy Tarreau | 5cf64dd | 2019-05-17 10:36:08 +0200 | [diff] [blame] | 176 | void ha_thread_dump(struct buffer *buf, int thr, int calling_tid) |
Willy Tarreau | 4e2b646 | 2019-05-16 17:44:30 +0200 | [diff] [blame] | 177 | { |
Willy Tarreau | 38d0712 | 2022-06-27 16:13:50 +0200 | [diff] [blame] | 178 | unsigned long thr_bit = ha_thread_info[thr].ltid_bit; |
Willy Tarreau | 45c38e2 | 2021-09-30 18:28:49 +0200 | [diff] [blame] | 179 | unsigned long long p = ha_thread_ctx[thr].prev_cpu_time; |
Willy Tarreau | 2169498 | 2021-10-08 15:09:17 +0200 | [diff] [blame] | 180 | unsigned long long n = now_cpu_time_thread(thr); |
Willy Tarreau | a0b9953 | 2021-09-30 18:48:37 +0200 | [diff] [blame] | 181 | int stuck = !!(ha_thread_ctx[thr].flags & TH_FL_STUCK); |
Willy Tarreau | 03f9b35 | 2022-06-27 16:02:24 +0200 | [diff] [blame] | 182 | int tgrp = ha_thread_info[thr].tgid; |
Willy Tarreau | 4e2b646 | 2019-05-16 17:44:30 +0200 | [diff] [blame] | 183 | |
Willy Tarreau | 5cf64dd | 2019-05-17 10:36:08 +0200 | [diff] [blame] | 184 | chunk_appendf(buf, |
Willy Tarreau | f0e5da2 | 2020-05-01 12:26:03 +0200 | [diff] [blame] | 185 | "%c%cThread %-2u: id=0x%llx act=%d glob=%d wq=%d rq=%d tl=%d tlsz=%d rqsz=%d\n" |
Willy Tarreau | a3870b7 | 2021-09-13 19:24:47 +0200 | [diff] [blame] | 186 | " %2u/%-2u stuck=%d prof=%d", |
Willy Tarreau | e6a02fa | 2019-05-22 07:06:44 +0200 | [diff] [blame] | 187 | (thr == calling_tid) ? '*' : ' ', stuck ? '>' : ' ', thr + 1, |
Willy Tarreau | ff64d3b | 2020-05-01 11:28:49 +0200 | [diff] [blame] | 188 | ha_get_pthread_id(thr), |
Olivier Houchard | cfbb3e6 | 2019-05-29 19:22:43 +0200 | [diff] [blame] | 189 | thread_has_tasks(), |
Willy Tarreau | c958c70 | 2022-06-16 15:59:36 +0200 | [diff] [blame] | 190 | !eb_is_empty(&ha_thread_ctx[thr].rqueue_shared), |
Willy Tarreau | 1a9c922 | 2021-10-01 11:30:33 +0200 | [diff] [blame] | 191 | !eb_is_empty(&ha_thread_ctx[thr].timers), |
| 192 | !eb_is_empty(&ha_thread_ctx[thr].rqueue), |
| 193 | !(LIST_ISEMPTY(&ha_thread_ctx[thr].tasklets[TL_URGENT]) && |
| 194 | LIST_ISEMPTY(&ha_thread_ctx[thr].tasklets[TL_NORMAL]) && |
| 195 | LIST_ISEMPTY(&ha_thread_ctx[thr].tasklets[TL_BULK]) && |
| 196 | MT_LIST_ISEMPTY(&ha_thread_ctx[thr].shared_tasklet_list)), |
| 197 | ha_thread_ctx[thr].tasks_in_list, |
| 198 | ha_thread_ctx[thr].rq_total, |
Willy Tarreau | 66ad98a | 2022-06-28 10:49:57 +0200 | [diff] [blame] | 199 | ha_thread_info[thr].tgid, ha_thread_info[thr].ltid + 1, |
Willy Tarreau | e6a02fa | 2019-05-22 07:06:44 +0200 | [diff] [blame] | 200 | stuck, |
Willy Tarreau | b30ced3 | 2023-05-04 11:30:55 +0200 | [diff] [blame] | 201 | !!(ha_thread_ctx[thr].flags & TH_FL_TASK_PROFILING)); |
Willy Tarreau | 4e2b646 | 2019-05-16 17:44:30 +0200 | [diff] [blame] | 202 | |
Willy Tarreau | 5cf64dd | 2019-05-17 10:36:08 +0200 | [diff] [blame] | 203 | chunk_appendf(buf, |
Willy Tarreau | b30ced3 | 2023-05-04 11:30:55 +0200 | [diff] [blame] | 204 | " harmless=%d isolated=%d", |
Willy Tarreau | 03f9b35 | 2022-06-27 16:02:24 +0200 | [diff] [blame] | 205 | !!(_HA_ATOMIC_LOAD(&ha_tgroup_ctx[tgrp-1].threads_harmless) & thr_bit), |
Willy Tarreau | b30ced3 | 2023-05-04 11:30:55 +0200 | [diff] [blame] | 206 | isolated_thread == thr); |
Willy Tarreau | 4e2b646 | 2019-05-16 17:44:30 +0200 | [diff] [blame] | 207 | |
Willy Tarreau | 5cf64dd | 2019-05-17 10:36:08 +0200 | [diff] [blame] | 208 | chunk_appendf(buf, "\n"); |
Willy Tarreau | 9c8800a | 2019-05-20 20:52:20 +0200 | [diff] [blame] | 209 | 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] | 210 | |
Willy Tarreau | a3870b7 | 2021-09-13 19:24:47 +0200 | [diff] [blame] | 211 | /* this is the end of what we can dump from outside the current thread */ |
Willy Tarreau | 4e2b646 | 2019-05-16 17:44:30 +0200 | [diff] [blame] | 212 | |
| 213 | if (thr != tid) |
| 214 | return; |
| 215 | |
Willy Tarreau | 5cf64dd | 2019-05-17 10:36:08 +0200 | [diff] [blame] | 216 | chunk_appendf(buf, " curr_task="); |
Willy Tarreau | 1a9c922 | 2021-10-01 11:30:33 +0200 | [diff] [blame] | 217 | ha_task_dump(buf, th_ctx->current, " "); |
Willy Tarreau | f5b4e06 | 2020-03-03 15:40:23 +0100 | [diff] [blame] | 218 | |
Willy Tarreau | f5b4e06 | 2020-03-03 15:40:23 +0100 | [diff] [blame] | 219 | if (stuck) { |
| 220 | /* We only emit the backtrace for stuck threads in order not to |
| 221 | * waste precious output buffer space with non-interesting data. |
Willy Tarreau | 123fc97 | 2021-01-22 13:52:41 +0100 | [diff] [blame] | 222 | * Please leave this as the last instruction in this function |
| 223 | * so that the compiler uses tail merging and the current |
| 224 | * function does not appear in the stack. |
Willy Tarreau | f5b4e06 | 2020-03-03 15:40:23 +0100 | [diff] [blame] | 225 | */ |
Willy Tarreau | 2bfce7e | 2021-01-22 14:48:34 +0100 | [diff] [blame] | 226 | ha_dump_backtrace(buf, " ", 0); |
Willy Tarreau | f5b4e06 | 2020-03-03 15:40:23 +0100 | [diff] [blame] | 227 | } |
Willy Tarreau | 4e2b646 | 2019-05-16 17:44:30 +0200 | [diff] [blame] | 228 | } |
| 229 | |
| 230 | |
Willy Tarreau | 5cf64dd | 2019-05-17 10:36:08 +0200 | [diff] [blame] | 231 | /* dumps into the buffer some information related to task <task> (which may |
Willy Tarreau | 4e2b646 | 2019-05-16 17:44:30 +0200 | [diff] [blame] | 232 | * 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] | 233 | * with <pfx>. The buffer is only appended and the first output starts by the |
| 234 | * pointer itself. The caller is responsible for making sure the task is not |
| 235 | * going to vanish during the dump. |
Willy Tarreau | 4e2b646 | 2019-05-16 17:44:30 +0200 | [diff] [blame] | 236 | */ |
Willy Tarreau | 5cf64dd | 2019-05-17 10:36:08 +0200 | [diff] [blame] | 237 | 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] | 238 | { |
Willy Tarreau | 578ea8b | 2019-05-22 09:43:09 +0200 | [diff] [blame] | 239 | const struct stream *s = NULL; |
Willy Tarreau | a512b02 | 2019-08-21 14:12:19 +0200 | [diff] [blame] | 240 | const struct appctx __maybe_unused *appctx = NULL; |
Willy Tarreau | 78a7cb6 | 2019-08-21 14:16:02 +0200 | [diff] [blame] | 241 | struct hlua __maybe_unused *hlua = NULL; |
Willy Tarreau | 52f238d | 2022-07-15 12:08:40 +0200 | [diff] [blame] | 242 | const struct stconn *sc; |
Willy Tarreau | 578ea8b | 2019-05-22 09:43:09 +0200 | [diff] [blame] | 243 | |
Willy Tarreau | 14a1ab7 | 2019-05-17 10:34:25 +0200 | [diff] [blame] | 244 | if (!task) { |
Willy Tarreau | 5cf64dd | 2019-05-17 10:36:08 +0200 | [diff] [blame] | 245 | chunk_appendf(buf, "0\n"); |
Willy Tarreau | 231ec39 | 2019-05-17 10:39:47 +0200 | [diff] [blame] | 246 | return; |
| 247 | } |
| 248 | |
Willy Tarreau | 20db911 | 2019-05-17 14:14:35 +0200 | [diff] [blame] | 249 | if (TASK_IS_TASKLET(task)) |
| 250 | chunk_appendf(buf, |
| 251 | "%p (tasklet) calls=%u\n", |
| 252 | task, |
| 253 | task->calls); |
| 254 | else |
| 255 | chunk_appendf(buf, |
| 256 | "%p (task) calls=%u last=%llu%s\n", |
| 257 | task, |
| 258 | task->calls, |
Willy Tarreau | 04e50b3 | 2022-09-07 14:49:50 +0200 | [diff] [blame] | 259 | task->wake_date ? (unsigned long long)(now_mono_time() - task->wake_date) : 0, |
| 260 | task->wake_date ? " ns ago" : ""); |
Willy Tarreau | 4e2b646 | 2019-05-16 17:44:30 +0200 | [diff] [blame] | 261 | |
Willy Tarreau | 2e89b09 | 2020-03-03 17:13:02 +0100 | [diff] [blame] | 262 | chunk_appendf(buf, "%s fct=%p(", pfx, task->process); |
| 263 | resolve_sym_name(buf, NULL, task->process); |
| 264 | chunk_appendf(buf,") ctx=%p", task->context); |
Willy Tarreau | 578ea8b | 2019-05-22 09:43:09 +0200 | [diff] [blame] | 265 | |
Willy Tarreau | a512b02 | 2019-08-21 14:12:19 +0200 | [diff] [blame] | 266 | if (task->process == task_run_applet && (appctx = task->context)) |
| 267 | chunk_appendf(buf, "(%s)\n", appctx->applet->name); |
| 268 | else |
| 269 | chunk_appendf(buf, "\n"); |
| 270 | |
Willy Tarreau | 578ea8b | 2019-05-22 09:43:09 +0200 | [diff] [blame] | 271 | if (task->process == process_stream && task->context) |
| 272 | s = (struct stream *)task->context; |
Willy Tarreau | 52f238d | 2022-07-15 12:08:40 +0200 | [diff] [blame] | 273 | else if (task->process == task_run_applet && task->context && (sc = appctx_sc((struct appctx *)task->context))) |
| 274 | s = sc_strm(sc); |
Willy Tarreau | 462b989 | 2022-05-18 18:06:53 +0200 | [diff] [blame] | 275 | else if (task->process == sc_conn_io_cb && task->context) |
Willy Tarreau | ea27f48 | 2022-05-18 16:10:52 +0200 | [diff] [blame] | 276 | s = sc_strm(((struct stconn *)task->context)); |
Willy Tarreau | 578ea8b | 2019-05-22 09:43:09 +0200 | [diff] [blame] | 277 | |
| 278 | if (s) |
| 279 | stream_dump(buf, s, pfx, '\n'); |
Willy Tarreau | 78a7cb6 | 2019-08-21 14:16:02 +0200 | [diff] [blame] | 280 | |
| 281 | #ifdef USE_LUA |
| 282 | hlua = NULL; |
| 283 | if (s && (hlua = s->hlua)) { |
| 284 | chunk_appendf(buf, "%sCurrent executing Lua from a stream analyser -- ", pfx); |
| 285 | } |
| 286 | else if (task->process == hlua_process_task && (hlua = task->context)) { |
| 287 | chunk_appendf(buf, "%sCurrent executing a Lua task -- ", pfx); |
| 288 | } |
| 289 | else if (task->process == task_run_applet && (appctx = task->context) && |
Willy Tarreau | e23f33b | 2022-05-06 14:07:13 +0200 | [diff] [blame] | 290 | (appctx->applet->fct == hlua_applet_tcp_fct)) { |
Willy Tarreau | 78a7cb6 | 2019-08-21 14:16:02 +0200 | [diff] [blame] | 291 | chunk_appendf(buf, "%sCurrent executing a Lua TCP service -- ", pfx); |
| 292 | } |
| 293 | else if (task->process == task_run_applet && (appctx = task->context) && |
Willy Tarreau | aa229cc | 2022-05-06 14:26:10 +0200 | [diff] [blame] | 294 | (appctx->applet->fct == hlua_applet_http_fct)) { |
Willy Tarreau | 78a7cb6 | 2019-08-21 14:16:02 +0200 | [diff] [blame] | 295 | chunk_appendf(buf, "%sCurrent executing a Lua HTTP service -- ", pfx); |
| 296 | } |
| 297 | |
Christopher Faulet | 471425f | 2020-07-24 19:08:05 +0200 | [diff] [blame] | 298 | if (hlua && hlua->T) { |
Christopher Faulet | cc2c4f8 | 2021-03-24 14:52:24 +0100 | [diff] [blame] | 299 | chunk_appendf(buf, "stack traceback:\n "); |
| 300 | append_prefixed_str(buf, hlua_traceback(hlua->T, "\n "), pfx, '\n', 0); |
| 301 | b_putchr(buf, '\n'); |
Willy Tarreau | 78a7cb6 | 2019-08-21 14:16:02 +0200 | [diff] [blame] | 302 | } |
Christopher Faulet | 471425f | 2020-07-24 19:08:05 +0200 | [diff] [blame] | 303 | else |
| 304 | b_putchr(buf, '\n'); |
Willy Tarreau | 78a7cb6 | 2019-08-21 14:16:02 +0200 | [diff] [blame] | 305 | #endif |
Willy Tarreau | 4e2b646 | 2019-05-16 17:44:30 +0200 | [diff] [blame] | 306 | } |
| 307 | |
Willy Tarreau | 4e2b646 | 2019-05-16 17:44:30 +0200 | [diff] [blame] | 308 | /* This function dumps all profiling settings. It returns 0 if the output |
| 309 | * buffer is full and it needs to be called again, otherwise non-zero. |
| 310 | */ |
| 311 | static int cli_io_handler_show_threads(struct appctx *appctx) |
| 312 | { |
Willy Tarreau | c12b321 | 2022-05-27 11:08:15 +0200 | [diff] [blame] | 313 | struct stconn *sc = appctx_sc(appctx); |
Willy Tarreau | 4e2b646 | 2019-05-16 17:44:30 +0200 | [diff] [blame] | 314 | int thr; |
| 315 | |
Christopher Faulet | 87633c3 | 2023-04-03 18:32:50 +0200 | [diff] [blame] | 316 | /* FIXME: Don't watch the other side !*/ |
Christopher Faulet | 208c712 | 2023-04-13 16:16:15 +0200 | [diff] [blame] | 317 | if (unlikely(sc_opposite(sc)->flags & SC_FL_SHUT_DONE)) |
Willy Tarreau | 4e2b646 | 2019-05-16 17:44:30 +0200 | [diff] [blame] | 318 | return 1; |
| 319 | |
| 320 | if (appctx->st0) |
| 321 | thr = appctx->st1; |
| 322 | else |
| 323 | thr = 0; |
| 324 | |
Willy Tarreau | 5cf64dd | 2019-05-17 10:36:08 +0200 | [diff] [blame] | 325 | chunk_reset(&trash); |
Willy Tarreau | c7091d8 | 2019-05-17 10:08:49 +0200 | [diff] [blame] | 326 | ha_thread_dump_all_to_trash(); |
Willy Tarreau | 5cf64dd | 2019-05-17 10:36:08 +0200 | [diff] [blame] | 327 | |
Willy Tarreau | d0a06d5 | 2022-05-18 15:07:19 +0200 | [diff] [blame] | 328 | if (applet_putchk(appctx, &trash) == -1) { |
Willy Tarreau | 5cf64dd | 2019-05-17 10:36:08 +0200 | [diff] [blame] | 329 | /* failed, try again */ |
Willy Tarreau | 5cf64dd | 2019-05-17 10:36:08 +0200 | [diff] [blame] | 330 | appctx->st1 = thr; |
| 331 | return 0; |
| 332 | } |
Willy Tarreau | 4e2b646 | 2019-05-16 17:44:30 +0200 | [diff] [blame] | 333 | return 1; |
| 334 | } |
| 335 | |
Willy Tarreau | 6ab7b21 | 2021-12-28 09:57:10 +0100 | [diff] [blame] | 336 | #if defined(HA_HAVE_DUMP_LIBS) |
| 337 | /* parse a "show libs" command. It returns 1 if it emits anything otherwise zero. */ |
| 338 | static int debug_parse_cli_show_libs(char **args, char *payload, struct appctx *appctx, void *private) |
| 339 | { |
| 340 | if (!cli_has_level(appctx, ACCESS_LVL_OPER)) |
| 341 | return 1; |
| 342 | |
| 343 | chunk_reset(&trash); |
| 344 | if (dump_libs(&trash, 1)) |
| 345 | return cli_msg(appctx, LOG_INFO, trash.area); |
| 346 | else |
| 347 | return 0; |
| 348 | } |
| 349 | #endif |
| 350 | |
Willy Tarreau | 56131ca | 2019-05-20 13:48:29 +0200 | [diff] [blame] | 351 | /* dumps a state of all threads into the trash and on fd #2, then aborts. */ |
| 352 | void ha_panic() |
| 353 | { |
Willy Tarreau | 55433f9 | 2022-07-15 12:48:58 +0200 | [diff] [blame] | 354 | if (HA_ATOMIC_FETCH_ADD(&panic_started, 1) != 0) { |
| 355 | /* a panic dump is already in progress, let's not disturb it, |
| 356 | * we'll be called via signal DEBUGSIG. By returning we may be |
| 357 | * able to leave a current signal handler (e.g. WDT) so that |
| 358 | * this will ensure more reliable signal delivery. |
| 359 | */ |
| 360 | return; |
| 361 | } |
Willy Tarreau | 56131ca | 2019-05-20 13:48:29 +0200 | [diff] [blame] | 362 | chunk_reset(&trash); |
Willy Tarreau | a9f9fc9 | 2019-05-20 17:45:35 +0200 | [diff] [blame] | 363 | 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] | 364 | ha_thread_dump_all_to_trash(); |
Willy Tarreau | 2e8ab6b | 2020-03-14 11:03:20 +0100 | [diff] [blame] | 365 | DISGUISE(write(2, trash.area, trash.data)); |
Willy Tarreau | 56131ca | 2019-05-20 13:48:29 +0200 | [diff] [blame] | 366 | for (;;) |
| 367 | abort(); |
| 368 | } |
| 369 | |
Willy Tarreau | 06e66c8 | 2022-03-02 15:52:03 +0100 | [diff] [blame] | 370 | /* Complain with message <msg> on stderr. If <counter> is not NULL, it is |
| 371 | * atomically incremented, and the message is only printed when the counter |
| 372 | * was zero, so that the message is only printed once. <taint> is only checked |
| 373 | * on bit 1, and will taint the process either for a bug (2) or warn (0). |
| 374 | */ |
| 375 | void complain(int *counter, const char *msg, int taint) |
| 376 | { |
| 377 | if (counter && _HA_ATOMIC_FETCH_ADD(counter, 1)) |
| 378 | return; |
| 379 | DISGUISE(write(2, msg, strlen(msg))); |
| 380 | if (taint & 2) |
| 381 | mark_tainted(TAINTED_BUG); |
| 382 | else |
| 383 | mark_tainted(TAINTED_WARN); |
| 384 | } |
| 385 | |
Willy Tarreau | 6bdf3e9 | 2019-05-20 14:25:05 +0200 | [diff] [blame] | 386 | /* parse a "debug dev exit" command. It always returns 1, though it should never return. */ |
| 387 | static int debug_parse_cli_exit(char **args, char *payload, struct appctx *appctx, void *private) |
| 388 | { |
| 389 | int code = 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 | exit(code); |
| 396 | return 1; |
| 397 | } |
| 398 | |
Willy Tarreau | 5baf4fe | 2021-01-22 14:15:46 +0100 | [diff] [blame] | 399 | /* parse a "debug dev bug" command. It always returns 1, though it should never return. |
| 400 | * Note: we make sure not to make the function static so that it appears in the trace. |
| 401 | */ |
| 402 | int debug_parse_cli_bug(char **args, char *payload, struct appctx *appctx, void *private) |
| 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 | 5baf4fe | 2021-01-22 14:15:46 +0100 | [diff] [blame] | 408 | BUG_ON(one > zero); |
| 409 | return 1; |
| 410 | } |
| 411 | |
Willy Tarreau | 305cfbd | 2022-02-25 08:52:39 +0100 | [diff] [blame] | 412 | /* parse a "debug dev warn" command. It always returns 1. |
| 413 | * Note: we make sure not to make the function static so that it appears in the trace. |
| 414 | */ |
| 415 | int debug_parse_cli_warn(char **args, char *payload, struct appctx *appctx, void *private) |
| 416 | { |
| 417 | if (!cli_has_level(appctx, ACCESS_LVL_ADMIN)) |
| 418 | return 1; |
| 419 | |
| 420 | _HA_ATOMIC_INC(&debug_commands_issued); |
| 421 | WARN_ON(one > zero); |
| 422 | return 1; |
| 423 | } |
| 424 | |
Willy Tarreau | 6d3f1e3 | 2022-02-28 11:51:23 +0100 | [diff] [blame] | 425 | /* parse a "debug dev check" command. It always returns 1. |
Willy Tarreau | 4e0a8b1 | 2022-02-25 08:55:11 +0100 | [diff] [blame] | 426 | * Note: we make sure not to make the function static so that it appears in the trace. |
| 427 | */ |
Willy Tarreau | 6d3f1e3 | 2022-02-28 11:51:23 +0100 | [diff] [blame] | 428 | int debug_parse_cli_check(char **args, char *payload, struct appctx *appctx, void *private) |
Willy Tarreau | 4e0a8b1 | 2022-02-25 08:55:11 +0100 | [diff] [blame] | 429 | { |
| 430 | if (!cli_has_level(appctx, ACCESS_LVL_ADMIN)) |
| 431 | return 1; |
| 432 | |
| 433 | _HA_ATOMIC_INC(&debug_commands_issued); |
Willy Tarreau | 6d3f1e3 | 2022-02-28 11:51:23 +0100 | [diff] [blame] | 434 | CHECK_IF(one > zero); |
Willy Tarreau | 4e0a8b1 | 2022-02-25 08:55:11 +0100 | [diff] [blame] | 435 | return 1; |
| 436 | } |
| 437 | |
Willy Tarreau | 6bdf3e9 | 2019-05-20 14:25:05 +0200 | [diff] [blame] | 438 | /* parse a "debug dev close" command. It always returns 1. */ |
| 439 | static int debug_parse_cli_close(char **args, char *payload, struct appctx *appctx, void *private) |
| 440 | { |
| 441 | int fd; |
| 442 | |
| 443 | if (!cli_has_level(appctx, ACCESS_LVL_ADMIN)) |
| 444 | return 1; |
| 445 | |
Willy Tarreau | 9d00869 | 2019-08-09 11:21:01 +0200 | [diff] [blame] | 446 | if (!*args[3]) |
| 447 | return cli_err(appctx, "Missing file descriptor number.\n"); |
Willy Tarreau | 6bdf3e9 | 2019-05-20 14:25:05 +0200 | [diff] [blame] | 448 | |
| 449 | fd = atoi(args[3]); |
Willy Tarreau | 9d00869 | 2019-08-09 11:21:01 +0200 | [diff] [blame] | 450 | if (fd < 0 || fd >= global.maxsock) |
| 451 | return cli_err(appctx, "File descriptor out of range.\n"); |
Willy Tarreau | 6bdf3e9 | 2019-05-20 14:25:05 +0200 | [diff] [blame] | 452 | |
Willy Tarreau | 9d00869 | 2019-08-09 11:21:01 +0200 | [diff] [blame] | 453 | if (!fdtab[fd].owner) |
| 454 | return cli_msg(appctx, LOG_INFO, "File descriptor was already closed.\n"); |
Willy Tarreau | 6bdf3e9 | 2019-05-20 14:25:05 +0200 | [diff] [blame] | 455 | |
Willy Tarreau | 4781b15 | 2021-04-06 13:53:36 +0200 | [diff] [blame] | 456 | _HA_ATOMIC_INC(&debug_commands_issued); |
Willy Tarreau | 6bdf3e9 | 2019-05-20 14:25:05 +0200 | [diff] [blame] | 457 | fd_delete(fd); |
| 458 | return 1; |
Willy Tarreau | 6bdf3e9 | 2019-05-20 14:25:05 +0200 | [diff] [blame] | 459 | } |
| 460 | |
Willy Tarreau | dadf00e | 2022-07-15 08:25:03 +0200 | [diff] [blame] | 461 | /* this is meant to cause a deadlock when more than one task is running it or when run twice */ |
| 462 | static struct task *debug_run_cli_deadlock(struct task *task, void *ctx, unsigned int state) |
| 463 | { |
| 464 | static HA_SPINLOCK_T lock __maybe_unused; |
| 465 | |
| 466 | HA_SPIN_LOCK(OTHER_LOCK, &lock); |
| 467 | return NULL; |
| 468 | } |
| 469 | |
| 470 | /* parse a "debug dev deadlock" command. It always returns 1. */ |
| 471 | static int debug_parse_cli_deadlock(char **args, char *payload, struct appctx *appctx, void *private) |
| 472 | { |
| 473 | int tasks; |
| 474 | |
| 475 | if (!cli_has_level(appctx, ACCESS_LVL_ADMIN)) |
| 476 | return 1; |
| 477 | |
| 478 | _HA_ATOMIC_INC(&debug_commands_issued); |
| 479 | for (tasks = atoi(args[3]); tasks > 0; tasks--) { |
| 480 | struct task *t = task_new_on(tasks % global.nbthread); |
| 481 | if (!t) |
| 482 | continue; |
| 483 | t->process = debug_run_cli_deadlock; |
| 484 | t->context = NULL; |
| 485 | task_wakeup(t, TASK_WOKEN_INIT); |
| 486 | } |
| 487 | |
| 488 | return 1; |
| 489 | } |
| 490 | |
Willy Tarreau | 6bdf3e9 | 2019-05-20 14:25:05 +0200 | [diff] [blame] | 491 | /* parse a "debug dev delay" command. It always returns 1. */ |
| 492 | static int debug_parse_cli_delay(char **args, char *payload, struct appctx *appctx, void *private) |
| 493 | { |
| 494 | int delay = atoi(args[3]); |
| 495 | |
| 496 | if (!cli_has_level(appctx, ACCESS_LVL_ADMIN)) |
| 497 | return 1; |
| 498 | |
Willy Tarreau | 4781b15 | 2021-04-06 13:53:36 +0200 | [diff] [blame] | 499 | _HA_ATOMIC_INC(&debug_commands_issued); |
Willy Tarreau | 6bdf3e9 | 2019-05-20 14:25:05 +0200 | [diff] [blame] | 500 | usleep((long)delay * 1000); |
| 501 | return 1; |
| 502 | } |
| 503 | |
| 504 | /* parse a "debug dev log" command. It always returns 1. */ |
| 505 | static int debug_parse_cli_log(char **args, char *payload, struct appctx *appctx, void *private) |
| 506 | { |
| 507 | int arg; |
| 508 | |
| 509 | if (!cli_has_level(appctx, ACCESS_LVL_ADMIN)) |
| 510 | return 1; |
| 511 | |
Willy Tarreau | 4781b15 | 2021-04-06 13:53:36 +0200 | [diff] [blame] | 512 | _HA_ATOMIC_INC(&debug_commands_issued); |
Willy Tarreau | 6bdf3e9 | 2019-05-20 14:25:05 +0200 | [diff] [blame] | 513 | chunk_reset(&trash); |
| 514 | for (arg = 3; *args[arg]; arg++) { |
| 515 | if (arg > 3) |
| 516 | chunk_strcat(&trash, " "); |
| 517 | chunk_strcat(&trash, args[arg]); |
| 518 | } |
| 519 | |
| 520 | send_log(NULL, LOG_INFO, "%s\n", trash.area); |
| 521 | return 1; |
| 522 | } |
| 523 | |
| 524 | /* parse a "debug dev loop" command. It always returns 1. */ |
| 525 | static int debug_parse_cli_loop(char **args, char *payload, struct appctx *appctx, void *private) |
| 526 | { |
| 527 | struct timeval deadline, curr; |
| 528 | int loop = atoi(args[3]); |
Willy Tarreau | e5e6223 | 2023-05-04 11:50:26 +0200 | [diff] [blame] | 529 | int isolate; |
Willy Tarreau | 6bdf3e9 | 2019-05-20 14:25:05 +0200 | [diff] [blame] | 530 | |
| 531 | if (!cli_has_level(appctx, ACCESS_LVL_ADMIN)) |
| 532 | return 1; |
| 533 | |
Willy Tarreau | e5e6223 | 2023-05-04 11:50:26 +0200 | [diff] [blame] | 534 | isolate = strcmp(args[4], "isolated") == 0; |
| 535 | |
Willy Tarreau | 4781b15 | 2021-04-06 13:53:36 +0200 | [diff] [blame] | 536 | _HA_ATOMIC_INC(&debug_commands_issued); |
Willy Tarreau | 6bdf3e9 | 2019-05-20 14:25:05 +0200 | [diff] [blame] | 537 | gettimeofday(&curr, NULL); |
| 538 | tv_ms_add(&deadline, &curr, loop); |
| 539 | |
Willy Tarreau | e5e6223 | 2023-05-04 11:50:26 +0200 | [diff] [blame] | 540 | if (isolate) |
| 541 | thread_isolate(); |
| 542 | |
Willy Tarreau | 6bdf3e9 | 2019-05-20 14:25:05 +0200 | [diff] [blame] | 543 | while (tv_ms_cmp(&curr, &deadline) < 0) |
| 544 | gettimeofday(&curr, NULL); |
| 545 | |
Willy Tarreau | e5e6223 | 2023-05-04 11:50:26 +0200 | [diff] [blame] | 546 | if (isolate) |
| 547 | thread_release(); |
| 548 | |
Willy Tarreau | 6bdf3e9 | 2019-05-20 14:25:05 +0200 | [diff] [blame] | 549 | return 1; |
| 550 | } |
| 551 | |
| 552 | /* parse a "debug dev panic" command. It always returns 1, though it should never return. */ |
| 553 | static int debug_parse_cli_panic(char **args, char *payload, struct appctx *appctx, void *private) |
| 554 | { |
| 555 | if (!cli_has_level(appctx, ACCESS_LVL_ADMIN)) |
| 556 | return 1; |
| 557 | |
Willy Tarreau | 4781b15 | 2021-04-06 13:53:36 +0200 | [diff] [blame] | 558 | _HA_ATOMIC_INC(&debug_commands_issued); |
Willy Tarreau | 6bdf3e9 | 2019-05-20 14:25:05 +0200 | [diff] [blame] | 559 | ha_panic(); |
| 560 | return 1; |
| 561 | } |
| 562 | |
| 563 | /* parse a "debug dev exec" command. It always returns 1. */ |
Willy Tarreau | b24ab22 | 2019-10-24 18:03:39 +0200 | [diff] [blame] | 564 | #if defined(DEBUG_DEV) |
Willy Tarreau | 6bdf3e9 | 2019-05-20 14:25:05 +0200 | [diff] [blame] | 565 | static int debug_parse_cli_exec(char **args, char *payload, struct appctx *appctx, void *private) |
| 566 | { |
Willy Tarreau | 368bff4 | 2019-12-06 17:18:28 +0100 | [diff] [blame] | 567 | int pipefd[2]; |
Willy Tarreau | 6bdf3e9 | 2019-05-20 14:25:05 +0200 | [diff] [blame] | 568 | int arg; |
Willy Tarreau | 368bff4 | 2019-12-06 17:18:28 +0100 | [diff] [blame] | 569 | int pid; |
Willy Tarreau | 6bdf3e9 | 2019-05-20 14:25:05 +0200 | [diff] [blame] | 570 | |
| 571 | if (!cli_has_level(appctx, ACCESS_LVL_ADMIN)) |
| 572 | return 1; |
| 573 | |
Willy Tarreau | 4781b15 | 2021-04-06 13:53:36 +0200 | [diff] [blame] | 574 | _HA_ATOMIC_INC(&debug_commands_issued); |
Willy Tarreau | 6bdf3e9 | 2019-05-20 14:25:05 +0200 | [diff] [blame] | 575 | chunk_reset(&trash); |
| 576 | for (arg = 3; *args[arg]; arg++) { |
| 577 | if (arg > 3) |
| 578 | chunk_strcat(&trash, " "); |
| 579 | chunk_strcat(&trash, args[arg]); |
| 580 | } |
| 581 | |
Willy Tarreau | 368bff4 | 2019-12-06 17:18:28 +0100 | [diff] [blame] | 582 | thread_isolate(); |
| 583 | if (pipe(pipefd) < 0) |
| 584 | goto fail_pipe; |
Willy Tarreau | 6bdf3e9 | 2019-05-20 14:25:05 +0200 | [diff] [blame] | 585 | |
Willy Tarreau | 3824743 | 2022-04-26 10:24:14 +0200 | [diff] [blame] | 586 | if (fd_set_cloexec(pipefd[0]) == -1) |
Willy Tarreau | 368bff4 | 2019-12-06 17:18:28 +0100 | [diff] [blame] | 587 | goto fail_fcntl; |
| 588 | |
Willy Tarreau | 3824743 | 2022-04-26 10:24:14 +0200 | [diff] [blame] | 589 | if (fd_set_cloexec(pipefd[1]) == -1) |
Willy Tarreau | 368bff4 | 2019-12-06 17:18:28 +0100 | [diff] [blame] | 590 | goto fail_fcntl; |
| 591 | |
| 592 | pid = fork(); |
| 593 | |
| 594 | if (pid < 0) |
| 595 | goto fail_fork; |
| 596 | else if (pid == 0) { |
| 597 | /* child */ |
| 598 | char *cmd[4] = { "/bin/sh", "-c", 0, 0 }; |
| 599 | |
| 600 | close(0); |
| 601 | dup2(pipefd[1], 1); |
| 602 | dup2(pipefd[1], 2); |
| 603 | |
| 604 | cmd[2] = trash.area; |
| 605 | execvp(cmd[0], cmd); |
| 606 | printf("execvp() failed\n"); |
| 607 | exit(1); |
| 608 | } |
| 609 | |
| 610 | /* parent */ |
| 611 | thread_release(); |
| 612 | close(pipefd[1]); |
Willy Tarreau | 6bdf3e9 | 2019-05-20 14:25:05 +0200 | [diff] [blame] | 613 | chunk_reset(&trash); |
| 614 | while (1) { |
Willy Tarreau | 368bff4 | 2019-12-06 17:18:28 +0100 | [diff] [blame] | 615 | size_t ret = read(pipefd[0], trash.area + trash.data, trash.size - 20 - trash.data); |
| 616 | if (ret <= 0) |
Willy Tarreau | 6bdf3e9 | 2019-05-20 14:25:05 +0200 | [diff] [blame] | 617 | break; |
| 618 | trash.data += ret; |
| 619 | if (trash.data + 20 == trash.size) { |
| 620 | chunk_strcat(&trash, "\n[[[TRUNCATED]]]\n"); |
| 621 | break; |
| 622 | } |
| 623 | } |
Willy Tarreau | 368bff4 | 2019-12-06 17:18:28 +0100 | [diff] [blame] | 624 | close(pipefd[0]); |
| 625 | waitpid(pid, NULL, WNOHANG); |
Willy Tarreau | 6bdf3e9 | 2019-05-20 14:25:05 +0200 | [diff] [blame] | 626 | trash.area[trash.data] = 0; |
Willy Tarreau | 9d00869 | 2019-08-09 11:21:01 +0200 | [diff] [blame] | 627 | return cli_msg(appctx, LOG_INFO, trash.area); |
Willy Tarreau | 368bff4 | 2019-12-06 17:18:28 +0100 | [diff] [blame] | 628 | |
| 629 | fail_fork: |
| 630 | fail_fcntl: |
| 631 | close(pipefd[0]); |
| 632 | close(pipefd[1]); |
| 633 | fail_pipe: |
| 634 | thread_release(); |
| 635 | return cli_err(appctx, "Failed to execute command.\n"); |
Willy Tarreau | 6bdf3e9 | 2019-05-20 14:25:05 +0200 | [diff] [blame] | 636 | } |
Willy Tarreau | bd3b44e | 2023-03-09 08:25:01 +0100 | [diff] [blame] | 637 | |
| 638 | /* handles SIGRTMAX to inject random delays on the receiving thread in order |
| 639 | * to try to increase the likelihood to reproduce inter-thread races. The |
| 640 | * signal is periodically sent by a task initiated by "debug dev delay-inj". |
| 641 | */ |
| 642 | void debug_delay_inj_sighandler(int sig, siginfo_t *si, void *arg) |
| 643 | { |
| 644 | volatile int i = statistical_prng_range(10000); |
| 645 | |
| 646 | while (i--) |
| 647 | __ha_cpu_relax(); |
| 648 | } |
Willy Tarreau | b24ab22 | 2019-10-24 18:03:39 +0200 | [diff] [blame] | 649 | #endif |
Willy Tarreau | 6bdf3e9 | 2019-05-20 14:25:05 +0200 | [diff] [blame] | 650 | |
| 651 | /* parse a "debug dev hex" command. It always returns 1. */ |
| 652 | static int debug_parse_cli_hex(char **args, char *payload, struct appctx *appctx, void *private) |
| 653 | { |
| 654 | unsigned long start, len; |
| 655 | |
| 656 | if (!cli_has_level(appctx, ACCESS_LVL_ADMIN)) |
| 657 | return 1; |
| 658 | |
Willy Tarreau | 9d00869 | 2019-08-09 11:21:01 +0200 | [diff] [blame] | 659 | if (!*args[3]) |
| 660 | return cli_err(appctx, "Missing memory address to dump from.\n"); |
Willy Tarreau | 6bdf3e9 | 2019-05-20 14:25:05 +0200 | [diff] [blame] | 661 | |
| 662 | start = strtoul(args[3], NULL, 0); |
Willy Tarreau | 9d00869 | 2019-08-09 11:21:01 +0200 | [diff] [blame] | 663 | if (!start) |
| 664 | return cli_err(appctx, "Will not dump from NULL address.\n"); |
Willy Tarreau | 6bdf3e9 | 2019-05-20 14:25:05 +0200 | [diff] [blame] | 665 | |
Willy Tarreau | 4781b15 | 2021-04-06 13:53:36 +0200 | [diff] [blame] | 666 | _HA_ATOMIC_INC(&debug_commands_issued); |
Willy Tarreau | 9b01370 | 2019-10-24 18:18:02 +0200 | [diff] [blame] | 667 | |
Willy Tarreau | 6bdf3e9 | 2019-05-20 14:25:05 +0200 | [diff] [blame] | 668 | /* by default, dump ~128 till next block of 16 */ |
| 669 | len = strtoul(args[4], NULL, 0); |
| 670 | if (!len) |
| 671 | len = ((start + 128) & -16) - start; |
| 672 | |
| 673 | chunk_reset(&trash); |
Willy Tarreau | 3710105 | 2019-05-20 16:48:20 +0200 | [diff] [blame] | 674 | dump_hex(&trash, " ", (const void *)start, len, 1); |
Willy Tarreau | 6bdf3e9 | 2019-05-20 14:25:05 +0200 | [diff] [blame] | 675 | trash.area[trash.data] = 0; |
Willy Tarreau | 9d00869 | 2019-08-09 11:21:01 +0200 | [diff] [blame] | 676 | return cli_msg(appctx, LOG_INFO, trash.area); |
Willy Tarreau | 6bdf3e9 | 2019-05-20 14:25:05 +0200 | [diff] [blame] | 677 | } |
| 678 | |
Willy Tarreau | 48129be | 2021-05-04 18:40:50 +0200 | [diff] [blame] | 679 | /* parse a "debug dev sym <addr>" command. It always returns 1. */ |
| 680 | static int debug_parse_cli_sym(char **args, char *payload, struct appctx *appctx, void *private) |
| 681 | { |
| 682 | unsigned long addr; |
| 683 | |
| 684 | if (!cli_has_level(appctx, ACCESS_LVL_ADMIN)) |
| 685 | return 1; |
| 686 | |
| 687 | if (!*args[3]) |
| 688 | return cli_err(appctx, "Missing memory address to be resolved.\n"); |
| 689 | |
| 690 | _HA_ATOMIC_INC(&debug_commands_issued); |
| 691 | |
| 692 | addr = strtoul(args[3], NULL, 0); |
| 693 | chunk_printf(&trash, "%#lx resolves to ", addr); |
| 694 | resolve_sym_name(&trash, NULL, (const void *)addr); |
| 695 | chunk_appendf(&trash, "\n"); |
| 696 | |
| 697 | return cli_msg(appctx, LOG_INFO, trash.area); |
| 698 | } |
| 699 | |
Willy Tarreau | 6bdf3e9 | 2019-05-20 14:25:05 +0200 | [diff] [blame] | 700 | /* parse a "debug dev tkill" command. It always returns 1. */ |
| 701 | static int debug_parse_cli_tkill(char **args, char *payload, struct appctx *appctx, void *private) |
| 702 | { |
| 703 | int thr = 0; |
| 704 | int sig = SIGABRT; |
| 705 | |
| 706 | if (!cli_has_level(appctx, ACCESS_LVL_ADMIN)) |
| 707 | return 1; |
| 708 | |
| 709 | if (*args[3]) |
| 710 | thr = atoi(args[3]); |
| 711 | |
Willy Tarreau | 9d00869 | 2019-08-09 11:21:01 +0200 | [diff] [blame] | 712 | if (thr < 0 || thr > global.nbthread) |
| 713 | 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] | 714 | |
| 715 | if (*args[4]) |
| 716 | sig = atoi(args[4]); |
| 717 | |
Willy Tarreau | 4781b15 | 2021-04-06 13:53:36 +0200 | [diff] [blame] | 718 | _HA_ATOMIC_INC(&debug_commands_issued); |
Willy Tarreau | 6bdf3e9 | 2019-05-20 14:25:05 +0200 | [diff] [blame] | 719 | if (thr) |
Willy Tarreau | fade80d | 2019-05-22 08:46:59 +0200 | [diff] [blame] | 720 | ha_tkill(thr - 1, sig); |
Willy Tarreau | 6bdf3e9 | 2019-05-20 14:25:05 +0200 | [diff] [blame] | 721 | else |
Willy Tarreau | 6bdf3e9 | 2019-05-20 14:25:05 +0200 | [diff] [blame] | 722 | raise(sig); |
| 723 | return 1; |
| 724 | } |
| 725 | |
Erwan Le Goas | 54966df | 2022-09-14 17:24:22 +0200 | [diff] [blame] | 726 | /* hashes 'word' in "debug dev hash 'word' ". */ |
| 727 | static int debug_parse_cli_hash(char **args, char *payload, struct appctx *appctx, void *private) |
| 728 | { |
| 729 | char *msg = NULL; |
| 730 | |
| 731 | cli_dynmsg(appctx, LOG_INFO, memprintf(&msg, "%s\n", HA_ANON_CLI(args[3]))); |
| 732 | return 1; |
| 733 | } |
| 734 | |
Willy Tarreau | 6cbe62b | 2020-03-05 17:16:24 +0100 | [diff] [blame] | 735 | /* parse a "debug dev write" command. It always returns 1. */ |
| 736 | static int debug_parse_cli_write(char **args, char *payload, struct appctx *appctx, void *private) |
| 737 | { |
| 738 | unsigned long len; |
| 739 | |
| 740 | if (!*args[3]) |
| 741 | return cli_err(appctx, "Missing output size.\n"); |
| 742 | |
| 743 | len = strtoul(args[3], NULL, 0); |
| 744 | if (len >= trash.size) |
| 745 | return cli_err(appctx, "Output too large, must be <tune.bufsize.\n"); |
| 746 | |
Willy Tarreau | 4781b15 | 2021-04-06 13:53:36 +0200 | [diff] [blame] | 747 | _HA_ATOMIC_INC(&debug_commands_issued); |
Willy Tarreau | 6cbe62b | 2020-03-05 17:16:24 +0100 | [diff] [blame] | 748 | |
| 749 | chunk_reset(&trash); |
| 750 | trash.data = len; |
| 751 | memset(trash.area, '.', trash.data); |
| 752 | trash.area[trash.data] = 0; |
| 753 | for (len = 64; len < trash.data; len += 64) |
| 754 | trash.area[len] = '\n'; |
| 755 | return cli_msg(appctx, LOG_INFO, trash.area); |
| 756 | } |
| 757 | |
Willy Tarreau | 68680bb | 2019-10-23 17:23:25 +0200 | [diff] [blame] | 758 | /* parse a "debug dev stream" command */ |
| 759 | /* |
| 760 | * debug dev stream [strm=<ptr>] [strm.f[{+-=}<flags>]] [txn.f[{+-=}<flags>]] \ |
| 761 | * [req.f[{+-=}<flags>]] [res.f[{+-=}<flags>]] \ |
| 762 | * [sif.f[{+-=<flags>]] [sib.f[{+-=<flags>]] \ |
| 763 | * [sif.s[=<state>]] [sib.s[=<state>]] |
| 764 | */ |
| 765 | static int debug_parse_cli_stream(char **args, char *payload, struct appctx *appctx, void *private) |
| 766 | { |
Willy Tarreau | 0698c80 | 2022-05-11 14:09:57 +0200 | [diff] [blame] | 767 | struct stream *s = appctx_strm(appctx); |
Willy Tarreau | 68680bb | 2019-10-23 17:23:25 +0200 | [diff] [blame] | 768 | int arg; |
| 769 | void *ptr; |
| 770 | int size; |
| 771 | const char *word, *end; |
| 772 | struct ist name; |
| 773 | char *msg = NULL; |
| 774 | char *endarg; |
| 775 | unsigned long long old, new; |
| 776 | |
| 777 | if (!cli_has_level(appctx, ACCESS_LVL_ADMIN)) |
| 778 | return 1; |
| 779 | |
| 780 | ptr = NULL; size = 0; |
| 781 | |
| 782 | if (!*args[3]) { |
| 783 | return cli_err(appctx, |
Willy Tarreau | dd01448 | 2023-05-02 16:37:13 +0200 | [diff] [blame] | 784 | "Usage: debug dev stream [ strm=<ptr> ] { <obj> <op> <value> | wake }*\n" |
| 785 | " <obj> = { strm.f | strm.x | scf.s | scb.s | txn.f | req.f | res.f }\n" |
Willy Tarreau | 68680bb | 2019-10-23 17:23:25 +0200 | [diff] [blame] | 786 | " <op> = {'' (show) | '=' (assign) | '^' (xor) | '+' (or) | '-' (andnot)}\n" |
| 787 | " <value> = 'now' | 64-bit dec/hex integer (0x prefix supported)\n" |
| 788 | " 'wake' wakes the stream asssigned to 'strm' (default: current)\n" |
| 789 | ); |
| 790 | } |
| 791 | |
Willy Tarreau | 4781b15 | 2021-04-06 13:53:36 +0200 | [diff] [blame] | 792 | _HA_ATOMIC_INC(&debug_commands_issued); |
Willy Tarreau | 68680bb | 2019-10-23 17:23:25 +0200 | [diff] [blame] | 793 | for (arg = 3; *args[arg]; arg++) { |
| 794 | old = 0; |
| 795 | end = word = args[arg]; |
| 796 | while (*end && *end != '=' && *end != '^' && *end != '+' && *end != '-') |
| 797 | end++; |
| 798 | name = ist2(word, end - word); |
| 799 | if (isteq(name, ist("strm"))) { |
Willy Tarreau | b2fee04 | 2019-10-25 10:06:55 +0200 | [diff] [blame] | 800 | ptr = (!s || !may_access(s)) ? NULL : &s; size = sizeof(s); |
Willy Tarreau | 68680bb | 2019-10-23 17:23:25 +0200 | [diff] [blame] | 801 | } else if (isteq(name, ist("strm.f"))) { |
Willy Tarreau | b2fee04 | 2019-10-25 10:06:55 +0200 | [diff] [blame] | 802 | ptr = (!s || !may_access(s)) ? NULL : &s->flags; size = sizeof(s->flags); |
Christopher Faulet | ae024ce | 2022-03-29 19:02:31 +0200 | [diff] [blame] | 803 | } else if (isteq(name, ist("strm.x"))) { |
| 804 | ptr = (!s || !may_access(s)) ? NULL : &s->conn_exp; size = sizeof(s->conn_exp); |
Willy Tarreau | 68680bb | 2019-10-23 17:23:25 +0200 | [diff] [blame] | 805 | } else if (isteq(name, ist("txn.f"))) { |
Willy Tarreau | b2fee04 | 2019-10-25 10:06:55 +0200 | [diff] [blame] | 806 | 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] | 807 | } else if (isteq(name, ist("req.f"))) { |
Willy Tarreau | b2fee04 | 2019-10-25 10:06:55 +0200 | [diff] [blame] | 808 | 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] | 809 | } else if (isteq(name, ist("res.f"))) { |
Willy Tarreau | b2fee04 | 2019-10-25 10:06:55 +0200 | [diff] [blame] | 810 | ptr = (!s || !may_access(s)) ? NULL : &s->res.flags; size = sizeof(s->res.flags); |
Willy Tarreau | 7cb9e6c | 2022-05-17 19:40:40 +0200 | [diff] [blame] | 811 | } else if (isteq(name, ist("scf.s"))) { |
| 812 | ptr = (!s || !may_access(s)) ? NULL : &s->scf->state; size = sizeof(s->scf->state); |
| 813 | } else if (isteq(name, ist("scb.s"))) { |
| 814 | ptr = (!s || !may_access(s)) ? NULL : &s->scf->state; size = sizeof(s->scb->state); |
Willy Tarreau | 68680bb | 2019-10-23 17:23:25 +0200 | [diff] [blame] | 815 | } else if (isteq(name, ist("wake"))) { |
Willy Tarreau | 2b5520d | 2019-10-24 18:28:23 +0200 | [diff] [blame] | 816 | if (s && may_access(s) && may_access((void *)s + sizeof(*s) - 1)) |
Willy Tarreau | 68680bb | 2019-10-23 17:23:25 +0200 | [diff] [blame] | 817 | task_wakeup(s->task, TASK_WOKEN_TIMER|TASK_WOKEN_IO|TASK_WOKEN_MSG); |
| 818 | continue; |
| 819 | } else |
| 820 | return cli_dynerr(appctx, memprintf(&msg, "Unsupported field name: '%s'.\n", word)); |
| 821 | |
| 822 | /* read previous value */ |
Willy Tarreau | 2b5520d | 2019-10-24 18:28:23 +0200 | [diff] [blame] | 823 | 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] | 824 | if (size == 8) |
| 825 | old = read_u64(ptr); |
| 826 | else if (size == 4) |
| 827 | old = read_u32(ptr); |
| 828 | else if (size == 2) |
| 829 | old = read_u16(ptr); |
| 830 | else |
| 831 | old = *(const uint8_t *)ptr; |
Willy Tarreau | 2b5520d | 2019-10-24 18:28:23 +0200 | [diff] [blame] | 832 | } else { |
| 833 | memprintf(&msg, |
| 834 | "%sSkipping inaccessible pointer %p for field '%.*s'.\n", |
| 835 | msg ? msg : "", ptr, (int)(end - word), word); |
| 836 | continue; |
Willy Tarreau | 68680bb | 2019-10-23 17:23:25 +0200 | [diff] [blame] | 837 | } |
| 838 | |
| 839 | /* parse the new value . */ |
| 840 | new = strtoll(end + 1, &endarg, 0); |
| 841 | if (end[1] && *endarg) { |
| 842 | if (strcmp(end + 1, "now") == 0) |
| 843 | new = now_ms; |
| 844 | else { |
| 845 | memprintf(&msg, |
| 846 | "%sIgnoring unparsable value '%s' for field '%.*s'.\n", |
| 847 | msg ? msg : "", end + 1, (int)(end - word), word); |
| 848 | continue; |
| 849 | } |
| 850 | } |
| 851 | |
| 852 | switch (*end) { |
| 853 | case '\0': /* show */ |
| 854 | memprintf(&msg, "%s%.*s=%#llx ", msg ? msg : "", (int)(end - word), word, old); |
| 855 | new = old; // do not change the value |
| 856 | break; |
| 857 | |
| 858 | case '=': /* set */ |
| 859 | break; |
| 860 | |
| 861 | case '^': /* XOR */ |
| 862 | new = old ^ new; |
| 863 | break; |
| 864 | |
| 865 | case '+': /* OR */ |
| 866 | new = old | new; |
| 867 | break; |
| 868 | |
| 869 | case '-': /* AND NOT */ |
| 870 | new = old & ~new; |
| 871 | break; |
| 872 | |
| 873 | default: |
| 874 | break; |
| 875 | } |
| 876 | |
| 877 | /* write the new value */ |
Willy Tarreau | 2b5520d | 2019-10-24 18:28:23 +0200 | [diff] [blame] | 878 | if (new != old) { |
Willy Tarreau | 68680bb | 2019-10-23 17:23:25 +0200 | [diff] [blame] | 879 | if (size == 8) |
| 880 | write_u64(ptr, new); |
| 881 | else if (size == 4) |
| 882 | write_u32(ptr, new); |
| 883 | else if (size == 2) |
| 884 | write_u16(ptr, new); |
| 885 | else |
| 886 | *(uint8_t *)ptr = new; |
| 887 | } |
| 888 | } |
| 889 | |
| 890 | if (msg && *msg) |
| 891 | return cli_dynmsg(appctx, LOG_INFO, msg); |
| 892 | return 1; |
| 893 | } |
| 894 | |
Willy Tarreau | 9867987 | 2023-05-03 11:22:45 +0200 | [diff] [blame] | 895 | /* parse a "debug dev stream" command */ |
| 896 | /* |
| 897 | * debug dev task <ptr> [ "wake" | "expire" | "kill" ] |
| 898 | * Show/change status of a task/tasklet |
| 899 | */ |
| 900 | static int debug_parse_cli_task(char **args, char *payload, struct appctx *appctx, void *private) |
| 901 | { |
| 902 | const struct ha_caller *caller; |
| 903 | struct task *t; |
| 904 | char *endarg; |
| 905 | char *msg; |
| 906 | void *ptr; |
| 907 | int ret = 1; |
| 908 | int task_ok; |
| 909 | int arg; |
| 910 | |
| 911 | if (!cli_has_level(appctx, ACCESS_LVL_ADMIN)) |
| 912 | return 1; |
| 913 | |
| 914 | /* parse the pointer value */ |
| 915 | ptr = (void *)strtoll(args[3], &endarg, 0); |
| 916 | if (!*args[3] || *endarg) |
| 917 | goto usage; |
| 918 | |
| 919 | _HA_ATOMIC_INC(&debug_commands_issued); |
| 920 | |
| 921 | /* everything below must run under thread isolation till reaching label "leave" */ |
| 922 | thread_isolate(); |
| 923 | |
| 924 | /* struct tasklet is smaller than struct task and is sufficient to check |
| 925 | * the TASK_COMMON part. |
| 926 | */ |
| 927 | if (!may_access(ptr) || !may_access(ptr + sizeof(struct tasklet) - 1) || |
| 928 | ((const struct tasklet *)ptr)->tid < -1 || |
| 929 | ((const struct tasklet *)ptr)->tid >= (int)MAX_THREADS) { |
| 930 | ret = cli_err(appctx, "The designated memory area doesn't look like a valid task/tasklet\n"); |
| 931 | goto leave; |
| 932 | } |
| 933 | |
| 934 | t = ptr; |
| 935 | caller = t->caller; |
| 936 | msg = NULL; |
| 937 | task_ok = may_access(t + sizeof(*t) - 1); |
| 938 | |
| 939 | chunk_reset(&trash); |
| 940 | resolve_sym_name(&trash, NULL, (const void *)t->process); |
| 941 | |
| 942 | /* we need to be careful here because we may dump a freed task that's |
| 943 | * still in the pool cache, containing garbage in pointers. |
| 944 | */ |
| 945 | if (!*args[4]) { |
| 946 | memprintf(&msg, "%s%p: %s state=%#x tid=%d process=%s ctx=%p calls=%d last=%s:%d intl=%d", |
| 947 | msg ? msg : "", t, (t->state & TASK_F_TASKLET) ? "tasklet" : "task", |
| 948 | t->state, t->tid, trash.area, t->context, t->calls, |
Willy Tarreau | ff508f1 | 2023-05-03 16:28:54 +0200 | [diff] [blame] | 949 | caller && may_access(caller) && may_access(caller->func) && isalnum((uchar)*caller->func) ? caller->func : "0", |
Willy Tarreau | 9867987 | 2023-05-03 11:22:45 +0200 | [diff] [blame] | 950 | caller ? t->caller->line : 0, |
| 951 | (t->state & TASK_F_TASKLET) ? LIST_INLIST(&((const struct tasklet *)t)->list) : 0); |
| 952 | |
| 953 | if (task_ok && !(t->state & TASK_F_TASKLET)) |
| 954 | memprintf(&msg, "%s inrq=%d inwq=%d exp=%d nice=%d", |
| 955 | msg ? msg : "", task_in_rq(t), task_in_wq(t), t->expire, t->nice); |
| 956 | |
| 957 | memprintf(&msg, "%s\n", msg ? msg : ""); |
| 958 | } |
| 959 | |
| 960 | for (arg = 4; *args[arg]; arg++) { |
| 961 | if (strcmp(args[arg], "expire") == 0) { |
| 962 | if (t->state & TASK_F_TASKLET) { |
| 963 | /* do nothing for tasklets */ |
| 964 | } |
| 965 | else if (task_ok) { |
| 966 | /* unlink task and wake with timer flag */ |
| 967 | __task_unlink_wq(t); |
| 968 | t->expire = now_ms; |
| 969 | task_wakeup(t, TASK_WOKEN_TIMER); |
| 970 | } |
| 971 | } else if (strcmp(args[arg], "wake") == 0) { |
| 972 | /* wake with all flags but init / timer */ |
| 973 | if (t->state & TASK_F_TASKLET) |
| 974 | tasklet_wakeup((struct tasklet *)t); |
| 975 | else if (task_ok) |
| 976 | task_wakeup(t, TASK_WOKEN_ANY & ~(TASK_WOKEN_INIT|TASK_WOKEN_TIMER)); |
| 977 | } else if (strcmp(args[arg], "kill") == 0) { |
| 978 | /* Kill the task. This is not idempotent! */ |
| 979 | if (!(t->state & TASK_KILLED)) { |
| 980 | if (t->state & TASK_F_TASKLET) |
| 981 | tasklet_kill((struct tasklet *)t); |
| 982 | else if (task_ok) |
| 983 | task_kill(t); |
| 984 | } |
| 985 | } else { |
| 986 | thread_release(); |
| 987 | goto usage; |
| 988 | } |
| 989 | } |
| 990 | |
| 991 | if (msg && *msg) |
| 992 | ret = cli_dynmsg(appctx, LOG_INFO, msg); |
| 993 | leave: |
| 994 | thread_release(); |
| 995 | return ret; |
| 996 | usage: |
| 997 | return cli_err(appctx, |
| 998 | "Usage: debug dev task <ptr> [ wake | expire | kill ]\n" |
| 999 | " By default, dumps some info on task/tasklet <ptr>. 'wake' will wake it up\n" |
| 1000 | " with all conditions flags but init/exp. 'expire' will expire the entry, and\n" |
| 1001 | " 'kill' will kill it (warning: may crash since later not idempotent!). All\n" |
| 1002 | " changes may crash the process if performed on a wrong object!\n" |
| 1003 | ); |
| 1004 | } |
| 1005 | |
Willy Tarreau | bd3b44e | 2023-03-09 08:25:01 +0100 | [diff] [blame] | 1006 | #if defined(DEBUG_DEV) |
| 1007 | static struct task *debug_delay_inj_task(struct task *t, void *ctx, unsigned int state) |
| 1008 | { |
| 1009 | unsigned long *tctx = ctx; // [0] = interval, [1] = nbwakeups |
| 1010 | unsigned long inter = tctx[0]; |
| 1011 | unsigned long count = tctx[1]; |
| 1012 | unsigned long rnd; |
| 1013 | |
| 1014 | if (inter) |
| 1015 | t->expire = tick_add(now_ms, inter); |
| 1016 | else |
| 1017 | task_wakeup(t, TASK_WOKEN_MSG); |
| 1018 | |
| 1019 | /* wake a random thread */ |
| 1020 | while (count--) { |
| 1021 | rnd = statistical_prng_range(global.nbthread); |
| 1022 | ha_tkill(rnd, SIGRTMAX); |
| 1023 | } |
| 1024 | return t; |
| 1025 | } |
| 1026 | |
| 1027 | /* parse a "debug dev delay-inj" command |
| 1028 | * debug dev delay-inj <inter> <count> |
| 1029 | */ |
| 1030 | static int debug_parse_delay_inj(char **args, char *payload, struct appctx *appctx, void *private) |
| 1031 | { |
| 1032 | unsigned long *tctx; // [0] = inter, [2] = count |
| 1033 | struct task *task; |
| 1034 | |
| 1035 | if (!cli_has_level(appctx, ACCESS_LVL_ADMIN)) |
| 1036 | return 1; |
| 1037 | |
| 1038 | if (!*args[4]) |
| 1039 | return cli_err(appctx, "Usage: debug dev delay-inj <inter_ms> <count>*\n"); |
| 1040 | |
| 1041 | _HA_ATOMIC_INC(&debug_commands_issued); |
| 1042 | |
| 1043 | tctx = calloc(sizeof(*tctx), 2); |
| 1044 | if (!tctx) |
| 1045 | goto fail; |
| 1046 | |
| 1047 | tctx[0] = atoi(args[3]); |
| 1048 | tctx[1] = atoi(args[4]); |
| 1049 | |
| 1050 | task = task_new_here/*anywhere*/(); |
| 1051 | if (!task) |
| 1052 | goto fail; |
| 1053 | |
| 1054 | task->process = debug_delay_inj_task; |
| 1055 | task->context = tctx; |
| 1056 | task_wakeup(task, TASK_WOKEN_INIT); |
| 1057 | return 1; |
| 1058 | |
| 1059 | fail: |
| 1060 | free(tctx); |
| 1061 | return cli_err(appctx, "Not enough memory"); |
| 1062 | } |
| 1063 | #endif // DEBUG_DEV |
| 1064 | |
Willy Tarreau | 144f84a | 2021-03-02 16:09:26 +0100 | [diff] [blame] | 1065 | 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] | 1066 | { |
| 1067 | unsigned long *tctx = ctx; // [0] = #tasks, [1] = inter, [2+] = { tl | (tsk+1) } |
| 1068 | unsigned long inter = tctx[1]; |
| 1069 | unsigned long rnd; |
| 1070 | |
| 1071 | t->expire = tick_add(now_ms, inter); |
| 1072 | |
| 1073 | /* half of the calls will wake up another entry */ |
Willy Tarreau | 06e69b5 | 2021-03-02 14:01:35 +0100 | [diff] [blame] | 1074 | rnd = statistical_prng(); |
Willy Tarreau | a5a4479 | 2020-11-29 17:12:15 +0100 | [diff] [blame] | 1075 | if (rnd & 1) { |
| 1076 | rnd >>= 1; |
| 1077 | rnd %= tctx[0]; |
| 1078 | rnd = tctx[rnd + 2]; |
| 1079 | |
| 1080 | if (rnd & 1) |
| 1081 | task_wakeup((struct task *)(rnd - 1), TASK_WOKEN_MSG); |
| 1082 | else |
| 1083 | tasklet_wakeup((struct tasklet *)rnd); |
| 1084 | } |
| 1085 | return t; |
| 1086 | } |
| 1087 | |
Willy Tarreau | 144f84a | 2021-03-02 16:09:26 +0100 | [diff] [blame] | 1088 | 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] | 1089 | { |
| 1090 | unsigned long *tctx = ctx; // [0] = #tasks, [1] = inter, [2+] = { tl | (tsk+1) } |
| 1091 | unsigned long rnd; |
| 1092 | int i; |
| 1093 | |
| 1094 | /* wake up two random entries */ |
| 1095 | for (i = 0; i < 2; i++) { |
Willy Tarreau | 06e69b5 | 2021-03-02 14:01:35 +0100 | [diff] [blame] | 1096 | rnd = statistical_prng() % tctx[0]; |
Willy Tarreau | a5a4479 | 2020-11-29 17:12:15 +0100 | [diff] [blame] | 1097 | rnd = tctx[rnd + 2]; |
| 1098 | |
| 1099 | if (rnd & 1) |
| 1100 | task_wakeup((struct task *)(rnd - 1), TASK_WOKEN_MSG); |
| 1101 | else |
| 1102 | tasklet_wakeup((struct tasklet *)rnd); |
| 1103 | } |
| 1104 | return t; |
| 1105 | } |
| 1106 | |
| 1107 | /* parse a "debug dev sched" command |
| 1108 | * debug dev sched {task|tasklet} [count=<count>] [mask=<mask>] [single=<single>] [inter=<inter>] |
| 1109 | */ |
| 1110 | static int debug_parse_cli_sched(char **args, char *payload, struct appctx *appctx, void *private) |
| 1111 | { |
| 1112 | int arg; |
| 1113 | void *ptr; |
| 1114 | int size; |
| 1115 | const char *word, *end; |
| 1116 | struct ist name; |
| 1117 | char *msg = NULL; |
| 1118 | char *endarg; |
| 1119 | unsigned long long new; |
| 1120 | unsigned long count = 0; |
Willy Tarreau | 8e5c53a | 2022-06-15 16:32:41 +0200 | [diff] [blame] | 1121 | unsigned long thrid = tid; |
Willy Tarreau | a5a4479 | 2020-11-29 17:12:15 +0100 | [diff] [blame] | 1122 | unsigned int inter = 0; |
Willy Tarreau | a5a4479 | 2020-11-29 17:12:15 +0100 | [diff] [blame] | 1123 | unsigned long i; |
| 1124 | int mode = 0; // 0 = tasklet; 1 = task |
Willy Tarreau | a5a4479 | 2020-11-29 17:12:15 +0100 | [diff] [blame] | 1125 | unsigned long *tctx; // [0] = #tasks, [1] = inter, [2+] = { tl | (tsk+1) } |
| 1126 | |
| 1127 | if (!cli_has_level(appctx, ACCESS_LVL_ADMIN)) |
| 1128 | return 1; |
| 1129 | |
| 1130 | ptr = NULL; size = 0; |
Willy Tarreau | a5a4479 | 2020-11-29 17:12:15 +0100 | [diff] [blame] | 1131 | |
| 1132 | if (strcmp(args[3], "task") != 0 && strcmp(args[3], "tasklet") != 0) { |
| 1133 | return cli_err(appctx, |
| 1134 | "Usage: debug dev sched {task|tasklet} { <obj> = <value> }*\n" |
Willy Tarreau | 8e5c53a | 2022-06-15 16:32:41 +0200 | [diff] [blame] | 1135 | " <obj> = {count | tid | inter }\n" |
Willy Tarreau | a5a4479 | 2020-11-29 17:12:15 +0100 | [diff] [blame] | 1136 | " <value> = 64-bit dec/hex integer (0x prefix supported)\n" |
| 1137 | ); |
| 1138 | } |
| 1139 | |
| 1140 | mode = strcmp(args[3], "task") == 0; |
| 1141 | |
Willy Tarreau | 4781b15 | 2021-04-06 13:53:36 +0200 | [diff] [blame] | 1142 | _HA_ATOMIC_INC(&debug_commands_issued); |
Willy Tarreau | a5a4479 | 2020-11-29 17:12:15 +0100 | [diff] [blame] | 1143 | for (arg = 4; *args[arg]; arg++) { |
| 1144 | end = word = args[arg]; |
| 1145 | while (*end && *end != '=' && *end != '^' && *end != '+' && *end != '-') |
| 1146 | end++; |
| 1147 | name = ist2(word, end - word); |
| 1148 | if (isteq(name, ist("count"))) { |
| 1149 | ptr = &count; size = sizeof(count); |
Willy Tarreau | a5a4479 | 2020-11-29 17:12:15 +0100 | [diff] [blame] | 1150 | } else if (isteq(name, ist("tid"))) { |
| 1151 | ptr = &thrid; size = sizeof(thrid); |
| 1152 | } else if (isteq(name, ist("inter"))) { |
| 1153 | ptr = &inter; size = sizeof(inter); |
Willy Tarreau | a5a4479 | 2020-11-29 17:12:15 +0100 | [diff] [blame] | 1154 | } else |
| 1155 | return cli_dynerr(appctx, memprintf(&msg, "Unsupported setting: '%s'.\n", word)); |
| 1156 | |
| 1157 | /* parse the new value . */ |
| 1158 | new = strtoll(end + 1, &endarg, 0); |
| 1159 | if (end[1] && *endarg) { |
| 1160 | memprintf(&msg, |
| 1161 | "%sIgnoring unparsable value '%s' for field '%.*s'.\n", |
| 1162 | msg ? msg : "", end + 1, (int)(end - word), word); |
| 1163 | continue; |
| 1164 | } |
| 1165 | |
| 1166 | /* write the new value */ |
| 1167 | if (size == 8) |
| 1168 | write_u64(ptr, new); |
| 1169 | else if (size == 4) |
| 1170 | write_u32(ptr, new); |
| 1171 | else if (size == 2) |
| 1172 | write_u16(ptr, new); |
| 1173 | else |
| 1174 | *(uint8_t *)ptr = new; |
| 1175 | } |
| 1176 | |
| 1177 | tctx = calloc(sizeof(*tctx), count + 2); |
| 1178 | if (!tctx) |
| 1179 | goto fail; |
| 1180 | |
| 1181 | tctx[0] = (unsigned long)count; |
| 1182 | tctx[1] = (unsigned long)inter; |
| 1183 | |
Willy Tarreau | 8e5c53a | 2022-06-15 16:32:41 +0200 | [diff] [blame] | 1184 | if (thrid >= global.nbthread) |
| 1185 | thrid = tid; |
Willy Tarreau | a5a4479 | 2020-11-29 17:12:15 +0100 | [diff] [blame] | 1186 | |
Willy Tarreau | a5a4479 | 2020-11-29 17:12:15 +0100 | [diff] [blame] | 1187 | for (i = 0; i < count; i++) { |
Willy Tarreau | a5a4479 | 2020-11-29 17:12:15 +0100 | [diff] [blame] | 1188 | /* now, if poly or mask was set, tmask corresponds to the |
| 1189 | * valid thread mask to use, otherwise it remains zero. |
| 1190 | */ |
| 1191 | //printf("%lu: mode=%d mask=%#lx\n", i, mode, tmask); |
| 1192 | if (mode == 0) { |
| 1193 | struct tasklet *tl = tasklet_new(); |
| 1194 | |
| 1195 | if (!tl) |
| 1196 | goto fail; |
| 1197 | |
Willy Tarreau | 8e5c53a | 2022-06-15 16:32:41 +0200 | [diff] [blame] | 1198 | tl->tid = thrid; |
Willy Tarreau | a5a4479 | 2020-11-29 17:12:15 +0100 | [diff] [blame] | 1199 | tl->process = debug_tasklet_handler; |
| 1200 | tl->context = tctx; |
| 1201 | tctx[i + 2] = (unsigned long)tl; |
| 1202 | } else { |
Willy Tarreau | 8e5c53a | 2022-06-15 16:32:41 +0200 | [diff] [blame] | 1203 | struct task *task = task_new_on(thrid); |
Willy Tarreau | a5a4479 | 2020-11-29 17:12:15 +0100 | [diff] [blame] | 1204 | |
| 1205 | if (!task) |
| 1206 | goto fail; |
| 1207 | |
| 1208 | task->process = debug_task_handler; |
| 1209 | task->context = tctx; |
| 1210 | tctx[i + 2] = (unsigned long)task + 1; |
| 1211 | } |
| 1212 | } |
| 1213 | |
| 1214 | /* start the tasks and tasklets */ |
| 1215 | for (i = 0; i < count; i++) { |
| 1216 | unsigned long ctx = tctx[i + 2]; |
| 1217 | |
| 1218 | if (ctx & 1) |
| 1219 | task_wakeup((struct task *)(ctx - 1), TASK_WOKEN_INIT); |
| 1220 | else |
| 1221 | tasklet_wakeup((struct tasklet *)ctx); |
| 1222 | } |
| 1223 | |
| 1224 | if (msg && *msg) |
| 1225 | return cli_dynmsg(appctx, LOG_INFO, msg); |
| 1226 | return 1; |
| 1227 | |
| 1228 | fail: |
| 1229 | /* free partially allocated entries */ |
| 1230 | for (i = 0; tctx && i < count; i++) { |
| 1231 | unsigned long ctx = tctx[i + 2]; |
| 1232 | |
| 1233 | if (!ctx) |
| 1234 | break; |
| 1235 | |
| 1236 | if (ctx & 1) |
| 1237 | task_destroy((struct task *)(ctx - 1)); |
| 1238 | else |
| 1239 | tasklet_free((struct tasklet *)ctx); |
| 1240 | } |
| 1241 | |
| 1242 | free(tctx); |
| 1243 | return cli_err(appctx, "Not enough memory"); |
| 1244 | } |
| 1245 | |
Willy Tarreau | e06bbf3 | 2022-05-05 14:26:28 +0200 | [diff] [blame] | 1246 | /* CLI state for "debug dev fd" */ |
| 1247 | struct dev_fd_ctx { |
| 1248 | int start_fd; |
| 1249 | }; |
| 1250 | |
Willy Tarreau | 5be7c19 | 2022-01-24 20:26:09 +0100 | [diff] [blame] | 1251 | /* CLI parser for the "debug dev fd" command. The current FD to restart from is |
Willy Tarreau | e06bbf3 | 2022-05-05 14:26:28 +0200 | [diff] [blame] | 1252 | * stored in a struct dev_fd_ctx pointed to by svcctx. |
Willy Tarreau | 5be7c19 | 2022-01-24 20:26:09 +0100 | [diff] [blame] | 1253 | */ |
| 1254 | static int debug_parse_cli_fd(char **args, char *payload, struct appctx *appctx, void *private) |
| 1255 | { |
Willy Tarreau | e06bbf3 | 2022-05-05 14:26:28 +0200 | [diff] [blame] | 1256 | struct dev_fd_ctx *ctx = applet_reserve_svcctx(appctx, sizeof(*ctx)); |
| 1257 | |
Willy Tarreau | 5be7c19 | 2022-01-24 20:26:09 +0100 | [diff] [blame] | 1258 | if (!cli_has_level(appctx, ACCESS_LVL_OPER)) |
| 1259 | return 1; |
| 1260 | |
| 1261 | /* start at fd #0 */ |
Willy Tarreau | e06bbf3 | 2022-05-05 14:26:28 +0200 | [diff] [blame] | 1262 | ctx->start_fd = 0; |
Willy Tarreau | 5be7c19 | 2022-01-24 20:26:09 +0100 | [diff] [blame] | 1263 | return 0; |
| 1264 | } |
| 1265 | |
| 1266 | /* CLI I/O handler for the "debug dev fd" command. Dumps all FDs that are |
| 1267 | * accessible from the process but not known from fdtab. The FD number to |
Willy Tarreau | e06bbf3 | 2022-05-05 14:26:28 +0200 | [diff] [blame] | 1268 | * restart from is stored in a struct dev_fd_ctx pointed to by svcctx. |
Willy Tarreau | 5be7c19 | 2022-01-24 20:26:09 +0100 | [diff] [blame] | 1269 | */ |
| 1270 | static int debug_iohandler_fd(struct appctx *appctx) |
| 1271 | { |
Willy Tarreau | e06bbf3 | 2022-05-05 14:26:28 +0200 | [diff] [blame] | 1272 | struct dev_fd_ctx *ctx = appctx->svcctx; |
Willy Tarreau | c12b321 | 2022-05-27 11:08:15 +0200 | [diff] [blame] | 1273 | struct stconn *sc = appctx_sc(appctx); |
Willy Tarreau | 5be7c19 | 2022-01-24 20:26:09 +0100 | [diff] [blame] | 1274 | struct sockaddr_storage sa; |
| 1275 | struct stat statbuf; |
| 1276 | socklen_t salen, vlen; |
| 1277 | int ret1, ret2, port; |
| 1278 | char *addrstr; |
| 1279 | int ret = 1; |
| 1280 | int i, fd; |
| 1281 | |
Christopher Faulet | 87633c3 | 2023-04-03 18:32:50 +0200 | [diff] [blame] | 1282 | /* FIXME: Don't watch the other side !*/ |
Christopher Faulet | 208c712 | 2023-04-13 16:16:15 +0200 | [diff] [blame] | 1283 | if (unlikely(sc_opposite(sc)->flags & SC_FL_SHUT_DONE)) |
Willy Tarreau | 5be7c19 | 2022-01-24 20:26:09 +0100 | [diff] [blame] | 1284 | goto end; |
| 1285 | |
| 1286 | chunk_reset(&trash); |
| 1287 | |
| 1288 | thread_isolate(); |
| 1289 | |
| 1290 | /* we have two inner loops here, one for the proxy, the other one for |
| 1291 | * the buffer. |
| 1292 | */ |
Willy Tarreau | e06bbf3 | 2022-05-05 14:26:28 +0200 | [diff] [blame] | 1293 | for (fd = ctx->start_fd; fd < global.maxsock; fd++) { |
Willy Tarreau | 5be7c19 | 2022-01-24 20:26:09 +0100 | [diff] [blame] | 1294 | /* check for FD's existence */ |
| 1295 | ret1 = fcntl(fd, F_GETFD, 0); |
| 1296 | if (ret1 == -1) |
| 1297 | continue; // not known to the process |
| 1298 | if (fdtab[fd].owner) |
| 1299 | continue; // well-known |
| 1300 | |
| 1301 | /* OK we're seeing an orphan let's try to retrieve as much |
| 1302 | * information as possible about it. |
| 1303 | */ |
| 1304 | chunk_printf(&trash, "%5d", fd); |
| 1305 | |
| 1306 | if (fstat(fd, &statbuf) != -1) { |
| 1307 | chunk_appendf(&trash, " type=%s mod=%04o dev=%#llx siz=%#llx uid=%lld gid=%lld fs=%#llx ino=%#llx", |
| 1308 | isatty(fd) ? "tty.": |
| 1309 | S_ISREG(statbuf.st_mode) ? "file": |
| 1310 | S_ISDIR(statbuf.st_mode) ? "dir.": |
| 1311 | S_ISCHR(statbuf.st_mode) ? "chr.": |
| 1312 | S_ISBLK(statbuf.st_mode) ? "blk.": |
| 1313 | S_ISFIFO(statbuf.st_mode) ? "pipe": |
| 1314 | S_ISLNK(statbuf.st_mode) ? "link": |
| 1315 | S_ISSOCK(statbuf.st_mode) ? "sock": |
| 1316 | #ifdef USE_EPOLL |
| 1317 | epoll_wait(fd, NULL, 0, 0) != -1 || errno != EBADF ? "epol": |
| 1318 | #endif |
| 1319 | "????", |
| 1320 | (uint)statbuf.st_mode & 07777, |
| 1321 | |
| 1322 | (ullong)statbuf.st_rdev, |
| 1323 | (ullong)statbuf.st_size, |
| 1324 | (ullong)statbuf.st_uid, |
| 1325 | (ullong)statbuf.st_gid, |
| 1326 | |
| 1327 | (ullong)statbuf.st_dev, |
| 1328 | (ullong)statbuf.st_ino); |
| 1329 | } |
| 1330 | |
| 1331 | chunk_appendf(&trash, " getfd=%s+%#x", |
| 1332 | (ret1 & FD_CLOEXEC) ? "cloex" : "", |
| 1333 | ret1 &~ FD_CLOEXEC); |
| 1334 | |
| 1335 | /* FD options */ |
| 1336 | ret2 = fcntl(fd, F_GETFL, 0); |
| 1337 | if (ret2) { |
| 1338 | chunk_appendf(&trash, " getfl=%s", |
| 1339 | (ret1 & 3) >= 2 ? "O_RDWR" : |
| 1340 | (ret1 & 1) ? "O_WRONLY" : "O_RDONLY"); |
| 1341 | |
| 1342 | for (i = 2; i < 32; i++) { |
| 1343 | if (!(ret2 & (1UL << i))) |
| 1344 | continue; |
| 1345 | switch (1UL << i) { |
| 1346 | case O_CREAT: chunk_appendf(&trash, ",O_CREAT"); break; |
| 1347 | case O_EXCL: chunk_appendf(&trash, ",O_EXCL"); break; |
| 1348 | case O_NOCTTY: chunk_appendf(&trash, ",O_NOCTTY"); break; |
| 1349 | case O_TRUNC: chunk_appendf(&trash, ",O_TRUNC"); break; |
| 1350 | case O_APPEND: chunk_appendf(&trash, ",O_APPEND"); break; |
Willy Tarreau | 410942b | 2022-01-25 14:51:53 +0100 | [diff] [blame] | 1351 | #ifdef O_ASYNC |
Willy Tarreau | 5be7c19 | 2022-01-24 20:26:09 +0100 | [diff] [blame] | 1352 | case O_ASYNC: chunk_appendf(&trash, ",O_ASYNC"); break; |
Willy Tarreau | 410942b | 2022-01-25 14:51:53 +0100 | [diff] [blame] | 1353 | #endif |
Willy Tarreau | 5be7c19 | 2022-01-24 20:26:09 +0100 | [diff] [blame] | 1354 | #ifdef O_DIRECT |
| 1355 | case O_DIRECT: chunk_appendf(&trash, ",O_DIRECT"); break; |
| 1356 | #endif |
| 1357 | #ifdef O_NOATIME |
| 1358 | case O_NOATIME: chunk_appendf(&trash, ",O_NOATIME"); break; |
| 1359 | #endif |
| 1360 | } |
| 1361 | } |
| 1362 | } |
| 1363 | |
| 1364 | vlen = sizeof(ret2); |
| 1365 | ret1 = getsockopt(fd, SOL_SOCKET, SO_TYPE, &ret2, &vlen); |
| 1366 | if (ret1 != -1) |
| 1367 | chunk_appendf(&trash, " so_type=%d", ret2); |
| 1368 | |
| 1369 | vlen = sizeof(ret2); |
| 1370 | ret1 = getsockopt(fd, SOL_SOCKET, SO_ACCEPTCONN, &ret2, &vlen); |
| 1371 | if (ret1 != -1) |
| 1372 | chunk_appendf(&trash, " so_accept=%d", ret2); |
| 1373 | |
| 1374 | vlen = sizeof(ret2); |
| 1375 | ret1 = getsockopt(fd, SOL_SOCKET, SO_ERROR, &ret2, &vlen); |
| 1376 | if (ret1 != -1) |
| 1377 | chunk_appendf(&trash, " so_error=%d", ret2); |
| 1378 | |
| 1379 | salen = sizeof(sa); |
| 1380 | if (getsockname(fd, (struct sockaddr *)&sa, &salen) != -1) { |
| 1381 | if (sa.ss_family == AF_INET) |
| 1382 | port = ntohs(((const struct sockaddr_in *)&sa)->sin_port); |
| 1383 | else if (sa.ss_family == AF_INET6) |
| 1384 | port = ntohs(((const struct sockaddr_in6 *)&sa)->sin6_port); |
| 1385 | else |
| 1386 | port = 0; |
| 1387 | addrstr = sa2str(&sa, port, 0); |
| 1388 | chunk_appendf(&trash, " laddr=%s", addrstr); |
| 1389 | free(addrstr); |
| 1390 | } |
| 1391 | |
| 1392 | salen = sizeof(sa); |
| 1393 | if (getpeername(fd, (struct sockaddr *)&sa, &salen) != -1) { |
| 1394 | if (sa.ss_family == AF_INET) |
| 1395 | port = ntohs(((const struct sockaddr_in *)&sa)->sin_port); |
| 1396 | else if (sa.ss_family == AF_INET6) |
| 1397 | port = ntohs(((const struct sockaddr_in6 *)&sa)->sin6_port); |
| 1398 | else |
| 1399 | port = 0; |
| 1400 | addrstr = sa2str(&sa, port, 0); |
| 1401 | chunk_appendf(&trash, " raddr=%s", addrstr); |
| 1402 | free(addrstr); |
| 1403 | } |
| 1404 | |
| 1405 | chunk_appendf(&trash, "\n"); |
| 1406 | |
Willy Tarreau | d0a06d5 | 2022-05-18 15:07:19 +0200 | [diff] [blame] | 1407 | if (applet_putchk(appctx, &trash) == -1) { |
Willy Tarreau | e06bbf3 | 2022-05-05 14:26:28 +0200 | [diff] [blame] | 1408 | ctx->start_fd = fd; |
Willy Tarreau | 5be7c19 | 2022-01-24 20:26:09 +0100 | [diff] [blame] | 1409 | ret = 0; |
| 1410 | break; |
| 1411 | } |
| 1412 | } |
| 1413 | |
| 1414 | thread_release(); |
| 1415 | end: |
| 1416 | return ret; |
| 1417 | } |
| 1418 | |
Willy Tarreau | a6026a0 | 2020-07-02 09:14:48 +0200 | [diff] [blame] | 1419 | #if defined(DEBUG_MEM_STATS) |
Willy Tarreau | 40e952f | 2022-05-05 14:39:51 +0200 | [diff] [blame] | 1420 | |
| 1421 | /* CLI state for "debug dev memstats" */ |
| 1422 | struct dev_mem_ctx { |
| 1423 | struct mem_stats *start, *stop; /* begin/end of dump */ |
Willy Tarreau | e57fbed | 2022-11-30 16:42:54 +0100 | [diff] [blame] | 1424 | char *match; /* non-null if a name prefix is specified */ |
Willy Tarreau | 40e952f | 2022-05-05 14:39:51 +0200 | [diff] [blame] | 1425 | int show_all; /* show all entries if non-null */ |
Willy Tarreau | b59e3f6 | 2022-11-30 17:16:51 +0100 | [diff] [blame] | 1426 | int width; /* 1st column width */ |
| 1427 | long tot_size; /* sum of alloc-free */ |
| 1428 | ulong tot_calls; /* sum of calls */ |
Willy Tarreau | 40e952f | 2022-05-05 14:39:51 +0200 | [diff] [blame] | 1429 | }; |
| 1430 | |
| 1431 | /* CLI parser for the "debug dev memstats" command. Sets a dev_mem_ctx shown above. */ |
Willy Tarreau | a6026a0 | 2020-07-02 09:14:48 +0200 | [diff] [blame] | 1432 | static int debug_parse_cli_memstats(char **args, char *payload, struct appctx *appctx, void *private) |
| 1433 | { |
Willy Tarreau | 40e952f | 2022-05-05 14:39:51 +0200 | [diff] [blame] | 1434 | struct dev_mem_ctx *ctx = applet_reserve_svcctx(appctx, sizeof(*ctx)); |
Willy Tarreau | 334d091 | 2022-11-30 16:50:48 +0100 | [diff] [blame] | 1435 | int arg; |
Willy Tarreau | 40e952f | 2022-05-05 14:39:51 +0200 | [diff] [blame] | 1436 | |
Willy Tarreau | a6026a0 | 2020-07-02 09:14:48 +0200 | [diff] [blame] | 1437 | extern __attribute__((__weak__)) struct mem_stats __start_mem_stats; |
| 1438 | extern __attribute__((__weak__)) struct mem_stats __stop_mem_stats; |
| 1439 | |
| 1440 | if (!cli_has_level(appctx, ACCESS_LVL_OPER)) |
| 1441 | return 1; |
| 1442 | |
Willy Tarreau | 334d091 | 2022-11-30 16:50:48 +0100 | [diff] [blame] | 1443 | for (arg = 3; *args[arg]; arg++) { |
| 1444 | if (strcmp(args[arg], "reset") == 0) { |
| 1445 | struct mem_stats *ptr; |
Willy Tarreau | a6026a0 | 2020-07-02 09:14:48 +0200 | [diff] [blame] | 1446 | |
Willy Tarreau | 334d091 | 2022-11-30 16:50:48 +0100 | [diff] [blame] | 1447 | if (!cli_has_level(appctx, ACCESS_LVL_ADMIN)) |
| 1448 | return 1; |
Willy Tarreau | a6026a0 | 2020-07-02 09:14:48 +0200 | [diff] [blame] | 1449 | |
Willy Tarreau | 334d091 | 2022-11-30 16:50:48 +0100 | [diff] [blame] | 1450 | for (ptr = &__start_mem_stats; ptr < &__stop_mem_stats; ptr++) { |
| 1451 | _HA_ATOMIC_STORE(&ptr->calls, 0); |
| 1452 | _HA_ATOMIC_STORE(&ptr->size, 0); |
| 1453 | } |
| 1454 | return 1; |
Willy Tarreau | a6026a0 | 2020-07-02 09:14:48 +0200 | [diff] [blame] | 1455 | } |
Willy Tarreau | 334d091 | 2022-11-30 16:50:48 +0100 | [diff] [blame] | 1456 | else if (strcmp(args[arg], "all") == 0) { |
| 1457 | ctx->show_all = 1; |
| 1458 | continue; |
| 1459 | } |
Willy Tarreau | e57fbed | 2022-11-30 16:42:54 +0100 | [diff] [blame] | 1460 | else if (strcmp(args[arg], "match") == 0 && *args[arg + 1]) { |
| 1461 | ha_free(&ctx->match); |
| 1462 | ctx->match = strdup(args[arg + 1]); |
| 1463 | arg++; |
| 1464 | continue; |
| 1465 | } |
Willy Tarreau | 334d091 | 2022-11-30 16:50:48 +0100 | [diff] [blame] | 1466 | else |
Willy Tarreau | e57fbed | 2022-11-30 16:42:54 +0100 | [diff] [blame] | 1467 | return cli_err(appctx, "Expects either 'reset', 'all', or 'match <pfx>'.\n"); |
Willy Tarreau | a6026a0 | 2020-07-02 09:14:48 +0200 | [diff] [blame] | 1468 | } |
| 1469 | |
Willy Tarreau | a6026a0 | 2020-07-02 09:14:48 +0200 | [diff] [blame] | 1470 | /* otherwise proceed with the dump from p0 to p1 */ |
Willy Tarreau | 40e952f | 2022-05-05 14:39:51 +0200 | [diff] [blame] | 1471 | ctx->start = &__start_mem_stats; |
| 1472 | ctx->stop = &__stop_mem_stats; |
Willy Tarreau | 4a426e2 | 2022-08-09 08:51:08 +0200 | [diff] [blame] | 1473 | ctx->width = 0; |
Willy Tarreau | a6026a0 | 2020-07-02 09:14:48 +0200 | [diff] [blame] | 1474 | return 0; |
| 1475 | } |
| 1476 | |
Willy Tarreau | 40e952f | 2022-05-05 14:39:51 +0200 | [diff] [blame] | 1477 | /* CLI I/O handler for the "debug dev memstats" command using a dev_mem_ctx |
| 1478 | * found in appctx->svcctx. Dumps all mem_stats structs referenced by pointers |
| 1479 | * located between ->start and ->stop. Dumps all entries if ->show_all != 0, |
| 1480 | * otherwise only non-zero calls. |
Willy Tarreau | a6026a0 | 2020-07-02 09:14:48 +0200 | [diff] [blame] | 1481 | */ |
| 1482 | static int debug_iohandler_memstats(struct appctx *appctx) |
| 1483 | { |
Willy Tarreau | 40e952f | 2022-05-05 14:39:51 +0200 | [diff] [blame] | 1484 | struct dev_mem_ctx *ctx = appctx->svcctx; |
Willy Tarreau | c12b321 | 2022-05-27 11:08:15 +0200 | [diff] [blame] | 1485 | struct stconn *sc = appctx_sc(appctx); |
Willy Tarreau | 4a426e2 | 2022-08-09 08:51:08 +0200 | [diff] [blame] | 1486 | struct mem_stats *ptr; |
Willy Tarreau | e57fbed | 2022-11-30 16:42:54 +0100 | [diff] [blame] | 1487 | const char *pfx = ctx->match; |
Willy Tarreau | a6026a0 | 2020-07-02 09:14:48 +0200 | [diff] [blame] | 1488 | int ret = 1; |
| 1489 | |
Christopher Faulet | 87633c3 | 2023-04-03 18:32:50 +0200 | [diff] [blame] | 1490 | /* FIXME: Don't watch the other side !*/ |
Christopher Faulet | 208c712 | 2023-04-13 16:16:15 +0200 | [diff] [blame] | 1491 | if (unlikely(sc_opposite(sc)->flags & SC_FL_SHUT_DONE)) |
Willy Tarreau | a6026a0 | 2020-07-02 09:14:48 +0200 | [diff] [blame] | 1492 | goto end; |
| 1493 | |
Willy Tarreau | 4a426e2 | 2022-08-09 08:51:08 +0200 | [diff] [blame] | 1494 | if (!ctx->width) { |
| 1495 | /* we don't know the first column's width, let's compute it |
| 1496 | * now based on a first pass on printable entries and their |
| 1497 | * expected width (approximated). |
| 1498 | */ |
| 1499 | for (ptr = ctx->start; ptr != ctx->stop; ptr++) { |
| 1500 | const char *p, *name; |
| 1501 | int w = 0; |
| 1502 | char tmp; |
| 1503 | |
| 1504 | if (!ptr->size && !ptr->calls && !ctx->show_all) |
| 1505 | continue; |
| 1506 | |
Willy Tarreau | d96d214 | 2022-09-06 08:05:59 +0200 | [diff] [blame] | 1507 | for (p = name = ptr->caller.file; *p; p++) { |
Willy Tarreau | 4a426e2 | 2022-08-09 08:51:08 +0200 | [diff] [blame] | 1508 | if (*p == '/') |
| 1509 | name = p + 1; |
| 1510 | } |
| 1511 | |
| 1512 | if (ctx->show_all) |
Willy Tarreau | d96d214 | 2022-09-06 08:05:59 +0200 | [diff] [blame] | 1513 | w = snprintf(&tmp, 0, "%s(%s:%d) ", ptr->caller.func, name, ptr->caller.line); |
Willy Tarreau | 4a426e2 | 2022-08-09 08:51:08 +0200 | [diff] [blame] | 1514 | else |
Willy Tarreau | d96d214 | 2022-09-06 08:05:59 +0200 | [diff] [blame] | 1515 | w = snprintf(&tmp, 0, "%s:%d ", name, ptr->caller.line); |
Willy Tarreau | 4a426e2 | 2022-08-09 08:51:08 +0200 | [diff] [blame] | 1516 | |
| 1517 | if (w > ctx->width) |
| 1518 | ctx->width = w; |
| 1519 | } |
| 1520 | } |
| 1521 | |
Willy Tarreau | a6026a0 | 2020-07-02 09:14:48 +0200 | [diff] [blame] | 1522 | /* we have two inner loops here, one for the proxy, the other one for |
| 1523 | * the buffer. |
| 1524 | */ |
Willy Tarreau | 4a426e2 | 2022-08-09 08:51:08 +0200 | [diff] [blame] | 1525 | for (ptr = ctx->start; ptr != ctx->stop; ptr++) { |
Willy Tarreau | a6026a0 | 2020-07-02 09:14:48 +0200 | [diff] [blame] | 1526 | const char *type; |
| 1527 | const char *name; |
| 1528 | const char *p; |
Willy Tarreau | 55c950b | 2022-08-09 08:15:27 +0200 | [diff] [blame] | 1529 | const char *info = NULL; |
Willy Tarreau | 17200dd | 2022-08-09 08:40:08 +0200 | [diff] [blame] | 1530 | const char *func = NULL; |
Willy Tarreau | b59e3f6 | 2022-11-30 17:16:51 +0100 | [diff] [blame] | 1531 | int direction = 0; // neither alloc nor free (e.g. realloc) |
Willy Tarreau | a6026a0 | 2020-07-02 09:14:48 +0200 | [diff] [blame] | 1532 | |
Willy Tarreau | 40e952f | 2022-05-05 14:39:51 +0200 | [diff] [blame] | 1533 | if (!ptr->size && !ptr->calls && !ctx->show_all) |
Willy Tarreau | a6026a0 | 2020-07-02 09:14:48 +0200 | [diff] [blame] | 1534 | continue; |
| 1535 | |
| 1536 | /* basename only */ |
Willy Tarreau | d96d214 | 2022-09-06 08:05:59 +0200 | [diff] [blame] | 1537 | for (p = name = ptr->caller.file; *p; p++) { |
Willy Tarreau | a6026a0 | 2020-07-02 09:14:48 +0200 | [diff] [blame] | 1538 | if (*p == '/') |
| 1539 | name = p + 1; |
| 1540 | } |
| 1541 | |
Willy Tarreau | d96d214 | 2022-09-06 08:05:59 +0200 | [diff] [blame] | 1542 | func = ptr->caller.func; |
Willy Tarreau | 17200dd | 2022-08-09 08:40:08 +0200 | [diff] [blame] | 1543 | |
Willy Tarreau | d96d214 | 2022-09-06 08:05:59 +0200 | [diff] [blame] | 1544 | switch (ptr->caller.what) { |
Willy Tarreau | b59e3f6 | 2022-11-30 17:16:51 +0100 | [diff] [blame] | 1545 | case MEM_STATS_TYPE_CALLOC: type = "CALLOC"; direction = 1; break; |
| 1546 | case MEM_STATS_TYPE_FREE: type = "FREE"; direction = -1; break; |
| 1547 | case MEM_STATS_TYPE_MALLOC: type = "MALLOC"; direction = 1; break; |
Willy Tarreau | a6026a0 | 2020-07-02 09:14:48 +0200 | [diff] [blame] | 1548 | case MEM_STATS_TYPE_REALLOC: type = "REALLOC"; break; |
Willy Tarreau | b59e3f6 | 2022-11-30 17:16:51 +0100 | [diff] [blame] | 1549 | case MEM_STATS_TYPE_STRDUP: type = "STRDUP"; direction = 1; break; |
| 1550 | case MEM_STATS_TYPE_P_ALLOC: type = "P_ALLOC"; direction = 1; if (ptr->extra) info = ((const struct pool_head *)ptr->extra)->name; break; |
| 1551 | case MEM_STATS_TYPE_P_FREE: type = "P_FREE"; direction = -1; if (ptr->extra) info = ((const struct pool_head *)ptr->extra)->name; break; |
Willy Tarreau | a6026a0 | 2020-07-02 09:14:48 +0200 | [diff] [blame] | 1552 | default: type = "UNSET"; break; |
| 1553 | } |
| 1554 | |
| 1555 | //chunk_printf(&trash, |
| 1556 | // "%20s:%-5d %7s size: %12lu calls: %9lu size/call: %6lu\n", |
| 1557 | // name, ptr->line, type, |
| 1558 | // (unsigned long)ptr->size, (unsigned long)ptr->calls, |
| 1559 | // (unsigned long)(ptr->calls ? (ptr->size / ptr->calls) : 0)); |
| 1560 | |
Willy Tarreau | e57fbed | 2022-11-30 16:42:54 +0100 | [diff] [blame] | 1561 | /* only match requested prefixes */ |
| 1562 | if (pfx && (!info || strncmp(info, pfx, strlen(pfx)) != 0)) |
| 1563 | continue; |
| 1564 | |
Willy Tarreau | 17200dd | 2022-08-09 08:40:08 +0200 | [diff] [blame] | 1565 | chunk_reset(&trash); |
| 1566 | if (ctx->show_all) |
| 1567 | chunk_appendf(&trash, "%s(", func); |
| 1568 | |
Willy Tarreau | d96d214 | 2022-09-06 08:05:59 +0200 | [diff] [blame] | 1569 | chunk_appendf(&trash, "%s:%d", name, ptr->caller.line); |
Willy Tarreau | 17200dd | 2022-08-09 08:40:08 +0200 | [diff] [blame] | 1570 | |
| 1571 | if (ctx->show_all) |
| 1572 | chunk_appendf(&trash, ")"); |
| 1573 | |
Willy Tarreau | 4a426e2 | 2022-08-09 08:51:08 +0200 | [diff] [blame] | 1574 | while (trash.data < ctx->width) |
Willy Tarreau | a6026a0 | 2020-07-02 09:14:48 +0200 | [diff] [blame] | 1575 | trash.area[trash.data++] = ' '; |
Willy Tarreau | 17200dd | 2022-08-09 08:40:08 +0200 | [diff] [blame] | 1576 | |
Willy Tarreau | 55c950b | 2022-08-09 08:15:27 +0200 | [diff] [blame] | 1577 | chunk_appendf(&trash, "%7s size: %12lu calls: %9lu size/call: %6lu %s\n", |
Willy Tarreau | a6026a0 | 2020-07-02 09:14:48 +0200 | [diff] [blame] | 1578 | type, |
| 1579 | (unsigned long)ptr->size, (unsigned long)ptr->calls, |
Willy Tarreau | 55c950b | 2022-08-09 08:15:27 +0200 | [diff] [blame] | 1580 | (unsigned long)(ptr->calls ? (ptr->size / ptr->calls) : 0), |
| 1581 | info ? info : ""); |
Willy Tarreau | a6026a0 | 2020-07-02 09:14:48 +0200 | [diff] [blame] | 1582 | |
Willy Tarreau | d0a06d5 | 2022-05-18 15:07:19 +0200 | [diff] [blame] | 1583 | if (applet_putchk(appctx, &trash) == -1) { |
Willy Tarreau | 40e952f | 2022-05-05 14:39:51 +0200 | [diff] [blame] | 1584 | ctx->start = ptr; |
Willy Tarreau | a6026a0 | 2020-07-02 09:14:48 +0200 | [diff] [blame] | 1585 | ret = 0; |
Willy Tarreau | b59e3f6 | 2022-11-30 17:16:51 +0100 | [diff] [blame] | 1586 | goto end; |
| 1587 | } |
| 1588 | if (direction > 0) { |
| 1589 | ctx->tot_size += (ulong)ptr->size; |
| 1590 | ctx->tot_calls += (ulong)ptr->calls; |
| 1591 | } |
| 1592 | else if (direction < 0) { |
| 1593 | ctx->tot_size -= (ulong)ptr->size; |
| 1594 | ctx->tot_calls += (ulong)ptr->calls; |
Willy Tarreau | a6026a0 | 2020-07-02 09:14:48 +0200 | [diff] [blame] | 1595 | } |
| 1596 | } |
| 1597 | |
Willy Tarreau | b59e3f6 | 2022-11-30 17:16:51 +0100 | [diff] [blame] | 1598 | /* now dump a summary */ |
| 1599 | chunk_reset(&trash); |
| 1600 | chunk_appendf(&trash, "Total"); |
| 1601 | while (trash.data < ctx->width) |
| 1602 | trash.area[trash.data++] = ' '; |
| 1603 | |
| 1604 | chunk_appendf(&trash, "%7s size: %12ld calls: %9lu size/call: %6ld %s\n", |
| 1605 | "BALANCE", |
| 1606 | ctx->tot_size, ctx->tot_calls, |
| 1607 | (long)(ctx->tot_calls ? (ctx->tot_size / ctx->tot_calls) : 0), |
| 1608 | "(excl. realloc)"); |
| 1609 | |
| 1610 | if (applet_putchk(appctx, &trash) == -1) { |
| 1611 | ctx->start = ptr; |
| 1612 | ret = 0; |
| 1613 | goto end; |
| 1614 | } |
Willy Tarreau | a6026a0 | 2020-07-02 09:14:48 +0200 | [diff] [blame] | 1615 | end: |
| 1616 | return ret; |
| 1617 | } |
| 1618 | |
Willy Tarreau | e57fbed | 2022-11-30 16:42:54 +0100 | [diff] [blame] | 1619 | /* release the "show pools" context */ |
| 1620 | static void debug_release_memstats(struct appctx *appctx) |
| 1621 | { |
| 1622 | struct dev_mem_ctx *ctx = appctx->svcctx; |
| 1623 | |
| 1624 | ha_free(&ctx->match); |
| 1625 | } |
Willy Tarreau | a6026a0 | 2020-07-02 09:14:48 +0200 | [diff] [blame] | 1626 | #endif |
| 1627 | |
Willy Tarreau | c7091d8 | 2019-05-17 10:08:49 +0200 | [diff] [blame] | 1628 | #ifndef USE_THREAD_DUMP |
| 1629 | |
| 1630 | /* This function dumps all threads' state to the trash. This version is the |
| 1631 | * most basic one, which doesn't inspect other threads. |
| 1632 | */ |
| 1633 | void ha_thread_dump_all_to_trash() |
| 1634 | { |
| 1635 | unsigned int thr; |
| 1636 | |
| 1637 | for (thr = 0; thr < global.nbthread; thr++) |
| 1638 | ha_thread_dump(&trash, thr, tid); |
| 1639 | } |
| 1640 | |
| 1641 | #else /* below USE_THREAD_DUMP is set */ |
| 1642 | |
Willy Tarreau | c7091d8 | 2019-05-17 10:08:49 +0200 | [diff] [blame] | 1643 | /* ID of the thread requesting the dump */ |
| 1644 | static unsigned int thread_dump_tid; |
| 1645 | |
| 1646 | /* points to the buffer where the dump functions should write. It must |
| 1647 | * have already been initialized by the requester. Nothing is done if |
| 1648 | * it's NULL. |
| 1649 | */ |
| 1650 | struct buffer *thread_dump_buffer = NULL; |
| 1651 | |
Willy Tarreau | 00c27b5 | 2022-07-01 19:08:56 +0200 | [diff] [blame] | 1652 | /* initiates a thread dump */ |
Willy Tarreau | c7091d8 | 2019-05-17 10:08:49 +0200 | [diff] [blame] | 1653 | void ha_thread_dump_all_to_trash() |
| 1654 | { |
Willy Tarreau | 039972b | 2022-07-01 19:37:42 +0200 | [diff] [blame] | 1655 | unsigned int old; |
Willy Tarreau | c7091d8 | 2019-05-17 10:08:49 +0200 | [diff] [blame] | 1656 | |
Willy Tarreau | f0c86dd | 2022-07-15 13:14:03 +0200 | [diff] [blame] | 1657 | /* initiate a dump starting from first thread. Use a CAS so that we do |
| 1658 | * not wait if we're not the first one, but we wait for a previous dump |
| 1659 | * to finish. |
Willy Tarreau | 6729726 | 2022-07-13 08:59:39 +0200 | [diff] [blame] | 1660 | */ |
Willy Tarreau | f0c86dd | 2022-07-15 13:14:03 +0200 | [diff] [blame] | 1661 | while (1) { |
| 1662 | old = 0; |
| 1663 | if (HA_ATOMIC_CAS(&thread_dump_state, &old, THREAD_DUMP_FSYNC)) |
| 1664 | break; |
| 1665 | ha_thread_relax(); |
| 1666 | } |
Willy Tarreau | c7091d8 | 2019-05-17 10:08:49 +0200 | [diff] [blame] | 1667 | thread_dump_buffer = &trash; |
| 1668 | thread_dump_tid = tid; |
Willy Tarreau | fade80d | 2019-05-22 08:46:59 +0200 | [diff] [blame] | 1669 | ha_tkillall(DEBUGSIG); |
Willy Tarreau | f0c86dd | 2022-07-15 13:14:03 +0200 | [diff] [blame] | 1670 | |
| 1671 | /* the call above contains a raise() so we're certain to return after |
| 1672 | * returning from the sighandler, hence when the dump is complete. |
| 1673 | */ |
Willy Tarreau | c7091d8 | 2019-05-17 10:08:49 +0200 | [diff] [blame] | 1674 | } |
| 1675 | |
Willy Tarreau | f0c86dd | 2022-07-15 13:14:03 +0200 | [diff] [blame] | 1676 | /* handles DEBUGSIG to dump the state of the thread it's working on. This is |
| 1677 | * appended at the end of thread_dump_buffer which must be protected against |
| 1678 | * reentrance from different threads (a thread-local buffer works fine). |
| 1679 | */ |
Willy Tarreau | c7091d8 | 2019-05-17 10:08:49 +0200 | [diff] [blame] | 1680 | void debug_handler(int sig, siginfo_t *si, void *arg) |
| 1681 | { |
Willy Tarreau | a2b8ed4 | 2022-07-01 17:11:03 +0200 | [diff] [blame] | 1682 | int harmless = is_thread_harmless(); |
Willy Tarreau | f0c86dd | 2022-07-15 13:14:03 +0200 | [diff] [blame] | 1683 | int running = 0; |
| 1684 | uint prev; |
Willy Tarreau | 00c27b5 | 2022-07-01 19:08:56 +0200 | [diff] [blame] | 1685 | uint next; |
Willy Tarreau | a2b8ed4 | 2022-07-01 17:11:03 +0200 | [diff] [blame] | 1686 | |
Willy Tarreau | 82aafc4 | 2020-03-03 08:31:34 +0100 | [diff] [blame] | 1687 | /* first, let's check it's really for us and that we didn't just get |
| 1688 | * a spurious DEBUGSIG. |
| 1689 | */ |
Willy Tarreau | 00c27b5 | 2022-07-01 19:08:56 +0200 | [diff] [blame] | 1690 | if (!_HA_ATOMIC_LOAD(&thread_dump_state)) |
Willy Tarreau | 82aafc4 | 2020-03-03 08:31:34 +0100 | [diff] [blame] | 1691 | return; |
| 1692 | |
Willy Tarreau | f0c86dd | 2022-07-15 13:14:03 +0200 | [diff] [blame] | 1693 | /* There are 5 phases in the dump process: |
| 1694 | * 1- wait for all threads to sync or the first one to start |
| 1695 | * 2- wait for our turn, i.e. when tid appears in lower bits. |
| 1696 | * 3- perform the action if our tid is there |
| 1697 | * 4- pass tid to the number of the next thread to dump or |
| 1698 | * reset running counter if we're last one. |
| 1699 | * 5- wait for running to be zero and decrement the count |
Willy Tarreau | c7091d8 | 2019-05-17 10:08:49 +0200 | [diff] [blame] | 1700 | */ |
| 1701 | |
| 1702 | /* wait for all previous threads to finish first */ |
Willy Tarreau | f7afdd9 | 2022-07-01 17:19:14 +0200 | [diff] [blame] | 1703 | if (!harmless) |
| 1704 | thread_harmless_now(); |
| 1705 | |
Willy Tarreau | f0c86dd | 2022-07-15 13:14:03 +0200 | [diff] [blame] | 1706 | if (HA_ATOMIC_FETCH_ADD(&thread_dump_state, 1) == THREAD_DUMP_FSYNC) { |
| 1707 | /* the first one which lands here is responsible for constantly |
| 1708 | * recounting the number of active theads and switching from |
| 1709 | * SYNC to DUMP. |
| 1710 | */ |
| 1711 | while (1) { |
| 1712 | int first = -1; // first tid to dump |
| 1713 | int thr; |
| 1714 | |
| 1715 | running = 0; |
| 1716 | for (thr = 0; thr < global.nbthread; thr++) { |
| 1717 | if (ha_thread_info[thr].tg->threads_enabled & ha_thread_info[thr].ltid_bit) { |
| 1718 | running++; |
| 1719 | if (first < 0) |
| 1720 | first = thr; |
| 1721 | } |
| 1722 | } |
| 1723 | |
| 1724 | if ((HA_ATOMIC_LOAD(&thread_dump_state) & THREAD_DUMP_TMASK) == running) { |
| 1725 | /* all threads are there, let's try to start */ |
| 1726 | prev = THREAD_DUMP_FSYNC | running; |
| 1727 | next = (running << 16) | first; |
| 1728 | if (HA_ATOMIC_CAS(&thread_dump_state, &prev, next)) |
| 1729 | break; |
| 1730 | /* it failed! maybe a thread appeared late (e.g. during boot), let's |
| 1731 | * recount. |
| 1732 | */ |
| 1733 | } |
| 1734 | ha_thread_relax(); |
| 1735 | } |
| 1736 | } |
| 1737 | |
| 1738 | /* all threads: let's wait for the SYNC flag to disappear; tid is reset at |
| 1739 | * the same time to the first valid tid to dump and pmask will reflect the |
| 1740 | * number of participants. |
| 1741 | */ |
| 1742 | while (HA_ATOMIC_LOAD(&thread_dump_state) & THREAD_DUMP_FSYNC) |
| 1743 | ha_thread_relax(); |
| 1744 | |
| 1745 | /* wait for our turn */ |
| 1746 | while ((HA_ATOMIC_LOAD(&thread_dump_state) & THREAD_DUMP_TMASK) != tid) |
Willy Tarreau | c7091d8 | 2019-05-17 10:08:49 +0200 | [diff] [blame] | 1747 | ha_thread_relax(); |
| 1748 | |
Willy Tarreau | f7afdd9 | 2022-07-01 17:19:14 +0200 | [diff] [blame] | 1749 | if (!harmless) |
Willy Tarreau | 9debe0f | 2023-01-19 18:52:31 +0100 | [diff] [blame] | 1750 | thread_harmless_end_sig(); |
Willy Tarreau | f7afdd9 | 2022-07-01 17:19:14 +0200 | [diff] [blame] | 1751 | |
Willy Tarreau | c7091d8 | 2019-05-17 10:08:49 +0200 | [diff] [blame] | 1752 | /* dump if needed */ |
Willy Tarreau | 00c27b5 | 2022-07-01 19:08:56 +0200 | [diff] [blame] | 1753 | if (thread_dump_buffer) |
| 1754 | ha_thread_dump(thread_dump_buffer, tid, thread_dump_tid); |
| 1755 | |
Willy Tarreau | f0c86dd | 2022-07-15 13:14:03 +0200 | [diff] [blame] | 1756 | /* figure which is the next thread ID to dump among enabled ones. Note |
| 1757 | * that this relies on the fact that we're not creating new threads in |
| 1758 | * the middle of a dump, which is normally granted by the harmless bits |
| 1759 | * anyway. |
| 1760 | */ |
Willy Tarreau | 00c27b5 | 2022-07-01 19:08:56 +0200 | [diff] [blame] | 1761 | for (next = tid + 1; next < global.nbthread; next++) { |
| 1762 | if (unlikely(next >= MAX_THREADS)) { |
| 1763 | /* just to please gcc 6.5 who guesses the ranges wrong. */ |
| 1764 | continue; |
Willy Tarreau | c7091d8 | 2019-05-17 10:08:49 +0200 | [diff] [blame] | 1765 | } |
Willy Tarreau | 00c27b5 | 2022-07-01 19:08:56 +0200 | [diff] [blame] | 1766 | |
| 1767 | if (ha_thread_info[next].tg && |
| 1768 | ha_thread_info[next].tg->threads_enabled & ha_thread_info[next].ltid_bit) |
| 1769 | break; |
Willy Tarreau | c7091d8 | 2019-05-17 10:08:49 +0200 | [diff] [blame] | 1770 | } |
| 1771 | |
Willy Tarreau | f0c86dd | 2022-07-15 13:14:03 +0200 | [diff] [blame] | 1772 | /* if there are threads left to dump, we atomically set the next one, |
| 1773 | * otherwise we'll clear dump and set the thread part to the number of |
| 1774 | * threads that need to disappear. |
| 1775 | */ |
| 1776 | if (next < global.nbthread) { |
| 1777 | next = (HA_ATOMIC_LOAD(&thread_dump_state) & THREAD_DUMP_PMASK) | next; |
| 1778 | HA_ATOMIC_STORE(&thread_dump_state, next); |
| 1779 | } else { |
Willy Tarreau | 00c27b5 | 2022-07-01 19:08:56 +0200 | [diff] [blame] | 1780 | thread_dump_buffer = NULL; // was the last one |
Willy Tarreau | f0c86dd | 2022-07-15 13:14:03 +0200 | [diff] [blame] | 1781 | running = (HA_ATOMIC_LOAD(&thread_dump_state) & THREAD_DUMP_PMASK) >> 16; |
| 1782 | HA_ATOMIC_STORE(&thread_dump_state, running); |
| 1783 | } |
Willy Tarreau | 00c27b5 | 2022-07-01 19:08:56 +0200 | [diff] [blame] | 1784 | |
| 1785 | /* now wait for all others to finish dumping: the lowest part will turn |
Willy Tarreau | 9debe0f | 2023-01-19 18:52:31 +0100 | [diff] [blame] | 1786 | * to zero. Then all others decrement the done part. We must not change |
| 1787 | * the harmless status anymore because one of the other threads might |
| 1788 | * have been interrupted in thread_isolate() waiting for all others to |
| 1789 | * become harmless, and changing the situation here would break that |
| 1790 | * promise. |
Willy Tarreau | c7091d8 | 2019-05-17 10:08:49 +0200 | [diff] [blame] | 1791 | */ |
Willy Tarreau | f7afdd9 | 2022-07-01 17:19:14 +0200 | [diff] [blame] | 1792 | |
Willy Tarreau | f0c86dd | 2022-07-15 13:14:03 +0200 | [diff] [blame] | 1793 | /* wait for everyone to finish*/ |
| 1794 | while (HA_ATOMIC_LOAD(&thread_dump_state) & THREAD_DUMP_PMASK) |
Willy Tarreau | c077362 | 2019-07-31 19:15:45 +0200 | [diff] [blame] | 1795 | ha_thread_relax(); |
Willy Tarreau | f7afdd9 | 2022-07-01 17:19:14 +0200 | [diff] [blame] | 1796 | |
Willy Tarreau | f0c86dd | 2022-07-15 13:14:03 +0200 | [diff] [blame] | 1797 | /* we're gone. Past this point anything can happen including another |
| 1798 | * thread trying to re-trigger a dump, so thread_dump_buffer and |
| 1799 | * thread_dump_tid may become invalid immediately after this call. |
| 1800 | */ |
| 1801 | HA_ATOMIC_SUB(&thread_dump_state, 1); |
Willy Tarreau | e6a02fa | 2019-05-22 07:06:44 +0200 | [diff] [blame] | 1802 | |
| 1803 | /* mark the current thread as stuck to detect it upon next invocation |
| 1804 | * if it didn't move. |
| 1805 | */ |
Willy Tarreau | a2b8ed4 | 2022-07-01 17:11:03 +0200 | [diff] [blame] | 1806 | if (!harmless && |
Willy Tarreau | e7475c8 | 2022-06-20 09:23:24 +0200 | [diff] [blame] | 1807 | !(_HA_ATOMIC_LOAD(&th_ctx->flags) & TH_FL_SLEEPING)) |
Willy Tarreau | bdcd325 | 2022-06-22 09:19:46 +0200 | [diff] [blame] | 1808 | _HA_ATOMIC_OR(&th_ctx->flags, TH_FL_STUCK); |
Willy Tarreau | c7091d8 | 2019-05-17 10:08:49 +0200 | [diff] [blame] | 1809 | } |
| 1810 | |
| 1811 | static int init_debug_per_thread() |
| 1812 | { |
| 1813 | sigset_t set; |
| 1814 | |
| 1815 | /* unblock the DEBUGSIG signal we intend to use */ |
| 1816 | sigemptyset(&set); |
| 1817 | sigaddset(&set, DEBUGSIG); |
Willy Tarreau | bd3b44e | 2023-03-09 08:25:01 +0100 | [diff] [blame] | 1818 | #if defined(DEBUG_DEV) |
| 1819 | sigaddset(&set, SIGRTMAX); |
| 1820 | #endif |
Willy Tarreau | c7091d8 | 2019-05-17 10:08:49 +0200 | [diff] [blame] | 1821 | ha_sigmask(SIG_UNBLOCK, &set, NULL); |
| 1822 | return 1; |
| 1823 | } |
| 1824 | |
| 1825 | static int init_debug() |
| 1826 | { |
| 1827 | struct sigaction sa; |
Willy Tarreau | 2f1227e | 2021-01-22 12:12:29 +0100 | [diff] [blame] | 1828 | void *callers[1]; |
Willy Tarreau | c7091d8 | 2019-05-17 10:08:49 +0200 | [diff] [blame] | 1829 | |
Willy Tarreau | 0214b45 | 2020-03-04 06:01:40 +0100 | [diff] [blame] | 1830 | /* calling backtrace() will access libgcc at runtime. We don't want to |
| 1831 | * do it after the chroot, so let's perform a first call to have it |
| 1832 | * ready in memory for later use. |
| 1833 | */ |
Willy Tarreau | 13faf16 | 2020-03-04 07:44:06 +0100 | [diff] [blame] | 1834 | my_backtrace(callers, sizeof(callers)/sizeof(*callers)); |
Willy Tarreau | c7091d8 | 2019-05-17 10:08:49 +0200 | [diff] [blame] | 1835 | sa.sa_handler = NULL; |
| 1836 | sa.sa_sigaction = debug_handler; |
| 1837 | sigemptyset(&sa.sa_mask); |
| 1838 | sa.sa_flags = SA_SIGINFO; |
| 1839 | sigaction(DEBUGSIG, &sa, NULL); |
Willy Tarreau | bd3b44e | 2023-03-09 08:25:01 +0100 | [diff] [blame] | 1840 | |
| 1841 | #if defined(DEBUG_DEV) |
| 1842 | sa.sa_handler = NULL; |
| 1843 | sa.sa_sigaction = debug_delay_inj_sighandler; |
| 1844 | sigemptyset(&sa.sa_mask); |
| 1845 | sa.sa_flags = SA_SIGINFO; |
| 1846 | sigaction(SIGRTMAX, &sa, NULL); |
| 1847 | #endif |
Christopher Faulet | fc633b6 | 2020-11-06 15:24:23 +0100 | [diff] [blame] | 1848 | return ERR_NONE; |
Willy Tarreau | c7091d8 | 2019-05-17 10:08:49 +0200 | [diff] [blame] | 1849 | } |
| 1850 | |
| 1851 | REGISTER_POST_CHECK(init_debug); |
| 1852 | REGISTER_PER_THREAD_INIT(init_debug_per_thread); |
| 1853 | |
| 1854 | #endif /* USE_THREAD_DUMP */ |
| 1855 | |
Willy Tarreau | 4e2b646 | 2019-05-16 17:44:30 +0200 | [diff] [blame] | 1856 | /* register cli keywords */ |
| 1857 | static struct cli_kw_list cli_kws = {{ },{ |
Willy Tarreau | b205bfd | 2021-05-07 11:38:37 +0200 | [diff] [blame] | 1858 | {{ "debug", "dev", "bug", NULL }, "debug dev bug : call BUG_ON() and crash", debug_parse_cli_bug, NULL, NULL, NULL, ACCESS_EXPERT }, |
Willy Tarreau | 6d3f1e3 | 2022-02-28 11:51:23 +0100 | [diff] [blame] | 1859 | {{ "debug", "dev", "check", NULL }, "debug dev check : call CHECK_IF() and possibly crash", debug_parse_cli_check, NULL, NULL, NULL, ACCESS_EXPERT }, |
Willy Tarreau | b205bfd | 2021-05-07 11:38:37 +0200 | [diff] [blame] | 1860 | {{ "debug", "dev", "close", NULL }, "debug dev close <fd> : close this file descriptor", debug_parse_cli_close, NULL, NULL, NULL, ACCESS_EXPERT }, |
Willy Tarreau | dadf00e | 2022-07-15 08:25:03 +0200 | [diff] [blame] | 1861 | {{ "debug", "dev", "deadlock", NULL }, "debug dev deadlock [nbtask] : deadlock between this number of tasks", debug_parse_cli_deadlock, NULL, NULL, NULL, ACCESS_EXPERT }, |
Willy Tarreau | b205bfd | 2021-05-07 11:38:37 +0200 | [diff] [blame] | 1862 | {{ "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] | 1863 | #if defined(DEBUG_DEV) |
Willy Tarreau | bd3b44e | 2023-03-09 08:25:01 +0100 | [diff] [blame] | 1864 | {{ "debug", "dev", "delay-inj", NULL },"debug dev delay-inj <inter> <count> : inject random delays into threads", debug_parse_delay_inj, NULL, NULL, NULL, ACCESS_EXPERT }, |
Willy Tarreau | b205bfd | 2021-05-07 11:38:37 +0200 | [diff] [blame] | 1865 | {{ "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] | 1866 | #endif |
Willy Tarreau | 5be7c19 | 2022-01-24 20:26:09 +0100 | [diff] [blame] | 1867 | {{ "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] | 1868 | {{ "debug", "dev", "exit", NULL }, "debug dev exit [code] : immediately exit the process", debug_parse_cli_exit, NULL, NULL, NULL, ACCESS_EXPERT }, |
Willy Tarreau | 111c783 | 2022-11-30 17:51:47 +0100 | [diff] [blame] | 1869 | {{ "debug", "dev", "hash", NULL }, "debug dev hash [msg] : return msg hashed if anon is set", debug_parse_cli_hash, NULL, NULL, NULL, 0 }, |
Willy Tarreau | b205bfd | 2021-05-07 11:38:37 +0200 | [diff] [blame] | 1870 | {{ "debug", "dev", "hex", NULL }, "debug dev hex <addr> [len] : dump a memory area", debug_parse_cli_hex, NULL, NULL, NULL, ACCESS_EXPERT }, |
| 1871 | {{ "debug", "dev", "log", NULL }, "debug dev log [msg] ... : send this msg to global logs", debug_parse_cli_log, NULL, NULL, NULL, ACCESS_EXPERT }, |
Willy Tarreau | e5e6223 | 2023-05-04 11:50:26 +0200 | [diff] [blame] | 1872 | {{ "debug", "dev", "loop", NULL }, "debug dev loop <ms> [isolated] : loop this long, possibly isolated", debug_parse_cli_loop, NULL, NULL, NULL, ACCESS_EXPERT }, |
Willy Tarreau | a6026a0 | 2020-07-02 09:14:48 +0200 | [diff] [blame] | 1873 | #if defined(DEBUG_MEM_STATS) |
Willy Tarreau | e57fbed | 2022-11-30 16:42:54 +0100 | [diff] [blame] | 1874 | {{ "debug", "dev", "memstats", NULL }, "debug dev memstats [reset|all|match ...]: dump/reset memory statistics", debug_parse_cli_memstats, debug_iohandler_memstats, debug_release_memstats, NULL, 0 }, |
Willy Tarreau | a6026a0 | 2020-07-02 09:14:48 +0200 | [diff] [blame] | 1875 | #endif |
Willy Tarreau | b205bfd | 2021-05-07 11:38:37 +0200 | [diff] [blame] | 1876 | {{ "debug", "dev", "panic", NULL }, "debug dev panic : immediately trigger a panic", debug_parse_cli_panic, NULL, NULL, NULL, ACCESS_EXPERT }, |
| 1877 | {{ "debug", "dev", "sched", NULL }, "debug dev sched {task|tasklet} [k=v]* : stress the scheduler", debug_parse_cli_sched, NULL, NULL, NULL, ACCESS_EXPERT }, |
| 1878 | {{ "debug", "dev", "stream",NULL }, "debug dev stream [k=v]* : show/manipulate stream flags", debug_parse_cli_stream,NULL, NULL, NULL, ACCESS_EXPERT }, |
| 1879 | {{ "debug", "dev", "sym", NULL }, "debug dev sym <addr> : resolve symbol address", debug_parse_cli_sym, NULL, NULL, NULL, ACCESS_EXPERT }, |
Willy Tarreau | 9867987 | 2023-05-03 11:22:45 +0200 | [diff] [blame] | 1880 | {{ "debug", "dev", "task", NULL }, "debug dev task <ptr> [wake|expire|kill] : show/wake/expire/kill task/tasklet", debug_parse_cli_task, NULL, NULL, NULL, ACCESS_EXPERT }, |
Willy Tarreau | b205bfd | 2021-05-07 11:38:37 +0200 | [diff] [blame] | 1881 | {{ "debug", "dev", "tkill", NULL }, "debug dev tkill [thr] [sig] : send signal to thread", debug_parse_cli_tkill, NULL, NULL, NULL, ACCESS_EXPERT }, |
Willy Tarreau | 305cfbd | 2022-02-25 08:52:39 +0100 | [diff] [blame] | 1882 | {{ "debug", "dev", "warn", NULL }, "debug dev warn : call WARN_ON() and possibly crash", debug_parse_cli_warn, NULL, NULL, NULL, ACCESS_EXPERT }, |
Willy Tarreau | b205bfd | 2021-05-07 11:38:37 +0200 | [diff] [blame] | 1883 | {{ "debug", "dev", "write", NULL }, "debug dev write [size] : write that many bytes in return", debug_parse_cli_write, NULL, NULL, NULL, ACCESS_EXPERT }, |
Erwan Le Goas | 54966df | 2022-09-14 17:24:22 +0200 | [diff] [blame] | 1884 | |
Willy Tarreau | 6ab7b21 | 2021-12-28 09:57:10 +0100 | [diff] [blame] | 1885 | #if defined(HA_HAVE_DUMP_LIBS) |
| 1886 | {{ "show", "libs", NULL, NULL }, "show libs : show loaded object files and libraries", debug_parse_cli_show_libs, NULL, NULL }, |
| 1887 | #endif |
Willy Tarreau | b205bfd | 2021-05-07 11:38:37 +0200 | [diff] [blame] | 1888 | {{ "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] | 1889 | {{},} |
| 1890 | }}; |
| 1891 | |
| 1892 | INITCALL1(STG_REGISTER, cli_register_kw, &cli_kws); |