From: Jeff Johnston <jjohnstn@redhat.com>
To: Daniel Jacobowitz <drow@false.org>
Cc: gdb-patches@sources.redhat.com
Subject: Re: [RFA]: Fix for pending breakpoints in manually loaded/unloaded shlibs
Date: Wed, 11 Aug 2004 20:12:00 -0000 [thread overview]
Message-ID: <411A7D97.50104@redhat.com> (raw)
In-Reply-To: <20040811171203.GA4152@nevyn.them.org>
[-- Attachment #1: Type: text/plain, Size: 3008 bytes --]
Daniel Jacobowitz wrote:
> On Tue, Aug 10, 2004 at 03:09:37PM -0400, Jeff Johnston wrote:
>
>>The following patch fixes a problem with breakpoints set in shlibs that are
>>manually loaded/unloaded by the program. What currently happens is that
>>pending breakpoints work properly for the first run of the program. On the
>>2nd run, the resolved breakpoint(s) can end up at the start of the
>>breakpoint list and is marked bp_shlib_disabled. This is fine for a bit
>>and we reach the breakpoint again when the shared library is loaded.
>>However, when we unload the 2nd time, there is trouble. We eventually get
>>a shlib_event from the dlclose() and we attempt to remove the breakpoint to
>>step over it. Unfortunately, we try and remove all breakpoints and we end
>>attempting to remove a breakpoint that no longer exists (remember the
>>breakpoint for the shared library routine is now at the start of the
>>breakpoint list). We fail trying to remove the first breakpoint and end up
>>failing remove_breakpoints. We subsequently keep running into the
>>shlib_event breakpoint over and over again ad-infinitum.
>
>
> I couldn't quite follow your explanation of the problem, but FWIW your
> patch does make sense to me.
>
> Please check it for coding style problems; I noticed a lot of operators
> at the end of lines instead of the beginning of the next line.
>
Noted. Fixed in appended patch.
>
>>+#if defined (PC_SOLIB)
>>+ if (((b->type == bp_breakpoint) ||
>>+ (b->type == bp_hardware_breakpoint)) &&
>>+ breakpoint_enabled (b) &&
>>+ !b->loc->duplicate)
>
>
> You are just grabbing this from disable_breakpoints_in_shlibs, but the
> b->type check is not correct. Try
> (b->loc->type == bp_loc_hardware_breakpoint
> || b->loc->type == bp_loc_software_breakpoint)
>
Done.
> [Conceptually, you want any breakpoint which corresponds to a code
> address.]
>
> Can this code be commonized rather than duplicated?
>
I don't see much value; the code is small, the test is now different, the input
parameter is different, and there is resetting of the inserted flag.
>
>>+ {
>>+ char *so_name = PC_SOLIB (b->loc->address);
>>+ if (so_name &&
>>+ !strcmp (so_name, solib->so_name))
>>+ {
>>+ b->enable_state = bp_shlib_disabled;
>>+ b->loc->inserted = 0;
>
>
> Are we guaranteed that the breakpoint is not inserted right now? This
> is the only place in breakpoint.c that changes the inserted flag
> directly other than initialization, insertion, and a hack for exec
> following.
>
> If you expect that the library has already been unmapped, so removing
> it would fail, please add a comment saying so.
>
Putting remove_breakpoint() at that point does not work. I have put the
following comment:
+ /* At this point, we cannot rely on remove_breakpoint
+ succeeding so we must mark the breakpoint as not inserted
+ to prevent future errors occurring in remove_breakpoints. */
Ok?
-- Jeff J.
[-- Attachment #2: unload.patch2 --]
[-- Type: text/plain, Size: 6744 bytes --]
Index: doc/observer.texi
===================================================================
RCS file: /cvs/src/src/gdb/doc/observer.texi,v
retrieving revision 1.7
diff -u -p -r1.7 observer.texi
--- doc/observer.texi 21 May 2004 16:04:03 -0000 1.7
+++ doc/observer.texi 11 Aug 2004 17:48:25 -0000
@@ -90,3 +90,8 @@ at the entry-point instruction. For @sa
@value{GDBN} calls this observer immediately after connecting to the
inferior, and before any information on the inferior has been printed.
@end deftypefun
+
+@deftypefun void solib_unloaded (struct so_list *@var{solib})
+The specified shared library has been discovered to be unloaded.
+@end deftypefun
+
Index: Makefile.in
===================================================================
RCS file: /cvs/src/src/gdb/Makefile.in,v
retrieving revision 1.607
diff -u -p -r1.607 Makefile.in
--- Makefile.in 8 Aug 2004 19:27:09 -0000 1.607
+++ Makefile.in 11 Aug 2004 17:48:26 -0000
@@ -1718,7 +1718,7 @@ breakpoint.o: breakpoint.c $(defs_h) $(s
$(gdb_string_h) $(demangle_h) $(annotate_h) $(symfile_h) \
$(objfiles_h) $(source_h) $(linespec_h) $(completer_h) $(gdb_h) \
$(ui_out_h) $(cli_script_h) $(gdb_assert_h) $(block_h) \
- $(gdb_events_h)
+ $(gdb_events_h) $(observer_h) $(solist_h)
bsd-kvm.o: bsd-kvm.c $(defs_h) $(cli_cmds_h) $(command_h) $(frame_h) \
$(regcache_h) $(target_h) $(value_h) $(gdb_assert_h) $(readline_h) \
$(bsd_kvm_h)
@@ -2450,7 +2450,8 @@ solib-aix5.o: solib-aix5.c $(defs_h) $(g
solib.o: solib.c $(defs_h) $(gdb_string_h) $(symtab_h) $(bfd_h) $(symfile_h) \
$(objfiles_h) $(gdbcore_h) $(command_h) $(target_h) $(frame_h) \
$(gdb_regex_h) $(inferior_h) $(environ_h) $(language_h) $(gdbcmd_h) \
- $(completer_h) $(filenames_h) $(exec_h) $(solist_h) $(readline_h)
+ $(completer_h) $(filenames_h) $(exec_h) $(solist_h) $(readline_h) \
+ $(observer_h)
solib-frv.o: solib-frv.c $(defs_h) $(gdb_string_h) $(inferior_h) \
$(gdbcore_h) $(solist_h) $(frv_tdep_h) $(objfiles_h) $(symtab_h) \
$(language_h) $(command_h) $(gdbcmd_h) $(elf_frv_h)
Index: breakpoint.c
===================================================================
RCS file: /cvs/src/src/gdb/breakpoint.c,v
retrieving revision 1.179
diff -u -p -r1.179 breakpoint.c
--- breakpoint.c 28 Jul 2004 17:26:26 -0000 1.179
+++ breakpoint.c 11 Aug 2004 17:48:26 -0000
@@ -49,6 +49,8 @@
#include "cli/cli-script.h"
#include "gdb_assert.h"
#include "block.h"
+#include "solist.h"
+#include "observer.h"
#include "gdb-events.h"
@@ -4388,6 +4390,46 @@ disable_breakpoints_in_shlibs (int silen
}
}
+/* Disable any breakpoints that are in in an unloaded shared library. Only
+ apply to enabled breakpoints, disabled ones can just stay disabled. */
+
+void
+disable_breakpoints_in_unloaded_shlib (struct so_list *solib)
+{
+ struct breakpoint *b;
+ int disabled_shlib_breaks = 0;
+
+ /* See also: insert_breakpoints, under DISABLE_UNSETTABLE_BREAK. */
+ ALL_BREAKPOINTS (b)
+ {
+#if defined (PC_SOLIB)
+ if ((b->loc->loc_type == bp_loc_hardware_breakpoint
+ || b->loc->loc_type == bp_loc_software_breakpoint)
+ && breakpoint_enabled (b)
+ && !b->loc->duplicate)
+ {
+ char *so_name = PC_SOLIB (b->loc->address);
+ if (so_name
+ && !strcmp (so_name, solib->so_name))
+ {
+ b->enable_state = bp_shlib_disabled;
+ /* At this point, we cannot rely on remove_breakpoint
+ succeeding so we must mark the breakpoint as not inserted
+ to prevent future errors occurring in remove_breakpoints. */
+ b->loc->inserted = 0;
+ if (!disabled_shlib_breaks)
+ {
+ target_terminal_ours_for_output ();
+ warning ("Temporarily disabling unloaded shared library breakpoints:");
+ }
+ disabled_shlib_breaks = 1;
+ warning ("breakpoint #%d ", b->number);
+ }
+ }
+#endif
+ }
+}
+
/* Try to reenable any breakpoints in shared libraries. */
void
re_enable_breakpoints_in_shlibs (void)
@@ -7100,6 +7142,8 @@ breakpoint_re_set_one (void *bint)
struct breakpoint *b = (struct breakpoint *) bint;
struct value *mark;
int i;
+ int not_found;
+ int *not_found_ptr = NULL;
struct symtabs_and_lines sals;
char *s;
enum enable_state save_enable;
@@ -7150,11 +7194,19 @@ breakpoint_re_set_one (void *bint)
save_enable = b->enable_state;
if (b->enable_state != bp_shlib_disabled)
b->enable_state = bp_disabled;
+ else
+ /* If resetting a shlib-disabled breakpoint, we don't want to
+ see an error message if it is not found since we will expect
+ this to occur until the shared library is finally reloaded.
+ We accomplish this by giving decode_line_1 a pointer to use
+ for silent notification that the symbol is not found. */
+ not_found_ptr = ¬_found;
set_language (b->language);
input_radix = b->input_radix;
s = b->addr_string;
- sals = decode_line_1 (&s, 1, (struct symtab *) NULL, 0, (char ***) NULL, NULL);
+ sals = decode_line_1 (&s, 1, (struct symtab *) NULL, 0, (char ***) NULL,
+ not_found_ptr);
for (i = 0; i < sals.nelts; i++)
{
resolve_sal_pc (&sals.sals[i]);
@@ -7755,6 +7807,10 @@ _initialize_breakpoint (void)
static struct cmd_list_element *breakpoint_show_cmdlist;
struct cmd_list_element *c;
+#ifdef SOLIB_ADD
+ observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib);
+#endif
+
breakpoint_chain = 0;
/* Don't bother to call set_breakpoint_count. $bpnum isn't useful
before a breakpoint is set. */
Index: observer.sh
===================================================================
RCS file: /cvs/src/src/gdb/observer.sh,v
retrieving revision 1.3
diff -u -p -r1.3 observer.sh
--- observer.sh 7 May 2004 22:51:52 -0000 1.3
+++ observer.sh 11 Aug 2004 17:48:26 -0000
@@ -52,6 +52,7 @@ case $lang in
struct observer;
struct bpstats;
+struct so_list;
EOF
;;
esac
Index: solib.c
===================================================================
RCS file: /cvs/src/src/gdb/solib.c,v
retrieving revision 1.66
diff -u -p -r1.66 solib.c
--- solib.c 30 Jul 2004 19:17:19 -0000 1.66
+++ solib.c 11 Aug 2004 17:48:26 -0000
@@ -42,6 +42,7 @@
#include "filenames.h" /* for DOSish file names */
#include "exec.h"
#include "solist.h"
+#include "observer.h"
#include "readline/readline.h"
/* external data declarations */
@@ -478,6 +479,10 @@ update_solib_list (int from_tty, struct
/* If it's not on the inferior's list, remove it from GDB's tables. */
else
{
+ /* Notify any observer that the SO has been unloaded
+ before we remove it from the gdb tables. */
+ observer_notify_solib_unloaded (gdb);
+
*gdb_link = gdb->next;
/* Unless the user loaded it explicitly, free SO's objfile. */
next prev parent reply other threads:[~2004-08-11 20:12 UTC|newest]
Thread overview: 48+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-08-10 19:09 Jeff Johnston
2004-08-10 19:45 ` Kevin Buettner
2004-08-11 4:07 ` Eli Zaretskii
2004-08-11 15:58 ` Jeff Johnston
2004-08-11 16:58 ` Andrew Cagney
2004-08-11 17:59 ` Eli Zaretskii
2004-08-11 20:42 ` Andrew Cagney
2004-08-11 20:47 ` Daniel Jacobowitz
2004-08-11 22:19 ` Andrew Cagney
2004-08-12 12:58 ` Daniel Jacobowitz
2004-08-12 13:16 ` New observer objfile_mapped; was Andrew Cagney
2004-08-12 13:18 ` Daniel Jacobowitz
2004-08-12 3:45 ` [RFA]: Fix for pending breakpoints in manually loaded/unloaded shlibs Eli Zaretskii
2004-08-12 12:10 ` Andrew Cagney
2004-08-12 18:49 ` Eli Zaretskii
2004-08-12 20:44 ` Andrew Cagney
2004-08-14 11:50 ` Eli Zaretskii
2004-08-18 13:45 ` Daniel Jacobowitz
2004-08-19 3:57 ` Eli Zaretskii
2004-08-11 8:09 ` Michael Chastain
2004-08-11 15:42 ` Jeff Johnston
2004-08-12 13:05 ` Michael Chastain
2004-08-12 13:33 ` Michael Chastain
2004-08-12 17:47 ` Jeff Johnston
2004-08-12 18:59 ` Michael Chastain
2004-08-12 20:23 ` Jeff Johnston
2004-08-11 17:12 ` Daniel Jacobowitz
2004-08-11 20:12 ` Jeff Johnston [this message]
2004-08-18 13:56 ` Daniel Jacobowitz
2004-08-18 19:22 ` Jeff Johnston
2004-08-18 19:39 ` Daniel Jacobowitz
2004-08-18 20:03 ` Jeff Johnston
2004-08-19 4:01 ` Eli Zaretskii
2004-09-01 15:15 ` Andrew Cagney
2004-09-01 18:01 ` Jeff Johnston
2004-09-01 19:30 ` Michael Chastain
2004-09-01 20:44 ` Jeff Johnston
2004-09-01 20:59 ` Michael Chastain
2004-09-01 23:27 ` Jeff Johnston
2004-09-02 3:54 ` Eli Zaretskii
2004-08-23 21:33 ` Jeff Johnston
2004-08-23 22:09 ` Michael Chastain
2004-08-23 22:35 ` Jeff Johnston
2004-08-24 2:26 ` Michael Chastain
2004-08-24 15:51 ` Jeff Johnston
2004-08-24 16:04 ` Michael Chastain
2004-08-12 2:48 ` Andrew Cagney
2004-08-12 3:54 ` Eli Zaretskii
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=411A7D97.50104@redhat.com \
--to=jjohnstn@redhat.com \
--cc=drow@false.org \
--cc=gdb-patches@sources.redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox