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
;
86 unsigned int dld_flags
;
89 /* If we're debugging a core file, or have attached to a running
90 process, then som_solib_create_inferior_hook will not have been
93 We need to examine __dld_flags to determine if the shared library
94 list is valid, and to determine if the libraries have been privately
96 msymbol
= lookup_minimal_symbol ("__dld_flags", (struct objfile
*) NULL
);
99 error ("Unable to find __dld_flags symbol in object file.\n");
103 addr
= SYMBOL_VALUE_ADDRESS (msymbol
);
104 /* Read the current contents. */
105 status
= target_read_memory (addr
, buf
, 4);
108 error ("Unable to read __dld_flags\n");
111 dld_flags
= extract_unsigned_integer (buf
, 4);
113 /* __dld_list may not be valid. If it's not valid tell the user. */
114 if ((dld_flags
& 4) == 0)
116 error ("__dld_list is not valid according to __dld_flags.\n");
120 /* If the libraries were not mapped private, warn the user. */
121 if ((dld_flags
& 1) == 0)
122 warning ("The shared libraries were not privately mapped;\nsetting a breakpoint in a shared library will not work.\n");
124 msymbol
= lookup_minimal_symbol ("__dld_list", (struct objfile
*) NULL
);
127 /* Older crt0.o files (hpux8) don't have __dld_list as a symbol,
128 but the data is still available if you know where to look. */
129 msymbol
= lookup_minimal_symbol ("__dld_flags", (struct objfile
*)NULL
);
132 error ("Unable to find dynamic library list.\n");
135 addr
= SYMBOL_VALUE_ADDRESS (msymbol
) - 8;
138 addr
= SYMBOL_VALUE_ADDRESS (msymbol
);
140 status
= target_read_memory (addr
, buf
, 4);
143 error ("Unable to find dynamic library list.\n");
147 addr
= extract_unsigned_integer (buf
, 4);
149 /* If addr is zero, then we're using an old dynamic loader which
150 doesn't maintain __dld_list. We'll have to use a completely
151 different approach to get shared library information. */
155 /* Using the information in __dld_list is the preferred method
156 to get at shared library information. It doesn't depend on
157 any functions in /usr/lib/end.o and has a chance of working
158 with hpux10 when it is released. */
159 status
= target_read_memory (addr
, buf
, 4);
162 error ("Unable to find dynamic library list.\n");
166 /* addr now holds the address of the first entry in the dynamic
168 addr
= extract_unsigned_integer (buf
, 4);
170 /* Now that we have a pointer to the dynamic library list, walk
171 through it and add the symbols for each library.
173 Skip the first entry since it's our executable. */
174 status
= target_read_memory (addr
+ 36, buf
, 4);
177 error ("Error while reading dynamic library list.\n");
180 addr
= extract_unsigned_integer (buf
, 4);
184 CORE_ADDR name_addr
, text_addr
;
185 unsigned int name_len
;
190 /* Get a pointer to the name of this library. */
191 status
= target_read_memory (addr
, buf
, 4);
194 error ("Error while reading dynamic library list.\n");
197 name_addr
= extract_unsigned_integer (buf
, 4);
201 target_read_memory (name_addr
+ name_len
, buf
, 1);
204 error ("Error while reading dynamic library list.\n");
211 name
= alloca (name_len
);
212 status
= target_read_memory (name_addr
, name
, name_len
);
215 error ("Error while reading dynamic library list.\n");
218 name
= obsavestring (name
, name_len
- 1,
219 &symfile_objfile
->symbol_obstack
);
221 status
= target_read_memory (addr
+ 8, buf
, 4);
224 error ("Error while reading dynamic library list.\n");
227 text_addr
= extract_unsigned_integer (buf
, 4);
229 /* OK, we've got everything we need. Tell GDB about it. */
230 symbol_file_add (name
, from_tty
, text_addr
, 0, 0, 0);
232 /* Get address of the next record. */
233 status
= target_read_memory (addr
+ 36, buf
, 4);
236 error ("Error while reading dynamic library list.\n");
239 addr
= extract_unsigned_integer (buf
, 4);
242 /* Getting new symbols may change our opinion about what is
244 reinit_frame_cache ();
248 error ("Debugging dynamic executables loaded via the hpux8 dld.sl is not supported.\n");
252 /* This hook gets called just before the first instruction in the
253 inferior process is executed.
255 This is our opportunity to set magic flags in the inferior so
256 that GDB can be notified when a shared library is mapped in and
257 to tell the dynamic linker that a private copy of the library is
258 needed (so GDB can set breakpoints in the library).
260 __dld_flags is the location of the magic flags; as of this implementation
261 there are 3 flags of interest:
263 bit 0 when set indicates that private copies of the libraries are needed
264 bit 1 when set indicates that the callback hook routine is valid
265 bit 2 when set indicates that the dynamic linker should maintain the
266 __dld_list structure when loading/unloading libraries.
268 Note that shared libraries are not mapped in at this time, so we have
269 run the inferior until the libraries are mapped in. Typically this
270 means running until the "_start" is called. */
273 som_solib_create_inferior_hook()
275 struct minimal_symbol
*msymbol
;
276 asection
*shlib_info
;
277 unsigned int dld_flags
, status
;
278 char shadow_contents
[BREAKPOINT_MAX
], buf
[4];
281 /* First see if the objfile was dynamically linked. */
282 shlib_info
= bfd_get_section_by_name (symfile_objfile
->obfd
, "$SHLIB_INFO$");
286 /* It's got a $SHLIB_INFO$ section, make sure it's not empty. */
287 if (bfd_section_size (symfile_objfile
->obfd
, shlib_info
) == 0)
290 /* Get the address of __dld_flags, if no such symbol exists, then we can
291 not debug the shared code. */
292 msymbol
= lookup_minimal_symbol ("__dld_flags", (struct objfile
*) NULL
);
295 error ("Unable to find __dld_flags symbol in object file.\n");
299 anaddr
= SYMBOL_VALUE_ADDRESS (msymbol
);
300 /* Read the current contents. */
301 status
= target_read_memory (anaddr
, buf
, 4);
304 error ("Unable to read __dld_flags\n");
307 dld_flags
= extract_unsigned_integer (buf
, 4);
309 /* Turn on the flags we care about. */
311 store_unsigned_integer (buf
, 4, dld_flags
);
312 status
= target_write_memory (anaddr
, buf
, 4);
315 error ("Unable to write __dld_flags\n");
319 /* Now find the address of _start and set a breakpoint there. */
320 msymbol
= lookup_minimal_symbol ("_start", symfile_objfile
);
323 error ("Unable to find _start symbol in object file.\n");
327 anaddr
= SYMBOL_VALUE_ADDRESS (msymbol
);
328 if (target_insert_breakpoint (anaddr
, shadow_contents
))
330 error ("Unable to set breakpoint at _start.\n");
334 /* Start the process again and wait for it to hit our breakpoint. */
335 clear_proceed_status ();
336 stop_soon_quietly
= 1;
337 stop_signal
= TARGET_SIGNAL_0
;
340 target_resume (-1, 0, stop_signal
);
341 wait_for_inferior ();
343 while (stop_signal
!= TARGET_SIGNAL_TRAP
);
344 stop_soon_quietly
= 0;
346 /* All the libraries should be mapped in now. Remove our breakpoint and
347 read in the symbol tables from the shared libraries. */
348 if (target_remove_breakpoint (anaddr
, shadow_contents
))
350 error ("Unable to remove breakpoint at _start.\n");
354 som_solib_add ((char *) 0, 0, (struct target_ops
*) 0);