drc: handle upto 64k page size
[pcsx_rearmed.git] / deps / libretro-common / utils / debugbreak / debugbreak.c
CommitLineData
3719602c
PC
1#ifndef _WIN32_WINNT
2#define _WIN32_WINNT 0x0501
3#endif
4
5#if _WIN32_WINNT < 0x0501
6#error Must target Windows NT 5.0.1 or later for DebugBreakProcess
7#endif
8
9#include <Windows.h>
10
11#include <stdio.h>
12#include <stddef.h>
13#include <stdlib.h>
14
15/* Compile with this line:
16
17gcc -o debugbreak -mno-cygwin -mthreads debugbreak.c
18
19*/
20
21static char errbuffer[256];
22
23static const char *geterrstr(DWORD errcode)
24{
25size_t skip = 0;
26DWORD chars;
27chars = FormatMessage(
28FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
29NULL, errcode, 0, errbuffer, sizeof(errbuffer)-1, 0);
30errbuffer[sizeof(errbuffer)-1] = 0;
31if (chars) {
32while (errbuffer[chars-1] == '\r' || errbuffer[chars-1] == '\n') {
33errbuffer[--chars] = 0;
34}
35}
36if (chars && errbuffer[chars-1] == '.') errbuffer[--chars] = 0;
37if (chars >= 2 && errbuffer[0] == '%' && errbuffer[1] >= '0'
38&& errbuffer[1] <= '9')
39{
40skip = 2;
41while (chars > skip && errbuffer[skip] == ' ') ++skip;
42if (chars >= skip+2 && errbuffer[skip] == 'i'
43&& errbuffer[skip+1] == 's')
44{
45skip += 2;
46while (chars > skip && errbuffer[skip] == ' ') ++skip;
47}
48}
49if (chars > skip && errbuffer[skip] >= 'A' && errbuffer[skip] <= 'Z') {
50errbuffer[skip] += 'a' - 'A';
51}
52return errbuffer+skip;
53}
54
55int main(int argc, char *argv[])
56{
57 HANDLE proc;
58 unsigned proc_id = 0;
59 BOOL break_result;
60
61 if (argc != 2) {
62 printf("Usage: debugbreak process_id_number\n");
63 return 1;
64 }
65 proc_id = (unsigned) strtol(argv[1], NULL, 0);
66 if (proc_id == 0) {
67 printf("Invalid process id %u\n", proc_id);
68 return 1;
69 }
70 proc = OpenProcess(PROCESS_ALL_ACCESS, FALSE, (DWORD)proc_id);
71 if (proc == NULL) {
72 DWORD lastError = GetLastError();
73 printf("Failed to open process %u\n", proc_id);
74 printf("Error code is %lu (%s)\n", (unsigned long)lastError,
75 geterrstr(lastError));
76 return 1;
77 }
78 break_result = DebugBreakProcess(proc);
79 if (!break_result) {
80 DWORD lastError = GetLastError();
81 printf("Failed to debug break process %u\n", proc_id);
82 printf("Error code is %lu (%s)\n", (unsigned long)lastError,
83 geterrstr(lastError));
84 CloseHandle(proc);
85 return 1;
86 }
87 printf("DebugBreak sent successfully to process id %u\n", proc_id);
88 CloseHandle(proc);
89 return 0;
90}
91
92/* END debugbreak.c */