From patchwork Wed Aug 10 07:11:45 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: LRN X-Patchwork-Id: 14463 Received: (qmail 109648 invoked by alias); 10 Aug 2016 07:12:06 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 109638 invoked by uid 89); 10 Aug 2016 07:12:05 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: =?ISO-8859-1?Q?No, score=0.3 required=5.0 tests=AWL, BAYES_00, BODY_8BITS, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, GARBLED_BODY, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=no version=3.3.2 spammy=H*r:sk:broadba, =d0=be=d0=b2, =d0=bb=d0=b0=d1, hell?= X-HELO: mail-wm0-f48.google.com Received: from mail-wm0-f48.google.com (HELO mail-wm0-f48.google.com) (74.125.82.48) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Wed, 10 Aug 2016 07:11:55 +0000 Received: by mail-wm0-f48.google.com with SMTP id o80so82704235wme.1 for ; Wed, 10 Aug 2016 00:11:54 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to; bh=Nzr/Ls/tW4O6MVziG4WU0ZKgKQgRtkRKB30fnyZh9SQ=; b=F9mhXpVS6J5YhbN8baTrGZ5tYpD5gFvk7lizQoM6JSq9OOM33HyvsfF8nKq/u5U+sM GF8ZvEZZYUUFGlZEPn3Mm31MjsT7LEcOB8Yd/7nR+YVWO4Rqn0Z2YWPiWWUtuY92L/0H /jknA30ZAsUj6XsMd/TM0QKKpB3uBagNZj8ebpkunnlQj2HQDbs500YpaTn/I0uPbt+l 2CyDBHZxWOuy5JRAet/eCFX7UnqDe2zHbn3cWcMWdwH11WwzZHekzCYkN5jn24FOvPEZ t0gFlMUGrlbne3xw3hdORs0BYlkwD78nSAtJIWLmbCOvJT8NBaSWUqd+NpKMXvHBlXri 9crQ== X-Gm-Message-State: AEkoousc87sigkB2Nilrl9CTgchvAGv9HNJRSwXs7jId9RZ++kb3IrV3+cvpcoFpLYiL3w== X-Received: by 10.46.1.35 with SMTP id 35mr369403ljb.8.1470813111377; Wed, 10 Aug 2016 00:11:51 -0700 (PDT) Received: from [192.168.4.39] (broadband-95-84-200-6.nationalcablenetworks.ru. [95.84.200.6]) by smtp.gmail.com with ESMTPSA id g88sm7312191ljg.26.2016.08.10.00.11.50 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 10 Aug 2016 00:11:50 -0700 (PDT) Subject: Re: Program-assigned thread names on Windows To: gdb-patches@sourceware.org References: <5052d495-ea40-b364-96ea-9e68c90bd747@gmail.com> <14995502.J10EtrK3xV@ralph.baldwin.cx> <6a3446f9-63dc-67a1-3702-203d77c8d85d@gmail.com> <0cabec98-8411-2c3a-98d0-3d950de02bc5@gmail.com> <28023f06-f99c-77d1-10cf-5243f2a082a4@gmail.com> <0e59216f-77cb-608a-aa39-578c2610eda1@dronecode.org.uk> <0f064b2b-6b51-f132-caa6-a4c1a85585a3@gmail.com> <2c9f43ec-af6f-cdaf-8e45-b251588b9b89@gmail.com> <0515957c-dfd2-b119-d423-517917e8a5cd@gmail.com> <40aaee01-35a5-9d3f-ceae-2bf4ca53a7b9@gmail.com> <83twf3md9t.fsf@gnu.org> From: LRN Message-ID: <96ea9dc1-ce52-532d-d733-97af33bb70b4@gmail.com> Date: Wed, 10 Aug 2016 10:11:45 +0300 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:51.0) Gecko/20100101 Thunderbird/51.0a1 MIME-Version: 1.0 In-Reply-To: <83twf3md9t.fsf@gnu.org> X-IsSubscribed: yes On 02.08.2016 17:55, Eli Zaretskii wrote: >> From: LRN >> Date: Tue, 2 Aug 2016 12:46:47 +0300 >> >> So, what happens now? > > If no one objects in a while, we push. > No one seems to object. I've attached the version of the patch with the named_thread == NULL issue fixed, and also the ChangeLog and NEWS patches just for the hell of it. diff --git a/gdb/windows-nat.c b/gdb/windows-nat.c index 3f67486..8917997 100644 --- a/gdb/windows-nat.c +++ b/gdb/windows-nat.c @@ -174,6 +174,15 @@ static int debug_registers_used; static int windows_initialization_done; #define DR6_CLEAR_VALUE 0xffff0ff0 +#define MS_VC_EXCEPTION 0x406D1388 + +typedef enum +{ + HANDLE_EXCEPTION_UNHANDLED = 0, + HANDLE_EXCEPTION_HANDLED, + HANDLE_EXCEPTION_IGNORED +} handle_exception_result; + /* The string sent by cygwin when it processes a signal. FIXME: This should be in a cygwin include file. */ #ifndef _CYGWIN_SIGNAL_STRING @@ -1031,10 +1040,11 @@ display_selectors (char * args, int from_tty) host_address_to_string (\ current_event.u.Exception.ExceptionRecord.ExceptionAddress)) -static int +static handle_exception_result handle_exception (struct target_waitstatus *ourstatus) { DWORD code = current_event.u.Exception.ExceptionRecord.ExceptionCode; + handle_exception_result result = HANDLE_EXCEPTION_HANDLED; ourstatus->kind = TARGET_WAITKIND_STOPPED; @@ -1064,7 +1074,7 @@ handle_exception (struct target_waitstatus *ourstatus) && addr < cygwin_load_end)) || (find_pc_partial_function (addr, &fn, NULL, NULL) && startswith (fn, "KERNEL32!IsBad"))) - return 0; + return HANDLE_EXCEPTION_UNHANDLED; } #endif break; @@ -1140,10 +1150,52 @@ handle_exception (struct target_waitstatus *ourstatus) DEBUG_EXCEPTION_SIMPLE ("EXCEPTION_NONCONTINUABLE_EXCEPTION"); ourstatus->value.sig = GDB_SIGNAL_ILL; break; + case MS_VC_EXCEPTION: + if (current_event.u.Exception.ExceptionRecord.NumberParameters >= 3 + && (current_event.u.Exception.ExceptionRecord.ExceptionInformation[0] & 0xFFFFFFFF) == 0x1000) + { + long named_thread_id; + ptid_t named_thread_ptid; + struct thread_info *named_thread; + CORE_ADDR thread_name_target; + char *thread_name; + int thread_name_len; + + DEBUG_EXCEPTION_SIMPLE ("MS_VC_EXCEPTION"); + + named_thread_id = (long) (0xFFFFFFFF & current_event.u.Exception.ExceptionRecord.ExceptionInformation[2]); + thread_name_target = current_event.u.Exception.ExceptionRecord.ExceptionInformation[1]; + + if (named_thread_id == (DWORD) -1) + named_thread_id = current_event.dwThreadId; + + named_thread_ptid = ptid_build (current_event.dwProcessId, 0, named_thread_id), + named_thread = find_thread_ptid (named_thread_ptid); + + thread_name = NULL; + thread_name_len = target_read_string (thread_name_target, &thread_name, 1025, 0); + if (thread_name_len > 0 && thread_name != NULL) + { + thread_name[thread_name_len - 1] = '\0'; + if (thread_name[0] != '\0' && named_thread != NULL) + { + xfree (named_thread->name); + named_thread->name = thread_name; + } + else + { + xfree (thread_name); + } + } + ourstatus->value.sig = GDB_SIGNAL_TRAP; + result = HANDLE_EXCEPTION_IGNORED; + break; + } + /* treat improperly formed exception as unknown, fallthrough */ default: /* Treat unhandled first chance exceptions specially. */ if (current_event.u.Exception.dwFirstChance) - return 0; + return HANDLE_EXCEPTION_UNHANDLED; printf_unfiltered ("gdb: unknown target exception 0x%08x at %s\n", (unsigned) current_event.u.Exception.ExceptionRecord.ExceptionCode, host_address_to_string ( @@ -1153,7 +1205,7 @@ handle_exception (struct target_waitstatus *ourstatus) } exception_count++; last_sig = ourstatus->value.sig; - return 1; + return result; } /* Resume thread specified by ID, or all artificially suspended @@ -1510,10 +1562,19 @@ get_windows_debug_event (struct target_ops *ops, "EXCEPTION_DEBUG_EVENT")); if (saw_create != 1) break; - if (handle_exception (ourstatus)) - thread_id = current_event.dwThreadId; - else - continue_status = DBG_EXCEPTION_NOT_HANDLED; + switch (handle_exception (ourstatus)) + { + case HANDLE_EXCEPTION_UNHANDLED: + default: + continue_status = DBG_EXCEPTION_NOT_HANDLED; + break; + case HANDLE_EXCEPTION_HANDLED: + thread_id = current_event.dwThreadId; + break; + case HANDLE_EXCEPTION_IGNORED: + continue_status = DBG_CONTINUE; + break; + } break; case OUTPUT_DEBUG_STRING_EVENT: /* Message from the kernel. */