Skip to content

Commit

Permalink
monitor: Move remaining HMP commands from misc.c to hmp-cmds.c
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
Markus Armbruster committed Feb 4, 2023
1 parent e224556 commit cbf8199
Show file tree
Hide file tree
Showing 4 changed files with 233 additions and 221 deletions.
4 changes: 2 additions & 2 deletions hmp-commands.hx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ HXCOMM HXCOMM can be used for comments, discarded from both rST and C.
.args_type = "name:S?",
.params = "[cmd]",
.help = "show the help",
.cmd = do_help_cmd,
.cmd = hmp_help,
.flags = "p",
},

Expand Down Expand Up @@ -563,7 +563,7 @@ ERST
.args_type = "fmt:/,val:l",
.params = "/fmt expr",
.help = "print expression value (use $reg for CPU register access)",
.cmd = do_print,
.cmd = hmp_print,
},

SRST
Expand Down
13 changes: 13 additions & 0 deletions include/monitor/hmp.h
Original file line number Diff line number Diff line change
Expand Up @@ -165,5 +165,18 @@ void hmp_wavcapture(Monitor *mon, const QDict *qdict);
void hmp_trace_event(Monitor *mon, const QDict *qdict);
void hmp_trace_file(Monitor *mon, const QDict *qdict);
void hmp_info_trace_events(Monitor *mon, const QDict *qdict);
void hmp_help(Monitor *mon, const QDict *qdict);
void hmp_info_help(Monitor *mon, const QDict *qdict);
void hmp_info_sync_profile(Monitor *mon, const QDict *qdict);
void hmp_info_history(Monitor *mon, const QDict *qdict);
void hmp_logfile(Monitor *mon, const QDict *qdict);
void hmp_log(Monitor *mon, const QDict *qdict);
void hmp_gdbserver(Monitor *mon, const QDict *qdict);
void hmp_print(Monitor *mon, const QDict *qdict);
void hmp_sum(Monitor *mon, const QDict *qdict);
void hmp_ioport_read(Monitor *mon, const QDict *qdict);
void hmp_ioport_write(Monitor *mon, const QDict *qdict);
void hmp_boot_set(Monitor *mon, const QDict *qdict);
void hmp_info_mtree(Monitor *mon, const QDict *qdict);

#endif
219 changes: 218 additions & 1 deletion monitor/hmp-cmds.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,21 @@
*/

#include "qemu/osdep.h"
#include "exec/address-spaces.h"
#include "exec/gdbstub.h"
#include "exec/ioport.h"
#include "monitor/hmp.h"
#include "qemu/help_option.h"
#include "monitor/monitor.h"
#include "monitor/monitor-internal.h"
#include "qapi/error.h"
#include "qapi/qapi-commands-control.h"
#include "qapi/qapi-commands-misc.h"
#include "qapi/qmp/qdict.h"
#include "qapi/qmp/qerror.h"
#include "qemu/cutils.h"
#include "hw/intc/intc.h"
#include "qemu/log.h"
#include "sysemu/sysemu.h"

bool hmp_handle_error(Monitor *mon, Error *err)
{
Expand Down Expand Up @@ -224,3 +229,215 @@ void hmp_info_iothreads(Monitor *mon, const QDict *qdict)

qapi_free_IOThreadInfoList(info_list);
}

void hmp_help(Monitor *mon, const QDict *qdict)
{
hmp_help_cmd(mon, qdict_get_try_str(qdict, "name"));
}

void hmp_info_help(Monitor *mon, const QDict *qdict)
{
hmp_help_cmd(mon, "info");
}

void hmp_info_sync_profile(Monitor *mon, const QDict *qdict)
{
int64_t max = qdict_get_try_int(qdict, "max", 10);
bool mean = qdict_get_try_bool(qdict, "mean", false);
bool coalesce = !qdict_get_try_bool(qdict, "no_coalesce", false);
enum QSPSortBy sort_by;

sort_by = mean ? QSP_SORT_BY_AVG_WAIT_TIME : QSP_SORT_BY_TOTAL_WAIT_TIME;
qsp_report(max, sort_by, coalesce);
}

void hmp_info_history(Monitor *mon, const QDict *qdict)
{
MonitorHMP *hmp_mon = container_of(mon, MonitorHMP, common);
int i;
const char *str;

if (!hmp_mon->rs) {
return;
}
i = 0;
for(;;) {
str = readline_get_history(hmp_mon->rs, i);
if (!str) {
break;
}
monitor_printf(mon, "%d: '%s'\n", i, str);
i++;
}
}

void hmp_logfile(Monitor *mon, const QDict *qdict)
{
Error *err = NULL;

if (!qemu_set_log_filename(qdict_get_str(qdict, "filename"), &err)) {
error_report_err(err);
}
}

void hmp_log(Monitor *mon, const QDict *qdict)
{
int mask;
const char *items = qdict_get_str(qdict, "items");
Error *err = NULL;

if (!strcmp(items, "none")) {
mask = 0;
} else {
mask = qemu_str_to_log_mask(items);
if (!mask) {
hmp_help_cmd(mon, "log");
return;
}
}

if (!qemu_set_log(mask, &err)) {
error_report_err(err);
}
}

void hmp_gdbserver(Monitor *mon, const QDict *qdict)
{
const char *device = qdict_get_try_str(qdict, "device");
if (!device) {
device = "tcp::" DEFAULT_GDBSTUB_PORT;
}

if (gdbserver_start(device) < 0) {
monitor_printf(mon, "Could not open gdbserver on device '%s'\n",
device);
} else if (strcmp(device, "none") == 0) {
monitor_printf(mon, "Disabled gdbserver\n");
} else {
monitor_printf(mon, "Waiting for gdb connection on device '%s'\n",
device);
}
}

void hmp_print(Monitor *mon, const QDict *qdict)
{
int format = qdict_get_int(qdict, "format");
hwaddr val = qdict_get_int(qdict, "val");

switch(format) {
case 'o':
monitor_printf(mon, "%#" HWADDR_PRIo, val);
break;
case 'x':
monitor_printf(mon, "%#" HWADDR_PRIx, val);
break;
case 'u':
monitor_printf(mon, "%" HWADDR_PRIu, val);
break;
default:
case 'd':
monitor_printf(mon, "%" HWADDR_PRId, val);
break;
case 'c':
monitor_printc(mon, val);
break;
}
monitor_printf(mon, "\n");
}

void hmp_sum(Monitor *mon, const QDict *qdict)
{
uint32_t addr;
uint16_t sum;
uint32_t start = qdict_get_int(qdict, "start");
uint32_t size = qdict_get_int(qdict, "size");

sum = 0;
for(addr = start; addr < (start + size); addr++) {
uint8_t val = address_space_ldub(&address_space_memory, addr,
MEMTXATTRS_UNSPECIFIED, NULL);
/* BSD sum algorithm ('sum' Unix command) */
sum = (sum >> 1) | (sum << 15);
sum += val;
}
monitor_printf(mon, "%05d\n", sum);
}

void hmp_ioport_read(Monitor *mon, const QDict *qdict)
{
int size = qdict_get_int(qdict, "size");
int addr = qdict_get_int(qdict, "addr");
int has_index = qdict_haskey(qdict, "index");
uint32_t val;
int suffix;

if (has_index) {
int index = qdict_get_int(qdict, "index");
cpu_outb(addr & IOPORTS_MASK, index & 0xff);
addr++;
}
addr &= 0xffff;

switch(size) {
default:
case 1:
val = cpu_inb(addr);
suffix = 'b';
break;
case 2:
val = cpu_inw(addr);
suffix = 'w';
break;
case 4:
val = cpu_inl(addr);
suffix = 'l';
break;
}
monitor_printf(mon, "port%c[0x%04x] = 0x%0*x\n",
suffix, addr, size * 2, val);
}

void hmp_ioport_write(Monitor *mon, const QDict *qdict)
{
int size = qdict_get_int(qdict, "size");
int addr = qdict_get_int(qdict, "addr");
int val = qdict_get_int(qdict, "val");

addr &= IOPORTS_MASK;

switch (size) {
default:
case 1:
cpu_outb(addr, val);
break;
case 2:
cpu_outw(addr, val);
break;
case 4:
cpu_outl(addr, val);
break;
}
}

void hmp_boot_set(Monitor *mon, const QDict *qdict)
{
Error *local_err = NULL;
const char *bootdevice = qdict_get_str(qdict, "bootdevice");

qemu_boot_set(bootdevice, &local_err);
if (local_err) {
error_report_err(local_err);
} else {
monitor_printf(mon, "boot device list now set to %s\n", bootdevice);
}
}

void hmp_info_mtree(Monitor *mon, const QDict *qdict)
{
bool flatview = qdict_get_try_bool(qdict, "flatview", false);
bool dispatch_tree = qdict_get_try_bool(qdict, "dispatch_tree", false);
bool owner = qdict_get_try_bool(qdict, "owner", false);
bool disabled = qdict_get_try_bool(qdict, "disabled", false);

mtree_info(flatview, dispatch_tree, owner, disabled);
}
Loading

0 comments on commit cbf8199

Please sign in to comment.