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
16 changes: 8 additions & 8 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: 3e8a8703264a2f4a69428a0aa4dcb512790b2c8c # frozen: v6.0.0
hooks:
- id: check-added-large-files
- id: check-json
Expand All @@ -12,41 +12,41 @@ repos:
exclude: "^[.]bumpversion[.]cfg"

- repo: https://github.com/pre-commit/pygrep-hooks
rev: v1.10.0
rev: 3a6eb0fadf60b3cccfd80bad9dbb6fae7e47b316 # frozen: v1.10.0
hooks:
- id: rst-directive-colons
- id: rst-inline-touching-normal

- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: "v0.0.262"
rev: "5e2fb545eba1ea9dc051f6f962d52fe8f76a9794" # frozen: v0.15.13
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
stages: [pre-commit]

- repo: https://github.com/psf/black
rev: 23.3.0
rev: 87928e6d6761a4a6d22250e1fee5601b3998086e # frozen: 26.5.1
hooks:
- id: black

- repo: https://github.com/pycqa/isort
rev: 5.12.0
rev: dac090ce4d9ee313d086e2e89ab1acb8c2664fa1 # frozen: 9.0.0a3
hooks:
- id: isort
exclude_types: [python]

- repo: https://github.com/sphinx-contrib/sphinx-lint
rev: v0.6.7
rev: c883505f64b59c3c5c9375191e4ad9f98e727ccd # frozen: v1.0.2
hooks:
- id: sphinx-lint

- repo: https://github.com/executablebooks/mdformat/
rev: 0.7.16
rev: 82912cdaea4fb830f751504486a7879c70526547 # frozen: 1.0.0
hooks:
- id: mdformat

- repo: https://github.com/pre-commit/mirrors-clang-format
rev: v16.0.2
rev: dd18dad857d6133e90bbe478f4f2f22ec0030269 # frozen: v22.1.5
hooks:
- id: clang-format
args: [--Werror, -i]
Expand Down
6 changes: 3 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ issue, or any other method of communication with the maintainers of this reposit

You can also search this project for issues with the following labels:

| Label | Search Term | Description |
| Label | Search Term | Description |
| ------------------------------------------------------------------------------------------------------------------------------------------ | ----------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| [good-first-issue](https://github.com/bloomberg/pystack/search?q=is%3Aissue+is%3Aopen+label%3Agood-first-issue&type=Issues&utf8=%E2%9C%93) | `is:issue is:open label:good-first-issue` | Recommended for first-time contributors! These are well-defined, and allow a user to get familiar with the project's workflow before tackling more complex issues. |
| [help wanted](https://github.com/bloomberg/pystack/search?q=is%3Aissue+is%3Aopen+label%3A%22help+wanted%22+&type=Issues&utf8=%E2%9C%93) | `is:issue is:open label:"help wanted"` | General issues where contributors help is wanted. |
| [question](https://github.com/bloomberg/pystack/search?q=is%3Aissue+is%3Aopen+label%3Aquestion&type=Issues&utf8=%E2%9C%93) | `is:issue is:open label:question` | Open discussions to resolve everything from implementation details to desired functionality. |
| [help wanted](https://github.com/bloomberg/pystack/search?q=is%3Aissue+is%3Aopen+label%3A%22help+wanted%22+&type=Issues&utf8=%E2%9C%93) | `is:issue is:open label:"help wanted"` | General issues where contributors help is wanted. |
| [question](https://github.com/bloomberg/pystack/search?q=is%3Aissue+is%3Aopen+label%3Aquestion&type=Issues&utf8=%E2%9C%93) | `is:issue is:open label:question` | Open discussions to resolve everything from implementation details to desired functionality. |

## Contribution Licensing

Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ CMAKE_BUILD_TYPE = "Release"

[tool.ruff]
line-length = 95
select = ["F", "E", "W", "I001"]
lint.select = ["F", "E", "W", "I001"]

[tool.ruff.isort]
[tool.ruff.lint.isort]
force-single-line = true
known-first-party = ["pystack"]
known-third-party=["rich", "elftools", "pytest"]
Expand Down
10 changes: 5 additions & 5 deletions src/pystack/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ def _exit_with_code(exception: BaseException) -> NoReturn: # pragma: no cover

def produce_error_message(exception: BaseException) -> str:
msg = (
f"💀 {exception} 💀\n" if os.environ.get("NO_COLOR") is None else f"{exception}\n"
f"💀 {exception} 💀\n"
if os.environ.get("NO_COLOR") is None
else f"{exception}\n"
)
if PERMISSION_ERROR_MSG in str(exception) or isinstance(exception, PermissionError):
msg += PERMISSION_HELP_TEXT
Expand Down Expand Up @@ -304,15 +306,13 @@ def green(key: str) -> str:

state = as_green_str(chr(psinfo["sname"]))
zombie = as_green_str(bool([psinfo["zomb"]]))
return dedent(
f"""
return dedent(f"""
{colored("Core file information:", "blue")}
state: {state} zombie: {zombie} niceness: {green('nice')}
pid: {green('pid')} ppid: {green('ppid')} sid: {green('sid')}
uid: {green('uid')} gid: {green('gid')} pgrp: {green('pgrp')}
executable: {green('fname')} arguments: {green('psargs')}
"""
)
""")


def format_failureinfo_information(failure_info: Dict[str, Any]) -> str:
Expand Down
4 changes: 2 additions & 2 deletions src/pystack/_pystack/corefile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ CoreFileExtractor::findExecFn() const

if (elf_getshdrnum(elf, &shnum) < 0) {
LOG(ERROR) << "Cannot determine the number of sections in the ELF file";
return (uintptr_t) nullptr;
return (uintptr_t)nullptr;
}

LOG(DEBUG) << "Found " << shnum << " sections in the ELF file";
Expand Down Expand Up @@ -460,7 +460,7 @@ CoreFileExtractor::findExecFn() const
}
}
LOG(ERROR) << "Failed to extract the ExecFn information from the core file";
return (uintptr_t) nullptr;
return (uintptr_t)nullptr;
}
std::vector<std::string>
CoreFileExtractor::missingModules() const
Expand Down
2 changes: 1 addition & 1 deletion src/pystack/_pystack/corefile.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class CoreAnalyzerError : public std::exception
{
public:
explicit CoreAnalyzerError(std::string error)
: d_error(std::move(error)){};
: d_error(std::move(error)) {};

[[nodiscard]] const char* what() const noexcept override
{
Expand Down
2 changes: 1 addition & 1 deletion src/pystack/_pystack/elf_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class ElfAnalyzerError : public std::exception
{
public:
explicit ElfAnalyzerError(std::string error)
: d_error(std::move(error)){};
: d_error(std::move(error)) {};

const char* what() const noexcept override
{
Expand Down
2 changes: 1 addition & 1 deletion src/pystack/_pystack/logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class LOG
public:
// Constructors
LOG()
: msgLevel(INFO){};
: msgLevel(INFO) {};

explicit LOG(logLevel type)
{
Expand Down
6 changes: 3 additions & 3 deletions src/pystack/_pystack/mem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ VirtualMap::Size() const

LRUCache::LRUCache(size_t capacity)
: d_cache_capacity(capacity)
, d_size(0){};
, d_size(0) {};

void
LRUCache::put(uintptr_t key, std::vector<char>&& value)
Expand Down Expand Up @@ -285,7 +285,7 @@ ProcessMemoryManager::copyMemoryFromProcess(remote_addr_t addr, size_t len, void
bool
ProcessMemoryManager::isAddressValid(remote_addr_t addr, const VirtualMap& map) const
{
if (addr == (uintptr_t) nullptr) {
if (addr == (uintptr_t)nullptr) {
return false;
}
return map.Start() <= addr && addr < map.End();
Expand Down Expand Up @@ -506,7 +506,7 @@ CorefileRemoteMemoryManager::getMemoryLocationFromElf(
bool
CorefileRemoteMemoryManager::isAddressValid(remote_addr_t addr, const VirtualMap& map) const
{
if (addr == (uintptr_t) nullptr) {
if (addr == (uintptr_t)nullptr) {
return false;
}
return map.Start() <= addr && addr < map.Start() + map.Size();
Expand Down
20 changes: 10 additions & 10 deletions src/pystack/_pystack/process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1425,11 +1425,11 @@ ProcessManager::ProcessManager(
std::optional<VirtualMap> bss,
std::optional<VirtualMap> heap)
: AbstractProcessManager(
pid,
std::move(memory_maps),
std::move(main_map),
std::move(bss),
std::move(heap))
pid,
std::move(memory_maps),
std::move(main_map),
std::move(bss),
std::move(heap))
, d_tracer(tracer)
{
if (d_tracer) {
Expand Down Expand Up @@ -1511,11 +1511,11 @@ CoreFileProcessManager::CoreFileProcessManager(
std::optional<VirtualMap> bss,
std::optional<VirtualMap> heap)
: AbstractProcessManager(
pid,
std::move(memory_maps),
std::move(main_map),
std::move(bss),
std::move(heap))
pid,
std::move(memory_maps),
std::move(main_map),
std::move(bss),
std::move(heap))
{
d_analyzer = analyzer;
d_manager = std::make_unique<CorefileRemoteMemoryManager>(analyzer, d_memory_maps);
Expand Down
4 changes: 1 addition & 3 deletions src/pystack/_pystack/pytypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -305,9 +305,7 @@ getDictEntries(
unicode_entries.cbegin(),
unicode_entries.cend(),
std::back_inserter(raw_entries),
[](auto& entry) {
return Python3::PyDictKeyEntry{0, entry.me_key, entry.me_value};
});
[](auto& entry) { return Python3::PyDictKeyEntry{0, entry.me_key, entry.me_value}; });
} else {
manager->copyMemoryFromProcess(
entries_addr,
Expand Down
8 changes: 4 additions & 4 deletions src/pystack/_pystack/structure.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ class Structure
void copyFromRemote();

template<typename FieldPointer>
remote_addr_t getFieldRemoteAddress(FieldPointer OffsetsStruct::*field) const;
remote_addr_t getFieldRemoteAddress(FieldPointer OffsetsStruct::* field) const;

template<typename FieldPointer>
const typename FieldPointer::Type& getField(FieldPointer OffsetsStruct::*field);
const typename FieldPointer::Type& getField(FieldPointer OffsetsStruct::* field);

private:
// Data members
Expand Down Expand Up @@ -66,7 +66,7 @@ Structure<OffsetsStruct>::copyFromRemote()
template<typename OffsetsStruct>
template<typename FieldPointer>
inline remote_addr_t
Structure<OffsetsStruct>::getFieldRemoteAddress(FieldPointer OffsetsStruct::*field) const
Structure<OffsetsStruct>::getFieldRemoteAddress(FieldPointer OffsetsStruct::* field) const
{
offset_t offset = (d_manager->offsets().get<OffsetsStruct>().*field).offset;
return d_addr + offset;
Expand All @@ -75,7 +75,7 @@ Structure<OffsetsStruct>::getFieldRemoteAddress(FieldPointer OffsetsStruct::*fie
template<typename OffsetsStruct>
template<typename FieldPointer>
inline const typename FieldPointer::Type&
Structure<OffsetsStruct>::getField(FieldPointer OffsetsStruct::*field)
Structure<OffsetsStruct>::getField(FieldPointer OffsetsStruct::* field)
{
copyFromRemote();
offset_t offset = (d_manager->offsets().get<OffsetsStruct>().*field).offset;
Expand Down
2 changes: 1 addition & 1 deletion src/pystack/_pystack/unwinder.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class UnwinderError : public std::exception
{
public:
explicit UnwinderError(std::string error)
: d_error(std::move(error)){};
: d_error(std::move(error)) {};

[[nodiscard]] const char* what() const noexcept override
{
Expand Down
9 changes: 3 additions & 6 deletions src/pystack/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,7 @@
"""


class PystackError(Exception):
...
class PystackError(Exception): ...


class EngineError(PystackError):
Expand All @@ -107,12 +106,10 @@ def __str__(self) -> str:
return f"Engine error: {message}"


class ProcessNotFound(PystackError, ProcessLookupError):
...
class ProcessNotFound(PystackError, ProcessLookupError): ...


class InvalidPythonProcess(PystackError):
...
class InvalidPythonProcess(PystackError): ...


class CoreExecutableNotFound(PystackError):
Expand Down
1 change: 1 addition & 0 deletions src/pystack/maps.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
This module provides data classes for representing memory maps.
The actual parsing is done in C++.
"""

import dataclasses
from pathlib import Path
from typing import Optional
Expand Down
1 change: 1 addition & 0 deletions src/pystack/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
This module provides utility functions for checking file types
and decompressing gzip files.
"""

import gzip
import pathlib
import tempfile
Expand Down
1 change: 0 additions & 1 deletion tests/integration/empty_thread_extension/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@


def foo():
fifo = sys.argv[1]
with open(sys.argv[1], "w") as fifo:
fifo.write("ready")
testext.sleep10()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@


def foo():
fifo = sys.argv[1]
with open(sys.argv[1], "w") as fifo:
fifo.write("ready")
testext.sleep10()
Expand Down
1 change: 0 additions & 1 deletion tests/integration/gc_freeze_program.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

class A:
def __del__(self):
fifo = sys.argv[1]
with open(sys.argv[1], "w") as fifo:
fifo.write("ready")
time.sleep(1000)
Expand Down
1 change: 0 additions & 1 deletion tests/integration/inline_calls_program.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ def bar():


def baz():
fifo = sys.argv[1]
with open(sys.argv[1], "w") as fifo:
fifo.write("ready")
time.sleep(1000)
Expand Down
1 change: 0 additions & 1 deletion tests/integration/multiple_thread_program.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ def third_func():
thread.start()
while threads_active != 3:
time.sleep(0.1)
fifo = sys.argv[1]
with open(sys.argv[1], "w") as fifo:
fifo.write("ready")
time.sleep(1000)
Expand Down
1 change: 0 additions & 1 deletion tests/integration/multiple_thread_program_gil.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ def third_func():
thread.start()
while threads_active != 3:
time.sleep(0.1)
fifo = sys.argv[1]
with open(sys.argv[1], "w") as fifo:
fifo.write("ready")
while True:
Expand Down
1 change: 0 additions & 1 deletion tests/integration/single_thread_program.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ def second_func():


def third_func():
fifo = sys.argv[1]
with open(sys.argv[1], "w") as fifo:
fifo.write("ready")
time.sleep(1000)
Expand Down
1 change: 0 additions & 1 deletion tests/integration/single_thread_program_gil.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ def second_func():

def third_func():
collection = list(range(10000))
fifo = sys.argv[1]
with open(sys.argv[1], "w") as fifo:
fifo.write("ready")
while True:
Expand Down
Loading
Loading