prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  The `ctx threads` (or `threads`) should display all threads no matter of context threads limit
  cc: @CptGibbon we should probably add this option for convenience :)
  
  --- 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/tls.py`
  Content:
  ```
  1 """
  2 Command to print the information of the current Thread Local Storage (TLS).
  3 """
  4 from __future__ import annotations
  5 
  6 import argparse
  7 
  8 import pwndbg.commands
  9 import pwndbg.gdblib.tls
  10 from pwndbg.color import message
  11 from pwndbg.commands import CommandCategory
  12 
  13 parser = argparse.ArgumentParser(
  14     formatter_class=argparse.RawTextHelpFormatter,
  15     description="Print out base address of the current Thread Local Storage (TLS).",
  16 )
  17 
  18 parser.add_argument(
  19     "-p",
  20     "--pthread-self",
  21     action="store_true",
  22     default=False,
  23     help="Try to get the address of TLS by calling pthread_self().",
  24 )
  25 
  26 
  27 @pwndbg.commands.ArgparsedCommand(parser, category=CommandCategory.LINUX)
  28 @pwndbg.commands.OnlyWhenRunning
  29 @pwndbg.commands.OnlyWhenUserspace
  30 def tls(pthread_self=False) -> None:
  31     tls_base = (
  32         pwndbg.gdblib.tls.find_address_with_register()
  33         if not pthread_self
  34         else pwndbg.gdblib.tls.find_address_with_pthread_self()
  35     )
  36     if pwndbg.gdblib.memory.is_readable_address(tls_base):
  37         print(message.success("Thread Local Storage (TLS) base: %#x" % tls_base))
  38         print(message.success("TLS is located at:"))
  39         print(message.notice(pwndbg.gdblib.vmmap.find(tls_base)))
  40         return
  41     print(message.error("Couldn't find Thread Local Storage (TLS) base."))
  42     if not pthread_self:
  43         print(
  44             message.notice(
  45                 "You can try to use -p/--pthread option to get the address of TLS by calling pthread_self().\n"
  46                 "(This might cause problems if the pthread_self() is not in libc or not initialized yet.)"
  47             )
  48         )
  49
  ```
  --- 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()
  
  ```
  
golden_diff: diff --git a/pwndbg/commands/tls.py b/pwndbg/commands/tls.py
  --- a/pwndbg/commands/tls.py
  +++ b/pwndbg/commands/tls.py
  @@ -5,6 +5,10 @@
   
   import argparse
   
  +import gdb
  +from tabulate import tabulate
  +
  +import pwndbg.color.memory as M
   import pwndbg.commands
   import pwndbg.gdblib.tls
   from pwndbg.color import message
  @@ -46,3 +50,97 @@
                   "(This might cause problems if the pthread_self() is not in libc or not initialized yet.)"
               )
           )
  +
  +
  +parser = argparse.ArgumentParser(
  +    formatter_class=argparse.RawTextHelpFormatter,
  +    description="List all threads belonging to the selected inferior.",
  +)
  +group = parser.add_mutually_exclusive_group()
  +
  +group.add_argument(
  +    "num_threads",
  +    type=int,
  +    nargs="?",
  +    default=None,
  +    help="Number of threads to display. Omit to display all threads.",
  +)
  +
  +group.add_argument(
  +    "-c",
  +    "--config",
  +    action="store_true",
  +    dest="respect_config",
  +    help="Respect context-max-threads config to limit number of threads displayed.",
  +)
  +
  +
  +@pwndbg.commands.ArgparsedCommand(parser, category=CommandCategory.LINUX)
  +@pwndbg.commands.OnlyWhenRunning
  +@pwndbg.commands.OnlyWhenUserspace
  +def threads(num_threads, respect_config) -> None:
  +    table = []
  +    headers = ["global_num", "name", "status", "pc", "symbol"]
  +    bold_green = lambda text: pwndbg.color.bold(pwndbg.color.green(text))
  +
  +    try:
  +        original_thread = gdb.selected_thread()
  +    except SystemError:
  +        original_thread = None
  +
  +    all_threads = gdb.selected_inferior().threads()[::-1]
  +
  +    displayed_threads = []
  +
  +    if original_thread is not None and original_thread.is_valid():
  +        displayed_threads.append(original_thread)
  +
  +    for thread in all_threads:
  +        if respect_config and len(displayed_threads) >= int(
  +            pwndbg.commands.context.config_max_threads_display
  +        ):
  +            break
  +        elif num_threads is not None and len(displayed_threads) >= num_threads:
  +            break
  +
  +        if thread.is_valid() and thread is not original_thread:
  +            displayed_threads.append(thread)
  +
  +    for thread in displayed_threads:
  +        name = thread.name or ""
  +
  +        if thread is original_thread:
  +            row = [
  +                bold_green(thread.global_num),
  +                bold_green(name),
  +            ]
  +        else:
  +            row = [
  +                thread.global_num,
  +                name,
  +            ]
  +
  +        row.append(pwndbg.commands.context.get_thread_status(thread))
  +
  +        if thread.is_stopped():
  +            thread.switch()
  +            pc = gdb.selected_frame().pc()
  +
  +            pc_colored = M.get(pc)
  +            symbol = pwndbg.gdblib.symbol.get(pc)
  +
  +            row.append(pc_colored)
  +
  +            if symbol:
  +                if thread is original_thread:
  +                    row.append(bold_green(symbol))
  +                else:
  +                    row.append(symbol)
  +
  +        table.append(row)
  +
  +    if original_thread is not None and original_thread.is_valid():
  +        original_thread.switch()
  +
  +    print(tabulate(table, headers))
  +    print(f"\nShowing {len(displayed_threads)} of {len(all_threads)} threads.")
  
verification_info: {"golden_diff": "diff --git a/pwndbg/commands/tls.py b/pwndbg/commands/tls.py\n--- a/pwndbg/commands/tls.py\n+++ b/pwndbg/commands/tls.py\n@@ -5,6 +5,10 @@\n \n import argparse\n \n+import gdb\n+from tabulate import tabulate\n+\n+import pwndbg.color.memory as M\n import pwndbg.commands\n import pwndbg.gdblib.tls\n from pwndbg.color import message\n@@ -46,3 +50,97 @@\n                 \"(This might cause problems if the pthread_self() is not in libc or not initialized yet.)\"\n             )\n         )\n+\n+\n+parser = argparse.ArgumentParser(\n+    formatter_class=argparse.RawTextHelpFormatter,\n+    description=\"List all threads belonging to the selected inferior.\",\n+)\n+group = parser.add_mutually_exclusive_group()\n+\n+group.add_argument(\n+    \"num_threads\",\n+    type=int,\n+    nargs=\"?\",\n+    default=None,\n+    help=\"Number of threads to display. Omit to display all threads.\",\n+)\n+\n+group.add_argument(\n+    \"-c\",\n+    \"--config\",\n+    action=\"store_true\",\n+    dest=\"respect_config\",\n+    help=\"Respect context-max-threads config to limit number of threads displayed.\",\n+)\n+\n+\n+@pwndbg.commands.ArgparsedCommand(parser, category=CommandCategory.LINUX)\n+@pwndbg.commands.OnlyWhenRunning\n+@pwndbg.commands.OnlyWhenUserspace\n+def threads(num_threads, respect_config) -> None:\n+    table = []\n+    headers = [\"global_num\", \"name\", \"status\", \"pc\", \"symbol\"]\n+    bold_green = lambda text: pwndbg.color.bold(pwndbg.color.green(text))\n+\n+    try:\n+        original_thread = gdb.selected_thread()\n+    except SystemError:\n+        original_thread = None\n+\n+    all_threads = gdb.selected_inferior().threads()[::-1]\n+\n+    displayed_threads = []\n+\n+    if original_thread is not None and original_thread.is_valid():\n+        displayed_threads.append(original_thread)\n+\n+    for thread in all_threads:\n+        if respect_config and len(displayed_threads) >= int(\n+            pwndbg.commands.context.config_max_threads_display\n+        ):\n+            break\n+        elif num_threads is not None and len(displayed_threads) >= num_threads:\n+            break\n+\n+        if thread.is_valid() and thread is not original_thread:\n+            displayed_threads.append(thread)\n+\n+    for thread in displayed_threads:\n+        name = thread.name or \"\"\n+\n+        if thread is original_thread:\n+            row = [\n+                bold_green(thread.global_num),\n+                bold_green(name),\n+            ]\n+        else:\n+            row = [\n+                thread.global_num,\n+                name,\n+            ]\n+\n+        row.append(pwndbg.commands.context.get_thread_status(thread))\n+\n+        if thread.is_stopped():\n+            thread.switch()\n+            pc = gdb.selected_frame().pc()\n+\n+            pc_colored = M.get(pc)\n+            symbol = pwndbg.gdblib.symbol.get(pc)\n+\n+            row.append(pc_colored)\n+\n+            if symbol:\n+                if thread is original_thread:\n+                    row.append(bold_green(symbol))\n+                else:\n+                    row.append(symbol)\n+\n+        table.append(row)\n+\n+    if original_thread is not None and original_thread.is_valid():\n+        original_thread.switch()\n+\n+    print(tabulate(table, headers))\n+    print(f\"\\nShowing {len(displayed_threads)} of {len(all_threads)} threads.\")\n", "issue": "The `ctx threads` (or `threads`) should display all threads no matter of context threads limit\ncc: @CptGibbon we should probably add this option for convenience :)\n", "before_files": [{"content": "\"\"\"\nCommand to print the information of the current Thread Local Storage (TLS).\n\"\"\"\nfrom __future__ import annotations\n\nimport argparse\n\nimport pwndbg.commands\nimport pwndbg.gdblib.tls\nfrom pwndbg.color import message\nfrom pwndbg.commands import CommandCategory\n\nparser = argparse.ArgumentParser(\n    formatter_class=argparse.RawTextHelpFormatter,\n    description=\"Print out base address of the current Thread Local Storage (TLS).\",\n)\n\nparser.add_argument(\n    \"-p\",\n    \"--pthread-self\",\n    action=\"store_true\",\n    default=False,\n    help=\"Try to get the address of TLS by calling pthread_self().\",\n)\n\n\n@pwndbg.commands.ArgparsedCommand(parser, category=CommandCategory.LINUX)\n@pwndbg.commands.OnlyWhenRunning\n@pwndbg.commands.OnlyWhenUserspace\ndef tls(pthread_self=False) -> None:\n    tls_base = (\n        pwndbg.gdblib.tls.find_address_with_register()\n        if not pthread_self\n        else pwndbg.gdblib.tls.find_address_with_pthread_self()\n    )\n    if pwndbg.gdblib.memory.is_readable_address(tls_base):\n        print(message.success(\"Thread Local Storage (TLS) base: %#x\" % tls_base))\n        print(message.success(\"TLS is located at:\"))\n        print(message.notice(pwndbg.gdblib.vmmap.find(tls_base)))\n        return\n    print(message.error(\"Couldn't find Thread Local Storage (TLS) base.\"))\n    if not pthread_self:\n        print(\n            message.notice(\n                \"You can try to use -p/--pthread option to get the address of TLS by calling pthread_self().\\n\"\n                \"(This might cause problems if the pthread_self() is not in libc or not initialized yet.)\"\n            )\n        )\n", "path": "pwndbg/commands/tls.py"}], "after_files": [{"content": "\"\"\"\nCommand to print the information of the current Thread Local Storage (TLS).\n\"\"\"\nfrom __future__ import annotations\n\nimport argparse\n\nimport gdb\nfrom tabulate import tabulate\n\nimport pwndbg.color.memory as M\nimport pwndbg.commands\nimport pwndbg.gdblib.tls\nfrom pwndbg.color import message\nfrom pwndbg.commands import CommandCategory\n\nparser = argparse.ArgumentParser(\n    formatter_class=argparse.RawTextHelpFormatter,\n    description=\"Print out base address of the current Thread Local Storage (TLS).\",\n)\n\nparser.add_argument(\n    \"-p\",\n    \"--pthread-self\",\n    action=\"store_true\",\n    default=False,\n    help=\"Try to get the address of TLS by calling pthread_self().\",\n)\n\n\n@pwndbg.commands.ArgparsedCommand(parser, category=CommandCategory.LINUX)\n@pwndbg.commands.OnlyWhenRunning\n@pwndbg.commands.OnlyWhenUserspace\ndef tls(pthread_self=False) -> None:\n    tls_base = (\n        pwndbg.gdblib.tls.find_address_with_register()\n        if not pthread_self\n        else pwndbg.gdblib.tls.find_address_with_pthread_self()\n    )\n    if pwndbg.gdblib.memory.is_readable_address(tls_base):\n        print(message.success(\"Thread Local Storage (TLS) base: %#x\" % tls_base))\n        print(message.success(\"TLS is located at:\"))\n        print(message.notice(pwndbg.gdblib.vmmap.find(tls_base)))\n        return\n    print(message.error(\"Couldn't find Thread Local Storage (TLS) base.\"))\n    if not pthread_self:\n        print(\n            message.notice(\n                \"You can try to use -p/--pthread option to get the address of TLS by calling pthread_self().\\n\"\n                \"(This might cause problems if the pthread_self() is not in libc or not initialized yet.)\"\n            )\n        )\n\n\nparser = argparse.ArgumentParser(\n    formatter_class=argparse.RawTextHelpFormatter,\n    description=\"List all threads belonging to the selected inferior.\",\n)\ngroup = parser.add_mutually_exclusive_group()\n\ngroup.add_argument(\n    \"num_threads\",\n    type=int,\n    nargs=\"?\",\n    default=None,\n    help=\"Number of threads to display. Omit to display all threads.\",\n)\n\ngroup.add_argument(\n    \"-c\",\n    \"--config\",\n    action=\"store_true\",\n    dest=\"respect_config\",\n    help=\"Respect context-max-threads config to limit number of threads displayed.\",\n)\n\n\n@pwndbg.commands.ArgparsedCommand(parser, category=CommandCategory.LINUX)\n@pwndbg.commands.OnlyWhenRunning\n@pwndbg.commands.OnlyWhenUserspace\ndef threads(num_threads, respect_config) -> None:\n    table = []\n    headers = [\"global_num\", \"name\", \"status\", \"pc\", \"symbol\"]\n    bold_green = lambda text: pwndbg.color.bold(pwndbg.color.green(text))\n\n    try:\n        original_thread = gdb.selected_thread()\n    except SystemError:\n        original_thread = None\n\n    all_threads = gdb.selected_inferior().threads()[::-1]\n\n    displayed_threads = []\n\n    if original_thread is not None and original_thread.is_valid():\n        displayed_threads.append(original_thread)\n\n    for thread in all_threads:\n        if respect_config and len(displayed_threads) >= int(\n            pwndbg.commands.context.config_max_threads_display\n        ):\n            break\n        elif num_threads is not None and len(displayed_threads) >= num_threads:\n            break\n\n        if thread.is_valid() and thread is not original_thread:\n            displayed_threads.append(thread)\n\n    for thread in displayed_threads:\n        name = thread.name or \"\"\n\n        if thread is original_thread:\n            row = [\n                bold_green(thread.global_num),\n                bold_green(name),\n            ]\n        else:\n            row = [\n                thread.global_num,\n                name,\n            ]\n\n        row.append(pwndbg.commands.context.get_thread_status(thread))\n\n        if thread.is_stopped():\n            thread.switch()\n            pc = gdb.selected_frame().pc()\n\n            pc_colored = M.get(pc)\n            symbol = pwndbg.gdblib.symbol.get(pc)\n\n            row.append(pc_colored)\n\n            if symbol:\n                if thread is original_thread:\n                    row.append(bold_green(symbol))\n                else:\n                    row.append(symbol)\n\n        table.append(row)\n\n    if original_thread is not None and original_thread.is_valid():\n        original_thread.switch()\n\n    print(tabulate(table, headers))\n    print(f\"\\nShowing {len(displayed_threads)} of {len(all_threads)} threads.\")\n", "path": "pwndbg/commands/tls.py"}]}