Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/protocol/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -366,4 +366,9 @@ commands! {
"qTfV" => _qTfV::qTfV,
"qTsV" => _qTsV::qTsV,
}

process_info {
"qHostInfo" => _qHostInfo::qHostInfo,
"qProcessInfo" => _qProcessInfo::qProcessInfo,
}
}
14 changes: 14 additions & 0 deletions src/protocol/commands/_qHostInfo.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
use super::prelude::*;

#[derive(Debug)]
pub struct qHostInfo;

impl<'a> ParseCommand<'a> for qHostInfo {
#[inline(always)]
fn from_packet(buf: PacketBuf<'a>) -> Option<Self> {
if !buf.into_body().is_empty() {
return None;
}
Some(qHostInfo)
}
}
14 changes: 14 additions & 0 deletions src/protocol/commands/_qProcessInfo.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
use super::prelude::*;

#[derive(Debug)]
pub struct qProcessInfo;

impl<'a> ParseCommand<'a> for qProcessInfo {
#[inline(always)]
fn from_packet(buf: PacketBuf<'a>) -> Option<Self> {
if !buf.into_body().is_empty() {
return None;
}
Some(qProcessInfo)
}
}
2 changes: 2 additions & 0 deletions src/stub/core_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ mod lldb_register_info;
mod memory_map;
mod monitor_cmd;
mod no_ack_mode;
mod process_info;
mod resume;
mod reverse_exec;
mod section_offsets;
Expand Down Expand Up @@ -223,6 +224,7 @@ impl<T: Target, C: Connection> GdbStubImpl<T, C> {
Command::LibrariesSvr4(cmd) => self.handle_libraries_svr4(res, target, cmd),
Command::Libraries(cmd) => self.handle_libraries(res, target, cmd),
Command::Tracepoints(cmd) => self.handle_tracepoints(res, target, cmd),
Command::ProcessInfo(cmd) => self.handle_process_info(res, target, cmd),
// in the worst case, the command could not be parsed...
Command::Unknown(cmd) => {
// HACK: if the user accidentally sends a resume command to a
Expand Down
43 changes: 43 additions & 0 deletions src/stub/core_impl/process_info.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
use super::prelude::*;
use crate::protocol::commands::ext::ProcessInfo;

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

crate::__dead_code_marker!("process_info", "impl");

let mut write_err = Ok(());
let mut write_cb = |data: &[u8]| {
if write_err.is_ok() {
if let Err(e) = res.write_str(core::str::from_utf8(data).unwrap_or("")) {
write_err = Err(e);
}
}
};

let handler_status = match command {
ProcessInfo::qHostInfo(_cmd) => {
ops.host_info(&mut write_cb).map_err(Error::TargetError)?;
write_err?;
HandlerStatus::Handled
}
ProcessInfo::qProcessInfo(_cmd) => {
ops.process_info(&mut write_cb)
.map_err(Error::TargetError)?;
write_err?;
HandlerStatus::Handled
}
};

Ok(handler_status)
}
}
1 change: 1 addition & 0 deletions src/target/ext/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ pub mod libraries;
pub mod lldb_register_info_override;
pub mod memory_map;
pub mod monitor_cmd;
pub mod process_info;
pub mod section_offsets;
pub mod target_description_xml_override;
pub mod thread_extra_info;
Expand Down
34 changes: 34 additions & 0 deletions src/target/ext/process_info.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//! Provide host and process information to the debugger.
//!
//! These correspond to the `qHostInfo` and `qProcessInfo` commands.
//! They report key-value metadata such as the target triple,
//! endianness, pointer size, and process ID.
//!
//! The callback passed to these methods should be called with byte slices
//! that together form a semicolon-delimited `key:value;` response string.
//! For example:
//!
//! ```text
//! triple:7761736d33322d756e6b6e6f776e2d756e6b6e6f776e2d7761736d;pid:1;endian:little;ptrsize:4;
//! ```
//!
//! Note: the `triple` value must be hex-encoded.

use crate::target::Target;

/// Target Extension - Provide host and process information.
pub trait ProcessInfo: Target {
/// Write the response to `qHostInfo`.
///
/// Call `write` one or more times with byte slices that together form
/// the response. Each call appends to the output.
fn host_info(&self, write: &mut dyn FnMut(&[u8])) -> Result<(), Self::Error>;

/// Write the response to `qProcessInfo`.
///
/// Call `write` one or more times with byte slices that together form
/// the response. Each call appends to the output.
fn process_info(&self, write: &mut dyn FnMut(&[u8])) -> Result<(), Self::Error>;
}

define_ext!(ProcessInfoOps, ProcessInfo);
6 changes: 6 additions & 0 deletions src/target/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -746,6 +746,12 @@ pub trait Target {
fn support_libraries(&mut self) -> Option<ext::libraries::LibrariesOps<'_, Self>> {
None
}

/// Support for host and process information (qHostInfo / qProcessInfo).
#[inline(always)]
fn support_process_info(&mut self) -> Option<ext::process_info::ProcessInfoOps<'_, Self>> {
None
}
}

macro_rules! __delegate {
Expand Down
Loading