1 |
148 |
jeremybenn |
/*
|
2 |
|
|
* Copyright (c) 1995, 1996 Cygnus Support
|
3 |
|
|
*
|
4 |
|
|
* The authors hereby grant permission to use, copy, modify, distribute,
|
5 |
|
|
* and license this software and its documentation for any purpose, provided
|
6 |
|
|
* that existing copyright notices are retained in all copies and that this
|
7 |
|
|
* notice is included verbatim in any distributions. No written agreement,
|
8 |
|
|
* license, or royalty fee is required for any of the authorized uses.
|
9 |
|
|
* Modifications to this software may be copyrighted by their authors
|
10 |
|
|
* and need not follow the licensing terms described here, provided that
|
11 |
|
|
* the new terms are clearly indicated on the first page of each file where
|
12 |
|
|
* they apply.
|
13 |
|
|
*/
|
14 |
|
|
|
15 |
|
|
static const char hexchars[]="0123456789abcdef";
|
16 |
|
|
|
17 |
|
|
typedef void (*exception_t)(int); /* pointer to function with int parm */
|
18 |
|
|
|
19 |
|
|
/*
|
20 |
|
|
* This is the default function handler to be called with all exceptions.
|
21 |
|
|
*/
|
22 |
|
|
extern exception_t default_trap_hook;
|
23 |
|
|
|
24 |
|
|
/* this is used to make Unix style signale nukbers to an exception */
|
25 |
|
|
struct trap_info
|
26 |
|
|
{
|
27 |
|
|
unsigned char tt; /* exception number */
|
28 |
|
|
unsigned char signo; /* corresponding signal number */
|
29 |
|
|
};
|
30 |
|
|
|
31 |
|
|
/*
|
32 |
|
|
* prototypes for the functions in debug.c. As these'll only be used with GCC,
|
33 |
|
|
* we don't worry about no stinkin K&R comilers.
|
34 |
|
|
*/
|
35 |
|
|
extern void exception_handler (int, unsigned long);
|
36 |
|
|
extern unsigned char *mem2hex(unsigned char *, unsigned char *, int, int);
|
37 |
|
|
extern unsigned char *hex2mem(unsigned char *, unsigned char *, int, int);
|
38 |
|
|
extern void getpacket(unsigned char *);
|
39 |
|
|
extern void putpacket(unsigned char *);
|
40 |
|
|
extern char *make_return_packet(int);
|
41 |
|
|
extern void set_debug_traps();
|
42 |
|
|
extern int computeSignal(int);
|
43 |
|
|
extern char digit2hex(int);
|
44 |
|
|
extern int hex2digit(int);
|
45 |
|
|
extern void debuglogs(int level, char *msg);
|
46 |
|
|
extern int hex2int();
|
47 |
|
|
extern char *int2hex(int);
|
48 |
|
|
extern void gdb_event_loop(int, unsigned long *);
|
49 |
|
|
|
50 |
|
|
extern char *gdb_read_registers(); /* g - read registers */
|
51 |
|
|
extern char *gdb_write_registers(char *); /* G - write registers */
|
52 |
|
|
extern char *gdb_read_memory(long, int); /* m - read memory */
|
53 |
|
|
extern char *gdb_write_memory(long, int, char *);/* M write memory */
|
54 |
|
|
extern char *gdb_continue(int, long ); /* c - continue */
|
55 |
|
|
extern char *gdb_step(int, long); /* s - step instruction(s) */
|
56 |
|
|
extern char *gdb_kill(); /* k - kill program */
|
57 |
|
|
extern char *gdb_last_signal(); /* ? - last signal */
|
58 |
|
|
extern char *gdb_baudrate(int); /* b - change baud rate */
|
59 |
|
|
extern char *gdb_dump_state(); /* T - dump state */
|
60 |
|
|
extern char *gdb_set_thread(int, int); /* H - set thread */
|
61 |
|
|
extern char *gdb_detach(); /* D - detach */
|
62 |
|
|
extern char *gdb_read_reg(int); /* p - read one register */
|
63 |
|
|
extern char *gdb_write_reg(int, long); /* P - write one register */
|
64 |
|
|
extern char *gdb_exited(); /* W - process exited */
|
65 |
|
|
extern char *gdb_terminated(); /* X - process terminated */
|
66 |
|
|
extern char *gdb_hex(); /* O - hex encoding */
|
67 |
|
|
extern char *gdb_thread_alive(int); /* A - tread alive request */
|
68 |
|
|
extern char *gdb_extended(); /* ! - extended protocol */
|
69 |
|
|
extern char *gdb_debug(); /* d - toggle stub diagnostics */
|
70 |
|
|
extern char *gdb_toggle(); /* unsupported, toggle stub on/off */
|
71 |
|
|
extern char *gdb_reset(); /* r - reset target */
|
72 |
|
|
extern char *gdb_search(long, long, long); /* t - search backwards */
|
73 |
|
|
extern char *gdb_query(char *); /* q - general query */
|
74 |
|
|
extern char *gdb_set(char *); /* Q - set value */
|
75 |
|
|
|
76 |
|
|
/*
|
77 |
|
|
* indicate to caller of mem2hex or hex2mem that there has been an error.
|
78 |
|
|
* 0 means ok, 1 means error
|
79 |
|
|
*/
|
80 |
|
|
extern volatile int mem_err;
|
81 |
|
|
|
82 |
|
|
/*
|
83 |
|
|
* indicate whether the debug vectors have been initialized
|
84 |
|
|
* 0 means not yet, 1 means yep, it's ready.
|
85 |
|
|
*/
|
86 |
|
|
extern int initialized;
|
87 |
|
|
|
88 |
|
|
/*
|
89 |
|
|
* 1 means print debugging messages from the target, 0 means be quiet.
|
90 |
|
|
*/
|
91 |
|
|
extern int remote_debug;
|
92 |
|
|
|
93 |
|
|
/*
|
94 |
|
|
* Set up the command processing required for GDB
|
95 |
|
|
*/
|
96 |
|
|
|
97 |
|
|
struct gdb_ops {
|
98 |
|
|
/*
|
99 |
|
|
* these functions are the most minimal working subset top get full
|
100 |
|
|
* functionality for remote debugging
|
101 |
|
|
*/
|
102 |
|
|
char *(*gdb_read_registers); /* g - read registers */
|
103 |
|
|
char *(*gdb_write_registers)(char *); /* G - write registers */
|
104 |
|
|
char *(*gdb_read_memory)(long, int); /* m - read memory */
|
105 |
|
|
char *(*gdb_write_memory)(long, int, char *);/* M write memory */
|
106 |
|
|
char *(*gdb_continue)(int, long ); /* c - continue */
|
107 |
|
|
char *(*gdb_step)(int, long); /* s - step instruction(s) */
|
108 |
|
|
char *(*gdb_kill); /* k - kill program */
|
109 |
|
|
char *(*gdb_last_signal); /* ? - last signal */
|
110 |
|
|
char *(*gdb_baudrate)(int); /* b - change baud rate */
|
111 |
|
|
char *(*gdb_dump_state); /* T - dump state */
|
112 |
|
|
/*
|
113 |
|
|
* these functions are for a more sophisticated target, typically
|
114 |
|
|
* running a simple RTOS.
|
115 |
|
|
*/
|
116 |
|
|
char *(*gdb_set_thread)(int, int); /* H - set thread */
|
117 |
|
|
char *(*gdb_detach); /* D - detach */
|
118 |
|
|
char *(*gdb_read_reg)(int); /* p - read one register */
|
119 |
|
|
char *(*gdb_write_reg)(int, long); /* P - write one register */
|
120 |
|
|
char *(*gdb_exited); /* W - process exited */
|
121 |
|
|
char *(*gdb_terminated); /* X - process terminated */
|
122 |
|
|
char *(*gdb_hex); /* O - hex encoding */
|
123 |
|
|
char *(*gdb_thread_alive)(int); /* A - tread alive request */
|
124 |
|
|
/* FIXME: not standard yet */
|
125 |
|
|
char *(*gdb_extended); /* ! - extended protocol */
|
126 |
|
|
char *(*gdb_debug); /* d - toggle stub diagnostics */
|
127 |
|
|
char *(*gdb_toggle); /* unsupported, toggle stub on/off */
|
128 |
|
|
char *(*gdb_reset); /* r - reset target */
|
129 |
|
|
char *(*gdb_search)(long, long, long); /* t - search backwards */
|
130 |
|
|
char *(*gdb_query)(char *); /* q - general query */
|
131 |
|
|
char *(*gdb_set)(long); /* Q - set value */
|
132 |
|
|
};
|
133 |
|
|
|
134 |
|
|
/*
|
135 |
|
|
* BUFMAX defines the maximum number of characters in inbound/outbound buffers
|
136 |
|
|
* at least NUMREGBYTES*2 are needed for register packets
|
137 |
|
|
*/
|
138 |
|
|
#define BUFMAX 2048
|
139 |
|
|
extern char packet_in_buf[BUFMAX];
|
140 |
|
|
extern char packet_out_buf[BUFMAX];
|
141 |
|
|
extern int packet_index;
|
142 |
|
|
|
143 |
|
|
#define DEBUG(x, y) debuglog(x, y);
|
144 |
|
|
#define set_debug_level(x) remote_debug = x;
|
145 |
|
|
#define OK 0
|
146 |
|
|
#define ERROR -1
|
147 |
|
|
#define ENN(x) "x"
|
148 |
|
|
|
149 |
|
|
#define MAY_FAULT 1
|
150 |
|
|
#define NO_FAULT 0
|