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