Netbeans debugger (used for Linux-C development) terminates(does not hit break points) during/after waitpid

The name of the picture


Netbeans debugger (used for Linux-C development) terminates(does not hit break points) during/after waitpid



We are working on client/server application. I'm working on logging of different sorts. We recently moved to netbeans IDE because of some administrative decision.



I was developer of Asp.net and recently moved to low-level programming. As I know only basics of C (course-level programmig), I spent 2 days in understanding forking concepts of C.



Now I'm debugging a piece of following code which is written by a very senior developer (ofcourse she is out of town):


int UpdateLogsDuringExecution(char *Input)
{
pid_t pid;
int status;
pid = fork();
if (pid == 0)
{
//write data to file
return 1; //on successful execution & 0 otherwise.
}
else
{
do
{
waitpid(pid, &status, WUNTRACED); //after this statement debugger does not hit any break points
} while (!WIFEXITED(status) && !WIFSIGNALED(status));
}

kill(0, SIGTERM); //if I change WUNTRACED to any other flag (for testing/understanding), debugger gives error something like Forward and Continue, Pause and Continue etc.
return 1;
}

int main()

{
setuid(0);
int stat = 1;
while (stat)
{
char *userInput = TakeUserInput();
stat = UpdateLogsDuringExecution(userInput);
if(!stat)
break;
stat= checkAndExecFlag();
.
.
.
.
//do more work

}
return 1;
}



P.S this code works fine but I want to debug the code for understanding of business logic



Please help me to understand this behavior. I think probably waitpid cause this behavior, if WUNTRACED was changed into any other flag, then kill cause the debugger to not hit any break points further.



All suggestions are welcome.



Thanks in advance.



Edit



All function in my program have exactly same structure only


if(pid==0) //differs





I don't see any business logic here, only technical stuff ;) But anyways, if you just set a breakpoint at the kill() call, this should always be reached, given your child indeed terminates. Probably some misuse or misconfiguration of the debugger. Did you compile with all debugging symbols? Is the debugger configured to attach to child processes and might hang in some breakpoint in the child?
– Felix Palmen
9 hours ago


kill()





btw, removed inappropriate tag cthreads. There's no threading here, especially not the one provided by the language in C11.
– Felix Palmen
9 hours ago





I understand that. We did not change anything in make file. Literally we just created a new project and moved code to that project. We are running/debugging with all default options of netbeans. Can you please give direction on how to do that? I mean I can see the option "Attach Debugger" in netbeans.
– Sikander Hayyat
9 hours ago





Thanks for removing @FelixPalmen
– Sikander Hayyat
9 hours ago







I can only play guessing game here ... when you have a fork() (or, on windows, CreateProcess()) in an active debugging sessions, the debugger has three options: Ignore the child process, attach to it and detach from the parent, or attach to both. That's normally configurable. If your debugger is attached to both processes and the child "hangs" because you have a breakpoint in there, you won't hit any breakpoints in the parent that's just waiting for the child with this code ...
– Felix Palmen
9 hours ago


fork()


CreateProcess()









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Stripe::AuthenticationError No API key provided. Set your API key using “Stripe.api_key = ”

CRM reporting Extension - SSRS instance is blank

Keycloak server returning user_not_found error when user is already imported with LDAP