1 /* Target-vector operations for controlling win32 child processes, for GDB.
3 Copyright 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005
4 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 2 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 eve nthe 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, write to the Free Software
22 Foundation, Inc., 59 Temple Place - Suite 330,
23 Boston, MA 02111-1307, USA. */
25 /* Originally by Steve Chamberlain, sac@cygnus.com */
27 /* We assume we're being built with and will be used for cygwin. */
30 #include "frame.h" /* required by inferior.h */
33 #include "exceptions.h"
36 #include "completer.h"
40 #include <sys/types.h>
45 #include <sys/cygwin.h>
50 #include "gdb_string.h"
51 #include "gdbthread.h"
53 #include <sys/param.h>
59 #include "i386-tdep.h"
60 #include "i387-tdep.h"
62 static struct target_ops win32_ops;
63 static struct target_so_ops win32_so_ops;
65 /* If we're not using the old Cygwin header file set, define the
66 following which never should have been in the generic Win32 API
67 headers in the first place since they were our own invention... */
68 #ifndef _GNU_H_WINDOWS_H
71 FLAG_TRACE_BIT = 0x100,
72 CONTEXT_DEBUGGER = (CONTEXT_FULL | CONTEXT_FLOATING_POINT)
75 #include <sys/procfs.h>
78 #define CONTEXT_DEBUGGER_DR CONTEXT_DEBUGGER | CONTEXT_DEBUG_REGISTERS \
79 | CONTEXT_EXTENDED_REGISTERS
81 static unsigned dr[8];
82 static int debug_registers_changed;
83 static int debug_registers_used;
85 /* The string sent by cygwin when it processes a signal.
86 FIXME: This should be in a cygwin include file. */
87 #ifndef _CYGWIN_SIGNAL_STRING
88 #define _CYGWIN_SIGNAL_STRING "cYgSiGw00f"
91 #define CHECK(x) check (x, __FILE__,__LINE__)
92 #define DEBUG_EXEC(x) if (debug_exec) printf_unfiltered x
93 #define DEBUG_EVENTS(x) if (debug_events) printf_unfiltered x
94 #define DEBUG_MEM(x) if (debug_memory) printf_unfiltered x
95 #define DEBUG_EXCEPT(x) if (debug_exceptions) printf_unfiltered x
97 static void win32_stop (void);
98 static int win32_win32_thread_alive (ptid_t);
99 static void win32_kill_inferior (void);
101 static enum target_signal last_sig = TARGET_SIGNAL_0;
102 /* Set if a signal was received from the debugged process */
104 /* Thread information structure used to track information that is
105 not available in gdb's thread structure. */
106 typedef struct thread_info_struct
108 struct thread_info_struct *next;
119 static thread_info thread_head;
121 /* The process and thread handles for the above context. */
123 static DEBUG_EVENT current_event; /* The current debug event from
125 static HANDLE current_process_handle; /* Currently executing process */
126 static thread_info *current_thread; /* Info on currently selected thread */
127 static DWORD main_thread_id; /* Thread ID of the main thread */
129 /* Counts of things. */
130 static int exception_count = 0;
131 static int event_count = 0;
132 static int saw_create;
135 static int new_console = 0;
136 static int new_group = 1;
137 static int debug_exec = 0; /* show execution */
138 static int debug_events = 0; /* show events from kernel */
139 static int debug_memory = 0; /* show target memory accesses */
140 static int debug_exceptions = 0; /* show target exceptions */
141 static int useshell = 0; /* use shell for subprocesses */
143 /* This vector maps GDB's idea of a register's number into an address
144 in the win32 exception context vector.
146 It also contains the bit mask needed to load the register in question.
148 One day we could read a reg, we could inspect the context we
149 already have loaded, if it doesn't have the bit set that we need,
150 we read that set of registers in using GetThreadContext. If the
151 context already contains what we need, we just unpack it. Then to
152 write a register, first we have to ensure that the context contains
153 the other regs of the group, and then we copy the info in and set
156 #define context_offset(x) ((int)&(((CONTEXT *)NULL)->x))
157 static const int mappings[] =
159 context_offset (Eax),
160 context_offset (Ecx),
161 context_offset (Edx),
162 context_offset (Ebx),
163 context_offset (Esp),
164 context_offset (Ebp),
165 context_offset (Esi),
166 context_offset (Edi),
167 context_offset (Eip),
168 context_offset (EFlags),
169 context_offset (SegCs),
170 context_offset (SegSs),
171 context_offset (SegDs),
172 context_offset (SegEs),
173 context_offset (SegFs),
174 context_offset (SegGs),
175 context_offset (FloatSave.RegisterArea[0 * 10]),
176 context_offset (FloatSave.RegisterArea[1 * 10]),
177 context_offset (FloatSave.RegisterArea[2 * 10]),
178 context_offset (FloatSave.RegisterArea[3 * 10]),
179 context_offset (FloatSave.RegisterArea[4 * 10]),
180 context_offset (FloatSave.RegisterArea[5 * 10]),
181 context_offset (FloatSave.RegisterArea[6 * 10]),
182 context_offset (FloatSave.RegisterArea[7 * 10]),
183 context_offset (FloatSave.ControlWord),
184 context_offset (FloatSave.StatusWord),
185 context_offset (FloatSave.TagWord),
186 context_offset (FloatSave.ErrorSelector),
187 context_offset (FloatSave.ErrorOffset),
188 context_offset (FloatSave.DataSelector),
189 context_offset (FloatSave.DataOffset),
190 context_offset (FloatSave.ErrorSelector)
192 context_offset (ExtendedRegisters[10*16]),
193 context_offset (ExtendedRegisters[11*16]),
194 context_offset (ExtendedRegisters[12*16]),
195 context_offset (ExtendedRegisters[13*16]),
196 context_offset (ExtendedRegisters[14*16]),
197 context_offset (ExtendedRegisters[15*16]),
198 context_offset (ExtendedRegisters[16*16]),
199 context_offset (ExtendedRegisters[17*16]),
201 context_offset (ExtendedRegisters[24])
204 #undef context_offset
206 /* This vector maps the target's idea of an exception (extracted
207 from the DEBUG_EVENT structure) to GDB's idea. */
209 struct xlate_exception
212 enum target_signal us;
215 static const struct xlate_exception
218 {EXCEPTION_ACCESS_VIOLATION, TARGET_SIGNAL_SEGV},
219 {STATUS_STACK_OVERFLOW, TARGET_SIGNAL_SEGV},
220 {EXCEPTION_BREAKPOINT, TARGET_SIGNAL_TRAP},
221 {DBG_CONTROL_C, TARGET_SIGNAL_INT},
222 {EXCEPTION_SINGLE_STEP, TARGET_SIGNAL_TRAP},
223 {STATUS_FLOAT_DIVIDE_BY_ZERO, TARGET_SIGNAL_FPE},
227 check (BOOL ok, const char *file, int line)
230 printf_filtered ("error return %s:%d was %lu\n", file, line,
234 /* Find a thread record given a thread id.
235 If get_context then also retrieve the context for this
238 thread_rec (DWORD id, int get_context)
242 for (th = &thread_head; (th = th->next) != NULL;)
245 if (!th->suspend_count && get_context)
247 if (get_context > 0 && id != current_event.dwThreadId)
248 th->suspend_count = SuspendThread (th->h) + 1;
249 else if (get_context < 0)
250 th->suspend_count = -1;
251 th->reload_context = 1;
259 /* Add a thread to the thread list */
261 win32_add_thread (DWORD id, HANDLE h)
265 if ((th = thread_rec (id, FALSE)))
268 th = XZALLOC (thread_info);
271 th->next = thread_head.next;
272 thread_head.next = th;
273 add_thread (pid_to_ptid (id));
274 /* Set the debug registers for the new thread in they are used. */
275 if (debug_registers_used)
277 /* Only change the value of the debug registers. */
278 th->context.ContextFlags = CONTEXT_DEBUG_REGISTERS;
279 CHECK (GetThreadContext (th->h, &th->context));
280 th->context.Dr0 = dr[0];
281 th->context.Dr1 = dr[1];
282 th->context.Dr2 = dr[2];
283 th->context.Dr3 = dr[3];
284 /* th->context.Dr6 = dr[6];
285 FIXME: should we set dr6 also ?? */
286 th->context.Dr7 = dr[7];
287 CHECK (SetThreadContext (th->h, &th->context));
288 th->context.ContextFlags = 0;
293 /* Clear out any old thread list and reintialize it to a
296 win32_init_thread_list (void)
298 thread_info *th = &thread_head;
300 DEBUG_EVENTS (("gdb: win32_init_thread_list\n"));
302 while (th->next != NULL)
304 thread_info *here = th->next;
305 th->next = here->next;
306 (void) CloseHandle (here->h);
309 thread_head.next = NULL;
312 /* Delete a thread from the list of threads */
314 win32_delete_thread (DWORD id)
319 printf_unfiltered ("[Deleting %s]\n", target_pid_to_str (pid_to_ptid (id)));
320 delete_thread (pid_to_ptid (id));
322 for (th = &thread_head;
323 th->next != NULL && th->next->id != id;
327 if (th->next != NULL)
329 thread_info *here = th->next;
330 th->next = here->next;
331 CloseHandle (here->h);
337 do_win32_fetch_inferior_registers (int r)
339 char *context_offset = ((char *) ¤t_thread->context) + mappings[r];
343 return; /* Windows sometimes uses a non-existent thread id in its
346 if (current_thread->reload_context)
348 thread_info *th = current_thread;
349 th->context.ContextFlags = CONTEXT_DEBUGGER_DR;
350 GetThreadContext (th->h, &th->context);
351 /* Copy dr values from that thread. */
352 dr[0] = th->context.Dr0;
353 dr[1] = th->context.Dr1;
354 dr[2] = th->context.Dr2;
355 dr[3] = th->context.Dr3;
356 dr[6] = th->context.Dr6;
357 dr[7] = th->context.Dr7;
358 current_thread->reload_context = 0;
361 #define I387_ST0_REGNUM I386_ST0_REGNUM
363 if (r == I387_FISEG_REGNUM)
365 l = *((long *) context_offset) & 0xffff;
366 regcache_raw_supply (current_regcache, r, (char *) &l);
368 else if (r == I387_FOP_REGNUM)
370 l = (*((long *) context_offset) >> 16) & ((1 << 11) - 1);
371 regcache_raw_supply (current_regcache, r, (char *) &l);
374 regcache_raw_supply (current_regcache, r, context_offset);
377 for (r = 0; r < NUM_REGS; r++)
378 do_win32_fetch_inferior_registers (r);
381 #undef I387_ST0_REGNUM
385 win32_fetch_inferior_registers (int r)
387 current_thread = thread_rec (PIDGET (inferior_ptid), TRUE);
388 /* Check if current_thread exists. Windows sometimes uses a non-existent
389 thread id in its events */
391 do_win32_fetch_inferior_registers (r);
395 do_win32_store_inferior_registers (int r)
398 /* Windows sometimes uses a non-existent thread id in its events */;
400 regcache_raw_collect (current_regcache, r,
401 ((char *) ¤t_thread->context) + mappings[r]);
404 for (r = 0; r < NUM_REGS; r++)
405 do_win32_store_inferior_registers (r);
409 /* Store a new register value into the current thread context */
411 win32_store_inferior_registers (int r)
413 current_thread = thread_rec (PIDGET (inferior_ptid), TRUE);
414 /* Check if current_thread exists. Windows sometimes uses a non-existent
415 thread id in its events */
417 do_win32_store_inferior_registers (r);
420 static int psapi_loaded = 0;
421 static HMODULE psapi_module_handle = NULL;
422 static BOOL WINAPI (*psapi_EnumProcessModules) (HANDLE, HMODULE *, DWORD, LPDWORD) = NULL;
423 static BOOL WINAPI (*psapi_GetModuleInformation) (HANDLE, HMODULE, LPMODULEINFO, DWORD) = NULL;
424 static DWORD WINAPI (*psapi_GetModuleFileNameExA) (HANDLE, HMODULE, LPSTR, DWORD) = NULL;
427 psapi_get_dll_name (DWORD BaseAddress, char *dll_name_ret)
433 HMODULE *DllHandle = dh_buf;
438 psapi_EnumProcessModules == NULL ||
439 psapi_GetModuleInformation == NULL ||
440 psapi_GetModuleFileNameExA == NULL)
445 psapi_module_handle = LoadLibrary ("psapi.dll");
446 if (!psapi_module_handle)
448 /* printf_unfiltered ("error loading psapi.dll: %u", GetLastError ()); */
451 psapi_EnumProcessModules = GetProcAddress (psapi_module_handle, "EnumProcessModules");
452 psapi_GetModuleInformation = GetProcAddress (psapi_module_handle, "GetModuleInformation");
453 psapi_GetModuleFileNameExA = (void *) GetProcAddress (psapi_module_handle,
454 "GetModuleFileNameExA");
455 if (psapi_EnumProcessModules == NULL ||
456 psapi_GetModuleInformation == NULL ||
457 psapi_GetModuleFileNameExA == NULL)
462 ok = (*psapi_EnumProcessModules) (current_process_handle,
467 if (!ok || !cbNeeded)
470 DllHandle = (HMODULE *) alloca (cbNeeded);
474 ok = (*psapi_EnumProcessModules) (current_process_handle,
481 for (i = 0; i < (int) (cbNeeded / sizeof (HMODULE)); i++)
483 if (!(*psapi_GetModuleInformation) (current_process_handle,
487 error (_("Can't get module info"));
489 len = (*psapi_GetModuleFileNameExA) (current_process_handle,
494 error (_("Error getting dll name: %u."), (unsigned) GetLastError ());
496 if ((DWORD) (mi.lpBaseOfDll) == BaseAddress)
501 dll_name_ret[0] = '\0';
505 /* Encapsulate the information required in a call to
506 symbol_file_add_args */
507 struct safe_symbol_file_add_args
511 struct section_addr_info *addrs;
514 struct ui_file *err, *out;
518 /* Maintain a linked list of "so" information. */
524 static struct so_list solib_start, *solib_end;
526 /* Call symbol_file_add with stderr redirected. We don't care if there
529 safe_symbol_file_add_stub (void *argv)
531 #define p ((struct safe_symbol_file_add_args *) argv)
532 struct so_list *so = &solib_start;
534 p->ret = symbol_file_add (p->name, p->from_tty, p->addrs, p->mainline, p->flags);
539 /* Restore gdb's stderr after calling symbol_file_add */
541 safe_symbol_file_add_cleanup (void *p)
543 #define sp ((struct safe_symbol_file_add_args *)p)
544 gdb_flush (gdb_stderr);
545 gdb_flush (gdb_stdout);
546 ui_file_delete (gdb_stderr);
547 ui_file_delete (gdb_stdout);
548 gdb_stderr = sp->err;
549 gdb_stdout = sp->out;
553 /* symbol_file_add wrapper that prevents errors from being displayed. */
554 static struct objfile *
555 safe_symbol_file_add (char *name, int from_tty,
556 struct section_addr_info *addrs,
557 int mainline, int flags)
559 struct safe_symbol_file_add_args p;
560 struct cleanup *cleanup;
562 cleanup = make_cleanup (safe_symbol_file_add_cleanup, &p);
566 gdb_flush (gdb_stderr);
567 gdb_flush (gdb_stdout);
568 gdb_stderr = ui_file_new ();
569 gdb_stdout = ui_file_new ();
571 p.from_tty = from_tty;
573 p.mainline = mainline;
575 catch_errors (safe_symbol_file_add_stub, &p, "", RETURN_MASK_ERROR);
577 do_cleanups (cleanup);
581 /* Get the loaded address of all sections, given that .text was loaded
582 at text_load. Assumes that all sections are subject to the same
583 relocation offset. Returns NULL if problems occur or if the
584 sections were not relocated. */
586 static struct section_addr_info *
587 get_relocated_section_addrs (bfd *abfd, CORE_ADDR text_load)
589 struct section_addr_info *result = NULL;
590 int section_count = bfd_count_sections (abfd);
591 asection *text_section = bfd_get_section_by_name (abfd, ".text");
596 /* Couldn't get the .text section. Weird. */
599 else if (text_load == (text_vma = bfd_get_section_vma (abfd, text_section)))
601 /* DLL wasn't relocated. */
606 /* Figure out all sections' loaded addresses. The offset here is
607 such that taking a bfd_get_section_vma() result and adding
608 offset will give the real load address of the section. */
610 CORE_ADDR offset = text_load - text_vma;
612 struct section_table *table_start = NULL;
613 struct section_table *table_end = NULL;
614 struct section_table *iter = NULL;
616 build_section_table (abfd, &table_start, &table_end);
618 for (iter = table_start; iter < table_end; ++iter)
620 /* Relocated addresses. */
621 iter->addr += offset;
622 iter->endaddr += offset;
625 result = build_section_addr_info_from_section_table (table_start,
634 /* Add DLL symbol information. */
636 solib_symbols_add (struct so_list *so, CORE_ADDR load_addr)
638 struct section_addr_info *addrs = NULL;
639 static struct objfile *result = NULL;
640 char *name = so->so_name;
643 /* The symbols in a dll are offset by 0x1000, which is the
644 the offset from 0 of the first byte in an image - because
645 of the file header and the section alignment. */
647 if (!name || !name[0])
650 abfd = bfd_openr (name, "pei-i386");
654 /* pei failed - try pe */
655 abfd = bfd_openr (name, "pe-i386");
660 if (bfd_check_format (abfd, bfd_object))
661 addrs = get_relocated_section_addrs (abfd, load_addr);
668 result = safe_symbol_file_add (name, 0, addrs, 0, OBJF_SHARED);
669 free_section_addr_info (addrs);
673 /* Fallback on handling just the .text section. */
674 struct cleanup *my_cleanups;
676 addrs = alloc_section_addr_info (1);
677 my_cleanups = make_cleanup (xfree, addrs);
678 addrs->other[0].name = ".text";
679 addrs->other[0].addr = load_addr;
681 result = safe_symbol_file_add (name, 0, addrs, 0, OBJF_SHARED);
682 do_cleanups (my_cleanups);
685 so->symbols_loaded = !!result;
689 /* Remember the maximum DLL length for printing in info dll command. */
690 static int max_dll_name_len;
693 register_loaded_dll (const char *name, DWORD load_addr, int readsyms)
696 char buf[MAX_PATH + 1];
697 char cwd[MAX_PATH + 1];
699 WIN32_FIND_DATA w32_fd;
700 HANDLE h = FindFirstFile(name, &w32_fd);
701 MEMORY_BASIC_INFORMATION m;
704 if (h == INVALID_HANDLE_VALUE)
710 if (GetCurrentDirectory (MAX_PATH + 1, cwd))
712 p = strrchr (buf, '\\');
715 SetCurrentDirectory (buf);
716 GetFullPathName (w32_fd.cFileName, MAX_PATH, buf, &p);
717 SetCurrentDirectory (cwd);
721 if (strcasecmp (buf, "ntdll.dll") == 0)
723 GetSystemDirectory (buf, sizeof (buf));
724 strcat (buf, "\\ntdll.dll");
726 so = XZALLOC (struct so_list);
727 so->lm_info = (struct lm_info *) xmalloc (sizeof (struct lm_info));
728 so->lm_info->load_addr = load_addr;
729 cygwin_conv_to_posix_path (buf, so->so_name);
730 strcpy (so->so_original_name, so->so_name);
732 solib_end->next = so;
734 len = strlen (so->so_name);
735 if (len > max_dll_name_len)
736 max_dll_name_len = len;
738 solib_symbols_add (so, (CORE_ADDR) load_addr);
743 get_image_name (HANDLE h, void *address, int unicode)
745 static char buf[(2 * MAX_PATH) + 1];
746 DWORD size = unicode ? sizeof (WCHAR) : sizeof (char);
752 /* Attempt to read the name of the dll that was detected.
753 This is documented to work only when actively debugging
754 a program. It will not work for attached processes. */
758 /* See if we could read the address of a string, and that the
759 address isn't null. */
760 if (!ReadProcessMemory (h, address, &address_ptr, sizeof (address_ptr), &done)
761 || done != sizeof (address_ptr) || !address_ptr)
764 /* Find the length of the string */
765 while (ReadProcessMemory (h, address_ptr + len++ * size, &b, size, &done)
766 && (b[0] != 0 || b[size - 1] != 0) && done == size)
770 ReadProcessMemory (h, address_ptr, buf, len, &done);
773 WCHAR *unicode_address = (WCHAR *) alloca (len * sizeof (WCHAR));
774 ReadProcessMemory (h, address_ptr, unicode_address, len * sizeof (WCHAR),
777 WideCharToMultiByte (CP_ACP, 0, unicode_address, len, buf, len, 0, 0);
783 /* Wait for child to do something. Return pid of child, or -1 in case
784 of error; store status through argument pointer OURSTATUS. */
786 handle_load_dll (void *dummy)
788 LOAD_DLL_DEBUG_INFO *event = ¤t_event.u.LoadDll;
789 char dll_buf[MAX_PATH + 1];
790 char *dll_name = NULL;
793 dll_buf[0] = dll_buf[sizeof (dll_buf) - 1] = '\0';
795 if (!psapi_get_dll_name ((DWORD) (event->lpBaseOfDll), dll_buf))
796 dll_buf[0] = dll_buf[sizeof (dll_buf) - 1] = '\0';
800 if (*dll_name == '\0')
801 dll_name = get_image_name (current_process_handle, event->lpImageName, event->fUnicode);
805 register_loaded_dll (dll_name, (DWORD) event->lpBaseOfDll + 0x1000, auto_solib_add);
806 solib_add (NULL, 0, NULL, auto_solib_add);
812 win32_free_so (struct so_list *so)
819 win32_relocate_section_addresses (struct so_list *so,
820 struct section_table *sec)
827 win32_solib_create_inferior_hook (void)
829 solib_add (NULL, 0, NULL, auto_solib_add);
834 handle_unload_dll (void *dummy)
836 DWORD lpBaseOfDll = (DWORD) current_event.u.UnloadDll.lpBaseOfDll + 0x1000;
839 for (so = &solib_start; so->next != NULL; so = so->next)
840 if (so->next->lm_info->load_addr == lpBaseOfDll)
842 struct so_list *sodel = so->next;
843 so->next = sodel->next;
847 solib_add (NULL, 0, NULL, auto_solib_add);
851 error (_("Error: dll starting at 0x%lx not found."), (DWORD) lpBaseOfDll);
856 /* Clear list of loaded DLLs. */
858 win32_clear_solib (void)
860 solib_start.next = NULL;
861 solib_end = &solib_start;
862 max_dll_name_len = sizeof ("DLL Name") - 1;
866 win32_special_symbol_handling (void)
871 /* Load DLL symbol info. */
873 dll_symbol_command (char *args, int from_tty)
879 error (_("dll-symbols requires a file name"));
882 if (n > 4 && strcasecmp (args + n - 4, ".dll") != 0)
884 char *newargs = (char *) alloca (n + 4 + 1);
885 strcpy (newargs, args);
886 strcat (newargs, ".dll");
890 safe_symbol_file_add (args, from_tty, NULL, 0, OBJF_SHARED | OBJF_USERLOADED);
893 /* Handle DEBUG_STRING output from child process.
894 Cygwin prepends its messages with a "cygwin:". Interpret this as
895 a Cygwin signal. Otherwise just print the string as a warning. */
897 handle_output_debug_string (struct target_waitstatus *ourstatus)
902 if (!target_read_string
903 ((CORE_ADDR) current_event.u.DebugString.lpDebugStringData, &s, 1024, 0)
907 if (strncmp (s, _CYGWIN_SIGNAL_STRING, sizeof (_CYGWIN_SIGNAL_STRING) - 1) != 0)
909 if (strncmp (s, "cYg", 3) != 0)
915 int sig = strtol (s + sizeof (_CYGWIN_SIGNAL_STRING) - 1, &p, 0);
916 gotasig = target_signal_from_host (sig);
917 ourstatus->value.sig = gotasig;
919 ourstatus->kind = TARGET_WAITKIND_STOPPED;
927 display_selector (HANDLE thread, DWORD sel)
930 if (GetThreadSelectorEntry (thread, sel, &info))
933 printf_filtered ("0x%03lx: ", sel);
934 if (!info.HighWord.Bits.Pres)
936 puts_filtered ("Segment not present\n");
939 base = (info.HighWord.Bits.BaseHi << 24) +
940 (info.HighWord.Bits.BaseMid << 16)
942 limit = (info.HighWord.Bits.LimitHi << 16) + info.LimitLow;
943 if (info.HighWord.Bits.Granularity)
944 limit = (limit << 12) | 0xfff;
945 printf_filtered ("base=0x%08x limit=0x%08x", base, limit);
946 if (info.HighWord.Bits.Default_Big)
947 puts_filtered(" 32-bit ");
949 puts_filtered(" 16-bit ");
950 switch ((info.HighWord.Bits.Type & 0xf) >> 1)
953 puts_filtered ("Data (Read-Only, Exp-up");
956 puts_filtered ("Data (Read/Write, Exp-up");
959 puts_filtered ("Unused segment (");
962 puts_filtered ("Data (Read/Write, Exp-down");
965 puts_filtered ("Code (Exec-Only, N.Conf");
968 puts_filtered ("Code (Exec/Read, N.Conf");
971 puts_filtered ("Code (Exec-Only, Conf");
974 puts_filtered ("Code (Exec/Read, Conf");
977 printf_filtered ("Unknown type 0x%x",info.HighWord.Bits.Type);
979 if ((info.HighWord.Bits.Type & 0x1) == 0)
980 puts_filtered(", N.Acc");
981 puts_filtered (")\n");
982 if ((info.HighWord.Bits.Type & 0x10) == 0)
983 puts_filtered("System selector ");
984 printf_filtered ("Priviledge level = %d. ", info.HighWord.Bits.Dpl);
985 if (info.HighWord.Bits.Granularity)
986 puts_filtered ("Page granular.\n");
988 puts_filtered ("Byte granular.\n");
993 printf_filtered ("Invalid selector 0x%lx.\n",sel);
999 display_selectors (char * args, int from_tty)
1001 if (!current_thread)
1003 puts_filtered ("Impossible to display selectors now.\n");
1009 puts_filtered ("Selector $cs\n");
1010 display_selector (current_thread->h,
1011 current_thread->context.SegCs);
1012 puts_filtered ("Selector $ds\n");
1013 display_selector (current_thread->h,
1014 current_thread->context.SegDs);
1015 puts_filtered ("Selector $es\n");
1016 display_selector (current_thread->h,
1017 current_thread->context.SegEs);
1018 puts_filtered ("Selector $ss\n");
1019 display_selector (current_thread->h,
1020 current_thread->context.SegSs);
1021 puts_filtered ("Selector $fs\n");
1022 display_selector (current_thread->h,
1023 current_thread->context.SegFs);
1024 puts_filtered ("Selector $gs\n");
1025 display_selector (current_thread->h,
1026 current_thread->context.SegGs);
1031 sel = parse_and_eval_long (args);
1032 printf_filtered ("Selector \"%s\"\n",args);
1033 display_selector (current_thread->h, sel);
1037 static struct cmd_list_element *info_w32_cmdlist = NULL;
1040 info_w32_command (char *args, int from_tty)
1042 help_list (info_w32_cmdlist, "info w32 ", class_info, gdb_stdout);
1046 #define DEBUG_EXCEPTION_SIMPLE(x) if (debug_exceptions) \
1047 printf_unfiltered ("gdb: Target exception %s at 0x%08lx\n", x, \
1048 (DWORD) current_event.u.Exception.ExceptionRecord.ExceptionAddress)
1051 handle_exception (struct target_waitstatus *ourstatus)
1054 DWORD code = current_event.u.Exception.ExceptionRecord.ExceptionCode;
1056 ourstatus->kind = TARGET_WAITKIND_STOPPED;
1058 /* Record the context of the current thread */
1059 th = thread_rec (current_event.dwThreadId, -1);
1063 case EXCEPTION_ACCESS_VIOLATION:
1064 DEBUG_EXCEPTION_SIMPLE ("EXCEPTION_ACCESS_VIOLATION");
1065 ourstatus->value.sig = TARGET_SIGNAL_SEGV;
1068 if (find_pc_partial_function ((CORE_ADDR) current_event.u.Exception
1069 .ExceptionRecord.ExceptionAddress,
1071 && strncmp (fn, "KERNEL32!IsBad", strlen ("KERNEL32!IsBad")) == 0)
1075 case STATUS_STACK_OVERFLOW:
1076 DEBUG_EXCEPTION_SIMPLE ("STATUS_STACK_OVERFLOW");
1077 ourstatus->value.sig = TARGET_SIGNAL_SEGV;
1079 case STATUS_FLOAT_DENORMAL_OPERAND:
1080 DEBUG_EXCEPTION_SIMPLE ("STATUS_FLOAT_DENORMAL_OPERAND");
1081 ourstatus->value.sig = TARGET_SIGNAL_FPE;
1083 case EXCEPTION_ARRAY_BOUNDS_EXCEEDED:
1084 DEBUG_EXCEPTION_SIMPLE ("EXCEPTION_ARRAY_BOUNDS_EXCEEDED");
1085 ourstatus->value.sig = TARGET_SIGNAL_FPE;
1087 case STATUS_FLOAT_INEXACT_RESULT:
1088 DEBUG_EXCEPTION_SIMPLE ("STATUS_FLOAT_INEXACT_RESULT");
1089 ourstatus->value.sig = TARGET_SIGNAL_FPE;
1091 case STATUS_FLOAT_INVALID_OPERATION:
1092 DEBUG_EXCEPTION_SIMPLE ("STATUS_FLOAT_INVALID_OPERATION");
1093 ourstatus->value.sig = TARGET_SIGNAL_FPE;
1095 case STATUS_FLOAT_OVERFLOW:
1096 DEBUG_EXCEPTION_SIMPLE ("STATUS_FLOAT_OVERFLOW");
1097 ourstatus->value.sig = TARGET_SIGNAL_FPE;
1099 case STATUS_FLOAT_STACK_CHECK:
1100 DEBUG_EXCEPTION_SIMPLE ("STATUS_FLOAT_STACK_CHECK");
1101 ourstatus->value.sig = TARGET_SIGNAL_FPE;
1103 case STATUS_FLOAT_UNDERFLOW:
1104 DEBUG_EXCEPTION_SIMPLE ("STATUS_FLOAT_UNDERFLOW");
1105 ourstatus->value.sig = TARGET_SIGNAL_FPE;
1107 case STATUS_FLOAT_DIVIDE_BY_ZERO:
1108 DEBUG_EXCEPTION_SIMPLE ("STATUS_FLOAT_DIVIDE_BY_ZERO");
1109 ourstatus->value.sig = TARGET_SIGNAL_FPE;
1111 case STATUS_INTEGER_DIVIDE_BY_ZERO:
1112 DEBUG_EXCEPTION_SIMPLE ("STATUS_INTEGER_DIVIDE_BY_ZERO");
1113 ourstatus->value.sig = TARGET_SIGNAL_FPE;
1115 case STATUS_INTEGER_OVERFLOW:
1116 DEBUG_EXCEPTION_SIMPLE ("STATUS_INTEGER_OVERFLOW");
1117 ourstatus->value.sig = TARGET_SIGNAL_FPE;
1119 case EXCEPTION_BREAKPOINT:
1120 DEBUG_EXCEPTION_SIMPLE ("EXCEPTION_BREAKPOINT");
1121 ourstatus->value.sig = TARGET_SIGNAL_TRAP;
1124 DEBUG_EXCEPTION_SIMPLE ("DBG_CONTROL_C");
1125 ourstatus->value.sig = TARGET_SIGNAL_INT;
1127 case DBG_CONTROL_BREAK:
1128 DEBUG_EXCEPTION_SIMPLE ("DBG_CONTROL_BREAK");
1129 ourstatus->value.sig = TARGET_SIGNAL_INT;
1131 case EXCEPTION_SINGLE_STEP:
1132 DEBUG_EXCEPTION_SIMPLE ("EXCEPTION_SINGLE_STEP");
1133 ourstatus->value.sig = TARGET_SIGNAL_TRAP;
1135 case EXCEPTION_ILLEGAL_INSTRUCTION:
1136 DEBUG_EXCEPTION_SIMPLE ("EXCEPTION_ILLEGAL_INSTRUCTION");
1137 ourstatus->value.sig = TARGET_SIGNAL_ILL;
1139 case EXCEPTION_PRIV_INSTRUCTION:
1140 DEBUG_EXCEPTION_SIMPLE ("EXCEPTION_PRIV_INSTRUCTION");
1141 ourstatus->value.sig = TARGET_SIGNAL_ILL;
1143 case EXCEPTION_NONCONTINUABLE_EXCEPTION:
1144 DEBUG_EXCEPTION_SIMPLE ("EXCEPTION_NONCONTINUABLE_EXCEPTION");
1145 ourstatus->value.sig = TARGET_SIGNAL_ILL;
1148 if (current_event.u.Exception.dwFirstChance)
1150 printf_unfiltered ("gdb: unknown target exception 0x%08lx at 0x%08lx\n",
1151 current_event.u.Exception.ExceptionRecord.ExceptionCode,
1152 (DWORD) current_event.u.Exception.ExceptionRecord.ExceptionAddress);
1153 ourstatus->value.sig = TARGET_SIGNAL_UNKNOWN;
1157 last_sig = ourstatus->value.sig;
1161 /* Resume all artificially suspended threads if we are continuing
1164 win32_continue (DWORD continue_status, int id)
1170 DEBUG_EVENTS (("ContinueDebugEvent (cpid=%ld, ctid=%ld, %s);\n",
1171 current_event.dwProcessId, current_event.dwThreadId,
1172 continue_status == DBG_CONTINUE ?
1173 "DBG_CONTINUE" : "DBG_EXCEPTION_NOT_HANDLED"));
1174 res = ContinueDebugEvent (current_event.dwProcessId,
1175 current_event.dwThreadId,
1177 continue_status = 0;
1179 for (th = &thread_head; (th = th->next) != NULL;)
1180 if (((id == -1) || (id == (int) th->id)) && th->suspend_count)
1183 for (i = 0; i < th->suspend_count; i++)
1184 (void) ResumeThread (th->h);
1185 th->suspend_count = 0;
1186 if (debug_registers_changed)
1188 /* Only change the value of the debug registers */
1189 th->context.ContextFlags = CONTEXT_DEBUG_REGISTERS;
1190 th->context.Dr0 = dr[0];
1191 th->context.Dr1 = dr[1];
1192 th->context.Dr2 = dr[2];
1193 th->context.Dr3 = dr[3];
1194 /* th->context.Dr6 = dr[6];
1195 FIXME: should we set dr6 also ?? */
1196 th->context.Dr7 = dr[7];
1197 CHECK (SetThreadContext (th->h, &th->context));
1198 th->context.ContextFlags = 0;
1202 debug_registers_changed = 0;
1206 /* Called in pathological case where Windows fails to send a
1207 CREATE_PROCESS_DEBUG_EVENT after an attach. */
1209 fake_create_process (void)
1211 current_process_handle = OpenProcess (PROCESS_ALL_ACCESS, FALSE,
1212 current_event.dwProcessId);
1213 main_thread_id = current_event.dwThreadId;
1214 current_thread = win32_add_thread (main_thread_id,
1215 current_event.u.CreateThread.hThread);
1216 return main_thread_id;
1219 /* Get the next event from the child. Return 1 if the event requires
1220 handling by WFI (or whatever).
1223 get_win32_debug_event (int pid, struct target_waitstatus *ourstatus)
1226 DWORD continue_status, event_code;
1228 static thread_info dummy_thread_info;
1231 last_sig = TARGET_SIGNAL_0;
1233 if (!(debug_event = WaitForDebugEvent (¤t_event, 1000)))
1237 continue_status = DBG_CONTINUE;
1239 event_code = current_event.dwDebugEventCode;
1240 ourstatus->kind = TARGET_WAITKIND_SPURIOUS;
1245 case CREATE_THREAD_DEBUG_EVENT:
1246 DEBUG_EVENTS (("gdb: kernel event for pid=%d tid=%x code=%s)\n",
1247 (unsigned) current_event.dwProcessId,
1248 (unsigned) current_event.dwThreadId,
1249 "CREATE_THREAD_DEBUG_EVENT"));
1250 if (saw_create != 1)
1252 if (!saw_create && attach_flag)
1254 /* Kludge around a Windows bug where first event is a create
1255 thread event. Caused when attached process does not have
1257 retval = ourstatus->value.related_pid = fake_create_process ();
1262 /* Record the existence of this thread */
1263 th = win32_add_thread (current_event.dwThreadId,
1264 current_event.u.CreateThread.hThread);
1266 printf_unfiltered ("[New %s]\n",
1268 pid_to_ptid (current_event.dwThreadId)));
1269 retval = current_event.dwThreadId;
1272 case EXIT_THREAD_DEBUG_EVENT:
1273 DEBUG_EVENTS (("gdb: kernel event for pid=%d tid=%d code=%s)\n",
1274 (unsigned) current_event.dwProcessId,
1275 (unsigned) current_event.dwThreadId,
1276 "EXIT_THREAD_DEBUG_EVENT"));
1277 if (current_event.dwThreadId != main_thread_id)
1279 win32_delete_thread (current_event.dwThreadId);
1280 th = &dummy_thread_info;
1284 case CREATE_PROCESS_DEBUG_EVENT:
1285 DEBUG_EVENTS (("gdb: kernel event for pid=%d tid=%d code=%s)\n",
1286 (unsigned) current_event.dwProcessId,
1287 (unsigned) current_event.dwThreadId,
1288 "CREATE_PROCESS_DEBUG_EVENT"));
1289 CloseHandle (current_event.u.CreateProcessInfo.hFile);
1290 if (++saw_create != 1)
1292 CloseHandle (current_event.u.CreateProcessInfo.hProcess);
1296 current_process_handle = current_event.u.CreateProcessInfo.hProcess;
1298 win32_delete_thread (main_thread_id);
1299 main_thread_id = current_event.dwThreadId;
1300 /* Add the main thread */
1301 th = win32_add_thread (main_thread_id,
1302 current_event.u.CreateProcessInfo.hThread);
1303 retval = ourstatus->value.related_pid = current_event.dwThreadId;
1306 case EXIT_PROCESS_DEBUG_EVENT:
1307 DEBUG_EVENTS (("gdb: kernel event for pid=%d tid=%d code=%s)\n",
1308 (unsigned) current_event.dwProcessId,
1309 (unsigned) current_event.dwThreadId,
1310 "EXIT_PROCESS_DEBUG_EVENT"));
1311 if (saw_create != 1)
1313 ourstatus->kind = TARGET_WAITKIND_EXITED;
1314 ourstatus->value.integer = current_event.u.ExitProcess.dwExitCode;
1315 CloseHandle (current_process_handle);
1316 retval = main_thread_id;
1319 case LOAD_DLL_DEBUG_EVENT:
1320 DEBUG_EVENTS (("gdb: kernel event for pid=%d tid=%d code=%s)\n",
1321 (unsigned) current_event.dwProcessId,
1322 (unsigned) current_event.dwThreadId,
1323 "LOAD_DLL_DEBUG_EVENT"));
1324 CloseHandle (current_event.u.LoadDll.hFile);
1325 if (saw_create != 1)
1327 catch_errors (handle_load_dll, NULL, (char *) "", RETURN_MASK_ALL);
1328 registers_changed (); /* mark all regs invalid */
1329 ourstatus->kind = TARGET_WAITKIND_LOADED;
1330 ourstatus->value.integer = 0;
1331 retval = main_thread_id;
1332 re_enable_breakpoints_in_shlibs ();
1335 case UNLOAD_DLL_DEBUG_EVENT:
1336 DEBUG_EVENTS (("gdb: kernel event for pid=%d tid=%d code=%s)\n",
1337 (unsigned) current_event.dwProcessId,
1338 (unsigned) current_event.dwThreadId,
1339 "UNLOAD_DLL_DEBUG_EVENT"));
1340 if (saw_create != 1)
1342 catch_errors (handle_unload_dll, NULL, (char *) "", RETURN_MASK_ALL);
1343 registers_changed (); /* mark all regs invalid */
1344 /* ourstatus->kind = TARGET_WAITKIND_UNLOADED;
1345 does not exist yet. */
1348 case EXCEPTION_DEBUG_EVENT:
1349 DEBUG_EVENTS (("gdb: kernel event for pid=%d tid=%d code=%s)\n",
1350 (unsigned) current_event.dwProcessId,
1351 (unsigned) current_event.dwThreadId,
1352 "EXCEPTION_DEBUG_EVENT"));
1353 if (saw_create != 1)
1355 if (handle_exception (ourstatus))
1356 retval = current_event.dwThreadId;
1358 continue_status = DBG_EXCEPTION_NOT_HANDLED;
1361 case OUTPUT_DEBUG_STRING_EVENT: /* message from the kernel */
1362 DEBUG_EVENTS (("gdb: kernel event for pid=%d tid=%d code=%s)\n",
1363 (unsigned) current_event.dwProcessId,
1364 (unsigned) current_event.dwThreadId,
1365 "OUTPUT_DEBUG_STRING_EVENT"));
1366 if (saw_create != 1)
1368 if (handle_output_debug_string (ourstatus))
1369 retval = main_thread_id;
1373 if (saw_create != 1)
1375 printf_unfiltered ("gdb: kernel event for pid=%ld tid=%ld\n",
1376 (DWORD) current_event.dwProcessId,
1377 (DWORD) current_event.dwThreadId);
1378 printf_unfiltered (" unknown event code %ld\n",
1379 current_event.dwDebugEventCode);
1383 if (!retval || saw_create != 1)
1384 CHECK (win32_continue (continue_status, -1));
1387 inferior_ptid = pid_to_ptid (retval);
1388 current_thread = th ?: thread_rec (current_event.dwThreadId, TRUE);
1395 /* Wait for interesting events to occur in the target process. */
1397 win32_wait (ptid_t ptid, struct target_waitstatus *ourstatus)
1399 int pid = PIDGET (ptid);
1401 /* We loop when we get a non-standard exception rather than return
1402 with a SPURIOUS because resume can try and step or modify things,
1403 which needs a current_thread->h. But some of these exceptions mark
1404 the birth or death of threads, which mean that the current thread
1405 isn't necessarily what you think it is. */
1409 int retval = get_win32_debug_event (pid, ourstatus);
1411 return pid_to_ptid (retval);
1416 if (deprecated_ui_loop_hook != NULL)
1417 detach = deprecated_ui_loop_hook (0);
1420 win32_kill_inferior ();
1426 do_initial_win32_stuff (DWORD pid)
1428 extern int stop_after_trap;
1431 last_sig = TARGET_SIGNAL_0;
1433 exception_count = 0;
1434 debug_registers_changed = 0;
1435 debug_registers_used = 0;
1436 for (i = 0; i < sizeof (dr) / sizeof (dr[0]); i++)
1438 current_event.dwProcessId = pid;
1439 memset (¤t_event, 0, sizeof (current_event));
1440 push_target (&win32_ops);
1441 disable_breakpoints_in_shlibs (1);
1442 win32_clear_solib ();
1443 clear_proceed_status ();
1444 init_wait_for_inferior ();
1446 target_terminal_init ();
1447 target_terminal_inferior ();
1451 stop_after_trap = 1;
1452 wait_for_inferior ();
1453 if (stop_signal != TARGET_SIGNAL_TRAP)
1454 resume (0, stop_signal);
1458 stop_after_trap = 0;
1462 /* Since Windows XP, detaching from a process is supported by Windows.
1463 The following code tries loading the appropriate functions dynamically.
1464 If loading these functions succeeds use them to actually detach from
1465 the inferior process, otherwise behave as usual, pretending that
1466 detach has worked. */
1467 static BOOL WINAPI (*DebugSetProcessKillOnExit)(BOOL);
1468 static BOOL WINAPI (*DebugActiveProcessStop)(DWORD);
1471 has_detach_ability (void)
1473 static HMODULE kernel32 = NULL;
1476 kernel32 = LoadLibrary ("kernel32.dll");
1479 if (!DebugSetProcessKillOnExit)
1480 DebugSetProcessKillOnExit = GetProcAddress (kernel32,
1481 "DebugSetProcessKillOnExit");
1482 if (!DebugActiveProcessStop)
1483 DebugActiveProcessStop = GetProcAddress (kernel32,
1484 "DebugActiveProcessStop");
1485 if (DebugSetProcessKillOnExit && DebugActiveProcessStop)
1491 /* Try to set or remove a user privilege to the current process. Return -1
1492 if that fails, the previous setting of that privilege otherwise.
1494 This code is copied from the Cygwin source code and rearranged to allow
1495 dynamically loading of the needed symbols from advapi32 which is only
1496 available on NT/2K/XP. */
1498 set_process_privilege (const char *privilege, BOOL enable)
1500 static HMODULE advapi32 = NULL;
1501 static BOOL WINAPI (*OpenProcessToken)(HANDLE, DWORD, PHANDLE);
1502 static BOOL WINAPI (*LookupPrivilegeValue)(LPCSTR, LPCSTR, PLUID);
1503 static BOOL WINAPI (*AdjustTokenPrivileges)(HANDLE, BOOL, PTOKEN_PRIVILEGES,
1504 DWORD, PTOKEN_PRIVILEGES, PDWORD);
1506 HANDLE token_hdl = NULL;
1508 TOKEN_PRIVILEGES new_priv, orig_priv;
1512 if (GetVersion () >= 0x80000000) /* No security availbale on 9x/Me */
1517 if (!(advapi32 = LoadLibrary ("advapi32.dll")))
1519 if (!OpenProcessToken)
1520 OpenProcessToken = GetProcAddress (advapi32, "OpenProcessToken");
1521 if (!LookupPrivilegeValue)
1522 LookupPrivilegeValue = GetProcAddress (advapi32,
1523 "LookupPrivilegeValueA");
1524 if (!AdjustTokenPrivileges)
1525 AdjustTokenPrivileges = GetProcAddress (advapi32,
1526 "AdjustTokenPrivileges");
1527 if (!OpenProcessToken || !LookupPrivilegeValue || !AdjustTokenPrivileges)
1534 if (!OpenProcessToken (GetCurrentProcess (),
1535 TOKEN_QUERY | TOKEN_ADJUST_PRIVILEGES,
1539 if (!LookupPrivilegeValue (NULL, privilege, &restore_priv))
1542 new_priv.PrivilegeCount = 1;
1543 new_priv.Privileges[0].Luid = restore_priv;
1544 new_priv.Privileges[0].Attributes = enable ? SE_PRIVILEGE_ENABLED : 0;
1546 if (!AdjustTokenPrivileges (token_hdl, FALSE, &new_priv,
1547 sizeof orig_priv, &orig_priv, &size))
1550 /* Disabled, otherwise every `attach' in an unprivileged user session
1551 would raise the "Failed to get SE_DEBUG_NAME privilege" warning in
1553 /* AdjustTokenPrivileges returns TRUE even if the privilege could not
1554 be enabled. GetLastError () returns an correct error code, though. */
1555 if (enable && GetLastError () == ERROR_NOT_ALL_ASSIGNED)
1559 ret = orig_priv.Privileges[0].Attributes == SE_PRIVILEGE_ENABLED ? 1 : 0;
1563 CloseHandle (token_hdl);
1568 /* Attach to process PID, then initialize for debugging it. */
1570 win32_attach (char *args, int from_tty)
1576 error_no_arg (_("process-id to attach"));
1578 if (set_process_privilege (SE_DEBUG_NAME, TRUE) < 0)
1580 printf_unfiltered ("Warning: Failed to get SE_DEBUG_NAME privilege\n");
1581 printf_unfiltered ("This can cause attach to fail on Windows NT/2K/XP\n");
1584 pid = strtoul (args, 0, 0); /* Windows pid */
1586 win32_init_thread_list ();
1587 ok = DebugActiveProcess (pid);
1592 /* Try fall back to Cygwin pid */
1593 pid = cygwin_internal (CW_CYGWIN_PID_TO_WINPID, pid);
1596 ok = DebugActiveProcess (pid);
1599 error (_("Can't attach to process."));
1602 if (has_detach_ability ())
1603 DebugSetProcessKillOnExit (FALSE);
1609 char *exec_file = (char *) get_exec_file (0);
1612 printf_unfiltered ("Attaching to program `%s', %s\n", exec_file,
1613 target_pid_to_str (pid_to_ptid (pid)));
1615 printf_unfiltered ("Attaching to %s\n",
1616 target_pid_to_str (pid_to_ptid (pid)));
1618 gdb_flush (gdb_stdout);
1621 do_initial_win32_stuff (pid);
1622 target_terminal_ours ();
1626 win32_detach (char *args, int from_tty)
1630 if (has_detach_ability ())
1632 delete_command (NULL, 0);
1633 win32_continue (DBG_CONTINUE, -1);
1634 if (!DebugActiveProcessStop (current_event.dwProcessId))
1636 error (_("Can't detach process %lu (error %lu)"),
1637 current_event.dwProcessId, GetLastError ());
1640 DebugSetProcessKillOnExit (FALSE);
1642 if (detached && from_tty)
1644 char *exec_file = get_exec_file (0);
1647 printf_unfiltered ("Detaching from program: %s, Pid %lu\n", exec_file,
1648 current_event.dwProcessId);
1649 gdb_flush (gdb_stdout);
1651 inferior_ptid = null_ptid;
1652 unpush_target (&win32_ops);
1656 win32_pid_to_exec_file (int pid)
1658 /* Try to find the process path using the Cygwin internal process list
1659 pid isn't a valid pid, unfortunately. Use current_event.dwProcessId
1661 /* TODO: Also find native Windows processes using CW_GETPINFO_FULL. */
1663 static char path[MAX_PATH + 1];
1664 char *path_ptr = NULL;
1666 struct external_pinfo *pinfo;
1668 cygwin_internal (CW_LOCK_PINFO, 1000);
1670 (pinfo = (struct external_pinfo *)
1671 cygwin_internal (CW_GETPINFO, cpid | CW_NEXTPID));
1674 if (pinfo->dwProcessId == current_event.dwProcessId) /* Got it */
1676 cygwin_conv_to_full_posix_path (pinfo->progname, path);
1681 cygwin_internal (CW_UNLOCK_PINFO);
1685 /* Print status information about what we're accessing. */
1688 win32_files_info (struct target_ops *ignore)
1690 printf_unfiltered ("\tUsing the running image of %s %s.\n",
1691 attach_flag ? "attached" : "child", target_pid_to_str (inferior_ptid));
1695 win32_open (char *arg, int from_tty)
1697 error (_("Use the \"run\" command to start a Unix child process."));
1700 /* Function called by qsort to sort environment strings. */
1702 env_sort (const void *a, const void *b)
1704 const char **p = (const char **) a;
1705 const char **q = (const char **) b;
1706 return strcasecmp (*p, *q);
1709 /* Start an inferior win32 child process and sets inferior_ptid to its pid.
1710 EXEC_FILE is the file to run.
1711 ALLARGS is a string containing the arguments to the program.
1712 ENV is the environment vector to pass. Errors reported with error(). */
1715 win32_create_inferior (char *exec_file, char *allargs, char **in_env,
1723 PROCESS_INFORMATION pi;
1727 char real_path[MAXPATHLEN];
1729 char shell[MAX_PATH + 1]; /* Path to shell */
1732 int ostdin, ostdout, ostderr;
1733 const char *inferior_io_terminal = get_inferior_io_terminal ();
1736 error (_("No executable specified, use `target exec'."));
1738 memset (&si, 0, sizeof (si));
1739 si.cb = sizeof (si);
1743 flags = DEBUG_ONLY_THIS_PROCESS;
1744 cygwin_conv_to_win32_path (exec_file, real_path);
1750 sh = getenv ("SHELL");
1753 cygwin_conv_to_win32_path (sh, shell);
1754 newallargs = alloca (sizeof (" -c 'exec '") + strlen (exec_file)
1755 + strlen (allargs) + 2);
1756 sprintf (newallargs, " -c 'exec %s %s'", exec_file, allargs);
1757 allargs = newallargs;
1759 flags = DEBUG_PROCESS;
1763 flags |= CREATE_NEW_PROCESS_GROUP;
1766 flags |= CREATE_NEW_CONSOLE;
1770 args = alloca (strlen (toexec) + strlen (allargs) + 2);
1771 strcpy (args, toexec);
1773 strcat (args, allargs);
1775 /* Prepare the environment vars for CreateProcess. */
1777 /* This code used to assume all env vars were file names and would
1778 translate them all to win32 style. That obviously doesn't work in the
1779 general case. The current rule is that we only translate PATH.
1780 We need to handle PATH because we're about to call CreateProcess and
1781 it uses PATH to find DLL's. Fortunately PATH has a well-defined value
1782 in both posix and win32 environments. cygwin.dll will change it back
1783 to posix style if necessary. */
1785 static const char *conv_path_names[] =
1791 /* CreateProcess takes the environment list as a null terminated set of
1792 strings (i.e. two nulls terminate the list). */
1794 /* Get total size for env strings. */
1795 for (envlen = 0, i = 0; in_env[i] && *in_env[i]; i++)
1799 for (j = 0; conv_path_names[j]; j++)
1801 len = strlen (conv_path_names[j]);
1802 if (strncmp (conv_path_names[j], in_env[i], len) == 0)
1804 if (cygwin_posix_path_list_p (in_env[i] + len))
1806 + cygwin_posix_to_win32_path_list_buf_size (in_env[i] + len);
1808 envlen += strlen (in_env[i]) + 1;
1812 if (conv_path_names[j] == NULL)
1813 envlen += strlen (in_env[i]) + 1;
1816 size_t envsize = sizeof (in_env[0]) * (i + 1);
1817 char **env = (char **) alloca (envsize);
1818 memcpy (env, in_env, envsize);
1819 /* Windows programs expect the environment block to be sorted. */
1820 qsort (env, i, sizeof (char *), env_sort);
1822 winenv = alloca (envlen + 1);
1824 /* Copy env strings into new buffer. */
1825 for (temp = winenv, i = 0; env[i] && *env[i]; i++)
1829 for (j = 0; conv_path_names[j]; j++)
1831 len = strlen (conv_path_names[j]);
1832 if (strncmp (conv_path_names[j], env[i], len) == 0)
1834 if (cygwin_posix_path_list_p (env[i] + len))
1836 memcpy (temp, env[i], len);
1837 cygwin_posix_to_win32_path_list (env[i] + len, temp + len);
1840 strcpy (temp, env[i]);
1844 if (conv_path_names[j] == NULL)
1845 strcpy (temp, env[i]);
1847 temp += strlen (temp) + 1;
1850 /* Final nil string to terminate new env. */
1854 if (!inferior_io_terminal)
1855 tty = ostdin = ostdout = ostderr = -1;
1858 tty = open (inferior_io_terminal, O_RDWR | O_NOCTTY);
1861 print_sys_errmsg (inferior_io_terminal, errno);
1862 ostdin = ostdout = ostderr = -1;
1875 win32_init_thread_list ();
1876 ret = CreateProcess (0,
1877 args, /* command line */
1878 NULL, /* Security */
1880 TRUE, /* inherit handles */
1881 flags, /* start flags */
1883 NULL, /* current directory */
1898 error (_("Error creating process %s, (error %d)."),
1899 exec_file, (unsigned) GetLastError ());
1901 CloseHandle (pi.hThread);
1902 CloseHandle (pi.hProcess);
1904 if (useshell && shell[0] != '\0')
1909 do_initial_win32_stuff (pi.dwProcessId);
1911 /* win32_continue (DBG_CONTINUE, -1); */
1912 proceed ((CORE_ADDR) - 1, TARGET_SIGNAL_0, 0);
1916 win32_mourn_inferior (void)
1918 (void) win32_continue (DBG_CONTINUE, -1);
1919 i386_cleanup_dregs();
1920 unpush_target (&win32_ops);
1921 generic_mourn_inferior ();
1924 /* Send a SIGINT to the process group. This acts just like the user typed a
1925 ^C on the controlling terminal. */
1930 DEBUG_EVENTS (("gdb: GenerateConsoleCtrlEvent (CTRLC_EVENT, 0)\n"));
1931 CHECK (GenerateConsoleCtrlEvent (CTRL_C_EVENT, current_event.dwProcessId));
1932 registers_changed (); /* refresh register state */
1936 win32_xfer_memory (CORE_ADDR memaddr, gdb_byte *our, int len,
1937 int write, struct mem_attrib *mem,
1938 struct target_ops *target)
1943 DEBUG_MEM (("gdb: write target memory, %d bytes at 0x%08lx\n",
1944 len, (DWORD) memaddr));
1945 if (!WriteProcessMemory (current_process_handle, (LPVOID) memaddr, our,
1948 FlushInstructionCache (current_process_handle, (LPCVOID) memaddr, len);
1952 DEBUG_MEM (("gdb: read target memory, %d bytes at 0x%08lx\n",
1953 len, (DWORD) memaddr));
1954 if (!ReadProcessMemory (current_process_handle, (LPCVOID) memaddr, our,
1962 win32_kill_inferior (void)
1964 CHECK (TerminateProcess (current_process_handle, 0));
1968 if (!win32_continue (DBG_CONTINUE, -1))
1970 if (!WaitForDebugEvent (¤t_event, INFINITE))
1972 if (current_event.dwDebugEventCode == EXIT_PROCESS_DEBUG_EVENT)
1976 CHECK (CloseHandle (current_process_handle));
1978 /* this may fail in an attached process so don't check. */
1979 if (current_thread && current_thread->h)
1980 (void) CloseHandle (current_thread->h);
1981 target_mourn_inferior (); /* or just win32_mourn_inferior? */
1985 win32_resume (ptid_t ptid, int step, enum target_signal sig)
1988 DWORD continue_status = DBG_CONTINUE;
1990 int pid = PIDGET (ptid);
1992 if (sig != TARGET_SIGNAL_0)
1994 if (current_event.dwDebugEventCode != EXCEPTION_DEBUG_EVENT)
1996 DEBUG_EXCEPT(("Cannot continue with signal %d here.\n",sig));
1998 else if (sig == last_sig)
1999 continue_status = DBG_EXCEPTION_NOT_HANDLED;
2002 /* This code does not seem to work, because
2003 the kernel does probably not consider changes in the ExceptionRecord
2004 structure when passing the exception to the inferior.
2005 Note that this seems possible in the exception handler itself. */
2008 for (i = 0; xlate[i].them != -1; i++)
2009 if (xlate[i].us == sig)
2011 current_event.u.Exception.ExceptionRecord.ExceptionCode =
2013 continue_status = DBG_EXCEPTION_NOT_HANDLED;
2016 if (continue_status == DBG_CONTINUE)
2018 DEBUG_EXCEPT(("Cannot continue with signal %d.\n",sig));
2022 DEBUG_EXCEPT(("Can only continue with recieved signal %d.\n",
2026 last_sig = TARGET_SIGNAL_0;
2028 DEBUG_EXEC (("gdb: win32_resume (pid=%d, step=%d, sig=%d);\n",
2031 /* Get context for currently selected thread */
2032 th = thread_rec (current_event.dwThreadId, FALSE);
2037 /* Single step by setting t bit */
2038 win32_fetch_inferior_registers (PS_REGNUM);
2039 th->context.EFlags |= FLAG_TRACE_BIT;
2042 if (th->context.ContextFlags)
2044 if (debug_registers_changed)
2046 th->context.Dr0 = dr[0];
2047 th->context.Dr1 = dr[1];
2048 th->context.Dr2 = dr[2];
2049 th->context.Dr3 = dr[3];
2050 /* th->context.Dr6 = dr[6];
2051 FIXME: should we set dr6 also ?? */
2052 th->context.Dr7 = dr[7];
2054 CHECK (SetThreadContext (th->h, &th->context));
2055 th->context.ContextFlags = 0;
2059 /* Allow continuing with the same signal that interrupted us.
2060 Otherwise complain. */
2062 win32_continue (continue_status, pid);
2066 win32_prepare_to_store (void)
2068 /* Do nothing, since we can store individual regs */
2072 win32_can_run (void)
2080 DEBUG_EVENTS (("gdb: win32_close, inferior_ptid=%d\n",
2081 PIDGET (inferior_ptid)));
2084 /* Convert pid to printable format. */
2086 cygwin_pid_to_str (ptid_t ptid)
2088 static char buf[80];
2089 int pid = PIDGET (ptid);
2091 if ((DWORD) pid == current_event.dwProcessId)
2092 sprintf (buf, "process %d", pid);
2094 sprintf (buf, "thread %ld.0x%x", current_event.dwProcessId, pid);
2100 struct target_ops *target;
2102 } map_code_section_args;
2105 map_single_dll_code_section (bfd *abfd, asection *sect, void *obj)
2109 struct section_table *new_target_sect_ptr;
2111 map_code_section_args *args = (map_code_section_args *) obj;
2112 struct target_ops *target = args->target;
2113 if (sect->flags & SEC_CODE)
2115 update_coreops = core_ops.to_sections == target->to_sections;
2117 if (target->to_sections)
2119 old = target->to_sections_end - target->to_sections;
2120 target->to_sections = (struct section_table *)
2121 xrealloc ((char *) target->to_sections,
2122 (sizeof (struct section_table)) * (1 + old));
2127 target->to_sections = (struct section_table *)
2128 xmalloc ((sizeof (struct section_table)));
2130 target->to_sections_end = target->to_sections + (1 + old);
2132 /* Update the to_sections field in the core_ops structure
2136 core_ops.to_sections = target->to_sections;
2137 core_ops.to_sections_end = target->to_sections_end;
2139 new_target_sect_ptr = target->to_sections + old;
2140 new_target_sect_ptr->addr = args->addr + bfd_section_vma (abfd, sect);
2141 new_target_sect_ptr->endaddr = args->addr + bfd_section_vma (abfd, sect) +
2142 bfd_section_size (abfd, sect);;
2143 new_target_sect_ptr->the_bfd_section = sect;
2144 new_target_sect_ptr->bfd = abfd;
2149 dll_code_sections_add (const char *dll_name, int base_addr, struct target_ops *target)
2152 map_code_section_args map_args;
2153 asection *lowest_sect;
2155 if (dll_name == NULL || target == NULL)
2157 name = xstrdup (dll_name);
2158 dll_bfd = bfd_openr (name, "pei-i386");
2159 if (dll_bfd == NULL)
2162 if (bfd_check_format (dll_bfd, bfd_object))
2164 lowest_sect = bfd_get_section_by_name (dll_bfd, ".text");
2165 if (lowest_sect == NULL)
2167 map_args.target = target;
2168 map_args.addr = base_addr - bfd_section_vma (dll_bfd, lowest_sect);
2170 bfd_map_over_sections (dll_bfd, &map_single_dll_code_section, (void *) (&map_args));
2177 core_section_load_dll_symbols (bfd *abfd, asection *sect, void *obj)
2179 struct target_ops *target = (struct target_ops *) obj;
2184 struct win32_pstatus *pstatus;
2189 struct objfile *objfile;
2190 const char *dll_basename;
2192 if (strncmp (sect->name, ".module", 7) != 0)
2195 buf = (char *) xmalloc (bfd_get_section_size (sect) + 1);
2198 printf_unfiltered ("memory allocation failed for %s\n", sect->name);
2201 if (!bfd_get_section_contents (abfd, sect, buf, 0, bfd_get_section_size (sect)))
2204 pstatus = (struct win32_pstatus *) buf;
2206 memmove (&base_addr, &(pstatus->data.module_info.base_address), sizeof (base_addr));
2207 dll_name_size = pstatus->data.module_info.module_name_size;
2208 if (offsetof (struct win32_pstatus, data.module_info.module_name) + dll_name_size > bfd_get_section_size (sect))
2211 dll_name = pstatus->data.module_info.module_name;
2213 if (!(dll_basename = strrchr (dll_name, '/')))
2214 dll_basename = dll_name;
2218 ALL_OBJFILES (objfile)
2220 char *objfile_basename = strrchr (objfile->name, '/');
2222 if (objfile_basename &&
2223 strcasecmp (dll_basename, objfile_basename + 1) == 0)
2227 base_addr += 0x1000;
2228 dll_name = register_loaded_dll (dll_name, base_addr, 1);
2230 if (!dll_code_sections_add (dll_name, (DWORD) base_addr, target))
2231 printf_unfiltered ("%s: Failed to map dll code sections.\n", dll_name);
2239 static struct so_list *
2240 win32_current_sos (void)
2242 struct so_list *sop;
2243 struct so_list *start = NULL;
2244 struct so_list *last = NULL;
2246 if (!solib_start.next && core_bfd)
2248 win32_clear_solib ();
2249 bfd_map_over_sections (core_bfd, &core_section_load_dll_symbols,
2253 for (sop = solib_start.next; sop; sop = sop->next)
2255 struct so_list *new = XZALLOC (struct so_list);
2256 strcpy (new->so_name, sop->so_name);
2257 strcpy (new->so_original_name, sop->so_original_name);
2271 fetch_elf_core_registers (char *core_reg_sect,
2272 unsigned core_reg_size,
2277 if (core_reg_size < sizeof (CONTEXT))
2279 error (_("Core file register section too small (%u bytes)."), core_reg_size);
2282 for (r = 0; r < NUM_REGS; r++)
2283 regcache_raw_supply (current_regcache, r, core_reg_sect + mappings[r]);
2287 init_win32_ops (void)
2289 win32_ops.to_shortname = "child";
2290 win32_ops.to_longname = "Win32 child process";
2291 win32_ops.to_doc = "Win32 child process (started by the \"run\" command).";
2292 win32_ops.to_open = win32_open;
2293 win32_ops.to_close = win32_close;
2294 win32_ops.to_attach = win32_attach;
2295 win32_ops.to_detach = win32_detach;
2296 win32_ops.to_resume = win32_resume;
2297 win32_ops.to_wait = win32_wait;
2298 win32_ops.to_fetch_registers = win32_fetch_inferior_registers;
2299 win32_ops.to_store_registers = win32_store_inferior_registers;
2300 win32_ops.to_prepare_to_store = win32_prepare_to_store;
2301 win32_ops.deprecated_xfer_memory = win32_xfer_memory;
2302 win32_ops.to_files_info = win32_files_info;
2303 win32_ops.to_insert_breakpoint = memory_insert_breakpoint;
2304 win32_ops.to_remove_breakpoint = memory_remove_breakpoint;
2305 win32_ops.to_terminal_init = terminal_init_inferior;
2306 win32_ops.to_terminal_inferior = terminal_inferior;
2307 win32_ops.to_terminal_ours_for_output = terminal_ours_for_output;
2308 win32_ops.to_terminal_ours = terminal_ours;
2309 win32_ops.to_terminal_save_ours = terminal_save_ours;
2310 win32_ops.to_terminal_info = child_terminal_info;
2311 win32_ops.to_kill = win32_kill_inferior;
2312 win32_ops.to_create_inferior = win32_create_inferior;
2313 win32_ops.to_mourn_inferior = win32_mourn_inferior;
2314 win32_ops.to_can_run = win32_can_run;
2315 win32_ops.to_thread_alive = win32_win32_thread_alive;
2316 win32_ops.to_pid_to_str = cygwin_pid_to_str;
2317 win32_ops.to_stop = win32_stop;
2318 win32_ops.to_stratum = process_stratum;
2319 win32_ops.to_has_all_memory = 1;
2320 win32_ops.to_has_memory = 1;
2321 win32_ops.to_has_stack = 1;
2322 win32_ops.to_has_registers = 1;
2323 win32_ops.to_has_execution = 1;
2324 win32_ops.to_magic = OPS_MAGIC;
2325 win32_ops.to_pid_to_exec_file = win32_pid_to_exec_file;
2327 win32_so_ops.relocate_section_addresses = win32_relocate_section_addresses;
2328 win32_so_ops.free_so = win32_free_so;
2329 win32_so_ops.clear_solib = win32_clear_solib;
2330 win32_so_ops.solib_create_inferior_hook = win32_solib_create_inferior_hook;
2331 win32_so_ops.special_symbol_handling = win32_special_symbol_handling;
2332 win32_so_ops.current_sos = win32_current_sos;
2333 win32_so_ops.open_symbol_file_object = NULL;
2334 win32_so_ops.in_dynsym_resolve_code = NULL;
2336 /* FIXME: Don't do this here. *_gdbarch_init() should set so_ops. */
2337 current_target_so_ops = &win32_so_ops;
2341 set_win32_aliases (char *argv0)
2343 add_info_alias ("dll", "sharedlibrary", 1);
2347 _initialize_win32_nat (void)
2349 struct cmd_list_element *c;
2353 c = add_com ("dll-symbols", class_files, dll_symbol_command,
2354 _("Load dll library symbols from FILE."));
2355 set_cmd_completer (c, filename_completer);
2357 add_com_alias ("sharedlibrary", "dll-symbols", class_alias, 1);
2359 add_setshow_boolean_cmd ("shell", class_support, &useshell, _("\
2360 Set use of shell to start subprocess."), _("\
2361 Show use of shell to start subprocess."), NULL,
2363 NULL, /* FIXME: i18n: */
2364 &setlist, &showlist);
2366 add_setshow_boolean_cmd ("new-console", class_support, &new_console, _("\
2367 Set creation of new console when creating child process."), _("\
2368 Show creation of new console when creating child process."), NULL,
2370 NULL, /* FIXME: i18n: */
2371 &setlist, &showlist);
2373 add_setshow_boolean_cmd ("new-group", class_support, &new_group, _("\
2374 Set creation of new group when creating child process."), _("\
2375 Show creation of new group when creating child process."), NULL,
2377 NULL, /* FIXME: i18n: */
2378 &setlist, &showlist);
2380 add_setshow_boolean_cmd ("debugexec", class_support, &debug_exec, _("\
2381 Set whether to display execution in child process."), _("\
2382 Show whether to display execution in child process."), NULL,
2384 NULL, /* FIXME: i18n: */
2385 &setlist, &showlist);
2387 add_setshow_boolean_cmd ("debugevents", class_support, &debug_events, _("\
2388 Set whether to display kernel events in child process."), _("\
2389 Show whether to display kernel events in child process."), NULL,
2391 NULL, /* FIXME: i18n: */
2392 &setlist, &showlist);
2394 add_setshow_boolean_cmd ("debugmemory", class_support, &debug_memory, _("\
2395 Set whether to display memory accesses in child process."), _("\
2396 Show whether to display memory accesses in child process."), NULL,
2398 NULL, /* FIXME: i18n: */
2399 &setlist, &showlist);
2401 add_setshow_boolean_cmd ("debugexceptions", class_support,
2402 &debug_exceptions, _("\
2403 Set whether to display kernel exceptions in child process."), _("\
2404 Show whether to display kernel exceptions in child process."), NULL,
2406 NULL, /* FIXME: i18n: */
2407 &setlist, &showlist);
2409 add_prefix_cmd ("w32", class_info, info_w32_command,
2410 _("Print information specific to Win32 debugging."),
2411 &info_w32_cmdlist, "info w32 ", 0, &infolist);
2413 add_cmd ("selector", class_info, display_selectors,
2414 _("Display selectors infos."),
2416 add_target (&win32_ops);
2417 deprecated_init_ui_hook = set_win32_aliases;
2420 /* Hardware watchpoint support, adapted from go32-nat.c code. */
2422 /* Pass the address ADDR to the inferior in the I'th debug register.
2423 Here we just store the address in dr array, the registers will be
2424 actually set up when win32_continue is called. */
2426 cygwin_set_dr (int i, CORE_ADDR addr)
2429 internal_error (__FILE__, __LINE__,
2430 _("Invalid register %d in cygwin_set_dr.\n"), i);
2431 dr[i] = (unsigned) addr;
2432 debug_registers_changed = 1;
2433 debug_registers_used = 1;
2436 /* Pass the value VAL to the inferior in the DR7 debug control
2437 register. Here we just store the address in D_REGS, the watchpoint
2438 will be actually set up in win32_wait. */
2440 cygwin_set_dr7 (unsigned val)
2443 debug_registers_changed = 1;
2444 debug_registers_used = 1;
2447 /* Get the value of the DR6 debug status register from the inferior.
2448 Here we just return the value stored in dr[6]
2449 by the last call to thread_rec for current_event.dwThreadId id. */
2451 cygwin_get_dr6 (void)
2456 /* Determine if the thread referenced by "pid" is alive
2457 by "polling" it. If WaitForSingleObject returns WAIT_OBJECT_0
2458 it means that the pid has died. Otherwise it is assumed to be alive. */
2460 win32_win32_thread_alive (ptid_t ptid)
2462 int pid = PIDGET (ptid);
2464 return WaitForSingleObject (thread_rec (pid, FALSE)->h, 0) == WAIT_OBJECT_0 ?
2468 static struct core_fns win32_elf_core_fns =
2470 bfd_target_elf_flavour,
2471 default_check_format,
2472 default_core_sniffer,
2473 fetch_elf_core_registers,
2478 _initialize_core_win32 (void)
2480 deprecated_add_core_fns (&win32_elf_core_fns);
2484 _initialize_check_for_gdb_ini (void)
2487 if (inhibit_gdbinit)
2490 homedir = getenv ("HOME");
2494 char *oldini = (char *) alloca (strlen (homedir) +
2495 sizeof ("/gdb.ini"));
2496 strcpy (oldini, homedir);
2497 p = strchr (oldini, '\0');
2498 if (p > oldini && p[-1] != '/')
2500 strcpy (p, "gdb.ini");
2501 if (access (oldini, 0) == 0)
2503 int len = strlen (oldini);
2504 char *newini = alloca (len + 1);
2505 sprintf (newini, "%.*s.gdbinit",
2506 (int) (len - (sizeof ("gdb.ini") - 1)), oldini);
2507 warning (_("obsolete '%s' found. Rename to '%s'."), oldini, newini);