Changeset 3698e44 in mainline for uspace/app/taskdump/taskdump.c
- Timestamp:
- 2010-01-26T22:46:29Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 196a1439, 2314381
- Parents:
- e515b21a
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/taskdump/taskdump.c
re515b21a r3698e44 46 46 #include <bool.h> 47 47 48 #include <symtab.h> 48 49 #include <stacktrace.h> 49 50 … … 56 57 static task_id_t task_id; 57 58 static bool dump_memory; 59 static char *app_name; 60 static symtab_t *app_symtab; 58 61 59 62 static int connect_task(task_id_t task_id); … … 67 70 static int td_read_uintptr(void *arg, uintptr_t addr, uintptr_t *value); 68 71 72 static void autoload_syms(void); 73 static char *get_app_task_name(void); 74 static char *fmt_sym_address(uintptr_t addr); 75 69 76 int main(int argc, char *argv[]) 70 77 { … … 90 97 } 91 98 92 printf("Dumping task %lld.\n\n", task_id); 99 app_name = get_app_task_name(); 100 app_symtab = NULL; 101 102 printf("Dumping task '%s' (task ID %lld).\n", app_name, task_id); 103 autoload_syms(); 104 putchar('\n'); 93 105 94 106 rc = threads_dump(); … … 303 315 uintptr_t pc, fp, nfp; 304 316 stacktrace_t st; 317 char *sym_pc; 305 318 int rc; 306 319 … … 320 333 321 334 while (stacktrace_fp_valid(&st, fp)) { 322 printf("%p: %p()\n", fp, pc); 335 sym_pc = fmt_sym_address(pc); 336 printf(" %p: %s()\n", fp, sym_pc); 337 free(sym_pc); 323 338 324 339 rc = stacktrace_ra_get(&st, fp, &pc); … … 412 427 } 413 428 429 /** Attempt to find the right executable file and load the symbol table. */ 430 static void autoload_syms(void) 431 { 432 char *file_name; 433 int rc; 434 435 assert(app_name != NULL); 436 assert(app_symtab == NULL); 437 438 rc = asprintf(&file_name, "/app/%s", app_name); 439 if (rc < 0) { 440 printf("Memory allocation failure.\n"); 441 exit(1); 442 } 443 444 rc = symtab_load(file_name, &app_symtab); 445 if (rc == EOK) { 446 printf("Loaded symbol table from %s\n", file_name); 447 free(file_name); 448 return; 449 } 450 451 free(file_name); 452 453 rc = asprintf(&file_name, "/srv/%s", app_name); 454 if (rc < 0) { 455 printf("Memory allocation failure.\n"); 456 exit(1); 457 } 458 459 rc = symtab_load("/srv/xyz", &app_symtab); 460 if (rc == EOK) { 461 printf("Loaded symbol table from %s\n", file_name); 462 free(file_name); 463 return; 464 } 465 466 free(file_name); 467 printf("Failed autoloading symbol table.\n"); 468 } 469 470 static char *get_app_task_name(void) 471 { 472 char dummy_buf; 473 size_t copied, needed, name_size; 474 char *name; 475 int rc; 476 477 rc = udebug_name_read(phoneid, &dummy_buf, 0, &copied, &needed); 478 if (rc < 0) 479 return NULL; 480 481 name_size = needed; 482 name = malloc(name_size + 1); 483 rc = udebug_name_read(phoneid, name, name_size, &copied, &needed); 484 if (rc < 0) { 485 free(name); 486 return NULL; 487 } 488 489 assert(copied == name_size); 490 assert(copied == needed); 491 name[copied] = '\0'; 492 493 return name; 494 } 495 496 /** Format address in symbolic form. 497 * 498 * Formats address as <symbol_name>+<offset> (<address>), if possible, 499 * otherwise as <address>. 500 * 501 * @param addr Address to format. 502 * @return Newly allocated string, address in symbolic form. 503 */ 504 static char *fmt_sym_address(uintptr_t addr) 505 { 506 char *name; 507 size_t offs; 508 int rc; 509 char *str; 510 511 if (app_symtab != NULL) { 512 rc = symtab_addr_to_name(app_symtab, addr, &name, &offs); 513 } else { 514 rc = ENOTSUP; 515 } 516 517 if (rc == EOK) { 518 rc = asprintf(&str, "(%p) %s+%p", addr, name, offs); 519 } else { 520 rc = asprintf(&str, "%p", addr); 521 } 522 523 if (rc < 0) { 524 printf("Memory allocation error.\n"); 525 exit(1); 526 } 527 528 return str; 529 } 530 414 531 /** @} 415 532 */
Note:
See TracChangeset
for help on using the changeset viewer.