server: Removed the thread attached flag, since we always detach now.

This commit is contained in:
Alexandre Julliard 2006-04-10 20:25:22 +02:00
parent 5cc97c4e0b
commit 820c5927c8
4 changed files with 5 additions and 66 deletions

View File

@ -428,7 +428,7 @@ static int debugger_attach( struct process *process, struct thread *debugger )
goto error;
suspend_process( process );
if (!attach_process( process ) || !set_process_debugger( process, debugger ))
if (!set_process_debugger( process, debugger ))
{
resume_process( process );
return 0;
@ -485,7 +485,6 @@ int debugger_detach( struct process *process, struct thread *debugger )
/* remove relationships between process and its debugger */
process->debugger = NULL;
if (!set_process_debug_flag( process, 0 )) clear_error(); /* ignore error */
detach_process( process );
/* from this function */
resume_process( process );

View File

@ -90,7 +90,6 @@ static int handle_child_status( struct thread *thread, int pid, int status, int
}
if (thread && (WIFSIGNALED(status) || WIFEXITED(status)))
{
thread->attached = 0;
thread->unix_pid = -1;
thread->unix_tid = -1;
if (debug_level)
@ -155,7 +154,6 @@ static int wait4_thread( struct thread *thread, int signal )
{
thread->unix_pid = -1;
thread->unix_tid = -1;
thread->attached = 0;
}
else perror( "wait4" );
stop_watchdog();
@ -193,52 +191,11 @@ int send_thread_signal( struct thread *thread, int sig )
{
thread->unix_pid = -1;
thread->unix_tid = -1;
thread->attached = 0;
}
}
return (ret != -1);
}
/* attach to a Unix process with ptrace */
int attach_process( struct process *process )
{
struct thread *thread;
int ret = 1;
if (list_empty( &process->thread_list )) /* need at least one running thread */
{
set_error( STATUS_ACCESS_DENIED );
return 0;
}
LIST_FOR_EACH_ENTRY( thread, &process->thread_list, struct thread, proc_entry )
{
if (thread->attached) continue;
if (suspend_for_ptrace( thread )) resume_after_ptrace( thread );
else ret = 0;
}
return ret;
}
/* detach from a ptraced Unix process */
void detach_process( struct process *process )
{
struct thread *thread;
LIST_FOR_EACH_ENTRY( thread, &process->thread_list, struct thread, proc_entry )
{
if (thread->attached)
{
/* make sure it is stopped */
suspend_for_ptrace( thread );
if (thread->unix_pid == -1) return;
if (debug_level) fprintf( stderr, "%04x: *detached*\n", thread->id );
ptrace( PTRACE_DETACH, get_ptrace_pid(thread), (caddr_t)1, 0 );
thread->attached = 0;
}
}
}
/* suspend a thread to allow using ptrace on it */
/* you must do a resume_after_ptrace when finished with the thread */
int suspend_for_ptrace( struct thread *thread )
@ -246,21 +203,11 @@ int suspend_for_ptrace( struct thread *thread )
/* can't stop a thread while initialisation is in progress */
if (thread->unix_pid == -1 || !is_process_init_done(thread->process)) goto error;
if (thread->attached)
/* this may fail if the client is already being debugged */
if (ptrace( PTRACE_ATTACH, get_ptrace_pid(thread), 0, 0 ) == -1)
{
if (!send_thread_signal( thread, SIGSTOP )) goto error;
}
else
{
/* this may fail if the client is already being debugged */
if (!use_ptrace) goto error;
if (ptrace( PTRACE_ATTACH, get_ptrace_pid(thread), 0, 0 ) == -1)
{
if (errno == ESRCH) thread->unix_pid = thread->unix_tid = -1; /* thread got killed */
goto error;
}
if (debug_level) fprintf( stderr, "%04x: *attached*\n", thread->id );
thread->attached = 1;
if (errno == ESRCH) thread->unix_pid = thread->unix_tid = -1; /* thread got killed */
goto error;
}
if (wait4_thread( thread, SIGSTOP )) return 1;
resume_after_ptrace( thread );
@ -273,13 +220,10 @@ int suspend_for_ptrace( struct thread *thread )
void resume_after_ptrace( struct thread *thread )
{
if (thread->unix_pid == -1) return;
assert( thread->attached );
if (ptrace( PTRACE_DETACH, get_ptrace_pid(thread), (caddr_t)1, 0 ) == -1)
{
if (errno == ESRCH) thread->unix_pid = thread->unix_tid = -1; /* thread got killed */
}
if (debug_level) fprintf( stderr, "%04x: *detached*\n", thread->id );
thread->attached = 0;
}
/* read an int from a thread address space */

View File

@ -139,7 +139,6 @@ inline static void init_thread_structure( struct thread *thread )
thread->reply_fd = NULL;
thread->wait_fd = NULL;
thread->state = RUNNING;
thread->attached = 0;
thread->exit_code = 0;
thread->priority = THREAD_PRIORITY_NORMAL;
thread->affinity = 1;

View File

@ -72,7 +72,6 @@ struct thread
struct fd *reply_fd; /* fd to send a reply to a client */
struct fd *wait_fd; /* fd to use to wake a sleeping client */
enum run_state state; /* running state */
int attached; /* is thread attached with ptrace? */
int exit_code; /* thread exit code */
int unix_pid; /* Unix pid of client */
int unix_tid; /* Unix tid of client */
@ -122,8 +121,6 @@ extern struct token *thread_get_impersonation_token( struct thread *thread );
extern void sigchld_callback(void);
extern int get_ptrace_pid( struct thread *thread );
extern int attach_process( struct process *process );
extern void detach_process( struct process *process );
extern int suspend_for_ptrace( struct thread *thread );
extern void resume_after_ptrace( struct thread *thread );
extern void *get_thread_ip( struct thread *thread );