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 539AF385801E for ; Thu, 14 Apr 2022 20:01:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 539AF385801E X-ASG-Debug-ID: 1649966498-0c856e06adba2140001-fS2M51 Received: from smtp.ebox.ca (smtp.ebox.ca [96.127.255.82]) by barracuda.ebox.ca with ESMTP id CrK3QZrmUsrtpQvW (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Thu, 14 Apr 2022 16:01:38 -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 77A9C441D65; Thu, 14 Apr 2022 16:01:38 -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 3/5] gdbsupport: make gdb_realpath_keepfile return an std::string Date: Thu, 14 Apr 2022 16:01:35 -0400 X-ASG-Orig-Subj: [PATCH 3/5] gdbsupport: make gdb_realpath_keepfile return an std::string Message-Id: <20220414200137.3479373-3-simon.marchi@polymtl.ca> X-Mailer: git-send-email 2.35.2 In-Reply-To: <20220414200137.3479373-1-simon.marchi@polymtl.ca> References: <20220414200137.3479373-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: 1649966498 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: 3164 X-Barracuda-BRTS-Status: 1 X-Barracuda-Spam-Score: 0.00 X-Barracuda-Spam-Status: No, SCORE=0.00 using global scores of TAG_LEVEL=1000.0 QUARANTINE_LEVEL=1000.0 KILL_LEVEL=8.0 tests= X-Barracuda-Spam-Report: Code version 3.2, rules version 3.2.3.97354 Rule breakdown below pts rule name description ---- ---------------------- -------------------------------------------------- X-Spam-Status: No, score=-3612.9 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: Thu, 14 Apr 2022 20:01:51 -0000 From: Simon Marchi I'm trying to switch these functions to use std::string instead of char arrays, as much as possible. Some callers benefit from it (can avoid doing a copy of the result), while others suffer (have to make one more copy). Change-Id: I793aab17baaef8345488f4c40b9094e2695425bc --- gdb/exec.c | 3 ++- gdbsupport/pathstuff.cc | 11 ++++------- gdbsupport/pathstuff.h | 3 +-- 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/gdb/exec.c b/gdb/exec.c index 84c36473abb0..38540c0840b9 100644 --- a/gdb/exec.c +++ b/gdb/exec.c @@ -467,7 +467,8 @@ exec_file_attach (const char *filename, int from_tty) (bfd_get_filename (current_program_space->exec_bfd ()))); else current_program_space->exec_filename - = gdb_realpath_keepfile (scratch_pathname); + = make_unique_xstrdup (gdb_realpath_keepfile + (scratch_pathname).c_str ()); if (!bfd_check_format_matches (current_program_space->exec_bfd (), bfd_object, &matching)) diff --git a/gdbsupport/pathstuff.cc b/gdbsupport/pathstuff.cc index dd6ffa49fb42..ac65651d4492 100644 --- a/gdbsupport/pathstuff.cc +++ b/gdbsupport/pathstuff.cc @@ -86,17 +86,16 @@ gdb_realpath (const char *filename) /* See gdbsupport/pathstuff.h. */ -gdb::unique_xmalloc_ptr +std::string gdb_realpath_keepfile (const char *filename) { const char *base_name = lbasename (filename); char *dir_name; - char *result; /* Extract the basename of filename, and return immediately a copy of filename if it does not contain any directory prefix. */ if (base_name == filename) - return make_unique_xstrdup (filename); + return filename; dir_name = (char *) alloca ((size_t) (base_name - filename + 2)); /* Allocate enough space to store the dir_name + plus one extra @@ -121,11 +120,9 @@ gdb_realpath_keepfile (const char *filename) gdb::unique_xmalloc_ptr path_storage = gdb_realpath (dir_name); const char *real_path = path_storage.get (); if (IS_DIR_SEPARATOR (real_path[strlen (real_path) - 1])) - result = concat (real_path, base_name, (char *) NULL); + return string_printf ("%s%s", real_path, base_name); else - result = concat (real_path, SLASH_STRING, base_name, (char *) NULL); - - return gdb::unique_xmalloc_ptr (result); + return string_printf ("%s/%s", real_path, base_name); } /* See gdbsupport/pathstuff.h. */ diff --git a/gdbsupport/pathstuff.h b/gdbsupport/pathstuff.h index 04d9bf9029b5..f6c51e9de887 100644 --- a/gdbsupport/pathstuff.h +++ b/gdbsupport/pathstuff.h @@ -39,8 +39,7 @@ extern gdb::unique_xmalloc_ptr gdb_realpath (const char *filename); /* Return a copy of FILENAME, with its directory prefix canonicalized by gdb_realpath. */ -extern gdb::unique_xmalloc_ptr - gdb_realpath_keepfile (const char *filename); +extern std::string gdb_realpath_keepfile (const char *filename); /* Return PATH in absolute form, performing tilde-expansion if necessary. PATH cannot be NULL or the empty string. -- 2.35.2