You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

698 lines
21 KiB

  1. /***************************************************************************
  2. * Copyright (C) 2011 by Broadcom Corporation *
  3. * Evan Hunter - ehunter@broadcom.com *
  4. * *
  5. * This program is free software; you can redistribute it and/or modify *
  6. * it under the terms of the GNU General Public License as published by *
  7. * the Free Software Foundation; either version 2 of the License, or *
  8. * (at your option) any later version. *
  9. * *
  10. * This program is distributed in the hope that it will be useful, *
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of *
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
  13. * GNU General Public License for more details. *
  14. * *
  15. * You should have received a copy of the GNU General Public License *
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>. *
  17. ***************************************************************************/
  18. #ifdef HAVE_CONFIG_H
  19. #include "config.h"
  20. #endif
  21. #include "rtos.h"
  22. #include "target/target.h"
  23. #include "helper/log.h"
  24. #include "helper/binarybuffer.h"
  25. #include "server/gdb_server.h"
  26. /* RTOSs */
  27. extern struct rtos_type freertos_rtos;
  28. extern struct rtos_type threadx_rtos;
  29. extern struct rtos_type ecos_rtos;
  30. extern struct rtos_type linux_rtos;
  31. extern struct rtos_type chibios_rtos;
  32. extern struct rtos_type chromium_ec_rtos;
  33. extern struct rtos_type embkernel_rtos;
  34. extern struct rtos_type mqx_rtos;
  35. extern struct rtos_type ucos_iii_rtos;
  36. extern struct rtos_type nuttx_rtos;
  37. extern struct rtos_type hwthread_rtos;
  38. extern struct rtos_type riot_rtos;
  39. extern struct rtos_type zephyr_rtos;
  40. static struct rtos_type *rtos_types[] = {
  41. &threadx_rtos,
  42. &freertos_rtos,
  43. &ecos_rtos,
  44. &linux_rtos,
  45. &chibios_rtos,
  46. &chromium_ec_rtos,
  47. &embkernel_rtos,
  48. &mqx_rtos,
  49. &ucos_iii_rtos,
  50. &nuttx_rtos,
  51. &riot_rtos,
  52. &zephyr_rtos,
  53. /* keep this as last, as it always matches with rtos auto */
  54. &hwthread_rtos,
  55. NULL
  56. };
  57. static int rtos_try_next(struct target *target);
  58. int rtos_thread_packet(struct connection *connection, const char *packet, int packet_size);
  59. int rtos_smp_init(struct target *target)
  60. {
  61. if (target->rtos->type->smp_init)
  62. return target->rtos->type->smp_init(target);
  63. return ERROR_TARGET_INIT_FAILED;
  64. }
  65. static int rtos_target_for_threadid(struct connection *connection, int64_t threadid, struct target **t)
  66. {
  67. struct target *curr = get_target_from_connection(connection);
  68. if (t)
  69. *t = curr;
  70. return ERROR_OK;
  71. }
  72. static int os_alloc(struct target *target, struct rtos_type *ostype)
  73. {
  74. struct rtos *os = target->rtos = calloc(1, sizeof(struct rtos));
  75. if (!os)
  76. return JIM_ERR;
  77. os->type = ostype;
  78. os->current_threadid = -1;
  79. os->current_thread = 0;
  80. os->symbols = NULL;
  81. os->target = target;
  82. /* RTOS drivers can override the packet handler in _create(). */
  83. os->gdb_thread_packet = rtos_thread_packet;
  84. os->gdb_target_for_threadid = rtos_target_for_threadid;
  85. return JIM_OK;
  86. }
  87. static void os_free(struct target *target)
  88. {
  89. if (!target->rtos)
  90. return;
  91. free(target->rtos->symbols);
  92. free(target->rtos);
  93. target->rtos = NULL;
  94. }
  95. static int os_alloc_create(struct target *target, struct rtos_type *ostype)
  96. {
  97. int ret = os_alloc(target, ostype);
  98. if (ret == JIM_OK) {
  99. ret = target->rtos->type->create(target);
  100. if (ret != JIM_OK)
  101. os_free(target);
  102. }
  103. return ret;
  104. }
  105. int rtos_create(struct jim_getopt_info *goi, struct target *target)
  106. {
  107. int x;
  108. const char *cp;
  109. Jim_Obj *res;
  110. int e;
  111. if (!goi->isconfigure && goi->argc != 0) {
  112. Jim_WrongNumArgs(goi->interp, goi->argc, goi->argv, "NO PARAMS");
  113. return JIM_ERR;
  114. }
  115. os_free(target);
  116. e = jim_getopt_string(goi, &cp, NULL);
  117. if (e != JIM_OK)
  118. return e;
  119. if (strcmp(cp, "auto") == 0) {
  120. /* Auto detect tries to look up all symbols for each RTOS,
  121. * and runs the RTOS driver's _detect() function when GDB
  122. * finds all symbols for any RTOS. See rtos_qsymbol(). */
  123. target->rtos_auto_detect = true;
  124. /* rtos_qsymbol() will iterate over all RTOSes. Allocate
  125. * target->rtos here, and set it to the first RTOS type. */
  126. return os_alloc(target, rtos_types[0]);
  127. }
  128. for (x = 0; rtos_types[x]; x++)
  129. if (0 == strcmp(cp, rtos_types[x]->name))
  130. return os_alloc_create(target, rtos_types[x]);
  131. Jim_SetResultFormatted(goi->interp, "Unknown RTOS type %s, try one of: ", cp);
  132. res = Jim_GetResult(goi->interp);
  133. for (x = 0; rtos_types[x]; x++)
  134. Jim_AppendStrings(goi->interp, res, rtos_types[x]->name, ", ", NULL);
  135. Jim_AppendStrings(goi->interp, res, " or auto", NULL);
  136. return JIM_ERR;
  137. }
  138. void rtos_destroy(struct target *target)
  139. {
  140. os_free(target);
  141. }
  142. int gdb_thread_packet(struct connection *connection, char const *packet, int packet_size)
  143. {
  144. struct target *target = get_target_from_connection(connection);
  145. if (!target->rtos)
  146. return rtos_thread_packet(connection, packet, packet_size); /* thread not
  147. *found*/
  148. return target->rtos->gdb_thread_packet(connection, packet, packet_size);
  149. }
  150. static struct symbol_table_elem *next_symbol(struct rtos *os, char *cur_symbol, uint64_t cur_addr)
  151. {
  152. struct symbol_table_elem *s;
  153. if (!os->symbols)
  154. os->type->get_symbol_list_to_lookup(&os->symbols);
  155. if (!cur_symbol[0])
  156. return &os->symbols[0];
  157. for (s = os->symbols; s->symbol_name; s++)
  158. if (!strcmp(s->symbol_name, cur_symbol)) {
  159. s->address = cur_addr;
  160. s++;
  161. return s;
  162. }
  163. return NULL;
  164. }
  165. /* searches for 'symbol' in the lookup table for 'os' and returns TRUE,
  166. * if 'symbol' is not declared optional */
  167. static bool is_symbol_mandatory(const struct rtos *os, const char *symbol)
  168. {
  169. for (struct symbol_table_elem *s = os->symbols; s->symbol_name; ++s) {
  170. if (!strcmp(s->symbol_name, symbol))
  171. return !s->optional;
  172. }
  173. return false;
  174. }
  175. /* rtos_qsymbol() processes and replies to all qSymbol packets from GDB.
  176. *
  177. * GDB sends a qSymbol:: packet (empty address, empty name) to notify
  178. * that it can now answer qSymbol::hexcodedname queries, to look up symbols.
  179. *
  180. * If the qSymbol packet has no address that means GDB did not find the
  181. * symbol, in which case auto-detect will move on to try the next RTOS.
  182. *
  183. * rtos_qsymbol() then calls the next_symbol() helper function, which
  184. * iterates over symbol names for the current RTOS until it finds the
  185. * symbol in the received GDB packet, and then returns the next entry
  186. * in the list of symbols.
  187. *
  188. * If GDB replied about the last symbol for the RTOS and the RTOS was
  189. * specified explicitly, then no further symbol lookup is done. When
  190. * auto-detecting, the RTOS driver _detect() function must return success.
  191. *
  192. * rtos_qsymbol() returns 1 if an RTOS has been detected, or 0 otherwise.
  193. */
  194. int rtos_qsymbol(struct connection *connection, char const *packet, int packet_size)
  195. {
  196. int rtos_detected = 0;
  197. uint64_t addr = 0;
  198. size_t reply_len;
  199. char reply[GDB_BUFFER_SIZE + 1], cur_sym[GDB_BUFFER_SIZE / 2 + 1] = ""; /* Extra byte for null-termination */
  200. struct symbol_table_elem *next_sym = NULL;
  201. struct target *target = get_target_from_connection(connection);
  202. struct rtos *os = target->rtos;
  203. reply_len = sprintf(reply, "OK");
  204. if (!os)
  205. goto done;
  206. /* Decode any symbol name in the packet*/
  207. size_t len = unhexify((uint8_t *)cur_sym, strchr(packet + 8, ':') + 1, strlen(strchr(packet + 8, ':') + 1));
  208. cur_sym[len] = 0;
  209. if ((strcmp(packet, "qSymbol::") != 0) && /* GDB is not offering symbol lookup for the first time */
  210. (!sscanf(packet, "qSymbol:%" SCNx64 ":", &addr)) && /* GDB did not find an address for a symbol */
  211. is_symbol_mandatory(os, cur_sym)) { /* the symbol is mandatory for this RTOS */
  212. /* GDB could not find an address for the previous symbol */
  213. if (!target->rtos_auto_detect) {
  214. LOG_WARNING("RTOS %s not detected. (GDB could not find symbol \'%s\')", os->type->name, cur_sym);
  215. goto done;
  216. } else {
  217. /* Autodetecting RTOS - try next RTOS */
  218. if (!rtos_try_next(target)) {
  219. LOG_WARNING("No RTOS could be auto-detected!");
  220. goto done;
  221. }
  222. /* Next RTOS selected - invalidate current symbol */
  223. cur_sym[0] = '\x00';
  224. }
  225. }
  226. next_sym = next_symbol(os, cur_sym, addr);
  227. if (!next_sym->symbol_name) {
  228. /* No more symbols need looking up */
  229. if (!target->rtos_auto_detect) {
  230. rtos_detected = 1;
  231. goto done;
  232. }
  233. if (os->type->detect_rtos(target)) {
  234. LOG_INFO("Auto-detected RTOS: %s", os->type->name);
  235. rtos_detected = 1;
  236. goto done;
  237. } else {
  238. LOG_WARNING("No RTOS could be auto-detected!");
  239. goto done;
  240. }
  241. }
  242. if (8 + (strlen(next_sym->symbol_name) * 2) + 1 > sizeof(reply)) {
  243. LOG_ERROR("ERROR: RTOS symbol '%s' name is too long for GDB!", next_sym->symbol_name);
  244. goto done;
  245. }
  246. reply_len = snprintf(reply, sizeof(reply), "qSymbol:");
  247. reply_len += hexify(reply + reply_len,
  248. (const uint8_t *)next_sym->symbol_name, strlen(next_sym->symbol_name),
  249. sizeof(reply) - reply_len);
  250. done:
  251. gdb_put_packet(connection, reply, reply_len);
  252. return rtos_detected;
  253. }
  254. int rtos_thread_packet(struct connection *connection, char const *packet, int packet_size)
  255. {
  256. struct target *target = get_target_from_connection(connection);
  257. if (strncmp(packet, "qThreadExtraInfo,", 17) == 0) {
  258. if ((target->rtos) && (target->rtos->thread_details) &&
  259. (target->rtos->thread_count != 0)) {
  260. threadid_t threadid = 0;
  261. int found = -1;
  262. sscanf(packet, "qThreadExtraInfo,%" SCNx64, &threadid);
  263. if ((target->rtos) && (target->rtos->thread_details)) {
  264. int thread_num;
  265. for (thread_num = 0; thread_num < target->rtos->thread_count; thread_num++) {
  266. if (target->rtos->thread_details[thread_num].threadid == threadid) {
  267. if (target->rtos->thread_details[thread_num].exists)
  268. found = thread_num;
  269. }
  270. }
  271. }
  272. if (found == -1) {
  273. gdb_put_packet(connection, "E01", 3); /* thread not found */
  274. return ERROR_OK;
  275. }
  276. struct thread_detail *detail = &target->rtos->thread_details[found];
  277. int str_size = 0;
  278. if (detail->thread_name_str)
  279. str_size += strlen(detail->thread_name_str);
  280. if (detail->extra_info_str)
  281. str_size += strlen(detail->extra_info_str);
  282. char *tmp_str = calloc(str_size + 9, sizeof(char));
  283. char *tmp_str_ptr = tmp_str;
  284. if (detail->thread_name_str)
  285. tmp_str_ptr += sprintf(tmp_str_ptr, "Name: %s", detail->thread_name_str);
  286. if (detail->extra_info_str) {
  287. if (tmp_str_ptr != tmp_str)
  288. tmp_str_ptr += sprintf(tmp_str_ptr, ", ");
  289. tmp_str_ptr += sprintf(tmp_str_ptr, "%s", detail->extra_info_str);
  290. }
  291. assert(strlen(tmp_str) ==
  292. (size_t) (tmp_str_ptr - tmp_str));
  293. char *hex_str = malloc(strlen(tmp_str) * 2 + 1);
  294. size_t pkt_len = hexify(hex_str, (const uint8_t *)tmp_str,
  295. strlen(tmp_str), strlen(tmp_str) * 2 + 1);
  296. gdb_put_packet(connection, hex_str, pkt_len);
  297. free(hex_str);
  298. free(tmp_str);
  299. return ERROR_OK;
  300. }
  301. gdb_put_packet(connection, "", 0);
  302. return ERROR_OK;
  303. } else if (strncmp(packet, "qSymbol", 7) == 0) {
  304. if (rtos_qsymbol(connection, packet, packet_size) == 1) {
  305. if (target->rtos_auto_detect == true) {
  306. target->rtos_auto_detect = false;
  307. target->rtos->type->create(target);
  308. }
  309. target->rtos->type->update_threads(target->rtos);
  310. }
  311. return ERROR_OK;
  312. } else if (strncmp(packet, "qfThreadInfo", 12) == 0) {
  313. int i;
  314. if (target->rtos) {
  315. if (target->rtos->thread_count == 0) {
  316. gdb_put_packet(connection, "l", 1);
  317. } else {
  318. /*thread id are 16 char +1 for ',' */
  319. char *out_str = malloc(17 * target->rtos->thread_count + 1);
  320. char *tmp_str = out_str;
  321. for (i = 0; i < target->rtos->thread_count; i++) {
  322. tmp_str += sprintf(tmp_str, "%c%016" PRIx64, i == 0 ? 'm' : ',',
  323. target->rtos->thread_details[i].threadid);
  324. }
  325. gdb_put_packet(connection, out_str, strlen(out_str));
  326. free(out_str);
  327. }
  328. } else
  329. gdb_put_packet(connection, "l", 1);
  330. return ERROR_OK;
  331. } else if (strncmp(packet, "qsThreadInfo", 12) == 0) {
  332. gdb_put_packet(connection, "l", 1);
  333. return ERROR_OK;
  334. } else if (strncmp(packet, "qAttached", 9) == 0) {
  335. gdb_put_packet(connection, "1", 1);
  336. return ERROR_OK;
  337. } else if (strncmp(packet, "qOffsets", 8) == 0) {
  338. char offsets[] = "Text=0;Data=0;Bss=0";
  339. gdb_put_packet(connection, offsets, sizeof(offsets)-1);
  340. return ERROR_OK;
  341. } else if (strncmp(packet, "qCRC:", 5) == 0) {
  342. /* make sure we check this before "qC" packet below
  343. * otherwise it gets incorrectly handled */
  344. return GDB_THREAD_PACKET_NOT_CONSUMED;
  345. } else if (strncmp(packet, "qC", 2) == 0) {
  346. if (target->rtos) {
  347. char buffer[19];
  348. int size;
  349. size = snprintf(buffer, 19, "QC%016" PRIx64, target->rtos->current_thread);
  350. gdb_put_packet(connection, buffer, size);
  351. } else
  352. gdb_put_packet(connection, "QC0", 3);
  353. return ERROR_OK;
  354. } else if (packet[0] == 'T') { /* Is thread alive? */
  355. threadid_t threadid;
  356. int found = -1;
  357. sscanf(packet, "T%" SCNx64, &threadid);
  358. if ((target->rtos) && (target->rtos->thread_details)) {
  359. int thread_num;
  360. for (thread_num = 0; thread_num < target->rtos->thread_count; thread_num++) {
  361. if (target->rtos->thread_details[thread_num].threadid == threadid) {
  362. if (target->rtos->thread_details[thread_num].exists)
  363. found = thread_num;
  364. }
  365. }
  366. }
  367. if (found != -1)
  368. gdb_put_packet(connection, "OK", 2); /* thread alive */
  369. else
  370. gdb_put_packet(connection, "E01", 3); /* thread not found */
  371. return ERROR_OK;
  372. } else if (packet[0] == 'H') { /* Set current thread ( 'c' for step and continue, 'g' for
  373. * all other operations ) */
  374. if ((packet[1] == 'g') && (target->rtos)) {
  375. threadid_t threadid;
  376. sscanf(packet, "Hg%16" SCNx64, &threadid);
  377. LOG_DEBUG("RTOS: GDB requested to set current thread to 0x%" PRIx64, threadid);
  378. /* threadid of 0 indicates target should choose */
  379. if (threadid == 0)
  380. target->rtos->current_threadid = target->rtos->current_thread;
  381. else
  382. target->rtos->current_threadid = threadid;
  383. }
  384. gdb_put_packet(connection, "OK", 2);
  385. return ERROR_OK;
  386. }
  387. return GDB_THREAD_PACKET_NOT_CONSUMED;
  388. }
  389. static int rtos_put_gdb_reg_list(struct connection *connection,
  390. struct rtos_reg *reg_list, int num_regs)
  391. {
  392. size_t num_bytes = 1; /* NUL */
  393. for (int i = 0; i < num_regs; ++i)
  394. num_bytes += DIV_ROUND_UP(reg_list[i].size, 8) * 2;
  395. char *hex = malloc(num_bytes);
  396. char *hex_p = hex;
  397. for (int i = 0; i < num_regs; ++i) {
  398. size_t count = DIV_ROUND_UP(reg_list[i].size, 8);
  399. size_t n = hexify(hex_p, reg_list[i].value, count, num_bytes);
  400. hex_p += n;
  401. num_bytes -= n;
  402. }
  403. gdb_put_packet(connection, hex, strlen(hex));
  404. free(hex);
  405. return ERROR_OK;
  406. }
  407. /** Look through all registers to find this register. */
  408. int rtos_get_gdb_reg(struct connection *connection, int reg_num)
  409. {
  410. struct target *target = get_target_from_connection(connection);
  411. int64_t current_threadid = target->rtos->current_threadid;
  412. if ((target->rtos) && (current_threadid != -1) &&
  413. (current_threadid != 0) &&
  414. ((current_threadid != target->rtos->current_thread) ||
  415. (target->smp))) { /* in smp several current thread are possible */
  416. struct rtos_reg *reg_list;
  417. int num_regs;
  418. LOG_DEBUG("getting register %d for thread 0x%" PRIx64
  419. ", target->rtos->current_thread=0x%" PRIx64,
  420. reg_num,
  421. current_threadid,
  422. target->rtos->current_thread);
  423. int retval;
  424. if (target->rtos->type->get_thread_reg) {
  425. reg_list = calloc(1, sizeof(*reg_list));
  426. num_regs = 1;
  427. retval = target->rtos->type->get_thread_reg(target->rtos,
  428. current_threadid, reg_num, &reg_list[0]);
  429. if (retval != ERROR_OK) {
  430. LOG_ERROR("RTOS: failed to get register %d", reg_num);
  431. return retval;
  432. }
  433. } else {
  434. retval = target->rtos->type->get_thread_reg_list(target->rtos,
  435. current_threadid,
  436. &reg_list,
  437. &num_regs);
  438. if (retval != ERROR_OK) {
  439. LOG_ERROR("RTOS: failed to get register list");
  440. return retval;
  441. }
  442. }
  443. for (int i = 0; i < num_regs; ++i) {
  444. if (reg_list[i].number == (uint32_t)reg_num) {
  445. rtos_put_gdb_reg_list(connection, reg_list + i, 1);
  446. free(reg_list);
  447. return ERROR_OK;
  448. }
  449. }
  450. free(reg_list);
  451. }
  452. return ERROR_FAIL;
  453. }
  454. /** Return a list of general registers. */
  455. int rtos_get_gdb_reg_list(struct connection *connection)
  456. {
  457. struct target *target = get_target_from_connection(connection);
  458. int64_t current_threadid = target->rtos->current_threadid;
  459. if ((target->rtos) && (current_threadid != -1) &&
  460. (current_threadid != 0) &&
  461. ((current_threadid != target->rtos->current_thread) ||
  462. (target->smp))) { /* in smp several current thread are possible */
  463. struct rtos_reg *reg_list;
  464. int num_regs;
  465. LOG_DEBUG("RTOS: getting register list for thread 0x%" PRIx64
  466. ", target->rtos->current_thread=0x%" PRIx64 "\r\n",
  467. current_threadid,
  468. target->rtos->current_thread);
  469. int retval = target->rtos->type->get_thread_reg_list(target->rtos,
  470. current_threadid,
  471. &reg_list,
  472. &num_regs);
  473. if (retval != ERROR_OK) {
  474. LOG_ERROR("RTOS: failed to get register list");
  475. return retval;
  476. }
  477. rtos_put_gdb_reg_list(connection, reg_list, num_regs);
  478. free(reg_list);
  479. return ERROR_OK;
  480. }
  481. return ERROR_FAIL;
  482. }
  483. int rtos_set_reg(struct connection *connection, int reg_num,
  484. uint8_t *reg_value)
  485. {
  486. struct target *target = get_target_from_connection(connection);
  487. int64_t current_threadid = target->rtos->current_threadid;
  488. if ((target->rtos) &&
  489. (target->rtos->type->set_reg) &&
  490. (current_threadid != -1) &&
  491. (current_threadid != 0)) {
  492. return target->rtos->type->set_reg(target->rtos, reg_num, reg_value);
  493. }
  494. return ERROR_FAIL;
  495. }
  496. int rtos_generic_stack_read(struct target *target,
  497. const struct rtos_register_stacking *stacking,
  498. int64_t stack_ptr,
  499. struct rtos_reg **reg_list,
  500. int *num_regs)
  501. {
  502. int retval;
  503. if (stack_ptr == 0) {
  504. LOG_ERROR("Error: null stack pointer in thread");
  505. return -5;
  506. }
  507. /* Read the stack */
  508. uint8_t *stack_data = malloc(stacking->stack_registers_size);
  509. uint32_t address = stack_ptr;
  510. if (stacking->stack_growth_direction == 1)
  511. address -= stacking->stack_registers_size;
  512. retval = target_read_buffer(target, address, stacking->stack_registers_size, stack_data);
  513. if (retval != ERROR_OK) {
  514. free(stack_data);
  515. LOG_ERROR("Error reading stack frame from thread");
  516. return retval;
  517. }
  518. LOG_DEBUG("RTOS: Read stack frame at 0x%" PRIx32, address);
  519. #if 0
  520. LOG_OUTPUT("Stack Data :");
  521. for (i = 0; i < stacking->stack_registers_size; i++)
  522. LOG_OUTPUT("%02X", stack_data[i]);
  523. LOG_OUTPUT("\r\n");
  524. #endif
  525. int64_t new_stack_ptr;
  526. if (stacking->calculate_process_stack) {
  527. new_stack_ptr = stacking->calculate_process_stack(target,
  528. stack_data, stacking, stack_ptr);
  529. } else {
  530. new_stack_ptr = stack_ptr - stacking->stack_growth_direction *
  531. stacking->stack_registers_size;
  532. }
  533. *reg_list = calloc(stacking->num_output_registers, sizeof(struct rtos_reg));
  534. *num_regs = stacking->num_output_registers;
  535. for (int i = 0; i < stacking->num_output_registers; ++i) {
  536. (*reg_list)[i].number = stacking->register_offsets[i].number;
  537. (*reg_list)[i].size = stacking->register_offsets[i].width_bits;
  538. int offset = stacking->register_offsets[i].offset;
  539. if (offset == -2)
  540. buf_cpy(&new_stack_ptr, (*reg_list)[i].value, (*reg_list)[i].size);
  541. else if (offset != -1)
  542. buf_cpy(stack_data + offset, (*reg_list)[i].value, (*reg_list)[i].size);
  543. }
  544. free(stack_data);
  545. /* LOG_OUTPUT("Output register string: %s\r\n", *hex_reg_list); */
  546. return ERROR_OK;
  547. }
  548. static int rtos_try_next(struct target *target)
  549. {
  550. struct rtos *os = target->rtos;
  551. struct rtos_type **type = rtos_types;
  552. if (!os)
  553. return 0;
  554. while (*type && os->type != *type)
  555. type++;
  556. if (!*type || !*(++type))
  557. return 0;
  558. os->type = *type;
  559. free(os->symbols);
  560. os->symbols = NULL;
  561. return 1;
  562. }
  563. int rtos_update_threads(struct target *target)
  564. {
  565. if ((target->rtos) && (target->rtos->type))
  566. target->rtos->type->update_threads(target->rtos);
  567. return ERROR_OK;
  568. }
  569. void rtos_free_threadlist(struct rtos *rtos)
  570. {
  571. if (rtos->thread_details) {
  572. int j;
  573. for (j = 0; j < rtos->thread_count; j++) {
  574. struct thread_detail *current_thread = &rtos->thread_details[j];
  575. free(current_thread->thread_name_str);
  576. free(current_thread->extra_info_str);
  577. }
  578. free(rtos->thread_details);
  579. rtos->thread_details = NULL;
  580. rtos->thread_count = 0;
  581. rtos->current_threadid = -1;
  582. rtos->current_thread = 0;
  583. }
  584. }
  585. int rtos_read_buffer(struct target *target, target_addr_t address,
  586. uint32_t size, uint8_t *buffer)
  587. {
  588. if (target->rtos->type->read_buffer)
  589. return target->rtos->type->read_buffer(target->rtos, address, size, buffer);
  590. return ERROR_NOT_IMPLEMENTED;
  591. }
  592. int rtos_write_buffer(struct target *target, target_addr_t address,
  593. uint32_t size, const uint8_t *buffer)
  594. {
  595. if (target->rtos->type->write_buffer)
  596. return target->rtos->type->write_buffer(target->rtos, address, size, buffer);
  597. return ERROR_NOT_IMPLEMENTED;
  598. }