本文整理汇总了C++中Segment::buffer方法的典型用法代码示例。如果您正苦于以下问题:C++ Segment::buffer方法的具体用法?C++ Segment::buffer怎么用?C++ Segment::buffer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Segment
的用法示例。
在下文中一共展示了Segment::buffer方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: escapeString
std::string
MemoryMap::segmentTitle(const Segment &segment) {
std::string s;
s += (segment.accessibility() & READABLE) !=0 ? "r" : "-";
s += (segment.accessibility() & WRITABLE) !=0 ? "w" : "-";
s += (segment.accessibility() & EXECUTABLE)!=0 ? "x" : "-";
s += (segment.accessibility() & PRIVATE) !=0 ? "p" : "-";
unsigned otherAccess = segment.accessibility() & ~(READABLE|WRITABLE|EXECUTABLE|PRIVATE);
std::string bufname = segment.buffer()->name();
if (bufname.find_first_of(" \t\n()")==std::string::npos)
bufname = "buffer " + bufname;
s += " at " + (bufname+std::string(12, ' ')).substr(0, 12);
s += " + " + StringUtility::addrToString(segment.offset());
if (otherAccess != 0)
s += " access=" + StringUtility::addrToString(otherAccess, 8*sizeof otherAccess);
if (!segment.name().empty()) {
static const size_t limit = 100;
std::string name = escapeString(segment.name());
if (name.size()>limit)
name = name.substr(0, limit-3) + "...";
s += " " + name;
}
return s;
}
示例2: insert
size_t
MemoryMap::insertFile(const std::string &fileName, rose_addr_t startVa, bool writable, std::string segmentName) {
if (segmentName.empty())
segmentName = FileSystem::toString(boost::filesystem::path(fileName).filename());
Segment segment = Segment::fileInstance(fileName, READABLE | (writable?WRITABLE:0), segmentName);
AddressInterval fileInterval = AddressInterval::baseSize(startVa, segment.buffer()->size());
insert(fileInterval, segment);
return fileInterval.size();
}
示例3: runtime_error
//.........这里部分代码省略.........
// Prepare to read subordinate's memory
std::string mapsName = "/proc/" + StringUtility::numberToString(pid) + "/maps";
if (NULL==(local.mapsFile = fopen(mapsName.c_str(), "r")))
throw insertProcessError(locatorString, "cannot open " + mapsName + ": " + strerror(errno));
std::string memName = "/proc/" + StringUtility::numberToString(pid) + "/mem";
if (-1 == (local.memFile = open(memName.c_str(), O_RDONLY)))
throw insertProcessError(locatorString, "cannot open " + memName + ": " + strerror(errno));
// Read each line from the /proc/xxx/maps to figure out what memory is mapped in the subordinate process. The format for
// the part we're interested in is /^([0-9a-f]+)-([0-9a-f]+) ([-r][-w][-x])/ where $1 is the inclusive starting address, $2
// is the exclusive ending address, and $3 are the permissions.
int mapsFileLineNumber = 0;
while (rose_getline(&local.buf, &local.bufsz, local.mapsFile)>0) {
++mapsFileLineNumber;
// Begin address
char *s=local.buf, *rest=s;
errno = 0;
rose_addr_t begin = rose_strtoull(s, &rest, 16);
if (errno!=0 || rest==s || '-'!=*rest) {
throw insertProcessError(locatorString, mapsName + " syntax error for beginning address at line " +
StringUtility::numberToString(mapsFileLineNumber) + ": " + local.buf);
}
// End address
s = rest+1;
rose_addr_t end = rose_strtoull(s, &rest, 16);
if (errno!=0 || rest==s || ' '!=*rest) {
throw insertProcessError(locatorString, mapsName + " syntax error for ending address at line " +
StringUtility::numberToString(mapsFileLineNumber) + ": " + local.buf);
}
if (begin >= end) {
throw insertProcessError(locatorString, mapsName + " invalid address range at line " +
StringUtility::numberToString(mapsFileLineNumber) + ": " + local.buf);
}
// Access permissions
s = ++rest;
if ((s[0]!='r' && s[0]!='-') || (s[1]!='w' && s[1]!='-') || (s[2]!='x' && s[2]!='-')) {
throw insertProcessError(locatorString, mapsName + " invalid access permissions at line " +
StringUtility::numberToString(mapsFileLineNumber) + ": " + local.buf);
}
unsigned accessibility = ('r'==s[0] ? READABLE : 0) | ('w'==s[1] ? WRITABLE : 0) | ('x'==s[2] ? EXECUTABLE : 0);
// Skip over unused fields
for (size_t nSpaces=0; nSpaces<4 && *s; ++s) {
if (isspace(*s))
++nSpaces;
}
while (isspace(*s)) ++s;
// Segment name according to the kernel
std::string kernelSegmentName;
while (*s && !isspace(*s))
kernelSegmentName += *s++;
// Create memory segment, but don't insert it until after we read all the data
std::string segmentName = "proc:" + StringUtility::numberToString(pid);
AddressInterval segmentInterval = AddressInterval::baseSize(begin, end-begin);
Segment segment = Segment::anonymousInstance(segmentInterval.size(), accessibility,
segmentName + "(" + kernelSegmentName + ")");
// Copy data from the subordinate process into our memory segment
if (-1 == lseek(local.memFile, begin, SEEK_SET))
throw insertProcessError(locatorString, memName + " seek failed: " + strerror(errno));
size_t nRemain = segmentInterval.size();
rose_addr_t segmentBufferOffset = 0;
while (nRemain > 0) {
uint8_t chunkBuf[8192];
size_t chunkSize = std::min(nRemain, sizeof chunkBuf);
ssize_t nRead = ::read(local.memFile, chunkBuf, chunkSize);
if (-1==nRead) {
if (EINTR==errno)
continue;
//mlog[WARN] <<strerror(errno) <<" during read from " <<memName <<" for segment " <<kernelSegmentName
// <<" at " <<segmentInterval <<"\n";
segmentName += "[" + boost::to_lower_copy(std::string(strerror(errno))) + "]";
break;
} else if (0==nRead) {
//mlog[WARN] <<"short read from " <<memName <<" for segment " <<kernelSegmentName <<" at " <<segmentInterval <<"\n";
segmentName += "[short read]";
break;
}
rose_addr_t nWrite = segment.buffer()->write(chunkBuf, segmentBufferOffset, nRead);
ASSERT_always_require(nWrite == (rose_addr_t)nRead);
nRemain -= chunkSize;
segmentBufferOffset += chunkSize;
}
if (nRemain > 0) {
// If a read failed, map only what we could read
segmentInterval = AddressInterval::baseSize(segmentInterval.least(), segmentInterval.size()-nRemain);
}
// Insert segment into memory map
if (!segmentInterval.isEmpty())
insert(segmentInterval, segment);
}
#endif
}