1 /* Target-vector operations for controlling win32 child processes, for GDB.
3 Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
4 2005, 2006, 2007 Free Software Foundation, Inc.
6 Contributed by Cygnus Solutions, A Red Hat Company.
8 This file is part of GDB.
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 3 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program. If not, see <http://www.gnu.org/licenses/>. */
23 /* Originally by Steve Chamberlain, sac@cygnus.com */
25 /* We assume we're being built with and will be used for cygwin. */
28 #include "frame.h" /* required by inferior.h */
31 #include "exceptions.h"
34 #include "completer.h"
38 #include <sys/types.h>
43 #include <sys/cygwin.h>
49 #include "gdb_string.h"
50 #include "gdbthread.h"
52 #include <sys/param.h>
58 #include "i386-tdep.h"
59 #include "i387-tdep.h"
61 static struct target_ops win32_ops
;
62 static struct target_so_ops win32_so_ops
;
64 /* The starting and ending address of the cygwin1.dll text segment. */
65 static bfd_vma cygwin_load_start
;
66 static bfd_vma cygwin_load_end
;
68 static int have_saved_context
; /* True if we've saved context from a cygwin signal. */
69 static CONTEXT saved_context
; /* Containes the saved context from a cygwin signal. */
71 /* If we're not using the old Cygwin header file set, define the
72 following which never should have been in the generic Win32 API
73 headers in the first place since they were our own invention... */
74 #ifndef _GNU_H_WINDOWS_H
77 FLAG_TRACE_BIT
= 0x100,
78 CONTEXT_DEBUGGER
= (CONTEXT_FULL
| CONTEXT_FLOATING_POINT
)
81 #include <sys/procfs.h>
84 #define CONTEXT_DEBUGGER_DR CONTEXT_DEBUGGER | CONTEXT_DEBUG_REGISTERS \
85 | CONTEXT_EXTENDED_REGISTERS
87 static unsigned dr
[8];
88 static int debug_registers_changed
;
89 static int debug_registers_used
;
91 /* The string sent by cygwin when it processes a signal.
92 FIXME: This should be in a cygwin include file. */
93 #ifndef _CYGWIN_SIGNAL_STRING
94 #define _CYGWIN_SIGNAL_STRING "cYgSiGw00f"
97 #define CHECK(x) check (x, __FILE__,__LINE__)
98 #define DEBUG_EXEC(x) if (debug_exec) printf_unfiltered x
99 #define DEBUG_EVENTS(x) if (debug_events) printf_unfiltered x
100 #define DEBUG_MEM(x) if (debug_memory) printf_unfiltered x
101 #define DEBUG_EXCEPT(x) if (debug_exceptions) printf_unfiltered x
103 static void win32_stop (void);
104 static int win32_win32_thread_alive (ptid_t
);
105 static void win32_kill_inferior (void);
107 static enum target_signal last_sig
= TARGET_SIGNAL_0
;
108 /* Set if a signal was received from the debugged process */
110 /* Thread information structure used to track information that is
111 not available in gdb's thread structure. */
112 typedef struct thread_info_struct
114 struct thread_info_struct
*next
;
125 static thread_info thread_head
;
127 /* The process and thread handles for the above context. */
129 static DEBUG_EVENT current_event
; /* The current debug event from
131 static HANDLE current_process_handle
; /* Currently executing process */
132 static thread_info
*current_thread
; /* Info on currently selected thread */
133 static DWORD main_thread_id
; /* Thread ID of the main thread */
135 /* Counts of things. */
136 static int exception_count
= 0;
137 static int event_count
= 0;
138 static int saw_create
;
141 static int new_console
= 0;
142 static int cygwin_exceptions
= 0;
143 static int new_group
= 1;
144 static int debug_exec
= 0; /* show execution */
145 static int debug_events
= 0; /* show events from kernel */
146 static int debug_memory
= 0; /* show target memory accesses */
147 static int debug_exceptions
= 0; /* show target exceptions */
148 static int useshell
= 0; /* use shell for subprocesses */
150 /* This vector maps GDB's idea of a register's number into an address
151 in the win32 exception context vector.
153 It also contains the bit mask needed to load the register in question.
155 One day we could read a reg, we could inspect the context we
156 already have loaded, if it doesn't have the bit set that we need,
157 we read that set of registers in using GetThreadContext. If the
158 context already contains what we need, we just unpack it. Then to
159 write a register, first we have to ensure that the context contains
160 the other regs of the group, and then we copy the info in and set
163 #define context_offset(x) ((int)&(((CONTEXT *)NULL)->x))
164 static const int mappings
[] =
166 context_offset (Eax
),
167 context_offset (Ecx
),
168 context_offset (Edx
),
169 context_offset (Ebx
),
170 context_offset (Esp
),
171 context_offset (Ebp
),
172 context_offset (Esi
),
173 context_offset (Edi
),
174 context_offset (Eip
),
175 context_offset (EFlags
),
176 context_offset (SegCs
),
177 context_offset (SegSs
),
178 context_offset (SegDs
),
179 context_offset (SegEs
),
180 context_offset (SegFs
),
181 context_offset (SegGs
),
182 context_offset (FloatSave
.RegisterArea
[0 * 10]),
183 context_offset (FloatSave
.RegisterArea
[1 * 10]),
184 context_offset (FloatSave
.RegisterArea
[2 * 10]),
185 context_offset (FloatSave
.RegisterArea
[3 * 10]),
186 context_offset (FloatSave
.RegisterArea
[4 * 10]),
187 context_offset (FloatSave
.RegisterArea
[5 * 10]),
188 context_offset (FloatSave
.RegisterArea
[6 * 10]),
189 context_offset (FloatSave
.RegisterArea
[7 * 10]),
190 context_offset (FloatSave
.ControlWord
),
191 context_offset (FloatSave
.StatusWord
),
192 context_offset (FloatSave
.TagWord
),
193 context_offset (FloatSave
.ErrorSelector
),
194 context_offset (FloatSave
.ErrorOffset
),
195 context_offset (FloatSave
.DataSelector
),
196 context_offset (FloatSave
.DataOffset
),
197 context_offset (FloatSave
.ErrorSelector
)
199 context_offset (ExtendedRegisters
[10*16]),
200 context_offset (ExtendedRegisters
[11*16]),
201 context_offset (ExtendedRegisters
[12*16]),
202 context_offset (ExtendedRegisters
[13*16]),
203 context_offset (ExtendedRegisters
[14*16]),
204 context_offset (ExtendedRegisters
[15*16]),
205 context_offset (ExtendedRegisters
[16*16]),
206 context_offset (ExtendedRegisters
[17*16]),
208 context_offset (ExtendedRegisters
[24])
211 #undef context_offset
213 /* This vector maps the target's idea of an exception (extracted
214 from the DEBUG_EVENT structure) to GDB's idea. */
216 struct xlate_exception
219 enum target_signal us
;
222 static const struct xlate_exception
225 {EXCEPTION_ACCESS_VIOLATION
, TARGET_SIGNAL_SEGV
},
226 {STATUS_STACK_OVERFLOW
, TARGET_SIGNAL_SEGV
},
227 {EXCEPTION_BREAKPOINT
, TARGET_SIGNAL_TRAP
},
228 {DBG_CONTROL_C
, TARGET_SIGNAL_INT
},
229 {EXCEPTION_SINGLE_STEP
, TARGET_SIGNAL_TRAP
},
230 {STATUS_FLOAT_DIVIDE_BY_ZERO
, TARGET_SIGNAL_FPE
},
234 check (BOOL ok
, const char *file
, int line
)
237 printf_filtered ("error return %s:%d was %lu\n", file
, line
,
241 /* Find a thread record given a thread id.
242 If get_context then also retrieve the context for this
245 thread_rec (DWORD id
, int get_context
)
249 for (th
= &thread_head
; (th
= th
->next
) != NULL
;)
252 if (!th
->suspend_count
&& get_context
)
254 if (get_context
> 0 && id
!= current_event
.dwThreadId
)
255 th
->suspend_count
= SuspendThread (th
->h
) + 1;
256 else if (get_context
< 0)
257 th
->suspend_count
= -1;
258 th
->reload_context
= 1;
266 /* Add a thread to the thread list */
268 win32_add_thread (DWORD id
, HANDLE h
)
272 if ((th
= thread_rec (id
, FALSE
)))
275 th
= XZALLOC (thread_info
);
278 th
->next
= thread_head
.next
;
279 thread_head
.next
= th
;
280 add_thread (pid_to_ptid (id
));
281 /* Set the debug registers for the new thread in they are used. */
282 if (debug_registers_used
)
284 /* Only change the value of the debug registers. */
285 th
->context
.ContextFlags
= CONTEXT_DEBUG_REGISTERS
;
286 CHECK (GetThreadContext (th
->h
, &th
->context
));
287 th
->context
.Dr0
= dr
[0];
288 th
->context
.Dr1
= dr
[1];
289 th
->context
.Dr2
= dr
[2];
290 th
->context
.Dr3
= dr
[3];
291 /* th->context.Dr6 = dr[6];
292 FIXME: should we set dr6 also ?? */
293 th
->context
.Dr7
= dr
[7];
294 CHECK (SetThreadContext (th
->h
, &th
->context
));
295 th
->context
.ContextFlags
= 0;
300 /* Clear out any old thread list and reintialize it to a
303 win32_init_thread_list (void)
305 thread_info
*th
= &thread_head
;
307 DEBUG_EVENTS (("gdb: win32_init_thread_list\n"));
309 while (th
->next
!= NULL
)
311 thread_info
*here
= th
->next
;
312 th
->next
= here
->next
;
313 (void) CloseHandle (here
->h
);
316 thread_head
.next
= NULL
;
319 /* Delete a thread from the list of threads */
321 win32_delete_thread (DWORD id
)
326 printf_unfiltered ("[Deleting %s]\n", target_pid_to_str (pid_to_ptid (id
)));
327 delete_thread (pid_to_ptid (id
));
329 for (th
= &thread_head
;
330 th
->next
!= NULL
&& th
->next
->id
!= id
;
334 if (th
->next
!= NULL
)
336 thread_info
*here
= th
->next
;
337 th
->next
= here
->next
;
338 CloseHandle (here
->h
);
344 do_win32_fetch_inferior_registers (struct regcache
*regcache
, int r
)
346 char *context_offset
= ((char *) ¤t_thread
->context
) + mappings
[r
];
350 return; /* Windows sometimes uses a non-existent thread id in its
353 if (current_thread
->reload_context
)
355 #ifdef __COPY_CONTEXT_SIZE
356 if (have_saved_context
)
358 /* Lie about where the program actually is stopped since cygwin has informed us that
359 we should consider the signal to have occurred at another location which is stored
360 in "saved_context. */
361 memcpy (¤t_thread
->context
, &saved_context
, __COPY_CONTEXT_SIZE
);
362 have_saved_context
= 0;
367 thread_info
*th
= current_thread
;
368 th
->context
.ContextFlags
= CONTEXT_DEBUGGER_DR
;
369 GetThreadContext (th
->h
, &th
->context
);
370 /* Copy dr values from that thread. */
371 dr
[0] = th
->context
.Dr0
;
372 dr
[1] = th
->context
.Dr1
;
373 dr
[2] = th
->context
.Dr2
;
374 dr
[3] = th
->context
.Dr3
;
375 dr
[6] = th
->context
.Dr6
;
376 dr
[7] = th
->context
.Dr7
;
378 current_thread
->reload_context
= 0;
381 #define I387_ST0_REGNUM I386_ST0_REGNUM
383 if (r
== I387_FISEG_REGNUM
)
385 l
= *((long *) context_offset
) & 0xffff;
386 regcache_raw_supply (regcache
, r
, (char *) &l
);
388 else if (r
== I387_FOP_REGNUM
)
390 l
= (*((long *) context_offset
) >> 16) & ((1 << 11) - 1);
391 regcache_raw_supply (regcache
, r
, (char *) &l
);
394 regcache_raw_supply (regcache
, r
, context_offset
);
397 for (r
= 0; r
< gdbarch_num_regs (current_gdbarch
); r
++)
398 do_win32_fetch_inferior_registers (regcache
, r
);
401 #undef I387_ST0_REGNUM
405 win32_fetch_inferior_registers (struct regcache
*regcache
, int r
)
407 current_thread
= thread_rec (PIDGET (inferior_ptid
), TRUE
);
408 /* Check if current_thread exists. Windows sometimes uses a non-existent
409 thread id in its events */
411 do_win32_fetch_inferior_registers (regcache
, r
);
415 do_win32_store_inferior_registers (const struct regcache
*regcache
, int r
)
418 /* Windows sometimes uses a non-existent thread id in its events */;
420 regcache_raw_collect (regcache
, r
,
421 ((char *) ¤t_thread
->context
) + mappings
[r
]);
424 for (r
= 0; r
< gdbarch_num_regs (current_gdbarch
); r
++)
425 do_win32_store_inferior_registers (regcache
, r
);
429 /* Store a new register value into the current thread context */
431 win32_store_inferior_registers (struct regcache
*regcache
, int r
)
433 current_thread
= thread_rec (PIDGET (inferior_ptid
), TRUE
);
434 /* Check if current_thread exists. Windows sometimes uses a non-existent
435 thread id in its events */
437 do_win32_store_inferior_registers (regcache
, r
);
440 static int psapi_loaded
= 0;
441 static HMODULE psapi_module_handle
= NULL
;
442 static BOOL
WINAPI (*psapi_EnumProcessModules
) (HANDLE
, HMODULE
*, DWORD
, LPDWORD
) = NULL
;
443 static BOOL
WINAPI (*psapi_GetModuleInformation
) (HANDLE
, HMODULE
, LPMODULEINFO
, DWORD
) = NULL
;
444 static DWORD
WINAPI (*psapi_GetModuleFileNameExA
) (HANDLE
, HMODULE
, LPSTR
, DWORD
) = NULL
;
447 psapi_get_dll_name (DWORD BaseAddress
, char *dll_name_ret
)
453 HMODULE
*DllHandle
= dh_buf
;
458 psapi_EnumProcessModules
== NULL
||
459 psapi_GetModuleInformation
== NULL
||
460 psapi_GetModuleFileNameExA
== NULL
)
465 psapi_module_handle
= LoadLibrary ("psapi.dll");
466 if (!psapi_module_handle
)
468 /* printf_unfiltered ("error loading psapi.dll: %u", GetLastError ()); */
471 psapi_EnumProcessModules
= GetProcAddress (psapi_module_handle
, "EnumProcessModules");
472 psapi_GetModuleInformation
= GetProcAddress (psapi_module_handle
, "GetModuleInformation");
473 psapi_GetModuleFileNameExA
= (void *) GetProcAddress (psapi_module_handle
,
474 "GetModuleFileNameExA");
475 if (psapi_EnumProcessModules
== NULL
||
476 psapi_GetModuleInformation
== NULL
||
477 psapi_GetModuleFileNameExA
== NULL
)
482 ok
= (*psapi_EnumProcessModules
) (current_process_handle
,
487 if (!ok
|| !cbNeeded
)
490 DllHandle
= (HMODULE
*) alloca (cbNeeded
);
494 ok
= (*psapi_EnumProcessModules
) (current_process_handle
,
501 for (i
= 0; i
< (int) (cbNeeded
/ sizeof (HMODULE
)); i
++)
503 if (!(*psapi_GetModuleInformation
) (current_process_handle
,
507 error (_("Can't get module info"));
509 len
= (*psapi_GetModuleFileNameExA
) (current_process_handle
,
514 error (_("Error getting dll name: %u."), (unsigned) GetLastError ());
516 if ((DWORD
) (mi
.lpBaseOfDll
) == BaseAddress
)
521 dll_name_ret
[0] = '\0';
525 /* Encapsulate the information required in a call to
526 symbol_file_add_args */
527 struct safe_symbol_file_add_args
531 struct section_addr_info
*addrs
;
534 struct ui_file
*err
, *out
;
538 /* Maintain a linked list of "so" information. */
544 static struct so_list solib_start
, *solib_end
;
546 /* Call symbol_file_add with stderr redirected. We don't care if there
549 safe_symbol_file_add_stub (void *argv
)
551 #define p ((struct safe_symbol_file_add_args *) argv)
552 struct so_list
*so
= &solib_start
;
554 p
->ret
= symbol_file_add (p
->name
, p
->from_tty
, p
->addrs
, p
->mainline
, p
->flags
);
559 /* Restore gdb's stderr after calling symbol_file_add */
561 safe_symbol_file_add_cleanup (void *p
)
563 #define sp ((struct safe_symbol_file_add_args *)p)
564 gdb_flush (gdb_stderr
);
565 gdb_flush (gdb_stdout
);
566 ui_file_delete (gdb_stderr
);
567 ui_file_delete (gdb_stdout
);
568 gdb_stderr
= sp
->err
;
569 gdb_stdout
= sp
->out
;
573 /* symbol_file_add wrapper that prevents errors from being displayed. */
574 static struct objfile
*
575 safe_symbol_file_add (char *name
, int from_tty
,
576 struct section_addr_info
*addrs
,
577 int mainline
, int flags
)
579 struct safe_symbol_file_add_args p
;
580 struct cleanup
*cleanup
;
582 cleanup
= make_cleanup (safe_symbol_file_add_cleanup
, &p
);
586 gdb_flush (gdb_stderr
);
587 gdb_flush (gdb_stdout
);
588 gdb_stderr
= ui_file_new ();
589 gdb_stdout
= ui_file_new ();
591 p
.from_tty
= from_tty
;
593 p
.mainline
= mainline
;
595 catch_errors (safe_symbol_file_add_stub
, &p
, "", RETURN_MASK_ERROR
);
597 do_cleanups (cleanup
);
601 /* Get the loaded address of all sections, given that .text was loaded
602 at text_load. Assumes that all sections are subject to the same
603 relocation offset. Returns NULL if problems occur or if the
604 sections were not relocated. */
606 static struct section_addr_info
*
607 get_relocated_section_addrs (bfd
*abfd
, CORE_ADDR text_load
)
609 struct section_addr_info
*result
= NULL
;
610 int section_count
= bfd_count_sections (abfd
);
611 asection
*text_section
= bfd_get_section_by_name (abfd
, ".text");
616 /* Couldn't get the .text section. Weird. */
618 else if (text_load
== (text_vma
= bfd_get_section_vma (abfd
, text_section
)))
620 /* DLL wasn't relocated. */
624 /* Figure out all sections' loaded addresses. The offset here is
625 such that taking a bfd_get_section_vma() result and adding
626 offset will give the real load address of the section. */
628 CORE_ADDR offset
= text_load
- text_vma
;
630 struct section_table
*table_start
= NULL
;
631 struct section_table
*table_end
= NULL
;
632 struct section_table
*iter
= NULL
;
634 build_section_table (abfd
, &table_start
, &table_end
);
636 for (iter
= table_start
; iter
< table_end
; ++iter
)
638 /* Relocated addresses. */
639 iter
->addr
+= offset
;
640 iter
->endaddr
+= offset
;
643 result
= build_section_addr_info_from_section_table (table_start
,
652 /* Add DLL symbol information. */
654 solib_symbols_add (struct so_list
*so
, CORE_ADDR load_addr
)
656 struct section_addr_info
*addrs
= NULL
;
657 static struct objfile
*result
= NULL
;
658 char *name
= so
->so_name
;
662 /* The symbols in a dll are offset by 0x1000, which is the
663 the offset from 0 of the first byte in an image - because
664 of the file header and the section alignment. */
666 if (!name
|| !name
[0])
669 abfd
= bfd_openr (name
, "pei-i386");
673 /* pei failed - try pe */
674 abfd
= bfd_openr (name
, "pe-i386");
679 if (bfd_check_format (abfd
, bfd_object
))
680 addrs
= get_relocated_section_addrs (abfd
, load_addr
);
685 result
= safe_symbol_file_add (name
, 0, addrs
, 0, OBJF_SHARED
);
686 free_section_addr_info (addrs
);
690 /* Fallback on handling just the .text section. */
691 struct cleanup
*my_cleanups
;
693 addrs
= alloc_section_addr_info (1);
694 my_cleanups
= make_cleanup (xfree
, addrs
);
695 addrs
->other
[0].name
= ".text";
696 addrs
->other
[0].addr
= load_addr
;
698 result
= safe_symbol_file_add (name
, 0, addrs
, 0, OBJF_SHARED
);
699 do_cleanups (my_cleanups
);
702 p
= strchr (so
->so_name
, '\0') - (sizeof ("/cygwin1.dll") - 1);
703 if (p
>= so
->so_name
&& strcasecmp (p
, "/cygwin1.dll") == 0)
705 asection
*text
= bfd_get_section_by_name (abfd
, ".text");
706 cygwin_load_start
= bfd_section_vma (abfd
, text
);
707 cygwin_load_end
= cygwin_load_start
+ bfd_section_size (abfd
, text
);
712 so
->symbols_loaded
= !!result
;
717 register_loaded_dll (const char *name
, DWORD load_addr
, int readsyms
)
720 char buf
[MAX_PATH
+ 1];
721 char cwd
[MAX_PATH
+ 1];
723 WIN32_FIND_DATA w32_fd
;
724 HANDLE h
= FindFirstFile(name
, &w32_fd
);
725 MEMORY_BASIC_INFORMATION m
;
728 if (h
== INVALID_HANDLE_VALUE
)
734 if (GetCurrentDirectory (MAX_PATH
+ 1, cwd
))
736 p
= strrchr (buf
, '\\');
739 SetCurrentDirectory (buf
);
740 GetFullPathName (w32_fd
.cFileName
, MAX_PATH
, buf
, &p
);
741 SetCurrentDirectory (cwd
);
745 if (strcasecmp (buf
, "ntdll.dll") == 0)
747 GetSystemDirectory (buf
, sizeof (buf
));
748 strcat (buf
, "\\ntdll.dll");
750 so
= XZALLOC (struct so_list
);
751 so
->lm_info
= (struct lm_info
*) xmalloc (sizeof (struct lm_info
));
752 so
->lm_info
->load_addr
= load_addr
;
753 cygwin_conv_to_posix_path (buf
, so
->so_name
);
754 strcpy (so
->so_original_name
, so
->so_name
);
756 solib_end
->next
= so
;
758 len
= strlen (so
->so_name
);
760 solib_symbols_add (so
, (CORE_ADDR
) load_addr
);
766 get_image_name (HANDLE h
, void *address
, int unicode
)
768 static char buf
[(2 * MAX_PATH
) + 1];
769 DWORD size
= unicode
? sizeof (WCHAR
) : sizeof (char);
775 /* Attempt to read the name of the dll that was detected.
776 This is documented to work only when actively debugging
777 a program. It will not work for attached processes. */
781 /* See if we could read the address of a string, and that the
782 address isn't null. */
783 if (!ReadProcessMemory (h
, address
, &address_ptr
, sizeof (address_ptr
), &done
)
784 || done
!= sizeof (address_ptr
) || !address_ptr
)
787 /* Find the length of the string */
788 while (ReadProcessMemory (h
, address_ptr
+ len
++ * size
, &b
, size
, &done
)
789 && (b
[0] != 0 || b
[size
- 1] != 0) && done
== size
)
793 ReadProcessMemory (h
, address_ptr
, buf
, len
, &done
);
796 WCHAR
*unicode_address
= (WCHAR
*) alloca (len
* sizeof (WCHAR
));
797 ReadProcessMemory (h
, address_ptr
, unicode_address
, len
* sizeof (WCHAR
),
800 WideCharToMultiByte (CP_ACP
, 0, unicode_address
, len
, buf
, len
, 0, 0);
806 /* Wait for child to do something. Return pid of child, or -1 in case
807 of error; store status through argument pointer OURSTATUS. */
809 handle_load_dll (void *dummy
)
811 LOAD_DLL_DEBUG_INFO
*event
= ¤t_event
.u
.LoadDll
;
812 char dll_buf
[MAX_PATH
+ 1];
813 char *dll_name
= NULL
;
815 dll_buf
[0] = dll_buf
[sizeof (dll_buf
) - 1] = '\0';
817 if (!psapi_get_dll_name ((DWORD
) (event
->lpBaseOfDll
), dll_buf
))
818 dll_buf
[0] = dll_buf
[sizeof (dll_buf
) - 1] = '\0';
822 if (*dll_name
== '\0')
823 dll_name
= get_image_name (current_process_handle
, event
->lpImageName
, event
->fUnicode
);
827 register_loaded_dll (dll_name
, (DWORD
) event
->lpBaseOfDll
+ 0x1000, auto_solib_add
);
833 win32_free_so (struct so_list
*so
)
840 win32_relocate_section_addresses (struct so_list
*so
,
841 struct section_table
*sec
)
848 win32_solib_create_inferior_hook (void)
850 solib_add (NULL
, 0, NULL
, auto_solib_add
);
855 handle_unload_dll (void *dummy
)
857 DWORD lpBaseOfDll
= (DWORD
) current_event
.u
.UnloadDll
.lpBaseOfDll
+ 0x1000;
860 for (so
= &solib_start
; so
->next
!= NULL
; so
= so
->next
)
861 if (so
->next
->lm_info
->load_addr
== lpBaseOfDll
)
863 struct so_list
*sodel
= so
->next
;
864 so
->next
= sodel
->next
;
868 solib_add (NULL
, 0, NULL
, auto_solib_add
);
872 error (_("Error: dll starting at 0x%lx not found."), (DWORD
) lpBaseOfDll
);
877 /* Clear list of loaded DLLs. */
879 win32_clear_solib (void)
881 solib_start
.next
= NULL
;
882 solib_end
= &solib_start
;
886 win32_special_symbol_handling (void)
891 /* Load DLL symbol info. */
893 dll_symbol_command (char *args
, int from_tty
)
899 error (_("dll-symbols requires a file name"));
902 if (n
> 4 && strcasecmp (args
+ n
- 4, ".dll") != 0)
904 char *newargs
= (char *) alloca (n
+ 4 + 1);
905 strcpy (newargs
, args
);
906 strcat (newargs
, ".dll");
910 safe_symbol_file_add (args
, from_tty
, NULL
, 0, OBJF_SHARED
| OBJF_USERLOADED
);
913 /* Handle DEBUG_STRING output from child process.
914 Cygwin prepends its messages with a "cygwin:". Interpret this as
915 a Cygwin signal. Otherwise just print the string as a warning. */
917 handle_output_debug_string (struct target_waitstatus
*ourstatus
)
922 if (!target_read_string
923 ((CORE_ADDR
) current_event
.u
.DebugString
.lpDebugStringData
, &s
, 1024, 0)
926 else if (strncmp (s
, _CYGWIN_SIGNAL_STRING
, sizeof (_CYGWIN_SIGNAL_STRING
) - 1) != 0)
928 if (strncmp (s
, "cYg", 3) != 0)
931 #ifdef __COPY_CONTEXT_SIZE
934 /* Got a cygwin signal marker. A cygwin signal is followed by the signal number
935 itself and then optionally followed by the thread id and address to saved context
936 within the DLL. If these are supplied, then the given thread is assumed to have
937 issued the signal and the context from the thread is assumed to be stored at the
938 given address in the inferior. Tell gdb to treat this like a real signal. */
940 int sig
= strtol (s
+ sizeof (_CYGWIN_SIGNAL_STRING
) - 1, &p
, 0);
941 int gotasig
= target_signal_from_host (sig
);
942 ourstatus
->value
.sig
= gotasig
;
947 ourstatus
->kind
= TARGET_WAITKIND_STOPPED
;
948 retval
= strtoul (p
, &p
, 0);
950 retval
= main_thread_id
;
951 else if ((x
= (LPCVOID
) strtoul (p
, &p
, 0))
952 && ReadProcessMemory (current_process_handle
, x
,
953 &saved_context
, __COPY_CONTEXT_SIZE
, &n
)
954 && n
== __COPY_CONTEXT_SIZE
)
955 have_saved_context
= 1;
956 current_event
.dwThreadId
= retval
;
967 display_selector (HANDLE thread
, DWORD sel
)
970 if (GetThreadSelectorEntry (thread
, sel
, &info
))
973 printf_filtered ("0x%03lx: ", sel
);
974 if (!info
.HighWord
.Bits
.Pres
)
976 puts_filtered ("Segment not present\n");
979 base
= (info
.HighWord
.Bits
.BaseHi
<< 24) +
980 (info
.HighWord
.Bits
.BaseMid
<< 16)
982 limit
= (info
.HighWord
.Bits
.LimitHi
<< 16) + info
.LimitLow
;
983 if (info
.HighWord
.Bits
.Granularity
)
984 limit
= (limit
<< 12) | 0xfff;
985 printf_filtered ("base=0x%08x limit=0x%08x", base
, limit
);
986 if (info
.HighWord
.Bits
.Default_Big
)
987 puts_filtered(" 32-bit ");
989 puts_filtered(" 16-bit ");
990 switch ((info
.HighWord
.Bits
.Type
& 0xf) >> 1)
993 puts_filtered ("Data (Read-Only, Exp-up");
996 puts_filtered ("Data (Read/Write, Exp-up");
999 puts_filtered ("Unused segment (");
1002 puts_filtered ("Data (Read/Write, Exp-down");
1005 puts_filtered ("Code (Exec-Only, N.Conf");
1008 puts_filtered ("Code (Exec/Read, N.Conf");
1011 puts_filtered ("Code (Exec-Only, Conf");
1014 puts_filtered ("Code (Exec/Read, Conf");
1017 printf_filtered ("Unknown type 0x%x",info
.HighWord
.Bits
.Type
);
1019 if ((info
.HighWord
.Bits
.Type
& 0x1) == 0)
1020 puts_filtered(", N.Acc");
1021 puts_filtered (")\n");
1022 if ((info
.HighWord
.Bits
.Type
& 0x10) == 0)
1023 puts_filtered("System selector ");
1024 printf_filtered ("Priviledge level = %d. ", info
.HighWord
.Bits
.Dpl
);
1025 if (info
.HighWord
.Bits
.Granularity
)
1026 puts_filtered ("Page granular.\n");
1028 puts_filtered ("Byte granular.\n");
1033 printf_filtered ("Invalid selector 0x%lx.\n",sel
);
1039 display_selectors (char * args
, int from_tty
)
1041 if (!current_thread
)
1043 puts_filtered ("Impossible to display selectors now.\n");
1049 puts_filtered ("Selector $cs\n");
1050 display_selector (current_thread
->h
,
1051 current_thread
->context
.SegCs
);
1052 puts_filtered ("Selector $ds\n");
1053 display_selector (current_thread
->h
,
1054 current_thread
->context
.SegDs
);
1055 puts_filtered ("Selector $es\n");
1056 display_selector (current_thread
->h
,
1057 current_thread
->context
.SegEs
);
1058 puts_filtered ("Selector $ss\n");
1059 display_selector (current_thread
->h
,
1060 current_thread
->context
.SegSs
);
1061 puts_filtered ("Selector $fs\n");
1062 display_selector (current_thread
->h
,
1063 current_thread
->context
.SegFs
);
1064 puts_filtered ("Selector $gs\n");
1065 display_selector (current_thread
->h
,
1066 current_thread
->context
.SegGs
);
1071 sel
= parse_and_eval_long (args
);
1072 printf_filtered ("Selector \"%s\"\n",args
);
1073 display_selector (current_thread
->h
, sel
);
1077 static struct cmd_list_element
*info_w32_cmdlist
= NULL
;
1080 info_w32_command (char *args
, int from_tty
)
1082 help_list (info_w32_cmdlist
, "info w32 ", class_info
, gdb_stdout
);
1086 #define DEBUG_EXCEPTION_SIMPLE(x) if (debug_exceptions) \
1087 printf_unfiltered ("gdb: Target exception %s at 0x%08lx\n", x, \
1088 (DWORD) current_event.u.Exception.ExceptionRecord.ExceptionAddress)
1091 handle_exception (struct target_waitstatus
*ourstatus
)
1094 DWORD code
= current_event
.u
.Exception
.ExceptionRecord
.ExceptionCode
;
1096 ourstatus
->kind
= TARGET_WAITKIND_STOPPED
;
1098 /* Record the context of the current thread */
1099 th
= thread_rec (current_event
.dwThreadId
, -1);
1103 case EXCEPTION_ACCESS_VIOLATION
:
1104 DEBUG_EXCEPTION_SIMPLE ("EXCEPTION_ACCESS_VIOLATION");
1105 ourstatus
->value
.sig
= TARGET_SIGNAL_SEGV
;
1107 /* See if the access violation happened within the cygwin DLL itself. Cygwin uses
1108 a kind of exception handling to deal with passed-in invalid addresses. gdb
1109 should not treat these as real SEGVs since they will be silently handled by
1110 cygwin. A real SEGV will (theoretically) be caught by cygwin later in the process
1111 and will be sent as a cygwin-specific-signal. So, ignore SEGVs if they show up
1112 within the text segment of the DLL itself. */
1114 bfd_vma addr
= (bfd_vma
) current_event
.u
.Exception
.ExceptionRecord
.ExceptionAddress
;
1115 if ((!cygwin_exceptions
&& (addr
>= cygwin_load_start
&& addr
< cygwin_load_end
))
1116 || (find_pc_partial_function (addr
, &fn
, NULL
, NULL
)
1117 && strncmp (fn
, "KERNEL32!IsBad", strlen ("KERNEL32!IsBad")) == 0))
1121 case STATUS_STACK_OVERFLOW
:
1122 DEBUG_EXCEPTION_SIMPLE ("STATUS_STACK_OVERFLOW");
1123 ourstatus
->value
.sig
= TARGET_SIGNAL_SEGV
;
1125 case STATUS_FLOAT_DENORMAL_OPERAND
:
1126 DEBUG_EXCEPTION_SIMPLE ("STATUS_FLOAT_DENORMAL_OPERAND");
1127 ourstatus
->value
.sig
= TARGET_SIGNAL_FPE
;
1129 case EXCEPTION_ARRAY_BOUNDS_EXCEEDED
:
1130 DEBUG_EXCEPTION_SIMPLE ("EXCEPTION_ARRAY_BOUNDS_EXCEEDED");
1131 ourstatus
->value
.sig
= TARGET_SIGNAL_FPE
;
1133 case STATUS_FLOAT_INEXACT_RESULT
:
1134 DEBUG_EXCEPTION_SIMPLE ("STATUS_FLOAT_INEXACT_RESULT");
1135 ourstatus
->value
.sig
= TARGET_SIGNAL_FPE
;
1137 case STATUS_FLOAT_INVALID_OPERATION
:
1138 DEBUG_EXCEPTION_SIMPLE ("STATUS_FLOAT_INVALID_OPERATION");
1139 ourstatus
->value
.sig
= TARGET_SIGNAL_FPE
;
1141 case STATUS_FLOAT_OVERFLOW
:
1142 DEBUG_EXCEPTION_SIMPLE ("STATUS_FLOAT_OVERFLOW");
1143 ourstatus
->value
.sig
= TARGET_SIGNAL_FPE
;
1145 case STATUS_FLOAT_STACK_CHECK
:
1146 DEBUG_EXCEPTION_SIMPLE ("STATUS_FLOAT_STACK_CHECK");
1147 ourstatus
->value
.sig
= TARGET_SIGNAL_FPE
;
1149 case STATUS_FLOAT_UNDERFLOW
:
1150 DEBUG_EXCEPTION_SIMPLE ("STATUS_FLOAT_UNDERFLOW");
1151 ourstatus
->value
.sig
= TARGET_SIGNAL_FPE
;
1153 case STATUS_FLOAT_DIVIDE_BY_ZERO
:
1154 DEBUG_EXCEPTION_SIMPLE ("STATUS_FLOAT_DIVIDE_BY_ZERO");
1155 ourstatus
->value
.sig
= TARGET_SIGNAL_FPE
;
1157 case STATUS_INTEGER_DIVIDE_BY_ZERO
:
1158 DEBUG_EXCEPTION_SIMPLE ("STATUS_INTEGER_DIVIDE_BY_ZERO");
1159 ourstatus
->value
.sig
= TARGET_SIGNAL_FPE
;
1161 case STATUS_INTEGER_OVERFLOW
:
1162 DEBUG_EXCEPTION_SIMPLE ("STATUS_INTEGER_OVERFLOW");
1163 ourstatus
->value
.sig
= TARGET_SIGNAL_FPE
;
1165 case EXCEPTION_BREAKPOINT
:
1166 DEBUG_EXCEPTION_SIMPLE ("EXCEPTION_BREAKPOINT");
1167 ourstatus
->value
.sig
= TARGET_SIGNAL_TRAP
;
1170 DEBUG_EXCEPTION_SIMPLE ("DBG_CONTROL_C");
1171 ourstatus
->value
.sig
= TARGET_SIGNAL_INT
;
1173 case DBG_CONTROL_BREAK
:
1174 DEBUG_EXCEPTION_SIMPLE ("DBG_CONTROL_BREAK");
1175 ourstatus
->value
.sig
= TARGET_SIGNAL_INT
;
1177 case EXCEPTION_SINGLE_STEP
:
1178 DEBUG_EXCEPTION_SIMPLE ("EXCEPTION_SINGLE_STEP");
1179 ourstatus
->value
.sig
= TARGET_SIGNAL_TRAP
;
1181 case EXCEPTION_ILLEGAL_INSTRUCTION
:
1182 DEBUG_EXCEPTION_SIMPLE ("EXCEPTION_ILLEGAL_INSTRUCTION");
1183 ourstatus
->value
.sig
= TARGET_SIGNAL_ILL
;
1185 case EXCEPTION_PRIV_INSTRUCTION
:
1186 DEBUG_EXCEPTION_SIMPLE ("EXCEPTION_PRIV_INSTRUCTION");
1187 ourstatus
->value
.sig
= TARGET_SIGNAL_ILL
;
1189 case EXCEPTION_NONCONTINUABLE_EXCEPTION
:
1190 DEBUG_EXCEPTION_SIMPLE ("EXCEPTION_NONCONTINUABLE_EXCEPTION");
1191 ourstatus
->value
.sig
= TARGET_SIGNAL_ILL
;
1194 /* Treat unhandled first chance exceptions specially. */
1195 if (current_event
.u
.Exception
.dwFirstChance
)
1197 printf_unfiltered ("gdb: unknown target exception 0x%08lx at 0x%08lx\n",
1198 current_event
.u
.Exception
.ExceptionRecord
.ExceptionCode
,
1199 (DWORD
) current_event
.u
.Exception
.ExceptionRecord
.ExceptionAddress
);
1200 ourstatus
->value
.sig
= TARGET_SIGNAL_UNKNOWN
;
1204 last_sig
= ourstatus
->value
.sig
;
1208 /* Resume all artificially suspended threads if we are continuing
1211 win32_continue (DWORD continue_status
, int id
)
1217 DEBUG_EVENTS (("ContinueDebugEvent (cpid=%ld, ctid=%ld, %s);\n",
1218 current_event
.dwProcessId
, current_event
.dwThreadId
,
1219 continue_status
== DBG_CONTINUE
?
1220 "DBG_CONTINUE" : "DBG_EXCEPTION_NOT_HANDLED"));
1221 res
= ContinueDebugEvent (current_event
.dwProcessId
,
1222 current_event
.dwThreadId
,
1225 for (th
= &thread_head
; (th
= th
->next
) != NULL
;)
1226 if (((id
== -1) || (id
== (int) th
->id
)) && th
->suspend_count
)
1229 for (i
= 0; i
< th
->suspend_count
; i
++)
1230 (void) ResumeThread (th
->h
);
1231 th
->suspend_count
= 0;
1232 if (debug_registers_changed
)
1234 /* Only change the value of the debug registers */
1235 th
->context
.ContextFlags
= CONTEXT_DEBUG_REGISTERS
;
1236 th
->context
.Dr0
= dr
[0];
1237 th
->context
.Dr1
= dr
[1];
1238 th
->context
.Dr2
= dr
[2];
1239 th
->context
.Dr3
= dr
[3];
1240 /* th->context.Dr6 = dr[6];
1241 FIXME: should we set dr6 also ?? */
1242 th
->context
.Dr7
= dr
[7];
1243 CHECK (SetThreadContext (th
->h
, &th
->context
));
1244 th
->context
.ContextFlags
= 0;
1248 debug_registers_changed
= 0;
1252 /* Called in pathological case where Windows fails to send a
1253 CREATE_PROCESS_DEBUG_EVENT after an attach. */
1255 fake_create_process (void)
1257 current_process_handle
= OpenProcess (PROCESS_ALL_ACCESS
, FALSE
,
1258 current_event
.dwProcessId
);
1259 main_thread_id
= current_event
.dwThreadId
;
1260 current_thread
= win32_add_thread (main_thread_id
,
1261 current_event
.u
.CreateThread
.hThread
);
1262 return main_thread_id
;
1266 win32_resume (ptid_t ptid
, int step
, enum target_signal sig
)
1269 DWORD continue_status
= DBG_CONTINUE
;
1271 int pid
= PIDGET (ptid
);
1273 if (sig
!= TARGET_SIGNAL_0
)
1275 if (current_event
.dwDebugEventCode
!= EXCEPTION_DEBUG_EVENT
)
1277 DEBUG_EXCEPT(("Cannot continue with signal %d here.\n",sig
));
1279 else if (sig
== last_sig
)
1280 continue_status
= DBG_EXCEPTION_NOT_HANDLED
;
1283 /* This code does not seem to work, because
1284 the kernel does probably not consider changes in the ExceptionRecord
1285 structure when passing the exception to the inferior.
1286 Note that this seems possible in the exception handler itself. */
1289 for (i
= 0; xlate
[i
].them
!= -1; i
++)
1290 if (xlate
[i
].us
== sig
)
1292 current_event
.u
.Exception
.ExceptionRecord
.ExceptionCode
=
1294 continue_status
= DBG_EXCEPTION_NOT_HANDLED
;
1297 if (continue_status
== DBG_CONTINUE
)
1299 DEBUG_EXCEPT(("Cannot continue with signal %d.\n",sig
));
1303 DEBUG_EXCEPT(("Can only continue with recieved signal %d.\n",
1307 last_sig
= TARGET_SIGNAL_0
;
1309 DEBUG_EXEC (("gdb: win32_resume (pid=%d, step=%d, sig=%d);\n",
1312 /* Get context for currently selected thread */
1313 th
= thread_rec (current_event
.dwThreadId
, FALSE
);
1318 /* Single step by setting t bit */
1319 win32_fetch_inferior_registers (get_current_regcache (),
1320 gdbarch_ps_regnum (current_gdbarch
));
1321 th
->context
.EFlags
|= FLAG_TRACE_BIT
;
1324 if (th
->context
.ContextFlags
)
1326 if (debug_registers_changed
)
1328 th
->context
.Dr0
= dr
[0];
1329 th
->context
.Dr1
= dr
[1];
1330 th
->context
.Dr2
= dr
[2];
1331 th
->context
.Dr3
= dr
[3];
1332 /* th->context.Dr6 = dr[6];
1333 FIXME: should we set dr6 also ?? */
1334 th
->context
.Dr7
= dr
[7];
1336 CHECK (SetThreadContext (th
->h
, &th
->context
));
1337 th
->context
.ContextFlags
= 0;
1341 /* Allow continuing with the same signal that interrupted us.
1342 Otherwise complain. */
1344 win32_continue (continue_status
, pid
);
1347 /* Get the next event from the child. Return 1 if the event requires
1348 handling by WFI (or whatever).
1351 get_win32_debug_event (int pid
, struct target_waitstatus
*ourstatus
)
1354 DWORD continue_status
, event_code
;
1356 static thread_info dummy_thread_info
;
1360 last_sig
= TARGET_SIGNAL_0
;
1362 if (!(debug_event
= WaitForDebugEvent (¤t_event
, 1000)))
1366 continue_status
= DBG_CONTINUE
;
1368 event_code
= current_event
.dwDebugEventCode
;
1369 ourstatus
->kind
= TARGET_WAITKIND_SPURIOUS
;
1371 have_saved_context
= 0;
1375 case CREATE_THREAD_DEBUG_EVENT
:
1376 DEBUG_EVENTS (("gdb: kernel event for pid=%d tid=%x code=%s)\n",
1377 (unsigned) current_event
.dwProcessId
,
1378 (unsigned) current_event
.dwThreadId
,
1379 "CREATE_THREAD_DEBUG_EVENT"));
1380 if (saw_create
!= 1)
1382 if (!saw_create
&& attach_flag
)
1384 /* Kludge around a Windows bug where first event is a create
1385 thread event. Caused when attached process does not have
1387 retval
= ourstatus
->value
.related_pid
= fake_create_process ();
1392 /* Record the existence of this thread */
1393 th
= win32_add_thread (current_event
.dwThreadId
,
1394 current_event
.u
.CreateThread
.hThread
);
1396 printf_unfiltered ("[New %s]\n",
1398 pid_to_ptid (current_event
.dwThreadId
)));
1399 retval
= current_event
.dwThreadId
;
1402 case EXIT_THREAD_DEBUG_EVENT
:
1403 DEBUG_EVENTS (("gdb: kernel event for pid=%d tid=%d code=%s)\n",
1404 (unsigned) current_event
.dwProcessId
,
1405 (unsigned) current_event
.dwThreadId
,
1406 "EXIT_THREAD_DEBUG_EVENT"));
1407 if (current_event
.dwThreadId
!= main_thread_id
)
1409 win32_delete_thread (current_event
.dwThreadId
);
1410 th
= &dummy_thread_info
;
1414 case CREATE_PROCESS_DEBUG_EVENT
:
1415 DEBUG_EVENTS (("gdb: kernel event for pid=%d tid=%d code=%s)\n",
1416 (unsigned) current_event
.dwProcessId
,
1417 (unsigned) current_event
.dwThreadId
,
1418 "CREATE_PROCESS_DEBUG_EVENT"));
1419 CloseHandle (current_event
.u
.CreateProcessInfo
.hFile
);
1420 if (++saw_create
!= 1)
1422 CloseHandle (current_event
.u
.CreateProcessInfo
.hProcess
);
1426 current_process_handle
= current_event
.u
.CreateProcessInfo
.hProcess
;
1428 win32_delete_thread (main_thread_id
);
1429 main_thread_id
= current_event
.dwThreadId
;
1430 /* Add the main thread */
1431 th
= win32_add_thread (main_thread_id
,
1432 current_event
.u
.CreateProcessInfo
.hThread
);
1433 retval
= ourstatus
->value
.related_pid
= current_event
.dwThreadId
;
1436 case EXIT_PROCESS_DEBUG_EVENT
:
1437 DEBUG_EVENTS (("gdb: kernel event for pid=%d tid=%d code=%s)\n",
1438 (unsigned) current_event
.dwProcessId
,
1439 (unsigned) current_event
.dwThreadId
,
1440 "EXIT_PROCESS_DEBUG_EVENT"));
1441 if (saw_create
!= 1)
1443 ourstatus
->kind
= TARGET_WAITKIND_EXITED
;
1444 ourstatus
->value
.integer
= current_event
.u
.ExitProcess
.dwExitCode
;
1445 CloseHandle (current_process_handle
);
1446 retval
= main_thread_id
;
1449 case LOAD_DLL_DEBUG_EVENT
:
1450 DEBUG_EVENTS (("gdb: kernel event for pid=%d tid=%d code=%s)\n",
1451 (unsigned) current_event
.dwProcessId
,
1452 (unsigned) current_event
.dwThreadId
,
1453 "LOAD_DLL_DEBUG_EVENT"));
1454 CloseHandle (current_event
.u
.LoadDll
.hFile
);
1455 if (saw_create
!= 1)
1457 catch_errors (handle_load_dll
, NULL
, (char *) "", RETURN_MASK_ALL
);
1458 registers_changed (); /* mark all regs invalid */
1459 ourstatus
->kind
= TARGET_WAITKIND_LOADED
;
1460 ourstatus
->value
.integer
= 0;
1461 retval
= main_thread_id
;
1462 re_enable_breakpoints_in_shlibs ();
1465 case UNLOAD_DLL_DEBUG_EVENT
:
1466 DEBUG_EVENTS (("gdb: kernel event for pid=%d tid=%d code=%s)\n",
1467 (unsigned) current_event
.dwProcessId
,
1468 (unsigned) current_event
.dwThreadId
,
1469 "UNLOAD_DLL_DEBUG_EVENT"));
1470 if (saw_create
!= 1)
1472 catch_errors (handle_unload_dll
, NULL
, (char *) "", RETURN_MASK_ALL
);
1473 registers_changed (); /* mark all regs invalid */
1474 /* ourstatus->kind = TARGET_WAITKIND_UNLOADED;
1475 does not exist yet. */
1478 case EXCEPTION_DEBUG_EVENT
:
1479 DEBUG_EVENTS (("gdb: kernel event for pid=%d tid=%d code=%s)\n",
1480 (unsigned) current_event
.dwProcessId
,
1481 (unsigned) current_event
.dwThreadId
,
1482 "EXCEPTION_DEBUG_EVENT"));
1483 if (saw_create
!= 1)
1485 switch (handle_exception (ourstatus
))
1488 continue_status
= DBG_EXCEPTION_NOT_HANDLED
;
1491 retval
= current_event
.dwThreadId
;
1495 continue_status
= -1;
1500 case OUTPUT_DEBUG_STRING_EVENT
: /* message from the kernel */
1501 DEBUG_EVENTS (("gdb: kernel event for pid=%d tid=%d code=%s)\n",
1502 (unsigned) current_event
.dwProcessId
,
1503 (unsigned) current_event
.dwThreadId
,
1504 "OUTPUT_DEBUG_STRING_EVENT"));
1505 if (saw_create
!= 1)
1507 retval
= handle_output_debug_string (ourstatus
);
1511 if (saw_create
!= 1)
1513 printf_unfiltered ("gdb: kernel event for pid=%ld tid=%ld\n",
1514 (DWORD
) current_event
.dwProcessId
,
1515 (DWORD
) current_event
.dwThreadId
);
1516 printf_unfiltered (" unknown event code %ld\n",
1517 current_event
.dwDebugEventCode
);
1521 if (!retval
|| saw_create
!= 1)
1523 if (continue_status
== -1)
1524 win32_resume (ptid
, 0, 1);
1526 CHECK (win32_continue (continue_status
, -1));
1530 inferior_ptid
= pid_to_ptid (retval
);
1531 current_thread
= th
?: thread_rec (current_event
.dwThreadId
, TRUE
);
1538 /* Wait for interesting events to occur in the target process. */
1540 win32_wait (ptid_t ptid
, struct target_waitstatus
*ourstatus
)
1542 int pid
= PIDGET (ptid
);
1544 target_terminal_ours ();
1546 /* We loop when we get a non-standard exception rather than return
1547 with a SPURIOUS because resume can try and step or modify things,
1548 which needs a current_thread->h. But some of these exceptions mark
1549 the birth or death of threads, which mean that the current thread
1550 isn't necessarily what you think it is. */
1554 int retval
= get_win32_debug_event (pid
, ourstatus
);
1556 return pid_to_ptid (retval
);
1561 if (deprecated_ui_loop_hook
!= NULL
)
1562 detach
= deprecated_ui_loop_hook (0);
1565 win32_kill_inferior ();
1571 do_initial_win32_stuff (DWORD pid
)
1573 extern int stop_after_trap
;
1576 last_sig
= TARGET_SIGNAL_0
;
1578 exception_count
= 0;
1579 debug_registers_changed
= 0;
1580 debug_registers_used
= 0;
1581 for (i
= 0; i
< sizeof (dr
) / sizeof (dr
[0]); i
++)
1583 current_event
.dwProcessId
= pid
;
1584 memset (¤t_event
, 0, sizeof (current_event
));
1585 push_target (&win32_ops
);
1586 disable_breakpoints_in_shlibs ();
1587 win32_clear_solib ();
1588 clear_proceed_status ();
1589 init_wait_for_inferior ();
1591 terminal_init_inferior_with_pgrp (pid
);
1592 target_terminal_inferior ();
1596 stop_after_trap
= 1;
1597 wait_for_inferior ();
1598 if (stop_signal
!= TARGET_SIGNAL_TRAP
)
1599 resume (0, stop_signal
);
1603 stop_after_trap
= 0;
1607 /* Since Windows XP, detaching from a process is supported by Windows.
1608 The following code tries loading the appropriate functions dynamically.
1609 If loading these functions succeeds use them to actually detach from
1610 the inferior process, otherwise behave as usual, pretending that
1611 detach has worked. */
1612 static BOOL
WINAPI (*DebugSetProcessKillOnExit
)(BOOL
);
1613 static BOOL
WINAPI (*DebugActiveProcessStop
)(DWORD
);
1616 has_detach_ability (void)
1618 static HMODULE kernel32
= NULL
;
1621 kernel32
= LoadLibrary ("kernel32.dll");
1624 if (!DebugSetProcessKillOnExit
)
1625 DebugSetProcessKillOnExit
= GetProcAddress (kernel32
,
1626 "DebugSetProcessKillOnExit");
1627 if (!DebugActiveProcessStop
)
1628 DebugActiveProcessStop
= GetProcAddress (kernel32
,
1629 "DebugActiveProcessStop");
1630 if (DebugSetProcessKillOnExit
&& DebugActiveProcessStop
)
1636 /* Try to set or remove a user privilege to the current process. Return -1
1637 if that fails, the previous setting of that privilege otherwise.
1639 This code is copied from the Cygwin source code and rearranged to allow
1640 dynamically loading of the needed symbols from advapi32 which is only
1641 available on NT/2K/XP. */
1643 set_process_privilege (const char *privilege
, BOOL enable
)
1645 static HMODULE advapi32
= NULL
;
1646 static BOOL
WINAPI (*OpenProcessToken
)(HANDLE
, DWORD
, PHANDLE
);
1647 static BOOL
WINAPI (*LookupPrivilegeValue
)(LPCSTR
, LPCSTR
, PLUID
);
1648 static BOOL
WINAPI (*AdjustTokenPrivileges
)(HANDLE
, BOOL
, PTOKEN_PRIVILEGES
,
1649 DWORD
, PTOKEN_PRIVILEGES
, PDWORD
);
1651 HANDLE token_hdl
= NULL
;
1653 TOKEN_PRIVILEGES new_priv
, orig_priv
;
1657 if (GetVersion () >= 0x80000000) /* No security availbale on 9x/Me */
1662 if (!(advapi32
= LoadLibrary ("advapi32.dll")))
1664 if (!OpenProcessToken
)
1665 OpenProcessToken
= GetProcAddress (advapi32
, "OpenProcessToken");
1666 if (!LookupPrivilegeValue
)
1667 LookupPrivilegeValue
= GetProcAddress (advapi32
,
1668 "LookupPrivilegeValueA");
1669 if (!AdjustTokenPrivileges
)
1670 AdjustTokenPrivileges
= GetProcAddress (advapi32
,
1671 "AdjustTokenPrivileges");
1672 if (!OpenProcessToken
|| !LookupPrivilegeValue
|| !AdjustTokenPrivileges
)
1679 if (!OpenProcessToken (GetCurrentProcess (),
1680 TOKEN_QUERY
| TOKEN_ADJUST_PRIVILEGES
,
1684 if (!LookupPrivilegeValue (NULL
, privilege
, &restore_priv
))
1687 new_priv
.PrivilegeCount
= 1;
1688 new_priv
.Privileges
[0].Luid
= restore_priv
;
1689 new_priv
.Privileges
[0].Attributes
= enable
? SE_PRIVILEGE_ENABLED
: 0;
1691 if (!AdjustTokenPrivileges (token_hdl
, FALSE
, &new_priv
,
1692 sizeof orig_priv
, &orig_priv
, &size
))
1695 /* Disabled, otherwise every `attach' in an unprivileged user session
1696 would raise the "Failed to get SE_DEBUG_NAME privilege" warning in
1698 /* AdjustTokenPrivileges returns TRUE even if the privilege could not
1699 be enabled. GetLastError () returns an correct error code, though. */
1700 if (enable
&& GetLastError () == ERROR_NOT_ALL_ASSIGNED
)
1704 ret
= orig_priv
.Privileges
[0].Attributes
== SE_PRIVILEGE_ENABLED
? 1 : 0;
1708 CloseHandle (token_hdl
);
1713 /* Attach to process PID, then initialize for debugging it. */
1715 win32_attach (char *args
, int from_tty
)
1721 error_no_arg (_("process-id to attach"));
1723 if (set_process_privilege (SE_DEBUG_NAME
, TRUE
) < 0)
1725 printf_unfiltered ("Warning: Failed to get SE_DEBUG_NAME privilege\n");
1726 printf_unfiltered ("This can cause attach to fail on Windows NT/2K/XP\n");
1729 pid
= strtoul (args
, 0, 0); /* Windows pid */
1731 win32_init_thread_list ();
1732 ok
= DebugActiveProcess (pid
);
1737 /* Try fall back to Cygwin pid */
1738 pid
= cygwin_internal (CW_CYGWIN_PID_TO_WINPID
, pid
);
1741 ok
= DebugActiveProcess (pid
);
1744 error (_("Can't attach to process."));
1747 if (has_detach_ability ())
1748 DebugSetProcessKillOnExit (FALSE
);
1754 char *exec_file
= (char *) get_exec_file (0);
1757 printf_unfiltered ("Attaching to program `%s', %s\n", exec_file
,
1758 target_pid_to_str (pid_to_ptid (pid
)));
1760 printf_unfiltered ("Attaching to %s\n",
1761 target_pid_to_str (pid_to_ptid (pid
)));
1763 gdb_flush (gdb_stdout
);
1766 do_initial_win32_stuff (pid
);
1767 target_terminal_ours ();
1771 win32_detach (char *args
, int from_tty
)
1775 if (has_detach_ability ())
1778 win32_resume (ptid
, 0, TARGET_SIGNAL_0
);
1780 if (!DebugActiveProcessStop (current_event
.dwProcessId
))
1782 error (_("Can't detach process %lu (error %lu)"),
1783 current_event
.dwProcessId
, GetLastError ());
1786 DebugSetProcessKillOnExit (FALSE
);
1788 if (detached
&& from_tty
)
1790 char *exec_file
= get_exec_file (0);
1793 printf_unfiltered ("Detaching from program: %s, Pid %lu\n", exec_file
,
1794 current_event
.dwProcessId
);
1795 gdb_flush (gdb_stdout
);
1797 inferior_ptid
= null_ptid
;
1798 unpush_target (&win32_ops
);
1802 win32_pid_to_exec_file (int pid
)
1804 /* Try to find the process path using the Cygwin internal process list
1805 pid isn't a valid pid, unfortunately. Use current_event.dwProcessId
1807 /* TODO: Also find native Windows processes using CW_GETPINFO_FULL. */
1809 static char path
[MAX_PATH
+ 1];
1810 char *path_ptr
= NULL
;
1812 struct external_pinfo
*pinfo
;
1814 cygwin_internal (CW_LOCK_PINFO
, 1000);
1816 (pinfo
= (struct external_pinfo
*)
1817 cygwin_internal (CW_GETPINFO
, cpid
| CW_NEXTPID
));
1820 if (pinfo
->dwProcessId
== current_event
.dwProcessId
) /* Got it */
1822 cygwin_conv_to_full_posix_path (pinfo
->progname
, path
);
1827 cygwin_internal (CW_UNLOCK_PINFO
);
1831 /* Print status information about what we're accessing. */
1834 win32_files_info (struct target_ops
*ignore
)
1836 printf_unfiltered ("\tUsing the running image of %s %s.\n",
1837 attach_flag
? "attached" : "child", target_pid_to_str (inferior_ptid
));
1841 win32_open (char *arg
, int from_tty
)
1843 error (_("Use the \"run\" command to start a Unix child process."));
1846 /* Start an inferior win32 child process and sets inferior_ptid to its pid.
1847 EXEC_FILE is the file to run.
1848 ALLARGS is a string containing the arguments to the program.
1849 ENV is the environment vector to pass. Errors reported with error(). */
1852 win32_create_inferior (char *exec_file
, char *allargs
, char **in_env
,
1856 PROCESS_INFORMATION pi
;
1860 char real_path
[MAXPATHLEN
];
1862 char shell
[MAX_PATH
+ 1]; /* Path to shell */
1865 int ostdin
, ostdout
, ostderr
;
1866 const char *inferior_io_terminal
= get_inferior_io_terminal ();
1869 error (_("No executable specified, use `target exec'."));
1871 memset (&si
, 0, sizeof (si
));
1872 si
.cb
= sizeof (si
);
1876 flags
= DEBUG_ONLY_THIS_PROCESS
;
1877 cygwin_conv_to_win32_path (exec_file
, real_path
);
1883 sh
= getenv ("SHELL");
1886 cygwin_conv_to_win32_path (sh
, shell
);
1887 newallargs
= alloca (sizeof (" -c 'exec '") + strlen (exec_file
)
1888 + strlen (allargs
) + 2);
1889 sprintf (newallargs
, " -c 'exec %s %s'", exec_file
, allargs
);
1890 allargs
= newallargs
;
1892 flags
= DEBUG_PROCESS
;
1896 flags
|= CREATE_NEW_PROCESS_GROUP
;
1899 flags
|= CREATE_NEW_CONSOLE
;
1903 args
= alloca (strlen (toexec
) + strlen (allargs
) + 2);
1904 strcpy (args
, toexec
);
1906 strcat (args
, allargs
);
1908 /* Prepare the environment vars for CreateProcess. */
1909 cygwin_internal (CW_SYNC_WINENV
);
1911 if (!inferior_io_terminal
)
1912 tty
= ostdin
= ostdout
= ostderr
= -1;
1915 tty
= open (inferior_io_terminal
, O_RDWR
| O_NOCTTY
);
1918 print_sys_errmsg (inferior_io_terminal
, errno
);
1919 ostdin
= ostdout
= ostderr
= -1;
1932 win32_init_thread_list ();
1933 ret
= CreateProcess (0,
1934 args
, /* command line */
1935 NULL
, /* Security */
1937 TRUE
, /* inherit handles */
1938 flags
, /* start flags */
1939 NULL
, /* environment */
1940 NULL
, /* current directory */
1955 error (_("Error creating process %s, (error %d)."),
1956 exec_file
, (unsigned) GetLastError ());
1958 CloseHandle (pi
.hThread
);
1959 CloseHandle (pi
.hProcess
);
1961 if (useshell
&& shell
[0] != '\0')
1966 do_initial_win32_stuff (pi
.dwProcessId
);
1968 /* win32_continue (DBG_CONTINUE, -1); */
1972 win32_mourn_inferior (void)
1974 (void) win32_continue (DBG_CONTINUE
, -1);
1975 i386_cleanup_dregs();
1976 unpush_target (&win32_ops
);
1977 generic_mourn_inferior ();
1980 /* Send a SIGINT to the process group. This acts just like the user typed a
1981 ^C on the controlling terminal. */
1986 DEBUG_EVENTS (("gdb: GenerateConsoleCtrlEvent (CTRLC_EVENT, 0)\n"));
1987 CHECK (GenerateConsoleCtrlEvent (CTRL_C_EVENT
, current_event
.dwProcessId
));
1988 registers_changed (); /* refresh register state */
1992 win32_xfer_memory (CORE_ADDR memaddr
, gdb_byte
*our
, int len
,
1993 int write
, struct mem_attrib
*mem
,
1994 struct target_ops
*target
)
1999 DEBUG_MEM (("gdb: write target memory, %d bytes at 0x%08lx\n",
2000 len
, (DWORD
) memaddr
));
2001 if (!WriteProcessMemory (current_process_handle
, (LPVOID
) memaddr
, our
,
2004 FlushInstructionCache (current_process_handle
, (LPCVOID
) memaddr
, len
);
2008 DEBUG_MEM (("gdb: read target memory, %d bytes at 0x%08lx\n",
2009 len
, (DWORD
) memaddr
));
2010 if (!ReadProcessMemory (current_process_handle
, (LPCVOID
) memaddr
, our
,
2018 win32_kill_inferior (void)
2020 CHECK (TerminateProcess (current_process_handle
, 0));
2024 if (!win32_continue (DBG_CONTINUE
, -1))
2026 if (!WaitForDebugEvent (¤t_event
, INFINITE
))
2028 if (current_event
.dwDebugEventCode
== EXIT_PROCESS_DEBUG_EVENT
)
2032 CHECK (CloseHandle (current_process_handle
));
2034 /* this may fail in an attached process so don't check. */
2035 if (current_thread
&& current_thread
->h
)
2036 (void) CloseHandle (current_thread
->h
);
2037 target_mourn_inferior (); /* or just win32_mourn_inferior? */
2041 win32_prepare_to_store (struct regcache
*regcache
)
2043 /* Do nothing, since we can store individual regs */
2047 win32_can_run (void)
2055 DEBUG_EVENTS (("gdb: win32_close, inferior_ptid=%d\n",
2056 PIDGET (inferior_ptid
)));
2059 /* Convert pid to printable format. */
2061 cygwin_pid_to_str (ptid_t ptid
)
2063 static char buf
[80];
2064 int pid
= PIDGET (ptid
);
2066 if ((DWORD
) pid
== current_event
.dwProcessId
)
2067 sprintf (buf
, "process %d", pid
);
2069 sprintf (buf
, "thread %ld.0x%x", current_event
.dwProcessId
, pid
);
2075 struct target_ops
*target
;
2077 } map_code_section_args
;
2080 map_single_dll_code_section (bfd
*abfd
, asection
*sect
, void *obj
)
2084 struct section_table
*new_target_sect_ptr
;
2086 map_code_section_args
*args
= (map_code_section_args
*) obj
;
2087 struct target_ops
*target
= args
->target
;
2088 if (sect
->flags
& SEC_CODE
)
2090 update_coreops
= core_ops
.to_sections
== target
->to_sections
;
2092 if (target
->to_sections
)
2094 old
= target
->to_sections_end
- target
->to_sections
;
2095 target
->to_sections
= (struct section_table
*)
2096 xrealloc ((char *) target
->to_sections
,
2097 (sizeof (struct section_table
)) * (1 + old
));
2102 target
->to_sections
= (struct section_table
*)
2103 xmalloc ((sizeof (struct section_table
)));
2105 target
->to_sections_end
= target
->to_sections
+ (1 + old
);
2107 /* Update the to_sections field in the core_ops structure
2111 core_ops
.to_sections
= target
->to_sections
;
2112 core_ops
.to_sections_end
= target
->to_sections_end
;
2114 new_target_sect_ptr
= target
->to_sections
+ old
;
2115 new_target_sect_ptr
->addr
= args
->addr
+ bfd_section_vma (abfd
, sect
);
2116 new_target_sect_ptr
->endaddr
= args
->addr
+ bfd_section_vma (abfd
, sect
) +
2117 bfd_section_size (abfd
, sect
);;
2118 new_target_sect_ptr
->the_bfd_section
= sect
;
2119 new_target_sect_ptr
->bfd
= abfd
;
2124 dll_code_sections_add (const char *dll_name
, int base_addr
, struct target_ops
*target
)
2127 map_code_section_args map_args
;
2128 asection
*lowest_sect
;
2130 if (dll_name
== NULL
|| target
== NULL
)
2132 name
= xstrdup (dll_name
);
2133 dll_bfd
= bfd_openr (name
, "pei-i386");
2134 if (dll_bfd
== NULL
)
2137 if (bfd_check_format (dll_bfd
, bfd_object
))
2139 lowest_sect
= bfd_get_section_by_name (dll_bfd
, ".text");
2140 if (lowest_sect
== NULL
)
2142 map_args
.target
= target
;
2143 map_args
.addr
= base_addr
- bfd_section_vma (dll_bfd
, lowest_sect
);
2145 bfd_map_over_sections (dll_bfd
, &map_single_dll_code_section
, (void *) (&map_args
));
2152 core_section_load_dll_symbols (bfd
*abfd
, asection
*sect
, void *obj
)
2154 struct target_ops
*target
= (struct target_ops
*) obj
;
2159 struct win32_pstatus
*pstatus
;
2164 struct objfile
*objfile
;
2165 const char *dll_basename
;
2167 if (strncmp (sect
->name
, ".module", 7) != 0)
2170 buf
= (char *) xmalloc (bfd_get_section_size (sect
) + 1);
2173 printf_unfiltered ("memory allocation failed for %s\n", sect
->name
);
2176 if (!bfd_get_section_contents (abfd
, sect
, buf
, 0, bfd_get_section_size (sect
)))
2179 pstatus
= (struct win32_pstatus
*) buf
;
2181 memmove (&base_addr
, &(pstatus
->data
.module_info
.base_address
), sizeof (base_addr
));
2182 dll_name_size
= pstatus
->data
.module_info
.module_name_size
;
2183 if (offsetof (struct win32_pstatus
, data
.module_info
.module_name
) + dll_name_size
> bfd_get_section_size (sect
))
2186 dll_name
= pstatus
->data
.module_info
.module_name
;
2188 if (!(dll_basename
= strrchr (dll_name
, '/')))
2189 dll_basename
= dll_name
;
2193 ALL_OBJFILES (objfile
)
2195 char *objfile_basename
= strrchr (objfile
->name
, '/');
2197 if (objfile_basename
&&
2198 strcasecmp (dll_basename
, objfile_basename
+ 1) == 0)
2202 base_addr
+= 0x1000;
2203 dll_name
= register_loaded_dll (dll_name
, base_addr
, 1);
2205 if (!dll_code_sections_add (dll_name
, (DWORD
) base_addr
, target
))
2206 printf_unfiltered ("%s: Failed to map dll code sections.\n", dll_name
);
2214 static struct so_list
*
2215 win32_current_sos (void)
2217 struct so_list
*sop
;
2218 struct so_list
*start
= NULL
;
2219 struct so_list
*last
= NULL
;
2221 if (!solib_start
.next
&& core_bfd
)
2223 win32_clear_solib ();
2224 bfd_map_over_sections (core_bfd
, &core_section_load_dll_symbols
,
2228 for (sop
= solib_start
.next
; sop
; sop
= sop
->next
)
2230 struct so_list
*new = XZALLOC (struct so_list
);
2231 strcpy (new->so_name
, sop
->so_name
);
2232 strcpy (new->so_original_name
, sop
->so_original_name
);
2246 open_symbol_file_object (void *from_ttyp
)
2252 in_dynsym_resolve_code (CORE_ADDR pc
)
2258 init_win32_ops (void)
2260 win32_ops
.to_shortname
= "child";
2261 win32_ops
.to_longname
= "Win32 child process";
2262 win32_ops
.to_doc
= "Win32 child process (started by the \"run\" command).";
2263 win32_ops
.to_open
= win32_open
;
2264 win32_ops
.to_close
= win32_close
;
2265 win32_ops
.to_attach
= win32_attach
;
2266 win32_ops
.to_detach
= win32_detach
;
2267 win32_ops
.to_resume
= win32_resume
;
2268 win32_ops
.to_wait
= win32_wait
;
2269 win32_ops
.to_fetch_registers
= win32_fetch_inferior_registers
;
2270 win32_ops
.to_store_registers
= win32_store_inferior_registers
;
2271 win32_ops
.to_prepare_to_store
= win32_prepare_to_store
;
2272 win32_ops
.deprecated_xfer_memory
= win32_xfer_memory
;
2273 win32_ops
.to_files_info
= win32_files_info
;
2274 win32_ops
.to_insert_breakpoint
= memory_insert_breakpoint
;
2275 win32_ops
.to_remove_breakpoint
= memory_remove_breakpoint
;
2276 win32_ops
.to_terminal_init
= terminal_init_inferior
;
2277 win32_ops
.to_terminal_inferior
= terminal_inferior
;
2278 win32_ops
.to_terminal_ours_for_output
= terminal_ours_for_output
;
2279 win32_ops
.to_terminal_ours
= terminal_ours
;
2280 win32_ops
.to_terminal_save_ours
= terminal_save_ours
;
2281 win32_ops
.to_terminal_info
= child_terminal_info
;
2282 win32_ops
.to_kill
= win32_kill_inferior
;
2283 win32_ops
.to_create_inferior
= win32_create_inferior
;
2284 win32_ops
.to_mourn_inferior
= win32_mourn_inferior
;
2285 win32_ops
.to_can_run
= win32_can_run
;
2286 win32_ops
.to_thread_alive
= win32_win32_thread_alive
;
2287 win32_ops
.to_pid_to_str
= cygwin_pid_to_str
;
2288 win32_ops
.to_stop
= win32_stop
;
2289 win32_ops
.to_stratum
= process_stratum
;
2290 win32_ops
.to_has_all_memory
= 1;
2291 win32_ops
.to_has_memory
= 1;
2292 win32_ops
.to_has_stack
= 1;
2293 win32_ops
.to_has_registers
= 1;
2294 win32_ops
.to_has_execution
= 1;
2295 win32_ops
.to_magic
= OPS_MAGIC
;
2296 win32_ops
.to_pid_to_exec_file
= win32_pid_to_exec_file
;
2298 win32_so_ops
.relocate_section_addresses
= win32_relocate_section_addresses
;
2299 win32_so_ops
.free_so
= win32_free_so
;
2300 win32_so_ops
.clear_solib
= win32_clear_solib
;
2301 win32_so_ops
.solib_create_inferior_hook
= win32_solib_create_inferior_hook
;
2302 win32_so_ops
.special_symbol_handling
= win32_special_symbol_handling
;
2303 win32_so_ops
.current_sos
= win32_current_sos
;
2304 win32_so_ops
.open_symbol_file_object
= open_symbol_file_object
;
2305 win32_so_ops
.in_dynsym_resolve_code
= in_dynsym_resolve_code
;
2307 /* FIXME: Don't do this here. *_gdbarch_init() should set so_ops. */
2308 current_target_so_ops
= &win32_so_ops
;
2312 set_win32_aliases (char *argv0
)
2314 add_info_alias ("dll", "sharedlibrary", 1);
2318 _initialize_win32_nat (void)
2320 struct cmd_list_element
*c
;
2324 c
= add_com ("dll-symbols", class_files
, dll_symbol_command
,
2325 _("Load dll library symbols from FILE."));
2326 set_cmd_completer (c
, filename_completer
);
2328 add_com_alias ("sharedlibrary", "dll-symbols", class_alias
, 1);
2330 add_setshow_boolean_cmd ("shell", class_support
, &useshell
, _("\
2331 Set use of shell to start subprocess."), _("\
2332 Show use of shell to start subprocess."), NULL
,
2334 NULL
, /* FIXME: i18n: */
2335 &setlist
, &showlist
);
2337 add_setshow_boolean_cmd ("cygwin-exceptions", class_support
, &cygwin_exceptions
, _("\
2338 Break when an exception is detected in the Cygwin DLL itself."), _("\
2339 Show whether gdb breaks on exceptions in the Cygwin DLL itself."), NULL
,
2341 NULL
, /* FIXME: i18n: */
2342 &setlist
, &showlist
);
2344 add_setshow_boolean_cmd ("new-console", class_support
, &new_console
, _("\
2345 Set creation of new console when creating child process."), _("\
2346 Show creation of new console when creating child process."), NULL
,
2348 NULL
, /* FIXME: i18n: */
2349 &setlist
, &showlist
);
2351 add_setshow_boolean_cmd ("new-group", class_support
, &new_group
, _("\
2352 Set creation of new group when creating child process."), _("\
2353 Show creation of new group when creating child process."), NULL
,
2355 NULL
, /* FIXME: i18n: */
2356 &setlist
, &showlist
);
2358 add_setshow_boolean_cmd ("debugexec", class_support
, &debug_exec
, _("\
2359 Set whether to display execution in child process."), _("\
2360 Show whether to display execution in child process."), NULL
,
2362 NULL
, /* FIXME: i18n: */
2363 &setlist
, &showlist
);
2365 add_setshow_boolean_cmd ("debugevents", class_support
, &debug_events
, _("\
2366 Set whether to display kernel events in child process."), _("\
2367 Show whether to display kernel events in child process."), NULL
,
2369 NULL
, /* FIXME: i18n: */
2370 &setlist
, &showlist
);
2372 add_setshow_boolean_cmd ("debugmemory", class_support
, &debug_memory
, _("\
2373 Set whether to display memory accesses in child process."), _("\
2374 Show whether to display memory accesses in child process."), NULL
,
2376 NULL
, /* FIXME: i18n: */
2377 &setlist
, &showlist
);
2379 add_setshow_boolean_cmd ("debugexceptions", class_support
,
2380 &debug_exceptions
, _("\
2381 Set whether to display kernel exceptions in child process."), _("\
2382 Show whether to display kernel exceptions in child process."), NULL
,
2384 NULL
, /* FIXME: i18n: */
2385 &setlist
, &showlist
);
2387 add_prefix_cmd ("w32", class_info
, info_w32_command
,
2388 _("Print information specific to Win32 debugging."),
2389 &info_w32_cmdlist
, "info w32 ", 0, &infolist
);
2391 add_cmd ("selector", class_info
, display_selectors
,
2392 _("Display selectors infos."),
2394 add_target (&win32_ops
);
2395 deprecated_init_ui_hook
= set_win32_aliases
;
2398 /* Hardware watchpoint support, adapted from go32-nat.c code. */
2400 /* Pass the address ADDR to the inferior in the I'th debug register.
2401 Here we just store the address in dr array, the registers will be
2402 actually set up when win32_continue is called. */
2404 cygwin_set_dr (int i
, CORE_ADDR addr
)
2407 internal_error (__FILE__
, __LINE__
,
2408 _("Invalid register %d in cygwin_set_dr.\n"), i
);
2409 dr
[i
] = (unsigned) addr
;
2410 debug_registers_changed
= 1;
2411 debug_registers_used
= 1;
2414 /* Pass the value VAL to the inferior in the DR7 debug control
2415 register. Here we just store the address in D_REGS, the watchpoint
2416 will be actually set up in win32_wait. */
2418 cygwin_set_dr7 (unsigned val
)
2421 debug_registers_changed
= 1;
2422 debug_registers_used
= 1;
2425 /* Get the value of the DR6 debug status register from the inferior.
2426 Here we just return the value stored in dr[6]
2427 by the last call to thread_rec for current_event.dwThreadId id. */
2429 cygwin_get_dr6 (void)
2434 /* Determine if the thread referenced by "pid" is alive
2435 by "polling" it. If WaitForSingleObject returns WAIT_OBJECT_0
2436 it means that the pid has died. Otherwise it is assumed to be alive. */
2438 win32_win32_thread_alive (ptid_t ptid
)
2440 int pid
= PIDGET (ptid
);
2442 return WaitForSingleObject (thread_rec (pid
, FALSE
)->h
, 0) == WAIT_OBJECT_0
?
2447 _initialize_check_for_gdb_ini (void)
2450 if (inhibit_gdbinit
)
2453 homedir
= getenv ("HOME");
2457 char *oldini
= (char *) alloca (strlen (homedir
) +
2458 sizeof ("/gdb.ini"));
2459 strcpy (oldini
, homedir
);
2460 p
= strchr (oldini
, '\0');
2461 if (p
> oldini
&& p
[-1] != '/')
2463 strcpy (p
, "gdb.ini");
2464 if (access (oldini
, 0) == 0)
2466 int len
= strlen (oldini
);
2467 char *newini
= alloca (len
+ 1);
2468 sprintf (newini
, "%.*s.gdbinit",
2469 (int) (len
- (sizeof ("gdb.ini") - 1)), oldini
);
2470 warning (_("obsolete '%s' found. Rename to '%s'."), oldini
, newini
);