X-Git-Url: https://review.openocd.org/gitweb?p=openocd.git;a=blobdiff_plain;f=src%2Frtos%2Frtos.c;h=e9a17ea214750effb4432fa7695cbddf98b6f9b7;hp=28d0a9e50b0d5c3230b3377120a9e9468a0b4f12;hb=d0507207ab91153622a053795336cce232cb3be9;hpb=08d4411b59dd8bd0e7d8009003b71d23acbf6eee diff --git a/src/rtos/rtos.c b/src/rtos/rtos.c index 28d0a9e50b..e9a17ea214 100644 --- a/src/rtos/rtos.c +++ b/src/rtos/rtos.c @@ -189,7 +189,7 @@ static char *next_symbol(struct rtos *os, char *cur_symbol, uint64_t cur_addr) int rtos_qsymbol(struct connection *connection, char *packet, int packet_size) { int rtos_detected = 0; - uint64_t addr; + uint64_t addr = 0; size_t reply_len; char reply[GDB_BUFFER_SIZE], cur_sym[GDB_BUFFER_SIZE / 2] = "", *next_sym; struct target *target = get_target_from_connection(connection); @@ -212,8 +212,10 @@ int rtos_qsymbol(struct connection *connection, char *packet, int packet_size) goto done; } else { /* Autodetecting RTOS - try next RTOS */ - if (!rtos_try_next(target)) + if (!rtos_try_next(target)) { + LOG_WARNING("No RTOS could be auto-detected!"); goto done; + } /* Next RTOS selected - invalidate current symbol */ cur_sym[0] = '\x00'; @@ -327,21 +329,22 @@ int rtos_thread_packet(struct connection *connection, char *packet, int packet_s return ERROR_OK; } else if (strncmp(packet, "qfThreadInfo", 12) == 0) { int i; - if ((target->rtos != NULL) && (target->rtos->thread_count != 0)) { - - char *out_str = (char *) malloc(17 * target->rtos->thread_count + 5); - char *tmp_str = out_str; - tmp_str += sprintf(tmp_str, "m"); - for (i = 0; i < target->rtos->thread_count; i++) { - if (i != 0) - tmp_str += sprintf(tmp_str, ","); - tmp_str += sprintf(tmp_str, "%016" PRIx64, - target->rtos->thread_details[i].threadid); + if (target->rtos != NULL) { + if (target->rtos->thread_count == 0) { + gdb_put_packet(connection, "l", 1); + } else { + /*thread id are 16 char +1 for ',' */ + char *out_str = (char *) malloc(17 * target->rtos->thread_count + 1); + char *tmp_str = out_str; + for (i = 0; i < target->rtos->thread_count; i++) { + tmp_str += sprintf(tmp_str, "%c%016" PRIx64, i == 0 ? 'm' : ',', + target->rtos->thread_details[i].threadid); + } + gdb_put_packet(connection, out_str, strlen(out_str)); + free(out_str); } - tmp_str[0] = 0; - gdb_put_packet(connection, out_str, strlen(out_str)); } else - gdb_put_packet(connection, "", 0); + gdb_put_packet(connection, "l", 1); return ERROR_OK; } else if (strncmp(packet, "qsThreadInfo", 12) == 0) { @@ -441,6 +444,7 @@ int rtos_generic_stack_read(struct target *target, address -= stacking->stack_registers_size; retval = target_read_buffer(target, address, stacking->stack_registers_size, stack_data); if (retval != ERROR_OK) { + free(stack_data); LOG_ERROR("Error reading stack frame from thread"); return retval; } @@ -475,6 +479,7 @@ int rtos_generic_stack_read(struct target *target, stack_data[stacking->register_offsets[i].offset + j]); } } + free(stack_data); /* LOG_OUTPUT("Output register string: %s\r\n", *hex_reg_list); */ return ERROR_OK; } @@ -508,3 +513,20 @@ int rtos_update_threads(struct target *target) target->rtos->type->update_threads(target->rtos); return ERROR_OK; } + +void rtos_free_threadlist(struct rtos *rtos) +{ + if (rtos->thread_details) { + int j; + + for (j = 0; j < rtos->thread_count; j++) { + struct thread_detail *current_thread = &rtos->thread_details[j]; + free(current_thread->display_str); + free(current_thread->thread_name_str); + free(current_thread->extra_info_str); + } + free(rtos->thread_details); + rtos->thread_details = NULL; + rtos->thread_count = 0; + } +}