0

I am trying to modify few existing c-functions in my project, and add a line of code at the beginning of each function using python. But I am unable to obtain the first line inside a function. What I have tried: -- using the gcc-addr2line utility to convert the absolute start address of function into the corresponding line inside c-code. However it doesn't always return the first line(in case the first operation is a conditional execution, it returns the line where first statement inside condition executes).

-- also tried using regular expression to identify the start of function. (for ex: void\s*_function__name_\s*\(.*\)\s*{). Doesn't return what I need. Also I am not very experienced with this.

I do not have trouble finding the function definition, although I am not able to find the line where the first statement inside c-function exists.

mdameenh
  • 9
  • 3
  • Well, is it 100% of the time that the functions in a *.c file start with `void`? Your regex `void\s*_function__name_\s*\(.*\)\s*{` will always search for one and only one function not all the functions. – Gaurav Pathak Sep 20 '17 at 06:35
  • Possible duplicate of [Python script to print all function definitions of a C/C++ file](https://stackoverflow.com/questions/1620851/python-script-to-print-all-function-definitions-of-a-c-c-file) – Gaurav Pathak Sep 20 '17 at 06:38
  • yes, the return is always void. – mdameenh Sep 20 '17 at 06:42
  • @GauravPathak> searching for all functions in a generic way simply cannot be done with a regular expression. On the other hand, searching for all functions with a known pattern in a known set of files might be doable. He's right exploiting the knowledge he has of his files. – spectras Sep 20 '17 at 07:52
  • 1
    @mdameenh> On the other hand, this means you must show some samples of what you're trying to find, since the solution has to be tied to your specific use case. – spectras Sep 20 '17 at 07:58
  • Looks interesting! Can you show us a couple of instances of each of the kinds of functions you have to process? (Put them in your question.) – Bill Bell Sep 21 '17 at 17:28

0 Answers0