patches/gdb/6.3/620-debian_static-thread-db.patch
author "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Thu May 17 16:22:51 2007 +0000 (2007-05-17)
changeset 96 aa1a9fbd6eb8
permissions -rw-r--r--
Debug facilities:
- add a framework to easily add new ones
- add gdb as a first debug facility
- add patches for gdb
After the kernel checked its installed headers, clean up the mess of .checked.* files.
Reorder scripts/crosstool.sh:
- dump the configuration early
- renice early
- get info about build system early, when setting up the environment
- when in cross or native, the host tools are those of the build system, and only in this case
- elapsed time calculations moved to scripts/functions
Remove handling of the color: it's gone once and for all.
Update tools/addToolVersion.sh:
- handle debug facilities
- commonalise some code
- remove dead tools (cygwin, tcc)
Point to my address for bug reports.
     1 Status: submitted similar patch 2004-12-08
     2 
     3 This patch cleans up the initialization of thread_db.  It works for static
     4 binaries now.  The vsyscall patches hide this problem, since new static
     5 binaries will load the vsyscall DSO and then trigger thread_db; but
     6 this is still a good cleanup.
     7 
     8 Index: gdb-6.3/gdb/thread-db.c
     9 ===================================================================
    10 --- gdb-6.3.orig/gdb/thread-db.c	2004-10-08 16:29:56.000000000 -0400
    11 +++ gdb-6.3/gdb/thread-db.c	2004-11-10 00:19:30.626530413 -0500
    12 @@ -34,6 +34,7 @@
    13  #include "target.h"
    14  #include "regcache.h"
    15  #include "solib-svr4.h"
    16 +#include "observer.h"
    17  
    18  #ifdef HAVE_GNU_LIBC_VERSION_H
    19  #include <gnu/libc-version.h>
    20 @@ -627,59 +628,49 @@ check_thread_signals (void)
    21  #endif
    22  }
    23  
    24 +/* Check whether thread_db is usable.  This function is called when
    25 +   an inferior is created (or otherwise acquired, e.g. attached to)
    26 +   and when new shared libraries are loaded into a running process.  */
    27 +
    28  static void
    29 -thread_db_new_objfile (struct objfile *objfile)
    30 +check_for_thread_db (void)
    31  {
    32    td_err_e err;
    33 +  static int already_loaded;
    34  
    35    /* First time through, report that libthread_db was successfuly
    36       loaded.  Can't print this in in thread_db_load as, at that stage,
    37 -     the interpreter and it's console haven't started.  The real
    38 -     problem here is that libthread_db is loaded too early - it should
    39 -     only be loaded when there is a program to debug.  */
    40 -  {
    41 -    static int dejavu;
    42 -    if (!dejavu)
    43 -      {
    44 -	Dl_info info;
    45 -	const char *library = NULL;
    46 -	/* Try dladdr.  */
    47 -	if (dladdr ((*td_ta_new_p), &info) != 0)
    48 -	  library = info.dli_fname;
    49 -	/* Try dlinfo?  */
    50 -	if (library == NULL)
    51 -	  /* Paranoid - don't let a NULL path slip through.  */
    52 -	  library = LIBTHREAD_DB_SO;
    53 -	printf_unfiltered ("Using host libthread_db library \"%s\".\n",
    54 -			   library);
    55 -	dejavu = 1;
    56 -      }
    57 -  }
    58 +     the interpreter and it's console haven't started.  */
    59  
    60 -  /* Don't attempt to use thread_db on targets which can not run
    61 -     (core files).  */
    62 -  if (objfile == NULL || !target_has_execution)
    63 +  if (!already_loaded)
    64      {
    65 -      /* All symbols have been discarded.  If the thread_db target is
    66 -         active, deactivate it now.  */
    67 -      if (using_thread_db)
    68 -	{
    69 -	  gdb_assert (proc_handle.pid == 0);
    70 -	  unpush_target (&thread_db_ops);
    71 -	  using_thread_db = 0;
    72 -	}
    73 +      Dl_info info;
    74 +      const char *library = NULL;
    75 +      if (dladdr ((*td_ta_new_p), &info) != 0)
    76 +	library = info.dli_fname;
    77 +
    78 +      /* Try dlinfo?  */
    79  
    80 -      goto quit;
    81 +      if (library == NULL)
    82 +	/* Paranoid - don't let a NULL path slip through.  */
    83 +	library = LIBTHREAD_DB_SO;
    84 +
    85 +      printf_unfiltered ("Using host libthread_db library \"%s\".\n",
    86 +			 library);
    87 +      already_loaded = 1;
    88      }
    89  
    90    if (using_thread_db)
    91      /* Nothing to do.  The thread library was already detected and the
    92         target vector was already activated.  */
    93 -    goto quit;
    94 +    return;
    95 +
    96 +  /* Don't attempt to use thread_db on targets which can not run
    97 +     (executables not running yet, core files) for now.  */
    98 +  if (!target_has_execution)
    99 +    return;
   100  
   101 -  /* Initialize the structure that identifies the child process.  Note
   102 -     that at this point there is no guarantee that we actually have a
   103 -     child process.  */
   104 +  /* Initialize the structure that identifies the child process.  */
   105    proc_handle.pid = GET_PID (inferior_ptid);
   106  
   107    /* Now attempt to open a connection to the thread library.  */
   108 @@ -706,12 +697,24 @@ thread_db_new_objfile (struct objfile *o
   109  	       thread_db_err_str (err));
   110        break;
   111      }
   112 +}
   113 +
   114 +static void
   115 +thread_db_new_objfile (struct objfile *objfile)
   116 +{
   117 +  if (objfile != NULL)
   118 +    check_for_thread_db ();
   119  
   120 -quit:
   121    if (target_new_objfile_chain)
   122      target_new_objfile_chain (objfile);
   123  }
   124  
   125 +static void
   126 +check_for_thread_db_observer (struct target_ops *target, int from_tty)
   127 +{
   128 +  check_for_thread_db ();
   129 +}
   130 +
   131  /* Attach to a new thread.  This function is called when we receive a
   132     TD_CREATE event or when we iterate over all threads and find one
   133     that wasn't already in our list.  */
   134 @@ -1366,5 +1369,8 @@ _initialize_thread_db (void)
   135        /* Add ourselves to objfile event chain.  */
   136        target_new_objfile_chain = deprecated_target_new_objfile_hook;
   137        deprecated_target_new_objfile_hook = thread_db_new_objfile;
   138 +
   139 +      /* Register ourselves for the new inferior observer.  */
   140 +      observer_attach_inferior_created (check_for_thread_db_observer);
   141      }
   142  }
   143 Index: gdb-6.3/gdb/Makefile.in
   144 ===================================================================
   145 --- gdb-6.3.orig/gdb/Makefile.in	2004-11-09 23:04:57.000000000 -0500
   146 +++ gdb-6.3/gdb/Makefile.in	2004-11-10 00:19:26.440347022 -0500
   147 @@ -2626,7 +2626,8 @@ thread.o: thread.c $(defs_h) $(symtab_h)
   148  	$(gdbcmd_h) $(regcache_h) $(gdb_h) $(gdb_string_h) $(ui_out_h)
   149  thread-db.o: thread-db.c $(defs_h) $(gdb_assert_h) $(gdb_proc_service_h) \
   150  	$(gdb_thread_db_h) $(bfd_h) $(gdbthread_h) $(inferior_h) \
   151 -	$(symfile_h) $(objfiles_h) $(target_h) $(regcache_h) $(solib_svr4_h)
   152 +	$(symfile_h) $(objfiles_h) $(target_h) $(regcache_h) $(solib_svr4_h) \
   153 +	$(observer_h)
   154  top.o: top.c $(defs_h) $(gdbcmd_h) $(call_cmds_h) $(cli_cmds_h) \
   155  	$(cli_script_h) $(cli_setshow_h) $(cli_decode_h) $(symtab_h) \
   156  	$(inferior_h) $(target_h) $(breakpoint_h) $(gdbtypes_h) \