@@ -457,14 +457,11 @@ void TraceFileParser::readFileHeader(TraceFileReader* that)
457457 }
458458}
459459
460- static bool readBlock (QFile & traceFile)
460+ static bool readBlock (QFile & traceFile, unsigned char blockType )
461461{
462462 if (!traceFile.isReadable ())
463463 throw std::wstring (L" File is not readable" );
464- unsigned char blockType;
465464 unsigned char changedCountFlags[3 ]; // reg changed count, mem accessed count, flags
466- if (traceFile.read ((char *)&blockType, 1 ) != 1 )
467- throw std::wstring (L" Read block type failed" );
468465 if (blockType == 0 )
469466 {
470467 if (traceFile.read ((char *)&changedCountFlags, 3 ) != 3 )
@@ -525,21 +522,27 @@ void TraceFileParser::run()
525522 while (!that->traceFile .atEnd ())
526523 {
527524 quint64 blockStart = that->traceFile .pos ();
528- bool isPageBoundary = readBlock (that->traceFile );
529- if (isPageBoundary)
525+ unsigned char blockType;
526+ if (that->traceFile .read ((char *)&blockType, 1 ) != 1 )
527+ throw std::wstring (L" Read block type failed" );
528+ bool isPageBoundary = readBlock (that->traceFile , blockType);
529+ if (blockType < 0x80 ) // Check whether it is a non-user block
530530 {
531- if (lastIndex != 0 )
532- that->fileIndex .back ().second .second = index - (lastIndex - 1 );
533- that->fileIndex .push_back (std::make_pair (index, TraceFileReader::Range (blockStart, 0 )));
534- lastIndex = index + 1 ;
535- // Update progress
536- that->progress .store (that->traceFile .pos () * 100 / filesize);
537- if (that->progress == 100 )
538- that->progress = 99 ;
539- if (this ->isInterruptionRequested () && !that->traceFile .atEnd ()) // Cancel loading
540- throw std::wstring (L" Canceled" );
531+ if (isPageBoundary)
532+ {
533+ if (lastIndex != 0 )
534+ that->fileIndex .back ().second .second = index - (lastIndex - 1 );
535+ that->fileIndex .push_back (std::make_pair (index, TraceFileReader::Range (blockStart, 0 )));
536+ lastIndex = index + 1 ;
537+ // Update progress
538+ that->progress .store (that->traceFile .pos () * 100 / filesize);
539+ if (that->progress == 100 )
540+ that->progress = 99 ;
541+ if (this ->isInterruptionRequested () && !that->traceFile .atEnd ()) // Cancel loading
542+ throw std::wstring (L" Canceled" );
543+ }
544+ index++;
541545 }
542- index++;
543546 }
544547 if (index > 0 )
545548 that->fileIndex .back ().second .second = index - (lastIndex - 1 );
@@ -591,16 +594,22 @@ void TraceFileReader::purgeLastPage()
591594 while (!traceFile.atEnd ())
592595 {
593596 quint64 blockStart = traceFile.pos ();
594- bool isPageBoundary = readBlock (traceFile);
595- if (isPageBoundary)
597+ unsigned char blockType;
598+ if (traceFile.read ((char *)&blockType, 1 ) != 1 )
599+ throw std::wstring (L" Read block type failed" );
600+ bool isPageBoundary = readBlock (traceFile, blockType);
601+ if (blockType < 0x80 ) // Check whether it is a non-user block
596602 {
597- if (lastIndex != 0 )
598- fileIndex.back ().second .second = index - (lastIndex - 1 );
599- fileIndex.push_back (std::make_pair (index, TraceFileReader::Range (blockStart, 0 )));
600- lastIndex = index + 1 ;
601- isBlockExist = true ;
603+ if (isPageBoundary)
604+ {
605+ if (lastIndex != 0 )
606+ fileIndex.back ().second .second = index - (lastIndex - 1 );
607+ fileIndex.push_back (std::make_pair (index, TraceFileReader::Range (blockStart, 0 )));
608+ lastIndex = index + 1 ;
609+ isBlockExist = true ;
610+ }
611+ index++;
602612 }
603- index++;
604613 }
605614 if (isBlockExist)
606615 fileIndex.back ().second .second = index - (lastIndex - 1 );
0 commit comments