1 /* Main code for remote server for GDB.
2 Copyright (C) 1989, 1993, 1994, 1995, 1997, 1998, 1999, 2000, 2002, 2003,
4 Free Software Foundation, Inc.
6 This file is part of GDB.
7 It has been modified to integrate it in valgrind
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin Street, Fifth Floor,
22 Boston, MA 02110-1301, USA. */
26 #include "pub_core_options.h"
27 #include "pub_core_translate.h"
28 #include "pub_core_mallocfree.h"
30 unsigned long cont_thread;
31 unsigned long general_thread;
32 unsigned long step_thread;
33 unsigned long thread_from_wait;
34 unsigned long old_thread_from_wait;
36 int pass_signals[TARGET_SIGNAL_LAST];
38 /* for a gdbserver integrated in valgrind, resuming the process consists
39 in returning the control to valgrind.
40 Then at the next error or break or ..., valgrind calls gdbserver again.
41 A resume packet must then be built.
42 resume_packet_needed records the fact that the next call to gdbserver
43 must send a resume packet to gdb. */
44 static Bool resume_packet_needed = False;
46 VG_MINIMAL_JMP_BUF(toplevel);
48 /* Decode a qXfer read request. Return 0 if everything looks OK,
52 int decode_xfer_read (char *buf, char **annex, CORE_ADDR *ofs, unsigned int *len)
54 /* Extract and NUL-terminate the annex. */
56 while (*buf && *buf != ':')
62 /* After the read/write marker and annex, qXfer looks like a
63 traditional 'm' packet. */
64 decode_m_packet (buf, ofs, len);
69 /* Write the response to a successful qXfer read. Returns the
70 length of the (binary) data stored in BUF, corresponding
71 to as much of DATA/LEN as we could fit. IS_MORE controls
72 the first character of the response. */
74 int write_qxfer_response (char *buf, unsigned char *data, int len, int is_more)
83 return remote_escape_output (data, len, (unsigned char *) buf + 1, &out_len,
84 PBUFSIZ - POVERHSIZ - 1) + 1;
87 static Bool initial_valgrind_sink_saved = False;
88 /* True <=> valgrind log sink saved in initial_valgrind_sink */
89 static OutputSink initial_valgrind_sink;
91 static Bool command_output_to_log = False;
92 /* True <=> command output goes to log instead of gdb */
94 void reset_valgrind_sink(char *info)
96 if (VG_(log_output_sink).fd != initial_valgrind_sink.fd
97 && initial_valgrind_sink_saved) {
98 VG_(log_output_sink).fd = initial_valgrind_sink.fd;
99 VG_(umsg) ("Reset valgrind output to log (%s)\n",
100 (info = NULL ? "" : info));
105 void kill_request (char *msg)
107 VG_(umsg) ("%s", msg);
112 /* handle_gdb_valgrind_command handles the provided mon string command.
113 If command is recognised, return 1 else return 0.
114 Note that in case of ambiguous command, 1 is returned.
116 *sink_wanted_at_return is modified if one of the commands
117 'vg.set *_output' is handled.
120 int handle_gdb_valgrind_command (char* mon, OutputSink* sink_wanted_at_return)
123 char s[strlen(mon)+1]; /* copy for strtok_r */
130 vg_assert (initial_valgrind_sink_saved);
133 wcmd = strtok_r (s, " ", &ssaveptr);
134 /* NB: if possible, avoid introducing a new command below which
135 starts with the same 4 first letters as an already existing
136 command. This ensures a shorter abbreviation for the user. */
137 switch (VG_(keyword_id) ("help vg.set vg.info vg.wait vg.kill vg.translate",
138 wcmd, kwd_report_duplicated_matches)) {
146 wcmd = strtok_r (NULL, " ", &ssaveptr);
150 switch (VG_(keyword_id) ("debug", wcmd, kwd_report_all)) {
151 case -2: int_value = 0; break;
152 case -1: int_value = 0; break;
153 case 0: int_value = 1; break;
154 default: tl_assert (0);
159 "general valgrind monitor commands:\n"
160 " help [debug] : monitor command help. With debug: + debugging commands\n"
161 " vg.wait [<ms>] : sleep <ms> (default 0) then continue\n"
162 " vg.info all_errors : show all errors found so far\n"
163 " vg.info last_error : show last error found\n"
164 " vg.info n_errs_found : show the nr of errors found so far\n"
165 " vg.kill : kill the Valgrind process\n"
166 " vg.set gdb_output : set valgrind output to gdb\n"
167 " vg.set log_output : set valgrind output to log\n"
168 " vg.set mixed_output : set valgrind output to log, interactive output to gdb\n"
169 " vg.set vgdb-error <errornr> : debug me at error >= <errornr> \n");
170 if (int_value) { VG_(gdb_printf) (
171 "debugging valgrind internals monitor commands:\n"
172 " vg.info gdbserver_status : show gdbserver status\n"
173 " vg.info memory : show valgrind heap memory stats\n"
174 " vg.set debuglog <level> : set valgrind debug log level to <level>\n"
175 " vg.translate <addr> [<traceflags>] : debug translation of <addr> with <traceflags>\n"
176 " (default traceflags 0b00100000 : show after instrumentation)\n"
177 " An additional flag 0b100000000 allows to show gdbserver instrumentation\n");
182 wcmd = strtok_r (NULL, " ", &ssaveptr);
183 switch (kwdid = VG_(keyword_id)
184 ("vgdb-error debuglog gdb_output log_output mixed_output",
185 wcmd, kwd_report_all)) {
189 case 0: /* vgdb-error */
190 case 1: /* debuglog */
191 wcmd = strtok_r (NULL, " ", &ssaveptr);
194 endptr = "empty"; /* to report an error below */
196 int_value = strtol (wcmd, &endptr, 10);
198 if (*endptr != '\0') {
199 VG_(gdb_printf) ("missing or malformed integer value\n");
200 } else if (kwdid == 0) {
201 VG_(gdb_printf) ("vgdb-error value changed from %d to %d\n",
202 VG_(dyn_vgdb_error), int_value);
203 VG_(dyn_vgdb_error) = int_value;
204 } else if (kwdid == 1) {
205 VG_(gdb_printf) ("debuglog value changed from %d to %d\n",
206 VG_(debugLog_getLevel)(), int_value);
207 VG_(debugLog_startup) (int_value, "gdbsrv");
212 case 2: /* gdb_output */
213 (*sink_wanted_at_return).fd = -2;
214 command_output_to_log = False;
215 VG_(gdb_printf) ("valgrind output will go to gdb\n");
217 case 3: /* log_output */
218 (*sink_wanted_at_return).fd = initial_valgrind_sink.fd;
219 command_output_to_log = True;
220 VG_(gdb_printf) ("valgrind output will go to log\n");
222 case 4: /* mixed output */
223 (*sink_wanted_at_return).fd = initial_valgrind_sink.fd;
224 command_output_to_log = False;
226 ("valgrind output will go to log, interactive output will go to gdb\n");
232 case 2: /* vg.info */ {
234 wcmd = strtok_r (NULL, " ", &ssaveptr);
235 switch (kwdid = VG_(keyword_id)
236 ("all_errors n_errs_found last_error gdbserver_status memory",
237 wcmd, kwd_report_all)) {
241 case 0: // all_errors
242 // A verbosity of minimum 2 is needed to show the errors.
243 VG_(show_all_errors)(/* verbosity */ 2, /* xml */ False);
245 case 1: // n_errs_found
246 VG_(gdb_printf) ("n_errs_found %d (vgdb-error %d)\n",
247 VG_(get_n_errs_found) (),
248 VG_(dyn_vgdb_error));
250 case 2: // last_error
251 VG_(show_last_error)();
253 case 3: // gdbserver_status
254 VG_(gdbserver_status_output)();
257 VG_(print_all_arena_stats) ();
258 if (VG_(clo_profile_heap))
259 VG_(print_arena_cc_analysis) ();
267 case 3: /* vg.wait */
268 wcmd = strtok_r (NULL, " ", &ssaveptr);
270 int_value = strtol (wcmd, &endptr, 10);
271 VG_(gdb_printf) ("gdbserver: continuing in %d ms ...\n", int_value);
272 VG_(poll)(NULL, 0, int_value);
274 VG_(gdb_printf) ("gdbserver: continuing after wait ...\n");
277 case 4: /* vg.kill */
278 kill_request ("monitor command request to kill this process\n");
280 case 5: { /* vg.translate */
282 SizeT verbosity = 0x20;
286 VG_(strtok_get_address_and_size) (&address, &verbosity, &ssaveptr);
287 if (address != (Addr) 0 || verbosity != 0) {
288 /* we need to force the output to log for the translation trace,
289 as low level VEX tracing cannot be redirected to gdb. */
290 int saved_command_output_to_log = command_output_to_log;
291 int saved_fd = VG_(log_output_sink).fd;
292 Bool single_stepping_on_entry = valgrind_single_stepping();
293 int vex_verbosity = verbosity & 0xff;
294 VG_(log_output_sink).fd = initial_valgrind_sink.fd;
295 if ((verbosity & 0x100) && !single_stepping_on_entry) {
296 valgrind_set_single_stepping(True);
297 // to force gdbserver instrumentation.
299 # if defined(VGA_arm)
300 // on arm, we need to (potentially) convert this address
301 // to the thumb form.
302 address = thumb_pc (address);
305 VG_(translate) ( 0 /* dummy ThreadId; irrelevant due to debugging*/,
310 /*allow redir?*/True);
311 if ((verbosity & 0x100) && !single_stepping_on_entry) {
312 valgrind_set_single_stepping(False);
313 // reset single stepping.
315 command_output_to_log = saved_command_output_to_log;
316 VG_(log_output_sink).fd = saved_fd;
327 /* handle_gdb_monitor_command handles the provided mon string command,
328 which can be either a "standard" valgrind monitor command
329 or a tool specific monitor command.
330 If command recognised, return 1 else return 0.
331 Note that in case of ambiguous command, 1 is returned.
334 int handle_gdb_monitor_command (char* mon)
338 // initially, we assume that when returning, the desired sink is the
339 // one we have when entering. It can however be changed by the standard
340 // valgrind command handling.
341 OutputSink sink_wanted_at_return = VG_(log_output_sink);
343 if (!initial_valgrind_sink_saved) {
344 /* first time we enter here, we save the valgrind default log sink */
345 initial_valgrind_sink = sink_wanted_at_return;
346 initial_valgrind_sink_saved = True;
349 if (!command_output_to_log)
350 VG_(log_output_sink).fd = -2; /* redirect to monitor_output */
352 ret = handle_gdb_valgrind_command (mon, &sink_wanted_at_return);
354 /* Even if command was recognised by valgrind core, we call the
355 tool command handler : this is needed to handle help command
356 and/or to let the tool do some additional processing of a
357 valgrind standard command. Note however that if valgrind
358 recognised the command, we will always return success. */
359 if (VG_(needs).client_requests) {
360 /* If the tool reports an error when handling a monitor command,
361 we need to avoid calling gdbserver during this command
362 handling. So, we temporarily set VG_(dyn_vgdb_error) to
363 a huge value to ensure m_errormgr.c does not call gdbserver. */
364 Int save_dyn_vgdb_error = VG_(dyn_vgdb_error);
366 VG_(dyn_vgdb_error) = 999999999;
367 arg[0] = (UWord) VG_USERREQ__GDB_MONITOR_COMMAND;
368 arg[1] = (UWord) mon;
369 VG_TDICT_CALL(tool_handle_client_request, VG_(running_tid), arg,
371 VG_(dyn_vgdb_error) = save_dyn_vgdb_error;
374 /* restore or set the desired output */
375 VG_(log_output_sink).fd = sink_wanted_at_return.fd;
383 /* Handle all of the extended 'Q' packets. */
385 void handle_set (char *arg_own_buf, int *new_packet_len_p)
387 if (strcmp ("QStartNoAckMode", arg_own_buf) == 0) {
389 write_ok (arg_own_buf);
393 if (strncmp ("QPassSignals:", arg_own_buf, 13) == 0) {
396 char *end = arg_own_buf + strlen(arg_own_buf);
398 for (i = 0; i < TARGET_SIGNAL_LAST; i++)
401 from = arg_own_buf + 13;
403 to = strchr(from, ';');
404 if (to == NULL) to = end;
405 decode_address (&sig, from, to - from);
406 pass_signals[(int)sig] = 1;
407 dlog(1, "pass_signal %d\n", (int)sig);
409 if (*from == ';') from++;
411 write_ok (arg_own_buf);
414 /* Otherwise we didn't know what packet it was. Say we didn't
419 /* Handle all of the extended 'q' packets. */
421 void handle_query (char *arg_own_buf, int *new_packet_len_p)
423 static struct inferior_list_entry *thread_ptr;
425 /* qRcmd, monitor command handling. */
426 if (strncmp ("qRcmd,", arg_own_buf, 6) == 0) {
427 char *p = arg_own_buf + 6;
428 int cmdlen = strlen(p)/2;
431 if (unhexify (cmd, p, cmdlen) != cmdlen) {
432 write_enn (arg_own_buf);
437 if (handle_gdb_monitor_command (cmd)) {
438 /* In case the command is from a standalone vgdb,
439 connection will be closed soon => flush the output. */
440 VG_(message_flush) ();
441 write_ok (arg_own_buf);
444 /* cmd not recognised */
446 ("command '%s' not recognised\n"
447 "In gdb, try 'monitor help'\n"
448 "In a shell, try 'vgdb help'\n",
450 write_ok (arg_own_buf);
455 /* provide some valgrind specific info in return to qThreadExtraInfo. */
456 if (strncmp ("qThreadExtraInfo,", arg_own_buf, 17) == 0) {
457 unsigned long gdb_id;
458 struct thread_info *ti;
462 gdb_id = strtoul (&arg_own_buf[17], NULL, 16);
463 ti = gdb_id_to_thread (gdb_id);
465 tst = (ThreadState *) inferior_target_data (ti);
466 /* Additional info is the tid and the thread status. */
467 VG_(snprintf) (status, sizeof(status), "tid %d %s",
469 VG_(name_of_ThreadStatus)(tst->status));
470 hexify (arg_own_buf, status, strlen(status));
473 write_enn (arg_own_buf);
478 if (strcmp ("qAttached", arg_own_buf) == 0) {
479 /* tell gdb to always detach, never kill the process */
480 arg_own_buf[0] = '1';
485 if (strcmp ("qSymbol::", arg_own_buf) == 0) {
486 /* We have no symbol to read. */
487 write_ok (arg_own_buf);
491 if (strcmp ("qfThreadInfo", arg_own_buf) == 0) {
492 thread_ptr = all_threads.head;
493 VG_(sprintf) (arg_own_buf, "m%x",
494 thread_to_gdb_id ((struct thread_info *)thread_ptr));
495 thread_ptr = thread_ptr->next;
499 if (strcmp ("qsThreadInfo", arg_own_buf) == 0) {
500 if (thread_ptr != NULL) {
501 VG_(sprintf) (arg_own_buf, "m%x",
502 thread_to_gdb_id ((struct thread_info *)thread_ptr));
503 thread_ptr = thread_ptr->next;
506 VG_(sprintf) (arg_own_buf, "l");
511 if ( ((*the_target->target_xml)() != NULL
512 || (*the_target->shadow_target_xml)() != NULL)
513 && strncmp ("qXfer:features:read:", arg_own_buf, 20) == 0) {
515 unsigned int len, doc_len;
517 // First, the annex is extracted from the packet received.
518 // Then, it is replaced by the corresponding file name.
521 /* Grab the annex, offset, and length. */
522 if (decode_xfer_read (arg_own_buf + 20, &annex, &ofs, &len) < 0) {
523 strcpy (arg_own_buf, "E00");
527 if (strcmp (annex, "target.xml") == 0) {
528 annex = NULL; // to replace it by the corresponding filename.
530 /* If VG_(clo_vgdb_shadow_registers), try to use
531 shadow_target_xml. Fallback to target_xml
533 if (VG_(clo_vgdb_shadow_registers)) {
534 annex = (*the_target->shadow_target_xml)();
536 /* Ensure the shadow registers are initialized. */
537 initialize_shadow_low(True);
540 annex = (*the_target->target_xml)();
542 strcpy (arg_own_buf, "E00");
548 char doc[VG_(strlen)(VG_(libdir)) + 1 + VG_(strlen)(annex)];
549 struct vg_stat stat_doc;
553 VG_(sprintf)(doc, "%s/%s", VG_(libdir), annex);
554 fd = VG_(fd_open) (doc, VKI_O_RDONLY, 0);
556 strcpy (arg_own_buf, "E00");
559 if (VG_(fstat) (fd, &stat_doc) != 0) {
561 strcpy (arg_own_buf, "E00");
564 doc_len = stat_doc.size;
566 if (len > PBUFSIZ - POVERHSIZ)
567 len = PBUFSIZ - POVERHSIZ;
570 write_enn (arg_own_buf);
574 VG_(lseek) (fd, ofs, VKI_SEEK_SET);
575 len_read = VG_(read) (fd, toread, len);
576 *new_packet_len_p = write_qxfer_response (arg_own_buf, toread,
577 len_read, ofs + len_read < doc_len);
583 /* Protocol features query. */
584 if (strncmp ("qSupported", arg_own_buf, 10) == 0
585 && (arg_own_buf[10] == ':' || arg_own_buf[10] == '\0')) {
586 VG_(sprintf) (arg_own_buf, "PacketSize=%x", PBUFSIZ - 1);
587 /* Note: max packet size including frame and checksum, but without
588 trailing null byte, which is not sent/received. */
590 strcat (arg_own_buf, ";QStartNoAckMode+");
591 strcat (arg_own_buf, ";QPassSignals+");
593 if ((*the_target->target_xml)() != NULL
594 || (*the_target->shadow_target_xml)() != NULL) {
595 strcat (arg_own_buf, ";qXfer:features:read+");
596 /* if a new gdb connects to us, we have to reset the register
597 set to the normal register sets to allow this new gdb to
598 decide to use or not the shadow registers.
600 Note that the reset is only done for gdb that are sending
601 qSupported packets. If a user first connected with a recent
602 gdb using shadow registers and then with a very old gdb
603 that does not use qSupported packet, then the old gdb will
604 not properly connect. */
605 initialize_shadow_low(False);
610 /* Otherwise we didn't know what packet it was. Say we didn't
615 /* Handle all of the extended 'v' packets. */
617 void handle_v_requests (char *arg_own_buf, char *status, int *signal)
619 /* vcont packet code from gdb 6.6 removed */
621 /* Otherwise we didn't know what packet it was. Say we didn't
628 void myresume (int step, int sig)
630 struct thread_resume resume_info[2];
633 if (step || sig || (cont_thread != 0 && cont_thread != -1)) {
634 resume_info[0].thread
635 = ((struct inferior_list_entry *) current_inferior)->id;
636 resume_info[0].step = step;
637 resume_info[0].sig = sig;
638 resume_info[0].leave_stopped = 0;
641 resume_info[n].thread = -1;
642 resume_info[n].step = 0;
643 resume_info[n].sig = 0;
644 resume_info[n].leave_stopped = (cont_thread != 0 && cont_thread != -1);
646 resume_packet_needed = True;
647 (*the_target->resume) (resume_info);
650 /* server_main global variables */
651 static char *own_buf;
652 static unsigned char *mem_buf;
654 void gdbserver_init (void)
656 dlog(1, "gdbserver_init gdbserver embedded in valgrind: %s\n", version);
659 own_buf = malloc (PBUFSIZ);
660 mem_buf = malloc (PBUFSIZ);
663 void gdbserver_terminate (void)
665 /* last call to gdbserver is cleanup call */
666 if (VG_MINIMAL_SETJMP(toplevel)) {
667 dlog(0, "error caused VG_MINIMAL_LONGJMP to gdbserver_terminate\n");
673 void server_main (void)
683 signal = mywait (&status);
684 if (VG_MINIMAL_SETJMP(toplevel)) {
685 dlog(0, "error caused VG_MINIMAL_LONGJMP to server_main\n");
690 int new_packet_len = -1;
692 if (resume_packet_needed) {
693 resume_packet_needed = False;
694 prepare_resume_reply (own_buf, status, signal);
698 packet_len = getpkt (own_buf);
706 handle_set (own_buf, &new_packet_len);
709 handle_query (own_buf, &new_packet_len);
712 /* set/unset debugging is done through valgrind debug level. */
716 reset_valgrind_sink("gdb detaching from process");
718 /* When detaching or kill the process, gdb expects to get
719 an packet OK back. Any other output will make gdb
720 believes detach did not work. */
723 remote_finish (reset_after_error);
724 remote_open (VG_(clo_vgdb_prefix));
726 resume_packet_needed = False;
729 /* We can not use the extended protocol with valgrind,
730 because we can not restart the running
731 program. So return unrecognized. */
735 prepare_resume_reply (own_buf, status, signal);
738 if (own_buf[1] == 'c' || own_buf[1] == 'g' || own_buf[1] == 's') {
739 unsigned long gdb_id, thread_id;
741 gdb_id = strtoul (&own_buf[2], NULL, 16);
742 thread_id = gdb_id_to_thread_id (gdb_id);
743 if (thread_id == 0) {
748 if (own_buf[1] == 'g') {
749 general_thread = thread_id;
750 set_desired_inferior (1);
751 } else if (own_buf[1] == 'c') {
752 cont_thread = thread_id;
753 } else if (own_buf[1] == 's') {
754 step_thread = thread_id;
759 /* Silently ignore it so that gdb can extend the protocol
760 without compatibility headaches. */
765 set_desired_inferior (1);
766 registers_to_string (own_buf);
769 set_desired_inferior (1);
770 registers_from_string (&own_buf[1]);
778 regno = strtol(&own_buf[1], NULL, 16);
779 regbytes = strchr(&own_buf[0], '=') + 1;
780 set_desired_inferior (1);
781 tst = (ThreadState *) inferior_target_data (current_inferior);
782 /* Only accept changing registers in "runnable state3.
783 In fact, it would be ok to change most of the registers
784 except a few "sensitive" registers such as the PC, SP, BP.
785 We assume we do not need to very specific here, and that we
786 can just refuse all of these. */
787 if (tst->status == VgTs_Runnable || tst->status == VgTs_Yielding) {
788 supply_register_from_string (regno, regbytes, &mod);
791 /* at least from gdb 6.6 onwards, an E. error
792 reply is shown to the user. So, we do an error
793 msg which both is accepted by gdb as an error msg
794 and is readable by the user. */
798 "ERROR changing register %s regno %d\n"
799 "gdb commands changing registers (pc, sp, ...) (e.g. 'jump',\n"
800 "set pc, calling from gdb a function in the debugged process, ...)\n"
801 "can only be accepted if the thread is VgTs_Runnable or VgTs_Yielding state\n"
802 "Thread status is %s\n",
803 find_register_by_number (regno)->name, regno,
804 VG_(name_of_ThreadStatus)(tst->status));
805 if (VG_(clo_verbosity) > 1)
806 VG_(umsg) ("%s\n", own_buf);
811 decode_m_packet (&own_buf[1], &mem_addr, &len);
812 if (read_inferior_memory (mem_addr, mem_buf, len) == 0)
813 convert_int_to_ascii (mem_buf, own_buf, len);
818 decode_M_packet (&own_buf[1], &mem_addr, &len, mem_buf);
819 if (write_inferior_memory (mem_addr, mem_buf, len) == 0)
825 if (decode_X_packet (&own_buf[1], packet_len - 1,
826 &mem_addr, &len, mem_buf) < 0
827 || write_inferior_memory (mem_addr, mem_buf, len) != 0)
833 convert_ascii_to_int (own_buf + 1, &sig, 1);
834 if (target_signal_to_host_p (sig))
835 signal = target_signal_to_host (sig);
838 set_desired_inferior (0);
839 myresume (0, signal);
840 return; // return control to valgrind
842 convert_ascii_to_int (own_buf + 1, &sig, 1);
843 if (target_signal_to_host_p (sig))
844 signal = target_signal_to_host (sig);
847 set_desired_inferior (0);
848 myresume (1, signal);
849 return; // return control to valgrind
851 set_desired_inferior (0);
853 return; // return control to valgrind
855 set_desired_inferior (0);
857 return; // return control to valgrind
861 CORE_ADDR addr = strtoul (&own_buf[3], &lenptr, 16);
862 int zlen = strtol (lenptr + 1, &dataptr, 16);
863 char type = own_buf[1];
865 if (the_target->insert_watchpoint == NULL
866 || (type < '0' || type > '4')) {
867 /* No watchpoint support or not a watchpoint command;
868 unrecognized either way. */
873 res = (*the_target->insert_watchpoint) (type, addr, zlen);
887 CORE_ADDR addr = strtoul (&own_buf[3], &lenptr, 16);
888 int zlen = strtol (lenptr + 1, &dataptr, 16);
889 char type = own_buf[1];
891 if (the_target->remove_watchpoint == NULL
892 || (type < '0' || type > '4')) {
893 /* No watchpoint support or not a watchpoint command;
894 unrecognized either way. */
899 res = (*the_target->remove_watchpoint) (type, addr, zlen);
911 kill_request("Gdb request to kill this process\n");
914 unsigned long gdb_id, thread_id;
916 gdb_id = strtoul (&own_buf[1], NULL, 16);
917 thread_id = gdb_id_to_thread_id (gdb_id);
918 if (thread_id == 0) {
923 if (mythread_alive (thread_id))
930 /* Restarting the inferior is only supported in the
932 => It is a request we don't understand. Respond with an
933 empty packet so that gdb knows that we don't support this
938 /* Extended (long) request. */
939 handle_v_requests (own_buf, &status, &signal);
942 /* It is a request we don't understand. Respond with an
943 empty packet so that gdb knows that we don't support this
949 if (new_packet_len != -1)
950 putpkt_binary (own_buf, new_packet_len);
955 VG_(umsg) ("\nChild exited with status %d\n", signal);
957 VG_(umsg) ("\nChild terminated with signal = 0x%x (%s)\n",
958 target_signal_to_host (signal),
959 target_signal_to_name (signal));
960 if (status == 'W' || status == 'X') {
961 VG_(umsg) ("Process exiting\n");
966 /* We come here when getpkt fails => close the connection,
967 and re-open. Then return control to valgrind.
968 We return the control to valgrind as we assume that
969 the connection was closed due to vgdb having finished
970 to execute a command. */
971 if (VG_(clo_verbosity) > 1)
972 VG_(umsg) ("Remote side has terminated connection. "
973 "GDBserver will reopen the connection.\n");
974 remote_finish (reset_after_error);
975 remote_open (VG_(clo_vgdb_prefix));
977 resume_packet_needed = False;