Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/pinterest/ptracer
A library for ptrace-based tracing of Python programs
https://github.com/pinterest/ptracer
ptrace python syscalls
Last synced: about 2 months ago
JSON representation
A library for ptrace-based tracing of Python programs
- Host: GitHub
- URL: https://github.com/pinterest/ptracer
- Owner: pinterest
- License: apache-2.0
- Created: 2017-10-17T20:28:31.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2024-07-10T04:48:57.000Z (2 months ago)
- Last Synced: 2024-07-10T07:02:39.263Z (2 months ago)
- Topics: ptrace, python, syscalls
- Language: Python
- Homepage: https://ptracer.readthedocs.io/
- Size: 67.4 KB
- Stars: 155
- Watchers: 13
- Forks: 27
- Open Issues: 5
-
Metadata Files:
- Readme: README.rst
- License: LICENSE
Awesome Lists containing this project
README
ptracer -- a library for ptrace-based tracing of Python programs
================================================================Ptracer is a library providing on-demand system call tracing in Python
programs.Basic Usage
-----------.. code-block:: python
import traceback
import ptracerdef callback(syscall):
print('{}({}) -> {}'.format(
syscall.name,
', '.join(repr(arg.value) for arg in syscall.args),
syscall.result.text))
print('Traceback: ')
print(''.join(traceback.format_list(syscall.traceback)))with ptracer.context(callback):
open('/dev/null', 'wb')Filtering
---------Ptracer allows elaborate syscall filtering via the *filter* argument:
.. code-block:: python
flt = [
ptracer.SysCallPattern(
name='open',
args=[
re.compile(b'/tmp/.*'),
lambda arg: arg.value & os.O_WRONLY
],
result=lambda res: res.value > 0
)
]with ptracer.context(callback, filter=flt):
# traced code
...In the above example, ptracer will invoke the callback only for successful
attempts to open files in the "/tmp" directory for writing.Documentation
-------------The documentation is available on
`ptracer.readthedocs.io `_.