1 /* Objective-C language support routines for GDB, the GNU debugger.
3 Copyright 2002, 2003 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"
56 CORE_ADDR super_class
;
78 /* Complaints about ObjC classes, selectors, etc. */
80 #if (!defined __GNUC__ || __GNUC__ < 2 || __GNUC_MINOR__ < (defined __cplusplus ? 6 : 4))
81 #define __CHECK_FUNCTION ((__const char *) 0)
83 #define __CHECK_FUNCTION __PRETTY_FUNCTION__
86 #define CHECK(expression) \
87 ((void) ((expression) ? 0 : gdb_check (#expression, __FILE__, __LINE__, \
90 #define CHECK_FATAL(expression) \
91 ((void) ((expression) ? 0 : gdb_check_fatal (#expression, __FILE__, \
92 __LINE__, __CHECK_FUNCTION)))
95 gdb_check (const char *str
, const char *file
,
96 unsigned int line
, const char *func
)
98 error ("assertion failure on line %u of \"%s\" in function \"%s\": %s\n",
99 line
, file
, func
, str
);
103 gdb_check_fatal (const char *str
, const char *file
,
104 unsigned int line
, const char *func
)
106 internal_error (file
, line
,
107 "assertion failure in function \"%s\": %s\n", func
, str
);
110 /* Lookup a structure type named "struct NAME", visible in lexical
111 block BLOCK. If NOERR is nonzero, return zero if NAME is not
115 lookup_struct_typedef (char *name
, struct block
*block
, int noerr
)
117 register struct symbol
*sym
;
119 sym
= lookup_symbol (name
, block
, STRUCT_DOMAIN
, 0,
120 (struct symtab
**) NULL
);
127 error ("No struct type named %s.", name
);
129 if (TYPE_CODE (SYMBOL_TYPE (sym
)) != TYPE_CODE_STRUCT
)
134 error ("This context has class, union or enum %s, not a struct.",
141 lookup_objc_class (char *classname
)
143 struct value
* function
, *classval
;
145 if (! target_has_execution
)
147 /* Can't call into inferior to lookup class. */
151 if (lookup_minimal_symbol("objc_lookUpClass", 0, 0))
152 function
= find_function_in_inferior("objc_lookUpClass");
153 else if (lookup_minimal_symbol ("objc_lookup_class", 0, 0))
154 function
= find_function_in_inferior("objc_lookup_class");
157 complaint (&symfile_complaints
, "no way to lookup Objective-C classes");
161 classval
= value_string (classname
, strlen (classname
) + 1);
162 classval
= value_coerce_array (classval
);
163 return (CORE_ADDR
) value_as_long (call_function_by_hand (function
,
168 lookup_child_selector (char *selname
)
170 struct value
* function
, *selstring
;
172 if (! target_has_execution
)
174 /* Can't call into inferior to lookup selector. */
178 if (lookup_minimal_symbol("sel_getUid", 0, 0))
179 function
= find_function_in_inferior("sel_getUid");
180 else if (lookup_minimal_symbol ("sel_get_any_uid", 0, 0))
181 function
= find_function_in_inferior("sel_get_any_uid");
184 complaint (&symfile_complaints
, "no way to lookup Objective-C selectors");
188 selstring
= value_coerce_array (value_string (selname
,
189 strlen (selname
) + 1));
190 return value_as_long (call_function_by_hand (function
, 1, &selstring
));
194 value_nsstring (char *ptr
, int len
)
196 struct value
*stringValue
[3];
197 struct value
*function
, *nsstringValue
;
201 if (!target_has_execution
)
202 return 0; /* Can't call into inferior to create NSString. */
204 sym
= lookup_struct_typedef("NSString", 0, 1);
206 sym
= lookup_struct_typedef("NXString", 0, 1);
208 type
= lookup_pointer_type(builtin_type_void
);
210 type
= lookup_pointer_type(SYMBOL_TYPE (sym
));
212 stringValue
[2] = value_string(ptr
, len
);
213 stringValue
[2] = value_coerce_array(stringValue
[2]);
214 /* _NSNewStringFromCString replaces "istr" after Lantern2A. */
215 if (lookup_minimal_symbol("_NSNewStringFromCString", 0, 0))
217 function
= find_function_in_inferior("_NSNewStringFromCString");
218 nsstringValue
= call_function_by_hand(function
, 1, &stringValue
[2]);
220 else if (lookup_minimal_symbol("istr", 0, 0))
222 function
= find_function_in_inferior("istr");
223 nsstringValue
= call_function_by_hand(function
, 1, &stringValue
[2]);
225 else if (lookup_minimal_symbol("+[NSString stringWithCString:]", 0, 0))
227 function
= find_function_in_inferior("+[NSString stringWithCString:]");
228 stringValue
[0] = value_from_longest
229 (builtin_type_long
, lookup_objc_class ("NSString"));
230 stringValue
[1] = value_from_longest
231 (builtin_type_long
, lookup_child_selector ("stringWithCString:"));
232 nsstringValue
= call_function_by_hand(function
, 3, &stringValue
[0]);
235 error ("NSString: internal error -- no way to create new NSString");
237 VALUE_TYPE(nsstringValue
) = type
;
238 return nsstringValue
;
241 /* Objective-C name demangling. */
244 objc_demangle (const char *mangled
, int options
)
246 char *demangled
, *cp
;
248 if (mangled
[0] == '_' &&
249 (mangled
[1] == 'i' || mangled
[1] == 'c') &&
252 cp
= demangled
= xmalloc(strlen(mangled
) + 2);
254 if (mangled
[1] == 'i')
255 *cp
++ = '-'; /* for instance method */
257 *cp
++ = '+'; /* for class method */
259 *cp
++ = '['; /* opening left brace */
260 strcpy(cp
, mangled
+3); /* tack on the rest of the mangled name */
262 while (*cp
&& *cp
== '_')
263 cp
++; /* skip any initial underbars in class name */
265 cp
= strchr(cp
, '_');
266 if (!cp
) /* find first non-initial underbar */
268 xfree(demangled
); /* not mangled name */
271 if (cp
[1] == '_') { /* easy case: no category name */
272 *cp
++ = ' '; /* replace two '_' with one ' ' */
273 strcpy(cp
, mangled
+ (cp
- demangled
) + 2);
276 *cp
++ = '('; /* less easy case: category name */
277 cp
= strchr(cp
, '_');
280 xfree(demangled
); /* not mangled name */
284 *cp
++ = ' '; /* overwriting 1st char of method name... */
285 strcpy(cp
, mangled
+ (cp
- demangled
)); /* get it back */
288 while (*cp
&& *cp
== '_')
289 cp
++; /* skip any initial underbars in method name */
293 *cp
= ':'; /* replace remaining '_' with ':' */
295 *cp
++ = ']'; /* closing right brace */
296 *cp
++ = 0; /* string terminator */
300 return NULL
; /* Not an objc mangled name. */
303 /* Print the character C on STREAM as part of the contents of a
304 literal string whose delimiter is QUOTER. Note that that format
305 for printing characters and strings is language specific. */
308 objc_emit_char (register int c
, struct ui_file
*stream
, int quoter
)
311 c
&= 0xFF; /* Avoid sign bit follies. */
313 if (PRINT_LITERAL_FORM (c
))
315 if (c
== '\\' || c
== quoter
)
317 fputs_filtered ("\\", stream
);
319 fprintf_filtered (stream
, "%c", c
);
326 fputs_filtered ("\\n", stream
);
329 fputs_filtered ("\\b", stream
);
332 fputs_filtered ("\\t", stream
);
335 fputs_filtered ("\\f", stream
);
338 fputs_filtered ("\\r", stream
);
341 fputs_filtered ("\\e", stream
);
344 fputs_filtered ("\\a", stream
);
347 fprintf_filtered (stream
, "\\%.3o", (unsigned int) c
);
354 objc_printchar (int c
, struct ui_file
*stream
)
356 fputs_filtered ("'", stream
);
357 objc_emit_char (c
, stream
, '\'');
358 fputs_filtered ("'", stream
);
361 /* Print the character string STRING, printing at most LENGTH
362 characters. Printing stops early if the number hits print_max;
363 repeat counts are printed as appropriate. Print ellipses at the
364 end if we had to stop before printing LENGTH characters, or if
368 objc_printstr (struct ui_file
*stream
, char *string
,
369 unsigned int length
, int width
, int force_ellipses
)
371 register unsigned int i
;
372 unsigned int things_printed
= 0;
375 extern int inspect_it
;
377 /* If the string was not truncated due to `set print elements', and
378 the last byte of it is a null, we don't print that, in
379 traditional C style. */
380 if ((!force_ellipses
) && length
> 0 && string
[length
-1] == '\0')
385 fputs_filtered ("\"\"", stream
);
389 for (i
= 0; i
< length
&& things_printed
< print_max
; ++i
)
391 /* Position of the character we are examining to see whether it
394 /* Number of repetitions we have detected so far. */
401 fputs_filtered (", ", stream
);
407 while (rep1
< length
&& string
[rep1
] == string
[i
])
413 if (reps
> repeat_count_threshold
)
418 fputs_filtered ("\\\", ", stream
);
420 fputs_filtered ("\", ", stream
);
423 objc_printchar (string
[i
], stream
);
424 fprintf_filtered (stream
, " <repeats %u times>", reps
);
426 things_printed
+= repeat_count_threshold
;
434 fputs_filtered ("\\\"", stream
);
436 fputs_filtered ("\"", stream
);
439 objc_emit_char (string
[i
], stream
, '"');
444 /* Terminate the quotes if necessary. */
448 fputs_filtered ("\\\"", stream
);
450 fputs_filtered ("\"", stream
);
453 if (force_ellipses
|| i
< length
)
454 fputs_filtered ("...", stream
);
457 /* Create a fundamental C type using default reasonable for the
460 Some object/debugging file formats (DWARF version 1, COFF, etc) do
461 not define fundamental types such as "int" or "double". Others
462 (stabs or DWARF version 2, etc) do define fundamental types. For
463 the formats which don't provide fundamental types, gdb can create
464 such types using this function.
466 FIXME: Some compilers distinguish explicitly signed integral types
467 (signed short, signed int, signed long) from "regular" integral
468 types (short, int, long) in the debugging information. There is
469 some disagreement as to how useful this feature is. In particular,
470 gcc does not support this. Also, only some debugging formats allow
471 the distinction to be passed on to a debugger. For now, we always
472 just use "short", "int", or "long" as the type name, for both the
473 implicit and explicitly signed types. This also makes life easier
474 for the gdb test suite since we don't have to account for the
475 differences in output depending upon what the compiler and
476 debugging format support. We will probably have to re-examine the
477 issue when gdb starts taking it's fundamental type information
478 directly from the debugging information supplied by the compiler.
482 objc_create_fundamental_type (struct objfile
*objfile
, int typeid)
484 register struct type
*type
= NULL
;
489 /* FIXME: For now, if we are asked to produce a type not in
490 this language, create the equivalent of a C integer type
491 with the name "<?type?>". When all the dust settles from
492 the type reconstruction work, this should probably become
494 type
= init_type (TYPE_CODE_INT
,
495 TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
496 0, "<?type?>", objfile
);
497 warning ("internal error: no C/C++ fundamental type %d", typeid);
500 type
= init_type (TYPE_CODE_VOID
,
501 TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
505 type
= init_type (TYPE_CODE_INT
,
506 TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
510 type
= init_type (TYPE_CODE_INT
,
511 TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
512 0, "signed char", objfile
);
514 case FT_UNSIGNED_CHAR
:
515 type
= init_type (TYPE_CODE_INT
,
516 TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
517 TYPE_FLAG_UNSIGNED
, "unsigned char", objfile
);
520 type
= init_type (TYPE_CODE_INT
,
521 TARGET_SHORT_BIT
/ TARGET_CHAR_BIT
,
522 0, "short", objfile
);
524 case FT_SIGNED_SHORT
:
525 type
= init_type (TYPE_CODE_INT
,
526 TARGET_SHORT_BIT
/ TARGET_CHAR_BIT
,
527 0, "short", objfile
); /* FIXME-fnf */
529 case FT_UNSIGNED_SHORT
:
530 type
= init_type (TYPE_CODE_INT
,
531 TARGET_SHORT_BIT
/ TARGET_CHAR_BIT
,
532 TYPE_FLAG_UNSIGNED
, "unsigned short", objfile
);
535 type
= init_type (TYPE_CODE_INT
,
536 TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
539 case FT_SIGNED_INTEGER
:
540 type
= init_type (TYPE_CODE_INT
,
541 TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
542 0, "int", objfile
); /* FIXME -fnf */
544 case FT_UNSIGNED_INTEGER
:
545 type
= init_type (TYPE_CODE_INT
,
546 TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
547 TYPE_FLAG_UNSIGNED
, "unsigned int", objfile
);
550 type
= init_type (TYPE_CODE_INT
,
551 TARGET_LONG_BIT
/ TARGET_CHAR_BIT
,
555 type
= init_type (TYPE_CODE_INT
,
556 TARGET_LONG_BIT
/ TARGET_CHAR_BIT
,
557 0, "long", objfile
); /* FIXME -fnf */
559 case FT_UNSIGNED_LONG
:
560 type
= init_type (TYPE_CODE_INT
,
561 TARGET_LONG_BIT
/ TARGET_CHAR_BIT
,
562 TYPE_FLAG_UNSIGNED
, "unsigned long", objfile
);
565 type
= init_type (TYPE_CODE_INT
,
566 TARGET_LONG_LONG_BIT
/ TARGET_CHAR_BIT
,
567 0, "long long", objfile
);
569 case FT_SIGNED_LONG_LONG
:
570 type
= init_type (TYPE_CODE_INT
,
571 TARGET_LONG_LONG_BIT
/ TARGET_CHAR_BIT
,
572 0, "signed long long", objfile
);
574 case FT_UNSIGNED_LONG_LONG
:
575 type
= init_type (TYPE_CODE_INT
,
576 TARGET_LONG_LONG_BIT
/ TARGET_CHAR_BIT
,
577 TYPE_FLAG_UNSIGNED
, "unsigned long long", objfile
);
580 type
= init_type (TYPE_CODE_FLT
,
581 TARGET_FLOAT_BIT
/ TARGET_CHAR_BIT
,
582 0, "float", objfile
);
584 case FT_DBL_PREC_FLOAT
:
585 type
= init_type (TYPE_CODE_FLT
,
586 TARGET_DOUBLE_BIT
/ TARGET_CHAR_BIT
,
587 0, "double", objfile
);
589 case FT_EXT_PREC_FLOAT
:
590 type
= init_type (TYPE_CODE_FLT
,
591 TARGET_LONG_DOUBLE_BIT
/ TARGET_CHAR_BIT
,
592 0, "long double", objfile
);
598 /* Determine if we are currently in the Objective-C dispatch function.
599 If so, get the address of the method function that the dispatcher
600 would call and use that as the function to step into instead. Also
601 skip over the trampoline for the function (if any). This is better
602 for the user since they are only interested in stepping into the
603 method function anyway. */
605 objc_skip_trampoline (CORE_ADDR stop_pc
)
607 CORE_ADDR real_stop_pc
;
608 CORE_ADDR method_stop_pc
;
610 real_stop_pc
= SKIP_TRAMPOLINE_CODE (stop_pc
);
612 if (real_stop_pc
!= 0)
613 find_objc_msgcall (real_stop_pc
, &method_stop_pc
);
615 find_objc_msgcall (stop_pc
, &method_stop_pc
);
619 real_stop_pc
= SKIP_TRAMPOLINE_CODE (method_stop_pc
);
620 if (real_stop_pc
== 0)
621 real_stop_pc
= method_stop_pc
;
628 /* Table mapping opcodes into strings for printing operators
629 and precedences of the operators. */
631 static const struct op_print objc_op_print_tab
[] =
633 {",", BINOP_COMMA
, PREC_COMMA
, 0},
634 {"=", BINOP_ASSIGN
, PREC_ASSIGN
, 1},
635 {"||", BINOP_LOGICAL_OR
, PREC_LOGICAL_OR
, 0},
636 {"&&", BINOP_LOGICAL_AND
, PREC_LOGICAL_AND
, 0},
637 {"|", BINOP_BITWISE_IOR
, PREC_BITWISE_IOR
, 0},
638 {"^", BINOP_BITWISE_XOR
, PREC_BITWISE_XOR
, 0},
639 {"&", BINOP_BITWISE_AND
, PREC_BITWISE_AND
, 0},
640 {"==", BINOP_EQUAL
, PREC_EQUAL
, 0},
641 {"!=", BINOP_NOTEQUAL
, PREC_EQUAL
, 0},
642 {"<=", BINOP_LEQ
, PREC_ORDER
, 0},
643 {">=", BINOP_GEQ
, PREC_ORDER
, 0},
644 {">", BINOP_GTR
, PREC_ORDER
, 0},
645 {"<", BINOP_LESS
, PREC_ORDER
, 0},
646 {">>", BINOP_RSH
, PREC_SHIFT
, 0},
647 {"<<", BINOP_LSH
, PREC_SHIFT
, 0},
648 {"+", BINOP_ADD
, PREC_ADD
, 0},
649 {"-", BINOP_SUB
, PREC_ADD
, 0},
650 {"*", BINOP_MUL
, PREC_MUL
, 0},
651 {"/", BINOP_DIV
, PREC_MUL
, 0},
652 {"%", BINOP_REM
, PREC_MUL
, 0},
653 {"@", BINOP_REPEAT
, PREC_REPEAT
, 0},
654 {"-", UNOP_NEG
, PREC_PREFIX
, 0},
655 {"!", UNOP_LOGICAL_NOT
, PREC_PREFIX
, 0},
656 {"~", UNOP_COMPLEMENT
, PREC_PREFIX
, 0},
657 {"*", UNOP_IND
, PREC_PREFIX
, 0},
658 {"&", UNOP_ADDR
, PREC_PREFIX
, 0},
659 {"sizeof ", UNOP_SIZEOF
, PREC_PREFIX
, 0},
660 {"++", UNOP_PREINCREMENT
, PREC_PREFIX
, 0},
661 {"--", UNOP_PREDECREMENT
, PREC_PREFIX
, 0},
665 struct type
** const (objc_builtin_types
[]) =
672 &builtin_type_double
,
674 &builtin_type_long_long
,
675 &builtin_type_signed_char
,
676 &builtin_type_unsigned_char
,
677 &builtin_type_unsigned_short
,
678 &builtin_type_unsigned_int
,
679 &builtin_type_unsigned_long
,
680 &builtin_type_unsigned_long_long
,
681 &builtin_type_long_double
,
682 &builtin_type_complex
,
683 &builtin_type_double_complex
,
687 const struct language_defn objc_language_defn
= {
688 "objective-c", /* Language name */
696 evaluate_subexp_standard
,
697 objc_printchar
, /* Print a character constant */
698 objc_printstr
, /* Function to print string constant */
700 objc_create_fundamental_type
, /* Create fundamental type in this language */
701 c_print_type
, /* Print a type using appropriate syntax */
702 c_val_print
, /* Print a value using appropriate syntax */
703 c_value_print
, /* Print a top-level value */
704 objc_skip_trampoline
, /* Language specific skip_trampoline */
705 objc_demangle
, /* Language specific symbol demangler */
706 {"", "", "", ""}, /* Binary format info */
707 {"0%lo", "0", "o", ""}, /* Octal format info */
708 {"%ld", "", "d", ""}, /* Decimal format info */
709 {"0x%lx", "0x", "x", ""}, /* Hex format info */
710 objc_op_print_tab
, /* Expression operators for printing */
711 1, /* C-style arrays */
712 0, /* String lower bound */
713 &builtin_type_char
, /* Type of string elements */
719 * Following functions help construct Objective-C message calls
722 struct selname
/* For parsing Objective-C. */
724 struct selname
*next
;
729 static int msglist_len
;
730 static struct selname
*selname_chain
;
731 static char *msglist_sel
;
736 register struct selname
*new =
737 (struct selname
*) xmalloc (sizeof (struct selname
));
739 new->next
= selname_chain
;
740 new->msglist_len
= msglist_len
;
741 new->msglist_sel
= msglist_sel
;
743 msglist_sel
= (char *)xmalloc(1);
749 add_msglist(struct stoken
*str
, int addcolon
)
754 if (str
== 0) { /* Unnamed arg, or... */
755 if (addcolon
== 0) { /* variable number of args. */
765 len
= plen
+ strlen(msglist_sel
) + 2;
766 s
= (char *)xmalloc(len
);
767 strcpy(s
, msglist_sel
);
782 register int val
= msglist_len
;
783 register struct selname
*sel
= selname_chain
;
784 register char *p
= msglist_sel
;
787 selname_chain
= sel
->next
;
788 msglist_len
= sel
->msglist_len
;
789 msglist_sel
= sel
->msglist_sel
;
790 selid
= lookup_child_selector(p
);
792 error("Can't find selector \"%s\"", p
);
793 write_exp_elt_longcst (selid
);
795 write_exp_elt_longcst (val
); /* Number of args */
802 * Function: specialcmp (char *a, char *b)
804 * Special strcmp: treats ']' and ' ' as end-of-string.
805 * Used for qsorting lists of objc methods (either by class or selector).
808 int specialcmp(char *a
, char *b
)
810 while (*a
&& *a
!= ' ' && *a
!= ']' && *b
&& *b
!= ' ' && *b
!= ']')
816 if (*a
&& *a
!= ' ' && *a
!= ']')
817 return 1; /* a is longer therefore greater */
818 if (*b
&& *b
!= ' ' && *b
!= ']')
819 return -1; /* a is shorter therefore lesser */
820 return 0; /* a and b are identical */
824 * Function: compare_selectors (const void *, const void *)
826 * Comparison function for use with qsort. Arguments are symbols or
827 * msymbols Compares selector part of objc method name alphabetically.
831 compare_selectors (const void *a
, const void *b
)
835 aname
= SYMBOL_PRINT_NAME (*(struct symbol
**) a
);
836 bname
= SYMBOL_PRINT_NAME (*(struct symbol
**) b
);
837 if (aname
== NULL
|| bname
== NULL
)
838 error ("internal: compare_selectors(1)");
840 aname
= strchr(aname
, ' ');
841 bname
= strchr(bname
, ' ');
842 if (aname
== NULL
|| bname
== NULL
)
843 error ("internal: compare_selectors(2)");
845 return specialcmp (aname
+1, bname
+1);
849 * Function: selectors_info (regexp, from_tty)
851 * Implements the "Info selectors" command. Takes an optional regexp
852 * arg. Lists all objective c selectors that match the regexp. Works
853 * by grepping thru all symbols for objective c methods. Output list
854 * is sorted and uniqued.
858 selectors_info (char *regexp
, int from_tty
)
860 struct objfile
*objfile
;
861 struct minimal_symbol
*msymbol
;
869 struct symbol
**sym_arr
;
873 strcpy(myregexp
, ".*]"); /* Null input, match all objc methods. */
876 if (*regexp
== '+' || *regexp
== '-')
877 { /* User wants only class methods or only instance methods. */
878 plusminus
= *regexp
++;
879 while (*regexp
== ' ' || *regexp
== '\t')
883 strcpy(myregexp
, ".*]");
886 strcpy(myregexp
, regexp
);
887 if (myregexp
[strlen(myregexp
) - 1] == '$') /* end of selector */
888 myregexp
[strlen(myregexp
) - 1] = ']'; /* end of method name */
890 strcat(myregexp
, ".*]");
896 val
= re_comp (myregexp
);
898 error ("Invalid regexp (%s): %s", val
, regexp
);
901 /* First time thru is JUST to get max length and count. */
902 ALL_MSYMBOLS (objfile
, msymbol
)
905 name
= SYMBOL_NATURAL_NAME (msymbol
);
907 (name
[0] == '-' || name
[0] == '+') &&
908 name
[1] == '[') /* Got a method name. */
910 /* Filter for class/instance methods. */
911 if (plusminus
&& name
[0] != plusminus
)
913 /* Find selector part. */
914 name
= (char *) strchr(name
+2, ' ');
915 if (regexp
== NULL
|| re_exec(++name
) != 0)
917 char *mystart
= name
;
918 char *myend
= (char *) strchr(mystart
, ']');
920 if (myend
&& (myend
- mystart
> maxlen
))
921 maxlen
= myend
- mystart
; /* Get longest selector. */
928 printf_filtered ("Selectors matching \"%s\":\n\n",
929 regexp
? regexp
: "*");
931 sym_arr
= alloca (matches
* sizeof (struct symbol
*));
933 ALL_MSYMBOLS (objfile
, msymbol
)
936 name
= SYMBOL_NATURAL_NAME (msymbol
);
938 (name
[0] == '-' || name
[0] == '+') &&
939 name
[1] == '[') /* Got a method name. */
941 /* Filter for class/instance methods. */
942 if (plusminus
&& name
[0] != plusminus
)
944 /* Find selector part. */
945 name
= (char *) strchr(name
+2, ' ');
946 if (regexp
== NULL
|| re_exec(++name
) != 0)
947 sym_arr
[matches
++] = (struct symbol
*) msymbol
;
951 qsort (sym_arr
, matches
, sizeof (struct minimal_symbol
*),
953 /* Prevent compare on first iteration. */
955 for (ix
= 0; ix
< matches
; ix
++) /* Now do the output. */
960 name
= SYMBOL_NATURAL_NAME (sym_arr
[ix
]);
961 name
= strchr (name
, ' ') + 1;
962 if (p
[0] && specialcmp(name
, p
) == 0)
963 continue; /* Seen this one already (not unique). */
965 /* Copy selector part. */
966 while (*name
&& *name
!= ']')
969 /* Print in columns. */
970 puts_filtered_tabular(asel
, maxlen
+ 1, 0);
975 printf_filtered ("No selectors matching \"%s\"\n", regexp
? regexp
: "*");
979 * Function: compare_classes (const void *, const void *)
981 * Comparison function for use with qsort. Arguments are symbols or
982 * msymbols Compares class part of objc method name alphabetically.
986 compare_classes (const void *a
, const void *b
)
990 aname
= SYMBOL_PRINT_NAME (*(struct symbol
**) a
);
991 bname
= SYMBOL_PRINT_NAME (*(struct symbol
**) b
);
992 if (aname
== NULL
|| bname
== NULL
)
993 error ("internal: compare_classes(1)");
995 return specialcmp (aname
+1, bname
+1);
999 * Function: classes_info(regexp, from_tty)
1001 * Implements the "info classes" command for objective c classes.
1002 * Lists all objective c classes that match the optional regexp.
1003 * Works by grepping thru the list of objective c methods. List will
1004 * be sorted and uniqued (since one class may have many methods).
1005 * BUGS: will not list a class that has no methods.
1009 classes_info (char *regexp
, int from_tty
)
1011 struct objfile
*objfile
;
1012 struct minimal_symbol
*msymbol
;
1018 char myregexp
[2048];
1020 struct symbol
**sym_arr
;
1023 strcpy(myregexp
, ".* "); /* Null input: match all objc classes. */
1026 strcpy(myregexp
, regexp
);
1027 if (myregexp
[strlen(myregexp
) - 1] == '$')
1028 /* In the method name, the end of the class name is marked by ' '. */
1029 myregexp
[strlen(myregexp
) - 1] = ' ';
1031 strcat(myregexp
, ".* ");
1036 val
= re_comp (myregexp
);
1038 error ("Invalid regexp (%s): %s", val
, regexp
);
1041 /* First time thru is JUST to get max length and count. */
1042 ALL_MSYMBOLS (objfile
, msymbol
)
1045 name
= SYMBOL_NATURAL_NAME (msymbol
);
1047 (name
[0] == '-' || name
[0] == '+') &&
1048 name
[1] == '[') /* Got a method name. */
1049 if (regexp
== NULL
|| re_exec(name
+2) != 0)
1051 /* Compute length of classname part. */
1052 char *mystart
= name
+ 2;
1053 char *myend
= (char *) strchr(mystart
, ' ');
1055 if (myend
&& (myend
- mystart
> maxlen
))
1056 maxlen
= myend
- mystart
;
1062 printf_filtered ("Classes matching \"%s\":\n\n",
1063 regexp
? regexp
: "*");
1064 sym_arr
= alloca (matches
* sizeof (struct symbol
*));
1066 ALL_MSYMBOLS (objfile
, msymbol
)
1069 name
= SYMBOL_NATURAL_NAME (msymbol
);
1071 (name
[0] == '-' || name
[0] == '+') &&
1072 name
[1] == '[') /* Got a method name. */
1073 if (regexp
== NULL
|| re_exec(name
+2) != 0)
1074 sym_arr
[matches
++] = (struct symbol
*) msymbol
;
1077 qsort (sym_arr
, matches
, sizeof (struct minimal_symbol
*),
1079 /* Prevent compare on first iteration. */
1081 for (ix
= 0; ix
< matches
; ix
++) /* Now do the output. */
1086 name
= SYMBOL_NATURAL_NAME (sym_arr
[ix
]);
1088 if (p
[0] && specialcmp(name
, p
) == 0)
1089 continue; /* Seen this one already (not unique). */
1091 /* Copy class part of method name. */
1092 while (*name
&& *name
!= ' ')
1095 /* Print in columns. */
1096 puts_filtered_tabular(aclass
, maxlen
+ 1, 0);
1101 printf_filtered ("No classes matching \"%s\"\n", regexp
? regexp
: "*");
1105 * Function: find_imps (char *selector, struct symbol **sym_arr)
1107 * Input: a string representing a selector
1108 * a pointer to an array of symbol pointers
1109 * possibly a pointer to a symbol found by the caller.
1111 * Output: number of methods that implement that selector. Side
1112 * effects: The array of symbol pointers is filled with matching syms.
1114 * By analogy with function "find_methods" (symtab.c), builds a list
1115 * of symbols matching the ambiguous input, so that "decode_line_2"
1116 * (symtab.c) can list them and ask the user to choose one or more.
1117 * In this case the matches are objective c methods
1118 * ("implementations") matching an objective c selector.
1120 * Note that it is possible for a normal (c-style) function to have
1121 * the same name as an objective c selector. To prevent the selector
1122 * from eclipsing the function, we allow the caller (decode_line_1) to
1123 * search for such a function first, and if it finds one, pass it in
1124 * to us. We will then integrate it into the list. We also search
1125 * for one here, among the minsyms.
1127 * NOTE: if NUM_DEBUGGABLE is non-zero, the sym_arr will be divided
1128 * into two parts: debuggable (struct symbol) syms, and
1129 * non_debuggable (struct minimal_symbol) syms. The debuggable
1130 * ones will come first, before NUM_DEBUGGABLE (which will thus
1131 * be the index of the first non-debuggable one).
1135 * Function: total_number_of_imps (char *selector);
1137 * Input: a string representing a selector
1138 * Output: number of methods that implement that selector.
1140 * By analogy with function "total_number_of_methods", this allows
1141 * decode_line_1 (symtab.c) to detect if there are objective c methods
1142 * matching the input, and to allocate an array of pointers to them
1143 * which can be manipulated by "decode_line_2" (also in symtab.c).
1147 parse_selector (char *method
, char **selector
)
1151 int found_quote
= 0;
1153 char *nselector
= NULL
;
1155 CHECK (selector
!= NULL
);
1159 while (isspace (*s1
))
1166 while (isspace (*s1
))
1173 if (isalnum (*s2
) || (*s2
== '_') || (*s2
== ':'))
1175 else if (isspace (*s2
))
1177 else if ((*s2
== '\0') || (*s2
== '\''))
1185 while (isspace (*s2
))
1191 while (isspace (*s2
))
1195 if (selector
!= NULL
)
1196 *selector
= nselector
;
1202 parse_method (char *method
, char *type
, char **class,
1203 char **category
, char **selector
)
1207 int found_quote
= 0;
1210 char *nclass
= NULL
;
1211 char *ncategory
= NULL
;
1212 char *nselector
= NULL
;
1214 CHECK (type
!= NULL
);
1215 CHECK (class != NULL
);
1216 CHECK (category
!= NULL
);
1217 CHECK (selector
!= NULL
);
1221 while (isspace (*s1
))
1228 while (isspace (*s1
))
1231 if ((s1
[0] == '+') || (s1
[0] == '-'))
1234 while (isspace (*s1
))
1242 while (isalnum (*s1
) || (*s1
== '_'))
1246 while (isspace (*s2
))
1252 while (isspace (*s2
))
1255 while (isalnum (*s2
) || (*s2
== '_'))
1260 /* Truncate the class name now that we're not using the open paren. */
1267 if (isalnum (*s2
) || (*s2
== '_') || (*s2
== ':'))
1269 else if (isspace (*s2
))
1271 else if (*s2
== ']')
1280 while (isspace (*s2
))
1287 while (isspace (*s2
))
1295 if (category
!= NULL
)
1296 *category
= ncategory
;
1297 if (selector
!= NULL
)
1298 *selector
= nselector
;
1304 find_methods (struct symtab
*symtab
, char type
,
1305 const char *class, const char *category
,
1306 const char *selector
, struct symbol
**syms
,
1307 unsigned int *nsym
, unsigned int *ndebug
)
1309 struct objfile
*objfile
= NULL
;
1310 struct minimal_symbol
*msymbol
= NULL
;
1311 struct block
*block
= NULL
;
1312 struct symbol
*sym
= NULL
;
1314 char *symname
= NULL
;
1317 char *nclass
= NULL
;
1318 char *ncategory
= NULL
;
1319 char *nselector
= NULL
;
1321 unsigned int csym
= 0;
1322 unsigned int cdebug
= 0;
1324 static char *tmp
= NULL
;
1325 static unsigned int tmplen
= 0;
1327 CHECK (nsym
!= NULL
);
1328 CHECK (ndebug
!= NULL
);
1331 block
= BLOCKVECTOR_BLOCK (BLOCKVECTOR (symtab
), STATIC_BLOCK
);
1333 ALL_MSYMBOLS (objfile
, msymbol
)
1337 if ((msymbol
->type
!= mst_text
) && (msymbol
->type
!= mst_file_text
))
1338 /* Not a function or method. */
1342 if ((SYMBOL_VALUE_ADDRESS (msymbol
) < BLOCK_START (block
)) ||
1343 (SYMBOL_VALUE_ADDRESS (msymbol
) >= BLOCK_END (block
)))
1344 /* Not in the specified symtab. */
1347 symname
= SYMBOL_NATURAL_NAME (msymbol
);
1348 if (symname
== NULL
)
1351 if ((symname
[0] != '-' && symname
[0] != '+') || (symname
[1] != '['))
1352 /* Not a method name. */
1355 while ((strlen (symname
) + 1) >= tmplen
)
1357 tmplen
= (tmplen
== 0) ? 1024 : tmplen
* 2;
1358 tmp
= xrealloc (tmp
, tmplen
);
1360 strcpy (tmp
, symname
);
1362 if (parse_method (tmp
, &ntype
, &nclass
, &ncategory
, &nselector
) == NULL
)
1365 if ((type
!= '\0') && (ntype
!= type
))
1369 && ((nclass
== NULL
) || (strcmp (class, nclass
) != 0)))
1372 if ((category
!= NULL
) &&
1373 ((ncategory
== NULL
) || (strcmp (category
, ncategory
) != 0)))
1376 if ((selector
!= NULL
) &&
1377 ((nselector
== NULL
) || (strcmp (selector
, nselector
) != 0)))
1380 sym
= find_pc_function (SYMBOL_VALUE_ADDRESS (msymbol
));
1383 const char *newsymname
= SYMBOL_NATURAL_NAME (sym
);
1385 if (strcmp (symname
, newsymname
) == 0)
1387 /* Found a high-level method sym: swap it into the
1388 lower part of sym_arr (below num_debuggable). */
1391 syms
[csym
] = syms
[cdebug
];
1400 "debugging symbol \"%s\" does not match minimal symbol (\"%s\"); ignoring",
1401 newsymname
, symname
);
1403 syms
[csym
] = (struct symbol
*) msymbol
;
1409 /* Found a non-debuggable method symbol. */
1411 syms
[csym
] = (struct symbol
*) msymbol
;
1422 char *find_imps (struct symtab
*symtab
, struct block
*block
,
1423 char *method
, struct symbol
**syms
,
1424 unsigned int *nsym
, unsigned int *ndebug
)
1428 char *category
= NULL
;
1429 char *selector
= NULL
;
1431 unsigned int csym
= 0;
1432 unsigned int cdebug
= 0;
1434 unsigned int ncsym
= 0;
1435 unsigned int ncdebug
= 0;
1440 CHECK (nsym
!= NULL
);
1441 CHECK (ndebug
!= NULL
);
1448 buf
= (char *) alloca (strlen (method
) + 1);
1449 strcpy (buf
, method
);
1450 tmp
= parse_method (buf
, &type
, &class, &category
, &selector
);
1454 struct symtab
*sym_symtab
= NULL
;
1455 struct symbol
*sym
= NULL
;
1456 struct minimal_symbol
*msym
= NULL
;
1458 strcpy (buf
, method
);
1459 tmp
= parse_selector (buf
, &selector
);
1464 sym
= lookup_symbol (selector
, block
, VAR_DOMAIN
, 0, &sym_symtab
);
1474 msym
= lookup_minimal_symbol (selector
, 0, 0);
1479 syms
[csym
] = (struct symbol
*)msym
;
1485 find_methods (symtab
, type
, class, category
, selector
,
1486 syms
+ csym
, &ncsym
, &ncdebug
);
1488 find_methods (symtab
, type
, class, category
, selector
,
1489 NULL
, &ncsym
, &ncdebug
);
1491 /* If we didn't find any methods, just return. */
1492 if (ncsym
== 0 && ncdebug
== 0)
1495 /* Take debug symbols from the second batch of symbols and swap them
1496 * with debug symbols from the first batch. Repeat until either the
1497 * second section is out of debug symbols or the first section is
1498 * full of debug symbols. Either way we have all debug symbols
1499 * packed to the beginning of the buffer.
1504 while ((cdebug
< csym
) && (ncdebug
> 0))
1506 struct symbol
*s
= NULL
;
1507 /* First non-debugging symbol. */
1508 unsigned int i
= cdebug
;
1509 /* Last of second batch of debug symbols. */
1510 unsigned int j
= csym
+ ncdebug
- 1;
1516 /* We've moved a symbol from the second debug section to the
1532 return method
+ (tmp
- buf
);
1536 /* Sort debuggable symbols. */
1538 qsort (syms
, cdebug
, sizeof (struct minimal_symbol
*),
1541 /* Sort minimal_symbols. */
1542 if ((csym
- cdebug
) > 1)
1543 qsort (&syms
[cdebug
], csym
- cdebug
,
1544 sizeof (struct minimal_symbol
*), compare_classes
);
1546 /* Terminate the sym_arr list. */
1549 return method
+ (tmp
- buf
);
1553 print_object_command (char *args
, int from_tty
)
1555 struct value
*object
, *function
, *description
;
1556 CORE_ADDR string_addr
, object_addr
;
1560 if (!args
|| !*args
)
1562 "The 'print-object' command requires an argument (an Objective-C object)");
1565 struct expression
*expr
= parse_expression (args
);
1566 register struct cleanup
*old_chain
=
1567 make_cleanup (free_current_contents
, &expr
);
1570 object
= expr
->language_defn
->evaluate_exp (builtin_type_void_data_ptr
,
1571 expr
, &pc
, EVAL_NORMAL
);
1572 do_cleanups (old_chain
);
1575 /* Validate the address for sanity. */
1576 object_addr
= value_as_long (object
);
1577 read_memory (object_addr
, &c
, 1);
1579 function
= find_function_in_inferior ("_NSPrintForDebugger");
1580 if (function
== NULL
)
1581 error ("Unable to locate _NSPrintForDebugger in child process");
1583 description
= call_function_by_hand (function
, 1, &object
);
1585 string_addr
= value_as_long (description
);
1586 if (string_addr
== 0)
1587 error ("object returns null description");
1589 read_memory (string_addr
+ i
++, &c
, 1);
1592 { /* Read and print characters up to EOS. */
1594 printf_filtered ("%c", c
);
1595 read_memory (string_addr
+ i
++, &c
, 1);
1598 printf_filtered("<object returns empty description>");
1599 printf_filtered ("\n");
1602 /* The data structure 'methcalls' is used to detect method calls (thru
1603 * ObjC runtime lib functions objc_msgSend, objc_msgSendSuper, etc.),
1604 * and ultimately find the method being called.
1607 struct objc_methcall
{
1609 /* Return instance method to be called. */
1610 int (*stop_at
) (CORE_ADDR
, CORE_ADDR
*);
1611 /* Start of pc range corresponding to method invocation. */
1613 /* End of pc range corresponding to method invocation. */
1617 static int resolve_msgsend (CORE_ADDR pc
, CORE_ADDR
*new_pc
);
1618 static int resolve_msgsend_stret (CORE_ADDR pc
, CORE_ADDR
*new_pc
);
1619 static int resolve_msgsend_super (CORE_ADDR pc
, CORE_ADDR
*new_pc
);
1620 static int resolve_msgsend_super_stret (CORE_ADDR pc
, CORE_ADDR
*new_pc
);
1622 static struct objc_methcall methcalls
[] = {
1623 { "_objc_msgSend", resolve_msgsend
, 0, 0},
1624 { "_objc_msgSend_stret", resolve_msgsend_stret
, 0, 0},
1625 { "_objc_msgSendSuper", resolve_msgsend_super
, 0, 0},
1626 { "_objc_msgSendSuper_stret", resolve_msgsend_super_stret
, 0, 0},
1627 { "_objc_getClass", NULL
, 0, 0},
1628 { "_objc_getMetaClass", NULL
, 0, 0}
1631 #define nmethcalls (sizeof (methcalls) / sizeof (methcalls[0]))
1633 /* The following function, "find_objc_msgsend", fills in the data
1634 * structure "objc_msgs" by finding the addresses of each of the
1635 * (currently four) functions that it holds (of which objc_msgSend is
1636 * the first). This must be called each time symbols are loaded, in
1637 * case the functions have moved for some reason.
1641 find_objc_msgsend (void)
1644 for (i
= 0; i
< nmethcalls
; i
++) {
1646 struct minimal_symbol
*func
;
1648 /* Try both with and without underscore. */
1649 func
= lookup_minimal_symbol (methcalls
[i
].name
, NULL
, NULL
);
1650 if ((func
== NULL
) && (methcalls
[i
].name
[0] == '_')) {
1651 func
= lookup_minimal_symbol (methcalls
[i
].name
+ 1, NULL
, NULL
);
1654 methcalls
[i
].begin
= 0;
1655 methcalls
[i
].end
= 0;
1659 methcalls
[i
].begin
= SYMBOL_VALUE_ADDRESS (func
);
1661 methcalls
[i
].end
= SYMBOL_VALUE_ADDRESS (++func
);
1662 } while (methcalls
[i
].begin
== methcalls
[i
].end
);
1666 /* find_objc_msgcall (replaces pc_off_limits)
1668 * ALL that this function now does is to determine whether the input
1669 * address ("pc") is the address of one of the Objective-C message
1670 * dispatch functions (mainly objc_msgSend or objc_msgSendSuper), and
1671 * if so, it returns the address of the method that will be called.
1673 * The old function "pc_off_limits" used to do a lot of other things
1674 * in addition, such as detecting shared library jump stubs and
1675 * returning the address of the shlib function that would be called.
1676 * That functionality has been moved into the SKIP_TRAMPOLINE_CODE and
1677 * IN_SOLIB_TRAMPOLINE macros, which are resolved in the target-
1678 * dependent modules.
1681 struct objc_submethod_helper_data
{
1682 int (*f
) (CORE_ADDR
, CORE_ADDR
*);
1688 find_objc_msgcall_submethod_helper (void * arg
)
1690 struct objc_submethod_helper_data
*s
=
1691 (struct objc_submethod_helper_data
*) arg
;
1693 if (s
->f (s
->pc
, s
->new_pc
) == 0)
1700 find_objc_msgcall_submethod (int (*f
) (CORE_ADDR
, CORE_ADDR
*),
1704 struct objc_submethod_helper_data s
;
1710 if (catch_errors (find_objc_msgcall_submethod_helper
,
1712 "Unable to determine target of Objective-C method call (ignoring):\n",
1713 RETURN_MASK_ALL
) == 0)
1720 find_objc_msgcall (CORE_ADDR pc
, CORE_ADDR
*new_pc
)
1724 find_objc_msgsend ();
1730 for (i
= 0; i
< nmethcalls
; i
++)
1731 if ((pc
>= methcalls
[i
].begin
) && (pc
< methcalls
[i
].end
))
1733 if (methcalls
[i
].stop_at
!= NULL
)
1734 return find_objc_msgcall_submethod (methcalls
[i
].stop_at
,
1744 _initialize_objc_language (void)
1746 add_language (&objc_language_defn
);
1747 add_info ("selectors", selectors_info
, /* INFO SELECTORS command. */
1748 "All Objective-C selectors, or those matching REGEXP.");
1749 add_info ("classes", classes_info
, /* INFO CLASSES command. */
1750 "All Objective-C classes, or those matching REGEXP.");
1751 add_com ("print-object", class_vars
, print_object_command
,
1752 "Ask an Objective-C object to print itself.");
1753 add_com_alias ("po", "print-object", class_vars
, 1);
1757 /* Disable these functions until we put them in the gdbarch vector. */
1758 static unsigned long FETCH_ARGUMENT (int i
)
1760 internal_error (__FILE__
, __LINE__
, "FETCH_ARGUMENT not implemented");
1763 static CORE_ADDR
CONVERT_FUNCPTR (CORE_ADDR pc
)
1765 internal_error (__FILE__
, __LINE__
, "CONVERT_FUNCPTR not implemented");
1769 #if defined (__powerpc__) || defined (__ppc__)
1770 static unsigned long FETCH_ARGUMENT (int i
)
1772 return read_register (3 + i
);
1774 #elif defined (__i386__)
1775 static unsigned long FETCH_ARGUMENT (int i
)
1777 CORE_ADDR stack
= read_register (SP_REGNUM
);
1778 return read_memory_unsigned_integer (stack
+ (4 * (i
+ 1)), 4);
1780 #elif defined (__sparc__)
1781 static unsigned long FETCH_ARGUMENT (int i
)
1783 return read_register (O0_REGNUM
+ i
);
1785 #elif defined (__hppa__) || defined (__hppa)
1786 static unsigned long FETCH_ARGUMENT (int i
)
1788 return read_register (R0_REGNUM
+ 26 - i
);
1791 #error unknown architecture
1794 #if defined (__hppa__) || defined (__hppa)
1795 static CORE_ADDR
CONVERT_FUNCPTR (CORE_ADDR pc
)
1798 pc
= (CORE_ADDR
) read_memory_integer (pc
& ~0x3, 4);
1803 static CORE_ADDR
CONVERT_FUNCPTR (CORE_ADDR pc
)
1811 read_objc_method (CORE_ADDR addr
, struct objc_method
*method
)
1813 method
->name
= read_memory_unsigned_integer (addr
+ 0, 4);
1814 method
->types
= read_memory_unsigned_integer (addr
+ 4, 4);
1815 method
->imp
= read_memory_unsigned_integer (addr
+ 8, 4);
1819 unsigned long read_objc_methlist_nmethods (CORE_ADDR addr
)
1821 return read_memory_unsigned_integer (addr
+ 4, 4);
1825 read_objc_methlist_method (CORE_ADDR addr
, unsigned long num
,
1826 struct objc_method
*method
)
1828 CHECK_FATAL (num
< read_objc_methlist_nmethods (addr
));
1829 read_objc_method (addr
+ 8 + (12 * num
), method
);
1833 read_objc_object (CORE_ADDR addr
, struct objc_object
*object
)
1835 object
->isa
= read_memory_unsigned_integer (addr
, 4);
1839 read_objc_super (CORE_ADDR addr
, struct objc_super
*super
)
1841 super
->receiver
= read_memory_unsigned_integer (addr
, 4);
1842 super
->class = read_memory_unsigned_integer (addr
+ 4, 4);
1846 read_objc_class (CORE_ADDR addr
, struct objc_class
*class)
1848 class->isa
= read_memory_unsigned_integer (addr
, 4);
1849 class->super_class
= read_memory_unsigned_integer (addr
+ 4, 4);
1850 class->name
= read_memory_unsigned_integer (addr
+ 8, 4);
1851 class->version
= read_memory_unsigned_integer (addr
+ 12, 4);
1852 class->info
= read_memory_unsigned_integer (addr
+ 16, 4);
1853 class->instance_size
= read_memory_unsigned_integer (addr
+ 18, 4);
1854 class->ivars
= read_memory_unsigned_integer (addr
+ 24, 4);
1855 class->methods
= read_memory_unsigned_integer (addr
+ 28, 4);
1856 class->cache
= read_memory_unsigned_integer (addr
+ 32, 4);
1857 class->protocols
= read_memory_unsigned_integer (addr
+ 36, 4);
1861 find_implementation_from_class (CORE_ADDR
class, CORE_ADDR sel
)
1863 CORE_ADDR subclass
= class;
1865 while (subclass
!= 0)
1868 struct objc_class class_str
;
1869 unsigned mlistnum
= 0;
1871 read_objc_class (subclass
, &class_str
);
1876 unsigned long nmethods
;
1879 mlist
= read_memory_unsigned_integer (class_str
.methods
+
1884 nmethods
= read_objc_methlist_nmethods (mlist
);
1886 for (i
= 0; i
< nmethods
; i
++)
1888 struct objc_method meth_str
;
1889 read_objc_methlist_method (mlist
, i
, &meth_str
);
1893 "checking method 0x%lx against selector 0x%lx\n",
1894 meth_str
.name
, sel
);
1897 if (meth_str
.name
== sel
)
1898 return CONVERT_FUNCPTR (meth_str
.imp
);
1902 subclass
= class_str
.super_class
;
1909 find_implementation (CORE_ADDR object
, CORE_ADDR sel
)
1911 struct objc_object ostr
;
1915 read_objc_object (object
, &ostr
);
1919 return find_implementation_from_class (ostr
.isa
, sel
);
1923 resolve_msgsend (CORE_ADDR pc
, CORE_ADDR
*new_pc
)
1929 object
= FETCH_ARGUMENT (0);
1930 sel
= FETCH_ARGUMENT (1);
1932 res
= find_implementation (object
, sel
);
1941 resolve_msgsend_stret (CORE_ADDR pc
, CORE_ADDR
*new_pc
)
1947 object
= FETCH_ARGUMENT (1);
1948 sel
= FETCH_ARGUMENT (2);
1950 res
= find_implementation (object
, sel
);
1959 resolve_msgsend_super (CORE_ADDR pc
, CORE_ADDR
*new_pc
)
1961 struct objc_super sstr
;
1967 super
= FETCH_ARGUMENT (0);
1968 sel
= FETCH_ARGUMENT (1);
1970 read_objc_super (super
, &sstr
);
1971 if (sstr
.class == 0)
1974 res
= find_implementation_from_class (sstr
.class, sel
);
1983 resolve_msgsend_super_stret (CORE_ADDR pc
, CORE_ADDR
*new_pc
)
1985 struct objc_super sstr
;
1991 super
= FETCH_ARGUMENT (1);
1992 sel
= FETCH_ARGUMENT (2);
1994 read_objc_super (super
, &sstr
);
1995 if (sstr
.class == 0)
1998 res
= find_implementation_from_class (sstr
.class, sel
);