13 #include "llvm/ADT/StringRef.h"
19 static llvm::Expected<MemoryRegionInfo>
ProcMapError(
const char *msg,
21 return llvm::createStringError(llvm::inconvertibleErrorCode(), msg,
25 static llvm::Expected<MemoryRegionInfo>
41 "malformed /proc/{pid}/%s entry, missing dash between address range",
50 "malformed /proc/{pid}/%s entry, missing space after range", maps_kind);
58 region.
SetMapped(MemoryRegionInfo::OptionalBool::eYes);
63 "malformed /proc/{pid}/%s entry, missing some portion of "
68 const char read_perm_char = line_extractor.
GetChar();
69 if (read_perm_char ==
'r')
70 region.
SetReadable(MemoryRegionInfo::OptionalBool::eYes);
71 else if (read_perm_char ==
'-')
72 region.
SetReadable(MemoryRegionInfo::OptionalBool::eNo);
74 return ProcMapError(
"unexpected /proc/{pid}/%s read permission char",
78 const char write_perm_char = line_extractor.
GetChar();
79 if (write_perm_char ==
'w')
80 region.
SetWritable(MemoryRegionInfo::OptionalBool::eYes);
81 else if (write_perm_char ==
'-')
82 region.
SetWritable(MemoryRegionInfo::OptionalBool::eNo);
84 return ProcMapError(
"unexpected /proc/{pid}/%s write permission char",
88 const char exec_perm_char = line_extractor.
GetChar();
89 if (exec_perm_char ==
'x')
91 else if (exec_perm_char ==
'-')
94 return ProcMapError(
"unexpected /proc/{pid}/%s exec permission char",
98 const char sharing_char = line_extractor.
GetChar();
99 if (sharing_char ==
's')
100 region.
SetShared(MemoryRegionInfo::OptionalBool::eYes);
101 else if (sharing_char ==
'p')
102 region.
SetShared(MemoryRegionInfo::OptionalBool::eNo);
104 region.
SetShared(MemoryRegionInfo::OptionalBool::eDontKnow);
112 line_extractor.
GetU64(0, 10);
115 const char *name = line_extractor.
Peek();
124 llvm::StringRef lines(linux_map);
125 llvm::StringRef line;
126 while (!lines.empty()) {
127 std::tie(line, lines) = lines.split(
'\n');
147 llvm::StringRef lines(linux_smap);
148 llvm::StringRef line;
149 llvm::Optional<MemoryRegionInfo> region;
151 while (lines.size()) {
152 std::tie(line, lines) = lines.split(
'\n');
158 llvm::StringRef name;
159 llvm::StringRef value;
160 std::tie(name, value) = line.split(
':');
163 if (!name.contains(
' ')) {
165 if (name ==
"VmFlags") {
166 if (value.contains(
"mt"))
175 "Found a property line without a corresponding mapping "
189 llvm::Expected<MemoryRegionInfo> new_region =
192 region = *new_region;
195 callback(new_region.takeError());