Mirror of the gdb mailing list
 help / color / mirror / Atom feed
From: 慕冬亮 <mudongliangabcd@gmail.com>
To: Jan Kratochvil <jan.kratochvil@redhat.com>
Cc: gdb@sourceware.org
Subject: Re: How to get value of gs:0xc with LTS note in coredump?
Date: Tue, 04 Oct 2016 01:49:00 -0000	[thread overview]
Message-ID: <CAD-N9QVdQ9S1odeE-BFaQUE36jY2q6RFzUTfq_h9CD6Wb83cWQ@mail.gmail.com> (raw)
In-Reply-To: <20161004012026.GA30611@host1.jankratochvil.net>

2016-10-03 21:20 GMT-04:00 Jan Kratochvil <jan.kratochvil@redhat.com>:
> On Tue, 04 Oct 2016 02:59:45 +0200, 慕冬亮 wrote:
>> I have a question about gs and TLS in core dump. When I read the
>> assembly code from one coredump, there is one memory dereference :
>> gs:[edx] or gs:0xc.
>>
>> I googled gs register and found it points to Thread Local Storage.
>> However, gs is a selector to GDT and this structure is in the kernel.
>> And I could not obtain it in coredump.
>
> %gs on i386 (and %fs on x86_64) points to pthread_self() which is
> 'struct pthread *' (if you have glibc debug info available) where at offset 0xc
> is 'void *self' which is the pthread_self() pointer itself (%gs:0xc is faster
> to access).
>
>
>> Then I searched all the segments in core dump. I found a note entry
>> with type NT_386_TLS, length 0x30. Is gs:0xc in this note ? And gs:0xc
>> is the 12th element of this note entry?
>
> Yes, pthread_self() is coincidentally also the value of %gsbase (%fsbase on
> x86_64) but GDB cannot show that register, in a core file you can see it by
> "eu-readelf -n" (from elfutils, "readelf -n" from binutils does not show it)
> as:
>   LINUX                 48  386_TLS
>     index: 12, base: 0xf7778800, limit: 0x000fffff, flags: 0x00000051
>                      ^^^^^^^^^^=pthread_self()
>

I need to analyze this note entry in my C code. How is it arranged by
kernel or gdb?
And what's the data structure for every item in this entry?

LINUX                 48  386_TLS
    index: 6, base: 0xb7fd57c0, limit: 0x000fffff, flags: 0x00000051
    index: 7, base: 0x00000000, limit: 0x00000000, flags: 0x00000028
    index: 8, base: 0x00000000, limit: 0x00000000, flags: 0x00000028

The above is output from "eu-readelf -n  mycore".

--
My best regards to you.

     No System Is Safe!
     Dongliang Mu


>
> Jan


  reply	other threads:[~2016-10-04  1:49 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-04  1:00 慕冬亮
2016-10-04  1:20 ` Jan Kratochvil
2016-10-04  1:49   ` 慕冬亮 [this message]
2016-10-04  6:57     ` Jan Kratochvil
2016-10-04 17:06       ` 慕冬亮

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=CAD-N9QVdQ9S1odeE-BFaQUE36jY2q6RFzUTfq_h9CD6Wb83cWQ@mail.gmail.com \
    --to=mudongliangabcd@gmail.com \
    --cc=gdb@sourceware.org \
    --cc=jan.kratochvil@redhat.com \
    /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