Running daemon as regular application (debugging in KDevelop) - c++

There are tools that enable one to run a console command or a console application as a daemon. To "daemonize" it, so to say.
Is there a way to run a daemon as a regular console application?
I'm coding in KDevelop and don't see any options for daemon debugging.
Thanks !

It's reasonably normal to add a special debugging mode to daemons to enable this. That is, add in a command-line option to disable the daemonizing step, having the program run in the foreground. Then it is is simple to run the daemon under gdb.
I'm not aware of any generic way to do this. Maybe it could be done somehow with LD_PRELOAD interception, which would be cool -- but it's simpler to just modify the source.
For debugging a running daemon you can use the gdb attach command. However this is not very good for debugging daemon startup, as you'll have to race to attach in time.
The linux kernel doesn't support any way to "pre-attach" to the next instance of a program, but I wrote a hack to do it via SystemTap that you can find here.

Related

Run C++ application with a custom script in Eclipse

I have a custom shell that I can run C++ applications in. I start the shell from a bash prompt and then run my C++ code. I want to emulate this behavior with Eclipse, particularly for debugging. I can't seem to figure this out.
I could write a simple bash script that kicks off the custom shell and runs my application but Eclipse does not let me debug when I do this.
Is there a way to achieve this functionality?
Please keep in mind eclipse can set environment variables for running/debugging job.
If your shell is more complicated than that, please provide more details about your shell.
But I'm not optimistic about it.
Btw, you can always attach an existing process for debugging.

Monitor a process (everything)

I want to monitor a process and everything it does (every signal it gives SIGINT what ever).
Is there anyway to do this?
I'm using Linux (Ubuntu 11 to be exact)
The strace unix command will do all that and more if you're looking for command-line monitoring.
It uses the ptrace system call infrastructure for monitoring which is in itself even more powerful: additionally allowing control of and interaction with the process. To quote from Wikipedia:
ptrace is used by debuggers (such as gdb and dbx), by tracing tools like strace and ltrace, and by code coverage tools. ptrace is also used by specialised programs to patch running programs, to avoid unfixed bugs or to overcome security features. It can further be used as a sandbox and as a runtime environment simulator (like emulating root access for non-root software).
If you want to do this monitoring programatically rather than from the command line, then ptrace is the solution for you.
strace ought to work, or something listed in the "Other Tools" section on that page.

Is there any enhanced gdb console for Eclipse?

Currently the gdb console of Eclipse just connects the stdin/stdout between the java gui and the underlying gdb process, hence many gdb shell features are missing, e.g. tab-autocomplete, command history etc.
I want to know if there is an enhanced console for fast gdb interacting. I really like the frequently used gdb commands like "print" and "call" etc. IMHO, "print" command is superiors sometimes than Eclipse "Expression watcher" because it only execute once and the later will be evaluated any time and be crash-prone.
If you think there is no need to use gdb console, then what's you best-practise in terms of gdb UI to eclipse UI transfer.
There doesn't seem to be any gdb-specific plugin, beside the initial gdb integration initiated with Eclipse3.4.
And the current list of gdb bugs doesn't include your missing features.
If you're writing c/++, why not just find the eclipse-generated elf and use gdb via the shell?

How to run and debug C++ application in Eclipse that's started with a script?

I'm trying to use Eclipse CDT on Ubuntu for C++ development. I'm working on a large C++ project that leverages Tcl as a scripting language to kick off and control the application.
How can I configure Eclipse to launch the application using shell scripts rather than using a C++ "main" application? The shell scripts launch a Tcl application that in turn calls into the C++ application.
Also, is it possible to debug a C++ application using Eclipse and gdb that's started via a script? If so, how does one go about doing it?
Interesting question. Without being able to provide you a straight solution, but Eclipse (gdb) can be attached to a running program - that may not help in your case.
What about trying to employ some kind of remote debugging? I.e. you start your program with gdb and configure gdb to wait for a remote debugger to attach? The 'remote' debugger will be on your local system, of course.
EDIT:
Start your program via
gdbserver localhost:1234 <executable>
Configure your debug session in Eclipse:
- GDB Hardware Debugging
- I had to select the "Standard GDB Hardware debugging launcher" (Debugger tab at the bottom for Helios)
- Check use remote target: Generic TCP/IP: localhost, port 1234
I didn't manage to resolve symbols yet, that might be a path issue.

How to use WINDBG debugging tool for debugging?

Can any one tell me how to use the WinDbg .
I am created an Application it is works fine in one machine.when i try to run on another machine it fails how can i debug it using windbg.
Start by downloading WinDbg from:
http://www.microsoft.com/whdc/devtools/debugging/default.mspx
You can install it on the target machine, and it will be listed on the Start menu under "Debugging Tools for Windows".
The general idea is to start your application, start WinDbg, attach to your app process, and run under the debugger. Try to provoke the failure and inspect the state of the process with the debugger.
The most common commands are available from the menus, and the help file is excellent for discovering the rest.
Here's a tutorial to get you started:
http://www.codeproject.com/KB/debug/windbg_part1.aspx
After you install windbg from http://www.microsoft.com/whdc/ you can start debugging your app. Windbg ships with help on commands, so feel free to use it by pressing F1 in the debugger any time.