.. | .. |
---|
1 | 1 | // SPDX-License-Identifier: GPL-2.0 |
---|
2 | 2 | /* For general debugging purposes */ |
---|
3 | 3 | |
---|
4 | | -#include "../perf.h" |
---|
5 | | - |
---|
6 | 4 | #include <inttypes.h> |
---|
7 | 5 | #include <string.h> |
---|
8 | 6 | #include <stdarg.h> |
---|
9 | 7 | #include <stdio.h> |
---|
| 8 | +#include <stdlib.h> |
---|
10 | 9 | #include <sys/wait.h> |
---|
11 | 10 | #include <api/debug.h> |
---|
| 11 | +#include <linux/kernel.h> |
---|
12 | 12 | #include <linux/time64.h> |
---|
13 | 13 | #ifdef HAVE_BACKTRACE_SUPPORT |
---|
14 | 14 | #include <execinfo.h> |
---|
15 | 15 | #endif |
---|
16 | | -#include "cache.h" |
---|
17 | 16 | #include "color.h" |
---|
18 | 17 | #include "event.h" |
---|
19 | 18 | #include "debug.h" |
---|
20 | 19 | #include "print_binary.h" |
---|
21 | | -#include "util.h" |
---|
22 | 20 | #include "target.h" |
---|
| 21 | +#include "ui/helpline.h" |
---|
| 22 | +#include "ui/ui.h" |
---|
| 23 | +#include "util/parse-sublevel-options.h" |
---|
23 | 24 | |
---|
24 | | -#include "sane_ctype.h" |
---|
| 25 | +#include <linux/ctype.h> |
---|
25 | 26 | |
---|
26 | 27 | int verbose; |
---|
| 28 | +int debug_peo_args; |
---|
27 | 29 | bool dump_trace = false, quiet = false; |
---|
28 | 30 | int debug_ordered_events; |
---|
29 | 31 | static int redirect_to_stderr; |
---|
.. | .. |
---|
143 | 145 | break; |
---|
144 | 146 | case BINARY_PRINT_CHAR_DATA: |
---|
145 | 147 | printed += color_fprintf(fp, color, "%c", |
---|
146 | | - isprint(ch) ? ch : '.'); |
---|
| 148 | + isprint(ch) && isascii(ch) ? ch : '.'); |
---|
147 | 149 | break; |
---|
148 | 150 | case BINARY_PRINT_CHAR_PAD: |
---|
149 | 151 | printed += color_fprintf(fp, color, " "); |
---|
.. | .. |
---|
172 | 174 | trace_event_printer, event); |
---|
173 | 175 | } |
---|
174 | 176 | |
---|
175 | | -static struct debug_variable { |
---|
176 | | - const char *name; |
---|
177 | | - int *ptr; |
---|
178 | | -} debug_variables[] = { |
---|
179 | | - { .name = "verbose", .ptr = &verbose }, |
---|
180 | | - { .name = "ordered-events", .ptr = &debug_ordered_events}, |
---|
181 | | - { .name = "stderr", .ptr = &redirect_to_stderr}, |
---|
182 | | - { .name = "data-convert", .ptr = &debug_data_convert }, |
---|
| 177 | +static struct sublevel_option debug_opts[] = { |
---|
| 178 | + { .name = "verbose", .value_ptr = &verbose }, |
---|
| 179 | + { .name = "ordered-events", .value_ptr = &debug_ordered_events}, |
---|
| 180 | + { .name = "stderr", .value_ptr = &redirect_to_stderr}, |
---|
| 181 | + { .name = "data-convert", .value_ptr = &debug_data_convert }, |
---|
| 182 | + { .name = "perf-event-open", .value_ptr = &debug_peo_args }, |
---|
183 | 183 | { .name = NULL, } |
---|
184 | 184 | }; |
---|
185 | 185 | |
---|
186 | 186 | int perf_debug_option(const char *str) |
---|
187 | 187 | { |
---|
188 | | - struct debug_variable *var = &debug_variables[0]; |
---|
189 | | - char *vstr, *s = strdup(str); |
---|
190 | | - int v = 1; |
---|
| 188 | + int ret; |
---|
191 | 189 | |
---|
192 | | - vstr = strchr(s, '='); |
---|
193 | | - if (vstr) |
---|
194 | | - *vstr++ = 0; |
---|
| 190 | + ret = perf_parse_sublevel_options(str, debug_opts); |
---|
| 191 | + if (ret) |
---|
| 192 | + return ret; |
---|
195 | 193 | |
---|
196 | | - while (var->name) { |
---|
197 | | - if (!strcmp(s, var->name)) |
---|
198 | | - break; |
---|
199 | | - var++; |
---|
200 | | - } |
---|
| 194 | + /* Allow only verbose value in range (0, 10), otherwise set 0. */ |
---|
| 195 | + verbose = (verbose < 0) || (verbose > 10) ? 0 : verbose; |
---|
201 | 196 | |
---|
202 | | - if (!var->name) { |
---|
203 | | - pr_err("Unknown debug variable name '%s'\n", s); |
---|
204 | | - free(s); |
---|
205 | | - return -1; |
---|
206 | | - } |
---|
207 | | - |
---|
208 | | - if (vstr) { |
---|
209 | | - v = atoi(vstr); |
---|
210 | | - /* |
---|
211 | | - * Allow only values in range (0, 10), |
---|
212 | | - * otherwise set 0. |
---|
213 | | - */ |
---|
214 | | - v = (v < 0) || (v > 10) ? 0 : v; |
---|
215 | | - } |
---|
216 | | - |
---|
217 | | - if (quiet) |
---|
218 | | - v = -1; |
---|
219 | | - |
---|
220 | | - *var->ptr = v; |
---|
221 | | - free(s); |
---|
222 | 197 | return 0; |
---|
223 | 198 | } |
---|
224 | 199 | |
---|
225 | 200 | int perf_quiet_option(void) |
---|
226 | 201 | { |
---|
227 | | - struct debug_variable *var = &debug_variables[0]; |
---|
| 202 | + struct sublevel_option *opt = &debug_opts[0]; |
---|
228 | 203 | |
---|
229 | 204 | /* disable all debug messages */ |
---|
230 | | - while (var->name) { |
---|
231 | | - *var->ptr = -1; |
---|
232 | | - var++; |
---|
| 205 | + while (opt->name) { |
---|
| 206 | + *opt->value_ptr = -1; |
---|
| 207 | + opt++; |
---|
233 | 208 | } |
---|
234 | 209 | |
---|
| 210 | + /* For debug variables that are used as bool types, set to 0. */ |
---|
| 211 | + redirect_to_stderr = 0; |
---|
| 212 | + debug_peo_args = 0; |
---|
| 213 | + |
---|
235 | 214 | return 0; |
---|
236 | 215 | } |
---|
237 | 216 | |
---|