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] Try to initialize data-directory by first searching for "data-directory" in the same directory as the gdb binary
Date: Wed, 19 Sep 2012 13:01:00 -0000	[thread overview]
Message-ID: <20120919130040.GA20442@host2.jankratochvil.net> (raw)
In-Reply-To: <21ACC598-F6B4-4117-BA7B-B316414DE9E3@cs.umd.edu>

On Tue, 18 Sep 2012 22:32:40 +0200, Khoo Yit Phang wrote:
> As discussed previously, here a patch that tries to initialize
> data-directory by first searching for "data-directory" in the same directory
> as the gdb binary.

I do not see how is it related to the 'isdir' addition, IMO 'isdir' is an
unrelated patch which should be posted separately.


> Additionally, I've also reverted my previous change to cc-with-tweaks.sh
> that added the -data-directory flag, since it is no longer necessary.

It can be kept there, it does not harm anything and it then does not depend on
a bit magic relocate_gdb_directory.



Thanks,
Jan


> gdb/ChangeLog
> 
> 2012-09-18  Khoo Yit Phang  <khooyp@cs.umd.edu>
> 
> 	Try to initialize data-directory by first searching for
> 	"data-directory" in the same directory as the gdb binary.
> 	* contrib/cc-with-tweaks.sh (GDB): Revert -data-directory
> 	additions that is now unnecessary.
> 	* main.c (relocate_path): Add an isdir argument, and check that
> 	the relocated file/directory exists.
> 	(relocate_gdb_directory): Remove the directory check that is
> 	subsumed by relocate_path.
> 	(get_init_files): Remove the file check that is subsumed by
> 	relocate_path.
> 	(relocate_gdb_data_directory): New function similar to
> 	relocate_gdb_directory, but specifically for data-directory.
> 	(captured_main): Call relocate_gdb_data_directory to initialize
> 	gdb_datadir.
> 
> diff --git a/gdb/contrib/cc-with-tweaks.sh b/gdb/contrib/cc-with-tweaks.sh
> --- a/gdb/contrib/cc-with-tweaks.sh
> +++ b/gdb/contrib/cc-with-tweaks.sh
> @@ -19,8 +19,7 @@
>  # This program requires gdb and objcopy in addition to gcc.
>  # The default values are gdb from the build tree and objcopy from $PATH.
>  # They may be overridden by setting environment variables GDB and OBJCOPY
> -# respectively.  Note that GDB should contain the gdb binary as well as the
> -# -data-directory flag, e.g., "foo/gdb -data-directory foo/data-directory".
> +# respectively.
>  # We assume the current directory is either $obj/gdb or $obj/gdb/testsuite.
>  #
>  # Example usage:
> @@ -47,13 +46,13 @@
>  then
>      if [ -f ./gdb ]
>      then
> -	GDB="./gdb -data-directory data-directory"
> +	GDB="./gdb"
>      elif [ -f ../gdb ]
>      then
> -	GDB="../gdb -data-directory ../data-directory"
> +	GDB="../gdb"
>      elif [ -f ../../gdb ]
>      then
> -	GDB="../../gdb -data-directory ../../data-directory"
> +	GDB="../../gdb"
>      else
>  	echo "$myname: unable to find usable gdb" >&2
>  	exit 1
> diff --git a/gdb/main.c b/gdb/main.c
> --- a/gdb/main.c
> +++ b/gdb/main.c
> @@ -91,17 +91,34 @@
>  
>  static void print_gdb_help (struct ui_file *);
>  
> -/* Relocate a file or directory.  PROGNAME is the name by which gdb
> -   was invoked (i.e., argv[0]).  INITIAL is the default value for the
> -   file or directory.  FLAG is true if the value is relocatable, false
> -   otherwise.  Returns a newly allocated string; this may return NULL
> -   under the same conditions as make_relative_prefix.  */
> +/* Relocate a file or directory, checking if it exists.  PROGNAME is the
> +   name by which gdb was invoked (i.e., argv[0]).  INITIAL is the default
> +   value for the file or directory.  ISDIR is true if INITIAL is a
> +   directory.  FLAG is true if the value is relocatable, false otherwise.
> +   Returns a newly allocated string; this may return NULL under the same
> +   conditions as make_relative_prefix, or if the relocated path does not
> +   exist.  */

GDB comments are formatted to textwidth=72 which may explain this excessive
reformatting.  Try to keep textwidth=72 instead of changes back and forth.


>  
>  static char *
> -relocate_path (const char *progname, const char *initial, int flag)
> +relocate_path (const char *progname, const char *initial, int isdir,
> +	       int flag)
>  {
>    if (flag)
> -    return make_relative_prefix (progname, BINDIR, initial);
> +    {
> +      char *path;
> +      path = make_relative_prefix (progname, BINDIR, initial);
> +      if (path)
> +	{
> +	  struct stat s;
> +
> +	  if (stat (path, &s) != 0 || (isdir && !S_ISDIR (s.st_mode)))
> +	    {
> +	      xfree (path);
> +	      path = NULL;
> +	    }
> +	}
> +      return path;
> +    }
>    return xstrdup (initial);
>  }
>  
> @@ -116,19 +133,52 @@
>  {
>    char *dir;
>  
> -  dir = relocate_path (gdb_program_name, initial, flag);
> -  if (dir)
> +  dir = relocate_path (gdb_program_name, initial, 1, flag);
> +  if (!dir)
> +    dir = xstrdup (initial);
> +
> +  /* Canonicalize the directory.  */
> +  if (*dir)
>      {
> -      struct stat s;
> +      char *canon_sysroot = lrealpath (dir);
>  
> -      if (stat (dir, &s) != 0 || !S_ISDIR (s.st_mode))
> +      if (canon_sysroot)
>  	{
>  	  xfree (dir);
> -	  dir = NULL;
> +	  dir = canon_sysroot;
>  	}
>      }
> +
> +  return dir;
> +}
> +
> +/* Like relocate_gdb_path, but specifically for data-directory. */
> +
> +static char *
> +relocate_gdb_data_directory (void)
> +{
> +  char *dir;
> +
> +  /* First try to find "data-directory" in the same directory as gdb.
> +
> +    Use relocate_path only to resolve the parent directory of
> +    gdb_program_name (i.e., based on PATH if necessary); relocate_path
> +    (gdb_program_name, BINDIR "/data-directory") cannot be used to resolve
> +    data-directory as it returns a path relative to the _grandparent
> +    directory_ of gdb_program_name (munging the parent directory).  */
> +
> +  dir = relocate_path (gdb_program_name, BINDIR, 1, 1);
> +  if (dir)
> +    dir = reconcat (dir, dir, SLASH_STRING, "data-directory", NULL);
> +
> +  /* Then try to find GDB_DATADIR relocated relative to gdb. */
>    if (!dir)

It can be more clear by replacing this 'if (!dir)' by 'else'.


> -    dir = xstrdup (initial);
> +    dir = relocate_path (gdb_program_name, GDB_DATADIR, 1,
> +			 GDB_DATADIR_RELOCATABLE);

Why isn't here the original statement?
	dir = relocate_gdb_directory (GDB_DATADIR, GDB_DATADIR_RELOCATABLE);



> +
> +  /* Otherwise use GDB_DATADIR as is. */
> +  if (!dir)
> +    dir = xstrdup (GDB_DATADIR);

This can be moved to the 'else' block suggested above to simplify it.


>  
>    /* Canonicalize the directory.  */
>    if (*dir)
> @@ -162,15 +212,15 @@
>  
>    if (!initialized)
>      {
> -      struct stat homebuf, cwdbuf, s;
> +      struct stat homebuf, cwdbuf;
>        char *homedir, *relocated_sysgdbinit;
>  
>        if (SYSTEM_GDBINIT[0])
>  	{
>  	  relocated_sysgdbinit = relocate_path (gdb_program_name,
> -						SYSTEM_GDBINIT,
> +						SYSTEM_GDBINIT, 0,
>  						SYSTEM_GDBINIT_RELOCATABLE);
> -	  if (relocated_sysgdbinit && stat (relocated_sysgdbinit, &s) == 0)
> +	  if (relocated_sysgdbinit)
>  	    sysgdbinit = relocated_sysgdbinit;
>  	  else
>  	    xfree (relocated_sysgdbinit);
> @@ -363,8 +413,7 @@
>    debug_file_directory = relocate_gdb_directory (DEBUGDIR,
>  						 DEBUGDIR_RELOCATABLE);
>  
> -  gdb_datadir = relocate_gdb_directory (GDB_DATADIR,
> -					GDB_DATADIR_RELOCATABLE);
> +  gdb_datadir = relocate_gdb_data_directory ();
>  
>  #ifdef WITH_PYTHON_PATH
>    {


  reply	other threads:[~2012-09-19 13:01 UTC|newest]

Thread overview: 72+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-09-18 20:33 Khoo Yit Phang
2012-09-19 13:01 ` Jan Kratochvil [this message]
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
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=20120919130040.GA20442@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