From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 26474 invoked by alias); 20 Nov 2008 12:08:02 -0000 Received: (qmail 26244 invoked by uid 22791); 20 Nov 2008 12:08:01 -0000 X-Spam-Check-By: sourceware.org Received: from imx12.toshiba.co.jp (HELO imx12.toshiba.co.jp) (61.202.160.132) by sourceware.org (qpsmtpd/0.31) with ESMTP; Thu, 20 Nov 2008 12:07:03 +0000 Received: from arc11.toshiba.co.jp ([133.199.90.127]) by imx12.toshiba.co.jp with ESMTP id mAKC6xTI013085 for ; Thu, 20 Nov 2008 21:06:59 +0900 (JST) Received: (from root@localhost) by arc11.toshiba.co.jp id mAKC6xVm011752 for gdb-patches@sourceware.org; Thu, 20 Nov 2008 21:06:59 +0900 (JST) Received: from ovp11.toshiba.co.jp [133.199.90.148] by arc11.toshiba.co.jp with ESMTP id XAA11751; Thu, 20 Nov 2008 21:06:59 +0900 Received: from mx11.toshiba.co.jp (localhost [127.0.0.1]) by ovp11.toshiba.co.jp with ESMTP id mAKC6xNs014928 for ; Thu, 20 Nov 2008 21:06:59 +0900 (JST) Received: from mx.tjsys.co.jp by toshiba.co.jp id mAKC6xWU024425; Thu, 20 Nov 2008 21:06:59 +0900 (JST) Received: from voltage-out.tjsys.co.jp (voltage-out.tjsys.co.jp [157.79.3.51]) by mx.tjsys.co.jp (8.12.11/8.12.11) with ESMTP id mAKC6xd6007865 for ; Thu, 20 Nov 2008 21:06:59 +0900 (JST) Received: from is-com10 ([157.79.3.71]) by voltage-out.tjsys.co.jp (8.13.1/8.13.1) with SMTP id mAKC6rwi015065 for ; Thu, 20 Nov 2008 21:06:54 +0900 Received: from localhost ([157.79.30.241]) by ims.tjsys.co.jp (iPlanet Messaging Server 5.2 HotFix 2.10 (built Dec 26 2005)) with ESMTP id <0KAM0011YSBGFV@ims.tjsys.co.jp> for gdb-patches@sourceware.org; Thu, 20 Nov 2008 21:06:52 +0900 (JST) Date: Thu, 20 Nov 2008 18:25:00 -0000 From: Emi SUZUKI Subject: Watchpoint on an unloaded shared library(1) To: gdb-patches@sourceware.org Message-id: <20081120.210657.01365938.emi-suzuki@tjsys.co.jp> MIME-version: 1.0 X-Mailer: Mew version 6.1 on Emacs 22.1 / Mule 5.0 (SAKAKI) Content-type: Text/Plain; charset=us-ascii Content-transfer-encoding: 7bit X-WAuditID: 0811202106520000005484 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: 2008-11/txt/msg00552.txt.bz2 Hello members, I've now faced three issues related to a watchpoint on an unloaded shared library: a segfault causes on GDB when referring to a watchpoint which is invalid at that time. Now I will report them separately. To begin with, I will provide a sample to reproduce all the issues: ----------------------------- dl-main.c: #include #include #include #include static void (*sample) (void); int main (void) { void *handle; if ((handle = dlopen("./libsample.so", RTLD_LAZY)) == NULL) errx(2, "dlopen(): %s", dlerror()); if ((sample = dlsym(handle, "sample")) == NULL) errx(2, "dlsym(): %s", dlerror()); sample (); if (dlclose(handle) < 0) errx(2, "dlclose(): %s", dlerror()); return 0; } ----------------------------- sample.c: #include int sample_glob = 1; void sample (void) { puts ("sample of shared library"); ++sample_glob; } ----------------------------- Build: $ gcc -c -g -Wall sample.c $ gcc -o libsample.so -shared sample.o $ gcc -c -g -Wall dl-test.c $ gcc -o dl-test dl-test.o -ldl ----------------------------- And the first issue: ----------------------------- $ gdb ./dl-test GNU gdb (GDB) 6.8.50.20081114-cvs Copyright (C) 2008 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "i686-pc-linux-gnu". For bug reporting instructions, please see: ... (gdb) start Temporary breakpoint 1 at 0x80484e5: file dl-test.c, line 13. Starting program: /home/suzuki/test/dl-test Temporary breakpoint 1, main () at dl-test.c:14 13 if ((handle = dlopen("./libsample.so", RTLD_LAZY)) == NULL) (gdb) next 16 if ((sample = dlsym(handle, "sample")) == NULL) (gdb) watch sample_glob Hardware watchpoint 2: sample_glob (gdb) continue Continuing. sample of shared library Hardware watchpoint 2: sample_glob Old value = 1 New value = 2 sample () at sample.c:10 10 } (gdb) disable 2 (gdb) c Continuing. Program exited normally. (gdb) start Temporary breakpoint 3 at 0x80484e5: file dl-test.c, line 13. Starting program: /homer/suzuki/test/dl-test Error in re-setting breakpoint 2: No symbol "sample_glob" in current context. Error in re-setting breakpoint 2: No symbol "sample_glob" in current context. Error in re-setting breakpoint 2: No symbol "sample_glob" in current context. Error in re-setting breakpoint 2: No symbol "sample_glob" in current context. Temporary breakpoint 3, main () at dl-test.c:13 13 if ((handle = dlopen("./libsample.so", RTLD_LAZY)) == NULL) (gdb) enable 2 sample of shared library Segmentation fault $ ----------------------------- The cause is rather simple: the pointer to struct expression in struct breakpoint (`bpt->exp') is set to NULL in breakpoint_re_set, when the program was restarted and the shared library in which the watchpoint expression is valid has not been loaded yet. However, do_enable_breakpoint does not care about it. The patch below addresses to the issue. Is that OK? 2008-11-20 Emi Suzuki * breakpoint.c (do_enable_breakpoint): Inform the user and return from the function if the expression of a watchpoint is invalid and cannot be updated. diff src/gdb/breakpoint.c.orig src/gdb/breakpoint.c --- src/gdb/breakpoint.c.orig 2008-11-20 18:52:13.000000000 +0900 +++ src/gdb/breakpoint.c 2008-11-20 18:52:56.000000000 +0900 @@ -7756,6 +7756,18 @@ is valid is not currently in scope.\n"), } select_frame (fr); } + + if (bpt->exp == NULL) + { + char *s = bpt->exp_string; + if (!gdb_parse_exp_1 (&s, bpt->exp_valid_block, 0, &bpt->exp)) + { + printf_filtered (_("\ +Cannot enable watchpoint %d because the block in which its expression\n\ +is valid is not exist.\n"), bpt->number); + return; + } + } if (bpt->val) value_free (bpt->val); My best regards, -- Emi SUZUKI / emi-suzuki at tjsys.co.jp