pike.git / src / code / amd64.c

version» Context lines:

pike.git/src/code/amd64.c:5098:    break;    case 0xc0:    sprintf(buf, "%s", amd64_describe_reg(rex & 1, modrm & 7));    break;    }    return bytes;   }      void amd64_disassemble_code(PIKE_OPCODE_T *pc, size_t len)   { +  struct string_builder buf;    size_t pos; -  +  +  init_string_builder(&buf, 0);    for (pos = 0; pos < len;) {    size_t op_start = pos;    size_t i;    const char *opcode = NULL;    const char *params[4] = { NULL, NULL, NULL, NULL, };    int legacy_prefix[4] = { 0, 0, 0, 0 };    int byte;    int rex = 0;    int modrm = 0;    struct amd64_opcode *table = amd64_opcodes[0];    struct amd64_opcode *op;    char buffers[4][256];    -  + #if 0    fprintf(stderr, "%p:\t", pc + pos); -  + #endif       // Handle prefixes.    while(1) {    byte = pc[pos++];    op = table + byte;    if (op->flags & OP_PREFIX) {    legacy_prefix[op->flags & 3] = byte;    continue;    }    break;
pike.git/src/code/amd64.c:5171:    buffers[1][0] = 0;    }    if (op->flags & (OP_8|OP_S8)) {    sprintf(buffers[1] + strlen(buffers[1]), "$%+d", ((signed char *)pc)[pos++]);    } else {    sprintf(buffers[1] + strlen(buffers[1]), "$");    pos += amd64_readint32(pc + pos, buffers[1] + strlen(buffers[1]));    }    } else if (op->flags & OP_PCREL) {    INT32 val; -  if (!params[1]) { -  params[1] = buffers[1]; -  buffers[1][0] = 0; +  if (!params[0]) { +  params[0] = buffers[0]; +  buffers[0][0] = 0;    }    if (op->flags & (OP_8|OP_S8)) {    val = ((signed char *)pc)[pos++];    } else {    val = ((INT32 *)(pc + pos))[0];    pos += 4;    } -  sprintf(buffers[1] + strlen(buffers[1]), "%p", pc + (pos + val)); +  sprintf(buffers[0] + strlen(buffers[0]), "%p", pc + (pos + val));    }       if (op->flags & OP_B_RM) {    /* Swap the two parameters. */    const char *tmp = params[0];    params[0] = params[1];    params[1] = tmp;    }    -  + #if 1 +  string_builder_append_disassembly(&buf, pc + op_start, pc + pos, +  opcode, params, NULL); + #else    if (opcode) {    fprintf(stderr, "%s", opcode);       if (params[0]) {    fprintf(stderr, " %s", params[0]);    if (params[1]) {    fprintf(stderr, ",");    }    }   
pike.git/src/code/amd64.c:5214:    } else {    fprintf(stderr, ".byte 0x%02x", byte);    }    for(i = 0; (op_start + i) < pos; i++) {    if (!(i & 7)) {    fprintf(stderr, "\n\t#");    }    fprintf(stderr, " %02x", pc[op_start + i]);    }    fprintf(stderr, "\n"); + #endif    } -  + #if 1 +  string_builder_putchar(&buf, 0); +  fprintf(stderr, "%s", buf.s->str); +  free_string_builder(&buf); + #endif   }