From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 13821 invoked by alias); 18 Mar 2009 04:49:02 -0000 Received: (qmail 13812 invoked by uid 22791); 18 Mar 2009 04:49:01 -0000 X-SWARE-Spam-Status: No, hits=-1.3 required=5.0 tests=AWL,BAYES_00,J_CHICKENPOX_41,J_CHICKENPOX_63,SARE_MSGID_LONG40,SPF_PASS X-Spam-Check-By: sourceware.org Received: from smtp-out.google.com (HELO smtp-out.google.com) (216.239.33.17) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 18 Mar 2009 04:48:51 +0000 Received: from spaceape8.eur.corp.google.com (spaceape8.eur.corp.google.com [172.28.16.142]) by smtp-out.google.com with ESMTP id n2I4mmLD000371 for ; Wed, 18 Mar 2009 04:48:48 GMT Received: from wf-out-1314.google.com (wfc25.prod.google.com [10.142.3.25]) by spaceape8.eur.corp.google.com with ESMTP id n2I4mkBK032347 for ; Tue, 17 Mar 2009 21:48:46 -0700 Received: by wf-out-1314.google.com with SMTP id 25so360325wfc.14 for ; Tue, 17 Mar 2009 21:48:46 -0700 (PDT) MIME-Version: 1.0 Received: by 10.141.75.1 with SMTP id c1mr152940rvl.178.1237351726021; Tue, 17 Mar 2009 21:48:46 -0700 (PDT) In-Reply-To: <20090318043626.D9F121C7301@localhost> References: <20090318043626.D9F121C7301@localhost> Date: Wed, 18 Mar 2009 05:02:00 -0000 Message-ID: Subject: Re: [RFA] (display_uses_solib_p): Redo loop, scan element list backwards. From: Doug Evans To: ppluzhnikov@google.com, gdb-patches@sourceware.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit 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-03/txt/msg00364.txt.bz2 On Tue, Mar 17, 2009 at 9:36 PM, Doug Evans wrote: > Hi. > > I noticed sigbpt.exp is failing. > I was getting a "Value out of range" error inside display_uses_solib_p. > I traced it to the expression elements array being referenced out of bounds. > > I think this patch is the right fix. > The expression elements array needs to be scanned backwards > when using operator_length: it examines the element at the _end_ > of the array. > > Ok to check in? > > 2009-03-17 Doug Evans > > * printcmd.c (display_uses_solib_p): Redo loop, scan element list > backwards. > > Index: printcmd.c > =================================================================== > RCS file: /cvs/src/src/gdb/printcmd.c,v > retrieving revision 1.147 > diff -u -p -r1.147 printcmd.c > --- printcmd.c 9 Mar 2009 22:38:37 -0000 1.147 > +++ printcmd.c 18 Mar 2009 04:28:26 -0000 > @@ -1763,18 +1763,23 @@ static int > display_uses_solib_p (const struct display *d, > const struct so_list *solib) > { > - int i; > + int endpos; > struct expression *const exp = d->exp; > + union exp_element *const elts = exp->elts; > > if (d->block != NULL > && solib_contains_address_p (solib, d->block->startaddr)) > return 1; > > - for (i = 0; i < exp->nelts; ) > + for (endpos = exp->nelts; endpos > 0; ) > { > - int args, oplen = 0; > - const union exp_element *const elts = exp->elts; > + int i, args, oplen = 0; > > + exp->language_defn->la_exp_desc->operator_length (exp, endpos, > + &oplen, &args); > + gdb_assert (oplen > 0); > + > + i = endpos - oplen; > if (elts[i].opcode == OP_VAR_VALUE) > { > const struct block *const block = elts[i + 1].block; > @@ -1789,11 +1794,9 @@ display_uses_solib_p (const struct displ > if (section && section->objfile == solib->objfile) > return 1; > } > - exp->language_defn->la_exp_desc->operator_length (exp, i + 1, > - &oplen, &args); > - gdb_assert (oplen > 0); > - i += oplen; > + endpos -= oplen; > } > + > return 0; > } > > btw, this was tested by singlestepping through display_uses_solib_p with several moderately complex display expressions. E.g., display/x ($pc + 123) * 321 before and after the patch is enough to see the problem.