• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

GNU Binutils with patches for OS216


Commit MetaInfo

Revisionbd8469f2d9317347e8b52dde987d672baf98454c (tree)
Time2004-03-24 13:10:01
AuthorElena Zannoni <ezannoni@kwik...>
CommiterElena Zannoni

Log Message

2004-03-23 Elena Zannoni <ezannoni@redhat.com>

        • solib-svr4.c (svr4_solib_create_inferior_hook): Disable
          breakpoints at startup.
          (elf_locate_base): Find out where the entry point for the program
          is, using the auxv vector, if possible. Compute the address of
          .dynamic using it.
          (svr4_current_sos): Don't ignore the first entry if we have PIE,
          it's our main program. Delete code that was skipping over the
          solib entry for main executable.
        • solist.h (struct so_list): Add fields main and main_relocated.
          (add_to_target_sections): Export.
        • solib.c (symbol_add_stub): Handle main executable in shared
          library list. Ignore it if it has been relocated already. Add it
          as the main symbol file, otherwise.
        • infrun.c (handle_inferior_event): Re-enable startup breakpoints.
        • solib-svr4.c (elf_locate_base, first_link_map_member)
          svr4_current_sos, enable_break): Add debugging output.
        • solist.h (debug_solib): Export.
        • solib.c (debug_solib): New variable to enable debugging output.
          (symbol_add_stub, update_solib_list, update_solib_list)
          (add_to_target_sections): Add debugging output.
          (_initialize_solib): Add new comand to enable printing of
          debugging output.
          (add_to_target_sections): New function. Factored out from
          update_solib_list.
          (update_solib_list): Call add_to_target_sections.
        • varobj.h (varobj_refresh): New prototype.
        • varobj.c (varobj_refresh): New function.
        • symfile.c (reread_symbols): Make sure that we recompute the
          entry point for the program.
          (symbol_file_clear): Clear the solibs as well, if we change symbol
          files.
          (clear_symtab_users): Refresh the varobjs that depend on the symtabs
          we are clearing.
        • objfiles.c (entry_point_address): Rewrite, to fetch entry point
          from auxv vector, if possible.
          Add include of elf/common.h.
        • breakpoint.h (enum bptype): Add bp type bp_startup_disabled.
          (re_enable_breakpoints_at_startup)
          (disable_breakpoints_at_startup): Add prototypes
        • breakpoint.c (re_enable_breakpoints_at_startup)
          (disable_breakpoints_at_startup): New functions.
          (describe_other_breakpoints, delete_breakpoint)
          (breakpoint_re_set_one): Handle new bp type.
        • auxv.h (target_auxv_parse, target_auxv_search): Update.
        • auxv.c (target_auxv_parse, target_auxv_search)
          (fprint_target_auxv): Use ULONGEST instead of CORE_ADDR for
        1. Change variable name to at_type.

Change Summary

Incremental Difference

--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,59 @@
1+2004-03-23 Elena Zannoni <ezannoni@redhat.com>
2+
3+ * solib-svr4.c (svr4_solib_create_inferior_hook): Disable
4+ breakpoints at startup.
5+ (elf_locate_base): Find out where the entry point for the program
6+ is, using the auxv vector, if possible. Compute the address of
7+ .dynamic using it.
8+ (svr4_current_sos): Don't ignore the first entry if we have PIE,
9+ it's our main program. Delete code that was skipping over the
10+ solib entry for main executable.
11+
12+ * solist.h (struct so_list): Add fields main and main_relocated.
13+ (add_to_target_sections): Export.
14+
15+ * solib.c (symbol_add_stub): Handle main executable in shared
16+ library list. Ignore it if it has been relocated already. Add it
17+ as the main symbol file, otherwise.
18+
19+ * infrun.c (handle_inferior_event): Re-enable startup breakpoints.
20+ * solib-svr4.c (elf_locate_base, first_link_map_member)
21+ svr4_current_sos, enable_break): Add debugging output.
22+
23+ * solist.h (debug_solib): Export.
24+
25+ * solib.c (debug_solib): New variable to enable debugging output.
26+ (symbol_add_stub, update_solib_list, update_solib_list)
27+ (add_to_target_sections): Add debugging output.
28+ (_initialize_solib): Add new comand to enable printing of
29+ debugging output.
30+ (add_to_target_sections): New function. Factored out from
31+ update_solib_list.
32+ (update_solib_list): Call add_to_target_sections.
33+
34+ * varobj.h (varobj_refresh): New prototype.
35+ * varobj.c (varobj_refresh): New function.
36+ * symfile.c (reread_symbols): Make sure that we recompute the
37+ entry point for the program.
38+ (symbol_file_clear): Clear the solibs as well, if we change symbol
39+ files.
40+ (clear_symtab_users): Refresh the varobjs that depend on the symtabs
41+ we are clearing.
42+ * objfiles.c (entry_point_address): Rewrite, to fetch entry point
43+ from auxv vector, if possible.
44+ Add include of elf/common.h.
45+ * breakpoint.h (enum bptype): Add bp type bp_startup_disabled.
46+ (re_enable_breakpoints_at_startup)
47+ (disable_breakpoints_at_startup): Add prototypes
48+ * breakpoint.c (re_enable_breakpoints_at_startup)
49+ (disable_breakpoints_at_startup): New functions.
50+ (describe_other_breakpoints, delete_breakpoint)
51+ (breakpoint_re_set_one): Handle new bp type.
52+ * auxv.h (target_auxv_parse, target_auxv_search): Update.
53+ * auxv.c (target_auxv_parse, target_auxv_search)
54+ (fprint_target_auxv): Use ULONGEST instead of CORE_ADDR for
55+ variable. Change variable name to at_type.
56+
157 2004-03-23 Andrew Cagney <cagney@redhat.com>
258
359 * MAINTAINERS (Past Maintainers): Add Mark Salter and Fernando
--- a/gdb/Makefile.in
+++ b/gdb/Makefile.in
@@ -2412,7 +2412,7 @@ symfile.o: symfile.c $(defs_h) $(bfdlink_h) $(symtab_h) $(gdbtypes_h) \
24122412 $(complaints_h) $(demangle_h) $(inferior_h) $(filenames_h) \
24132413 $(gdb_stabs_h) $(gdb_obstack_h) $(completer_h) $(bcache_h) \
24142414 $(hashtab_h) $(readline_h) $(gdb_assert_h) $(block_h) \
2415- $(gdb_string_h) $(gdb_stat_h)
2415+ $(gdb_string_h) $(gdb_stat_h) $(varobj_h)
24162416 symmisc.o: symmisc.c $(defs_h) $(symtab_h) $(gdbtypes_h) $(bfd_h) \
24172417 $(symfile_h) $(objfiles_h) $(breakpoint_h) $(command_h) \
24182418 $(gdb_obstack_h) $(language_h) $(bcache_h) $(block_h) $(gdb_regex_h) \
--- a/gdb/auxv.c
+++ b/gdb/auxv.c
@@ -119,7 +119,7 @@ target_auxv_read (struct target_ops *ops, char **data)
119119 Return 1 if an entry was read into *TYPEP and *VALP. */
120120 int
121121 target_auxv_parse (struct target_ops *ops, char **readptr, char *endptr,
122- CORE_ADDR *typep, CORE_ADDR *valp)
122+ ULONGEST *typep, CORE_ADDR *valp)
123123 {
124124 const int sizeof_auxv_field = TYPE_LENGTH (builtin_type_void_data_ptr);
125125 char *ptr = *readptr;
@@ -144,9 +144,10 @@ target_auxv_parse (struct target_ops *ops, char **readptr, char *endptr,
144144 an error getting the information. On success, return 1 after
145145 storing the entry's value field in *VALP. */
146146 int
147-target_auxv_search (struct target_ops *ops, CORE_ADDR match, CORE_ADDR *valp)
147+target_auxv_search (struct target_ops *ops, ULONGEST match, CORE_ADDR *valp)
148148 {
149- CORE_ADDR type, val;
149+ CORE_ADDR val;
150+ ULONGEST at_type;
150151 char *data;
151152 int n = target_auxv_read (ops, &data);
152153 char *ptr = data;
@@ -156,10 +157,10 @@ target_auxv_search (struct target_ops *ops, CORE_ADDR match, CORE_ADDR *valp)
156157 return n;
157158
158159 while (1)
159- switch (target_auxv_parse (ops, &ptr, data + n, &type, &val))
160+ switch (target_auxv_parse (ops, &ptr, data + n, &at_type, &val))
160161 {
161162 case 1: /* Here's an entry, check it. */
162- if (type == match)
163+ if (at_type == match)
163164 {
164165 xfree (data);
165166 *valp = val;
@@ -182,7 +183,8 @@ target_auxv_search (struct target_ops *ops, CORE_ADDR match, CORE_ADDR *valp)
182183 int
183184 fprint_target_auxv (struct ui_file *file, struct target_ops *ops)
184185 {
185- CORE_ADDR type, val;
186+ CORE_ADDR val;
187+ ULONGEST at_type;
186188 char *data;
187189 int len = target_auxv_read (ops, &data);
188190 char *ptr = data;
@@ -191,14 +193,14 @@ fprint_target_auxv (struct ui_file *file, struct target_ops *ops)
191193 if (len <= 0)
192194 return len;
193195
194- while (target_auxv_parse (ops, &ptr, data + len, &type, &val) > 0)
196+ while (target_auxv_parse (ops, &ptr, data + len, &at_type, &val) > 0)
195197 {
196198 extern int addressprint;
197199 const char *name = "???";
198200 const char *description = "";
199201 enum { dec, hex, str } flavor = hex;
200202
201- switch (type)
203+ switch (at_type)
202204 {
203205 #define TAG(tag, text, kind) \
204206 case tag: name = #tag; description = text; flavor = kind; break
@@ -249,7 +251,7 @@ fprint_target_auxv (struct ui_file *file, struct target_ops *ops)
249251 }
250252
251253 fprintf_filtered (file, "%-4s %-20s %-30s ",
252- paddr_d (type), name, description);
254+ paddr_d (at_type), name, description);
253255 switch (flavor)
254256 {
255257 case dec:
--- a/gdb/auxv.h
+++ b/gdb/auxv.h
@@ -43,14 +43,14 @@ extern LONGEST target_auxv_read (struct target_ops *ops, char **data);
4343 Return 1 if an entry was read into *TYPEP and *VALP. */
4444 extern int target_auxv_parse (struct target_ops *ops,
4545 char **readptr, char *endptr,
46- CORE_ADDR *typep, CORE_ADDR *valp);
46+ ULONGEST *typep, CORE_ADDR *valp);
4747
4848 /* Extract the auxiliary vector entry with a_type matching MATCH.
4949 Return zero if no such entry was found, or -1 if there was
5050 an error getting the information. On success, return 1 after
5151 storing the entry's value field in *VALP. */
5252 extern int target_auxv_search (struct target_ops *ops,
53- CORE_ADDR match, CORE_ADDR *valp);
53+ ULONGEST match, CORE_ADDR *valp);
5454
5555 /* Print the contents of the target's AUXV on the specified file. */
5656 extern int fprint_target_auxv (struct ui_file *file, struct target_ops *ops);
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -3793,6 +3793,7 @@ describe_other_breakpoints (CORE_ADDR pc, asection *section)
37933793 b->number,
37943794 ((b->enable_state == bp_disabled ||
37953795 b->enable_state == bp_shlib_disabled ||
3796+ b->enable_state == bp_startup_disabled ||
37963797 b->enable_state == bp_call_disabled)
37973798 ? " (disabled)"
37983799 : b->enable_state == bp_permanent
@@ -4427,6 +4428,62 @@ re_enable_breakpoints_in_shlibs (void)
44274428
44284429 #endif
44294430
4431+void
4432+disable_breakpoints_at_startup (int silent)
4433+{
4434+ struct breakpoint *b;
4435+ int disabled_startup_breaks = 0;
4436+
4437+ if (bfd_get_start_address (exec_bfd) != entry_point_address ())
4438+ {
4439+ ALL_BREAKPOINTS (b)
4440+ {
4441+ if (((b->type == bp_breakpoint) ||
4442+ (b->type == bp_hardware_breakpoint)) &&
4443+ b->enable_state == bp_enabled &&
4444+ !b->loc->duplicate)
4445+ {
4446+ b->enable_state = bp_startup_disabled;
4447+ if (!silent)
4448+ {
4449+ if (!disabled_startup_breaks)
4450+ {
4451+ target_terminal_ours_for_output ();
4452+ warning ("Temporarily disabling breakpoints:");
4453+ }
4454+ disabled_startup_breaks = 1;
4455+ warning ("breakpoint #%d addr 0x%s", b->number, paddr_nz(b->loc->address));
4456+ }
4457+ }
4458+ }
4459+ }
4460+}
4461+
4462+/* Try to reenable any breakpoints after startup. */
4463+void
4464+re_enable_breakpoints_at_startup (void)
4465+{
4466+ struct breakpoint *b;
4467+
4468+ if (bfd_get_start_address (exec_bfd) != entry_point_address ())
4469+ {
4470+ ALL_BREAKPOINTS (b)
4471+ if (b->enable_state == bp_startup_disabled)
4472+ {
4473+ char buf[1];
4474+
4475+ /* Do not reenable the breakpoint if the shared library
4476+ is still not mapped in. */
4477+ if (target_read_memory (b->loc->address, buf, 1) == 0)
4478+ {
4479+ /*printf ("enabling breakpoint at 0x%s\n", paddr_nz(b->loc->address));*/
4480+ b->enable_state = bp_enabled;
4481+ }
4482+ }
4483+ }
4484+}
4485+
4486+
44304487 static void
44314488 solib_load_unload_1 (char *hookname, int tempflag, char *dll_pathname,
44324489 char *cond_string, enum bptype bp_kind)
@@ -6940,6 +6997,7 @@ delete_breakpoint (struct breakpoint *bpt)
69406997 && !b->loc->duplicate
69416998 && b->enable_state != bp_disabled
69426999 && b->enable_state != bp_shlib_disabled
7000+ && b->enable_state != bp_startup_disabled
69437001 && !b->pending
69447002 && b->enable_state != bp_call_disabled)
69457003 {
@@ -7151,7 +7209,8 @@ breakpoint_re_set_one (void *bint)
71517209 break;
71527210
71537211 save_enable = b->enable_state;
7154- if (b->enable_state != bp_shlib_disabled)
7212+ if (b->enable_state != bp_shlib_disabled
7213+ || b->enable_state != bp_shlib_disabled)
71557214 b->enable_state = bp_disabled;
71567215
71577216 set_language (b->language);
--- a/gdb/breakpoint.h
+++ b/gdb/breakpoint.h
@@ -159,6 +159,7 @@ enum enable_state
159159 automatically enabled and reset when the call
160160 "lands" (either completes, or stops at another
161161 eventpoint). */
162+ bp_startup_disabled,
162163 bp_permanent /* There is a breakpoint instruction hard-wired into
163164 the target's code. Don't try to write another
164165 breakpoint instruction on top of it, or restore
@@ -771,8 +772,12 @@ extern void remove_thread_event_breakpoints (void);
771772
772773 extern void disable_breakpoints_in_shlibs (int silent);
773774
775+extern void disable_breakpoints_at_startup (int silent);
776+
774777 extern void re_enable_breakpoints_in_shlibs (void);
775778
779+void re_enable_breakpoints_at_startup (void);
780+
776781 extern void create_solib_load_event_breakpoint (char *, int, char *, char *);
777782
778783 extern void create_solib_unload_event_breakpoint (char *, int,
--- a/gdb/infrun.c
+++ b/gdb/infrun.c
@@ -2355,6 +2355,11 @@ process_event_stop_test:
23552355 code segments in shared libraries might be mapped in now. */
23562356 re_enable_breakpoints_in_shlibs ();
23572357
2358+ /* For PIE executables, we dont really know where the
2359+ breakpoints are going to be until we start up the
2360+ inferior. */
2361+ re_enable_breakpoints_at_startup ();
2362+
23582363 /* If requested, stop when the dynamic linker notifies
23592364 gdb of events. This allows the user to get control
23602365 and place breakpoints in initializer routines for
--- a/gdb/objfiles.c
+++ b/gdb/objfiles.c
@@ -46,6 +46,8 @@
4646 #include "block.h"
4747 #include "dictionary.h"
4848
49+#include "elf/common.h"
50+
4951 /* Prototypes for local functions */
5052
5153 static void objfile_alloc_data (struct objfile *objfile);
@@ -263,7 +265,19 @@ init_entry_point_info (struct objfile *objfile)
263265 CORE_ADDR
264266 entry_point_address (void)
265267 {
266- return symfile_objfile ? symfile_objfile->ei.entry_point : 0;
268+ int ret;
269+ CORE_ADDR entry_addr;
270+
271+ /* Find the address of the entry point of the program from the
272+ auxv vector. */
273+ ret = target_auxv_search (&current_target, AT_ENTRY, &entry_addr);
274+ if (ret == 1)
275+ return entry_addr;
276+ /*if (ret == 0 || ret == -1)*/
277+ else
278+ {
279+ return symfile_objfile ? symfile_objfile->ei.entry_point : 0;
280+ }
267281 }
268282
269283 /* Create the terminating entry of OBJFILE's minimal symbol table.
--- a/gdb/solib-svr4.c
+++ b/gdb/solib-svr4.c
@@ -179,7 +179,9 @@ static CORE_ADDR breakpoint_addr; /* Address where end bkpt is set */
179179
180180 /* Local function prototypes */
181181
182+#if 0
182183 static int match_main (char *);
184+#endif
183185
184186 static CORE_ADDR bfd_lookup_symbol (bfd *, char *, flagword);
185187
@@ -428,22 +430,79 @@ elf_locate_base (void)
428430 {
429431 struct bfd_section *dyninfo_sect;
430432 int dyninfo_sect_size;
431- CORE_ADDR dyninfo_addr;
433+ CORE_ADDR dyninfo_addr, relocated_dyninfo_addr, entry_addr;
432434 char *buf;
433435 char *bufend;
434436 int arch_size;
437+ int ret;
438+
439+ /* Find the address of the entry point of the program from the
440+ auxv vector. */
441+ ret = target_auxv_search (&current_target, AT_ENTRY, &entry_addr);
442+
443+ if (ret == 0 || ret == -1)
444+ {
445+ /* No auxv info, maybe an older kernel. Fake our way through. */
446+ entry_addr = bfd_get_start_address (exec_bfd);
447+
448+ if (debug_solib)
449+ fprintf_unfiltered (gdb_stdlog,
450+ "elf_locate_base: program entry address not found. Using bfd's 0x%s for %s\n",
451+ paddr_nz (entry_addr), exec_bfd->filename);
452+ }
453+ else
454+ {
455+ if (debug_solib)
456+ fprintf_unfiltered (gdb_stdlog,
457+ "elf_locate_base: found program entry address 0x%s for %s\n",
458+ paddr_nz (entry_addr), exec_bfd->filename);
459+ }
435460
436461 /* Find the start address of the .dynamic section. */
437462 dyninfo_sect = bfd_get_section_by_name (exec_bfd, ".dynamic");
438463 if (dyninfo_sect == NULL)
439- return 0;
464+ {
465+ if (debug_solib)
466+ fprintf_unfiltered (gdb_stdlog,
467+ "elf_locate_base: .dynamic section not found in %s -- return now\n",
468+ exec_bfd->filename);
469+ return 0;
470+ }
471+ else
472+ {
473+ if (debug_solib)
474+ fprintf_unfiltered (gdb_stdlog,
475+ "elf_locate_base: .dynamic section found in %s\n",
476+ exec_bfd->filename);
477+ }
478+
440479 dyninfo_addr = bfd_section_vma (exec_bfd, dyninfo_sect);
480+ if (debug_solib)
481+ fprintf_unfiltered (gdb_stdlog,
482+ "elf_locate_base: unrelocated .dynamic addr 0x%s\n",
483+ paddr_nz (dyninfo_addr));
484+
485+ relocated_dyninfo_addr = dyninfo_addr
486+ + entry_addr - bfd_get_start_address(exec_bfd);
487+ if (debug_solib)
488+ fprintf_unfiltered (gdb_stdlog,
489+ "elf_locate_base: relocated .dyn addr 0x%s for %s\n",
490+ paddr_nz(relocated_dyninfo_addr), exec_bfd->filename);
441491
442492 /* Read in .dynamic section, silently ignore errors. */
443493 dyninfo_sect_size = bfd_section_size (exec_bfd, dyninfo_sect);
444494 buf = alloca (dyninfo_sect_size);
445- if (target_read_memory (dyninfo_addr, buf, dyninfo_sect_size))
446- return 0;
495+ if (debug_solib)
496+ fprintf_unfiltered (gdb_stdlog,
497+ "elf_locate_base: read in .dynamic section\n");
498+ if (target_read_memory (relocated_dyninfo_addr, buf, dyninfo_sect_size))
499+ {
500+ if (debug_solib)
501+ fprintf_unfiltered (gdb_stdlog,
502+ "elf_locate_base: couldn't read .dynamic section at 0x%s -- return now\n",
503+ paddr_nz (relocated_dyninfo_addr));
504+ return 0;
505+ }
447506
448507 /* Find the DT_DEBUG entry in the the .dynamic section.
449508 For mips elf we look for DT_MIPS_RLD_MAP, mips elf apparently has
@@ -470,6 +529,10 @@ elf_locate_base (void)
470529 {
471530 dyn_ptr = bfd_h_get_32 (exec_bfd,
472531 (bfd_byte *) x_dynp->d_un.d_ptr);
532+ if (debug_solib)
533+ fprintf_unfiltered (gdb_stdlog,
534+ "elf_locate_base: DT_DEBUG entry has value 0x%s -- return now\n",
535+ paddr_nz (dyn_ptr));
473536 return dyn_ptr;
474537 }
475538 else if (dyn_tag == DT_MIPS_RLD_MAP)
@@ -613,6 +676,10 @@ first_link_map_member (void)
613676 char *r_map_buf = xmalloc (lmo->r_map_size);
614677 struct cleanup *cleanups = make_cleanup (xfree, r_map_buf);
615678
679+ if (debug_solib)
680+ fprintf_unfiltered (gdb_stdlog,
681+ "first_link_map_member: read at 0x%s\n",
682+ paddr_nz (debug_base + lmo->r_map_offset));
616683 read_memory (debug_base + lmo->r_map_offset, r_map_buf, lmo->r_map_size);
617684
618685 /* Assume that the address is unsigned. */
@@ -726,6 +793,10 @@ svr4_current_sos (void)
726793 CORE_ADDR lm;
727794 struct so_list *head = 0;
728795 struct so_list **link_ptr = &head;
796+ if (debug_solib)
797+ fprintf_unfiltered (gdb_stdlog,
798+ "svr4_current_sos: exec_bfd %s\n",
799+ exec_bfd->filename);
729800
730801 /* Make sure we've looked up the inferior's dynamic linker's base
731802 structure. */
@@ -736,12 +807,22 @@ svr4_current_sos (void)
736807 /* If we can't find the dynamic linker's base structure, this
737808 must not be a dynamically linked executable. Hmm. */
738809 if (! debug_base)
739- return 0;
810+ {
811+ if (debug_solib)
812+ fprintf_unfiltered (gdb_stdlog,
813+ "svr4_current_sos: no DT_DEBUG found in %s -- return now\n",
814+ exec_bfd->filename);
815+ return 0;
816+ }
740817 }
741818
742819 /* Walk the inferior's link map list, and build our list of
743820 `struct so_list' nodes. */
744- lm = first_link_map_member ();
821+ if (debug_solib)
822+ fprintf_unfiltered (gdb_stdlog,
823+ "svr4_current_sos: walk link map in %s\n",
824+ exec_bfd->filename);
825+ lm = first_link_map_member ();
745826 while (lm)
746827 {
747828 struct link_map_offsets *lmo = SVR4_FETCH_LINK_MAP_OFFSETS ();
@@ -758,54 +839,133 @@ svr4_current_sos (void)
758839 make_cleanup (xfree, new->lm_info->lm);
759840 memset (new->lm_info->lm, 0, lmo->link_map_size);
760841
842+ if (debug_solib)
843+ fprintf_unfiltered (gdb_stdlog,
844+ "svr4_current_sos: read lm at 0x%s\n", paddr_nz(lm));
761845 read_memory (lm, new->lm_info->lm, lmo->link_map_size);
762846
763847 lm = LM_NEXT (new);
764848
849+ if (debug_solib)
850+ fprintf_unfiltered (gdb_stdlog,
851+ "svr4_current_sos: is first link entry? %d\n",
852+ IGNORE_FIRST_LINK_MAP_ENTRY (new));
853+
765854 /* For SVR4 versions, the first entry in the link map is for the
766855 inferior executable, so we must ignore it. For some versions of
767856 SVR4, it has no name. For others (Solaris 2.3 for example), it
768857 does have a name, so we can no longer use a missing name to
769858 decide when to ignore it. */
770859 if (IGNORE_FIRST_LINK_MAP_ENTRY (new))
771- free_so (new);
860+ {
861+
862+ if (bfd_get_start_address (exec_bfd) == entry_point_address ())
863+ {
864+ free_so (new);
865+ }
866+ else
867+ {
868+ struct so_list *gdb_solib;
869+ if (debug_solib)
870+ fprintf_unfiltered (gdb_stdlog,
871+ "svr4_current_sos: Processing first link map entry\n");
872+ strncpy (new->so_name, exec_bfd->filename,
873+ SO_NAME_MAX_PATH_SIZE - 1);
874+ new->so_name[SO_NAME_MAX_PATH_SIZE - 1] = '\0';
875+ strcpy (new->so_original_name, new->so_name);
876+ /*new->main = 1;*/
877+ new->main_relocated = 0;
878+
879+ if (debug_solib)
880+ {
881+ fprintf_unfiltered (gdb_stdlog,
882+ "svr4_current_sos: Processing nameless DSO\n");
883+ fprintf_unfiltered (gdb_stdlog,
884+ "svr4_current_sos: adding name %s\n",
885+ new->so_name);
886+ }
887+
888+ for (gdb_solib = master_so_list (); gdb_solib; gdb_solib = gdb_solib->next)
889+ {
890+ if (debug_solib)
891+ fprintf_unfiltered (gdb_stdlog,
892+ "svr4_current_sos: compare gdb %s and new %s\n",
893+ gdb_solib->so_name, new->so_name);
894+ if (!strcmp (gdb_solib->so_name, new->so_name))
895+ if (gdb_solib->main_relocated)
896+ {
897+ if (debug_solib)
898+ fprintf_unfiltered (gdb_stdlog,
899+ "svr4_current_sos: found main relocated\n");
900+ break;
901+ }
902+ }
903+
904+ if ((gdb_solib && !gdb_solib->main_relocated) || (!gdb_solib))
905+ {
906+ add_to_target_sections (0 /*from_tty*/, &current_target, new);
907+ new->main = 1;
908+ }
909+ /* We need this in the list of shared libs we return because
910+ solib_add_stub will loop through it and add the symbol file. */
911+ new->next = 0;
912+ *link_ptr = new;
913+ link_ptr = &new->next;
914+ }
915+ }
772916 else
773917 {
774918 int errcode;
775919 char *buffer;
776920
777921 /* Extract this shared object's name. */
922+ if (debug_solib)
923+ fprintf_unfiltered (gdb_stdlog,
924+ "svr4_current_sos: read LM_NAME\n");
925+
778926 target_read_string (LM_NAME (new), &buffer,
779927 SO_NAME_MAX_PATH_SIZE - 1, &errcode);
780928 if (errcode != 0)
781929 {
782- warning ("current_sos: Can't read pathname for load map: %s\n",
930+ warning ("svr4_current_sos: Can't read pathname for load map: %s\n",
783931 safe_strerror (errcode));
784932 }
785933 else
786934 {
935+ if (debug_solib)
936+ fprintf_unfiltered (gdb_stdlog,
937+ "svr4_current_sos: LM_NAME is <%s>\n",
938+ buffer);
939+
787940 strncpy (new->so_name, buffer, SO_NAME_MAX_PATH_SIZE - 1);
788941 new->so_name[SO_NAME_MAX_PATH_SIZE - 1] = '\0';
789942 xfree (buffer);
790943 strcpy (new->so_original_name, new->so_name);
944+ if (debug_solib)
945+ {
946+ fprintf_unfiltered (gdb_stdlog,
947+ "svr4_current_sos: Processing DSO: %s\n",
948+ new->so_name);
949+ fprintf_unfiltered (gdb_stdlog,
950+ "svr4_current_sos: first link entry %d\n",
951+ IGNORE_FIRST_LINK_MAP_ENTRY (new));
952+ }
791953 }
792954
793- /* If this entry has no name, or its name matches the name
794- for the main executable, don't include it in the list. */
795- if (! new->so_name[0]
796- || match_main (new->so_name))
797- free_so (new);
798- else
799- {
800- new->next = 0;
801- *link_ptr = new;
802- link_ptr = &new->next;
803- }
955+ new->next = 0;
956+ *link_ptr = new;
957+ link_ptr = &new->next;
958+
804959 }
805960
806961 discard_cleanups (old_chain);
807962 }
808963
964+ if (debug_solib)
965+ fprintf_unfiltered (gdb_stdlog,
966+ "svr4_current_sos: ENDS %s\n",
967+ exec_bfd->filename);
968+
809969 return head;
810970 }
811971
@@ -824,7 +984,7 @@ svr4_fetch_objfile_link_map (struct objfile *objfile)
824984 return 0; /* failed somehow... */
825985
826986 /* Position ourselves on the first link map. */
827- lm = first_link_map_member ();
987+ lm = first_link_map_member ();
828988 while (lm)
829989 {
830990 /* Get info on the layout of the r_debug and link_map structures. */
@@ -885,7 +1045,7 @@ svr4_fetch_objfile_link_map (struct objfile *objfile)
8851045 /* On some systems, the only way to recognize the link map entry for
8861046 the main executable file is by looking at its name. Return
8871047 non-zero iff SONAME matches one of the known main executable names. */
888-
1048+#if 0
8891049 static int
8901050 match_main (char *soname)
8911051 {
@@ -899,6 +1059,7 @@ match_main (char *soname)
8991059
9001060 return (0);
9011061 }
1062+#endif
9021063
9031064 /* Return 1 if PC lies in the dynamic symbol resolution code of the
9041065 SVR4 run time loader. */
@@ -998,6 +1159,11 @@ enable_break (void)
9981159 /* Find the .interp section; if not found, warn the user and drop
9991160 into the old breakpoint at symbol code. */
10001161 interp_sect = bfd_get_section_by_name (exec_bfd, ".interp");
1162+
1163+ if (debug_solib)
1164+ fprintf_unfiltered (gdb_stdlog,
1165+ "enable_break: search for .interp in %s\n",
1166+ exec_bfd->filename);
10011167 if (interp_sect)
10021168 {
10031169 unsigned int interp_sect_size;
@@ -1031,6 +1197,9 @@ enable_break (void)
10311197 if (tmp_fd >= 0)
10321198 tmp_bfd = bfd_fdopenr (tmp_pathname, gnutarget, tmp_fd);
10331199
1200+ if (debug_solib)
1201+ fprintf_unfiltered (gdb_stdlog,
1202+ "enable_break: opening %s\n", tmp_pathname);
10341203 if (tmp_bfd == NULL)
10351204 goto bkpt_at_symbol;
10361205
@@ -1112,6 +1281,9 @@ enable_break (void)
11121281 if (sym_addr != 0)
11131282 {
11141283 create_solib_event_breakpoint (load_addr + sym_addr);
1284+ if (debug_solib)
1285+ fprintf_unfiltered (gdb_stdlog,
1286+ "enable_break: solib bp set\n");
11151287 return 1;
11161288 }
11171289
@@ -1371,6 +1543,8 @@ svr4_solib_create_inferior_hook (void)
13711543 while (stop_signal != TARGET_SIGNAL_TRAP);
13721544 stop_soon = NO_STOP_QUIETLY;
13731545 #endif /* defined(_SCO_DS) */
1546+
1547+ disable_breakpoints_at_startup (1);
13741548 }
13751549
13761550 static void
--- a/gdb/solib.c
+++ b/gdb/solib.c
@@ -46,6 +46,8 @@
4646
4747 /* external data declarations */
4848
49+int debug_solib;
50+
4951 /* FIXME: gdbarch needs to control this variable */
5052 struct target_so_ops *current_target_so_ops;
5153
@@ -68,6 +70,8 @@ static char *solib_absolute_prefix = NULL;
6870 and LD_LIBRARY_PATH. */
6971 static char *solib_search_path = NULL;
7072
73+void add_to_target_sections (int, struct target_ops *, struct so_list *);
74+
7175 /*
7276
7377 GLOBAL FUNCTION
@@ -340,7 +344,6 @@ master_so_list (void)
340344 return so_list_head;
341345 }
342346
343-
344347 /* A small stub to get us past the arg-passing pinhole of catch_errors. */
345348
346349 static int
@@ -352,15 +355,40 @@ symbol_add_stub (void *arg)
352355 /* Have we already loaded this shared object? */
353356 ALL_OBJFILES (so->objfile)
354357 {
355- if (strcmp (so->objfile->name, so->so_name) == 0)
358+ /* Found an already loaded shared library. */
359+ if (strcmp (so->objfile->name, so->so_name) == 0
360+ && !so->main)
356361 return 1;
362+ /* Found an already loaded main executable. This could happen in
363+ two circumstances.
364+ First case: the main file has already been read in
365+ as the first thing that gdb does at startup, and the file
366+ hasn't been relocated properly yet. Therefor we need to read
367+ it in with the proper section info.
368+ Second case: it has been read in with the correct relocation,
369+ and therefore we need to skip it. */
370+ if (strcmp (so->objfile->name, so->so_name) == 0
371+ && so->main
372+ && so->main_relocated)
373+ return 1;
357374 }
358375
359376 sap = build_section_addr_info_from_section_table (so->sections,
360377 so->sections_end);
361378
362- so->objfile = symbol_file_add (so->so_name, so->from_tty,
363- sap, 0, OBJF_SHARED);
379+ if (so->main)
380+ {
381+ if (debug_solib)
382+ fprintf_unfiltered (gdb_stdlog,
383+ "symbol_add_stub: adding symbols for main\n");
384+ so->objfile = symbol_file_add (so->so_name, /*so->from_tty*/ 0,
385+ sap, 1, 0);
386+ so->main_relocated = 1;
387+ }
388+ else
389+ so->objfile = symbol_file_add (so->so_name, so->from_tty,
390+ sap, 0, OBJF_SHARED);
391+
364392 free_section_addr_info (sap);
365393
366394 return (1);
@@ -455,6 +483,10 @@ update_solib_list (int from_tty, struct target_ops *target)
455483 the inferior's current list. */
456484 while (i)
457485 {
486+ if (debug_solib)
487+ fprintf_unfiltered (gdb_stdlog,
488+ "update_solib_list: compare gdb:%s and inferior:%s\n",
489+ gdb->so_original_name, i->so_original_name);
458490 if (! strcmp (gdb->so_original_name, i->so_original_name))
459491 break;
460492
@@ -504,32 +536,46 @@ update_solib_list (int from_tty, struct target_ops *target)
504536 /* Fill in the rest of each of the `struct so_list' nodes. */
505537 for (i = inferior; i; i = i->next)
506538 {
507- i->from_tty = from_tty;
508-
509- /* Fill in the rest of the `struct so_list' node. */
510- catch_errors (solib_map_sections, i,
511- "Error while mapping shared library sections:\n",
512- RETURN_MASK_ALL);
513-
514- /* If requested, add the shared object's sections to the TARGET's
515- section table. Do this immediately after mapping the object so
516- that later nodes in the list can query this object, as is needed
517- in solib-osf.c. */
518- if (target)
519- {
520- int count = (i->sections_end - i->sections);
521- if (count > 0)
522- {
523- int space = target_resize_to_sections (target, count);
524- memcpy (target->to_sections + space,
525- i->sections,
526- count * sizeof (i->sections[0]));
527- }
528- }
539+ add_to_target_sections (from_tty, target, i);
529540 }
530541 }
531542 }
532543
544+void
545+add_to_target_sections (int from_tty, struct target_ops *target, struct so_list *solib)
546+{
547+ /* If this is set, then the sections have been already added to the
548+ target list. */
549+ if (solib->main)
550+ return;
551+
552+ solib->from_tty = from_tty;
553+
554+ /* Fill in the rest of the `struct so_list' node. */
555+ catch_errors (solib_map_sections, solib,
556+ "Error while mapping shared library sections:\n",
557+ RETURN_MASK_ALL);
558+
559+ /* If requested, add the shared object's sections to the TARGET's
560+ section table. Do this immediately after mapping the object so
561+ that later nodes in the list can query this object, as is needed
562+ in solib-osf.c. */
563+ if (target)
564+ {
565+ int count = (solib->sections_end - solib->sections);
566+ if (count > 0)
567+ {
568+ int space = target_resize_to_sections (target, count);
569+ if (debug_solib)
570+ fprintf_unfiltered (gdb_stdlog,
571+ "add_to_target_sections: add %s to to_sections\n",
572+ solib->so_original_name);
573+ memcpy (target->to_sections + space,
574+ solib->sections,
575+ count * sizeof (solib->sections[0]));
576+ }
577+ }
578+}
533579
534580 /* GLOBAL FUNCTION
535581
@@ -917,4 +963,10 @@ This takes precedence over the environment variables PATH and LD_LIBRARY_PATH.",
917963 add_show_from_set (c, &showlist);
918964 set_cmd_cfunc (c, reload_shared_libraries);
919965 set_cmd_completer (c, filename_completer);
966+
967+ add_show_from_set (add_set_cmd ("solib", no_class, var_zinteger,
968+ (char *) &debug_solib,
969+ "Set debugging of GNU/Linux shlib module.\n\
970+Enables printf debugging output.\n", &setdebuglist), &showdebuglist);
971+
920972 }
--- a/gdb/solist.h
+++ b/gdb/solist.h
@@ -62,6 +62,8 @@ struct so_list
6262 bfd *abfd;
6363 char symbols_loaded; /* flag: symbols read in yet? */
6464 char from_tty; /* flag: print msgs? */
65+ char main; /* flag: is this the main executable? */
66+ char main_relocated; /* flag: has it been relocated yet? */
6567 struct objfile *objfile; /* objfile for loaded lib */
6668 struct section_table *sections;
6769 struct section_table *sections_end;
@@ -113,9 +115,15 @@ void free_so (struct so_list *so);
113115 /* Return address of first so_list entry in master shared object list. */
114116 struct so_list *master_so_list (void);
115117
118+/* Return address of first so_list entry in master shared object list. */
119+struct so_list *master_so_list (void);
120+
116121 /* Find solib binary file and open it. */
117122 extern int solib_open (char *in_pathname, char **found_pathname);
118123
124+/* Add the list of sections in so_list to the target to_sections. */
125+extern void add_to_target_sections (int, struct target_ops *, struct so_list *);
126+
119127 /* FIXME: gdbarch needs to control this variable */
120128 extern struct target_so_ops *current_target_so_ops;
121129
@@ -135,4 +143,6 @@ extern struct target_so_ops *current_target_so_ops;
135143 #define TARGET_SO_FIND_AND_OPEN_SOLIB \
136144 (current_target_so_ops->find_and_open_solib)
137145
146+/* Controls the printing of debugging output. */
147+extern int debug_solib;
138148 #endif
--- a/gdb/symfile.c
+++ b/gdb/symfile.c
@@ -48,6 +48,7 @@
4848 #include "readline/readline.h"
4949 #include "gdb_assert.h"
5050 #include "block.h"
51+#include "varobj.h"
5152
5253 #include <sys/types.h>
5354 #include <fcntl.h>
@@ -573,7 +574,7 @@ syms_from_objfile (struct objfile *objfile,
573574
574575 We no longer warn if the lowest section is not a text segment (as
575576 happens for the PA64 port. */
576- if (!mainline && addrs && addrs->other[0].name)
577+ if (/*!mainline &&*/ addrs && addrs->other[0].name)
577578 {
578579 asection *lower_sect;
579580 asection *sect;
@@ -960,6 +961,10 @@ symbol_file_clear (int from_tty)
960961 && !query ("Discard symbol table from `%s'? ",
961962 symfile_objfile->name))
962963 error ("Not confirmed.");
964+#ifdef CLEAR_SOLIB
965+ CLEAR_SOLIB ();
966+#endif
967+
963968 free_all_objfiles ();
964969
965970 /* solib descriptors may have handles to objfiles. Since their
@@ -1957,6 +1962,8 @@ reread_symbols (void)
19571962 /* Discard cleanups as symbol reading was successful. */
19581963 discard_cleanups (old_cleanups);
19591964
1965+ init_entry_point_info (objfile);
1966+
19601967 /* If the mtime has changed between the time we set new_modtime
19611968 and now, we *want* this to be out of date, so don't call stat
19621969 again now. */
@@ -2312,6 +2319,7 @@ clear_symtab_users (void)
23122319 clear_pc_function_cache ();
23132320 if (target_new_objfile_hook)
23142321 target_new_objfile_hook (NULL);
2322+ varobj_refresh();
23152323 }
23162324
23172325 static void
--- a/gdb/varobj.c
+++ b/gdb/varobj.c
@@ -854,6 +854,62 @@ varobj_list (struct varobj ***varlist)
854854 return rootcount;
855855 }
856856
857+void
858+varobj_refresh (void)
859+{
860+ struct varobj *var;
861+ struct varobj_root *croot;
862+ int mycount = rootcount;
863+ char * name;
864+
865+ croot = rootlist;
866+ while ((croot != NULL) && (mycount > 0))
867+ {
868+ var = croot->rootvar;
869+
870+ /* Get rid of the memory for the old expression. This also
871+ leaves var->root->exp == NULL, which is ok for the parsing
872+ below. */
873+ free_current_contents ((char **) &var->root->exp);
874+
875+ value_free (var->value);
876+ var->type = NULL;
877+
878+ name = xstrdup (var->name);
879+
880+ /* Reparse the expression. Wrap the call to parse expression,
881+ so we can return a sensible error. */
882+ if (!gdb_parse_exp_1 (&name, var->root->valid_block, 0, &var->root->exp))
883+ {
884+ return;
885+ }
886+
887+ /* We definitively need to catch errors here.
888+ If evaluate_expression succeeds we got the value we wanted.
889+ But if it fails, we still go on with a call to evaluate_type() */
890+ if (gdb_evaluate_expression (var->root->exp, &var->value))
891+ {
892+ /* no error */
893+ release_value (var->value);
894+ if (VALUE_LAZY (var->value))
895+ gdb_value_fetch_lazy (var->value);
896+ }
897+ else
898+ var->value = evaluate_type (var->root->exp);
899+
900+ var->type = VALUE_TYPE (var->value);
901+
902+ mycount--;
903+ croot = croot->next;
904+ }
905+
906+ if (mycount || (croot != NULL))
907+ warning
908+ ("varobj_refresh: assertion failed - wrong tally of root vars (%d:%d)",
909+ rootcount, mycount);
910+}
911+
912+
857913 /* Update the values for a variable and its children. This is a
858914 two-pronged attack. First, re-parse the value for the root's
859915 expression to see if it's changed. Then go all the way
--- a/gdb/varobj.h
+++ b/gdb/varobj.h
@@ -97,4 +97,6 @@ extern int varobj_list (struct varobj ***rootlist);
9797
9898 extern int varobj_update (struct varobj **varp, struct varobj ***changelist);
9999
100+extern void varobj_refresh(void);
101+
100102 #endif /* VAROBJ_H */