-
-
Notifications
You must be signed in to change notification settings - Fork 64
Add support for qProcessInfo and qHostInfo queries.
#190
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
6fb1b3d
Add support for `qProcessInfo` and `qHostInfo` queries.
cfallin dbd0887
Review feedback.
cfallin 8d856f4
Review feedback.
cfallin 3f1a01d
Update src/target/ext/host_info.rs
cfallin f63c30d
Update src/target/ext/host_info.rs
cfallin 3a8d471
Review feedback.
cfallin 1b4090e
Merge remote-tracking branch 'origin/master' into process-host-info
cfallin fe400ea
remove extra files from merge
daniel5151 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| use super::prelude::*; | ||
| use crate::common::Endianness; | ||
| use crate::protocol::commands::ext::ProcessInfo; | ||
| use crate::protocol::ResponseWriterError; | ||
| use crate::target::ext::process_info::InfoResponse; | ||
|
|
||
| impl<'a> InfoResponse<'a> { | ||
| fn write_response<C: Connection>( | ||
| &self, | ||
| res: &mut ResponseWriter<'_, C>, | ||
| ) -> Result<(), ResponseWriterError<C::Error>> { | ||
| match self { | ||
cfallin marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| InfoResponse::Pid(pid) => { | ||
| res.write_str("pid:")?; | ||
| res.write_dec(usize::from(*pid))?; | ||
| } | ||
| InfoResponse::Triple(triple) => { | ||
| res.write_str("triple:")?; | ||
| res.write_hex_buf(triple.as_bytes())?; | ||
| } | ||
| InfoResponse::Endianness(endian) => { | ||
| res.write_str("endian:")?; | ||
| res.write_str(match endian { | ||
| Endianness::Big => "big;", | ||
| Endianness::Little => "little;", | ||
| })?; | ||
| } | ||
| InfoResponse::PointerSize(p) => { | ||
| res.write_str("ptrsize:")?; | ||
| res.write_dec(*p)?; | ||
| } | ||
| } | ||
| res.write_str(";")?; | ||
| Ok(()) | ||
| } | ||
| } | ||
|
|
||
| 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 result = Ok(()); | ||
| let mut write_info = |info: &InfoResponse<'_>| { | ||
| if result.is_ok() { | ||
| if let Err(e) = info.write_response(res) { | ||
| result = Err(e); | ||
| } | ||
| } | ||
| }; | ||
|
|
||
| let handler_status = match command { | ||
| ProcessInfo::qHostInfo(_cmd) => { | ||
| ops.host_info(&mut write_info).map_err(Error::TargetError)?; | ||
| result?; | ||
| HandlerStatus::Handled | ||
| } | ||
| ProcessInfo::qProcessInfo(_cmd) => { | ||
| ops.process_info(&mut write_info) | ||
| .map_err(Error::TargetError)?; | ||
| result?; | ||
| HandlerStatus::Handled | ||
| } | ||
| }; | ||
|
|
||
| Ok(handler_status) | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| //! 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. We take the information | ||
| //! that we can return as responses to this commands in the | ||
| //! [`HostInfoResponse`] and [`ProcessInfoResponse`] structs, | ||
|
Check failure on line 7 in src/target/ext/process_info.rs
|
||
cfallin marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| //! respectively. | ||
|
|
||
| use crate::common::{Endianness, Pid}; | ||
cfallin marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| /// A response key-value pair to a qProcessInfo or qHostInfo query. | ||
cfallin marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| /// | ||
| /// A response to either of these commands consists of a list of | ||
| /// key-value pairs, each of which is represented by one instance of | ||
| /// this enum. | ||
| pub enum InfoResponse<'a> { | ||
cfallin marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| /// The current process PID. | ||
| Pid(Pid), | ||
| /// The target triple for the debuggee, as a string. | ||
| Triple(&'a str), | ||
| /// The target endianness. | ||
| Endianness(Endianness), | ||
| /// The pointer size. | ||
| PointerSize(usize), | ||
| } | ||
|
|
||
| use crate::target::Target; | ||
cfallin marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| /// Target Extension - Provide host and process information. | ||
| pub trait ProcessInfo: Target { | ||
| /// Write a response to `qHostInfo`. | ||
cfallin marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| /// | ||
| /// Call `write_item` with each `InfoResponse` you wish to send. | ||
| fn host_info(&self, write_item: &mut dyn FnMut(&InfoResponse<'_>)) -> Result<(), Self::Error>; | ||
|
|
||
| /// Write the response to `qProcessInfo`. | ||
| /// | ||
| /// Call `write_item` with each `InfoResponse` you wish to send. | ||
| fn process_info( | ||
| &self, | ||
| write_item: &mut dyn FnMut(&InfoResponse<'_>), | ||
| ) -> Result<(), Self::Error>; | ||
| } | ||
|
|
||
| define_ext!(ProcessInfoOps, ProcessInfo); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.