Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/taskdump/taskdump.c

    re3a3a619 r1ccafee  
    4040#include <udebug.h>
    4141#include <task.h>
    42 #include <as.h>
     42#include <kernel/mm/as.h>
    4343#include <sys/types.h>
    4444#include <sys/typefmt.h>
     
    4949
    5050#include <symtab.h>
    51 #include <elf_core.h>
    5251#include <stacktrace.h>
    5352
    5453#define LINE_BYTES 16
     54
     55#define DBUF_SIZE 4096
     56static uint8_t data_buf[DBUF_SIZE];
    5557
    5658static int phoneid;
    5759static task_id_t task_id;
    58 static bool write_core_file;
    59 static char *core_file_name;
     60static bool dump_memory;
    6061static char *app_name;
    6162static symtab_t *app_symtab;
     
    6768static int thread_dump(uintptr_t thash);
    6869static int areas_dump(void);
     70static int area_dump(as_area_info_t *area);
     71static void hex_dump(uintptr_t addr, void *buffer, size_t size);
    6972static int td_read_uintptr(void *arg, uintptr_t addr, uintptr_t *value);
    7073
     
    7780        int rc;
    7881
     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
    7989        printf("Task Dump Utility\n");
    80         write_core_file = false;
     90        dump_memory = false;
    8191
    8292        if (parse_args(argc, argv) < 0)
     
    162172                                        return -1;
    163173                                }
    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;
    169176                        } else {
    170177                                printf("Uknown option '%s'\n", arg[0]);
     
    196203static void print_syntax(void)
    197204{
    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");
    200207        printf("\t-t <task_id>\tWhich task to dump.\n");
    201208}
     
    290297                    (ainfo_buf[i].flags & AS_AREA_CACHEABLE) ? 'C' : '-',
    291298                    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                }
    292305        }
    293306
    294307        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         }
    304308
    305309        free(ainfo_buf);
     
    349353
    350354        return EOK;
     355}
     356
     357static 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
     384static 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        }
    351414}
    352415
Note: See TracChangeset for help on using the changeset viewer.