Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: "Rob Quill" <rob.quill@gmail.com>
To: "Jim Blandy" <jimb@codesourcery.com>
Cc: msnyder@specifix.com, gdb-patches@sourceware.org
Subject: Re: New scope checking patch
Date: Thu, 17 Jan 2008 19:32:00 -0000	[thread overview]
Message-ID: <baf6008d0801171132x53374906vb98b243a39ab8d8c@mail.gmail.com> (raw)
In-Reply-To: <m37iigugbw.fsf@codesourcery.com>

[-- Attachment #1: Type: text/plain, Size: 3573 bytes --]

On 11/01/2008, Jim Blandy <jimb@codesourcery.com> wrote:
>
> "Rob Quill" <rob.quill at gmail.com> writes:
> > Please find attached the revised and much simpler patch. One of the
> > drawbacks of the new patch is that you cannot check the scope of
> > structure members, which is quite inconvenient, but I can't really fix
> > that without resorting to the old style of patch.
> >
> > I think that for the moment this patch is sufficient and definitely
> > provides and improvement, but I think in future it would be good to be
> > able to check arbitrary expressions, but as you say in your previous
> > email, this requires some significant reworking of the patch. It also
> > depends on how much people will find it useful. Michael, how do you
> > feel about this? (As you seemed interested in the previous attempt) If
> > there is enough interest then I am more than happy to spend some time
> > reworking the old patch at a later date.
>
> Unfortunately, I can't try out this patch.  Absurdly, the default
> output format for 'diff' can't be used reliably by patch, because it
> doesn't include any context lines (unchanged text surrounding the
> changed text), which 'patch' uses to ensure that the change doesn't
> conflict with other changes made to the code.
>
> Use 'cvs diff -u' or 'cvs diff -c' to produce unified or context
> diffs.  Unified diffs seem to be the more widely preferred form these
> days.  All patches posted to this list (or pretty much to any other
> open source list) should be in unified or context diff form.
>
> I have the following in my ~/.cvsrc file, so I don't have to remember
> to type '-u' all the time:
>
>         diff -u
>

Sorry about that, the attached patch is done with cvs diff -up

> >>          parse_number ("1", 1, 0, &val);
> >>          write_exp_elt_opcode (OP_LONG);
> >>          write_exp_elt_type (val.typed_val_int.type);
> >>          write_exp_elt_longcst ((LONGEST)val.typed_val_int.val);
> >>          write_exp_elt_opcode (OP_LONG);
>
> You've written out this code three times; that's quite a chunk.  I'd
> recommend first deciding whether the symbol is in scope (checking
> '$3.sym', and then calling lookup_minimal_symbol, as you do now), and
> computing a one or a zero from that.
>
> Then, did you know that you can get away with, simply:
>
>           struct type *int_type = builtin_type (current_gdbarch)->builtin_int;
>           write_exp_elt_opcode (OP_LONG);
>           write_exp_elt_type (int_type);
>           write_exp_elt_longcst (<flag value>);
>           write_exp_elt_opcode (OP_LONG);
>
> So there's no need to parse the number from a string.
>

Thanks for the tip :) I think the only example I had seen of parsing
actual values was where it used the parse number function, so I
assumed that was the right thing to use.

> > 1313a1357,1361
> >> static const struct token tokentab9[] =
> >>   {
> >>     {"$in_scope", IN_SCOPE, BINOP_END}
> >>   };
> >>
> > 1375a1424,1432
> >>   /* Code for recognising the $in_scope token. */
> >>   /* See if it is a special token of length 9.  */
> >>   for (i = 0; i < sizeof tokentab9 / sizeof tokentab9[0]; i++)
> >>     if (strncmp (tokstart, tokentab9[i].operator, 9) == 0)
> >>     {
> >>          lexptr += 9;
> >>          yylval.opcode = tokentab9[i].opcode;
> >>          return tokentab9[i].token;
> >>     }
>
> I think I would rather see $in_scope recognized like the other
> keywords (see "Catch specific keywords.") than at this point as a
> symbolic token.

My mistake, I didn't realise before that keywords were declared here.

Rob

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: in_scope.patch --]
[-- Type: text/x-diff; name=in_scope.patch, Size: 1544 bytes --]

Index: gdb/c-exp.y
===================================================================
RCS file: /cvs/src/src/gdb/c-exp.y,v
retrieving revision 1.42
diff -u -r1.42 c-exp.y
--- gdb/c-exp.y	9 Jan 2008 19:27:15 -0000	1.42
+++ gdb/c-exp.y	13 Jan 2008 20:22:26 -0000
@@ -208,6 +208,8 @@
 %token TRUEKEYWORD
 %token FALSEKEYWORD
 
+/* $in_scope opperator */
+%left IN_SCOPE
 
 %left ','
 %left ABOVE_COMMA
@@ -251,6 +253,32 @@
 	;
 
 /* Expressions, not including the comma operator.  */
+exp	: IN_SCOPE '(' name_not_typename ')'
+	{
+	  struct type *int_type;
+
+	  /* If there are no symbols then just stop right away */
+	  if (!have_full_symbols () && !have_partial_symbols ())
+		error ("No symbol table is loaded.  Use the \"file\" command.");
+
+	  /* Otherwise, prepare to write out the value */
+      int_type = builtin_type (current_gdbarch)->builtin_int;
+      write_exp_elt_opcode (OP_LONG);
+      write_exp_elt_type (int_type);
+
+	  if ($3.sym || lookup_minimal_symbol(copy_name($3.stoken), NULL, NULL))
+	  {
+        write_exp_elt_longcst ((LONGEST) 1);
+	  }
+	  else
+	  {
+	    write_exp_elt_longcst ((LONGEST) 0);
+	  }
+
+	  write_exp_elt_opcode (OP_LONG);
+	}
+	;
+
 exp	:	'*' exp    %prec UNARY
 			{ write_exp_elt_opcode (UNOP_IND); }
 	;
@@ -1678,6 +1706,9 @@
   /* Catch specific keywords.  Should be done with a data structure.  */
   switch (namelen)
     {
+	case 9:
+	  if (strncmp (tokstart, "$in_scope", 9) == 0)
+	return IN_SCOPE;
     case 8:
       if (strncmp (tokstart, "unsigned", 8) == 0)
 	return UNSIGNED;

  parent reply	other threads:[~2008-01-17 19:32 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-11-12 16:29 Rob Quill
2007-11-12 23:26 ` Michael Snyder
2008-01-10  1:00 ` Jim Blandy
2008-01-11  0:52   ` Rob Quill
2008-01-11 22:51     ` Jim Blandy
2008-01-14 23:07       ` Michael Snyder
2008-01-15 17:06         ` Jim Blandy
2008-01-17 19:32       ` Rob Quill [this message]
2008-01-17 20:15         ` Jim Blandy
2008-01-17 21:11           ` Rob Quill
2008-01-17 21:58             ` Jim Blandy
2008-01-17 23:40               ` Doug Evans
2008-01-18  1:31               ` Daniel Jacobowitz
2008-01-18  3:35               ` Rob Quill
2008-01-18 18:48                 ` Jim Blandy
2008-01-18 22:43                   ` Rob Quill
2008-01-19  0:38                     ` Jim Blandy
2008-01-30 13:11                       ` Rob Quill
2008-01-30 18:14                         ` Jim Blandy
2008-01-30 18:31                         ` Eli Zaretskii
2008-01-31  4:11                           ` Jim Blandy
2008-01-31  7:26                             ` Eli Zaretskii
2008-07-27 23:45                               ` Rob Quill
2008-07-28  3:18                                 ` Eli Zaretskii
2008-07-28 10:31                                   ` Rob Quill
2008-07-28 18:27                                     ` Eli Zaretskii
2008-07-29 20:31                                 ` Tom Tromey
2008-07-29 21:04                                   ` Rob Quill
2008-07-29 21:45                                     ` Tom Tromey
2008-07-29 22:53                                       ` Rob Quill
2008-07-30  3:34                                     ` Tom Tromey
2008-10-23 13:42                                       ` Convenience functions (was: Re: New scope checking patch) Daniel Jacobowitz
2008-10-23 15:17                                         ` Convenience functions Tom Tromey
2008-10-23 15:22                                           ` Daniel Jacobowitz
2008-10-23 15:26                                             ` Tom Tromey
2008-10-23 19:14                                             ` Tom Tromey
2008-10-24 12:53                                               ` Eli Zaretskii
2008-11-04 21:37                                         ` Convenience functions (was: Re: New scope checking patch) Thiago Jung Bauermann
2008-11-04 22:23                                           ` Daniel Jacobowitz
2008-11-04 22:43                                             ` Convenience functions Tom Tromey
2008-01-31  7:52                             ` New scope checking patch Michael Snyder
2008-01-19  1:35                     ` Michael Snyder

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=baf6008d0801171132x53374906vb98b243a39ab8d8c@mail.gmail.com \
    --to=rob.quill@gmail.com \
    --cc=gdb-patches@sourceware.org \
    --cc=jimb@codesourcery.com \
    --cc=msnyder@specifix.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox