Skip to content

Commit

Permalink
Handle the case that gdb.prompt_hook might have an error
Browse files Browse the repository at this point in the history
  • Loading branch information
lebr0nli committed Sep 7, 2023
1 parent 31e1dc6 commit f8a70db
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion gdbinit-gep.py
Original file line number Diff line number Diff line change
Expand Up @@ -472,11 +472,22 @@ def gep_prompt(current_prompt: str) -> None:
output=create_output(stdout=sys.__stdout__),
)
while True:
prompt_string = None
try:
# emulate the original prompt
prompt_string = gdb.prompt_hook(current_prompt) if gdb.prompt_hook else None
if prompt_string is None: # prompt string is set by gdb command
if prompt_string:
# If prompt_string is generated by gdb.prompt_hook, we update the prompt like native GDB
safe_prompt_string = "".join(
f"\\{ord(c):o}" if ord(c) < 0x100 else c for c in prompt_string
)
gdb.execute(f"set prompt {safe_prompt_string}", from_tty=False, to_string=True)
except Exception as e:
print(f"Python Exception {type(e)}: {e}")
finally:
if prompt_string is None:
prompt_string = gdb.parameter("prompt")
try:
prompt_string = prompt_string.replace("\001", "").replace(
"\002", ""
) # fix for ANSI prompt
Expand Down

0 comments on commit f8a70db

Please sign in to comment.