From: Keith Seitz <keiths@redhat.com>
To: Doug Evans <xdje42@gmail.com>
Cc: gdb-patches@sourceware.org
Subject: Re: [PATCH v4 7/9] Explicit locations: add UI features for CLI
Date: Tue, 19 May 2015 20:41:00 -0000 [thread overview]
Message-ID: <555B9FF2.4030203@redhat.com> (raw)
In-Reply-To: <m3wq06pe9j.fsf@sspiff.org>
On 05/17/2015 11:54 PM, Doug Evans wrote:
> Keith Seitz <keiths@redhat.com> writes:
>>
>> diff --git a/gdb/location.c b/gdb/location.c
>> index 7882b2d..779bcfa 100644
>> --- a/gdb/location.c
>> +++ b/gdb/location.c
>> @@ -442,6 +442,203 @@ event_location_to_string (struct event_location *location)
>> return EL_STRING (location);
>> }
>>
>> +/* A lexer for explicit locations. This function will advance INP
>> + past any strings that it lexes. Returns a malloc'd copy of the
>> + lexed string or NULL if no lexing was done. */
>> +
>> +static char *
>> +explicit_location_lex_one (const char **inp,
>> + const struct language_defn *language)
>> +{
>> + const char *start = *inp;
>> +
>> + if (*start == '\0')
>> + return NULL;
>> +
>> + /* If quoted, skip to the ending quote. */
>> + if (strchr (get_gdb_linespec_parser_quote_characters (), *start))
>> + {
>> + char quote_char = *start;
>> +
>> + /* If the input is not an Ada operator, skip to the matching
>> + closing quote and return the string. */
>> + if (!(language->la_language == language_ada
>> + && quote_char == '\"' && is_ada_operator (start)))
>> + {
>> + const char *end = find_toplevel_char (start + 1, quote_char);
>> +
>> + if (end == NULL)
>> + error (_("Unmatched quote, %s."), start);
>> + *inp = end + 1;
>> + return savestring (start + 1, *inp - start - 2);
>> + }
>> + }
>> +
>> + /* If the input starts with '-' or '+', the string ends with the next
>> + whitespace. */
>> + if (*start == '-' || *start == '+')
>> + *inp = skip_to_space_const (*inp);
>
> I suspect this is just following what the existing code does,
> but why not also watch for commas when there's a leading +,-?
> If this is just following code and there's an issue here
> I'd leave it for another day to change.
Good catch. I've implemented this and added a few tests for it.
>> +/* See description in location.h. */
>> +
>> +struct event_location *
>> +string_to_explicit_location (const char **argp,
>> + const struct language_defn *language,
>> + int dont_throw)
>> +{
>> + struct cleanup *cleanup;
>> + struct event_location *location;
>> +
>> + /* It is assumed that input beginning with '-' and a non-digit
>> + character is an explicit location. */
>> + if (argp == NULL
>> + || *argp == '\0'
>> + || *argp[0] != '-'
>> + || !isalpha ((*argp)[1]))
>> + return NULL;
>> +
>> + location = new_explicit_location (NULL);
>> + cleanup = make_cleanup_delete_event_location (location);
>> +
>> + /* Process option/argument pairs. dprintf_command
>> + requires that processing stop on ','. */
>> + while ((*argp)[0] != '\0' && (*argp)[0] != ',')
>> + {
>> + int len;
>> + char *opt, *oarg;
>> + const char *start;
>> + struct cleanup *inner;
>> +
>> + /* If *ARGP starts with a keyword, stop processing
>> + options. */
>> + if (linespec_lexer_lex_keyword (*argp) != NULL)
>> + break;
>> +
>> + /* Mark the start of the string in case we need to rewind. */
>> + start = *argp;
>> +
>> + /* Get the option string. */
>> + opt = explicit_location_lex_one (argp, language);
>> + inner = make_cleanup (xfree, opt);
>> +
>> + *argp = skip_spaces_const (*argp);
>> +
>> + /* Get the argument string. */
>> + oarg = explicit_location_lex_one (argp, language);
>> +
>> + *argp = skip_spaces_const (*argp);
>> +
>> + /* Use the length of the option to allow abbreviations. */
>> + len = strlen (opt);
>> +
>> + /* All options have a required argument. Checking for this required
>> + argument is deferred until later. */
>> + if (strncmp (opt, "-source", len) == 0)
>> + EL_EXPLICIT (location)->source_filename = oarg;
>> + else if (strncmp (opt, "-function", len) == 0)
>> + EL_EXPLICIT (location)->function_name = oarg;
>> + else if (strncmp (opt, "-line", len) == 0)
>> + {
>> + if (oarg != NULL)
>> + {
>> + TRY
>> + {
>> + EL_EXPLICIT (location)->line_offset
>> + = linespec_parse_line_offset (oarg);
>> + }
>> + CATCH (e, RETURN_MASK_ERROR)
>> + {
>> + xfree (oarg);
>
> Could other exception types leak oarg here?
Not that I can see. When any successful argument value is parsed, it is
added to the event_location, which has a cleanup on it which will free
any defined members when an exception occurs.
The only two functions (in this loop) that could throw an exception are
explicit_location_lex_one and linespec_parse_line_offset.
In the former case, the option name has a cleanup when parsing the
value. The value is either saved into the event_location or discarded if
we are going to throw an exception.
linespec_parse_line_offset can throw an error (GENERIC_ERROR), but it is
already caught and memory for oarg is freed. Nothing can generate a
RETURN_QUIT as far as I can tell. Did you have a case specifically in mind?
Keith
next prev parent reply other threads:[~2015-05-19 20:41 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-05-07 18:05 [PATCH v4 0/9] Locations API Keith Seitz
2015-05-07 18:05 ` [PATCH v4 2/9] Explicit locations: introduce new struct event_location-based API Keith Seitz
2015-05-17 20:54 ` Doug Evans
2015-05-19 20:41 ` Keith Seitz
2015-05-19 22:16 ` Pedro Alves
2015-05-07 18:06 ` [PATCH v4 4/9] Explicit locations: introduce address locations Keith Seitz
2015-05-18 5:45 ` Doug Evans
2015-05-07 18:06 ` [PATCH v4 5/9] Explicit locations: introduce probe locations Keith Seitz
2015-05-18 5:49 ` Doug Evans
2015-05-07 18:06 ` [PATCH v4 7/9] Explicit locations: add UI features for CLI Keith Seitz
2015-05-18 6:55 ` Doug Evans
2015-05-19 20:41 ` Keith Seitz [this message]
2015-05-27 4:27 ` Doug Evans
2015-05-07 18:06 ` [PATCH v4 1/9] Explicit locations: rename "address string"/"addr_string" to "location" Keith Seitz
2015-05-17 20:10 ` Doug Evans
2015-05-07 18:06 ` [PATCH v4 3/9] Explicit locations: use new location API Keith Seitz
2015-05-18 5:21 ` Doug Evans
2015-05-19 21:30 ` Keith Seitz
2015-05-07 18:06 ` [PATCH v4 8/9] Explicit locations: MI support for explicit locations Keith Seitz
2015-05-18 7:16 ` Doug Evans
2015-05-07 18:06 ` [PATCH v4 6/9] Explicit locations: introduce " Keith Seitz
2015-05-18 6:13 ` Doug Evans
2015-05-18 20:14 ` Keith Seitz
2015-05-19 22:09 ` Pedro Alves
2015-05-19 22:12 ` Keith Seitz
2015-05-19 22:15 ` Pedro Alves
2015-05-19 22:20 ` Keith Seitz
2015-05-21 19:34 ` [PATCH v5] Explicit locations: add UI features for CLI Keith Seitz
2015-05-27 4:43 ` [PATCH v4 6/9] Explicit locations: introduce explicit locations Doug Evans
2015-05-27 11:36 ` Matt Rice
2015-05-30 15:17 ` Matt Rice
2015-05-07 18:13 ` [PATCH v4 9/9] Explicit locations: documentation updates Keith Seitz
2015-05-07 18:55 ` Eli Zaretskii
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=555B9FF2.4030203@redhat.com \
--to=keiths@redhat.com \
--cc=gdb-patches@sourceware.org \
--cc=xdje42@gmail.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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).