iPXE
Data Structures | Enumerations | Functions | Variables
gdbstub.c File Reference

GDB stub for remote debugging. More...

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <byteswap.h>
#include <ipxe/gdbstub.h>

Go to the source code of this file.

Data Structures

struct  gdbstub
 

Enumerations

enum  { POSIX_EINVAL = 0x1c, SIZEOF_PAYLOAD = 512 }
 

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
static void gdbstub_state_new (struct gdbstub *stub, char ch)
 
static void gdbstub_state_data (struct gdbstub *stub, char ch)
 
static void gdbstub_state_cksum1 (struct gdbstub *stub, char ch)
 
static void gdbstub_state_cksum2 (struct gdbstub *stub, char ch)
 
static void gdbstub_state_wait_ack (struct gdbstub *stub, char ch)
 
static uint8_t gdbstub_from_hex_digit (char ch)
 
static uint8_t gdbstub_to_hex_digit (uint8_t b)
 
static void gdbstub_from_hex_buf (char *dst, char *src, int lenbytes)
 
static void gdbstub_to_hex_buf (char *dst, char *src, int lenbytes)
 
static uint8_t gdbstub_cksum (char *data, int len)
 
static void gdbstub_tx_packet (struct gdbstub *stub)
 
static void gdbstub_send_ok (struct gdbstub *stub)
 
static void gdbstub_send_num_packet (struct gdbstub *stub, char reply, int num)
 
static int gdbstub_get_packet_args (struct gdbstub *stub, unsigned long *args, int nargs, int *stop_idx)
 
static void gdbstub_send_errno (struct gdbstub *stub, int errno)
 
static void gdbstub_report_signal (struct gdbstub *stub)
 
static void gdbstub_read_regs (struct gdbstub *stub)
 
static void gdbstub_write_regs (struct gdbstub *stub)
 
static void gdbstub_read_mem (struct gdbstub *stub)
 
static void gdbstub_write_mem (struct gdbstub *stub)
 
static void gdbstub_continue (struct gdbstub *stub, int single_step)
 
static void gdbstub_breakpoint (struct gdbstub *stub)
 
static void gdbstub_rx_packet (struct gdbstub *stub)
 
static void gdbstub_parse (struct gdbstub *stub, char ch)
 
void gdbstub_handler (int signo, gdbreg_t *regs)
 Interrupt handler. More...
 
struct gdb_transportfind_gdb_transport (const char *name)
 Look up GDB transport by name. More...
 
void gdbstub_start (struct gdb_transport *trans)
 Break into the debugger using the given transport. More...
 

Variables

static struct gdbstub stub
 

Detailed Description

GDB stub for remote debugging.

Definition in file gdbstub.c.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
POSIX_EINVAL 
SIZEOF_PAYLOAD 

Definition at line 40 of file gdbstub.c.

40  {
41  POSIX_EINVAL = 0x1c, /* used to report bad arguments to GDB */
42  SIZEOF_PAYLOAD = 512, /* buffer size of GDB payload data */
43 };

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ gdbstub_state_new()

static void gdbstub_state_new ( struct gdbstub stub,
char  ch 
)
static

Definition at line 311 of file gdbstub.c.

311  {
312  if ( ch == '$' ) {
313  stub->len = 0;
315  }
316 }
void(* parse)(struct gdbstub *stub, char ch)
Definition: gdbstub.c:52
static void gdbstub_state_data(struct gdbstub *stub, char ch)
Definition: gdbstub.c:318
uint8_t ch
Definition: registers.h:83
static struct gdbstub stub
Definition: gdbstub.c:367
int len
Definition: gdbstub.c:60

References ch, gdbstub_state_data(), gdbstub::len, gdbstub::parse, and stub.

Referenced by gdbstub_state_cksum2(), and gdbstub_state_wait_ack().

◆ gdbstub_state_data()

static void gdbstub_state_data ( struct gdbstub stub,
char  ch 
)
static

Definition at line 318 of file gdbstub.c.

318  {
319  if ( ch == '#' ) {
321  } else if ( ch == '$' ) {
322  stub->len = 0; /* retry new packet */
323  } else {
324  /* If the length exceeds our buffer, let the checksum fail */
325  if ( stub->len < SIZEOF_PAYLOAD ) {
326  stub->payload [ stub->len++ ] = ch;
327  }
328  }
329 }
void(* parse)(struct gdbstub *stub, char ch)
Definition: gdbstub.c:52
static void gdbstub_state_cksum1(struct gdbstub *stub, char ch)
Definition: gdbstub.c:331
uint8_t ch
Definition: registers.h:83
char * payload
Definition: gdbstub.c:59
static struct gdbstub stub
Definition: gdbstub.c:367
int len
Definition: gdbstub.c:60

References ch, gdbstub_state_cksum1(), gdbstub::len, gdbstub::parse, gdbstub::payload, SIZEOF_PAYLOAD, and stub.

Referenced by gdbstub_state_new().

◆ gdbstub_state_cksum1()

static void gdbstub_state_cksum1 ( struct gdbstub stub,
char  ch 
)
static

Definition at line 331 of file gdbstub.c.

331  {
332  stub->cksum1 = gdbstub_from_hex_digit ( ch ) << 4;
334 }
void(* parse)(struct gdbstub *stub, char ch)
Definition: gdbstub.c:52
static void gdbstub_state_cksum2(struct gdbstub *stub, char ch)
Definition: gdbstub.c:336
uint8_t ch
Definition: registers.h:83
static uint8_t gdbstub_from_hex_digit(char ch)
Definition: gdbstub.c:70
static struct gdbstub stub
Definition: gdbstub.c:367
uint8_t cksum1
Definition: gdbstub.c:53

References ch, gdbstub::cksum1, gdbstub_from_hex_digit(), gdbstub_state_cksum2(), gdbstub::parse, and stub.

Referenced by gdbstub_state_data().

◆ gdbstub_state_cksum2()

static void gdbstub_state_cksum2 ( struct gdbstub stub,
char  ch 
)
static

Definition at line 336 of file gdbstub.c.

336  {
337  uint8_t their_cksum;
338  uint8_t our_cksum;
339 
341  their_cksum = stub->cksum1 + gdbstub_from_hex_digit ( ch );
342  our_cksum = gdbstub_cksum ( stub->payload, stub->len );
343  if ( their_cksum == our_cksum ) {
344  stub->trans->send ( "+", 1 );
345  if ( stub->len > 0 ) {
347  }
348  } else {
349  stub->trans->send ( "-", 1 );
350  }
351 }
static uint8_t gdbstub_cksum(char *data, int len)
Definition: gdbstub.c:136
void(* parse)(struct gdbstub *stub, char ch)
Definition: gdbstub.c:52
uint8_t ch
Definition: registers.h:83
char * payload
Definition: gdbstub.c:59
static uint8_t gdbstub_from_hex_digit(char ch)
Definition: gdbstub.c:70
struct gdb_transport * trans
Definition: gdbstub.c:46
static struct gdbstub stub
Definition: gdbstub.c:367
uint8_t cksum1
Definition: gdbstub.c:53
unsigned char uint8_t
Definition: stdint.h:10
static void gdbstub_rx_packet(struct gdbstub *stub)
Definition: gdbstub.c:273
int len
Definition: gdbstub.c:60
void(* send)(const char *buf, size_t len)
Write, may block.
Definition: gdbstub.h:47
static void gdbstub_state_new(struct gdbstub *stub, char ch)
Definition: gdbstub.c:311

References ch, gdbstub::cksum1, gdbstub_cksum(), gdbstub_from_hex_digit(), gdbstub_rx_packet(), gdbstub_state_new(), gdbstub::len, gdbstub::parse, gdbstub::payload, gdb_transport::send, stub, and gdbstub::trans.

Referenced by gdbstub_state_cksum1().

◆ gdbstub_state_wait_ack()

static void gdbstub_state_wait_ack ( struct gdbstub stub,
char  ch 
)
static

Definition at line 353 of file gdbstub.c.

353  {
354  if ( ch == '+' ) {
356  } else {
357  /* This retransmit is very aggressive but necessary to keep
358  * in sync with GDB. */
360  }
361 }
void(* parse)(struct gdbstub *stub, char ch)
Definition: gdbstub.c:52
uint8_t ch
Definition: registers.h:83
static void gdbstub_tx_packet(struct gdbstub *stub)
Definition: gdbstub.c:144
static struct gdbstub stub
Definition: gdbstub.c:367
static void gdbstub_state_new(struct gdbstub *stub, char ch)
Definition: gdbstub.c:311

References ch, gdbstub_state_new(), gdbstub_tx_packet(), gdbstub::parse, and stub.

Referenced by gdbstub_tx_packet().

◆ gdbstub_from_hex_digit()

static uint8_t gdbstub_from_hex_digit ( char  ch)
static

Definition at line 70 of file gdbstub.c.

70  {
71  return ( isdigit ( ch ) ? ch - '0' : tolower ( ch ) - 'a' + 0xa ) & 0xf;
72 }
uint8_t ch
Definition: registers.h:83
static int isdigit(int character)
Check if character is a decimal digit.
Definition: ctype.h:29
static int tolower(int character)
Convert character to lower case.
Definition: ctype.h:108

References ch, isdigit(), and tolower().

Referenced by gdbstub_from_hex_buf(), gdbstub_get_packet_args(), gdbstub_state_cksum1(), and gdbstub_state_cksum2().

◆ gdbstub_to_hex_digit()

static uint8_t gdbstub_to_hex_digit ( uint8_t  b)
static

Definition at line 74 of file gdbstub.c.

74  {
75  b &= 0xf;
76  return ( b < 0xa ? '0' : 'a' - 0xa ) + b;
77 }

Referenced by gdbstub_send_num_packet(), gdbstub_to_hex_buf(), and gdbstub_tx_packet().

◆ gdbstub_from_hex_buf()

static void gdbstub_from_hex_buf ( char *  dst,
char *  src,
int  lenbytes 
)
static

Definition at line 84 of file gdbstub.c.

84  {
85  if ( lenbytes == 2 && ( ( unsigned long ) dst & 0x1 ) == 0 ) {
86  uint16_t i = gdbstub_from_hex_digit ( src [ 2 ] ) << 12 |
87  gdbstub_from_hex_digit ( src [ 3 ] ) << 8 |
88  gdbstub_from_hex_digit ( src [ 0 ] ) << 4 |
89  gdbstub_from_hex_digit ( src [ 1 ] );
90  * ( uint16_t * ) dst = cpu_to_le16 ( i );
91  } else if ( lenbytes == 4 && ( ( unsigned long ) dst & 0x3 ) == 0 ) {
92  uint32_t i = gdbstub_from_hex_digit ( src [ 6 ] ) << 28 |
93  gdbstub_from_hex_digit ( src [ 7 ] ) << 24 |
94  gdbstub_from_hex_digit ( src [ 4 ] ) << 20 |
95  gdbstub_from_hex_digit ( src [ 5 ] ) << 16 |
96  gdbstub_from_hex_digit ( src [ 2 ] ) << 12 |
97  gdbstub_from_hex_digit ( src [ 3 ] ) << 8 |
98  gdbstub_from_hex_digit ( src [ 0 ] ) << 4 |
99  gdbstub_from_hex_digit ( src [ 1 ] );
100  * ( uint32_t * ) dst = cpu_to_le32 ( i );
101  } else {
102  while ( lenbytes-- > 0 ) {
103  *dst++ = gdbstub_from_hex_digit ( src [ 0 ] ) << 4 |
104  gdbstub_from_hex_digit ( src [ 1 ] );
105  src += 2;
106  }
107  }
108 }
static const void * src
Definition: string.h:47
unsigned short uint16_t
Definition: stdint.h:11
static uint8_t gdbstub_from_hex_digit(char ch)
Definition: gdbstub.c:70
#define cpu_to_le32(value)
Definition: byteswap.h:107
unsigned int uint32_t
Definition: stdint.h:12
#define cpu_to_le16(value)
Definition: byteswap.h:106

References cpu_to_le16, cpu_to_le32, gdbstub_from_hex_digit(), and src.

Referenced by gdbstub_write_mem(), and gdbstub_write_regs().

◆ gdbstub_to_hex_buf()

static void gdbstub_to_hex_buf ( char *  dst,
char *  src,
int  lenbytes 
)
static

Definition at line 110 of file gdbstub.c.

110  {
111  if ( lenbytes == 2 && ( ( unsigned long ) src & 0x1 ) == 0 ) {
112  uint16_t i = cpu_to_le16 ( * ( uint16_t * ) src );
113  dst [ 0 ] = gdbstub_to_hex_digit ( i >> 4 );
114  dst [ 1 ] = gdbstub_to_hex_digit ( i );
115  dst [ 2 ] = gdbstub_to_hex_digit ( i >> 12 );
116  dst [ 3 ] = gdbstub_to_hex_digit ( i >> 8 );
117  } else if ( lenbytes == 4 && ( ( unsigned long ) src & 0x3 ) == 0 ) {
118  uint32_t i = cpu_to_le32 ( * ( uint32_t * ) src );
119  dst [ 0 ] = gdbstub_to_hex_digit ( i >> 4 );
120  dst [ 1 ] = gdbstub_to_hex_digit ( i );
121  dst [ 2 ] = gdbstub_to_hex_digit ( i >> 12 );
122  dst [ 3 ] = gdbstub_to_hex_digit ( i >> 8 );
123  dst [ 4 ] = gdbstub_to_hex_digit ( i >> 20 );
124  dst [ 5 ] = gdbstub_to_hex_digit ( i >> 16);
125  dst [ 6 ] = gdbstub_to_hex_digit ( i >> 28 );
126  dst [ 7 ] = gdbstub_to_hex_digit ( i >> 24 );
127  } else {
128  while ( lenbytes-- > 0 ) {
129  *dst++ = gdbstub_to_hex_digit ( *src >> 4 );
130  *dst++ = gdbstub_to_hex_digit ( *src );
131  src++;
132  }
133  }
134 }
static const void * src
Definition: string.h:47
unsigned short uint16_t
Definition: stdint.h:11
#define cpu_to_le32(value)
Definition: byteswap.h:107
unsigned int uint32_t
Definition: stdint.h:12
static uint8_t gdbstub_to_hex_digit(uint8_t b)
Definition: gdbstub.c:74
#define cpu_to_le16(value)
Definition: byteswap.h:106

References cpu_to_le16, cpu_to_le32, gdbstub_to_hex_digit(), and src.

Referenced by gdbstub_read_mem(), and gdbstub_read_regs().

◆ gdbstub_cksum()

static uint8_t gdbstub_cksum ( char *  data,
int  len 
)
static

Definition at line 136 of file gdbstub.c.

136  {
137  uint8_t cksum = 0;
138  while ( len-- > 0 ) {
139  cksum += ( uint8_t ) *data++;
140  }
141  return cksum;
142 }
unsigned char uint8_t
Definition: stdint.h:10
uint8_t data[48]
Additional event data.
Definition: ena.h:22
uint32_t len
Length.
Definition: ena.h:14

References data, and len.

Referenced by gdbstub_state_cksum2(), and gdbstub_tx_packet().

◆ gdbstub_tx_packet()

static void gdbstub_tx_packet ( struct gdbstub stub)
static

Definition at line 144 of file gdbstub.c.

144  {
145  uint8_t cksum = gdbstub_cksum ( stub->payload, stub->len );
146  stub->buf [ 0 ] = '$';
147  stub->buf [ stub->len + 1 ] = '#';
148  stub->buf [ stub->len + 2 ] = gdbstub_to_hex_digit ( cksum >> 4 );
149  stub->buf [ stub->len + 3 ] = gdbstub_to_hex_digit ( cksum );
150  stub->trans->send ( stub->buf, stub->len + 4 );
152 }
static uint8_t gdbstub_cksum(char *data, int len)
Definition: gdbstub.c:136
static void gdbstub_state_wait_ack(struct gdbstub *stub, char ch)
Definition: gdbstub.c:353
void(* parse)(struct gdbstub *stub, char ch)
Definition: gdbstub.c:52
char * payload
Definition: gdbstub.c:59
char buf[SIZEOF_PAYLOAD+4]
Definition: gdbstub.c:58
struct gdb_transport * trans
Definition: gdbstub.c:46
static struct gdbstub stub
Definition: gdbstub.c:367
unsigned char uint8_t
Definition: stdint.h:10
static uint8_t gdbstub_to_hex_digit(uint8_t b)
Definition: gdbstub.c:74
int len
Definition: gdbstub.c:60
void(* send)(const char *buf, size_t len)
Write, may block.
Definition: gdbstub.h:47

References gdbstub::buf, gdbstub_cksum(), gdbstub_state_wait_ack(), gdbstub_to_hex_digit(), gdbstub::len, gdbstub::parse, gdbstub::payload, gdb_transport::send, stub, and gdbstub::trans.

Referenced by gdbstub_breakpoint(), gdbstub_read_mem(), gdbstub_read_regs(), gdbstub_rx_packet(), gdbstub_send_num_packet(), gdbstub_send_ok(), and gdbstub_state_wait_ack().

◆ gdbstub_send_ok()

static void gdbstub_send_ok ( struct gdbstub stub)
static

Definition at line 155 of file gdbstub.c.

155  {
156  stub->payload [ 0 ] = 'O';
157  stub->payload [ 1 ] = 'K';
158  stub->len = 2;
160 }
char * payload
Definition: gdbstub.c:59
static void gdbstub_tx_packet(struct gdbstub *stub)
Definition: gdbstub.c:144
static struct gdbstub stub
Definition: gdbstub.c:367
int len
Definition: gdbstub.c:60

References gdbstub_tx_packet(), gdbstub::len, gdbstub::payload, and stub.

Referenced by gdbstub_breakpoint(), gdbstub_rx_packet(), gdbstub_write_mem(), and gdbstub_write_regs().

◆ gdbstub_send_num_packet()

static void gdbstub_send_num_packet ( struct gdbstub stub,
char  reply,
int  num 
)
static

Definition at line 162 of file gdbstub.c.

162  {
163  stub->payload [ 0 ] = reply;
164  stub->payload [ 1 ] = gdbstub_to_hex_digit ( ( char ) num >> 4 );
165  stub->payload [ 2 ] = gdbstub_to_hex_digit ( ( char ) num );
166  stub->len = 3;
168 }
uint32_t num
Definition: multiboot.h:12
char * payload
Definition: gdbstub.c:59
static void gdbstub_tx_packet(struct gdbstub *stub)
Definition: gdbstub.c:144
static struct gdbstub stub
Definition: gdbstub.c:367
static uint8_t gdbstub_to_hex_digit(uint8_t b)
Definition: gdbstub.c:74
int len
Definition: gdbstub.c:60

References gdbstub_to_hex_digit(), gdbstub_tx_packet(), gdbstub::len, num, gdbstub::payload, and stub.

Referenced by gdbstub_report_signal(), and gdbstub_send_errno().

◆ gdbstub_get_packet_args()

static int gdbstub_get_packet_args ( struct gdbstub stub,
unsigned long *  args,
int  nargs,
int *  stop_idx 
)
static

Definition at line 171 of file gdbstub.c.

171  {
172  int i;
173  char ch = 0;
174  int argc = 0;
175  unsigned long val = 0;
176  for ( i = 1; i < stub->len && argc < nargs; i++ ) {
177  ch = stub->payload [ i ];
178  if ( ch == ':' ) {
179  break;
180  } else if ( ch == ',' ) {
181  args [ argc++ ] = val;
182  val = 0;
183  } else {
184  val = ( val << 4 ) | gdbstub_from_hex_digit ( ch );
185  }
186  }
187  if ( stop_idx ) {
188  *stop_idx = i;
189  }
190  if ( argc < nargs ) {
191  args [ argc++ ] = val;
192  }
193  return ( ( i == stub->len || ch == ':' ) && argc == nargs );
194 }
void __asmcall int val
Definition: setjmp.h:12
uint8_t ch
Definition: registers.h:83
char * payload
Definition: gdbstub.c:59
static uint8_t gdbstub_from_hex_digit(char ch)
Definition: gdbstub.c:70
static struct gdbstub stub
Definition: gdbstub.c:367
int len
Definition: gdbstub.c:60

References ch, gdbstub_from_hex_digit(), gdbstub::len, gdbstub::payload, stub, and val.

Referenced by gdbstub_breakpoint(), gdbstub_continue(), gdbstub_read_mem(), and gdbstub_write_mem().

◆ gdbstub_send_errno()

static void gdbstub_send_errno ( struct gdbstub stub,
int  errno 
)
static

Definition at line 196 of file gdbstub.c.

196  {
198 }
static void gdbstub_send_num_packet(struct gdbstub *stub, char reply, int num)
Definition: gdbstub.c:162
int errno
Global "last error" number.
Definition: errno.c:20
static struct gdbstub stub
Definition: gdbstub.c:367

References errno, gdbstub_send_num_packet(), and stub.

Referenced by gdbstub_breakpoint(), gdbstub_read_mem(), gdbstub_write_mem(), and gdbstub_write_regs().

◆ gdbstub_report_signal()

static void gdbstub_report_signal ( struct gdbstub stub)
static

Definition at line 200 of file gdbstub.c.

200  {
202 }
static void gdbstub_send_num_packet(struct gdbstub *stub, char reply, int num)
Definition: gdbstub.c:162
int signo
Definition: gdbstub.c:49
static struct gdbstub stub
Definition: gdbstub.c:367

References gdbstub_send_num_packet(), gdbstub::signo, and stub.

Referenced by gdbstub_handler(), and gdbstub_rx_packet().

◆ gdbstub_read_regs()

static void gdbstub_read_regs ( struct gdbstub stub)
static

Definition at line 204 of file gdbstub.c.

204  {
208 }
char * payload
Definition: gdbstub.c:59
static void gdbstub_tx_packet(struct gdbstub *stub)
Definition: gdbstub.c:144
static struct gdbstub stub
Definition: gdbstub.c:367
gdbreg_t * regs
Definition: gdbstub.c:50
int len
Definition: gdbstub.c:60
static void gdbstub_to_hex_buf(char *dst, char *src, int lenbytes)
Definition: gdbstub.c:110

References GDBMACH_SIZEOF_REGS, gdbstub_to_hex_buf(), gdbstub_tx_packet(), gdbstub::len, gdbstub::payload, gdbstub::regs, and stub.

Referenced by gdbstub_rx_packet().

◆ gdbstub_write_regs()

static void gdbstub_write_regs ( struct gdbstub stub)
static

Definition at line 210 of file gdbstub.c.

210  {
211  if ( stub->len != 1 + GDBMACH_SIZEOF_REGS * 2 ) {
213  return;
214  }
215  gdbstub_from_hex_buf ( ( char * ) stub->regs, &stub->payload [ 1 ], GDBMACH_SIZEOF_REGS );
216  gdbstub_send_ok ( stub );
217 }
char * payload
Definition: gdbstub.c:59
static void gdbstub_send_errno(struct gdbstub *stub, int errno)
Definition: gdbstub.c:196
static struct gdbstub stub
Definition: gdbstub.c:367
gdbreg_t * regs
Definition: gdbstub.c:50
static void gdbstub_send_ok(struct gdbstub *stub)
Definition: gdbstub.c:155
int len
Definition: gdbstub.c:60
static void gdbstub_from_hex_buf(char *dst, char *src, int lenbytes)
Definition: gdbstub.c:84

References GDBMACH_SIZEOF_REGS, gdbstub_from_hex_buf(), gdbstub_send_errno(), gdbstub_send_ok(), gdbstub::len, gdbstub::payload, POSIX_EINVAL, gdbstub::regs, and stub.

Referenced by gdbstub_rx_packet().

◆ gdbstub_read_mem()

static void gdbstub_read_mem ( struct gdbstub stub)
static

Definition at line 219 of file gdbstub.c.

219  {
220  unsigned long args [ 2 ];
221  if ( !gdbstub_get_packet_args ( stub, args, sizeof args / sizeof args [ 0 ], NULL ) ) {
223  return;
224  }
225  args [ 1 ] = ( args [ 1 ] < SIZEOF_PAYLOAD / 2 ) ? args [ 1 ] : SIZEOF_PAYLOAD / 2;
226  gdbstub_to_hex_buf ( stub->payload, ( char * ) args [ 0 ], args [ 1 ] );
227  stub->len = args [ 1 ] * 2;
229 }
static int gdbstub_get_packet_args(struct gdbstub *stub, unsigned long *args, int nargs, int *stop_idx)
Definition: gdbstub.c:171
char * payload
Definition: gdbstub.c:59
static void gdbstub_tx_packet(struct gdbstub *stub)
Definition: gdbstub.c:144
static void gdbstub_send_errno(struct gdbstub *stub, int errno)
Definition: gdbstub.c:196
static struct gdbstub stub
Definition: gdbstub.c:367
int len
Definition: gdbstub.c:60
static void gdbstub_to_hex_buf(char *dst, char *src, int lenbytes)
Definition: gdbstub.c:110
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

References gdbstub_get_packet_args(), gdbstub_send_errno(), gdbstub_to_hex_buf(), gdbstub_tx_packet(), gdbstub::len, NULL, gdbstub::payload, POSIX_EINVAL, SIZEOF_PAYLOAD, and stub.

Referenced by gdbstub_rx_packet().

◆ gdbstub_write_mem()

static void gdbstub_write_mem ( struct gdbstub stub)
static

Definition at line 231 of file gdbstub.c.

231  {
232  unsigned long args [ 2 ];
233  int colon;
234  if ( !gdbstub_get_packet_args ( stub, args, sizeof args / sizeof args [ 0 ], &colon ) ||
235  colon >= stub->len || stub->payload [ colon ] != ':' ||
236  ( stub->len - colon - 1 ) % 2 != 0 ) {
238  return;
239  }
240  gdbstub_from_hex_buf ( ( char * ) args [ 0 ], &stub->payload [ colon + 1 ], ( stub->len - colon - 1 ) / 2 );
241  gdbstub_send_ok ( stub );
242 }
static int gdbstub_get_packet_args(struct gdbstub *stub, unsigned long *args, int nargs, int *stop_idx)
Definition: gdbstub.c:171
char * payload
Definition: gdbstub.c:59
static void gdbstub_send_errno(struct gdbstub *stub, int errno)
Definition: gdbstub.c:196
static struct gdbstub stub
Definition: gdbstub.c:367
static void gdbstub_send_ok(struct gdbstub *stub)
Definition: gdbstub.c:155
int len
Definition: gdbstub.c:60
static void gdbstub_from_hex_buf(char *dst, char *src, int lenbytes)
Definition: gdbstub.c:84

References gdbstub_from_hex_buf(), gdbstub_get_packet_args(), gdbstub_send_errno(), gdbstub_send_ok(), gdbstub::len, gdbstub::payload, POSIX_EINVAL, and stub.

Referenced by gdbstub_rx_packet().

◆ gdbstub_continue()

static void gdbstub_continue ( struct gdbstub stub,
int  single_step 
)
static

Definition at line 244 of file gdbstub.c.

244  {
245  gdbreg_t pc;
246  if ( stub->len > 1 && gdbstub_get_packet_args ( stub, &pc, 1, NULL ) ) {
247  gdbmach_set_pc ( stub->regs, pc );
248  }
249  gdbmach_set_single_step ( stub->regs, single_step );
250  stub->exit_handler = 1;
251  /* Reply will be sent when we hit the next breakpoint or interrupt */
252 }
unsigned long gdbreg_t
Definition: gdbmach.h:15
static int gdbstub_get_packet_args(struct gdbstub *stub, unsigned long *args, int nargs, int *stop_idx)
Definition: gdbstub.c:171
int exit_handler
Definition: gdbstub.c:47
static struct gdbstub stub
Definition: gdbstub.c:367
gdbreg_t * regs
Definition: gdbstub.c:50
static void gdbmach_set_pc(gdbreg_t *regs, gdbreg_t pc)
Definition: gdbmach.h:55
int len
Definition: gdbstub.c:60
static void gdbmach_set_single_step(gdbreg_t *regs, int step)
Definition: gdbmach.h:59
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

References gdbstub::exit_handler, gdbmach_set_pc(), gdbmach_set_single_step(), gdbstub_get_packet_args(), gdbstub::len, NULL, gdbstub::regs, and stub.

Referenced by gdbstub_rx_packet().

◆ gdbstub_breakpoint()

static void gdbstub_breakpoint ( struct gdbstub stub)
static

Definition at line 254 of file gdbstub.c.

254  {
255  unsigned long args [ 3 ];
256  int enable = stub->payload [ 0 ] == 'Z' ? 1 : 0;
257  int rc;
258 
259  if ( !gdbstub_get_packet_args ( stub, args, sizeof args / sizeof args [ 0 ], NULL ) ) {
261  return;
262  }
263  if ( ( rc = gdbmach_set_breakpoint ( args [ 0 ], args [ 1 ],
264  args [ 2 ], enable ) ) != 0 ) {
265  /* Not supported */
266  stub->len = 0;
268  return;
269  }
270  gdbstub_send_ok ( stub );
271 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
int gdbmach_set_breakpoint(int type, unsigned long addr, size_t len, int enable)
Set hardware breakpoint.
Definition: gdbmach.c:133
static int gdbstub_get_packet_args(struct gdbstub *stub, unsigned long *args, int nargs, int *stop_idx)
Definition: gdbstub.c:171
char * payload
Definition: gdbstub.c:59
static void gdbstub_tx_packet(struct gdbstub *stub)
Definition: gdbstub.c:144
static void gdbstub_send_errno(struct gdbstub *stub, int errno)
Definition: gdbstub.c:196
static struct gdbstub stub
Definition: gdbstub.c:367
static void gdbstub_send_ok(struct gdbstub *stub)
Definition: gdbstub.c:155
int len
Definition: gdbstub.c:60
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

References gdbmach_set_breakpoint(), gdbstub_get_packet_args(), gdbstub_send_errno(), gdbstub_send_ok(), gdbstub_tx_packet(), gdbstub::len, NULL, gdbstub::payload, POSIX_EINVAL, rc, and stub.

Referenced by gdbstub_rx_packet().

◆ gdbstub_rx_packet()

static void gdbstub_rx_packet ( struct gdbstub stub)
static

Definition at line 273 of file gdbstub.c.

273  {
274  switch ( stub->payload [ 0 ] ) {
275  case '?':
277  break;
278  case 'g':
280  break;
281  case 'G':
283  break;
284  case 'm':
286  break;
287  case 'M':
289  break;
290  case 'c': /* Continue */
291  case 'k': /* Kill */
292  case 's': /* Step */
293  case 'D': /* Detach */
294  gdbstub_continue ( stub, stub->payload [ 0 ] == 's' );
295  if ( stub->payload [ 0 ] == 'D' ) {
296  gdbstub_send_ok ( stub );
297  }
298  break;
299  case 'Z': /* Insert breakpoint */
300  case 'z': /* Remove breakpoint */
302  break;
303  default:
304  stub->len = 0;
306  break;
307  }
308 }
static void gdbstub_continue(struct gdbstub *stub, int single_step)
Definition: gdbstub.c:244
static void gdbstub_report_signal(struct gdbstub *stub)
Definition: gdbstub.c:200
static void gdbstub_write_regs(struct gdbstub *stub)
Definition: gdbstub.c:210
char * payload
Definition: gdbstub.c:59
static void gdbstub_tx_packet(struct gdbstub *stub)
Definition: gdbstub.c:144
static void gdbstub_read_regs(struct gdbstub *stub)
Definition: gdbstub.c:204
static void gdbstub_breakpoint(struct gdbstub *stub)
Definition: gdbstub.c:254
static struct gdbstub stub
Definition: gdbstub.c:367
static void gdbstub_write_mem(struct gdbstub *stub)
Definition: gdbstub.c:231
static void gdbstub_read_mem(struct gdbstub *stub)
Definition: gdbstub.c:219
static void gdbstub_send_ok(struct gdbstub *stub)
Definition: gdbstub.c:155
int len
Definition: gdbstub.c:60

References gdbstub_breakpoint(), gdbstub_continue(), gdbstub_read_mem(), gdbstub_read_regs(), gdbstub_report_signal(), gdbstub_send_ok(), gdbstub_tx_packet(), gdbstub_write_mem(), gdbstub_write_regs(), gdbstub::len, gdbstub::payload, and stub.

Referenced by gdbstub_state_cksum2().

◆ gdbstub_parse()

static void gdbstub_parse ( struct gdbstub stub,
char  ch 
)
static

Definition at line 363 of file gdbstub.c.

363  {
364  stub->parse ( stub, ch );
365 }
void(* parse)(struct gdbstub *stub, char ch)
Definition: gdbstub.c:52
uint8_t ch
Definition: registers.h:83
static struct gdbstub stub
Definition: gdbstub.c:367

References ch, gdbstub::parse, and stub.

Referenced by gdbstub_handler().

◆ gdbstub_handler()

void gdbstub_handler ( int  signo,
gdbreg_t regs 
)

Interrupt handler.

@signo POSIX signal number @regs CPU register snapshot

Definition at line 371 of file gdbstub.c.

371  {
372  char packet [ SIZEOF_PAYLOAD + 4 ];
373  size_t len, i;
374 
375  /* A transport must be set up */
376  if ( !stub.trans ) {
377  return;
378  }
379 
380  stub.signo = signo;
381  stub.regs = regs;
382  stub.exit_handler = 0;
384  while ( !stub.exit_handler && ( len = stub.trans->recv ( packet, sizeof ( packet ) ) ) > 0 ) {
385  for ( i = 0; i < len; i++ ) {
386  gdbstub_parse ( &stub, packet [ i ] );
387  }
388  }
389 }
static void gdbstub_report_signal(struct gdbstub *stub)
Definition: gdbstub.c:200
int signo
Definition: gdbstub.c:49
int exit_handler
Definition: gdbstub.c:47
struct gdb_transport * trans
Definition: gdbstub.c:46
static struct gdbstub stub
Definition: gdbstub.c:367
gdbreg_t * regs
Definition: gdbstub.c:50
struct i386_regs regs
Definition: registers.h:15
static void gdbstub_parse(struct gdbstub *stub, char ch)
Definition: gdbstub.c:363
size_t(* recv)(char *buf, size_t len)
Perform a blocking read.
Definition: gdbstub.h:40
uint32_t len
Length.
Definition: ena.h:14

References gdbstub::exit_handler, gdbstub_parse(), gdbstub_report_signal(), len, gdb_transport::recv, gdbstub::regs, regs, gdbstub::signo, SIZEOF_PAYLOAD, stub, and gdbstub::trans.

Referenced by gdbmach_handler().

◆ find_gdb_transport()

struct gdb_transport* find_gdb_transport ( const char *  name)

Look up GDB transport by name.

Parameters
nameName of transport
Return values
GDBtransport or NULL

Definition at line 391 of file gdbstub.c.

391  {
392  struct gdb_transport *trans;
393 
395  if ( strcmp ( trans->name, name ) == 0 ) {
396  return trans;
397  }
398  }
399  return NULL;
400 }
const char * name
Definition: ath9k_hw.c:1984
const char * name
Transport name.
Definition: gdbstub.h:22
#define for_each_table_entry(pointer, table)
Iterate through all entries within a linker table.
Definition: tables.h:385
int strcmp(const char *first, const char *second)
Compare strings.
Definition: string.c:173
#define GDB_TRANSPORTS
Definition: gdbstub.h:50
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
A transport mechanism for the GDB protocol.
Definition: gdbstub.h:20

References for_each_table_entry, GDB_TRANSPORTS, gdb_transport::name, name, NULL, and strcmp().

Referenced by parse_gdb_transport().

◆ gdbstub_start()

void gdbstub_start ( struct gdb_transport trans)

Break into the debugger using the given transport.

Parameters
transGDB transport

Definition at line 402 of file gdbstub.c.

402  {
403  stub.trans = trans;
404  stub.payload = &stub.buf [ 1 ];
405  gdbmach_init();
407 }
static void gdbmach_breakpoint(void)
Definition: gdbmach.h:64
void gdbmach_init(void)
Initialise GDB.
Definition: gdbmach.c:241
char * payload
Definition: gdbstub.c:59
char buf[SIZEOF_PAYLOAD+4]
Definition: gdbstub.c:58
struct gdb_transport * trans
Definition: gdbstub.c:46
static struct gdbstub stub
Definition: gdbstub.c:367

References gdbstub::buf, gdbmach_breakpoint(), gdbmach_init(), gdbstub::payload, stub, and gdbstub::trans.

Referenced by gdbstub_exec().

Variable Documentation

◆ stub

struct gdbstub stub
static