Re: [hjl@lucon.org: Re: Does gdb 5.2 work with statically linked thread application under Linux?]

H . J . Lu
2002-03-13T17:54:18Z

[-- Attachment #1: Type: text/plain, Size: 333 bytes --]

On Wed, Mar 13, 2002 at 12:50:34PM -0500, Daniel Jacobowitz wrote:
> Does anyone have a comment on this patch? It fixes thread_db for
> statically linked binaries (which I broke), and I think it's
> legitimate.
>

I am enclosing an upated patch here. Any targets should be able to
use target_corefile_hook if necessary.

H.J.
---

[-- Attachment #2: gdb-static.patch --]
[-- Type: text/plain, Size: 3110 bytes --]

2002-03-07 H.J. Lu (hjl@gnu.org)

* target.h (target_corefile_hook): New prototype.

* target.c (target_corefile_hook): New.

* corelow.c (core_open): Call target_corefile_hook if needed.

* thread-db.c (target_corefile_chain): New.
(thread_db_corefile): New.
(thread_db_new_objfile): Don't check target_has_execution.
(_initialize_thread_db): Save target_corefile_hook in
target_corefile_chain.
Set target_corefile_hook to thread_db_corefile.

--- gdb/corelow.c.static Wed Mar 6 22:30:49 2002
+++ gdb/corelow.c Thu Mar 7 15:01:41 2002
@@ -303,6 +303,9 @@ core_open (char *filename, int from_tty)
filename, bfd_errmsg (bfd_get_error ()));
}

+ if (target_corefile_hook)
+ target_corefile_hook ();
+
/* Looks semi-reasonable. Toss the old core file and work on the new. */

discard_cleanups (old_chain); /* Don't free filename any more */
--- gdb/target.c.static Wed Mar 6 22:31:31 2002
+++ gdb/target.c Thu Mar 7 14:54:50 2002
@@ -38,6 +38,8 @@

extern int errno;

+void (*target_corefile_hook) (void);
+
static void target_info (char *, int);

static void cleanup_target (struct target_ops *);
--- gdb/target.h.static Wed Mar 6 22:31:31 2002
+++ gdb/target.h Thu Mar 7 14:54:38 2002
@@ -985,6 +985,8 @@ extern char *normal_pid_to_str (ptid_t p

extern void (*target_new_objfile_hook) (struct objfile *);

+extern void (*target_corefile_hook) (void);
+
#ifndef target_pid_or_tid_to_str
#define target_pid_or_tid_to_str(ID) \
target_pid_to_str (ID)
--- gdb/thread-db.c.static Wed Mar 6 22:31:31 2002
+++ gdb/thread-db.c Thu Mar 7 15:20:17 2002
@@ -54,6 +54,9 @@ static struct target_ops *target_beneath
/* Pointer to the next function on the objfile event chain. */
static void (*target_new_objfile_chain) (struct objfile *objfile);

+/* Pointer to the next function on the corefile event chain. */
+static void (*target_corefile_chain) (void);
+
/* Non-zero if we're using this module's target vector. */
static int using_thread_db;

@@ -479,13 +482,28 @@ disable_thread_signals (void)
}

static void
+thread_db_corefile (void)
+{
+ if (using_thread_db)
+ {
+ /* If the thread_db target is active, deactivate it now. */
+ gdb_assert (proc_handle.pid == 0);
+ unpush_target (&thread_db_ops);
+ using_thread_db = 0;
+ }
+
+ keep_thread_db = 0;
+
+ if (target_corefile_chain)
+ target_corefile_chain ();
+}
+
+static void
thread_db_new_objfile (struct objfile *objfile)
{
td_err_e err;

- /* Don't attempt to use thread_db on targets which can not run
- (core files). */
- if (objfile == NULL || !target_has_execution)
+ if (objfile == NULL)
{
/* All symbols have been discarded. If the thread_db target is
active, deactivate it now. */
@@ -1040,5 +1058,7 @@ _initialize_thread_db (void)
/* Add ourselves to objfile event chain. */
target_new_objfile_chain = target_new_objfile_hook;
target_new_objfile_hook = thread_db_new_objfile;
+ target_corefile_chain = target_corefile_hook;
+ target_corefile_hook = thread_db_corefile;
}
}