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 &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 &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 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 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) - ? "" : "???"); + 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) + ? "" : "???"); + + 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)