Line |
Branch |
Exec |
Source |
1 |
|
|
#include "addr2line.h" |
2 |
|
|
#include "crc32.h" |
3 |
|
|
|
4 |
|
|
////////////////////////////////////////////////////////////////////////// |
5 |
|
|
// Class to store address-to-line mappings for richer symbolic information |
6 |
|
|
// |
7 |
|
|
// During assembly, included files and information about generated asm |
8 |
|
|
// should be added to this, and then read back during symbol file |
9 |
|
|
// generation |
10 |
|
|
|
11 |
|
826 |
void AddressToLineMapping::reset() |
12 |
|
|
{ |
13 |
|
826 |
m_fileList.reset(); |
14 |
|
826 |
m_filenameCrcs.reset(); |
15 |
|
826 |
m_addrToLineInfo.reset(); |
16 |
|
826 |
} |
17 |
|
|
|
18 |
|
|
// Adds information of what source file and line number an output rom address is at |
19 |
|
5501 |
void AddressToLineMapping::includeMapping(const char* filename, int line, int addr) |
20 |
|
|
{ |
21 |
|
2767 |
AddrToLineInfo newInfo; |
22 |
2/3
✓ Branch 0 taken 2734 times.
✓ Branch 1 taken 2767 times.
✗ Branch 2 not taken.
|
5501 |
newInfo.fileIdx = getFileIndex(filename); |
23 |
|
5501 |
newInfo.line = line; |
24 |
|
5501 |
newInfo.addr = addr; |
25 |
|
|
|
26 |
2/4
✓ Branch 0 taken 2734 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2767 times.
✗ Branch 3 not taken.
|
5501 |
m_addrToLineInfo.append(newInfo); |
27 |
|
5501 |
} |
28 |
|
|
|
29 |
|
|
// Helper to add file to list, and get the index of that file |
30 |
|
5501 |
int AddressToLineMapping::getFileIndex(const char* filename) |
31 |
|
|
{ |
32 |
|
|
// check if the file exists first |
33 |
3/4
✓ Branch 0 taken 2734 times.
✓ Branch 1 taken 2767 times.
✓ Branch 2 taken 2767 times.
✗ Branch 3 not taken.
|
5501 |
uint32_t filenameCrc = crc32((const uint8_t*)filename, (unsigned int)strlen(filename)); |
34 |
4/4
✓ Branch 0 taken 2686 times.
✓ Branch 1 taken 98 times.
✓ Branch 2 taken 2703 times.
✓ Branch 3 taken 120 times.
|
5607 |
for (int i = 0; i < m_filenameCrcs.count; ++i) |
35 |
|
|
{ |
36 |
5/7
✓ Branch 0 taken 2686 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2636 times.
✓ Branch 3 taken 2753 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 2647 times.
✓ Branch 6 taken 56 times.
|
5389 |
if (m_filenameCrcs[i] == filenameCrc) |
37 |
|
|
{ |
38 |
|
5283 |
return i; |
39 |
|
|
} |
40 |
|
|
} |
41 |
|
|
|
42 |
|
|
// file doesn't exist, so start tracking it |
43 |
|
218 |
char* data = nullptr; |
44 |
|
218 |
int len = 0; |
45 |
|
218 |
uint32_t fileCrc = 0; |
46 |
2/4
✓ Branch 0 taken 218 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 218 times.
✗ Branch 3 not taken.
|
218 |
if (readfile(filename, "", &data, &len)) |
47 |
|
|
{ |
48 |
1/2
✓ Branch 0 taken 218 times.
✗ Branch 1 not taken.
|
218 |
fileCrc = crc32((const uint8_t*)data, (unsigned int)len); |
49 |
|
|
} |
50 |
|
218 |
free(data); |
51 |
|
|
|
52 |
1/2
✓ Branch 0 taken 120 times.
✗ Branch 1 not taken.
|
338 |
m_fileList.append({ string(filename), fileCrc }); |
53 |
2/4
✓ Branch 0 taken 98 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 120 times.
✗ Branch 3 not taken.
|
218 |
m_filenameCrcs.append(filenameCrc); |
54 |
|
|
|
55 |
|
218 |
return m_fileList.count - 1; |
56 |
2/6
✓ Branch 0 taken 218 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 98 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
|
218 |
} |
57 |
|
|
|