Skip to content

Commit cbf8199

Browse files
author
Markus Armbruster
committed
monitor: Move remaining HMP commands from misc.c to hmp-cmds.c
This requires giving them external linkage. Rename do_help_cmd() to hmp_help(), and do_print() to hmp_print(). Signed-off-by: Markus Armbruster <[email protected]> Message-Id: <[email protected]>
1 parent e224556 commit cbf8199

File tree

4 files changed

+233
-221
lines changed

4 files changed

+233
-221
lines changed

hmp-commands.hx

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ HXCOMM HXCOMM can be used for comments, discarded from both rST and C.
1111
.args_type = "name:S?",
1212
.params = "[cmd]",
1313
.help = "show the help",
14-
.cmd = do_help_cmd,
14+
.cmd = hmp_help,
1515
.flags = "p",
1616
},
1717

@@ -563,7 +563,7 @@ ERST
563563
.args_type = "fmt:/,val:l",
564564
.params = "/fmt expr",
565565
.help = "print expression value (use $reg for CPU register access)",
566-
.cmd = do_print,
566+
.cmd = hmp_print,
567567
},
568568

569569
SRST

include/monitor/hmp.h

+13
Original file line numberDiff line numberDiff line change
@@ -165,5 +165,18 @@ void hmp_wavcapture(Monitor *mon, const QDict *qdict);
165165
void hmp_trace_event(Monitor *mon, const QDict *qdict);
166166
void hmp_trace_file(Monitor *mon, const QDict *qdict);
167167
void hmp_info_trace_events(Monitor *mon, const QDict *qdict);
168+
void hmp_help(Monitor *mon, const QDict *qdict);
169+
void hmp_info_help(Monitor *mon, const QDict *qdict);
170+
void hmp_info_sync_profile(Monitor *mon, const QDict *qdict);
171+
void hmp_info_history(Monitor *mon, const QDict *qdict);
172+
void hmp_logfile(Monitor *mon, const QDict *qdict);
173+
void hmp_log(Monitor *mon, const QDict *qdict);
174+
void hmp_gdbserver(Monitor *mon, const QDict *qdict);
175+
void hmp_print(Monitor *mon, const QDict *qdict);
176+
void hmp_sum(Monitor *mon, const QDict *qdict);
177+
void hmp_ioport_read(Monitor *mon, const QDict *qdict);
178+
void hmp_ioport_write(Monitor *mon, const QDict *qdict);
179+
void hmp_boot_set(Monitor *mon, const QDict *qdict);
180+
void hmp_info_mtree(Monitor *mon, const QDict *qdict);
168181

169182
#endif

monitor/hmp-cmds.c

+218-1
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,21 @@
1414
*/
1515

1616
#include "qemu/osdep.h"
17+
#include "exec/address-spaces.h"
18+
#include "exec/gdbstub.h"
19+
#include "exec/ioport.h"
1720
#include "monitor/hmp.h"
1821
#include "qemu/help_option.h"
19-
#include "monitor/monitor.h"
22+
#include "monitor/monitor-internal.h"
2023
#include "qapi/error.h"
2124
#include "qapi/qapi-commands-control.h"
2225
#include "qapi/qapi-commands-misc.h"
2326
#include "qapi/qmp/qdict.h"
2427
#include "qapi/qmp/qerror.h"
2528
#include "qemu/cutils.h"
2629
#include "hw/intc/intc.h"
30+
#include "qemu/log.h"
31+
#include "sysemu/sysemu.h"
2732

2833
bool hmp_handle_error(Monitor *mon, Error *err)
2934
{
@@ -224,3 +229,215 @@ void hmp_info_iothreads(Monitor *mon, const QDict *qdict)
224229

225230
qapi_free_IOThreadInfoList(info_list);
226231
}
232+
233+
void hmp_help(Monitor *mon, const QDict *qdict)
234+
{
235+
hmp_help_cmd(mon, qdict_get_try_str(qdict, "name"));
236+
}
237+
238+
void hmp_info_help(Monitor *mon, const QDict *qdict)
239+
{
240+
hmp_help_cmd(mon, "info");
241+
}
242+
243+
void hmp_info_sync_profile(Monitor *mon, const QDict *qdict)
244+
{
245+
int64_t max = qdict_get_try_int(qdict, "max", 10);
246+
bool mean = qdict_get_try_bool(qdict, "mean", false);
247+
bool coalesce = !qdict_get_try_bool(qdict, "no_coalesce", false);
248+
enum QSPSortBy sort_by;
249+
250+
sort_by = mean ? QSP_SORT_BY_AVG_WAIT_TIME : QSP_SORT_BY_TOTAL_WAIT_TIME;
251+
qsp_report(max, sort_by, coalesce);
252+
}
253+
254+
void hmp_info_history(Monitor *mon, const QDict *qdict)
255+
{
256+
MonitorHMP *hmp_mon = container_of(mon, MonitorHMP, common);
257+
int i;
258+
const char *str;
259+
260+
if (!hmp_mon->rs) {
261+
return;
262+
}
263+
i = 0;
264+
for(;;) {
265+
str = readline_get_history(hmp_mon->rs, i);
266+
if (!str) {
267+
break;
268+
}
269+
monitor_printf(mon, "%d: '%s'\n", i, str);
270+
i++;
271+
}
272+
}
273+
274+
void hmp_logfile(Monitor *mon, const QDict *qdict)
275+
{
276+
Error *err = NULL;
277+
278+
if (!qemu_set_log_filename(qdict_get_str(qdict, "filename"), &err)) {
279+
error_report_err(err);
280+
}
281+
}
282+
283+
void hmp_log(Monitor *mon, const QDict *qdict)
284+
{
285+
int mask;
286+
const char *items = qdict_get_str(qdict, "items");
287+
Error *err = NULL;
288+
289+
if (!strcmp(items, "none")) {
290+
mask = 0;
291+
} else {
292+
mask = qemu_str_to_log_mask(items);
293+
if (!mask) {
294+
hmp_help_cmd(mon, "log");
295+
return;
296+
}
297+
}
298+
299+
if (!qemu_set_log(mask, &err)) {
300+
error_report_err(err);
301+
}
302+
}
303+
304+
void hmp_gdbserver(Monitor *mon, const QDict *qdict)
305+
{
306+
const char *device = qdict_get_try_str(qdict, "device");
307+
if (!device) {
308+
device = "tcp::" DEFAULT_GDBSTUB_PORT;
309+
}
310+
311+
if (gdbserver_start(device) < 0) {
312+
monitor_printf(mon, "Could not open gdbserver on device '%s'\n",
313+
device);
314+
} else if (strcmp(device, "none") == 0) {
315+
monitor_printf(mon, "Disabled gdbserver\n");
316+
} else {
317+
monitor_printf(mon, "Waiting for gdb connection on device '%s'\n",
318+
device);
319+
}
320+
}
321+
322+
void hmp_print(Monitor *mon, const QDict *qdict)
323+
{
324+
int format = qdict_get_int(qdict, "format");
325+
hwaddr val = qdict_get_int(qdict, "val");
326+
327+
switch(format) {
328+
case 'o':
329+
monitor_printf(mon, "%#" HWADDR_PRIo, val);
330+
break;
331+
case 'x':
332+
monitor_printf(mon, "%#" HWADDR_PRIx, val);
333+
break;
334+
case 'u':
335+
monitor_printf(mon, "%" HWADDR_PRIu, val);
336+
break;
337+
default:
338+
case 'd':
339+
monitor_printf(mon, "%" HWADDR_PRId, val);
340+
break;
341+
case 'c':
342+
monitor_printc(mon, val);
343+
break;
344+
}
345+
monitor_printf(mon, "\n");
346+
}
347+
348+
void hmp_sum(Monitor *mon, const QDict *qdict)
349+
{
350+
uint32_t addr;
351+
uint16_t sum;
352+
uint32_t start = qdict_get_int(qdict, "start");
353+
uint32_t size = qdict_get_int(qdict, "size");
354+
355+
sum = 0;
356+
for(addr = start; addr < (start + size); addr++) {
357+
uint8_t val = address_space_ldub(&address_space_memory, addr,
358+
MEMTXATTRS_UNSPECIFIED, NULL);
359+
/* BSD sum algorithm ('sum' Unix command) */
360+
sum = (sum >> 1) | (sum << 15);
361+
sum += val;
362+
}
363+
monitor_printf(mon, "%05d\n", sum);
364+
}
365+
366+
void hmp_ioport_read(Monitor *mon, const QDict *qdict)
367+
{
368+
int size = qdict_get_int(qdict, "size");
369+
int addr = qdict_get_int(qdict, "addr");
370+
int has_index = qdict_haskey(qdict, "index");
371+
uint32_t val;
372+
int suffix;
373+
374+
if (has_index) {
375+
int index = qdict_get_int(qdict, "index");
376+
cpu_outb(addr & IOPORTS_MASK, index & 0xff);
377+
addr++;
378+
}
379+
addr &= 0xffff;
380+
381+
switch(size) {
382+
default:
383+
case 1:
384+
val = cpu_inb(addr);
385+
suffix = 'b';
386+
break;
387+
case 2:
388+
val = cpu_inw(addr);
389+
suffix = 'w';
390+
break;
391+
case 4:
392+
val = cpu_inl(addr);
393+
suffix = 'l';
394+
break;
395+
}
396+
monitor_printf(mon, "port%c[0x%04x] = 0x%0*x\n",
397+
suffix, addr, size * 2, val);
398+
}
399+
400+
void hmp_ioport_write(Monitor *mon, const QDict *qdict)
401+
{
402+
int size = qdict_get_int(qdict, "size");
403+
int addr = qdict_get_int(qdict, "addr");
404+
int val = qdict_get_int(qdict, "val");
405+
406+
addr &= IOPORTS_MASK;
407+
408+
switch (size) {
409+
default:
410+
case 1:
411+
cpu_outb(addr, val);
412+
break;
413+
case 2:
414+
cpu_outw(addr, val);
415+
break;
416+
case 4:
417+
cpu_outl(addr, val);
418+
break;
419+
}
420+
}
421+
422+
void hmp_boot_set(Monitor *mon, const QDict *qdict)
423+
{
424+
Error *local_err = NULL;
425+
const char *bootdevice = qdict_get_str(qdict, "bootdevice");
426+
427+
qemu_boot_set(bootdevice, &local_err);
428+
if (local_err) {
429+
error_report_err(local_err);
430+
} else {
431+
monitor_printf(mon, "boot device list now set to %s\n", bootdevice);
432+
}
433+
}
434+
435+
void hmp_info_mtree(Monitor *mon, const QDict *qdict)
436+
{
437+
bool flatview = qdict_get_try_bool(qdict, "flatview", false);
438+
bool dispatch_tree = qdict_get_try_bool(qdict, "dispatch_tree", false);
439+
bool owner = qdict_get_try_bool(qdict, "owner", false);
440+
bool disabled = qdict_get_try_bool(qdict, "disabled", false);
441+
442+
mtree_info(flatview, dispatch_tree, owner, disabled);
443+
}

0 commit comments

Comments
 (0)