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