From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 24924 invoked by alias); 6 Mar 2003 22:56:46 -0000 Mailing-List: contact gdb-patches-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sources.redhat.com Received: (qmail 24907 invoked from network); 6 Mar 2003 22:56:45 -0000 Received: from unknown (HELO kerberos.suse.cz) (195.47.106.10) by 172.16.49.205 with SMTP; 6 Mar 2003 22:56:45 -0000 Received: from chimera.suse.cz (chimera.suse.cz [10.20.0.2]) by kerberos.suse.cz (SuSE SMTP server) with ESMTP id A6BCD59D307 for ; Thu, 6 Mar 2003 23:56:44 +0100 (CET) Received: from suse.cz (naga.suse.cz [10.20.1.16]) by chimera.suse.cz (8.11.0/8.11.0/SuSE Linux 8.11.0-0.4) with ESMTP id h26Mui405273 for ; Thu, 6 Mar 2003 23:56:44 +0100 X-Authentication-Warning: chimera.suse.cz: Host naga.suse.cz [10.20.1.16] claimed to be suse.cz Message-ID: <3E67D22C.3030908@suse.cz> Date: Thu, 06 Mar 2003 22:56:00 -0000 From: Michal Ludvig Organization: SuSE CR User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.2.1) Gecko/20021130 X-Accept-Language: cs, cz, en MIME-Version: 1.0 To: GDB Patches Subject: [RFA] Prologue detection on x86-64 Content-Type: multipart/mixed; boundary="------------000103050307030402070603" X-SW-Source: 2003-03/txt/msg00146.txt.bz2 This is a multi-part message in MIME format. --------------000103050307030402070603 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Content-length: 375 Hi all, the attached patch moves prologue detection from x86_64_skip_prologue() to separate function, that could be reused later. I need this separate function to implement unwinding of functions without debug info. It's an almost obvious patch, I believe. OK to commit? Michal Ludvig -- * SuSE CR, s.r.o * mludvig@suse.cz * (+420) 296.545.373 * http://www.suse.cz --------------000103050307030402070603 Content-Type: text/plain; name="skip-prologue-1.diff" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="skip-prologue-1.diff" Content-length: 2992 2003-03-06 Michal Ludvig * x86-64-tdep.c (x86_64_function_has_prologue): New function. (x86_64_skip_prologue): Move prologue detection to separate function. * x86-64-tdep.h (x86_64_function_has_prologue): New prototype. Index: x86-64-tdep.c =================================================================== RCS file: /cvs/src/src/gdb/x86-64-tdep.c,v retrieving revision 1.51 diff -u -p -r1.51 x86-64-tdep.c --- x86-64-tdep.c 2 Mar 2003 04:02:25 -0000 1.51 +++ x86-64-tdep.c 6 Mar 2003 22:50:09 -0000 @@ -851,11 +851,31 @@ x86_64_frameless_function_invocation (st return 0; } +/* We will handle only functions beginning with: + 55 pushq %rbp + 48 89 e5 movq %rsp,%rbp */ +#define PROLOG_BUFSIZE 4 +static int +x86_64_function_has_prologue (CORE_ADDR pc) +{ + int i; + unsigned char prolog_expect[PROLOG_BUFSIZE] = { 0x55, 0x48, 0x89, 0xe5 }, + prolog_buf[PROLOG_BUFSIZE]; + + read_memory (pc, (char *) prolog_buf, PROLOG_BUFSIZE); + + /* First check, whether pc points to pushq %rbp, movq %rsp,%rbp. */ + for (i = 0; i < PROLOG_BUFSIZE; i++) + if (prolog_expect[i] != prolog_buf[i]) + return 0; /* ... no, it doesn't. Nothing to skip. */ + + return 1; +} + /* If a function with debugging information and known beginning is detected, we will return pc of the next line in the source code. With this approach we effectively skip the prolog. */ -#define PROLOG_BUFSIZE 4 CORE_ADDR x86_64_skip_prologue (CORE_ADDR pc) { @@ -863,21 +883,9 @@ x86_64_skip_prologue (CORE_ADDR pc) struct symtab_and_line v_sal; struct symbol *v_function; CORE_ADDR endaddr; - unsigned char prolog_buf[PROLOG_BUFSIZE]; - - /* We will handle only functions starting with: */ - static unsigned char prolog_expect[PROLOG_BUFSIZE] = - { - 0x55, /* pushq %rbp */ - 0x48, 0x89, 0xe5 /* movq %rsp, %rbp */ - }; - read_memory (pc, (char *) prolog_buf, PROLOG_BUFSIZE); - - /* First check, whether pc points to pushq %rbp, movq %rsp, %rbp. */ - for (i = 0; i < PROLOG_BUFSIZE; i++) - if (prolog_expect[i] != prolog_buf[i]) - return pc; /* ... no, it doesn't. Nothing to skip. */ + if (! x86_64_function_has_prologue (pc)) + return pc; /* OK, we have found the prologue and want PC of the first non-prologue instruction. */ Index: x86-64-tdep.h =================================================================== RCS file: /cvs/src/src/gdb/x86-64-tdep.h,v retrieving revision 1.10 diff -u -p -r1.10 x86-64-tdep.h --- x86-64-tdep.h 21 Dec 2002 21:09:58 -0000 1.10 +++ x86-64-tdep.h 6 Mar 2003 22:50:09 -0000 @@ -36,6 +36,7 @@ gdbarch_saved_pc_after_call_ftype x86_64 gdbarch_pc_in_sigtramp_ftype x86_64_linux_in_sigtramp; CORE_ADDR x86_64_linux_frame_chain (struct frame_info *fi); CORE_ADDR x86_64_init_frame_pc (int fromleaf, struct frame_info *fi); +int x86_64_function_has_prologue (CORE_ADDR pc); void x86_64_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch); --------------000103050307030402070603--