From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 17456 invoked by alias); 19 Sep 2002 00:32:09 -0000 Mailing-List: contact gdb-patches-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sources.redhat.com Received: (qmail 17449 invoked from network); 19 Sep 2002 00:32:08 -0000 Received: from unknown (HELO smtp-server6.tampabay.rr.com) (65.32.1.43) by sources.redhat.com with SMTP; 19 Sep 2002 00:32:08 -0000 Received: from dell (251.196.33.65.cfl.rr.com [65.33.196.251]) by smtp-server6.tampabay.rr.com (8.12.2/8.12.2) with SMTP id g8J0W6u7019621 for ; Wed, 18 Sep 2002 20:32:06 -0400 (EDT) Message-ID: <000d01c25f73$fda6a5b0$6501a8c0@dell> From: "Al Stevens" To: Subject: contribution to cygwin gdb Date: Wed, 18 Sep 2002 17:32:00 -0000 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_NextPart_000_000A_01C25F52.765BCD40" X-Priority: 3 X-MSMail-Priority: Normal X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000 X-SW-Source: 2002-09/txt/msg00445.txt.bz2 This is a multi-part message in MIME format. ------=_NextPart_000_000A_01C25F52.765BCD40 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-length: 3487 This bug and patch might have already been submitted. There was considerable discussion of it on the mingw mailing list and I gave the patch to a couple of the participants. Christopher Faylor is aware of this bug and has a copy of the fixed source code file. Description of the bug: When an IDE launches GDB to debug a console application on Windows 95/98/ME platforms with the set new-console option, and the IDE communicates with GDB's stdin/stdout through pipes, the target application's console does not work. It displays the console window, but output to the console goes no where and input from the console (getchar(), e.g.) just locks up the program. This problem does not seem to exist on Windows NT/XP/2000 platforms. The problem is due to inconsistent implementation of CreateProcess with the win32 debugger api between platforms. Somehow the Win9x platform forces the target to inherit gdb's stdin/stdout handles, which are the pipes. It must have something to do with pipes not having three ends, I'm not sure. It's not really GDB's problem, but GDB has to find a way around it. The solution is for GDB to temporarily set its handles to INVALID_HANDLE_VALUE before launching the target and then restore the handles after the target is running. This must be done only when the new-console option is set. Otherwise a command-line run of GDB without set new-console would not work. To observe this bug, you must use an IDE that uses pipes to communicate with GDB. There are two such IDEs that I know of. One is VIDE, which exhibits this problem. (http://www.objectcentral.com/vide.htm). Make sure that you use the existing released gdb. I gave VIDE's author a patched one, and he might already be distributing it. The other IDE is Quincy 2002. (http://www.alstevens.com/quincy.html) It distributes a patched GDB which you can replace with the released version. Just put your gdb.exe in the gdb subdirectory. This must be a gdb built without the Insight hooks because Quincy does not use the -nw option. Build a hello-world application with MinGW from the IDE with debugging info, and step through it. Don't just run the application; that procedure does not use GDB. Step through the program and observe that the target's message to stdout does not display in the console window. Then restore the patched GDB that comes along with Quincy 2002, run the test again, and observe that the problem goes away. If it would help, I can walk a tester through the steps needed to install Quincy 2002 and get MinGW and gdb setup for the test. We can do it via email. Your submission instructions ask for a ChangeLog entry. I searched the website for a format but did not find one. If you'll point me in the right direction, I'll build one and send it to you. It would be helpful if the instructions on the CONTRIBUTE page included a link. Attached is the fixed win32-nat.c. I know that's not the way you prefer to get contributions, and I apologize, but I'm not all that familiar with how to work with CVS. A search of the file on the string QUINCY will turn up the very small patch it takes to fix this problem. It's in three places fairly near one another in the same function. I am virtually certain that the patch has no effect whatsoever in environments other than IDEs that launch GDB with pipes. I am equally certain that without this patch, GDB cannot be used in that environment on the 9x derived platforms. Thanks for looking at this. Al Stevens Dr, Dobb's Journal ------=_NextPart_000_000A_01C25F52.765BCD40 Content-Type: application/octet-stream; name="win32-nat.c" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="win32-nat.c" Content-length: 71523 /* Target-vector operations for controlling win32 child processes, for GDB.= =0A= =0A= Copyright 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002 Free=0A= Software Foundation, Inc.=0A= =0A= Contributed by Cygnus Solutions, A Red Hat Company.=0A= =0A= This file is part of GDB.=0A= =0A= This program is free software; you can redistribute it and/or modify=0A= it under the terms of the GNU General Public License as published by=0A= the Free Software Foundation; either version 2 of the License, or=0A= (at your option) any later version.=0A= =0A= This program is distributed in the hope that it will be useful,=0A= but WITHOUT ANY WARRANTY; without eve nthe implied warranty of=0A= MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the=0A= GNU General Public License for more details.=0A= =0A= You should have received a copy of the GNU General Public License=0A= along with this program; if not, write to the Free Software=0A= Foundation, Inc., 59 Temple Place - Suite 330,=0A= Boston, MA 02111-1307, USA. */=0A= =0A= /* Originally by Steve Chamberlain, sac@cygnus.com */=0A= =0A= /* We assume we're being built with and will be used for cygwin. */=0A= =0A= #include "defs.h"=0A= #include "tm.h" /* required for SSE registers */=0A= #include "frame.h" /* required by inferior.h */=0A= #include "inferior.h"=0A= #include "target.h"=0A= #include "gdbcore.h"=0A= #include "command.h"=0A= #include "completer.h"=0A= #include "regcache.h"=0A= #include "top.h"=0A= #include "i386-tdep.h"=0A= #include =0A= #include =0A= #include =0A= #include =0A= #include =0A= #include =0A= #include =0A= =0A= #include "buildsym.h"=0A= #include "symfile.h"=0A= #include "objfiles.h"=0A= #include "gdb_string.h"=0A= #include "gdbthread.h"=0A= #include "gdbcmd.h"=0A= #include =0A= #include =0A= =0A= /* The ui's event loop. */=0A= extern int (*ui_loop_hook) (int signo);=0A= =0A= /* If we're not using the old Cygwin header file set, define the=0A= following which never should have been in the generic Win32 API=0A= headers in the first place since they were our own invention... */=0A= #ifndef _GNU_H_WINDOWS_H=0A= enum=0A= {=0A= FLAG_TRACE_BIT =3D 0x100,=0A= CONTEXT_DEBUGGER =3D (CONTEXT_FULL | CONTEXT_FLOATING_POINT)=0A= };=0A= #endif=0A= #include =0A= #include =0A= =0A= #ifdef HAVE_SSE_REGS=0A= #define CONTEXT_DEBUGGER_DR CONTEXT_DEBUGGER | CONTEXT_DEBUG_REGISTERS \=0A= | CONTEXT_EXTENDED_REGISTERS=0A= #else=0A= #define CONTEXT_DEBUGGER_DR CONTEXT_DEBUGGER | CONTEXT_DEBUG_REGISTERS=0A= #endif=0A= =0A= static unsigned dr[8];=0A= static int debug_registers_changed =3D 0;=0A= static int debug_registers_used =3D 0;=0A= =0A= /* The string sent by cygwin when it processes a signal.=0A= FIXME: This should be in a cygwin include file. */=0A= #define CYGWIN_SIGNAL_STRING "cygwin: signal"=0A= =0A= #define CHECK(x) check (x, __FILE__,__LINE__)=0A= #define DEBUG_EXEC(x) if (debug_exec) printf_unfiltered x=0A= #define DEBUG_EVENTS(x) if (debug_events) printf_unfiltered x=0A= #define DEBUG_MEM(x) if (debug_memory) printf_unfiltered x=0A= #define DEBUG_EXCEPT(x) if (debug_exceptions) printf_unfiltered x=0A= =0A= /* Forward declaration */=0A= extern struct target_ops child_ops;=0A= =0A= static void child_stop (void);=0A= static int win32_child_thread_alive (ptid_t);=0A= void child_kill_inferior (void);=0A= =0A= static enum target_signal last_sig =3D TARGET_SIGNAL_0;=0A= /* Set if a signal was received from the debugged process */=0A= =0A= /* Thread information structure used to track information that is=0A= not available in gdb's thread structure. */=0A= typedef struct thread_info_struct=0A= {=0A= struct thread_info_struct *next;=0A= DWORD id;=0A= HANDLE h;=0A= char *name;=0A= int suspend_count;=0A= CONTEXT context;=0A= STACKFRAME sf;=0A= }=0A= thread_info;=0A= =0A= static thread_info thread_head;=0A= =0A= /* The process and thread handles for the above context. */=0A= =0A= static DEBUG_EVENT current_event; /* The current debug event from=0A= WaitForDebugEvent */=0A= static HANDLE current_process_handle; /* Currently executing process */=0A= static thread_info *current_thread; /* Info on currently selected thread */= =0A= static DWORD main_thread_id; /* Thread ID of the main thread */=0A= static pid_t cygwin_pid; /* pid of cygwin process */=0A= =0A= /* Counts of things. */=0A= static int exception_count =3D 0;=0A= static int event_count =3D 0;=0A= static int saw_create;=0A= =0A= /* User options. */=0A= static int new_console =3D 0;=0A= static int new_group =3D 1;=0A= static int debug_exec =3D 0; /* show execution */=0A= static int debug_events =3D 0; /* show events from kernel */=0A= static int debug_memory =3D 0; /* show target memory accesses */=0A= static int debug_exceptions =3D 0; /* show target exceptions */=0A= static int useshell =3D 0; /* use shell for subprocesses */=0A= =0A= /* This vector maps GDB's idea of a register's number into an address=0A= in the win32 exception context vector.=0A= =0A= It also contains the bit mask needed to load the register in question.= =0A= =0A= One day we could read a reg, we could inspect the context we=0A= already have loaded, if it doesn't have the bit set that we need,=0A= we read that set of registers in using GetThreadContext. If the=0A= context already contains what we need, we just unpack it. Then to=0A= write a register, first we have to ensure that the context contains=0A= the other regs of the group, and then we copy the info in and set=0A= out bit. */=0A= =0A= #define context_offset(x) ((int)&(((CONTEXT *)NULL)->x))=0A= static const int mappings[] =3D=0A= {=0A= context_offset (Eax),=0A= context_offset (Ecx),=0A= context_offset (Edx),=0A= context_offset (Ebx),=0A= context_offset (Esp),=0A= context_offset (Ebp),=0A= context_offset (Esi),=0A= context_offset (Edi),=0A= context_offset (Eip),=0A= context_offset (EFlags),=0A= context_offset (SegCs),=0A= context_offset (SegSs),=0A= context_offset (SegDs),=0A= context_offset (SegEs),=0A= context_offset (SegFs),=0A= context_offset (SegGs),=0A= context_offset (FloatSave.RegisterArea[0 * 10]),=0A= context_offset (FloatSave.RegisterArea[1 * 10]),=0A= context_offset (FloatSave.RegisterArea[2 * 10]),=0A= context_offset (FloatSave.RegisterArea[3 * 10]),=0A= context_offset (FloatSave.RegisterArea[4 * 10]),=0A= context_offset (FloatSave.RegisterArea[5 * 10]),=0A= context_offset (FloatSave.RegisterArea[6 * 10]),=0A= context_offset (FloatSave.RegisterArea[7 * 10]),=0A= context_offset (FloatSave.ControlWord),=0A= context_offset (FloatSave.StatusWord),=0A= context_offset (FloatSave.TagWord),=0A= context_offset (FloatSave.ErrorSelector),=0A= context_offset (FloatSave.ErrorOffset),=0A= context_offset (FloatSave.DataSelector),=0A= context_offset (FloatSave.DataOffset),=0A= context_offset (FloatSave.ErrorSelector)=0A= #ifdef HAVE_SSE_REGS=0A= /* XMM0-7 */ ,=0A= context_offset (ExtendedRegisters[10*16]),=0A= context_offset (ExtendedRegisters[11*16]),=0A= context_offset (ExtendedRegisters[12*16]),=0A= context_offset (ExtendedRegisters[13*16]),=0A= context_offset (ExtendedRegisters[14*16]),=0A= context_offset (ExtendedRegisters[15*16]),=0A= context_offset (ExtendedRegisters[16*16]),=0A= context_offset (ExtendedRegisters[17*16]),=0A= /* MXCSR */=0A= context_offset (ExtendedRegisters[24])=0A= #endif=0A= };=0A= =0A= #undef context_offset=0A= =0A= /* This vector maps the target's idea of an exception (extracted=0A= from the DEBUG_EVENT structure) to GDB's idea. */=0A= =0A= struct xlate_exception=0A= {=0A= int them;=0A= enum target_signal us;=0A= };=0A= =0A= static const struct xlate_exception=0A= xlate[] =3D=0A= {=0A= {EXCEPTION_ACCESS_VIOLATION, TARGET_SIGNAL_SEGV},=0A= {STATUS_STACK_OVERFLOW, TARGET_SIGNAL_SEGV},=0A= {EXCEPTION_BREAKPOINT, TARGET_SIGNAL_TRAP},=0A= {DBG_CONTROL_C, TARGET_SIGNAL_INT},=0A= {EXCEPTION_SINGLE_STEP, TARGET_SIGNAL_TRAP},=0A= {STATUS_FLOAT_DIVIDE_BY_ZERO, TARGET_SIGNAL_FPE},=0A= {-1, -1}};=0A= =0A= static void=0A= check (BOOL ok, const char *file, int line)=0A= {=0A= if (!ok)=0A= printf_filtered ("error return %s:%d was %lu\n", file, line,=0A= GetLastError ());=0A= }=0A= =0A= =0A= /* Find a thread record given a thread id.=0A= If get_context then also retrieve the context for this=0A= thread. */=0A= static thread_info *=0A= thread_rec (DWORD id, int get_context)=0A= {=0A= thread_info *th;=0A= =0A= for (th =3D &thread_head; (th =3D th->next) !=3D NULL;)=0A= if (th->id =3D=3D id)=0A= {=0A= if (!th->suspend_count && get_context)=0A= {=0A= if (get_context > 0 && id !=3D current_event.dwThreadId)=0A= th->suspend_count =3D SuspendThread (th->h) + 1;=0A= else if (get_context < 0)=0A= th->suspend_count =3D -1;=0A= =0A= th->context.ContextFlags =3D CONTEXT_DEBUGGER_DR;=0A= GetThreadContext (th->h, &th->context);=0A= if (id =3D=3D current_event.dwThreadId)=0A= {=0A= /* Copy dr values from that thread. */=0A= dr[0] =3D th->context.Dr0;=0A= dr[1] =3D th->context.Dr1;=0A= dr[2] =3D th->context.Dr2;=0A= dr[3] =3D th->context.Dr3;=0A= dr[6] =3D th->context.Dr6;=0A= dr[7] =3D th->context.Dr7;=0A= }=0A= }=0A= return th;=0A= }=0A= =0A= return NULL;=0A= }=0A= =0A= /* Add a thread to the thread list */=0A= static thread_info *=0A= child_add_thread (DWORD id, HANDLE h)=0A= {=0A= thread_info *th;=0A= =0A= if ((th =3D thread_rec (id, FALSE)))=0A= return th;=0A= =0A= th =3D (thread_info *) xmalloc (sizeof (*th));=0A= memset (th, 0, sizeof (*th));=0A= th->id =3D id;=0A= th->h =3D h;=0A= th->next =3D thread_head.next;=0A= thread_head.next =3D th;=0A= add_thread (pid_to_ptid (id));=0A= /* Set the debug registers for the new thread in they are used. */=0A= if (debug_registers_used)=0A= {=0A= /* Only change the value of the debug registers. */=0A= th->context.ContextFlags =3D CONTEXT_DEBUG_REGISTERS;=0A= CHECK (GetThreadContext (th->h, &th->context));=0A= th->context.Dr0 =3D dr[0];=0A= th->context.Dr1 =3D dr[1];=0A= th->context.Dr2 =3D dr[2];=0A= th->context.Dr3 =3D dr[3];=0A= /* th->context.Dr6 =3D dr[6];=0A= FIXME: should we set dr6 also ?? */=0A= th->context.Dr7 =3D dr[7];=0A= CHECK (SetThreadContext (th->h, &th->context));=0A= th->context.ContextFlags =3D 0;=0A= }=0A= return th;=0A= }=0A= =0A= /* Clear out any old thread list and reintialize it to a=0A= pristine state. */=0A= static void=0A= child_init_thread_list (void)=0A= {=0A= thread_info *th =3D &thread_head;=0A= =0A= DEBUG_EVENTS (("gdb: child_init_thread_list\n"));=0A= init_thread_list ();=0A= while (th->next !=3D NULL)=0A= {=0A= thread_info *here =3D th->next;=0A= th->next =3D here->next;=0A= (void) CloseHandle (here->h);=0A= xfree (here);=0A= }=0A= }=0A= =0A= /* Delete a thread from the list of threads */=0A= static void=0A= child_delete_thread (DWORD id)=0A= {=0A= thread_info *th;=0A= =0A= if (info_verbose)=0A= printf_unfiltered ("[Deleting %s]\n", target_pid_to_str (pid_to_ptid (i= d)));=0A= delete_thread (pid_to_ptid (id));=0A= =0A= for (th =3D &thread_head;=0A= th->next !=3D NULL && th->next->id !=3D id;=0A= th =3D th->next)=0A= continue;=0A= =0A= if (th->next !=3D NULL)=0A= {=0A= thread_info *here =3D th->next;=0A= th->next =3D here->next;=0A= CloseHandle (here->h);=0A= xfree (here);=0A= }=0A= }=0A= =0A= static void=0A= do_child_fetch_inferior_registers (int r)=0A= {=0A= char *context_offset =3D ((char *) ¤t_thread->context) + mappings[r= ];=0A= long l;=0A= if (r =3D=3D FCS_REGNUM)=0A= {=0A= l =3D *((long *) context_offset) & 0xffff;=0A= supply_register (r, (char *) &l);=0A= }=0A= else if (r =3D=3D FOP_REGNUM)=0A= {=0A= l =3D (*((long *) context_offset) >> 16) & ((1 << 11) - 1);=0A= supply_register (r, (char *) &l);=0A= }=0A= else if (r >=3D 0)=0A= supply_register (r, context_offset);=0A= else=0A= {=0A= for (r =3D 0; r < NUM_REGS; r++)=0A= do_child_fetch_inferior_registers (r);=0A= }=0A= }=0A= =0A= static void=0A= child_fetch_inferior_registers (int r)=0A= {=0A= current_thread =3D thread_rec (PIDGET (inferior_ptid), TRUE);=0A= do_child_fetch_inferior_registers (r);=0A= }=0A= =0A= static void=0A= do_child_store_inferior_registers (int r)=0A= {=0A= if (r >=3D 0)=0A= read_register_gen (r, ((char *) ¤t_thread->context) + mappings[r]= );=0A= else=0A= {=0A= for (r =3D 0; r < NUM_REGS; r++)=0A= do_child_store_inferior_registers (r);=0A= }=0A= }=0A= =0A= /* Store a new register value into the current thread context */=0A= static void=0A= child_store_inferior_registers (int r)=0A= {=0A= current_thread =3D thread_rec (PIDGET (inferior_ptid), TRUE);=0A= do_child_store_inferior_registers (r);=0A= }=0A= =0A= static int psapi_loaded =3D 0;=0A= static HMODULE psapi_module_handle =3D NULL;=0A= static BOOL WINAPI (*psapi_EnumProcessModules) (HANDLE, HMODULE *, DWORD, L= PDWORD) =3D NULL;=0A= static BOOL WINAPI (*psapi_GetModuleInformation) (HANDLE, HMODULE, LPMODULE= INFO, DWORD) =3D NULL;=0A= static DWORD WINAPI (*psapi_GetModuleFileNameExA) (HANDLE, HMODULE, LPSTR, = DWORD) =3D NULL;=0A= =0A= int=0A= psapi_get_dll_name (DWORD BaseAddress, char *dll_name_ret)=0A= {=0A= DWORD len;=0A= MODULEINFO mi;=0A= int i;=0A= HMODULE dh_buf[1];=0A= HMODULE *DllHandle =3D dh_buf;=0A= DWORD cbNeeded;=0A= BOOL ok;=0A= =0A= if (!psapi_loaded ||=0A= psapi_EnumProcessModules =3D=3D NULL ||=0A= psapi_GetModuleInformation =3D=3D NULL ||=0A= psapi_GetModuleFileNameExA =3D=3D NULL)=0A= {=0A= if (psapi_loaded)=0A= goto failed;=0A= psapi_loaded =3D 1;=0A= psapi_module_handle =3D LoadLibrary ("psapi.dll");=0A= if (!psapi_module_handle)=0A= {=0A= /* printf_unfiltered ("error loading psapi.dll: %u", GetLastError ()); *= /=0A= goto failed;=0A= }=0A= psapi_EnumProcessModules =3D GetProcAddress (psapi_module_handle, "En= umProcessModules");=0A= psapi_GetModuleInformation =3D GetProcAddress (psapi_module_handle, "= GetModuleInformation");=0A= psapi_GetModuleFileNameExA =3D (void *) GetProcAddress (psapi_module_= handle,=0A= "GetModuleFileNameExA");=0A= if (psapi_EnumProcessModules =3D=3D NULL ||=0A= psapi_GetModuleInformation =3D=3D NULL ||=0A= psapi_GetModuleFileNameExA =3D=3D NULL)=0A= goto failed;=0A= }=0A= =0A= cbNeeded =3D 0;=0A= ok =3D (*psapi_EnumProcessModules) (current_process_handle,=0A= DllHandle,=0A= sizeof (HMODULE),=0A= &cbNeeded);=0A= =0A= if (!ok || !cbNeeded)=0A= goto failed;=0A= =0A= DllHandle =3D (HMODULE *) alloca (cbNeeded);=0A= if (!DllHandle)=0A= goto failed;=0A= =0A= ok =3D (*psapi_EnumProcessModules) (current_process_handle,=0A= DllHandle,=0A= cbNeeded,=0A= &cbNeeded);=0A= if (!ok)=0A= goto failed;=0A= =0A= for (i =3D 0; i < (int) (cbNeeded / sizeof (HMODULE)); i++)=0A= {=0A= if (!(*psapi_GetModuleInformation) (current_process_handle,=0A= DllHandle[i],=0A= &mi,=0A= sizeof (mi)))=0A= error ("Can't get module info");=0A= =0A= len =3D (*psapi_GetModuleFileNameExA) (current_process_handle,=0A= DllHandle[i],=0A= dll_name_ret,=0A= MAX_PATH);=0A= if (len =3D=3D 0)=0A= error ("Error getting dll name: %u\n", GetLastError ());=0A= =0A= if ((DWORD) (mi.lpBaseOfDll) =3D=3D BaseAddress)=0A= return 1;=0A= }=0A= =0A= failed:=0A= dll_name_ret[0] =3D '\0';=0A= return 0;=0A= }=0A= =0A= /* Encapsulate the information required in a call to=0A= symbol_file_add_args */=0A= struct safe_symbol_file_add_args=0A= {=0A= char *name;=0A= int from_tty;=0A= struct section_addr_info *addrs;=0A= int mainline;=0A= int flags;=0A= struct ui_file *err, *out;=0A= struct objfile *ret;=0A= };=0A= =0A= /* Maintain a linked list of "so" information. */=0A= struct so_stuff=0A= {=0A= struct so_stuff *next;=0A= DWORD load_addr;=0A= int loaded;=0A= struct objfile *objfile;=0A= char name[1];=0A= } solib_start, *solib_end;=0A= =0A= /* Call symbol_file_add with stderr redirected. We don't care if there=0A= are errors. */=0A= static int=0A= safe_symbol_file_add_stub (void *argv)=0A= {=0A= #define p ((struct safe_symbol_file_add_args *)argv)=0A= struct so_stuff *so =3D &solib_start;=0A= =0A= while ((so =3D so->next))=0A= if (so->loaded && strcasecmp (so->name, p->name) =3D=3D 0)=0A= return 0;=0A= p->ret =3D symbol_file_add (p->name, p->from_tty, p->addrs, p->mainline, = p->flags);=0A= return !!p->ret;=0A= #undef p=0A= }=0A= =0A= /* Restore gdb's stderr after calling symbol_file_add */=0A= static void=0A= safe_symbol_file_add_cleanup (void *p)=0A= {=0A= #define sp ((struct safe_symbol_file_add_args *)p)=0A= gdb_flush (gdb_stderr);=0A= gdb_flush (gdb_stdout);=0A= ui_file_delete (gdb_stderr);=0A= ui_file_delete (gdb_stdout);=0A= gdb_stderr =3D sp->err;=0A= gdb_stdout =3D sp->out;=0A= #undef sp=0A= }=0A= =0A= /* symbol_file_add wrapper that prevents errors from being displayed. */=0A= static struct objfile *=0A= safe_symbol_file_add (char *name, int from_tty,=0A= struct section_addr_info *addrs,=0A= int mainline, int flags)=0A= {=0A= struct safe_symbol_file_add_args p;=0A= struct cleanup *cleanup;=0A= =0A= cleanup =3D make_cleanup (safe_symbol_file_add_cleanup, &p);=0A= =0A= p.err =3D gdb_stderr;=0A= p.out =3D gdb_stdout;=0A= gdb_flush (gdb_stderr);=0A= gdb_flush (gdb_stdout);=0A= gdb_stderr =3D ui_file_new ();=0A= gdb_stdout =3D ui_file_new ();=0A= p.name =3D name;=0A= p.from_tty =3D from_tty;=0A= p.addrs =3D addrs;=0A= p.mainline =3D mainline;=0A= p.flags =3D flags;=0A= catch_errors (safe_symbol_file_add_stub, &p, "", RETURN_MASK_ERROR);=0A= =0A= do_cleanups (cleanup);=0A= return p.ret;=0A= }=0A= =0A= /* Remember the maximum DLL length for printing in info dll command. */=0A= int max_dll_name_len;=0A= =0A= static void=0A= register_loaded_dll (const char *name, DWORD load_addr)=0A= {=0A= struct so_stuff *so;=0A= char ppath[MAX_PATH + 1];=0A= char buf[MAX_PATH + 1];=0A= char cwd[MAX_PATH + 1];=0A= char *p;=0A= WIN32_FIND_DATA w32_fd;=0A= HANDLE h =3D FindFirstFile(name, &w32_fd);=0A= size_t len;=0A= =0A= if (h =3D=3D INVALID_HANDLE_VALUE)=0A= strcpy (buf, name);=0A= else=0A= {=0A= FindClose (h);=0A= strcpy (buf, name);=0A= if (GetCurrentDirectory (MAX_PATH + 1, cwd))=0A= {=0A= p =3D strrchr (buf, '\\');=0A= if (p)=0A= p[1] =3D '\0';=0A= SetCurrentDirectory (buf);=0A= GetFullPathName (w32_fd.cFileName, MAX_PATH, buf, &p);=0A= SetCurrentDirectory (cwd);=0A= }=0A= }=0A= =0A= cygwin_conv_to_posix_path (buf, ppath);=0A= so =3D (struct so_stuff *) xmalloc (sizeof (struct so_stuff) + strlen (pp= ath) + 8 + 1);=0A= so->loaded =3D 0;=0A= so->load_addr =3D load_addr;=0A= so->next =3D NULL;=0A= so->objfile =3D NULL;=0A= strcpy (so->name, ppath);=0A= =0A= solib_end->next =3D so;=0A= solib_end =3D so;=0A= len =3D strlen (ppath);=0A= if (len > max_dll_name_len)=0A= max_dll_name_len =3D len;=0A= }=0A= =0A= char *=0A= get_image_name (HANDLE h, void *address, int unicode)=0A= {=0A= static char buf[(2 * MAX_PATH) + 1];=0A= DWORD size =3D unicode ? sizeof (WCHAR) : sizeof (char);=0A= char *address_ptr;=0A= int len =3D 0;=0A= char b[2];=0A= DWORD done;=0A= =0A= /* Attempt to read the name of the dll that was detected.=0A= This is documented to work only when actively debugging=0A= a program. It will not work for attached processes. */=0A= if (address =3D=3D NULL)=0A= return NULL;=0A= =0A= ReadProcessMemory (h, address, &address_ptr, sizeof (address_ptr), &done= );=0A= =0A= /* See if we could read the address of a string, and that the=0A= address isn't null. */=0A= =0A= if (done !=3D sizeof (address_ptr) || !address_ptr)=0A= return NULL;=0A= =0A= /* Find the length of the string */=0A= do=0A= {=0A= ReadProcessMemory (h, address_ptr + len * size, &b, size, &done);=0A= len++;=0A= }=0A= while ((b[0] !=3D 0 || b[size - 1] !=3D 0) && done =3D=3D size);=0A= =0A= if (!unicode)=0A= ReadProcessMemory (h, address_ptr, buf, len, &done);=0A= else=0A= {=0A= WCHAR *unicode_address =3D (WCHAR *) alloca (len * sizeof (WCHAR));= =0A= ReadProcessMemory (h, address_ptr, unicode_address, len * sizeof (WCH= AR),=0A= &done);=0A= =0A= WideCharToMultiByte (CP_ACP, 0, unicode_address, len, buf, len, 0, 0)= ;=0A= }=0A= =0A= return buf;=0A= }=0A= =0A= /* Wait for child to do something. Return pid of child, or -1 in case=0A= of error; store status through argument pointer OURSTATUS. */=0A= static int=0A= handle_load_dll (void *dummy)=0A= {=0A= LOAD_DLL_DEBUG_INFO *event =3D ¤t_event.u.LoadDll;=0A= char dll_buf[MAX_PATH + 1];=0A= char *dll_name =3D NULL;=0A= char *p;=0A= =0A= dll_buf[0] =3D dll_buf[sizeof (dll_buf) - 1] =3D '\0';=0A= =0A= if (!psapi_get_dll_name ((DWORD) (event->lpBaseOfDll), dll_buf))=0A= dll_buf[0] =3D dll_buf[sizeof (dll_buf) - 1] =3D '\0';=0A= =0A= dll_name =3D dll_buf;=0A= =0A= if (*dll_name =3D=3D '\0')=0A= dll_name =3D get_image_name (current_process_handle, event->lpImageName= , event->fUnicode);=0A= if (!dll_name)=0A= return 1;=0A= =0A= register_loaded_dll (dll_name, (DWORD) event->lpBaseOfDll + 0x1000);=0A= =0A= return 1;=0A= }=0A= =0A= static int=0A= handle_unload_dll (void *dummy)=0A= {=0A= DWORD lpBaseOfDll =3D (DWORD) current_event.u.UnloadDll.lpBaseOfDll + 0x1= 000;=0A= struct so_stuff *so;=0A= =0A= for (so =3D &solib_start; so->next !=3D NULL; so =3D so->next)=0A= if (so->next->load_addr =3D=3D lpBaseOfDll)=0A= {=0A= struct so_stuff *sodel =3D so->next;=0A= so->next =3D sodel->next;=0A= if (!so->next)=0A= solib_end =3D so;=0A= if (sodel->objfile)=0A= free_objfile (sodel->objfile);=0A= xfree(sodel);=0A= return 1;=0A= }=0A= error ("Error: dll starting at 0x%lx not found.\n", (DWORD) lpBaseOfDll);= =0A= =0A= return 0;=0A= }=0A= =0A= /* Return name of last loaded DLL. */=0A= char *=0A= child_solib_loaded_library_pathname (int pid)=0A= {=0A= return !solib_end || !solib_end->name[0] ? NULL : solib_end->name;=0A= }=0A= =0A= /* Clear list of loaded DLLs. */=0A= void=0A= child_clear_solibs (void)=0A= {=0A= struct so_stuff *so, *so1 =3D solib_start.next;=0A= =0A= while ((so =3D so1) !=3D NULL)=0A= {=0A= so1 =3D so->next;=0A= xfree (so);=0A= }=0A= =0A= solib_start.next =3D NULL;=0A= solib_start.objfile =3D NULL;=0A= solib_end =3D &solib_start;=0A= max_dll_name_len =3D sizeof ("DLL Name") - 1;=0A= }=0A= =0A= /* Add DLL symbol information. */=0A= static struct objfile *=0A= solib_symbols_add (char *name, int from_tty, CORE_ADDR load_addr)=0A= {=0A= struct section_addr_info section_addrs;=0A= =0A= /* The symbols in a dll are offset by 0x1000, which is the=0A= the offset from 0 of the first byte in an image - because=0A= of the file header and the section alignment. */=0A= =0A= if (!name || !name[0])=0A= return NULL;=0A= =0A= memset (§ion_addrs, 0, sizeof (section_addrs));=0A= section_addrs.other[0].name =3D ".text";=0A= section_addrs.other[0].addr =3D load_addr;=0A= return safe_symbol_file_add (name, from_tty, NULL, 0, OBJF_SHARED);=0A= }=0A= =0A= /* Load DLL symbol info. */=0A= void=0A= dll_symbol_command (char *args, int from_tty)=0A= {=0A= int n;=0A= dont_repeat ();=0A= =0A= if (args =3D=3D NULL)=0A= error ("dll-symbols requires a file name");=0A= =0A= n =3D strlen (args);=0A= if (n > 4 && strcasecmp (args + n - 4, ".dll") !=3D 0)=0A= {=0A= char *newargs =3D (char *) alloca (n + 4 + 1);=0A= strcpy (newargs, args);=0A= strcat (newargs, ".dll");=0A= args =3D newargs;=0A= }=0A= =0A= safe_symbol_file_add (args, from_tty, NULL, 0, OBJF_SHARED | OBJF_USERLOA= DED);=0A= }=0A= =0A= /* List currently loaded DLLs. */=0A= void=0A= info_dll_command (char *ignore, int from_tty)=0A= {=0A= struct so_stuff *so =3D &solib_start;=0A= =0A= if (!so->next)=0A= return;=0A= =0A= printf_filtered ("%*s Load Address\n", -max_dll_name_len, "DLL Name");= =0A= while ((so =3D so->next) !=3D NULL)=0A= printf_filtered ("%*s %08lx\n", -max_dll_name_len, so->name, so->load_= addr);=0A= =0A= return;=0A= }=0A= =0A= /* Handle DEBUG_STRING output from child process.=0A= Cygwin prepends its messages with a "cygwin:". Interpret this as=0A= a Cygwin signal. Otherwise just print the string as a warning. */=0A= static int=0A= handle_output_debug_string (struct target_waitstatus *ourstatus)=0A= {=0A= char *s;=0A= int gotasig =3D FALSE;=0A= =0A= if (!target_read_string=0A= ((CORE_ADDR) current_event.u.DebugString.lpDebugStringData, &s, 1024, 0= )=0A= || !s || !*s)=0A= return gotasig;=0A= =0A= if (strncmp (s, CYGWIN_SIGNAL_STRING, sizeof (CYGWIN_SIGNAL_STRING) - 1) = !=3D 0)=0A= {=0A= if (strncmp (s, "cYg", 3) !=3D 0)=0A= warning ("%s", s);=0A= }=0A= else=0A= {=0A= char *p;=0A= int sig =3D strtol (s + sizeof (CYGWIN_SIGNAL_STRING) - 1, &p, 0);=0A= gotasig =3D target_signal_from_host (sig);=0A= ourstatus->value.sig =3D gotasig;=0A= if (gotasig)=0A= ourstatus->kind =3D TARGET_WAITKIND_STOPPED;=0A= }=0A= =0A= xfree (s);=0A= return gotasig;=0A= }=0A= =0A= static int=0A= display_selector (HANDLE thread, DWORD sel)=0A= {=0A= LDT_ENTRY info;=0A= if (GetThreadSelectorEntry (thread, sel, &info))=0A= {=0A= int base, limit;=0A= printf_filtered ("0x%03lx: ", sel);=0A= if (!info.HighWord.Bits.Pres)=0A= {=0A= puts_filtered ("Segment not present\n");=0A= return 0;=0A= }=0A= base =3D (info.HighWord.Bits.BaseHi << 24) +=0A= (info.HighWord.Bits.BaseMid << 16)=0A= + info.BaseLow;=0A= limit =3D (info.HighWord.Bits.LimitHi << 16) + info.LimitLow;=0A= if (info.HighWord.Bits.Granularity)=0A= limit =3D (limit << 12) | 0xfff;=0A= printf_filtered ("base=3D0x%08x limit=3D0x%08x", base, limit);=0A= if (info.HighWord.Bits.Default_Big)=0A= puts_filtered(" 32-bit ");=0A= else=0A= puts_filtered(" 16-bit ");=0A= switch ((info.HighWord.Bits.Type & 0xf) >> 1)=0A= {=0A= case 0:=0A= puts_filtered ("Data (Read-Only, Exp-up");=0A= break;=0A= case 1:=0A= puts_filtered ("Data (Read/Write, Exp-up");=0A= break;=0A= case 2:=0A= puts_filtered ("Unused segment (");=0A= break;=0A= case 3:=0A= puts_filtered ("Data (Read/Write, Exp-down");=0A= break;=0A= case 4:=0A= puts_filtered ("Code (Exec-Only, N.Conf");=0A= break;=0A= case 5:=0A= puts_filtered ("Code (Exec/Read, N.Conf");=0A= break;=0A= case 6:=0A= puts_filtered ("Code (Exec-Only, Conf");=0A= break;=0A= case 7:=0A= puts_filtered ("Code (Exec/Read, Conf");=0A= break;=0A= default:=0A= printf_filtered ("Unknown type 0x%x",info.HighWord.Bits.Type);=0A= }=0A= if ((info.HighWord.Bits.Type & 0x1) =3D=3D 0)=0A= puts_filtered(", N.Acc");=0A= puts_filtered (")\n");=0A= if ((info.HighWord.Bits.Type & 0x10) =3D=3D 0)=0A= puts_filtered("System selector ");=0A= printf_filtered ("Priviledge level =3D %d. ", info.HighWord.Bits.Dpl)= ;=0A= if (info.HighWord.Bits.Granularity)=0A= puts_filtered ("Page granular.\n");=0A= else=0A= puts_filtered ("Byte granular.\n");=0A= return 1;=0A= }=0A= else=0A= {=0A= printf_filtered ("Invalid selector 0x%lx.\n",sel);=0A= return 0;=0A= }=0A= }=0A= =0A= static void=0A= display_selectors (char * args, int from_tty)=0A= {=0A= if (!current_thread)=0A= {=0A= puts_filtered ("Impossible to display selectors now.\n");=0A= return;=0A= }=0A= if (!args)=0A= {=0A= =0A= puts_filtered ("Selector $cs\n");=0A= display_selector (current_thread->h,=0A= current_thread->context.SegCs);=0A= puts_filtered ("Selector $ds\n");=0A= display_selector (current_thread->h,=0A= current_thread->context.SegDs);=0A= puts_filtered ("Selector $es\n");=0A= display_selector (current_thread->h,=0A= current_thread->context.SegEs);=0A= puts_filtered ("Selector $ss\n");=0A= display_selector (current_thread->h,=0A= current_thread->context.SegSs);=0A= puts_filtered ("Selector $fs\n");=0A= display_selector (current_thread->h,=0A= current_thread->context.SegFs);=0A= puts_filtered ("Selector $gs\n");=0A= display_selector (current_thread->h,=0A= current_thread->context.SegGs);=0A= }=0A= else=0A= {=0A= int sel;=0A= sel =3D parse_and_eval_long (args);=0A= printf_filtered ("Selector \"%s\"\n",args);=0A= display_selector (current_thread->h, sel);=0A= }=0A= }=0A= =0A= static struct cmd_list_element *info_w32_cmdlist =3D NULL;=0A= =0A= static void=0A= info_w32_command (char *args, int from_tty)=0A= {=0A= help_list (info_w32_cmdlist, "info w32 ", class_info, gdb_stdout);=0A= }=0A= =0A= =0A= #define DEBUG_EXCEPTION_SIMPLE(x) if (debug_exceptions) \=0A= printf_unfiltered ("gdb: Target exception %s at 0x%08lx\n", x, \=0A= (DWORD) current_event.u.Exception.ExceptionRecord.ExceptionAddress)=0A= =0A= static int=0A= handle_exception (struct target_waitstatus *ourstatus)=0A= {=0A= thread_info *th;=0A= DWORD code =3D current_event.u.Exception.ExceptionRecord.ExceptionCode;= =0A= =0A= ourstatus->kind =3D TARGET_WAITKIND_STOPPED;=0A= =0A= /* Record the context of the current thread */=0A= th =3D thread_rec (current_event.dwThreadId, -1);=0A= =0A= switch (code)=0A= {=0A= case EXCEPTION_ACCESS_VIOLATION:=0A= DEBUG_EXCEPTION_SIMPLE ("EXCEPTION_ACCESS_VIOLATION");=0A= ourstatus->value.sig =3D TARGET_SIGNAL_SEGV;=0A= break;=0A= case STATUS_STACK_OVERFLOW:=0A= DEBUG_EXCEPTION_SIMPLE ("STATUS_STACK_OVERFLOW");=0A= ourstatus->value.sig =3D TARGET_SIGNAL_SEGV;=0A= break;=0A= case STATUS_FLOAT_DENORMAL_OPERAND:=0A= DEBUG_EXCEPTION_SIMPLE ("STATUS_FLOAT_DENORMAL_OPERAND");=0A= ourstatus->value.sig =3D TARGET_SIGNAL_FPE;=0A= break;=0A= case EXCEPTION_ARRAY_BOUNDS_EXCEEDED:=0A= DEBUG_EXCEPTION_SIMPLE ("EXCEPTION_ARRAY_BOUNDS_EXCEEDED");=0A= ourstatus->value.sig =3D TARGET_SIGNAL_FPE;=0A= break;=0A= case STATUS_FLOAT_INEXACT_RESULT:=0A= DEBUG_EXCEPTION_SIMPLE ("STATUS_FLOAT_INEXACT_RESULT");=0A= ourstatus->value.sig =3D TARGET_SIGNAL_FPE;=0A= break;=0A= case STATUS_FLOAT_INVALID_OPERATION:=0A= DEBUG_EXCEPTION_SIMPLE ("STATUS_FLOAT_INVALID_OPERATION");=0A= ourstatus->value.sig =3D TARGET_SIGNAL_FPE;=0A= break;=0A= case STATUS_FLOAT_OVERFLOW:=0A= DEBUG_EXCEPTION_SIMPLE ("STATUS_FLOAT_OVERFLOW");=0A= ourstatus->value.sig =3D TARGET_SIGNAL_FPE;=0A= break;=0A= case STATUS_FLOAT_STACK_CHECK:=0A= DEBUG_EXCEPTION_SIMPLE ("STATUS_FLOAT_STACK_CHECK");=0A= ourstatus->value.sig =3D TARGET_SIGNAL_FPE;=0A= break;=0A= case STATUS_FLOAT_UNDERFLOW:=0A= DEBUG_EXCEPTION_SIMPLE ("STATUS_FLOAT_UNDERFLOW");=0A= ourstatus->value.sig =3D TARGET_SIGNAL_FPE;=0A= break;=0A= case STATUS_FLOAT_DIVIDE_BY_ZERO:=0A= DEBUG_EXCEPTION_SIMPLE ("STATUS_FLOAT_DIVIDE_BY_ZERO");=0A= ourstatus->value.sig =3D TARGET_SIGNAL_FPE;=0A= break;=0A= case STATUS_INTEGER_DIVIDE_BY_ZERO:=0A= DEBUG_EXCEPTION_SIMPLE ("STATUS_INTEGER_DIVIDE_BY_ZERO");=0A= ourstatus->value.sig =3D TARGET_SIGNAL_FPE;=0A= break;=0A= case STATUS_INTEGER_OVERFLOW:=0A= DEBUG_EXCEPTION_SIMPLE ("STATUS_INTEGER_OVERFLOW");=0A= ourstatus->value.sig =3D TARGET_SIGNAL_FPE;=0A= break;=0A= case EXCEPTION_BREAKPOINT:=0A= DEBUG_EXCEPTION_SIMPLE ("EXCEPTION_BREAKPOINT");=0A= ourstatus->value.sig =3D TARGET_SIGNAL_TRAP;=0A= break;=0A= case DBG_CONTROL_C:=0A= DEBUG_EXCEPTION_SIMPLE ("DBG_CONTROL_C");=0A= ourstatus->value.sig =3D TARGET_SIGNAL_INT;=0A= break;=0A= case DBG_CONTROL_BREAK:=0A= DEBUG_EXCEPTION_SIMPLE ("DBG_CONTROL_BREAK");=0A= ourstatus->value.sig =3D TARGET_SIGNAL_INT;=0A= break;=0A= case EXCEPTION_SINGLE_STEP:=0A= DEBUG_EXCEPTION_SIMPLE ("EXCEPTION_SINGLE_STEP");=0A= ourstatus->value.sig =3D TARGET_SIGNAL_TRAP;=0A= break;=0A= case EXCEPTION_ILLEGAL_INSTRUCTION:=0A= DEBUG_EXCEPTION_SIMPLE ("EXCEPTION_ILLEGAL_INSTRUCTION");=0A= ourstatus->value.sig =3D TARGET_SIGNAL_ILL;=0A= break;=0A= case EXCEPTION_PRIV_INSTRUCTION:=0A= DEBUG_EXCEPTION_SIMPLE ("EXCEPTION_PRIV_INSTRUCTION");=0A= ourstatus->value.sig =3D TARGET_SIGNAL_ILL;=0A= break;=0A= case EXCEPTION_NONCONTINUABLE_EXCEPTION:=0A= DEBUG_EXCEPTION_SIMPLE ("EXCEPTION_NONCONTINUABLE_EXCEPTION");=0A= ourstatus->value.sig =3D TARGET_SIGNAL_ILL;=0A= break;=0A= default:=0A= if (current_event.u.Exception.dwFirstChance)=0A= return 0;=0A= printf_unfiltered ("gdb: unknown target exception 0x%08lx at 0x%08lx\= n",=0A= current_event.u.Exception.ExceptionRecord.ExceptionCode,=0A= (DWORD) current_event.u.Exception.ExceptionRecord.ExceptionAddress);=0A= ourstatus->value.sig =3D TARGET_SIGNAL_UNKNOWN;=0A= break;=0A= }=0A= exception_count++;=0A= last_sig =3D ourstatus->value.sig;=0A= return 1;=0A= }=0A= =0A= /* Resume all artificially suspended threads if we are continuing=0A= execution */=0A= static BOOL=0A= child_continue (DWORD continue_status, int id)=0A= {=0A= int i;=0A= thread_info *th;=0A= BOOL res;=0A= =0A= DEBUG_EVENTS (("ContinueDebugEvent (cpid=3D%ld, ctid=3D%ld, %s);\n",=0A= current_event.dwProcessId, current_event.dwThreadId,=0A= continue_status =3D=3D DBG_CONTINUE ?=0A= "DBG_CONTINUE" : "DBG_EXCEPTION_NOT_HANDLED"));=0A= res =3D ContinueDebugEvent (current_event.dwProcessId,=0A= current_event.dwThreadId,=0A= continue_status);=0A= continue_status =3D 0;=0A= if (res)=0A= for (th =3D &thread_head; (th =3D th->next) !=3D NULL;)=0A= if (((id =3D=3D -1) || (id =3D=3D (int) th->id)) && th->suspend_count= )=0A= {=0A= =0A= for (i =3D 0; i < th->suspend_count; i++)=0A= (void) ResumeThread (th->h);=0A= th->suspend_count =3D 0;=0A= if (debug_registers_changed)=0A= {=0A= /* Only change the value of the debug reisters */=0A= th->context.ContextFlags =3D CONTEXT_DEBUG_REGISTERS;=0A= th->context.Dr0 =3D dr[0];=0A= th->context.Dr1 =3D dr[1];=0A= th->context.Dr2 =3D dr[2];=0A= th->context.Dr3 =3D dr[3];=0A= /* th->context.Dr6 =3D dr[6];=0A= FIXME: should we set dr6 also ?? */=0A= th->context.Dr7 =3D dr[7];=0A= CHECK (SetThreadContext (th->h, &th->context));=0A= th->context.ContextFlags =3D 0;=0A= }=0A= }=0A= =0A= debug_registers_changed =3D 0;=0A= return res;=0A= }=0A= =0A= /* Get the next event from the child. Return 1 if the event requires=0A= handling by WFI (or whatever).=0A= */=0A= static int=0A= get_child_debug_event (int pid, struct target_waitstatus *ourstatus)=0A= {=0A= BOOL debug_event;=0A= DWORD continue_status, event_code;=0A= thread_info *th =3D NULL;=0A= static thread_info dummy_thread_info;=0A= int retval =3D 0;=0A= =0A= last_sig =3D TARGET_SIGNAL_0;=0A= =0A= if (!(debug_event =3D WaitForDebugEvent (¤t_event, 1000)))=0A= goto out;=0A= =0A= event_count++;=0A= continue_status =3D DBG_CONTINUE;=0A= =0A= event_code =3D current_event.dwDebugEventCode;=0A= ourstatus->kind =3D TARGET_WAITKIND_SPURIOUS;=0A= =0A= switch (event_code)=0A= {=0A= case CREATE_THREAD_DEBUG_EVENT:=0A= DEBUG_EVENTS (("gdb: kernel event for pid=3D%d tid=3D%x code=3D%s)\n"= ,=0A= (unsigned) current_event.dwProcessId,=0A= (unsigned) current_event.dwThreadId,=0A= "CREATE_THREAD_DEBUG_EVENT"));=0A= if (saw_create !=3D 1)=0A= break;=0A= /* Record the existence of this thread */=0A= th =3D child_add_thread (current_event.dwThreadId,=0A= current_event.u.CreateThread.hThread);=0A= if (info_verbose)=0A= printf_unfiltered ("[New %s]\n",=0A= target_pid_to_str (=0A= pid_to_ptid (current_event.dwThreadId)));=0A= retval =3D current_event.dwThreadId;=0A= break;=0A= =0A= case EXIT_THREAD_DEBUG_EVENT:=0A= DEBUG_EVENTS (("gdb: kernel event for pid=3D%d tid=3D%d code=3D%s)\n"= ,=0A= (unsigned) current_event.dwProcessId,=0A= (unsigned) current_event.dwThreadId,=0A= "EXIT_THREAD_DEBUG_EVENT"));=0A= if (saw_create !=3D 1)=0A= break;=0A= child_delete_thread (current_event.dwThreadId);=0A= th =3D &dummy_thread_info;=0A= break;=0A= =0A= case CREATE_PROCESS_DEBUG_EVENT:=0A= DEBUG_EVENTS (("gdb: kernel event for pid=3D%d tid=3D%d code=3D%s)\n"= ,=0A= (unsigned) current_event.dwProcessId,=0A= (unsigned) current_event.dwThreadId,=0A= "CREATE_PROCESS_DEBUG_EVENT"));=0A= CloseHandle (current_event.u.CreateProcessInfo.hFile);=0A= if (++saw_create !=3D 1)=0A= {=0A= CloseHandle (current_event.u.CreateProcessInfo.hProcess);=0A= break;=0A= }=0A= =0A= current_process_handle =3D current_event.u.CreateProcessInfo.hProcess= ;=0A= main_thread_id =3D current_event.dwThreadId;=0A= /* Add the main thread */=0A= #if 0=0A= th =3D child_add_thread (current_event.dwProcessId,=0A= current_event.u.CreateProcessInfo.hProcess);=0A= #endif=0A= th =3D child_add_thread (main_thread_id,=0A= current_event.u.CreateProcessInfo.hThread);=0A= retval =3D ourstatus->value.related_pid =3D current_event.dwThreadId;= =0A= break;=0A= =0A= case EXIT_PROCESS_DEBUG_EVENT:=0A= DEBUG_EVENTS (("gdb: kernel event for pid=3D%d tid=3D%d code=3D%s)\n"= ,=0A= (unsigned) current_event.dwProcessId,=0A= (unsigned) current_event.dwThreadId,=0A= "EXIT_PROCESS_DEBUG_EVENT"));=0A= if (saw_create !=3D 1)=0A= break;=0A= ourstatus->kind =3D TARGET_WAITKIND_EXITED;=0A= ourstatus->value.integer =3D current_event.u.ExitProcess.dwExitCode;= =0A= CloseHandle (current_process_handle);=0A= retval =3D main_thread_id;=0A= break;=0A= =0A= case LOAD_DLL_DEBUG_EVENT:=0A= DEBUG_EVENTS (("gdb: kernel event for pid=3D%d tid=3D%d code=3D%s)\n"= ,=0A= (unsigned) current_event.dwProcessId,=0A= (unsigned) current_event.dwThreadId,=0A= "LOAD_DLL_DEBUG_EVENT"));=0A= CloseHandle (current_event.u.LoadDll.hFile);=0A= if (saw_create !=3D 1)=0A= break;=0A= catch_errors (handle_load_dll, NULL, (char *) "", RETURN_MASK_ALL);= =0A= registers_changed (); /* mark all regs invalid */=0A= ourstatus->kind =3D TARGET_WAITKIND_LOADED;=0A= ourstatus->value.integer =3D 0;=0A= retval =3D main_thread_id;=0A= break;=0A= =0A= case UNLOAD_DLL_DEBUG_EVENT:=0A= DEBUG_EVENTS (("gdb: kernel event for pid=3D%d tid=3D%d code=3D%s)\n"= ,=0A= (unsigned) current_event.dwProcessId,=0A= (unsigned) current_event.dwThreadId,=0A= "UNLOAD_DLL_DEBUG_EVENT"));=0A= if (saw_create !=3D 1)=0A= break;=0A= catch_errors (handle_unload_dll, NULL, (char *) "", RETURN_MASK_ALL);= =0A= registers_changed (); /* mark all regs invalid */=0A= /* ourstatus->kind =3D TARGET_WAITKIND_UNLOADED;=0A= does not exist yet. */=0A= break;=0A= =0A= case EXCEPTION_DEBUG_EVENT:=0A= DEBUG_EVENTS (("gdb: kernel event for pid=3D%d tid=3D%d code=3D%s)\n"= ,=0A= (unsigned) current_event.dwProcessId,=0A= (unsigned) current_event.dwThreadId,=0A= "EXCEPTION_DEBUG_EVENT"));=0A= if (saw_create !=3D 1)=0A= break;=0A= if (handle_exception (ourstatus))=0A= retval =3D current_event.dwThreadId;=0A= break;=0A= =0A= case OUTPUT_DEBUG_STRING_EVENT: /* message from the kernel */=0A= DEBUG_EVENTS (("gdb: kernel event for pid=3D%d tid=3D%d code=3D%s)\n"= ,=0A= (unsigned) current_event.dwProcessId,=0A= (unsigned) current_event.dwThreadId,=0A= "OUTPUT_DEBUG_STRING_EVENT"));=0A= if (saw_create !=3D 1)=0A= break;=0A= if (handle_output_debug_string (ourstatus))=0A= retval =3D main_thread_id;=0A= break;=0A= =0A= default:=0A= if (saw_create !=3D 1)=0A= break;=0A= printf_unfiltered ("gdb: kernel event for pid=3D%ld tid=3D%ld\n",=0A= (DWORD) current_event.dwProcessId,=0A= (DWORD) current_event.dwThreadId);=0A= printf_unfiltered (" unknown event code %ld\n",=0A= current_event.dwDebugEventCode);=0A= break;=0A= }=0A= =0A= if (!retval || saw_create !=3D 1)=0A= CHECK (child_continue (continue_status, -1));=0A= else=0A= {=0A= current_thread =3D th ? : thread_rec (current_event.dwThreadId, TRUE)= ;=0A= inferior_ptid =3D pid_to_ptid (retval);=0A= }=0A= =0A= out:=0A= return retval;=0A= }=0A= =0A= /* Wait for interesting events to occur in the target process. */=0A= static ptid_t=0A= child_wait (ptid_t ptid, struct target_waitstatus *ourstatus)=0A= {=0A= int pid =3D PIDGET (ptid);=0A= =0A= /* We loop when we get a non-standard exception rather than return=0A= with a SPURIOUS because resume can try and step or modify things,=0A= which needs a current_thread->h. But some of these exceptions mark=0A= the birth or death of threads, which mean that the current thread=0A= isn't necessarily what you think it is. */=0A= =0A= while (1)=0A= {=0A= int retval =3D get_child_debug_event (pid, ourstatus);=0A= if (retval)=0A= return pid_to_ptid (retval);=0A= else=0A= {=0A= int detach =3D 0;=0A= =0A= if (ui_loop_hook !=3D NULL)=0A= detach =3D ui_loop_hook (0);=0A= =0A= if (detach)=0A= child_kill_inferior ();=0A= }=0A= }=0A= }=0A= =0A= static void=0A= do_initial_child_stuff (DWORD pid)=0A= {=0A= extern int stop_after_trap;=0A= int i;=0A= =0A= last_sig =3D TARGET_SIGNAL_0;=0A= event_count =3D 0;=0A= exception_count =3D 0;=0A= debug_registers_changed =3D 0;=0A= debug_registers_used =3D 0;=0A= for (i =3D 0; i < sizeof (dr) / sizeof (dr[0]); i++)=0A= dr[i] =3D 0;=0A= current_event.dwProcessId =3D pid;=0A= memset (¤t_event, 0, sizeof (current_event));=0A= push_target (&child_ops);=0A= child_init_thread_list ();=0A= child_clear_solibs ();=0A= clear_proceed_status ();=0A= init_wait_for_inferior ();=0A= =0A= target_terminal_init ();=0A= target_terminal_inferior ();=0A= =0A= while (1)=0A= {=0A= stop_after_trap =3D 1;=0A= wait_for_inferior ();=0A= if (stop_signal !=3D TARGET_SIGNAL_TRAP)=0A= resume (0, stop_signal);=0A= else=0A= break;=0A= }=0A= stop_after_trap =3D 0;=0A= return;=0A= }=0A= =0A= /* Since Windows XP, detaching from a process is supported by Windows.=0A= The following code tries loading the appropriate functions dynamically.= =0A= If loading these functions succeeds use them to actually detach from=0A= the inferior process, otherwise behave as usual, pretending that=0A= detach has worked. */=0A= static BOOL WINAPI (*DebugSetProcessKillOnExit)(BOOL);=0A= static BOOL WINAPI (*DebugActiveProcessStop)(DWORD);=0A= =0A= static int=0A= has_detach_ability ()=0A= {=0A= static HMODULE kernel32 =3D NULL;=0A= =0A= if (!kernel32)=0A= kernel32 =3D LoadLibrary ("kernel32.dll");=0A= if (kernel32)=0A= {=0A= if (!DebugSetProcessKillOnExit)=0A= DebugSetProcessKillOnExit =3D GetProcAddress (kernel32,=0A= "DebugSetProcessKillOnExit");=0A= if (!DebugActiveProcessStop)=0A= DebugActiveProcessStop =3D GetProcAddress (kernel32,=0A= "DebugActiveProcessStop");=0A= if (DebugSetProcessKillOnExit && DebugActiveProcessStop)=0A= return 1;=0A= }=0A= return 0;=0A= }=0A= =0A= /* Attach to process PID, then initialize for debugging it. */=0A= static void=0A= child_attach (char *args, int from_tty)=0A= {=0A= BOOL ok;=0A= DWORD pid;=0A= =0A= if (!args)=0A= error_no_arg ("process-id to attach");=0A= =0A= pid =3D strtoul (args, 0, 0);=0A= ok =3D DebugActiveProcess (pid);=0A= =0A= if (!ok)=0A= error ("Can't attach to process.");=0A= =0A= if (has_detach_ability ())=0A= {=0A= attach_flag =3D 1;=0A= DebugSetProcessKillOnExit (FALSE);=0A= }=0A= =0A= if (from_tty)=0A= {=0A= char *exec_file =3D (char *) get_exec_file (0);=0A= =0A= if (exec_file)=0A= printf_unfiltered ("Attaching to program `%s', %s\n", exec_file,=0A= target_pid_to_str (pid_to_ptid (pid)));=0A= else=0A= printf_unfiltered ("Attaching to %s\n",=0A= target_pid_to_str (pid_to_ptid (pid)));=0A= =0A= gdb_flush (gdb_stdout);=0A= }=0A= =0A= do_initial_child_stuff (pid);=0A= target_terminal_ours ();=0A= }=0A= =0A= static void=0A= child_detach (char *args, int from_tty)=0A= {=0A= int detached =3D 1;=0A= =0A= if (has_detach_ability ())=0A= {=0A= delete_command (NULL, 0);=0A= child_continue (DBG_CONTINUE, -1);=0A= if (!DebugActiveProcessStop (current_event.dwProcessId))=0A= {=0A= error ("Can't detach process %lu (error %lu)",=0A= current_event.dwProcessId, GetLastError ());=0A= detached =3D 0;=0A= }=0A= DebugSetProcessKillOnExit (FALSE);=0A= }=0A= if (detached && from_tty)=0A= {=0A= char *exec_file =3D get_exec_file (0);=0A= if (exec_file =3D=3D 0)=0A= exec_file =3D "";=0A= printf_unfiltered ("Detaching from program: %s, Pid %lu\n", exec_file= ,=0A= current_event.dwProcessId);=0A= gdb_flush (gdb_stdout);=0A= }=0A= inferior_ptid =3D null_ptid;=0A= unpush_target (&child_ops);=0A= }=0A= =0A= /* Print status information about what we're accessing. */=0A= =0A= static void=0A= child_files_info (struct target_ops *ignore)=0A= {=0A= printf_unfiltered ("\tUsing the running image of %s %s.\n",=0A= attach_flag ? "attached" : "child", target_pid_to_str (inferior_ptid)= );=0A= }=0A= =0A= /* ARGSUSED */=0A= static void=0A= child_open (char *arg, int from_tty)=0A= {=0A= error ("Use the \"run\" command to start a Unix child process.");=0A= }=0A= =0A= /* Start an inferior win32 child process and sets inferior_ptid to its pid.= =0A= EXEC_FILE is the file to run.=0A= ALLARGS is a string containing the arguments to the program.=0A= ENV is the environment vector to pass. Errors reported with error(). *= /=0A= =0A= static void=0A= child_create_inferior (char *exec_file, char *allargs, char **env)=0A= {=0A= char *winenv;=0A= char *temp;=0A= int envlen;=0A= int i;=0A= STARTUPINFO si;=0A= PROCESS_INFORMATION pi;=0A= BOOL ret;=0A= DWORD flags;=0A= char *args;=0A= char real_path[MAXPATHLEN];=0A= char *toexec;=0A= char shell[MAX_PATH + 1]; /* Path to shell */=0A= const char *sh;=0A= =20=20=0A= /* QUINCY */=20=20=0A= HANDLE hStdInput =3D 0;=0A= HANDLE hStdOutput =3D 0;=0A= HANDLE hStdError =3D 0;=0A= /* QUINCY */=20=0A= =20=20=0A= if (!exec_file)=0A= error ("No executable specified, use `target exec'.\n");=0A= =0A= memset (&si, 0, sizeof (si));=0A= si.cb =3D sizeof (si);=0A= =0A= if (!useshell)=0A= {=0A= flags =3D DEBUG_ONLY_THIS_PROCESS;=0A= cygwin_conv_to_win32_path (exec_file, real_path);=0A= toexec =3D real_path;=0A= }=0A= else=0A= {=0A= char *newallargs;=0A= sh =3D getenv ("SHELL");=0A= if (!sh)=0A= sh =3D "/bin/sh";=0A= cygwin_conv_to_win32_path (sh, shell);=0A= newallargs =3D alloca (sizeof (" -c 'exec '") + strlen (exec_file)= =0A= + strlen (allargs) + 2);=0A= sprintf (newallargs, " -c 'exec %s %s'", exec_file, allargs);=0A= allargs =3D newallargs;=0A= toexec =3D shell;=0A= flags =3D DEBUG_PROCESS;=0A= }=0A= =0A= if (new_group)=0A= flags |=3D CREATE_NEW_PROCESS_GROUP;=0A= =0A= if (new_console)=0A= flags |=3D CREATE_NEW_CONSOLE;=0A= =0A= args =3D alloca (strlen (toexec) + strlen (allargs) + 2);=0A= strcpy (args, toexec);=0A= strcat (args, " ");=0A= strcat (args, allargs);=0A= =0A= /* Prepare the environment vars for CreateProcess. */=0A= {=0A= /* This code used to assume all env vars were file names and would=0A= translate them all to win32 style. That obviously doesn't work in t= he=0A= general case. The current rule is that we only translate PATH.=0A= We need to handle PATH because we're about to call CreateProcess and= =0A= it uses PATH to find DLL's. Fortunately PATH has a well-defined val= ue=0A= in both posix and win32 environments. cygwin.dll will change it bac= k=0A= to posix style if necessary. */=0A= =0A= static const char *conv_path_names[] =3D=0A= {=0A= "PATH=3D",=0A= 0=0A= };=0A= =0A= /* CreateProcess takes the environment list as a null terminated set of= =0A= strings (i.e. two nulls terminate the list). */=0A= =0A= /* Get total size for env strings. */=0A= for (envlen =3D 0, i =3D 0; env[i] && *env[i]; i++)=0A= {=0A= int j, len;=0A= =0A= for (j =3D 0; conv_path_names[j]; j++)=0A= {=0A= len =3D strlen (conv_path_names[j]);=0A= if (strncmp (conv_path_names[j], env[i], len) =3D=3D 0)=0A= {=0A= if (cygwin_posix_path_list_p (env[i] + len))=0A= envlen +=3D len=0A= + cygwin_posix_to_win32_path_list_buf_size (env[i] + len);=0A= else=0A= envlen +=3D strlen (env[i]) + 1;=0A= break;=0A= }=0A= }=0A= if (conv_path_names[j] =3D=3D NULL)=0A= envlen +=3D strlen (env[i]) + 1;=0A= }=0A= =0A= winenv =3D alloca (envlen + 1);=0A= =0A= /* Copy env strings into new buffer. */=0A= for (temp =3D winenv, i =3D 0; env[i] && *env[i]; i++)=0A= {=0A= int j, len;=0A= =0A= for (j =3D 0; conv_path_names[j]; j++)=0A= {=0A= len =3D strlen (conv_path_names[j]);=0A= if (strncmp (conv_path_names[j], env[i], len) =3D=3D 0)=0A= {=0A= if (cygwin_posix_path_list_p (env[i] + len))=0A= {=0A= memcpy (temp, env[i], len);=0A= cygwin_posix_to_win32_path_list (env[i] + len, temp + len);=0A= }=0A= else=0A= strcpy (temp, env[i]);=0A= break;=0A= }=0A= }=0A= if (conv_path_names[j] =3D=3D NULL)=0A= strcpy (temp, env[i]);=0A= =0A= temp +=3D strlen (temp) + 1;=0A= }=0A= =0A= /* Final nil string to terminate new env. */=0A= *temp =3D 0;=0A= }=0A= =0A= =0A= =0A= /* QUINCY */=0A= if (new_console) {=0A= hStdInput=3DGetStdHandle(STD_INPUT_HANDLE);=0A= hStdOutput=3DGetStdHandle(STD_OUTPUT_HANDLE);=0A= hStdError=3DGetStdHandle(STD_ERROR_HANDLE);=0A= SetStdHandle(STD_INPUT_HANDLE, INVALID_HANDLE_VALUE);=0A= SetStdHandle(STD_OUTPUT_HANDLE, INVALID_HANDLE_VALUE);=0A= SetStdHandle(STD_ERROR_HANDLE, INVALID_HANDLE_VALUE);=0A= }=0A= /* QUINCY */=0A= =20=20=0A= =0A= ret =3D CreateProcess (0,=0A= args, /* command line */=0A= NULL, /* Security */=0A= NULL, /* thread */=0A= TRUE, /* inherit handles */=0A= flags, /* start flags */=0A= winenv,=0A= NULL, /* current directory */=0A= &si,=0A= &pi);=0A= if (!ret)=0A= error ("Error creating process %s, (error %d)\n", exec_file, GetLastErr= or ());=0A= =0A= CloseHandle (pi.hThread);=0A= CloseHandle (pi.hProcess);=0A= =0A= /* QUINCY */=0A= if (new_console) {=0A= SetStdHandle(STD_INPUT_HANDLE, hStdInput);=0A= SetStdHandle(STD_OUTPUT_HANDLE, hStdOutput);=0A= SetStdHandle(STD_ERROR_HANDLE, hStdError);=0A= }=0A= /* QUINCY */=0A= =0A= if (useshell && shell[0] !=3D '\0')=0A= saw_create =3D -1;=0A= else=0A= saw_create =3D 0;=0A= =0A= do_initial_child_stuff (pi.dwProcessId);=0A= =0A= /* child_continue (DBG_CONTINUE, -1); */=0A= proceed ((CORE_ADDR) - 1, TARGET_SIGNAL_0, 0);=0A= }=0A= =0A= static void=0A= child_mourn_inferior (void)=0A= {=0A= (void) child_continue (DBG_CONTINUE, -1);=0A= i386_cleanup_dregs();=0A= unpush_target (&child_ops);=0A= generic_mourn_inferior ();=0A= }=0A= =0A= /* Send a SIGINT to the process group. This acts just like the user typed = a=0A= ^C on the controlling terminal. */=0A= =0A= static void=0A= child_stop (void)=0A= {=0A= DEBUG_EVENTS (("gdb: GenerateConsoleCtrlEvent (CTRLC_EVENT, 0)\n"));=0A= CHECK (GenerateConsoleCtrlEvent (CTRL_C_EVENT, current_event.dwProcessId)= );=0A= registers_changed (); /* refresh register state */=0A= }=0A= =0A= int=0A= child_xfer_memory (CORE_ADDR memaddr, char *our, int len,=0A= int write, struct mem_attrib *mem,=0A= struct target_ops *target)=0A= {=0A= DWORD done;=0A= if (write)=0A= {=0A= DEBUG_MEM (("gdb: write target memory, %d bytes at 0x%08lx\n",=0A= len, (DWORD) memaddr));=0A= WriteProcessMemory (current_process_handle, (LPVOID) memaddr, our,=0A= len, &done);=0A= FlushInstructionCache (current_process_handle, (LPCVOID) memaddr, len= );=0A= }=0A= else=0A= {=0A= DEBUG_MEM (("gdb: read target memory, %d bytes at 0x%08lx\n",=0A= len, (DWORD) memaddr));=0A= ReadProcessMemory (current_process_handle, (LPCVOID) memaddr, our, le= n,=0A= &done);=0A= }=0A= return done;=0A= }=0A= =0A= void=0A= child_kill_inferior (void)=0A= {=0A= CHECK (TerminateProcess (current_process_handle, 0));=0A= =0A= for (;;)=0A= {=0A= if (!child_continue (DBG_CONTINUE, -1))=0A= break;=0A= if (!WaitForDebugEvent (¤t_event, INFINITE))=0A= break;=0A= if (current_event.dwDebugEventCode =3D=3D EXIT_PROCESS_DEBUG_EVENT)= =0A= break;=0A= }=0A= =0A= CHECK (CloseHandle (current_process_handle));=0A= =0A= /* this may fail in an attached process so don't check. */=0A= (void) CloseHandle (current_thread->h);=0A= target_mourn_inferior (); /* or just child_mourn_inferior? */=0A= }=0A= =0A= void=0A= child_resume (ptid_t ptid, int step, enum target_signal sig)=0A= {=0A= thread_info *th;=0A= DWORD continue_status =3D DBG_CONTINUE;=0A= =0A= int pid =3D PIDGET (ptid);=0A= =0A= if (sig !=3D TARGET_SIGNAL_0)=0A= {=0A= if (current_event.dwDebugEventCode !=3D EXCEPTION_DEBUG_EVENT)=0A= {=0A= DEBUG_EXCEPT(("Cannot continue with signal %d here.\n",sig));=0A= }=0A= else if (sig =3D=3D last_sig)=0A= continue_status =3D DBG_EXCEPTION_NOT_HANDLED;=0A= else=0A= #if 0=0A= /* This code does not seem to work, because=0A= the kernel does probably not consider changes in the ExceptionRecord=0A= structure when passing the exception to the inferior.=0A= Note that this seems possible in the exception handler itself. */=0A= {=0A= int i;=0A= for (i =3D 0; xlate[i].them !=3D -1; i++)=0A= if (xlate[i].us =3D=3D sig)=0A= {=0A= current_event.u.Exception.ExceptionRecord.ExceptionCode =3D=0A= xlate[i].them;=0A= continue_status =3D DBG_EXCEPTION_NOT_HANDLED;=0A= break;=0A= }=0A= if (continue_status =3D=3D DBG_CONTINUE)=0A= {=0A= DEBUG_EXCEPT(("Cannot continue with signal %d.\n",sig));=0A= }=0A= }=0A= #endif=0A= DEBUG_EXCEPT(("Can only continue with recieved signal %d.\n",=0A= last_sig));=0A= }=0A= =0A= last_sig =3D TARGET_SIGNAL_0;=0A= =0A= DEBUG_EXEC (("gdb: child_resume (pid=3D%d, step=3D%d, sig=3D%d);\n",=0A= pid, step, sig));=0A= =0A= /* Get context for currently selected thread */=0A= th =3D thread_rec (current_event.dwThreadId, FALSE);=0A= if (th)=0A= {=0A= if (step)=0A= {=0A= /* Single step by setting t bit */=0A= child_fetch_inferior_registers (PS_REGNUM);=0A= th->context.EFlags |=3D FLAG_TRACE_BIT;=0A= }=0A= =0A= if (th->context.ContextFlags)=0A= {=0A= if (debug_registers_changed)=0A= {=0A= th->context.Dr0 =3D dr[0];=0A= th->context.Dr1 =3D dr[1];=0A= th->context.Dr2 =3D dr[2];=0A= th->context.Dr3 =3D dr[3];=0A= /* th->context.Dr6 =3D dr[6];=0A= FIXME: should we set dr6 also ?? */=0A= th->context.Dr7 =3D dr[7];=0A= }=0A= CHECK (SetThreadContext (th->h, &th->context));=0A= th->context.ContextFlags =3D 0;=0A= }=0A= }=0A= =0A= /* Allow continuing with the same signal that interrupted us.=0A= Otherwise complain. */=0A= =0A= child_continue (continue_status, pid);=0A= }=0A= =0A= static void=0A= child_prepare_to_store (void)=0A= {=0A= /* Do nothing, since we can store individual regs */=0A= }=0A= =0A= static int=0A= child_can_run (void)=0A= {=0A= return 1;=0A= }=0A= =0A= static void=0A= child_close (int x)=0A= {=0A= DEBUG_EVENTS (("gdb: child_close, inferior_ptid=3D%d\n",=0A= PIDGET (inferior_ptid)));=0A= }=0A= =0A= struct target_ops child_ops;=0A= =0A= static void=0A= init_child_ops (void)=0A= {=0A= child_ops.to_shortname =3D "child";=0A= child_ops.to_longname =3D "Win32 child process";=0A= child_ops.to_doc =3D "Win32 child process (started by the \"run\" command= ).";=0A= child_ops.to_open =3D child_open;=0A= child_ops.to_close =3D child_close;=0A= child_ops.to_attach =3D child_attach;=0A= child_ops.to_detach =3D child_detach;=0A= child_ops.to_resume =3D child_resume;=0A= child_ops.to_wait =3D child_wait;=0A= child_ops.to_fetch_registers =3D child_fetch_inferior_registers;=0A= child_ops.to_store_registers =3D child_store_inferior_registers;=0A= child_ops.to_prepare_to_store =3D child_prepare_to_store;=0A= child_ops.to_xfer_memory =3D child_xfer_memory;=0A= child_ops.to_files_info =3D child_files_info;=0A= child_ops.to_insert_breakpoint =3D memory_insert_breakpoint;=0A= child_ops.to_remove_breakpoint =3D memory_remove_breakpoint;=0A= child_ops.to_terminal_init =3D terminal_init_inferior;=0A= child_ops.to_terminal_inferior =3D terminal_inferior;=0A= child_ops.to_terminal_ours_for_output =3D terminal_ours_for_output;=0A= child_ops.to_terminal_ours =3D terminal_ours;=0A= child_ops.to_terminal_info =3D child_terminal_info;=0A= child_ops.to_kill =3D child_kill_inferior;=0A= child_ops.to_load =3D 0;=0A= child_ops.to_lookup_symbol =3D 0;=0A= child_ops.to_create_inferior =3D child_create_inferior;=0A= child_ops.to_mourn_inferior =3D child_mourn_inferior;=0A= child_ops.to_can_run =3D child_can_run;=0A= child_ops.to_notice_signals =3D 0;=0A= child_ops.to_thread_alive =3D win32_child_thread_alive;=0A= child_ops.to_pid_to_str =3D cygwin_pid_to_str;=0A= child_ops.to_stop =3D child_stop;=0A= child_ops.to_stratum =3D process_stratum;=0A= child_ops.DONT_USE =3D 0;=0A= child_ops.to_has_all_memory =3D 1;=0A= child_ops.to_has_memory =3D 1;=0A= child_ops.to_has_stack =3D 1;=0A= child_ops.to_has_registers =3D 1;=0A= child_ops.to_has_execution =3D 1;=0A= child_ops.to_sections =3D 0;=0A= child_ops.to_sections_end =3D 0;=0A= child_ops.to_magic =3D OPS_MAGIC;=0A= }=0A= =0A= void=0A= _initialize_inftarg (void)=0A= {=0A= struct cmd_list_element *c;=0A= =0A= init_child_ops ();=0A= =0A= c =3D add_com ("dll-symbols", class_files, dll_symbol_command,=0A= "Load dll library symbols from FILE.");=0A= c->completer =3D filename_completer;=0A= =0A= add_com_alias ("sharedlibrary", "dll-symbols", class_alias, 1);=0A= =0A= add_show_from_set (add_set_cmd ("shell", class_support, var_boolean,=0A= (char *) &useshell,=0A= "Set use of shell to start subprocess.",=0A= &setlist),=0A= &showlist);=0A= =0A= add_show_from_set (add_set_cmd ("new-console", class_support, var_boolean= ,=0A= (char *) &new_console,=0A= "Set creation of new console when creating child process.",=0A= &setlist),=0A= &showlist);=0A= =0A= add_show_from_set (add_set_cmd ("new-group", class_support, var_boolean,= =0A= (char *) &new_group,=0A= "Set creation of new group when creating child process.",=0A= &setlist),=0A= &showlist);=0A= =0A= add_show_from_set (add_set_cmd ("debugexec", class_support, var_boolean,= =0A= (char *) &debug_exec,=0A= "Set whether to display execution in child process.",=0A= &setlist),=0A= &showlist);=0A= =0A= add_show_from_set (add_set_cmd ("debugevents", class_support, var_boolean= ,=0A= (char *) &debug_events,=0A= "Set whether to display kernel events in child process.",=0A= &setlist),=0A= &showlist);=0A= =0A= add_show_from_set (add_set_cmd ("debugmemory", class_support, var_boolean= ,=0A= (char *) &debug_memory,=0A= "Set whether to display memory accesses in child process.",=0A= &setlist),=0A= &showlist);=0A= =0A= add_show_from_set (add_set_cmd ("debugexceptions", class_support, var_boo= lean,=0A= (char *) &debug_exceptions,=0A= "Set whether to display kernel exceptions in child process.",=0A= &setlist),=0A= &showlist);=0A= =0A= add_info ("dll", info_dll_command, "Status of loaded DLLs.");=0A= add_info_alias ("sharedlibrary", "dll", 1);=0A= =0A= add_prefix_cmd ("w32", class_info, info_w32_command,=0A= "Print information specific to Win32 debugging.",=0A= &info_w32_cmdlist, "info w32 ", 0, &infolist);=0A= =0A= add_cmd ("selector", class_info, display_selectors,=0A= "Display selectors infos.",=0A= &info_w32_cmdlist);=0A= =0A= add_target (&child_ops);=0A= }=0A= =0A= /* Hardware watchpoint support, adapted from go32-nat.c code. */=0A= =0A= /* Pass the address ADDR to the inferior in the I'th debug register.=0A= Here we just store the address in dr array, the registers will be=0A= actually set up when child_continue is called. */=0A= void=0A= cygwin_set_dr (int i, CORE_ADDR addr)=0A= {=0A= if (i < 0 || i > 3)=0A= internal_error (__FILE__, __LINE__,=0A= "Invalid register %d in cygwin_set_dr.\n", i);=0A= dr[i] =3D (unsigned) addr;=0A= debug_registers_changed =3D 1;=0A= debug_registers_used =3D 1;=0A= }=0A= =0A= /* Pass the value VAL to the inferior in the DR7 debug control=0A= register. Here we just store the address in D_REGS, the watchpoint=0A= will be actually set up in child_wait. */=0A= void=0A= cygwin_set_dr7 (unsigned val)=0A= {=0A= dr[7] =3D val;=0A= debug_registers_changed =3D 1;=0A= debug_registers_used =3D 1;=0A= }=0A= =0A= /* Get the value of the DR6 debug status register from the inferior.=0A= Here we just return the value stored in dr[6]=0A= by the last call to thread_rec for current_event.dwThreadId id. */=0A= unsigned=0A= cygwin_get_dr6 (void)=0A= {=0A= return dr[6];=0A= }=0A= =0A= =0A= /* Determine if the thread referenced by "pid" is alive=0A= by "polling" it. If WaitForSingleObject returns WAIT_OBJECT_0=0A= it means that the pid has died. Otherwise it is assumed to be alive. */= =0A= static int=0A= win32_child_thread_alive (ptid_t ptid)=0A= {=0A= int pid =3D PIDGET (ptid);=0A= =0A= return WaitForSingleObject (thread_rec (pid, FALSE)->h, 0) =3D=3D WAIT_OB= JECT_0 ?=0A= FALSE : TRUE;=0A= }=0A= =0A= /* Convert pid to printable format. */=0A= char *=0A= cygwin_pid_to_str (ptid_t ptid)=0A= {=0A= static char buf[80];=0A= int pid =3D PIDGET (ptid);=0A= =0A= if ((DWORD) pid =3D=3D current_event.dwProcessId)=0A= sprintf (buf, "process %d", pid);=0A= else=0A= sprintf (buf, "thread %ld.0x%x", current_event.dwProcessId, pid);=0A= return buf;=0A= }=0A= =0A= static int=0A= core_dll_symbols_add (char *dll_name, DWORD base_addr)=0A= {=0A= struct objfile *objfile;=0A= char *objfile_basename;=0A= const char *dll_basename;=0A= =0A= if (!(dll_basename =3D strrchr (dll_name, '/')))=0A= dll_basename =3D dll_name;=0A= else=0A= dll_basename++;=0A= =0A= ALL_OBJFILES (objfile)=0A= {=0A= objfile_basename =3D strrchr (objfile->name, '/');=0A= =0A= if (objfile_basename &&=0A= strcmp (dll_basename, objfile_basename + 1) =3D=3D 0)=0A= {=0A= printf_unfiltered ("%08lx:%s (symbols previously loaded)\n",=0A= base_addr, dll_name);=0A= goto out;=0A= }=0A= }=0A= =0A= register_loaded_dll (dll_name, base_addr + 0x1000);=0A= solib_symbols_add (dll_name, 0, (CORE_ADDR) base_addr + 0x1000);=0A= =0A= out:=0A= return 1;=0A= }=0A= =0A= typedef struct=0A= {=0A= struct target_ops *target;=0A= bfd_vma addr;=0A= }=0A= map_code_section_args;=0A= =0A= static void=0A= map_single_dll_code_section (bfd * abfd, asection * sect, void *obj)=0A= {=0A= int old;=0A= int update_coreops;=0A= struct section_table *new_target_sect_ptr;=0A= =0A= map_code_section_args *args =3D (map_code_section_args *) obj;=0A= struct target_ops *target =3D args->target;=0A= if (sect->flags & SEC_CODE)=0A= {=0A= update_coreops =3D core_ops.to_sections =3D=3D target->to_sections;= =0A= =0A= if (target->to_sections)=0A= {=0A= old =3D target->to_sections_end - target->to_sections;=0A= target->to_sections =3D (struct section_table *)=0A= xrealloc ((char *) target->to_sections,=0A= (sizeof (struct section_table)) * (1 + old));=0A= }=0A= else=0A= {=0A= old =3D 0;=0A= target->to_sections =3D (struct section_table *)=0A= xmalloc ((sizeof (struct section_table)));=0A= }=0A= target->to_sections_end =3D target->to_sections + (1 + old);=0A= =0A= /* Update the to_sections field in the core_ops structure=0A= if needed. */=0A= if (update_coreops)=0A= {=0A= core_ops.to_sections =3D target->to_sections;=0A= core_ops.to_sections_end =3D target->to_sections_end;=0A= }=0A= new_target_sect_ptr =3D target->to_sections + old;=0A= new_target_sect_ptr->addr =3D args->addr + bfd_section_vma (abfd, sec= t);=0A= new_target_sect_ptr->endaddr =3D args->addr + bfd_section_vma (abfd, = sect) +=0A= bfd_section_size (abfd, sect);;=0A= new_target_sect_ptr->the_bfd_section =3D sect;=0A= new_target_sect_ptr->bfd =3D abfd;=0A= }=0A= }=0A= =0A= static int=0A= dll_code_sections_add (const char *dll_name, int base_addr, struct target_o= ps *target)=0A= {=0A= bfd *dll_bfd;=0A= map_code_section_args map_args;=0A= asection *lowest_sect;=0A= char *name;=0A= if (dll_name =3D=3D NULL || target =3D=3D NULL)=0A= return 0;=0A= name =3D xstrdup (dll_name);=0A= dll_bfd =3D bfd_openr (name, "pei-i386");=0A= if (dll_bfd =3D=3D NULL)=0A= return 0;=0A= =0A= if (bfd_check_format (dll_bfd, bfd_object))=0A= {=0A= lowest_sect =3D bfd_get_section_by_name (dll_bfd, ".text");=0A= if (lowest_sect =3D=3D NULL)=0A= return 0;=0A= map_args.target =3D target;=0A= map_args.addr =3D base_addr - bfd_section_vma (dll_bfd, lowest_sect);= =0A= =0A= bfd_map_over_sections (dll_bfd, &map_single_dll_code_section, (void *= ) (&map_args));=0A= }=0A= =0A= return 1;=0A= }=0A= =0A= static void=0A= core_section_load_dll_symbols (bfd * abfd, asection * sect, void *obj)=0A= {=0A= struct target_ops *target =3D (struct target_ops *) obj;=0A= =0A= DWORD base_addr;=0A= =0A= int dll_name_size;=0A= char *dll_name =3D NULL;=0A= char *buf =3D NULL;=0A= struct win32_pstatus *pstatus;=0A= char *p;=0A= =0A= if (strncmp (sect->name, ".module", 7))=0A= return;=0A= =0A= buf =3D (char *) xmalloc (sect->_raw_size + 1);=0A= if (!buf)=0A= {=0A= printf_unfiltered ("memory allocation failed for %s\n", sect->name);= =0A= goto out;=0A= }=0A= if (!bfd_get_section_contents (abfd, sect, buf, 0, sect->_raw_size))=0A= goto out;=0A= =0A= pstatus =3D (struct win32_pstatus *) buf;=0A= =0A= memmove (&base_addr, &(pstatus->data.module_info.base_address), sizeof (b= ase_addr));=0A= dll_name_size =3D pstatus->data.module_info.module_name_size;=0A= if (offsetof (struct win32_pstatus, data.module_info.module_name) + dll_n= ame_size > sect->_raw_size)=0A= goto out;=0A= =0A= dll_name =3D (char *) xmalloc (dll_name_size + 1);=0A= if (!dll_name)=0A= {=0A= printf_unfiltered ("memory allocation failed for %s\n", sect->name);= =0A= goto out;=0A= }=0A= strncpy (dll_name, pstatus->data.module_info.module_name, dll_name_size);= =0A= =0A= while ((p =3D strchr (dll_name, '\\')))=0A= *p =3D '/';=0A= =0A= if (!core_dll_symbols_add (dll_name, (DWORD) base_addr))=0A= printf_unfiltered ("%s: Failed to load dll symbols.\n", dll_name);=0A= =0A= if (!dll_code_sections_add (dll_name, (DWORD) base_addr + 0x1000, target)= )=0A= printf_unfiltered ("%s: Failed to map dll code sections.\n", dll_name);= =0A= =0A= out:=0A= if (buf)=0A= xfree (buf);=0A= if (dll_name)=0A= xfree (dll_name);=0A= return;=0A= }=0A= =0A= void=0A= child_solib_add (char *filename, int from_tty, struct target_ops *target,= =0A= int readsyms)=0A= {=0A= if (!readsyms)=0A= return;=0A= if (core_bfd)=0A= {=0A= child_clear_solibs ();=0A= bfd_map_over_sections (core_bfd, &core_section_load_dll_symbols, targ= et);=0A= }=0A= else=0A= {=0A= if (solib_end && solib_end->name)=0A= solib_end->objfile =3D solib_symbols_add (solib_end->name, from_tty,= =0A= solib_end->load_addr);=0A= }=0A= }=0A= =0A= static void=0A= fetch_elf_core_registers (char *core_reg_sect,=0A= unsigned core_reg_size,=0A= int which,=0A= CORE_ADDR reg_addr)=0A= {=0A= int r;=0A= if (core_reg_size < sizeof (CONTEXT))=0A= {=0A= error ("Core file register section too small (%u bytes).", core_reg_s= ize);=0A= return;=0A= }=0A= for (r =3D 0; r < NUM_REGS; r++)=0A= supply_register (r, core_reg_sect + mappings[r]);=0A= }=0A= =0A= static struct core_fns win32_elf_core_fns =3D=0A= {=0A= bfd_target_elf_flavour,=0A= default_check_format,=0A= default_core_sniffer,=0A= fetch_elf_core_registers,=0A= NULL=0A= };=0A= =0A= void=0A= _initialize_core_win32 (void)=0A= {=0A= add_core_fns (&win32_elf_core_fns);=0A= }=0A= =0A= void=0A= _initialize_check_for_gdb_ini (void)=0A= {=0A= char *homedir;=0A= if (inhibit_gdbinit)=0A= return;=0A= =0A= homedir =3D getenv ("HOME");=0A= if (homedir)=0A= {=0A= char *p;=0A= char *oldini =3D (char *) alloca (strlen (homedir) +=0A= sizeof ("/gdb.ini"));=0A= strcpy (oldini, homedir);=0A= p =3D strchr (oldini, '\0');=0A= if (p > oldini && p[-1] !=3D '/')=0A= *p++ =3D '/';=0A= strcpy (p, "gdb.ini");=0A= if (access (oldini, 0) =3D=3D 0)=0A= {=0A= int len =3D strlen (oldini);=0A= char *newini =3D alloca (len + 1);=0A= sprintf (newini, "%.*s.gdbinit",=0A= (int) (len - (sizeof ("gdb.ini") - 1)), oldini);=0A= warning ("obsolete '%s' found. Rename to '%s'.", oldini, newini);=0A= }=0A= }=0A= }=0A= ------=_NextPart_000_000A_01C25F52.765BCD40--