ctagsexuberant-ctags

can't generate tag __mrs_s from "#define __mrs_s(v, r)" in a file.. even using --excmd=pattern


generating tags using ctags seems to be very tricky.
I wanted make tag file for https://elixir.bootlin.com/linux/v5.4.21/source/arch/arm64/include/asm/sysreg.h
you can get this sysreg.h file by

wget https://elixir.bootlin.com/linux/v5.4.21/source/arch/arm64/include/asm/sysreg.h

Please see Can't add reg expression for a #define in ctags. I tried the same method in this answer as below.

ctags --excmd=pattern sysreg.h 

I see tag for mrs_s or msr_s in the generated tags file. But I don't see the tag for __mrs_s or __msr_s that I originally wanted. What is wrong?


Solution

  • There is no simple way to satisfy the goal.

    sysreg.h contains assembly language code that makes the C++ indexer of ctags confused. See https://elixir.bootlin.com/linux/v5.4.21/source/arch/arm64/include/asm/sysreg.h#L741

    (It would be nice to add a feature to the C++ indexer to skip __ASSEMBLY__ and __ASSEMBLER__ area.)

    I found one hacky technique that works only with Universal ctags (https://ctags.io). Your ctags may be Exuberant Ctags. So the technique I will write here may not work with your ctags.

    $ ./ctags --version
    ./ctags --version
    Universal Ctags 5.9.0(692f5fd15), Copyright (C) 2015 Universal Ctags Team
    Universal Ctags is derived from Exuberant Ctags.
    Exuberant Ctags 5.8, Copyright (C) 1996-2009 Darren Hiebert
      Compiled: Feb  6 2022, 06:19:35
      URL: https://ctags.io/
      Optional compiled features: +wildcards, +regex, +gnulib_regex, +iconv, +debug, +option-directory, +xpath, +json, +interactive, +sandbox, +yaml, +packcc, +optscript, +pcre2
    $ ./ctags --options=NONE -Dendm='endm;' -o - /tmp/sysreg.h | grep __msr_s 
    ./ctags --options=NONE -Dendm='endm;' -o - /tmp/sysreg.h | grep __msr_s 
    ctags: Notice: No options will be read from files or environment
    __msr_s /tmp/sysreg.h   /^#define __msr_s(/;"   d
    

    The option -D... replaces the words endm in the __ASSEMBLY__ area with endm;. The appended semicolon characters mitigate the indexer's confusion.