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

Method scanMemoryAreaForInterpreterState

src/pystack/_pystack/process.cpp:375–408  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

373}
374
375remote_addr_t
376AbstractProcessManager::scanMemoryAreaForInterpreterState(const VirtualMap& map) const
377{
378 void* result = nullptr;
379 size_t size = map.Size();
380 std::vector<char> memory_buffer(size);
381 remote_addr_t base = map.Start();
382 copyMemoryFromProcess(base, size, memory_buffer.data());
383
384 void* upper_bound = (void*)(memory_buffer.data() + size);
385
386 LOG(INFO) << std::showbase << std::hex
387 << "Searching for PyInterpreterState in memory area spanning from " << map.Start()
388 << " to " << map.End();
389
390 for (void** raddr = (void**)memory_buffer.data(); (void*)raddr < upper_bound; raddr++) {
391 if (!isValidInterpreterState((remote_addr_t)*raddr)) {
392 continue;
393 }
394 LOG(DEBUG) << std::hex << std::showbase
395 << "Possible interpreter state referenced by memory segment "
396 << reinterpret_cast<void*>((char*)raddr - (char*)memory_buffer.data() + (char*)base)
397 << " (offset " << reinterpret_cast<void*>((char*)raddr - (char*)memory_buffer.data())
398 << " ) -> addr " << static_cast<void*>((char*)raddr);
399 result = *raddr;
400 break;
401 }
402 if (result == nullptr) {
403 LOG(INFO) << std::showbase << std::hex
404 << "Could not find a valid PyInterpreterState in memory area spanning from "
405 << map.Start() << " to " << map.End();
406 }
407 return (remote_addr_t)result;
408}
409
410remote_addr_t
411AbstractProcessManager::scanMemoryAreaForDebugOffsets(const VirtualMap& map) const

Callers

nothing calls this directly

Calls 4

LOGClass · 0.85
SizeMethod · 0.80
StartMethod · 0.80
EndMethod · 0.80

Tested by

no test coverage detected