Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Pedro Alves <pedro@codesourcery.com>
To: gdb-patches@sourceware.org
Subject: Fix 'catch catch' crash
Date: Wed, 29 Apr 2009 19:35:00 -0000	[thread overview]
Message-ID: <200904292035.17446.pedro@codesourcery.com> (raw)

Brain short-circuited, fingers slipped, and instead of typing "watch C", I
typed "catch C", go figure, and, puff!

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7ffff7fd36e0 (LWP 30252)]
0x00000000004dfa7b in print_mention_exception_catchpoint (b=0xc35ac0) at ../../src/gdb/breakpoint.c:7044
7044      bp_temp = b->loc->owner->disposition == disp_del;

(top-gdb) p b->loc
$4 = (struct bp_location *) 0x0

I've fixed this with the obvious patch below.

Long version:

(top-gdb) bt
#0  0x00000000004dfa7b in print_mention_exception_catchpoint (b=0xc35ac0) at ../../src/gdb/breakpoint.c:7044
#1  0x00000000004dc454 in mention (b=0xc35ac0) at ../../src/gdb/breakpoint.c:5335
#2  0x00000000004ddf01 in break_command_really (arg=0x730b59 "", cond_string=0x0, thread=-1,
    parse_condition_and_thread=0, tempflag=0, hardwareflag=0, traceflag=0, ignore_count=0,
    pending_break_support=AUTO_BOOLEAN_TRUE, ops=0xab3e20, from_tty=1, enabled=1) at ../../src/gdb/breakpoint.c:6164
#3  0x00000000004dfbac in handle_gnu_v3_exceptions (tempflag=0, cond_string=0x0, ex_event=EX_EVENT_CATCH, from_tty=1)
    at ../../src/gdb/breakpoint.c:7073
#4  0x00000000004dfc7f in catch_exception_command_1 (ex_event=EX_EVENT_CATCH, arg=0x72fd6b "", tempflag=0,
    from_tty=1) at ../../src/gdb/breakpoint.c:7106
#5  0x00000000004dfcd9 in catch_catch_command (arg=0x0, from_tty=1, command=0xb07390)
    at ../../src/gdb/breakpoint.c:7118
#6  0x00000000004a9ca5 in do_sfunc (c=0xb07390, args=0x0, from_tty=1) at ../../src/gdb/cli/cli-decode.c:83
#7  0x00000000004acadb in cmd_func (cmd=0xb07390, args=0x0, from_tty=1) at ../../src/gdb/cli/cli-decode.c:1745
During symbol reading, DW_AT_type missing from DW_TAG_subrange_type.
#8  0x000000000045beea in execute_command (p=0xadf1e7 "", from_tty=1) at ../../src/gdb/top.c:445
#9  0x000000000053f45b in command_handler (command=0xadf1e0 "catch C") at ../../src/gdb/event-top.c:514

"catch C" is actually "catch catch".

The issue here is that since I didn't have any symbols
loaded in GDB:

 >./gdb
 GNU gdb (GDB) 6.8.50.20090427-cvs
 (...)
 (gdb) catch catch
 No symbol table is loaded.  Use the "file" command.
 Segmentation fault

and the "catch catch" catchpoint is implemented with a breakpoint,
this breakpoint was left pending, hence b->loc == NULL.  Then,
`mention' tried to print it, but print_mention_exception_catchpoint
accesses `b->loc->owner'.  This indirection is unnecessary.  If
`b->loc->owner' points to something other than `b', then
we have bigger troubles elsewhere.

BTW, GDB 6.8 used to just refuse to set the catchpoint:

 (gdb) catch catch
 No symbol table is loaded.  Use the "file" command.
 (gdb) info breakpoints
 No breakpoints or watchpoints.

I think it does makes sense to leave the internal
breakpoint pending.  E.g, after the crash is fixed, I get:

 (gdb) catch catch
 Function "__cxa_begin_catch" not defined.
 Catchpoint 1 (catch)
 (gdb) info breakpoints
 Num     Type           Disp Enb Address            What
 1       breakpoint     keep y   <PENDING>          exception catch
 (gdb) start
 Temporary breakpoint 2 at 0x40053c: file ../../../src/gdb/testsuite/gdb.cp/gdb1355.cc, line 34.
 Starting program: /home/pedro/gdb/mainline/build/gdb/testsuite/gdb.cp/gdb1355

 Temporary breakpoint 2, main () at ../../../src/gdb/testsuite/gdb.cp/gdb1355.cc:34
 34        return 0;
 (gdb) info breakpoints
 Num     Type           Disp Enb Address            What
 1       breakpoint     keep y   0x00007ffff7b983c0 exception catch
 (gdb)     

The nagging about not finding the "__cxa_begin_catch" function
could be hidden from the user; and one argue that the "Type" should
show "catchpoint"; and the "Address" should not show through to
the user the address of the internal breakpoint used, but ...

I just want GDB to not crash on me when I do a dumb typo!

-- 
Pedro Alves

2009-04-29  Pedro Alves  <pedro@codesourcery.com>

	* breakpoint.c (print_exception_catchpoint): Access `b' directly
	instead of `b->loc->owner'.
	(print_mention_exception_catchpoint): Ditto.

---
 gdb/breakpoint.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Index: src/gdb/breakpoint.c
===================================================================
--- src.orig/gdb/breakpoint.c	2009-04-29 20:11:58.000000000 +0100
+++ src/gdb/breakpoint.c	2009-04-29 20:13:59.000000000 +0100
@@ -6631,7 +6631,7 @@ print_exception_catchpoint (struct break
     breakpoint_adjustment_warning (b->loc->requested_address,
 	                           b->loc->address,
 				   b->number, 1);
-  bp_temp = b->loc->owner->disposition == disp_del;
+  bp_temp = b->disposition == disp_del;
   ui_out_text (uiout, 
 	       bp_temp ? "Temporary catchpoint "
 		       : "Catchpoint ");
@@ -6678,7 +6678,7 @@ print_mention_exception_catchpoint (stru
   int bp_temp;
   int bp_throw;
 
-  bp_temp = b->loc->owner->disposition == disp_del;
+  bp_temp = b->disposition == disp_del;
   bp_throw = strstr (b->addr_string, "throw") != NULL;
   ui_out_text (uiout, bp_temp ? _("Temporary catchpoint ")
 			      : _("Catchpoint "));


             reply	other threads:[~2009-04-29 19:35 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-04-29 19:35 Pedro Alves [this message]
2009-04-29 21:06 ` Tom Tromey
2009-04-30 22:46   ` Pedro Alves

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=200904292035.17446.pedro@codesourcery.com \
    --to=pedro@codesourcery.com \
    --cc=gdb-patches@sourceware.org \
    /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