36 comments

[ 3.7 ms ] story [ 92.7 ms ] thread
A great tool for understanding source code is Source Trail. Supports parsing of C/C++, Python and Java currently. I love tools that help understand a large code base.
I take it you've used Source Trail? Are there any operations you particularly like using it for? Are there any you wish it could do, but it wasn't able to?

I built https://twitter.com/PredragGruevski/status/13447256045208780... just for fun as an exploration of this space, and I'm wondering where the limits are :)

I have used it to graph large python projects and c++ projects. It is great for visualizing the classes and relationship of classes and functions along with references to all the program elements.

The hardest part for me has been setting up the list of files and folders to scan for the project and trying to eliminate errors. Fortunately you still get useful data depending on the errors.

More direct link:

https://sourceforge.net/projects/cscope/files/

I set the forward proxy automatically rewrite http://subdomain.sourceforge.net links into the above https:// format.

Hehe, I usually do the opposite, as the SourceForge project page usually contains very little information about the project in general and is usually harder to navigate than the home page.
I find all the information, if there is any, is inside the tarball. I use a text-only browser. Even with text-only, the Sourceforge pages are always a mess of cruft to wade through. I would not even attempt to use Surceforge with a popular browser.
Obsolete.
By no means.
What has it got that makes it better than clang-complete/you complete me?

I switched a few years ago, maybe i wasn't using all of cscope's strengths?

They are two different things; cscope is a source code browser while YouCompleteMe is for source code completion. The cscope features are listed on its home page.

The reason i like it is because it is implemented in the classic "Unix Tools" manner i.e. small, fast, self-contained, good feature set and easily integrated with many editors. Now of course you have lots more tools with similar functionalities but i find most to be too big and unwieldy with lots of dependencies and a pain to setup. If you have ever been forced to work on minimal systems with no Desktop GUIs, remote targets etc. you come to appreciate small powerful tools which you can carry with you everywhere.

>They are two different things; cscope is a source code browser while YouCompleteMe is for source code completion

Not in my experience. YCM does browsing in Vim better than cscope's the way i used both. It was an easy switch to make and not look back for me. YCM features seemed to me like a superset of cscope Vim integration. Maybe i was missing something? Jumping to and back to function callers, definitions, variables etc. Clang just seemed to work better. Possibly because it understands C parsing which cscope kinda does some heuristics and hopes for the best? Dunno.

But yeah because it parses properly you get tab completion that works too. That isn't a negative for mine. Don't have to use it, super convenient and fast sometimes when you do.

I run Vim in a terminal. Works most places with my vimrc etc that i would edit source code. Includes a mips router, arm phone etc.

I used cscope for years. Before that ctags. I consider them obsolete for my uses, but i may have been missing something. Still don't know what.

I don't think you are "missing" anything. It is just a way of working with minimal overhead/setup and yet full-featured tools.

For example, for my work environment i have standardized on GNU Screen + dvtm + vim (few plugins) + cscope + ctags; thats it. Depending upon available hardware and need, i may add more tools but the above is what i try to carry everywhere.

What would be the workflow when using such tools like this or Source Trail? I've used cscope once while I'm testing out vim as my main text editor a bit.

Nowadays I'm using the global search feature of vscode for code exploration. Combined with the available language server for each language, it seems to work well enough for me currently.

Cscope in vim to jump between caller and callee (examine relationship). See where symbols are used. Jump to global definition. Could not live without cscope!
Yes this is how I use it and I love it. I think some IDEs havee similar capability but for vim users cscope is an great way to understand large code bases by quickly jumping through callchains. There's a 'Using Cscope with Vim' tutorial on the page that covers it.
Vim now also supports the more powerful vscode language servers. If you haven't done so already, I encourage you to give them a try.
Vim Youcompleteme plugin with libclang support does this better for me. Have you compared?
What’s the diff of features compared to VSCode’s language server interface?
(comment deleted)
An Oldie but a Goldie.

Related "CodeQuery"(https://github.com/ruben2020/codequery) which uses both cscope and ctags databases (i use both for C/C++ code from within vim) and provides a GUI frontend.

Combine with "Doxygen" and "GNU cflow" (https://www.gnu.org/software/cflow/) and you get a very good view of the static structure of any codebase.

To get a Runtime view i prefer the call graph emitted by the profiler gprof.

Is it C only? Does it index assembly files (.S) as well?
Amazing that the last update was apparently 8 years ago. My workflow works better w ctags, but when ctags lack, cscope can usually fill the gap.
for purely c based codesbases i don’t think there is anything better that is freely available (would _love_ to hear about equivalent alternatives though. ctags etc don’t seem to have similar functionality afaik)

cacope has excellent emacs integration as well.

for c++, unfortunately, cscope was ok till about c++-98, but modern incarnation of the standard seem to have given rise to a slew of tools for code navigation.

most notable amongst them being around the notion of compilation databases and language servers etc. unfortunately though, for large codebases (>= 1 giga-lines) in my experience they don’t seem to offer anything better, and need to be used in conjunction with grep and their modern incarnations f.e ripgrep etc. making the entire workflow quite unwieldy...

I used Geany editor (well, it's a "lightweight IDE" GTK based, Scintilla powered) for its ctags integration.

Also helpful for exploration of unknown code. However, in general it navigates between files opened already (as it generates ctags on open). But allows loading an externally generated ctags file. Also does symbol usage lookup and auto-completion.

OMG I used this in the early 80s - first time I’ve seen it mentioned in 30 years!