620-debian_static-thread-db.patch 5.2 KB

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