Skip to content

Commit a38d511

Browse files
committed
Adding initial version of goto-inspect.
This allows to inspect a goto-binary (this means showing the goto-functions, for now at least). The reason this binary is helpful is that different tools (CBMC, goto-instrument, etc) perform instrumentation before showing the goto-functions, and there's a need to be able to inspect certain properties of a goto-binary without doing instrumentation.
1 parent 68af7a4 commit a38d511

File tree

6 files changed

+152
-0
lines changed

6 files changed

+152
-0
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@ cprover_default_properties(
230230
goto-checker
231231
goto-diff
232232
goto-diff-lib
233+
goto-inspect
233234
goto-harness
234235
goto-instrument
235236
goto-instrument-lib

src/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ add_subdirectory(xmllang)
9898
add_subdirectory(goto-checker)
9999
add_subdirectory(goto-programs)
100100
add_subdirectory(goto-symex)
101+
add_subdirectory(goto-inspect)
101102
add_subdirectory(jsil)
102103
add_subdirectory(json)
103104
add_subdirectory(json-symtab-language)

src/goto-inspect/CMakeLists.txt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
file(GLOB_RECURSE sources "*.cpp" "*.h")
2+
add_executable(goto-inspect ${sources})
3+
generic_includes(goto-inspect)
4+
5+
target_link_libraries(goto-inspect
6+
util
7+
goto-programs
8+
)
9+
install(TARGETS goto-inspect DESTINATION ${CMAKE_INSTALL_BINDIR})
10+
11+
# # Man page
12+
# if(NOT WIN32)
13+
# install(
14+
# DIRECTORY ${CMAKE_SOURCE_DIR}/doc/man/
15+
# DESTINATION ${CMAKE_INSTALL_MANDIR}/man1
16+
# FILES_MATCHING PATTERN "goto-harness*")
17+
# endif()
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// Author: Fotis Koutoulakis for Diffblue Ltd.
2+
3+
#include "goto_inspect_parse_options.h"
4+
5+
int main(int argc, const char *argv[])
6+
{
7+
return goto_inspect_parse_optionst{argc, argv}.main();
8+
}
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
// Author: Fotis Koutoulakis for Diffblue Ltd.
2+
3+
#include "goto_inspect_parse_options.h"
4+
5+
#include <util/config.h>
6+
#include <util/exception_utils.h>
7+
#include <util/exit_codes.h>
8+
#include <util/invariant.h>
9+
#include <util/make_unique.h>
10+
#include <util/version.h>
11+
12+
#include <goto-programs/goto_model.h>
13+
#include <goto-programs/read_goto_binary.h>
14+
#include <goto-programs/show_goto_functions.h>
15+
16+
#include <iostream>
17+
18+
int goto_inspect_parse_optionst::doit()
19+
{
20+
if(cmdline.isset("version"))
21+
{
22+
std::cout << CBMC_VERSION << '\n';
23+
return CPROVER_EXIT_SUCCESS;
24+
}
25+
26+
// Before we do anything else, positional arguments needs to be > 1.
27+
// (i.e. a filename has been given).
28+
if(cmdline.args.size() < 1)
29+
{
30+
help();
31+
throw invalid_command_line_argument_exceptiont{
32+
"failed to supply a goto-binary name",
33+
"<input goto-binary> <inspection-option>"};
34+
}
35+
36+
// This just sets up the defaults (and would interpret options such as --32).
37+
config.set(cmdline);
38+
39+
// Normally we would register language front-ends here but as goto-harness
40+
// only works on goto binaries, we don't need to
41+
42+
auto binary_filename = cmdline.args[0];
43+
44+
// Read goto binary into goto-model
45+
auto read_goto_binary_result =
46+
read_goto_binary(binary_filename, ui_message_handler);
47+
if(!read_goto_binary_result.has_value())
48+
{
49+
throw deserialization_exceptiont{
50+
"failed to read goto program from file '" + binary_filename + "'"};
51+
}
52+
auto goto_model = std::move(read_goto_binary_result.value());
53+
54+
// This has to be called after the defaults are set up (as per the
55+
// config.set(cmdline) above) otherwise, e.g. the architecture specification
56+
// will be unknown.
57+
config.set_from_symbol_table(goto_model.symbol_table);
58+
59+
if(
60+
cmdline.isset("show-goto-functions") ||
61+
cmdline.isset("list-goto-functions"))
62+
{
63+
show_goto_functions(
64+
goto_model, ui_message_handler, cmdline.isset("list-goto-functions"));
65+
return CPROVER_EXIT_SUCCESS;
66+
}
67+
68+
// No options was passed in - erroneously?
69+
return CPROVER_EXIT_INCORRECT_TASK;
70+
}
71+
72+
void goto_inspect_parse_optionst::help()
73+
{
74+
std::cout << '\n'
75+
<< banner_string("Goto-Inspect", CBMC_VERSION) << '\n'
76+
<< align_center_with_border("Copyright (C) 2023") << '\n'
77+
<< align_center_with_border("Diffblue Ltd.") << '\n'
78+
<< align_center_with_border("[email protected]") << '\n'
79+
<< '\n'
80+
<< "Usage: Purpose:\n"
81+
<< '\n'
82+
<< " goto-inspect [-?] [-h] [--help] show help\n"
83+
<< " goto-inspect --version show version\n"
84+
<< " goto-inspect --show-goto-functions show code for "
85+
"goto-functions present in goto-binary\n"
86+
<< "\n"
87+
<< "<in> goto binary to read from\n";
88+
}
89+
90+
goto_inspect_parse_optionst::goto_inspect_parse_optionst(
91+
int argc,
92+
const char *argv[])
93+
: parse_options_baset{
94+
GOTO_INSPECT_OPTIONS,
95+
argc,
96+
argv,
97+
std::string("GOTO-INSPECT ") + CBMC_VERSION}
98+
{
99+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Author: Fotis Koutoulakis for Diffblue Ltd.
2+
3+
#ifndef CPROVER_GOTO_INSPECT_PARSE_OPTIONS_H
4+
#define CPROVER_GOTO_INSPECT_PARSE_OPTIONS_H
5+
6+
#include <util/parse_options.h>
7+
8+
#include <string>
9+
10+
// clang-format off
11+
#define GOTO_INSPECT_OPTIONS \
12+
"(version)" \
13+
"(show-goto-functions)" \
14+
// end GOTO_INSPECT_OPTIONS
15+
16+
// clang-format on
17+
18+
struct goto_inspect_parse_optionst : public parse_options_baset
19+
{
20+
int doit() override;
21+
void help() override;
22+
23+
goto_inspect_parse_optionst(int argc, const char *argv[]);
24+
};
25+
26+
#endif // CPROVER_GOTO_INSPECT_PARSE_OPTIONS_H

0 commit comments

Comments
 (0)