Link the tools and the server against libwine so we can use the
[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 <stdio.h>
28
29 #include "winbase.h"
30
31 #include "handle.h"
32 #include "process.h"
33 #include "thread.h"
34 #include "request.h"
35 #include "console.h"
36
37 enum debug_event_state { EVENT_QUEUED, EVENT_SENT, EVENT_CONTINUED };
38
39 /* debug event */
40 struct debug_event
41 {
42     struct object          obj;       /* object header */
43     struct debug_event    *next;      /* event queue */
44     struct debug_event    *prev;
45     struct thread         *sender;    /* thread which sent this event */
46     struct thread         *debugger;  /* debugger thread receiving the event */
47     enum debug_event_state state;     /* event state */
48     int                    status;    /* continuation status */
49     debug_event_t          data;      /* event data */
50     CONTEXT                context;   /* register context */
51 };
52
53 /* debug context */
54 struct debug_ctx
55 {
56     struct object        obj;         /* object header */
57     struct debug_event  *event_head;  /* head of pending events queue */
58     struct debug_event  *event_tail;  /* tail of 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     NULL,                          /* get_poll_events */
76     NULL,                          /* poll_event */
77     no_get_fd,                     /* get_fd */
78     no_flush,                      /* flush */
79     no_get_file_info,              /* get_file_info */
80     NULL,                          /* queue_async */
81     debug_event_destroy            /* destroy */
82 };
83
84 static void debug_ctx_dump( struct object *obj, int verbose );
85 static int debug_ctx_signaled( struct object *obj, struct thread *thread );
86 static void debug_ctx_destroy( struct object *obj );
87
88 static const struct object_ops debug_ctx_ops =
89 {
90     sizeof(struct debug_ctx),      /* size */
91     debug_ctx_dump,                /* dump */
92     add_queue,                     /* add_queue */
93     remove_queue,                  /* remove_queue */
94     debug_ctx_signaled,            /* signaled */
95     no_satisfied,                  /* satisfied */
96     NULL,                          /* get_poll_events */
97     NULL,                          /* poll_event */
98     no_get_fd,                     /* get_fd */
99     no_flush,                      /* flush */
100     no_get_file_info,              /* get_file_info */
101     NULL,                          /* queue_async */
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     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, FALSE ))) 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     handle_t handle;
134
135     /* documented: PROCESS_VM_READ | PROCESS_VM_WRITE */
136     if (!(handle = alloc_handle( debugger, process, PROCESS_ALL_ACCESS, FALSE ))) 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, FALSE )))
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, FALSE )))
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    = 0;
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     handle_t handle = 0;
186
187     if (dll->file && !(handle = alloc_handle( debugger, dll->file, GENERIC_READ, FALSE )))
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    = 0;
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     if (event->prev) event->prev->next = event->next;
232     else debug_ctx->event_head = event->next;
233     if (event->next) event->next->prev = event->prev;
234     else debug_ctx->event_tail = event->prev;
235     event->next = event->prev = NULL;
236     if (event->sender->debug_event == event) event->sender->debug_event = NULL;
237     release_object( event );
238 }
239
240 /* link an event at the end of the queue */
241 static void link_event( struct debug_event *event )
242 {
243     struct debug_ctx *debug_ctx = event->debugger->debug_ctx;
244
245     assert( debug_ctx );
246     grab_object( event );
247     event->next = NULL;
248     event->prev = debug_ctx->event_tail;
249     debug_ctx->event_tail = event;
250     if (event->prev) event->prev->next = event;
251     else debug_ctx->event_head = event;
252     if (!event->sender->debug_event) wake_up( &debug_ctx->obj, 0 );
253 }
254
255 /* find the next event that we can send to the debugger */
256 static struct debug_event *find_event_to_send( struct debug_ctx *debug_ctx )
257 {
258     struct debug_event *event;
259     for (event = debug_ctx->event_head; event; event = event->next)
260     {
261         if (event->state == EVENT_SENT) continue;  /* already sent */
262         if (event->sender->debug_event) continue;  /* thread busy with another one */
263         break;
264     }
265     return event;
266 }
267
268 static void debug_event_dump( struct object *obj, int verbose )
269 {
270     struct debug_event *debug_event = (struct debug_event *)obj;
271     assert( obj->ops == &debug_event_ops );
272     fprintf( stderr, "Debug event sender=%p code=%d state=%d\n",
273              debug_event->sender, debug_event->data.code, debug_event->state );
274 }
275
276 static int debug_event_signaled( struct object *obj, struct thread *thread )
277 {
278     struct debug_event *debug_event = (struct debug_event *)obj;
279     assert( obj->ops == &debug_event_ops );
280     return debug_event->state == EVENT_CONTINUED;
281 }
282
283 static void debug_event_destroy( struct object *obj )
284 {
285     struct debug_event *event = (struct debug_event *)obj;
286     assert( obj->ops == &debug_event_ops );
287
288     /* cannot still be in the queue */
289     assert( !event->next );
290     assert( !event->prev );
291
292     /* If the event has been sent already, the handles are now under the */
293     /* responsibility of the debugger process, so we don't touch them    */
294     if (event->state == EVENT_QUEUED)
295     {
296         struct process *debugger = event->debugger->process;
297         switch(event->data.code)
298         {
299         case CREATE_THREAD_DEBUG_EVENT:
300             close_handle( debugger, event->data.info.create_thread.handle, NULL );
301             break;
302         case CREATE_PROCESS_DEBUG_EVENT:
303             if (event->data.info.create_process.file)
304                 close_handle( debugger, event->data.info.create_process.file, NULL );
305             close_handle( debugger, event->data.info.create_process.thread, NULL );
306             close_handle( debugger, event->data.info.create_process.process, NULL );
307             break;
308         case LOAD_DLL_DEBUG_EVENT:
309             if (event->data.info.load_dll.handle)
310                 close_handle( debugger, event->data.info.load_dll.handle, NULL );
311             break;
312         }
313     }
314     if (event->sender->context == &event->context) event->sender->context = NULL;
315     release_object( event->sender );
316     release_object( event->debugger );
317 }
318
319 static void debug_ctx_dump( struct object *obj, int verbose )
320 {
321     struct debug_ctx *debug_ctx = (struct debug_ctx *)obj;
322     assert( obj->ops == &debug_ctx_ops );
323     fprintf( stderr, "Debug context head=%p tail=%p\n",
324              debug_ctx->event_head, debug_ctx->event_tail );
325 }
326
327 static int debug_ctx_signaled( struct object *obj, struct thread *thread )
328 {
329     struct debug_ctx *debug_ctx = (struct debug_ctx *)obj;
330     assert( obj->ops == &debug_ctx_ops );
331     return find_event_to_send( debug_ctx ) != NULL;
332 }
333
334 static void debug_ctx_destroy( struct object *obj )
335 {
336     struct debug_event *event;
337     struct debug_ctx *debug_ctx = (struct debug_ctx *)obj;
338     assert( obj->ops == &debug_ctx_ops );
339
340     /* free all pending events */
341     while ((event = debug_ctx->event_head) != NULL) unlink_event( debug_ctx, event );
342 }
343
344 /* continue a debug event */
345 static int continue_debug_event( struct process *process, struct thread *thread, int status )
346 {
347     struct debug_event *event;
348     struct debug_ctx *debug_ctx = current->debug_ctx;
349
350     if (!debug_ctx || process->debugger != current || thread->process != process) goto error;
351
352     /* find the event in the queue */
353     for (event = debug_ctx->event_head; event; event = event->next)
354     {
355         if (event->state != EVENT_SENT) continue;
356         if (event->sender == thread) break;
357     }
358     if (!event) goto error;
359
360     assert( event->sender->debug_event == event );
361
362     event->status = status;
363     event->state  = EVENT_CONTINUED;
364     wake_up( &event->obj, 0 );
365
366     unlink_event( debug_ctx, event );
367     resume_process( process );
368     return 1;
369  error:
370     /* not debugging this process, or no such event */
371     set_error( STATUS_ACCESS_DENIED );  /* FIXME */
372     return 0;
373 }
374
375 /* alloc a debug event for a debugger */
376 static struct debug_event *alloc_debug_event( struct thread *thread, int code,
377                                               void *arg, const CONTEXT *context )
378 {
379     struct thread *debugger = thread->process->debugger;
380     struct debug_event *event;
381
382     assert( code > 0 && code <= NB_DEBUG_EVENTS );
383     /* cannot queue a debug event for myself */
384     assert( debugger->process != thread->process );
385
386     /* build the event */
387     if (!(event = alloc_object( &debug_event_ops, -1 ))) return NULL;
388     event->next      = NULL;
389     event->prev      = NULL;
390     event->state     = EVENT_QUEUED;
391     event->sender    = (struct thread *)grab_object( thread );
392     event->debugger  = (struct thread *)grab_object( debugger );
393     event->data.code = code;
394
395     if (!fill_debug_event[code-1]( event, arg ))
396     {
397         event->data.code = -1;  /* make sure we don't attempt to close handles */
398         release_object( event );
399         return NULL;
400     }
401     if (context)
402     {
403         memcpy( &event->context, context, sizeof(event->context) );
404         thread->context = &event->context;
405     }
406     return event;
407 }
408
409 /* generate a debug event from inside the server and queue it */
410 void generate_debug_event( struct thread *thread, int code, void *arg )
411 {
412     if (thread->process->debugger)
413     {
414         struct debug_event *event = alloc_debug_event( thread, code, arg, NULL );
415         if (event)
416         {
417             link_event( event );
418             suspend_process( thread->process );
419             release_object( event );
420         }
421     }
422 }
423
424 /* attach a process to a debugger thread and suspend it */
425 static int debugger_attach( struct process *process, struct thread *debugger )
426 {
427     struct thread *thread;
428
429     if (process->debugger) goto error;  /* already being debugged */
430     if (process->init_event) goto error;  /* still starting up */
431     if (!process->thread_list) goto error;  /* no thread running in the process */
432
433     /* make sure we don't create a debugging loop */
434     for (thread = debugger; thread; thread = thread->process->debugger)
435         if (thread->process == process) goto error;
436
437     /* don't let a debugger debug its console... won't work */
438     if (debugger->process->console && debugger->process->console->renderer->process == process)
439         goto error;
440
441     suspend_process( process );
442
443     /* we must have been able to attach all threads */
444     if (!process->thread_list) goto error2;
445     for (thread = process->thread_list; thread; thread = thread->proc_next)
446     {
447         if (!thread->attached) goto error2;
448     }
449
450     if (set_process_debugger( process, debugger )) return 1;
451     resume_process( process );
452     return 0;
453
454  error2:
455     resume_process( process );
456  error:
457     set_error( STATUS_ACCESS_DENIED );
458     return 0;
459 }
460
461
462 /* detach a process from a debugger thread (and resume it ?) */
463 int debugger_detach( struct process *process, struct thread *debugger )
464 {
465     struct thread *thread;
466     struct debug_event *event;
467     struct debug_ctx *debug_ctx;
468
469     if (!process->debugger || process->debugger != debugger)
470         goto error;  /* not currently debugged, or debugged by another debugger */
471     if (!debugger->debug_ctx ) goto error; /* should be a debugger */
472     /* init should be done, otherwise wouldn't be attached */
473     assert(!process->init_event);
474
475     suspend_process( process );
476     /* send continue indication for all events */
477     debug_ctx = debugger->debug_ctx;
478
479     /* find the event in the queue
480      * FIXME: could loop on process' threads and look the debug_event field */
481     for (event = debug_ctx->event_head; event; event = event->next)
482     {
483         if (event->state != EVENT_QUEUED) continue;
484
485         if (event->sender->process == process)
486         {
487             assert( event->sender->debug_event == event );
488             event->status = DBG_CONTINUE;
489             event->state  = EVENT_CONTINUED;
490             wake_up( &event->obj, 0 );
491             unlink_event( debug_ctx, event );
492             /* from queued debug event */
493             resume_process( process );
494         }
495     }
496
497     /* remove relationships between process and its debugger */
498     process->debugger = NULL;
499     release_object( debugger->debug_ctx );
500     debugger->debug_ctx = NULL;
501
502     /* now detach all the threads */
503     for (thread = process->thread_list; thread; thread = thread->proc_next)
504     {
505         if (thread->attached)
506         {
507             detach_thread( thread, 0 );
508         }
509     }
510
511     /* from this function */
512     resume_process( process );
513     return 0;
514
515  error:
516     set_error( STATUS_ACCESS_DENIED );
517     return 0;
518 }
519
520 /* generate all startup events of a given process */
521 void generate_startup_debug_events( struct process *process, void *entry )
522 {
523     struct process_dll *dll;
524     struct thread *thread = process->thread_list;
525
526     /* generate creation events */
527     generate_debug_event( thread, CREATE_PROCESS_DEBUG_EVENT, entry );
528     while ((thread = thread->proc_next))
529         generate_debug_event( thread, CREATE_THREAD_DEBUG_EVENT, NULL );
530
531     /* generate dll events (in loading order, i.e. reverse list order) */
532     dll = &process->exe;
533     while (dll->next) dll = dll->next;
534     while (dll != &process->exe)
535     {
536         generate_debug_event( process->thread_list, LOAD_DLL_DEBUG_EVENT, dll );
537         dll = dll->prev;
538     }
539 }
540
541 /* set the debugger of a given process */
542 int set_process_debugger( struct process *process, struct thread *debugger )
543 {
544     struct debug_ctx *debug_ctx;
545
546     assert( !process->debugger );
547
548     if (!debugger->debug_ctx)  /* need to allocate a context */
549     {
550         if (!(debug_ctx = alloc_object( &debug_ctx_ops, -1 ))) return 0;
551         debug_ctx->event_head = NULL;
552         debug_ctx->event_tail = NULL;
553         debug_ctx->kill_on_exit = 1;
554         debugger->debug_ctx = debug_ctx;
555     }
556     process->debugger = debugger;
557     return 1;
558 }
559
560 /* a thread is exiting */
561 void debug_exit_thread( struct thread *thread )
562 {
563     if (thread->debug_ctx)  /* this thread is a debugger */
564     {
565         if (thread->debug_ctx->kill_on_exit)
566         {
567             /* kill all debugged processes */
568             kill_debugged_processes( thread, thread->exit_code );
569         }
570         else
571         {
572             detach_debugged_processes( thread );
573         }
574         release_object( thread->debug_ctx );
575         thread->debug_ctx = NULL;
576     }
577 }
578
579 /* Wait for a debug event */
580 DECL_HANDLER(wait_debug_event)
581 {
582     struct debug_ctx *debug_ctx = current->debug_ctx;
583     struct debug_event *event;
584
585     if (!debug_ctx)  /* current thread is not a debugger */
586     {
587         set_error( STATUS_INVALID_HANDLE );
588         return;
589     }
590     reply->wait = 0;
591     if ((event = find_event_to_send( debug_ctx )))
592     {
593         size_t size = get_reply_max_size();
594         event->state = EVENT_SENT;
595         event->sender->debug_event = event;
596         reply->pid = event->sender->process;
597         reply->tid = event->sender;
598         if (size > sizeof(debug_event_t)) size = sizeof(debug_event_t);
599         set_reply_data( &event->data, size );
600     }
601     else  /* no event ready */
602     {
603         reply->pid  = 0;
604         reply->tid  = 0;
605         if (req->get_handle)
606             reply->wait = alloc_handle( current->process, debug_ctx, SYNCHRONIZE, FALSE );
607     }
608 }
609
610 /* Continue a debug event */
611 DECL_HANDLER(continue_debug_event)
612 {
613     struct process *process = get_process_from_id( req->pid );
614     if (process)
615     {
616         struct thread *thread = get_thread_from_id( req->tid );
617         if (thread)
618         {
619             continue_debug_event( process, thread, req->status );
620             release_object( thread );
621         }
622         release_object( process );
623     }
624 }
625
626 /* Start debugging an existing process */
627 DECL_HANDLER(debug_process)
628 {
629     struct process *process = get_process_from_id( req->pid );
630     if (!process) return;
631
632     if (!req->attach)
633     {
634         debugger_detach( process, current );
635     }
636     else if (debugger_attach( process, current ))
637     {
638         struct debug_event_exception data;
639
640         generate_startup_debug_events( process, NULL );
641         resume_process( process );
642
643         data.record.ExceptionCode    = EXCEPTION_BREAKPOINT;
644         data.record.ExceptionFlags   = EXCEPTION_CONTINUABLE;
645         data.record.ExceptionRecord  = NULL;
646         data.record.ExceptionAddress = get_thread_ip( process->thread_list );
647         data.record.NumberParameters = 0;
648         data.first = 1;
649         generate_debug_event( process->thread_list, EXCEPTION_DEBUG_EVENT, &data );
650     }
651     release_object( process );
652 }
653
654 /* queue an exception event */
655 DECL_HANDLER(queue_exception_event)
656 {
657     reply->handle = 0;
658     if (current->process->debugger)
659     {
660         struct debug_event_exception data;
661         struct debug_event *event;
662         const CONTEXT *context = get_req_data();
663         EXCEPTION_RECORD *rec = (EXCEPTION_RECORD *)(context + 1);
664
665         if (get_req_data_size() < sizeof(*rec) + sizeof(*context))
666         {
667             set_error( STATUS_INVALID_PARAMETER );
668             return;
669         }
670         data.record = *rec;
671         data.first  = req->first;
672         if ((event = alloc_debug_event( current, EXCEPTION_DEBUG_EVENT, &data, context )))
673         {
674             if ((reply->handle = alloc_handle( current->process, event, SYNCHRONIZE, FALSE )))
675             {
676                 link_event( event );
677                 suspend_process( current->process );
678             }
679             release_object( event );
680         }
681     }
682 }
683
684 /* retrieve the status of an exception event */
685 DECL_HANDLER(get_exception_status)
686 {
687     struct debug_event *event;
688
689     reply->status = 0;
690     if ((event = (struct debug_event *)get_handle_obj( current->process, req->handle,
691                                                        0, &debug_event_ops )))
692     {
693         if (event->state == EVENT_CONTINUED)
694         {
695             reply->status = event->status;
696             if (current->context == &event->context)
697             {
698                 size_t size = min( sizeof(CONTEXT), get_reply_max_size() );
699                 set_reply_data( &event->context, size );
700                 current->context = NULL;
701             }
702         }
703         else set_error( STATUS_PENDING );
704         release_object( event );
705     }
706 }
707
708 /* send an output string to the debugger */
709 DECL_HANDLER(output_debug_string)
710 {
711     struct debug_event_output_string data;
712
713     data.string  = req->string;
714     data.unicode = req->unicode;
715     data.length  = req->length;
716     generate_debug_event( current, OUTPUT_DEBUG_STRING_EVENT, &data );
717 }
718
719 /* simulate a breakpoint in a process */
720 DECL_HANDLER(debug_break)
721 {
722     struct process *process;
723
724     reply->self = 0;
725     if (!(process = get_process_from_handle( req->handle, PROCESS_SET_INFORMATION /*FIXME*/ )))
726         return;
727     if (process != current->process)
728     {
729         /* find a suitable thread to signal */
730         struct thread *thread;
731         for (thread = process->thread_list; thread; thread = thread->proc_next)
732         {
733             if (thread->unix_pid)
734             {
735                 kill( thread->unix_pid, SIGTRAP );
736                 break;
737             }
738         }
739         if (!thread) set_error( STATUS_ACCESS_DENIED );
740     }
741     else reply->self = 1;
742     release_object( process );
743 }
744
745 /* set debugger kill on exit flag */
746 DECL_HANDLER(set_debugger_kill_on_exit)
747 {
748     if (!current->debug_ctx)
749     {
750         set_error( STATUS_ACCESS_DENIED );
751         return;
752     }
753     current->debug_ctx->kill_on_exit = req->kill_on_exit;
754 }