blob: 7888a376d8fd661f52f8f1d402a1564a18b011ee (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
import gdb
import gdb.prompt
from subprocess import check_output
from os import environ
class TryCommand(gdb.Command):
"""
Try evaluating the argument(s) as a regular GDB command, but do not fail if the command fails.
"""
def __init__(self):
super().__init__("try", gdb.COMMAND_USER)
def invoke(self, argument, from_tty):
try:
gdb.execute(argument)
except gdb.error:
pass
TryCommand()
def custom_prompt() -> str:
try:
env = environ
env["eo"] = "\\["
env["ec"] = "\\]"
prompt = check_output(["prompt", "gdb"], text=True, env=env)
return prompt
except Exception:
return "(gdb) "
# add custom prompt ("\P") escape code to extended-prompt
substitute_prompt = gdb.prompt.substitute_prompt
def new_substitute_prompt(prompt: str):
out = ""
escape = False
for char in prompt:
out += char
if not escape:
if char == "\\":
escape = True
continue
escape = False
if char == "P":
out = out[:-2] + custom_prompt()
out = substitute_prompt(out)
return out
gdb.prompt.substitute_prompt = new_substitute_prompt
|