From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from barracuda.ebox.ca (barracuda.ebox.ca [96.127.255.19]) by sourceware.org (Postfix) with ESMTPS id 48CB2383981B for ; Wed, 6 Apr 2022 14:42:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 48CB2383981B X-ASG-Debug-ID: 1649256127-0c856e06adaebe30001-fS2M51 Received: from smtp.ebox.ca (smtp.ebox.ca [96.127.255.82]) by barracuda.ebox.ca with ESMTP id jISZ5KPvPkAxPzQX (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Wed, 06 Apr 2022 10:42:07 -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 0A336441D64; Wed, 6 Apr 2022 10:42:07 -0400 (EDT) From: Simon Marchi 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 Cc: Simon Marchi Subject: [PATCH 1/4] gdb: remove symtab::dirname Date: Wed, 6 Apr 2022 10:42:02 -0400 X-ASG-Orig-Subj: [PATCH 1/4] gdb: remove symtab::dirname Message-Id: <20220406144205.1415376-2-simon.marchi@polymtl.ca> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220406144205.1415376-1-simon.marchi@polymtl.ca> References: <20220406144205.1415376-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: 1649256127 X-Barracuda-Encrypted: DHE-RSA-AES256-SHA X-Barracuda-URL: https://96.127.255.19:443/cgi-mod/mark.cgi X-Barracuda-BRTS-Status: 1 X-Virus-Scanned: by bsmtpd at ebox.ca X-Barracuda-Scan-Msg-Size: 5204 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.97169 Rule breakdown below pts rule name description ---- ---------------------- -------------------------------------------------- 0.50 BSF_RULE7568M Custom Rule 7568M X-Spam-Status: No, score=-3613.0 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_QUARANTINE, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_SOFTFAIL, 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: 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: Wed, 06 Apr 2022 14:42:18 -0000 From: Simon Marchi I think the symtab::dirname method is bogus, or at least very misleading. It makes you think that it returns the directory that was used to find that symtab's file during compilation (i.e. the directory the file refers to in the DWARF line header file table), or the directory part of the symtab's filename maybe. In fact, it returns the compilation unit's directory, which is the CWD of the compiler, at compilation time. At least for DWARF, if the symtab's filename is relative, it will be relative to that directory. But if the symtab's filename is absolute, then the directory returned by symtab::dirname has nothing to do with the symtab's filename. Remove symtab::dirname to avoid this confusion, change all users to fetch the same information through the compunit. At least, it will be clear that this is a compunit property, not a symtab property. Change-Id: I2894c3bf3789d7359a676db3c58be2c10763f5f0 --- gdb/cli/cli-cmds.c | 4 ++-- gdb/source.c | 15 ++++++++------- gdb/symmisc.c | 4 ++-- gdb/symtab.h | 8 -------- 4 files changed, 12 insertions(+), 19 deletions(-) diff --git a/gdb/cli/cli-cmds.c b/gdb/cli/cli-cmds.c index 945fd354d52e..31b493e1c500 100644 --- a/gdb/cli/cli-cmds.c +++ b/gdb/cli/cli-cmds.c @@ -2050,8 +2050,8 @@ ambiguous_line_spec (gdb::array_view sals, static int cmp_symtabs (const symtab_and_line &sala, const symtab_and_line &salb) { - const char *dira = sala.symtab->dirname (); - const char *dirb = salb.symtab->dirname (); + const char *dira = sala.symtab->compunit ()->dirname (); + const char *dirb = salb.symtab->compunit ()->dirname (); int r; if (dira == NULL) diff --git a/gdb/source.c b/gdb/source.c index 020e94d4ae95..2025c93e93e3 100644 --- a/gdb/source.c +++ b/gdb/source.c @@ -713,8 +713,8 @@ info_source_command (const char *ignore, int from_tty) cust = s->compunit (); gdb_printf (_("Current source file is %s\n"), s->filename); - if (s->dirname () != NULL) - gdb_printf (_("Compilation directory is %s\n"), s->dirname ()); + if (s->compunit ()->dirname () != NULL) + gdb_printf (_("Compilation directory is %s\n"), s->compunit ()->dirname ()); if (s->fullname) gdb_printf (_("Located in %s\n"), s->fullname); const std::vector *offsets; @@ -1180,7 +1180,7 @@ open_source_file (struct symtab *s) gdb::unique_xmalloc_ptr fullname (s->fullname); s->fullname = NULL; - scoped_fd fd = find_and_open_source (s->filename, s->dirname (), + scoped_fd fd = find_and_open_source (s->filename, s->compunit ()->dirname (), &fullname); if (fd.get () < 0) @@ -1192,9 +1192,9 @@ open_source_file (struct symtab *s) std::string srcpath; if (IS_ABSOLUTE_PATH (s->filename)) srcpath = s->filename; - else if (s->dirname () != nullptr) + else if (s->compunit ()->dirname () != nullptr) { - srcpath = s->dirname (); + srcpath = s->compunit ()->dirname (); srcpath += SLASH_STRING; srcpath += s->filename; } @@ -1268,10 +1268,11 @@ symtab_to_fullname (struct symtab *s) /* rewrite_source_path would be applied by find_and_open_source, we should report the pathname where GDB tried to find the file. */ - if (s->dirname () == NULL || IS_ABSOLUTE_PATH (s->filename)) + if (s->compunit ()->dirname () == nullptr + || IS_ABSOLUTE_PATH (s->filename)) fullname.reset (xstrdup (s->filename)); else - fullname.reset (concat (s->dirname (), SLASH_STRING, + fullname.reset (concat (s->compunit ()->dirname (), SLASH_STRING, s->filename, (char *) NULL)); s->fullname = rewrite_source_path (fullname.get ()).release (); diff --git a/gdb/symmisc.c b/gdb/symmisc.c index e8092e8af08a..5d8d641fa275 100644 --- a/gdb/symmisc.c +++ b/gdb/symmisc.c @@ -249,9 +249,9 @@ dump_symtab_1 (struct symtab *symtab, struct ui_file *outfile) symtab_to_filename_for_display (symtab), host_address_to_string (symtab)); - if (symtab->dirname () != NULL) + if (symtab->compunit ()->dirname () != NULL) gdb_printf (outfile, "Compilation directory is %s\n", - symtab->dirname ()); + symtab->compunit ()->dirname ()); gdb_printf (outfile, "Read from object file %s (%s)\n", objfile_name (objfile), host_address_to_string (objfile)); diff --git a/gdb/symtab.h b/gdb/symtab.h index 25b4f7d2704b..567c0fcce7c0 100644 --- a/gdb/symtab.h +++ b/gdb/symtab.h @@ -1482,8 +1482,6 @@ struct symtab program_space *pspace () const; - const char *dirname () const; - /* Unordered chain of all filetabs in the compunit, with the exception that the "main" source file is the first entry in the list. */ @@ -1769,12 +1767,6 @@ symtab::objfile () const return this->compunit ()->objfile (); } -inline const char * -symtab::dirname () const -{ - return this->compunit ()->dirname (); -} - /* Return the language of CUST. */ extern enum language compunit_language (const struct compunit_symtab *cust); -- 2.35.1