winedbg: Add German translation.
[wine] / programs / winedbg / be_x86_64.c
1 /*
2  * Debugger x86_64 specific functions
3  *
4  * Copyright 2004 Vincent BĂ©ron
5  *
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.
10  *
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.
15  *
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
19  */
20
21 #include "debugger.h"
22
23 #if defined(__x86_64__)
24
25 #define STEP_FLAG 0x00000100 /* single step flag */
26
27 static unsigned be_x86_64_get_addr(HANDLE hThread, const CONTEXT* ctx, 
28                                  enum be_cpu_addr bca, ADDRESS64* addr)
29 {
30     addr->Mode = AddrModeFlat;
31     switch (bca)
32     {
33     case be_cpu_addr_pc:
34         addr->Segment = ctx->SegCs;
35         addr->Offset = ctx->Rip;
36         return TRUE;
37     case be_cpu_addr_stack:
38         addr->Segment = ctx->SegSs;
39         addr->Offset = ctx->Rsp;
40         return TRUE;
41     case be_cpu_addr_frame:
42         addr->Segment = ctx->SegSs;
43         addr->Offset = ctx->Rbp;
44         return TRUE;
45     default:
46         addr->Mode = -1;
47         return FALSE;
48     }
49 }
50
51 static unsigned be_x86_64_get_register_info(int regno, enum be_cpu_addr* kind)
52 {
53     /* this is true when running in 32bit mode... and wrong in 64 :-/ */
54     switch (regno)
55     {
56     case CV_AMD64_RIP: *kind = be_cpu_addr_pc; return TRUE;
57     case CV_AMD64_EBP: *kind = be_cpu_addr_frame; return TRUE;
58     case CV_AMD64_ESP: *kind = be_cpu_addr_stack; return TRUE;
59     }
60     return FALSE;
61 }
62
63 static void be_x86_64_single_step(CONTEXT* ctx, unsigned enable)
64 {
65     if (enable) ctx->EFlags |= STEP_FLAG;
66     else ctx->EFlags &= ~STEP_FLAG;
67 }
68
69 static void be_x86_64_print_context(HANDLE hThread, const CONTEXT* ctx,
70                                     int all_regs)
71 {
72     static const char flags[] = "aVR-N--ODITSZ-A-P-C";
73     char buf[33];
74     int i;
75
76     strcpy(buf, flags);
77     for (i = 0; buf[i]; i++)
78         if (buf[i] != '-' && !(ctx->EFlags & (1 << (sizeof(flags) - 2 - i))))
79             buf[i] = ' ';
80
81     dbg_printf("Register dump:\n");
82     dbg_printf(" rip:%016lx rsp:%016lx rbp:%016lx eflags:%08x (%s)\n",
83                ctx->Rip, ctx->Rsp, ctx->Rbp, ctx->EFlags, buf);
84     dbg_printf(" rax:%016lx rbx:%016lx rcx:%016lx rdx:%016lx\n",
85                ctx->Rax, ctx->Rbx, ctx->Rcx, ctx->Rdx);
86     dbg_printf(" rsi:%016lx rdi:%016lx  r8:%016lx  r9:%016lx r10:%016lx\n",
87                ctx->Rsi, ctx->Rdi, ctx->R8, ctx->R9, ctx->R10 );
88     dbg_printf(" r11:%016lx r12:%016lx r13:%016lx r14:%016lx r15:%016lx\n",
89                ctx->R11, ctx->R12, ctx->R13, ctx->R14, ctx->R15 );
90
91     if (all_regs) dbg_printf( "Floating point x86_64 dump not implemented\n" );
92 }
93
94 static void be_x86_64_print_segment_info(HANDLE hThread, const CONTEXT* ctx)
95 {
96 }
97
98 static struct dbg_internal_var be_x86_64_ctx[] =
99 {
100     {CV_AMD64_AL,       "AL",           (DWORD*)FIELD_OFFSET(CONTEXT, Rax),     dbg_itype_unsigned_char_int},
101     {CV_AMD64_BL,       "BL",           (DWORD*)FIELD_OFFSET(CONTEXT, Rbx),     dbg_itype_unsigned_char_int},
102     {CV_AMD64_CL,       "CL",           (DWORD*)FIELD_OFFSET(CONTEXT, Rcx),     dbg_itype_unsigned_char_int},
103     {CV_AMD64_DL,       "DL",           (DWORD*)FIELD_OFFSET(CONTEXT, Rdx),     dbg_itype_unsigned_char_int},
104     {CV_AMD64_AH,       "AH",           (DWORD*)(FIELD_OFFSET(CONTEXT, Rax)+1), dbg_itype_unsigned_char_int},
105     {CV_AMD64_BH,       "BH",           (DWORD*)(FIELD_OFFSET(CONTEXT, Rbx)+1), dbg_itype_unsigned_char_int},
106     {CV_AMD64_CH,       "CH",           (DWORD*)(FIELD_OFFSET(CONTEXT, Rcx)+1), dbg_itype_unsigned_char_int},
107     {CV_AMD64_DH,       "DH",           (DWORD*)(FIELD_OFFSET(CONTEXT, Rdx)+1), dbg_itype_unsigned_char_int},
108     {CV_AMD64_AX,       "AX",           (DWORD*)FIELD_OFFSET(CONTEXT, Rax),     dbg_itype_unsigned_short_int},
109     {CV_AMD64_BX,       "BX",           (DWORD*)FIELD_OFFSET(CONTEXT, Rbx),     dbg_itype_unsigned_short_int},
110     {CV_AMD64_CX,       "CX",           (DWORD*)FIELD_OFFSET(CONTEXT, Rcx),     dbg_itype_unsigned_short_int},
111     {CV_AMD64_DX,       "DX",           (DWORD*)FIELD_OFFSET(CONTEXT, Rdx),     dbg_itype_unsigned_short_int},
112     {CV_AMD64_SP,       "SP",           (DWORD*)FIELD_OFFSET(CONTEXT, Rsp),     dbg_itype_unsigned_short_int},
113     {CV_AMD64_BP,       "BP",           (DWORD*)FIELD_OFFSET(CONTEXT, Rbp),     dbg_itype_unsigned_short_int},
114     {CV_AMD64_SI,       "SI",           (DWORD*)FIELD_OFFSET(CONTEXT, Rsi),     dbg_itype_unsigned_short_int},
115     {CV_AMD64_DI,       "DI",           (DWORD*)FIELD_OFFSET(CONTEXT, Rdi),     dbg_itype_unsigned_short_int},
116     {CV_AMD64_EAX,      "EAX",          (DWORD*)FIELD_OFFSET(CONTEXT, Rax),     dbg_itype_unsigned_int},
117     {CV_AMD64_EBX,      "EBX",          (DWORD*)FIELD_OFFSET(CONTEXT, Rbx),     dbg_itype_unsigned_int},
118     {CV_AMD64_ECX,      "ECX",          (DWORD*)FIELD_OFFSET(CONTEXT, Rcx),     dbg_itype_unsigned_int},
119     {CV_AMD64_EDX,      "EDX",          (DWORD*)FIELD_OFFSET(CONTEXT, Rdx),     dbg_itype_unsigned_int},
120     {CV_AMD64_ESP,      "ESP",          (DWORD*)FIELD_OFFSET(CONTEXT, Rsp),     dbg_itype_unsigned_int},
121     {CV_AMD64_EBP,      "EBP",          (DWORD*)FIELD_OFFSET(CONTEXT, Rbp),     dbg_itype_unsigned_int},
122     {CV_AMD64_ESI,      "ESI",          (DWORD*)FIELD_OFFSET(CONTEXT, Rsi),     dbg_itype_unsigned_int},
123     {CV_AMD64_EDI,      "EDI",          (DWORD*)FIELD_OFFSET(CONTEXT, Rdi),     dbg_itype_unsigned_int},
124     {CV_AMD64_ES,       "ES",           (DWORD*)FIELD_OFFSET(CONTEXT, SegEs),   dbg_itype_unsigned_short_int},
125     {CV_AMD64_CS,       "CS",           (DWORD*)FIELD_OFFSET(CONTEXT, SegCs),   dbg_itype_unsigned_short_int},
126     {CV_AMD64_SS,       "SS",           (DWORD*)FIELD_OFFSET(CONTEXT, SegSs),   dbg_itype_unsigned_short_int},
127     {CV_AMD64_DS,       "DS",           (DWORD*)FIELD_OFFSET(CONTEXT, SegDs),   dbg_itype_unsigned_short_int},
128     {CV_AMD64_FS,       "FS",           (DWORD*)FIELD_OFFSET(CONTEXT, SegFs),   dbg_itype_unsigned_short_int},
129     {CV_AMD64_GS,       "GS",           (DWORD*)FIELD_OFFSET(CONTEXT, SegGs),   dbg_itype_unsigned_short_int},
130     {CV_AMD64_FLAGS,    "FLAGS",        (DWORD*)FIELD_OFFSET(CONTEXT, EFlags),  dbg_itype_unsigned_short_int},
131     {CV_AMD64_EFLAGS,   "EFLAGS",       (DWORD*)FIELD_OFFSET(CONTEXT, EFlags),  dbg_itype_unsigned_int},
132     {CV_AMD64_RIP,      "RIP",          (DWORD*)FIELD_OFFSET(CONTEXT, Rip),     dbg_itype_unsigned_int},
133     {CV_AMD64_RAX,      "RAX",          (DWORD*)FIELD_OFFSET(CONTEXT, Rax),     dbg_itype_unsigned_long_int},
134     {CV_AMD64_RBX,      "RBX",          (DWORD*)FIELD_OFFSET(CONTEXT, Rbx),     dbg_itype_unsigned_long_int},
135     {CV_AMD64_RCX,      "RCX",          (DWORD*)FIELD_OFFSET(CONTEXT, Rcx),     dbg_itype_unsigned_long_int},
136     {CV_AMD64_RDX,      "RDX",          (DWORD*)FIELD_OFFSET(CONTEXT, Rdx),     dbg_itype_unsigned_long_int},
137     {CV_AMD64_RSP,      "RSP",          (DWORD*)FIELD_OFFSET(CONTEXT, Rsp),     dbg_itype_unsigned_long_int},
138     {CV_AMD64_RBP,      "RBP",          (DWORD*)FIELD_OFFSET(CONTEXT, Rbp),     dbg_itype_unsigned_long_int},
139     {CV_AMD64_RSI,      "RSI",          (DWORD*)FIELD_OFFSET(CONTEXT, Rsi),     dbg_itype_unsigned_long_int},
140     {CV_AMD64_RDI,      "RDI",          (DWORD*)FIELD_OFFSET(CONTEXT, Rdi),     dbg_itype_unsigned_long_int},
141     {CV_AMD64_R8,       "R8",           (DWORD*)FIELD_OFFSET(CONTEXT, R8),      dbg_itype_unsigned_long_int},
142     {CV_AMD64_R9,       "R9",           (DWORD*)FIELD_OFFSET(CONTEXT, R9),      dbg_itype_unsigned_long_int},
143     {CV_AMD64_R10,      "R10",          (DWORD*)FIELD_OFFSET(CONTEXT, R10),     dbg_itype_unsigned_long_int},
144     {CV_AMD64_R11,      "R11",          (DWORD*)FIELD_OFFSET(CONTEXT, R11),     dbg_itype_unsigned_long_int},
145     {CV_AMD64_R12,      "R12",          (DWORD*)FIELD_OFFSET(CONTEXT, R12),     dbg_itype_unsigned_long_int},
146     {CV_AMD64_R13,      "R13",          (DWORD*)FIELD_OFFSET(CONTEXT, R13),     dbg_itype_unsigned_long_int},
147     {CV_AMD64_R14,      "R14",          (DWORD*)FIELD_OFFSET(CONTEXT, R14),     dbg_itype_unsigned_long_int},
148     {CV_AMD64_R15,      "R15",          (DWORD*)FIELD_OFFSET(CONTEXT, R15),     dbg_itype_unsigned_long_int},
149     {0,                 NULL,           0,                                      dbg_itype_none}
150 };
151
152 static const struct dbg_internal_var* be_x86_64_init_registers(CONTEXT* ctx)
153 {
154     struct dbg_internal_var*    div;
155
156     for (div = be_x86_64_ctx; div->name; div++)
157         div->pval = (DWORD*)((char*)ctx + (DWORD_PTR)div->pval);
158     return be_x86_64_ctx;
159 }
160
161 static unsigned be_x86_64_is_step_over_insn(const void* insn)
162 {
163     dbg_printf("not done step_over_insn\n");
164     return FALSE;
165 }
166
167 static unsigned be_x86_64_is_function_return(const void* insn)
168 {
169     dbg_printf("not done is_function_return\n");
170     return FALSE;
171 }
172
173 static unsigned be_x86_64_is_break_insn(const void* insn)
174 {
175     dbg_printf("not done is_break_insn\n");
176     return FALSE;
177 }
178
179 static unsigned be_x86_64_is_func_call(const void* insn, ADDRESS64* callee)
180 {
181     dbg_printf("not done is_func_call\n");
182     return FALSE;
183 }
184
185 static void be_x86_64_disasm_one_insn(ADDRESS64* addr, int display)
186 {
187     dbg_printf("Disasm NIY\n");
188 }
189
190 static unsigned be_x86_64_insert_Xpoint(HANDLE hProcess, const struct be_process_io* pio,
191                                        CONTEXT* ctx, enum be_xpoint_type type,
192                                        void* addr, unsigned long* val, unsigned size)
193 {
194     dbg_printf("not done insert_Xpoint\n");
195     return 0;
196 }
197
198 static unsigned be_x86_64_remove_Xpoint(HANDLE hProcess, const struct be_process_io* pio,
199                                        CONTEXT* ctx, enum be_xpoint_type type, 
200                                        void* addr, unsigned long val, unsigned size)
201 {
202     dbg_printf("not done remove_Xpoint\n");
203     return FALSE;
204 }
205
206 static unsigned be_x86_64_is_watchpoint_set(const CONTEXT* ctx, unsigned idx)
207 {
208     dbg_printf("not done is_watchpoint_set\n");
209     return FALSE;
210 }
211
212 static void be_x86_64_clear_watchpoint(CONTEXT* ctx, unsigned idx)
213 {
214     dbg_printf("not done clear_watchpoint\n");
215 }
216
217 static int be_x86_64_adjust_pc_for_break(CONTEXT* ctx, BOOL way)
218 {
219     if (way)
220     {
221         ctx->Rip--;
222         return -1;
223     }
224     ctx->Rip++;
225     return 1;
226 }
227
228 static int be_x86_64_fetch_integer(const struct dbg_lvalue* lvalue, unsigned size,
229                                   unsigned ext_sign, LONGLONG* ret)
230 {
231     dbg_printf("not done fetch_integer\n");
232     return FALSE;
233 }
234
235 static int be_x86_64_fetch_float(const struct dbg_lvalue* lvalue, unsigned size, 
236                                 long double* ret)
237 {
238     dbg_printf("not done fetch_float\n");
239     return FALSE;
240 }
241
242 struct backend_cpu be_x86_64 =
243 {
244     be_cpu_linearize,
245     be_cpu_build_addr,
246     be_x86_64_get_addr,
247     be_x86_64_get_register_info,
248     be_x86_64_single_step,
249     be_x86_64_print_context,
250     be_x86_64_print_segment_info,
251     be_x86_64_init_registers,
252     be_x86_64_is_step_over_insn,
253     be_x86_64_is_function_return,
254     be_x86_64_is_break_insn,
255     be_x86_64_is_func_call,
256     be_x86_64_disasm_one_insn,
257     be_x86_64_insert_Xpoint,
258     be_x86_64_remove_Xpoint,
259     be_x86_64_is_watchpoint_set,
260     be_x86_64_clear_watchpoint,
261     be_x86_64_adjust_pc_for_break,
262     be_x86_64_fetch_integer,
263     be_x86_64_fetch_float,
264 };
265 #endif