From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-io1-xd35.google.com (mail-io1-xd35.google.com [IPv6:2607:f8b0:4864:20::d35]) by sourceware.org (Postfix) with ESMTPS id 99F0D3858D35 for ; Tue, 8 Nov 2022 18:52:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 99F0D3858D35 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com Received: by mail-io1-xd35.google.com with SMTP id n191so12171630iod.13 for ; Tue, 08 Nov 2022 10:52:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; h=mime-version:user-agent:message-id:in-reply-to:date:references :subject:cc:to:from:from:to:cc:subject:date:message-id:reply-to; bh=jAxRSZ8jCurJElzap/qYC4litERYi0xLt+rvkU7xwmw=; b=f8yRD02LsaRRGAAeNAsiXsRVsLMq4DoznKZ0DX61AiJ5wpuTIOiH5lWYdX4RYCuIlY hVMoelWId7C/zHCRi1Gr/Sox+3puVqQ3mc+MdyLWM+BgQ6u12ECCUAcABbtZcGprgCJP AXdtfdfbzULI1vIjLlGIhMDcGDtOCNS3hoBwTLkNTREYv46VPr1koqvxEy/ERNPj+ykD 1N57XO8lZ1W5BYUVDRKB1jxjM0QvQQdFKmEHA7jkHf0e+x/lL03tuGQUA6lu/E6PDf/F h/Q1BsjgQ1283gOjbDgKA5O9a81Vco1HrtcWSPvFB/CQtYKENcC2rFm+El7SssBSOXF0 sCvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=mime-version:user-agent:message-id:in-reply-to:date:references :subject:cc:to:from:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=jAxRSZ8jCurJElzap/qYC4litERYi0xLt+rvkU7xwmw=; b=0xzNkB1gO0n/zCR1/EKJvXA6hyA6e/aj7/iV00PQHQUafy8o8dFodYaNuX9QOuXhY3 phpmi9Fx3bTGUIzkXgMS8Osq8ExMvOyxjDoCurSYyD3Tgv3bjmXaOPHf7dIJ3ChCMSpH TyApW8d6UvL0YxuyU+xdNVt2KTyOvy4mPc90MUJejo30UsmvEemqvCbZWKe7MF02ipHT 0umGeI+VWz7hJuzK+8bZoCb0a94u1RLa9ffRMU05Eo3atECoP9TpF6BCsaX64l67JUj8 ze/+o2vRW9MIEyWl9fIdGs+UaXtl4xNRcDaow+6OAtrHL+SiXD/Il/RtKxqYYF7sc/xb Bt6Q== X-Gm-Message-State: ACrzQf1b2Zk42y1FrM9rGJ+OBfY7XTcKDT0c/eO17EZ5jtwAoOAmpsNG /8lrBYxFLmKDsTg7PZ7Pfl0qcw== X-Google-Smtp-Source: AMsMyM5lOxsgWHsEr+gPDBftyd7KpaCUUCZx963/drcis4PwRQIoRLxyfVQIdpC6PBhKE6+G504bfg== X-Received: by 2002:a05:6638:42:b0:363:9776:492e with SMTP id a2-20020a056638004200b003639776492emr917353jap.208.1667933529864; Tue, 08 Nov 2022 10:52:09 -0800 (PST) Received: from murgatroyd (97-122-76-186.hlrn.qwest.net. [97.122.76.186]) by smtp.gmail.com with ESMTPSA id q2-20020a02a982000000b00363e61908bfsm4049289jam.10.2022.11.08.10.52.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Nov 2022 10:52:09 -0800 (PST) From: Tom Tromey To: Jon Turney Cc: Tom Tromey , gdb-patches@sourceware.org Subject: Re: [PATCH 2/2] Implement target async for Windows References: <20220803130822.735057-1-tromey@adacore.com> <20220803130822.735057-3-tromey@adacore.com> X-Attribution: Tom Date: Tue, 08 Nov 2022 11:52:08 -0700 In-Reply-To: (Jon Turney's message of "Fri, 4 Nov 2022 14:59:30 +0000") Message-ID: <87bkph46uf.fsf@tromey.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Status: No, score=-11.0 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP,WEIRD_PORT autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: >>>>> "Jon" == Jon Turney writes: >> Thread 1 "gdb" received signal SIGSEGV, Segmentation fault. >> ops=ops@entry=0x100abfca0 , open_name=open_name@entry=0x0) at ../../gdb/serial.c:249 >> 249 if (!serial_logfile.empty ()) >> (top-gdb) p serial_logfile >> $1 = >> (top-gdb) bt >> #0 0x000000010071e755 in serial_open_ops_1 (ops=ops@entry=0x100abfca0 , open_name=open_name@entry=0x0) at ../../gdb/serial.c:249 >> #1 0x000000010071ec77 in serial_open_ops (ops=ops@entry=0x100abfca0 ) at ../../gdb/serial.c:267 >> #2 0x000000010071d0ac in make_serial_event () at ../../gdb/ser-event.c:164 >> #3 0x0000000100810f9e in windows_nat_target::windows_nat_target (this=0x100cdf2e0 ) at ../../gdb/windows-nat.c:406 >> #4 0x00000001009d77f0 in __static_initialization_and_destruction_0 (__initialize_p=1, __priority=65535) at ../../gdb/windows-nat.c:390 >> #5 _GLOBAL__sub_I__ZN18windows_nat_targetC2Ev () at ../../gdb/windows-nat.c:3311 >> #6 0x00007fff152a6582 in do_global_ctors (force=0, in_pfunc=0x1009d8700 <___CTOR_LIST__>) at ../../../../src/winsup/cygwin/dcrt0.cc:78 >> #7 __main () at ../../../../src/winsup/cygwin/dcrt0.cc:1084 >> #8 0x00000001009cd7d0 in main (argc=1, argv=0x7ffffcc50) at ../../gdb/gdb.c:25 Jon> This looks like an problem with static object construction ordering: Jon> the serial_logfile object needs to be constructed before before Jon> the_windows_nat_target object, but nothing enforces that, currently. Ugh... Jon> Attached is a patch I wrote to verify the issue, and applying it fixes Jon> the crash for me, but I'm sure there is a more elegant solution out Jon> there... It seems to me that serial.c is blameless and that windows-nat should probably not have a static initializer with dependencies. Could you try this change instead? Tom diff --git a/gdb/windows-nat.c b/gdb/windows-nat.c index ab94de03bbf..ecd5cf7e3fb 100644 --- a/gdb/windows-nat.c +++ b/gdb/windows-nat.c @@ -385,7 +385,9 @@ struct windows_nat_target final : public x86_nat_target bool m_is_async = false; }; -static windows_nat_target the_windows_nat_target; +/* This is a pointer and not a global specifically to avoid a C++ + "static initializer fiasco" situation. */ +static windows_nat_target *the_windows_nat_target; static void check (BOOL ok, const char *file, int line) @@ -621,7 +623,7 @@ windows_nat_target::delete_thread (ptid_t ptid, DWORD exit_code, target_pid_to_str (ptid).c_str (), (unsigned) exit_code); - ::delete_thread (find_thread_ptid (&the_windows_nat_target, ptid)); + ::delete_thread (find_thread_ptid (the_windows_nat_target, ptid)); auto iter = std::find_if (windows_process.thread_list.begin (), windows_process.thread_list.end (), @@ -3119,7 +3121,8 @@ _initialize_windows_nat () calling x86_set_debug_register_length function in processor windows specific native file. */ - add_inf_child_target (&the_windows_nat_target); + the_windows_nat_target = new windows_nat_target; + add_inf_child_target (the_windows_nat_target); #ifdef __CYGWIN__ cygwin_internal (CW_SET_DOS_FILE_WARNING, 0);