166e63ce3Schristos /* Shared library declarations for GDB, the GNU Debugger. 2*1424dfb3Schristos Copyright (C) 1990-2020 Free Software Foundation, Inc. 366e63ce3Schristos 466e63ce3Schristos This file is part of GDB. 566e63ce3Schristos 666e63ce3Schristos This program is free software; you can redistribute it and/or modify 766e63ce3Schristos it under the terms of the GNU General Public License as published by 866e63ce3Schristos the Free Software Foundation; either version 3 of the License, or 966e63ce3Schristos (at your option) any later version. 1066e63ce3Schristos 1166e63ce3Schristos This program is distributed in the hope that it will be useful, 1266e63ce3Schristos but WITHOUT ANY WARRANTY; without even the implied warranty of 1366e63ce3Schristos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1466e63ce3Schristos GNU General Public License for more details. 1566e63ce3Schristos 1666e63ce3Schristos You should have received a copy of the GNU General Public License 1766e63ce3Schristos along with this program. If not, see <http://www.gnu.org/licenses/>. */ 1866e63ce3Schristos 1966e63ce3Schristos #ifndef SOLIST_H 2066e63ce3Schristos #define SOLIST_H 2166e63ce3Schristos 2266e63ce3Schristos #define SO_NAME_MAX_PATH_SIZE 512 /* FIXME: Should be dynamic */ 2366e63ce3Schristos /* For domain_enum domain. */ 2466e63ce3Schristos #include "symtab.h" 251c468f90Schristos #include "gdb_bfd.h" 261c468f90Schristos 2707163879Schristos /* Base class for target-specific link map information. */ 2807163879Schristos 2907163879Schristos struct lm_info_base 3007163879Schristos { 3107163879Schristos }; 3266e63ce3Schristos 3366e63ce3Schristos struct so_list 3466e63ce3Schristos { 3566e63ce3Schristos /* The following fields of the structure come directly from the 3666e63ce3Schristos dynamic linker's tables in the inferior, and are initialized by 3766e63ce3Schristos current_sos. */ 3866e63ce3Schristos 3966e63ce3Schristos struct so_list *next; /* next structure in linked list */ 4066e63ce3Schristos 4166e63ce3Schristos /* A pointer to target specific link map information. Often this 4266e63ce3Schristos will be a copy of struct link_map from the user process, but 4366e63ce3Schristos it need not be; it can be any collection of data needed to 4466e63ce3Schristos traverse the dynamic linker's data structures. */ 4507163879Schristos lm_info_base *lm_info; 4666e63ce3Schristos 4766e63ce3Schristos /* Shared object file name, exactly as it appears in the 4866e63ce3Schristos inferior's link map. This may be a relative path, or something 4966e63ce3Schristos which needs to be looked up in LD_LIBRARY_PATH, etc. We use it 5066e63ce3Schristos to tell which entries in the inferior's dynamic linker's link 5166e63ce3Schristos map we've already loaded. */ 5266e63ce3Schristos char so_original_name[SO_NAME_MAX_PATH_SIZE]; 5366e63ce3Schristos 5466e63ce3Schristos /* Shared object file name, expanded to something GDB can open. */ 5566e63ce3Schristos char so_name[SO_NAME_MAX_PATH_SIZE]; 5666e63ce3Schristos 5766e63ce3Schristos /* Program space this shared library belongs to. */ 5866e63ce3Schristos struct program_space *pspace; 5966e63ce3Schristos 6066e63ce3Schristos /* The following fields of the structure are built from 6166e63ce3Schristos information gathered from the shared object file itself, and 6266e63ce3Schristos are set when we actually add it to our symbol tables. 6366e63ce3Schristos 6466e63ce3Schristos current_sos must initialize these fields to 0. */ 6566e63ce3Schristos 6666e63ce3Schristos bfd *abfd; 6766e63ce3Schristos char symbols_loaded; /* flag: symbols read in yet? */ 6866e63ce3Schristos 6966e63ce3Schristos /* objfile with symbols for a loaded library. Target memory is read from 7066e63ce3Schristos ABFD. OBJFILE may be NULL either before symbols have been loaded, if 7166e63ce3Schristos the file cannot be found or after the command "nosharedlibrary". */ 7266e63ce3Schristos struct objfile *objfile; 7366e63ce3Schristos 7466e63ce3Schristos struct target_section *sections; 7566e63ce3Schristos struct target_section *sections_end; 7666e63ce3Schristos 7766e63ce3Schristos /* Record the range of addresses belonging to this shared library. 7866e63ce3Schristos There may not be just one (e.g. if two segments are relocated 791c468f90Schristos differently). This is used for "info sharedlibrary" and 801c468f90Schristos the MI command "-file-list-shared-libraries". The latter has a format 811c468f90Schristos that supports outputting multiple segments once the related code 821c468f90Schristos supports them. */ 8366e63ce3Schristos CORE_ADDR addr_low, addr_high; 8466e63ce3Schristos }; 8566e63ce3Schristos 8666e63ce3Schristos struct target_so_ops 8766e63ce3Schristos { 8866e63ce3Schristos /* Adjust the section binding addresses by the base address at 8966e63ce3Schristos which the object was actually mapped. */ 9066e63ce3Schristos void (*relocate_section_addresses) (struct so_list *so, 9166e63ce3Schristos struct target_section *); 9266e63ce3Schristos 9366e63ce3Schristos /* Free the link map info and any other private data structures 9466e63ce3Schristos associated with a so_list entry. */ 9566e63ce3Schristos void (*free_so) (struct so_list *so); 9666e63ce3Schristos 977af5a897Schristos /* Reset private data structures associated with SO. 987af5a897Schristos This is called when SO is about to be reloaded. 997af5a897Schristos It is also called before free_so when SO is about to be freed. */ 1007af5a897Schristos void (*clear_so) (struct so_list *so); 1017af5a897Schristos 10266e63ce3Schristos /* Reset or free private data structures not associated with 10366e63ce3Schristos so_list entries. */ 10466e63ce3Schristos void (*clear_solib) (void); 10566e63ce3Schristos 10666e63ce3Schristos /* Target dependent code to run after child process fork. */ 10766e63ce3Schristos void (*solib_create_inferior_hook) (int from_tty); 10866e63ce3Schristos 10948596154Schristos /* Construct a list of the currently loaded shared objects. This 11048596154Schristos list does not include an entry for the main executable file. 11148596154Schristos 11248596154Schristos Note that we only gather information directly available from the 11348596154Schristos inferior --- we don't examine any of the shared library files 11448596154Schristos themselves. The declaration of `struct so_list' says which fields 11548596154Schristos we provide values for. */ 11666e63ce3Schristos struct so_list *(*current_sos) (void); 11766e63ce3Schristos 11848596154Schristos /* Find, open, and read the symbols for the main executable. If 11907163879Schristos FROM_TTY is non-zero, allow messages to be printed. */ 12007163879Schristos int (*open_symbol_file_object) (int from_ttyp); 12166e63ce3Schristos 12266e63ce3Schristos /* Determine if PC lies in the dynamic symbol resolution code of 12366e63ce3Schristos the run time loader. */ 12466e63ce3Schristos int (*in_dynsym_resolve_code) (CORE_ADDR pc); 12566e63ce3Schristos 12666e63ce3Schristos /* Find and open shared library binary file. */ 12707163879Schristos gdb_bfd_ref_ptr (*bfd_open) (const char *pathname); 12866e63ce3Schristos 1297af5a897Schristos /* Optional extra hook for finding and opening a solib. 1307af5a897Schristos If TEMP_PATHNAME is non-NULL: If the file is successfully opened a 1317af5a897Schristos pointer to a malloc'd and realpath'd copy of SONAME is stored there, 1327af5a897Schristos otherwise NULL is stored there. */ 1331c468f90Schristos int (*find_and_open_solib) (const char *soname, 13407163879Schristos unsigned o_flags, 13507163879Schristos gdb::unique_xmalloc_ptr<char> *temp_pathname); 13666e63ce3Schristos 13766e63ce3Schristos /* Given two so_list objects, one from the GDB thread list 13866e63ce3Schristos and another from the list returned by current_sos, return 1 13966e63ce3Schristos if they represent the same library. 14066e63ce3Schristos Falls back to using strcmp on so_original_name field when set 14166e63ce3Schristos to NULL. */ 14266e63ce3Schristos int (*same) (struct so_list *gdb, struct so_list *inferior); 14366e63ce3Schristos 14466e63ce3Schristos /* Return whether a region of memory must be kept in a core file 14566e63ce3Schristos for shared libraries loaded before "gcore" is used to be 14666e63ce3Schristos handled correctly when the core file is loaded. This only 14766e63ce3Schristos applies when the section would otherwise not be kept in the 14866e63ce3Schristos core file (in particular, for readonly sections). */ 14966e63ce3Schristos int (*keep_data_in_core) (CORE_ADDR vaddr, 15066e63ce3Schristos unsigned long size); 1517af5a897Schristos 1527af5a897Schristos /* Enable or disable optional solib event breakpoints as 1537af5a897Schristos appropriate. This should be called whenever 1547af5a897Schristos stop_on_solib_events is changed. This pointer can be 1557af5a897Schristos NULL, in which case no enabling or disabling is necessary 1567af5a897Schristos for this target. */ 1577af5a897Schristos void (*update_breakpoints) (void); 1587af5a897Schristos 1597af5a897Schristos /* Target-specific processing of solib events that will be 1607af5a897Schristos performed before solib_add is called. This pointer can be 1617af5a897Schristos NULL, in which case no specific preprocessing is necessary 1627af5a897Schristos for this target. */ 1637af5a897Schristos void (*handle_event) (void); 16466e63ce3Schristos }; 16566e63ce3Schristos 16666e63ce3Schristos /* Free the memory associated with a (so_list *). */ 16766e63ce3Schristos void free_so (struct so_list *so); 16866e63ce3Schristos 16907163879Schristos /* A deleter that calls free_so. */ 17007163879Schristos struct so_deleter 17107163879Schristos { operatorso_deleter17207163879Schristos void operator() (struct so_list *so) const 17307163879Schristos { 17407163879Schristos free_so (so); 17507163879Schristos } 17607163879Schristos }; 17707163879Schristos 17807163879Schristos /* A unique pointer to a so_list. */ 17907163879Schristos typedef std::unique_ptr<so_list, so_deleter> so_list_up; 18007163879Schristos 181ed6a76a9Schristos /* Find main executable binary file. */ 18207163879Schristos extern gdb::unique_xmalloc_ptr<char> exec_file_find (const char *in_pathname, 18307163879Schristos int *fd); 184ed6a76a9Schristos 18566e63ce3Schristos /* Find shared library binary file. */ 18607163879Schristos extern gdb::unique_xmalloc_ptr<char> solib_find (const char *in_pathname, 18707163879Schristos int *fd); 18866e63ce3Schristos 18966e63ce3Schristos /* Open BFD for shared library file. */ 19007163879Schristos extern gdb_bfd_ref_ptr solib_bfd_fopen (const char *pathname, int fd); 19166e63ce3Schristos 19266e63ce3Schristos /* Find solib binary file and open it. */ 19307163879Schristos extern gdb_bfd_ref_ptr solib_bfd_open (const char *in_pathname); 19466e63ce3Schristos 19566e63ce3Schristos /* FIXME: gdbarch needs to control this variable. */ 19666e63ce3Schristos extern struct target_so_ops *current_target_so_ops; 19766e63ce3Schristos 19866e63ce3Schristos #endif 199