2 /*--------------------------------------------------------------------*/
3 /*--- Handle remote gdb protocol. m_gdbserver.c ---*/
4 /*--------------------------------------------------------------------*/
7 This file is part of Valgrind, a dynamic binary instrumentation
10 Copyright (C) 2011-2017 Philippe Waroquiers
12 This program is free software; you can redistribute it and/or
13 modify it under the terms of the GNU General Public License as
14 published by the Free Software Foundation; either version 2 of the
15 License, or (at your option) any later version.
17 This program is distributed in the hope that it will be useful, but
18 WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 General Public License for more details.
22 You should have received a copy of the GNU General Public License
23 along with this program; if not, see <http://www.gnu.org/licenses/>.
25 The GNU General Public License is contained in the file COPYING.
28 #include "pub_core_basics.h"
29 #include "pub_core_vki.h"
30 #include "pub_core_debuglog.h"
31 #include "pub_core_libcproc.h"
32 #include "pub_core_libcprint.h"
33 #include "pub_core_mallocfree.h"
34 #include "pub_core_threadstate.h"
35 #include "pub_core_gdbserver.h"
36 #include "pub_core_options.h"
37 #include "pub_core_transtab.h"
38 #include "pub_core_hashtable.h"
39 #include "pub_core_xarray.h"
40 #include "pub_core_libcassert.h"
41 #include "pub_core_libcbase.h"
42 #include "pub_core_libcsignal.h"
43 #include "pub_core_signals.h"
44 #include "pub_core_machine.h" // VG_(fnptr_to_fnentry)
45 #include "pub_core_debuginfo.h"
46 #include "pub_core_scheduler.h"
47 #include "pub_core_syswrap.h"
51 /* forward declarations */
53 void VG_(helperc_CallDebugger
) ( HWord iaddr
);
55 void VG_(helperc_invalidate_if_not_gdbserved
) ( Addr addr
);
56 static void invalidate_current_ip (ThreadId tid
, const HChar
*who
);
58 /* reasons of call to call_gdbserver. */
61 init_reason
, // initialises gdbserver resources
62 vgdb_reason
, // gdbserver invocation by vgdb doing ptrace
63 core_reason
, // gdbserver invocation by core (e.g. error encountered)
64 break_reason
, // break encountered
65 watch_reason
, // watchpoint detected by tool
66 signal_reason
, // signal encountered
67 exit_reason
} // process terminated
70 static const HChar
* ppCallReason(CallReason reason
)
73 case init_reason
: return "init_reason";
74 case vgdb_reason
: return "vgdb_reason";
75 case core_reason
: return "core_reason";
76 case break_reason
: return "break_reason";
77 case watch_reason
: return "watch_reason";
78 case signal_reason
: return "signal_reason";
79 case exit_reason
: return "exit_reason";
80 default: vg_assert (0);
84 /* An instruction instrumented for gdbserver looks like this:
87 3. helperc_CallDebugger (0x1234)
88 This will give control to gdb if there is a break at 0x1234
89 or if we are single stepping
90 4. ... here the real IR for the instruction at 0x1234
92 When there is a break at 0x1234:
93 if user does "continue" or "step" or similar,
94 then - the call to debugger returns
95 - valgrind executes at 3. the real IR(s) for 0x1234
97 if as part of helperc_CallDebugger, the user calls
98 some code in gdb e.g print hello_world()
99 then - gdb prepares a dummy stack frame with a specific
100 return address (typically it uses _start) and
101 inserts a break at this address
102 - gdb then puts in EIP the address of hello_world()
103 - gdb then continues (so the helperc_CallDebugger
105 - call_gdbserver() function will then return the
106 control to the scheduler (using VG_MINIMAL_LONGJMP)
107 to allow the block of the new EIP
109 - hello_world code is executed.
110 - when hello_world() returns, it returns to
111 _start and encounters the break at _start.
112 - gdb then removes this break, put 0x1234 in EIP
113 and does a "step". This causes to jump from
114 _start to 0x1234, where the call to
115 helperc_CallDebugger is redone.
116 - This is all ok, the user can then give new gdb
119 However, when continue is given, address 0x1234 is to
120 be executed: gdb gives a single step, which must not
121 report again the break at 0x1234. To avoid a 2nd report
122 of the same break, the below tells that the next
123 helperc_CallDebugger call must ignore a break/stop at
126 static Addr ignore_this_break_once
= 0;
129 static void call_gdbserver ( ThreadId tid
, CallReason reason
);
131 /* Describes the address addr (for debugging/printing purposes).
132 Last two results are kept. A third call will replace the
134 static HChar
* sym (Addr addr
, Bool is_code
)
136 static HChar
*buf
[2];
141 // sym is used for debugging/tracing, so cur_ep is a reasonable choice.
142 const DiEpoch cur_ep
= VG_(current_DiEpoch
)();
146 name
= VG_(describe_IP
) (cur_ep
, addr
, NULL
);
147 if (buf
[w
]) VG_(free
)(buf
[w
]);
148 buf
[w
] = VG_(strdup
)("gdbserver sym", name
);
151 VG_(get_datasym_and_offset
) (cur_ep
, addr
, &name
, &offset
);
152 if (buf
[w
]) VG_(free
)(buf
[w
]);
153 buf
[w
] = VG_(strdup
)("gdbserver sym", name
);
158 /* Each time gdbserver is called, gdbserver_called is incremented
159 gdbserver_exited is incremented when gdbserver is asked to exit */
160 static int gdbserver_called
= 0;
161 static int gdbserver_exited
= 0;
163 /* alloc and free functions for xarray and similar. */
164 static void* gs_alloc (const HChar
* cc
, SizeT sz
)
166 return VG_(malloc
)(cc
, sz
);
168 static void gs_free (void* ptr
)
182 struct _GS_Address
* next
;
188 /* gs_addresses contains a list of all addresses that have been invalidated
189 because they have been (or must be) instrumented for gdbserver.
190 An entry is added in this table when there is a break at this
191 address (kind == GS_break) or if this address is the jump target of an
192 exit of a block that has been instrumented for gdbserver while
193 single stepping (kind == GS_jump).
194 When gdbserver is not single stepping anymore, all GS_jump entries
195 are removed, their translations are invalidated.
197 Note for ARM: addr in GS_Address is the value without the thumb bit set.
199 static VgHashTable
*gs_addresses
= NULL
;
201 // Transform addr in the form stored in the list of addresses.
202 // For the ARM architecture, we store it with the thumb bit set to 0.
203 static Addr
HT_addr ( Addr addr
)
206 return addr
& ~(Addr
)1;
212 static void add_gs_address (Addr addr
, GS_Kind kind
, const HChar
* from
)
216 p
= VG_(malloc
)(from
, sizeof(GS_Address
));
217 p
->addr
= HT_addr (addr
);
219 VG_(HT_add_node
)(gs_addresses
, p
);
220 /* It should be sufficient to discard a range of 1.
221 We use 2 to ensure the below is not sensitive to the presence
222 of thumb bit in the range of addresses to discard.
223 No need to discard translations for Vg_VgdbFull as all
224 instructions are in any case vgdb-instrumented. */
225 if (VG_(clo_vgdb
) != Vg_VgdbFull
)
226 VG_(discard_translations
) (addr
, 2, from
);
229 static void remove_gs_address (GS_Address
* g
, const HChar
* from
)
231 VG_(HT_remove
) (gs_addresses
, g
->addr
);
232 // See add_gs_address for the explanation for condition and the range 2 below.
233 if (VG_(clo_vgdb
) != Vg_VgdbFull
)
234 VG_(discard_translations
) (g
->addr
, 2, from
);
238 const HChar
* VG_(ppPointKind
) (PointKind kind
)
241 case software_breakpoint
: return "software_breakpoint";
242 case hardware_breakpoint
: return "hardware_breakpoint";
243 case write_watchpoint
: return "write_watchpoint";
244 case read_watchpoint
: return "read_watchpoint";
245 case access_watchpoint
: return "access_watchpoint";
246 default: return "???wrong PointKind";
258 /* gs_watches contains a list of all addresses+len+kind that are being
260 static XArray
* gs_watches
= NULL
;
262 static inline GS_Watch
* index_gs_watches(Word i
)
264 return *(GS_Watch
**) VG_(indexXA
) (gs_watches
, i
);
267 /* Returns the GS_Watch matching addr/len/kind and sets *g_ix to its
268 position in gs_watches.
269 If no matching GS_Watch is found, returns NULL and sets g_ix to -1. */
270 static GS_Watch
* lookup_gs_watch (Addr addr
, SizeT len
, PointKind kind
,
273 const Word n_elems
= VG_(sizeXA
) (gs_watches
);
277 /* Linear search. If we have many watches, this might be optimised
278 by having the array sorted and using VG_(lookupXA) */
279 for (i
= 0; i
< n_elems
; i
++) {
280 g
= index_gs_watches(i
);
281 if (g
->addr
== addr
&& g
->len
== len
&& g
->kind
== kind
) {
294 /* protocol spec tells the below must be idempotent. */
295 static void breakpoint (Bool insert
, CORE_ADDR addr
)
299 g
= VG_(HT_lookup
) (gs_addresses
, (UWord
)HT_addr(addr
));
301 /* insert a breakpoint at addr or upgrade its kind */
303 add_gs_address (addr
, GS_break
, "m_gdbserver breakpoint insert");
305 /* already gdbserved. Normally, it must be because of a jump.
306 However, due to idempotent or if connection with gdb was
307 lost (kept breaks from the previous gdb), if already existing,
308 we just upgrade its kind. */
312 /* delete a breakpoint at addr or downgrade its kind */
313 if (g
!= NULL
&& g
->kind
== GS_break
) {
314 if (valgrind_single_stepping()) {
315 /* keep gdbserved instrumentation while single stepping */
318 remove_gs_address (g
, "m_gdbserver breakpoint remove");
321 dlog (1, "remove break addr %p %s\n",
322 C2v(addr
), (g
== NULL
?
324 (g
->kind
== GS_jump
? "GS_jump" : "GS_break")));
329 static Bool (*tool_watchpoint
) (PointKind kind
,
333 void VG_(needs_watchpoint
) (Bool (*watchpoint
) (PointKind kind
,
338 tool_watchpoint
= watchpoint
;
341 Bool
VG_(gdbserver_point
) (PointKind kind
, Bool insert
,
342 CORE_ADDR addr
, int len
)
347 Bool is_code
= kind
== software_breakpoint
|| kind
== hardware_breakpoint
;
349 dlog(1, "%s %s at addr %p %s\n",
350 (insert
? "insert" : "remove"),
351 VG_(ppPointKind
) (kind
),
356 breakpoint (insert
, addr
);
360 vg_assert (kind
== access_watchpoint
361 || kind
== read_watchpoint
362 || kind
== write_watchpoint
);
364 if (tool_watchpoint
== NULL
)
367 res
= (*tool_watchpoint
) (kind
, insert
, addr
, len
);
369 return False
; /* error or unsupported */
371 // Protocol says insert/remove must be idempotent.
372 // So, we just ignore double insert or (supposed) double delete.
374 g
= lookup_gs_watch (addr
, len
, kind
, &g_ix
);
377 g
= VG_(malloc
)("gdbserver_point watchpoint", sizeof(GS_Watch
));
381 VG_(addToXA
)(gs_watches
, &g
);
384 "VG_(gdbserver_point) addr %p len %d kind %s already inserted\n",
385 C2v(addr
), len
, VG_(ppPointKind
) (kind
));
389 VG_(removeIndexXA
) (gs_watches
, g_ix
);
393 "VG_(gdbserver_point) addr %p len %d kind %s already deleted?\n",
394 C2v(addr
), len
, VG_(ppPointKind
) (kind
));
400 Bool
VG_(has_gdbserver_breakpoint
) (Addr addr
)
403 if (!gdbserver_called
)
405 g
= VG_(HT_lookup
) (gs_addresses
, (UWord
)HT_addr(addr
));
406 return (g
!= NULL
&& g
->kind
== GS_break
);
409 Bool
VG_(is_watched
)(PointKind kind
, Addr addr
, Int szB
)
414 Bool watched
= False
;
415 const ThreadId tid
= VG_(running_tid
);
417 if (!gdbserver_called
)
420 n_elems
= VG_(sizeXA
) (gs_watches
);
422 Addr to
= addr
+ szB
; // semi-open interval [addr, to[
424 vg_assert (kind
== access_watchpoint
425 || kind
== read_watchpoint
426 || kind
== write_watchpoint
);
427 dlog(1, "tid %u VG_(is_watched) %s addr %p szB %d\n",
428 tid
, VG_(ppPointKind
) (kind
), C2v(addr
), szB
);
430 for (i
= 0; i
< n_elems
; i
++) {
431 g
= index_gs_watches(i
);
433 case software_breakpoint
:
434 case hardware_breakpoint
:
436 case access_watchpoint
:
437 case read_watchpoint
:
438 case write_watchpoint
:
439 if (to
<= g
->addr
|| addr
>= (g
->addr
+ g
->len
))
440 /* If no overlap, examine next watchpoint: */
443 watched
= True
; /* We have an overlap */
445 /* call gdbserver if access kind reported by the tool
446 matches the watchpoint kind. */
447 if (kind
== access_watchpoint
448 || g
->kind
== access_watchpoint
449 || g
->kind
== kind
) {
450 /* Watchpoint encountered.
451 If this is a read watchpoint, we directly call gdbserver
453 Otherwise, for a write watchpoint, we have to finish
454 the instruction so as to modify the value.
455 If we do not finish the instruction, then gdb sees no
456 value change and continues.
457 For a read watchpoint, we better call gdbserver directly:
458 in case the current block is not gdbserved, Valgrind
459 will execute instructions till the next block. */
461 /* set the watchpoint stop address to the first read or written. */
462 if (g
->addr
<= addr
) {
463 VG_(set_watchpoint_stop_address
) (addr
);
465 VG_(set_watchpoint_stop_address
) (g
->addr
);
468 if (kind
== write_watchpoint
) {
469 /* Let Valgrind stop as early as possible after this instruction
470 by switching to Single Stepping mode. */
471 valgrind_set_single_stepping (True
);
472 invalidate_current_ip (tid
, "m_gdbserver write watchpoint");
474 call_gdbserver (tid
, watch_reason
);
475 VG_(set_watchpoint_stop_address
) ((Addr
) 0);
477 return True
; // we are watched here.
487 /* Returns the reason for which gdbserver instrumentation is needed */
488 static VgVgdb
VG_(gdbserver_instrumentation_needed
) (const VexGuestExtents
* vge
)
493 if (!gdbserver_called
)
496 if (valgrind_single_stepping()) {
497 dlog(2, "gdbserver_instrumentation_needed due to single stepping\n");
501 if (VG_(clo_vgdb
) == Vg_VgdbYes
&& VG_(HT_count_nodes
) (gs_addresses
) == 0)
504 /* We assume we do not have a huge nr of breakpoints.
505 Otherwise, we need something more efficient e.g.
506 a sorted list of breakpoints or associate extents to it or ...
508 VG_(HT_ResetIter
) (gs_addresses
);
509 while ((g
= VG_(HT_Next
) (gs_addresses
))) {
510 for (e
= 0; e
< vge
->n_used
; e
++) {
511 if (g
->addr
>= HT_addr(vge
->base
[e
])
512 && g
->addr
< HT_addr(vge
->base
[e
]) + vge
->len
[e
]) {
514 "gdbserver_instrumentation_needed %p %s reason %s\n",
515 C2v(g
->addr
), sym(g
->addr
, /* is_code */ True
),
516 (g
->kind
== GS_jump
? "GS_jump" : "GS_break"));
522 if (VG_(clo_vgdb
) == Vg_VgdbFull
) {
523 dlog(4, "gdbserver_instrumentation_needed"
524 " due to VG_(clo_vgdb) == Vg_VgdbFull\n");
532 // Clear gdbserved_addresses in gs_addresses.
533 // If clear_only_jumps, clears only the addresses that are served
535 // Otherwise, clear all the addresses.
536 // Cleared addresses are invalidated so as to have them re-translated.
537 static void clear_gdbserved_addresses(Bool clear_only_jumps
)
544 "clear_gdbserved_addresses: scanning hash table nodes %u\n",
545 VG_(HT_count_nodes
) (gs_addresses
));
546 ag
= (GS_Address
**) VG_(HT_to_array
) (gs_addresses
, &n_elems
);
547 for (i
= 0; i
< n_elems
; i
++)
548 if (!clear_only_jumps
|| ag
[i
]->kind
== GS_jump
)
549 remove_gs_address (ag
[i
], "clear_gdbserved_addresses");
553 // Clear watched addressed in gs_watches, delete gs_watches.
554 static void clear_watched_addresses(void)
557 const Word n_elems
= VG_(sizeXA
) (gs_watches
);
561 "clear_watched_addresses: %ld elements\n",
564 for (i
= 0; i
< n_elems
; i
++) {
565 g
= index_gs_watches(i
);
566 if (!VG_(gdbserver_point
) (g
->kind
,
574 VG_(deleteXA
) (gs_watches
);
578 static void invalidate_if_jump_not_yet_gdbserved (Addr addr
, const HChar
* from
)
580 if (VG_(HT_lookup
) (gs_addresses
, (UWord
)HT_addr(addr
)))
582 add_gs_address (addr
, GS_jump
, from
);
585 static void invalidate_current_ip (ThreadId tid
, const HChar
*who
)
587 invalidate_if_jump_not_yet_gdbserved (VG_(get_IP
) (tid
), who
);
590 Bool
VG_(gdbserver_init_done
) (void)
592 return gdbserver_called
> 0;
595 Bool
VG_(gdbserver_stop_at
) (VgdbStopAt stopat
)
597 return gdbserver_called
> 0 && VgdbStopAtiS(stopat
, VG_(clo_vgdb_stop_at
));
600 void VG_(gdbserver_prerun_action
) (ThreadId tid
)
602 // Using VG_(clo_vgdb_error) allows the user to control if gdbserver
603 // stops after a fork.
604 if (VG_(clo_vgdb_error
) == 0
605 || VgdbStopAtiS(VgdbStopAt_Startup
, VG_(clo_vgdb_stop_at
))) {
606 /* The below call allows gdb to attach at startup
607 before the first guest instruction is executed. */
608 VG_(umsg
)("(action at startup) vgdb me ... \n");
611 /* User has activated gdbserver => initialize now the FIFOs
612 to let vgdb/gdb contact us either via the scheduler poll
613 mechanism or via vgdb ptrace-ing valgrind. */
614 if (VG_(gdbserver_activity
) (tid
))
615 VG_(gdbserver
) (tid
);
619 /* when fork is done, various cleanup is needed in the child process.
620 In particular, child must have its own connection to avoid stealing
621 data from its parent */
622 static void gdbserver_cleanup_in_child_after_fork(ThreadId me
)
624 dlog(1, "thread %u gdbserver_cleanup_in_child_after_fork pid %d\n",
627 /* finish connection inheritated from parent */
628 remote_finish(reset_after_fork
);
630 /* ensure next call to gdbserver will be considered as a brand
631 new call that will initialize a fresh gdbserver. */
632 if (gdbserver_called
) {
633 gdbserver_called
= 0;
634 vg_assert (gs_addresses
!= NULL
);
635 vg_assert (gs_watches
!= NULL
);
636 clear_gdbserved_addresses(/* clear only jumps */ False
);
637 VG_(HT_destruct
) (gs_addresses
, VG_(free
));
639 clear_watched_addresses();
641 vg_assert (gs_addresses
== NULL
);
642 vg_assert (gs_watches
== NULL
);
646 if (VG_(clo_trace_children
)) {
647 VG_(gdbserver_prerun_action
) (me
);
649 /* After fork, if we do not trace the children, disable vgdb
650 poll to avoid gdbserver being called unexpectedly. */
651 VG_(disable_vgdb_poll
) ();
655 /* If reason is init_reason, creates the connection resources (e.g.
656 the FIFOs) to allow a gdb connection to be detected by polling
657 using remote_desc_activity.
658 Otherwise (other reasons):
659 If connection with gdb not yet opened, opens the connection with gdb.
660 reads gdb remote protocol packets and executes the requested commands.
662 static void call_gdbserver ( ThreadId tid
, CallReason reason
)
664 ThreadState
* tst
= VG_(get_ThreadState
)(tid
);
669 "entering call_gdbserver %s ... pid %d tid %u status %s "
670 "sched_jmpbuf_valid %d\n",
671 ppCallReason (reason
),
672 VG_(getpid
) (), tid
, VG_(name_of_ThreadStatus
)(tst
->status
),
673 tst
->sched_jmpbuf_valid
);
675 /* If we are about to die, then just run server_main() once to get
676 the resume reply out and return immediately because most of the state
677 of this tid and process is about to be torn down. */
678 if (reason
== exit_reason
) {
683 vg_assert(VG_(is_valid_tid
)(tid
));
684 saved_pc
= VG_(get_IP
) (tid
);
686 if (gdbserver_exited
) {
687 dlog(0, "call_gdbserver called when gdbserver_exited %d\n",
692 if (gdbserver_called
== 0) {
693 vg_assert (gs_addresses
== NULL
);
694 vg_assert (gs_watches
== NULL
);
695 gs_addresses
= VG_(HT_construct
)( "gdbserved_addresses" );
696 gs_watches
= VG_(newXA
)(gs_alloc
,
700 VG_(atfork
)(NULL
, NULL
, gdbserver_cleanup_in_child_after_fork
);
702 vg_assert (gs_addresses
!= NULL
);
703 vg_assert (gs_watches
!= NULL
);
707 /* call gdbserver_init if this is the first call to gdbserver. */
708 if (gdbserver_called
== 1)
711 if (reason
== init_reason
|| gdbserver_called
== 1)
712 remote_open(VG_(clo_vgdb_prefix
));
714 /* if the call reason is to initialize, then return control to
715 valgrind. After this initialization, gdbserver will be called
716 again either if there is an error detected by valgrind or
717 if vgdb sends data to the valgrind process. */
718 if (reason
== init_reason
) {
722 stepping
= valgrind_single_stepping();
726 ignore_this_break_once
= valgrind_get_ignore_break_once();
727 if (ignore_this_break_once
)
728 dlog(1, "!!! will ignore_this_break_once %s\n",
729 sym(ignore_this_break_once
, /* is_code */ True
));
732 if (valgrind_single_stepping()) {
733 /* we are single stepping. If we were not stepping on entry,
734 then invalidate the current program counter so as to properly
735 do single step. In case the program counter was changed by
736 gdb, this will also invalidate the target address we will
738 if (!stepping
&& tid
!= 0) {
739 invalidate_current_ip (tid
, "m_gdbserver single step");
742 /* We are not single stepping. If we were stepping on entry,
743 then clear the gdbserved addresses. This will cause all
744 these gdbserved blocks to be invalidated so that they can be
745 re-translated without being gdbserved. */
747 clear_gdbserved_addresses(/* clear only jumps */ True
);
750 /* can't do sanity check at beginning. At least the stack
751 check is not yet possible. */
752 if (gdbserver_called
> 1)
753 VG_(sanity_check_general
) (/* force_expensive */ False
);
755 /* If the PC has been changed by gdb, then we VG_MINIMAL_LONGJMP to
756 the scheduler to execute the block of the new PC.
757 Otherwise we just return to continue executing the
759 if (VG_(get_IP
) (tid
) != saved_pc
) {
760 dlog(1, "tid %u %s PC changed from %s to %s\n",
761 tid
, VG_(name_of_ThreadStatus
) (tst
->status
),
762 sym(saved_pc
, /* is_code */ True
),
763 sym(VG_(get_IP
) (tid
), /* is_code */ True
));
764 if (tst
->status
== VgTs_Yielding
) {
766 VG_(memset
)(&sres
, 0, sizeof(SysRes
));
767 VG_(acquire_BigLock
)(tid
, "gdbsrv VG_MINIMAL_LONGJMP");
769 if (tst
->sched_jmpbuf_valid
) {
770 /* resume scheduler */
771 VG_MINIMAL_LONGJMP(tst
->sched_jmpbuf
);
773 /* else continue to run */
775 /* continue to run */
778 /* busy > 0 when gdbserver is currently being called.
779 busy is used to avoid vgdb invoking gdbserver
780 while gdbserver by Valgrind. */
781 static volatile int busy
= 0;
783 void VG_(gdbserver
) ( ThreadId tid
)
786 /* called by the rest of valgrind for
787 --vgdb-error=0 reason
788 or by scheduler "poll/debug/interrupt" reason
791 call_gdbserver (tid
, core_reason
);
793 if (gdbserver_called
== 0) {
794 dlog(1, "VG_(gdbserver) called to terminate, nothing to terminate\n");
795 } else if (gdbserver_exited
) {
796 dlog(1, "VG_(gdbserver) called to terminate again %d\n",
799 gdbserver_terminate();
806 // nr of invoke_gdbserver while gdbserver is already executing.
807 static int interrupts_while_busy
= 0;
809 // nr of invoke_gdbserver while gdbserver is not executing.
810 static int interrupts_non_busy
= 0;
812 // nr of invoke_gdbserver when some threads are not interruptible.
813 static int interrupts_non_interruptible
= 0;
815 /* When all threads are blocked in a system call, the Valgrind
816 scheduler cannot poll the shared memory for gdbserver activity. In
817 such a case, vgdb will force the invocation of gdbserver using
818 ptrace. To do that, vgdb 'pushes' a call to invoke_gdbserver
819 on the stack using ptrace. invoke_gdbserver must not return.
820 Instead, it must call give_control_back_to_vgdb.
821 vgdb expects to receive a SIGSTOP, which this function generates.
822 When vgdb gets this SIGSTOP, it knows invoke_gdbserver call
823 is finished and can reset the Valgrind process in the state prior to
824 the 'pushed call' (using ptrace again).
825 This all works well. However, the user must avoid
826 'kill-9ing' vgdb during such a pushed call, otherwise
827 the SIGSTOP generated below will be seen by the Valgrind core,
828 instead of being handled by vgdb. The OS will then handle the SIGSTOP
829 by stopping the Valgrind process.
830 We use SIGSTOP as this process cannot be masked. */
832 static void give_control_back_to_vgdb(void)
834 #if !defined(VGO_solaris)
835 /* cause a SIGSTOP to be sent to ourself, so that vgdb takes control.
836 vgdb will then restore the stack so as to resume the activity
837 before the ptrace (typically do_syscall_WRK). */
838 if (VG_(kill
)(VG_(getpid
)(), VKI_SIGSTOP
) != 0)
839 vg_assert2(0, "SIGSTOP for vgdb could not be generated\n");
841 /* If we arrive here, it means a call was pushed on the stack
842 by vgdb, but during this call, vgdb and/or connection
843 died. Alternatively, it is a bug in the vgdb<=>Valgrind gdbserver
846 "vgdb did not took control. Did you kill vgdb ?\n"
847 "busy %d vgdb_interrupted_tid %u\n",
848 busy
, vgdb_interrupted_tid
);
849 #else /* defined(VGO_solaris) */
850 /* On Solaris, this code is run within the context of an agent thread
851 (see vgdb-invoker-solaris.c and "PCAGENT" control message in
852 proc(4)). Exit the agent thread now.
854 SysRes sres
= VG_(do_syscall0
)(SYS_lwp_exit
);
855 if (sr_isError(sres
))
856 vg_assert2(0, "The agent thread could not be exited\n");
857 #endif /* !defined(VGO_solaris) */
860 /* Using ptrace calls, vgdb will force an invocation of gdbserver.
861 VG_(invoke_gdbserver) is the entry point called through the
862 vgdb ptrace technique. */
863 void VG_(invoke_gdbserver
) ( int check
)
865 /* ******* Avoid non-reentrant function call from here .....
866 till the ".... till here" below. */
868 /* We need to determine the state of the various threads to decide
869 if we directly invoke gdbserver or if we rather indicate to the
870 scheduler to invoke the gdbserver. To decide that, it is
871 critical to avoid any "coregrind" function call as the ptrace
872 might have stopped the process in the middle of this (possibly)
873 non-rentrant function. So, it is only when all threads are in
874 an "interruptible" state that we can safely invoke
875 gdbserver. Otherwise, we let the valgrind scheduler invoke
876 gdbserver at the next poll. This poll will be made very soon
877 thanks to a call to VG_(force_vgdb_poll). */
878 int n_tid
, vgdb_interrupted_tid_local
= 0;
880 vg_assert (check
== 0x8BADF00D);
883 interrupts_while_busy
++;
884 give_control_back_to_vgdb();
886 interrupts_non_busy
++;
888 /* check if all threads are in an "interruptible" state. If yes,
889 we invoke gdbserver. Otherwise, we tell the scheduler to wake up
891 for (n_tid
= 1; n_tid
< VG_N_THREADS
; n_tid
++) {
892 switch (VG_(threads
)[n_tid
].status
) {
893 /* interruptible states. */
896 if (vgdb_interrupted_tid_local
== 0)
897 vgdb_interrupted_tid_local
= n_tid
;
904 /* non interruptible states. */
907 interrupts_non_interruptible
++;
908 VG_(force_vgdb_poll
) ();
909 give_control_back_to_vgdb();
910 /* If give_control_back_to_vgdb returns in an non interruptable
911 state something went horribly wrong, fallthrough to vg_assert. */
912 default: vg_assert(0);
916 vgdb_interrupted_tid
= vgdb_interrupted_tid_local
;
919 From here onwards, function calls are ok: it is
920 safe to call valgrind core functions: all threads are blocked in
921 a system call or are yielding or ... */
922 dlog(1, "invoke_gdbserver running_tid %u vgdb_interrupted_tid %u\n",
923 VG_(running_tid
), vgdb_interrupted_tid
);
924 call_gdbserver (vgdb_interrupted_tid
, vgdb_reason
);
925 vgdb_interrupted_tid
= 0;
927 "exit invoke_gdbserver running_tid %u\n", VG_(running_tid
));
928 give_control_back_to_vgdb();
930 vg_assert2(0, "end of invoke_gdbserver reached");
934 Bool
VG_(gdbserver_activity
) (ThreadId tid
)
938 if (!gdbserver_called
)
939 call_gdbserver (tid
, init_reason
);
940 switch (remote_desc_activity("VG_(gdbserver_activity)")) {
941 case 0: ret
= False
; break;
942 case 1: ret
= True
; break;
944 remote_finish(reset_after_error
);
945 call_gdbserver (tid
, init_reason
);
948 default: vg_assert (0);
954 static void dlog_signal (const HChar
*who
, const vki_siginfo_t
*info
,
957 dlog(1, "VG core calling %s "
958 "vki_nr %d %s gdb_nr %u %s tid %u\n",
960 info
->si_signo
, VG_(signame
)(info
->si_signo
),
961 target_signal_from_host (info
->si_signo
),
962 target_signal_to_name(target_signal_from_host (info
->si_signo
)),
967 void VG_(gdbserver_report_fatal_signal
) (const vki_siginfo_t
*info
,
970 dlog_signal("VG_(gdbserver_report_fatal_signal)", info
, tid
);
972 if (remote_connected()) {
973 dlog(1, "already connected, assuming already reported\n");
977 VG_(umsg
)("(action on fatal signal) vgdb me ... \n");
979 /* indicate to gdbserver that there is a signal */
980 gdbserver_signal_encountered (info
);
982 /* let gdbserver do some work, e.g. show the signal to the user */
983 call_gdbserver (tid
, signal_reason
);
987 Bool
VG_(gdbserver_report_signal
) (vki_siginfo_t
*info
, ThreadId tid
)
989 dlog_signal("VG_(gdbserver_report_signal)", info
, tid
);
991 /* if gdbserver is currently not connected, then signal
992 is to be given to the process */
993 if (!remote_connected()) {
994 dlog(1, "not connected => pass\n");
997 /* if gdb has informed gdbserver that this signal can be
998 passed directly without informing gdb, then signal is
999 to be given to the process. */
1000 if (pass_signals
[target_signal_from_host(info
->si_signo
)]) {
1001 dlog(1, "pass_signals => pass\n");
1005 /* indicate to gdbserver that there is a signal */
1006 gdbserver_signal_encountered (info
);
1008 /* let gdbserver do some work, e.g. show the signal to the user.
1009 User can also decide to ignore the signal or change the signal. */
1010 call_gdbserver (tid
, signal_reason
);
1012 /* ask gdbserver what is the final decision */
1013 if (gdbserver_deliver_signal (info
)) {
1014 dlog(1, "gdbserver deliver signal\n");
1017 dlog(1, "gdbserver ignore signal\n");
1022 Bool catching_syscalls
= False
; // True if catching all or some syscalls.
1023 /* If catching_syscalls is True, then syscalls_to_catch_size == 0 means
1024 to catch all syscalls. Otherwise, it is the size of the syscalls_to_catch
1026 Int syscalls_to_catch_size
= 0;
1027 Int
*syscalls_to_catch
;
1028 static Bool
catch_this_syscall (Int sysno
)
1032 if (syscalls_to_catch_size
== 0)
1035 for (i
= 0; i
< syscalls_to_catch_size
; i
++)
1036 if (syscalls_to_catch
[i
] == sysno
)
1042 void VG_(gdbserver_report_syscall
) (Bool before
, UWord sysno
, ThreadId tid
)
1044 dlog(4, "VG_(gdbserver_report_syscall) before %d sysno %lu tid %u\n",
1045 before
, sysno
, tid
);
1047 if (UNLIKELY(catching_syscalls
)) {
1048 if (!remote_connected()) {
1049 dlog(2, "not connected => no report\n");
1052 if (catch_this_syscall ((Int
)sysno
)) {
1053 /* let gdbserver do some work */
1054 gdbserver_syscall_encountered (before
, (Int
)sysno
);
1055 call_gdbserver (tid
, signal_reason
);
1060 void VG_(gdbserver_exit
) (ThreadId tid
, VgSchedReturnCode tids_schedretcode
)
1062 dlog(1, "VG core calling VG_(gdbserver_exit) tid %u will exit\n", tid
);
1063 if (remote_connected()) {
1064 /* Make sure vgdb knows we are about to die and why. */
1065 switch(tids_schedretcode
) {
1068 case VgSrc_ExitThread
:
1069 case VgSrc_ExitProcess
:
1070 gdbserver_process_exit_encountered
1071 ('W', VG_(threads
)[tid
].os_state
.exitcode
);
1072 call_gdbserver (tid
, exit_reason
);
1074 case VgSrc_FatalSig
:
1075 gdbserver_process_exit_encountered
1076 ('X', VG_(threads
)[tid
].os_state
.fatalsig
);
1077 call_gdbserver (tid
, exit_reason
);
1083 dlog(1, "not connected\n");
1086 /* Tear down the connection if it still exists. */
1090 // Check if single_stepping or if there is a break requested at iaddr.
1091 // If yes, call debugger
1093 void VG_(helperc_CallDebugger
) ( HWord iaddr
)
1097 // For Vg_VgdbFull, after a fork, we might have calls to this helper
1098 // while gdbserver is not yet initialized.
1099 if (!gdbserver_called
)
1102 if (valgrind_single_stepping() ||
1103 ((g
= VG_(HT_lookup
) (gs_addresses
, (UWord
)HT_addr(iaddr
))) &&
1104 (g
->kind
== GS_break
))) {
1105 if (iaddr
== HT_addr(ignore_this_break_once
)) {
1106 dlog(1, "ignoring ignore_this_break_once %s\n",
1107 sym(ignore_this_break_once
, /* is_code */ True
));
1108 ignore_this_break_once
= 0;
1110 call_gdbserver (VG_(get_running_tid
)(), break_reason
);
1115 /* software_breakpoint support --------------------------------------*/
1116 /* When a block is instrumented for gdbserver, single step and breaks
1117 will be obeyed in this block. However, if a jump to another block
1118 is executed while single_stepping is active, we must ensure that
1119 this block is also instrumented. For this, when a block is
1120 instrumented for gdbserver while single_stepping, the target of all
1121 the Jump instructions in this block will be checked to verify if
1122 the block is already instrumented for gdbserver. The below will
1123 ensure that if not already instrumented for gdbserver, the target
1124 block translation containing addr will be invalidated. The list of
1125 gdbserved Addr will also be kept so that translations can be
1126 dropped automatically by gdbserver when going out of single step
1129 Call the below at translation time if the jump target is a constant.
1130 Otherwise, rather use VG_(add_stmt_call_invalidate_if_not_gdbserved).
1132 To instrument the target exit statement, you can call
1133 VG_(add_stmt_call_invalidate_exit_target_if_not_gdbserved) rather
1134 than check the kind of target exit. */
1135 static void VG_(invalidate_if_not_gdbserved
) (Addr addr
)
1137 if (valgrind_single_stepping())
1138 invalidate_if_jump_not_yet_gdbserved
1139 (addr
, "gdbserver target jump (instrument)");
1142 // same as VG_(invalidate_if_not_gdbserved) but is intended to be called
1143 // at runtime (only difference is the invalidate reason which traces
1144 // it is at runtime)
1146 void VG_(helperc_invalidate_if_not_gdbserved
) ( Addr addr
)
1148 if (valgrind_single_stepping())
1149 invalidate_if_jump_not_yet_gdbserved
1150 (addr
, "gdbserver target jump (runtime)");
1153 static void VG_(add_stmt_call_invalidate_if_not_gdbserved
)
1155 const VexGuestLayout
* layout
,
1156 const VexGuestExtents
* vge
,
1167 fn
= &VG_(helperc_invalidate_if_not_gdbserved
);
1168 nm
= "VG_(helperc_invalidate_if_not_gdbserved)";
1169 args
= mkIRExprVec_1(IRExpr_RdTmp (jmp
));
1172 di
= unsafeIRDirty_0_N( nargs
/*regparms*/, nm
,
1173 VG_(fnptr_to_fnentry
)( fn
), args
);
1177 addStmtToIRSB(irsb
, IRStmt_Dirty(di
));
1180 /* software_breakpoint support --------------------------------------*/
1181 /* If a tool wants to allow gdbserver to do something at Addr, then
1182 VG_(add_stmt_call_gdbserver) will add in IRSB a call to a helper
1183 function. This helper function will check if the process must be
1184 stopped at the instruction Addr: either there is a break at Addr or
1185 the process is being single-stepped. Typical usage of the below is to
1186 instrument an Ist_IMark to allow the debugger to interact at any
1187 instruction being executed. As soon as there is one break in a block,
1188 then to allow single stepping in this block (and possible insertions
1189 of other breaks in the same sb_in while the process is stopped), a
1190 debugger statement will be inserted for all instructions of a block. */
1191 static void VG_(add_stmt_call_gdbserver
)
1192 (IRSB
* sb_in
, /* block being translated */
1193 const VexGuestLayout
* layout
,
1194 const VexGuestExtents
* vge
,
1195 IRType gWordTy
, IRType hWordTy
,
1196 Addr iaddr
, /* Addr of instruction being instrumented */
1197 UChar delta
, /* delta to add to iaddr to obtain IP */
1198 IRSB
* irsb
) /* irsb block to which call is added */
1206 /* first store the address in the program counter so that the check
1207 done by VG_(helperc_CallDebugger) will be based on the correct
1208 program counter. We might make this more efficient by rather
1209 searching for assignement to program counter and instrumenting
1210 that but the below is easier and I guess that the optimiser will
1211 remove the redundant store. And in any case, when debugging a
1212 piece of code, the efficiency requirement is not critical: very
1213 few blocks will be instrumented for debugging. */
1215 /* For platforms on which the IP can differ from the addr of the instruction
1216 being executed, we need to add the delta to obtain the IP.
1217 This IP will be given to gdb (e.g. if a breakpoint is put at iaddr).
1219 For ARM, this delta will ensure that the thumb bit is set in the
1220 IP when executing thumb code. gdb uses this thumb bit a.o.
1221 to properly guess the next IP for the 'step' and 'stepi' commands. */
1222 vg_assert(delta
<= 1);
1223 addStmtToIRSB(irsb
, IRStmt_Put(layout
->offset_IP
,
1224 mkIRExpr_HWord(iaddr
+ (Addr
)delta
)));
1226 fn
= &VG_(helperc_CallDebugger
);
1227 nm
= "VG_(helperc_CallDebugger)";
1228 args
= mkIRExprVec_1(mkIRExpr_HWord (iaddr
));
1231 di
= unsafeIRDirty_0_N( nargs
/*regparms*/, nm
,
1232 VG_(fnptr_to_fnentry
)( fn
), args
);
1234 /* Note: in fact, a debugger call can read whatever register
1235 or memory. It can also write whatever register or memory.
1236 So, in theory, we have to indicate the whole universe
1237 can be read and modified. It is however not critical
1238 to indicate precisely what is being read/written
1239 as such indications are needed for tool error detection
1240 and we do not want to have errors being detected for
1241 gdb interactions. */
1244 di
->fxState
[0].fx
= Ifx_Read
;
1245 di
->fxState
[0].offset
= layout
->offset_SP
;
1246 di
->fxState
[0].size
= layout
->sizeof_SP
;
1247 di
->fxState
[0].nRepeats
= 0;
1248 di
->fxState
[0].repeatLen
= 0;
1249 di
->fxState
[1].fx
= Ifx_Modify
;
1250 di
->fxState
[1].offset
= layout
->offset_IP
;
1251 di
->fxState
[1].size
= layout
->sizeof_IP
;
1252 di
->fxState
[1].nRepeats
= 0;
1253 di
->fxState
[1].repeatLen
= 0;
1255 addStmtToIRSB(irsb
, IRStmt_Dirty(di
));
1260 /* Invalidate the target of the exit if needed:
1261 If target is constant, it is invalidated at translation time.
1262 Otherwise, a call to a helper function is generated to invalidate
1263 the translation at run time.
1264 The below is thus calling either VG_(invalidate_if_not_gdbserved)
1265 or VG_(add_stmt_call_invalidate_if_not_gdbserved). */
1266 static void VG_(add_stmt_call_invalidate_exit_target_if_not_gdbserved
)
1268 const VexGuestLayout
* layout
,
1269 const VexGuestExtents
* vge
,
1273 if (sb_in
->next
->tag
== Iex_Const
) {
1274 VG_(invalidate_if_not_gdbserved
) (gWordTy
== Ity_I64
?
1275 sb_in
->next
->Iex
.Const
.con
->Ico
.U64
1276 : sb_in
->next
->Iex
.Const
.con
->Ico
.U32
);
1277 } else if (sb_in
->next
->tag
== Iex_RdTmp
) {
1278 VG_(add_stmt_call_invalidate_if_not_gdbserved
)
1279 (sb_in
, layout
, vge
, sb_in
->next
->Iex
.RdTmp
.tmp
, irsb
);
1281 vg_assert (0); /* unexpected expression tag in exit. */
1285 IRSB
* VG_(instrument_for_gdbserver_if_needed
)
1287 const VexGuestLayout
* layout
,
1288 const VexGuestExtents
* vge
,
1289 IRType gWordTy
, IRType hWordTy
)
1293 const VgVgdb instr_needed
= VG_(gdbserver_instrumentation_needed
) (vge
);
1295 if (instr_needed
== Vg_VgdbNo
)
1299 /* here, we need to instrument for gdbserver */
1300 sb_out
= deepCopyIRSBExceptStmts(sb_in
);
1302 for (i
= 0; i
< sb_in
->stmts_used
; i
++) {
1303 IRStmt
* st
= sb_in
->stmts
[i
];
1305 if (!st
|| st
->tag
== Ist_NoOp
) continue;
1307 if (st
->tag
== Ist_Exit
&& instr_needed
== Vg_VgdbYes
) {
1308 VG_(invalidate_if_not_gdbserved
)
1309 (hWordTy
== Ity_I64
?
1310 st
->Ist
.Exit
.dst
->Ico
.U64
:
1311 st
->Ist
.Exit
.dst
->Ico
.U32
);
1313 addStmtToIRSB( sb_out
, st
);
1314 if (st
->tag
== Ist_IMark
) {
1315 /* For an Ist_Mark, add a call to debugger. */
1316 switch (instr_needed
) {
1317 case Vg_VgdbNo
: vg_assert (0);
1320 VG_(add_stmt_call_gdbserver
) ( sb_in
, layout
, vge
,
1323 st
->Ist
.IMark
.delta
,
1325 /* There is an optimisation possible here for Vg_VgdbFull:
1326 Put a guard ensuring we only call gdbserver if 'FullCallNeeded'.
1327 FullCallNeeded would be set to 1 we have just switched on
1328 Single Stepping or have just encountered a watchpoint
1329 or have just inserted a breakpoint.
1330 (as gdb by default removes and re-insert breakpoints), we would
1331 need to also implement the notion of 'breakpoint pending removal'
1332 to remove at the next 'continue/step' packet. */
1334 default: vg_assert (0);
1339 if (instr_needed
== Vg_VgdbYes
) {
1340 VG_(add_stmt_call_invalidate_exit_target_if_not_gdbserved
) (sb_in
,
1349 struct mon_out_buf
{
1350 HChar buf
[DATASIZ
+1];
1355 static void mon_out (HChar c
, void *opaque
)
1357 struct mon_out_buf
*b
= (struct mon_out_buf
*) opaque
;
1359 b
->buf
[b
->next
] = c
;
1361 if (b
->next
== DATASIZ
) {
1362 b
->buf
[b
->next
] = '\0';
1363 monitor_output(b
->buf
);
1367 UInt
VG_(gdb_printf
) ( const HChar
*format
, ... )
1369 struct mon_out_buf b
;
1375 va_start(vargs
, format
);
1376 VG_(vcbprintf
) (mon_out
, &b
, format
, vargs
);
1380 b
.buf
[b
.next
] = '\0';
1381 monitor_output(b
.buf
);
1386 Int
VG_(keyword_id
) (const HChar
* keywords
, const HChar
* input_word
,
1387 kwd_report_error report
)
1389 const Int il
= (input_word
== NULL
? 0 : VG_(strlen
) (input_word
));
1391 HChar kwds
[VG_(strlen
)(keywords
)+1];
1394 HChar
* kw
; /* current keyword, its length, its position */
1399 /* pass 0 = search, optional pass 1 = output message multiple matches */
1401 Int pass1needed
= 0;
1403 Int partial_match
= -1;
1404 Int full_match
= -1;
1406 if (input_word
== NULL
) {
1408 partial_match
= 0; /* to force an empty string to cause an error */
1410 VG_(strcpy
) (iw
, input_word
);
1413 for (pass
= 0; pass
< 2; pass
++) {
1414 VG_(strcpy
) (kwds
, keywords
);
1416 VG_(gdb_printf
) ("%s can match",
1417 (il
== 0 ? "<empty string>" : iw
));
1418 for (kw
= VG_(strtok_r
) (kwds
, " ", &kwdssaveptr
);
1420 kw
= VG_(strtok_r
) (NULL
, " ", &kwdssaveptr
)) {
1421 kwl
= VG_(strlen
) (kw
);
1425 ; /* ishtar !~ is */
1426 } else if (il
== kwl
) {
1427 if (VG_(strcmp
) (kw
, iw
) == 0) {
1430 VG_(gdb_printf
) (" %s", kw
);
1431 if (full_match
!= -1)
1437 if (VG_(strncmp
) (iw
, kw
, il
) == 0) {
1440 VG_(gdb_printf
) (" %s", kw
);
1441 if (partial_match
!= -1)
1443 partial_match
= kpos
;
1447 /* check for success or for no match at all */
1448 if (pass1needed
== 0) {
1449 if (full_match
!= -1) {
1452 if (report
== kwd_report_all
&& partial_match
== -1) {
1453 VG_(gdb_printf
) ("%s does not match any of '%s'\n",
1456 return partial_match
;
1460 /* here we have duplicated match error */
1461 if (pass
== 1 || report
== kwd_report_none
) {
1462 if (report
!= kwd_report_none
) {
1463 VG_(gdb_printf
) ("\n");
1465 if (partial_match
!= -1 || full_match
!= -1)
1475 /* True if string can be a 0x number */
1476 static Bool
is_zero_x (const HChar
*s
)
1478 if (strlen (s
) >= 3 && s
[0] == '0' && s
[1] == 'x')
1484 /* True if string can be a 0b number */
1485 static Bool
is_zero_b (const HChar
*s
)
1487 if (strlen (s
) >= 3 && s
[0] == '0' && s
[1] == 'b')
1493 Bool
VG_(strtok_get_address_and_size
) (Addr
* address
,
1502 wa
= VG_(strtok_r
) (NULL
, " [", ssaveptr
);
1504 if (ppc
== NULL
|| !VG_(parse_Addr
) (&ppc
, address
)) {
1505 VG_(gdb_printf
) ("missing or malformed address\n");
1506 *address
= (Addr
) 0;
1510 ws
= VG_(strtok_r
) (NULL
, " ]", ssaveptr
);
1512 /* Do nothing, i.e. keep current value of szB. */ ;
1513 } else if (is_zero_x (ws
)) {
1514 *szB
= VG_(strtoull16
) (ws
, &endptr
);
1515 } else if (is_zero_b (ws
)) {
1517 HChar
*parsews
= ws
;
1518 Int n_bits
= VG_(strlen
) (ws
) - 2;
1520 ws
= NULL
; // assume the below loop gives a correct nr.
1521 for (j
= 0; j
< n_bits
; j
++) {
1522 if ('0' == parsews
[j
+2]) { /* do nothing */ }
1523 else if ('1' == parsews
[j
+2]) *szB
|= (1 << (n_bits
-j
-1));
1525 /* report malformed binary integer */
1527 endptr
= ws
+ j
+ 2;
1532 *szB
= VG_(strtoull10
) (ws
, &endptr
);
1535 if (ws
!= NULL
&& *endptr
!= '\0') {
1536 VG_(gdb_printf
) ("malformed integer, expecting "
1537 "hex 0x..... or dec ...... or binary 0b.....\n");
1538 *address
= (Addr
) 0;
1546 void VG_(gdbserver_status_output
)(void)
1548 const int nr_gdbserved_addresses
1549 = (gs_addresses
== NULL
? -1 : VG_(HT_count_nodes
) (gs_addresses
));
1550 const int nr_watchpoints
1551 = (gs_watches
== NULL
? -1 : (int) VG_(sizeXA
) (gs_watches
));
1552 remote_utils_output_status();
1554 ("nr of calls to gdbserver: %d\n"
1555 "single stepping %d\n"
1556 "interrupts intr_tid %u gs_non_busy %d gs_busy %d tid_non_intr %d\n"
1557 "gdbserved addresses %d (-1 = not initialized)\n"
1558 "watchpoints %d (-1 = not initialized)\n"
1560 "hostvisibility %s\n",
1562 valgrind_single_stepping(),
1564 vgdb_interrupted_tid
,
1565 interrupts_non_busy
,
1566 interrupts_while_busy
,
1567 interrupts_non_interruptible
,
1569 nr_gdbserved_addresses
,
1571 VG_(clo_vgdb_error
),
1572 hostvisibility
? "yes" : "no");