Revision 5fafdf24 monitor.c
b/monitor.c | ||
---|---|---|
1 | 1 |
/* |
2 | 2 |
* QEMU monitor |
3 |
*
|
|
3 |
* |
|
4 | 4 |
* Copyright (c) 2003-2004 Fabrice Bellard |
5 |
*
|
|
5 |
* |
|
6 | 6 |
* Permission is hereby granted, free of charge, to any person obtaining a copy |
7 | 7 |
* of this software and associated documentation files (the "Software"), to deal |
8 | 8 |
* in the Software without restriction, including without limitation the rights |
... | ... | |
34 | 34 |
|
35 | 35 |
/* |
36 | 36 |
* Supported types: |
37 |
*
|
|
37 |
* |
|
38 | 38 |
* 'F' filename |
39 | 39 |
* 'B' block device name |
40 | 40 |
* 's' string (accept optional quote) |
... | ... | |
206 | 206 |
all_devices = !strcmp(device, "all"); |
207 | 207 |
for (i = 0; i < MAX_DISKS; i++) { |
208 | 208 |
if (bs_table[i]) { |
209 |
if (all_devices ||
|
|
209 |
if (all_devices || |
|
210 | 210 |
!strcmp(bdrv_get_device_name(bs_table[i]), device)) |
211 | 211 |
bdrv_commit(bs_table[i]); |
212 | 212 |
} |
... | ... | |
223 | 223 |
if (!item) |
224 | 224 |
goto help; |
225 | 225 |
for(cmd = info_cmds; cmd->name != NULL; cmd++) { |
226 |
if (compare_cmd(item, cmd->name))
|
|
226 |
if (compare_cmd(item, cmd->name)) |
|
227 | 227 |
goto found; |
228 | 228 |
} |
229 | 229 |
help: |
... | ... | |
281 | 281 |
cpu_dump_state(env, NULL, monitor_fprintf, |
282 | 282 |
X86_DUMP_FPU); |
283 | 283 |
#else |
284 |
cpu_dump_state(env, NULL, monitor_fprintf,
|
|
284 |
cpu_dump_state(env, NULL, monitor_fprintf, |
|
285 | 285 |
0); |
286 | 286 |
#endif |
287 | 287 |
} |
... | ... | |
294 | 294 |
mon_get_cpu(); |
295 | 295 |
|
296 | 296 |
for(env = first_cpu; env != NULL; env = env->next_cpu) { |
297 |
term_printf("%c CPU #%d:",
|
|
297 |
term_printf("%c CPU #%d:", |
|
298 | 298 |
(env == mon_cpu) ? '*' : ' ', |
299 | 299 |
env->cpu_index); |
300 | 300 |
#if defined(TARGET_I386) |
... | ... | |
333 | 333 |
{ |
334 | 334 |
int i; |
335 | 335 |
const char *str; |
336 |
|
|
336 |
|
|
337 | 337 |
i = 0; |
338 | 338 |
for(;;) { |
339 | 339 |
str = readline_get_history(i); |
... | ... | |
442 | 442 |
static void do_log(const char *items) |
443 | 443 |
{ |
444 | 444 |
int mask; |
445 |
|
|
445 |
|
|
446 | 446 |
if (!strcmp(items, "none")) { |
447 | 447 |
mask = 0; |
448 | 448 |
} else { |
... | ... | |
505 | 505 |
term_printf("'"); |
506 | 506 |
} |
507 | 507 |
|
508 |
static void memory_dump(int count, int format, int wsize,
|
|
508 |
static void memory_dump(int count, int format, int wsize, |
|
509 | 509 |
target_ulong addr, int is_physical) |
510 | 510 |
{ |
511 | 511 |
CPUState *env; |
... | ... | |
529 | 529 |
flags = 0; |
530 | 530 |
if (env) { |
531 | 531 |
#ifdef TARGET_X86_64 |
532 |
if ((env->efer & MSR_EFER_LMA) &&
|
|
532 |
if ((env->efer & MSR_EFER_LMA) && |
|
533 | 533 |
(env->segs[R_CS].flags & DESC_L_MASK)) |
534 | 534 |
flags = 2; |
535 | 535 |
else |
... | ... | |
581 | 581 |
break; |
582 | 582 |
cpu_memory_rw_debug(env, addr, buf, l, 0); |
583 | 583 |
} |
584 |
i = 0;
|
|
584 |
i = 0; |
|
585 | 585 |
while (i < l) { |
586 | 586 |
switch(wsize) { |
587 | 587 |
default: |
... | ... | |
630 | 630 |
#define GET_TLONG(h, l) (l) |
631 | 631 |
#endif |
632 | 632 |
|
633 |
static void do_memory_dump(int count, int format, int size,
|
|
633 |
static void do_memory_dump(int count, int format, int size, |
|
634 | 634 |
uint32_t addrh, uint32_t addrl) |
635 | 635 |
{ |
636 | 636 |
target_long addr = GET_TLONG(addrh, addrl); |
... | ... | |
690 | 690 |
term_printf("\n"); |
691 | 691 |
} |
692 | 692 |
|
693 |
static void do_memory_save(unsigned int valh, unsigned int vall,
|
|
693 |
static void do_memory_save(unsigned int valh, unsigned int vall, |
|
694 | 694 |
uint32_t size, const char *filename) |
695 | 695 |
{ |
696 | 696 |
FILE *f; |
... | ... | |
744 | 744 |
static const KeyDef key_defs[] = { |
745 | 745 |
{ 0x2a, "shift" }, |
746 | 746 |
{ 0x36, "shift_r" }, |
747 |
|
|
747 |
|
|
748 | 748 |
{ 0x38, "alt" }, |
749 | 749 |
{ 0xb8, "alt_r" }, |
750 | 750 |
{ 0x1d, "ctrl" }, |
... | ... | |
799 | 799 |
{ 0x30, "b" }, |
800 | 800 |
{ 0x31, "n" }, |
801 | 801 |
{ 0x32, "m" }, |
802 |
|
|
802 |
|
|
803 | 803 |
{ 0x39, "spc" }, |
804 | 804 |
{ 0x3a, "caps_lock" }, |
805 | 805 |
{ 0x3b, "f1" }, |
... | ... | |
832 | 832 |
{ 0x47, "kp_7" }, |
833 | 833 |
{ 0x48, "kp_8" }, |
834 | 834 |
{ 0x49, "kp_9" }, |
835 |
|
|
835 |
|
|
836 | 836 |
{ 0x56, "<" }, |
837 | 837 |
|
838 | 838 |
{ 0x57, "f11" }, |
... | ... | |
879 | 879 |
uint8_t keycodes[16]; |
880 | 880 |
const char *p; |
881 | 881 |
int nb_keycodes, keycode, i; |
882 |
|
|
882 |
|
|
883 | 883 |
nb_keycodes = 0; |
884 | 884 |
p = string; |
885 | 885 |
while (*p != '\0') { |
... | ... | |
919 | 919 |
|
920 | 920 |
static int mouse_button_state; |
921 | 921 |
|
922 |
static void do_mouse_move(const char *dx_str, const char *dy_str,
|
|
922 |
static void do_mouse_move(const char *dx_str, const char *dy_str, |
|
923 | 923 |
const char *dz_str) |
924 | 924 |
{ |
925 | 925 |
int dx, dy, dz; |
926 | 926 |
dx = strtol(dx_str, NULL, 0); |
927 | 927 |
dy = strtol(dy_str, NULL, 0); |
928 | 928 |
dz = 0; |
929 |
if (dz_str)
|
|
929 |
if (dz_str) |
|
930 | 930 |
dz = strtol(dz_str, NULL, 0); |
931 | 931 |
kbd_mouse_event(dx, dy, dz, mouse_button_state); |
932 | 932 |
} |
... | ... | |
980 | 980 |
#if defined(TARGET_I386) |
981 | 981 |
static void print_pte(uint32_t addr, uint32_t pte, uint32_t mask) |
982 | 982 |
{ |
983 |
term_printf("%08x: %08x %c%c%c%c%c%c%c%c\n",
|
|
983 |
term_printf("%08x: %08x %c%c%c%c%c%c%c%c\n", |
|
984 | 984 |
addr, |
985 | 985 |
pte & mask, |
986 | 986 |
pte & PG_GLOBAL_MASK ? 'G' : '-', |
... | ... | |
1016 | 1016 |
print_pte((l1 << 22), pde, ~((1 << 20) - 1)); |
1017 | 1017 |
} else { |
1018 | 1018 |
for(l2 = 0; l2 < 1024; l2++) { |
1019 |
cpu_physical_memory_read((pde & ~0xfff) + l2 * 4,
|
|
1019 |
cpu_physical_memory_read((pde & ~0xfff) + l2 * 4, |
|
1020 | 1020 |
(uint8_t *)&pte, 4); |
1021 | 1021 |
pte = le32_to_cpu(pte); |
1022 | 1022 |
if (pte & PG_PRESENT_MASK) { |
1023 |
print_pte((l1 << 22) + (l2 << 12),
|
|
1024 |
pte & ~PG_PSE_MASK,
|
|
1023 |
print_pte((l1 << 22) + (l2 << 12), |
|
1024 |
pte & ~PG_PSE_MASK, |
|
1025 | 1025 |
~0xfff); |
1026 | 1026 |
} |
1027 | 1027 |
} |
... | ... | |
1030 | 1030 |
} |
1031 | 1031 |
} |
1032 | 1032 |
|
1033 |
static void mem_print(uint32_t *pstart, int *plast_prot,
|
|
1033 |
static void mem_print(uint32_t *pstart, int *plast_prot, |
|
1034 | 1034 |
uint32_t end, int prot) |
1035 | 1035 |
{ |
1036 | 1036 |
int prot1; |
... | ... | |
1038 | 1038 |
if (prot != prot1) { |
1039 | 1039 |
if (*pstart != -1) { |
1040 | 1040 |
term_printf("%08x-%08x %08x %c%c%c\n", |
1041 |
*pstart, end, end - *pstart,
|
|
1041 |
*pstart, end, end - *pstart, |
|
1042 | 1042 |
prot1 & PG_USER_MASK ? 'u' : '-', |
1043 | 1043 |
'r', |
1044 | 1044 |
prot1 & PG_RW_MASK ? 'w' : '-'); |
... | ... | |
1078 | 1078 |
mem_print(&start, &last_prot, end, prot); |
1079 | 1079 |
} else { |
1080 | 1080 |
for(l2 = 0; l2 < 1024; l2++) { |
1081 |
cpu_physical_memory_read((pde & ~0xfff) + l2 * 4,
|
|
1081 |
cpu_physical_memory_read((pde & ~0xfff) + l2 * 4, |
|
1082 | 1082 |
(uint8_t *)&pte, 4); |
1083 | 1083 |
pte = le32_to_cpu(pte); |
1084 | 1084 |
end = (l1 << 22) + (l2 << 12); |
... | ... | |
1126 | 1126 |
#else |
1127 | 1127 |
term_printf("kqemu support: not compiled\n"); |
1128 | 1128 |
#endif |
1129 |
}
|
|
1129 |
} |
|
1130 | 1130 |
|
1131 | 1131 |
#ifdef CONFIG_PROFILER |
1132 | 1132 |
|
... | ... | |
1232 | 1232 |
#endif |
1233 | 1233 |
|
1234 | 1234 |
static term_cmd_t term_cmds[] = { |
1235 |
{ "help|?", "s?", do_help,
|
|
1235 |
{ "help|?", "s?", do_help, |
|
1236 | 1236 |
"[cmd]", "show the help" }, |
1237 |
{ "commit", "s", do_commit,
|
|
1237 |
{ "commit", "s", do_commit, |
|
1238 | 1238 |
"device|all", "commit changes to the disk images (if -snapshot is used) or backing files" }, |
1239 | 1239 |
{ "info", "s?", do_info, |
1240 | 1240 |
"subcommand", "show various information about the system state" }, |
... | ... | |
1244 | 1244 |
"[-f] device", "eject a removable medium (use -f to force it)" }, |
1245 | 1245 |
{ "change", "BF", do_change, |
1246 | 1246 |
"device filename", "change a removable medium" }, |
1247 |
{ "screendump", "F", do_screen_dump,
|
|
1247 |
{ "screendump", "F", do_screen_dump, |
|
1248 | 1248 |
"filename", "save screen into PPM image 'filename'" }, |
1249 | 1249 |
{ "logfile", "s", do_logfile, |
1250 | 1250 |
"filename", "output logs to 'filename'" }, |
1251 | 1251 |
{ "log", "s", do_log, |
1252 |
"item1[,...]", "activate logging of the specified items to '/tmp/qemu.log'" },
|
|
1252 |
"item1[,...]", "activate logging of the specified items to '/tmp/qemu.log'" }, |
|
1253 | 1253 |
{ "savevm", "s?", do_savevm, |
1254 |
"tag|id", "save a VM snapshot. If no tag or id are provided, a new snapshot is created" },
|
|
1254 |
"tag|id", "save a VM snapshot. If no tag or id are provided, a new snapshot is created" }, |
|
1255 | 1255 |
{ "loadvm", "s", do_loadvm, |
1256 |
"tag|id", "restore a VM snapshot from its tag or id" },
|
|
1256 |
"tag|id", "restore a VM snapshot from its tag or id" }, |
|
1257 | 1257 |
{ "delvm", "s", do_delvm, |
1258 |
"tag|id", "delete a VM snapshot from its tag or id" },
|
|
1259 |
{ "stop", "", do_stop,
|
|
1258 |
"tag|id", "delete a VM snapshot from its tag or id" }, |
|
1259 |
{ "stop", "", do_stop, |
|
1260 | 1260 |
"", "stop emulation", }, |
1261 |
{ "c|cont", "", do_cont,
|
|
1261 |
{ "c|cont", "", do_cont, |
|
1262 | 1262 |
"", "resume emulation", }, |
1263 | 1263 |
#ifdef CONFIG_GDBSTUB |
1264 |
{ "gdbserver", "s?", do_gdbserver,
|
|
1264 |
{ "gdbserver", "s?", do_gdbserver, |
|
1265 | 1265 |
"[port]", "start gdbserver session (default port=1234)", }, |
1266 | 1266 |
#endif |
1267 |
{ "x", "/l", do_memory_dump,
|
|
1267 |
{ "x", "/l", do_memory_dump, |
|
1268 | 1268 |
"/fmt addr", "virtual memory dump starting at 'addr'", }, |
1269 |
{ "xp", "/l", do_physical_memory_dump,
|
|
1269 |
{ "xp", "/l", do_physical_memory_dump, |
|
1270 | 1270 |
"/fmt addr", "physical memory dump starting at 'addr'", }, |
1271 |
{ "p|print", "/l", do_print,
|
|
1271 |
{ "p|print", "/l", do_print, |
|
1272 | 1272 |
"/fmt expr", "print expression value (use $reg for CPU register access)", }, |
1273 |
{ "i", "/ii.", do_ioport_read,
|
|
1273 |
{ "i", "/ii.", do_ioport_read, |
|
1274 | 1274 |
"/fmt addr", "I/O port read" }, |
1275 | 1275 |
|
1276 |
{ "sendkey", "s", do_send_key,
|
|
1276 |
{ "sendkey", "s", do_send_key, |
|
1277 | 1277 |
"keys", "send keys to the VM (e.g. 'sendkey ctrl-alt-f1')" }, |
1278 |
{ "system_reset", "", do_system_reset,
|
|
1278 |
{ "system_reset", "", do_system_reset, |
|
1279 | 1279 |
"", "reset the system" }, |
1280 |
{ "system_powerdown", "", do_system_powerdown,
|
|
1280 |
{ "system_powerdown", "", do_system_powerdown, |
|
1281 | 1281 |
"", "send system power down event" }, |
1282 |
{ "sum", "ii", do_sum,
|
|
1282 |
{ "sum", "ii", do_sum, |
|
1283 | 1283 |
"addr size", "compute the checksum of a memory region" }, |
1284 | 1284 |
{ "usb_add", "s", do_usb_add, |
1285 | 1285 |
"device", "add USB device (e.g. 'host:bus.addr' or 'host:vendor_id:product_id')" }, |
1286 | 1286 |
{ "usb_del", "s", do_usb_del, |
1287 | 1287 |
"device", "remove USB device 'bus.addr'" }, |
1288 |
{ "cpu", "i", do_cpu_set,
|
|
1288 |
{ "cpu", "i", do_cpu_set, |
|
1289 | 1289 |
"index", "set the default CPU" }, |
1290 |
{ "mouse_move", "sss?", do_mouse_move,
|
|
1290 |
{ "mouse_move", "sss?", do_mouse_move, |
|
1291 | 1291 |
"dx dy [dz]", "send mouse move events" }, |
1292 |
{ "mouse_button", "i", do_mouse_button,
|
|
1292 |
{ "mouse_button", "i", do_mouse_button, |
|
1293 | 1293 |
"state", "change mouse button state (1=L, 2=M, 4=R)" }, |
1294 | 1294 |
{ "mouse_set", "i", do_mouse_set, |
1295 | 1295 |
"index", "set which mouse device receives events" }, |
... | ... | |
1300 | 1300 |
#endif |
1301 | 1301 |
{ "stopcapture", "i", do_stop_capture, |
1302 | 1302 |
"capture index", "stop capture" }, |
1303 |
{ "memsave", "lis", do_memory_save,
|
|
1303 |
{ "memsave", "lis", do_memory_save, |
|
1304 | 1304 |
"addr size file", "save to disk virtual memory dump starting at 'addr' of size 'size'", }, |
1305 |
{ NULL, NULL, },
|
|
1305 |
{ NULL, NULL, }, |
|
1306 | 1306 |
}; |
1307 | 1307 |
|
1308 | 1308 |
static term_cmd_t info_cmds[] = { |
... | ... | |
1678 | 1678 |
{ NULL }, |
1679 | 1679 |
}; |
1680 | 1680 |
|
1681 |
static void expr_error(const char *fmt)
|
|
1681 |
static void expr_error(const char *fmt) |
|
1682 | 1682 |
{ |
1683 | 1683 |
term_printf(fmt); |
1684 | 1684 |
term_printf("\n"); |
... | ... | |
1769 | 1769 |
case '$': |
1770 | 1770 |
{ |
1771 | 1771 |
char buf[128], *q; |
1772 |
|
|
1772 |
|
|
1773 | 1773 |
pch++; |
1774 | 1774 |
q = buf; |
1775 | 1775 |
while ((*pch >= 'a' && *pch <= 'z') || |
... | ... | |
1786 | 1786 |
ret = get_monitor_def(&n, buf); |
1787 | 1787 |
if (ret == -1) |
1788 | 1788 |
expr_error("unknown register"); |
1789 |
else if (ret == -2)
|
|
1789 |
else if (ret == -2) |
|
1790 | 1790 |
expr_error("no cpu defined"); |
1791 | 1791 |
} |
1792 | 1792 |
break; |
... | ... | |
1816 | 1816 |
{ |
1817 | 1817 |
target_long val, val2; |
1818 | 1818 |
int op; |
1819 |
|
|
1819 |
|
|
1820 | 1820 |
val = expr_unary(); |
1821 | 1821 |
for(;;) { |
1822 | 1822 |
op = *pch; |
... | ... | |
1831 | 1831 |
break; |
1832 | 1832 |
case '/': |
1833 | 1833 |
case '%': |
1834 |
if (val2 == 0)
|
|
1834 |
if (val2 == 0) |
|
1835 | 1835 |
expr_error("division by zero"); |
1836 | 1836 |
if (op == '/') |
1837 | 1837 |
val /= val2; |
... | ... | |
1989 | 1989 |
#ifdef DEBUG |
1990 | 1990 |
term_printf("command='%s'\n", cmdline); |
1991 | 1991 |
#endif |
1992 |
|
|
1992 |
|
|
1993 | 1993 |
/* extract the command name */ |
1994 | 1994 |
p = cmdline; |
1995 | 1995 |
q = cmdname; |
... | ... | |
2005 | 2005 |
len = sizeof(cmdname) - 1; |
2006 | 2006 |
memcpy(cmdname, pstart, len); |
2007 | 2007 |
cmdname[len] = '\0'; |
2008 |
|
|
2008 |
|
|
2009 | 2009 |
/* find the command */ |
2010 | 2010 |
for(cmd = term_cmds; cmd->name != NULL; cmd++) { |
2011 |
if (compare_cmd(cmdname, cmd->name))
|
|
2011 |
if (compare_cmd(cmdname, cmd->name)) |
|
2012 | 2012 |
goto found; |
2013 | 2013 |
} |
2014 | 2014 |
term_printf("unknown command: '%s'\n", cmdname); |
... | ... | |
2017 | 2017 |
|
2018 | 2018 |
for(i = 0; i < MAX_ARGS; i++) |
2019 | 2019 |
str_allocated[i] = NULL; |
2020 |
|
|
2020 |
|
|
2021 | 2021 |
/* parse the parameters */ |
2022 | 2022 |
typestr = cmd->args_type; |
2023 | 2023 |
nb_args = 0; |
... | ... | |
2033 | 2033 |
{ |
2034 | 2034 |
int ret; |
2035 | 2035 |
char *str; |
2036 |
|
|
2037 |
while (isspace(*p))
|
|
2036 |
|
|
2037 |
while (isspace(*p)) |
|
2038 | 2038 |
p++; |
2039 | 2039 |
if (*typestr == '?') { |
2040 | 2040 |
typestr++; |
... | ... | |
2074 | 2074 |
case '/': |
2075 | 2075 |
{ |
2076 | 2076 |
int count, format, size; |
2077 |
|
|
2077 |
|
|
2078 | 2078 |
while (isspace(*p)) |
2079 | 2079 |
p++; |
2080 | 2080 |
if (*p == '/') { |
... | ... | |
2155 | 2155 |
case 'l': |
2156 | 2156 |
{ |
2157 | 2157 |
target_long val; |
2158 |
while (isspace(*p))
|
|
2158 |
while (isspace(*p)) |
|
2159 | 2159 |
p++; |
2160 | 2160 |
if (*typestr == '?' || *typestr == '.') { |
2161 | 2161 |
if (*typestr == '?') { |
... | ... | |
2166 | 2166 |
} else { |
2167 | 2167 |
if (*p == '.') { |
2168 | 2168 |
p++; |
2169 |
while (isspace(*p))
|
|
2169 |
while (isspace(*p)) |
|
2170 | 2170 |
p++; |
2171 | 2171 |
has_arg = 1; |
2172 | 2172 |
} else { |
... | ... | |
2207 | 2207 |
{ |
2208 | 2208 |
int has_option; |
2209 | 2209 |
/* option */ |
2210 |
|
|
2210 |
|
|
2211 | 2211 |
c = *typestr++; |
2212 | 2212 |
if (c == '\0') |
2213 | 2213 |
goto bad_type; |
2214 |
while (isspace(*p))
|
|
2214 |
while (isspace(*p)) |
|
2215 | 2215 |
p++; |
2216 | 2216 |
has_option = 0; |
2217 | 2217 |
if (*p == '-') { |
2218 | 2218 |
p++; |
2219 | 2219 |
if (*p != c) { |
2220 |
term_printf("%s: unsupported option -%c\n",
|
|
2220 |
term_printf("%s: unsupported option -%c\n", |
|
2221 | 2221 |
cmdname, *p); |
2222 | 2222 |
goto fail; |
2223 | 2223 |
} |
... | ... | |
2239 | 2239 |
while (isspace(*p)) |
2240 | 2240 |
p++; |
2241 | 2241 |
if (*p != '\0') { |
2242 |
term_printf("%s: extraneous characters at the end of line\n",
|
|
2242 |
term_printf("%s: extraneous characters at the end of line\n", |
|
2243 | 2243 |
cmdname); |
2244 | 2244 |
goto fail; |
2245 | 2245 |
} |
... | ... | |
2314 | 2314 |
int input_path_len; |
2315 | 2315 |
const char *p; |
2316 | 2316 |
|
2317 |
p = strrchr(input, '/');
|
|
2317 |
p = strrchr(input, '/'); |
|
2318 | 2318 |
if (!p) { |
2319 | 2319 |
input_path_len = 0; |
2320 | 2320 |
pstrcpy(file_prefix, sizeof(file_prefix), input); |
Also available in: Unified diff