Skip to content
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

[Proposal] Provide CallContext APIs to allow modification of parameters or return values #4

Closed
y1yang0 opened this issue Jul 24, 2024 · 2 comments

Comments

@y1yang0
Copy link
Member

y1yang0 commented Jul 24, 2024

Currently, if we want to change the parameters or return values of the original function, we are using a very error-prone and meticulously written code:

*(call.Params[0].(*string)) = "olleH%s\n"
(*(call.Params[1].(*[]any)))[0] = "goodcatch"
}

This troubles rule authors and is highly prone to errors. We should consider providing APIs in the CallContext to allow rule authors to easily modify parameters or return values without needing to understand the "pointer to a pointer is the original value" magic. For example:

call.SetArg0("olleH%s\n")
call.SetArg1("goodcatch")
call.SetRet0(1024)

This patch significantly changes the form of the hook code; specifically, CallContext is no longer a struct but an interface. The reason for this change is that we might be instrumenting different methods within the same package, and we need to generate the get/setParam functions at compile time. The parameter types of different methods are different, so we need to dynamically generate different struct implementations for different methods.

@123liuziming
Copy link
Collaborator

Could you please put your related PR in this issue?

@y1yang0
Copy link
Member Author

y1yang0 commented Jul 26, 2024

Could you please put your related PR in this issue?

This is quite complex and still in progress. For very early access, you can checkout this branch to explore more :)

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

No branches or pull requests

2 participants