MCPcopy Create free account
hub / github.com/bloomberg/pystack / readCorefile

Method readCorefile

src/pystack/_pystack/mem.cpp:361–399  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

359}
360
361CorefileRemoteMemoryManager::StatusCode
362CorefileRemoteMemoryManager::readCorefile(int fd, const char* filename) noexcept
363{
364 struct stat fileInfo = {0};
365
366 if (fstat(fd, &fileInfo) == -1) {
367 LOG(ERROR) << "Failed to get a file size for a file " << filename;
368 return StatusCode::ERROR;
369 }
370
371 if (fileInfo.st_size == 0) {
372 LOG(ERROR) << "File " << filename << " is empty";
373 return StatusCode::ERROR;
374 }
375
376 d_corefile_size = fileInfo.st_size;
377
378 void* map = mmap(0, d_corefile_size, PROT_READ, MAP_PRIVATE, fd, 0);
379 if (map == MAP_FAILED) {
380 LOG(ERROR) << "Failed to mmap a file " << filename;
381 return StatusCode::ERROR;
382 }
383
384 d_corefile_data = std::unique_ptr<char, std::function<void(char*)>>(
385 reinterpret_cast<char*>(map),
386 [this](auto addr) {
387 if (munmap(addr, d_corefile_size) == -1) {
388 LOG(ERROR) << "Failed to un-mmap a file " << d_analyzer->d_filename.c_str();
389 }
390 });
391
392 int madvise_result = madvise(d_corefile_data.get(), d_corefile_size, MADV_RANDOM);
393
394 if (madvise_result == -1) {
395 LOG(WARNING) << "Madvise for a file " << filename << " failed";
396 }
397
398 return StatusCode::SUCCESS;
399}
400
401ssize_t
402CorefileRemoteMemoryManager::copyMemoryFromProcess(remote_addr_t addr, size_t size, void* destination)

Callers

nothing calls this directly

Calls 1

LOGClass · 0.85

Tested by

no test coverage detected