Skip to content
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

feat: add many safe wrapper functions #39

Merged
merged 10 commits into from
Nov 26, 2024

Conversation

anatawa12
Copy link
Contributor

This PR adds many safe wrapper functions that I need in my project.

Those functions are firstly implemented with SBXxxExt trait in my project and it looks work well so I create this PR to upstream functionalities.

@anatawa12 anatawa12 force-pushed the add-many-wrappers branch 4 times, most recently from 0828838 to a22851e Compare November 25, 2024 05:11
Copy link
Contributor

@waywardmonkeys waywardmonkeys left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

This looks good with just some minor details.

If you don't want to deal with that, I can merge it and fix it up myself as well. Just let me know!

src/address.rs Outdated
/// Returns offset of the address in the section
///
/// See also:
/// - [`get_section`] for get the section corresponding to this address
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"for getting the"

src/filespec.rs Outdated
@@ -33,6 +33,12 @@ impl SBFileSpec {
}
}

/// Create SBFileSpec from path
pub fn from_path(path: &str, resolve: bool) -> Self {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense for this to be generic on something like:

pub fn from_path<P: AsRef<Path>>(path: P, resolve: bool) -> Self

?

src/module.rs Outdated
@@ -133,6 +139,63 @@ impl<'d> Iterator for SBModuleSectionIter<'d> {

impl<'d> ExactSizeIterator for SBModuleSectionIter<'d> {}

/// The list of symbols in the module
pub struct ModuleSymbols<'d> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this just be a SBModuleSymbolsIter like the other iterators?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it should have direct indexed accessor and length access so I made it have intermediate struct.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Curious to know why... but not going to block on it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I want to get first library (excluding exexutable), I think it should be possible to access 1th element without accessing 0th element, but I came up with implementing nth of iterator is enough so I'll do this instead of intermediate struct.

src/process.rs Outdated

/// Reads the memory at specified address in the process to the `buffer`
pub fn read_memory(&self, addr: lldb_addr_t, buffer: &mut [u8]) -> Result<(), SBError> {
// SBProcessReadMemory will return error the memory region is not allowed to read
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"will return an error if the" (2 missing words)

src/process.rs Outdated
}

/// Loads the specified image to the process
pub fn load_image(&self, file: &SBFileSpec) -> Result<u32, SBError> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd probably make a quick pub struct ImageToken(u32) to hide the image_token rather than just allowing any u32 to be used.

src/process.rs Outdated
unsafe { sys::SBProcessGetByteOrder(self.raw) }
}

/// Loads the specified image to the process
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"into the" and a missing period at the end.

src/process.rs Outdated
}
}

/// Unloads the image loaded with [`load_image`]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing period at the end.

src/process.rs Outdated
///
/// [`load_image`]: Self::load_image
pub fn unload_image(&self, image_token: u32) -> Result<(), SBError> {
// the method returns error if image_token is not valid, instead of cause undefined behavior
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"instead of causing"

src/process.rs Outdated
}
}

/// Returns the [`SBTarget`] corresponds to this SBProcess.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"corresponding" and missing backticks on SBProcess and None (below)

src/process.rs Outdated
@@ -700,6 +700,9 @@ impl<'d> Iterator for SBProcessQueueIter<'d> {
}
}

/// The token to unload image
struct ImageToken(u32);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won't this need to be pub? And exported from lib.rs?

src/module.rs Outdated
@@ -133,6 +139,63 @@ impl<'d> Iterator for SBModuleSectionIter<'d> {

impl<'d> ExactSizeIterator for SBModuleSectionIter<'d> {}

/// The list of symbols in the module
pub struct ModuleSymbols<'d> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Curious to know why... but not going to block on it.

@waywardmonkeys waywardmonkeys merged commit 5bb8cff into endoli:main Nov 26, 2024
3 checks passed
@waywardmonkeys
Copy link
Contributor

Thank you!

@anatawa12 anatawa12 deleted the add-many-wrappers branch November 26, 2024 03:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants