asar coverage - build #86


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