0

I'm trying to analyze functions by using clang libtooling. Here is the source code that I want to analyze:

#include <stdio.h>

int main(){
    int a = 100;
    printf("a==%d", a);
}

when I run my tool to get all the function decl in above files, I found there are a lot of build-in / system functions, like:

decls: 
_IO_cookie_init
 __underflow
 __uflow
 __overflow
 _IO_getc
 _IO_putc
 _IO_feof
 _IO_ferror
 _IO_peekc_locked
 _IO_flockfile
 _IO_funlockfile
 _IO_ftrylockfile
 _IO_vfscanf
 _IO_vfprintf
 _IO_padn
 _IO_sgetn
 _IO_seekoff
 _IO_seekpos
 _IO_free_backup_area
 remove
 rename
 renameat
 tmpfile
 tmpfile64
 tmpnam
 tmpnam_r
 tempnam
 fclose
 fflush
 fflush_unlocked
 fcloseall
 fopen

(I think they are introduced by the header file "stdio.h" )

my question is: How can I get rid of all these built-in/system functions from the "stdio.h" file, or other (system) header files?

Thanks in advance!!!

ignorer
  • 327
  • 1
  • 11
  • Does your tool look for functions that are defined or functions that are just declared and not defined? – deLta Jul 09 '17 at 02:35
  • @deLta Thanks for replying. Currently, I just look for the decls of functions created by the programmers themselves. – ignorer Jul 11 '17 at 21:18
  • @deLta BTW, the method of getting defined function and that of getting declared and not defined function are different? I'm curious about it. Would it be possible to explain a little bit about it? Thanks :) – ignorer Jul 11 '17 at 21:21
  • Are you using [isDeclaration](http://llvm.org/doxygen/classllvm_1_1GlobalValue.html#a32e606ac4c88f71f14212e42b808e7f4)? – deLta Jul 11 '17 at 21:27
  • @deLta Not yet. I've checked the spec. Maybe it can help. – ignorer Jul 11 '17 at 21:35

1 Answers1

2

When you visit a function, check if its location (startLoc or endLoc) is in system header using SourceManagers api 'isInSystemHeader(loc)'

e.g.:

Bool VisitFunctionDecl(FunctionDecl * D)
{
    If(sourceManager.isInSystemHeader(D->getLocStart()))
        return true;
}

Thanks, Hemant

Hemant
  • 767
  • 6
  • 20