I have a C file in which I would like to add a print at the beginning and end of each function that includes file name, function name and line number. I am trying to automate this for an entire folder of C files using python.
Example: For function add in math.c file
int add(int a, int b){
sum = a +b;
return sum;
}
I would want the result file to look something like this:
int add(int a, int b){
printf("Math.c, add, 12");
sum = a +b;
return sum;
}
I am looking at the regex as suggested in this link Using Python Regex to Find C function in File
Any other suggestions? Ctags is the other option I am exploring, but I prefer using python libraries if any for this purpose.
Edit:
- Running the code on a microcontroller
- Not using Linux
- Debugger with limited capabilities (can get printf only)