Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Launch gdb automatically on Linux

Is there a way to automatically start a process under gdb on Linux? An equivalent of setting the Image File Execution Options on Windows.

I am trying to debug start-up phase of a process that is launched from another one.

like image 616
Nemanja Trifunovic Avatar asked Mar 07 '26 17:03

Nemanja Trifunovic


2 Answers

I would normally move the real program out of the way, and replace it with a script that launches the program under GDB with the same parameters.

#!/bin/bash

exec gdb -args <realprog> "$@"

If that doesn't work due to the output being redirected to file, or something, then try this:

#!/bin/bash

exec xterm -e gdb -args <realprog> "$@"

That should give you a pop-up terminal with GDB running inside.

like image 88
ams Avatar answered Mar 09 '26 09:03

ams


You don't have to go through all that registry voodoo on Linux :)

Simply:

1) Rename your program

2) Write a shell script that calls gdb with your (renamed) program and passes any arguments you want. Make sure you "chmod +rx" your script.

3) Name the shell script the original name of your program, and put it in the same directory as your program

4) Execute!

like image 29
paulsm4 Avatar answered Mar 09 '26 09:03

paulsm4



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!