source: rtems-testing/covoar/TraceReaderLogQEMU.cc @ a518bc5

4.11
Last change on this file since a518bc5 was a518bc5, checked in by Jennifer Averett <Jennifer.Averett@…>, on May 24, 2010 at 8:07:09 PM

2010-05-24 Jennifer Averett <Jennifer.Averett@…>

  • covoar/05_ascending.gif, covoar/05_descending.gif, covoar/05_unsorted.gif, covoar/ConfigFile.cc, covoar/ConfigFile.h, covoar/CoverageFactory.cc, covoar/CoverageFactory.h, covoar/CoverageMap.cc, covoar/CoverageMap.h, covoar/CoverageMapBase.cc, covoar/CoverageMapBase.h, covoar/CoverageRanges.cc, covoar/CoverageRanges.h, covoar/CoverageReaderBase.cc, covoar/CoverageReaderBase.h, covoar/CoverageReaderQEMU.cc, covoar/CoverageReaderQEMU.h, covoar/CoverageReaderRTEMS.cc, covoar/CoverageReaderRTEMS.h, covoar/CoverageReaderSkyeye.cc, covoar/CoverageReaderSkyeye.h, covoar/CoverageReaderTSIM.cc, covoar/CoverageReaderTSIM.h, covoar/CoverageWriterBase.cc, covoar/CoverageWriterBase.h, covoar/CoverageWriterRTEMS.cc, covoar/CoverageWriterRTEMS.h, covoar/CoverageWriterSkyeye.cc, covoar/CoverageWriterSkyeye.h, covoar/CoverageWriterTSIM.cc, covoar/CoverageWriterTSIM.h, covoar/DesiredSymbols.cc, covoar/DesiredSymbols.h, covoar/ExecutableInfo.cc, covoar/ExecutableInfo.h, covoar/Explanations.cc, covoar/Explanations.h, covoar/Makefile, covoar/ObjdumpProcessor.cc, covoar/ObjdumpProcessor.h, covoar/ReportsBase.cc, covoar/ReportsBase.h, covoar/ReportsHtml.cc, covoar/ReportsHtml.h, covoar/ReportsText.cc, covoar/ReportsText.h, covoar/SymbolTable.cc, covoar/SymbolTable.h, covoar/TargetBase.cc, covoar/TargetBase.h, covoar/TargetFactory.cc, covoar/TargetFactory.h, covoar/Target_arm.cc, covoar/Target_arm.h, covoar/Target_i386.cc, covoar/Target_i386.h, covoar/Target_lm32.cc, covoar/Target_lm32.h, covoar/Target_m68k.cc, covoar/Target_m68k.h, covoar/Target_powerpc.cc, covoar/Target_powerpc.h, covoar/Target_sparc.cc, covoar/Target_sparc.h, covoar/TraceConverter.cc, covoar/TraceList.cc, covoar/TraceList.h, covoar/TraceReaderBase.cc, covoar/TraceReaderBase.h, covoar/TraceReaderLogQEMU.cc, covoar/TraceReaderLogQEMU.h, covoar/TraceWriterBase.cc, covoar/TraceWriterBase.h, covoar/TraceWriterQEMU.cc, covoar/TraceWriterQEMU.h, covoar/app_common.cc, covoar/app_common.h, covoar/configfile_test.cc, covoar/coverage_converter.cc, covoar/covmerge.cc, covoar/covoar.cc, covoar/covoar.css, covoar/filter.gif, covoar/qemu-dump-trace.c, covoar/qemu-log.h, covoar/qemu-traces.h, covoar/rtemscov_header.h, covoar/skyeye_header.h, covoar/table.js: New files.
  • Property mode set to 100644
File size: 4.1 KB
Line 
1/*
2 *  $Id$
3 */
4
5/*! @file TraceReaderLogQEMU.cc
6 *  @brief TraceReaderLogQEMU Implementation
7 *
8 *  This file contains the implementation of the functions supporting
9 *  reading the QEMU coverage data files.
10 */
11
12#include <stdio.h>
13#include <stdlib.h>
14#include <sys/stat.h>
15#include <string.h>
16
17#include "qemu-log.h"
18
19#include "app_common.h"
20#include "TraceReaderBase.h"
21#include "TraceReaderLogQEMU.h"
22#include "TraceList.h"
23
24/* XXX really not always right */
25typedef uint32_t target_ulong;
26
27#include "qemu-traces.h"
28
29/* hack so this can compile on the RH7 RTEMS 4.5 host */
30#if (__GNUC__ <= 2)
31#define STAT stat
32#define OPEN fopen
33#else
34#define STAT stat64
35#define OPEN fopen64
36#endif
37
38
39namespace Trace {
40
41  TraceReaderLogQEMU::TraceReaderLogQEMU()
42  {
43  }
44
45  TraceReaderLogQEMU::~TraceReaderLogQEMU()
46  {
47  }
48
49  bool TraceReaderLogQEMU::processFile(
50    const char* const     file
51  )
52  {
53    bool                done          = false;
54    QEMU_LOG_IN_Block_t first         = { 0, "", "" };
55    QEMU_LOG_IN_Block_t last          = { 0, "", "" };
56    QEMU_LOG_IN_Block_t nextExecuted  = { 0, "", "" };
57    uint32_t            nextlogical;
58    struct STAT         statbuf;
59    int                 status;
60    FILE*               logFile;
61    int                 result;
62    char                buffer[120];
63
64    //
65    // Verify that the log file has a non-zero size.
66    //
67    // NOTE: We prefer stat64 because some of the coverage files are HUGE!
68    status = STAT( file, &statbuf );
69    if (status == -1) {
70      fprintf( stderr, "Unable to stat %s\n", file );
71      return false;
72    }
73
74    if (statbuf.st_size == 0) {
75      fprintf( stderr, "%s is 0 bytes long\n", file );
76      return false;
77    }
78
79    //
80    // Open the coverage file and discard the header.
81    //
82    logFile = OPEN( file, "r" );
83    if (!logFile) {
84      fprintf( stderr, "Unable to open %s\n", file );
85      return false;
86    }
87
88
89    //
90    //  Discard Header section
91    //
92    if (! ReadUntilFound( logFile, QEMU_LOG_SECTION_END ) ) {
93      fprintf( stderr, "Unable to locate end of log file header\n" );
94      return false;
95    }
96
97    //
98    //  Find first IN block
99    //
100    if (! ReadUntilFound( logFile, QEMU_LOG_IN_KEY )){
101      fprintf(stderr,"Error: Unable to locate first IN: Block in Log file \n");
102      return false;
103    }
104
105    //
106    //  Read First Start Address
107    //
108    fgets(buffer, 120, logFile );
109    result = sscanf( 
110      buffer, 
111      "0x%08lx: %s %s\n", 
112      &first.address, 
113      first.instruction, 
114      first.data
115    );
116    if ( result < 2 ) 
117    {
118      fprintf(stderr, "Error Unable to Read Initial First Block\n" );
119      done = true;
120    }
121
122    while (!done) {
123
124      last = first;
125   
126      // Read until we get to the last instruction in the block.
127      do {
128        fgets(buffer, 120, logFile );
129        result = sscanf( 
130          buffer, 
131          "0x%08lx: %s %s\n", 
132          &last.address, 
133          last.instruction, 
134          last.data
135        );
136      } while( result > 1);
137
138      nextlogical = objdumpProcessor->getAddressAfter(last.address);
139
140      if (! ReadUntilFound( logFile, QEMU_LOG_IN_KEY )) {
141        done = true;
142        nextExecuted = last;
143      } else {
144        fgets(buffer, 120, logFile );
145        result = sscanf( 
146          buffer, 
147          "0x%08lx: %s %s\n", 
148          &nextExecuted.address, 
149          nextExecuted.instruction, 
150          nextExecuted.data
151        );
152        if ( result < 2 ) 
153        {
154          fprintf(stderr, "Error Unable to Read First Block\n" );
155        }
156      }
157
158      // If the nextlogical was not found we are throwing away
159      // the block; otherwise add the block to the trace list.
160      if (nextlogical != 0) {
161        TraceList::exitReason_t reason = TraceList::EXIT_REASON_OTHER;
162
163        if ( objdumpProcessor->IsBranch( last.instruction ) ) {
164          if ( nextExecuted.address == nextlogical ) {
165            reason = TraceList::EXIT_REASON_BRANCH_NOT_TAKEN;
166          }  else {
167            reason = TraceList::EXIT_REASON_BRANCH_TAKEN;
168          }
169        }
170        Trace.add( first.address, nextlogical, reason );
171      }
172      first = nextExecuted;
173    } 
174    fclose( logFile );
175    return true;
176  }
177}
Note: See TracBrowser for help on using the repository browser.