@@ -86,7 +86,7 @@ def pid(self) -> int:
8686 def _attach_direct (self ):
8787 self ._gdb = unix_process ()(["gdb" , "-q" , "-p" , str (self ._pid )])
8888 self ._gdb .recvuntil (GDB_ATTACH_MSG )
89- init_msg = self ._gdb .recvuntil (self ._gdb_prompt , lookahead = True )
89+ init_msg = self ._gdb .recvuntil (self ._gdb_prompt , consume = False )
9090 if GDB_PTRACE_ERROR in init_msg :
9191 raise PermissionError (f"Cannot attach pid={ self ._pid } " )
9292
@@ -98,7 +98,7 @@ def _attach_with_sudo(self):
9898
9999 init_msg = b''
100100 for _ in range (3 ):
101- init_msg = self ._gdb .recvuntil ([CUSTOM_SUDO_PROMPT ] + self ._gdb_prompt , lookahead = True )
101+ init_msg = self ._gdb .recvuntil ([CUSTOM_SUDO_PROMPT ] + self ._gdb_prompt , consume = False )
102102 if CUSTOM_SUDO_PROMPT .encode () in init_msg :
103103 # Password is required (The user does not set NOPASSWD in sudoers)
104104 self ._gdb .sendlineafter (CUSTOM_SUDO_PROMPT , getpass .getpass (CUSTOM_SUDO_PROMPT ))
@@ -171,8 +171,7 @@ def execute(self,
171171 return result
172172
173173 self .gdb .after (self ._gdb_prompt ).sendline (command )
174- # TODO: self._gdb.before(self._gdb_prompt).lastline() to keep color sequence
175- result = self .gdb .recvuntil (self ._gdb_prompt , drop = True , lookahead = True )
174+ result = self .gdb .recvuntil (self ._gdb_prompt , drop = True , consume = False )
176175 # Remove ANSI escape sequences aggressively
177176 result = CTRL_RE .sub (b'' , ANSI_RE .sub (b'' , result )).decode ().strip ()
178177 if resume :
0 commit comments