13#include "llvm/ADT/StringRef.h"
20static llvm::Expected<MemoryRegionInfo>
ProcMapError(
const char *msg,
22 return llvm::createStringError(llvm::inconvertibleErrorCode(), msg,
26static llvm::Expected<MemoryRegionInfo>
42 "malformed /proc/{pid}/%s entry, missing dash between address range",
51 "malformed /proc/{pid}/%s entry, missing space after range", maps_kind);
59 region.
SetMapped(MemoryRegionInfo::OptionalBool::eYes);
64 "malformed /proc/{pid}/%s entry, missing some portion of "
69 const char read_perm_char = line_extractor.
GetChar();
70 if (read_perm_char ==
'r')
71 region.
SetReadable(MemoryRegionInfo::OptionalBool::eYes);
72 else if (read_perm_char ==
'-')
73 region.
SetReadable(MemoryRegionInfo::OptionalBool::eNo);
75 return ProcMapError(
"unexpected /proc/{pid}/%s read permission char",
79 const char write_perm_char = line_extractor.
GetChar();
80 if (write_perm_char ==
'w')
81 region.
SetWritable(MemoryRegionInfo::OptionalBool::eYes);
82 else if (write_perm_char ==
'-')
83 region.
SetWritable(MemoryRegionInfo::OptionalBool::eNo);
85 return ProcMapError(
"unexpected /proc/{pid}/%s write permission char",
89 const char exec_perm_char = line_extractor.
GetChar();
90 if (exec_perm_char ==
'x')
92 else if (exec_perm_char ==
'-')
95 return ProcMapError(
"unexpected /proc/{pid}/%s exec permission char",
99 const char sharing_char = line_extractor.
GetChar();
100 if (sharing_char ==
's')
101 region.
SetShared(MemoryRegionInfo::OptionalBool::eYes);
102 else if (sharing_char ==
'p')
103 region.
SetShared(MemoryRegionInfo::OptionalBool::eNo);
105 region.
SetShared(MemoryRegionInfo::OptionalBool::eDontKnow);
113 line_extractor.
GetU64(0, 10);
116 const char *name = line_extractor.
Peek();
125 llvm::StringRef lines(linux_map);
126 llvm::StringRef line;
127 while (!lines.empty()) {
128 std::tie(line, lines) = lines.split(
'\n');
148 llvm::StringRef lines(linux_smap);
149 llvm::StringRef line;
150 std::optional<MemoryRegionInfo> region;
152 while (lines.size()) {
153 std::tie(line, lines) = lines.split(
'\n');
159 llvm::StringRef name;
160 llvm::StringRef value;
161 std::tie(name, value) = line.split(
':');
164 if (!name.contains(
' ')) {
166 if (name ==
"VmFlags") {
167 if (value.contains(
"mt"))
176 "Found a property line without a corresponding mapping "
190 llvm::Expected<MemoryRegionInfo> new_region =
193 region = *new_region;
196 callback(new_region.takeError());
static llvm::Expected< MemoryRegionInfo > ProcMapError(const char *msg, MapsKind kind)
static llvm::Expected< MemoryRegionInfo > ParseMemoryRegionInfoFromProcMapsLine(llvm::StringRef maps_line, MapsKind maps_kind)
void SetMapped(OptionalBool val)
void SetReadable(OptionalBool val)
void SetExecutable(OptionalBool val)
void SetName(const char *name)
void SetWritable(OptionalBool val)
void SetShared(OptionalBool val)
A class that represents a running process on the host machine.
std::function< bool(llvm::Expected< MemoryRegionInfo >)> LinuxMapCallback
void ParseLinuxMapRegions(llvm::StringRef linux_map, LinuxMapCallback const &callback)
void ParseLinuxSMapRegions(llvm::StringRef linux_smap, LinuxMapCallback const &callback)
void SetRangeEnd(BaseType end)
void SetRangeBase(BaseType b)
Set the start value for the range, and keep the same size.