From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 11391 invoked by alias); 28 Aug 2006 23:19:54 -0000 Received: (qmail 11380 invoked by uid 22791); 28 Aug 2006 23:19:53 -0000 X-Spam-Check-By: sourceware.org Received: from e34.co.us.ibm.com (HELO e34.co.us.ibm.com) (32.97.110.152) by sourceware.org (qpsmtpd/0.31) with ESMTP; Mon, 28 Aug 2006 23:19:52 +0000 Received: from d03relay04.boulder.ibm.com (d03relay04.boulder.ibm.com [9.17.195.106]) by e34.co.us.ibm.com (8.13.8/8.12.11) with ESMTP id k7SNJopZ029531 for ; Mon, 28 Aug 2006 19:19:50 -0400 Received: from d03av02.boulder.ibm.com (d03av02.boulder.ibm.com [9.17.195.168]) by d03relay04.boulder.ibm.com (8.13.6/8.13.6/NCO v8.1.1) with ESMTP id k7SNJoK1258786 for ; Mon, 28 Aug 2006 17:19:50 -0600 Received: from d03av02.boulder.ibm.com (loopback [127.0.0.1]) by d03av02.boulder.ibm.com (8.12.11.20060308/8.13.3) with ESMTP id k7SNJn1a006934 for ; Mon, 28 Aug 2006 17:19:49 -0600 Received: from dufur.beaverton.ibm.com (dufur.beaverton.ibm.com [9.47.22.20]) by d03av02.boulder.ibm.com (8.12.11.20060308/8.12.11) with ESMTP id k7SNJnNl006922; Mon, 28 Aug 2006 17:19:49 -0600 Subject: breaks at thread create and delete fail on PPC64/Linux From: PAUL GILLIAM Reply-To: pgilliam@us.ibm.com To: gdb@sources.redhat.com Cc: sjmunroe@us.ibm.com Content-Type: multipart/mixed; boundary="=-B0kRuHovpk6CD2CzjPp8" Date: Mon, 28 Aug 2006 23:19:00 -0000 Message-Id: <1156806903.5898.29.camel@dufur.beaverton.ibm.com> Mime-Version: 1.0 X-Mailer: Evolution 2.2.2 (2.2.2-5) X-IsSubscribed: yes Mailing-List: contact gdb-help@sourceware.org; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-owner@sourceware.org X-SW-Source: 2006-08/txt/msg00204.txt.bz2 --=-B0kRuHovpk6CD2CzjPp8 Content-Type: text/plain Content-Transfer-Encoding: 7bit Content-length: 2675 Here is an example: > gdb example64 (gdb) start Breakpoint 1 at 0x10000734: file example.c, line 10. Starting program: /home/pgilliam/example64 [Thread debugging using libthread_db enabled] [New Thread 4398046665456 (LWP 9443)] Warning: Cannot insert breakpoint -2. Error accessing memory address 0x9ce0: Input/output error. Cannot insert breakpoint -3. Error accessing memory address 0x9cf0: Input/output error. (gdb) Here is the problem: 1) In linux-thread-db.c: enable_thread_event(), The routine "td_ta_event_addr" in the library "thread_db" gets called and returns a function descriptor for the address at which to set the breakpoints for the "create" and "delete" thread events in the "pthread" library. 2) These address point at PLT entries in the '.opd' section. 3) 'dereferencing' the function descriptor should give the actual address at which to set a breakpoint, but gives instead the offset within the "pthread" library where the breakpoint should be placed. The attached patch 'fixes' the problem by looking up the load address of the "pthread" library and adding that to the address from the PLT. This seems to do the trick, but THIS HAS ONLY BEEN TESTED WITH A 64-BIT GDB AND A 64-BIT TARGET. And it's a real HACK!!! But it does illustrate the problem. So, should I try to change GDB so that enable_thread_event() gets called after the dynamic loader has has a chance to relocate the .opd? or Find a better place way to do the relocation for just these two things? -=# Paul Gilliam #=- --- /home/pgilliam/linux-thread-db.c 2006-08-17 02:27:05.000000000 -0700 +++ hacked.linux-thread-db.c 2006-08-17 02:29:16.000000000 -0700 @@ -497,6 +497,7 @@ static td_err_e enable_thread_event (td_thragent_t *thread_agent, int event, CORE_ADDR *bp) { + static CORE_ADDR thread_lib_reloc = 0; td_notify_t notify; td_err_e err; @@ -514,7 +515,24 @@ ? (CORE_ADDR) (intptr_t) notify.u.bptaddr : (CORE_ADDR) (uintptr_t) notify.u.bptaddr), ¤t_target)); - create_thread_event_breakpoint ((*bp)); + if (! thread_lib_reloc) { + char tbuf[1024]; + FILE *pmf; + + sprintf (tbuf, "/proc/%d/maps", proc_handle.pid); + pmf = fopen (tbuf, "r"); + if (pmf) { + while (fgets( tbuf, sizeof(tbuf), pmf)) { + char *cp = rindex (tbuf, '/'); + if (cp && strncmp (cp+1, "libpthread", 10) == 0) { + thread_lib_reloc = (CORE_ADDR) strtol (tbuf, 0, 16); + break; + } + } + fclose (pmf); + } + } + create_thread_event_breakpoint ((*bp) + thread_lib_reloc); return TD_OK; } --=-B0kRuHovpk6CD2CzjPp8 Content-Disposition: attachment; filename=hack.patch Content-Type: text/x-patch; name=hack.patch; charset=UTF-8 Content-Transfer-Encoding: 7bit Content-length: 1039 --- /home/pgilliam/linux-thread-db.c 2006-08-17 02:27:05.000000000 -0700 +++ hacked.linux-thread-db.c 2006-08-17 02:29:16.000000000 -0700 @@ -497,6 +497,7 @@ static td_err_e enable_thread_event (td_thragent_t *thread_agent, int event, CORE_ADDR *bp) { + static CORE_ADDR thread_lib_reloc = 0; td_notify_t notify; td_err_e err; @@ -514,7 +515,24 @@ ? (CORE_ADDR) (intptr_t) notify.u.bptaddr : (CORE_ADDR) (uintptr_t) notify.u.bptaddr), ¤t_target)); - create_thread_event_breakpoint ((*bp)); + if (! thread_lib_reloc) { + char tbuf[1024]; + FILE *pmf; + + sprintf (tbuf, "/proc/%d/maps", proc_handle.pid); + pmf = fopen (tbuf, "r"); + if (pmf) { + while (fgets( tbuf, sizeof(tbuf), pmf)) { + char *cp = rindex (tbuf, '/'); + if (cp && strncmp (cp+1, "libpthread", 10) == 0) { + thread_lib_reloc = (CORE_ADDR) strtol (tbuf, 0, 16); + break; + } + } + fclose (pmf); + } + } + create_thread_event_breakpoint ((*bp) + thread_lib_reloc); return TD_OK; } --=-B0kRuHovpk6CD2CzjPp8--