23 #include "gdb/fileio.h"
37 #include <sys/cygwin.h>
40 #define OUTMSG(X) do { printf X; fflush (stderr); } while (0)
53 #define _T(x) TEXT (x)
57 #define COUNTOF(STR) (sizeof (STR) / sizeof ((STR)[0]))
61 # define GETPROCADDRESS(DLL, PROC) \
62 ((winapi_ ## PROC) GetProcAddress (DLL, TEXT (#PROC)))
64 # define GETPROCADDRESS(DLL, PROC) \
65 ((winapi_ ## PROC) GetProcAddress (DLL, #PROC))
75 static enum gdb_signal
last_sig = GDB_SIGNAL_0;
95 #define NUM_REGS (the_low_target.num_regs)
97 typedef BOOL (WINAPI *winapi_DebugActiveProcessStop) (DWORD dwProcessId);
98 typedef BOOL (WINAPI *winapi_DebugSetProcessKillOnExit) (
BOOL KillOnExit);
99 typedef BOOL (WINAPI *winapi_DebugBreakProcess) (
HANDLE);
100 typedef BOOL (WINAPI *winapi_GenerateConsoleCtrlEvent) (
DWORD,
DWORD);
121 return ptid_build (event->dwProcessId, event->dwThreadId, 0);
129 memset (&th->
context, 0, sizeof (CONTEXT));
132 memcpy (&th->base_context, &th->
context, sizeof (CONTEXT));
152 if (memcmp (&th->
context, &th->base_context, sizeof (CONTEXT)) != 0)
154 SetThreadContext (th->
h, &th->
context);
171 if (th->
context.ContextFlags == 0)
175 if (SuspendThread (th->
h) == (DWORD) -1)
177 DWORD err = GetLastError ();
178 OUTMSG ((
"warning: SuspendThread failed in thread_rec, "
179 "(error %d): %s\n", (
int) err,
strwinerror (err)));
217 th =
xcalloc (1,
sizeof (*th));
319 uintptr_t addr = (uintptr_t) memaddr;
323 success = WriteProcessMemory (current_process_handle, (LPVOID) addr,
324 (LPCVOID) our, len, &done);
326 lasterror = GetLastError ();
327 FlushInstructionCache (current_process_handle, (LPCVOID) addr, len);
331 success = ReadProcessMemory (current_process_handle, (LPCVOID) addr,
332 (LPVOID) our, len, &done);
334 lasterror = GetLastError ();
336 if (!success && lasterror == ERROR_PARTIAL_COPY && done > 0)
339 return success ? done : -1;
359 last_sig = GDB_SIGNAL_0;
361 current_process_handle = proch;
362 current_process_id = pid;
365 soft_interrupt_requested = 0;
366 faked_breakpoint = 0;
368 memset (¤t_event, 0,
sizeof (current_event));
373 child_initialization_done = 0;
384 struct target_waitstatus status;
389 if (status.kind != TARGET_WAITKIND_LOADED)
399 resume.
kind = resume_continue;
425 child_initialization_done = 1;
434 int thread_id = * (
int *) id_ptr;
437 if (thread_id == -1 || thread_id == th->
tid)
449 if (ResumeThread (th->
h) == (DWORD) -1)
451 DWORD err = GetLastError ();
452 OUTMSG ((
"warning: ResumeThread failed in continue_one_thread, "
453 "(error %d): %s\n", (
int) err,
strwinerror (err)));
468 faked_breakpoint = 0;
470 if (!ContinueDebugEvent (current_event.dwProcessId,
471 current_event.dwThreadId,
487 for (regno = 0; regno < r; regno++)
498 if (r == -1 || r == 0 || r >
NUM_REGS)
501 for (regno = 0; regno < r; regno++)
518 static char buf[1024];
520 DWORD lasterr = GetLastError ();
521 DWORD chars = FormatMessage (FORMAT_MESSAGE_FROM_SYSTEM
522 | FORMAT_MESSAGE_ALLOCATE_BUFFER,
533 && msgbuf[chars - 2] ==
'\r'
534 && msgbuf[chars - 1] ==
'\n')
540 if (chars > ((
COUNTOF (buf)) - 1))
547 wcstombs (buf, msgbuf, chars + 1);
549 strncpy (buf, msgbuf, chars + 1);
554 sprintf (buf,
"unknown win32 error (%u)", (
unsigned) error);
556 SetLastError (lasterr);
562 DWORD flags, PROCESS_INFORMATION *pi)
567 wchar_t *p, *wprogram, *wargs;
570 wprogram =
alloca ((strlen (program) + 1) *
sizeof (
wchar_t));
571 mbstowcs (wprogram, program, strlen (program) + 1);
573 for (p = wprogram; *p; ++p)
577 argslen = strlen (args);
578 wargs =
alloca ((argslen + 1) *
sizeof (
wchar_t));
579 mbstowcs (wargs, args, argslen + 1);
581 ret = CreateProcessW (wprogram,
592 STARTUPINFOA si = {
sizeof (STARTUPINFOA) };
594 ret = CreateProcessA (program,
619 char real_path[PATH_MAX];
620 char *orig_path, *new_path, *path_ptr;
627 PROCESS_INFORMATION pi;
634 error (
"No executable specified, specify executable to debug.\n");
636 flags = DEBUG_PROCESS | DEBUG_ONLY_THIS_PROCESS;
640 path_ptr = getenv (
"PATH");
643 int size = cygwin_conv_path_list (CCP_POSIX_TO_WIN_A, path_ptr, NULL, 0);
644 orig_path =
alloca (strlen (path_ptr) + 1);
646 strcpy (orig_path, path_ptr);
647 cygwin_conv_path_list (CCP_POSIX_TO_WIN_A, path_ptr, new_path, size);
648 setenv (
"PATH", new_path, 1);
650 cygwin_conv_path (CCP_POSIX_TO_WIN_A, program, real_path, PATH_MAX);
655 for (argc = 1; program_args[argc]; argc++)
656 argslen += strlen (program_args[argc]) + 1;
659 for (argc = 1; program_args[argc]; argc++)
664 strcat (args, program_args[argc]);
666 OUTMSG2 ((
"Command line is \"%s\"\n", args));
668 #ifdef CREATE_NEW_PROCESS_GROUP
669 flags |= CREATE_NEW_PROCESS_GROUP;
673 err = GetLastError ();
674 if (!ret && err == ERROR_FILE_NOT_FOUND)
676 char *exename =
alloca (strlen (program) + 5);
677 strcat (strcpy (exename, program),
".exe");
679 err = GetLastError ();
684 setenv (
"PATH", orig_path, 1);
689 error (
"Error creating process \"%s%s\", (error %d): %s\n",
694 OUTMSG2 ((
"Process created: %s\n", (
char *) args));
701 CloseHandle (pi.hThread);
716 winapi_DebugSetProcessKillOnExit DebugSetProcessKillOnExit = NULL;
719 HMODULE dll = GetModuleHandle (
_T(
"COREDLL.DLL"));
721 HMODULE dll = GetModuleHandle (
_T(
"KERNEL32.DLL"));
723 DebugSetProcessKillOnExit =
GETPROCADDRESS (dll, DebugSetProcessKillOnExit);
725 h = OpenProcess (PROCESS_ALL_ACCESS, FALSE, pid);
728 if (DebugActiveProcess (pid))
730 if (DebugSetProcessKillOnExit != NULL)
731 DebugSetProcessKillOnExit (FALSE);
742 err = GetLastError ();
743 error (
"Attach to process failed (error %d): %s\n",
751 #define READ_BUFFER_LEN 1024
754 DWORD nbytes = current_event.u.DebugString.nDebugStringLength;
762 addr = (
CORE_ADDR) (
size_t) current_event.u.DebugString.lpDebugStringData;
764 if (current_event.u.DebugString.fUnicode)
771 wcstombs (s, buffer, (nbytes + 1) /
sizeof (WCHAR));
789 #undef READ_BUFFER_LEN
795 if (current_process_handle != NULL)
796 CloseHandle (current_process_handle);
808 if (current_process_handle == NULL)
811 TerminateProcess (current_process_handle, 0);
816 if (!WaitForDebugEvent (¤t_event, INFINITE))
818 if (current_event.dwDebugEventCode == EXIT_PROCESS_DEBUG_EVENT)
820 else if (current_event.dwDebugEventCode == OUTPUT_DEBUG_STRING_EVENT)
822 struct target_waitstatus our_status = { 0 };
839 winapi_DebugActiveProcessStop DebugActiveProcessStop = NULL;
840 winapi_DebugSetProcessKillOnExit DebugSetProcessKillOnExit = NULL;
842 HMODULE dll = GetModuleHandle (
_T(
"COREDLL.DLL"));
844 HMODULE dll = GetModuleHandle (
_T(
"KERNEL32.DLL"));
846 DebugActiveProcessStop =
GETPROCADDRESS (dll, DebugActiveProcessStop);
847 DebugSetProcessKillOnExit =
GETPROCADDRESS (dll, DebugSetProcessKillOnExit);
849 if (DebugSetProcessKillOnExit == NULL
850 || DebugActiveProcessStop == NULL)
856 resume.
kind = resume_continue;
861 if (!DebugActiveProcessStop (current_process_id))
864 DebugSetProcessKillOnExit (FALSE);
882 HANDLE h = OpenProcess (PROCESS_ALL_ACCESS, FALSE, pid);
885 WaitForSingleObject (h, INFINITE);
914 DWORD continue_status = DBG_CONTINUE;
927 tid = current_event.dwThreadId;
931 sig = resume_info[0].
sig;
932 step = resume_info[0].
kind == resume_step;
940 if (sig != GDB_SIGNAL_0)
942 if (current_event.dwDebugEventCode != EXCEPTION_DEBUG_EVENT)
944 OUTMSG ((
"Cannot continue with signal %d here.\n", sig));
946 else if (sig == last_sig)
947 continue_status = DBG_EXCEPTION_NOT_HANDLED;
949 OUTMSG ((
"Can only continue with recieved signal %d.\n", last_sig));
952 last_sig = GDB_SIGNAL_0;
972 error (
"Single stepping is not supported "
973 "in this configuration.\n");
990 char buf[MAX_PATH + 1];
991 char buf2[MAX_PATH + 1];
994 WIN32_FIND_DATA w32_fd;
995 WCHAR wname[MAX_PATH + 1];
996 mbstowcs (wname, name, MAX_PATH);
997 HANDLE h = FindFirstFile (wname, &w32_fd);
999 WIN32_FIND_DATAA w32_fd;
1000 HANDLE h = FindFirstFileA (name, &w32_fd);
1006 load_addr += 0x1000;
1008 if (h == INVALID_HANDLE_VALUE)
1016 char cwd[MAX_PATH + 1];
1018 if (GetCurrentDirectoryA (MAX_PATH + 1, cwd))
1020 p = strrchr (buf,
'\\');
1023 SetCurrentDirectoryA (buf);
1024 GetFullPathNameA (w32_fd.cFileName, MAX_PATH, buf, &p);
1025 SetCurrentDirectoryA (cwd);
1032 if (strcasecmp (buf,
"ntdll.dll") == 0)
1034 GetSystemDirectoryA (buf,
sizeof (buf));
1035 strcat (buf,
"\\ntdll.dll");
1040 cygwin_conv_path (CCP_WIN_A_TO_POSIX, buf, buf2,
sizeof (buf2));
1051 static char buf[(2 * MAX_PATH) + 1];
1052 DWORD size = unicode ?
sizeof (WCHAR) :
sizeof (
char);
1061 if (address == NULL)
1067 address_ptr = address;
1071 if (!ReadProcessMemory (h, address, &address_ptr,
1072 sizeof (address_ptr), &done)
1073 || done !=
sizeof (address_ptr)
1079 while (ReadProcessMemory (h, address_ptr + len++ * size, &b, size, &done)
1080 && (b[0] != 0 || b[size - 1] != 0) && done == size)
1084 ReadProcessMemory (h, address_ptr, buf, len, &done);
1087 WCHAR *unicode_address = (WCHAR *)
alloca (len *
sizeof (WCHAR));
1088 ReadProcessMemory (h, address_ptr, unicode_address, len *
sizeof (WCHAR),
1091 WideCharToMultiByte (CP_ACP, 0, unicode_address, len, buf, len, 0, 0);
1097 typedef BOOL (WINAPI *winapi_EnumProcessModules) (
HANDLE, HMODULE *,
1111 static int psapi_loaded = 0;
1112 static HMODULE dll = NULL;
1117 dll = LoadLibrary (TEXT(
"psapi.dll"));
1120 win32_EnumProcessModules =
1122 win32_GetModuleInformation =
1124 win32_GetModuleFileNameExA =
1128 return (win32_EnumProcessModules != NULL
1129 && win32_GetModuleInformation != NULL
1130 && win32_GetModuleFileNameExA != NULL);
1143 HMODULE *DllHandle = dh_buf;
1156 if (!ok || !cbNeeded)
1159 DllHandle = (HMODULE *)
alloca (cbNeeded);
1170 for (i = 1; i < ((size_t) cbNeeded /
sizeof (HMODULE)); i++)
1173 char dll_name[MAX_PATH];
1204 LOAD_DLL_DEBUG_INFO *
event = ¤t_event.u.LoadDll;
1208 event->lpImageName, event->fUnicode);
1226 (
CORE_ADDR) (uintptr_t) current_event.u.UnloadDll.lpBaseOfDll;
1231 load_addr += 0x1000;
1238 DWORD code = current_event.u.Exception.ExceptionRecord.ExceptionCode;
1240 ourstatus->kind = TARGET_WAITKIND_STOPPED;
1244 case EXCEPTION_ACCESS_VIOLATION:
1245 OUTMSG2 ((
"EXCEPTION_ACCESS_VIOLATION"));
1246 ourstatus->value.sig = GDB_SIGNAL_SEGV;
1248 case STATUS_STACK_OVERFLOW:
1249 OUTMSG2 ((
"STATUS_STACK_OVERFLOW"));
1250 ourstatus->value.sig = GDB_SIGNAL_SEGV;
1252 case STATUS_FLOAT_DENORMAL_OPERAND:
1253 OUTMSG2 ((
"STATUS_FLOAT_DENORMAL_OPERAND"));
1254 ourstatus->value.sig = GDB_SIGNAL_FPE;
1256 case EXCEPTION_ARRAY_BOUNDS_EXCEEDED:
1257 OUTMSG2 ((
"EXCEPTION_ARRAY_BOUNDS_EXCEEDED"));
1258 ourstatus->value.sig = GDB_SIGNAL_FPE;
1260 case STATUS_FLOAT_INEXACT_RESULT:
1261 OUTMSG2 ((
"STATUS_FLOAT_INEXACT_RESULT"));
1262 ourstatus->value.sig = GDB_SIGNAL_FPE;
1264 case STATUS_FLOAT_INVALID_OPERATION:
1265 OUTMSG2 ((
"STATUS_FLOAT_INVALID_OPERATION"));
1266 ourstatus->value.sig = GDB_SIGNAL_FPE;
1268 case STATUS_FLOAT_OVERFLOW:
1269 OUTMSG2 ((
"STATUS_FLOAT_OVERFLOW"));
1270 ourstatus->value.sig = GDB_SIGNAL_FPE;
1272 case STATUS_FLOAT_STACK_CHECK:
1273 OUTMSG2 ((
"STATUS_FLOAT_STACK_CHECK"));
1274 ourstatus->value.sig = GDB_SIGNAL_FPE;
1276 case STATUS_FLOAT_UNDERFLOW:
1277 OUTMSG2 ((
"STATUS_FLOAT_UNDERFLOW"));
1278 ourstatus->value.sig = GDB_SIGNAL_FPE;
1280 case STATUS_FLOAT_DIVIDE_BY_ZERO:
1281 OUTMSG2 ((
"STATUS_FLOAT_DIVIDE_BY_ZERO"));
1282 ourstatus->value.sig = GDB_SIGNAL_FPE;
1284 case STATUS_INTEGER_DIVIDE_BY_ZERO:
1285 OUTMSG2 ((
"STATUS_INTEGER_DIVIDE_BY_ZERO"));
1286 ourstatus->value.sig = GDB_SIGNAL_FPE;
1288 case STATUS_INTEGER_OVERFLOW:
1289 OUTMSG2 ((
"STATUS_INTEGER_OVERFLOW"));
1290 ourstatus->value.sig = GDB_SIGNAL_FPE;
1292 case EXCEPTION_BREAKPOINT:
1293 OUTMSG2 ((
"EXCEPTION_BREAKPOINT"));
1294 ourstatus->value.sig = GDB_SIGNAL_TRAP;
1298 .u.Exception.ExceptionRecord.ExceptionAddress);
1303 ourstatus->value.sig = GDB_SIGNAL_INT;
1305 case DBG_CONTROL_BREAK:
1306 OUTMSG2 ((
"DBG_CONTROL_BREAK"));
1307 ourstatus->value.sig = GDB_SIGNAL_INT;
1309 case EXCEPTION_SINGLE_STEP:
1310 OUTMSG2 ((
"EXCEPTION_SINGLE_STEP"));
1311 ourstatus->value.sig = GDB_SIGNAL_TRAP;
1313 case EXCEPTION_ILLEGAL_INSTRUCTION:
1314 OUTMSG2 ((
"EXCEPTION_ILLEGAL_INSTRUCTION"));
1315 ourstatus->value.sig = GDB_SIGNAL_ILL;
1317 case EXCEPTION_PRIV_INSTRUCTION:
1318 OUTMSG2 ((
"EXCEPTION_PRIV_INSTRUCTION"));
1319 ourstatus->value.sig = GDB_SIGNAL_ILL;
1321 case EXCEPTION_NONCONTINUABLE_EXCEPTION:
1322 OUTMSG2 ((
"EXCEPTION_NONCONTINUABLE_EXCEPTION"));
1323 ourstatus->value.sig = GDB_SIGNAL_ILL;
1326 if (current_event.u.Exception.dwFirstChance)
1328 ourstatus->kind = TARGET_WAITKIND_SPURIOUS;
1331 OUTMSG2 ((
"gdbserver: unknown target exception 0x%08x at 0x%s",
1332 (
unsigned) current_event.u.Exception.ExceptionRecord.ExceptionCode,
1333 phex_nz ((uintptr_t) current_event.u.Exception.ExceptionRecord.
1334 ExceptionAddress, sizeof (uintptr_t))));
1335 ourstatus->value.sig = GDB_SIGNAL_UNKNOWN;
1339 last_sig = ourstatus->value.sig;
1351 if (SuspendThread (th->
h) == (DWORD) -1)
1353 DWORD err = GetLastError ();
1354 OUTMSG ((
"warning: SuspendThread failed in suspend_one_thread, "
1355 "(error %d): %s\n", (
int) err,
strwinerror (err)));
1365 OUTMSG2((
"fake_breakpoint_event\n"));
1367 faked_breakpoint = 1;
1369 memset (¤t_event, 0,
sizeof (current_event));
1371 current_event.dwDebugEventCode = EXCEPTION_DEBUG_EVENT;
1372 current_event.u.Exception.ExceptionRecord.ExceptionCode
1373 = EXCEPTION_BREAKPOINT;
1380 auto_delete_breakpoint (
CORE_ADDR stop_pc)
1393 last_sig = GDB_SIGNAL_0;
1394 ourstatus->kind = TARGET_WAITKIND_SPURIOUS;
1399 if (soft_interrupt_requested)
1401 soft_interrupt_requested = 0;
1425 current_event.dwDebugEventCode = 0;
1426 if (!WaitForDebugEvent (¤t_event, 0))
1428 OUTMSG2((
"no attach events left\n"));
1433 OUTMSG2((
"got attach event\n"));
1441 if (!WaitForDebugEvent (¤t_event, 250))
1443 DWORD e = GetLastError();
1445 if (e == ERROR_PIPE_NOT_CONNECTED)
1451 ourstatus->kind = TARGET_WAITKIND_EXITED;
1452 ourstatus->value.integer = 1;
1462 switch (current_event.dwDebugEventCode)
1464 case CREATE_THREAD_DEBUG_EVENT:
1465 OUTMSG2 ((
"gdbserver: kernel event CREATE_THREAD_DEBUG_EVENT "
1466 "for pid=%u tid=%x)\n",
1467 (
unsigned) current_event.dwProcessId,
1468 (
unsigned) current_event.dwThreadId));
1472 current_event.dwThreadId,
1473 current_event.u.CreateThread.hThread,
1474 current_event.u.CreateThread.lpThreadLocalBase);
1477 case EXIT_THREAD_DEBUG_EVENT:
1478 OUTMSG2 ((
"gdbserver: kernel event EXIT_THREAD_DEBUG_EVENT "
1479 "for pid=%u tid=%x\n",
1480 (
unsigned) current_event.dwProcessId,
1481 (
unsigned) current_event.dwThreadId));
1483 current_event.dwThreadId);
1488 case CREATE_PROCESS_DEBUG_EVENT:
1489 OUTMSG2 ((
"gdbserver: kernel event CREATE_PROCESS_DEBUG_EVENT "
1490 "for pid=%u tid=%x\n",
1491 (
unsigned) current_event.dwProcessId,
1492 (
unsigned) current_event.dwThreadId));
1493 CloseHandle (current_event.u.CreateProcessInfo.hFile);
1495 current_process_handle = current_event.u.CreateProcessInfo.hProcess;
1496 main_thread_id = current_event.dwThreadId;
1498 ourstatus->kind = TARGET_WAITKIND_EXECD;
1499 ourstatus->value.execd_pathname =
"Main executable";
1504 current_event.u.CreateProcessInfo.hThread,
1505 current_event.u.CreateProcessInfo.lpThreadLocalBase);
1516 .CreateProcessInfo.lpStartAddress,
1517 auto_delete_breakpoint);
1522 case EXIT_PROCESS_DEBUG_EVENT:
1523 OUTMSG2 ((
"gdbserver: kernel event EXIT_PROCESS_DEBUG_EVENT "
1524 "for pid=%u tid=%x\n",
1525 (
unsigned) current_event.dwProcessId,
1526 (
unsigned) current_event.dwThreadId));
1527 ourstatus->kind = TARGET_WAITKIND_EXITED;
1528 ourstatus->value.integer = current_event.u.ExitProcess.dwExitCode;
1530 CloseHandle (current_process_handle);
1531 current_process_handle = NULL;
1534 case LOAD_DLL_DEBUG_EVENT:
1535 OUTMSG2 ((
"gdbserver: kernel event LOAD_DLL_DEBUG_EVENT "
1536 "for pid=%u tid=%x\n",
1537 (
unsigned) current_event.dwProcessId,
1538 (
unsigned) current_event.dwThreadId));
1539 CloseHandle (current_event.u.LoadDll.hFile);
1540 if (! child_initialization_done)
1544 ourstatus->kind = TARGET_WAITKIND_LOADED;
1545 ourstatus->value.sig = GDB_SIGNAL_TRAP;
1548 case UNLOAD_DLL_DEBUG_EVENT:
1549 OUTMSG2 ((
"gdbserver: kernel event UNLOAD_DLL_DEBUG_EVENT "
1550 "for pid=%u tid=%x\n",
1551 (
unsigned) current_event.dwProcessId,
1552 (
unsigned) current_event.dwThreadId));
1553 if (! child_initialization_done)
1556 ourstatus->kind = TARGET_WAITKIND_LOADED;
1557 ourstatus->value.sig = GDB_SIGNAL_TRAP;
1560 case EXCEPTION_DEBUG_EVENT:
1561 OUTMSG2 ((
"gdbserver: kernel event EXCEPTION_DEBUG_EVENT "
1562 "for pid=%u tid=%x\n",
1563 (
unsigned) current_event.dwProcessId,
1564 (
unsigned) current_event.dwThreadId));
1568 case OUTPUT_DEBUG_STRING_EVENT:
1570 OUTMSG2 ((
"gdbserver: kernel event OUTPUT_DEBUG_STRING_EVENT "
1571 "for pid=%u tid=%x\n",
1572 (
unsigned) current_event.dwProcessId,
1573 (
unsigned) current_event.dwThreadId));
1578 OUTMSG2 ((
"gdbserver: kernel event unknown "
1579 "for pid=%u tid=%x code=%x\n",
1580 (
unsigned) current_event.dwProcessId,
1581 (
unsigned) current_event.dwThreadId,
1582 (
unsigned) current_event.dwDebugEventCode));
1616 switch (ourstatus->kind)
1618 case TARGET_WAITKIND_EXITED:
1619 OUTMSG2 ((
"Child exited with retcode = %x\n",
1620 ourstatus->value.integer));
1623 case TARGET_WAITKIND_STOPPED:
1624 case TARGET_WAITKIND_LOADED:
1625 OUTMSG2 ((
"Child Stopped with signal = %d \n",
1626 ourstatus->value.sig));
1632 OUTMSG ((
"Ignoring unknown internal event, %d\n", ourstatus->kind));
1634 case TARGET_WAITKIND_SPURIOUS:
1635 case TARGET_WAITKIND_EXECD:
1683 winapi_DebugBreakProcess DebugBreakProcess;
1684 winapi_GenerateConsoleCtrlEvent GenerateConsoleCtrlEvent;
1687 HMODULE dll = GetModuleHandle (
_T(
"COREDLL.DLL"));
1689 HMODULE dll = GetModuleHandle (
_T(
"KERNEL32.DLL"));
1692 GenerateConsoleCtrlEvent =
GETPROCADDRESS (dll, GenerateConsoleCtrlEvent);
1694 if (GenerateConsoleCtrlEvent != NULL
1695 && GenerateConsoleCtrlEvent (CTRL_BREAK_EVENT, current_process_id))
1705 if (DebugBreakProcess != NULL
1706 && DebugBreakProcess (current_process_handle))
1710 soft_interrupt_requested = 1;
1715 win32_error_to_fileio_error (DWORD err)
1719 case ERROR_BAD_PATHNAME:
1720 case ERROR_FILE_NOT_FOUND:
1721 case ERROR_INVALID_NAME:
1722 case ERROR_PATH_NOT_FOUND:
1723 return FILEIO_ENOENT;
1725 case ERROR_IO_DEVICE:
1726 case ERROR_OPEN_FAILED:
1728 case ERROR_INVALID_HANDLE:
1729 return FILEIO_EBADF;
1730 case ERROR_ACCESS_DENIED:
1731 case ERROR_SHARING_VIOLATION:
1732 return FILEIO_EACCES;
1733 case ERROR_NOACCESS:
1734 return FILEIO_EFAULT;
1736 return FILEIO_EBUSY;
1737 case ERROR_ALREADY_EXISTS:
1738 case ERROR_FILE_EXISTS:
1739 return FILEIO_EEXIST;
1740 case ERROR_BAD_DEVICE:
1741 return FILEIO_ENODEV;
1742 case ERROR_DIRECTORY:
1743 return FILEIO_ENOTDIR;
1744 case ERROR_FILENAME_EXCED_RANGE:
1745 case ERROR_INVALID_DATA:
1746 case ERROR_INVALID_PARAMETER:
1747 case ERROR_NEGATIVE_SEEK:
1748 return FILEIO_EINVAL;
1749 case ERROR_TOO_MANY_OPEN_FILES:
1750 return FILEIO_EMFILE;
1751 case ERROR_HANDLE_DISK_FULL:
1752 case ERROR_DISK_FULL:
1753 return FILEIO_ENOSPC;
1754 case ERROR_WRITE_PROTECT:
1755 return FILEIO_EROFS;
1756 case ERROR_NOT_SUPPORTED:
1757 return FILEIO_ENOSYS;
1760 return FILEIO_EUNKNOWN;
1764 wince_hostio_last_error (
char *buf)
1766 DWORD winerr = GetLastError ();
1767 int fileio_err = win32_error_to_fileio_error (winerr);
1768 sprintf (buf,
"F-1,%x", fileio_err);
1822 wince_hostio_last_error,
static winapi_GetModuleInformation win32_GetModuleInformation
static int win32_detach(int pid)
struct thread_info * current_thread
static void suspend_one_thread(struct inferior_list_entry *entry)
static DEBUG_EVENT current_event
void monitor_output(const char *msg)
struct process_info * add_process(int pid, int attached)
static void win32_add_all_dlls(void)
CORE_ADDR thread_local_base
static ptid_t debug_event_ptid(DEBUG_EVENT *event)
int ptid_equal(ptid_t ptid1, ptid_t ptid2)
int(* supports_z_point_type)(char z_type)
static void child_delete_thread(DWORD pid, DWORD tid)
static void win32_request_interrupt(void)
static int win32_create_inferior(char *program, char **program_args)
static void win32_store_inferior_registers(struct regcache *regcache, int regno)
struct process_info * find_process_pid(int pid)
char * strwinerror(DWORD error)
static BOOL load_psapi(void)
static void handle_exception(struct target_waitstatus *ourstatus)
static char * get_image_name(HANDLE h, void *address, int unicode)
static DWORD current_process_id
static int win32_write_inferior_memory(CORE_ADDR memaddr, const unsigned char *myaddr, int len)
void for_each_inferior(struct inferior_list *list, void(*action)(struct inferior_list_entry *))
static void win32_clear_inferiors(void)
int(* stopped_by_watchpoint)(void)
void set_breakpoint_data(const unsigned char *bp_data, int bp_len)
struct linux_target_ops the_low_target
typedef BOOL(WINAPI *winapi_DebugActiveProcessStop)(DWORD dwProcessId)
static int soft_interrupt_requested
static int child_initialization_done
static void win32_fetch_inferior_registers(struct regcache *regcache, int regno)
static void win32_prepare_to_resume(win32_thread_info *th)
const struct target_desc * tdesc
const unsigned char * breakpoint
void win32_require_context(win32_thread_info *th)
static void fake_breakpoint_event(void)
ptid_t ptid_build(int pid, long lwp, long tid)
void * inferior_target_data(struct thread_info *inferior)
static void handle_load_dll(void)
static void child_fetch_inferior_registers(struct regcache *regcache, int r)
static int faked_breakpoint
static int win32_attach(unsigned long pid)
static void handle_unload_dll(void)
void regcache_invalidate(void)
void initialize_low(void)
static winapi_EnumProcessModules win32_EnumProcessModules
static void win32_get_thread_context(win32_thread_info *th)
int read_inferior_memory(CORE_ADDR memaddr, unsigned char *myaddr, int len)
ptid_t pid_to_ptid(int pid)
static void win32_set_thread_context(win32_thread_info *th)
static int win32_remove_point(enum raw_bkpt_type type, CORE_ADDR addr, int size, struct raw_breakpoint *bp)
static void delete_thread_info(struct inferior_list_entry *thread)
void unloaded_dll(const char *name, CORE_ADDR base_addr)
static int child_xfer_memory(CORE_ADDR memaddr, char *our, int len, int write, struct target_ops *target)
static int win32_supports_z_point_type(char z_type)
static int win32_read_inferior_memory(CORE_ADDR memaddr, unsigned char *myaddr, int len)
static int startswith(const char *string, const char *pattern)
CORE_ADDR(* stopped_data_address)(void)
static int continue_one_thread(struct inferior_list_entry *this_thread, void *id_ptr)
void check_breakpoints(CORE_ADDR stop_pc)
void remove_process(struct process_info *process)
void set_target_ops(struct target_ops *target)
static win32_thread_info * thread_rec(ptid_t ptid, int get_context)
static ptid_t win32_wait(ptid_t ptid, struct target_waitstatus *ourstatus, int options)
struct inferior_list_entry * head
static void handle_output_debug_string(struct target_waitstatus *ourstatus)
struct inferior_list all_threads
static ptid_t current_thread_ptid(void)
static void child_init_thread_list(void)
static struct target_waitstatus cached_status
static BOOL create_process(const char *program, char *args, DWORD flags, PROCESS_INFORMATION *pi)
static int win32_insert_point(enum raw_bkpt_type type, CORE_ADDR addr, int size, struct raw_breakpoint *bp)
int(* insert_point)(enum raw_bkpt_type type, CORE_ADDR addr, int size, struct raw_breakpoint *bp)
static int win32_kill(int pid)
struct inferior_list_entry * find_inferior_id(struct inferior_list *list, ptid_t id)
int(* remove_point)(enum raw_bkpt_type type, CORE_ADDR addr, int size, struct raw_breakpoint *bp)
#define GETPROCADDRESS(DLL, PROC)
static int win32_thread_alive(ptid_t ptid)
void(* prepare_to_resume)(struct lwp_info *)
typedef HANDLE(WINAPI *winapi_CreateToolhelp32Snapshot)(DWORD
static enum gdb_signal last_sig
static winapi_GetModuleFileNameExA win32_GetModuleFileNameExA
static int win32_stopped_by_watchpoint(void)
static void do_initial_child_stuff(HANDLE proch, DWORD pid, int attached)
char * phex_nz(ULONGEST l, int sizeof_l)
static CORE_ADDR win32_stopped_data_address(void)
static void win32_mourn(struct process_info *process)
static int get_child_debug_event(struct target_waitstatus *ourstatus)
static win32_thread_info * child_add_thread(DWORD pid, DWORD tid, HANDLE h, void *tlb)
static DWORD main_thread_id
void hostio_last_error_from_errno(char *buf)
int one_inferior_p(struct inferior_list *list)
const struct target_desc * win32_tdesc
struct regcache * get_thread_regcache(struct thread_info *thread, int fetch)
void remove_thread(struct thread_info *thread)
static void win32_add_one_solib(const char *name, CORE_ADDR load_addr)
struct breakpoint * set_breakpoint_at(CORE_ADDR where, int(*handler)(CORE_ADDR))
static void win32_resume(struct thread_resume *resume_info, size_t n)
void loaded_dll(const char *name, CORE_ADDR base_addr)
void check_remote_input_interrupt_request(void)
struct thread_info * add_thread(ptid_t ptid, void *target_data)
PTR xcalloc(size_t number, size_t size)
void clear_inferiors(void)
static void win32_join(int pid)
void error(const char *fmt,...)
static HANDLE current_process_handle
static void child_store_inferior_registers(struct regcache *regcache, int r)
struct inferior_list_entry * find_inferior(struct inferior_list *list, int(*func)(struct inferior_list_entry *, void *), void *arg)
static BOOL child_continue(DWORD continue_status, int thread_id)
static int win32_get_tib_address(ptid_t ptid, CORE_ADDR *addr)