Article View: gnu.gdb.bug
Article #1269Re: [RFA] Fix file name generation in edit_command (was: Ver 6.3 edit command failing)
From: Eli Zaretskii
Date: Thu, 28 Apr 2005 20:36
Date: Thu, 28 Apr 2005 20:36
89 lines
4980 bytes
4980 bytes
> Date: Wed, 27 Apr 2005 14:04:10 -0400
> From: Daniel Jacobowitz <drow@false.org>
> Cc: bug-gdb@rich-paul.net, bug-gdb@gnu.org, gdb-patches@sources.redhat.com
>
> It strikes me as odd that you can use "edit" if GDB doesn't know where
> the source file is. I realize this is a pre-existing condition, but...
> Also, symtab_to_fullname includes the cached fullname check. So what's
> your opinion of boiling the whole thing down to:
>
> fn = symtab_to_fullname (sal.symtab);
> if (fn == NULL)
> error (_("Could not find file \"%s\""), sal.symtab->filename);
> p = xstrprintf ("%s +%d %s", editor, sal.line, fn);
>
> Mark, can I have those bonus points? :-)
I ended up committing the attached. Note that it quotes the file
name, to account for possible special characters that would confise
the shell. (I use "..." for quoting because this is more portable to
various shells, including on Windows.)
Thanks to Daniel and Mark for valuable input.
2005-04-28 Eli Zaretskii <eliz@gnu.org>
* cli/cli-cmds.c (edit_command): If symtab->fullname is not yet
set, use symtab_to_fullname, instead of trying to do its job. Use
xstrprintf instead of malloc and sprintf.
Index: gdb/cli/cli-cmds.c
===================================================================
RCS file: /cvs/src/src/gdb/cli/cli-cmds.c,v
retrieving revision 1.58
retrieving revision 1.59
diff -u -r1.58 -r1.59
--- gdb/cli/cli-cmds.c 16 Mar 2005 15:58:41 -0000 1.58
+++ gdb/cli/cli-cmds.c 28 Apr 2005 20:32:41 -0000 1.59
@@ -554,7 +554,7 @@
int cmdlen, log10;
unsigned m;
char *editor;
- char *p;
+ char *p, *fn;
/* Pull in the current default source line if necessary */
if (arg == 0)
@@ -627,25 +627,26 @@
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;
-
- 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)
- );
- shell_escape(p, from_tty);
+ /* If we don't already know the full absolute file name of the
+ source file, find it now. */
+ if (!sal.symtab->fullname)
+ {
+ fn = symtab_to_fullname (sal.symtab);
+ if (!fn)
+ fn = "unknown";
+ }
+ else
+ fn = sal.symtab->fullname;
+ /* Quote the file name, in case it has whitespace or other special
+ characters. */
+ p = xstrprintf ("%s +%d \"%s\"", editor, sal.line, fn);
+ shell_escape(p, from_tty);
xfree(p);
}
Technical Details
Message-ID:
<mailman.3365.1114720816.2895.bug-gdb@gnu.org>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!newsfeed.stanford.edu!shelby.stanford.edu!not-for-mailReferences:
<E1DLM3u-0000IQ-Vj@lists.gnu.org> <01c54b35$Blat.v2.4$c3f52520@zahav.net.il> <20050427143620.GA1686@nevyn.them.org> <01c54b40$Blat.v2.4$be3bafe0@zahav.net.il> <20050427180410.GA19592@nevyn.them.org>Show Full Headers
Complete Article Headers
X-Google-Thread: f5053,f951753e39b033fe X-Google-Attributes: gidf5053,public X-Google-Language: ENGLISH,ASCII-7-bit Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!newsfeed.stanford.edu!shelby.stanford.edu!not-for-mail From: "Eli Zaretskii" <eliz@gnu.org> Newsgroups: gnu.gdb.bug Subject: Re: [RFA] Fix file name generation in edit_command (was: Ver 6.3 edit command failing) Date: Thu, 28 Apr 2005 23:36:50 +0300 Lines: 91 Sender: halo1@zahav.net.il Approved: bug-gdb@gnu.org Message-ID: <mailman.3365.1114720816.2895.bug-gdb@gnu.org> References: <E1DLM3u-0000IQ-Vj@lists.gnu.org> <01c54b35$Blat.v2.4$c3f52520@zahav.net.il> <20050427143620.GA1686@nevyn.them.org> <01c54b40$Blat.v2.4$be3bafe0@zahav.net.il> <20050427180410.GA19592@nevyn.them.org> Reply-To: Eli Zaretskii <eliz@gnu.org> NNTP-Posting-Host: lists.gnu.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7BIT X-Trace: news.Stanford.EDU 1114720775 16180 199.232.76.165 (28 Apr 2005 20:39:35 GMT) X-Complaints-To: news@news.stanford.edu Cc: gdb-patches@sources.redhat.com, bug-gdb@gnu.org To: bug-gdb@rich-paul.net Envelope-to: bug-gdb@gnu.org X-Mailer: emacs 22.0.50 (via feedmail 8 I) and Blat ver 2.4 In-reply-to: <20050427180410.GA19592@nevyn.them.org> (message from Daniel Jacobowitz on Wed, 27 Apr 2005 14:04:10 -0400) X-BeenThere: bug-gdb@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Bug reports for GDB, the GNU debugger" <bug-gdb.gnu.org> List-Unsubscribe: <http://lists.gnu.org/mailman/listinfo/bug-gdb>, <mailto:bug-gdb-request@gnu.org?subject=unsubscribe> List-Archive: <http://lists.gnu.org/pipermail/bug-gdb> List-Post: <mailto:bug-gdb@gnu.org> List-Help: <mailto:bug-gdb-request@gnu.org?subject=help> List-Subscribe: <http://lists.gnu.org/mailman/listinfo/bug-gdb>, <mailto:bug-gdb-request@gnu.org?subject=subscribe>