⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xenitp.c

📁 xen虚拟机源代码安装包
💻 C
📖 第 1 页 / 共 4 页
字号:
    { XEN_IA64_DEBUG_ON_TC, "tc" },#if 0    { XEN_IA64_DEBUG_ON_KEYS, "keys" },    { XEN_IA64_DEBUG_ON_MOV_TO_CR, "mov_to_cr" },    { XEN_IA64_DEBUG_ON_VHPT, "vhpt" },    { XEN_IA64_DEBUG_ON_IOSAPIC, "iosapic" },#endif    { 0, NULL }};static enum cmd_statuscmd_disp (char *arg){    if (strcmp (arg, "br") == 0)        print_br (cur_ctx);    else if (strcmp (arg, "regs") == 0)        print_regs (cur_ctx);    else if (strcmp (arg, "cr") == 0)        print_cr (cur_ctx);    else if (strcmp (arg, "ar") == 0)        print_ar (cur_ctx);    else if (strcmp (arg, "tr") == 0)        print_tr (cur_ctx);    else if (strcmp (arg, "rr") == 0)        print_rr (cur_ctx);    else if (strcmp (arg, "db") == 0)        print_db (cur_ctx);    else if (strcmp (arg, "psr") == 0) {        printf ("psr:");        print_bits (psr_bits, cur_ctx->regs.psr);        printf ("\n");    }    else if (strcmp (arg, "ipsr") == 0) {        printf ("ipsr:");        print_bits (psr_bits, cur_ctx->regs.cr.ipsr);        printf ("\n");    }    else if (strcmp (arg, "break") == 0) {        int i;        for (i = 0; i < 4; i++)            if (cur_ctx->regs.ibr[2 * i + 1])                printf ("%d: 0x%016lx %s\n", i, cur_ctx->regs.ibr[2 * i],                        (cur_ctx->regs.ibr[2 * i + 1] & (1UL << 63)) ?                        "enabled" : "disabled");        for (i = 0; i < 4; i++)            if (cur_ctx->regs.dbr[2 * i + 1])                printf ("%d: 0x%016lx %s\n", i, cur_ctx->regs.dbr[2 * i],                        (cur_ctx->regs.dbr[2 * i + 1] & (1UL << 63)) ?                        "enabled" : "disabled");    }    else if (strcmp (arg, "domain") == 0) {        xc_dominfo_t dominfo;#ifdef HAVE_DEBUG_OP        xen_ia64_debug_op_t debug_op;        int i;#endif        if (xc_domain_getinfo (xc_handle, domid, 1, &dominfo) < 0) {            perror ("xc_domain_getinfo");            return 0;        }        printf ("id=%d nr_pages=%lu shared_info_frame=%lu max_mem=%luKB\n",                dominfo.domid, dominfo.nr_pages, dominfo.shared_info_frame,                dominfo.max_memkb);        printf ("  nr_online_vcpu=%u max_vcpu_id=%u\n",                dominfo.nr_online_vcpus, dominfo.max_vcpu_id);        printf ("  status:");        if (dominfo.dying)            printf (" dying");        if (dominfo.crashed)            printf (" crashed");        if (dominfo.shutdown)            printf (" shutdown(%u)", dominfo.shutdown_reason);        if (dominfo.paused)            printf (" paused");        if (dominfo.blocked)            printf (" blocked");        if (dominfo.running)            printf (" running");        if (dominfo.hvm)            printf (" hvm");        if (dominfo.debugged)            printf (" debug");        printf ("\n");#ifdef HAVE_DEBUG_OP        if (do_ia64_debug_op (xc_handle, XEN_IA64_DEBUG_OP_GET_FLAGS,                              domid, &debug_op) < 0) {            perror ("xc_domain_getinfo");            return 0;        }        printf ("debug flags: %08lx: ", debug_op.flags);        for (i = 0; debug_flags[i].name; i++)            if (debug_flags[i].bit & debug_op.flags)                printf (" %s", debug_flags[i].name);        printf ("\n");#endif    }    else if (*arg == 0)        printf ("choose among br, regs, cr, ar, tr, rr, db\n");    else {        printf ("cannot disp '%s'\n", arg);        return CMD_ERROR;    }    return CMD_OK;}static enum cmd_statuscmd_bev (char *arg){    xen_ia64_debug_op_t debug_op;    int i;    if (do_ia64_debug_op (xc_handle, XEN_IA64_DEBUG_OP_GET_FLAGS,                          domid, &debug_op) < 0) {        perror ("get debug flags");        return CMD_ERROR;    }    if (arg == NULL || arg[0] == 0) {        printf ("debug flags: %08lx:\n", debug_op.flags);        for (i = 0; debug_flags[i].name; i++)            printf (" %c%s\n",                    (debug_flags[i].bit & debug_op.flags) ? '+' : '-',                    debug_flags[i].name);        return CMD_OK;    }    else {        char *p = strtok ((char *)arg, " ");        while (p != NULL) {            unsigned int flag = 0;            for (i = 0; debug_flags[i].name; i++)                if (strcmp (p, debug_flags[i].name) == 0                    || ((p[0] == '-' || p[0] == '+')                        && strcmp (p + 1, debug_flags[i].name) == 0)) {                    flag = debug_flags[i].bit;                    break;                }            if (flag == 0) {                printf ("unknown event %s\n", p);                return CMD_ERROR;            }            if (p[0] == '-')                debug_op.flags &= ~flag;            else                debug_op.flags |= flag;            p = strtok (NULL, " ");        }        if (do_ia64_debug_op (xc_handle, XEN_IA64_DEBUG_OP_SET_FLAGS,                              domid, &debug_op) < 0) {            perror ("set debug flags");            return CMD_ERROR;        }        /* Disabling force_SS and force_DB requires setting psr.  */        if (vcpu_setcontext (cur_vcpu) < 0)            return CMD_ERROR;        else            return CMD_OK;    }}static enum cmd_statuscmd_set (char *line){    char *reg;    unsigned long *addr;    unsigned long val;    reg = parse_arg (&line);    addr = get_reg_addr (reg);    if (addr == NULL) {        printf ("unknown register %s\n", reg);        return CMD_ERROR;    }    if (parse_expr (&line, &val, 0) < 0)        return CMD_ERROR;    *addr = val;    if (vcpu_setcontext (cur_vcpu) < 0)        return CMD_ERROR;    else        return CMD_OK;}const struct command_desc commands[];static enum cmd_statuscmd_help (char *line){    int i;    for (i = 0; commands[i].name; i++)        printf ("%s -- %s\n", commands[i].name, commands[i].help);    return CMD_OK;}const struct command_desc commands[] = {    { "registers", "display current registers", cmd_registers },    { "sstep", "single step", cmd_sstep },    { "go", "resume execution", cmd_go },    { "quit", "quit debugger", cmd_quit },    { "echo", "display parameters", cmd_echo },    { "disassemble", "disassemble memory", cmd_disassemble },    { "dump", "dump memory", cmd_dump },    { "break", "set a break point", cmd_break },    { "watch", "set a watch point", cmd_watch },    { "cb", "resume until branch", cmd_cb },    { "delete", "delete a break point", cmd_delete },    { "disable", "disable a break point", cmd_disable },    { "enable", "enable a break point", cmd_enable },    { "print", "print an expression", cmd_print },    { "disp", "disp br/regs/cr/ar/tr/rr/db/psr/break/domain", cmd_disp},    { "bev", "break on event", cmd_bev},    { "set", "set reg val", cmd_set},    { "help", "disp help", cmd_help },    { NULL, NULL, NULL }};enum cmd_status do_command (int vcpu, char *line){    char *cmd;    char *args;    int i;    const struct command_desc *desc;    static const struct command_desc *last_desc;    enum cmd_status status;    int flag_ambiguous;    cur_vcpu = vcpu;    cur_ctx = &vcpu_ctx_any[vcpu].c;    /* Handle repeat last-command.  */    if (*line == 0) {        if (last_desc != NULL)            return (*last_desc->cmd)("");        else            return CMD_OK;    }    last_desc = NULL;    cmd = parse_arg (&line);    args = line;    desc = NULL;    flag_ambiguous = 0;    for (i = 0; commands[i].name; i++) {        const char *n = commands[i].name;        char *c = cmd;        while (*n == *c && *n)            n++, c++;        if (*c == 0) {            /* Match.  */            if (desc != NULL) {                if (!flag_ambiguous)                    printf ("ambiguous command: %s", desc->name);                printf (", %s", commands[i].name);                flag_ambiguous = 1;            }            else                desc = &commands[i];        }    }    if (flag_ambiguous) {        printf ("\n");        return CMD_ERROR;    }    else if (!desc) {        printf ("command not found, try help\n");        return CMD_ERROR;    }    status = (*desc->cmd)(args);    if (status == CMD_REPEAT)        last_desc = desc;    return status;}void xenitp (int vcpu){    int ret;    struct sigaction sa;    cur_ctx = &vcpu_ctx_any[vcpu].c;    xc_handle = xc_interface_open (); /* for accessing control interface */    if (xc_domain_setdebugging (xc_handle, domid, 1) != 0)        perror ("setdebugging");    ret = xc_domain_pause (xc_handle, domid);    if (ret < 0) {        perror ("xc_domain_pause");        exit (-1);    }    ret = xc_ia64_vcpu_getcontext (xc_handle, domid, vcpu, cur_ctx);    if (ret < 0) {        perror ("xc_ia64_vcpu_getcontext");        exit (-1);    }    print_ctx (cur_ctx);    /* Catch ctrl-c.  */    sa.sa_handler = &ctrl_c_handler;    sa.sa_flags = 0;    sigemptyset (&sa.sa_mask);    if (sigaction (SIGINT, &sa, NULL) != 0)        perror ("sigaction");    while (1) {        char buf[128];        int len;        printf ("XenITP> ");        fflush (stdout);        if (fgets (buf, sizeof (buf), stdin) == NULL)            break;        len = strlen ((char *)buf);        if (len >= 1 && buf[len - 1] == '\n')            buf[len - 1] = 0;        ret = do_command (vcpu, buf);        if (ret == CMD_QUIT)            break;    }    /* Clear debug bits.  */    if ((cur_ctx->regs.psr & (PSR_SS | PSR_TB | PSR_DB)) != 0) {        cur_ctx->regs.psr &= ~(PSR_SS | PSR_TB | PSR_DB);        cur_ctx->regs.psr |= PSR_DD | PSR_ID;        vcpu_setcontext (cur_vcpu);    }    /* Disable debugging.  */    if (xc_domain_setdebugging (xc_handle, domid, 0) != 0)            perror ("setdebugging");    if (!quit_paused) {        ret = xc_domain_unpause (xc_handle, domid);        if (ret < 0) {            perror ("xc_domain_unpause");            exit (-1);        }    }    xc_interface_close (xc_handle);    if (ret < 0) {        perror ("xc_interface_close");        exit (-1);    }}static void usage (void){    printf ("usage:\n");    printf ("  xenitp <DOMAIN> [VCPU]\n");}int main (int argc, char **argv){    int ch;    static const char *sopts = "h"        ;    static const struct option lopts[] = {        {"help", 0, NULL, 'h'},        {0, 0, 0, 0}    };    int vcpu = 0;    while ((ch = getopt_long (argc, argv, sopts, lopts, NULL)) != -1) {        switch (ch) {        case 'h':            usage ();            exit (-1);        case '?':            fprintf (stderr, "%s --help for more options\n", argv[0]);            exit (-1);        }    }    argv += optind;    argc -= optind;    if (argc < 1 || argc > 2) {        usage ();        exit (-1);    }    domid = atoi (argv[0]);    if (domid == 0) {        fprintf (stderr, "cannot trace dom0\n");        exit (-1);    }    if (argc == 2)        vcpu = atoi (argv[1]);    xenitp (vcpu);    return 0;}/* * Local variables: * mode: C * c-set-style: "BSD" * c-basic-offset: 4 * tab-width: 4 * indent-tabs-mode: nil * End: */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -