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 : 335 : void AddressToLineMapping::reset()
13 : : {
14 : 335 : m_fileList.reset();
15 : 335 : m_filenameCrcs.reset();
16 : 335 : m_addrToLineInfo.reset();
17 : 335 : }
18 : :
19 : : // Adds information of what source file and line number an output rom address is at
20 : 2612 : void AddressToLineMapping::includeMapping(const char* filename, int line, int addr)
21 : : {
22 : : AddrToLineInfo newInfo;
23 : 2612 : newInfo.fileIdx = getFileIndex(filename);
24 : 2612 : newInfo.line = line;
25 : 2612 : newInfo.addr = addr;
26 : :
27 : 2612 : m_addrToLineInfo.append(newInfo);
28 : 2612 : }
29 : :
30 : : // Helper to add file to list, and get the index of that file
31 : 2612 : int AddressToLineMapping::getFileIndex(const char* filename)
32 : : {
33 : : // check if the file exists first
34 : 2612 : uint32_t filenameCrc = crc32((const uint8_t*)filename, (unsigned int)strlen(filename));
35 [ + + ]: 2662 : for (int i = 0; i < m_filenameCrcs.count; ++i)
36 : : {
37 [ + + ]: 2569 : if (m_filenameCrcs[i] == filenameCrc)
38 : : {
39 : 2519 : return i;
40 : : }
41 : : }
42 : :
43 : : // file doesn't exist, so start tracking it
44 : 93 : char* data = nullptr;
45 : 93 : int len = 0;
46 : : uint32_t fileCrc = 0;
47 [ + - ]: 93 : if (readfile(filename, "", &data, &len))
48 : : {
49 : 93 : fileCrc = crc32((const uint8_t*)data, (unsigned int)len);
50 : : }
51 : 93 : free(data);
52 : :
53 : 279 : m_fileList.append({ string(filename), fileCrc });
54 : 93 : m_filenameCrcs.append(filenameCrc);
55 : :
56 : 93 : return m_fileList.count - 1;
57 : 93 : }
|