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 |
|
37405 |
AddrToLineInfo newInfo; |
25 |
1/2
✓ Branch 0 taken 37405 times.
✗ Branch 1 not taken.
|
74810 |
newInfo.fileIdx = getFileIndex(filename); |
26 |
|
74810 |
newInfo.line = line; |
27 |
|
74810 |
newInfo.addr = addr; |
28 |
|
|
|
29 |
1/2
✓ Branch 0 taken 37405 times.
✗ Branch 1 not taken.
|
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 |
1/2
✓ Branch 0 taken 37405 times.
✗ Branch 1 not taken.
|
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 |
4/4
✓ Branch 0 taken 74681 times.
✓ Branch 1 taken 39 times.
✓ Branch 2 taken 37321 times.
✓ Branch 3 taken 39 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 |
|
84 |
uint32_t fileCrc = 0; |
49 |
2/4
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 84 times.
✗ Branch 3 not taken.
|
168 |
if (readfile(filename, "", &data, &len)) |
50 |
|
|
{ |
51 |
1/2
✓ Branch 0 taken 84 times.
✗ Branch 1 not taken.
|
168 |
fileCrc = crc32((const uint8_t*)data, (unsigned int)len); |
52 |
|
|
} |
53 |
|
168 |
free(data); |
54 |
|
|
|
55 |
|
252 |
m_fileList.append({ string(filename), fileCrc }); |
56 |
1/2
✓ Branch 0 taken 84 times.
✗ Branch 1 not taken.
|
168 |
m_filenameCrcs.append(filenameCrc); |
57 |
|
|
|
58 |
|
168 |
return m_fileList.count - 1; |
59 |
2/6
✓ Branch 0 taken 84 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 84 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
|
168 |
} |
60 |
|
|
|
61 |
|
|
|