-
-
Notifications
You must be signed in to change notification settings - Fork 51
Dynamic read_register
+ RegId
support
#85
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
Conversation
We may also need to do similar changes to the |
Hmm, it seems this change is doing a few different things:
That first change seems totally reasonable. That second one... well, I'll need a better explanation for that. The API you're proposing makes it very easy for a target to inadvertently send too much / too little data to the GDB client. The whole point of encoding the expected register size as part of the Could you elaborate on why you want to remove this guard rail? Am I missing something? Note that if this is an attempt to revive/complete #58, then I would much prefer the approach taken in that PR, where the "guard-rail" becomes optional vs. removing it entirely. I think there's a lot of merit in making it "hard to do the wrong thing", which has been a guiding principle in my approach to (though it should be noted, I would not want to keep the callback approach proposed in #58 - we most certainly would want to use the PacketBuf directly) In other words: I don't mind the API changes, but I don't think removing register sizes from |
Could you elaborate on what you mean? The |
Fine. I thought you use register size because you don't know how long the buffer should be passed. If you think the size guard is necessary, I will add it back. I just thought that, if the user want to fill
Is this so important? For example, if I want to report a 64-bit register is 0, can't I just reply "00"? ( Not tested )
Then how to design the API if we replace
Oh, you remind me. What I want to do is replacing the |
Truncating the buffer to the required length makes it possible to use Though I'll admit: this is a somewhat minor detail, and we could very-well pass the full untruncated PacketBuf to the implementation, forcing the implementation to truncate it to the correct length. Then again, why force users to write boilerplate, when we can just do it ourselves ¯_(ツ)_/¯
As per the spec: "The register number n is in hexadecimal, and r… contains two hex digits for each byte in the register (target byte order)." So it seems the response needs to be exactly the right size.
I was thinking it would look something like: fn read_register(
&mut self,
tid: Id,
reg_id: <Self::Arch as Arch>::RegId,
buf: &mut [u8],
) -> TargetResult<usize, Self>;
To reiterate: the rationale behind including the guard-rails in the API is realizing the following key aspect of implementing a GDB stub: it is very easy to mess up a handler implementation, and then have things Not Work:tm: for very non-obvious reasons. I love it when libraries double-check things for me, and return a useful error when I've messed up my end of the contract, thereby making my life a lot easier. That's my philosophy with As a side-note: at some point, I hope to eventually revisit the idea I linked to in #80 (comment), and see if there's some way of tying a fixed-size array / actual native number type with each This would require a lot of changes, and I still don't have a clear idea of how to best design / implement this. Nonetheless, I thought I'd mention this idea to you, for two reasons:
Yep, I'm all for this change. It would certainly make those implementations a lot cleaner, so if you're keen on improving that aspect of |
Co-authored-by: Dr. Chat <[email protected]>
This reminds me that why we need both
If I do this, I need to replace all the |
As per the spec: "At a minimum, a stub is required to support the ‘?’ command to tell GDB the reason for halting, ‘g’ and ‘G’ commands for register access, and the ‘m’ and ‘M’ commands for memory access." https://sourceware.org/gdb/current/onlinedocs/gdb/Overview.html i.e: single register reads/writes are optional, and shouldn't be a required part of a target implementation. ...though now that I re-read your question, I think you're actually suggesting something else: "why not implement the If so. then that is certainly an interesting point, that might merit a separate discussion. I can think of a few reasons why the current approach is better, though on the flipside, it would be nice to simplify this bit of the API... To avoid burying this discussion in this PR, could you re-state the question as a Discussion thread? That will make it easier to refer back to the discussion in the future.
I would probably be alright with taking a dependency on something like That said, I just brushed up on why exactly I opted to use a callback in Also, to avoid losing this context and discussion, can you open a new Discussion thread on the topic of refactoring |
Yes, that's what I mean!
Oh, I just thought that pass |
Lets keep this PR focused on changing the I've also gone ahead and changed the PR's title to reflect this focus. |
read_register
+ RegId
support
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.
Tiny nit, but aside from that, I think this is good to merge.
Co-authored-by: Daniel Prilik <[email protected]>
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.
Give me a 👍 if this is good to merge :)
Description
New approach to #58.
Part of #70.
Closes #58. Closes #80.
API Stability
Checklist
cargo build
compiles withouterrors
orwarnings
cargo clippy
runs withouterrors
orwarnings
cargo fmt
was runexamples/armv4t
examples/armv4t
withRUST_LOG=trace
+ any relevant GDB output under the "Validation" section below./scripts/test_dead_code_elim.sh
and/or./example_no_std/check_size.sh
)Arch
implementation