OpenOCD
gdb_server.c File Reference

GDB server implementation. More...

Include dependency graph for gdb_server.c:

Go to the source code of this file.

Data Structures

struct  gdb_connection
 
struct  target_desc_format
 

Enumerations

enum  gdb_output_flag { GDB_OUTPUT_NO , GDB_OUTPUT_NOTIF , GDB_OUTPUT_ALL }
 

Functions

static __attribute__ ((format(PRINTF_ATTRIBUTE_FORMAT, 5, 6)))
 
static int check_pending (struct connection *connection, int timeout_s, int *got_data)
 
 COMMAND_HANDLER (handle_gdb_breakpoint_override_command)
 
 COMMAND_HANDLER (handle_gdb_flash_program_command)
 
 COMMAND_HANDLER (handle_gdb_memory_map_command)
 
 COMMAND_HANDLER (handle_gdb_port_command)
 
 COMMAND_HANDLER (handle_gdb_report_data_abort_command)
 
 COMMAND_HANDLER (handle_gdb_report_register_access_error)
 
 COMMAND_HANDLER (handle_gdb_save_tdesc_command)
 
 COMMAND_HANDLER (handle_gdb_sync_command)
 
 COMMAND_HANDLER (handle_gdb_target_description_command)
 
static int compare_bank (const void *a, const void *b)
 
static int decode_xfer_read (char const *buf, char **annex, int *ofs, unsigned int *len)
 
static int fetch_packet (struct connection *connection, int *checksum_ok, int noack, int *len, char *buffer)
 
static void gdb_async_notif (struct connection *connection)
 
static int gdb_breakpoint_watchpoint_packet (struct connection *connection, char const *packet, int packet_size)
 
static int gdb_connection_closed (struct connection *connection)
 
static int gdb_detach (struct connection *connection)
 
static int gdb_error (struct connection *connection, int retval)
 
static void gdb_fileio_reply (struct target *target, struct connection *connection)
 
static int gdb_fileio_response_packet (struct connection *connection, char const *packet, int packet_size)
 
static void gdb_frontend_halted (struct target *target, struct connection *connection)
 
static int gdb_generate_reg_type_description (struct target *target, char **tdesc, int *pos, int *size, struct reg_data_type *type, char const **arch_defined_types_list[], int *num_arch_defined_types)
 
static int gdb_generate_target_description (struct target *target, char **tdesc_out)
 
static int gdb_generate_thread_list (struct target *target, char **thread_list_out)
 
int gdb_get_actual_connections (void)
 
static int gdb_get_char (struct connection *connection, int *next_char)
 
static int gdb_get_char_fast (struct connection *connection, int *next_char, char **buf_p, int *buf_cnt)
 The cool thing about this fn is that it allows buf_p and buf_cnt to be held in registers in the inner loop. More...
 
static int gdb_get_char_inner (struct connection *connection, int *next_char)
 
static int gdb_get_packet (struct connection *connection, char *buffer, int *len)
 
static int gdb_get_packet_inner (struct connection *connection, char *buffer, int *len)
 
static const char * gdb_get_reg_type_name (enum reg_type type)
 
static int gdb_get_reg_value_as_str (struct target *target, char *tstr, struct reg *reg)
 
static int gdb_get_register_packet (struct connection *connection, char const *packet, int packet_size)
 
static int gdb_get_registers_packet (struct connection *connection, char const *packet, int packet_size)
 
static int gdb_get_target_description_chunk (struct target *target, struct target_desc_format *target_desc, char **chunk, int32_t offset, uint32_t length)
 
static int gdb_get_thread_list_chunk (struct target *target, char **thread_list, char **chunk, int32_t offset, uint32_t length)
 
static bool gdb_handle_vcont_packet (struct connection *connection, const char *packet, __attribute__((unused)) int packet_size)
 
static bool gdb_handle_vrun_packet (struct connection *connection, const char *packet, int packet_size)
 
static int gdb_input (struct connection *connection)
 
static int gdb_input_inner (struct connection *connection)
 
static void gdb_keep_client_alive (struct connection *connection)
 
static int gdb_last_signal (struct target *target)
 
static int gdb_last_signal_packet (struct connection *connection, char const *packet, int packet_size)
 
static void gdb_log_callback (void *priv, const char *file, unsigned int line, const char *function, const char *string)
 
static void gdb_log_incoming_packet (struct connection *connection, const char *packet)
 
static void gdb_log_outgoing_packet (struct connection *connection, const char *packet_buf, unsigned int packet_len, unsigned char checksum)
 
static int gdb_memory_map (struct connection *connection, char const *packet, int packet_size)
 
static int gdb_new_connection (struct connection *connection)
 
static int gdb_output (struct command_context *context, const char *line)
 
static int gdb_output_con (struct connection *connection, const char *line)
 
int gdb_put_packet (struct connection *connection, const char *buffer, int len)
 
static int gdb_put_packet_inner (struct connection *connection, const char *buffer, int len)
 
static int gdb_putback_char (struct connection *connection, int last_char)
 
static int gdb_query_packet (struct connection *connection, char const *packet, int packet_size)
 
static int gdb_read_memory_packet (struct connection *connection, char const *packet, int packet_size)
 
static int gdb_reg_pos (struct target *target, int pos, int len)
 
int gdb_register_commands (struct command_context *cmd_ctx)
 
static void gdb_restart_inferior (struct connection *connection, const char *packet, int packet_size)
 
static void gdb_send_error (struct connection *connection, uint8_t the_error)
 
void gdb_service_free (void)
 
static int gdb_set_register_packet (struct connection *connection, char const *packet, int packet_size)
 
static int gdb_set_registers_packet (struct connection *connection, char const *packet, int packet_size)
 
static void gdb_sig_halted (struct connection *connection)
 
static void gdb_signal_reply (struct target *target, struct connection *connection)
 
static int gdb_step_continue_packet (struct connection *connection, char const *packet, int packet_size)
 
static void gdb_str_to_target (struct target *target, char *tstr, struct reg *reg)
 
int gdb_target_add_all (struct target *target)
 
static int gdb_target_add_one (struct target *target)
 
static int gdb_target_callback_event_handler (struct target *target, enum target_event event, void *priv)
 
static int gdb_target_description_supported (struct target *target, bool *supported)
 
static int gdb_target_start (struct target *target, const char *port)
 
static void gdb_target_to_reg (struct target *target, char const *tstr, int str_len, uint8_t *bin)
 
static int gdb_v_packet (struct connection *connection, char const *packet, int packet_size)
 
static int gdb_write (struct connection *connection, const void *data, int len)
 
static int gdb_write_memory_binary_packet (struct connection *connection, char const *packet, int packet_size)
 
static int gdb_write_memory_packet (struct connection *connection, char const *packet, int packet_size)
 
static int get_reg_features_list (struct target *target, char const **feature_list[], int *feature_list_size, struct reg **reg_list, int reg_list_size)
 
static int lookup_add_arch_defined_types (char const **arch_defined_types_list[], const char *type_id, int *num_arch_defined_types)
 
static char * next_hex_encoded_field (const char **str, char sep)
 
static int smp_reg_list_noread (struct target *target, struct reg **combined_list[], int *combined_list_size, enum target_register_class reg_class)
 

Variables

static struct gdb_connectioncurrent_gdb_connection
 
static int gdb_actual_connections
 
static int gdb_breakpoint_override
 
static enum breakpoint_type gdb_breakpoint_override_type
 
static const struct command_registration gdb_command_handlers []
 
static bool gdb_flash_program = true
 
static char * gdb_port
 
static char * gdb_port_next
 
static int gdb_report_data_abort
 
static int gdb_report_register_access_error
 
static char gdb_running_type
 
static const struct service_driver gdb_service_driver
 
static const struct command_registration gdb_subcommand_handlers []
 
static bool gdb_use_memory_map = true
 
static bool gdb_use_target_description = true
 

Detailed Description

GDB server implementation.

This implements the GDB Remote Serial Protocol, over TCP connections, giving GDB access to the JTAG or other hardware debugging facilities found in most modern embedded processors.

Definition in file gdb_server.c.

Enumeration Type Documentation

◆ gdb_output_flag

Enumerator
GDB_OUTPUT_NO 
GDB_OUTPUT_NOTIF 
GDB_OUTPUT_ALL 

Definition at line 53 of file gdb_server.c.

Function Documentation

◆ __attribute__()

static __attribute__ ( (format(PRINTF_ATTRIBUTE_FORMAT, 5, 6))  )
static

Definition at line 1820 of file gdb_server.c.

References ERROR_OK, ERROR_SERVER_REMOTE_CLOSED, and size.

◆ check_pending()

static int check_pending ( struct connection connection,
int  timeout_s,
int *  got_data 
)
static

◆ COMMAND_HANDLER() [1/9]

COMMAND_HANDLER ( handle_gdb_breakpoint_override_command  )

◆ COMMAND_HANDLER() [2/9]

COMMAND_HANDLER ( handle_gdb_flash_program_command  )

◆ COMMAND_HANDLER() [3/9]

COMMAND_HANDLER ( handle_gdb_memory_map_command  )

◆ COMMAND_HANDLER() [4/9]

COMMAND_HANDLER ( handle_gdb_port_command  )

Definition at line 3941 of file gdb_server.c.

References CALL_COMMAND_HANDLER, ERROR_OK, gdb_port, and gdb_port_next.

◆ COMMAND_HANDLER() [5/9]

COMMAND_HANDLER ( handle_gdb_report_data_abort_command  )

◆ COMMAND_HANDLER() [6/9]

COMMAND_HANDLER ( handle_gdb_report_register_access_error  )

◆ COMMAND_HANDLER() [7/9]

◆ COMMAND_HANDLER() [8/9]

COMMAND_HANDLER ( handle_gdb_sync_command  )

◆ COMMAND_HANDLER() [9/9]

COMMAND_HANDLER ( handle_gdb_target_description_command  )

◆ compare_bank()

static int compare_bank ( const void *  a,
const void *  b 
)
static

Definition at line 1883 of file gdb_server.c.

References flash_bank::base.

Referenced by gdb_memory_map().

◆ decode_xfer_read()

static int decode_xfer_read ( char const *  buf,
char **  annex,
int *  ofs,
unsigned int *  len 
)
static

Definition at line 1856 of file gdb_server.c.

References ERROR_FAIL, ERROR_OK, NULL, and strndup().

Referenced by gdb_query_packet().

◆ fetch_packet()

static int fetch_packet ( struct connection connection,
int *  checksum_ok,
int  noack,
int *  len,
char *  buffer 
)
inlinestatic

◆ gdb_async_notif()

static void gdb_async_notif ( struct connection connection)
static

Definition at line 3774 of file gdb_server.c.

References count, gdb_write(), and LOG_DEBUG.

Referenced by gdb_keep_client_alive().

◆ gdb_breakpoint_watchpoint_packet()

◆ gdb_connection_closed()

◆ gdb_detach()

static int gdb_detach ( struct connection connection)
static

Definition at line 3413 of file gdb_server.c.

References gdb_put_packet().

Referenced by gdb_input_inner().

◆ gdb_error()

◆ gdb_fileio_reply()

◆ gdb_fileio_response_packet()

static int gdb_fileio_response_packet ( struct connection connection,
char const *  packet,
int  packet_size 
)
static

◆ gdb_frontend_halted()

◆ gdb_generate_reg_type_description()

◆ gdb_generate_target_description()

◆ gdb_generate_thread_list()

static int gdb_generate_thread_list ( struct target target,
char **  thread_list_out 
)
static

◆ gdb_get_actual_connections()

int gdb_get_actual_connections ( void  )

Definition at line 4163 of file gdb_server.c.

References gdb_actual_connections.

Referenced by gdb_timeout_warning(), and semihosting_common().

◆ gdb_get_char()

static int gdb_get_char ( struct connection connection,
int *  next_char 
)
static

◆ gdb_get_char_fast()

static int gdb_get_char_fast ( struct connection connection,
int *  next_char,
char **  buf_p,
int *  buf_cnt 
)
inlinestatic

The cool thing about this fn is that it allows buf_p and buf_cnt to be held in registers in the inner loop.

For small caches and embedded systems this is important!

Definition at line 286 of file gdb_server.c.

References gdb_connection::buf_cnt, gdb_connection::buf_p, ERROR_OK, gdb_get_char_inner(), connection::input_pending, LOG_DEBUG, and connection::priv.

Referenced by fetch_packet(), and gdb_get_char().

◆ gdb_get_char_inner()

◆ gdb_get_packet()

static int gdb_get_packet ( struct connection connection,
char *  buffer,
int *  len 
)
static

Definition at line 736 of file gdb_server.c.

References buffer, gdb_connection::busy, gdb_get_packet_inner(), and connection::priv.

Referenced by gdb_input_inner().

◆ gdb_get_packet_inner()

static int gdb_get_packet_inner ( struct connection connection,
char *  buffer,
int *  len 
)
static

◆ gdb_get_reg_type_name()

◆ gdb_get_reg_value_as_str()

static int gdb_get_reg_value_as_str ( struct target target,
char *  tstr,
struct reg reg 
)
static

◆ gdb_get_register_packet()

◆ gdb_get_registers_packet()

static int gdb_get_registers_packet ( struct connection connection,
char const *  packet,
int  packet_size 
)
static

◆ gdb_get_target_description_chunk()

static int gdb_get_target_description_chunk ( struct target target,
struct target_desc_format target_desc,
char **  chunk,
int32_t  offset,
uint32_t  length 
)
static

◆ gdb_get_thread_list_chunk()

static int gdb_get_thread_list_chunk ( struct target target,
char **  thread_list,
char **  chunk,
int32_t  offset,
uint32_t  length 
)
static

Definition at line 2698 of file gdb_server.c.

References ERROR_FAIL, ERROR_OK, gdb_generate_thread_list(), length, LOG_ERROR, MIN, NULL, and offset.

Referenced by gdb_query_packet().

◆ gdb_handle_vcont_packet()

◆ gdb_handle_vrun_packet()

static bool gdb_handle_vrun_packet ( struct connection connection,
const char *  packet,
int  packet_size 
)
static

◆ gdb_input()

static int gdb_input ( struct connection connection)
static

◆ gdb_input_inner()

◆ gdb_keep_client_alive()

static void gdb_keep_client_alive ( struct connection connection)
static

◆ gdb_last_signal()

◆ gdb_last_signal_packet()

static int gdb_last_signal_packet ( struct connection connection,
char const *  packet,
int  packet_size 
)
static

◆ gdb_log_callback()

static void gdb_log_callback ( void *  priv,
const char *  file,
unsigned int  line,
const char *  function,
const char *  string 
)
static

◆ gdb_log_incoming_packet()

static void gdb_log_incoming_packet ( struct connection connection,
const char *  packet 
)
static

◆ gdb_log_outgoing_packet()

static void gdb_log_outgoing_packet ( struct connection connection,
const char *  packet_buf,
unsigned int  packet_len,
unsigned char  checksum 
)
static

◆ gdb_memory_map()

◆ gdb_new_connection()

static int gdb_new_connection ( struct connection connection)
static

◆ gdb_output()

static int gdb_output ( struct command_context context,
const char *  line 
)
static

Definition at line 765 of file gdb_server.c.

References ERROR_OK, and LOG_USER_N.

Referenced by gdb_new_connection().

◆ gdb_output_con()

static int gdb_output_con ( struct connection connection,
const char *  line 
)
static

◆ gdb_put_packet()

◆ gdb_put_packet_inner()

◆ gdb_putback_char()

static int gdb_putback_char ( struct connection connection,
int  last_char 
)
static

◆ gdb_query_packet()

◆ gdb_read_memory_packet()

static int gdb_read_memory_packet ( struct connection connection,
char const *  packet,
int  packet_size 
)
static

◆ gdb_reg_pos()

static int gdb_reg_pos ( struct target target,
int  pos,
int  len 
)
inlinestatic

Definition at line 1162 of file gdb_server.c.

References target::endianness, and TARGET_LITTLE_ENDIAN.

Referenced by gdb_str_to_target(), and gdb_target_to_reg().

◆ gdb_register_commands()

int gdb_register_commands ( struct command_context cmd_ctx)

Definition at line 4150 of file gdb_server.c.

References gdb_command_handlers, gdb_port, gdb_port_next, NULL, and register_commands().

Referenced by setup_command_handler().

◆ gdb_restart_inferior()

static void gdb_restart_inferior ( struct connection connection,
const char *  packet,
int  packet_size 
)
static

◆ gdb_send_error()

static void gdb_send_error ( struct connection connection,
uint8_t  the_error 
)
static

Definition at line 1132 of file gdb_server.c.

References gdb_put_packet().

Referenced by gdb_error(), gdb_query_packet(), and gdb_v_packet().

◆ gdb_service_free()

void gdb_service_free ( void  )

Definition at line 4157 of file gdb_server.c.

References gdb_port, and gdb_port_next.

Referenced by openocd_main().

◆ gdb_set_register_packet()

◆ gdb_set_registers_packet()

◆ gdb_sig_halted()

static void gdb_sig_halted ( struct connection connection)
static

Definition at line 3490 of file gdb_server.c.

References gdb_put_packet().

Referenced by gdb_handle_vcont_packet(), and gdb_input_inner().

◆ gdb_signal_reply()

◆ gdb_step_continue_packet()

static int gdb_step_continue_packet ( struct connection connection,
char const *  packet,
int  packet_size 
)
static

◆ gdb_str_to_target()

static void gdb_str_to_target ( struct target target,
char *  tstr,
struct reg reg 
)
static

Definition at line 1179 of file gdb_server.c.

References DIV_ROUND_UP, gdb_reg_pos(), reg::size, and reg::value.

Referenced by gdb_get_reg_value_as_str().

◆ gdb_target_add_all()

int gdb_target_add_all ( struct target target)

Definition at line 3907 of file gdb_server.c.

References ERROR_OK, gdb_target_add_one(), LOG_WARNING, and target::next.

Referenced by COMMAND_HANDLER().

◆ gdb_target_add_one()

◆ gdb_target_callback_event_handler()

static int gdb_target_callback_event_handler ( struct target target,
enum target_event  event,
void *  priv 
)
static

◆ gdb_target_description_supported()

static int gdb_target_description_supported ( struct target target,
bool *  supported 
)
static

◆ gdb_target_start()

static int gdb_target_start ( struct target target,
const char *  port 
)
static

◆ gdb_target_to_reg()

static void gdb_target_to_reg ( struct target target,
char const *  tstr,
int  str_len,
uint8_t *  bin 
)
static

Definition at line 1196 of file gdb_server.c.

References gdb_reg_pos(), and LOG_ERROR.

Referenced by gdb_set_register_packet(), and gdb_set_registers_packet().

◆ gdb_v_packet()

◆ gdb_write()

static int gdb_write ( struct connection connection,
const void *  data,
int  len 
)
static

◆ gdb_write_memory_binary_packet()

static int gdb_write_memory_binary_packet ( struct connection connection,
char const *  packet,
int  packet_size 
)
static

◆ gdb_write_memory_packet()

static int gdb_write_memory_packet ( struct connection connection,
char const *  packet,
int  packet_size 
)
static

◆ get_reg_features_list()

static int get_reg_features_list ( struct target target,
char const **  feature_list[],
int *  feature_list_size,
struct reg **  reg_list,
int  reg_list_size 
)
static

◆ lookup_add_arch_defined_types()

static int lookup_add_arch_defined_types ( char const **  arch_defined_types_list[],
const char *  type_id,
int *  num_arch_defined_types 
)
static

Definition at line 2090 of file gdb_server.c.

References NULL.

Referenced by gdb_generate_reg_type_description(), and gdb_generate_target_description().

◆ next_hex_encoded_field()

static char* next_hex_encoded_field ( const char **  str,
char  sep 
)
static

Definition at line 3153 of file gdb_server.c.

References count, NULL, and unhexify().

Referenced by gdb_handle_vrun_packet().

◆ smp_reg_list_noread()

static int smp_reg_list_noread ( struct target target,
struct reg **  combined_list[],
int *  combined_list_size,
enum target_register_class  reg_class 
)
static

Variable Documentation

◆ current_gdb_connection

struct gdb_connection* current_gdb_connection
static

Definition at line 110 of file gdb_server.c.

Referenced by COMMAND_HANDLER(), and gdb_query_packet().

◆ gdb_actual_connections

int gdb_actual_connections
static

◆ gdb_breakpoint_override

int gdb_breakpoint_override
static

Definition at line 112 of file gdb_server.c.

Referenced by COMMAND_HANDLER(), and gdb_breakpoint_watchpoint_packet().

◆ gdb_breakpoint_override_type

enum breakpoint_type gdb_breakpoint_override_type
static

Definition at line 112 of file gdb_server.c.

Referenced by COMMAND_HANDLER(), and gdb_breakpoint_watchpoint_packet().

◆ gdb_command_handlers

const struct command_registration gdb_command_handlers[]
static
Initial value:
= {
{
.name = "gdb",
.mode = COMMAND_ANY,
.help = "GDB commands",
.usage = "",
},
}
#define COMMAND_REGISTRATION_DONE
Use this as the last entry in an array of command_registration records.
Definition: command.h:253
@ COMMAND_ANY
Definition: command.h:42
static const struct command_registration gdb_subcommand_handlers[]
Definition: gdb_server.c:4063
const char * usage
a string listing the options and arguments, required or optional
Definition: command.h:241

Definition at line 4019 of file gdb_server.c.

Referenced by gdb_register_commands().

◆ gdb_flash_program

bool gdb_flash_program = true
static

Definition at line 133 of file gdb_server.c.

Referenced by COMMAND_HANDLER(), and gdb_v_packet().

◆ gdb_port

char* gdb_port
static

Definition at line 116 of file gdb_server.c.

Referenced by COMMAND_HANDLER(), gdb_register_commands(), and gdb_service_free().

◆ gdb_port_next

char* gdb_port_next
static

◆ gdb_report_data_abort

int gdb_report_data_abort
static

Definition at line 139 of file gdb_server.c.

Referenced by COMMAND_HANDLER(), and gdb_read_memory_packet().

◆ gdb_report_register_access_error

int gdb_report_register_access_error
static

◆ gdb_running_type

char gdb_running_type
static

◆ gdb_service_driver

const struct service_driver gdb_service_driver
static
Initial value:
= {
.name = "gdb",
.new_connection_during_keep_alive_handler = NULL,
.new_connection_handler = gdb_new_connection,
.input_handler = gdb_input,
.connection_closed_handler = gdb_connection_closed,
.keep_client_alive_handler = gdb_keep_client_alive,
}
static void gdb_keep_client_alive(struct connection *connection)
Definition: gdb_server.c:3792
static int gdb_connection_closed(struct connection *connection)
Definition: gdb_server.c:1092
static int gdb_input(struct connection *connection)
Definition: gdb_server.c:3744
static int gdb_new_connection(struct connection *connection)
Definition: gdb_server.c:977
#define NULL
Definition: usb.h:16

Definition at line 3792 of file gdb_server.c.

Referenced by gdb_target_start().

◆ gdb_subcommand_handlers

const struct command_registration gdb_subcommand_handlers[]
static

Definition at line 4019 of file gdb_server.c.

◆ gdb_use_memory_map

bool gdb_use_memory_map = true
static

Definition at line 131 of file gdb_server.c.

Referenced by COMMAND_HANDLER(), gdb_new_connection(), and gdb_query_packet().

◆ gdb_use_target_description

bool gdb_use_target_description = true
static

Definition at line 147 of file gdb_server.c.

Referenced by COMMAND_HANDLER(), and gdb_query_packet().