asar coverage - build #178


src/asar/
File: src/asar/addr2line.cpp
Date: 2024-01-28 19:46:03
Lines:
27/27
100.0%
Functions:
3/3
100.0%
Branches:
15/26
57.7%

Line Branch Exec Source
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 586 void AddressToLineMapping::reset()
15 {
16 586 m_fileList.reset();
17 586 m_filenameCrcs.reset();
18 586 m_addrToLineInfo.reset();
19 586 }
20
21 // Adds information of what source file and line number an output rom address is at
22 74928 void AddressToLineMapping::includeMapping(const char* filename, int line, int addr)
23 {
24 37464 AddrToLineInfo newInfo;
25
1/2
✓ Branch 0 taken 37464 times.
✗ Branch 1 not taken.
74928 newInfo.fileIdx = getFileIndex(filename);
26 74928 newInfo.line = line;
27 74928 newInfo.addr = addr;
28
29
1/2
✓ Branch 0 taken 37464 times.
✗ Branch 1 not taken.
74928 m_addrToLineInfo.append(newInfo);
30 74928 }
31
32 // Helper to add file to list, and get the index of that file
33 74928 int AddressToLineMapping::getFileIndex(const char* filename)
34 {
35 // check if the file exists first
36
1/2
✓ Branch 0 taken 37464 times.
✗ Branch 1 not taken.
74928 uint32_t filenameCrc = crc32((const uint8_t*)filename, (unsigned int)strlen(filename));
37
2/2
✓ Branch 0 taken 74830 times.
✓ Branch 1 taken 176 times.
75006 for (int i = 0; i < m_filenameCrcs.count; ++i)
38 {
39
4/4
✓ Branch 0 taken 74791 times.
✓ Branch 1 taken 39 times.
✓ Branch 2 taken 37376 times.
✓ Branch 3 taken 39 times.
74830 if (m_filenameCrcs[i] == filenameCrc)
40 {
41 74752 return i;
42 }
43 }
44
45 // file doesn't exist, so start tracking it
46 176 char* data = nullptr;
47 176 int len = 0;
48 88 uint32_t fileCrc = 0;
49
2/4
✓ Branch 0 taken 176 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 88 times.
✗ Branch 3 not taken.
176 if (readfile(filename, "", &data, &len))
50 {
51
1/2
✓ Branch 0 taken 88 times.
✗ Branch 1 not taken.
176 fileCrc = crc32((const uint8_t*)data, (unsigned int)len);
52 }
53 176 free(data);
54
55 264 m_fileList.append({ string(filename), fileCrc });
56
1/2
✓ Branch 0 taken 88 times.
✗ Branch 1 not taken.
176 m_filenameCrcs.append(filenameCrc);
57
58 176 return m_fileList.count - 1;
59
2/6
✓ Branch 0 taken 88 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 88 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
176 }
60
61