diff options
author | Eli Zaretskii <eliz@gnu.org> | 2005-04-28 20:32:42 +0000 |
---|---|---|
committer | Eli Zaretskii <eliz@gnu.org> | 2005-04-28 20:32:42 +0000 |
commit | a955ca7173f8c0fed60292d19b949adb23b76214 (patch) | |
tree | 50e82aba941a7d4a98657fead11868e1b4fbef8e /gdb/cli | |
parent | 46845f5e980b0b6e59ca5d83100ff9c42f380039 (diff) | |
download | fsf-binutils-gdb-a955ca7173f8c0fed60292d19b949adb23b76214.zip fsf-binutils-gdb-a955ca7173f8c0fed60292d19b949adb23b76214.tar.gz fsf-binutils-gdb-a955ca7173f8c0fed60292d19b949adb23b76214.tar.bz2 |
* 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.
Diffstat (limited to 'gdb/cli')
-rw-r--r-- | gdb/cli/cli-cmds.c | 31 |
1 files changed, 16 insertions, 15 deletions
diff --git a/gdb/cli/cli-cmds.c b/gdb/cli/cli-cmds.c index 3c091fe..3d25f1a 100644 --- a/gdb/cli/cli-cmds.c +++ b/gdb/cli/cli-cmds.c @@ -554,7 +554,7 @@ edit_command (char *arg, int from_tty) 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 @@ 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; - - 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); } |