GNU Binutils with patches for OS216
Revision | eeb1af437c6f1ca111bc31b63eefc5344b553681 (tree) |
---|---|
Zeit | 2016-02-10 03:02:53 |
Autor | Keith Seitz <keiths@redh...> |
Commiter | Keith Seitz |
Refactor string_to_event_location for legacy linespec support.
This patch refactors string_to_event_location, breaking it into two
separate functions:
1) string_to_event_location_basic
A "basic" string parser that implements support for "legacy" linespecs
(linespec, address, and probe locations). This function is intended to
be used by any UI wishing/needing to support this legacy behavior.
2) string_to_event_location
This is now intended as a CLI-only function which adds explicit location
parsing in a CLI-appropriate manner (in the form of traditional option/value
pairs).
Together these patches serve to simplify string-to-event location parsing
for all existing non-CLI interfaces (MI, guile, and python).
gdb/ChangeLog
* location.c (string_to_explicit_location): Note that "-p" is
reserved for probe locations and return NULL for any input
that starts with that.
(string_to_event_location): Move "legacy" linespec code to ...
(string_to_event_location_basic): ... here.
* location.h (string_to_event_location): Update comment.
(string_to_event_location_basic): New function.
@@ -1,3 +1,13 @@ | ||
1 | +2016-02-09 Keith Seitz <keiths@redhat.com> | |
2 | + | |
3 | + * location.c (string_to_explicit_location): Note that "-p" is | |
4 | + reserved for probe locations and return NULL for any input | |
5 | + that starts with that. | |
6 | + (string_to_event_location): Move "legacy" linespec code to ... | |
7 | + (string_to_event_location_basic): ... here. | |
8 | + * location.h (string_to_event_location): Update comment. | |
9 | + (string_to_event_location_basic): New function. | |
10 | + | |
1 | 11 | 2016-02-09 Simon Marchi <simon.marchi@ericsson.com> |
2 | 12 | |
3 | 13 | * configure.ac: Use AC_CONFIG_FILES instead of passing arguments |
@@ -522,11 +522,13 @@ string_to_explicit_location (const char **argp, | ||
522 | 522 | struct event_location *location; |
523 | 523 | |
524 | 524 | /* It is assumed that input beginning with '-' and a non-digit |
525 | - character is an explicit location. */ | |
525 | + character is an explicit location. "-p" is reserved, though, | |
526 | + for probe locations. */ | |
526 | 527 | if (argp == NULL |
527 | 528 | || *argp == '\0' |
528 | 529 | || *argp[0] != '-' |
529 | - || !isalpha ((*argp)[1])) | |
530 | + || !isalpha ((*argp)[1]) | |
531 | + || ((*argp)[0] == '-' && (*argp)[1] == 'p')) | |
530 | 532 | return NULL; |
531 | 533 | |
532 | 534 | location = new_explicit_location (NULL); |
@@ -634,51 +636,36 @@ string_to_explicit_location (const char **argp, | ||
634 | 636 | /* See description in location.h. */ |
635 | 637 | |
636 | 638 | struct event_location * |
637 | -string_to_event_location (char **stringp, | |
638 | - const struct language_defn *language) | |
639 | +string_to_event_location_basic (char **stringp, | |
640 | + const struct language_defn *language) | |
639 | 641 | { |
640 | 642 | struct event_location *location; |
643 | + const char *arg, *orig, *cs; | |
641 | 644 | |
642 | - /* First, check if the string is an address location. */ | |
643 | - if (*stringp != NULL && **stringp == '*') | |
645 | + /* Try the input as a probe spec. */ | |
646 | + cs = *stringp; | |
647 | + if (cs != NULL && probe_linespec_to_ops (&cs) != NULL) | |
644 | 648 | { |
645 | - const char *arg, *orig; | |
646 | - CORE_ADDR addr; | |
647 | - | |
648 | - orig = arg = *stringp; | |
649 | - addr = linespec_expression_to_pc (&arg); | |
650 | - location = new_address_location (addr, orig, arg - orig); | |
651 | - *stringp += arg - orig; | |
649 | + location = new_probe_location (*stringp); | |
650 | + *stringp += strlen (*stringp); | |
652 | 651 | } |
653 | 652 | else |
654 | 653 | { |
655 | - const char *cs; | |
656 | - | |
657 | - /* Next, try the input as a probe spec. */ | |
658 | - cs = *stringp; | |
659 | - if (cs != NULL && probe_linespec_to_ops (&cs) != NULL) | |
660 | - { | |
661 | - location = new_probe_location (*stringp); | |
662 | - *stringp += strlen (*stringp); | |
663 | - } | |
664 | - else | |
654 | + /* Try an address location. */ | |
655 | + if (*stringp != NULL && **stringp == '*') | |
665 | 656 | { |
666 | 657 | const char *arg, *orig; |
658 | + CORE_ADDR addr; | |
667 | 659 | |
668 | - /* Next, try an explicit location. */ | |
669 | 660 | orig = arg = *stringp; |
670 | - location = string_to_explicit_location (&arg, language, 0); | |
671 | - if (location != NULL) | |
672 | - { | |
673 | - /* It was a valid explicit location. Advance STRINGP to | |
674 | - the end of input. */ | |
675 | - *stringp += arg - orig; | |
676 | - } | |
677 | - else | |
678 | - { | |
679 | - /* Everything else is a linespec. */ | |
680 | - location = new_linespec_location (stringp); | |
681 | - } | |
661 | + addr = linespec_expression_to_pc (&arg); | |
662 | + location = new_address_location (addr, orig, arg - orig); | |
663 | + *stringp += arg - orig; | |
664 | + } | |
665 | + else | |
666 | + { | |
667 | + /* Everything else is a linespec. */ | |
668 | + location = new_linespec_location (stringp); | |
682 | 669 | } |
683 | 670 | } |
684 | 671 |
@@ -687,6 +674,34 @@ string_to_event_location (char **stringp, | ||
687 | 674 | |
688 | 675 | /* See description in location.h. */ |
689 | 676 | |
677 | +struct event_location * | |
678 | +string_to_event_location (char **stringp, | |
679 | + const struct language_defn *language) | |
680 | +{ | |
681 | + struct event_location *location; | |
682 | + const char *arg, *orig; | |
683 | + | |
684 | + /* Try an explicit location. */ | |
685 | + orig = arg = *stringp; | |
686 | + location = string_to_explicit_location (&arg, language, 0); | |
687 | + if (location != NULL) | |
688 | + { | |
689 | + /* It was a valid explicit location. Advance STRINGP to | |
690 | + the end of input. */ | |
691 | + *stringp += arg - orig; | |
692 | + } | |
693 | + else | |
694 | + { | |
695 | + /* Everything else is a "basic" linespec, address, or probe | |
696 | + location. */ | |
697 | + location = string_to_event_location_basic (stringp, language); | |
698 | + } | |
699 | + | |
700 | + return location; | |
701 | +} | |
702 | + | |
703 | +/* See description in location.h. */ | |
704 | + | |
690 | 705 | int |
691 | 706 | event_location_empty_p (const struct event_location *location) |
692 | 707 | { |
@@ -207,12 +207,24 @@ extern struct event_location * | ||
207 | 207 | but invalid, input, e.g., if it is called with missing argument parameters |
208 | 208 | or invalid options. |
209 | 209 | |
210 | - The return result must be freed with delete_event_location. */ | |
210 | + The return result must be freed with delete_event_location. | |
211 | + | |
212 | + This function is intended to be used by CLI commands and will parse | |
213 | + explicit locations in a CLI-centric way. Other interfaces should use | |
214 | + string_to_event_location_basic if they want to maintain support for | |
215 | + legacy specifications of probe, address, and linespec locations. */ | |
211 | 216 | |
212 | 217 | extern struct event_location * |
213 | 218 | string_to_event_location (char **argp, |
214 | 219 | const struct language_defn *langauge); |
215 | 220 | |
221 | +/* Like string_to_event_location, but does not attempt to parse explicit | |
222 | + locations. */ | |
223 | + | |
224 | +extern struct event_location * | |
225 | + string_to_event_location_basic (char **argp, | |
226 | + const struct language_defn *language); | |
227 | + | |
216 | 228 | /* Attempt to convert the input string in *ARGP into an explicit location. |
217 | 229 | ARGP is advanced past any processed input. Returns an event_location |
218 | 230 | (malloc'd) if an explicit location was successfully found in *ARGP, |