xref: /netbsd/external/gpl3/gdb/dist/gdb/solist.h (revision 48596154)
166e63ce3Schristos /* Shared library declarations for GDB, the GNU Debugger.
2*48596154Schristos    Copyright (C) 1990-2013 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"
2566e63ce3Schristos 
2666e63ce3Schristos /* Forward declaration for target specific link map information.  This
2766e63ce3Schristos    struct is opaque to all but the target specific file.  */
2866e63ce3Schristos struct lm_info;
2966e63ce3Schristos 
3066e63ce3Schristos struct so_list
3166e63ce3Schristos   {
3266e63ce3Schristos     /* The following fields of the structure come directly from the
3366e63ce3Schristos        dynamic linker's tables in the inferior, and are initialized by
3466e63ce3Schristos        current_sos.  */
3566e63ce3Schristos 
3666e63ce3Schristos     struct so_list *next;	/* next structure in linked list */
3766e63ce3Schristos 
3866e63ce3Schristos     /* A pointer to target specific link map information.  Often this
3966e63ce3Schristos        will be a copy of struct link_map from the user process, but
4066e63ce3Schristos        it need not be; it can be any collection of data needed to
4166e63ce3Schristos        traverse the dynamic linker's data structures.  */
4266e63ce3Schristos     struct lm_info *lm_info;
4366e63ce3Schristos 
4466e63ce3Schristos     /* Shared object file name, exactly as it appears in the
4566e63ce3Schristos        inferior's link map.  This may be a relative path, or something
4666e63ce3Schristos        which needs to be looked up in LD_LIBRARY_PATH, etc.  We use it
4766e63ce3Schristos        to tell which entries in the inferior's dynamic linker's link
4866e63ce3Schristos        map we've already loaded.  */
4966e63ce3Schristos     char so_original_name[SO_NAME_MAX_PATH_SIZE];
5066e63ce3Schristos 
5166e63ce3Schristos     /* Shared object file name, expanded to something GDB can open.  */
5266e63ce3Schristos     char so_name[SO_NAME_MAX_PATH_SIZE];
5366e63ce3Schristos 
5466e63ce3Schristos     /* Program space this shared library belongs to.  */
5566e63ce3Schristos     struct program_space *pspace;
5666e63ce3Schristos 
5766e63ce3Schristos     /* The following fields of the structure are built from
5866e63ce3Schristos        information gathered from the shared object file itself, and
5966e63ce3Schristos        are set when we actually add it to our symbol tables.
6066e63ce3Schristos 
6166e63ce3Schristos        current_sos must initialize these fields to 0.  */
6266e63ce3Schristos 
6366e63ce3Schristos     bfd *abfd;
6466e63ce3Schristos     char symbols_loaded;	/* flag: symbols read in yet?  */
6566e63ce3Schristos 
6666e63ce3Schristos     /* objfile with symbols for a loaded library.  Target memory is read from
6766e63ce3Schristos        ABFD.  OBJFILE may be NULL either before symbols have been loaded, if
6866e63ce3Schristos        the file cannot be found or after the command "nosharedlibrary".  */
6966e63ce3Schristos     struct objfile *objfile;
7066e63ce3Schristos 
7166e63ce3Schristos     struct target_section *sections;
7266e63ce3Schristos     struct target_section *sections_end;
7366e63ce3Schristos 
7466e63ce3Schristos     /* Record the range of addresses belonging to this shared library.
7566e63ce3Schristos        There may not be just one (e.g. if two segments are relocated
7666e63ce3Schristos        differently); but this is only used for "info sharedlibrary".  */
7766e63ce3Schristos     CORE_ADDR addr_low, addr_high;
7866e63ce3Schristos   };
7966e63ce3Schristos 
8066e63ce3Schristos struct target_so_ops
8166e63ce3Schristos   {
8266e63ce3Schristos     /* Adjust the section binding addresses by the base address at
8366e63ce3Schristos        which the object was actually mapped.  */
8466e63ce3Schristos     void (*relocate_section_addresses) (struct so_list *so,
8566e63ce3Schristos                                         struct target_section *);
8666e63ce3Schristos 
8766e63ce3Schristos     /* Free the link map info and any other private data structures
8866e63ce3Schristos        associated with a so_list entry.  */
8966e63ce3Schristos     void (*free_so) (struct so_list *so);
9066e63ce3Schristos 
9166e63ce3Schristos     /* Reset or free private data structures not associated with
9266e63ce3Schristos        so_list entries.  */
9366e63ce3Schristos     void (*clear_solib) (void);
9466e63ce3Schristos 
9566e63ce3Schristos     /* Target dependent code to run after child process fork.  */
9666e63ce3Schristos     void (*solib_create_inferior_hook) (int from_tty);
9766e63ce3Schristos 
98*48596154Schristos     /* Do additional symbol handling, lookup, etc. after symbols for a
99*48596154Schristos        shared object have been loaded in the usual way.  This is
100*48596154Schristos        called to do any system specific symbol handling that might be
101*48596154Schristos        needed.  */
10266e63ce3Schristos     void (*special_symbol_handling) (void);
10366e63ce3Schristos 
104*48596154Schristos     /* Construct a list of the currently loaded shared objects.  This
105*48596154Schristos        list does not include an entry for the main executable file.
106*48596154Schristos 
107*48596154Schristos        Note that we only gather information directly available from the
108*48596154Schristos        inferior --- we don't examine any of the shared library files
109*48596154Schristos        themselves.  The declaration of `struct so_list' says which fields
110*48596154Schristos        we provide values for.  */
11166e63ce3Schristos     struct so_list *(*current_sos) (void);
11266e63ce3Schristos 
113*48596154Schristos     /* Find, open, and read the symbols for the main executable.  If
114*48596154Schristos        FROM_TTYP dereferences to a non-zero integer, allow messages to
115*48596154Schristos        be printed.  This parameter is a pointer rather than an int
116*48596154Schristos        because open_symbol_file_object is called via catch_errors and
117*48596154Schristos        catch_errors requires a pointer argument.  */
11866e63ce3Schristos     int (*open_symbol_file_object) (void *from_ttyp);
11966e63ce3Schristos 
12066e63ce3Schristos     /* Determine if PC lies in the dynamic symbol resolution code of
12166e63ce3Schristos        the run time loader.  */
12266e63ce3Schristos     int (*in_dynsym_resolve_code) (CORE_ADDR pc);
12366e63ce3Schristos 
12466e63ce3Schristos     /* Find and open shared library binary file.  */
12566e63ce3Schristos     bfd *(*bfd_open) (char *pathname);
12666e63ce3Schristos 
12766e63ce3Schristos     /* Extra hook for finding and opening a solib.
12866e63ce3Schristos        Convenience function for remote debuggers finding host libs.  */
12966e63ce3Schristos     int (*find_and_open_solib) (char *soname,
13066e63ce3Schristos         unsigned o_flags, char **temp_pathname);
13166e63ce3Schristos 
13266e63ce3Schristos     /* Hook for looking up global symbols in a library-specific way.  */
13366e63ce3Schristos     struct symbol * (*lookup_lib_global_symbol) (const struct objfile *objfile,
13466e63ce3Schristos 						 const char *name,
13566e63ce3Schristos 						 const domain_enum domain);
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);
15166e63ce3Schristos   };
15266e63ce3Schristos 
15366e63ce3Schristos /* Free the memory associated with a (so_list *).  */
15466e63ce3Schristos void free_so (struct so_list *so);
15566e63ce3Schristos 
15666e63ce3Schristos /* Return address of first so_list entry in master shared object list.  */
15766e63ce3Schristos struct so_list *master_so_list (void);
15866e63ce3Schristos 
15966e63ce3Schristos /* Find shared library binary file.  */
16066e63ce3Schristos extern char *solib_find (char *in_pathname, int *fd);
16166e63ce3Schristos 
16266e63ce3Schristos /* Open BFD for shared library file.  */
16366e63ce3Schristos extern bfd *solib_bfd_fopen (char *pathname, int fd);
16466e63ce3Schristos 
16566e63ce3Schristos /* Find solib binary file and open it.  */
16666e63ce3Schristos extern bfd *solib_bfd_open (char *in_pathname);
16766e63ce3Schristos 
16866e63ce3Schristos /* FIXME: gdbarch needs to control this variable.  */
16966e63ce3Schristos extern struct target_so_ops *current_target_so_ops;
17066e63ce3Schristos 
17166e63ce3Schristos /* Handler for library-specific global symbol lookup in solib.c.  */
17266e63ce3Schristos struct symbol *solib_global_lookup (const struct objfile *objfile,
17366e63ce3Schristos 				    const char *name,
17466e63ce3Schristos 				    const domain_enum domain);
17566e63ce3Schristos 
17666e63ce3Schristos #endif
177