Commit e712e077 authored by Alexandre Julliard's avatar Alexandre Julliard

Added debug events support.

parent 3e2be8d7
......@@ -48,6 +48,7 @@ struct new_process_request
{
int inherit; /* inherit flag */
int inherit_all; /* inherit all handles from parent */
int create_flags; /* creation flags */
int start_flags; /* flags from startup info */
int hstdin; /* handle for stdin */
int hstdout; /* handle for stdout */
......@@ -732,6 +733,119 @@ struct next_process_reply
};
/* Wait for a debug event */
struct wait_debug_event_request
{
int timeout; /* timeout in ms */
};
struct wait_debug_event_reply
{
int code; /* event code */
void* pid; /* process id */
void* tid; /* thread id */
/* followed by the event data (see below) */
};
/* Send a debug event */
struct send_debug_event_request
{
int code; /* event code */
/* followed by the event data (see below) */
};
struct send_debug_event_reply
{
int status; /* event continuation status */
};
/* definitions of the event data depending on the event code */
struct debug_event_exception
{
int code; /* exception code */
int flags; /* exception flags */
void *record; /* exception record ptr */
void *addr; /* exception address */
int nb_params; /* exceptions parameters */
int params[15];
int first_chance; /* first chance to handle it? */
};
struct debug_event_create_thread
{
int handle; /* handle to the new thread */
void *teb; /* thread teb (in debugged process address space) */
void *start; /* thread startup routine */
};
struct debug_event_create_process
{
int file; /* handle to the process exe file */
int process; /* handle to the new process */
int thread; /* handle to the new thread */
void *base; /* base of executable image */
int dbg_offset; /* offset of debug info in file */
int dbg_size; /* size of debug info */
void *teb; /* thread teb (in debugged process address space) */
void *start; /* thread startup routine */
void *name; /* image name (optional) */
int unicode; /* is it Unicode? */
};
struct debug_event_exit
{
int exit_code; /* thread or process exit code */
};
struct debug_event_load_dll
{
int handle; /* file handle for the dll */
void *base; /* base address of the dll */
int dbg_offset; /* offset of debug info in file */
int dbg_size; /* size of debug info */
void *name; /* image name (optional) */
int unicode; /* is it Unicode? */
};
struct debug_event_unload_dll
{
void *base; /* base address of the dll */
};
struct debug_event_output_string
{
void *string; /* string to display (in debugged process address space) */
int unicode; /* is it Unicode? */
int length; /* string length */
};
struct debug_event_rip_info
{
int error; /* ??? */
int type; /* ??? */
};
union debug_event_data
{
struct debug_event_exception exception;
struct debug_event_create_thread create_thread;
struct debug_event_create_process create_process;
struct debug_event_exit exit;
struct debug_event_load_dll load_dll;
struct debug_event_unload_dll unload_dll;
struct debug_event_output_string output_string;
struct debug_event_rip_info rip_info;
};
/* Continue a debug event */
struct continue_debug_event_request
{
void* pid; /* process id to continue */
void* tid; /* thread id to continue */
int status; /* continuation status */
};
/* Start debugging an existing process */
struct debug_process_request
{
void* pid; /* id of the process to debug */
};
/* requests definitions */
#include "server/request.h"
......@@ -740,14 +854,13 @@ struct next_process_reply
#ifndef __WINE_SERVER__
/* client communication functions */
extern void CLIENT_ProtocolError( const char *err, ... );
extern void CLIENT_SendRequest( enum request req, int pass_fd,
int n, ... /* arg_1, len_1, etc. */ );
extern unsigned int CLIENT_WaitReply( int *len, int *passed_fd,
int n, ... /* arg_1, len_1, etc. */ );
extern unsigned int CLIENT_WaitSimpleReply( void *reply, int len, int *passed_fd );
extern int CLIENT_InitServer(void);
struct _THDB;
extern int CLIENT_SetDebug( int level );
extern int CLIENT_DebuggerRequest( int op );
extern int CLIENT_InitThread(void);
......
......@@ -63,6 +63,10 @@ enum request
REQ_CREATE_DEVICE,
REQ_CREATE_SNAPSHOT,
REQ_NEXT_PROCESS,
REQ_WAIT_DEBUG_EVENT,
REQ_SEND_DEBUG_EVENT,
REQ_CONTINUE_DEBUG_EVENT,
REQ_DEBUG_PROCESS,
REQ_NB_REQUESTS
};
......@@ -126,6 +130,10 @@ DECL_HANDLER(get_mapping_info);
DECL_HANDLER(create_device);
DECL_HANDLER(create_snapshot);
DECL_HANDLER(next_process);
DECL_HANDLER(wait_debug_event);
DECL_HANDLER(send_debug_event);
DECL_HANDLER(continue_debug_event);
DECL_HANDLER(debug_process);
static const struct handler {
void (*handler)();
......@@ -189,6 +197,10 @@ static const struct handler {
{ (void(*)())req_create_device, sizeof(struct create_device_request) },
{ (void(*)())req_create_snapshot, sizeof(struct create_snapshot_request) },
{ (void(*)())req_next_process, sizeof(struct next_process_request) },
{ (void(*)())req_wait_debug_event, sizeof(struct wait_debug_event_request) },
{ (void(*)())req_send_debug_event, sizeof(struct send_debug_event_request) },
{ (void(*)())req_continue_debug_event, sizeof(struct continue_debug_event_request) },
{ (void(*)())req_debug_process, sizeof(struct debug_process_request) },
};
#endif /* WANT_REQUEST_HANDLERS */
......
......@@ -8,6 +8,7 @@ MODULE = server
C_SRCS = \
change.c \
console.c \
debugger.c \
device.c \
event.c \
file.c \
......
......@@ -153,6 +153,11 @@ extern void file_set_error(void);
extern int create_console( int fd, struct object *obj[2] );
/* debugger functions */
extern int debugger_attach( struct process *process, struct thread *debugger );
extern void debug_exit_thread( struct thread *thread, int exit_code );
extern int debug_level;
#endif /* __WINE_SERVER_OBJECT_H */
......@@ -109,12 +109,21 @@ static struct process *create_process( struct new_process_request *req )
return NULL;
}
init_process( process );
if (parent->console_in) process->console_in = grab_object( parent->console_in );
if (parent->console_out) process->console_out = grab_object( parent->console_out );
if (!(process->info = mem_alloc( sizeof(*process->info) ))) goto error;
memcpy( process->info, req, sizeof(*req) );
/* set the process console */
if (req->create_flags & CREATE_NEW_CONSOLE)
{
if (!alloc_console( process )) goto error;
}
else if (!(req->create_flags & DETACHED_PROCESS))
{
if (parent->console_in) process->console_in = grab_object( parent->console_in );
if (parent->console_out) process->console_out = grab_object( parent->console_out );
}
if (!req->inherit_all && !(req->start_flags & STARTF_USESTDHANDLES))
{
process->info->hstdin = duplicate_handle( parent, req->hstdin, process,
......@@ -125,6 +134,12 @@ static struct process *create_process( struct new_process_request *req )
0, TRUE, DUPLICATE_SAME_ACCESS );
}
/* attach to the debugger if requested */
if (req->create_flags & DEBUG_PROCESS)
debugger_attach( process, current );
else if (parent->debugger && !(req->create_flags & DEBUG_ONLY_THIS_PROCESS))
debugger_attach( process, parent->debugger );
process->next = first_process;
first_process->prev = process;
first_process = process;
......
......@@ -87,6 +87,7 @@ static void init_thread( struct thread *thread, int fd )
thread->mutex = NULL;
thread->debug_ctx = NULL;
thread->debug_first = NULL;
thread->debug_event = NULL;
thread->wait = NULL;
thread->apc = NULL;
thread->apc_count = 0;
......@@ -157,6 +158,7 @@ static void destroy_thread( struct object *obj )
struct thread *thread = (struct thread *)obj;
assert( obj->ops == &thread_ops );
assert( !thread->debug_ctx ); /* cannot still be debugging something */
release_object( thread->process );
if (thread->next) thread->next->prev = thread->prev;
if (thread->prev) thread->prev->next = thread->next;
......@@ -522,6 +524,7 @@ void thread_killed( struct thread *thread, int exit_code )
thread->state = TERMINATED;
thread->exit_code = exit_code;
if (thread->wait) end_wait( thread );
debug_exit_thread( thread, exit_code );
abandon_mutexes( thread );
remove_process_thread( thread->process, thread );
wake_up( &thread->obj, 0 );
......
......@@ -20,6 +20,7 @@ struct thread_wait;
struct thread_apc;
struct mutex;
struct debug_ctx;
struct debug_event;
enum run_state { STARTING, RUNNING, TERMINATED };
......@@ -34,6 +35,7 @@ struct thread
struct mutex *mutex; /* list of currently owned mutexes */
struct debug_ctx *debug_ctx; /* debugger context if this thread is a debugger */
struct process *debug_first; /* head of debugged processes list */
struct debug_event *debug_event; /* pending debug event for this thread */
struct thread_wait *wait; /* current wait condition if sleeping */
struct thread_apc *apc; /* list of async procedure calls */
int apc_count; /* number of outstanding APCs */
......
......@@ -10,6 +10,7 @@ static int dump_new_process_request( struct new_process_request *req, int len )
{
fprintf( stderr, " inherit=%d,", req->inherit );
fprintf( stderr, " inherit_all=%d,", req->inherit_all );
fprintf( stderr, " create_flags=%d,", req->create_flags );
fprintf( stderr, " start_flags=%d,", req->start_flags );
fprintf( stderr, " hstdin=%d,", req->hstdin );
fprintf( stderr, " hstdout=%d,", req->hstdout );
......@@ -682,6 +683,46 @@ static int dump_next_process_reply( struct next_process_reply *req, int len )
return (int)sizeof(*req);
}
static int dump_wait_debug_event_request( struct wait_debug_event_request *req, int len )
{
fprintf( stderr, " timeout=%d", req->timeout );
return (int)sizeof(*req);
}
static int dump_wait_debug_event_reply( struct wait_debug_event_reply *req, int len )
{
fprintf( stderr, " code=%d,", req->code );
fprintf( stderr, " pid=%p,", req->pid );
fprintf( stderr, " tid=%p", req->tid );
return (int)sizeof(*req);
}
static int dump_send_debug_event_request( struct send_debug_event_request *req, int len )
{
fprintf( stderr, " code=%d", req->code );
return (int)sizeof(*req);
}
static int dump_send_debug_event_reply( struct send_debug_event_reply *req, int len )
{
fprintf( stderr, " status=%d", req->status );
return (int)sizeof(*req);
}
static int dump_continue_debug_event_request( struct continue_debug_event_request *req, int len )
{
fprintf( stderr, " pid=%p,", req->pid );
fprintf( stderr, " tid=%p,", req->tid );
fprintf( stderr, " status=%d", req->status );
return (int)sizeof(*req);
}
static int dump_debug_process_request( struct debug_process_request *req, int len )
{
fprintf( stderr, " pid=%p", req->pid );
return (int)sizeof(*req);
}
struct dumper
{
int (*dump_req)( void *data, int len );
......@@ -806,6 +847,14 @@ static const struct dumper dumpers[REQ_NB_REQUESTS] =
(void(*)())dump_create_snapshot_reply },
{ (int(*)(void *,int))dump_next_process_request,
(void(*)())dump_next_process_reply },
{ (int(*)(void *,int))dump_wait_debug_event_request,
(void(*)())dump_wait_debug_event_reply },
{ (int(*)(void *,int))dump_send_debug_event_request,
(void(*)())dump_send_debug_event_reply },
{ (int(*)(void *,int))dump_continue_debug_event_request,
(void(*)())0 },
{ (int(*)(void *,int))dump_debug_process_request,
(void(*)())0 },
};
static const char * const req_names[REQ_NB_REQUESTS] =
......@@ -868,6 +917,10 @@ static const char * const req_names[REQ_NB_REQUESTS] =
"create_device",
"create_snapshot",
"next_process",
"wait_debug_event",
"send_debug_event",
"continue_debug_event",
"debug_process",
};
void trace_request( enum request req, void *data, int len, int fd )
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment