From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id kHuKHXOlamMOWxUAWB0awg (envelope-from ) for ; Tue, 08 Nov 2022 13:52:35 -0500 Received: by simark.ca (Postfix, from userid 112) id 6D9EF1E124; Tue, 8 Nov 2022 13:52:35 -0500 (EST) Authentication-Results: simark.ca; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=C39NOTEZ; dkim-atps=neutral X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, RDNS_DYNAMIC,URIBL_BLOCKED,WEIRD_PORT autolearn=ham autolearn_force=no version=3.4.6 Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 1F4191E0D3 for ; Tue, 8 Nov 2022 13:52:35 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 318E3385842F for ; Tue, 8 Nov 2022 18:52:33 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 318E3385842F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1667933553; bh=jAxRSZ8jCurJElzap/qYC4litERYi0xLt+rvkU7xwmw=; h=To:Cc:Subject:References:Date:In-Reply-To:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=C39NOTEZnnDAnvtuPDRTJTB9HtpDkidYn0QUoMeWE7DWV0dtAwMIrwA7p8dy9GpiZ 1uUA7e74E4wwDByASnInIg78pXhefa0rEmgOcyZbuBD6CGJTt87CL0IScZdLpOU0J8 ZlK8koVsP4Gq0dIz+MPc/6g35aSUG1EP5uKjBwtg= 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 Received: by mail-io1-xd35.google.com with SMTP id n191so12171630iod.13 for ; Tue, 08 Nov 2022 10:52:10 -0800 (PST) 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) 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-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Tom Tromey via Gdb-patches Reply-To: Tom Tromey Errors-To: gdb-patches-bounces+public-inbox=simark.ca@sourceware.org Sender: "Gdb-patches" >>>>> "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);