We were being very inconsistent with the way we were adding names to the indexes.
For DW_TAG_subprogram and DW_TAG_inlined_subroutine we would not add the mangled name if the we didn't have a simple name. We would only add the mangled name if started with '_' (even if it matches the simple name that started with '_') or if the name differed if the mangled name didn't start with '_'.
For DW_TAG_array_type, DW_TAG_base_type, DW_TAG_class_type, DW_TAG_constant, DW_TAG_enumeration_type, DW_TAG_string_type, DW_TAG_structure_type, DW_TAG_subroutine_type, DW_TAG_typedef, DW_TAG_union_type, and DW_TAG_unspecified_type we would add the simple name and the mangled name if either existed, even if they were the same..
For DW_TAG_variable we would only follow the same rule as the DW_TAG_subprogram and DW_TAG_inlined_subroutine (so no simple name meant we wouldn't add the mangled name).
Not sure if this was on purpose or not, but wanted to post this diff for discussion on what the right thing to do should be.
The new way adds a helper function called AddMangled that takes both the name and mangled name and:
- returns false if mangled is NULL or of name == mangled (same string in .debug_str)
- returns true if name is NULL so we add the mangled name even if we don't have a simple name
- returns true if the first character of mangled is different than the first character in simple name (not just blindly accepting any mangled name that starts with '_' like before)
- return true if name differs from mangled using strcmp as a last resort
We might think about adding a feature where if there is a mangled name and no simple name, chop up the demangled name like we do in the ObjectFile plug-ins when we see mangled names so we extract the basename out and then could use this as the simple name. This might help expressions find things correctly by basename