server: Don't round up the header size for image mappings.
[wine] / server / debugger.c
1 /*
2  * Server-side debugger functions
3  *
4  * Copyright (C) 1999 Alexandre Julliard
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
20
21 #include "config.h"
22 #include "wine/port.h"
23
24 #include <assert.h>
25 #include <signal.h>
26 #include <string.h>
27 #include <stdarg.h>
28 #include <stdio.h>
29
30 #include "ntstatus.h"
31 #define WIN32_NO_STATUS
32 #include "windef.h"
33 #include "winternl.h"
34
35 #include "handle.h"
36 #include "process.h"
37 #include "thread.h"
38 #include "request.h"
39 #include "console.h"
40
41 enum debug_event_state { EVENT_QUEUED, EVENT_SENT, EVENT_CONTINUED };
42
43 /* debug event */
44 struct debug_event
45 {
46     struct object          obj;       /* object header */
47     struct list            entry;     /* entry in event queue */
48     struct thread         *sender;    /* thread which sent this event */
49     struct thread         *debugger;  /* debugger thread receiving the event */
50     enum debug_event_state state;     /* event state */
51     int                    status;    /* continuation status */
52     debug_event_t          data;      /* event data */
53     CONTEXT                context;   /* register context */
54 };
55
56 /* debug context */
57 struct debug_ctx
58 {
59     struct object        obj;         /* object header */
60     struct list          event_queue; /* pending events queue */
61     int                  kill_on_exit;/* kill debuggees on debugger exit ? */
62 };
63
64
65 static void debug_event_dump( struct object *obj, int verbose );
66 static int debug_event_signaled( struct object *obj, struct thread *thread );
67 static void debug_event_destroy( struct object *obj );
68
69 static const struct object_ops debug_event_ops =
70 {
71     sizeof(struct debug_event),    /* size */
72     debug_event_dump,              /* dump */
73     add_queue,                     /* add_queue */
74     remove_queue,                  /* remove_queue */
75     debug_event_signaled,          /* signaled */
76     no_satisfied,                  /* satisfied */
77     no_signal,                     /* signal */
78     no_get_fd,                     /* get_fd */
79     no_map_access,                 /* map_access */
80     no_lookup_name,                /* lookup_name */
81     no_close_handle,               /* close_handle */
82     debug_event_destroy            /* destroy */
83 };
84
85 static void debug_ctx_dump( struct object *obj, int verbose );
86 static int debug_ctx_signaled( struct object *obj, struct thread *thread );
87 static void debug_ctx_destroy( struct object *obj );
88
89 static const struct object_ops debug_ctx_ops =
90 {
91     sizeof(struct debug_ctx),      /* size */
92     debug_ctx_dump,                /* dump */
93     add_queue,                     /* add_queue */
94     remove_queue,                  /* remove_queue */
95     debug_ctx_signaled,            /* signaled */
96     no_satisfied,                  /* satisfied */
97     no_signal,                     /* signal */
98     no_get_fd,                     /* get_fd */
99     no_map_access,                 /* map_access */
100     no_lookup_name,                /* lookup_name */
101     no_close_handle,               /* close_handle */
102     debug_ctx_destroy              /* destroy */
103 };
104
105
106 /* routines to build an event according to its type */
107
108 static int fill_exception_event( struct debug_event *event, void *arg )
109 {
110     memcpy( &event->data.info.exception, arg, sizeof(event->data.info.exception) );
111     return 1;
112 }
113
114 static int fill_create_thread_event( struct debug_event *event, void *arg )
115 {
116     struct process *debugger = event->debugger->process;
117     struct thread *thread = event->sender;
118     obj_handle_t handle;
119
120     /* documented: THREAD_GET_CONTEXT | THREAD_SET_CONTEXT | THREAD_SUSPEND_RESUME */
121     if (!(handle = alloc_handle( debugger, thread, THREAD_ALL_ACCESS, 0 ))) return 0;
122     event->data.info.create_thread.handle = handle;
123     event->data.info.create_thread.teb    = thread->teb;
124     event->data.info.create_thread.start  = arg;
125     return 1;
126 }
127
128 static int fill_create_process_event( struct debug_event *event, void *arg )
129 {
130     struct process *debugger = event->debugger->process;
131     struct thread *thread = event->sender;
132     struct process *process = thread->process;
133     obj_handle_t handle;
134
135     /* documented: PROCESS_VM_READ | PROCESS_VM_WRITE */
136     if (!(handle = alloc_handle( debugger, process, PROCESS_ALL_ACCESS, 0 ))) return 0;
137     event->data.info.create_process.process = handle;
138
139     /* documented: THREAD_GET_CONTEXT | THREAD_SET_CONTEXT | THREAD_SUSPEND_RESUME */
140     if (!(handle = alloc_handle( debugger, thread, THREAD_ALL_ACCESS, 0 )))
141     {
142         close_handle( debugger, event->data.info.create_process.process, NULL );
143         return 0;
144     }
145     event->data.info.create_process.thread = handle;
146
147     handle = 0;
148     if (process->exe.file &&
149         /* the doc says write access too, but this doesn't seem a good idea */
150         !(handle = alloc_handle( debugger, process->exe.file, GENERIC_READ, 0 )))
151     {
152         close_handle( debugger, event->data.info.create_process.process, NULL );
153         close_handle( debugger, event->data.info.create_process.thread, NULL );
154         return 0;
155     }
156     event->data.info.create_process.file       = handle;
157     event->data.info.create_process.teb        = thread->teb;
158     event->data.info.create_process.base       = process->exe.base;
159     event->data.info.create_process.start      = arg;
160     event->data.info.create_process.dbg_offset = process->exe.dbg_offset;
161     event->data.info.create_process.dbg_size   = process->exe.dbg_size;
162     event->data.info.create_process.name       = process->exe.name;
163     event->data.info.create_process.unicode    = 1;
164     return 1;
165 }
166
167 static int fill_exit_thread_event( struct debug_event *event, void *arg )
168 {
169     struct thread *thread = arg;
170     event->data.info.exit.exit_code = thread->exit_code;
171     return 1;
172 }
173
174 static int fill_exit_process_event( struct debug_event *event, void *arg )
175 {
176     struct process *process = arg;
177     event->data.info.exit.exit_code = process->exit_code;
178     return 1;
179 }
180
181 static int fill_load_dll_event( struct debug_event *event, void *arg )
182 {
183     struct process *debugger = event->debugger->process;
184     struct process_dll *dll = arg;
185     obj_handle_t handle = 0;
186
187     if (dll->file && !(handle = alloc_handle( debugger, dll->file, GENERIC_READ, 0 )))
188         return 0;
189     event->data.info.load_dll.handle     = handle;
190     event->data.info.load_dll.base       = dll->base;
191     event->data.info.load_dll.dbg_offset = dll->dbg_offset;
192     event->data.info.load_dll.dbg_size   = dll->dbg_size;
193     event->data.info.load_dll.name       = dll->name;
194     event->data.info.load_dll.unicode    = 1;
195     return 1;
196 }
197
198 static int fill_unload_dll_event( struct debug_event *event, void *arg )
199 {
200     event->data.info.unload_dll.base = arg;
201     return 1;
202 }
203
204 static int fill_output_debug_string_event( struct debug_event *event, void *arg )
205 {
206     struct debug_event_output_string *data = arg;
207     event->data.info.output_string = *data;
208     return 1;
209 }
210
211 typedef int (*fill_event_func)( struct debug_event *event, void *arg );
212
213 #define NB_DEBUG_EVENTS OUTPUT_DEBUG_STRING_EVENT  /* RIP_EVENT not supported */
214
215 static const fill_event_func fill_debug_event[NB_DEBUG_EVENTS] =
216 {
217     fill_exception_event,            /* EXCEPTION_DEBUG_EVENT */
218     fill_create_thread_event,        /* CREATE_THREAD_DEBUG_EVENT */
219     fill_create_process_event,       /* CREATE_PROCESS_DEBUG_EVENT */
220     fill_exit_thread_event,          /* EXIT_THREAD_DEBUG_EVENT */
221     fill_exit_process_event,         /* EXIT_PROCESS_DEBUG_EVENT */
222     fill_load_dll_event,             /* LOAD_DLL_DEBUG_EVENT */
223     fill_unload_dll_event,           /* UNLOAD_DLL_DEBUG_EVENT */
224     fill_output_debug_string_event   /* OUTPUT_DEBUG_STRING_EVENT */
225 };
226
227
228 /* unlink the first event from the queue */
229 static void unlink_event( struct debug_ctx *debug_ctx, struct debug_event *event )
230 {
231     list_remove( &event->entry );
232     if (event->sender->debug_event == event) event->sender->debug_event = NULL;
233     release_object( event );
234 }
235
236 /* link an event at the end of the queue */
237 static void link_event( struct debug_event *event )
238 {
239     struct debug_ctx *debug_ctx = event->debugger->debug_ctx;
240
241     assert( debug_ctx );
242     grab_object( event );
243     list_add_tail( &debug_ctx->event_queue, &event->entry );
244     if (!event->sender->debug_event) wake_up( &debug_ctx->obj, 0 );
245 }
246
247 /* find the next event that we can send to the debugger */
248 static struct debug_event *find_event_to_send( struct debug_ctx *debug_ctx )
249 {
250     struct debug_event *event;
251
252     LIST_FOR_EACH_ENTRY( event, &debug_ctx->event_queue, struct debug_event, entry )
253     {
254         if (event->state == EVENT_SENT) continue;  /* already sent */
255         if (event->sender->debug_event) continue;  /* thread busy with another one */
256         return event;
257     }
258     return NULL;
259 }
260
261 static void debug_event_dump( struct object *obj, int verbose )
262 {
263     struct debug_event *debug_event = (struct debug_event *)obj;
264     assert( obj->ops == &debug_event_ops );
265     fprintf( stderr, "Debug event sender=%p code=%d state=%d\n",
266              debug_event->sender, debug_event->data.code, debug_event->state );
267 }
268
269 static int debug_event_signaled( struct object *obj, struct thread *thread )
270 {
271     struct debug_event *debug_event = (struct debug_event *)obj;
272     assert( obj->ops == &debug_event_ops );
273     return debug_event->state == EVENT_CONTINUED;
274 }
275
276 static void debug_event_destroy( struct object *obj )
277 {
278     struct debug_event *event = (struct debug_event *)obj;
279     assert( obj->ops == &debug_event_ops );
280
281     /* If the event has been sent already, the handles are now under the */
282     /* responsibility of the debugger process, so we don't touch them    */
283     if (event->state == EVENT_QUEUED)
284     {
285         struct process *debugger = event->debugger->process;
286         switch(event->data.code)
287         {
288         case CREATE_THREAD_DEBUG_EVENT:
289             close_handle( debugger, event->data.info.create_thread.handle, NULL );
290             break;
291         case CREATE_PROCESS_DEBUG_EVENT:
292             if (event->data.info.create_process.file)
293                 close_handle( debugger, event->data.info.create_process.file, NULL );
294             close_handle( debugger, event->data.info.create_process.thread, NULL );
295             close_handle( debugger, event->data.info.create_process.process, NULL );
296             break;
297         case LOAD_DLL_DEBUG_EVENT:
298             if (event->data.info.load_dll.handle)
299                 close_handle( debugger, event->data.info.load_dll.handle, NULL );
300             break;
301         }
302     }
303     if (event->sender->context == &event->context) event->sender->context = NULL;
304     release_object( event->sender );
305     release_object( event->debugger );
306 }
307
308 static void debug_ctx_dump( struct object *obj, int verbose )
309 {
310     struct debug_ctx *debug_ctx = (struct debug_ctx *)obj;
311     assert( obj->ops == &debug_ctx_ops );
312     fprintf( stderr, "Debug context head=%p tail=%p\n",
313              debug_ctx->event_queue.next, debug_ctx->event_queue.prev );
314 }
315
316 static int debug_ctx_signaled( struct object *obj, struct thread *thread )
317 {
318     struct debug_ctx *debug_ctx = (struct debug_ctx *)obj;
319     assert( obj->ops == &debug_ctx_ops );
320     return find_event_to_send( debug_ctx ) != NULL;
321 }
322
323 static void debug_ctx_destroy( struct object *obj )
324 {
325     struct list *ptr;
326     struct debug_ctx *debug_ctx = (struct debug_ctx *)obj;
327     assert( obj->ops == &debug_ctx_ops );
328
329     /* free all pending events */
330     while ((ptr = list_head( &debug_ctx->event_queue )))
331         unlink_event( debug_ctx, LIST_ENTRY( ptr, struct debug_event, entry ));
332 }
333
334 /* continue a debug event */
335 static int continue_debug_event( struct process *process, struct thread *thread, int status )
336 {
337     struct debug_ctx *debug_ctx = current->debug_ctx;
338
339     if (debug_ctx && process->debugger == current && thread->process == process)
340     {
341         struct debug_event *event;
342
343         /* find the event in the queue */
344         LIST_FOR_EACH_ENTRY( event, &debug_ctx->event_queue, struct debug_event, entry )
345         {
346             if (event->state != EVENT_SENT) continue;
347             if (event->sender == thread)
348             {
349                 assert( event->sender->debug_event == event );
350
351                 event->status = status;
352                 event->state  = EVENT_CONTINUED;
353                 wake_up( &event->obj, 0 );
354                 unlink_event( debug_ctx, event );
355                 resume_process( process );
356                 return 1;
357             }
358         }
359     }
360     /* not debugging this process, or no such event */
361     set_error( STATUS_ACCESS_DENIED );  /* FIXME */
362     return 0;
363 }
364
365 /* alloc a debug event for a debugger */
366 static struct debug_event *alloc_debug_event( struct thread *thread, int code,
367                                               void *arg, const CONTEXT *context )
368 {
369     struct thread *debugger = thread->process->debugger;
370     struct debug_event *event;
371
372     assert( code > 0 && code <= NB_DEBUG_EVENTS );
373     /* cannot queue a debug event for myself */
374     assert( debugger->process != thread->process );
375
376     /* build the event */
377     if (!(event = alloc_object( &debug_event_ops ))) return NULL;
378     event->state     = EVENT_QUEUED;
379     event->sender    = (struct thread *)grab_object( thread );
380     event->debugger  = (struct thread *)grab_object( debugger );
381     event->data.code = code;
382
383     if (!fill_debug_event[code-1]( event, arg ))
384     {
385         event->data.code = -1;  /* make sure we don't attempt to close handles */
386         release_object( event );
387         return NULL;
388     }
389     if (context)
390     {
391         memcpy( &event->context, context, sizeof(event->context) );
392         thread->context = &event->context;
393     }
394     return event;
395 }
396
397 /* generate a debug event from inside the server and queue it */
398 void generate_debug_event( struct thread *thread, int code, void *arg )
399 {
400     if (thread->process->debugger)
401     {
402         struct debug_event *event = alloc_debug_event( thread, code, arg, NULL );
403         if (event)
404         {
405             link_event( event );
406             suspend_process( thread->process );
407             release_object( event );
408         }
409     }
410 }
411
412 /* attach a process to a debugger thread and suspend it */
413 static int debugger_attach( struct process *process, struct thread *debugger )
414 {
415     struct thread *thread;
416
417     if (process->debugger) goto error;  /* already being debugged */
418     if (!is_process_init_done( process )) goto error;  /* still starting up */
419     if (list_empty( &process->thread_list )) goto error;  /* no thread running in the process */
420
421     /* make sure we don't create a debugging loop */
422     for (thread = debugger; thread; thread = thread->process->debugger)
423         if (thread->process == process) goto error;
424
425     /* don't let a debugger debug its console... won't work */
426     if (debugger->process->console && debugger->process->console->renderer->process == process)
427         goto error;
428
429     suspend_process( process );
430     if (!attach_process( process ) || !set_process_debugger( process, debugger ))
431     {
432         resume_process( process );
433         return 0;
434     }
435     if (!set_process_debug_flag( process, 1 ))
436     {
437         process->debugger = NULL;
438         resume_process( process );
439         return 0;
440     }
441     return 1;
442
443  error:
444     set_error( STATUS_ACCESS_DENIED );
445     return 0;
446 }
447
448
449 /* detach a process from a debugger thread (and resume it ?) */
450 int debugger_detach( struct process *process, struct thread *debugger )
451 {
452     struct debug_event *event;
453     struct debug_ctx *debug_ctx;
454
455     if (!process->debugger || process->debugger != debugger)
456         goto error;  /* not currently debugged, or debugged by another debugger */
457     if (!debugger->debug_ctx ) goto error; /* should be a debugger */
458     /* init should be done, otherwise wouldn't be attached */
459     assert(is_process_init_done(process));
460
461     suspend_process( process );
462     /* send continue indication for all events */
463     debug_ctx = debugger->debug_ctx;
464
465     /* find the event in the queue
466      * FIXME: could loop on process' threads and look the debug_event field */
467     LIST_FOR_EACH_ENTRY( event, &debug_ctx->event_queue, struct debug_event, entry )
468     {
469         if (event->state != EVENT_QUEUED) continue;
470
471         if (event->sender->process == process)
472         {
473             assert( event->sender->debug_event == event );
474             event->status = DBG_CONTINUE;
475             event->state  = EVENT_CONTINUED;
476             wake_up( &event->obj, 0 );
477             unlink_event( debug_ctx, event );
478             /* from queued debug event */
479             resume_process( process );
480             break;
481         }
482     }
483
484     /* remove relationships between process and its debugger */
485     process->debugger = NULL;
486     if (!set_process_debug_flag( process, 0 )) clear_error();  /* ignore error */
487     detach_process( process );
488
489     /* from this function */
490     resume_process( process );
491     return 0;
492
493  error:
494     set_error( STATUS_ACCESS_DENIED );
495     return 0;
496 }
497
498 /* generate all startup events of a given process */
499 void generate_startup_debug_events( struct process *process, void *entry )
500 {
501     struct list *ptr;
502     struct thread *thread, *first_thread = get_process_first_thread( process );
503
504     /* generate creation events */
505     LIST_FOR_EACH_ENTRY( thread, &process->thread_list, struct thread, proc_entry )
506     {
507         if (thread == first_thread)
508             generate_debug_event( thread, CREATE_PROCESS_DEBUG_EVENT, entry );
509         else
510             generate_debug_event( thread, CREATE_THREAD_DEBUG_EVENT, NULL );
511     }
512
513     /* generate dll events (in loading order, i.e. reverse list order) */
514     ptr = list_tail( &process->dlls );
515     while (ptr)
516     {
517         struct process_dll *dll = LIST_ENTRY( ptr, struct process_dll, entry );
518         generate_debug_event( first_thread, LOAD_DLL_DEBUG_EVENT, dll );
519         ptr = list_prev( &process->dlls, ptr );
520     }
521 }
522
523 /* set the debugger of a given process */
524 int set_process_debugger( struct process *process, struct thread *debugger )
525 {
526     struct debug_ctx *debug_ctx;
527
528     assert( !process->debugger );
529
530     if (!debugger->debug_ctx)  /* need to allocate a context */
531     {
532         if (!(debug_ctx = alloc_object( &debug_ctx_ops ))) return 0;
533         debug_ctx->kill_on_exit = 1;
534         list_init( &debug_ctx->event_queue );
535         debugger->debug_ctx = debug_ctx;
536     }
537     process->debugger = debugger;
538     return 1;
539 }
540
541 /* a thread is exiting */
542 void debug_exit_thread( struct thread *thread )
543 {
544     if (thread->debug_ctx)  /* this thread is a debugger */
545     {
546         if (thread->debug_ctx->kill_on_exit)
547         {
548             /* kill all debugged processes */
549             kill_debugged_processes( thread, thread->exit_code );
550         }
551         else
552         {
553             detach_debugged_processes( thread );
554         }
555         release_object( thread->debug_ctx );
556         thread->debug_ctx = NULL;
557     }
558 }
559
560 /* Wait for a debug event */
561 DECL_HANDLER(wait_debug_event)
562 {
563     struct debug_ctx *debug_ctx = current->debug_ctx;
564     struct debug_event *event;
565
566     if (!debug_ctx)  /* current thread is not a debugger */
567     {
568         set_error( STATUS_INVALID_HANDLE );
569         return;
570     }
571     reply->wait = 0;
572     if ((event = find_event_to_send( debug_ctx )))
573     {
574         size_t size = get_reply_max_size();
575         event->state = EVENT_SENT;
576         event->sender->debug_event = event;
577         reply->pid = get_process_id( event->sender->process );
578         reply->tid = get_thread_id( event->sender );
579         if (size > sizeof(debug_event_t)) size = sizeof(debug_event_t);
580         set_reply_data( &event->data, size );
581     }
582     else  /* no event ready */
583     {
584         reply->pid  = 0;
585         reply->tid  = 0;
586         if (req->get_handle)
587             reply->wait = alloc_handle( current->process, debug_ctx, SYNCHRONIZE, 0 );
588     }
589 }
590
591 /* Continue a debug event */
592 DECL_HANDLER(continue_debug_event)
593 {
594     struct process *process = get_process_from_id( req->pid );
595     if (process)
596     {
597         struct thread *thread = get_thread_from_id( req->tid );
598         if (thread)
599         {
600             continue_debug_event( process, thread, req->status );
601             release_object( thread );
602         }
603         release_object( process );
604     }
605 }
606
607 /* Start debugging an existing process */
608 DECL_HANDLER(debug_process)
609 {
610     struct process *process = get_process_from_id( req->pid );
611     if (!process) return;
612
613     if (!req->attach)
614     {
615         debugger_detach( process, current );
616     }
617     else if (debugger_attach( process, current ))
618     {
619         struct debug_event_exception data;
620         struct thread *thread = get_process_first_thread( process );
621
622         generate_startup_debug_events( process, NULL );
623         resume_process( process );
624
625         data.record.ExceptionCode    = EXCEPTION_BREAKPOINT;
626         data.record.ExceptionFlags   = EXCEPTION_CONTINUABLE;
627         data.record.ExceptionRecord  = NULL;
628         data.record.ExceptionAddress = get_thread_ip( thread );
629         data.record.NumberParameters = 0;
630         data.first = 1;
631         generate_debug_event( thread, EXCEPTION_DEBUG_EVENT, &data );
632     }
633     release_object( process );
634 }
635
636 /* queue an exception event */
637 DECL_HANDLER(queue_exception_event)
638 {
639     reply->handle = 0;
640     if (current->process->debugger)
641     {
642         struct debug_event_exception data;
643         struct debug_event *event;
644         const CONTEXT *context = get_req_data();
645         const EXCEPTION_RECORD *rec = (const EXCEPTION_RECORD *)(context + 1);
646
647         if (get_req_data_size() < sizeof(*rec) + sizeof(*context))
648         {
649             set_error( STATUS_INVALID_PARAMETER );
650             return;
651         }
652         data.record = *rec;
653         data.first  = req->first;
654         if ((event = alloc_debug_event( current, EXCEPTION_DEBUG_EVENT, &data, context )))
655         {
656             if ((reply->handle = alloc_handle( current->process, event, SYNCHRONIZE, 0 )))
657             {
658                 link_event( event );
659                 suspend_process( current->process );
660             }
661             release_object( event );
662         }
663     }
664 }
665
666 /* retrieve the status of an exception event */
667 DECL_HANDLER(get_exception_status)
668 {
669     struct debug_event *event;
670
671     if ((event = (struct debug_event *)get_handle_obj( current->process, req->handle,
672                                                        0, &debug_event_ops )))
673     {
674         close_handle( current->process, req->handle, NULL );
675         if (event->state == EVENT_CONTINUED)
676         {
677             if (current->context == &event->context)
678             {
679                 size_t size = min( sizeof(CONTEXT), get_reply_max_size() );
680                 set_reply_data( &event->context, size );
681                 current->context = NULL;
682             }
683             set_error( event->status );
684         }
685         else set_error( STATUS_PENDING );
686         release_object( event );
687     }
688 }
689
690 /* send an output string to the debugger */
691 DECL_HANDLER(output_debug_string)
692 {
693     struct debug_event_output_string data;
694
695     data.string  = req->string;
696     data.unicode = req->unicode;
697     data.length  = req->length;
698     generate_debug_event( current, OUTPUT_DEBUG_STRING_EVENT, &data );
699 }
700
701 /* simulate a breakpoint in a process */
702 DECL_HANDLER(debug_break)
703 {
704     struct process *process;
705
706     reply->self = 0;
707     if (!(process = get_process_from_handle( req->handle, PROCESS_SET_INFORMATION /*FIXME*/ )))
708         return;
709     if (process != current->process)
710     {
711         /* find a suitable thread to signal */
712         struct thread *thread;
713         LIST_FOR_EACH_ENTRY( thread, &process->thread_list, struct thread, proc_entry )
714         {
715             if (send_thread_signal( thread, SIGTRAP )) goto done;
716         }
717         set_error( STATUS_ACCESS_DENIED );
718     }
719     else reply->self = 1;
720
721 done:
722     release_object( process );
723 }
724
725 /* set debugger kill on exit flag */
726 DECL_HANDLER(set_debugger_kill_on_exit)
727 {
728     if (!current->debug_ctx)
729     {
730         set_error( STATUS_ACCESS_DENIED );
731         return;
732     }
733     current->debug_ctx->kill_on_exit = req->kill_on_exit;
734 }