From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 23973 invoked by alias); 26 Jul 2012 21:24:36 -0000 Received: (qmail 23964 invoked by uid 22791); 26 Jul 2012 21:24:35 -0000 X-SWARE-Spam-Status: No, hits=-6.3 required=5.0 tests=AWL,BAYES_00,KHOP_RCVD_UNTRUST,RCVD_IN_DNSWL_HI,RCVD_IN_HOSTKARMA_W,SPF_HELO_PASS,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 26 Jul 2012 21:24:19 +0000 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q6QLNppf022198 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 26 Jul 2012 17:23:51 -0400 Received: from host2.jankratochvil.net (ovpn-116-33.ams2.redhat.com [10.36.116.33]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id q6QLNjRB002523 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NO); Thu, 26 Jul 2012 17:23:48 -0400 Date: Thu, 26 Jul 2012 21:24:00 -0000 From: Jan Kratochvil To: Joel Brobecker Cc: Philippe Waroquiers , Pedro Alves , gdb-patches@sourceware.org, "Maciej W. Rozycki" Subject: [patchv2] Write bpt at the ON_STACK bpt address Message-ID: <20120726212339.GA1710@host2.jankratochvil.net> References: <20120723155951.GA24718@adacore.com> <20120723163513.GA1222@host2.jankratochvil.net> <1343074047.2209.23.camel@soleil> <20120723201611.GA19567@host2.jankratochvil.net> <1343075809.2209.53.camel@soleil> <501009AE.40901@redhat.com> <1343247870.2240.29.camel@soleil> <20120725212653.GC2767@adacore.com> <1343252775.2240.51.camel@soleil> <20120725223933.GD2767@adacore.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20120725223933.GD2767@adacore.com> User-Agent: Mutt/1.5.21 (2010-09-15) 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: 2012-07/txt/msg00644.txt.bz2 On Thu, 26 Jul 2012 00:39:33 +0200, Joel Brobecker wrote: > > A valid instruction is not enough. We need a valid instruction > > that will cause Valgrind to terminate block translation. > > The breakpoint trap instruction is ok for that. > > (0xcc for x86 and amd64, 0x0005000d for mips32). > > I think it is fine to update GDB to insert the breakpoint instruction > instead of leaving random bytes at the breakpoint location. Attached. I no longer find it useful as arch-dependent code, it would do the same in each arch. No regressions on {x86_64,x86_64-m32,i686}-fedorarawhide-linux-gnu. Philippe, do you have an easy enough way to regression test it on mips when you was asking for the mips fix? mips has many execution modes as I see. I still have to write a testcase for it using valgrind. > But it sounds like this is forcing GDB to have insider knowledge of > valgrind. As you were asking to put there 'int3' (and not 'hlt') the user convenience coincidentally matches here with what Philippe asks for valgrind. I am only concerned a bit about this change arcross all archs for 7.5. Maybe 7.5 could limit this patch only for i386/x86_64 which is well understood. Thanks, Jan gdb/ 2012-07-26 Jan Kratochvil * infcall.c (call_function_by_hand): Move BP_ADDR comment to AT_ENTRY_POINT. (call_function_by_hand) : Call write_memory with gdbarch_breakpoint_from_pc, if possible. (call_function_by_hand) : The BP_ADDR comment is moved here. gdb/doc/ 2012-07-26 Jan Kratochvil * gdbint.texinfo (Defining Other Architecture Features): Clarify *pcptr encoding for gdbarch_breakpoint_from_pc, bp_addr for gdbarch_push_dummy_call and bp_addr for gdbarch_push_dummy_code. diff --git a/gdb/doc/gdbint.texinfo b/gdb/doc/gdbint.texinfo index 5e00f1f..b66f80b 100644 --- a/gdb/doc/gdbint.texinfo +++ b/gdb/doc/gdbint.texinfo @@ -4540,8 +4540,10 @@ contents and size of a breakpoint instruction. It returns a pointer to a static string of bytes that encode a breakpoint instruction, stores the length of the string to @code{*@var{lenptr}}, and adjusts the program counter (if necessary) to point to the actual memory location where the -breakpoint should be inserted. May return @code{NULL} to indicate that -software breakpoints are not supported. +breakpoint should be inserted. The program counter (@code{*@var{pcptr}} +is inferior PC register encoded on the input and it is a plain address on the +output. Function may return @code{NULL} to indicate that software breakpoints +are not supported. Although it is common to use a trap instruction for a breakpoint, it's not required; for instance, the bit pattern could be an invalid @@ -4821,7 +4823,7 @@ instead of value. @anchor{gdbarch_push_dummy_call} Define this to push the dummy frame's call to the inferior function onto the stack. In addition to pushing @var{nargs}, the code should push @var{struct_addr} (when @var{struct_return} is non-zero), and -the return address (@var{bp_addr}). +the return address (@var{bp_addr}, in inferior PC register encoding). @var{function} is a pointer to a @code{struct value}; on architectures that use function descriptors, this contains the function descriptor value. @@ -4835,12 +4837,14 @@ instruction sequence (including space for a breakpoint) to which the called function should return. Set @var{bp_addr} to the address at which the breakpoint instruction -should be inserted, @var{real_pc} to the resume address when starting -the call sequence, and return the updated inner-most stack address. +should be inserted (in inferior PC register encoding), @var{real_pc} to the +resume address when starting the call sequence, and return the updated +inner-most stack address. By default, the stack is grown sufficient to hold a frame-aligned (@pxref{frame_align}) breakpoint, @var{bp_addr} is set to the address -reserved for that breakpoint, and @var{real_pc} set to @var{funaddr}. +reserved for that breakpoint (in inferior PC register encoding), and +@var{real_pc} set to @var{funaddr}. This method replaces @w{@code{gdbarch_call_dummy_location (@var{gdbarch})}}. diff --git a/gdb/infcall.c b/gdb/infcall.c index 51cd118..6ac6624 100644 --- a/gdb/infcall.c +++ b/gdb/infcall.c @@ -618,15 +618,37 @@ call_function_by_hand (struct value *function, int nargs, struct value **args) not just the breakpoint but also an extra word containing the size (?) of the structure being passed. */ - /* The actual breakpoint (at BP_ADDR) is inserted separatly so there - is no need to write that out. */ - switch (gdbarch_call_dummy_location (gdbarch)) { case ON_STACK: - sp = push_dummy_code (gdbarch, sp, funaddr, - args, nargs, target_values_type, - &real_pc, &bp_addr, get_current_regcache ()); + { + const gdb_byte *bp_bytes; + CORE_ADDR bp_addr_as_address; + int bp_size; + + /* Be careful BP_ADDR is in inferior PC encoding while + BP_ADDR_AS_ADDRESS is a plain memory address. */ + + sp = push_dummy_code (gdbarch, sp, funaddr, args, nargs, + target_values_type, &real_pc, &bp_addr, + get_current_regcache ()); + + /* Write a legitimate instruction at the point where the infcall + breakpoint is going to be inserted. While this instruction + is never going to be executed, a user investigating the + memory from GDB would see this instruction instead of random + uninitialized bytes. We chose the breakpoint instruction + just because it may look as the most logical one to the user. + + If software breakpoints are unsupported for this target we + leave the user visible memory content uninitialized. */ + + bp_addr_as_address = bp_addr; + bp_bytes = gdbarch_breakpoint_from_pc (gdbarch, &bp_addr_as_address, + &bp_size); + if (bp_bytes != NULL) + write_memory (bp_addr_as_address, bp_bytes, bp_size); + } break; case AT_ENTRY_POINT: { @@ -634,8 +656,12 @@ call_function_by_hand (struct value *function, int nargs, struct value **args) real_pc = funaddr; dummy_addr = entry_point_address (); + /* A call dummy always consists of just a single breakpoint, so - its address is the same as the address of the dummy. */ + its address is the same as the address of the dummy. + + The actual breakpoint is inserted separatly so there is no need to + write that out. */ bp_addr = dummy_addr; break; }