mirror of
https://github.com/RGBCube/serenity
synced 2025-07-23 13:17:36 +00:00
Everywhere: Move shared library checks into a common function
While we're at it, unify the various different conditions that are scattered accross the codebase.
This commit is contained in:
parent
31c634be5a
commit
80cb44afae
7 changed files with 25 additions and 6 deletions
|
@ -5,6 +5,7 @@
|
|||
*/
|
||||
|
||||
#include "Process.h"
|
||||
#include <LibCore/File.h>
|
||||
|
||||
namespace Profiler {
|
||||
|
||||
|
@ -90,7 +91,7 @@ void LibraryMetadata::handle_mmap(FlatPtr base, size_t size, const String& name)
|
|||
} else {
|
||||
String path_string = path.to_string();
|
||||
String full_path;
|
||||
if (path_string.ends_with(".so"sv))
|
||||
if (Core::File::looks_like_shared_library(path_string))
|
||||
full_path = String::formatted("/usr/lib/{}", path);
|
||||
else
|
||||
full_path = path_string;
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
#include <AK/LexicalPath.h>
|
||||
#include <AK/MappedFile.h>
|
||||
#include <AK/StringUtils.h>
|
||||
#include <LibCore/File.h>
|
||||
#include <LibELF/AuxiliaryVector.h>
|
||||
#include <LibELF/Image.h>
|
||||
#include <LibELF/Validation.h>
|
||||
|
@ -395,7 +396,7 @@ MmapRegion const* Emulator::load_library_from_address(FlatPtr address)
|
|||
return {};
|
||||
|
||||
String lib_path = lib_name;
|
||||
if (lib_name.ends_with(".so"))
|
||||
if (Core::File::looks_like_shared_library(lib_name))
|
||||
lib_path = String::formatted("/usr/lib/{}", lib_path);
|
||||
|
||||
if (!m_dynamic_library_cache.contains(lib_path)) {
|
||||
|
@ -432,7 +433,10 @@ Optional<Emulator::SymbolInfo> Emulator::symbol_at(FlatPtr address)
|
|||
auto lib_name = address_region->lib_name();
|
||||
auto const* first_region = (lib_name.is_null() || lib_name.is_empty()) ? address_region : first_region_for_object(lib_name);
|
||||
VERIFY(first_region);
|
||||
auto lib_path = lib_name.ends_with(".so"sv) ? String::formatted("/usr/lib/{}", lib_name) : lib_name;
|
||||
auto lib_path = lib_name;
|
||||
if (Core::File::looks_like_shared_library(lib_name)) {
|
||||
lib_path = String::formatted("/usr/lib/{}", lib_name);
|
||||
}
|
||||
|
||||
auto it = m_dynamic_library_cache.find(lib_path);
|
||||
auto const& elf = it->value.debug_info->elf();
|
||||
|
|
|
@ -147,6 +147,16 @@ bool File::is_link(String const& filename)
|
|||
return S_ISLNK(st.st_mode);
|
||||
}
|
||||
|
||||
bool File::looks_like_shared_library() const
|
||||
{
|
||||
return File::looks_like_shared_library(m_filename);
|
||||
}
|
||||
|
||||
bool File::looks_like_shared_library(const String& filename)
|
||||
{
|
||||
return filename.ends_with(".so"sv) || filename.contains(".so."sv);
|
||||
}
|
||||
|
||||
bool File::exists(String const& filename)
|
||||
{
|
||||
struct stat st;
|
||||
|
|
|
@ -32,6 +32,9 @@ public:
|
|||
bool is_link() const;
|
||||
static bool is_link(String const& filename);
|
||||
|
||||
bool looks_like_shared_library() const;
|
||||
static bool looks_like_shared_library(String const& filename);
|
||||
|
||||
static bool exists(String const& filename);
|
||||
static ErrorOr<size_t> size(String const& filename);
|
||||
static bool ensure_parent_directories(String const& path);
|
||||
|
|
|
@ -20,7 +20,7 @@ namespace Coredump {
|
|||
ELFObjectInfo const* Backtrace::object_info_for_region(ELF::Core::MemoryRegionInfo const& region)
|
||||
{
|
||||
auto path = region.object_name();
|
||||
if (!path.starts_with('/') && (path.ends_with(".so"sv) || path.contains(".so."sv)))
|
||||
if (!path.starts_with('/') && Core::File::looks_like_shared_library(path))
|
||||
path = LexicalPath::join("/usr/lib", path).string();
|
||||
|
||||
auto maybe_ptr = m_debug_info_cache.get(path);
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#include <AK/JsonObject.h>
|
||||
#include <AK/JsonValue.h>
|
||||
#include <LibCompress/Gzip.h>
|
||||
#include <LibCore/File.h>
|
||||
#include <LibCoredump/Reader.h>
|
||||
#include <signal_numbers.h>
|
||||
#include <string.h>
|
||||
|
@ -273,7 +274,7 @@ const Reader::LibraryData* Reader::library_containing(FlatPtr address) const
|
|||
auto name = region->object_name();
|
||||
|
||||
String path;
|
||||
if (name.ends_with(".so"))
|
||||
if (Core::File::looks_like_shared_library(name))
|
||||
path = String::formatted("/usr/lib/{}", name);
|
||||
else {
|
||||
path = name;
|
||||
|
|
|
@ -433,7 +433,7 @@ void DebugSession::update_loaded_libs()
|
|||
return IterationDecision::Continue;
|
||||
|
||||
String lib_name = object_path.value();
|
||||
if (lib_name.ends_with(".so"))
|
||||
if (Core::File::looks_like_shared_library(lib_name))
|
||||
lib_name = LexicalPath::basename(object_path.value());
|
||||
|
||||
FlatPtr base_address = entry.as_object().get("address").to_addr();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue