Notes
main
main
  • Introduction
  • linuxKernel
    • tips
    • make_help
    • old linux
      • compile_linux0.11
      • TestEnvironment
      • load_setup
      • get_hard_data
    • list
    • plist
    • fifo
    • idr
    • xarray
    • rbtree
    • maple_tree
    • syscall
    • bitmap
    • page
    • page_flags
    • page_size
    • page mapcount
    • page refcount
    • folio
    • slub
      • proc_slabinfo
      • slub_theory
      • kmalloc_kfree
      • kmem_cache
      • slab_alloc
      • slab_free
      • proc_meminfo_SReclaimable_SReclaimable
    • vmalloc
    • brk
    • mmap
    • mremap
    • mprotect
    • madvise
    • read
    • write
    • shmem
    • huge_page
    • page_fault
    • rmap
    • lru
    • multi-gen-LRU
    • page_reclaim
    • page_cache
    • page_table
    • rcu
    • kvm
    • aarch64_boot
    • tracing_system
    • cache_coherence_and_memory_consistency
    • cpu_speculates
    • mmap_lock
    • per-vma_lock
    • cgroup
    • symbol
    • campact
    • page_ext
    • mempool
    • kernelstack
    • filesystem
    • io_stack
    • workingset
    • ioremap
    • sched_period
  • linuxDebug
    • openocd_openjtag
    • i2c_tools
    • objdump
    • addr2line
    • gdb_useage
    • debug_linux_kernel_via_gdb
    • debug_linux_module_via_gdb
    • early_boot
    • sequentially_execute
    • dynamic_debug
    • research_linuxKernel_by_patch
    • tracefs
    • ebpf
    • bpftrace
    • perf
    • flame_graph
    • crash
    • ASAN_HWASAN_MTE_check_mem_bug
    • page_owner
    • vmtouch
    • fio
    • benchmark
  • linuxSystem
    • common
      • system_version
      • procfs
      • proc_sys_vm
      • cmd_ps
      • makefile
      • file_descriptor
      • psi
      • ulimit
      • top
      • delay_accounting
    • ubuntu
      • custom_kernel
      • get_cmd_src
      • record_ssh_info
      • log
      • run_custom_script
      • repo
      • cockpit
      • nfs
      • tftp
      • misc
    • fedora
      • system_upgrade
      • custom_kernel
      • lvextend
      • yt-dlp
      • jellyfin
  • linuxDriver
    • i2c_peripherals_driver
    • spi_peripherals_driver
    • gpio_subsystem
    • IRQ_driver
    • blockIO_unblockIO_async
    • linux_own_driver
    • misc_device
    • input_device
    • timer
    • atomic_spinlock_semaphore_mutex
    • lcd
    • touch_screen
    • debugfs
    • v4l2
    • mmap
  • hardware
    • paging_mmu_pt
    • iommu
  • process_thread_scheduler
    • scheduler01
    • scheduler02
    • scheduler03
    • scheduler04
    • scheduler05
    • scheduler06
  • memory_management
    • mm1
    • mm2
    • mm3
    • mm4
    • mm5
  • input_output_filesystem
    • io_fs_01
    • io_fs_02
    • io_fs_03
    • io_fs_04
  • lock_and_lockup_detector
    • general_lock
    • hung_task
    • softLockup_hardLockup
    • crash_experiment
  • MIT_6.S081
    • 6.S081_Operating_System_Engineering
    • Schedule.md
    • Class
      • Overview
      • Administrivia
    • Labs
      • Tools
      • Guidance
      • startup
      • syscall
      • page_table
      • Calling_Convention
      • traps
    • xv6
      • xv6
    • References.md
  • qemu
    • qemu_buildroot
    • qemu_busybox.md
    • Serial.md
    • demo_mini2440
      • 0_compilation_error_summary
      • 1_compilation_steps
      • 2_operation_mode
      • 3_transplant_tools_libraries
      • 4_tools_use
      • reference_website
  • tools
    • getKernelSourceCodeList
    • nat
    • shell
    • translating
    • YouCompleteMe
    • cscope
    • global
    • vscode
    • vim
    • binary
    • markdown
    • draw
    • git
    • tig
    • tmux
    • mail_client
    • download_patchset_from_LKML
    • minicom
    • clash
  • other
    • interview
    • interview_c_base
    • know_dontknow
    • Stop-Ask-Questions-The-Stupid-Ways
    • How-To-Ask-Questions-The-Smart-Way
    • docker
    • buildroot
    • rv32_to_rv64
Powered by GitBook
On this page
  • 安装
  • 生成数据库
  • 查询

Was this helpful?

  1. tools

cscope

安装

安装cscope,以ubuntu为例:

$ sudo apt install cscope

生成数据库

生成cscope数据库,以linux kernel为例:

$ make ARCH=arm cscope          # 只生成arm的数据库
或
$ cscope -b -q -k -f cscope.out # 不建议使用,默认会生成所有arch的数据库

查询

通过cscope查询 函数在哪里定义 或 函数在哪里被调用等等,下面分别介绍vim与vscode是如何进行查询

A. 当通过vim进行查询

首先,在/etc/vim/vimrc.local添加如下配置

set cscopeprg=cscope

if filereadable("cscope.out")
    cs add cscope.out
else
    let cscope_file=findfile("cscope.out", ".;")
    let cscope_pre=matchstr(cscope_file, ".*/")
    if !empty(cscope_file) && filereadable(cscope_file)
        exe "cs add" cscope_file cscope_pre
    endif
endif

nmap <C-@>g :cs find g <C-R>=expand("<cword>")<CR><CR> " Find function definition
nmap <C-@>c :cs find c <C-R>=expand("<cword>")<CR><CR> " Find function call

然后,用vim打开某一个文件后,就可以通过ctrl-@ g查询 函数在哪里定义,通过ctrl-@ c查询 函数在哪里被调用

B. 通过vscode进行查询

首先,安装 scope4code插件

接着,配置xxx.code-workspace的settings属性,如下:

"scope4code.databasePath": "${workspaceRoot}/",
"scope4code.engineCommands": {
    "config_index": {
        "cscope": {
            "linux": 0
        }
    },
    "config": [
        {
            "find_cmd": "find ${src_path} -type f -name *.c -o -type f -name *.h -o -type f -name *.cpp -o -type f -name *.cc -o -type f -name *.mm",
            // "database_cmd": "cscope -b -q -k -f ${database_path}/cscope.out",
            "database_cmd": "make ARCH=x86 cscope",
            "find_all_ref": "cscope -q -k -f ${database_path}/cscope.out -L0 ${text}",
            "find_define": "cscope -q -k -f ${database_path}/cscope.out -L1 ${text}",
            "find_callee": "cscope -q -k -f ${database_path}/cscope.out -L2 ${text}",
            "find_caller": "cscope -q -k -f ${database_path}/cscope.out -L3 ${text}",
            "find_text": "cscope -q -k -f ${database_path}/cscope.out -L4 ${text}"
        }
    ]
}

然后,用vscode打开某一个文件后,就可以通过右键->xxx查询 函数在哪里定义 或 函数在哪里被调用

PreviousYouCompleteMeNextglobal

Last updated 3 years ago

Was this helpful?