Skip to content

Commit

Permalink
Fixes issue when we try to display context while selected thread is r…
Browse files Browse the repository at this point in the history
  • Loading branch information
disconnect3d authored and zachriggle committed Aug 28, 2017
1 parent 0bd903e commit 1ab3de0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
18 changes: 17 additions & 1 deletion pwndbg/proc.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
# -*- coding: utf-8 -*-
"""
Provides values which would be available from /proc which
are not fulfilled by other modules.
are not fulfilled by other modules and some process/gdb flow
related information.
"""
from __future__ import absolute_import
from __future__ import division
Expand Down Expand Up @@ -47,6 +48,18 @@ def tid(self):
def alive(self):
return gdb.selected_thread() is not None

@property
def thread_is_stopped(self):
"""
This detects whether selected thread is stopped.
It is not stopped in situations when gdb is executing commands
that are attached to a breakpoint by `command` command.
For more info see issue #229 ( https://github.com/pwndbg/pwndbg/issues/299 )
:return: Whether gdb executes commands attached to bp with `command` command.
"""
return gdb.selected_thread().is_stopped()

@property
def exe(self):
for obj in gdb.objfiles():
Expand All @@ -56,13 +69,16 @@ def exe(self):
if self.alive:
auxv = pwndbg.auxv.get()
return auxv['AT_EXECFN']

def OnlyWhenRunning(self, func):
@functools.wraps(func)
def wrapper(*a, **kw):
if self.alive:
return func(*a, **kw)

return wrapper


# To prevent garbage collection
tether = sys.modules[__name__]

Expand Down
3 changes: 2 additions & 1 deletion pwndbg/prompt.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def prompt_hook(*a):
pwndbg.events.after_reload(start=False)
cur = new

if pwndbg.proc.alive:
if pwndbg.proc.alive and pwndbg.proc.thread_is_stopped:
prompt_hook_on_stop(*a)


Expand All @@ -33,4 +33,5 @@ def prompt_hook_on_stop(*a):
with pwndbg.stdio.stdio:
pwndbg.commands.context.context()


gdb.prompt_hook = prompt_hook

0 comments on commit 1ab3de0

Please sign in to comment.