prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  `context` sometimes gets printed with the `set` command
  `set $rax=0` sometimes causes `context` to be immediately called afterwards. I think don't think this is always reproducible, but will keep investigating it.
  
  --- 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/gdblib/prompt.py`
  Content:
  ```
  1 import re
  2 
  3 import gdb
  4 
  5 import pwndbg.decorators
  6 import pwndbg.gdblib.events
  7 import pwndbg.gdbutils
  8 import pwndbg.lib.memoize
  9 from pwndbg.color import disable_colors
  10 from pwndbg.color import message
  11 from pwndbg.lib.tips import get_tip_of_the_day
  12 
  13 funcs_list_str = ", ".join(
  14     message.notice("$" + f.name) for f in pwndbg.gdbutils.functions.functions
  15 )
  16 
  17 num_pwndbg_cmds = sum(1 for _ in filter(lambda c: not c.shell, pwndbg.commands.commands))
  18 num_shell_cmds = sum(1 for _ in filter(lambda c: c.shell, pwndbg.commands.commands))
  19 hint_lines = (
  20     "loaded %i pwndbg commands and %i shell commands. Type %s for a list."
  21     % (num_pwndbg_cmds, num_shell_cmds, message.notice("pwndbg [--shell | --all] [filter]")),
  22     "created %s gdb functions (can be used with print/break)" % funcs_list_str,
  23 )
  24 
  25 for line in hint_lines:
  26     print(message.prompt("pwndbg: ") + message.system(line))
  27 
  28 # noinspection PyPackageRequirements
  29 show_tip = pwndbg.config.Parameter(
  30     "show-tips", True, "whether to display the tip of the day on startup"
  31 )
  32 
  33 cur = None
  34 
  35 
  36 def initial_hook(*a):
  37     if show_tip and not pwndbg.decorators.first_prompt:
  38         colored_tip = re.sub(
  39             "`(.*?)`", lambda s: message.warn(s.group()[1:-1]), get_tip_of_the_day()
  40         )
  41         print(
  42             message.prompt("------- tip of the day")
  43             + message.system(" (disable with %s)" % message.notice("set show-tips off"))
  44             + message.prompt(" -------")
  45         )
  46         print((colored_tip))
  47     pwndbg.decorators.first_prompt = True
  48 
  49     prompt_hook(*a)
  50     gdb.prompt_hook = prompt_hook
  51 
  52 
  53 def prompt_hook(*a):
  54     global cur
  55 
  56     new = (gdb.selected_inferior(), gdb.selected_thread())
  57 
  58     if cur != new:
  59         pwndbg.gdblib.events.after_reload(start=cur is None)
  60         cur = new
  61 
  62     if pwndbg.proc.alive and pwndbg.proc.thread_is_stopped:
  63         prompt_hook_on_stop(*a)
  64 
  65 
  66 @pwndbg.lib.memoize.reset_on_stop
  67 def prompt_hook_on_stop(*a):
  68     pwndbg.commands.context.context()
  69 
  70 
  71 @pwndbg.config.Trigger([message.config_prompt_color, disable_colors])
  72 def set_prompt():
  73     prompt = "pwndbg> "
  74 
  75     if not disable_colors:
  76         prompt = "\x02" + prompt + "\x01"  # STX + prompt + SOH
  77         prompt = message.prompt(prompt)
  78         prompt = "\x01" + prompt + "\x02"  # SOH + prompt + STX
  79 
  80     gdb.execute("set prompt %s" % prompt)
  81 
  82 
  83 if pwndbg.gdblib.events.before_prompt_event.is_real_event:
  84     gdb.prompt_hook = initial_hook
  85 
  86 else:
  87     # Old GDBs doesn't have gdb.events.before_prompt, so we will emulate it using gdb.prompt_hook
  88     def extended_prompt_hook(*a):
  89         pwndbg.gdblib.events.before_prompt_event.invoke_callbacks()
  90         return prompt_hook(*a)
  91 
  92     gdb.prompt_hook = extended_prompt_hook
  93
  ```
  --- 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/gdblib/prompt.py b/pwndbg/gdblib/prompt.py
  --- a/pwndbg/gdblib/prompt.py
  +++ b/pwndbg/gdblib/prompt.py
  @@ -50,8 +50,11 @@
       gdb.prompt_hook = prompt_hook
   
   
  +context_shown = False
  +
  +
   def prompt_hook(*a):
  -    global cur
  +    global cur, context_shown
   
       new = (gdb.selected_inferior(), gdb.selected_thread())
   
  @@ -59,13 +62,15 @@
           pwndbg.gdblib.events.after_reload(start=cur is None)
           cur = new
   
  -    if pwndbg.proc.alive and pwndbg.proc.thread_is_stopped:
  -        prompt_hook_on_stop(*a)
  +    if pwndbg.proc.alive and pwndbg.proc.thread_is_stopped and not context_shown:
  +        pwndbg.commands.context.context()
  +        context_shown = True
   
   
  -@pwndbg.lib.memoize.reset_on_stop
  -def prompt_hook_on_stop(*a):
  -    pwndbg.commands.context.context()
  +@pwndbg.gdblib.events.cont
  +def reset_context_shown(*a):
  +    global context_shown
  +    context_shown = False
   
   
   @pwndbg.config.Trigger([message.config_prompt_color, disable_colors])
  
verification_info: {"golden_diff": "diff --git a/pwndbg/gdblib/prompt.py b/pwndbg/gdblib/prompt.py\n--- a/pwndbg/gdblib/prompt.py\n+++ b/pwndbg/gdblib/prompt.py\n@@ -50,8 +50,11 @@\n     gdb.prompt_hook = prompt_hook\n \n \n+context_shown = False\n+\n+\n def prompt_hook(*a):\n-    global cur\n+    global cur, context_shown\n \n     new = (gdb.selected_inferior(), gdb.selected_thread())\n \n@@ -59,13 +62,15 @@\n         pwndbg.gdblib.events.after_reload(start=cur is None)\n         cur = new\n \n-    if pwndbg.proc.alive and pwndbg.proc.thread_is_stopped:\n-        prompt_hook_on_stop(*a)\n+    if pwndbg.proc.alive and pwndbg.proc.thread_is_stopped and not context_shown:\n+        pwndbg.commands.context.context()\n+        context_shown = True\n \n \n-@pwndbg.lib.memoize.reset_on_stop\n-def prompt_hook_on_stop(*a):\n-    pwndbg.commands.context.context()\n+@pwndbg.gdblib.events.cont\n+def reset_context_shown(*a):\n+    global context_shown\n+    context_shown = False\n \n \n @pwndbg.config.Trigger([message.config_prompt_color, disable_colors])\n", "issue": "`context` sometimes gets printed with the `set` command\n`set $rax=0` sometimes causes `context` to be immediately called afterwards. I think don't think this is always reproducible, but will keep investigating it.\n", "before_files": [{"content": "import re\n\nimport gdb\n\nimport pwndbg.decorators\nimport pwndbg.gdblib.events\nimport pwndbg.gdbutils\nimport pwndbg.lib.memoize\nfrom pwndbg.color import disable_colors\nfrom pwndbg.color import message\nfrom pwndbg.lib.tips import get_tip_of_the_day\n\nfuncs_list_str = \", \".join(\n    message.notice(\"$\" + f.name) for f in pwndbg.gdbutils.functions.functions\n)\n\nnum_pwndbg_cmds = sum(1 for _ in filter(lambda c: not c.shell, pwndbg.commands.commands))\nnum_shell_cmds = sum(1 for _ in filter(lambda c: c.shell, pwndbg.commands.commands))\nhint_lines = (\n    \"loaded %i pwndbg commands and %i shell commands. Type %s for a list.\"\n    % (num_pwndbg_cmds, num_shell_cmds, message.notice(\"pwndbg [--shell | --all] [filter]\")),\n    \"created %s gdb functions (can be used with print/break)\" % funcs_list_str,\n)\n\nfor line in hint_lines:\n    print(message.prompt(\"pwndbg: \") + message.system(line))\n\n# noinspection PyPackageRequirements\nshow_tip = pwndbg.config.Parameter(\n    \"show-tips\", True, \"whether to display the tip of the day on startup\"\n)\n\ncur = None\n\n\ndef initial_hook(*a):\n    if show_tip and not pwndbg.decorators.first_prompt:\n        colored_tip = re.sub(\n            \"`(.*?)`\", lambda s: message.warn(s.group()[1:-1]), get_tip_of_the_day()\n        )\n        print(\n            message.prompt(\"------- tip of the day\")\n            + message.system(\" (disable with %s)\" % message.notice(\"set show-tips off\"))\n            + message.prompt(\" -------\")\n        )\n        print((colored_tip))\n    pwndbg.decorators.first_prompt = True\n\n    prompt_hook(*a)\n    gdb.prompt_hook = prompt_hook\n\n\ndef prompt_hook(*a):\n    global cur\n\n    new = (gdb.selected_inferior(), gdb.selected_thread())\n\n    if cur != new:\n        pwndbg.gdblib.events.after_reload(start=cur is None)\n        cur = new\n\n    if pwndbg.proc.alive and pwndbg.proc.thread_is_stopped:\n        prompt_hook_on_stop(*a)\n\n\n@pwndbg.lib.memoize.reset_on_stop\ndef prompt_hook_on_stop(*a):\n    pwndbg.commands.context.context()\n\n\n@pwndbg.config.Trigger([message.config_prompt_color, disable_colors])\ndef set_prompt():\n    prompt = \"pwndbg> \"\n\n    if not disable_colors:\n        prompt = \"\\x02\" + prompt + \"\\x01\"  # STX + prompt + SOH\n        prompt = message.prompt(prompt)\n        prompt = \"\\x01\" + prompt + \"\\x02\"  # SOH + prompt + STX\n\n    gdb.execute(\"set prompt %s\" % prompt)\n\n\nif pwndbg.gdblib.events.before_prompt_event.is_real_event:\n    gdb.prompt_hook = initial_hook\n\nelse:\n    # Old GDBs doesn't have gdb.events.before_prompt, so we will emulate it using gdb.prompt_hook\n    def extended_prompt_hook(*a):\n        pwndbg.gdblib.events.before_prompt_event.invoke_callbacks()\n        return prompt_hook(*a)\n\n    gdb.prompt_hook = extended_prompt_hook\n", "path": "pwndbg/gdblib/prompt.py"}], "after_files": [{"content": "import re\n\nimport gdb\n\nimport pwndbg.decorators\nimport pwndbg.gdblib.events\nimport pwndbg.gdbutils\nimport pwndbg.lib.memoize\nfrom pwndbg.color import disable_colors\nfrom pwndbg.color import message\nfrom pwndbg.lib.tips import get_tip_of_the_day\n\nfuncs_list_str = \", \".join(\n    message.notice(\"$\" + f.name) for f in pwndbg.gdbutils.functions.functions\n)\n\nnum_pwndbg_cmds = sum(1 for _ in filter(lambda c: not c.shell, pwndbg.commands.commands))\nnum_shell_cmds = sum(1 for _ in filter(lambda c: c.shell, pwndbg.commands.commands))\nhint_lines = (\n    \"loaded %i pwndbg commands and %i shell commands. Type %s for a list.\"\n    % (num_pwndbg_cmds, num_shell_cmds, message.notice(\"pwndbg [--shell | --all] [filter]\")),\n    \"created %s gdb functions (can be used with print/break)\" % funcs_list_str,\n)\n\nfor line in hint_lines:\n    print(message.prompt(\"pwndbg: \") + message.system(line))\n\n# noinspection PyPackageRequirements\nshow_tip = pwndbg.config.Parameter(\n    \"show-tips\", True, \"whether to display the tip of the day on startup\"\n)\n\ncur = None\n\n\ndef initial_hook(*a):\n    if show_tip and not pwndbg.decorators.first_prompt:\n        colored_tip = re.sub(\n            \"`(.*?)`\", lambda s: message.warn(s.group()[1:-1]), get_tip_of_the_day()\n        )\n        print(\n            message.prompt(\"------- tip of the day\")\n            + message.system(\" (disable with %s)\" % message.notice(\"set show-tips off\"))\n            + message.prompt(\" -------\")\n        )\n        print((colored_tip))\n    pwndbg.decorators.first_prompt = True\n\n    prompt_hook(*a)\n    gdb.prompt_hook = prompt_hook\n\n\ncontext_shown = False\n\n\ndef prompt_hook(*a):\n    global cur, context_shown\n\n    new = (gdb.selected_inferior(), gdb.selected_thread())\n\n    if cur != new:\n        pwndbg.gdblib.events.after_reload(start=cur is None)\n        cur = new\n\n    if pwndbg.proc.alive and pwndbg.proc.thread_is_stopped and not context_shown:\n        pwndbg.commands.context.context()\n        context_shown = True\n\n\n@pwndbg.gdblib.events.cont\ndef reset_context_shown(*a):\n    global context_shown\n    context_shown = False\n\n\n@pwndbg.config.Trigger([message.config_prompt_color, disable_colors])\ndef set_prompt():\n    prompt = \"pwndbg> \"\n\n    if not disable_colors:\n        prompt = \"\\x02\" + prompt + \"\\x01\"  # STX + prompt + SOH\n        prompt = message.prompt(prompt)\n        prompt = \"\\x01\" + prompt + \"\\x02\"  # SOH + prompt + STX\n\n    gdb.execute(\"set prompt %s\" % prompt)\n\n\nif pwndbg.gdblib.events.before_prompt_event.is_real_event:\n    gdb.prompt_hook = initial_hook\n\nelse:\n    # Old GDBs doesn't have gdb.events.before_prompt, so we will emulate it using gdb.prompt_hook\n    def extended_prompt_hook(*a):\n        pwndbg.gdblib.events.before_prompt_event.invoke_callbacks()\n        return prompt_hook(*a)\n\n    gdb.prompt_hook = extended_prompt_hook\n", "path": "pwndbg/gdblib/prompt.py"}]}