From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 25212 invoked by alias); 29 Apr 2009 19:35:18 -0000 Received: (qmail 25204 invoked by uid 22791); 29 Apr 2009 19:35:17 -0000 X-SWARE-Spam-Status: No, hits=-2.4 required=5.0 tests=AWL,BAYES_00,SPF_PASS,WEIRD_PORT X-Spam-Check-By: sourceware.org Received: from mail.codesourcery.com (HELO mail.codesourcery.com) (65.74.133.4) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 29 Apr 2009 19:35:12 +0000 Received: (qmail 6551 invoked from network); 29 Apr 2009 19:35:10 -0000 Received: from unknown (HELO orlando) (pedro@127.0.0.2) by mail.codesourcery.com with ESMTPA; 29 Apr 2009 19:35:10 -0000 From: Pedro Alves To: gdb-patches@sourceware.org Subject: Fix 'catch catch' crash Date: Wed, 29 Apr 2009 19:35:00 -0000 User-Agent: KMail/1.9.10 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200904292035.17446.pedro@codesourcery.com> X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2009-04/txt/msg00790.txt.bz2 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 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 * 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 "));