From 6a4859e627fa10690741d36b2f1c39a1c4d6cc3a Mon Sep 17 00:00:00 2001 From: Cillian O'Donnell Date: Sat, 26 Aug 2017 09:15:56 +0100 Subject: covoar: Use rld tempfile and add signals to clean up in event of crash. Use rld tempfile for temporary files and add fatal signal handling to clean them up in the event of a crash. --- tester/covoar/TraceConverter.cc | 60 +++++++++++++++++++++++++++++++++-------- 1 file changed, 49 insertions(+), 11 deletions(-) (limited to 'tester/covoar/TraceConverter.cc') diff --git a/tester/covoar/TraceConverter.cc b/tester/covoar/TraceConverter.cc index 0f7a44e..22b0f81 100644 --- a/tester/covoar/TraceConverter.cc +++ b/tester/covoar/TraceConverter.cc @@ -10,9 +10,10 @@ #include #include #include +#include +#include #include "qemu-log.h" - #include "TraceReaderLogQEMU.h" #include "TraceWriterQEMU.h" #include "TraceList.h" @@ -20,6 +21,9 @@ #include "app_common.h" #include "TargetFactory.h" +#include "rld.h" +#include "rld-process.h" + char* progname; void usage() @@ -32,6 +36,40 @@ void usage() exit(1); } +static void +fatal_signal( int signum ) +{ + signal( signum, SIG_DFL ); + + rld::process::temporaries_clean_up(); + + /* + * Get the same signal again, this time not handled, so its normal effect + * occurs. + */ + kill( getpid(), signum ); +} + +static void +setup_signals( void ) +{ + if ( signal (SIGINT, SIG_IGN) != SIG_IGN ) + signal( SIGINT, fatal_signal ); +#ifdef SIGHUP + if ( signal( SIGHUP, SIG_IGN ) != SIG_IGN ) + signal( SIGHUP, fatal_signal ); +#endif + if ( signal( SIGTERM, SIG_IGN ) != SIG_IGN ) + signal( SIGTERM, fatal_signal ); +#ifdef SIGPIPE + if ( signal( SIGPIPE, SIG_IGN ) != SIG_IGN ) + signal( SIGPIPE, fatal_signal ); +#endif +#ifdef SIGCHLD + signal( SIGCHLD, SIG_DFL ); +#endif +} + int main( int argc, char** argv @@ -45,10 +83,14 @@ int main( const char *tracefile = ""; const char *logname = "/tmp/qemu.log"; Coverage::ExecutableInfo* executableInfo; - - // - // Process command line options. - // + rld::process::tempfile objdumpFile( ".dmp" ); + rld::process::tempfile err( ".err" ); + + setup_signals(); + + // + // Process command line options. + // progname = argv[0]; while ((opt = getopt(argc, argv, "c:e:l:L:t:v")) != -1) { @@ -88,17 +130,13 @@ int main( executableInfo = new Coverage::ExecutableInfo( executable ); objdumpProcessor = new Coverage::ObjdumpProcessor(); - + // If a dynamic library was specified, determine the load address. if (dynamicLibrary) executableInfo->setLoadAddress( objdumpProcessor->determineLoadAddress( executableInfo ) ); - - objdumpProcessor->loadAddressTable( executableInfo ); - + objdumpProcessor->loadAddressTable( executableInfo, objdumpFile, err ); log.processFile( logname ); - trace.writeFile( tracefile, &log ); - } -- cgit v1.2.3