Skip to content
Verified Commit 3016a339 authored by Sean Fitzgibbon's avatar Sean Fitzgibbon
Browse files

Fix a defect in function coverage reporting.

DWARF line table entries refer to files by their index in the file table
for the compilation unit ('CU').  Entries in the file table refer to
directories by their index in the directory table for the CU.

The function _full_path() reads the tables to recover the path for a
file index.  It assumes that the result is the full path to the file.
This is mistaken: the directory table may contain paths which are
relative to the compilation directory of the CU as given in the
attribute 'DW_AT_comp_dir' of the topmost Debugging Information Entry
('DIE') for the CU.

This patch fixes the defect, adds unit tests, and adds handling for a
few edge cases recommended as defensive programming by ChatGPT.

- Read DW_AT_comp_dir from the top DIE of each CU and prepend it to any
  non-absolute paths found in the directory table.

- Do not report line table entries referring to line 0 of a source file.
  These indicate instructions which originate from the source file, but
  which the compiler couldn't attribute to any particular line(s). Since
  the ultimate goals of this tool are line / function / branch coverage,
  they should be ignored.  (In particular, they do not indicate coverage
  of line zero).

- Tolerate file table entries which refer to index 0 in the directory
  table.  The table is 1-based, but index 0 is permitted and means the
  compilation directory of the CU.

- Tolerate CUs which don't have a line program in the DWARF.

- Expand the opaque _gen_line_entries() function for readability.

- Fix a typo 'scr' -> 'src'.

Change-Id: I03d781660267bf8dcc6372874adfa312ca3df54d
parent 242c3012
Loading
Loading
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment