diff mbox

Cache the Thread Local Base pointer type in the gdbarch

Message ID 20200209164150.43386-1-ssbssa@yahoo.de
State New
Headers show

Commit Message

Doug Evans via gdb-patches Feb. 9, 2020, 4:41 p.m. UTC
gdb/ChangeLog:

2020-02-09  Hannes Domani  <ssbssa@yahoo.de>

	* windows-tdep.c (struct windows_gdbarch_data): Add tib_ptr_type.
	(windows_get_tlb_type): Use windows_gdbarch_data->tib_ptr_type.
---
 gdb/windows-tdep.c | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)

Comments

Luis Machado Feb. 10, 2020, 10:03 p.m. UTC | #1
Hi,

On 2/9/20 1:41 PM, Hannes Domani via gdb-patches wrote:
> gdb/ChangeLog:
> 
> 2020-02-09  Hannes Domani  <ssbssa@yahoo.de>
> 
> 	* windows-tdep.c (struct windows_gdbarch_data): Add tib_ptr_type.
> 	(windows_get_tlb_type): Use windows_gdbarch_data->tib_ptr_type.
> ---
>   gdb/windows-tdep.c | 15 +++++++--------
>   1 file changed, 7 insertions(+), 8 deletions(-)
> 
> diff --git a/gdb/windows-tdep.c b/gdb/windows-tdep.c
> index 6eef476fb5..2efd2f0d7e 100644
> --- a/gdb/windows-tdep.c
> +++ b/gdb/windows-tdep.c
> @@ -162,6 +162,7 @@ static struct gdbarch_data *windows_gdbarch_data_handle;
>   struct windows_gdbarch_data
>   {
>     struct type *siginfo_type;
> +  struct type *tib_ptr_type;
>   };
>   
>   /* Allocate windows_gdbarch_data for an arch.  */

 From someone that doesn't know the inner workings of Windows, i was 
slightly confused with the change from tlb to tib. But i see what it is 
now. Maybe worth adding a comment mentioning what it is that you're caching.

> @@ -186,8 +187,7 @@ get_windows_gdbarch_data (struct gdbarch *gdbarch)
>   static struct type *
>   windows_get_tlb_type (struct gdbarch *gdbarch)
>   {
> -  static struct gdbarch *last_gdbarch = NULL;
> -  static struct type *last_tlb_type = NULL;
> +  struct windows_gdbarch_data *windows_gdbarch_data;
>     struct type *dword_ptr_type, *dword32_type, *void_ptr_type;
>     struct type *peb_ldr_type, *peb_ldr_ptr_type;
>     struct type *peb_type, *peb_ptr_type, *list_type;
> @@ -196,10 +196,10 @@ windows_get_tlb_type (struct gdbarch *gdbarch)
>     struct type *word_type, *wchar_type, *wchar_ptr_type;
>     struct type *uni_str_type, *rupp_type, *rupp_ptr_type;
>   
> -  /* Do not rebuild type if same gdbarch as last time.  */
> -  if (last_tlb_type && last_gdbarch == gdbarch)
> -    return last_tlb_type;
> -
> +  windows_gdbarch_data = get_windows_gdbarch_data (gdbarch);
> +  if (windows_gdbarch_data->tib_ptr_type != NULL)
> +    return windows_gdbarch_data->tib_ptr_type;
> +

NULL should be nullptr now that we've switched to C++, since we're 
patching this code up.

>     dword_ptr_type = arch_integer_type (gdbarch, gdbarch_ptr_bit (gdbarch),
>   				 1, "DWORD_PTR");
>     dword32_type = arch_integer_type (gdbarch, 32,
> @@ -369,8 +369,7 @@ windows_get_tlb_type (struct gdbarch *gdbarch)
>   			    NULL);
>     TYPE_TARGET_TYPE (tib_ptr_type) = tib_type;
>   
> -  last_tlb_type = tib_ptr_type;
> -  last_gdbarch = gdbarch;
> +  windows_gdbarch_data->tib_ptr_type = tib_ptr_type;
>   
>     return tib_ptr_type;
>   }
>
diff mbox

Patch

diff --git a/gdb/windows-tdep.c b/gdb/windows-tdep.c
index 6eef476fb5..2efd2f0d7e 100644
--- a/gdb/windows-tdep.c
+++ b/gdb/windows-tdep.c
@@ -162,6 +162,7 @@  static struct gdbarch_data *windows_gdbarch_data_handle;
 struct windows_gdbarch_data
 {
   struct type *siginfo_type;
+  struct type *tib_ptr_type;
 };
 
 /* Allocate windows_gdbarch_data for an arch.  */
@@ -186,8 +187,7 @@  get_windows_gdbarch_data (struct gdbarch *gdbarch)
 static struct type *
 windows_get_tlb_type (struct gdbarch *gdbarch)
 {
-  static struct gdbarch *last_gdbarch = NULL;
-  static struct type *last_tlb_type = NULL;
+  struct windows_gdbarch_data *windows_gdbarch_data;
   struct type *dword_ptr_type, *dword32_type, *void_ptr_type;
   struct type *peb_ldr_type, *peb_ldr_ptr_type;
   struct type *peb_type, *peb_ptr_type, *list_type;
@@ -196,10 +196,10 @@  windows_get_tlb_type (struct gdbarch *gdbarch)
   struct type *word_type, *wchar_type, *wchar_ptr_type;
   struct type *uni_str_type, *rupp_type, *rupp_ptr_type;
 
-  /* Do not rebuild type if same gdbarch as last time.  */
-  if (last_tlb_type && last_gdbarch == gdbarch)
-    return last_tlb_type;
-  
+  windows_gdbarch_data = get_windows_gdbarch_data (gdbarch);
+  if (windows_gdbarch_data->tib_ptr_type != NULL)
+    return windows_gdbarch_data->tib_ptr_type;
+
   dword_ptr_type = arch_integer_type (gdbarch, gdbarch_ptr_bit (gdbarch),
 				 1, "DWORD_PTR");
   dword32_type = arch_integer_type (gdbarch, 32,
@@ -369,8 +369,7 @@  windows_get_tlb_type (struct gdbarch *gdbarch)
 			    NULL);
   TYPE_TARGET_TYPE (tib_ptr_type) = tib_type;
 
-  last_tlb_type = tib_ptr_type;
-  last_gdbarch = gdbarch;
+  windows_gdbarch_data->tib_ptr_type = tib_ptr_type;
 
   return tib_ptr_type;
 }