asar coverage - build #76


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