2 * Debugger x86_64 specific functions
4 * Copyright 2004 Vincent BĂ©ron
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #if defined(__x86_64__)
25 static unsigned be_x86_64_get_addr(HANDLE hThread, const CONTEXT* ctx,
26 enum be_cpu_addr bca, ADDRESS64* addr)
28 addr->Mode = AddrModeFlat;
32 addr->Segment = ctx->SegCs;
33 addr->Offset = ctx->Rip;
35 case be_cpu_addr_stack:
36 addr->Segment = ctx->SegSs;
37 addr->Offset = ctx->Rsp;
39 case be_cpu_addr_frame:
40 addr->Segment = ctx->SegSs;
41 addr->Offset = ctx->Rbp;
49 static unsigned be_x86_64_get_register_info(int regno, enum be_cpu_addr* kind)
51 /* this is true when running in 32bit mode... and wrong in 64 :-/ */
54 case CV_AMD64_RIP: *kind = be_cpu_addr_pc; return TRUE;
55 case CV_AMD64_EBP: *kind = be_cpu_addr_frame; return TRUE;
56 case CV_AMD64_ESP: *kind = be_cpu_addr_stack; return TRUE;
61 static void be_x86_64_single_step(CONTEXT* ctx, unsigned enable)
63 dbg_printf("not done single_step\n");
66 static void be_x86_64_print_context(HANDLE hThread, const CONTEXT* ctx,
69 dbg_printf("Context printing for x86_64 not done yet\n");
72 static void be_x86_64_print_segment_info(HANDLE hThread, const CONTEXT* ctx)
76 static struct dbg_internal_var be_x86_64_ctx[] =
78 {CV_AMD64_AL, "AL", (DWORD*)FIELD_OFFSET(CONTEXT, Rax), dbg_itype_unsigned_char_int},
79 {CV_AMD64_BL, "BL", (DWORD*)FIELD_OFFSET(CONTEXT, Rbx), dbg_itype_unsigned_char_int},
80 {CV_AMD64_CL, "CL", (DWORD*)FIELD_OFFSET(CONTEXT, Rcx), dbg_itype_unsigned_char_int},
81 {CV_AMD64_DL, "DL", (DWORD*)FIELD_OFFSET(CONTEXT, Rdx), dbg_itype_unsigned_char_int},
82 {CV_AMD64_AH, "AH", (DWORD*)(FIELD_OFFSET(CONTEXT, Rax)+1), dbg_itype_unsigned_char_int},
83 {CV_AMD64_BH, "BH", (DWORD*)(FIELD_OFFSET(CONTEXT, Rbx)+1), dbg_itype_unsigned_char_int},
84 {CV_AMD64_CH, "CH", (DWORD*)(FIELD_OFFSET(CONTEXT, Rcx)+1), dbg_itype_unsigned_char_int},
85 {CV_AMD64_DH, "DH", (DWORD*)(FIELD_OFFSET(CONTEXT, Rdx)+1), dbg_itype_unsigned_char_int},
86 {CV_AMD64_AX, "AX", (DWORD*)FIELD_OFFSET(CONTEXT, Rax), dbg_itype_unsigned_short_int},
87 {CV_AMD64_BX, "BX", (DWORD*)FIELD_OFFSET(CONTEXT, Rbx), dbg_itype_unsigned_short_int},
88 {CV_AMD64_CX, "CX", (DWORD*)FIELD_OFFSET(CONTEXT, Rcx), dbg_itype_unsigned_short_int},
89 {CV_AMD64_DX, "DX", (DWORD*)FIELD_OFFSET(CONTEXT, Rdx), dbg_itype_unsigned_short_int},
90 {CV_AMD64_SP, "SP", (DWORD*)FIELD_OFFSET(CONTEXT, Rsp), dbg_itype_unsigned_short_int},
91 {CV_AMD64_BP, "BP", (DWORD*)FIELD_OFFSET(CONTEXT, Rbp), dbg_itype_unsigned_short_int},
92 {CV_AMD64_SI, "SI", (DWORD*)FIELD_OFFSET(CONTEXT, Rsi), dbg_itype_unsigned_short_int},
93 {CV_AMD64_DI, "DI", (DWORD*)FIELD_OFFSET(CONTEXT, Rdi), dbg_itype_unsigned_short_int},
94 {CV_AMD64_EAX, "EAX", (DWORD*)FIELD_OFFSET(CONTEXT, Rax), dbg_itype_unsigned_int},
95 {CV_AMD64_EBX, "EBX", (DWORD*)FIELD_OFFSET(CONTEXT, Rbx), dbg_itype_unsigned_int},
96 {CV_AMD64_ECX, "ECX", (DWORD*)FIELD_OFFSET(CONTEXT, Rcx), dbg_itype_unsigned_int},
97 {CV_AMD64_EDX, "EDX", (DWORD*)FIELD_OFFSET(CONTEXT, Rdx), dbg_itype_unsigned_int},
98 {CV_AMD64_ESP, "ESP", (DWORD*)FIELD_OFFSET(CONTEXT, Rsp), dbg_itype_unsigned_int},
99 {CV_AMD64_EBP, "EBP", (DWORD*)FIELD_OFFSET(CONTEXT, Rbp), dbg_itype_unsigned_int},
100 {CV_AMD64_ESI, "ESI", (DWORD*)FIELD_OFFSET(CONTEXT, Rsi), dbg_itype_unsigned_int},
101 {CV_AMD64_EDI, "EDI", (DWORD*)FIELD_OFFSET(CONTEXT, Rdi), dbg_itype_unsigned_int},
102 {CV_AMD64_ES, "ES", (DWORD*)FIELD_OFFSET(CONTEXT, SegEs), dbg_itype_unsigned_short_int},
103 {CV_AMD64_CS, "CS", (DWORD*)FIELD_OFFSET(CONTEXT, SegCs), dbg_itype_unsigned_short_int},
104 {CV_AMD64_SS, "SS", (DWORD*)FIELD_OFFSET(CONTEXT, SegSs), dbg_itype_unsigned_short_int},
105 {CV_AMD64_DS, "DS", (DWORD*)FIELD_OFFSET(CONTEXT, SegDs), dbg_itype_unsigned_short_int},
106 {CV_AMD64_FS, "FS", (DWORD*)FIELD_OFFSET(CONTEXT, SegFs), dbg_itype_unsigned_short_int},
107 {CV_AMD64_GS, "GS", (DWORD*)FIELD_OFFSET(CONTEXT, SegGs), dbg_itype_unsigned_short_int},
108 {CV_AMD64_FLAGS, "FLAGS", (DWORD*)FIELD_OFFSET(CONTEXT, EFlags), dbg_itype_unsigned_short_int},
109 {CV_AMD64_EFLAGS, "EFLAGS", (DWORD*)FIELD_OFFSET(CONTEXT, EFlags), dbg_itype_unsigned_int},
110 {CV_AMD64_RIP, "RIP", (DWORD*)FIELD_OFFSET(CONTEXT, Rip), dbg_itype_unsigned_int},
111 {CV_AMD64_RAX, "RAX", (DWORD*)FIELD_OFFSET(CONTEXT, Rax), dbg_itype_unsigned_long_int},
112 {CV_AMD64_RBX, "RBX", (DWORD*)FIELD_OFFSET(CONTEXT, Rbx), dbg_itype_unsigned_long_int},
113 {CV_AMD64_RCX, "RCX", (DWORD*)FIELD_OFFSET(CONTEXT, Rcx), dbg_itype_unsigned_long_int},
114 {CV_AMD64_RDX, "RDX", (DWORD*)FIELD_OFFSET(CONTEXT, Rdx), dbg_itype_unsigned_long_int},
115 {CV_AMD64_RSP, "RSP", (DWORD*)FIELD_OFFSET(CONTEXT, Rsp), dbg_itype_unsigned_long_int},
116 {CV_AMD64_RBP, "RBP", (DWORD*)FIELD_OFFSET(CONTEXT, Rbp), dbg_itype_unsigned_long_int},
117 {CV_AMD64_RSI, "RSI", (DWORD*)FIELD_OFFSET(CONTEXT, Rsi), dbg_itype_unsigned_long_int},
118 {CV_AMD64_RDI, "RDI", (DWORD*)FIELD_OFFSET(CONTEXT, Rdi), dbg_itype_unsigned_long_int},
119 {CV_AMD64_R8, "R8", (DWORD*)FIELD_OFFSET(CONTEXT, R8), dbg_itype_unsigned_long_int},
120 {CV_AMD64_R9, "R9", (DWORD*)FIELD_OFFSET(CONTEXT, R9), dbg_itype_unsigned_long_int},
121 {CV_AMD64_R10, "R10", (DWORD*)FIELD_OFFSET(CONTEXT, R10), dbg_itype_unsigned_long_int},
122 {CV_AMD64_R11, "R11", (DWORD*)FIELD_OFFSET(CONTEXT, R11), dbg_itype_unsigned_long_int},
123 {CV_AMD64_R12, "R12", (DWORD*)FIELD_OFFSET(CONTEXT, R12), dbg_itype_unsigned_long_int},
124 {CV_AMD64_R13, "R13", (DWORD*)FIELD_OFFSET(CONTEXT, R13), dbg_itype_unsigned_long_int},
125 {CV_AMD64_R14, "R14", (DWORD*)FIELD_OFFSET(CONTEXT, R14), dbg_itype_unsigned_long_int},
126 {CV_AMD64_R15, "R15", (DWORD*)FIELD_OFFSET(CONTEXT, R15), dbg_itype_unsigned_long_int},
127 {0, NULL, 0, dbg_itype_none}
130 static const struct dbg_internal_var* be_x86_64_init_registers(CONTEXT* ctx)
132 struct dbg_internal_var* div;
134 for (div = be_x86_64_ctx; div->name; div++)
135 div->pval = (DWORD*)((char*)ctx + (DWORD_PTR)div->pval);
136 return be_x86_64_ctx;
139 static unsigned be_x86_64_is_step_over_insn(const void* insn)
141 dbg_printf("not done step_over_insn\n");
145 static unsigned be_x86_64_is_function_return(const void* insn)
147 dbg_printf("not done is_function_return\n");
151 static unsigned be_x86_64_is_break_insn(const void* insn)
153 dbg_printf("not done is_break_insn\n");
157 static unsigned be_x86_64_is_func_call(const void* insn, ADDRESS64* callee)
159 dbg_printf("not done is_func_call\n");
163 static void be_x86_64_disasm_one_insn(ADDRESS64* addr, int display)
165 dbg_printf("Disasm NIY\n");
168 static unsigned be_x86_64_insert_Xpoint(HANDLE hProcess, const struct be_process_io* pio,
169 CONTEXT* ctx, enum be_xpoint_type type,
170 void* addr, unsigned long* val, unsigned size)
172 dbg_printf("not done insert_Xpoint\n");
176 static unsigned be_x86_64_remove_Xpoint(HANDLE hProcess, const struct be_process_io* pio,
177 CONTEXT* ctx, enum be_xpoint_type type,
178 void* addr, unsigned long val, unsigned size)
180 dbg_printf("not done remove_Xpoint\n");
184 static unsigned be_x86_64_is_watchpoint_set(const CONTEXT* ctx, unsigned idx)
186 dbg_printf("not done is_watchpoint_set\n");
190 static void be_x86_64_clear_watchpoint(CONTEXT* ctx, unsigned idx)
192 dbg_printf("not done clear_watchpoint\n");
195 static int be_x86_64_adjust_pc_for_break(CONTEXT* ctx, BOOL way)
206 static int be_x86_64_fetch_integer(const struct dbg_lvalue* lvalue, unsigned size,
207 unsigned ext_sign, LONGLONG* ret)
209 dbg_printf("not done fetch_integer\n");
213 static int be_x86_64_fetch_float(const struct dbg_lvalue* lvalue, unsigned size,
216 dbg_printf("not done fetch_float\n");
220 struct backend_cpu be_x86_64 =
225 be_x86_64_get_register_info,
226 be_x86_64_single_step,
227 be_x86_64_print_context,
228 be_x86_64_print_segment_info,
229 be_x86_64_init_registers,
230 be_x86_64_is_step_over_insn,
231 be_x86_64_is_function_return,
232 be_x86_64_is_break_insn,
233 be_x86_64_is_func_call,
234 be_x86_64_disasm_one_insn,
235 be_x86_64_insert_Xpoint,
236 be_x86_64_remove_Xpoint,
237 be_x86_64_is_watchpoint_set,
238 be_x86_64_clear_watchpoint,
239 be_x86_64_adjust_pc_for_break,
240 be_x86_64_fetch_integer,
241 be_x86_64_fetch_float,