oxref(1) | oxref - cross reference utility | oxref(1) |
oxref - cross reference utility for various languages
oxref [OPTIONS] arguments
[OPTIONS] - see the OPTIONS section below
arguments - object files and/or libraries to process
The cross reference listing is written to the standard output stram.
The program oxref generates cross reference listings of symbols defined in non-stripped object files and/or libraries as well as program or function call-trees.
Cross reference listings show the functions using certain symbols (functions, data). This is useful information during program development and debugging phases. E.g., assuming that the signature; the pre-conditions or the post-conditions of a function must be changed it is important to know from what function(s) the function-to-modify is called to verify that the changes to the modified function do not break its calling functions.
Oxref’s output starts with a header showing information about the program, a time stamp and the arguments passed to oxref. E.g.,
oxref by Frank B. Brokken (f.b.brokken@rug.nl) oxref V2.00.00 2012-2019 CREATED Mon, 11 Mar 2019 05:35:47 +0000 CROSS REFERENCE FOR: -t main -r replace -fxs tmp/main.o tmp/libmodules.a ----------------------------------------------------------------------
The header is followed by the cross reference information and the call tree. Both the cross reference information and the call tree can be omitted.
The cross reference listing shows the symbols, as well as (optionally) their full names (e.g., prefixed by class-names), source files and the source files and names of functions using the symbols. The cross reference listings of a global variable and a function looks like this:
author
Full name: Icmbuild::author
Source: version.cc
Used By:
header.cc: header(int, char**)
usage.cc: usage(std::string const&)
calledFrom(unsigned long)
Full name: XrefData::calledFrom(unsigned long)
Source: calledfrom.cc
Used By:
undefined.cc: Store::undefined(std::string const&)
The call tree shows the names of all entities used or called from a certain starting point. For C and C++ programs the starting point main produces the program’s full call tree. A (partially shown) call tree might look like this:
Calling levels are indented using +- indicators, continuation at identical levels are indicated by vertical lines, using | characters. In the shown call tree main calls usage, the Storage constructor and the Storage::tree() member. Likewise, the Storage constructor calls the Store constructor and the member Storage::patternFile. Recursively called functions appear in the overview where their names are followed by ==> nr arrows where nr refers to the call-level where the function is defined. The top level (e.g. main) is referred to as level 0. Here is an example showing recursion in the call-tree of the bisonc++ program:
CALL TREE FOR: main
main
+-usage(std::string const&)
| +-Icmbuild::version
+-Storage::Storage()
| +-Store::Store()
| +-Storage::patternFile(std::string const&)
+-Storage::tree() const
+-Store::tree(std::string const&) const
+-Tree::print(unsigned long, unsigned long)
+-Tree::calls(unsigned long, unsigned long)
| +-Tree::calls(unsigned long, XrefData const&)
+-Tree::indent(unsigned long) const
Indirect recursion is shown this way as well.
main
...
+-Grammar::deriveSentence()
| +-Rules::s_startSymbol
| +-Grammar::derivable(Symbol const*)
| +-Grammar::becomesDerivable(Production const*)
| | +-Grammar::derivable(Symbol const*) ==> 2
| +-Grammar::isDerivable(Production const*)
...
Caveat: in order to produce the program’s call tree the object file containing the program’s starting point (e.g., main) must be available to oxref. If main.o is the object file of the function main then main.o must explicitly be specified as oxref’s command-line argument (see, e.g., the command specification shown above in the header line of oxref’s output).
Oxref returns 0 to the operating system unless an error occurs or oxref’s version or usage info is shown or requested. In those cases 1 is returned
If available, single letter options are listed between parentheses following their associated long-option variants. Single letter options require arguments if their associated long options require arguments as well.
instead of
usage(1)
usage(std::string const&)
instead of
insertDefined(unsigned, std::ostream&, std::vector&)
insertDefined(unsigned int, std::ostream&,
std::vector<XrefData,
std::allocator<XrefData> > const&)
instead of
insertDefined(unsigned int, std::ostream&, std::vect...&)
insertDefined(unsigned int, std::ostream&,
std::vector<XrefData,
std::allocator<XrefData> > const&)
insertDefined(unsigned int, std::ostream&, std::vector<XrefData,
std::allocator<XrefData> > const&)
Full name: Store::insertDefined(unsigned int, std::ostream&,
std::vector<XrefData, std::allocator<XrefData> > const&)
R options are used to specify text replacements of the form
std::__cxx11::basic_string<char, std::char_traits<char>
const &
where # can be any character not used in either the find text or the replace text. For example:
#find#replace#
Multiple R options may be specified, which are applied in sequence line-by-line to all output lines of objdump. E.g, after replacing the above long definition of a string into std::string subsequent replacements should use std::string rather than the original long definition provided by the compiler.
#std::__cxx11::basic_string<char, std::char_traits<char>#std::string#
The examples show how oxref was called, followed by a representative example of a cross-reference listing for a symbol. Oxref’s own cross reference listing was used:
called as: oxref liboxref define(std::string const&, bool)
Used By:
Store::setFunction(std::string const&)
Store::setObject(std::string const&)
Store::setSource(std::string const&) -------------------- called as: oxref -foxs liboxref define(std::string const&, bool)
Full name: Store::define(std::string const&, bool)
Source: define.cc (1define.o)
Used By:
setfunction.cc: Store::setFunction(std::string const&)
setobject.cc: Store::setObject(std::string const&)
setsource.cc: Store::setSource(std::string const&)
No bugs reported
In theory, creating cross reference listings is a complex matter as it requires a full syntax analysis of the sources defining a program. Especially with complex languages like C++ this is a difficult hurdle to pass.
Looking for `cross reference programs’ using a search engine returns remarkably few hits. LXR is a promising cross referencing program (see http://lxr.linux.no/), but it requires the use of data base packages, making it somewhat complex to use. Other links refer to cross-reference programs for textual documents, not programs.
The complexity of developing a program generating a cross reference listing has baffled me for a long time. Eventually I realized that in practice the essential information has already been generated by the compiler, when it compiles our source files. So why do it all again?
Once a program has been compiled one or (usually) more object files are available. The linker uses tables of defined and external symbols embedded in the object files to connect the various functions. If all requirements can be satisfied the linker is able to create a running program.
Programs like nm(1) and objdump(1) can be used to produce human readable output from the information embedded in object files. Oxref reads this information and organizes it, creating a cross reference listing.
Since all compilable program languages generate identically organized object files (or maybe better: generate object files that can be interpreted by objdump(1)), oxref can broadly be applied. As long as objdump(1) produces sensible output oxref should be able to generate a cross reference listing.
Oxref’s name consists of two syllables: o and xref. The o represents the program objdump(1), called from oxref as a child program. The important part is of course the cross-referencing of symbols. Like the common abbreviation of rail-road crossing, rail-road xing, cross referencing is abbreviated to xref. Hence oxref.
Of course, nearly everybody will read oxref as ox-ref. Fortunately, here too we’re on familiar ground: Bison, Cow, Gnu, Yacc: all are bovine animals. To that important list oxref adds the Ox.
An example of oxref’s own cross reference listing is provided (on Debian systems) in the file
/usr/share/doc/oxref/oxref.xref.gz
Frank B. Brokken (f.b.brokken@rug.nl).
2012-2022 | oxref.2.00.03 |