Fix: flt.lttng-utils.debug-info: cannot find addr past the first CU
authorFrancis Deslauriers <francis.deslauriers@efficios.com>
Tue, 28 May 2019 00:45:06 +0000 (20:45 -0400)
committerPhilippe Proulx <eeppeliteloop@gmail.com>
Tue, 28 May 2019 14:04:03 +0000 (10:04 -0400)
Issue
=====
The `bin_info_lookup_source_location()` function doesn't look past the
first Compile Unit(CU) in the Dwarf information to find the filename and
line number of an address. This function iterates over all CUs of the
binary (or shared object) and tries to translate the address with each
of them. It ends up calling two other functions:
`bin_info_lookup_cu_src_loc_no_inl()`and `bin_info_lookup_cu_src_loc_inl()`
in a loop to cover all the CUs.

The `bin_info_lookup_cu_src_loc_no_inl()` function returns an error
(returning -1) if it can't find the line of the give address making the
calling function exit the loop, and thus abort the resolving.

The information that the resolving was unsuccessful is transmit back to
the caller by omitting to set the `src_loc` output parameter. The return
value of this function is used to notify the caller of an error. Not
resolving the source line should not make the function return -1.

This has the effect that if an address is contained in a CU after the
first one this function will not be able to resolve it.

Solution
========
Return 0 if the line is not found so that the search continues with
other CUs.

Drawbacks
=========
None.

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Change-Id: I4d85bc75d32a9a25a7044f3686c6d5940311fa68
Reviewed-on: https://review.lttng.org/c/babeltrace/+/1337
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
plugins/lttng-utils/debug-info/bin-info.c

index 280462906b8192cd8e98ea6f84eb1adde02cea80..c0546c861df8a4288f489bb089d860800fbdc7c5 100644 (file)
@@ -1435,7 +1435,9 @@ error:
  * @param cu           bt_dwarf_cu instance in which to look for the address
  * @param addr         The address for which to look for
  * @param src_loc      Out parameter, the source location (filename and
- *                     line number) for the address
+ *                     line number) for the address. Set only if the address
+ *                     is found and resolved successfully
+ *
  * @returns            0 on success, -1 on failure
  */
 static
@@ -1460,7 +1462,8 @@ int bin_info_lookup_cu_src_loc_no_inl(struct bt_dwarf_cu *cu, uint64_t addr,
 
        line = dwarf_getsrc_die(die->dwarf_die, addr);
        if (!line) {
-               goto error;
+               /* This is not an error. The caller needs to keep looking. */
+               goto end;
        }
 
        ret = dwarf_lineaddr(line, &line_addr);
@@ -1494,6 +1497,7 @@ int bin_info_lookup_cu_src_loc_no_inl(struct bt_dwarf_cu *cu, uint64_t addr,
                *src_loc = _src_loc;
        }
 
+end:
        return 0;
 
 error:
This page took 0.025184 seconds and 4 git commands to generate.