asar coverage - build #84


src/asar/
File: src/asar/addr2line.cpp
Date: 2024-01-19 08:25:32
Lines:
25/25
100.0%
Functions:
3/3
100.0%
Branches:
5/6
83.3%

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