Hi All,

I am relatively new to QEMU. I am using the latest version from git and I
am trying to add the necessary code to QEMU to perform a dynamic
instruction trace of guest code.  My basic approach is to add a op call to
a function I have created with the parameters PC and opcode into the
disassmebly for each instruction.  When this function is subsequently
called at the beginning of each instruction's execution it should accept
these two parameters and simply printf them right now.  I am doing this
inside of translate.c in the disas_insn function.


When i do not pass any parameters to the output function and just simply
print a message, everything executes fine.  However, If i attempt to add
parameters I get a segfault.  Specifically, it happens inside of
tcg_optimize with the following error:

Program received signal SIGSEGV, Segmentation fault.
0x0000555555657aea in tcg_constant_folding (tcg_op_defs=0x5555558e0f80,
    args=0x5555578f2110, tcg_opc_ptr=<optimized out>, s=0x5555578ea980)
    at /home/lguckert/qemu/tcg/optimize.c:541
541                     if (temps[args[i]].state == TCG_TEMP_COPY) {

where i is 1 (the first parameter I pass) and args[i] is the pc value.  My
first question is why its using the parameter value as an index into temps.
 It must be something I'm misunderstanding about parameter passing.

any help would be greatly appreciated.

Here is the code modifications I have made (NOTE i have tried many
variations on the sizemask, parameter types, parameter vals, etc. to no
avail).

IN TRANSLATE.C:
DISAS_INSN FUNCTION:

++    TCGv t0 = tcg_temp_new();
++    TCGv t1 = tcg_temp_new();
++    t0= pc_start; t1 = b;
++    tcg_gen_helper_fast_trace(t0,t1);

    /* now check op code */
 reswitch:
    switch(b) {
    case 0x0f:


IN TCG/TCG-OP.H ADDED (here if I pass 0 args, it executes fine and prints
dummy message correct number of times):
static inline void tcg_gen_helper_fast_trace(target_ulong pc,int op)
{
        int sizemask = 0;
TCGArg args[2];
#ifdef TARGET_X86_64
 sizemask |= tcg_gen_sizemask(0,0,0);
 sizemask |= tcg_gen_sizemask(1,1,0);
 sizemask |= tcg_gen_sizemask(2,1,0);
    args[0] = GET_TCGV_I64(pc);
    args[1] = GET_TCGV_I64(op);
tcg_gen_helperN(tcg_helper_fast_trace64, 0, sizemask, ((TCGArg)(-1)),2 ,
args);
#else
 sizemask |= tcg_gen_sizemask(0,0,0);
 sizemask |= tcg_gen_sizemask(1,0,0);
 sizemask |= tcg_gen_sizemask(2,0,0);
    args[0] = GET_TCGV_I32(pc);
    args[1] = GET_TCGV_I32(op);
tcg_gen_helperN(tcg_helper_fast_trace32, 0, sizemask, ((TCGArg)(-1)),2 ,
args);
#endif
}

i have declared the functions tcg_helper_fast_trace32 and
tcg_helper_fast_trace64 in tcg/tcg-runtime.h

IN TCG-RUNTIME.H ADDED
void tcg_helper_fast_trace64(uint64_t arg1, uint64_t arg2)
{
        printf(PC = %016lx\t OPCODE:%08x\n", (unsigned long
int)arg1,(unsigned int)arg2);
}
void tcg_helper_fast_trace32(uint32_t arg1, uint32_t arg2)
{
    printf("PC = %016lx\t OPCODE = %08x\n", (unsigned long
int)arg1,(unsigned int)arg2);
}

thanks,
Lauren

Reply via email to