From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 11362 invoked by alias); 24 Jan 2008 00:52:42 -0000 Received: (qmail 11351 invoked by uid 22791); 24 Jan 2008 00:52:41 -0000 X-Spam-Check-By: sourceware.org Received: from nf-out-0910.google.com (HELO nf-out-0910.google.com) (64.233.182.188) by sourceware.org (qpsmtpd/0.31) with ESMTP; Thu, 24 Jan 2008 00:52:21 +0000 Received: by nf-out-0910.google.com with SMTP id b11so1305nfh.48 for ; Wed, 23 Jan 2008 16:52:18 -0800 (PST) Received: by 10.66.239.2 with SMTP id m2mr1609790ugh.26.1201135936985; Wed, 23 Jan 2008 16:52:16 -0800 (PST) Received: from ?192.168.0.100? ( [85.241.1.216]) by mx.google.com with ESMTPS id q9sm117332gve.10.2008.01.23.16.52.13 (version=TLSv1/SSLv3 cipher=RC4-MD5); Wed, 23 Jan 2008 16:52:13 -0800 (PST) Message-ID: <4797E13B.6040408@portugalmail.pt> Date: Thu, 24 Jan 2008 00:52:00 -0000 From: Pedro Alves User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.0.13pre) Gecko/20071023 Thunderbird/1.5.0.14pre Mnenhy/0.7.5.0 MIME-Version: 1.0 To: Pierre Muller CC: 'Mark Kettenis' , gdb-patches@sourceware.org Subject: Re: [RFC-v2] Enhance backtrace for microsoft system DLL calls References: <000001c83b4a$573b4560$05b1d020$@u-strasbg.fr> <200712101854.lBAIs91J031646@brahms.sibelius.xs4all.nl> <002701c83be2$ac2a9a60$047fcf20$@u-strasbg.fr> <003101c85696$6f4d9e20$4de8da60$@u-strasbg.fr> In-Reply-To: <003101c85696$6f4d9e20$4de8da60$@u-strasbg.fr> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit 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-01/txt/msg00573.txt.bz2 Pierre Muller wrote: > I wrote a i386_skip_noop function. > Tested on cygwin target, no regressions found. > The patch allows to get the backtrace of the main thread of gdb > to come up to the functions that called the systems DLL. > If I use ./gdb ./gdb with 'set new-console on' > and use Ctrl-C on the debuggee gdb window. > Without the patch, the backtrace only shows > 3 levels in ntdll.dll and kernel32.dll > [ I forgot to say before: This is great, thanks for doing this! ] > Questions: > 1) Is the 'nop' test useful or should it be removed? > > 2) Should we add other possible no-ops? It is my opinion that it isn't needed, and the function that detects the mov %edi,%edi should be called i386_skip_msft_hotpatch, or i386_skip_hotpatch. The nop is a 2 byte op for a reason, plus, I don't see the point of detecting a lot of patterns if we know they're never emitted. Plus, if we ever need to augment this hot-patching support to another different form, of detect the 5 bytes slack before, this is the natural place to do it. Plus not detecting for a 1 byte nop, you can read 2 bytes at once. (ok, that is going extreme :-) ) > 3) this call is used for all i386 targets, but it > is probably useless for all operating systems but Microsoft Windows, > so should it be called only for that OS, and if yes, how should > we code this? > The way to do it would be to put a flag in i386's gdbarch_tdep, but Daniel didn't think we need to keep this MSFT specific. (adding a flag would at least prevent a needless memory read on non Windows platforms) > 4) Any suggestions to make the comment clearer will be > most appreciated. Grabbing my own comment from upthread, how about: /* Some Microsoft's system dll functions start with a `mov %edi,%edi' instruction, which is effectively a two byte `nop'. This instruction is used for hot patching support, together with 5 bytes of slack before the function. Later, when hot-patching, the 2 byte op can be replaced with a relative jump to 5 bytes back. The 5 bytes slack is large enough to hold a jump into anywhere in the 32-bit address space. */ If you find it interesting, you can add: /* A two byte nop is used to be sure that no thread is executing the instruction at byte 1 of the function, so the patching can be performed atomically. */ -- Pedro Alves