2 * Copyright (c) 2002-2005 The Regents of The University of Michigan
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 * Authors: Nathan Binkert
31 #ifndef __REMOTE_GDB_HH__
32 #define __REMOTE_GDB_HH__
34 #include <sys/signal.h>
38 #include "arch/types.hh"
39 #include "base/pollevent.hh"
40 #include "base/socket.hh"
41 #include "cpu/pc_event.hh"
51 GDBSignal = '?', // last signal
52 GDBSetBaud = 'b', // set baud (depracated)
53 GDBSetBreak = 'B', // set breakpoint (depracated)
54 GDBCont = 'c', // resume
55 GDBAsyncCont = 'C', // continue with signal
56 GDBDebug = 'd', // toggle debug flags (deprecated)
57 GDBDetach = 'D', // detach remote gdb
58 GDBRegR = 'g', // read general registers
59 GDBRegW = 'G', // write general registers
60 GDBSetThread = 'H', // set thread
61 GDBCycleStep = 'i', // step a single cycle
62 GDBSigCycleStep = 'I', // signal then cycle step
63 GDBKill = 'k', // kill program
64 GDBMemR = 'm', // read memory
65 GDBMemW = 'M', // write memory
66 GDBReadReg = 'p', // read register
67 GDBSetReg = 'P', // write register
68 GDBQueryVar = 'q', // query variable
69 GDBSetVar = 'Q', // set variable
70 GDBReset = 'r', // reset system. (Deprecated)
71 GDBStep = 's', // step
72 GDBAsyncStep = 'S', // signal and step
73 GDBThreadAlive = 'T', // find out if the thread is alive
74 GDBTargetExit = 'W', // target exited
75 GDBBinaryDload = 'X', // write memory
76 GDBClrHwBkpt = 'z', // remove breakpoint or watchpoint
77 GDBSetHwBkpt = 'Z' // insert breakpoint or watchpoint
80 const char GDBStart = '$';
81 const char GDBEnd = '#';
82 const char GDBGoodP = '+';
83 const char GDBBadP = '-';
85 const int GDBPacketBufLen = 1024;
90 friend void debugger();
91 friend class GDBListener;
97 Addr hex2i(const char **);
98 //Address formats, break types, and gdb commands may change
99 //between architectures, so they're defined as virtual
101 virtual void mem2hex(void *, const void *, int);
102 virtual const char * hex2mem(void *, const char *, int);
103 virtual const char * break_type(char c);
104 virtual const char * gdb_command(char cmd);
107 class Event : public PollEvent
113 Event(BaseRemoteGDB *g, int fd, int e);
114 void process(int revent);
119 GDBListener *listener;
123 //The socket commands come in through
134 PhysicalMemory *pmem;
135 ThreadContext *context;
141 GdbRegCache(size_t newSize) : regs(new uint64_t[newSize]), size(newSize)
150 size_t bytes() { return size * sizeof(uint64_t); }
157 void putbyte(uint8_t b);
159 int recv(char *data, int len);
160 void send(const char *data);
164 virtual bool read(Addr addr, size_t size, char *data);
165 virtual bool write(Addr addr, size_t size, const char *data);
167 template <class T> T read(Addr addr);
168 template <class T> void write(Addr addr, T data);
171 BaseRemoteGDB(System *system, ThreadContext *context, size_t cacheSize);
172 virtual ~BaseRemoteGDB();
174 void replaceThreadContext(ThreadContext *tc) { context = tc; }
180 virtual bool acc(Addr addr, size_t len) = 0;
182 virtual bool breakpoint()
184 return trap(SIGTRAP);
188 virtual void getregs() = 0;
189 virtual void setregs() = 0;
191 virtual void clearSingleStep() = 0;
192 virtual void setSingleStep() = 0;
194 PCEventQueue *getPcEventQueue();
197 class HardBreakpoint : public PCEvent
206 HardBreakpoint(BaseRemoteGDB *_gdb, Addr addr);
207 std::string name() { return gdb->name() + ".hwbkpt"; }
209 virtual void process(ThreadContext *tc);
211 friend class HardBreakpoint;
213 typedef std::map<Addr, HardBreakpoint *> break_map_t;
214 typedef break_map_t::iterator break_iter_t;
215 break_map_t hardBreakMap;
217 bool insertSoftBreak(Addr addr, size_t len);
218 bool removeSoftBreak(Addr addr, size_t len);
219 virtual bool insertHardBreak(Addr addr, size_t len);
220 bool removeHardBreak(Addr addr, size_t len);
223 void clearTempBreakpoint(Addr &bkpt);
224 void setTempBreakpoint(Addr bkpt);
232 BaseRemoteGDB::read(Addr addr)
235 read(addr, sizeof(T), (char *)&temp);
241 BaseRemoteGDB::write(Addr addr, T data)
242 { write(addr, sizeof(T), (const char *)&data); }
247 class Event : public PollEvent
250 GDBListener *listener;
253 Event(GDBListener *l, int fd, int e);
254 void process(int revent);
261 ListenSocket listener;
266 GDBListener(BaseRemoteGDB *g, int p);
274 #endif /* __REMOTE_GDB_H__ */