Author Topic: Using a shell launcher script and debugging through it  (Read 3386 times)

worstje

  • Guest
Using a shell launcher script and debugging through it
« on: August 10, 2018, 01:56:01 pm »
I've been messing with this for hours, and I can't seem to figure out how to configure Code::Blocks to do what I want it to. Please don't confuse my lack of going over everything I have tried as not trying; I've just tried too many things at this point to remember them all! :-) Instead, I will just list what I ended up with.

My specific situation: My application (a daemon) has a launcher script that serves as watchdog and some other functions, some of them rather messy on the filesystem. Some of the features also involve the application being restarted. Because of existing features and compatibility with the production environment, there is an existing Makefile.

My goals:

1. Use my existing Makefile.

Complete: I was able to accomplish this.

2. When I click Run/Debug, I want the launcher script to be launched, not my executable.

Complete-ish: I worked around the problem using the first method listed in https://stackoverflow.com/questions/22059855/configure-launch-command-in-codeblocks, which relies on an extra virtual target. The fact I need to confirm my target to run each time is kind of annoying, but it is better than nothing. I would love to get rid of that dialog each time, though.

3. Have GDB automatically attach to child processes spawned by my launcher script.

Almost zero progress here. I configured gdb's initialization command to go 'set follow-fork-mode child', but unfortunately I am not getting anywhere; a segmentation fault during process start is not picked up on.


My current results when trying to 'Start / Continue' (F8, red arrow) look as follows:

Code
Active debugger config: GDB/CDB debugger:Myproject
Building to ensure sources are up-to-date
Selecting target:
startup
Adding source dir: /home/worstje/myproject/
Adding source dir: /home/worstje/myproject/
Adding file: /home/worstje/myproject/src/startup
Changing directory to: /home/worstje/myproject/src
Set variable: LD_LIBRARY_PATH=.:
Starting debugger: /usr/bin/gdb -fullname -quiet  -args /home/worstje/myproject/src/startup
done
Setting breakpoints
Debugger name and version: GNU gdb (Ubuntu 8.1-0ubuntu3) 8.1.0.20180409-git
Continuing...
Starting the debuggee failed: No executable file specified.
Debugger finished with status 0

Note that it freezes with a blank xterm screen after the 'Setting breakpoints', at which point I tell it to continue. (I guess it is trying to debug the shell script?) Unfortunately, it doesn't pickup anything afterwards, and then completely stops with the message you see below.

Using plain 'Run' (Ctrl+F10, green arrow) has the shell script executing normally, but when it launches my binary it has its segmentation fault.


I hope this information is enough to let you experts direct me to exactly what I need to do to try and make this work.

Thank you for your time and assistance. :-)
« Last Edit: August 10, 2018, 03:44:00 pm by worstje »

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Using a shell launcher script and debugging through it
« Reply #1 on: August 10, 2018, 08:02:29 pm »
Generally it is hard to make this work.
What I do these days when I want to debug programs started by some complex scripts is to place code looking something like this in my application:
Code
system("codeblocks --dbg-config=<my config> --dbg-attach=<mypid>");
sleep(2); // just to make sure attaching works
I put this somewhere around the beginning of main.
I start my application in a terminal and then the debugger attaches automagically.
For this to work you need really recent night/trunk build of codeblocks.

Can you reproduce "Starting the debuggee failed: No executable file specified." in a simple project you can share with us? I'm interested to try to make it less confusing or make it work if possible.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]