如何利用Callgraph生成函数调用图?
生活随笔
收集整理的這篇文章主要介紹了
如何利用Callgraph生成函数调用图?
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
Ubuntu版本:ubuntu-gnome-16.04-desktop-amd64,gnome版
-----------------------------------------------------------------------
1. 安裝 Callgraph Callgraph 實際由三個工具組合而成。
2. 使用 2.1 生成調(diào)用圖 callgraph -f main -d ./file.c -b firefox 指定分析file.c文件中的main函數(shù),并使用firefox顯示圖片,也可以使用其他瀏覽器。 生成的函數(shù)調(diào)用關(guān)系圖默認(rèn)保存為main.file_c.svg。
2.2 其他用法 1)類似 main 函數(shù),實際也可渲染其他函數(shù),例如: callgraph -f test1 -d ./file.c -b firefox 2)指定函數(shù)所在文件(或者指定函數(shù)搜索路徑) 使用 -d 選項 3)砍掉不感興趣的函數(shù)分支 callgraph -f main -d file.c -F printf -b firefox 同時指定多個函數(shù)分支: callgraph -f main -d file.c -F "printf test3 test2" -b firefox 4)指定函數(shù)調(diào)用深度: 用 -D 命令可以指定:callgraph -f main -d file.c -D 2 -b firefox
3. 代碼 #include<stdio.h>void test1(); void test2(); void test3();void test1() {printf("hello"); }void test2() {test3(); }void test3() {}void main() {test1();test2();test3();printf("hello.\n"); }
1. 安裝 Callgraph Callgraph 實際由三個工具組合而成。
- 一個是用于生成 C 函數(shù)調(diào)用樹的 cflow 或者 calltree,下文主要介紹 cflow。
- 一個處理 dot 文本圖形語言的工具,由 graphviz 提升。
- 一個用于把 C 函數(shù)調(diào)用樹轉(zhuǎn)換為 dot 格式的腳本:tree2dotx
2. 使用 2.1 生成調(diào)用圖 callgraph -f main -d ./file.c -b firefox 指定分析file.c文件中的main函數(shù),并使用firefox顯示圖片,也可以使用其他瀏覽器。 生成的函數(shù)調(diào)用關(guān)系圖默認(rèn)保存為main.file_c.svg。
2.2 其他用法 1)類似 main 函數(shù),實際也可渲染其他函數(shù),例如: callgraph -f test1 -d ./file.c -b firefox 2)指定函數(shù)所在文件(或者指定函數(shù)搜索路徑) 使用 -d 選項 3)砍掉不感興趣的函數(shù)分支 callgraph -f main -d file.c -F printf -b firefox 同時指定多個函數(shù)分支: callgraph -f main -d file.c -F "printf test3 test2" -b firefox 4)指定函數(shù)調(diào)用深度: 用 -D 命令可以指定:callgraph -f main -d file.c -D 2 -b firefox
3. 代碼 #include<stdio.h>void test1(); void test2(); void test3();void test1() {printf("hello"); }void test2() {test3(); }void test3() {}void main() {test1();test2();test3();printf("hello.\n"); }
總結(jié)
以上是生活随笔為你收集整理的如何利用Callgraph生成函数调用图?的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 游戏与“神隐”文化
- 下一篇: Intel 4/3/20A/18A四种新