source: rtems-tools/tester/covoar/TraceConverter.cc @ f4773ac

5
Last change on this file since f4773ac was f4773ac, checked in by Cillian O'Donnell <cpodonnell8@…>, on 09/13/17 at 15:45:30

covoar: Add function defs to fix Windows build errors.

Closes #3129

  • Property mode set to 100644
File size: 3.4 KB
Line 
1/*! @file TraceReaderLogQEMU.cc
2 *  @brief TraceReaderLogQEMU Implementation
3 *
4 *  This file contains the implementation of the functions supporting
5 *  reading the QEMU coverage data files.
6 */
7
8#include <stdio.h>
9#include <stdlib.h>
10#include <sys/stat.h>
11#include <string.h>
12#include <getopt.h>
13#include <signal.h>
14#include <unistd.h>
15
16#include "qemu-log.h"
17#include "TraceReaderLogQEMU.h"
18#include "TraceWriterQEMU.h"
19#include "TraceList.h"
20#include "ObjdumpProcessor.h"
21#include "app_common.h"
22#include "TargetFactory.h"
23
24#include "rld.h"
25#include "rld-process.h"
26
27#ifdef _WIN32
28  #define kill(p,s) raise(s)
29#endif
30
31char*       progname;
32
33void usage()
34{
35  fprintf(
36    stderr,
37    "Usage: %s [-v] -c CPU -e executable -t tracefile [-E logfile]\n",
38    progname
39  );
40  exit(1);
41}
42
43static void
44fatal_signal( int signum )
45{
46  signal( signum, SIG_DFL );
47
48  rld::process::temporaries_clean_up();
49
50  /*
51   * Get the same signal again, this time not handled, so its normal effect
52   * occurs.
53   */
54  kill( getpid(), signum );
55}
56
57static void
58setup_signals( void )
59{
60  if ( signal (SIGINT, SIG_IGN) != SIG_IGN )
61    signal( SIGINT, fatal_signal );
62#ifdef SIGHUP
63  if ( signal( SIGHUP, SIG_IGN ) != SIG_IGN )
64    signal( SIGHUP, fatal_signal );
65#endif
66  if ( signal( SIGTERM, SIG_IGN ) != SIG_IGN )
67    signal( SIGTERM, fatal_signal );
68#ifdef SIGPIPE
69  if ( signal( SIGPIPE, SIG_IGN ) != SIG_IGN )
70    signal( SIGPIPE, fatal_signal );
71#endif
72#ifdef SIGCHLD
73  signal( SIGCHLD, SIG_DFL );
74#endif
75}
76
77int main(
78  int    argc,
79  char** argv
80)
81{
82  int                          opt;
83  Trace::TraceReaderLogQEMU    log;
84  Trace::TraceWriterQEMU       trace;
85  const char                  *cpuname    = "";
86  const char                  *executable = "";
87  const char                  *tracefile  =  "";
88  const char                  *logname = "/tmp/qemu.log";
89  Coverage::ExecutableInfo*    executableInfo;
90  rld::process::tempfile       objdumpFile( ".dmp" );
91  rld::process::tempfile       err( ".err" );
92
93  setup_signals();
94
95   //
96   // Process command line options.
97   //
98  progname = argv[0];
99
100  while ((opt = getopt(argc, argv, "c:e:l:L:t:v")) != -1) {
101    switch (opt) {
102      case 'c': cpuname = optarg;        break;
103      case 'e': executable = optarg;     break;
104      case 'l': logname = optarg;        break;
105      case 'L': dynamicLibrary = optarg; break;
106      case 't': tracefile = optarg;      break;
107      case 'v': Verbose = true;          break;
108      default:  usage();
109    }
110  }
111
112  // Make sure we have all the required parameters
113  if ( !cpuname ) {
114    fprintf( stderr, "cpuname not specified\n" );
115    usage();
116  }
117
118  if ( !executable ) {
119    fprintf( stderr, "executable not specified\n" );
120    usage();
121  }
122
123  if ( !tracefile ) {
124    fprintf( stderr, "output trace file not specified\n" );
125    usage();
126  }
127
128  // Create toolnames.
129  TargetInfo = Target::TargetFactory( cpuname );
130
131  if (dynamicLibrary)
132    executableInfo = new Coverage::ExecutableInfo( executable, dynamicLibrary );
133  else
134    executableInfo = new Coverage::ExecutableInfo( executable );
135
136  objdumpProcessor = new Coverage::ObjdumpProcessor();
137
138  // If a dynamic library was specified, determine the load address.
139  if (dynamicLibrary)
140    executableInfo->setLoadAddress(
141      objdumpProcessor->determineLoadAddress( executableInfo )
142    );
143  objdumpProcessor->loadAddressTable( executableInfo, objdumpFile, err );
144  log.processFile( logname );
145  trace.writeFile( tracefile, &log );
146}
Note: See TracBrowser for help on using the repository browser.