Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Jan Kratochvil <jan.kratochvil@redhat.com>
To: Khoo Yit Phang <khooyp@cs.umd.edu>
Cc: GDB Patches <gdb-patches@sourceware.org>
Subject: Re: [PATCH 2/2] Try to initialize data-directory by first searching for "data-directory" in the same directory as the gdb binary
Date: Fri, 21 Sep 2012 18:31:00 -0000	[thread overview]
Message-ID: <20120921183122.GB8747@host2.jankratochvil.net> (raw)
In-Reply-To: <D25DD5A2-956A-4D0F-9A00-383976EBD397@cs.umd.edu>

On Wed, 19 Sep 2012 21:55:28 +0200, Khoo Yit Phang wrote:
> +  /* Then try to find GDB_DATADIR relocated relative to gdb. */
> +  if (!dir)
> +    dir = relocate_path (gdb_program_name, GDB_DATADIR, 1,
> +			 GDB_DATADIR_RELOCATABLE);
> +
> +  /* Otherwise use GDB_DATADIR as is. */
> +  if (!dir)
> +    dir = xstrdup (GDB_DATADIR);
> +
> +  /* Canonicalize the directory.  */
> +  if (*dir)
> +    {
> +      char *canon_sysroot = lrealpath (dir);
> +
> +      if (canon_sysroot)
> +	{
> +	  xfree (dir);
> +	  dir = canon_sysroot;
> +	}
> +    }

I am not happy from the code duplication with existing function:

	char *
	relocate_gdb_directory (const char *initial, int flag)
	{
	  char *dir;

	  dir = relocate_path (gdb_program_name, initial, 1, flag);
	  if (!dir)
	    dir = xstrdup (initial);

	  /* Canonicalize the directory.  */
	  if (*dir)
	    {
	      char *canon_sysroot = lrealpath (dir);

	      if (canon_sysroot)
		{
		  xfree (dir);
		  dir = canon_sysroot;
		}
	    }

	  return dir;
	}

Also it could check for /usr/gdb/data-directory which is less likely to be
present than /usr/bin/data-directory .

Proposing the patch below instead, although I do not like it much either.


Thanks,
Jan


gdb/
2012-09-21  Jan Kratochvil  <jan.kratochvil@redhat.com>

	* main.c: New variables dir and datadir.  Change GDB_DATADIR
	initialization to attempt to find gdb/data-directory/ first.

diff --git a/gdb/main.c b/gdb/main.c
index bde37f9..635c86b 100644
--- a/gdb/main.c
+++ b/gdb/main.c
@@ -314,6 +314,7 @@ captured_main (void *data)
   int i;
   int save_auto_load;
   struct objfile *objfile;
+  char *dir, *datadir;
 
   struct cleanup *pre_stat_chain;
 
@@ -370,8 +371,23 @@ captured_main (void *data)
   debug_file_directory = relocate_gdb_directory (DEBUGDIR,
 						 DEBUGDIR_RELOCATABLE);
 
-  gdb_datadir = relocate_gdb_directory (GDB_DATADIR,
-					GDB_DATADIR_RELOCATABLE);
+  /* Attempt first to find gdb/data-directory/ if we are run still from the
+     build directory.  */
+  datadir = ldirname (BINDIR);
+  datadir = reconcat (datadir, datadir,
+		      SLASH_STRING "gdb" SLASH_STRING "data-directory", NULL);
+  dir = relocate_path (gdb_program_name, datadir, 1, 1);
+  xfree (datadir);
+  if (dir)
+    {
+      /* DATADIR could never have less components than BINDIR, therefore
+         we do not need to check it DIR is not "" like
+         relocate_gdb_directory has to.  */
+      gdb_datadir = lrealpath (dir);
+      xfree (dir);
+    }
+  if (gdb_datadir == NULL)
+    gdb_datadir = relocate_gdb_directory (GDB_DATADIR, GDB_DATADIR_RELOCATABLE);
 
 #ifdef WITH_PYTHON_PATH
   {


  reply	other threads:[~2012-09-21 18:31 UTC|newest]

Thread overview: 72+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-09-18 20:33 [PATCH] " Khoo Yit Phang
2012-09-19 13:01 ` Jan Kratochvil
2012-09-19 19:53   ` [PATCH 1/2]: Refactor relocate_path to also check if the relocated file/directory exists Khoo Yit Phang
2012-09-21 18:27     ` Jan Kratochvil
2012-09-21 18:36       ` Eli Zaretskii
2012-09-21 18:46         ` Jan Kratochvil
2012-09-21 18:59           ` Eli Zaretskii
2012-09-21 19:09           ` Andreas Schwab
2012-09-22 16:07             ` Khoo Yit Phang
2012-09-25  6:59               ` Jan Kratochvil
2012-09-19 19:56   ` [PATCH 2/2] Try to initialize data-directory by first searching for "data-directory" in the same directory as the gdb binary Khoo Yit Phang
2012-09-21 18:31     ` Jan Kratochvil [this message]
2012-09-21 19:05       ` Khoo Yit Phang
2012-09-22 11:08         ` Jan Kratochvil
2012-09-22 15:50           ` Khoo Yit Phang
2012-09-24  7:30             ` Joel Brobecker
2012-09-24 13:14               ` Khoo Yit Phang
2012-09-24 14:24                 ` Eli Zaretskii
2012-09-24 14:37                   ` Khoo Yit Phang
2012-09-24 14:51                     ` Eli Zaretskii
2012-09-24 15:00                       ` Khoo Yit Phang
2012-09-24 15:27                         ` Khoo Yit Phang
2012-09-24 15:49                           ` Eli Zaretskii
2012-09-24 14:59                 ` Joel Brobecker
2012-09-24 15:08                   ` Khoo Yit Phang
2012-09-24 15:09                   ` Eli Zaretskii
2012-09-24 15:12                   ` Khoo Yit Phang
2012-09-24 15:27                     ` Joel Brobecker
2012-09-24 16:10                       ` Khoo Yit Phang
2012-09-24 16:45                         ` Khoo Yit Phang
2012-09-24 17:04                           ` Joel Brobecker
2012-09-24 19:19                             ` [PATCH] Also install data-directory into the build directory as computed by relocate_gdb_directory Khoo Yit Phang
2012-09-27  9:17                               ` Joel Brobecker
2012-09-27 14:57                                 ` Khoo Yit Phang
2012-10-03 21:31                                 ` Doug Evans
2012-10-04  0:09                                   ` Joel Brobecker
2012-10-04  0:50                                     ` Doug Evans
2012-10-04  1:34                                       ` Joel Brobecker
2012-10-04  3:41                                         ` Khoo Yit Phang
2012-10-04 13:39                                           ` Joel Brobecker
2012-10-04 14:26                                           ` Doug Evans
2012-10-04 14:25                                         ` Doug Evans
2012-10-04 14:51                                           ` Joel Brobecker
2012-10-04 15:07                                             ` Doug Evans
2012-10-04 15:28                                               ` Joel Brobecker
2012-10-06 19:02                                               ` Khoo Yit Phang
2012-10-06 19:25                                                 ` Eli Zaretskii
2012-10-06 19:36                                                   ` Khoo Yit Phang
2012-10-06 20:07                                                     ` Eli Zaretskii
2012-10-06 20:12                                                       ` Khoo Yit Phang
2012-10-06 20:29                                                         ` Eli Zaretskii
2012-10-06 20:32                                                           ` Khoo Yit Phang
2012-10-06 21:00                                                             ` Eli Zaretskii
2012-10-08 16:33                                                 ` Doug Evans
2012-10-08 20:13                                                   ` Khoo Yit Phang
2012-10-08 20:24                                                     ` Doug Evans
2012-10-09  5:48                                                   ` Joel Brobecker
2012-10-09 16:49                                                     ` Eli Zaretskii
2012-10-04  3:43                                     ` Eli Zaretskii
2012-10-04 13:49                                       ` Joel Brobecker
2012-10-04 14:48                                         ` Doug Evans
2012-10-04 15:23                                           ` Doug Evans
2012-10-04 17:07                                         ` Eli Zaretskii
2012-09-24 18:12                           ` [PATCH 2/2] Try to initialize data-directory by first searching for "data-directory" in the same directory as the gdb binary Eli Zaretskii
2012-09-24 20:49                             ` Joel Brobecker
2012-09-24 21:08                               ` Eli Zaretskii
2012-09-24 21:37                                 ` Joel Brobecker
2012-09-25  6:29                                   ` Eli Zaretskii
2012-09-25  6:35                                     ` Joel Brobecker
2012-09-25  6:50                                       ` Eli Zaretskii
2012-09-25  7:02                                         ` Joel Brobecker
2012-09-24 18:11                         ` Eli Zaretskii

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=20120921183122.GB8747@host2.jankratochvil.net \
    --to=jan.kratochvil@redhat.com \
    --cc=gdb-patches@sourceware.org \
    --cc=khooyp@cs.umd.edu \
    /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