hc
2024-05-10 23fa18eaa71266feff7ba8d83022d9e1cc83c65a
kernel/tools/perf/util/debug.c
....@@ -1,29 +1,31 @@
11 // SPDX-License-Identifier: GPL-2.0
22 /* For general debugging purposes */
33
4
-#include "../perf.h"
5
-
64 #include <inttypes.h>
75 #include <string.h>
86 #include <stdarg.h>
97 #include <stdio.h>
8
+#include <stdlib.h>
109 #include <sys/wait.h>
1110 #include <api/debug.h>
11
+#include <linux/kernel.h>
1212 #include <linux/time64.h>
1313 #ifdef HAVE_BACKTRACE_SUPPORT
1414 #include <execinfo.h>
1515 #endif
16
-#include "cache.h"
1716 #include "color.h"
1817 #include "event.h"
1918 #include "debug.h"
2019 #include "print_binary.h"
21
-#include "util.h"
2220 #include "target.h"
21
+#include "ui/helpline.h"
22
+#include "ui/ui.h"
23
+#include "util/parse-sublevel-options.h"
2324
24
-#include "sane_ctype.h"
25
+#include <linux/ctype.h>
2526
2627 int verbose;
28
+int debug_peo_args;
2729 bool dump_trace = false, quiet = false;
2830 int debug_ordered_events;
2931 static int redirect_to_stderr;
....@@ -143,7 +145,7 @@
143145 break;
144146 case BINARY_PRINT_CHAR_DATA:
145147 printed += color_fprintf(fp, color, "%c",
146
- isprint(ch) ? ch : '.');
148
+ isprint(ch) && isascii(ch) ? ch : '.');
147149 break;
148150 case BINARY_PRINT_CHAR_PAD:
149151 printed += color_fprintf(fp, color, " ");
....@@ -172,66 +174,43 @@
172174 trace_event_printer, event);
173175 }
174176
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 },
183183 { .name = NULL, }
184184 };
185185
186186 int perf_debug_option(const char *str)
187187 {
188
- struct debug_variable *var = &debug_variables[0];
189
- char *vstr, *s = strdup(str);
190
- int v = 1;
188
+ int ret;
191189
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;
195193
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;
201196
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);
222197 return 0;
223198 }
224199
225200 int perf_quiet_option(void)
226201 {
227
- struct debug_variable *var = &debug_variables[0];
202
+ struct sublevel_option *opt = &debug_opts[0];
228203
229204 /* 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++;
233208 }
234209
210
+ /* For debug variables that are used as bool types, set to 0. */
211
+ redirect_to_stderr = 0;
212
+ debug_peo_args = 0;
213
+
235214 return 0;
236215 }
237216