This is the mail archive of the
gdb-patches@sources.redhat.com
mailing list for the GDB project.
[RFA]: gdbarch FETCH_POINTER_ARGUMENT
- From: Adam Fedor <fedor at doc dot com>
- To: GDB Patches <gdb-patches at sources dot redhat dot com>
- Cc: Daniel Jacobowitz <drow at mvista dot com>
- Date: Sun, 18 May 2003 21:12:26 -0600
- Subject: [RFA]: gdbarch FETCH_POINTER_ARGUMENT
This patch added some arch-specific macros that aid in getting function
forwarding information, namely a macro to get the arguments in a
function. Hopefully someone can figure out a good way to test it...
2003-05-18 Adam Fedor <fedor@gnu.org>
* gdbarch.sh (function_list): Add FETCH_POINTER_ARGUMENT,
CONVERT_FUNCTION_POINTER.
* gdbarch.[ch]: Regenerate.
* arch-utils.c (default_convert_function_pointer): New function.
* arch-utils.h (default_convert_function_pointer): Add definition.
* hppa-tdep.c (hppa_fetch_pointer_argument,
hppa_convert_function_pointer): New functions.
(hppa_gdbarch_init): Set them in the gdbarch vector.
* i386-tdep.c (i386_fetch_pointer_argument): New
(i386_gdbarch_init): Set it into gdbarch.
* rs6000-tdep.c (rs6000_fetch_pointer_argument): New.
(rs6000_gdbarch_init): Set it in gdbarch.
* sparc-tdep.c (sparc_fetch_pointer_argument): New
(sparc_gdbarch_init): Set it in gdbarch.
* objc-lang.c (FETCH_ARGUMENT, CONVERT_FUNCPTRE): Remove.
(read_objc_method, resolve_msgsend, resolve_msgsend_stret,
resolve_msgsend_super, resolve_msgsend_super_stret): Rename macros
to FETCH_POINTER_ARGUMENT, CONVERT_FUNCTION_POINTER.
Index: arch-utils.c
===================================================================
RCS file: /cvs/src/src/gdb/arch-utils.c,v
retrieving revision 1.83
diff -u -p -r1.83 arch-utils.c
--- arch-utils.c 15 May 2003 22:58:36 -0000 1.83
+++ arch-utils.c 19 May 2003 02:28:33 -0000
@@ -362,6 +362,12 @@ default_coff_make_msymbol_special (int v
return;
}
+CORE_ADDR
+default_convert_function_pointer (CORE_ADDR pc)
+{
+ return pc;
+}
+
int
cannot_register_not (int regnum)
{
Index: arch-utils.h
===================================================================
RCS file: /cvs/src/src/gdb/arch-utils.h,v
retrieving revision 1.46
diff -u -p -r1.46 arch-utils.h
--- arch-utils.h 15 May 2003 22:58:36 -0000 1.46
+++ arch-utils.h 19 May 2003 02:28:33 -0000
@@ -130,6 +130,9 @@ void default_elf_make_msymbol_special (a
void default_coff_make_msymbol_special (int val, struct minimal_symbol *msym);
+/* Default convert_function_pointer */
+CORE_ADDR default_convert_function_pointer (CORE_ADDR pc);
+
/* Version of cannot_fetch_register() / cannot_store_register() that
always fails. */
Index: gdbarch.c
===================================================================
RCS file: /cvs/src/src/gdb/gdbarch.c,v
retrieving revision 1.216
diff -u -p -r1.216 gdbarch.c
--- gdbarch.c 17 May 2003 05:59:58 -0000 1.216
+++ gdbarch.c 19 May 2003 02:28:52 -0000
@@ -280,6 +280,8 @@ struct gdbarch
gdbarch_address_class_type_flags_to_name_ftype *address_class_type_flags_to_name;
gdbarch_address_class_name_to_type_flags_ftype *address_class_name_to_type_flags;
gdbarch_register_reggroup_p_ftype *register_reggroup_p;
+ gdbarch_fetch_pointer_argument_ftype *fetch_pointer_argument;
+ gdbarch_convert_function_pointer_ftype *convert_function_pointer;
};
@@ -446,6 +448,8 @@ struct gdbarch startup_gdbarch =
0,
0,
default_register_reggroup_p,
+ 0,
+ 0,
/* startup_gdbarch() */
};
@@ -564,6 +568,7 @@ gdbarch_alloc (const struct gdbarch_info
current_gdbarch->coff_make_msymbol_special = default_coff_make_msymbol_special;
current_gdbarch->name_of_malloc = "malloc";
current_gdbarch->register_reggroup_p = default_register_reggroup_p;
+ current_gdbarch->convert_function_pointer = default_convert_function_pointer;
/* gdbarch_alloc() */
return current_gdbarch;
@@ -762,6 +767,9 @@ verify_gdbarch (struct gdbarch *gdbarch)
/* Skip verify of address_class_type_flags_to_name, has predicate */
/* Skip verify of address_class_name_to_type_flags, has predicate */
/* Skip verify of register_reggroup_p, invalid_p == 0 */
+ if ((GDB_MULTI_ARCH > GDB_MULTI_ARCH_PARTIAL)
+ && (gdbarch->convert_function_pointer == default_convert_function_pointer))
+ fprintf_unfiltered (log, "\n\tconvert_function_pointer");
buf = ui_file_xstrdup (log, &dummy);
make_cleanup (xfree, buf);
if (strlen (buf) > 0)
@@ -984,6 +992,17 @@ gdbarch_dump (struct gdbarch *gdbarch, s
(long) current_gdbarch->convert_from_func_ptr_addr
/*CONVERT_FROM_FUNC_PTR_ADDR ()*/);
#endif
+#ifdef CONVERT_FUNCTION_POINTER
+ fprintf_unfiltered (file,
+ "gdbarch_dump: %s # %s\n",
+ "CONVERT_FUNCTION_POINTER(pc)",
+ XSTRING (CONVERT_FUNCTION_POINTER (pc)));
+ if (GDB_MULTI_ARCH)
+ fprintf_unfiltered (file,
+ "gdbarch_dump: CONVERT_FUNCTION_POINTER = <0x%08lx>\n",
+ (long) current_gdbarch->convert_function_pointer
+ /*CONVERT_FUNCTION_POINTER ()*/);
+#endif
#ifdef CONVERT_REGISTER_P
fprintf_unfiltered (file,
"gdbarch_dump: %s # %s\n",
@@ -1693,6 +1712,17 @@ gdbarch_dump (struct gdbarch *gdbarch, s
(long) current_gdbarch->extract_struct_value_address
/*EXTRACT_STRUCT_VALUE_ADDRESS ()*/);
#endif
+#ifdef FETCH_POINTER_ARGUMENT
+ fprintf_unfiltered (file,
+ "gdbarch_dump: %s # %s\n",
+ "FETCH_POINTER_ARGUMENT(i)",
+ XSTRING (FETCH_POINTER_ARGUMENT (i)));
+ if (GDB_MULTI_ARCH)
+ fprintf_unfiltered (file,
+ "gdbarch_dump: FETCH_POINTER_ARGUMENT = <0x%08lx>\n",
+ (long) current_gdbarch->fetch_pointer_argument
+ /*FETCH_POINTER_ARGUMENT ()*/);
+#endif
#ifdef FP0_REGNUM
fprintf_unfiltered (file,
"gdbarch_dump: FP0_REGNUM # %s\n",
@@ -5689,6 +5719,44 @@ set_gdbarch_register_reggroup_p (struct
gdbarch_register_reggroup_p_ftype register_reggroup_p)
{
gdbarch->register_reggroup_p = register_reggroup_p;
+}
+
+unsigned long
+gdbarch_fetch_pointer_argument (struct gdbarch *gdbarch, int i)
+{
+ gdb_assert (gdbarch != NULL);
+ if (gdbarch->fetch_pointer_argument == 0)
+ internal_error (__FILE__, __LINE__,
+ "gdbarch: gdbarch_fetch_pointer_argument invalid");
+ if (gdbarch_debug >= 2)
+ fprintf_unfiltered (gdb_stdlog, "gdbarch_fetch_pointer_argument called\n");
+ return gdbarch->fetch_pointer_argument (i);
+}
+
+void
+set_gdbarch_fetch_pointer_argument (struct gdbarch *gdbarch,
+ gdbarch_fetch_pointer_argument_ftype fetch_pointer_argument)
+{
+ gdbarch->fetch_pointer_argument = fetch_pointer_argument;
+}
+
+CORE_ADDR
+gdbarch_convert_function_pointer (struct gdbarch *gdbarch, CORE_ADDR pc)
+{
+ gdb_assert (gdbarch != NULL);
+ if (gdbarch->convert_function_pointer == 0)
+ internal_error (__FILE__, __LINE__,
+ "gdbarch: gdbarch_convert_function_pointer invalid");
+ if (gdbarch_debug >= 2)
+ fprintf_unfiltered (gdb_stdlog, "gdbarch_convert_function_pointer called\n");
+ return gdbarch->convert_function_pointer (pc);
+}
+
+void
+set_gdbarch_convert_function_pointer (struct gdbarch *gdbarch,
+ gdbarch_convert_function_pointer_ftype convert_function_pointer)
+{
+ gdbarch->convert_function_pointer = convert_function_pointer;
}
Index: gdbarch.h
===================================================================
RCS file: /cvs/src/src/gdb/gdbarch.h,v
retrieving revision 1.185
diff -u -p -r1.185 gdbarch.h
--- gdbarch.h 17 May 2003 05:59:58 -0000 1.185
+++ gdbarch.h 19 May 2003 02:28:57 -0000
@@ -3184,6 +3184,34 @@ typedef int (gdbarch_register_reggroup_p
extern int gdbarch_register_reggroup_p (struct gdbarch *gdbarch, int regnum, struct reggroup *reggroup);
extern void set_gdbarch_register_reggroup_p (struct gdbarch *gdbarch, gdbarch_register_reggroup_p_ftype *register_reggroup_p);
+/* Fetch the pointer to the ith function argument. */
+
+typedef unsigned long (gdbarch_fetch_pointer_argument_ftype) (int i);
+extern unsigned long gdbarch_fetch_pointer_argument (struct gdbarch *gdbarch, int i);
+extern void set_gdbarch_fetch_pointer_argument (struct gdbarch *gdbarch, gdbarch_fetch_pointer_argument_ftype *fetch_pointer_argument);
+#if (GDB_MULTI_ARCH > GDB_MULTI_ARCH_PARTIAL) && defined (FETCH_POINTER_ARGUMENT)
+#error "Non multi-arch definition of FETCH_POINTER_ARGUMENT"
+#endif
+#if GDB_MULTI_ARCH
+#if (GDB_MULTI_ARCH > GDB_MULTI_ARCH_PARTIAL) || !defined (FETCH_POINTER_ARGUMENT)
+#define FETCH_POINTER_ARGUMENT(i) (gdbarch_fetch_pointer_argument (current_gdbarch, i))
+#endif
+#endif
+
+/* Get the real address of the function. */
+
+typedef CORE_ADDR (gdbarch_convert_function_pointer_ftype) (CORE_ADDR pc);
+extern CORE_ADDR gdbarch_convert_function_pointer (struct gdbarch *gdbarch, CORE_ADDR pc);
+extern void set_gdbarch_convert_function_pointer (struct gdbarch *gdbarch, gdbarch_convert_function_pointer_ftype *convert_function_pointer);
+#if (GDB_MULTI_ARCH > GDB_MULTI_ARCH_PARTIAL) && defined (CONVERT_FUNCTION_POINTER)
+#error "Non multi-arch definition of CONVERT_FUNCTION_POINTER"
+#endif
+#if GDB_MULTI_ARCH
+#if (GDB_MULTI_ARCH > GDB_MULTI_ARCH_PARTIAL) || !defined (CONVERT_FUNCTION_POINTER)
+#define CONVERT_FUNCTION_POINTER(pc) (gdbarch_convert_function_pointer (current_gdbarch, pc))
+#endif
+#endif
+
extern struct gdbarch_tdep *gdbarch_tdep (struct gdbarch *gdbarch);
Index: gdbarch.sh
===================================================================
RCS file: /cvs/src/src/gdb/gdbarch.sh,v
retrieving revision 1.237
diff -u -p -r1.237 gdbarch.sh
--- gdbarch.sh 17 May 2003 05:59:58 -0000 1.237
+++ gdbarch.sh 19 May 2003 02:28:58 -0000
@@ -716,6 +716,10 @@ M:2:ADDRESS_CLASS_TYPE_FLAGS_TO_NAME:con
M:2:ADDRESS_CLASS_NAME_TO_TYPE_FLAGS:int:address_class_name_to_type_flags:const char *name, int *type_flags_ptr:name, type_flags_ptr
# Is a register in a group
m:::int:register_reggroup_p:int regnum, struct reggroup *reggroup:regnum, reggroup:::default_register_reggroup_p::0
+# Fetch the pointer to the ith function argument.
+f::FETCH_POINTER_ARGUMENT:unsigned long:fetch_pointer_argument:int i:i:::::::::
+# Get the real address of the function.
+f::CONVERT_FUNCTION_POINTER:CORE_ADDR:convert_function_pointer:CORE_ADDR pc:pc:::default_convert_function_pointer::::::
EOF
}
Index: hppa-tdep.c
===================================================================
RCS file: /cvs/src/src/gdb/hppa-tdep.c,v
retrieving revision 1.78
diff -u -p -r1.78 hppa-tdep.c
--- hppa-tdep.c 17 May 2003 05:59:58 -0000 1.78
+++ hppa-tdep.c 19 May 2003 02:29:02 -0000
@@ -4962,6 +4962,22 @@ hppa_smash_text_address (CORE_ADDR addr)
return (addr &= ~0x3);
}
+/* Get the ith function argument for the current function. */
+unsigned long
+hppa_fetch_pointer_argument (int i)
+{
+ return read_register (R0_REGNUM + 26 - i);
+}
+
+CORE_ADDR
+hppa_convert_function_pointer (CORE_ADDR pc)
+{
+ if (pc & 0x2)
+ pc = (CORE_ADDR) read_memory_integer (pc & ~0x3, 4);
+
+ return pc;
+}
+
static struct gdbarch *
hppa_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
{
@@ -5040,6 +5056,9 @@ hppa_gdbarch_init (struct gdbarch_info i
set_gdbarch_write_pc (gdbarch, hppa_target_write_pc);
set_gdbarch_deprecated_target_read_fp (gdbarch, hppa_target_read_fp);
+ /* Helpers for function argument information. */
+ set_gdbarch_fetch_pointer_argument (gdbarch, hppa_fetch_pointer_argument);
+ set_gdbarch_convert_function_pointer (gdbarch, hppa_convert_function_pointer);
return gdbarch;
}
Index: i386-tdep.c
===================================================================
RCS file: /cvs/src/src/gdb/i386-tdep.c,v
retrieving revision 1.144
diff -u -p -r1.144 i386-tdep.c
--- i386-tdep.c 17 May 2003 05:59:58 -0000 1.144
+++ i386-tdep.c 19 May 2003 02:29:07 -0000
@@ -1420,6 +1420,14 @@ i386_register_reggroup_p (struct gdbarch
return default_register_reggroup_p (gdbarch, regnum, group);
}
+/* Get the ith function argument for the current function. */
+unsigned long
+i386_fetch_pointer_argument (int i)
+{
+ CORE_ADDR stack = read_register (SP_REGNUM);
+ return read_memory_unsigned_integer (stack + (4 * (i + 1)), 4);
+}
+
static struct gdbarch *
i386_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
@@ -1551,6 +1559,9 @@ i386_gdbarch_init (struct gdbarch_info i
/* Add the i386 register groups. */
i386_add_reggroups (gdbarch);
set_gdbarch_register_reggroup_p (gdbarch, i386_register_reggroup_p);
+
+ /* Helper for function argument information. */
+ set_gdbarch_fetch_pointer_argument (gdbarch, i386_fetch_pointer_argument);
/* Should be using push_dummy_call. */
set_gdbarch_deprecated_dummy_write_sp (gdbarch, generic_target_write_sp);
Index: objc-lang.c
===================================================================
RCS file: /cvs/src/src/gdb/objc-lang.c,v
retrieving revision 1.22
diff -u -p -r1.22 objc-lang.c
--- objc-lang.c 15 May 2003 22:18:42 -0000 1.22
+++ objc-lang.c 19 May 2003 02:29:08 -0000
@@ -1752,60 +1752,6 @@ _initialize_objc_language (void)
add_com_alias ("po", "print-object", class_vars, 1);
}
-#if 1
-/* Disable these functions until we put them in the gdbarch vector. */
-static unsigned long FETCH_ARGUMENT (int i)
-{
- internal_error (__FILE__, __LINE__, "FETCH_ARGUMENT not implemented");
- return 0;
-}
-static CORE_ADDR CONVERT_FUNCPTR (CORE_ADDR pc)
-{
- internal_error (__FILE__, __LINE__, "CONVERT_FUNCPTR not implemented");
- return pc;
-}
-#else
-#if defined (__powerpc__) || defined (__ppc__)
-static unsigned long FETCH_ARGUMENT (int i)
-{
- return read_register (3 + i);
-}
-#elif defined (__i386__)
-static unsigned long FETCH_ARGUMENT (int i)
-{
- CORE_ADDR stack = read_register (SP_REGNUM);
- return read_memory_unsigned_integer (stack + (4 * (i + 1)), 4);
-}
-#elif defined (__sparc__)
-static unsigned long FETCH_ARGUMENT (int i)
-{
- return read_register (O0_REGNUM + i);
-}
-#elif defined (__hppa__) || defined (__hppa)
-static unsigned long FETCH_ARGUMENT (int i)
-{
- return read_register (R0_REGNUM + 26 - i);
-}
-#else
-#error unknown architecture
-#endif
-
-#if defined (__hppa__) || defined (__hppa)
-static CORE_ADDR CONVERT_FUNCPTR (CORE_ADDR pc)
-{
- if (pc & 0x2)
- pc = (CORE_ADDR) read_memory_integer (pc & ~0x3, 4);
-
- return pc;
-}
-#else
-static CORE_ADDR CONVERT_FUNCPTR (CORE_ADDR pc)
-{
- return pc;
-}
-#endif
-#endif
-
static void
read_objc_method (CORE_ADDR addr, struct objc_method *method)
{
@@ -1894,7 +1840,7 @@ find_implementation_from_class (CORE_ADD
#endif
if (meth_str.name == sel)
- return CONVERT_FUNCPTR (meth_str.imp);
+ return CONVERT_FUNCTION_POINTER (meth_str.imp);
}
mlistnum++;
}
@@ -1925,8 +1871,8 @@ resolve_msgsend (CORE_ADDR pc, CORE_ADDR
CORE_ADDR sel;
CORE_ADDR res;
- object = FETCH_ARGUMENT (0);
- sel = FETCH_ARGUMENT (1);
+ object = FETCH_POINTER_ARGUMENT (0);
+ sel = FETCH_POINTER_ARGUMENT (1);
res = find_implementation (object, sel);
if (new_pc != 0)
@@ -1943,8 +1889,8 @@ resolve_msgsend_stret (CORE_ADDR pc, COR
CORE_ADDR sel;
CORE_ADDR res;
- object = FETCH_ARGUMENT (1);
- sel = FETCH_ARGUMENT (2);
+ object = FETCH_POINTER_ARGUMENT (1);
+ sel = FETCH_POINTER_ARGUMENT (2);
res = find_implementation (object, sel);
if (new_pc != 0)
@@ -1963,8 +1909,8 @@ resolve_msgsend_super (CORE_ADDR pc, COR
CORE_ADDR sel;
CORE_ADDR res;
- super = FETCH_ARGUMENT (0);
- sel = FETCH_ARGUMENT (1);
+ super = FETCH_POINTER_ARGUMENT (0);
+ sel = FETCH_POINTER_ARGUMENT (1);
read_objc_super (super, &sstr);
if (sstr.class == 0)
@@ -1987,8 +1933,8 @@ resolve_msgsend_super_stret (CORE_ADDR p
CORE_ADDR sel;
CORE_ADDR res;
- super = FETCH_ARGUMENT (1);
- sel = FETCH_ARGUMENT (2);
+ super = FETCH_POINTER_ARGUMENT (1);
+ sel = FETCH_POINTER_ARGUMENT (2);
read_objc_super (super, &sstr);
if (sstr.class == 0)
Index: rs6000-tdep.c
===================================================================
RCS file: /cvs/src/src/gdb/rs6000-tdep.c,v
retrieving revision 1.134
diff -u -p -r1.134 rs6000-tdep.c
--- rs6000-tdep.c 17 May 2003 05:59:58 -0000 1.134
+++ rs6000-tdep.c 19 May 2003 02:29:10 -0000
@@ -230,6 +230,13 @@ rs6000_saved_pc_after_call (struct frame
return read_register (gdbarch_tdep (current_gdbarch)->ppc_lr_regnum);
}
+/* Get the ith function argument for the current function. */
+unsigned long
+rs6000_fetch_pointer_argument (int i)
+{
+ return read_register (3 + i);
+}
+
/* Calculate the destination of a branch/jump. Return -1 if not a branch. */
static CORE_ADDR
@@ -2957,6 +2964,9 @@ rs6000_gdbarch_init (struct gdbarch_info
set_gdbarch_frame_args_address (gdbarch, rs6000_frame_args_address);
set_gdbarch_frame_locals_address (gdbarch, rs6000_frame_args_address);
set_gdbarch_deprecated_saved_pc_after_call (gdbarch, rs6000_saved_pc_after_call);
+
+ /* Helpers for function argument information. */
+ set_gdbarch_fetch_pointer_argument (gdbarch, rs6000_fetch_pointer_argument);
/* We can't tell how many args there are
now that the C compiler delays popping them. */
Index: sparc-tdep.c
===================================================================
RCS file: /cvs/src/src/gdb/sparc-tdep.c,v
retrieving revision 1.101
diff -u -p -r1.101 sparc-tdep.c
--- sparc-tdep.c 17 May 2003 05:59:59 -0000 1.101
+++ sparc-tdep.c 19 May 2003 02:29:11 -0000
@@ -3092,6 +3092,13 @@ sparc_return_value_on_stack (struct type
return 0;
}
+/* Get the ith function argument for the current function. */
+unsigned long
+sparc_fetch_pointer_argument (int i)
+{
+ return read_register (O0_REGNUM + i);
+}
+
/*
* Gdbarch "constructor" function.
*/
@@ -3201,6 +3208,9 @@ sparc_gdbarch_init (struct gdbarch_info
set_gdbarch_sp_regnum (gdbarch, SPARC_SP_REGNUM);
set_gdbarch_deprecated_use_generic_dummy_frames (gdbarch, 0);
set_gdbarch_write_pc (gdbarch, generic_target_write_pc);
+
+ /* Helper for function argument information. */
+ set_gdbarch_fetch_pointer_argument (gdbarch, sparc_fetch_pointer_argument);
/*
* Settings that depend only on 32/64 bit word size