simulavr  1.1.0
gdb.h
Go to the documentation of this file.
1 /*
2  ****************************************************************************
3  *
4  * simulavr - A simulator for the Atmel AVR family of microcontrollers.
5  * Copyright (C) 2001, 2002 Theodore A. Roth
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along
18  * with this program; if not, write to the Free Software Foundation, Inc.,
19  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20  *
21  ****************************************************************************
22  *
23  * $Id$
24  */
25 
26 
27 #ifndef SIM_GDB_H
28 #define SIM_GDB_H
29 
30 #include <sys/socket.h>
31 #include <sys/types.h>
32 #include <netinet/in.h>
33 #include <netinet/tcp.h>
34 #include <arpa/inet.h>
35 #include <vector>
36 
37 #include "config.h"
38 #include "avrdevice.h"
39 #include "types.h"
40 #include "simulationmember.h"
41 
42 #define MAX_BUF 400 /* Maximum size of read/write buffers. */
43 
44 // this are similar to unix signal numbers, but here used only as number, not
45 // as signal! See signum.h on unix systems for the values.
46 #define GDB_SIGHUP 1 // Hangup (POSIX).
47 #define GDB_SIGINT 2 // Interrupt (ANSI).
48 #define GDB_SIGILL 4 // Illegal instruction (ANSI).
49 #define GDB_SIGTRAP 5 // Trace trap (POSIX).
50 
53  public:
54  virtual void Close(void) = 0;
55  virtual int ReadByte(void) = 0;
56  virtual void Write(const void* buf, size_t count) = 0;
57  virtual void SetBlockingMode(int mode) = 0;
58  virtual bool Connect(void) = 0;
59  virtual void CloseConnection(void) = 0;
60  virtual ~GdbServerSocket() {}
61 };
62 
65  private:
66  int sock;
67  int conn;
68  struct sockaddr_in address[1];
69 
70  public:
71  GdbServerSocketUnix(int port);
73  virtual void Close(void);
74  virtual int ReadByte(void);
75  virtual void Write(const void* buf, size_t count);
76  virtual void SetBlockingMode(int mode);
77  virtual bool Connect(void);
78  virtual void CloseConnection(void);
79 };
80 
82 class GdbServer: public SimulationMember {
83 
84  protected:
85  static std::vector<GdbServer*> allGdbServers;
88  bool connState;
89 
92  time_t oldTime;
93 
97  int runMode;
99 
100  //old function local static vars, must move to class, no way to handle
101  //method local static vars.
102  char *last_reply; //used in last_reply();
103  char buf[MAX_BUF]; //used in send_reply();
105 
106 
107  bool avr_core_flash_read(int addr, word& val) ;
108  void avr_core_flash_write(int addr, word val) ;
109  void avr_core_flash_write_hi8( int addr, byte val) ;
110  void avr_core_flash_write_lo8( int addr, byte val) ;
111  void avr_core_remove_breakpoint(dword pc) ;
112  void avr_core_insert_breakpoint(dword pc) ;
113  int signal_has_occurred(int signo);
114  void signal_watch_start(int signo);
115  void signal_watch_stop(int signo);
116  int avr_core_step() ;
117  int hex2nib(char hex);
118  const char* gdb_last_reply(const char *reply);
119  void gdb_send_ack();
120  void gdb_send_reply(const char *reply);
121  void gdb_send_hex_reply(const char *reply, const char *reply_to_encode);
122  void gdb_read_registers();
123  void gdb_write_registers(const char *pkt);
124  int gdb_extract_hex_num(const char **pkt, char stop);
125  void gdb_read_register(const char *pkt);
126  void gdb_write_register(const char *pkt);
127  int gdb_get_addr_len(const char *pkt, char a_end, char l_end, unsigned int *addr, int *len);
128  void gdb_read_memory(const char *pkt);
129  void gdb_write_memory(const char *pkt);
130  void gdb_break_point(const char *pkt);
131  void gdb_select_thread(const char *pkt);
132  void gdb_is_thread_alive(const char *pkt);
133  void gdb_get_thread_list(const char *pkt);
134  int gdb_get_signal(const char *pkt);
135  int gdb_parse_packet(const char *pkt);
136  int gdb_receive_and_process_packet(int blocking);
137  void gdb_main_loop();
138  void gdb_interact(int port, int debug_on);
139  void IdleStep();
140 
141  public:
142  int Step(bool &trueHwStep, SystemClockOffset *timeToNextStepIn_ns=0) ;
143  int InternalStep(bool &trueHwStep, SystemClockOffset *timeToNextStepIn_ns=0) ;
144  void TryConnectGdb();
145  void SendPosition(int signal); //send gdb the actual position where the simulation is stopped
146  int SleepStep();
147  GdbServer( AvrDevice*, int port, int debugOn, int WaitForGdbConnection=true);
148  virtual ~GdbServer();
149  void Run(); //helper, would be removed in the future
150 };
151 
152 #endif /* SIM_GDB_H */
Basic AVR device, contains the core functionality.
Definition: avrdevice.h:66
int m_gdb_thread_id
For queries by GDB. First thread ID is 1. See http://sources.redhat.com/gdb/current/onlinedocs/gdb/Pa...
Definition: gdb.h:104
bool lastCoreStepFinished
Definition: gdb.h:98
int global_debug_on
debugging the debugger interface
Definition: gdb.h:94
virtual ~GdbServerSocket()
Definition: gdb.h:60
unsigned char byte
Definition: types.h:26
unsigned short word
Definition: types.h:27
int conn
the TCP connection from gdb client
Definition: gdb.h:67
virtual void Write(const void *buf, size_t count)=0
int waitForGdbConnection
Definition: gdb.h:95
virtual bool Connect(void)=0
#define MAX_BUF
Definition: gdb.h:42
virtual int ReadByte(void)=0
bool connState
result of server->Connect()
Definition: gdb.h:88
AvrDevice * core
Definition: gdb.h:86
static std::vector< GdbServer * > allGdbServers
Definition: gdb.h:85
Interface implementation for server socket wrapper on unix systems.
Definition: gdb.h:64
int sock
socket for listening for a new client
Definition: gdb.h:66
long long SystemClockOffset
int runMode
Definition: gdb.h:97
GdbServerSocket * server
the server socket wrapper
Definition: gdb.h:87
time_t oldTime
Definition: gdb.h:92
virtual void SetBlockingMode(int mode)=0
int dword
Definition: types.h:30
virtual void CloseConnection(void)=0
virtual void Close(void)=0
GDB server instance to give the possibility to debug target by debugger.
Definition: gdb.h:82
bool exitOnKillRequest
flag for regression test to shutdown simulator on kill request from gdb
Definition: gdb.h:96
char * last_reply
Definition: gdb.h:102
~GdbServerSocketUnix()
Definition: gdb.h:72
Interface for server socket wrapper.
Definition: gdb.h:52