From 3d78e5a34b32834803ccbaeeb5d78a07da9c1ad7 Mon Sep 17 00:00:00 2001 From: Cedric Roux <cedric.roux@eurecom.fr> Date: Tue, 28 Jun 2016 12:50:58 +0200 Subject: [PATCH] add option --T_dont_fork to tracee (lte-softmodem, oaisim) The T has 2 processes: the tracee and the local tracer if the tracee dies (segfault or whatever) the tracee may still be running. So there is a third process that monitors those two others and kill everything when one dies. The problem is that this third process has to be the parent of the two others. That makes debugging the tracee with gdb impossible. This new option disables the third monitor process. --- common/utils/T/T.c | 14 ++++++++------ common/utils/T/T.h | 2 +- targets/RT/USER/lte-softmodem.c | 12 +++++++++++- targets/SIMU/USER/oaisim.c | 4 +++- targets/SIMU/USER/oaisim_functions.c | 8 ++++++++ 5 files changed, 31 insertions(+), 9 deletions(-) diff --git a/common/utils/T/T.c b/common/utils/T/T.c index b9e9b29326..5d84afa660 100644 --- a/common/utils/T/T.c +++ b/common/utils/T/T.c @@ -107,7 +107,7 @@ static void monitor_and_kill(int child1, int child2) exit(0); } -void T_init(int remote_port, int wait_for_tracer) +void T_init(int remote_port, int wait_for_tracer, int dont_fork) { int socket_pair[2]; int s; @@ -117,7 +117,7 @@ void T_init(int remote_port, int wait_for_tracer) if (socketpair(AF_UNIX, SOCK_STREAM, 0, socket_pair)) { perror("socketpair"); abort(); } - /* child1 runs the local tracer and child2 runs the tracee */ + /* child1 runs the local tracer and child2 (or main) runs the tracee */ child1 = fork(); if (child1 == -1) abort(); if (child1 == 0) { @@ -127,10 +127,12 @@ void T_init(int remote_port, int wait_for_tracer) } close(socket_pair[0]); - child2 = fork(); if (child2 == -1) abort(); - if (child2 != 0) { - close(socket_pair[1]); - monitor_and_kill(child1, child2); + if (dont_fork == 0) { + child2 = fork(); if (child2 == -1) abort(); + if (child2 != 0) { + close(socket_pair[1]); + monitor_and_kill(child1, child2); + } } s = socket_pair[1]; diff --git a/common/utils/T/T.h b/common/utils/T/T.h index a5aacb4b4f..819615131e 100644 --- a/common/utils/T/T.h +++ b/common/utils/T/T.h @@ -562,7 +562,7 @@ extern T_cache_t *T_cache; extern int *T_active; -void T_init(int remote_port, int wait_for_tracer); +void T_init(int remote_port, int wait_for_tracer, int dont_fork); #else /* T_TRACER */ diff --git a/targets/RT/USER/lte-softmodem.c b/targets/RT/USER/lte-softmodem.c index ca97ad0e22..3f419ed49c 100644 --- a/targets/RT/USER/lte-softmodem.c +++ b/targets/RT/USER/lte-softmodem.c @@ -490,6 +490,7 @@ void help (void) { #if T_TRACER printf(" --T_port [port] use given port\n"); printf(" --T_nowait don't wait for tracer, start immediately\n"); + printf(" --T_dont_fork to ease debugging with gdb\n"); #endif printf(RESET); fflush(stdout); @@ -2332,6 +2333,7 @@ static void get_options (int argc, char **argv) #if T_TRACER LONG_OPTION_T_PORT, LONG_OPTION_T_NOWAIT, + LONG_OPTION_T_DONT_FORK, #endif }; @@ -2355,6 +2357,7 @@ static void get_options (int argc, char **argv) #if T_TRACER {"T_port", required_argument, 0, LONG_OPTION_T_PORT}, {"T_nowait", no_argument, 0, LONG_OPTION_T_NOWAIT}, + {"T_dont_fork", no_argument, 0, LONG_OPTION_T_DONT_FORK}, #endif {NULL, 0, NULL, 0} @@ -2457,6 +2460,12 @@ static void get_options (int argc, char **argv) T_wait = 0; break; } + + case LONG_OPTION_T_DONT_FORK: { + extern int T_dont_fork; + T_dont_fork = 1; + break; + } #endif case 'A': @@ -2822,6 +2831,7 @@ static void get_options (int argc, char **argv) #if T_TRACER int T_wait = 1; /* by default we wait for the tracer */ int T_port = 2021; /* default port to listen to to wait for the tracer */ +int T_dont_fork = 0; /* default is to fork, see 'T_init' to understand */ #endif int main( int argc, char **argv ) @@ -2894,7 +2904,7 @@ int main( int argc, char **argv ) openair0_cfg[0].configFilename = rf_config_file; #if T_TRACER - T_init(T_port, T_wait); + T_init(T_port, T_wait, T_dont_fork); #endif // initialize the log (see log.h for details) diff --git a/targets/SIMU/USER/oaisim.c b/targets/SIMU/USER/oaisim.c index dfbf8f9676..744952b5d0 100644 --- a/targets/SIMU/USER/oaisim.c +++ b/targets/SIMU/USER/oaisim.c @@ -250,6 +250,7 @@ help (void) #if T_TRACER printf ("--T_port [port] use given port\n"); printf ("--T_nowait don't wait for tracer, start immediately\n"); + printf ("--T_dont_fork to ease debugging with gdb\n"); #endif } @@ -1258,6 +1259,7 @@ l2l1_task (void *args_p) #if T_TRACER int T_wait = 1; /* by default we wait for the tracer */ int T_port = 2021; /* default port to listen to to wait for the tracer */ +int T_dont_fork = 0; /* default is to fork, see 'T_init' to understand */ #endif /*------------------------------------------------------------------------------*/ @@ -1294,7 +1296,7 @@ main (int argc, char **argv) get_simulation_options (argc, argv); //Command-line options #if T_TRACER - T_init(T_port, T_wait); + T_init(T_port, T_wait, T_dont_fork); #endif // Initialize VCD LOG module diff --git a/targets/SIMU/USER/oaisim_functions.c b/targets/SIMU/USER/oaisim_functions.c index f8043b2cfd..a5acb2616a 100644 --- a/targets/SIMU/USER/oaisim_functions.c +++ b/targets/SIMU/USER/oaisim_functions.c @@ -216,6 +216,7 @@ void get_simulation_options(int argc, char *argv[]) #if T_TRACER LONG_OPTION_T_PORT, LONG_OPTION_T_NOWAIT, + LONG_OPTION_T_DONT_FORK, #endif }; @@ -254,6 +255,7 @@ void get_simulation_options(int argc, char *argv[]) #if T_TRACER {"T_port", required_argument, 0, LONG_OPTION_T_PORT}, {"T_nowait", no_argument, 0, LONG_OPTION_T_NOWAIT}, + {"T_dont_fork", no_argument, 0, LONG_OPTION_T_DONT_FORK}, #endif {NULL, 0, NULL, 0} @@ -436,6 +438,12 @@ void get_simulation_options(int argc, char *argv[]) T_wait = 0; break; } + + case LONG_OPTION_T_DONT_FORK: { + extern int T_dont_fork; + T_dont_fork = 1; + break; + } #endif case 'a': -- GitLab