Timer8 now has a variable amount of output compare units.
[avr-sim.git] / src / GdbServer.h
blob958a433e496f43a8b1eca7a72c7fd62a43d2a782
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 /**
15 * @author Tom Haber
16 * @date Apr 27, 2008
17 * @brief gdb communication error
19 * Thrown when something goes wrong with the gdb communication.
21 class GdbException : public util::Exception {
22 public:
23 GdbException() : Exception("Gdb Exception") {}
24 GdbException(const char * msg) : Exception(msg) {}
25 GdbException(const std::string & msg) : Exception(msg) {}
28 /**
29 * @author Tom Haber
30 * @date Apr 27, 2008
31 * @brief Gnu debugger interfacing server
33 * This server can speak the gnu debugger remote debugging language
34 * and is used for remote debugging of the avr chip.
36 * This is largely based on code from simulavr.
38 * TODO rewrite, cleanup
39 * TODO implement trace points
41 class GdbServer {
42 public:
43 GdbServer(SimulationClock & clock, int port = 1234);
44 ~GdbServer();
46 public:
47 void add(Device *dev);
48 void exec();
50 private:
51 void openSocket(int port);
52 void closeSocket();
53 void acceptClient();
55 private:
56 void handleClient();
57 int preParsePacket(bool blocking = false);
58 int parsePacket( char *pkt );
59 void setBlockingMode( bool blocking );
60 int readPacket();
61 int readByte();
62 void sendPosition(int signo);
64 void write( const void *buf, size_t count );
65 void sendAck();
66 void sendReply( char *reply );
67 void saveLastReply( char *reply );
69 private:
70 void queryPacket( char *pkt );
71 void readRegisters();
72 void writeRegisters( char *pkt );
73 void readRegister( char *pkt );
74 void writeRegister( char *pkt );
75 void readMemory( char *pkt );
76 void writeMemory( char *pkt );
77 int getSignal( char *pkt );
78 void breakPoint( char *pkt );
80 private:
81 SimulationClock & clock;
82 std::vector<DebugInterface*> devices;
83 int current;
85 private:
86 /* A buffer containing a agent expression. */
87 struct AgentExpr {
88 std::vector<unsigned char> buf;
89 dword scope;
92 struct Tracepoint {
93 bool enabled;
95 /* Number of times this tracepoint should single-step
96 and collect additional data. */
97 long step_count;
99 /* Number of times this tracepoint should be hit before
100 disabling/ending. */
101 int pass_count;
103 /* Count of the number of times this tracepoint was taken, dumped
104 with the info, but not used for anything else. Useful for
105 seeing how many times you hit a tracepoint prior to the program
106 aborting, so you can back up to just before the abort. */
107 int hit_count;
109 std::vector<Tracepoint> tracePoints;
111 private:
112 int sock, conn;
113 int runMode;
114 bool blockingOn;
115 char *lastReply;
120 #endif /*AVR_GDBSERVER_H*/