We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
nextproginstr doesn't stop when reaching the program instructions
The `nextproginstr` command should stop when it reaches an instruction in the binary, but it seems to reach those instructions and continue executing instead of breaking.

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `pwndbg/proc.py`
Content:
```
1 """
2 Provides values which would be available from /proc which
3 are not fulfilled by other modules and some process/gdb flow
4 related information.
5 """
6 
7 import functools
8 import sys
9 from types import ModuleType
10 
11 import gdb
12 
13 import pwndbg.gdblib.qemu
14 import pwndbg.lib.memoize
15 
16 
17 class module(ModuleType):
18     @property
19     def pid(self):
20         # QEMU usermode emualtion always returns 42000 for some reason.
21         # In any case, we can't use the info.
22         if pwndbg.gdblib.qemu.is_qemu_usermode():
23             return pwndbg.gdblib.qemu.pid()
24 
25         i = gdb.selected_inferior()
26         if i is not None:
27             return i.pid
28         return 0
29 
30     @property
31     def tid(self):
32         if pwndbg.gdblib.qemu.is_qemu_usermode():
33             return pwndbg.gdblib.qemu.pid()
34 
35         i = gdb.selected_thread()
36         if i is not None:
37             return i.ptid[1]
38 
39         return self.pid
40 
41     @property
42     def alive(self):
43         return gdb.selected_thread() is not None
44 
45     @property
46     def thread_is_stopped(self):
47         """
48         This detects whether selected thread is stopped.
49         It is not stopped in situations when gdb is executing commands
50         that are attached to a breakpoint by `command` command.
51 
52         For more info see issue #229 ( https://github.com/pwndbg/pwndbg/issues/299 )
53         :return: Whether gdb executes commands attached to bp with `command` command.
54         """
55         return gdb.selected_thread().is_stopped()
56 
57     @property
58     def exe(self):
59         """
60         Returns the debugged file name.
61 
62         On remote targets, this may be prefixed with "target:" string.
63         See this by executing those in two terminals:
64         1. gdbserver 127.0.0.1:1234 /bin/ls
65         2. gdb -ex "target remote :1234" -ex "pi pwndbg.proc.exe"
66 
67         If you need to process the debugged file use:
68             `pwndbg.file.get_file(pwndbg.proc.exe)`
69         """
70         return gdb.current_progspace().filename
71 
72     @property
73     def mem_page(self):
74         return next(p for p in pwndbg.vmmap.get() if p.objfile == self.exe)
75 
76     def OnlyWhenRunning(self, func):
77         @functools.wraps(func)
78         def wrapper(*a, **kw):
79             if self.alive:
80                 return func(*a, **kw)
81 
82         return wrapper
83 
84 
85 # To prevent garbage collection
86 tether = sys.modules[__name__]
87 
88 sys.modules[__name__] = module(__name__, "")
89
```

Path: `pwndbg/commands/next.py`
Content:
```
1 """
2 Stepping until an event occurs
3 """
4 
5 import argparse
6 
7 import gdb
8 
9 import pwndbg.commands
10 import pwndbg.gdblib.next
11 
12 
13 @pwndbg.commands.ArgparsedCommand("Breaks at the next jump instruction.", aliases=["nextjump"])
14 @pwndbg.commands.OnlyWhenRunning
15 def nextjmp():
16     """Breaks at the next jump instruction"""
17     if pwndbg.gdblib.next.break_next_branch():
18         pwndbg.commands.context.context()
19 
20 
21 parser = argparse.ArgumentParser(description="""Breaks at the next call instruction""")
22 parser.add_argument(
23     "symbol_regex",
24     type=str,
25     default=None,
26     nargs="?",
27     help="A regex matching the name of next symbol to be broken on before calling.",
28 )
29 
30 
31 @pwndbg.commands.ArgparsedCommand(parser)
32 @pwndbg.commands.OnlyWhenRunning
33 def nextcall(symbol_regex=None):
34     """Breaks at the next call instruction"""
35     if pwndbg.gdblib.next.break_next_call(symbol_regex):
36         pwndbg.commands.context.context()
37 
38 
39 @pwndbg.commands.ArgparsedCommand("""Breaks at next return-like instruction""")
40 @pwndbg.commands.OnlyWhenRunning
41 def nextret():
42     """Breaks at next return-like instruction"""
43     if pwndbg.gdblib.next.break_next_ret():
44         pwndbg.commands.context.context()
45 
46 
47 @pwndbg.commands.ArgparsedCommand("""Breaks at next return-like instruction by 'stepping' to it""")
48 @pwndbg.commands.OnlyWhenRunning
49 def stepret():
50     """Breaks at next return-like instruction by 'stepping' to it"""
51     while (
52         pwndbg.proc.alive
53         and not pwndbg.gdblib.next.break_next_ret()
54         and pwndbg.gdblib.next.break_next_branch()
55     ):
56         # Here we are e.g. on a CALL instruction (temporarily breakpointed by `break_next_branch`)
57         # We need to step so that we take this branch instead of ignoring it
58         gdb.execute("si")
59         continue
60 
61     if pwndbg.proc.alive:
62         pwndbg.commands.context.context()
63 
64 
65 @pwndbg.commands.ArgparsedCommand(
66     """Breaks at the next instruction that belongs to the running program"""
67 )
68 @pwndbg.commands.OnlyWhenRunning
69 def nextproginstr():
70     """Breaks at the next instruction that belongs to the running program"""
71     if pwndbg.gdblib.next.break_on_program_code():
72         pwndbg.commands.context.context()
73 
74 
75 parser = argparse.ArgumentParser(
76     description="""Sets a breakpoint on the instruction after this one"""
77 )
78 parser.add_argument("addr", type=int, default=None, nargs="?", help="The address to break after.")
79 
80 
81 @pwndbg.commands.ArgparsedCommand(parser, aliases=["so"])
82 @pwndbg.commands.OnlyWhenRunning
83 def stepover(addr=None):
84     """Sets a breakpoint on the instruction after this one"""
85     pwndbg.gdblib.next.break_on_next(addr)
86 
87 
88 @pwndbg.commands.ArgparsedCommand(
89     "Breaks at the next syscall not taking branches.", aliases=["nextsc"]
90 )
91 @pwndbg.commands.OnlyWhenRunning
92 def nextsyscall():
93     """
94     Breaks at the next syscall not taking branches.
95     """
96     while (
97         pwndbg.proc.alive
98         and not pwndbg.gdblib.next.break_next_interrupt()
99         and pwndbg.gdblib.next.break_next_branch()
100     ):
101         continue
102 
103     if pwndbg.proc.alive:
104         pwndbg.commands.context.context()
105 
106 
107 @pwndbg.commands.ArgparsedCommand(
108     "Breaks at the next syscall by taking branches.", aliases=["stepsc"]
109 )
110 @pwndbg.commands.OnlyWhenRunning
111 def stepsyscall():
112     """
113     Breaks at the next syscall by taking branches.
114     """
115     while (
116         pwndbg.proc.alive
117         and not pwndbg.gdblib.next.break_next_interrupt()
118         and pwndbg.gdblib.next.break_next_branch()
119     ):
120         # Here we are e.g. on a CALL instruction (temporarily breakpointed by `break_next_branch`)
121         # We need to step so that we take this branch instead of ignoring it
122         gdb.execute("si")
123         continue
124 
125     if pwndbg.proc.alive:
126         pwndbg.commands.context.context()
127
```

Path: `pwndbg/gdblib/next.py`
Content:
```
1 """
2 Commands for setting temporary breakpoints on the next
3 instruction of some type (call, branch, etc.)
4 """
5 
6 import re
7 
8 import capstone
9 import gdb
10 
11 import pwndbg.disasm
12 import pwndbg.gdblib.events
13 import pwndbg.gdblib.regs
14 import pwndbg.proc
15 from pwndbg.color import message
16 
17 jumps = set((capstone.CS_GRP_CALL, capstone.CS_GRP_JUMP, capstone.CS_GRP_RET, capstone.CS_GRP_IRET))
18 
19 interrupts = set((capstone.CS_GRP_INT,))
20 
21 
22 @pwndbg.gdblib.events.exit
23 def clear_temp_breaks():
24     if not pwndbg.proc.alive:
25         breakpoints = gdb.breakpoints()
26         if breakpoints:
27             for bp in breakpoints:
28                 if (
29                     bp.temporary and not bp.visible
30                 ):  # visible is used instead of internal because older gdb's don't support internal
31                     bp.delete()
32 
33 
34 def next_int(address=None):
35     """
36     If there is a syscall in the current basic black,
37     return the instruction of the one closest to $PC.
38 
39     Otherwise, return None.
40     """
41     if address is None:
42         ins = pwndbg.disasm.one(pwndbg.gdblib.regs.pc)
43         if not ins:
44             return None
45         address = ins.next
46 
47     ins = pwndbg.disasm.one(address)
48     while ins:
49         if set(ins.groups) & jumps:
50             return None
51         if set(ins.groups) & interrupts:
52             return ins
53         ins = pwndbg.disasm.one(ins.next)
54 
55     return None
56 
57 
58 def next_branch(address=None):
59     if address is None:
60         ins = pwndbg.disasm.one(pwndbg.gdblib.regs.pc)
61         if not ins:
62             return None
63         address = ins.next
64 
65     ins = pwndbg.disasm.one(address)
66     while ins:
67         if set(ins.groups) & jumps:
68             return ins
69         ins = pwndbg.disasm.one(ins.next)
70 
71     return None
72 
73 
74 def break_next_branch(address=None):
75     ins = next_branch(address)
76 
77     if ins:
78         gdb.Breakpoint("*%#x" % ins.address, internal=True, temporary=True)
79         gdb.execute("continue", from_tty=False, to_string=True)
80         return ins
81 
82 
83 def break_next_interrupt(address=None):
84     ins = next_int(address)
85 
86     if ins:
87         gdb.Breakpoint("*%#x" % ins.address, internal=True, temporary=True)
88         gdb.execute("continue", from_tty=False, to_string=True)
89         return ins
90 
91 
92 def break_next_call(symbol_regex=None):
93     while pwndbg.proc.alive:
94         ins = break_next_branch()
95 
96         if not ins:
97             break
98 
99         # continue if not a call
100         if capstone.CS_GRP_CALL not in ins.groups:
101             continue
102 
103         # return call if we don't search for a symbol
104         if not symbol_regex:
105             return ins
106 
107         # return call if we match target address
108         if ins.target_const and re.match("%s$" % symbol_regex, hex(ins.target)):
109             return ins
110 
111         # return call if we match symbol name
112         if ins.symbol and re.match("%s$" % symbol_regex, ins.symbol):
113             return ins
114 
115 
116 def break_next_ret(address=None):
117     while pwndbg.proc.alive:
118         ins = break_next_branch(address)
119 
120         if not ins:
121             break
122 
123         if capstone.CS_GRP_RET in ins.groups:
124             return ins
125 
126 
127 def break_on_program_code():
128     """
129     Breaks on next instruction that belongs to process' objfile code.
130     :return: True for success, False when process ended or when pc is at the code.
131     """
132     mp = pwndbg.proc.mem_page
133     start = mp.start
134     end = mp.end
135 
136     if start <= pwndbg.gdblib.regs.pc < end:
137         print(message.error("The pc is already at the binary objfile code. Not stepping."))
138         return False
139 
140     while pwndbg.proc.alive:
141         gdb.execute("si", from_tty=False, to_string=False)
142 
143         addr = pwndbg.gdblib.regs.pc
144         if start <= addr < end:
145             return True
146 
147     return False
148 
149 
150 def break_on_next(address=None):
151     address = address or pwndbg.gdblib.regs.pc
152     ins = pwndbg.disasm.one(address)
153 
154     gdb.Breakpoint("*%#x" % (ins.address + ins.size), temporary=True)
155     gdb.execute("continue", from_tty=False, to_string=True)
156
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/pwndbg/commands/next.py b/pwndbg/commands/next.py
--- a/pwndbg/commands/next.py
+++ b/pwndbg/commands/next.py
@@ -67,9 +67,7 @@
 )
 @pwndbg.commands.OnlyWhenRunning
 def nextproginstr():
-    """Breaks at the next instruction that belongs to the running program"""
-    if pwndbg.gdblib.next.break_on_program_code():
-        pwndbg.commands.context.context()
+    pwndbg.gdblib.next.break_on_program_code()
 
 
 parser = argparse.ArgumentParser(
diff --git a/pwndbg/gdblib/next.py b/pwndbg/gdblib/next.py
--- a/pwndbg/gdblib/next.py
+++ b/pwndbg/gdblib/next.py
@@ -129,20 +129,24 @@
     Breaks on next instruction that belongs to process' objfile code.
     :return: True for success, False when process ended or when pc is at the code.
     """
-    mp = pwndbg.proc.mem_page
-    start = mp.start
-    end = mp.end
+    exe = pwndbg.proc.exe
+    binary_exec_page_ranges = [
+        (p.start, p.end) for p in pwndbg.vmmap.get() if p.objfile == exe and p.execute
+    ]
 
-    if start <= pwndbg.gdblib.regs.pc < end:
-        print(message.error("The pc is already at the binary objfile code. Not stepping."))
-        return False
+    pc = pwndbg.gdblib.regs.pc
+    for start, end in binary_exec_page_ranges:
+        if start <= pc < end:
+            print(message.error("The pc is already at the binary objfile code. Not stepping."))
+            return False
 
     while pwndbg.proc.alive:
         gdb.execute("si", from_tty=False, to_string=False)
 
-        addr = pwndbg.gdblib.regs.pc
-        if start <= addr < end:
-            return True
+        pc = pwndbg.gdblib.regs.pc
+        for start, end in binary_exec_page_ranges:
+            if start <= pc < end:
+                return True
 
     return False
 
diff --git a/pwndbg/proc.py b/pwndbg/proc.py
--- a/pwndbg/proc.py
+++ b/pwndbg/proc.py
@@ -69,10 +69,6 @@
         """
         return gdb.current_progspace().filename
 
-    @property
-    def mem_page(self):
-        return next(p for p in pwndbg.vmmap.get() if p.objfile == self.exe)
-
     def OnlyWhenRunning(self, func):
         @functools.wraps(func)
         def wrapper(*a, **kw):

{"golden_diff": "diff --git a/pwndbg/commands/next.py b/pwndbg/commands/next.py\n--- a/pwndbg/commands/next.py\n+++ b/pwndbg/commands/next.py\n@@ -67,9 +67,7 @@\n )\n @pwndbg.commands.OnlyWhenRunning\n def nextproginstr():\n-    \"\"\"Breaks at the next instruction that belongs to the running program\"\"\"\n-    if pwndbg.gdblib.next.break_on_program_code():\n-        pwndbg.commands.context.context()\n+    pwndbg.gdblib.next.break_on_program_code()\n \n \n parser = argparse.ArgumentParser(\ndiff --git a/pwndbg/gdblib/next.py b/pwndbg/gdblib/next.py\n--- a/pwndbg/gdblib/next.py\n+++ b/pwndbg/gdblib/next.py\n@@ -129,20 +129,24 @@\n     Breaks on next instruction that belongs to process' objfile code.\n     :return: True for success, False when process ended or when pc is at the code.\n     \"\"\"\n-    mp = pwndbg.proc.mem_page\n-    start = mp.start\n-    end = mp.end\n+    exe = pwndbg.proc.exe\n+    binary_exec_page_ranges = [\n+        (p.start, p.end) for p in pwndbg.vmmap.get() if p.objfile == exe and p.execute\n+    ]\n \n-    if start <= pwndbg.gdblib.regs.pc < end:\n-        print(message.error(\"The pc is already at the binary objfile code. Not stepping.\"))\n-        return False\n+    pc = pwndbg.gdblib.regs.pc\n+    for start, end in binary_exec_page_ranges:\n+        if start <= pc < end:\n+            print(message.error(\"The pc is already at the binary objfile code. Not stepping.\"))\n+            return False\n \n     while pwndbg.proc.alive:\n         gdb.execute(\"si\", from_tty=False, to_string=False)\n \n-        addr = pwndbg.gdblib.regs.pc\n-        if start <= addr < end:\n-            return True\n+        pc = pwndbg.gdblib.regs.pc\n+        for start, end in binary_exec_page_ranges:\n+            if start <= pc < end:\n+                return True\n \n     return False\n \ndiff --git a/pwndbg/proc.py b/pwndbg/proc.py\n--- a/pwndbg/proc.py\n+++ b/pwndbg/proc.py\n@@ -69,10 +69,6 @@\n         \"\"\"\n         return gdb.current_progspace().filename\n \n-    @property\n-    def mem_page(self):\n-        return next(p for p in pwndbg.vmmap.get() if p.objfile == self.exe)\n-\n     def OnlyWhenRunning(self, func):\n         @functools.wraps(func)\n         def wrapper(*a, **kw):\n", "issue": "nextproginstr doesn't stop when reaching the program instructions\nThe `nextproginstr` command should stop when it reaches an instruction in the binary, but it seems to reach those instructions and continue executing instead of breaking.\n", "before_files": [{"content": "\"\"\"\nProvides values which would be available from /proc which\nare not fulfilled by other modules and some process/gdb flow\nrelated information.\n\"\"\"\n\nimport functools\nimport sys\nfrom types import ModuleType\n\nimport gdb\n\nimport pwndbg.gdblib.qemu\nimport pwndbg.lib.memoize\n\n\nclass module(ModuleType):\n    @property\n    def pid(self):\n        # QEMU usermode emualtion always returns 42000 for some reason.\n        # In any case, we can't use the info.\n        if pwndbg.gdblib.qemu.is_qemu_usermode():\n            return pwndbg.gdblib.qemu.pid()\n\n        i = gdb.selected_inferior()\n        if i is not None:\n            return i.pid\n        return 0\n\n    @property\n    def tid(self):\n        if pwndbg.gdblib.qemu.is_qemu_usermode():\n            return pwndbg.gdblib.qemu.pid()\n\n        i = gdb.selected_thread()\n        if i is not None:\n            return i.ptid[1]\n\n        return self.pid\n\n    @property\n    def alive(self):\n        return gdb.selected_thread() is not None\n\n    @property\n    def thread_is_stopped(self):\n        \"\"\"\n        This detects whether selected thread is stopped.\n        It is not stopped in situations when gdb is executing commands\n        that are attached to a breakpoint by `command` command.\n\n        For more info see issue #229 ( https://github.com/pwndbg/pwndbg/issues/299 )\n        :return: Whether gdb executes commands attached to bp with `command` command.\n        \"\"\"\n        return gdb.selected_thread().is_stopped()\n\n    @property\n    def exe(self):\n        \"\"\"\n        Returns the debugged file name.\n\n        On remote targets, this may be prefixed with \"target:\" string.\n        See this by executing those in two terminals:\n        1. gdbserver 127.0.0.1:1234 /bin/ls\n        2. gdb -ex \"target remote :1234\" -ex \"pi pwndbg.proc.exe\"\n\n        If you need to process the debugged file use:\n            `pwndbg.file.get_file(pwndbg.proc.exe)`\n        \"\"\"\n        return gdb.current_progspace().filename\n\n    @property\n    def mem_page(self):\n        return next(p for p in pwndbg.vmmap.get() if p.objfile == self.exe)\n\n    def OnlyWhenRunning(self, func):\n        @functools.wraps(func)\n        def wrapper(*a, **kw):\n            if self.alive:\n                return func(*a, **kw)\n\n        return wrapper\n\n\n# To prevent garbage collection\ntether = sys.modules[__name__]\n\nsys.modules[__name__] = module(__name__, \"\")\n", "path": "pwndbg/proc.py"}, {"content": "\"\"\"\nStepping until an event occurs\n\"\"\"\n\nimport argparse\n\nimport gdb\n\nimport pwndbg.commands\nimport pwndbg.gdblib.next\n\n\n@pwndbg.commands.ArgparsedCommand(\"Breaks at the next jump instruction.\", aliases=[\"nextjump\"])\n@pwndbg.commands.OnlyWhenRunning\ndef nextjmp():\n    \"\"\"Breaks at the next jump instruction\"\"\"\n    if pwndbg.gdblib.next.break_next_branch():\n        pwndbg.commands.context.context()\n\n\nparser = argparse.ArgumentParser(description=\"\"\"Breaks at the next call instruction\"\"\")\nparser.add_argument(\n    \"symbol_regex\",\n    type=str,\n    default=None,\n    nargs=\"?\",\n    help=\"A regex matching the name of next symbol to be broken on before calling.\",\n)\n\n\n@pwndbg.commands.ArgparsedCommand(parser)\n@pwndbg.commands.OnlyWhenRunning\ndef nextcall(symbol_regex=None):\n    \"\"\"Breaks at the next call instruction\"\"\"\n    if pwndbg.gdblib.next.break_next_call(symbol_regex):\n        pwndbg.commands.context.context()\n\n\n@pwndbg.commands.ArgparsedCommand(\"\"\"Breaks at next return-like instruction\"\"\")\n@pwndbg.commands.OnlyWhenRunning\ndef nextret():\n    \"\"\"Breaks at next return-like instruction\"\"\"\n    if pwndbg.gdblib.next.break_next_ret():\n        pwndbg.commands.context.context()\n\n\n@pwndbg.commands.ArgparsedCommand(\"\"\"Breaks at next return-like instruction by 'stepping' to it\"\"\")\n@pwndbg.commands.OnlyWhenRunning\ndef stepret():\n    \"\"\"Breaks at next return-like instruction by 'stepping' to it\"\"\"\n    while (\n        pwndbg.proc.alive\n        and not pwndbg.gdblib.next.break_next_ret()\n        and pwndbg.gdblib.next.break_next_branch()\n    ):\n        # Here we are e.g. on a CALL instruction (temporarily breakpointed by `break_next_branch`)\n        # We need to step so that we take this branch instead of ignoring it\n        gdb.execute(\"si\")\n        continue\n\n    if pwndbg.proc.alive:\n        pwndbg.commands.context.context()\n\n\n@pwndbg.commands.ArgparsedCommand(\n    \"\"\"Breaks at the next instruction that belongs to the running program\"\"\"\n)\n@pwndbg.commands.OnlyWhenRunning\ndef nextproginstr():\n    \"\"\"Breaks at the next instruction that belongs to the running program\"\"\"\n    if pwndbg.gdblib.next.break_on_program_code():\n        pwndbg.commands.context.context()\n\n\nparser = argparse.ArgumentParser(\n    description=\"\"\"Sets a breakpoint on the instruction after this one\"\"\"\n)\nparser.add_argument(\"addr\", type=int, default=None, nargs=\"?\", help=\"The address to break after.\")\n\n\n@pwndbg.commands.ArgparsedCommand(parser, aliases=[\"so\"])\n@pwndbg.commands.OnlyWhenRunning\ndef stepover(addr=None):\n    \"\"\"Sets a breakpoint on the instruction after this one\"\"\"\n    pwndbg.gdblib.next.break_on_next(addr)\n\n\n@pwndbg.commands.ArgparsedCommand(\n    \"Breaks at the next syscall not taking branches.\", aliases=[\"nextsc\"]\n)\n@pwndbg.commands.OnlyWhenRunning\ndef nextsyscall():\n    \"\"\"\n    Breaks at the next syscall not taking branches.\n    \"\"\"\n    while (\n        pwndbg.proc.alive\n        and not pwndbg.gdblib.next.break_next_interrupt()\n        and pwndbg.gdblib.next.break_next_branch()\n    ):\n        continue\n\n    if pwndbg.proc.alive:\n        pwndbg.commands.context.context()\n\n\n@pwndbg.commands.ArgparsedCommand(\n    \"Breaks at the next syscall by taking branches.\", aliases=[\"stepsc\"]\n)\n@pwndbg.commands.OnlyWhenRunning\ndef stepsyscall():\n    \"\"\"\n    Breaks at the next syscall by taking branches.\n    \"\"\"\n    while (\n        pwndbg.proc.alive\n        and not pwndbg.gdblib.next.break_next_interrupt()\n        and pwndbg.gdblib.next.break_next_branch()\n    ):\n        # Here we are e.g. on a CALL instruction (temporarily breakpointed by `break_next_branch`)\n        # We need to step so that we take this branch instead of ignoring it\n        gdb.execute(\"si\")\n        continue\n\n    if pwndbg.proc.alive:\n        pwndbg.commands.context.context()\n", "path": "pwndbg/commands/next.py"}, {"content": "\"\"\"\nCommands for setting temporary breakpoints on the next\ninstruction of some type (call, branch, etc.)\n\"\"\"\n\nimport re\n\nimport capstone\nimport gdb\n\nimport pwndbg.disasm\nimport pwndbg.gdblib.events\nimport pwndbg.gdblib.regs\nimport pwndbg.proc\nfrom pwndbg.color import message\n\njumps = set((capstone.CS_GRP_CALL, capstone.CS_GRP_JUMP, capstone.CS_GRP_RET, capstone.CS_GRP_IRET))\n\ninterrupts = set((capstone.CS_GRP_INT,))\n\n\n@pwndbg.gdblib.events.exit\ndef clear_temp_breaks():\n    if not pwndbg.proc.alive:\n        breakpoints = gdb.breakpoints()\n        if breakpoints:\n            for bp in breakpoints:\n                if (\n                    bp.temporary and not bp.visible\n                ):  # visible is used instead of internal because older gdb's don't support internal\n                    bp.delete()\n\n\ndef next_int(address=None):\n    \"\"\"\n    If there is a syscall in the current basic black,\n    return the instruction of the one closest to $PC.\n\n    Otherwise, return None.\n    \"\"\"\n    if address is None:\n        ins = pwndbg.disasm.one(pwndbg.gdblib.regs.pc)\n        if not ins:\n            return None\n        address = ins.next\n\n    ins = pwndbg.disasm.one(address)\n    while ins:\n        if set(ins.groups) & jumps:\n            return None\n        if set(ins.groups) & interrupts:\n            return ins\n        ins = pwndbg.disasm.one(ins.next)\n\n    return None\n\n\ndef next_branch(address=None):\n    if address is None:\n        ins = pwndbg.disasm.one(pwndbg.gdblib.regs.pc)\n        if not ins:\n            return None\n        address = ins.next\n\n    ins = pwndbg.disasm.one(address)\n    while ins:\n        if set(ins.groups) & jumps:\n            return ins\n        ins = pwndbg.disasm.one(ins.next)\n\n    return None\n\n\ndef break_next_branch(address=None):\n    ins = next_branch(address)\n\n    if ins:\n        gdb.Breakpoint(\"*%#x\" % ins.address, internal=True, temporary=True)\n        gdb.execute(\"continue\", from_tty=False, to_string=True)\n        return ins\n\n\ndef break_next_interrupt(address=None):\n    ins = next_int(address)\n\n    if ins:\n        gdb.Breakpoint(\"*%#x\" % ins.address, internal=True, temporary=True)\n        gdb.execute(\"continue\", from_tty=False, to_string=True)\n        return ins\n\n\ndef break_next_call(symbol_regex=None):\n    while pwndbg.proc.alive:\n        ins = break_next_branch()\n\n        if not ins:\n            break\n\n        # continue if not a call\n        if capstone.CS_GRP_CALL not in ins.groups:\n            continue\n\n        # return call if we don't search for a symbol\n        if not symbol_regex:\n            return ins\n\n        # return call if we match target address\n        if ins.target_const and re.match(\"%s$\" % symbol_regex, hex(ins.target)):\n            return ins\n\n        # return call if we match symbol name\n        if ins.symbol and re.match(\"%s$\" % symbol_regex, ins.symbol):\n            return ins\n\n\ndef break_next_ret(address=None):\n    while pwndbg.proc.alive:\n        ins = break_next_branch(address)\n\n        if not ins:\n            break\n\n        if capstone.CS_GRP_RET in ins.groups:\n            return ins\n\n\ndef break_on_program_code():\n    \"\"\"\n    Breaks on next instruction that belongs to process' objfile code.\n    :return: True for success, False when process ended or when pc is at the code.\n    \"\"\"\n    mp = pwndbg.proc.mem_page\n    start = mp.start\n    end = mp.end\n\n    if start <= pwndbg.gdblib.regs.pc < end:\n        print(message.error(\"The pc is already at the binary objfile code. Not stepping.\"))\n        return False\n\n    while pwndbg.proc.alive:\n        gdb.execute(\"si\", from_tty=False, to_string=False)\n\n        addr = pwndbg.gdblib.regs.pc\n        if start <= addr < end:\n            return True\n\n    return False\n\n\ndef break_on_next(address=None):\n    address = address or pwndbg.gdblib.regs.pc\n    ins = pwndbg.disasm.one(address)\n\n    gdb.Breakpoint(\"*%#x\" % (ins.address + ins.size), temporary=True)\n    gdb.execute(\"continue\", from_tty=False, to_string=True)\n", "path": "pwndbg/gdblib/next.py"}], "after_files": [{"content": "\"\"\"\nProvides values which would be available from /proc which\nare not fulfilled by other modules and some process/gdb flow\nrelated information.\n\"\"\"\n\nimport functools\nimport sys\nfrom types import ModuleType\n\nimport gdb\n\nimport pwndbg.gdblib.qemu\nimport pwndbg.lib.memoize\n\n\nclass module(ModuleType):\n    @property\n    def pid(self):\n        # QEMU usermode emualtion always returns 42000 for some reason.\n        # In any case, we can't use the info.\n        if pwndbg.gdblib.qemu.is_qemu_usermode():\n            return pwndbg.gdblib.qemu.pid()\n\n        i = gdb.selected_inferior()\n        if i is not None:\n            return i.pid\n        return 0\n\n    @property\n    def tid(self):\n        if pwndbg.gdblib.qemu.is_qemu_usermode():\n            return pwndbg.gdblib.qemu.pid()\n\n        i = gdb.selected_thread()\n        if i is not None:\n            return i.ptid[1]\n\n        return self.pid\n\n    @property\n    def alive(self):\n        return gdb.selected_thread() is not None\n\n    @property\n    def thread_is_stopped(self):\n        \"\"\"\n        This detects whether selected thread is stopped.\n        It is not stopped in situations when gdb is executing commands\n        that are attached to a breakpoint by `command` command.\n\n        For more info see issue #229 ( https://github.com/pwndbg/pwndbg/issues/299 )\n        :return: Whether gdb executes commands attached to bp with `command` command.\n        \"\"\"\n        return gdb.selected_thread().is_stopped()\n\n    @property\n    def exe(self):\n        \"\"\"\n        Returns the debugged file name.\n\n        On remote targets, this may be prefixed with \"target:\" string.\n        See this by executing those in two terminals:\n        1. gdbserver 127.0.0.1:1234 /bin/ls\n        2. gdb -ex \"target remote :1234\" -ex \"pi pwndbg.proc.exe\"\n\n        If you need to process the debugged file use:\n            `pwndbg.file.get_file(pwndbg.proc.exe)`\n        \"\"\"\n        return gdb.current_progspace().filename\n\n    def OnlyWhenRunning(self, func):\n        @functools.wraps(func)\n        def wrapper(*a, **kw):\n            if self.alive:\n                return func(*a, **kw)\n\n        return wrapper\n\n\n# To prevent garbage collection\ntether = sys.modules[__name__]\n\nsys.modules[__name__] = module(__name__, \"\")\n", "path": "pwndbg/proc.py"}, {"content": "\"\"\"\nStepping until an event occurs\n\"\"\"\n\nimport argparse\n\nimport gdb\n\nimport pwndbg.commands\nimport pwndbg.gdblib.next\n\n\n@pwndbg.commands.ArgparsedCommand(\"Breaks at the next jump instruction.\", aliases=[\"nextjump\"])\n@pwndbg.commands.OnlyWhenRunning\ndef nextjmp():\n    \"\"\"Breaks at the next jump instruction\"\"\"\n    if pwndbg.gdblib.next.break_next_branch():\n        pwndbg.commands.context.context()\n\n\nparser = argparse.ArgumentParser(description=\"\"\"Breaks at the next call instruction\"\"\")\nparser.add_argument(\n    \"symbol_regex\",\n    type=str,\n    default=None,\n    nargs=\"?\",\n    help=\"A regex matching the name of next symbol to be broken on before calling.\",\n)\n\n\n@pwndbg.commands.ArgparsedCommand(parser)\n@pwndbg.commands.OnlyWhenRunning\ndef nextcall(symbol_regex=None):\n    \"\"\"Breaks at the next call instruction\"\"\"\n    if pwndbg.gdblib.next.break_next_call(symbol_regex):\n        pwndbg.commands.context.context()\n\n\n@pwndbg.commands.ArgparsedCommand(\"\"\"Breaks at next return-like instruction\"\"\")\n@pwndbg.commands.OnlyWhenRunning\ndef nextret():\n    \"\"\"Breaks at next return-like instruction\"\"\"\n    if pwndbg.gdblib.next.break_next_ret():\n        pwndbg.commands.context.context()\n\n\n@pwndbg.commands.ArgparsedCommand(\"\"\"Breaks at next return-like instruction by 'stepping' to it\"\"\")\n@pwndbg.commands.OnlyWhenRunning\ndef stepret():\n    \"\"\"Breaks at next return-like instruction by 'stepping' to it\"\"\"\n    while (\n        pwndbg.proc.alive\n        and not pwndbg.gdblib.next.break_next_ret()\n        and pwndbg.gdblib.next.break_next_branch()\n    ):\n        # Here we are e.g. on a CALL instruction (temporarily breakpointed by `break_next_branch`)\n        # We need to step so that we take this branch instead of ignoring it\n        gdb.execute(\"si\")\n        continue\n\n    if pwndbg.proc.alive:\n        pwndbg.commands.context.context()\n\n\n@pwndbg.commands.ArgparsedCommand(\n    \"\"\"Breaks at the next instruction that belongs to the running program\"\"\"\n)\n@pwndbg.commands.OnlyWhenRunning\ndef nextproginstr():\n    pwndbg.gdblib.next.break_on_program_code()\n\n\nparser = argparse.ArgumentParser(\n    description=\"\"\"Sets a breakpoint on the instruction after this one\"\"\"\n)\nparser.add_argument(\"addr\", type=int, default=None, nargs=\"?\", help=\"The address to break after.\")\n\n\n@pwndbg.commands.ArgparsedCommand(parser, aliases=[\"so\"])\n@pwndbg.commands.OnlyWhenRunning\ndef stepover(addr=None):\n    \"\"\"Sets a breakpoint on the instruction after this one\"\"\"\n    pwndbg.gdblib.next.break_on_next(addr)\n\n\n@pwndbg.commands.ArgparsedCommand(\n    \"Breaks at the next syscall not taking branches.\", aliases=[\"nextsc\"]\n)\n@pwndbg.commands.OnlyWhenRunning\ndef nextsyscall():\n    \"\"\"\n    Breaks at the next syscall not taking branches.\n    \"\"\"\n    while (\n        pwndbg.proc.alive\n        and not pwndbg.gdblib.next.break_next_interrupt()\n        and pwndbg.gdblib.next.break_next_branch()\n    ):\n        continue\n\n    if pwndbg.proc.alive:\n        pwndbg.commands.context.context()\n\n\n@pwndbg.commands.ArgparsedCommand(\n    \"Breaks at the next syscall by taking branches.\", aliases=[\"stepsc\"]\n)\n@pwndbg.commands.OnlyWhenRunning\ndef stepsyscall():\n    \"\"\"\n    Breaks at the next syscall by taking branches.\n    \"\"\"\n    while (\n        pwndbg.proc.alive\n        and not pwndbg.gdblib.next.break_next_interrupt()\n        and pwndbg.gdblib.next.break_next_branch()\n    ):\n        # Here we are e.g. on a CALL instruction (temporarily breakpointed by `break_next_branch`)\n        # We need to step so that we take this branch instead of ignoring it\n        gdb.execute(\"si\")\n        continue\n\n    if pwndbg.proc.alive:\n        pwndbg.commands.context.context()\n", "path": "pwndbg/commands/next.py"}, {"content": "\"\"\"\nCommands for setting temporary breakpoints on the next\ninstruction of some type (call, branch, etc.)\n\"\"\"\n\nimport re\n\nimport capstone\nimport gdb\n\nimport pwndbg.disasm\nimport pwndbg.gdblib.events\nimport pwndbg.gdblib.regs\nimport pwndbg.proc\nfrom pwndbg.color import message\n\njumps = set((capstone.CS_GRP_CALL, capstone.CS_GRP_JUMP, capstone.CS_GRP_RET, capstone.CS_GRP_IRET))\n\ninterrupts = set((capstone.CS_GRP_INT,))\n\n\n@pwndbg.gdblib.events.exit\ndef clear_temp_breaks():\n    if not pwndbg.proc.alive:\n        breakpoints = gdb.breakpoints()\n        if breakpoints:\n            for bp in breakpoints:\n                if (\n                    bp.temporary and not bp.visible\n                ):  # visible is used instead of internal because older gdb's don't support internal\n                    bp.delete()\n\n\ndef next_int(address=None):\n    \"\"\"\n    If there is a syscall in the current basic black,\n    return the instruction of the one closest to $PC.\n\n    Otherwise, return None.\n    \"\"\"\n    if address is None:\n        ins = pwndbg.disasm.one(pwndbg.gdblib.regs.pc)\n        if not ins:\n            return None\n        address = ins.next\n\n    ins = pwndbg.disasm.one(address)\n    while ins:\n        if set(ins.groups) & jumps:\n            return None\n        if set(ins.groups) & interrupts:\n            return ins\n        ins = pwndbg.disasm.one(ins.next)\n\n    return None\n\n\ndef next_branch(address=None):\n    if address is None:\n        ins = pwndbg.disasm.one(pwndbg.gdblib.regs.pc)\n        if not ins:\n            return None\n        address = ins.next\n\n    ins = pwndbg.disasm.one(address)\n    while ins:\n        if set(ins.groups) & jumps:\n            return ins\n        ins = pwndbg.disasm.one(ins.next)\n\n    return None\n\n\ndef break_next_branch(address=None):\n    ins = next_branch(address)\n\n    if ins:\n        gdb.Breakpoint(\"*%#x\" % ins.address, internal=True, temporary=True)\n        gdb.execute(\"continue\", from_tty=False, to_string=True)\n        return ins\n\n\ndef break_next_interrupt(address=None):\n    ins = next_int(address)\n\n    if ins:\n        gdb.Breakpoint(\"*%#x\" % ins.address, internal=True, temporary=True)\n        gdb.execute(\"continue\", from_tty=False, to_string=True)\n        return ins\n\n\ndef break_next_call(symbol_regex=None):\n    while pwndbg.proc.alive:\n        ins = break_next_branch()\n\n        if not ins:\n            break\n\n        # continue if not a call\n        if capstone.CS_GRP_CALL not in ins.groups:\n            continue\n\n        # return call if we don't search for a symbol\n        if not symbol_regex:\n            return ins\n\n        # return call if we match target address\n        if ins.target_const and re.match(\"%s$\" % symbol_regex, hex(ins.target)):\n            return ins\n\n        # return call if we match symbol name\n        if ins.symbol and re.match(\"%s$\" % symbol_regex, ins.symbol):\n            return ins\n\n\ndef break_next_ret(address=None):\n    while pwndbg.proc.alive:\n        ins = break_next_branch(address)\n\n        if not ins:\n            break\n\n        if capstone.CS_GRP_RET in ins.groups:\n            return ins\n\n\ndef break_on_program_code():\n    \"\"\"\n    Breaks on next instruction that belongs to process' objfile code.\n    :return: True for success, False when process ended or when pc is at the code.\n    \"\"\"\n    exe = pwndbg.proc.exe\n    binary_exec_page_ranges = [\n        (p.start, p.end) for p in pwndbg.vmmap.get() if p.objfile == exe and p.execute\n    ]\n\n    pc = pwndbg.gdblib.regs.pc\n    for start, end in binary_exec_page_ranges:\n        if start <= pc < end:\n            print(message.error(\"The pc is already at the binary objfile code. Not stepping.\"))\n            return False\n\n    while pwndbg.proc.alive:\n        gdb.execute(\"si\", from_tty=False, to_string=False)\n\n        pc = pwndbg.gdblib.regs.pc\n        for start, end in binary_exec_page_ranges:\n            if start <= pc < end:\n                return True\n\n    return False\n\n\ndef break_on_next(address=None):\n    address = address or pwndbg.gdblib.regs.pc\n    ins = pwndbg.disasm.one(address)\n\n    gdb.Breakpoint(\"*%#x\" % (ins.address + ins.size), temporary=True)\n    gdb.execute(\"continue\", from_tty=False, to_string=True)\n", "path": "pwndbg/gdblib/next.py"}]}