samply_api/asm/
request_json.rs

1use serde_derive::Deserialize;
2
3#[derive(Deserialize, Debug)]
4#[serde(rename_all = "camelCase")]
5pub struct Request {
6    pub name: Option<String>, // example: "xul.dll"
7    pub code_id: Option<String>,
8    pub debug_name: Option<String>, // example: "xul.pdb"
9    pub debug_id: Option<String>,
10
11    /// The start address where the disassembly should start,
12    /// as a "0x"-prefixed hex string, interpreted as a
13    /// library-relative offset in bytes.
14    #[serde(deserialize_with = "crate::hex::from_prefixed_hex_str")]
15    pub start_address: u32,
16
17    /// The length, in bytes, of the machine code that should be disassembled,
18    /// as a "0x"-prefixed hex string.
19    #[serde(deserialize_with = "crate::hex::from_prefixed_hex_str")]
20    pub size: u32,
21
22    /// Whether to continue disassembling after `start_address + size` until the
23    /// end of the function that `start_address` was found in. This field is
24    /// optional and defaults to false.
25    ///
26    /// Prefer to specify the full function size in `size`, and only set this field
27    /// if the function size is not known, for example because symbolication did
28    /// not provide that information.
29    #[serde(default)]
30    pub continue_until_function_end: bool,
31}
32
33#[cfg(test)]
34mod test {
35    use serde_json::Result;
36
37    use super::Request;
38
39    #[test]
40    fn parse_job() -> Result<()> {
41        let data = r#"
42        {
43          "debugName": "xul.pdb",
44          "debugId": "A14CAFD390A3E1884C4C44205044422E1",
45          "startAddress": "0x1d04742",
46          "size": "0x84"
47        }"#;
48
49        let r: Request = serde_json::from_str(data)?;
50        assert_eq!(r.start_address, 30426946);
51        assert_eq!(r.debug_id, Some("A14CAFD390A3E1884C4C44205044422E1".into()));
52        assert!(!r.continue_until_function_end);
53        Ok(())
54    }
55}