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