Changeset fb987e8 in rtems-tools for tester/covoar/DesiredSymbols.cc


Ignore:
Timestamp:
May 8, 2018, 5:09:39 AM (14 months ago)
Author:
Chris Johns <chrisj@…>
Branches:
master
Children:
efbf8f0
Parents:
558cab8
git-author:
Chris Johns <chrisj@…> (05/08/18 05:09:39)
git-committer:
Chris Johns <chrisj@…> (06/15/18 05:54:25)
Message:

covoar: Use DWARF to map addresses to source files and lines.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tester/covoar/DesiredSymbols.cc

    r558cab8 rfb987e8  
    1010#endif
    1111
    12 #include <libgen.h>
    1312#include <limits.h>
    1413#include <stdio.h>
     
    446445  )
    447446  {
    448     char*                              base;
    449     char*                              cStatus;
    450     char                               command[512];
    451     std::string                        fileName;
    452     CoverageRanges::ranges_t::iterator ritr;
    453     char                               rpath[PATH_MAX];
    454     FILE*                              tmpfile;
    455 
    456     // Open a temporary file for the uncovered ranges.
    457     tmpfile = fopen( "ranges1.tmp", "w" );
    458     if ( !tmpfile ) {
    459       fprintf(
    460         stderr,
    461         "ERROR: DesiredSymbols::determineSourceLines - "
    462         "unable to open %s\n",
    463         "ranges1.tmp"
    464       );
    465       exit(-1);
    466     }
    467 
    468     // Write the range addresses to the temporary file.
    469     for (ritr =  theRanges->set.begin();
    470          ritr != theRanges->set.end();
    471          ritr++ ) {
    472       fprintf(
    473         tmpfile,
    474         "0x%08x\n0x%08x\n",
    475         ritr->lowAddress - theExecutable->getLoadAddress(),
    476         ritr->highAddress - theExecutable->getLoadAddress()
    477       );
    478     }
    479 
    480     fclose( tmpfile );
    481 
    482     // Invoke addr2line to generate the source lines for each address.
    483     if (theExecutable->hasDynamicLibrary())
    484       fileName = theExecutable->getLibraryName();
    485     else
    486       fileName = theExecutable->getFileName();
    487 
    488     sprintf(
    489       command,
    490       "%s -Ce %s <%s | dos2unix >%s",
    491       TargetInfo->getAddr2line(),
    492       fileName.c_str(),
    493       "ranges1.tmp",
    494       "ranges2.tmp"
    495     );
    496 
    497     if (system( command )) {
    498       fprintf(
    499         stderr,
    500         "ERROR: DesiredSymbols::determineSourceLines - "
    501         "command (%s) failed\n",
    502         command
    503       );
    504       exit( -1 );
    505     }
    506 
    507     // Open the addr2line output file.
    508     tmpfile = fopen( "ranges2.tmp", "r" );
    509     if ( !tmpfile ) {
    510       fprintf(
    511         stderr,
    512         "ERROR: DesiredSymbols::determineSourceLines - "
    513         "unable to open %s\n",
    514         "ranges2.tmp"
    515       );
    516       exit(-1);
    517     }
    518 
    519     // Process the addr2line output.
    520     for (ritr =  theRanges->set.begin();
    521          ritr != theRanges->set.end();
    522          ritr++ ) {
    523 
    524       cStatus = fgets( inputBuffer, MAX_LINE_LENGTH, tmpfile );
    525       if ( cStatus == NULL ) {
    526         fprintf(
    527           stderr,
    528           "ERROR: DesiredSymbols::determineSourceLines - "
    529           "Out of sync in addr2line output\n"
    530         );
    531         exit( -1 );
    532       }
    533       inputBuffer[ strlen(inputBuffer) - 1] = '\0';
    534 
    535       // Use only the base filename without directory path.
    536 #ifdef _WIN32
    537       #define realpath(N,R) _fullpath((R),(N),_MAX_PATH)
    538 #endif
    539       realpath( inputBuffer, rpath );
    540       base = basename( rpath );
    541 
    542       ritr->lowSourceLine = std::string( base );
    543 
    544       cStatus = fgets( inputBuffer, MAX_LINE_LENGTH, tmpfile );
    545       if ( cStatus == NULL ) {
    546         fprintf(
    547           stderr,
    548           "ERROR: DesiredSymbols::determineSourceLines - "
    549           "Out of sync in addr2line output\n"
    550         );
    551         exit( -1 );
    552       }
    553       inputBuffer[ strlen(inputBuffer) - 1] = '\0';
    554 
    555       // Use only the base filename without directory path.
    556       realpath( inputBuffer, rpath );
    557       base = basename( rpath );
    558 
    559       ritr->highSourceLine = std::string( base );
    560     }
    561 
    562     fclose( tmpfile );
    563     unlink( "ranges1.tmp" );
    564     unlink( "ranges2.tmp" );
     447    for (auto& r : theRanges->set) {
     448      std::string location;
     449      theExecutable->getSourceAndLine(r.lowAddress, location);
     450      r.lowSourceLine = rld::path::basename (location);
     451      theExecutable->getSourceAndLine(r.highAddress, location);
     452      r.highSourceLine = rld::path::basename (location);
     453    }
    565454  }
    566455
Note: See TracChangeset for help on using the changeset viewer.