diff mbox

[PR58315] reset inlined debug vars at return-to point

Message ID orbnkfaw4b.fsf@livre.home
State New
Headers show

Commit Message

Alexandre Oliva Feb. 27, 2015, 9:21 p.m. UTC
On Feb 27, 2015, Petr Machata <pmachata@redhat.com> wrote:

> Alexandre Oliva <aoliva@redhat.com> writes:
>> Ok, I looked into it further, after patching dwlocstat to dump
>> per-variable per-range coverage/length info, so as to be able to compare
>> object files more easily.

> If you send me those patches, I can finish them, bind the functionality
> to a command line option, and merge upstream.

Here's what I've got so far.  It's ugly and needs polishing, that I
planned to do once this issue was resolved, but if you feel like beating
me to it, you're surely welcome to ;-)

I'm sure there must be a better way to compute the CIE offset, or even
the base address of the debug info section (at least the "- 11" needs to
be replaced by something more sensible and more portable), but I didn't
try very hard to find it out :-)  Anyway, ideally, dumping it would be
optional; I've added and removed it numerous times depending on the
exact object file I was comparing and what info I sought.
diff mbox

Patch

diff --git a/locstats.cc b/locstats.cc
index 8a458cb..0b71ceb 100644
--- a/locstats.cc
+++ b/locstats.cc
@@ -240,7 +240,8 @@  static die_action process_location (Dwarf_Attribute *locattr,
 				    bool full_implicit,
 				    std::bitset<dt__count> &die_type,
 				    mutability_t &mut,
-				    int &coverage);
+				    int &coverage,
+				    bool dump_partials = false);
 
 static die_action process_implicit_pointer (Dwarf_Attribute *locattr,
 					    Dwarf_Op *op,
@@ -400,7 +401,8 @@  process_location (Dwarf_Attribute *locattr,
 		  bool full_implicit,
 		  std::bitset<dt__count> &die_type,
 		  mutability_t &mut,
-		  int &coverage)
+		  int &coverage,
+		  bool dump_partials)
 {
   Dwarf_Op *expr;
   size_t len;
@@ -459,6 +461,7 @@  process_location (Dwarf_Attribute *locattr,
 	{
 	  Dwarf_Addr low = rit->first;
 	  Dwarf_Addr high = rit->second;
+	  size_t const covered_before = covered;
 	  length += high - low;
 	  //std::cerr << " " << low << ".." << high << std::endl;
 
@@ -525,6 +528,10 @@  process_location (Dwarf_Attribute *locattr,
 	      if (cover)
 		covered++;
 	    }
+
+	  if (dump_partials)
+	    std::cout << ' ' << (covered - covered_before)
+		      << '/' << (high - low);
 	}
 
       if (length == 0 || covered == 0)
@@ -562,6 +569,8 @@  is_inlined (Dwarf_Die *die)
 void
 process (Dwarf *dw)
 {
+  const bool dump_partials = true;
+
   // map percentage->occurrences.  Percentage is cov_00..100, where
   // 0..100 is rounded-down integer division.
   std::map<int, unsigned long> tally;
@@ -586,11 +595,16 @@  process (Dwarf *dw)
     for (cu_iterator it = cu_iterator (dw); it != cu_iterator::end (); ++it)
       last_cit = it;
 
+  char *base = NULL;
+
   for (all_dies_iterator it (dw); it != all_dies_iterator::end (); ++it)
     {
       std::bitset<dt__count> die_type;
       Dwarf_Die *die = *it;
 
+      if (!base)
+	base = (char*)die->addr - 11;
+
       if (show_progress)
 	{
 	  cu_iterator cit = it.cu ();
@@ -677,17 +691,29 @@  process (Dwarf *dw)
       if (locattr == NULL)
 	locattr = dwarf_attr (die, DW_AT_const_value, &locattr_mem);
 
-      /*
-      Dwarf_Attribute name_attr_mem,
-	*name_attr = dwarf_attr_integrate (die, DW_AT_name, &name_attr_mem);
-      std::string name = name_attr != NULL
-	? dwarf_formstring (name_attr)
-	: (dwarf_hasattr_integrate (die, DW_AT_artificial)
-	   ? "<artificial>" : "???");
+      if (dump_partials)
+	{
+	  std::string name;
 
-      std::cerr << "die=" << std::hex << die.offset ()
-		<< " '" << name << '\'';
-      */
+	  for (auto pit = it; pit != all_dies_iterator::end ();
+	       pit = pit.parent ())
+	    {
+	      Dwarf_Attribute name_attr_mem,
+		*name_attr = dwarf_attr_integrate (*pit, DW_AT_name, &name_attr_mem);
+	      std::string thisname = name_attr != NULL
+		? dwarf_formstring (name_attr)
+		: (dwarf_hasattr_integrate (*pit, DW_AT_artificial)
+		   ? "<artificial>" : "???");
+
+	      if (name != "")
+		name = thisname + "::" + name;
+	      else
+		name = thisname;
+	    }
+
+	  std::cout // << "die=" << std::hex << (char*)die->addr - base << ' '
+	    << name;
+	}
 
       int coverage;
       mutability_t mut;
@@ -697,7 +723,7 @@  process (Dwarf *dw)
 				interested_mutability,
 				interested_implicit,
 				full_implicit,
-				die_type, mut, coverage) != da_ok)
+				die_type, mut, coverage, dump_partials) != da_ok)
 	    continue;
 	}
       catch (::error &e)
@@ -751,7 +777,7 @@  process (Dwarf *dw)
 
       tally[coverage]++;
       total++;
-      //std::cerr << std::endl;
+      std::cout << std::endl;
     }
 
   if (show_progress)