1212#include < vector>
1313
1414#include < errno.h>
15- #include < unistd.h>
1615#include < signal.h>
16+ #include < unistd.h>
1717
1818#include " trace_parser.h"
1919
@@ -32,7 +32,10 @@ void split(const std::string &str, std::vector<std::string> &cont,
3232 }
3333}
3434
35- inst_trace_t ::inst_trace_t () { memadd_info = NULL ; imm = 0 ;}
35+ inst_trace_t ::inst_trace_t () {
36+ memadd_info = NULL ;
37+ imm = 0 ;
38+ }
3639
3740inst_trace_t ::~inst_trace_t () {
3841 if (memadd_info != NULL ) delete memadd_info;
@@ -169,7 +172,7 @@ bool inst_trace_t::parse_from_string(std::string trace, unsigned trace_version,
169172 ss >> temp;
170173 sscanf (temp.c_str (), " R%d" , ®_src[i]);
171174 }
172-
175+
173176 // parse mem info
174177 unsigned address_mode = 0 ;
175178 unsigned mem_width = 0 ;
@@ -287,60 +290,60 @@ kernel_trace_t *trace_parser::parse_kernel_info(
287290
288291 std::string read_trace_cmd;
289292 int _l = kerneltraces_filepath.length ();
290- if (_l > 3 && kerneltraces_filepath.substr (_l- 3 , 3 ) == " .xz" ){
293+ if (_l > 3 && kerneltraces_filepath.substr (_l - 3 , 3 ) == " .xz" ) {
291294 // this is xz-compressed trace
292295 read_trace_cmd = " xz -dc " + kerneltraces_filepath;
293- } else if (_l > 7 && kerneltraces_filepath.substr (_l- 7 , 7 ) == " .traceg" ){
296+ } else if (_l > 7 && kerneltraces_filepath.substr (_l - 7 , 7 ) == " .traceg" ) {
294297 // this is plain text trace
295- read_trace_cmd =" cat " + kerneltraces_filepath;
298+ read_trace_cmd = " cat " + kerneltraces_filepath;
296299 } else {
297- std::cerr << " Can't read trace. Only .xz and plain text are supported: "
298- << kerneltraces_filepath <<" \n " ;
300+ std::cerr << " Can't read trace. Only .xz and plain text are supported: "
301+ << kerneltraces_filepath << " \n " ;
299302 exit (1 );
300303 }
301304
302305 // Create an interprocess channel, and fork out a data source process. The
303306 // data source process reads trace from disk, write to the channel, and the
304- // simulator process read from the channel.
307+ // simulator process read from the channel.
305308 int *pipefd = kernel_info->pipefd ;
306- if (pipe (pipefd) != 0 ){
309+ if (pipe (pipefd) != 0 ) {
307310 std::cerr << " Failed to create interprocess channel\n " ;
308311 perror (" pipe" );
309312 exit (1 );
310313 }
311314
312315 pid_t pid = fork ();
313- if (pid == 0 ){
316+ if (pid == 0 ) {
314317 // The child process is the data source. Redirect its
315318 // stdout to the write end of the pipe.
316319 close (pipefd[0 ]);
317320 dup2 (pipefd[1 ], STDOUT_FILENO);
318321
319322 // When using GDB, sending Ctrl+C to the simulator will send a SIGINT signal
320323 // to the child process as well, subsequently causing it to terminate. To
321- // avoid this, we let the child process ignore (SIG_IGN) the SIGINT signal.
324+ // avoid this, we let the child process ignore (SIG_IGN) the SIGINT signal.
322325 // Reference:
323- // https://stackoverflow.com/questions/38404925/gdb-interrupt-running-process-without-killing-child-processes
326+ // https://stackoverflow.com/questions/38404925/gdb-interrupt-running-process-without-killing-child-processes
324327 signal (SIGINT, SIG_IGN);
325328
326329 execle (" /bin/sh" , " sh" , " -c" , read_trace_cmd.c_str (), NULL , environ);
327- perror (" execle" ); // the child process shouldn't reach here if all is well.
330+ perror (" execle" ); // the child process shouldn't reach here if all is well.
328331 exit (1 );
329332 } else {
330333 // parent (simulator)
331334 close (pipefd[1 ]);
332335 dup2 (pipefd[0 ], STDIN_FILENO);
333336 }
334-
335- // Parent continues from here.
336- kernel_info->ifs = &std::cin;
337+
338+ // Parent continues from here.
339+ kernel_info->ifs = &std::cin;
337340 std::istream *ifs = kernel_info->ifs ;
338341
339342 std::cout << " Processing kernel " << kerneltraces_filepath << std::endl;
340343
341344 std::string line;
342345
343- // Important to clear the istream. Otherwise, the eofbit from the last
346+ // Important to clear the istream. Otherwise, the eofbit from the last
344347 // kernel may be carried over to this kernel
345348 ifs->clear ();
346349 clearerr (stdin);
@@ -417,7 +420,7 @@ void trace_parser::kernel_finalizer(kernel_trace_t *trace_info) {
417420 // The pipe read/write end file descriptors held by the child process would
418421 // have been automatically closed when it terminated. But the parent
419422 // process may read an arbitrary amount of trace files, so it has to close
420- // all file descriptors.
423+ // all file descriptors.
421424 close (trace_info->pipefd [0 ]);
422425 close (trace_info->pipefd [1 ]);
423426 delete trace_info;
0 commit comments