+ int retval = ERROR_OK;
+ struct reg **reg_list = NULL;
+ int reg_list_size;
+ char const *architecture;
+ char const **features = NULL;
+ int feature_list_size = 0;
+ char *tdesc = NULL;
+ int pos = 0;
+ int size = 0;
+
+
+ retval = target_get_gdb_reg_list_noread(target, ®_list,
+ ®_list_size, REG_CLASS_ALL);
+
+ if (retval != ERROR_OK) {
+ LOG_ERROR("get register list failed");
+ retval = ERROR_FAIL;
+ goto error;
+ }
+
+ if (reg_list_size <= 0) {
+ LOG_ERROR("get register list failed");
+ retval = ERROR_FAIL;
+ goto error;
+ }
+
+ /* Get a list of available target registers features */
+ retval = get_reg_features_list(target, &features, &feature_list_size, reg_list, reg_list_size);
+ if (retval != ERROR_OK) {
+ LOG_ERROR("Can't get the registers feature list");
+ retval = ERROR_FAIL;
+ goto error;
+ }
+
+ /* If we found some features associated with registers, create sections */
+ int current_feature = 0;
+
+ xml_printf(&retval, &tdesc, &pos, &size,
+ "<?xml version=\"1.0\"?>\n"
+ "<!DOCTYPE target SYSTEM \"gdb-target.dtd\">\n"
+ "<target version=\"1.0\">\n");
+
+ /* generate architecture element if supported by target */
+ architecture = target_get_gdb_arch(target);
+ if (architecture != NULL)
+ xml_printf(&retval, &tdesc, &pos, &size,
+ "<architecture>%s</architecture>\n", architecture);
+
+ /* generate target description according to register list */
+ if (features != NULL) {
+ while (features[current_feature]) {
+ char const **arch_defined_types = NULL;
+ int num_arch_defined_types = 0;
+
+ arch_defined_types = calloc(1, sizeof(char *));
+ xml_printf(&retval, &tdesc, &pos, &size,
+ "<feature name=\"%s\">\n",
+ features[current_feature]);
+
+ int i;
+ for (i = 0; i < reg_list_size; i++) {
+
+ if (reg_list[i]->exist == false)
+ continue;
+
+ if (strcmp(reg_list[i]->feature->name, features[current_feature]))
+ continue;
+
+ const char *type_str;
+ if (reg_list[i]->reg_data_type != NULL) {
+ if (reg_list[i]->reg_data_type->type == REG_TYPE_ARCH_DEFINED) {
+ /* generate <type... first, if there are architecture-defined types. */
+ if (lookup_add_arch_defined_types(&arch_defined_types,
+ reg_list[i]->reg_data_type->id,
+ &num_arch_defined_types))
+ gdb_generate_reg_type_description(target, &tdesc, &pos, &size,
+ reg_list[i]->reg_data_type,
+ &arch_defined_types,
+ &num_arch_defined_types);
+
+ type_str = reg_list[i]->reg_data_type->id;
+ } else {
+ /* predefined type */
+ type_str = gdb_get_reg_type_name(
+ reg_list[i]->reg_data_type->type);
+ }
+ } else {
+ /* Default type is "int" */
+ type_str = "int";
+ }
+
+ xml_printf(&retval, &tdesc, &pos, &size,
+ "<reg name=\"%s\"", reg_list[i]->name);
+ xml_printf(&retval, &tdesc, &pos, &size,
+ " bitsize=\"%d\"", reg_list[i]->size);
+ xml_printf(&retval, &tdesc, &pos, &size,
+ " regnum=\"%d\"", reg_list[i]->number);
+ if (reg_list[i]->caller_save)
+ xml_printf(&retval, &tdesc, &pos, &size,
+ " save-restore=\"yes\"");
+ else
+ xml_printf(&retval, &tdesc, &pos, &size,
+ " save-restore=\"no\"");
+
+ xml_printf(&retval, &tdesc, &pos, &size,
+ " type=\"%s\"", type_str);
+
+ if (reg_list[i]->group != NULL)
+ xml_printf(&retval, &tdesc, &pos, &size,
+ " group=\"%s\"", reg_list[i]->group);
+
+ xml_printf(&retval, &tdesc, &pos, &size,
+ "/>\n");
+ }
+
+ xml_printf(&retval, &tdesc, &pos, &size,
+ "</feature>\n");
+
+ current_feature++;
+ free(arch_defined_types);
+ }
+ }
+
+ xml_printf(&retval, &tdesc, &pos, &size,
+ "</target>\n");
+
+error:
+ free(features);
+ free(reg_list);
+
+ if (retval == ERROR_OK)
+ *tdesc_out = tdesc;
+ else
+ free(tdesc);
+
+ return retval;
+}
+
+static int gdb_get_target_description_chunk(struct target *target, struct target_desc_format *target_desc,
+ char **chunk, int32_t offset, uint32_t length)
+{
+ if (target_desc == NULL) {
+ LOG_ERROR("Unable to Generate Target Description");
+ return ERROR_FAIL;
+ }
+
+ char *tdesc = target_desc->tdesc;
+ uint32_t tdesc_length = target_desc->tdesc_length;
+
+ if (tdesc == NULL) {
+ int retval = gdb_generate_target_description(target, &tdesc);
+ if (retval != ERROR_OK) {
+ LOG_ERROR("Unable to Generate Target Description");
+ return ERROR_FAIL;
+ }
+
+ tdesc_length = strlen(tdesc);
+ }
+
+ char transfer_type;
+
+ if (length < (tdesc_length - offset))
+ transfer_type = 'm';
+ else
+ transfer_type = 'l';
+
+ *chunk = malloc(length + 2);
+ if (*chunk == NULL) {
+ LOG_ERROR("Unable to allocate memory");
+ return ERROR_FAIL;
+ }
+
+ (*chunk)[0] = transfer_type;
+ if (transfer_type == 'm') {
+ strncpy((*chunk) + 1, tdesc + offset, length);
+ (*chunk)[1 + length] = '\0';
+ } else {
+ strncpy((*chunk) + 1, tdesc + offset, tdesc_length - offset);
+ (*chunk)[1 + (tdesc_length - offset)] = '\0';
+
+ /* After gdb-server sends out last chunk, invalidate tdesc. */
+ free(tdesc);
+ tdesc = NULL;
+ tdesc_length = 0;
+ }
+
+ target_desc->tdesc = tdesc;
+ target_desc->tdesc_length = tdesc_length;
+
+ return ERROR_OK;
+}
+
+static int gdb_target_description_supported(struct target *target, int *supported)
+{
+ int retval = ERROR_OK;
+ struct reg **reg_list = NULL;
+ int reg_list_size = 0;
+ char const **features = NULL;
+ int feature_list_size = 0;
+
+ char const *architecture = target_get_gdb_arch(target);
+
+ retval = target_get_gdb_reg_list_noread(target, ®_list,
+ ®_list_size, REG_CLASS_ALL);
+ if (retval != ERROR_OK) {
+ LOG_ERROR("get register list failed");
+ goto error;
+ }
+
+ if (reg_list_size <= 0) {
+ LOG_ERROR("get register list failed");
+ retval = ERROR_FAIL;
+ goto error;
+ }
+
+ /* Get a list of available target registers features */
+ retval = get_reg_features_list(target, &features, &feature_list_size, reg_list, reg_list_size);
+ if (retval != ERROR_OK) {
+ LOG_ERROR("Can't get the registers feature list");
+ goto error;
+ }
+
+ if (supported) {
+ if (architecture || feature_list_size)
+ *supported = 1;
+ else
+ *supported = 0;
+ }
+
+error:
+ free(features);
+
+ free(reg_list);
+
+ return retval;
+}
+
+static int gdb_generate_thread_list(struct target *target, char **thread_list_out)
+{
+ struct rtos *rtos = target->rtos;
+ int retval = ERROR_OK;
+ char *thread_list = NULL;
+ int pos = 0;
+ int size = 0;
+
+ xml_printf(&retval, &thread_list, &pos, &size,
+ "<?xml version=\"1.0\"?>\n"
+ "<threads>\n");
+
+ if (rtos != NULL) {
+ for (int i = 0; i < rtos->thread_count; i++) {
+ struct thread_detail *thread_detail = &rtos->thread_details[i];
+
+ if (!thread_detail->exists)
+ continue;
+
+ xml_printf(&retval, &thread_list, &pos, &size,
+ "<thread id=\"%" PRIx64 "\">", thread_detail->threadid);
+
+ if (thread_detail->thread_name_str != NULL)
+ xml_printf(&retval, &thread_list, &pos, &size,
+ "Name: %s", thread_detail->thread_name_str);
+
+ if (thread_detail->extra_info_str != NULL) {
+ if (thread_detail->thread_name_str != NULL)
+ xml_printf(&retval, &thread_list, &pos, &size,
+ ", ");
+ xml_printf(&retval, &thread_list, &pos, &size,
+ thread_detail->extra_info_str);
+ }
+
+ xml_printf(&retval, &thread_list, &pos, &size,
+ "</thread>\n");
+ }
+ }
+
+ xml_printf(&retval, &thread_list, &pos, &size,
+ "</threads>\n");
+
+ if (retval == ERROR_OK)
+ *thread_list_out = thread_list;
+ else
+ free(thread_list);
+
+ return retval;
+}
+
+static int gdb_get_thread_list_chunk(struct target *target, char **thread_list,
+ char **chunk, int32_t offset, uint32_t length)
+{
+ if (*thread_list == NULL) {
+ int retval = gdb_generate_thread_list(target, thread_list);
+ if (retval != ERROR_OK) {
+ LOG_ERROR("Unable to Generate Thread List");
+ return ERROR_FAIL;
+ }
+ }
+
+ size_t thread_list_length = strlen(*thread_list);
+ char transfer_type;
+
+ length = MIN(length, thread_list_length - offset);
+ if (length < (thread_list_length - offset))
+ transfer_type = 'm';
+ else
+ transfer_type = 'l';
+
+ *chunk = malloc(length + 2 + 3);
+ /* Allocating extra 3 bytes prevents false positive valgrind report
+ * of strlen(chunk) word access:
+ * Invalid read of size 4
+ * Address 0x4479934 is 44 bytes inside a block of size 45 alloc'd */
+ if (*chunk == NULL) {
+ LOG_ERROR("Unable to allocate memory");
+ return ERROR_FAIL;
+ }
+
+ (*chunk)[0] = transfer_type;
+ strncpy((*chunk) + 1, (*thread_list) + offset, length);
+ (*chunk)[1 + length] = '\0';
+
+ /* After gdb-server sends out last chunk, invalidate thread list. */
+ if (transfer_type == 'l') {
+ free(*thread_list);
+ *thread_list = NULL;
+ }
+
+ return ERROR_OK;
+}
+
+static int gdb_query_packet(struct connection *connection,
+ char const *packet, int packet_size)
+{
+ struct command_context *cmd_ctx = connection->cmd_ctx;
+ struct gdb_connection *gdb_connection = connection->priv;
+ struct target *target = get_target_from_connection(connection);
+
+ if (strncmp(packet, "qRcmd,", 6) == 0) {
+ if (packet_size > 6) {
+ char *cmd;
+ cmd = malloc((packet_size - 6) / 2 + 1);
+ size_t len = unhexify((uint8_t *)cmd, packet + 6, (packet_size - 6) / 2);
+ cmd[len] = 0;
+
+ /* We want to print all debug output to GDB connection */
+ log_add_callback(gdb_log_callback, connection);
+ target_call_timer_callbacks_now();
+ /* some commands need to know the GDB connection, make note of current
+ * GDB connection. */
+ current_gdb_connection = gdb_connection;
+ command_run_line(cmd_ctx, cmd);
+ current_gdb_connection = NULL;
+ target_call_timer_callbacks_now();
+ log_remove_callback(gdb_log_callback, connection);
+ free(cmd);
+ }
+ gdb_put_packet(connection, "OK", 2);
+ return ERROR_OK;
+ } else if (strncmp(packet, "qCRC:", 5) == 0) {
+ if (packet_size > 5) {
+ int retval;
+ char gdb_reply[10];
+ char *separator;
+ uint32_t checksum;
+ target_addr_t addr = 0;
+ uint32_t len = 0;
+
+ /* skip command character */
+ packet += 5;
+
+ addr = strtoull(packet, &separator, 16);
+
+ if (*separator != ',') {
+ LOG_ERROR("incomplete read memory packet received, dropping connection");
+ return ERROR_SERVER_REMOTE_CLOSED;
+ }
+
+ len = strtoul(separator + 1, NULL, 16);
+
+ retval = target_checksum_memory(target, addr, len, &checksum);
+
+ if (retval == ERROR_OK) {
+ snprintf(gdb_reply, 10, "C%8.8" PRIx32 "", checksum);
+ gdb_put_packet(connection, gdb_reply, 9);
+ } else {
+ retval = gdb_error(connection, retval);
+ if (retval != ERROR_OK)
+ return retval;
+ }
+
+ return ERROR_OK;
+ }
+ } else if (strncmp(packet, "qSupported", 10) == 0) {
+ /* we currently support packet size and qXfer:memory-map:read (if enabled)
+ * qXfer:features:read is supported for some targets */
+ int retval = ERROR_OK;
+ char *buffer = NULL;
+ int pos = 0;
+ int size = 0;
+ int gdb_target_desc_supported = 0;
+
+ /* we need to test that the target supports target descriptions */
+ retval = gdb_target_description_supported(target, &gdb_target_desc_supported);
+ if (retval != ERROR_OK) {
+ LOG_INFO("Failed detecting Target Description Support, disabling");
+ gdb_target_desc_supported = 0;
+ }
+
+ /* support may be disabled globally */
+ if (gdb_use_target_description == 0) {
+ if (gdb_target_desc_supported)
+ LOG_WARNING("Target Descriptions Supported, but disabled");
+ gdb_target_desc_supported = 0;
+ }
+
+ xml_printf(&retval,
+ &buffer,
+ &pos,
+ &size,
+ "PacketSize=%x;qXfer:memory-map:read%c;qXfer:features:read%c;qXfer:threads:read+;QStartNoAckMode+;vContSupported+",
+ GDB_BUFFER_SIZE,
+ ((gdb_use_memory_map == 1) && (flash_get_bank_count() > 0)) ? '+' : '-',
+ (gdb_target_desc_supported == 1) ? '+' : '-');
+
+ if (retval != ERROR_OK) {
+ gdb_send_error(connection, 01);
+ return ERROR_OK;
+ }
+
+ gdb_put_packet(connection, buffer, strlen(buffer));
+ free(buffer);
+
+ return ERROR_OK;
+ } else if ((strncmp(packet, "qXfer:memory-map:read::", 23) == 0)
+ && (flash_get_bank_count() > 0))
+ return gdb_memory_map(connection, packet, packet_size);
+ else if (strncmp(packet, "qXfer:features:read:", 20) == 0) {
+ char *xml = NULL;
+ int retval = ERROR_OK;
+
+ int offset;
+ unsigned int length;
+
+ /* skip command character */
+ packet += 20;
+
+ if (decode_xfer_read(packet, NULL, &offset, &length) < 0) {
+ gdb_send_error(connection, 01);
+ return ERROR_OK;
+ }
+
+ /* Target should prepare correct target description for annex.
+ * The first character of returned xml is 'm' or 'l'. 'm' for
+ * there are *more* chunks to transfer. 'l' for it is the *last*
+ * chunk of target description.
+ */
+ retval = gdb_get_target_description_chunk(target, &gdb_connection->target_desc,
+ &xml, offset, length);
+ if (retval != ERROR_OK) {
+ gdb_error(connection, retval);
+ return retval;
+ }
+
+ gdb_put_packet(connection, xml, strlen(xml));
+
+ free(xml);
+ return ERROR_OK;
+ } else if (strncmp(packet, "qXfer:threads:read:", 19) == 0) {
+ char *xml = NULL;
+ int retval = ERROR_OK;
+
+ int offset;
+ unsigned int length;
+
+ /* skip command character */
+ packet += 19;
+
+ if (decode_xfer_read(packet, NULL, &offset, &length) < 0) {
+ gdb_send_error(connection, 01);
+ return ERROR_OK;
+ }
+
+ /* Target should prepare correct thread list for annex.
+ * The first character of returned xml is 'm' or 'l'. 'm' for
+ * there are *more* chunks to transfer. 'l' for it is the *last*
+ * chunk of target description.
+ */
+ retval = gdb_get_thread_list_chunk(target, &gdb_connection->thread_list,
+ &xml, offset, length);
+ if (retval != ERROR_OK) {
+ gdb_error(connection, retval);
+ return retval;
+ }
+
+ gdb_put_packet(connection, xml, strlen(xml));
+
+ free(xml);
+ return ERROR_OK;
+ } else if (strncmp(packet, "QStartNoAckMode", 15) == 0) {
+ gdb_connection->noack_mode = 1;
+ gdb_put_packet(connection, "OK", 2);
+ return ERROR_OK;
+ }
+
+ gdb_put_packet(connection, "", 0);
+ return ERROR_OK;
+}
+
+static bool gdb_handle_vcont_packet(struct connection *connection, const char *packet, int packet_size)
+{
+ struct gdb_connection *gdb_connection = connection->priv;
+ struct target *target = get_target_from_connection(connection);
+ const char *parse = packet;
+ int retval;
+
+ /* query for vCont supported */
+ if (parse[0] == '?') {
+ if (target->type->step != NULL) {
+ /* gdb doesn't accept c without C and s without S */
+ gdb_put_packet(connection, "vCont;c;C;s;S", 13);
+ return true;
+ }
+ return false;
+ }
+
+ if (parse[0] == ';') {
+ ++parse;
+ --packet_size;
+ }
+
+ /* simple case, a continue packet */
+ if (parse[0] == 'c') {
+ gdb_running_type = 'c';
+ LOG_DEBUG("target %s continue", target_name(target));
+ log_add_callback(gdb_log_callback, connection);
+ retval = target_resume(target, 1, 0, 0, 0);
+ if (retval == ERROR_TARGET_NOT_HALTED)
+ LOG_INFO("target %s was not halted when resume was requested", target_name(target));
+
+ /* poll target in an attempt to make its internal state consistent */
+ if (retval != ERROR_OK) {
+ retval = target_poll(target);
+ if (retval != ERROR_OK)
+ LOG_DEBUG("error polling target %s after failed resume", target_name(target));
+ }
+
+ /*
+ * We don't report errors to gdb here, move frontend_state to
+ * TARGET_RUNNING to stay in sync with gdb's expectation of the
+ * target state
+ */
+ gdb_connection->frontend_state = TARGET_RUNNING;
+ target_call_event_callbacks(target, TARGET_EVENT_GDB_START);
+
+ return true;
+ }
+
+ /* single-step or step-over-breakpoint */
+ if (parse[0] == 's') {
+ gdb_running_type = 's';
+ bool fake_step = false;
+
+ if (strncmp(parse, "s:", 2) == 0) {
+ struct target *ct = target;
+ int current_pc = 1;
+ int64_t thread_id;
+ char *endp;
+
+ parse += 2;
+ packet_size -= 2;
+
+ thread_id = strtoll(parse, &endp, 16);
+ if (endp != NULL) {
+ packet_size -= endp - parse;
+ parse = endp;
+ }
+
+ if (target->rtos != NULL) {
+ /* FIXME: why is this necessary? rtos state should be up-to-date here already! */
+ rtos_update_threads(target);
+
+ target->rtos->gdb_target_for_threadid(connection, thread_id, &ct);
+
+ /*
+ * check if the thread to be stepped is the current rtos thread
+ * if not, we must fake the step
+ */
+ if (target->rtos->current_thread != thread_id)
+ fake_step = true;
+ }
+
+ if (parse[0] == ';') {
+ ++parse;
+ --packet_size;
+
+ if (parse[0] == 'c') {
+ parse += 1;
+
+ /* check if thread-id follows */
+ if (parse[0] == ':') {
+ int64_t tid;
+ parse += 1;
+
+ tid = strtoll(parse, &endp, 16);
+ if (tid == thread_id) {
+ /*
+ * Special case: only step a single thread (core),
+ * keep the other threads halted. Currently, only
+ * aarch64 target understands it. Other target types don't
+ * care (nobody checks the actual value of 'current')
+ * and it doesn't really matter. This deserves
+ * a symbolic constant and a formal interface documentation
+ * at a later time.
+ */
+ LOG_DEBUG("request to step current core only");
+ /* uncomment after checking that indeed other targets are safe */
+ /*current_pc = 2;*/
+ }
+ }
+ }
+ }
+
+ LOG_DEBUG("target %s single-step thread %"PRIx64, target_name(ct), thread_id);
+ log_add_callback(gdb_log_callback, connection);
+ target_call_event_callbacks(ct, TARGET_EVENT_GDB_START);
+
+ /*
+ * work around an annoying gdb behaviour: when the current thread
+ * is changed in gdb, it assumes that the target can follow and also
+ * make the thread current. This is an assumption that cannot hold
+ * for a real target running a multi-threading OS. We just fake
+ * the step to not trigger an internal error in gdb. See
+ * https://sourceware.org/bugzilla/show_bug.cgi?id=22925 for details
+ */
+ if (fake_step) {
+ int sig_reply_len;
+ char sig_reply[128];
+
+ LOG_DEBUG("fake step thread %"PRIx64, thread_id);
+
+ sig_reply_len = snprintf(sig_reply, sizeof(sig_reply),
+ "T05thread:%016"PRIx64";", thread_id);
+
+ gdb_put_packet(connection, sig_reply, sig_reply_len);
+ log_remove_callback(gdb_log_callback, connection);
+
+ return true;
+ }
+
+ /* support for gdb_sync command */
+ if (gdb_connection->sync) {
+ gdb_connection->sync = false;
+ if (ct->state == TARGET_HALTED) {
+ LOG_DEBUG("stepi ignored. GDB will now fetch the register state " \
+ "from the target.");
+ gdb_sig_halted(connection);
+ log_remove_callback(gdb_log_callback, connection);
+ } else
+ gdb_connection->frontend_state = TARGET_RUNNING;
+ return true;
+ }
+
+ retval = target_step(ct, current_pc, 0, 0);
+ if (retval == ERROR_TARGET_NOT_HALTED)
+ LOG_INFO("target %s was not halted when step was requested", target_name(ct));
+
+ /* if step was successful send a reply back to gdb */
+ if (retval == ERROR_OK) {
+ retval = target_poll(ct);
+ if (retval != ERROR_OK)
+ LOG_DEBUG("error polling target %s after successful step", target_name(ct));
+ /* send back signal information */
+ gdb_signal_reply(ct, connection);
+ /* stop forwarding log packets! */
+ log_remove_callback(gdb_log_callback, connection);
+ } else
+ gdb_connection->frontend_state = TARGET_RUNNING;
+ } else {
+ LOG_ERROR("Unknown vCont packet");
+ return false;
+ }
+ return true;
+ }
+
+ return false;
+}
+
+static char *next_hex_encoded_field(const char **str, char sep)
+{
+ size_t hexlen;
+ const char *hex = *str;
+ if (hex[0] == '\0')
+ return NULL;
+
+ const char *end = strchr(hex, sep);
+ if (end == NULL)
+ hexlen = strlen(hex);
+ else
+ hexlen = end - hex;
+ *str = hex + hexlen + 1;
+
+ if (hexlen % 2 != 0) {
+ /* Malformed hex data */
+ return NULL;
+ }
+
+ size_t count = hexlen / 2;
+ char *decoded = malloc(count + 1);
+ if (decoded == NULL)
+ return NULL;
+
+ size_t converted = unhexify((void *)decoded, hex, count);
+ if (converted != count) {
+ free(decoded);
+ return NULL;
+ }
+
+ decoded[count] = '\0';
+ return decoded;
+}
+
+/* handle extended restart packet */
+static void gdb_restart_inferior(struct connection *connection, const char *packet, int packet_size)
+{
+ struct gdb_connection *gdb_con = connection->priv;
+ struct target *target = get_target_from_connection(connection);
+
+ breakpoint_clear_target(target);
+ watchpoint_clear_target(target);
+ command_run_linef(connection->cmd_ctx, "ocd_gdb_restart %s",
+ target_name(target));
+ /* set connection as attached after reset */
+ gdb_con->attached = true;
+ /* info rtos parts */
+ gdb_thread_packet(connection, packet, packet_size);
+}
+
+static bool gdb_handle_vrun_packet(struct connection *connection, const char *packet, int packet_size)
+{
+ struct target *target = get_target_from_connection(connection);
+ const char *parse = packet;
+
+ /* Skip "vRun" */
+ parse += 4;
+
+ if (parse[0] != ';')
+ return false;
+ parse++;
+
+ /* Skip first field "filename"; don't know what to do with it. */
+ free(next_hex_encoded_field(&parse, ';'));
+
+ char *cmdline = next_hex_encoded_field(&parse, ';');
+ char *arg;
+ while (cmdline != NULL && (arg = next_hex_encoded_field(&parse, ';')) != NULL) {
+ char *new_cmdline = alloc_printf("%s %s", cmdline, arg);
+ free(cmdline);
+ free(arg);
+ cmdline = new_cmdline;
+ }
+
+ if (cmdline != NULL) {
+ if (target->semihosting != NULL) {
+ LOG_INFO("GDB set inferior command line to '%s'", cmdline);
+ free(target->semihosting->cmdline);
+ target->semihosting->cmdline = cmdline;
+ } else {
+ LOG_INFO("GDB set inferior command line to '%s' but semihosting is unavailable", cmdline);
+ free(cmdline);
+ }
+ }
+
+ gdb_restart_inferior(connection, packet, packet_size);
+ gdb_put_packet(connection, "S00", 3);
+ return true;
+}
+
+static int gdb_v_packet(struct connection *connection,
+ char const *packet, int packet_size)
+{
+ struct gdb_connection *gdb_connection = connection->priv;
+ int result;
+
+ struct target *target = get_target_from_connection(connection);
+
+ if (strncmp(packet, "vCont", 5) == 0) {
+ bool handled;
+
+ packet += 5;
+ packet_size -= 5;
+
+ handled = gdb_handle_vcont_packet(connection, packet, packet_size);
+ if (!handled)
+ gdb_put_packet(connection, "", 0);
+
+ return ERROR_OK;
+ }
+
+ if (strncmp(packet, "vRun", 4) == 0) {
+ bool handled;
+
+ handled = gdb_handle_vrun_packet(connection, packet, packet_size);
+ if (!handled)
+ gdb_put_packet(connection, "", 0);
+
+ return ERROR_OK;
+ }