From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 30955 invoked by alias); 19 Mar 2002 16:01:02 -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 30828 invoked from network); 19 Mar 2002 16:00:55 -0000 Received: from unknown (HELO kerberos.suse.cz) (195.47.106.10) by sources.redhat.com with SMTP; 19 Mar 2002 16:00:55 -0000 Received: from chimera.suse.cz (chimera.suse.cz [10.20.0.2]) by kerberos.suse.cz (SuSE SMTP server) with ESMTP id 7FD8759D34A for ; Tue, 19 Mar 2002 17:00:54 +0100 (CET) Received: from suse.cz (leviathan.suse.cz [10.20.1.56]) by chimera.suse.cz (8.11.0/8.11.0/SuSE Linux 8.11.0-0.4) with ESMTP id g2JG0sp15606 for ; Tue, 19 Mar 2002 17:00:54 +0100 X-Authentication-Warning: chimera.suse.cz: Host leviathan.suse.cz [10.20.1.56] claimed to be suse.cz Message-ID: <3C9760B6.7040900@suse.cz> Date: Tue, 19 Mar 2002 08:01:00 -0000 From: Michal Ludvig Organization: SuSE CR User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:0.9.9) Gecko/20020310 X-Accept-Language: cs, cz, en MIME-Version: 1.0 To: gdb-patches@sources.redhat.com Subject: Re: [RFA] x86_64_skip_prologue References: <3C923BD9.80403@suse.cz> <1020315184051.ZM27571@localhost.localdomain> Content-Type: multipart/mixed; boundary="------------060304020609060302040606" X-SW-Source: 2002-03/txt/msg00344.txt.bz2 This is a multi-part message in MIME format. --------------060304020609060302040606 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Content-length: 1124 Kevin Buettner wrote: >>3) Now pc points to the first line of the sourcecode of the function >>(usually opening '{'). If the next line with debuginfo has pc within >>bounds of this function, we will return this pc instead. > > You might want to take a look at some of the other prologue analyzers. > In particular, you might want to consider calling find_pc_line() instead > of accessing the data structures directly. Most of other *_skip_prologue functions pretend, that prolog is an always-the-same sequence of instructions, what is not the case on x86-64. I can't see an approach other than the one I have chosen. Of course I can use other structures and maybe some macros, but the concept will remain. Or is there another way? Why should I preferably use find_pc_line()? It gives me the same symtab as find_pc_symtab() does... Anyway I have rewritten the code to use it. > BTW, you might want to run your code through indent. Sorry, I'm not yet used to follow GNU coding style. Hopefully now it is better ;-) Michal Ludvig -- * SuSE CR, s.r.o * mludvig@suse.cz * +420 2 9654 5373 * http://www.suse.cz --------------060304020609060302040606 Content-Type: text/plain; name="x8664-04.diff" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="x8664-04.diff" Content-length: 2245 Index: x86-64-tdep.c =================================================================== RCS file: /cvs/src/src/gdb/x86-64-tdep.c,v retrieving revision 1.10 diff -c -3 -p -r1.10 x86-64-tdep.c *** x86-64-tdep.c 2002/03/04 11:08:28 1.10 --- x86-64-tdep.c 2002/03/19 15:29:24 *************** x86_64_frameless_function_invocation (st *** 759,768 **** return 0; } ! /* On x86_64 there are no reasonable prologs. */ CORE_ADDR x86_64_skip_prologue (CORE_ADDR pc) { return pc; } --- 759,815 ---- return 0; } ! /* 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) { + int i, firstline, currline; + struct symtab_and_line v_sal; + struct symbol *v_function; + CORE_ADDR salendaddr = 0, endaddr = 0; + + /* We will handle only functions beginning with: + 55 pushq %rbp + 48 89 e5 movq %rsp,%rbp + */ + 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 pc; + + v_function = find_pc_function (pc); + v_sal = find_pc_line (pc, 0); + + /* If pc doesn't point to a function with debuginfo, + some of the following may be NULL. */ + if (!v_function || !v_function->ginfo.value.block + || !v_sal.symtab) + return pc; + + firstline = v_sal.line; + currline = firstline; + salendaddr = v_sal.end; + endaddr = v_function->ginfo.value.block->endaddr; + + for (i = 0; i < v_sal.symtab->linetable->nitems; i++) + if (v_sal.symtab->linetable->item[i].line > firstline + && v_sal.symtab->linetable->item[i].pc >= salendaddr + && v_sal.symtab->linetable->item[i].pc < endaddr) + { + pc = v_sal.symtab->linetable->item[i].pc; + currline = v_sal.symtab->linetable->item[i].line; + break; + } + return pc; } --------------060304020609060302040606--