2006-06-20 07:34:43 +00:00
|
|
|
/*
|
|
|
|
* Debugger x86_64 specific functions
|
|
|
|
*
|
2008-10-18 17:22:19 +00:00
|
|
|
* Copyright 2004 Vincent Béron
|
2006-06-20 07:34:43 +00:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "debugger.h"
|
|
|
|
|
|
|
|
#if defined(__x86_64__)
|
|
|
|
|
2009-05-01 16:29:10 +00:00
|
|
|
#define STEP_FLAG 0x00000100 /* single step flag */
|
|
|
|
|
2006-06-20 07:34:43 +00:00
|
|
|
static unsigned be_x86_64_get_addr(HANDLE hThread, const CONTEXT* ctx,
|
2006-07-26 09:57:27 +00:00
|
|
|
enum be_cpu_addr bca, ADDRESS64* addr)
|
2006-06-20 07:34:43 +00:00
|
|
|
{
|
2006-07-10 06:59:10 +00:00
|
|
|
addr->Mode = AddrModeFlat;
|
|
|
|
switch (bca)
|
|
|
|
{
|
|
|
|
case be_cpu_addr_pc:
|
|
|
|
addr->Segment = ctx->SegCs;
|
|
|
|
addr->Offset = ctx->Rip;
|
|
|
|
return TRUE;
|
|
|
|
case be_cpu_addr_stack:
|
|
|
|
addr->Segment = ctx->SegSs;
|
|
|
|
addr->Offset = ctx->Rsp;
|
|
|
|
return TRUE;
|
|
|
|
case be_cpu_addr_frame:
|
|
|
|
addr->Segment = ctx->SegSs;
|
|
|
|
addr->Offset = ctx->Rbp;
|
|
|
|
return TRUE;
|
|
|
|
default:
|
|
|
|
addr->Mode = -1;
|
|
|
|
return FALSE;
|
|
|
|
}
|
2006-06-20 07:34:43 +00:00
|
|
|
}
|
|
|
|
|
2006-12-02 16:43:08 +00:00
|
|
|
static unsigned be_x86_64_get_register_info(int regno, enum be_cpu_addr* kind)
|
|
|
|
{
|
|
|
|
/* this is true when running in 32bit mode... and wrong in 64 :-/ */
|
|
|
|
switch (regno)
|
|
|
|
{
|
2007-05-24 08:15:59 +00:00
|
|
|
case CV_AMD64_RIP: *kind = be_cpu_addr_pc; return TRUE;
|
2006-12-02 16:43:08 +00:00
|
|
|
case CV_AMD64_EBP: *kind = be_cpu_addr_frame; return TRUE;
|
|
|
|
case CV_AMD64_ESP: *kind = be_cpu_addr_stack; return TRUE;
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2006-06-20 07:34:43 +00:00
|
|
|
static void be_x86_64_single_step(CONTEXT* ctx, unsigned enable)
|
|
|
|
{
|
2009-05-01 16:29:10 +00:00
|
|
|
if (enable) ctx->EFlags |= STEP_FLAG;
|
|
|
|
else ctx->EFlags &= ~STEP_FLAG;
|
2006-06-20 07:34:43 +00:00
|
|
|
}
|
|
|
|
|
2006-07-10 06:59:10 +00:00
|
|
|
static void be_x86_64_print_context(HANDLE hThread, const CONTEXT* ctx,
|
|
|
|
int all_regs)
|
2006-06-20 07:34:43 +00:00
|
|
|
{
|
2009-05-01 16:28:49 +00:00
|
|
|
static const char flags[] = "aVR-N--ODITSZ-A-P-C";
|
|
|
|
char buf[33];
|
|
|
|
int i;
|
2009-04-08 18:40:35 +00:00
|
|
|
|
2009-05-01 16:28:49 +00:00
|
|
|
strcpy(buf, flags);
|
|
|
|
for (i = 0; buf[i]; i++)
|
|
|
|
if (buf[i] != '-' && !(ctx->EFlags & (1 << (sizeof(flags) - 2 - i))))
|
|
|
|
buf[i] = ' ';
|
2009-04-08 18:40:35 +00:00
|
|
|
|
2009-05-01 16:28:49 +00:00
|
|
|
dbg_printf("Register dump:\n");
|
2009-04-08 18:40:35 +00:00
|
|
|
dbg_printf(" rip:%016lx rsp:%016lx rbp:%016lx eflags:%08x (%s)\n",
|
|
|
|
ctx->Rip, ctx->Rsp, ctx->Rbp, ctx->EFlags, buf);
|
|
|
|
dbg_printf(" rax:%016lx rbx:%016lx rcx:%016lx rdx:%016lx\n",
|
|
|
|
ctx->Rax, ctx->Rbx, ctx->Rcx, ctx->Rdx);
|
|
|
|
dbg_printf(" rsi:%016lx rdi:%016lx r8:%016lx r9:%016lx r10:%016lx\n",
|
|
|
|
ctx->Rsi, ctx->Rdi, ctx->R8, ctx->R9, ctx->R10 );
|
|
|
|
dbg_printf(" r11:%016lx r12:%016lx r13:%016lx r14:%016lx r15:%016lx\n",
|
|
|
|
ctx->R11, ctx->R12, ctx->R13, ctx->R14, ctx->R15 );
|
|
|
|
|
|
|
|
if (all_regs) dbg_printf( "Floating point x86_64 dump not implemented\n" );
|
2006-06-20 07:34:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void be_x86_64_print_segment_info(HANDLE hThread, const CONTEXT* ctx)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct dbg_internal_var be_x86_64_ctx[] =
|
|
|
|
{
|
2006-06-30 19:37:41 +00:00
|
|
|
{CV_AMD64_AL, "AL", (DWORD*)FIELD_OFFSET(CONTEXT, Rax), dbg_itype_unsigned_char_int},
|
|
|
|
{CV_AMD64_BL, "BL", (DWORD*)FIELD_OFFSET(CONTEXT, Rbx), dbg_itype_unsigned_char_int},
|
|
|
|
{CV_AMD64_CL, "CL", (DWORD*)FIELD_OFFSET(CONTEXT, Rcx), dbg_itype_unsigned_char_int},
|
|
|
|
{CV_AMD64_DL, "DL", (DWORD*)FIELD_OFFSET(CONTEXT, Rdx), dbg_itype_unsigned_char_int},
|
|
|
|
{CV_AMD64_AH, "AH", (DWORD*)(FIELD_OFFSET(CONTEXT, Rax)+1), dbg_itype_unsigned_char_int},
|
|
|
|
{CV_AMD64_BH, "BH", (DWORD*)(FIELD_OFFSET(CONTEXT, Rbx)+1), dbg_itype_unsigned_char_int},
|
|
|
|
{CV_AMD64_CH, "CH", (DWORD*)(FIELD_OFFSET(CONTEXT, Rcx)+1), dbg_itype_unsigned_char_int},
|
|
|
|
{CV_AMD64_DH, "DH", (DWORD*)(FIELD_OFFSET(CONTEXT, Rdx)+1), dbg_itype_unsigned_char_int},
|
|
|
|
{CV_AMD64_AX, "AX", (DWORD*)FIELD_OFFSET(CONTEXT, Rax), dbg_itype_unsigned_short_int},
|
|
|
|
{CV_AMD64_BX, "BX", (DWORD*)FIELD_OFFSET(CONTEXT, Rbx), dbg_itype_unsigned_short_int},
|
|
|
|
{CV_AMD64_CX, "CX", (DWORD*)FIELD_OFFSET(CONTEXT, Rcx), dbg_itype_unsigned_short_int},
|
|
|
|
{CV_AMD64_DX, "DX", (DWORD*)FIELD_OFFSET(CONTEXT, Rdx), dbg_itype_unsigned_short_int},
|
|
|
|
{CV_AMD64_SP, "SP", (DWORD*)FIELD_OFFSET(CONTEXT, Rsp), dbg_itype_unsigned_short_int},
|
|
|
|
{CV_AMD64_BP, "BP", (DWORD*)FIELD_OFFSET(CONTEXT, Rbp), dbg_itype_unsigned_short_int},
|
|
|
|
{CV_AMD64_SI, "SI", (DWORD*)FIELD_OFFSET(CONTEXT, Rsi), dbg_itype_unsigned_short_int},
|
|
|
|
{CV_AMD64_DI, "DI", (DWORD*)FIELD_OFFSET(CONTEXT, Rdi), dbg_itype_unsigned_short_int},
|
|
|
|
{CV_AMD64_EAX, "EAX", (DWORD*)FIELD_OFFSET(CONTEXT, Rax), dbg_itype_unsigned_int},
|
|
|
|
{CV_AMD64_EBX, "EBX", (DWORD*)FIELD_OFFSET(CONTEXT, Rbx), dbg_itype_unsigned_int},
|
|
|
|
{CV_AMD64_ECX, "ECX", (DWORD*)FIELD_OFFSET(CONTEXT, Rcx), dbg_itype_unsigned_int},
|
|
|
|
{CV_AMD64_EDX, "EDX", (DWORD*)FIELD_OFFSET(CONTEXT, Rdx), dbg_itype_unsigned_int},
|
|
|
|
{CV_AMD64_ESP, "ESP", (DWORD*)FIELD_OFFSET(CONTEXT, Rsp), dbg_itype_unsigned_int},
|
|
|
|
{CV_AMD64_EBP, "EBP", (DWORD*)FIELD_OFFSET(CONTEXT, Rbp), dbg_itype_unsigned_int},
|
|
|
|
{CV_AMD64_ESI, "ESI", (DWORD*)FIELD_OFFSET(CONTEXT, Rsi), dbg_itype_unsigned_int},
|
|
|
|
{CV_AMD64_EDI, "EDI", (DWORD*)FIELD_OFFSET(CONTEXT, Rdi), dbg_itype_unsigned_int},
|
|
|
|
{CV_AMD64_ES, "ES", (DWORD*)FIELD_OFFSET(CONTEXT, SegEs), dbg_itype_unsigned_short_int},
|
|
|
|
{CV_AMD64_CS, "CS", (DWORD*)FIELD_OFFSET(CONTEXT, SegCs), dbg_itype_unsigned_short_int},
|
|
|
|
{CV_AMD64_SS, "SS", (DWORD*)FIELD_OFFSET(CONTEXT, SegSs), dbg_itype_unsigned_short_int},
|
|
|
|
{CV_AMD64_DS, "DS", (DWORD*)FIELD_OFFSET(CONTEXT, SegDs), dbg_itype_unsigned_short_int},
|
|
|
|
{CV_AMD64_FS, "FS", (DWORD*)FIELD_OFFSET(CONTEXT, SegFs), dbg_itype_unsigned_short_int},
|
|
|
|
{CV_AMD64_GS, "GS", (DWORD*)FIELD_OFFSET(CONTEXT, SegGs), dbg_itype_unsigned_short_int},
|
|
|
|
{CV_AMD64_FLAGS, "FLAGS", (DWORD*)FIELD_OFFSET(CONTEXT, EFlags), dbg_itype_unsigned_short_int},
|
|
|
|
{CV_AMD64_EFLAGS, "EFLAGS", (DWORD*)FIELD_OFFSET(CONTEXT, EFlags), dbg_itype_unsigned_int},
|
|
|
|
{CV_AMD64_RIP, "RIP", (DWORD*)FIELD_OFFSET(CONTEXT, Rip), dbg_itype_unsigned_int},
|
|
|
|
{CV_AMD64_RAX, "RAX", (DWORD*)FIELD_OFFSET(CONTEXT, Rax), dbg_itype_unsigned_long_int},
|
|
|
|
{CV_AMD64_RBX, "RBX", (DWORD*)FIELD_OFFSET(CONTEXT, Rbx), dbg_itype_unsigned_long_int},
|
|
|
|
{CV_AMD64_RCX, "RCX", (DWORD*)FIELD_OFFSET(CONTEXT, Rcx), dbg_itype_unsigned_long_int},
|
|
|
|
{CV_AMD64_RDX, "RDX", (DWORD*)FIELD_OFFSET(CONTEXT, Rdx), dbg_itype_unsigned_long_int},
|
|
|
|
{CV_AMD64_RSP, "RSP", (DWORD*)FIELD_OFFSET(CONTEXT, Rsp), dbg_itype_unsigned_long_int},
|
|
|
|
{CV_AMD64_RBP, "RBP", (DWORD*)FIELD_OFFSET(CONTEXT, Rbp), dbg_itype_unsigned_long_int},
|
|
|
|
{CV_AMD64_RSI, "RSI", (DWORD*)FIELD_OFFSET(CONTEXT, Rsi), dbg_itype_unsigned_long_int},
|
|
|
|
{CV_AMD64_RDI, "RDI", (DWORD*)FIELD_OFFSET(CONTEXT, Rdi), dbg_itype_unsigned_long_int},
|
|
|
|
{CV_AMD64_R8, "R8", (DWORD*)FIELD_OFFSET(CONTEXT, R8), dbg_itype_unsigned_long_int},
|
|
|
|
{CV_AMD64_R9, "R9", (DWORD*)FIELD_OFFSET(CONTEXT, R9), dbg_itype_unsigned_long_int},
|
|
|
|
{CV_AMD64_R10, "R10", (DWORD*)FIELD_OFFSET(CONTEXT, R10), dbg_itype_unsigned_long_int},
|
|
|
|
{CV_AMD64_R11, "R11", (DWORD*)FIELD_OFFSET(CONTEXT, R11), dbg_itype_unsigned_long_int},
|
|
|
|
{CV_AMD64_R12, "R12", (DWORD*)FIELD_OFFSET(CONTEXT, R12), dbg_itype_unsigned_long_int},
|
|
|
|
{CV_AMD64_R13, "R13", (DWORD*)FIELD_OFFSET(CONTEXT, R13), dbg_itype_unsigned_long_int},
|
|
|
|
{CV_AMD64_R14, "R14", (DWORD*)FIELD_OFFSET(CONTEXT, R14), dbg_itype_unsigned_long_int},
|
|
|
|
{CV_AMD64_R15, "R15", (DWORD*)FIELD_OFFSET(CONTEXT, R15), dbg_itype_unsigned_long_int},
|
2006-06-20 07:34:43 +00:00
|
|
|
{0, NULL, 0, dbg_itype_none}
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct dbg_internal_var* be_x86_64_init_registers(CONTEXT* ctx)
|
|
|
|
{
|
2006-06-30 19:37:41 +00:00
|
|
|
struct dbg_internal_var* div;
|
|
|
|
|
|
|
|
for (div = be_x86_64_ctx; div->name; div++)
|
|
|
|
div->pval = (DWORD*)((char*)ctx + (DWORD_PTR)div->pval);
|
2006-06-20 07:34:43 +00:00
|
|
|
return be_x86_64_ctx;
|
|
|
|
}
|
|
|
|
|
2006-07-10 06:59:10 +00:00
|
|
|
static unsigned be_x86_64_is_step_over_insn(const void* insn)
|
2006-06-20 07:34:43 +00:00
|
|
|
{
|
2006-07-10 06:59:10 +00:00
|
|
|
dbg_printf("not done step_over_insn\n");
|
2006-06-20 07:34:43 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2006-07-10 06:59:10 +00:00
|
|
|
static unsigned be_x86_64_is_function_return(const void* insn)
|
2006-06-20 07:34:43 +00:00
|
|
|
{
|
2006-07-10 06:59:10 +00:00
|
|
|
dbg_printf("not done is_function_return\n");
|
2006-06-20 07:34:43 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2006-07-10 06:59:10 +00:00
|
|
|
static unsigned be_x86_64_is_break_insn(const void* insn)
|
2006-06-20 07:34:43 +00:00
|
|
|
{
|
2006-07-10 06:59:10 +00:00
|
|
|
dbg_printf("not done is_break_insn\n");
|
2006-06-20 07:34:43 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2006-07-26 09:57:27 +00:00
|
|
|
static unsigned be_x86_64_is_func_call(const void* insn, ADDRESS64* callee)
|
2006-06-20 07:34:43 +00:00
|
|
|
{
|
2006-07-10 06:59:10 +00:00
|
|
|
dbg_printf("not done is_func_call\n");
|
2006-06-20 07:34:43 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2006-07-26 09:57:27 +00:00
|
|
|
static void be_x86_64_disasm_one_insn(ADDRESS64* addr, int display)
|
2006-06-20 07:34:43 +00:00
|
|
|
{
|
|
|
|
dbg_printf("Disasm NIY\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned be_x86_64_insert_Xpoint(HANDLE hProcess, const struct be_process_io* pio,
|
|
|
|
CONTEXT* ctx, enum be_xpoint_type type,
|
|
|
|
void* addr, unsigned long* val, unsigned size)
|
|
|
|
{
|
2006-07-10 06:59:10 +00:00
|
|
|
dbg_printf("not done insert_Xpoint\n");
|
2006-06-20 07:34:43 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned be_x86_64_remove_Xpoint(HANDLE hProcess, const struct be_process_io* pio,
|
|
|
|
CONTEXT* ctx, enum be_xpoint_type type,
|
|
|
|
void* addr, unsigned long val, unsigned size)
|
|
|
|
{
|
2006-07-10 06:59:10 +00:00
|
|
|
dbg_printf("not done remove_Xpoint\n");
|
2006-06-20 07:34:43 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned be_x86_64_is_watchpoint_set(const CONTEXT* ctx, unsigned idx)
|
|
|
|
{
|
2006-07-10 06:59:10 +00:00
|
|
|
dbg_printf("not done is_watchpoint_set\n");
|
2006-06-20 07:34:43 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void be_x86_64_clear_watchpoint(CONTEXT* ctx, unsigned idx)
|
|
|
|
{
|
2006-07-10 06:59:10 +00:00
|
|
|
dbg_printf("not done clear_watchpoint\n");
|
2006-06-20 07:34:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int be_x86_64_adjust_pc_for_break(CONTEXT* ctx, BOOL way)
|
|
|
|
{
|
2006-07-10 06:59:10 +00:00
|
|
|
if (way)
|
|
|
|
{
|
|
|
|
ctx->Rip--;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
ctx->Rip++;
|
|
|
|
return 1;
|
2006-06-20 07:34:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int be_x86_64_fetch_integer(const struct dbg_lvalue* lvalue, unsigned size,
|
|
|
|
unsigned ext_sign, LONGLONG* ret)
|
|
|
|
{
|
2006-07-10 06:59:10 +00:00
|
|
|
dbg_printf("not done fetch_integer\n");
|
2006-06-20 07:34:43 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int be_x86_64_fetch_float(const struct dbg_lvalue* lvalue, unsigned size,
|
|
|
|
long double* ret)
|
|
|
|
{
|
2006-07-10 06:59:10 +00:00
|
|
|
dbg_printf("not done fetch_float\n");
|
2006-06-20 07:34:43 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct backend_cpu be_x86_64 =
|
|
|
|
{
|
|
|
|
be_cpu_linearize,
|
|
|
|
be_cpu_build_addr,
|
|
|
|
be_x86_64_get_addr,
|
2006-12-02 16:43:08 +00:00
|
|
|
be_x86_64_get_register_info,
|
2006-06-20 07:34:43 +00:00
|
|
|
be_x86_64_single_step,
|
|
|
|
be_x86_64_print_context,
|
|
|
|
be_x86_64_print_segment_info,
|
|
|
|
be_x86_64_init_registers,
|
|
|
|
be_x86_64_is_step_over_insn,
|
|
|
|
be_x86_64_is_function_return,
|
|
|
|
be_x86_64_is_break_insn,
|
|
|
|
be_x86_64_is_func_call,
|
|
|
|
be_x86_64_disasm_one_insn,
|
|
|
|
be_x86_64_insert_Xpoint,
|
|
|
|
be_x86_64_remove_Xpoint,
|
|
|
|
be_x86_64_is_watchpoint_set,
|
|
|
|
be_x86_64_clear_watchpoint,
|
|
|
|
be_x86_64_adjust_pc_for_break,
|
|
|
|
be_x86_64_fetch_integer,
|
|
|
|
be_x86_64_fetch_float,
|
|
|
|
};
|
|
|
|
#endif
|