-
-
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 3 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,39 @@ | ||
| use super::prelude::*; | ||
| use crate::protocol::commands::ext::HostInfo; | ||
|
|
||
| use super::info_response::InfoResponse; | ||
| use crate::target::ext::host_info::InfoResponse as HostInfoResponse; | ||
|
|
||
| impl<T: Target, C: Connection> GdbStubImpl<T, C> { | ||
| pub(crate) fn handle_host_info( | ||
| &mut self, | ||
| res: &mut ResponseWriter<'_, C>, | ||
| target: &mut T, | ||
| command: HostInfo, | ||
| ) -> Result<HandlerStatus, Error<T::Error, C::Error>> { | ||
| let ops = match target.support_host_info() { | ||
| Some(ops) => ops, | ||
| None => return Ok(HandlerStatus::Handled), | ||
| }; | ||
|
|
||
| crate::__dead_code_marker!("host_info", "impl"); | ||
|
|
||
| let mut result = Ok(()); | ||
| let mut write_info = |info: &HostInfoResponse<'_>| { | ||
| if result.is_ok() { | ||
| if let Err(e) = InfoResponse::from(info).write_response(res) { | ||
| result = Err(e); | ||
| } | ||
| } | ||
| }; | ||
|
|
||
| match command { | ||
| HostInfo::qHostInfo(_cmd) => { | ||
| ops.host_info(&mut write_info).map_err(Error::TargetError)?; | ||
| result?; | ||
| } | ||
| }; | ||
|
|
||
| Ok(HandlerStatus::Handled) | ||
| } | ||
| } |
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,65 @@ | ||
| use super::prelude::*; | ||
| use crate::common::Endianness; | ||
| use crate::common::Pid; | ||
| use crate::protocol::ResponseWriterError; | ||
|
|
||
| pub(crate) enum InfoResponse<'a> { | ||
| Pid(Pid), | ||
| Triple(&'a str), | ||
| Endianness(Endianness), | ||
| PointerSize(usize), | ||
| } | ||
|
|
||
| impl<'a> InfoResponse<'a> { | ||
| pub(crate) fn write_response<C: Connection>( | ||
| &self, | ||
| res: &mut ResponseWriter<'_, C>, | ||
| ) -> Result<(), ResponseWriterError<C::Error>> { | ||
| match self { | ||
| 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<'a> From<&crate::target::ext::host_info::InfoResponse<'a>> for InfoResponse<'a> { | ||
cfallin marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| fn from(resp: &crate::target::ext::host_info::InfoResponse<'a>) -> Self { | ||
| use crate::target::ext::host_info::InfoResponse as R; | ||
| match *resp { | ||
| R::Triple(s) => InfoResponse::Triple(s), | ||
| R::Endianness(e) => InfoResponse::Endianness(e), | ||
| R::PointerSize(p) => InfoResponse::PointerSize(p), | ||
| } | ||
| } | ||
| } | ||
|
|
||
| impl<'a> From<&crate::target::ext::process_info::InfoResponse<'a>> for InfoResponse<'a> { | ||
| fn from(resp: &crate::target::ext::process_info::InfoResponse<'a>) -> Self { | ||
| use crate::target::ext::process_info::InfoResponse as R; | ||
| match *resp { | ||
| R::Pid(pid) => InfoResponse::Pid(pid), | ||
| R::Triple(s) => InfoResponse::Triple(s), | ||
| R::Endianness(e) => InfoResponse::Endianness(e), | ||
| R::PointerSize(p) => InfoResponse::PointerSize(p), | ||
| } | ||
| } | ||
| } | ||
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,40 @@ | ||
| use super::prelude::*; | ||
| use crate::protocol::commands::ext::ProcessInfo; | ||
|
|
||
| use super::info_response::InfoResponse; | ||
| use crate::target::ext::process_info::InfoResponse as ProcessInfoResponse; | ||
|
|
||
| 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: &ProcessInfoResponse<'_>| { | ||
| if result.is_ok() { | ||
| if let Err(e) = InfoResponse::from(info).write_response(res) { | ||
| result = Err(e); | ||
| } | ||
| } | ||
| }; | ||
|
|
||
| match command { | ||
| ProcessInfo::qProcessInfo(_cmd) => { | ||
| ops.process_info(&mut write_info) | ||
| .map_err(Error::TargetError)?; | ||
| result?; | ||
| } | ||
| }; | ||
|
|
||
| Ok(HandlerStatus::Handled) | ||
| } | ||
| } |
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,42 @@ | ||||||
| //! Provide host information to the debugger. | ||||||
cfallin marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
| //! | ||||||
| //! This allows for reporting key-value metadata, for example the | ||||||
| //! target triple, endianness, and pointer size. | ||||||
| //! | ||||||
| //! This corresponds to the `qHostInfo` command in the LLDB | ||||||
| //! extensions. | ||||||
|
|
||||||
| use crate::common::Endianness; | ||||||
| use crate::target::Target; | ||||||
|
|
||||||
| /// A response key-value pair to a qHostInfo query. | ||||||
cfallin marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
| /// | ||||||
| /// A response consists of a list of key-value pairs, each of which is | ||||||
| /// represented by one instance of this enum. | ||||||
| /// | ||||||
| /// The allowed responses are documented in the [LLDB extension | ||||||
| /// documentation]. Not all supported responses are currently | ||||||
| /// represented in this enum. If you need another one, please feel | ||||||
| /// free to send a PR! | ||||||
| /// | ||||||
| /// [LLDB extension documentation]: https://lldb.llvm.org/resources/lldbplatformpackets.html | ||||||
| #[derive(Clone, Copy)] | ||||||
| #[non_exhaustive] | ||||||
| pub enum InfoResponse<'a> { | ||||||
cfallin marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
| /// The target triple for the debuggee, as a string. | ||||||
| Triple(&'a str), | ||||||
| /// The target endianness. | ||||||
| Endianness(Endianness), | ||||||
| /// The pointer size. | ||||||
| PointerSize(usize), | ||||||
| } | ||||||
|
|
||||||
| /// Target Extension - Provide host information. | ||||||
cfallin marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
| pub trait HostInfo: Target { | ||||||
| /// Write a response to a host-info query (LLDB extension). | ||||||
|
||||||
| /// Write a response to a host-info query (LLDB extension). | |
| /// Write a response to a host-info query. |
(since it'd be present on the trait itself)
Contributor
Author
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
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,48 @@ | ||
| //! Provide process information to the debugger. | ||
cfallin marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| //! | ||
| //! This allows for reporting key-value metadata, for example the | ||
| //! current PID, target triple, endianness, and pointer size. | ||
| //! | ||
| //! This corresponds to the `qHostInfo` command in the LLDB | ||
| //! extensions. | ||
|
|
||
| use crate::common::Endianness; | ||
| use crate::common::Pid; | ||
| use crate::target::Target; | ||
|
|
||
| /// A response key-value pair to a qProcessInfo query. | ||
cfallin marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| /// | ||
| /// A response consists of a list of key-value pairs, each of which is | ||
| /// represented by one instance of this enum. | ||
| /// | ||
| /// The allowed responses are documented in the [LLDB extension | ||
| /// documentation]. Not all supported responses are currently | ||
| /// represented in this enum. If you need another one, please feel | ||
| /// free to send a PR! | ||
| /// | ||
| /// [LLDB extension documentation]: https://lldb.llvm.org/resources/lldbplatformpackets.html | ||
| #[derive(Clone, Copy)] | ||
| #[non_exhaustive] | ||
| 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), | ||
| } | ||
|
|
||
| /// Target Extension - Provide process information. | ||
cfallin marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| pub trait ProcessInfo: Target { | ||
| /// Write the response to process-info query (LLDB extension). | ||
cfallin marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| /// | ||
| /// 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.