Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: "Eli Zaretskii" <eliz@gnu.org>
To: bug-gdb@rich-paul.net
Cc: bug-gdb@gnu.org, gdb-patches@sources.redhat.com
Subject: [RFA] Fix file name generation in edit_command (was: Ver 6.3 edit command failing)
Date: Wed, 27 Apr 2005 14:32:00 -0000	[thread overview]
Message-ID: <01c54b35$Blat.v2.4$c3f52520@zahav.net.il> (raw)
In-Reply-To: <E1DLM3u-0000IQ-Vj@lists.gnu.org> (bug-gdb@rich-paul.net)

> Date: Tue, 12 Apr 2005 09:58:25 -0400
> From: bug-gdb@rich-paul.net
> 
> While using gdb 6.3,  I was having a problem with the directory name and the
> file name being concatenated by the edit command without an intervening slash.
> My solution was just to add the slash to the sprintf format string
> in cli/cli-cmds.c, near line 650.  It worked for me.

Thanks for pointing this out.

In fact, the code there had quite a few problems besides the one you
found: it didn't use symtab->fullname, failed miserably for DOS-style
d:/foo/bar file names, etc.

Does anyone object to the following patch?

2005-04-27  Eli Zaretskii  <eliz@gnu.org>

	* cli/cli-cmds.c (edit_command): Use symtab->fullname if
	possible.  Use IS_ABSOLUTE_PATH instead of checking for a literal
	'/'.  Make sure there's a slash between the directory and the file
	name.  Simplify and clarify the code logic.


--- gdb/cli/cli-cmds.c~0	2005-03-26 16:18:14.000000000 +0300
+++ gdb/cli/cli-cmds.c	2005-04-27 17:14:46.000000000 +0300
@@ -554,7 +554,7 @@ edit_command (char *arg, int from_tty)
   int cmdlen, log10;
   unsigned m;
   char *editor;
-  char *p;
+  char *p, *fn, *dn;
 
   /* Pull in the current default source line if necessary */
   if (arg == 0)
@@ -627,23 +627,33 @@ edit_command (char *arg, int from_tty)
 
   if ((editor = (char *) getenv ("EDITOR")) == NULL)
       editor = "/bin/ex";
-  
+
   /* Approximate base-10 log of line to 1 unit for digit count */
   for(log10=32, m=0x80000000; !(sal.line & m) && log10>0; log10--, m=m>>1);
   log10 = 1 + (int)((log10 + (0 == ((m-1) & sal.line)))/3.32192809);
 
-  cmdlen = strlen(editor) + 1
-         + (NULL == sal.symtab->dirname ? 0 : strlen(sal.symtab->dirname) + 1)
-	 + (NULL == sal.symtab->filename? 0 : strlen(sal.symtab->filename)+ 1)
-	 + log10 + 2;
-  
+  dn = "";
+  if (NULL != sal.symtab->fullname)
+    fn = sal.symtab->fullname;
+  else if (NULL == sal.symtab->filename)
+    {
+      fn = "unknown";
+      if (NULL != sal.symtab->dirname)
+	dn = sal.symtab->dirname;
+    }
+  else if (IS_ABSOLUTE_PATH (sal.symtab->filename))
+    fn = sal.symtab->filename;
+  else
+    {
+      fn = sal.symtab->filename;
+      dn = sal.symtab->dirname;
+      if (NULL == dn)
+	dn = ".";
+    }
+  /*         $EDITOR      blank  +NN  blank    dir       /     file      \0 */
+  cmdlen = strlen(editor) + 1 + log10 + 2 + strlen(dn) + 1 + strlen(fn) + 1;
   p = xmalloc(cmdlen);
-  sprintf(p,"%s +%d %s%s",editor,sal.line,
-     (NULL == sal.symtab->dirname ? "./" :
-        (NULL != sal.symtab->filename && *(sal.symtab->filename) != '/') ?
-	   sal.symtab->dirname : ""),
-     (NULL == sal.symtab->filename ? "unknown" : sal.symtab->filename)
-  );
+  sprintf (p, "%s +%d %s%s%s", editor, sal.line, dn, (*dn ? "/" : ""), fn);
   shell_escape(p, from_tty);
 
   xfree(p);


       reply	other threads:[~2005-04-27 14:32 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <E1DLM3u-0000IQ-Vj@lists.gnu.org>
2005-04-27 14:32 ` Eli Zaretskii [this message]
2005-04-27 14:36   ` Daniel Jacobowitz
2005-04-27 15:52     ` Eli Zaretskii
2005-04-27 17:43       ` Mark Kettenis
2005-04-28  7:10         ` Eli Zaretskii
2005-04-27 18:04       ` Daniel Jacobowitz
2005-04-28  7:05         ` Eli Zaretskii
2005-04-28 20:39         ` Eli Zaretskii
2005-04-28 20:42           ` Daniel Jacobowitz
2005-04-28 21:04             ` Eli Zaretskii
2005-04-28 21:18               ` Daniel Jacobowitz
2005-04-29  7:07                 ` 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='01c54b35$Blat.v2.4$c3f52520@zahav.net.il' \
    --to=eliz@gnu.org \
    --cc=bug-gdb@gnu.org \
    --cc=bug-gdb@rich-paul.net \
    --cc=gdb-patches@sources.redhat.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