From 2a064a9d1bbb8de6ce489b685cce026eee167cd2 Mon Sep 17 00:00:00 2001 From: johannst Date: Tue, 17 Mar 2020 22:48:49 +0000 Subject: deploy: fb719f52b73920fb18c7f3080ebb1fc73300be49 --- gdb.html | 57 +++++++++++++++++++++++++++++++++------------------------ 1 file changed, 33 insertions(+), 24 deletions(-) (limited to 'gdb.html') diff --git a/gdb.html b/gdb.html index 08ca0da..4957850 100644 --- a/gdb.html +++ b/gdb.html @@ -81,7 +81,7 @@ @@ -214,6 +214,7 @@ Create a catchpoint for <signal>.

User commands (macros)

+

Gdb allows to create & document user commands as follows:

  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>.
+
+

To get all user commands or documentations one can use:

+
  help user-defined
+  help <cmd>
 

Hooks

-

Gdb allows to create two types of command hooks which will be either executed -before or after a certain command.

-
  define hook-<cmd>             Run commands defined in hook before
-    # cmds                      executing <cmd>.
+

Gdb allows to create two types of command 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

+

This creates a 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>
 

Script gdb for automating debugging sessions

-
# 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.