[RFA] Fix jump on uninit producer_is_clang of cu.h, rm declared/undefined find_partial_die

Message ID 20221123113254.2771869-1-philippe.waroquiers@skynet.be
State New
Headers
Series [RFA] Fix jump on uninit producer_is_clang of cu.h, rm declared/undefined find_partial_die |

Commit Message

Philippe Waroquiers Nov. 23, 2022, 11:32 a.m. UTC
  Valgrind reports a "jump on unitialised bit error" when running
e.g. gdb.base/macro-source-path.exp (see details below).

Fix this by initializing producer_is_clang member variable of dwarf2_cu.
Also remove the declared but undefined/unused method
   struct partial_die_info *find_partial_die (sect_offset sect_off);

Tested on amd64/debian11 and re-running gdb.base/macro-source-path.exp
under valgrind.

==2140965== Conditional jump or move depends on uninitialised value(s)
==2140965==    at 0x5211F7: dwarf_decode_macro_bytes(dwarf2_per_objfile*, buildsym_compunit*, bfd*, unsigned char const*, unsigned char const*, macro_source_file*, line_header const*, dwarf2_section_info const*, int, int, unsigned int, dwarf2_section_info*, dwarf2_section_info*, gdb::optional<unsigned long>, htab*, dwarf2_cu*) (macro.c:676)
==2140965==    by 0x52158A: dwarf_decode_macros(dwarf2_per_objfile*, buildsym_compunit*, dwarf2_section_info const*, line_header const*, unsigned int, unsigned int, dwarf2_section_info*, dwarf2_section_info*, gdb::optional<unsigned long>, int, dwarf2_cu*) (macro.c:967)
==2140965==    by 0x523BC4: dwarf_decode_macros(dwarf2_cu*, unsigned int, int) (read.c:23379)
==2140965==    by 0x552AB5: read_file_scope(die_info*, dwarf2_cu*) (read.c:9687)
==2140965==    by 0x54F7B2: process_die(die_info*, dwarf2_cu*) (read.c:8660)
==2140965==    by 0x5569C7: process_full_comp_unit (read.c:8429)
==2140965==    by 0x5569C7: process_queue (read.c:7675)
==2140965==    by 0x5569C7: dw2_do_instantiate_symtab (read.c:2063)
==2140965==    by 0x5569C7: dw2_instantiate_symtab(dwarf2_per_cu_data*, dwarf2_per_objfile*, bool) (read.c:2085)
==2140965==    by 0x55700B: dw2_expand_symtabs_matching_one(dwarf2_per_cu_data*, dwarf2_per_objfile*, gdb::function_view<bool (char const*, bool)>, gdb::function_view<bool (compunit_symtab*)>) (read.c:3984)
==2140965==    by 0x557EA3: cooked_index_functions::expand_symtabs_matching(objfile*, gdb::function_view<bool (char const*, bool)>, lookup_name_info const*, gdb::function_view<bool (char const*)>, gdb::function_view<bool (compunit_symtab*)>, enum_flags<block_search_flag_values>, domain_enum, search_domain) (read.c:18781)
==2140965==    by 0x778977: objfile::lookup_symbol(block_enum, char const*, domain_enum) (symfile-debug.c:276)
....
==2140965==  Uninitialised value was created by a heap allocation
==2140965==    at 0x4839F01: operator new(unsigned long) (vg_replace_malloc.c:434)
==2140965==    by 0x533A64: cutu_reader::cutu_reader(dwarf2_per_cu_data*, dwarf2_per_objfile*, abbrev_table*, dwarf2_cu*, bool, abbrev_cache*) (read.c:6264)
==2140965==    by 0x5340C2: load_full_comp_unit(dwarf2_per_cu_data*, dwarf2_per_objfile*, dwarf2_cu*, bool, language) (read.c:7729)
==2140965==    by 0x548338: load_cu(dwarf2_per_cu_data*, dwarf2_per_objfile*, bool) (read.c:2021)
==2140965==    by 0x55634C: dw2_do_instantiate_symtab (read.c:2048)
==2140965==    by 0x55634C: dw2_instantiate_symtab(dwarf2_per_cu_data*, dwarf2_per_objfile*, bool) (read.c:2085)
==2140965==    by 0x55700B: dw2_expand_symtabs_matching_one(dwarf2_per_cu_data*, dwarf2_per_objfile*, gdb::function_view<bool (char const*, bool)>, gdb::function_view<bool (compunit_symtab*)>) (read.c:3984)
==2140965==    by 0x557EA3: cooked_index_functions::expand_symtabs_matching(objfile*, gdb::function_view<bool (char const*, bool)>, lookup_name_info const*, gdb::function_view<bool (char const*)>, gdb::function_view<bool (compunit_symtab*)>, enum_flags<block_search_flag_values>, domain_enum, search_domain) (read.c:18781)
==2140965==    by 0x778977: objfile::lookup_symbol(block_enum, char const*, domain_enum) (symfile-debug.c:276)
....
---
 gdb/dwarf2/cu.c | 1 +
 gdb/dwarf2/cu.h | 2 --
 2 files changed, 1 insertion(+), 2 deletions(-)
  

Comments

Simon Marchi Nov. 24, 2022, 4:13 p.m. UTC | #1
On 11/23/22 06:32, Philippe Waroquiers via Gdb-patches wrote:
> Valgrind reports a "jump on unitialised bit error" when running
> e.g. gdb.base/macro-source-path.exp (see details below).
> 
> Fix this by initializing producer_is_clang member variable of dwarf2_cu.
> Also remove the declared but undefined/unused method
>    struct partial_die_info *find_partial_die (sect_offset sect_off);
> 
> Tested on amd64/debian11 and re-running gdb.base/macro-source-path.exp
> under valgrind.
> 
> ==2140965== Conditional jump or move depends on uninitialised value(s)
> ==2140965==    at 0x5211F7: dwarf_decode_macro_bytes(dwarf2_per_objfile*, buildsym_compunit*, bfd*, unsigned char const*, unsigned char const*, macro_source_file*, line_header const*, dwarf2_section_info const*, int, int, unsigned int, dwarf2_section_info*, dwarf2_section_info*, gdb::optional<unsigned long>, htab*, dwarf2_cu*) (macro.c:676)
> ==2140965==    by 0x52158A: dwarf_decode_macros(dwarf2_per_objfile*, buildsym_compunit*, dwarf2_section_info const*, line_header const*, unsigned int, unsigned int, dwarf2_section_info*, dwarf2_section_info*, gdb::optional<unsigned long>, int, dwarf2_cu*) (macro.c:967)
> ==2140965==    by 0x523BC4: dwarf_decode_macros(dwarf2_cu*, unsigned int, int) (read.c:23379)
> ==2140965==    by 0x552AB5: read_file_scope(die_info*, dwarf2_cu*) (read.c:9687)
> ==2140965==    by 0x54F7B2: process_die(die_info*, dwarf2_cu*) (read.c:8660)
> ==2140965==    by 0x5569C7: process_full_comp_unit (read.c:8429)
> ==2140965==    by 0x5569C7: process_queue (read.c:7675)
> ==2140965==    by 0x5569C7: dw2_do_instantiate_symtab (read.c:2063)
> ==2140965==    by 0x5569C7: dw2_instantiate_symtab(dwarf2_per_cu_data*, dwarf2_per_objfile*, bool) (read.c:2085)
> ==2140965==    by 0x55700B: dw2_expand_symtabs_matching_one(dwarf2_per_cu_data*, dwarf2_per_objfile*, gdb::function_view<bool (char const*, bool)>, gdb::function_view<bool (compunit_symtab*)>) (read.c:3984)
> ==2140965==    by 0x557EA3: cooked_index_functions::expand_symtabs_matching(objfile*, gdb::function_view<bool (char const*, bool)>, lookup_name_info const*, gdb::function_view<bool (char const*)>, gdb::function_view<bool (compunit_symtab*)>, enum_flags<block_search_flag_values>, domain_enum, search_domain) (read.c:18781)
> ==2140965==    by 0x778977: objfile::lookup_symbol(block_enum, char const*, domain_enum) (symfile-debug.c:276)
> ....
> ==2140965==  Uninitialised value was created by a heap allocation
> ==2140965==    at 0x4839F01: operator new(unsigned long) (vg_replace_malloc.c:434)
> ==2140965==    by 0x533A64: cutu_reader::cutu_reader(dwarf2_per_cu_data*, dwarf2_per_objfile*, abbrev_table*, dwarf2_cu*, bool, abbrev_cache*) (read.c:6264)
> ==2140965==    by 0x5340C2: load_full_comp_unit(dwarf2_per_cu_data*, dwarf2_per_objfile*, dwarf2_cu*, bool, language) (read.c:7729)
> ==2140965==    by 0x548338: load_cu(dwarf2_per_cu_data*, dwarf2_per_objfile*, bool) (read.c:2021)
> ==2140965==    by 0x55634C: dw2_do_instantiate_symtab (read.c:2048)
> ==2140965==    by 0x55634C: dw2_instantiate_symtab(dwarf2_per_cu_data*, dwarf2_per_objfile*, bool) (read.c:2085)
> ==2140965==    by 0x55700B: dw2_expand_symtabs_matching_one(dwarf2_per_cu_data*, dwarf2_per_objfile*, gdb::function_view<bool (char const*, bool)>, gdb::function_view<bool (compunit_symtab*)>) (read.c:3984)
> ==2140965==    by 0x557EA3: cooked_index_functions::expand_symtabs_matching(objfile*, gdb::function_view<bool (char const*, bool)>, lookup_name_info const*, gdb::function_view<bool (char const*)>, gdb::function_view<bool (compunit_symtab*)>, enum_flags<block_search_flag_values>, domain_enum, search_domain) (read.c:18781)
> ==2140965==    by 0x778977: objfile::lookup_symbol(block_enum, char const*, domain_enum) (symfile-debug.c:276)
> ....
> ---
>  gdb/dwarf2/cu.c | 1 +
>  gdb/dwarf2/cu.h | 2 --
>  2 files changed, 1 insertion(+), 2 deletions(-)

Both changes are ok (you can add my Approved-By), but please push a
separate patch for each change.

Simon
  

Patch

diff --git a/gdb/dwarf2/cu.c b/gdb/dwarf2/cu.c
index e95208e2e75..af95725ebcf 100644
--- a/gdb/dwarf2/cu.c
+++ b/gdb/dwarf2/cu.c
@@ -39,6 +39,7 @@  dwarf2_cu::dwarf2_cu (dwarf2_per_cu_data *per_cu,
     producer_is_icc (false),
     producer_is_icc_lt_14 (false),
     producer_is_codewarrior (false),
+    producer_is_clang (false),
     processing_has_namespace_info (false),
     load_all_dies (false)
 {
diff --git a/gdb/dwarf2/cu.h b/gdb/dwarf2/cu.h
index 51638e71b19..52975095871 100644
--- a/gdb/dwarf2/cu.h
+++ b/gdb/dwarf2/cu.h
@@ -278,8 +278,6 @@  struct dwarf2_cu
      hash table and don't find it.  */
   bool load_all_dies : 1;
 
-  struct partial_die_info *find_partial_die (sect_offset sect_off);
-
   /* Get the buildsym_compunit for this CU.  */
   buildsym_compunit *get_builder ();
 };