How to find a structure definition when reading a c program on linux?

I am reading the xl2tpd source code and xl2tpd encountering many problems reading this code. For example, I cannot find where the lac structure is defined. How to find the definition of this structure?

I used ctags and vim to read this code, but could not find the structure. I googled and could not find the structure. Is there a way that can make the process of reading code more convenient? That is, can I move on to defining most variables, functions, and structures?

+7
source share
4 answers

try cscope with vim. follow the steps below -
1) run cscope -R in the xl2tpd directory. he will create the cscope.out file
2) open a file with vim where the lac structure is used
3) use :cs fg <lac> . it will now show the files where lac defined.
4) select file.h it contains a definition.
if you are interested in the definition of struct lac , it is below -

 struct lac { struct lac *next; struct host *lns; /* LNS 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 */ }; 
+9
source

When looking at third-party code, there are several tools that I found invaluable:

I believe that the Eclipse CDT also allows you to quickly find the definition of any variable that you are looking at, but I have not actually used it - I prefer to use console programs for my actual C encoding.

None of them are vim , although at least ctags can be used via vim or emacs . However, they can be very useful when learning a new code base that you know nothing about ...

+2
source

Are you saying that ?

The source code already comes with a tags file.

Uploading any file ( common.h in my case) to Vim, you can use :tag lac to go to the first lac definition or :tselect lac to choose between 3 entries in this project and :tag gconfig go to the unique gconfig definition.

See :help tags .

0
source

I am writing this answer to those using cscope in vim. In my case, I work a lot with the source code of the Linux kernel, and there are two million structures when I use cscope with vim. I get a list of 50 entries on average, and each time I go through the list, it's just a huge problem. For me it was important to get around this problem, so I implemented a dumb, but working idea, I wrote a patch for vim that sorts

0
source

All Articles