[RFC,10/13] {amd64, i386}-fbsd-tdep: Include NT_X86_CPUID notes in core dumps from gcore

Message ID 20231009183617.24862-11-jhb@FreeBSD.org
State New
Headers
Series Proposal for a new NT_X86_CPUID core dump note |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 success Testing passed
linaro-tcwg-bot/tcwg_gdb_build--master-arm success Testing passed
linaro-tcwg-bot/tcwg_gdb_check--master-aarch64 success Testing passed
linaro-tcwg-bot/tcwg_gdb_check--master-arm success Testing passed

Commit Message

John Baldwin Oct. 9, 2023, 6:36 p.m. UTC
  Override the gdbarch make_corefile_notes method for the FreeBSD x86
arches with a new function that calls fbsd_make_corefile_notes and
x86_elf_make_cpuid_note to generate the core dump notes.
---
 gdb/amd64-fbsd-tdep.c |  1 +
 gdb/i386-fbsd-tdep.c  | 15 +++++++++++++++
 gdb/i386-fbsd-tdep.h  |  7 +++++++
 3 files changed, 23 insertions(+)
  

Comments

Lancelot SIX Oct. 16, 2023, 9:31 a.m. UTC | #1
Hi,

Just a forating nit below (again, feel free to discard as this is a RFC
series)

On Mon, Oct 09, 2023 at 11:36:12AM -0700, John Baldwin wrote:
> Override the gdbarch make_corefile_notes method for the FreeBSD x86
> arches with a new function that calls fbsd_make_corefile_notes and
> x86_elf_make_cpuid_note to generate the core dump notes.
> ---
>  gdb/amd64-fbsd-tdep.c |  1 +
>  gdb/i386-fbsd-tdep.c  | 15 +++++++++++++++
>  gdb/i386-fbsd-tdep.h  |  7 +++++++
>  3 files changed, 23 insertions(+)
> 
> diff --git a/gdb/i386-fbsd-tdep.c b/gdb/i386-fbsd-tdep.c
> index 1789f3921fd..810ecc90df1 100644
> --- a/gdb/i386-fbsd-tdep.c
> +++ b/gdb/i386-fbsd-tdep.c
> @@ -26,6 +26,7 @@
>  #include "tramp-frame.h"
>  #include "i386-fbsd-tdep.h"
>  
> +#include "x86-tdep.h"
>  #include "i386-tdep.h"
>  #include "i387-tdep.h"
>  #include "fbsd-tdep.h"
> @@ -370,6 +371,19 @@ i386fbsd_get_thread_local_address (struct gdbarch *gdbarch, ptid_t ptid,
>    return fbsd_get_thread_local_address (gdbarch, dtv_addr, lm_addr, offset);
>  }
>  
> +/* See i386-fbsd-tdep.h.  */
> +
> +gdb::unique_xmalloc_ptr<char>
> +i386_fbsd_make_corefile_notes (struct gdbarch *gdbarch, bfd *obfd,
> +			       int *note_size)
> +{
> +  gdb::unique_xmalloc_ptr<char> note_data =
> +    fbsd_make_corefile_notes (gdbarch, obfd, note_size);

In GDB's coding style, the linebreak should be before the "=".

Best,
Lancelot.

> +
> +  x86_elf_make_cpuid_note (obfd, &note_data, note_size);
> +  return note_data;
> +}
> +
>  static void
>  i386fbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
>  {
> @@ -403,6 +417,7 @@ i386fbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
>  
>    set_gdbarch_core_read_description (gdbarch,
>  				     i386fbsd_core_read_description);
> +  set_gdbarch_make_corefile_notes (gdbarch, i386_fbsd_make_corefile_notes);
>  
>    /* FreeBSD uses SVR4-style shared libraries.  */
>    set_solib_svr4_fetch_link_map_offsets
> diff --git a/gdb/i386-fbsd-tdep.h b/gdb/i386-fbsd-tdep.h
> index c49cb1eba68..fc7bb1c521d 100644
> --- a/gdb/i386-fbsd-tdep.h
> +++ b/gdb/i386-fbsd-tdep.h
> @@ -40,6 +40,13 @@ bool i386_fbsd_core_read_x86_xsave_layout (struct gdbarch *gdbarch,
>     matches the layout on Linux.  */
>  #define I386_FBSD_XSAVE_XCR0_OFFSET 464
>  
> +/* Create appropriate note sections for a corefile, returning them in
> +   allocated memory.  Extends fbsd_make_corefile_notes to add a
> +   NT_X86_CPUID note.  */
> +
> +gdb::unique_xmalloc_ptr<char> i386_fbsd_make_corefile_notes
> +(struct gdbarch *gdbarch, bfd *obfd, int *note_size);
> +
>  extern const struct regset i386_fbsd_gregset;
>  
>  #endif /* i386-fbsd-tdep.h */
> -- 
> 2.41.0
>
  
John Baldwin Oct. 17, 2023, 12:26 a.m. UTC | #2
On 10/16/23 2:31 AM, Lancelot SIX wrote:
> Hi,
> 
> Just a forating nit below (again, feel free to discard as this is a RFC
> series)
> 
> On Mon, Oct 09, 2023 at 11:36:12AM -0700, John Baldwin wrote:
>> Override the gdbarch make_corefile_notes method for the FreeBSD x86
>> arches with a new function that calls fbsd_make_corefile_notes and
>> x86_elf_make_cpuid_note to generate the core dump notes.
>> ---
>>   gdb/amd64-fbsd-tdep.c |  1 +
>>   gdb/i386-fbsd-tdep.c  | 15 +++++++++++++++
>>   gdb/i386-fbsd-tdep.h  |  7 +++++++
>>   3 files changed, 23 insertions(+)
>>
>> diff --git a/gdb/i386-fbsd-tdep.c b/gdb/i386-fbsd-tdep.c
>> index 1789f3921fd..810ecc90df1 100644
>> --- a/gdb/i386-fbsd-tdep.c
>> +++ b/gdb/i386-fbsd-tdep.c
>> @@ -26,6 +26,7 @@
>>   #include "tramp-frame.h"
>>   #include "i386-fbsd-tdep.h"
>>   
>> +#include "x86-tdep.h"
>>   #include "i386-tdep.h"
>>   #include "i387-tdep.h"
>>   #include "fbsd-tdep.h"
>> @@ -370,6 +371,19 @@ i386fbsd_get_thread_local_address (struct gdbarch *gdbarch, ptid_t ptid,
>>     return fbsd_get_thread_local_address (gdbarch, dtv_addr, lm_addr, offset);
>>   }
>>   
>> +/* See i386-fbsd-tdep.h.  */
>> +
>> +gdb::unique_xmalloc_ptr<char>
>> +i386_fbsd_make_corefile_notes (struct gdbarch *gdbarch, bfd *obfd,
>> +			       int *note_size)
>> +{
>> +  gdb::unique_xmalloc_ptr<char> note_data =
>> +    fbsd_make_corefile_notes (gdbarch, obfd, note_size);
> 
> In GDB's coding style, the linebreak should be before the "=".

Thanks, fixed here and in the final patch.
  

Patch

diff --git a/gdb/amd64-fbsd-tdep.c b/gdb/amd64-fbsd-tdep.c
index 2b633cd479c..30cba8f6e6a 100644
--- a/gdb/amd64-fbsd-tdep.c
+++ b/gdb/amd64-fbsd-tdep.c
@@ -329,6 +329,7 @@  amd64fbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 
   set_gdbarch_core_read_description (gdbarch,
 				     amd64fbsd_core_read_description);
+  set_gdbarch_make_corefile_notes (gdbarch, i386_fbsd_make_corefile_notes);
 
   /* FreeBSD uses SVR4-style shared libraries.  */
   set_solib_svr4_fetch_link_map_offsets
diff --git a/gdb/i386-fbsd-tdep.c b/gdb/i386-fbsd-tdep.c
index 1789f3921fd..810ecc90df1 100644
--- a/gdb/i386-fbsd-tdep.c
+++ b/gdb/i386-fbsd-tdep.c
@@ -26,6 +26,7 @@ 
 #include "tramp-frame.h"
 #include "i386-fbsd-tdep.h"
 
+#include "x86-tdep.h"
 #include "i386-tdep.h"
 #include "i387-tdep.h"
 #include "fbsd-tdep.h"
@@ -370,6 +371,19 @@  i386fbsd_get_thread_local_address (struct gdbarch *gdbarch, ptid_t ptid,
   return fbsd_get_thread_local_address (gdbarch, dtv_addr, lm_addr, offset);
 }
 
+/* See i386-fbsd-tdep.h.  */
+
+gdb::unique_xmalloc_ptr<char>
+i386_fbsd_make_corefile_notes (struct gdbarch *gdbarch, bfd *obfd,
+			       int *note_size)
+{
+  gdb::unique_xmalloc_ptr<char> note_data =
+    fbsd_make_corefile_notes (gdbarch, obfd, note_size);
+
+  x86_elf_make_cpuid_note (obfd, &note_data, note_size);
+  return note_data;
+}
+
 static void
 i386fbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
@@ -403,6 +417,7 @@  i386fbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 
   set_gdbarch_core_read_description (gdbarch,
 				     i386fbsd_core_read_description);
+  set_gdbarch_make_corefile_notes (gdbarch, i386_fbsd_make_corefile_notes);
 
   /* FreeBSD uses SVR4-style shared libraries.  */
   set_solib_svr4_fetch_link_map_offsets
diff --git a/gdb/i386-fbsd-tdep.h b/gdb/i386-fbsd-tdep.h
index c49cb1eba68..fc7bb1c521d 100644
--- a/gdb/i386-fbsd-tdep.h
+++ b/gdb/i386-fbsd-tdep.h
@@ -40,6 +40,13 @@  bool i386_fbsd_core_read_x86_xsave_layout (struct gdbarch *gdbarch,
    matches the layout on Linux.  */
 #define I386_FBSD_XSAVE_XCR0_OFFSET 464
 
+/* Create appropriate note sections for a corefile, returning them in
+   allocated memory.  Extends fbsd_make_corefile_notes to add a
+   NT_X86_CPUID note.  */
+
+gdb::unique_xmalloc_ptr<char> i386_fbsd_make_corefile_notes
+(struct gdbarch *gdbarch, bfd *obfd, int *note_size);
+
 extern const struct regset i386_fbsd_gregset;
 
 #endif /* i386-fbsd-tdep.h */