We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
`telescope -r <num>` is broken
```
pwndbg> telescope -r 30
Traceback (most recent call last):
  File "/home/gsgx/code/pwndbg/pwndbg/commands/__init__.py", line 145, in __call__
    return self.function(*args, **kwargs)
  File "/home/gsgx/code/pwndbg/pwndbg/commands/__init__.py", line 216, in _OnlyWhenRunning
    return function(*a, **kw)
  File "/home/gsgx/code/pwndbg/pwndbg/commands/telescope.py", line 191, in telescope
    telescope.offset += i
UnboundLocalError: local variable 'i' referenced before assignment
```
`telescope -r` works fine though.

--- 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/commands/telescope.py`
Content:
```
1 """
2 Prints out pointer chains starting at some address in memory.
3 
4 Generally used to print out the stack or register values.
5 """
6 
7 import argparse
8 import collections
9 import math
10 
11 import pwndbg.chain
12 import pwndbg.color.telescope as T
13 import pwndbg.color.theme as theme
14 import pwndbg.commands
15 import pwndbg.config
16 import pwndbg.gdblib.arch
17 import pwndbg.gdblib.memory
18 import pwndbg.gdblib.regs
19 import pwndbg.gdblib.typeinfo
20 
21 telescope_lines = pwndbg.config.Parameter(
22     "telescope-lines", 8, "number of lines to printed by the telescope command"
23 )
24 skip_repeating_values = pwndbg.config.Parameter(
25     "telescope-skip-repeating-val",
26     True,
27     "whether to skip repeating values of the telescope command",
28 )
29 skip_repeating_values_minimum = pwndbg.config.Parameter(
30     "telescope-skip-repeating-val-minimum",
31     3,
32     "minimum amount of repeated values before skipping lines",
33 )
34 
35 offset_separator = theme.Parameter(
36     "telescope-offset-separator", "│", "offset separator of the telescope command"
37 )
38 offset_delimiter = theme.Parameter(
39     "telescope-offset-delimiter", ":", "offset delimiter of the telescope command"
40 )
41 repeating_marker = theme.Parameter(
42     "telescope-repeating-marker", "... ↓", "repeating values marker of the telescope command"
43 )
44 
45 
46 parser = argparse.ArgumentParser(
47     description="""
48     Recursively dereferences pointers starting at the specified address
49     ($sp by default)
50     """
51 )
52 parser.add_argument(
53     "address", nargs="?", default=None, type=int, help="The address to telescope at."
54 )
55 parser.add_argument(
56     "count", nargs="?", default=telescope_lines, type=int, help="The number of lines to show."
57 )
58 parser.add_argument(
59     "-r",
60     "--reverse",
61     dest="reverse",
62     action="store_true",
63     default=False,
64     help="Show <count> previous addresses instead of next ones",
65 )
66 
67 
68 @pwndbg.commands.ArgparsedCommand(parser)
69 @pwndbg.commands.OnlyWhenRunning
70 def telescope(address=None, count=telescope_lines, to_string=False, reverse=False):
71     """
72     Recursively dereferences pointers starting at the specified address
73     ($sp by default)
74     """
75     ptrsize = pwndbg.gdblib.typeinfo.ptrsize
76     if telescope.repeat:
77         address = telescope.last_address + ptrsize
78         telescope.offset += 1
79     else:
80         telescope.offset = 0
81 
82     address = int(address if address else pwndbg.gdblib.regs.sp) & pwndbg.gdblib.arch.ptrmask
83     count = max(int(count), 1) & pwndbg.gdblib.arch.ptrmask
84     delimiter = T.delimiter(offset_delimiter)
85     separator = T.separator(offset_separator)
86 
87     # Allow invocation of telescope -r to dump previous addresses
88     if reverse:
89         address -= (count - 1) * ptrsize
90 
91     # Allow invocation of "telescope 20" to dump 20 bytes at the stack pointer
92     if address < pwndbg.gdblib.memory.MMAP_MIN_ADDR and not pwndbg.gdblib.memory.peek(address):
93         count = address
94         address = pwndbg.gdblib.regs.sp
95 
96     # Allow invocation of "telescope a b" to dump all bytes from A to B
97     if int(address) <= int(count):
98         # adjust count if it is an address. use ceil division as count is number of
99         # ptrsize values and we don't want to strip out a value if dest is unaligned
100         count -= address
101         count = max(math.ceil(count / ptrsize), 1)
102 
103     reg_values = collections.defaultdict(lambda: [])
104     for reg in pwndbg.gdblib.regs.common:
105         reg_values[pwndbg.gdblib.regs[reg]].append(reg)
106     # address    = pwndbg.gdblib.memory.poi(pwndbg.gdblib.typeinfo.ppvoid, address)
107 
108     start = address
109     stop = address + (count * ptrsize)
110     step = ptrsize
111 
112     # Find all registers which show up in the trace
113     regs = {}
114     for i in range(start, stop, step):
115         values = list(reg_values[i])
116 
117         for width in range(1, pwndbg.gdblib.arch.ptrsize):
118             values.extend("%s-%i" % (r, width) for r in reg_values[i + width])
119 
120         regs[i] = " ".join(values)
121 
122     # Find the longest set of register information
123     if regs:
124         longest_regs = max(map(len, regs.values()))
125     else:
126         longest_regs = 0
127 
128     # Print everything out
129     result = []
130     last = None
131     collapse_buffer = []
132     skipped_padding = (
133         2
134         + len(offset_delimiter)
135         + 4
136         + len(offset_separator)
137         + 1
138         + longest_regs
139         + 1
140         - len(repeating_marker)
141     )
142 
143     # Collapse repeating values exceeding minimum delta.
144     def collapse_repeating_values():
145         # The first line was already printed, hence increment by 1
146         if collapse_buffer and len(collapse_buffer) + 1 >= skip_repeating_values_minimum:
147             result.append(
148                 T.repeating_marker(
149                     "%s%s%i skipped"
150                     % (repeating_marker, " " * skipped_padding, len(collapse_buffer))
151                 )
152             )
153         else:
154             result.extend(collapse_buffer)
155         collapse_buffer.clear()
156 
157     for i, addr in enumerate(range(start, stop, step)):
158         if not pwndbg.gdblib.memory.peek(addr):
159             collapse_repeating_values()
160             result.append("<Could not read memory at %#x>" % addr)
161             break
162 
163         line = " ".join(
164             (
165                 T.offset(
166                     "%02x%s%04x%s"
167                     % (
168                         i + telescope.offset,
169                         delimiter,
170                         addr - start + (telescope.offset * ptrsize),
171                         separator,
172                     )
173                 ),
174                 T.register(regs[addr].ljust(longest_regs)),
175                 pwndbg.chain.format(addr),
176             )
177         )
178 
179         # Buffer repeating values.
180         if skip_repeating_values:
181             value = pwndbg.gdblib.memory.pvoid(addr)
182             if last == value:
183                 collapse_buffer.append(line)
184                 continue
185             collapse_repeating_values()
186             last = value
187 
188         result.append(line)
189 
190     collapse_repeating_values()
191     telescope.offset += i
192     telescope.last_address = addr
193 
194     if not to_string:
195         print("\n".join(result))
196 
197     return result
198 
199 
200 parser = argparse.ArgumentParser(
201     description="dereferences on stack data with specified count and offset."
202 )
203 parser.add_argument("count", nargs="?", default=8, type=int, help="number of element to dump")
204 parser.add_argument(
205     "offset",
206     nargs="?",
207     default=0,
208     type=int,
209     help="Element offset from $sp (support negative offset)",
210 )
211 
212 
213 @pwndbg.commands.ArgparsedCommand(parser)
214 @pwndbg.commands.OnlyWhenRunning
215 def stack(count, offset):
216     ptrsize = pwndbg.gdblib.typeinfo.ptrsize
217     telescope.repeat = stack.repeat
218     telescope(address=pwndbg.gdblib.regs.sp + offset * ptrsize, count=count)
219 
220 
221 telescope.last_address = 0
222 telescope.offset = 0
223
```
--- 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/telescope.py b/pwndbg/commands/telescope.py
--- a/pwndbg/commands/telescope.py
+++ b/pwndbg/commands/telescope.py
@@ -49,12 +49,6 @@
     ($sp by default)
     """
 )
-parser.add_argument(
-    "address", nargs="?", default=None, type=int, help="The address to telescope at."
-)
-parser.add_argument(
-    "count", nargs="?", default=telescope_lines, type=int, help="The number of lines to show."
-)
 parser.add_argument(
     "-r",
     "--reverse",
@@ -64,6 +58,14 @@
     help="Show <count> previous addresses instead of next ones",
 )
 
+parser.add_argument(
+    "address", nargs="?", default=None, type=int, help="The address to telescope at."
+)
+
+parser.add_argument(
+    "count", nargs="?", default=telescope_lines, type=int, help="The number of lines to show."
+)
+
 
 @pwndbg.commands.ArgparsedCommand(parser)
 @pwndbg.commands.OnlyWhenRunning
@@ -84,15 +86,15 @@
     delimiter = T.delimiter(offset_delimiter)
     separator = T.separator(offset_separator)
 
-    # Allow invocation of telescope -r to dump previous addresses
-    if reverse:
-        address -= (count - 1) * ptrsize
-
     # Allow invocation of "telescope 20" to dump 20 bytes at the stack pointer
     if address < pwndbg.gdblib.memory.MMAP_MIN_ADDR and not pwndbg.gdblib.memory.peek(address):
         count = address
         address = pwndbg.gdblib.regs.sp
 
+    # Allow invocation of telescope -r to dump previous addresses
+    if reverse:
+        address -= (count - 1) * ptrsize
+
     # Allow invocation of "telescope a b" to dump all bytes from A to B
     if int(address) <= int(count):
         # adjust count if it is an address. use ceil division as count is number of
@@ -103,7 +105,6 @@
     reg_values = collections.defaultdict(lambda: [])
     for reg in pwndbg.gdblib.regs.common:
         reg_values[pwndbg.gdblib.regs[reg]].append(reg)
-    # address    = pwndbg.gdblib.memory.poi(pwndbg.gdblib.typeinfo.ppvoid, address)
 
     start = address
     stop = address + (count * ptrsize)

{"golden_diff": "diff --git a/pwndbg/commands/telescope.py b/pwndbg/commands/telescope.py\n--- a/pwndbg/commands/telescope.py\n+++ b/pwndbg/commands/telescope.py\n@@ -49,12 +49,6 @@\n     ($sp by default)\n     \"\"\"\n )\n-parser.add_argument(\n-    \"address\", nargs=\"?\", default=None, type=int, help=\"The address to telescope at.\"\n-)\n-parser.add_argument(\n-    \"count\", nargs=\"?\", default=telescope_lines, type=int, help=\"The number of lines to show.\"\n-)\n parser.add_argument(\n     \"-r\",\n     \"--reverse\",\n@@ -64,6 +58,14 @@\n     help=\"Show <count> previous addresses instead of next ones\",\n )\n \n+parser.add_argument(\n+    \"address\", nargs=\"?\", default=None, type=int, help=\"The address to telescope at.\"\n+)\n+\n+parser.add_argument(\n+    \"count\", nargs=\"?\", default=telescope_lines, type=int, help=\"The number of lines to show.\"\n+)\n+\n \n @pwndbg.commands.ArgparsedCommand(parser)\n @pwndbg.commands.OnlyWhenRunning\n@@ -84,15 +86,15 @@\n     delimiter = T.delimiter(offset_delimiter)\n     separator = T.separator(offset_separator)\n \n-    # Allow invocation of telescope -r to dump previous addresses\n-    if reverse:\n-        address -= (count - 1) * ptrsize\n-\n     # Allow invocation of \"telescope 20\" to dump 20 bytes at the stack pointer\n     if address < pwndbg.gdblib.memory.MMAP_MIN_ADDR and not pwndbg.gdblib.memory.peek(address):\n         count = address\n         address = pwndbg.gdblib.regs.sp\n \n+    # Allow invocation of telescope -r to dump previous addresses\n+    if reverse:\n+        address -= (count - 1) * ptrsize\n+\n     # Allow invocation of \"telescope a b\" to dump all bytes from A to B\n     if int(address) <= int(count):\n         # adjust count if it is an address. use ceil division as count is number of\n@@ -103,7 +105,6 @@\n     reg_values = collections.defaultdict(lambda: [])\n     for reg in pwndbg.gdblib.regs.common:\n         reg_values[pwndbg.gdblib.regs[reg]].append(reg)\n-    # address    = pwndbg.gdblib.memory.poi(pwndbg.gdblib.typeinfo.ppvoid, address)\n \n     start = address\n     stop = address + (count * ptrsize)\n", "issue": "`telescope -r <num>` is broken\n```\r\npwndbg> telescope -r 30\r\nTraceback (most recent call last):\r\n  File \"/home/gsgx/code/pwndbg/pwndbg/commands/__init__.py\", line 145, in __call__\r\n    return self.function(*args, **kwargs)\r\n  File \"/home/gsgx/code/pwndbg/pwndbg/commands/__init__.py\", line 216, in _OnlyWhenRunning\r\n    return function(*a, **kw)\r\n  File \"/home/gsgx/code/pwndbg/pwndbg/commands/telescope.py\", line 191, in telescope\r\n    telescope.offset += i\r\nUnboundLocalError: local variable 'i' referenced before assignment\r\n```\r\n`telescope -r` works fine though.\n", "before_files": [{"content": "\"\"\"\nPrints out pointer chains starting at some address in memory.\n\nGenerally used to print out the stack or register values.\n\"\"\"\n\nimport argparse\nimport collections\nimport math\n\nimport pwndbg.chain\nimport pwndbg.color.telescope as T\nimport pwndbg.color.theme as theme\nimport pwndbg.commands\nimport pwndbg.config\nimport pwndbg.gdblib.arch\nimport pwndbg.gdblib.memory\nimport pwndbg.gdblib.regs\nimport pwndbg.gdblib.typeinfo\n\ntelescope_lines = pwndbg.config.Parameter(\n    \"telescope-lines\", 8, \"number of lines to printed by the telescope command\"\n)\nskip_repeating_values = pwndbg.config.Parameter(\n    \"telescope-skip-repeating-val\",\n    True,\n    \"whether to skip repeating values of the telescope command\",\n)\nskip_repeating_values_minimum = pwndbg.config.Parameter(\n    \"telescope-skip-repeating-val-minimum\",\n    3,\n    \"minimum amount of repeated values before skipping lines\",\n)\n\noffset_separator = theme.Parameter(\n    \"telescope-offset-separator\", \"\u2502\", \"offset separator of the telescope command\"\n)\noffset_delimiter = theme.Parameter(\n    \"telescope-offset-delimiter\", \":\", \"offset delimiter of the telescope command\"\n)\nrepeating_marker = theme.Parameter(\n    \"telescope-repeating-marker\", \"... \u2193\", \"repeating values marker of the telescope command\"\n)\n\n\nparser = argparse.ArgumentParser(\n    description=\"\"\"\n    Recursively dereferences pointers starting at the specified address\n    ($sp by default)\n    \"\"\"\n)\nparser.add_argument(\n    \"address\", nargs=\"?\", default=None, type=int, help=\"The address to telescope at.\"\n)\nparser.add_argument(\n    \"count\", nargs=\"?\", default=telescope_lines, type=int, help=\"The number of lines to show.\"\n)\nparser.add_argument(\n    \"-r\",\n    \"--reverse\",\n    dest=\"reverse\",\n    action=\"store_true\",\n    default=False,\n    help=\"Show <count> previous addresses instead of next ones\",\n)\n\n\n@pwndbg.commands.ArgparsedCommand(parser)\n@pwndbg.commands.OnlyWhenRunning\ndef telescope(address=None, count=telescope_lines, to_string=False, reverse=False):\n    \"\"\"\n    Recursively dereferences pointers starting at the specified address\n    ($sp by default)\n    \"\"\"\n    ptrsize = pwndbg.gdblib.typeinfo.ptrsize\n    if telescope.repeat:\n        address = telescope.last_address + ptrsize\n        telescope.offset += 1\n    else:\n        telescope.offset = 0\n\n    address = int(address if address else pwndbg.gdblib.regs.sp) & pwndbg.gdblib.arch.ptrmask\n    count = max(int(count), 1) & pwndbg.gdblib.arch.ptrmask\n    delimiter = T.delimiter(offset_delimiter)\n    separator = T.separator(offset_separator)\n\n    # Allow invocation of telescope -r to dump previous addresses\n    if reverse:\n        address -= (count - 1) * ptrsize\n\n    # Allow invocation of \"telescope 20\" to dump 20 bytes at the stack pointer\n    if address < pwndbg.gdblib.memory.MMAP_MIN_ADDR and not pwndbg.gdblib.memory.peek(address):\n        count = address\n        address = pwndbg.gdblib.regs.sp\n\n    # Allow invocation of \"telescope a b\" to dump all bytes from A to B\n    if int(address) <= int(count):\n        # adjust count if it is an address. use ceil division as count is number of\n        # ptrsize values and we don't want to strip out a value if dest is unaligned\n        count -= address\n        count = max(math.ceil(count / ptrsize), 1)\n\n    reg_values = collections.defaultdict(lambda: [])\n    for reg in pwndbg.gdblib.regs.common:\n        reg_values[pwndbg.gdblib.regs[reg]].append(reg)\n    # address    = pwndbg.gdblib.memory.poi(pwndbg.gdblib.typeinfo.ppvoid, address)\n\n    start = address\n    stop = address + (count * ptrsize)\n    step = ptrsize\n\n    # Find all registers which show up in the trace\n    regs = {}\n    for i in range(start, stop, step):\n        values = list(reg_values[i])\n\n        for width in range(1, pwndbg.gdblib.arch.ptrsize):\n            values.extend(\"%s-%i\" % (r, width) for r in reg_values[i + width])\n\n        regs[i] = \" \".join(values)\n\n    # Find the longest set of register information\n    if regs:\n        longest_regs = max(map(len, regs.values()))\n    else:\n        longest_regs = 0\n\n    # Print everything out\n    result = []\n    last = None\n    collapse_buffer = []\n    skipped_padding = (\n        2\n        + len(offset_delimiter)\n        + 4\n        + len(offset_separator)\n        + 1\n        + longest_regs\n        + 1\n        - len(repeating_marker)\n    )\n\n    # Collapse repeating values exceeding minimum delta.\n    def collapse_repeating_values():\n        # The first line was already printed, hence increment by 1\n        if collapse_buffer and len(collapse_buffer) + 1 >= skip_repeating_values_minimum:\n            result.append(\n                T.repeating_marker(\n                    \"%s%s%i skipped\"\n                    % (repeating_marker, \" \" * skipped_padding, len(collapse_buffer))\n                )\n            )\n        else:\n            result.extend(collapse_buffer)\n        collapse_buffer.clear()\n\n    for i, addr in enumerate(range(start, stop, step)):\n        if not pwndbg.gdblib.memory.peek(addr):\n            collapse_repeating_values()\n            result.append(\"<Could not read memory at %#x>\" % addr)\n            break\n\n        line = \" \".join(\n            (\n                T.offset(\n                    \"%02x%s%04x%s\"\n                    % (\n                        i + telescope.offset,\n                        delimiter,\n                        addr - start + (telescope.offset * ptrsize),\n                        separator,\n                    )\n                ),\n                T.register(regs[addr].ljust(longest_regs)),\n                pwndbg.chain.format(addr),\n            )\n        )\n\n        # Buffer repeating values.\n        if skip_repeating_values:\n            value = pwndbg.gdblib.memory.pvoid(addr)\n            if last == value:\n                collapse_buffer.append(line)\n                continue\n            collapse_repeating_values()\n            last = value\n\n        result.append(line)\n\n    collapse_repeating_values()\n    telescope.offset += i\n    telescope.last_address = addr\n\n    if not to_string:\n        print(\"\\n\".join(result))\n\n    return result\n\n\nparser = argparse.ArgumentParser(\n    description=\"dereferences on stack data with specified count and offset.\"\n)\nparser.add_argument(\"count\", nargs=\"?\", default=8, type=int, help=\"number of element to dump\")\nparser.add_argument(\n    \"offset\",\n    nargs=\"?\",\n    default=0,\n    type=int,\n    help=\"Element offset from $sp (support negative offset)\",\n)\n\n\n@pwndbg.commands.ArgparsedCommand(parser)\n@pwndbg.commands.OnlyWhenRunning\ndef stack(count, offset):\n    ptrsize = pwndbg.gdblib.typeinfo.ptrsize\n    telescope.repeat = stack.repeat\n    telescope(address=pwndbg.gdblib.regs.sp + offset * ptrsize, count=count)\n\n\ntelescope.last_address = 0\ntelescope.offset = 0\n", "path": "pwndbg/commands/telescope.py"}], "after_files": [{"content": "\"\"\"\nPrints out pointer chains starting at some address in memory.\n\nGenerally used to print out the stack or register values.\n\"\"\"\n\nimport argparse\nimport collections\nimport math\n\nimport pwndbg.chain\nimport pwndbg.color.telescope as T\nimport pwndbg.color.theme as theme\nimport pwndbg.commands\nimport pwndbg.config\nimport pwndbg.gdblib.arch\nimport pwndbg.gdblib.memory\nimport pwndbg.gdblib.regs\nimport pwndbg.gdblib.typeinfo\n\ntelescope_lines = pwndbg.config.Parameter(\n    \"telescope-lines\", 8, \"number of lines to printed by the telescope command\"\n)\nskip_repeating_values = pwndbg.config.Parameter(\n    \"telescope-skip-repeating-val\",\n    True,\n    \"whether to skip repeating values of the telescope command\",\n)\nskip_repeating_values_minimum = pwndbg.config.Parameter(\n    \"telescope-skip-repeating-val-minimum\",\n    3,\n    \"minimum amount of repeated values before skipping lines\",\n)\n\noffset_separator = theme.Parameter(\n    \"telescope-offset-separator\", \"\u2502\", \"offset separator of the telescope command\"\n)\noffset_delimiter = theme.Parameter(\n    \"telescope-offset-delimiter\", \":\", \"offset delimiter of the telescope command\"\n)\nrepeating_marker = theme.Parameter(\n    \"telescope-repeating-marker\", \"... \u2193\", \"repeating values marker of the telescope command\"\n)\n\n\nparser = argparse.ArgumentParser(\n    description=\"\"\"\n    Recursively dereferences pointers starting at the specified address\n    ($sp by default)\n    \"\"\"\n)\nparser.add_argument(\n    \"-r\",\n    \"--reverse\",\n    dest=\"reverse\",\n    action=\"store_true\",\n    default=False,\n    help=\"Show <count> previous addresses instead of next ones\",\n)\n\nparser.add_argument(\n    \"address\", nargs=\"?\", default=None, type=int, help=\"The address to telescope at.\"\n)\n\nparser.add_argument(\n    \"count\", nargs=\"?\", default=telescope_lines, type=int, help=\"The number of lines to show.\"\n)\n\n\n@pwndbg.commands.ArgparsedCommand(parser)\n@pwndbg.commands.OnlyWhenRunning\ndef telescope(address=None, count=telescope_lines, to_string=False, reverse=False):\n    \"\"\"\n    Recursively dereferences pointers starting at the specified address\n    ($sp by default)\n    \"\"\"\n    ptrsize = pwndbg.gdblib.typeinfo.ptrsize\n    if telescope.repeat:\n        address = telescope.last_address + ptrsize\n        telescope.offset += 1\n    else:\n        telescope.offset = 0\n\n    address = int(address if address else pwndbg.gdblib.regs.sp) & pwndbg.gdblib.arch.ptrmask\n    count = max(int(count), 1) & pwndbg.gdblib.arch.ptrmask\n    delimiter = T.delimiter(offset_delimiter)\n    separator = T.separator(offset_separator)\n\n    # Allow invocation of \"telescope 20\" to dump 20 bytes at the stack pointer\n    if address < pwndbg.gdblib.memory.MMAP_MIN_ADDR and not pwndbg.gdblib.memory.peek(address):\n        count = address\n        address = pwndbg.gdblib.regs.sp\n\n    # Allow invocation of telescope -r to dump previous addresses\n    if reverse:\n        address -= (count - 1) * ptrsize\n\n    # Allow invocation of \"telescope a b\" to dump all bytes from A to B\n    if int(address) <= int(count):\n        # adjust count if it is an address. use ceil division as count is number of\n        # ptrsize values and we don't want to strip out a value if dest is unaligned\n        count -= address\n        count = max(math.ceil(count / ptrsize), 1)\n\n    reg_values = collections.defaultdict(lambda: [])\n    for reg in pwndbg.gdblib.regs.common:\n        reg_values[pwndbg.gdblib.regs[reg]].append(reg)\n\n    start = address\n    stop = address + (count * ptrsize)\n    step = ptrsize\n\n    # Find all registers which show up in the trace\n    regs = {}\n    for i in range(start, stop, step):\n        values = list(reg_values[i])\n\n        for width in range(1, pwndbg.gdblib.arch.ptrsize):\n            values.extend(\"%s-%i\" % (r, width) for r in reg_values[i + width])\n\n        regs[i] = \" \".join(values)\n\n    # Find the longest set of register information\n    if regs:\n        longest_regs = max(map(len, regs.values()))\n    else:\n        longest_regs = 0\n\n    # Print everything out\n    result = []\n    last = None\n    collapse_buffer = []\n    skipped_padding = (\n        2\n        + len(offset_delimiter)\n        + 4\n        + len(offset_separator)\n        + 1\n        + longest_regs\n        + 1\n        - len(repeating_marker)\n    )\n\n    # Collapse repeating values exceeding minimum delta.\n    def collapse_repeating_values():\n        # The first line was already printed, hence increment by 1\n        if collapse_buffer and len(collapse_buffer) + 1 >= skip_repeating_values_minimum:\n            result.append(\n                T.repeating_marker(\n                    \"%s%s%i skipped\"\n                    % (repeating_marker, \" \" * skipped_padding, len(collapse_buffer))\n                )\n            )\n        else:\n            result.extend(collapse_buffer)\n        collapse_buffer.clear()\n\n    for i, addr in enumerate(range(start, stop, step)):\n        if not pwndbg.gdblib.memory.peek(addr):\n            collapse_repeating_values()\n            result.append(\"<Could not read memory at %#x>\" % addr)\n            break\n\n        line = \" \".join(\n            (\n                T.offset(\n                    \"%02x%s%04x%s\"\n                    % (\n                        i + telescope.offset,\n                        delimiter,\n                        addr - start + (telescope.offset * ptrsize),\n                        separator,\n                    )\n                ),\n                T.register(regs[addr].ljust(longest_regs)),\n                pwndbg.chain.format(addr),\n            )\n        )\n\n        # Buffer repeating values.\n        if skip_repeating_values:\n            value = pwndbg.gdblib.memory.pvoid(addr)\n            if last == value:\n                collapse_buffer.append(line)\n                continue\n            collapse_repeating_values()\n            last = value\n\n        result.append(line)\n\n    collapse_repeating_values()\n    telescope.offset += i\n    telescope.last_address = addr\n\n    if not to_string:\n        print(\"\\n\".join(result))\n\n    return result\n\n\nparser = argparse.ArgumentParser(\n    description=\"dereferences on stack data with specified count and offset.\"\n)\nparser.add_argument(\"count\", nargs=\"?\", default=8, type=int, help=\"number of element to dump\")\nparser.add_argument(\n    \"offset\",\n    nargs=\"?\",\n    default=0,\n    type=int,\n    help=\"Element offset from $sp (support negative offset)\",\n)\n\n\n@pwndbg.commands.ArgparsedCommand(parser)\n@pwndbg.commands.OnlyWhenRunning\ndef stack(count, offset):\n    ptrsize = pwndbg.gdblib.typeinfo.ptrsize\n    telescope.repeat = stack.repeat\n    telescope(address=pwndbg.gdblib.regs.sp + offset * ptrsize, count=count)\n\n\ntelescope.last_address = 0\ntelescope.offset = 0\n", "path": "pwndbg/commands/telescope.py"}]}