Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Vladimir Prus <vladimir@codesourcery.com>
To: "Marc Khouzam" <marc.khouzam@ericsson.com>
Cc: gdb-patches@sources.redhat.com
Subject: Re: [MI non-stop 04/11] Implement --thread and --frame.
Date: Sun, 29 Jun 2008 06:08:00 -0000	[thread overview]
Message-ID: <200806291003.28226.vladimir@codesourcery.com> (raw)
In-Reply-To: <6D19CA8D71C89C43A057926FE0D4ADAA04E1BD85@ecamlmw720.eamcs.ericsson.se>

On Saturday 28 June 2008 21:56:21 Marc Khouzam wrote:
> Hi,
> 
> I don't know enough to thoroughly review so I'll give the minor comments
> I have.
>  
> > +  if (parse->frame != -1 && !parse->thread == -1)
> 
> You probably didn't mean to have ! before parse->thread

Doh! You're right.

> 
> > +    error ("Cannot specify --frame without --thread");
> > +  
> > +  if (parse->thread != -1)
> > +    {
> > +      struct thread_info *tp = find_thread_id (parse->thread);
> > +      if (!tp)
> > + error (_("Invalid thread id: %d"), parse->thread);
> > +      
> > +      if (non_stop)
> > + context_switch_to (tp->ptid);
> > +      else
> > +   switch_to_thread (tp->ptid);
> > +    }
> > +  
> > +  if (parse->frame != -1)
> > +    {
> > +      struct frame_info *fid;
> > +      int frame = parse->frame;
> > +      fid = find_relative_frame (get_current_frame (), &frame);
> > +      if (frame == 0)
> > +   /* find_relative_frame was successful */
> > +   select_frame (fid);
> > +      else
> > +   error (_("Invalid frame id: %s"), frame_str);
> > +    }
> > +  
> >    if (parse->cmd->argv_func != NULL)
> >      {
> >        if (target_can_async_p ()
> > @@ -1171,6 +1202,7 @@ mi_cmd_execute (struct mi_parse *parse)
> >           error_stream (stb);
> >         }
> >     }
> > +
> >        current_token = xstrdup (parse->token);
> >        cleanup = make_cleanup (free_current_contents, &current_token);
> >        parse->cmd->argv_func (parse->command, parse->argv, parse->argc);
> > diff --git a/gdb/mi/mi-parse.c b/gdb/mi/mi-parse.c
> > index a2dc50d..835fb74 100644
> > --- a/gdb/mi/mi-parse.c
> > +++ b/gdb/mi/mi-parse.c
> > @@ -150,6 +150,8 @@ mi_parse (char *cmd)
> >    char *chp;
> >    struct mi_parse *parse = XMALLOC (struct mi_parse);
> >    memset (parse, 0, sizeof (*parse));
> > +  parse->thread = -1;
> > +  parse->frame = -1;
> >  
> >    /* Before starting, skip leading white space. */
> >    while (isspace (*cmd))
> > @@ -199,6 +201,38 @@ mi_parse (char *cmd)
> >    while (isspace (*chp))
> >      chp++;
> >  
> > +  /* Parse the --thread and --frame options, if present.  At present,
> > +     some important commands, like '-break-*' are implemented by forwarding
> > +     to the CLI layer directly.  We want to parse --thread and --frame
> > +     here, so as not to leave those option in the string that will be passed
> > +     to CLI.  */
> > +  for (;;)
> > +    {
> > +      char *start = chp;
> > +      if (strncmp (chp, "--thread", 8) == 0)
> 
> Although this works, if you later add a new param like --thread-list,
> it will falsly match here.  Maybe you want to strncmp with "--thread "?
> (with a space at the end) 

Yes, I think this will make the code more robust.
    
> I'm not sure what the coding style is for GDB in this case, but I have
> found that it is more maintainable not to hard-code the lengths, but to use
> something like
>    char* threadStr = "--thread ";
>    int len = strlen(threadStr);

This is nice bikeshed question :-) Personally, I find that what I have is
perfectly maintainable, due to GNU Emacs having Esc-= shortcut -- which
counts the number of characters in a region.

> > +   {
> > +     if (parse->thread != -1)
> > +       error ("Duplicate '--thread' option");
> > +     chp += 8;
> > +     parse->thread = strtol (chp, &chp, 10);
> > +   }
> > +      else if (strncmp (chp, "--frame", 7) == 0)
> > +   {
> > +     if (parse->frame != -1)
> > +       error ("Duplicate '--frame' option");
> > +     chp += 7;
> > +     parse->frame = strtol (chp, &chp, 10);
> > +   }
> > +      else
> > +   break;
> 
> Are --frame and --thread the only options that can be found when we are
> running this code? If yes, then its fine; if no, then you shouldn't break
> on else but should skip the uninteresting option.

I intend for those option to be required to be the first.  This is yet another
issue arising from too many ways to handle MI commands -- for some commands
we parse the command per MI rule, get argc/argv and then can extract options
just fine. Some other commands are passed to CLI, verbatim. But we want --thread
to work for those commands, too. It's a bit risky to grab --thread in the
middle of command, so I look for --thread and --frame at the beginning of the
command, and pass the remainder to CLI.

- Volodya


  parent reply	other threads:[~2008-06-29  6:03 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-06-28 16:54 Vladimir Prus
2008-06-28 17:30 ` Eli Zaretskii
2008-06-28 18:00   ` Vladimir Prus
2008-06-28 18:23     ` Eli Zaretskii
2008-06-28 18:26       ` Marc Khouzam
2008-06-29  6:10       ` Vladimir Prus
2008-06-29 20:15         ` Eli Zaretskii
2008-07-01  3:53           ` Vladimir Prus
2008-06-30 18:35       ` Michael Snyder
2008-06-30 18:42         ` Daniel Jacobowitz
2008-06-28 18:13 ` Marc Khouzam
2008-06-28 18:26   ` Eli Zaretskii
2008-06-28 18:27     ` Marc Khouzam
2008-06-29  6:08   ` Vladimir Prus [this message]
2008-06-29 19:42     ` Eli Zaretskii
2008-06-30  0:09       ` Tom Tromey
2008-06-30  8:39         ` Eli Zaretskii
2008-06-30 18:35         ` Michael Snyder
2008-06-30 19:19           ` Tom Tromey
2008-06-30 20:47             ` Daniel Jacobowitz
2008-07-11 12:50 ` Daniel Jacobowitz
2008-07-12 20:15 ` Ulrich Weigand
2008-07-13  3:54   ` Vladimir Prus
2008-07-15 18:42     ` Ulrich Weigand
2008-07-13  5:45 ` Vladimir Prus

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=200806291003.28226.vladimir@codesourcery.com \
    --to=vladimir@codesourcery.com \
    --cc=gdb-patches@sources.redhat.com \
    --cc=marc.khouzam@ericsson.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