Cscope regression at patch 9.0.0584

13 views
Skip to first unread message

Gary Johnson

unread,
Oct 12, 2022, 9:40:20 PM10/12/22
to vim...@googlegroups.com
I started noticing odd behavior from cscope recently, so I ran 'git
bisect' and found the problem at this commit:

$ git bisect good
dc21552c9a83413a018a91e61649cc632929d6a1 is the first bad commit
commit dc21552c9a83413a018a91e61649cc632929d6a1
Author: Bram Moolenaar <Br...@vim.org>
Date: Sun Sep 25 17:03:26 2022 +0100

patch 9.0.0584: cscope test with wrong executable name fails

Problem: Cscope test with wrong executable name fails.
Solution: Use /bin/sh to execute the command. (Yegappan Lakshmanan)

src/if_cscope.c | 27 ++++++++++++++++-----------
src/testdir/test_cscope.vim | 14 +++++---------
src/version.c | 2 ++
3 files changed, 23 insertions(+), 20 deletions(-)

I build a GNU Global database in a project's root directory, and
then use that database with vim's :cscope commands to find
references to symbols. I doesn't matter where I start vim in the
project's directories because vim knows how to construct the full
pathname to each target file.

Since that commit, however, I've had to start vim in the project's
root directory for the :cs find s <symbol>" command to work.
Otherwise, vim leaves out part of the path to the file.

For example, I have my vim repo at ~/src/vim/vim, and that's where
my GTAGS, etc., files are located.

1. $ cd ~/src/vim/vim
2. $ cd src
3. $ vim -N -u NONE
4. :set cscopeprg=gtags-cscope
5. :cs add /home/gary/src/vim/vim/GTAGS /home/gary/src/vim/vim -a
6. :set cscopequickfix=a-,c-,d-,e-,f0,g0,i-,s-,t-
7. :cs find s parse_printoptions

Vim opens ~/src/vim/vim/hardcopy.c. Note that this should be
~/src/vim/vim/src/hardcopy.c--the "src/" component was omitted.

This works properly if vim is started in the ~/src/vim/vim directory
or is a version older than 9.0.0584.

Version of Vim

9.0.658
but this been happening since patch 9.0.0584

Environment

Operating system: Ubuntu 20.04
Terminal: XTerm(370)
Value of $TERM: xterm-256color
Shell: bash 5.0.17
GNU Global and gtags-cscope: 6.6.4

Regards,
Gary

Gary Johnson

unread,
Oct 13, 2022, 3:48:07 AM10/13/22
to vim...@googlegroups.com
On 2022-10-12, Gary Johnson wrote:
> I started noticing odd behavior from cscope recently, so I ran 'git
> bisect' and found the problem at this commit:
>
> $ git bisect good
> dc21552c9a83413a018a91e61649cc632929d6a1 is the first bad commit
> commit dc21552c9a83413a018a91e61649cc632929d6a1
> Author: Bram Moolenaar <Br...@vim.org>
> Date: Sun Sep 25 17:03:26 2022 +0100
>
> patch 9.0.0584: cscope test with wrong executable name fails
>
> Problem: Cscope test with wrong executable name fails.
> Solution: Use /bin/sh to execute the command. (Yegappan Lakshmanan)
>
> src/if_cscope.c | 27 ++++++++++++++++-----------
> src/testdir/test_cscope.vim | 14 +++++---------
> src/version.c | 2 ++
> 3 files changed, 23 insertions(+), 20 deletions(-)

I had a little time this evening, so I built 9.0.0584 and ran it
with gdb. I found a problem in cs_create_connection(), in
if_cscope.c. That function creates a command line to be executed,
but does so incorrectly, so when that command line is converted to
argc and argv[] for execvp(), the arguments are incorrect.

From gdb, just before execvp() is to be called:

(gdb) p cmd
$6 = 0x555555f932b0 "/bin/sh -c \"exec gtags-cscope -dl -f /home/gary/src/vim/vim/GTAGS\" -P/home/gary/src/vim/vim -a"
(gdb) p *argv@5
$8 = {0x555555cbb1c0 "/bin/sh", 0x555555f8d420 "-c",
0x555555f8dcb0 "exec gtags-cscope -dl -f /home/gary/src/vim/vim/GTAGS",
0x555555f8ef60 "-P/home/gary/src/vim/vim", 0x555555f93a40 "-a"}

The problem is that the quotes that close the exec command are
placed after the -f file name instead of at the end of the complete
command. That causes execvp() to get the exec argument as

exec gtags-cscope -dl -f /home/gary/src/vim/vim/GTAGS

followed by two more arguments,

-P/home/gary/src/vim/vim
-a

I haven't thought through the effect of that, but it doesn't seem
right. The fix should be pretty simple, but I have no more time to
work on it tonight.

Someone else can fix it if they wish, or I'll try fixing it
tomorrow.

Regards,
Gary

Bram Moolenaar

unread,
Oct 13, 2022, 7:00:21 AM10/13/22
to vim...@googlegroups.com, Gary Johnson
I'm glad you could locate the source of the problem. Please try the
patch below. How could we make a regression test for this?


*** ../vim-9.0.0735/src/if_cscope.c 2022-10-01 20:17:13.820291832 +0100
--- src/if_cscope.c 2022-10-13 10:42:26.947402744 +0100
***************
*** 954,960 ****

// run the cscope command
#ifdef UNIX
! vim_snprintf(cmd, cmdlen, "/bin/sh -c \"exec %s -dl -f %s\"",
prog, csinfo[i].fname);
#else
vim_snprintf(cmd, cmdlen, "%s -dl -f %s", prog, csinfo[i].fname);
--- 954,960 ----

// run the cscope command
#ifdef UNIX
! vim_snprintf(cmd, cmdlen, "/bin/sh -c \"exec %s -dl -f %s",
prog, csinfo[i].fname);
#else
vim_snprintf(cmd, cmdlen, "%s -dl -f %s", prog, csinfo[i].fname);
***************
*** 970,975 ****
--- 970,978 ----
vim_snprintf(cmd + len, cmdlen - len, " %s", csinfo[i].flags);
}
# ifdef UNIX
+ // terminate the -c command argument
+ STRCAT(cmd, "\"");
+
// on Win32 we still need prog
vim_free(prog);
# endif

--
LAUNCELOT: I am, sir. I am a Knight of King Arthur.
FATHER: 'Mm ... very nice castle, Camelot ... very good pig country....
"Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///

Gary Johnson

unread,
Oct 13, 2022, 11:08:40 AM10/13/22
to vim...@googlegroups.com
On 2022-10-13, Bram Moolenaar wrote:

> I'm glad you could locate the source of the problem. Please try the
> patch below. How could we make a regression test for this?

I tested it in the cases that had failed before and they work fine
now. Thank you.

As for a regression test, I'll have to think about that and spend
some time understanding test_cscope.vim.

Regards,
Gary

Reply all
Reply to author
Forward
0 new messages