asar coverage - build #291


src/asar/
File: src/asar/addr2line.cpp
Date: 2025-03-10 01:11:53
Lines:
27/27
100.0%
Functions:
3/3
100.0%
Branches:
14/26
53.8%

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