summaryrefslogtreecommitdiff
path: root/Userland/Libraries
diff options
context:
space:
mode:
authorItamar <itamar8910@gmail.com>2021-09-09 12:25:02 +0300
committerBrian Gianforcaro <b.gianfo@gmail.com>2021-09-10 13:57:34 +0000
commitc78838c2d247d9e838095f15faebb8a404c07242 (patch)
tree687afaabdd56534d2871a8a51378c18b4a4373da /Userland/Libraries
parent679bde06edf301e920f2fc3ede3be37a910a3ebd (diff)
downloadserenity-c78838c2d247d9e838095f15faebb8a404c07242.zip
LibDebug: Use the first memory segment of a library as the ELF's base
When parsing the libraries of the debugee process, we previously assumed that the region that's called `<library name>: .text` was also the base of the ELF file. However, since we started linking with `-z separate-code`, this is no longer the case - our executables have a read-only segment before the .text segment, and that segment is actually at the base of the ELF. This broke inserting breakpoints with the debugger since they were inserted at a wrong offset. To fix that, we now use the address of the first segment in the memory map for the ELF's base address (The memory map is sorted by address).
Diffstat (limited to 'Userland/Libraries')
-rw-r--r--Userland/Libraries/LibDebug/DebugSession.cpp15
1 files changed, 9 insertions, 6 deletions
diff --git a/Userland/Libraries/LibDebug/DebugSession.cpp b/Userland/Libraries/LibDebug/DebugSession.cpp
index ae7a32d01b..9fec825a22 100644
--- a/Userland/Libraries/LibDebug/DebugSession.cpp
+++ b/Userland/Libraries/LibDebug/DebugSession.cpp
@@ -409,13 +409,13 @@ void DebugSession::update_loaded_libs()
VERIFY(json.has_value());
auto vm_entries = json.value().as_array();
- Regex<PosixExtended> re("(.+): \\.text");
+ Regex<PosixExtended> segment_name_re("(.+): ");
- auto get_path_to_object = [&re](String const& vm_name) -> Optional<String> {
+ auto get_path_to_object = [&segment_name_re](String const& vm_name) -> Optional<String> {
if (vm_name == "/usr/lib/Loader.so")
return vm_name;
RegexResult result;
- auto rc = re.search(vm_name, result);
+ auto rc = segment_name_re.search(vm_name, result);
if (!rc)
return {};
auto lib_name = result.capture_group_matches.at(0).at(0).view.string_view().to_string();
@@ -440,14 +440,17 @@ void DebugSession::update_loaded_libs()
if (lib_name == "libgcc_s.so")
return IterationDecision::Continue;
- if (m_loaded_libraries.contains(lib_name))
+ FlatPtr base_address = entry.as_object().get("address").to_addr();
+ if (auto it = m_loaded_libraries.find(lib_name); it != m_loaded_libraries.end()) {
+ // We expect the VM regions to be sorted by address.
+ VERIFY(base_address >= it->value->base_address);
return IterationDecision::Continue;
+ }
- auto file_or_error = MappedFile ::map(object_path.value());
+ auto file_or_error = MappedFile::map(object_path.value());
if (file_or_error.is_error())
return IterationDecision::Continue;
- FlatPtr base_address = entry.as_object().get("address").to_addr();
auto image = make<ELF::Image>(file_or_error.value()->bytes());
auto debug_info = make<DebugInfo>(*image, m_source_root, base_address);
auto lib = make<LoadedLibrary>(lib_name, file_or_error.release_value(), move(image), move(debug_info), base_address);