84 static volatile int ctrl_c;
89 static struct machine *debugger_machine;
90 static struct emul *debugger_emul;
92 #define MAX_CMD_BUFLEN 72 93 #define N_PREVIOUS_CMDS 150 95 static int last_cmd_index;
99 #define MAGIC_UNTOUCHED 0x98ca76c2ffcc0011ULL 153 repeat_cmd[0] =
'\0';
163 static void show_breakpoint(
struct machine *m,
int i)
165 printf(
"%3i: 0x", i);
193 int res_left, res_right;
195 uint64_t old_pc = m->
cpus[0]->
pc;
199 right = strchr(left,
'=');
201 fprintf(stderr,
"internal error in the debugger\n");
207 while (
strlen(left) >= 1 && left[
strlen(left)-1] ==
' ')
208 left[
strlen(left)-1] =
'\0';
212 while (*right ==
' ' && *right !=
'\0')
220 printf(
"No match for the right-hand side of the assignment.\n");
223 printf(
"Multiple matches for the right-hand side of the " 230 printf(
"No match for the left-hand side of the " 234 printf(
"Multiple matches for the left-hand side " 235 "of the assignment.\n");
238 debugger_cmd_print(m, left);
248 if (old_pc != m->
cpus[0]->
pc)
260 int i, n, i_match, matchlen;
268 if (strchr(cmd,
'=') != NULL) {
270 int nw = 0, inword = 0;
291 while (cmds[i].
name != NULL)
292 cmds[i++].tmp_flag = 0;
296 while (isalpha((
int)cmd[matchlen]))
301 while (cmds[i].
name != NULL) {
302 if (strncasecmp(cmds[i].
name, cmd, matchlen) == 0
303 && cmds[i].
f != NULL) {
304 cmds[i].tmp_flag = 1;
313 printf(
"Unknown command '%s'. Type 'help' for help.\n", cmd);
319 printf(
"Ambiguous command '%s': ", cmd);
321 while (cmds[i].
name != NULL) {
322 if (cmds[i].tmp_flag)
323 printf(
" %s", cmds[i].
name);
331 if (cmds[i_match].
f != NULL) {
332 char *p = cmd + matchlen;
334 while (*p !=
'\0' && *p ==
' ')
338 cmds[i_match].f(debugger_machine, p);
340 printf(
"FATAL ERROR: internal error in debugger.c:" 341 " no handler for this command?\n");
350 static char *debugger_readline(
void)
352 int ch, i, j, n, i_match, reallen, cmd_len, cursor_pos;
353 int read_from_index = last_cmd_index;
354 char *
cmd = last_cmd[last_cmd_index];
356 cmd_len = 0; cmd[0] =
'\0';
367 if ((ch ==
'\b' || ch == 127) && cursor_pos > 0) {
371 memmove(cmd + cursor_pos, cmd + cursor_pos + 1,
375 for (i=cursor_pos; i<cmd_len; i++)
376 printf(
"%c", cmd[i]);
378 for (i=cursor_pos; i<cmd_len; i++)
380 }
else if (ch == 4 && cmd_len > 0 && cursor_pos < cmd_len) {
383 memmove(cmd + cursor_pos, cmd + cursor_pos + 1,
386 for (i=cursor_pos; i<cmd_len; i++)
387 printf(
"%c", cmd[i]);
389 for (i=cursor_pos; i<cmd_len; i++)
391 }
else if (ch == 1) {
393 while (cursor_pos > 0) {
397 }
else if (ch == 2) {
399 if (cursor_pos > 0) {
403 }
else if (ch == 5) {
405 while (cursor_pos < cmd_len) {
406 printf(
"%c", cmd[cursor_pos]);
409 }
else if (ch == 6) {
411 if (cursor_pos < cmd_len) {
416 }
else if (ch == 11) {
420 }
else if (ch == 14 || ch == 16) {
425 read_from_index == last_cmd_index)
428 i = read_from_index - 1;
430 i = read_from_index + 1;
439 if (i == last_cmd_index) {
441 for (i=cursor_pos; i<cmd_len;
444 for (i=cmd_len-1; i>=0; i--)
447 cmd_len = cursor_pos = 0;
448 }
else if (last_cmd[i][0] !=
'\0') {
451 for (i=cursor_pos; i<cmd_len;
454 for (i=cmd_len-1; i>=0; i--)
457 last_cmd[read_from_index],
461 cursor_pos = cmd_len;
466 memmove(cmd + cursor_pos + 1, cmd + cursor_pos,
467 cmd_len - cursor_pos);
468 cmd[cursor_pos] = ch;
473 for (i=cursor_pos; i<cmd_len; i++)
474 printf(
"%c", cmd[i]);
475 for (i=cursor_pos; i<cmd_len; i++)
477 }
else if (ch ==
'\r' || ch ==
'\n') {
480 }
else if (ch ==
'\t') {
483 while (cmds[i].
name != NULL)
484 cmds[i++].tmp_flag = 0;
488 while (cmds[i].
name != NULL) {
489 if (strncasecmp(cmds[i].
name, cmd,
491 cmds[i].tmp_flag = 1;
504 for (i=cmd_len; i<reallen; i++)
506 cmds[i_match].name[i]);
509 if (cmds[i_match].args != NULL &&
510 cmds[i_match].args[0] !=
'\0')
518 while (cmds[i].name != NULL) {
519 if (cmds[i].tmp_flag) {
540 for (i=0; i<cmd_len; i++)
541 printf(
"%c", cmd[i]);
543 }
else if (ch == 27) {
547 if (ch ==
'[' || ch ==
'O') {
626 for (i=0; i<debugger_machine->
ncpus; i++)
629 debugger_machine->
cpus[i]->
630 invalidate_translation_caches(
641 cmd = debugger_readline();
646 while (cmd_len > 0 && cmd[0]==
' ')
647 memmove(cmd, cmd+1, cmd_len --);
648 while (cmd_len > 0 && cmd[cmd_len-1] ==
' ')
649 cmd[(cmd_len--)-1] =
'\0';
654 if (repeat_cmd[0] !=
'\0')
663 repeat_cmd[0] =
'\0';
678 for (i=0; i<debugger_machine->
ncpus; i++) {
713 debugger_emul = emul;
716 fprintf(stderr,
"\nERROR: No machines, " 717 "cannot handle this situation yet.\n\n");
721 debugger_machine = emul->
machines[0];
728 last_cmd[i][0] =
'\0';
732 repeat_cmd[0] =
'\0';
volatile int single_step_breakpoint
void x11_check_event(struct emul *emul)
struct breakpoints breakpoints
void f(int s, int func, int only_name)
void debugger_execute_cmd(char *cmd, int cmd_len)
void console_makeavail(int handle, char ch)
int console_readchar(int handle)
int old_instruction_trace
#define CHECK_ALLOCATION(ptr)
int force_debugger_at_exit
void debugger_activate(int x)
int console_charavail(int handle)
unsigned char * translation_cache
#define ENTER_SINGLE_STEPPING
int debugger_n_steps_left_before_interaction
void debugger_init(struct emul *emul)
void COMBINE() strlen(struct cpu *cpu, struct arm_instr_call *ic, int low_addr)
int64_t ninstrs_since_gettimeofday
volatile int exit_debugger
void debugger_assignment(struct machine *m, char *cmd)
struct settings * global_settings
struct machine ** machines
int debugger_parse_expression(struct machine *m, char *expr, int writeflag, uint64_t *valuep)
void cpu_create_or_reset_tc(struct cpu *cpu)
char debugger_readchar(void)
#define NOT_SINGLE_STEPPING
void debugger_reset(void)