This is the mail archive of the gdb@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Support of gdb for Windows 64 native systems


Joel Brobecker wrote:
Not sure who you're asking that, but, I'm not doing or going to do
anything, since you're already about to :)

OK :). I don't have much time these days, and in fact, I wasn't really supposed to dedicate the 4+ hours I have already spent on this, but since we seem to be on a roll, I'll try to spend some time on it next week to start the process and get us a minimal MinGW debugger.


Nah, nah, na-na-naaah. I've done it, and I said wouldn't :)


Seriously, and rethinking a bit after sleep, it is safer to do
it from scratch, so the copyright issues are cleared.

The initial changes are pretty mechanic, so, here goes.

What's done:

- Added mingw.mh, mingw.mt as copies from the cygwin files.
- Updated configure.tgt to set gdb_target.
- Disabled cygwin specific functionality in win32-nat.c. As can
be seen, the changes are very small.
- profs.h isn't needed anymore, since I've implemented cygwin cross-core support a few weeks ago (in i386-cygwin-tdep.c). The include can be
unconditionally removed.


What's next:

Test with a mingw built libexpat to test dll support.

	win32_pid_to_exec_file:  Could be done with GetModuleFileNameEx
	from PSAPI and/or with toolhelp.

	Rename a few things, which really aren't cygwin specific, like:
		* cygwin_get_dr6 -> win32_get_dr6
		* i386-cygwin-tdep.h -> i386-win32-tdep.h
		* nm-cygwin.h -> nm-cygming.h

What's disabled:
	Use a shell to start the subprocess.

I'm sure there are other problems, but it is useable already.

cygcheck.exe ./gdb.exe
.\gdb.exe
  C:\WINDOWS\system32\KERNEL32.dll
    C:\WINDOWS\system32\ntdll.dll
  C:\WINDOWS\system32\msvcrt.dll
  C:\WINDOWS\system32\USER32.dll
    C:\WINDOWS\system32\GDI32.dll
  C:\WINDOWS\system32\WS2_32.DLL
    C:\WINDOWS\system32\WS2HELP.dll
      C:\WINDOWS\system32\ADVAPI32.dll
        C:\WINDOWS\system32\RPCRT4.dll
          C:\WINDOWS\system32\Secur32.dll

build-gdb_mingw\gdb>gdb ./gdb.exe
GNU gdb 6.7.50-20071012-cvs
Copyright (C) 2007 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "mingw32"...
Setting up the environment for debugging gdb.
During symbol reading, struct/union type gets multiply defined: struct type.
Breakpoint 1 at 0x40b513: file ../../gdb-server_submit/src/gdb/utils.c, line 817
.
Breakpoint 2 at 0x4185c6: file ../../gdb-server_submit/src/gdb/cli/cli-cmds.c, l
ine 199.
(top-gdb) start
Breakpoint 3 at 0x401309: file ../../gdb-server_submit/src/gdb/gdb.c, line 28.
Starting program: D:\cegccsf\cegcc\cegcc\src\build-gdb_mingw\gdb/./gdb.exe
warning: Can not parse XML library list; XML support was disabled at compile tim
e
main (argc=1, argv=0x3d24f0) at ../../gdb-server_submit/src/gdb/gdb.c:28
28        memset (&args, 0, sizeof args);

Cheers,
Pedro Alves
2007-10-14  Pedro Alves  <pedro_alves@portugalmail.pt>

	* config/i386/mingw.mh, config/i386/mingw.mt: New files.
	* configure.tgt	(i[34567]86-*-mingw32*): Set gdb_target = mingw.
	* win32-nat.c: Only include cygwin.h on Cygwin host.  Don't
	include procfs.h.
	(win32_make_so): Don't convert path to posix on MinGW.
	(win32_attach): Only fallback to Cygwin pids on Cygwin.
	(win32_pid_to_exec_file): Disable Cygwin specific code.
	(win32_create_inferior): Disable handle starting the inferior
	through a shell on MinGW.  Disable environment var processing.
	Disable tty handling.
	(cygwin_pid_to_str): Rename to ...
	(win32_pid_to_str): ... this.
	(init_win32_ops): Update use of win32_pid_to_str.  Disable "shell"
	command on MinGW.

---
 gdb/config/i386/mingw.mh |    4 ++++
 gdb/config/i386/mingw.mt |    3 +++
 gdb/configure.tgt        |    2 +-
 gdb/win32-nat.c          |   44 ++++++++++++++++++++++++++++++++++----------
 4 files changed, 42 insertions(+), 11 deletions(-)

Index: src/gdb/config/i386/mingw.mh
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ src/gdb/config/i386/mingw.mh	2007-10-14 12:19:44.000000000 +0100
@@ -0,0 +1,4 @@
+MH_CFLAGS=
+NATDEPFILES= i386-nat.o win32-nat.o
+NAT_FILE=nm-cygwin.h
+XM_CLIBS=
Index: src/gdb/config/i386/mingw.mt
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ src/gdb/config/i386/mingw.mt	2007-10-14 10:36:20.000000000 +0100
@@ -0,0 +1,3 @@
+# Target: Intel 386 run win32
+TDEPFILES= i386-tdep.o i386-cygwin-tdep.o i387-tdep.o \
+	   solib-target.o corelow.o
Index: src/gdb/configure.tgt
===================================================================
--- src.orig/gdb/configure.tgt	2007-10-12 20:25:20.000000000 +0100
+++ src/gdb/configure.tgt	2007-10-14 11:19:50.000000000 +0100
@@ -120,7 +120,7 @@ i[34567]86-*-gnu*)	gdb_target=i386gnu ;;
 i[34567]86-*-cygwin*)	gdb_target=cygwin
 			build_gdbserver=yes
 			;;
-i[34567]86-*-mingw32*)	gdb_target=i386
+i[34567]86-*-mingw32*)	gdb_target=mingw
 			build_gdbserver=yes
 			;;
 i[34567]86-*-*)		gdb_target=i386 ;;
Index: src/gdb/win32-nat.c
===================================================================
--- src.orig/gdb/win32-nat.c	2007-10-13 02:27:04.000000000 +0100
+++ src/gdb/win32-nat.c	2007-10-14 12:23:22.000000000 +0100
@@ -22,8 +22,6 @@
 
 /* Originally by Steve Chamberlain, sac@cygnus.com */
 
-/* We assume we're being built with and will be used for cygwin.  */
-
 #include "defs.h"
 #include "frame.h"		/* required by inferior.h */
 #include "inferior.h"
@@ -40,7 +38,9 @@
 #include <stdlib.h>
 #include <windows.h>
 #include <imagehlp.h>
+#ifdef __CYGWIN__
 #include <sys/cygwin.h>
+#endif
 #include <signal.h>
 
 #include "buildsym.h"
@@ -81,7 +81,6 @@ enum
     CONTEXT_DEBUGGER = (CONTEXT_FULL | CONTEXT_FLOATING_POINT)
   };
 #endif
-#include <sys/procfs.h>
 #include <psapi.h>
 
 #define CONTEXT_DEBUGGER_DR CONTEXT_DEBUGGER | CONTEXT_DEBUG_REGISTERS \
@@ -637,7 +636,11 @@ win32_make_so (const char *name, DWORD l
   so = XZALLOC (struct so_list);
   so->lm_info = (struct lm_info *) xmalloc (sizeof (struct lm_info));
   so->lm_info->load_addr = load_addr;
+#ifdef __CYGWIN__
   cygwin_conv_to_posix_path (buf, so->so_name);
+#else
+  strcpy (so->so_name, buf);
+#endif
   strcpy (so->so_original_name, name);
 
   /* Record cygwin1.dll .text start/end.  */
@@ -1625,6 +1628,7 @@ win32_attach (char *args, int from_tty)
   ok = DebugActiveProcess (pid);
   saw_create = 0;
 
+#ifdef __CYGWIN__
   if (!ok)
     {
       /* Try fall back to Cygwin pid */
@@ -1632,10 +1636,11 @@ win32_attach (char *args, int from_tty)
 
       if (pid > 0)
 	ok = DebugActiveProcess (pid);
+  }
+#endif
 
-      if (!ok)
-	error (_("Can't attach to process."));
-    }
+  if (!ok)
+    error (_("Can't attach to process."));
 
   if (has_detach_ability ())
     DebugSetProcessKillOnExit (FALSE);
@@ -1697,10 +1702,12 @@ win32_pid_to_exec_file (int pid)
   /* Try to find the process path using the Cygwin internal process list
      pid isn't a valid pid, unfortunately.  Use current_event.dwProcessId
      instead.  */
-  /* TODO: Also find native Windows processes using CW_GETPINFO_FULL.  */
 
   static char path[MAX_PATH + 1];
   char *path_ptr = NULL;
+
+#ifdef __CYGWIN__
+  /* TODO: Also find native Windows processes using CW_GETPINFO_FULL.  */
   int cpid;
   struct external_pinfo *pinfo;
 
@@ -1718,6 +1725,10 @@ win32_pid_to_exec_file (int pid)
        }
     }
   cygwin_internal (CW_UNLOCK_PINFO);
+  if (path_ptr)
+    return path_ptr;
+#endif
+
   return path_ptr;
 }
 
@@ -1764,9 +1775,12 @@ win32_create_inferior (char *exec_file, 
   memset (&si, 0, sizeof (si));
   si.cb = sizeof (si);
 
+  flags = DEBUG_ONLY_THIS_PROCESS;
+  toexec = exec_file;
+
+#ifdef __CYGWIN__
   if (!useshell)
     {
-      flags = DEBUG_ONLY_THIS_PROCESS;
       cygwin_conv_to_win32_path (exec_file, real_path);
       toexec = real_path;
     }
@@ -1784,6 +1798,7 @@ win32_create_inferior (char *exec_file, 
       toexec = shell;
       flags = DEBUG_PROCESS;
     }
+#endif
 
   if (new_group)
     flags |= CREATE_NEW_PROCESS_GROUP;
@@ -1798,6 +1813,8 @@ win32_create_inferior (char *exec_file, 
   strcat (args, " ");
   strcat (args, allargs);
 
+#ifdef __CYGWIN__
+
   /* Prepare the environment vars for CreateProcess.  */
   cygwin_internal (CW_SYNC_WINENV);
 
@@ -1822,6 +1839,8 @@ win32_create_inferior (char *exec_file, 
 	}
     }
 
+#endif
+
   win32_init_thread_list ();
   ret = CreateProcess (0,
 		       args,	/* command line */
@@ -1833,6 +1852,8 @@ win32_create_inferior (char *exec_file, 
 		       NULL,	/* current directory */
 		       &si,
 		       &pi);
+
+#ifdef __CYGWIN__
   if (tty >= 0)
     {
       close (tty);
@@ -1843,6 +1864,7 @@ win32_create_inferior (char *exec_file, 
       close (ostdout);
       close (ostderr);
     }
+#endif
 
   if (!ret)
     error (_("Error creating process %s, (error %d)."),
@@ -1951,7 +1973,7 @@ win32_close (int x)
 
 /* Convert pid to printable format. */
 static char *
-cygwin_pid_to_str (ptid_t ptid)
+win32_pid_to_str (ptid_t ptid)
 {
   static char buf[80];
   int pid = PIDGET (ptid);
@@ -2055,7 +2077,7 @@ init_win32_ops (void)
   win32_ops.to_mourn_inferior = win32_mourn_inferior;
   win32_ops.to_can_run = win32_can_run;
   win32_ops.to_thread_alive = win32_win32_thread_alive;
-  win32_ops.to_pid_to_str = cygwin_pid_to_str;
+  win32_ops.to_pid_to_str = win32_pid_to_str;
   win32_ops.to_stop = win32_stop;
   win32_ops.to_stratum = process_stratum;
   win32_ops.to_has_all_memory = 1;
@@ -2086,12 +2108,14 @@ _initialize_win32_nat (void)
 
   add_com_alias ("sharedlibrary", "dll-symbols", class_alias, 1);
 
+#ifdef __CYGWIN__
   add_setshow_boolean_cmd ("shell", class_support, &useshell, _("\
 Set use of shell to start subprocess."), _("\
 Show use of shell to start subprocess."), NULL,
 			   NULL,
 			   NULL, /* FIXME: i18n: */
 			   &setlist, &showlist);
+#endif
 
   add_setshow_boolean_cmd ("cygwin-exceptions", class_support, &cygwin_exceptions, _("\
 Break when an exception is detected in the Cygwin DLL itself."), _("\

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]