From: "Christian Biesinger via gdb-patches" <gdb-patches@sourceware.org>
To: gdb-patches@sourceware.org
Cc: Christian Biesinger <cbiesinger@google.com>
Subject: [PATCH 2/3] Factor out the code to do the datadir-relocation for gdbinit
Date: Tue, 20 Aug 2019 22:18:00 -0000 [thread overview]
Message-ID: <20190820221745.147370-3-cbiesinger@google.com> (raw)
In-Reply-To: <20190820221745.147370-1-cbiesinger@google.com>
gdb/ChangeLog:
2019-08-20 Christian Biesinger <cbiesinger@google.com>
* main.c (relocate_gdbinit_path_maybe_in_datadir): New function.
(get_init_files): Update.
---
gdb/main.c | 68 +++++++++++++++++++++++++++++-------------------------
1 file changed, 37 insertions(+), 31 deletions(-)
diff --git a/gdb/main.c b/gdb/main.c
index b9e12589ab..a1d1904c9b 100644
--- a/gdb/main.c
+++ b/gdb/main.c
@@ -191,6 +191,41 @@ relocate_gdb_directory (const char *initial, int flag)
return dir;
}
+static std::string relocate_gdbinit_path_maybe_in_datadir (std::string file)
+{
+ int datadir_len = strlen (GDB_DATADIR);
+
+ /* If SYSTEM_GDBINIT lives in data-directory, and data-directory
+ has been provided, search for SYSTEM_GDBINIT there. */
+ if (gdb_datadir_provided
+ && datadir_len < file.length ()
+ && filename_ncmp (file.c_str (), GDB_DATADIR, datadir_len) == 0
+ && IS_DIR_SEPARATOR (file[datadir_len]))
+ {
+ /* Append the part of SYSTEM_GDBINIT that follows GDB_DATADIR
+ to gdb_datadir. */
+
+ size_t start = datadir_len;
+ for (; IS_DIR_SEPARATOR (file[start]); ++start)
+ continue;
+ return std::string (gdb_datadir) + SLASH_STRING +
+ file.substr(start);
+ }
+ else
+ {
+ char *relocated = relocate_path (gdb_program_name,
+ file.c_str(),
+ SYSTEM_GDBINIT_RELOCATABLE);
+ if (relocated != nullptr)
+ {
+ std::string retval(relocated);
+ xfree (relocated);
+ return retval;
+ }
+ }
+ return "";
+}
+
/* Compute the locations of init files that GDB should source and
return them in SYSTEM_GDBINIT, HOME_GDBINIT, LOCAL_GDBINIT. If
there is no system gdbinit (resp. home gdbinit and local gdbinit)
@@ -212,37 +247,8 @@ get_init_files (std::string *system_gdbinit,
if (SYSTEM_GDBINIT[0])
{
- int datadir_len = strlen (GDB_DATADIR);
- int sys_gdbinit_len = strlen (SYSTEM_GDBINIT);
- std::string relocated_sysgdbinit;
-
- /* If SYSTEM_GDBINIT lives in data-directory, and data-directory
- has been provided, search for SYSTEM_GDBINIT there. */
- if (gdb_datadir_provided
- && datadir_len < sys_gdbinit_len
- && filename_ncmp (SYSTEM_GDBINIT, GDB_DATADIR, datadir_len) == 0
- && IS_DIR_SEPARATOR (SYSTEM_GDBINIT[datadir_len]))
- {
- /* Append the part of SYSTEM_GDBINIT that follows GDB_DATADIR
- to gdb_datadir. */
-
- size_t start = datadir_len;
- for (; IS_DIR_SEPARATOR (SYSTEM_GDBINIT[start]); ++start)
- continue;
- relocated_sysgdbinit = std::string (gdb_datadir) + SLASH_STRING +
- &SYSTEM_GDBINIT[start];
- }
- else
- {
- char *relocated = relocate_path (gdb_program_name,
- SYSTEM_GDBINIT,
- SYSTEM_GDBINIT_RELOCATABLE);
- if (relocated != nullptr)
- {
- relocated_sysgdbinit = relocated;
- xfree (relocated);
- }
- }
+ std::string relocated_sysgdbinit =
+ relocate_gdbinit_path_maybe_in_datadir (SYSTEM_GDBINIT);
if (!relocated_sysgdbinit.empty () &&
stat (relocated_sysgdbinit.c_str (), &s) == 0)
sysgdbinit = relocated_sysgdbinit;
--
2.23.0.rc1.153.gdeed80330f-goog
next prev parent reply other threads:[~2019-08-20 22:18 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-08-20 22:17 [PATCH 0/3] [RFC] Load gdbinit files from a directory Christian Biesinger via gdb-patches
2019-08-20 22:18 ` [PATCH 1/3] Refactor get_init_files to use std::string Christian Biesinger via gdb-patches
2019-08-21 17:13 ` Sergio Durigan Junior
2019-08-21 17:29 ` Christian Biesinger via gdb-patches
2019-08-21 17:31 ` [PATCH 1/3 v2] " Christian Biesinger via gdb-patches
2019-08-21 17:34 ` [PATCH 1/3] " Sergio Durigan Junior
2019-08-20 22:18 ` [PATCH 3/3] Load system gdbinit files from a directory Christian Biesinger via gdb-patches
2019-08-21 17:32 ` Sergio Durigan Junior
2019-08-26 0:25 ` Christian Biesinger via gdb-patches
2019-08-26 0:33 ` [PATCH 3/3 v2] " Christian Biesinger via gdb-patches
2019-08-26 7:22 ` Eli Zaretskii
2019-09-12 22:12 ` Christian Biesinger via gdb-patches
2019-09-24 16:30 ` [PATCH 3/3 v3] " Christian Biesinger via gdb-patches
2019-10-03 18:42 ` Christian Biesinger via gdb-patches
2019-10-13 1:19 ` Christian Biesinger via gdb-patches
2019-08-21 18:15 ` [PATCH 3/3] " Sergio Durigan Junior
2019-08-21 18:46 ` Christian Biesinger via gdb-patches
2019-08-20 22:18 ` Christian Biesinger via gdb-patches [this message]
2019-08-21 17:19 ` [PATCH 2/3] Factor out the code to do the datadir-relocation for gdbinit Sergio Durigan Junior
2019-08-21 17:44 ` Christian Biesinger via gdb-patches
2019-08-21 17:44 ` [PATCH 2/3 v2] " Christian Biesinger via gdb-patches
2019-08-21 17:47 ` [PATCH 2/3] " Sergio Durigan Junior
2019-08-21 18:08 ` Christian Biesinger via gdb-patches
2019-08-21 18:10 ` Sergio Durigan Junior
2019-08-21 18:13 ` [PATCH 0/3] [RFC] Load gdbinit files from a directory Pedro Alves
2019-08-21 18:33 ` Christian Biesinger via gdb-patches
2019-08-21 18:54 ` Sergio Durigan Junior
2019-08-25 22:24 ` Christian Biesinger via gdb-patches
2019-08-26 13:31 ` Pedro Alves
2019-09-12 22:14 ` Christian Biesinger via gdb-patches
2019-09-09 18:08 [PATCH 0/3] Refactor some path methods in main.c to use std::string Christian Biesinger via gdb-patches
2019-09-09 18:08 ` [PATCH 2/3] Factor out the code to do the datadir-relocation for gdbinit Christian Biesinger via gdb-patches
2019-09-10 15:15 ` Tom Tromey
2019-09-10 19:14 ` Christian Biesinger via gdb-patches
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190820221745.147370-3-cbiesinger@google.com \
--to=gdb-patches@sourceware.org \
--cc=cbiesinger@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).