#----------------------------------------------------------------- # pycparser: func_defs.py # # Using pycparser for printing out all the calls of some function # in a C file. # # Copyright (C) 2008-2015, Eli Bendersky # License: BSD #----------------------------------------------------------------- from __future__ import print_function import sys from pycparser import c_parser, c_ast, parse_file # A visitor with some state information (the funcname it's # looking for) # class FuncCallVisitor(c_ast.NodeVisitor): def __init__(self, funcname): self.funcname = funcname def visit_FuncCall(self, node): if node.name.name == self.funcname: print('%s called at %s' % (self.funcname, node.name.coord)) def show_func_calls(filename, funcname): ast = parse_file(filename, use_cpp=True) v = FuncCallVisitor(funcname) v.visit(ast) if __name__ == "__main__": if len(sys.argv) > 2: filename = sys.argv[1] func = sys.argv[2] else: filename = 'examples/c_files/hash.c' func = 'malloc' show_func_calls(filename, func)
Name | Type | Size | Permission | Actions |
---|---|---|---|---|
c_files | Folder | 0755 |
|
|
c-to-c.py | File | 1.42 KB | 0644 |
|
cdecl.py | File | 3.05 KB | 0644 |
|
explore_ast.py | File | 5.27 KB | 0644 |
|
func_calls.py | File | 1.08 KB | 0644 |
|
func_defs.py | File | 1.08 KB | 0644 |
|
rewrite_ast.py | File | 599 B | 0644 |
|
using_cpp_libc.py | File | 744 B | 0644 |
|
using_gcc_E_libc.py | File | 797 B | 0644 |
|