Verified Commit a40315f9 authored by jD91mZM2's avatar jD91mZM2

Implement qXfer:features:...:target.xml

GDB can now read target.xml on its own :)
parent 1f6aeb30
use nix
eval "$(lorri direnv)"
[submodule "rust-gdb-remote-protocol"]
path = rust-gdb-remote-protocol
url = git@github.com:jD91mZM2/rust-gdb-remote-protocol.git
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
[[package]]
name = "aho-corasick"
version = "0.7.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"memchr 2.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "ansi_term"
version = "0.11.0"
......@@ -41,12 +49,24 @@ dependencies = [
"vec_map 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "env_logger"
version = "0.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"atty 0.2.13 (registry+https://github.com/rust-lang/crates.io-index)",
"humantime 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
"regex 1.3.9 (registry+https://github.com/rust-lang/crates.io-index)",
"termcolor 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "gdb-remote-protocol"
version = "0.1.0"
source = "git+https://github.com/luser/rust-gdb-remote-protocol?rev=565ab0c0ac189c82b0e7df217860599fc1ae6287#565ab0c0ac189c82b0e7df217860599fc1ae6287"
dependencies = [
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
"memchr 2.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
"nom 3.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
"strum 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
"strum_macros 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
......@@ -56,9 +76,11 @@ dependencies = [
name = "gdbserver"
version = "0.1.0"
dependencies = [
"gdb-remote-protocol 0.1.0 (git+https://github.com/luser/rust-gdb-remote-protocol?rev=565ab0c0ac189c82b0e7df217860599fc1ae6287)",
"env_logger 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)",
"gdb-remote-protocol 0.1.0",
"libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)",
"memchr 2.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
"memchr 2.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
"structopt 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)",
]
......@@ -70,6 +92,19 @@ dependencies = [
"unicode-segmentation 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "humantime"
version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"quick-error 1.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "lazy_static"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "libc"
version = "0.2.62"
......@@ -93,7 +128,7 @@ dependencies = [
[[package]]
name = "memchr"
version = "2.2.1"
version = "2.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
......@@ -112,6 +147,11 @@ dependencies = [
"unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "quick-error"
version = "1.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "quote"
version = "0.3.15"
......@@ -125,6 +165,22 @@ dependencies = [
"proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "regex"
version = "1.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"aho-corasick 0.7.10 (registry+https://github.com/rust-lang/crates.io-index)",
"memchr 2.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
"regex-syntax 0.6.18 (registry+https://github.com/rust-lang/crates.io-index)",
"thread_local 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "regex-syntax"
version = "0.6.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "strsim"
version = "0.8.0"
......@@ -192,6 +248,14 @@ dependencies = [
"unicode-xid 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "termcolor"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"winapi-util 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "textwrap"
version = "0.11.0"
......@@ -200,6 +264,14 @@ dependencies = [
"unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "thread_local"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "unicode-segmentation"
version = "1.3.0"
......@@ -239,27 +311,41 @@ name = "winapi-i686-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "winapi-util"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[metadata]
"checksum aho-corasick 0.7.10 (registry+https://github.com/rust-lang/crates.io-index)" = "8716408b8bc624ed7f65d223ddb9ac2d044c0547b6fa4b0d554f3a9540496ada"
"checksum ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b"
"checksum atty 0.2.13 (registry+https://github.com/rust-lang/crates.io-index)" = "1803c647a3ec87095e7ae7acfca019e98de5ec9a7d01343f611cf3152ed71a90"
"checksum bitflags 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3d155346769a6855b86399e9bc3814ab343cd3d62c7e985113d46a0ec3c281fd"
"checksum cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "b486ce3ccf7ffd79fdeb678eac06a9e6c09fc88d33836340becb8fffe87c5e33"
"checksum clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5067f5bb2d80ef5d68b4c87db81601f0b75bca627bc2ef76b141d7b846a3c6d9"
"checksum gdb-remote-protocol 0.1.0 (git+https://github.com/luser/rust-gdb-remote-protocol?rev=565ab0c0ac189c82b0e7df217860599fc1ae6287)" = "<none>"
"checksum env_logger 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "44533bbbb3bb3c1fa17d9f2e4e38bbbaf8396ba82193c4cb1b6445d711445d36"
"checksum heck 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "20564e78d53d2bb135c343b3f47714a56af2061f1c928fdb541dc7b9fdd94205"
"checksum humantime 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "df004cfca50ef23c36850aaaa59ad52cc70d0e90243c3c7737a4dd32dc7a3c4f"
"checksum lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
"checksum libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)" = "34fcd2c08d2f832f376f4173a231990fa5aef4e99fb569867318a227ef4c06ba"
"checksum log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)" = "14b6052be84e6b71ab17edffc2eeabf5c2c3ae1fdb464aae35ac50c67a44e1f7"
"checksum memchr 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "148fab2e51b4f1cfc66da2a7c32981d1d3c083a803978268bb11fe4b86925e7a"
"checksum memchr 2.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "88579771288728879b57485cc7d6b07d648c9f0141eb955f8ab7f9d45394468e"
"checksum memchr 2.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3728d817d99e5ac407411fa471ff9800a778d88a24685968b36824eaf4bee400"
"checksum nom 3.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "05aec50c70fd288702bcd93284a8444607f3292dbdf2a30de5ea5dcdbe72287b"
"checksum proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)" = "cf3d2011ab5c909338f7887f4fc896d35932e29146c12c8d01da6b22a80ba759"
"checksum quick-error 1.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0"
"checksum quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6e920b65c65f10b2ae65c831a81a073a89edd28c7cce89475bff467ab4167a"
"checksum quote 0.6.13 (registry+https://github.com/rust-lang/crates.io-index)" = "6ce23b6b870e8f94f81fb0a363d65d86675884b34a09043c81e5562f11c1f8e1"
"checksum regex 1.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "9c3780fcf44b193bc4d09f36d2a3c87b251da4a046c87795a0d35f4f927ad8e6"
"checksum regex-syntax 0.6.18 (registry+https://github.com/rust-lang/crates.io-index)" = "26412eb97c6b088a6997e05f69403a802a92d520de2f8e63c2b65f9e0f47c4e8"
"checksum strsim 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a"
"checksum structopt 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)" = "16c2cdbf9cc375f15d1b4141bc48aeef444806655cd0e904207edc8d68d86ed7"
"checksum structopt-derive 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)" = "53010261a84b37689f9ed7d395165029f9cc7abb9f56bbfe86bee2597ed25107"
......@@ -268,7 +354,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum syn 0.11.11 (registry+https://github.com/rust-lang/crates.io-index)" = "d3b891b9015c88c576343b9b3e41c2c11a51c219ef067b264bd9c8aa9b441dad"
"checksum syn 0.15.44 (registry+https://github.com/rust-lang/crates.io-index)" = "9ca4b3b69a77cbe1ffc9e198781b7acb0c7365a883670e8f1c1bc66fba79a5c5"
"checksum synom 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a393066ed9010ebaed60b9eafa373d4b1baac186dd7e008555b0f702b51945b6"
"checksum termcolor 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bb6bfa289a4d7c5766392812c0a1f4c1ba45afa1ad47803c11e1f407d846d75f"
"checksum textwrap 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060"
"checksum thread_local 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d40c6d1b69745a6ec6fb1ca717914848da4b44ae29d9b3080cbee91d72a69b14"
"checksum unicode-segmentation 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1967f4cdfc355b37fd76d2a954fb2ed3871034eb4f26d60537d88795cfc332a9"
"checksum unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "882386231c45df4700b275c7ff55b6f3698780a650026380e72dabe76fa46526"
"checksum unicode-xid 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "8c1f860d7d29cf02cb2f3f359fd35991af3d30bac52c57d265a3c461074cb4dc"
......@@ -276,4 +364,5 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum vec_map 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "05c78687fb1a80548ae3250346c3db86a80a7cdd77bda190189f2d0a0987c81a"
"checksum winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)" = "f10e386af2b13e47c89e7236a7a14a086791a2b88ebad6df9bf42040195cf770"
"checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
"checksum winapi-util 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178"
"checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
......@@ -5,7 +5,9 @@ authors = ["jD91mZM2 <me@krake.one>"]
edition = "2018"
[dependencies]
gdb-remote-protocol = { git = "https://github.com/luser/rust-gdb-remote-protocol", rev = "565ab0c0ac189c82b0e7df217860599fc1ae6287" }
gdb-remote-protocol = { path = "rust-gdb-remote-protocol" }
structopt = "0.2.18"
memchr = "2.2.1"
libc = "0.2.62"
env_logger = "0.7.1"
log = "0.4.8"
Subproject commit 74043ee893bf00d25f8b3af05b2e362ad328a690
{ pkgs ? import <nixpkgs> {} }:
let
gdb-init = pkgs.writers.writeBashBin "gdb" ''
${pkgs.gdb}/bin/gdb \
-ex "set tdesc filename ${./target-desc.xml}" \
"$@"
'';
gdb-test = pkgs.writers.writeBashBin "gdb-test" ''
${gdb-init}/bin/gdb \
-ex "set debug remote 1" \
......@@ -13,5 +8,5 @@ let
"$@"
'';
in pkgs.mkShell {
nativeBuildInputs = [ gdb-init gdb-test ];
nativeBuildInputs = [ gdb-test ];
}
use std::{cmp::min, borrow::Cow, net::TcpListener, convert::TryFrom};
use gdb_remote_protocol::{
Error, Handler, Id, MemoryRegion, ProcessType, StopReason, ThreadId, VCont, VContFeature,
Error, Handler, Id, MemoryRegion, ProcessType, StopReason, ThreadId, VCont,
VContFeature,
};
use log::debug;
use structopt::StructOpt;
use std::{borrow::Cow, net::TcpListener};
mod os;
use os::{Os, Registers, Target};
......@@ -54,6 +56,11 @@ impl Handler for App {
self.tracee.setmem(bytes, address as usize)?;
Ok(())
}
fn query_supported_features(&self) -> Vec<String> {
vec![
String::from("qXfer:features:read+"),
]
}
fn query_supported_vcont(&self) -> Result<Cow<'static, [VContFeature]>> {
Ok(Cow::Borrowed(&[
VContFeature::Continue,
......@@ -76,8 +83,8 @@ impl Handler for App {
fn vcont(&self, actions: Vec<(VCont, Option<ThreadId>)>) -> Result<StopReason> {
for (cmd, id) in &actions {
let id = id.unwrap_or(ThreadId { pid: Id::All, tid: Id::All });
dbg!(id);
dbg!(self.tracee.pid());
debug!("Continuing thread: {:?}", id);
debug!("Continuing PID: {:?}", self.tracee.pid());
match (id.pid, id.tid) {
(Id::Id(pid), _) if pid != self.tracee.pid() => continue,
(_, Id::Id(tid)) if tid != self.tracee.pid() => continue,
......@@ -107,9 +114,28 @@ impl Handler for App {
Ok(self.tracee.status())
}
fn read_bytes(&self, object: String, annex: String, offset: u64, length: u64) -> Result<(Vec<u8>, bool)> {
match (&*object, &*annex) {
("features", "target.xml") => {
let target_xml = include_str!("../target-desc.xml");
let start = usize::try_from(offset).expect("usize < u64");
let end = start.saturating_add(usize::try_from(length).expect("usize < u64"));
if start >= target_xml.len() {
return Ok((Vec::new(), true));
}
let slice = &target_xml[start..min(end, target_xml.len())];
dbg!(slice.len());
Ok((Vec::from(slice), false))
},
_ => Err(Error::Unimplemented),
}
}
}
fn main() -> Result<(), Box<dyn std::error::Error>> {
env_logger::init();
let mut opt = Opt::from_args();
opt.args.insert(0, opt.program.clone());
......
use super::Registers;
use crate::Result;
use log::error;
use std::{
cell::Cell,
ffi::CString,
......@@ -98,21 +100,21 @@ impl super::Target for Os {
if pid == 0 {
// Must not drop any memory, not unwind (panic).
if libc::ptrace(libc::PTRACE_TRACEME) < 0 {
eprintln!(
error!(
"ptrace(PTRACE_TRACEME) failed: {:?}",
io::Error::last_os_error()
);
libc::exit(1);
}
if libc::raise(libc::SIGSTOP) < 0 {
eprintln!("raise(SIGSTOP) failed: {:?}", io::Error::last_os_error());
error!("raise(SIGSTOP) failed: {:?}", io::Error::last_os_error());
libc::exit(1);
}
if libc::execvp(program, args.as_ptr()) < 0 {
eprintln!("execv(...) failed: {:?}", io::Error::last_os_error());
error!("execv(...) failed: {:?}", io::Error::last_os_error());
libc::exit(1);
}
eprintln!("execv(...) should not be able to succeed");
error!("execv(...) should not be able to succeed");
libc::exit(1);
} else {
// Drop variables only the child needed
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment