Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Here is a project source code folder for c/c++, I want to write a small and fast tool/script to get the filename, line number, and function name for all source files .

For example, I want it will output like below:

./src/a.c line 1500 call func1(); ./src/a.c line 1600 call func1();
./src/a.c line 1700 call func2(); ./src/b.c line 1700 call func3();
...


for example,here is tmp.c's context,I want it to analyze the file,
C++


C#
#include <stdio.h>
#include <string.h>  
int main (){   
        char dest1[4];   
        char dest2[4];   
        char *src="Sample string";   
        strcpy (dest2,strcpy(dest1,src));   
        printf ("src1: %s\ndest: %s\n",src,dest1);
        return 0;
 }

and output like :

./tmp.c line 7 call strcpy
./tmp.c line 8 call printf

How to do it with any tools or language? best with gcc.

What I have tried:

get function call's name,and line number for a file.
Posted
Updated 30-Aug-16 19:33pm
Comments
Richard MacCutchan 31-Aug-16 3:27am    
You need to write a code analyser/parser. Google for those terms and you will find lots of information.
Member 12712046 31-Aug-16 4:07am    
Thanks for your reply.I think it would be a lot of work to do it.Is there any way to do it in a easy and fast way, such as base on gcc/ctags/cscope/... any other tools?
Richard MacCutchan 31-Aug-16 8:59am    
Yes, it would be a lot of work. However, if you can find some open source code that already does some of the work you could always adapt that.

1 solution

You can use C macros __func__ and __LINE__ Please refer below link for more details,
C macros __LINE__, __FILE__ and __func__[^]
 
Share this answer
 
Comments
Member 12712046 31-Aug-16 2:43am    
thanks,for your reply.But the precondition is I can't modify the source code,and there are lots of ".c" and ".cpp" source files. What I can do,just is read it. get those information.
LaxmikantYadav 31-Aug-16 4:09am    
You can try doxygen tool

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900