* gdbarch.sh (push_dummy_code): Add REGCACHE argument.
[deliverable/binutils-gdb.git] / gdb / objc-lang.c
CommitLineData
d2e6263c 1/* Objective-C language support routines for GDB, the GNU debugger.
b81654f1 2
6aba47ca 3 Copyright (C) 2002, 2003, 2004, 2005, 2007 Free Software Foundation, Inc.
b81654f1 4
437666f8
AC
5 Contributed by Apple Computer, Inc.
6 Written by Michael Snyder.
b81654f1 7
437666f8 8 This file is part of GDB.
b81654f1 9
437666f8
AC
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.
14
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.
19
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
197e01b6
EZ
22 Foundation, Inc., 51 Franklin Street, Fifth Floor,
23 Boston, MA 02110-1301, USA. */
b81654f1
MS
24
25#include "defs.h"
26#include "symtab.h"
27#include "gdbtypes.h"
28#include "expression.h"
29#include "parser-defs.h"
30#include "language.h"
d2e6263c 31#include "c-lang.h"
b81654f1 32#include "objc-lang.h"
60250e8b 33#include "exceptions.h"
b81654f1
MS
34#include "complaints.h"
35#include "value.h"
36#include "symfile.h"
37#include "objfiles.h"
7248f48e 38#include "gdb_string.h" /* for strchr */
b81654f1
MS
39#include "target.h" /* for target_has_execution */
40#include "gdbcore.h"
41#include "gdbcmd.h"
42#include "frame.h"
43#include "gdb_regex.h"
44#include "regcache.h"
fe898f56 45#include "block.h"
04714b91 46#include "infcall.h"
4e45ca2e 47#include "valprint.h"
e8f3fcdd 48#include "gdb_assert.h"
b81654f1
MS
49
50#include <ctype.h>
51
52struct objc_object {
53 CORE_ADDR isa;
54};
55
56struct objc_class {
57 CORE_ADDR isa;
58 CORE_ADDR super_class;
59 CORE_ADDR name;
60 long version;
61 long info;
62 long instance_size;
63 CORE_ADDR ivars;
64 CORE_ADDR methods;
65 CORE_ADDR cache;
66 CORE_ADDR protocols;
67};
68
69struct objc_super {
70 CORE_ADDR receiver;
71 CORE_ADDR class;
72};
73
74struct objc_method {
75 CORE_ADDR name;
76 CORE_ADDR types;
77 CORE_ADDR imp;
78};
79
d2e6263c
MS
80/* Lookup a structure type named "struct NAME", visible in lexical
81 block BLOCK. If NOERR is nonzero, return zero if NAME is not
82 suitably defined. */
b81654f1
MS
83
84struct symbol *
85lookup_struct_typedef (char *name, struct block *block, int noerr)
86{
f86f5ca3 87 struct symbol *sym;
b81654f1 88
176620f1 89 sym = lookup_symbol (name, block, STRUCT_DOMAIN, 0,
d2e6263c 90 (struct symtab **) NULL);
b81654f1
MS
91
92 if (sym == NULL)
93 {
94 if (noerr)
95 return 0;
96 else
8a3fe4f8 97 error (_("No struct type named %s."), name);
b81654f1
MS
98 }
99 if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_STRUCT)
100 {
101 if (noerr)
102 return 0;
103 else
8a3fe4f8 104 error (_("This context has class, union or enum %s, not a struct."),
d2e6263c 105 name);
b81654f1
MS
106 }
107 return sym;
108}
109
110CORE_ADDR
111lookup_objc_class (char *classname)
112{
113 struct value * function, *classval;
114
115 if (! target_has_execution)
116 {
d2e6263c 117 /* Can't call into inferior to lookup class. */
b81654f1
MS
118 return 0;
119 }
120
121 if (lookup_minimal_symbol("objc_lookUpClass", 0, 0))
122 function = find_function_in_inferior("objc_lookUpClass");
123 else if (lookup_minimal_symbol ("objc_lookup_class", 0, 0))
124 function = find_function_in_inferior("objc_lookup_class");
125 else
126 {
e2e0b3e5 127 complaint (&symfile_complaints, _("no way to lookup Objective-C classes"));
b81654f1
MS
128 return 0;
129 }
130
131 classval = value_string (classname, strlen (classname) + 1);
132 classval = value_coerce_array (classval);
133 return (CORE_ADDR) value_as_long (call_function_by_hand (function,
134 1, &classval));
135}
136
c253954e 137CORE_ADDR
b81654f1
MS
138lookup_child_selector (char *selname)
139{
140 struct value * function, *selstring;
141
142 if (! target_has_execution)
143 {
d2e6263c 144 /* Can't call into inferior to lookup selector. */
b81654f1
MS
145 return 0;
146 }
147
148 if (lookup_minimal_symbol("sel_getUid", 0, 0))
149 function = find_function_in_inferior("sel_getUid");
150 else if (lookup_minimal_symbol ("sel_get_any_uid", 0, 0))
151 function = find_function_in_inferior("sel_get_any_uid");
152 else
153 {
e2e0b3e5 154 complaint (&symfile_complaints, _("no way to lookup Objective-C selectors"));
b81654f1
MS
155 return 0;
156 }
157
d2e6263c
MS
158 selstring = value_coerce_array (value_string (selname,
159 strlen (selname) + 1));
b81654f1
MS
160 return value_as_long (call_function_by_hand (function, 1, &selstring));
161}
162
163struct value *
164value_nsstring (char *ptr, int len)
165{
166 struct value *stringValue[3];
167 struct value *function, *nsstringValue;
168 struct symbol *sym;
169 struct type *type;
170
171 if (!target_has_execution)
d2e6263c 172 return 0; /* Can't call into inferior to create NSString. */
b81654f1 173
5e488a7b
AC
174 sym = lookup_struct_typedef("NSString", 0, 1);
175 if (sym == NULL)
176 sym = lookup_struct_typedef("NXString", 0, 1);
177 if (sym == NULL)
b81654f1
MS
178 type = lookup_pointer_type(builtin_type_void);
179 else
180 type = lookup_pointer_type(SYMBOL_TYPE (sym));
181
182 stringValue[2] = value_string(ptr, len);
183 stringValue[2] = value_coerce_array(stringValue[2]);
d2e6263c 184 /* _NSNewStringFromCString replaces "istr" after Lantern2A. */
b81654f1
MS
185 if (lookup_minimal_symbol("_NSNewStringFromCString", 0, 0))
186 {
187 function = find_function_in_inferior("_NSNewStringFromCString");
188 nsstringValue = call_function_by_hand(function, 1, &stringValue[2]);
189 }
190 else if (lookup_minimal_symbol("istr", 0, 0))
191 {
192 function = find_function_in_inferior("istr");
193 nsstringValue = call_function_by_hand(function, 1, &stringValue[2]);
194 }
195 else if (lookup_minimal_symbol("+[NSString stringWithCString:]", 0, 0))
196 {
197 function = find_function_in_inferior("+[NSString stringWithCString:]");
198 stringValue[0] = value_from_longest
199 (builtin_type_long, lookup_objc_class ("NSString"));
200 stringValue[1] = value_from_longest
201 (builtin_type_long, lookup_child_selector ("stringWithCString:"));
202 nsstringValue = call_function_by_hand(function, 3, &stringValue[0]);
203 }
204 else
8a3fe4f8 205 error (_("NSString: internal error -- no way to create new NSString"));
b81654f1 206
04624583 207 deprecated_set_value_type (nsstringValue, type);
b81654f1
MS
208 return nsstringValue;
209}
210
d2e6263c 211/* Objective-C name demangling. */
b81654f1
MS
212
213char *
9a3d7dfd 214objc_demangle (const char *mangled, int options)
b81654f1
MS
215{
216 char *demangled, *cp;
217
218 if (mangled[0] == '_' &&
219 (mangled[1] == 'i' || mangled[1] == 'c') &&
220 mangled[2] == '_')
221 {
222 cp = demangled = xmalloc(strlen(mangled) + 2);
223
224 if (mangled[1] == 'i')
225 *cp++ = '-'; /* for instance method */
226 else
227 *cp++ = '+'; /* for class method */
228
229 *cp++ = '['; /* opening left brace */
230 strcpy(cp, mangled+3); /* tack on the rest of the mangled name */
231
232 while (*cp && *cp == '_')
233 cp++; /* skip any initial underbars in class name */
234
7248f48e
AF
235 cp = strchr(cp, '_');
236 if (!cp) /* find first non-initial underbar */
b81654f1 237 {
7248f48e 238 xfree(demangled); /* not mangled name */
b81654f1
MS
239 return NULL;
240 }
241 if (cp[1] == '_') { /* easy case: no category name */
242 *cp++ = ' '; /* replace two '_' with one ' ' */
243 strcpy(cp, mangled + (cp - demangled) + 2);
244 }
245 else {
246 *cp++ = '('; /* less easy case: category name */
7248f48e
AF
247 cp = strchr(cp, '_');
248 if (!cp)
b81654f1 249 {
7248f48e 250 xfree(demangled); /* not mangled name */
b81654f1
MS
251 return NULL;
252 }
253 *cp++ = ')';
d2e6263c 254 *cp++ = ' '; /* overwriting 1st char of method name... */
b81654f1
MS
255 strcpy(cp, mangled + (cp - demangled)); /* get it back */
256 }
257
258 while (*cp && *cp == '_')
259 cp++; /* skip any initial underbars in method name */
260
261 for (; *cp; cp++)
262 if (*cp == '_')
263 *cp = ':'; /* replace remaining '_' with ':' */
264
265 *cp++ = ']'; /* closing right brace */
266 *cp++ = 0; /* string terminator */
267 return demangled;
268 }
269 else
d2e6263c 270 return NULL; /* Not an objc mangled name. */
b81654f1
MS
271}
272
d2e6263c
MS
273/* Print the character C on STREAM as part of the contents of a
274 literal string whose delimiter is QUOTER. Note that that format
275 for printing characters and strings is language specific. */
b81654f1
MS
276
277static void
f86f5ca3 278objc_emit_char (int c, struct ui_file *stream, int quoter)
b81654f1
MS
279{
280
d2e6263c 281 c &= 0xFF; /* Avoid sign bit follies. */
b81654f1
MS
282
283 if (PRINT_LITERAL_FORM (c))
284 {
285 if (c == '\\' || c == quoter)
286 {
287 fputs_filtered ("\\", stream);
288 }
289 fprintf_filtered (stream, "%c", c);
290 }
291 else
292 {
293 switch (c)
294 {
295 case '\n':
296 fputs_filtered ("\\n", stream);
297 break;
298 case '\b':
299 fputs_filtered ("\\b", stream);
300 break;
301 case '\t':
302 fputs_filtered ("\\t", stream);
303 break;
304 case '\f':
305 fputs_filtered ("\\f", stream);
306 break;
307 case '\r':
308 fputs_filtered ("\\r", stream);
309 break;
310 case '\033':
311 fputs_filtered ("\\e", stream);
312 break;
313 case '\007':
314 fputs_filtered ("\\a", stream);
315 break;
316 default:
317 fprintf_filtered (stream, "\\%.3o", (unsigned int) c);
318 break;
319 }
320 }
321}
322
323static void
324objc_printchar (int c, struct ui_file *stream)
325{
326 fputs_filtered ("'", stream);
327 objc_emit_char (c, stream, '\'');
328 fputs_filtered ("'", stream);
329}
330
d2e6263c
MS
331/* Print the character string STRING, printing at most LENGTH
332 characters. Printing stops early if the number hits print_max;
333 repeat counts are printed as appropriate. Print ellipses at the
334 end if we had to stop before printing LENGTH characters, or if
335 FORCE_ELLIPSES. */
b81654f1
MS
336
337static void
fc1a4b47 338objc_printstr (struct ui_file *stream, const gdb_byte *string,
36e53c63 339 unsigned int length, int width, int force_ellipses)
b81654f1 340{
f86f5ca3 341 unsigned int i;
b81654f1
MS
342 unsigned int things_printed = 0;
343 int in_quotes = 0;
344 int need_comma = 0;
b81654f1
MS
345
346 /* If the string was not truncated due to `set print elements', and
d2e6263c
MS
347 the last byte of it is a null, we don't print that, in
348 traditional C style. */
b81654f1
MS
349 if ((!force_ellipses) && length > 0 && string[length-1] == '\0')
350 length--;
351
352 if (length == 0)
353 {
354 fputs_filtered ("\"\"", stream);
355 return;
356 }
357
358 for (i = 0; i < length && things_printed < print_max; ++i)
359 {
d2e6263c
MS
360 /* Position of the character we are examining to see whether it
361 is repeated. */
b81654f1
MS
362 unsigned int rep1;
363 /* Number of repetitions we have detected so far. */
364 unsigned int reps;
365
366 QUIT;
367
368 if (need_comma)
369 {
370 fputs_filtered (", ", stream);
371 need_comma = 0;
372 }
373
374 rep1 = i + 1;
375 reps = 1;
376 while (rep1 < length && string[rep1] == string[i])
377 {
378 ++rep1;
379 ++reps;
380 }
381
382 if (reps > repeat_count_threshold)
383 {
384 if (in_quotes)
385 {
386 if (inspect_it)
387 fputs_filtered ("\\\", ", stream);
388 else
389 fputs_filtered ("\", ", stream);
390 in_quotes = 0;
391 }
392 objc_printchar (string[i], stream);
393 fprintf_filtered (stream, " <repeats %u times>", reps);
394 i = rep1 - 1;
395 things_printed += repeat_count_threshold;
396 need_comma = 1;
397 }
398 else
399 {
400 if (!in_quotes)
401 {
402 if (inspect_it)
403 fputs_filtered ("\\\"", stream);
404 else
405 fputs_filtered ("\"", stream);
406 in_quotes = 1;
407 }
408 objc_emit_char (string[i], stream, '"');
409 ++things_printed;
410 }
411 }
412
413 /* Terminate the quotes if necessary. */
414 if (in_quotes)
415 {
416 if (inspect_it)
417 fputs_filtered ("\\\"", stream);
418 else
419 fputs_filtered ("\"", stream);
420 }
421
422 if (force_ellipses || i < length)
423 fputs_filtered ("...", stream);
424}
425
d2e6263c
MS
426/* Create a fundamental C type using default reasonable for the
427 current target.
428
429 Some object/debugging file formats (DWARF version 1, COFF, etc) do
430 not define fundamental types such as "int" or "double". Others
431 (stabs or DWARF version 2, etc) do define fundamental types. For
432 the formats which don't provide fundamental types, gdb can create
433 such types using this function.
434
435 FIXME: Some compilers distinguish explicitly signed integral types
436 (signed short, signed int, signed long) from "regular" integral
437 types (short, int, long) in the debugging information. There is
438 some disagreement as to how useful this feature is. In particular,
439 gcc does not support this. Also, only some debugging formats allow
440 the distinction to be passed on to a debugger. For now, we always
441 just use "short", "int", or "long" as the type name, for both the
442 implicit and explicitly signed types. This also makes life easier
443 for the gdb test suite since we don't have to account for the
444 differences in output depending upon what the compiler and
445 debugging format support. We will probably have to re-examine the
446 issue when gdb starts taking it's fundamental type information
447 directly from the debugging information supplied by the compiler.
448 fnf@cygnus.com */
b81654f1
MS
449
450static struct type *
451objc_create_fundamental_type (struct objfile *objfile, int typeid)
452{
f86f5ca3 453 struct type *type = NULL;
b81654f1
MS
454
455 switch (typeid)
456 {
457 default:
d2e6263c
MS
458 /* FIXME: For now, if we are asked to produce a type not in
459 this language, create the equivalent of a C integer type
460 with the name "<?type?>". When all the dust settles from
461 the type reconstruction work, this should probably become
462 an error. */
b81654f1 463 type = init_type (TYPE_CODE_INT,
9a76efb6 464 gdbarch_int_bit (current_gdbarch) / TARGET_CHAR_BIT,
b81654f1 465 0, "<?type?>", objfile);
8a3fe4f8 466 warning (_("internal error: no C/C++ fundamental type %d"), typeid);
b81654f1
MS
467 break;
468 case FT_VOID:
469 type = init_type (TYPE_CODE_VOID,
470 TARGET_CHAR_BIT / TARGET_CHAR_BIT,
471 0, "void", objfile);
472 break;
473 case FT_CHAR:
474 type = init_type (TYPE_CODE_INT,
475 TARGET_CHAR_BIT / TARGET_CHAR_BIT,
476 0, "char", objfile);
477 break;
478 case FT_SIGNED_CHAR:
479 type = init_type (TYPE_CODE_INT,
480 TARGET_CHAR_BIT / TARGET_CHAR_BIT,
481 0, "signed char", objfile);
482 break;
483 case FT_UNSIGNED_CHAR:
484 type = init_type (TYPE_CODE_INT,
485 TARGET_CHAR_BIT / TARGET_CHAR_BIT,
486 TYPE_FLAG_UNSIGNED, "unsigned char", objfile);
487 break;
488 case FT_SHORT:
489 type = init_type (TYPE_CODE_INT,
9a76efb6 490 gdbarch_short_bit (current_gdbarch) / TARGET_CHAR_BIT,
b81654f1
MS
491 0, "short", objfile);
492 break;
493 case FT_SIGNED_SHORT:
494 type = init_type (TYPE_CODE_INT,
9a76efb6 495 gdbarch_short_bit (current_gdbarch) / TARGET_CHAR_BIT,
b81654f1
MS
496 0, "short", objfile); /* FIXME-fnf */
497 break;
498 case FT_UNSIGNED_SHORT:
499 type = init_type (TYPE_CODE_INT,
9a76efb6 500 gdbarch_short_bit (current_gdbarch) / TARGET_CHAR_BIT,
b81654f1
MS
501 TYPE_FLAG_UNSIGNED, "unsigned short", objfile);
502 break;
503 case FT_INTEGER:
504 type = init_type (TYPE_CODE_INT,
9a76efb6 505 gdbarch_int_bit (current_gdbarch) / TARGET_CHAR_BIT,
b81654f1
MS
506 0, "int", objfile);
507 break;
508 case FT_SIGNED_INTEGER:
509 type = init_type (TYPE_CODE_INT,
9a76efb6 510 gdbarch_int_bit (current_gdbarch) / TARGET_CHAR_BIT,
b81654f1
MS
511 0, "int", objfile); /* FIXME -fnf */
512 break;
513 case FT_UNSIGNED_INTEGER:
514 type = init_type (TYPE_CODE_INT,
9a76efb6 515 gdbarch_int_bit (current_gdbarch) / TARGET_CHAR_BIT,
b81654f1
MS
516 TYPE_FLAG_UNSIGNED, "unsigned int", objfile);
517 break;
518 case FT_LONG:
519 type = init_type (TYPE_CODE_INT,
9a76efb6 520 gdbarch_long_bit (current_gdbarch) / TARGET_CHAR_BIT,
b81654f1
MS
521 0, "long", objfile);
522 break;
523 case FT_SIGNED_LONG:
524 type = init_type (TYPE_CODE_INT,
9a76efb6 525 gdbarch_long_bit (current_gdbarch) / TARGET_CHAR_BIT,
b81654f1
MS
526 0, "long", objfile); /* FIXME -fnf */
527 break;
528 case FT_UNSIGNED_LONG:
529 type = init_type (TYPE_CODE_INT,
9a76efb6 530 gdbarch_long_bit (current_gdbarch) / TARGET_CHAR_BIT,
b81654f1
MS
531 TYPE_FLAG_UNSIGNED, "unsigned long", objfile);
532 break;
533 case FT_LONG_LONG:
534 type = init_type (TYPE_CODE_INT,
9a76efb6
UW
535 gdbarch_long_long_bit (current_gdbarch)
536 / TARGET_CHAR_BIT,
b81654f1
MS
537 0, "long long", objfile);
538 break;
539 case FT_SIGNED_LONG_LONG:
540 type = init_type (TYPE_CODE_INT,
9a76efb6
UW
541 gdbarch_long_long_bit (current_gdbarch)
542 / TARGET_CHAR_BIT,
b81654f1
MS
543 0, "signed long long", objfile);
544 break;
545 case FT_UNSIGNED_LONG_LONG:
546 type = init_type (TYPE_CODE_INT,
9a76efb6
UW
547 gdbarch_long_long_bit (current_gdbarch)
548 / TARGET_CHAR_BIT,
b81654f1
MS
549 TYPE_FLAG_UNSIGNED, "unsigned long long", objfile);
550 break;
551 case FT_FLOAT:
552 type = init_type (TYPE_CODE_FLT,
ea06eb3d 553 gdbarch_float_bit (current_gdbarch) / TARGET_CHAR_BIT,
b81654f1
MS
554 0, "float", objfile);
555 break;
556 case FT_DBL_PREC_FLOAT:
557 type = init_type (TYPE_CODE_FLT,
ea06eb3d
UW
558 gdbarch_double_bit (current_gdbarch)
559 / TARGET_CHAR_BIT,
b81654f1
MS
560 0, "double", objfile);
561 break;
562 case FT_EXT_PREC_FLOAT:
563 type = init_type (TYPE_CODE_FLT,
ea06eb3d
UW
564 gdbarch_long_double_bit (current_gdbarch)
565 / TARGET_CHAR_BIT,
b81654f1
MS
566 0, "long double", objfile);
567 break;
568 }
569 return (type);
570}
571
f636b87d
AF
572/* Determine if we are currently in the Objective-C dispatch function.
573 If so, get the address of the method function that the dispatcher
574 would call and use that as the function to step into instead. Also
575 skip over the trampoline for the function (if any). This is better
576 for the user since they are only interested in stepping into the
577 method function anyway. */
578static CORE_ADDR
52f729a7 579objc_skip_trampoline (struct frame_info *frame, CORE_ADDR stop_pc)
f636b87d
AF
580{
581 CORE_ADDR real_stop_pc;
582 CORE_ADDR method_stop_pc;
583
52f729a7
UW
584 real_stop_pc = gdbarch_skip_trampoline_code
585 (current_gdbarch, frame, stop_pc);
f636b87d
AF
586
587 if (real_stop_pc != 0)
588 find_objc_msgcall (real_stop_pc, &method_stop_pc);
589 else
590 find_objc_msgcall (stop_pc, &method_stop_pc);
591
592 if (method_stop_pc)
593 {
e76f05fa 594 real_stop_pc = gdbarch_skip_trampoline_code
52f729a7 595 (current_gdbarch, frame, method_stop_pc);
f636b87d
AF
596 if (real_stop_pc == 0)
597 real_stop_pc = method_stop_pc;
598 }
599
600 return real_stop_pc;
601}
602
b81654f1
MS
603
604/* Table mapping opcodes into strings for printing operators
605 and precedences of the operators. */
606
607static const struct op_print objc_op_print_tab[] =
608 {
609 {",", BINOP_COMMA, PREC_COMMA, 0},
610 {"=", BINOP_ASSIGN, PREC_ASSIGN, 1},
611 {"||", BINOP_LOGICAL_OR, PREC_LOGICAL_OR, 0},
612 {"&&", BINOP_LOGICAL_AND, PREC_LOGICAL_AND, 0},
613 {"|", BINOP_BITWISE_IOR, PREC_BITWISE_IOR, 0},
614 {"^", BINOP_BITWISE_XOR, PREC_BITWISE_XOR, 0},
615 {"&", BINOP_BITWISE_AND, PREC_BITWISE_AND, 0},
616 {"==", BINOP_EQUAL, PREC_EQUAL, 0},
617 {"!=", BINOP_NOTEQUAL, PREC_EQUAL, 0},
618 {"<=", BINOP_LEQ, PREC_ORDER, 0},
619 {">=", BINOP_GEQ, PREC_ORDER, 0},
620 {">", BINOP_GTR, PREC_ORDER, 0},
621 {"<", BINOP_LESS, PREC_ORDER, 0},
622 {">>", BINOP_RSH, PREC_SHIFT, 0},
623 {"<<", BINOP_LSH, PREC_SHIFT, 0},
624 {"+", BINOP_ADD, PREC_ADD, 0},
625 {"-", BINOP_SUB, PREC_ADD, 0},
626 {"*", BINOP_MUL, PREC_MUL, 0},
627 {"/", BINOP_DIV, PREC_MUL, 0},
628 {"%", BINOP_REM, PREC_MUL, 0},
629 {"@", BINOP_REPEAT, PREC_REPEAT, 0},
630 {"-", UNOP_NEG, PREC_PREFIX, 0},
631 {"!", UNOP_LOGICAL_NOT, PREC_PREFIX, 0},
632 {"~", UNOP_COMPLEMENT, PREC_PREFIX, 0},
633 {"*", UNOP_IND, PREC_PREFIX, 0},
634 {"&", UNOP_ADDR, PREC_PREFIX, 0},
635 {"sizeof ", UNOP_SIZEOF, PREC_PREFIX, 0},
636 {"++", UNOP_PREINCREMENT, PREC_PREFIX, 0},
637 {"--", UNOP_PREDECREMENT, PREC_PREFIX, 0},
e8f3fcdd 638 {NULL, OP_NULL, PREC_NULL, 0}
b81654f1
MS
639};
640
641struct type ** const (objc_builtin_types[]) =
642{
643 &builtin_type_int,
644 &builtin_type_long,
645 &builtin_type_short,
646 &builtin_type_char,
647 &builtin_type_float,
648 &builtin_type_double,
649 &builtin_type_void,
650 &builtin_type_long_long,
651 &builtin_type_signed_char,
652 &builtin_type_unsigned_char,
653 &builtin_type_unsigned_short,
654 &builtin_type_unsigned_int,
655 &builtin_type_unsigned_long,
656 &builtin_type_unsigned_long_long,
657 &builtin_type_long_double,
658 &builtin_type_complex,
659 &builtin_type_double_complex,
660 0
661};
662
663const struct language_defn objc_language_defn = {
d2e6263c 664 "objective-c", /* Language name */
b81654f1
MS
665 language_objc,
666 objc_builtin_types,
667 range_check_off,
668 type_check_off,
669 case_sensitive_on,
7ca2d3a3 670 array_row_major,
5f9769d1 671 &exp_descriptor_standard,
b81654f1
MS
672 objc_parse,
673 objc_error,
e85c3284 674 null_post_parser,
b81654f1
MS
675 objc_printchar, /* Print a character constant */
676 objc_printstr, /* Function to print string constant */
677 objc_emit_char,
678 objc_create_fundamental_type, /* Create fundamental type in this language */
679 c_print_type, /* Print a type using appropriate syntax */
680 c_val_print, /* Print a value using appropriate syntax */
681 c_value_print, /* Print a top-level value */
f636b87d 682 objc_skip_trampoline, /* Language specific skip_trampoline */
5f9a71c3
DC
683 value_of_this, /* value_of_this */
684 basic_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */
b368761e 685 basic_lookup_transparent_type,/* lookup_transparent_type */
9a3d7dfd 686 objc_demangle, /* Language specific symbol demangler */
31c27f77 687 NULL, /* Language specific class_name_from_physname */
d2e6263c
MS
688 objc_op_print_tab, /* Expression operators for printing */
689 1, /* C-style arrays */
b81654f1
MS
690 0, /* String lower bound */
691 &builtin_type_char, /* Type of string elements */
6084f43a 692 default_word_break_characters,
f290d38e 693 NULL, /* FIXME: la_language_arch_info. */
e79af960 694 default_print_array_index,
b81654f1
MS
695 LANG_MAGIC
696};
697
698/*
699 * ObjC:
d2e6263c 700 * Following functions help construct Objective-C message calls
b81654f1
MS
701 */
702
d2e6263c 703struct selname /* For parsing Objective-C. */
b81654f1
MS
704 {
705 struct selname *next;
706 char *msglist_sel;
707 int msglist_len;
708 };
709
710static int msglist_len;
711static struct selname *selname_chain;
712static char *msglist_sel;
713
714void
715start_msglist(void)
716{
f86f5ca3 717 struct selname *new =
b81654f1
MS
718 (struct selname *) xmalloc (sizeof (struct selname));
719
720 new->next = selname_chain;
721 new->msglist_len = msglist_len;
722 new->msglist_sel = msglist_sel;
723 msglist_len = 0;
724 msglist_sel = (char *)xmalloc(1);
725 *msglist_sel = 0;
726 selname_chain = new;
727}
728
729void
730add_msglist(struct stoken *str, int addcolon)
731{
732 char *s, *p;
733 int len, plen;
734
d2e6263c
MS
735 if (str == 0) { /* Unnamed arg, or... */
736 if (addcolon == 0) { /* variable number of args. */
b81654f1
MS
737 msglist_len++;
738 return;
739 }
740 p = "";
741 plen = 0;
742 } else {
743 p = str->ptr;
744 plen = str->length;
745 }
746 len = plen + strlen(msglist_sel) + 2;
747 s = (char *)xmalloc(len);
748 strcpy(s, msglist_sel);
749 strncat(s, p, plen);
7248f48e 750 xfree(msglist_sel);
b81654f1
MS
751 msglist_sel = s;
752 if (addcolon) {
753 s[len-2] = ':';
754 s[len-1] = 0;
755 msglist_len++;
756 } else
757 s[len-2] = '\0';
758}
759
760int
761end_msglist(void)
762{
f86f5ca3
PH
763 int val = msglist_len;
764 struct selname *sel = selname_chain;
765 char *p = msglist_sel;
c253954e 766 CORE_ADDR selid;
b81654f1
MS
767
768 selname_chain = sel->next;
769 msglist_len = sel->msglist_len;
770 msglist_sel = sel->msglist_sel;
771 selid = lookup_child_selector(p);
772 if (!selid)
8a3fe4f8 773 error (_("Can't find selector \"%s\""), p);
b81654f1 774 write_exp_elt_longcst (selid);
7248f48e 775 xfree(p);
d2e6263c 776 write_exp_elt_longcst (val); /* Number of args */
7248f48e 777 xfree(sel);
b81654f1
MS
778
779 return val;
780}
781
782/*
783 * Function: specialcmp (char *a, char *b)
784 *
785 * Special strcmp: treats ']' and ' ' as end-of-string.
d2e6263c 786 * Used for qsorting lists of objc methods (either by class or selector).
b81654f1
MS
787 */
788
b9362cc7
AC
789static int
790specialcmp (char *a, char *b)
b81654f1
MS
791{
792 while (*a && *a != ' ' && *a != ']' && *b && *b != ' ' && *b != ']')
793 {
794 if (*a != *b)
795 return *a - *b;
796 a++, b++;
797 }
798 if (*a && *a != ' ' && *a != ']')
799 return 1; /* a is longer therefore greater */
800 if (*b && *b != ' ' && *b != ']')
801 return -1; /* a is shorter therefore lesser */
802 return 0; /* a and b are identical */
803}
804
805/*
36e53c63 806 * Function: compare_selectors (const void *, const void *)
b81654f1 807 *
d2e6263c
MS
808 * Comparison function for use with qsort. Arguments are symbols or
809 * msymbols Compares selector part of objc method name alphabetically.
b81654f1
MS
810 */
811
812static int
36e53c63 813compare_selectors (const void *a, const void *b)
b81654f1
MS
814{
815 char *aname, *bname;
816
de5ad195
DC
817 aname = SYMBOL_PRINT_NAME (*(struct symbol **) a);
818 bname = SYMBOL_PRINT_NAME (*(struct symbol **) b);
7248f48e 819 if (aname == NULL || bname == NULL)
8a3fe4f8 820 error (_("internal: compare_selectors(1)"));
b81654f1 821
7248f48e
AF
822 aname = strchr(aname, ' ');
823 bname = strchr(bname, ' ');
824 if (aname == NULL || bname == NULL)
8a3fe4f8 825 error (_("internal: compare_selectors(2)"));
b81654f1
MS
826
827 return specialcmp (aname+1, bname+1);
828}
829
830/*
831 * Function: selectors_info (regexp, from_tty)
832 *
d2e6263c
MS
833 * Implements the "Info selectors" command. Takes an optional regexp
834 * arg. Lists all objective c selectors that match the regexp. Works
835 * by grepping thru all symbols for objective c methods. Output list
836 * is sorted and uniqued.
b81654f1
MS
837 */
838
839static void
840selectors_info (char *regexp, int from_tty)
841{
842 struct objfile *objfile;
843 struct minimal_symbol *msymbol;
844 char *name;
845 char *val;
846 int matches = 0;
847 int maxlen = 0;
848 int ix;
849 char myregexp[2048];
850 char asel[256];
851 struct symbol **sym_arr;
852 int plusminus = 0;
853
854 if (regexp == NULL)
d2e6263c 855 strcpy(myregexp, ".*]"); /* Null input, match all objc methods. */
b81654f1
MS
856 else
857 {
d2e6263c
MS
858 if (*regexp == '+' || *regexp == '-')
859 { /* User wants only class methods or only instance methods. */
b81654f1
MS
860 plusminus = *regexp++;
861 while (*regexp == ' ' || *regexp == '\t')
862 regexp++;
863 }
864 if (*regexp == '\0')
865 strcpy(myregexp, ".*]");
866 else
867 {
868 strcpy(myregexp, regexp);
869 if (myregexp[strlen(myregexp) - 1] == '$') /* end of selector */
870 myregexp[strlen(myregexp) - 1] = ']'; /* end of method name */
871 else
872 strcat(myregexp, ".*]");
873 }
874 }
875
876 if (regexp != NULL)
5e488a7b
AC
877 {
878 val = re_comp (myregexp);
879 if (val != 0)
8a3fe4f8 880 error (_("Invalid regexp (%s): %s"), val, regexp);
5e488a7b 881 }
b81654f1 882
d2e6263c 883 /* First time thru is JUST to get max length and count. */
b81654f1
MS
884 ALL_MSYMBOLS (objfile, msymbol)
885 {
886 QUIT;
36018d2e 887 name = SYMBOL_NATURAL_NAME (msymbol);
b81654f1
MS
888 if (name &&
889 (name[0] == '-' || name[0] == '+') &&
d2e6263c 890 name[1] == '[') /* Got a method name. */
b81654f1 891 {
d2e6263c 892 /* Filter for class/instance methods. */
b81654f1 893 if (plusminus && name[0] != plusminus)
d2e6263c
MS
894 continue;
895 /* Find selector part. */
896 name = (char *) strchr(name+2, ' ');
b81654f1
MS
897 if (regexp == NULL || re_exec(++name) != 0)
898 {
899 char *mystart = name;
900 char *myend = (char *) strchr(mystart, ']');
901
902 if (myend && (myend - mystart > maxlen))
d2e6263c 903 maxlen = myend - mystart; /* Get longest selector. */
b81654f1
MS
904 matches++;
905 }
906 }
907 }
908 if (matches)
909 {
a3f17187 910 printf_filtered (_("Selectors matching \"%s\":\n\n"),
b81654f1
MS
911 regexp ? regexp : "*");
912
913 sym_arr = alloca (matches * sizeof (struct symbol *));
914 matches = 0;
915 ALL_MSYMBOLS (objfile, msymbol)
916 {
917 QUIT;
36018d2e 918 name = SYMBOL_NATURAL_NAME (msymbol);
b81654f1
MS
919 if (name &&
920 (name[0] == '-' || name[0] == '+') &&
d2e6263c 921 name[1] == '[') /* Got a method name. */
b81654f1 922 {
d2e6263c 923 /* Filter for class/instance methods. */
b81654f1 924 if (plusminus && name[0] != plusminus)
d2e6263c
MS
925 continue;
926 /* Find selector part. */
927 name = (char *) strchr(name+2, ' ');
b81654f1
MS
928 if (regexp == NULL || re_exec(++name) != 0)
929 sym_arr[matches++] = (struct symbol *) msymbol;
930 }
931 }
932
933 qsort (sym_arr, matches, sizeof (struct minimal_symbol *),
934 compare_selectors);
d2e6263c
MS
935 /* Prevent compare on first iteration. */
936 asel[0] = 0;
937 for (ix = 0; ix < matches; ix++) /* Now do the output. */
b81654f1
MS
938 {
939 char *p = asel;
940
941 QUIT;
36018d2e 942 name = SYMBOL_NATURAL_NAME (sym_arr[ix]);
b81654f1
MS
943 name = strchr (name, ' ') + 1;
944 if (p[0] && specialcmp(name, p) == 0)
d2e6263c 945 continue; /* Seen this one already (not unique). */
b81654f1 946
d2e6263c
MS
947 /* Copy selector part. */
948 while (*name && *name != ']')
b81654f1
MS
949 *p++ = *name++;
950 *p++ = '\0';
d2e6263c
MS
951 /* Print in columns. */
952 puts_filtered_tabular(asel, maxlen + 1, 0);
b81654f1
MS
953 }
954 begin_line();
955 }
956 else
a3f17187 957 printf_filtered (_("No selectors matching \"%s\"\n"), regexp ? regexp : "*");
b81654f1
MS
958}
959
960/*
36e53c63 961 * Function: compare_classes (const void *, const void *)
b81654f1 962 *
d2e6263c
MS
963 * Comparison function for use with qsort. Arguments are symbols or
964 * msymbols Compares class part of objc method name alphabetically.
b81654f1
MS
965 */
966
967static int
36e53c63 968compare_classes (const void *a, const void *b)
b81654f1
MS
969{
970 char *aname, *bname;
971
de5ad195
DC
972 aname = SYMBOL_PRINT_NAME (*(struct symbol **) a);
973 bname = SYMBOL_PRINT_NAME (*(struct symbol **) b);
7248f48e 974 if (aname == NULL || bname == NULL)
8a3fe4f8 975 error (_("internal: compare_classes(1)"));
b81654f1
MS
976
977 return specialcmp (aname+1, bname+1);
978}
979
980/*
981 * Function: classes_info(regexp, from_tty)
982 *
983 * Implements the "info classes" command for objective c classes.
984 * Lists all objective c classes that match the optional regexp.
d2e6263c
MS
985 * Works by grepping thru the list of objective c methods. List will
986 * be sorted and uniqued (since one class may have many methods).
987 * BUGS: will not list a class that has no methods.
b81654f1
MS
988 */
989
990static void
991classes_info (char *regexp, int from_tty)
992{
993 struct objfile *objfile;
994 struct minimal_symbol *msymbol;
995 char *name;
996 char *val;
997 int matches = 0;
998 int maxlen = 0;
999 int ix;
1000 char myregexp[2048];
1001 char aclass[256];
1002 struct symbol **sym_arr;
1003
1004 if (regexp == NULL)
d2e6263c 1005 strcpy(myregexp, ".* "); /* Null input: match all objc classes. */
b81654f1
MS
1006 else
1007 {
1008 strcpy(myregexp, regexp);
1009 if (myregexp[strlen(myregexp) - 1] == '$')
d2e6263c 1010 /* In the method name, the end of the class name is marked by ' '. */
b81654f1
MS
1011 myregexp[strlen(myregexp) - 1] = ' ';
1012 else
1013 strcat(myregexp, ".* ");
1014 }
1015
1016 if (regexp != NULL)
5e488a7b
AC
1017 {
1018 val = re_comp (myregexp);
1019 if (val != 0)
8a3fe4f8 1020 error (_("Invalid regexp (%s): %s"), val, regexp);
5e488a7b 1021 }
b81654f1 1022
d2e6263c 1023 /* First time thru is JUST to get max length and count. */
b81654f1
MS
1024 ALL_MSYMBOLS (objfile, msymbol)
1025 {
1026 QUIT;
36018d2e 1027 name = SYMBOL_NATURAL_NAME (msymbol);
b81654f1
MS
1028 if (name &&
1029 (name[0] == '-' || name[0] == '+') &&
d2e6263c 1030 name[1] == '[') /* Got a method name. */
b81654f1
MS
1031 if (regexp == NULL || re_exec(name+2) != 0)
1032 {
d2e6263c
MS
1033 /* Compute length of classname part. */
1034 char *mystart = name + 2;
b81654f1
MS
1035 char *myend = (char *) strchr(mystart, ' ');
1036
1037 if (myend && (myend - mystart > maxlen))
1038 maxlen = myend - mystart;
1039 matches++;
1040 }
1041 }
1042 if (matches)
1043 {
a3f17187 1044 printf_filtered (_("Classes matching \"%s\":\n\n"),
b81654f1
MS
1045 regexp ? regexp : "*");
1046 sym_arr = alloca (matches * sizeof (struct symbol *));
1047 matches = 0;
1048 ALL_MSYMBOLS (objfile, msymbol)
1049 {
1050 QUIT;
36018d2e 1051 name = SYMBOL_NATURAL_NAME (msymbol);
b81654f1
MS
1052 if (name &&
1053 (name[0] == '-' || name[0] == '+') &&
d2e6263c 1054 name[1] == '[') /* Got a method name. */
b81654f1
MS
1055 if (regexp == NULL || re_exec(name+2) != 0)
1056 sym_arr[matches++] = (struct symbol *) msymbol;
1057 }
1058
1059 qsort (sym_arr, matches, sizeof (struct minimal_symbol *),
1060 compare_classes);
d2e6263c
MS
1061 /* Prevent compare on first iteration. */
1062 aclass[0] = 0;
1063 for (ix = 0; ix < matches; ix++) /* Now do the output. */
b81654f1
MS
1064 {
1065 char *p = aclass;
1066
1067 QUIT;
36018d2e 1068 name = SYMBOL_NATURAL_NAME (sym_arr[ix]);
b81654f1
MS
1069 name += 2;
1070 if (p[0] && specialcmp(name, p) == 0)
d2e6263c 1071 continue; /* Seen this one already (not unique). */
b81654f1 1072
d2e6263c
MS
1073 /* Copy class part of method name. */
1074 while (*name && *name != ' ')
b81654f1
MS
1075 *p++ = *name++;
1076 *p++ = '\0';
d2e6263c
MS
1077 /* Print in columns. */
1078 puts_filtered_tabular(aclass, maxlen + 1, 0);
b81654f1
MS
1079 }
1080 begin_line();
1081 }
1082 else
a3f17187 1083 printf_filtered (_("No classes matching \"%s\"\n"), regexp ? regexp : "*");
b81654f1
MS
1084}
1085
1086/*
1087 * Function: find_imps (char *selector, struct symbol **sym_arr)
1088 *
1089 * Input: a string representing a selector
1090 * a pointer to an array of symbol pointers
1091 * possibly a pointer to a symbol found by the caller.
1092 *
d2e6263c
MS
1093 * Output: number of methods that implement that selector. Side
1094 * effects: The array of symbol pointers is filled with matching syms.
b81654f1 1095 *
d2e6263c
MS
1096 * By analogy with function "find_methods" (symtab.c), builds a list
1097 * of symbols matching the ambiguous input, so that "decode_line_2"
1098 * (symtab.c) can list them and ask the user to choose one or more.
1099 * In this case the matches are objective c methods
1100 * ("implementations") matching an objective c selector.
b81654f1 1101 *
d2e6263c
MS
1102 * Note that it is possible for a normal (c-style) function to have
1103 * the same name as an objective c selector. To prevent the selector
1104 * from eclipsing the function, we allow the caller (decode_line_1) to
1105 * search for such a function first, and if it finds one, pass it in
1106 * to us. We will then integrate it into the list. We also search
1107 * for one here, among the minsyms.
b81654f1 1108 *
d2e6263c
MS
1109 * NOTE: if NUM_DEBUGGABLE is non-zero, the sym_arr will be divided
1110 * into two parts: debuggable (struct symbol) syms, and
1111 * non_debuggable (struct minimal_symbol) syms. The debuggable
1112 * ones will come first, before NUM_DEBUGGABLE (which will thus
1113 * be the index of the first non-debuggable one).
b81654f1
MS
1114 */
1115
1116/*
1117 * Function: total_number_of_imps (char *selector);
1118 *
1119 * Input: a string representing a selector
1120 * Output: number of methods that implement that selector.
1121 *
d2e6263c 1122 * By analogy with function "total_number_of_methods", this allows
b81654f1 1123 * decode_line_1 (symtab.c) to detect if there are objective c methods
d2e6263c
MS
1124 * matching the input, and to allocate an array of pointers to them
1125 * which can be manipulated by "decode_line_2" (also in symtab.c).
b81654f1
MS
1126 */
1127
1128char *
1129parse_selector (char *method, char **selector)
1130{
1131 char *s1 = NULL;
1132 char *s2 = NULL;
1133 int found_quote = 0;
1134
1135 char *nselector = NULL;
1136
e8f3fcdd 1137 gdb_assert (selector != NULL);
b81654f1
MS
1138
1139 s1 = method;
1140
1141 while (isspace (*s1))
1142 s1++;
1143 if (*s1 == '\'')
1144 {
1145 found_quote = 1;
1146 s1++;
1147 }
1148 while (isspace (*s1))
1149 s1++;
1150
1151 nselector = s1;
1152 s2 = s1;
1153
1154 for (;;) {
1155 if (isalnum (*s2) || (*s2 == '_') || (*s2 == ':'))
1156 *s1++ = *s2;
1157 else if (isspace (*s2))
1158 ;
1159 else if ((*s2 == '\0') || (*s2 == '\''))
1160 break;
1161 else
1162 return NULL;
1163 s2++;
1164 }
1165 *s1++ = '\0';
1166
1167 while (isspace (*s2))
1168 s2++;
1169 if (found_quote)
1170 {
1171 if (*s2 == '\'')
1172 s2++;
1173 while (isspace (*s2))
1174 s2++;
1175 }
1176
1177 if (selector != NULL)
1178 *selector = nselector;
1179
1180 return s2;
1181}
1182
1183char *
d2e6263c
MS
1184parse_method (char *method, char *type, char **class,
1185 char **category, char **selector)
b81654f1
MS
1186{
1187 char *s1 = NULL;
1188 char *s2 = NULL;
1189 int found_quote = 0;
1190
1191 char ntype = '\0';
1192 char *nclass = NULL;
1193 char *ncategory = NULL;
1194 char *nselector = NULL;
1195
e8f3fcdd
AC
1196 gdb_assert (type != NULL);
1197 gdb_assert (class != NULL);
1198 gdb_assert (category != NULL);
1199 gdb_assert (selector != NULL);
b81654f1
MS
1200
1201 s1 = method;
1202
1203 while (isspace (*s1))
1204 s1++;
1205 if (*s1 == '\'')
1206 {
1207 found_quote = 1;
1208 s1++;
1209 }
1210 while (isspace (*s1))
1211 s1++;
1212
1213 if ((s1[0] == '+') || (s1[0] == '-'))
1214 ntype = *s1++;
1215
1216 while (isspace (*s1))
1217 s1++;
1218
1219 if (*s1 != '[')
1220 return NULL;
1221 s1++;
1222
1223 nclass = s1;
1224 while (isalnum (*s1) || (*s1 == '_'))
1225 s1++;
1226
1227 s2 = s1;
1228 while (isspace (*s2))
1229 s2++;
1230
1231 if (*s2 == '(')
1232 {
1233 s2++;
1234 while (isspace (*s2))
1235 s2++;
1236 ncategory = s2;
1237 while (isalnum (*s2) || (*s2 == '_'))
1238 s2++;
1239 *s2++ = '\0';
1240 }
1241
d2e6263c 1242 /* Truncate the class name now that we're not using the open paren. */
b81654f1
MS
1243 *s1++ = '\0';
1244
1245 nselector = s2;
1246 s1 = s2;
1247
1248 for (;;) {
1249 if (isalnum (*s2) || (*s2 == '_') || (*s2 == ':'))
1250 *s1++ = *s2;
1251 else if (isspace (*s2))
1252 ;
1253 else if (*s2 == ']')
1254 break;
1255 else
1256 return NULL;
1257 s2++;
1258 }
1259 *s1++ = '\0';
1260 s2++;
1261
1262 while (isspace (*s2))
1263 s2++;
1264 if (found_quote)
1265 {
1266 if (*s2 != '\'')
1267 return NULL;
1268 s2++;
1269 while (isspace (*s2))
1270 s2++;
1271 }
1272
1273 if (type != NULL)
1274 *type = ntype;
1275 if (class != NULL)
1276 *class = nclass;
1277 if (category != NULL)
1278 *category = ncategory;
1279 if (selector != NULL)
1280 *selector = nselector;
1281
1282 return s2;
1283}
1284
2f9a90b4 1285static void
d2e6263c
MS
1286find_methods (struct symtab *symtab, char type,
1287 const char *class, const char *category,
1288 const char *selector, struct symbol **syms,
1289 unsigned int *nsym, unsigned int *ndebug)
b81654f1
MS
1290{
1291 struct objfile *objfile = NULL;
1292 struct minimal_symbol *msymbol = NULL;
1293 struct block *block = NULL;
1294 struct symbol *sym = NULL;
1295
1296 char *symname = NULL;
1297
1298 char ntype = '\0';
1299 char *nclass = NULL;
1300 char *ncategory = NULL;
1301 char *nselector = NULL;
1302
1303 unsigned int csym = 0;
1304 unsigned int cdebug = 0;
1305
1306 static char *tmp = NULL;
1307 static unsigned int tmplen = 0;
1308
e8f3fcdd
AC
1309 gdb_assert (nsym != NULL);
1310 gdb_assert (ndebug != NULL);
b81654f1
MS
1311
1312 if (symtab)
1313 block = BLOCKVECTOR_BLOCK (BLOCKVECTOR (symtab), STATIC_BLOCK);
1314
1315 ALL_MSYMBOLS (objfile, msymbol)
1316 {
1317 QUIT;
1318
1319 if ((msymbol->type != mst_text) && (msymbol->type != mst_file_text))
d2e6263c 1320 /* Not a function or method. */
b81654f1
MS
1321 continue;
1322
1323 if (symtab)
8da065d5
DC
1324 if ((SYMBOL_VALUE_ADDRESS (msymbol) < BLOCK_START (block)) ||
1325 (SYMBOL_VALUE_ADDRESS (msymbol) >= BLOCK_END (block)))
d2e6263c 1326 /* Not in the specified symtab. */
b81654f1
MS
1327 continue;
1328
36018d2e 1329 symname = SYMBOL_NATURAL_NAME (msymbol);
b81654f1
MS
1330 if (symname == NULL)
1331 continue;
1332
1333 if ((symname[0] != '-' && symname[0] != '+') || (symname[1] != '['))
d2e6263c 1334 /* Not a method name. */
b81654f1
MS
1335 continue;
1336
1337 while ((strlen (symname) + 1) >= tmplen)
1338 {
1339 tmplen = (tmplen == 0) ? 1024 : tmplen * 2;
1340 tmp = xrealloc (tmp, tmplen);
1341 }
1342 strcpy (tmp, symname);
1343
1344 if (parse_method (tmp, &ntype, &nclass, &ncategory, &nselector) == NULL)
1345 continue;
1346
1347 if ((type != '\0') && (ntype != type))
1348 continue;
1349
d2e6263c
MS
1350 if ((class != NULL)
1351 && ((nclass == NULL) || (strcmp (class, nclass) != 0)))
b81654f1
MS
1352 continue;
1353
d2e6263c
MS
1354 if ((category != NULL) &&
1355 ((ncategory == NULL) || (strcmp (category, ncategory) != 0)))
b81654f1
MS
1356 continue;
1357
d2e6263c
MS
1358 if ((selector != NULL) &&
1359 ((nselector == NULL) || (strcmp (selector, nselector) != 0)))
b81654f1
MS
1360 continue;
1361
1362 sym = find_pc_function (SYMBOL_VALUE_ADDRESS (msymbol));
1363 if (sym != NULL)
1364 {
36018d2e 1365 const char *newsymname = SYMBOL_NATURAL_NAME (sym);
b81654f1 1366
b81654f1
MS
1367 if (strcmp (symname, newsymname) == 0)
1368 {
d2e6263c
MS
1369 /* Found a high-level method sym: swap it into the
1370 lower part of sym_arr (below num_debuggable). */
b81654f1
MS
1371 if (syms != NULL)
1372 {
1373 syms[csym] = syms[cdebug];
1374 syms[cdebug] = sym;
1375 }
1376 csym++;
1377 cdebug++;
1378 }
1379 else
1380 {
d2e6263c
MS
1381 warning (
1382"debugging symbol \"%s\" does not match minimal symbol (\"%s\"); ignoring",
b81654f1
MS
1383 newsymname, symname);
1384 if (syms != NULL)
1385 syms[csym] = (struct symbol *) msymbol;
1386 csym++;
1387 }
1388 }
1389 else
1390 {
d2e6263c 1391 /* Found a non-debuggable method symbol. */
b81654f1
MS
1392 if (syms != NULL)
1393 syms[csym] = (struct symbol *) msymbol;
1394 csym++;
1395 }
1396 }
1397
1398 if (nsym != NULL)
1399 *nsym = csym;
1400 if (ndebug != NULL)
1401 *ndebug = cdebug;
1402}
1403
1404char *find_imps (struct symtab *symtab, struct block *block,
d2e6263c
MS
1405 char *method, struct symbol **syms,
1406 unsigned int *nsym, unsigned int *ndebug)
b81654f1
MS
1407{
1408 char type = '\0';
1409 char *class = NULL;
1410 char *category = NULL;
1411 char *selector = NULL;
1412
1413 unsigned int csym = 0;
1414 unsigned int cdebug = 0;
1415
1416 unsigned int ncsym = 0;
1417 unsigned int ncdebug = 0;
1418
1419 char *buf = NULL;
1420 char *tmp = NULL;
1421
e8f3fcdd
AC
1422 gdb_assert (nsym != NULL);
1423 gdb_assert (ndebug != NULL);
b81654f1
MS
1424
1425 if (nsym != NULL)
1426 *nsym = 0;
1427 if (ndebug != NULL)
1428 *ndebug = 0;
1429
1430 buf = (char *) alloca (strlen (method) + 1);
1431 strcpy (buf, method);
1432 tmp = parse_method (buf, &type, &class, &category, &selector);
1433
1434 if (tmp == NULL) {
1435
b81654f1
MS
1436 struct symbol *sym = NULL;
1437 struct minimal_symbol *msym = NULL;
1438
1439 strcpy (buf, method);
1440 tmp = parse_selector (buf, &selector);
1441
1442 if (tmp == NULL)
1443 return NULL;
1444
cdef89d0 1445 sym = lookup_symbol (selector, block, VAR_DOMAIN, 0, NULL);
b81654f1
MS
1446 if (sym != NULL)
1447 {
1448 if (syms)
1449 syms[csym] = sym;
1450 csym++;
1451 cdebug++;
1452 }
1453
1454 if (sym == NULL)
1455 msym = lookup_minimal_symbol (selector, 0, 0);
1456
1457 if (msym != NULL)
1458 {
1459 if (syms)
36e53c63 1460 syms[csym] = (struct symbol *)msym;
b81654f1
MS
1461 csym++;
1462 }
1463 }
1464
1465 if (syms != NULL)
d2e6263c
MS
1466 find_methods (symtab, type, class, category, selector,
1467 syms + csym, &ncsym, &ncdebug);
b81654f1 1468 else
d2e6263c
MS
1469 find_methods (symtab, type, class, category, selector,
1470 NULL, &ncsym, &ncdebug);
b81654f1 1471
d2e6263c 1472 /* If we didn't find any methods, just return. */
b81654f1
MS
1473 if (ncsym == 0 && ncdebug == 0)
1474 return method;
1475
1476 /* Take debug symbols from the second batch of symbols and swap them
1477 * with debug symbols from the first batch. Repeat until either the
1478 * second section is out of debug symbols or the first section is
1479 * full of debug symbols. Either way we have all debug symbols
d2e6263c
MS
1480 * packed to the beginning of the buffer.
1481 */
b81654f1
MS
1482
1483 if (syms != NULL)
1484 {
1485 while ((cdebug < csym) && (ncdebug > 0))
1486 {
1487 struct symbol *s = NULL;
d2e6263c
MS
1488 /* First non-debugging symbol. */
1489 unsigned int i = cdebug;
1490 /* Last of second batch of debug symbols. */
1491 unsigned int j = csym + ncdebug - 1;
b81654f1
MS
1492
1493 s = syms[j];
1494 syms[j] = syms[i];
1495 syms[i] = s;
1496
d2e6263c
MS
1497 /* We've moved a symbol from the second debug section to the
1498 first one. */
b81654f1
MS
1499 cdebug++;
1500 ncdebug--;
1501 }
1502 }
1503
1504 csym += ncsym;
1505 cdebug += ncdebug;
1506
1507 if (nsym != NULL)
1508 *nsym = csym;
1509 if (ndebug != NULL)
1510 *ndebug = cdebug;
1511
1512 if (syms == NULL)
1513 return method + (tmp - buf);
1514
1515 if (csym > 1)
1516 {
d2e6263c 1517 /* Sort debuggable symbols. */
b81654f1 1518 if (cdebug > 1)
d2e6263c
MS
1519 qsort (syms, cdebug, sizeof (struct minimal_symbol *),
1520 compare_classes);
b81654f1 1521
d2e6263c 1522 /* Sort minimal_symbols. */
b81654f1 1523 if ((csym - cdebug) > 1)
d2e6263c
MS
1524 qsort (&syms[cdebug], csym - cdebug,
1525 sizeof (struct minimal_symbol *), compare_classes);
b81654f1 1526 }
d2e6263c
MS
1527 /* Terminate the sym_arr list. */
1528 syms[csym] = 0;
b81654f1
MS
1529
1530 return method + (tmp - buf);
1531}
1532
b9362cc7 1533static void
b81654f1
MS
1534print_object_command (char *args, int from_tty)
1535{
1536 struct value *object, *function, *description;
36e53c63 1537 CORE_ADDR string_addr, object_addr;
b81654f1 1538 int i = 0;
22a44745 1539 gdb_byte c = 0;
b81654f1
MS
1540
1541 if (!args || !*args)
d2e6263c
MS
1542 error (
1543"The 'print-object' command requires an argument (an Objective-C object)");
b81654f1
MS
1544
1545 {
1546 struct expression *expr = parse_expression (args);
f86f5ca3 1547 struct cleanup *old_chain =
d2e6263c 1548 make_cleanup (free_current_contents, &expr);
b81654f1
MS
1549 int pc = 0;
1550
5f9769d1
PH
1551 object = expr->language_defn->la_exp_desc->evaluate_exp
1552 (builtin_type_void_data_ptr, expr, &pc, EVAL_NORMAL);
b81654f1
MS
1553 do_cleanups (old_chain);
1554 }
1555
36e53c63
AF
1556 /* Validate the address for sanity. */
1557 object_addr = value_as_long (object);
1558 read_memory (object_addr, &c, 1);
1559
7248f48e 1560 function = find_function_in_inferior ("_NSPrintForDebugger");
36e53c63 1561 if (function == NULL)
8a3fe4f8 1562 error (_("Unable to locate _NSPrintForDebugger in child process"));
b81654f1
MS
1563
1564 description = call_function_by_hand (function, 1, &object);
1565
7248f48e
AF
1566 string_addr = value_as_long (description);
1567 if (string_addr == 0)
8a3fe4f8 1568 error (_("object returns null description"));
b81654f1
MS
1569
1570 read_memory (string_addr + i++, &c, 1);
22a44745 1571 if (c != 0)
b81654f1 1572 do
d2e6263c 1573 { /* Read and print characters up to EOS. */
b81654f1
MS
1574 QUIT;
1575 printf_filtered ("%c", c);
1576 read_memory (string_addr + i++, &c, 1);
1577 } while (c != 0);
1578 else
a3f17187 1579 printf_filtered(_("<object returns empty description>"));
b81654f1
MS
1580 printf_filtered ("\n");
1581}
1582
d2e6263c
MS
1583/* The data structure 'methcalls' is used to detect method calls (thru
1584 * ObjC runtime lib functions objc_msgSend, objc_msgSendSuper, etc.),
1585 * and ultimately find the method being called.
b81654f1
MS
1586 */
1587
1588struct objc_methcall {
1589 char *name;
d2e6263c 1590 /* Return instance method to be called. */
36e53c63 1591 int (*stop_at) (CORE_ADDR, CORE_ADDR *);
d2e6263c
MS
1592 /* Start of pc range corresponding to method invocation. */
1593 CORE_ADDR begin;
1594 /* End of pc range corresponding to method invocation. */
1595 CORE_ADDR end;
b81654f1
MS
1596};
1597
d2e6263c
MS
1598static int resolve_msgsend (CORE_ADDR pc, CORE_ADDR *new_pc);
1599static int resolve_msgsend_stret (CORE_ADDR pc, CORE_ADDR *new_pc);
1600static int resolve_msgsend_super (CORE_ADDR pc, CORE_ADDR *new_pc);
1601static int resolve_msgsend_super_stret (CORE_ADDR pc, CORE_ADDR *new_pc);
b81654f1
MS
1602
1603static struct objc_methcall methcalls[] = {
1604 { "_objc_msgSend", resolve_msgsend, 0, 0},
1605 { "_objc_msgSend_stret", resolve_msgsend_stret, 0, 0},
1606 { "_objc_msgSendSuper", resolve_msgsend_super, 0, 0},
1607 { "_objc_msgSendSuper_stret", resolve_msgsend_super_stret, 0, 0},
1608 { "_objc_getClass", NULL, 0, 0},
1609 { "_objc_getMetaClass", NULL, 0, 0}
1610};
1611
1612#define nmethcalls (sizeof (methcalls) / sizeof (methcalls[0]))
1613
d2e6263c
MS
1614/* The following function, "find_objc_msgsend", fills in the data
1615 * structure "objc_msgs" by finding the addresses of each of the
1616 * (currently four) functions that it holds (of which objc_msgSend is
1617 * the first). This must be called each time symbols are loaded, in
1618 * case the functions have moved for some reason.
b81654f1
MS
1619 */
1620
b9362cc7 1621static void
b81654f1
MS
1622find_objc_msgsend (void)
1623{
1624 unsigned int i;
1625 for (i = 0; i < nmethcalls; i++) {
1626
1627 struct minimal_symbol *func;
1628
d2e6263c 1629 /* Try both with and without underscore. */
b81654f1
MS
1630 func = lookup_minimal_symbol (methcalls[i].name, NULL, NULL);
1631 if ((func == NULL) && (methcalls[i].name[0] == '_')) {
1632 func = lookup_minimal_symbol (methcalls[i].name + 1, NULL, NULL);
1633 }
1634 if (func == NULL) {
1635 methcalls[i].begin = 0;
1636 methcalls[i].end = 0;
1637 continue;
1638 }
1639
1640 methcalls[i].begin = SYMBOL_VALUE_ADDRESS (func);
1641 do {
1642 methcalls[i].end = SYMBOL_VALUE_ADDRESS (++func);
1643 } while (methcalls[i].begin == methcalls[i].end);
1644 }
1645}
1646
1647/* find_objc_msgcall (replaces pc_off_limits)
1648 *
d2e6263c
MS
1649 * ALL that this function now does is to determine whether the input
1650 * address ("pc") is the address of one of the Objective-C message
b81654f1
MS
1651 * dispatch functions (mainly objc_msgSend or objc_msgSendSuper), and
1652 * if so, it returns the address of the method that will be called.
1653 *
1654 * The old function "pc_off_limits" used to do a lot of other things
d2e6263c 1655 * in addition, such as detecting shared library jump stubs and
b81654f1 1656 * returning the address of the shlib function that would be called.
e76f05fa 1657 * That functionality has been moved into the gdbarch_skip_trampoline_code and
d2e6263c
MS
1658 * IN_SOLIB_TRAMPOLINE macros, which are resolved in the target-
1659 * dependent modules.
b81654f1
MS
1660 */
1661
1662struct objc_submethod_helper_data {
36e53c63 1663 int (*f) (CORE_ADDR, CORE_ADDR *);
b81654f1
MS
1664 CORE_ADDR pc;
1665 CORE_ADDR *new_pc;
1666};
1667
b9362cc7 1668static int
7248f48e 1669find_objc_msgcall_submethod_helper (void * arg)
b81654f1 1670{
d2e6263c
MS
1671 struct objc_submethod_helper_data *s =
1672 (struct objc_submethod_helper_data *) arg;
1673
1674 if (s->f (s->pc, s->new_pc) == 0)
b81654f1 1675 return 1;
d2e6263c 1676 else
b81654f1 1677 return 0;
b81654f1
MS
1678}
1679
b9362cc7 1680static int
36e53c63 1681find_objc_msgcall_submethod (int (*f) (CORE_ADDR, CORE_ADDR *),
d2e6263c
MS
1682 CORE_ADDR pc,
1683 CORE_ADDR *new_pc)
b81654f1
MS
1684{
1685 struct objc_submethod_helper_data s;
1686
1687 s.f = f;
1688 s.pc = pc;
1689 s.new_pc = new_pc;
1690
1691 if (catch_errors (find_objc_msgcall_submethod_helper,
7248f48e 1692 (void *) &s,
d2e6263c
MS
1693 "Unable to determine target of Objective-C method call (ignoring):\n",
1694 RETURN_MASK_ALL) == 0)
b81654f1 1695 return 1;
d2e6263c 1696 else
b81654f1 1697 return 0;
b81654f1
MS
1698}
1699
1700int
1701find_objc_msgcall (CORE_ADDR pc, CORE_ADDR *new_pc)
1702{
1703 unsigned int i;
1704
1705 find_objc_msgsend ();
5e488a7b
AC
1706 if (new_pc != NULL)
1707 {
1708 *new_pc = 0;
1709 }
b81654f1 1710
d2e6263c
MS
1711 for (i = 0; i < nmethcalls; i++)
1712 if ((pc >= methcalls[i].begin) && (pc < methcalls[i].end))
1713 {
1714 if (methcalls[i].stop_at != NULL)
1715 return find_objc_msgcall_submethod (methcalls[i].stop_at,
1716 pc, new_pc);
1717 else
1718 return 0;
b81654f1 1719 }
d2e6263c 1720
b81654f1
MS
1721 return 0;
1722}
1723
a78f21af 1724extern initialize_file_ftype _initialize_objc_language; /* -Wmissing-prototypes */
b9362cc7 1725
b81654f1
MS
1726void
1727_initialize_objc_language (void)
1728{
1729 add_language (&objc_language_defn);
d2e6263c 1730 add_info ("selectors", selectors_info, /* INFO SELECTORS command. */
1bedd215 1731 _("All Objective-C selectors, or those matching REGEXP."));
d2e6263c 1732 add_info ("classes", classes_info, /* INFO CLASSES command. */
1bedd215 1733 _("All Objective-C classes, or those matching REGEXP."));
b81654f1 1734 add_com ("print-object", class_vars, print_object_command,
1bedd215 1735 _("Ask an Objective-C object to print itself."));
b81654f1
MS
1736 add_com_alias ("po", "print-object", class_vars, 1);
1737}
1738
b81654f1
MS
1739static void
1740read_objc_method (CORE_ADDR addr, struct objc_method *method)
1741{
d2e6263c 1742 method->name = read_memory_unsigned_integer (addr + 0, 4);
b81654f1 1743 method->types = read_memory_unsigned_integer (addr + 4, 4);
d2e6263c 1744 method->imp = read_memory_unsigned_integer (addr + 8, 4);
b81654f1
MS
1745}
1746
1747static
1748unsigned long read_objc_methlist_nmethods (CORE_ADDR addr)
1749{
1750 return read_memory_unsigned_integer (addr + 4, 4);
1751}
1752
1753static void
1754read_objc_methlist_method (CORE_ADDR addr, unsigned long num,
1755 struct objc_method *method)
1756{
e8f3fcdd 1757 gdb_assert (num < read_objc_methlist_nmethods (addr));
b81654f1
MS
1758 read_objc_method (addr + 8 + (12 * num), method);
1759}
1760
1761static void
1762read_objc_object (CORE_ADDR addr, struct objc_object *object)
1763{
1764 object->isa = read_memory_unsigned_integer (addr, 4);
1765}
1766
1767static void
1768read_objc_super (CORE_ADDR addr, struct objc_super *super)
1769{
1770 super->receiver = read_memory_unsigned_integer (addr, 4);
1771 super->class = read_memory_unsigned_integer (addr + 4, 4);
1772};
1773
1774static void
1775read_objc_class (CORE_ADDR addr, struct objc_class *class)
1776{
1777 class->isa = read_memory_unsigned_integer (addr, 4);
1778 class->super_class = read_memory_unsigned_integer (addr + 4, 4);
1779 class->name = read_memory_unsigned_integer (addr + 8, 4);
1780 class->version = read_memory_unsigned_integer (addr + 12, 4);
1781 class->info = read_memory_unsigned_integer (addr + 16, 4);
1782 class->instance_size = read_memory_unsigned_integer (addr + 18, 4);
1783 class->ivars = read_memory_unsigned_integer (addr + 24, 4);
1784 class->methods = read_memory_unsigned_integer (addr + 28, 4);
1785 class->cache = read_memory_unsigned_integer (addr + 32, 4);
1786 class->protocols = read_memory_unsigned_integer (addr + 36, 4);
1787}
1788
b9362cc7 1789static CORE_ADDR
b81654f1
MS
1790find_implementation_from_class (CORE_ADDR class, CORE_ADDR sel)
1791{
1792 CORE_ADDR subclass = class;
1793
d2e6263c
MS
1794 while (subclass != 0)
1795 {
b81654f1 1796
d2e6263c
MS
1797 struct objc_class class_str;
1798 unsigned mlistnum = 0;
b81654f1 1799
d2e6263c 1800 read_objc_class (subclass, &class_str);
b81654f1 1801
d2e6263c
MS
1802 for (;;)
1803 {
1804 CORE_ADDR mlist;
1805 unsigned long nmethods;
1806 unsigned long i;
b81654f1 1807
d2e6263c
MS
1808 mlist = read_memory_unsigned_integer (class_str.methods +
1809 (4 * mlistnum), 4);
1810 if (mlist == 0)
1811 break;
b81654f1 1812
d2e6263c 1813 nmethods = read_objc_methlist_nmethods (mlist);
b81654f1 1814
d2e6263c
MS
1815 for (i = 0; i < nmethods; i++)
1816 {
1817 struct objc_method meth_str;
1818 read_objc_methlist_method (mlist, i, &meth_str);
b81654f1
MS
1819
1820#if 0
d2e6263c
MS
1821 fprintf (stderr,
1822 "checking method 0x%lx against selector 0x%lx\n",
1823 meth_str.name, sel);
b81654f1
MS
1824#endif
1825
d2e6263c 1826 if (meth_str.name == sel)
1abf022c
AF
1827 /* FIXME: hppa arch was doing a pointer dereference
1828 here. There needs to be a better way to do that. */
1829 return meth_str.imp;
d2e6263c
MS
1830 }
1831 mlistnum++;
b81654f1 1832 }
d2e6263c 1833 subclass = class_str.super_class;
b81654f1 1834 }
b81654f1
MS
1835
1836 return 0;
1837}
1838
b9362cc7 1839static CORE_ADDR
b81654f1
MS
1840find_implementation (CORE_ADDR object, CORE_ADDR sel)
1841{
1842 struct objc_object ostr;
1843
d2e6263c
MS
1844 if (object == 0)
1845 return 0;
b81654f1 1846 read_objc_object (object, &ostr);
d2e6263c
MS
1847 if (ostr.isa == 0)
1848 return 0;
b81654f1
MS
1849
1850 return find_implementation_from_class (ostr.isa, sel);
1851}
1852
a0273b2f 1853#define OBJC_FETCH_POINTER_ARGUMENT(argi) \
d99344c0
UW
1854 gdbarch_fetch_pointer_argument (current_gdbarch, get_current_frame (), \
1855 argi, builtin_type_void_func_ptr)
a0273b2f 1856
b81654f1
MS
1857static int
1858resolve_msgsend (CORE_ADDR pc, CORE_ADDR *new_pc)
1859{
1860 CORE_ADDR object;
1861 CORE_ADDR sel;
1862 CORE_ADDR res;
1863
a0273b2f
AF
1864 object = OBJC_FETCH_POINTER_ARGUMENT (0);
1865 sel = OBJC_FETCH_POINTER_ARGUMENT (1);
b81654f1
MS
1866
1867 res = find_implementation (object, sel);
d2e6263c
MS
1868 if (new_pc != 0)
1869 *new_pc = res;
1870 if (res == 0)
1871 return 1;
b81654f1
MS
1872 return 0;
1873}
1874
1875static int
1876resolve_msgsend_stret (CORE_ADDR pc, CORE_ADDR *new_pc)
1877{
1878 CORE_ADDR object;
1879 CORE_ADDR sel;
1880 CORE_ADDR res;
1881
a0273b2f
AF
1882 object = OBJC_FETCH_POINTER_ARGUMENT (1);
1883 sel = OBJC_FETCH_POINTER_ARGUMENT (2);
b81654f1
MS
1884
1885 res = find_implementation (object, sel);
d2e6263c
MS
1886 if (new_pc != 0)
1887 *new_pc = res;
1888 if (res == 0)
1889 return 1;
b81654f1
MS
1890 return 0;
1891}
1892
1893static int
1894resolve_msgsend_super (CORE_ADDR pc, CORE_ADDR *new_pc)
1895{
1896 struct objc_super sstr;
1897
1898 CORE_ADDR super;
1899 CORE_ADDR sel;
1900 CORE_ADDR res;
1901
a0273b2f
AF
1902 super = OBJC_FETCH_POINTER_ARGUMENT (0);
1903 sel = OBJC_FETCH_POINTER_ARGUMENT (1);
b81654f1
MS
1904
1905 read_objc_super (super, &sstr);
d2e6263c
MS
1906 if (sstr.class == 0)
1907 return 0;
b81654f1
MS
1908
1909 res = find_implementation_from_class (sstr.class, sel);
d2e6263c
MS
1910 if (new_pc != 0)
1911 *new_pc = res;
1912 if (res == 0)
1913 return 1;
b81654f1
MS
1914 return 0;
1915}
1916
1917static int
1918resolve_msgsend_super_stret (CORE_ADDR pc, CORE_ADDR *new_pc)
1919{
1920 struct objc_super sstr;
1921
1922 CORE_ADDR super;
1923 CORE_ADDR sel;
1924 CORE_ADDR res;
1925
a0273b2f
AF
1926 super = OBJC_FETCH_POINTER_ARGUMENT (1);
1927 sel = OBJC_FETCH_POINTER_ARGUMENT (2);
b81654f1
MS
1928
1929 read_objc_super (super, &sstr);
d2e6263c
MS
1930 if (sstr.class == 0)
1931 return 0;
b81654f1
MS
1932
1933 res = find_implementation_from_class (sstr.class, sel);
d2e6263c
MS
1934 if (new_pc != 0)
1935 *new_pc = res;
1936 if (res == 0)
1937 return 1;
b81654f1
MS
1938 return 0;
1939}
This page took 0.488943 seconds and 4 git commands to generate.