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"
54 CORE_ADDR super_class
;
76 /* Complaints about ObjC classes, selectors, etc. */
78 #if (!defined __GNUC__ || __GNUC__ < 2 || __GNUC_MINOR__ < (defined __cplusplus ? 6 : 4))
79 #define __CHECK_FUNCTION ((__const char *) 0)
81 #define __CHECK_FUNCTION __PRETTY_FUNCTION__
84 #define CHECK(expression) \
85 ((void) ((expression) ? 0 : gdb_check (#expression, __FILE__, __LINE__, \
88 #define CHECK_FATAL(expression) \
89 ((void) ((expression) ? 0 : gdb_check_fatal (#expression, __FILE__, \
90 __LINE__, __CHECK_FUNCTION)))
93 gdb_check (const char *str
, const char *file
,
94 unsigned int line
, const char *func
)
96 error ("assertion failure on line %u of \"%s\" in function \"%s\": %s\n",
97 line
, file
, func
, str
);
101 gdb_check_fatal (const char *str
, const char *file
,
102 unsigned int line
, const char *func
)
104 internal_error (file
, line
,
105 "assertion failure in function \"%s\": %s\n", func
, str
);
108 /* Lookup a structure type named "struct NAME", visible in lexical
109 block BLOCK. If NOERR is nonzero, return zero if NAME is not
113 lookup_struct_typedef (char *name
, struct block
*block
, int noerr
)
115 register struct symbol
*sym
;
117 sym
= lookup_symbol (name
, block
, STRUCT_NAMESPACE
, 0,
118 (struct symtab
**) NULL
);
125 error ("No struct type named %s.", name
);
127 if (TYPE_CODE (SYMBOL_TYPE (sym
)) != TYPE_CODE_STRUCT
)
132 error ("This context has class, union or enum %s, not a struct.",
139 lookup_objc_class (char *classname
)
141 struct value
* function
, *classval
;
143 if (! target_has_execution
)
145 /* Can't call into inferior to lookup class. */
149 if (lookup_minimal_symbol("objc_lookUpClass", 0, 0))
150 function
= find_function_in_inferior("objc_lookUpClass");
151 else if (lookup_minimal_symbol ("objc_lookup_class", 0, 0))
152 function
= find_function_in_inferior("objc_lookup_class");
155 complaint (&symfile_complaints
, "no way to lookup Objective-C classes");
159 classval
= value_string (classname
, strlen (classname
) + 1);
160 classval
= value_coerce_array (classval
);
161 return (CORE_ADDR
) value_as_long (call_function_by_hand (function
,
166 lookup_child_selector (char *selname
)
168 struct value
* function
, *selstring
;
170 if (! target_has_execution
)
172 /* Can't call into inferior to lookup selector. */
176 if (lookup_minimal_symbol("sel_getUid", 0, 0))
177 function
= find_function_in_inferior("sel_getUid");
178 else if (lookup_minimal_symbol ("sel_get_any_uid", 0, 0))
179 function
= find_function_in_inferior("sel_get_any_uid");
182 complaint (&symfile_complaints
, "no way to lookup Objective-C selectors");
186 selstring
= value_coerce_array (value_string (selname
,
187 strlen (selname
) + 1));
188 return value_as_long (call_function_by_hand (function
, 1, &selstring
));
192 value_nsstring (char *ptr
, int len
)
194 struct value
*stringValue
[3];
195 struct value
*function
, *nsstringValue
;
199 if (!target_has_execution
)
200 return 0; /* Can't call into inferior to create NSString. */
202 if (!(sym
= lookup_struct_typedef("NSString", 0, 1)) &&
203 !(sym
= lookup_struct_typedef("NXString", 0, 1)))
204 type
= lookup_pointer_type(builtin_type_void
);
206 type
= lookup_pointer_type(SYMBOL_TYPE (sym
));
208 stringValue
[2] = value_string(ptr
, len
);
209 stringValue
[2] = value_coerce_array(stringValue
[2]);
210 /* _NSNewStringFromCString replaces "istr" after Lantern2A. */
211 if (lookup_minimal_symbol("_NSNewStringFromCString", 0, 0))
213 function
= find_function_in_inferior("_NSNewStringFromCString");
214 nsstringValue
= call_function_by_hand(function
, 1, &stringValue
[2]);
216 else if (lookup_minimal_symbol("istr", 0, 0))
218 function
= find_function_in_inferior("istr");
219 nsstringValue
= call_function_by_hand(function
, 1, &stringValue
[2]);
221 else if (lookup_minimal_symbol("+[NSString stringWithCString:]", 0, 0))
223 function
= find_function_in_inferior("+[NSString stringWithCString:]");
224 stringValue
[0] = value_from_longest
225 (builtin_type_long
, lookup_objc_class ("NSString"));
226 stringValue
[1] = value_from_longest
227 (builtin_type_long
, lookup_child_selector ("stringWithCString:"));
228 nsstringValue
= call_function_by_hand(function
, 3, &stringValue
[0]);
231 error ("NSString: internal error -- no way to create new NSString");
233 VALUE_TYPE(nsstringValue
) = type
;
234 return nsstringValue
;
237 /* Objective-C name demangling. */
240 objc_demangle (const char *mangled
, int options
)
242 char *demangled
, *cp
;
244 if (mangled
[0] == '_' &&
245 (mangled
[1] == 'i' || mangled
[1] == 'c') &&
248 cp
= demangled
= xmalloc(strlen(mangled
) + 2);
250 if (mangled
[1] == 'i')
251 *cp
++ = '-'; /* for instance method */
253 *cp
++ = '+'; /* for class method */
255 *cp
++ = '['; /* opening left brace */
256 strcpy(cp
, mangled
+3); /* tack on the rest of the mangled name */
258 while (*cp
&& *cp
== '_')
259 cp
++; /* skip any initial underbars in class name */
261 cp
= strchr(cp
, '_');
262 if (!cp
) /* find first non-initial underbar */
264 xfree(demangled
); /* not mangled name */
267 if (cp
[1] == '_') { /* easy case: no category name */
268 *cp
++ = ' '; /* replace two '_' with one ' ' */
269 strcpy(cp
, mangled
+ (cp
- demangled
) + 2);
272 *cp
++ = '('; /* less easy case: category name */
273 cp
= strchr(cp
, '_');
276 xfree(demangled
); /* not mangled name */
280 *cp
++ = ' '; /* overwriting 1st char of method name... */
281 strcpy(cp
, mangled
+ (cp
- demangled
)); /* get it back */
284 while (*cp
&& *cp
== '_')
285 cp
++; /* skip any initial underbars in method name */
289 *cp
= ':'; /* replace remaining '_' with ':' */
291 *cp
++ = ']'; /* closing right brace */
292 *cp
++ = 0; /* string terminator */
296 return NULL
; /* Not an objc mangled name. */
299 /* Print the character C on STREAM as part of the contents of a
300 literal string whose delimiter is QUOTER. Note that that format
301 for printing characters and strings is language specific. */
304 objc_emit_char (register int c
, struct ui_file
*stream
, int quoter
)
307 c
&= 0xFF; /* Avoid sign bit follies. */
309 if (PRINT_LITERAL_FORM (c
))
311 if (c
== '\\' || c
== quoter
)
313 fputs_filtered ("\\", stream
);
315 fprintf_filtered (stream
, "%c", c
);
322 fputs_filtered ("\\n", stream
);
325 fputs_filtered ("\\b", stream
);
328 fputs_filtered ("\\t", stream
);
331 fputs_filtered ("\\f", stream
);
334 fputs_filtered ("\\r", stream
);
337 fputs_filtered ("\\e", stream
);
340 fputs_filtered ("\\a", stream
);
343 fprintf_filtered (stream
, "\\%.3o", (unsigned int) c
);
350 objc_printchar (int c
, struct ui_file
*stream
)
352 fputs_filtered ("'", stream
);
353 objc_emit_char (c
, stream
, '\'');
354 fputs_filtered ("'", stream
);
357 /* Print the character string STRING, printing at most LENGTH
358 characters. Printing stops early if the number hits print_max;
359 repeat counts are printed as appropriate. Print ellipses at the
360 end if we had to stop before printing LENGTH characters, or if
364 objc_printstr (struct ui_file
*stream
, char *string
,
365 unsigned int length
, int width
, int force_ellipses
)
367 register unsigned int i
;
368 unsigned int things_printed
= 0;
371 extern int inspect_it
;
372 extern int repeat_count_threshold
;
373 extern int print_max
;
375 /* If the string was not truncated due to `set print elements', and
376 the last byte of it is a null, we don't print that, in
377 traditional C style. */
378 if ((!force_ellipses
) && length
> 0 && string
[length
-1] == '\0')
383 fputs_filtered ("\"\"", stream
);
387 for (i
= 0; i
< length
&& things_printed
< print_max
; ++i
)
389 /* Position of the character we are examining to see whether it
392 /* Number of repetitions we have detected so far. */
399 fputs_filtered (", ", stream
);
405 while (rep1
< length
&& string
[rep1
] == string
[i
])
411 if (reps
> repeat_count_threshold
)
416 fputs_filtered ("\\\", ", stream
);
418 fputs_filtered ("\", ", stream
);
421 objc_printchar (string
[i
], stream
);
422 fprintf_filtered (stream
, " <repeats %u times>", reps
);
424 things_printed
+= repeat_count_threshold
;
432 fputs_filtered ("\\\"", stream
);
434 fputs_filtered ("\"", stream
);
437 objc_emit_char (string
[i
], stream
, '"');
442 /* Terminate the quotes if necessary. */
446 fputs_filtered ("\\\"", stream
);
448 fputs_filtered ("\"", stream
);
451 if (force_ellipses
|| i
< length
)
452 fputs_filtered ("...", stream
);
455 /* Create a fundamental C type using default reasonable for the
458 Some object/debugging file formats (DWARF version 1, COFF, etc) do
459 not define fundamental types such as "int" or "double". Others
460 (stabs or DWARF version 2, etc) do define fundamental types. For
461 the formats which don't provide fundamental types, gdb can create
462 such types using this function.
464 FIXME: Some compilers distinguish explicitly signed integral types
465 (signed short, signed int, signed long) from "regular" integral
466 types (short, int, long) in the debugging information. There is
467 some disagreement as to how useful this feature is. In particular,
468 gcc does not support this. Also, only some debugging formats allow
469 the distinction to be passed on to a debugger. For now, we always
470 just use "short", "int", or "long" as the type name, for both the
471 implicit and explicitly signed types. This also makes life easier
472 for the gdb test suite since we don't have to account for the
473 differences in output depending upon what the compiler and
474 debugging format support. We will probably have to re-examine the
475 issue when gdb starts taking it's fundamental type information
476 directly from the debugging information supplied by the compiler.
480 objc_create_fundamental_type (struct objfile
*objfile
, int typeid)
482 register struct type
*type
= NULL
;
487 /* FIXME: For now, if we are asked to produce a type not in
488 this language, create the equivalent of a C integer type
489 with the name "<?type?>". When all the dust settles from
490 the type reconstruction work, this should probably become
492 type
= init_type (TYPE_CODE_INT
,
493 TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
494 0, "<?type?>", objfile
);
495 warning ("internal error: no C/C++ fundamental type %d", typeid);
498 type
= init_type (TYPE_CODE_VOID
,
499 TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
503 type
= init_type (TYPE_CODE_INT
,
504 TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
508 type
= init_type (TYPE_CODE_INT
,
509 TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
510 0, "signed char", objfile
);
512 case FT_UNSIGNED_CHAR
:
513 type
= init_type (TYPE_CODE_INT
,
514 TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
515 TYPE_FLAG_UNSIGNED
, "unsigned char", objfile
);
518 type
= init_type (TYPE_CODE_INT
,
519 TARGET_SHORT_BIT
/ TARGET_CHAR_BIT
,
520 0, "short", objfile
);
522 case FT_SIGNED_SHORT
:
523 type
= init_type (TYPE_CODE_INT
,
524 TARGET_SHORT_BIT
/ TARGET_CHAR_BIT
,
525 0, "short", objfile
); /* FIXME-fnf */
527 case FT_UNSIGNED_SHORT
:
528 type
= init_type (TYPE_CODE_INT
,
529 TARGET_SHORT_BIT
/ TARGET_CHAR_BIT
,
530 TYPE_FLAG_UNSIGNED
, "unsigned short", objfile
);
533 type
= init_type (TYPE_CODE_INT
,
534 TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
537 case FT_SIGNED_INTEGER
:
538 type
= init_type (TYPE_CODE_INT
,
539 TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
540 0, "int", objfile
); /* FIXME -fnf */
542 case FT_UNSIGNED_INTEGER
:
543 type
= init_type (TYPE_CODE_INT
,
544 TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
545 TYPE_FLAG_UNSIGNED
, "unsigned int", objfile
);
548 type
= init_type (TYPE_CODE_INT
,
549 TARGET_LONG_BIT
/ TARGET_CHAR_BIT
,
553 type
= init_type (TYPE_CODE_INT
,
554 TARGET_LONG_BIT
/ TARGET_CHAR_BIT
,
555 0, "long", objfile
); /* FIXME -fnf */
557 case FT_UNSIGNED_LONG
:
558 type
= init_type (TYPE_CODE_INT
,
559 TARGET_LONG_BIT
/ TARGET_CHAR_BIT
,
560 TYPE_FLAG_UNSIGNED
, "unsigned long", objfile
);
563 type
= init_type (TYPE_CODE_INT
,
564 TARGET_LONG_LONG_BIT
/ TARGET_CHAR_BIT
,
565 0, "long long", objfile
);
567 case FT_SIGNED_LONG_LONG
:
568 type
= init_type (TYPE_CODE_INT
,
569 TARGET_LONG_LONG_BIT
/ TARGET_CHAR_BIT
,
570 0, "signed long long", objfile
);
572 case FT_UNSIGNED_LONG_LONG
:
573 type
= init_type (TYPE_CODE_INT
,
574 TARGET_LONG_LONG_BIT
/ TARGET_CHAR_BIT
,
575 TYPE_FLAG_UNSIGNED
, "unsigned long long", objfile
);
578 type
= init_type (TYPE_CODE_FLT
,
579 TARGET_FLOAT_BIT
/ TARGET_CHAR_BIT
,
580 0, "float", objfile
);
582 case FT_DBL_PREC_FLOAT
:
583 type
= init_type (TYPE_CODE_FLT
,
584 TARGET_DOUBLE_BIT
/ TARGET_CHAR_BIT
,
585 0, "double", objfile
);
587 case FT_EXT_PREC_FLOAT
:
588 type
= init_type (TYPE_CODE_FLT
,
589 TARGET_LONG_DOUBLE_BIT
/ TARGET_CHAR_BIT
,
590 0, "long double", objfile
);
596 /* Determine if we are currently in the Objective-C dispatch function.
597 If so, get the address of the method function that the dispatcher
598 would call and use that as the function to step into instead. Also
599 skip over the trampoline for the function (if any). This is better
600 for the user since they are only interested in stepping into the
601 method function anyway. */
603 objc_skip_trampoline (CORE_ADDR stop_pc
)
605 CORE_ADDR real_stop_pc
;
606 CORE_ADDR method_stop_pc
;
608 real_stop_pc
= SKIP_TRAMPOLINE_CODE (stop_pc
);
610 if (real_stop_pc
!= 0)
611 find_objc_msgcall (real_stop_pc
, &method_stop_pc
);
613 find_objc_msgcall (stop_pc
, &method_stop_pc
);
617 real_stop_pc
= SKIP_TRAMPOLINE_CODE (method_stop_pc
);
618 if (real_stop_pc
== 0)
619 real_stop_pc
= method_stop_pc
;
626 /* Table mapping opcodes into strings for printing operators
627 and precedences of the operators. */
629 static const struct op_print objc_op_print_tab
[] =
631 {",", BINOP_COMMA
, PREC_COMMA
, 0},
632 {"=", BINOP_ASSIGN
, PREC_ASSIGN
, 1},
633 {"||", BINOP_LOGICAL_OR
, PREC_LOGICAL_OR
, 0},
634 {"&&", BINOP_LOGICAL_AND
, PREC_LOGICAL_AND
, 0},
635 {"|", BINOP_BITWISE_IOR
, PREC_BITWISE_IOR
, 0},
636 {"^", BINOP_BITWISE_XOR
, PREC_BITWISE_XOR
, 0},
637 {"&", BINOP_BITWISE_AND
, PREC_BITWISE_AND
, 0},
638 {"==", BINOP_EQUAL
, PREC_EQUAL
, 0},
639 {"!=", BINOP_NOTEQUAL
, PREC_EQUAL
, 0},
640 {"<=", BINOP_LEQ
, PREC_ORDER
, 0},
641 {">=", BINOP_GEQ
, PREC_ORDER
, 0},
642 {">", BINOP_GTR
, PREC_ORDER
, 0},
643 {"<", BINOP_LESS
, PREC_ORDER
, 0},
644 {">>", BINOP_RSH
, PREC_SHIFT
, 0},
645 {"<<", BINOP_LSH
, PREC_SHIFT
, 0},
646 {"+", BINOP_ADD
, PREC_ADD
, 0},
647 {"-", BINOP_SUB
, PREC_ADD
, 0},
648 {"*", BINOP_MUL
, PREC_MUL
, 0},
649 {"/", BINOP_DIV
, PREC_MUL
, 0},
650 {"%", BINOP_REM
, PREC_MUL
, 0},
651 {"@", BINOP_REPEAT
, PREC_REPEAT
, 0},
652 {"-", UNOP_NEG
, PREC_PREFIX
, 0},
653 {"!", UNOP_LOGICAL_NOT
, PREC_PREFIX
, 0},
654 {"~", UNOP_COMPLEMENT
, PREC_PREFIX
, 0},
655 {"*", UNOP_IND
, PREC_PREFIX
, 0},
656 {"&", UNOP_ADDR
, PREC_PREFIX
, 0},
657 {"sizeof ", UNOP_SIZEOF
, PREC_PREFIX
, 0},
658 {"++", UNOP_PREINCREMENT
, PREC_PREFIX
, 0},
659 {"--", UNOP_PREDECREMENT
, PREC_PREFIX
, 0},
663 struct type
** const (objc_builtin_types
[]) =
670 &builtin_type_double
,
672 &builtin_type_long_long
,
673 &builtin_type_signed_char
,
674 &builtin_type_unsigned_char
,
675 &builtin_type_unsigned_short
,
676 &builtin_type_unsigned_int
,
677 &builtin_type_unsigned_long
,
678 &builtin_type_unsigned_long_long
,
679 &builtin_type_long_double
,
680 &builtin_type_complex
,
681 &builtin_type_double_complex
,
685 const struct language_defn objc_language_defn
= {
686 "objective-c", /* Language name */
694 evaluate_subexp_standard
,
695 objc_printchar
, /* Print a character constant */
696 objc_printstr
, /* Function to print string constant */
698 objc_create_fundamental_type
, /* Create fundamental type in this language */
699 c_print_type
, /* Print a type using appropriate syntax */
700 c_val_print
, /* Print a value using appropriate syntax */
701 c_value_print
, /* Print a top-level value */
702 objc_skip_trampoline
, /* Language specific skip_trampoline */
703 objc_demangle
, /* Language specific symbol demangler */
704 {"", "", "", ""}, /* Binary format info */
705 {"0%lo", "0", "o", ""}, /* Octal format info */
706 {"%ld", "", "d", ""}, /* Decimal format info */
707 {"0x%lx", "0x", "x", ""}, /* Hex format info */
708 objc_op_print_tab
, /* Expression operators for printing */
709 1, /* C-style arrays */
710 0, /* String lower bound */
711 &builtin_type_char
, /* Type of string elements */
717 * Following functions help construct Objective-C message calls
720 struct selname
/* For parsing Objective-C. */
722 struct selname
*next
;
727 static int msglist_len
;
728 static struct selname
*selname_chain
;
729 static char *msglist_sel
;
734 register struct selname
*new =
735 (struct selname
*) xmalloc (sizeof (struct selname
));
737 new->next
= selname_chain
;
738 new->msglist_len
= msglist_len
;
739 new->msglist_sel
= msglist_sel
;
741 msglist_sel
= (char *)xmalloc(1);
747 add_msglist(struct stoken
*str
, int addcolon
)
752 if (str
== 0) { /* Unnamed arg, or... */
753 if (addcolon
== 0) { /* variable number of args. */
763 len
= plen
+ strlen(msglist_sel
) + 2;
764 s
= (char *)xmalloc(len
);
765 strcpy(s
, msglist_sel
);
780 register int val
= msglist_len
;
781 register struct selname
*sel
= selname_chain
;
782 register char *p
= msglist_sel
;
785 selname_chain
= sel
->next
;
786 msglist_len
= sel
->msglist_len
;
787 msglist_sel
= sel
->msglist_sel
;
788 selid
= lookup_child_selector(p
);
790 error("Can't find selector \"%s\"", p
);
791 write_exp_elt_longcst (selid
);
793 write_exp_elt_longcst (val
); /* Number of args */
800 * Function: specialcmp (char *a, char *b)
802 * Special strcmp: treats ']' and ' ' as end-of-string.
803 * Used for qsorting lists of objc methods (either by class or selector).
806 int specialcmp(char *a
, char *b
)
808 while (*a
&& *a
!= ' ' && *a
!= ']' && *b
&& *b
!= ' ' && *b
!= ']')
814 if (*a
&& *a
!= ' ' && *a
!= ']')
815 return 1; /* a is longer therefore greater */
816 if (*b
&& *b
!= ' ' && *b
!= ']')
817 return -1; /* a is shorter therefore lesser */
818 return 0; /* a and b are identical */
822 * Function: compare_selectors (const void *, const void *)
824 * Comparison function for use with qsort. Arguments are symbols or
825 * msymbols Compares selector part of objc method name alphabetically.
829 compare_selectors (const void *a
, const void *b
)
833 aname
= SYMBOL_PRINT_NAME (*(struct symbol
**) a
);
834 bname
= SYMBOL_PRINT_NAME (*(struct symbol
**) b
);
835 if (aname
== NULL
|| bname
== NULL
)
836 error ("internal: compare_selectors(1)");
838 aname
= strchr(aname
, ' ');
839 bname
= strchr(bname
, ' ');
840 if (aname
== NULL
|| bname
== NULL
)
841 error ("internal: compare_selectors(2)");
843 return specialcmp (aname
+1, bname
+1);
847 * Function: selectors_info (regexp, from_tty)
849 * Implements the "Info selectors" command. Takes an optional regexp
850 * arg. Lists all objective c selectors that match the regexp. Works
851 * by grepping thru all symbols for objective c methods. Output list
852 * is sorted and uniqued.
856 selectors_info (char *regexp
, int from_tty
)
858 struct objfile
*objfile
;
859 struct minimal_symbol
*msymbol
;
867 struct symbol
**sym_arr
;
871 strcpy(myregexp
, ".*]"); /* Null input, match all objc methods. */
874 if (*regexp
== '+' || *regexp
== '-')
875 { /* User wants only class methods or only instance methods. */
876 plusminus
= *regexp
++;
877 while (*regexp
== ' ' || *regexp
== '\t')
881 strcpy(myregexp
, ".*]");
884 strcpy(myregexp
, regexp
);
885 if (myregexp
[strlen(myregexp
) - 1] == '$') /* end of selector */
886 myregexp
[strlen(myregexp
) - 1] = ']'; /* end of method name */
888 strcat(myregexp
, ".*]");
893 if (0 != (val
= re_comp (myregexp
)))
894 error ("Invalid regexp (%s): %s", val
, regexp
);
896 /* First time thru is JUST to get max length and count. */
897 ALL_MSYMBOLS (objfile
, msymbol
)
900 name
= SYMBOL_DEMANGLED_NAME (msymbol
);
902 name
= DEPRECATED_SYMBOL_NAME (msymbol
);
904 (name
[0] == '-' || name
[0] == '+') &&
905 name
[1] == '[') /* Got a method name. */
907 /* Filter for class/instance methods. */
908 if (plusminus
&& name
[0] != plusminus
)
910 /* Find selector part. */
911 name
= (char *) strchr(name
+2, ' ');
912 if (regexp
== NULL
|| re_exec(++name
) != 0)
914 char *mystart
= name
;
915 char *myend
= (char *) strchr(mystart
, ']');
917 if (myend
&& (myend
- mystart
> maxlen
))
918 maxlen
= myend
- mystart
; /* Get longest selector. */
925 printf_filtered ("Selectors matching \"%s\":\n\n",
926 regexp
? regexp
: "*");
928 sym_arr
= alloca (matches
* sizeof (struct symbol
*));
930 ALL_MSYMBOLS (objfile
, msymbol
)
933 name
= SYMBOL_DEMANGLED_NAME (msymbol
);
935 name
= DEPRECATED_SYMBOL_NAME (msymbol
);
937 (name
[0] == '-' || name
[0] == '+') &&
938 name
[1] == '[') /* Got a method name. */
940 /* Filter for class/instance methods. */
941 if (plusminus
&& name
[0] != plusminus
)
943 /* Find selector part. */
944 name
= (char *) strchr(name
+2, ' ');
945 if (regexp
== NULL
|| re_exec(++name
) != 0)
946 sym_arr
[matches
++] = (struct symbol
*) msymbol
;
950 qsort (sym_arr
, matches
, sizeof (struct minimal_symbol
*),
952 /* Prevent compare on first iteration. */
954 for (ix
= 0; ix
< matches
; ix
++) /* Now do the output. */
959 name
= SYMBOL_DEMANGLED_NAME (sym_arr
[ix
]);
961 name
= DEPRECATED_SYMBOL_NAME (sym_arr
[ix
]);
962 name
= strchr (name
, ' ') + 1;
963 if (p
[0] && specialcmp(name
, p
) == 0)
964 continue; /* Seen this one already (not unique). */
966 /* Copy selector part. */
967 while (*name
&& *name
!= ']')
970 /* Print in columns. */
971 puts_filtered_tabular(asel
, maxlen
+ 1, 0);
976 printf_filtered ("No selectors matching \"%s\"\n", regexp
? regexp
: "*");
980 * Function: compare_classes (const void *, const void *)
982 * Comparison function for use with qsort. Arguments are symbols or
983 * msymbols Compares class part of objc method name alphabetically.
987 compare_classes (const void *a
, const void *b
)
991 aname
= SYMBOL_PRINT_NAME (*(struct symbol
**) a
);
992 bname
= SYMBOL_PRINT_NAME (*(struct symbol
**) b
);
993 if (aname
== NULL
|| bname
== NULL
)
994 error ("internal: compare_classes(1)");
996 return specialcmp (aname
+1, bname
+1);
1000 * Function: classes_info(regexp, from_tty)
1002 * Implements the "info classes" command for objective c classes.
1003 * Lists all objective c classes that match the optional regexp.
1004 * Works by grepping thru the list of objective c methods. List will
1005 * be sorted and uniqued (since one class may have many methods).
1006 * BUGS: will not list a class that has no methods.
1010 classes_info (char *regexp
, int from_tty
)
1012 struct objfile
*objfile
;
1013 struct minimal_symbol
*msymbol
;
1019 char myregexp
[2048];
1021 struct symbol
**sym_arr
;
1024 strcpy(myregexp
, ".* "); /* Null input: match all objc classes. */
1027 strcpy(myregexp
, regexp
);
1028 if (myregexp
[strlen(myregexp
) - 1] == '$')
1029 /* In the method name, the end of the class name is marked by ' '. */
1030 myregexp
[strlen(myregexp
) - 1] = ' ';
1032 strcat(myregexp
, ".* ");
1036 if (0 != (val
= re_comp (myregexp
)))
1037 error ("Invalid regexp (%s): %s", val
, regexp
);
1039 /* First time thru is JUST to get max length and count. */
1040 ALL_MSYMBOLS (objfile
, msymbol
)
1043 name
= SYMBOL_DEMANGLED_NAME (msymbol
);
1045 name
= DEPRECATED_SYMBOL_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_DEMANGLED_NAME (msymbol
);
1071 name
= DEPRECATED_SYMBOL_NAME (msymbol
);
1073 (name
[0] == '-' || name
[0] == '+') &&
1074 name
[1] == '[') /* Got a method name. */
1075 if (regexp
== NULL
|| re_exec(name
+2) != 0)
1076 sym_arr
[matches
++] = (struct symbol
*) msymbol
;
1079 qsort (sym_arr
, matches
, sizeof (struct minimal_symbol
*),
1081 /* Prevent compare on first iteration. */
1083 for (ix
= 0; ix
< matches
; ix
++) /* Now do the output. */
1088 name
= SYMBOL_DEMANGLED_NAME (sym_arr
[ix
]);
1090 name
= DEPRECATED_SYMBOL_NAME (sym_arr
[ix
]);
1092 if (p
[0] && specialcmp(name
, p
) == 0)
1093 continue; /* Seen this one already (not unique). */
1095 /* Copy class part of method name. */
1096 while (*name
&& *name
!= ' ')
1099 /* Print in columns. */
1100 puts_filtered_tabular(aclass
, maxlen
+ 1, 0);
1105 printf_filtered ("No classes matching \"%s\"\n", regexp
? regexp
: "*");
1109 * Function: find_imps (char *selector, struct symbol **sym_arr)
1111 * Input: a string representing a selector
1112 * a pointer to an array of symbol pointers
1113 * possibly a pointer to a symbol found by the caller.
1115 * Output: number of methods that implement that selector. Side
1116 * effects: The array of symbol pointers is filled with matching syms.
1118 * By analogy with function "find_methods" (symtab.c), builds a list
1119 * of symbols matching the ambiguous input, so that "decode_line_2"
1120 * (symtab.c) can list them and ask the user to choose one or more.
1121 * In this case the matches are objective c methods
1122 * ("implementations") matching an objective c selector.
1124 * Note that it is possible for a normal (c-style) function to have
1125 * the same name as an objective c selector. To prevent the selector
1126 * from eclipsing the function, we allow the caller (decode_line_1) to
1127 * search for such a function first, and if it finds one, pass it in
1128 * to us. We will then integrate it into the list. We also search
1129 * for one here, among the minsyms.
1131 * NOTE: if NUM_DEBUGGABLE is non-zero, the sym_arr will be divided
1132 * into two parts: debuggable (struct symbol) syms, and
1133 * non_debuggable (struct minimal_symbol) syms. The debuggable
1134 * ones will come first, before NUM_DEBUGGABLE (which will thus
1135 * be the index of the first non-debuggable one).
1139 * Function: total_number_of_imps (char *selector);
1141 * Input: a string representing a selector
1142 * Output: number of methods that implement that selector.
1144 * By analogy with function "total_number_of_methods", this allows
1145 * decode_line_1 (symtab.c) to detect if there are objective c methods
1146 * matching the input, and to allocate an array of pointers to them
1147 * which can be manipulated by "decode_line_2" (also in symtab.c).
1151 parse_selector (char *method
, char **selector
)
1155 int found_quote
= 0;
1157 char *nselector
= NULL
;
1159 CHECK (selector
!= NULL
);
1163 while (isspace (*s1
))
1170 while (isspace (*s1
))
1177 if (isalnum (*s2
) || (*s2
== '_') || (*s2
== ':'))
1179 else if (isspace (*s2
))
1181 else if ((*s2
== '\0') || (*s2
== '\''))
1189 while (isspace (*s2
))
1195 while (isspace (*s2
))
1199 if (selector
!= NULL
)
1200 *selector
= nselector
;
1206 parse_method (char *method
, char *type
, char **class,
1207 char **category
, char **selector
)
1211 int found_quote
= 0;
1214 char *nclass
= NULL
;
1215 char *ncategory
= NULL
;
1216 char *nselector
= NULL
;
1218 CHECK (type
!= NULL
);
1219 CHECK (class != NULL
);
1220 CHECK (category
!= NULL
);
1221 CHECK (selector
!= NULL
);
1225 while (isspace (*s1
))
1232 while (isspace (*s1
))
1235 if ((s1
[0] == '+') || (s1
[0] == '-'))
1238 while (isspace (*s1
))
1246 while (isalnum (*s1
) || (*s1
== '_'))
1250 while (isspace (*s2
))
1256 while (isspace (*s2
))
1259 while (isalnum (*s2
) || (*s2
== '_'))
1264 /* Truncate the class name now that we're not using the open paren. */
1271 if (isalnum (*s2
) || (*s2
== '_') || (*s2
== ':'))
1273 else if (isspace (*s2
))
1275 else if (*s2
== ']')
1284 while (isspace (*s2
))
1291 while (isspace (*s2
))
1299 if (category
!= NULL
)
1300 *category
= ncategory
;
1301 if (selector
!= NULL
)
1302 *selector
= nselector
;
1308 find_methods (struct symtab
*symtab
, char type
,
1309 const char *class, const char *category
,
1310 const char *selector
, struct symbol
**syms
,
1311 unsigned int *nsym
, unsigned int *ndebug
)
1313 struct objfile
*objfile
= NULL
;
1314 struct minimal_symbol
*msymbol
= NULL
;
1315 struct block
*block
= NULL
;
1316 struct symbol
*sym
= NULL
;
1318 char *symname
= NULL
;
1321 char *nclass
= NULL
;
1322 char *ncategory
= NULL
;
1323 char *nselector
= NULL
;
1325 unsigned int csym
= 0;
1326 unsigned int cdebug
= 0;
1328 static char *tmp
= NULL
;
1329 static unsigned int tmplen
= 0;
1331 CHECK (nsym
!= NULL
);
1332 CHECK (ndebug
!= NULL
);
1335 block
= BLOCKVECTOR_BLOCK (BLOCKVECTOR (symtab
), STATIC_BLOCK
);
1337 ALL_MSYMBOLS (objfile
, msymbol
)
1341 if ((msymbol
->type
!= mst_text
) && (msymbol
->type
!= mst_file_text
))
1342 /* Not a function or method. */
1346 if ((SYMBOL_VALUE_ADDRESS (msymbol
) < BLOCK_START (block
)) ||
1347 (SYMBOL_VALUE_ADDRESS (msymbol
) >= BLOCK_END (block
)))
1348 /* Not in the specified symtab. */
1351 symname
= SYMBOL_DEMANGLED_NAME (msymbol
);
1352 if (symname
== NULL
)
1353 symname
= DEPRECATED_SYMBOL_NAME (msymbol
);
1354 if (symname
== NULL
)
1357 if ((symname
[0] != '-' && symname
[0] != '+') || (symname
[1] != '['))
1358 /* Not a method name. */
1361 while ((strlen (symname
) + 1) >= tmplen
)
1363 tmplen
= (tmplen
== 0) ? 1024 : tmplen
* 2;
1364 tmp
= xrealloc (tmp
, tmplen
);
1366 strcpy (tmp
, symname
);
1368 if (parse_method (tmp
, &ntype
, &nclass
, &ncategory
, &nselector
) == NULL
)
1371 if ((type
!= '\0') && (ntype
!= type
))
1375 && ((nclass
== NULL
) || (strcmp (class, nclass
) != 0)))
1378 if ((category
!= NULL
) &&
1379 ((ncategory
== NULL
) || (strcmp (category
, ncategory
) != 0)))
1382 if ((selector
!= NULL
) &&
1383 ((nselector
== NULL
) || (strcmp (selector
, nselector
) != 0)))
1386 sym
= find_pc_function (SYMBOL_VALUE_ADDRESS (msymbol
));
1389 const char *newsymname
= SYMBOL_DEMANGLED_NAME (sym
);
1391 if (newsymname
== NULL
)
1392 newsymname
= DEPRECATED_SYMBOL_NAME (sym
);
1393 if (strcmp (symname
, newsymname
) == 0)
1395 /* Found a high-level method sym: swap it into the
1396 lower part of sym_arr (below num_debuggable). */
1399 syms
[csym
] = syms
[cdebug
];
1408 "debugging symbol \"%s\" does not match minimal symbol (\"%s\"); ignoring",
1409 newsymname
, symname
);
1411 syms
[csym
] = (struct symbol
*) msymbol
;
1417 /* Found a non-debuggable method symbol. */
1419 syms
[csym
] = (struct symbol
*) msymbol
;
1430 char *find_imps (struct symtab
*symtab
, struct block
*block
,
1431 char *method
, struct symbol
**syms
,
1432 unsigned int *nsym
, unsigned int *ndebug
)
1436 char *category
= NULL
;
1437 char *selector
= NULL
;
1439 unsigned int csym
= 0;
1440 unsigned int cdebug
= 0;
1442 unsigned int ncsym
= 0;
1443 unsigned int ncdebug
= 0;
1448 CHECK (nsym
!= NULL
);
1449 CHECK (ndebug
!= NULL
);
1456 buf
= (char *) alloca (strlen (method
) + 1);
1457 strcpy (buf
, method
);
1458 tmp
= parse_method (buf
, &type
, &class, &category
, &selector
);
1462 struct symtab
*sym_symtab
= NULL
;
1463 struct symbol
*sym
= NULL
;
1464 struct minimal_symbol
*msym
= NULL
;
1466 strcpy (buf
, method
);
1467 tmp
= parse_selector (buf
, &selector
);
1472 sym
= lookup_symbol (selector
, block
, VAR_NAMESPACE
, 0, &sym_symtab
);
1482 msym
= lookup_minimal_symbol (selector
, 0, 0);
1487 syms
[csym
] = (struct symbol
*)msym
;
1493 find_methods (symtab
, type
, class, category
, selector
,
1494 syms
+ csym
, &ncsym
, &ncdebug
);
1496 find_methods (symtab
, type
, class, category
, selector
,
1497 NULL
, &ncsym
, &ncdebug
);
1499 /* If we didn't find any methods, just return. */
1500 if (ncsym
== 0 && ncdebug
== 0)
1503 /* Take debug symbols from the second batch of symbols and swap them
1504 * with debug symbols from the first batch. Repeat until either the
1505 * second section is out of debug symbols or the first section is
1506 * full of debug symbols. Either way we have all debug symbols
1507 * packed to the beginning of the buffer.
1512 while ((cdebug
< csym
) && (ncdebug
> 0))
1514 struct symbol
*s
= NULL
;
1515 /* First non-debugging symbol. */
1516 unsigned int i
= cdebug
;
1517 /* Last of second batch of debug symbols. */
1518 unsigned int j
= csym
+ ncdebug
- 1;
1524 /* We've moved a symbol from the second debug section to the
1540 return method
+ (tmp
- buf
);
1544 /* Sort debuggable symbols. */
1546 qsort (syms
, cdebug
, sizeof (struct minimal_symbol
*),
1549 /* Sort minimal_symbols. */
1550 if ((csym
- cdebug
) > 1)
1551 qsort (&syms
[cdebug
], csym
- cdebug
,
1552 sizeof (struct minimal_symbol
*), compare_classes
);
1554 /* Terminate the sym_arr list. */
1557 return method
+ (tmp
- buf
);
1561 print_object_command (char *args
, int from_tty
)
1563 struct value
*object
, *function
, *description
;
1564 CORE_ADDR string_addr
, object_addr
;
1568 if (!args
|| !*args
)
1570 "The 'print-object' command requires an argument (an Objective-C object)");
1573 struct expression
*expr
= parse_expression (args
);
1574 register struct cleanup
*old_chain
=
1575 make_cleanup (free_current_contents
, &expr
);
1578 object
= expr
->language_defn
->evaluate_exp (builtin_type_void_data_ptr
,
1579 expr
, &pc
, EVAL_NORMAL
);
1580 do_cleanups (old_chain
);
1583 /* Validate the address for sanity. */
1584 object_addr
= value_as_long (object
);
1585 read_memory (object_addr
, &c
, 1);
1587 function
= find_function_in_inferior ("_NSPrintForDebugger");
1588 if (function
== NULL
)
1589 error ("Unable to locate _NSPrintForDebugger in child process");
1591 description
= call_function_by_hand (function
, 1, &object
);
1593 string_addr
= value_as_long (description
);
1594 if (string_addr
== 0)
1595 error ("object returns null description");
1597 read_memory (string_addr
+ i
++, &c
, 1);
1600 { /* Read and print characters up to EOS. */
1602 printf_filtered ("%c", c
);
1603 read_memory (string_addr
+ i
++, &c
, 1);
1606 printf_filtered("<object returns empty description>");
1607 printf_filtered ("\n");
1610 /* The data structure 'methcalls' is used to detect method calls (thru
1611 * ObjC runtime lib functions objc_msgSend, objc_msgSendSuper, etc.),
1612 * and ultimately find the method being called.
1615 struct objc_methcall
{
1617 /* Return instance method to be called. */
1618 int (*stop_at
) (CORE_ADDR
, CORE_ADDR
*);
1619 /* Start of pc range corresponding to method invocation. */
1621 /* End of pc range corresponding to method invocation. */
1625 static int resolve_msgsend (CORE_ADDR pc
, CORE_ADDR
*new_pc
);
1626 static int resolve_msgsend_stret (CORE_ADDR pc
, CORE_ADDR
*new_pc
);
1627 static int resolve_msgsend_super (CORE_ADDR pc
, CORE_ADDR
*new_pc
);
1628 static int resolve_msgsend_super_stret (CORE_ADDR pc
, CORE_ADDR
*new_pc
);
1630 static struct objc_methcall methcalls
[] = {
1631 { "_objc_msgSend", resolve_msgsend
, 0, 0},
1632 { "_objc_msgSend_stret", resolve_msgsend_stret
, 0, 0},
1633 { "_objc_msgSendSuper", resolve_msgsend_super
, 0, 0},
1634 { "_objc_msgSendSuper_stret", resolve_msgsend_super_stret
, 0, 0},
1635 { "_objc_getClass", NULL
, 0, 0},
1636 { "_objc_getMetaClass", NULL
, 0, 0}
1639 #define nmethcalls (sizeof (methcalls) / sizeof (methcalls[0]))
1641 /* The following function, "find_objc_msgsend", fills in the data
1642 * structure "objc_msgs" by finding the addresses of each of the
1643 * (currently four) functions that it holds (of which objc_msgSend is
1644 * the first). This must be called each time symbols are loaded, in
1645 * case the functions have moved for some reason.
1649 find_objc_msgsend (void)
1652 for (i
= 0; i
< nmethcalls
; i
++) {
1654 struct minimal_symbol
*func
;
1656 /* Try both with and without underscore. */
1657 func
= lookup_minimal_symbol (methcalls
[i
].name
, NULL
, NULL
);
1658 if ((func
== NULL
) && (methcalls
[i
].name
[0] == '_')) {
1659 func
= lookup_minimal_symbol (methcalls
[i
].name
+ 1, NULL
, NULL
);
1662 methcalls
[i
].begin
= 0;
1663 methcalls
[i
].end
= 0;
1667 methcalls
[i
].begin
= SYMBOL_VALUE_ADDRESS (func
);
1669 methcalls
[i
].end
= SYMBOL_VALUE_ADDRESS (++func
);
1670 } while (methcalls
[i
].begin
== methcalls
[i
].end
);
1674 /* find_objc_msgcall (replaces pc_off_limits)
1676 * ALL that this function now does is to determine whether the input
1677 * address ("pc") is the address of one of the Objective-C message
1678 * dispatch functions (mainly objc_msgSend or objc_msgSendSuper), and
1679 * if so, it returns the address of the method that will be called.
1681 * The old function "pc_off_limits" used to do a lot of other things
1682 * in addition, such as detecting shared library jump stubs and
1683 * returning the address of the shlib function that would be called.
1684 * That functionality has been moved into the SKIP_TRAMPOLINE_CODE and
1685 * IN_SOLIB_TRAMPOLINE macros, which are resolved in the target-
1686 * dependent modules.
1689 struct objc_submethod_helper_data
{
1690 int (*f
) (CORE_ADDR
, CORE_ADDR
*);
1696 find_objc_msgcall_submethod_helper (void * arg
)
1698 struct objc_submethod_helper_data
*s
=
1699 (struct objc_submethod_helper_data
*) arg
;
1701 if (s
->f (s
->pc
, s
->new_pc
) == 0)
1708 find_objc_msgcall_submethod (int (*f
) (CORE_ADDR
, CORE_ADDR
*),
1712 struct objc_submethod_helper_data s
;
1718 if (catch_errors (find_objc_msgcall_submethod_helper
,
1720 "Unable to determine target of Objective-C method call (ignoring):\n",
1721 RETURN_MASK_ALL
) == 0)
1728 find_objc_msgcall (CORE_ADDR pc
, CORE_ADDR
*new_pc
)
1732 find_objc_msgsend ();
1733 if (new_pc
!= NULL
) { *new_pc
= 0; }
1735 for (i
= 0; i
< nmethcalls
; i
++)
1736 if ((pc
>= methcalls
[i
].begin
) && (pc
< methcalls
[i
].end
))
1738 if (methcalls
[i
].stop_at
!= NULL
)
1739 return find_objc_msgcall_submethod (methcalls
[i
].stop_at
,
1749 _initialize_objc_language (void)
1751 add_language (&objc_language_defn
);
1752 add_info ("selectors", selectors_info
, /* INFO SELECTORS command. */
1753 "All Objective-C selectors, or those matching REGEXP.");
1754 add_info ("classes", classes_info
, /* INFO CLASSES command. */
1755 "All Objective-C classes, or those matching REGEXP.");
1756 add_com ("print-object", class_vars
, print_object_command
,
1757 "Ask an Objective-C object to print itself.");
1758 add_com_alias ("po", "print-object", class_vars
, 1);
1761 #if defined (__powerpc__) || defined (__ppc__)
1762 static unsigned long FETCH_ARGUMENT (int i
)
1764 return read_register (3 + i
);
1766 #elif defined (__i386__)
1767 static unsigned long FETCH_ARGUMENT (int i
)
1769 CORE_ADDR stack
= read_register (SP_REGNUM
);
1770 return read_memory_unsigned_integer (stack
+ (4 * (i
+ 1)), 4);
1772 #elif defined (__sparc__)
1773 static unsigned long FETCH_ARGUMENT (int i
)
1775 return read_register (O0_REGNUM
+ i
);
1777 #elif defined (__hppa__) || defined (__hppa)
1778 static unsigned long FETCH_ARGUMENT (int i
)
1780 return read_register (R0_REGNUM
+ 26 - i
);
1783 #error unknown architecture
1786 #if defined (__hppa__) || defined (__hppa)
1787 static CORE_ADDR
CONVERT_FUNCPTR (CORE_ADDR pc
)
1790 pc
= (CORE_ADDR
) read_memory_integer (pc
& ~0x3, 4);
1795 static CORE_ADDR
CONVERT_FUNCPTR (CORE_ADDR pc
)
1802 read_objc_method (CORE_ADDR addr
, struct objc_method
*method
)
1804 method
->name
= read_memory_unsigned_integer (addr
+ 0, 4);
1805 method
->types
= read_memory_unsigned_integer (addr
+ 4, 4);
1806 method
->imp
= read_memory_unsigned_integer (addr
+ 8, 4);
1810 unsigned long read_objc_methlist_nmethods (CORE_ADDR addr
)
1812 return read_memory_unsigned_integer (addr
+ 4, 4);
1816 read_objc_methlist_method (CORE_ADDR addr
, unsigned long num
,
1817 struct objc_method
*method
)
1819 CHECK_FATAL (num
< read_objc_methlist_nmethods (addr
));
1820 read_objc_method (addr
+ 8 + (12 * num
), method
);
1824 read_objc_object (CORE_ADDR addr
, struct objc_object
*object
)
1826 object
->isa
= read_memory_unsigned_integer (addr
, 4);
1830 read_objc_super (CORE_ADDR addr
, struct objc_super
*super
)
1832 super
->receiver
= read_memory_unsigned_integer (addr
, 4);
1833 super
->class = read_memory_unsigned_integer (addr
+ 4, 4);
1837 read_objc_class (CORE_ADDR addr
, struct objc_class
*class)
1839 class->isa
= read_memory_unsigned_integer (addr
, 4);
1840 class->super_class
= read_memory_unsigned_integer (addr
+ 4, 4);
1841 class->name
= read_memory_unsigned_integer (addr
+ 8, 4);
1842 class->version
= read_memory_unsigned_integer (addr
+ 12, 4);
1843 class->info
= read_memory_unsigned_integer (addr
+ 16, 4);
1844 class->instance_size
= read_memory_unsigned_integer (addr
+ 18, 4);
1845 class->ivars
= read_memory_unsigned_integer (addr
+ 24, 4);
1846 class->methods
= read_memory_unsigned_integer (addr
+ 28, 4);
1847 class->cache
= read_memory_unsigned_integer (addr
+ 32, 4);
1848 class->protocols
= read_memory_unsigned_integer (addr
+ 36, 4);
1852 find_implementation_from_class (CORE_ADDR
class, CORE_ADDR sel
)
1854 CORE_ADDR subclass
= class;
1856 while (subclass
!= 0)
1859 struct objc_class class_str
;
1860 unsigned mlistnum
= 0;
1862 read_objc_class (subclass
, &class_str
);
1867 unsigned long nmethods
;
1870 mlist
= read_memory_unsigned_integer (class_str
.methods
+
1875 nmethods
= read_objc_methlist_nmethods (mlist
);
1877 for (i
= 0; i
< nmethods
; i
++)
1879 struct objc_method meth_str
;
1880 read_objc_methlist_method (mlist
, i
, &meth_str
);
1884 "checking method 0x%lx against selector 0x%lx\n",
1885 meth_str
.name
, sel
);
1888 if (meth_str
.name
== sel
)
1889 return CONVERT_FUNCPTR (meth_str
.imp
);
1893 subclass
= class_str
.super_class
;
1900 find_implementation (CORE_ADDR object
, CORE_ADDR sel
)
1902 struct objc_object ostr
;
1906 read_objc_object (object
, &ostr
);
1910 return find_implementation_from_class (ostr
.isa
, sel
);
1914 resolve_msgsend (CORE_ADDR pc
, CORE_ADDR
*new_pc
)
1920 object
= FETCH_ARGUMENT (0);
1921 sel
= FETCH_ARGUMENT (1);
1923 res
= find_implementation (object
, sel
);
1932 resolve_msgsend_stret (CORE_ADDR pc
, CORE_ADDR
*new_pc
)
1938 object
= FETCH_ARGUMENT (1);
1939 sel
= FETCH_ARGUMENT (2);
1941 res
= find_implementation (object
, sel
);
1950 resolve_msgsend_super (CORE_ADDR pc
, CORE_ADDR
*new_pc
)
1952 struct objc_super sstr
;
1958 super
= FETCH_ARGUMENT (0);
1959 sel
= FETCH_ARGUMENT (1);
1961 read_objc_super (super
, &sstr
);
1962 if (sstr
.class == 0)
1965 res
= find_implementation_from_class (sstr
.class, sel
);
1974 resolve_msgsend_super_stret (CORE_ADDR pc
, CORE_ADDR
*new_pc
)
1976 struct objc_super sstr
;
1982 super
= FETCH_ARGUMENT (1);
1983 sel
= FETCH_ARGUMENT (2);
1985 read_objc_super (super
, &sstr
);
1986 if (sstr
.class == 0)
1989 res
= find_implementation_from_class (sstr
.class, sel
);