-
-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a new sub-IDET for `MultiThreadBase` to respond with extra information about a thread Signed-off-by: Ryan Fairfax <[email protected]>
- Loading branch information
Showing
9 changed files
with
145 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 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 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 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,34 @@ | ||
use super::prelude::*; | ||
|
||
use crate::protocol::common::thread_id::ThreadId; | ||
use crate::protocol::SpecificThreadId; | ||
|
||
#[derive(Debug)] | ||
pub struct qThreadExtraInfo<'a> { | ||
pub id: SpecificThreadId, | ||
|
||
pub buf: &'a mut [u8], | ||
} | ||
|
||
impl<'a> ParseCommand<'a> for qThreadExtraInfo<'a> { | ||
#[inline(always)] | ||
fn from_packet(buf: PacketBuf<'a>) -> Option<Self> { | ||
let (buf, body_range) = buf.into_raw_buf(); | ||
let body = buf.get(body_range.start..body_range.end)?; | ||
|
||
if body.is_empty() { | ||
return None; | ||
} | ||
|
||
match body { | ||
[b',', body @ ..] => { | ||
let id = SpecificThreadId::try_from(ThreadId::try_from(body).ok()?).ok()?; | ||
|
||
drop(body); | ||
|
||
Some(qThreadExtraInfo { id, buf }) | ||
} | ||
_ => None, | ||
} | ||
} | ||
} |
This file contains 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 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::ThreadExtraInfo; | ||
use crate::protocol::SpecificIdKind; | ||
use crate::target::ext::base::BaseOps; | ||
|
||
impl<T: Target, C: Connection> GdbStubImpl<T, C> { | ||
pub(crate) fn handle_thread_extra_info<'a>( | ||
&mut self, | ||
res: &mut ResponseWriter<'_, C>, | ||
target: &mut T, | ||
command: ThreadExtraInfo<'a>, | ||
) -> Result<HandlerStatus, Error<T::Error, C::Error>> { | ||
let ops = match target.base_ops() { | ||
BaseOps::SingleThread(_) => return Ok(HandlerStatus::Handled), | ||
BaseOps::MultiThread(ops) => match ops.support_thread_extra_info() { | ||
Some(ops) => ops, | ||
None => return Ok(HandlerStatus::Handled), | ||
}, | ||
}; | ||
|
||
crate::__dead_code_marker!("thread_extra_info", "impl"); | ||
|
||
let handler_status = match command { | ||
ThreadExtraInfo::qThreadExtraInfo(info) => { | ||
if let SpecificIdKind::WithId(tid) = info.id.tid { | ||
let size = ops | ||
.thread_extra_info(tid, info.buf) | ||
.map_err(Error::TargetError)?; | ||
let data = info.buf.get(..size).ok_or(Error::PacketBufferOverflow)?; | ||
|
||
res.write_hex_buf(data)?; | ||
} | ||
|
||
HandlerStatus::Handled | ||
} | ||
}; | ||
|
||
Ok(handler_status) | ||
} | ||
} |
This file contains 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 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 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,22 @@ | ||
//! Provide extra information for a thread | ||
use crate::common::Tid; | ||
use crate::target::Target; | ||
|
||
/// Target Extension - Provide extra information for a thread | ||
pub trait ThreadExtraInfo: Target { | ||
/// Provide extra information about a thread | ||
/// | ||
/// GDB queries for extra information for a thread as part of the | ||
/// `info threads` command. This function will be called once | ||
/// for each active thread. | ||
/// | ||
/// A string can be copied into `buf` that will then be displayed | ||
/// to the client. The string is displayed as `(value)`, such as: | ||
/// | ||
/// `Thread 1.1 (value)` | ||
/// | ||
/// Return the number of bytes written into `buf`. | ||
fn thread_extra_info(&self, tid: Tid, buf: &mut [u8]) -> Result<usize, Self::Error>; | ||
} | ||
|
||
define_ext!(ThreadExtraInfoOps, ThreadExtraInfo); |