From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from aserp2120.oracle.com (aserp2120.oracle.com [141.146.126.78]) by sourceware.org (Postfix) with ESMTPS id 92FAC389364A for ; Tue, 27 Apr 2021 01:01:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 92FAC389364A Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 13R0nTZc107136 for ; Tue, 27 Apr 2021 01:01:22 GMT Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by aserp2120.oracle.com with ESMTP id 385ahbktw6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 27 Apr 2021 01:01:21 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 13R0nkg0082835 for ; Tue, 27 Apr 2021 01:01:21 GMT Received: from nam11-co1-obe.outbound.protection.outlook.com (mail-co1nam11lp2168.outbound.protection.outlook.com [104.47.56.168]) by aserp3020.oracle.com with ESMTP id 384b55mbcy-3 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 27 Apr 2021 01:01:21 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=RKI+1CYb4U/QI6s59WjzaR6x16PpD/i3O4gIYPgMrVS3O+nbVg0teYRsrL83SFHh9HJ9S3ZIWur7mYFCdnQAlbIF3qBTOircmaXahmbMJR4T2dwI4j6fHim6VZH85Ir+4kWo9UO2pTIk+XFB+6mLliwAbfgM5YqQ1Z1iTM9fD23S1oB348d01LN+FsLjR6P1vI1FF7iiKjupFZITRi467fSFgm7NaBECwlw0l3rFDf9oWuvQ9i8d46itnSOxiDNtSktB0LIG1N+GpyN/+TK9XtrM/LB77TWRRPHOO4GLhYJAkWD3JnmdY2x0MMbXw67s00nb4EiDGMU/tJ/15AjPEw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=YHMJrO7LowTT2tsvTP08Ob2hknQMuez7spN7dtBYZ2M=; b=ejCqO6AW6uYyKQo2stxAcd1Y+130ZyOEgoK0kaVswZUMxJUCQ5s8NNhlTZKm0a0S1od3XJUW+Z+yAp11n8zdVTSny+qxKSSkmjfMTskXVaLqhN7MeEkLKhYCwzmOMpvcpSZefSfjGq39oHEhA6aKejARDj0no8KYFK6d3Dld0Sp/KhhqxJPBV9quALu8awslfbsG6QldQZ0E9oc8hiTdPzJNdm9zyRI40PbAAMSQPZeSlnH771QKmoktGngYwwrqfNrbAJZKbJlH91pV5lxGXxOg1e4AUJooXMEzP85z1PEK0D/Q9LNZiTX0lQh0VnHC0dl98wm9gQHi5r/N2R1YdQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none Received: from BN6PR10MB1748.namprd10.prod.outlook.com (2603:10b6:405:9::16) by BN6PR10MB1876.namprd10.prod.outlook.com (2603:10b6:404:ff::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4065.23; Tue, 27 Apr 2021 01:01:18 +0000 Received: from BN6PR10MB1748.namprd10.prod.outlook.com ([fe80::250a:e1c3:3146:8e02]) by BN6PR10MB1748.namprd10.prod.outlook.com ([fe80::250a:e1c3:3146:8e02%9]) with mapi id 15.20.4065.027; Tue, 27 Apr 2021 01:01:18 +0000 From: Weimin Pan To: gdb-patches@sourceware.org Subject: [PATCH,V4 2/2] CTF: multi-CU and archive support Date: Mon, 26 Apr 2021 21:00:54 -0400 Message-Id: <1619485254-7340-3-git-send-email-weimin.pan@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1619485254-7340-2-git-send-email-weimin.pan@oracle.com> References: <1619485254-7340-1-git-send-email-weimin.pan@oracle.com> <1619485254-7340-2-git-send-email-weimin.pan@oracle.com> Content-Type: text/plain X-Originating-IP: [148.87.23.13] X-ClientProxiedBy: SN2PR01CA0076.prod.exchangelabs.com (2603:10b6:800::44) To BN6PR10MB1748.namprd10.prod.outlook.com (2603:10b6:405:9::16) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost.us.oracle.com (148.87.23.13) by SN2PR01CA0076.prod.exchangelabs.com (2603:10b6:800::44) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4065.20 via Frontend Transport; Tue, 27 Apr 2021 01:01:17 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 007bed42-0d69-4ca0-ff92-08d90917f6d0 X-MS-TrafficTypeDiagnostic: BN6PR10MB1876: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:800; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: bg8Y1mC4R5bJW0A9uVFTGh7B7n9Uwb+5hkB+8jcQ5H05FxxxZynDi8d5Z7ggeBZEkH1YPdEyGw1RmBVPRqcUHGepw3DroewmnyLqylT2DsgIpRqkRqOVrmWsMLAKhl3nyjUauvBh3TK7rLn/H7A8c9vXIO/TDBRau4WPKbKX9xDE3Uo4fw6T2QBHk1+XvSadTmUAGd5efZNv4aWcV55TvFScDsbXA8dDg7U5UIYVoc8+tT+8UNkBn6Z/p/gONQ2o0AJc/vwOkn8Swyep5E7PzLZ8hU3pTHASu6TgFvgvKB9ANT0kGzRLPmnLsBxgnoPNVNf3hLSglYY4T+DV+KaA/C0wooWYYM8nDFsJnWnA/fTWCkJdb+LQij8v5OW+0UDHEObJRuZ2LuqMuZYBoJp8+GBUNYSoiZ40bFRV6gHhPVC9yW1BDHAZCmUPov6LKA+IvqhChpZNouRWpdGj5OWwU1K5r46J9OfgtS7xUaW1gUa3LnLelmMp185r9wW+Md3AwTRPy/MseLGp5DzIxfejSUEkpE9KEK3HJ2MUg6gtTQrPe6CVfschSyn/4Fx+VLlR4dnwU7xvxR7suhT7bYEvVpsjCwUeBrZ6UY0anOIpvvPVIrLOsdcD8cdRVXi/qPx3LOhiYe1crk4RCiIIauSJVAeWFDI2ZiiscJQJ6vrTos4x2WtMuekp4cXMJNQrLijv1rUrRM2mC8tEHgfRu5ksMpQXT/gGRrQjGYjrkThmuvdKIf7LixtzShiNwW0TqslB X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:BN6PR10MB1748.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(376002)(136003)(396003)(39860400002)(346002)(366004)(2906002)(38350700002)(38100700002)(6486002)(66476007)(478600001)(86362001)(66556008)(52116002)(7696005)(8676002)(16526019)(66946007)(83380400001)(956004)(6916009)(8936002)(36756003)(2616005)(6666004)(186003)(44832011)(5660300002)(316002)(30864003)(26005)(2004002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?us-ascii?Q?xsPc9xqE+ompic9aq/izfUt/kpZDlLRIjqqd89ct7Ee8RH3TdZPBu0dyuQFK?= =?us-ascii?Q?xmsAYeBll4mNCo+3kYgU2vB0P20esQ5JCfl3BhudYXxomktUX4GIkdojq4gj?= =?us-ascii?Q?qMR+ockXWLcWW8Dplw0aGeQ5FIvcQvuKd29QFfVa5qXrhiiD6Fa1gkiO0uE2?= =?us-ascii?Q?65OYciCF+hnLIqR1HXYr72BJXIMniHMq9hSfxBhKlYRKAeKeWKmqpz+6lAAh?= =?us-ascii?Q?Z5diXCm+tfzXJA+2XsdHYhHPVCtpiLfyjcbbfGdf+te9rlstmm/lHzM4P7jg?= =?us-ascii?Q?7FKGxqJn4Ahd8Cl1++wfA8AC6D7C2TasSnfTDo5YSj135kcsnuJXq+3mosne?= =?us-ascii?Q?GEJQRIWPqF7e2zCzV89a70iEX7mkBdhAElKt041Ka+N99W+bw5BN2zA5fYQb?= =?us-ascii?Q?Gi0zUzQdUNLnxHqSP3h0uSVzfNA8kymgyv3Qr9g26oODIQVIsTMSVX0JhQdf?= =?us-ascii?Q?Au/sJpeN38ckx/3eri3Go3Rjiqn+57SQ6Fn7EtRtIVtN9LNNRoOTibKQmcyW?= =?us-ascii?Q?XOMJ/K9qCqzrgKidZEM3zbqSX+Cn/EeOWtlL8hwHjngnUjvYiWss+MZfCUNH?= =?us-ascii?Q?n4M+Jd6KRCdnr2Seiz5Wt5qDNfLz/iCCcUS47icgvZg+1Rp281Cb82VVEVHo?= =?us-ascii?Q?TF6niv+tE0W6nycdUHlaX9qHiHT+AbLB/rIj2Z4IxQuRpN4dHd0C5ZWJBcTc?= =?us-ascii?Q?AkeQM6LiZSofdFiN+hcrEPq4JhO52IB1uVjuuS0geioGt0myLek6iZrgxcHU?= =?us-ascii?Q?EQn8vq+Z/a2avjazscviVNzobEjKaedug8J4ufc3N2VWcL+VcG/6eENQAiy6?= =?us-ascii?Q?DNeM7POog39mvkQKdg6l4c+JN1Oc7EZWh2948l6hRViqw4WZ/3LxCnuqkXKB?= =?us-ascii?Q?ad5aohX2BAOLwF3WAZk4E5FqegtvchDQYTFJk6qHnwgG6z/NDYajmg0aS5zm?= =?us-ascii?Q?btybErbuPj/I7a56oEgqTAVf+qpF9dVahncMLV3OV47a9u5kpLOKdYCwJspC?= =?us-ascii?Q?5soo3jzo2hFIn4vb4guYlCcgZvqx9sGcTBCtLzlbYb4o+bOdz+cFet+kLdlZ?= =?us-ascii?Q?vpoxI80K0yfCpQF98hh2uZL1tXiE1bMRX9KrZZiqYw2LJJN2CLbFZJbvcwvC?= =?us-ascii?Q?D/H7QkJEpmopPbxBNKd/KEunfSfDJSFl1AVQ40uCkjPWNxUwQAbSladMNB/z?= =?us-ascii?Q?NJnmd5+/b0M9OH9xr/thTICwoXtIfN1waM7vzbfGh4tk+nPqgFEzBhXtrOnU?= =?us-ascii?Q?3n398OATdtphM7LbjHu+QFZCRvoG8WXxpNg484NcPyZpT9nUJo0v/l3y+FU7?= =?us-ascii?Q?xS2hYuzFYdAg1KRAcxPZe5pA?= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 007bed42-0d69-4ca0-ff92-08d90917f6d0 X-MS-Exchange-CrossTenant-AuthSource: BN6PR10MB1748.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Apr 2021 01:01:18.3253 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: UG/zh1hJjzhP+YDVF+2plWhhfzZ1SuAsLGed5achJeRg8TJR6Pms1tMTT7tZ6iY0i4phEqK6ezdygGV+kkXB4g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN6PR10MB1876 X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9966 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 bulkscore=0 mlxscore=0 malwarescore=0 phishscore=0 adultscore=0 mlxlogscore=999 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104060000 definitions=main-2104270002 X-Proofpoint-GUID: wKVsOqbdFDM6-umKni7NUHVhIglJR_FO X-Proofpoint-ORIG-GUID: wKVsOqbdFDM6-umKni7NUHVhIglJR_FO X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9966 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 bulkscore=0 mlxlogscore=999 priorityscore=1501 clxscore=1015 adultscore=0 suspectscore=0 spamscore=0 phishscore=0 malwarescore=0 lowpriorityscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104060000 definitions=main-2104270002 X-Spam-Status: No, score=-10.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, KAM_STOCKGEN, MSGID_FROM_MTA_HEADER, RCVD_IN_MSPIKE_BL, RCVD_IN_MSPIKE_L4, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 27 Apr 2021 01:01:26 -0000 Now gdb is capable of debugging executable, which consists of multiple compilation units, with CTF. An executable could potentially have one or more archives, which, in CTF context, contain conflicting types. When comparing to DWARF2, there is a major difference in the type sections, all changes were made in ctfread.c where elfctf_build_psymtabs and scan_partial_symbols, with the new ctf_per_tu_data struct, were modify to handle archives which were treated as dependencies in gdb, via the ctf archive iterator and its callback build_ctf_archive_member, and were then expanded with expand_dependencies when psymtabs were expanded. Also changes were made to handle CTF's data object section and function info section which now share the same format for their contents - an array of type IDs. New functions ctf_psymtab_add_stt_entries, which is called by ctf_psymtab_add_stt_obj and ctf_psymtab_add_stt_func, and add_stt_entries, which is called by add_stt_obj and add_stt_func when setting up psymtabs and full symtab, respectively. --- gdb/ctfread.c | 317 ++++++++++++++++++------------ gdb/testsuite/gdb.ctf/cross-tu-cyclic-1.c | 18 ++ gdb/testsuite/gdb.ctf/cross-tu-cyclic-2.c | 16 ++ gdb/testsuite/gdb.ctf/cross-tu-cyclic-3.c | 3 + gdb/testsuite/gdb.ctf/cross-tu-cyclic-4.c | 4 + gdb/testsuite/gdb.ctf/cross-tu-cyclic.exp | 43 ++++ gdb/testsuite/gdb.ctf/ctf-a.c | 32 +++ gdb/testsuite/gdb.ctf/ctf-a.h | 22 +++ gdb/testsuite/gdb.ctf/ctf-b.c | 25 +++ gdb/testsuite/gdb.ctf/ctf-b.h | 22 +++ gdb/testsuite/gdb.ctf/ctf-c.c | 25 +++ gdb/testsuite/gdb.ctf/ctf-c.h | 21 ++ gdb/testsuite/gdb.ctf/multi.exp | 42 ++++ 13 files changed, 464 insertions(+), 126 deletions(-) create mode 100644 gdb/testsuite/gdb.ctf/cross-tu-cyclic-1.c create mode 100644 gdb/testsuite/gdb.ctf/cross-tu-cyclic-2.c create mode 100644 gdb/testsuite/gdb.ctf/cross-tu-cyclic-3.c create mode 100644 gdb/testsuite/gdb.ctf/cross-tu-cyclic-4.c create mode 100644 gdb/testsuite/gdb.ctf/cross-tu-cyclic.exp create mode 100644 gdb/testsuite/gdb.ctf/ctf-a.c create mode 100644 gdb/testsuite/gdb.ctf/ctf-a.h create mode 100644 gdb/testsuite/gdb.ctf/ctf-b.c create mode 100644 gdb/testsuite/gdb.ctf/ctf-b.h create mode 100644 gdb/testsuite/gdb.ctf/ctf-c.c create mode 100644 gdb/testsuite/gdb.ctf/ctf-c.h create mode 100644 gdb/testsuite/gdb.ctf/multi.exp diff --git a/gdb/ctfread.c b/gdb/ctfread.c index 97355bf..284cf91 100644 --- a/gdb/ctfread.c +++ b/gdb/ctfread.c @@ -117,6 +117,7 @@ struct ctf_context struct objfile *of; psymtab_storage *partial_symtabs; partial_symtab *pst; + ctf_archive_t *arc; struct buildsym_compunit *builder; }; @@ -166,6 +167,18 @@ struct ctf_field_info std::vector nested_types_list; }; +/* Persistent data held for a translation unit. */ + +struct ctf_per_tu_data +{ + ctf_dict_t *fp; + struct objfile *of; + ctf_archive_t *arc; + ctf_psymtab *parent_psymtab; + psymtab_storage *pss; + psymbol_functions *psf; + std::vector imported_symtabs; +}; /* Local function prototypes */ @@ -245,10 +258,8 @@ struct ctf_tid_and_type ids.tid = tid; ids.type = typ; slot = (struct ctf_tid_and_type **) htab_find_slot (htab, &ids, INSERT); - if (*slot) - complaint (_("An internal GDB problem: ctf_ id_t %ld type already set"), - (tid)); - *slot = XOBNEW (&of->objfile_obstack, struct ctf_tid_and_type); + if (*slot == nullptr) + *slot = XOBNEW (&of->objfile_obstack, struct ctf_tid_and_type); **slot = ids; return typ; } @@ -1144,7 +1155,8 @@ struct ctf_tid_and_type if (type) { sym = new_symbol (ccp, type, id); - sym->compute_and_set_names (name, false, ccp->of->per_bfd); + if (sym) + sym->compute_and_set_names (name, false, ccp->of->per_bfd); } break; case CTF_K_STRUCT: @@ -1174,80 +1186,48 @@ struct ctf_tid_and_type return 0; } -/* Add an ELF STT_OBJ symbol with index IDX to the symbol table. */ +/* Add entries in either data objects or function info section, controlled + by FUNCTIONS. */ -static struct symbol * -add_stt_obj (struct ctf_context *ccp, unsigned long idx) +static void +add_stt_entries (struct ctf_context *ccp, int functions) { - struct symbol *sym; - struct type *type; + ctf_next_t *i = nullptr; + const char *tname; ctf_id_t tid; + struct symbol *sym = nullptr; + struct type *type; - if ((tid = ctf_lookup_by_symbol (ccp->fp, idx)) == CTF_ERR) - return nullptr; - - type = fetch_tid_type (ccp, tid); - if (type == nullptr) - return nullptr; - - sym = new_symbol (ccp, type, tid); - - return sym; + while ((tid = ctf_symbol_next (ccp->fp, &i, &tname, functions)) != CTF_ERR) + { + type = get_tid_type (ccp->of, tid); + if (type == nullptr) + continue; + sym = new (&ccp->of->objfile_obstack) symbol; + OBJSTAT (ccp->of, n_syms++); + SYMBOL_TYPE (sym) = type; + SYMBOL_DOMAIN (sym) = VAR_DOMAIN; + SYMBOL_ACLASS_INDEX (sym) = LOC_STATIC; + sym->compute_and_set_names (tname, false, ccp->of->per_bfd); + add_symbol_to_list (sym, ccp->builder->get_global_symbols ()); + set_symbol_address (ccp->of, sym, tname); + } } -/* Add an ELF STT_FUNC symbol with index IDX to the symbol table. */ +/* Add entries in data objects section. */ -static struct symbol * -add_stt_func (struct ctf_context *ccp, unsigned long idx) +static void +add_stt_obj (struct ctf_context *ccp) { - struct type *ftype, *atyp, *rettyp; - struct symbol *sym; - ctf_funcinfo_t finfo; - ctf_id_t argv[32]; - uint32_t argc; - ctf_id_t tid; - struct type *void_type = objfile_type (ccp->of)->builtin_void; - - if (ctf_func_info (ccp->fp, idx, &finfo) == CTF_ERR) - return nullptr; - - argc = finfo.ctc_argc; - if (ctf_func_args (ccp->fp, idx, argc, argv) == CTF_ERR) - return nullptr; - - if (ctf_type_name_raw (ccp->fp, idx) == nullptr) - return nullptr; - - tid = ctf_lookup_by_symbol (ccp->fp, idx); - ftype = fetch_tid_type (ccp, tid); - if ((finfo.ctc_flags & CTF_FUNC_VARARG) != 0) - ftype->set_has_varargs (true); - ftype->set_num_fields (argc); - - /* If argc is 0, it has a "void" type. */ - if (argc != 0) - ftype->set_fields - ((struct field *) TYPE_ZALLOC (ftype, argc * sizeof (struct field))); - - /* TYPE_FIELD_TYPE must never be NULL. Fill it with void_type, if failed - to find the argument type. */ - for (int iparam = 0; iparam < argc; iparam++) - { - atyp = fetch_tid_type (ccp, argv[iparam]); - if (atyp) - ftype->field (iparam).set_type (atyp); - else - ftype->field (iparam).set_type (void_type); - } + add_stt_entries (ccp, 0); +} - sym = new_symbol (ccp, ftype, tid); - rettyp = fetch_tid_type (ccp, finfo.ctc_return); - if (rettyp != nullptr) - SYMBOL_TYPE (sym) = rettyp; - else - SYMBOL_TYPE (sym) = void_type; +/* Add entries in function info section. */ - return sym; +static void +add_stt_func (struct ctf_context *ccp) +{ + add_stt_entries (ccp, 1); } /* Get text segment base for OBJFILE, TSIZE contains the segment size. */ @@ -1270,12 +1250,20 @@ struct ctf_tid_and_type struct objfile *of, CORE_ADDR text_offset) { struct ctf_context *ccp; + ctf_psymtab *dp; ccp = pst->context; ccp->builder = new buildsym_compunit (of, of->original_name, nullptr, language_c, text_offset); ccp->builder->record_debugformat ("ctf"); + + for (int i = 0; i < pst->number_of_dependencies; i++) + { + dp = (ctf_psymtab *)pst->dependencies[i]; + dp->context->builder = ccp->builder; + dp->context->of = of; + } } /* Finish reading symbol/type definitions in CTF format. @@ -1317,17 +1305,77 @@ struct ctf_tid_and_type ctf_errmsg (ctf_errno (ccp->fp))); } +/* Add entries in either data objects or function info section, controlled + by FUNCTIONS, to psymtab. */ + +static void +ctf_psymtab_add_stt_entries (ctf_dict_t *cfp, ctf_psymtab *pst, + struct objfile *of, int functions) +{ + ctf_next_t *i = nullptr; + ctf_id_t tid; + const char *tname; + + while ((tid = ctf_symbol_next (cfp, &i, &tname, functions)) != CTF_ERR) + { + uint32_t kind = ctf_type_kind (cfp, tid); + address_class aclass; + domain_enum tdomain; + switch (kind) + { + case CTF_K_STRUCT: + case CTF_K_UNION: + case CTF_K_ENUM: + tdomain = STRUCT_DOMAIN; + break; + default: + tdomain = VAR_DOMAIN; + break; + } + + if (kind == CTF_K_FUNCTION) + aclass = LOC_STATIC; + else if (kind == CTF_K_CONST) + aclass = LOC_CONST; + else + aclass = LOC_TYPEDEF; + + pst->add_psymbol (tname, true, + tdomain, aclass, -1, + psymbol_placement::GLOBAL, + 0, language_c, pst->context->partial_symtabs, of); + } +} + +/* Add entries in data objects section to psymtab. */ + +static void +ctf_psymtab_add_stt_obj (ctf_dict_t *cfp, ctf_psymtab *pst, + struct objfile *of) +{ + ctf_psymtab_add_stt_entries (cfp, pst, of, 0); +} + +/* Add entries in function info section to psymtab. */ + +static void +ctf_psymtab_add_stt_func (ctf_dict_t *cfp, ctf_psymtab *pst, + struct objfile *of) +{ + ctf_psymtab_add_stt_entries (cfp, pst, of, 1); +} + /* Read in full symbols for PST, and anything it depends on. */ void ctf_psymtab::expand_psymtab (struct objfile *objfile) { - struct symbol *sym; struct ctf_context *ccp; gdb_assert (!readin); ccp = context; + expand_dependencies (objfile); /* Iterate over entries in data types section. */ if (ctf_type_iter (ccp->fp, ctf_add_type_cb, ccp) == CTF_ERR) @@ -1341,22 +1389,10 @@ struct ctf_tid_and_type ctf_errmsg (ctf_errno (ccp->fp))); /* Add entries in data objects and function info sections. */ - for (unsigned long i = 0; ; i++) - { - sym = add_stt_obj (ccp, i); - if (sym == nullptr) - { - if (ctf_errno (ccp->fp) == EINVAL - || ctf_errno (ccp->fp) == ECTF_NOSYMTAB) - break; - sym = add_stt_func (ccp, i); - } - if (sym == nullptr) - continue; - - set_symbol_address (ccp->of, sym, sym->linkage_name ()); - } + add_stt_obj (ccp); + add_stt_func (ccp); + ctf_dict_close (ccp->fp); readin = true; } @@ -1409,6 +1445,7 @@ struct ctf_tid_and_type static ctf_psymtab * create_partial_symtab (const char *name, + ctf_archive_t *arc, ctf_dict_t *cfp, psymtab_storage *partial_symtabs, struct objfile *objfile) @@ -1419,11 +1456,12 @@ struct ctf_tid_and_type pst = new ctf_psymtab (name, partial_symtabs, objfile->per_bfd, 0); ccx = XOBNEW (&objfile->objfile_obstack, struct ctf_context); + ccx->arc = arc; ccx->fp = cfp; + ctf_ref (cfp); ccx->of = objfile; ccx->partial_symtabs = partial_symtabs; ccx->pst = pst; - ccx->builder = nullptr; pst->context = ccx; return pst; @@ -1509,13 +1547,15 @@ struct ctf_tid_and_type /* Setup partial_symtab's describing each source file for which debugging information is available. */ -static void +static ctf_psymtab * scan_partial_symbols (ctf_dict_t *cfp, psymtab_storage *partial_symtabs, - struct objfile *of) + struct ctf_per_tu_data *tup) { + struct objfile *of = tup->of; bfd *abfd = of->obfd; const char *name = bfd_get_filename (abfd); - ctf_psymtab *pst = create_partial_symtab (name, cfp, partial_symtabs, of); + ctf_psymtab *pst = create_partial_symtab (name, tup->arc, cfp, + partial_symtabs, of); struct ctf_context *ccx = pst->context; @@ -1530,46 +1570,46 @@ struct ctf_tid_and_type /* Scan CTF object and function sections which correspond to each STT_FUNC or STT_OBJECT entry in the symbol table, pick up what init_symtab has done. */ - for (unsigned long idx = 0; ; idx++) - { - ctf_id_t tid; - if ((tid = ctf_lookup_by_symbol (cfp, idx)) == CTF_ERR) - { - if (ctf_errno (cfp) == EINVAL || ctf_errno (cfp) == ECTF_NOSYMTAB) - break; // Done, reach end of the section. - else - continue; - } - const char *tname = ctf_type_name_raw (cfp, tid); - uint32_t kind = ctf_type_kind (cfp, tid); - address_class aclass; - domain_enum tdomain; - switch (kind) - { - case CTF_K_STRUCT: - case CTF_K_UNION: - case CTF_K_ENUM: - tdomain = STRUCT_DOMAIN; - break; - default: - tdomain = VAR_DOMAIN; - break; - } + ctf_psymtab_add_stt_obj (cfp, pst, of); + ctf_psymtab_add_stt_func (cfp, pst, of); - if (kind == CTF_K_FUNCTION) - aclass = LOC_STATIC; - else if (kind == CTF_K_CONST) - aclass = LOC_CONST; - else - aclass = LOC_TYPEDEF; + pst->end (); - pst->add_psymbol (tname, true, - tdomain, aclass, -1, - psymbol_placement::STATIC, - 0, language_c, partial_symtabs, of); + return pst; +} + +/* Callback to build the psymtab for archive member NAME. */ + +static int +build_ctf_archive_member (ctf_dict_t *ctf, const char *name, void *arg) +{ + struct ctf_per_tu_data *tup = (struct ctf_per_tu_data *) arg; + ctf_dict_t *parent = tup->fp; + ctf_psymtab *pst; + int isparent = 0; + + if (strcmp (name, ".ctf") != 0) + { + ctf_import (ctf, parent); } + else + isparent = 1; - pst->end (); + if (info_verbose) + { + printf_filtered (_("Scanning archive member %s..."), name); + gdb_flush (gdb_stdout); + } + + psymtab_storage *pss = tup->psf->get_partial_symtabs ().get (); + pst = scan_partial_symbols (ctf, pss, tup); + + if (isparent) + tup->parent_psymtab = pst; + else + tup->imported_symtabs.push_back (pst); + + return 0; } /* Read CTF debugging information from a BFD section. This is @@ -1579,6 +1619,7 @@ struct ctf_tid_and_type void elfctf_build_psymtabs (struct objfile *of) { + struct ctf_per_tu_data pcu; bfd *abfd = of->obfd; int err; @@ -1593,10 +1634,34 @@ struct ctf_tid_and_type bfd_get_filename (abfd), ctf_errmsg (err)); ctf_dict_key.emplace (of, fp); + pcu.fp = fp; + pcu.of = of; + pcu.arc = arc; + psymbol_functions *psf = new psymbol_functions (); psymtab_storage *partial_symtabs = psf->get_partial_symtabs ().get (); of->qf.emplace_front (psf); - scan_partial_symbols (fp, partial_symtabs, of); + pcu.psf = psf; + + if (ctf_archive_iter (arc, build_ctf_archive_member, &pcu) < 0) + error (_("ctf_archive_iter failed in input file %s: - %s"), + bfd_get_filename (abfd), ctf_errmsg (err)); + + int arch_cnt = pcu.imported_symtabs.size (); + struct partial_symtab *parent_pst = pcu.parent_psymtab; + + if (parent_pst && arch_cnt) + { + /* Fill in the 'dependencies'. */ + parent_pst->number_of_dependencies = arch_cnt; + parent_pst->dependencies + = partial_symtabs->allocate_dependencies (arch_cnt); + for (int i = 0; i < arch_cnt; ++i) + { + parent_pst->dependencies[i] + = pcu.imported_symtabs.at (i); + } + } } #else diff --git a/gdb/testsuite/gdb.ctf/cross-tu-cyclic-1.c b/gdb/testsuite/gdb.ctf/cross-tu-cyclic-1.c new file mode 100644 index 0000000..fe52b9e --- /dev/null +++ b/gdb/testsuite/gdb.ctf/cross-tu-cyclic-1.c @@ -0,0 +1,18 @@ +struct A; +struct B +{ + int foo; + struct A *bar; +}; + +struct A +{ + long a; + struct B *foo; +}; + +static struct A *foo __attribute__((used)); + +int main() +{ +} diff --git a/gdb/testsuite/gdb.ctf/cross-tu-cyclic-2.c b/gdb/testsuite/gdb.ctf/cross-tu-cyclic-2.c new file mode 100644 index 0000000..aa2d177 --- /dev/null +++ b/gdb/testsuite/gdb.ctf/cross-tu-cyclic-2.c @@ -0,0 +1,16 @@ +struct B; +struct A +{ + long a; + struct B *foo; + struct C *bar; +}; + +struct C +{ + struct B *foo; + int b; +}; + +static struct C *foo __attribute__((used)); +static struct A *bar __attribute__((used)); diff --git a/gdb/testsuite/gdb.ctf/cross-tu-cyclic-3.c b/gdb/testsuite/gdb.ctf/cross-tu-cyclic-3.c new file mode 100644 index 0000000..19947e8 --- /dev/null +++ b/gdb/testsuite/gdb.ctf/cross-tu-cyclic-3.c @@ -0,0 +1,3 @@ +struct A { struct B *foo; }; +static struct A *a __attribute__((__used__)); +static struct A *conflicty __attribute__((__used__)); diff --git a/gdb/testsuite/gdb.ctf/cross-tu-cyclic-4.c b/gdb/testsuite/gdb.ctf/cross-tu-cyclic-4.c new file mode 100644 index 0000000..6e0c957 --- /dev/null +++ b/gdb/testsuite/gdb.ctf/cross-tu-cyclic-4.c @@ -0,0 +1,4 @@ +struct A { struct B *foo; }; +struct B { struct B *next; }; +static struct A *a __attribute__((__used__)); +static struct B *conflicty __attribute__((__used__)); diff --git a/gdb/testsuite/gdb.ctf/cross-tu-cyclic.exp b/gdb/testsuite/gdb.ctf/cross-tu-cyclic.exp new file mode 100644 index 0000000..734892d --- /dev/null +++ b/gdb/testsuite/gdb.ctf/cross-tu-cyclic.exp @@ -0,0 +1,43 @@ +# Copyright 2021 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# This file is a subset of ptype.exp written by Rob Savoye. (rob@cygnus.com) + +if [skip_ctf_tests] { + unsupported "no CTF debug format support, or CTF disabled in GDB" + return 0 +} + +standard_testfile cross-tu-cyclic-1.c cross-tu-cyclic-2.c \ + cross-tu-cyclic-3.c cross-tu-cyclic-4.c + +# Using `-gt` generates full-fledged CTF debug information. +set opts "additional_flags=-gt -Wl,--export-dynamic" +if { [prepare_for_testing "failed to prepare" ${testfile} \ + [list $srcfile $srcfile2 $srcfile3 $srcfile4] \ + [list $opts nowarnings]] } { + return 0 +} + +# Create and source the file that provides information about the compiler +# used to compile the test case. +if [get_compiler_info] { + return -1 +} + +# Same thing with struct and union. +gdb_test "ptype struct A" "type = struct A \{\[\r\n\]+\[ \t\]+long a;\[\r\n\]+\[ \t\]+struct B \\*foo;\[\r\n\]+\}.*" "ptype structure A" +gdb_test "ptype struct B" "type = struct B \{\[\r\n\]+\[ \t\]+int foo;\[\r\n\]+\[ \t\]+struct A \\*bar;\[\r\n\]+\}.*" "ptype structure B" +gdb_test "ptype struct C" "type = struct C \{\[\r\n\]+\[ \t\]+struct B \\*foo;\[\r\n\]+\[ \t\]+int b;\[\r\n\]+\}.*" "ptype structure C" diff --git a/gdb/testsuite/gdb.ctf/ctf-a.c b/gdb/testsuite/gdb.ctf/ctf-a.c new file mode 100644 index 0000000..9aa2a8f --- /dev/null +++ b/gdb/testsuite/gdb.ctf/ctf-a.c @@ -0,0 +1,32 @@ +/* This test program is part of GDB, the GNU debugger. + + Copyright 2021 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +#include "ctf-a.h" + +static struct A a __attribute__((used)); + +extern struct C *foo (); +extern int bar (); + +int main () +{ + struct C *cp; + cp = foo (); + if (cp) + return bar (); + return 0; +} diff --git a/gdb/testsuite/gdb.ctf/ctf-a.h b/gdb/testsuite/gdb.ctf/ctf-a.h new file mode 100644 index 0000000..297d740 --- /dev/null +++ b/gdb/testsuite/gdb.ctf/ctf-a.h @@ -0,0 +1,22 @@ +/* This test program is part of GDB, the GNU debugger. + + Copyright 2021 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +struct A { + struct B *b; + struct A *next; +}; + diff --git a/gdb/testsuite/gdb.ctf/ctf-b.c b/gdb/testsuite/gdb.ctf/ctf-b.c new file mode 100644 index 0000000..c3a8ce5 --- /dev/null +++ b/gdb/testsuite/gdb.ctf/ctf-b.c @@ -0,0 +1,25 @@ +/* This test program is part of GDB, the GNU debugger. + + Copyright 2021 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +#include "ctf-b.h" + +static struct B b __attribute__((used)); + +int bar () +{ + return b.wombat; +} diff --git a/gdb/testsuite/gdb.ctf/ctf-b.h b/gdb/testsuite/gdb.ctf/ctf-b.h new file mode 100644 index 0000000..9dbdd7d --- /dev/null +++ b/gdb/testsuite/gdb.ctf/ctf-b.h @@ -0,0 +1,22 @@ +/* This test program is part of GDB, the GNU debugger. + + Copyright 2021 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +struct B { + struct C *c; + int wombat; +}; + diff --git a/gdb/testsuite/gdb.ctf/ctf-c.c b/gdb/testsuite/gdb.ctf/ctf-c.c new file mode 100644 index 0000000..b4051b3 --- /dev/null +++ b/gdb/testsuite/gdb.ctf/ctf-c.c @@ -0,0 +1,25 @@ +/* This test program is part of GDB, the GNU debugger. + + Copyright 2021 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +#include "ctf-c.h" + +static struct C c __attribute__((used)); + +struct C * foo () +{ + return &c; +} diff --git a/gdb/testsuite/gdb.ctf/ctf-c.h b/gdb/testsuite/gdb.ctf/ctf-c.h new file mode 100644 index 0000000..fb18157 --- /dev/null +++ b/gdb/testsuite/gdb.ctf/ctf-c.h @@ -0,0 +1,21 @@ +/* This test program is part of GDB, the GNU debugger. + + Copyright 2021 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +struct C { + struct A *a; + int b; +}; diff --git a/gdb/testsuite/gdb.ctf/multi.exp b/gdb/testsuite/gdb.ctf/multi.exp new file mode 100644 index 0000000..973115e --- /dev/null +++ b/gdb/testsuite/gdb.ctf/multi.exp @@ -0,0 +1,42 @@ +# Copyright 2021 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# This file is a subset of ptype.exp written by Rob Savoye. (rob@cygnus.com) + +if [skip_ctf_tests] { + unsupported "no CTF debug format support, or CTF disabled in GDB" + return 0 +} + +standard_testfile ctf-a.c ctf-b.c ctf-c.c + +# Using `-gt` generates full-fledged CTF debug information. +set opts "additional_flags=-gt -Wl,--export-dynamic" +if { [prepare_for_testing "failed to prepare" ${testfile} \ + [list $srcfile $srcfile2 $srcfile3] \ + [list $opts nowarnings]] } { + return 0 +} + +# Create and source the file that provides information about the compiler +# used to compile the test case. +if [get_compiler_info] { + return -1 +} + +# Same thing with struct and union. +gdb_test "ptype struct A" "type = struct A \{\[\r\n\]+\[ \t\]+struct B \\*b;\[\r\n\]+\[ \t\]+struct A \\*next;\[\r\n\]+\}.*" "ptype structure A" +gdb_test "ptype struct B" "type = struct B \{\[\r\n\]+\[ \t\]+struct C \\*c;\[\r\n\]+\[ \t\]+int \\wombat;\[\r\n\]+\}.*" "ptype structure B" +gdb_test "ptype struct C" "type = struct C \{\[\r\n\]+\[ \t\]+struct A \\*a;\[\r\n\]+\[ \t\]+int b;\[\r\n\]+\}.*" "ptype structure C" -- 1.8.3.1