diff options
author | Rodrigo Tobar <rtobarc@gmail.com> | 2021-09-27 23:54:53 +0800 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-09-28 10:55:14 +0200 |
commit | 12e18e44ae2a12605c2641a89413d7a1050445d4 (patch) | |
tree | b5be29e26f81c02fcf65df17b959b96b2f45af97 /Userland/Libraries/LibSymbolication | |
parent | f4ebcf486787927cabb9cc6b17323f98444483dc (diff) | |
download | serenity-12e18e44ae2a12605c2641a89413d7a1050445d4.zip |
LibSymbolication: Look for libraries under /usr/local/lib
While trying to investigate a problem with the ssl module in the python
port I found that the SystemMonitor Stack tab for a process wouldn't
show the symbols for the libssl and libcrypto shared libraries that are
installed under /usr/local/lib. The main reason for this is that
LibSymbolication didn't look for libraries under /usr/local/lib.
This commit adds support for looking for libraries under /usr/local/lib.
Absolute paths are still respected, and lookup gives precedence to
/usr/lib, just like dynamic linker does.
Diffstat (limited to 'Userland/Libraries/LibSymbolication')
-rw-r--r-- | Userland/Libraries/LibSymbolication/Symbolication.cpp | 37 |
1 files changed, 27 insertions, 10 deletions
diff --git a/Userland/Libraries/LibSymbolication/Symbolication.cpp b/Userland/Libraries/LibSymbolication/Symbolication.cpp index d9635848ff..67a0f8b894 100644 --- a/Userland/Libraries/LibSymbolication/Symbolication.cpp +++ b/Userland/Libraries/LibSymbolication/Symbolication.cpp @@ -4,10 +4,12 @@ * SPDX-License-Identifier: BSD-2-Clause */ +#include <AK/Array.h> #include <AK/Checked.h> #include <AK/JsonArray.h> #include <AK/JsonObject.h> #include <AK/JsonValue.h> +#include <AK/LexicalPath.h> #include <AK/MappedFile.h> #include <LibCore/File.h> #include <LibDebug/DebugInfo.h> @@ -61,24 +63,41 @@ Optional<FlatPtr> kernel_base() Optional<Symbol> symbolicate(String const& path, FlatPtr address) { - if (!s_cache.contains(path)) { - auto mapped_file = MappedFile::map(path); - if (mapped_file.is_error()) { - dbgln("Failed to map {}: {}", path, mapped_file.error().string()); + String full_path = path; + if (!path.starts_with('/')) { + Array<StringView, 2> search_paths { "/usr/lib"sv, "/usr/local/lib"sv }; + bool found = false; + for (auto& search_path : search_paths) { + full_path = LexicalPath::join(search_path, path).string(); + if (Core::File::exists(full_path)) { + found = true; + break; + } + } + if (!found) { + dbgln("Failed to find candidate for {}", path); s_cache.set(path, {}); return {}; } + } + if (!s_cache.contains(full_path)) { + auto mapped_file = MappedFile::map(full_path); + if (mapped_file.is_error()) { + dbgln("Failed to map {}: {}", full_path, mapped_file.error().string()); + s_cache.set(full_path, {}); + return {}; + } auto elf = make<ELF::Image>(mapped_file.value()->bytes()); if (!elf->is_valid()) { - dbgln("ELF not valid: {}", path); - s_cache.set(path, {}); + dbgln("ELF not valid: {}", full_path); + s_cache.set(full_path, {}); return {}; } auto cached_elf = make<CachedELF>(mapped_file.release_value(), make<Debug::DebugInfo>(*elf), move(elf)); - s_cache.set(path, move(cached_elf)); + s_cache.set(full_path, move(cached_elf)); } - auto it = s_cache.find(path); + auto it = s_cache.find(full_path); VERIFY(it != s_cache.end()); auto& cached_elf = it->value; @@ -172,8 +191,6 @@ Vector<Symbol> symbolicate_thread(pid_t pid, pid_t tid) } else if (name.ends_with(": .text") || name.ends_with(": .rodata")) { auto parts = name.split_view(':'); path = parts[0]; - if (!path.starts_with('/')) - path = String::formatted("/usr/lib/{}", path); } else { continue; } |