Giter VIP home page Giter VIP logo

dspinellis / cscout Goto Github PK

View Code? Open in Web Editor NEW
190.0 14.0 35.0 4.07 MB

C code refactoring browser

Home Page: http://www.spinellis.gr/cscout

License: GNU General Public License v3.0

Makefile 0.56% C 66.38% CSS 0.32% Shell 0.95% C# 0.13% Yacc 3.86% Batchfile 0.02% C++ 25.63% Perl 1.30% Haxe 0.01% HTML 0.38% Smalltalk 0.01% Roff 0.40% sed 0.01% Awk 0.06%
c refactoring static-analysis call-graph c-preprocessor

cscout's Introduction

Build and Test Coverity Scan Build Status

CScout is a source code analyzer and refactoring browser for collections of C programs. It can process workspaces of multiple projects (a project is defined as a collection of C source files that are linked together) mapping the complexity introduced by the C preprocessor back into the original C source code files. CScout takes advantage of modern hardware (fast processors and large memory capacities) to analyze C source code beyond the level of detail and accuracy provided by current compilers and linkers. The analysis CScout performs takes into account the identifier scopes introduced by the C preprocessor and the C language proper scopes and namespaces. CScout has already been applied on projects of tens of thousands of lines to millions of lines, like the Linux, OpenSolaris, and FreeBSD kernels, and the Apache web server.

For more details, examples, and documentation visit the project's web site.

Building, Testing, Installing, Using

CScout has been compiled and tested on GNU/Linux (Debian jessie), Apple OS X (El Capitan), FreeBSD (11.0), and Cygwin. In order to build and use CScout you need a Unix (like) system with a modern C++ compiler, GNU make, and Perl. To test CScout you also need to be able to have SQLite installed. To view CScout's diagrams you must have the GraphViz dot command in your executable file path.

  • To build run make. You can also use the -j make option to increase the build's speed.
  • To build and test, run make test.
  • To install (typically after building and testing), run sudo make install.
  • To see CScout in action run make example.

Under FreeBSD use gmake rather than make.

Testing requires an installed version of SQLite.

Contributing

  • You can contribute to any of the open issues or you can open a new one describing what you want to do.
  • For small-scale improvements and fixes simply submit a GitHub pull request. Each pull request should cover only a single feature or bug fix. The changed code should follow the code style of the rest of the program. If you're contributing a feature don't forget to update the documentation. If you're submitting a bug fix, open a corresponding GitHub issue, and refer to the issue in your commit. Avoid gratuitous code changes. Ensure that the tests continue to pass after your change. If you're fixing a bug or adding a feature related to the language, add a corresponding test case.
  • Before embarking on a large-scale contribution, please open a GitHub issue.

cscout's People

Contributors

andreasgoulas avatar antonisgkortzis avatar dspinellis avatar ericcurtin avatar iridakos avatar lokesh-007 avatar papachristoumarios avatar ralphcorderoy avatar stefanoschaliasos avatar theosotr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cscout's Issues

Different result between (cscout/icc) and (gcc/clang) after preprocessing.

Hello.

I'm not really understand in what order this should expand, and why not otherwise, but: 'we have what we have'.

// The definition's and TokenSequence:

#define A(x) C(B, D
#define D A(1))
#define C(x,y) E(y)
#define E(y) #y
A(2))

Clang, gcc, tcc preprocess this text equally: "\"D\""

But cscout has another result: "A(1)")
(Intel compiler has similar result.)

Anyway, perhaps, this is an excellent example for the next test suite.

With respect and best regards.

can't build in parallel make

The file src/Makefile is missing some explicit dependencies, which causes parallel builds (using make -j N) to fail.
For example the generation of funmetrics.o or workdb.o depends onfunmetrics.h, which in turn depends on the generated file ytab.h.

I would suggest to include all dependencies (e.g., generated by gcc -MM) in the Makefile, or (if using GNU make is expected), use the technique described in https://www.gnu.org/software/make/manual/html_node/Automatic-Prerequisites.html.

Portability improvement (autotools, pkg-config, cmake, …)

Hi,

Would you consider using a Makefile generator or anything making the build process more portable ? As for #18 it helps a lot in the packaging process for any distribution.

In addition of the CC variables, you also have some INSTALL_PREFIX and dependencies variables hardcoded.

Build warnings and test failure with clang/clang++ 10

Hi there,
I am trying to build and test cscout and I have no idea if I am doing it correctly.
I just set $CC = /usr/bin/clang and $CXX = /usr/bin/clang++ (version 10) Ubuntu 20.04 LTS
And used my normal make line to output stdout to a file.
eg:
1st logfile: make -j6 -i 2>&1 | tee -a clang-cscout-build-op-20200811.log
2nd logfile: make test -j6 -i 2>&1 | tee -a clang-cscout-build-optests-20200811.log

Here are the logfiles:
clang-cscout-build-op.zip

I installed cscout to home/user/mystuff/programs but get this error when I try to use csmake on my project.

../../programs/bin/csmake -j6 2>&1 | tee -a clang-build-op-20200801.log
Unable to open /tmp/spy-make.33214//usr/bin/clang for writing: No such file or directory

Thanks for any advice on correctly build cscout,
Regards,
David.

Cross compiler support

Upon running csmake, I get this error:

Unable to open /tmp/spy-make.3076/rules for reading: No such file or directory
Make sure you have run `make clean' or an equivalent command.

Upon digging into the source:

http://github.com/dspinellis/cscout/blob/c758472/src/csmake.pl#L67-L70

it appears that GCC, LD and AR are hard coded. This would mean that cross
compilers such as x86_64-w64-mingw32-gcc are not supported. Please advise if
this is the case, or if a setting is available to change the compiler.

-c and -r do not work together

According to this documentation:

https://www.spinellis.gr/cscout/doc/run.html
Section: Checking invocation

I should be able to run the command:

cscout -rc marklar.cs

but all I get is Usage message.

The option processing logic in cscout.cpp clearly forbids this combination.
The cases 'c' and 'r': ... require the variable 'process_mode' to be 0 (pm_unspecified).

Since process_mode is an enum, you must pick one and only one.
There does not seem to be a way to specify a set of process modes.
If process_mode were some set type, like a bitmap, then more than one
can be specified. That would make the logic for validating combinations
a bit more complicated.

If it is really true that -c and -r are incompatible, then I guess the documentation
needs to be changed, instead. But it seems to me that -c has implications that
are completely orthogonal to other options, and so needs to be kept track of
separately, not as part of an enum.

-- Guy Shaw

Syntax error when including complex.h

When trying to process

#include <complex.h>

int main() {
}

I get a syntax error for cmathcalls.h. I use glibc version 2.19 and gcc 4.9.2.

Best regards

Georg Geiser

A lot of compilation rules are missing when csmake linux kernel 2.6.34

I have compiled linux kernel 2.6.34 with gcc 4.8 successfully.

I want to generate make.cs as input of cscout, so I run csmake to capture the compilation rules for each .c file.

However, I find a lot of Warning when running csmake, as following:
Warning: No compilation rule for /home/plus/linux/linux-2.6.34/lib/show_mem.o

These warnings indicate csmake fails to capture compilation rule for these compilation units, and when I use make.cs to run cscout, these files are not analyzed.

Is there any solution to deal with this problem?

Support #pragma once

The #pragma once non-standard extension is supported by most C compilers. Without it, programs that use it may enter an infinite include recursion.

Syntax Error

When running the awk example provided, I am getting an error when running cscout make.cs. The error is:

/usr/include/x86_64-linux-gnu/bits/mathcalls-helper-functions.h:21 error: syntax error.

make-version.sh compilation infinite loop

Hi,
I cloned the repo and ran the make command. During the compilation, it entered into an inifinite loop:
.... sh make-version.sh >version.cpp : not foundn.sh: 4: echo Expect 3 shift/reduce conflicts, 64 reduce/reduce conflicts Expect 3 shift/reduce conflicts, 64 reduce/reduce conflicts ../btyacc/btyacc -d -b eval -p eval_ eval.y mv -f eval.tab.c eval.cpp sh make-version.sh >version.cpp : not foundn.sh: 4: sh make-version.sh >version.cpp : not foundn.sh: 4: sh make-version.sh >version.cpp : not foundn.sh: 4: sh make-version.sh >version.cpp : not foundn.sh: 4: sh make-version.sh >version.cpp : not foundn.sh: 4: sh make-version.sh >version.cpp : not foundn.sh: 4: sh make-version.sh >version.cpp : not foundn.sh: 4: sh make-version.sh >version.cpp : not foundn.sh: 4: sh make-version.sh >version.cpp : not foundn.sh: 4: ...

Trying to run 'make clean' afterwards also hits the infinite loop:
ilyar@irozents-mobl:/mnt/c/Users/irozents/Downloads/cscout$ make clean cd src && make clean make[1]: Entering directory '/mnt/c/Users/irozents/Downloads/cscout/src' sh make-version.sh >version.cpp : not foundn.sh: 4: sh make-version.sh >version.cpp : not foundn.sh: 4: sh make-version.sh >version.cpp : not foundn.sh: 4: sh make-version.sh >version.cpp : not foundn.sh: 4:

obtaining info in plain text rather than through a browser

(Great soft!)
2 questions:
My interest is in processing potentially large C projects and obtain the static call graph of each in plain text.

  1. I've understood how to do that through the browser but it'd be much easier for me to redirect the output of cscout to some plain text file in order to automatically process many projects. How can I do that ?
  2. Is there a way to get rid of calls to functions and macros that belong to include'd files?
    Thanks!
    Philippe

Makefile can't download hsqldb

--2018-09-20 00:54:43--  http://hsqldb.org/download/hsqldb-2.3.3.zip
Resolving hsqldb.org (hsqldb.org)... 208.95.105.31
Connecting to hsqldb.org (hsqldb.org)|208.95.105.31|:80... connected.
HTTP request sent, awaiting response... remote: Counting objects: 186, done.
404 Not Found
2018-09-20 00:54:44 ERROR 404: Not Found.

I gave up immediately afterwards ;)

win10:cygwin, can not create version.cpp

sed: version.cpp:No such file or directory
fatal: Not a git repository (or any of the parent directories): .git
Makefile:287: dep/md5.d: No such file or directory
Makefile:287: dep/attr.d: No such file or directory
Makefile:287: dep/call.d: No such file or directory
Makefile:287: dep/cscout.d: No such file or directory
Makefile:287: dep/ctag.d: No such file or directory
Makefile:287: dep/ctconst.d: No such file or directory
Makefile:287: dep/ctoken.d: No such file or directory
Makefile:287: dep/debug.d: No such file or directory
Makefile:287: dep/dirbrowse.d: No such file or directory
Makefile:287: dep/eclass.d: No such file or directory
Makefile:287: dep/error.d: No such file or directory
Makefile:287: dep/fcall.d: No such file or directory
Makefile:287: dep/fchar.d: No such file or directory
Makefile:287: dep/fdep.d: No such file or directory
Makefile:287: dep/fileid.d: No such file or directory
Makefile:287: dep/filemetrics.d: No such file or directory
Makefile:287: dep/filequery.d: No such file or directory
Makefile:287: dep/fileutils.d: No such file or directory
Makefile:287: dep/funmetrics.d: No such file or directory
Makefile:287: dep/funquery.d: No such file or directory
Makefile:287: dep/gdisplay.d: No such file or directory
Makefile:287: dep/globobj.d: No such file or directory
Makefile:287: dep/html.d: No such file or directory
Makefile:287: dep/idquery.d: No such file or directory
Makefile:287: dep/logo.d: No such file or directory
Makefile:287: dep/macro.d: No such file or directory
Makefile:287: dep/mcall.d: No such file or directory
Makefile:287: dep/metrics.d: No such file or directory
Makefile:287: dep/obfuscate.d: No such file or directory
Makefile:287: dep/option.d: No such file or directory
Makefile:287: dep/os.d: No such file or directory
Makefile:287: dep/pager.d: No such file or directory
Makefile:287: dep/pdtoken.d: No such file or directory
Makefile:287: dep/pltoken.d: No such file or directory
Makefile:287: dep/ptoken.d: No such file or directory
Makefile:287: dep/query.d: No such file or directory
Makefile:287: dep/simple_cpp.d: No such file or directory
Makefile:287: dep/sql.d: No such file or directory
Makefile:287: dep/stab.d: No such file or directory
Makefile:287: dep/tchar.d: No such file or directory
Makefile:287: dep/timer.d: No such file or directory
Makefile:287: dep/token.d: No such file or directory
Makefile:287: dep/tokid.d: No such file or directory
Makefile:287: dep/tokmap.d: No such file or directory
Makefile:287: dep/type.d: No such file or directory
Makefile:287: dep/workdb.d: No such file or directory
Makefile:287: dep/css.d: No such file or directory
Makefile:287: dep/eval.d: No such file or directory
Makefile:287: dep/logo.d: No such file or directory
Makefile:287: dep/parse.d: No such file or directory
Makefile:287: dep/tokname.d: No such file or directory
Makefile:287: dep/version.d: No such file or directory
make: *** No rule to make target 'dep/version.d'。

Remove hardcoded CC/CXX

Hi,

You have some CC = cc and CXX = c++ in your Makefiles. If there are no specific reason to keep them, could we simply remove these lines ? It would help packaging it if it respects system’s compiler.

Error shot when compiling html.cpp on cygwin

$ make -j
cd swill && /usr/bin/make
cd btyacc && /usr/bin/make
make[1]: Entering directory '/d/Eda/cygwin/cygwin64/home/kelle/cscout/swill'
cd Source/Objects; /usr/bin/make
make[1]: Entering directory '/d/Eda/cygwin/cygwin64/home/kelle/cscout/btyacc'
make[1]: Nothing to be done for 'all'.
make[1]: Leaving directory '/d/Eda/cygwin/cygwin64/home/kelle/cscout/btyacc'
make[2]: Entering directory '/d/Eda/cygwin/cygwin64/home/kelle/cscout/swill/Source/Objects'
make[2]: Nothing to be done for 'all'.
make[2]: Leaving directory '/d/Eda/cygwin/cygwin64/home/kelle/cscout/swill/Source/Objects'
cd Source/SWILL; /usr/bin/make static
make[2]: Entering directory '/d/Eda/cygwin/cygwin64/home/kelle/cscout/swill/Source/SWILL'
make[2]: Nothing to be done for 'static'.
make[2]: Leaving directory '/d/Eda/cygwin/cygwin64/home/kelle/cscout/swill/Source/SWILL'
make[1]: Leaving directory '/d/Eda/cygwin/cygwin64/home/kelle/cscout/swill'
cd src && /usr/bin/make
make[1]: Entering directory '/d/Eda/cygwin/cygwin64/home/kelle/cscout/src'
/usr/bin/make depend
make[2]: Entering directory '/d/Eda/cygwin/cygwin64/home/kelle/cscout/src'
make[2]: Nothing to be done for 'depend'.
make[2]: Leaving directory '/d/Eda/cygwin/cygwin64/home/kelle/cscout/src'
/usr/bin/make build/cscout
make[2]: Entering directory '/d/Eda/cygwin/cygwin64/home/kelle/cscout/src'
g++ -c -std=gnu++11 -O3 -pipe -Wall -I. -DINSTALL_PREFIX='"/usr/local"' -DPRODUCTION -o build/html.o html.cpp
html.cpp: In function ‘void html_head(FILE*, std::string, std::string, const char*)’:
html.cpp:170:17: error: expected primary-expression before ‘,’ token
170 | , of);
| ^
make[2]: *** [Makefile:152: build/html.o] Error 1
make[2]: Leaving directory '/d/Eda/cygwin/cygwin64/home/kelle/cscout/src'
make[1]: *** [Makefile:174: all] Error 2
make[1]: Leaving directory '/d/Eda/cygwin/cygwin64/home/kelle/cscout/src'
make: *** [Makefile:31: src/build/cscout] Error 2

Race condition in csmake rule generation

When running csmake against my codebase, the output to the rules file from all the concurrent spy processes isn't synchronised, resulting in "BEGIN COMPILE...END COMPILE" blocks appearing in the middle of others, often breaking a random #define line in half.

Ideally each spy invocation should write to an independent temp file, and all the files concatenated at the end of the run.

Error message interpretation

Hi,

I am refactoring old C code and came across cscout which probably is a big help. I created a specification using the documentation on your website for cscout:

workspace xwpe-git {
ro_prefix "/usr/include"
define LIBRARY_DIR 1
project xwpe {
cd "src"
ipath ".."
file we_block.c we_edit.c we_fl_unix.c WeLinux.c we_mouse.c
file we_progn.c we_term.c we_xterm.c we_debug.c WeExpArr.c we_gpm.c
file we_main.c we_opt.c WeString.c we_unix.c WeXterm.c we_e_aus.c
file we_fl_fkt.c we_hfkt.c we_menue.c we_prog.c WeSyntax.c we_wind.c
}
}

executed cswc xwpe.cscout > xwpe.cs and cscout xwpe.cs. The output points to an error I do not understand, I print the last few lines.

/home/data/gbonnema/projects/c/xwpe-guus/src/we_fl_fkt.c:1498: warning: assuming declaration int __builtin_strncpy(...)
Done processing file we_fl_fkt.c
Processing file we_hfkt.c
/usr/local/include/cscout/host-defs.h:289: warning: Duplicate (different) macro definition of macro __has_include_next
/usr/include/regex.h:568: error: syntax error

It seems like there is an error in a library header? Or do I misunderstand the message completely. I checked the regex.h file and do not see the error it refers to. Could you point me in the right direction?

Kind regards, Guus Bonnema.

Last line of #included file gets concatenated with next line

My codebase has multiple auto-generated headers that don't start or end with newlines. When they're included consecutively the first line of the second header ends up joined to the end of the last line of the first header. This resulted in something like the following:

#define MACRO (some + expression)#define SECONDMACRO

which of course cscout's parser choked on when MACRO was finally invoked in an expression.

CPP always keeps the lines separate in this case, and the project builds successfully.

Convert documentation into markdown format

This will make it easier to generate the final formatted version. It seems the conversion process can be automated using Pandoc.
Issues:

  • Literal HTML blocks
  • Syntax highlighting
  • Page navigation
  • Images

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.