mirror of https://github.com/pwndbg/pwndbg.git
Simplify command exception debugging and make stdio work correctly (#251)
* Simplify command exception debugging and make stdio work correctly * Make isort happy * Reorganize exception handler, add default case * Fix print statement * Attempt to use ipdb where available * Sort requirements and add ipdb * Only use pwndbg.stdio in the exception handler * Documentation, hook pdb.set_trace() * Do not require ipdb * Remove import loop, fix accidental call, set python print-stack * Use the correct values for print-stack * Use pdb.Pdb for better set_trace()pull/276/head
parent
5861c6a675
commit
63d107c1aa
@ -0,0 +1,65 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import functools
|
||||
import pdb
|
||||
import sys
|
||||
import traceback
|
||||
|
||||
import gdb
|
||||
|
||||
import pwndbg.config
|
||||
|
||||
try:
|
||||
import ipdb as pdb
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
verbose = pwndbg.config.Parameter('exception-verbose', False, 'whether to print a full stacktracefor exceptions raised in Pwndbg commands')
|
||||
debug = pwndbg.config.Parameter('exception-debugger', False, 'whether to debug exceptions raised in Pwndbg commands')
|
||||
|
||||
def handle():
|
||||
"""Displays an exception to the user, optionally displaying a full traceback
|
||||
and spawning an interactive post-moretem debugger.
|
||||
|
||||
Notes:
|
||||
- ``set exception-verbose on`` enables stack traces.
|
||||
- ``set exception-debugger on`` enables the post-mortem debugger.
|
||||
"""
|
||||
# Display the error
|
||||
if debug or verbose:
|
||||
print(traceback.format_exc())
|
||||
else:
|
||||
exc_type, exc_value, exc_traceback = sys.exc_info()
|
||||
print(exc_type, exc_value)
|
||||
|
||||
# Break into the interactive debugger
|
||||
if debug:
|
||||
with pwndbg.stdio.stdio:
|
||||
pdb.post_mortem()
|
||||
|
||||
|
||||
|
||||
@functools.wraps(pdb.set_trace)
|
||||
def set_trace():
|
||||
"""Enable sane debugging in Pwndbg by switching to the "real" stdio.
|
||||
"""
|
||||
debugger = pdb.Pdb(stdin=sys.__stdin__,
|
||||
stdout=sys.__stdout__,
|
||||
skip=['pwndbg.stdio', 'pwndbg.exception'])
|
||||
debugger.set_trace()
|
||||
|
||||
pdb.set_trace = set_trace
|
||||
|
||||
@pwndbg.config.Trigger([verbose, debug])
|
||||
def update():
|
||||
if verbose or debug:
|
||||
command = 'set python print-stack full'
|
||||
else:
|
||||
command = 'set python print-stack message'
|
||||
|
||||
gdb.execute(command, from_tty=True, to_string=True)
|
||||
@ -1,11 +1,11 @@
|
||||
future
|
||||
isort
|
||||
pip
|
||||
pycparser
|
||||
psutil>=3.1.0
|
||||
python-ptrace>=0.8
|
||||
pycparser
|
||||
pyelftools
|
||||
isort
|
||||
six
|
||||
future
|
||||
python-ptrace>=0.8
|
||||
ROPgadget
|
||||
six
|
||||
unicorn>=1.0.0
|
||||
https://github.com/aquynh/capstone/archive/next.zip#subdirectory=bindings/python
|
||||
Loading…
Reference in new issue