[RFA] "constify" parse_exp_1

Pedro Alves palves@redhat.com
Fri Mar 8 13:55:00 GMT 2013


On 03/08/2013 12:27 PM, Pedro Alves wrote:
>> > @@ -749,9 +749,13 @@ validate_actionline (char **line, struct
>> >  	  tmp_p = p;
>> >  	  for (loc = t->base.loc; loc; loc = loc->next)
>> >  	    {
>> > -	      p = tmp_p;
>> > -	      exp = parse_exp_1 (&p, loc->address,
>> > +	      const char *q, *o;
>> > +
>> > +	      o = q = tmp_p;
>> > +
>> > +	      exp = parse_exp_1 (&q, loc->address,
>> >  				 block_for_pc (loc->address), 1);
>> > +	      p += q - o;
>> >  	      old_chain = make_cleanup (free_current_contents, &exp);
>> >  
>> >  	      if (exp->elts[0].opcode == OP_VAR_VALUE)
> Argh all that extra pointer arithmetic hurts my eyes.
> 
> Do we really need it?  

BTW, over lunch I just had an epiphany.  :-)
This is perfectly fine:

 	  for (loc = t->base.loc; loc; loc = loc->next)
 	    {
-	      p = tmp_p;
+	      const char *q;
+
+	      q = tmp_p;
-	      exp = parse_exp_1 (&p, loc->address,
+	      exp = parse_exp_1 (&q, loc->address,
				 block_for_pc (loc->address), 1);
+	      p = (char *) q;

It's perfectly valid, as we know Q on output must point within
the object/string TMP_P pointed at on entry.
This reads much more intuitively to me, no funny arithmetic, and
gets rid of the aliasing issue with the other suggestion, and
no new function necessary.

-- 
Pedro Alves



More information about the Gdb-patches mailing list