linux: Add FindMappingWithName to MemoryMap

Bug: crashpad:30
Change-Id: I5e03dc14e3cd1e09ac45cba97922499ec48ea389
Reviewed-on: https://chromium-review.googlesource.com/532753
Commit-Queue: Joshua Peraza <jperaza@chromium.org>
Reviewed-by: Mark Mentovai <mark@chromium.org>
This commit is contained in:
Joshua Peraza 2017-06-13 08:39:46 -07:00 committed by Commit Bot
parent 8e2e805fa5
commit 1c0c305bc9
3 changed files with 22 additions and 3 deletions

View File

@ -255,4 +255,16 @@ const MemoryMap::Mapping* MemoryMap::FindMapping(LinuxVMAddress address) const {
return nullptr;
}
const MemoryMap::Mapping* MemoryMap::FindMappingWithName(
const std::string& name) const {
INITIALIZATION_STATE_DCHECK_VALID(initialized_);
for (const auto& mapping : mappings_) {
if (mapping.name == name) {
return &mapping;
}
}
return nullptr;
}
} // namespace crashpad

View File

@ -63,11 +63,17 @@ class MemoryMap {
//! \return `true` on success, `false` on failure with a message logged.
bool Initialize(pid_t pid);
//! \return The Mapping containing \a address. The caller does not take
//! ownership of this object. It is scoped to the lifetime of the
//! MemoryMap object that it was obtained from.
//! \return The Mapping containing \a address or `nullptr` if no match is
//! found. The caller does not take ownership of this object. It is scoped
//! to the lifetime of the MemoryMap object that it was obtained from.
const Mapping* FindMapping(LinuxVMAddress address) const;
//! \return The Mapping with the lowest base address whose name is \a name or
//! `nullptr` if no match is found. The caller does not take ownership of
//! this object. It is scoped to the lifetime of the MemoryMap object that
//! it was obtained from.
const Mapping* FindMappingWithName(const std::string& name) const;
private:
std::vector<Mapping> mappings_;
InitializationStateDcheck initialized_;

View File

@ -149,6 +149,7 @@ class MapChildTest : public Multiprocess {
<< ErrnoMessage("stat");
EXPECT_EQ(mapping->device, file_stat.st_dev);
EXPECT_EQ(mapping->inode, file_stat.st_ino);
EXPECT_EQ(map.FindMappingWithName(mapping->name), mapping);
}
void MultiprocessChild() override {