+
+static char *next_symbol(struct rtos *os, char *cur_symbol, uint64_t cur_addr)
+{
+ symbol_table_elem_t *s;
+
+ if (!os->symbols)
+ os->type->get_symbol_list_to_lookup(&os->symbols);
+
+ if (!cur_symbol[0])
+ return os->symbols[0].symbol_name;
+
+ for (s = os->symbols; s->symbol_name; s++)
+ if (!strcmp(s->symbol_name, cur_symbol)) {
+ s->address = cur_addr;
+ s++;
+ return s->symbol_name;
+ }
+
+ return NULL;
+}
+
+/* rtos_qsymbol() processes and replies to all qSymbol packets from GDB.
+ *
+ * GDB sends a qSymbol:: packet (empty address, empty name) to notify
+ * that it can now answer qSymbol::hexcodedname queries, to look up symbols.
+ *
+ * If the qSymbol packet has no address that means GDB did not find the
+ * symbol, in which case auto-detect will move on to try the next RTOS.
+ *
+ * rtos_qsymbol() then calls the next_symbol() helper function, which
+ * iterates over symbol names for the current RTOS until it finds the
+ * symbol in the received GDB packet, and then returns the next entry
+ * in the list of symbols.
+ *
+ * If GDB replied about the last symbol for the RTOS and the RTOS was
+ * specified explicitly, then no further symbol lookup is done. When
+ * auto-detecting, the RTOS driver _detect() function must return success.
+ *
+ * rtos_qsymbol() returns 1 if an RTOS has been detected, or 0 otherwise.
+ */