Ignore:
File:
1 edited

Legend:

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

    r6a343bdf r5baf209  
    3434
    3535#include <async.h>
     36#include <elf/elf_linux.h>
    3637#include <stdio.h>
    3738#include <stdlib.h>
     
    5455#define LINE_BYTES 16
    5556
    56 static int phoneid;
     57static async_sess_t *sess;
    5758static task_id_t task_id;
    5859static bool write_core_file;
     
    7374static char *fmt_sym_address(uintptr_t addr);
    7475
     76static istate_t reg_state;
     77
    7578int main(int argc, char *argv[])
    7679{
     
    104107                printf("Failed dumping address space areas.\n");
    105108
    106         udebug_end(phoneid);
    107         async_hangup(phoneid);
     109        udebug_end(sess);
     110        async_hangup(sess);
    108111
    109112        return 0;
     
    112115static int connect_task(task_id_t task_id)
    113116{
    114         int rc;
    115 
    116         rc = async_connect_kbox(task_id);
    117 
    118         if (rc == ENOTSUP) {
    119                 printf("You do not have userspace debugging support "
    120                     "compiled in the kernel.\n");
    121                 printf("Compile kernel with 'Support for userspace debuggers' "
    122                     "(CONFIG_UDEBUG) enabled.\n");
    123                 return rc;
    124         }
    125 
    126         if (rc < 0) {
     117        async_sess_t *ksess = async_connect_kbox(task_id);
     118       
     119        if (!ksess) {
     120                if (errno == ENOTSUP) {
     121                        printf("You do not have userspace debugging support "
     122                            "compiled in the kernel.\n");
     123                        printf("Compile kernel with 'Support for userspace debuggers' "
     124                            "(CONFIG_UDEBUG) enabled.\n");
     125                        return errno;
     126                }
     127               
    127128                printf("Error connecting\n");
    128                 printf("async_connect_kbox(%" PRIu64 ") -> %d ", task_id, rc);
    129                 return rc;
    130         }
    131 
    132         phoneid = rc;
    133 
    134         rc = udebug_begin(phoneid);
     129                printf("async_connect_kbox(%" PRIu64 ") -> %d ", task_id, errno);
     130                return errno;
     131        }
     132       
     133        int rc = udebug_begin(ksess);
    135134        if (rc < 0) {
    136135                printf("udebug_begin() -> %d\n", rc);
    137136                return rc;
    138137        }
    139 
     138       
     139        sess = ksess;
    140140        return 0;
    141141}
     
    213213
    214214        /* TODO: See why NULL does not work. */
    215         rc = udebug_thread_read(phoneid, &dummy_buf, 0, &copied, &needed);
     215        rc = udebug_thread_read(sess, &dummy_buf, 0, &copied, &needed);
    216216        if (rc < 0) {
    217217                printf("udebug_thread_read() -> %d\n", rc);
     
    227227        thash_buf = malloc(buf_size);
    228228
    229         rc = udebug_thread_read(phoneid, thash_buf, buf_size, &copied, &needed);
     229        rc = udebug_thread_read(sess, thash_buf, buf_size, &copied, &needed);
    230230        if (rc < 0) {
    231231                printf("udebug_thread_read() -> %d\n", rc);
     
    262262        int rc;
    263263
    264         rc = udebug_areas_read(phoneid, &dummy_buf, 0, &copied, &needed);
     264        rc = udebug_areas_read(sess, &dummy_buf, 0, &copied, &needed);
    265265        if (rc < 0) {
    266266                printf("udebug_areas_read() -> %d\n", rc);
     
    271271        ainfo_buf = malloc(buf_size);
    272272
    273         rc = udebug_areas_read(phoneid, ainfo_buf, buf_size, &copied, &needed);
     273        rc = udebug_areas_read(sess, ainfo_buf, buf_size, &copied, &needed);
    274274        if (rc < 0) {
    275275                printf("udebug_areas_read() -> %d\n", rc);
     
    296296        if (write_core_file) {
    297297                printf("Writing core file '%s'\n", core_file_name);
    298                 rc = elf_core_save(core_file_name, ainfo_buf, n_areas, phoneid);
     298
     299                rc = elf_core_save(core_file_name, ainfo_buf, n_areas, sess,
     300                    &reg_state);
     301
    299302                if (rc != EOK) {
    300303                        printf("Failed writing core file.\n");
     
    316319        int rc;
    317320
    318         rc = udebug_regs_read(phoneid, thash, &istate);
     321        rc = udebug_regs_read(sess, thash, &istate);
    319322        if (rc < 0) {
    320323                printf("Failed reading registers (%d).\n", rc);
     
    324327        pc = istate_get_pc(&istate);
    325328        fp = istate_get_fp(&istate);
     329
     330        /* Save register state for dumping to core file later. */
     331        reg_state = istate;
    326332
    327333        sym_pc = fmt_sym_address(pc);
     
    359365        (void) arg;
    360366
    361         rc = udebug_mem_read(phoneid, &data, addr, sizeof(data));
     367        rc = udebug_mem_read(sess, &data, addr, sizeof(data));
    362368        if (rc < 0) {
    363369                printf("Warning: udebug_mem_read() failed.\n");
     
    430436        int rc;
    431437
    432         rc = udebug_name_read(phoneid, &dummy_buf, 0, &copied, &needed);
     438        rc = udebug_name_read(sess, &dummy_buf, 0, &copied, &needed);
    433439        if (rc < 0)
    434440                return NULL;
     
    436442        name_size = needed;
    437443        name = malloc(name_size + 1);
    438         rc = udebug_name_read(phoneid, name, name_size, &copied, &needed);
     444        rc = udebug_name_read(sess, name, name_size, &copied, &needed);
    439445        if (rc < 0) {
    440446                free(name);
Note: See TracChangeset for help on using the changeset viewer.