From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 1137 invoked by alias); 15 Sep 2009 20:36:58 -0000 Received: (qmail 1127 invoked by uid 22791); 15 Sep 2009 20:36:57 -0000 X-SWARE-Spam-Status: No, hits=-1.8 required=5.0 tests=AWL,BAYES_00,SARE_MSGID_LONG40,SPF_PASS X-Spam-Check-By: sourceware.org Received: from smtp-out.google.com (HELO smtp-out.google.com) (216.239.45.13) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 15 Sep 2009 20:36:52 +0000 Received: from wpaz21.hot.corp.google.com (wpaz21.hot.corp.google.com [172.24.198.85]) by smtp-out.google.com with ESMTP id n8FKaoig012234 for ; Tue, 15 Sep 2009 13:36:50 -0700 Received: from ywh5 (ywh5.prod.google.com [10.192.8.5]) by wpaz21.hot.corp.google.com with ESMTP id n8FKaJm7024044 for ; Tue, 15 Sep 2009 13:36:48 -0700 Received: by ywh5 with SMTP id 5so6282076ywh.4 for ; Tue, 15 Sep 2009 13:36:48 -0700 (PDT) MIME-Version: 1.0 Received: by 10.150.131.5 with SMTP id e5mr13210242ybd.262.1253047006734; Tue, 15 Sep 2009 13:36:46 -0700 (PDT) In-Reply-To: References: <20090910231912.0733A843B9@localhost> Date: Tue, 15 Sep 2009 20:36:00 -0000 Message-ID: Subject: Re: [RFC] better dwarf checking for values on the stack From: Doug Evans To: Cary Coutant Cc: Tom Tromey , gdb-patches@sourceware.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-System-Of-Record: true 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: 2009-09/txt/msg00490.txt.bz2 On Tue, Sep 15, 2009 at 1:20 PM, Cary Coutant wrote: >> =A0 =A0 =A0 =A0* dwarf2expr.c (dwarf_expr_grow_stack): Update calculatio= n of >> =A0 =A0 =A0 =A0size of stack value. >> =A0 =A0 =A0 =A0(dwarf_expr_push): New arg in_stack_memory, all callers u= pdated. >> =A0 =A0 =A0 =A0(dwarf_expr_fetch_in_stack_memory): New function. >> =A0 =A0 =A0 =A0(add_piece): Set in_stack_memory for non-literal values. >> =A0 =A0 =A0 =A0(execute_stack_op): Allow ops to specify where the value = is on the >> =A0 =A0 =A0 =A0program's stack. >> =A0 =A0 =A0 =A0(execute_stack_op, case DW_OP_fbreg): Mark value as in st= ack memory. >> =A0 =A0 =A0 =A0(execute_stack_op, case DW_OP_call_frame_cfa): Ditto. >> =A0 =A0 =A0 =A0(execute_stack_op, case DW_OP_dup): Copy in_stack_memory = flag. >> =A0 =A0 =A0 =A0(execute_stack_op, cases DW_OP_pick, DW_OP_over): Ditto. >> =A0 =A0 =A0 =A0(execute_stack_op, cases DW_OP_swap, DW_OP_rot): Update t= ype of >> =A0 =A0 =A0 =A0dwarf stack value. > > It seems to me that if you're going to go this route (rather than the > heuristic approach of your first patch), you need to do some type > algebra here. You've got three types of things on the expression > stack; let's call them M (generic addresses, probably not on the > memory stack), S (addresses of things on the memory stack), and K > (unitless constants). There are combining rules for these types; for > example: > > =A0K K -> K > =A0M +/- K -> M > =A0K +/- M -> M > =A0M - M -> K > =A0S +/- K -> S > =A0K +/- S -> S > =A0S - S -> K > > There are combinations that don't make sense, but aren't technically > illegal in the DWARF spec, so these will need to be handled > conservatively; for example: > > =A0M + M -> M > =A0M * M -> M > =A0M + S -> M > > You could have an expression like S - S + M [ =3D (S - S) + M =3D K + M -> > M ] -- admittedly unlikely, but the same can be said for Tom's example > that fooled the heuristic approach -- which should yield a memory > address, but from what I can tell will end up claiming it's a stack > address. Yeah, if we wanted to catch more cases of what's on the stack than what's currently there does, then we need to appropriately handle the math. I explicitly left that for another day. dwarf2expr.c: /* Assume the value is not in stack memory. Code that knows otherwise sets this to 1. Some arithmetic on stack addresses can probably be assumed to still be a stack address, but we skip this complication for now. This is just an optimization, so it's always ok to punt and leave this as 0. */ int in_stack_memory =3D 0; Sound ok?