+ /* Value returned by last libthread_db call. */
+ td_err_e last_result;
+};
+
+static struct check_thread_db_info *tdb_testinfo;
+
+/* Callback for check_thread_db. */
+
+static int
+check_thread_db_callback (const td_thrhandle_t *th, void *arg)
+{
+ gdb_assert (tdb_testinfo != NULL);
+ tdb_testinfo->threads_seen = true;
+
+#define LOG(fmt, args...) \
+ do \
+ { \
+ if (tdb_testinfo->log_progress) \
+ { \
+ debug_printf (fmt, ## args); \
+ gdb_flush (gdb_stdlog); \
+ } \
+ } \
+ while (0)
+
+#define CHECK_1(expr, args...) \
+ do \
+ { \
+ if (!(expr)) \
+ { \
+ LOG (" ... FAIL!\n"); \
+ error (args); \
+ } \
+ } \
+ while (0)
+
+#define CHECK(expr) \
+ CHECK_1 (expr, "(%s) == false", #expr)
+
+#define CALL_UNCHECKED(func, args...) \
+ do \
+ { \
+ tdb_testinfo->last_call = #func; \
+ tdb_testinfo->last_result \
+ = tdb_testinfo->info->func ## _p (args); \
+ } \
+ while (0)
+
+#define CHECK_CALL() \
+ CHECK_1 (tdb_testinfo->last_result == TD_OK, \
+ _("%s failed: %s"), \
+ tdb_testinfo->last_call, \
+ thread_db_err_str (tdb_testinfo->last_result)) \
+
+#define CALL(func, args...) \
+ do \
+ { \
+ CALL_UNCHECKED (func, args); \
+ CHECK_CALL (); \
+ } \
+ while (0)
+
+ LOG (" Got thread");
+
+ /* Check td_ta_thr_iter passed consistent arguments. */
+ CHECK (th != NULL);
+ CHECK (arg == (void *) tdb_testinfo);
+ CHECK (th->th_ta_p == tdb_testinfo->info->thread_agent);
+
+ LOG (" %s", core_addr_to_string_nz ((CORE_ADDR) th->th_unique));
+
+ /* Check td_thr_get_info. */
+ td_thrinfo_t ti;
+ CALL (td_thr_get_info, th, &ti);
+
+ LOG (" => %d", ti.ti_lid);
+
+ CHECK (ti.ti_ta_p == th->th_ta_p);
+ CHECK (ti.ti_tid == (thread_t) th->th_unique);
+
+ /* Check td_ta_map_lwp2thr. */
+ td_thrhandle_t th2;
+ memset (&th2, 23, sizeof (td_thrhandle_t));
+ CALL_UNCHECKED (td_ta_map_lwp2thr, th->th_ta_p, ti.ti_lid, &th2);
+
+ if (tdb_testinfo->last_result == TD_ERR && !target_has_execution)