2 2012-07-30 Gary Benson <gbenson@redhat.com>
4 * breakpoint.h (handle_solib_event): Moved function definition
5 to solib.h, and added a new parameter.
6 * breakpoint.c (handle_solib_event): Moved function to solib.c
7 and added a new parameter.
8 (bpstat_stop_status): Pass new argument to handle_solib_event.
9 * solib.h (breakpoint.h): New include.
10 (handle_solib_event): Moved function definition from breakpoint.h
11 and added a new parameter.
12 (update_solib_breakpoints): New function definition.
13 * solib.c (handle_solib_event): Moved function from breakpoint.c
14 and added a new parameter.
15 (update_solib_breakpoints): New function.
16 * solist.h (breakpoint.h): New include.
17 (target_so_ops): New fields "handle_solib_event" and
19 * infrun.c (set_stop_on_solib_events): New function.
20 (_initialize_infrun): Use the above for "set stop-on-solib-events".
21 (handle_inferior_event): Pass new argument to handle_solib_event.
22 * solib-svr4.c (probe.h): New include.
23 (namespace_table_flatten): New forward declaration.
24 (lm_info): New fields "lmid" and "in_initial_ns".
25 (probe_action): New enum.
26 (probe_info): New struct.
27 (probe_info): New static variable.
28 (NUM_PROBES): New definition.
29 (svr4_info): New fields "using_probes", "probes" and
31 (free_probes): New function.
32 (free_namespace_table): Likewise.
33 (svr4_pspace_data_cleanup): Free probes and namespace table.
34 (svr4_same): Also compare namespaces if using probes.
35 (lm_addr_check): Only print .dynamic section at wrong address
36 warning for initial namespace if using probes.
37 (r_map_from_debug_base): New function.
38 (solib_svr4_r_map): Call the above.
39 (svr4_read_so_list): New parameter "prev_lm".
40 Changed return type from void to int.
41 Return nonzero on success, zero on error.
42 (svr4_current_sos_from_debug_base): New function.
43 (svr4_current_sos): Create result from namespace table if available.
44 Use svr4_current_sos_from_debug_base to generate list otherwise.
45 (probe_and_info): New struct.
46 (solib_event_probe_at): New function.
47 (solib_event_probe_action): Likewise.
48 (namespace): New struct.
49 (hash_namespace): New function.
50 (equal_namespace): Likewise.
51 (free_namespace): Likewise.
52 (namespace_update_full): Likewise.
53 (namespace_update_incremental): Likewise.
54 (svr4_handle_solib_event): Likewise.
55 (namespace_table_flatten_helper): Likewise.
56 (namespace_table_flatten): Likewise.
57 (svr4_update_solib_event_breakpoint): Likewise.
58 (svr4_update_solib_event_breakpoints): Likewise.
59 (svr4_create_solib_event_breakpoints): Likewise.
60 (enable_break): Free probes before creating breakpoints.
61 Use svr4_create_solib_event_breakpoints to create breakpoints.
62 (svr4_solib_create_inferior_hook): Free the namespace table.
63 (_initialize_svr4_solib): Initialise svr4_so_ops.handle_solib_event
64 and svr4_so_ops.update_breakpoints.
67 2012-07-30 Gary Benson <gbenson@redhat.com>
69 * gdb.base/break-interp.exp (solib_bp): New constant.
70 (reach_1): Use the above instead of "_dl_debug_state".
71 (test_attach): Likewise.
73 * gdb.base/break-probes.exp: New file.
74 * gdb.base/break-probes.c: Likewise.
75 * gdb.base/break-probes-solib.c: Likewise.
76 * gdb.base/info-shared.exp: New file.
77 * gdb.base/info-shared.c: Likewise.
78 * gdb.base/info-shared-solib1.c: Likewise.
79 * gdb.base/info-shared-solib2.c: Likewise.
80 * gdb.base/break-dlmopen.exp: Likewise.
81 * gdb.base/break-dlmopen.c: Likewise.
82 * gdb.base/break-dlmopen-solib.c: Likewise.
84 Index: gdb-7.4.91.20120814/gdb/breakpoint.h
85 ===================================================================
86 --- gdb-7.4.91.20120814.orig/gdb/breakpoint.h 2012-08-14 17:31:37.050984427 +0200
87 +++ gdb-7.4.91.20120814/gdb/breakpoint.h 2012-08-14 17:34:44.203746601 +0200
88 @@ -1515,8 +1515,6 @@ extern int user_breakpoint_p (struct bre
89 /* Attempt to determine architecture of location identified by SAL. */
90 extern struct gdbarch *get_sal_arch (struct symtab_and_line sal);
92 -extern void handle_solib_event (void);
94 extern void breakpoints_relocate (struct objfile *objfile,
95 struct section_offsets *delta);
97 Index: gdb-7.4.91.20120814/gdb/breakpoint.c
98 ===================================================================
99 --- gdb-7.4.91.20120814.orig/gdb/breakpoint.c 2012-08-14 17:31:37.128984404 +0200
100 +++ gdb-7.4.91.20120814/gdb/breakpoint.c 2012-08-14 17:34:44.211746597 +0200
101 @@ -5205,7 +5205,7 @@ bpstat_stop_status (struct address_space
103 if (bs->breakpoint_at && bs->breakpoint_at->type == bp_shlib_event)
105 - handle_solib_event ();
106 + handle_solib_event (bs);
110 @@ -5301,25 +5301,6 @@ handle_jit_event (void)
111 target_terminal_inferior ();
114 -/* Handle an solib event by calling solib_add. */
117 -handle_solib_event (void)
119 - clear_program_space_solib_cache (current_inferior ()->pspace);
121 - /* Check for any newly added shared libraries if we're supposed to
122 - be adding them automatically. Switch terminal for any messages
123 - produced by breakpoint_re_set. */
124 - target_terminal_ours_for_output ();
126 - SOLIB_ADD (NULL, 0, ¤t_target, auto_solib_add);
128 - solib_add (NULL, 0, ¤t_target, auto_solib_add);
130 - target_terminal_inferior ();
133 /* Prepare WHAT final decision for infrun. */
135 /* Decide what infrun needs to do with this bpstat. */
136 Index: gdb-7.4.91.20120814/gdb/solib.h
137 ===================================================================
138 --- gdb-7.4.91.20120814.orig/gdb/solib.h 2012-02-03 16:19:37.000000000 +0100
139 +++ gdb-7.4.91.20120814/gdb/solib.h 2012-08-14 17:34:44.257746587 +0200
145 +#include "breakpoint.h"
147 /* Forward decl's for prototypes */
150 @@ -91,4 +94,15 @@ extern CORE_ADDR gdb_bfd_lookup_symbol_f
154 +/* Handle an solib event by calling solib_add. Targets which handle
155 + solib events using breakpoints must pass a valid bpstat. Targets
156 + which handle solib events using some other mechanism should pass
159 +extern void handle_solib_event (bpstat bs);
161 +/* Enable or disable optional solib event breakpoints as appropriate. */
163 +extern void update_solib_breakpoints (void);
166 Index: gdb-7.4.91.20120814/gdb/solib.c
167 ===================================================================
168 --- gdb-7.4.91.20120814.orig/gdb/solib.c 2012-08-14 17:31:36.832984492 +0200
169 +++ gdb-7.4.91.20120814/gdb/solib.c 2012-08-14 17:34:44.272746583 +0200
170 @@ -1226,6 +1226,42 @@ no_shared_libraries (char *ignored, int
171 objfile_purge_solibs ();
177 +handle_solib_event (bpstat bs)
179 + struct target_so_ops *ops = solib_ops (target_gdbarch);
181 + if (ops->handle_solib_event != NULL)
182 + ops->handle_solib_event (bs);
184 + clear_program_space_solib_cache (current_inferior ()->pspace);
186 + /* Check for any newly added shared libraries if we're supposed to
187 + be adding them automatically. Switch terminal for any messages
188 + produced by breakpoint_re_set. */
189 + target_terminal_ours_for_output ();
191 + SOLIB_ADD (NULL, 0, ¤t_target, auto_solib_add);
193 + solib_add (NULL, 0, ¤t_target, auto_solib_add);
195 + target_terminal_inferior ();
201 +update_solib_breakpoints (void)
203 + struct target_so_ops *ops = solib_ops (target_gdbarch);
205 + if (ops->update_breakpoints != NULL)
206 + ops->update_breakpoints ();
210 /* Reload shared libraries, but avoid reloading the same symbol file
211 we already have loaded. */
213 Index: gdb-7.4.91.20120814/gdb/solist.h
214 ===================================================================
215 --- gdb-7.4.91.20120814.orig/gdb/solist.h 2012-01-04 09:17:11.000000000 +0100
216 +++ gdb-7.4.91.20120814/gdb/solist.h 2012-08-14 17:34:44.273746584 +0200
218 #define SO_NAME_MAX_PATH_SIZE 512 /* FIXME: Should be dynamic */
219 /* For domain_enum domain. */
222 +#include "breakpoint.h"
224 /* Forward declaration for target specific link map information. This
225 struct is opaque to all but the target specific file. */
226 @@ -149,6 +151,20 @@ struct target_so_ops
227 core file (in particular, for readonly sections). */
228 int (*keep_data_in_core) (CORE_ADDR vaddr,
231 + /* Target-specific handling of solib events. For targets which
232 + handle solib events using breakpoints a valid bpstat must be
233 + passed. Targets which handle solib events using some other
234 + mechanism should pass NULL. This pointer can be NULL, in which
235 + case no specific handling is necessary for this target. */
236 + void (*handle_solib_event) (bpstat bs);
238 + /* Enable or disable optional solib event breakpoints as
239 + appropriate. This should be called whenever
240 + stop_on_solib_events is changed. This pointer can be
241 + NULL, in which case no enabling or disabling is necessary
242 + for this target. */
243 + void (*update_breakpoints) (void);
246 /* Free the memory associated with a (so_list *). */
247 Index: gdb-7.4.91.20120814/gdb/infrun.c
248 ===================================================================
249 --- gdb-7.4.91.20120814.orig/gdb/infrun.c 2012-08-14 17:33:16.249955007 +0200
250 +++ gdb-7.4.91.20120814/gdb/infrun.c 2012-08-14 17:34:44.276746583 +0200
251 @@ -361,6 +361,16 @@ static struct symbol *step_start_functio
252 /* Nonzero if we want to give control to the user when we're notified
253 of shared library events by the dynamic linker. */
254 int stop_on_solib_events;
256 +/* Enable or disable optional shared library event breakpoints
257 + as appropriate when the above flag is changed. */
260 +set_stop_on_solib_events (char *args, int from_tty, struct cmd_list_element *c)
262 + update_solib_breakpoints ();
266 show_stop_on_solib_events (struct ui_file *file, int from_tty,
267 struct cmd_list_element *c, const char *value)
268 @@ -3321,7 +3331,7 @@ handle_inferior_event (struct execution_
269 context_switch (ecs->ptid);
270 regcache = get_thread_regcache (ecs->ptid);
272 - handle_solib_event ();
273 + handle_solib_event (NULL);
275 ecs->event_thread->control.stop_bpstat
276 = bpstat_stop_status (get_regcache_aspace (regcache),
277 @@ -7226,7 +7236,7 @@ Show stopping for shared library events.
278 If nonzero, gdb will give control to the user when the dynamic linker\n\
279 notifies gdb of shared library events. The most common event of interest\n\
280 to the user would be loading/unloading of a new library."),
282 + set_stop_on_solib_events,
283 show_stop_on_solib_events,
284 &setlist, &showlist);
286 Index: gdb-7.4.91.20120814/gdb/solib-svr4.c
287 ===================================================================
288 --- gdb-7.4.91.20120814.orig/gdb/solib-svr4.c 2012-08-14 17:34:39.346752840 +0200
289 +++ gdb-7.4.91.20120814/gdb/solib-svr4.c 2012-08-14 17:35:42.635732596 +0200
292 #include "exceptions.h"
296 static struct link_map_offsets *svr4_fetch_link_map_offsets (void);
297 static int svr4_have_link_map_offsets (void);
298 static void svr4_relocate_main_executable (void);
299 +static struct so_list *namespace_table_flatten (htab_t namespace_table);
301 /* Link map info to include in an allocated so_list entry. */
303 @@ -71,6 +73,16 @@ struct lm_info
305 /* Values read in from inferior's fields of the same name. */
306 CORE_ADDR l_ld, l_next, l_prev, l_name;
308 + /* Numeric link-map ID of the namespace this object is loaded
309 + into. This value is only valid when using the probes-based
313 + /* Nonzero if the namespace list this object is loaded into is the
314 + application's initial namespace (LM_ID_BASE). This value is
315 + only valid when using the probes-based interface. */
316 + unsigned int in_initial_ns : 1;
319 /* On SVR4 systems, a list of symbols in the dynamic linker where
320 @@ -107,6 +119,53 @@ static const char * const main_name_lis
324 +/* What to do with the namespace table when a probe stop occurs. */
328 + /* Something went seriously wrong. Stop using probes and
329 + revert to using the older interface. */
330 + NAMESPACE_TABLE_INVALIDATE,
332 + /* No action is required. This namespace is still valid. */
333 + NAMESPACE_NO_ACTION,
335 + /* This namespace should be reloaded entirely. */
338 + /* Attempt to incrementally update this namespace. If the
339 + update fails or is not possible, fall back to reloading
340 + the namespace in full. */
341 + NAMESPACE_UPDATE_OR_RELOAD,
344 +/* A probe's name and its associated action. */
348 + /* The name of the probe. */
351 + /* What to do with the namespace table when a probe stop occurs. */
352 + enum probe_action action;
355 +/* A list of named probes and their associated actions. If all
356 + probes are present in the dynamic linker then the probes-based
357 + interface will be used. */
359 +static const struct probe_info probe_info[] =
361 + { "init_start", NAMESPACE_NO_ACTION },
362 + { "init_complete", NAMESPACE_RELOAD },
363 + { "map_start", NAMESPACE_NO_ACTION },
364 + { "reloc_complete", NAMESPACE_UPDATE_OR_RELOAD },
365 + { "unmap_start", NAMESPACE_NO_ACTION },
366 + { "unmap_complete", NAMESPACE_RELOAD },
369 +#define NUM_PROBES ARRAY_SIZE (probe_info)
371 /* Per pspace SVR4 specific data. */
374 @@ -129,17 +188,58 @@ struct svr4_info
375 CORE_ADDR interp_text_sect_high;
376 CORE_ADDR interp_plt_sect_low;
377 CORE_ADDR interp_plt_sect_high;
379 + /* Nonzero if we are using the probes-based interface. */
380 + unsigned int using_probes : 1;
382 + /* Named probes in the dynamic linker. */
383 + VEC (probe_p) *probes[NUM_PROBES];
385 + /* Table of dynamic linker namespaces, used by the probes-based
387 + htab_t namespace_table;
390 /* Per-program-space data key. */
391 static const struct program_space_data *solib_svr4_pspace_data;
393 +/* Free any allocated probe vectors. */
396 +free_probes (struct svr4_info *info)
400 + for (i = 0; i < NUM_PROBES; i++)
401 + VEC_free (probe_p, info->probes[i]);
403 + memset (info->probes, 0, sizeof (info->probes));
406 +/* Free the namespace table. */
409 +free_namespace_table (struct svr4_info *info)
411 + if (info->namespace_table == NULL)
414 + htab_delete (info->namespace_table);
415 + info->namespace_table = NULL;
419 svr4_pspace_data_cleanup (struct program_space *pspace, void *arg)
421 struct svr4_info *info;
423 info = program_space_data (pspace, solib_svr4_pspace_data);
427 + free_probes (info);
428 + free_namespace_table (info);
433 @@ -188,10 +288,21 @@ svr4_same_1 (const char *gdb_so_name, co
437 +/* Return non-zero if GDB and INFERIOR represent the same shared
441 svr4_same (struct so_list *gdb, struct so_list *inferior)
443 - return (svr4_same_1 (gdb->so_original_name, inferior->so_original_name));
444 + struct svr4_info *info = get_svr4_info ();
446 + if (info->using_probes)
448 + if (gdb->lm_info->lmid != inferior->lm_info->lmid)
452 + return svr4_same_1 (gdb->so_original_name, inferior->so_original_name);
455 static struct lm_info *
456 @@ -322,18 +433,26 @@ lm_addr_check (struct so_list *so, bfd *
460 - /* There is no way to verify the library file matches. prelink
461 - can during prelinking of an unprelinked file (or unprelinking
462 - of a prelinked file) shift the DYNAMIC segment by arbitrary
463 - offset without any page size alignment. There is no way to
464 - find out the ELF header and/or Program Headers for a limited
465 - verification if it they match. One could do a verification
466 - of the DYNAMIC segment. Still the found address is the best
467 - one GDB could find. */
469 - warning (_(".dynamic section for \"%s\" "
470 - "is not at the expected address "
471 - "(wrong library or version mismatch?)"), so->so_name);
472 + struct svr4_info *info = get_svr4_info ();
474 + if (!info->using_probes || so->lm_info->in_initial_ns)
476 + /* There is no way to verify the library file
477 + matches. prelink can during prelinking of an
478 + unprelinked file (or unprelinking of a prelinked
479 + file) shift the DYNAMIC segment by arbitrary
480 + offset without any page size alignment. There is
481 + no way to find out the ELF header and/or Program
482 + Headers for a limited verification if it they
483 + match. One could do a verification of the
484 + DYNAMIC segment. Still the found address is the
485 + best one GDB could find. */
487 + warning (_(".dynamic section for \"%s\" "
488 + "is not at the expected address "
489 + "(wrong library or version mismatch?)"),
495 @@ -775,16 +894,10 @@ locate_base (struct svr4_info *info)
496 return info->debug_base;
499 -/* Find the first element in the inferior's dynamic link map, and
500 - return its address in the inferior. Return zero if the address
501 - could not be determined.
503 - FIXME: Perhaps we should validate the info somehow, perhaps by
504 - checking r_version for a known version number, or r_state for
506 +/* Read the r_map field from the supplied r_debug structure. */
509 -solib_svr4_r_map (struct svr4_info *info)
510 +r_map_from_debug_base (CORE_ADDR debug_base)
512 struct link_map_offsets *lmo = svr4_fetch_link_map_offsets ();
513 struct type *ptr_type = builtin_type (target_gdbarch)->builtin_data_ptr;
514 @@ -793,13 +906,27 @@ solib_svr4_r_map (struct svr4_info *info
516 TRY_CATCH (ex, RETURN_MASK_ERROR)
518 - addr = read_memory_typed_address (info->debug_base + lmo->r_map_offset,
519 + addr = read_memory_typed_address (debug_base + lmo->r_map_offset,
522 exception_print (gdb_stderr, ex);
526 +/* Find the first element in the inferior's dynamic link map, and
527 + return its address in the inferior. Return zero if the address
528 + could not be determined.
530 + FIXME: Perhaps we should validate the info somehow, perhaps by
531 + checking r_version for a known version number, or r_state for
535 +solib_svr4_r_map (struct svr4_info *info)
537 + return r_map_from_debug_base (info->debug_base);
540 /* Find r_brk from the inferior's debug base. */
543 @@ -1164,15 +1291,17 @@ svr4_default_sos (void)
547 -/* Read the whole inferior libraries chain starting at address LM. Add the
548 - entries to the tail referenced by LINK_PTR_PTR. Ignore the first entry if
549 - IGNORE_FIRST and set global MAIN_LM_ADDR according to it. */
550 +/* Read the whole inferior libraries chain starting at address LM.
551 + Expect the first entry in the chain's previous entry to be PREV_LM.
552 + Add the entries to the tail referenced by LINK_PTR_PTR. Ignore the
553 + first entry if IGNORE_FIRST and set global MAIN_LM_ADDR according
554 + to it. Returns nonzero upon success. */
557 -svr4_read_so_list (CORE_ADDR lm, struct so_list ***link_ptr_ptr,
560 +svr4_read_so_list (CORE_ADDR lm, CORE_ADDR prev_lm,
561 + struct so_list ***link_ptr_ptr, int ignore_first)
563 - CORE_ADDR prev_lm = 0, next_lm;
566 for (; lm != 0; prev_lm = lm, lm = next_lm)
568 @@ -1189,7 +1318,7 @@ svr4_read_so_list (CORE_ADDR lm, struct
569 if (new->lm_info == NULL)
571 do_cleanups (old_chain);
576 next_lm = new->lm_info->l_next;
577 @@ -1200,7 +1329,7 @@ svr4_read_so_list (CORE_ADDR lm, struct
578 paddress (target_gdbarch, prev_lm),
579 paddress (target_gdbarch, new->lm_info->l_prev));
580 do_cleanups (old_chain);
585 /* For SVR4 versions, the first entry in the link map is for the
586 @@ -1295,20 +1424,61 @@ svr4_read_so_list (CORE_ADDR lm, struct
587 **link_ptr_ptr = new;
588 *link_ptr_ptr = &new->next;
594 -/* Implement the "current_sos" target_so_ops method. */
595 +/* Read the list of loaded libraries from the dynamic linker's base
598 static struct so_list *
599 -svr4_current_sos (void)
600 +svr4_current_sos_from_debug_base (void)
602 + struct svr4_info *info = get_svr4_info ();
604 struct so_list *head = NULL;
605 struct so_list **link_ptr = &head;
606 - struct svr4_info *info;
607 struct cleanup *back_to;
610 + gdb_assert (info->debug_base);
612 + /* Assume that everything is a library if the dynamic loader was loaded
613 + late by a static executable. */
614 + if (exec_bfd && bfd_get_section_by_name (exec_bfd, ".dynamic") == NULL)
619 + back_to = make_cleanup (svr4_free_library_list, &head);
621 + /* Walk the inferior's link map list, and build our list of
622 + `struct so_list' nodes. */
623 + lm = solib_svr4_r_map (info);
625 + svr4_read_so_list (lm, 0, &link_ptr, ignore_first);
627 + /* On Solaris, the dynamic linker is not in the normal list of
628 + shared objects, so make sure we pick it up too. Having
629 + symbol information for the dynamic linker is quite crucial
630 + for skipping dynamic linker resolver code. */
631 + lm = solib_svr4_r_ldsomap (info);
633 + svr4_read_so_list (lm, 0, &link_ptr, 0);
635 + discard_cleanups (back_to);
640 +/* Implement the "current_sos" target_so_ops method. */
642 +static struct so_list *
643 +svr4_current_sos (void)
645 + struct svr4_info *info;
646 struct svr4_library_list library_list;
647 + struct so_list *result;
649 /* Fall back to manual examination of the target if the packet is not
650 supported or gdbserver failed to find DT_DEBUG. gdb.server/solib-list.exp
651 @@ -1331,6 +1501,10 @@ svr4_current_sos (void)
653 info = get_svr4_info ();
655 + /* If we have a namespace table then return a flattened copy. */
656 + if (info->namespace_table != NULL)
657 + return namespace_table_flatten (info->namespace_table);
659 /* Always locate the debug struct, in case it has moved. */
660 info->debug_base = 0;
662 @@ -1340,35 +1514,12 @@ svr4_current_sos (void)
663 if (! info->debug_base)
664 return svr4_default_sos ();
666 - /* Assume that everything is a library if the dynamic loader was loaded
667 - late by a static executable. */
668 - if (exec_bfd && bfd_get_section_by_name (exec_bfd, ".dynamic") == NULL)
673 - back_to = make_cleanup (svr4_free_library_list, &head);
675 - /* Walk the inferior's link map list, and build our list of
676 - `struct so_list' nodes. */
677 - lm = solib_svr4_r_map (info);
679 - svr4_read_so_list (lm, &link_ptr, ignore_first);
681 - /* On Solaris, the dynamic linker is not in the normal list of
682 - shared objects, so make sure we pick it up too. Having
683 - symbol information for the dynamic linker is quite crucial
684 - for skipping dynamic linker resolver code. */
685 - lm = solib_svr4_r_ldsomap (info);
687 - svr4_read_so_list (lm, &link_ptr, 0);
689 - discard_cleanups (back_to);
690 + result = svr4_current_sos_from_debug_base ();
693 + if (result == NULL)
694 return svr4_default_sos ();
700 /* Get the address of the link_map for a given OBJFILE. */
701 @@ -1450,6 +1601,498 @@ exec_entry_point (struct bfd *abfd, stru
705 +/* A probe and its associated information structure. */
707 +struct probe_and_info
710 + struct probe *probe;
712 + /* The probe_info from which the probe was created. */
713 + const struct probe_info *info;
716 +/* Get the solib event probe at the specified location, and the
717 + probe_info the probe was created with. Fills in RESULT and
718 + returns nonzero if a solib event probe was found at the
719 + specified location. Returns zero if no solib event probe
723 +solib_event_probe_at (struct svr4_info *info, struct bp_location *loc,
724 + struct probe_and_info *result)
728 + for (i = 0; i < NUM_PROBES; i++)
730 + struct probe *probe;
733 + for (ix = 0; VEC_iterate (probe_p, info->probes[i], ix, probe); ++ix)
735 + if (loc->pspace == current_program_space
736 + && loc->address == probe->address)
738 + result->info = &probe_info[i];
739 + result->probe = probe;
749 +/* Decide what action to take when the specified solib event probe is
752 +static enum probe_action
753 +solib_event_probe_action (struct probe_and_info *pi)
755 + enum probe_action action;
756 + unsigned probe_argc;
758 + action = pi->info->action;
759 + if (action == NAMESPACE_NO_ACTION || action == NAMESPACE_TABLE_INVALIDATE)
762 + gdb_assert (action == NAMESPACE_RELOAD
763 + || action == NAMESPACE_UPDATE_OR_RELOAD);
765 + /* Check that an appropriate number of arguments has been supplied.
767 + arg0: Lmid_t lmid (mandatory)
768 + arg1: struct r_debug *debug_base (mandatory)
769 + arg2: struct link_map *new (optional, for incremental updates) */
770 + probe_argc = get_probe_argument_count (pi->probe);
771 + if (probe_argc == 2)
772 + action = NAMESPACE_RELOAD;
773 + else if (probe_argc < 2)
774 + action = NAMESPACE_TABLE_INVALIDATE;
779 +/* A namespace in the dynamic linker. */
783 + /* Numeric link-map ID of the namespace. */
786 + /* List of objects loaded into the namespace. */
787 + struct so_list *solist;
790 +/* Returns a hash code for the namespace referenced by p. */
793 +hash_namespace (const void *p)
795 + const struct namespace *ns = p;
797 + return (hashval_t) ns->lmid;
800 +/* Returns non-zero if the namespaces referenced by p1 and p2
804 +equal_namespace (const void *p1, const void *p2)
806 + const struct namespace *ns1 = p1;
807 + const struct namespace *ns2 = p2;
809 + return ns1->lmid == ns2->lmid;
812 +/* Free a namespace. */
815 +free_namespace (void *p)
817 + struct namespace *ns = p;
819 + svr4_free_library_list (ns->solist);
823 +/* Populate this namespace by reading the entire list of shared
824 + objects from the inferior. Returns nonzero on success. */
827 +namespace_update_full (struct svr4_info *info, LONGEST lmid,
828 + CORE_ADDR debug_base, int is_initial_ns)
830 + struct so_list *result = NULL, *so;
831 + struct namespace lookup, *ns;
834 + /* Read the list of shared objects from the inferior. The
835 + initial namespace requires extra processing and is handled
839 + result = svr4_current_sos_from_debug_base ();
843 + CORE_ADDR lm = r_map_from_debug_base (debug_base);
844 + struct so_list **link_ptr = &result;
846 + if (!svr4_read_so_list (lm, 0, &link_ptr, 0))
850 + /* If the namespace is empty then delete it from the table. */
851 + if (result == NULL)
853 + if (info->namespace_table != NULL)
855 + lookup.lmid = lmid;
856 + htab_remove_elt (info->namespace_table, &lookup);
862 + /* Fill in the link-map IDs and initial namespace flags. */
863 + for (so = result; so; so = so->next)
865 + so->lm_info->lmid = lmid;
866 + so->lm_info->in_initial_ns = is_initial_ns;
869 + /* Create the namespace table, if necessary. */
870 + if (info->namespace_table == NULL)
872 + info->namespace_table = htab_create_alloc (1, hash_namespace,
878 + /* Update the namespace table with our new list. */
879 + lookup.lmid = lmid;
880 + slot = htab_find_slot (info->namespace_table, &lookup, INSERT);
881 + if (*slot == HTAB_EMPTY_ENTRY)
883 + ns = XCNEW (struct namespace);
890 + svr4_free_library_list (ns->solist);
892 + ns->solist = result;
897 +/* Update this namespace starting from the link-map entry passed by
898 + the linker in the probe's third argument. Returns nonzero if the
899 + list was successfully updated, or zero to indicate failure. */
902 +namespace_update_incremental (struct svr4_info *info, LONGEST lmid,
903 + CORE_ADDR lm, int is_initial_ns)
905 + struct namespace lookup, *ns;
906 + struct so_list *tail, **link, *so;
909 + /* Find our namespace in the table. */
910 + if (info->namespace_table == NULL)
913 + lookup.lmid = lmid;
914 + ns = htab_find (info->namespace_table, &lookup);
918 + /* Walk to the end of the list. */
925 + link = &tail->next;
927 + /* Read the new objects. */
928 + if (!svr4_read_so_list (lm, tail->lm_info->lm_addr, &link, 0))
931 + /* Fill in the link-map IDs and initial namespace flags. */
932 + for (so = tail; so; so = so->next)
934 + so->lm_info->lmid = lmid;
935 + so->lm_info->in_initial_ns = is_initial_ns;
941 +/* Update the namespace table as appropriate when using the
942 + probes-based linker interface. Do nothing if using the
943 + standard interface. */
946 +svr4_handle_solib_event (bpstat bs)
948 + struct svr4_info *info = get_svr4_info ();
949 + struct probe_and_info buf, *pi = &buf;
950 + enum probe_action action;
953 + CORE_ADDR debug_base, lm = 0;
956 + /* It is possible that this function will be called incorrectly
957 + by the handle_solib_event in handle_inferior_event if GDB goes
958 + fully multi-target. */
959 + gdb_assert (bs != NULL);
961 + if (!info->using_probes)
964 + if (!solib_event_probe_at (info, bs->bp_location_at, pi))
967 + action = solib_event_probe_action (pi);
968 + if (action == NAMESPACE_TABLE_INVALIDATE)
971 + if (action == NAMESPACE_NO_ACTION)
974 + val = evaluate_probe_argument (pi->probe, 0);
978 + lmid = value_as_long (val);
980 + val = evaluate_probe_argument (pi->probe, 1);
984 + debug_base = value_as_address (val);
985 + if (debug_base == 0)
988 + /* Always locate the debug struct, in case it moved. */
989 + info->debug_base = 0;
990 + if (locate_base (info) == 0)
993 + is_initial_ns = (debug_base == info->debug_base);
995 + if (action == NAMESPACE_UPDATE_OR_RELOAD)
997 + val = evaluate_probe_argument (pi->probe, 2);
999 + lm = value_as_address (val);
1002 + action = NAMESPACE_RELOAD;
1005 + if (action == NAMESPACE_UPDATE_OR_RELOAD)
1007 + if (namespace_update_incremental (info, lmid, lm, is_initial_ns))
1010 + action = NAMESPACE_RELOAD;
1013 + gdb_assert (action == NAMESPACE_RELOAD);
1015 + if (namespace_update_full (info, lmid, debug_base, is_initial_ns))
1020 + /* We should never reach here, but if we do we disable the
1021 + probes interface and revert to the original interface.
1022 + We don't reset the breakpoints as the ones we've set up
1024 + warning (_("Probes-based dynamic linker interface failed.\n"
1025 + "Reverting to original interface.\n"));
1027 + free_namespace_table (info);
1028 + free_probes (info);
1029 + info->using_probes = 0;
1032 +/* Helper function for namespace_table_flatten. */
1035 +namespace_table_flatten_helper (void **slot, void *arg)
1037 + struct namespace *ns = (struct namespace *) *slot;
1038 + struct so_list *src = ns->solist;
1039 + struct so_list **link = (struct so_list **) arg;
1042 + link = &(*link)->next;
1044 + while (src != NULL)
1046 + struct so_list *dst;
1048 + dst = xmalloc (sizeof (struct so_list));
1049 + memcpy (dst, src, sizeof (struct so_list));
1051 + dst->lm_info = xmalloc (sizeof (struct lm_info));
1052 + memcpy (dst->lm_info, src->lm_info, sizeof (struct lm_info));
1055 + link = &dst->next;
1062 + return 1; /* Continue traversal. */
1065 +/* Flatten the namespace table into a single list. */
1067 +static struct so_list *
1068 +namespace_table_flatten (htab_t namespace_table)
1070 + struct so_list *dst = NULL;
1072 + htab_traverse (namespace_table, namespace_table_flatten_helper, &dst);
1077 +/* Helper function for svr4_update_solib_event_breakpoints. */
1080 +svr4_update_solib_event_breakpoint (struct breakpoint *b, void *arg)
1082 + struct svr4_info *info = get_svr4_info ();
1083 + struct bp_location *loc;
1085 + if (b->type != bp_shlib_event)
1086 + return 0; /* Continue iterating. */
1088 + for (loc = b->loc; loc; loc = loc->next)
1090 + struct probe_and_info buf, *pi = &buf;
1092 + if (solib_event_probe_at (info, loc, pi))
1094 + if (pi->info->action == NAMESPACE_NO_ACTION)
1095 + b->enable_state = (stop_on_solib_events
1096 + ? bp_enabled : bp_disabled);
1098 + return 0; /* Continue iterating. */
1102 + return 0; /* Continue iterating. */
1105 +/* Enable or disable optional solib event breakpoints as appropriate.
1106 + Called whenever stop_on_solib_events is changed. */
1109 +svr4_update_solib_event_breakpoints (void)
1111 + struct svr4_info *info = get_svr4_info ();
1113 + if (info->using_probes)
1114 + iterate_over_breakpoints (svr4_update_solib_event_breakpoint, NULL);
1117 +/* Both the SunOS and the SVR4 dynamic linkers call a marker function
1118 + before and after mapping and unmapping shared libraries. The sole
1119 + purpose of this method is to allow debuggers to set a breakpoint so
1120 + they can track these changes.
1122 + Some versions of the glibc dynamic linker contain named probes
1123 + to allow more fine grained stopping. Given the address of the
1124 + original marker function, this function attempts to find these
1125 + probes, and if found, sets breakpoints on those instead. If the
1126 + probes aren't found, a single breakpoint is set on the original
1127 + marker function. */
1130 +svr4_create_solib_event_breakpoints (struct gdbarch *gdbarch,
1131 + CORE_ADDR address)
1133 + struct svr4_info *info = get_svr4_info ();
1134 + struct obj_section *os;
1136 + os = find_pc_section (address);
1141 + for (with_prefix = 0; with_prefix <= 1; with_prefix++)
1143 + int all_probes_found = 1;
1146 + for (i = 0; i < NUM_PROBES; i++)
1148 + char name[32] = { '\0' };
1150 + /* Fedora 17, RHEL 6.2, and RHEL 6.3 shipped with an
1151 + early version of the probes code in which the probes'
1152 + names were prefixed with "rtld_". The locations and
1153 + arguments of the probes are otherwise the same, so we
1154 + check for the prefixed version if the unprefixed
1155 + probes are not found. */
1158 + strncat (name, "rtld_", sizeof (name));
1160 + strncat (name, probe_info[i].name, sizeof (name) - sizeof ("rtld_"));
1162 + info->probes[i] = find_probes_in_objfile (os->objfile, "rtld",
1165 + if (!VEC_length (probe_p, info->probes[i]))
1167 + free_probes (info);
1168 + all_probes_found = 0;
1173 + if (all_probes_found)
1175 + info->using_probes = 1;
1177 + for (i = 0; i < NUM_PROBES; i++)
1179 + struct probe *probe;
1183 + VEC_iterate (probe_p, info->probes[i], ix, probe);
1185 + create_solib_event_breakpoint (gdbarch, probe->address);
1188 + svr4_update_solib_event_breakpoints ();
1194 + create_solib_event_breakpoint (gdbarch, address);
1197 /* Helper function for gdb_bfd_lookup_symbol. */
1200 @@ -1502,6 +2145,9 @@ enable_break (struct svr4_info *info, in
1201 info->interp_text_sect_low = info->interp_text_sect_high = 0;
1202 info->interp_plt_sect_low = info->interp_plt_sect_high = 0;
1204 + free_probes (info);
1205 + info->using_probes = 0;
1207 /* If we already have a shared library list in the target, and
1208 r_debug contains r_brk, set the breakpoint there - this should
1209 mean r_brk has already been relocated. Assume the dynamic linker
1210 @@ -1533,7 +2179,7 @@ enable_break (struct svr4_info *info, in
1211 That knowledge is encoded in the address, if it's Thumb the low bit
1212 is 1. However, we've stripped that info above and it's not clear
1213 what all the consequences are of passing a non-addr_bits_remove'd
1214 - address to create_solib_event_breakpoint. The call to
1215 + address to svr4_create_solib_event_breakpoints. The call to
1216 find_pc_section verifies we know about the address and have some
1217 hope of computing the right kind of breakpoint to use (via
1218 symbol info). It does mean that GDB needs to be pointed at a
1219 @@ -1571,7 +2217,7 @@ enable_break (struct svr4_info *info, in
1220 + bfd_section_size (tmp_bfd, interp_sect);
1223 - create_solib_event_breakpoint (target_gdbarch, sym_addr);
1224 + svr4_create_solib_event_breakpoints (target_gdbarch, sym_addr);
1228 @@ -1729,7 +2375,8 @@ enable_break (struct svr4_info *info, in
1232 - create_solib_event_breakpoint (target_gdbarch, load_addr + sym_addr);
1233 + svr4_create_solib_event_breakpoints (target_gdbarch,
1234 + load_addr + sym_addr);
1235 xfree (interp_name);
1238 @@ -1755,7 +2402,7 @@ enable_break (struct svr4_info *info, in
1239 sym_addr = gdbarch_convert_from_func_ptr_addr (target_gdbarch,
1242 - create_solib_event_breakpoint (target_gdbarch, sym_addr);
1243 + svr4_create_solib_event_breakpoints (target_gdbarch, sym_addr);
1247 @@ -1771,7 +2418,7 @@ enable_break (struct svr4_info *info, in
1248 sym_addr = gdbarch_convert_from_func_ptr_addr (target_gdbarch,
1251 - create_solib_event_breakpoint (target_gdbarch, sym_addr);
1252 + svr4_create_solib_event_breakpoints (target_gdbarch, sym_addr);
1256 @@ -2281,6 +2928,9 @@ svr4_solib_create_inferior_hook (int fro
1258 info = get_svr4_info ();
1260 + /* Free the probes-based interface's namespace table. */
1261 + free_namespace_table (info);
1263 /* Relocate the main executable if necessary. */
1264 svr4_relocate_main_executable ();
1266 @@ -2547,4 +3197,6 @@ _initialize_svr4_solib (void)
1267 svr4_so_ops.lookup_lib_global_symbol = elf_lookup_lib_symbol;
1268 svr4_so_ops.same = svr4_same;
1269 svr4_so_ops.keep_data_in_core = svr4_keep_data_in_core;
1270 + svr4_so_ops.handle_solib_event = svr4_handle_solib_event;
1271 + svr4_so_ops.update_breakpoints = svr4_update_solib_event_breakpoints;
1273 Index: gdb-7.4.91.20120814/gdb/testsuite/gdb.base/break-dlmopen-solib.c
1274 ===================================================================
1275 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
1276 +++ gdb-7.4.91.20120814/gdb/testsuite/gdb.base/break-dlmopen-solib.c 2012-08-14 17:34:44.330746591 +0200
1278 +/* Copyright 2012 Free Software Foundation, Inc.
1280 + This program is free software; you can redistribute it and/or modify
1281 + it under the terms of the GNU General Public License as published by
1282 + the Free Software Foundation; either version 3 of the License, or
1283 + (at your option) any later version.
1285 + This program is distributed in the hope that it will be useful,
1286 + but WITHOUT ANY WARRANTY; without even the implied warranty of
1287 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1288 + GNU General Public License for more details.
1290 + You should have received a copy of the GNU General Public License
1291 + along with this program. If not, see <http://www.gnu.org/licenses/>. */
1298 + printf ("foo %d\n", n);
1302 Index: gdb-7.4.91.20120814/gdb/testsuite/gdb.base/break-dlmopen.c
1303 ===================================================================
1304 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
1305 +++ gdb-7.4.91.20120814/gdb/testsuite/gdb.base/break-dlmopen.c 2012-08-14 17:34:44.339746576 +0200
1307 +/* Copyright 2012 Free Software Foundation, Inc.
1309 + This program is free software; you can redistribute it and/or modify
1310 + it under the terms of the GNU General Public License as published by
1311 + the Free Software Foundation; either version 3 of the License, or
1312 + (at your option) any later version.
1314 + This program is distributed in the hope that it will be useful,
1315 + but WITHOUT ANY WARRANTY; without even the implied warranty of
1316 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1317 + GNU General Public License for more details.
1319 + You should have received a copy of the GNU General Public License
1320 + along with this program. If not, see <http://www.gnu.org/licenses/>. */
1322 +#define _GNU_SOURCE
1333 + void *handle1, *handle2, *handle3;
1334 + void (*func)(int);
1336 + handle1 = dlmopen (LM_ID_NEWLM, SHLIB_NAME, RTLD_LAZY);
1339 + func = (void (*)(int)) dlsym (handle1, "foo");
1342 + handle2 = dlmopen (LM_ID_NEWLM, SHLIB_NAME, RTLD_LAZY);
1345 + func = (void (*)(int)) dlsym (handle2, "foo");
1348 + handle3 = dlopen (SHLIB_NAME, RTLD_LAZY);
1351 + func = (void (*)(int)) dlsym (handle3, "foo");
1354 + dlclose (handle1);
1357 + dlclose (handle2);
1360 + dlclose (handle3);
1365 Index: gdb-7.4.91.20120814/gdb/testsuite/gdb.base/break-dlmopen.exp
1366 ===================================================================
1367 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
1368 +++ gdb-7.4.91.20120814/gdb/testsuite/gdb.base/break-dlmopen.exp 2012-08-14 17:34:44.343746563 +0200
1370 +# Copyright 2012 Free Software Foundation, Inc.
1372 +# This program is free software; you can redistribute it and/or modify
1373 +# it under the terms of the GNU General Public License as published by
1374 +# the Free Software Foundation; either version 3 of the License, or
1375 +# (at your option) any later version.
1377 +# This program is distributed in the hope that it will be useful,
1378 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1379 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1380 +# GNU General Public License for more details.
1382 +# You should have received a copy of the GNU General Public License
1383 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1385 +if { [skip_shlib_tests] || [is_remote target] } {
1391 +set libname $testfile-solib
1392 +set srcfile_lib $srcdir/$subdir/$libname.c
1393 +set binfile_lib [standard_output_file $libname.so]
1395 +set normal_bp "_dl_debug_state"
1396 +set probes_bp "dl_main"
1398 +if { [gdb_compile_shlib $srcfile_lib $binfile_lib \
1399 + [list additional_flags=-fPIC]] != "" } {
1400 + untested "Could not compile $binfile_lib."
1404 +if { [prepare_for_testing $testfile.exp $testfile $srcfile \
1405 + [list additional_flags=-DSHLIB_NAME\=\"$binfile_lib\" libs=-ldl]] } {
1409 +# Run "info sharedlibrary" and check our library is shown the expected
1411 +proc check_info_shared { test expect } {
1417 + gdb_test_multiple "info sharedlibrary" $test {
1422 + -re "\r\n$gdb_prompt $" {
1423 + if { $actual == $expect } {
1432 +# Enable stop-on-solib-events
1433 +gdb_test_no_output "set stop-on-solib-events 1"
1435 +# Run to the first stop
1436 +gdb_test "run" ".*Stopped due to shared library event.*"
1438 +# XFAIL if we are not using probes
1439 +set test "ensure using probes"
1441 +gdb_test_multiple "bt" $test {
1442 + -re "#0 +\[^\r\n\]*\\m(__GI_)?$normal_bp\\M.*$gdb_prompt $" {
1445 + -re "#0 +\[^\r\n\]*\\m(__GI_)?$probes_bp\\M.*$gdb_prompt $" {
1447 + set using_probes 1
1451 +if { $using_probes } {
1452 + # Set up breakpoints.
1453 + gdb_test_no_output "set stop-on-solib-events 0"
1454 + gdb_test "break stop" {Breakpoint [0-9]+ at .*}
1455 + gdb_test_no_output "set breakpoint pending on"
1456 + gdb_test "break foo" {Breakpoint [0-9]+ \(foo\) pending\.}
1458 + # Check our library isn't loaded.
1459 + check_info_shared "info sharedlibrary #1" 0
1461 + # Run to the first stop and check our library loaded.
1462 + gdb_test "c" {Breakpoint [0-9]+, .* in stop \(\)}
1463 + check_info_shared "info sharedlibrary #2" 1
1465 + # The next stop should be the function in the library.
1466 + gdb_test "c" {Breakpoint [0-9]+, .* in foo \(\) from .*}
1468 + # Run to the next stop and check our library is now loaded twice.
1469 + gdb_test "c" {Breakpoint [0-9]+, .* in stop \(\)}
1470 + check_info_shared "info sharedlibrary #3" 2
1472 + # The next stop should be the function in the library.
1473 + gdb_test "c" {Breakpoint [0-9]+, .* in foo \(\) from .*}
1475 + # Run to the next stop and check our library is now loaded three
1477 + gdb_test "c" {Breakpoint [0-9]+, .* in stop \(\)}
1478 + check_info_shared "info sharedlibrary #4" 3
1480 + # The next stop should be the function in the library.
1481 + gdb_test "c" {Breakpoint [0-9]+, .* in foo \(\) from .*}
1483 + # Run to the next stop and check our library is now loaded twice.
1484 + gdb_test "c" {Breakpoint [0-9]+, .* in stop \(\)}
1485 + check_info_shared "info sharedlibrary #5" 2
1487 + # Run to the next stop and check our library is now loaded once.
1488 + gdb_test "c" {Breakpoint [0-9]+, .* in stop \(\)}
1489 + check_info_shared "info sharedlibrary #6" 1
1491 + # Run to the next stop and check our library is not loaded.
1492 + gdb_test "c" {Breakpoint [0-9]+, .* in stop \(\)}
1493 + check_info_shared "info sharedlibrary #7" 0
1495 Index: gdb-7.4.91.20120814/gdb/testsuite/gdb.base/break-interp.exp
1496 ===================================================================
1497 --- gdb-7.4.91.20120814.orig/gdb/testsuite/gdb.base/break-interp.exp 2012-06-21 22:46:21.000000000 +0200
1498 +++ gdb-7.4.91.20120814/gdb/testsuite/gdb.base/break-interp.exp 2012-08-14 17:34:44.344746565 +0200
1499 @@ -109,12 +109,19 @@ proc strip_debug {dest} {
1503 +# The marker function for the standard runtime linker interface is
1504 +# _dl_debug_state. The probes-based interface has no specific marker
1505 +# function; the probe we will stop on (init_start) is in dl_main so we
1508 +set solib_bp {(_dl_debug_state|dl_main)}
1510 # Implementation of reach.
1512 proc reach_1 {func command displacement} {
1513 - global gdb_prompt expect_out
1514 + global gdb_prompt expect_out solib_bp
1516 - if {$func == "_dl_debug_state"} {
1517 + if {$func == $solib_bp} {
1518 # Breakpoint on _dl_debug_state can have problems due to its overlap
1519 # with the existing internal breakpoint from GDB.
1520 gdb_test_no_output "set stop-on-solib-events 1"
1521 @@ -142,21 +149,21 @@ proc reach_1 {func command displacement}
1524 -re "Breakpoint \[0-9\]+, \\.?(__GI_)?$func \\(.*\\) at .*:\[0-9\]+\r\n.*$gdb_prompt $" {
1525 - if {$func == "_dl_debug_state"} {
1526 + if {$func == $solib_bp} {
1532 -re "Breakpoint \[0-9\]+, \[0-9xa-f\]+ in \\.?(__GI_)?$func \\(\\).*\r\n$gdb_prompt $" {
1533 - if {$func == "_dl_debug_state"} {
1534 + if {$func == $solib_bp} {
1540 -re "Stopped due to (spurious )?shared library event.*\r\n$gdb_prompt $" {
1541 - if {$func == "_dl_debug_state"} {
1542 + if {$func == $solib_bp} {
1543 if {$debug_state_count == 0} {
1544 # First stop does not yet relocate the _start function
1545 # descriptor on ppc64.
1546 @@ -175,7 +182,7 @@ proc reach_1 {func command displacement}
1547 fail $test_displacement
1550 - if {$func == "_dl_debug_state"} {
1551 + if {$func == $solib_bp} {
1552 gdb_test_no_output "set stop-on-solib-events 0"
1555 @@ -357,7 +364,7 @@ proc test_attach {file displacement {rel
1558 proc test_ld {file ifmain trynosym displacement} {
1559 - global srcdir subdir gdb_prompt expect_out inferior_exited_re
1560 + global srcdir subdir gdb_prompt expect_out inferior_exited_re solib_bp
1562 # First test normal `file'-command loaded $FILE with symbols.
1564 @@ -385,9 +392,9 @@ proc test_ld {file ifmain trynosym displ
1565 gdb_test_no_output "set args ${objdir}/${subdir}/$binfile_test" "set args OBJDIR/${subdir}/$binfile_test"
1568 - reach "_dl_debug_state" "run" $displacement
1569 + reach $solib_bp "run" $displacement
1571 - gdb_test "bt" "#0 +\[^\r\n\]*\\m(__GI_)?_dl_debug_state\\M.*" "dl bt"
1572 + gdb_test "bt" "#0 +\[^\r\n\]*\\m(__GI_)?$solib_bp\\M.*" "dl bt"
1575 reach "main" continue "NONE"
1576 @@ -399,7 +406,7 @@ proc test_ld {file ifmain trynosym displ
1578 # Try re-run if the new PIE displacement takes effect.
1579 gdb_test "kill" "" "kill" {Kill the program being debugged\? \(y or n\) } "y"
1580 - reach "_dl_debug_state" "run" $displacement
1581 + reach $solib_bp "run" $displacement
1584 test_core $file $displacement
1585 @@ -431,7 +438,7 @@ proc test_ld {file ifmain trynosym displ
1586 gdb_test "exec-file $file" "exec-file $escapedfile" "load"
1589 - reach "_dl_debug_state" run $displacement
1590 + reach $solib_bp run $displacement
1592 # Use two separate gdb_test_multiple statements to avoid timeouts due
1593 # to slow processing of wildcard capturing long output
1594 Index: gdb-7.4.91.20120814/gdb/testsuite/gdb.base/break-probes-solib.c
1595 ===================================================================
1596 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
1597 +++ gdb-7.4.91.20120814/gdb/testsuite/gdb.base/break-probes-solib.c 2012-08-14 17:34:44.355746561 +0200
1599 +/* Copyright 2012 Free Software Foundation, Inc.
1601 + This program is free software; you can redistribute it and/or modify
1602 + it under the terms of the GNU General Public License as published by
1603 + the Free Software Foundation; either version 3 of the License, or
1604 + (at your option) any later version.
1606 + This program is distributed in the hope that it will be useful,
1607 + but WITHOUT ANY WARRANTY; without even the implied warranty of
1608 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1609 + GNU General Public License for more details.
1611 + You should have received a copy of the GNU General Public License
1612 + along with this program. If not, see <http://www.gnu.org/licenses/>. */
1619 + printf ("foo %d\n", n);
1623 Index: gdb-7.4.91.20120814/gdb/testsuite/gdb.base/break-probes.c
1624 ===================================================================
1625 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
1626 +++ gdb-7.4.91.20120814/gdb/testsuite/gdb.base/break-probes.c 2012-08-14 17:34:44.362746561 +0200
1628 +/* Copyright 2012 Free Software Foundation, Inc.
1630 + This program is free software; you can redistribute it and/or modify
1631 + it under the terms of the GNU General Public License as published by
1632 + the Free Software Foundation; either version 3 of the License, or
1633 + (at your option) any later version.
1635 + This program is distributed in the hope that it will be useful,
1636 + but WITHOUT ANY WARRANTY; without even the implied warranty of
1637 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1638 + GNU General Public License for more details.
1640 + You should have received a copy of the GNU General Public License
1641 + along with this program. If not, see <http://www.gnu.org/licenses/>. */
1648 + void *handle = dlopen (SHLIB_NAME, RTLD_LAZY);
1654 Index: gdb-7.4.91.20120814/gdb/testsuite/gdb.base/break-probes.exp
1655 ===================================================================
1656 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
1657 +++ gdb-7.4.91.20120814/gdb/testsuite/gdb.base/break-probes.exp 2012-08-14 17:34:44.363746561 +0200
1659 +# Copyright 2012 Free Software Foundation, Inc.
1661 +# This program is free software; you can redistribute it and/or modify
1662 +# it under the terms of the GNU General Public License as published by
1663 +# the Free Software Foundation; either version 3 of the License, or
1664 +# (at your option) any later version.
1666 +# This program is distributed in the hope that it will be useful,
1667 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1668 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1669 +# GNU General Public License for more details.
1671 +# You should have received a copy of the GNU General Public License
1672 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1674 +if { [skip_shlib_tests] || [is_remote target] } {
1680 +set libname $testfile-solib
1681 +set srcfile_lib $srcdir/$subdir/$libname.c
1682 +set binfile_lib [standard_output_file $libname.so]
1684 +set normal_bp "_dl_debug_state"
1685 +set probes_bp "dl_main"
1687 +if { [gdb_compile_shlib $srcfile_lib $binfile_lib \
1688 + [list additional_flags=-fPIC]] != "" } {
1689 + untested "Could not compile $binfile_lib."
1693 +if { [prepare_for_testing $testfile.exp $testfile $srcfile \
1694 + [list additional_flags=-DSHLIB_NAME\=\"$binfile_lib\" libs=-ldl]] } {
1698 +# Enable stop-on-solib-events
1699 +gdb_test_no_output "set stop-on-solib-events 1"
1701 +# Run to the first stop
1702 +gdb_test "run" ".*Stopped due to shared library event.*"
1704 +# XFAIL if we are not using probes
1705 +set test "ensure using probes"
1707 +gdb_test_multiple "bt" $test {
1708 + -re "#0 +\[^\r\n\]*\\m(__GI_)?$normal_bp\\M.*$gdb_prompt $" {
1711 + -re "#0 +\[^\r\n\]*\\m(__GI_)?$probes_bp\\M.*$gdb_prompt $" {
1713 + set using_probes 1
1717 +if { $using_probes } {
1718 + # Run til it loads our library
1719 + set test "run til our library loads"
1720 + set loaded_library 0
1721 + while { !$loaded_library } {
1722 + gdb_test_multiple "c" $test {
1723 + -re "Inferior loaded $binfile_lib\\M.*$gdb_prompt $" {
1725 + set loaded_library 1
1727 + -re "Stopped due to shared library event\\M.*$gdb_prompt $" {
1732 + # Call something to ensure that relocation occurred
1733 + gdb_test "call foo(23)" "foo 23.*\\\$.* = .*"
1735 Index: gdb-7.4.91.20120814/gdb/testsuite/gdb.base/info-shared-solib1.c
1736 ===================================================================
1737 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
1738 +++ gdb-7.4.91.20120814/gdb/testsuite/gdb.base/info-shared-solib1.c 2012-08-14 17:34:44.365746561 +0200
1740 +/* Copyright 2012 Free Software Foundation, Inc.
1742 + This program is free software; you can redistribute it and/or modify
1743 + it under the terms of the GNU General Public License as published by
1744 + the Free Software Foundation; either version 3 of the License, or
1745 + (at your option) any later version.
1747 + This program is distributed in the hope that it will be useful,
1748 + but WITHOUT ANY WARRANTY; without even the implied warranty of
1749 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1750 + GNU General Public License for more details.
1752 + You should have received a copy of the GNU General Public License
1753 + along with this program. If not, see <http://www.gnu.org/licenses/>. */
1760 + printf ("foo %d\n", n);
1764 Index: gdb-7.4.91.20120814/gdb/testsuite/gdb.base/info-shared-solib2.c
1765 ===================================================================
1766 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
1767 +++ gdb-7.4.91.20120814/gdb/testsuite/gdb.base/info-shared-solib2.c 2012-08-14 17:34:44.365746561 +0200
1769 +/* Copyright 2012 Free Software Foundation, Inc.
1771 + This program is free software; you can redistribute it and/or modify
1772 + it under the terms of the GNU General Public License as published by
1773 + the Free Software Foundation; either version 3 of the License, or
1774 + (at your option) any later version.
1776 + This program is distributed in the hope that it will be useful,
1777 + but WITHOUT ANY WARRANTY; without even the implied warranty of
1778 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1779 + GNU General Public License for more details.
1781 + You should have received a copy of the GNU General Public License
1782 + along with this program. If not, see <http://www.gnu.org/licenses/>. */
1789 + printf ("bar %d\n", n);
1793 Index: gdb-7.4.91.20120814/gdb/testsuite/gdb.base/info-shared.c
1794 ===================================================================
1795 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
1796 +++ gdb-7.4.91.20120814/gdb/testsuite/gdb.base/info-shared.c 2012-08-14 17:34:44.366746561 +0200
1798 +/* Copyright 2012 Free Software Foundation, Inc.
1800 + This program is free software; you can redistribute it and/or modify
1801 + it under the terms of the GNU General Public License as published by
1802 + the Free Software Foundation; either version 3 of the License, or
1803 + (at your option) any later version.
1805 + This program is distributed in the hope that it will be useful,
1806 + but WITHOUT ANY WARRANTY; without even the implied warranty of
1807 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1808 + GNU General Public License for more details.
1810 + You should have received a copy of the GNU General Public License
1811 + along with this program. If not, see <http://www.gnu.org/licenses/>. */
1823 + void *handle1, *handle2;
1824 + void (*func)(int);
1826 + handle1 = dlopen (SHLIB1_NAME, RTLD_LAZY);
1829 + handle2 = dlopen (SHLIB2_NAME, RTLD_LAZY);
1832 + func = (void (*)(int)) dlsym (handle1, "foo");
1835 + func = (void (*)(int)) dlsym (handle2, "bar");
1838 + dlclose (handle1);
1841 + dlclose (handle2);
1846 Index: gdb-7.4.91.20120814/gdb/testsuite/gdb.base/info-shared.exp
1847 ===================================================================
1848 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
1849 +++ gdb-7.4.91.20120814/gdb/testsuite/gdb.base/info-shared.exp 2012-08-14 17:34:44.367746561 +0200
1851 +# Copyright 2012 Free Software Foundation, Inc.
1853 +# This program is free software; you can redistribute it and/or modify
1854 +# it under the terms of the GNU General Public License as published by
1855 +# the Free Software Foundation; either version 3 of the License, or
1856 +# (at your option) any later version.
1858 +# This program is distributed in the hope that it will be useful,
1859 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1860 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1861 +# GNU General Public License for more details.
1863 +# You should have received a copy of the GNU General Public License
1864 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1866 +if { [skip_shlib_tests] || [is_remote target] } {
1872 +set lib1name $testfile-solib1
1873 +set srcfile_lib1 $srcdir/$subdir/$lib1name.c
1874 +set binfile_lib1 [standard_output_file $lib1name.so]
1875 +set define1 -DSHLIB1_NAME\=\"$binfile_lib1\"
1877 +set lib2name $testfile-solib2
1878 +set srcfile_lib2 $srcdir/$subdir/$lib2name.c
1879 +set binfile_lib2 [standard_output_file $lib2name.so]
1880 +set define2 -DSHLIB2_NAME\=\"$binfile_lib2\"
1882 +if { [gdb_compile_shlib $srcfile_lib1 $binfile_lib1 \
1883 + [list additional_flags=-fPIC]] != "" } {
1884 + untested "Could not compile $binfile_lib1."
1888 +if { [gdb_compile_shlib $srcfile_lib2 $binfile_lib2 \
1889 + [list additional_flags=-fPIC]] != "" } {
1890 + untested "Could not compile $binfile_lib2."
1894 +set cflags "$define1 $define2"
1895 +if { [prepare_for_testing $testfile.exp $testfile $srcfile \
1896 + [list additional_flags=$cflags libs=-ldl]] } {
1900 +# Run "info sharedlibrary" and check for the presence or absence of
1902 +proc check_info_shared { test expect1 expect2 } {
1910 + gdb_test_multiple "info sharedlibrary" $test {
1919 + -re "\r\n$gdb_prompt $" {
1920 + if { $actual1 == $expect1 && $actual2 == $expect2 } {
1929 +# Set up breakpoints.
1930 +gdb_test "break stop" {Breakpoint [0-9]+ at .*}
1931 +gdb_test_no_output "set breakpoint pending on"
1932 +gdb_test "break foo" {Breakpoint [0-9]+ \(foo\) pending\.}
1933 +gdb_test "break bar" {Breakpoint [0-9]+ \(bar\) pending\.}
1935 +# Check neither of the libraries are loaded at the start.
1936 +gdb_test "start" {Temporary breakpoint [0-9]+, .* in main \(\)}
1937 +check_info_shared "info sharedlibrary #1" 0 0
1939 +# Run to the first stop and check that only the first library is loaded.
1940 +gdb_test "c" {Breakpoint [0-9]+, .* in stop \(\)}
1941 +check_info_shared "info sharedlibrary #2" 1 0
1943 +# Run to the second stop and check that both libraries are loaded.
1944 +gdb_test "c" {Breakpoint [0-9]+, .* in stop \(\)}
1945 +check_info_shared "info sharedlibrary #3" 1 1
1947 +# Check that the next stop is in foo.
1948 +gdb_test "c" {Breakpoint [0-9]+, .* in foo \(\) from .*}
1950 +# Check that the next stop is in bar.
1951 +gdb_test "c" {Breakpoint [0-9]+, .* in bar \(\) from .*}
1953 +# Restart the inferior and make sure there are no breakpoint reset
1954 +# errors. These can happen with the probes-based runtime linker
1955 +# interface if the cache is not cleared correctly.
1957 +gdb_test_multiple "run" $test {
1958 + -re {Start it from the beginning\? \(y or n\) } {
1962 + -re {Error in re-setting breakpoint} {
1965 + -re "\r\n$gdb_prompt $" {
1970 +# We're at the first stop. Check that only the first library is loaded.
1971 +check_info_shared "info sharedlibrary #4" 1 0
1973 +# Run to the second stop and check that both libraries are loaded.
1974 +gdb_test "c" {Breakpoint [0-9]+, .* in stop \(\)}
1975 +check_info_shared "info sharedlibrary #5" 1 1
1977 +# Check that the next stop is in foo.
1978 +gdb_test "c" {Breakpoint [0-9]+, .* in foo \(\) from .*}
1980 +# Check that the next stop is in bar.
1981 +gdb_test "c" {Breakpoint [0-9]+, .* in bar \(\) from .*}
1983 +# Run to the next stop and check that the first library has been unloaded.
1984 +gdb_test "c" {Breakpoint [0-9]+, .* in stop \(\)}
1985 +check_info_shared "info sharedlibrary #6" 0 1
1987 +# Run to the last stop and check that both libraries are gone.
1988 +gdb_test "c" {Breakpoint [0-9]+, .* in stop \(\)}
1989 +check_info_shared "info sharedlibrary #7" 0 0