solist.h 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. /* Shared library declarations for GDB, the GNU Debugger.
  2. Copyright (C) 1990-2022 Free Software Foundation, Inc.
  3. This file is part of GDB.
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 3 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>. */
  14. #ifndef SOLIST_H
  15. #define SOLIST_H
  16. #define SO_NAME_MAX_PATH_SIZE 512 /* FIXME: Should be dynamic */
  17. /* For domain_enum domain. */
  18. #include "symtab.h"
  19. #include "gdb_bfd.h"
  20. #include "target-section.h"
  21. /* Base class for target-specific link map information. */
  22. struct lm_info_base
  23. {
  24. };
  25. struct so_list
  26. {
  27. /* The following fields of the structure come directly from the
  28. dynamic linker's tables in the inferior, and are initialized by
  29. current_sos. */
  30. struct so_list *next; /* next structure in linked list */
  31. /* A pointer to target specific link map information. Often this
  32. will be a copy of struct link_map from the user process, but
  33. it need not be; it can be any collection of data needed to
  34. traverse the dynamic linker's data structures. */
  35. lm_info_base *lm_info;
  36. /* Shared object file name, exactly as it appears in the
  37. inferior's link map. This may be a relative path, or something
  38. which needs to be looked up in LD_LIBRARY_PATH, etc. We use it
  39. to tell which entries in the inferior's dynamic linker's link
  40. map we've already loaded. */
  41. char so_original_name[SO_NAME_MAX_PATH_SIZE];
  42. /* Shared object file name, expanded to something GDB can open. */
  43. char so_name[SO_NAME_MAX_PATH_SIZE];
  44. /* Program space this shared library belongs to. */
  45. struct program_space *pspace;
  46. /* The following fields of the structure are built from
  47. information gathered from the shared object file itself, and
  48. are set when we actually add it to our symbol tables.
  49. current_sos must initialize these fields to 0. */
  50. bfd *abfd;
  51. char symbols_loaded; /* flag: symbols read in yet? */
  52. /* objfile with symbols for a loaded library. Target memory is read from
  53. ABFD. OBJFILE may be NULL either before symbols have been loaded, if
  54. the file cannot be found or after the command "nosharedlibrary". */
  55. struct objfile *objfile;
  56. target_section_table *sections;
  57. /* Record the range of addresses belonging to this shared library.
  58. There may not be just one (e.g. if two segments are relocated
  59. differently). This is used for "info sharedlibrary" and
  60. the MI command "-file-list-shared-libraries". The latter has a format
  61. that supports outputting multiple segments once the related code
  62. supports them. */
  63. CORE_ADDR addr_low, addr_high;
  64. };
  65. struct target_so_ops
  66. {
  67. /* Adjust the section binding addresses by the base address at
  68. which the object was actually mapped. */
  69. void (*relocate_section_addresses) (struct so_list *so,
  70. struct target_section *);
  71. /* Free the link map info and any other private data structures
  72. associated with a so_list entry. */
  73. void (*free_so) (struct so_list *so);
  74. /* Reset private data structures associated with SO.
  75. This is called when SO is about to be reloaded.
  76. It is also called before free_so when SO is about to be freed. */
  77. void (*clear_so) (struct so_list *so);
  78. /* Reset or free private data structures not associated with
  79. so_list entries. */
  80. void (*clear_solib) (void);
  81. /* Target dependent code to run after child process fork. */
  82. void (*solib_create_inferior_hook) (int from_tty);
  83. /* Construct a list of the currently loaded shared objects. This
  84. list does not include an entry for the main executable file.
  85. Note that we only gather information directly available from the
  86. inferior --- we don't examine any of the shared library files
  87. themselves. The declaration of `struct so_list' says which fields
  88. we provide values for. */
  89. struct so_list *(*current_sos) (void);
  90. /* Find, open, and read the symbols for the main executable. If
  91. FROM_TTY is non-zero, allow messages to be printed. */
  92. int (*open_symbol_file_object) (int from_ttyp);
  93. /* Determine if PC lies in the dynamic symbol resolution code of
  94. the run time loader. */
  95. int (*in_dynsym_resolve_code) (CORE_ADDR pc);
  96. /* Find and open shared library binary file. */
  97. gdb_bfd_ref_ptr (*bfd_open) (const char *pathname);
  98. /* Optional extra hook for finding and opening a solib.
  99. If TEMP_PATHNAME is non-NULL: If the file is successfully opened a
  100. pointer to a malloc'd and realpath'd copy of SONAME is stored there,
  101. otherwise NULL is stored there. */
  102. int (*find_and_open_solib) (const char *soname,
  103. unsigned o_flags,
  104. gdb::unique_xmalloc_ptr<char> *temp_pathname);
  105. /* Given two so_list objects, one from the GDB thread list
  106. and another from the list returned by current_sos, return 1
  107. if they represent the same library.
  108. Falls back to using strcmp on so_original_name field when set
  109. to NULL. */
  110. int (*same) (struct so_list *gdb, struct so_list *inferior);
  111. /* Return whether a region of memory must be kept in a core file
  112. for shared libraries loaded before "gcore" is used to be
  113. handled correctly when the core file is loaded. This only
  114. applies when the section would otherwise not be kept in the
  115. core file (in particular, for readonly sections). */
  116. int (*keep_data_in_core) (CORE_ADDR vaddr,
  117. unsigned long size);
  118. /* Enable or disable optional solib event breakpoints as
  119. appropriate. This should be called whenever
  120. stop_on_solib_events is changed. This pointer can be
  121. NULL, in which case no enabling or disabling is necessary
  122. for this target. */
  123. void (*update_breakpoints) (void);
  124. /* Target-specific processing of solib events that will be
  125. performed before solib_add is called. This pointer can be
  126. NULL, in which case no specific preprocessing is necessary
  127. for this target. */
  128. void (*handle_event) (void);
  129. };
  130. using so_list_range = next_range<so_list>;
  131. /* Free the memory associated with a (so_list *). */
  132. void free_so (struct so_list *so);
  133. /* A deleter that calls free_so. */
  134. struct so_deleter
  135. {
  136. void operator() (struct so_list *so) const
  137. {
  138. free_so (so);
  139. }
  140. };
  141. /* A unique pointer to a so_list. */
  142. typedef std::unique_ptr<so_list, so_deleter> so_list_up;
  143. /* Find main executable binary file. */
  144. extern gdb::unique_xmalloc_ptr<char> exec_file_find (const char *in_pathname,
  145. int *fd);
  146. /* Find shared library binary file. */
  147. extern gdb::unique_xmalloc_ptr<char> solib_find (const char *in_pathname,
  148. int *fd);
  149. /* Open BFD for shared library file. */
  150. extern gdb_bfd_ref_ptr solib_bfd_fopen (const char *pathname, int fd);
  151. /* Find solib binary file and open it. */
  152. extern gdb_bfd_ref_ptr solib_bfd_open (const char *in_pathname);
  153. /* FIXME: gdbarch needs to control this variable. */
  154. extern struct target_so_ops *current_target_so_ops;
  155. #endif