# eel-ctools **Repository Path**: kingdix10/eel-ctools ## Basic Information - **Project Name**: eel-ctools - **Description**: 代码辅助工具 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 4 - **Forks**: 4 - **Created**: 2022-12-03 - **Last Updated**: 2024-11-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # 1. utils脚本说明 | script | function | | :--------------- | :------------------------------------------------------------------------- | | formatspace.sh | 删除行尾空格,换行符转为Linux格式,以\n结尾 | | linux-as.sh | astyle代码格式化脚本,Linux代码风格 | | code-as.sh | astyle代码格式化脚本,修改过的Linux代码风格 | | code-indent.sh | indent代码格式化脚本,基于linux scripts/Lindent修改,修改过的Linux代码风格 | | keepdep_patch.sh | 修改编译脚本,保留编译过程中的.o.d文件 | | depfilelist.sh | 根本编译生成的.o.d文件生成依赖文件列表 | linxu-as.sh和code-as.sh需要安装astyle。 code-indent.sh需安装indent。 # 2. ctools说明 ## 2.1. 环境准备 安装依赖包 ```shell sudo apt install python3 python3-pip python3-venv graphviz libgraphviz-dev # apt install python3-pygraphviz apt install openjdk-17-jre ``` 创建venv【可选】,如果提示 error: externally-managed-environment,则需要执行 ```shell python3 -m venv /data/.venvs/newenv/ # 路径随意 export PATH="/data/.venvs/newenv/bin/:${PATH}" ``` 安装依赖的wheel ```shell python3 -m pip install pygraphviz prettytable pycparser ply python3 -m pip install pyelftools watchdog html-table ``` 安装ctools ```shell git clone https://gitee.com/kingdix10/eel-ctools ctools cd ctools make install ``` ## 2.2. ctools ctree使用 构建cscope.out数据库 ```shell ctools ctree build -k --arch arm64 /path/to/kernel ctools ctree build -u --arch arm /path/to/u-boot ``` 查看调用关系和被调用关系 ```shell $ ctools ctree -d /path/to/cscope.out # 查看mm_init的调用关系 CTree=> mm_init > 1; mm_init > mt_init_flags; mm_init > mt_set_external_lock; mm_init > mmap_init_lock; mm_init > mm_pgtables_bytes_init; mm_init > mm_init_cpumask; mm_init > mm_init_aio; mm_init > mm_init_owner; mm_init > mm_pasid_init; mm_init > mmu_notifier_subscriptions_init; mm_init > init_tlb_flush_pending; mm_init > mm_init_uprobes_state; mm_init > hugetlb_count_init; mm_init > mm_alloc_pgd; mm_init > init_new_context; mm_init > mm_alloc_cid; mm_init > get_user_ns; mm_init > lru_gen_init_mm; mm_init > mm_destroy_cid; mm_init > destroy_context; mm_init > mm_free_pgd; mm_init > free_mm; # 查看mm_init的被调用关系 CTree=> 1 < mm_init ; mm_init < mm_alloc; mm_init < dup_mm; ``` 查看和修改控制变量 ```shell CTree=> pri show params tryshell False autorep True auto repeat when Enter exc_break True comment_prefix # cscope_db /path/to/cscope.out mode c c/gvtext/calltree/tree ctrl_direction auto >/ set mode c set mode c CTree=> q Exiting... ``` ## 2.3. ctools cview使用 帮助信息 ```c $ ctools cview CView=> help Documented commands (type help ): ======================================== EOF clear del exit p pri pwd quit set unset cd cls eval help pr print q reset shell Undocumented commands: ====================== addfile dumpfile export killfile newfile rmfile showfiles unexport ``` 解析文件结构 ```c CView=> dumpfile demo.c +-- _TreeNode(/path/to/demo.c None) | +-- ParamNode(template_version /path/to/demo.c:4:13) | +-- ParamNode(template_date /path/to/demo.c:5:13) | +-- ParamNode(NODE_COLOR_MIN /path/to/demo.c:7:5) | +-- ParamNode(NODE_COLOR_MAX /path/to/demo.c:8:5) | +-- ParamNode(EDGE_COLOR_MIN /path/to/demo.c:10:5) | +-- ParamNode(EDGE_COLOR_MAX /path/to/demo.c:11:5) | +-- ParamNode(CLUSTER_COLOR_MIN /path/to/demo.c:13:5) | +-- ParamNode(CLUSTER_COLOR_MAX /path/to/demo.c:14:5) | +-- ParamNode(MODE /path/to/demo.c:19:13) ... ... | +-- KeepNode(/path/to/demo.c:134:1 /path/to/demo.c:134:1) | +-- FuncNode(main /path/to/demo.c:142:1) | | +-- VarNode(var1 :143:17) | | +-- VarNode(var2 :143:23) | | +-- VarNode(array :144:17) | | +-- VarNode(invis_test :147:24) | | +-- LinkNode(var1.c + var2.b :149:12) | | +-- LinkNode(var1 --- var2 :150:10) | | +-- CallNode(func :152:5) | | +-- LinkNode(funcA >>>>> funcB :154:11) | | +-- KeepNode(:156:5 :156:5) | +-- FuncNode(func /path/to/demo.c:161:1) | | +-- VarNode(varA :162:17) | | +-- VarNode(varB :163:18) | | +-- KeepNode(:165:5 :165:5) | | +-- LinkNode(array.a <<< varB.xxx.private :166:13) ``` 添加文件 ```c CView=> addfile demo.c CView=> showfiles 1: /path/to/demo.c ``` 修改文件后,自动生成新图片 ```c CView=> !touch -m demo.c CView=> [2024-08-04 11:30:00,147] [INFO ] file /path/to/demo.c modified CView=> !ls demo* demo.c demo.png ```