Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,24 @@ project(pystack LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)

# Find Python
find_package(Python 3.9 COMPONENTS Interpreter Development.Module REQUIRED)
find_package(Python COMPONENTS Interpreter Development.Module Development.SABIModule REQUIRED)

# Set compiler flags
add_compile_options(-Wall)
add_compile_definitions(_FILE_OFFSET_BITS=64)

add_compile_definitions(
"$<$<CONFIG:Debug>:_GLIBCXX_DEBUG>"
"$<$<CONFIG:Debug>:_LIBCPP_DEBUG>"
)

set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -flto")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -flto")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Og")

# Find nanobind
execute_process(
Expand Down
12 changes: 10 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ Homepage = "https://github.com/bloomberg/pystack"
pystack = "pystack.__main__:main"

[tool.scikit-build]
minimum-version = "0.9"
cmake.verbose = true
cmake.build-type = "RelWithDebInfo"
logging.level = "INFO"
install.strip = false
wheel.packages = ["src/pystack"]
wheel.install-dir = "pystack"
wheel.exclude = ["pystack/_pystack/**"]
Expand All @@ -75,8 +80,11 @@ sdist.exclude = [
"uv.lock",
]

[tool.scikit-build.cmake.define]
CMAKE_BUILD_TYPE = "Release"
[[tool.scikit-build.overrides]]
if.state = "editable"
build-dir = "build"
editable.verbose = false
cmake.build-type = "Debug"

[tool.ruff]
line-length = 95
Expand Down
1 change: 0 additions & 1 deletion src/pystack/_pystack.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ def get_process_threads_for_core(
method: StackMethod = StackMethod.AUTO,
) -> List[PyThread]: ...
def get_bss_info(binary: Union[str, pathlib.Path]) -> Optional[Dict[str, Any]]: ...
def copy_memory_from_address(pid: int, address: int, size: int) -> bytes: ...
def _check_interpreter_shutdown(manager: ProcessManager) -> None: ...
def is_eval_frame(symbol: str, python_version: Tuple[int, int]) -> bool: ...
def _normalize_threads_for_testing(
Expand Down
19 changes: 0 additions & 19 deletions src/pystack/_pystack/bindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -363,18 +363,6 @@ class ProcessManagerWrapper
std::shared_ptr<pystack::AbstractProcessManager> d_manager;
};

nb::bytes
copy_memory_from_address(pid_t pid, uintptr_t address, size_t size)
{
auto manager = std::make_shared<pystack::ProcessMemoryManager>(pid);
PyObject* py_bytes = PyBytes_FromStringAndSize(nullptr, static_cast<Py_ssize_t>(size));
if (!py_bytes) {
throw nb::python_error();
}
manager->copyMemoryFromProcess(address, size, PyBytes_AS_STRING(py_bytes));
return nb::steal<nb::bytes>(py_bytes);
}

nb::object
get_bss_info(const std::filesystem::path& binary)
{
Expand Down Expand Up @@ -972,13 +960,6 @@ NB_MODULE(_pystack, m)
nb::rv_policy::reference)
.def("__exit__", [](ProcessManagerWrapper& self, nb::args) { self.reset(); });

m.def("copy_memory_from_address",
&copy_memory_from_address,
"pid"_a,
"address"_a,
"size"_a,
"Copy memory from a remote process");

m.def("get_bss_info", &get_bss_info, "binary"_a, "Get BSS section information from an ELF binary");

// Note: We use nb::arg().none() to allow None to be passed explicitly
Expand Down
Loading