mopsa-db
The tool mopsa-db
allows you to inspect the contents of a database file created by mopsa-build.
It can print the list of executables in the database and the compilation options used to build each source file.
Usage
Without any option, mopsa-db
lists the executable files that were generated as part of the build process. Any such executable can serve as Mopsa target, using the -make-target
option, as Mopsa can extract the source files required for the analysis. The option must be specified if there are more than one executables. The full path can be shortened to the file name only.
There are a few alternate uses depending on the command-line options used:
- target
Where
target
is a generated executable program, lists the source files that will be used in the analysis of the program, together with the options passed to the front end (-I
,-D
, etc.). In case the executable is built by linking (static or dynamic) libraries that were compiled as part of the build process, the list expands recursively the library sources as well.mopsa-build
tries hard to collect all the sources available for each target, so as to avoid undefined symbols.
- -v
Print the whole contents of the database, including compiled C files, libraries and executable built, with their compilation and linking options. For libraries and executables, it lists the object and library files they contain (but it does not expand their contents recursively).
- target -json
Print the same information as
mopsa-db target
, in JSON format.
- -json
Print the same information as
mopsa-db -v
, in JSON format.
The behavior of mopsa-bd
is also controlled by environment variables:
MOPSADB
Location of the database (
mopsa.db
in the current directory if not specified).
Example
For instance, here is the output of mopsa-db
when run on the previous example database of GNU time
:
$ mopsa-db
DB file is mopsa.db
List of executables:
/tmp/time-1.9/time
$ mopsa-db time
DB file is mopsa.db
Executable time
/tmp/time-1.9/lib/basename-lgpl.c C, in /tmp/time-1.9, -D HAVE_CONFIG_H -I /tmp/time-1.9 -I /tmp/time-1.9/lib -I /tmp/time-1.9/src -MT -MD -MF
/tmp/time-1.9/lib/dirname-lgpl.c C, in /tmp/time-1.9, -D HAVE_CONFIG_H -I /tmp/time-1.9 -I /tmp/time-1.9/lib -I /tmp/time-1.9/src -MT -MD -MF
...
/tmp/time-1.9/src/time.c C, in /tmp/time-1.9, -D HAVE_CONFIG_H -I /tmp/time-1.9 -I /tmp/time-1.9/lib -I /tmp/time-1.9/src -Wall -Wextra -Wformat-security -Wswitch-enum -Wswitch-default -Wformat-nonliteral -Wunused-parameter -Wfloat-equal -fdiagnostics-show-option -funit-at-a-time -Wmissing-format-attribute -Wstrict-overflow -MT -MD -MF
JSON format
Using the -json
option is particularly useful for front ends.
The output is a record with:
dbfile
: a string field recalling the path of the database filecontents
: an array of elements. Each element corresponds to a file generated by the build system (object file, library, executable) and is a record with the following fields:filename
: the path to the generated filetype
: can beobject
,executable
,library
, orunknown
For object files, the following fields are used:
lang
: the source language (onlyC
files are currently supported in the analysis)source
: the source fileargs
: the command-line arguments used during compilationpath
: the current directory at the time of compilation
For executables and libraries:
contents
: a string array listing the files that were used to link this element. These files may correspond to elements that are available in the database (they have an entry with matchingfilename
), or external files the database does not know about (such as pre-installed libraries).kind
: for libraries only, indicates whether the library isstatic
ordynamic
When specifying a target to mopsa-db
, all the libraries known in the database are recursively expanded, leaving only a list of source entries as well as library entries with no known sources.