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);
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')
72 else if (read_perm_char ==
'-')
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')
82 else if (write_perm_char ==
'-')
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')
102 else if (sharing_char ==
'p')
113 line_extractor.
GetU64(0, 10);
116 const char *name = line_extractor.
Peek();
121 if (llvm::StringRef(name) ==
"[stack]")
123 else if (llvm::StringRef(name) ==
"[heap]")
134 llvm::StringRef lines(linux_map);
135 llvm::StringRef line;
136 while (!lines.empty()) {
137 std::tie(line, lines) = lines.split(
'\n');
157 llvm::StringRef lines(linux_smap);
158 llvm::StringRef line;
159 std::optional<MemoryRegionInfo> region;
161 while (lines.size()) {
162 std::tie(line, lines) = lines.split(
'\n');
168 llvm::StringRef name;
169 llvm::StringRef value;
170 std::tie(name, value) = line.split(
':');
173 if (!name.contains(
' ')) {
175 if (name ==
"VmFlags") {
179 llvm::SmallVector<llvm::StringRef> flags;
180 value.split(flags,
' ', -1,
false);
181 for (llvm::StringRef flag : flags)
184 else if (flag ==
"ss")
186 }
else if (name ==
"ProtectionKey") {
188 if (!value.ltrim().getAsInteger(10, key))
189 region->SetProtectionKey(key);
194 "Found a property line without a corresponding mapping "
208 llvm::Expected<MemoryRegionInfo> new_region =
211 region = *new_region;
214 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 SetReadable(LazyBool val)
void SetName(const char *name)
MemoryRegionInfo & SetIsStackMemory(LazyBool val)
void SetMapped(LazyBool val)
void SetShared(LazyBool val)
void SetExecutable(LazyBool val)
void SetWritable(LazyBool 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.