[Lldb-commits] [lldb] r349267 - Remove /proc/pid/maps parsing code from NativeProcessLinux
Pavel Labath via lldb-commits
lldb-commits at lists.llvm.org
Sat Dec 15 05:38:16 PST 2018
Author: labath
Date: Sat Dec 15 05:38:16 2018
New Revision: 349267
URL: http://llvm.org/viewvc/llvm-project?rev=349267&view=rev
Log:
Remove /proc/pid/maps parsing code from NativeProcessLinux
A utility function doing this was added in r349182, so use that instead.
Modified:
lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.cpp
Modified: lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.cpp?rev=349267&r1=349266&r2=349267&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.cpp (original)
+++ lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.cpp Sat Dec 15 05:38:16 2018
@@ -45,6 +45,7 @@
#include "NativeThreadLinux.h"
#include "Plugins/Process/POSIX/ProcessPOSIXLog.h"
+#include "Plugins/Process/Utility/LinuxProcMaps.h"
#include "Procfs.h"
#include <linux/unistd.h>
@@ -1232,90 +1233,6 @@ Status NativeProcessLinux::Kill() {
return error;
}
-static Status
-ParseMemoryRegionInfoFromProcMapsLine(llvm::StringRef &maps_line,
- MemoryRegionInfo &memory_region_info) {
- memory_region_info.Clear();
-
- StringExtractor line_extractor(maps_line);
-
- // Format: {address_start_hex}-{address_end_hex} perms offset dev inode
- // pathname perms: rwxp (letter is present if set, '-' if not, final
- // character is p=private, s=shared).
-
- // Parse out the starting address
- lldb::addr_t start_address = line_extractor.GetHexMaxU64(false, 0);
-
- // Parse out hyphen separating start and end address from range.
- if (!line_extractor.GetBytesLeft() || (line_extractor.GetChar() != '-'))
- return Status(
- "malformed /proc/{pid}/maps entry, missing dash between address range");
-
- // Parse out the ending address
- lldb::addr_t end_address = line_extractor.GetHexMaxU64(false, start_address);
-
- // Parse out the space after the address.
- if (!line_extractor.GetBytesLeft() || (line_extractor.GetChar() != ' '))
- return Status(
- "malformed /proc/{pid}/maps entry, missing space after range");
-
- // Save the range.
- memory_region_info.GetRange().SetRangeBase(start_address);
- memory_region_info.GetRange().SetRangeEnd(end_address);
-
- // Any memory region in /proc/{pid}/maps is by definition mapped into the
- // process.
- memory_region_info.SetMapped(MemoryRegionInfo::OptionalBool::eYes);
-
- // Parse out each permission entry.
- if (line_extractor.GetBytesLeft() < 4)
- return Status("malformed /proc/{pid}/maps entry, missing some portion of "
- "permissions");
-
- // Handle read permission.
- const char read_perm_char = line_extractor.GetChar();
- if (read_perm_char == 'r')
- memory_region_info.SetReadable(MemoryRegionInfo::OptionalBool::eYes);
- else if (read_perm_char == '-')
- memory_region_info.SetReadable(MemoryRegionInfo::OptionalBool::eNo);
- else
- return Status("unexpected /proc/{pid}/maps read permission char");
-
- // Handle write permission.
- const char write_perm_char = line_extractor.GetChar();
- if (write_perm_char == 'w')
- memory_region_info.SetWritable(MemoryRegionInfo::OptionalBool::eYes);
- else if (write_perm_char == '-')
- memory_region_info.SetWritable(MemoryRegionInfo::OptionalBool::eNo);
- else
- return Status("unexpected /proc/{pid}/maps write permission char");
-
- // Handle execute permission.
- const char exec_perm_char = line_extractor.GetChar();
- if (exec_perm_char == 'x')
- memory_region_info.SetExecutable(MemoryRegionInfo::OptionalBool::eYes);
- else if (exec_perm_char == '-')
- memory_region_info.SetExecutable(MemoryRegionInfo::OptionalBool::eNo);
- else
- return Status("unexpected /proc/{pid}/maps exec permission char");
-
- line_extractor.GetChar(); // Read the private bit
- line_extractor.SkipSpaces(); // Skip the separator
- line_extractor.GetHexMaxU64(false, 0); // Read the offset
- line_extractor.GetHexMaxU64(false, 0); // Read the major device number
- line_extractor.GetChar(); // Read the device id separator
- line_extractor.GetHexMaxU64(false, 0); // Read the major device number
- line_extractor.SkipSpaces(); // Skip the separator
- line_extractor.GetU64(0, 10); // Read the inode number
-
- line_extractor.SkipSpaces();
- const char *name = line_extractor.Peek();
- if (name)
- memory_region_info.SetName(name);
-
- return Status();
-}
-
Status NativeProcessLinux::GetMemoryRegionInfo(lldb::addr_t load_addr,
MemoryRegionInfo &range_info) {
// FIXME review that the final memory region returned extends to the end of
@@ -1401,23 +1318,23 @@ Status NativeProcessLinux::PopulateMemor
m_supports_mem_region = LazyBool::eLazyBoolNo;
return BufferOrError.getError();
}
- StringRef Rest = BufferOrError.get()->getBuffer();
- while (! Rest.empty()) {
- StringRef Line;
- std::tie(Line, Rest) = Rest.split('\n');
- MemoryRegionInfo info;
- const Status parse_error =
- ParseMemoryRegionInfoFromProcMapsLine(Line, info);
- if (parse_error.Fail()) {
- LLDB_LOG(log, "failed to parse proc maps line '{0}': {1}", Line,
- parse_error);
- m_supports_mem_region = LazyBool::eLazyBoolNo;
- return parse_error;
- }
- FileSpec file_spec(info.GetName().GetCString());
- FileSystem::Instance().Resolve(file_spec);
- m_mem_region_cache.emplace_back(info, file_spec);
- }
+ Status Result;
+ ParseLinuxMapRegions(BufferOrError.get()->getBuffer(),
+ [&](const MemoryRegionInfo &Info, const Status &ST) {
+ if (ST.Success()) {
+ FileSpec file_spec(Info.GetName().GetCString());
+ FileSystem::Instance().Resolve(file_spec);
+ m_mem_region_cache.emplace_back(Info, file_spec);
+ return true;
+ } else {
+ m_supports_mem_region = LazyBool::eLazyBoolNo;
+ LLDB_LOG(log, "failed to parse proc maps: {0}", ST);
+ Result = ST;
+ return false;
+ }
+ });
+ if (Result.Fail())
+ return Result;
if (m_mem_region_cache.empty()) {
// No entries after attempting to read them. This shouldn't happen if
More information about the lldb-commits
mailing list