Changeset 0b9ac3c in mainline for uspace/app/taskdump/taskdump.c


Ignore:
Timestamp:
2010-02-23T19:03:28Z (14 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
c62d2e1
Parents:
1ccafee (diff), 5e50394 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge mainline changes.

File:
1 edited

Legend:

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

    r1ccafee r0b9ac3c  
    4040#include <udebug.h>
    4141#include <task.h>
    42 #include <kernel/mm/as.h>
     42#include <as.h>
    4343#include <sys/types.h>
    4444#include <sys/typefmt.h>
     
    4949
    5050#include <symtab.h>
     51#include <elf_core.h>
    5152#include <stacktrace.h>
    5253
    5354#define LINE_BYTES 16
    54 
    55 #define DBUF_SIZE 4096
    56 static uint8_t data_buf[DBUF_SIZE];
    5755
    5856static int phoneid;
    5957static task_id_t task_id;
    60 static bool dump_memory;
     58static bool write_core_file;
     59static char *core_file_name;
    6160static char *app_name;
    6261static symtab_t *app_symtab;
     
    6867static int thread_dump(uintptr_t thash);
    6968static 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);
    7269static int td_read_uintptr(void *arg, uintptr_t addr, uintptr_t *value);
    7370
     
    8077        int rc;
    8178
    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 
    8979        printf("Task Dump Utility\n");
    90         dump_memory = false;
     80        write_core_file = false;
    9181
    9282        if (parse_args(argc, argv) < 0)
     
    172162                                        return -1;
    173163                                }
    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;
    176169                        } else {
    177170                                printf("Uknown option '%s'\n", arg[0]);
     
    203196static void print_syntax(void)
    204197{
    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");
    207200        printf("\t-t <task_id>\tWhich task to dump.\n");
    208201}
     
    297290                    (ainfo_buf[i].flags & AS_AREA_CACHEABLE) ? 'C' : '-',
    298291                    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;
    304302                }
    305303        }
    306 
    307         putchar('\n');
    308304
    309305        free(ainfo_buf);
     
    353349
    354350        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         }
    414351}
    415352
Note: See TracChangeset for help on using the changeset viewer.