ia64/xen-unstable
changeset 16020:9f2b83a34453
[IA64] xenitp improvements
Remove all the casts by using char * instead of unsigned char *.
The go command now accept a number.
The disass command can now accept a range.
Number of TRs is not hard-coded.
'-' (minus) can now be used in expressions.
'$iip' and '$b0' can be used in expressions.
Signed-off-by: Tristan Gingold <tgingold@free.fr>
Remove all the casts by using char * instead of unsigned char *.
The go command now accept a number.
The disass command can now accept a range.
Number of TRs is not hard-coded.
'-' (minus) can now be used in expressions.
'$iip' and '$b0' can be used in expressions.
Signed-off-by: Tristan Gingold <tgingold@free.fr>
author | Alex Williamson <alex.williamson@hp.com> |
---|---|
date | Tue Oct 02 09:31:45 2007 -0600 (2007-10-02) |
parents | 669347b873fa |
children | df985cc06100 |
files | tools/debugger/xenitp/xenitp.c |
line diff
1.1 --- a/tools/debugger/xenitp/xenitp.c Tue Oct 02 09:20:41 2007 -0600 1.2 +++ b/tools/debugger/xenitp/xenitp.c Tue Oct 02 09:31:45 2007 -0600 1.3 @@ -57,7 +57,7 @@ static int cur_vcpu; 1.4 1.5 int virt_to_phys (int is_inst, unsigned long vaddr, unsigned long *paddr); 1.6 1.7 -inline unsigned int ctx_slot (vcpu_guest_context_t *ctx) 1.8 +static inline unsigned int ctx_slot (vcpu_guest_context_t *ctx) 1.9 { 1.10 return (ctx->regs.psr >> PSR_RI_SHIFT) & 3; 1.11 } 1.12 @@ -65,7 +65,7 @@ inline unsigned int ctx_slot (vcpu_guest 1.13 unsigned char * 1.14 target_map_memory (unsigned long paddr) 1.15 { 1.16 - static unsigned long cur_page = -1; 1.17 + static unsigned long cur_page = (unsigned long)-1; 1.18 static unsigned char *cur_map = NULL; 1.19 1.20 if ((paddr >> XC_PAGE_SHIFT) != cur_page) { 1.21 @@ -243,8 +243,6 @@ void target_disas (FILE *out, unsigned l 1.22 unsigned long pc; 1.23 int count; 1.24 struct disassemble_info disasm_info; 1.25 - int slot; 1.26 - int (*print_insn)(bfd_vma pc, disassemble_info *info); 1.27 1.28 INIT_DISASSEMBLE_INFO(disasm_info, out, fprintf); 1.29 1.30 @@ -257,14 +255,15 @@ void target_disas (FILE *out, unsigned l 1.31 1.32 disasm_info.endian = BFD_ENDIAN_LITTLE; 1.33 disasm_info.mach = 0; //bfd_mach_ia64; 1.34 - print_insn = print_insn_ia64; 1.35 1.36 - for (pc = code, slot = 0; pc < code + size; pc += count, slot++) { 1.37 - fprintf (out, "0x%016lx+%d:%c ", code, slot, 1.38 + for (pc = code; pc < code + size; pc += count) { 1.39 + int slot = (pc & 0x0f) / 6; 1.40 + fprintf (out, "0x%016lx+%d:%c ", pc & ~0x0fUL, slot, 1.41 ((pc & ~0x0fUL) == cur_ctx->regs.ip 1.42 && slot == ctx_slot (cur_ctx)) ? '*' : ' '); 1.43 1.44 - count = print_insn (pc, &disasm_info); 1.45 + count = print_insn_ia64 (pc, &disasm_info); 1.46 + 1.47 #if 0 1.48 { 1.49 int i; 1.50 @@ -337,7 +336,7 @@ static void print_a_tr (int i, const str 1.51 ma_val = tr->pte >> PTE_MA_SHIFT & PTE_MA_MASK; 1.52 pa = (tr->pte >> PTE_PPN_SHIFT & PTE_PPN_MASK) << PTE_PPN_SHIFT; 1.53 pa = (pa >> ps_val) << ps_val; 1.54 - printf (" [%d] %ld %06lx %016lx %013lx %02d %s %ld %ld %ld %ld " 1.55 + printf (" [%2d] %ld %06lx %016lx %013lx %02d %s %ld %ld %ld %ld " 1.56 "%ld %d %s %06lx\n", i, 1.57 tr->pte >> PTE_P_SHIFT & PTE_P_MASK, 1.58 tr->rid >> RR_RID_SHIFT & RR_RID_MASK, 1.59 @@ -638,13 +637,13 @@ void print_tr (vcpu_guest_context_t *ctx 1.60 printf ("\n itr: P rid va pa ps ed pl " 1.61 "ar a d ma key\n"); 1.62 1.63 - for (i = 0; i < 8; i++) 1.64 + for (i = 0; i < sizeof (tr->itrs) / sizeof (tr->itrs[0]); i++) 1.65 print_a_tr (i, &tr->itrs[i]); 1.66 1.67 printf ("\n dtr: P rid va pa ps ed pl " 1.68 "ar a d ma key\n"); 1.69 1.70 - for (i = 0; i < 8; i++) 1.71 + for (i = 0; i < sizeof (tr->dtrs) / sizeof (tr->dtrs[0]); i++) 1.72 print_a_tr (i, &tr->dtrs[i]); 1.73 } 1.74 1.75 @@ -734,15 +733,21 @@ int wait_domain (int vcpu, vcpu_guest_co 1.76 1.77 int virt_to_phys (int is_inst, unsigned long vaddr, unsigned long *paddr) 1.78 { 1.79 + struct vcpu_tr_regs *trs = &cur_ctx->regs.tr; 1.80 struct ia64_tr_entry *tr; 1.81 int i; 1.82 + int num; 1.83 1.84 /* Search in tr. */ 1.85 - if (is_inst) 1.86 - tr = cur_ctx->regs.tr.itrs; 1.87 - else 1.88 - tr = cur_ctx->regs.tr.dtrs; 1.89 - for (i = 0; i < 8; i++, tr++) { 1.90 + if (is_inst) { 1.91 + tr = trs->itrs; 1.92 + num = sizeof (trs->itrs) / sizeof (trs->itrs[0]); 1.93 + } 1.94 + else { 1.95 + tr = trs->dtrs; 1.96 + num = sizeof (trs->dtrs) / sizeof (trs->dtrs[0]); 1.97 + } 1.98 + for (i = 0; i < num; i++, tr++) { 1.99 int ps_val = (tr->itir >> ITIR_PS_SHIFT) & ITIR_PS_MASK; 1.100 unsigned long ps_mask = (-1L) << ps_val; 1.101 1.102 @@ -762,40 +767,44 @@ get_reg_addr (const char *name) 1.103 return &cur_ctx->regs.ip; 1.104 else if (strcmp (name, "psr") == 0) 1.105 return &cur_ctx->regs.psr; 1.106 + else if (strcmp (name, "iip") == 0) 1.107 + return &cur_ctx->regs.cr.iip; 1.108 + else if (strcmp (name, "b0") == 0) 1.109 + return &cur_ctx->regs.b[0]; 1.110 else 1.111 return 0; 1.112 } 1.113 1.114 enum prio_expr {EXPR_BASE, EXPR_SUM, EXPR_LOGIC, EXPR_PROD}; 1.115 1.116 -int parse_expr (unsigned char **buf, unsigned long *res, enum prio_expr prio); 1.117 +int parse_expr (char **buf, unsigned long *res, enum prio_expr prio); 1.118 1.119 -int next_char (unsigned char **buf) 1.120 +int next_char (char **buf) 1.121 { 1.122 - unsigned char *b; 1.123 + char *b; 1.124 1.125 b = *buf; 1.126 - while (isspace (*b)) 1.127 + while (isspace ((unsigned char)*b)) 1.128 b++; 1.129 *buf = b; 1.130 return *b; 1.131 } 1.132 1.133 -int parse_unary (unsigned char **buf, unsigned long *res) 1.134 +int parse_unary (char **buf, unsigned long *res) 1.135 { 1.136 - unsigned char c; 1.137 + char c; 1.138 1.139 c = next_char (buf); 1.140 switch (c) { 1.141 case '0' ... '9': 1.142 { 1.143 char *e; 1.144 - *res = strtoul ((char *)*buf, &e, 0); 1.145 - if (e == (char *)*buf) { 1.146 + *res = strtoul (*buf, &e, 0); 1.147 + if (e == *buf) { 1.148 printf ("bad literal\n"); 1.149 return -1; 1.150 } 1.151 - *buf = (unsigned char *)e; 1.152 + *buf = e; 1.153 } 1.154 break; 1.155 case '+': 1.156 @@ -803,9 +812,9 @@ int parse_unary (unsigned char **buf, un 1.157 return parse_unary (buf, res); 1.158 case '$': 1.159 { 1.160 - unsigned char *b; 1.161 - unsigned char *e; 1.162 - unsigned char c; 1.163 + char *b; 1.164 + char *e; 1.165 + char c; 1.166 unsigned long *reg; 1.167 int len; 1.168 1.169 @@ -828,13 +837,13 @@ int parse_unary (unsigned char **buf, un 1.170 1.171 c = b[len]; 1.172 b[len] = 0; 1.173 - reg = get_reg_addr ((char *)b); 1.174 + reg = get_reg_addr (b); 1.175 b[len] = c; 1.176 1.177 if (reg != NULL) 1.178 *res = *reg; 1.179 - else if (strncmp ((char *)b, "d2p", len) == 0 || 1.180 - strncmp ((char *)b, "i2p", len) == 0) { 1.181 + else if (strncmp (b, "d2p", len) == 0 || 1.182 + strncmp (b, "i2p", len) == 0) { 1.183 unsigned long vaddr; 1.184 1.185 *buf = e; 1.186 @@ -873,25 +882,29 @@ int parse_unary (unsigned char **buf, un 1.187 return 0; 1.188 } 1.189 1.190 -int parse_expr (unsigned char **buf, unsigned long *res, enum prio_expr prio) 1.191 +int parse_expr (char **buf, unsigned long *res, enum prio_expr prio) 1.192 { 1.193 unsigned long val = 0; 1.194 unsigned long val1; 1.195 + char c; 1.196 1.197 if (parse_unary (buf, &val) != 0) 1.198 return -1; 1.199 1.200 while (1) { 1.201 - switch (next_char (buf)) { 1.202 + c = next_char (buf); 1.203 + switch (c) { 1.204 case '+': 1.205 + case '-': 1.206 if (prio > EXPR_SUM) 1.207 return 0; 1.208 - 1.209 (*buf)++; 1.210 if (parse_expr (buf, &val1, EXPR_SUM) < 0) 1.211 return -1; 1.212 - 1.213 - val += val1; 1.214 + if (c == '+') 1.215 + val += val1; 1.216 + else 1.217 + val -= val1; 1.218 break; 1.219 case '*': 1.220 if (prio > EXPR_PROD) 1.221 @@ -910,17 +923,17 @@ int parse_expr (unsigned char **buf, uns 1.222 } 1.223 } 1.224 1.225 -unsigned char *parse_arg (unsigned char **buf) 1.226 +char *parse_arg (char **buf) 1.227 { 1.228 - unsigned char *res; 1.229 - unsigned char *b = *buf; 1.230 + char *res; 1.231 + char *b = *buf; 1.232 1.233 /* Eat leading spaces. */ 1.234 - while (isspace (*b)) 1.235 + while (isspace ((unsigned char)*b)) 1.236 b++; 1.237 1.238 res = b; 1.239 - while (*b && !isspace (*b)) 1.240 + while (*b && !isspace ((unsigned char)*b)) 1.241 b++; 1.242 1.243 /* Set the NUL terminator. */ 1.244 @@ -948,18 +961,18 @@ struct command_desc 1.245 { 1.246 const char *name; 1.247 const char *help; 1.248 - int (*cmd)(unsigned char *line); 1.249 + int (*cmd)(char *line); 1.250 }; 1.251 1.252 static int 1.253 -cmd_registers (unsigned char *line) 1.254 +cmd_registers (char *line) 1.255 { 1.256 print_ctx (cur_ctx); 1.257 return 0; 1.258 } 1.259 1.260 static int 1.261 -cmd_sstep (unsigned char *line) 1.262 +cmd_sstep (char *line) 1.263 { 1.264 if ((cur_ctx->regs.psr & (PSR_SS | PSR_TB)) != PSR_SS) { 1.265 cur_ctx->regs.psr |= PSR_SS; 1.266 @@ -979,27 +992,36 @@ cmd_sstep (unsigned char *line) 1.267 } 1.268 1.269 static int 1.270 -cmd_go (unsigned char *line) 1.271 +cmd_go (char *line) 1.272 { 1.273 - if ((cur_ctx->regs.psr & (PSR_SS | PSR_TB | PSR_DB)) != 0) { 1.274 - cur_ctx->regs.psr &= ~(PSR_SS | PSR_TB); 1.275 - cur_ctx->regs.psr |= PSR_DD | PSR_ID; 1.276 - if (vcpu_setcontext (cur_vcpu) < 0) 1.277 + unsigned long n = 1; 1.278 + 1.279 + if (*line != 0) { 1.280 + if (parse_expr (&line, &n, 0) < 0) 1.281 return -1; 1.282 } 1.283 + while (n > 0) { 1.284 + /* Set psr.dd and psr.id to skip over current breakpoint. */ 1.285 + if ((cur_ctx->regs.psr & (PSR_SS | PSR_TB | PSR_DB)) != 0) { 1.286 + cur_ctx->regs.psr &= ~(PSR_SS | PSR_TB); 1.287 + cur_ctx->regs.psr |= PSR_DD | PSR_ID; 1.288 + if (vcpu_setcontext (cur_vcpu) < 0) 1.289 + return -1; 1.290 + } 1.291 1.292 - if (wait_domain (cur_vcpu, cur_ctx) < 0) { 1.293 - perror ("wait_domain"); 1.294 - return -1; 1.295 + if (wait_domain (cur_vcpu, cur_ctx) < 0) { 1.296 + perror ("wait_domain"); 1.297 + return -1; 1.298 + } 1.299 + print_ctx (cur_ctx); 1.300 + n--; 1.301 } 1.302 1.303 - print_ctx (cur_ctx); 1.304 - 1.305 return 0; 1.306 } 1.307 1.308 static int 1.309 -cmd_cb (unsigned char *line) 1.310 +cmd_cb (char *line) 1.311 { 1.312 if ((cur_ctx->regs.psr & (PSR_SS | PSR_TB)) != PSR_TB) { 1.313 cur_ctx->regs.psr &= ~PSR_SS; 1.314 @@ -1019,35 +1041,42 @@ cmd_cb (unsigned char *line) 1.315 } 1.316 1.317 static int 1.318 -cmd_quit (unsigned char *line) 1.319 +cmd_quit (char *line) 1.320 { 1.321 return -2; 1.322 } 1.323 1.324 static int 1.325 -cmd_echo (unsigned char *line) 1.326 +cmd_echo (char *line) 1.327 { 1.328 printf ("%s", line); 1.329 return 0; 1.330 } 1.331 1.332 static int 1.333 -cmd_disassemble (unsigned char *args) 1.334 +cmd_disassemble (char *args) 1.335 { 1.336 static unsigned long addr; 1.337 + unsigned long end_addr = addr + 16; 1.338 1.339 - if (*args != 0) 1.340 + if (*args != 0) { 1.341 if (parse_expr (&args, &addr, 0) < 0) 1.342 return -1; 1.343 + if (*args != 0) { 1.344 + if (parse_expr (&args, &end_addr, 0) < 0) 1.345 + return -1; 1.346 + } 1.347 + else 1.348 + end_addr = addr + 16; 1.349 + } 1.350 + target_disas (stdout, addr, end_addr - addr); 1.351 + addr = end_addr; 1.352 + return 0; 1.353 1.354 - target_disas (stdout, addr, 16); 1.355 - addr += 16; 1.356 - 1.357 - return 0; 1.358 } 1.359 1.360 static int 1.361 -cmd_break (unsigned char *args) 1.362 +cmd_break (char *args) 1.363 { 1.364 unsigned long addr; 1.365 int i; 1.366 @@ -1072,7 +1101,7 @@ cmd_break (unsigned char *args) 1.367 } 1.368 1.369 static int 1.370 -cmd_watch (unsigned char *args) 1.371 +cmd_watch (char *args) 1.372 { 1.373 unsigned long addr; 1.374 unsigned long mask; 1.375 @@ -1101,7 +1130,7 @@ cmd_watch (unsigned char *args) 1.376 } 1.377 1.378 static int 1.379 -cmd_delete (unsigned char *args) 1.380 +cmd_delete (char *args) 1.381 { 1.382 unsigned long num; 1.383 1.384 @@ -1128,7 +1157,7 @@ cmd_delete (unsigned char *args) 1.385 } 1.386 1.387 static int 1.388 -cmd_disable (unsigned char *args) 1.389 +cmd_disable (char *args) 1.390 { 1.391 unsigned long num; 1.392 1.393 @@ -1146,7 +1175,7 @@ cmd_disable (unsigned char *args) 1.394 } 1.395 1.396 static int 1.397 -cmd_enable (unsigned char *args) 1.398 +cmd_enable (char *args) 1.399 { 1.400 unsigned long num; 1.401 1.402 @@ -1164,7 +1193,7 @@ cmd_enable (unsigned char *args) 1.403 } 1.404 1.405 static int 1.406 -cmd_print (unsigned char *args) 1.407 +cmd_print (char *args) 1.408 { 1.409 unsigned long addr; 1.410 1.411 @@ -1199,37 +1228,38 @@ static const struct bit_xlat debug_flags 1.412 { XEN_IA64_DEBUG_FORCE_DB, "db" }, 1.413 { XEN_IA64_DEBUG_ON_TR, "tr" }, 1.414 { XEN_IA64_DEBUG_ON_TC, "tc" }, 1.415 + /* { XEN_IA64_DEBUG_ON_KEYS, "keys" }, */ 1.416 { 0, NULL } 1.417 }; 1.418 1.419 static int 1.420 -cmd_disp (unsigned char *arg) 1.421 +cmd_disp (char *arg) 1.422 { 1.423 - if (strcmp ((char *)arg, "br") == 0) 1.424 + if (strcmp (arg, "br") == 0) 1.425 print_br (cur_ctx); 1.426 - else if (strcmp ((char *)arg, "regs") == 0) 1.427 + else if (strcmp (arg, "regs") == 0) 1.428 print_regs (cur_ctx); 1.429 - else if (strcmp ((char *)arg, "cr") == 0) 1.430 + else if (strcmp (arg, "cr") == 0) 1.431 print_cr (cur_ctx); 1.432 - else if (strcmp ((char *)arg, "ar") == 0) 1.433 + else if (strcmp (arg, "ar") == 0) 1.434 print_ar (cur_ctx); 1.435 - else if (strcmp ((char *)arg, "tr") == 0) 1.436 + else if (strcmp (arg, "tr") == 0) 1.437 print_tr (cur_ctx); 1.438 - else if (strcmp ((char *)arg, "rr") == 0) 1.439 + else if (strcmp (arg, "rr") == 0) 1.440 print_rr (cur_ctx); 1.441 - else if (strcmp ((char *)arg, "db") == 0) 1.442 + else if (strcmp (arg, "db") == 0) 1.443 print_db (cur_ctx); 1.444 - else if (strcmp ((char *)arg, "psr") == 0) { 1.445 + else if (strcmp (arg, "psr") == 0) { 1.446 printf ("psr:"); 1.447 print_bits (psr_bits, cur_ctx->regs.psr); 1.448 printf ("\n"); 1.449 } 1.450 - else if (strcmp ((char *)arg, "ipsr") == 0) { 1.451 + else if (strcmp (arg, "ipsr") == 0) { 1.452 printf ("ipsr:"); 1.453 print_bits (psr_bits, cur_ctx->regs.cr.ipsr); 1.454 printf ("\n"); 1.455 } 1.456 - else if (strcmp ((char *)arg, "break") == 0) { 1.457 + else if (strcmp (arg, "break") == 0) { 1.458 int i; 1.459 1.460 for (i = 0; i < 4; i++) 1.461 @@ -1238,7 +1268,7 @@ cmd_disp (unsigned char *arg) 1.462 (cur_ctx->regs.ibr[2 * i + 1] & (1UL << 63)) ? 1.463 "enabled" : "disabled"); 1.464 } 1.465 - else if (strcmp ((char *)arg, "domain") == 0) { 1.466 + else if (strcmp (arg, "domain") == 0) { 1.467 xc_dominfo_t dominfo; 1.468 #ifdef HAVE_DEBUG_OP 1.469 xen_ia64_debug_op_t debug_op; 1.470 @@ -1269,6 +1299,8 @@ cmd_disp (unsigned char *arg) 1.471 printf (" running"); 1.472 if (dominfo.hvm) 1.473 printf (" hvm"); 1.474 + if (dominfo.debugged) 1.475 + printf (" debug"); 1.476 printf ("\n"); 1.477 1.478 #ifdef HAVE_DEBUG_OP 1.479 @@ -1292,7 +1324,7 @@ cmd_disp (unsigned char *arg) 1.480 } 1.481 1.482 static int 1.483 -cmd_bev (unsigned char *arg) 1.484 +cmd_bev (char *arg) 1.485 { 1.486 xen_ia64_debug_op_t debug_op; 1.487 int i; 1.488 @@ -1345,15 +1377,15 @@ cmd_bev (unsigned char *arg) 1.489 } 1.490 1.491 static int 1.492 -cmd_set (unsigned char *line) 1.493 +cmd_set (char *line) 1.494 { 1.495 - unsigned char *reg; 1.496 + char *reg; 1.497 unsigned long *addr; 1.498 unsigned long val; 1.499 1.500 reg = parse_arg (&line); 1.501 1.502 - addr = get_reg_addr ((char *)reg); 1.503 + addr = get_reg_addr (reg); 1.504 if (addr == NULL) { 1.505 printf ("unknown register %s\n", reg); 1.506 return -1; 1.507 @@ -1370,7 +1402,7 @@ cmd_set (unsigned char *line) 1.508 const struct command_desc commands[]; 1.509 1.510 static int 1.511 -cmd_help (unsigned char *line) 1.512 +cmd_help (char *line) 1.513 { 1.514 int i; 1.515 1.516 @@ -1398,14 +1430,14 @@ const struct command_desc commands[] = { 1.517 { "bev", "break on event", cmd_bev}, 1.518 { "set", "set reg val", cmd_set}, 1.519 { "help", "disp help", cmd_help }, 1.520 - { NULL, NULL } 1.521 + { NULL, NULL, NULL } 1.522 }; 1.523 1.524 1.525 -int do_command (int vcpu, unsigned char *line) 1.526 +int do_command (int vcpu, char *line) 1.527 { 1.528 - unsigned char *cmd; 1.529 - unsigned char *args; 1.530 + char *cmd; 1.531 + char *args; 1.532 int i; 1.533 const struct command_desc *desc; 1.534 int flag_ambiguous; 1.535 @@ -1421,7 +1453,7 @@ int do_command (int vcpu, unsigned char 1.536 1.537 for (i = 0; commands[i].name; i++) { 1.538 const char *n = commands[i].name; 1.539 - unsigned char *c = cmd; 1.540 + char *c = cmd; 1.541 1.542 while (*n == *c && *n) 1.543 n++, c++; 1.544 @@ -1494,12 +1526,12 @@ void xenitp (int vcpu) 1.545 perror ("sigaction"); 1.546 1.547 while (1) { 1.548 - unsigned char buf[128]; 1.549 + char buf[128]; 1.550 int len; 1.551 1.552 printf ("XenITP> "); 1.553 1.554 - if (fgets ((char *)buf, sizeof (buf), stdin) == NULL) 1.555 + if (fgets (buf, sizeof (buf), stdin) == NULL) 1.556 break; 1.557 1.558 len = strlen ((char *)buf);