I am trying to create a line coverage program in Python.
The goal is to receive list of PCs from a test running on a device and to get information of which functions, conditions and lines of the FW of said device were covered by the test.
The said device has an ARC processor, if that helps.
I have the ELF binaries and the source code (written in C), but can't share them here (confidential company information).
I have taken the ELF file and managed to get .text section disassembly (which is essentially the assembly code of the program).
I have disassembled the FW of the device, so I have the disassembled FW in this manner:
PC: hex_opcode assembly_command operands
like this:
0x100: 7eff mov a,b
Also, using pyelftools from Eli Bendersky : https://github.com/eliben/pyelftools
I have managed to get the source file and line number of the beginning of the function, so I have managed to map the assembly code of each function to source.
And using High PC and Low PC from the functions, I have managed to link the PCs from test logs to functions.
But now I am stuck trying to map individual assembly lines to their location in C source code.
I know that for this I need to read information in .debug_line in DWARF, but I can't quite understand it.
I have managed to come across this:
Where they say: Line += Line base + (Opcode - Opcode base) % Line range
I have all the information except Line and Opcode.
By "Line" do they mean starting line on function? (f.e. if "void func()" is located at file source.c line 5) Previous line?
And by "opcode" is this the major opcode of the assembly command? Or the full assembly command opcode (like 0x7eff in binary representation) Something else? Some other Opcodes from DWARF info?
The calculation, from what I understood, is done in decimal, so the opcode must be converted to decimal.
Thanks in advance for the help.
Vadim