From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id wOeBOvoLamL0AwMAWB0awg (envelope-from ) for ; Wed, 27 Apr 2022 23:37:30 -0400 Received: by simark.ca (Postfix, from userid 112) id EB1751E058; Wed, 27 Apr 2022 23:37:30 -0400 (EDT) Authentication-Results: simark.ca; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=ulcmlooX; dkim-atps=neutral X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RDNS_DYNAMIC,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 800521E00E for ; Wed, 27 Apr 2022 23:37:30 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2E5ED3857823 for ; Thu, 28 Apr 2022 03:37:30 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2E5ED3857823 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1651117050; bh=tZah87EMhwPgCyO+xNKs3n+dmmgNDWOCedgRQWdRQGY=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=ulcmlooXGj8GaS/EeMfb+TmCFTQvxazTu9Hj4dFdp0aX8FQH3Ca2U0K1RW4pp48UZ FCvlyQnLNBqa4ECN3Ucq+ZzBynQhOTlS3L/W71aEyv7s9QPhNZpEKL4ipI7za13d0j AFCfEZsmR2/eU4DbKM/p5IClngawXsycfA9TJQFg= Received: from barracuda.ebox.ca (barracuda.ebox.ca [96.127.255.19]) by sourceware.org (Postfix) with ESMTPS id EA0603857415 for ; Thu, 28 Apr 2022 03:35:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org EA0603857415 X-ASG-Debug-ID: 1651116943-0c856e06add0a470001-fS2M51 Received: from smtp.ebox.ca (smtp.ebox.ca [96.127.255.82]) by barracuda.ebox.ca with ESMTP id aihqQ9bEZyi6bsWh (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Wed, 27 Apr 2022 23:35:43 -0400 (EDT) X-Barracuda-Envelope-From: simon.marchi@polymtl.ca X-Barracuda-RBL-Trusted-Forwarder: 96.127.255.82 Received: from simark.localdomain (192-222-157-6.qc.cable.ebox.net [192.222.157.6]) by smtp.ebox.ca (Postfix) with ESMTP id C49A0441D67; Wed, 27 Apr 2022 23:35:43 -0400 (EDT) X-Barracuda-RBL-IP: 192.222.157.6 X-Barracuda-Effective-Source-IP: 192-222-157-6.qc.cable.ebox.net[192.222.157.6] X-Barracuda-Apparent-Source-IP: 192.222.157.6 To: gdb-patches@sourceware.org Subject: [PATCH v3 4/7] gdb/dwarf: pass a file_entry to line_header::file_file_name Date: Wed, 27 Apr 2022 23:35:39 -0400 X-ASG-Orig-Subj: [PATCH v3 4/7] gdb/dwarf: pass a file_entry to line_header::file_file_name Message-Id: <20220428033542.1636284-5-simon.marchi@polymtl.ca> X-Mailer: git-send-email 2.35.2 In-Reply-To: <20220428033542.1636284-1-simon.marchi@polymtl.ca> References: <20220428033542.1636284-1-simon.marchi@polymtl.ca> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Barracuda-Connect: smtp.ebox.ca[96.127.255.82] X-Barracuda-Start-Time: 1651116943 X-Barracuda-Encrypted: DHE-RSA-AES256-SHA X-Barracuda-URL: https://96.127.255.19:443/cgi-mod/mark.cgi X-Virus-Scanned: by bsmtpd at ebox.ca X-Barracuda-Scan-Msg-Size: 5681 X-Barracuda-BRTS-Status: 1 X-Barracuda-Spam-Score: 0.50 X-Barracuda-Spam-Status: No, SCORE=0.50 using global scores of TAG_LEVEL=1000.0 QUARANTINE_LEVEL=1000.0 KILL_LEVEL=8.0 tests=BSF_RULE7568M X-Barracuda-Spam-Report: Code version 3.2, rules version 3.2.3.97646 Rule breakdown below pts rule name description ---- ---------------------- -------------------------------------------------- 0.50 BSF_RULE7568M Custom Rule 7568M 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: , From: Simon Marchi via Gdb-patches Reply-To: Simon Marchi Errors-To: gdb-patches-bounces+public-inbox=simark.ca@sourceware.org Sender: "Gdb-patches" In the following patch, there will be some callers of file_file_name that will already have access to the file_entry object for which they want the file name. It would be inefficient to have them pass an index, only for line_header::file_file_name to re-lookup the same file_entry object. Change line_header::file_file_name to accept a file_entry object reference, instead of an index to look up. I think this change makes sense in any case. Callers that have an index can first obtain a file_entry using line_header::file_name_at or line_header::file_names. When passing a file_entry object, we can assume that the file_entry's index is valid, unlike when passing an index. So, push the special case about an invalid index to the sole current caller of file_file_name, macro_start_file. I think that error belongs there anyway, since it specifically talks about "bad file number in macro information". This requires recording the file index in the file_entry structure, so add that. Change-Id: Ic6e44c407539d92b7863d7ba82405ade17f384ad --- gdb/dwarf2/line-header.c | 47 ++++++++++++---------------------------- gdb/dwarf2/line-header.h | 10 ++++++--- gdb/dwarf2/macro.c | 16 +++++++++++++- 3 files changed, 36 insertions(+), 37 deletions(-) diff --git a/gdb/dwarf2/line-header.c b/gdb/dwarf2/line-header.c index 13379851b9b6..33af77d3ecf3 100644 --- a/gdb/dwarf2/line-header.c +++ b/gdb/dwarf2/line-header.c @@ -48,47 +48,28 @@ line_header::add_file_name (const char *name, unsigned int mod_time, unsigned int length) { + file_name_index index + = version >= 5 ? file_names_size (): file_names_size () + 1; + if (dwarf_line_debug >= 2) - { - size_t new_size; - if (version >= 5) - new_size = file_names_size (); - else - new_size = file_names_size () + 1; - gdb_printf (gdb_stdlog, "Adding file %zu: %s\n", - new_size, name); - } - m_file_names.emplace_back (name, d_index, mod_time, length); + gdb_printf (gdb_stdlog, "Adding file %d: %s\n", index, name); + + m_file_names.emplace_back (name, index, d_index, mod_time, length); } std::string -line_header::file_file_name (int file) const +line_header::file_file_name (const file_entry &fe) const { - /* Is the file number a valid index into the line header's file name - table? Remember that file numbers start with one, not zero. */ - if (is_valid_file_index (file)) - { - const file_entry *fe = file_name_at (file); + gdb_assert (is_valid_file_index (fe.index)); - if (!IS_ABSOLUTE_PATH (fe->name)) - { - const char *dir = fe->include_dir (this); - if (dir != NULL) - return path_join (dir, fe->name); - } + if (IS_ABSOLUTE_PATH (fe.name)) + return fe.name; - return fe->name; - } - else - { - /* The compiler produced a bogus file number. We can at least - record the macro definitions made in the file, even if we - won't be able to find the file by name. */ - complaint (_("bad file number in macro information (%d)"), - file); + const char *dir = fe.include_dir (this); + if (dir != nullptr) + return path_join (dir, fe.name); - return string_printf ("", file); - } + return fe.name; } static void diff --git a/gdb/dwarf2/line-header.h b/gdb/dwarf2/line-header.h index 53db3a1d5aa8..0fe539b0c427 100644 --- a/gdb/dwarf2/line-header.h +++ b/gdb/dwarf2/line-header.h @@ -36,9 +36,10 @@ struct file_entry { file_entry () = default; - file_entry (const char *name_, dir_index d_index_, + file_entry (const char *name_, file_name_index index_, dir_index d_index_, unsigned int mod_time_, unsigned int length_) : name (name_), + index (index_), d_index (d_index_), mod_time (mod_time_), length (length_) @@ -52,6 +53,9 @@ struct file_entry owned by debug_line_buffer. */ const char *name {}; + /* The index of this file in the file table. */ + file_name_index index {}; + /* The directory index (1-based). */ dir_index d_index {}; @@ -168,8 +172,8 @@ struct line_header const gdb_byte *statement_program_start {}, *statement_program_end {}; /* Return file name relative to the compilation directory of file - number FILE in this object's file name table. */ - std::string file_file_name (int file) const; + FE in this object's file name table. */ + std::string file_file_name (const file_entry &fe) const; /* Return the compilation directory of the compilation unit in the context of which this line header is read. Return nullptr if non applicable. */ diff --git a/gdb/dwarf2/macro.c b/gdb/dwarf2/macro.c index 99c3653a2c3a..38c0fdfec738 100644 --- a/gdb/dwarf2/macro.c +++ b/gdb/dwarf2/macro.c @@ -52,7 +52,21 @@ macro_start_file (buildsym_compunit *builder, const struct line_header *lh) { /* File name relative to the compilation directory of this source file. */ - std::string file_name = lh->file_file_name (file); + const file_entry *fe = lh->file_name_at (file); + std::string file_name; + + if (fe != nullptr) + file_name = lh->file_file_name (*fe); + else + { + /* The compiler produced a bogus file number. We can at least + record the macro definitions made in the file, even if we + won't be able to find the file by name. */ + complaint (_("bad file number in macro information (%d)"), + file); + + file_name = string_printf ("", file); + } if (! current_file) { -- 2.35.2