From: Thiago Jung Bauermann <bauerman@br.ibm.com>
To: Paul Pluzhnikov <ppluzhnikov@google.com>
Cc: gdb-patches ml <gdb-patches@sourceware.org>
Subject: Re: [patch][rfc] Allow GDB to search for the right libthread_db.so.1
Date: Wed, 08 Apr 2009 21:23:00 -0000 [thread overview]
Message-ID: <1239225742.8871.145.camel@localhost.localdomain> (raw)
In-Reply-To: <20090406203920.CCD6F19C4EC@localhost>
Hi Paul,
El lun, 06-04-2009 a las 13:39 -0700, Paul Pluzhnikov escribió:
> We have perhaps uncommon setup here, where we have several installed
> versions of glibc, and need to debug executables which are compiled
> and linked against them (using -rpath).
Many thanks for posting this patch! This is an issue for glibc
developers too, and I already considered working on exactly this
problem. I'm glad you did it first. :-)
> If this looks reasonable, I'll work on documentation next.
> There is also a matching change to gdbserver, which I am postponing until
> a decision on this patch is made.
Looks reasonable to me in general, but I have some comments. I wasn't
familiar with linux-thread-db.c before reviewing this patch, so I'd
appreciate if someone with more familiarity with this code would verify
that I'm not talking nonsense. :-)
> 2009-04-06 Paul Pluzhnikov <ppluzhnikov@google.com>
>
> * gdb_thread_db.h (LIBTHREAD_DB_SEARCH_PATH): New define.
> (LIBTHREAD_DB_SO): Moved from linux-thread-db.c
>
> * linux-thread-db.c (try_thread_db_load_1): New function.
> (try_thread_db_load, thread_db_load_search): Likewise.
> (thread_db_load): Iterate over possibly multiple libthread_db's.
I think the ChangeLog should mention that thread_db_load is now called
from check_for_thread_db instead of _initialize_thread_db. Also, there
are changes in the patch that this ChangeLog doesn't mention.
> /* Non-zero if we're using this module's target vector. */
> -static int using_thread_db;
> +static void *using_thread_db;
The comment for this variable needs to be updated. It's not a binary
flag anymore, so it should mention what the void * value is. The
variable should have a different name too, to reflect its new meaning.
> static int
> -thread_db_load (void)
> +try_thread_db_load_1(void *handle)
> {
I know that this function was undocumented already, but would you mind
adding a brief comment describing what it does, and what its return
value means?
Since you are changing a bit its behaviour and purpose, it seems fair
that you get to (briefly) document it. :-)
> + /* Now attempt to open a connection to the thread library. */
> + err = td_ta_new_p (&proc_handle, &thread_agent);
> + if (err != TD_OK)
> + {
> + td_ta_new_p = NULL;
> + if (info_verbose)
> + printf_unfiltered (_("td_ta_new(): %s.\n"),
> + thread_db_err_str (err));
> + return 0;
> + }
If err != TD_OK && err != TD_NOLIBTHREAD, a warning should be emitted,
like in the current version of the code:
warning (_("Cannot initialize thread debugging library: %s"),
thread_db_err_str (err));
In your version of the code, this message is gone.
> @@ -447,9 +450,141 @@ thread_db_load (void)
> td_thr_event_enable_p = dlsym (handle, "td_thr_event_enable");
> td_thr_tls_get_addr_p = dlsym (handle, "td_thr_tls_get_addr");
>
> + printf_unfiltered (_("[Thread debugging using libthread_db enabled]\n"));
> +
> + init_thread_db_ops ();
> + add_target (&thread_db_ops);
Why can't you keep these calls in _initialize_thread_db? Isn't it wrong
to call add_target whenever a libthread_db is loaded (I admit I don't
know much about the target infrastructure in GDB)?
> + handle = dlopen (library, RTLD_NOW);
> + if (handle == NULL)
> + {
> + if (info_verbose)
> + printf_unfiltered (_("dlopen(): %s.\n"), dlerror ());
The parenthesis shouldn't be in the message. Also, suggest being a bit
more descriptive: "dlopen failed: %s.\n"
The other error and information messages which currently have
parenthesis in them should also be fixed.
> +static int
> +thread_db_load_search ()
> +{
> + char path[PATH_MAX];
This function can overflow path. Serious problem, IMHO.
> + Dl_info info;
> + const char *library = NULL;
> + if (dladdr ((*td_ta_new_p), &info) != 0)
> + library = info.dli_fname;
> + if (library == NULL)
> + library = LIBTHREAD_DB_SO;
> + printf_unfiltered (_("Warning: guessed host libthread_db "
> + "library \"%s\".\n"), library);
Not sure this should be a warning. It's possible that the guessed
libthread_db is correct. Or is it more likely that it's not?
Also, I think it's clearer to rephrase it as:
"Searched libthread_db library to use, selected %s"
That is, avoid the (IMHO confusing) term "guessed library".
> + }
> + else
> + printf_unfiltered (_("Warning: unable to guess libthread_db, "
> + "thread debugging will not be available.\n"));
Again, printf_unfiltered vs warning. I'd appreciate other opinions on
this topic. Also, suggest rewording to avoid "guess":
"Unable to find libthread_db matching inferior's thread library, thread
debugging will not be available.\n".
> +static int
> +thread_db_load (void)
> +{
Please add a comment describing the function and its return value.
Please also do this to the other functions which you introduced.
> + msym = lookup_minimal_symbol ("nptl_version", NULL, NULL);
> + if (!msym)
> + msym = lookup_minimal_symbol ("__linuxthreads_version", NULL, NULL);
> +
> + if (!msym)
> + /* No threads yet */
> + return 0;
Clever way to detect if a thread library is present. I can't comment on
its correctness and reliability though. Perhaps others will have more
insight. My only comment is that an alternative would be to search
through the inferior's link map. Don't know if it would be better or
worse.
Also, I assume you tested your patch in both NPTL systems and
LinuxThread systems, right?
> + soname = solib_name_from_address (SYMBOL_VALUE_ADDRESS (msym));
> + if (soname)
> + {
> + /* Attempt to load libthread_db from the same directory. */
> + char path[PATH_MAX], *cp;
> + strcpy (path, soname);
> + cp = strrchr (path, '/');
> + if (cp == NULL)
> + {
> + /* Expected to get fully resolved pathname, but got
> + something else. Hope for the best. */
> + printf_unfiltered (_("warning: (Internal error: "
> + "solib_name_from_address() returned \"%s\".\n"),
> + soname);
> + return thread_db_load_search ();
> + }
"Internal error" has a specific meaning in GDB already, and it's not
what you use it for here. I suggest rewording to:
warning (_("Cannot obtain absolute path of thread library: %s"));
Note that I changed from calling printf_unfiltered to warning. I'm not
sure, but I gather the latter is preferred, right? (/me looks nervously
at other GDB developers, seeking a nod.)
Also, please clarify what "hope for the best" means here.
> + printf_unfiltered (_("Using host libthread_db library \"%s\".\n"),
> + library);
> + last_loaded = td_ta_new_p;
This message is currently only printed when verbose is on, but you
changed it to be always printed. Please provide a rationale for the
change.
> @@ -896,7 +993,10 @@ thread_db_wait (struct target_ops *ops,
> {
> remove_thread_event_breakpoints ();
> unpush_target (&thread_db_ops);
> + if (using_thread_db)
> + dlclose (using_thread_db);
> using_thread_db = 0;
> + no_shared_libraries (NULL, 0);
I don't know much about GDB's mourning process, so this is a genuine
question: is this the appropriate place to call no_shared_libraries?
Doesn't feel right to me.
--
[]'s
Thiago Jung Bauermann
IBM Linux Technology Center
next prev parent reply other threads:[~2009-04-08 21:23 UTC|newest]
Thread overview: 59+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-04-06 20:39 Paul Pluzhnikov
2009-04-08 21:23 ` Thiago Jung Bauermann [this message]
2009-04-10 19:06 ` Paul Pluzhnikov
2009-04-16 17:56 ` Tom Tromey
2009-04-16 18:22 ` Eli Zaretskii
2009-04-17 19:13 ` Paul Pluzhnikov
2009-04-18 17:01 ` Eli Zaretskii
2009-04-19 14:59 ` Thiago Jung Bauermann
2009-04-19 18:03 ` Paul Pluzhnikov
2009-04-20 13:18 ` Daniel Jacobowitz
2009-04-20 16:47 ` Paul Pluzhnikov
2009-04-20 17:02 ` Daniel Jacobowitz
2009-04-20 17:20 ` Paul Pluzhnikov
2009-04-20 18:04 ` Daniel Jacobowitz
2009-04-20 19:09 ` Paul Pluzhnikov
2009-04-22 17:25 ` Daniel Jacobowitz
2009-04-23 1:10 ` Paul Pluzhnikov
2009-04-23 1:34 ` Tom Tromey
2009-04-23 6:28 ` Hui Zhu
2009-04-23 6:21 ` Hui Zhu
2009-04-23 7:01 ` Paul Pluzhnikov
2009-04-23 8:06 ` Hui Zhu
2009-04-23 11:32 ` Hui Zhu
2009-04-29 20:30 ` Paul Pluzhnikov
2009-04-30 5:38 ` Hui Zhu
2009-04-30 18:56 ` Joel Brobecker
2009-04-30 19:11 ` Paul Pluzhnikov
2009-04-30 22:12 ` Doug Evans
2009-04-30 23:18 ` Paul Pluzhnikov
2009-05-01 0:20 ` Paul Pluzhnikov
2009-05-11 13:13 ` Pedro Alves
2009-05-11 18:09 ` Paul Pluzhnikov
2009-05-11 21:09 ` Pedro Alves
2009-05-12 7:16 ` Hui Zhu
2009-05-12 16:42 ` Paul Pluzhnikov
2009-05-13 2:56 ` Hui Zhu
2009-05-13 3:29 ` Paul Pluzhnikov
2009-05-13 4:39 ` Hui Zhu
2009-05-15 14:37 ` Daniel Jacobowitz
2009-05-15 16:56 ` Paul Pluzhnikov
2009-05-01 7:21 ` Eli Zaretskii
2009-05-01 15:49 ` Paul Pluzhnikov
2009-05-01 16:49 ` Daniel Jacobowitz
2009-05-01 17:02 ` Paul Pluzhnikov
2009-05-01 17:11 ` Daniel Jacobowitz
2009-05-01 17:17 ` Pedro Alves
2009-05-01 18:53 ` Doug Evans
2009-05-04 0:07 ` Hui Zhu
2009-05-04 3:31 ` Paul Pluzhnikov
2009-05-05 2:54 ` Hui Zhu
2009-05-05 3:38 ` Joel Brobecker
2009-05-05 11:42 ` Hui Zhu
2009-05-11 11:34 ` Pedro Alves
2009-05-11 12:24 ` Joel Brobecker
2009-04-20 17:37 ` Paul Pluzhnikov
2009-04-20 18:46 ` Eli Zaretskii
2015-08-25 18:01 ` Jan Kratochvil
2015-08-25 18:14 ` Paul Pluzhnikov
2015-08-25 18:22 ` Jan Kratochvil
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1239225742.8871.145.camel@localhost.localdomain \
--to=bauerman@br.ibm.com \
--cc=gdb-patches@sourceware.org \
--cc=ppluzhnikov@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox