asar coverage - build #324


src/asar/
File: src/asar/addr2line.cpp
Date: 2025-11-02 06:43:51
Lines:
26/26
100.0%
Functions:
3/3
100.0%
Branches:
19/36
52.8%

Line Branch Exec Source
1 #include "addr2line.h"
2 #include "crc32.h"
3
4 //////////////////////////////////////////////////////////////////////////
5 // Class to store address-to-line mappings for richer symbolic information
6 //
7 // During assembly, included files and information about generated asm
8 // should be added to this, and then read back during symbol file
9 // generation
10
11 847 void AddressToLineMapping::reset()
12 {
13 847 m_fileList.reset();
14 847 m_file_indices_map.clear();
15 847 m_addrToLineInfo.reset();
16 847 }
17
18 // Adds information of what source file and line number an output rom address is at
19 5520 void AddressToLineMapping::includeMapping(const char* filename, int line, int addr)
20 {
21 2775 AddrToLineInfo newInfo;
22
2/3
✓ Branch 0 taken 2745 times.
✓ Branch 1 taken 2775 times.
✗ Branch 2 not taken.
5520 newInfo.fileIdx = getFileIndex(filename);
23 5520 newInfo.line = line;
24 5520 newInfo.addr = addr;
25
26
2/4
✓ Branch 0 taken 2745 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2775 times.
✗ Branch 3 not taken.
5520 m_addrToLineInfo.append(newInfo);
27 5520 }
28
29 // Helper to add file to list, and get the index of that file
30 5520 int AddressToLineMapping::getFileIndex(const char* filename)
31 {
32 // check if the file exists first
33
7/11
✓ Branch 0 taken 2745 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2745 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 5421 times.
✓ Branch 5 taken 99 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 2775 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 2655 times.
✓ Branch 10 taken 120 times.
5520 if(auto it = m_file_indices_map.find(filename); it != m_file_indices_map.end()) {
34 5301 return it->second;
35 }
36
37 // file doesn't exist, so start tracking it
38 219 char* data = nullptr;
39 219 int len = 0;
40 219 uint32_t fileCrc = 0;
41
2/4
✓ Branch 0 taken 219 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 219 times.
✗ Branch 3 not taken.
219 if (readfile(filename, "", &data, &len))
42 {
43
1/2
✓ Branch 0 taken 219 times.
✗ Branch 1 not taken.
219 fileCrc = crc32((const uint8_t*)data, (unsigned int)len);
44 }
45 219 free(data);
46
47 219 int result = m_fileList.count;
48
1/2
✓ Branch 0 taken 120 times.
✗ Branch 1 not taken.
339 m_fileList.append({ string(filename), fileCrc });
49
2/4
✓ Branch 0 taken 99 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 120 times.
✗ Branch 3 not taken.
219 m_file_indices_map.emplace(filename, result);
50
51 219 return result;
52
2/6
✓ Branch 0 taken 219 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 99 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
219 }
53