From 2a064a9d1bbb8de6ce489b685cce026eee167cd2 Mon Sep 17 00:00:00 2001
From: johannst Gdb allows to create & document user commands as follows: To get all user commands or documentations one can use: Gdb allows to create two types of command Gdb allows to create two types of command This creates a User commands (macros)
+
+ define <cmd>
# cmds
end
@@ -221,23 +222,29 @@
document <cmd>
# docu
end
-
- help user-defined List user defined commands.
- help <cmd> List documentation for command <cmd>.
+
help user-defined
+ help <cmd>
Hooks
-hooks
which will be either executed
-before or after a certain command. define hook-<cmd> Run commands defined in hook before
- # cmds executing <cmd>.
+
hooks
+
+hook-
will be run before <cmd>
hookpost-
will be run after <cmd>
- define hook-<cmd>
+ # cmds
end
- define hookpost-<cmd> Run commands defined in hookpost after
- # cmds executing <cmd>.
+ define hookpost-<cmd>
+ # cmds
end
Flows
-Catch SIGSEGV and execute commands on occurrence
+Examples
+Catch SIGSEGV and execute commands
+catchpoint
for the SIGSEGV
signal and attached the command
+to it. catch signal SIGSEGV
command
bt
@@ -248,8 +255,9 @@ before or after a certain command.
gdb --batch -ex 'thread 1' -ex 'bt' -p <pid>
# run.gdb
- set pagination off
+To script gdb add commands into a file and pass it to gdb via -x
.
+For example create run.gdb
:
+ set pagination off
break mmap
command
@@ -262,20 +270,21 @@ before or after a certain command.
c
This script can be used as:
- gdb -p <pid> -x ./run.gdb --batch &> run.log
+ gdb --batch -x ./run.gdb -p <pid>
+Know Bugs
Workaround command + finish
bug
-When using finish
action inside a command
block, actions after finish
are
-not executed anymore. To workaround that bug one can create a wrapper function
-which calls finish
.
+When using finish
inside a command
block, commands after finish
are not
+executed. To workaround that bug one can create a wrapper function which calls
+finish
.
define handler
- bt
- finish
- info reg rax
+ bt
+ finish
+ info reg rax
end
command
- handler
+ handler
end
@@ -284,7 +293,7 @@ which calls finish
.