PR symtab/12406:
* solib.c (update_solib_list): Update the program space's added_solibs and deleted_solibs fields. * progspace.h (struct program_space) <added_solibs, deleted_solibs>: New fields. (clear_program_space_solib_cache): Declare. * progspace.c (release_program_space): Call clear_program_space_solib_cache. (clear_program_space_solib_cache): New function. * infrun.c (handle_inferior_event) <TARGET_WAITKIND_LOADED>: Call bpstat_stop_status. Use handle_solib_event. * breakpoint.c: Include gdb_regex.h. (print_solib_event): New function. (bpstat_print): Use print_solib_event. (bpstat_stop_status): Add special case for bp_shlib_event. (handle_solib_event): New function. (bpstat_what): Use handle_solib_event. (struct solib_catchpoint): New. (dtor_catch_solib, insert_catch_solib, remove_catch_solib) (breakpoint_hit_catch_solib, check_status_catch_solib) (print_it_catch_solib, print_one_catch_solib) (print_mention_catch_solib, print_recreate_catch_solib): New functions. (catch_solib_breakpoint_ops): New global. (catch_load_or_unload, catch_load_command_1) (catch_unload_command_1): New functions. (internal_bkpt_check_status): Add special case for bp_shlib_event. (internal_bkpt_print_it): Use print_solib_event. (initialize_breakpoint_ops): Initialize catch_solib_breakpoint_ops. (_initialize_breakpoint): Register "catch load" and "catch unload". * breakpoint.h (handle_solib_event): Declare. * NEWS: Add entry for "catch load" and "catch unload". gdb/doc * gdb.texinfo (Set Catchpoints): Document "catch load" and "catch unload". (Files): Mention new catch commands. (GDB/MI Async Records): Likewise. gdb/testsuite * lib/mi-support.exp (mi_expect_stop): Add special case for solib-event. * gdb.base/catch-load-so.c: New file. * gdb.base/catch-load.exp: New file. * gdb.base/catch-load.c: New file. * gdb.base/break-interp.exp (reach_1): Update regexp.
This commit is contained in:
parent
fa86499982
commit
edcc512082
16 changed files with 714 additions and 61 deletions
|
@ -1,3 +1,41 @@
|
||||||
|
2012-01-24 Tom Tromey <tromey@redhat.com>
|
||||||
|
|
||||||
|
PR symtab/12406:
|
||||||
|
* solib.c (update_solib_list): Update the program space's
|
||||||
|
added_solibs and deleted_solibs fields.
|
||||||
|
* progspace.h (struct program_space) <added_solibs,
|
||||||
|
deleted_solibs>: New fields.
|
||||||
|
(clear_program_space_solib_cache): Declare.
|
||||||
|
* progspace.c (release_program_space): Call
|
||||||
|
clear_program_space_solib_cache.
|
||||||
|
(clear_program_space_solib_cache): New function.
|
||||||
|
* infrun.c (handle_inferior_event) <TARGET_WAITKIND_LOADED>: Call
|
||||||
|
bpstat_stop_status. Use handle_solib_event.
|
||||||
|
* breakpoint.c: Include gdb_regex.h.
|
||||||
|
(print_solib_event): New function.
|
||||||
|
(bpstat_print): Use print_solib_event.
|
||||||
|
(bpstat_stop_status): Add special case for bp_shlib_event.
|
||||||
|
(handle_solib_event): New function.
|
||||||
|
(bpstat_what): Use handle_solib_event.
|
||||||
|
(struct solib_catchpoint): New.
|
||||||
|
(dtor_catch_solib, insert_catch_solib, remove_catch_solib)
|
||||||
|
(breakpoint_hit_catch_solib, check_status_catch_solib)
|
||||||
|
(print_it_catch_solib, print_one_catch_solib)
|
||||||
|
(print_mention_catch_solib, print_recreate_catch_solib): New
|
||||||
|
functions.
|
||||||
|
(catch_solib_breakpoint_ops): New global.
|
||||||
|
(catch_load_or_unload, catch_load_command_1)
|
||||||
|
(catch_unload_command_1): New functions.
|
||||||
|
(internal_bkpt_check_status): Add special case for
|
||||||
|
bp_shlib_event.
|
||||||
|
(internal_bkpt_print_it): Use print_solib_event.
|
||||||
|
(initialize_breakpoint_ops): Initialize
|
||||||
|
catch_solib_breakpoint_ops.
|
||||||
|
(_initialize_breakpoint): Register "catch load" and "catch
|
||||||
|
unload".
|
||||||
|
* breakpoint.h (handle_solib_event): Declare.
|
||||||
|
* NEWS: Add entry for "catch load" and "catch unload".
|
||||||
|
|
||||||
2012-01-24 Tom Tromey <tromey@redhat.com>
|
2012-01-24 Tom Tromey <tromey@redhat.com>
|
||||||
|
|
||||||
* ada-lang.c: Include gdb_vecs.h.
|
* ada-lang.c: Include gdb_vecs.h.
|
||||||
|
|
5
gdb/NEWS
5
gdb/NEWS
|
@ -34,6 +34,11 @@
|
||||||
* The command "info catch" has been removed. It has been disabled
|
* The command "info catch" has been removed. It has been disabled
|
||||||
since December 2007.
|
since December 2007.
|
||||||
|
|
||||||
|
* New commands
|
||||||
|
|
||||||
|
** "catch load" and "catch unload" can be used to stop when a shared
|
||||||
|
library is loaded or unloaded, respectively.
|
||||||
|
|
||||||
*** Changes in GDB 7.4
|
*** Changes in GDB 7.4
|
||||||
|
|
||||||
* GDB now handles ambiguous linespecs more consistently; the existing
|
* GDB now handles ambiguous linespecs more consistently; the existing
|
||||||
|
|
433
gdb/breakpoint.c
433
gdb/breakpoint.c
|
@ -65,6 +65,7 @@
|
||||||
#include "stack.h"
|
#include "stack.h"
|
||||||
#include "skip.h"
|
#include "skip.h"
|
||||||
#include "record.h"
|
#include "record.h"
|
||||||
|
#include "gdb_regex.h"
|
||||||
|
|
||||||
/* readline include files */
|
/* readline include files */
|
||||||
#include "readline/readline.h"
|
#include "readline/readline.h"
|
||||||
|
@ -259,6 +260,11 @@ static int is_masked_watchpoint (const struct breakpoint *b);
|
||||||
|
|
||||||
static int strace_marker_p (struct breakpoint *b);
|
static int strace_marker_p (struct breakpoint *b);
|
||||||
|
|
||||||
|
static void init_catchpoint (struct breakpoint *b,
|
||||||
|
struct gdbarch *gdbarch, int tempflag,
|
||||||
|
char *cond_string,
|
||||||
|
const struct breakpoint_ops *ops);
|
||||||
|
|
||||||
/* The abstract base class all breakpoint_ops structures inherit
|
/* The abstract base class all breakpoint_ops structures inherit
|
||||||
from. */
|
from. */
|
||||||
static struct breakpoint_ops base_breakpoint_ops;
|
static struct breakpoint_ops base_breakpoint_ops;
|
||||||
|
@ -3490,6 +3496,78 @@ print_bp_stop_message (bpstat bs)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* A helper function that prints a shared library stopped event. */
|
||||||
|
|
||||||
|
static void
|
||||||
|
print_solib_event (int is_catchpoint)
|
||||||
|
{
|
||||||
|
int any_deleted
|
||||||
|
= !VEC_empty (char_ptr, current_program_space->deleted_solibs);
|
||||||
|
int any_added
|
||||||
|
= !VEC_empty (so_list_ptr, current_program_space->added_solibs);
|
||||||
|
|
||||||
|
if (!is_catchpoint)
|
||||||
|
{
|
||||||
|
if (any_added || any_deleted)
|
||||||
|
ui_out_text (current_uiout,
|
||||||
|
_("Stopped due to shared library event:\n"));
|
||||||
|
else
|
||||||
|
ui_out_text (current_uiout,
|
||||||
|
_("Stopped due to shared library event (no "
|
||||||
|
"libraries added or removed)\n"));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ui_out_is_mi_like_p (current_uiout))
|
||||||
|
ui_out_field_string (current_uiout, "reason",
|
||||||
|
async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT));
|
||||||
|
|
||||||
|
if (any_deleted)
|
||||||
|
{
|
||||||
|
struct cleanup *cleanup;
|
||||||
|
char *name;
|
||||||
|
int ix;
|
||||||
|
|
||||||
|
ui_out_text (current_uiout, _(" Inferior unloaded "));
|
||||||
|
cleanup = make_cleanup_ui_out_list_begin_end (current_uiout,
|
||||||
|
"removed");
|
||||||
|
for (ix = 0;
|
||||||
|
VEC_iterate (char_ptr, current_program_space->deleted_solibs,
|
||||||
|
ix, name);
|
||||||
|
++ix)
|
||||||
|
{
|
||||||
|
if (ix > 0)
|
||||||
|
ui_out_text (current_uiout, " ");
|
||||||
|
ui_out_field_string (current_uiout, "library", name);
|
||||||
|
ui_out_text (current_uiout, "\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
do_cleanups (cleanup);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (any_added)
|
||||||
|
{
|
||||||
|
struct so_list *iter;
|
||||||
|
int ix;
|
||||||
|
struct cleanup *cleanup;
|
||||||
|
|
||||||
|
ui_out_text (current_uiout, _(" Inferior loaded "));
|
||||||
|
cleanup = make_cleanup_ui_out_list_begin_end (current_uiout,
|
||||||
|
"added");
|
||||||
|
for (ix = 0;
|
||||||
|
VEC_iterate (so_list_ptr, current_program_space->added_solibs,
|
||||||
|
ix, iter);
|
||||||
|
++ix)
|
||||||
|
{
|
||||||
|
if (ix > 0)
|
||||||
|
ui_out_text (current_uiout, " ");
|
||||||
|
ui_out_field_string (current_uiout, "library", iter->so_name);
|
||||||
|
ui_out_text (current_uiout, "\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
do_cleanups (cleanup);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Print a message indicating what happened. This is called from
|
/* Print a message indicating what happened. This is called from
|
||||||
normal_stop(). The input to this routine is the head of the bpstat
|
normal_stop(). The input to this routine is the head of the bpstat
|
||||||
list - a list of the eventpoints that caused this stop. KIND is
|
list - a list of the eventpoints that caused this stop. KIND is
|
||||||
|
@ -3534,10 +3612,7 @@ bpstat_print (bpstat bs, int kind)
|
||||||
OS-level shared library event, do the same thing. */
|
OS-level shared library event, do the same thing. */
|
||||||
if (kind == TARGET_WAITKIND_LOADED)
|
if (kind == TARGET_WAITKIND_LOADED)
|
||||||
{
|
{
|
||||||
ui_out_text (current_uiout, _("Stopped due to shared library event\n"));
|
print_solib_event (0);
|
||||||
if (ui_out_is_mi_like_p (current_uiout))
|
|
||||||
ui_out_field_string (current_uiout, "reason",
|
|
||||||
async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT));
|
|
||||||
return PRINT_NOTHING;
|
return PRINT_NOTHING;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4222,6 +4297,19 @@ bpstat_stop_status (struct address_space *aspace,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* A bit of special processing for shlib breakpoints. We need to
|
||||||
|
process solib loading here, so that the lists of loaded and
|
||||||
|
unloaded libraries are correct before we handle "catch load" and
|
||||||
|
"catch unload". */
|
||||||
|
for (bs = bs_head; bs != NULL; bs = bs->next)
|
||||||
|
{
|
||||||
|
if (bs->breakpoint_at->type == bp_shlib_event)
|
||||||
|
{
|
||||||
|
handle_solib_event ();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Now go through the locations that caused the target to stop, and
|
/* Now go through the locations that caused the target to stop, and
|
||||||
check whether we're interested in reporting this stop to higher
|
check whether we're interested in reporting this stop to higher
|
||||||
layers, or whether we should resume the target transparently. */
|
layers, or whether we should resume the target transparently. */
|
||||||
|
@ -4311,6 +4399,25 @@ handle_jit_event (void)
|
||||||
target_terminal_inferior ();
|
target_terminal_inferior ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Handle an solib event by calling solib_add. */
|
||||||
|
|
||||||
|
void
|
||||||
|
handle_solib_event (void)
|
||||||
|
{
|
||||||
|
clear_program_space_solib_cache (current_inferior ()->pspace);
|
||||||
|
|
||||||
|
/* Check for any newly added shared libraries if we're supposed to
|
||||||
|
be adding them automatically. Switch terminal for any messages
|
||||||
|
produced by breakpoint_re_set. */
|
||||||
|
target_terminal_ours_for_output ();
|
||||||
|
#ifdef SOLIB_ADD
|
||||||
|
SOLIB_ADD (NULL, 0, ¤t_target, auto_solib_add);
|
||||||
|
#else
|
||||||
|
solib_add (NULL, 0, ¤t_target, auto_solib_add);
|
||||||
|
#endif
|
||||||
|
target_terminal_inferior ();
|
||||||
|
}
|
||||||
|
|
||||||
/* Prepare WHAT final decision for infrun. */
|
/* Prepare WHAT final decision for infrun. */
|
||||||
|
|
||||||
/* Decide what infrun needs to do with this bpstat. */
|
/* Decide what infrun needs to do with this bpstat. */
|
||||||
|
@ -4319,10 +4426,6 @@ struct bpstat_what
|
||||||
bpstat_what (bpstat bs_head)
|
bpstat_what (bpstat bs_head)
|
||||||
{
|
{
|
||||||
struct bpstat_what retval;
|
struct bpstat_what retval;
|
||||||
/* We need to defer calling `solib_add', as adding new symbols
|
|
||||||
resets breakpoints, which in turn deletes breakpoint locations,
|
|
||||||
and hence may clear unprocessed entries in the BS chain. */
|
|
||||||
int shlib_event = 0;
|
|
||||||
int jit_event = 0;
|
int jit_event = 0;
|
||||||
bpstat bs;
|
bpstat bs;
|
||||||
|
|
||||||
|
@ -4346,9 +4449,6 @@ bpstat_what (bpstat bs_head)
|
||||||
else
|
else
|
||||||
bptype = bs->breakpoint_at->type;
|
bptype = bs->breakpoint_at->type;
|
||||||
|
|
||||||
if (bptype == bp_shlib_event)
|
|
||||||
shlib_event = 1;
|
|
||||||
|
|
||||||
switch (bptype)
|
switch (bptype)
|
||||||
{
|
{
|
||||||
case bp_none:
|
case bp_none:
|
||||||
|
@ -4480,27 +4580,6 @@ bpstat_what (bpstat bs_head)
|
||||||
/* These operations may affect the bs->breakpoint_at state so they are
|
/* These operations may affect the bs->breakpoint_at state so they are
|
||||||
delayed after MAIN_ACTION is decided above. */
|
delayed after MAIN_ACTION is decided above. */
|
||||||
|
|
||||||
if (shlib_event)
|
|
||||||
{
|
|
||||||
if (debug_infrun)
|
|
||||||
fprintf_unfiltered (gdb_stdlog, "bpstat_what: bp_shlib_event\n");
|
|
||||||
|
|
||||||
/* Check for any newly added shared libraries if we're supposed
|
|
||||||
to be adding them automatically. */
|
|
||||||
|
|
||||||
/* Switch terminal for any messages produced by
|
|
||||||
breakpoint_re_set. */
|
|
||||||
target_terminal_ours_for_output ();
|
|
||||||
|
|
||||||
#ifdef SOLIB_ADD
|
|
||||||
SOLIB_ADD (NULL, 0, ¤t_target, auto_solib_add);
|
|
||||||
#else
|
|
||||||
solib_add (NULL, 0, ¤t_target, auto_solib_add);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
target_terminal_inferior ();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (jit_event)
|
if (jit_event)
|
||||||
{
|
{
|
||||||
if (debug_infrun)
|
if (debug_infrun)
|
||||||
|
@ -6431,6 +6510,264 @@ print_recreate_catch_vfork (struct breakpoint *b, struct ui_file *fp)
|
||||||
|
|
||||||
static struct breakpoint_ops catch_vfork_breakpoint_ops;
|
static struct breakpoint_ops catch_vfork_breakpoint_ops;
|
||||||
|
|
||||||
|
/* An instance of this type is used to represent an solib catchpoint.
|
||||||
|
It includes a "struct breakpoint" as a kind of base class; users
|
||||||
|
downcast to "struct breakpoint *" when needed. A breakpoint is
|
||||||
|
really of this type iff its ops pointer points to
|
||||||
|
CATCH_SOLIB_BREAKPOINT_OPS. */
|
||||||
|
|
||||||
|
struct solib_catchpoint
|
||||||
|
{
|
||||||
|
/* The base class. */
|
||||||
|
struct breakpoint base;
|
||||||
|
|
||||||
|
/* True for "catch load", false for "catch unload". */
|
||||||
|
unsigned char is_load;
|
||||||
|
|
||||||
|
/* Regular expression to match, if any. COMPILED is only valid when
|
||||||
|
REGEX is non-NULL. */
|
||||||
|
char *regex;
|
||||||
|
regex_t compiled;
|
||||||
|
};
|
||||||
|
|
||||||
|
static void
|
||||||
|
dtor_catch_solib (struct breakpoint *b)
|
||||||
|
{
|
||||||
|
struct solib_catchpoint *self = (struct solib_catchpoint *) b;
|
||||||
|
|
||||||
|
if (self->regex)
|
||||||
|
regfree (&self->compiled);
|
||||||
|
xfree (self->regex);
|
||||||
|
|
||||||
|
base_breakpoint_ops.dtor (b);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
insert_catch_solib (struct bp_location *ignore)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
remove_catch_solib (struct bp_location *ignore)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
breakpoint_hit_catch_solib (const struct bp_location *bl,
|
||||||
|
struct address_space *aspace,
|
||||||
|
CORE_ADDR bp_addr,
|
||||||
|
const struct target_waitstatus *ws)
|
||||||
|
{
|
||||||
|
struct solib_catchpoint *self = (struct solib_catchpoint *) bl->owner;
|
||||||
|
struct breakpoint *other;
|
||||||
|
|
||||||
|
if (ws->kind == TARGET_WAITKIND_LOADED)
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
ALL_BREAKPOINTS (other)
|
||||||
|
{
|
||||||
|
struct bp_location *other_bl;
|
||||||
|
|
||||||
|
if (other == bl->owner)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (other->type != bp_shlib_event)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (self->base.pspace != NULL && other->pspace != self->base.pspace)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
for (other_bl = other->loc; other_bl != NULL; other_bl = other_bl->next)
|
||||||
|
{
|
||||||
|
if (other->ops->breakpoint_hit (other_bl, aspace, bp_addr, ws))
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
check_status_catch_solib (struct bpstats *bs)
|
||||||
|
{
|
||||||
|
struct solib_catchpoint *self
|
||||||
|
= (struct solib_catchpoint *) bs->breakpoint_at;
|
||||||
|
int ix;
|
||||||
|
|
||||||
|
if (self->is_load)
|
||||||
|
{
|
||||||
|
struct so_list *iter;
|
||||||
|
|
||||||
|
for (ix = 0;
|
||||||
|
VEC_iterate (so_list_ptr, current_program_space->added_solibs,
|
||||||
|
ix, iter);
|
||||||
|
++ix)
|
||||||
|
{
|
||||||
|
if (!self->regex
|
||||||
|
|| regexec (&self->compiled, iter->so_name, 0, NULL, 0) == 0)
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
char *iter;
|
||||||
|
|
||||||
|
for (ix = 0;
|
||||||
|
VEC_iterate (char_ptr, current_program_space->deleted_solibs,
|
||||||
|
ix, iter);
|
||||||
|
++ix)
|
||||||
|
{
|
||||||
|
if (!self->regex
|
||||||
|
|| regexec (&self->compiled, iter, 0, NULL, 0) == 0)
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bs->stop = 0;
|
||||||
|
bs->print_it = print_it_noop;
|
||||||
|
}
|
||||||
|
|
||||||
|
static enum print_stop_action
|
||||||
|
print_it_catch_solib (bpstat bs)
|
||||||
|
{
|
||||||
|
struct breakpoint *b = bs->breakpoint_at;
|
||||||
|
struct ui_out *uiout = current_uiout;
|
||||||
|
|
||||||
|
annotate_catchpoint (b->number);
|
||||||
|
if (b->disposition == disp_del)
|
||||||
|
ui_out_text (uiout, "\nTemporary catchpoint ");
|
||||||
|
else
|
||||||
|
ui_out_text (uiout, "\nCatchpoint ");
|
||||||
|
ui_out_field_int (uiout, "bkptno", b->number);
|
||||||
|
ui_out_text (uiout, "\n");
|
||||||
|
if (ui_out_is_mi_like_p (uiout))
|
||||||
|
ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
|
||||||
|
print_solib_event (1);
|
||||||
|
return PRINT_SRC_AND_LOC;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
print_one_catch_solib (struct breakpoint *b, struct bp_location **locs)
|
||||||
|
{
|
||||||
|
struct solib_catchpoint *self = (struct solib_catchpoint *) b;
|
||||||
|
struct value_print_options opts;
|
||||||
|
struct ui_out *uiout = current_uiout;
|
||||||
|
char *msg;
|
||||||
|
|
||||||
|
get_user_print_options (&opts);
|
||||||
|
/* Field 4, the address, is omitted (which makes the columns not
|
||||||
|
line up too nicely with the headers, but the effect is relatively
|
||||||
|
readable). */
|
||||||
|
if (opts.addressprint)
|
||||||
|
{
|
||||||
|
annotate_field (4);
|
||||||
|
ui_out_field_skip (uiout, "addr");
|
||||||
|
}
|
||||||
|
|
||||||
|
annotate_field (5);
|
||||||
|
if (self->is_load)
|
||||||
|
{
|
||||||
|
if (self->regex)
|
||||||
|
msg = xstrprintf (_("load of library matching %s"), self->regex);
|
||||||
|
else
|
||||||
|
msg = xstrdup (_("load of library"));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (self->regex)
|
||||||
|
msg = xstrprintf (_("unload of library matching %s"), self->regex);
|
||||||
|
else
|
||||||
|
msg = xstrdup (_("unload of library"));
|
||||||
|
}
|
||||||
|
ui_out_field_string (uiout, "what", msg);
|
||||||
|
xfree (msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
print_mention_catch_solib (struct breakpoint *b)
|
||||||
|
{
|
||||||
|
struct solib_catchpoint *self = (struct solib_catchpoint *) b;
|
||||||
|
|
||||||
|
printf_filtered (_("Catchpoint %d (%s)"), b->number,
|
||||||
|
self->is_load ? "load" : "unload");
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
print_recreate_catch_solib (struct breakpoint *b, struct ui_file *fp)
|
||||||
|
{
|
||||||
|
struct solib_catchpoint *self = (struct solib_catchpoint *) b;
|
||||||
|
|
||||||
|
fprintf_unfiltered (fp, "%s %s",
|
||||||
|
b->disposition == disp_del ? "tcatch" : "catch",
|
||||||
|
self->is_load ? "load" : "unload");
|
||||||
|
if (self->regex)
|
||||||
|
fprintf_unfiltered (fp, " %s", self->regex);
|
||||||
|
fprintf_unfiltered (fp, "\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
static struct breakpoint_ops catch_solib_breakpoint_ops;
|
||||||
|
|
||||||
|
/* A helper function that does all the work for "catch load" and
|
||||||
|
"catch unload". */
|
||||||
|
|
||||||
|
static void
|
||||||
|
catch_load_or_unload (char *arg, int from_tty, int is_load,
|
||||||
|
struct cmd_list_element *command)
|
||||||
|
{
|
||||||
|
struct solib_catchpoint *c;
|
||||||
|
struct gdbarch *gdbarch = get_current_arch ();
|
||||||
|
int tempflag;
|
||||||
|
regex_t compiled;
|
||||||
|
struct cleanup *cleanup;
|
||||||
|
|
||||||
|
tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
|
||||||
|
|
||||||
|
if (!arg)
|
||||||
|
arg = "";
|
||||||
|
arg = skip_spaces (arg);
|
||||||
|
|
||||||
|
c = XCNEW (struct solib_catchpoint);
|
||||||
|
cleanup = make_cleanup (xfree, c);
|
||||||
|
|
||||||
|
if (*arg != '\0')
|
||||||
|
{
|
||||||
|
int errcode;
|
||||||
|
|
||||||
|
errcode = regcomp (&c->compiled, arg, REG_NOSUB);
|
||||||
|
if (errcode != 0)
|
||||||
|
{
|
||||||
|
char *err = get_regcomp_error (errcode, &c->compiled);
|
||||||
|
|
||||||
|
make_cleanup (xfree, err);
|
||||||
|
error (_("Invalid regexp (%s): %s"), err, arg);
|
||||||
|
}
|
||||||
|
c->regex = xstrdup (arg);
|
||||||
|
}
|
||||||
|
|
||||||
|
c->is_load = is_load;
|
||||||
|
init_catchpoint (&c->base, gdbarch, tempflag, NULL,
|
||||||
|
&catch_solib_breakpoint_ops);
|
||||||
|
|
||||||
|
discard_cleanups (cleanup);
|
||||||
|
install_breakpoint (0, &c->base, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
catch_load_command_1 (char *arg, int from_tty,
|
||||||
|
struct cmd_list_element *command)
|
||||||
|
{
|
||||||
|
catch_load_or_unload (arg, from_tty, 1, command);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
catch_unload_command_1 (char *arg, int from_tty,
|
||||||
|
struct cmd_list_element *command)
|
||||||
|
{
|
||||||
|
catch_load_or_unload (arg, from_tty, 0, command);
|
||||||
|
}
|
||||||
|
|
||||||
/* An instance of this type is used to represent a syscall catchpoint.
|
/* An instance of this type is used to represent a syscall catchpoint.
|
||||||
It includes a "struct breakpoint" as a kind of base class; users
|
It includes a "struct breakpoint" as a kind of base class; users
|
||||||
downcast to "struct breakpoint *" when needed. A breakpoint is
|
downcast to "struct breakpoint *" when needed. A breakpoint is
|
||||||
|
@ -11199,10 +11536,7 @@ internal_bkpt_print_it (bpstat bs)
|
||||||
/* Did we stop because the user set the stop_on_solib_events
|
/* Did we stop because the user set the stop_on_solib_events
|
||||||
variable? (If so, we report this as a generic, "Stopped due
|
variable? (If so, we report this as a generic, "Stopped due
|
||||||
to shlib event" message.) */
|
to shlib event" message.) */
|
||||||
ui_out_text (uiout, _("Stopped due to shared library event\n"));
|
print_solib_event (0);
|
||||||
if (ui_out_is_mi_like_p (uiout))
|
|
||||||
ui_out_field_string (uiout, "reason",
|
|
||||||
async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT));
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case bp_thread_event:
|
case bp_thread_event:
|
||||||
|
@ -13841,6 +14175,19 @@ initialize_breakpoint_ops (void)
|
||||||
ops->print_one = print_one_catch_syscall;
|
ops->print_one = print_one_catch_syscall;
|
||||||
ops->print_mention = print_mention_catch_syscall;
|
ops->print_mention = print_mention_catch_syscall;
|
||||||
ops->print_recreate = print_recreate_catch_syscall;
|
ops->print_recreate = print_recreate_catch_syscall;
|
||||||
|
|
||||||
|
/* Solib-related catchpoints. */
|
||||||
|
ops = &catch_solib_breakpoint_ops;
|
||||||
|
*ops = base_breakpoint_ops;
|
||||||
|
ops->dtor = dtor_catch_solib;
|
||||||
|
ops->insert_location = insert_catch_solib;
|
||||||
|
ops->remove_location = remove_catch_solib;
|
||||||
|
ops->breakpoint_hit = breakpoint_hit_catch_solib;
|
||||||
|
ops->check_status = check_status_catch_solib;
|
||||||
|
ops->print_it = print_it_catch_solib;
|
||||||
|
ops->print_one = print_one_catch_solib;
|
||||||
|
ops->print_mention = print_mention_catch_solib;
|
||||||
|
ops->print_recreate = print_recreate_catch_solib;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -14144,6 +14491,20 @@ Catch an exception, when thrown."),
|
||||||
NULL,
|
NULL,
|
||||||
CATCH_PERMANENT,
|
CATCH_PERMANENT,
|
||||||
CATCH_TEMPORARY);
|
CATCH_TEMPORARY);
|
||||||
|
add_catch_command ("load", _("Catch loads of shared libraries.\n\
|
||||||
|
Usage: catch load [REGEX]\n\
|
||||||
|
If REGEX is given, only stop for libraries matching the regular expression."),
|
||||||
|
catch_load_command_1,
|
||||||
|
NULL,
|
||||||
|
CATCH_PERMANENT,
|
||||||
|
CATCH_TEMPORARY);
|
||||||
|
add_catch_command ("unload", _("Catch unloads of shared libraries.\n\
|
||||||
|
Usage: catch unload [REGEX]\n\
|
||||||
|
If REGEX is given, only stop for libraries matching the regular expression."),
|
||||||
|
catch_unload_command_1,
|
||||||
|
NULL,
|
||||||
|
CATCH_PERMANENT,
|
||||||
|
CATCH_TEMPORARY);
|
||||||
add_catch_command ("syscall", _("\
|
add_catch_command ("syscall", _("\
|
||||||
Catch system calls by their names and/or numbers.\n\
|
Catch system calls by their names and/or numbers.\n\
|
||||||
Arguments say which system calls to catch. If no arguments\n\
|
Arguments say which system calls to catch. If no arguments\n\
|
||||||
|
|
|
@ -1419,4 +1419,6 @@ extern int user_breakpoint_p (struct breakpoint *);
|
||||||
/* Attempt to determine architecture of location identified by SAL. */
|
/* Attempt to determine architecture of location identified by SAL. */
|
||||||
extern struct gdbarch *get_sal_arch (struct symtab_and_line sal);
|
extern struct gdbarch *get_sal_arch (struct symtab_and_line sal);
|
||||||
|
|
||||||
|
extern void handle_solib_event (void);
|
||||||
|
|
||||||
#endif /* !defined (BREAKPOINT_H) */
|
#endif /* !defined (BREAKPOINT_H) */
|
||||||
|
|
|
@ -1,3 +1,10 @@
|
||||||
|
2012-01-24 Tom Tromey <tromey@redhat.com>
|
||||||
|
|
||||||
|
* gdb.texinfo (Set Catchpoints): Document "catch load" and "catch
|
||||||
|
unload".
|
||||||
|
(Files): Mention new catch commands.
|
||||||
|
(GDB/MI Async Records): Likewise.
|
||||||
|
|
||||||
2012-01-24 Gary Benson <gbenson@redhat.com>
|
2012-01-24 Gary Benson <gbenson@redhat.com>
|
||||||
|
|
||||||
Delete #if 0'd out code.
|
Delete #if 0'd out code.
|
||||||
|
|
|
@ -4113,6 +4113,12 @@ and @sc{gnu}/Linux.
|
||||||
A call to @code{vfork}. This is currently only available for HP-UX
|
A call to @code{vfork}. This is currently only available for HP-UX
|
||||||
and @sc{gnu}/Linux.
|
and @sc{gnu}/Linux.
|
||||||
|
|
||||||
|
@item load @r{[}regexp@r{]}
|
||||||
|
@itemx unload @r{[}regexp@r{]}
|
||||||
|
The loading or unloading of a shared library. If @var{regexp} is
|
||||||
|
given, then the catchpoint will stop only if the regular expression
|
||||||
|
matches one of the affected libraries.
|
||||||
|
|
||||||
@end table
|
@end table
|
||||||
|
|
||||||
@item tcatch @var{event}
|
@item tcatch @var{event}
|
||||||
|
@ -15588,8 +15594,14 @@ discarded.
|
||||||
@end table
|
@end table
|
||||||
|
|
||||||
Sometimes you may wish that @value{GDBN} stops and gives you control
|
Sometimes you may wish that @value{GDBN} stops and gives you control
|
||||||
when any of shared library events happen. Use the @code{set
|
when any of shared library events happen. The best way to do this is
|
||||||
stop-on-solib-events} command for this:
|
to use @code{catch load} and @code{catch unload} (@pxref{Set
|
||||||
|
Catchpoints}).
|
||||||
|
|
||||||
|
@value{GDBN} also supports the the @code{set stop-on-solib-events}
|
||||||
|
command for this. This command exists for historical reasons. It is
|
||||||
|
less useful than setting a catchpoint, because it does not allow for
|
||||||
|
conditions or commands as a catchpoint does.
|
||||||
|
|
||||||
@table @code
|
@table @code
|
||||||
@item set stop-on-solib-events
|
@item set stop-on-solib-events
|
||||||
|
@ -26293,8 +26305,9 @@ The inferior exited normally.
|
||||||
A signal was received by the inferior.
|
A signal was received by the inferior.
|
||||||
@item solib-event
|
@item solib-event
|
||||||
The inferior has stopped due to a library being loaded or unloaded.
|
The inferior has stopped due to a library being loaded or unloaded.
|
||||||
This can only happen when @code{stop-on-solib-events} (@pxref{Files})
|
This can happen when @code{stop-on-solib-events} (@pxref{Files}) is
|
||||||
is set.
|
set or when a @code{catch load} or @code{catch unload} catchpoint is
|
||||||
|
in use (@pxref{Set Catchpoints}).
|
||||||
@item fork
|
@item fork
|
||||||
The inferior has forked. This is reported when @code{catch fork}
|
The inferior has forked. This is reported when @code{catch fork}
|
||||||
(@pxref{Set Catchpoints}) has been used.
|
(@pxref{Set Catchpoints}) has been used.
|
||||||
|
|
41
gdb/infrun.c
41
gdb/infrun.c
|
@ -3316,28 +3316,32 @@ handle_inferior_event (struct execution_control_state *ecs)
|
||||||
established. */
|
established. */
|
||||||
if (stop_soon == NO_STOP_QUIETLY)
|
if (stop_soon == NO_STOP_QUIETLY)
|
||||||
{
|
{
|
||||||
/* Check for any newly added shared libraries if we're
|
struct regcache *regcache;
|
||||||
supposed to be adding them automatically. Switch
|
|
||||||
terminal for any messages produced by
|
if (!ptid_equal (ecs->ptid, inferior_ptid))
|
||||||
breakpoint_re_set. */
|
context_switch (ecs->ptid);
|
||||||
target_terminal_ours_for_output ();
|
regcache = get_thread_regcache (ecs->ptid);
|
||||||
/* NOTE: cagney/2003-11-25: Make certain that the target
|
|
||||||
stack's section table is kept up-to-date. Architectures,
|
handle_solib_event ();
|
||||||
(e.g., PPC64), use the section table to perform
|
|
||||||
operations such as address => section name and hence
|
ecs->event_thread->control.stop_bpstat
|
||||||
require the table to contain all sections (including
|
= bpstat_stop_status (get_regcache_aspace (regcache),
|
||||||
those found in shared libraries). */
|
stop_pc, ecs->ptid, &ecs->ws);
|
||||||
#ifdef SOLIB_ADD
|
ecs->random_signal
|
||||||
SOLIB_ADD (NULL, 0, ¤t_target, auto_solib_add);
|
= !bpstat_explains_signal (ecs->event_thread->control.stop_bpstat);
|
||||||
#else
|
|
||||||
solib_add (NULL, 0, ¤t_target, auto_solib_add);
|
if (!ecs->random_signal)
|
||||||
#endif
|
{
|
||||||
target_terminal_inferior ();
|
/* A catchpoint triggered. */
|
||||||
|
ecs->event_thread->suspend.stop_signal = TARGET_SIGNAL_TRAP;
|
||||||
|
goto process_event_stop_test;
|
||||||
|
}
|
||||||
|
|
||||||
/* If requested, stop when the dynamic linker notifies
|
/* If requested, stop when the dynamic linker notifies
|
||||||
gdb of events. This allows the user to get control
|
gdb of events. This allows the user to get control
|
||||||
and place breakpoints in initializer routines for
|
and place breakpoints in initializer routines for
|
||||||
dynamically loaded objects (among other things). */
|
dynamically loaded objects (among other things). */
|
||||||
|
ecs->event_thread->suspend.stop_signal = TARGET_SIGNAL_0;
|
||||||
if (stop_on_solib_events)
|
if (stop_on_solib_events)
|
||||||
{
|
{
|
||||||
/* Make sure we print "Stopped due to solib-event" in
|
/* Make sure we print "Stopped due to solib-event" in
|
||||||
|
@ -3347,9 +3351,6 @@ handle_inferior_event (struct execution_control_state *ecs)
|
||||||
stop_stepping (ecs);
|
stop_stepping (ecs);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* NOTE drow/2007-05-11: This might be a good place to check
|
|
||||||
for "catch load". */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If we are skipping through a shell, or through shared library
|
/* If we are skipping through a shell, or through shared library
|
||||||
|
|
|
@ -149,6 +149,7 @@ release_program_space (struct program_space *pspace)
|
||||||
free_address_space (pspace->aspace);
|
free_address_space (pspace->aspace);
|
||||||
resize_section_table (&pspace->target_sections,
|
resize_section_table (&pspace->target_sections,
|
||||||
-resize_section_table (&pspace->target_sections, 0));
|
-resize_section_table (&pspace->target_sections, 0));
|
||||||
|
clear_program_space_solib_cache (pspace);
|
||||||
/* Discard any data modules have associated with the PSPACE. */
|
/* Discard any data modules have associated with the PSPACE. */
|
||||||
program_space_free_data (pspace);
|
program_space_free_data (pspace);
|
||||||
xfree (pspace);
|
xfree (pspace);
|
||||||
|
@ -503,6 +504,22 @@ switch_to_program_space_and_thread (struct program_space *pspace)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* See progspace.h. */
|
||||||
|
|
||||||
|
void
|
||||||
|
clear_program_space_solib_cache (struct program_space *pspace)
|
||||||
|
{
|
||||||
|
int ix;
|
||||||
|
char *name;
|
||||||
|
|
||||||
|
VEC_free (so_list_ptr, pspace->added_solibs);
|
||||||
|
for (ix = 0; VEC_iterate (char_ptr, pspace->deleted_solibs, ix, name); ++ix)
|
||||||
|
xfree (name);
|
||||||
|
VEC_free (char_ptr, pspace->deleted_solibs);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* Keep a registry of per-program_space data-pointers required by other GDB
|
/* Keep a registry of per-program_space data-pointers required by other GDB
|
||||||
modules. */
|
modules. */
|
||||||
|
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
|
|
||||||
#include "target.h"
|
#include "target.h"
|
||||||
#include "vec.h"
|
#include "vec.h"
|
||||||
|
#include "gdb_vecs.h"
|
||||||
|
|
||||||
struct target_ops;
|
struct target_ops;
|
||||||
struct bfd;
|
struct bfd;
|
||||||
|
@ -32,6 +33,9 @@ struct exec;
|
||||||
struct address_space;
|
struct address_space;
|
||||||
struct program_space_data;
|
struct program_space_data;
|
||||||
|
|
||||||
|
typedef struct so_list *so_list_ptr;
|
||||||
|
DEF_VEC_P (so_list_ptr);
|
||||||
|
|
||||||
/* A program space represents a symbolic view of an address space.
|
/* A program space represents a symbolic view of an address space.
|
||||||
Roughly speaking, it holds all the data associated with a
|
Roughly speaking, it holds all the data associated with a
|
||||||
non-running-yet program (main executable, main symbols), and when
|
non-running-yet program (main executable, main symbols), and when
|
||||||
|
@ -188,6 +192,14 @@ struct program_space
|
||||||
/* Number of calls to solib_add. */
|
/* Number of calls to solib_add. */
|
||||||
unsigned solib_add_generation;
|
unsigned solib_add_generation;
|
||||||
|
|
||||||
|
/* When an solib is added, it is also added to this vector. This
|
||||||
|
is so we can properly report solib changes to the user. */
|
||||||
|
VEC (so_list_ptr) *added_solibs;
|
||||||
|
|
||||||
|
/* When an solib is removed, its name is added to this vector.
|
||||||
|
This is so we can properly report solib changes to the user. */
|
||||||
|
VEC (char_ptr) *deleted_solibs;
|
||||||
|
|
||||||
/* Per pspace data-pointers required by other GDB modules. */
|
/* Per pspace data-pointers required by other GDB modules. */
|
||||||
void **data;
|
void **data;
|
||||||
unsigned num_data;
|
unsigned num_data;
|
||||||
|
@ -278,6 +290,11 @@ extern void update_address_spaces (void);
|
||||||
anymore. */
|
anymore. */
|
||||||
extern void prune_program_spaces (void);
|
extern void prune_program_spaces (void);
|
||||||
|
|
||||||
|
/* Reset saved solib data at the start of an solib event. This lets
|
||||||
|
us properly collect the data when calling solib_add, so it can then
|
||||||
|
later be printed. */
|
||||||
|
extern void clear_program_space_solib_cache (struct program_space *);
|
||||||
|
|
||||||
/* Keep a registry of per-pspace data-pointers required by other GDB
|
/* Keep a registry of per-pspace data-pointers required by other GDB
|
||||||
modules. */
|
modules. */
|
||||||
|
|
||||||
|
|
|
@ -758,6 +758,9 @@ update_solib_list (int from_tty, struct target_ops *target)
|
||||||
unloaded before we remove it from GDB's tables. */
|
unloaded before we remove it from GDB's tables. */
|
||||||
observer_notify_solib_unloaded (gdb);
|
observer_notify_solib_unloaded (gdb);
|
||||||
|
|
||||||
|
VEC_safe_push (char_ptr, current_program_space->deleted_solibs,
|
||||||
|
xstrdup (gdb->so_name));
|
||||||
|
|
||||||
*gdb_link = gdb->next;
|
*gdb_link = gdb->next;
|
||||||
|
|
||||||
/* Unless the user loaded it explicitly, free SO's objfile. */
|
/* Unless the user loaded it explicitly, free SO's objfile. */
|
||||||
|
@ -793,6 +796,7 @@ update_solib_list (int from_tty, struct target_ops *target)
|
||||||
volatile struct gdb_exception e;
|
volatile struct gdb_exception e;
|
||||||
|
|
||||||
i->pspace = current_program_space;
|
i->pspace = current_program_space;
|
||||||
|
VEC_safe_push (so_list_ptr, current_program_space->added_solibs, i);
|
||||||
|
|
||||||
TRY_CATCH (e, RETURN_MASK_ERROR)
|
TRY_CATCH (e, RETURN_MASK_ERROR)
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,3 +1,12 @@
|
||||||
|
2012-01-24 Tom Tromey <tromey@redhat.com>
|
||||||
|
|
||||||
|
* lib/mi-support.exp (mi_expect_stop): Add special case for
|
||||||
|
solib-event.
|
||||||
|
* gdb.base/catch-load-so.c: New file.
|
||||||
|
* gdb.base/catch-load.exp: New file.
|
||||||
|
* gdb.base/catch-load.c: New file.
|
||||||
|
* gdb.base/break-interp.exp (reach_1): Update regexp.
|
||||||
|
|
||||||
2012-01-24 Jan Kratochvil <jan.kratochvil@redhat.com>
|
2012-01-24 Jan Kratochvil <jan.kratochvil@redhat.com>
|
||||||
|
|
||||||
Fix fuzzy results.
|
Fix fuzzy results.
|
||||||
|
|
|
@ -155,7 +155,7 @@ proc reach_1 {func command displacement} {
|
||||||
pass $test
|
pass $test
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
-re "Stopped due to shared library event\r\n$gdb_prompt $" {
|
-re "Stopped due to (spurious )?shared library event.*\r\n$gdb_prompt $" {
|
||||||
if {$func == "_dl_debug_state"} {
|
if {$func == "_dl_debug_state"} {
|
||||||
if {$debug_state_count == 0} {
|
if {$debug_state_count == 0} {
|
||||||
# First stop does not yet relocate the _start function
|
# First stop does not yet relocate the _start function
|
||||||
|
|
22
gdb/testsuite/gdb.base/catch-load-so.c
Normal file
22
gdb/testsuite/gdb.base/catch-load-so.c
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
/* This testcase is part of GDB, the GNU debugger.
|
||||||
|
|
||||||
|
Copyright 2012 Free Software Foundation, Inc.
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation; either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||||
|
|
||||||
|
int
|
||||||
|
f(void)
|
||||||
|
{
|
||||||
|
return 23;
|
||||||
|
}
|
35
gdb/testsuite/gdb.base/catch-load.c
Normal file
35
gdb/testsuite/gdb.base/catch-load.c
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
/* This testcase is part of GDB, the GNU debugger.
|
||||||
|
|
||||||
|
Copyright 2012 Free Software Foundation, Inc.
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation; either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||||
|
|
||||||
|
#include <dlfcn.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
/* This is updated by the .exp file. */
|
||||||
|
char *libname = "catch-load-so.so";
|
||||||
|
|
||||||
|
int
|
||||||
|
main ()
|
||||||
|
{
|
||||||
|
void *h;
|
||||||
|
|
||||||
|
h = dlopen (libname, RTLD_LAZY);
|
||||||
|
|
||||||
|
dlclose (h);
|
||||||
|
|
||||||
|
h = NULL; /* final breakpoint here */
|
||||||
|
return 0;
|
||||||
|
}
|
120
gdb/testsuite/gdb.base/catch-load.exp
Normal file
120
gdb/testsuite/gdb.base/catch-load.exp
Normal file
|
@ -0,0 +1,120 @@
|
||||||
|
# Copyright 2012 Free Software Foundation, Inc.
|
||||||
|
# This program is free software; you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation; either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
|
||||||
|
if {[skip_shlib_tests]} {
|
||||||
|
untested catch-load.exp
|
||||||
|
return -1
|
||||||
|
}
|
||||||
|
|
||||||
|
if {[get_compiler_info not-used]} {
|
||||||
|
warning "Could not get compiler info"
|
||||||
|
untested catch-load.exp
|
||||||
|
return -1
|
||||||
|
}
|
||||||
|
|
||||||
|
set testfile catch-load
|
||||||
|
set srcfile ${testfile}.c
|
||||||
|
set binfile ${objdir}/${subdir}/${testfile}
|
||||||
|
if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug shlib_load}] != "" } {
|
||||||
|
untested catch-load.exp
|
||||||
|
return -1
|
||||||
|
}
|
||||||
|
|
||||||
|
set testfile2 catch-load-so
|
||||||
|
set srcfile2 ${testfile2}.c
|
||||||
|
set binfile2 ${objdir}/${subdir}/${testfile2}.so
|
||||||
|
set binfile2_dlopen [shlib_target_file ${testfile2}.so]
|
||||||
|
if { [gdb_compile_shlib "${srcdir}/${subdir}/${srcfile2}" ${binfile2} {debug}] != "" } {
|
||||||
|
untested catch-load.exp
|
||||||
|
return -1
|
||||||
|
}
|
||||||
|
|
||||||
|
# Run one set of tests.
|
||||||
|
# SCENARIO is the name of the test scenario, it is just used in test
|
||||||
|
# names.
|
||||||
|
# KIND is passed to the "catch" command.
|
||||||
|
# MATCH is a boolean saying whether we expect the catchpoint to be hit.
|
||||||
|
proc one_catch_load_test {scenario kind match sostop} {
|
||||||
|
global verbose testfile testfile2 binfile2_dlopen
|
||||||
|
global pf_prefix srcfile
|
||||||
|
global decimal gdb_prompt
|
||||||
|
|
||||||
|
set saved_prefix $pf_prefix
|
||||||
|
append pf_prefix "${scenario}:"
|
||||||
|
|
||||||
|
clean_restart $testfile
|
||||||
|
gdb_load_shlibs $binfile2_dlopen
|
||||||
|
|
||||||
|
if {![runto_main]} {
|
||||||
|
fail "can't run to main"
|
||||||
|
set pf_prefix $saved_prefix
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
gdb_breakpoint [gdb_get_line_number "final breakpoint here"]
|
||||||
|
gdb_test_no_output "set var libname = \"$binfile2_dlopen\""
|
||||||
|
gdb_test_no_output "set stop-on-solib-events $sostop"
|
||||||
|
gdb_test "catch $kind" "Catchpoint $decimal \\(.*\\)"
|
||||||
|
|
||||||
|
send_gdb "continue\n"
|
||||||
|
gdb_test_multiple "continue" "continue" {
|
||||||
|
-re "Catchpoint $decimal\r\n.*loaded .*/$testfile2.*\r\n.*$gdb_prompt $" {
|
||||||
|
if {$match} {
|
||||||
|
pass "continue"
|
||||||
|
} else {
|
||||||
|
fail "continue"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
-re "Stopped due to shared library event.*\r\n$gdb_prompt $" {
|
||||||
|
if {$sostop} {
|
||||||
|
pass "continue"
|
||||||
|
} else {
|
||||||
|
fail "continue"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
-re "Breakpoint $decimal, .*\r\n$gdb_prompt $" {
|
||||||
|
if {!$match} {
|
||||||
|
pass "continue"
|
||||||
|
} else {
|
||||||
|
fail "continue"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
-re ".*$gdb_prompt $" {
|
||||||
|
fail "continue"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
set pf_prefix $saved_prefix
|
||||||
|
}
|
||||||
|
|
||||||
|
one_catch_load_test "plain load" "load" 1 0
|
||||||
|
one_catch_load_test "plain load with stop-on-solib-events" "load" 1 1
|
||||||
|
one_catch_load_test "rx load" "load $testfile2" 1 0
|
||||||
|
one_catch_load_test "rx load with stop-on-solib-events" "load $testfile2" 1 1
|
||||||
|
one_catch_load_test "non-matching load" "load zardoz" 0 0
|
||||||
|
one_catch_load_test "non-matching load with stop-on-solib-events" \
|
||||||
|
"load zardoz" 0 1
|
||||||
|
|
||||||
|
one_catch_load_test "plain unload" "unload" 1 0
|
||||||
|
one_catch_load_test "plain unload with stop-on-solib-events" "unload" 1 1
|
||||||
|
one_catch_load_test "rx unload" "unload $testfile2" 1 0
|
||||||
|
one_catch_load_test "rx unload with stop-on-solib-events" \
|
||||||
|
"unload $testfile2" 1 1
|
||||||
|
one_catch_load_test "non-matching unload" "unload zardoz" 0 0
|
||||||
|
one_catch_load_test "non-matching unload with stop-on-solib-events" \
|
||||||
|
"unload zardoz" 0 1
|
|
@ -1060,6 +1060,8 @@ proc mi_expect_stop { reason func args file line extra test } {
|
||||||
set bn ""
|
set bn ""
|
||||||
if { $reason == "breakpoint-hit" } {
|
if { $reason == "breakpoint-hit" } {
|
||||||
set bn {bkptno="[0-9]+",}
|
set bn {bkptno="[0-9]+",}
|
||||||
|
} elseif { $reason == "solib-event" } {
|
||||||
|
set bn ".*"
|
||||||
}
|
}
|
||||||
|
|
||||||
set r ""
|
set r ""
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue