update dependency

This commit is contained in:
ridethepig 2023-03-07 14:39:02 +00:00
parent 1adfb67cff
commit 67eb2bcdfb
5 changed files with 34 additions and 27 deletions

View File

@ -7,11 +7,12 @@ edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]
nix = "0.17.0" nix = "0.26.2"
libc = "0.2.68" libc = "0.2.139"
rustyline = "6.1.2" rustyline = "11.0.0"
# gimli = { git = "https://github.com/gimli-rs/gimli", rev = "ad23cdb2", default-features = false, features = ["read"] } # gimli = { git = "https://github.com/gimli-rs/gimli", rev = "ad23cdb2", default-features = false, features = ["read"] }
gimli = "0.27.2" gimli = "0.27.2"
object = { version = "0.17", default-features = false, features = ["read"] } # object = { version = "0.17", default-features = false, features = ["read"] }
memmap = "0.7" object = "0.30.3"
addr2line = "0.11.0" memmap2 = "0.5.10"
addr2line = "0.19.0"

View File

@ -6,11 +6,12 @@ use crate::inferior::{Inferior, Status};
use nix::sys::signal::Signal::SIGTRAP; use nix::sys::signal::Signal::SIGTRAP;
use rustyline::error::ReadlineError; use rustyline::error::ReadlineError;
use rustyline::Editor; use rustyline::Editor;
use rustyline::history::FileHistory;
pub struct Debugger { pub struct Debugger {
target: String, target: String,
history_path: String, history_path: String,
readline: Editor<()>, readline: Editor<(), FileHistory>,
inferior: Option<Inferior>, inferior: Option<Inferior>,
debug_data: DwarfData, debug_data: DwarfData,
breakpoint_vec: Vec<usize>, breakpoint_vec: Vec<usize>,
@ -55,7 +56,7 @@ impl Debugger {
// debug_data.print(); // debug_data.print();
let history_path = format!("{}/.deet_history", std::env::var("HOME").unwrap()); let history_path = format!("{}/.deet_history", std::env::var("HOME").unwrap());
let mut readline = Editor::<()>::new(); let mut readline = Editor::<(), FileHistory>::new().unwrap();
// Attempt to load history from ~/.deet_history if it exists // Attempt to load history from ~/.deet_history if it exists
let _ = readline.load_history(&history_path); let _ = readline.load_history(&history_path);
@ -296,7 +297,7 @@ impl Debugger {
if line.trim().len() == 0 { if line.trim().len() == 0 {
continue; continue;
} }
self.readline.add_history_entry(line.as_str()); self.readline.add_history_entry(line.as_str()).unwrap();
if let Err(err) = self.readline.save_history(&self.history_path) { if let Err(err) = self.readline.save_history(&self.history_path) {
println!( println!(
"Warning: failed to save history file at {}: {}", "Warning: failed to save history file at {}: {}",

View File

@ -30,7 +30,7 @@ impl From<gimli_wrapper::Error> for Error {
impl DwarfData { impl DwarfData {
pub fn from_file(path: &str) -> Result<DwarfData, Error> { pub fn from_file(path: &str) -> Result<DwarfData, Error> {
let file = fs::File::open(path).or(Err(Error::ErrorOpeningFile))?; let file = fs::File::open(path).or(Err(Error::ErrorOpeningFile))?;
let mmap = unsafe { memmap::Mmap::map(&file).or(Err(Error::ErrorOpeningFile))? }; let mmap = unsafe { memmap2::Mmap::map(&file).or(Err(Error::ErrorOpeningFile))? };
let object = object::File::parse(&*mmap) let object = object::File::parse(&*mmap)
.or_else(|e| Err(gimli_wrapper::Error::ObjectError(e.to_string())))?; .or_else(|e| Err(gimli_wrapper::Error::ObjectError(e.to_string())))?;
let endian = if object.is_little_endian() { let endian = if object.is_little_endian() {

View File

@ -7,7 +7,7 @@
use gimli; use gimli;
use gimli::{UnitOffset, UnitSectionOffset}; use gimli::{UnitOffset, UnitSectionOffset};
use object::Object; use object::{Object, ObjectSection};
use std::borrow; use std::borrow;
//use std::io::{BufWriter, Write}; //use std::io::{BufWriter, Write};
use crate::dwarf_data::{File, Function, Line, Location, Type, Variable}; use crate::dwarf_data::{File, Function, Line, Location, Type, Variable};
@ -19,9 +19,12 @@ use std::{io, path};
pub fn load_file(object: &object::File, endian: gimli::RunTimeEndian) -> Result<Vec<File>, Error> { pub fn load_file(object: &object::File, endian: gimli::RunTimeEndian) -> Result<Vec<File>, Error> {
// Load a section and return as `Cow<[u8]>`. // Load a section and return as `Cow<[u8]>`.
let load_section = |id: gimli::SectionId| -> Result<borrow::Cow<[u8]>, gimli::Error> { let load_section = |id: gimli::SectionId| -> Result<borrow::Cow<[u8]>, gimli::Error> {
Ok(object match object.section_by_name(id.name()) {
.section_data_by_name(id.name()) Some(ref section) => Ok(section
.unwrap_or(borrow::Cow::Borrowed(&[][..]))) .uncompressed_data()
.unwrap_or(borrow::Cow::Borrowed(&[][..]))),
None => Ok(borrow::Cow::Borrowed(&[][..])),
}
}; };
// Load a supplementary section. We don't have a supplementary object file, // Load a supplementary section. We don't have a supplementary object file,
// so always return an empty slice. // so always return an empty slice.
@ -259,7 +262,7 @@ pub enum DebugValue {
#[derive(Debug, Clone, PartialEq, Eq)] #[derive(Debug, Clone, PartialEq, Eq)]
pub enum Error { pub enum Error {
GimliError(gimli::Error), GimliError(gimli::Error),
Addr2lineError(addr2line::gimli::Error), // Addr2lineError(addr2line::gimli::Error),
ObjectError(String), ObjectError(String),
IoError, IoError,
} }
@ -270,11 +273,11 @@ impl From<gimli::Error> for Error {
} }
} }
impl From<addr2line::gimli::Error> for Error { // impl From<addr2line::gimli::Error> for Error {
fn from(err: addr2line::gimli::Error) -> Self { // fn from(err: addr2line::gimli::Error) -> Self {
Error::Addr2lineError(err) // Error::Addr2lineError(err)
} // }
} // }
impl From<io::Error> for Error { impl From<io::Error> for Error {
fn from(_: io::Error) -> Self { fn from(_: io::Error) -> Self {

View File

@ -3,10 +3,10 @@ use nix::sys::signal;
use nix::sys::signal::Signal; use nix::sys::signal::Signal;
use nix::sys::wait::{waitpid, WaitPidFlag, WaitStatus}; use nix::sys::wait::{waitpid, WaitPidFlag, WaitStatus};
use nix::unistd::Pid; use nix::unistd::Pid;
use std::mem::size_of;
use std::os::unix::process::CommandExt; use std::os::unix::process::CommandExt;
use std::process::Child; use std::process::Child;
use std::process::Command; use std::process::Command;
use std::mem::size_of;
use crate::dwarf_data::DwarfData; use crate::dwarf_data::DwarfData;
#[derive(Debug)] #[derive(Debug)]
@ -134,11 +134,13 @@ impl Inferior {
let orig_byte = (word >> 8 * byte_offset) & 0xff; let orig_byte = (word >> 8 * byte_offset) & 0xff;
let masked_word = word & !(0xff << 8 * byte_offset); let masked_word = word & !(0xff << 8 * byte_offset);
let updated_word = masked_word | ((val as u64) << 8 * byte_offset); let updated_word = masked_word | ((val as u64) << 8 * byte_offset);
ptrace::write( unsafe {
self.pid(), ptrace::write(
aligned_addr as ptrace::AddressType, self.pid(),
updated_word as *mut std::ffi::c_void, aligned_addr as ptrace::AddressType,
)?; updated_word as *mut std::ffi::c_void,
)?;
}
Ok(orig_byte as u8) Ok(orig_byte as u8)
} }
@ -147,7 +149,7 @@ impl Inferior {
self.wait(None) self.wait(None)
} }
pub fn restore_rip(&mut self, rip: u64) -> Result<(), nix::Error>{ pub fn restore_rip(&mut self, rip: u64) -> Result<(), nix::Error> {
let mut regs = ptrace::getregs(self.pid()).unwrap(); let mut regs = ptrace::getregs(self.pid()).unwrap();
regs.rip = rip; regs.rip = rip;
ptrace::setregs(self.pid(), regs) ptrace::setregs(self.pid(), regs)