From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 24746 invoked by alias); 15 Sep 2009 20:20:54 -0000 Received: (qmail 24736 invoked by uid 22791); 15 Sep 2009 20:20:54 -0000 X-SWARE-Spam-Status: No, hits=-1.5 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:20:50 +0000 Received: from spaceape23.eur.corp.google.com (spaceape23.eur.corp.google.com [172.28.16.75]) by smtp-out.google.com with ESMTP id n8FKKln6020782 for ; Tue, 15 Sep 2009 13:20:48 -0700 Received: from pzk41 (pzk41.prod.google.com [10.243.19.169]) by spaceape23.eur.corp.google.com with ESMTP id n8FKKicl020702 for ; Tue, 15 Sep 2009 13:20:45 -0700 Received: by pzk41 with SMTP id 41so3684069pzk.4 for ; Tue, 15 Sep 2009 13:20:44 -0700 (PDT) MIME-Version: 1.0 Received: by 10.142.59.10 with SMTP id h10mr572523wfa.268.1253046042683; Tue, 15 Sep 2009 13:20:42 -0700 (PDT) In-Reply-To: References: <20090910231912.0733A843B9@localhost> Date: Tue, 15 Sep 2009 20:20:00 -0000 Message-ID: Subject: Re: [RFC] better dwarf checking for values on the stack From: Cary Coutant To: Doug Evans 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/msg00489.txt.bz2 > =A0 =A0 =A0 =A0* dwarf2expr.c (dwarf_expr_grow_stack): Update calculation= of > =A0 =A0 =A0 =A0size of stack value. > =A0 =A0 =A0 =A0(dwarf_expr_push): New arg in_stack_memory, all callers up= dated. > =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 i= s on the > =A0 =A0 =A0 =A0program's stack. > =A0 =A0 =A0 =A0(execute_stack_op, case DW_OP_fbreg): Mark value as in sta= ck 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 f= lag. > =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 ty= pe 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: K K -> K M +/- K -> M K +/- M -> M M - M -> K S +/- K -> S K +/- S -> S S - 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: M + M -> M M * M -> M M + 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. -cary