aboutsummaryrefslogtreecommitdiff
path: root/gdb/i386-linux-nat.c
diff options
context:
space:
mode:
authorGary Benson <gbenson@redhat.com>2014-06-25 11:49:55 +0100
committerGary Benson <gbenson@redhat.com>2014-07-11 12:23:16 +0100
commit8c420b8d59e8e045aa733f478adb1d0509d447e3 (patch)
treed254802f2f14195d901dbb2455b69142ca7c08e8 /gdb/i386-linux-nat.c
parentcb1da100b6291ad35ad886555a0f7114925ed29f (diff)
downloadgdb-8c420b8d59e8e045aa733f478adb1d0509d447e3.zip
gdb-8c420b8d59e8e045aa733f478adb1d0509d447e3.tar.gz
gdb-8c420b8d59e8e045aa733f478adb1d0509d447e3.tar.bz2
Merge ps_get_thread_area
This commit adds a new helper, x86_linux_get_thread_area, to hold the common parts of the ps_get_thread_area functions in i386-linux-nat.c and amd64-linux-nat.c. gdb/ 2014-07-11 Gary Benson <gbenson@redhat.com> * amd64-linux-nat.c (x86_linux_get_thread_area): New function. (ps_get_thread_area): Delegate to the above in 32-bit mode. * i386-linux-nat.c (x86_linux_get_thread_area): New function. (ps_get_thread_area): Delegate to the above.
Diffstat (limited to 'gdb/i386-linux-nat.c')
-rw-r--r--gdb/i386-linux-nat.c36
1 files changed, 28 insertions, 8 deletions
diff --git a/gdb/i386-linux-nat.c b/gdb/i386-linux-nat.c
index 62ad29f..d647c3d 100644
--- a/gdb/i386-linux-nat.c
+++ b/gdb/i386-linux-nat.c
@@ -848,12 +848,12 @@ x86_linux_new_fork (struct lwp_info *parent, pid_t child_pid)
-/* Called by libthread_db. Returns a pointer to the thread local
- storage (or its descriptor). */
+/* Helper for ps_get_thread_area. Sets BASE_ADDR to a pointer to
+ the thread local storage (or its descriptor) and returns PS_OK
+ on success. Returns PS_ERR on failure. */
-ps_err_e
-ps_get_thread_area (const struct ps_prochandle *ph,
- lwpid_t lwpid, int idx, void **base)
+static ps_err_e
+x86_linux_get_thread_area (pid_t pid, void *addr, unsigned int *base_addr)
{
/* NOTE: cagney/2003-08-26: The definition of this buffer is found
in the kernel header <asm-i386/ldt.h>. It, after padding, is 4 x
@@ -873,19 +873,39 @@ ps_get_thread_area (const struct ps_prochandle *ph,
libthread_db calls this function without prompting (gdb
requesting tls base) I guess it needs info in there anyway. */
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 *) idx, (unsigned long) &desc) < 0)
+ if (ptrace (PTRACE_GET_THREAD_AREA, pid, addr, &desc) < 0)
return PS_ERR;
- *(int *)base = desc[1];
+ *base_addr = desc[1];
return PS_OK;
}
+
+/* Called by libthread_db. Returns a pointer to the thread local
+ storage (or its descriptor). */
+
+ps_err_e
+ps_get_thread_area (const struct ps_prochandle *ph,
+ lwpid_t lwpid, int idx, void **base)
+{
+ unsigned int base_addr;
+ ps_err_e result;
+
+ result = x86_linux_get_thread_area (lwpid, (void *) idx, &base_addr);
+
+ if (result == PS_OK)
+ *(int *) base = base_addr;
+
+ return result;
+}
/* The instruction for a GNU/Linux system call is: