- int success = 0;
-
-#ifndef SVR4_SHARED_LIBS
-
- int j;
- int in_debugger;
-
- /* Get link_dynamic structure */
-
- j = target_read_memory (debug_base, (char *) &dynamic_copy,
- sizeof (dynamic_copy));
- if (j)
- {
- /* unreadable */
- return (0);
- }
-
- /* Calc address of debugger interface structure */
-
- debug_addr = (CORE_ADDR) dynamic_copy.ldd;
-
- /* Calc address of `in_debugger' member of debugger interface structure */
-
- flag_addr = debug_addr + (CORE_ADDR) ((char *) &debug_copy.ldd_in_debugger -
- (char *) &debug_copy);
-
- /* Write a value of 1 to this member. */
-
- in_debugger = 1;
- write_memory (flag_addr, (char *) &in_debugger, sizeof (in_debugger));
- success = 1;
-
-#else /* SVR4_SHARED_LIBS */
-
-#ifdef BKPT_AT_SYMBOL
-
- struct minimal_symbol *msymbol;
- struct objfile *objfile;
- char **bkpt_namep;
- CORE_ADDR bkpt_addr;
- asection *interp_sect;
-
- /* First, remove all the solib event breakpoints. Their addresses
- may have changed since the last time we ran the program. */
- remove_solib_event_breakpoints ();
-
-#ifdef SVR4_SHARED_LIBS
- /* Find the .interp section; if not found, warn the user and drop
- into the old breakpoint at symbol code. */
- interp_sect = bfd_get_section_by_name (exec_bfd, ".interp");
- if (interp_sect)
- {
- unsigned int interp_sect_size;
- char *buf;
- CORE_ADDR load_addr;
- bfd *tmp_bfd;
- asection *lowest_sect;
-
- /* Read the contents of the .interp section into a local buffer;
- the contents specify the dynamic linker this program uses. */
- interp_sect_size = bfd_section_size (exec_bfd, interp_sect);
- buf = alloca (interp_sect_size);
- bfd_get_section_contents (exec_bfd, interp_sect,
- buf, 0, interp_sect_size);
-
- /* Now we need to figure out where the dynamic linker was
- loaded so that we can load its symbols and place a breakpoint
- in the dynamic linker itself.
-
- This address is stored on the stack. However, I've been unable
- to find any magic formula to find it for Solaris (appears to
- be trivial on Linux). Therefore, we have to try an alternate
- mechanism to find the dynamic linker's base address. */
- tmp_bfd = bfd_openr (buf, gnutarget);
- if (tmp_bfd == NULL)
- goto bkpt_at_symbol;
-
- /* Make sure the dynamic linker's really a useful object. */
- if (!bfd_check_format (tmp_bfd, bfd_object))
- {
- warning ("Unable to grok dynamic linker %s as an object file", buf);
- bfd_close (tmp_bfd);
- goto bkpt_at_symbol;
- }
-
- /* We find the dynamic linker's base address by examining the
- current pc (which point at the entry point for the dynamic
- linker) and subtracting the offset of the entry point. */
- load_addr = read_pc () - tmp_bfd->start_address;
-
- /* load_addr now has the base address of the dynamic linker;
- however, due to severe braindamage in syms_from_objfile
- we need to add the address of the .text section, or the
- lowest section of .text doesn't exist to work around the
- braindamage. Gross. */
- lowest_sect = bfd_get_section_by_name (tmp_bfd, ".text");
- if (lowest_sect == NULL)
- bfd_map_over_sections (tmp_bfd, find_lowest_section,
- (PTR) &lowest_sect);
-
- if (lowest_sect == NULL)
- {
- warning ("Unable to find base address for dynamic linker %s\n", buf);
- bfd_close (tmp_bfd);
- goto bkpt_at_symbol;
- }
-
- load_addr += bfd_section_vma (tmp_bfd, lowest_sect);
-
- /* We're done with the temporary bfd. */
- bfd_close (tmp_bfd);
-
- /* Now make GDB aware of the symbols in the dynamic linker. Some
- might complain about namespace pollution, but as a developer I've
- often wanted these symbols available from within the debugger. */
- objfile = symbol_file_add (buf, 0, load_addr, 0, 0, 1);
-
- /* Now try to set a breakpoint in the dynamic linker. */
- for (bkpt_namep = solib_break_names; *bkpt_namep != NULL; bkpt_namep++)
- {
- msymbol = lookup_minimal_symbol (*bkpt_namep, NULL, objfile);
- if ((msymbol != NULL) && (SYMBOL_VALUE_ADDRESS (msymbol) != 0))
- {
- create_solib_event_breakpoint (SYMBOL_VALUE_ADDRESS (msymbol));
- return 1;
- }
- }