4 * gdb_stub/gdbserver --
6 * Definition of the GDB server stub
8 * (c) 2011-2013 Björn Döbel <doebel@os.inf.tu-dresden.de>,
9 * economic rights: Technische Universität Dresden (Germany)
10 * This file is part of TUD:OS and distributed under the terms of the
11 * GNU General Public License 2.
12 * Please see the COPYING-GPL-2 file for details.
18 #include "../fault_observers"
30 enum GDBSpecialCommands {
39 class GDBServerObserver : public Observer
41 DECLARE_OBSERVER("gdb");
46 // XXX: platform_thread?
47 pthread_t _thread; // the pthread we use for receiving
49 bool _connected; // flag if we have a connection yet
50 bool _ack_mode; // are we in ack mode?
51 bool _await_ack; // expecting and ack?
52 char * _bufptr; // pointer to last cmd found in packetbuf
53 char _inbuf[1024]; // buffer for incoming packet data
54 char _outbuf[1024]; // buffer for outgoing packet data
55 char _last_cmd[64]; // last command (in case we need to retry)
57 L4vcpu::Vcpu _saved_vcpu; // saved VCPU TODO: per-thread
58 //l4_utcb_t saved_utcb; // saved UTCB TODO: per-thread
59 Romain::App_model const * _app_model; // saved APP model
60 Romain::App_thread * _notifyThread; // last thread that entered the debugger
62 // XXX: platform_signal_type ?
63 sem_t _app_wait_signal; // sem to be polled by notify() until gdb sends C or S
64 sem_t _gdb_wait_signal; // sem to be polled by gdb until app finished exec of S
66 bool _want_halt; // do we want to halt our threads?
67 bool _singlestep; // single-stepping mode?
70 GDBServerObserver(Connection* con);
72 virtual ~GDBServerObserver();
74 void notify_and_wait(sem_t *toSend, sem_t *toWait)
76 int r = sem_post(toSend);
77 _check(r != 0, "sem_post");
79 _check(r != 0, "sem_wait");
86 notify_and_wait(&_app_wait_signal, &_gdb_wait_signal);
90 char *buffer() const { return (char * const)_inbuf; }
91 unsigned maxbuffer() const { return 1024; }
92 Connection * connection() const { return _con; }
98 memset(_inbuf, 0, sizeof(_inbuf));
99 memset(_outbuf, 0, sizeof(_outbuf));
105 * XXX: Udo optimization: only copy the stuff that has been changed instead
106 * of everything, because most commands will not ever modify the UTCB?
108 void save_vcpu(Romain::App_thread *t)
111 memcpy(&_saved_vcpu, t->vcpu(), sizeof(*t->vcpu()));
112 //memcpy(&saved_utcb, t->vcpu_utcb(), sizeof(*t->vcpu_utcb()));
115 void restore_vcpu(Romain::App_thread *t)
117 memcpy(t->vcpu(), &_saved_vcpu, sizeof(*t->vcpu()));
118 //memcpy(t->vcpu_utcb(), &saved_utcb, sizeof(*t->vcpu_utcb()));
123 * Determine which signal to return to a waiting gdb client
125 void signal_return(Romain::App_thread *t = 0);
128 * Generic command handlers
134 * Packet handling functions
136 bool checksum_cmd(char const *, char const **);
137 void append_checksum(char *ptr);
140 * Command implementations
142 void gdb_continue(char const* cmd, bool withSignal);
143 void gdb_get_registers(char const * const);
144 void gdb_select_thread(char const * const cmd);
145 void gdb_dump_mem(char const * const cmd);
146 void gdb_query(char const * const query);
147 void gdb_settings(char const * const cmd);
148 void gdb_step(char const* cmd, bool withSignal);
149 void gdb_breakpoint(char const* cmd);
150 void gdb_write_mem(char const* cmd, bool binaryData);
151 void gdb_read_register(char const* cmd);
152 void gdb_write_register(char const *cmd);