Fill some gaps in .debug_loc.

Use best-effort guess when the location is unknown.  This is only
relevant for PCs in the middle of the statement where the debugger
should not usually stop in the first place.

The main motivation is to reduce the size .debug_loc since the
best-effort guesses allow us to merge consecutive entries.

Change-Id: I94bfd01363404e72a2c953309e59020b1a6a4764
diff --git a/compiler/debug/elf_debug_loc_writer.h b/compiler/debug/elf_debug_loc_writer.h
index fd7f949..a19b36f 100644
--- a/compiler/debug/elf_debug_loc_writer.h
+++ b/compiler/debug/elf_debug_loc_writer.h
@@ -82,6 +82,8 @@
 // Get the location of given dex register (e.g. stack or machine register).
 // Note that the location might be different based on the current pc.
 // The result will cover all ranges where the variable is in scope.
+// PCs corresponding to stackmap with dex register map are accurate,
+// all other PCs are best-effort only.
 std::vector<VariableLocation> GetVariableLocations(const MethodDebugInfo* method_info,
                                                    uint16_t vreg,
                                                    bool is64bitValue,
@@ -141,6 +143,9 @@
         variable_locations.back().high_pc == low_pc) {
       // Merge with the previous entry (extend its range).
       variable_locations.back().high_pc = high_pc;
+    } else if (!variable_locations.empty() && reg_lo == DexRegisterLocation::None()) {
+      // Unknown location - use the last known location as best-effort guess.
+      variable_locations.back().high_pc = high_pc;
     } else {
       variable_locations.push_back({low_pc, high_pc, reg_lo, reg_hi});
     }