Beispiel #1
0
static int process_cpu_info(QemuHttpConnection *conn) {
    CPUState *env;
    QList *cpu_list;
    int i;

    cpu_list = qlist_new();

    for (env = first_cpu; env != NULL; env = env->next_cpu) {
        QDict *cpu;
        QObject *obj;

        obj = qobject_from_jsonf("{ 'CPU': %d }", env->cpu_index);

        cpu = qobject_to_qdict(obj);

        qdict_put(cpu, "eip", qint_from_int(env->eip + env->segs[R_CS].base));
        qdict_put(cpu, "eax", qint_from_int(EAX));
        qdict_put(cpu, "ebx", qint_from_int(EBX));
        qdict_put(cpu, "ecx", qint_from_int(ECX));
        qdict_put(cpu, "edx", qint_from_int(EDX));
        qdict_put(cpu, "esp", qint_from_int(ESP));
        qdict_put(cpu, "ebp", qint_from_int(EBP));
        qdict_put(cpu, "esi", qint_from_int(ESI));
        qdict_put(cpu, "edi", qint_from_int(EDI));

        qdict_put(cpu, "dt", qint_from_int(dev_time));
        qdict_put(cpu, "qt", qint_from_int(qemu_time));

#ifdef CONFIG_PROFILER
        qdict_put(cpu, "tb_count", qint_from_int(tcg_ctx.tb_count));
        qdict_put(cpu, "tb_count1", qint_from_int(tcg_ctx.tb_count1));
        qdict_put(cpu, "op_count", qint_from_int(tcg_ctx.op_count));
        qdict_put(cpu, "op_count_max", qint_from_int(tcg_ctx.op_count_max));
        qdict_put(cpu, "temp_count", qint_from_int(tcg_ctx.temp_count));
        qdict_put(cpu, "temp_count_max", qint_from_int(tcg_ctx.temp_count_max));
        qdict_put(cpu, "del_op_count", qint_from_int(tcg_ctx.del_op_count));
        qdict_put(cpu, "code_in_len", qint_from_int(tcg_ctx.code_in_len));
        qdict_put(cpu, "code_out_len", qint_from_int(tcg_ctx.code_out_len));
        qdict_put(cpu, "interm_time", qint_from_int(tcg_ctx.interm_time));
        qdict_put(cpu, "code_time", qint_from_int(tcg_ctx.code_time));
        qdict_put(cpu, "la_time", qint_from_int(tcg_ctx.la_time));
        qdict_put(cpu, "restore_count", qint_from_int(tcg_ctx.restore_count));
        qdict_put(cpu, "restore_time", qint_from_int(tcg_ctx.restore_time));

        for (i = INDEX_op_end; i < NB_OPS; i++) {
            qdict_put(cpu, tcg_op_defs[i].name, qint_from_int(tcg_table_op_count[i]));
        }
#endif

        qlist_append(cpu_list, cpu);
    }

    int st = 0;
    st = respond_with_json(conn, QOBJECT(cpu_list));
    qobject_decref(QOBJECT(cpu_list));

    return st;
}
Beispiel #2
0
static int process_jit_info(QemuHttpConnection *conn) {
    int i;
    TranslationBlock *tb;

    QList *res = qlist_new();
    for (i = 0; i < nb_tbs; i++) {
        tb = &tbs[i];

        QList *item = qlist_new();
        qlist_append(item, qint_from_int(tb->pc));
        qlist_append(item, qint_from_int(tb->size));
        qlist_append(item, qint_from_int(tb->flags));
        qlist_append(item, qint_from_int(tb->page_addr[1] != -1 ? 1 : 0));
        qlist_append(item, qint_from_int(tb->tb_next_offset[0]));
        qlist_append(item, qint_from_int(tb->tb_next_offset[1]));

        qlist_append(res, item);
    }

    int st = 0;
    st = respond_with_json(conn, QOBJECT(res));
    qobject_decref(QOBJECT(res));

    return st;
}
Beispiel #3
0
static int process_memory_info(QemuHttpConnection *conn) {
    int l1, l2;
    int st;
    uint32_t pgd, pde, pte;
    int buf_size;
    char buf[128];
    CPUState *env = first_cpu;

    QList *res = qlist_new();

    if (!(env->cr[0] & CR0_PG_MASK))
        goto out;

    if (env->cr[4] & CR4_PAE_MASK)
        goto out;

    pgd = env->cr[3] & ~0xfff;
    for (l1 = 0; l1 < 1024; ++l1) {
        cpu_physical_memory_read(pgd + l1 * 4, &pde, 4);
        pde = le32_to_cpu(pde);
        if (pde & PG_PRESENT_MASK) {
            /* 4kb pages */
            if (!(pde & PG_PSE_MASK) || !(env->cr[4] & CR4_PSE_MASK)) {
                for (l2 = 0; l2 < 1024; ++l2) {
                    cpu_physical_memory_read((pde & ~0xfff) + l2 * 4, &pte, 4);
                    pte = le32_to_cpu(pte);
                    if (pte & PG_PRESENT_MASK) {
                        buf_size = snprintf(buf, sizeof(buf),
                                            "%02X (%02X) (%c%c%c%c%c%c%c%c%c)",
                                            (l1 << 22) + (l2 << 12), (pde & ~0xfff) + l2 * 4,
                                            pte & PG_NX_MASK ? 'X' : '-',
                                            pte & PG_GLOBAL_MASK ? 'G' : '-',
                                            pte & PG_PSE_MASK ? 'P' : '-',
                                            pte & PG_DIRTY_MASK ? 'D' : '-',
                                            pte & PG_ACCESSED_MASK ? 'A' : '-',
                                            pte & PG_PCD_MASK ? 'C' : '-',
                                            pte & PG_PWT_MASK ? 'T' : '-',
                                            pte & PG_USER_MASK ? 'U' : '-',
                                            pte & PG_RW_MASK ? 'W' : '-');
                        buf[buf_size] = 0;
                        qlist_append(res, qstring_from_str(buf));
                    }
                }
            }
        }
    }

out:
    st = respond_with_json(conn, QOBJECT(res));
    qobject_decref(QOBJECT(res));

    return st;
}
Beispiel #4
0
static int process_irq_info(QemuHttpConnection *conn) {
    int i;
    int64_t count;

    QList *res = qlist_new();
    for (i = 0; i < 16; ++i) {
        count = irq_count[i];
        qlist_append(res, qint_from_int(count));
    }

    int st = 0;
    st = respond_with_json(conn, QOBJECT(res));
    qobject_decref(QOBJECT(res));

    return st;
}
Beispiel #5
0
static int process_disas_info(QemuHttpConnection *conn) {
    TranslationBlock *tb;
    DisasBuffer disas_buf = { {0}, 0 };

    QList *res = qlist_new();
    tb = &tbs[0];

    disassemble_to_buffer(tb, &disas_buf);
    qlist_append(res, qstring_from_str(disas_buf.buffer));

    int st = 0;
    st = respond_with_json(conn, QOBJECT(res));
    qobject_decref(QOBJECT(res));

    return st;
}
Beispiel #6
0
static void qobject_is_equal_list_test(void)
{
    QList *list_0, *list_1, *list_cloned;
    QList *list_reordered, *list_longer, *list_shorter;

    list_0 = qlist_new();
    list_1 = qlist_new();
    list_reordered = qlist_new();
    list_longer = qlist_new();
    list_shorter = qlist_new();

    qlist_append_int(list_0, 1);
    qlist_append_int(list_0, 2);
    qlist_append_int(list_0, 3);

    qlist_append_int(list_1, 1);
    qlist_append_int(list_1, 2);
    qlist_append_int(list_1, 3);

    qlist_append_int(list_reordered, 1);
    qlist_append_int(list_reordered, 3);
    qlist_append_int(list_reordered, 2);

    qlist_append_int(list_longer, 1);
    qlist_append_int(list_longer, 2);
    qlist_append_int(list_longer, 3);
    qlist_append_null(list_longer);

    qlist_append_int(list_shorter, 1);
    qlist_append_int(list_shorter, 2);

    list_cloned = qlist_copy(list_0);

    check_equal(list_0, list_1, list_cloned);
    check_unequal(list_0, list_reordered, list_longer, list_shorter);

    /* With a NaN in it, the list should no longer compare equal to
     * itself */
    qlist_append(list_0, qnum_from_double(NAN));
    g_assert(qobject_is_equal(QOBJECT(list_0), QOBJECT(list_0)) == false);

    free_all(list_0, list_1, list_cloned, list_reordered, list_longer,
             list_shorter);
}
Beispiel #7
0
static void qlist_append_test(void)
{
    QInt *qi;
    QList *qlist;
    QListEntry *entry;

    qi = qint_from_int(42);

    qlist = qlist_new();
    qlist_append(qlist, qi);

    entry = QTAILQ_FIRST(&qlist->head);
    g_assert(entry != NULL);
    g_assert(entry->value == QOBJECT(qi));

    // destroy doesn't exist yet
    QDECREF(qi);
    g_free(entry);
    g_free(qlist);
}
Beispiel #8
0
static void qdict_flatten_test(void)
{
    QList *e_1 = qlist_new();
    QList *e = qlist_new();
    QDict *e_1_2 = qdict_new();
    QDict *f = qdict_new();
    QList *y = qlist_new();
    QDict *z = qdict_new();
    QDict *root = qdict_new();

    /*
     * Test the flattening of
     *
     * {
     *     "e": [
     *         42,
     *         [
     *             23,
     *             66,
     *             {
     *                 "a": 0,
     *                 "b": 1
     *             }
     *         ]
     *     ],
     *     "f": {
     *         "c": 2,
     *         "d": 3,
     *     },
     *     "g": 4,
     *     "y": [{}],
     *     "z": {"a": []}
     * }
     *
     * to
     *
     * {
     *     "e.0": 42,
     *     "e.1.0": 23,
     *     "e.1.1": 66,
     *     "e.1.2.a": 0,
     *     "e.1.2.b": 1,
     *     "f.c": 2,
     *     "f.d": 3,
     *     "g": 4,
     *     "y.0": {},
     *     "z.a": []
     * }
     */

    qdict_put_int(e_1_2, "a", 0);
    qdict_put_int(e_1_2, "b", 1);

    qlist_append_int(e_1, 23);
    qlist_append_int(e_1, 66);
    qlist_append(e_1, e_1_2);
    qlist_append_int(e, 42);
    qlist_append(e, e_1);

    qdict_put_int(f, "c", 2);
    qdict_put_int(f, "d", 3);

    qlist_append(y, qdict_new());

    qdict_put(z, "a", qlist_new());

    qdict_put(root, "e", e);
    qdict_put(root, "f", f);
    qdict_put_int(root, "g", 4);
    qdict_put(root, "y", y);
    qdict_put(root, "z", z);

    qdict_flatten(root);

    g_assert(qdict_get_int(root, "e.0") == 42);
    g_assert(qdict_get_int(root, "e.1.0") == 23);
    g_assert(qdict_get_int(root, "e.1.1") == 66);
    g_assert(qdict_get_int(root, "e.1.2.a") == 0);
    g_assert(qdict_get_int(root, "e.1.2.b") == 1);
    g_assert(qdict_get_int(root, "f.c") == 2);
    g_assert(qdict_get_int(root, "f.d") == 3);
    g_assert(qdict_get_int(root, "g") == 4);
    g_assert(!qdict_size(qdict_get_qdict(root, "y.0")));
    g_assert(qlist_empty(qdict_get_qlist(root, "z.a")));

    g_assert(qdict_size(root) == 10);

    qobject_unref(root);
}