Сбой GDB при печати значения атомарного перечисления - PullRequest
3 голосов
/ 23 марта 2019

При компиляции следующей программы с g++ [gcc версия 8.3.1 20190223 (Red Hat 8.3.1-2) (GCC)], отладка с помощью gdb [GNU gdb (GDB) Fedora 8.2-6.fc29] вызывает ошибку сегментации.

#include <atomic>

enum class foo {ONE, TWO, THREE, FOUR, FIVE, SIX};

int main(int argc, char **argv)
{
  std::atomic<foo> x = foo::FOUR;
  std::atomic<int> y = int(foo::FOUR);
  return 0;
}

, скомпилированный с g++ -Wall -Wextra -Wpedantic -std=gnu++2a -O0 -g3, сеанс gdb имеет следующее поведение:

(gdb) break main
(gdb) r
(gdb) p y
$1 = {<std::__atomic_base<int>> = {static _S_alignment = 4, _M_i = 3}, static is_always_lock_free = true}
(gdb) p x
$2 = {static _S_min_alignment = 4, static _S_alignment = 4, _M_i = foo::FOUR, 
Segmentation fault (core dumped)

Как видно, значение atomic<int> y может быть проверено, но попытка проверки atomic<foo> x вызывает ошибку segfault.

Я злоупотребляю c ++, или это ошибка в gdb?

1 Ответ

2 голосов
/ 25 марта 2019

это ошибка в GDB?

Да, GDB аварийно завершает работу со следующей трассировкой стека:

(gdb) bt
#0  0x000055dd368292ac in value_entirely_covered_by_range_vector (value=0x0, ranges=<error reading variable: Cannot access memory at address 0xa0>) at ../../gdb/value.c:417
#1  0x000055dd3666e854 in cp_print_static_field (options=0x7ffd14597de0, recurse=1, stream=0x55dd384ea5c0, val=0x0, type=0x55dd385531f0) at ../../gdb/cp-valprint.c:631
#2  cp_print_value_fields (type=<optimized out>, real_type=<optimized out>, offset=0, address=140737488343980, stream=0x55dd384ea5c0, recurse=0, val=0x55dd38903ed0, options=0x7ffd14597de0, dont_print_vb=0x0, dont_print_statmem=0) at ../../gdb/cp-valprint.c:332
#3  0x000055dd3666f02c in cp_print_value_fields_rtti (type=<optimized out>, type@entry=0x55dd38662a30, valaddr=valaddr@entry=0x55dd38903f90 "\003", offset=offset@entry=0, address=address@entry=140737488343980, stream=stream@entry=0x55dd384ea5c0, recurse=<optimized out>, val=0x55dd38903ed0, options=0x7ffd14597de0, dont_print_vb=0x0, dont_print_statmem=0) at ../../gdb/cp-valprint.c:449
#4  0x000055dd366492e5 in c_val_print_struct (type=0x55dd38662a30, valaddr=0x55dd38903f90 "\003", embedded_offset=0, address=140737488343980, stream=0x55dd384ea5c0, recurse=<optimized out>, original_value=0x55dd38903ed0, options=0x7ffd14597de0) at ../../gdb/c-valprint.c:411
#5  0x000055dd36649800 in c_val_print (type=<optimized out>, embedded_offset=0, address=140737488343980, stream=0x55dd384ea5c0, recurse=0, original_value=0x55dd38903ed0, options=0x7ffd14597de0) at ../../gdb/c-valprint.c:532
#6  0x000055dd36820c50 in val_print (type=type@entry=0x55dd38662a30, embedded_offset=0, address=address@entry=140737488343980, stream=stream@entry=0x55dd384ea5c0, recurse=recurse@entry=0, val=val@entry=0x55dd38903ed0, options=<optimized out>, language=0x55dd36d4f2c0 <cplus_language_defn>) at ../../gdb/valprint.c:1061
#7  0x000055dd3664a00d in c_value_print (val=0x55dd38903ed0, stream=0x55dd384ea5c0, options=<optimized out>) at ../../gdb/c-valprint.c:723
#8  0x000055dd36758da1 in print_value (val=val@entry=0x55dd38903ed0, fmtp=fmtp@entry=0x7ffd14597ff0) at ../../gdb/printcmd.c:1173
#9  0x000055dd36758e65 in print_command_1 (exp=<optimized out>, voidprint=1) at ../../gdb/printcmd.c:1205
#10 0x000055dd365504ba in cmd_func (cmd=<optimized out>, args=<optimized out>, from_tty=<optimized out>) at ../../gdb/cli/cli-decode.c:1857
#11 0x000055dd367f44a1 in execute_command (p=<optimized out>, p@entry=0x55dd37bf19f0 "p x", from_tty=1) at ../../gdb/top.c:630
#12 0x000055dd366cf884 in command_handler (command=0x55dd37bf19f0 "p x") at ../../gdb/event-top.c:586
#13 0x000055dd366d074e in command_line_handler (rl=<optimized out>) at ../../gdb/event-top.c:777
#14 0x000055dd366cef90 in gdb_rl_callback_handler (rl=0x55dd38cba750 "p x") at ../../gdb/event-top.c:214
#15 0x00007f3231ae1ede in rl_callback_read_char () from /lib64/libreadline.so.7
#16 0x000055dd366ceea6 in gdb_rl_callback_read_char_wrapper_noexcept () at ../../gdb/event-top.c:176
#17 0x000055dd366cef2d in gdb_rl_callback_read_char_wrapper (client_data=<optimized out>) at ../../gdb/event-top.c:192
#18 0x000055dd366cf458 in stdin_event_handler (error=<optimized out>, client_data=0x55dd37be9990) at ../../gdb/event-top.c:514
#19 0x000055dd366ce29d in gdb_wait_for_event (block=<optimized out>) at ../../gdb/event-loop.c:859
#20 gdb_wait_for_event (block=<optimized out>) at ../../gdb/event-loop.c:746
#21 0x000055dd366ce448 in gdb_do_one_event () at ../../gdb/event-loop.c:347
#22 0x000055dd366ce55e in gdb_do_one_event () at ../../gdb/event-loop.c:371
#23 start_event_loop () at ../../gdb/event-loop.c:371
#24 0x000055dd3673342b in captured_command_loop () at ../../gdb/main.c:331
#25 0x000055dd36734afd in captured_main (data=0x7ffd14598470) at ../../gdb/main.c:1267
#26 gdb_main (args=0x7ffd14598470) at ../../gdb/main.c:1284
#27 0x000055dd3648489f in main (argc=<optimized out>, argv=<optimized out>) at ../../gdb/gdb.c:40
(gdb) 

Существуют похожие следы стека в уже сообщенной ошибке https://sourceware.org/bugzilla/show_bug.cgi?id=20020. Также уже есть патч, который исправляет эту ошибку, см. https://sourceware.org/bugzilla/show_bug.cgi?id=20020#c16.

...