I want to visualize the relationship between function calls as an analysis of past software.

Asked 1 years ago, Updated 1 years ago, 45 views

I am currently analyzing past software.
Do you have an application that lists function calls?

I was able to make a call graph with doxygen, but it's too complicated and I can't document it
I'd like to print it out using csv etc. (not limited to csv, it would be great if I could list it anyway)

foa->fob->foc1
->footc2

If it's a call
fooa, foob, fooc1
,foot2

Looking for software to print as shown in
I'd appreciate it if you could mark it as well because it's meaningless recursion and function calls loop. Anyway, please let me know if there are any apps that I can list.

c

2022-09-30 21:33

2 Answers

As user29553 commented, I think cflow is good.
I tried shaping the results into CSV.

[Examples of awk plastic surgery (call_stack.sh)]

#!/bin/bash
while read file; docflow${file}; done | sed'
s/\t/g
US>s /)/)\t/
' |awk-F'\t' '
US>BEGIN{
        ## DELIMITER="->"
        DELIMITER=", "
}
{
        num = NF;
        for (no=1; no<=num;no++) {
                if($no!=""){
                        if(!match($no, "^<")}
                                ga[no] = $no
                        }
                        else{
                                if(match($no, "recursive:")}
                                        ga[no-1] = ga[no-1]"*";
                                }
                                delete ga [ no ];
                                num - = 1;
                        }
                }
        }
        dlmt=""
        call_stack=";
        for (no=1; no<=num;no++) {
                call_stack = call_stack dlmtga [no]
                dlmt = DELIMITER
        }
        printf("%s\n", call_stack);
}
'

[How to use]

find.-name "*.c" | ./call_stack.sh

[Results]
I marked the function * because cflow detects simple recursive calls.


func()
func(), printf()
func(), func2()
func(), n_sub()
func(), n_sub(), func3()
func(), n_sub(), printf()
func(), func()*
func2()
func2(), printf()
func2(), n_sub()
func2(), n_sub(), func3()
func2(), n_sub(), printf()
func2(), func()
func3()
func3(), printf()
func3(), func2()
func3(), n_sub()
func3(), n_sub(), printf()
main()
main(), printf()
main(), n_sub()
main(), n_sub(), printf()
main(), func()
main(), func2()

[Cflow Output (Reference)]

for file in *.c; docflow${file}; done
 func()<int func() at func.c:7>(R):
    printf()
    func2()
    n_sub()<int n_sub() at func.c:14>:
        func3()
        printf()
    func()<int func() at func.c:7>(recursive:see1)
func2()<int func2(void) at func2.c:7>:
    printf()
    n_sub()<int n_sub() at func2.c:13>:
        func3()
        printf()
    func()
func3()<int func3() at func3.c:5>:
    printf()
    func2()
    n_sub()<int n_sub() at func3.c:11>:
        printf()
main()<int main(intargc, char*argv[]) at main.c:6>:
    printf()
    n_sub()<int n_sub() at main.c:13>:
        printf()
    func()
    func2()

使用Tools Used 】

cflow(GNU cflow) 1.4
sed(GNUsed) 4.4
GNU bash, version 4.4.20(1)-release(x86_64-pc-linux-gnu)
GNU Awk 4.1.4, API: 1.1 (GNU MPFR 4.0.1, GNU MP 6.1.2)

[Free gift]

With Clang's Python binding, C language source analysis is very easy.
※ cflow is easier if you're just looking at the calling relationship of a function.


2022-09-30 21:33

Unfortunately, huge number of steps will be of little use to existing tools.
In my case, I made two simple scripts in Perl.
Source 1) Script 1
Detects ' and prints out List 1 as follows: --- <List 1
:
...
---
おYou may want to use a preprocessor in advance.

No. 2) Script 2
that follows list 1 and prints list 2 like this: --- <List 2
: : ...
...
---
「 It means "A function 2 is called from a function 1 and a function 3 is called from a function 2".

If you can do list 1, it's useful to find out who the parent is, so that you can see the range of influence from the top when you make changes to a function.
These scripts are instantly listed, and there are many advantages such as finding problems with existing sources.
For this reason, I recommend that you create your own tools.
Also, you should avoid using the tools that you can get for free, as they say you are not responsible for anything.


2022-09-30 21:33

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.