From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id sOHeNN4LamL0AwMAWB0awg (envelope-from ) for ; Wed, 27 Apr 2022 23:37:02 -0400 Received: by simark.ca (Postfix, from userid 112) id D52F41E058; Wed, 27 Apr 2022 23:37:02 -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=tr7WlbwT; 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 392361E00E for ; Wed, 27 Apr 2022 23:37:02 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id DD074385842B for ; Thu, 28 Apr 2022 03:37:01 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DD074385842B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1651117021; bh=aC/TB2epKgYBtYkMVn4DjLrhulnPoPSAHM4c03nEt7g=; 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=tr7WlbwTG0ULB/QlzKRt6dsIIuShoYhewHBOR2CQAKamoBoiIKHYkrz/rSzwLWvXC 6rb2nOAYizHODu3aZwTH2QDCcuW848qYQYImgdkVDKr0Ksf7if82ioDLjVMMckaJzr 2isp9528InBG20VV1ryfc/kMGIPPWQBAeZiwwB24= Received: from barracuda.ebox.ca (barracuda.ebox.ca [96.127.255.19]) by sourceware.org (Postfix) with ESMTPS id C600B3857340 for ; Thu, 28 Apr 2022 03:35:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org C600B3857340 X-ASG-Debug-ID: 1651116943-0c856e06abd07b90001-fS2M51 Received: from smtp.ebox.ca (smtp.ebox.ca [96.127.255.82]) by barracuda.ebox.ca with ESMTP id UrnIvklBKzz4wiKG (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 AF725441D66; 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 3/7] gdb/dwarf: pass compilation directory to line header Date: Wed, 27 Apr 2022 23:35:38 -0400 X-ASG-Orig-Subj: [PATCH v3 3/7] gdb/dwarf: pass compilation directory to line header Message-Id: <20220428033542.1636284-4-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: 8949 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" The following patch changes line_header::file_file_name to prepend the compilation directory to the file name, if needed. For that, the line header needs to know about the compilation directory. Prepare for that by adding a constructor that takes it as a parameter, and passing the value down everywhere needed. Add a second constructor for the special case of building a line_header for doing a hash table lookup, since that case doesn't require a compilation directory value. Change-Id: Iba3ba0293e4e2d13a64b257cf9a3094684d54330 --- gdb/dwarf2/line-header.c | 5 ++-- gdb/dwarf2/line-header.h | 26 +++++++++++++++--- gdb/dwarf2/read.c | 27 ++++++++++--------- .../gdb.dwarf2/dw2-compdir-oldgcc.exp | 2 +- 4 files changed, 42 insertions(+), 18 deletions(-) diff --git a/gdb/dwarf2/line-header.c b/gdb/dwarf2/line-header.c index 63230847568c..13379851b9b6 100644 --- a/gdb/dwarf2/line-header.c +++ b/gdb/dwarf2/line-header.c @@ -264,7 +264,8 @@ line_header_up dwarf_decode_line_header (sect_offset sect_off, bool is_dwz, dwarf2_per_objfile *per_objfile, struct dwarf2_section_info *section, - const struct comp_unit_head *cu_header) + const struct comp_unit_head *cu_header, + const char *comp_dir) { const gdb_byte *line_ptr; unsigned int bytes_read, offset_size; @@ -281,7 +282,7 @@ dwarf_decode_line_header (sect_offset sect_off, bool is_dwz, return 0; } - line_header_up lh (new line_header ()); + line_header_up lh (new line_header (comp_dir)); lh->sect_off = sect_off; lh->offset_in_dwz = is_dwz; diff --git a/gdb/dwarf2/line-header.h b/gdb/dwarf2/line-header.h index 59b317d0d727..53db3a1d5aa8 100644 --- a/gdb/dwarf2/line-header.h +++ b/gdb/dwarf2/line-header.h @@ -68,8 +68,18 @@ struct file_entry which contains the following information. */ struct line_header { - line_header () - : offset_in_dwz {} + /* COMP_DIR is the value of the DW_AT_comp_dir attribute of the compilation + unit in the context of which we are reading this line header, or nullptr + if not applicable. */ + line_header (const char *comp_dir) + : m_comp_dir (comp_dir != nullptr ? comp_dir : "") + {} + + /* This constructor should only be used to create line_header intances to do + hash table lookups. */ + line_header (sect_offset sect_off, bool offset_in_dwz) + : sect_off (sect_off), + offset_in_dwz (offset_in_dwz) {} /* Add an entry to the include directory table. */ @@ -161,6 +171,11 @@ struct line_header number FILE in this object's file name table. */ std::string file_file_name (int file) const; + /* Return the compilation directory of the compilation unit in the context of + which this line header is read. Return nullptr if non applicable. */ + const char *comp_dir () const + { return !m_comp_dir.empty () ? m_comp_dir.c_str () : nullptr; } + private: /* The include_directories table. Note these are observing pointers. The memory is owned by debug_line_buffer. */ @@ -171,6 +186,10 @@ struct line_header before, and is 0 in DWARF 5 and later). So the client should use file_name_at method for access. */ std::vector m_file_names; + + /* Compilation directory of the compilation unit in the context of which this + line header is read. */ + std::string m_comp_dir; }; typedef std::unique_ptr line_header_up; @@ -191,6 +210,7 @@ file_entry::include_dir (const line_header *lh) const extern line_header_up dwarf_decode_line_header (sect_offset sect_off, bool is_dwz, dwarf2_per_objfile *per_objfile, - struct dwarf2_section_info *section, const struct comp_unit_head *cu_header); + struct dwarf2_section_info *section, const struct comp_unit_head *cu_header, + const char *comp_dir); #endif /* DWARF2_LINE_HEADER_H */ diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index d146d5250669..56f58a004af6 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -943,7 +943,8 @@ static struct die_info *die_specification (struct die_info *die, struct dwarf2_cu **); static line_header_up dwarf_decode_line_header (sect_offset sect_off, - struct dwarf2_cu *cu); + struct dwarf2_cu *cu, + const char *comp_dir); static void dwarf_decode_lines (struct line_header *, struct dwarf2_cu *, @@ -2738,6 +2739,8 @@ dw2_get_file_names_reader (const struct die_reader_specs *reader, line_header_up lh; sect_offset line_offset {}; + file_and_directory &fnd = find_file_and_directory (comp_unit_die, cu); + attr = dwarf2_attr (comp_unit_die, DW_AT_stmt_list, cu); if (attr != nullptr && attr->form_is_unsigned ()) { @@ -2757,11 +2760,9 @@ dw2_get_file_names_reader (const struct die_reader_specs *reader, return; } - lh = dwarf_decode_line_header (line_offset, cu); + lh = dwarf_decode_line_header (line_offset, cu, fnd.get_comp_dir ()); } - file_and_directory &fnd = find_file_and_directory (comp_unit_die, cu); - int offset = 0; if (!fnd.is_unknown ()) ++offset; @@ -9416,11 +9417,11 @@ find_file_and_directory (struct die_info *die, struct dwarf2_cu *cu) static void handle_DW_AT_stmt_list (struct die_info *die, struct dwarf2_cu *cu, + const file_and_directory &fnd, CORE_ADDR lowpc) /* ARI: editCase function */ { dwarf2_per_objfile *per_objfile = cu->per_objfile; struct attribute *attr; - struct line_header line_header_local; hashval_t line_header_local_hash; void **slot; int decode_mapping; @@ -9449,8 +9450,7 @@ handle_DW_AT_stmt_list (struct die_info *die, struct dwarf2_cu *cu, xcalloc, xfree)); } - line_header_local.sect_off = line_offset; - line_header_local.offset_in_dwz = cu->per_cu->is_dwz; + line_header line_header_local (line_offset, cu->per_cu->is_dwz); line_header_local_hash = line_header_hash (&line_header_local); if (per_objfile->line_header_hash != NULL) { @@ -9471,7 +9471,8 @@ handle_DW_AT_stmt_list (struct die_info *die, struct dwarf2_cu *cu, /* dwarf_decode_line_header does not yet provide sufficient information. We always have to call also dwarf_decode_lines for it. */ - line_header_up lh = dwarf_decode_line_header (line_offset, cu); + line_header_up lh = dwarf_decode_line_header (line_offset, cu, + fnd.get_comp_dir ()); if (lh == NULL) return; @@ -9549,7 +9550,7 @@ read_file_scope (struct die_info *die, struct dwarf2_cu *cu) lnp_state_machine::check_line_address) will fail to properly exclude an entry that was removed via --gc-sections. */ if (lowpc != highpc) - handle_DW_AT_stmt_list (die, cu, lowpc); + handle_DW_AT_stmt_list (die, cu, fnd, lowpc); /* Process all dies in compilation unit. */ if (die->child != NULL) @@ -9623,7 +9624,7 @@ dwarf2_cu::setup_type_unit_groups (struct die_info *die) if (attr != NULL && attr->form_is_unsigned ()) { sect_offset line_offset = (sect_offset) attr->as_unsigned (); - lh = dwarf_decode_line_header (line_offset, this); + lh = dwarf_decode_line_header (line_offset, this, nullptr); } if (lh == NULL) { @@ -19664,7 +19665,8 @@ get_debug_line_section (struct dwarf2_cu *cu) and must not be freed. */ static line_header_up -dwarf_decode_line_header (sect_offset sect_off, struct dwarf2_cu *cu) +dwarf_decode_line_header (sect_offset sect_off, struct dwarf2_cu *cu, + const char *comp_dir) { struct dwarf2_section_info *section; dwarf2_per_objfile *per_objfile = cu->per_objfile; @@ -19681,7 +19683,8 @@ dwarf_decode_line_header (sect_offset sect_off, struct dwarf2_cu *cu) } return dwarf_decode_line_header (sect_off, cu->per_cu->is_dwz, - per_objfile, section, &cu->header); + per_objfile, section, &cu->header, + comp_dir); } /* Subroutine of dwarf_decode_lines to simplify it. diff --git a/gdb/testsuite/gdb.dwarf2/dw2-compdir-oldgcc.exp b/gdb/testsuite/gdb.dwarf2/dw2-compdir-oldgcc.exp index 0766b9688aeb..0601d26f4e86 100644 --- a/gdb/testsuite/gdb.dwarf2/dw2-compdir-oldgcc.exp +++ b/gdb/testsuite/gdb.dwarf2/dw2-compdir-oldgcc.exp @@ -30,7 +30,7 @@ if {[prepare_for_testing "failed to prepare" $testfile $srcfile \ # Here should be GDB-computed "Compilation directory is". gdb_test "list gcc42" ".*" -gdb_test "info source" "\r\nCurrent source file is dw2-compdir-oldgcc42.S\r\nCompilation directory is /dir/d\r\n.*" \ +gdb_test "info source" "\r\nCurrent source file is /dir/d/dw2-compdir-oldgcc42.S\r\nCompilation directory is /dir/d\r\n.*" \ "info source gcc42" # Here should not be GDB-computed "Compilation directory is". -- 2.35.2