Changes in uspace/app/taskdump/taskdump.c [e3a3a619:1ccafee] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/taskdump/taskdump.c
re3a3a619 r1ccafee 40 40 #include <udebug.h> 41 41 #include <task.h> 42 #include < as.h>42 #include <kernel/mm/as.h> 43 43 #include <sys/types.h> 44 44 #include <sys/typefmt.h> … … 49 49 50 50 #include <symtab.h> 51 #include <elf_core.h>52 51 #include <stacktrace.h> 53 52 54 53 #define LINE_BYTES 16 54 55 #define DBUF_SIZE 4096 56 static uint8_t data_buf[DBUF_SIZE]; 55 57 56 58 static int phoneid; 57 59 static task_id_t task_id; 58 static bool write_core_file; 59 static char *core_file_name; 60 static bool dump_memory; 60 61 static char *app_name; 61 62 static symtab_t *app_symtab; … … 67 68 static int thread_dump(uintptr_t thash); 68 69 static int areas_dump(void); 70 static int area_dump(as_area_info_t *area); 71 static void hex_dump(uintptr_t addr, void *buffer, size_t size); 69 72 static int td_read_uintptr(void *arg, uintptr_t addr, uintptr_t *value); 70 73 … … 77 80 int rc; 78 81 82 /* 83 * FIXME: The stdio module cannot currently detect whether we are 84 * writing to a console or file. This workaround make file output 85 * faster. 86 */ 87 setvbuf(stdout, NULL, _IOFBF, 32768); 88 79 89 printf("Task Dump Utility\n"); 80 write_core_file= false;90 dump_memory = false; 81 91 82 92 if (parse_args(argc, argv) < 0) … … 162 172 return -1; 163 173 } 164 } else if (arg[1] == 'c' && arg[2] == '\0') { 165 write_core_file = true; 166 167 --argc; ++argv; 168 core_file_name = *argv; 174 } else if (arg[1] == 'm' && arg[2] == '\0') { 175 dump_memory = true; 169 176 } else { 170 177 printf("Uknown option '%s'\n", arg[0]); … … 196 203 static void print_syntax(void) 197 204 { 198 printf("Syntax: taskdump [- c <core_file>] -t <task_id>\n");199 printf("\t- c <core_file_id>\tName of core file to write.\n");205 printf("Syntax: taskdump [-m] -t <task_id>\n"); 206 printf("\t-m\tDump memory area contents.\n"); 200 207 printf("\t-t <task_id>\tWhich task to dump.\n"); 201 208 } … … 290 297 (ainfo_buf[i].flags & AS_AREA_CACHEABLE) ? 'C' : '-', 291 298 ainfo_buf[i].start_addr, ainfo_buf[i].size); 299 300 if (dump_memory) { 301 putchar('\n'); 302 area_dump(&ainfo_buf[i]); 303 putchar('\n'); 304 } 292 305 } 293 306 294 307 putchar('\n'); 295 296 if (write_core_file) {297 printf("Writing core file '%s'\n", core_file_name);298 rc = elf_core_save(core_file_name, ainfo_buf, n_areas, phoneid);299 if (rc != EOK) {300 printf("Failed writing core file.\n");301 return EIO;302 }303 }304 308 305 309 free(ainfo_buf); … … 349 353 350 354 return EOK; 355 } 356 357 static int area_dump(as_area_info_t *area) 358 { 359 size_t to_copy; 360 size_t total; 361 uintptr_t addr; 362 int rc; 363 364 addr = area->start_addr; 365 total = 0; 366 367 while (total < area->size) { 368 to_copy = min(area->size - total, DBUF_SIZE); 369 rc = udebug_mem_read(phoneid, data_buf, addr, to_copy); 370 if (rc < 0) { 371 printf("udebug_mem_read() failed.\n"); 372 return rc; 373 } 374 375 hex_dump(addr, data_buf, to_copy); 376 377 addr += to_copy; 378 total += to_copy; 379 } 380 381 return EOK; 382 } 383 384 static void hex_dump(uintptr_t addr, void *buffer, size_t size) 385 { 386 uint8_t *data = (uint8_t *) buffer; 387 uint8_t b; 388 size_t pos, i; 389 390 assert(addr % LINE_BYTES == 0); 391 assert(size % LINE_BYTES == 0); 392 393 pos = 0; 394 395 while (pos < size) { 396 printf("%08lx:", addr + pos); 397 for (i = 0; i < LINE_BYTES; ++i) { 398 if (i % 4 == 0) putchar(' '); 399 printf(" %02x", data[pos + i]); 400 } 401 putchar('\t'); 402 403 for (i = 0; i < LINE_BYTES; ++i) { 404 b = data[pos + i]; 405 if (b >= 32 && b < 127) { 406 putchar(b); 407 } else { 408 putchar(' '); 409 } 410 } 411 putchar('\n'); 412 pos += LINE_BYTES; 413 } 351 414 } 352 415
Note:
See TracChangeset
for help on using the changeset viewer.