aboutsummaryrefslogtreecommitdiff
path: root/src/stub/core_impl/libraries.rs
blob: dd18cb7f03d5f1dcd8706199bd8de23605c96577 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
use super::prelude::*;
use crate::protocol::commands::ext::LibrariesSvr4;

impl<T: Target, C: Connection> GdbStubImpl<T, C> {
    pub(crate) fn handle_libraries_svr4(
        &mut self,
        res: &mut ResponseWriter<'_, C>,
        target: &mut T,
        command: LibrariesSvr4<'_>,
    ) -> Result<HandlerStatus, Error<T::Error, C::Error>> {
        let ops = match target.support_libraries_svr4() {
            Some(ops) => ops,
            None => return Ok(HandlerStatus::Handled),
        };

        crate::__dead_code_marker!("libraries-svr4", "impl");

        let handler_status = match command {
            LibrariesSvr4::qXferLibrariesSvr4Read(cmd) => {
                let ret = ops
                    .get_libraries_svr4(cmd.offset, cmd.length, cmd.buf)
                    .handle_error()?;
                if ret == 0 {
                    res.write_str("l")?;
                } else {
                    res.write_str("m")?;
                    // TODO: add more specific error variant?
                    res.write_binary(cmd.buf.get(..ret).ok_or(Error::PacketBufferOverflow)?)?;
                }
                HandlerStatus::Handled
            }
        };

        Ok(handler_status)
    }
}