aboutsummaryrefslogtreecommitdiffstats
path: root/packages/gdb/gdb-6.8/gdb-6.8-mingw-3.patch
blob: 7bfcca7518eee3f5044239c168aaa85b48a31234 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
diff -urp gdb-6.8_orig/gdb/gdbserver/remote-utils.c gdb-6.8/gdb/gdbserver/remote-utils.c
--- gdb-6.8_orig/gdb/gdbserver/remote-utils.c	2008-01-29 16:51:50.000000000 -0800
+++ gdb-6.8/gdb/gdbserver/remote-utils.c	2008-04-09 14:04:30.000000000 -0700
@@ -617,7 +617,12 @@ input_interrupt (int unused)
 
       cc = read (remote_desc, &c, 1);
 
+#ifdef _WIN32_WINNT
+      // its normal in windows for current_inferior to be null.
+      if (cc != 1 || c != '\003' /*|| current_inferior == NULL*/)
+#else
       if (cc != 1 || c != '\003' || current_inferior == NULL)
+#endif
 	{
 	  fprintf (stderr, "input_interrupt, count = %d c = %d ('%c')\n",
 		   cc, c, c);
diff -urp gdb-6.8_orig/gdb/gdbserver/server.c gdb-6.8/gdb/gdbserver/server.c
--- gdb-6.8_orig/gdb/gdbserver/server.c	2008-02-19 13:36:54.000000000 -0800
+++ gdb-6.8/gdb/gdbserver/server.c	2008-04-23 13:56:51.000000000 -0700
@@ -29,6 +29,10 @@
 #include <sys/wait.h>
 #endif
 
+#ifdef _WIN32
+#include <windows.h>
+#endif
+
 unsigned long cont_thread;
 unsigned long general_thread;
 unsigned long step_thread;
@@ -268,6 +272,20 @@ monitor_show_help (void)
   monitor_output ("    Enable general debugging messages\n");  
   monitor_output ("  set remote-debug <0|1>\n");
   monitor_output ("    Enable remote protocol debugging messages\n");
+#ifdef _WIN32
+  monitor_output ("  get processlist\n");
+  monitor_output ("    List remote processes with names and pid\n");
+  monitor_output ("  get processlistmi\n");
+  monitor_output ("    Process list in an MI-like format\n");
+#endif
+  monitor_output ("  set env <name=value>\n");
+  monitor_output ("    Set environment variable in remote environment\n");
+  monitor_output ("  cd <directory>\n");
+  monitor_output ("    Change current working directory\n");
+  monitor_output ("  pwd\n");
+  monitor_output ("    Print current working directory\n");
+  monitor_output ("  shell <command line>\n");
+  monitor_output ("    Execute command on remote target\n");
   monitor_output ("  exit\n");
   monitor_output ("    Quit GDBserver\n");
 }
@@ -279,6 +297,47 @@ monitor_show_help (void)
       return;					\
     }
 
+#ifdef _WIN32
+typedef DWORD (__stdcall *GETPROCESSIMAGEFILENAME)(HANDLE hProcess, LPTSTR lpImageFileName, DWORD nSize);
+typedef BOOL (__stdcall *ENUMPROCESSES)(DWORD* pProcessIds, DWORD cb, DWORD* pBytesReturned);
+
+# define HAS_DEVICE(P) \
+((((P)[0] >= 'A' && (P)[0] <= 'Z') || ((P)[0] >= 'a' && (P)[0] <= 'z')) \
+&& (P)[1] == ':')
+# define FILE_SYSTEM_PREFIX_LEN(P) (HAS_DEVICE (P) ? 2 : 0)
+# define ISSLASH(C) ((C) == '/' || (C) == '\\')
+
+char *
+__basename (char const *name)
+{
+	char const *base = name += FILE_SYSTEM_PREFIX_LEN (name);
+	int all_slashes = 1;
+	char const *p;
+	
+	for (p = name; *p; p++)
+    {
+		if (ISSLASH (*p))
+			base = p + 1;
+		else
+			all_slashes = 0;
+    }
+	
+	/* If NAME is all slashes, arrange to return `/'.  */
+	if (*base == '\0' && ISSLASH (*name) && all_slashes)
+		--base;
+	
+	/* Make sure the last byte is not a slash.  */
+	//assert (all_slashes || !ISSLASH (*(p - 1)));
+	
+	return (char *) base;
+}
+#endif
+
+#ifndef _POSIX_PATH_MAX
+#define _POSIX_PATH_MAX 1024
+#define _POSIX_PATH_MAX_WAS_UNDEFINED
+#endif
+
 /* Handle all of the extended 'q' packets.  */
 void
 handle_query (char *own_buf, int packet_len, int *new_packet_len_p)
@@ -664,6 +723,158 @@ handle_query (char *own_buf, int packet_
 	  debug_threads = 1;
 	  monitor_output ("Debug output enabled.\n");
 	}
+#ifdef _WIN32
+  else if (strncmp (mon, "get processlist", 15) == 0)
+  {
+	  HINSTANCE lib = LoadLibrary("PSAPI.DLL");
+	  GETPROCESSIMAGEFILENAME imageFilename = (GETPROCESSIMAGEFILENAME)GetProcAddress(lib, "GetProcessImageFileNameA");
+	  ENUMPROCESSES enumProcesses = (ENUMPROCESSES)GetProcAddress(lib, "EnumProcesses");
+	  
+	  char* name = (char*)malloc(MAX_PATH);
+	  
+	  int miMode = (strcmp(mon, "get processlistmi") == 0);
+	  
+	  DWORD* pids = (DWORD*)malloc(sizeof(DWORD)*1024);
+	  memset(pids, 0, sizeof(pids));
+	  DWORD size = 0;
+	  
+	  if (!enumProcesses(pids, 1024 * sizeof(DWORD), &size))
+	  {
+		  free(pids);
+		  free(mon);
+		  return;
+	  }
+	  
+	  int cnt = 0;
+	  int number = size / sizeof(DWORD);
+	  
+	  char* miOutput = NULL;
+	  
+	  if (!miMode) 
+		  monitor_output("Remote process list:\n");
+	  else
+	  {
+		  miOutput = (char*)malloc((number * 255) * sizeof(char));
+		  strcpy(miOutput, "^done,processlist=[");
+	  }
+	  
+	  for (cnt = 0; cnt < number; cnt++)
+	  {
+		  HMODULE hProcess = (HMODULE)OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, pids[cnt]);
+		  strcpy(name, "");
+		  printf(name);
+		  
+		  imageFilename(hProcess, name, MAX_PATH);
+		  
+		  if (pids[cnt] > 4 && strcmp(name, "") != 0)
+		  {
+			  char item[2048] = "";
+			  char tmp[24] = "0";
+			  itoa(pids[cnt], tmp, 10);
+			  strcat(item, tmp);
+			  strcat(item, "=");
+			  strcat(item, __basename(name));
+			  
+			  if (!miMode)
+			  {
+				  strcat(item, "\n");
+				  monitor_output(item);
+			  }
+			  else
+			  {
+				  strcat(miOutput, item);
+				  strcat(miOutput, ",");
+			  }
+		  }
+		  
+		  CloseHandle(hProcess);
+	  }
+	  
+	  if (miMode)
+	  {
+		  strcat(miOutput, "]\n");
+		  monitor_output(miOutput);
+		  free(miOutput);
+	  }
+	  
+	  FreeLibrary(lib);
+	  
+	  free(pids);
+	  free(name);	  
+  }
+#endif		
+  else if (strncmp (mon, "set env ", 8) == 0)
+  {
+	  char* envLine = mon + 8;
+	  char* envName = strtok(envLine, "= ");
+	  char* envValue = strtok(NULL, "= ");
+	  if (envName && envValue)
+	  {
+#ifdef _WIN32
+		  SetEnvironmentVariable(envName, envValue);
+#else
+		  setenv(envName, envValue, 1);
+#endif 
+		  monitor_output("Target environment variable set (");
+		  monitor_output(envName);
+		  monitor_output(" = ");
+		  monitor_output(envValue);
+		  monitor_output(").\n");
+	  }
+	  else
+		  monitor_output("Incorrect format for environment variable.\n");
+  }
+  else if (strncmp (mon, "cd ", 3) == 0)
+  {
+	  char* dir = mon + 3;
+	  if (strlen(dir) > 0)
+		  chdir(dir);
+  }
+  else if (strcmp(mon, "pwd") == 0)
+  {
+	  long size = _POSIX_PATH_MAX;
+	  char* current_directory = (char*)malloc(size);	  
+	  getcwd(current_directory, size);
+	  if (strlen(current_directory) > 0)
+	  {
+		  monitor_output(current_directory);
+		  monitor_output("\n");
+	  }
+	  free(current_directory);
+  }
+  else if (strncmp (mon, "shell ", 6) == 0)
+  {
+	  char* arg = mon + 6;
+	  
+	  if (strlen(arg) == 0)
+	  {
+		  monitor_output("Inferior shells are not supported.");
+		  free(mon);
+		  return;
+	  }
+	  
+	  long size = _POSIX_PATH_MAX;
+	  char* current_directory = (char*)malloc(size);  
+	  getcwd(current_directory, size);
+
+	  int rc = system (arg);
+	  char msg[255];
+	  if (rc == -1)
+	  {
+		  sprintf(msg, "Cannot execute '%s': %s.\n", arg, strerror(errno));
+		  monitor_output(msg);
+	  }
+	  else if (rc != -1)
+	  {
+		  sprintf(msg, "'%s' exited with status %d.\n", arg, rc);
+		  monitor_output(msg);
+	  }
+
+	  /* Make sure to return to the directory GDB thinks it is, in case the
+	   shell command we just ran changed it.  */
+	  chdir(current_directory);
+	  free(current_directory);
+  }
       else if (strcmp (mon, "set debug 0") == 0)
 	{
 	  debug_threads = 0;
@@ -699,6 +910,11 @@ handle_query (char *own_buf, int packet_
   own_buf[0] = 0;
 }
 
+#ifdef _POSIX_PATH_MAX_WAS_UNDEFINED
+#undef _POSIX_PATH_MAX
+#undef _POSIX_PATH_MAX_WAS_UNDEFINED
+#endif
+
 /* Parse vCont packets.  */
 void
 handle_v_cont (char *own_buf, char *status, int *signal)
@@ -1503,6 +1719,8 @@ main (int argc, char *argv[])
 		fprintf (stderr, "\nChild terminated with signal = 0x%x (%s)\n",
 			 target_signal_to_host (signal),
 			 target_signal_to_name (signal));
+			
+		kill_inferior();
 
 	      if (extended_protocol)
 		goto restart;
diff -urp gdb-6.8_orig/gdb/gdbserver/win32-low.c gdb-6.8/gdb/gdbserver/win32-low.c
--- gdb-6.8_orig/gdb/gdbserver/win32-low.c	2008-02-14 14:41:39.000000000 -0800
+++ gdb-6.8/gdb/gdbserver/win32-low.c	2008-04-22 23:24:38.000000000 -0700
@@ -38,7 +38,7 @@
 #include <sys/cygwin.h>
 #endif
 
-#define LOG 0
+#define LOG 1
 
 #define OUTMSG(X) do { printf X; fflush (stdout); } while (0)
 #if LOG
@@ -543,9 +543,9 @@ win32_create_inferior (char *program, ch
     }
   OUTMSG2 (("Command line is \"%s\"\n", args));
 
-#ifdef CREATE_NEW_PROCESS_GROUP
+//#ifdef CREATE_NEW_PROCESS_GROUP
   flags |= CREATE_NEW_PROCESS_GROUP;
-#endif
+//#endif
 
   ret = create_process (program, args, flags, &pi);
   err = GetLastError ();
@@ -684,8 +684,37 @@ win32_kill (void)
   if (current_process_handle == NULL)
     return;
 
-  TerminateProcess (current_process_handle, 0);
-  for (;;)
+	TerminateProcess (current_process_handle, 0);
+	
+	// BKS - fix for terminating apps prior to their exit, lets go of execs.
+	winapi_DebugActiveProcessStop DebugActiveProcessStop = NULL;
+	winapi_DebugSetProcessKillOnExit DebugSetProcessKillOnExit = NULL;
+#ifdef _WIN32_WCE
+	HMODULE dll = GetModuleHandle (_T("COREDLL.DLL"));
+#else
+	HMODULE dll = GetModuleHandle (_T("KERNEL32.DLL"));
+#endif
+	DebugActiveProcessStop = GETPROCADDRESS (dll, DebugActiveProcessStop);
+	DebugSetProcessKillOnExit = GETPROCADDRESS (dll, DebugSetProcessKillOnExit);
+	
+	if (DebugSetProcessKillOnExit != NULL
+		&& DebugActiveProcessStop != NULL)
+	{	
+		{
+			struct thread_resume resume;
+			resume.thread = -1;
+			resume.step = 0;
+			resume.sig = 0;
+			resume.leave_stopped = 0;
+			win32_resume (&resume);
+		}
+	
+		DebugActiveProcessStop (current_process_id);
+		DebugSetProcessKillOnExit (FALSE);
+	}
+	// end BKS
+
+   for (;;)
     {
       if (!child_continue (DBG_CONTINUE, -1))
 	break;
@@ -1186,6 +1215,7 @@ handle_exception (struct target_waitstat
 
   ourstatus->kind = TARGET_WAITKIND_STOPPED;
 
+	//printf("handle exception....................%X\n", (unsigned int)code);
   switch (code)
     {
     case EXCEPTION_ACCESS_VIOLATION:
@@ -1196,7 +1226,13 @@ handle_exception (struct target_waitstat
       OUTMSG2 (("STATUS_STACK_OVERFLOW"));
       ourstatus->value.sig = TARGET_SIGNAL_SEGV;
       break;
-    case STATUS_FLOAT_DENORMAL_OPERAND:
+	// BKS
+	case STATUS_INVALID_HANDLE:
+      OUTMSG2 (("STATUS_INVALID_HANDLE"));
+	  ourstatus->value.sig = TARGET_SIGNAL_TRAP;
+	  break;
+	// BKS
+	case STATUS_FLOAT_DENORMAL_OPERAND:
       OUTMSG2 (("STATUS_FLOAT_DENORMAL_OPERAND"));
       ourstatus->value.sig = TARGET_SIGNAL_FPE;
       break;
@@ -1453,7 +1489,8 @@ get_child_debug_event (struct target_wai
 		(unsigned) current_event.dwThreadId));
       ourstatus->kind = TARGET_WAITKIND_EXITED;
       ourstatus->value.integer = current_event.u.ExitProcess.dwExitCode;
-      CloseHandle (current_process_handle);
+	  win32_kill();  // fixed problem with exec's not being let go after completion.
+      //CloseHandle (current_process_handle); // let this get done by win32_kill().
       current_process_handle = NULL;
       break;
 
diff -urp gdb-6.8_orig/gdb/linespec.c gdb-6.8/gdb/linespec.c
--- gdb-6.8_orig/gdb/linespec.c	2008-01-01 14:53:11.000000000 -0800
+++ gdb-6.8/gdb/linespec.c	2008-04-23 11:15:58.000000000 -0700
@@ -1534,11 +1534,11 @@ symtab_from_filename (char **argptr, cha
   file_symtab = lookup_symtab (copy);
   if (file_symtab == 0)
     {
-      if (!have_full_symbols () && !have_partial_symbols ())
-	error (_("No symbol table is loaded.  Use the \"file\" command."));
+//      if (!have_full_symbols () && !have_partial_symbols ())
+//	error (_("No symbol table is loaded.  Use the \"file\" command."));
       if (not_found_ptr)
 	*not_found_ptr = 1;
-      throw_error (NOT_FOUND_ERROR, _("No source file named %s."), copy);
+      throw_error (NOT_FOUND_ERROR, _("No source file named %s in loaded symbols."), copy);
     }
 
   /* Discard the file name from the arg.  */
@@ -1744,13 +1744,13 @@ decode_variable (char *copy, int funfirs
   if (msymbol != NULL)
     return minsym_found (funfirstline, msymbol);
 
-  if (!have_full_symbols () &&
+  /*if (!have_full_symbols () &&
       !have_partial_symbols () && !have_minimal_symbols ())
-    error (_("No symbol table is loaded.  Use the \"file\" command."));
+    error (_("No symbol table is loaded.  Use the \"file\" command."));*/
 
   if (not_found_ptr)
     *not_found_ptr = 1;
-  throw_error (NOT_FOUND_ERROR, _("Function \"%s\" not defined."), copy);
+  throw_error (NOT_FOUND_ERROR, _("Function \"%s\" not defined in loaded symbols."), copy);
 }
 
 
diff -urp gdb-6.8_orig/gdb/win32-nat.c gdb-6.8/gdb/win32-nat.c
--- gdb-6.8_orig/gdb/win32-nat.c	2008-01-29 13:11:24.000000000 -0800
+++ gdb-6.8/gdb/win32-nat.c	2008-04-18 17:45:52.000000000 -0700
@@ -1031,6 +1031,10 @@ handle_exception (struct target_waitstat
       DEBUG_EXCEPTION_SIMPLE ("STATUS_STACK_OVERFLOW");
       ourstatus->value.sig = TARGET_SIGNAL_SEGV;
       break;
+	case STATUS_INVALID_HANDLE:
+	  DEBUG_EXCEPTION_SIMPLE ("STATUS_INVALID_HANDLE");
+	  ourstatus->value.sig = TARGET_SIGNAL_TRAP;
+	  break;
     case STATUS_FLOAT_DENORMAL_OPERAND:
       DEBUG_EXCEPTION_SIMPLE ("STATUS_FLOAT_DENORMAL_OPERAND");
       ourstatus->value.sig = TARGET_SIGNAL_FPE;