blob: a001cc6c09a08ecfa1711754032200ebb1e7776f [file] [log] [blame]
sewardj3b290482011-05-06 21:02:55 +00001
2/*--------------------------------------------------------------------*/
3/*--- Handle remote gdb protocol. pub_core_gdbserver.h ---*/
4/*--------------------------------------------------------------------*/
5
6/*
7 This file is part of Valgrind, a dynamic binary instrumentation
8 framework.
9
sewardj1568e172011-06-18 08:28:04 +000010 Copyright (C) 2011-2011 Philippe Waroquiers
sewardj3b290482011-05-06 21:02:55 +000011
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.
16
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.
21
22 You should have received a copy of the GNU General Public License
23 along with this program; if not, write to the Free Software
24 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
25 02111-1307, USA.
26
27 The GNU General Public License is contained in the file COPYING.
28*/
29
30#ifndef __PUB_CORE_GDBSERVER_H
31#define __PUB_CORE_GDBSERVER_H
32
33#include "pub_tool_gdbserver.h"
34
sewardj997546c2011-05-17 18:14:53 +000035
36// After a fork or after an exec, call the below to (possibly) terminate
37// the previous gdbserver and then activate a new gdbserver
38// before any guest code execution, to e.g. allow the user to set
39// breakpoints before execution.
40// If VG_(clo_vgdb) == No, the below has no effect.
41void VG_(gdbserver_prerun_action) (ThreadId tid);
42
sewardj3b290482011-05-06 21:02:55 +000043// True if there is some activity from vgdb
44// If it returns True, then extern void VG_(gdbserver) can be called
45// to handle this incoming vgdb request.
46extern Bool VG_(gdbserver_activity) (ThreadId tid);
47
48
49/* Called by low level to insert or remove a break or watch point.
50 Break or watch point implementation is done using help from the tool.
51 break point support implies some (small) specific instrumentation
52 taken in charge for all tools by m_translate.c.
53
54 Write/read/access watchpoint can only be provided by tools which are
55 tracking addressability and/or accessibility of memory
56 (so typically memcheck can provide it). Note that memcheck addressability
57 bits do not differentiate between read and write accessibility.
58 However, when accessing unaddressable byte, memcheck can differentiate
59 reads from write, thereby providing read/write or access watchpoints.
60
61 Note that gdbserver assumes that software breakpoint is supported
62 (as this will be done by re-instrumenting the code).
63 Note that len is ignored for sofware breakpoints. hardware_breakpoint
64 are not supported.
65
66 Returns True if the point has properly been inserted or removed
67 Returns False otherwise. */
68Bool VG_(gdbserver_point) (PointKind kind, Bool insert,
69 Addr addr, int len);
70
71/* Entry point invoked by vgdb when it uses ptrace to cause a gdbserver
72 invocation. A magic value is passed by vgdb in check as a verification
73 that the call has been properly pushed by vgdb. */
74extern void VG_(invoke_gdbserver) ( int check );
75
76// To be called before delivering a signal.
77// Returns True if gdb user asks to pass the signal to the client.
78// Note that if the below returns True, the signal might
79// still be ignored if this is the action desired by the
80// guest program.
81extern Bool VG_(gdbserver_report_signal) (Int signo, ThreadId tid);
82
83/* software_breakpoint, single step and jump support ------------------------*/
84/* VG_(instrument_for_gdbserver_if_needed) allows to do "standard and easy"
85 instrumentation for gdbserver.
86 VG_(instrument_for_gdbserver_if_needed) does the following:
87 * checks if gdbserver instrumentation is needed for vge.
88 * if no gdbserver instrumentation needed,
89 returns sb_in
90 * otherwise
91 It will instrument sb_in to allow gdbserver to properly
92 handle breakpoints and single_stepping in sb_in.
93 All the target jumps of sb_in will also be invalidated
94 if these are not yet instrumented for gdbserver.
95 This allows to have single_step working, using a lazily
96 translation of the blocks which are being single stepped
97 in.
98
99 The typical usage of this function is to call it on the block
100 instrumented by the tool instrument function i.e. :
101 return VG_(instrument_for_gdbserver_if_needed) (sb_out,
102 layout,
103 vge,
104 gWordTy,
105 hWordTy);
106 where sb_out is the block instrumented by the tool.
107
108 If the block contains a call to a dirty helper that indirectly
109 calls gdbserver, then this dirty helper can (indirectly) change
110 the IP. This implies to jump to this IP after the call to
111 gdbserver. */
112extern IRSB* VG_(instrument_for_gdbserver_if_needed)
113 (IRSB* sb_in, /* block to be instrumented */
114 VexGuestLayout* layout,
115 VexGuestExtents* vge,
116 IRType gWordTy, IRType hWordTy);
117
118/* reason for which gdbserver connection must be finished */
119typedef
120 enum {
121 orderly_finish,
122 reset_after_error,
123 reset_after_fork} FinishReason;
124
125/* output various gdbserver statistics and status. */
126extern void VG_(gdbserver_status_output)(void);
127
128/* Shared structure between vgdb and the process running
129 under valgrind.
130 We define two variants: a 32 bit and a 64 bit.
131 The valgrind process will use the appropriate size,
132 according to the architecture.
133 vgdb will use what the valgrind process is using. */
134/* The below takes care that sizes will be 32 or 64 bits,
135 whatever the architecture. A.o., vgdb.c cannot use directly
136 the types from pub_core_threadstate.h as we want vgdb.c to
137 be independent of the arch it is debugging in case of bi-arch
138 Valgrind (e.g. x86 and amd64). So, the valgrind process must
139 give all the needed info/offset to vgdb in the below structure. */
140
141typedef
142 struct {
143 // PID of the vgdb that last connected to the Valgrind gdbserver.
144 // It will be set by vgdb after connecting.
145 int vgdb_pid;
146
147 // nr of bytes vgdb has written to valgrind
148 volatile int written_by_vgdb;
149 // nr of bytes seen by valgrind
150 volatile int seen_by_valgrind;
151
152 // address at which gdbserver can be invoked
153 Addr32 invoke_gdbserver;
154
155 // address of VG_(threads) and various sizes
156 // and offset needed by vgdb.
157 Addr32 threads;
158 int sizeof_ThreadState;
159 int offset_status;
160 int offset_lwpid;
161 } VgdbShared32;
162
163/* Same as VgdbShared32 but for 64 bits arch. */
164typedef
165 struct {
166 int vgdb_pid;
167
168 volatile int written_by_vgdb;
169 volatile int seen_by_valgrind;
170
171 Addr64 invoke_gdbserver;
172
173 Addr64 threads;
174 int sizeof_ThreadState;
175 int offset_status;
176 int offset_lwpid;
177 } VgdbShared64;
178
179// The below typedef makes the life of valgrind easier.
180// vgdb must however work explicitely with the specific 32 or 64 bits version.
181
182#if VEX_HOST_WORDSIZE == 8
183typedef VgdbShared64 VgdbShared;
184#elif VEX_HOST_WORDSIZE == 4
185typedef VgdbShared32 VgdbShared;
186#else
187# error "unexpected wordsize"
188#endif
189
190
191#endif // __PUB_CORE_GDBSERVER_H
192/*--------------------------------------------------------------------*/
193/*--- end ---*/
194/*--------------------------------------------------------------------*/