From: Simon Marchi Date: Thu, 3 Jul 2025 17:37:41 +0000 (-0400) Subject: gdb/linux-nat: initialize lwp_info::syscall_state X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=b7ff16c68a2c0bacc0416c4b36a44e65888ce72b;p=thirdparty%2Fbinutils-gdb.git gdb/linux-nat: initialize lwp_info::syscall_state When running gdb.base/foll-fork-syscall.exp with a GDB built with UBSan, I get: /home/simark/src/binutils-gdb/gdb/linux-nat.c:1906:28: runtime error: load of value 3200171710, which is not a valid value for type 'target_waitkind' ERROR: GDB process no longer exists GDB process exited with wait status 3026417 exp9 0 1 UNRESOLVED: gdb.base/foll-fork-syscall.exp: follow-fork-mode=child: detach-on-fork=on: test_catch_syscall: continue to breakpoint after fork The error happens here: #0 __sanitizer::Die () at /usr/src/debug/gcc/gcc/libsanitizer/sanitizer_common/sanitizer_termination.cpp:50 #1 0x00007ffff600d8dd in __ubsan::__ubsan_handle_load_invalid_value_abort (Data=, Val=) at /usr/src/debug/gcc/gcc/libsanitizer/ubsan/ubsan_handlers.cpp:551 #2 0x00005555636d37b6 in linux_handle_syscall_trap (lp=0x7cdff1eb1b00, stopping=0) at /home/simark/src/binutils-gdb/gdb/linux-nat.c:1906 #3 0x00005555636e0991 in linux_nat_filter_event (lwpid=3030627, status=1407) at /home/simark/src/binutils-gdb/gdb/linux-nat.c:3044 #4 0x00005555636e407f in linux_nat_wait_1 (ptid=..., ourstatus=0x7bfff0d6cf18, target_options=...) at /home/simark/src/binutils-gdb/gdb/linux-nat.c:3381 #5 0x00005555636e7795 in linux_nat_target::wait (this=0x5555704d35e0 , ptid=..., ourstatus=0x7bfff0d6cf18, target_options=...) at /home/simark/src/binutils-gdb/gdb/linux-nat.c:3607 #6 0x000055556378fad2 in thread_db_target::wait (this=0x55556af42980 , ptid=..., ourstatus=0x7bfff0d6cf18, options=...) at /home/simark/src/binutils-gdb/gdb/linux-thread-db.c:1398 #7 0x0000555564811327 in target_wait (ptid=..., status=0x7bfff0d6cf18, options=...) at /home/simark/src/binutils-gdb/gdb/target.c:2593 I believe the problem is that lwp_info::syscall_state is never initialized. Fix that by initializing it with TARGET_WAITKIND_IGNORE. This is the value we use elsewhere when resetting this field to mean "not stopped at a syscall". Change-Id: I5b76c63d1466d6e63448fced03305fd5ca8294eb Approved-By: Tom Tromey --- diff --git a/gdb/linux-nat.h b/gdb/linux-nat.h index 21ec309dafb..7cbe9a98789 100644 --- a/gdb/linux-nat.h +++ b/gdb/linux-nat.h @@ -279,12 +279,12 @@ struct lwp_info : intrusive_list_node will be recorded here, while 'status == 0' is ambiguous. */ struct target_waitstatus waitstatus; - /* Signal whether we are in a SYSCALL_ENTRY or - in a SYSCALL_RETURN event. - Values: - - TARGET_WAITKIND_SYSCALL_ENTRY - - TARGET_WAITKIND_SYSCALL_RETURN */ - enum target_waitkind syscall_state; + /* Signal whether we are in a SYSCALL_ENTRY or SYSCALL_RETURN event. + + Valid values are TARGET_WAITKIND_SYSCALL_ENTRY, + TARGET_WAITKIND_SYSCALL_RETURN, or TARGET_WAITKIND_SYSCALL_IGNORE, when + not stopped at a syscall. */ + target_waitkind syscall_state = TARGET_WAITKIND_IGNORE; /* The processor core this LWP was last seen on. */ int core = -1;