X-Git-Url: https://review.openocd.org/gitweb?a=blobdiff_plain;ds=sidebyside;f=src%2Fserver%2Fgdb_server.c;h=4151ec7932bd0a563ed584e94c25861b4ef45a4d;hb=98723c4ecdbe06f90c66f3abec27b792c3b38e34;hp=761ae4064294c316e3d015270977568ca1f6670e;hpb=5b6df55a1e5e4c0f531bc336691bc7c9a6a0df87;p=openocd.git diff --git a/src/server/gdb_server.c b/src/server/gdb_server.c index 761ae40642..4151ec7932 100644 --- a/src/server/gdb_server.c +++ b/src/server/gdb_server.c @@ -40,12 +40,12 @@ #define _DEBUG_GDB_IO_ #endif -static gdb_connection_t *current_gdb_connection; +static struct gdb_connection *current_gdb_connection; static int gdb_breakpoint_override; static enum breakpoint_type gdb_breakpoint_override_type; -extern int gdb_error(connection_t *connection, int retval); +extern int gdb_error(struct connection *connection, int retval); static unsigned short gdb_port = 3333; static const char *DIGITS = "0123456789abcdef"; @@ -67,7 +67,7 @@ int gdb_flash_program = 1; * see the code in gdb_read_memory_packet() for further explanations */ int gdb_report_data_abort = 0; -int gdb_last_signal(target_t *target) +int gdb_last_signal(struct target *target) { switch (target->debug_reason) { @@ -87,14 +87,14 @@ int gdb_last_signal(target_t *target) } } -int check_pending(connection_t *connection, int timeout_s, int *got_data) +int check_pending(struct connection *connection, int timeout_s, int *got_data) { /* a non-blocking socket will block if there is 0 bytes available on the socket, * but return with as many bytes as are available immediately */ struct timeval tv; fd_set read_fds; - gdb_connection_t *gdb_con = connection->priv; + struct gdb_connection *gdb_con = connection->priv; int t; if (got_data == NULL) got_data=&t; @@ -128,9 +128,9 @@ int check_pending(connection_t *connection, int timeout_s, int *got_data) return ERROR_OK; } -int gdb_get_char(connection_t *connection, int* next_char) +int gdb_get_char(struct connection *connection, int* next_char) { - gdb_connection_t *gdb_con = connection->priv; + struct gdb_connection *gdb_con = connection->priv; int retval = ERROR_OK; #ifdef _DEBUG_GDB_IO_ @@ -236,9 +236,9 @@ int gdb_get_char(connection_t *connection, int* next_char) return retval; } -int gdb_putback_char(connection_t *connection, int last_char) +int gdb_putback_char(struct connection *connection, int last_char) { - gdb_connection_t *gdb_con = connection->priv; + struct gdb_connection *gdb_con = connection->priv; if (gdb_con->buf_p > gdb_con->buffer) { @@ -256,9 +256,9 @@ int gdb_putback_char(connection_t *connection, int last_char) /* The only way we can detect that the socket is closed is the first time * we write to it, we will fail. Subsequent write operations will * succeed. Shudder! */ -int gdb_write(connection_t *connection, void *data, int len) +int gdb_write(struct connection *connection, void *data, int len) { - gdb_connection_t *gdb_con = connection->priv; + struct gdb_connection *gdb_con = connection->priv; if (gdb_con->closed) return ERROR_SERVER_REMOTE_CLOSED; @@ -281,7 +281,7 @@ int gdb_write(connection_t *connection, void *data, int len) return ERROR_SERVER_REMOTE_CLOSED; } -int gdb_put_packet_inner(connection_t *connection, char *buffer, int len) +int gdb_put_packet_inner(struct connection *connection, char *buffer, int len) { int i; unsigned char my_checksum = 0; @@ -290,7 +290,7 @@ int gdb_put_packet_inner(connection_t *connection, char *buffer, int len) #endif int reply; int retval; - gdb_connection_t *gdb_con = connection->priv; + struct gdb_connection *gdb_con = connection->priv; for (i = 0; i < len; i++) my_checksum += buffer[i]; @@ -422,9 +422,9 @@ int gdb_put_packet_inner(connection_t *connection, char *buffer, int len) return ERROR_OK; } -int gdb_put_packet(connection_t *connection, char *buffer, int len) +int gdb_put_packet(struct connection *connection, char *buffer, int len) { - gdb_connection_t *gdb_con = connection->priv; + struct gdb_connection *gdb_con = connection->priv; gdb_con->busy = 1; int retval = gdb_put_packet_inner(connection, buffer, len); gdb_con->busy = 0; @@ -435,14 +435,14 @@ int gdb_put_packet(connection_t *connection, char *buffer, int len) return retval; } -static __inline__ int fetch_packet(connection_t *connection, int *checksum_ok, int noack, int *len, char *buffer) +static __inline__ int fetch_packet(struct connection *connection, int *checksum_ok, int noack, int *len, char *buffer) { unsigned char my_checksum = 0; char checksum[3]; int character; int retval; - gdb_connection_t *gdb_con = connection->priv; + struct gdb_connection *gdb_con = connection->priv; my_checksum = 0; int count = 0; count = 0; @@ -544,11 +544,11 @@ static __inline__ int fetch_packet(connection_t *connection, int *checksum_ok, i return ERROR_OK; } -int gdb_get_packet_inner(connection_t *connection, char *buffer, int *len) +int gdb_get_packet_inner(struct connection *connection, char *buffer, int *len) { int character; int retval; - gdb_connection_t *gdb_con = connection->priv; + struct gdb_connection *gdb_con = connection->priv; while (1) { @@ -619,16 +619,16 @@ int gdb_get_packet_inner(connection_t *connection, char *buffer, int *len) return ERROR_OK; } -int gdb_get_packet(connection_t *connection, char *buffer, int *len) +int gdb_get_packet(struct connection *connection, char *buffer, int *len) { - gdb_connection_t *gdb_con = connection->priv; + struct gdb_connection *gdb_con = connection->priv; gdb_con->busy = 1; int retval = gdb_get_packet_inner(connection, buffer, len); gdb_con->busy = 0; return retval; } -int gdb_output_con(connection_t *connection, const char* line) +int gdb_output_con(struct connection *connection, const char* line) { char *hex_buffer; int i, bin_size; @@ -650,7 +650,7 @@ int gdb_output_con(connection_t *connection, const char* line) return retval; } -int gdb_output(struct command_context_s *context, const char* line) +int gdb_output(struct command_context *context, const char* line) { /* this will be dumped to the log and also sent as an O packet if possible */ LOG_USER_N("%s", line); @@ -658,9 +658,9 @@ int gdb_output(struct command_context_s *context, const char* line) } -static void gdb_frontend_halted(struct target_s *target, connection_t *connection) +static void gdb_frontend_halted(struct target *target, struct connection *connection) { - gdb_connection_t *gdb_connection = connection->priv; + struct gdb_connection *gdb_connection = connection->priv; /* In the GDB protocol when we are stepping or continuing execution, * we have a lingering reply. Upon receiving a halted event @@ -695,10 +695,10 @@ static void gdb_frontend_halted(struct target_s *target, connection_t *connectio } } -int gdb_target_callback_event_handler(struct target_s *target, enum target_event event, void *priv) +int gdb_target_callback_event_handler(struct target *target, enum target_event event, void *priv) { int retval; - connection_t *connection = priv; + struct connection *connection = priv; target_handle_event(target, event); switch (event) @@ -723,10 +723,10 @@ int gdb_target_callback_event_handler(struct target_s *target, enum target_event return ERROR_OK; } -int gdb_new_connection(connection_t *connection) +int gdb_new_connection(struct connection *connection) { - gdb_connection_t *gdb_connection = malloc(sizeof(gdb_connection_t)); - gdb_service_t *gdb_service = connection->service->priv; + struct gdb_connection *gdb_connection = malloc(sizeof(struct gdb_connection)); + struct gdb_service *gdb_service = connection->service->priv; int retval; int initial_ack; @@ -779,10 +779,10 @@ int gdb_new_connection(connection_t *connection) return ERROR_OK; } -int gdb_connection_closed(connection_t *connection) +int gdb_connection_closed(struct connection *connection) { - gdb_service_t *gdb_service = connection->service->priv; - gdb_connection_t *gdb_connection = connection->priv; + struct gdb_service *gdb_service = connection->service->priv; + struct gdb_connection *gdb_connection = connection->priv; /* we're done forwarding messages. Tear down callback before * cleaning up connection. @@ -826,14 +826,14 @@ int gdb_connection_closed(connection_t *connection) return ERROR_OK; } -void gdb_send_error(connection_t *connection, uint8_t the_error) +void gdb_send_error(struct connection *connection, uint8_t the_error) { char err[4]; snprintf(err, 4, "E%2.2X", the_error); gdb_put_packet(connection, err, 3); } -int gdb_last_signal_packet(connection_t *connection, target_t *target, char* packet, int packet_size) +int gdb_last_signal_packet(struct connection *connection, struct target *target, char* packet, int packet_size) { char sig_reply[4]; int signal; @@ -846,7 +846,7 @@ int gdb_last_signal_packet(connection_t *connection, target_t *target, char* pac return ERROR_OK; } -static int gdb_reg_pos(target_t *target, int pos, int len) +static int gdb_reg_pos(struct target *target, int pos, int len) { if (target->endianness == TARGET_LITTLE_ENDIAN) return pos; @@ -863,7 +863,7 @@ static int gdb_reg_pos(target_t *target, int pos, int len) * The format of reg->value is little endian * */ -void gdb_str_to_target(target_t *target, char *tstr, reg_t *reg) +void gdb_str_to_target(struct target *target, char *tstr, struct reg *reg) { int i; @@ -896,7 +896,7 @@ static int hextoint(char c) } /* copy over in register buffer */ -void gdb_target_to_reg(target_t *target, char *tstr, int str_len, uint8_t *bin) +void gdb_target_to_reg(struct target *target, char *tstr, int str_len, uint8_t *bin) { if (str_len % 2) { @@ -915,9 +915,9 @@ void gdb_target_to_reg(target_t *target, char *tstr, int str_len, uint8_t *bin) } } -int gdb_get_registers_packet(connection_t *connection, target_t *target, char* packet, int packet_size) +int gdb_get_registers_packet(struct connection *connection, struct target *target, char* packet, int packet_size) { - reg_t **reg_list; + struct reg **reg_list; int reg_list_size; int retval; int reg_packet_size = 0; @@ -965,10 +965,10 @@ int gdb_get_registers_packet(connection_t *connection, target_t *target, char* p return ERROR_OK; } -int gdb_set_registers_packet(connection_t *connection, target_t *target, char *packet, int packet_size) +int gdb_set_registers_packet(struct connection *connection, struct target *target, char *packet, int packet_size) { int i; - reg_t **reg_list; + struct reg **reg_list; int reg_list_size; int retval; char *packet_p; @@ -1003,7 +1003,7 @@ int gdb_set_registers_packet(connection_t *connection, target_t *target, char *p LOG_ERROR("BUG: register packet is too small for registers"); } - reg_arch_type_t *arch_type; + struct reg_arch_type *arch_type; bin_buf = malloc(CEIL(reg_list[i]->size, 8)); gdb_target_to_reg(target, packet_p, chars, bin_buf); @@ -1019,7 +1019,7 @@ int gdb_set_registers_packet(connection_t *connection, target_t *target, char *p free(bin_buf); } - /* free reg_t *reg_list[] array allocated by get_gdb_reg_list */ + /* free struct reg *reg_list[] array allocated by get_gdb_reg_list */ free(reg_list); gdb_put_packet(connection, "OK", 2); @@ -1027,11 +1027,11 @@ int gdb_set_registers_packet(connection_t *connection, target_t *target, char *p return ERROR_OK; } -int gdb_get_register_packet(connection_t *connection, target_t *target, char *packet, int packet_size) +int gdb_get_register_packet(struct connection *connection, struct target *target, char *packet, int packet_size) { char *reg_packet; int reg_num = strtoul(packet + 1, NULL, 16); - reg_t **reg_list; + struct reg **reg_list; int reg_list_size; int retval; @@ -1062,15 +1062,15 @@ int gdb_get_register_packet(connection_t *connection, target_t *target, char *pa return ERROR_OK; } -int gdb_set_register_packet(connection_t *connection, target_t *target, char *packet, int packet_size) +int gdb_set_register_packet(struct connection *connection, struct target *target, char *packet, int packet_size) { char *separator; uint8_t *bin_buf; int reg_num = strtoul(packet + 1, &separator, 16); - reg_t **reg_list; + struct reg **reg_list; int reg_list_size; int retval; - reg_arch_type_t *arch_type; + struct reg_arch_type *arch_type; LOG_DEBUG("-"); @@ -1111,7 +1111,7 @@ int gdb_set_register_packet(connection_t *connection, target_t *target, char *pa return ERROR_OK; } -int gdb_error(connection_t *connection, int retval) +int gdb_error(struct connection *connection, int retval) { switch (retval) { @@ -1142,7 +1142,7 @@ int gdb_error(connection_t *connection, int retval) * * 8191 bytes by the looks of it. Why 8191 bytes instead of 8192????? */ -int gdb_read_memory_packet(connection_t *connection, target_t *target, char *packet, int packet_size) +int gdb_read_memory_packet(struct connection *connection, struct target *target, char *packet, int packet_size) { char *separator; uint32_t addr = 0; @@ -1216,7 +1216,7 @@ int gdb_read_memory_packet(connection_t *connection, target_t *target, char *pac return retval; } -int gdb_write_memory_packet(connection_t *connection, target_t *target, char *packet, int packet_size) +int gdb_write_memory_packet(struct connection *connection, struct target *target, char *packet, int packet_size) { char *separator; uint32_t addr = 0; @@ -1273,7 +1273,7 @@ int gdb_write_memory_packet(connection_t *connection, target_t *target, char *pa return retval; } -int gdb_write_memory_binary_packet(connection_t *connection, target_t *target, char *packet, int packet_size) +int gdb_write_memory_binary_packet(struct connection *connection, struct target *target, char *packet, int packet_size) { char *separator; uint32_t addr = 0; @@ -1321,7 +1321,7 @@ int gdb_write_memory_binary_packet(connection_t *connection, target_t *target, c return ERROR_OK; } -int gdb_step_continue_packet(connection_t *connection, target_t *target, char *packet, int packet_size) +int gdb_step_continue_packet(struct connection *connection, struct target *target, char *packet, int packet_size) { int current = 0; uint32_t address = 0x0; @@ -1354,7 +1354,7 @@ int gdb_step_continue_packet(connection_t *connection, target_t *target, char *p return retval; } -int gdb_breakpoint_watchpoint_packet(connection_t *connection, target_t *target, char *packet, int packet_size) +int gdb_breakpoint_watchpoint_packet(struct connection *connection, struct target *target, char *packet, int packet_size) { int type; enum breakpoint_type bp_type = BKPT_SOFT /* dummy init to avoid warning */; @@ -1520,7 +1520,7 @@ static int decode_xfer_read(char *buf, char **annex, int *ofs, unsigned int *len return 0; } -int gdb_calc_blocksize(flash_bank_t *bank) +int gdb_calc_blocksize(struct flash_bank *bank) { uint32_t i; uint32_t block_size = 0xffffffff; @@ -1538,9 +1538,9 @@ int gdb_calc_blocksize(flash_bank_t *bank) static int compare_bank (const void * a, const void * b) { - flash_bank_t *b1, *b2; - b1=*((flash_bank_t **)a); - b2=*((flash_bank_t **)b); + struct flash_bank *b1, *b2; + b1=*((struct flash_bank **)a); + b2=*((struct flash_bank **)b); if (b1->base == b2->base) { @@ -1554,10 +1554,10 @@ static int compare_bank (const void * a, const void * b) } } -int gdb_query_packet(connection_t *connection, target_t *target, char *packet, int packet_size) +int gdb_query_packet(struct connection *connection, struct target *target, char *packet, int packet_size) { - command_context_t *cmd_ctx = connection->cmd_ctx; - gdb_connection_t *gdb_connection = connection->priv; + struct command_context *cmd_ctx = connection->cmd_ctx; + struct gdb_connection *gdb_connection = connection->priv; if (strstr(packet, "qRcmd,")) { @@ -1661,7 +1661,7 @@ int gdb_query_packet(connection_t *connection, target_t *target, char *packet, i * Normally we only execute this code once, but no big deal if we * have to regenerate it a couple of times. */ - flash_bank_t *p; + struct flash_bank *p; char *xml = NULL; int size = 0; int pos = 0; @@ -1685,7 +1685,7 @@ int gdb_query_packet(connection_t *connection, target_t *target, char *packet, i read/write) by default for GDB. GDB does not have a concept of non-cacheable read/write memory. */ - flash_bank_t **banks = malloc(sizeof(flash_bank_t *)*flash_get_bank_count()); + struct flash_bank **banks = malloc(sizeof(struct flash_bank *)*flash_get_bank_count()); int i; for (i = 0; i < flash_get_bank_count(); i++) @@ -1701,7 +1701,7 @@ int gdb_query_packet(connection_t *connection, target_t *target, char *packet, i banks[i]=p; } - qsort(banks, flash_get_bank_count(), sizeof(flash_bank_t *), compare_bank); + qsort(banks, flash_get_bank_count(), sizeof(struct flash_bank *), compare_bank); uint32_t ram_start = 0; for (i = 0; i < flash_get_bank_count(); i++) @@ -1810,10 +1810,10 @@ int gdb_query_packet(connection_t *connection, target_t *target, char *packet, i return ERROR_OK; } -int gdb_v_packet(connection_t *connection, target_t *target, char *packet, int packet_size) +int gdb_v_packet(struct connection *connection, struct target *target, char *packet, int packet_size) { - gdb_connection_t *gdb_connection = connection->priv; - gdb_service_t *gdb_service = connection->service->priv; + struct gdb_connection *gdb_connection = connection->priv; + struct gdb_service *gdb_service = connection->service->priv; int result; /* if flash programming disabled - send a empty reply */ @@ -1899,7 +1899,7 @@ int gdb_v_packet(connection_t *connection, target_t *target, char *packet, int p /* create a new image if there isn't already one */ if (gdb_connection->vflash_image == NULL) { - gdb_connection->vflash_image = malloc(sizeof(image_t)); + gdb_connection->vflash_image = malloc(sizeof(struct image)); image_open(gdb_connection->vflash_image, "", "build"); } @@ -1947,9 +1947,9 @@ int gdb_v_packet(connection_t *connection, target_t *target, char *packet, int p return ERROR_OK; } -int gdb_detach(connection_t *connection, target_t *target) +int gdb_detach(struct connection *connection, struct target *target) { - gdb_service_t *gdb_service = connection->service->priv; + struct gdb_service *gdb_service = connection->service->priv; target_call_event_callbacks(gdb_service->target, TARGET_EVENT_GDB_DETACH); @@ -1959,8 +1959,8 @@ int gdb_detach(connection_t *connection, target_t *target) static void gdb_log_callback(void *priv, const char *file, unsigned line, const char *function, const char *string) { - connection_t *connection = priv; - gdb_connection_t *gdb_con = connection->priv; + struct connection *connection = priv; + struct gdb_connection *gdb_con = connection->priv; if (gdb_con->busy) { @@ -1974,7 +1974,7 @@ static void gdb_log_callback(void *priv, const char *file, unsigned line, /* Do not allocate this on the stack */ char gdb_packet_buffer[GDB_BUFFER_SIZE]; -static void gdb_sig_halted(connection_t *connection) +static void gdb_sig_halted(struct connection *connection) { char sig_reply[4]; snprintf(sig_reply, 4, "T%2.2x", 2); @@ -1982,14 +1982,14 @@ static void gdb_sig_halted(connection_t *connection) } -int gdb_input_inner(connection_t *connection) +int gdb_input_inner(struct connection *connection) { - gdb_service_t *gdb_service = connection->service->priv; - target_t *target = gdb_service->target; + struct gdb_service *gdb_service = connection->service->priv; + struct target *target = gdb_service->target; char *packet = gdb_packet_buffer; int packet_size; int retval; - gdb_connection_t *gdb_con = connection->priv; + struct gdb_connection *gdb_con = connection->priv; static int extended_protocol = 0; /* drain input buffer */ @@ -2063,7 +2063,7 @@ int gdb_input_inner(connection_t *connection) { int retval = ERROR_OK; - gdb_connection_t *gdb_con = connection->priv; + struct gdb_connection *gdb_con = connection->priv; log_add_callback(gdb_log_callback, connection); bool nostep = false; @@ -2180,10 +2180,10 @@ int gdb_input_inner(connection_t *connection) return ERROR_OK; } -int gdb_input(connection_t *connection) +int gdb_input(struct connection *connection) { int retval = gdb_input_inner(connection); - gdb_connection_t *gdb_con = connection->priv; + struct gdb_connection *gdb_con = connection->priv; if (retval == ERROR_SERVER_REMOTE_CLOSED) return retval; @@ -2197,8 +2197,8 @@ int gdb_input(connection_t *connection) int gdb_init(void) { - gdb_service_t *gdb_service; - target_t *target = all_targets; + struct gdb_service *gdb_service; + struct target *target = all_targets; if (!target) { @@ -2216,7 +2216,7 @@ int gdb_init(void) { /* only a single gdb connection when using a pipe */ - gdb_service = malloc(sizeof(gdb_service_t)); + gdb_service = malloc(sizeof(struct gdb_service)); gdb_service->target = target; add_service("gdb", CONNECTION_PIPE, 0, 1, gdb_new_connection, gdb_input, gdb_connection_closed, gdb_service); @@ -2230,7 +2230,7 @@ int gdb_init(void) while (target) { - gdb_service = malloc(sizeof(gdb_service_t)); + gdb_service = malloc(sizeof(struct gdb_service)); gdb_service->target = target; add_service("gdb", CONNECTION_TCP, @@ -2371,7 +2371,7 @@ COMMAND_HANDLER(handle_gdb_breakpoint_override_command) return ERROR_OK; } -int gdb_register_commands(command_context_t *command_context) +int gdb_register_commands(struct command_context *command_context) { register_command(command_context, NULL, "gdb_sync", handle_gdb_sync_command, COMMAND_ANY,