How can i get coverage data with a stay process like system_server by gcov? thank you - gdb

i need to get coverage data with stay process like system_server by gcov
cause the process not exit so can not get *.gcda files
and i try to use __gcov_flush();
then use :gdb --batch --ex 'call dlopen("/data/libxxx.so", 2)' --pid SERVER_PID
sadly the stay process already used SIGUSR1
"Thread 1 "foundation" received signal SIGUSR1, User defined signal 1"
and the stay process must not be exited casuse if it exit,the system will shutdown
i still can not get .gcda
how can i do
anyone who can help? thank you

Related

Remote GDB checkpoint/fork failure

I am trying to debug on a remote target that does not support run or restart without a checkpoint. The only user available is root, so there shouldn't be any permission issues. I tried:
Breakpoint 1, main (argc=4, argv=0x7fffffffe348) at foo.cpp:40
(gdb) checkpoint
checkpoint -1: fork returned pid 6145.
Failed to find new fork
(gdb) i checkpoints
No checkpoints.
Does anyone know how to get run to work? Or how I can check to see what is actually causing the fork to fail and prevent the checkpoint?
After some experimentation, add the following to your .gdbinit file
target extended-remote <host>:<port>
This should allow you to use the run command, eliminating the need to use restart.
Once you fork how could you restore a checkpoint? A checkpoint does a rewind to a processes saved state at a moment in time. Once the fork occurs, I imagine the checkpoint would only exist for the original process.
From the manual there is this entry:
Finally, there is one bit of internal program state that will be
different when you return to a checkpoint — the program's process id.
Each checkpoint will have a unique process id (or pid), and each will
be different from the program's original pid. If your program has
saved a local copy of its process id, this could potentially pose a
problem.
Regarding the required use of checkpoints to perform restarts on remote sessions. I have never used checkpoints before but I have restarted many a remote session.

How to know if a SIGHUP signal has been handled?

I have a python script who sends a SIGHUP signal to another process, unrelated with my script (not a child, not alterable). When the process receives the SIGHUP, it starts a "light restart", reloading configuration file and updating information.
The "restart" doesn't stop the process, so I can't wait for an exit code. I know I can look at the process log file to know if the signal is handled, but that's too heavy and too slow for the script flow.
I would like to know if I can use another method to be warned that the SIGHUP have been received by my process?
The inotify-tools C library may solve your problem. Its installation gives you access to new commands: inotifywait and inotifywatch.
Let's say you have this /tmp/foo.bar file. You can start watching for any read access on this file with the following command:
inotifywait --event access /tmp/foo.bar
Then, do a cat /tmp/foo.bar and the program will return.
As I said, it's a C library and I guess there are other language implementations of it. So feel free to not use this Bash example and write you own program using this library.

Process terminates with HUP signal despite starting with nohup

I'm quite new to solaris. I have this problem thats bugging me for sometime now.
I start a process in solaris as
nohup <binary>
I do this so that my process would not get SIGHUP, the process will not terminate even after I exit from my shell.
I tested this out, by exitting from my shell.
It works as expected,the process still runs.
Problem:
When my process is idle for too long, I see the following line in dmesg..
[ID 702911 auth.error] [29069] Run idle timeout reached (32400 seconds)
Then my process gets a SIGHUP, and terminates.
I'm struggling with the following questions...
Which process writes this timeout message in dmesg? How can I find it out?
How come my process still get a SIGHUP despite starting with nohup? Are there any other means for a process to get a HUP signal?
Note: I tried kill -1 <my process id> . Then my process terminates because of the HUP signal.
Can anyone help me on this?

How to get .gcda files when the process is killed?

I have a binary build with -fprofile-arcs and -ftest-coverage. The binary is run by a process monitor which spawns the process as a child process. Then, when I want the process to exit, I have to go through the process monitor. It sends a SIGKILL to the process. I found out that .gcda files do not generate in this case. What can I do?
EDIT: Actually the process monitor first tries to make the process exit. However, the ProcessMonitor library (used in each process) calls _exit instead of exit when the user issues a command to stop the process. This is the cause of all trouble.
This might work:
http://nixcraft.com/coding-general/12544-gcov-g.html
In summary: call __gcov_flush() in the program, possibly in a signal handler or periodically during execution.
If C++ code remember to make a extern "C" declaration of the function.
Also remember to use some kind of preprocessor ifdef so that the program does not call it when not built with profiling.
SIGKILL is a "hard" kill signal, that cannot be caught by the application. Therefore, the app has no chance to write out the .gcda file.
I see two options:
Catch signals other than SIGKILL: any sensible process monitor should send a SIGTERM first. init and the batch managers I've encountered do this. SIGKILL is a last resort, so it should be sent only after SIGTERM followed by a grace period.
Workaround: run the program via an intermediate program that gets the SIGKILL; have the actual program check periodically (or in a separate thread) if its parent still lives, and if not, have it exit gracefully.
Afaik compilers (IntelC too) only store profiling stats in exit handler.
So what about somehow telling the process to quit, instead of killing it?
Like adding a SIGKILL handler maybe, with exit() in it?

How to check if a process is running or got segfaulted or terminated in linux from its pid in my main() in c++

I am invoking several processes in my main and I can get the pid of that processes. Now I want to wait until all this processes have been finished and then clear the shared memory block from my parent process. Also if any of the process not finished and segfaulted I want to kill that process. So how to check from the pid of processes in my parent process code that a process is finished without any error or it gave broke down becoz of runtime error or any other cause, so that I can kill that process.
Also what if I want to see the status of some other process which is not a child process but its pid is known.
Code is appreciated( I am not looking for script but code ).
Look into waitpid(2) with WNOHANG option. Check the "fate" of the process with macros in the manual page, especially WIFSIGNALED().
Also, segfaulted process is already dead (unless SIGSEGV is specifically handled by the process, which is usually not a good idea.)
From your updates, it looks like you also want to check on other processes, which are not children of your current process.
You can look at /proc/{pid}/status to get an overview of what a process is currently doing, its either going to be:
Running
Stopped
Sleeping
Disk (D) sleep (i/o bound, uninterruptable)
Zombie
However, once a process dies (fully, unless zombied) so does its entry in /proc. There's no way to tell if it exited successfully, segfaulted, caught a signal that could not be handled, or failed to handle a signal that could be handled. Not unless its parent logs that information somewhere.
It sounds like your writing a watchdog for other processes that you did not start, rather than keeping track of child processes.
If a program segfaults, you won't need to kill it. It's dead already.
Use the wait and waitpid calls to wait for children to finish and check the status for some idea of how they exiting. See here for details on how to use these functions. Note especially the WIFSIGNALED and WTERMSIG macros.
waitpid() from SIGCHLD handler to catch the moment when application terminates itself. Note that if you start multiple processes you have to loop on waitpid() with WNOHANG until it returns 0.
kill() with signal 0 to check whether the process is still running. IIRC zombies still qualify as processes thus you have to have proper SIGCHLD handler for that to work.