(win32_init_thread_list): Remove call to CloseHandle for thread.
(win32_delete_thread): Ditto.
(fake_create_process): Set open_process_used if OpenProcess call is successful.
(get_win32_debug_event): Do not close process handle.
(do_initial_win32_stuff): Set open_process_used to zero.
(win32_mourn_inferior): Call CloseHandle for current_process_handle if
open_process_used is set.
(win32_kill_inferior): Do not close process and main_thread handles.
+2007-12-02 Pierre Muller <muller@ics.u-strasbg.fr>
+
+ *win32-nat.c (open_process_used): New static variable.
+ (win32_init_thread_list): Remove call to CloseHandle for thread.
+ (win32_delete_thread): Ditto.
+ (fake_create_process): Set open_process_used if OpenProcess call is
+ successful.
+ (get_win32_debug_event): Do not close process handle.
+ (do_initial_win32_stuff): Set open_process_used to zero.
+ (win32_mourn_inferior): Call CloseHandle for current_process_handle if
+ open_process_used is set.
+ (win32_kill_inferior): Do not close process and main_thread handles.
+
2007-11-30 Daniel Jacobowitz <dan@codesourcery.com>
* remote.c (remote_cmdlist): New variable.
static int exception_count = 0;
static int event_count = 0;
static int saw_create;
+static int open_process_used = 0;
/* User options. */
static int new_console = 0;
{
thread_info *here = th->next;
th->next = here->next;
- (void) CloseHandle (here->h);
xfree (here);
}
thread_head.next = NULL;
{
thread_info *here = th->next;
th->next = here->next;
- CloseHandle (here->h);
xfree (here);
}
}
{
current_process_handle = OpenProcess (PROCESS_ALL_ACCESS, FALSE,
current_event.dwProcessId);
+ if (current_process_handle != NULL)
+ open_process_used = 1;
+ else
+ {
+ error (_("OpenProcess call failed, GetLastError = %lud\n"),
+ GetLastError ());
+ /* We can not debug anything in that case. */
+ }
main_thread_id = current_event.dwThreadId;
current_thread = win32_add_thread (main_thread_id,
current_event.u.CreateThread.hThread);
thread event. Caused when attached process does not have
a main thread. */
retval = ourstatus->value.related_pid = fake_create_process ();
- saw_create++;
+ if (retval)
+ saw_create++;
}
break;
}
"CREATE_PROCESS_DEBUG_EVENT"));
CloseHandle (current_event.u.CreateProcessInfo.hFile);
if (++saw_create != 1)
- {
- CloseHandle (current_event.u.CreateProcessInfo.hProcess);
- break;
- }
+ break;
current_process_handle = current_event.u.CreateProcessInfo.hProcess;
if (main_thread_id)
break;
ourstatus->kind = TARGET_WAITKIND_EXITED;
ourstatus->value.integer = current_event.u.ExitProcess.dwExitCode;
- CloseHandle (current_process_handle);
retval = main_thread_id;
break;
last_sig = TARGET_SIGNAL_0;
event_count = 0;
exception_count = 0;
+ open_process_used = 0;
debug_registers_changed = 0;
debug_registers_used = 0;
for (i = 0; i < sizeof (dr) / sizeof (dr[0]); i++)
error (_("Error creating process %s, (error %d)."),
exec_file, (unsigned) GetLastError ());
- CloseHandle (pi.hThread);
- CloseHandle (pi.hProcess);
-
if (useshell && shell[0] != '\0')
saw_create = -1;
else
{
(void) win32_continue (DBG_CONTINUE, -1);
i386_cleanup_dregs();
+ if (open_process_used)
+ {
+ CHECK (CloseHandle (current_process_handle));
+ open_process_used = 0;
+ }
unpush_target (&win32_ops);
generic_mourn_inferior ();
}
break;
}
- CHECK (CloseHandle (current_process_handle));
-
- /* this may fail in an attached process so don't check. */
- if (current_thread && current_thread->h)
- (void) CloseHandle (current_thread->h);
target_mourn_inferior (); /* or just win32_mourn_inferior? */
}
static int exception_count = 0;
static int event_count = 0;
static int saw_create;
+static int open_process_used = 0;
/* User options. */
static int new_console = 0;
{
thread_info *here = th->next;
th->next = here->next;
- (void) CloseHandle (here->h);
xfree (here);
}
thread_head.next = NULL;
{
thread_info *here = th->next;
th->next = here->next;
- CloseHandle (here->h);
xfree (here);
}
}
{
current_process_handle = OpenProcess (PROCESS_ALL_ACCESS, FALSE,
current_event.dwProcessId);
+ if (current_process_handle != NULL)
+ open_process_used = 1;
+ else
+ {
+ error (_("OpenProcess call failed, GetLastError = %lud\n"),
+ GetLastError ());
+ /* We can not debug anything in that case. */
+ }
main_thread_id = current_event.dwThreadId;
current_thread = win32_add_thread (main_thread_id,
current_event.u.CreateThread.hThread);
thread event. Caused when attached process does not have
a main thread. */
retval = ourstatus->value.related_pid = fake_create_process ();
- saw_create++;
+ if (retval)
+ saw_create++;
}
break;
}
"CREATE_PROCESS_DEBUG_EVENT"));
CloseHandle (current_event.u.CreateProcessInfo.hFile);
if (++saw_create != 1)
- {
- CloseHandle (current_event.u.CreateProcessInfo.hProcess);
- break;
- }
+ break;
current_process_handle = current_event.u.CreateProcessInfo.hProcess;
if (main_thread_id)
break;
ourstatus->kind = TARGET_WAITKIND_EXITED;
ourstatus->value.integer = current_event.u.ExitProcess.dwExitCode;
- CloseHandle (current_process_handle);
retval = main_thread_id;
break;
last_sig = TARGET_SIGNAL_0;
event_count = 0;
exception_count = 0;
+ open_process_used = 0;
debug_registers_changed = 0;
debug_registers_used = 0;
for (i = 0; i < sizeof (dr) / sizeof (dr[0]); i++)
error (_("Error creating process %s, (error %d)."),
exec_file, (unsigned) GetLastError ());
- CloseHandle (pi.hThread);
- CloseHandle (pi.hProcess);
-
if (useshell && shell[0] != '\0')
saw_create = -1;
else
{
(void) win32_continue (DBG_CONTINUE, -1);
i386_cleanup_dregs();
+ if (open_process_used)
+ {
+ CHECK (CloseHandle (current_process_handle));
+ open_process_used = 0;
+ }
unpush_target (&win32_ops);
generic_mourn_inferior ();
}
break;
}
- CHECK (CloseHandle (current_process_handle));
-
- /* this may fail in an attached process so don't check. */
- if (current_thread && current_thread->h)
- (void) CloseHandle (current_thread->h);
target_mourn_inferior (); /* or just win32_mourn_inferior? */
}