* gdbarch.sh (software_single_step): Replace REGCACHE argument by
[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
579objc_skip_trampoline (CORE_ADDR stop_pc)
580{
581 CORE_ADDR real_stop_pc;
582 CORE_ADDR method_stop_pc;
583
e76f05fa 584 real_stop_pc = gdbarch_skip_trampoline_code (current_gdbarch, stop_pc);
f636b87d
AF
585
586 if (real_stop_pc != 0)
587 find_objc_msgcall (real_stop_pc, &method_stop_pc);
588 else
589 find_objc_msgcall (stop_pc, &method_stop_pc);
590
591 if (method_stop_pc)
592 {
e76f05fa
UW
593 real_stop_pc = gdbarch_skip_trampoline_code
594 (current_gdbarch, method_stop_pc);
f636b87d
AF
595 if (real_stop_pc == 0)
596 real_stop_pc = method_stop_pc;
597 }
598
599 return real_stop_pc;
600}
601
b81654f1
MS
602
603/* Table mapping opcodes into strings for printing operators
604 and precedences of the operators. */
605
606static const struct op_print objc_op_print_tab[] =
607 {
608 {",", BINOP_COMMA, PREC_COMMA, 0},
609 {"=", BINOP_ASSIGN, PREC_ASSIGN, 1},
610 {"||", BINOP_LOGICAL_OR, PREC_LOGICAL_OR, 0},
611 {"&&", BINOP_LOGICAL_AND, PREC_LOGICAL_AND, 0},
612 {"|", BINOP_BITWISE_IOR, PREC_BITWISE_IOR, 0},
613 {"^", BINOP_BITWISE_XOR, PREC_BITWISE_XOR, 0},
614 {"&", BINOP_BITWISE_AND, PREC_BITWISE_AND, 0},
615 {"==", BINOP_EQUAL, PREC_EQUAL, 0},
616 {"!=", BINOP_NOTEQUAL, PREC_EQUAL, 0},
617 {"<=", BINOP_LEQ, PREC_ORDER, 0},
618 {">=", BINOP_GEQ, PREC_ORDER, 0},
619 {">", BINOP_GTR, PREC_ORDER, 0},
620 {"<", BINOP_LESS, PREC_ORDER, 0},
621 {">>", BINOP_RSH, PREC_SHIFT, 0},
622 {"<<", BINOP_LSH, PREC_SHIFT, 0},
623 {"+", BINOP_ADD, PREC_ADD, 0},
624 {"-", BINOP_SUB, PREC_ADD, 0},
625 {"*", BINOP_MUL, PREC_MUL, 0},
626 {"/", BINOP_DIV, PREC_MUL, 0},
627 {"%", BINOP_REM, PREC_MUL, 0},
628 {"@", BINOP_REPEAT, PREC_REPEAT, 0},
629 {"-", UNOP_NEG, PREC_PREFIX, 0},
630 {"!", UNOP_LOGICAL_NOT, PREC_PREFIX, 0},
631 {"~", UNOP_COMPLEMENT, PREC_PREFIX, 0},
632 {"*", UNOP_IND, PREC_PREFIX, 0},
633 {"&", UNOP_ADDR, PREC_PREFIX, 0},
634 {"sizeof ", UNOP_SIZEOF, PREC_PREFIX, 0},
635 {"++", UNOP_PREINCREMENT, PREC_PREFIX, 0},
636 {"--", UNOP_PREDECREMENT, PREC_PREFIX, 0},
e8f3fcdd 637 {NULL, OP_NULL, PREC_NULL, 0}
b81654f1
MS
638};
639
640struct type ** const (objc_builtin_types[]) =
641{
642 &builtin_type_int,
643 &builtin_type_long,
644 &builtin_type_short,
645 &builtin_type_char,
646 &builtin_type_float,
647 &builtin_type_double,
648 &builtin_type_void,
649 &builtin_type_long_long,
650 &builtin_type_signed_char,
651 &builtin_type_unsigned_char,
652 &builtin_type_unsigned_short,
653 &builtin_type_unsigned_int,
654 &builtin_type_unsigned_long,
655 &builtin_type_unsigned_long_long,
656 &builtin_type_long_double,
657 &builtin_type_complex,
658 &builtin_type_double_complex,
659 0
660};
661
662const struct language_defn objc_language_defn = {
d2e6263c 663 "objective-c", /* Language name */
b81654f1
MS
664 language_objc,
665 objc_builtin_types,
666 range_check_off,
667 type_check_off,
668 case_sensitive_on,
7ca2d3a3 669 array_row_major,
5f9769d1 670 &exp_descriptor_standard,
b81654f1
MS
671 objc_parse,
672 objc_error,
e85c3284 673 null_post_parser,
b81654f1
MS
674 objc_printchar, /* Print a character constant */
675 objc_printstr, /* Function to print string constant */
676 objc_emit_char,
677 objc_create_fundamental_type, /* Create fundamental type in this language */
678 c_print_type, /* Print a type using appropriate syntax */
679 c_val_print, /* Print a value using appropriate syntax */
680 c_value_print, /* Print a top-level value */
f636b87d 681 objc_skip_trampoline, /* Language specific skip_trampoline */
5f9a71c3
DC
682 value_of_this, /* value_of_this */
683 basic_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */
b368761e 684 basic_lookup_transparent_type,/* lookup_transparent_type */
9a3d7dfd 685 objc_demangle, /* Language specific symbol demangler */
31c27f77 686 NULL, /* Language specific class_name_from_physname */
d2e6263c
MS
687 objc_op_print_tab, /* Expression operators for printing */
688 1, /* C-style arrays */
b81654f1
MS
689 0, /* String lower bound */
690 &builtin_type_char, /* Type of string elements */
6084f43a 691 default_word_break_characters,
f290d38e 692 NULL, /* FIXME: la_language_arch_info. */
e79af960 693 default_print_array_index,
b81654f1
MS
694 LANG_MAGIC
695};
696
697/*
698 * ObjC:
d2e6263c 699 * Following functions help construct Objective-C message calls
b81654f1
MS
700 */
701
d2e6263c 702struct selname /* For parsing Objective-C. */
b81654f1
MS
703 {
704 struct selname *next;
705 char *msglist_sel;
706 int msglist_len;
707 };
708
709static int msglist_len;
710static struct selname *selname_chain;
711static char *msglist_sel;
712
713void
714start_msglist(void)
715{
f86f5ca3 716 struct selname *new =
b81654f1
MS
717 (struct selname *) xmalloc (sizeof (struct selname));
718
719 new->next = selname_chain;
720 new->msglist_len = msglist_len;
721 new->msglist_sel = msglist_sel;
722 msglist_len = 0;
723 msglist_sel = (char *)xmalloc(1);
724 *msglist_sel = 0;
725 selname_chain = new;
726}
727
728void
729add_msglist(struct stoken *str, int addcolon)
730{
731 char *s, *p;
732 int len, plen;
733
d2e6263c
MS
734 if (str == 0) { /* Unnamed arg, or... */
735 if (addcolon == 0) { /* variable number of args. */
b81654f1
MS
736 msglist_len++;
737 return;
738 }
739 p = "";
740 plen = 0;
741 } else {
742 p = str->ptr;
743 plen = str->length;
744 }
745 len = plen + strlen(msglist_sel) + 2;
746 s = (char *)xmalloc(len);
747 strcpy(s, msglist_sel);
748 strncat(s, p, plen);
7248f48e 749 xfree(msglist_sel);
b81654f1
MS
750 msglist_sel = s;
751 if (addcolon) {
752 s[len-2] = ':';
753 s[len-1] = 0;
754 msglist_len++;
755 } else
756 s[len-2] = '\0';
757}
758
759int
760end_msglist(void)
761{
f86f5ca3
PH
762 int val = msglist_len;
763 struct selname *sel = selname_chain;
764 char *p = msglist_sel;
c253954e 765 CORE_ADDR selid;
b81654f1
MS
766
767 selname_chain = sel->next;
768 msglist_len = sel->msglist_len;
769 msglist_sel = sel->msglist_sel;
770 selid = lookup_child_selector(p);
771 if (!selid)
8a3fe4f8 772 error (_("Can't find selector \"%s\""), p);
b81654f1 773 write_exp_elt_longcst (selid);
7248f48e 774 xfree(p);
d2e6263c 775 write_exp_elt_longcst (val); /* Number of args */
7248f48e 776 xfree(sel);
b81654f1
MS
777
778 return val;
779}
780
781/*
782 * Function: specialcmp (char *a, char *b)
783 *
784 * Special strcmp: treats ']' and ' ' as end-of-string.
d2e6263c 785 * Used for qsorting lists of objc methods (either by class or selector).
b81654f1
MS
786 */
787
b9362cc7
AC
788static int
789specialcmp (char *a, char *b)
b81654f1
MS
790{
791 while (*a && *a != ' ' && *a != ']' && *b && *b != ' ' && *b != ']')
792 {
793 if (*a != *b)
794 return *a - *b;
795 a++, b++;
796 }
797 if (*a && *a != ' ' && *a != ']')
798 return 1; /* a is longer therefore greater */
799 if (*b && *b != ' ' && *b != ']')
800 return -1; /* a is shorter therefore lesser */
801 return 0; /* a and b are identical */
802}
803
804/*
36e53c63 805 * Function: compare_selectors (const void *, const void *)
b81654f1 806 *
d2e6263c
MS
807 * Comparison function for use with qsort. Arguments are symbols or
808 * msymbols Compares selector part of objc method name alphabetically.
b81654f1
MS
809 */
810
811static int
36e53c63 812compare_selectors (const void *a, const void *b)
b81654f1
MS
813{
814 char *aname, *bname;
815
de5ad195
DC
816 aname = SYMBOL_PRINT_NAME (*(struct symbol **) a);
817 bname = SYMBOL_PRINT_NAME (*(struct symbol **) b);
7248f48e 818 if (aname == NULL || bname == NULL)
8a3fe4f8 819 error (_("internal: compare_selectors(1)"));
b81654f1 820
7248f48e
AF
821 aname = strchr(aname, ' ');
822 bname = strchr(bname, ' ');
823 if (aname == NULL || bname == NULL)
8a3fe4f8 824 error (_("internal: compare_selectors(2)"));
b81654f1
MS
825
826 return specialcmp (aname+1, bname+1);
827}
828
829/*
830 * Function: selectors_info (regexp, from_tty)
831 *
d2e6263c
MS
832 * Implements the "Info selectors" command. Takes an optional regexp
833 * arg. Lists all objective c selectors that match the regexp. Works
834 * by grepping thru all symbols for objective c methods. Output list
835 * is sorted and uniqued.
b81654f1
MS
836 */
837
838static void
839selectors_info (char *regexp, int from_tty)
840{
841 struct objfile *objfile;
842 struct minimal_symbol *msymbol;
843 char *name;
844 char *val;
845 int matches = 0;
846 int maxlen = 0;
847 int ix;
848 char myregexp[2048];
849 char asel[256];
850 struct symbol **sym_arr;
851 int plusminus = 0;
852
853 if (regexp == NULL)
d2e6263c 854 strcpy(myregexp, ".*]"); /* Null input, match all objc methods. */
b81654f1
MS
855 else
856 {
d2e6263c
MS
857 if (*regexp == '+' || *regexp == '-')
858 { /* User wants only class methods or only instance methods. */
b81654f1
MS
859 plusminus = *regexp++;
860 while (*regexp == ' ' || *regexp == '\t')
861 regexp++;
862 }
863 if (*regexp == '\0')
864 strcpy(myregexp, ".*]");
865 else
866 {
867 strcpy(myregexp, regexp);
868 if (myregexp[strlen(myregexp) - 1] == '$') /* end of selector */
869 myregexp[strlen(myregexp) - 1] = ']'; /* end of method name */
870 else
871 strcat(myregexp, ".*]");
872 }
873 }
874
875 if (regexp != NULL)
5e488a7b
AC
876 {
877 val = re_comp (myregexp);
878 if (val != 0)
8a3fe4f8 879 error (_("Invalid regexp (%s): %s"), val, regexp);
5e488a7b 880 }
b81654f1 881
d2e6263c 882 /* First time thru is JUST to get max length and count. */
b81654f1
MS
883 ALL_MSYMBOLS (objfile, msymbol)
884 {
885 QUIT;
36018d2e 886 name = SYMBOL_NATURAL_NAME (msymbol);
b81654f1
MS
887 if (name &&
888 (name[0] == '-' || name[0] == '+') &&
d2e6263c 889 name[1] == '[') /* Got a method name. */
b81654f1 890 {
d2e6263c 891 /* Filter for class/instance methods. */
b81654f1 892 if (plusminus && name[0] != plusminus)
d2e6263c
MS
893 continue;
894 /* Find selector part. */
895 name = (char *) strchr(name+2, ' ');
b81654f1
MS
896 if (regexp == NULL || re_exec(++name) != 0)
897 {
898 char *mystart = name;
899 char *myend = (char *) strchr(mystart, ']');
900
901 if (myend && (myend - mystart > maxlen))
d2e6263c 902 maxlen = myend - mystart; /* Get longest selector. */
b81654f1
MS
903 matches++;
904 }
905 }
906 }
907 if (matches)
908 {
a3f17187 909 printf_filtered (_("Selectors matching \"%s\":\n\n"),
b81654f1
MS
910 regexp ? regexp : "*");
911
912 sym_arr = alloca (matches * sizeof (struct symbol *));
913 matches = 0;
914 ALL_MSYMBOLS (objfile, msymbol)
915 {
916 QUIT;
36018d2e 917 name = SYMBOL_NATURAL_NAME (msymbol);
b81654f1
MS
918 if (name &&
919 (name[0] == '-' || name[0] == '+') &&
d2e6263c 920 name[1] == '[') /* Got a method name. */
b81654f1 921 {
d2e6263c 922 /* Filter for class/instance methods. */
b81654f1 923 if (plusminus && name[0] != plusminus)
d2e6263c
MS
924 continue;
925 /* Find selector part. */
926 name = (char *) strchr(name+2, ' ');
b81654f1
MS
927 if (regexp == NULL || re_exec(++name) != 0)
928 sym_arr[matches++] = (struct symbol *) msymbol;
929 }
930 }
931
932 qsort (sym_arr, matches, sizeof (struct minimal_symbol *),
933 compare_selectors);
d2e6263c
MS
934 /* Prevent compare on first iteration. */
935 asel[0] = 0;
936 for (ix = 0; ix < matches; ix++) /* Now do the output. */
b81654f1
MS
937 {
938 char *p = asel;
939
940 QUIT;
36018d2e 941 name = SYMBOL_NATURAL_NAME (sym_arr[ix]);
b81654f1
MS
942 name = strchr (name, ' ') + 1;
943 if (p[0] && specialcmp(name, p) == 0)
d2e6263c 944 continue; /* Seen this one already (not unique). */
b81654f1 945
d2e6263c
MS
946 /* Copy selector part. */
947 while (*name && *name != ']')
b81654f1
MS
948 *p++ = *name++;
949 *p++ = '\0';
d2e6263c
MS
950 /* Print in columns. */
951 puts_filtered_tabular(asel, maxlen + 1, 0);
b81654f1
MS
952 }
953 begin_line();
954 }
955 else
a3f17187 956 printf_filtered (_("No selectors matching \"%s\"\n"), regexp ? regexp : "*");
b81654f1
MS
957}
958
959/*
36e53c63 960 * Function: compare_classes (const void *, const void *)
b81654f1 961 *
d2e6263c
MS
962 * Comparison function for use with qsort. Arguments are symbols or
963 * msymbols Compares class part of objc method name alphabetically.
b81654f1
MS
964 */
965
966static int
36e53c63 967compare_classes (const void *a, const void *b)
b81654f1
MS
968{
969 char *aname, *bname;
970
de5ad195
DC
971 aname = SYMBOL_PRINT_NAME (*(struct symbol **) a);
972 bname = SYMBOL_PRINT_NAME (*(struct symbol **) b);
7248f48e 973 if (aname == NULL || bname == NULL)
8a3fe4f8 974 error (_("internal: compare_classes(1)"));
b81654f1
MS
975
976 return specialcmp (aname+1, bname+1);
977}
978
979/*
980 * Function: classes_info(regexp, from_tty)
981 *
982 * Implements the "info classes" command for objective c classes.
983 * Lists all objective c classes that match the optional regexp.
d2e6263c
MS
984 * Works by grepping thru the list of objective c methods. List will
985 * be sorted and uniqued (since one class may have many methods).
986 * BUGS: will not list a class that has no methods.
b81654f1
MS
987 */
988
989static void
990classes_info (char *regexp, int from_tty)
991{
992 struct objfile *objfile;
993 struct minimal_symbol *msymbol;
994 char *name;
995 char *val;
996 int matches = 0;
997 int maxlen = 0;
998 int ix;
999 char myregexp[2048];
1000 char aclass[256];
1001 struct symbol **sym_arr;
1002
1003 if (regexp == NULL)
d2e6263c 1004 strcpy(myregexp, ".* "); /* Null input: match all objc classes. */
b81654f1
MS
1005 else
1006 {
1007 strcpy(myregexp, regexp);
1008 if (myregexp[strlen(myregexp) - 1] == '$')
d2e6263c 1009 /* In the method name, the end of the class name is marked by ' '. */
b81654f1
MS
1010 myregexp[strlen(myregexp) - 1] = ' ';
1011 else
1012 strcat(myregexp, ".* ");
1013 }
1014
1015 if (regexp != NULL)
5e488a7b
AC
1016 {
1017 val = re_comp (myregexp);
1018 if (val != 0)
8a3fe4f8 1019 error (_("Invalid regexp (%s): %s"), val, regexp);
5e488a7b 1020 }
b81654f1 1021
d2e6263c 1022 /* First time thru is JUST to get max length and count. */
b81654f1
MS
1023 ALL_MSYMBOLS (objfile, msymbol)
1024 {
1025 QUIT;
36018d2e 1026 name = SYMBOL_NATURAL_NAME (msymbol);
b81654f1
MS
1027 if (name &&
1028 (name[0] == '-' || name[0] == '+') &&
d2e6263c 1029 name[1] == '[') /* Got a method name. */
b81654f1
MS
1030 if (regexp == NULL || re_exec(name+2) != 0)
1031 {
d2e6263c
MS
1032 /* Compute length of classname part. */
1033 char *mystart = name + 2;
b81654f1
MS
1034 char *myend = (char *) strchr(mystart, ' ');
1035
1036 if (myend && (myend - mystart > maxlen))
1037 maxlen = myend - mystart;
1038 matches++;
1039 }
1040 }
1041 if (matches)
1042 {
a3f17187 1043 printf_filtered (_("Classes matching \"%s\":\n\n"),
b81654f1
MS
1044 regexp ? regexp : "*");
1045 sym_arr = alloca (matches * sizeof (struct symbol *));
1046 matches = 0;
1047 ALL_MSYMBOLS (objfile, msymbol)
1048 {
1049 QUIT;
36018d2e 1050 name = SYMBOL_NATURAL_NAME (msymbol);
b81654f1
MS
1051 if (name &&
1052 (name[0] == '-' || name[0] == '+') &&
d2e6263c 1053 name[1] == '[') /* Got a method name. */
b81654f1
MS
1054 if (regexp == NULL || re_exec(name+2) != 0)
1055 sym_arr[matches++] = (struct symbol *) msymbol;
1056 }
1057
1058 qsort (sym_arr, matches, sizeof (struct minimal_symbol *),
1059 compare_classes);
d2e6263c
MS
1060 /* Prevent compare on first iteration. */
1061 aclass[0] = 0;
1062 for (ix = 0; ix < matches; ix++) /* Now do the output. */
b81654f1
MS
1063 {
1064 char *p = aclass;
1065
1066 QUIT;
36018d2e 1067 name = SYMBOL_NATURAL_NAME (sym_arr[ix]);
b81654f1
MS
1068 name += 2;
1069 if (p[0] && specialcmp(name, p) == 0)
d2e6263c 1070 continue; /* Seen this one already (not unique). */
b81654f1 1071
d2e6263c
MS
1072 /* Copy class part of method name. */
1073 while (*name && *name != ' ')
b81654f1
MS
1074 *p++ = *name++;
1075 *p++ = '\0';
d2e6263c
MS
1076 /* Print in columns. */
1077 puts_filtered_tabular(aclass, maxlen + 1, 0);
b81654f1
MS
1078 }
1079 begin_line();
1080 }
1081 else
a3f17187 1082 printf_filtered (_("No classes matching \"%s\"\n"), regexp ? regexp : "*");
b81654f1
MS
1083}
1084
1085/*
1086 * Function: find_imps (char *selector, struct symbol **sym_arr)
1087 *
1088 * Input: a string representing a selector
1089 * a pointer to an array of symbol pointers
1090 * possibly a pointer to a symbol found by the caller.
1091 *
d2e6263c
MS
1092 * Output: number of methods that implement that selector. Side
1093 * effects: The array of symbol pointers is filled with matching syms.
b81654f1 1094 *
d2e6263c
MS
1095 * By analogy with function "find_methods" (symtab.c), builds a list
1096 * of symbols matching the ambiguous input, so that "decode_line_2"
1097 * (symtab.c) can list them and ask the user to choose one or more.
1098 * In this case the matches are objective c methods
1099 * ("implementations") matching an objective c selector.
b81654f1 1100 *
d2e6263c
MS
1101 * Note that it is possible for a normal (c-style) function to have
1102 * the same name as an objective c selector. To prevent the selector
1103 * from eclipsing the function, we allow the caller (decode_line_1) to
1104 * search for such a function first, and if it finds one, pass it in
1105 * to us. We will then integrate it into the list. We also search
1106 * for one here, among the minsyms.
b81654f1 1107 *
d2e6263c
MS
1108 * NOTE: if NUM_DEBUGGABLE is non-zero, the sym_arr will be divided
1109 * into two parts: debuggable (struct symbol) syms, and
1110 * non_debuggable (struct minimal_symbol) syms. The debuggable
1111 * ones will come first, before NUM_DEBUGGABLE (which will thus
1112 * be the index of the first non-debuggable one).
b81654f1
MS
1113 */
1114
1115/*
1116 * Function: total_number_of_imps (char *selector);
1117 *
1118 * Input: a string representing a selector
1119 * Output: number of methods that implement that selector.
1120 *
d2e6263c 1121 * By analogy with function "total_number_of_methods", this allows
b81654f1 1122 * decode_line_1 (symtab.c) to detect if there are objective c methods
d2e6263c
MS
1123 * matching the input, and to allocate an array of pointers to them
1124 * which can be manipulated by "decode_line_2" (also in symtab.c).
b81654f1
MS
1125 */
1126
1127char *
1128parse_selector (char *method, char **selector)
1129{
1130 char *s1 = NULL;
1131 char *s2 = NULL;
1132 int found_quote = 0;
1133
1134 char *nselector = NULL;
1135
e8f3fcdd 1136 gdb_assert (selector != NULL);
b81654f1
MS
1137
1138 s1 = method;
1139
1140 while (isspace (*s1))
1141 s1++;
1142 if (*s1 == '\'')
1143 {
1144 found_quote = 1;
1145 s1++;
1146 }
1147 while (isspace (*s1))
1148 s1++;
1149
1150 nselector = s1;
1151 s2 = s1;
1152
1153 for (;;) {
1154 if (isalnum (*s2) || (*s2 == '_') || (*s2 == ':'))
1155 *s1++ = *s2;
1156 else if (isspace (*s2))
1157 ;
1158 else if ((*s2 == '\0') || (*s2 == '\''))
1159 break;
1160 else
1161 return NULL;
1162 s2++;
1163 }
1164 *s1++ = '\0';
1165
1166 while (isspace (*s2))
1167 s2++;
1168 if (found_quote)
1169 {
1170 if (*s2 == '\'')
1171 s2++;
1172 while (isspace (*s2))
1173 s2++;
1174 }
1175
1176 if (selector != NULL)
1177 *selector = nselector;
1178
1179 return s2;
1180}
1181
1182char *
d2e6263c
MS
1183parse_method (char *method, char *type, char **class,
1184 char **category, char **selector)
b81654f1
MS
1185{
1186 char *s1 = NULL;
1187 char *s2 = NULL;
1188 int found_quote = 0;
1189
1190 char ntype = '\0';
1191 char *nclass = NULL;
1192 char *ncategory = NULL;
1193 char *nselector = NULL;
1194
e8f3fcdd
AC
1195 gdb_assert (type != NULL);
1196 gdb_assert (class != NULL);
1197 gdb_assert (category != NULL);
1198 gdb_assert (selector != NULL);
b81654f1
MS
1199
1200 s1 = method;
1201
1202 while (isspace (*s1))
1203 s1++;
1204 if (*s1 == '\'')
1205 {
1206 found_quote = 1;
1207 s1++;
1208 }
1209 while (isspace (*s1))
1210 s1++;
1211
1212 if ((s1[0] == '+') || (s1[0] == '-'))
1213 ntype = *s1++;
1214
1215 while (isspace (*s1))
1216 s1++;
1217
1218 if (*s1 != '[')
1219 return NULL;
1220 s1++;
1221
1222 nclass = s1;
1223 while (isalnum (*s1) || (*s1 == '_'))
1224 s1++;
1225
1226 s2 = s1;
1227 while (isspace (*s2))
1228 s2++;
1229
1230 if (*s2 == '(')
1231 {
1232 s2++;
1233 while (isspace (*s2))
1234 s2++;
1235 ncategory = s2;
1236 while (isalnum (*s2) || (*s2 == '_'))
1237 s2++;
1238 *s2++ = '\0';
1239 }
1240
d2e6263c 1241 /* Truncate the class name now that we're not using the open paren. */
b81654f1
MS
1242 *s1++ = '\0';
1243
1244 nselector = s2;
1245 s1 = s2;
1246
1247 for (;;) {
1248 if (isalnum (*s2) || (*s2 == '_') || (*s2 == ':'))
1249 *s1++ = *s2;
1250 else if (isspace (*s2))
1251 ;
1252 else if (*s2 == ']')
1253 break;
1254 else
1255 return NULL;
1256 s2++;
1257 }
1258 *s1++ = '\0';
1259 s2++;
1260
1261 while (isspace (*s2))
1262 s2++;
1263 if (found_quote)
1264 {
1265 if (*s2 != '\'')
1266 return NULL;
1267 s2++;
1268 while (isspace (*s2))
1269 s2++;
1270 }
1271
1272 if (type != NULL)
1273 *type = ntype;
1274 if (class != NULL)
1275 *class = nclass;
1276 if (category != NULL)
1277 *category = ncategory;
1278 if (selector != NULL)
1279 *selector = nselector;
1280
1281 return s2;
1282}
1283
2f9a90b4 1284static void
d2e6263c
MS
1285find_methods (struct symtab *symtab, char type,
1286 const char *class, const char *category,
1287 const char *selector, struct symbol **syms,
1288 unsigned int *nsym, unsigned int *ndebug)
b81654f1
MS
1289{
1290 struct objfile *objfile = NULL;
1291 struct minimal_symbol *msymbol = NULL;
1292 struct block *block = NULL;
1293 struct symbol *sym = NULL;
1294
1295 char *symname = NULL;
1296
1297 char ntype = '\0';
1298 char *nclass = NULL;
1299 char *ncategory = NULL;
1300 char *nselector = NULL;
1301
1302 unsigned int csym = 0;
1303 unsigned int cdebug = 0;
1304
1305 static char *tmp = NULL;
1306 static unsigned int tmplen = 0;
1307
e8f3fcdd
AC
1308 gdb_assert (nsym != NULL);
1309 gdb_assert (ndebug != NULL);
b81654f1
MS
1310
1311 if (symtab)
1312 block = BLOCKVECTOR_BLOCK (BLOCKVECTOR (symtab), STATIC_BLOCK);
1313
1314 ALL_MSYMBOLS (objfile, msymbol)
1315 {
1316 QUIT;
1317
1318 if ((msymbol->type != mst_text) && (msymbol->type != mst_file_text))
d2e6263c 1319 /* Not a function or method. */
b81654f1
MS
1320 continue;
1321
1322 if (symtab)
8da065d5
DC
1323 if ((SYMBOL_VALUE_ADDRESS (msymbol) < BLOCK_START (block)) ||
1324 (SYMBOL_VALUE_ADDRESS (msymbol) >= BLOCK_END (block)))
d2e6263c 1325 /* Not in the specified symtab. */
b81654f1
MS
1326 continue;
1327
36018d2e 1328 symname = SYMBOL_NATURAL_NAME (msymbol);
b81654f1
MS
1329 if (symname == NULL)
1330 continue;
1331
1332 if ((symname[0] != '-' && symname[0] != '+') || (symname[1] != '['))
d2e6263c 1333 /* Not a method name. */
b81654f1
MS
1334 continue;
1335
1336 while ((strlen (symname) + 1) >= tmplen)
1337 {
1338 tmplen = (tmplen == 0) ? 1024 : tmplen * 2;
1339 tmp = xrealloc (tmp, tmplen);
1340 }
1341 strcpy (tmp, symname);
1342
1343 if (parse_method (tmp, &ntype, &nclass, &ncategory, &nselector) == NULL)
1344 continue;
1345
1346 if ((type != '\0') && (ntype != type))
1347 continue;
1348
d2e6263c
MS
1349 if ((class != NULL)
1350 && ((nclass == NULL) || (strcmp (class, nclass) != 0)))
b81654f1
MS
1351 continue;
1352
d2e6263c
MS
1353 if ((category != NULL) &&
1354 ((ncategory == NULL) || (strcmp (category, ncategory) != 0)))
b81654f1
MS
1355 continue;
1356
d2e6263c
MS
1357 if ((selector != NULL) &&
1358 ((nselector == NULL) || (strcmp (selector, nselector) != 0)))
b81654f1
MS
1359 continue;
1360
1361 sym = find_pc_function (SYMBOL_VALUE_ADDRESS (msymbol));
1362 if (sym != NULL)
1363 {
36018d2e 1364 const char *newsymname = SYMBOL_NATURAL_NAME (sym);
b81654f1 1365
b81654f1
MS
1366 if (strcmp (symname, newsymname) == 0)
1367 {
d2e6263c
MS
1368 /* Found a high-level method sym: swap it into the
1369 lower part of sym_arr (below num_debuggable). */
b81654f1
MS
1370 if (syms != NULL)
1371 {
1372 syms[csym] = syms[cdebug];
1373 syms[cdebug] = sym;
1374 }
1375 csym++;
1376 cdebug++;
1377 }
1378 else
1379 {
d2e6263c
MS
1380 warning (
1381"debugging symbol \"%s\" does not match minimal symbol (\"%s\"); ignoring",
b81654f1
MS
1382 newsymname, symname);
1383 if (syms != NULL)
1384 syms[csym] = (struct symbol *) msymbol;
1385 csym++;
1386 }
1387 }
1388 else
1389 {
d2e6263c 1390 /* Found a non-debuggable method symbol. */
b81654f1
MS
1391 if (syms != NULL)
1392 syms[csym] = (struct symbol *) msymbol;
1393 csym++;
1394 }
1395 }
1396
1397 if (nsym != NULL)
1398 *nsym = csym;
1399 if (ndebug != NULL)
1400 *ndebug = cdebug;
1401}
1402
1403char *find_imps (struct symtab *symtab, struct block *block,
d2e6263c
MS
1404 char *method, struct symbol **syms,
1405 unsigned int *nsym, unsigned int *ndebug)
b81654f1
MS
1406{
1407 char type = '\0';
1408 char *class = NULL;
1409 char *category = NULL;
1410 char *selector = NULL;
1411
1412 unsigned int csym = 0;
1413 unsigned int cdebug = 0;
1414
1415 unsigned int ncsym = 0;
1416 unsigned int ncdebug = 0;
1417
1418 char *buf = NULL;
1419 char *tmp = NULL;
1420
e8f3fcdd
AC
1421 gdb_assert (nsym != NULL);
1422 gdb_assert (ndebug != NULL);
b81654f1
MS
1423
1424 if (nsym != NULL)
1425 *nsym = 0;
1426 if (ndebug != NULL)
1427 *ndebug = 0;
1428
1429 buf = (char *) alloca (strlen (method) + 1);
1430 strcpy (buf, method);
1431 tmp = parse_method (buf, &type, &class, &category, &selector);
1432
1433 if (tmp == NULL) {
1434
b81654f1
MS
1435 struct symbol *sym = NULL;
1436 struct minimal_symbol *msym = NULL;
1437
1438 strcpy (buf, method);
1439 tmp = parse_selector (buf, &selector);
1440
1441 if (tmp == NULL)
1442 return NULL;
1443
cdef89d0 1444 sym = lookup_symbol (selector, block, VAR_DOMAIN, 0, NULL);
b81654f1
MS
1445 if (sym != NULL)
1446 {
1447 if (syms)
1448 syms[csym] = sym;
1449 csym++;
1450 cdebug++;
1451 }
1452
1453 if (sym == NULL)
1454 msym = lookup_minimal_symbol (selector, 0, 0);
1455
1456 if (msym != NULL)
1457 {
1458 if (syms)
36e53c63 1459 syms[csym] = (struct symbol *)msym;
b81654f1
MS
1460 csym++;
1461 }
1462 }
1463
1464 if (syms != NULL)
d2e6263c
MS
1465 find_methods (symtab, type, class, category, selector,
1466 syms + csym, &ncsym, &ncdebug);
b81654f1 1467 else
d2e6263c
MS
1468 find_methods (symtab, type, class, category, selector,
1469 NULL, &ncsym, &ncdebug);
b81654f1 1470
d2e6263c 1471 /* If we didn't find any methods, just return. */
b81654f1
MS
1472 if (ncsym == 0 && ncdebug == 0)
1473 return method;
1474
1475 /* Take debug symbols from the second batch of symbols and swap them
1476 * with debug symbols from the first batch. Repeat until either the
1477 * second section is out of debug symbols or the first section is
1478 * full of debug symbols. Either way we have all debug symbols
d2e6263c
MS
1479 * packed to the beginning of the buffer.
1480 */
b81654f1
MS
1481
1482 if (syms != NULL)
1483 {
1484 while ((cdebug < csym) && (ncdebug > 0))
1485 {
1486 struct symbol *s = NULL;
d2e6263c
MS
1487 /* First non-debugging symbol. */
1488 unsigned int i = cdebug;
1489 /* Last of second batch of debug symbols. */
1490 unsigned int j = csym + ncdebug - 1;
b81654f1
MS
1491
1492 s = syms[j];
1493 syms[j] = syms[i];
1494 syms[i] = s;
1495
d2e6263c
MS
1496 /* We've moved a symbol from the second debug section to the
1497 first one. */
b81654f1
MS
1498 cdebug++;
1499 ncdebug--;
1500 }
1501 }
1502
1503 csym += ncsym;
1504 cdebug += ncdebug;
1505
1506 if (nsym != NULL)
1507 *nsym = csym;
1508 if (ndebug != NULL)
1509 *ndebug = cdebug;
1510
1511 if (syms == NULL)
1512 return method + (tmp - buf);
1513
1514 if (csym > 1)
1515 {
d2e6263c 1516 /* Sort debuggable symbols. */
b81654f1 1517 if (cdebug > 1)
d2e6263c
MS
1518 qsort (syms, cdebug, sizeof (struct minimal_symbol *),
1519 compare_classes);
b81654f1 1520
d2e6263c 1521 /* Sort minimal_symbols. */
b81654f1 1522 if ((csym - cdebug) > 1)
d2e6263c
MS
1523 qsort (&syms[cdebug], csym - cdebug,
1524 sizeof (struct minimal_symbol *), compare_classes);
b81654f1 1525 }
d2e6263c
MS
1526 /* Terminate the sym_arr list. */
1527 syms[csym] = 0;
b81654f1
MS
1528
1529 return method + (tmp - buf);
1530}
1531
b9362cc7 1532static void
b81654f1
MS
1533print_object_command (char *args, int from_tty)
1534{
1535 struct value *object, *function, *description;
36e53c63 1536 CORE_ADDR string_addr, object_addr;
b81654f1 1537 int i = 0;
22a44745 1538 gdb_byte c = 0;
b81654f1
MS
1539
1540 if (!args || !*args)
d2e6263c
MS
1541 error (
1542"The 'print-object' command requires an argument (an Objective-C object)");
b81654f1
MS
1543
1544 {
1545 struct expression *expr = parse_expression (args);
f86f5ca3 1546 struct cleanup *old_chain =
d2e6263c 1547 make_cleanup (free_current_contents, &expr);
b81654f1
MS
1548 int pc = 0;
1549
5f9769d1
PH
1550 object = expr->language_defn->la_exp_desc->evaluate_exp
1551 (builtin_type_void_data_ptr, expr, &pc, EVAL_NORMAL);
b81654f1
MS
1552 do_cleanups (old_chain);
1553 }
1554
36e53c63
AF
1555 /* Validate the address for sanity. */
1556 object_addr = value_as_long (object);
1557 read_memory (object_addr, &c, 1);
1558
7248f48e 1559 function = find_function_in_inferior ("_NSPrintForDebugger");
36e53c63 1560 if (function == NULL)
8a3fe4f8 1561 error (_("Unable to locate _NSPrintForDebugger in child process"));
b81654f1
MS
1562
1563 description = call_function_by_hand (function, 1, &object);
1564
7248f48e
AF
1565 string_addr = value_as_long (description);
1566 if (string_addr == 0)
8a3fe4f8 1567 error (_("object returns null description"));
b81654f1
MS
1568
1569 read_memory (string_addr + i++, &c, 1);
22a44745 1570 if (c != 0)
b81654f1 1571 do
d2e6263c 1572 { /* Read and print characters up to EOS. */
b81654f1
MS
1573 QUIT;
1574 printf_filtered ("%c", c);
1575 read_memory (string_addr + i++, &c, 1);
1576 } while (c != 0);
1577 else
a3f17187 1578 printf_filtered(_("<object returns empty description>"));
b81654f1
MS
1579 printf_filtered ("\n");
1580}
1581
d2e6263c
MS
1582/* The data structure 'methcalls' is used to detect method calls (thru
1583 * ObjC runtime lib functions objc_msgSend, objc_msgSendSuper, etc.),
1584 * and ultimately find the method being called.
b81654f1
MS
1585 */
1586
1587struct objc_methcall {
1588 char *name;
d2e6263c 1589 /* Return instance method to be called. */
36e53c63 1590 int (*stop_at) (CORE_ADDR, CORE_ADDR *);
d2e6263c
MS
1591 /* Start of pc range corresponding to method invocation. */
1592 CORE_ADDR begin;
1593 /* End of pc range corresponding to method invocation. */
1594 CORE_ADDR end;
b81654f1
MS
1595};
1596
d2e6263c
MS
1597static int resolve_msgsend (CORE_ADDR pc, CORE_ADDR *new_pc);
1598static int resolve_msgsend_stret (CORE_ADDR pc, CORE_ADDR *new_pc);
1599static int resolve_msgsend_super (CORE_ADDR pc, CORE_ADDR *new_pc);
1600static int resolve_msgsend_super_stret (CORE_ADDR pc, CORE_ADDR *new_pc);
b81654f1
MS
1601
1602static struct objc_methcall methcalls[] = {
1603 { "_objc_msgSend", resolve_msgsend, 0, 0},
1604 { "_objc_msgSend_stret", resolve_msgsend_stret, 0, 0},
1605 { "_objc_msgSendSuper", resolve_msgsend_super, 0, 0},
1606 { "_objc_msgSendSuper_stret", resolve_msgsend_super_stret, 0, 0},
1607 { "_objc_getClass", NULL, 0, 0},
1608 { "_objc_getMetaClass", NULL, 0, 0}
1609};
1610
1611#define nmethcalls (sizeof (methcalls) / sizeof (methcalls[0]))
1612
d2e6263c
MS
1613/* The following function, "find_objc_msgsend", fills in the data
1614 * structure "objc_msgs" by finding the addresses of each of the
1615 * (currently four) functions that it holds (of which objc_msgSend is
1616 * the first). This must be called each time symbols are loaded, in
1617 * case the functions have moved for some reason.
b81654f1
MS
1618 */
1619
b9362cc7 1620static void
b81654f1
MS
1621find_objc_msgsend (void)
1622{
1623 unsigned int i;
1624 for (i = 0; i < nmethcalls; i++) {
1625
1626 struct minimal_symbol *func;
1627
d2e6263c 1628 /* Try both with and without underscore. */
b81654f1
MS
1629 func = lookup_minimal_symbol (methcalls[i].name, NULL, NULL);
1630 if ((func == NULL) && (methcalls[i].name[0] == '_')) {
1631 func = lookup_minimal_symbol (methcalls[i].name + 1, NULL, NULL);
1632 }
1633 if (func == NULL) {
1634 methcalls[i].begin = 0;
1635 methcalls[i].end = 0;
1636 continue;
1637 }
1638
1639 methcalls[i].begin = SYMBOL_VALUE_ADDRESS (func);
1640 do {
1641 methcalls[i].end = SYMBOL_VALUE_ADDRESS (++func);
1642 } while (methcalls[i].begin == methcalls[i].end);
1643 }
1644}
1645
1646/* find_objc_msgcall (replaces pc_off_limits)
1647 *
d2e6263c
MS
1648 * ALL that this function now does is to determine whether the input
1649 * address ("pc") is the address of one of the Objective-C message
b81654f1
MS
1650 * dispatch functions (mainly objc_msgSend or objc_msgSendSuper), and
1651 * if so, it returns the address of the method that will be called.
1652 *
1653 * The old function "pc_off_limits" used to do a lot of other things
d2e6263c 1654 * in addition, such as detecting shared library jump stubs and
b81654f1 1655 * returning the address of the shlib function that would be called.
e76f05fa 1656 * That functionality has been moved into the gdbarch_skip_trampoline_code and
d2e6263c
MS
1657 * IN_SOLIB_TRAMPOLINE macros, which are resolved in the target-
1658 * dependent modules.
b81654f1
MS
1659 */
1660
1661struct objc_submethod_helper_data {
36e53c63 1662 int (*f) (CORE_ADDR, CORE_ADDR *);
b81654f1
MS
1663 CORE_ADDR pc;
1664 CORE_ADDR *new_pc;
1665};
1666
b9362cc7 1667static int
7248f48e 1668find_objc_msgcall_submethod_helper (void * arg)
b81654f1 1669{
d2e6263c
MS
1670 struct objc_submethod_helper_data *s =
1671 (struct objc_submethod_helper_data *) arg;
1672
1673 if (s->f (s->pc, s->new_pc) == 0)
b81654f1 1674 return 1;
d2e6263c 1675 else
b81654f1 1676 return 0;
b81654f1
MS
1677}
1678
b9362cc7 1679static int
36e53c63 1680find_objc_msgcall_submethod (int (*f) (CORE_ADDR, CORE_ADDR *),
d2e6263c
MS
1681 CORE_ADDR pc,
1682 CORE_ADDR *new_pc)
b81654f1
MS
1683{
1684 struct objc_submethod_helper_data s;
1685
1686 s.f = f;
1687 s.pc = pc;
1688 s.new_pc = new_pc;
1689
1690 if (catch_errors (find_objc_msgcall_submethod_helper,
7248f48e 1691 (void *) &s,
d2e6263c
MS
1692 "Unable to determine target of Objective-C method call (ignoring):\n",
1693 RETURN_MASK_ALL) == 0)
b81654f1 1694 return 1;
d2e6263c 1695 else
b81654f1 1696 return 0;
b81654f1
MS
1697}
1698
1699int
1700find_objc_msgcall (CORE_ADDR pc, CORE_ADDR *new_pc)
1701{
1702 unsigned int i;
1703
1704 find_objc_msgsend ();
5e488a7b
AC
1705 if (new_pc != NULL)
1706 {
1707 *new_pc = 0;
1708 }
b81654f1 1709
d2e6263c
MS
1710 for (i = 0; i < nmethcalls; i++)
1711 if ((pc >= methcalls[i].begin) && (pc < methcalls[i].end))
1712 {
1713 if (methcalls[i].stop_at != NULL)
1714 return find_objc_msgcall_submethod (methcalls[i].stop_at,
1715 pc, new_pc);
1716 else
1717 return 0;
b81654f1 1718 }
d2e6263c 1719
b81654f1
MS
1720 return 0;
1721}
1722
a78f21af 1723extern initialize_file_ftype _initialize_objc_language; /* -Wmissing-prototypes */
b9362cc7 1724
b81654f1
MS
1725void
1726_initialize_objc_language (void)
1727{
1728 add_language (&objc_language_defn);
d2e6263c 1729 add_info ("selectors", selectors_info, /* INFO SELECTORS command. */
1bedd215 1730 _("All Objective-C selectors, or those matching REGEXP."));
d2e6263c 1731 add_info ("classes", classes_info, /* INFO CLASSES command. */
1bedd215 1732 _("All Objective-C classes, or those matching REGEXP."));
b81654f1 1733 add_com ("print-object", class_vars, print_object_command,
1bedd215 1734 _("Ask an Objective-C object to print itself."));
b81654f1
MS
1735 add_com_alias ("po", "print-object", class_vars, 1);
1736}
1737
b81654f1
MS
1738static void
1739read_objc_method (CORE_ADDR addr, struct objc_method *method)
1740{
d2e6263c 1741 method->name = read_memory_unsigned_integer (addr + 0, 4);
b81654f1 1742 method->types = read_memory_unsigned_integer (addr + 4, 4);
d2e6263c 1743 method->imp = read_memory_unsigned_integer (addr + 8, 4);
b81654f1
MS
1744}
1745
1746static
1747unsigned long read_objc_methlist_nmethods (CORE_ADDR addr)
1748{
1749 return read_memory_unsigned_integer (addr + 4, 4);
1750}
1751
1752static void
1753read_objc_methlist_method (CORE_ADDR addr, unsigned long num,
1754 struct objc_method *method)
1755{
e8f3fcdd 1756 gdb_assert (num < read_objc_methlist_nmethods (addr));
b81654f1
MS
1757 read_objc_method (addr + 8 + (12 * num), method);
1758}
1759
1760static void
1761read_objc_object (CORE_ADDR addr, struct objc_object *object)
1762{
1763 object->isa = read_memory_unsigned_integer (addr, 4);
1764}
1765
1766static void
1767read_objc_super (CORE_ADDR addr, struct objc_super *super)
1768{
1769 super->receiver = read_memory_unsigned_integer (addr, 4);
1770 super->class = read_memory_unsigned_integer (addr + 4, 4);
1771};
1772
1773static void
1774read_objc_class (CORE_ADDR addr, struct objc_class *class)
1775{
1776 class->isa = read_memory_unsigned_integer (addr, 4);
1777 class->super_class = read_memory_unsigned_integer (addr + 4, 4);
1778 class->name = read_memory_unsigned_integer (addr + 8, 4);
1779 class->version = read_memory_unsigned_integer (addr + 12, 4);
1780 class->info = read_memory_unsigned_integer (addr + 16, 4);
1781 class->instance_size = read_memory_unsigned_integer (addr + 18, 4);
1782 class->ivars = read_memory_unsigned_integer (addr + 24, 4);
1783 class->methods = read_memory_unsigned_integer (addr + 28, 4);
1784 class->cache = read_memory_unsigned_integer (addr + 32, 4);
1785 class->protocols = read_memory_unsigned_integer (addr + 36, 4);
1786}
1787
b9362cc7 1788static CORE_ADDR
b81654f1
MS
1789find_implementation_from_class (CORE_ADDR class, CORE_ADDR sel)
1790{
1791 CORE_ADDR subclass = class;
1792
d2e6263c
MS
1793 while (subclass != 0)
1794 {
b81654f1 1795
d2e6263c
MS
1796 struct objc_class class_str;
1797 unsigned mlistnum = 0;
b81654f1 1798
d2e6263c 1799 read_objc_class (subclass, &class_str);
b81654f1 1800
d2e6263c
MS
1801 for (;;)
1802 {
1803 CORE_ADDR mlist;
1804 unsigned long nmethods;
1805 unsigned long i;
b81654f1 1806
d2e6263c
MS
1807 mlist = read_memory_unsigned_integer (class_str.methods +
1808 (4 * mlistnum), 4);
1809 if (mlist == 0)
1810 break;
b81654f1 1811
d2e6263c 1812 nmethods = read_objc_methlist_nmethods (mlist);
b81654f1 1813
d2e6263c
MS
1814 for (i = 0; i < nmethods; i++)
1815 {
1816 struct objc_method meth_str;
1817 read_objc_methlist_method (mlist, i, &meth_str);
b81654f1
MS
1818
1819#if 0
d2e6263c
MS
1820 fprintf (stderr,
1821 "checking method 0x%lx against selector 0x%lx\n",
1822 meth_str.name, sel);
b81654f1
MS
1823#endif
1824
d2e6263c 1825 if (meth_str.name == sel)
1abf022c
AF
1826 /* FIXME: hppa arch was doing a pointer dereference
1827 here. There needs to be a better way to do that. */
1828 return meth_str.imp;
d2e6263c
MS
1829 }
1830 mlistnum++;
b81654f1 1831 }
d2e6263c 1832 subclass = class_str.super_class;
b81654f1 1833 }
b81654f1
MS
1834
1835 return 0;
1836}
1837
b9362cc7 1838static CORE_ADDR
b81654f1
MS
1839find_implementation (CORE_ADDR object, CORE_ADDR sel)
1840{
1841 struct objc_object ostr;
1842
d2e6263c
MS
1843 if (object == 0)
1844 return 0;
b81654f1 1845 read_objc_object (object, &ostr);
d2e6263c
MS
1846 if (ostr.isa == 0)
1847 return 0;
b81654f1
MS
1848
1849 return find_implementation_from_class (ostr.isa, sel);
1850}
1851
a0273b2f 1852#define OBJC_FETCH_POINTER_ARGUMENT(argi) \
d99344c0
UW
1853 gdbarch_fetch_pointer_argument (current_gdbarch, get_current_frame (), \
1854 argi, builtin_type_void_func_ptr)
a0273b2f 1855
b81654f1
MS
1856static int
1857resolve_msgsend (CORE_ADDR pc, CORE_ADDR *new_pc)
1858{
1859 CORE_ADDR object;
1860 CORE_ADDR sel;
1861 CORE_ADDR res;
1862
a0273b2f
AF
1863 object = OBJC_FETCH_POINTER_ARGUMENT (0);
1864 sel = OBJC_FETCH_POINTER_ARGUMENT (1);
b81654f1
MS
1865
1866 res = find_implementation (object, sel);
d2e6263c
MS
1867 if (new_pc != 0)
1868 *new_pc = res;
1869 if (res == 0)
1870 return 1;
b81654f1
MS
1871 return 0;
1872}
1873
1874static int
1875resolve_msgsend_stret (CORE_ADDR pc, CORE_ADDR *new_pc)
1876{
1877 CORE_ADDR object;
1878 CORE_ADDR sel;
1879 CORE_ADDR res;
1880
a0273b2f
AF
1881 object = OBJC_FETCH_POINTER_ARGUMENT (1);
1882 sel = OBJC_FETCH_POINTER_ARGUMENT (2);
b81654f1
MS
1883
1884 res = find_implementation (object, sel);
d2e6263c
MS
1885 if (new_pc != 0)
1886 *new_pc = res;
1887 if (res == 0)
1888 return 1;
b81654f1
MS
1889 return 0;
1890}
1891
1892static int
1893resolve_msgsend_super (CORE_ADDR pc, CORE_ADDR *new_pc)
1894{
1895 struct objc_super sstr;
1896
1897 CORE_ADDR super;
1898 CORE_ADDR sel;
1899 CORE_ADDR res;
1900
a0273b2f
AF
1901 super = OBJC_FETCH_POINTER_ARGUMENT (0);
1902 sel = OBJC_FETCH_POINTER_ARGUMENT (1);
b81654f1
MS
1903
1904 read_objc_super (super, &sstr);
d2e6263c
MS
1905 if (sstr.class == 0)
1906 return 0;
b81654f1
MS
1907
1908 res = find_implementation_from_class (sstr.class, sel);
d2e6263c
MS
1909 if (new_pc != 0)
1910 *new_pc = res;
1911 if (res == 0)
1912 return 1;
b81654f1
MS
1913 return 0;
1914}
1915
1916static int
1917resolve_msgsend_super_stret (CORE_ADDR pc, CORE_ADDR *new_pc)
1918{
1919 struct objc_super sstr;
1920
1921 CORE_ADDR super;
1922 CORE_ADDR sel;
1923 CORE_ADDR res;
1924
a0273b2f
AF
1925 super = OBJC_FETCH_POINTER_ARGUMENT (1);
1926 sel = OBJC_FETCH_POINTER_ARGUMENT (2);
b81654f1
MS
1927
1928 read_objc_super (super, &sstr);
d2e6263c
MS
1929 if (sstr.class == 0)
1930 return 0;
b81654f1
MS
1931
1932 res = find_implementation_from_class (sstr.class, sel);
d2e6263c
MS
1933 if (new_pc != 0)
1934 *new_pc = res;
1935 if (res == 0)
1936 return 1;
b81654f1
MS
1937 return 0;
1938}
This page took 0.601119 seconds and 4 git commands to generate.