tags:

views:

656

answers:

5

Shouldn't be hard, right? Right?

I am currently trawling the OpenAFS codebase to find the header definition of pioctl. I've thrown everything I've got at it: checked ctags, grepped the source code for pioctl, etc. The closest I've got to a lead is the fact that there's a file pioctl_nt.h that contains the definition, except it's not actually what I want because none of the userspace code directly includes it, and it's Windows specific.

Now, I'm not expecting you to go and download the OpenAFS codebase and find the header file for me. I am curious, though: what are your techniques for finding the header file you need when everything else fails? What are the worst case scenarios that could cause a grep for pioctl in the codebase to not actually come up with anything that looks like a function definition?

I should also note that I have access to two independent userspace programs that have done it properly, so in theory I could do an O(n) search for the function. But none of the header files pop out to me, and n is large...

Edit: The immediate issue has been resolved: pioctl() is defined implicitly, as shown by this:

AFS.xs:2796: error: implicit declaration of function ‘pioctl’
+2  A: 

There are compiler options to show the preprocessor output. Try those? In a horrible pinch where my head was completely empty of any possible definition the -E option (in most c compilers) does nothing but spew out the the preprocessed code.

Per requested information: Normally I just capture a compile of the file in question as it is output on the screen do a quick copy and paste and put the -E right after the compiler invocation. The result will spew preprocessor output to the screen so redirect it to a file. Look through that file as all of the macros and silly things are already taken care of.

Worst case scenarios:

  • K&R style prototypes
  • Macros are hiding the definition
  • Implicit Declaration (per your answer)
ojblass
What stage during the compilation process would be most appropriate for this?
Edward Z. Yang
+2  A: 

If grep -r and ctags are failing, then it's probably being defined as the result of some nasty macro(s). You can try making the simplest possible file that calls pioctl() and compiles successfully, and then preprocessing it to see what happens:

gcc -E test.c -o test.i
grep pioctl -C10 test.i
Adam Rosenfield
A: 

Have you considered using cscope (available from SourceForge)?

I use it on some fairly significant code sets (25,000+ files, ranging up to about 20,000 lines in a file) with good success. It takes a while to derive the file list (5-10 minutes) and longer (20-30 minutes) to build the cross-reference on an ancient Sun E450, but I find the results useful.


On an almost equally ancient Mac (dual 1GHz PPC 32-bit processors), cscope run on the OpenAFS (1.5.59) source code comes up with quite a lot of places where the function is declared, sometimes inline in code, sometimes in headers. It took a few minutes to scan the 4949 files, generating a 58 MB cscope.out file.

  • openafs-1.5.59/src/sys/sys_prototypes.h
  • openafs-1.5.59/src/aklog/aklog_main.c (along with comment "Why doesn't AFS provide these prototypes?")
  • openafs-1.5.59/src/sys/pioctl_nt.h
  • openafs-1.5.59/src/auth/ktc.c includes a define for PIOCTL
  • openafs-1.5.59/src/sys/pioctl_nt.c provides an implementation of it
  • openafs-1.5.59/src/sys/rmtsysc.c provides an implementation of it (and sometimes afs_pioctl() instead)

The rest of the 184 instances found seem to be uses of the function, or documentation references, or release notes, change logs, and the like.

Jonathan Leffler
I would imagine that, if I grepped through /usr/include for pioctl and didn't find any mention of pioctl, cscope wouldn't be able to find it either.
Edward Z. Yang
cscope will look in places outside /usr/include, such as the source tree. Have you checked to see whether pioctl() appears as a referenced symbol in the object file? If it appears in the source (not commented out by #ifdef et al) and not in the object, then there must be a macro somewhere that redefines it.
Jonathan Leffler
What Googling have you done? Simply searching for 'pioctl' comes up with plausible references in a number of places - some of the better ones seem to be on the second page (items 11..20) of the search. One system has 'sys/sys_pioctl.h', for example. There are also suggestions that pioctl() may be implemented as a call to regular 'ioctl'.
Jonathan Leffler
I have the OpenAFS source tree, and have also been grepping it heavily. I also know where the "real function definition" is (there are, in fact, multiple definitions of it). sys/sys_pioctl.h doesn't exist for me (not in source tree, not in /usr/include). pioctl() used to be ioctl() with some extra code spliced into the kernel at runtime, but then GPL happened and OpenAFS had to stop doing that.
Edward Z. Yang
A: 

Doesn't it usually say in the man page synopsis?

Jeremy Huiskamp
Manpages? Haha, you make me laugh! OpenAFS has no manpages.
Edward Z. Yang
A: 

The current working theory that we've decided on, after poking at the preprocessor and not finding anything either, is that OpenAFS is letting the compiler infer the prototype of the function, since it returns an integer and takes pointer, integer, pointer, integer as its parameters. I'll be dealing with this by merely defining it myself.

Edit: Excellent! I've found the smoking gun:

AFS.xs:2796: error: implicit declaration of function ‘pioctl’
Edward Z. Yang
Does it still compile if you add the '-Werror-implicit-function-declaration' flag to disallow implicit function declarations?
Adam Rosenfield
So... it failed on an incompatible memcpy declaration...
Edward Z. Yang
Found it! See edit.
Edward Z. Yang