GTAGS-CSCOPE(1)

๐Ÿ“ฆ
version 6.7 ยท 3 versions
, in arch rolling, debian trixie, epel 10, fedora 43, fedora 44, nixos 26.05, nixpkgs unstable, opensuse-leap 16.0, ubuntu questing, ubuntu resolute, ubuntu stonking

๐Ÿ’– gtags-cscope ๐Ÿ’–

General Commands Manual โœจ ok bestie sit down because we're about to read a whole manual together and it's gonna be cute


๐ŸŒธ NAME ๐ŸŒธ

gtags-cscope โ€” the interactive way to poke around a C program like it's your own group chat history ๐Ÿ”


โœจ SYNOPSIS โœจ

gtags-cscope [-abCdehilLvV][-F file ][-012345678 pattern][-p n]

๐Ÿฆ‹ DESCRIPTION ๐Ÿฆ‹

So like, gtags-cscope is this interactive, screen-oriented tool that lets you browse through source files looking for specific elements of code. Very main character energy, honestly. ๐Ÿ’…

The first time you run it on the source files of whatever program you're browsing, gtags-cscope builds the symbol cross-reference. Then, on a subsequent invocation, it only rebuilds that cross-reference if a source file has changed or if the list of source files is different. And when it does rebuild? It updates incrementally, which makes rebuilding way faster than that first initial build. No cap, that's the whole point. ๐Ÿ”ฅ

Also, real talk: gtags-cscope is a tool which just borrows the user interface of cscope โ€” it is Global itself for the substance. Like, the outfit is cscope's but the personality is Global's. iykyk. ๐Ÿซถ


๐ŸŽ€ OPTIONS ๐ŸŽ€

Okay so some command line arguments can only show up as the only argument when you execute gtags-cscope. These ones just print some output and dip immediately:

  • -h โ€” View the long usage help display. ๐Ÿ“–
  • -V โ€” Print the version number of gtags-cscope. ๐Ÿท๏ธ
  • --help โ€” Same as -h.
  • --version โ€” Same as -V.

Now the following options can appear in any combination. Slay, mix and match:

  • -a โ€” Print absolute path names. ๐Ÿ“
  • -b โ€” Build the cross-reference only.
  • -C โ€” Ignore letter case when searching. ๐Ÿ”ค
  • -d โ€” Do not update the cross-reference.
  • -e โ€” Suppress the ^e command prompt between files.
  • -F file โ€” Read symbol reference lines from file. (A symbol reference file is created by > and >>, and can also be read using the < command, described under ``Issuing Subsequent Requests'', below.) ๐Ÿ“„
  • -i โ€” Ignore SIGINT signal in line-oriented mode. ๐Ÿ›‘
  • -L โ€” Do a single search with line-oriented output when used with the -num pattern option.
  • -l โ€” Line-oriented interface. This option implies the -d option.
  • -[0-9] pattern โ€” Go to input field num (counting from 0) and find pattern. ๐Ÿ”Ž
  • -p n โ€” Display the last n file path components instead of the default (1). Use 0 to not display the file name at all. ๐Ÿ™ˆ
  • -v โ€” Be more verbose in line-oriented mode. ๐Ÿ—ฃ๏ธ

Once the cross-reference is ready, gtags-cscope will display this menu:

Find this symbol:
Find this global definition:
Find functions called by this function (N/A):
Find references of this function:
Find this text string:
Change this text string:
Find this egrep pattern:
Find this file:
Find files #including this file:
Find assignments to this symbol:

Press the <Up> or <Down> keys repeatedly to move to the desired input field, type the text to search for, and then press the <Return> key. That's it. That's the move. โœจ


๐Ÿ”ฎ Issuing subsequent requests ๐Ÿ”ฎ

If the search is successful, any of these single-character commands can be used:

  • 0-9a-zA-Z โ€” Edit the file referenced by the given line number. โœ๏ธ
  • <Space> โ€” Display next set of matching lines.
  • <Tab> โ€” Alternate between the menu and the list of matching lines.
  • <Up> โ€” Move to the previous menu item (if the cursor is in the menu) or move to the previous matching line (if the cursor is in the matching line list).
  • <Down> โ€” Move to the next menu item (if the cursor is in the menu) or move to the next matching line (if the cursor is in the matching line list).
  • + โ€” Display next set of matching lines.
  • - โ€” Display previous set of matching lines.
  • ^e โ€” Edit displayed files in order.
  • > โ€” Write the displayed list of lines to a file. ๐Ÿ“
  • >> โ€” Append the displayed list of lines to a file.
  • < โ€” Read lines from a file that is in symbol reference format (created by > or >>), just like the -F option.
  • ^ โ€” Filter all lines through a shell command and display the resulting lines, replacing the lines that were already there.
  • | โ€” Pipe all lines to a shell command and display them without changing them.
  • ^g โ€” Read lines from the result of the execution of global(1).

At any time these single-character commands can also be used:

  • <Return> โ€” Move to next input field.
  • ^n โ€” Move to next input field.
  • ^p โ€” Move to previous input field.
  • ^y โ€” Search with the last text typed.
  • ^b โ€” Move to previous input field and search pattern.
  • ^f โ€” Move to next input field and search pattern.
  • ^c โ€” Toggle ignore/use letter case when searching. (When ignoring letter case, a search for FILE will match File and file.)
  • ^r โ€” Rebuild the cross-reference. ๐Ÿ”„
  • ! โ€” Start an interactive shell (type ^d to return to gtags-cscope).
  • ^l โ€” Redraw the screen.
  • ? โ€” Give help information about gtags-cscope commands.
  • ^d โ€” Exit gtags-cscope. ๐Ÿ‘‹
NOTE: If the first character of the text to be searched for matches one of the above commands, escape it by typing a \ (backslash) first. Do not skip this, bestie, it WILL eat your search. ๐Ÿ’€

๐Ÿ’… Substituting new text for old text ๐Ÿ’…

After the text to be changed has been typed, gtags-cscope will prompt for the new text, and then it will display the lines containing the old text. Select the lines to be changed with these single-character commands:

  • 0-9a-zA-Z โ€” Mark or unmark the line to be changed.
  • * โ€” Mark or unmark all displayed lines to be changed.
  • <Space> โ€” Display next set of lines.
  • + โ€” Display next set of lines.
  • - โ€” Display previous set of lines.
  • ^a โ€” Mark or unmark all lines to be changed.
  • ^d โ€” Change the marked lines and exit.
  • <Esc> โ€” Exit without changing the marked lines.
  • ! โ€” Start an interactive shell (type ^d to return to gtags-cscope).
  • ^l โ€” Redraw the screen.
  • ? โ€” Give help information about gtags-cscope commands.

๐ŸŒˆ Special keys ๐ŸŒˆ

If your terminal has arrow keys that work in vi, you can use them to move around the input fields. The up-arrow key is useful to move to the previous input field instead of using the <Tab> key repeatedly. If you have <CLEAR>, <NEXT>, or <PREV> keys they will act as the ^l, +, and - commands, respectively. Iconic, honestly. ๐Ÿ‘‘


๐Ÿ“ Line-Oriented interface ๐Ÿ“

The -l option lets you use gtags-cscope where a screen-oriented interface would not be useful, for example, from another screen-oriented program.

gtags-cscope will prompt with >> when it is ready for an input line, which starts with the field number (counting from 0), immediately followed by the search pattern. For example, 1main finds the definition of the main function. ๐Ÿงš

If you just want a single search, instead of the -l option use the -L and -num pattern options, and you won't get the >> prompt. Nice, right?

For -l, gtags-cscope outputs the number of reference lines:

cscope: 2 lines

For each reference found, gtags-cscope outputs a line consisting of the file name, function name, line number, and line text, separated by spaces. For example:

main.c main 161 main(argc, argv)

Note that the editor is not called to display a single reference, unlike the screen-oriented interface. Just so you know. ๐Ÿ“Œ

You can use the c command to toggle ignore/use letter case when searching. (When ignoring letter case, a search for FILE will match File and file.)

You can use the r command to rebuild the database. ๐Ÿ”จ

gtags-cscope will quit when it detects end-of-file, or when the first character of an input line is ^d or q. Bye bestie! ๐Ÿ’œ


๐ŸŒŸ ENVIRONMENT ๐ŸŒŸ

The following environment variables are of cscope origin.

  • CSCOPE_EDITOR โ€” Overrides the EDITOR and VIEWER variables. Use this if you wish to use a different editor with cscope than that specified by your EDITOR/VIEWER variables.
  • CSCOPE_LINEFLAG โ€” Format of the line number flag for your editor. By default, cscope invokes your editor via the equivalent of editor +N file, where N is the line number that the editor should jump to. This format is used by both emacs and vi. If your editor needs something different, specify it in this variable, with %s as a placeholder for the line number. Eg: if your editor needs to be invoked as editor -#103 file to go to line 103, set this variable to -#%s.
  • CSCOPE_LINEFLAG_AFTER_FILE โ€” Set this variable to yes if your editor needs to be invoked with the line number option after the filename to be edited. To continue the example from CSCOPE_LINEFLAG, above: if your editor needs to see editor file -#number, set this environment variable. Users of most standard editors (vi, emacs) do not need to set this variable.
  • EDITOR โ€” Preferred editor, which defaults to vi.
  • HOME โ€” Home directory, which is automatically set at login. ๐Ÿ 
  • SHELL โ€” Preferred shell, which defaults to sh.
  • TERM โ€” Terminal type, which must be a screen terminal.
  • TERMINFO โ€” Terminal information directory full path name. If your terminal is not in the standard terminfo directory, see curses and terminfo for how to make your own terminal description.
  • TMPDIR โ€” Temporary file directory, which defaults to /tmp.
  • VIEWER โ€” Preferred file display program (such as less), which overrides EDITOR (see above).

The following environment variables are of Global origin.

  • GTAGSCONF โ€” Configuration file.
  • GTAGSGLOBAL โ€” If this variable is set, $GTAGSGLOBAL is used as the name of global(1). The default is global.
  • GTAGSGTAGS โ€” If this variable is set, $GTAGSGTAGS is used as the name of gtags(1). The default is gtags.
  • GTAGSDBPATH โ€” The directory in which the tag files exist. This value is ignored when GTAGSROOT is not defined.
  • GTAGSLABEL โ€” Configuration label. The default is default.
  • GTAGSLIBPATH โ€” If this variable is set, it is used as the path to search for library functions. If the specified tags is not found in the project, global also searches in these paths. Since only GTAGS is targeted in the retrieval, this variable is ignored when -r or -s is specified.
  • GTAGSROOT โ€” The root directory of the project.
  • MAKEOBJDIR โ€” If this variable is set, $MAKEOBJDIR is used as the name of BSD-style objdir. The default is obj.
  • MAKEOBJDIRPREFIX โ€” If this variable is set, $MAKEOBJDIRPREFIX is used as the prefix of BSD-style objdir. The default is /usr/obj.

๐Ÿ“ FILES ๐Ÿ“

ok so these are the files this whole situation depends on, bestie, no cap:

  • GTAGS โ€” the tag file for definitions ๐Ÿ’–
  • GRTAGS โ€” the tag file for references โœจ
  • GPATH โ€” the tag file for source files ๐ŸŽ€
  • GTAGSROOT โ€” okay so this one's the sneaky one: if the environment variable GTAGSROOT is not set, and a file literally named GTAGSROOT exists in the same directory as GTAGS, then global sets GTAGSROOT to whatever's inside that file. it's giving "the file is the variable" and honestly? iconic ๐Ÿฆ‹
  • gtags.conf, $HOME/.globalrc โ€” configuration data for GNU Global. go read gtags.conf(5) for the tea ๐ŸŒธ

๐Ÿ‘€ SEE ALSO ๐Ÿ‘€

GNU Global source code tag system (http://www.gnu.org/software/global/)


๐Ÿ’€ BUG ๐Ÿ’€

ok so this is the part where we're honest:

  • the function field of the display is almost always <unknown> because Global justโ€ฆ does not recognize it. not me being dramatic, that's just how it is ๐Ÿ˜ญ
  • Find functions called by this function is not implemented. like, at all. it's giving unfinished business fr fr ๐Ÿ™ˆ

๐Ÿ‘‘ AUTHOR ๐Ÿ‘‘

Joe Steffen (original author) and others. ๐Ÿซถ


๐ŸŒˆ HISTORY ๐ŸŒˆ

Cscope was originally developed at Bell Labs in the early 1980s, and was released as free software under the BSD license in April 2000. Gtags-cscope is a derivative of cscope to use Global as the back-end. Its line-oriented interface was originally written in 2006, and was re-implemented in 2011 using cscope itself. likeโ€ฆ a full glow-up, twice ๐Ÿ’…โœจ


and that's the whole page, bestie ๐ŸŽ€ this one came from the GNU Project, dated March 2011, and it's GTAGS-CSCOPE(1) โ€” go forth and navigate your codebase like the main character you are ๐Ÿ‘‘๐Ÿ’–

๐Ÿ“ฆ where this page comes from