- int symbols_done = 0;
- if (target->rtos->symbols[next_symbol_num].symbol_name == NULL) {
- if ((target->rtos_auto_detect == false) ||
- (1 == target->rtos->type->detect_rtos(target))) {
- /* Found correct RTOS or not autodetecting */
- if (target->rtos_auto_detect == true)
- LOG_OUTPUT("Auto-detected RTOS: %s\r\n",
- target->rtos->type->name);
- symbols_done = 1;
- } else {
- /* Auto detecting RTOS and currently not found */
- if (1 != rtos_try_next(target))
- /* No more RTOS's to try */
- symbols_done = 1;
- else {
- next_symbol_num = 0;
- target->rtos->type->get_symbol_list_to_lookup(
- &target->rtos->symbols);
- }
+ 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.
+ */
+int rtos_qsymbol(struct connection *connection, char const *packet, int packet_size)
+{
+ int rtos_detected = 0;
+ uint64_t addr = 0;
+ size_t reply_len;
+ char reply[GDB_BUFFER_SIZE], cur_sym[GDB_BUFFER_SIZE / 2] = "", *next_sym;
+ struct target *target = get_target_from_connection(connection);
+ struct rtos *os = target->rtos;
+
+ reply_len = sprintf(reply, "OK");
+
+ if (!os)
+ goto done;
+
+ /* Decode any symbol name in the packet*/
+ int len = unhexify(cur_sym, strchr(packet + 8, ':') + 1, strlen(strchr(packet + 8, ':') + 1));
+ cur_sym[len] = 0;
+
+ if ((strcmp(packet, "qSymbol::") != 0) && /* GDB is not offering symbol lookup for the first time */
+ (!sscanf(packet, "qSymbol:%" SCNx64 ":", &addr))) { /* GDB did not found an address for a symbol */
+ /* GDB could not find an address for the previous symbol */
+ if (!target->rtos_auto_detect) {
+ LOG_WARNING("RTOS %s not detected. (GDB could not find symbol \'%s\')", os->type->name, cur_sym);
+ goto done;
+ } else {
+ /* Autodetecting RTOS - try next RTOS */
+ if (!rtos_try_next(target)) {
+ LOG_WARNING("No RTOS could be auto-detected!");
+ goto done;