在linux上读取c程序时如何找到结构的定义?

前端之家收集整理的这篇文章主要介绍了在linux上读取c程序时如何找到结构的定义?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在阅读xl2tpd的源代码,并在阅读此代码时遇到很多问题.例如,我找不到结构lac的定义.我如何找到这个结构的定义?

我使用ctags和vim来读取此代码,但未能找到结构.我用Google搜索,找不到结构.有没有什么方法可以让代码阅读过程更舒服?也就是说,我可以跳到大多数变量,函数和结构的定义?

解决方法

用vim试试cscope.按照以下步骤 –
1)在xl2tpd目录中运行cscope -R.它将创建文件cscope.out
2)使用vim打开文件,其中使用结构lac
3)使用:cs f g< lac> .现在它将显示定义lac的文件.
4)选择file.h.它包含定义.
如果您对struct lac的定义非常感兴趣,那么它是 –
struct lac
{
    struct lac *next;
    struct host *lns;           /* LNS's we can connect to */
    struct schedule_entry *rsched;
    int tun_rws;                /* Receive window size (tunnel) */
    int call_rws;               /* Call rws */
    int rxspeed;                /* Tunnel rx speed */
    int txspeed;                /* Tunnel tx speed */
    int active;                 /* Is this connection in active use? */
    int hbit;                   /* Permit hidden AVP's? */
    int lbit;                   /* Use the length field? */
    int challenge;              /* Challenge authenticate the peer? */
    unsigned int localaddr;     /* Local IP address */    
    unsigned int remoteaddr;    /* Force remote address to this */
    char authname[STRLEN];      /* Who we authenticate as */
    char password[STRLEN];      /* Password to authenticate with */
    char peername[STRLEN];      /* Force peer name to this */
    char hostname[STRLEN];      /* Hostname to report */
    char entname[STRLEN];       /* Name of this entry */
    int authpeer;               /* Authenticate our peer? */
    int authself;               /* Authenticate ourselves? */
    int pap_require;            /* Require PAP auth for PPP */
    int chap_require;           /* Require CHAP auth for PPP */
    int pap_refuse;             /* Refuse PAP authentication for us */
    int chap_refuse;            /* Refuse CHAP authentication for us */
    int idle;                   /* Idle timeout in seconds */
    int autodial;               /* Try to dial immediately? */
    int defaultroute;           /* Use as default route? */
    int redial;                 /* Redial if disconnected */
    int rmax;                   /* Maximum # of consecutive redials */
    int rtries;                 /* # of tries so far */
    int rtimeout;               /* Redial every this many # of seconds */
    char pppoptfile[STRLEN];    /* File containing PPP options */
    int debug;
    struct tunnel *t;           /* Our tunnel */
    struct call *c;             /* Our call */
};

猜你在找的Linux相关文章