Bug fix: check if vm exists
[avr-sim.git] / GdbServer.h
blobd111755004a52b7e1e6d0f73d4bf7954929b3f31
1 #ifndef AVR_GDBSERVER_H
2 #define AVR_GDBSERVER_H
4 #include <vector>
5 #include "Exception.h"
6 #include "Types.h"
8 namespace avr {
10 class Device;
11 class DebugInterface;
12 class SimulationClock;
14 class GdbException : public util::Exception {
15 public:
16 GdbException() : Exception("Gdb Exception") {}
17 GdbException(const char * msg) : Exception(msg) {}
18 GdbException(const std::string & msg) : Exception(msg) {}
21 class GdbServer {
22 public:
23 GdbServer(SimulationClock & clock, int port = 1234);
24 ~GdbServer();
26 public:
27 void add(Device *dev);
28 void exec();
30 private:
31 void openSocket(int port);
32 void closeSocket();
33 void acceptClient();
35 private:
36 void handleClient();
37 int preParsePacket(bool blocking = false);
38 int parsePacket( char *pkt );
39 void setBlockingMode( bool blocking );
40 int readPacket();
41 int readByte();
42 void sendPosition(int signo);
44 void write( const void *buf, size_t count );
45 void sendAck();
46 void sendReply( char *reply );
47 void saveLastReply( char *reply );
49 private:
50 void queryPacket( char *pkt );
51 void readRegisters();
52 void writeRegisters( char *pkt );
53 void readRegister( char *pkt );
54 void writeRegister( char *pkt );
55 void readMemory( char *pkt );
56 void writeMemory( char *pkt );
57 int getSignal( char *pkt );
58 void breakPoint( char *pkt );
60 private:
61 SimulationClock & clock;
62 std::vector<DebugInterface*> devices;
63 int current;
65 private:
66 /* A buffer containing a agent expression. */
67 struct AgentExpr {
68 std::vector<unsigned char> buf;
69 dword scope;
72 struct Tracepoint {
73 bool enabled;
75 /* Number of times this tracepoint should single-step
76 and collect additional data. */
77 long step_count;
79 /* Number of times this tracepoint should be hit before
80 disabling/ending. */
81 int pass_count;
83 /* Count of the number of times this tracepoint was taken, dumped
84 with the info, but not used for anything else. Useful for
85 seeing how many times you hit a tracepoint prior to the program
86 aborting, so you can back up to just before the abort. */
87 int hit_count;
89 std::vector<Tracepoint> tracePoints;
91 private:
92 int sock, conn;
93 int runMode;
94 bool blockingOn;
95 char *lastReply;
100 #endif /*AVR_GDBSERVER_H*/