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