Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Eli Zaretskii <eliz@gnu.org>
To: luisgpm@linux.vnet.ibm.com
Cc: gdb-patches@sourceware.org
Subject: Re: [patch] Watchpoints: support for thread <thread_num> parameters
Date: Fri, 17 Aug 2007 10:24:00 -0000	[thread overview]
Message-ID: <uwsvuv4re.fsf@gnu.org> (raw)
In-Reply-To: <1187298178.5853.11.camel@localhost> (message from Luis Machado 	on Thu, 16 Aug 2007 18:02:58 -0300)

> From: Luis Machado <luisgpm@linux.vnet.ibm.com>
> Date: Thu, 16 Aug 2007 18:02:58 -0300
> 
> This is a first try on the implementation of the additional "thread
> <thread_num>" parameter for the watchpoint command in order to make GDB
> stop only on specific threads when a watchpoint is triggered.

Thanks.

> Basically i started parsing the arguments backwards, trying to locate
> tokens that identify a "thread <thread_num>" command. After that i hand
> all the left parameters over to the default expression parser.

Your code assumes that <thread_num> is a literal number.  Do we want
to allow an integral expression there, or is a literal number good
enough?

In any case, this change, if and when accepted, should be accompanied
by a suitable change to the user manual.

Allow me a few comments on your code:

> +    toklen = strlen (arg); /* Size of argument list  */
> +
> +    /* Points tok to the end of the argument list  */
> +    tok = arg + toklen;

Did you try your code when the argument has trailing whitespace?
Unless I'm missing something, the last line above make `tok' point to
the null character that ends the argument, so the while loop after
that will end immediately, even if there is whitespace after the
thread ID number, and the whole parsing business will not work
correctly.

> +    while (strlen (tok) < toklen && (*tok == ' ' || *tok == '\t'))
> +      tok--;
> +    while (strlen (tok) < toklen && (*tok != ' ' && *tok != '\t'))
> +      tok--;
> +
> +    /* Go backwards in the parameters list. Skip one more parameter.
> +       If we're expecting a 'thread <thread_num>' parameter, we should
> +       reach a "thread" token.  */
> +    while (strlen (tok) < toklen && (*tok == ' ' || *tok == '\t'))
> +      tok--;
> +
> +    end_tok = tok;
> +
> +    while (strlen (tok) < toklen && (*tok != ' ' && *tok != '\t'))
> +      tok--;

You don't need to compute `strlen (tok)' every time through the loops,
because each iteration you go back exactly one character.  So you can
compute it only once, and then decrement its value inside the loop
bodies.

Alternatively, just check that you didn't yet get to the first
character of the argument:

	  while (tok > arg && (*tok != ' ' && *tok != '\t'))
	    tok--;

I like this latter alternative better.

Actually, given the trailing whitespace problem I mentioned above,
this is even better:

	  while (tok > arg && (tok[-1] != ' ' && tok[-1] != '\t'))
	    tok--;

(You will need to adjust the rest of code to bump `tok' one position
forward after you exit the loop, to account for the -1 above.)

> +      tmptok = tok;
> +      thread = strtol (tok, &tok, 0);
> +
> +      if (tok == tmptok)
> +        error (_("Incorrect parameter after thread keyword."));

There's a much better way of checking whether `tok' is a literal
number: look at the pointer returned by `strtol' in its 2nd arg, and
if it points to something other than a whitespace character, err out:

     char *endp;
     thread = strtol (tok, &endp, 0);
     if (*endp != ' ' && *endp != '\t')
       error (_("Invalid thread ID specification %s."), tok);

Thanks again for working on this.


  reply	other threads:[~2007-08-17 10:24 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-08-16 21:03 Luis Machado
2007-08-17 10:24 ` Eli Zaretskii [this message]
2007-08-17 15:47   ` Luis Machado
2007-08-17 18:41     ` Eli Zaretskii
2007-08-17 18:50       ` Daniel Jacobowitz
2007-08-20 14:28         ` Luis Machado
2007-08-20 14:21           ` Daniel Jacobowitz
2007-08-20 15:23             ` Luis Machado
2007-08-20 15:29               ` Daniel Jacobowitz
2007-08-23 21:08                 ` Joel Brobecker
2007-08-23 21:15                   ` Luis Machado
2007-10-11 19:40     ` Daniel Jacobowitz
2007-10-11 20:33       ` Luis Machado
2007-11-13 14:50         ` Luis Machado
2007-11-13 15:38           ` Andreas Schwab
2007-11-13 22:30           ` Eli Zaretskii
2007-11-14 12:20             ` Luis Machado
2007-11-30 16:10               ` Luis Machado
2007-12-16 21:50               ` Daniel Jacobowitz
2007-12-17 13:29                 ` Luis Machado
2007-12-19 13:05                   ` [RFC/RFA] testsuite/gdb.base/watch_thread_num.exp: Fix test for systems having hidden threads Pierre Muller
2007-12-19 13:56                     ` Luis Machado
2007-12-19 14:04                       ` Pierre Muller
2007-12-19 14:05                     ` 'Daniel Jacobowitz'
2007-12-19 14:55                       ` Pierre Muller
2007-12-19 15:04                         ` 'Daniel Jacobowitz'

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=uwsvuv4re.fsf@gnu.org \
    --to=eliz@gnu.org \
    --cc=gdb-patches@sourceware.org \
    --cc=luisgpm@linux.vnet.ibm.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