* [rfa:amd64] Fetch 32-bit thread area
@ 2004-02-27 1:24 Andrew Cagney
2004-02-28 11:51 ` Mark Kettenis
0 siblings, 1 reply; 5+ messages in thread
From: Andrew Cagney @ 2004-02-27 1:24 UTC (permalink / raw)
To: gdb-patches
[-- Attachment #1: Type: text/plain, Size: 155 bytes --]
Hello,
This modifies the amd64 code so that, when 32-bit, it fetches the 32-bit
thread area register (I think this has been posted before?).
ok?
Andrew
[-- Attachment #2: diffs --]
[-- Type: text/plain, Size: 2901 bytes --]
* amd64-linux-nat.c (ps_get_thread_area): When architecture is
i386 use PTRACE_GET_THREAD_AREA. Suggested by Roland McGrath.
Index: amd64-linux-nat.c
===================================================================
RCS file: /cvs/src/src/gdb/amd64-linux-nat.c,v
retrieving revision 1.1
diff -u -r1.1 amd64-linux-nat.c
--- amd64-linux-nat.c 25 Feb 2004 20:45:30 -0000 1.1
+++ amd64-linux-nat.c 27 Feb 2004 01:22:36 -0000
@@ -350,10 +350,14 @@
}
\f
+/* This function is called by libthread_db as part of its handling of
+ a request for a thread's local storage address. */
+
ps_err_e
ps_get_thread_area (const struct ps_prochandle *ph,
lwpid_t lwpid, int idx, void **base)
{
+#if 0
/* This definition comes from prctl.h, but some kernels may not have it. */
#ifndef PTRACE_ARCH_PRCTL
#define PTRACE_ARCH_PRCTL 30
@@ -377,6 +381,67 @@
return PS_BADADDR;
}
return PS_ERR; /* ptrace failed. */
+#else
+ switch (TARGET_ARCHITECTURE->mach)
+ {
+ case bfd_mach_i386_i386:
+ case bfd_mach_i386_i386_intel_syntax:
+ {
+ /* The full structure is found in <asm-i386/ldt.h>. The
+ second integer is the LDT's base_address and that is used
+ to locate the thread's local storage. See i386-linux-nat.c
+ more info. */
+ unsigned int desc[4];
+
+ /* This code assumes that "int" is 32 bits and that
+ GET_THREAD_AREA returns no more than 4 int values. */
+ gdb_assert (sizeof (int) == 4);
+#ifndef PTRACE_GET_THREAD_AREA
+#define PTRACE_GET_THREAD_AREA 25
+#endif
+ if (ptrace (PTRACE_GET_THREAD_AREA,
+ lwpid, (void *) (long) idx, (unsigned long) &desc) < 0)
+ return PS_ERR;
+
+ /* Extend the value to 64 bits. Here it's assumed that a
+ "long" and a "void *" are the same. */
+ (*base) = (void *) (long) desc[1];
+ return PS_OK;
+ }
+
+ case bfd_mach_x86_64:
+ case bfd_mach_x86_64_intel_syntax:
+
+ /* This definition comes from prctl.h, but some kernels may not
+ have it. */
+#ifndef PTRACE_ARCH_PRCTL
+#define PTRACE_ARCH_PRCTL 30
+#endif
+ /* FIXME: ezannoni-2003-07-09 see comment above about include
+ file order. We could be getting bogus values for these two. */
+ gdb_assert (FS < ELF_NGREG);
+ gdb_assert (GS < ELF_NGREG);
+ switch (idx)
+ {
+ case FS:
+ if (ptrace (PTRACE_ARCH_PRCTL, lwpid, base, ARCH_GET_FS) == 0)
+ return PS_OK;
+ break;
+ case GS:
+ if (ptrace (PTRACE_ARCH_PRCTL, lwpid, base, ARCH_GET_GS) == 0)
+ return PS_OK;
+ break;
+ default: /* Should not happen. */
+ return PS_BADADDR;
+ }
+ return PS_ERR; /* ptrace failed. */
+
+ case bfd_mach_i386_i8086:
+ internal_error (__FILE__, __LINE__, "bad i8086 machine");
+ default:
+ internal_error (__FILE__, __LINE__, "bad_switch");
+ }
+#endif
}
\f
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [rfa:amd64] Fetch 32-bit thread area
2004-02-27 1:24 [rfa:amd64] Fetch 32-bit thread area Andrew Cagney
@ 2004-02-28 11:51 ` Mark Kettenis
2004-02-28 15:22 ` Andrew Cagney
0 siblings, 1 reply; 5+ messages in thread
From: Mark Kettenis @ 2004-02-28 11:51 UTC (permalink / raw)
To: ac131313; +Cc: gdb-patches
Date: Thu, 26 Feb 2004 20:24:47 -0500
From: Andrew Cagney <ac131313@redhat.com>
Hello,
This modifies the amd64 code so that, when 32-bit, it fetches the 32-bit
thread area register (I think this has been posted before?).
Why #if 0 ... #else ... #endif?
Anyway, I'm not really happy with the
switch (TARGET_ARCHITECTURE->mach)
construction. The other AMD64 native code uses an
if (gdbarch_ptr_bit (current_gdbarch) == 32)
to distinguish between 32-bit and 64-bit code. While this may not be
completely correct (someone might come up with a native AMD64 ABI with
32-bit pointers), I'd rather not use multiple variations of the
32-bit/64-bit check in the code.
Mark
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [rfa:amd64] Fetch 32-bit thread area
2004-02-28 11:51 ` Mark Kettenis
@ 2004-02-28 15:22 ` Andrew Cagney
2004-02-28 17:37 ` Mark Kettenis
0 siblings, 1 reply; 5+ messages in thread
From: Andrew Cagney @ 2004-02-28 15:22 UTC (permalink / raw)
To: Mark Kettenis; +Cc: ac131313, gdb-patches
> Date: Thu, 26 Feb 2004 20:24:47 -0500
> From: Andrew Cagney <ac131313@redhat.com>
>
> Hello,
>
> This modifies the amd64 code so that, when 32-bit, it fetches the 32-bit
> thread area register (I think this has been posted before?).
>
> Why #if 0 ... #else ... #endif?
Tipo from testing.
> Anyway, I'm not really happy with the
>
> switch (TARGET_ARCHITECTURE->mach)
>
> construction. The other AMD64 native code uses an
>
> if (gdbarch_ptr_bit (current_gdbarch) == 32)
>
> to distinguish between 32-bit and 64-bit code. While this may not be
> completely correct (someone might come up with a native AMD64 ABI with
> 32-bit pointers), I'd rather not use multiple variations of the
> 32-bit/64-bit check in the code.
Is it ok with that change?
Andrew
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [rfa:amd64] Fetch 32-bit thread area
2004-02-28 15:22 ` Andrew Cagney
@ 2004-02-28 17:37 ` Mark Kettenis
2004-02-28 19:40 ` Andrew Cagney
0 siblings, 1 reply; 5+ messages in thread
From: Mark Kettenis @ 2004-02-28 17:37 UTC (permalink / raw)
To: cagney; +Cc: ac131313, gdb-patches
Date: Sat, 28 Feb 2004 10:22:29 -0500
From: Andrew Cagney <cagney@gnu.org>
> Date: Thu, 26 Feb 2004 20:24:47 -0500
> From: Andrew Cagney <ac131313@redhat.com>
>
> Hello,
>
> This modifies the amd64 code so that, when 32-bit, it fetches the 32-bit
> thread area register (I think this has been posted before?).
>
> Why #if 0 ... #else ... #endif?
Tipo from testing.
Typo? You mean that you intended to remove the #if 0 block before
submitting the patch? Or what?
> Anyway, I'm not really happy with the
>
> switch (TARGET_ARCHITECTURE->mach)
>
> construction. The other AMD64 native code uses an
>
> if (gdbarch_ptr_bit (current_gdbarch) == 32)
>
> to distinguish between 32-bit and 64-bit code. While this may not be
> completely correct (someone might come up with a native AMD64 ABI with
> 32-bit pointers), I'd rather not use multiple variations of the
> 32-bit/64-bit check in the code.
Is it ok with that change?
If you remove the #if 0 block and re-indent the #else block. Yes.
Mark
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [rfa:amd64] Fetch 32-bit thread area
2004-02-28 17:37 ` Mark Kettenis
@ 2004-02-28 19:40 ` Andrew Cagney
0 siblings, 0 replies; 5+ messages in thread
From: Andrew Cagney @ 2004-02-28 19:40 UTC (permalink / raw)
To: Mark Kettenis; +Cc: ac131313, gdb-patches
[-- Attachment #1: Type: text/plain, Size: 1263 bytes --]
> Date: Sat, 28 Feb 2004 10:22:29 -0500
> From: Andrew Cagney <cagney@gnu.org>
>
> > Date: Thu, 26 Feb 2004 20:24:47 -0500
> > From: Andrew Cagney <ac131313@redhat.com>
> >
> > Hello,
> >
> > This modifies the amd64 code so that, when 32-bit, it fetches the 32-bit
> > thread area register (I think this has been posted before?).
> >
> > Why #if 0 ... #else ... #endif?
>
> Tipo from testing.
>
> Typo? You mean that you intended to remove the #if 0 block before
> submitting the patch? Or what?
Yes, "tipo". As Stan Shebs where the word comes from.
> > Anyway, I'm not really happy with the
> >
> > switch (TARGET_ARCHITECTURE->mach)
> >
> > construction. The other AMD64 native code uses an
> >
> > if (gdbarch_ptr_bit (current_gdbarch) == 32)
> >
> > to distinguish between 32-bit and 64-bit code. While this may not be
> > completely correct (someone might come up with a native AMD64 ABI with
> > 32-bit pointers), I'd rather not use multiple variations of the
> > 32-bit/64-bit check in the code.
>
> Is it ok with that change?
>
> If you remove the #if 0 block and re-indent the #else block. Yes.
Done. Committed the attached.
Andrew
[-- Attachment #2: diffs --]
[-- Type: text/plain, Size: 2989 bytes --]
2004-02-28 Andrew Cagney <cagney@redhat.com>
* amd64-linux-nat.c (ps_get_thread_area): When architecture is
i386 use PTRACE_GET_THREAD_AREA. Suggested by Roland McGrath.
Index: amd64-linux-nat.c
===================================================================
RCS file: /cvs/src/src/gdb/amd64-linux-nat.c,v
retrieving revision 1.3
diff -u -r1.3 amd64-linux-nat.c
--- amd64-linux-nat.c 28 Feb 2004 18:54:31 -0000 1.3
+++ amd64-linux-nat.c 28 Feb 2004 19:28:56 -0000
@@ -350,31 +350,60 @@
}
\f
+/* This function is called by libthread_db as part of its handling of
+ a request for a thread's local storage address. */
+
ps_err_e
ps_get_thread_area (const struct ps_prochandle *ph,
lwpid_t lwpid, int idx, void **base)
{
-/* This definition comes from prctl.h, but some kernels may not have it. */
+ if (gdbarch_ptr_bit (current_gdbarch) == 32)
+ {
+ /* The full structure is found in <asm-i386/ldt.h>. The second
+ integer is the LDT's base_address and that is used to locate
+ the thread's local storage. See i386-linux-nat.c more
+ info. */
+ unsigned int desc[4];
+
+ /* This code assumes that "int" is 32 bits and that
+ GET_THREAD_AREA returns no more than 4 int values. */
+ gdb_assert (sizeof (int) == 4);
+#ifndef PTRACE_GET_THREAD_AREA
+#define PTRACE_GET_THREAD_AREA 25
+#endif
+ if (ptrace (PTRACE_GET_THREAD_AREA,
+ lwpid, (void *) (long) idx, (unsigned long) &desc) < 0)
+ return PS_ERR;
+
+ /* Extend the value to 64 bits. Here it's assumed that a "long"
+ and a "void *" are the same. */
+ (*base) = (void *) (long) desc[1];
+ return PS_OK;
+ }
+ else
+ {
+ /* This definition comes from prctl.h, but some kernels may not
+ have it. */
#ifndef PTRACE_ARCH_PRCTL
#define PTRACE_ARCH_PRCTL 30
#endif
-
- /* FIXME: ezannoni-2003-07-09 see comment above about include file order.
- We could be getting bogus values for these two. */
- gdb_assert (FS < ELF_NGREG);
- gdb_assert (GS < ELF_NGREG);
- switch (idx)
- {
- case FS:
- if (ptrace (PTRACE_ARCH_PRCTL, lwpid, base, ARCH_GET_FS) == 0)
- return PS_OK;
- break;
- case GS:
- if (ptrace (PTRACE_ARCH_PRCTL, lwpid, base, ARCH_GET_GS) == 0)
- return PS_OK;
- break;
- default: /* Should not happen. */
- return PS_BADADDR;
+ /* FIXME: ezannoni-2003-07-09 see comment above about include
+ file order. We could be getting bogus values for these two. */
+ gdb_assert (FS < ELF_NGREG);
+ gdb_assert (GS < ELF_NGREG);
+ switch (idx)
+ {
+ case FS:
+ if (ptrace (PTRACE_ARCH_PRCTL, lwpid, base, ARCH_GET_FS) == 0)
+ return PS_OK;
+ break;
+ case GS:
+ if (ptrace (PTRACE_ARCH_PRCTL, lwpid, base, ARCH_GET_GS) == 0)
+ return PS_OK;
+ break;
+ default: /* Should not happen. */
+ return PS_BADADDR;
+ }
}
return PS_ERR; /* ptrace failed. */
}
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2004-02-28 19:40 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-02-27 1:24 [rfa:amd64] Fetch 32-bit thread area Andrew Cagney
2004-02-28 11:51 ` Mark Kettenis
2004-02-28 15:22 ` Andrew Cagney
2004-02-28 17:37 ` Mark Kettenis
2004-02-28 19:40 ` Andrew Cagney
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox