asar coverage - build #209


src/asar/
File: src/asar/addr2line.cpp
Date: 2024-02-22 21:34:57
Lines:
26/26
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
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 2247 void AddressToLineMapping::reset()
13 {
14 2247 m_fileList.reset();
15 2247 m_filenameCrcs.reset();
16 2247 m_addrToLineInfo.reset();
17 2247 }
18
19 // Adds information of what source file and line number an output rom address is at
20 16348 void AddressToLineMapping::includeMapping(const char* filename, int line, int addr)
21 {
22 AddrToLineInfo newInfo;
23
1/2
✓ Branch 0 taken 8190 times.
✗ Branch 1 not taken.
16348 newInfo.fileIdx = getFileIndex(filename);
24 16348 newInfo.line = line;
25 16348 newInfo.addr = addr;
26
27
1/2
✓ Branch 0 taken 8190 times.
✗ Branch 1 not taken.
16348 m_addrToLineInfo.append(newInfo);
28 16348 }
29
30 // Helper to add file to list, and get the index of that file
31 16348 int AddressToLineMapping::getFileIndex(const char* filename)
32 {
33 // check if the file exists first
34
1/2
✓ Branch 0 taken 8190 times.
✗ Branch 1 not taken.
16348 uint32_t filenameCrc = crc32((const uint8_t*)filename, (unsigned int)strlen(filename));
35
2/2
✓ Branch 0 taken 16045 times.
✓ Branch 1 taken 609 times.
16654 for (int i = 0; i < m_filenameCrcs.count; ++i)
36 {
37
4/4
✓ Branch 0 taken 15895 times.
✓ Branch 1 taken 150 times.
✓ Branch 2 taken 7875 times.
✓ Branch 3 taken 156 times.
16045 if (m_filenameCrcs[i] == filenameCrc)
38 {
39 15739 return i;
40 }
41 }
42
43 // file doesn't exist, so start tracking it
44 609 char* data = nullptr;
45 609 int len = 0;
46 315 uint32_t fileCrc = 0;
47
2/4
✓ Branch 0 taken 609 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 315 times.
✗ Branch 3 not taken.
609 if (readfile(filename, "", &data, &len))
48 {
49
1/2
✓ Branch 0 taken 315 times.
✗ Branch 1 not taken.
609 fileCrc = crc32((const uint8_t*)data, (unsigned int)len);
50 }
51 609 free(data);
52
53 609 m_fileList.append({ string(filename), fileCrc });
54
1/2
✓ Branch 0 taken 315 times.
✗ Branch 1 not taken.
609 m_filenameCrcs.append(filenameCrc);
55
56 609 return m_fileList.count - 1;
57
2/6
✓ Branch 0 taken 315 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 315 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
609 }
58