From patchwork Fri Dec 6 02:00:18 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Weimin Pan X-Patchwork-Id: 36549 Received: (qmail 59451 invoked by alias); 6 Dec 2019 02:00:59 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 58098 invoked by uid 89); 6 Dec 2019 02:00:35 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-20.0 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_HELO_PASS, SPF_PASS, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 spammy=Pan, ctf_id_t, pan X-HELO: userp2120.oracle.com Received: from userp2120.oracle.com (HELO userp2120.oracle.com) (156.151.31.85) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 06 Dec 2019 02:00:32 +0000 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.27/8.16.0.27) with SMTP id xB61x1So196007; Fri, 6 Dec 2019 02:00:26 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id; s=corp-2019-08-05; bh=BJORjEM84FX0gocWznjNTkiiGP1Uvq+8nb9xEBZL4hA=; b=YLxrJbQEPRoYD4536wypk9XTEHpwjxrBdH6tqdKbx98OtTeiqvl2m1EVtfELuPNM5rQH eNk6mWDOxN7PjRDwkMFaEk/jNKyQV+MvY14iITEDViTQjawAjkz5cY/4LWwiKkuu+5lz cxJnL8uwKdoEc1+OH+MQ4YruuOHVBPEiXpIQaCCEl4ncfAHfPiKEDmEDQ7u/v+Kmu7h/ x6et84K+B9o3O5z1VtVle3XvSJnE6FPvx6YeFWRsP9QwfHYZRheqKC8Md4EgaYFKYLkn 7+H6iZqIsZHSK23dWS4SXopd+YxzvQndDpdMzlR7UmYVfeBs/BvbkerJCDbvBorOuYCx Lw== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by userp2120.oracle.com with ESMTP id 2wkh2rrrfv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 06 Dec 2019 02:00:26 +0000 Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.0.27/8.16.0.27) with SMTP id xB61sKHt045217; Fri, 6 Dec 2019 02:00:25 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by userp3030.oracle.com with ESMTP id 2wqbepx797-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 06 Dec 2019 02:00:25 +0000 Received: from abhmp0007.oracle.com (abhmp0007.oracle.com [141.146.116.13]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id xB620OT9007900; Fri, 6 Dec 2019 02:00:24 GMT Received: from localhost.us.oracle.com (/10.211.14.157) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 05 Dec 2019 18:00:24 -0800 From: Weimin Pan To: gdb-patches@sourceware.org Cc: tom@tromey.com Subject: [PATCH v5] gdb: CTF support update Date: Thu, 5 Dec 2019 21:00:18 -0500 Message-Id: <1575597618-20336-1-git-send-email-weimin.pan@oracle.com> This patch addresses Tom Tromey's comments on the CTF reader: * Use the type-safe registry for ctf_file_key; * Drop "typedef" when defining "struct ctf_context"; * Use ANOFFSET with SECT_OFF_TEXT to get the text base address; gdb/ChangeLog +2019-12-05 Weimin Pan + * ctfread.c (ctf_file_key): Change type to objfile_key. + (struct ctf_context): Remove typedef. + (get_objfile_text_range): Use ANOFFSET to get text base. + --- gdb/ChangeLog | 5 ++ gdb/ctfread.c | 145 ++++++++++++++++++++++++++++------------------------------ 2 files changed, 75 insertions(+), 75 deletions(-) static const struct objfile_key ctf_tid_key; -static const struct objfile_data *ctf_file_key; + +struct ctf_fp_info + { + ctf_fp_info (ctf_file_t *cfp) : fp (cfp) {} + ~ctf_fp_info (); + ctf_file_t *fp; +}; + +/* Cleanup function for the ctf_file_key data. */ +ctf_fp_info::~ctf_fp_info () +{ + if (!fp) + return; + + ctf_archive_t *arc = ctf_get_arc (fp); + ctf_file_close (fp); + ctf_close (arc); +} + +static const objfile_key ctf_file_key; /* A CTF context consists of a file pointer and an objfile pointer. */ -typedef struct ctf_context +struct ctf_context { ctf_file_t *fp; struct objfile *of; struct buildsym_compunit *builder; -} ctf_context_t; +}; /* The routines that read and process fields/members of a C struct, union, or enumeration, pass lists of data member fields in an instance of a @@ -111,7 +130,7 @@ struct ctf_field_info std::vector fields; /* Context. */ - ctf_context_t *cur_context; + struct ctf_context *cur_context; /* Parent type. */ struct type *ptype; @@ -132,26 +151,26 @@ static void psymtab_to_symtab (struct partial_symtab *); static int ctf_add_type_cb (ctf_id_t tid, void *arg); -static struct type *read_array_type (ctf_context_t *ccp, ctf_id_t tid); +static struct type *read_array_type (struct ctf_context *cp, ctf_id_t tid); -static struct type *read_pointer_type (ctf_context_t *ccp, ctf_id_t tid, +static struct type *read_pointer_type (struct ctf_context *cp, ctf_id_t tid, ctf_id_t btid); -static struct type *read_structure_type (ctf_context_t *ccp, ctf_id_t tid); +static struct type *read_structure_type (struct ctf_context *cp, ctf_id_t tid); -static struct type *read_enum_type (ctf_context_t *ccp, ctf_id_t tid); +static struct type *read_enum_type (struct ctf_context *cp, ctf_id_t tid); -static struct type *read_typedef_type (ctf_context_t *ccp, ctf_id_t tid, +static struct type *read_typedef_type (struct ctf_context *cp, ctf_id_t tid, ctf_id_t btid, const char *name); -static struct type *read_type_record (ctf_context_t *ccp, ctf_id_t tid); +static struct type *read_type_record (struct ctf_context *cp, ctf_id_t tid); -static void process_structure_type (ctf_context_t *ccp, ctf_id_t tid); +static void process_structure_type (struct ctf_context *cp, ctf_id_t tid); -static void process_struct_members (ctf_context_t *ccp, ctf_id_t tid, +static void process_struct_members (struct ctf_context *cp, ctf_id_t tid, struct type *type); -static struct symbol *new_symbol (ctf_context_t *ccp, struct type *type, +static struct symbol *new_symbol (struct ctf_context *cp, struct type *type, ctf_id_t tid); struct ctf_tid_and_type @@ -323,7 +342,7 @@ ctf_add_member_cb (const char *name, void *arg) { struct ctf_field_info *fip = (struct ctf_field_info *) arg; - ctf_context_t *ccp = fip->cur_context; + struct ctf_context *ccp = fip->cur_context; struct ctf_nextfield new_field; struct field *fp; struct type *t; @@ -366,7 +385,7 @@ ctf_add_enum_member_cb (const char *name, int enum_value, void *arg) struct ctf_field_info *fip = (struct ctf_field_info *) arg; struct ctf_nextfield new_field; struct field *fp; - ctf_context_t *ccp = fip->cur_context; + struct ctf_context *ccp = fip->cur_context; fp = &new_field.field; FIELD_NAME (*fp) = name; @@ -396,7 +415,7 @@ ctf_add_enum_member_cb (const char *name, int enum_value, void *arg) domain from TID's kind, and its type from TYPE. */ static struct symbol * -new_symbol (ctf_context_t *ccp, struct type *type, ctf_id_t tid) +new_symbol (struct ctf_context *ccp, struct type *type, ctf_id_t tid) { struct objfile *objfile = ccp->of; ctf_file_t *fp = ccp->fp; @@ -459,7 +478,7 @@ new_symbol (ctf_context_t *ccp, struct type *type, ctf_id_t tid) and create the symbol for it. */ static struct type * -read_base_type (ctf_context_t *ccp, ctf_id_t tid) +read_base_type (struct ctf_context *ccp, ctf_id_t tid) { struct objfile *of = ccp->of; ctf_file_t *fp = ccp->fp; @@ -538,7 +557,7 @@ read_base_type (ctf_context_t *ccp, ctf_id_t tid) } static void -process_base_type (ctf_context_t *ccp, ctf_id_t tid) +process_base_type (struct ctf_context *ccp, ctf_id_t tid) { struct type *type; @@ -554,7 +573,7 @@ process_base_type (ctf_context_t *ccp, ctf_id_t tid) (assuming the type has a name). */ static struct type * -read_structure_type (ctf_context_t *ccp, ctf_id_t tid) +read_structure_type (struct ctf_context *ccp, ctf_id_t tid) { struct objfile *of = ccp->of; ctf_file_t *fp = ccp->fp; @@ -583,7 +602,7 @@ read_structure_type (ctf_context_t *ccp, ctf_id_t tid) and create the symbol for it. */ static void -process_struct_members (ctf_context_t *ccp, +process_struct_members (struct ctf_context *ccp, ctf_id_t tid, struct type *type) { @@ -601,7 +620,7 @@ process_struct_members (ctf_context_t *ccp, } static void -process_structure_type (ctf_context_t *ccp, ctf_id_t tid) +process_structure_type (struct ctf_context *ccp, ctf_id_t tid) { struct type *type; @@ -612,7 +631,7 @@ process_structure_type (ctf_context_t *ccp, ctf_id_t tid) /* Create a function type for TID and set its return type. */ static struct type * -read_func_kind_type (ctf_context_t *ccp, ctf_id_t tid) +read_func_kind_type (struct ctf_context *ccp, ctf_id_t tid) { struct objfile *of = ccp->of; ctf_file_t *fp = ccp->fp; @@ -638,7 +657,7 @@ read_func_kind_type (ctf_context_t *ccp, ctf_id_t tid) enumeration, and create the symbol for the enumeration type. */ static struct type * -read_enum_type (ctf_context_t *ccp, ctf_id_t tid) +read_enum_type (struct ctf_context *ccp, ctf_id_t tid) { struct objfile *of = ccp->of; ctf_file_t *fp = ccp->fp; @@ -662,7 +681,7 @@ read_enum_type (ctf_context_t *ccp, ctf_id_t tid) } static void -process_enum_type (ctf_context_t *ccp, ctf_id_t tid) +process_enum_type (struct ctf_context *ccp, ctf_id_t tid) { struct type *type; struct ctf_field_info fi; @@ -684,7 +703,7 @@ process_enum_type (ctf_context_t *ccp, ctf_id_t tid) /* Add given cv-qualifiers CNST+VOLTL to the BASE_TYPE of array TID. */ static struct type * -add_array_cv_type (ctf_context_t *ccp, +add_array_cv_type (struct ctf_context *ccp, ctf_id_t tid, struct type *base_type, int cnst, @@ -713,7 +732,7 @@ add_array_cv_type (ctf_context_t *ccp, /* Read all information from a TID of CTF_K_ARRAY. */ static struct type * -read_array_type (ctf_context_t *ccp, ctf_id_t tid) +read_array_type (struct ctf_context *ccp, ctf_id_t tid) { struct objfile *objfile = ccp->of; ctf_file_t *fp = ccp->fp; @@ -755,7 +774,7 @@ read_array_type (ctf_context_t *ccp, ctf_id_t tid) /* Read TID of kind CTF_K_CONST with base type BTID. */ static struct type * -read_const_type (ctf_context_t *ccp, ctf_id_t tid, ctf_id_t btid) +read_const_type (struct ctf_context *ccp, ctf_id_t tid, ctf_id_t btid) { struct objfile *objfile = ccp->of; struct type *base_type, *cv_type; @@ -778,7 +797,7 @@ read_const_type (ctf_context_t *ccp, ctf_id_t tid, ctf_id_t btid) /* Read TID of kind CTF_K_VOLATILE with base type BTID. */ static struct type * -read_volatile_type (ctf_context_t *ccp, ctf_id_t tid, ctf_id_t btid) +read_volatile_type (struct ctf_context *ccp, ctf_id_t tid, ctf_id_t btid) { struct objfile *objfile = ccp->of; ctf_file_t *fp = ccp->fp; @@ -805,7 +824,7 @@ read_volatile_type (ctf_context_t *ccp, ctf_id_t tid, ctf_id_t btid) /* Read TID of kind CTF_K_RESTRICT with base type BTID. */ static struct type * -read_restrict_type (ctf_context_t *ccp, ctf_id_t tid, ctf_id_t btid) +read_restrict_type (struct ctf_context *ccp, ctf_id_t tid, ctf_id_t btid) { struct objfile *objfile = ccp->of; struct type *base_type, *cv_type; @@ -828,7 +847,7 @@ read_restrict_type (ctf_context_t *ccp, ctf_id_t tid, ctf_id_t btid) /* Read TID of kind CTF_K_TYPEDEF with its NAME and base type BTID. */ static struct type * -read_typedef_type (ctf_context_t *ccp, ctf_id_t tid, +read_typedef_type (struct ctf_context *ccp, ctf_id_t tid, ctf_id_t btid, const char *name) { struct objfile *objfile = ccp->of; @@ -850,7 +869,7 @@ read_typedef_type (ctf_context_t *ccp, ctf_id_t tid, /* Read TID of kind CTF_K_POINTER with base type BTID. */ static struct type * -read_pointer_type (ctf_context_t *ccp, ctf_id_t tid, ctf_id_t btid) +read_pointer_type (struct ctf_context *ccp, ctf_id_t tid, ctf_id_t btid) { struct objfile *of = ccp->of; struct type *target_type, *type; @@ -875,7 +894,7 @@ read_pointer_type (ctf_context_t *ccp, ctf_id_t tid, ctf_id_t btid) /* Read information associated with type TID. */ static struct type * -read_type_record (ctf_context_t *ccp, ctf_id_t tid) +read_type_record (struct ctf_context *ccp, ctf_id_t tid) { ctf_file_t *fp = ccp->fp; uint32_t kind; @@ -939,7 +958,7 @@ read_type_record (ctf_context_t *ccp, ctf_id_t tid) static int ctf_add_type_cb (ctf_id_t tid, void *arg) { - ctf_context_t *ccp = (ctf_context_t *) arg; + struct ctf_context *ccp = (struct ctf_context *) arg; struct type *type; uint32_t kind; @@ -1004,7 +1023,7 @@ ctf_add_type_cb (ctf_id_t tid, void *arg) static int ctf_add_var_cb (const char *name, ctf_id_t id, void *arg) { - ctf_context_t *ccp = (ctf_context_t *) arg; + struct ctf_context *ccp = (struct ctf_context *) arg; struct symbol *sym = NULL; struct type *type; uint32_t kind; @@ -1062,7 +1081,7 @@ ctf_add_var_cb (const char *name, ctf_id_t id, void *arg) /* Add an ELF STT_OBJ symbol with index IDX to the symbol table. */ static struct symbol * -add_stt_obj (ctf_context_t *ccp, unsigned long idx) +add_stt_obj (struct ctf_context *ccp, unsigned long idx) { struct symbol *sym; struct type *type; @@ -1083,7 +1102,7 @@ add_stt_obj (ctf_context_t *ccp, unsigned long idx) /* Add an ELF STT_FUNC symbol with index IDX to the symbol table. */ static struct symbol * -add_stt_func (ctf_context_t *ccp, unsigned long idx) +add_stt_func (struct ctf_context *ccp, unsigned long idx) { struct type *ftype, *atyp, *rettyp; struct symbol *sym; @@ -1141,23 +1160,12 @@ add_stt_func (ctf_context_t *ccp, unsigned long idx) static CORE_ADDR get_objfile_text_range (struct objfile *of, int *tsize) { - CORE_ADDR text_base; bfd *abfd = of->obfd; const asection *codes; codes = bfd_get_section_by_name (abfd, ".text"); - if (codes == NULL) - { - text_base = 0; - *tsize = 0; - } - else - { - text_base = bfd_section_vma (codes); - *tsize = codes->size; - } - - return text_base; + *tsize = codes ? bfd_section_size (codes) : 0; + return ANOFFSET (of->section_offsets, SECT_OFF_TEXT (of)); } /* Start a symtab for OBJFILE in CTF format. */ @@ -1166,9 +1174,9 @@ static void ctf_start_symtab (struct partial_symtab *pst, struct objfile *of, CORE_ADDR text_offset) { - ctf_context_t *ccp; + struct ctf_context *ccp; - ccp = (ctf_context_t *) pst->read_symtab_private; + ccp = (struct ctf_context *) pst->read_symtab_private; ccp->builder = new buildsym_compunit (of, of->original_name, NULL, language_c, text_offset); @@ -1183,9 +1191,9 @@ static struct compunit_symtab * ctf_end_symtab (struct partial_symtab *pst, CORE_ADDR end_addr, int section) { - ctf_context_t *ccp; + struct ctf_context *ccp; - ccp = (ctf_context_t *) pst->read_symtab_private; + ccp = (struct ctf_context *) pst->read_symtab_private; struct compunit_symtab *result = ccp->builder->end_symtab (end_addr, section); delete ccp->builder; @@ -1199,11 +1207,11 @@ static void psymtab_to_symtab (struct partial_symtab *pst) { struct symbol *sym; - ctf_context_t *ccp; + struct ctf_context *ccp; gdb_assert (!pst->readin); - ccp = (ctf_context_t *) pst->read_symtab_private; + ccp = (struct ctf_context *) pst->read_symtab_private; /* Iterate over entries in data types section. */ if (ctf_type_iter (ccp->fp, ctf_add_type_cb, ccp) == CTF_ERR) @@ -1271,17 +1279,6 @@ ctf_read_symtab (struct partial_symtab *pst, struct objfile *objfile) } } -/* Cleanup function for the ctf_file_key data. */ - -static void -ctf_close_objfile (struct objfile *of, void *datum) -{ - ctf_file_t *fp = static_cast (datum); - ctf_archive_t *arc = ctf_get_arc (fp); - ctf_file_close (fp); - ctf_close (arc); -} - /* Allocate a new partial_symtab NAME. Each source file that has not been fully read in is represented by @@ -1300,11 +1297,11 @@ create_partial_symtab (const char *name, struct objfile *objfile) { struct partial_symtab *pst; - ctf_context_t *ccx; + struct ctf_context *ccx; pst = start_psymtab_common (objfile, name, 0); - ccx = XOBNEW (&objfile->objfile_obstack, ctf_context_t); + ccx = XOBNEW (&objfile->objfile_obstack, struct ctf_context); ccx->fp = cfp; ccx->of = objfile; pst->read_symtab_private = (void *) ccx; @@ -1318,11 +1315,11 @@ create_partial_symtab (const char *name, static int ctf_psymtab_type_cb (ctf_id_t tid, void *arg) { - ctf_context_t *ccp; + struct ctf_context *ccp; uint32_t kind; short section = -1; - ccp = (ctf_context_t *) arg; + ccp = (struct ctf_context *) arg; gdb::unique_xmalloc_ptr name (ctf_type_aname_raw (ccp->fp, tid)); if (name == NULL || strlen (name.get ()) == 0) return 0; @@ -1378,7 +1375,7 @@ ctf_psymtab_type_cb (ctf_id_t tid, void *arg) static int ctf_psymtab_var_cb (const char *name, ctf_id_t id, void *arg) { - ctf_context_t *ccp = (ctf_context_t *) arg; + struct ctf_context *ccp = (struct ctf_context *) arg; add_psymbol_to_list (name, true, VAR_DOMAIN, LOC_STATIC, -1, @@ -1393,7 +1390,7 @@ ctf_psymtab_var_cb (const char *name, ctf_id_t id, void *arg) static void scan_partial_symbols (ctf_file_t *cfp, struct objfile *of) { - ctf_context_t ccx; + struct ctf_context ccx; bfd *abfd = of->obfd; const char *name = bfd_get_filename (abfd); struct partial_symtab *pst = create_partial_symtab (name, cfp, of); @@ -1473,7 +1470,7 @@ elfctf_build_psymtabs (struct objfile *of) if (fp == NULL) error (_("ctf_arc_open_by_name failed on %s - %s"), bfd_get_filename (abfd), ctf_errmsg (err)); - set_objfile_data (of, ctf_file_key, fp); + ctf_file_key.emplace (of, fp); scan_partial_symbols (fp, of); } @@ -1481,6 +1478,4 @@ elfctf_build_psymtabs (struct objfile *of) void _initialize_ctfread (void) { - ctf_file_key - = register_objfile_data_with_cleanup (NULL, ctf_close_objfile); } diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 92ee52b..d0d212d 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,8 @@ 2019-12-04 Christian Biesinger * configure.nat (obsd64): Add missing files x86-nat.o and diff --git a/gdb/ctfread.c b/gdb/ctfread.c index c5f9130..3863178 100644 --- a/gdb/ctfread.c +++ b/gdb/ctfread.c @@ -85,16 +85,35 @@ #include "ctf-api.h"