ppc/xive: Add support for the PC MMIOs
[qemu/kevin.git] / trace / trace-hmp-cmds.c
blob86211fce27397e091953a88c56813e88acad88c5
1 /*
2 * HMP commands related to tracing
4 * Copyright (c) 2003-2004 Fabrice Bellard
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
25 #include "qemu/osdep.h"
26 #include "monitor/hmp.h"
27 #include "monitor/monitor.h"
28 #include "qapi/error.h"
29 #include "qapi/qapi-commands-trace.h"
30 #include "qapi/qmp/qdict.h"
31 #include "trace/control.h"
32 #ifdef CONFIG_TRACE_SIMPLE
33 #include "trace/simple.h"
34 #endif
36 void hmp_trace_event(Monitor *mon, const QDict *qdict)
38 const char *tp_name = qdict_get_str(qdict, "name");
39 bool new_state = qdict_get_bool(qdict, "option");
40 Error *local_err = NULL;
42 qmp_trace_event_set_state(tp_name, new_state,
43 true, true, false, 0, &local_err);
44 if (local_err) {
45 error_report_err(local_err);
49 #ifdef CONFIG_TRACE_SIMPLE
50 void hmp_trace_file(Monitor *mon, const QDict *qdict)
52 const char *op = qdict_get_try_str(qdict, "op");
53 const char *arg = qdict_get_try_str(qdict, "arg");
55 if (!op) {
56 st_print_trace_file_status();
57 } else if (!strcmp(op, "on")) {
58 st_set_trace_file_enabled(true);
59 } else if (!strcmp(op, "off")) {
60 st_set_trace_file_enabled(false);
61 } else if (!strcmp(op, "flush")) {
62 st_flush_trace_buffer();
63 } else if (!strcmp(op, "set")) {
64 if (arg) {
65 st_set_trace_file(arg);
67 } else {
68 monitor_printf(mon, "unexpected argument \"%s\"\n", op);
69 hmp_help_cmd(mon, "trace-file");
72 #endif
74 void hmp_info_trace_events(Monitor *mon, const QDict *qdict)
76 const char *name = qdict_get_try_str(qdict, "name");
77 TraceEventInfoList *events;
78 TraceEventInfoList *elem;
79 Error *local_err = NULL;
81 if (name == NULL) {
82 name = "*";
85 events = qmp_trace_event_get_state(name, false, 0, &local_err);
86 if (local_err) {
87 error_report_err(local_err);
88 return;
91 for (elem = events; elem != NULL; elem = elem->next) {
92 monitor_printf(mon, "%s : state %u\n",
93 elem->value->name,
94 elem->value->state == TRACE_EVENT_STATE_ENABLED ? 1 : 0);
96 qapi_free_TraceEventInfoList(events);
99 void info_trace_events_completion(ReadLineState *rs, int nb_args, const char *str)
101 size_t len;
103 len = strlen(str);
104 readline_set_completion_index(rs, len);
105 if (nb_args == 2) {
106 TraceEventIter iter;
107 TraceEvent *ev;
108 char *pattern = g_strdup_printf("%s*", str);
109 trace_event_iter_init_pattern(&iter, pattern);
110 while ((ev = trace_event_iter_next(&iter)) != NULL) {
111 readline_add_completion(rs, trace_event_get_name(ev));
113 g_free(pattern);
117 void trace_event_completion(ReadLineState *rs, int nb_args, const char *str)
119 size_t len;
121 len = strlen(str);
122 readline_set_completion_index(rs, len);
123 if (nb_args == 2) {
124 TraceEventIter iter;
125 TraceEvent *ev;
126 char *pattern = g_strdup_printf("%s*", str);
127 trace_event_iter_init_pattern(&iter, pattern);
128 while ((ev = trace_event_iter_next(&iter)) != NULL) {
129 readline_add_completion(rs, trace_event_get_name(ev));
131 g_free(pattern);
132 } else if (nb_args == 3) {
133 readline_add_completion_of(rs, str, "on");
134 readline_add_completion_of(rs, str, "off");