From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 18047 invoked by alias); 23 Apr 2009 11:32:59 -0000 Received: (qmail 18028 invoked by uid 22791); 23 Apr 2009 11:32:56 -0000 X-SWARE-Spam-Status: No, hits=-1.6 required=5.0 tests=AWL,BAYES_00,SARE_MSGID_LONG40,SPF_PASS X-Spam-Check-By: sourceware.org Received: from ti-out-0910.google.com (HELO ti-out-0910.google.com) (209.85.142.185) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 23 Apr 2009 11:32:51 +0000 Received: by ti-out-0910.google.com with SMTP id a1so76111tib.12 for ; Thu, 23 Apr 2009 04:32:48 -0700 (PDT) MIME-Version: 1.0 Received: by 10.110.84.3 with SMTP id h3mr80802tib.3.1240486368311; Thu, 23 Apr 2009 04:32:48 -0700 (PDT) In-Reply-To: References: <1239225742.8871.145.camel@localhost.localdomain> <20090420170154.GA10112@caradoc.them.org> <8ac60eac0904201019g7ba8056bx5e84e6bfdf5935d8@mail.gmail.com> <20090420180352.GA14206@caradoc.them.org> <8ac60eac0904201208m95d4585k2b09f6b6fe5edb40@mail.gmail.com> <20090422172517.GA17235@caradoc.them.org> <8ac60eac0904221810x24763ecaj4a888927b766e7f7@mail.gmail.com> <8ac60eac0904230001w1afd9179wcb76e1cfd7f3f386@mail.gmail.com> Date: Thu, 23 Apr 2009 11:32:00 -0000 Message-ID: Subject: Re: [patch][rfc] Allow GDB to search for the right libthread_db.so.1 From: Hui Zhu To: Paul Pluzhnikov Cc: tromey@redhat.com, Thiago Jung Bauermann , gdb-patches ml , Eli Zaretskii Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-IsSubscribed: yes 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: 2009-04/txt/msg00643.txt.bz2 In function thread_db_load, I suggest try_thread_db_load with libthread_db_search_path first. Cause I think if user set a directory, he must want it be loaded. Thanks, Hui On Thu, Apr 23, 2009 at 16:05, Hui Zhu wrote: > On Thu, Apr 23, 2009 at 15:01, Paul Pluzhnikov w= rote: >> On Wed, Apr 22, 2009 at 11:21 PM, Hui Zhu wrote: >> >>> About your patch, I think let user choice load which libthread_db is >>> very cool idea. >>> Why not let they set which file they want to load directly? >>> >>> For example: >>> set libthread-db /xxx_dir/libxxx >> >> As I stated at the start of this thread, we have a mixture of >> executables: some are linked statically, some dynamically, and >> against several (incompatible WRT libthread_db) glibc versions. >> >> I'd like GDB to work "automagically" for all such executables, >> without the end user having to understand and specify exactly >> which libthread_db must be loaded for each one [1]. >> >> The patch allows me to achieve that (all I need to do is provide >> appropriate local definition of LIBTHREAD_DB_SEARCH_PATH). >> >> [1] Understanding this requires the user to understand how >> GDB uses libthread_db and the relationship between libpthread and >> libthread_db. Also, the mapping is complicated by the fact that >> 64-bit GDB is sometimes used to debug 32-bit inferiors. >> > > I read your patch again, And I think let user set file name is not > conflict with your patch. > In thread_db_load_search: > + =A0while (*search_path) > + =A0 =A0{ > + =A0 =A0 =A0const char *end =3D strchr (search_path, ':'); > + =A0 =A0 =A0if (end) > + =A0 =A0 =A0 { > + =A0 =A0 =A0 =A0 size_t len =3D end - search_path; > + =A0 =A0 =A0 =A0 =A0if (len + 1 + strlen (LIBTHREAD_DB_SO) + 1 > sizeof = (path)) > + =A0 =A0 =A0 =A0 =A0 =A0{ > + =A0 =A0 =A0 =A0 =A0 =A0 =A0char *cp =3D xmalloc (len + 1); > + =A0 =A0 =A0 =A0 =A0 =A0 =A0memcpy (cp, search_path, len); > + =A0 =A0 =A0 =A0 =A0 =A0 =A0cp[len] =3D '\0'; > + =A0 =A0 =A0 =A0 =A0 =A0 =A0warning (_("libthread_db_search_path compone= nt too long," > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 " ignored: %s."), cp); > + =A0 =A0 =A0 =A0 =A0 =A0 =A0xfree (cp); > + =A0 =A0 =A0 =A0 =A0 =A0 =A0search_path +=3D len + 1; > + =A0 =A0 =A0 =A0 =A0 =A0 =A0continue; > + =A0 =A0 =A0 =A0 =A0 =A0} > + =A0 =A0 =A0 =A0 memcpy (path, search_path, len); > + =A0 =A0 =A0 =A0 path[len] =3D '\0'; > + =A0 =A0 =A0 =A0 search_path +=3D len + 1; > + =A0 =A0 =A0 } > + =A0 =A0 =A0else > + =A0 =A0 =A0 { > + =A0 =A0 =A0 =A0 =A0size_t len =3D strlen (search_path); > + > + =A0 =A0 =A0 =A0 =A0if (len + 1 + strlen (LIBTHREAD_DB_SO) + 1 > sizeof = (path)) > + =A0 =A0 =A0 =A0 =A0 =A0{ > + =A0 =A0 =A0 =A0 =A0 =A0 =A0warning (_("libthread_db_search_path compone= nt too long," > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 " ignored: %s."), searc= h_path); > + =A0 =A0 =A0 =A0 =A0 =A0 =A0break; > + =A0 =A0 =A0 =A0 =A0 =A0} > + =A0 =A0 =A0 =A0 memcpy (path, search_path, len + 1); > + =A0 =A0 =A0 =A0 search_path +=3D len; > + =A0 =A0 =A0 } > > When you get a path, you can check if this is a directory. > > If this is a directory, do following job. > > + =A0 =A0 =A0strcat (path, "/"); > + =A0 =A0 =A0strcat (path, LIBTHREAD_DB_SO); > + =A0 =A0 =A0if (try_thread_db_load (path)) > + =A0 =A0 =A0 { > + =A0 =A0 =A0 =A0 rc =3D 1; > + =A0 =A0 =A0 =A0 break; > + =A0 =A0 =A0 } > > If this is a normal file, try_thread_db_load (path) without strcat > LIBTHREAD_DB_SO. > > What do you think about it? > > > And in thread_db_load: > + =A0msym =3D lookup_minimal_symbol ("nptl_version", NULL, NULL); > + =A0if (!msym) > + =A0 =A0msym =3D lookup_minimal_symbol ("__linuxthreads_version", NULL, = NULL); > + > + =A0/* Some really old libpthread versions do not have either of the abo= ve. =A0*/ > + =A0if (!msym) > + =A0 =A0msym =3D lookup_minimal_symbol ("__pthread_threads_events", NULL= , NULL); > + > + =A0if (!msym) > + =A0 =A0/* No threads yet */ > + =A0 =A0return 0; > > You really don't want gdb try it with libthread_db? > If in the future, this code doesn't cover everything. =A0And I think let > gdb try will not affect anything. =A0:) > > Thanks, > Hui >