67d12ab8fb425b9196877703212e333eed37ef69
1 /* Handle HP SOM shared libraries for GDB, the GNU Debugger.
2 Copyright 1993 Free Software Foundation, Inc.
4 This file is part of GDB.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 Written by the Center for Software Science at the Univerity of Utah
21 and by Cygnus Support. */
32 #include "breakpoint.h"
37 /* We don't currently use this structure, but it isn't documented anywhere,
38 and we'll likely need it in som_solib_add as more shared library support
41 struct som_solib_mapped_entry
43 /* The name of the library. */
46 /* Version of this structure (it is expected to change again in hpux10. */
47 unsigned char struct_version
;
49 /* Binding mode for this library. */
50 unsigned char bind_mode
;
52 /* Version of this library. */
53 short library_version
;
55 /* Start of text address, link-time text location, end of text address. */
57 CORE_ADDR text_link_addr
;
60 /* Start of data, start of bss and end of data. */
65 /* Value of linkage pointer (%r19). */
69 struct som_solib_mapped_entry
*next
;
71 /* There are other fields, but I don't have information as to what is
75 /* Add symbols from shared libraries into the symtab list. */
78 som_solib_add (arg_string
, from_tty
, target
)
81 struct target_ops
*target
;
83 struct minimal_symbol
*msymbol
;
88 msymbol
= lookup_minimal_symbol ("__dld_list", (struct objfile
*) NULL
);
91 /* Older crt0.o files (hpux8) don't have __dld_list as a symbol,
92 but the data is still available if you know where to look. */
93 msymbol
= lookup_minimal_symbol ("__dld_flags", (struct objfile
*)NULL
);
96 error ("Unable to find dynamic library list.\n");
99 addr
= SYMBOL_VALUE_ADDRESS (msymbol
) - 8;
102 addr
= SYMBOL_VALUE_ADDRESS (msymbol
);
104 status
= target_read_memory (addr
, buf
, 4);
107 error ("Unable to find dynamic library list.\n");
111 addr
= extract_unsigned_integer (buf
, 4);
113 /* If addr is zero, then we're using an old dynamic loader which
114 doesn't maintain __dld_list. We'll have to use a completely
115 different approach to get shared library information. */
119 /* Using the information in __dld_list is the preferred method
120 to get at shared library information. It doesn't depend on
121 any functions in /usr/lib/end.o and has a chance of working
122 with hpux10 when it is released. */
123 status
= target_read_memory (addr
, buf
, 4);
126 error ("Unable to find dynamic library list.\n");
130 /* addr now holds the address of the first entry in the dynamic
132 addr
= extract_unsigned_integer (buf
, 4);
134 /* Now that we have a pointer to the dynamic library list, walk
135 through it and add the symbols for each library.
137 Skip the first entry since it's our executable. */
138 status
= target_read_memory (addr
+ 36, buf
, 4);
141 error ("Error while reading dynamic library list.\n");
144 addr
= extract_unsigned_integer (buf
, 4);
148 CORE_ADDR name_addr
, text_addr
;
149 unsigned int name_len
;
154 /* Get a pointer to the name of this library. */
155 status
= target_read_memory (addr
, buf
, 4);
158 error ("Error while reading dynamic library list.\n");
161 name_addr
= extract_unsigned_integer (buf
, 4);
165 target_read_memory (name_addr
+ name_len
, buf
, 1);
168 error ("Error while reading dynamic library list.\n");
175 name
= alloca (name_len
);
176 status
= target_read_memory (name_addr
, name
, name_len
);
179 error ("Error while reading dynamic library list.\n");
182 name
= obsavestring (name
, name_len
- 1,
183 &symfile_objfile
->symbol_obstack
);
185 status
= target_read_memory (addr
+ 8, buf
, 4);
188 error ("Error while reading dynamic library list.\n");
191 text_addr
= extract_unsigned_integer (buf
, 4);
193 /* OK, we've got everything we need. Tell GDB about it. */
194 symbol_file_add (name
, from_tty
, text_addr
, 0, 0, 0);
196 /* Get address of the next record. */
197 status
= target_read_memory (addr
+ 36, buf
, 4);
200 error ("Error while reading dynamic library list.\n");
203 addr
= extract_unsigned_integer (buf
, 4);
206 /* Getting new symbols may change our opinion about what is
208 reinit_frame_cache ();
212 error ("Debugging dynamic executables loaded via the hpux8 dld.sl is not supported.\n");
216 /* This hook gets called just before the first instruction in the
217 inferior process is executed.
219 This is our opportunity to set magic flags in the inferior so
220 that GDB can be notified when a shared library is mapped in and
221 to tell the dynamic linker that a private copy of the library is
222 needed (so GDB can set breakpoints in the library).
224 __dld_flags is the location of the magic flags; as of this implementation
225 there are 3 flags of interest:
227 bit 0 when set indicates that private copies of the libraries are needed
228 bit 1 when set indicates that the callback hook routine is valid
229 bit 2 when set indicates that the dynamic linker should maintain the
230 __dld_list structure when loading/unloading libraries.
232 Note that shared libraries are not mapped in at this time, so we have
233 run the inferior until the libraries are mapped in. Typically this
234 means running until the "_start" is called. */
237 som_solib_create_inferior_hook()
239 struct minimal_symbol
*msymbol
;
240 asection
*shlib_info
;
241 unsigned int dld_flags
, status
;
242 char shadow_contents
[BREAKPOINT_MAX
], buf
[4];
245 /* First see if the objfile was dynamically linked. */
246 shlib_info
= bfd_get_section_by_name (symfile_objfile
->obfd
, "$SHLIB_INFO$");
250 /* It's got a $SHLIB_INFO$ section, make sure it's not empty. */
251 if (bfd_section_size (symfile_objfile
->obfd
, shlib_info
) == 0)
254 /* Get the address of __dld_flags, if no such symbol exists, then we can
255 not debug the shared code. */
256 msymbol
= lookup_minimal_symbol ("__dld_flags", (struct objfile
*) NULL
);
259 error ("Unable to find __dld_flags symbol in object file.\n");
263 anaddr
= SYMBOL_VALUE_ADDRESS (msymbol
);
264 /* Read the current contents. */
265 status
= target_read_memory (anaddr
, buf
, 4);
268 error ("Unable to read __dld_flags\n");
271 dld_flags
= extract_unsigned_integer (buf
, 4);
273 /* Turn on the flags we care about. */
275 store_unsigned_integer (buf
, 4, dld_flags
);
276 status
= target_write_memory (anaddr
, buf
, 4);
279 error ("Unable to write __dld_flags\n");
283 /* Now find the address of _start and set a breakpoint there. */
284 msymbol
= lookup_minimal_symbol ("_start", symfile_objfile
);
287 error ("Unable to find _start symbol in object file.\n");
291 anaddr
= SYMBOL_VALUE_ADDRESS (msymbol
);
292 if (target_insert_breakpoint (anaddr
, shadow_contents
))
294 error ("Unable to set breakpoint at _start.\n");
298 /* Start the process again and wait for it to hit our breakpoint. */
299 clear_proceed_status ();
300 stop_soon_quietly
= 1;
301 stop_signal
= TARGET_SIGNAL_0
;
304 target_resume (-1, 0, stop_signal
);
305 wait_for_inferior ();
307 while (stop_signal
!= TARGET_SIGNAL_TRAP
);
308 stop_soon_quietly
= 0;
310 /* All the libraries should be mapped in now. Remove our breakpoint and
311 read in the symbol tables from the shared libraries. */
312 if (target_remove_breakpoint (anaddr
, shadow_contents
))
314 error ("Unable to remove breakpoint at _start.\n");
318 som_solib_add ((char *) 0, 0, (struct target_ops
*) 0);
This page took 0.036042 seconds and 4 git commands to generate.