From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 1476 invoked by alias); 28 Mar 2011 15:18:22 -0000 Received: (qmail 1467 invoked by uid 22791); 28 Mar 2011 15:18:20 -0000 X-SWARE-Spam-Status: No, hits=-5.6 required=5.0 tests=AWL,BAYES_00,KAM_STOCKGEN,RCVD_IN_DNSWL_HI,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; Mon, 28 Mar 2011 15:18:09 +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 p2SFI7Zq019284 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 28 Mar 2011 11:18:07 -0400 Received: from host1.jankratochvil.net (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id p2SFI56Q027233 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Mon, 28 Mar 2011 11:18:07 -0400 Received: from host1.jankratochvil.net (localhost [127.0.0.1]) by host1.jankratochvil.net (8.14.4/8.14.4) with ESMTP id p2SFI5TS011652; Mon, 28 Mar 2011 17:18:05 +0200 Received: (from jkratoch@localhost) by host1.jankratochvil.net (8.14.4/8.14.4/Submit) id p2SFI5Kx011651; Mon, 28 Mar 2011 17:18:05 +0200 Date: Mon, 28 Mar 2011 17:11:00 -0000 From: Jan Kratochvil To: Paul Pluzhnikov Cc: Tom Tromey , gdb-patches@sourceware.org Subject: [patch] Do not skip prologue for -O2 -g with GCC VTA Re: [patch] Fix for PR gdb/12573 Message-ID: <20110328151804.GA10936@host1.jankratochvil.net> References: <20110316235418.34BA7190B17@elbrus2.mtv.corp.google.com> <20110318171246.GA13366@host1.jankratochvil.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20110318171246.GA13366@host1.jankratochvil.net> 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: 2011-03/txt/msg01131.txt.bz2 On Fri, 18 Mar 2011 18:12:46 +0100, Jan Kratochvil wrote: > One of the problems is that GDB tries to skip prologue even for -O2 -g code. > There is no such reason as with -O2 -g the debug info is correct for each > instructions. With -O0 -g there are frame-related absolute addresses of > autovariables which is the reason GDB needs to skip the prologue to have valid > location of such -O0 -g autovariables. > > -O2 -g code can be detected for a Compilation Unit if there is referenced any > location list from that CU (suggested by GCC hackers). In such case skipping > prologues should be disabled. Implementation attached. I was told systemtap is using the same idea (I have ot checked the systemtap implementation). It does not fix the artificial testcase of mine and it does not fix the problem in general. But it fixes the binary you (Paul) attached to PR 12573 and the binary in the Red Hat BZ. It is a mess GDB now chooses "random" addresses in the -O2 -g code and with this clean up the problem does not happen in the cases I am aware of. I am not sure if there should not be also a GCC DW_AT_producer check but I hope no compiler produces DW_AT_location as a location list not covering the functions prologues. No regressions on {x86_64,x86_64-m32,i686}-fedora15-linux-gnu. This is not suitable for 7.3 so late. Thanks, Jan gdb/ 2011-03-28 Jan Kratochvil * dwarf2read.c: Include ctype.h. (struct dwarf2_cu): New field has_loclist. (process_full_comp_unit): Set also symtab->locations_valid. Move the symtab->language code. (var_decode_location): Set cu->has_loclist. * symtab.c (skip_prologue_sal): Return on LOCATIONS_VALID. * symtab.h (struct symtab): Make the primary field a bitfield. New field locations_valid. --- a/gdb/dwarf2read.c +++ b/gdb/dwarf2read.c @@ -57,6 +57,7 @@ #include "vec.h" #include "c-lang.h" #include "valprint.h" +#include #include #include "gdb_string.h" @@ -395,6 +396,11 @@ struct dwarf2_cu DIEs for namespaces, we don't need to try to infer them from mangled names. */ unsigned int has_namespace_info : 1; + + /* This CU references .debug_loc. It means it has been compiled with + optimizations and debug info together so that GDB may stop skipping the + prologue. */ + unsigned int has_loclist : 1; }; /* Persistent data held for a compilation unit, even when not @@ -4626,13 +4632,15 @@ process_full_comp_unit (struct dwarf2_per_cu_data *per_cu) symtab = end_symtab (highpc + baseaddr, objfile, SECT_OFF_TEXT (objfile)); - /* Set symtab language to language from DW_AT_language. - If the compilation is from a C file generated by language preprocessors, - do not set the language if it was already deduced by start_subfile. */ - if (symtab != NULL - && !(cu->language == language_c && symtab->language != language_c)) + if (symtab != NULL) { - symtab->language = cu->language; + /* Set symtab language to language from DW_AT_language. If the + compilation is from a C file generated by language preprocessors, do + not set the language if it was already deduced by start_subfile. */ + if (!(cu->language == language_c && symtab->language != language_c)) + symtab->language = cu->language; + + symtab->locations_valid = cu->has_loclist; } if (dwarf2_per_objfile->using_index) @@ -10839,6 +10847,9 @@ var_decode_location (struct attribute *attr, struct symbol *sym, dwarf2_symbol_mark_computed (attr, sym, cu); SYMBOL_CLASS (sym) = LOC_COMPUTED; + + if (SYMBOL_COMPUTED_OPS (sym) == &dwarf2_loclist_funcs) + cu->has_loclist = 1; } /* Given a pointer to a DWARF information entry, figure out if we need --- a/gdb/symtab.c +++ b/gdb/symtab.c @@ -2470,6 +2470,9 @@ skip_prologue_sal (struct symtab_and_line *sal) if (sal->explicit_pc) return; + if (sal->symtab != NULL && sal->symtab->locations_valid) + return; + old_chain = save_current_space_and_thread (); switch_to_program_space_and_thread (sal->pspace); --- a/gdb/symtab.h +++ b/gdb/symtab.h @@ -762,7 +762,12 @@ struct symtab should be designated the primary, so that the blockvector is relocated exactly once by objfile_relocate. */ - int primary; + unsigned int primary : 1; + + /* GDB does not need to skip prologues as the variable locations are valid + for all the PC values. */ + + unsigned int locations_valid : 1; /* The macro table for this symtab. Like the blockvector, this may be shared between different symtabs --- and normally is for