From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 9516 invoked by alias); 12 Mar 2008 17:08:49 -0000 Received: (qmail 9506 invoked by uid 22791); 12 Mar 2008 17:08:48 -0000 X-Spam-Check-By: sourceware.org Received: from rock.gnat.com (HELO rock.gnat.com) (205.232.38.15) by sourceware.org (qpsmtpd/0.31) with ESMTP; Wed, 12 Mar 2008 17:08:18 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id DAA942AA4B2 for ; Wed, 12 Mar 2008 13:08:16 -0400 (EDT) Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 9IHnQJubiikx for ; Wed, 12 Mar 2008 13:08:16 -0400 (EDT) Received: from joel.gnat.com (localhost.localdomain [127.0.0.1]) by rock.gnat.com (Postfix) with ESMTP id 777932AA45E for ; Wed, 12 Mar 2008 13:08:16 -0400 (EDT) Received: by joel.gnat.com (Postfix, from userid 1000) id 1B996E7ACB; Wed, 12 Mar 2008 10:08:14 -0700 (PDT) Date: Wed, 12 Mar 2008 17:08:00 -0000 From: Joel Brobecker To: gdb-patches@sourceware.org Subject: [RFA/RFC] Fix broken user-thread debugging on x86-solaris Message-ID: <20080312170814.GC4433@adacore.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="OXfL5xGRrasGEqWY" Content-Disposition: inline User-Agent: Mutt/1.4.2.2i Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2008-03/txt/msg00128.txt.bz2 --OXfL5xGRrasGEqWY Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-length: 2653 Hello, While testing GDB on x86-solaris, I noticed that the debugger now prints a warning during startup: % ./gdb [GDB will not be able to debug user-mode threads: ld.so.1: gdb.ref: fatal: relocation error: file /usr/lib/libthread_db.so.1: symbol ps_lgetLDT: referenced symbol not found] GNU gdb 6.8.50.20080311-cvs Copyright (C) 2008 Free Software Foundation, Inc. [...] The problem was introduced when we killed the TM file, which was defining the TM_I386SOL2_H macro that a couple of units were actually using (ugh!). Basically, the problem on x86-solaris is that, in order to load libthread_db.so, we need to define ps_lgetLDT or the loading will fail due to this symbol being undefined. This function is defined inside sol-thread.c but is conditionalized on TM_I386SOL2_H being defined: #ifdef TM_I386SOL2_H /* Reads the local descriptor table of a LWP. */ ps_err_e ps_lgetLDT (gdb_ps_prochandle_t ph, lwpid_t lwpid, struct ssd *pldt) { Similarly, a couple of other functions inside procfs.c that this function uses are conditionalized on the same macro: proc_get_LDT_entry and procfs_find_LDT_entry. This stuff is entirely x86-solaris specific, so cannot be enabled on sparc-solaris. I think the most classical way of fixing this would be to move these to their own file, such as sol-x86-thread.c. But I'm not sure whether this is going to be the prefered solution in this case, because the procfs routines need access to certain fields of a structure that is not public (struct procinfo). In this version, I went to the simplest, which is to have configure define a new macro (HAVE_X86_SOLARIS_USER_THREADS) when on x86-solaris and the thread_db library is available. I then replaced TM_I386SOL2_H by the new macro. If I were to move the 3 functions to their own file, I would have to create procfs.h to provide an opaque definition of struct procinfo. I would also add a few accessor routines (to get the pid and the ctl_fd), and make a few routines such as find_procinfo or proc_get_gregs non-static. I don't mind doing this work, but I want to make sure others prefer it too. 2008-03-12 Joel Brobecker * configure.ac (HAVE_X86_SOLARIS_USER_THREADS): Define this macro if we are building a native x86-solaris debugger that has access to user-threads. * configure, config.in: Regenerate. * sol-thread.c, procfs.c : Use HAVE_X86_SOLARIS_USER_THREADS in place of TM_I386SOL2_H. Tested on x86-solaris. No regression. Opinions? BTW: We should fix this in the branch as well. Thanks, -- Joel --OXfL5xGRrasGEqWY Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="x86-user-threads.diff" Content-length: 3155 Index: configure.ac =================================================================== --- configure.ac (revision 34930) +++ configure.ac (working copy) @@ -1221,6 +1221,11 @@ if test ${build} = ${host} -a ${host} = [Define if on solaris uses int instead of size_t, and assorted other type changes.]) fi + if test "${gdb_host_cpu}" = "i386" ; then + AC_DEFINE(HAVE_X86_SOLARIS_USER_THREADS, 1, + [Define if the thread layer uses the user-thread debug library + on an x86-solaris system]) + fi else AC_MSG_RESULT(no) fi Index: configure =================================================================== --- configure (revision 34930) +++ configure (working copy) @@ -22865,6 +22865,13 @@ cat >>confdefs.h <<\_ACEOF _ACEOF fi + if test "${gdb_host_cpu}" = "i386" ; then + +cat >>confdefs.h <<\_ACEOF +#define HAVE_X86_SOLARIS_USER_THREADS 1 +_ACEOF + + fi else echo "$as_me:$LINENO: result: no" >&5 echo "${ECHO_T}no" >&6 Index: config.in =================================================================== --- config.in (revision 34930) +++ config.in (working copy) @@ -482,6 +482,10 @@ /* Define to 1 if `vfork' works. */ #undef HAVE_WORKING_VFORK +/* Define if the thread layer uses the user-thread debug library on an + x86-solaris system */ +#undef HAVE_X86_SOLARIS_USER_THREADS + /* Define to 1 if you have the `XML_StopParser' function. */ #undef HAVE_XML_STOPPARSER Index: sol-thread.c =================================================================== --- sol-thread.c (revision 34930) +++ sol-thread.c (working copy) @@ -1298,7 +1298,7 @@ ps_pdmodel (gdb_ps_prochandle_t ph, int } #endif /* PR_MODEL_LP64 */ -#ifdef TM_I386SOL2_H +#ifdef HAVE_X86_SOLARIS_USER_THREADS /* Reads the local descriptor table of a LWP. */ @@ -1326,7 +1326,7 @@ ps_lgetLDT (gdb_ps_prochandle_t ph, lwpi /* LDT not found. */ return PS_ERR; } -#endif /* TM_I386SOL2_H */ +#endif /* HAVE_X86_SOLARIS_USER_THREADS */ /* Convert PTID to printable form. */ Index: procfs.c =================================================================== --- procfs.c (revision 34930) +++ procfs.c (working copy) @@ -3028,7 +3028,7 @@ proc_set_watchpoint (procinfo *pi, CORE_ #endif } -#ifdef TM_I386SOL2_H /* Is it hokey to use this? */ +#ifdef HAVE_X86_SOLARIS_USER_THREADS #include @@ -3120,7 +3120,7 @@ proc_get_LDT_entry (procinfo *pi, int ke #endif } -#endif /* TM_I386SOL2_H */ +#endif /* HAVE_X86_SOLARIS_USER_THREADS */ /* =============== END, non-thread part of /proc "MODULE" =============== */ @@ -5549,7 +5549,7 @@ procfs_stopped_by_watchpoint (ptid_t pti return 0; } -#ifdef TM_I386SOL2_H +#ifdef HAVE_X86_SOLARIS_USER_THREADS /* * Function: procfs_find_LDT_entry * @@ -5587,7 +5587,7 @@ procfs_find_LDT_entry (ptid_t ptid) /* Find the matching entry and return it. */ return proc_get_LDT_entry (pi, key); } -#endif /* TM_I386SOL2_H */ +#endif /* HAVE_X86_SOLARIS_USER_THREADS */ /* * Memory Mappings Functions: --OXfL5xGRrasGEqWY--