-
-
Notifications
You must be signed in to change notification settings - Fork 64
Add support for Wasm-specific commands. #188
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 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
ac46530
Add support for Wasm-specific commands.
cfallin 2da4988
Review feedback.
cfallin 40937cc
Review feedback.
cfallin 8fbc6e9
Update src/target/mod.rs
cfallin eb4f543
Update src/target/ext/wasm.rs
cfallin 168f64b
Update src/target/ext/wasm.rs
cfallin 15dd0ec
Update src/target/ext/wasm.rs
cfallin 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| use super::prelude::*; | ||
| use crate::protocol::common::thread_id::ThreadId; | ||
|
|
||
| #[derive(Debug)] | ||
| pub struct qWasmCallStack { | ||
| pub tid: ThreadId, | ||
| } | ||
|
|
||
| impl<'a> ParseCommand<'a> for qWasmCallStack { | ||
| #[inline(always)] | ||
| fn from_packet(buf: PacketBuf<'a>) -> Option<Self> { | ||
| let body = buf.into_body(); | ||
| if body.is_empty() || body[0] != b':' { | ||
| return None; | ||
| } | ||
| let tid = &body[1..]; | ||
| let tid = ThreadId::try_from(tid).ok()?; | ||
| Some(qWasmCallStack { tid }) | ||
| } | ||
| } | ||
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,27 @@ | ||
| use super::prelude::*; | ||
|
|
||
| #[derive(Debug)] | ||
| pub struct qWasmGlobal { | ||
| pub frame: u32, | ||
| pub global: u32, | ||
| } | ||
|
|
||
| impl<'a> ParseCommand<'a> for qWasmGlobal { | ||
| #[inline(always)] | ||
| fn from_packet(buf: PacketBuf<'a>) -> Option<Self> { | ||
| let body = buf.into_body(); | ||
| if body.is_empty() || body[0] != b':' { | ||
| return None; | ||
| } | ||
| let mut parts = body[1..].split(|b| *b == b';'); | ||
| let frame = parts.next()?; | ||
| let frame = str::from_utf8(frame).ok()?.parse::<u32>().ok()?; | ||
| let global = parts.next()?; | ||
| let global = str::from_utf8(global).ok()?.parse::<u32>().ok()?; | ||
| if parts.next().is_some() { | ||
| // Too many parameters. | ||
| return None; | ||
| } | ||
| Some(qWasmGlobal { frame, global }) | ||
| } | ||
| } |
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,27 @@ | ||
| use super::prelude::*; | ||
|
|
||
| #[derive(Debug)] | ||
| pub struct qWasmLocal { | ||
| pub frame: u32, | ||
| pub local: u32, | ||
| } | ||
|
|
||
| impl<'a> ParseCommand<'a> for qWasmLocal { | ||
| #[inline(always)] | ||
| fn from_packet(buf: PacketBuf<'a>) -> Option<Self> { | ||
| let body = buf.into_body(); | ||
| if body.is_empty() || body[0] != b':' { | ||
| return None; | ||
| } | ||
| let mut parts = body[1..].split(|b| *b == b';'); | ||
| let frame = parts.next()?; | ||
| let frame = str::from_utf8(frame).ok()?.parse::<u32>().ok()?; | ||
| let local = parts.next()?; | ||
| let local = str::from_utf8(local).ok()?.parse::<u32>().ok()?; | ||
| if parts.next().is_some() { | ||
| // Too many parameters. | ||
| return None; | ||
| } | ||
| Some(qWasmLocal { frame, local }) | ||
| } | ||
| } |
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,27 @@ | ||
| use super::prelude::*; | ||
|
|
||
| #[derive(Debug)] | ||
| pub struct qWasmStackValue { | ||
| pub frame: u32, | ||
cfallin marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| pub index: u32, | ||
| } | ||
|
|
||
| impl<'a> ParseCommand<'a> for qWasmStackValue { | ||
| #[inline(always)] | ||
| fn from_packet(buf: PacketBuf<'a>) -> Option<Self> { | ||
| let body = buf.into_body(); | ||
| if body.is_empty() || body[0] != b':' { | ||
| return None; | ||
| } | ||
| let mut parts = body[1..].split(|b| *b == b';'); | ||
| let frame = parts.next()?; | ||
| let frame = str::from_utf8(frame).ok()?.parse::<u32>().ok()?; | ||
| let index = parts.next()?; | ||
| let index = str::from_utf8(index).ok()?.parse::<u32>().ok()?; | ||
| if parts.next().is_some() { | ||
| // Too many parameters. | ||
| return None; | ||
| } | ||
| Some(qWasmStackValue { frame, index }) | ||
| } | ||
| } | ||
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,61 @@ | ||
| use super::prelude::*; | ||
| use crate::protocol::{commands::ext::Wasm, IdKind}; | ||
cfallin marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| impl<T: Target, C: Connection> GdbStubImpl<T, C> { | ||
| pub(crate) fn handle_wasm( | ||
| &mut self, | ||
| res: &mut ResponseWriter<'_, C>, | ||
| target: &mut T, | ||
| command: Wasm, | ||
| ) -> Result<HandlerStatus, Error<T::Error, C::Error>> { | ||
| let ops = match target.support_wasm() { | ||
| Some(ops) => ops, | ||
| None => return Ok(HandlerStatus::Handled), | ||
| }; | ||
|
|
||
| crate::__dead_code_marker!("wasm", "impl"); | ||
|
|
||
| match command { | ||
| Wasm::qWasmCallStack(cmd) => { | ||
| let mut error: Result<(), Error<T::Error, C::Error>> = Ok(()); | ||
| let tid = match cmd.tid.tid { | ||
| IdKind::All => { | ||
| return Err(Error::NonFatalError(1)); | ||
| } | ||
| IdKind::Any => self.current_mem_tid, | ||
| IdKind::WithId(id) => id, | ||
| }; | ||
| ops.wasm_call_stack(tid, &mut |pc| { | ||
| if let Err(e) = res.write_hex_buf(&pc.to_le_bytes()) { | ||
| error = Err(e.into()); | ||
| } | ||
| }) | ||
| .map_err(Error::TargetError)?; | ||
| error?; | ||
| } | ||
| Wasm::qWasmLocal(cmd) => { | ||
| let mut buf = [0u8; 16]; | ||
| let len = ops | ||
| .read_wasm_local(self.current_mem_tid, cmd.frame, cmd.local, &mut buf) | ||
| .map_err(Error::TargetError)?; | ||
| res.write_hex_buf(&buf[0..len])?; | ||
| } | ||
| Wasm::qWasmGlobal(cmd) => { | ||
| let mut buf = [0u8; 16]; | ||
| let len = ops | ||
| .read_wasm_global(self.current_mem_tid, cmd.frame, cmd.global, &mut buf) | ||
| .map_err(Error::TargetError)?; | ||
| res.write_hex_buf(&buf[0..len])?; | ||
| } | ||
| Wasm::qWasmStackValue(cmd) => { | ||
| let mut buf = [0u8; 16]; | ||
| let len = ops | ||
| .read_wasm_stack(self.current_mem_tid, cmd.frame, cmd.index, &mut buf) | ||
| .map_err(Error::TargetError)?; | ||
| res.write_hex_buf(&buf[0..len])?; | ||
| } | ||
| }; | ||
|
|
||
| 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
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,63 @@ | ||
| //! Provide Wasm-specific actions for the target. | ||
cfallin marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| use crate::{common::Tid, target::Target}; | ||
cfallin marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| /// Target Extension - perform Wasm-specific actions. | ||
cfallin marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| pub trait Wasm: Target { | ||
cfallin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| /// Get the Wasm call stack for a given thread. | ||
| /// | ||
| /// See the [LLDB Wasm Extension Documentation] for a description | ||
| /// of the format of the PC values. | ||
| /// | ||
| /// [LLDB Wasm Extension Documentation]: https://lldb.llvm.org/resources/lldbgdbremote.html#wasm-packets | ||
cfallin marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| /// | ||
| /// To avoid allocation, the call stack PCs should be returned to | ||
| /// the caller by calling the given callback, in order from | ||
| /// innermost (most recently called) frame to outermost. | ||
| fn wasm_call_stack(&self, tid: Tid, next_pc: &mut dyn FnMut(u64)) -> Result<(), Self::Error>; | ||
cfallin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| /// Get the Wasm local for a given thread, frame index, and local | ||
| /// index. | ||
| /// | ||
| /// The Wasm local's value should be placed into `buf`, and the | ||
| /// length should be returned. If the Wasm local or frame does not | ||
| /// exist, this method should return `0`. | ||
| fn read_wasm_local( | ||
| &self, | ||
| tid: Tid, | ||
| frame: u32, | ||
| local: u32, | ||
| buf: &mut [u8; 16], | ||
daniel5151 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ) -> Result<usize, Self::Error>; | ||
|
|
||
| /// Get the Wasm operand-stack value for a given thread, frame | ||
| /// index, and stack index. Top-of-stack is index 0, and values | ||
| /// below that have incrementing indices. | ||
| /// | ||
| /// The Wasm operand's value should be placed into `buf`, and the | ||
| /// length should be returned. If the Wasm local or frame does not | ||
| /// exist, this method should return `0`. | ||
| fn read_wasm_stack( | ||
| &self, | ||
| tid: Tid, | ||
| frame: u32, | ||
| index: u32, | ||
| buf: &mut [u8; 16], | ||
| ) -> Result<usize, Self::Error>; | ||
|
|
||
| /// Get the Wasm global value for a given thread, frame, and | ||
| /// global index. The global index is relative to the module whose | ||
| /// function corresponds to that frame. | ||
| /// | ||
| /// The Wasm global's value should be placed into `buf`, and the | ||
| /// length should be returned. If the Wasm local or frame does not | ||
| /// exist, this method should return `0`. | ||
| fn read_wasm_global( | ||
| &self, | ||
| tid: Tid, | ||
| frame: u32, | ||
| global: u32, | ||
| buf: &mut [u8; 16], | ||
| ) -> Result<usize, Self::Error>; | ||
| } | ||
|
|
||
| define_ext!(WasmOps, Wasm); | ||
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.