Print source code where available

pull/17/head
Zach Riggle 11 years ago
parent 0f7de52e13
commit 9ab2371dbe

@ -32,6 +32,7 @@ def context(*args):
result.append(pwndbg.color.legend())
if 'r' in args: result.extend(context_regs())
if 'c' in args: result.extend(context_code())
if 'c' in args: result.extend(context_source())
if 'a' in args: result.extend(context_args())
if 's' in args: result.extend(context_stack())
if 'b' in args: result.extend(context_backtrace())
@ -92,6 +93,22 @@ def context_code():
return banner + result
def context_source():
try:
source = gdb.execute('list', from_tty=False, to_string=True)
# If it starts on line 1, it's not really using the
# correct source code.
if not source or source.startswith('1\t'):
return []
banner = [pwndbg.color.blue(pwndbg.ui.banner("code"))]
banner.extend(source.splitlines())
return banner
except:
pass
return []
def context_stack():
result = []
result.append(pwndbg.color.blue(pwndbg.ui.banner("stack")))

@ -2,6 +2,9 @@
# -*- coding: utf-8 -*-
from capstone import *
import collections
import gdb
import pwndbg.arguments
import pwndbg.color
import pwndbg.disasm
@ -36,6 +39,22 @@ def nearpc(pc=None, lines=None, to_string=False):
pc = int(pc)
lines = int(lines)
# # Load source data if it's available
# pc_to_linenos = collections.defaultdict(lambda: [])
# lineno_to_src = {}
# frame = gdb.selected_frame()
# if frame:
# sal = frame.find_sal()
# if sal:
# symtab = sal.symtab
# objfile = symtab.objfile
# sourcefilename = symtab.filename
# with open(sourcefilename, 'r') as sourcefile:
# lineno_to_src = {i:l for i,l in enumerate(sourcefile.readlines())}
# for line in symtab.linetable():
# pc_to_linenos[line.pc].append(line.line)
result = []
instructions = pwndbg.disasm.near(pc, lines)
@ -72,6 +91,9 @@ def nearpc(pc=None, lines=None, to_string=False):
if pre:
result.append(pwndbg.color.bold(pre))
# for line in pc_to_linenos[i.address]:
# result.append('%s %s' % (line, lineno_to_src[line].strip()))
line = ' '.join((prefix, "%#x" % i.address, s or '', asm))
# If there was a branch before this instruction which was not

@ -58,8 +58,9 @@ def next_syscall(*args):
"""
Breaks at the next syscall.
"""
if pwndbg.next.break_next_interrupt():
pwndbg.commands.context.context()
while not pwndbg.next.break_next_interrupt() and pwndbg.next.break_next_branch():
continue
pwndbg.commands.context.context()
@pwndbg.commands.Command

Loading…
Cancel
Save