How to find out where a C struct is declared?

1.1k Views Asked by At

I am trying to add logging to the web proxy Polipo and as part of this need to log the url request in the following function following line:

httpClientRequest(HTTPRequestPtr request, AtomPtr url)

From compilation I see that AtomPtr is a struct of type _Atom but I cannot find where this is defined so that I can reference the text of the url in a log statement. What is the canonical method of looking up struct definitions in C code?

4

There are 4 best solutions below

0
On BEST ANSWER

you can search AtomPtr like this and see where AtomPtr is defined

typedef struct _Atom {
    unsigned int refcount;
    struct _Atom *next;
    unsigned short length;
    char string[1];
} AtomRec, *AtomPtr;
0
On

If you are working on Linux, then grep the struct keyword in the current directory to see the definition of it in the file.

0
On

Unfortunately, as far as I know, you cannot do this from the source code in C.
If you are working on Linux, and if your sources are all in the src/ directory:

$ find src/ -name ".*\.h" | xargs grep -e "struct _Atom"
0
On

I was able to look up the definition of a structure MenuType by

grep -Rwn --include \*.h "struct MenuType"

This post helped me.