From patchwork Fri Mar 11 14:49:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Wielaard X-Patchwork-Id: 51895 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 6A7A23857018 for ; Fri, 11 Mar 2022 14:49:25 +0000 (GMT) X-Original-To: elfutils-devel@sourceware.org Delivered-To: elfutils-devel@sourceware.org Received: from gnu.wildebeest.org (gnu.wildebeest.org [45.83.234.184]) by sourceware.org (Postfix) with ESMTPS id 451BA3858D3C for ; Fri, 11 Mar 2022 14:49:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 451BA3858D3C Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=klomp.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=klomp.org Received: from tarox.wildebeest.org (83-87-18-245.cable.dynamic.v4.ziggo.nl [83.87.18.245]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by gnu.wildebeest.org (Postfix) with ESMTPSA id 3DA4030006D6; Fri, 11 Mar 2022 15:49:14 +0100 (CET) Received: by tarox.wildebeest.org (Postfix, from userid 1000) id D6A22425A47C; Fri, 11 Mar 2022 15:49:13 +0100 (CET) From: Mark Wielaard To: elfutils-devel@sourceware.org Subject: [PATCH] addr2line: Make --absolute the default, add --relative option. Date: Fri, 11 Mar 2022 15:49:10 +0100 Message-Id: <20220311144910.20892-1-mark@klomp.org> X-Mailer: git-send-email 2.18.4 X-Spam-Status: No, score=-10.0 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE 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: elfutils-devel@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Elfutils-devel mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , Cc: Mark Wielaard Errors-To: elfutils-devel-bounces+patchwork=sourceware.org@sourceware.org Sender: "Elfutils-devel" Make --absolute (including the compilation directory in file names) the default and add a new option --relative to get the previous default behavior. https://www.sourceware.org/bugzilla/show_bug.cgi?id=28951 Signed-off-by: Mark Wielaard --- ChangeLog | 4 ++++ NEWS | 3 +++ src/ChangeLog | 7 +++++++ src/addr2line.c | 14 +++++++++++--- 4 files changed, 25 insertions(+), 3 deletions(-) https://code.wildebeest.org/git/user/mjw/elfutils/commit/?h=addr2line-relative diff --git a/ChangeLog b/ChangeLog index f00db17b..4035dffb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2021-03-11 Mark Wielaard + + * NEWS: Document new --relative option for addr2line. + 2021-12-04 Mark Wielaard * configure.ac: Add --enable-sanitize-address. diff --git a/NEWS b/NEWS index 6be58866..ea74c019 100644 --- a/NEWS +++ b/NEWS @@ -2,6 +2,9 @@ Version 0.187 after 0.186 debuginfod: Support -C option for connection thread pooling. +addr2line: The -A, --absolute option, which shows file names including + the full compilation directory is now the default. To get the + old behavior use the new option --relative. Version 0.186 diff --git a/src/ChangeLog b/src/ChangeLog index 263e9faa..0e705b7d 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,10 @@ +2022-03-11 Mark Wielaard + + * addr2line.c (OPT_RELATIVE): New constant. + (options): Add --relative. + (use_comp_dir): Initialize to true. + (parse_opt): Handle OPT_RELATIVE. + 2021-12-04 Mark Wielaard * readelf.c (print_ehdr): Pass sizeof (buf) - 1 to strncpy. diff --git a/src/addr2line.c b/src/addr2line.c index 34945046..7c8d3a72 100644 --- a/src/addr2line.c +++ b/src/addr2line.c @@ -1,5 +1,6 @@ /* Locate source files and line information for given addresses Copyright (C) 2005-2010, 2012, 2013, 2015 Red Hat, Inc. + Copyright (C) 2022 Mark J. Wielaard This file is part of elfutils. Written by Ulrich Drepper , 2005. @@ -49,7 +50,8 @@ ARGP_PROGRAM_BUG_ADDRESS_DEF = PACKAGE_BUGREPORT; /* Values for the parameters which have no short form. */ #define OPT_DEMANGLER 0x100 -#define OPT_PRETTY 0x101 /* 'p' is already used to select the process. */ +#define OPT_PRETTY 0x101 /* 'p' is already used to select the process. */ +#define OPT_RELATIVE 0x102 /* 'r' is something else in binutils addr2line. */ /* Definitions of arguments for argp functions. */ static const struct argp_option options[] = @@ -62,7 +64,7 @@ static const struct argp_option options[] = { "addresses", 'a', NULL, 0, N_("Print address before each entry"), 0 }, { "basenames", 's', NULL, 0, N_("Show only base names of source files"), 0 }, { "absolute", 'A', NULL, 0, - N_("Show absolute file names using compilation directory"), 0 }, + N_("Show absolute file names using compilation directory (default)"), 0 }, { "functions", 'f', NULL, 0, N_("Also show function names"), 0 }, { "symbols", 'S', NULL, 0, N_("Also show symbol or section names"), 0 }, { "symbols-sections", 'x', NULL, 0, N_("Also show symbol and the section names"), 0 }, @@ -74,6 +76,8 @@ static const struct argp_option options[] = N_("Show demangled symbols (ARG is always ignored)"), 0 }, { "pretty-print", OPT_PRETTY, NULL, 0, N_("Print all information on one line, and indent inlines"), 0 }, + { "relative", OPT_RELATIVE, NULL, 0, + N_("Show relative file names without compilation directory"), 0 }, { NULL, 0, NULL, 0, N_("Miscellaneous:"), 0 }, /* Unsupported options. */ @@ -111,7 +115,7 @@ static bool print_addresses; static bool only_basenames; /* True if absolute file names based on DW_AT_comp_dir should be shown. */ -static bool use_comp_dir; +static bool use_comp_dir = true; /* True if line flags should be shown. */ static bool show_flags; @@ -236,6 +240,10 @@ parse_opt (int key, char *arg, struct argp_state *state) use_comp_dir = true; break; + case OPT_RELATIVE: + use_comp_dir = false; + break; + case 'f': show_functions = true; break;