1 /* Objective-C language support routines for GDB, the GNU debugger.
3 Copyright 2002 Free Software Foundation, Inc.
5 Contributed by Apple Computer, Inc.
6 Written by Michael Snyder.
8 This file is part of GDB.
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place - Suite 330,
23 Boston, MA 02111-1307, USA. */
28 #include "expression.h"
29 #include "parser-defs.h"
32 #include "objc-lang.h"
33 #include "complaints.h"
37 #include "string.h" /* for strchr */
38 #include "target.h" /* for target_has_execution */
42 #include "gdb_regex.h"
53 CORE_ADDR super_class
;
75 /* Complaints about ObjC classes, selectors, etc. */
77 static struct complaint noclass_lookup_complaint
= {
78 "no way to lookup Objective-C classes", 0, 0
81 static struct complaint nosel_lookup_complaint
= {
82 "no way to lookup Objective-C selectors", 0, 0
86 #if (!defined __GNUC__ || __GNUC__ < 2 || __GNUC_MINOR__ < (defined __cplusplus ? 6 : 4))
87 #define __CHECK_FUNCTION ((__const char *) 0)
89 #define __CHECK_FUNCTION __PRETTY_FUNCTION__
92 #define CHECK(expression) \
93 ((void) ((expression) ? 0 : gdb_check (#expression, __FILE__, __LINE__, \
96 #define CHECK_FATAL(expression) \
97 ((void) ((expression) ? 0 : gdb_check_fatal (#expression, __FILE__, \
98 __LINE__, __CHECK_FUNCTION)))
101 gdb_check (const char *str
, const char *file
,
102 unsigned int line
, const char *func
)
104 error ("assertion failure on line %u of \"%s\" in function \"%s\": %s\n",
105 line
, file
, func
, str
);
109 gdb_check_fatal (const char *str
, const char *file
,
110 unsigned int line
, const char *func
)
112 internal_error (file
, line
,
113 "assertion failure in function \"%s\": %s\n", func
, str
);
116 /* Lookup a structure type named "struct NAME", visible in lexical
117 block BLOCK. If NOERR is nonzero, return zero if NAME is not
121 lookup_struct_typedef (char *name
, struct block
*block
, int noerr
)
123 register struct symbol
*sym
;
125 sym
= lookup_symbol (name
, block
, STRUCT_NAMESPACE
, 0,
126 (struct symtab
**) NULL
);
133 error ("No struct type named %s.", name
);
135 if (TYPE_CODE (SYMBOL_TYPE (sym
)) != TYPE_CODE_STRUCT
)
140 error ("This context has class, union or enum %s, not a struct.",
147 lookup_objc_class (char *classname
)
149 struct value
* function
, *classval
;
151 if (! target_has_execution
)
153 /* Can't call into inferior to lookup class. */
157 if (lookup_minimal_symbol("objc_lookUpClass", 0, 0))
158 function
= find_function_in_inferior("objc_lookUpClass");
159 else if (lookup_minimal_symbol ("objc_lookup_class", 0, 0))
160 function
= find_function_in_inferior("objc_lookup_class");
163 complain (&noclass_lookup_complaint
, 0);
167 classval
= value_string (classname
, strlen (classname
) + 1);
168 classval
= value_coerce_array (classval
);
169 return (CORE_ADDR
) value_as_long (call_function_by_hand (function
,
174 lookup_child_selector (char *selname
)
176 struct value
* function
, *selstring
;
178 if (! target_has_execution
)
180 /* Can't call into inferior to lookup selector. */
184 if (lookup_minimal_symbol("sel_getUid", 0, 0))
185 function
= find_function_in_inferior("sel_getUid");
186 else if (lookup_minimal_symbol ("sel_get_any_uid", 0, 0))
187 function
= find_function_in_inferior("sel_get_any_uid");
190 complain (&nosel_lookup_complaint
, 0);
194 selstring
= value_coerce_array (value_string (selname
,
195 strlen (selname
) + 1));
196 return value_as_long (call_function_by_hand (function
, 1, &selstring
));
200 value_nsstring (char *ptr
, int len
)
202 struct value
*stringValue
[3];
203 struct value
*function
, *nsstringValue
;
207 if (!target_has_execution
)
208 return 0; /* Can't call into inferior to create NSString. */
210 if (!(sym
= lookup_struct_typedef("NSString", 0, 1)) &&
211 !(sym
= lookup_struct_typedef("NXString", 0, 1)))
212 type
= lookup_pointer_type(builtin_type_void
);
214 type
= lookup_pointer_type(SYMBOL_TYPE (sym
));
216 stringValue
[2] = value_string(ptr
, len
);
217 stringValue
[2] = value_coerce_array(stringValue
[2]);
218 /* _NSNewStringFromCString replaces "istr" after Lantern2A. */
219 if (lookup_minimal_symbol("_NSNewStringFromCString", 0, 0))
221 function
= find_function_in_inferior("_NSNewStringFromCString");
222 nsstringValue
= call_function_by_hand(function
, 1, &stringValue
[2]);
224 else if (lookup_minimal_symbol("istr", 0, 0))
226 function
= find_function_in_inferior("istr");
227 nsstringValue
= call_function_by_hand(function
, 1, &stringValue
[2]);
229 else if (lookup_minimal_symbol("+[NSString stringWithCString:]", 0, 0))
231 function
= find_function_in_inferior("+[NSString stringWithCString:]");
232 stringValue
[0] = value_from_longest
233 (builtin_type_long
, lookup_objc_class ("NSString"));
234 stringValue
[1] = value_from_longest
235 (builtin_type_long
, lookup_child_selector ("stringWithCString:"));
236 nsstringValue
= call_function_by_hand(function
, 3, &stringValue
[0]);
239 error ("NSString: internal error -- no way to create new NSString");
241 VALUE_TYPE(nsstringValue
) = type
;
242 return nsstringValue
;
245 /* Objective-C name demangling. */
248 objc_demangle (const char *mangled
)
250 char *demangled
, *cp
;
252 if (mangled
[0] == '_' &&
253 (mangled
[1] == 'i' || mangled
[1] == 'c') &&
256 cp
= demangled
= xmalloc(strlen(mangled
) + 2);
258 if (mangled
[1] == 'i')
259 *cp
++ = '-'; /* for instance method */
261 *cp
++ = '+'; /* for class method */
263 *cp
++ = '['; /* opening left brace */
264 strcpy(cp
, mangled
+3); /* tack on the rest of the mangled name */
266 while (*cp
&& *cp
== '_')
267 cp
++; /* skip any initial underbars in class name */
269 if (!(cp
= strchr(cp
, '_'))) /* find first non-initial underbar */
271 free(demangled
); /* not mangled name */
274 if (cp
[1] == '_') { /* easy case: no category name */
275 *cp
++ = ' '; /* replace two '_' with one ' ' */
276 strcpy(cp
, mangled
+ (cp
- demangled
) + 2);
279 *cp
++ = '('; /* less easy case: category name */
280 if (!(cp
= strchr(cp
, '_')))
282 free(demangled
); /* not mangled name */
286 *cp
++ = ' '; /* overwriting 1st char of method name... */
287 strcpy(cp
, mangled
+ (cp
- demangled
)); /* get it back */
290 while (*cp
&& *cp
== '_')
291 cp
++; /* skip any initial underbars in method name */
295 *cp
= ':'; /* replace remaining '_' with ':' */
297 *cp
++ = ']'; /* closing right brace */
298 *cp
++ = 0; /* string terminator */
302 return NULL
; /* Not an objc mangled name. */
305 /* Print the character C on STREAM as part of the contents of a
306 literal string whose delimiter is QUOTER. Note that that format
307 for printing characters and strings is language specific. */
310 objc_emit_char (register int c
, struct ui_file
*stream
, int quoter
)
313 c
&= 0xFF; /* Avoid sign bit follies. */
315 if (PRINT_LITERAL_FORM (c
))
317 if (c
== '\\' || c
== quoter
)
319 fputs_filtered ("\\", stream
);
321 fprintf_filtered (stream
, "%c", c
);
328 fputs_filtered ("\\n", stream
);
331 fputs_filtered ("\\b", stream
);
334 fputs_filtered ("\\t", stream
);
337 fputs_filtered ("\\f", stream
);
340 fputs_filtered ("\\r", stream
);
343 fputs_filtered ("\\e", stream
);
346 fputs_filtered ("\\a", stream
);
349 fprintf_filtered (stream
, "\\%.3o", (unsigned int) c
);
356 objc_printchar (int c
, struct ui_file
*stream
)
358 fputs_filtered ("'", stream
);
359 objc_emit_char (c
, stream
, '\'');
360 fputs_filtered ("'", stream
);
363 /* Print the character string STRING, printing at most LENGTH
364 characters. Printing stops early if the number hits print_max;
365 repeat counts are printed as appropriate. Print ellipses at the
366 end if we had to stop before printing LENGTH characters, or if
370 objc_printstr (struct ui_file
*stream
, char *string
,
371 unsigned int length
, int force_ellipses
)
373 register unsigned int i
;
374 unsigned int things_printed
= 0;
377 extern int inspect_it
;
378 extern int repeat_count_threshold
;
379 extern int print_max
;
381 /* If the string was not truncated due to `set print elements', and
382 the last byte of it is a null, we don't print that, in
383 traditional C style. */
384 if ((!force_ellipses
) && length
> 0 && string
[length
-1] == '\0')
389 fputs_filtered ("\"\"", stream
);
393 for (i
= 0; i
< length
&& things_printed
< print_max
; ++i
)
395 /* Position of the character we are examining to see whether it
398 /* Number of repetitions we have detected so far. */
405 fputs_filtered (", ", stream
);
411 while (rep1
< length
&& string
[rep1
] == string
[i
])
417 if (reps
> repeat_count_threshold
)
422 fputs_filtered ("\\\", ", stream
);
424 fputs_filtered ("\", ", stream
);
427 objc_printchar (string
[i
], stream
);
428 fprintf_filtered (stream
, " <repeats %u times>", reps
);
430 things_printed
+= repeat_count_threshold
;
438 fputs_filtered ("\\\"", stream
);
440 fputs_filtered ("\"", stream
);
443 objc_emit_char (string
[i
], stream
, '"');
448 /* Terminate the quotes if necessary. */
452 fputs_filtered ("\\\"", stream
);
454 fputs_filtered ("\"", stream
);
457 if (force_ellipses
|| i
< length
)
458 fputs_filtered ("...", stream
);
461 /* Create a fundamental C type using default reasonable for the
464 Some object/debugging file formats (DWARF version 1, COFF, etc) do
465 not define fundamental types such as "int" or "double". Others
466 (stabs or DWARF version 2, etc) do define fundamental types. For
467 the formats which don't provide fundamental types, gdb can create
468 such types using this function.
470 FIXME: Some compilers distinguish explicitly signed integral types
471 (signed short, signed int, signed long) from "regular" integral
472 types (short, int, long) in the debugging information. There is
473 some disagreement as to how useful this feature is. In particular,
474 gcc does not support this. Also, only some debugging formats allow
475 the distinction to be passed on to a debugger. For now, we always
476 just use "short", "int", or "long" as the type name, for both the
477 implicit and explicitly signed types. This also makes life easier
478 for the gdb test suite since we don't have to account for the
479 differences in output depending upon what the compiler and
480 debugging format support. We will probably have to re-examine the
481 issue when gdb starts taking it's fundamental type information
482 directly from the debugging information supplied by the compiler.
486 objc_create_fundamental_type (struct objfile
*objfile
, int typeid)
488 register struct type
*type
= NULL
;
493 /* FIXME: For now, if we are asked to produce a type not in
494 this language, create the equivalent of a C integer type
495 with the name "<?type?>". When all the dust settles from
496 the type reconstruction work, this should probably become
498 type
= init_type (TYPE_CODE_INT
,
499 TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
500 0, "<?type?>", objfile
);
501 warning ("internal error: no C/C++ fundamental type %d", typeid);
504 type
= init_type (TYPE_CODE_VOID
,
505 TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
509 type
= init_type (TYPE_CODE_INT
,
510 TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
514 type
= init_type (TYPE_CODE_INT
,
515 TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
516 0, "signed char", objfile
);
518 case FT_UNSIGNED_CHAR
:
519 type
= init_type (TYPE_CODE_INT
,
520 TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
521 TYPE_FLAG_UNSIGNED
, "unsigned char", objfile
);
524 type
= init_type (TYPE_CODE_INT
,
525 TARGET_SHORT_BIT
/ TARGET_CHAR_BIT
,
526 0, "short", objfile
);
528 case FT_SIGNED_SHORT
:
529 type
= init_type (TYPE_CODE_INT
,
530 TARGET_SHORT_BIT
/ TARGET_CHAR_BIT
,
531 0, "short", objfile
); /* FIXME-fnf */
533 case FT_UNSIGNED_SHORT
:
534 type
= init_type (TYPE_CODE_INT
,
535 TARGET_SHORT_BIT
/ TARGET_CHAR_BIT
,
536 TYPE_FLAG_UNSIGNED
, "unsigned short", objfile
);
539 type
= init_type (TYPE_CODE_INT
,
540 TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
543 case FT_SIGNED_INTEGER
:
544 type
= init_type (TYPE_CODE_INT
,
545 TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
546 0, "int", objfile
); /* FIXME -fnf */
548 case FT_UNSIGNED_INTEGER
:
549 type
= init_type (TYPE_CODE_INT
,
550 TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
551 TYPE_FLAG_UNSIGNED
, "unsigned int", objfile
);
554 type
= init_type (TYPE_CODE_INT
,
555 TARGET_LONG_BIT
/ TARGET_CHAR_BIT
,
559 type
= init_type (TYPE_CODE_INT
,
560 TARGET_LONG_BIT
/ TARGET_CHAR_BIT
,
561 0, "long", objfile
); /* FIXME -fnf */
563 case FT_UNSIGNED_LONG
:
564 type
= init_type (TYPE_CODE_INT
,
565 TARGET_LONG_BIT
/ TARGET_CHAR_BIT
,
566 TYPE_FLAG_UNSIGNED
, "unsigned long", objfile
);
569 type
= init_type (TYPE_CODE_INT
,
570 TARGET_LONG_LONG_BIT
/ TARGET_CHAR_BIT
,
571 0, "long long", objfile
);
573 case FT_SIGNED_LONG_LONG
:
574 type
= init_type (TYPE_CODE_INT
,
575 TARGET_LONG_LONG_BIT
/ TARGET_CHAR_BIT
,
576 0, "signed long long", objfile
);
578 case FT_UNSIGNED_LONG_LONG
:
579 type
= init_type (TYPE_CODE_INT
,
580 TARGET_LONG_LONG_BIT
/ TARGET_CHAR_BIT
,
581 TYPE_FLAG_UNSIGNED
, "unsigned long long", objfile
);
584 type
= init_type (TYPE_CODE_FLT
,
585 TARGET_FLOAT_BIT
/ TARGET_CHAR_BIT
,
586 0, "float", objfile
);
588 case FT_DBL_PREC_FLOAT
:
589 type
= init_type (TYPE_CODE_FLT
,
590 TARGET_DOUBLE_BIT
/ TARGET_CHAR_BIT
,
591 0, "double", objfile
);
593 case FT_EXT_PREC_FLOAT
:
594 type
= init_type (TYPE_CODE_FLT
,
595 TARGET_LONG_DOUBLE_BIT
/ TARGET_CHAR_BIT
,
596 0, "long double", objfile
);
603 /* Table mapping opcodes into strings for printing operators
604 and precedences of the operators. */
606 static const struct op_print objc_op_print_tab
[] =
608 {",", BINOP_COMMA
, PREC_COMMA
, 0},
609 {"=", BINOP_ASSIGN
, PREC_ASSIGN
, 1},
610 {"||", BINOP_LOGICAL_OR
, PREC_LOGICAL_OR
, 0},
611 {"&&", BINOP_LOGICAL_AND
, PREC_LOGICAL_AND
, 0},
612 {"|", BINOP_BITWISE_IOR
, PREC_BITWISE_IOR
, 0},
613 {"^", BINOP_BITWISE_XOR
, PREC_BITWISE_XOR
, 0},
614 {"&", BINOP_BITWISE_AND
, PREC_BITWISE_AND
, 0},
615 {"==", BINOP_EQUAL
, PREC_EQUAL
, 0},
616 {"!=", BINOP_NOTEQUAL
, PREC_EQUAL
, 0},
617 {"<=", BINOP_LEQ
, PREC_ORDER
, 0},
618 {">=", BINOP_GEQ
, PREC_ORDER
, 0},
619 {">", BINOP_GTR
, PREC_ORDER
, 0},
620 {"<", BINOP_LESS
, PREC_ORDER
, 0},
621 {">>", BINOP_RSH
, PREC_SHIFT
, 0},
622 {"<<", BINOP_LSH
, PREC_SHIFT
, 0},
623 {"+", BINOP_ADD
, PREC_ADD
, 0},
624 {"-", BINOP_SUB
, PREC_ADD
, 0},
625 {"*", BINOP_MUL
, PREC_MUL
, 0},
626 {"/", BINOP_DIV
, PREC_MUL
, 0},
627 {"%", BINOP_REM
, PREC_MUL
, 0},
628 {"@", BINOP_REPEAT
, PREC_REPEAT
, 0},
629 {"-", UNOP_NEG
, PREC_PREFIX
, 0},
630 {"!", UNOP_LOGICAL_NOT
, PREC_PREFIX
, 0},
631 {"~", UNOP_COMPLEMENT
, PREC_PREFIX
, 0},
632 {"*", UNOP_IND
, PREC_PREFIX
, 0},
633 {"&", UNOP_ADDR
, PREC_PREFIX
, 0},
634 {"sizeof ", UNOP_SIZEOF
, PREC_PREFIX
, 0},
635 {"++", UNOP_PREINCREMENT
, PREC_PREFIX
, 0},
636 {"--", UNOP_PREDECREMENT
, PREC_PREFIX
, 0},
640 struct type
** const (objc_builtin_types
[]) =
647 &builtin_type_double
,
649 &builtin_type_long_long
,
650 &builtin_type_signed_char
,
651 &builtin_type_unsigned_char
,
652 &builtin_type_unsigned_short
,
653 &builtin_type_unsigned_int
,
654 &builtin_type_unsigned_long
,
655 &builtin_type_unsigned_long_long
,
656 &builtin_type_long_double
,
657 &builtin_type_complex
,
658 &builtin_type_double_complex
,
662 const struct language_defn objc_language_defn
= {
663 "objective-c", /* Language name */
671 evaluate_subexp_standard
,
672 objc_printchar
, /* Print a character constant */
673 objc_printstr
, /* Function to print string constant */
675 objc_create_fundamental_type
, /* Create fundamental type in this language */
676 c_print_type
, /* Print a type using appropriate syntax */
677 c_val_print
, /* Print a value using appropriate syntax */
678 c_value_print
, /* Print a top-level value */
679 {"", "", "", ""}, /* Binary format info */
680 {"0%lo", "0", "o", ""}, /* Octal format info */
681 {"%ld", "", "d", ""}, /* Decimal format info */
682 {"0x%lx", "0x", "x", ""}, /* Hex format info */
683 objc_op_print_tab
, /* Expression operators for printing */
684 1, /* C-style arrays */
685 0, /* String lower bound */
686 &builtin_type_char
, /* Type of string elements */
692 * Following functions help construct Objective-C message calls
695 struct selname
/* For parsing Objective-C. */
697 struct selname
*next
;
702 static int msglist_len
;
703 static struct selname
*selname_chain
;
704 static char *msglist_sel
;
709 register struct selname
*new =
710 (struct selname
*) xmalloc (sizeof (struct selname
));
712 new->next
= selname_chain
;
713 new->msglist_len
= msglist_len
;
714 new->msglist_sel
= msglist_sel
;
716 msglist_sel
= (char *)xmalloc(1);
722 add_msglist(struct stoken
*str
, int addcolon
)
727 if (str
== 0) { /* Unnamed arg, or... */
728 if (addcolon
== 0) { /* variable number of args. */
738 len
= plen
+ strlen(msglist_sel
) + 2;
739 s
= (char *)xmalloc(len
);
740 strcpy(s
, msglist_sel
);
755 register int val
= msglist_len
;
756 register struct selname
*sel
= selname_chain
;
757 register char *p
= msglist_sel
;
760 selname_chain
= sel
->next
;
761 msglist_len
= sel
->msglist_len
;
762 msglist_sel
= sel
->msglist_sel
;
763 selid
= lookup_child_selector(p
);
765 error("Can't find selector \"%s\"", p
);
766 write_exp_elt_longcst (selid
);
768 write_exp_elt_longcst (val
); /* Number of args */
775 * Function: specialcmp (char *a, char *b)
777 * Special strcmp: treats ']' and ' ' as end-of-string.
778 * Used for qsorting lists of objc methods (either by class or selector).
781 int specialcmp(char *a
, char *b
)
783 while (*a
&& *a
!= ' ' && *a
!= ']' && *b
&& *b
!= ' ' && *b
!= ']')
789 if (*a
&& *a
!= ' ' && *a
!= ']')
790 return 1; /* a is longer therefore greater */
791 if (*b
&& *b
!= ' ' && *b
!= ']')
792 return -1; /* a is shorter therefore lesser */
793 return 0; /* a and b are identical */
797 * Function: compare_selectors (void *, void *)
799 * Comparison function for use with qsort. Arguments are symbols or
800 * msymbols Compares selector part of objc method name alphabetically.
804 compare_selectors (void *a
, void *b
)
808 if ((aname
= SYMBOL_SOURCE_NAME (*(struct symbol
**) a
)) == NULL
||
809 (bname
= SYMBOL_SOURCE_NAME (*(struct symbol
**) b
)) == NULL
)
810 error ("internal: compare_selectors(1)");
812 if ((aname
= strchr(aname
, ' ')) == NULL
||
813 (bname
= strchr(bname
, ' ')) == NULL
)
814 error ("internal: compare_selectors(2)");
816 return specialcmp (aname
+1, bname
+1);
820 * Function: selectors_info (regexp, from_tty)
822 * Implements the "Info selectors" command. Takes an optional regexp
823 * arg. Lists all objective c selectors that match the regexp. Works
824 * by grepping thru all symbols for objective c methods. Output list
825 * is sorted and uniqued.
829 selectors_info (char *regexp
, int from_tty
)
831 struct objfile
*objfile
;
832 struct minimal_symbol
*msymbol
;
840 struct symbol
**sym_arr
;
844 strcpy(myregexp
, ".*]"); /* Null input, match all objc methods. */
847 if (*regexp
== '+' || *regexp
== '-')
848 { /* User wants only class methods or only instance methods. */
849 plusminus
= *regexp
++;
850 while (*regexp
== ' ' || *regexp
== '\t')
854 strcpy(myregexp
, ".*]");
857 strcpy(myregexp
, regexp
);
858 if (myregexp
[strlen(myregexp
) - 1] == '$') /* end of selector */
859 myregexp
[strlen(myregexp
) - 1] = ']'; /* end of method name */
861 strcat(myregexp
, ".*]");
866 if (0 != (val
= re_comp (myregexp
)))
867 error ("Invalid regexp (%s): %s", val
, regexp
);
869 /* First time thru is JUST to get max length and count. */
870 ALL_MSYMBOLS (objfile
, msymbol
)
873 if ((name
= SYMBOL_DEMANGLED_NAME (msymbol
)) == NULL
)
874 name
= SYMBOL_NAME (msymbol
);
876 (name
[0] == '-' || name
[0] == '+') &&
877 name
[1] == '[') /* Got a method name. */
879 /* Filter for class/instance methods. */
880 if (plusminus
&& name
[0] != plusminus
)
882 /* Find selector part. */
883 name
= (char *) strchr(name
+2, ' ');
884 if (regexp
== NULL
|| re_exec(++name
) != 0)
886 char *mystart
= name
;
887 char *myend
= (char *) strchr(mystart
, ']');
889 if (myend
&& (myend
- mystart
> maxlen
))
890 maxlen
= myend
- mystart
; /* Get longest selector. */
897 printf_filtered ("Selectors matching \"%s\":\n\n",
898 regexp
? regexp
: "*");
900 sym_arr
= alloca (matches
* sizeof (struct symbol
*));
902 ALL_MSYMBOLS (objfile
, msymbol
)
905 if ((name
= SYMBOL_DEMANGLED_NAME (msymbol
)) == NULL
)
906 name
= SYMBOL_NAME (msymbol
);
908 (name
[0] == '-' || name
[0] == '+') &&
909 name
[1] == '[') /* Got a method name. */
911 /* Filter for class/instance methods. */
912 if (plusminus
&& name
[0] != plusminus
)
914 /* Find selector part. */
915 name
= (char *) strchr(name
+2, ' ');
916 if (regexp
== NULL
|| re_exec(++name
) != 0)
917 sym_arr
[matches
++] = (struct symbol
*) msymbol
;
921 qsort (sym_arr
, matches
, sizeof (struct minimal_symbol
*),
923 /* Prevent compare on first iteration. */
925 for (ix
= 0; ix
< matches
; ix
++) /* Now do the output. */
930 if ((name
= SYMBOL_DEMANGLED_NAME (sym_arr
[ix
])) == NULL
)
931 name
= SYMBOL_NAME (sym_arr
[ix
]);
932 name
= strchr (name
, ' ') + 1;
933 if (p
[0] && specialcmp(name
, p
) == 0)
934 continue; /* Seen this one already (not unique). */
936 /* Copy selector part. */
937 while (*name
&& *name
!= ']')
940 /* Print in columns. */
941 puts_filtered_tabular(asel
, maxlen
+ 1, 0);
946 printf_filtered ("No selectors matching \"%s\"\n", regexp
? regexp
: "*");
950 * Function: compare_classes (void *, void *)
952 * Comparison function for use with qsort. Arguments are symbols or
953 * msymbols Compares class part of objc method name alphabetically.
957 compare_classes (void *a
, void *b
)
961 if ((aname
= SYMBOL_SOURCE_NAME (*(struct symbol
**) a
)) == NULL
||
962 (bname
= SYMBOL_SOURCE_NAME (*(struct symbol
**) b
)) == NULL
)
963 error ("internal: compare_classes(1)");
965 return specialcmp (aname
+1, bname
+1);
969 * Function: classes_info(regexp, from_tty)
971 * Implements the "info classes" command for objective c classes.
972 * Lists all objective c classes that match the optional regexp.
973 * Works by grepping thru the list of objective c methods. List will
974 * be sorted and uniqued (since one class may have many methods).
975 * BUGS: will not list a class that has no methods.
979 classes_info (char *regexp
, int from_tty
)
981 struct objfile
*objfile
;
982 struct minimal_symbol
*msymbol
;
990 struct symbol
**sym_arr
;
993 strcpy(myregexp
, ".* "); /* Null input: match all objc classes. */
996 strcpy(myregexp
, regexp
);
997 if (myregexp
[strlen(myregexp
) - 1] == '$')
998 /* In the method name, the end of the class name is marked by ' '. */
999 myregexp
[strlen(myregexp
) - 1] = ' ';
1001 strcat(myregexp
, ".* ");
1005 if (0 != (val
= re_comp (myregexp
)))
1006 error ("Invalid regexp (%s): %s", val
, regexp
);
1008 /* First time thru is JUST to get max length and count. */
1009 ALL_MSYMBOLS (objfile
, msymbol
)
1012 if ((name
= SYMBOL_DEMANGLED_NAME (msymbol
)) == NULL
)
1013 name
= SYMBOL_NAME (msymbol
);
1015 (name
[0] == '-' || name
[0] == '+') &&
1016 name
[1] == '[') /* Got a method name. */
1017 if (regexp
== NULL
|| re_exec(name
+2) != 0)
1019 /* Compute length of classname part. */
1020 char *mystart
= name
+ 2;
1021 char *myend
= (char *) strchr(mystart
, ' ');
1023 if (myend
&& (myend
- mystart
> maxlen
))
1024 maxlen
= myend
- mystart
;
1030 printf_filtered ("Classes matching \"%s\":\n\n",
1031 regexp
? regexp
: "*");
1032 sym_arr
= alloca (matches
* sizeof (struct symbol
*));
1034 ALL_MSYMBOLS (objfile
, msymbol
)
1037 if ((name
= SYMBOL_DEMANGLED_NAME (msymbol
)) == NULL
)
1038 name
= SYMBOL_NAME (msymbol
);
1040 (name
[0] == '-' || name
[0] == '+') &&
1041 name
[1] == '[') /* Got a method name. */
1042 if (regexp
== NULL
|| re_exec(name
+2) != 0)
1043 sym_arr
[matches
++] = (struct symbol
*) msymbol
;
1046 qsort (sym_arr
, matches
, sizeof (struct minimal_symbol
*),
1048 /* Prevent compare on first iteration. */
1050 for (ix
= 0; ix
< matches
; ix
++) /* Now do the output. */
1055 if ((name
= SYMBOL_DEMANGLED_NAME (sym_arr
[ix
])) == NULL
)
1056 name
= SYMBOL_NAME (sym_arr
[ix
]);
1058 if (p
[0] && specialcmp(name
, p
) == 0)
1059 continue; /* Seen this one already (not unique). */
1061 /* Copy class part of method name. */
1062 while (*name
&& *name
!= ' ')
1065 /* Print in columns. */
1066 puts_filtered_tabular(aclass
, maxlen
+ 1, 0);
1071 printf_filtered ("No classes matching \"%s\"\n", regexp
? regexp
: "*");
1075 * Function: find_imps (char *selector, struct symbol **sym_arr)
1077 * Input: a string representing a selector
1078 * a pointer to an array of symbol pointers
1079 * possibly a pointer to a symbol found by the caller.
1081 * Output: number of methods that implement that selector. Side
1082 * effects: The array of symbol pointers is filled with matching syms.
1084 * By analogy with function "find_methods" (symtab.c), builds a list
1085 * of symbols matching the ambiguous input, so that "decode_line_2"
1086 * (symtab.c) can list them and ask the user to choose one or more.
1087 * In this case the matches are objective c methods
1088 * ("implementations") matching an objective c selector.
1090 * Note that it is possible for a normal (c-style) function to have
1091 * the same name as an objective c selector. To prevent the selector
1092 * from eclipsing the function, we allow the caller (decode_line_1) to
1093 * search for such a function first, and if it finds one, pass it in
1094 * to us. We will then integrate it into the list. We also search
1095 * for one here, among the minsyms.
1097 * NOTE: if NUM_DEBUGGABLE is non-zero, the sym_arr will be divided
1098 * into two parts: debuggable (struct symbol) syms, and
1099 * non_debuggable (struct minimal_symbol) syms. The debuggable
1100 * ones will come first, before NUM_DEBUGGABLE (which will thus
1101 * be the index of the first non-debuggable one).
1105 * Function: total_number_of_imps (char *selector);
1107 * Input: a string representing a selector
1108 * Output: number of methods that implement that selector.
1110 * By analogy with function "total_number_of_methods", this allows
1111 * decode_line_1 (symtab.c) to detect if there are objective c methods
1112 * matching the input, and to allocate an array of pointers to them
1113 * which can be manipulated by "decode_line_2" (also in symtab.c).
1117 parse_selector (char *method
, char **selector
)
1121 int found_quote
= 0;
1123 char *nselector
= NULL
;
1125 CHECK (selector
!= NULL
);
1129 while (isspace (*s1
))
1136 while (isspace (*s1
))
1143 if (isalnum (*s2
) || (*s2
== '_') || (*s2
== ':'))
1145 else if (isspace (*s2
))
1147 else if ((*s2
== '\0') || (*s2
== '\''))
1155 while (isspace (*s2
))
1161 while (isspace (*s2
))
1165 if (selector
!= NULL
)
1166 *selector
= nselector
;
1172 parse_method (char *method
, char *type
, char **class,
1173 char **category
, char **selector
)
1177 int found_quote
= 0;
1180 char *nclass
= NULL
;
1181 char *ncategory
= NULL
;
1182 char *nselector
= NULL
;
1184 CHECK (type
!= NULL
);
1185 CHECK (class != NULL
);
1186 CHECK (category
!= NULL
);
1187 CHECK (selector
!= NULL
);
1191 while (isspace (*s1
))
1198 while (isspace (*s1
))
1201 if ((s1
[0] == '+') || (s1
[0] == '-'))
1204 while (isspace (*s1
))
1212 while (isalnum (*s1
) || (*s1
== '_'))
1216 while (isspace (*s2
))
1222 while (isspace (*s2
))
1225 while (isalnum (*s2
) || (*s2
== '_'))
1230 /* Truncate the class name now that we're not using the open paren. */
1237 if (isalnum (*s2
) || (*s2
== '_') || (*s2
== ':'))
1239 else if (isspace (*s2
))
1241 else if (*s2
== ']')
1250 while (isspace (*s2
))
1257 while (isspace (*s2
))
1265 if (category
!= NULL
)
1266 *category
= ncategory
;
1267 if (selector
!= NULL
)
1268 *selector
= nselector
;
1274 find_methods (struct symtab
*symtab
, char type
,
1275 const char *class, const char *category
,
1276 const char *selector
, struct symbol
**syms
,
1277 unsigned int *nsym
, unsigned int *ndebug
)
1279 struct objfile
*objfile
= NULL
;
1280 struct minimal_symbol
*msymbol
= NULL
;
1281 struct block
*block
= NULL
;
1282 struct symbol
*sym
= NULL
;
1284 char *symname
= NULL
;
1287 char *nclass
= NULL
;
1288 char *ncategory
= NULL
;
1289 char *nselector
= NULL
;
1291 unsigned int csym
= 0;
1292 unsigned int cdebug
= 0;
1294 static char *tmp
= NULL
;
1295 static unsigned int tmplen
= 0;
1297 CHECK (nsym
!= NULL
);
1298 CHECK (ndebug
!= NULL
);
1301 block
= BLOCKVECTOR_BLOCK (BLOCKVECTOR (symtab
), STATIC_BLOCK
);
1303 ALL_MSYMBOLS (objfile
, msymbol
)
1307 if ((msymbol
->type
!= mst_text
) && (msymbol
->type
!= mst_file_text
))
1308 /* Not a function or method. */
1312 if ((SYMBOL_VALUE_ADDRESS (msymbol
) < block
->startaddr
) ||
1313 (SYMBOL_VALUE_ADDRESS (msymbol
) >= block
->endaddr
))
1314 /* Not in the specified symtab. */
1317 symname
= SYMBOL_DEMANGLED_NAME (msymbol
);
1318 if (symname
== NULL
)
1319 symname
= SYMBOL_NAME (msymbol
);
1320 if (symname
== NULL
)
1323 if ((symname
[0] != '-' && symname
[0] != '+') || (symname
[1] != '['))
1324 /* Not a method name. */
1327 while ((strlen (symname
) + 1) >= tmplen
)
1329 tmplen
= (tmplen
== 0) ? 1024 : tmplen
* 2;
1330 tmp
= xrealloc (tmp
, tmplen
);
1332 strcpy (tmp
, symname
);
1334 if (parse_method (tmp
, &ntype
, &nclass
, &ncategory
, &nselector
) == NULL
)
1337 if ((type
!= '\0') && (ntype
!= type
))
1341 && ((nclass
== NULL
) || (strcmp (class, nclass
) != 0)))
1344 if ((category
!= NULL
) &&
1345 ((ncategory
== NULL
) || (strcmp (category
, ncategory
) != 0)))
1348 if ((selector
!= NULL
) &&
1349 ((nselector
== NULL
) || (strcmp (selector
, nselector
) != 0)))
1352 sym
= find_pc_function (SYMBOL_VALUE_ADDRESS (msymbol
));
1355 const char *newsymname
= SYMBOL_DEMANGLED_NAME (sym
);
1357 if (newsymname
== NULL
)
1358 newsymname
= SYMBOL_NAME (sym
);
1359 if (strcmp (symname
, newsymname
) == 0)
1361 /* Found a high-level method sym: swap it into the
1362 lower part of sym_arr (below num_debuggable). */
1365 syms
[csym
] = syms
[cdebug
];
1374 "debugging symbol \"%s\" does not match minimal symbol (\"%s\"); ignoring",
1375 newsymname
, symname
);
1377 syms
[csym
] = (struct symbol
*) msymbol
;
1383 /* Found a non-debuggable method symbol. */
1385 syms
[csym
] = (struct symbol
*) msymbol
;
1396 char *find_imps (struct symtab
*symtab
, struct block
*block
,
1397 char *method
, struct symbol
**syms
,
1398 unsigned int *nsym
, unsigned int *ndebug
)
1402 char *category
= NULL
;
1403 char *selector
= NULL
;
1405 unsigned int csym
= 0;
1406 unsigned int cdebug
= 0;
1408 unsigned int ncsym
= 0;
1409 unsigned int ncdebug
= 0;
1414 CHECK (nsym
!= NULL
);
1415 CHECK (ndebug
!= NULL
);
1422 buf
= (char *) alloca (strlen (method
) + 1);
1423 strcpy (buf
, method
);
1424 tmp
= parse_method (buf
, &type
, &class, &category
, &selector
);
1428 struct symtab
*sym_symtab
= NULL
;
1429 struct symbol
*sym
= NULL
;
1430 struct minimal_symbol
*msym
= NULL
;
1432 strcpy (buf
, method
);
1433 tmp
= parse_selector (buf
, &selector
);
1438 sym
= lookup_symbol (selector
, block
, VAR_NAMESPACE
, 0, &sym_symtab
);
1448 msym
= lookup_minimal_symbol (selector
, 0, 0);
1459 find_methods (symtab
, type
, class, category
, selector
,
1460 syms
+ csym
, &ncsym
, &ncdebug
);
1462 find_methods (symtab
, type
, class, category
, selector
,
1463 NULL
, &ncsym
, &ncdebug
);
1465 /* If we didn't find any methods, just return. */
1466 if (ncsym
== 0 && ncdebug
== 0)
1469 /* Take debug symbols from the second batch of symbols and swap them
1470 * with debug symbols from the first batch. Repeat until either the
1471 * second section is out of debug symbols or the first section is
1472 * full of debug symbols. Either way we have all debug symbols
1473 * packed to the beginning of the buffer.
1478 while ((cdebug
< csym
) && (ncdebug
> 0))
1480 struct symbol
*s
= NULL
;
1481 /* First non-debugging symbol. */
1482 unsigned int i
= cdebug
;
1483 /* Last of second batch of debug symbols. */
1484 unsigned int j
= csym
+ ncdebug
- 1;
1490 /* We've moved a symbol from the second debug section to the
1506 return method
+ (tmp
- buf
);
1510 /* Sort debuggable symbols. */
1512 qsort (syms
, cdebug
, sizeof (struct minimal_symbol
*),
1515 /* Sort minimal_symbols. */
1516 if ((csym
- cdebug
) > 1)
1517 qsort (&syms
[cdebug
], csym
- cdebug
,
1518 sizeof (struct minimal_symbol
*), compare_classes
);
1520 /* Terminate the sym_arr list. */
1523 return method
+ (tmp
- buf
);
1527 print_object_command (char *args
, int from_tty
)
1529 struct value
*object
, *function
, *description
;
1530 CORE_ADDR string_addr
;
1534 if (!args
|| !*args
)
1536 "The 'print-object' command requires an argument (an Objective-C object)");
1539 struct expression
*expr
= parse_expression (args
);
1540 register struct cleanup
*old_chain
=
1541 make_cleanup (free_current_contents
, &expr
);
1545 object
= expr
->language_defn
->evaluate_exp (builtin_type_void_data_ptr
,
1546 expr
, &pc
, EVAL_NORMAL
);
1548 object
= evaluate_subexp (builtin_type_void_data_ptr
,
1549 expr
, &pc
, EVAL_NORMAL
);
1551 do_cleanups (old_chain
);
1554 if (!(function
= find_function_in_inferior ("_NSPrintForDebugger")))
1555 error ("Unable to locate _NSPrintForDebugger in child process");
1557 description
= call_function_by_hand (function
, 1, &object
);
1559 if ((string_addr
= value_as_long (description
)) == 0)
1560 error ("object returns null description");
1562 read_memory (string_addr
+ i
++, &c
, 1);
1565 { /* Read and print characters up to EOS. */
1567 printf_filtered ("%c", c
);
1568 read_memory (string_addr
+ i
++, &c
, 1);
1571 printf_filtered("<object returns empty description>");
1572 printf_filtered ("\n");
1575 /* The data structure 'methcalls' is used to detect method calls (thru
1576 * ObjC runtime lib functions objc_msgSend, objc_msgSendSuper, etc.),
1577 * and ultimately find the method being called.
1580 struct objc_methcall
{
1582 /* Return instance method to be called. */
1583 CORE_ADDR (*stop_at
) (CORE_ADDR
);
1584 /* Start of pc range corresponding to method invocation. */
1586 /* End of pc range corresponding to method invocation. */
1590 static int resolve_msgsend (CORE_ADDR pc
, CORE_ADDR
*new_pc
);
1591 static int resolve_msgsend_stret (CORE_ADDR pc
, CORE_ADDR
*new_pc
);
1592 static int resolve_msgsend_super (CORE_ADDR pc
, CORE_ADDR
*new_pc
);
1593 static int resolve_msgsend_super_stret (CORE_ADDR pc
, CORE_ADDR
*new_pc
);
1595 static struct objc_methcall methcalls
[] = {
1596 { "_objc_msgSend", resolve_msgsend
, 0, 0},
1597 { "_objc_msgSend_stret", resolve_msgsend_stret
, 0, 0},
1598 { "_objc_msgSendSuper", resolve_msgsend_super
, 0, 0},
1599 { "_objc_msgSendSuper_stret", resolve_msgsend_super_stret
, 0, 0},
1600 { "_objc_getClass", NULL
, 0, 0},
1601 { "_objc_getMetaClass", NULL
, 0, 0}
1604 #define nmethcalls (sizeof (methcalls) / sizeof (methcalls[0]))
1606 /* The following function, "find_objc_msgsend", fills in the data
1607 * structure "objc_msgs" by finding the addresses of each of the
1608 * (currently four) functions that it holds (of which objc_msgSend is
1609 * the first). This must be called each time symbols are loaded, in
1610 * case the functions have moved for some reason.
1614 find_objc_msgsend (void)
1617 for (i
= 0; i
< nmethcalls
; i
++) {
1619 struct minimal_symbol
*func
;
1621 /* Try both with and without underscore. */
1622 func
= lookup_minimal_symbol (methcalls
[i
].name
, NULL
, NULL
);
1623 if ((func
== NULL
) && (methcalls
[i
].name
[0] == '_')) {
1624 func
= lookup_minimal_symbol (methcalls
[i
].name
+ 1, NULL
, NULL
);
1627 methcalls
[i
].begin
= 0;
1628 methcalls
[i
].end
= 0;
1632 methcalls
[i
].begin
= SYMBOL_VALUE_ADDRESS (func
);
1634 methcalls
[i
].end
= SYMBOL_VALUE_ADDRESS (++func
);
1635 } while (methcalls
[i
].begin
== methcalls
[i
].end
);
1639 /* find_objc_msgcall (replaces pc_off_limits)
1641 * ALL that this function now does is to determine whether the input
1642 * address ("pc") is the address of one of the Objective-C message
1643 * dispatch functions (mainly objc_msgSend or objc_msgSendSuper), and
1644 * if so, it returns the address of the method that will be called.
1646 * The old function "pc_off_limits" used to do a lot of other things
1647 * in addition, such as detecting shared library jump stubs and
1648 * returning the address of the shlib function that would be called.
1649 * That functionality has been moved into the SKIP_TRAMPOLINE_CODE and
1650 * IN_SOLIB_TRAMPOLINE macros, which are resolved in the target-
1651 * dependent modules.
1654 struct objc_submethod_helper_data
{
1655 CORE_ADDR (*f
) (CORE_ADDR
, CORE_ADDR
*);
1661 find_objc_msgcall_submethod_helper (PTR arg
)
1663 struct objc_submethod_helper_data
*s
=
1664 (struct objc_submethod_helper_data
*) arg
;
1666 if (s
->f (s
->pc
, s
->new_pc
) == 0)
1673 find_objc_msgcall_submethod (CORE_ADDR (*f
) (CORE_ADDR
, CORE_ADDR
*),
1677 struct objc_submethod_helper_data s
;
1683 if (catch_errors (find_objc_msgcall_submethod_helper
,
1685 "Unable to determine target of Objective-C method call (ignoring):\n",
1686 RETURN_MASK_ALL
) == 0)
1693 find_objc_msgcall (CORE_ADDR pc
, CORE_ADDR
*new_pc
)
1697 find_objc_msgsend ();
1698 if (new_pc
!= NULL
) { *new_pc
= 0; }
1700 for (i
= 0; i
< nmethcalls
; i
++)
1701 if ((pc
>= methcalls
[i
].begin
) && (pc
< methcalls
[i
].end
))
1703 if (methcalls
[i
].stop_at
!= NULL
)
1704 return find_objc_msgcall_submethod (methcalls
[i
].stop_at
,
1714 _initialize_objc_language (void)
1716 add_language (&objc_language_defn
);
1717 add_info ("selectors", selectors_info
, /* INFO SELECTORS command. */
1718 "All Objective-C selectors, or those matching REGEXP.");
1719 add_info ("classes", classes_info
, /* INFO CLASSES command. */
1720 "All Objective-C classes, or those matching REGEXP.");
1721 add_com ("print-object", class_vars
, print_object_command
,
1722 "Ask an Objective-C object to print itself.\n");
1723 add_com_alias ("po", "print-object", class_vars
, 1);
1726 #if defined (__powerpc__) || defined (__ppc__)
1727 static unsigned long FETCH_ARGUMENT (int i
)
1729 return read_register (3 + i
);
1731 #elif defined (__i386__)
1732 static unsigned long FETCH_ARGUMENT (int i
)
1734 CORE_ADDR stack
= read_register (SP_REGNUM
);
1735 return read_memory_unsigned_integer (stack
+ (4 * (i
+ 1)), 4);
1737 #elif defined (__sparc__)
1738 static unsigned long FETCH_ARGUMENT (int i
)
1740 return read_register (O0_REGNUM
+ i
);
1742 #elif defined (__hppa__) || defined (__hppa)
1743 static unsigned long FETCH_ARGUMENT (int i
)
1745 return read_register (R0_REGNUM
+ 26 - i
);
1748 #error unknown architecture
1751 #if defined (__hppa__) || defined (__hppa)
1752 static CORE_ADDR
CONVERT_FUNCPTR (CORE_ADDR pc
)
1755 pc
= (CORE_ADDR
) read_memory_integer (pc
& ~0x3, 4);
1760 static CORE_ADDR
CONVERT_FUNCPTR (CORE_ADDR pc
)
1767 read_objc_method (CORE_ADDR addr
, struct objc_method
*method
)
1769 method
->name
= read_memory_unsigned_integer (addr
+ 0, 4);
1770 method
->types
= read_memory_unsigned_integer (addr
+ 4, 4);
1771 method
->imp
= read_memory_unsigned_integer (addr
+ 8, 4);
1775 unsigned long read_objc_methlist_nmethods (CORE_ADDR addr
)
1777 return read_memory_unsigned_integer (addr
+ 4, 4);
1781 read_objc_methlist_method (CORE_ADDR addr
, unsigned long num
,
1782 struct objc_method
*method
)
1784 CHECK_FATAL (num
< read_objc_methlist_nmethods (addr
));
1785 read_objc_method (addr
+ 8 + (12 * num
), method
);
1789 read_objc_object (CORE_ADDR addr
, struct objc_object
*object
)
1791 object
->isa
= read_memory_unsigned_integer (addr
, 4);
1795 read_objc_super (CORE_ADDR addr
, struct objc_super
*super
)
1797 super
->receiver
= read_memory_unsigned_integer (addr
, 4);
1798 super
->class = read_memory_unsigned_integer (addr
+ 4, 4);
1802 read_objc_class (CORE_ADDR addr
, struct objc_class
*class)
1804 class->isa
= read_memory_unsigned_integer (addr
, 4);
1805 class->super_class
= read_memory_unsigned_integer (addr
+ 4, 4);
1806 class->name
= read_memory_unsigned_integer (addr
+ 8, 4);
1807 class->version
= read_memory_unsigned_integer (addr
+ 12, 4);
1808 class->info
= read_memory_unsigned_integer (addr
+ 16, 4);
1809 class->instance_size
= read_memory_unsigned_integer (addr
+ 18, 4);
1810 class->ivars
= read_memory_unsigned_integer (addr
+ 24, 4);
1811 class->methods
= read_memory_unsigned_integer (addr
+ 28, 4);
1812 class->cache
= read_memory_unsigned_integer (addr
+ 32, 4);
1813 class->protocols
= read_memory_unsigned_integer (addr
+ 36, 4);
1817 find_implementation_from_class (CORE_ADDR
class, CORE_ADDR sel
)
1819 CORE_ADDR subclass
= class;
1821 while (subclass
!= 0)
1824 struct objc_class class_str
;
1825 unsigned mlistnum
= 0;
1827 read_objc_class (subclass
, &class_str
);
1832 unsigned long nmethods
;
1835 mlist
= read_memory_unsigned_integer (class_str
.methods
+
1840 nmethods
= read_objc_methlist_nmethods (mlist
);
1842 for (i
= 0; i
< nmethods
; i
++)
1844 struct objc_method meth_str
;
1845 read_objc_methlist_method (mlist
, i
, &meth_str
);
1849 "checking method 0x%lx against selector 0x%lx\n",
1850 meth_str
.name
, sel
);
1853 if (meth_str
.name
== sel
)
1854 return CONVERT_FUNCPTR (meth_str
.imp
);
1858 subclass
= class_str
.super_class
;
1865 find_implementation (CORE_ADDR object
, CORE_ADDR sel
)
1867 struct objc_object ostr
;
1871 read_objc_object (object
, &ostr
);
1875 return find_implementation_from_class (ostr
.isa
, sel
);
1879 resolve_msgsend (CORE_ADDR pc
, CORE_ADDR
*new_pc
)
1885 object
= FETCH_ARGUMENT (0);
1886 sel
= FETCH_ARGUMENT (1);
1888 res
= find_implementation (object
, sel
);
1897 resolve_msgsend_stret (CORE_ADDR pc
, CORE_ADDR
*new_pc
)
1903 object
= FETCH_ARGUMENT (1);
1904 sel
= FETCH_ARGUMENT (2);
1906 res
= find_implementation (object
, sel
);
1915 resolve_msgsend_super (CORE_ADDR pc
, CORE_ADDR
*new_pc
)
1917 struct objc_super sstr
;
1923 super
= FETCH_ARGUMENT (0);
1924 sel
= FETCH_ARGUMENT (1);
1926 read_objc_super (super
, &sstr
);
1927 if (sstr
.class == 0)
1930 res
= find_implementation_from_class (sstr
.class, sel
);
1939 resolve_msgsend_super_stret (CORE_ADDR pc
, CORE_ADDR
*new_pc
)
1941 struct objc_super sstr
;
1947 super
= FETCH_ARGUMENT (1);
1948 sel
= FETCH_ARGUMENT (2);
1950 read_objc_super (super
, &sstr
);
1951 if (sstr
.class == 0)
1954 res
= find_implementation_from_class (sstr
.class, sel
);