-
Notifications
You must be signed in to change notification settings - Fork 277
Memory snapshot harness lines #4411
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
Memory snapshot harness lines #4411
Conversation
c09dc87
to
b6788e3
Compare
const auto &goto_function = entry.second; | ||
|
||
if(!goto_function.body_available()) | ||
continue; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's actually unnecessary, the std::find_if
will do the right thing either way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand. I call find_if
on the instructions inside goto_function.body
. If the body is not body_available
is it still safe to do?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is safe (body_available()
just tests emptiness), but arguably that could change at some point in the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I removed it but left a comment.
|
||
if(it != goto_program.instructions.end()) | ||
{ | ||
entry_function_name = entry.first; //TODO - move elsewhere |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think I understand this TODO
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, should have been removed before.
goto_program.instructions.end(), | ||
[this](const goto_programt::instructiont &instruction) { | ||
return safe_string2unsigned(id2string( | ||
instruction.source_location.get_line())) >= *line_number; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But then the same line number can occur in multiple files?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well find_if
should return the first location with "high enough" line number. Is this still relevant if we insist on having the user specify the file as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the user can/has to specify the file then that's sorted, thanks!
const auto &goto_program = goto_function->second.body; | ||
if(!location_number.has_value()) | ||
return goto_program.instructions.begin(); | ||
if(goto_program.instructions.size() > *location_number) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this condition necessary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because I'm advancing the iterator by *location_number
position and I don't want to get past the end()
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, sorry, I missed that. But also this isn't how the location_number
member of instructions works: these location numbers are guaranteed to be unique across all goto functions, and monotonically increasing in a single function. Therefore a location number could well be larger than the size of a single function. At the same time, there could be gaps, so locations in a function could legitimately be numbered "7, 10, 15" instead of "1, 2, 3."
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I give up. What about find_if
to get the right instruction? That should be safe right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I'm afraid you will have to do some form of search (technically binary search would be faster, but quite likely no one will notice the cost of linear search here).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But would binary search on a std::list
really be faster? I thought that random access there is linear in the distance
of the jump.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a question of how expensive the comparison operation is. Most likely you are right in that binary search would not add any value (or may indeed be more expensive).
@@ -34,6 +35,7 @@ Author: Daniel Poetzl | |||
"--initial-location <func[:<n>]>\n" \ | |||
" use given function and location number as " \ | |||
"entry\n point\n" \ | |||
"--initial-line <n> use given line as entry point\n" \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we actually use file:line
? I think the line number alone is too ambiguous. You might actually end up picking an instruction from some system header file!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a very good idea. Added in the last commit. Which will also be squashed.
979cd9e
to
e2598d2
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR failed Diffblue compatibility checks (cbmc commit: 1f0d7e9).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/105415411
Status will be re-evaluated on next push.
Common spurious failures:
-
the cbmc commit has disappeared in the mean time (e.g. in a force-push)
-
the author is not in the list of contributors (e.g. first-time contributors).
-
the compatibility was already broken by an earlier merge.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR failed Diffblue compatibility checks (cbmc commit: e2598d2).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/105422508
Status will be re-evaluated on next push.
Common spurious failures:
-
the cbmc commit has disappeared in the mean time (e.g. in a force-push)
-
the author is not in the list of contributors (e.g. first-time contributors).
-
the compatibility was already broken by an earlier merge.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR failed Diffblue compatibility checks (cbmc commit: 948b575).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/105424064
Status will be re-evaluated on next push.
Common spurious failures:
-
the cbmc commit has disappeared in the mean time (e.g. in a force-push)
-
the author is not in the list of contributors (e.g. first-time contributors).
-
the compatibility was already broken by an earlier merge.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like a reasonable feature. Will approve once @tautschnig 's comments have been resolved.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me overall, not even really nitpicks just suggestion/questions
@@ -61,6 +63,24 @@ void memory_snapshot_harness_generatort::handle_option( | |||
{ | |||
variables_to_havoc.insert(values.begin(), values.end()); | |||
} | |||
else if(option == "initial-file-line") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚲 🏚️ maybe --initial-source-location
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
require_exactly_one_value(option, values); | ||
|
||
std::vector<std::string> start; | ||
split_string(initial_file_line, ':', start, true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
split_string
has a special cased version for working with 2 values, maybe worth considering?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
"invalid initial location specification", "--initial-file-line"); | ||
} | ||
|
||
initial_file_name = start.front(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 might be worth wrapping these two in a struct to keep (and make obvious) the invariant that either both or neither of these are set
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@hannes-steffenhagen-diffblue This required a little bigger change: the last 7 commits. Please have a look if its still acceptable.
irep_idt function_name; | ||
optionalt<goto_programt::const_targett> start_instruction; | ||
|
||
void initialize_via_goto( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd be more comfortable if these were builder/constructor functions, i.e. entry_locationt make_from_goto_location(...);
, entry_locationt make_from_source_location
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea: done.
irep_idt function_name; | ||
optionalt<unsigned> location_number; | ||
|
||
entry_goto_locationt(const std::string &cmdl_option); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
explicit
- also, I'm personally not a huge fan of "do work" constructors, i.e. this one parses from string, I'd prefer if it was a function that said it did that in its name
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done + constructors are now trivial.
irep_idt file_name; | ||
unsigned line_number; | ||
|
||
entry_source_locationt(const std::string &cmdl_option); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also explicit
and the above comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
const entry_source_locationt &entry_source_location, | ||
const goto_functionst &goto_functions); | ||
|
||
bool valid() const |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally it shouldn't be possible to construct this in an invalid state, if it can be avoided
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
|
||
if(start.size() == 2) | ||
{ | ||
location_number = optionalt<unsigned>(safe_string2unsigned(start.back())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should be string2optional_unsigned
instead, and you should check the result... if this function returns nullopt
it means its argument wasn't a valid integer, which is something you don't want to silently ignore
(with safe_string2unsigned
you're basically asserting that this conversion will always succeed which is not correct for user supplied strings)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
} | ||
|
||
file_name = initial_file_string; | ||
line_number = safe_string2unsigned(initial_line_string); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as above
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
"choose either source or goto location to specify the entry point", | ||
"--initial-source/goto-location"); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this needs a check that only one of goto location and source location is set?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's there somewhere (line 69).
To test the new entry point selection and reflect the renaming of the option.
And unify the option names.
Two kinds of user specification: either via goto location or via source line. We wrap these in entry_goto/source_locationt and build the production of the final entry_locationt.
We only store the strings here.
e3e90ec
to
217ee86
Compare
217ee86
to
8fc213e
Compare
Most of the sanity checks are in the wrappers and the `get_target` function is now redundant.
8fc213e
to
0249ba0
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR failed Diffblue compatibility checks (cbmc commit: 0249ba0).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/106287968
Status will be re-evaluated on next push.
Common spurious failures include: the cbmc commit has disappeared in the mean time (e.g. in a force-push); the author is not in the list of contributors (e.g. first-time contributors); compatibility was already broken by an earlier merge.
Before the user had to run the CBMC first to find out the location where they wanted to start their snaphot. This PR adds to option to specify the code line.