With current trunk (at commit e37c930f9e "gcc-4.4.7 warning fixes"), I see these probably related internal errors: ... FAIL: gdb.ada/variant.exp: scenario=minimal: fetch type for python (GDB internal error) FAIL: gdb.ada/variant.exp: scenario=minimal: python print(t.dynamic) FAIL: gdb.ada/variant.exp: scenario=minimal: python print(t['onevalue'].bitpos) FAIL: gdb.dwarf2/variant.exp: print as Simple (GDB internal error) FAIL: gdb.dwarf2/variant.exp: print as Defaulted (GDB internal error) FAIL: gdb.dwarf2/variant.exp: print as Univariant (GDB internal error) FAIL: gdb.dwarf2/variant.exp: print as Negative (GDB internal error) ... Looking at gdb.dwarf2/variant.exp: ... (gdb) PASS: gdb.dwarf2/variant.exp: set language rust print *($1 as *mut Simple)^M /home/vries/gdb_versions/devel/src/gdb/dwarf2/attribute.h:90: internal-error: ULONGEST attribute::as_unsigned() const: Assertion `form_is_unsigned ()' failed.^M A problem internal to GDB has been detected,^M further debugging may prove unreliable.^M ...
Reproduce: ... gdb \ -batch \ ./outputs/gdb.dwarf2/variant/variant \ -ex "break func" \ -ex run \ -ex "print (void *) buffer" \ -ex "set language rust" \ -ex "print *(\$1 as *mut Simple)" ... Backtrace: ... (gdb) bt #0 __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:51 #1 0x00007ffff4b96b01 in __GI_abort () at abort.c:79 #2 0x00000000007fe516 in dump_core () at /home/vries/gdb_versions/devel/src/gdb/utils.c:204 #3 0x0000000000803133 in internal_vproblem(internal_problem *, const char *, int, const char *, typedef __va_list_tag __va_list_tag *) ( problem=problem@entry=0x10846c0 <internal_error_problem>, file=<optimized out>, line=90, fmt=<optimized out>, ap=ap@entry=0x7fffffffc3b8) at /home/vries/gdb_versions/devel/src/gdb/utils.c:414 #4 0x00000000008032b9 in internal_verror (file=<optimized out>, line=<optimized out>, fmt=<optimized out>, ap=ap@entry=0x7fffffffc3b8) at /home/vries/gdb_versions/devel/src/gdb/utils.c:439 #5 0x00000000009b8412 in internal_error ( file=file@entry=0xa4bd98 "/home/vries/gdb_versions/devel/src/gdb/dwarf2/attribute.h", line=line@entry=90, fmt=<optimized out>) at /home/vries/gdb_versions/devel/src/gdbsupport/errors.cc:55 #6 0x000000000056e1d8 in attribute::as_unsigned (this=0x2220a88) at /home/vries/gdb_versions/devel/src/gdb/dwarf2/attribute.h:90 #7 handle_variant (cu=0x1d6eee0, template_args=0x7fffffffc6f0, fi=0x7fffffffc810, type=0x21ba210, die=0x2220a60) at /home/vries/gdb_versions/devel/src/gdb/dwarf2/read.c:16190 #8 handle_struct_member_die (child_die=child_die@entry=0x2220a60, type=type@entry=0x21ba210, fi=fi@entry=0x7fffffffc810, template_args=template_args@entry=0x7fffffffc6f0, cu=cu@entry=0x1d6eee0) at /home/vries/gdb_versions/devel/src/gdb/dwarf2/read.c:16250 #9 0x000000000056de56 in handle_variant_part (cu=0x1d6eee0, template_args=0x7fffffffc6f0, fi=0x7fffffffc810, type=0x21ba210, die=0x1ff6ad0) at /home/vries/gdb_versions/devel/src/gdb/dwarf2/read.c:16141 #10 handle_struct_member_die (child_die=child_die@entry=0x22209c0, type=0x21ba210, fi=fi@entry=0x7fffffffc810, template_args=template_args@entry=0x7fffffffc6f0, cu=cu@entry=0x1d6eee0) at /home/vries/gdb_versions/devel/src/gdb/dwarf2/read.c:16248 #11 0x000000000056f0a1 in process_structure_scope (cu=0x1d6eee0, die=0x2220970) at /home/vries/gdb_versions/devel/src/gdb/dwarf2/read.c:16277 #12 process_die (die=die@entry=0x2220970, cu=cu@entry=0x1d6eee0) at /home/vries/gdb_versions/devel/src/gdb/dwarf2/read.c:10183 #13 0x000000000056f62f in read_file_scope (cu=0x1d6eee0, die=0x221fe00) at /home/vries/gdb_versions/devel/src/gdb/dwarf2/read.c:11138 #14 process_die (die=0x221fe00, cu=cu@entry=0x1d6eee0) at /home/vries/gdb_versions/devel/src/gdb/dwarf2/read.c:10155 #15 0x0000000000571aa5 in process_full_comp_unit (pretend_language=<optimized out>, cu=0x1d6eee0) at /home/vries/gdb_versions/devel/src/gdb/dwarf2/read.c:9925 #16 process_queue (per_objfile=0x1a786f0) at /home/vries/gdb_versions/devel/src/gdb/dwarf2/read.c:9154 #17 dw2_do_instantiate_symtab (per_cu=<optimized out>, per_objfile=per_objfile@entry=0x1a786f0, skip_partial=skip_partial@entry=false) at /home/vries/gdb_versions/devel/src/gdb/dwarf2/read.c:2433 #18 0x00000000005732af in dwarf2_psymtab::expand_psymtab (this=0x1d72a00, objfile=0x1a8f9b0) at /home/vries/gdb_versions/devel/src/gdb/dwarf2/read.c:9183 #19 0x0000000000554549 in dwarf2_psymtab::read_symtab (this=0x1d72a00, objfile=0x1a8f9b0) at /home/vries/gdb_versions/devel/src/gdb/dwarf2/read.c:9031 #20 0x00000000006af3e1 in psymtab_to_symtab (objfile=objfile@entry=0x1a8f9b0, pst=pst@entry=0x1d72a00) at /home/vries/gdb_versions/devel/src/gdb/psymtab.c:756 #21 0x00000000006b1dba in psym_lookup_symbol (objfile=0x1a8f9b0, block_index=STATIC_BLOCK, name=0x217a9d0 "Simple", domain=STRUCT_DOMAIN) at /home/vries/gdb_versions/devel/src/gdb/psymtab.c:483 #22 0x0000000000793e4c in lookup_symbol_via_quick_fns (domain=STRUCT_DOMAIN, name=0x217a9d0 "Simple", block_index=STATIC_BLOCK, objfile=0x1a8f9b0) at /home/vries/gdb_versions/devel/src/gdb/symtab.c:2373 #23 lookup_symbol_in_objfile (objfile=0x1a8f9b0, block_index=STATIC_BLOCK, name=0x217a9d0 "Simple", domain=STRUCT_DOMAIN) at /home/vries/gdb_versions/devel/src/gdb/symtab.c:2521 #24 0x0000000000794060 in lookup_symbol_global_or_static_iterator_cb ( objfile=<optimized out>, cb_data=0x7fffffffd0a0) at /home/vries/gdb_versions/devel/src/gdb/symtab.c:2595 #25 0x000000000076006c in svr4_iterate_over_objfiles_in_search_order ( gdbarch=<optimized out>, cb=0x794040 <lookup_symbol_global_or_static_iterator_cb(objfile*, void*)>, cb_data=0x7fffffffd0a0, current_objfile=0x0) at /home/vries/gdb_versions/devel/src/gdb/solib-svr4.c:3248 #26 0x000000000078e72e in lookup_global_or_static_symbol ( name=name@entry=0x217a9d0 "Simple", block_index=block_index@entry=STATIC_BLOCK, objfile=objfile@entry=0x0, domain=domain@entry=STRUCT_DOMAIN) at /home/vries/gdb_versions/devel/src/gdb/symtab.c:2641 #27 0x0000000000793649 in lookup_static_symbol (domain=STRUCT_DOMAIN, name=0x217a9d0 "Simple") at /home/vries/gdb_versions/devel/src/gdb/symtab.c:2659 #28 lookup_symbol_aux (name=0x217a9d0 "Simple", match_type=match_type@entry=symbol_name_match_type::FULL, block=block@entry=0x1d9c1b0, domain=domain@entry=STRUCT_DOMAIN, language=language@entry=language_rust, is_a_field_of_this=is_a_field_of_this@entry=0x0) at /home/vries/gdb_versions/devel/src/gdb/symtab.c:2103 #29 0x0000000000793703 in lookup_symbol_in_language (name=<optimized out>, block=0x1d9c1b0, domain=domain@entry=STRUCT_DOMAIN, lang=language_rust, is_a_field_of_this=is_a_field_of_this@entry=0x0) at /home/vries/gdb_versions/devel/src/gdb/symtab.c:1884 #30 0x0000000000793762 in lookup_symbol (name=<optimized out>, block=<optimized out>, domain=domain@entry=STRUCT_DOMAIN, is_a_field_of_this=is_a_field_of_this@entry=0x0) at /home/vries/gdb_versions/devel/src/gdb/symtab.c:1896 #31 0x0000000000736914 in rust_parser::rust_lookup_type (this=this@entry=0x7fffffffd470, name=<optimized out>, name@entry=0x217a9d0 "Simple", block=<optimized out>) at /home/vries/gdb_versions/devel/src/gdb/rust-exp.y:2020 #32 0x000000000073a8e6 in rust_parser::convert_ast_to_type (this=0x7fffffffd470, operation=<optimized out>) at /home/vries/gdb_versions/devel/src/gdb/rust-exp.y:2063 #33 0x000000000073a981 in rust_parser::convert_ast_to_type (this=0x7fffffffd470, operation=0x217aa20) at /home/vries/gdb_versions/devel/src/gdb/rust-exp.y:2093 #34 0x000000000073b241 in rust_parser::convert_ast_to_expression (this=0x7fffffffd470, operation=0x217aa60, top=0x217aaa0, want_type=want_type@entry=false) at /home/vries/gdb_versions/devel/src/gdb/rust-exp.y:2313 #35 0x000000000073b29b in rust_parser::convert_ast_to_expression ( this=this@entry=0x7fffffffd470, operation=0x217aaa0, top=0x217aaa0, want_type=want_type@entry=false) at /home/vries/gdb_versions/devel/src/gdb/rust-exp.y:2256 #36 0x000000000073b831 in rust_parse (state=0x7fffffffd590) at /home/vries/gdb_versions/devel/src/gdb/rust-exp.y:2549 #37 0x0000000000681cb7 in parse_exp_in_context (stringptr=stringptr@entry=0x7fffffffd668, pc=pc@entry=0, block=block@entry=0x0, comma=comma@entry=0, out_subexp=out_subexp@entry=0x0, tracker=0x7fffffffd580, cstate=0x0, void_context_p=0, this=<optimized out>) at /home/vries/gdb_versions/devel/src/gdb/parse.c:1121 #38 0x0000000000682035 in parse_exp_1 (tracker=0x0, comma=0, block=0x0, pc=0, stringptr=0x7fffffffd668) at /home/vries/gdb_versions/devel/src/gdb/parse.c:1030 #39 parse_expression (string=<optimized out>, tracker=tracker@entry=0x0) at /home/vries/gdb_versions/devel/src/gdb/parse.c:1165 #40 0x00000000006a5334 in print_command_1 (args=<optimized out>, voidprint=1) at /home/vries/gdb_versions/devel/src/gdb/printcmd.c:1223 #41 0x00000000004d4f22 in cmd_func (cmd=<optimized out>, args=<optimized out>, from_tty=<optimized out>) at /home/vries/gdb_versions/devel/src/gdb/cli/cli-decode.c:2181 #42 0x00000000007c1970 in execute_command (p=<optimized out>, p@entry=<error reading variable: value has been optimized out>, from_tty=0, from_tty@entry=<error reading variable: value has been optimized out>) at /home/vries/gdb_versions/devel/src/gdb/top.c:664 #43 0x000000000063d07e in catch_command_errors (command=<optimized out>, arg=<optimized out>, from_tty=<optimized out>) at /home/vries/gdb_versions/devel/src/gdb/main.c:457 #44 0x000000000063ed07 in captured_main_1 (context=context@entry=0x7fffffffda60) at /home/vries/gdb_versions/devel/src/gdb/main.c:1218 #45 0x000000000063f2bb in captured_main (data=data@entry=0x7fffffffda60) at /home/vries/gdb_versions/devel/src/gdb/main.c:1243 #46 gdb_main (args=args@entry=0x7fffffffda80) at /home/vries/gdb_versions/devel/src/gdb/main.c:1268 #47 0x000000000041b745 in main (argc=<optimized out>, argv=<optimized out>) at /home/vries/gdb_versions/devel/src/gdb/gdb.c:32 ...
Triggered here: ... #6 0x000000000056e1d8 in attribute::as_unsigned (this=0x225c818) at /home/vries/gdb_versions/devel/src/gdb/dwarf2/attribute.h:90 90 gdb_assert (form_is_unsigned ()); ... because form_is_unsigned is false, given that form == DW_FORM_sdata: ... (gdb) p *this $5 = {name = DW_AT_discr_value, requires_reprocessing = 0, form = DW_FORM_sdata, string_is_canonical = 0, u = { str = 0xffffffffffffffff <error: Cannot access memory at address 0xffffffffffffffff>, blk = 0xffffffffffffffff, unsnd = 18446744073709551615, snd = -1, addr = 18446744073709551615, signature = 18446744073709551615}} ... It's called from: ... (gdb) #7 handle_variant (cu=0x1d6eee0, template_args=0x7fffffffc6f0, fi=0x7fffffffc810, type=0x218ab80, die=0x217bc50) at /home/vries/gdb_versions/devel/src/gdb/dwarf2/read.c:16190 16190 variant.discriminant_value = discr->as_unsigned (); ... which I guess triggers on this bit from the test-case: ... variant { {discr_value -1 sdata} } { ...
Tentative patch: ... diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index bcac94ed36..ba98fe6ff6 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -16187,7 +16187,17 @@ handle_variant (struct die_info *die, struct type *type, variant.discr_list_data = discr->as_block (); } else - variant.discriminant_value = discr->as_unsigned (); + if (discr->form_is_unsigned ()) + variant.discriminant_value = discr->as_unsigned (); + else + { + union { + ULONGEST u; + LONGEST i; + } val; + val.i = discr->as_signed ();; + variant.discriminant_value = val.u; + } for (die_info *variant_child = die->child; variant_child != NULL; ...
(In reply to Tom de Vries from comment #3) > Tentative patch: Fixes all mentioned internal-errors.
How about something like this: ... diff --git a/gdb/dwarf2/attribute.h b/gdb/dwarf2/attribute.h index aded129764..1c431f1791 100644 --- a/gdb/dwarf2/attribute.h +++ b/gdb/dwarf2/attribute.h @@ -92,6 +92,13 @@ struct attribute return u.unsnd; } + /* Return the unsigned value. Requires that reprocessing not be needed. */ + ULONGEST as_unsigned_relaxed () const + { + gdb_assert (!requires_reprocessing); + return u.unsnd; + } + /* Return non-zero if ATTR's value is a section offset --- classes lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise. You may use the as_unsigned method to retrieve such offsets. diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index bcac94ed36..b287441101 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -16187,7 +16187,7 @@ handle_variant (struct die_info *die, struct type *type, variant.discr_list_data = discr->as_block (); } else - variant.discriminant_value = discr->as_unsigned (); + variant.discriminant_value = discr->as_unsigned_relaxed (); for (die_info *variant_child = die->child; variant_child != NULL; ...
Sorry about this. I fixed it before I was aware of this bug: https://sourceware.org/pipermail/gdb-patches/2020-September/172207.html I did it using the existing constant_value method.