• ctags命令行使用笔记


    所有命令行选项使用的官方手册: https://docs.ctags.io/en/latest/man/ctags.1.html#synopsis

    !_TAG_FILE_FORMAT       2       /extended format; --format=1 will not append ;" to lines/
    !_TAG_FILE_SORTED       1       /0=unsorted, 1=sorted, 2=foldcase/

    这些称为 pseudo tags,--pseudo-tags=[+|-](|*)可以设置是否开启

    有4个域,各自包含标识符的信息

    1. fields,命令行 --list-fields 查看,查看对于universal ctags.exe新增的关于c++的一些属性标记信息 --list-fields=c++
    2. kinds,--list-kinds
    3. extras,同理
    4. roles,同理查看

    查看到的,比如fields域,有些enable是该功能是否使能,我们通过  --fields-c++=+{xx} 就可以来打开fields域对应的xx功能

    • --list-xx:用于打印出关于xx功能的信息
    •  xx=:是用于设置这个xx功能的
    • --list-map-extensions=all:列出所有语言的名称对应的源文件扩展名
    • 很多选项都有单字母缩写,如果混用的话,长符号需要加大括号{}
    • --_xformat 自己定制xref格式,使用类似printf函数那样的占位符使用

    查看fields字段具有哪些信息

    1. .\ctags.exe --list-fields
    2. #LETTER NAME ENABLED LANGUAGE JSTYPE FIXED DESCRIPTION
    3. N name yes NONE s-- yes tag name
    4. F input yes NONE s-- yes input file
    5. P pattern yes NONE s-b yes pattern
    6. C compact no NONE s-- no compact input line (used only in xref output)
    7. E extras no NONE s-- no Extra tag type information
    8. K NONE no NONE s-- no Kind of tag as full name
    9. R NONE no NONE s-- no Marker (R or D) representing whether tag is definition or reference
    10. S signature no NONE s-- no Signature of routine (e.g. prototype or parameter list)
    11. Z scope no NONE s-- no Include the "scope:" key in scope field (use s) in tags output, scope name in xref output
    12. a access no NONE s-- no Access (or export) of class members
    13. e end no NONE -i- no end lines of various items
    14. f file yes NONE --b no File-restricted scoping
    15. i inherits no NONE s-b no Inheritance information
    16. k NONE yes NONE s-- no Kind of tag as a single letter
    17. l language no NONE s-- no Language of input file containing tag
    18. m implementation no NONE s-- no Implementation information
    19. n line no NONE -i- no Line number of tag definition
    20. p scopeKind no NONE s-- no Kind of scope as full name
    21. r roles no NONE s-- no Roles
    22. s NONE yes NONE s-- no Scope of tag definition (`p' can be used for printing its kind)
    23. t typeref yes NONE s-- no Type and name of a variable or typedef
    24. x xpath no NONE s-- no xpath for the tag
    25. z kind no NONE s-- no Include the "kind:" key in kind field (use k or K) in tags output, kind full name in xref output
    26. - properties no AutoIt s-- no properties (static, volatile, ...)
    27. - macrodef no C s-- no macro definition
    28. - properties no C s-- no properties (static, inline, mutable,...)
    29. - captures no C++ s-- no lambda capture list
    30. - macrodef no C++ s-- no macro definition
    31. - name yes C++ s-- no aliased names
    32. - properties no C++ s-- no properties (static, inline, mutable,...)
    33. - template no C++ s-- no template parameters
    34. - macrodef no CPreProcessor s-- no macro definition
    35. - macrodef no CUDA s-- no macro definition
    36. - properties no CUDA s-- no properties (static, inline, mutable,...)
    37. - access yes Elixir s-- no access
    38. - howImported no Go s-- no how the package is imported ("inline" for `.' or "init" for `_')
    39. - package yes Go s-- no the real package specified by the package name
    40. - packageName yes Go s-- no the name for referring the package
    41. - implements yes Inko s-- no Trait being implemented
    42. - assignment yes LdScript s-- no how a value is assigned to the symbol
    43. - sectionMarker no Markdown s-- no character used for declaring section(#, ##, =, or -)
    44. - version no Maven2 s-- no version of artifact
    45. - wrapping yes Moose s-- no how a wrapper wrapping the method (around, after, or before)
    46. - langid yes NSIS s-- no language identifier specified in (License)LangString commands
    47. - category yes ObjectiveC s-- no category attached to the class
    48. - protocols yes ObjectiveC s-- no protocols that the class (or category) confirms to
    49. - home yes Passwd s-- no home directory
    50. - shell yes Passwd s-- no login shell
    51. - decorators no Python s-- no decorators on functions and classes
    52. - sectionMarker no ReStructuredText s-- no character used for declaring section
    53. - uri yes XML s-- no uri associated with name prefix

    查看kinds字段具有哪些信息

    1. .\ctags.exe --list-kinds=c
    2. d macro definitions
    3. e enumerators (values inside an enumeration)
    4. f function definitions
    5. g enumeration names
    6. h included header files
    7. l local variables [off]
    8. m struct, and union members
    9. p function prototypes [off]
    10. s structure names
    11. t typedefs
    12. u union names
    13. v variable definitions
    14. x external and forward variable declarations [off]
    15. z function parameters inside function definitions [off]
    16. L goto labels [off]
    17. D parameters inside macro definitions [off]

    查看roles字段具有哪些信息

    1. .\ctags.exe --list-roles=c
    2. #KIND(L/N) NAME ENABLED DESCRIPTION
    3. d/macro undef on undefined
    4. h/header local on local header
    5. h/header system on system header

    查看extras字段具有哪些信息

    1. .\ctags.exe --list-extras
    2. #LETTER NAME ENABLED LANGUAGE FIXED DESCRIPTION
    3. - anonymous yes NONE no Include tags for non-named objects like lambda
    4. F fileScope yes NONE no Include tags of file scope
    5. f inputFile no NONE no Include an entry for the base file name of every input file
    6. g guest no NONE no Include tags generated by guest parsers
    7. p pseudo yes NONE no Include pseudo tags
    8. q qualified no NONE no Include an extra class-qualified tag entry for each tag
    9. r reference no NONE no Include reference tags
    10. s subparser yes NONE no Include tags generated by subparsers
    11. - funcmap yes QemuHX no Include mapping SQMP to C function name
    12. - whitespaceSwapped yes Robot no Include tags swapping whitespace and underscore chars

    例子:打印出源码工程中所有字段属性信息(json格式)

    从上面的enable列可以看出,有些属性是没有开启的,这里我们用--xx=*,就是开启xx字段的所有属性了,所以这里例子,打印出ctags能记录的所有属性信息

    1. .\ctags.exe --output-format=json --kinds-all=* --extras=* --fields=* -R
    2. {"_type": "ptag", "name": "JSON_OUTPUT_VERSION", "path": "0.0", "pattern": "in development"}
    3. {"_type": "ptag", "name": "TAG_FILE_SORTED", "path": "1", "pattern": "0=unsorted, 1=sorted, 2=foldcase"}
    4. {"_type": "ptag", "name": "TAG_OUTPUT_FILESEP", "path": "backslash", "pattern": "slash or backslash"}
    5. {"_type": "ptag", "name": "TAG_PROGRAM_AUTHOR", "path": "Universal Ctags Team", "pattern": ""}
    6. {"_type": "ptag", "name": "TAG_PROGRAM_NAME", "path": "Universal Ctags", "pattern": "Derived from Exuberant Ctags"}
    7. {"_type": "ptag", "name": "TAG_PROGRAM_URL", "path": "https://ctags.io/", "pattern": "official site"}
    8. {"_type": "ptag", "name": "TAG_PROGRAM_VERSION", "path": "0.0.0", "pattern": "fefbad26"}
    9. {"_type": "tag", "name": "TEST_H", "path": "test.h", "pattern": "/^#define TEST_H$/", "language": "C++", "line": 2, "kind": "macro", "roles": "def", "end": 2}
    10. {"_type": "tag", "name": "a", "path": "main.c", "pattern": "/^\tint a = 1;$/", "file": true, "language": "C", "line": 9, "typeref": "typename:int", "kind": "local", "roles": "def", "scope": "main", "extras": "fileScope", "scopeKind": "function"}
    11. {"_type": "tag", "name": "a", "path": "test.c", "pattern": "/^int fun(int a, int b)$/", "file": true, "language": "C", "line": 4, "typeref": "typename:int", "kind": "parameter", "roles": "def", "scope": "fun", "extras": "fileScope", "scopeKind": "function"}
    12. {"_type": "tag", "name": "argc", "path": "main.c", "pattern": "/^int main(int argc, char *argv[]) {$/", "file": true, "language": "C", "line": 8, "typeref": "typename:int", "kind": "parameter", "roles": "def", "scope": "main", "extras": "fileScope", "scopeKind": "function"}
    13. {"_type": "tag", "name": "argv", "path": "main.c", "pattern": "/^int main(int argc, char *argv[]) {$/", "file": true, "language": "C", "line": 8, "typeref": "typename:char * []", "kind": "parameter", "roles": "def", "scope": "main", "extras": "fileScope", "scopeKind": "function"}
    14. {"_type": "tag", "name": "b", "path": "main.c", "pattern": "/^\tint b = 2;$/", "file": true, "language": "C", "line": 10, "typeref": "typename:int", "kind": "local", "roles": "def", "scope": "main", "extras": "fileScope", "scopeKind": "function"}
    15. {"_type": "tag", "name": "b", "path": "test.c", "pattern": "/^int fun(int a, int b)$/", "file": true, "language": "C", "line": 4, "typeref": "typename:int", "kind": "parameter", "roles": "def", "scope": "fun", "extras": "fileScope", "scopeKind": "function"}
    16. {"_type": "tag", "name": "c", "path": "main.c", "pattern": "/^int c = 3;$/", "language": "C", "line": 7, "typeref": "typename:int", "kind": "variable", "roles": "def"}
    17. {"_type": "tag", "name": "d", "path": "main.c", "pattern": "/^\tint d = a+b+c;$/", "file": true, "language": "C", "line": 12, "typeref": "typename:int", "kind": "local", "roles": "def", "scope": "main", "extras": "fileScope", "scopeKind": "function"}
    18. {"_type": "tag", "name": "d", "path": "test.c", "pattern": "/^\tint d = 1;$/", "file": true, "language": "C", "line": 6, "typeref": "typename:int", "kind": "local", "roles": "def", "scope": "fun", "extras": "fileScope", "scopeKind": "function"}
    19. {"_type": "tag", "name": "fun", "path": "test.c", "pattern": "/^int fun(int a, int b)$/", "language": "C", "line": 4, "signature": "(int a,int b)", "typeref": "typename:int", "kind": "function", "roles": "def", "end": 10}
    20. {"_type": "tag", "name": "fun", "path": "test.h", "pattern": "/^int fun(int a, int b);$/", "language": "C++", "line": 6, "signature": "(int a,int b)", "typeref": "typename:int", "kind": "prototype", "roles": "def"}
    21. {"_type": "tag", "name": "main", "path": "main.c", "pattern": "/^int main(int argc, char *argv[]) {$/", "language": "C", "line": 8, "signature": "(int argc,char * argv[])", "typeref": "typename:int", "kind": "function", "roles": "def", "end": 18}
    22. {"_type": "tag", "name": "main.c", "path": "main.c", "pattern": false, "language": "C", "line": 1, "kind": "file", "roles": "def", "extras": "inputFile", "end": 18}
    23. {"_type": "tag", "name": "stdio.h", "path": "main.c", "pattern": "/^#include /", "language": "C", "line": 1, "kind": "header", "roles": "system", "extras": "reference"}
    24. {"_type": "tag", "name": "stdlib.h", "path": "main.c", "pattern": "/^#include /", "language": "C", "line": 2, "kind": "header", "roles": "system", "extras": "reference"}
    25. {"_type": "tag", "name": "test.c", "path": "test.c", "pattern": false, "language": "C", "line": 1, "kind": "file", "roles": "def", "extras": "inputFile", "end": 10}
    26. {"_type": "tag", "name": "test.h", "path": "test.h", "pattern": false, "language": "C++", "line": 1, "kind": "file", "roles": "def", "extras": "inputFile", "end": 8}
    27. {"_type": "tag", "name": "var", "path": "test.c", "pattern": "/^int var = 5;$/", "language": "C", "line": 1, "typeref": "typename:int", "kind": "variable", "roles": "def"}
    28. {"_type": "tag", "name": "var", "path": "test.h", "pattern": "/^extern int var;$/", "language": "C++", "line": 4, "typeref": "typename:int", "kind": "externvar", "roles": "def"}

    我们可以看出,ctags生成不了标识符的被引用信息,比如某个符号在哪些地方都被用到了。它只能生成某个头文件在哪个源文件哪个位置引用到了。

  • 相关阅读:
    阿里8年经验之谈 —— 分享一次接口性能摸底测试过程!
    XSS-labs靶场实战(六)——第15关及Angular JS利用
    详细解析张雪峰老师对计算机专业的评价“进可攻,退可守”--【职场篇】
    基于Java+SpringBoot+Vue前后端分离在线互动学习网站设计和实现
    JUC并发编程与源码分析笔记06-Java内存模型之JMM
    谷歌研究员走火入魔事件曝光:认为AI已具备人格,被罚带薪休假,聊天记录让网友San值狂掉...
    距离度量 —— 汉明距离(Hamming Distance)
    C#里TcpListener的阻塞式服务器
    【服务器数据恢复】raid5崩溃导致lvm信息和VXFS文件系统损坏的数据恢复案例
    写给开发人员的实用密码学(六)—— 对称密钥加密算法
  • 原文地址:https://blog.csdn.net/kangkanglhb88008/article/details/126986535