Comments (7)
Sure! I'd be happy to put in some work to improve this API :)
I like your suggestion of providing a size hint via an Option<Self, Option<NonZeroUsize>>
return value. I suppose to take it further, if a RegId
implementation returns Some(NonZeroUsize)
- we would enforce that a register be sized appropriately.
Otherwise, it can be any size.
gdbstub/examples/armv4t/gdb/mod.rs
Lines 205 to 219 in 9e0526d
copy_from_slice
will panic if the source or destination have a size mismatch, which ensures that (this particular case) cannot pass invalid-sized registers.
from gdbstub.
To add to this discussion - gdbstub
's RegId
abstraction does not allow for dynamic dispatch due to RegId::from_raw_id
returning both an ID and size, the latter of which cannot be known at compile-time.
I'm wondering if there's any drawbacks to modifying the signature of SingleRegisterAccess::read_register
to take a &mut Write
in lieu of a buffer, that way it can effectively directly call ResponseWriter::write_hex_buf
instead of using a temporary buffer.
This will allow us to remove size information from from_raw_id
- instead read_register
will determine the size of a register.
The most obvious drawback I can think of now is that it'll allow the size of a register returned from write_register
to deviate from the target spec (as of now it will panic in core::slice::copy_from_slice
in the armv4t
example).
A similar approach could be taken for SingleRegisterAccess::write_register
for symmetry, though the current approach taken is perfectly fine.
from gdbstub.
Damn, you're right. RegId
totally isn't object safe.
Your idea of modifying read_register
to accept something like a output: &mut dyn FnMut(&[u8])
is intriguing, as while it'll certainly be a bit more clunky to use, it does alleviate the need for a temporary buffer...
I guess the broader question is whether or not gdbstub
should provide any "guard rails" to avoid accidentally sending invalid register data back to the client. One way to get the best of both worlds might be to keep RegId::from_raw_id
's signature as-is, and instead of using the size value as a way to truncate the buffer passed to SingleRegisterAccess::read_register
, it would instead be used to validate the length of any outgoing data sent via the &mut dyn FnMut(&[u8])
callback.
In the case of PassthroughRegId
, you could simply return usize::MAX
for the size, which would be equivalent to "send back as much data as you'd like". Alternatively, since these changes will already require a breaking API change, we could also change RegId::from_raw_id
to return a Option<Self, Option<NonZeroUsize>>
instead, where the Some(usize, None)
would represent "no size hint available".
If you can hack together a POC implementation, I'd be more than happy to work with you to tweak the API to me more amenable to your use case. Since I just released 0.5
a few days ago, I'm not sure if I'd want to cut a breaking 0.6
release just yet, so we'd want to land these changes on a [currently non-existent] dev/0.6
branch.
Also, could you elaborate on what you mean by "(as of now it will panic in core::slice::copy_from_slice
in the armv4t example)"? I'm not sure I follow.
from gdbstub.
Also - I noticed that there is a new pc()
function on the Registers
trait. It doesn't appear to be used at this point, but for obvious reasons it isn't going to work when the architecture is dynamically selected :)
P.S: Have you had any thoughts about the weird x86 boot process? Specifically its mode-switching between 16-bit, to 32-bit, to 64-bit?
I've been wondering if GDB can support that. It seems that it allows you to switch the target architecture via set arch
, but I haven't figured out how to get the gdbstub
side to adjust accordingly.
from gdbstub.
Also - I noticed that there is a new
pc()
function on theRegisters
trait.
sigh this is another vestigial bit of infrastructure left over from when I took a crack at implementing GDB Agent support (see the feature-draft/agent
branch). In hindsight, I could achieve the same functionality by having a get_pc()
method as part of the Agent IDET itself... oops.
I should probably just mark that bit of the Arch
API as deprecated and mark it for removal in 0.6
...
P.S: Have you had any thoughts about the weird x86 boot process? Specifically its mode-switching between 16-bit, to 32-bit, to 64-bit?
Hmmm, that's an interesting point...
Taking a very cursory look at the "prior art" in the open-source GDB stub space, it seems that most stubs assume a single static architecture throughout execution. e.g: QEMU seems to have the same issue, and as such, requires some client side workarounds to debug early-boot code.
Another consideration is that the GDB RSP doesn't have any built-in arch-switching signaling mechanism, so even though you can set arch
on the client side, it's up to you to signal that switch to gdbstub
.
TL;DR, I think there are two approaches you can take here:
- Do the QEMU thing where you just stick to the lowest-common-denominator arch, and then do those translation shenanigans as outlined in the linked StackOverflow thread
- Implement the
MonitorCmd
IDET and add a custom arch-switching mechanism to mirror the client-sideset arch
. I'm not super sure on the specifics on what an implementation would look like, so you'll be breaking even more new ground if you go that route.
from gdbstub.
Add this to 0.6
milestone?
from gdbstub.
Which bit specifically?
Dynamic Arch
selection as a whole is a larger design problem, one which I've already had a couple of false-starts on fixing in the past. Fixing this issue entirely will require a holistic reexamination of the current Arch
infrastructure, and it'll be a non-trivial time commitment to rewrite / tweak the API to be more dynamic while still retaining as many of the performance and ergonomic benefits that come with having it be statically defined.
At the moment, my gut feeling is to keep 0.6 the "bare metal" release (with an emphasis on the new state-machine API + no panic support), and punting the bulk of this issue to 0.7.
from gdbstub.
Related Issues (20)
- Improved Error Type (more specificity, fewer semver hazards, etc...) HOT 1
- Clippy warnings in library code HOT 3
- Allow passing a custom initial stop reason
- [mips] "unexpected packet" packet on single step HOT 10
- Not getting any events when breakpoint is set HOT 1
- All registers are byteswapped when using lldb HOT 14
- Switch `enum Signal` to `struct Signal(pub u8)` with associated constants
- NoActiveThreads error when there are no active thread HOT 9
- Misleading comment in `state_machine`? HOT 2
- Multiprocess debugging HOT 8
- [riscv32] `PacketUnexpected` when issuing `stepi` HOT 3
- vAttach: invalid response causes command to not work HOT 6
- Remove `NoActiveThread` Error
- example_no_std doesn't build on Windows HOT 1
- Remove `SingleStepBehavior` guard rail HOT 1
- Make `QStartNoAckMode` optional HOT 1
- Options for flow control? HOT 3
- Support "ack/nack" packets for unreliable transports HOT 6
- Fails to compile for atmega328p (Arduino Uno) HOT 2
- Add APIs for generating XML on-the-fly
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gdbstub.