|
2 | 2 | //! |
3 | 3 | //! These correspond to the `qHostInfo` and `qProcessInfo` commands. |
4 | 4 | //! They report key-value metadata such as the target triple, |
5 | | -//! endianness, pointer size, and process ID. |
6 | | -//! |
7 | | -//! The callback passed to these methods should be called with byte slices |
8 | | -//! that together form a semicolon-delimited `key:value;` response string. |
9 | | -//! For example: |
10 | | -//! |
11 | | -//! ```text |
12 | | -//! triple:7761736d33322d756e6b6e6f776e2d756e6b6e6f776e2d7761736d;pid:1;endian:little;ptrsize:4; |
13 | | -//! ``` |
14 | | -//! |
15 | | -//! Note: the `triple` value must be hex-encoded. |
| 5 | +//! endianness, pointer size, and process ID. We take the information |
| 6 | +//! that we can return as responses to this commands in the |
| 7 | +//! [`HostInfoResponse`] and [`ProcessInfoResponse`] structs, |
| 8 | +//! respectively. |
| 9 | +
|
| 10 | +use crate::common::{Endianness, Pid}; |
| 11 | + |
| 12 | +/// A response to a `qProcessInfo` query from the debugger. |
| 13 | +/// |
| 14 | +/// This does not contain all possible fields, but it contains a few |
| 15 | +/// common ones that are needed to satisfy some debuggers. More may be |
| 16 | +/// added in the future. |
| 17 | +pub struct ProcessInfoResponse<'a> { |
| 18 | + /// The PID. |
| 19 | + pub pid: Pid, |
| 20 | + /// The triple (e.g. `wasm32-wasi` or `x86_64-unknown-linux-gnu`). |
| 21 | + pub triple: &'a str, |
| 22 | + /// The target endianness. |
| 23 | + pub endianness: Endianness, |
| 24 | + /// The pointer size. |
| 25 | + pub ptrsize: usize, |
| 26 | +} |
| 27 | + |
| 28 | +/// A response to a `qHostInfo` query from the debugger. |
| 29 | +/// |
| 30 | +/// This does not contain all possible fields, but it contains a few |
| 31 | +/// common ones that are needed to satisfy some debuggers. More may be |
| 32 | +/// added in the future. |
| 33 | +pub struct HostInfoResponse<'a> { |
| 34 | + /// The triple (e.g. `wasm32-wasi` or `x86_64-unknown-linux-gnu`). |
| 35 | + pub triple: &'a str, |
| 36 | + /// The target endianness. |
| 37 | + pub endianness: Endianness, |
| 38 | + /// The pointer size. |
| 39 | + pub ptrsize: usize, |
| 40 | +} |
16 | 41 |
|
17 | 42 | use crate::target::Target; |
18 | 43 |
|
19 | 44 | /// Target Extension - Provide host and process information. |
20 | 45 | pub trait ProcessInfo: Target { |
21 | | - /// Write the response to `qHostInfo`. |
| 46 | + /// Write a response to `qHostInfo`. |
22 | 47 | /// |
23 | | - /// Call `write` one or more times with byte slices that together form |
24 | | - /// the response. Each call appends to the output. |
25 | | - fn host_info(&self, write: &mut dyn FnMut(&[u8])) -> Result<(), Self::Error>; |
| 48 | + /// Call `respond` with a `HostInfoResponse` in order to send an |
| 49 | + /// appropriate response. |
| 50 | + fn host_info(&self, respond: &mut dyn FnMut(&HostInfoResponse<'_>)) -> Result<(), Self::Error>; |
26 | 51 |
|
27 | 52 | /// Write the response to `qProcessInfo`. |
28 | 53 | /// |
29 | | - /// Call `write` one or more times with byte slices that together form |
30 | | - /// the response. Each call appends to the output. |
31 | | - fn process_info(&self, write: &mut dyn FnMut(&[u8])) -> Result<(), Self::Error>; |
| 54 | + /// Call `respond` with a `ProcessInfoResponse` in order to send an |
| 55 | + /// appropriate response. |
| 56 | + fn process_info( |
| 57 | + &self, |
| 58 | + respond: &mut dyn FnMut(&ProcessInfoResponse<'_>), |
| 59 | + ) -> Result<(), Self::Error>; |
32 | 60 | } |
33 | 61 |
|
34 | 62 | define_ext!(ProcessInfoOps, ProcessInfo); |
0 commit comments