Skip to main content



      Home
Home » Language IDEs » C / C++ IDE (CDT) » How to Cleanly Terminate GDB?
How to Cleanly Terminate GDB? [message #1818131] Fri, 06 December 2019 13:48 Go to next message
Eclipse UserFriend
I am developing a continuously-running Linux daemon in C++ and am remotely debugging it using GDB and the Eclipse CDT. When I terminate a debugging session using the Terminate button in the Eclipse IDE, my daemon is seemingly killed using a SIGKILL signal. This causes issues for me because the abrupt termination of my daemon does not allow for process cleanup to be done and can lead to data corruption in the files/databases that it interacts with.

With this in mind, what are my options for performing a clean application shutdown under GDB when the Terminate button is pressed in Eclipse?

In an ideal world, I would like to have the Terminate button first send a signal of my choosing to my daemon which I could then use to cleanup/terminate it before GDB is killed. However, I would be open to using any available CDT or GDB tricks which would accomplish my goal.
Re: How to Cleanly Terminate GDB? [message #1819090 is a reply to message #1818131] Tue, 07 January 2020 13:32 Go to previous messageGo to next message
Eclipse UserFriend
Bump
Re: How to Cleanly Terminate GDB? [message #1819091 is a reply to message #1819090] Tue, 07 January 2020 13:51 Go to previous messageGo to next message
Eclipse UserFriend
Have you tried to use a remote terminal to the target Linux and sending a less forceful termination signal to the daemon (SIGHUP, SIGTERM or whatever) which allows the daemon to shut down cleanly?

Hopefully, you do have a signal handler in the daemon to make a clean exit.
Re: How to Cleanly Terminate GDB? [message #1819176 is a reply to message #1819091] Thu, 09 January 2020 09:49 Go to previous messageGo to next message
Eclipse UserFriend
Yes, I can connect another remote terminal and send a SIGTERM which will be caught by my respective handler and cleanly terminate my daemon. However, having to manage a second terminal is a little inconvenient which is why I'm looking for a way to have CDT send the SIGTERM when the Terminate button is pressed. I also looked at my .gdbinit configuration in hopes of finding a way to change the signal that GDB sends to my daemon when Eclipse terminates GDB, but I didn't have any luck there either.
Re: How to Cleanly Terminate GDB? [message #1819179 is a reply to message #1819176] Thu, 09 January 2020 09:59 Go to previous messageGo to next message
Eclipse UserFriend
What you're requesting is if there is a mechanism in CDT - GDB communication and GDB - stub communication which is able to send an arbitrary signal to the target running under the stub. As far a I remember there is none such.
Re: How to Cleanly Terminate GDB? [message #1819193 is a reply to message #1819179] Thu, 09 January 2020 13:52 Go to previous messageGo to next message
Eclipse UserFriend
Tauno Voipio wrote on Thu, 09 January 2020 14:59
What you're requesting is if there is a mechanism in CDT - GDB communication and GDB - stub communication which is able to send an arbitrary signal to the target running under the stub. As far a I remember there is none such.

That is more or less what I am wondering. It looks like CDT sends a SIGKILL to my daemon when the Terminate button is pressed. I would like to know if there is a way to send a SIGTERM instead.
Re: How to Cleanly Terminate GDB? [message #1819198 is a reply to message #1819193] Thu, 09 January 2020 14:48 Go to previous messageGo to next message
Eclipse UserFriend
IIRC, CDT just terminates the GDB, which in turn gets rid of everything under it.

The CDT-GDB communication is available on a terminal window to look at.

To debug the connection downward from GDB, you can set up GDB to monitor the communication with the stub.
Re: How to Cleanly Terminate GDB? [message #1819400 is a reply to message #1819198] Tue, 14 January 2020 10:31 Go to previous messageGo to next message
Eclipse UserFriend
Tauno Voipio wrote on Thu, 09 January 2020 19:48
To debug the connection downward from GDB, you can set up GDB to monitor the communication with the stub.

What would recommend as the best way to accomplish this? I am unfamiliar with the monitoring that you are describing.
Re: How to Cleanly Terminate GDB? [message #1819404 is a reply to message #1819400] Tue, 14 January 2020 11:18 Go to previous messageGo to next message
Eclipse UserFriend
Get the GDB manual and read it. A good starting point is <https://www.gnu.org/software/gdb/documentation/>.

Google finds a lot of documentation with 'gdb manual'.
Re: How to Cleanly Terminate GDB? [message #1819406 is a reply to message #1819400] Tue, 14 January 2020 11:41 Go to previous messageGo to next message
Eclipse UserFriend
I think Tauno was merely making a generic suggestion.

Eclipse only does the common things most users would find helpful.
It however does provide a Debugger Console view for the more exotic tasks.
To use it, you need to know how to run GDB as a standalone process.

Here's the manual for GDB
https://sourceware.org/gdb/current/onlinedocs/gdb/index.html#SEC_Contents

In particular, you may want to read:
https://sourceware.org/gdb/current/onlinedocs/gdb/Running.html#Running
https://sourceware.org/gdb/current/onlinedocs/gdb/Stopping.html#Stopping
https://sourceware.org/gdb/current/onlinedocs/gdb/Signals.html#Signals

You probably should also read:
https://sourceware.org/gdb/current/onlinedocs/gdb/Signaling.html#Signaling
and maybe the containing section.

You might also want to consider attaching to your daemon.
https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/developer_guide/debugging-running-application
Google "GDB Attach to running process" for more links.

Re: How to Cleanly Terminate GDB? [message #1819449 is a reply to message #1819406] Wed, 15 January 2020 10:24 Go to previous messageGo to next message
Eclipse UserFriend
Thanks for the links. I am familiar with the operation of GDB as a standalone process. (I was looking for clarification on the terminology used by Tauno.) I can accomplish my goals in GDB without CDT (just send a signal via the console and call it a day) - my question was how to modify the behavior of CDT's terminate sequence to have it send the signal instead of having to do it in the GDB console. So my understanding is that there is no way to do this in CDT?
Re: How to Cleanly Terminate GDB? [message #1819452 is a reply to message #1819449] Wed, 15 January 2020 10:50 Go to previous messageGo to next message
Eclipse UserFriend
I presume you could download the source and modify it.
Otherwise, I don't think there is.
Re: How to Cleanly Terminate GDB? [message #1819453 is a reply to message #1819452] Wed, 15 January 2020 10:55 Go to previous message
Eclipse UserFriend
David Vavra wrote on Wed, 15 January 2020 15:50
I presume you could download the source and modify it.
Otherwise, I don't think there is.

OK. Thank you for the clarification.
Previous Topic:Create compile_commands.json for clang-tidy CDT 910 (2019-12)
Next Topic:How connect *.tlib to C++ project
Goto Forum:
  


Current Time: Sun Jun 22 18:09:33 EDT 2025

Powered by FUDForum. Page generated in 0.06766 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top