Bug 25102 - internal-error: bool value_contents_bits_eq(const value*, int, const value*, int, int): Assertion `offset2 + length <= TYPE_LENGTH (val2->enclosing_type) * TARGET_CHAR_BIT' failed
Summary: internal-error: bool value_contents_bits_eq(const value*, int, const value*, ...
Status: UNCONFIRMED
Alias: None
Product: gdb
Classification: Unclassified
Component: gdb (show other bugs)
Version: 8.3.1
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-10-14 23:12 UTC by Martin
Modified: 2020-10-11 20:57 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Martin 2019-10-14 23:12:33 UTC
compile the below with fpc 3.0.4
command-line option  -gw3  
(for dwarf 3)

As soon as a is assigned 
try

-data-evaluate-expression A^

The ^ deref is needed, so the structure is printed, instead just the pointer

This prints b as structure: -data-evaluate-expression B^
This prints the address of the structure b: -data-evaluate-expression B


program Project1;
type
  t = class
    i: Integer;
    x: array of word;
  end;
  t2 = class
    i: Integer;
    x: word;
  end;
var
  a: t;
  b: t2;
begin
  a:= t.Create;
  b:= t2.Create;
  SetLength(a.x, 20);
end.
Comment 1 lemo1234 2020-07-09 17:55:32 UTC
I hit the same assert failure with GCC 9.2, debugging a C++ application built with GCC 8.4.0:

../../gdb/value.c:850: internal-error: bool value_contents_bits_eq(const value*, int, const value*, int, int): Assertion `offset2 + length <= TYPE_LENGTH (val2->enclosing_type) * TARGET_CHAR_BIT' failed.
A problem internal to GDB has been detected,
further debugging may prove unreliable.

Loading the GDB core dump:

#0  0x00007f1e7788bf47 in raise () from /lib/x86_64-linux-gnu/libc.so.6
#1  0x00007f1e7788d8b1 in abort () from /lib/x86_64-linux-gnu/libc.so.6
#2  0x000056162488ab96 in dump_core () at ../../gdb/utils.c:203
#3  0x000056162488fc5d in internal_vproblem(internal_problem *, const char *, int, const char *, typedef __va_list_tag __va_list_tag *) (
    problem=0x561624eadb20 <internal_error_problem>, file=<optimized out>, line=850, fmt=<optimized out>, ap=<optimized out>) at ../../gdb/utils.c:413
#4  0x000056162488fe0b in internal_verror (file=<optimized out>, line=<optimized out>, fmt=<optimized out>, ap=ap@entry=0x7fff867ceb50) at ../../gdb/utils.c:438
#5  0x00005616246c5d8f in internal_error (file=file@entry=0x561624a81df5 "../../gdb/value.c", line=line@entry=850, fmt=<optimized out>)
    at ../../gdb/gdbsupport/errors.c:55
#6  0x00005616248a0e0f in value_contents_bits_eq (length=128, offset2=2176, val2=0x561661b32560, offset1=1408, val1=0x561661b32560) at ../../gdb/value.c:787
#7  value_contents_eq (val1=val1@entry=0x561661b32560, offset1=offset1@entry=176, val2=val2@entry=0x561661b32560, offset2=offset2@entry=272, length=length@entry=16)
    at ../../gdb/value.c:901
#8  0x000056162489d6ab in val_print_array_elements (type=<optimized out>, embedded_offset=embedded_offset@entry=176, address=address@entry=140737488341504, 
    stream=stream@entry=0x7fff867cfbd0, recurse=recurse@entry=3, val=val@entry=0x561661b32560, options=0x7fff867cef50, i=<optimized out>) at ../../gdb/valprint.c:2059
#9  0x00005616245eee9b in c_val_print_array (options=0x7fff867cef50, original_value=0x561661b32560, recurse=3, stream=0x7fff867cfbd0, address=140737488341504, 
    embedded_offset=176, valaddr=<optimized out>, type=<optimized out>) at ../../gdb/c-valprint.c:328
#10 c_val_print (type=<optimized out>, embedded_offset=176, address=140737488341504, stream=0x7fff867cfbd0, recurse=3, original_value=0x561661b32560, 
    options=0x7fff867cef50) at ../../gdb/c-valprint.c:510
#11 0x000056162489c1f4 in val_print (type=type@entry=0x5616634a47b0, embedded_offset=176, address=address@entry=140737488341504, stream=stream@entry=0x7fff867cfbd0, 
    recurse=recurse@entry=3, val=val@entry=0x561661b32560, options=<optimized out>, language=0x561624e8ae60 <cplus_language_defn>) at ../../gdb/valprint.c:1083
#12 0x0000561624631408 in cp_print_value_fields (type=0x5616634a2900, real_type=<optimized out>, offset=112, address=140737488341504, stream=0x7fff867cfbd0, recurse=2, 
    val=<optimized out>, options=<optimized out>, dont_print_vb=<optimized out>, dont_print_statmem=<optimized out>) at ../../gdb/cp-valprint.c:336
#13 0x00005616246318a1 in cp_print_value (dont_print_vb=<optimized out>, options=0x7fff867cf7e0, val=<optimized out>, recurse=<optimized out>, stream=0x7fff867cfbd0, 
    address=<optimized out>, offset=<optimized out>, real_type=<optimized out>, type=0x56166167f830) at ../../gdb/cp-valprint.c:576
#14 cp_print_value_fields (type=0x56166167f830, real_type=0x56166654c4f0, offset=112, address=140737488341504, stream=0x7fff867cfbd0, recurse=1, val=<optimized out>, 
    options=<optimized out>, dont_print_vb=0x56162562cff0, dont_print_statmem=<optimized out>) at ../../gdb/cp-valprint.c:165
#15 0x00005616246318a1 in cp_print_value (dont_print_vb=<optimized out>, options=0x7fff867cf7e0, val=<optimized out>, recurse=<optimized out>, stream=0x7fff867cfbd0, 
    address=<optimized out>, offset=<optimized out>, real_type=<optimized out>, type=0x56166337c7d0) at ../../gdb/cp-valprint.c:576
#16 cp_print_value_fields (type=0x56166337c7d0, real_type=0x56166654c4f0, offset=0, address=140737488341504, stream=0x7fff867cfbd0, recurse=0, val=<optimized out>, 
    options=<optimized out>, dont_print_vb=0x0, dont_print_statmem=<optimized out>) at ../../gdb/cp-valprint.c:165
#17 0x00005616246323b5 in cp_print_value_fields_rtti (type=<optimized out>, type@entry=0x56166337c7d0, valaddr=valaddr@entry=0x561625719230 "PN\374\367\377\177", 
    offset=offset@entry=0, address=address@entry=140737488341504, stream=stream@entry=0x7fff867cfbd0, recurse=<optimized out>, val=0x561661b32560, 
    options=0x7fff867cf7e0, dont_print_vb=0x0, dont_print_statmem=0) at ../../gdb/cp-valprint.c:429
#18 0x00005616245ee513 in c_val_print_struct (type=0x56166337c7d0, valaddr=0x561625719230 "PN\374\367\377\177", embedded_offset=0, address=140737488341504, 
    stream=0x7fff867cfbd0, recurse=<optimized out>, original_value=0x561661b32560, options=0x7fff867cf7e0) at ../../gdb/c-valprint.c:408
#19 0x00005616245eea3c in c_val_print (type=<optimized out>, embedded_offset=0, address=140737488341504, stream=0x7fff867cfbd0, recurse=0, 
    original_value=0x561661b32560, options=0x7fff867cf7e0) at ../../gdb/c-valprint.c:529
#20 0x000056162489c1f4 in val_print (type=0x56165dcc9de0, embedded_offset=0, address=140737488341504, stream=0x7fff867cfbd0, recurse=0, val=0x561661b32560, 
    options=<optimized out>, language=0x561624e8ae60 <cplus_language_defn>) at ../../gdb/valprint.c:1083
#21 0x000056162489c38a in common_val_print (language=0x561624e8ae60 <cplus_language_defn>, options=0x7fff867cfab0, recurse=0, stream=0x7fff867cfbd0, val=0x561661b32560)
    at ../../gdb/valprint.c:1191
#22 common_val_print (val=<optimized out>, stream=0x7fff867cfbd0, recurse=0, options=0x7fff867cfab0, language=0x561624e8ae60 <cplus_language_defn>)
    at ../../gdb/valprint.c:1174
#23 0x000056162489e10b in generic_val_print_ref (options=0x7fff867cfab0, original_value=0x7fff867cfbd0, recurse=0, stream=0x7fff867cfbd0, embedded_offset=-2038629712, 
    type=0x56165dcc9f20) at ../../gdb/valprint.c:599
#24 generic_val_print (type=0x56165dcc9f20, embedded_offset=embedded_offset@entry=0, address=address@entry=140737488341216, stream=stream@entry=0x7fff867cfbd0, 
    recurse=recurse@entry=0, original_value=original_value@entry=0x56165fe49fe0, options=0x7fff867cfab0, decorations=0x561624dc5020 <c_decorations>)
    at ../../gdb/valprint.c:929
#25 0x00005616245eec59 in c_val_print (type=<optimized out>, embedded_offset=0, address=140737488341216, stream=0x7fff867cfbd0, recurse=0, 
    original_value=0x56165fe49fe0, options=0x7fff867cfab0) at ../../gdb/c-valprint.c:559
#26 0x000056162489c1f4 in val_print (type=0x56165dcc9f20, embedded_offset=0, address=140737488341216, stream=0x7fff867cfbd0, recurse=0, val=0x56165fe49fe0, 
    options=<optimized out>, language=0x561624e8ae60 <cplus_language_defn>) at ../../gdb/valprint.c:1083
#27 0x000056162489c38a in common_val_print (language=0x561624e8ae60 <cplus_language_defn>, options=0x7fff867cfba0, recurse=0, stream=0x7fff867cfbd0, val=0x56165fe49fe0)
    at ../../gdb/valprint.c:1191
#28 common_val_print (val=<optimized out>, stream=stream@entry=0x7fff867cfbd0, recurse=recurse@entry=0, options=options@entry=0x7fff867cfba0, 


(gdb) frame 6
#6  0x00005616248a0e0f in value_contents_bits_eq (length=128, offset2=2176, val2=0x561661b32560, offset1=1408, val1=0x561661b32560) at ../../gdb/value.c:787


(gdb) info args
length = 128
offset2 = 2176
val2 = 0x561661b32560
offset1 = 1408
val1 = 0x561661b32560


(gdb) p val2->enclosing_type->length
$3 = 272
Comment 2 lemo1234 2020-10-11 20:57:37 UTC
This issue was blocking me, so I put together a quick fix for it:
https://github.com/tlemo/gdb/commit/e7836ff2801e306dfa940ca6a5c0761c1b617a0b

I'm not familiar with the GDB's internals so this is a basic patch that made sense to me from a quick inspection of the source tree. For what is worth, I've been using GDB 9.2 + this patch for a few months now and I haven't noticed any problems.