Changes in uspace/app/taskdump/taskdump.c [1ccafee:e3a3a619] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/taskdump/taskdump.c
r1ccafee re3a3a619 40 40 #include <udebug.h> 41 41 #include <task.h> 42 #include < kernel/mm/as.h>42 #include <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> 51 52 #include <stacktrace.h> 52 53 53 54 #define LINE_BYTES 16 54 55 #define DBUF_SIZE 409656 static uint8_t data_buf[DBUF_SIZE];57 55 58 56 static int phoneid; 59 57 static task_id_t task_id; 60 static bool dump_memory; 58 static bool write_core_file; 59 static char *core_file_name; 61 60 static char *app_name; 62 61 static symtab_t *app_symtab; … … 68 67 static int thread_dump(uintptr_t thash); 69 68 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);72 69 static int td_read_uintptr(void *arg, uintptr_t addr, uintptr_t *value); 73 70 … … 80 77 int rc; 81 78 82 /*83 * FIXME: The stdio module cannot currently detect whether we are84 * writing to a console or file. This workaround make file output85 * faster.86 */87 setvbuf(stdout, NULL, _IOFBF, 32768);88 89 79 printf("Task Dump Utility\n"); 90 dump_memory= false;80 write_core_file = false; 91 81 92 82 if (parse_args(argc, argv) < 0) … … 172 162 return -1; 173 163 } 174 } else if (arg[1] == 'm' && arg[2] == '\0') { 175 dump_memory = true; 164 } else if (arg[1] == 'c' && arg[2] == '\0') { 165 write_core_file = true; 166 167 --argc; ++argv; 168 core_file_name = *argv; 176 169 } else { 177 170 printf("Uknown option '%s'\n", arg[0]); … … 203 196 static void print_syntax(void) 204 197 { 205 printf("Syntax: taskdump [- m] -t <task_id>\n");206 printf("\t- m\tDump memory area contents.\n");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"); 207 200 printf("\t-t <task_id>\tWhich task to dump.\n"); 208 201 } … … 297 290 (ainfo_buf[i].flags & AS_AREA_CACHEABLE) ? 'C' : '-', 298 291 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'); 292 } 293 294 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; 304 302 } 305 303 } 306 307 putchar('\n');308 304 309 305 free(ainfo_buf); … … 353 349 354 350 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 }414 351 } 415 352
Note:
See TracChangeset
for help on using the changeset viewer.