1 /* Objective-C language support routines for GDB, the GNU debugger.
2 Copyright 1996 NeXT Software, Inc.
4 This file is part of GDB.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
23 #include "expression.h"
24 #include "parser-defs.h"
27 #include "objc-lang.h"
28 #include "complaints.h"
32 #include "string.h" /* for strchr */
33 #include "target.h" /* for target_has_execution */
37 #include "gdb_regex.h"
48 CORE_ADDR super_class
;
70 /* Complaints about ObjC classes, selectors, etc. */
72 static struct complaint noclass_lookup_complaint
= {
73 "no way to lookup Objective-C classes", 0, 0
76 static struct complaint nosel_lookup_complaint
= {
77 "no way to lookup Objective-C selectors", 0, 0
81 #if (!defined __GNUC__ || __GNUC__ < 2 || __GNUC_MINOR__ < (defined __cplusplus ? 6 : 4))
82 #define __CHECK_FUNCTION ((__const char *) 0)
84 #define __CHECK_FUNCTION __PRETTY_FUNCTION__
87 #define CHECK(expression) \
88 ((void) ((expression) ? 0 : gdb_check (#expression, __FILE__, __LINE__, \
91 #define CHECK_FATAL(expression) \
92 ((void) ((expression) ? 0 : gdb_check_fatal (#expression, __FILE__, \
93 __LINE__, __CHECK_FUNCTION)))
96 gdb_check (const char *str
, const char *file
,
97 unsigned int line
, const char *func
)
99 error ("assertion failure on line %u of \"%s\" in function \"%s\": %s\n",
100 line
, file
, func
, str
);
104 gdb_check_fatal (const char *str
, const char *file
,
105 unsigned int line
, const char *func
)
107 internal_error (file
, line
,
108 "assertion failure in function \"%s\": %s\n", func
, str
);
111 /* Lookup a structure type named "struct NAME", visible in lexical
112 block BLOCK. If NOERR is nonzero, return zero if NAME is not
116 lookup_struct_typedef (char *name
, struct block
*block
, int noerr
)
118 register struct symbol
*sym
;
120 sym
= lookup_symbol (name
, block
, STRUCT_NAMESPACE
, 0,
121 (struct symtab
**) NULL
);
128 error ("No struct type named %s.", name
);
130 if (TYPE_CODE (SYMBOL_TYPE (sym
)) != TYPE_CODE_STRUCT
)
135 error ("This context has class, union or enum %s, not a struct.",
142 lookup_objc_class (char *classname
)
144 struct value
* function
, *classval
;
146 if (! target_has_execution
)
148 /* Can't call into inferior to lookup class. */
152 if (lookup_minimal_symbol("objc_lookUpClass", 0, 0))
153 function
= find_function_in_inferior("objc_lookUpClass");
154 else if (lookup_minimal_symbol ("objc_lookup_class", 0, 0))
155 function
= find_function_in_inferior("objc_lookup_class");
158 complain (&noclass_lookup_complaint
, 0);
162 classval
= value_string (classname
, strlen (classname
) + 1);
163 classval
= value_coerce_array (classval
);
164 return (CORE_ADDR
) value_as_long (call_function_by_hand (function
,
169 lookup_child_selector (char *selname
)
171 struct value
* function
, *selstring
;
173 if (! target_has_execution
)
175 /* Can't call into inferior to lookup selector. */
179 if (lookup_minimal_symbol("sel_getUid", 0, 0))
180 function
= find_function_in_inferior("sel_getUid");
181 else if (lookup_minimal_symbol ("sel_get_any_uid", 0, 0))
182 function
= find_function_in_inferior("sel_get_any_uid");
185 complain (&nosel_lookup_complaint
, 0);
189 selstring
= value_coerce_array (value_string (selname
,
190 strlen (selname
) + 1));
191 return value_as_long (call_function_by_hand (function
, 1, &selstring
));
195 value_nsstring (char *ptr
, int len
)
197 struct value
*stringValue
[3];
198 struct value
*function
, *nsstringValue
;
202 if (!target_has_execution
)
203 return 0; /* Can't call into inferior to create NSString. */
205 if (!(sym
= lookup_struct_typedef("NSString", 0, 1)) &&
206 !(sym
= lookup_struct_typedef("NXString", 0, 1)))
207 type
= lookup_pointer_type(builtin_type_void
);
209 type
= lookup_pointer_type(SYMBOL_TYPE (sym
));
211 stringValue
[2] = value_string(ptr
, len
);
212 stringValue
[2] = value_coerce_array(stringValue
[2]);
213 /* _NSNewStringFromCString replaces "istr" after Lantern2A. */
214 if (lookup_minimal_symbol("_NSNewStringFromCString", 0, 0))
216 function
= find_function_in_inferior("_NSNewStringFromCString");
217 nsstringValue
= call_function_by_hand(function
, 1, &stringValue
[2]);
219 else if (lookup_minimal_symbol("istr", 0, 0))
221 function
= find_function_in_inferior("istr");
222 nsstringValue
= call_function_by_hand(function
, 1, &stringValue
[2]);
224 else if (lookup_minimal_symbol("+[NSString stringWithCString:]", 0, 0))
226 function
= find_function_in_inferior("+[NSString stringWithCString:]");
227 stringValue
[0] = value_from_longest
228 (builtin_type_long
, lookup_objc_class ("NSString"));
229 stringValue
[1] = value_from_longest
230 (builtin_type_long
, lookup_child_selector ("stringWithCString:"));
231 nsstringValue
= call_function_by_hand(function
, 3, &stringValue
[0]);
234 error ("NSString: internal error -- no way to create new NSString");
236 VALUE_TYPE(nsstringValue
) = type
;
237 return nsstringValue
;
240 /* Objective-C name demangling. */
243 objc_demangle (const char *mangled
)
245 char *demangled
, *cp
;
247 if (mangled
[0] == '_' &&
248 (mangled
[1] == 'i' || mangled
[1] == 'c') &&
251 cp
= demangled
= xmalloc(strlen(mangled
) + 2);
253 if (mangled
[1] == 'i')
254 *cp
++ = '-'; /* for instance method */
256 *cp
++ = '+'; /* for class method */
258 *cp
++ = '['; /* opening left brace */
259 strcpy(cp
, mangled
+3); /* tack on the rest of the mangled name */
261 while (*cp
&& *cp
== '_')
262 cp
++; /* skip any initial underbars in class name */
264 if (!(cp
= strchr(cp
, '_'))) /* find first non-initial underbar */
266 free(demangled
); /* not mangled name */
269 if (cp
[1] == '_') { /* easy case: no category name */
270 *cp
++ = ' '; /* replace two '_' with one ' ' */
271 strcpy(cp
, mangled
+ (cp
- demangled
) + 2);
274 *cp
++ = '('; /* less easy case: category name */
275 if (!(cp
= strchr(cp
, '_')))
277 free(demangled
); /* not mangled name */
281 *cp
++ = ' '; /* overwriting 1st char of method name... */
282 strcpy(cp
, mangled
+ (cp
- demangled
)); /* get it back */
285 while (*cp
&& *cp
== '_')
286 cp
++; /* skip any initial underbars in method name */
290 *cp
= ':'; /* replace remaining '_' with ':' */
292 *cp
++ = ']'; /* closing right brace */
293 *cp
++ = 0; /* string terminator */
297 return NULL
; /* Not an objc mangled name. */
300 /* Print the character C on STREAM as part of the contents of a
301 literal string whose delimiter is QUOTER. Note that that format
302 for printing characters and strings is language specific. */
305 objc_emit_char (register int c
, struct ui_file
*stream
, int quoter
)
308 c
&= 0xFF; /* Avoid sign bit follies. */
310 if (PRINT_LITERAL_FORM (c
))
312 if (c
== '\\' || c
== quoter
)
314 fputs_filtered ("\\", stream
);
316 fprintf_filtered (stream
, "%c", c
);
323 fputs_filtered ("\\n", stream
);
326 fputs_filtered ("\\b", stream
);
329 fputs_filtered ("\\t", stream
);
332 fputs_filtered ("\\f", stream
);
335 fputs_filtered ("\\r", stream
);
338 fputs_filtered ("\\e", stream
);
341 fputs_filtered ("\\a", stream
);
344 fprintf_filtered (stream
, "\\%.3o", (unsigned int) c
);
351 objc_printchar (int c
, struct ui_file
*stream
)
353 fputs_filtered ("'", stream
);
354 objc_emit_char (c
, stream
, '\'');
355 fputs_filtered ("'", stream
);
358 /* Print the character string STRING, printing at most LENGTH
359 characters. Printing stops early if the number hits print_max;
360 repeat counts are printed as appropriate. Print ellipses at the
361 end if we had to stop before printing LENGTH characters, or if
365 objc_printstr (struct ui_file
*stream
, char *string
,
366 unsigned int length
, int force_ellipses
)
368 register unsigned int i
;
369 unsigned int things_printed
= 0;
372 extern int inspect_it
;
373 extern int repeat_count_threshold
;
374 extern int print_max
;
376 /* If the string was not truncated due to `set print elements', and
377 the last byte of it is a null, we don't print that, in
378 traditional C style. */
379 if ((!force_ellipses
) && length
> 0 && string
[length
-1] == '\0')
384 fputs_filtered ("\"\"", stream
);
388 for (i
= 0; i
< length
&& things_printed
< print_max
; ++i
)
390 /* Position of the character we are examining to see whether it
393 /* Number of repetitions we have detected so far. */
400 fputs_filtered (", ", stream
);
406 while (rep1
< length
&& string
[rep1
] == string
[i
])
412 if (reps
> repeat_count_threshold
)
417 fputs_filtered ("\\\", ", stream
);
419 fputs_filtered ("\", ", stream
);
422 objc_printchar (string
[i
], stream
);
423 fprintf_filtered (stream
, " <repeats %u times>", reps
);
425 things_printed
+= repeat_count_threshold
;
433 fputs_filtered ("\\\"", stream
);
435 fputs_filtered ("\"", stream
);
438 objc_emit_char (string
[i
], stream
, '"');
443 /* Terminate the quotes if necessary. */
447 fputs_filtered ("\\\"", stream
);
449 fputs_filtered ("\"", stream
);
452 if (force_ellipses
|| i
< length
)
453 fputs_filtered ("...", stream
);
456 /* Create a fundamental C type using default reasonable for the
459 Some object/debugging file formats (DWARF version 1, COFF, etc) do
460 not define fundamental types such as "int" or "double". Others
461 (stabs or DWARF version 2, etc) do define fundamental types. For
462 the formats which don't provide fundamental types, gdb can create
463 such types using this function.
465 FIXME: Some compilers distinguish explicitly signed integral types
466 (signed short, signed int, signed long) from "regular" integral
467 types (short, int, long) in the debugging information. There is
468 some disagreement as to how useful this feature is. In particular,
469 gcc does not support this. Also, only some debugging formats allow
470 the distinction to be passed on to a debugger. For now, we always
471 just use "short", "int", or "long" as the type name, for both the
472 implicit and explicitly signed types. This also makes life easier
473 for the gdb test suite since we don't have to account for the
474 differences in output depending upon what the compiler and
475 debugging format support. We will probably have to re-examine the
476 issue when gdb starts taking it's fundamental type information
477 directly from the debugging information supplied by the compiler.
481 objc_create_fundamental_type (struct objfile
*objfile
, int typeid)
483 register struct type
*type
= NULL
;
488 /* FIXME: For now, if we are asked to produce a type not in
489 this language, create the equivalent of a C integer type
490 with the name "<?type?>". When all the dust settles from
491 the type reconstruction work, this should probably become
493 type
= init_type (TYPE_CODE_INT
,
494 TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
495 0, "<?type?>", objfile
);
496 warning ("internal error: no C/C++ fundamental type %d", typeid);
499 type
= init_type (TYPE_CODE_VOID
,
500 TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
504 type
= init_type (TYPE_CODE_INT
,
505 TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
509 type
= init_type (TYPE_CODE_INT
,
510 TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
511 0, "signed char", objfile
);
513 case FT_UNSIGNED_CHAR
:
514 type
= init_type (TYPE_CODE_INT
,
515 TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
516 TYPE_FLAG_UNSIGNED
, "unsigned char", objfile
);
519 type
= init_type (TYPE_CODE_INT
,
520 TARGET_SHORT_BIT
/ TARGET_CHAR_BIT
,
521 0, "short", objfile
);
523 case FT_SIGNED_SHORT
:
524 type
= init_type (TYPE_CODE_INT
,
525 TARGET_SHORT_BIT
/ TARGET_CHAR_BIT
,
526 0, "short", objfile
); /* FIXME-fnf */
528 case FT_UNSIGNED_SHORT
:
529 type
= init_type (TYPE_CODE_INT
,
530 TARGET_SHORT_BIT
/ TARGET_CHAR_BIT
,
531 TYPE_FLAG_UNSIGNED
, "unsigned short", objfile
);
534 type
= init_type (TYPE_CODE_INT
,
535 TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
538 case FT_SIGNED_INTEGER
:
539 type
= init_type (TYPE_CODE_INT
,
540 TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
541 0, "int", objfile
); /* FIXME -fnf */
543 case FT_UNSIGNED_INTEGER
:
544 type
= init_type (TYPE_CODE_INT
,
545 TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
546 TYPE_FLAG_UNSIGNED
, "unsigned int", objfile
);
549 type
= init_type (TYPE_CODE_INT
,
550 TARGET_LONG_BIT
/ TARGET_CHAR_BIT
,
554 type
= init_type (TYPE_CODE_INT
,
555 TARGET_LONG_BIT
/ TARGET_CHAR_BIT
,
556 0, "long", objfile
); /* FIXME -fnf */
558 case FT_UNSIGNED_LONG
:
559 type
= init_type (TYPE_CODE_INT
,
560 TARGET_LONG_BIT
/ TARGET_CHAR_BIT
,
561 TYPE_FLAG_UNSIGNED
, "unsigned long", objfile
);
564 type
= init_type (TYPE_CODE_INT
,
565 TARGET_LONG_LONG_BIT
/ TARGET_CHAR_BIT
,
566 0, "long long", objfile
);
568 case FT_SIGNED_LONG_LONG
:
569 type
= init_type (TYPE_CODE_INT
,
570 TARGET_LONG_LONG_BIT
/ TARGET_CHAR_BIT
,
571 0, "signed long long", objfile
);
573 case FT_UNSIGNED_LONG_LONG
:
574 type
= init_type (TYPE_CODE_INT
,
575 TARGET_LONG_LONG_BIT
/ TARGET_CHAR_BIT
,
576 TYPE_FLAG_UNSIGNED
, "unsigned long long", objfile
);
579 type
= init_type (TYPE_CODE_FLT
,
580 TARGET_FLOAT_BIT
/ TARGET_CHAR_BIT
,
581 0, "float", objfile
);
583 case FT_DBL_PREC_FLOAT
:
584 type
= init_type (TYPE_CODE_FLT
,
585 TARGET_DOUBLE_BIT
/ TARGET_CHAR_BIT
,
586 0, "double", objfile
);
588 case FT_EXT_PREC_FLOAT
:
589 type
= init_type (TYPE_CODE_FLT
,
590 TARGET_LONG_DOUBLE_BIT
/ TARGET_CHAR_BIT
,
591 0, "long double", objfile
);
598 /* Table mapping opcodes into strings for printing operators
599 and precedences of the operators. */
601 static const struct op_print objc_op_print_tab
[] =
603 {",", BINOP_COMMA
, PREC_COMMA
, 0},
604 {"=", BINOP_ASSIGN
, PREC_ASSIGN
, 1},
605 {"||", BINOP_LOGICAL_OR
, PREC_LOGICAL_OR
, 0},
606 {"&&", BINOP_LOGICAL_AND
, PREC_LOGICAL_AND
, 0},
607 {"|", BINOP_BITWISE_IOR
, PREC_BITWISE_IOR
, 0},
608 {"^", BINOP_BITWISE_XOR
, PREC_BITWISE_XOR
, 0},
609 {"&", BINOP_BITWISE_AND
, PREC_BITWISE_AND
, 0},
610 {"==", BINOP_EQUAL
, PREC_EQUAL
, 0},
611 {"!=", BINOP_NOTEQUAL
, PREC_EQUAL
, 0},
612 {"<=", BINOP_LEQ
, PREC_ORDER
, 0},
613 {">=", BINOP_GEQ
, PREC_ORDER
, 0},
614 {">", BINOP_GTR
, PREC_ORDER
, 0},
615 {"<", BINOP_LESS
, PREC_ORDER
, 0},
616 {">>", BINOP_RSH
, PREC_SHIFT
, 0},
617 {"<<", BINOP_LSH
, PREC_SHIFT
, 0},
618 {"+", BINOP_ADD
, PREC_ADD
, 0},
619 {"-", BINOP_SUB
, PREC_ADD
, 0},
620 {"*", BINOP_MUL
, PREC_MUL
, 0},
621 {"/", BINOP_DIV
, PREC_MUL
, 0},
622 {"%", BINOP_REM
, PREC_MUL
, 0},
623 {"@", BINOP_REPEAT
, PREC_REPEAT
, 0},
624 {"-", UNOP_NEG
, PREC_PREFIX
, 0},
625 {"!", UNOP_LOGICAL_NOT
, PREC_PREFIX
, 0},
626 {"~", UNOP_COMPLEMENT
, PREC_PREFIX
, 0},
627 {"*", UNOP_IND
, PREC_PREFIX
, 0},
628 {"&", UNOP_ADDR
, PREC_PREFIX
, 0},
629 {"sizeof ", UNOP_SIZEOF
, PREC_PREFIX
, 0},
630 {"++", UNOP_PREINCREMENT
, PREC_PREFIX
, 0},
631 {"--", UNOP_PREDECREMENT
, PREC_PREFIX
, 0},
635 struct type
** const (objc_builtin_types
[]) =
642 &builtin_type_double
,
644 &builtin_type_long_long
,
645 &builtin_type_signed_char
,
646 &builtin_type_unsigned_char
,
647 &builtin_type_unsigned_short
,
648 &builtin_type_unsigned_int
,
649 &builtin_type_unsigned_long
,
650 &builtin_type_unsigned_long_long
,
651 &builtin_type_long_double
,
652 &builtin_type_complex
,
653 &builtin_type_double_complex
,
657 const struct language_defn objc_language_defn
= {
658 "objective-c", /* Language name */
666 evaluate_subexp_standard
,
667 objc_printchar
, /* Print a character constant */
668 objc_printstr
, /* Function to print string constant */
670 objc_create_fundamental_type
, /* Create fundamental type in this language */
671 c_print_type
, /* Print a type using appropriate syntax */
672 c_val_print
, /* Print a value using appropriate syntax */
673 c_value_print
, /* Print a top-level value */
674 {"", "", "", ""}, /* Binary format info */
675 {"0%lo", "0", "o", ""}, /* Octal format info */
676 {"%ld", "", "d", ""}, /* Decimal format info */
677 {"0x%lx", "0x", "x", ""}, /* Hex format info */
678 objc_op_print_tab
, /* Expression operators for printing */
679 1, /* C-style arrays */
680 0, /* String lower bound */
681 &builtin_type_char
, /* Type of string elements */
687 * Following functions help construct Objective-C message calls
690 struct selname
/* For parsing Objective-C. */
692 struct selname
*next
;
697 static int msglist_len
;
698 static struct selname
*selname_chain
;
699 static char *msglist_sel
;
704 register struct selname
*new =
705 (struct selname
*) xmalloc (sizeof (struct selname
));
707 new->next
= selname_chain
;
708 new->msglist_len
= msglist_len
;
709 new->msglist_sel
= msglist_sel
;
711 msglist_sel
= (char *)xmalloc(1);
717 add_msglist(struct stoken
*str
, int addcolon
)
722 if (str
== 0) { /* Unnamed arg, or... */
723 if (addcolon
== 0) { /* variable number of args. */
733 len
= plen
+ strlen(msglist_sel
) + 2;
734 s
= (char *)xmalloc(len
);
735 strcpy(s
, msglist_sel
);
750 register int val
= msglist_len
;
751 register struct selname
*sel
= selname_chain
;
752 register char *p
= msglist_sel
;
755 selname_chain
= sel
->next
;
756 msglist_len
= sel
->msglist_len
;
757 msglist_sel
= sel
->msglist_sel
;
758 selid
= lookup_child_selector(p
);
760 error("Can't find selector \"%s\"", p
);
761 write_exp_elt_longcst (selid
);
763 write_exp_elt_longcst (val
); /* Number of args */
770 * Function: specialcmp (char *a, char *b)
772 * Special strcmp: treats ']' and ' ' as end-of-string.
773 * Used for qsorting lists of objc methods (either by class or selector).
776 int specialcmp(char *a
, char *b
)
778 while (*a
&& *a
!= ' ' && *a
!= ']' && *b
&& *b
!= ' ' && *b
!= ']')
784 if (*a
&& *a
!= ' ' && *a
!= ']')
785 return 1; /* a is longer therefore greater */
786 if (*b
&& *b
!= ' ' && *b
!= ']')
787 return -1; /* a is shorter therefore lesser */
788 return 0; /* a and b are identical */
792 * Function: compare_selectors (void *, void *)
794 * Comparison function for use with qsort. Arguments are symbols or
795 * msymbols Compares selector part of objc method name alphabetically.
799 compare_selectors (void *a
, void *b
)
803 if ((aname
= SYMBOL_SOURCE_NAME (*(struct symbol
**) a
)) == NULL
||
804 (bname
= SYMBOL_SOURCE_NAME (*(struct symbol
**) b
)) == NULL
)
805 error ("internal: compare_selectors(1)");
807 if ((aname
= strchr(aname
, ' ')) == NULL
||
808 (bname
= strchr(bname
, ' ')) == NULL
)
809 error ("internal: compare_selectors(2)");
811 return specialcmp (aname
+1, bname
+1);
815 * Function: selectors_info (regexp, from_tty)
817 * Implements the "Info selectors" command. Takes an optional regexp
818 * arg. Lists all objective c selectors that match the regexp. Works
819 * by grepping thru all symbols for objective c methods. Output list
820 * is sorted and uniqued.
824 selectors_info (char *regexp
, int from_tty
)
826 struct objfile
*objfile
;
827 struct minimal_symbol
*msymbol
;
835 struct symbol
**sym_arr
;
839 strcpy(myregexp
, ".*]"); /* Null input, match all objc methods. */
842 if (*regexp
== '+' || *regexp
== '-')
843 { /* User wants only class methods or only instance methods. */
844 plusminus
= *regexp
++;
845 while (*regexp
== ' ' || *regexp
== '\t')
849 strcpy(myregexp
, ".*]");
852 strcpy(myregexp
, regexp
);
853 if (myregexp
[strlen(myregexp
) - 1] == '$') /* end of selector */
854 myregexp
[strlen(myregexp
) - 1] = ']'; /* end of method name */
856 strcat(myregexp
, ".*]");
861 if (0 != (val
= re_comp (myregexp
)))
862 error ("Invalid regexp (%s): %s", val
, regexp
);
864 /* First time thru is JUST to get max length and count. */
865 ALL_MSYMBOLS (objfile
, msymbol
)
868 if ((name
= SYMBOL_DEMANGLED_NAME (msymbol
)) == NULL
)
869 name
= SYMBOL_NAME (msymbol
);
871 (name
[0] == '-' || name
[0] == '+') &&
872 name
[1] == '[') /* Got a method name. */
874 /* Filter for class/instance methods. */
875 if (plusminus
&& name
[0] != plusminus
)
877 /* Find selector part. */
878 name
= (char *) strchr(name
+2, ' ');
879 if (regexp
== NULL
|| re_exec(++name
) != 0)
881 char *mystart
= name
;
882 char *myend
= (char *) strchr(mystart
, ']');
884 if (myend
&& (myend
- mystart
> maxlen
))
885 maxlen
= myend
- mystart
; /* Get longest selector. */
892 printf_filtered ("Selectors matching \"%s\":\n\n",
893 regexp
? regexp
: "*");
895 sym_arr
= alloca (matches
* sizeof (struct symbol
*));
897 ALL_MSYMBOLS (objfile
, msymbol
)
900 if ((name
= SYMBOL_DEMANGLED_NAME (msymbol
)) == NULL
)
901 name
= SYMBOL_NAME (msymbol
);
903 (name
[0] == '-' || name
[0] == '+') &&
904 name
[1] == '[') /* Got a method name. */
906 /* Filter for class/instance methods. */
907 if (plusminus
&& name
[0] != plusminus
)
909 /* Find selector part. */
910 name
= (char *) strchr(name
+2, ' ');
911 if (regexp
== NULL
|| re_exec(++name
) != 0)
912 sym_arr
[matches
++] = (struct symbol
*) msymbol
;
916 qsort (sym_arr
, matches
, sizeof (struct minimal_symbol
*),
918 /* Prevent compare on first iteration. */
920 for (ix
= 0; ix
< matches
; ix
++) /* Now do the output. */
925 if ((name
= SYMBOL_DEMANGLED_NAME (sym_arr
[ix
])) == NULL
)
926 name
= SYMBOL_NAME (sym_arr
[ix
]);
927 name
= strchr (name
, ' ') + 1;
928 if (p
[0] && specialcmp(name
, p
) == 0)
929 continue; /* Seen this one already (not unique). */
931 /* Copy selector part. */
932 while (*name
&& *name
!= ']')
935 /* Print in columns. */
936 puts_filtered_tabular(asel
, maxlen
+ 1, 0);
941 printf_filtered ("No selectors matching \"%s\"\n", regexp
? regexp
: "*");
945 * Function: compare_classes (void *, void *)
947 * Comparison function for use with qsort. Arguments are symbols or
948 * msymbols Compares class part of objc method name alphabetically.
952 compare_classes (void *a
, void *b
)
956 if ((aname
= SYMBOL_SOURCE_NAME (*(struct symbol
**) a
)) == NULL
||
957 (bname
= SYMBOL_SOURCE_NAME (*(struct symbol
**) b
)) == NULL
)
958 error ("internal: compare_classes(1)");
960 return specialcmp (aname
+1, bname
+1);
964 * Function: classes_info(regexp, from_tty)
966 * Implements the "info classes" command for objective c classes.
967 * Lists all objective c classes that match the optional regexp.
968 * Works by grepping thru the list of objective c methods. List will
969 * be sorted and uniqued (since one class may have many methods).
970 * BUGS: will not list a class that has no methods.
974 classes_info (char *regexp
, int from_tty
)
976 struct objfile
*objfile
;
977 struct minimal_symbol
*msymbol
;
985 struct symbol
**sym_arr
;
988 strcpy(myregexp
, ".* "); /* Null input: match all objc classes. */
991 strcpy(myregexp
, regexp
);
992 if (myregexp
[strlen(myregexp
) - 1] == '$')
993 /* In the method name, the end of the class name is marked by ' '. */
994 myregexp
[strlen(myregexp
) - 1] = ' ';
996 strcat(myregexp
, ".* ");
1000 if (0 != (val
= re_comp (myregexp
)))
1001 error ("Invalid regexp (%s): %s", val
, regexp
);
1003 /* First time thru is JUST to get max length and count. */
1004 ALL_MSYMBOLS (objfile
, msymbol
)
1007 if ((name
= SYMBOL_DEMANGLED_NAME (msymbol
)) == NULL
)
1008 name
= SYMBOL_NAME (msymbol
);
1010 (name
[0] == '-' || name
[0] == '+') &&
1011 name
[1] == '[') /* Got a method name. */
1012 if (regexp
== NULL
|| re_exec(name
+2) != 0)
1014 /* Compute length of classname part. */
1015 char *mystart
= name
+ 2;
1016 char *myend
= (char *) strchr(mystart
, ' ');
1018 if (myend
&& (myend
- mystart
> maxlen
))
1019 maxlen
= myend
- mystart
;
1025 printf_filtered ("Classes matching \"%s\":\n\n",
1026 regexp
? regexp
: "*");
1027 sym_arr
= alloca (matches
* sizeof (struct symbol
*));
1029 ALL_MSYMBOLS (objfile
, msymbol
)
1032 if ((name
= SYMBOL_DEMANGLED_NAME (msymbol
)) == NULL
)
1033 name
= SYMBOL_NAME (msymbol
);
1035 (name
[0] == '-' || name
[0] == '+') &&
1036 name
[1] == '[') /* Got a method name. */
1037 if (regexp
== NULL
|| re_exec(name
+2) != 0)
1038 sym_arr
[matches
++] = (struct symbol
*) msymbol
;
1041 qsort (sym_arr
, matches
, sizeof (struct minimal_symbol
*),
1043 /* Prevent compare on first iteration. */
1045 for (ix
= 0; ix
< matches
; ix
++) /* Now do the output. */
1050 if ((name
= SYMBOL_DEMANGLED_NAME (sym_arr
[ix
])) == NULL
)
1051 name
= SYMBOL_NAME (sym_arr
[ix
]);
1053 if (p
[0] && specialcmp(name
, p
) == 0)
1054 continue; /* Seen this one already (not unique). */
1056 /* Copy class part of method name. */
1057 while (*name
&& *name
!= ' ')
1060 /* Print in columns. */
1061 puts_filtered_tabular(aclass
, maxlen
+ 1, 0);
1066 printf_filtered ("No classes matching \"%s\"\n", regexp
? regexp
: "*");
1070 * Function: find_imps (char *selector, struct symbol **sym_arr)
1072 * Input: a string representing a selector
1073 * a pointer to an array of symbol pointers
1074 * possibly a pointer to a symbol found by the caller.
1076 * Output: number of methods that implement that selector. Side
1077 * effects: The array of symbol pointers is filled with matching syms.
1079 * By analogy with function "find_methods" (symtab.c), builds a list
1080 * of symbols matching the ambiguous input, so that "decode_line_2"
1081 * (symtab.c) can list them and ask the user to choose one or more.
1082 * In this case the matches are objective c methods
1083 * ("implementations") matching an objective c selector.
1085 * Note that it is possible for a normal (c-style) function to have
1086 * the same name as an objective c selector. To prevent the selector
1087 * from eclipsing the function, we allow the caller (decode_line_1) to
1088 * search for such a function first, and if it finds one, pass it in
1089 * to us. We will then integrate it into the list. We also search
1090 * for one here, among the minsyms.
1092 * NOTE: if NUM_DEBUGGABLE is non-zero, the sym_arr will be divided
1093 * into two parts: debuggable (struct symbol) syms, and
1094 * non_debuggable (struct minimal_symbol) syms. The debuggable
1095 * ones will come first, before NUM_DEBUGGABLE (which will thus
1096 * be the index of the first non-debuggable one).
1100 * Function: total_number_of_imps (char *selector);
1102 * Input: a string representing a selector
1103 * Output: number of methods that implement that selector.
1105 * By analogy with function "total_number_of_methods", this allows
1106 * decode_line_1 (symtab.c) to detect if there are objective c methods
1107 * matching the input, and to allocate an array of pointers to them
1108 * which can be manipulated by "decode_line_2" (also in symtab.c).
1112 parse_selector (char *method
, char **selector
)
1116 int found_quote
= 0;
1118 char *nselector
= NULL
;
1120 CHECK (selector
!= NULL
);
1124 while (isspace (*s1
))
1131 while (isspace (*s1
))
1138 if (isalnum (*s2
) || (*s2
== '_') || (*s2
== ':'))
1140 else if (isspace (*s2
))
1142 else if ((*s2
== '\0') || (*s2
== '\''))
1150 while (isspace (*s2
))
1156 while (isspace (*s2
))
1160 if (selector
!= NULL
)
1161 *selector
= nselector
;
1167 parse_method (char *method
, char *type
, char **class,
1168 char **category
, char **selector
)
1172 int found_quote
= 0;
1175 char *nclass
= NULL
;
1176 char *ncategory
= NULL
;
1177 char *nselector
= NULL
;
1179 CHECK (type
!= NULL
);
1180 CHECK (class != NULL
);
1181 CHECK (category
!= NULL
);
1182 CHECK (selector
!= NULL
);
1186 while (isspace (*s1
))
1193 while (isspace (*s1
))
1196 if ((s1
[0] == '+') || (s1
[0] == '-'))
1199 while (isspace (*s1
))
1207 while (isalnum (*s1
) || (*s1
== '_'))
1211 while (isspace (*s2
))
1217 while (isspace (*s2
))
1220 while (isalnum (*s2
) || (*s2
== '_'))
1225 /* Truncate the class name now that we're not using the open paren. */
1232 if (isalnum (*s2
) || (*s2
== '_') || (*s2
== ':'))
1234 else if (isspace (*s2
))
1236 else if (*s2
== ']')
1245 while (isspace (*s2
))
1252 while (isspace (*s2
))
1260 if (category
!= NULL
)
1261 *category
= ncategory
;
1262 if (selector
!= NULL
)
1263 *selector
= nselector
;
1269 find_methods (struct symtab
*symtab
, char type
,
1270 const char *class, const char *category
,
1271 const char *selector
, struct symbol
**syms
,
1272 unsigned int *nsym
, unsigned int *ndebug
)
1274 struct objfile
*objfile
= NULL
;
1275 struct minimal_symbol
*msymbol
= NULL
;
1276 struct block
*block
= NULL
;
1277 struct symbol
*sym
= NULL
;
1279 char *symname
= NULL
;
1282 char *nclass
= NULL
;
1283 char *ncategory
= NULL
;
1284 char *nselector
= NULL
;
1286 unsigned int csym
= 0;
1287 unsigned int cdebug
= 0;
1289 static char *tmp
= NULL
;
1290 static unsigned int tmplen
= 0;
1292 CHECK (nsym
!= NULL
);
1293 CHECK (ndebug
!= NULL
);
1296 block
= BLOCKVECTOR_BLOCK (BLOCKVECTOR (symtab
), STATIC_BLOCK
);
1298 ALL_MSYMBOLS (objfile
, msymbol
)
1302 if ((msymbol
->type
!= mst_text
) && (msymbol
->type
!= mst_file_text
))
1303 /* Not a function or method. */
1307 if ((SYMBOL_VALUE_ADDRESS (msymbol
) < block
->startaddr
) ||
1308 (SYMBOL_VALUE_ADDRESS (msymbol
) >= block
->endaddr
))
1309 /* Not in the specified symtab. */
1312 symname
= SYMBOL_DEMANGLED_NAME (msymbol
);
1313 if (symname
== NULL
)
1314 symname
= SYMBOL_NAME (msymbol
);
1315 if (symname
== NULL
)
1318 if ((symname
[0] != '-' && symname
[0] != '+') || (symname
[1] != '['))
1319 /* Not a method name. */
1322 while ((strlen (symname
) + 1) >= tmplen
)
1324 tmplen
= (tmplen
== 0) ? 1024 : tmplen
* 2;
1325 tmp
= xrealloc (tmp
, tmplen
);
1327 strcpy (tmp
, symname
);
1329 if (parse_method (tmp
, &ntype
, &nclass
, &ncategory
, &nselector
) == NULL
)
1332 if ((type
!= '\0') && (ntype
!= type
))
1336 && ((nclass
== NULL
) || (strcmp (class, nclass
) != 0)))
1339 if ((category
!= NULL
) &&
1340 ((ncategory
== NULL
) || (strcmp (category
, ncategory
) != 0)))
1343 if ((selector
!= NULL
) &&
1344 ((nselector
== NULL
) || (strcmp (selector
, nselector
) != 0)))
1347 sym
= find_pc_function (SYMBOL_VALUE_ADDRESS (msymbol
));
1350 const char *newsymname
= SYMBOL_DEMANGLED_NAME (sym
);
1352 if (newsymname
== NULL
)
1353 newsymname
= SYMBOL_NAME (sym
);
1354 if (strcmp (symname
, newsymname
) == 0)
1356 /* Found a high-level method sym: swap it into the
1357 lower part of sym_arr (below num_debuggable). */
1360 syms
[csym
] = syms
[cdebug
];
1369 "debugging symbol \"%s\" does not match minimal symbol (\"%s\"); ignoring",
1370 newsymname
, symname
);
1372 syms
[csym
] = (struct symbol
*) msymbol
;
1378 /* Found a non-debuggable method symbol. */
1380 syms
[csym
] = (struct symbol
*) msymbol
;
1391 char *find_imps (struct symtab
*symtab
, struct block
*block
,
1392 char *method
, struct symbol
**syms
,
1393 unsigned int *nsym
, unsigned int *ndebug
)
1397 char *category
= NULL
;
1398 char *selector
= NULL
;
1400 unsigned int csym
= 0;
1401 unsigned int cdebug
= 0;
1403 unsigned int ncsym
= 0;
1404 unsigned int ncdebug
= 0;
1409 CHECK (nsym
!= NULL
);
1410 CHECK (ndebug
!= NULL
);
1417 buf
= (char *) alloca (strlen (method
) + 1);
1418 strcpy (buf
, method
);
1419 tmp
= parse_method (buf
, &type
, &class, &category
, &selector
);
1423 struct symtab
*sym_symtab
= NULL
;
1424 struct symbol
*sym
= NULL
;
1425 struct minimal_symbol
*msym
= NULL
;
1427 strcpy (buf
, method
);
1428 tmp
= parse_selector (buf
, &selector
);
1433 sym
= lookup_symbol (selector
, block
, VAR_NAMESPACE
, 0, &sym_symtab
);
1443 msym
= lookup_minimal_symbol (selector
, 0, 0);
1454 find_methods (symtab
, type
, class, category
, selector
,
1455 syms
+ csym
, &ncsym
, &ncdebug
);
1457 find_methods (symtab
, type
, class, category
, selector
,
1458 NULL
, &ncsym
, &ncdebug
);
1460 /* If we didn't find any methods, just return. */
1461 if (ncsym
== 0 && ncdebug
== 0)
1464 /* Take debug symbols from the second batch of symbols and swap them
1465 * with debug symbols from the first batch. Repeat until either the
1466 * second section is out of debug symbols or the first section is
1467 * full of debug symbols. Either way we have all debug symbols
1468 * packed to the beginning of the buffer.
1473 while ((cdebug
< csym
) && (ncdebug
> 0))
1475 struct symbol
*s
= NULL
;
1476 /* First non-debugging symbol. */
1477 unsigned int i
= cdebug
;
1478 /* Last of second batch of debug symbols. */
1479 unsigned int j
= csym
+ ncdebug
- 1;
1485 /* We've moved a symbol from the second debug section to the
1501 return method
+ (tmp
- buf
);
1505 /* Sort debuggable symbols. */
1507 qsort (syms
, cdebug
, sizeof (struct minimal_symbol
*),
1510 /* Sort minimal_symbols. */
1511 if ((csym
- cdebug
) > 1)
1512 qsort (&syms
[cdebug
], csym
- cdebug
,
1513 sizeof (struct minimal_symbol
*), compare_classes
);
1515 /* Terminate the sym_arr list. */
1518 return method
+ (tmp
- buf
);
1522 print_object_command (char *args
, int from_tty
)
1524 struct value
*object
, *function
, *description
;
1525 CORE_ADDR string_addr
;
1529 if (!args
|| !*args
)
1531 "The 'print-object' command requires an argument (an Objective-C object)");
1534 struct expression
*expr
= parse_expression (args
);
1535 register struct cleanup
*old_chain
=
1536 make_cleanup (free_current_contents
, &expr
);
1540 object
= expr
->language_defn
->evaluate_exp (builtin_type_void_data_ptr
,
1541 expr
, &pc
, EVAL_NORMAL
);
1543 object
= evaluate_subexp (builtin_type_void_data_ptr
,
1544 expr
, &pc
, EVAL_NORMAL
);
1546 do_cleanups (old_chain
);
1549 if (!(function
= find_function_in_inferior ("_NSPrintForDebugger")))
1550 error ("Unable to locate _NSPrintForDebugger in child process");
1552 description
= call_function_by_hand (function
, 1, &object
);
1554 if ((string_addr
= value_as_long (description
)) == 0)
1555 error ("object returns null description");
1557 read_memory (string_addr
+ i
++, &c
, 1);
1560 { /* Read and print characters up to EOS. */
1562 printf_filtered ("%c", c
);
1563 read_memory (string_addr
+ i
++, &c
, 1);
1566 printf_filtered("<object returns empty description>");
1567 printf_filtered ("\n");
1570 /* The data structure 'methcalls' is used to detect method calls (thru
1571 * ObjC runtime lib functions objc_msgSend, objc_msgSendSuper, etc.),
1572 * and ultimately find the method being called.
1575 struct objc_methcall
{
1577 /* Return instance method to be called. */
1578 CORE_ADDR (*stop_at
) (CORE_ADDR
);
1579 /* Start of pc range corresponding to method invocation. */
1581 /* End of pc range corresponding to method invocation. */
1585 static int resolve_msgsend (CORE_ADDR pc
, CORE_ADDR
*new_pc
);
1586 static int resolve_msgsend_stret (CORE_ADDR pc
, CORE_ADDR
*new_pc
);
1587 static int resolve_msgsend_super (CORE_ADDR pc
, CORE_ADDR
*new_pc
);
1588 static int resolve_msgsend_super_stret (CORE_ADDR pc
, CORE_ADDR
*new_pc
);
1590 static struct objc_methcall methcalls
[] = {
1591 { "_objc_msgSend", resolve_msgsend
, 0, 0},
1592 { "_objc_msgSend_stret", resolve_msgsend_stret
, 0, 0},
1593 { "_objc_msgSendSuper", resolve_msgsend_super
, 0, 0},
1594 { "_objc_msgSendSuper_stret", resolve_msgsend_super_stret
, 0, 0},
1595 { "_objc_getClass", NULL
, 0, 0},
1596 { "_objc_getMetaClass", NULL
, 0, 0}
1599 #define nmethcalls (sizeof (methcalls) / sizeof (methcalls[0]))
1601 /* The following function, "find_objc_msgsend", fills in the data
1602 * structure "objc_msgs" by finding the addresses of each of the
1603 * (currently four) functions that it holds (of which objc_msgSend is
1604 * the first). This must be called each time symbols are loaded, in
1605 * case the functions have moved for some reason.
1609 find_objc_msgsend (void)
1612 for (i
= 0; i
< nmethcalls
; i
++) {
1614 struct minimal_symbol
*func
;
1616 /* Try both with and without underscore. */
1617 func
= lookup_minimal_symbol (methcalls
[i
].name
, NULL
, NULL
);
1618 if ((func
== NULL
) && (methcalls
[i
].name
[0] == '_')) {
1619 func
= lookup_minimal_symbol (methcalls
[i
].name
+ 1, NULL
, NULL
);
1622 methcalls
[i
].begin
= 0;
1623 methcalls
[i
].end
= 0;
1627 methcalls
[i
].begin
= SYMBOL_VALUE_ADDRESS (func
);
1629 methcalls
[i
].end
= SYMBOL_VALUE_ADDRESS (++func
);
1630 } while (methcalls
[i
].begin
== methcalls
[i
].end
);
1634 /* find_objc_msgcall (replaces pc_off_limits)
1636 * ALL that this function now does is to determine whether the input
1637 * address ("pc") is the address of one of the Objective-C message
1638 * dispatch functions (mainly objc_msgSend or objc_msgSendSuper), and
1639 * if so, it returns the address of the method that will be called.
1641 * The old function "pc_off_limits" used to do a lot of other things
1642 * in addition, such as detecting shared library jump stubs and
1643 * returning the address of the shlib function that would be called.
1644 * That functionality has been moved into the SKIP_TRAMPOLINE_CODE and
1645 * IN_SOLIB_TRAMPOLINE macros, which are resolved in the target-
1646 * dependent modules.
1649 struct objc_submethod_helper_data
{
1650 CORE_ADDR (*f
) (CORE_ADDR
, CORE_ADDR
*);
1656 find_objc_msgcall_submethod_helper (PTR arg
)
1658 struct objc_submethod_helper_data
*s
=
1659 (struct objc_submethod_helper_data
*) arg
;
1661 if (s
->f (s
->pc
, s
->new_pc
) == 0)
1668 find_objc_msgcall_submethod (CORE_ADDR (*f
) (CORE_ADDR
, CORE_ADDR
*),
1672 struct objc_submethod_helper_data s
;
1678 if (catch_errors (find_objc_msgcall_submethod_helper
,
1680 "Unable to determine target of Objective-C method call (ignoring):\n",
1681 RETURN_MASK_ALL
) == 0)
1688 find_objc_msgcall (CORE_ADDR pc
, CORE_ADDR
*new_pc
)
1692 find_objc_msgsend ();
1693 if (new_pc
!= NULL
) { *new_pc
= 0; }
1695 for (i
= 0; i
< nmethcalls
; i
++)
1696 if ((pc
>= methcalls
[i
].begin
) && (pc
< methcalls
[i
].end
))
1698 if (methcalls
[i
].stop_at
!= NULL
)
1699 return find_objc_msgcall_submethod (methcalls
[i
].stop_at
,
1709 _initialize_objc_language (void)
1711 add_language (&objc_language_defn
);
1712 add_info ("selectors", selectors_info
, /* INFO SELECTORS command. */
1713 "All Objective-C selectors, or those matching REGEXP.");
1714 add_info ("classes", classes_info
, /* INFO CLASSES command. */
1715 "All Objective-C classes, or those matching REGEXP.");
1716 add_com ("print-object", class_vars
, print_object_command
,
1717 "Ask an Objective-C object to print itself.\n");
1718 add_com_alias ("po", "print-object", class_vars
, 1);
1721 #if defined (__powerpc__) || defined (__ppc__)
1722 static unsigned long FETCH_ARGUMENT (int i
)
1724 return read_register (3 + i
);
1726 #elif defined (__i386__)
1727 static unsigned long FETCH_ARGUMENT (int i
)
1729 CORE_ADDR stack
= read_register (SP_REGNUM
);
1730 return read_memory_unsigned_integer (stack
+ (4 * (i
+ 1)), 4);
1732 #elif defined (__sparc__)
1733 static unsigned long FETCH_ARGUMENT (int i
)
1735 return read_register (O0_REGNUM
+ i
);
1737 #elif defined (__hppa__) || defined (__hppa)
1738 static unsigned long FETCH_ARGUMENT (int i
)
1740 return read_register (R0_REGNUM
+ 26 - i
);
1743 #error unknown architecture
1746 #if defined (__hppa__) || defined (__hppa)
1747 static CORE_ADDR
CONVERT_FUNCPTR (CORE_ADDR pc
)
1750 pc
= (CORE_ADDR
) read_memory_integer (pc
& ~0x3, 4);
1755 static CORE_ADDR
CONVERT_FUNCPTR (CORE_ADDR pc
)
1762 read_objc_method (CORE_ADDR addr
, struct objc_method
*method
)
1764 method
->name
= read_memory_unsigned_integer (addr
+ 0, 4);
1765 method
->types
= read_memory_unsigned_integer (addr
+ 4, 4);
1766 method
->imp
= read_memory_unsigned_integer (addr
+ 8, 4);
1770 unsigned long read_objc_methlist_nmethods (CORE_ADDR addr
)
1772 return read_memory_unsigned_integer (addr
+ 4, 4);
1776 read_objc_methlist_method (CORE_ADDR addr
, unsigned long num
,
1777 struct objc_method
*method
)
1779 CHECK_FATAL (num
< read_objc_methlist_nmethods (addr
));
1780 read_objc_method (addr
+ 8 + (12 * num
), method
);
1784 read_objc_object (CORE_ADDR addr
, struct objc_object
*object
)
1786 object
->isa
= read_memory_unsigned_integer (addr
, 4);
1790 read_objc_super (CORE_ADDR addr
, struct objc_super
*super
)
1792 super
->receiver
= read_memory_unsigned_integer (addr
, 4);
1793 super
->class = read_memory_unsigned_integer (addr
+ 4, 4);
1797 read_objc_class (CORE_ADDR addr
, struct objc_class
*class)
1799 class->isa
= read_memory_unsigned_integer (addr
, 4);
1800 class->super_class
= read_memory_unsigned_integer (addr
+ 4, 4);
1801 class->name
= read_memory_unsigned_integer (addr
+ 8, 4);
1802 class->version
= read_memory_unsigned_integer (addr
+ 12, 4);
1803 class->info
= read_memory_unsigned_integer (addr
+ 16, 4);
1804 class->instance_size
= read_memory_unsigned_integer (addr
+ 18, 4);
1805 class->ivars
= read_memory_unsigned_integer (addr
+ 24, 4);
1806 class->methods
= read_memory_unsigned_integer (addr
+ 28, 4);
1807 class->cache
= read_memory_unsigned_integer (addr
+ 32, 4);
1808 class->protocols
= read_memory_unsigned_integer (addr
+ 36, 4);
1812 find_implementation_from_class (CORE_ADDR
class, CORE_ADDR sel
)
1814 CORE_ADDR subclass
= class;
1816 while (subclass
!= 0)
1819 struct objc_class class_str
;
1820 unsigned mlistnum
= 0;
1822 read_objc_class (subclass
, &class_str
);
1827 unsigned long nmethods
;
1830 mlist
= read_memory_unsigned_integer (class_str
.methods
+
1835 nmethods
= read_objc_methlist_nmethods (mlist
);
1837 for (i
= 0; i
< nmethods
; i
++)
1839 struct objc_method meth_str
;
1840 read_objc_methlist_method (mlist
, i
, &meth_str
);
1844 "checking method 0x%lx against selector 0x%lx\n",
1845 meth_str
.name
, sel
);
1848 if (meth_str
.name
== sel
)
1849 return CONVERT_FUNCPTR (meth_str
.imp
);
1853 subclass
= class_str
.super_class
;
1860 find_implementation (CORE_ADDR object
, CORE_ADDR sel
)
1862 struct objc_object ostr
;
1866 read_objc_object (object
, &ostr
);
1870 return find_implementation_from_class (ostr
.isa
, sel
);
1874 resolve_msgsend (CORE_ADDR pc
, CORE_ADDR
*new_pc
)
1880 object
= FETCH_ARGUMENT (0);
1881 sel
= FETCH_ARGUMENT (1);
1883 res
= find_implementation (object
, sel
);
1892 resolve_msgsend_stret (CORE_ADDR pc
, CORE_ADDR
*new_pc
)
1898 object
= FETCH_ARGUMENT (1);
1899 sel
= FETCH_ARGUMENT (2);
1901 res
= find_implementation (object
, sel
);
1910 resolve_msgsend_super (CORE_ADDR pc
, CORE_ADDR
*new_pc
)
1912 struct objc_super sstr
;
1918 super
= FETCH_ARGUMENT (0);
1919 sel
= FETCH_ARGUMENT (1);
1921 read_objc_super (super
, &sstr
);
1922 if (sstr
.class == 0)
1925 res
= find_implementation_from_class (sstr
.class, sel
);
1934 resolve_msgsend_super_stret (CORE_ADDR pc
, CORE_ADDR
*new_pc
)
1936 struct objc_super sstr
;
1942 super
= FETCH_ARGUMENT (1);
1943 sel
= FETCH_ARGUMENT (2);
1945 read_objc_super (super
, &sstr
);
1946 if (sstr
.class == 0)
1949 res
= find_implementation_from_class (sstr
.class, sel
);