Skip to main content

Yet another stack/session dumper utility

Project description

Yet another stack/session dumper utility

A "simple" library to help analyze issues post-mortem without a debugger attached.

Usage

Dumping the process state

You can use yasdu.dump() to dump the process state. Be careful:

  • Dumps like this can contain sensitive data, like passwords, authentication tokens etc. SHARE THEM WITH EXTREME CAUTION.
  • yasdu.dump will not overwrite files and will create filename.number files.
import yasdu
yasdu.dump('dump.json', 'Comment here')
# *** Created stack dump in 'dump.json' ***
# => 'dump.json'
# 'dump.json' is actual filename the dump was saved in

yasdu.dump('dump.json', 'Comment here')
# *** Created stack dump in 'dump.json.1' ***
# => 'dump.json.1'
# Since 'dump.json' already exists, the library picked 'dump.json.1'

Hooking exceptions.

The yasdu.hook() function will hook sys.excepthook and if there's an uncaught exception killing the program it will dump the process state into yasdu_autodump_[ISODATETIME].json See hook and crash example

Loading dumps

CLI tool

For the CLI IPython is recommended but not needed.

usage: yasdu [-h] -l FILE [-S] [-y]

optional arguments:
  -l FILE, --load FILE  Loads given file and starts a Python interpreter

  -S, --no-sources      Disables reading the sources from disk and showing them, useful if they have changed.
  -y                    Assume yes to all questions
  -h, --help            show this help message and exit

Example:

$ python examples/hook_and_crash.py
*** Created stack dump in 'yasdu_autodump.json' ***
Traceback (most recent call last):
  File "examples/hook_and_crash.py", line 13, in <module>
    happily_convert_some_values()
  File "examples/hook_and_crash.py", line 8, in happily_convert_some_values
    v2 = int('deadbeef')  # oh noes
ValueError: invalid literal for int() with base 10: 'deadbeef'

Let's inspect the automatic dump.

$ yasdu -l yasdu_autodump.json
Loading dump files can allow them to execute code. Do you still want to proceed? [y/N]y
Unpickled 9 objects...
Done loading data.


# exception traceback generated by the program ↓
This is an automatic dump it has been triggered by an exception:
Traceback (most recent call last):
  File "examples/hook_and_crash.py", line 13, in <module>
    happily_convert_some_values()
  File "examples/hook_and_crash.py", line 8, in happily_convert_some_values
    v2 = int('deadbeef')  # oh noes
ValueError: invalid literal for int() with base 10: 'deadbeef'

# stack data saved in the dump and sources loaded from disk
Available frames
  0. examples/hook_and_crash.py:13 happily_convert_some_values() <--  # we're here
  1. examples/hook_and_crash.py:8 v2 = int('deadbeef')  # oh noes
LoadedFrame object is available through the `_lframe` global variable

Using IPython for shell...
# [snip]

[hook_and_crash.py:13 (0)] In [1]: sources()
   import yasdu

   some_global_variable = 'testing123'


   def happily_convert_some_values():
       v1 = int('deadbeef', 16)
       v2 = int('deadbeef')  # oh noes


   if __name__ == '__main__':
       yasdu.hook()
->     happily_convert_some_values()

[hook_and_crash.py:13 (0)] In [2]: down()
Available frames
  0. examples/hook_and_crash.py:13 happily_convert_some_values()
  1. examples/hook_and_crash.py:8 v2 = int('deadbeef')  # oh noes <--

[hook_and_crash.py:13 (0)] In [3]: sources()
   import yasdu

   some_global_variable = 'testing123'


   def happily_convert_some_values():
       v1 = int('deadbeef', 16)
->     v2 = int('deadbeef')  # oh noes


   if __name__ == '__main__':
       yasdu.hook()
       happily_convert_some_values()

# variables are loaded from the dump
[hook_and_crash.py:13 (0)] In [4]: v1
Out[4]: 3735928559

[hook_and_crash.py:13 (0)] In [5]: some_global_variable
Out[5]: 'testing123'

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

yasdu-1.0.0.tar.gz (8.9 kB view details)

Uploaded Source

Built Distribution

yasdu-1.0.0-py3-none-any.whl (9.5 kB view details)

Uploaded Python 3

File details

Details for the file yasdu-1.0.0.tar.gz.

File metadata

  • Download URL: yasdu-1.0.0.tar.gz
  • Upload date:
  • Size: 8.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.8.2

File hashes

Hashes for yasdu-1.0.0.tar.gz
Algorithm Hash digest
SHA256 37845bee6df769ce1ae35a5a885a50a2d6d1e5fefa06d8ef3fa14d11459bd58c
MD5 fb30c1803b928403d7019d12b44fd658
BLAKE2b-256 d50e89a2b4aea44c54d463cf5cb721370edccc61cbc1e632cecae0f577c2237d

See more details on using hashes here.

File details

Details for the file yasdu-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: yasdu-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 9.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.8.2

File hashes

Hashes for yasdu-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b3c524e622cd9d0d31f8da5d2ac877d9e0335a57e9dc1926f04e46e57fde7220
MD5 9f414d7be59d086e1139c6c1b1b695bb
BLAKE2b-256 6b90b09c3d2b92ea83f6c9b59688b6d5f1ecefd2f48fe72ac541294038c7b9ed

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page