* [RFA] Add ObjC recognition to linespec.c [5/5]
@ 2003-01-03 23:31 Adam Fedor
2003-01-04 1:32 ` Michael Snyder
2003-01-06 20:23 ` Elena Zannoni
0 siblings, 2 replies; 9+ messages in thread
From: Adam Fedor @ 2003-01-03 23:31 UTC (permalink / raw)
To: GDB Patches
[-- Attachment #1: Type: text/plain, Size: 265 bytes --]
I know that linespec has been changing a lot lately, and I'm not sure if
it's finished changing yet. So this is my attempt to insert ObjC
handling into linespec. Actually Klee Dienes really did most of these
changes, and I probably bastardized those as well...
[-- Attachment #2: objc23.patch --]
[-- Type: text/plain, Size: 6732 bytes --]
2003-01-03 Adam Fedor <fedor@gnu.org>
* linespec.c (decode_objc): New function to decode ObjC calls
(decode_line_1): Check for ObjC calls (using decode_objc)
Index: linespec.c
===================================================================
RCS file: /cvs/src/src/gdb/linespec.c,v
retrieving revision 1.32
diff -u -p -r1.32 linespec.c
--- linespec.c 19 Dec 2002 18:56:14 -0000 1.32
+++ linespec.c 3 Jan 2003 22:56:54 -0000
@@ -37,6 +37,11 @@
extern char *operator_chars (char *, char **);
+/* From objc-lang.h. Included here to avoid conflict with other prototypes */
+extern char *find_imps (struct symtab *symtab, struct block *block,
+ char *method, struct symbol **syms, unsigned int *nsym,
+ unsigned int *ndebug);
+
/* Prototypes for local functions */
static void initialize_defaults (struct symtab **default_symtab,
@@ -48,6 +53,12 @@ static struct symtabs_and_lines decode_i
static char *locate_first_half (char **argptr, int *is_quote_enclosed);
+static struct symtabs_and_lines decode_objc (char **argptr,
+ int funfirstline,
+ struct symtab *file_symtab,
+ char ***canonical,
+ char *saved_arg);
+
static struct symtabs_and_lines decode_compound (char **argptr,
int funfirstline,
char ***canonical,
@@ -568,6 +579,7 @@ decode_line_1 (char **argptr, int funfir
int is_quoted;
/* Is part of *ARGPTR is enclosed in double quotes? */
int is_quote_enclosed;
+ int is_objc_method = 0;
char *saved_arg = *argptr;
init_sal (&val); /* initialize to zeroes */
@@ -596,6 +608,24 @@ decode_line_1 (char **argptr, int funfir
p = locate_first_half (argptr, &is_quote_enclosed);
+ /* Check if this is an Objective-C method. */
+ if (*p && (p[0] == ':') && (strchr ("+-", p[1]) != NULL)
+ && (p[2] == '['))
+ {
+ is_objc_method = 1;
+ paren_pointer = NULL; /* Probably just a category name. Ignore it */
+ }
+
+ /* Is it an Objective-C selector? */
+
+ {
+ struct symtabs_and_lines values;
+ values = decode_objc (argptr, funfirstline, NULL,
+ canonical, saved_arg);
+ if (values.sals != NULL)
+ return values;
+ }
+
/* Does it look like there actually were two parts? */
if ((p[0] == ':' || p[0] == '.') && paren_pointer == NULL)
@@ -669,13 +699,21 @@ decode_line_1 (char **argptr, int funfir
Find the next token (everything up to end or next whitespace). */
if (**argptr == '$') /* May be a convenience variable */
- p = skip_quoted (*argptr + (((*argptr)[1] == '$') ? 2 : 1)); /* One or two $ chars possible */
+ {
+ /* One or two $ chars possible */
+ p = skip_quoted (*argptr + (((*argptr)[1] == '$') ? 2 : 1));
+ }
else if (is_quoted)
{
p = skip_quoted (*argptr);
if (p[-1] != '\'')
error ("Unmatched single quote.");
}
+ else if (is_objc_method)
+ {
+ /* allow word separators in method names for Obj-C */
+ p = skip_quoted_chars (*argptr, NULL, "");
+ }
else if (paren_pointer != NULL)
{
p = paren_pointer + 1;
@@ -952,6 +990,13 @@ locate_first_half (char **argptr, int *i
error ("malformed template specification in command");
p = temp_end;
}
+ /* Check for a colon and a plus or minus and a [ (which
+ indicates an Objective-C method) */
+ if (*p && (p[0] == ':') && (strchr ("+-", p[1]) != NULL)
+ && (p[2] == '['))
+ {
+ break;
+ }
/* Check for the end of the first half of the linespec. End of line,
a tab, a double colon or the last single colon, or a space. But
if enclosed in double quotes we do not break on enclosed spaces */
@@ -993,6 +1038,98 @@ locate_first_half (char **argptr, int *i
}
\f
+
+struct symtabs_and_lines
+decode_objc (char **argptr, int funfirstline, struct symtab *file_symtab,
+ char ***canonical, char *saved_arg)
+{
+ /* here's where we recognise an Objective-C Selector. An
+ * Objective C selector may be implemented by more than one
+ * class, therefore it may represent more than one
+ * method/function. This gives us a situation somewhat
+ * analogous to C++ overloading. If there's more than one
+ * method that could represent the selector, then use some of
+ * the existing C++ code to let the user choose one.
+ */
+
+ struct symtabs_and_lines values;
+ struct symbol **sym_arr = NULL;
+ struct symbol *sym = NULL;
+ char *copy = NULL;
+ struct block *block = NULL;
+ int i1 = 0;
+ int i2 = 0;
+
+ values.sals = NULL;
+ values.nelts = 0;
+
+ if (file_symtab != NULL)
+ block = BLOCKVECTOR_BLOCK (BLOCKVECTOR (file_symtab), STATIC_BLOCK);
+ else
+ block = get_selected_block (0);
+
+ copy = find_imps (file_symtab, block, *argptr, NULL, &i1, &i2);
+
+ if (i1 > 0)
+ {
+ sym_arr = (struct symbol **) alloca ((i1 + 1) * sizeof (struct symbol *));
+ sym_arr[i1] = 0;
+
+ copy = find_imps (file_symtab, block, *argptr, sym_arr, &i1, &i2);
+ *argptr = copy;
+ }
+
+ /* i1 now represents the TOTAL number of matches found...
+ i2 represents how many HIGH-LEVEL (struct symbol) matches,
+ which will come first in the sym_arr array. Any low-level
+ (minimal_symbol) matches will follow those. */
+
+ if (i1 == 1)
+ {
+ if (i2 > 0)
+ {
+ /* already a struct symbol */
+ sym = sym_arr[0];
+ }
+ else
+ {
+ sym = find_pc_function (SYMBOL_VALUE_ADDRESS (sym_arr[0]));
+ if ((sym != NULL) && strcmp (SYMBOL_NAME (sym_arr[0]), SYMBOL_NAME (sym)) != 0)
+ {
+ warning ("debugging symbol \"%s\" does not match selector; ignoring", SYMBOL_NAME (sym));
+ sym = NULL;
+ }
+ }
+
+ values.sals = (struct symtab_and_line *) xmalloc (sizeof (struct symtab_and_line));
+ values.nelts = 1;
+
+ if (sym && SYMBOL_CLASS (sym) == LOC_BLOCK)
+ {
+ /* canonicalize this, so it remains resolved for dylib loads */
+ values.sals[0] = find_function_start_sal (sym, funfirstline);
+ build_canonical_line_spec (values.sals, SYMBOL_SOURCE_NAME (sym), canonical);
+ }
+ else
+ {
+ /* the only match was a non-debuggable symbol */
+ values.sals[0].symtab = 0;
+ values.sals[0].line = 0;
+ values.sals[0].end = 0;
+ values.sals[0].pc = SYMBOL_VALUE_ADDRESS (sym_arr[0]);
+ }
+ return values;
+ }
+
+ if (i1 > 1)
+ {
+ /* more than one match -- user must choose one or more */
+ return decode_line_2 (sym_arr, i2, funfirstline, canonical);
+ //return select_symbols (sym_arr, i1, i2, funfirstline, canonical);
+ }
+
+ return values;
+}
/* This handles C++ and Java compound data structures. P should point
at the first component separator, i.e. double-colon or period. */
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [RFA] Add ObjC recognition to linespec.c [5/5]
2003-01-03 23:31 [RFA] Add ObjC recognition to linespec.c [5/5] Adam Fedor
@ 2003-01-04 1:32 ` Michael Snyder
2003-01-04 2:53 ` Adam Fedor
2003-01-06 20:23 ` Elena Zannoni
1 sibling, 1 reply; 9+ messages in thread
From: Michael Snyder @ 2003-01-04 1:32 UTC (permalink / raw)
To: Adam Fedor; +Cc: GDB Patches
Adam Fedor wrote:
>
> I know that linespec has been changing a lot lately, and I'm not sure if
> it's finished changing yet. So this is my attempt to insert ObjC
> handling into linespec. Actually Klee Dienes really did most of these
> changes, and I probably bastardized those as well...
>
> -------------------------------------------------------------------------------
> 2003-01-03 Adam Fedor <fedor@gnu.org>
>
> * linespec.c (decode_objc): New function to decode ObjC calls
> (decode_line_1): Check for ObjC calls (using decode_objc)
>
> Index: linespec.c
> ===================================================================
> RCS file: /cvs/src/src/gdb/linespec.c,v
> retrieving revision 1.32
> diff -u -p -r1.32 linespec.c
> --- linespec.c 19 Dec 2002 18:56:14 -0000 1.32
> +++ linespec.c 3 Jan 2003 22:56:54 -0000
> @@ -37,6 +37,11 @@
>
> extern char *operator_chars (char *, char **);
>
> +/* From objc-lang.h. Included here to avoid conflict with other prototypes */
> +extern char *find_imps (struct symtab *symtab, struct block *block,
> + char *method, struct symbol **syms, unsigned int *nsym,
> + unsigned int *ndebug);
> +
I presume this will go away when you can include objc-lang.h.
> /* Prototypes for local functions */
>
> static void initialize_defaults (struct symtab **default_symtab,
> @@ -48,6 +53,12 @@ static struct symtabs_and_lines decode_i
>
> static char *locate_first_half (char **argptr, int *is_quote_enclosed);
>
> +static struct symtabs_and_lines decode_objc (char **argptr,
> + int funfirstline,
> + struct symtab *file_symtab,
> + char ***canonical,
> + char *saved_arg);
> +
I like this -- presumably it keeps a lot of the new code
out of poor old decrepit decode_line_1.
> static struct symtabs_and_lines decode_compound (char **argptr,
> int funfirstline,
> char ***canonical,
> @@ -568,6 +579,7 @@ decode_line_1 (char **argptr, int funfir
> int is_quoted;
> /* Is part of *ARGPTR is enclosed in double quotes? */
> int is_quote_enclosed;
> + int is_objc_method = 0;
> char *saved_arg = *argptr;
>
> init_sal (&val); /* initialize to zeroes */
> @@ -596,6 +608,24 @@ decode_line_1 (char **argptr, int funfir
>
> p = locate_first_half (argptr, &is_quote_enclosed);
>
> + /* Check if this is an Objective-C method. */
> + if (*p && (p[0] == ':') && (strchr ("+-", p[1]) != NULL)
> + && (p[2] == '['))
> + {
> + is_objc_method = 1;
> + paren_pointer = NULL; /* Probably just a category name. Ignore it */
> + }
> +
> + /* Is it an Objective-C selector? */
> +
> + {
> + struct symtabs_and_lines values;
> + values = decode_objc (argptr, funfirstline, NULL,
> + canonical, saved_arg);
> + if (values.sals != NULL)
> + return values;
> + }
Was this meant to be an if? It seems to be a naked block.
I'd feel better if there was an if around it, eg. is there
a simple way to test for a selector name? Do I remember
that they begin with a unique prefix such as '@'?
> +
> /* Does it look like there actually were two parts? */
>
> if ((p[0] == ':' || p[0] == '.') && paren_pointer == NULL)
> @@ -669,13 +699,21 @@ decode_line_1 (char **argptr, int funfir
> Find the next token (everything up to end or next whitespace). */
>
> if (**argptr == '$') /* May be a convenience variable */
> - p = skip_quoted (*argptr + (((*argptr)[1] == '$') ? 2 : 1)); /* One or two $ chars possible */
> + {
> + /* One or two $ chars possible */
> + p = skip_quoted (*argptr + (((*argptr)[1] == '$') ? 2 : 1));
> + }
> else if (is_quoted)
> {
> p = skip_quoted (*argptr);
> if (p[-1] != '\'')
> error ("Unmatched single quote.");
> }
> + else if (is_objc_method)
> + {
> + /* allow word separators in method names for Obj-C */
> + p = skip_quoted_chars (*argptr, NULL, "");
> + }
OK, except didn't we decide that "skip_quoted_chars" needs a
better name? One that identifies it with objc?
> else if (paren_pointer != NULL)
> {
> p = paren_pointer + 1;
> @@ -952,6 +990,13 @@ locate_first_half (char **argptr, int *i
> error ("malformed template specification in command");
> p = temp_end;
> }
> + /* Check for a colon and a plus or minus and a [ (which
> + indicates an Objective-C method) */
> + if (*p && (p[0] == ':') && (strchr ("+-", p[1]) != NULL)
> + && (p[2] == '['))
> + {
> + break;
> + }
> /* Check for the end of the first half of the linespec. End of line,
> a tab, a double colon or the last single colon, or a space. But
> if enclosed in double quotes we do not break on enclosed spaces */
> @@ -993,6 +1038,98 @@ locate_first_half (char **argptr, int *i
> }
>
>
> +
> +struct symtabs_and_lines
> +decode_objc (char **argptr, int funfirstline, struct symtab *file_symtab,
> + char ***canonical, char *saved_arg)
> +{
> + /* here's where we recognise an Objective-C Selector. An
> + * Objective C selector may be implemented by more than one
> + * class, therefore it may represent more than one
> + * method/function. This gives us a situation somewhat
> + * analogous to C++ overloading. If there's more than one
> + * method that could represent the selector, then use some of
> + * the existing C++ code to let the user choose one.
> + */
> +
> + struct symtabs_and_lines values;
> + struct symbol **sym_arr = NULL;
> + struct symbol *sym = NULL;
> + char *copy = NULL;
> + struct block *block = NULL;
> + int i1 = 0;
> + int i2 = 0;
> +
> + values.sals = NULL;
> + values.nelts = 0;
> +
> + if (file_symtab != NULL)
> + block = BLOCKVECTOR_BLOCK (BLOCKVECTOR (file_symtab), STATIC_BLOCK);
> + else
> + block = get_selected_block (0);
> +
> + copy = find_imps (file_symtab, block, *argptr, NULL, &i1, &i2);
> +
> + if (i1 > 0)
> + {
> + sym_arr = (struct symbol **) alloca ((i1 + 1) * sizeof (struct symbol *));
> + sym_arr[i1] = 0;
> +
> + copy = find_imps (file_symtab, block, *argptr, sym_arr, &i1, &i2);
> + *argptr = copy;
> + }
> +
> + /* i1 now represents the TOTAL number of matches found...
> + i2 represents how many HIGH-LEVEL (struct symbol) matches,
> + which will come first in the sym_arr array. Any low-level
> + (minimal_symbol) matches will follow those. */
> +
> + if (i1 == 1)
> + {
> + if (i2 > 0)
> + {
> + /* already a struct symbol */
> + sym = sym_arr[0];
> + }
> + else
> + {
> + sym = find_pc_function (SYMBOL_VALUE_ADDRESS (sym_arr[0]));
> + if ((sym != NULL) && strcmp (SYMBOL_NAME (sym_arr[0]), SYMBOL_NAME (sym)) != 0)
> + {
> + warning ("debugging symbol \"%s\" does not match selector; ignoring", SYMBOL_NAME (sym));
> + sym = NULL;
> + }
> + }
> +
> + values.sals = (struct symtab_and_line *) xmalloc (sizeof (struct symtab_and_line));
> + values.nelts = 1;
> +
> + if (sym && SYMBOL_CLASS (sym) == LOC_BLOCK)
> + {
> + /* canonicalize this, so it remains resolved for dylib loads */
> + values.sals[0] = find_function_start_sal (sym, funfirstline);
> + build_canonical_line_spec (values.sals, SYMBOL_SOURCE_NAME (sym), canonical);
> + }
> + else
> + {
> + /* the only match was a non-debuggable symbol */
> + values.sals[0].symtab = 0;
> + values.sals[0].line = 0;
> + values.sals[0].end = 0;
> + values.sals[0].pc = SYMBOL_VALUE_ADDRESS (sym_arr[0]);
> + }
> + return values;
> + }
> +
> + if (i1 > 1)
> + {
> + /* more than one match -- user must choose one or more */
> + return decode_line_2 (sym_arr, i2, funfirstline, canonical);
> + //return select_symbols (sym_arr, i1, i2, funfirstline, canonical);
> + }
> +
> + return values;
> +}
>
> /* This handles C++ and Java compound data structures. P should point
> at the first component separator, i.e. double-colon or period. */
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [RFA] Add ObjC recognition to linespec.c [5/5]
2003-01-04 1:32 ` Michael Snyder
@ 2003-01-04 2:53 ` Adam Fedor
2003-01-06 20:32 ` Michael Snyder
0 siblings, 1 reply; 9+ messages in thread
From: Adam Fedor @ 2003-01-04 2:53 UTC (permalink / raw)
To: Michael Snyder; +Cc: GDB Patches
Michael Snyder wrote:
> Adam Fedor wrote:
>
>>I know that linespec has been changing a lot lately, and I'm not sure if
>>it's finished changing yet. So this is my attempt to insert ObjC
>>handling into linespec. Actually Klee Dienes really did most of these
>>changes, and I probably bastardized those as well...
>>
>> -------------------------------------------------------------------------------
>>2003-01-03 Adam Fedor <fedor@gnu.org>
>>
>> * linespec.c (decode_objc): New function to decode ObjC calls
>> (decode_line_1): Check for ObjC calls (using decode_objc)
>>
>>Index: linespec.c
>>===================================================================
>>RCS file: /cvs/src/src/gdb/linespec.c,v
>>retrieving revision 1.32
>>diff -u -p -r1.32 linespec.c
>>--- linespec.c 19 Dec 2002 18:56:14 -0000 1.32
>>+++ linespec.c 3 Jan 2003 22:56:54 -0000
>>@@ -37,6 +37,11 @@
>>
>> extern char *operator_chars (char *, char **);
>>
>>+/* From objc-lang.h. Included here to avoid conflict with other prototypes */
>>+extern char *find_imps (struct symtab *symtab, struct block *block,
>>+ char *method, struct symbol **syms, unsigned int *nsym,
>>+ unsigned int *ndebug);
>>+
>
>
> I presume this will go away when you can include objc-lang.h.
>
I couldn't include objc-lang.h because linespec.c defines a function
'find_methods' which objc-lang also defines. But actually I just
realized I could just take it out of objc-lang.h, since it's not used
anywhere else other than objc-lang.c
>
>> /* Prototypes for local functions */
>>
>> static void initialize_defaults (struct symtab **default_symtab,
>>@@ -48,6 +53,12 @@ static struct symtabs_and_lines decode_i
>>
>> static char *locate_first_half (char **argptr, int *is_quote_enclosed);
>>
>>+static struct symtabs_and_lines decode_objc (char **argptr,
>>+ int funfirstline,
>>+ struct symtab *file_symtab,
>>+ char ***canonical,
>>+ char *saved_arg);
>>+
>
>
> I like this -- presumably it keeps a lot of the new code
> out of poor old decrepit decode_line_1.
>
>
>> static struct symtabs_and_lines decode_compound (char **argptr,
>> int funfirstline,
>> char ***canonical,
>>@@ -568,6 +579,7 @@ decode_line_1 (char **argptr, int funfir
>> int is_quoted;
>> /* Is part of *ARGPTR is enclosed in double quotes? */
>> int is_quote_enclosed;
>>+ int is_objc_method = 0;
>> char *saved_arg = *argptr;
>>
>> init_sal (&val); /* initialize to zeroes */
>>@@ -596,6 +608,24 @@ decode_line_1 (char **argptr, int funfir
>>
>> p = locate_first_half (argptr, &is_quote_enclosed);
>>
>>+ /* Check if this is an Objective-C method. */
>>+ if (*p && (p[0] == ':') && (strchr ("+-", p[1]) != NULL)
>>+ && (p[2] == '['))
>>+ {
>>+ is_objc_method = 1;
>>+ paren_pointer = NULL; /* Probably just a category name. Ignore it */
>>+ }
>>+
>>+ /* Is it an Objective-C selector? */
>>+
>>+ {
>>+ struct symtabs_and_lines values;
>>+ values = decode_objc (argptr, funfirstline, NULL,
>>+ canonical, saved_arg);
>>+ if (values.sals != NULL)
>>+ return values;
>>+ }
>
>
> Was this meant to be an if? It seems to be a naked block.
> I'd feel better if there was an if around it, eg. is there
> a simple way to test for a selector name? Do I remember
> that they begin with a unique prefix such as '@'?
>
>
No. Because the user can do things like 'break init' or 'break
isAnImage', and this will determine that these are really Objective-C
methods and not regular C functions. It's really just a way to keep the
variable local to where it is really used.
>>+
>> /* Does it look like there actually were two parts? */
>>
>> if ((p[0] == ':' || p[0] == '.') && paren_pointer == NULL)
>>@@ -669,13 +699,21 @@ decode_line_1 (char **argptr, int funfir
>> Find the next token (everything up to end or next whitespace). */
>>
>> if (**argptr == '$') /* May be a convenience variable */
>>- p = skip_quoted (*argptr + (((*argptr)[1] == '$') ? 2 : 1)); /* One or two $ chars possible */
>>+ {
>>+ /* One or two $ chars possible */
>>+ p = skip_quoted (*argptr + (((*argptr)[1] == '$') ? 2 : 1));
>>+ }
>> else if (is_quoted)
>> {
>> p = skip_quoted (*argptr);
>> if (p[-1] != '\'')
>> error ("Unmatched single quote.");
>> }
>>+ else if (is_objc_method)
>>+ {
>>+ /* allow word separators in method names for Obj-C */
>>+ p = skip_quoted_chars (*argptr, NULL, "");
>>+ }
>
>
> OK, except didn't we decide that "skip_quoted_chars" needs a
> better name? One that identifies it with objc?
>
We made it more generic. It's now just like skip_quoted, except that you
can pass the character sets that are to be used (in fact, skip_quoted is
now defined in terms of skip_quoted_chars).
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [RFA] Add ObjC recognition to linespec.c [5/5]
2003-01-03 23:31 [RFA] Add ObjC recognition to linespec.c [5/5] Adam Fedor
2003-01-04 1:32 ` Michael Snyder
@ 2003-01-06 20:23 ` Elena Zannoni
2003-01-11 4:49 ` Adam Fedor
1 sibling, 1 reply; 9+ messages in thread
From: Elena Zannoni @ 2003-01-06 20:23 UTC (permalink / raw)
To: Adam Fedor; +Cc: GDB Patches
Adam Fedor writes:
> I know that linespec has been changing a lot lately, and I'm not sure if
> it's finished changing yet. So this is my attempt to insert ObjC
> handling into linespec. Actually Klee Dienes really did most of these
> changes, and I probably bastardized those as well...
>
See below for some questions...
> 2003-01-03 Adam Fedor <fedor@gnu.org>
>
> * linespec.c (decode_objc): New function to decode ObjC calls
> (decode_line_1): Check for ObjC calls (using decode_objc)
>
> Index: linespec.c
> ===================================================================
> RCS file: /cvs/src/src/gdb/linespec.c,v
> retrieving revision 1.32
> diff -u -p -r1.32 linespec.c
> --- linespec.c 19 Dec 2002 18:56:14 -0000 1.32
> +++ linespec.c 3 Jan 2003 22:56:54 -0000
> @@ -37,6 +37,11 @@
>
> extern char *operator_chars (char *, char **);
>
> +/* From objc-lang.h. Included here to avoid conflict with other prototypes */
> +extern char *find_imps (struct symtab *symtab, struct block *block,
> + char *method, struct symbol **syms, unsigned int *nsym,
> + unsigned int *ndebug);
> +
No externs in 'c' files... But you seem to have found a workaround.
> /* Prototypes for local functions */
>
> static void initialize_defaults (struct symtab **default_symtab,
> @@ -48,6 +53,12 @@ static struct symtabs_and_lines decode_i
>
> static char *locate_first_half (char **argptr, int *is_quote_enclosed);
>
> +static struct symtabs_and_lines decode_objc (char **argptr,
> + int funfirstline,
> + struct symtab *file_symtab,
> + char ***canonical,
> + char *saved_arg);
> +
> static struct symtabs_and_lines decode_compound (char **argptr,
> int funfirstline,
> char ***canonical,
> @@ -568,6 +579,7 @@ decode_line_1 (char **argptr, int funfir
> int is_quoted;
> /* Is part of *ARGPTR is enclosed in double quotes? */
> int is_quote_enclosed;
> + int is_objc_method = 0;
> char *saved_arg = *argptr;
>
> init_sal (&val); /* initialize to zeroes */
> @@ -596,6 +608,24 @@ decode_line_1 (char **argptr, int funfir
>
> p = locate_first_half (argptr, &is_quote_enclosed);
>
> + /* Check if this is an Objective-C method. */
Could you add in the comment an example of such a thing?
> + if (*p && (p[0] == ':') && (strchr ("+-", p[1]) != NULL)
> + && (p[2] == '['))
> + {
> + is_objc_method = 1;
> + paren_pointer = NULL; /* Probably just a category name. Ignore it */
> + }
> +
If you find a parenthesis what exactly does that mean? I.e. why are
you making it null again, ignoring what set_flags has found?
> + /* Is it an Objective-C selector? */
> +
What form does a selector have? Could you add that in the comment?
> + {
> + struct symtabs_and_lines values;
> + values = decode_objc (argptr, funfirstline, NULL,
> + canonical, saved_arg);
> + if (values.sals != NULL)
> + return values;
> + }
> +
> /* Does it look like there actually were two parts? */
>
> if ((p[0] == ':' || p[0] == '.') && paren_pointer == NULL)
this check above will trigger for the objc methods, right? If so, do
decode_compound and symtab_from_filename do the right things for objc
methods?
> @@ -669,13 +699,21 @@ decode_line_1 (char **argptr, int funfir
> Find the next token (everything up to end or next whitespace). */
>
> if (**argptr == '$') /* May be a convenience variable */
> - p = skip_quoted (*argptr + (((*argptr)[1] == '$') ? 2 : 1)); /* One or two $ chars possible */
> + {
> + /* One or two $ chars possible */
> + p = skip_quoted (*argptr + (((*argptr)[1] == '$') ? 2 : 1));
> + }
> else if (is_quoted)
> {
> p = skip_quoted (*argptr);
> if (p[-1] != '\'')
> error ("Unmatched single quote.");
> }
> + else if (is_objc_method)
I wonder if the check above that sets is_objc_method needs to be done
that early, and couldn't be instead moved to here (thinking out
loud).
> + {
> + /* allow word separators in method names for Obj-C */
> + p = skip_quoted_chars (*argptr, NULL, "");
> + }
> else if (paren_pointer != NULL)
> {
> p = paren_pointer + 1;
> @@ -952,6 +990,13 @@ locate_first_half (char **argptr, int *i
> error ("malformed template specification in command");
> p = temp_end;
> }
> + /* Check for a colon and a plus or minus and a [ (which
> + indicates an Objective-C method) */
> + if (*p && (p[0] == ':') && (strchr ("+-", p[1]) != NULL)
> + && (p[2] == '['))
> + {
> + break;
> + }
> /* Check for the end of the first half of the linespec. End of line,
> a tab, a double colon or the last single colon, or a space. But
> if enclosed in double quotes we do not break on enclosed spaces */
> @@ -993,6 +1038,98 @@ locate_first_half (char **argptr, int *i
> }
>
> \f
> +
> +struct symtabs_and_lines
> +decode_objc (char **argptr, int funfirstline, struct symtab *file_symtab,
> + char ***canonical, char *saved_arg)
> +{
> + /* here's where we recognise an Objective-C Selector. An
> + * Objective C selector may be implemented by more than one
> + * class, therefore it may represent more than one
> + * method/function. This gives us a situation somewhat
> + * analogous to C++ overloading. If there's more than one
> + * method that could represent the selector, then use some of
> + * the existing C++ code to let the user choose one.
> + */
> +
Comments should go before the function. Also, sentences should be
capitalized, end with a '.' and 2 spaces after the period. (yes, it's a
pain). (No asterisks either).
> + struct symtabs_and_lines values;
> + struct symbol **sym_arr = NULL;
> + struct symbol *sym = NULL;
> + char *copy = NULL;
> + struct block *block = NULL;
> + int i1 = 0;
> + int i2 = 0;
> +
> + values.sals = NULL;
> + values.nelts = 0;
> +
> + if (file_symtab != NULL)
> + block = BLOCKVECTOR_BLOCK (BLOCKVECTOR (file_symtab), STATIC_BLOCK);
> + else
> + block = get_selected_block (0);
> +
> + copy = find_imps (file_symtab, block, *argptr, NULL, &i1, &i2);
> +
> + if (i1 > 0)
> + {
> + sym_arr = (struct symbol **) alloca ((i1 + 1) * sizeof (struct symbol *));
> + sym_arr[i1] = 0;
> +
> + copy = find_imps (file_symtab, block, *argptr, sym_arr, &i1, &i2);
> + *argptr = copy;
> + }
> +
> + /* i1 now represents the TOTAL number of matches found...
> + i2 represents how many HIGH-LEVEL (struct symbol) matches,
> + which will come first in the sym_arr array. Any low-level
> + (minimal_symbol) matches will follow those. */
> +
> + if (i1 == 1)
> + {
> + if (i2 > 0)
> + {
> + /* already a struct symbol */
> + sym = sym_arr[0];
> + }
> + else
> + {
> + sym = find_pc_function (SYMBOL_VALUE_ADDRESS (sym_arr[0]));
> + if ((sym != NULL) && strcmp (SYMBOL_NAME (sym_arr[0]), SYMBOL_NAME (sym)) != 0)
> + {
> + warning ("debugging symbol \"%s\" does not match selector; ignoring", SYMBOL_NAME (sym));
> + sym = NULL;
> + }
> + }
> +
> + values.sals = (struct symtab_and_line *) xmalloc (sizeof (struct symtab_and_line));
> + values.nelts = 1;
> +
> + if (sym && SYMBOL_CLASS (sym) == LOC_BLOCK)
> + {
> + /* canonicalize this, so it remains resolved for dylib loads */
> + values.sals[0] = find_function_start_sal (sym, funfirstline);
> + build_canonical_line_spec (values.sals, SYMBOL_SOURCE_NAME (sym), canonical);
> + }
> + else
> + {
> + /* the only match was a non-debuggable symbol */
> + values.sals[0].symtab = 0;
> + values.sals[0].line = 0;
> + values.sals[0].end = 0;
> + values.sals[0].pc = SYMBOL_VALUE_ADDRESS (sym_arr[0]);
> + }
> + return values;
> + }
> +
> + if (i1 > 1)
> + {
> + /* more than one match -- user must choose one or more */
> + return decode_line_2 (sym_arr, i2, funfirstline, canonical);
> + //return select_symbols (sym_arr, i1, i2, funfirstline, canonical);
C++ comments are not ok.
> + }
> +
> + return values;
> +}
>
> /* This handles C++ and Java compound data structures. P should point
> at the first component separator, i.e. double-colon or period. */
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [RFA] Add ObjC recognition to linespec.c [5/5]
2003-01-04 2:53 ` Adam Fedor
@ 2003-01-06 20:32 ` Michael Snyder
0 siblings, 0 replies; 9+ messages in thread
From: Michael Snyder @ 2003-01-06 20:32 UTC (permalink / raw)
To: Adam Fedor; +Cc: GDB Patches
Adam Fedor wrote:
>
> Michael Snyder wrote:
> > Adam Fedor wrote:
> >
> >>I know that linespec has been changing a lot lately, and I'm not sure if
> >>it's finished changing yet. So this is my attempt to insert ObjC
> >>handling into linespec. Actually Klee Dienes really did most of these
> >>changes, and I probably bastardized those as well...
> >>
> >> -------------------------------------------------------------------------------
> >>2003-01-03 Adam Fedor <fedor@gnu.org>
> >>
> >> * linespec.c (decode_objc): New function to decode ObjC calls
> >> (decode_line_1): Check for ObjC calls (using decode_objc)
> >>
> >>Index: linespec.c
> >>===================================================================
> >>RCS file: /cvs/src/src/gdb/linespec.c,v
> >>retrieving revision 1.32
> >>diff -u -p -r1.32 linespec.c
> >>--- linespec.c 19 Dec 2002 18:56:14 -0000 1.32
> >>+++ linespec.c 3 Jan 2003 22:56:54 -0000
> >>@@ -37,6 +37,11 @@
> >>
> >> extern char *operator_chars (char *, char **);
> >>
> >>+/* From objc-lang.h. Included here to avoid conflict with other prototypes */
> >>+extern char *find_imps (struct symtab *symtab, struct block *block,
> >>+ char *method, struct symbol **syms, unsigned int *nsym,
> >>+ unsigned int *ndebug);
> >>+
> >
> >
> > I presume this will go away when you can include objc-lang.h.
> >
>
> I couldn't include objc-lang.h because linespec.c defines a function
> 'find_methods' which objc-lang also defines. But actually I just
> realized I could just take it out of objc-lang.h, since it's not used
> anywhere else other than objc-lang.c
Good, then I presume your version is static.
Either way, it wouldn't hurt to make its name "objc_find_methods'.
>
> >
> >> /* Prototypes for local functions */
> >>
> >> static void initialize_defaults (struct symtab **default_symtab,
> >>@@ -48,6 +53,12 @@ static struct symtabs_and_lines decode_i
> >>
> >> static char *locate_first_half (char **argptr, int *is_quote_enclosed);
> >>
> >>+static struct symtabs_and_lines decode_objc (char **argptr,
> >>+ int funfirstline,
> >>+ struct symtab *file_symtab,
> >>+ char ***canonical,
> >>+ char *saved_arg);
> >>+
> >
> >
> > I like this -- presumably it keeps a lot of the new code
> > out of poor old decrepit decode_line_1.
> >
> >
> >> static struct symtabs_and_lines decode_compound (char **argptr,
> >> int funfirstline,
> >> char ***canonical,
> >>@@ -568,6 +579,7 @@ decode_line_1 (char **argptr, int funfir
> >> int is_quoted;
> >> /* Is part of *ARGPTR is enclosed in double quotes? */
> >> int is_quote_enclosed;
> >>+ int is_objc_method = 0;
> >> char *saved_arg = *argptr;
> >>
> >> init_sal (&val); /* initialize to zeroes */
> >>@@ -596,6 +608,24 @@ decode_line_1 (char **argptr, int funfir
> >>
> >> p = locate_first_half (argptr, &is_quote_enclosed);
> >>
> >>+ /* Check if this is an Objective-C method. */
> >>+ if (*p && (p[0] == ':') && (strchr ("+-", p[1]) != NULL)
> >>+ && (p[2] == '['))
> >>+ {
> >>+ is_objc_method = 1;
> >>+ paren_pointer = NULL; /* Probably just a category name. Ignore it */
> >>+ }
> >>+
> >>+ /* Is it an Objective-C selector? */
> >>+
> >>+ {
> >>+ struct symtabs_and_lines values;
> >>+ values = decode_objc (argptr, funfirstline, NULL,
> >>+ canonical, saved_arg);
> >>+ if (values.sals != NULL)
> >>+ return values;
> >>+ }
> >
> >
> > Was this meant to be an if? It seems to be a naked block.
> > I'd feel better if there was an if around it, eg. is there
> > a simple way to test for a selector name? Do I remember
> > that they begin with a unique prefix such as '@'?
> >
> >
>
> No. Because the user can do things like 'break init' or 'break
> isAnImage', and this will determine that these are really Objective-C
> methods and not regular C functions. It's really just a way to keep the
> variable local to where it is really used.
OK, so if there is a C function init and an objc selector init,
how do we resolve the conflict? Which one wins? In other words,
will this un-protected code (not inside an if) ever obscure a
C function when it shouldn't?
>
> >>+
> >> /* Does it look like there actually were two parts? */
> >>
> >> if ((p[0] == ':' || p[0] == '.') && paren_pointer == NULL)
> >>@@ -669,13 +699,21 @@ decode_line_1 (char **argptr, int funfir
> >> Find the next token (everything up to end or next whitespace). */
> >>
> >> if (**argptr == '$') /* May be a convenience variable */
> >>- p = skip_quoted (*argptr + (((*argptr)[1] == '$') ? 2 : 1)); /* One or two $ chars possible */
> >>+ {
> >>+ /* One or two $ chars possible */
> >>+ p = skip_quoted (*argptr + (((*argptr)[1] == '$') ? 2 : 1));
> >>+ }
> >> else if (is_quoted)
> >> {
> >> p = skip_quoted (*argptr);
> >> if (p[-1] != '\'')
> >> error ("Unmatched single quote.");
> >> }
> >>+ else if (is_objc_method)
> >>+ {
> >>+ /* allow word separators in method names for Obj-C */
> >>+ p = skip_quoted_chars (*argptr, NULL, "");
> >>+ }
> >
> >
> > OK, except didn't we decide that "skip_quoted_chars" needs a
> > better name? One that identifies it with objc?
> >
>
> We made it more generic. It's now just like skip_quoted, except that you
> can pass the character sets that are to be used (in fact, skip_quoted is
> now defined in terms of skip_quoted_chars).
OK, I guess.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [RFA] Add ObjC recognition to linespec.c [5/5]
2003-01-06 20:23 ` Elena Zannoni
@ 2003-01-11 4:49 ` Adam Fedor
2003-02-19 15:16 ` Elena Zannoni
0 siblings, 1 reply; 9+ messages in thread
From: Adam Fedor @ 2003-01-11 4:49 UTC (permalink / raw)
To: GDB Patches; +Cc: Elena Zannoni, Michael Snyder
[-- Attachment #1: Type: text/plain, Size: 46 bytes --]
Here's an updated patch with better comments.
[-- Attachment #2: objc23.patch --]
[-- Type: text/plain, Size: 7306 bytes --]
2003-01-03 Adam Fedor <fedor@gnu.org>
* Makefile (linespec.o): Add $(objc_lang_h)
* linespec.c (decode_objc): New function to decode ObjC calls
(decode_line_1): Check for ObjC calls (using decode_objc)
Index: Makefile.in
===================================================================
RCS file: /cvs/src/src/gdb/Makefile.in,v
retrieving revision 1.311
diff -u -p -r1.311 Makefile.in
--- Makefile.in 9 Jan 2003 18:03:35 -0000 1.311
@@ -1831,7 +1833,7 @@ lin-lwp.o: lin-lwp.c $(defs_h) $(gdb_ass
$(gdbthread_h) $(inferior_h) $(target_h) $(regcache_h) $(gdbcmd_h)
linespec.o: linespec.c $(defs_h) $(symtab_h) $(frame_h) $(command_h) \
$(symfile_h) $(objfiles_h) $(demangle_h) $(value_h) $(completer_h) \
- $(cp_abi_h) $(source_h) $(parser_defs_h)
+ $(cp_abi_h) $(source_h) $(parser_defs_h) $(objc_lang_h)
linux-proc.o: linux-proc.c $(defs_h) $(inferior_h) $(regcache_h) \
$(gregset_h) $(gdbcore_h) $(gdbthread_h) $(elf_bfd_h) \
$(cli_decode_h) $(gdb_string_h)
Index: linespec.c
===================================================================
RCS file: /cvs/src/src/gdb/linespec.c,v
retrieving revision 1.36
diff -u -p -r1.36 linespec.c
--- linespec.c 11 Jan 2003 01:01:04 -0000 1.36
+++ linespec.c 11 Jan 2003 04:36:07 -0000
@@ -32,6 +32,7 @@
#include "completer.h"
#include "cp-abi.h"
#include "parser-defs.h"
+#include "objc-lang.h"
/* We share this one with symtab.c, but it is not exported widely. */
@@ -48,6 +49,12 @@ static struct symtabs_and_lines decode_i
static char *locate_first_half (char **argptr, int *is_quote_enclosed);
+static struct symtabs_and_lines decode_objc (char **argptr,
+ int funfirstline,
+ struct symtab *file_symtab,
+ char ***canonical,
+ char *saved_arg);
+
static struct symtabs_and_lines decode_compound (char **argptr,
int funfirstline,
char ***canonical,
@@ -573,6 +580,7 @@ decode_line_1 (char **argptr, int funfir
int is_quoted;
/* Is part of *ARGPTR is enclosed in double quotes? */
int is_quote_enclosed;
+ int is_objc_method = 0;
char *saved_arg = *argptr;
/* Defaults have defaults. */
@@ -599,6 +607,25 @@ decode_line_1 (char **argptr, int funfir
p = locate_first_half (argptr, &is_quote_enclosed);
+ /* Check if this is an Objective-C method (anything that starts with
+ a '+' or '-' and a '['). */
+ if (*p && (p[0] == ':') && (strchr ("+-", p[1]) != NULL)
+ && (p[2] == '['))
+ {
+ is_objc_method = 1;
+ paren_pointer = NULL; /* Just a category name. Ignore it. */
+ }
+
+ /* Check if the symbol could be an Objective-C selector. */
+
+ {
+ struct symtabs_and_lines values;
+ values = decode_objc (argptr, funfirstline, NULL,
+ canonical, saved_arg);
+ if (values.sals != NULL)
+ return values;
+ }
+
/* Does it look like there actually were two parts? */
if ((p[0] == ':' || p[0] == '.') && paren_pointer == NULL)
@@ -672,13 +699,21 @@ decode_line_1 (char **argptr, int funfir
Find the next token (everything up to end or next whitespace). */
if (**argptr == '$') /* May be a convenience variable */
- p = skip_quoted (*argptr + (((*argptr)[1] == '$') ? 2 : 1)); /* One or two $ chars possible */
+ {
+ /* One or two $ chars possible */
+ p = skip_quoted (*argptr + (((*argptr)[1] == '$') ? 2 : 1));
+ }
else if (is_quoted)
{
p = skip_quoted (*argptr);
if (p[-1] != '\'')
error ("Unmatched single quote.");
}
+ else if (is_objc_method)
+ {
+ /* allow word separators in method names for Obj-C */
+ p = skip_quoted_chars (*argptr, NULL, "");
+ }
else if (paren_pointer != NULL)
{
p = paren_pointer + 1;
@@ -881,6 +916,13 @@ locate_first_half (char **argptr, int *i
error ("malformed template specification in command");
p = temp_end;
}
+ /* Check for a colon and a plus or minus and a [ (which
+ indicates an Objective-C method) */
+ if (*p && (p[0] == ':') && (strchr ("+-", p[1]) != NULL)
+ && (p[2] == '['))
+ {
+ break;
+ }
/* Check for the end of the first half of the linespec. End of line,
a tab, a double colon or the last single colon, or a space. But
if enclosed in double quotes we do not break on enclosed spaces */
@@ -922,6 +964,95 @@ locate_first_half (char **argptr, int *i
}
\f
+
+/* Here's where we recognise an Objective-C Selector. An Objective C
+ selector may be implemented by more than one class, therefore it
+ may represent more than one method/function. This gives us a
+ situation somewhat analogous to C++ overloading. If there's more
+ than one method that could represent the selector, then use some of
+ the existing C++ code to let the user choose one. */
+
+struct symtabs_and_lines
+decode_objc (char **argptr, int funfirstline, struct symtab *file_symtab,
+ char ***canonical, char *saved_arg)
+{
+ struct symtabs_and_lines values;
+ struct symbol **sym_arr = NULL;
+ struct symbol *sym = NULL;
+ char *copy = NULL;
+ struct block *block = NULL;
+ int i1 = 0;
+ int i2 = 0;
+
+ values.sals = NULL;
+ values.nelts = 0;
+
+ if (file_symtab != NULL)
+ block = BLOCKVECTOR_BLOCK (BLOCKVECTOR (file_symtab), STATIC_BLOCK);
+ else
+ block = get_selected_block (0);
+
+ copy = find_imps (file_symtab, block, *argptr, NULL, &i1, &i2);
+
+ if (i1 > 0)
+ {
+ sym_arr = (struct symbol **) alloca ((i1 + 1) * sizeof (struct symbol *));
+ sym_arr[i1] = 0;
+
+ copy = find_imps (file_symtab, block, *argptr, sym_arr, &i1, &i2);
+ *argptr = copy;
+ }
+
+ /* i1 now represents the TOTAL number of matches found.
+ i2 represents how many HIGH-LEVEL (struct symbol) matches,
+ which will come first in the sym_arr array. Any low-level
+ (minimal_symbol) matches will follow those. */
+
+ if (i1 == 1)
+ {
+ if (i2 > 0)
+ {
+ /* Already a struct symbol. */
+ sym = sym_arr[0];
+ }
+ else
+ {
+ sym = find_pc_function (SYMBOL_VALUE_ADDRESS (sym_arr[0]));
+ if ((sym != NULL) && strcmp (SYMBOL_NAME (sym_arr[0]), SYMBOL_NAME (sym)) != 0)
+ {
+ warning ("debugging symbol \"%s\" does not match selector; ignoring", SYMBOL_NAME (sym));
+ sym = NULL;
+ }
+ }
+
+ values.sals = (struct symtab_and_line *) xmalloc (sizeof (struct symtab_and_line));
+ values.nelts = 1;
+
+ if (sym && SYMBOL_CLASS (sym) == LOC_BLOCK)
+ {
+ /* Canonicalize this, so it remains resolved for dylib loads. */
+ values.sals[0] = find_function_start_sal (sym, funfirstline);
+ build_canonical_line_spec (values.sals, SYMBOL_SOURCE_NAME (sym), canonical);
+ }
+ else
+ {
+ /* The only match was a non-debuggable symbol. */
+ values.sals[0].symtab = 0;
+ values.sals[0].line = 0;
+ values.sals[0].end = 0;
+ values.sals[0].pc = SYMBOL_VALUE_ADDRESS (sym_arr[0]);
+ }
+ return values;
+ }
+
+ if (i1 > 1)
+ {
+ /* More than one match. The user must choose one or more. */
+ return decode_line_2 (sym_arr, i2, funfirstline, canonical);
+ }
+
+ return values;
+}
/* This handles C++ and Java compound data structures. P should point
at the first component separator, i.e. double-colon or period. */
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [RFA] Add ObjC recognition to linespec.c [5/5]
2003-01-11 4:49 ` Adam Fedor
@ 2003-02-19 15:16 ` Elena Zannoni
0 siblings, 0 replies; 9+ messages in thread
From: Elena Zannoni @ 2003-02-19 15:16 UTC (permalink / raw)
To: Adam Fedor; +Cc: GDB Patches, Elena Zannoni, Michael Snyder
Adam Fedor writes:
> Here's an updated patch with better comments.
> 2003-01-03 Adam Fedor <fedor@gnu.org>
>
> * Makefile (linespec.o): Add $(objc_lang_h)
> * linespec.c (decode_objc): New function to decode ObjC calls
> (decode_line_1): Check for ObjC calls (using decode_objc)
>
Yes.
thanks
elena
> Index: Makefile.in
> ===================================================================
> RCS file: /cvs/src/src/gdb/Makefile.in,v
> retrieving revision 1.311
> diff -u -p -r1.311 Makefile.in
> --- Makefile.in 9 Jan 2003 18:03:35 -0000 1.311
> @@ -1831,7 +1833,7 @@ lin-lwp.o: lin-lwp.c $(defs_h) $(gdb_ass
> $(gdbthread_h) $(inferior_h) $(target_h) $(regcache_h) $(gdbcmd_h)
> linespec.o: linespec.c $(defs_h) $(symtab_h) $(frame_h) $(command_h) \
> $(symfile_h) $(objfiles_h) $(demangle_h) $(value_h) $(completer_h) \
> - $(cp_abi_h) $(source_h) $(parser_defs_h)
> + $(cp_abi_h) $(source_h) $(parser_defs_h) $(objc_lang_h)
> linux-proc.o: linux-proc.c $(defs_h) $(inferior_h) $(regcache_h) \
> $(gregset_h) $(gdbcore_h) $(gdbthread_h) $(elf_bfd_h) \
> $(cli_decode_h) $(gdb_string_h)
> Index: linespec.c
> ===================================================================
> RCS file: /cvs/src/src/gdb/linespec.c,v
> retrieving revision 1.36
> diff -u -p -r1.36 linespec.c
> --- linespec.c 11 Jan 2003 01:01:04 -0000 1.36
> +++ linespec.c 11 Jan 2003 04:36:07 -0000
> @@ -32,6 +32,7 @@
> #include "completer.h"
> #include "cp-abi.h"
> #include "parser-defs.h"
> +#include "objc-lang.h"
>
> /* We share this one with symtab.c, but it is not exported widely. */
>
> @@ -48,6 +49,12 @@ static struct symtabs_and_lines decode_i
>
> static char *locate_first_half (char **argptr, int *is_quote_enclosed);
>
> +static struct symtabs_and_lines decode_objc (char **argptr,
> + int funfirstline,
> + struct symtab *file_symtab,
> + char ***canonical,
> + char *saved_arg);
> +
> static struct symtabs_and_lines decode_compound (char **argptr,
> int funfirstline,
> char ***canonical,
> @@ -573,6 +580,7 @@ decode_line_1 (char **argptr, int funfir
> int is_quoted;
> /* Is part of *ARGPTR is enclosed in double quotes? */
> int is_quote_enclosed;
> + int is_objc_method = 0;
> char *saved_arg = *argptr;
>
> /* Defaults have defaults. */
> @@ -599,6 +607,25 @@ decode_line_1 (char **argptr, int funfir
>
> p = locate_first_half (argptr, &is_quote_enclosed);
>
> + /* Check if this is an Objective-C method (anything that starts with
> + a '+' or '-' and a '['). */
> + if (*p && (p[0] == ':') && (strchr ("+-", p[1]) != NULL)
> + && (p[2] == '['))
> + {
> + is_objc_method = 1;
> + paren_pointer = NULL; /* Just a category name. Ignore it. */
> + }
> +
> + /* Check if the symbol could be an Objective-C selector. */
> +
> + {
> + struct symtabs_and_lines values;
> + values = decode_objc (argptr, funfirstline, NULL,
> + canonical, saved_arg);
> + if (values.sals != NULL)
> + return values;
> + }
> +
> /* Does it look like there actually were two parts? */
>
> if ((p[0] == ':' || p[0] == '.') && paren_pointer == NULL)
> @@ -672,13 +699,21 @@ decode_line_1 (char **argptr, int funfir
> Find the next token (everything up to end or next whitespace). */
>
> if (**argptr == '$') /* May be a convenience variable */
> - p = skip_quoted (*argptr + (((*argptr)[1] == '$') ? 2 : 1)); /* One or two $ chars possible */
> + {
> + /* One or two $ chars possible */
> + p = skip_quoted (*argptr + (((*argptr)[1] == '$') ? 2 : 1));
> + }
> else if (is_quoted)
> {
> p = skip_quoted (*argptr);
> if (p[-1] != '\'')
> error ("Unmatched single quote.");
> }
> + else if (is_objc_method)
> + {
> + /* allow word separators in method names for Obj-C */
> + p = skip_quoted_chars (*argptr, NULL, "");
> + }
> else if (paren_pointer != NULL)
> {
> p = paren_pointer + 1;
> @@ -881,6 +916,13 @@ locate_first_half (char **argptr, int *i
> error ("malformed template specification in command");
> p = temp_end;
> }
> + /* Check for a colon and a plus or minus and a [ (which
> + indicates an Objective-C method) */
> + if (*p && (p[0] == ':') && (strchr ("+-", p[1]) != NULL)
> + && (p[2] == '['))
> + {
> + break;
> + }
> /* Check for the end of the first half of the linespec. End of line,
> a tab, a double colon or the last single colon, or a space. But
> if enclosed in double quotes we do not break on enclosed spaces */
> @@ -922,6 +964,95 @@ locate_first_half (char **argptr, int *i
> }
>
> \f
> +
> +/* Here's where we recognise an Objective-C Selector. An Objective C
> + selector may be implemented by more than one class, therefore it
> + may represent more than one method/function. This gives us a
> + situation somewhat analogous to C++ overloading. If there's more
> + than one method that could represent the selector, then use some of
> + the existing C++ code to let the user choose one. */
> +
> +struct symtabs_and_lines
> +decode_objc (char **argptr, int funfirstline, struct symtab *file_symtab,
> + char ***canonical, char *saved_arg)
> +{
> + struct symtabs_and_lines values;
> + struct symbol **sym_arr = NULL;
> + struct symbol *sym = NULL;
> + char *copy = NULL;
> + struct block *block = NULL;
> + int i1 = 0;
> + int i2 = 0;
> +
> + values.sals = NULL;
> + values.nelts = 0;
> +
> + if (file_symtab != NULL)
> + block = BLOCKVECTOR_BLOCK (BLOCKVECTOR (file_symtab), STATIC_BLOCK);
> + else
> + block = get_selected_block (0);
> +
> + copy = find_imps (file_symtab, block, *argptr, NULL, &i1, &i2);
> +
> + if (i1 > 0)
> + {
> + sym_arr = (struct symbol **) alloca ((i1 + 1) * sizeof (struct symbol *));
> + sym_arr[i1] = 0;
> +
> + copy = find_imps (file_symtab, block, *argptr, sym_arr, &i1, &i2);
> + *argptr = copy;
> + }
> +
> + /* i1 now represents the TOTAL number of matches found.
> + i2 represents how many HIGH-LEVEL (struct symbol) matches,
> + which will come first in the sym_arr array. Any low-level
> + (minimal_symbol) matches will follow those. */
> +
> + if (i1 == 1)
> + {
> + if (i2 > 0)
> + {
> + /* Already a struct symbol. */
> + sym = sym_arr[0];
> + }
> + else
> + {
> + sym = find_pc_function (SYMBOL_VALUE_ADDRESS (sym_arr[0]));
> + if ((sym != NULL) && strcmp (SYMBOL_NAME (sym_arr[0]), SYMBOL_NAME (sym)) != 0)
> + {
> + warning ("debugging symbol \"%s\" does not match selector; ignoring", SYMBOL_NAME (sym));
> + sym = NULL;
> + }
> + }
> +
> + values.sals = (struct symtab_and_line *) xmalloc (sizeof (struct symtab_and_line));
> + values.nelts = 1;
> +
> + if (sym && SYMBOL_CLASS (sym) == LOC_BLOCK)
> + {
> + /* Canonicalize this, so it remains resolved for dylib loads. */
> + values.sals[0] = find_function_start_sal (sym, funfirstline);
> + build_canonical_line_spec (values.sals, SYMBOL_SOURCE_NAME (sym), canonical);
> + }
> + else
> + {
> + /* The only match was a non-debuggable symbol. */
> + values.sals[0].symtab = 0;
> + values.sals[0].line = 0;
> + values.sals[0].end = 0;
> + values.sals[0].pc = SYMBOL_VALUE_ADDRESS (sym_arr[0]);
> + }
> + return values;
> + }
> +
> + if (i1 > 1)
> + {
> + /* More than one match. The user must choose one or more. */
> + return decode_line_2 (sym_arr, i2, funfirstline, canonical);
> + }
> +
> + return values;
> +}
>
> /* This handles C++ and Java compound data structures. P should point
> at the first component separator, i.e. double-colon or period. */
^ permalink raw reply [flat|nested] 9+ messages in thread
* RE: [RFA] Add ObjC recognition to linespec.c [5/5]
@ 2003-01-07 13:59 Adam Fedor
0 siblings, 0 replies; 9+ messages in thread
From: Adam Fedor @ 2003-01-07 13:59 UTC (permalink / raw)
To: Michael Snyder; +Cc: GDB Patches
> -----Original Message-----
> From: Michael Snyder [mailto:msnyder@redhat.com]
> Sent: Monday, January 06, 2003 3:32 PM
> To: Adam Fedor
> Cc: GDB Patches
> Subject: Re: [RFA] Add ObjC recognition to linespec.c [5/5]
>
> > >>+
> > >>+ /* Is it an Objective-C selector? */
> > >>+
> > >>+ {
> > >>+ struct symtabs_and_lines values;
> > >>+ values = decode_objc (argptr, funfirstline, NULL,
> > >>+ canonical, saved_arg);
> > >>+ if (values.sals != NULL)
> > >>+ return values;
> > >>+ }
> > >
> > >
> > > Was this meant to be an if? It seems to be a naked block.
> > > I'd feel better if there was an if around it, eg. is there
> > > a simple way to test for a selector name? Do I remember
> > > that they begin with a unique prefix such as '@'?
> > >
> > >
> >
> > No. Because the user can do things like 'break init' or 'break
> > isAnImage', and this will determine that these are really
> Objective-C
> > methods and not regular C functions. It's really just a way
> to keep the
> > variable local to where it is really used.
>
> OK, so if there is a C function init and an objc selector init,
> how do we resolve the conflict? Which one wins? In other words,
> will this un-protected code (not inside an if) ever obscure a
> C function when it shouldn't?
>
You get presented with a choice:
(gdb) break init
[0] cancel
[1] all
[2] -[MyObject init] at testit.m:27
[3] -[NewObject init] at testit.m:13
[4] init at testit.m:33
>
So you can choose which init you want.
^ permalink raw reply [flat|nested] 9+ messages in thread
* RE: [RFA] Add ObjC recognition to linespec.c [5/5]
@ 2003-01-07 13:56 Adam Fedor
0 siblings, 0 replies; 9+ messages in thread
From: Adam Fedor @ 2003-01-07 13:56 UTC (permalink / raw)
To: Elena Zannoni; +Cc: GDB Patches
> -----Original Message-----
> From: Elena Zannoni [mailto:ezannoni@redhat.com]
> Sent: Monday, January 06, 2003 3:27 PM
> To: Adam Fedor
> Cc: GDB Patches
> Subject: Re: [RFA] Add ObjC recognition to linespec.c [5/5]
>
>
[...skipped...]
>
> > + if (*p && (p[0] == ':') && (strchr ("+-", p[1]) != NULL)
> > + && (p[2] == '['))
> > + {
> > + is_objc_method = 1;
> > + paren_pointer = NULL; /* Probably just a category
> name. Ignore it */
> > + }
> > +
>
> If you find a parenthesis what exactly does that mean? I.e. why are
> you making it null again, ignoring what set_flags has found?
>
The paren_pointer is (I think) used for C++ overload checking, in Objective-C that isn't necessary, but you may have something like
break -[MyObject(PrivateCategory) someMethod:]
where the paren_pointer code gets hung up on the 'PrivateCategory' specification when it should just ignore this and skip past the whole method specification (The whole thing gets handled in decode_objc.)
> > + /* Is it an Objective-C selector? */
> > +
>
> What form does a selector have? Could you add that in the comment?
>
I could, but a selector can have almost any form, from completly unqualified ('break isFlipped') to fullly qualified ('break -[MyObject isFlipped]').
> > + {
> > + struct symtabs_and_lines values;
> > + values = decode_objc (argptr, funfirstline, NULL,
> > + canonical, saved_arg);
> > + if (values.sals != NULL)
> > + return values;
> > + }
> > +
> > /* Does it look like there actually were two parts? */
> >
> > if ((p[0] == ':' || p[0] == '.') && paren_pointer == NULL)
>
> this check above will trigger for the objc methods, right? If so, do
> decode_compound and symtab_from_filename do the right things for objc
> methods?
>
If it's an objc method it gets handled in decode_objc, otherwise it is handled correctly in decode_compound, etc.
> > @@ -669,13 +699,21 @@ decode_line_1 (char **argptr, int funfir
> > Find the next token (everything up to end or next
> whitespace). */
> >
> > if (**argptr == '$') /* May be a convenience
> variable */
> > - p = skip_quoted (*argptr + (((*argptr)[1] == '$') ? 2
> : 1)); /* One or two $ chars possible */
> > + {
> > + /* One or two $ chars possible */
> > + p = skip_quoted (*argptr + (((*argptr)[1] == '$') ? 2 : 1));
> > + }
> > else if (is_quoted)
> > {
> > p = skip_quoted (*argptr);
> > if (p[-1] != '\'')
> > error ("Unmatched single quote.");
> > }
> > + else if (is_objc_method)
>
> I wonder if the check above that sets is_objc_method needs to be done
> that early, and couldn't be instead moved to here (thinking out
> loud).
>
Yes you could, except it's also needed for the paren_pointer check.
> > + {
> > + /* allow word separators in method names for Obj-C */
> > + p = skip_quoted_chars (*argptr, NULL, "");
> > + }
> > else if (paren_pointer != NULL)
> > {
> > p = paren_pointer + 1;
> > @@ -952,6 +990,13 @@ locate_first_half (char **argptr, int *i
> > error ("malformed template specification in command");
> > p = temp_end;
> > }
> > + /* Check for a colon and a plus or minus and a [ (which
> > + indicates an Objective-C method) */
> > + if (*p && (p[0] == ':') && (strchr ("+-", p[1]) != NULL)
> > + && (p[2] == '['))
> > + {
> > + break;
> > + }
> > /* Check for the end of the first half of the
> linespec. End of line,
> > a tab, a double colon or the last single colon,
> or a space. But
> > if enclosed in double quotes we do not break on
> enclosed spaces */
> > @@ -993,6 +1038,98 @@ locate_first_half (char **argptr, int *i
> > }
> >
> > \f>
> > +
> > +struct symtabs_and_lines
> > +decode_objc (char **argptr, int funfirstline, struct
> symtab *file_symtab,
> > + char ***canonical, char *saved_arg)
> > +{
> > + /* here's where we recognise an Objective-C Selector. An
> > + * Objective C selector may be implemented by more than one
> > + * class, therefore it may represent more than one
> > + * method/function. This gives us a situation somewhat
> > + * analogous to C++ overloading. If there's more than one
> > + * method that could represent the selector, then use some of
> > + * the existing C++ code to let the user choose one.
> > + */
> > +
>
> Comments should go before the function. Also, sentences should be
> capitalized, end with a '.' and 2 spaces after the period.
> (yes, it's a
> pain). (No asterisks either).
>
[...]
OK. I'll update the patch (splitting the two functions into separate patches also).
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2003-02-19 15:16 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-01-03 23:31 [RFA] Add ObjC recognition to linespec.c [5/5] Adam Fedor
2003-01-04 1:32 ` Michael Snyder
2003-01-04 2:53 ` Adam Fedor
2003-01-06 20:32 ` Michael Snyder
2003-01-06 20:23 ` Elena Zannoni
2003-01-11 4:49 ` Adam Fedor
2003-02-19 15:16 ` Elena Zannoni
2003-01-07 13:56 Adam Fedor
2003-01-07 13:59 Adam Fedor
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox