# callgraph-py2 **Repository Path**: lbit/callgraph-py2 ## Basic Information - **Project Name**: callgraph-py2 - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-07-08 - **Last Updated**: 2026-07-08 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # callgraph-py2 Find all callees of a C/C++ function using the **clangd** LSP server. Since clangd 14 does not implement `callHierarchy/outgoingCalls`, this tool uses an alternative approach: it locates the target function via `prepareCallHierarchy`, scans its body for call sites, and resolves each callee's definition using `textDocument/definition`. ## Architecture ``` src/ ├── main.py # CLI entry point └── core/ # Core library ├── lsp.py # Generic LSP client (JSON-RPC over stdio) ├── clangd.py # Clangd server wrapper (spawn, init, document ops) ├── finder.py # Callee finder (body scan + definition resolution) └── project.py# Project root auto-detection ``` - **`core/lsp.py`** — A general-purpose LSP client that implements JSON-RPC message framing (Content-Length headers), request/response correlation, and server-request handling. Works with any LSP server, not just clangd. - **`core/clangd.py`** — Wraps the LSP client with clangd-specific configuration (compile_commands.json path, background indexing, document management). - **`core/finder.py`** — Uses `prepareCallHierarchy` to obtain the function body range, scans the source for call sites (`identifier(`), and resolves each callee via `textDocument/definition`. When line/column are not provided, locates the function via `documentSymbol`. - **`project.py`** — Walks up the directory tree to find the project root, prioritising `compile_commands.json`. ## Usage ```bash # Install dependencies (none required — pure stdlib) cd /home/linux/code/callgraph-py2 uv sync # Run built-in targets uv run callgraph-py2 --root /home/linux/code/lynxi-drivers/ # Analyse a single function (auto-locate position) uv run callgraph-py2 \ --func lynd_pci_probe \ --file /home/linux/code/lynxi-drivers/lyn_drv/drivers/pci_host/lynd_pci_host.c # Analyse with explicit position (1-based line/column) uv run callgraph-py2 \ --func lynd_pci_remove \ --file /home/linux/code/lynxi-drivers/lyn_drv/drivers/pci_host/lynd_pci_host.c \ --line 1724 --column 1 ``` ## Output Each callee is printed with its name, file path, line, and column: ``` ============================================================ Function: lynd_pci_remove File: /home/linux/code/lynxi-drivers/lyn_drv/drivers/pci_host/lynd_pci_host.c Pos: line 1724, col 1 Callees (8): lynd_tag /home/linux/code/lynxi-drivers/.../lynd_pci_host.c:1728:2 pci_disable_device /home/linux/code/lynxi-linux/drivers/pci/pci.c:4567:1 ... ============================================================ ``` ## Line / Column Convention Line and column arguments are **1-based** (as displayed in editors). They are converted to 0-based internally for the LSP protocol.