40#include "gdbsupport/gdb_regex.h"
97 error (_(
"No struct type named %s."),
name);
99 if (sym->
type ()->
code () != TYPE_CODE_STRUCT)
104 error (_(
"This context has class, union or enum %s, not a struct."),
114 struct value * function, *classval;
128 complaint (_(
"no way to lookup Objective-C classes"));
132 classval =
value_string (classname, strlen (classname) + 1, char_type);
143 struct value * function, *selstring;
157 complaint (_(
"no way to lookup Objective-C selectors"));
171 struct value *stringValue[3];
172 struct value *function, *nsstringValue;
205 error (_(
"NSString: internal error -- no way to create new NSString"));
216 return nsstringValue;
230 const char *
name ()
const override
231 {
return "objective-c"; }
236 {
return "Objective-C"; }
242 static const std::vector<const char *> extensions = {
".m" };
255 (
const char *mangled, gdb::unique_xmalloc_ptr<char> *demangled)
259 return *demangled != NULL;
265 int options)
const override;
277 struct ui_file *stream,
int show,
int level,
286 CORE_ADDR stop_pc)
const override
289 CORE_ADDR real_stop_pc;
290 CORE_ADDR method_stop_pc;
301 if (real_stop_pc != 0)
309 (
gdbarch, frame, method_stop_pc);
310 if (real_stop_pc == 0)
311 real_stop_pc = method_stop_pc;
330gdb::unique_xmalloc_ptr<char>
333 char *demangled, *cp;
335 if (mangled[0] ==
'_'
336 && (mangled[1] ==
'i' || mangled[1] ==
'c')
337 && mangled[2] ==
'_')
339 cp = demangled = (
char *)
xmalloc (strlen (mangled) + 2);
341 if (mangled[1] ==
'i')
347 strcpy(cp, mangled+3);
349 while (*cp !=
'\0' && *cp ==
'_')
353 cp = strchr(cp,
'_');
362 strcpy(cp, mangled + (cp - demangled) + 2);
367 cp = strchr(cp,
'_');
375 strcpy(cp, mangled + (cp - demangled));
378 while (*cp !=
'\0' && *cp ==
'_')
382 for (; *cp !=
'\0'; cp++)
388 return gdb::unique_xmalloc_ptr<char> (demangled);
474 std::vector<expr::operation_up> args = ps->
pop_vector (val);
482 error (_(
"Can't find selector \"%s\""), p);
503 while (*a && *a !=
' ' && *a !=
']' && *b && *b !=
' ' && *b !=
']')
509 if (*a && *a !=
' ' && *a !=
']')
511 if (*b && *b !=
' ' && *b !=
']')
526 const char *aname, *bname;
528 aname = (*(
struct symbol **) a)->print_name ();
529 bname = (*(
struct symbol **) b)->print_name ();
530 if (aname == NULL || bname == NULL)
531 error (_(
"internal: compare_selectors(1)"));
533 aname = strchr(aname,
' ');
534 bname = strchr(bname,
' ');
535 if (aname == NULL || bname == NULL)
536 error (_(
"internal: compare_selectors(2)"));
564 strcpy(myregexp,
".*]");
567 if (*regexp ==
'+' || *regexp ==
'-')
569 plusminus = *regexp++;
570 while (*regexp ==
' ' || *regexp ==
'\t')
574 strcpy(myregexp,
".*]");
578 if (
sizeof (myregexp) < strlen (regexp) + 4)
579 error (_(
"Regexp is too long: %s"), regexp);
580 strcpy(myregexp, regexp);
581 if (myregexp[strlen(myregexp) - 1] ==
'$')
582 myregexp[strlen(myregexp) - 1] =
']';
584 strcat(myregexp,
".*]");
592 error (_(
"Invalid regexp (%s): %s"), val, regexp);
601 name = msymbol->natural_name ();
603 && (
name[0] ==
'-' ||
name[0] ==
'+')
607 if (plusminus &&
name[0] != plusminus)
610 name = (
char *) strchr (
name+2,
' ');
614 msymbol->natural_name ());
617 if (regexp == NULL || re_exec(++
name) != 0)
619 const char *mystart =
name;
620 const char *myend = strchr (mystart,
']');
622 if (myend && (myend - mystart > maxlen))
623 maxlen = myend - mystart;
631 gdb_printf (_(
"Selectors matching \"%s\":\n\n"),
632 regexp ? regexp :
"*");
641 name = msymbol->natural_name ();
643 (
name[0] ==
'-' ||
name[0] ==
'+') &&
647 if (plusminus &&
name[0] != plusminus)
650 name = (
char *) strchr(
name+2,
' ');
651 if (regexp == NULL || re_exec(++
name) != 0)
661 for (ix = 0; ix <
matches; ix++)
666 name = sym_arr[ix]->natural_name ();
681 gdb_printf (_(
"No selectors matching \"%s\"\n"),
682 regexp ? regexp :
"*");
695 const char *aname, *bname;
697 aname = (*(
struct symbol **) a)->print_name ();
698 bname = (*(
struct symbol **) b)->print_name ();
699 if (aname == NULL || bname == NULL)
700 error (_(
"internal: compare_classes(1)"));
728 strcpy(myregexp,
".* ");
732 if (
sizeof (myregexp) < strlen (regexp) + 4)
733 error (_(
"Regexp is too long: %s"), regexp);
734 strcpy(myregexp, regexp);
735 if (myregexp[strlen(myregexp) - 1] ==
'$')
737 myregexp[strlen(myregexp) - 1] =
' ';
739 strcat(myregexp,
".* ");
746 error (_(
"Invalid regexp (%s): %s"), val, regexp);
755 name = msymbol->natural_name ();
757 (
name[0] ==
'-' ||
name[0] ==
'+') &&
759 if (regexp == NULL || re_exec(
name+2) != 0)
762 const char *mystart =
name + 2;
763 const char *myend = strchr (mystart,
' ');
765 if (myend && (myend - mystart > maxlen))
766 maxlen = myend - mystart;
773 gdb_printf (_(
"Classes matching \"%s\":\n\n"),
774 regexp ? regexp :
"*");
782 name = msymbol->natural_name ();
784 (
name[0] ==
'-' ||
name[0] ==
'+') &&
786 if (regexp == NULL || re_exec(
name+2) != 0)
795 for (ix = 0; ix <
matches; ix++)
800 name = sym_arr[ix]->natural_name ();
815 gdb_printf (_(
"No classes matching \"%s\"\n"), regexp ? regexp :
"*");
825 char *nselector = NULL;
831 s1 = skip_spaces (
s1);
837 s1 = skip_spaces (
s1);
844 if (isalnum (*
s2) || (*
s2 ==
'_') || (*
s2 ==
':'))
846 else if (isspace (*
s2))
848 else if ((*
s2 ==
'\0') || (*
s2 ==
'\''))
856 s2 = skip_spaces (
s2);
861 s2 = skip_spaces (
s2);
880 char *ncategory = NULL;
881 char *nselector = NULL;
883 gdb_assert (
type != NULL);
884 gdb_assert (theclass != NULL);
885 gdb_assert (category != NULL);
890 s1 = skip_spaces (
s1);
896 s1 = skip_spaces (
s1);
898 if ((
s1[0] ==
'+') || (
s1[0] ==
'-'))
901 s1 = skip_spaces (
s1);
908 while (isalnum (*
s1) || (*
s1 ==
'_'))
912 s2 = skip_spaces (
s2);
917 s2 = skip_spaces (
s2);
919 while (isalnum (*
s2) || (*
s2 ==
'_'))
932 if (isalnum (*
s2) || (*
s2 ==
'_') || (*
s2 ==
':'))
934 else if (isspace (*
s2))
945 s2 = skip_spaces (
s2);
951 s2 = skip_spaces (
s2);
956 if (theclass != NULL)
958 if (category != NULL)
959 *category = ncategory;
969 std::vector<const char *> *symbol_names)
971 const char *symname = NULL;
975 char *ncategory = NULL;
976 char *nselector = NULL;
978 static char *tmp = NULL;
979 static unsigned int tmplen = 0;
981 gdb_assert (symbol_names != NULL);
985 unsigned int *objc_csym;
992 unsigned int objfile_csym = 0;
995 if (objc_csym != NULL && *objc_csym == 0)
1005 symname = msymbol->natural_name ();
1006 if (symname == NULL)
1009 if ((symname[0] !=
'-' && symname[0] !=
'+') || (symname[1] !=
'['))
1016 while ((strlen (symname) + 1) >= tmplen)
1018 tmplen = (tmplen == 0) ? 1024 : tmplen * 2;
1019 tmp = (
char *)
xrealloc (tmp, tmplen);
1021 strcpy (tmp, symname);
1024 &ncategory, &nselector) == NULL)
1027 if ((
type !=
'\0') && (ntype !=
type))
1030 if ((theclass != NULL)
1031 && ((nclass == NULL) || (strcmp (theclass, nclass) != 0)))
1034 if ((category != NULL) &&
1035 ((ncategory == NULL) || (strcmp (category, ncategory) != 0)))
1039 ((nselector == NULL) || (strcmp (
selector, nselector) != 0)))
1042 symbol_names->push_back (symname);
1045 if (objc_csym == NULL)
1049 gdb_assert (*objc_csym == objfile_csym);
1058 if (strings->empty ())
1061 std::sort (strings->begin (), strings->end (), compare_cstrings);
1062 strings->erase (std::unique (strings->begin (), strings->end (), streq),
1097find_imps (
const char *method, std::vector<const char *> *symbol_names)
1100 char *theclass = NULL;
1101 char *category = NULL;
1107 int selector_case = 0;
1109 gdb_assert (symbol_names != NULL);
1111 buf = (
char *) alloca (strlen (method) + 1);
1112 strcpy (buf, method);
1117 strcpy (buf, method);
1130 if (selector_case && !symbol_names->empty ())
1149 return method + (tmp - buf);
1155 struct value *object, *function, *description;
1156 CORE_ADDR string_addr, object_addr;
1160 if (!args || !*args)
1162"The 'print-object' command requires an argument (an Objective-C object)");
1175 if (function == NULL)
1176 error (_(
"Unable to locate _NSPrintForDebugger in child process"));
1181 if (string_addr == 0)
1182 error (_(
"object returns null description"));
1193 gdb_printf(_(
"<object returns empty description>"));
1222 {
"_objc_getClass", NULL, 0, 0},
1223 {
"_objc_getMetaClass", NULL, 0, 0}
1226#define nmethcalls (sizeof (methcalls) / sizeof (methcalls[0]))
1250 if (
func.minsym == NULL)
1284 if (
f (pc, new_pc) == 0)
1287 catch (
const gdb_exception_error &ex)
1290 "Unable to determine target of "
1291 "Objective-C method call (ignoring):\n");
1326 _(
"All Objective-C selectors, or those matching REGEXP."));
1328 _(
"All Objective-C classes, or those matching REGEXP."));
1331 _(
"Ask an Objective-C object to print itself."));
1402 CORE_ADDR theclass, CORE_ADDR sel)
1405 CORE_ADDR subclass = theclass;
1407 while (subclass != 0)
1411 unsigned mlistnum = 0;
1418 unsigned long nmethods;
1429 for (i = 0; i < nmethods; i++)
1435 if (meth_str.
name == sel)
1438 return meth_str.
imp;
1450 CORE_ADDR
object, CORE_ADDR sel)
void * xrealloc(void *ptr, size_t size)
constexpr std::string_view s1
constexpr std::string_view s2
void c_language_arch_info(struct gdbarch *gdbarch, struct language_arch_info *lai)
void c_print_type(struct type *type, const char *varstring, struct ui_file *stream, int show, int level, enum language language, const struct type_print_options *flags)
const char * name_of_this() const override
gdb::unique_xmalloc_ptr< char > demangle_symbol(const char *mangled, int options) const override
enum macro_expansion macro_expansion() const override
bool can_print_type_offsets() const override
const std::vector< const char * > & filename_extensions() const override
CORE_ADDR skip_trampoline(const frame_info_ptr &frame, CORE_ADDR stop_pc) const override
const char * name() const override
void print_type(struct type *type, const char *varstring, struct ui_file *stream, int show, int level, const struct type_print_options *flags) const override
void language_arch_info(struct gdbarch *gdbarch, struct language_arch_info *lai) const override
bool sniff_from_mangled_name(const char *mangled, gdb::unique_xmalloc_ptr< char > *demangled) const override
const char * natural_name() const override
cmd_list_element * add_com_alias(const char *name, cmd_list_element *target, command_class theclass, int abbrev_flag)
struct cmd_list_element * add_com(const char *name, enum command_class theclass, cmd_simple_func_ftype *fun, const char *doc)
struct cmd_list_element * add_info(const char *name, cmd_simple_func_ftype *fun, const char *doc)
#define complaint(FMT,...)
ULONGEST read_memory_unsigned_integer(CORE_ADDR memaddr, int len, enum bfd_endian byte_order)
void read_memory(CORE_ADDR memaddr, gdb_byte *myaddr, ssize_t len)
EXTERN_C char * re_comp(const char *)
void exception_fprintf(struct ui_file *file, const struct gdb_exception &e, const char *prefix,...)
std::unique_ptr< expression > expression_up
expression_up parse_expression(const char *, innermost_block_tracker *=nullptr, parser_flags flags=0)
struct gdbarch * get_frame_arch(frame_info_ptr this_frame)
frame_info_ptr get_current_frame(void)
enum bfd_endian gdbarch_byte_order(struct gdbarch *gdbarch)
CORE_ADDR gdbarch_skip_trampoline_code(struct gdbarch *gdbarch, frame_info_ptr frame, CORE_ADDR pc)
CORE_ADDR gdbarch_fetch_pointer_argument(struct gdbarch *gdbarch, frame_info_ptr frame, int argi, struct type *type)
struct type * lookup_pointer_type(struct type *type)
const struct builtin_type * builtin_type(struct gdbarch *gdbarch)
mach_port_t kern_return_t mach_port_t mach_msg_type_name_t msgportsPoly mach_port_t kern_return_t pid_t pid mach_port_t kern_return_t mach_port_t task mach_port_t kern_return_t int flags
struct value * call_function_by_hand(struct value *function, type *default_return_type, gdb::array_view< value * > args)
CORE_ADDR minimal_symbol_upper_bound(struct bound_minimal_symbol minsym)
struct bound_minimal_symbol lookup_minimal_symbol(const char *name, const char *sfile, struct objfile *objf)
struct bound_minimal_symbol lookup_bound_minimal_symbol(const char *name)
std::unique_ptr< operation > operation_up
void _initialize_objc_language()
static void print_object_command(const char *args, int from_tty)
struct symbol * lookup_struct_typedef(const char *name, const struct block *block, int noerr)
static void find_methods(char type, const char *theclass, const char *category, const char *selector, std::vector< const char * > *symbol_names)
struct value * value_nsstring(struct gdbarch *gdbarch, const char *ptr, int len)
static void read_objc_methlist_method(struct gdbarch *gdbarch, CORE_ADDR addr, unsigned long num, struct objc_method *method)
static int resolve_msgsend(CORE_ADDR pc, CORE_ADDR *new_pc)
const char * find_imps(const char *method, std::vector< const char * > *symbol_names)
static int compare_classes(const void *a, const void *b)
static objc_language objc_language_defn
static char * msglist_sel
static void read_objc_method(struct gdbarch *gdbarch, CORE_ADDR addr, struct objc_method *method)
CORE_ADDR lookup_child_selector(struct gdbarch *gdbarch, const char *selname)
static const registry< objfile >::key< unsigned int > objc_objfile_data
static void info_selectors_command(const char *regexp, int from_tty)
static void read_objc_class(struct gdbarch *gdbarch, CORE_ADDR addr, struct objc_class *theclass)
static int resolve_msgsend_super_stret(CORE_ADDR pc, CORE_ADDR *new_pc)
static int find_objc_msgcall_submethod(int(*f)(CORE_ADDR, CORE_ADDR *), CORE_ADDR pc, CORE_ADDR *new_pc)
static struct objc_methcall methcalls[]
static void uniquify_strings(std::vector< const char * > *strings)
static int resolve_msgsend_super(CORE_ADDR pc, CORE_ADDR *new_pc)
static CORE_ADDR find_implementation_from_class(struct gdbarch *gdbarch, CORE_ADDR theclass, CORE_ADDR sel)
int end_msglist(struct parser_state *ps)
static void find_objc_msgsend(void)
static char * parse_method(char *method, char *type, char **theclass, char **category, char **selector)
int find_objc_msgcall(CORE_ADDR pc, CORE_ADDR *new_pc)
static int specialcmp(const char *a, const char *b)
static int compare_selectors(const void *a, const void *b)
CORE_ADDR lookup_objc_class(struct gdbarch *gdbarch, const char *classname)
static struct selname * selname_chain
static unsigned long read_objc_methlist_nmethods(struct gdbarch *gdbarch, CORE_ADDR addr)
static void read_objc_super(struct gdbarch *gdbarch, CORE_ADDR addr, struct objc_super *super)
static CORE_ADDR find_implementation(struct gdbarch *gdbarch, CORE_ADDR object, CORE_ADDR sel)
static char * parse_selector(char *method, char **selector)
static void info_classes_command(const char *regexp, int from_tty)
void add_msglist(struct stoken *str, int addcolon)
static int resolve_msgsend_stret(CORE_ADDR pc, CORE_ADDR *new_pc)
static void read_objc_object(struct gdbarch *gdbarch, CORE_ADDR addr, struct objc_object *object)
struct program_space * current_program_space
void(* func)(remote_target *remote, char *)
struct minimal_symbol * minsym
struct type * builtin_func_ptr
struct type * builtin_long
struct type * builtin_data_ptr
struct type * builtin_char
struct gdbarch * gdbarch()
const char * natural_name() const
enum language la_language
int(* stop_at)(CORE_ADDR, CORE_ADDR *)
msymbols_range msymbols()
void push_new(Arg... args)
std::vector< expr::operation_up > pop_vector(int n)
objfiles_range objfiles()
address_class aclass() const
struct type * type() const
bool matches(domain_enum d) const
void deprecated_set_type(struct type *type)
struct block_symbol lookup_symbol(const char *name, const struct block *block, domain_enum domain, struct field_of_this_result *is_a_field_of_this)
bool target_has_execution(inferior *inf)
void gdb_printf(struct ui_file *stream, const char *format,...)
void puts_tabular(char *string, int width, int right)
struct value * value_coerce_array(struct value *arg1)
struct value * find_function_in_inferior(const char *name, struct objfile **objf_p)
struct value * value_string(const gdb_byte *ptr, ssize_t count, struct type *char_type)
struct value * value_from_longest(struct type *type, LONGEST num)
LONGEST value_as_long(struct value *val)