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