cscope: cannot find file XXX(绝对路径)

我在使用cscope -b生成 cscope.out的时候, 一直出现cscope找不到路径,定位问题的方法记录一下。

1. 确保生成的cscope.files里的路径为绝对路径, 不能是相对路径.

2. 查看本地vim配置文件里的cscope的安装路径是否填充正确。因为有的cscope的安装路径在/usr/local/bin/下面。

if has("cscope")&&filereadable("/usr/bin/cscope")
    set csprg=/usr/bin/cscope
    set csto=0
    set cst
    set nocsverb
    if filereadable("cscope.out")
        cs add cscope.out
    elseif $CSCOPE_DB != ""
        cs add $CSCOPE_DB
    endif
    set csverb
endif
3.    确定上面两个方法没有问题之后,仍报错,我便去把cscope的源码下载下来,查看的代码逻辑.
cscope: cannot find file

如下, 可以看到源码逻辑是判断该路径文件是否存在, 该文件是否可读, 如果否, 判断第一个字符是否为"/",以此判断文件是否为绝对路径,。。。。

accessible_file(char *file)
{
    if (access(compath(file), READ) == 0) {
	struct stat stats;

	if (lstat(file, &stats) == 0
	    && S_ISREG(stats.st_mode)) {
	    return YES;
	}
    }
    return NO;
}

/* search for the file in the view path */
char *
inviewpath(char *file)
{
    static char	path[PATHLEN + 1];
    unsigned int i;

    /* look for the file */
    if (accessible_file(file)) {
	return(file);
    }

    /* if it isn't a full path name and there is a multi-directory
     * view path */
    if (*file != '/' && vpndirs > 1) {
	int file_len = strlen(file);

	/* compute its path from higher view path source dirs */
	for (i = 1; i < nvpsrcdirs; ++i) {
	    snprintf(path, sizeof(path), "%.*s/%s",
		    PATHLEN - 2 - file_len, srcdirs[i],
		    file);
	    if (accessible_file(path)) {
		return(path);
	    }
	}
    }
    return(NULL);
}


由此代码逻辑,我便去检查文件是否存在, 是否可读, 是否为链接文件。最后找到原因,目标文件为链接文件,cscope无法识别.

hz@ubuntu:~/dpdk$ ls -l /home/hz/dpdk/dpdk-stable-17.11.2/build/include/rte_dev.h
lrwxrwxrwx 1 root root 45  6月 12 10:58 /home/hz/dpdk/dpdk-stable-17.11.2/build/include/rte_dev.h -> ../../lib/librte_eal/common/include/rte_dev.h


猜你喜欢

转载自blog.csdn.net/asiawong/article/details/80839862
今日推荐