Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make gdb run a user-defined function (defined in .gdbinit) everytime it starts?

Tags:

debugging

gdb

I have a set of basic breakpoints defined in a user-defined fn setup in my .gdbinit. So, every time i start gdb, I have to execute that fn. to set all my brkpoints , before I start debugging. Can I configure my .gdbinit so that whenever it starts , it first executes my user-defined fn setup ?

like image 954
TCSGrad Avatar asked Dec 16 '09 08:12

TCSGrad


People also ask

How do I run a function in GDB?

To execute one line of code, type "step" or "s". If the line to be executed is a function call, gdb will step into that function and start executing its code one line at a time. If you want to execute the entire function with one keypress, type "next" or "n".

How do I run a script in GDB?

Execute commands from a script The commands in a script file are exactly the same as commands on the gdb command line. You can specify the script name when you are starting GDB using execute script switch ( -x ). You can also execute a GDB script inside GDB using source command.

Where is the main difference between the command next N and step's in GDB?

The difference between "next" and "step" is that "step" stops inside a called function, while "next" executes called functions at (nearly) full speed, stopping only at the next line in the current function.

What is the GDB command to stop running to GDB tool and return to the Linux operating system prompt?

Quitting GDB To exit GDB, use the quit command (abbreviated q ), or type an end-of-file character (usually C-d ). If you do not supply expression , GDB will terminate normally; otherwise it will terminate using the result of expression as the error code.


1 Answers

Just call it by function name:

My .gdbinit:

define setup    
  echo Foobar\n
end   

setup #This is the function call

And when I run it:

$ gdb
GNU gdb Fedora (6.8-37.el5)
Copyright (C) 2008 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-redhat-linux-gnu".
Foobar
(gdb) 
like image 53
Kimvais Avatar answered Sep 18 '22 18:09

Kimvais