From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 11524 invoked by alias); 17 Mar 2011 19:29:44 -0000 Received: (qmail 11468 invoked by uid 22791); 17 Mar 2011 19:29:43 -0000 X-SWARE-Spam-Status: No, hits=-1.9 required=5.0 tests=BAYES_00,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mail.codesourcery.com (HELO mail.codesourcery.com) (38.113.113.100) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 17 Mar 2011 19:29:38 +0000 Received: (qmail 10446 invoked from network); 17 Mar 2011 19:29:36 -0000 Received: from unknown (HELO ?192.168.1.2?) (kcy@127.0.0.2) by mail.codesourcery.com with ESMTPA; 17 Mar 2011 19:29:36 -0000 Message-ID: <4D82611B.50609@codesourcery.com> Date: Thu, 17 Mar 2011 19:49:00 -0000 From: Kwok Cheung Yeung User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-GB; rv:1.9.2.15) Gecko/20110303 Thunderbird/3.1.9 MIME-Version: 1.0 To: gdb-patches@sourceware.org Subject: [PATCH] Fix instruction relocation for fast tracepoints Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit 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: 2011-03/txt/msg00904.txt.bz2 Hello There is a problem with the instruction relocation facility in GDB, which is triggered when fast tracepoints are set on call or jump instructions. The third and fourth arguments of calls to store_signed_integer (defined in findvar.c) in the i386 and amd64 implementations of relocate_instruction are the wrong way around, which results in a relative jump one byte forward. In the context of fast tracepoints, this results in a jump to the address portion of another jump instruction, which typically causes the program to crash when the tracepoint is reached. This patch fixes the ordering of the arguments to store_signed_integer. It also adds debug messages to the case where a call instruction is relocated (identical to the ones for jump instructions), and tidies up the presentation of the messages by removing the duplicate '0x0x' prefix of hexadecimal numbers (since hex_string and paddress already output the prefix). Kwok Cheung Yeung 2011-03-17 Kwok Cheung Yeung * amd64-tdep.c (amd64_relocate_instruction): Fix ordering of arguments to store_signed_integer. Add debug message when relocating CALL instructions. Fix formatting of debug message. * i386-tdep.c (i386_relocate_instruction): Ditto. --- gdb-7.2/gdb/amd64-tdep.c 2010-05-26 19:19:26.000000000 +0100 +++ gdb-7.2.new/gdb/amd64-tdep.c 2011-03-17 18:28:11.390662621 +0000 @@ -1588,7 +1588,14 @@ amd64_relocate_instruction (struct gdbar /* Adjust the destination offset. */ rel32 = extract_signed_integer (insn + 1, 4, byte_order); newrel = (oldloc - *to) + rel32; - store_signed_integer (insn + 1, 4, newrel, byte_order); + store_signed_integer (insn + 1, 4, byte_order, newrel); + + if (debug_displaced) + fprintf_unfiltered (gdb_stdlog, + "Adjusted insn rel32=%s at %s to" + " rel32=%s at %s\n", + hex_string (rel32), paddress (gdbarch, oldloc), + hex_string (newrel), paddress (gdbarch, *to)); /* Write the adjusted jump into its displaced location. */ append_insns (to, 5, insn); @@ -1611,11 +1618,11 @@ amd64_relocate_instruction (struct gdbar { rel32 = extract_signed_integer (insn + offset, 4, byte_order); newrel = (oldloc - *to) + rel32; - store_signed_integer (insn + offset, 4, newrel, byte_order); + store_signed_integer (insn + offset, 4, byte_order, newrel); if (debug_displaced) fprintf_unfiltered (gdb_stdlog, - "Adjusted insn rel32=0x%s at 0x%s to" - " rel32=0x%s at 0x%s\n", + "Adjusted insn rel32=%s at %s to" + " rel32=%s at %s\n", hex_string (rel32), paddress (gdbarch, oldloc), hex_string (newrel), paddress (gdbarch, *to)); } --- gdb-7.2/gdb/i386-tdep.c 2010-06-22 03:15:45.000000000 +0100 +++ gdb-7.2.new/gdb/i386-tdep.c 2011-03-17 18:28:11.398608604 +0000 @@ -747,7 +747,14 @@ i386_relocate_instruction (struct gdbarc /* Adjust the destination offset. */ rel32 = extract_signed_integer (insn + 1, 4, byte_order); newrel = (oldloc - *to) + rel32; - store_signed_integer (insn + 1, 4, newrel, byte_order); + store_signed_integer (insn + 1, 4, byte_order, newrel); + + if (debug_displaced) + fprintf_unfiltered (gdb_stdlog, + "Adjusted insn rel32=%s at %s to" + " rel32=%s at %s\n", + hex_string (rel32), paddress (gdbarch, oldloc), + hex_string (newrel), paddress (gdbarch, *to)); /* Write the adjusted jump into its displaced location. */ append_insns (to, 5, insn); @@ -766,11 +773,11 @@ i386_relocate_instruction (struct gdbarc { rel32 = extract_signed_integer (insn + offset, 4, byte_order); newrel = (oldloc - *to) + rel32; - store_signed_integer (insn + offset, 4, newrel, byte_order); + store_signed_integer (insn + offset, 4, byte_order, newrel); if (debug_displaced) fprintf_unfiltered (gdb_stdlog, - "Adjusted insn rel32=0x%s at 0x%s to" - " rel32=0x%s at 0x%s\n", + "Adjusted insn rel32=%s at %s to" + " rel32=%s at %s\n", hex_string (rel32), paddress (gdbarch, oldloc), hex_string (newrel), paddress (gdbarch, *to)); }