Make "./a.out" entry the first in rmap list

This fixes a regression in gdb where sometimes it decides to ignore the
first entry in the list.
This commit is contained in:
oddcoder
2020-05-03 12:35:01 +02:00
parent 67be05d3a3
commit 850dfd971b
2 changed files with 15 additions and 2 deletions
+14 -1
View File
@@ -52,6 +52,16 @@ impl RTLDDebug {
}
return;
}
pub fn insert_first(&mut self, l_addr: usize, name: &str, l_ld: usize) {
if self.r_map.is_null() {
self.r_map = LinkMap::new_with_args(l_addr, name, l_ld);
} else {
let tmp = self.r_map;
self.r_map = LinkMap::new_with_args(l_addr, name, l_ld);
unsafe { (*self.r_map).link(&mut *tmp) };
}
return;
}
}
#[repr(C)]
@@ -80,7 +90,10 @@ impl LinkMap {
});
Box::into_raw(map)
}
fn link(&mut self, map: &mut LinkMap) {
map.l_prev = self as *mut LinkMap;
self.l_next = map as *mut LinkMap;
}
fn new_with_args(l_addr: usize, name: &str, l_ld: usize) -> *mut Self {
let map = LinkMap::new();
unsafe {
+1 -1
View File
@@ -429,7 +429,7 @@ impl Linker {
size,
sys_mman::PROT_READ | sys_mman::PROT_WRITE,
);
_r_debug.insert(addr as usize, &elf_name, addr + l_ld as usize);
_r_debug.insert_first(addr as usize, &elf_name, addr + l_ld as usize);
slice::from_raw_parts_mut(addr as *mut u8, size)
} else {
let size = bounds.1;