Skip to content
Browse files

Add option to redirect context output to other tty or files (#610)

* Add option to redirect context output to other tty or files

The output of context/dashboard can be now be redirected with
 "set context-output /dev/pts/x" to everything wich python can open and
 offers a file like "write".

* Sorted imports correctly (fixing pwndbg CI)
  • Loading branch information...
jerdna-regeiz authored and disconnect3d committed Apr 15, 2019
1 parent f1c0f09 commit 35890f0430878cecc4aee81f18735971a740a02d
Showing with 27 additions and 11 deletions.
  1. +2 −0
  2. +23 −8 pwndbg/commands/
  3. +2 −3 pwndbg/commands/
@@ -17,6 +17,8 @@ All function call sites are annotated with the arguments to those functions. Th

A useful summary of the current execution context is printed every time GDB stops (e.g. breakpoint or single-step), displaying all registers, the stack, call frames, disassembly, and additionally recursively dereferencing all pointers. All memory addresses are color-coded to the type of memory they represent.

The output of the context may be redirected to a file (including other tty) by using `set context-output /path/to/file` while leaving other output in place.


## Disassembly
@@ -7,8 +7,8 @@

import ast
import codecs
import sys
import ctypes
import sys
from io import open

import gdb
@@ -35,14 +35,15 @@
from pwndbg.color import theme

def clear_screen():
def clear_screen(out=sys.stdout):
Clear the screen by moving the cursor to top-left corner and
clear the content

config_clear_screen = pwndbg.config.Parameter('context-clear-screen', False, 'whether to clear the screen before printing the context')
config_output = pwndbg.config.Parameter('context-output', 'stdout', 'where pwndbg should output ("stdout" or file/tty).')
config_context_sections = pwndbg.config.Parameter('context-sections',
'regs disasm code stack backtrace',
'which context sections are displayed (controls order)')
@@ -66,6 +67,19 @@ def validate_context_sections():

class StdOutput(object):
"""A context manager wrapper to give stdout"""
def __enter__(*args,**kwargs):
return sys.stdout
def __exit__(*args, **kwargs):

def output():
"""Creates a context manager corresponding to configured context ouput"""
if not config_output or config_output == "stdout":
return StdOutput()
return open(str( config_output ), "w")

@@ -89,12 +103,13 @@ def context(*args):

if config_clear_screen:
with output() as out:
if config_clear_screen:

for line in result:
sys.stdout.write(line + '\n')
for line in result:
out.write(line + '\n')

def context_regs():
@@ -5,14 +5,13 @@
from __future__ import print_function
from __future__ import unicode_literals

import argparse
import sys

import gdb

import argparse

import pwndbg.color.message as message
import pwndbg.auxv
import pwndbg.color.message as message
import pwndbg.commands
import pwndbg.commands.context
import pwndbg.commands.telescope

0 comments on commit 35890f0

Please sign in to comment.
You can’t perform that action at this time.