From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 65206 invoked by alias); 22 Sep 2015 18:38:29 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 65196 invoked by uid 89); 22 Sep 2015 18:38:29 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=0.4 required=5.0 tests=AWL,BAYES_00,KAM_LAZY_DOMAIN_SECURITY,RCVD_IN_DNSWL_LOW autolearn=no version=3.3.2 X-HELO: smtp-out4.electric.net Received: from smtp-out4.electric.net (HELO smtp-out4.electric.net) (192.162.216.182) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Tue, 22 Sep 2015 18:38:26 +0000 Received: from 1ZeSSL-00013G-UT by out4a.electric.net with emc1-ok (Exim 4.85) (envelope-from ) id 1ZeSSM-00014J-Tg; Tue, 22 Sep 2015 11:38:22 -0700 Received: by emcmailer; Tue, 22 Sep 2015 11:38:22 -0700 Received: from [188.39.184.227] (helo=GLAEXCH3.ftdi.local) by out4a.electric.net with esmtps (TLSv1:AES128-SHA:128) (Exim 4.85) (envelope-from ) id 1ZeSSL-00013G-UT; Tue, 22 Sep 2015 11:38:21 -0700 Received: from GLAEXCH1.ftdi.local ([172.16.0.121]) by glaexch3 ([172.16.0.161]) with mapi id 14.01.0438.000; Tue, 22 Sep 2015 19:37:22 +0100 From: James Bowman To: Yao Qi CC: "gdb-patches@sourceware.org" Subject: RE: [PATCH, FT32] Proper support for address <-> pointer conversions Date: Tue, 22 Sep 2015 18:38:00 -0000 Message-ID: References: ,<86wpvi9zst.fsf@gmail.com> In-Reply-To: <86wpvi9zst.fsf@gmail.com> Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-Outbound-IP: 188.39.184.227 X-Env-From: james.bowman@ftdichip.com X-PolicySMART: 3094660 X-SW-Source: 2015-09/txt/msg00537.txt.bz2 Thanks for the review. Corrected Changelog/patch is below. However I was not sure about splitting -- these changes all seem to go together. That is, applying just some of the patch results in a non-functioning gdb. 2015-09-22 James Bowman * ft32-tdep.c: Implement the pointer to address method so that FT32's address spaces (RAM and flash) work correctly when dereferencing pointers in gdb. Also make PC a flash pointer. * ft32-tdep.h: Add a type for an address space 1 pointer, for the PC. diff --git a/gdb/ft32-tdep.c b/gdb/ft32-tdep.c index 2e5deca..7c6efbb 100644 --- a/gdb/ft32-tdep.c +++ b/gdb/ft32-tdep.c @@ -117,7 +117,7 @@ static struct type * ft32_register_type (struct gdbarch *gdbarch, int reg_nr) { if (reg_nr =3D=3D FT32_PC_REGNUM) - return builtin_type (gdbarch)->builtin_func_ptr; + return gdbarch_tdep (gdbarch)->pc_type; else if (reg_nr =3D=3D FT32_SP_REGNUM || reg_nr =3D=3D FT32_FP_REGNUM) return builtin_type (gdbarch)->builtin_data_ptr; else @@ -270,6 +270,73 @@ ft32_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR= pc) return pc; } =20 +/* Implementation of `pointer_to_address' gdbarch method. + + On FT32 address space zero is RAM, address space 1 is flash. + RAM appears at address RAM_BIAS, flash at address 0. */ + +static CORE_ADDR +ft32_pointer_to_address (struct gdbarch *gdbarch, + struct type *type, const gdb_byte *buf) +{ + enum bfd_endian byte_order =3D gdbarch_byte_order (gdbarch); + CORE_ADDR addr + =3D extract_unsigned_integer (buf, TYPE_LENGTH (type), byte_order); + + if (TYPE_ADDRESS_CLASS_1 (type)) + return addr; + else + return addr | RAM_BIAS; +} + +/* Implementation of `address_class_type_flags' gdbarch method. + + This method maps DW_AT_address_class attributes to a + type_instance_flag_value. */ + +static int +ft32_address_class_type_flags (int byte_size, int dwarf2_addr_class) +{ + /* The value 1 of the DW_AT_address_class attribute corresponds to the + __flash__ qualifier, meaning pointer to data in FT32 program memory. + */ + if (dwarf2_addr_class =3D=3D 1) + return TYPE_INSTANCE_FLAG_ADDRESS_CLASS_1; + return 0; +} + +/* Implementation of `address_class_type_flags_to_name' gdbarch method. + + Convert a type_instance_flag_value to an address space qualifier. */ + +static const char* +ft32_address_class_type_flags_to_name (struct gdbarch *gdbarch, int type_f= lags) +{ + if (type_flags & TYPE_INSTANCE_FLAG_ADDRESS_CLASS_1) + return "flash"; + else + return NULL; +} + +/* Implementation of `address_class_name_to_type_flags' gdbarch method. + + Convert an address space qualifier to a type_instance_flag_value. */ + +static int +ft32_address_class_name_to_type_flags (struct gdbarch *gdbarch, + const char* name, + int *type_flags_ptr) +{ + if (strcmp (name, "flash") =3D=3D 0) + { + *type_flags_ptr =3D TYPE_INSTANCE_FLAG_ADDRESS_CLASS_1; + return 1; + } + else + return 0; +} + + /* Implement the "read_pc" gdbarch method. */ =20 static CORE_ADDR @@ -488,6 +555,8 @@ ft32_gdbarch_init (struct gdbarch_info info, struct gdb= arch_list *arches) { struct gdbarch *gdbarch; struct gdbarch_tdep *tdep; + struct type *void_type; + struct type *func_void_type; =20 /* If there is already a candidate, use it. */ arches =3D gdbarch_list_lookup_by_info (arches, &info); @@ -498,6 +567,15 @@ ft32_gdbarch_init (struct gdbarch_info info, struct gd= barch_list *arches) tdep =3D XNEW (struct gdbarch_tdep); gdbarch =3D gdbarch_alloc (&info, tdep); =20 + /* Create a type for PC. We can't use builtin types here, as they may n= ot + be defined. */ + void_type =3D arch_type (gdbarch, TYPE_CODE_VOID, 1, "void"); + func_void_type =3D make_function_type (void_type, NULL); + tdep->pc_type =3D arch_type (gdbarch, TYPE_CODE_PTR, 4, NULL); + TYPE_TARGET_TYPE (tdep->pc_type) =3D func_void_type; + TYPE_UNSIGNED (tdep->pc_type) =3D 1; + TYPE_INSTANCE_FLAGS (tdep->pc_type) |=3D TYPE_INSTANCE_FLAG_ADDRESS_CLAS= S_1; + set_gdbarch_read_pc (gdbarch, ft32_read_pc); set_gdbarch_write_pc (gdbarch, ft32_write_pc); set_gdbarch_unwind_sp (gdbarch, ft32_unwind_sp); @@ -510,6 +588,8 @@ ft32_gdbarch_init (struct gdbarch_info info, struct gdb= arch_list *arches) =20 set_gdbarch_return_value (gdbarch, ft32_return_value); =20 + set_gdbarch_pointer_to_address (gdbarch, ft32_pointer_to_address); + set_gdbarch_skip_prologue (gdbarch, ft32_skip_prologue); set_gdbarch_inner_than (gdbarch, core_addr_lessthan); set_gdbarch_breakpoint_from_pc (gdbarch, ft32_breakpoint_from_pc); @@ -535,6 +615,12 @@ ft32_gdbarch_init (struct gdbarch_info info, struct gd= barch_list *arches) /* Support simple overlay manager. */ set_gdbarch_overlay_update (gdbarch, simple_overlay_update); =20 + set_gdbarch_address_class_type_flags (gdbarch, ft32_address_class_type_f= lags); + set_gdbarch_address_class_name_to_type_flags + (gdbarch, ft32_address_class_name_to_type_flags); + set_gdbarch_address_class_type_flags_to_name + (gdbarch, ft32_address_class_type_flags_to_name); + return gdbarch; } =20 diff --git a/gdb/ft32-tdep.h b/gdb/ft32-tdep.h index 5c52480..ba747b0 100644 --- a/gdb/ft32-tdep.h +++ b/gdb/ft32-tdep.h @@ -22,7 +22,8 @@ =20 struct gdbarch_tdep { - /* gdbarch target dependent data here. Currently unused for FT32. */ + /* Type for a pointer to a function. Used for the type of PC. */ + struct type *pc_type; }; =20 #endif /* FT32_TDEP_H */