Fixed problem in DeviceSettings::strParam, returned wrong string
[avr-sim.git] / src / GdbServer.h
blob5ab2607091612ed634fa8f4132c85e98903ef6ee
1 #ifndef AVR_GDBSERVER_H
2 #define AVR_GDBSERVER_H
4 #include <vector>
5 #include "Exception.h"
6 #include "Types.h"
8 namespace sim {
9 class SimulationClock;
12 namespace avr {
14 class Device;
15 class DebugInterface;
17 /**
18 * @author Tom Haber
19 * @date Apr 27, 2008
20 * @brief gdb communication error
22 * Thrown when something goes wrong with the gdb communication.
24 class GdbException : public util::Exception {
25 public:
26 GdbException() : Exception("Gdb Exception") {}
27 GdbException(const char * msg) : Exception(msg) {}
28 GdbException(const std::string & msg) : Exception(msg) {}
31 /**
32 * @author Tom Haber
33 * @date Apr 27, 2008
34 * @brief Gnu debugger interfacing server
36 * This server can speak the gnu debugger remote debugging language
37 * and is used for remote debugging of the avr chip.
39 * This is largely based on code from simulavr.
41 * TODO rewrite, cleanup
42 * TODO implement trace points
44 class GdbServer {
45 public:
46 GdbServer(sim::SimulationClock & clock, int port = 1234);
47 ~GdbServer();
49 public:
50 void add(Device *dev);
51 void exec();
53 private:
54 void openSocket(int port);
55 void closeSocket();
56 void acceptClient();
58 private:
59 void handleClient();
60 int preParsePacket(bool blocking = false);
61 int parsePacket( char *pkt );
62 void setBlockingMode( bool blocking );
63 int readPacket();
64 int readByte();
65 void sendPosition(int signo);
67 void write( const void *buf, size_t count );
68 void sendAck();
69 void sendReply( const char *reply );
70 void saveLastReply( const char *reply );
72 private:
73 void queryPacket( char *pkt );
74 void readRegisters();
75 void writeRegisters( char *pkt );
76 void readRegister( char *pkt );
77 void writeRegister( char *pkt );
78 void readMemory( char *pkt );
79 void writeMemory( char *pkt );
80 int getSignal( char *pkt );
81 void breakPoint( char *pkt );
83 private:
84 sim::SimulationClock & clock;
85 std::vector<DebugInterface*> devices;
86 int current;
88 private:
89 /* A buffer containing a agent expression. */
90 struct AgentExpr {
91 std::vector<unsigned char> buf;
92 dword scope;
95 struct Tracepoint {
96 bool enabled;
98 /* Number of times this tracepoint should single-step
99 and collect additional data. */
100 long step_count;
102 /* Number of times this tracepoint should be hit before
103 disabling/ending. */
104 int pass_count;
106 /* Count of the number of times this tracepoint was taken, dumped
107 with the info, but not used for anything else. Useful for
108 seeing how many times you hit a tracepoint prior to the program
109 aborting, so you can back up to just before the abort. */
110 int hit_count;
112 std::vector<Tracepoint> tracePoints;
114 private:
115 int sock, conn;
116 int runMode;
117 bool blockingOn;
118 char *lastReply;
123 #endif /*AVR_GDBSERVER_H*/