* RFA: Add builtin void (*) () type
@ 2001-07-05 15:34 Jim Blandy
2001-07-05 15:54 ` Andrew Cagney
0 siblings, 1 reply; 2+ messages in thread
From: Jim Blandy @ 2001-07-05 15:34 UTC (permalink / raw)
To: gdb-patches
Having this patch simplifies the D10V fixes. And given ANSI C's rules
about which pointer types are interconvertible, it makes sense to have
generic pointer types for both data and functions.
2001-07-05 Jim Blandy <jimb@redhat.com>
* gdbtypes.h (builtin_type_void_func_ptr): New builtin type.
* gdbtypes.c (builtin_type_void_func_ptr): Define the variable.
(build_gdbtypes): Initialize it.
(_initialize_gdbtypes): Swap it.
Index: gdb/gdbtypes.c
===================================================================
RCS file: /cvs/src/src/gdb/gdbtypes.c,v
retrieving revision 1.21
diff -c -r1.21 gdbtypes.c
*** gdb/gdbtypes.c 2001/04/30 17:09:19 1.21
--- gdb/gdbtypes.c 2001/07/05 22:30:25
***************
*** 74,79 ****
--- 74,80 ----
struct type *builtin_type_v4hi;
struct type *builtin_type_v2si;
struct type *builtin_type_ptr;
+ struct type *builtin_type_void_func_ptr;
struct type *builtin_type_CORE_ADDR;
struct type *builtin_type_bfd_vma;
***************
*** 2928,2937 ****
= init_simd_type ("__builtin_v2si", builtin_type_int32, "f", 2);
/* Pointer/Address types. */
! /* NOTE: At present there is no way of differentiating between at
! target address and the target C language pointer type type even
! though the two can be different (cf d10v) */
builtin_type_ptr = make_pointer_type (builtin_type_void, NULL);
builtin_type_CORE_ADDR =
init_type (TYPE_CODE_INT, TARGET_ADDR_BIT / 8,
TYPE_FLAG_UNSIGNED,
--- 2929,2964 ----
= init_simd_type ("__builtin_v2si", builtin_type_int32, "f", 2);
/* Pointer/Address types. */
!
! /* NOTE: on some targets, addresses and pointers are not necessarily
! the same --- for example, on the D10V, pointers are 16 bits long,
! but addresses are 32 bits long. See doc/gdbint.texinfo,
! ``Pointers Are Not Always Addresses''.
!
! The upshot is:
! - gdb's `struct type' always describes the target's
! representation.
! - gdb's `struct value' objects should always hold values in
! target form.
! - gdb's CORE_ADDR values are addresses in the unified virtual
! address space that the assembler and linker work with. Thus,
! since target_read_memory takes a CORE_ADDR as an argument, it
! can access any memory on the target, even if the processor has
! separate code and data address spaces.
!
! So, for example:
! - If v is a value holding a D10V code pointer, its contents are
! in target form: a big-endian address left-shifted two bits.
! - If p is a D10V pointer type, TYPE_LENGTH (p) == 2, just as
! sizeof (void *) == 2 on the target.
!
! In this context, builtin_type_CORE_ADDR is a bit odd: it's a
! target type for a value the target will never see. It's only
! used to hold the values of (typeless) linker symbols, which are
! indeed in the unified virtual address space. */
builtin_type_ptr = make_pointer_type (builtin_type_void, NULL);
+ builtin_type_void_func_ptr
+ = lookup_pointer_type (lookup_function_type (builtin_type_void));
builtin_type_CORE_ADDR =
init_type (TYPE_CODE_INT, TARGET_ADDR_BIT / 8,
TYPE_FLAG_UNSIGNED,
***************
*** 2985,2990 ****
--- 3012,3018 ----
register_gdbarch_swap (&builtin_type_v4hi, sizeof (struct type *), NULL);
register_gdbarch_swap (&builtin_type_v2si, sizeof (struct type *), NULL);
REGISTER_GDBARCH_SWAP (builtin_type_ptr);
+ REGISTER_GDBARCH_SWAP (builtin_type_void_func_ptr);
REGISTER_GDBARCH_SWAP (builtin_type_CORE_ADDR);
REGISTER_GDBARCH_SWAP (builtin_type_bfd_vma);
register_gdbarch_swap (NULL, 0, build_gdbtypes);
Index: gdb/gdbtypes.h
===================================================================
RCS file: /cvs/src/src/gdb/gdbtypes.h,v
retrieving revision 1.9
diff -c -r1.9 gdbtypes.h
*** gdb/gdbtypes.h 2001/03/27 20:36:23 1.9
--- gdb/gdbtypes.h 2001/07/05 22:30:26
***************
*** 849,854 ****
--- 849,864 ----
/* (C) Language pointer type. Some target platforms use an implicitly
{sign,zero} -extended 32 bit C language pointer on a 64 bit ISA. */
extern struct type *builtin_type_ptr;
+
+ /* (C) Language `pointer to function returning void' type. Since
+ ANSI, C standards have explicitly said that pointers to functions
+ and pointers to data are not interconvertible --- that is, you
+ can't cast a function pointer to void * and back, and expect to get
+ the same value. However, all function pointer types are
+ interconvertible, so void (*) () can server as a generic function
+ pointer. */
+ extern struct type *builtin_type_void_func_ptr;
+
/* The target CPU's address type. This is the ISA address size. */
extern struct type *builtin_type_CORE_ADDR;
/* The symbol table address type. Some object file formats have a 32
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: RFA: Add builtin void (*) () type
2001-07-05 15:34 RFA: Add builtin void (*) () type Jim Blandy
@ 2001-07-05 15:54 ` Andrew Cagney
0 siblings, 0 replies; 2+ messages in thread
From: Andrew Cagney @ 2001-07-05 15:54 UTC (permalink / raw)
To: Jim Blandy; +Cc: gdb-patches
Jim,
I think this is an obvious fix.
People (well at least me :-) have been threatening to add this for
months if not years. The thing that stopped me was figuring out what
the magic call to create the type was.
Do you want to s/builtin_type_ptr/buitlin_type_data_ptr/ as well? If
not, I will.
Andrew
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2001-07-05 15:54 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-07-05 15:34 RFA: Add builtin void (*) () type Jim Blandy
2001-07-05 15:54 ` Andrew Cagney
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox