asar coverage - build #90


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