debug_worker/gdb/targets/target_x86_64_qemu/
target_xml.rsuse crate::gdb::arch::x86::X86_64_QEMU;
use crate::gdb::targets::VmTarget;
use gdbstub::target;
use gdbstub::target::TargetError;
use gdbstub::target::TargetResult;
fn copy_to_buf(data: &[u8], buf: &mut [u8]) -> usize {
let len = buf.len().min(data.len());
buf[..len].copy_from_slice(&data[..len]);
len
}
fn copy_range_to_buf(data: &[u8], offset: u64, length: usize, buf: &mut [u8]) -> usize {
let offset = offset as usize;
if offset > data.len() {
return 0;
}
let start = offset;
let end = (offset + length).min(data.len());
copy_to_buf(&data[start..end], buf)
}
impl target::ext::target_description_xml_override::TargetDescriptionXmlOverride
for VmTarget<'_, X86_64_QEMU>
{
fn target_description_xml(
&self,
annex: &[u8],
offset: u64,
length: usize,
buf: &mut [u8],
) -> TargetResult<usize, Self> {
let xml = match annex {
b"target.xml" => TARGET_XML.trim(),
b"i386-64bit.xml" => include_str!("./i386-64bit.xml").trim(),
_ => return Err(TargetError::NonFatal),
};
Ok(copy_range_to_buf(
xml.trim().as_bytes(),
offset,
length,
buf,
))
}
}
const TARGET_XML: &str = r#"
<?xml version="1.0"?><!DOCTYPE target SYSTEM "gdb-target.dtd"><target><architecture>i386:x86-64</architecture><xi:include href="i386-64bit.xml"/></target>
"#;