aboutsummaryrefslogtreecommitdiff
path: root/.config/gdb
diff options
context:
space:
mode:
Diffstat (limited to '.config/gdb')
-rw-r--r--.config/gdb/gdbinit15
-rw-r--r--.config/gdb/gdbinit.py55
2 files changed, 61 insertions, 9 deletions
diff --git a/.config/gdb/gdbinit b/.config/gdb/gdbinit
index 919b13a..bf4a25d 100644
--- a/.config/gdb/gdbinit
+++ b/.config/gdb/gdbinit
@@ -1,9 +1,22 @@
+# load ./gdbinit.py
python
import sys, os
sys.path.append(os.path.join(os.environ["XDG_CONFIG_HOME"], "gdb"))
import gdbinit
end
-alias mk = !mk
+# preferences
+try set disassembly-flavor intel
+set debuginfod enabled off
+set confirm off
+set extended-prompt \P
+set history save on
+set history size 10000000
+set history remove-duplicates 100
+
+# aliases
alias reset = monitor reset
+# commands
+alias mk = !mk
+alias ls = !ls
diff --git a/.config/gdb/gdbinit.py b/.config/gdb/gdbinit.py
index a6ebfea..1a137c5 100644
--- a/.config/gdb/gdbinit.py
+++ b/.config/gdb/gdbinit.py
@@ -1,14 +1,53 @@
import gdb
+import gdb.prompt
-def try_execute(*args):
+from subprocess import DEVNULL, 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:
- gdb.execute(*args)
- except gdb.error:
- pass
+ 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()
-# x86 only
-try_execute("set disassembly-flavor intel")
+ out = substitute_prompt(out)
+ return out
-gdb.execute("set debuginfod enabled off")
-gdb.execute("set confirm off")
+gdb.prompt.substitute_prompt = new_substitute_prompt