OpenOCD
rtos.c
Go to the documentation of this file.
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 
3 /***************************************************************************
4  * Copyright (C) 2011 by Broadcom Corporation *
5  * Evan Hunter - ehunter@broadcom.com *
6  ***************************************************************************/
7 
8 #ifdef HAVE_CONFIG_H
9 #include "config.h"
10 #endif
11 
12 #include "rtos.h"
13 #include "target/target.h"
14 #include "helper/log.h"
15 #include "helper/binarybuffer.h"
16 #include "helper/types.h"
17 #include "server/gdb_server.h"
18 
19 static const struct rtos_type *rtos_types[] = {
20  // Keep in alphabetic order this list of rtos, except hwthread
21  &chibios_rtos,
23  &ecos_rtos,
26  &linux_rtos,
27  &mqx_rtos,
28  &nuttx_rtos,
29  &riot_rtos,
31  &threadx_rtos,
33  &zephyr_rtos,
34 
35  // keep this as last, as it always matches with rtos auto
37 };
38 
40 {
41  if (target->rtos->type->smp_init)
42  return target->rtos->type->smp_init(target);
44 }
45 
46 static int rtos_target_for_threadid(struct connection *connection, int64_t threadid, struct target **t)
47 {
49  if (t)
50  *t = curr;
51 
52  return ERROR_OK;
53 }
54 
55 static int os_alloc(struct target *target, const struct rtos_type *ostype)
56 {
57  struct rtos *os = target->rtos = calloc(1, sizeof(struct rtos));
58 
59  if (!os)
60  return ERROR_FAIL;
61 
62  os->type = ostype;
63  os->current_threadid = -1;
64  os->current_thread = 0;
65  os->symbols = NULL;
66  os->target = target;
67 
68  /* RTOS drivers can override the packet handler in _create(). */
71 
72  return ERROR_OK;
73 }
74 
75 static void os_free(struct target *target)
76 {
77  if (!target->rtos)
78  return;
79 
80  free(target->rtos->symbols);
82  free(target->rtos);
83  target->rtos = NULL;
84 }
85 
86 static int os_alloc_create(struct target *target, const struct rtos_type *ostype)
87 {
88  int ret = os_alloc(target, ostype);
89  if (ret != ERROR_OK)
90  return ret;
91 
92  ret = target->rtos->type->create(target);
93  if (ret != ERROR_OK)
94  os_free(target);
95 
96  return ret;
97 }
98 
100  const char *rtos_name)
101 {
102  os_free(target);
103  target->rtos_auto_detect = false;
104 
105  if (strcmp(rtos_name, "none") == 0)
106  return ERROR_OK;
107 
108  if (strcmp(rtos_name, "auto") == 0) {
109  /* Auto detect tries to look up all symbols for each RTOS,
110  * and runs the RTOS driver's _detect() function when GDB
111  * finds all symbols for any RTOS. See rtos_qsymbol(). */
112  target->rtos_auto_detect = true;
113 
114  /* rtos_qsymbol() will iterate over all RTOSes. Allocate
115  * target->rtos here, and set it to the first RTOS type. */
116  return os_alloc(target, rtos_types[0]);
117  }
118 
119  for (size_t x = 0; x < ARRAY_SIZE(rtos_types); x++)
120  if (strcmp(rtos_name, rtos_types[x]->name) == 0)
121  return os_alloc_create(target, rtos_types[x]);
122 
123  char *all = NULL;
124  for (size_t x = 0; x < ARRAY_SIZE(rtos_types); x++) {
125  char *prev = all;
126  if (all)
127  all = alloc_printf("%s, %s", all, rtos_types[x]->name);
128  else
129  all = alloc_printf("%s", rtos_types[x]->name);
130  free(prev);
131  if (!all) {
132  LOG_ERROR("Out of memory");
133  return ERROR_FAIL;
134  }
135  }
136 
137  command_print(cmd, "Unknown RTOS type %s, try one of: %s, auto or none",
138  rtos_name, all);
139  free(all);
140 
142 }
143 
145 {
146  os_free(target);
147 }
148 
149 int gdb_thread_packet(struct connection *connection, char const *packet, int packet_size)
150 {
152  if (!target->rtos)
153  return rtos_thread_packet(connection, packet, packet_size); /* thread not
154  *found*/
155  return target->rtos->gdb_thread_packet(connection, packet, packet_size);
156 }
157 
158 static bool rtos_try_next(struct target *target)
159 {
160  struct rtos *os = target->rtos;
161 
162  if (!os)
163  return false;
164 
165  for (size_t x = 0; x < ARRAY_SIZE(rtos_types) - 1; x++) {
166  if (os->type == rtos_types[x]) {
167  // Use next RTOS in the list
168  os->type = rtos_types[x + 1];
169 
170  free(os->symbols);
171  os->symbols = NULL;
172 
173  return true;
174  }
175  }
176 
177  // No next RTOS to try
178  return false;
179 }
180 
181 static struct symbol_table_elem *find_symbol(const struct rtos *os, const char *symbol)
182 {
183  struct symbol_table_elem *s;
184 
185  for (s = os->symbols; s->symbol_name; s++)
186  if (!strcmp(s->symbol_name, symbol))
187  return s;
188 
189  return NULL;
190 }
191 
192 static struct symbol_table_elem *next_symbol(struct rtos *os, char *cur_symbol, uint64_t cur_addr)
193 {
194  if (!os->symbols)
196 
197  if (!cur_symbol[0])
198  return &os->symbols[0];
199 
200  struct symbol_table_elem *s = find_symbol(os, cur_symbol);
201  if (!s)
202  return NULL;
203 
204  s->address = cur_addr;
205  s++;
206  return s;
207 }
208 
209 /* rtos_qsymbol() processes and replies to all qSymbol packets from GDB.
210  *
211  * GDB sends a qSymbol:: packet (empty address, empty name) to notify
212  * that it can now answer qSymbol::hexcodedname queries, to look up symbols.
213  *
214  * If the qSymbol packet has no address that means GDB did not find the
215  * symbol, in which case auto-detect will move on to try the next RTOS.
216  *
217  * rtos_qsymbol() then calls the next_symbol() helper function, which
218  * iterates over symbol names for the current RTOS until it finds the
219  * symbol in the received GDB packet, and then returns the next entry
220  * in the list of symbols.
221  *
222  * If GDB replied about the last symbol for the RTOS and the RTOS was
223  * specified explicitly, then no further symbol lookup is done. When
224  * auto-detecting, the RTOS driver _detect() function must return success.
225  *
226  * The symbol is tried twice to handle the -flto case with gcc. The first
227  * attempt uses the symbol as-is, and the second attempt tries the symbol
228  * with ".lto_priv.0" appended to it. We only consider the first static
229  * symbol here from the -flto case. (Each subsequent static symbol with
230  * the same name is exported as .lto_priv.1, .lto_priv.2, etc.)
231  *
232  * rtos_qsymbol() returns 1 if an RTOS has been detected, or 0 otherwise.
233  */
234 int rtos_qsymbol(struct connection *connection, char const *packet, int packet_size)
235 {
236  int rtos_detected = 0;
237  uint64_t addr = 0;
238  size_t reply_len;
239  char reply[GDB_BUFFER_SIZE + 1], cur_sym[GDB_BUFFER_SIZE / 2 + 1] = ""; /* Extra byte for null-termination */
240  struct symbol_table_elem *next_sym = NULL;
242  struct rtos *os = target->rtos;
243 
244  reply_len = sprintf(reply, "OK");
245 
246  if (!os)
247  goto done;
248 
249  /* Decode any symbol name in the packet*/
250  size_t len = unhexify((uint8_t *)cur_sym, strchr(packet + 8, ':') + 1, strlen(strchr(packet + 8, ':') + 1));
251  cur_sym[len] = 0;
252 
253  const char no_suffix[] = "";
254  const char lto_suffix[] = ".lto_priv.0";
255  const size_t lto_suffix_len = strlen(lto_suffix);
256 
257  const char *cur_suffix;
258  const char *next_suffix;
259 
260  /* Detect what suffix was used during the previous symbol lookup attempt, and
261  * speculatively determine the next suffix (only used for the unknown address case) */
262  if (len > lto_suffix_len && !strcmp(cur_sym + len - lto_suffix_len, lto_suffix)) {
263  /* Trim the suffix from cur_sym for comparison purposes below */
264  cur_sym[len - lto_suffix_len] = '\0';
265  cur_suffix = lto_suffix;
266  next_suffix = NULL;
267  } else {
268  cur_suffix = no_suffix;
269  next_suffix = lto_suffix;
270  }
271 
272  if ((strcmp(packet, "qSymbol::") != 0) && /* GDB is not offering symbol lookup for the first time */
273  (!sscanf(packet, "qSymbol:%" SCNx64 ":", &addr))) { /* GDB did not find an address for a symbol */
274 
275  /* GDB could not find an address for the previous symbol */
276  struct symbol_table_elem *sym = find_symbol(os, cur_sym);
277 
278  if (next_suffix) {
279  next_sym = sym;
280  } else if (sym && !sym->optional) { /* the symbol is mandatory for this RTOS */
281  if (!target->rtos_auto_detect) {
282  LOG_WARNING("RTOS %s not detected. (GDB could not find symbol \'%s\')", os->type->name, cur_sym);
283  goto done;
284  } else {
285  /* Autodetecting RTOS - try next RTOS */
286  if (!rtos_try_next(target)) {
287  LOG_WARNING("No RTOS could be auto-detected!");
288  goto done;
289  }
290 
291  /* Next RTOS selected - invalidate current symbol */
292  cur_sym[0] = '\x00';
293  }
294  }
295  }
296 
297  LOG_DEBUG("RTOS: Address of symbol '%s%s' is 0x%" PRIx64, cur_sym, cur_suffix, addr);
298 
299  if (!next_sym) {
300  next_sym = next_symbol(os, cur_sym, addr);
301  next_suffix = no_suffix;
302  }
303 
304  /* Should never happen unless the debugger misbehaves */
305  if (!next_sym) {
306  LOG_WARNING("RTOS: Debugger sent us qSymbol with '%s%s' that we did not ask for", cur_sym, cur_suffix);
307  goto done;
308  }
309 
310  if (!next_sym->symbol_name) {
311  /* No more symbols need looking up */
312 
313  if (!target->rtos_auto_detect) {
314  rtos_detected = 1;
315  goto done;
316  }
317 
318  if (os->type->detect_rtos(target)) {
319  LOG_INFO("Auto-detected RTOS: %s", os->type->name);
320  rtos_detected = 1;
321  goto done;
322  } else {
323  LOG_WARNING("No RTOS could be auto-detected!");
324  goto done;
325  }
326  }
327 
328  assert(next_suffix);
329 
330  reply_len = 8; /* snprintf(..., "qSymbol:") */
331  reply_len += 2 * strlen(next_sym->symbol_name); /* hexify(..., next_sym->symbol_name, ...) */
332  reply_len += 2 * strlen(next_suffix); /* hexify(..., next_suffix, ...) */
333  reply_len += 1; /* Terminating NUL */
334  if (reply_len > sizeof(reply)) {
335  LOG_ERROR("RTOS symbol '%s%s' name is too long for GDB", next_sym->symbol_name, next_suffix);
336  goto done;
337  }
338 
339  LOG_DEBUG("RTOS: Requesting symbol lookup of '%s%s' from the debugger", next_sym->symbol_name, next_suffix);
340 
341  reply_len = snprintf(reply, sizeof(reply), "qSymbol:");
342  reply_len += hexify(reply + reply_len,
343  (const uint8_t *)next_sym->symbol_name, strlen(next_sym->symbol_name),
344  sizeof(reply) - reply_len);
345  reply_len += hexify(reply + reply_len,
346  (const uint8_t *)next_suffix, strlen(next_suffix),
347  sizeof(reply) - reply_len);
348 
349 done:
350  gdb_put_packet(connection, reply, reply_len);
351  return rtos_detected;
352 }
353 
354 int rtos_thread_packet(struct connection *connection, char const *packet, int packet_size)
355 {
357 
358  if (strncmp(packet, "qThreadExtraInfo,", 17) == 0) {
359  if ((target->rtos) && (target->rtos->thread_details) &&
360  (target->rtos->thread_count != 0)) {
361  threadid_t threadid = 0;
362  int found = -1;
363  sscanf(packet, "qThreadExtraInfo,%" SCNx64, &threadid);
364 
365  if ((target->rtos) && (target->rtos->thread_details)) {
366  int thread_num;
367  for (thread_num = 0; thread_num < target->rtos->thread_count; thread_num++) {
368  if (target->rtos->thread_details[thread_num].threadid == threadid) {
369  if (target->rtos->thread_details[thread_num].exists)
370  found = thread_num;
371  }
372  }
373  }
374  if (found == -1) {
375  gdb_put_packet(connection, "E01", 3); /* thread not found */
376  return ERROR_OK;
377  }
378 
379  struct thread_detail *detail = &target->rtos->thread_details[found];
380 
381  int str_size = 0;
382  if (detail->thread_name_str)
383  str_size += strlen(detail->thread_name_str);
384  if (detail->extra_info_str)
385  str_size += strlen(detail->extra_info_str);
386 
387  char *tmp_str = calloc(str_size + 9, sizeof(char));
388  if (!tmp_str) {
389  LOG_ERROR("Out of memory");
390  return ERROR_FAIL;
391  }
392  char *tmp_str_ptr = tmp_str;
393 
394  if (detail->thread_name_str)
395  tmp_str_ptr += sprintf(tmp_str_ptr, "Name: %s", detail->thread_name_str);
396  if (detail->extra_info_str) {
397  if (tmp_str_ptr != tmp_str)
398  tmp_str_ptr += sprintf(tmp_str_ptr, ", ");
399  tmp_str_ptr += sprintf(tmp_str_ptr, "%s", detail->extra_info_str);
400  }
401 
402  assert(strlen(tmp_str) ==
403  (size_t) (tmp_str_ptr - tmp_str));
404 
405  char *hex_str = malloc(strlen(tmp_str) * 2 + 1);
406  size_t pkt_len = hexify(hex_str, (const uint8_t *)tmp_str,
407  strlen(tmp_str), strlen(tmp_str) * 2 + 1);
408 
409  gdb_put_packet(connection, hex_str, pkt_len);
410  free(hex_str);
411  free(tmp_str);
412  return ERROR_OK;
413 
414  }
415  gdb_put_packet(connection, "", 0);
416  return ERROR_OK;
417  } else if (strncmp(packet, "qSymbol", 7) == 0) {
418  if (rtos_qsymbol(connection, packet, packet_size) == 1) {
419  if (target->rtos_auto_detect) {
420  target->rtos_auto_detect = false;
422  }
424  }
425  return ERROR_OK;
426  } else if (strncmp(packet, "qfThreadInfo", 12) == 0) {
427  int i;
428  if (target->rtos) {
429  if (target->rtos->thread_count == 0) {
430  gdb_put_packet(connection, "l", 1);
431  } else {
432  /*thread id are 16 char +1 for ',' */
433  char *out_str = malloc(17 * target->rtos->thread_count + 1);
434  char *tmp_str = out_str;
435  for (i = 0; i < target->rtos->thread_count; i++) {
436  tmp_str += sprintf(tmp_str, "%c%016" PRIx64, i == 0 ? 'm' : ',',
438  }
439  gdb_put_packet(connection, out_str, strlen(out_str));
440  free(out_str);
441  }
442  } else
443  gdb_put_packet(connection, "l", 1);
444 
445  return ERROR_OK;
446  } else if (strncmp(packet, "qsThreadInfo", 12) == 0) {
447  gdb_put_packet(connection, "l", 1);
448  return ERROR_OK;
449  } else if (strncmp(packet, "qAttached", 9) == 0) {
450  gdb_put_packet(connection, "1", 1);
451  return ERROR_OK;
452  } else if (strncmp(packet, "qOffsets", 8) == 0) {
453  char offsets[] = "Text=0;Data=0;Bss=0";
454  gdb_put_packet(connection, offsets, sizeof(offsets)-1);
455  return ERROR_OK;
456  } else if (strncmp(packet, "qCRC:", 5) == 0) {
457  /* make sure we check this before "qC" packet below
458  * otherwise it gets incorrectly handled */
460  } else if (strncmp(packet, "qC", 2) == 0) {
461  if (target->rtos) {
462  char buffer[19];
463  int size;
464  size = snprintf(buffer, 19, "QC%016" PRIx64, target->rtos->current_thread);
466  } else
467  gdb_put_packet(connection, "QC0", 3);
468  return ERROR_OK;
469  } else if (packet[0] == 'T') { /* Is thread alive? */
471  int found = -1;
472  sscanf(packet, "T%" SCNx64, &threadid);
473  if ((target->rtos) && (target->rtos->thread_details)) {
474  int thread_num;
475  for (thread_num = 0; thread_num < target->rtos->thread_count; thread_num++) {
476  if (target->rtos->thread_details[thread_num].threadid == threadid) {
477  if (target->rtos->thread_details[thread_num].exists)
478  found = thread_num;
479  }
480  }
481  }
482  if (found != -1)
483  gdb_put_packet(connection, "OK", 2); /* thread alive */
484  else
485  gdb_put_packet(connection, "E01", 3); /* thread not found */
486  return ERROR_OK;
487  } else if (packet[0] == 'H') { /* Set current thread ( 'c' for step and continue, 'g' for
488  * all other operations ) */
489  if ((packet[1] == 'g') && (target->rtos)) {
491  sscanf(packet, "Hg%16" SCNx64, &threadid);
492  LOG_DEBUG("RTOS: GDB requested to set current thread to 0x%" PRIx64, threadid);
493  /* threadid of 0 indicates target should choose */
494  if (threadid == 0)
496  else
498  }
499  gdb_put_packet(connection, "OK", 2);
500  return ERROR_OK;
501  }
502 
504 }
505 
507  struct rtos_reg *reg_list, int num_regs)
508 {
509  size_t num_bytes = 1; /* NUL */
510  for (int i = 0; i < num_regs; ++i)
511  num_bytes += DIV_ROUND_UP(reg_list[i].size, 8) * 2;
512 
513  char *hex = malloc(num_bytes);
514  char *hex_p = hex;
515 
516  for (int i = 0; i < num_regs; ++i) {
517  size_t count = DIV_ROUND_UP(reg_list[i].size, 8);
518  size_t n = hexify(hex_p, reg_list[i].value, count, num_bytes);
519  hex_p += n;
520  num_bytes -= n;
521  }
522 
523  gdb_put_packet(connection, hex, strlen(hex));
524  free(hex);
525 
526  return ERROR_OK;
527 }
528 
530 int rtos_get_gdb_reg(struct connection *connection, int reg_num)
531 {
533  int64_t current_threadid = target->rtos->current_threadid;
534  if ((target->rtos) && (current_threadid != -1) &&
535  (current_threadid != 0) &&
536  ((current_threadid != target->rtos->current_thread) ||
537  (target->smp))) { /* in smp several current thread are possible */
538  struct rtos_reg *reg_list;
539  int num_regs;
540 
541  LOG_DEBUG("getting register %d for thread 0x%" PRIx64
542  ", target->rtos->current_thread=0x%" PRIx64,
543  reg_num,
544  current_threadid,
546 
547  int retval;
548  if (target->rtos->type->get_thread_reg) {
549  reg_list = calloc(1, sizeof(*reg_list));
550  num_regs = 1;
551  retval = target->rtos->type->get_thread_reg(target->rtos,
552  current_threadid, reg_num, &reg_list[0]);
553  if (retval != ERROR_OK) {
554  LOG_ERROR("RTOS: failed to get register %d", reg_num);
555  return retval;
556  }
557  } else {
559  current_threadid,
560  &reg_list,
561  &num_regs);
562  if (retval != ERROR_OK) {
563  LOG_ERROR("RTOS: failed to get register list");
564  return retval;
565  }
566  }
567 
568  for (int i = 0; i < num_regs; ++i) {
569  if (reg_list[i].number == (uint32_t)reg_num) {
570  rtos_put_gdb_reg_list(connection, reg_list + i, 1);
571  free(reg_list);
572  return ERROR_OK;
573  }
574  }
575 
576  free(reg_list);
577  }
578  return ERROR_FAIL;
579 }
580 
583 {
585  int64_t current_threadid = target->rtos->current_threadid;
586  if ((target->rtos) && (current_threadid != -1) &&
587  (current_threadid != 0) &&
588  ((current_threadid != target->rtos->current_thread) ||
589  (target->smp))) { /* in smp several current thread are possible */
590  struct rtos_reg *reg_list;
591  int num_regs;
592 
593  LOG_DEBUG("RTOS: getting register list for thread 0x%" PRIx64
594  ", target->rtos->current_thread=0x%" PRIx64 "\r\n",
595  current_threadid,
597 
598  int retval = target->rtos->type->get_thread_reg_list(target->rtos,
599  current_threadid,
600  &reg_list,
601  &num_regs);
602  if (retval != ERROR_OK) {
603  LOG_ERROR("RTOS: failed to get register list");
604  return retval;
605  }
606 
607  rtos_put_gdb_reg_list(connection, reg_list, num_regs);
608  free(reg_list);
609 
610  return ERROR_OK;
611  }
612  return ERROR_FAIL;
613 }
614 
615 int rtos_set_reg(struct connection *connection, int reg_num,
616  uint8_t *reg_value)
617 {
619  int64_t current_threadid = target->rtos->current_threadid;
620  if ((target->rtos) &&
621  (target->rtos->type->set_reg) &&
622  (current_threadid != -1) &&
623  (current_threadid != 0)) {
624  return target->rtos->type->set_reg(target->rtos, reg_num, reg_value);
625  }
626  return ERROR_FAIL;
627 }
628 
630  const struct rtos_register_stacking *stacking,
631  int64_t stack_ptr,
632  struct rtos_reg **reg_list,
633  int *num_regs)
634 {
635  int retval;
636 
637  if (stack_ptr == 0) {
638  LOG_ERROR("null stack pointer in thread");
639  return -5;
640  }
641  /* Read the stack */
642  uint8_t *stack_data = malloc(stacking->stack_registers_size);
643  uint32_t address = stack_ptr;
644 
645  if (stacking->stack_growth_direction == 1)
646  address -= stacking->stack_registers_size;
647  if (stacking->read_stack)
648  retval = stacking->read_stack(target, address, stacking, stack_data);
649  else
650  retval = target_read_buffer(target, address, stacking->stack_registers_size, stack_data);
651  if (retval != ERROR_OK) {
652  free(stack_data);
653  LOG_ERROR("Error reading stack frame from thread");
654  return retval;
655  }
656  LOG_DEBUG("RTOS: Read stack frame at 0x%" PRIx32, address);
657 
658 #if 0
659  LOG_OUTPUT("Stack Data :");
660  for (i = 0; i < stacking->stack_registers_size; i++)
661  LOG_OUTPUT("%02X", stack_data[i]);
662  LOG_OUTPUT("\r\n");
663 #endif
664 
665  target_addr_t new_stack_ptr;
666  if (stacking->calculate_process_stack) {
667  new_stack_ptr = stacking->calculate_process_stack(target,
668  stack_data, stacking, stack_ptr);
669  } else {
670  new_stack_ptr = stack_ptr - stacking->stack_growth_direction *
671  stacking->stack_registers_size;
672  }
673 
674  *reg_list = calloc(stacking->num_output_registers, sizeof(struct rtos_reg));
675  *num_regs = stacking->num_output_registers;
676 
677  for (int i = 0; i < stacking->num_output_registers; ++i) {
678  (*reg_list)[i].number = stacking->register_offsets[i].number;
679  (*reg_list)[i].size = stacking->register_offsets[i].width_bits;
680 
681  int offset = stacking->register_offsets[i].offset;
682  if (offset == -2)
683  buf_cpy(&new_stack_ptr, (*reg_list)[i].value, (*reg_list)[i].size);
684  else if (offset != -1)
685  buf_cpy(stack_data + offset, (*reg_list)[i].value, (*reg_list)[i].size);
686  }
687 
688  free(stack_data);
689 /* LOG_OUTPUT("Output register string: %s\r\n", *hex_reg_list); */
690  return ERROR_OK;
691 }
692 
694 {
695  if ((target->rtos) && (target->rtos->type))
697  return ERROR_OK;
698 }
699 
701 {
702  if (rtos->thread_details) {
703  int j;
704 
705  for (j = 0; j < rtos->thread_count; j++) {
707  free(current_thread->thread_name_str);
708  free(current_thread->extra_info_str);
709  }
710  free(rtos->thread_details);
712  rtos->thread_count = 0;
713  rtos->current_threadid = -1;
714  rtos->current_thread = 0;
715  }
716 }
717 
719  uint32_t size, uint8_t *buffer)
720 {
721  if (target->rtos->type->read_buffer)
723  return ERROR_NOT_IMPLEMENTED;
724 }
725 
727  uint32_t size, const uint8_t *buffer)
728 {
729  if (target->rtos->type->write_buffer)
731  return ERROR_NOT_IMPLEMENTED;
732 }
const char * name
Definition: armv4_5.c:76
void * buf_cpy(const void *from, void *_to, unsigned int size)
Copies size bits out of from and into to.
Definition: binarybuffer.c:43
size_t hexify(char *hex, const uint8_t *bin, size_t count, size_t length)
Convert binary data into a string of hexadecimal pairs.
Definition: binarybuffer.c:380
size_t unhexify(uint8_t *bin, const char *hex, size_t count)
Convert a string of hexadecimal pairs into its binary representation.
Definition: binarybuffer.c:342
Support functions to access arbitrary bits in a byte array.
const struct rtos_type chibios_rtos
Definition: chibios.c:99
const struct rtos_type chromium_ec_rtos
Definition: chromium-ec.c:383
void command_print(struct command_invocation *cmd, const char *format,...)
Definition: command.c:375
#define ERROR_COMMAND_ARGUMENT_INVALID
Definition: command.h:402
uint64_t buffer
Pointer to data buffer to send over SPI.
Definition: dw-spi-helper.h:0
uint32_t size
Size of dw_spi_transaction::buffer.
Definition: dw-spi-helper.h:4
uint32_t address
Starting address. Sector aligned.
Definition: dw-spi-helper.h:0
const struct rtos_type ecos_rtos
Definition: ecos.c:455
const struct rtos_type embkernel_rtos
Definition: embkernel.c:29
enum esirisc_reg_num number
Definition: esirisc.c:87
const struct rtos_type freertos_rtos
Definition: freertos.c:82
int gdb_put_packet(struct connection *connection, const char *buffer, int len)
Definition: gdb_server.c:554
#define GDB_BUFFER_SIZE
Definition: gdb_server.h:25
static struct target * get_target_from_connection(struct connection *connection)
Definition: gdb_server.h:35
const struct rtos_type hwthread_rtos
Definition: hwthread.c:50
const struct rtos_type linux_rtos
Definition: linux.c:250
char * alloc_printf(const char *format,...)
Definition: log.c:375
#define ERROR_NOT_IMPLEMENTED
Definition: log.h:178
#define LOG_OUTPUT(expr ...)
Definition: log.h:142
#define LOG_WARNING(expr ...)
Definition: log.h:130
#define ERROR_FAIL
Definition: log.h:174
#define LOG_ERROR(expr ...)
Definition: log.h:133
#define LOG_INFO(expr ...)
Definition: log.h:127
#define LOG_DEBUG(expr ...)
Definition: log.h:110
#define ERROR_OK
Definition: log.h:168
const struct rtos_type mqx_rtos
Definition: mqx.c:499
const struct rtos_type nuttx_rtos
Definition: nuttx.c:396
const struct rtos_type riot_rtos
Definition: riot.c:97
const struct rtos_type rtkernel_rtos
Definition: rtkernel.c:375
static int rtos_target_for_threadid(struct connection *connection, int64_t threadid, struct target **t)
Definition: rtos.c:46
int rtos_generic_stack_read(struct target *target, const struct rtos_register_stacking *stacking, int64_t stack_ptr, struct rtos_reg **reg_list, int *num_regs)
Definition: rtos.c:629
static const struct rtos_type * rtos_types[]
Definition: rtos.c:19
static int os_alloc_create(struct target *target, const struct rtos_type *ostype)
Definition: rtos.c:86
int rtos_thread_packet(struct connection *connection, char const *packet, int packet_size)
Definition: rtos.c:354
int gdb_thread_packet(struct connection *connection, char const *packet, int packet_size)
Definition: rtos.c:149
static struct symbol_table_elem * find_symbol(const struct rtos *os, const char *symbol)
Definition: rtos.c:181
static int os_alloc(struct target *target, const struct rtos_type *ostype)
Definition: rtos.c:55
int rtos_create(struct command_invocation *cmd, struct target *target, const char *rtos_name)
Definition: rtos.c:99
static void os_free(struct target *target)
Definition: rtos.c:75
int rtos_set_reg(struct connection *connection, int reg_num, uint8_t *reg_value)
Definition: rtos.c:615
int rtos_get_gdb_reg_list(struct connection *connection)
Return a list of general registers.
Definition: rtos.c:582
void rtos_destroy(struct target *target)
Definition: rtos.c:144
static int rtos_put_gdb_reg_list(struct connection *connection, struct rtos_reg *reg_list, int num_regs)
Definition: rtos.c:506
static bool rtos_try_next(struct target *target)
Definition: rtos.c:158
int rtos_write_buffer(struct target *target, target_addr_t address, uint32_t size, const uint8_t *buffer)
Definition: rtos.c:726
static struct symbol_table_elem * next_symbol(struct rtos *os, char *cur_symbol, uint64_t cur_addr)
Definition: rtos.c:192
int rtos_update_threads(struct target *target)
Definition: rtos.c:693
int rtos_read_buffer(struct target *target, target_addr_t address, uint32_t size, uint8_t *buffer)
Definition: rtos.c:718
int rtos_smp_init(struct target *target)
Definition: rtos.c:39
int rtos_qsymbol(struct connection *connection, char const *packet, int packet_size)
Definition: rtos.c:234
void rtos_free_threadlist(struct rtos *rtos)
Definition: rtos.c:700
int rtos_get_gdb_reg(struct connection *connection, int reg_num)
Look through all registers to find this register.
Definition: rtos.c:530
#define GDB_THREAD_PACKET_NOT_CONSUMED
Definition: rtos.h:113
const struct rtos_type zephyr_rtos
Definition: zephyr.c:788
const struct rtos_type threadx_rtos
Definition: threadx.c:193
int64_t threadid_t
Definition: rtos.h:14
const struct rtos_type ucos_iii_rtos
Definition: ucos_iii.c:501
target_addr_t addr
Start address to search for the control block.
Definition: rtt/rtt.c:28
struct target * target
Definition: rtt/rtt.c:26
When run_command is called, a new instance will be created on the stack, filled with the proper value...
Definition: command.h:76
Definition: rtos.h:52
const struct stack_register_offset * register_offsets
Definition: rtos.h:103
unsigned char num_output_registers
Definition: rtos.h:93
target_addr_t(* calculate_process_stack)(struct target *target, const uint8_t *stack_data, const struct rtos_register_stacking *stacking, target_addr_t stack_ptr)
Definition: rtos.h:99
unsigned char stack_registers_size
Definition: rtos.h:91
int(* read_stack)(struct target *target, int64_t stack_ptr, const struct rtos_register_stacking *stacking, uint8_t *stack_data)
Definition: rtos.h:107
signed char stack_growth_direction
Definition: rtos.h:92
Definition: rtos.h:58
int(* create)(struct target *target)
Definition: rtos.h:61
int(* smp_init)(struct target *target)
Definition: rtos.h:62
int(* update_threads)(struct rtos *rtos)
Definition: rtos.h:63
int(* get_thread_reg)(struct rtos *rtos, int64_t thread_id, uint32_t reg_num, struct rtos_reg *reg)
Definition: rtos.h:67
int(* get_symbol_list_to_lookup)(struct symbol_table_elem *symbol_list[])
Definition: rtos.h:69
const char * name
Definition: rtos.h:59
int(* write_buffer)(struct rtos *rtos, target_addr_t address, uint32_t size, const uint8_t *buffer)
Definition: rtos.h:78
int(* read_buffer)(struct rtos *rtos, target_addr_t address, uint32_t size, uint8_t *buffer)
Definition: rtos.h:76
bool(* detect_rtos)(struct target *target)
Definition: rtos.h:60
int(* get_thread_reg_list)(struct rtos *rtos, int64_t thread_id, struct rtos_reg **reg_list, int *num_regs)
Return a list of general registers, with their values filled out.
Definition: rtos.h:65
int(* set_reg)(struct rtos *rtos, uint32_t reg_num, uint8_t *reg_value)
Definition: rtos.h:72
Definition: rtos.h:35
const struct rtos_type * type
Definition: rtos.h:36
int thread_count
Definition: rtos.h:46
int(* gdb_thread_packet)(struct connection *connection, char const *packet, int packet_size)
Definition: rtos.h:47
struct thread_detail * thread_details
Definition: rtos.h:45
struct symbol_table_elem * symbols
Definition: rtos.h:38
struct target * target
Definition: rtos.h:39
int(* gdb_target_for_threadid)(struct connection *connection, int64_t thread_id, struct target **p_target)
Definition: rtos.h:48
threadid_t current_thread
Definition: rtos.h:44
int64_t current_threadid
Definition: rtos.h:42
unsigned short width_bits
Definition: rtos.h:87
unsigned short number
Definition: rtos.h:83
signed short offset
Definition: rtos.h:84
Table should be terminated by an element with NULL in symbol_name.
Definition: rtos.h:22
symbol_address_t address
Definition: rtos.h:24
bool optional
Definition: rtos.h:25
const char * symbol_name
Definition: rtos.h:23
Definition: target.h:119
struct rtos * rtos
Definition: target.h:186
bool rtos_auto_detect
Definition: target.h:187
unsigned int smp
Definition: target.h:190
char * extra_info_str
Definition: rtos.h:32
char * thread_name_str
Definition: rtos.h:31
bool exists
Definition: rtos.h:30
threadid_t threadid
Definition: rtos.h:29
int target_read_buffer(struct target *target, target_addr_t address, uint32_t size, uint8_t *buffer)
Definition: target.c:2416
#define ERROR_TARGET_INIT_FAILED
Definition: target.h:784
#define ARRAY_SIZE(x)
Compute the number of elements of a variable length array.
Definition: types.h:57
#define DIV_ROUND_UP(m, n)
Rounds m up to the nearest multiple of n using division.
Definition: types.h:79
uint64_t target_addr_t
Definition: types.h:335
#define NULL
Definition: usb.h:16
uint8_t cmd
Definition: vdebug.c:1
uint8_t offset[4]
Definition: vdebug.c:9
uint8_t count[4]
Definition: vdebug.c:22