Skip to content

Adding initial version of goto-inspect. #7673

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 23, 2023

Conversation

NlightNFotis
Copy link
Contributor

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.

  • Each commit message has a non-empty body, explaining why the change was made.
  • Methods or procedures I have added are documented, following the guidelines provided in CODING_STANDARD.md.
  • The feature or user visible behaviour I have added or modified has been documented in the User Guide in doc/cprover-manual/
  • Regression or unit tests are included, or existing tests cover the modified code (in this case I have detailed which ones those are in the commit message).
  • My commit message includes data points confirming performance improvements (if claimed).
  • My PR is restricted to a single feature or bugfix.
  • White-space or formatting changes outside the feature-related changed lines are in commits of their own.

@martin-cs
Copy link
Collaborator

How different is this to just using goto-instrument --show-goto-programs ?

@martin-cs
Copy link
Collaborator

Apologies, I hadn't seen #7674, will discuss there.

@codecov
Copy link

codecov bot commented Apr 19, 2023

Codecov Report

Patch coverage: 59.45% and project coverage change: +0.13 🎉

Comparison is base (68af7a4) 78.42% compared to head (13997e0) 78.55%.

❗ Current head 13997e0 differs from pull request most recent head 7724092. Consider uploading reports for the commit 7724092 to get more accurate results

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #7673      +/-   ##
===========================================
+ Coverage    78.42%   78.55%   +0.13%     
===========================================
  Files         1674     1689      +15     
  Lines       191935   192964    +1029     
===========================================
+ Hits        150521   151582    +1061     
+ Misses       41414    41382      -32     
Impacted Files Coverage Δ
src/goto-inspect/goto_inspect_parse_options.cpp 55.88% <55.88%> (ø)
src/goto-inspect/goto_inspect_main.cpp 100.00% <100.00%> (ø)
src/goto-inspect/goto_inspect_parse_options.h 100.00% <100.00%> (ø)

... and 94 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@tautschnig
Copy link
Collaborator

Please take a look at #7415, which is the most recent new tool that was added and is much more complete in what it takes to add a new tool.

@NlightNFotis
Copy link
Contributor Author

Hi Michael (@tautschnig), latest commit should have everything that has been asked.

Let me know if this is closer to what you envisioned.

@NlightNFotis NlightNFotis marked this pull request as ready for review May 2, 2023 09:47
Copy link
Contributor

@thomasspriggs thomasspriggs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks reasonable to me, aside from a few minor issues.

install(TARGETS goto-inspect DESTINATION ${CMAKE_INSTALL_BINDIR})

# # Man page
# if(NOT WIN32)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this commented out?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch - it shouldn't be commented out.

It was in the first commit, when we didn't have a man page at first, but now we do.

CMakeLists.txt Outdated
goto-harness
goto-inspect
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: duplication

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch.

// This just sets up the defaults (and would interpret options such as --32).
config.set(cmdline);

// Normally we would register language front-ends here but as goto-harness
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should "goto-harness" here be "goto-inspect"?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this was a copy-paste fail.

I used the code under src/goto-harness as the base for a lot of what you're seeing here, but it seems like I forgot to update some of the references.

Will have another look myself, just to make sure.

@NlightNFotis NlightNFotis force-pushed the goto-inspect branch 2 times, most recently from 306ea84 to 075630b Compare May 3, 2023 09:51
@@ -0,0 +1,33 @@
.TH GOTO-INSPECT "2" "May 2023" "goto-inspect-5.81.0" "User Commands"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably not worth pinning a date/version here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This reference leads me to believe that the date is necessary in the title line.

It does look like the date we have though doesn't align with the proposed format in the reference I linked. I'm not sure how the tools behave if I leave it with an empty date, but it seems to be diverging from the expected format too much IMO.

.BR goto-cc (1)
.BR goto-instrument (1)
.SH COPYRIGHT
2023, Fotis Koutoulakis
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copyright is Diffblue I believe.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right - I copied and hastily changed this from a previous one, so I've made a number of mistakes.

I'm fixing now.

Comment on lines 24 to 31
// Before we do anything else, positional arguments needs to be > 1.
// (i.e. a filename has been given).
if(cmdline.args.size() < 1)
{
help();
throw invalid_command_line_argument_exceptiont{
"failed to supply a goto-binary name",
"<input goto-binary> <inspection-option>"};
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like it should be > 2 and < 2 since we require a binary name and another option?

Maybe we also need a code path before this to response to the --help option.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like it should be > 2 and < 2 since we require a binary name and another option?

Yes, changed to > 2. With the current implementation, if just a binary is given, the behaviour is that the tool doesn't appear to do anything. It's reasonable in my opinion, but not very helpful, as it doesn't indicate to the user whether it succeeded or failed, or what.

Maybe we also need a code path before this to response to the --help option.

We don't need to do that, as it's handled already by the base class parse_options_baset::main(), where it's checking for h or help before calling doit().

Comment on lines 66 to 70
// No options was passed in - erroneously?
return CPROVER_EXIT_INCORRECT_TASK;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The failure for lack of an option should be caught/reported earlier as in comment above, so this code path should perhaps be unreachable?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be unreachable - I have added a lengthier comment addressing why the value is there, in order not to confuse people. Let me know if it now makes more sense.

@@ -63,7 +63,14 @@ int goto_inspect_parse_optionst::doit()
return CPROVER_EXIT_SUCCESS;
}

// No options was passed in - erroneously?
// If an option + binary was provided, the program will have exited gracefully
// through different a different branch. If we hit the code below, it means
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"different a different" -> "a different"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

@NlightNFotis NlightNFotis force-pushed the goto-inspect branch 2 times, most recently from 2aaaac2 to b79bfaa Compare May 18, 2023 10:02
@kroening
Copy link
Member

May I suggest that you consider the user interface. In particular, consider swapping the order of the command line arguments.

All command line tools that I can think of have the order "action" and then "file name". E.g., think git add some_file.cpp, or maybe tar tfz tarball.tgz.

@NlightNFotis
Copy link
Contributor Author

Hi @kroening, I'm working on adding tests (didn't want to commit to writing tests before there's conclusion that the approach is not objectionable to people) and during the authoring of tests I have discovered some issues with the interface that led me to rethink the approach.

Will update the PR as soon as my current change is stable and the interface is smoother.

@NlightNFotis NlightNFotis force-pushed the goto-inspect branch 2 times, most recently from ac8c34a to 13997e0 Compare May 19, 2023 14:59
@NlightNFotis
Copy link
Contributor Author

Hi @kroening, I've had some more time to play around with this, and it doesn't have any particular dependency on the order of arguments, i.e. both: goto-inspect --show-goto-functions example.goto and goto-inspect example.goto --show-goto-functions will work.

Copy link
Member

@peterschrammel peterschrammel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The individual commits are not very clean. I suggest to squash them as they all fix up earlier commits of the same PR.


if(
cmdline.isset("show-goto-functions") ||
cmdline.isset("list-goto-functions"))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This alias is not configured in GOTO_INSPECT_OPTIONS.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed.

@NlightNFotis NlightNFotis force-pushed the goto-inspect branch 3 times, most recently from c7e67aa to 5cffca7 Compare May 19, 2023 15:30
@NlightNFotis
Copy link
Contributor Author

Squashed the commits down to one.

@NlightNFotis NlightNFotis enabled auto-merge May 19, 2023 15:31
@kroening
Copy link
Member

Hi @kroening, I've had some more time to play around with this, and it doesn't have any particular dependency on the order of arguments, i.e. both: goto-inspect --show-goto-functions example.goto and goto-inspect example.goto --show-goto-functions will work.

I got thrown off by your comment "Yes, changed to > 2" -- this is outdated?

@NlightNFotis
Copy link
Contributor Author

Hi @kroening,

I got thrown off by your comment "Yes, changed to > 2" -- this is outdated?

Yes. Thomas had asked if I can tighten the error checking there, which I initially did by checking that the cmdline.args > 2 (1 for the filename and 1 for the option). After some experimenting during the addition of tests, I found out that the initial approach was (more) correct because cmdline.args contains the positional arguments of the program, with the optional ones being added to the cmdline.options vector (so if you issue, for example, $ goto-inspect --show-goto-functions example.gb, the option --show-goto-functions won't be present in the cmdline.args, and cmdline.args == 1 holds)

At that point, I changed it to check that we always get one positional argument (based on the fact that the tool, for now, operates on one goto-binary at a time) before we do anything, and dispatches to various inspection options based on them being set and the above precondition (at least 1 positional argument, i.e. 1 goto-binary filename) holds.

If the positional argument doesn't correspond to a goto-binary, we get an error that the program failed to read a goto-binary.

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.
@NlightNFotis NlightNFotis merged commit 1ad9a76 into diffblue:develop May 23, 2023
@NlightNFotis NlightNFotis deleted the goto-inspect branch May 23, 2023 17:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants