Bug 29294 - [REG 11.2->12.1] Internal error when stepping into a function
Summary: [REG 11.2->12.1] Internal error when stepping into a function
Status: RESOLVED FIXED
Alias: None
Product: gdb
Classification: Unclassified
Component: exp (show other bugs)
Version: 12.1
: P2 critical
Target Milestone: 13.1
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2022-06-27 20:03 UTC by Orgad Shaneh
Modified: 2022-07-05 20:43 UTC (History)
3 users (show)

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


Attachments
Tentative patch (1.40 KB, patch)
2022-06-30 13:44 UTC, Tom de Vries
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Orgad Shaneh 2022-06-27 20:03:37 UTC
GDB version 12.1 with all targets enabled on mingw32. The inferior is mingw32 executable.

When I step into a particular function, gdb crashes with the following message:
"../../gdb-12.1/gdb/gdbtypes.h:690: internal-error: loc_bitpos: Assertion `m_loc_kind == FIELD_LOC_KIND_BITPOS' failed"

The same scenario works fine with GDB 11.2.

I couldn't find a small reproducible program, still trying and will update.
Comment 1 Tom Tromey 2022-06-28 17:31:14 UTC
Can you get a stack trace of gdb?  That might help.
Also can you try git master?
Comment 2 Orgad Shaneh 2022-06-28 17:42:45 UTC
This is the trace without debugging symbols:

msvcrt!abort
dump_core()
internal_vproblem(internal_problem *, const char *, int, const char *, char *)
internal_verror(const char *, int, const char *, char *)
internal_error(const char *, int, const char *, ...)
cp_print_class_member(unsigned const char *, type *, ui_file *, const char *)
c_value_print_inner(value *, ui_file *, int, value_print_options const *)
common_val_print(value *, ui_file *, int, value_print_options const *, language_defn const *)
print_frame_arg(frame_print_options const&, frame_arg const *)
print_frame_args(frame_print_options const&, symbol *, frame_info *, int, ui_file *)
print_frame_info(frame_print_options const&, frame_info *, int, print_what, int, int)
print_stack_frame(frame_info *, int, print_what, int)
print_stop_event(ui_out *, bool)
mi_on_normal_stop(bpstat *, int)
normal_stop()
fetch_inferior_event()
check_async_event_handlers()
gdb_do_one_event()
captured_command_loop()
gdb_main(captured_main_args *)

I'm building now from master, will hopefully have more data.
Comment 3 Orgad Shaneh 2022-06-28 19:22:48 UTC
Reproduces in master, this time I have debugging symbols.

#0  0x00007ffdb415f1e7 in msvcrt!abort () from C:\\WINDOWS\\System32\\msvcrt.dll
#1  0x00007ff6c02fd3c5 in dump_core () at ../../gdb/utils.c:202
#2  0x00007ff6c030afbd in internal_vproblem (problem=problem@entry=0x7ff6c05d1020 <internal_error_problem>, file=<optimized out>, line=<optimized out>, fmt=<optimized out>, ap=0xd8ba9fe5c8 \"\\033\\332b\\300\\366\366\\177\") at ../../gdb/utils.c:450
#3  0x00007ff6c030b1fe in internal_verror (file=<optimized out>, line=<optimized out>, fmt=<optimized out>, ap=<optimized out>) at ../../gdb/utils.c:476
#4  0x00007ff6c0428dd8 in internal_error (file=0xffffffff <error: Cannot access memory at address 0xffffffff>, file@entry=0x7ff6c062da26 <yytranslate+5158> \"../../gdb/gdbtypes.h\", line=1913836239, line@entry=695, fmt=0x1dd89e58040 \"\260\\r\345\211\\335\\001\") at ../../gdbsupport/errors.cc:55
#5  0x00007ff6c006a2de in field::loc_bitpos (this=<optimized out>) at ../../gdb/gdbtypes.h:695
#6  field::loc_bitpos (this=<optimized out>) at ../../gdb/gdbtypes.h:693
#7  cp_find_class_member (offset=800, fieldno=<optimized out>, self_p=<optimized out>) at ../../gdb/cp-valprint.c:651

#8  cp_print_class_member (valaddr=<optimized out>, type=<optimized out>, stream=0xd8ba9fe8c0, prefix=0x7ff6c06dd341 <internal_problem_ask+12730> \"&\") at ../../gdb/cp-valprint.c:698
#9  0x00007ff6c0017c1d in c_value_print_inner (val=0x1ddd89bde40, stream=0xd8ba9fe8c0, recurse=2, options=0xd8ba9fe7d0) at ../../gdb/c-valprint.c:464
#10 0x00007ff6c0319c4f in common_val_print (value=0x1ddd89bde40, stream=stream@entry=0xd8ba9fe8c0, recurse=recurse@entry=2, options=options@entry=0xd8ba9fe890, language=0x7ff6c09b4140 <cplus_language_defn>) at ../../gdb/valprint.c:1073
#11 0x00007ff6c0319de8 in common_val_print_checked (val=<optimized out>, stream=stream@entry=0xd8ba9fe8c0, recurse=recurse@entry=2, options=options@entry=0xd8ba9fe890, language=<optimized out>, language@entry=0x7ff6c09b4140 <cplus_language_defn>) at ../../gdb/valprint.c:1165
#12 0x00007ff6c026385a in print_frame_arg (fp_opts=..., arg=arg@entry=0xd8ba9fe9c0) at ../../gdb/stack.c:487
#13 0x00007ff6c026476f in print_frame_args (fp_opts=..., func=<optimized out>, frame=frame@entry=0x1dde079b150, num=num@entry=-1, stream=0x1dd8b729aa0) at ../../gdb/stack.c:891
#14 0x00007ff6c0266349 in print_frame (sal=..., print_args=1, print_what=LOC_AND_ADDRESS, print_level=<optimized out>, frame=0x1dde079b150, fp_opts=...) at ../../gdb/stack.c:1391
#15 print_frame_info (fp_opts=..., frame=0x1dde079b150, print_level=<optimized out>, print_what=LOC_AND_ADDRESS, print_args=1, set_current_sal=1) at ../../gdb/stack.c:1117
#16 0x00007ff6c026689d in print_stack_frame (frame=0x1dde079b150, print_level=0, print_what=<optimized out>, set_current_sal=1) at ../../gdb/stack.c:367
#17 0x00007ff6c01488ca in print_stop_location (ws=...) at ../../gdb/infrun.c:8497

#18 print_stop_event (uiout=0x1dd8b7272f0, displays=<optimized out>) at ../../gdb/infrun.c:8513
#19 0x00007ff6c0191fe3 in mi_on_normal_stop_1 (bs=<optimized out>, print_frame=1) at ../../gdb/mi/mi-interp.c:657
#20 mi_on_normal_stop (bs=<optimized out>, print_frame=1) at ../../gdb/mi/mi-interp.c:693
#21 0x00007ff6c056e5e2 in std::function<void (bpstat*, int)>::operator()(bpstat*, int) const (__args#1=<optimized out>, __args#0=<optimized out>, this=0x1dd8bd23f18) at C:/msys64/mingw64/include/c++/12.1.0/bits/std_function.h:591
#22 gdb::observers::observable<bpstat*, int>::notify (this=0x7ff6c09c3fe0 <gdb::observers::normal_stop>, args#0=0x1dd90a7d880, args#1=args#1@entry=1) at ../../gdb/../gdbsupport/observable.h:166
#23 0x00007ff6c0149a23 in normal_stop () at ../../gdb/infrun.c:8775
#24 0x00007ff6c0156ca7 in fetch_inferior_event () at ../../gdb/infrun.c:4253
#25 0x00007ff6bffcc5bb in check_async_event_handlers () at ../../gdb/async-event.c:335
#26 0x00007ff6c042915c in gdb_do_one_event () at ../../gdbsupport/event-loop.cc:214
#27 0x00007ff6c0178dc5 in start_event_loop () at ../../gdb/main.c:411
#28 captured_command_loop () at ../../gdb/main.c:471
#29 0x00007ff6c017b095 in captured_main (data=0xd8ba9ff6c0) at ../../gdb/main.c:1329
#30 gdb_main (args=args@entry=0xd8ba9ff720) at ../../gdb/main.c:1344
#31 0x00007ff6c05af587 in main (argc=3, argv=0x1dd89e91ee0) at ../../gdb/gdb.c:32
Comment 4 Orgad Shaneh 2022-06-28 19:54:45 UTC
In field::loc_bitpos, m_loc_kind is FIELD_LOC_KIND_PHYSNAME (3). m_name is m_MsgIdx.

The field is a static field in a class. Its type is a typedef of std::atomic<unsigned int> derivative.

Something like this (notice it *doesn't reproduce* with this example):

#include <atomic>

template<typename T>
struct ac_atomic:public std::atomic<T>
{
    ac_atomic(T value = 0) : std::atomic<T>(value) {}
    using std::atomic<T>::operator=;
};

typedef ac_atomic<unsigned int> ac_atomic_uint;

class Foo
{
public:
    static ac_atomic_uint m_MsgIdx;
    const char *Bar;
};

enum class E { V1, V2 };

static void CheckField(const char* Foo::*StrField, E Enum)
{
}

int main() {
    CheckField(&Foo::Bar, E::V1); // Break here and execute "step"
}
Comment 5 Orgad Shaneh 2022-06-30 08:53:30 UTC
I finally found a minimal reproducible example:

struct Base { const char *Bar; };
struct Foo : public Base
{
  static const int m_MsgIdx = 0;
};

static void Func(const char* Foo::*Field) {}

int main() {
  Func(&Foo::Bar); // Break here and step
}

I'll try to bisect.
Comment 6 Orgad Shaneh 2022-06-30 09:14:43 UTC
Aaaaand we have a winner!

84a6adfd4c ([gdb] Make execute_command_to_string return string on throw)
Comment 7 Tom de Vries 2022-06-30 12:35:13 UTC
Reproduced:
...
$ cat test.cc
struct Base { const char *Bar; };

struct Foo : public Base
{
  static const int m_MsgIdx = 0;
};

static void
Func (const char* Foo::*Field)
{
}

int
main ()
{
  Func (&Foo::Bar);
}
$ g++ -g test.cc
$ gdb -q -batch a.out -ex start -ex step
Temporary breakpoint 1 at 0x4004d6: file test.cc, line 16.

Temporary breakpoint 1, main () at test.cc:16
16        Func (&Foo::Bar);
Func (Field=/home/vries/gdb_versions/devel/src/gdb/gdbtypes.h:695: internal-error: loc_bitpos: Assertion `m_loc_kind == FIELD_LOC_KIND_BITPOS' failed.
A problem internal to GDB has been detected,
further debugging may prove unreliable.
----- Backtrace -----
0x57e9cc gdb_internal_backtrace_1
        /home/vries/gdb_versions/devel/src/gdb/bt-utils.c:122
0x57ea6f _Z22gdb_internal_backtracev
        /home/vries/gdb_versions/devel/src/gdb/bt-utils.c:168
0xc69b17 internal_vproblem
        /home/vries/gdb_versions/devel/src/gdb/utils.c:396
0xc69ee6 _Z15internal_verrorPKciS0_P13__va_list_tag
        /home/vries/gdb_versions/devel/src/gdb/utils.c:476
0x139be70 _Z14internal_errorPKciS0_z
        /home/vries/gdb_versions/devel/src/gdbsupport/errors.cc:55
0x47246c _ZNK5field10loc_bitposEv
        /home/vries/gdb_versions/devel/src/gdb/gdbtypes.h:695
0x64c8fd cp_find_class_member
        /home/vries/gdb_versions/devel/src/gdb/cp-valprint.c:639
0x64cac2 _Z21cp_print_class_memberPKhP4typeP7ui_filePKc
        /home/vries/gdb_versions/devel/src/gdb/cp-valprint.c:698
0xc90705 generic_value_print_memberptr
        /home/vries/gdb_versions/devel/src/gdb/valprint.c:879
0xc9082d _Z19generic_value_printP5valueP7ui_fileiPK19value_print_optionsPK29generic_val_print_decorations
        /home/vries/gdb_versions/devel/src/gdb/valprint.c:914
0x5c2d7c _Z19c_value_print_innerP5valueP7ui_fileiPK19value_print_options
        /home/vries/gdb_versions/devel/src/gdb/c-valprint.c:464
0x8589b1 _ZNK13language_defn17value_print_innerEP5valueP7ui_fileiPK19value_print_options
        /home/vries/gdb_versions/devel/src/gdb/language.c:633
0xc90e0d _Z16common_val_printP5valueP7ui_fileiPK19value_print_optionsPK13language_defn
        /home/vries/gdb_versions/devel/src/gdb/valprint.c:1073
0xc911e3 _Z24common_val_print_checkedP5valueP7ui_fileiPK19value_print_optionsPK13language_defn
        /home/vries/gdb_versions/devel/src/gdb/valprint.c:1165
0xb4cb02 print_frame_arg
        /home/vries/gdb_versions/devel/src/gdb/stack.c:487
0xb4d9b3 print_frame_args
        /home/vries/gdb_versions/devel/src/gdb/stack.c:891
0xb4ebed print_frame
        /home/vries/gdb_versions/devel/src/gdb/stack.c:1391
0xb4e2a8 _Z16print_frame_infoRK19frame_print_optionsP10frame_infoi10print_whatii
        /home/vries/gdb_versions/devel/src/gdb/stack.c:1117
0xb4c61d _Z17print_stack_frameP10frame_infoi10print_whati
        /home/vries/gdb_versions/devel/src/gdb/stack.c:367
0x83e72a print_stop_location
        /home/vries/gdb_versions/devel/src/gdb/infrun.c:8497
0x83e7af _Z16print_stop_eventP6ui_outb
        /home/vries/gdb_versions/devel/src/gdb/infrun.c:8513
0x5de30e cli_base_on_normal_stop
        /home/vries/gdb_versions/devel/src/gdb/cli/cli-interp.c:144
0x48b856 _ZNSt17_Function_handlerIFvP6bpstatiEPS2_E9_M_invokeERKSt9_Any_dataOS1_Oi
        /usr/include/c++/7/bits/std_function.h:316
0x844a6f _ZNKSt8functionIFvP6bpstatiEEclES1_i
        /usr/include/c++/7/bits/std_function.h:706
0x843ca7 _ZNK3gdb9observers10observableIJP6bpstatiEE6notifyES3_i
        /home/vries/gdb_versions/devel/src/gdb/../gdbsupport/observable.h:166
0x83f022 _Z11normal_stopv
        /home/vries/gdb_versions/devel/src/gdb/infrun.c:8775
0x8342e9 _Z20fetch_inferior_eventv
        /home/vries/gdb_versions/devel/src/gdb/infrun.c:4253
0x81535d _Z22inferior_event_handler19inferior_event_type
        /home/vries/gdb_versions/devel/src/gdb/inf-loop.c:41
0x87b24d handle_target_event
        /home/vries/gdb_versions/devel/src/gdb/linux-nat.c:4140
0x139cb81 handle_file_event
        /home/vries/gdb_versions/devel/src/gdbsupport/event-loop.cc:549
0x139d109 gdb_wait_for_event
        /home/vries/gdb_versions/devel/src/gdbsupport/event-loop.cc:670
0x139bfa4 _Z16gdb_do_one_eventv
        /home/vries/gdb_versions/devel/src/gdbsupport/event-loop.cc:210
0xbd6ea5 _Z22wait_sync_command_donev
        /home/vries/gdb_versions/devel/src/gdb/top.c:553
0xbd6f3a _Z28maybe_wait_sync_command_donei
        /home/vries/gdb_versions/devel/src/gdb/top.c:570
0xbd752a _Z15execute_commandPKci
        /home/vries/gdb_versions/devel/src/gdb/top.c:701
0x8be89f catch_command_errors
        /home/vries/gdb_versions/devel/src/gdb/main.c:513
0x8bea77 execute_cmdargs
        /home/vries/gdb_versions/devel/src/gdb/main.c:608
0x8bfdf8 captured_main_1
        /home/vries/gdb_versions/devel/src/gdb/main.c:1298
0x8bfffb captured_main
        /home/vries/gdb_versions/devel/src/gdb/main.c:1319
0x8c0066 _Z8gdb_mainP18captured_main_args
        /home/vries/gdb_versions/devel/src/gdb/main.c:1344
0x418b3d main
        /home/vries/gdb_versions/devel/src/gdb/gdb.c:32
...
Comment 8 Tom de Vries 2022-06-30 12:56:57 UTC
This seems to fix it:
...
diff --git a/gdb/cp-valprint.c b/gdb/cp-valprint.c
index 43a52698b71..11d75ced602 100644
--- a/gdb/cp-valprint.c
+++ b/gdb/cp-valprint.c
@@ -636,7 +636,10 @@ cp_find_class_member (struct type **self_p, int *fieldno,
 
   for (i = TYPE_N_BASECLASSES (self); i < len; i++)
     {
-      LONGEST bitpos = self->field (i).loc_bitpos ();
+      field &f = self->field (i);
+      if (f.loc_kind () != FIELD_LOC_KIND_BITPOS)
+       continue;
+      LONGEST bitpos = f.loc_bitpos ();
 
       QUIT;
       if (offset == bitpos)
...
Comment 9 Tom de Vries 2022-06-30 13:19:25 UTC
A slightly simpler reproducer:
...
$ cat test.cc
struct Base
{
  const char *Bar;
};

struct Foo : public Base
{
  static const int m_MsgIdx = 0;
};

const char* Foo::*Field = &Foo::Bar;

int
main ()
{
  return 0;
}
$ g++ test.cc -g
$ gdb -q -batch a.out -ex "p Field"
$1 = /home/vries/gdb_versions/devel/src/gdb/gdbtypes.h:695: internal-error: loc_bitpos: Assertion `m_loc_kind == FIELD_LOC_KIND_BITPOS' failed.
...
Comment 10 Tom de Vries 2022-06-30 13:44:00 UTC
Created attachment 14185 [details]
Tentative patch
Comment 11 Orgad Shaneh 2022-06-30 13:45:24 UTC
Thank you!
Comment 12 Tom de Vries 2022-06-30 13:54:26 UTC
(In reply to Orgad Shaneh from comment #11)
> Thank you!

You're welcome, and thanks for the reproducer :)
Comment 13 Tom de Vries 2022-06-30 14:09:33 UTC
(In reply to Orgad Shaneh from comment #6)
> Aaaaand we have a winner!
> 
> 84a6adfd4c ([gdb] Make execute_command_to_string return string on throw)

Btw, I've verified that the problem (using the simplified test-case) starts with commit cd3f655cc7a5, the one that introduced the assert.