LCOV - code coverage report
Current view: top level - asar - addr2line.cpp (source / functions) Coverage Total Hit
Test: asar.info Lines: 100.0 % 25 25
Test Date: 2024-01-15 16:32:53 Functions: 100.0 % 3 3
Branches: 83.3 % 6 5

             Branch data     Line data    Source code
       1                 :             : #include "addr2line.h"
       2                 :             : #include "asar.h"
       3                 :             : #include "crc32.h"
       4                 :             : #include "libstr.h"
       5                 :             : #include <cstdint>
       6                 :             : 
       7                 :             : //////////////////////////////////////////////////////////////////////////
       8                 :             : // Class to store address-to-line mappings for richer symbolic information
       9                 :             : //
      10                 :             : // During assembly, included files and information about generated asm
      11                 :             : // should be added to this, and then read back during symbol file
      12                 :             : // generation
      13                 :             : 
      14                 :         281 : void AddressToLineMapping::reset()
      15                 :             : {
      16                 :         281 :         m_fileList.reset();
      17                 :         281 :         m_filenameCrcs.reset();
      18                 :         281 :         m_addrToLineInfo.reset();
      19                 :         281 : }
      20                 :             : 
      21                 :             : // Adds information of what source file and line number an output rom address is at
      22                 :       37405 : void AddressToLineMapping::includeMapping(const char* filename, int line, int addr)
      23                 :             : {
      24                 :             :         AddrToLineInfo newInfo;
      25                 :       37405 :         newInfo.fileIdx = getFileIndex(filename);
      26                 :       37405 :         newInfo.line = line;
      27                 :       37405 :         newInfo.addr = addr;
      28                 :             : 
      29                 :       37405 :         m_addrToLineInfo.append(newInfo);
      30                 :       37405 : }
      31                 :             : 
      32                 :             : // Helper to add file to list, and get the index of that file
      33                 :       37405 : int AddressToLineMapping::getFileIndex(const char* filename)
      34                 :             : {
      35                 :             :         // check if the file exists first
      36                 :       37405 :         uint32_t filenameCrc = crc32((const uint8_t*)filename, (unsigned int)strlen(filename));
      37         [ +  + ]:       37444 :         for (int i = 0; i < m_filenameCrcs.count; ++i)
      38                 :             :         {
      39         [ +  + ]:       37360 :                 if (m_filenameCrcs[i] == filenameCrc)
      40                 :             :                 {
      41                 :       37321 :                         return i;
      42                 :             :                 }
      43                 :             :         }
      44                 :             : 
      45                 :             :         // file doesn't exist, so start tracking it
      46                 :          84 :         char* data = nullptr;
      47                 :          84 :         int len = 0;
      48                 :             :         uint32_t fileCrc = 0;
      49         [ +  - ]:          84 :         if (readfile(filename, "", &data, &len))
      50                 :             :         {
      51                 :          84 :                 fileCrc = crc32((const uint8_t*)data, (unsigned int)len);
      52                 :             :         }
      53                 :          84 :         free(data);
      54                 :             : 
      55                 :         252 :         m_fileList.append({ string(filename), fileCrc });
      56                 :          84 :         m_filenameCrcs.append(filenameCrc);
      57                 :             : 
      58                 :          84 :         return m_fileList.count - 1;
      59                 :          84 : }
      60                 :             : 
        

Generated by: LCOV version 2.0-1