35 static void debugger_cmd_allsettings(
struct machine *m,
char *cmd_line)
46 static void debugger_cmd_breakpoint(
struct machine *m,
char *cmd_line)
50 while (cmd_line[0] !=
'\0' && cmd_line[0] ==
' ')
53 if (cmd_line[0] ==
'\0') {
54 printf(
"syntax: breakpoint subcmd [args...]\n");
55 printf(
"Available subcmds (and args) are:\n");
56 printf(
" add addr add a breakpoint for address addr\n");
57 printf(
" delete x delete breakpoint nr x\n");
58 printf(
" show show current breakpoints\n");
62 if (strcmp(cmd_line,
"show") == 0) {
64 printf(
"No breakpoints set.\n");
66 show_breakpoint(m, i);
70 if (strncmp(cmd_line,
"delete ", 7) == 0) {
71 int x = atoi(cmd_line + 7);
74 printf(
"No breakpoints set.\n");
78 printf(
"Invalid breakpoint nr %i. Use 'breakpoint " 79 "show' to see the current breakpoints.\n", x);
92 for (i=0; i<m->
ncpus; i++)
98 if (strncmp(cmd_line,
"add ", 4) == 0) {
100 size_t breakpoint_buf_len;
106 printf(
"Couldn't parse '%s'\n", cmd_line + 4);
117 breakpoint_buf_len =
strlen(cmd_line+4) + 1;
120 malloc(breakpoint_buf_len));
126 show_breakpoint(m, i);
129 for (i=0; i<m->
ncpus; i++)
135 printf(
"Unknown breakpoint subcommand.\n");
142 static void debugger_cmd_continue(
struct machine *m,
char *cmd_line)
145 printf(
"syntax: continue\n");
156 static void debugger_cmd_device(
struct machine *m,
char *cmd_line)
162 if (cmd_line[0] ==
'\0')
165 if (m->
cpus == NULL) {
166 printf(
"No cpus (?)\n");
171 printf(
"m->cpus[m->bootstrap_cpu] = NULL\n");
176 if (m->
cpus == NULL) {
177 printf(
"No cpus (?)\n");
182 printf(
"m->cpus[m->bootstrap_cpu] = NULL\n");
187 if (strcmp(cmd_line,
"all") == 0) {
189 }
else if (strncmp(cmd_line,
"add ", 4) == 0) {
191 }
else if (strcmp(cmd_line,
"consoles") == 0) {
193 }
else if (strncmp(cmd_line,
"remove ", 7) == 0) {
194 i = atoi(cmd_line + 7);
195 if (i==0 && cmd_line[7]!=
'0') {
196 printf(
"Weird device number. Use 'device list'.\n");
199 }
else if (strcmp(cmd_line,
"list") == 0) {
201 printf(
"No memory-mapped devices in this machine.\n");
204 printf(
"%2i: %25s @ 0x%011" PRIx64
", len = 0x%" PRIx64,
212 printf(
"DYNTRANS R");
225 printf(
"syntax: devices cmd [...]\n");
226 printf(
"Available cmds are:\n");
227 printf(
" add name_and_params add a device to the current " 229 printf(
" all list all registered devices\n");
230 printf(
" consoles list all slave consoles\n");
231 printf(
" list list memory-mapped devices in the" 232 " current machine\n");
233 printf(
" remove x remove device nr x from the " 234 "current machine\n");
245 static void debugger_cmd_dump(
struct machine *m,
char *cmd_line)
247 uint64_t
addr, addr_start, addr_end;
253 if (cmd_line[0] !=
'\0') {
260 p = strchr(tmps,
' ');
267 printf(
"Unparsable address: %s\n", cmd_line);
270 last_dump_addr = tmp;
273 p = strchr(cmd_line,
' ');
276 if (m->
cpus == NULL) {
277 printf(
"No cpus (?)\n");
282 printf(
"m->cpus[m->bootstrap_cpu] = NULL\n");
287 addr_start = last_dump_addr;
292 addr_end = addr_start + 16 * 16;
296 while (*p ==
' ' && *p)
300 printf(
"Unparsable address: %s\n", cmd_line);
305 addr = addr_start & ~0xf;
309 while (addr < addr_end) {
310 unsigned char buf[16];
311 memset(buf, 0,
sizeof(buf));
312 r = c->
memory_rw(c, mem, addr, &buf[0],
sizeof(buf),
316 printf(
"0x%08" PRIx32
" ", (uint32_t) addr);
318 printf(
"0x%016" PRIx64
" ", (uint64_t) addr);
321 printf(
"(memory access failed)\n");
323 for (x=0; x<16; x++) {
324 if (addr + x >= addr_start &&
326 printf(
"%02x%s", buf[x],
329 printf(
" %s", (x&3)==3?
" " :
"");
332 for (x=0; x<16; x++) {
333 if (addr + x >= addr_start &&
335 printf(
"%c", (buf[x]>=
' ' &&
336 buf[x]<127)? buf[x] :
'.');
349 last_dump_addr = addr_end;
360 static void debugger_cmd_emul(
struct machine *m,
char *cmd_line)
365 printf(
"syntax: emul\n");
369 debug(
"emulation \"%s\":\n", debugger_emul->name == NULL?
370 "(simple setup)" : debugger_emul->name);
384 static void debugger_cmd_focus(
struct machine *m,
char *cmd_line)
390 printf(
"syntax: focus x[,y]\n");
391 printf(
"where x (cpu id) and y (machine number) " 392 "are integers as\nreported by the 'emul'" 394 goto print_current_focus_and_return;
398 p = strchr(cmd_line,
',');
400 printf(
"No cpu number specified?\n");
406 p2 = strchr(p+1,
',');
408 printf(
"No machine number specified?\n");
415 if (y < 0 || y >= debugger_emul->n_machines) {
416 printf(
"Invalid machine number: %i\n", y);
421 debugger_machine = debugger_emul->machines[y];
425 if (x < 0 || x >= debugger_machine->ncpus) {
426 printf(
"Invalid cpu number: %i\n", x);
432 print_current_focus_and_return:
433 if (debugger_emul->n_machines > 1)
434 printf(
"current machine (%i): \"%s\"\n",
436 "(no name)" : debugger_machine->name);
443 static void debugger_cmd_help(
struct machine *m,
char *cmd_line);
449 static void debugger_cmd_itrace(
struct machine *m,
char *cmd_line)
452 printf(
"syntax: itrace\n");
467 static void debugger_cmd_lookup(
struct machine *m,
char *cmd_line)
474 if (cmd_line[0] ==
'\0') {
475 printf(
"syntax: lookup name|addr\n");
482 addr = strtoull(cmd_line, NULL, 16);
489 printf(
"lookup for '%s' failed\n", cmd_line);
492 printf(
"%s = 0x", cmd_line);
494 printf(
"%08" PRIx32
"\n", (uint32_t) newaddr);
496 printf(
"%016" PRIx64
"\n", (uint64_t) newaddr);
502 if (symbol != NULL) {
504 printf(
"0x%08" PRIx32, (uint32_t) addr);
506 printf(
"0x%016" PRIx64, (uint64_t) addr);
507 printf(
" = %s\n", symbol);
509 printf(
"lookup for '%s' failed\n", cmd_line);
518 static void debugger_cmd_machine(
struct machine *m,
char *cmd_line)
523 printf(
"syntax: machine\n");
527 if (m->
name != NULL) {
541 static void debugger_cmd_ninstrs(
struct machine *m,
char *cmd_line)
546 if (cmd_line[0] !=
'\0') {
547 while (cmd_line[0] !=
'\0' && cmd_line[0] ==
' ')
549 switch (cmd_line[0]) {
561 switch (cmd_line[1]) {
571 printf(
"syntax: trace [on|off]\n");
579 printf(
"show_nr_of_instructions = %s",
582 printf(
" (was: %s)", previous_mode?
"ON" :
"OFF");
590 static void debugger_cmd_pause(
struct machine *m,
char *cmd_line)
594 if (cmd_line[0] !=
'\0')
595 cpuid = atoi(cmd_line);
597 printf(
"syntax: pause cpuid\n");
601 if (cpuid < 0 || cpuid >= m->
ncpus) {
602 printf(
"cpu%i doesn't exist.\n", cpuid);
608 printf(
"cpu%i (%s) in machine \"%s\" is now %s\n", cpuid,
617 static void debugger_cmd_print(
struct machine *m,
char *cmd_line)
622 while (cmd_line[0] !=
'\0' && cmd_line[0] ==
' ')
625 if (cmd_line[0] ==
'\0') {
626 printf(
"syntax: print expr\n");
633 printf(
"No match.\n");
636 printf(
"Multiple matches. Try prefixing with %%, $, or @.\n");
639 printf(
"%s = 0x%" PRIx64
"\n", cmd_line, (uint64_t)tmp);
643 printf(
"%s = 0x%08" PRIx32
"\n", cmd_line, (uint32_t)tmp);
645 printf(
"%s = 0x%016" PRIx64
"\n", cmd_line,(uint64_t)tmp);
648 printf(
"0x%" PRIx64
"\n", (uint64_t) tmp);
657 static void debugger_cmd_put(
struct machine *m,
char *cmd_line)
659 static char put_type =
' ';
661 int res, syntax_ok = 0;
662 char *p, *p2, *q = NULL;
664 unsigned char a_byte;
666 strncpy(copy, cmd_line,
sizeof(copy));
667 copy[
sizeof(copy)-1] =
'\0';
671 p = strchr(copy,
',');
674 while (*p ==
' ' && *p)
676 while (
strlen(copy) >= 1 &&
677 copy[
strlen(copy) - 1] ==
' ')
678 copy[
strlen(copy) - 1] =
'\0';
688 printf(
"Invalid type '%s'\n", q);
700 printf(
"syntax: put [b|h|w|d|q] addr, data\n");
701 printf(
" b byte (8 bits)\n");
702 printf(
" h half-word (16 bits)\n");
703 printf(
" w word (32 bits)\n");
704 printf(
" d doubleword (64 bits)\n");
705 printf(
" q quad-word (128 bits)\n");
709 if (put_type ==
' ') {
710 printf(
"No type specified.\n");
718 printf(
"Couldn't parse the address.\n");
721 printf(
"Multiple matches for the address." 722 " Try prefixing with %%, $, or @.\n");
729 printf(
"INTERNAL ERROR in debugger.c.\n");
736 printf(
"Couldn't parse the data.\n");
739 printf(
"Multiple matches for the data value." 740 " Try prefixing with %%, $, or @.\n");
747 printf(
"INTERNAL ERROR in debugger.c.\n");
757 printf(
"0x%08" PRIx32, (uint32_t) addr);
759 printf(
"0x%016" PRIx64, (uint64_t) addr);
760 printf(
": %02x", a_byte);
762 printf(
" (NOTE: truncating %0" PRIx64
")",
767 printf(
" FAILED!\n");
772 printf(
"WARNING: address isn't aligned\n");
774 printf(
"0x%08" PRIx32, (uint32_t) addr);
776 printf(
"0x%016" PRIx64, (uint64_t) addr);
777 printf(
": %04x", (
int)data);
779 printf(
" (NOTE: truncating %0" PRIx64
")",
783 printf(
" FAILED!\n");
788 printf(
"WARNING: address isn't aligned\n");
790 printf(
"0x%08" PRIx32, (uint32_t) addr);
792 printf(
"0x%016" PRIx64, (uint64_t) addr);
794 printf(
": %08x", (
int)data);
796 if (data > 0xffffffff && (data >> 32) != 0
797 && (data >> 32) != 0xffffffff)
798 printf(
" (NOTE: truncating %0" PRIx64
")",
803 printf(
" FAILED!\n");
808 printf(
"WARNING: address isn't aligned\n");
810 printf(
"0x%08" PRIx32, (uint32_t) addr);
812 printf(
"0x%016" PRIx64, (uint64_t) addr);
814 printf(
": %016" PRIx64, (uint64_t) data);
818 printf(
" FAILED!\n");
822 printf(
"quad-words: TODO\n");
826 printf(
"Unimplemented type '%c'\n", put_type);
835 static void debugger_cmd_quiet(
struct machine *m,
char *cmd_line)
840 if (cmd_line[0] !=
'\0') {
841 while (cmd_line[0] !=
'\0' && cmd_line[0] ==
' ')
843 switch (cmd_line[0]) {
855 switch (cmd_line[1]) {
865 printf(
"syntax: quiet [on|off]\n");
875 printf(
" (was: %s)", previous_mode?
"ON" :
"OFF");
883 static void debugger_cmd_quit(
struct machine *m,
char *cmd_line)
888 printf(
"syntax: quit\n");
896 for (j=0; j<debugger_emul->n_machines; j++) {
897 struct machine *mp = debugger_emul->machines[j];
899 for (k=0; k<mp->
ncpus; k++)
912 static void debugger_cmd_reg(
struct machine *m,
char *cmd_line)
919 if (cmd_line[0] !=
'\0') {
920 if (cmd_line[0] !=
',') {
921 cpuid = strtoull(cmd_line, NULL, 0);
922 if (cpuid < 0 || cpuid >= m->
ncpus) {
923 printf(
"cpu%i doesn't exist.\n", cpuid);
927 p = strchr(cmd_line,
',');
929 coprocnr = atoi(p + 1);
930 if (coprocnr < 0 || coprocnr >= 4) {
931 printf(
"Invalid coprocessor number.\n");
937 gprs = (coprocnr == -1)? 1 : 0;
938 coprocs = (coprocnr == -1)? 0x0 : (1 << coprocnr);
947 static void debugger_cmd_step(
struct machine *m,
char *cmd_line)
951 if (cmd_line[0] !=
'\0') {
952 n = strtoull(cmd_line, NULL, 0);
954 printf(
"invalid nr of steps\n");
973 static void debugger_cmd_tlbdump(
struct machine *m,
char *cmd_line)
978 if (cmd_line[0] !=
'\0') {
980 if (cmd_line[0] !=
',') {
981 x = strtoull(cmd_line, NULL, 0);
982 if (x < 0 || x >= m->
ncpus) {
983 printf(
"cpu%i doesn't exist.\n", x);
987 p = strchr(cmd_line,
',');
995 printf(
"Unknown tlbdump flag.\n");
996 printf(
"syntax: tlbdump [cpuid][,r]\n");
1009 static void debugger_cmd_trace(
struct machine *m,
char *cmd_line)
1014 if (cmd_line[0] !=
'\0') {
1015 while (cmd_line[0] !=
'\0' && cmd_line[0] ==
' ')
1017 switch (cmd_line[0]) {
1029 switch (cmd_line[1]) {
1039 printf(
"syntax: trace [on|off]\n");
1049 printf(
" (was: %s)", previous_mode?
"ON" :
"OFF");
1061 static void debugger_cmd_unassemble(
struct machine *m,
char *cmd_line)
1063 uint64_t
addr, addr_start, addr_end;
1067 int r, lines_left = -1;
1069 if (cmd_line[0] !=
'\0') {
1076 p = strchr(tmps,
' ');
1083 printf(
"Unparsable address: %s\n", cmd_line);
1086 last_unasm_addr = tmp;
1089 p = strchr(cmd_line,
' ');
1092 if (m->
cpus == NULL) {
1093 printf(
"No cpus (?)\n");
1098 printf(
"m->cpus[m->bootstrap_cpu] = NULL\n");
1103 addr_start = last_unasm_addr;
1112 addr_end = addr_start + 1000;
1116 while (*p ==
' ' && *p)
1120 printf(
"Unparsable address: %s\n", cmd_line);
1130 while (addr < addr_end) {
1131 unsigned int i, len;
1133 unsigned char buf[17];
1135 memset(buf, 0,
sizeof(buf));
1137 for (i=0; i<
sizeof(buf); i++) {
1143 if (failed ==
sizeof(buf)) {
1144 printf(
"(memory access failed)\n");
1157 if (lines_left != -1) {
1159 if (lines_left == 0)
1164 last_unasm_addr =
addr;
1173 static void debugger_cmd_version(
struct machine *m,
char *cmd_line)
1176 printf(
"syntax: version\n");
1180 printf(
"%s, %s\n", VERSION, COMPILE_DATE);
1195 static struct cmd cmds[] = {
1196 {
"allsettings",
"", 0, debugger_cmd_allsettings,
1197 "show all settings" },
1199 {
"breakpoint",
"...", 0, debugger_cmd_breakpoint,
1200 "manipulate breakpoints" },
1205 {
"continue",
"", 0, debugger_cmd_continue,
1206 "continue execution" },
1208 {
"device",
"...", 0, debugger_cmd_device,
1209 "show info about (or manipulate) devices" },
1211 {
"dump",
"[addr [endaddr]]", 0, debugger_cmd_dump,
1212 "dump memory contents in hex and ASCII" },
1214 {
"emul",
"", 0, debugger_cmd_emul,
1215 " PRInt a summary of the current emulation" },
1217 {
"focus",
"x[,y[,z]]", 0, debugger_cmd_focus,
1218 "changes focus to cpu x, machine x, emul z" },
1220 {
"help",
"", 0, debugger_cmd_help,
1221 " PRInt this help message" },
1223 {
"itrace",
"", 0, debugger_cmd_itrace,
1224 "toggle instruction_trace on or off" },
1226 {
"lookup",
"name|addr", 0, debugger_cmd_lookup,
1227 "lookup a symbol by name or address" },
1229 {
"machine",
"", 0, debugger_cmd_machine,
1230 " PRInt a summary of the current machine" },
1232 {
"ninstrs",
"[on|off]", 0, debugger_cmd_ninstrs,
1233 "toggle (set or unset) show_nr_of_instructions" },
1235 {
"pause",
"cpuid", 0, debugger_cmd_pause,
1236 "pause (or unpause) a CPU" },
1238 {
" PRInt",
"expr", 0, debugger_cmd_print,
1239 "evaluate an expression without side-effects" },
1241 {
"put",
"[b|h|w|d|q] addr, data", 0, debugger_cmd_put,
1242 "modify emulated memory contents" },
1244 {
"quiet",
"[on|off]", 0, debugger_cmd_quiet,
1245 "toggle quiet_mode on or off" },
1247 {
"quit",
"", 0, debugger_cmd_quit,
1248 "quit the emulator" },
1253 {
"reg",
"[cpuid][,c]", 0, debugger_cmd_reg,
1254 "show GPRs (or coprocessor c's registers)" },
1259 {
"step",
"[n]", 0, debugger_cmd_step,
1260 "single-step one (or n) instruction(s)" },
1262 {
"tlbdump",
"[cpuid][,r]", 0, debugger_cmd_tlbdump,
1263 "dump TLB contents (add ',r' for raw data)" },
1265 {
"trace",
"[on|off]", 0, debugger_cmd_trace,
1266 "toggle show_trace_tree on or off" },
1268 {
"unassemble",
"[addr [endaddr]]", 0, debugger_cmd_unassemble,
1269 "dump memory contents as instructions" },
1271 {
"version",
"", 0, debugger_cmd_version,
1272 " PRInt version information" },
1275 {
"x = expr",
"", 0, NULL,
"generic assignment" },
1277 { NULL, NULL, 0, NULL, NULL }
1291 static void debugger_cmd_help(
struct machine *m,
char *cmd_line)
1293 int only_one = 0, only_one_match = 0;
1294 char *nlines_env = getenv(
"LINES");
1295 int nlines = atoi(nlines_env != NULL? nlines_env :
"999999"), curlines;
1296 size_t i, j, max_name_len = 0;
1298 if (cmd_line[0] !=
'\0') {
1303 while (cmds[i].
name != NULL) {
1305 if (cmds[i].
args != NULL)
1307 if (a > max_name_len)
1314 printf(
"Available commands:\n");
1319 while (cmds[i].
name != NULL) {
1321 snprintf(buf,
sizeof(buf),
"%s", cmds[i].
name);
1324 if (strcmp(cmds[i].name, cmd_line) != 0) {
1331 if (cmds[i].
args != NULL)
1333 " %s", cmds[i].
args);
1336 for (j=0; j<max_name_len; j++)
1338 printf(
"%c", buf[j]);
1346 if (curlines >= nlines - 1) {
1348 printf(
"-- more --"); fflush(stdout);
1351 if (ch ==
'q' || ch ==
'Q')
1358 if (!only_one_match)
1359 printf(
"%s: no such command\n", cmd_line);
1365 if (curlines > nlines - 1) {
1367 printf(
"-- more --"); fflush(stdout);
1370 if (ch ==
'q' || ch ==
'Q')
1375 printf(
"\nIn generic assignments, x must be a register or other " 1376 "writable settings\nvariable, and expr can contain registers/" 1377 "settings, numeric values, or symbol\nnames, in combination with" 1378 " parenthesis and + - * / & %% ^ | operators.\nIn case there are" 1379 " multiple matches (i.e. a symbol that has the same name as a\n" 1380 "register), you may add a prefix character as a hint: '#' for" 1381 " registers, '@'\nfor symbols, and '$' for numeric values. Use" 1382 " 0x for hexadecimal values.\n");
#define DEBUG_INDENTATION
int store_32bit_word(struct cpu *cpu, uint64_t addr, uint64_t data32)
void cpu_tlbdump(struct machine *m, int x, int rawflag)
struct breakpoints breakpoints
char * get_symbol_name(struct symbol_context *, uint64_t addr, uint64_t *offset)
void * device_add(struct machine *machine, const char *name_and_params)
int exit_without_entering_debugger
int store_64bit_word(struct cpu *cpu, uint64_t addr, uint64_t data64)
int debugger_n_steps_left_before_interaction
#define CHECK_ALLOCATION(ptr)
int force_debugger_at_exit
struct settings * global_settings
int old_instruction_trace
int(* memory_rw)(struct cpu *cpu, struct memory *mem, uint64_t vaddr, unsigned char *data, size_t len, int writeflag, int cache_flags)
#define DM_DYNTRANS_WRITE_OK
unsigned char * translation_cache
void cpu_register_dump(struct machine *m, struct cpu *cpu, int gprs, int coprocs)
void device_dumplist(void)
void(* f)(struct machine *, char *cmd_line)
void COMBINE() strlen(struct cpu *cpu, struct arm_instr_call *ic, int low_addr)
#define MEMORY_ACCESS_FAILED
void debug_indentation(int diff)
void memory_device_remove(struct memory *mem, int i)
void settings_debugdump(struct settings *settings, const char *prefix, int recurse)
struct symbol_context symbol_context
volatile int exit_debugger
int get_symbol_addr(struct symbol_context *, const char *symbol, uint64_t *addr)
int store_16bit_word(struct cpu *cpu, uint64_t addr, uint64_t data16)
#define GLOBAL_SETTINGS_NAME
struct memory_device * devices
int debugger_parse_expression(struct machine *m, char *expr, int writeflag, uint64_t *valuep)
int cpu_disassemble_instr(struct machine *m, struct cpu *cpu, unsigned char *instr, int running, uint64_t addr)
void emul_dumpinfo(struct emul *e)
void cpu_create_or_reset_tc(struct cpu *cpu)
char debugger_readchar(void)
#define NOT_SINGLE_STEPPING
void machine_dumpinfo(struct machine *)
int show_nr_of_instructions
void console_debug_dump(struct machine *machine)