Comments (2)
I think I've figured out why I wasn't able to get it working.
TL;DR: The T05;watch:<addr>;...
signal must be sent when after the CPU tries to access the memory location, but before it modifies it!
I figured this out by running a local gdbstub
+gdb
session on my x86 box with set debug remote 1
. Here's the transcript:
Sending packet: $Z0,7ffff7fe63e4,1#e6...Packet received: OK
Sending packet: $Z2,7fffffffdbac,4#a3...Packet received: OK
Sending packet: $vCont;c:p5104.-1#a8...Packet received: T05watch:00007fffffffdbac;06:b0dbffffff7f0000;07:b0dbffffff7f0000;10:3f51555555550000;thread:p5104.5104;core:4;
Sending packet: $m7fffffffdbac,4#58...Packet received: 00000000
Sending packet: $m7fffffffdbac,4#58...Packet received: 00000000
Sending packet: $m7fffffffdbac,4#58...Packet received: 00000000
Sending packet: $vCont;c:p5104.-1#a8...Packet received: T05watch:00007fffffffdbac;06:b0dbffffff7f0000;07:b0dbffffff7f0000;10:4d51555555550000;thread:p5104.5104;core:4;
Sending packet: $m7fffffffdbac,4#58...Packet received: 02000000
Sending packet: $qXfer:threads:read::0,1000#92...Packet received: l<threads>\n<thread id="p5104.5104" core="4" name="test"/>\n</threads>\n
Sending packet: $z0,7ffff7fd37a5,1#03...Packet received: OK
Sending packet: $z0,7ffff7fe508e,1#06...Packet received: OK
Sending packet: $z0,7ffff7fe63e4,1#06...Packet received: OK
Sending packet: $z2,7fffffffdbac,4#c3...Packet received: OK
As you can see, the first thing gdb
does after receiving the stop signal is to read the value of the memory location. It proceeds to resume execution, and immediately hits the watchpoint again, except this time, when it goes to read the memory location, there's a new value present!
Unlike my previous mental model (where the only thing that's required is to log when a system has already accessed a memory location), implementing this feature may be tricky depending on how the end user has architected their emulator.
As such, I think the best way to fix this is to extract the log_mem_access
callback from the step method, and create a new optional trait method like fn update_hw_breakpoint(&mut self, addr: Self::Usize, op: HwBreakOp) -> Option<Result<(), ()>>)
which gives individual targets an option to implement this hardware-level break/watchpoint support.
I'm currently working on a POC, and might push up some work soon-ish.
from gdbstub.
guh, it turns out the real issue was a lot simpler:
- I was writing the target's
pc
instead of the data address in the Stop packet - I was using
to_ne_bytes
instead ofto_be_bytes
from gdbstub.
Related Issues (20)
- Use `Option` in return type for `SingleRegisterAccess::read_register` HOT 1
- Allow `read_addrs()` to send fewer bytes than requested HOT 2
- 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
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.