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 "gdb_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 #if (!defined __GNUC__ || __GNUC__ < 2 || __GNUC_MINOR__ < (defined __cplusplus ? 6 : 4))
78 #define __CHECK_FUNCTION ((__const char *) 0)
80 #define __CHECK_FUNCTION __PRETTY_FUNCTION__
83 #define CHECK(expression) \
84 ((void) ((expression) ? 0 : gdb_check (#expression, __FILE__, __LINE__, \
87 #define CHECK_FATAL(expression) \
88 ((void) ((expression) ? 0 : gdb_check_fatal (#expression, __FILE__, \
89 __LINE__, __CHECK_FUNCTION)))
92 gdb_check (const char *str
, const char *file
,
93 unsigned int line
, const char *func
)
95 error ("assertion failure on line %u of \"%s\" in function \"%s\": %s\n",
96 line
, file
, func
, str
);
100 gdb_check_fatal (const char *str
, const char *file
,
101 unsigned int line
, const char *func
)
103 internal_error (file
, line
,
104 "assertion failure in function \"%s\": %s\n", func
, str
);
107 /* Lookup a structure type named "struct NAME", visible in lexical
108 block BLOCK. If NOERR is nonzero, return zero if NAME is not
112 lookup_struct_typedef (char *name
, struct block
*block
, int noerr
)
114 register struct symbol
*sym
;
116 sym
= lookup_symbol (name
, block
, STRUCT_NAMESPACE
, 0,
117 (struct symtab
**) NULL
);
124 error ("No struct type named %s.", name
);
126 if (TYPE_CODE (SYMBOL_TYPE (sym
)) != TYPE_CODE_STRUCT
)
131 error ("This context has class, union or enum %s, not a struct.",
138 lookup_objc_class (char *classname
)
140 struct value
* function
, *classval
;
142 if (! target_has_execution
)
144 /* Can't call into inferior to lookup class. */
148 if (lookup_minimal_symbol("objc_lookUpClass", 0, 0))
149 function
= find_function_in_inferior("objc_lookUpClass");
150 else if (lookup_minimal_symbol ("objc_lookup_class", 0, 0))
151 function
= find_function_in_inferior("objc_lookup_class");
154 complaint (&symfile_complaints
, "no way to lookup Objective-C classes");
158 classval
= value_string (classname
, strlen (classname
) + 1);
159 classval
= value_coerce_array (classval
);
160 return (CORE_ADDR
) value_as_long (call_function_by_hand (function
,
165 lookup_child_selector (char *selname
)
167 struct value
* function
, *selstring
;
169 if (! target_has_execution
)
171 /* Can't call into inferior to lookup selector. */
175 if (lookup_minimal_symbol("sel_getUid", 0, 0))
176 function
= find_function_in_inferior("sel_getUid");
177 else if (lookup_minimal_symbol ("sel_get_any_uid", 0, 0))
178 function
= find_function_in_inferior("sel_get_any_uid");
181 complaint (&symfile_complaints
, "no way to lookup Objective-C selectors");
185 selstring
= value_coerce_array (value_string (selname
,
186 strlen (selname
) + 1));
187 return value_as_long (call_function_by_hand (function
, 1, &selstring
));
191 value_nsstring (char *ptr
, int len
)
193 struct value
*stringValue
[3];
194 struct value
*function
, *nsstringValue
;
198 if (!target_has_execution
)
199 return 0; /* Can't call into inferior to create NSString. */
201 if (!(sym
= lookup_struct_typedef("NSString", 0, 1)) &&
202 !(sym
= lookup_struct_typedef("NXString", 0, 1)))
203 type
= lookup_pointer_type(builtin_type_void
);
205 type
= lookup_pointer_type(SYMBOL_TYPE (sym
));
207 stringValue
[2] = value_string(ptr
, len
);
208 stringValue
[2] = value_coerce_array(stringValue
[2]);
209 /* _NSNewStringFromCString replaces "istr" after Lantern2A. */
210 if (lookup_minimal_symbol("_NSNewStringFromCString", 0, 0))
212 function
= find_function_in_inferior("_NSNewStringFromCString");
213 nsstringValue
= call_function_by_hand(function
, 1, &stringValue
[2]);
215 else if (lookup_minimal_symbol("istr", 0, 0))
217 function
= find_function_in_inferior("istr");
218 nsstringValue
= call_function_by_hand(function
, 1, &stringValue
[2]);
220 else if (lookup_minimal_symbol("+[NSString stringWithCString:]", 0, 0))
222 function
= find_function_in_inferior("+[NSString stringWithCString:]");
223 stringValue
[0] = value_from_longest
224 (builtin_type_long
, lookup_objc_class ("NSString"));
225 stringValue
[1] = value_from_longest
226 (builtin_type_long
, lookup_child_selector ("stringWithCString:"));
227 nsstringValue
= call_function_by_hand(function
, 3, &stringValue
[0]);
230 error ("NSString: internal error -- no way to create new NSString");
232 VALUE_TYPE(nsstringValue
) = type
;
233 return nsstringValue
;
236 /* Objective-C name demangling. */
239 objc_demangle (const char *mangled
)
241 char *demangled
, *cp
;
243 if (mangled
[0] == '_' &&
244 (mangled
[1] == 'i' || mangled
[1] == 'c') &&
247 cp
= demangled
= xmalloc(strlen(mangled
) + 2);
249 if (mangled
[1] == 'i')
250 *cp
++ = '-'; /* for instance method */
252 *cp
++ = '+'; /* for class method */
254 *cp
++ = '['; /* opening left brace */
255 strcpy(cp
, mangled
+3); /* tack on the rest of the mangled name */
257 while (*cp
&& *cp
== '_')
258 cp
++; /* skip any initial underbars in class name */
260 cp
= strchr(cp
, '_');
261 if (!cp
) /* find first non-initial underbar */
263 xfree(demangled
); /* not mangled name */
266 if (cp
[1] == '_') { /* easy case: no category name */
267 *cp
++ = ' '; /* replace two '_' with one ' ' */
268 strcpy(cp
, mangled
+ (cp
- demangled
) + 2);
271 *cp
++ = '('; /* less easy case: category name */
272 cp
= strchr(cp
, '_');
275 xfree(demangled
); /* not mangled name */
279 *cp
++ = ' '; /* overwriting 1st char of method name... */
280 strcpy(cp
, mangled
+ (cp
- demangled
)); /* get it back */
283 while (*cp
&& *cp
== '_')
284 cp
++; /* skip any initial underbars in method name */
288 *cp
= ':'; /* replace remaining '_' with ':' */
290 *cp
++ = ']'; /* closing right brace */
291 *cp
++ = 0; /* string terminator */
295 return NULL
; /* Not an objc mangled name. */
298 /* Print the character C on STREAM as part of the contents of a
299 literal string whose delimiter is QUOTER. Note that that format
300 for printing characters and strings is language specific. */
303 objc_emit_char (register int c
, struct ui_file
*stream
, int quoter
)
306 c
&= 0xFF; /* Avoid sign bit follies. */
308 if (PRINT_LITERAL_FORM (c
))
310 if (c
== '\\' || c
== quoter
)
312 fputs_filtered ("\\", stream
);
314 fprintf_filtered (stream
, "%c", c
);
321 fputs_filtered ("\\n", stream
);
324 fputs_filtered ("\\b", stream
);
327 fputs_filtered ("\\t", stream
);
330 fputs_filtered ("\\f", stream
);
333 fputs_filtered ("\\r", stream
);
336 fputs_filtered ("\\e", stream
);
339 fputs_filtered ("\\a", stream
);
342 fprintf_filtered (stream
, "\\%.3o", (unsigned int) c
);
349 objc_printchar (int c
, struct ui_file
*stream
)
351 fputs_filtered ("'", stream
);
352 objc_emit_char (c
, stream
, '\'');
353 fputs_filtered ("'", stream
);
356 /* Print the character string STRING, printing at most LENGTH
357 characters. Printing stops early if the number hits print_max;
358 repeat counts are printed as appropriate. Print ellipses at the
359 end if we had to stop before printing LENGTH characters, or if
363 objc_printstr (struct ui_file
*stream
, char *string
,
364 unsigned int length
, int width
, int force_ellipses
)
366 register unsigned int i
;
367 unsigned int things_printed
= 0;
370 extern int inspect_it
;
371 extern int repeat_count_threshold
;
372 extern int print_max
;
374 /* If the string was not truncated due to `set print elements', and
375 the last byte of it is a null, we don't print that, in
376 traditional C style. */
377 if ((!force_ellipses
) && length
> 0 && string
[length
-1] == '\0')
382 fputs_filtered ("\"\"", stream
);
386 for (i
= 0; i
< length
&& things_printed
< print_max
; ++i
)
388 /* Position of the character we are examining to see whether it
391 /* Number of repetitions we have detected so far. */
398 fputs_filtered (", ", stream
);
404 while (rep1
< length
&& string
[rep1
] == string
[i
])
410 if (reps
> repeat_count_threshold
)
415 fputs_filtered ("\\\", ", stream
);
417 fputs_filtered ("\", ", stream
);
420 objc_printchar (string
[i
], stream
);
421 fprintf_filtered (stream
, " <repeats %u times>", reps
);
423 things_printed
+= repeat_count_threshold
;
431 fputs_filtered ("\\\"", stream
);
433 fputs_filtered ("\"", stream
);
436 objc_emit_char (string
[i
], stream
, '"');
441 /* Terminate the quotes if necessary. */
445 fputs_filtered ("\\\"", stream
);
447 fputs_filtered ("\"", stream
);
450 if (force_ellipses
|| i
< length
)
451 fputs_filtered ("...", stream
);
454 /* Create a fundamental C type using default reasonable for the
457 Some object/debugging file formats (DWARF version 1, COFF, etc) do
458 not define fundamental types such as "int" or "double". Others
459 (stabs or DWARF version 2, etc) do define fundamental types. For
460 the formats which don't provide fundamental types, gdb can create
461 such types using this function.
463 FIXME: Some compilers distinguish explicitly signed integral types
464 (signed short, signed int, signed long) from "regular" integral
465 types (short, int, long) in the debugging information. There is
466 some disagreement as to how useful this feature is. In particular,
467 gcc does not support this. Also, only some debugging formats allow
468 the distinction to be passed on to a debugger. For now, we always
469 just use "short", "int", or "long" as the type name, for both the
470 implicit and explicitly signed types. This also makes life easier
471 for the gdb test suite since we don't have to account for the
472 differences in output depending upon what the compiler and
473 debugging format support. We will probably have to re-examine the
474 issue when gdb starts taking it's fundamental type information
475 directly from the debugging information supplied by the compiler.
479 objc_create_fundamental_type (struct objfile
*objfile
, int typeid)
481 register struct type
*type
= NULL
;
486 /* FIXME: For now, if we are asked to produce a type not in
487 this language, create the equivalent of a C integer type
488 with the name "<?type?>". When all the dust settles from
489 the type reconstruction work, this should probably become
491 type
= init_type (TYPE_CODE_INT
,
492 TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
493 0, "<?type?>", objfile
);
494 warning ("internal error: no C/C++ fundamental type %d", typeid);
497 type
= init_type (TYPE_CODE_VOID
,
498 TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
502 type
= init_type (TYPE_CODE_INT
,
503 TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
507 type
= init_type (TYPE_CODE_INT
,
508 TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
509 0, "signed char", objfile
);
511 case FT_UNSIGNED_CHAR
:
512 type
= init_type (TYPE_CODE_INT
,
513 TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
514 TYPE_FLAG_UNSIGNED
, "unsigned char", objfile
);
517 type
= init_type (TYPE_CODE_INT
,
518 TARGET_SHORT_BIT
/ TARGET_CHAR_BIT
,
519 0, "short", objfile
);
521 case FT_SIGNED_SHORT
:
522 type
= init_type (TYPE_CODE_INT
,
523 TARGET_SHORT_BIT
/ TARGET_CHAR_BIT
,
524 0, "short", objfile
); /* FIXME-fnf */
526 case FT_UNSIGNED_SHORT
:
527 type
= init_type (TYPE_CODE_INT
,
528 TARGET_SHORT_BIT
/ TARGET_CHAR_BIT
,
529 TYPE_FLAG_UNSIGNED
, "unsigned short", objfile
);
532 type
= init_type (TYPE_CODE_INT
,
533 TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
536 case FT_SIGNED_INTEGER
:
537 type
= init_type (TYPE_CODE_INT
,
538 TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
539 0, "int", objfile
); /* FIXME -fnf */
541 case FT_UNSIGNED_INTEGER
:
542 type
= init_type (TYPE_CODE_INT
,
543 TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
544 TYPE_FLAG_UNSIGNED
, "unsigned int", objfile
);
547 type
= init_type (TYPE_CODE_INT
,
548 TARGET_LONG_BIT
/ TARGET_CHAR_BIT
,
552 type
= init_type (TYPE_CODE_INT
,
553 TARGET_LONG_BIT
/ TARGET_CHAR_BIT
,
554 0, "long", objfile
); /* FIXME -fnf */
556 case FT_UNSIGNED_LONG
:
557 type
= init_type (TYPE_CODE_INT
,
558 TARGET_LONG_BIT
/ TARGET_CHAR_BIT
,
559 TYPE_FLAG_UNSIGNED
, "unsigned long", objfile
);
562 type
= init_type (TYPE_CODE_INT
,
563 TARGET_LONG_LONG_BIT
/ TARGET_CHAR_BIT
,
564 0, "long long", objfile
);
566 case FT_SIGNED_LONG_LONG
:
567 type
= init_type (TYPE_CODE_INT
,
568 TARGET_LONG_LONG_BIT
/ TARGET_CHAR_BIT
,
569 0, "signed long long", objfile
);
571 case FT_UNSIGNED_LONG_LONG
:
572 type
= init_type (TYPE_CODE_INT
,
573 TARGET_LONG_LONG_BIT
/ TARGET_CHAR_BIT
,
574 TYPE_FLAG_UNSIGNED
, "unsigned long long", objfile
);
577 type
= init_type (TYPE_CODE_FLT
,
578 TARGET_FLOAT_BIT
/ TARGET_CHAR_BIT
,
579 0, "float", objfile
);
581 case FT_DBL_PREC_FLOAT
:
582 type
= init_type (TYPE_CODE_FLT
,
583 TARGET_DOUBLE_BIT
/ TARGET_CHAR_BIT
,
584 0, "double", objfile
);
586 case FT_EXT_PREC_FLOAT
:
587 type
= init_type (TYPE_CODE_FLT
,
588 TARGET_LONG_DOUBLE_BIT
/ TARGET_CHAR_BIT
,
589 0, "long double", objfile
);
596 /* Table mapping opcodes into strings for printing operators
597 and precedences of the operators. */
599 static const struct op_print objc_op_print_tab
[] =
601 {",", BINOP_COMMA
, PREC_COMMA
, 0},
602 {"=", BINOP_ASSIGN
, PREC_ASSIGN
, 1},
603 {"||", BINOP_LOGICAL_OR
, PREC_LOGICAL_OR
, 0},
604 {"&&", BINOP_LOGICAL_AND
, PREC_LOGICAL_AND
, 0},
605 {"|", BINOP_BITWISE_IOR
, PREC_BITWISE_IOR
, 0},
606 {"^", BINOP_BITWISE_XOR
, PREC_BITWISE_XOR
, 0},
607 {"&", BINOP_BITWISE_AND
, PREC_BITWISE_AND
, 0},
608 {"==", BINOP_EQUAL
, PREC_EQUAL
, 0},
609 {"!=", BINOP_NOTEQUAL
, PREC_EQUAL
, 0},
610 {"<=", BINOP_LEQ
, PREC_ORDER
, 0},
611 {">=", BINOP_GEQ
, PREC_ORDER
, 0},
612 {">", BINOP_GTR
, PREC_ORDER
, 0},
613 {"<", BINOP_LESS
, PREC_ORDER
, 0},
614 {">>", BINOP_RSH
, PREC_SHIFT
, 0},
615 {"<<", BINOP_LSH
, PREC_SHIFT
, 0},
616 {"+", BINOP_ADD
, PREC_ADD
, 0},
617 {"-", BINOP_SUB
, PREC_ADD
, 0},
618 {"*", BINOP_MUL
, PREC_MUL
, 0},
619 {"/", BINOP_DIV
, PREC_MUL
, 0},
620 {"%", BINOP_REM
, PREC_MUL
, 0},
621 {"@", BINOP_REPEAT
, PREC_REPEAT
, 0},
622 {"-", UNOP_NEG
, PREC_PREFIX
, 0},
623 {"!", UNOP_LOGICAL_NOT
, PREC_PREFIX
, 0},
624 {"~", UNOP_COMPLEMENT
, PREC_PREFIX
, 0},
625 {"*", UNOP_IND
, PREC_PREFIX
, 0},
626 {"&", UNOP_ADDR
, PREC_PREFIX
, 0},
627 {"sizeof ", UNOP_SIZEOF
, PREC_PREFIX
, 0},
628 {"++", UNOP_PREINCREMENT
, PREC_PREFIX
, 0},
629 {"--", UNOP_PREDECREMENT
, PREC_PREFIX
, 0},
633 struct type
** const (objc_builtin_types
[]) =
640 &builtin_type_double
,
642 &builtin_type_long_long
,
643 &builtin_type_signed_char
,
644 &builtin_type_unsigned_char
,
645 &builtin_type_unsigned_short
,
646 &builtin_type_unsigned_int
,
647 &builtin_type_unsigned_long
,
648 &builtin_type_unsigned_long_long
,
649 &builtin_type_long_double
,
650 &builtin_type_complex
,
651 &builtin_type_double_complex
,
655 const struct language_defn objc_language_defn
= {
656 "objective-c", /* Language name */
664 evaluate_subexp_standard
,
665 objc_printchar
, /* Print a character constant */
666 objc_printstr
, /* Function to print string constant */
668 objc_create_fundamental_type
, /* Create fundamental type in this language */
669 c_print_type
, /* Print a type using appropriate syntax */
670 c_val_print
, /* Print a value using appropriate syntax */
671 c_value_print
, /* Print a top-level value */
672 {"", "", "", ""}, /* Binary format info */
673 {"0%lo", "0", "o", ""}, /* Octal format info */
674 {"%ld", "", "d", ""}, /* Decimal format info */
675 {"0x%lx", "0x", "x", ""}, /* Hex format info */
676 objc_op_print_tab
, /* Expression operators for printing */
677 1, /* C-style arrays */
678 0, /* String lower bound */
679 &builtin_type_char
, /* Type of string elements */
685 * Following functions help construct Objective-C message calls
688 struct selname
/* For parsing Objective-C. */
690 struct selname
*next
;
695 static int msglist_len
;
696 static struct selname
*selname_chain
;
697 static char *msglist_sel
;
702 register struct selname
*new =
703 (struct selname
*) xmalloc (sizeof (struct selname
));
705 new->next
= selname_chain
;
706 new->msglist_len
= msglist_len
;
707 new->msglist_sel
= msglist_sel
;
709 msglist_sel
= (char *)xmalloc(1);
715 add_msglist(struct stoken
*str
, int addcolon
)
720 if (str
== 0) { /* Unnamed arg, or... */
721 if (addcolon
== 0) { /* variable number of args. */
731 len
= plen
+ strlen(msglist_sel
) + 2;
732 s
= (char *)xmalloc(len
);
733 strcpy(s
, msglist_sel
);
748 register int val
= msglist_len
;
749 register struct selname
*sel
= selname_chain
;
750 register char *p
= msglist_sel
;
753 selname_chain
= sel
->next
;
754 msglist_len
= sel
->msglist_len
;
755 msglist_sel
= sel
->msglist_sel
;
756 selid
= lookup_child_selector(p
);
758 error("Can't find selector \"%s\"", p
);
759 write_exp_elt_longcst (selid
);
761 write_exp_elt_longcst (val
); /* Number of args */
768 * Function: specialcmp (char *a, char *b)
770 * Special strcmp: treats ']' and ' ' as end-of-string.
771 * Used for qsorting lists of objc methods (either by class or selector).
774 int specialcmp(char *a
, char *b
)
776 while (*a
&& *a
!= ' ' && *a
!= ']' && *b
&& *b
!= ' ' && *b
!= ']')
782 if (*a
&& *a
!= ' ' && *a
!= ']')
783 return 1; /* a is longer therefore greater */
784 if (*b
&& *b
!= ' ' && *b
!= ']')
785 return -1; /* a is shorter therefore lesser */
786 return 0; /* a and b are identical */
790 * Function: compare_selectors (const void *, const void *)
792 * Comparison function for use with qsort. Arguments are symbols or
793 * msymbols Compares selector part of objc method name alphabetically.
797 compare_selectors (const void *a
, const void *b
)
801 aname
= SYMBOL_SOURCE_NAME (*(struct symbol
**) a
);
802 bname
= SYMBOL_SOURCE_NAME (*(struct symbol
**) b
);
803 if (aname
== NULL
|| bname
== NULL
)
804 error ("internal: compare_selectors(1)");
806 aname
= strchr(aname
, ' ');
807 bname
= strchr(bname
, ' ');
808 if (aname
== NULL
|| 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 name
= SYMBOL_DEMANGLED_NAME (msymbol
);
870 name
= SYMBOL_NAME (msymbol
);
872 (name
[0] == '-' || name
[0] == '+') &&
873 name
[1] == '[') /* Got a method name. */
875 /* Filter for class/instance methods. */
876 if (plusminus
&& name
[0] != plusminus
)
878 /* Find selector part. */
879 name
= (char *) strchr(name
+2, ' ');
880 if (regexp
== NULL
|| re_exec(++name
) != 0)
882 char *mystart
= name
;
883 char *myend
= (char *) strchr(mystart
, ']');
885 if (myend
&& (myend
- mystart
> maxlen
))
886 maxlen
= myend
- mystart
; /* Get longest selector. */
893 printf_filtered ("Selectors matching \"%s\":\n\n",
894 regexp
? regexp
: "*");
896 sym_arr
= alloca (matches
* sizeof (struct symbol
*));
898 ALL_MSYMBOLS (objfile
, msymbol
)
901 name
= SYMBOL_DEMANGLED_NAME (msymbol
);
903 name
= SYMBOL_NAME (msymbol
);
905 (name
[0] == '-' || name
[0] == '+') &&
906 name
[1] == '[') /* Got a method name. */
908 /* Filter for class/instance methods. */
909 if (plusminus
&& name
[0] != plusminus
)
911 /* Find selector part. */
912 name
= (char *) strchr(name
+2, ' ');
913 if (regexp
== NULL
|| re_exec(++name
) != 0)
914 sym_arr
[matches
++] = (struct symbol
*) msymbol
;
918 qsort (sym_arr
, matches
, sizeof (struct minimal_symbol
*),
920 /* Prevent compare on first iteration. */
922 for (ix
= 0; ix
< matches
; ix
++) /* Now do the output. */
927 name
= SYMBOL_DEMANGLED_NAME (sym_arr
[ix
]);
929 name
= SYMBOL_NAME (sym_arr
[ix
]);
930 name
= strchr (name
, ' ') + 1;
931 if (p
[0] && specialcmp(name
, p
) == 0)
932 continue; /* Seen this one already (not unique). */
934 /* Copy selector part. */
935 while (*name
&& *name
!= ']')
938 /* Print in columns. */
939 puts_filtered_tabular(asel
, maxlen
+ 1, 0);
944 printf_filtered ("No selectors matching \"%s\"\n", regexp
? regexp
: "*");
948 * Function: compare_classes (const void *, const void *)
950 * Comparison function for use with qsort. Arguments are symbols or
951 * msymbols Compares class part of objc method name alphabetically.
955 compare_classes (const void *a
, const void *b
)
959 aname
= SYMBOL_SOURCE_NAME (*(struct symbol
**) a
);
960 bname
= SYMBOL_SOURCE_NAME (*(struct symbol
**) b
);
961 if (aname
== NULL
|| bname
== NULL
)
962 error ("internal: compare_classes(1)");
964 return specialcmp (aname
+1, bname
+1);
968 * Function: classes_info(regexp, from_tty)
970 * Implements the "info classes" command for objective c classes.
971 * Lists all objective c classes that match the optional regexp.
972 * Works by grepping thru the list of objective c methods. List will
973 * be sorted and uniqued (since one class may have many methods).
974 * BUGS: will not list a class that has no methods.
978 classes_info (char *regexp
, int from_tty
)
980 struct objfile
*objfile
;
981 struct minimal_symbol
*msymbol
;
989 struct symbol
**sym_arr
;
992 strcpy(myregexp
, ".* "); /* Null input: match all objc classes. */
995 strcpy(myregexp
, regexp
);
996 if (myregexp
[strlen(myregexp
) - 1] == '$')
997 /* In the method name, the end of the class name is marked by ' '. */
998 myregexp
[strlen(myregexp
) - 1] = ' ';
1000 strcat(myregexp
, ".* ");
1004 if (0 != (val
= re_comp (myregexp
)))
1005 error ("Invalid regexp (%s): %s", val
, regexp
);
1007 /* First time thru is JUST to get max length and count. */
1008 ALL_MSYMBOLS (objfile
, msymbol
)
1011 name
= SYMBOL_DEMANGLED_NAME (msymbol
);
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 name
= SYMBOL_DEMANGLED_NAME (msymbol
);
1039 name
= SYMBOL_NAME (msymbol
);
1041 (name
[0] == '-' || name
[0] == '+') &&
1042 name
[1] == '[') /* Got a method name. */
1043 if (regexp
== NULL
|| re_exec(name
+2) != 0)
1044 sym_arr
[matches
++] = (struct symbol
*) msymbol
;
1047 qsort (sym_arr
, matches
, sizeof (struct minimal_symbol
*),
1049 /* Prevent compare on first iteration. */
1051 for (ix
= 0; ix
< matches
; ix
++) /* Now do the output. */
1056 name
= SYMBOL_DEMANGLED_NAME (sym_arr
[ix
]);
1058 name
= SYMBOL_NAME (sym_arr
[ix
]);
1060 if (p
[0] && specialcmp(name
, p
) == 0)
1061 continue; /* Seen this one already (not unique). */
1063 /* Copy class part of method name. */
1064 while (*name
&& *name
!= ' ')
1067 /* Print in columns. */
1068 puts_filtered_tabular(aclass
, maxlen
+ 1, 0);
1073 printf_filtered ("No classes matching \"%s\"\n", regexp
? regexp
: "*");
1077 * Function: find_imps (char *selector, struct symbol **sym_arr)
1079 * Input: a string representing a selector
1080 * a pointer to an array of symbol pointers
1081 * possibly a pointer to a symbol found by the caller.
1083 * Output: number of methods that implement that selector. Side
1084 * effects: The array of symbol pointers is filled with matching syms.
1086 * By analogy with function "find_methods" (symtab.c), builds a list
1087 * of symbols matching the ambiguous input, so that "decode_line_2"
1088 * (symtab.c) can list them and ask the user to choose one or more.
1089 * In this case the matches are objective c methods
1090 * ("implementations") matching an objective c selector.
1092 * Note that it is possible for a normal (c-style) function to have
1093 * the same name as an objective c selector. To prevent the selector
1094 * from eclipsing the function, we allow the caller (decode_line_1) to
1095 * search for such a function first, and if it finds one, pass it in
1096 * to us. We will then integrate it into the list. We also search
1097 * for one here, among the minsyms.
1099 * NOTE: if NUM_DEBUGGABLE is non-zero, the sym_arr will be divided
1100 * into two parts: debuggable (struct symbol) syms, and
1101 * non_debuggable (struct minimal_symbol) syms. The debuggable
1102 * ones will come first, before NUM_DEBUGGABLE (which will thus
1103 * be the index of the first non-debuggable one).
1107 * Function: total_number_of_imps (char *selector);
1109 * Input: a string representing a selector
1110 * Output: number of methods that implement that selector.
1112 * By analogy with function "total_number_of_methods", this allows
1113 * decode_line_1 (symtab.c) to detect if there are objective c methods
1114 * matching the input, and to allocate an array of pointers to them
1115 * which can be manipulated by "decode_line_2" (also in symtab.c).
1119 parse_selector (char *method
, char **selector
)
1123 int found_quote
= 0;
1125 char *nselector
= NULL
;
1127 CHECK (selector
!= NULL
);
1131 while (isspace (*s1
))
1138 while (isspace (*s1
))
1145 if (isalnum (*s2
) || (*s2
== '_') || (*s2
== ':'))
1147 else if (isspace (*s2
))
1149 else if ((*s2
== '\0') || (*s2
== '\''))
1157 while (isspace (*s2
))
1163 while (isspace (*s2
))
1167 if (selector
!= NULL
)
1168 *selector
= nselector
;
1174 parse_method (char *method
, char *type
, char **class,
1175 char **category
, char **selector
)
1179 int found_quote
= 0;
1182 char *nclass
= NULL
;
1183 char *ncategory
= NULL
;
1184 char *nselector
= NULL
;
1186 CHECK (type
!= NULL
);
1187 CHECK (class != NULL
);
1188 CHECK (category
!= NULL
);
1189 CHECK (selector
!= NULL
);
1193 while (isspace (*s1
))
1200 while (isspace (*s1
))
1203 if ((s1
[0] == '+') || (s1
[0] == '-'))
1206 while (isspace (*s1
))
1214 while (isalnum (*s1
) || (*s1
== '_'))
1218 while (isspace (*s2
))
1224 while (isspace (*s2
))
1227 while (isalnum (*s2
) || (*s2
== '_'))
1232 /* Truncate the class name now that we're not using the open paren. */
1239 if (isalnum (*s2
) || (*s2
== '_') || (*s2
== ':'))
1241 else if (isspace (*s2
))
1243 else if (*s2
== ']')
1252 while (isspace (*s2
))
1259 while (isspace (*s2
))
1267 if (category
!= NULL
)
1268 *category
= ncategory
;
1269 if (selector
!= NULL
)
1270 *selector
= nselector
;
1276 find_methods (struct symtab
*symtab
, char type
,
1277 const char *class, const char *category
,
1278 const char *selector
, struct symbol
**syms
,
1279 unsigned int *nsym
, unsigned int *ndebug
)
1281 struct objfile
*objfile
= NULL
;
1282 struct minimal_symbol
*msymbol
= NULL
;
1283 struct block
*block
= NULL
;
1284 struct symbol
*sym
= NULL
;
1286 char *symname
= NULL
;
1289 char *nclass
= NULL
;
1290 char *ncategory
= NULL
;
1291 char *nselector
= NULL
;
1293 unsigned int csym
= 0;
1294 unsigned int cdebug
= 0;
1296 static char *tmp
= NULL
;
1297 static unsigned int tmplen
= 0;
1299 CHECK (nsym
!= NULL
);
1300 CHECK (ndebug
!= NULL
);
1303 block
= BLOCKVECTOR_BLOCK (BLOCKVECTOR (symtab
), STATIC_BLOCK
);
1305 ALL_MSYMBOLS (objfile
, msymbol
)
1309 if ((msymbol
->type
!= mst_text
) && (msymbol
->type
!= mst_file_text
))
1310 /* Not a function or method. */
1314 if ((SYMBOL_VALUE_ADDRESS (msymbol
) < BLOCK_START (block
)) ||
1315 (SYMBOL_VALUE_ADDRESS (msymbol
) >= BLOCK_END (block
)))
1316 /* Not in the specified symtab. */
1319 symname
= SYMBOL_DEMANGLED_NAME (msymbol
);
1320 if (symname
== NULL
)
1321 symname
= SYMBOL_NAME (msymbol
);
1322 if (symname
== NULL
)
1325 if ((symname
[0] != '-' && symname
[0] != '+') || (symname
[1] != '['))
1326 /* Not a method name. */
1329 while ((strlen (symname
) + 1) >= tmplen
)
1331 tmplen
= (tmplen
== 0) ? 1024 : tmplen
* 2;
1332 tmp
= xrealloc (tmp
, tmplen
);
1334 strcpy (tmp
, symname
);
1336 if (parse_method (tmp
, &ntype
, &nclass
, &ncategory
, &nselector
) == NULL
)
1339 if ((type
!= '\0') && (ntype
!= type
))
1343 && ((nclass
== NULL
) || (strcmp (class, nclass
) != 0)))
1346 if ((category
!= NULL
) &&
1347 ((ncategory
== NULL
) || (strcmp (category
, ncategory
) != 0)))
1350 if ((selector
!= NULL
) &&
1351 ((nselector
== NULL
) || (strcmp (selector
, nselector
) != 0)))
1354 sym
= find_pc_function (SYMBOL_VALUE_ADDRESS (msymbol
));
1357 const char *newsymname
= SYMBOL_DEMANGLED_NAME (sym
);
1359 if (newsymname
== NULL
)
1360 newsymname
= SYMBOL_NAME (sym
);
1361 if (strcmp (symname
, newsymname
) == 0)
1363 /* Found a high-level method sym: swap it into the
1364 lower part of sym_arr (below num_debuggable). */
1367 syms
[csym
] = syms
[cdebug
];
1376 "debugging symbol \"%s\" does not match minimal symbol (\"%s\"); ignoring",
1377 newsymname
, symname
);
1379 syms
[csym
] = (struct symbol
*) msymbol
;
1385 /* Found a non-debuggable method symbol. */
1387 syms
[csym
] = (struct symbol
*) msymbol
;
1398 char *find_imps (struct symtab
*symtab
, struct block
*block
,
1399 char *method
, struct symbol
**syms
,
1400 unsigned int *nsym
, unsigned int *ndebug
)
1404 char *category
= NULL
;
1405 char *selector
= NULL
;
1407 unsigned int csym
= 0;
1408 unsigned int cdebug
= 0;
1410 unsigned int ncsym
= 0;
1411 unsigned int ncdebug
= 0;
1416 CHECK (nsym
!= NULL
);
1417 CHECK (ndebug
!= NULL
);
1424 buf
= (char *) alloca (strlen (method
) + 1);
1425 strcpy (buf
, method
);
1426 tmp
= parse_method (buf
, &type
, &class, &category
, &selector
);
1430 struct symtab
*sym_symtab
= NULL
;
1431 struct symbol
*sym
= NULL
;
1432 struct minimal_symbol
*msym
= NULL
;
1434 strcpy (buf
, method
);
1435 tmp
= parse_selector (buf
, &selector
);
1440 sym
= lookup_symbol (selector
, block
, VAR_NAMESPACE
, 0, &sym_symtab
);
1450 msym
= lookup_minimal_symbol (selector
, 0, 0);
1455 syms
[csym
] = (struct symbol
*)msym
;
1461 find_methods (symtab
, type
, class, category
, selector
,
1462 syms
+ csym
, &ncsym
, &ncdebug
);
1464 find_methods (symtab
, type
, class, category
, selector
,
1465 NULL
, &ncsym
, &ncdebug
);
1467 /* If we didn't find any methods, just return. */
1468 if (ncsym
== 0 && ncdebug
== 0)
1471 /* Take debug symbols from the second batch of symbols and swap them
1472 * with debug symbols from the first batch. Repeat until either the
1473 * second section is out of debug symbols or the first section is
1474 * full of debug symbols. Either way we have all debug symbols
1475 * packed to the beginning of the buffer.
1480 while ((cdebug
< csym
) && (ncdebug
> 0))
1482 struct symbol
*s
= NULL
;
1483 /* First non-debugging symbol. */
1484 unsigned int i
= cdebug
;
1485 /* Last of second batch of debug symbols. */
1486 unsigned int j
= csym
+ ncdebug
- 1;
1492 /* We've moved a symbol from the second debug section to the
1508 return method
+ (tmp
- buf
);
1512 /* Sort debuggable symbols. */
1514 qsort (syms
, cdebug
, sizeof (struct minimal_symbol
*),
1517 /* Sort minimal_symbols. */
1518 if ((csym
- cdebug
) > 1)
1519 qsort (&syms
[cdebug
], csym
- cdebug
,
1520 sizeof (struct minimal_symbol
*), compare_classes
);
1522 /* Terminate the sym_arr list. */
1525 return method
+ (tmp
- buf
);
1529 print_object_command (char *args
, int from_tty
)
1531 struct value
*object
, *function
, *description
;
1532 CORE_ADDR string_addr
, object_addr
;
1536 if (!args
|| !*args
)
1538 "The 'print-object' command requires an argument (an Objective-C object)");
1541 struct expression
*expr
= parse_expression (args
);
1542 register struct cleanup
*old_chain
=
1543 make_cleanup (free_current_contents
, &expr
);
1546 object
= expr
->language_defn
->evaluate_exp (builtin_type_void_data_ptr
,
1547 expr
, &pc
, EVAL_NORMAL
);
1548 do_cleanups (old_chain
);
1551 /* Validate the address for sanity. */
1552 object_addr
= value_as_long (object
);
1553 read_memory (object_addr
, &c
, 1);
1555 function
= find_function_in_inferior ("_NSPrintForDebugger");
1556 if (function
== NULL
)
1557 error ("Unable to locate _NSPrintForDebugger in child process");
1559 description
= call_function_by_hand (function
, 1, &object
);
1561 string_addr
= value_as_long (description
);
1562 if (string_addr
== 0)
1563 error ("object returns null description");
1565 read_memory (string_addr
+ i
++, &c
, 1);
1568 { /* Read and print characters up to EOS. */
1570 printf_filtered ("%c", c
);
1571 read_memory (string_addr
+ i
++, &c
, 1);
1574 printf_filtered("<object returns empty description>");
1575 printf_filtered ("\n");
1578 /* The data structure 'methcalls' is used to detect method calls (thru
1579 * ObjC runtime lib functions objc_msgSend, objc_msgSendSuper, etc.),
1580 * and ultimately find the method being called.
1583 struct objc_methcall
{
1585 /* Return instance method to be called. */
1586 int (*stop_at
) (CORE_ADDR
, CORE_ADDR
*);
1587 /* Start of pc range corresponding to method invocation. */
1589 /* End of pc range corresponding to method invocation. */
1593 static int resolve_msgsend (CORE_ADDR pc
, CORE_ADDR
*new_pc
);
1594 static int resolve_msgsend_stret (CORE_ADDR pc
, CORE_ADDR
*new_pc
);
1595 static int resolve_msgsend_super (CORE_ADDR pc
, CORE_ADDR
*new_pc
);
1596 static int resolve_msgsend_super_stret (CORE_ADDR pc
, CORE_ADDR
*new_pc
);
1598 static struct objc_methcall methcalls
[] = {
1599 { "_objc_msgSend", resolve_msgsend
, 0, 0},
1600 { "_objc_msgSend_stret", resolve_msgsend_stret
, 0, 0},
1601 { "_objc_msgSendSuper", resolve_msgsend_super
, 0, 0},
1602 { "_objc_msgSendSuper_stret", resolve_msgsend_super_stret
, 0, 0},
1603 { "_objc_getClass", NULL
, 0, 0},
1604 { "_objc_getMetaClass", NULL
, 0, 0}
1607 #define nmethcalls (sizeof (methcalls) / sizeof (methcalls[0]))
1609 /* The following function, "find_objc_msgsend", fills in the data
1610 * structure "objc_msgs" by finding the addresses of each of the
1611 * (currently four) functions that it holds (of which objc_msgSend is
1612 * the first). This must be called each time symbols are loaded, in
1613 * case the functions have moved for some reason.
1617 find_objc_msgsend (void)
1620 for (i
= 0; i
< nmethcalls
; i
++) {
1622 struct minimal_symbol
*func
;
1624 /* Try both with and without underscore. */
1625 func
= lookup_minimal_symbol (methcalls
[i
].name
, NULL
, NULL
);
1626 if ((func
== NULL
) && (methcalls
[i
].name
[0] == '_')) {
1627 func
= lookup_minimal_symbol (methcalls
[i
].name
+ 1, NULL
, NULL
);
1630 methcalls
[i
].begin
= 0;
1631 methcalls
[i
].end
= 0;
1635 methcalls
[i
].begin
= SYMBOL_VALUE_ADDRESS (func
);
1637 methcalls
[i
].end
= SYMBOL_VALUE_ADDRESS (++func
);
1638 } while (methcalls
[i
].begin
== methcalls
[i
].end
);
1642 /* find_objc_msgcall (replaces pc_off_limits)
1644 * ALL that this function now does is to determine whether the input
1645 * address ("pc") is the address of one of the Objective-C message
1646 * dispatch functions (mainly objc_msgSend or objc_msgSendSuper), and
1647 * if so, it returns the address of the method that will be called.
1649 * The old function "pc_off_limits" used to do a lot of other things
1650 * in addition, such as detecting shared library jump stubs and
1651 * returning the address of the shlib function that would be called.
1652 * That functionality has been moved into the SKIP_TRAMPOLINE_CODE and
1653 * IN_SOLIB_TRAMPOLINE macros, which are resolved in the target-
1654 * dependent modules.
1657 struct objc_submethod_helper_data
{
1658 int (*f
) (CORE_ADDR
, CORE_ADDR
*);
1664 find_objc_msgcall_submethod_helper (void * arg
)
1666 struct objc_submethod_helper_data
*s
=
1667 (struct objc_submethod_helper_data
*) arg
;
1669 if (s
->f (s
->pc
, s
->new_pc
) == 0)
1676 find_objc_msgcall_submethod (int (*f
) (CORE_ADDR
, CORE_ADDR
*),
1680 struct objc_submethod_helper_data s
;
1686 if (catch_errors (find_objc_msgcall_submethod_helper
,
1688 "Unable to determine target of Objective-C method call (ignoring):\n",
1689 RETURN_MASK_ALL
) == 0)
1696 find_objc_msgcall (CORE_ADDR pc
, CORE_ADDR
*new_pc
)
1700 find_objc_msgsend ();
1701 if (new_pc
!= NULL
) { *new_pc
= 0; }
1703 for (i
= 0; i
< nmethcalls
; i
++)
1704 if ((pc
>= methcalls
[i
].begin
) && (pc
< methcalls
[i
].end
))
1706 if (methcalls
[i
].stop_at
!= NULL
)
1707 return find_objc_msgcall_submethod (methcalls
[i
].stop_at
,
1717 _initialize_objc_language (void)
1719 add_language (&objc_language_defn
);
1720 add_info ("selectors", selectors_info
, /* INFO SELECTORS command. */
1721 "All Objective-C selectors, or those matching REGEXP.");
1722 add_info ("classes", classes_info
, /* INFO CLASSES command. */
1723 "All Objective-C classes, or those matching REGEXP.");
1724 add_com ("print-object", class_vars
, print_object_command
,
1725 "Ask an Objective-C object to print itself.");
1726 add_com_alias ("po", "print-object", class_vars
, 1);
1729 #if defined (__powerpc__) || defined (__ppc__)
1730 static unsigned long FETCH_ARGUMENT (int i
)
1732 return read_register (3 + i
);
1734 #elif defined (__i386__)
1735 static unsigned long FETCH_ARGUMENT (int i
)
1737 CORE_ADDR stack
= read_register (SP_REGNUM
);
1738 return read_memory_unsigned_integer (stack
+ (4 * (i
+ 1)), 4);
1740 #elif defined (__sparc__)
1741 static unsigned long FETCH_ARGUMENT (int i
)
1743 return read_register (O0_REGNUM
+ i
);
1745 #elif defined (__hppa__) || defined (__hppa)
1746 static unsigned long FETCH_ARGUMENT (int i
)
1748 return read_register (R0_REGNUM
+ 26 - i
);
1751 #error unknown architecture
1754 #if defined (__hppa__) || defined (__hppa)
1755 static CORE_ADDR
CONVERT_FUNCPTR (CORE_ADDR pc
)
1758 pc
= (CORE_ADDR
) read_memory_integer (pc
& ~0x3, 4);
1763 static CORE_ADDR
CONVERT_FUNCPTR (CORE_ADDR pc
)
1770 read_objc_method (CORE_ADDR addr
, struct objc_method
*method
)
1772 method
->name
= read_memory_unsigned_integer (addr
+ 0, 4);
1773 method
->types
= read_memory_unsigned_integer (addr
+ 4, 4);
1774 method
->imp
= read_memory_unsigned_integer (addr
+ 8, 4);
1778 unsigned long read_objc_methlist_nmethods (CORE_ADDR addr
)
1780 return read_memory_unsigned_integer (addr
+ 4, 4);
1784 read_objc_methlist_method (CORE_ADDR addr
, unsigned long num
,
1785 struct objc_method
*method
)
1787 CHECK_FATAL (num
< read_objc_methlist_nmethods (addr
));
1788 read_objc_method (addr
+ 8 + (12 * num
), method
);
1792 read_objc_object (CORE_ADDR addr
, struct objc_object
*object
)
1794 object
->isa
= read_memory_unsigned_integer (addr
, 4);
1798 read_objc_super (CORE_ADDR addr
, struct objc_super
*super
)
1800 super
->receiver
= read_memory_unsigned_integer (addr
, 4);
1801 super
->class = read_memory_unsigned_integer (addr
+ 4, 4);
1805 read_objc_class (CORE_ADDR addr
, struct objc_class
*class)
1807 class->isa
= read_memory_unsigned_integer (addr
, 4);
1808 class->super_class
= read_memory_unsigned_integer (addr
+ 4, 4);
1809 class->name
= read_memory_unsigned_integer (addr
+ 8, 4);
1810 class->version
= read_memory_unsigned_integer (addr
+ 12, 4);
1811 class->info
= read_memory_unsigned_integer (addr
+ 16, 4);
1812 class->instance_size
= read_memory_unsigned_integer (addr
+ 18, 4);
1813 class->ivars
= read_memory_unsigned_integer (addr
+ 24, 4);
1814 class->methods
= read_memory_unsigned_integer (addr
+ 28, 4);
1815 class->cache
= read_memory_unsigned_integer (addr
+ 32, 4);
1816 class->protocols
= read_memory_unsigned_integer (addr
+ 36, 4);
1820 find_implementation_from_class (CORE_ADDR
class, CORE_ADDR sel
)
1822 CORE_ADDR subclass
= class;
1824 while (subclass
!= 0)
1827 struct objc_class class_str
;
1828 unsigned mlistnum
= 0;
1830 read_objc_class (subclass
, &class_str
);
1835 unsigned long nmethods
;
1838 mlist
= read_memory_unsigned_integer (class_str
.methods
+
1843 nmethods
= read_objc_methlist_nmethods (mlist
);
1845 for (i
= 0; i
< nmethods
; i
++)
1847 struct objc_method meth_str
;
1848 read_objc_methlist_method (mlist
, i
, &meth_str
);
1852 "checking method 0x%lx against selector 0x%lx\n",
1853 meth_str
.name
, sel
);
1856 if (meth_str
.name
== sel
)
1857 return CONVERT_FUNCPTR (meth_str
.imp
);
1861 subclass
= class_str
.super_class
;
1868 find_implementation (CORE_ADDR object
, CORE_ADDR sel
)
1870 struct objc_object ostr
;
1874 read_objc_object (object
, &ostr
);
1878 return find_implementation_from_class (ostr
.isa
, sel
);
1882 resolve_msgsend (CORE_ADDR pc
, CORE_ADDR
*new_pc
)
1888 object
= FETCH_ARGUMENT (0);
1889 sel
= FETCH_ARGUMENT (1);
1891 res
= find_implementation (object
, sel
);
1900 resolve_msgsend_stret (CORE_ADDR pc
, CORE_ADDR
*new_pc
)
1906 object
= FETCH_ARGUMENT (1);
1907 sel
= FETCH_ARGUMENT (2);
1909 res
= find_implementation (object
, sel
);
1918 resolve_msgsend_super (CORE_ADDR pc
, CORE_ADDR
*new_pc
)
1920 struct objc_super sstr
;
1926 super
= FETCH_ARGUMENT (0);
1927 sel
= FETCH_ARGUMENT (1);
1929 read_objc_super (super
, &sstr
);
1930 if (sstr
.class == 0)
1933 res
= find_implementation_from_class (sstr
.class, sel
);
1942 resolve_msgsend_super_stret (CORE_ADDR pc
, CORE_ADDR
*new_pc
)
1944 struct objc_super sstr
;
1950 super
= FETCH_ARGUMENT (1);
1951 sel
= FETCH_ARGUMENT (2);
1953 read_objc_super (super
, &sstr
);
1954 if (sstr
.class == 0)
1957 res
= find_implementation_from_class (sstr
.class, sel
);