1

I have two programs in abstraction form are:

//test_driver.C"
#include"iostream"
int main() 
{
std::cout << "Alarm" << '\n';
}

}



//test_platform.C    
#include <iostream>
#include <cstdlib>
int main()
{
std:cout << "Starting test_driver..." << '\n' ;
int result = system("./test_driver");
}

the question is:

how can i set breakpoints to test_driver.C in GDB or netbeans?

Do not make any changes in code not test_driver.C nor test_platform.C.

dt128
  • 81
  • 9
  • This is almost exact duplicate of https://stackoverflow.com/questions/46046194/how-to-gdb-from-main-of-app2-triggered-by-app1 – Employed Russian Sep 06 '17 at 14:46
  • @Employed Russian that not allowed to any change in code applications not test_driver.C nor test_platform.C , also test_driver not run by system(), in fact by more complex procedure in test_platform – dt128 Sep 07 '17 at 07:52

2 Answers2

2

Don't think there is a platform independent way to do this.

Might try:

  • raise(SIGTRAP) on posix systems
  • DebugBreak on Windows
Josh
  • 12,602
  • 2
  • 41
  • 47
2

on a Linux machine, gcc can intercept the fork/vfork system call. there are several debug options you need to set.

set detach-on-fork MODE
    MODE can be on(default) or off

set follow-fork-mode MODE
    MODE can be child or parent(default)

when detach-on-fork is set to on, one process (depending on follow-fork-mode) is debugged as usual, the other will be detached and allowed to run independently.

when detach-on-fork is set to off, both processes will be held under the control of GDB, one process (depending on follow-fork-mode) is debugged as usual, while the other is held suspended.

see the sections labeled "inferiors and programs" and "forks" of the gdb manual here for details.

I don't know if other platforms are also supported.

书呆彭
  • 101
  • 4