From patchwork Wed Nov 17 07:39:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Jose E. Marchesi" X-Patchwork-Id: 47800 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 49608385AC38 for ; Wed, 17 Nov 2021 07:39:29 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 49608385AC38 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1637134769; bh=BoIJ6XySxB5TA7OzJpGrl3+eaapIfkht391zbVrTbQ0=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Help: List-Subscribe:From:Reply-To:From; b=Im0v9iH9AjqBdRX71aBF/YxjYaFDwBp+BtZa/97iduNxP/YsNGMBPXf483jrKt2ZX pBXFAUA/ANddCbJ/UTqaGNCQO7Bjcyi8f3/vaVJOuFj/oVhTl2MgC/xqG5TDtQPxOn LMtk7lf/TKBS7UN0RxHrZmvurJ41tFNCNz6GNbno= X-Original-To: libabigail@sourceware.org Delivered-To: libabigail@sourceware.org Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by sourceware.org (Postfix) with ESMTPS id 69FCD3858C27 for ; Wed, 17 Nov 2021 07:39:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 69FCD3858C27 Received: from pps.filterd (m0246632.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 1AH6Rf1q019192 for ; Wed, 17 Nov 2021 07:39:22 GMT Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by mx0b-00069f02.pphosted.com with ESMTP id 3cbhv5ej7s-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Wed, 17 Nov 2021 07:39:21 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.1.2/8.16.1.2) with SMTP id 1AH7Kf4j084580 for ; Wed, 17 Nov 2021 07:39:13 GMT Received: from nam11-bn8-obe.outbound.protection.outlook.com (mail-bn8nam11lp2170.outbound.protection.outlook.com [104.47.58.170]) by aserp3020.oracle.com with ESMTP id 3ca566kb9j-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Wed, 17 Nov 2021 07:39:13 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Awag2A5A+1SOF2iLMplnhRtUIhzb5TrRX6+GwwIoslAfIgjkqXxE04phB6sBCEtComeqfzZFNFddr8tgT+pVoM1punPFtmKWPsvCyd343I1x8evzxa6uBx1yu0I4duKx/rhmLegi/V3TiFamt7RnTrpPO15DWvIg4lYztEDIFI9aTSKwJX4YrR+YBJaVPSqodFaRCFX5hC+A3Bw00OzRPhiApX69ItNEBe8pOFTgBhWwhL+FpZFUFQAFTf8l3NWl77UTiMK2LaoPubEJFJlFZ6Glsy5NSsXVdErSHfXuwdtVEmrrOxce3qLo4VVXF8piSEeeN39AaLFiP+qMY3wA1A== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=BoIJ6XySxB5TA7OzJpGrl3+eaapIfkht391zbVrTbQ0=; b=l5M2s588OSEo8SDic+kaAyDPhkINf8mfnlHW4b9XJ5ims2pSdHjYt4XSFmpRkfFsRHNsdKK1eWT3rl5P3cmhrHUEmqdjcvgXjj4urN6/L9y8h2wsk9lfKFTeX5RdGaKX5WFoaNH3QXO4vlrmvwp3mr9kFwDQDmnm2Il4qPGZ28xnRkMFzDsg8SBkKLmIviApVl3cYf486r6PgS91i73YnGL4t5vujAHtam9lPZq4is5qMtySdAkIBz3R1WPvPVZJIYyonNITekEBy5GoXtQGNJ0yo8XOVBg5riP6nxKqu7tN2L/vn8f/0ujkG//cWqY0JdmVX7dUIkWp7rENdWwOlA== 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 BYAPR10MB2888.namprd10.prod.outlook.com (2603:10b6:a03:88::32) by BYAPR10MB2632.namprd10.prod.outlook.com (2603:10b6:a02:b2::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4690.25; Wed, 17 Nov 2021 07:39:10 +0000 Received: from BYAPR10MB2888.namprd10.prod.outlook.com ([fe80::48bf:86b4:32e1:6574]) by BYAPR10MB2888.namprd10.prod.outlook.com ([fe80::48bf:86b4:32e1:6574%4]) with mapi id 15.20.4690.027; Wed, 17 Nov 2021 07:39:10 +0000 To: libabigail@sourceware.org Subject: [PATCH] abidw: add support for CTF Date: Wed, 17 Nov 2021 08:39:03 +0100 Message-Id: <20211117073903.15773-1-jose.marchesi@oracle.com> X-Mailer: git-send-email 2.11.0 X-ClientProxiedBy: LO4P123CA0412.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:189::21) To BYAPR10MB2888.namprd10.prod.outlook.com (2603:10b6:a03:88::32) MIME-Version: 1.0 Received: from termi.localdomain (141.143.193.70) by LO4P123CA0412.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:189::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4690.25 via Frontend Transport; Wed, 17 Nov 2021 07:39:09 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 9af8bd9c-0b4b-42c5-03aa-08d9a99d5826 X-MS-TrafficTypeDiagnostic: BYAPR10MB2632: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:4502; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: URBCQ9mHkRdwVAWu8DMYvZUBToCmwHyKu+fO5LGYksaFvpufK0WvSKMP93IaGFg5wNQeNBYvlcwRYf+RmvLoyrMgktBy9f3PK2nJJ6ZzGND4MMkv/SFSMS7f1ACS4m7TSiTsMcXPi14IJ0gCIGIh8gad3xG5xnyKFUMCFIbrblwVaZwMnn7N5mEHMz7ATJd7HzOiTOe6ys6VFDXAqtFF96JEI7H6Ixr3RJYLawwJs9p4yiP7Wp1NDt8reYg+EbIsyk6PaCQXtDwbdM1hjncJLrZqBXNpwLVYJGVtCnZIyssK1uALbqo2F7lELHvXq4YUSjVyKHXExzskQ/Srcx9ijstjHE7p8xOFpfvbqeR0o5ywXrvI74JOMYOfMogBqjMTA/xbIxejFEbkMbb0gEH61pXvtXJ12ZrDNCexlGmyAAXA/SyW2rvm9Ng97x3dBgq+DKdxEYqqZB+GYxtDpfQl3YFgBzg84hJ2T/jihVhjS1WC3IEk6S5w2WBQyJpKUVvvSv6Udvx5+ULy/IOOtheTdEBEjd7eD11RIvjO+Wxwi38a5VTVbD8bR34Ss+Uyms+99zEkMmoTx4hMj5PgV89f4Eisw17oL3p9kKmh4Yf7oY11WcTv0QTrvpmiQwbWXA5xilKZq3Q7n/QhyxeFSr3GLZ7sEI4yvUC47fkBBZgm+274fUgb5yC4aok0cYIgPiarlwoxyECntpZnzNuhQiUvjQ== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:BYAPR10MB2888.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(366004)(66556008)(66476007)(86362001)(6916009)(26005)(66946007)(8936002)(6512007)(2616005)(38100700002)(956004)(38350700002)(508600001)(316002)(6666004)(5660300002)(186003)(52116002)(36756003)(1076003)(30864003)(6506007)(2906002)(6486002)(8676002)(83380400001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: mw/ed8eeZZCWbdF7CFod7T0WuiAsVfFvSYOvXIthnk5ttTVvTlpg72cfsQDOe/p3uxI4yFF6aSjQH43lZV4+XUPQiLRPK3Cg2G14Yn1i2RWpreNQWXBDYJIfK9Lgvv/504Ah2KANWzjNlrh7Y8zI8vBDpOnjYVHHCMBhnwp5t4uLQ3xWrATwSh8JRzRLWfTvWQpQHQT796cidKUzSWDLjWrSdLelkZkzT4sLv+uomGXHtbwiEtsOZvvpXgZZTYl/Cxsu8cNeqQ7sx85/ZYz7pWgOlqEFY1GrX0XCICIQzfy9eGJJM9Rw4DMnICOYh5xKV0RSe8rAuYU0mmJjId6L0MtQ+Bi652zUpnimtbyHEF6d9Tzi1DEEB7b2hzlW9tJeHb58i+3C9nVSdwV65qlKt62PxD9r0iYsvZC950btRpOE5DClHchxFiAfj93l+d5miNp5U7fX0XksQusE7Wsj7mtHmvZT+NdMNcZLibliW3f1EICi5fYToh1cKoKTMWUw8ET04f6Sywl+k8HeU0Ow026JE2ZC2vrxTSMm+2x7XGfSZs6l3JRgvnExk9IATCb3AdhDFbtitFsCMFVIZeesxlGJ2trrXiNNrcnzrzovMkbeIQ08GW0jP6kE+UG7bJinEM7pdXVmKpduojA0WahCSeWeQNUzL+EGXgPzLry1zXDqq/G6LvaxqTCVqSZ053qnH9Al/xP7CSlaRs1PbLJ8ufGmP7KiRrTHqdtc3wtrqq5HeKC4pfWhuzcgovLxaZMa7wyyEto/5C371Dtpr32ueJdR3QE0uRB6H7nHeyLe3U61roycp/ZlOapQmURSDDfaZFh7pOTJcRcswTSQ1KosFns4AsnU3Hydkt/qlltWIXKawTFTmOYirmOUEM/NrQq1dwH190dkQRUoDjlZPFezyKbjIuBHPnIOiGLGYvRmTvPaGP/9PM7vNVdwq0P3HJ1AmxZuqdOuHe08NzsfA+xFwRVA7wYLk5w1IQ4jACmonGFYiq3UHFsE+5/3roi2k1aPyhKWGCQ6NQMhe7c/VneJAPxM0lO25gV0HRMwlLTKYVp/0Sp4JwwsCQYToFVeUaqF+D4cBAI0xwLwLo5wTElei8DFlsKBwScOqvcwrQ6OKMgKcqLU2hJaZAdOqVMoLCbG10RxH7ZgCF6VYfRIYuNA0A5xVobTiXOg7ed7LMLwpjMvUlsf3QRWaaWwFkIjn8U+OUhHMYRCET6d4ItBe/pUkKx6AOS58Thxlw4U1xy5opXMpPM9ZY1csHJfJrvDqQXRS/+aNQRx7ZqgVtSpAI4sqFsMfqSa66Bi9CWBLX0Xz4yME1/5zumJD2fraFKewEVDWTRR5C1jCVPHis/DOp4+YxXb2W8wJ1Z0nJSgCdkQEiEHWDNJKapHv+1aAm4QBqWFKOn1jQh7E8HhG4Z5Lkcocdr+YK51ysnH1/1LVcMl1hErJHXz1C2DhnPmfXNtbYRBExm1X2TjemJWyGgchRRw/FH29LdFc15Gd42HEfi+rcDQ5ETHNsm0adnS++cj8czte1o3P/wXFtgFkvZp7IiQCWYbUcAZwErDjw/z9NttglbMD1oZF1A0XEFOpPBHcQM7lGWkeMzMbLPSGqpm5GtiJzDQfgQpRyvBMwL082AIRh0QUOTihhnwjJQA0EEZRmRsOScGPGxly8266d1Lr6828FsgPhIkUBE9F+vRWIDTeFk= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9af8bd9c-0b4b-42c5-03aa-08d9a99d5826 X-MS-Exchange-CrossTenant-AuthSource: BYAPR10MB2888.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Nov 2021 07:39:10.7039 (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: m0t4nGkBaBOd0U2lTdIU280xcAyssqrh4OlwzVf74J6LWmMw0gyaJC8dcQ9bglI4ErRGJixY5VlZ4yzwhvIWsQlLlR0WeubDt6NeHhX6EyI= X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR10MB2632 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10170 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 adultscore=0 mlxscore=0 spamscore=0 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2110150000 definitions=main-2111170034 X-Proofpoint-ORIG-GUID: 62WWNWPJaysFFQL9eWfB2wNXsyd2Zeme X-Proofpoint-GUID: 62WWNWPJaysFFQL9eWfB2wNXsyd2Zeme X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, MSGID_FROM_MTA_HEADER, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: libabigail@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Mailing list of the Libabigail project List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-Patchwork-Original-From: "Jose E. Marchesi via Libabigail" From: "Jose E. Marchesi" Reply-To: "Jose E. Marchesi" Errors-To: libabigail-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libabigail" This patch adds support for CTF to the abidw utility. It depends on the previous patch that makes abigail::ctf_reader::read_corpus to return a status code. Signed-off-by: Jose E. Marchesi * tools/abidw.cc: Conditionally include abg-ctf-reader.h. (load_corpus_and_write_abixml): Do not get a dwarf_reader::read_context as an argument. (main): Adjust call to load_corpus_and_write_abixml accordingly. (struct options): New option use_ctf. (options): ... and initialize it. (display_usage): Document --ctf. (parse_command_line): Handle --ctf. * doc/manuals/abidw.rst: Document --ctf. --- doc/manuals/abidw.rst | 5 + tools/abidw.cc | 363 +++++++++++++++++++++++++++----------------------- 2 files changed, 202 insertions(+), 166 deletions(-) diff --git a/doc/manuals/abidw.rst b/doc/manuals/abidw.rst index fe4aafd8..bdd6204d 100644 --- a/doc/manuals/abidw.rst +++ b/doc/manuals/abidw.rst @@ -268,6 +268,11 @@ Options the --enable-debug-type-canonicalization option. + * ``--ctf`` + + Extract ABI information from CTF debug information, if present in + the given object. + * ``--annotate`` Annotate the ABIXML output with comments above most elements. The diff --git a/tools/abidw.cc b/tools/abidw.cc index 48f509a0..d2bc029b 100644 --- a/tools/abidw.cc +++ b/tools/abidw.cc @@ -26,6 +26,9 @@ #include "abg-tools-utils.h" #include "abg-corpus.h" #include "abg-dwarf-reader.h" +#ifdef WITH_CTF +#include "abg-ctf-reader.h" +#endif #include "abg-writer.h" #include "abg-reader.h" #include "abg-comparison.h" @@ -64,10 +67,6 @@ using abigail::xml_writer::write_context_sptr; using abigail::xml_writer::write_corpus; using abigail::xml_reader::read_corpus_from_native_xml_file; using abigail::xml_reader::create_native_xml_read_context; -using abigail::dwarf_reader::read_context; -using abigail::dwarf_reader::read_context_sptr; -using abigail::dwarf_reader::read_corpus_from_elf; -using abigail::dwarf_reader::create_read_context; using namespace abigail; struct options @@ -99,6 +98,9 @@ struct options bool corpus_group_for_linux; bool show_stats; bool noout; +#ifdef WITH_CTF + bool use_ctf; +#endif bool show_locs; bool abidiff; #ifdef WITH_DEBUG_SELF_COMPARISON @@ -133,6 +135,9 @@ struct options corpus_group_for_linux(false), show_stats(), noout(), +#ifdef WITH_CTF + use_ctf(false), +#endif show_locs(true), abidiff(), #ifdef WITH_DEBUG_SELF_COMPARISON @@ -208,6 +213,9 @@ display_usage(const string& prog_name, ostream& out) #ifdef WITH_DEBUG_TYPE_CANONICALIZATION << " --debug-tc debug the type canonicalization process\n" #endif +#ifdef WITH_CTF + << " --ctf use CTF instead of DWARF in ELF files\n" +#endif << " --annotate annotate the ABI artifacts emitted in the output\n" << " --stats show statistics about various internal stuff\n" << " --verbose show verbose messages about internal stuff\n"; @@ -306,6 +314,10 @@ parse_command_line(int argc, char* argv[], options& opts) } else if (!strcmp(argv[i], "--noout")) opts.noout = true; +#ifdef WITH_CTF + else if (!strcmp(argv[i], "--ctf")) + opts.use_ctf = true; +#endif else if (!strcmp(argv[i], "--no-architecture")) opts.write_architecture = false; else if (!strcmp(argv[i], "--no-corpus-path")) @@ -462,7 +474,7 @@ maybe_check_header_files(const options& opts) /// @param opts the options where to get the suppression /// specifications from. static void -set_suppressions(read_context& read_ctxt, options& opts) +set_suppressions(dwarf_reader::read_context& read_ctxt, options& opts) { suppressions_type supprs; for (vector::const_iterator i = opts.suppression_paths.begin(); @@ -498,8 +510,6 @@ set_suppressions(read_context& read_ctxt, options& opts) /// /// @param env the environment the ABI artifacts are being created in. /// -/// @param context the context of the ELF reading. -/// /// @param opts the options of the program. /// /// @return the exit code: 0 if everything went fine, non-zero @@ -507,7 +517,6 @@ set_suppressions(read_context& read_ctxt, options& opts) static int load_corpus_and_write_abixml(char* argv[], environment_sptr& env, - read_context_sptr& context, options& opts) { int exit_code = 0; @@ -523,24 +532,90 @@ load_corpus_and_write_abixml(char* argv[], env->debug_type_canonicalization_is_on(true); #endif - read_context& ctxt = *context; + // First of all, read a libabigail IR corpus from the file specified + // in OPTS. corpus_sptr corp; elf_reader::status s = elf_reader::STATUS_UNKNOWN; - t.start(); - corp = read_corpus_from_elf(ctxt, s); - t.stop(); - if (opts.do_log) - emit_prefix(argv[0], cerr) - << "read corpus from elf file in: " << t << "\n"; +#ifdef WITH_CTF + if (opts.use_ctf) + { + abigail::ctf_reader::read_context *ctxt + = abigail::ctf_reader::create_read_context (opts.in_file_path, + env.get()); - t.start(); - context.reset(); - t.stop(); + assert (ctxt); + t.start(); + corp = abigail::ctf_reader::read_corpus (ctxt, s); + t.stop(); + if (opts.do_log) + emit_prefix(argv[0], cerr) + << "read corpus from elf file in: " << t << "\n"; + } + else +#endif + { + dwarf_reader::read_context_sptr c + = abigail::dwarf_reader::create_read_context(opts.in_file_path, + opts.prepared_di_root_paths, + env.get(), + opts.load_all_types, + opts.linux_kernel_mode); + dwarf_reader::read_context& ctxt = *c; + set_drop_undefined_syms(ctxt, opts.drop_undefined_syms); + set_show_stats(ctxt, opts.show_stats); + set_suppressions(ctxt, opts); + abigail::dwarf_reader::set_do_log(ctxt, opts.do_log); - if (opts.do_log) - emit_prefix(argv[0], cerr) - << "reset read context in: " << t << "\n"; + if (opts.check_alt_debug_info_path) + { + bool has_alt_di = false; + string alt_di_path; + abigail::elf_reader::status status = + abigail::dwarf_reader::has_alt_debug_info(ctxt, + has_alt_di, + alt_di_path); + if (status & abigail::elf_reader::STATUS_OK) + { + if (alt_di_path.empty()) + ; + else + { + cout << "found the alternate debug info file"; + if (opts.show_base_name_alt_debug_info_path) + { + tools_utils::base_name(alt_di_path, alt_di_path); + cout << " '" << alt_di_path << "'"; + } + cout << "\n"; + } + return 0; + } + else + { + emit_prefix(argv[0], cerr) + << "could not find alternate debug info file\n"; + return 1; + } + } + t.start(); + corp = dwarf_reader::read_corpus_from_elf(ctxt, s); + t.stop(); + if (opts.do_log) + emit_prefix(argv[0], cerr) + << "read corpus from elf file in: " << t << "\n"; + + t.start(); + c.reset(); + t.stop(); + + if (opts.do_log) + emit_prefix(argv[0], cerr) + << "reset read context in: " << t << "\n"; + } + + // If we couldn't create a corpus, emit some (hopefully) useful + // diagnostics and return and error. if (!corp) { if (s == elf_reader::STATUS_DEBUG_INFO_NOT_FOUND) @@ -580,122 +655,122 @@ load_corpus_and_write_abixml(char* argv[], return 1; } - else - { - t.start(); - const write_context_sptr& write_ctxt - = create_write_context(corp->get_environment(), cout); - set_common_options(*write_ctxt, opts); - t.stop(); - if (opts.do_log) - emit_prefix(argv[0], cerr) - << "created & initialized write context in: " - << t << "\n"; + // Now create a write context and write out an ABI XML description + // of the read corpus. + t.start(); + const write_context_sptr& write_ctxt + = create_write_context(corp->get_environment(), cout); + set_common_options(*write_ctxt, opts); + t.stop(); - if (opts.abidiff) - { - // Save the abi in abixml format in a temporary file, read - // it back, and compare the ABI of what we've read back - // against the ABI of the input ELF file. - temp_file_sptr tmp_file = temp_file::create(); - set_ostream(*write_ctxt, tmp_file->get_stream()); - write_corpus(*write_ctxt, corp, 0); - tmp_file->get_stream().flush(); + if (opts.do_log) + emit_prefix(argv[0], cerr) + << "created & initialized write context in: " + << t << "\n"; + + if (opts.abidiff) + { + // Save the abi in abixml format in a temporary file, read + // it back, and compare the ABI of what we've read back + // against the ABI of the input ELF file. + temp_file_sptr tmp_file = temp_file::create(); + set_ostream(*write_ctxt, tmp_file->get_stream()); + write_corpus(*write_ctxt, corp, 0); + tmp_file->get_stream().flush(); #ifdef WITH_DEBUG_SELF_COMPARISON - if (opts.debug_abidiff) - { - opts.type_id_file_path = tmp_file->get_path() + string(".typeid"); - write_canonical_type_ids(*write_ctxt, opts.type_id_file_path); - } + if (opts.debug_abidiff) + { + opts.type_id_file_path = tmp_file->get_path() + string(".typeid"); + write_canonical_type_ids(*write_ctxt, opts.type_id_file_path); + } #endif - xml_reader::read_context_sptr read_ctxt = - create_native_xml_read_context(tmp_file->get_path(), env.get()); + xml_reader::read_context_sptr read_ctxt = + create_native_xml_read_context(tmp_file->get_path(), env.get()); #ifdef WITH_DEBUG_SELF_COMPARISON - if (opts.debug_abidiff - && !opts.type_id_file_path.empty()) - load_canonical_type_ids(*read_ctxt, opts.type_id_file_path); + if (opts.debug_abidiff + && !opts.type_id_file_path.empty()) + load_canonical_type_ids(*read_ctxt, opts.type_id_file_path); #endif - t.start(); - corpus_sptr corp2 = - read_corpus_from_input(*read_ctxt); - t.stop(); - if (opts.do_log) - emit_prefix(argv[0], cerr) - << "Read corpus in: " << t << "\n"; + t.start(); + corpus_sptr corp2 = + read_corpus_from_input(*read_ctxt); + t.stop(); + if (opts.do_log) + emit_prefix(argv[0], cerr) + << "Read corpus in: " << t << "\n"; - if (!corp2) - { - emit_prefix(argv[0], cerr) - << "Could not read temporary XML representation of " - "elf file back\n"; - return 1; - } + if (!corp2) + { + emit_prefix(argv[0], cerr) + << "Could not read temporary XML representation of " + "elf file back\n"; + return 1; + } - diff_context_sptr ctxt(new diff_context); - set_diff_context(ctxt); - ctxt->show_locs(opts.show_locs); - t.start(); - corpus_diff_sptr diff = compute_diff(corp, corp2, ctxt); - t.stop(); - if (opts.do_log) - emit_prefix(argv[0], cerr) - << "computed diff in: " << t << "\n"; + diff_context_sptr ctxt(new diff_context); + set_diff_context(ctxt); + ctxt->show_locs(opts.show_locs); + t.start(); + corpus_diff_sptr diff = compute_diff(corp, corp2, ctxt); + t.stop(); + if (opts.do_log) + emit_prefix(argv[0], cerr) + << "computed diff in: " << t << "\n"; - bool has_error = diff->has_changes(); - if (has_error) - { - t.start(); - diff->report(cerr); - t.stop(); - if (opts.do_log) - emit_prefix(argv[0], cerr) - << "emitted report in: " << t << "\n"; - return 1; - } - return 0; - } + bool has_error = diff->has_changes(); + if (has_error) + { + t.start(); + diff->report(cerr); + t.stop(); + if (opts.do_log) + emit_prefix(argv[0], cerr) + << "emitted report in: " << t << "\n"; + return 1; + } + return 0; + } #ifdef WITH_DEBUG_SELF_COMPARISON - if (opts.debug_abidiff - && !opts.type_id_file_path.empty()) - remove(opts.type_id_file_path.c_str()); + if (opts.debug_abidiff + && !opts.type_id_file_path.empty()) + remove(opts.type_id_file_path.c_str()); #endif - if (opts.noout) - return 0; + if (opts.noout) + return 0; - if (!opts.out_file_path.empty()) - { - ofstream of(opts.out_file_path.c_str(), std::ios_base::trunc); - if (!of.is_open()) - { - emit_prefix(argv[0], cerr) - << "could not open output file '" - << opts.out_file_path << "'\n"; - return 1; - } - set_ostream(*write_ctxt, of); - t.start(); - write_corpus(*write_ctxt, corp, 0); - t.stop(); - if (opts.do_log) - emit_prefix(argv[0], cerr) - << "emitted abixml output in: " << t << "\n"; - of.close(); - return 0; - } - else - { - t.start(); - exit_code = !write_corpus(*write_ctxt, corp, 0); - t.stop(); - if (opts.do_log) - emit_prefix(argv[0], cerr) - << "emitted abixml out in: " << t << "\n"; - } + if (!opts.out_file_path.empty()) + { + ofstream of(opts.out_file_path.c_str(), std::ios_base::trunc); + if (!of.is_open()) + { + emit_prefix(argv[0], cerr) + << "could not open output file '" + << opts.out_file_path << "'\n"; + return 1; + } + set_ostream(*write_ctxt, of); + t.start(); + write_corpus(*write_ctxt, corp, 0); + t.stop(); + if (opts.do_log) + emit_prefix(argv[0], cerr) + << "emitted abixml output in: " << t << "\n"; + of.close(); + return 0; + } + else + { + t.start(); + exit_code = !write_corpus(*write_ctxt, corp, 0); + t.stop(); + if (opts.do_log) + emit_prefix(argv[0], cerr) + << "emitted abixml out in: " << t << "\n"; } return exit_code; @@ -884,51 +959,7 @@ main(int argc, char* argv[]) int exit_code = 0; if (tools_utils::is_regular_file(opts.in_file_path)) - { - read_context_sptr c = create_read_context(opts.in_file_path, - opts.prepared_di_root_paths, - env.get(), - opts.load_all_types, - opts.linux_kernel_mode); - read_context& ctxt = *c; - set_drop_undefined_syms(ctxt, opts.drop_undefined_syms); - set_show_stats(ctxt, opts.show_stats); - set_suppressions(ctxt, opts); - abigail::dwarf_reader::set_do_log(ctxt, opts.do_log); - - if (opts.check_alt_debug_info_path) - { - bool has_alt_di = false; - string alt_di_path; - abigail::elf_reader::status status = - abigail::dwarf_reader::has_alt_debug_info(ctxt, - has_alt_di, - alt_di_path); - if (status & abigail::elf_reader::STATUS_OK) - { - if (alt_di_path.empty()) - ; - else - { - cout << "found the alternate debug info file"; - if (opts.show_base_name_alt_debug_info_path) - { - tools_utils::base_name(alt_di_path, alt_di_path); - cout << " '" << alt_di_path << "'"; - } - cout << "\n"; - } - return 0; - } - else - { - emit_prefix(argv[0], cerr) - << "could not find alternate debug info file\n"; - return 1; - } - } - exit_code = load_corpus_and_write_abixml(argv, env, c, opts); - } + exit_code = load_corpus_and_write_abixml(argv, env, opts); else exit_code = load_kernel_corpus_group_and_write_abixml(argv, env, opts);