Add history command (#643)

* Add history command

* Sort the imports in history.py

* Add history command to docs
pull/656/head
Vesim 7 years ago committed by Disconnect3d
parent 011752a1ff
commit d1118f2cbb

@ -0,0 +1,2 @@
.. autoprogram:: pwndbg.commands.history:parser
:prog: history

@ -30,6 +30,7 @@ import pwndbg.commands.gdbinit
import pwndbg.commands.got
import pwndbg.commands.heap
import pwndbg.commands.hexdump
import pwndbg.commands.history
import pwndbg.commands.ida
import pwndbg.commands.leakfind
import pwndbg.commands.misc

@ -81,6 +81,8 @@ class Command(gdb.Command):
"""Invoke the command with an argument string"""
try:
args, kwargs = self.split_args(argument)
# skip all None kwargs so we don't have to pass default values twice in argparse and function
kwargs = {k: v for k, v in kwargs.items() if v is not None}
except SystemExit:
# Raised when the usage is printed by an ArgparsedCommand
return

@ -0,0 +1,28 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Display the history.
"""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
import argparse
import readline
import gdb
import pwndbg.commands
parser = argparse.ArgumentParser()
parser.description = __doc__
parser.add_argument('count', type=int, nargs='?',
help='The amount of history entries to display')
@pwndbg.commands.ArgparsedCommand(parser)
def history(count=10):
history_length = readline.get_current_history_length()
history = reversed([readline.get_history_item(i) for i in range(history_length)])
history = list(history)[:min(count, history_length)]
for entry in history:
print(entry)
Loading…
Cancel
Save