-
Notifications
You must be signed in to change notification settings - Fork 273
Extract function pointers using memory analyzer #4730
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
Extract function pointers using memory analyzer #4730
Conversation
ab9c7be
to
ac5dee2
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.
Seems reasonable to me (modulo note on error handling) (probably needs a rebase due to changes in cbmc that broke/fixed/broke/fixed again CI.
const auto &function_name = pointer_value.pointee; | ||
CHECK_RETURN(!function_name.empty()); | ||
const auto function_symbol = symbol_table.lookup(function_name); | ||
CHECK_RETURN(function_symbol != nullptr); |
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 causing a runtime error instead of us asserting this is true; In practical programs it's very possible for this to happen.
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.
ac5dee2
to
de53ece
Compare
de53ece
to
64e9fdb
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.
✔️
Passed Diffblue compatibility checks (cbmc commit: 64e9fdb).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/114620019
Codecov Report
@@ Coverage Diff @@
## develop #4730 +/- ##
==========================================
Coverage ? 68.51%
==========================================
Files ? 1275
Lines ? 105032
Branches ? 0
==========================================
Hits ? 71958
Misses ? 33074
Partials ? 0
Continue to review full report at Codecov.
|
{ | ||
const auto target_expr = | ||
get_pointer_to_function_value(expr, value, location); | ||
CHECK_RETURN(target_expr.id() != ID_nil); |
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.
Although equivalent, I'd prefer target_expr.is_not_nil()
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 auto target_expr = | ||
get_pointer_to_function_value(expr, value, location); | ||
CHECK_RETURN(target_expr.id() != ID_nil); | ||
const auto result_expr = address_of_exprt(target_expr); |
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 use either exprt result_expr = ...
or address_of_exprt result_expr{target_expr};
(see below for more).
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 went for the address_of_exprt
and then std::move
.
CHECK_RETURN(target_expr.id() != ID_nil); | ||
const auto result_expr = address_of_exprt(target_expr); | ||
CHECK_RETURN(result_expr.type() == zero_expr.type()); | ||
return result_expr; |
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 needs to be return std::move(result_expr);
if you use address_of_exprt
above, or can stay as-is if using exprt result_expr = ...
. I'd say this is a case where auto
above really hurts you, because it hides a lot of this.
64e9fdb
to
a71e426
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.
✔️
Passed Diffblue compatibility checks (cbmc commit: a71e426).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/114723581
a71e426
to
420e334
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.
✔️
Passed Diffblue compatibility checks (cbmc commit: 420e334).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/114734689
By simply grabbing the pointee name from gdb (which is the function name) and returning the associated symbol expression.
1. one function one pointer 2. two functions two pointers, check they point to the right ones 3. two functions, array of function pointers, pointers initialised from the array
420e334
to
8941f72
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.
✔️
Passed Diffblue compatibility checks (cbmc commit: 8941f72).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/114902696
This PR adds the facilities to query GDB via
memory-analyzer
to obtain information about function pointers. The values of function pointers can then be extracted into a symbol table and reused, e.g. bygoto-harness
.