Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: LRN <lrn1986@gmail.com>
To: gdb-patches@sourceware.org
Subject: Re: Program-assigned thread names on Windows
Date: Mon, 25 Jul 2016 21:33:00 -0000	[thread overview]
Message-ID: <28023f06-f99c-77d1-10cf-5243f2a082a4@gmail.com> (raw)
In-Reply-To: <e50e62e8-b3a8-cd4a-aff0-ea2097cf2412@gmail.com>


[-- Attachment #1.1.1: Type: text/plain, Size: 3663 bytes --]

On 25.07.2016 17:23, LRN wrote:
> On 25.07.2016 17:06, Jon Turney wrote:
>> On 25/07/2016 14:34, LRN wrote:
>>> On 25.07.2016 15:17, Jon Turney wrote:
>>>> On 23/07/2016 18:01, LRN wrote:
>>>>> +	  named_thread_id = (DWORD) current_event.u.Exception.ExceptionRecord.ExceptionInformation[2];
>>>>> +	  thread_name_target = (uintptr_t) current_event.u.Exception.ExceptionRecord.ExceptionInformation[1];
>>>>
>>>> Is this going to be correct for 64-bit builds?
>>>
>>> I've only tested this on i686.
>>>
>>> Which variable are you concerned about - named_thread_id or thread_name_target?
>>
>> Both.  The ExceptionInformation isn't actually array of DWORDs, it's a 
>> THREADNAME_INFO structure, which contains a LPCSTR pointer (which has a 
>> different size on x86 and x86_64) *before* the thread id.
>>
>> So, I think this should check that NumbersParameters * sizeof(DWORD) is 
>> equal to or greater than sizeof(THREADNAME_INFO), then cast 
>> ExceptionInformation to a THREADNAME_INFO.
>>
>>> Tough this is a good point. MSDN says that i686 and x86_64 EXCEPTION_RECORD
>>> structures have different layout (well, to-be-pointer struct fields are
>>> DWORD64 on x86_64).
>>
>> I don't think gdb currently supports 32/64 bit interworking on Windows, 
>> so perhaps that is all moot (although if that is the case, perhaps it 
>> should diagnose attempts to do that)
>>
> 
> Yep, just tried to attach to a 64-bit process from a 32-bit gdb, and gdb
> failed to attach.
> 
> I'll try to come up with a way to build 64-bit gdb... it might take a while
> though.
> 

1) 64-bit gdb can attach to 32-bit debugees.
64-bit gdb sure throws a number of warnings when attaching to a 32-bit
debugee, but still attaches. However, it quickly gets into a tailspin, if i
do anything other than "run" (set breakpoints, step through functions).

2) EXCEPTION_RECORD does not need to be casted into EXCEPTION_RECORD32 or
EXCEPTION_RECORD64 for native processes, as it's correctly aligned in
either way ("2x4, 2 pointers, 4, pointer" - for 32-bit case everything is
tightly packed and 4-byte aligned, for 64-bit case the last pointer moves 4
bytes further to be self-aligned to 8 bytes, while everything else remains
the same), so we can keep accessing stuff via EXCEPTION_RECORD natively.
That is, EXCEPTION_RECORD64 is how EXCEPTION_RECORD normally looks in
64-bit process.

3) EXCEPTION_RECORD that we receive is sized to *gdb* bitness. That is,
casing it to EXCEPTION_RECORD32 in 64-bit gdb will always lead to bad
interpretation, even if debugee is 32-bit.

4) ExceptionInfromation array that we receive as part of EXCEPTION_RECORD
is *also natively aligned for gdb*. I've made 32-bit debugee print out the
addresses of fields of the THEADNAME_INFO structure, and it's aligned to 4
bytes (as expected), but examining the EXCEPTION_RECORD structure that
64-bit gdb receives shows that the ExceptionInformation array is aligned to
8 bytes. Therefore, it's safe to always use EXCEPTION_RECORD as-is, without
worrying about alignment of the ExceptionInformation data.

5) 64-bit gdb receives an EXCEPTION_RECORD with NumberParameters == 6 when
debugee is 64-bit. The contents of the extra 2 elements are a mystery (they
seem to point to the stack, but that's all i can tell). Also, the 4-th
element (which is "Reserved for future use, must be zero") is not zero when
the exception is caught.
In light of this, we should probably check for NumberParameters >= 4. Or
even NumberParameters >= 3, given that we don't really look at the 4th
parameter.

-- 
O< ascii ribbon - stop html email! - www.asciiribbon.org

[-- Attachment #1.1.2: 0x6759BA74.asc --]
[-- Type: application/pgp-keys, Size: 3540 bytes --]

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

  parent reply	other threads:[~2016-07-25 21:33 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-07-23  9:25 LRN
2016-07-23  9:33 ` Eli Zaretskii
2016-07-23  9:43   ` LRN
2016-07-23 10:18     ` Eli Zaretskii
2016-07-23 16:43 ` John Baldwin
2016-07-23 17:01   ` LRN
2016-07-25 12:17     ` Jon Turney
2016-07-25 13:34       ` LRN
2016-07-25 14:07         ` Jon Turney
     [not found]           ` <e50e62e8-b3a8-cd4a-aff0-ea2097cf2412@gmail.com>
2016-07-25 21:33             ` LRN [this message]
2016-07-26  6:08               ` LRN
2016-07-26 13:18                 ` Jon Turney
2016-07-26 14:17                   ` LRN
2016-07-26 15:41                     ` LRN
2016-07-26 17:15                       ` LRN
2016-07-26 22:20                         ` Jon Turney
2016-07-27 21:35                         ` Jon Turney
2016-07-28  7:21                           ` LRN
2016-08-02  9:47                             ` LRN
2016-08-02 14:55                               ` Eli Zaretskii
2016-08-10  7:12                                 ` LRN
2016-08-10 12:15                                   ` Pedro Alves
2016-08-10 17:54                                     ` LRN
2016-08-10 18:45                                       ` Pedro Alves
2016-08-10 23:42                                         ` LRN
2016-08-11  0:39                                           ` Pedro Alves

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=28023f06-f99c-77d1-10cf-5243f2a082a4@gmail.com \
    --to=lrn1986@gmail.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox