-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Support for instruction reordering / jumping #1045
Comments
As an additional question, do you think this would be a simple enough feature for a newbie contributor such as me? Thank you. |
This is definitely an interesting feature, but it can also be dangerous during a debug session.
We wouldn't have to modify any of the instructions, we would simply have to set the program counter register to point to the address of the instruction we want to start executing. There are some considerations for this feature, as we could easily corrupt the program being executed. We could attempt to detect moves that would very likely corrupt the program and warn / stop that from happening.
The basic feature would be fairly easy to implement. The user would click on a file location in the IDE (or describe it in the CLI via linespec) and then we would translate that file:line to an instruction address in the program, and then set the value of the program counter register to that instruction. We have plenty of functions to be able to accomplish this part easily. As we'd only be modifying the program counter, going to another function would be dangerous as the stack frame would still be setup from the old function, etc. There may be GC implications here as well. I could see having this feature warn if the user decides to make a move that is outside of the current function (we could also pretty easily detect this with functions we already have) and have the opportunity to cancel the action. |
I agree on how dangerous it can be.
Oh, ok, my apologies for speculating on this.
Yes, I agree that this might be the case. I would say just declining to run the operation could be enough, with an error message as to why it's not possible to do so. Both the CLI and the API clients could then act on this as needed.
I know I'll make this sound more trivial than it is but what I have in mind is allowing jumps only in the current scope and return an error telling the user that this operation is not permitted. Regarding the GC complexity, should I try to get someone from the Go team pinged about this issue to jump in as well? My knowledge is very limited around these parts of Go unfortunately. |
@heschik @aarzilli any more thoughts / considerations here regarding potential program corruption when this feature is used? |
Jumping to a completely unrelated function is clearly asking for trouble. I wonder whether it'd be okay to force a function to return early to allow people to jump in non-leaf functions. I can't think of any reason the GC will give any trouble here, presuming you're not doing something crazy like jumping out of the middle of the GC itself. Offhand, defers are the thing I'd be concerned about. I think it might be okay because the runtime just maintains a stack, without the compiler doing anything special, but if I'm wrong and the compiler generates code that has assumptions about where defers can and cannot exist, strange stuff will happen if you jump around. |
|
I'll try and come up with something for this in the near future, just so that I get more familiar with Delve's inner code / how a debugger works in general and so on. |
instructions. Fixes go-delve#1045.
Sorry for the delay. The patch for this is almost done, I have a few things to polish then I'll send the PR. |
instructions. Fixes go-delve#1045.
instructions. Fixes go-delve#1045.
This currently is a more or less work in progress, it depends on the feature set we want to support this feature. In my opinion, this could be flagged as an experimental feature and if the user has an issue then it's their fault. Maybe it's not a 100% good statement to have. There are cases where this could be useful to have and a user that understands how to use it, will be able to use it to the full extent. I've tested this only on Windows, I'll let the integration test do the job on the other systems. Cross function jumping works as well, but only in the toy example below, I have no clue how the runtime will be affected by this. Fixes go-delve#1045
Hi @dlsniper , I just came across this discussion and I wonder if we are planning to support it or it is deemed impractical? |
This was received on GoLands issue tracker, see issue GO-5109.
The original request is:
From my understanding of the page documentation:
I believe this effectively means that we'd need to insert jumps in the source code to allow the execution to skip over code portions.
Now, given Go's nature of things, I don't expect this to be 100% bulletproof in the first version, so basically no validations would be required (such as making sure that there's no new memory allocation done by creating a variable and so on). Later on we could think about that.
As I don't know how complex this is to do, in general or in Go in particular, I'll leave this with you. Please let me know if there's anything that I can help.
Thank you.
The text was updated successfully, but these errors were encountered: