Eric Pouech | 527eea9 | 2000-03-08 16:44:54 +0000 | [diff] [blame] | 1 | /* -*- tab-width: 8; c-basic-offset: 4 -*- */ |
| 2 | |
| 3 | /* Wine internal debugger |
| 4 | * Interface to Windows debugger API |
Alexandre Julliard | 0799c1a | 2002-03-09 23:29:33 +0000 | [diff] [blame] | 5 | * Copyright 2000 Eric Pouech |
| 6 | * |
| 7 | * This library is free software; you can redistribute it and/or |
| 8 | * modify it under the terms of the GNU Lesser General Public |
| 9 | * License as published by the Free Software Foundation; either |
| 10 | * version 2.1 of the License, or (at your option) any later version. |
| 11 | * |
| 12 | * This library is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 | * Lesser General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU Lesser General Public |
| 18 | * License along with this library; if not, write to the Free Software |
| 19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
Eric Pouech | 527eea9 | 2000-03-08 16:44:54 +0000 | [diff] [blame] | 20 | */ |
| 21 | |
| 22 | #include <stdlib.h> |
Alexandre Julliard | 58d5a0a | 2000-07-29 21:58:17 +0000 | [diff] [blame] | 23 | #include <stdarg.h> |
Eric Pouech | 527eea9 | 2000-03-08 16:44:54 +0000 | [diff] [blame] | 24 | #include <stdio.h> |
Eric Pouech | e5efa0c | 2000-04-13 19:31:58 +0000 | [diff] [blame] | 25 | #include <string.h> |
Eric Pouech | 527eea9 | 2000-03-08 16:44:54 +0000 | [diff] [blame] | 26 | #include "debugger.h" |
Eric Pouech | ac11a68 | 2000-03-26 13:37:39 +0000 | [diff] [blame] | 27 | |
Alexandre Julliard | 09d7822 | 2001-05-05 00:44:48 +0000 | [diff] [blame] | 28 | #include "ntddk.h" |
Eric Pouech | ac11a68 | 2000-03-26 13:37:39 +0000 | [diff] [blame] | 29 | #include "thread.h" |
Alexandre Julliard | f818d42 | 2000-05-03 17:48:21 +0000 | [diff] [blame] | 30 | #include "wincon.h" |
Eric Pouech | ac11a68 | 2000-03-26 13:37:39 +0000 | [diff] [blame] | 31 | #include "wingdi.h" |
| 32 | #include "winuser.h" |
Peter Hunnisett | 73ab649 | 2002-02-25 20:10:35 +0000 | [diff] [blame] | 33 | #include "msvcrt/excpt.h" |
Eric Pouech | ac11a68 | 2000-03-26 13:37:39 +0000 | [diff] [blame] | 34 | |
Eric Pouech | 527eea9 | 2000-03-08 16:44:54 +0000 | [diff] [blame] | 35 | #include "winreg.h" |
Eric Pouech | 527eea9 | 2000-03-08 16:44:54 +0000 | [diff] [blame] | 36 | |
Eric Pouech | ac11a68 | 2000-03-26 13:37:39 +0000 | [diff] [blame] | 37 | DBG_PROCESS* DEBUG_CurrProcess = NULL; |
| 38 | DBG_THREAD* DEBUG_CurrThread = NULL; |
Eric Pouech | f182235 | 2000-05-11 21:43:43 +0000 | [diff] [blame] | 39 | DWORD DEBUG_CurrTid; |
| 40 | DWORD DEBUG_CurrPid; |
Eric Pouech | ac11a68 | 2000-03-26 13:37:39 +0000 | [diff] [blame] | 41 | CONTEXT DEBUG_context; |
Eric Pouech | 52c7534 | 2001-05-03 18:32:47 +0000 | [diff] [blame] | 42 | BOOL DEBUG_interactiveP = FALSE; |
Eric Pouech | 911436b | 2000-06-18 19:30:24 +0000 | [diff] [blame] | 43 | int curr_frame = 0; |
| 44 | static char* DEBUG_LastCmdLine = NULL; |
Eric Pouech | 527eea9 | 2000-03-08 16:44:54 +0000 | [diff] [blame] | 45 | |
Eric Pouech | 7c43b22 | 2000-06-24 12:52:13 +0000 | [diff] [blame] | 46 | static DBG_PROCESS* DEBUG_ProcessList = NULL; |
Alexandre Julliard | f5a8b96 | 2001-10-22 19:00:34 +0000 | [diff] [blame] | 47 | static int automatic_mode; |
Eric Pouech | 04c16b8 | 2000-04-30 12:21:15 +0000 | [diff] [blame] | 48 | DBG_INTVAR DEBUG_IntVars[DBG_IV_LAST]; |
Eric Pouech | e5efa0c | 2000-04-13 19:31:58 +0000 | [diff] [blame] | 49 | |
Eric Pouech | 04c16b8 | 2000-04-30 12:21:15 +0000 | [diff] [blame] | 50 | void DEBUG_Output(int chn, const char* buffer, int len) |
| 51 | { |
| 52 | if (DBG_IVAR(ConChannelMask) & chn) |
| 53 | WriteFile(GetStdHandle(STD_OUTPUT_HANDLE), buffer, len, NULL, NULL); |
| 54 | if (DBG_IVAR(StdChannelMask) & chn) |
| 55 | fwrite(buffer, len, 1, stderr); |
| 56 | } |
Eric Pouech | e5efa0c | 2000-04-13 19:31:58 +0000 | [diff] [blame] | 57 | |
| 58 | int DEBUG_Printf(int chn, const char* format, ...) |
| 59 | { |
Eric Pouech | 52c7534 | 2001-05-03 18:32:47 +0000 | [diff] [blame] | 60 | static char buf[4*1024]; |
Eric Pouech | e5efa0c | 2000-04-13 19:31:58 +0000 | [diff] [blame] | 61 | va_list valist; |
Eric Pouech | 04c16b8 | 2000-04-30 12:21:15 +0000 | [diff] [blame] | 62 | int len; |
Eric Pouech | e5efa0c | 2000-04-13 19:31:58 +0000 | [diff] [blame] | 63 | |
| 64 | va_start(valist, format); |
Alexandre Julliard | 58d5a0a | 2000-07-29 21:58:17 +0000 | [diff] [blame] | 65 | len = vsnprintf(buf, sizeof(buf), format, valist); |
Eric Pouech | e5efa0c | 2000-04-13 19:31:58 +0000 | [diff] [blame] | 66 | va_end(valist); |
Eric Pouech | b971745 | 2000-05-05 18:14:34 +0000 | [diff] [blame] | 67 | |
Bill Medland | 7a364bb | 2001-12-24 20:23:57 +0000 | [diff] [blame] | 68 | if (len <= -1 || len >= sizeof(buf)) { |
Eric Pouech | b971745 | 2000-05-05 18:14:34 +0000 | [diff] [blame] | 69 | len = sizeof(buf) - 1; |
| 70 | buf[len] = 0; |
| 71 | buf[len - 1] = buf[len - 2] = buf[len - 3] = '.'; |
| 72 | } |
Eric Pouech | 04c16b8 | 2000-04-30 12:21:15 +0000 | [diff] [blame] | 73 | DEBUG_Output(chn, buf, len); |
| 74 | return len; |
Eric Pouech | e5efa0c | 2000-04-13 19:31:58 +0000 | [diff] [blame] | 75 | } |
Eric Pouech | 527eea9 | 2000-03-08 16:44:54 +0000 | [diff] [blame] | 76 | |
Eric Pouech | 04c16b8 | 2000-04-30 12:21:15 +0000 | [diff] [blame] | 77 | static BOOL DEBUG_IntVarsRW(int read) |
Eric Pouech | 527eea9 | 2000-03-08 16:44:54 +0000 | [diff] [blame] | 78 | { |
Eric Pouech | ac11a68 | 2000-03-26 13:37:39 +0000 | [diff] [blame] | 79 | HKEY hkey; |
Eric Pouech | 04c16b8 | 2000-04-30 12:21:15 +0000 | [diff] [blame] | 80 | DWORD type = REG_DWORD; |
Eric Pouech | ac11a68 | 2000-03-26 13:37:39 +0000 | [diff] [blame] | 81 | DWORD val; |
| 82 | DWORD count = sizeof(val); |
Eric Pouech | 04c16b8 | 2000-04-30 12:21:15 +0000 | [diff] [blame] | 83 | int i; |
| 84 | DBG_INTVAR* div = DEBUG_IntVars; |
Eric Pouech | ac11a68 | 2000-03-26 13:37:39 +0000 | [diff] [blame] | 85 | |
Eric Pouech | 04c16b8 | 2000-04-30 12:21:15 +0000 | [diff] [blame] | 86 | if (read) { |
| 87 | /* initializes internal vars table */ |
| 88 | #define INTERNAL_VAR(_var,_val,_ref,_typ) \ |
| 89 | div->val = _val; div->name = #_var; div->pval = _ref; \ |
Eric Pouech | 02ecb68 | 2001-12-21 20:29:58 +0000 | [diff] [blame] | 90 | div->type = DEBUG_GetBasicType(_typ); div++; |
Eric Pouech | e5efa0c | 2000-04-13 19:31:58 +0000 | [diff] [blame] | 91 | #include "intvar.h" |
| 92 | #undef INTERNAL_VAR |
Eric Pouech | 04c16b8 | 2000-04-30 12:21:15 +0000 | [diff] [blame] | 93 | } |
| 94 | |
Eric Pouech | f182235 | 2000-05-11 21:43:43 +0000 | [diff] [blame] | 95 | if (RegCreateKeyA(HKEY_CURRENT_USER, "Software\\Wine\\WineDbg", &hkey)) { |
Eric Pouech | 26342c9 | 2000-05-01 14:22:02 +0000 | [diff] [blame] | 96 | /* since the IVars are not yet setup, DEBUG_Printf doesn't work, |
| 97 | * so don't use it */ |
| 98 | fprintf(stderr, "Cannot create WineDbg key in registry\n"); |
| 99 | return FALSE; |
Eric Pouech | ac11a68 | 2000-03-26 13:37:39 +0000 | [diff] [blame] | 100 | } |
Eric Pouech | 26342c9 | 2000-05-01 14:22:02 +0000 | [diff] [blame] | 101 | |
| 102 | for (i = 0; i < DBG_IV_LAST; i++) { |
| 103 | if (read) { |
| 104 | if (!DEBUG_IntVars[i].pval) { |
| 105 | if (!RegQueryValueEx(hkey, DEBUG_IntVars[i].name, 0, |
| 106 | &type, (LPSTR)&val, &count)) |
| 107 | DEBUG_IntVars[i].val = val; |
| 108 | DEBUG_IntVars[i].pval = &DEBUG_IntVars[i].val; |
| 109 | } else { |
| 110 | *DEBUG_IntVars[i].pval = 0; |
| 111 | } |
| 112 | } else { |
| 113 | /* FIXME: type should be infered from basic type -if any- of intvar */ |
| 114 | if (DEBUG_IntVars[i].pval == &DEBUG_IntVars[i].val) |
| 115 | RegSetValueEx(hkey, DEBUG_IntVars[i].name, 0, |
| 116 | type, (LPCVOID)DEBUG_IntVars[i].pval, count); |
| 117 | } |
| 118 | } |
| 119 | RegCloseKey(hkey); |
Eric Pouech | ac11a68 | 2000-03-26 13:37:39 +0000 | [diff] [blame] | 120 | return TRUE; |
| 121 | } |
Eric Pouech | 04c16b8 | 2000-04-30 12:21:15 +0000 | [diff] [blame] | 122 | |
| 123 | DBG_INTVAR* DEBUG_GetIntVar(const char* name) |
| 124 | { |
| 125 | int i; |
| 126 | |
| 127 | for (i = 0; i < DBG_IV_LAST; i++) { |
| 128 | if (!strcmp(DEBUG_IntVars[i].name, name)) |
| 129 | return &DEBUG_IntVars[i]; |
| 130 | } |
| 131 | return NULL; |
| 132 | } |
Eric Pouech | ac11a68 | 2000-03-26 13:37:39 +0000 | [diff] [blame] | 133 | |
| 134 | static WINE_EXCEPTION_FILTER(wine_dbg) |
| 135 | { |
Eric Pouech | b971745 | 2000-05-05 18:14:34 +0000 | [diff] [blame] | 136 | DEBUG_Printf(DBG_CHN_MESG, "\nwine_dbg: Exception (%lx) inside debugger, continuing...\n", GetExceptionCode()); |
Eric Pouech | ac11a68 | 2000-03-26 13:37:39 +0000 | [diff] [blame] | 137 | DEBUG_ExternalDebugger(); |
Eric Pouech | ac11a68 | 2000-03-26 13:37:39 +0000 | [diff] [blame] | 138 | return EXCEPTION_EXECUTE_HANDLER; |
| 139 | } |
| 140 | |
Eric Pouech | 800773f | 2001-08-06 17:51:52 +0000 | [diff] [blame] | 141 | DBG_PROCESS* DEBUG_GetProcess(DWORD pid) |
Eric Pouech | ac11a68 | 2000-03-26 13:37:39 +0000 | [diff] [blame] | 142 | { |
| 143 | DBG_PROCESS* p; |
Eric Pouech | 527eea9 | 2000-03-08 16:44:54 +0000 | [diff] [blame] | 144 | |
Eric Pouech | 7c43b22 | 2000-06-24 12:52:13 +0000 | [diff] [blame] | 145 | for (p = DEBUG_ProcessList; p; p = p->next) |
Eric Pouech | 527eea9 | 2000-03-08 16:44:54 +0000 | [diff] [blame] | 146 | if (p->pid == pid) break; |
| 147 | return p; |
| 148 | } |
| 149 | |
Eric Pouech | 800773f | 2001-08-06 17:51:52 +0000 | [diff] [blame] | 150 | static DBG_PROCESS* DEBUG_AddProcess(DWORD pid, HANDLE h, const char* imageName) |
Eric Pouech | 527eea9 | 2000-03-08 16:44:54 +0000 | [diff] [blame] | 151 | { |
Eric Pouech | ac11a68 | 2000-03-26 13:37:39 +0000 | [diff] [blame] | 152 | DBG_PROCESS* p = DBG_alloc(sizeof(DBG_PROCESS)); |
Eric Pouech | 527eea9 | 2000-03-08 16:44:54 +0000 | [diff] [blame] | 153 | if (!p) |
| 154 | return NULL; |
| 155 | p->handle = h; |
| 156 | p->pid = pid; |
Eric Pouech | 800773f | 2001-08-06 17:51:52 +0000 | [diff] [blame] | 157 | p->imageName = imageName ? DBG_strdup(imageName) : NULL; |
Eric Pouech | 527eea9 | 2000-03-08 16:44:54 +0000 | [diff] [blame] | 158 | p->threads = NULL; |
Eric Pouech | ac11a68 | 2000-03-26 13:37:39 +0000 | [diff] [blame] | 159 | p->num_threads = 0; |
Eric Pouech | b971745 | 2000-05-05 18:14:34 +0000 | [diff] [blame] | 160 | p->continue_on_first_exception = FALSE; |
Eric Pouech | ac11a68 | 2000-03-26 13:37:39 +0000 | [diff] [blame] | 161 | p->modules = NULL; |
Eric Pouech | e939206 | 2000-11-15 22:16:26 +0000 | [diff] [blame] | 162 | p->num_modules = 0; |
Eric Pouech | ac11a68 | 2000-03-26 13:37:39 +0000 | [diff] [blame] | 163 | p->next_index = 0; |
Eric Pouech | b971745 | 2000-05-05 18:14:34 +0000 | [diff] [blame] | 164 | p->dbg_hdr_addr = 0; |
Eric Pouech | eaafb73 | 2001-05-21 18:33:15 +0000 | [diff] [blame] | 165 | p->delayed_bp = NULL; |
| 166 | p->num_delayed_bp = 0; |
Eric Pouech | 527eea9 | 2000-03-08 16:44:54 +0000 | [diff] [blame] | 167 | |
Eric Pouech | 7c43b22 | 2000-06-24 12:52:13 +0000 | [diff] [blame] | 168 | p->next = DEBUG_ProcessList; |
Eric Pouech | 527eea9 | 2000-03-08 16:44:54 +0000 | [diff] [blame] | 169 | p->prev = NULL; |
Eric Pouech | 7c43b22 | 2000-06-24 12:52:13 +0000 | [diff] [blame] | 170 | if (DEBUG_ProcessList) DEBUG_ProcessList->prev = p; |
| 171 | DEBUG_ProcessList = p; |
Eric Pouech | 527eea9 | 2000-03-08 16:44:54 +0000 | [diff] [blame] | 172 | return p; |
| 173 | } |
| 174 | |
Eric Pouech | ac11a68 | 2000-03-26 13:37:39 +0000 | [diff] [blame] | 175 | static void DEBUG_DelThread(DBG_THREAD* p); |
Eric Pouech | 527eea9 | 2000-03-08 16:44:54 +0000 | [diff] [blame] | 176 | |
Eric Pouech | ac11a68 | 2000-03-26 13:37:39 +0000 | [diff] [blame] | 177 | static void DEBUG_DelProcess(DBG_PROCESS* p) |
Eric Pouech | 527eea9 | 2000-03-08 16:44:54 +0000 | [diff] [blame] | 178 | { |
Eric Pouech | eaafb73 | 2001-05-21 18:33:15 +0000 | [diff] [blame] | 179 | int i; |
| 180 | |
Eric Pouech | 527eea9 | 2000-03-08 16:44:54 +0000 | [diff] [blame] | 181 | if (p->threads != NULL) { |
Eric Pouech | e5efa0c | 2000-04-13 19:31:58 +0000 | [diff] [blame] | 182 | DEBUG_Printf(DBG_CHN_ERR, "Shouldn't happen\n"); |
Eric Pouech | 527eea9 | 2000-03-08 16:44:54 +0000 | [diff] [blame] | 183 | while (p->threads) DEBUG_DelThread(p->threads); |
| 184 | } |
Eric Pouech | eaafb73 | 2001-05-21 18:33:15 +0000 | [diff] [blame] | 185 | for (i = 0; i < p->num_delayed_bp; i++) { |
| 186 | DBG_free(p->delayed_bp[i].name); |
| 187 | } |
| 188 | DBG_free(p->delayed_bp); |
Eric Pouech | 527eea9 | 2000-03-08 16:44:54 +0000 | [diff] [blame] | 189 | if (p->prev) p->prev->next = p->next; |
| 190 | if (p->next) p->next->prev = p->prev; |
Eric Pouech | 7c43b22 | 2000-06-24 12:52:13 +0000 | [diff] [blame] | 191 | if (p == DEBUG_ProcessList) DEBUG_ProcessList = p->next; |
Eric Pouech | 911436b | 2000-06-18 19:30:24 +0000 | [diff] [blame] | 192 | if (p == DEBUG_CurrProcess) DEBUG_CurrProcess = NULL; |
Eric Pouech | 800773f | 2001-08-06 17:51:52 +0000 | [diff] [blame] | 193 | DBG_free((char*)p->imageName); |
Eric Pouech | 527eea9 | 2000-03-08 16:44:54 +0000 | [diff] [blame] | 194 | DBG_free(p); |
| 195 | } |
| 196 | |
| 197 | static void DEBUG_InitCurrProcess(void) |
| 198 | { |
Eric Pouech | 527eea9 | 2000-03-08 16:44:54 +0000 | [diff] [blame] | 199 | } |
| 200 | |
Alexandre Julliard | 0966a6d | 2000-03-10 22:25:07 +0000 | [diff] [blame] | 201 | static BOOL DEBUG_ProcessGetString(char* buffer, int size, HANDLE hp, LPSTR addr) |
| 202 | { |
| 203 | DWORD sz; |
| 204 | *(WCHAR*)buffer = 0; |
| 205 | return (addr && ReadProcessMemory(hp, addr, buffer, size, &sz)); |
| 206 | } |
| 207 | |
| 208 | static BOOL DEBUG_ProcessGetStringIndirect(char* buffer, int size, HANDLE hp, LPVOID addr) |
Eric Pouech | 527eea9 | 2000-03-08 16:44:54 +0000 | [diff] [blame] | 209 | { |
| 210 | LPVOID ad; |
| 211 | DWORD sz; |
| 212 | |
| 213 | if ( addr |
| 214 | && ReadProcessMemory(hp, addr, &ad, sizeof(ad), &sz) |
| 215 | && sz == sizeof(ad) |
| 216 | && ad |
| 217 | && ReadProcessMemory(hp, ad, buffer, size, &sz)) |
| 218 | return TRUE; |
| 219 | *(WCHAR*)buffer = 0; |
| 220 | return FALSE; |
| 221 | } |
| 222 | |
Eric Pouech | 800773f | 2001-08-06 17:51:52 +0000 | [diff] [blame] | 223 | DBG_THREAD* DEBUG_GetThread(DBG_PROCESS* p, DWORD tid) |
Eric Pouech | 527eea9 | 2000-03-08 16:44:54 +0000 | [diff] [blame] | 224 | { |
Eric Pouech | ac11a68 | 2000-03-26 13:37:39 +0000 | [diff] [blame] | 225 | DBG_THREAD* t; |
Eric Pouech | 527eea9 | 2000-03-08 16:44:54 +0000 | [diff] [blame] | 226 | |
| 227 | for (t = p->threads; t; t = t->next) |
| 228 | if (t->tid == tid) break; |
| 229 | return t; |
| 230 | } |
| 231 | |
Eric Pouech | ac11a68 | 2000-03-26 13:37:39 +0000 | [diff] [blame] | 232 | static DBG_THREAD* DEBUG_AddThread(DBG_PROCESS* p, DWORD tid, |
| 233 | HANDLE h, LPVOID start, LPVOID teb) |
Eric Pouech | 527eea9 | 2000-03-08 16:44:54 +0000 | [diff] [blame] | 234 | { |
Eric Pouech | ac11a68 | 2000-03-26 13:37:39 +0000 | [diff] [blame] | 235 | DBG_THREAD* t = DBG_alloc(sizeof(DBG_THREAD)); |
Eric Pouech | 527eea9 | 2000-03-08 16:44:54 +0000 | [diff] [blame] | 236 | if (!t) |
| 237 | return NULL; |
| 238 | |
| 239 | t->handle = h; |
| 240 | t->tid = tid; |
| 241 | t->start = start; |
| 242 | t->teb = teb; |
| 243 | t->process = p; |
| 244 | t->wait_for_first_exception = 0; |
| 245 | t->dbg_exec_mode = EXEC_CONT; |
| 246 | t->dbg_exec_count = 0; |
Eric Pouech | 2b713ba | 2001-04-13 22:26:23 +0000 | [diff] [blame] | 247 | sprintf(t->name, "%08lx", tid); |
Eric Pouech | ac11a68 | 2000-03-26 13:37:39 +0000 | [diff] [blame] | 248 | |
| 249 | p->num_threads++; |
Eric Pouech | 527eea9 | 2000-03-08 16:44:54 +0000 | [diff] [blame] | 250 | t->next = p->threads; |
| 251 | t->prev = NULL; |
| 252 | if (p->threads) p->threads->prev = t; |
| 253 | p->threads = t; |
| 254 | |
| 255 | return t; |
| 256 | } |
| 257 | |
| 258 | static void DEBUG_InitCurrThread(void) |
| 259 | { |
Eric Pouech | 527eea9 | 2000-03-08 16:44:54 +0000 | [diff] [blame] | 260 | if (DEBUG_CurrThread->start) { |
Eric Pouech | e5efa0c | 2000-04-13 19:31:58 +0000 | [diff] [blame] | 261 | if (DEBUG_CurrThread->process->num_threads == 1 || |
| 262 | DBG_IVAR(BreakAllThreadsStartup)) { |
Eric Pouech | ac11a68 | 2000-03-26 13:37:39 +0000 | [diff] [blame] | 263 | DBG_VALUE value; |
| 264 | |
| 265 | DEBUG_SetBreakpoints(FALSE); |
| 266 | value.type = NULL; |
| 267 | value.cookie = DV_TARGET; |
| 268 | value.addr.seg = 0; |
| 269 | value.addr.off = (DWORD)DEBUG_CurrThread->start; |
Eric Pouech | b971745 | 2000-05-05 18:14:34 +0000 | [diff] [blame] | 270 | DEBUG_AddBreakpoint(&value, NULL); |
Eric Pouech | ac11a68 | 2000-03-26 13:37:39 +0000 | [diff] [blame] | 271 | DEBUG_SetBreakpoints(TRUE); |
| 272 | } |
Eric Pouech | 527eea9 | 2000-03-08 16:44:54 +0000 | [diff] [blame] | 273 | } else { |
| 274 | DEBUG_CurrThread->wait_for_first_exception = 1; |
| 275 | } |
| 276 | } |
| 277 | |
Eric Pouech | ac11a68 | 2000-03-26 13:37:39 +0000 | [diff] [blame] | 278 | static void DEBUG_DelThread(DBG_THREAD* t) |
Eric Pouech | 527eea9 | 2000-03-08 16:44:54 +0000 | [diff] [blame] | 279 | { |
| 280 | if (t->prev) t->prev->next = t->next; |
| 281 | if (t->next) t->next->prev = t->prev; |
| 282 | if (t == t->process->threads) t->process->threads = t->next; |
Eric Pouech | ac11a68 | 2000-03-26 13:37:39 +0000 | [diff] [blame] | 283 | t->process->num_threads--; |
Eric Pouech | 911436b | 2000-06-18 19:30:24 +0000 | [diff] [blame] | 284 | if (t == DEBUG_CurrThread) DEBUG_CurrThread = NULL; |
Eric Pouech | 527eea9 | 2000-03-08 16:44:54 +0000 | [diff] [blame] | 285 | DBG_free(t); |
| 286 | } |
| 287 | |
Eric Pouech | 911436b | 2000-06-18 19:30:24 +0000 | [diff] [blame] | 288 | BOOL DEBUG_Attach(DWORD pid, BOOL cofe) |
| 289 | { |
Eric Pouech | 800773f | 2001-08-06 17:51:52 +0000 | [diff] [blame] | 290 | if (!(DEBUG_CurrProcess = DEBUG_AddProcess(pid, 0, NULL))) return FALSE; |
Eric Pouech | 911436b | 2000-06-18 19:30:24 +0000 | [diff] [blame] | 291 | |
| 292 | if (!DebugActiveProcess(pid)) { |
Alexandre Julliard | 1ce1bef | 2001-07-11 17:33:08 +0000 | [diff] [blame] | 293 | DEBUG_Printf(DBG_CHN_MESG, "Can't attach process %lx: error %ld\n", pid, GetLastError()); |
| 294 | DEBUG_DelProcess(DEBUG_CurrProcess); |
| 295 | DEBUG_CurrProcess = NULL; |
Eric Pouech | 911436b | 2000-06-18 19:30:24 +0000 | [diff] [blame] | 296 | return FALSE; |
| 297 | } |
| 298 | DEBUG_CurrProcess->continue_on_first_exception = cofe; |
| 299 | return TRUE; |
| 300 | } |
| 301 | |
Eric Pouech | 21b366e | 2002-02-27 01:29:18 +0000 | [diff] [blame] | 302 | BOOL DEBUG_Detach(void) |
| 303 | { |
| 304 | /* remove all set breakpoints in debuggee code */ |
| 305 | DEBUG_SetBreakpoints(FALSE); |
| 306 | /* needed for single stepping (ugly). |
| 307 | * should this be handled inside the server ??? */ |
| 308 | #ifdef __i386__ |
| 309 | DEBUG_context.EFlags &= ~STEP_FLAG; |
| 310 | #endif |
| 311 | SetThreadContext(DEBUG_CurrThread->handle, &DEBUG_context); |
| 312 | DebugActiveProcessStop(DEBUG_CurrProcess->pid); |
| 313 | DEBUG_DelProcess(DEBUG_CurrProcess); |
| 314 | DEBUG_CurrProcess = NULL; |
| 315 | /* FIXME: should zero out the symbol table too */ |
| 316 | return TRUE; |
| 317 | } |
| 318 | |
Eric Pouech | 911436b | 2000-06-18 19:30:24 +0000 | [diff] [blame] | 319 | static BOOL DEBUG_ExceptionProlog(BOOL is_debug, BOOL force, DWORD code) |
| 320 | { |
| 321 | DBG_ADDR addr; |
| 322 | int newmode; |
| 323 | |
| 324 | DEBUG_GetCurrentAddress(&addr); |
| 325 | DEBUG_SuspendExecution(); |
| 326 | |
| 327 | if (!is_debug) { |
Alexandre Julliard | 954a413 | 2000-09-24 03:15:50 +0000 | [diff] [blame] | 328 | if (!addr.seg) |
Eric Pouech | 38f2be4 | 2001-08-15 17:40:31 +0000 | [diff] [blame] | 329 | DEBUG_Printf(DBG_CHN_MESG, " in 32-bit code (0x%08lx)", addr.off); |
Eric Pouech | 911436b | 2000-06-18 19:30:24 +0000 | [diff] [blame] | 330 | else |
Alexandre Julliard | 954a413 | 2000-09-24 03:15:50 +0000 | [diff] [blame] | 331 | switch(DEBUG_GetSelectorType(addr.seg)) |
| 332 | { |
| 333 | case MODE_32: |
Eric Pouech | 38f2be4 | 2001-08-15 17:40:31 +0000 | [diff] [blame] | 334 | DEBUG_Printf(DBG_CHN_MESG, " in 32-bit code (%04lx:%08lx)", addr.seg, addr.off); |
Alexandre Julliard | 954a413 | 2000-09-24 03:15:50 +0000 | [diff] [blame] | 335 | break; |
| 336 | case MODE_16: |
Eric Pouech | 38f2be4 | 2001-08-15 17:40:31 +0000 | [diff] [blame] | 337 | DEBUG_Printf(DBG_CHN_MESG, " in 16-bit code (%04lx:%04lx)", addr.seg, addr.off); |
Alexandre Julliard | 954a413 | 2000-09-24 03:15:50 +0000 | [diff] [blame] | 338 | break; |
| 339 | case MODE_VM86: |
Eric Pouech | 38f2be4 | 2001-08-15 17:40:31 +0000 | [diff] [blame] | 340 | DEBUG_Printf(DBG_CHN_MESG, " in vm86 code (%04lx:%04lx)", addr.seg, addr.off); |
Alexandre Julliard | 954a413 | 2000-09-24 03:15:50 +0000 | [diff] [blame] | 341 | break; |
| 342 | case MODE_INVALID: |
Eric Pouech | 38f2be4 | 2001-08-15 17:40:31 +0000 | [diff] [blame] | 343 | DEBUG_Printf(DBG_CHN_MESG, " bad CS (%lx)", addr.seg); |
Alexandre Julliard | 954a413 | 2000-09-24 03:15:50 +0000 | [diff] [blame] | 344 | break; |
| 345 | } |
Eric Pouech | 38f2be4 | 2001-08-15 17:40:31 +0000 | [diff] [blame] | 346 | DEBUG_Printf(DBG_CHN_MESG, ".\n"); |
Eric Pouech | 911436b | 2000-06-18 19:30:24 +0000 | [diff] [blame] | 347 | } |
Eric Pouech | 38f2be4 | 2001-08-15 17:40:31 +0000 | [diff] [blame] | 348 | |
Eric Pouech | 911436b | 2000-06-18 19:30:24 +0000 | [diff] [blame] | 349 | DEBUG_LoadEntryPoints("Loading new modules symbols:\n"); |
| 350 | |
| 351 | if (!force && is_debug && |
James Abbatiello | ebef9a9 | 2000-09-01 01:22:05 +0000 | [diff] [blame] | 352 | DEBUG_ShouldContinue(&addr, |
| 353 | code, |
Eric Pouech | 911436b | 2000-06-18 19:30:24 +0000 | [diff] [blame] | 354 | DEBUG_CurrThread->dbg_exec_mode, |
| 355 | &DEBUG_CurrThread->dbg_exec_count)) |
| 356 | return FALSE; |
| 357 | |
Alexandre Julliard | 954a413 | 2000-09-24 03:15:50 +0000 | [diff] [blame] | 358 | if ((newmode = DEBUG_GetSelectorType(addr.seg)) == MODE_INVALID) newmode = MODE_32; |
Eric Pouech | 911436b | 2000-06-18 19:30:24 +0000 | [diff] [blame] | 359 | if (newmode != DEBUG_CurrThread->dbg_mode) |
Alexandre Julliard | 954a413 | 2000-09-24 03:15:50 +0000 | [diff] [blame] | 360 | { |
| 361 | static const char * const names[] = { "???", "16-bit", "32-bit", "vm86" }; |
| 362 | DEBUG_Printf(DBG_CHN_MESG,"In %s mode.\n", names[newmode] ); |
| 363 | DEBUG_CurrThread->dbg_mode = newmode; |
| 364 | } |
Eric Pouech | 911436b | 2000-06-18 19:30:24 +0000 | [diff] [blame] | 365 | |
| 366 | DEBUG_DoDisplay(); |
| 367 | |
| 368 | if (is_debug || force) { |
| 369 | /* |
| 370 | * Do a quiet backtrace so that we have an idea of what the situation |
| 371 | * is WRT the source files. |
| 372 | */ |
Eric Pouech | 800773f | 2001-08-06 17:51:52 +0000 | [diff] [blame] | 373 | DEBUG_BackTrace(DEBUG_CurrTid, FALSE); |
Eric Pouech | 911436b | 2000-06-18 19:30:24 +0000 | [diff] [blame] | 374 | } else { |
| 375 | /* This is a real crash, dump some info */ |
| 376 | DEBUG_InfoRegisters(); |
| 377 | DEBUG_InfoStack(); |
| 378 | #ifdef __i386__ |
Alexandre Julliard | 954a413 | 2000-09-24 03:15:50 +0000 | [diff] [blame] | 379 | if (DEBUG_CurrThread->dbg_mode == MODE_16) { |
Eric Pouech | 911436b | 2000-06-18 19:30:24 +0000 | [diff] [blame] | 380 | DEBUG_InfoSegments(DEBUG_context.SegDs >> 3, 1); |
| 381 | if (DEBUG_context.SegEs != DEBUG_context.SegDs) |
| 382 | DEBUG_InfoSegments(DEBUG_context.SegEs >> 3, 1); |
| 383 | } |
| 384 | DEBUG_InfoSegments(DEBUG_context.SegFs >> 3, 1); |
| 385 | #endif |
Eric Pouech | 800773f | 2001-08-06 17:51:52 +0000 | [diff] [blame] | 386 | DEBUG_BackTrace(DEBUG_CurrTid, TRUE); |
Eric Pouech | 911436b | 2000-06-18 19:30:24 +0000 | [diff] [blame] | 387 | } |
| 388 | |
| 389 | if (!is_debug || |
| 390 | (DEBUG_CurrThread->dbg_exec_mode == EXEC_STEPI_OVER) || |
| 391 | (DEBUG_CurrThread->dbg_exec_mode == EXEC_STEPI_INSTR)) { |
Eric Pouech | 71189b5 | 2000-07-25 12:51:56 +0000 | [diff] [blame] | 392 | |
| 393 | struct list_id list; |
| 394 | |
Eric Pouech | 911436b | 2000-06-18 19:30:24 +0000 | [diff] [blame] | 395 | /* Show where we crashed */ |
| 396 | curr_frame = 0; |
Eric Pouech | 71189b5 | 2000-07-25 12:51:56 +0000 | [diff] [blame] | 397 | DEBUG_DisassembleInstruction(&addr); |
| 398 | |
| 399 | /* resets list internal arguments so we can look at source code when needed */ |
| 400 | DEBUG_FindNearestSymbol(&addr, TRUE, NULL, 0, &list); |
| 401 | if (list.sourcefile) DEBUG_List(&list, NULL, 0); |
Eric Pouech | 911436b | 2000-06-18 19:30:24 +0000 | [diff] [blame] | 402 | } |
| 403 | return TRUE; |
| 404 | } |
| 405 | |
| 406 | static DWORD DEBUG_ExceptionEpilog(void) |
| 407 | { |
| 408 | DEBUG_CurrThread->dbg_exec_mode = DEBUG_RestartExecution(DEBUG_CurrThread->dbg_exec_mode, |
| 409 | DEBUG_CurrThread->dbg_exec_count); |
| 410 | /* |
| 411 | * This will have gotten absorbed into the breakpoint info |
| 412 | * if it was used. Otherwise it would have been ignored. |
| 413 | * In any case, we don't mess with it any more. |
| 414 | */ |
| 415 | if (DEBUG_CurrThread->dbg_exec_mode == EXEC_CONT || DEBUG_CurrThread->dbg_exec_mode == EXEC_PASS) |
| 416 | DEBUG_CurrThread->dbg_exec_count = 0; |
| 417 | |
| 418 | return (DEBUG_CurrThread->dbg_exec_mode == EXEC_PASS) ? DBG_EXCEPTION_NOT_HANDLED : DBG_CONTINUE; |
| 419 | } |
| 420 | |
Eric Pouech | 21b366e | 2002-02-27 01:29:18 +0000 | [diff] [blame] | 421 | static enum exit_mode DEBUG_HandleException(EXCEPTION_RECORD *rec, BOOL first_chance, BOOL force, LPDWORD cont) |
Eric Pouech | 527eea9 | 2000-03-08 16:44:54 +0000 | [diff] [blame] | 422 | { |
James Hatheway | f552359 | 2001-04-09 18:31:47 +0000 | [diff] [blame] | 423 | BOOL is_debug = FALSE; |
Eric Pouech | 21b366e | 2002-02-27 01:29:18 +0000 | [diff] [blame] | 424 | enum exit_mode ret = EXIT_CONT; |
James Hatheway | f552359 | 2001-04-09 18:31:47 +0000 | [diff] [blame] | 425 | THREADNAME_INFO *pThreadName; |
| 426 | DBG_THREAD *pThread; |
| 427 | |
Eric Pouech | 527eea9 | 2000-03-08 16:44:54 +0000 | [diff] [blame] | 428 | |
Eric Pouech | 911436b | 2000-06-18 19:30:24 +0000 | [diff] [blame] | 429 | *cont = DBG_CONTINUE; |
Eric Pouech | 527eea9 | 2000-03-08 16:44:54 +0000 | [diff] [blame] | 430 | |
| 431 | switch (rec->ExceptionCode) |
| 432 | { |
| 433 | case EXCEPTION_BREAKPOINT: |
| 434 | case EXCEPTION_SINGLE_STEP: |
| 435 | is_debug = TRUE; |
| 436 | break; |
James Hatheway | f552359 | 2001-04-09 18:31:47 +0000 | [diff] [blame] | 437 | case EXCEPTION_NAME_THREAD: |
| 438 | pThreadName = (THREADNAME_INFO*)(rec->ExceptionInformation); |
| 439 | if (pThreadName->dwThreadID == -1) |
| 440 | pThread = DEBUG_CurrThread; |
| 441 | else |
| 442 | pThread = DEBUG_GetThread(DEBUG_CurrProcess, pThreadName->dwThreadID); |
| 443 | |
| 444 | if (ReadProcessMemory(DEBUG_CurrThread->process->handle, pThreadName->szName, |
| 445 | pThread->name, 9, NULL)) |
| 446 | DEBUG_Printf (DBG_CHN_MESG, |
| 447 | "Thread ID=0x%lx renamed using MS VC6 extension (name==\"%s\")\n", |
| 448 | pThread->tid, pThread->name); |
Eric Pouech | 21b366e | 2002-02-27 01:29:18 +0000 | [diff] [blame] | 449 | return EXIT_CONT; |
Eric Pouech | 527eea9 | 2000-03-08 16:44:54 +0000 | [diff] [blame] | 450 | } |
| 451 | |
Alexandre Julliard | 840434a | 2001-10-04 16:17:16 +0000 | [diff] [blame] | 452 | if (first_chance && !is_debug && !force && !DBG_IVAR(BreakOnFirstChance)) |
Alexandre Julliard | 954a413 | 2000-09-24 03:15:50 +0000 | [diff] [blame] | 453 | { |
| 454 | /* pass exception to program except for debug exceptions */ |
| 455 | *cont = is_debug ? DBG_CONTINUE : DBG_EXCEPTION_NOT_HANDLED; |
Eric Pouech | 21b366e | 2002-02-27 01:29:18 +0000 | [diff] [blame] | 456 | return EXIT_CONT; |
Alexandre Julliard | 954a413 | 2000-09-24 03:15:50 +0000 | [diff] [blame] | 457 | } |
| 458 | |
Eric Pouech | 527eea9 | 2000-03-08 16:44:54 +0000 | [diff] [blame] | 459 | if (!is_debug) |
| 460 | { |
| 461 | /* print some infos */ |
Eric Pouech | 911436b | 2000-06-18 19:30:24 +0000 | [diff] [blame] | 462 | DEBUG_Printf(DBG_CHN_MESG, "%s: ", |
| 463 | first_chance ? "First chance exception" : "Unhandled exception"); |
Eric Pouech | b971745 | 2000-05-05 18:14:34 +0000 | [diff] [blame] | 464 | switch (rec->ExceptionCode) |
Eric Pouech | 527eea9 | 2000-03-08 16:44:54 +0000 | [diff] [blame] | 465 | { |
| 466 | case EXCEPTION_INT_DIVIDE_BY_ZERO: |
Eric Pouech | 911436b | 2000-06-18 19:30:24 +0000 | [diff] [blame] | 467 | DEBUG_Printf(DBG_CHN_MESG, "divide by zero"); |
Eric Pouech | 527eea9 | 2000-03-08 16:44:54 +0000 | [diff] [blame] | 468 | break; |
| 469 | case EXCEPTION_INT_OVERFLOW: |
Eric Pouech | 911436b | 2000-06-18 19:30:24 +0000 | [diff] [blame] | 470 | DEBUG_Printf(DBG_CHN_MESG, "overflow"); |
Eric Pouech | 527eea9 | 2000-03-08 16:44:54 +0000 | [diff] [blame] | 471 | break; |
| 472 | case EXCEPTION_ARRAY_BOUNDS_EXCEEDED: |
Eric Pouech | 911436b | 2000-06-18 19:30:24 +0000 | [diff] [blame] | 473 | DEBUG_Printf(DBG_CHN_MESG, "array bounds "); |
Eric Pouech | 527eea9 | 2000-03-08 16:44:54 +0000 | [diff] [blame] | 474 | break; |
| 475 | case EXCEPTION_ILLEGAL_INSTRUCTION: |
Eric Pouech | 911436b | 2000-06-18 19:30:24 +0000 | [diff] [blame] | 476 | DEBUG_Printf(DBG_CHN_MESG, "illegal instruction"); |
Eric Pouech | 527eea9 | 2000-03-08 16:44:54 +0000 | [diff] [blame] | 477 | break; |
| 478 | case EXCEPTION_STACK_OVERFLOW: |
Eric Pouech | 911436b | 2000-06-18 19:30:24 +0000 | [diff] [blame] | 479 | DEBUG_Printf(DBG_CHN_MESG, "stack overflow"); |
Eric Pouech | 527eea9 | 2000-03-08 16:44:54 +0000 | [diff] [blame] | 480 | break; |
| 481 | case EXCEPTION_PRIV_INSTRUCTION: |
Andreas Mohr | e15badb | 2001-10-21 15:18:15 +0000 | [diff] [blame] | 482 | DEBUG_Printf(DBG_CHN_MESG, "privileged instruction"); |
Eric Pouech | 527eea9 | 2000-03-08 16:44:54 +0000 | [diff] [blame] | 483 | break; |
| 484 | case EXCEPTION_ACCESS_VIOLATION: |
| 485 | if (rec->NumberParameters == 2) |
Eric Pouech | 911436b | 2000-06-18 19:30:24 +0000 | [diff] [blame] | 486 | DEBUG_Printf(DBG_CHN_MESG, "page fault on %s access to 0x%08lx", |
Eric Pouech | e5efa0c | 2000-04-13 19:31:58 +0000 | [diff] [blame] | 487 | rec->ExceptionInformation[0] ? "write" : "read", |
Eric Pouech | 911436b | 2000-06-18 19:30:24 +0000 | [diff] [blame] | 488 | rec->ExceptionInformation[1]); |
Eric Pouech | 527eea9 | 2000-03-08 16:44:54 +0000 | [diff] [blame] | 489 | else |
Eric Pouech | 911436b | 2000-06-18 19:30:24 +0000 | [diff] [blame] | 490 | DEBUG_Printf(DBG_CHN_MESG, "page fault"); |
Eric Pouech | 527eea9 | 2000-03-08 16:44:54 +0000 | [diff] [blame] | 491 | break; |
| 492 | case EXCEPTION_DATATYPE_MISALIGNMENT: |
Eric Pouech | 911436b | 2000-06-18 19:30:24 +0000 | [diff] [blame] | 493 | DEBUG_Printf(DBG_CHN_MESG, "Alignment"); |
Eric Pouech | 527eea9 | 2000-03-08 16:44:54 +0000 | [diff] [blame] | 494 | break; |
Eric Pouech | d0a0493 | 2001-11-23 23:10:08 +0000 | [diff] [blame] | 495 | case DBG_CONTROL_C: |
| 496 | DEBUG_Printf(DBG_CHN_MESG, "^C"); |
| 497 | break; |
Eric Pouech | 527eea9 | 2000-03-08 16:44:54 +0000 | [diff] [blame] | 498 | case CONTROL_C_EXIT: |
Eric Pouech | 911436b | 2000-06-18 19:30:24 +0000 | [diff] [blame] | 499 | DEBUG_Printf(DBG_CHN_MESG, "^C"); |
Eric Pouech | 527eea9 | 2000-03-08 16:44:54 +0000 | [diff] [blame] | 500 | break; |
| 501 | case EXCEPTION_CRITICAL_SECTION_WAIT: |
Eric Pouech | c2b5cb3 | 2001-08-07 19:32:14 +0000 | [diff] [blame] | 502 | { |
| 503 | DBG_ADDR addr; |
| 504 | |
| 505 | addr.seg = 0; |
| 506 | addr.off = rec->ExceptionInformation[0]; |
| 507 | |
| 508 | DEBUG_Printf(DBG_CHN_MESG, "wait failed on critical section "); |
| 509 | DEBUG_PrintAddress(&addr, DEBUG_CurrThread->dbg_mode, FALSE); |
| 510 | } |
Eric Pouech | 04c16b8 | 2000-04-30 12:21:15 +0000 | [diff] [blame] | 511 | if (!DBG_IVAR(BreakOnCritSectTimeOut)) |
Andreas Mohr | 20cd935 | 2000-09-12 23:40:40 +0000 | [diff] [blame] | 512 | { |
| 513 | DEBUG_Printf(DBG_CHN_MESG, "\n"); |
Eric Pouech | 21b366e | 2002-02-27 01:29:18 +0000 | [diff] [blame] | 514 | return EXIT_CONT; |
Andreas Mohr | 20cd935 | 2000-09-12 23:40:40 +0000 | [diff] [blame] | 515 | } |
Eric Pouech | 527eea9 | 2000-03-08 16:44:54 +0000 | [diff] [blame] | 516 | break; |
Alexandre Julliard | 634824b | 2000-10-26 22:03:34 +0000 | [diff] [blame] | 517 | case EXCEPTION_WINE_STUB: |
| 518 | { |
| 519 | char dll[32], name[64]; |
| 520 | DEBUG_ProcessGetString( dll, sizeof(dll), DEBUG_CurrThread->process->handle, |
| 521 | (char *)rec->ExceptionInformation[0] ); |
| 522 | DEBUG_ProcessGetString( name, sizeof(name), DEBUG_CurrThread->process->handle, |
| 523 | (char *)rec->ExceptionInformation[1] ); |
| 524 | DEBUG_Printf(DBG_CHN_MESG, "unimplemented function %s.%s called", dll, name ); |
| 525 | } |
| 526 | break; |
Alexandre Julliard | 954a413 | 2000-09-24 03:15:50 +0000 | [diff] [blame] | 527 | case EXCEPTION_VM86_INTx: |
| 528 | DEBUG_Printf(DBG_CHN_MESG, "interrupt %02lx in vm86 mode", |
| 529 | rec->ExceptionInformation[0]); |
| 530 | break; |
| 531 | case EXCEPTION_VM86_STI: |
| 532 | DEBUG_Printf(DBG_CHN_MESG, "sti in vm86 mode"); |
| 533 | break; |
| 534 | case EXCEPTION_VM86_PICRETURN: |
| 535 | DEBUG_Printf(DBG_CHN_MESG, "PIC return in vm86 mode"); |
| 536 | break; |
Eric Pouech | 527eea9 | 2000-03-08 16:44:54 +0000 | [diff] [blame] | 537 | default: |
Eric Pouech | 911436b | 2000-06-18 19:30:24 +0000 | [diff] [blame] | 538 | DEBUG_Printf(DBG_CHN_MESG, "%08lx", rec->ExceptionCode); |
Eric Pouech | 527eea9 | 2000-03-08 16:44:54 +0000 | [diff] [blame] | 539 | break; |
| 540 | } |
| 541 | } |
| 542 | |
Eric Pouech | 38f2be4 | 2001-08-15 17:40:31 +0000 | [diff] [blame] | 543 | #if 0 |
Eric Pouech | e5efa0c | 2000-04-13 19:31:58 +0000 | [diff] [blame] | 544 | DEBUG_Printf(DBG_CHN_TRACE, |
| 545 | "Entering debugger PC=%lx EFL=%08lx mode=%d count=%d\n", |
Ulrich Weigand | 1cbf27a | 2000-06-04 01:33:21 +0000 | [diff] [blame] | 546 | #ifdef __i386__ |
Eric Pouech | e5efa0c | 2000-04-13 19:31:58 +0000 | [diff] [blame] | 547 | DEBUG_context.Eip, DEBUG_context.EFlags, |
Ulrich Weigand | 1cbf27a | 2000-06-04 01:33:21 +0000 | [diff] [blame] | 548 | #else |
| 549 | 0L, 0L, |
| 550 | #endif |
Eric Pouech | e5efa0c | 2000-04-13 19:31:58 +0000 | [diff] [blame] | 551 | DEBUG_CurrThread->dbg_exec_mode, DEBUG_CurrThread->dbg_exec_count); |
Eric Pouech | 38f2be4 | 2001-08-15 17:40:31 +0000 | [diff] [blame] | 552 | #endif |
Eric Pouech | 527eea9 | 2000-03-08 16:44:54 +0000 | [diff] [blame] | 553 | |
Alexandre Julliard | f5a8b96 | 2001-10-22 19:00:34 +0000 | [diff] [blame] | 554 | if (automatic_mode) |
| 555 | { |
| 556 | DEBUG_ExceptionProlog(is_debug, FALSE, rec->ExceptionCode); |
Eric Pouech | 21b366e | 2002-02-27 01:29:18 +0000 | [diff] [blame] | 557 | return EXIT_QUIT; /* terminate execution */ |
Alexandre Julliard | f5a8b96 | 2001-10-22 19:00:34 +0000 | [diff] [blame] | 558 | } |
| 559 | |
Eric Pouech | 911436b | 2000-06-18 19:30:24 +0000 | [diff] [blame] | 560 | if (DEBUG_ExceptionProlog(is_debug, force, rec->ExceptionCode)) { |
Eric Pouech | 52c7534 | 2001-05-03 18:32:47 +0000 | [diff] [blame] | 561 | DEBUG_interactiveP = TRUE; |
Eric Pouech | 21b366e | 2002-02-27 01:29:18 +0000 | [diff] [blame] | 562 | while ((ret = DEBUG_Parser()) == EXIT_CONT) { |
Eric Pouech | 5b471ba | 2000-06-25 12:49:13 +0000 | [diff] [blame] | 563 | if (DEBUG_ValidateRegisters()) { |
| 564 | if (DEBUG_CurrThread->dbg_exec_mode != EXEC_PASS || first_chance) |
| 565 | break; |
| 566 | DEBUG_Printf(DBG_CHN_MESG, "Cannot pass on last chance exception. You must use cont\n"); |
| 567 | } |
Eric Pouech | 911436b | 2000-06-18 19:30:24 +0000 | [diff] [blame] | 568 | } |
Eric Pouech | 52c7534 | 2001-05-03 18:32:47 +0000 | [diff] [blame] | 569 | DEBUG_interactiveP = FALSE; |
Eric Pouech | 911436b | 2000-06-18 19:30:24 +0000 | [diff] [blame] | 570 | } |
| 571 | *cont = DEBUG_ExceptionEpilog(); |
Eric Pouech | e5efa0c | 2000-04-13 19:31:58 +0000 | [diff] [blame] | 572 | |
Eric Pouech | 38f2be4 | 2001-08-15 17:40:31 +0000 | [diff] [blame] | 573 | #if 0 |
Eric Pouech | e5efa0c | 2000-04-13 19:31:58 +0000 | [diff] [blame] | 574 | DEBUG_Printf(DBG_CHN_TRACE, |
| 575 | "Exiting debugger PC=%lx EFL=%08lx mode=%d count=%d\n", |
Ulrich Weigand | 1cbf27a | 2000-06-04 01:33:21 +0000 | [diff] [blame] | 576 | #ifdef __i386__ |
Eric Pouech | e5efa0c | 2000-04-13 19:31:58 +0000 | [diff] [blame] | 577 | DEBUG_context.Eip, DEBUG_context.EFlags, |
Ulrich Weigand | 1cbf27a | 2000-06-04 01:33:21 +0000 | [diff] [blame] | 578 | #else |
| 579 | 0L, 0L, |
| 580 | #endif |
Eric Pouech | e5efa0c | 2000-04-13 19:31:58 +0000 | [diff] [blame] | 581 | DEBUG_CurrThread->dbg_exec_mode, DEBUG_CurrThread->dbg_exec_count); |
Eric Pouech | 38f2be4 | 2001-08-15 17:40:31 +0000 | [diff] [blame] | 582 | #endif |
Eric Pouech | 527eea9 | 2000-03-08 16:44:54 +0000 | [diff] [blame] | 583 | |
| 584 | return ret; |
| 585 | } |
| 586 | |
Eric Pouech | e5efa0c | 2000-04-13 19:31:58 +0000 | [diff] [blame] | 587 | static BOOL DEBUG_HandleDebugEvent(DEBUG_EVENT* de, LPDWORD cont) |
Eric Pouech | 527eea9 | 2000-03-08 16:44:54 +0000 | [diff] [blame] | 588 | { |
Eric Pouech | 527eea9 | 2000-03-08 16:44:54 +0000 | [diff] [blame] | 589 | char buffer[256]; |
Eric Pouech | 21b366e | 2002-02-27 01:29:18 +0000 | [diff] [blame] | 590 | enum exit_mode ret; |
Eric Pouech | 911436b | 2000-06-18 19:30:24 +0000 | [diff] [blame] | 591 | |
Eric Pouech | f182235 | 2000-05-11 21:43:43 +0000 | [diff] [blame] | 592 | DEBUG_CurrPid = de->dwProcessId; |
| 593 | DEBUG_CurrTid = de->dwThreadId; |
| 594 | |
Eric Pouech | ac11a68 | 2000-03-26 13:37:39 +0000 | [diff] [blame] | 595 | __TRY { |
Eric Pouech | 21b366e | 2002-02-27 01:29:18 +0000 | [diff] [blame] | 596 | ret = EXIT_CONT; |
Eric Pouech | e5efa0c | 2000-04-13 19:31:58 +0000 | [diff] [blame] | 597 | *cont = 0L; |
Eric Pouech | ac11a68 | 2000-03-26 13:37:39 +0000 | [diff] [blame] | 598 | |
| 599 | if ((DEBUG_CurrProcess = DEBUG_GetProcess(de->dwProcessId)) != NULL) |
| 600 | DEBUG_CurrThread = DEBUG_GetThread(DEBUG_CurrProcess, de->dwThreadId); |
Eric Pouech | 527eea9 | 2000-03-08 16:44:54 +0000 | [diff] [blame] | 601 | else |
| 602 | DEBUG_CurrThread = NULL; |
Eric Pouech | ac11a68 | 2000-03-26 13:37:39 +0000 | [diff] [blame] | 603 | |
| 604 | switch (de->dwDebugEventCode) { |
Eric Pouech | 527eea9 | 2000-03-08 16:44:54 +0000 | [diff] [blame] | 605 | case EXCEPTION_DEBUG_EVENT: |
Eric Pouech | e5efa0c | 2000-04-13 19:31:58 +0000 | [diff] [blame] | 606 | if (!DEBUG_CurrThread) { |
| 607 | DEBUG_Printf(DBG_CHN_ERR, "%08lx:%08lx: not a registered process or thread (perhaps a 16 bit one ?)\n", |
| 608 | de->dwProcessId, de->dwThreadId); |
| 609 | break; |
| 610 | } |
Eric Pouech | ac11a68 | 2000-03-26 13:37:39 +0000 | [diff] [blame] | 611 | |
Eric Pouech | b971745 | 2000-05-05 18:14:34 +0000 | [diff] [blame] | 612 | DEBUG_Printf(DBG_CHN_TRACE, "%08lx:%08lx: exception code=%08lx\n", |
Eric Pouech | e5efa0c | 2000-04-13 19:31:58 +0000 | [diff] [blame] | 613 | de->dwProcessId, de->dwThreadId, |
Eric Pouech | b971745 | 2000-05-05 18:14:34 +0000 | [diff] [blame] | 614 | de->u.Exception.ExceptionRecord.ExceptionCode); |
| 615 | |
| 616 | if (DEBUG_CurrProcess->continue_on_first_exception) { |
| 617 | DEBUG_CurrProcess->continue_on_first_exception = FALSE; |
| 618 | if (!DBG_IVAR(BreakOnAttach)) { |
| 619 | *cont = DBG_CONTINUE; |
| 620 | break; |
| 621 | } |
| 622 | } |
| 623 | |
Ulrich Weigand | 1cbf27a | 2000-06-04 01:33:21 +0000 | [diff] [blame] | 624 | DEBUG_context.ContextFlags = CONTEXT_CONTROL |
| 625 | | CONTEXT_INTEGER |
| 626 | #ifdef CONTEXT_SEGMENTS |
| 627 | | CONTEXT_SEGMENTS |
| 628 | #endif |
| 629 | #ifdef CONTEXT_DEBUG_REGISTERS |
| 630 | | CONTEXT_DEBUG_REGISTERS |
| 631 | #endif |
| 632 | ; |
| 633 | |
Eric Pouech | 527eea9 | 2000-03-08 16:44:54 +0000 | [diff] [blame] | 634 | if (!GetThreadContext(DEBUG_CurrThread->handle, &DEBUG_context)) { |
Eric Pouech | e5efa0c | 2000-04-13 19:31:58 +0000 | [diff] [blame] | 635 | DEBUG_Printf(DBG_CHN_WARN, "Can't get thread's context\n"); |
Eric Pouech | 527eea9 | 2000-03-08 16:44:54 +0000 | [diff] [blame] | 636 | break; |
| 637 | } |
Eric Pouech | ac11a68 | 2000-03-26 13:37:39 +0000 | [diff] [blame] | 638 | |
Eric Pouech | 911436b | 2000-06-18 19:30:24 +0000 | [diff] [blame] | 639 | ret = DEBUG_HandleException(&de->u.Exception.ExceptionRecord, |
| 640 | de->u.Exception.dwFirstChance, |
| 641 | DEBUG_CurrThread->wait_for_first_exception, |
| 642 | cont); |
| 643 | if (DEBUG_CurrThread) { |
Eric Pouech | 527eea9 | 2000-03-08 16:44:54 +0000 | [diff] [blame] | 644 | DEBUG_CurrThread->wait_for_first_exception = 0; |
Eric Pouech | e5efa0c | 2000-04-13 19:31:58 +0000 | [diff] [blame] | 645 | SetThreadContext(DEBUG_CurrThread->handle, &DEBUG_context); |
Eric Pouech | 527eea9 | 2000-03-08 16:44:54 +0000 | [diff] [blame] | 646 | } |
Eric Pouech | 527eea9 | 2000-03-08 16:44:54 +0000 | [diff] [blame] | 647 | break; |
| 648 | |
| 649 | case CREATE_THREAD_DEBUG_EVENT: |
Eric Pouech | f182235 | 2000-05-11 21:43:43 +0000 | [diff] [blame] | 650 | DEBUG_Printf(DBG_CHN_TRACE, "%08lx:%08lx: create thread D @%08lx\n", de->dwProcessId, de->dwThreadId, |
| 651 | (unsigned long)(LPVOID)de->u.CreateThread.lpStartAddress); |
Eric Pouech | 527eea9 | 2000-03-08 16:44:54 +0000 | [diff] [blame] | 652 | |
| 653 | if (DEBUG_CurrProcess == NULL) { |
Eric Pouech | e5efa0c | 2000-04-13 19:31:58 +0000 | [diff] [blame] | 654 | DEBUG_Printf(DBG_CHN_ERR, "Unknown process\n"); |
Eric Pouech | 527eea9 | 2000-03-08 16:44:54 +0000 | [diff] [blame] | 655 | break; |
| 656 | } |
Eric Pouech | ac11a68 | 2000-03-26 13:37:39 +0000 | [diff] [blame] | 657 | if (DEBUG_GetThread(DEBUG_CurrProcess, de->dwThreadId) != NULL) { |
Eric Pouech | e5efa0c | 2000-04-13 19:31:58 +0000 | [diff] [blame] | 658 | DEBUG_Printf(DBG_CHN_TRACE, "Thread already listed, skipping\n"); |
Eric Pouech | 527eea9 | 2000-03-08 16:44:54 +0000 | [diff] [blame] | 659 | break; |
| 660 | } |
Eric Pouech | ac11a68 | 2000-03-26 13:37:39 +0000 | [diff] [blame] | 661 | |
Eric Pouech | 527eea9 | 2000-03-08 16:44:54 +0000 | [diff] [blame] | 662 | DEBUG_CurrThread = DEBUG_AddThread(DEBUG_CurrProcess, |
Eric Pouech | ac11a68 | 2000-03-26 13:37:39 +0000 | [diff] [blame] | 663 | de->dwThreadId, |
| 664 | de->u.CreateThread.hThread, |
| 665 | de->u.CreateThread.lpStartAddress, |
| 666 | de->u.CreateThread.lpThreadLocalBase); |
Eric Pouech | 527eea9 | 2000-03-08 16:44:54 +0000 | [diff] [blame] | 667 | if (!DEBUG_CurrThread) { |
Eric Pouech | e5efa0c | 2000-04-13 19:31:58 +0000 | [diff] [blame] | 668 | DEBUG_Printf(DBG_CHN_ERR, "Couldn't create thread\n"); |
Eric Pouech | 527eea9 | 2000-03-08 16:44:54 +0000 | [diff] [blame] | 669 | break; |
| 670 | } |
| 671 | DEBUG_InitCurrThread(); |
| 672 | break; |
| 673 | |
| 674 | case CREATE_PROCESS_DEBUG_EVENT: |
Alexandre Julliard | 0966a6d | 2000-03-10 22:25:07 +0000 | [diff] [blame] | 675 | DEBUG_ProcessGetStringIndirect(buffer, sizeof(buffer), |
Eric Pouech | ac11a68 | 2000-03-26 13:37:39 +0000 | [diff] [blame] | 676 | de->u.CreateProcessInfo.hProcess, |
Eric Pouech | e5efa0c | 2000-04-13 19:31:58 +0000 | [diff] [blame] | 677 | de->u.CreateProcessInfo.lpImageName); |
Eric Pouech | 800773f | 2001-08-06 17:51:52 +0000 | [diff] [blame] | 678 | |
Eric Pouech | ac11a68 | 2000-03-26 13:37:39 +0000 | [diff] [blame] | 679 | /* FIXME unicode ? de->u.CreateProcessInfo.fUnicode */ |
Eric Pouech | 800773f | 2001-08-06 17:51:52 +0000 | [diff] [blame] | 680 | DEBUG_Printf(DBG_CHN_TRACE, "%08lx:%08lx: create process '%s'/%p @%08lx (%ld<%ld>)\n", |
Eric Pouech | e5efa0c | 2000-04-13 19:31:58 +0000 | [diff] [blame] | 681 | de->dwProcessId, de->dwThreadId, |
Eric Pouech | 800773f | 2001-08-06 17:51:52 +0000 | [diff] [blame] | 682 | buffer, de->u.CreateProcessInfo.lpImageName, |
Eric Pouech | f182235 | 2000-05-11 21:43:43 +0000 | [diff] [blame] | 683 | (unsigned long)(LPVOID)de->u.CreateProcessInfo.lpStartAddress, |
Eric Pouech | e5efa0c | 2000-04-13 19:31:58 +0000 | [diff] [blame] | 684 | de->u.CreateProcessInfo.dwDebugInfoFileOffset, |
| 685 | de->u.CreateProcessInfo.nDebugInfoSize); |
Eric Pouech | 527eea9 | 2000-03-08 16:44:54 +0000 | [diff] [blame] | 686 | |
Eric Pouech | b971745 | 2000-05-05 18:14:34 +0000 | [diff] [blame] | 687 | if ((DEBUG_CurrProcess = DEBUG_GetProcess(de->dwProcessId)) != NULL) { |
| 688 | if (DEBUG_CurrProcess->handle) { |
| 689 | DEBUG_Printf(DBG_CHN_ERR, "Skipping already defined process\n"); |
| 690 | break; |
| 691 | } |
| 692 | DEBUG_CurrProcess->handle = de->u.CreateProcessInfo.hProcess; |
Eric Pouech | 800773f | 2001-08-06 17:51:52 +0000 | [diff] [blame] | 693 | if (DEBUG_CurrProcess->imageName == NULL) |
| 694 | DEBUG_CurrProcess->imageName = DBG_strdup(buffer[0] ? buffer : "<Debugged Process>"); |
| 695 | |
Eric Pouech | b971745 | 2000-05-05 18:14:34 +0000 | [diff] [blame] | 696 | } else { |
| 697 | DEBUG_CurrProcess = DEBUG_AddProcess(de->dwProcessId, |
Eric Pouech | 800773f | 2001-08-06 17:51:52 +0000 | [diff] [blame] | 698 | de->u.CreateProcessInfo.hProcess, |
| 699 | buffer[0] ? buffer : "<Debugged Process>"); |
Eric Pouech | b971745 | 2000-05-05 18:14:34 +0000 | [diff] [blame] | 700 | if (DEBUG_CurrProcess == NULL) { |
| 701 | DEBUG_Printf(DBG_CHN_ERR, "Unknown process\n"); |
| 702 | break; |
| 703 | } |
Eric Pouech | 527eea9 | 2000-03-08 16:44:54 +0000 | [diff] [blame] | 704 | } |
| 705 | |
Eric Pouech | f182235 | 2000-05-11 21:43:43 +0000 | [diff] [blame] | 706 | DEBUG_Printf(DBG_CHN_TRACE, "%08lx:%08lx: create thread I @%08lx\n", |
Eric Pouech | e5efa0c | 2000-04-13 19:31:58 +0000 | [diff] [blame] | 707 | de->dwProcessId, de->dwThreadId, |
Eric Pouech | f182235 | 2000-05-11 21:43:43 +0000 | [diff] [blame] | 708 | (unsigned long)(LPVOID)de->u.CreateProcessInfo.lpStartAddress); |
Eric Pouech | 527eea9 | 2000-03-08 16:44:54 +0000 | [diff] [blame] | 709 | |
| 710 | DEBUG_CurrThread = DEBUG_AddThread(DEBUG_CurrProcess, |
Eric Pouech | ac11a68 | 2000-03-26 13:37:39 +0000 | [diff] [blame] | 711 | de->dwThreadId, |
| 712 | de->u.CreateProcessInfo.hThread, |
| 713 | de->u.CreateProcessInfo.lpStartAddress, |
| 714 | de->u.CreateProcessInfo.lpThreadLocalBase); |
Eric Pouech | 527eea9 | 2000-03-08 16:44:54 +0000 | [diff] [blame] | 715 | if (!DEBUG_CurrThread) { |
Eric Pouech | e5efa0c | 2000-04-13 19:31:58 +0000 | [diff] [blame] | 716 | DEBUG_Printf(DBG_CHN_ERR, "Couldn't create thread\n"); |
Eric Pouech | 527eea9 | 2000-03-08 16:44:54 +0000 | [diff] [blame] | 717 | break; |
| 718 | } |
| 719 | |
| 720 | DEBUG_InitCurrProcess(); |
| 721 | DEBUG_InitCurrThread(); |
Alexandre Julliard | 291fa66 | 2000-06-08 05:02:19 +0000 | [diff] [blame] | 722 | |
Eric Pouech | 800773f | 2001-08-06 17:51:52 +0000 | [diff] [blame] | 723 | DEBUG_LoadModule32(DEBUG_CurrProcess->imageName, de->u.CreateProcessInfo.hFile, |
Eric Pouech | e5efa0c | 2000-04-13 19:31:58 +0000 | [diff] [blame] | 724 | (DWORD)de->u.CreateProcessInfo.lpBaseOfImage); |
Alexandre Julliard | 291fa66 | 2000-06-08 05:02:19 +0000 | [diff] [blame] | 725 | |
| 726 | if (buffer[0]) /* we got a process name */ |
| 727 | { |
| 728 | DWORD type; |
| 729 | if (!GetBinaryTypeA( buffer, &type )) |
| 730 | { |
| 731 | /* not a Windows binary, assume it's a Unix executable then */ |
Alexandre Julliard | 633293f | 2000-12-06 03:20:47 +0000 | [diff] [blame] | 732 | char unixname[MAX_PATH]; |
Alexandre Julliard | 291fa66 | 2000-06-08 05:02:19 +0000 | [diff] [blame] | 733 | /* HACK!! should fix DEBUG_ReadExecutableDbgInfo to accept DOS filenames */ |
Alexandre Julliard | 633293f | 2000-12-06 03:20:47 +0000 | [diff] [blame] | 734 | if (wine_get_unix_file_name( buffer, unixname, sizeof(unixname) )) |
Alexandre Julliard | 291fa66 | 2000-06-08 05:02:19 +0000 | [diff] [blame] | 735 | { |
Alexandre Julliard | 633293f | 2000-12-06 03:20:47 +0000 | [diff] [blame] | 736 | DEBUG_ReadExecutableDbgInfo( unixname ); |
Alexandre Julliard | 291fa66 | 2000-06-08 05:02:19 +0000 | [diff] [blame] | 737 | break; |
| 738 | } |
| 739 | } |
| 740 | } |
| 741 | /* if it is a Windows binary, or an invalid or missing file name, |
| 742 | * we use wine itself as the main executable */ |
| 743 | DEBUG_ReadExecutableDbgInfo( "wine" ); |
Eric Pouech | 527eea9 | 2000-03-08 16:44:54 +0000 | [diff] [blame] | 744 | break; |
| 745 | |
| 746 | case EXIT_THREAD_DEBUG_EVENT: |
Eric Pouech | e5efa0c | 2000-04-13 19:31:58 +0000 | [diff] [blame] | 747 | DEBUG_Printf(DBG_CHN_TRACE, "%08lx:%08lx: exit thread (%ld)\n", |
| 748 | de->dwProcessId, de->dwThreadId, de->u.ExitThread.dwExitCode); |
Eric Pouech | ac11a68 | 2000-03-26 13:37:39 +0000 | [diff] [blame] | 749 | |
Eric Pouech | 527eea9 | 2000-03-08 16:44:54 +0000 | [diff] [blame] | 750 | if (DEBUG_CurrThread == NULL) { |
Eric Pouech | e5efa0c | 2000-04-13 19:31:58 +0000 | [diff] [blame] | 751 | DEBUG_Printf(DBG_CHN_ERR, "Unknown thread\n"); |
Eric Pouech | 527eea9 | 2000-03-08 16:44:54 +0000 | [diff] [blame] | 752 | break; |
| 753 | } |
| 754 | /* FIXME: remove break point set on thread startup */ |
| 755 | DEBUG_DelThread(DEBUG_CurrThread); |
| 756 | break; |
| 757 | |
| 758 | case EXIT_PROCESS_DEBUG_EVENT: |
Eric Pouech | e5efa0c | 2000-04-13 19:31:58 +0000 | [diff] [blame] | 759 | DEBUG_Printf(DBG_CHN_TRACE, "%08lx:%08lx: exit process (%ld)\n", |
| 760 | de->dwProcessId, de->dwThreadId, de->u.ExitProcess.dwExitCode); |
Eric Pouech | ac11a68 | 2000-03-26 13:37:39 +0000 | [diff] [blame] | 761 | |
Eric Pouech | 527eea9 | 2000-03-08 16:44:54 +0000 | [diff] [blame] | 762 | if (DEBUG_CurrProcess == NULL) { |
Eric Pouech | e5efa0c | 2000-04-13 19:31:58 +0000 | [diff] [blame] | 763 | DEBUG_Printf(DBG_CHN_ERR, "Unknown process\n"); |
Eric Pouech | 527eea9 | 2000-03-08 16:44:54 +0000 | [diff] [blame] | 764 | break; |
| 765 | } |
Eric Pouech | e5efa0c | 2000-04-13 19:31:58 +0000 | [diff] [blame] | 766 | /* just in case */ |
| 767 | DEBUG_SetBreakpoints(FALSE); |
Eric Pouech | 527eea9 | 2000-03-08 16:44:54 +0000 | [diff] [blame] | 768 | /* kill last thread */ |
| 769 | DEBUG_DelThread(DEBUG_CurrProcess->threads); |
Eric Pouech | 527eea9 | 2000-03-08 16:44:54 +0000 | [diff] [blame] | 770 | DEBUG_DelProcess(DEBUG_CurrProcess); |
Eric Pouech | 911436b | 2000-06-18 19:30:24 +0000 | [diff] [blame] | 771 | |
| 772 | DEBUG_Printf(DBG_CHN_MESG, "Process of pid=%08lx has terminated\n", DEBUG_CurrPid); |
Eric Pouech | 527eea9 | 2000-03-08 16:44:54 +0000 | [diff] [blame] | 773 | break; |
| 774 | |
| 775 | case LOAD_DLL_DEBUG_EVENT: |
| 776 | if (DEBUG_CurrThread == NULL) { |
Eric Pouech | e5efa0c | 2000-04-13 19:31:58 +0000 | [diff] [blame] | 777 | DEBUG_Printf(DBG_CHN_ERR, "Unknown thread\n"); |
Eric Pouech | 527eea9 | 2000-03-08 16:44:54 +0000 | [diff] [blame] | 778 | break; |
| 779 | } |
Alexandre Julliard | 0966a6d | 2000-03-10 22:25:07 +0000 | [diff] [blame] | 780 | DEBUG_ProcessGetStringIndirect(buffer, sizeof(buffer), |
| 781 | DEBUG_CurrThread->process->handle, |
Eric Pouech | ac11a68 | 2000-03-26 13:37:39 +0000 | [diff] [blame] | 782 | de->u.LoadDll.lpImageName); |
Eric Pouech | 527eea9 | 2000-03-08 16:44:54 +0000 | [diff] [blame] | 783 | |
Eric Pouech | ac11a68 | 2000-03-26 13:37:39 +0000 | [diff] [blame] | 784 | /* FIXME unicode: de->u.LoadDll.fUnicode */ |
Eric Pouech | f182235 | 2000-05-11 21:43:43 +0000 | [diff] [blame] | 785 | DEBUG_Printf(DBG_CHN_TRACE, "%08lx:%08lx: loads DLL %s @%08lx (%ld<%ld>)\n", |
Eric Pouech | e5efa0c | 2000-04-13 19:31:58 +0000 | [diff] [blame] | 786 | de->dwProcessId, de->dwThreadId, |
Eric Pouech | f182235 | 2000-05-11 21:43:43 +0000 | [diff] [blame] | 787 | buffer, (unsigned long)de->u.LoadDll.lpBaseOfDll, |
Eric Pouech | e5efa0c | 2000-04-13 19:31:58 +0000 | [diff] [blame] | 788 | de->u.LoadDll.dwDebugInfoFileOffset, |
| 789 | de->u.LoadDll.nDebugInfoSize); |
Alexandre Julliard | 09d7822 | 2001-05-05 00:44:48 +0000 | [diff] [blame] | 790 | _strupr(buffer); |
Eric Pouech | e5efa0c | 2000-04-13 19:31:58 +0000 | [diff] [blame] | 791 | DEBUG_LoadModule32(buffer, de->u.LoadDll.hFile, (DWORD)de->u.LoadDll.lpBaseOfDll); |
Eric Pouech | eaafb73 | 2001-05-21 18:33:15 +0000 | [diff] [blame] | 792 | DEBUG_CheckDelayedBP(); |
Eric Pouech | f516be6 | 2000-07-10 13:05:44 +0000 | [diff] [blame] | 793 | if (DBG_IVAR(BreakOnDllLoad)) { |
| 794 | DEBUG_Printf(DBG_CHN_MESG, "Stopping on DLL %s loading at %08lx\n", |
| 795 | buffer, (unsigned long)de->u.LoadDll.lpBaseOfDll); |
| 796 | ret = DEBUG_Parser(); |
| 797 | } |
Eric Pouech | 527eea9 | 2000-03-08 16:44:54 +0000 | [diff] [blame] | 798 | break; |
| 799 | |
| 800 | case UNLOAD_DLL_DEBUG_EVENT: |
Eric Pouech | f182235 | 2000-05-11 21:43:43 +0000 | [diff] [blame] | 801 | DEBUG_Printf(DBG_CHN_TRACE, "%08lx:%08lx: unload DLL @%08lx\n", de->dwProcessId, de->dwThreadId, |
| 802 | (unsigned long)de->u.UnloadDll.lpBaseOfDll); |
Eric Pouech | 527eea9 | 2000-03-08 16:44:54 +0000 | [diff] [blame] | 803 | break; |
| 804 | |
| 805 | case OUTPUT_DEBUG_STRING_EVENT: |
| 806 | if (DEBUG_CurrThread == NULL) { |
Eric Pouech | e5efa0c | 2000-04-13 19:31:58 +0000 | [diff] [blame] | 807 | DEBUG_Printf(DBG_CHN_ERR, "Unknown thread\n"); |
Eric Pouech | 527eea9 | 2000-03-08 16:44:54 +0000 | [diff] [blame] | 808 | break; |
| 809 | } |
Eric Pouech | ac11a68 | 2000-03-26 13:37:39 +0000 | [diff] [blame] | 810 | |
Eric Pouech | 527eea9 | 2000-03-08 16:44:54 +0000 | [diff] [blame] | 811 | DEBUG_ProcessGetString(buffer, sizeof(buffer), |
| 812 | DEBUG_CurrThread->process->handle, |
Eric Pouech | ac11a68 | 2000-03-26 13:37:39 +0000 | [diff] [blame] | 813 | de->u.DebugString.lpDebugStringData); |
Eric Pouech | 527eea9 | 2000-03-08 16:44:54 +0000 | [diff] [blame] | 814 | |
Dimitrie O. Paun | 693cca5 | 2002-01-29 03:12:19 +0000 | [diff] [blame] | 815 | /* FIXME unicode de->u.DebugString.fUnicode ? */ |
Eric Pouech | e5efa0c | 2000-04-13 19:31:58 +0000 | [diff] [blame] | 816 | DEBUG_Printf(DBG_CHN_TRACE, "%08lx:%08lx: output debug string (%s)\n", |
| 817 | de->dwProcessId, de->dwThreadId, buffer); |
Eric Pouech | 527eea9 | 2000-03-08 16:44:54 +0000 | [diff] [blame] | 818 | break; |
| 819 | |
| 820 | case RIP_EVENT: |
Eric Pouech | e5efa0c | 2000-04-13 19:31:58 +0000 | [diff] [blame] | 821 | DEBUG_Printf(DBG_CHN_TRACE, "%08lx:%08lx: rip error=%ld type=%ld\n", |
| 822 | de->dwProcessId, de->dwThreadId, de->u.RipInfo.dwError, |
| 823 | de->u.RipInfo.dwType); |
Eric Pouech | 527eea9 | 2000-03-08 16:44:54 +0000 | [diff] [blame] | 824 | break; |
| 825 | |
| 826 | default: |
Eric Pouech | e5efa0c | 2000-04-13 19:31:58 +0000 | [diff] [blame] | 827 | DEBUG_Printf(DBG_CHN_TRACE, "%08lx:%08lx: unknown event (%ld)\n", |
| 828 | de->dwProcessId, de->dwThreadId, de->dwDebugEventCode); |
Eric Pouech | 527eea9 | 2000-03-08 16:44:54 +0000 | [diff] [blame] | 829 | } |
Eric Pouech | ac11a68 | 2000-03-26 13:37:39 +0000 | [diff] [blame] | 830 | |
| 831 | } __EXCEPT(wine_dbg) { |
Eric Pouech | e5efa0c | 2000-04-13 19:31:58 +0000 | [diff] [blame] | 832 | *cont = 0; |
Eric Pouech | 21b366e | 2002-02-27 01:29:18 +0000 | [diff] [blame] | 833 | ret = EXIT_CONT; |
Eric Pouech | ac11a68 | 2000-03-26 13:37:39 +0000 | [diff] [blame] | 834 | } |
| 835 | __ENDTRY; |
Eric Pouech | e5efa0c | 2000-04-13 19:31:58 +0000 | [diff] [blame] | 836 | return ret; |
Eric Pouech | ac11a68 | 2000-03-26 13:37:39 +0000 | [diff] [blame] | 837 | } |
| 838 | |
Eric Pouech | 911436b | 2000-06-18 19:30:24 +0000 | [diff] [blame] | 839 | static DWORD DEBUG_MainLoop(void) |
Eric Pouech | ac11a68 | 2000-03-26 13:37:39 +0000 | [diff] [blame] | 840 | { |
| 841 | DEBUG_EVENT de; |
| 842 | DWORD cont; |
Eric Pouech | 21b366e | 2002-02-27 01:29:18 +0000 | [diff] [blame] | 843 | enum exit_mode ret = EXIT_CONT; |
Eric Pouech | ac11a68 | 2000-03-26 13:37:39 +0000 | [diff] [blame] | 844 | |
Alexandre Julliard | 954a413 | 2000-09-24 03:15:50 +0000 | [diff] [blame] | 845 | DEBUG_Printf(DBG_CHN_MESG, " on pid %lx\n", DEBUG_CurrPid); |
Eric Pouech | e5efa0c | 2000-04-13 19:31:58 +0000 | [diff] [blame] | 846 | |
Eric Pouech | 21b366e | 2002-02-27 01:29:18 +0000 | [diff] [blame] | 847 | while (ret == EXIT_CONT) |
| 848 | { |
Eric Pouech | 911436b | 2000-06-18 19:30:24 +0000 | [diff] [blame] | 849 | /* wait until we get at least one loaded process */ |
Eric Pouech | 21b366e | 2002-02-27 01:29:18 +0000 | [diff] [blame] | 850 | while (!DEBUG_ProcessList && (ret = DEBUG_Parser()) == EXIT_CONT); |
| 851 | if (ret != EXIT_CONT) break; |
Eric Pouech | 911436b | 2000-06-18 19:30:24 +0000 | [diff] [blame] | 852 | |
Eric Pouech | 21b366e | 2002-02-27 01:29:18 +0000 | [diff] [blame] | 853 | while (ret == EXIT_CONT && DEBUG_ProcessList && WaitForDebugEvent(&de, INFINITE)) { |
Eric Pouech | 911436b | 2000-06-18 19:30:24 +0000 | [diff] [blame] | 854 | ret = DEBUG_HandleDebugEvent(&de, &cont); |
| 855 | ContinueDebugEvent(de.dwProcessId, de.dwThreadId, cont); |
| 856 | } |
Eric Pouech | 21b366e | 2002-02-27 01:29:18 +0000 | [diff] [blame] | 857 | if (ret == EXIT_DETACH && DEBUG_Detach()) |
| 858 | { |
| 859 | /* ret = EXIT_CONT; */ |
| 860 | /* FIXME: as we don't have a simple way to zero out the process symbol table |
| 861 | * we simply quit the debugger on detach... |
| 862 | */ |
| 863 | ret = EXIT_QUIT; |
| 864 | } |
| 865 | } |
Eric Pouech | 527eea9 | 2000-03-08 16:44:54 +0000 | [diff] [blame] | 866 | |
Alexandre Julliard | 954a413 | 2000-09-24 03:15:50 +0000 | [diff] [blame] | 867 | DEBUG_Printf(DBG_CHN_MESG, "WineDbg terminated on pid %lx\n", DEBUG_CurrPid); |
Eric Pouech | 04c16b8 | 2000-04-30 12:21:15 +0000 | [diff] [blame] | 868 | |
| 869 | return 0; |
Eric Pouech | 527eea9 | 2000-03-08 16:44:54 +0000 | [diff] [blame] | 870 | } |
| 871 | |
Alexandre Julliard | f5a8b96 | 2001-10-22 19:00:34 +0000 | [diff] [blame] | 872 | static DWORD DEBUG_AutoMode(void) |
| 873 | { |
| 874 | DEBUG_EVENT de; |
| 875 | DWORD cont; |
Eric Pouech | 21b366e | 2002-02-27 01:29:18 +0000 | [diff] [blame] | 876 | enum exit_mode ret = EXIT_CONT; |
Alexandre Julliard | f5a8b96 | 2001-10-22 19:00:34 +0000 | [diff] [blame] | 877 | |
| 878 | DEBUG_Printf(DBG_CHN_MESG, " on pid %lx\n", DEBUG_CurrPid); |
| 879 | |
Eric Pouech | 21b366e | 2002-02-27 01:29:18 +0000 | [diff] [blame] | 880 | while (ret == EXIT_CONT && DEBUG_ProcessList && WaitForDebugEvent(&de, INFINITE)) |
Alexandre Julliard | f5a8b96 | 2001-10-22 19:00:34 +0000 | [diff] [blame] | 881 | { |
| 882 | ret = DEBUG_HandleDebugEvent(&de, &cont); |
| 883 | ContinueDebugEvent(de.dwProcessId, de.dwThreadId, cont); |
| 884 | } |
| 885 | /* print some extra information */ |
| 886 | DEBUG_Printf(DBG_CHN_MESG, "Modules:\n"); |
| 887 | DEBUG_WalkModules(); |
| 888 | DEBUG_Printf(DBG_CHN_MESG, "Threads:\n"); |
| 889 | DEBUG_WalkThreads(); |
| 890 | |
| 891 | DEBUG_Printf(DBG_CHN_MESG, "WineDbg terminated on pid %lx\n", DEBUG_CurrPid); |
| 892 | return 0; |
| 893 | } |
| 894 | |
Eric Pouech | 911436b | 2000-06-18 19:30:24 +0000 | [diff] [blame] | 895 | static BOOL DEBUG_Start(LPSTR cmdLine) |
| 896 | { |
| 897 | PROCESS_INFORMATION info; |
| 898 | STARTUPINFOA startup; |
| 899 | |
| 900 | memset(&startup, 0, sizeof(startup)); |
| 901 | startup.cb = sizeof(startup); |
| 902 | startup.dwFlags = STARTF_USESHOWWINDOW; |
| 903 | startup.wShowWindow = SW_SHOWNORMAL; |
| 904 | |
| 905 | if (!CreateProcess(NULL, cmdLine, NULL, NULL, |
Eric Pouech | d0a0493 | 2001-11-23 23:10:08 +0000 | [diff] [blame] | 906 | FALSE, DEBUG_PROCESS|DETACHED_PROCESS, NULL, NULL, &startup, &info)) { |
Eric Pouech | 911436b | 2000-06-18 19:30:24 +0000 | [diff] [blame] | 907 | DEBUG_Printf(DBG_CHN_MESG, "Couldn't start process '%s'\n", cmdLine); |
| 908 | return FALSE; |
| 909 | } |
| 910 | DEBUG_CurrPid = info.dwProcessId; |
Eric Pouech | 800773f | 2001-08-06 17:51:52 +0000 | [diff] [blame] | 911 | if (!(DEBUG_CurrProcess = DEBUG_AddProcess(DEBUG_CurrPid, 0, NULL))) return FALSE; |
Eric Pouech | 911436b | 2000-06-18 19:30:24 +0000 | [diff] [blame] | 912 | |
| 913 | return TRUE; |
| 914 | } |
| 915 | |
| 916 | void DEBUG_Run(const char* args) |
| 917 | { |
| 918 | DBG_MODULE* wmod = DEBUG_GetProcessMainModule(DEBUG_CurrProcess); |
| 919 | const char* pgm = (wmod) ? wmod->module_name : "none"; |
| 920 | |
| 921 | if (args) { |
| 922 | DEBUG_Printf(DBG_CHN_MESG, "Run (%s) with '%s'\n", pgm, args); |
| 923 | } else { |
| 924 | if (!DEBUG_LastCmdLine) { |
| 925 | DEBUG_Printf(DBG_CHN_MESG, "Cannot find previously used command line.\n"); |
| 926 | return; |
| 927 | } |
| 928 | DEBUG_Start(DEBUG_LastCmdLine); |
| 929 | } |
| 930 | } |
| 931 | |
Eric Pouech | d0a0493 | 2001-11-23 23:10:08 +0000 | [diff] [blame] | 932 | static void DEBUG_InitConsole(void) |
| 933 | { |
| 934 | COORD c; |
| 935 | SMALL_RECT sr; |
| 936 | DWORD mode; |
| 937 | |
| 938 | /* keep it as a cuiexe for now, so that Wine won't touch the Unix stdin, |
| 939 | * stdout and stderr streams |
| 940 | */ |
| 941 | if (DBG_IVAR(UseXTerm)) |
| 942 | { |
| 943 | FreeConsole(); |
| 944 | AllocConsole(); |
| 945 | } |
Eric Pouech | 21b366e | 2002-02-27 01:29:18 +0000 | [diff] [blame] | 946 | |
Eric Pouech | d0a0493 | 2001-11-23 23:10:08 +0000 | [diff] [blame] | 947 | /* this would be nicer for output */ |
| 948 | c.X = 132; |
| 949 | c.Y = 500; |
| 950 | SetConsoleScreenBufferSize(GetStdHandle(STD_OUTPUT_HANDLE), c); |
| 951 | |
| 952 | /* sets the console's window width accordingly */ |
| 953 | sr.Left = 0; |
| 954 | sr.Top = 0; |
| 955 | sr.Right = c.X - 1; |
| 956 | sr.Bottom = 50; |
| 957 | SetConsoleWindowInfo(GetStdHandle(STD_OUTPUT_HANDLE), TRUE, &sr); |
| 958 | |
| 959 | /* put the line editing mode with the nice emacs features (FIXME: could be triggered by a IVAR) */ |
| 960 | if (GetConsoleMode(GetStdHandle(STD_INPUT_HANDLE), &mode)) |
| 961 | SetConsoleMode(GetStdHandle(STD_INPUT_HANDLE), mode | WINE_ENABLE_LINE_INPUT_EMACS); |
| 962 | } |
| 963 | |
Eric Pouech | 04c16b8 | 2000-04-30 12:21:15 +0000 | [diff] [blame] | 964 | int DEBUG_main(int argc, char** argv) |
Eric Pouech | 527eea9 | 2000-03-08 16:44:54 +0000 | [diff] [blame] | 965 | { |
Eric Pouech | 911436b | 2000-06-18 19:30:24 +0000 | [diff] [blame] | 966 | DWORD retv = 0; |
Eric Pouech | e5efa0c | 2000-04-13 19:31:58 +0000 | [diff] [blame] | 967 | |
Eric Pouech | 04c16b8 | 2000-04-30 12:21:15 +0000 | [diff] [blame] | 968 | /* Initialize the type handling stuff. */ |
| 969 | DEBUG_InitTypes(); |
| 970 | DEBUG_InitCVDataTypes(); |
Eric Pouech | 527eea9 | 2000-03-08 16:44:54 +0000 | [diff] [blame] | 971 | |
Eric Pouech | 800773f | 2001-08-06 17:51:52 +0000 | [diff] [blame] | 972 | /* Initialize internal vars (types must have been initialized before) */ |
Eric Pouech | 26342c9 | 2000-05-01 14:22:02 +0000 | [diff] [blame] | 973 | if (!DEBUG_IntVarsRW(TRUE)) return -1; |
Eric Pouech | 04c16b8 | 2000-04-30 12:21:15 +0000 | [diff] [blame] | 974 | |
Alexandre Julliard | f5a8b96 | 2001-10-22 19:00:34 +0000 | [diff] [blame] | 975 | if (argc > 1 && !strcmp( argv[1], "--auto" )) |
| 976 | { |
| 977 | argc--; |
| 978 | argv++; |
| 979 | automatic_mode = 1; |
| 980 | /* force some internal variables */ |
| 981 | DBG_IVAR(UseXTerm) = 0; |
| 982 | DBG_IVAR(BreakOnDllLoad) = 0; |
| 983 | DBG_IVAR(ConChannelMask) = 0; |
| 984 | DBG_IVAR(StdChannelMask) = DBG_CHN_MESG; |
| 985 | } |
| 986 | |
Eric Pouech | d0a0493 | 2001-11-23 23:10:08 +0000 | [diff] [blame] | 987 | DEBUG_InitConsole(); |
| 988 | |
Andreas Mohr | a59324d | 2000-11-25 01:40:10 +0000 | [diff] [blame] | 989 | DEBUG_Printf(DBG_CHN_MESG, "WineDbg starting... "); |
Eric Pouech | 52c7534 | 2001-05-03 18:32:47 +0000 | [diff] [blame] | 990 | |
Eric Pouech | 04c16b8 | 2000-04-30 12:21:15 +0000 | [diff] [blame] | 991 | if (argc == 3) { |
| 992 | HANDLE hEvent; |
Eric Pouech | 911436b | 2000-06-18 19:30:24 +0000 | [diff] [blame] | 993 | DWORD pid; |
Eric Pouech | e5efa0c | 2000-04-13 19:31:58 +0000 | [diff] [blame] | 994 | |
François Gouget | d5042c4 | 2000-12-29 05:38:00 +0000 | [diff] [blame] | 995 | if ((pid = atoi(argv[1])) != 0 && (hEvent = (HANDLE)atoi(argv[2])) != 0) { |
Eric Pouech | 2b713ba | 2001-04-13 22:26:23 +0000 | [diff] [blame] | 996 | if (!DEBUG_Attach(pid, TRUE)) { |
Eric Pouech | 2b713ba | 2001-04-13 22:26:23 +0000 | [diff] [blame] | 997 | /* don't care about result */ |
| 998 | SetEvent(hEvent); |
Eric Pouech | f182235 | 2000-05-11 21:43:43 +0000 | [diff] [blame] | 999 | goto leave; |
| 1000 | } |
Eric Pouech | 2b713ba | 2001-04-13 22:26:23 +0000 | [diff] [blame] | 1001 | if (!SetEvent(hEvent)) { |
| 1002 | DEBUG_Printf(DBG_CHN_ERR, "Invalid event handle: %p\n", hEvent); |
| 1003 | goto leave; |
| 1004 | } |
| 1005 | CloseHandle(hEvent); |
Eric Pouech | 911436b | 2000-06-18 19:30:24 +0000 | [diff] [blame] | 1006 | DEBUG_CurrPid = pid; |
Eric Pouech | f182235 | 2000-05-11 21:43:43 +0000 | [diff] [blame] | 1007 | } |
| 1008 | } |
| 1009 | |
Eric Pouech | 911436b | 2000-06-18 19:30:24 +0000 | [diff] [blame] | 1010 | if (DEBUG_CurrPid == 0 && argc > 1) { |
| 1011 | int i, len; |
| 1012 | LPSTR cmdLine; |
| 1013 | |
| 1014 | if (!(cmdLine = DBG_alloc(len = 1))) goto oom_leave; |
| 1015 | cmdLine[0] = '\0'; |
Eric Pouech | e5efa0c | 2000-04-13 19:31:58 +0000 | [diff] [blame] | 1016 | |
Eric Pouech | 911436b | 2000-06-18 19:30:24 +0000 | [diff] [blame] | 1017 | for (i = 1; i < argc; i++) { |
| 1018 | len += strlen(argv[i]) + 1; |
| 1019 | if (!(cmdLine = DBG_realloc(cmdLine, len))) goto oom_leave; |
| 1020 | strcat(cmdLine, argv[i]); |
| 1021 | cmdLine[len - 2] = ' '; |
| 1022 | cmdLine[len - 1] = '\0'; |
| 1023 | } |
Eric Pouech | e5efa0c | 2000-04-13 19:31:58 +0000 | [diff] [blame] | 1024 | |
Eric Pouech | 911436b | 2000-06-18 19:30:24 +0000 | [diff] [blame] | 1025 | if (!DEBUG_Start(cmdLine)) { |
| 1026 | DEBUG_Printf(DBG_CHN_MESG, "Couldn't start process '%s'\n", cmdLine); |
Eric Pouech | 04c16b8 | 2000-04-30 12:21:15 +0000 | [diff] [blame] | 1027 | goto leave; |
Eric Pouech | e5efa0c | 2000-04-13 19:31:58 +0000 | [diff] [blame] | 1028 | } |
Eric Pouech | 911436b | 2000-06-18 19:30:24 +0000 | [diff] [blame] | 1029 | DBG_free(DEBUG_LastCmdLine); |
| 1030 | DEBUG_LastCmdLine = cmdLine; |
Eric Pouech | 04c16b8 | 2000-04-30 12:21:15 +0000 | [diff] [blame] | 1031 | } |
| 1032 | |
Alexandre Julliard | f5a8b96 | 2001-10-22 19:00:34 +0000 | [diff] [blame] | 1033 | if (automatic_mode) |
| 1034 | { |
| 1035 | retv = DEBUG_AutoMode(); |
| 1036 | /* don't save modified variables in auto mode */ |
| 1037 | } |
| 1038 | else |
| 1039 | { |
| 1040 | retv = DEBUG_MainLoop(); |
| 1041 | /* saves modified variables */ |
| 1042 | DEBUG_IntVarsRW(FALSE); |
| 1043 | } |
Eric Pouech | 04c16b8 | 2000-04-30 12:21:15 +0000 | [diff] [blame] | 1044 | |
Eric Pouech | 800773f | 2001-08-06 17:51:52 +0000 | [diff] [blame] | 1045 | leave: |
Eric Pouech | 04c16b8 | 2000-04-30 12:21:15 +0000 | [diff] [blame] | 1046 | return retv; |
Eric Pouech | 911436b | 2000-06-18 19:30:24 +0000 | [diff] [blame] | 1047 | |
| 1048 | oom_leave: |
| 1049 | DEBUG_Printf(DBG_CHN_MESG, "Out of memory\n"); |
| 1050 | goto leave; |
Eric Pouech | cbb7a17 | 2000-03-09 18:45:43 +0000 | [diff] [blame] | 1051 | } |