Skip to content

Better error messages from hooks #599

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 2 commits into from
Nov 21, 2022
Merged

Better error messages from hooks #599

merged 2 commits into from
Nov 21, 2022

Conversation

Baltoli
Copy link
Contributor

@Baltoli Baltoli commented Nov 21, 2022

This PR adds a generic identifier to every exception thrown by hooked function symbols in the LLVM backend.

The new output looks like this:

terminate called after throwing an instance of 'std::invalid_argument'
  what():  [hook_STRING_string2base_long]: Not a valid integer

Note that the exact hook name printed each time may not precisely match the source of the error (because some hooks are implemented in terms of each other - e.g. int2string in terms of base2string), but this change will at least make it slightly easier to track down what the problem is.

Closes #593

@Baltoli Baltoli marked this pull request as ready for review November 21, 2022 15:34
Comment on lines +276 to +282
#define KLLVM_HOOK_INVALID_ARGUMENT(msg) \
do { \
auto err_msg = std::string("[") + std::string(__func__) \
+ std::string("]: ") + std::string(msg); \
throw std::invalid_argument(err_msg); \
} while (false)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The changes in this PR are largely mechanical; replacing throw std::invalid_argument with a call to this macro.

Copy link
Collaborator

@dwightguth dwightguth left a comment

Choose a reason for hiding this comment

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

Very nice! We probably also want to try to print the arguments to the function via the macro somehow, but we can leave that for a future pr.

@rv-jenkins rv-jenkins merged commit 5408542 into master Nov 21, 2022
@rv-jenkins rv-jenkins deleted the better-errors branch November 21, 2022 21:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Better error message when failing to evaluate hooked function symbol
3 participants