From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 12456 invoked by alias); 3 Jul 2009 16:11:55 -0000 Received: (qmail 12445 invoked by uid 22791); 3 Jul 2009 16:11:54 -0000 X-SWARE-Spam-Status: No, hits=-1.4 required=5.0 tests=AWL,BAYES_00,MIME_QP_LONG_LINE X-Spam-Check-By: sourceware.org Received: from mailhost.u-strasbg.fr (HELO mailhost.u-strasbg.fr) (130.79.200.157) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 03 Jul 2009 16:11:47 +0000 Received: from baal.u-strasbg.fr (baal.u-strasbg.fr [IPv6:2001:660:2402::41]) by mailhost.u-strasbg.fr (8.14.2/jtpda-5.5pre1) with ESMTP id n63GBarb068413 ; Fri, 3 Jul 2009 18:11:36 +0200 (CEST) Received: from mailserver.u-strasbg.fr (ms2.u-strasbg.fr [IPv6:2001:660:2402:d::11]) by baal.u-strasbg.fr (8.14.0/jtpda-5.5pre1) with ESMTP id n63GBae8063396 ; Fri, 3 Jul 2009 18:11:36 +0200 (CEST) (envelope-from muller@ics.u-strasbg.fr) Received: from d620muller (www-ics.u-strasbg.fr [130.79.210.225]) (user=mullerp mech=LOGIN) by mailserver.u-strasbg.fr (8.14.3/jtpda-5.5pre1) with ESMTP id n63GBZQc039901 (version=TLSv1/SSLv3 cipher=RC4-MD5 bits=128 verify=NO) ; Fri, 3 Jul 2009 18:11:35 +0200 (CEST) (envelope-from muller@ics.u-strasbg.fr) From: "Pierre Muller" To: , Cc: "'Pedro Alves'" References: <000901c9f5ef$4ee06f10$eca14d30$@u-strasbg.fr> <20090626155254.GA15627@caradoc.them.org> <001f01c9fa5a$0e1297f0$2a37c7d0$@u-strasbg.fr> <831vp047u8.fsf@gnu.org> <20090701180419.GA8152@ednor.casa.cgf.cx> In-Reply-To: <20090701180419.GA8152@ednor.casa.cgf.cx> Subject: [RFC-v3] Add windows Thread Information Block Date: Fri, 03 Jul 2009 16:11:00 -0000 Message-ID: <003a01c9fbf8$f3e91610$dbbb4230$@u-strasbg.fr> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_NextPart_000_003B_01C9FC09.B771E610" Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2009-07/txt/msg00093.txt.bz2 This is a multi-part message in MIME format. ------=_NextPart_000_003B_01C9FC09.B771E610 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Content-length: 1104 Here is a new version of this patch: - It does add a convenience variable name "$_tlb" for "thread local base" as this is the only value that needs to be fetch especially. Maybe "_tib" is better, in the sense that it "talks" more to windows used debuggers? But this is really only a pointer and not the block itself. Any better idea? I tried to create a type that really fits the Windows OS layout, but as this structure is not documented really and has changed between OS version, there can be no assurance that all fields are OK in all versions... It works both native and remotely. I didn't check if it works OK, if endianess are different but the extra field in extract_unsigned_integer should take care of this. As Christopher reported problems trying to apply my previous version, I attach it this time, hoping that this will avoid troubles. Pedro, I didn't change the TARGET_OBJECT type, and I really want to know if this is really required, as it seems to be a lot of work and I can't see the benefit... Pierre Muller Pascal language support maintainer for GDB ------=_NextPart_000_003B_01C9FC09.B771E610 Content-Type: application/octet-stream; name="windows-tlb2.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="windows-tlb2.patch" Content-length: 29503 2009-07-03 Pierre Muller =0A= =0A= * windows-nat.c: Include target.h.=0A= (thread_info): Add THREAD_LOCAL_BASE field.=0A= (windows_add_thread): Add TLB argument of type 'void *'.=0A= (fake_create_process): Adapt windows_add_thread call.=0A= (get_windows_debug_event): Idem.=0A= (windows_xfer_partial): Handle TARGET_OBJECT_OSDATA type.=0A= (_initialize_windows_nat): Replace info_w32_cmdlist=0A= initialization by a call to init_w32_command_list.=0A= (info_w32_command, info_w32_cmdlist): Removed from here...=0A= to windows-tdep.c file.=0A= * windows-tdep.h (info_w32_cmdlist): Declare.=0A= (init_w32_command_list): New external function=20=0A= declaration.=09=0A= * windows-tdep.c: Add several headers.=0A= (info_w32_cmdlist): to here, made global.=0A= (thread_information_32): New struct.=0A= (thread_information_64): New struct.=0A= (TIB_NAME): New char array.=0A= (MAX_TIB32, MAX_TIB64, FULL_TIB_SIZE): New constants.=0A= (maint_display_all_tib): New static variable.=0A= (windows_get_tlb_type): New function.=0A= (tlb_value_read, tlb_value_write): New functions.=0A= (tlb_value_funcs): New static struct.=0A= (tlb_make_value): New function.=0A= (display_one_tib): New function.=0A= (display_tib): New function.=0A= (info_w32_command): Moved from windows-nat.c.=0A= (init_w32_command_list): New function.=0A= (_initialize_windows_tdep): New function.=0A= New "maint set/show show-all-tib" command=0A= New "$_tlb" internal variable.=0A= =09=0A= gdbserver/ChangeLog entry:=0A= =0A= 2009-07-01 Pierre Muller =0A= =0A= * gdbserver/win32-low.h (win32_thread_info): Add THREAD_LOCAL_BASE=20=0A= field.=0A= * gdbserver/win32-low.c (child_add_thread): Add TLB argument.=0A= (get_child_debug_event): Adapt to child_add_thread change.=0A= (win32_qxfer_osdata): New function.=0A= (win32_target_op): Set qxfer_osdata field to win32_qxfer_osdata.=0A= =0A= Index: windows-nat.c=0A= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0A= RCS file: /cvs/src/src/gdb/windows-nat.c,v=0A= retrieving revision 1.196=0A= diff -u -p -r1.196 windows-nat.c=0A= --- windows-nat.c 2 Jul 2009 17:21:07 -0000 1.196=0A= +++ windows-nat.c 3 Jul 2009 15:53:20 -0000=0A= @@ -57,6 +57,7 @@=0A= #include "solist.h"=0A= #include "solib.h"=0A= #include "xml-support.h"=0A= +#include "target.h"=0A= =20=0A= #include "i386-tdep.h"=0A= #include "i387-tdep.h"=0A= @@ -155,6 +156,7 @@ typedef struct thread_info_struct=0A= struct thread_info_struct *next;=0A= DWORD id;=0A= HANDLE h;=0A= + CORE_ADDR thread_local_base;=0A= char *name;=0A= int suspended;=0A= int reload_context;=0A= @@ -284,7 +286,7 @@ thread_rec (DWORD id, int get_context)=0A= =20=0A= /* Add a thread to the thread list. */=0A= static thread_info *=0A= -windows_add_thread (ptid_t ptid, HANDLE h)=0A= +windows_add_thread (ptid_t ptid, HANDLE h, void *tlb)=0A= {=0A= thread_info *th;=0A= DWORD id;=0A= @@ -299,6 +301,7 @@ windows_add_thread (ptid_t ptid, HANDLE=20=0A= th =3D XZALLOC (thread_info);=0A= th->id =3D id;=0A= th->h =3D h;=0A= + th->thread_local_base =3D (CORE_ADDR) (uintptr_t) tlb;=0A= th->next =3D thread_head.next;=0A= thread_head.next =3D th;=0A= add_thread (ptid);=0A= @@ -984,15 +987,6 @@ display_selectors (char * args, int from=0A= }=0A= }=0A= =20=0A= -static struct cmd_list_element *info_w32_cmdlist =3D NULL;=0A= -=0A= -static void=0A= -info_w32_command (char *args, int from_tty)=0A= -{=0A= - help_list (info_w32_cmdlist, "info w32 ", class_info, gdb_stdout);=0A= -}=0A= -=0A= -=0A= #define DEBUG_EXCEPTION_SIMPLE(x) if (debug_exceptions) \=0A= printf_unfiltered ("gdb: Target exception %s at %s\n", x, \=0A= host_address_to_string (\=0A= @@ -1181,9 +1175,11 @@ fake_create_process (void)=0A= /* We can not debug anything in that case. */=0A= }=0A= main_thread_id =3D current_event.dwThreadId;=0A= - current_thread =3D windows_add_thread (ptid_build (current_event.dwProce= ssId, 0,=0A= - current_event.dwThreadId),=0A= - current_event.u.CreateThread.hThread);=0A= + current_thread =3D windows_add_thread (=0A= + ptid_build (current_event.dwProcessId, 0,=0A= + current_event.dwThreadId),=0A= + current_event.u.CreateThread.hThread,=0A= + current_event.u.CreateThread.lpThreadLocalBase);=0A= return main_thread_id;=0A= }=0A= =20=0A= @@ -1357,7 +1353,8 @@ get_windows_debug_event (struct target_o=0A= retval =3D current_event.dwThreadId;=0A= th =3D windows_add_thread (ptid_build (current_event.dwProcessId, 0,= =0A= current_event.dwThreadId),=0A= - current_event.u.CreateThread.hThread);=0A= + current_event.u.CreateThread.hThread,=0A= + current_event.u.CreateThread.lpThreadLocalBase);=0A= break;=0A= =20=0A= case EXIT_THREAD_DEBUG_EVENT:=0A= @@ -1390,7 +1387,8 @@ get_windows_debug_event (struct target_o=0A= /* Add the main thread */=0A= th =3D windows_add_thread (ptid_build (current_event.dwProcessId, 0,= =0A= current_event.dwThreadId),=0A= - current_event.u.CreateProcessInfo.hThread);=0A= + current_event.u.CreateProcessInfo.hThread,=0A= + current_event.u.CreateProcessInfo.lpThreadLocalBase);=0A= retval =3D current_event.dwThreadId;=0A= break;=0A= =20=0A= @@ -2103,6 +2101,11 @@ windows_xfer_partial (struct target_ops=20=0A= const char *annex, gdb_byte *readbuf,=0A= const gdb_byte *writebuf, ULONGEST offset, LONGEST len)=0A= {=0A= + ULONGEST val;=0A= + thread_info *th;=0A= + char info_type[20];=0A= + char *type_end;=0A= +=0A= switch (object)=0A= {=0A= case TARGET_OBJECT_MEMORY:=0A= @@ -2114,6 +2117,31 @@ windows_xfer_partial (struct target_ops=20=0A= len, 1/*write*/, NULL, ops);=0A= return -1;=0A= =20=0A= + case TARGET_OBJECT_OSDATA:=0A= + memset (info_type, 0, sizeof (info_type));=0A= + val =3D 0;=0A= + sscanf (annex, "%s %llu", info_type, &val);=0A= + if (strcmp (info_type, "tlb") =3D=3D 0 && readbuf)=0A= + {=0A= + th =3D thread_rec (val, 0);=0A= + if (th =3D=3D NULL)=0A= + return -1;=0A= +=0A= + if (len =3D=3D 8)=0A= + {=0A= + uint64_t tlb =3D th->thread_local_base;=0A= + memcpy ((void *)readbuf, (void *) &tlb, len);=0A= + return len;=0A= + }=0A= + else if (len =3D=3D 4)=0A= + {=0A= + uint32_t tlb =3D th->thread_local_base;=0A= + memcpy ((void *)readbuf, (void *) &tlb, len);=0A= + return len;=0A= + }=0A= + }=0A= + return -1;=0A= +=0A= case TARGET_OBJECT_LIBRARIES:=0A= return windows_xfer_shared_libraries (ops, object, annex, readbuf,= =0A= writebuf, offset, len);=0A= @@ -2271,9 +2299,7 @@ Show whether to display kernel exception=0A= NULL, /* FIXME: i18n: */=0A= &setlist, &showlist);=0A= =20=0A= - add_prefix_cmd ("w32", class_info, info_w32_command,=0A= - _("Print information specific to Win32 debugging."),=0A= - &info_w32_cmdlist, "info w32 ", 0, &infolist);=0A= + init_w32_command_list ();=0A= =20=0A= add_cmd ("selector", class_info, display_selectors,=0A= _("Display selectors infos."),=0A= Index: windows-tdep.c=0A= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0A= RCS file: /cvs/src/src/gdb/windows-tdep.c,v=0A= retrieving revision 1.4=0A= diff -u -p -r1.4 windows-tdep.c=0A= --- windows-tdep.c 2 Jul 2009 17:21:07 -0000 1.4=0A= +++ windows-tdep.c 3 Jul 2009 15:53:22 -0000=0A= @@ -19,6 +19,356 @@=0A= #include "windows-tdep.h"=0A= #include "gdb_obstack.h"=0A= #include "xml-support.h"=0A= +#include "gdbarch.h"=0A= +#include "target.h"=0A= +#include "value.h"=0A= +#include "inferior.h"=0A= +#include "command.h"=0A= +#include "gdbcmd.h"=0A= +=0A= +struct cmd_list_element *info_w32_cmdlist;=0A= +=0A= +typedef struct thread_information_block_32=0A= + {=0A= + uint32_t current_seh; /* %fs:0x0000 */=0A= + uint32_t current_top_of_stack; /* %fs:0x0004 */=0A= + uint32_t current_bottom_of_stack; /* %fs:0x0008 */=0A= + uint32_t sub_system_tib; /* %fs:0x000c */=0A= + uint32_t fiber_data; /* %fs:0x0010 */=0A= + uint32_t arbitrary_data_slot; /* %fs:0x0014 */=0A= + uint32_t linear_address_tib; /* %fs:0x0018 */=0A= + uint32_t environment_pointer; /* %fs:0x001c */=0A= + uint32_t process_id; /* %fs:0x0020 */=0A= + uint32_t current_thread_id; /* %fs:0x0024 */=0A= + uint32_t thread_local_storage; /* %fs:0x0028 */=0A= + uint32_t active_rpc_handle; /* %fs:0x002c */=0A= + uint32_t process_environment_block; /* %fs:0x0030 */=0A= + uint32_t last_error_number; /* %fs:0x0034 */=0A= + }=0A= +thread_information_32;=0A= +=0A= +typedef struct thread_information_block_64=0A= + {=0A= + uint64_t current_seh; /* %gs:0x0000 */=0A= + uint64_t current_top_of_stack; /* %gs:0x0008 */=0A= + uint64_t current_bottom_of_stack; /* %gs:0x0010 */=0A= + uint64_t sub_system_tib; /* %gs:0x0018 */=0A= + uint64_t fiber_data; /* %gs:0x0020 */=0A= + uint64_t arbitrary_data_slot; /* %gs:0x0028 */=0A= + uint64_t linear_address_tib; /* %gs:0x0030 */=0A= + }=0A= +thread_information_64;=0A= +=0A= +=0A= +static const=0A= +char* TIB_NAME[] =3D=0A= + {=0A= + " current_seh ", /* %fs:0x0000 */=0A= + " current_top_of_stack ", /* %fs:0x0004 */=0A= + " current_bottom_of_stack ", /* %fs:0x0008 */=0A= + " sub_system_tib ", /* %fs:0x000c */=0A= + " fiber_data ", /* %fs:0x0010 */=0A= + " arbitrary_data_slot ", /* %fs:0x0014 */=0A= + " linear_address_tib ", /* %fs:0x0018 */=0A= + " environment_pointer ", /* %fs:0x001c */=0A= + " process_id ", /* %fs:0x0020 */=0A= + " current_thread_id ", /* %fs:0x0024 */=0A= + " thread_local_storage ", /* %fs:0x0028 */=0A= + " active_rpc_handle ", /* %fs:0x002c */=0A= + " process_environment_block ", /* %fs:0x0030 */=0A= + " last_error_number " /* %fs:0x0034 */=0A= + };=0A= +=0A= +static const int=0A= +MAX_TIB32 =3D sizeof (thread_information_32) / sizeof (uint32_t);=0A= +static const int=0A= +MAX_TIB64 =3D sizeof (thread_information_64) / sizeof (uint64_t);=0A= +static const int=0A= +FULL_TIB_SIZE =3D 0x1000;=0A= +=0A= +static int maint_display_all_tib =3D 0;=0A= +=0A= +/* Define ThreadLocalBase pointer type */=0A= +struct type *=0A= +windows_get_tlb_type (struct gdbarch *gdbarch)=0A= +{=0A= + struct type *dword_ptr_type, *void_ptr_type;=0A= + struct type *peb_ldr_type, *peb_ldr_ptr_type;=0A= + struct type *peb_type, *peb_ptr_type, *list_type, *list_ptr_type;=0A= + struct type *module_list_ptr_type;=0A= + struct type *tib_type, *seh_type, *tib_ptr_type, *seh_ptr_type;=0A= +=0A= + dword_ptr_type =3D arch_integer_type (gdbarch, gdbarch_ptr_bit (gdbarch)= ,=0A= + 1, "DWORD_PTR");=0A= + void_ptr_type =3D lookup_pointer_type (builtin_type (gdbarch)->builtin_v= oid);=0A= +=0A= + /* list entry */=0A= +=0A= + list_type =3D arch_composite_type (gdbarch, NULL, TYPE_CODE_STRUCT);=0A= + TYPE_NAME (list_type) =3D xstrdup ("list");=0A= +=0A= + list_ptr_type =3D arch_type (gdbarch, TYPE_CODE_PTR,=0A= + TYPE_LENGTH (void_ptr_type), NULL);=0A= +=0A= + module_list_ptr_type =3D void_ptr_type;=0A= +=0A= + append_composite_type_field (list_type, "forward_list", module_list_ptr_= type);=0A= + append_composite_type_field (list_type, "backward_list",=0A= + module_list_ptr_type);=0A= +=0A= + /* Structured Exception Handler */=0A= +=0A= + seh_type =3D arch_composite_type (gdbarch, NULL, TYPE_CODE_STRUCT);=0A= + TYPE_NAME (seh_type) =3D xstrdup ("seh");=0A= +=0A= + seh_ptr_type =3D arch_type (gdbarch, TYPE_CODE_PTR,=0A= + TYPE_LENGTH (void_ptr_type), NULL);=0A= + TYPE_TARGET_TYPE (seh_ptr_type) =3D seh_type;=0A= +=0A= + append_composite_type_field (seh_type, "next_seh", seh_ptr_type);=0A= + append_composite_type_field (seh_type, "handler", void_ptr_type);=0A= +=0A= + /* struct _PEB_LDR_DATA */=0A= + /* FIXME: 64bit layout is unknown. */=0A= + peb_ldr_type =3D arch_composite_type (gdbarch, NULL, TYPE_CODE_STRUCT);= =0A= + TYPE_NAME (peb_ldr_type) =3D xstrdup ("peb_ldr_data");=0A= +=0A= + append_composite_type_field (peb_ldr_type, "length", dword_ptr_type);=0A= + append_composite_type_field (peb_ldr_type, "initialized", dword_ptr_type= );=0A= + append_composite_type_field (peb_ldr_type, "ss_handle", void_ptr_type);= =0A= + append_composite_type_field (peb_ldr_type, "in_load_order", list_type);= =0A= + append_composite_type_field (peb_ldr_type, "in_memory_order", list_type)= ;=0A= + append_composite_type_field (peb_ldr_type, "in_init_order", list_type);= =0A= + append_composite_type_field (peb_ldr_type, "entry_in_progress",=0A= + void_ptr_type);=0A= + peb_ldr_ptr_type =3D arch_type (gdbarch, TYPE_CODE_PTR,=0A= + TYPE_LENGTH (void_ptr_type), NULL);=0A= + TYPE_TARGET_TYPE (peb_ldr_ptr_type) =3D peb_ldr_type;=0A= +=0A= +=0A= + /* struct process environment block */=0A= + peb_type =3D arch_composite_type (gdbarch, NULL, TYPE_CODE_STRUCT);=0A= + TYPE_NAME (peb_type) =3D xstrdup ("peb");=0A= +=0A= + /* 4 first byte contain several flags. */=0A= + /* FIXME: 64bit layout is unknown. */=0A= + append_composite_type_field (peb_type, "flags", dword_ptr_type);=0A= + append_composite_type_field (peb_type, "mutant", void_ptr_type);=0A= + append_composite_type_field (peb_type, "image_base_address", void_ptr_ty= pe);=0A= + append_composite_type_field (peb_type, "ldr", peb_ldr_ptr_type);=0A= + append_composite_type_field (peb_type, "process_parameters", void_ptr_ty= pe);=0A= + append_composite_type_field (peb_type, "sub_system_data", void_ptr_type)= ;=0A= + append_composite_type_field (peb_type, "process_heap", void_ptr_type);= =0A= + append_composite_type_field (peb_type, "fast_peb_lock", void_ptr_type);= =0A= + peb_ptr_type =3D arch_type (gdbarch, TYPE_CODE_PTR,=0A= + TYPE_LENGTH (void_ptr_type), NULL);=0A= + TYPE_TARGET_TYPE (peb_ptr_type) =3D peb_type;=0A= +=0A= +=0A= + /* struct thread information block */=0A= + tib_type =3D arch_composite_type (gdbarch, NULL, TYPE_CODE_STRUCT);=0A= + TYPE_NAME (tib_type) =3D xstrdup ("tib");=0A= +=0A= + /* uint32_t current_seh; %fs:0x0000 */=0A= + append_composite_type_field (tib_type, "current_seh", seh_ptr_type);=0A= + /* uint32_t current_top_of_stack; %fs:0x0004 */=0A= + append_composite_type_field (tib_type, "current_top_of_stack", void_ptr_= type);=0A= + /* uint32_t current_bottom_of_stack; %fs:0x0008 */=0A= + append_composite_type_field (tib_type, "current_bottom_of_stack",=0A= + void_ptr_type);=0A= + /* uint32_t sub_system_tib; %fs:0x000c */=0A= + append_composite_type_field (tib_type, "sub_system_tib", void_ptr_type);= =0A= +=0A= + /* uint32_t fiber_data; %fs:0x0010 */=0A= + append_composite_type_field (tib_type, "fiber_data", void_ptr_type);=0A= + /* uint32_t arbitrary_data_slot; %fs:0x0014 */=0A= + append_composite_type_field (tib_type, "arbitrary_data_slot", void_ptr_t= ype);=0A= + /* uint32_t linear_address_tib; %fs:0x0018 */=0A= + append_composite_type_field (tib_type, "linear_address_tib", void_ptr_ty= pe);=0A= + /* uint32_t environment_pointer; %fs:0x001c */=0A= + append_composite_type_field (tib_type, "environment_pointer", void_ptr_t= ype);=0A= + /* uint32_t process_id; %fs:0x0020 */=0A= + append_composite_type_field (tib_type, "process_id", dword_ptr_type);=0A= + /* uint32_t current_thread_id; %fs:0x0024 */=0A= + append_composite_type_field (tib_type, "thread_id", dword_ptr_type);=0A= + /* uint32_t thread_local_storage; %fs:0x0028 */=0A= + append_composite_type_field (tib_type, "thread_local_storage", void_ptr_= type);=0A= + /* uint32_t active_rpc_handle; %fs:0x002c */=0A= + append_composite_type_field (tib_type, "active_rpc_handle", dword_ptr_ty= pe);=0A= + /* uint32_t process_environment_block; %fs:0x0030 */=0A= + append_composite_type_field (tib_type, "process_environment_block",=0A= + peb_ptr_type);=0A= + /* uint32_t last_error_number; %fs:0x0034 */=0A= + append_composite_type_field (tib_type, "last_error_number", dword_ptr_ty= pe);=0A= +=0A= + tib_ptr_type =3D arch_type (gdbarch, TYPE_CODE_PTR,=0A= + TYPE_LENGTH (void_ptr_type), NULL);=0A= + TYPE_TARGET_TYPE (tib_ptr_type) =3D tib_type;=0A= +=0A= + return tib_ptr_type;=0A= +}=0A= +/* The $_tlb convenience variable is a bit special. We don't know=0A= + for sure the type of the value until we actually have a chance to=0A= + fetch the data. The type can change depending on gdbarch, so it it=0A= + also dependent on which thread you have selected.=0A= +=0A= + 1. making $_tlb be an internalvar that creates a new value on=0A= + access.=0A= +=0A= + 2. making the value of $_tlbi be an lval_computed value. */=0A= +=0A= +/* This function implements the lval_computed support for reading a=0A= + $_tlb value. */=0A= +=0A= +static void=0A= +tlb_value_read (struct value *v)=0A= +{=0A= + LONGEST transferred;=0A= + char annex[20];=0A= + /* This needs to be changed if multi-process support is added. */=0A= + strcpy (annex, "tlb ");=0A= + strcat (annex, pulongest (ptid_get_tid (inferior_ptid)));=0A= +=0A= + transferred =3D=0A= + target_read (¤t_target, TARGET_OBJECT_OSDATA,=0A= + annex,=0A= + value_contents_all_raw (v),=0A= + value_offset (v),=0A= + TYPE_LENGTH (value_type (v)));=0A= +=20=0A= + if (transferred !=3D TYPE_LENGTH (value_type (v)))=0A= + error (_("Unable to read tlb"));=0A= +}=0A= +=0A= +/* This function implements the lval_computed support for writing a=0A= + $_siginfo value. */=0A= +=0A= +static void=0A= +tlb_value_write (struct value *v, struct value *fromval)=0A= +{=0A= + error (_("Impossible to change tlb"));=0A= +}=0A= +=0A= +static struct lval_funcs tlb_value_funcs =3D=0A= + {=0A= + tlb_value_read,=0A= + tlb_value_write=0A= + };=0A= +=0A= +=0A= +/* Return a new value with the correct type for the tlb object of=0A= + the current thread using architecture GDBARCH. Return a void value=0A= + if there's no object available. */=0A= +=0A= +static struct value *=0A= +tlb_make_value (struct gdbarch *gdbarch, struct internalvar *var)=0A= +{=0A= + if (target_has_stack=0A= + && !ptid_equal (inferior_ptid, null_ptid))=0A= + {=0A= + struct type *type =3D windows_get_tlb_type (gdbarch);=0A= + return allocate_computed_value (type, &tlb_value_funcs, NULL);=0A= + }=0A= +=0A= + return allocate_value (builtin_type (gdbarch)->builtin_void);=0A= +}=0A= +=0A= +=0A= +/* Display thread information block of a given thread. */=0A= +static int=0A= +display_one_tib (ULONGEST ThreadId)=0A= +{=0A= +#define PTID_STRING_SIZE 40=0A= + char annex[PTID_STRING_SIZE];=0A= + char *annex_end =3D annex + PTID_STRING_SIZE;=0A= + gdb_byte *tib =3D NULL;=0A= + gdb_byte *index;=0A= + CORE_ADDR thread_local_base;=0A= + ULONGEST i, val, max, max_name, size, tib_size;=0A= + ULONGEST sizeof_ptr =3D gdbarch_ptr_bit (target_gdbarch);=0A= + enum bfd_endian byte_order =3D gdbarch_byte_order (target_gdbarch);=0A= +=0A= + if (sizeof_ptr =3D=3D 64)=0A= + {=0A= + size =3D sizeof (uint64_t);=0A= + tib_size =3D sizeof (thread_information_64);=0A= + max =3D MAX_TIB64;=0A= + }=0A= + else=0A= + {=0A= + size =3D sizeof (uint32_t);=0A= + tib_size =3D sizeof (thread_information_32);=0A= + max =3D MAX_TIB32;=0A= + }=0A= +=0A= + max_name =3D max;=0A= +=0A= + if (maint_display_all_tib)=0A= + {=0A= + tib_size =3D FULL_TIB_SIZE;=0A= + max =3D tib_size / size;=0A= + }=0A= +=20=20=0A= + tib =3D alloca (tib_size);=0A= +=0A= + /* This needs to be changed if multi-process support is added. */=0A= + strcpy (annex, "tlb ");=0A= + strcat (annex, pulongest (ThreadId));=0A= +=0A= + if (target_read (¤t_target, TARGET_OBJECT_OSDATA,=0A= + annex, tib, 0, size) !=3D size)=0A= + {=0A= + printf_filtered ("Unable to get thread local base for ThreadId %s\n"= ,=0A= + pulongest (ThreadId));=0A= + return -1;=0A= + }=0A= + thread_local_base =3D extract_unsigned_integer (tib, size, byte_order);= =0A= +=0A= + if (target_read (¤t_target, TARGET_OBJECT_MEMORY,=0A= + annex, tib, thread_local_base, tib_size) !=3D tib_size)=0A= + {=0A= + printf_filtered ("Unable to read thread information block for Thread= Id %s at address %s\n",=0A= + pulongest (ThreadId), paddress (target_gdbarch, thread_local_base));=0A= + return -1;=0A= + }=0A= +=0A= + printf_filtered ("Thread Information Block %s at %s\n",=0A= + pulongest (ThreadId),=0A= + paddress (target_gdbarch, thread_local_base));=0A= +=0A= + index =3D (gdb_byte *) tib;=0A= +=0A= + /* All fields have the size of a pointer, this allows to iterate=20=0A= + using the same for loop for both layouts. */=0A= + for (i =3D 0; i < max; i++)=0A= + {=0A= + val =3D extract_unsigned_integer (index, size, byte_order);=0A= + if (i < max_name)=0A= + printf_filtered ("%s is 0x%s\n", TIB_NAME [i], phex (val, size));=0A= + else if (val !=3D 0)=0A= + printf_filtered ("TIB[0x%s] is 0x%s\n", phex (i*size, 2),=0A= + phex (val, size));=0A= + index +=3D size;=0A= + }=20=0A= + return 1;=20=20=0A= +}=0A= +=0A= +/* Display thread information block of a thread specified by ARGS.=0A= + If ARGS is empty, display thread information block of current_thread=0A= + if current_thread is non NULL.=0A= + Otherwise ARGS is parsed and converted to a integer that should=0A= + be the windows ThreadID (not the internal GDB thread ID). */=0A= +static void=0A= +display_tib (char * args, int from_tty)=0A= +{=0A= + if (args)=0A= + {=0A= + ULONGEST id =3D (ULONGEST) parse_and_eval_long (args);=0A= + display_one_tib (id);=0A= + }=0A= + else if (!ptid_equal (inferior_ptid, null_ptid))=0A= + display_one_tib (ptid_get_tid (inferior_ptid));=0A= +}=0A= =20=0A= void=0A= windows_xfer_shared_library (const char* so_name, CORE_ADDR load_addr,=0A= @@ -36,3 +386,51 @@ windows_xfer_shared_library (const char*=0A= obstack_grow_str (obstack, paddress (gdbarch, load_addr + 0x1000));=0A= obstack_grow_str (obstack, "\"/>");=0A= }=0A= +=0A= +static void=0A= +info_w32_command (char *args, int from_tty)=0A= +{=0A= + help_list (info_w32_cmdlist, "info w32 ", class_info, gdb_stdout);=0A= +}=0A= +=0A= +static int w32_prefix_command_valid =3D 0;=0A= +void=0A= +init_w32_command_list (void)=0A= +{=0A= + if (!w32_prefix_command_valid)=0A= + {=0A= + add_prefix_cmd ("w32", class_info, info_w32_command,=0A= + _("Print information specific to Win32 debugging."),=0A= + &info_w32_cmdlist, "info w32 ", 0, &infolist);=0A= + w32_prefix_command_valid =3D 1;=0A= + }=0A= +}=0A= +=0A= +void=0A= +_initialize_windows_tdep (void)=0A= +{=0A= + init_w32_command_list ();=0A= + add_cmd ("thread-information-block", class_info, display_tib,=0A= + _("Display thread information block."),=0A= + &info_w32_cmdlist);=0A= + add_alias_cmd ("tib", "thread-information-block", class_info, 1,=0A= + &info_w32_cmdlist);=0A= +=0A= + add_setshow_boolean_cmd ("show-all-tib", class_maintenance,=0A= + &maint_display_all_tib, _("\=0A= +Set whether to display all non-zero fields of thread information block."),= _("\=0A= +Show whether to display all non-zero fields of thread information block.")= , _("\=0A= +Use \"on\" to enable, \"off\" to disable.\n\=0A= +If enabled, all non-zero fields of thread information block are displayed,= \n\=0A= +even if its meaning is unknown."),=0A= + NULL,=0A= + NULL,=0A= + &maintenance_set_cmdlist,=0A= + &maintenance_show_cmdlist);=0A= +=0A= + /* Explicitly create without lookup, since that tries to create a=0A= + value with a void typed value, and when we get here, gdbarch=0A= + isn't initialized yet. At this point, we're quite sure there=0A= + isn't another convenience variable of the same name. */=0A= + create_internalvar_type_lazy ("_tlb", tlb_make_value);=0A= +}=0A= Index: windows-tdep.h=0A= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0A= RCS file: /cvs/src/src/gdb/windows-tdep.h,v=0A= retrieving revision 1.3=0A= diff -u -p -r1.3 windows-tdep.h=0A= --- windows-tdep.h 2 Jul 2009 17:21:07 -0000 1.3=0A= +++ windows-tdep.h 3 Jul 2009 15:53:22 -0000=0A= @@ -21,6 +21,10 @@=0A= struct obstack;=0A= struct gdbarch;=0A= =20=0A= +extern struct cmd_list_element *info_w32_cmdlist;=0A= +=0A= +extern void init_w32_command_list (void);=0A= +=0A= extern void windows_xfer_shared_library (const char* so_name,=0A= CORE_ADDR load_addr,=0A= struct gdbarch *gdbarch,=0A= Index: gdbserver/win32-low.c=0A= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0A= RCS file: /cvs/src/src/gdb/gdbserver/win32-low.c,v=0A= retrieving revision 1.37=0A= diff -u -p -r1.37 win32-low.c=0A= --- gdbserver/win32-low.c 30 Jun 2009 16:35:25 -0000 1.37=0A= +++ gdbserver/win32-low.c 3 Jul 2009 15:53:23 -0000=0A= @@ -175,7 +175,7 @@ thread_rec (ptid_t ptid, int get_context=0A= =20=0A= /* Add a thread to the thread list. */=0A= static win32_thread_info *=0A= -child_add_thread (DWORD pid, DWORD tid, HANDLE h)=0A= +child_add_thread (DWORD pid, DWORD tid, HANDLE h, void *tlb)=0A= {=0A= win32_thread_info *th;=0A= ptid_t ptid =3D ptid_build (pid, tid, 0);=0A= @@ -186,6 +186,7 @@ child_add_thread (DWORD pid, DWORD tid,=20=0A= th =3D xcalloc (1, sizeof (*th));=0A= th->tid =3D tid;=0A= th->h =3D h;=0A= + th->thread_local_base =3D (CORE_ADDR) (uintptr_t) tlb;=0A= =20=0A= add_thread (ptid, th);=0A= set_inferior_regcache_data ((struct thread_info *)=0A= @@ -1427,7 +1428,8 @@ get_child_debug_event (struct target_wai=0A= /* Record the existence of this thread. */=0A= child_add_thread (current_event.dwProcessId,=0A= current_event.dwThreadId,=0A= - current_event.u.CreateThread.hThread);=0A= + current_event.u.CreateThread.hThread,=0A= + current_event.u.CreateThread.lpThreadLocalBase);=0A= break;=0A= =20=0A= case EXIT_THREAD_DEBUG_EVENT:=0A= @@ -1455,7 +1457,8 @@ get_child_debug_event (struct target_wai=0A= /* Add the main thread. */=0A= child_add_thread (current_event.dwProcessId,=0A= main_thread_id,=0A= - current_event.u.CreateProcessInfo.hThread);=0A= + current_event.u.CreateProcessInfo.hThread,=0A= + current_event.u.CreateProcessInfo.lpThreadLocalBase);=0A= =20=0A= ourstatus->value.related_pid =3D debug_event_ptid (¤t_event);= =0A= #ifdef _WIN32_WCE=0A= @@ -1723,6 +1726,42 @@ wince_hostio_last_error (char *buf)=0A= }=0A= #endif=0A= =20=0A= +/* Read/Write Windows OS information. */=0A= +int=0A= +win32_qxfer_osdata (const char *info_type,=0A= + unsigned char *readbuf, unsigned const char *writebuf,=0A= + CORE_ADDR offset, int len)=0A= +=0A= +{=0A= + if (strncmp (info_type, "tlb ", 4) =3D=3D 0 && readbuf)=0A= + {=0A= + unsigned long long tid;=0A= + char type_name[20];=0A= + ptid_t ptid;=0A= + win32_thread_info *th;=0A= + sscanf (info_type, "%s %llu", type_name, &tid);=0A= + ptid =3D ptid_build (current_process_id, tid, 0);=0A= + th =3D thread_rec (ptid, 0);=0A= + if (th =3D=3D NULL)=0A= + return 0;=0A= + len--;=0A= + if (len =3D=3D 8)=0A= + {=0A= + uint64_t tlb =3D th->thread_local_base;=0A= + memcpy (readbuf, &tlb, len);=0A= + return len;=0A= + }=0A= + else if (len =3D=3D 4)=0A= + {=0A= + uint32_t tlb =3D th->thread_local_base;=0A= + memcpy (readbuf, &tlb, len);=0A= + return len;=0A= + }=0A= + }=0A= + return -1;=0A= +}=0A= +=0A= +=0A= static struct target_ops win32_target_ops =3D {=0A= win32_create_inferior,=0A= win32_attach,=0A= @@ -1751,6 +1790,7 @@ static struct target_ops win32_target_op=0A= #else=0A= hostio_last_error_from_errno,=0A= #endif=0A= + win32_qxfer_osdata,=0A= };=0A= =20=0A= /* Initialize the Win32 backend. */=0A= Index: gdbserver/win32-low.h=0A= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0A= RCS file: /cvs/src/src/gdb/gdbserver/win32-low.h,v=0A= retrieving revision 1.10=0A= diff -u -p -r1.10 win32-low.h=0A= --- gdbserver/win32-low.h 30 Jun 2009 16:35:25 -0000 1.10=0A= +++ gdbserver/win32-low.h 3 Jul 2009 15:53:23 -0000=0A= @@ -28,6 +28,9 @@ typedef struct win32_thread_info=0A= /* The handle to the thread. */=0A= HANDLE h;=0A= =20=0A= + /* Thread Information Block address. */=0A= + CORE_ADDR thread_local_base;=0A= +=0A= /* Non zero if SuspendThread was called on this thread. */=0A= int suspended;=0A= =20=0A= ------=_NextPart_000_003B_01C9FC09.B771E610--