From: Simon Marchi <simon.marchi@efficios.com>
To: gdb-patches@sourceware.org
Cc: Simon Marchi <simon.marchi@efficios.com>
Subject: [PATCH 2/2] gdb: pass type name directly to arch_composite_type
Date: Thu, 13 Aug 2026 12:18:59 -0400 [thread overview]
Message-ID: <20260813161905.345483-2-simon.marchi@efficios.com> (raw)
In-Reply-To: <20260813161905.345483-1-simon.marchi@efficios.com>
There are a few spots that call arch_composite_type followed by set_name
on the created type:
sigval_type = arch_composite_type (gdbarch, NULL, TYPE_CODE_UNION);
sigval_type->set_name (xstrdup ("sigval"));
First, it's not necessary to duplicate the string, we can pass the
literal string directly, and its lifetime will be appropriate. Second,
we can pass the name directly to arch_composite_type, instead of doing a
separate set_name call. So, replace the above with:
sigval_type = arch_composite_type (gdbarch, "sigval", TYPE_CODE_UNION);
Tested on Linux by running the gdb.*/*siginfo*.exp tests.
Change-Id: I7779e2156ca42212623dea8de709887acc40d242
---
gdb/fbsd-tdep.c | 7 +++----
gdb/linux-tdep.c | 6 ++----
gdb/netbsd-tdep.c | 16 ++++++++--------
gdb/windows-tdep.c | 16 ++++++----------
4 files changed, 19 insertions(+), 26 deletions(-)
diff --git a/gdb/fbsd-tdep.c b/gdb/fbsd-tdep.c
index 419f935ea72f..0bb63b8c199d 100644
--- a/gdb/fbsd-tdep.c
+++ b/gdb/fbsd-tdep.c
@@ -1590,8 +1590,7 @@ fbsd_get_siginfo_type (struct gdbarch *gdbarch)
void_ptr_type = lookup_pointer_type (builtin_type (gdbarch)->builtin_void);
/* union sigval */
- sigval_type = arch_composite_type (gdbarch, NULL, TYPE_CODE_UNION);
- sigval_type->set_name (xstrdup ("sigval"));
+ sigval_type = arch_composite_type (gdbarch, "sigval", TYPE_CODE_UNION);
append_composite_type_field (sigval_type, "sival_int", int_type);
append_composite_type_field (sigval_type, "sival_ptr", void_ptr_type);
@@ -1641,8 +1640,8 @@ fbsd_get_siginfo_type (struct gdbarch *gdbarch)
append_composite_type_field (reason_type, "__spare__", type);
/* struct siginfo */
- siginfo_type = arch_composite_type (gdbarch, NULL, TYPE_CODE_STRUCT);
- siginfo_type->set_name (xstrdup ("siginfo"));
+ siginfo_type = arch_composite_type (gdbarch, "siginfo",
+ TYPE_CODE_STRUCT);
append_composite_type_field (siginfo_type, "si_signo", int_type);
append_composite_type_field (siginfo_type, "si_errno", int_type);
append_composite_type_field (siginfo_type, "si_code", int_type);
diff --git a/gdb/linux-tdep.c b/gdb/linux-tdep.c
index fa9e5cb6f4d9..de2e5aba313c 100644
--- a/gdb/linux-tdep.c
+++ b/gdb/linux-tdep.c
@@ -286,9 +286,8 @@ linux_get_siginfo_type (struct gdbarch *gdbarch)
= lookup_pointer_type (builtin_type (gdbarch)->builtin_void);
/* sival_t */
- type *sigval_union_type = arch_composite_type (gdbarch, nullptr,
+ type *sigval_union_type = arch_composite_type (gdbarch, "sigval_t",
TYPE_CODE_UNION);
- sigval_union_type->set_name (xstrdup ("sigval_t"));
append_composite_type_field (sigval_union_type, "sival_int", int_type);
append_composite_type_field (sigval_union_type, "sival_ptr", void_ptr_type);
@@ -394,9 +393,8 @@ linux_get_siginfo_type (struct gdbarch *gdbarch)
sigsys_struct_type);
/* struct siginfo */
- type *siginfo_struct_type = arch_composite_type (gdbarch, nullptr,
+ type *siginfo_struct_type = arch_composite_type (gdbarch, "siginfo",
TYPE_CODE_STRUCT);
- siginfo_struct_type->set_name (xstrdup ("siginfo"));
append_composite_type_field (siginfo_struct_type, "si_signo", int_type);
append_composite_type_field (siginfo_struct_type, "si_errno", int_type);
append_composite_type_field (siginfo_struct_type, "si_code", int_type);
diff --git a/gdb/netbsd-tdep.c b/gdb/netbsd-tdep.c
index e369622ae7f7..1c0569873091 100644
--- a/gdb/netbsd-tdep.c
+++ b/gdb/netbsd-tdep.c
@@ -419,14 +419,14 @@ nbsd_get_siginfo_type (struct gdbarch *gdbarch)
lwpid_type->set_target_type (int32_type);
/* union sigval */
- type *sigval_type = arch_composite_type (gdbarch, NULL, TYPE_CODE_UNION);
- sigval_type->set_name (gdbarch_obstack_strdup (gdbarch, "sigval"));
+ type *sigval_type = arch_composite_type (gdbarch, "sigval",
+ TYPE_CODE_UNION);
append_composite_type_field (sigval_type, "sival_int", int_type);
append_composite_type_field (sigval_type, "sival_ptr", void_ptr_type);
/* union _option */
- type *option_type = arch_composite_type (gdbarch, NULL, TYPE_CODE_UNION);
- option_type->set_name (gdbarch_obstack_strdup (gdbarch, "_option"));
+ type *option_type = arch_composite_type (gdbarch, "_option",
+ TYPE_CODE_UNION);
append_composite_type_field (option_type, "_pe_other_pid", pid_type);
append_composite_type_field (option_type, "_pe_lwp", lwpid_type);
@@ -480,8 +480,8 @@ nbsd_get_siginfo_type (struct gdbarch *gdbarch)
append_composite_type_field (reason_type, "_ptrace_state", t);
/* struct _ksiginfo */
- type *ksiginfo_type = arch_composite_type (gdbarch, NULL, TYPE_CODE_STRUCT);
- ksiginfo_type->set_name (gdbarch_obstack_strdup (gdbarch, "_ksiginfo"));
+ type *ksiginfo_type = arch_composite_type (gdbarch, "_ksiginfo",
+ TYPE_CODE_STRUCT);
append_composite_type_field (ksiginfo_type, "_signo", int_type);
append_composite_type_field (ksiginfo_type, "_code", int_type);
append_composite_type_field (ksiginfo_type, "_errno", int_type);
@@ -490,8 +490,8 @@ nbsd_get_siginfo_type (struct gdbarch *gdbarch)
append_composite_type_field (ksiginfo_type, "_reason", reason_type);
/* union siginfo */
- type *siginfo_type = arch_composite_type (gdbarch, NULL, TYPE_CODE_UNION);
- siginfo_type->set_name (gdbarch_obstack_strdup (gdbarch, "siginfo"));
+ type *siginfo_type = arch_composite_type (gdbarch, "siginfo",
+ TYPE_CODE_UNION);
append_composite_type_field (siginfo_type, "si_pad",
init_vector_type (char_type, 128));
append_composite_type_field (siginfo_type, "_info", ksiginfo_type);
diff --git a/gdb/windows-tdep.c b/gdb/windows-tdep.c
index c0a743914b1c..6e83c8773c2d 100644
--- a/gdb/windows-tdep.c
+++ b/gdb/windows-tdep.c
@@ -225,8 +225,7 @@ windows_get_tlb_type (struct gdbarch *gdbarch)
/* list entry */
- list_type = arch_composite_type (gdbarch, NULL, TYPE_CODE_STRUCT);
- list_type->set_name (xstrdup ("list"));
+ list_type = arch_composite_type (gdbarch, "list", TYPE_CODE_STRUCT);
module_list_ptr_type = void_ptr_type;
@@ -237,8 +236,7 @@ windows_get_tlb_type (struct gdbarch *gdbarch)
/* Structured Exception Handler */
- seh_type = arch_composite_type (gdbarch, NULL, TYPE_CODE_STRUCT);
- seh_type->set_name (xstrdup ("seh"));
+ seh_type = arch_composite_type (gdbarch, "seh", TYPE_CODE_STRUCT);
seh_ptr_type = alloc.new_type (TYPE_CODE_PTR,
void_ptr_type->length () * TARGET_CHAR_BIT,
@@ -250,8 +248,8 @@ windows_get_tlb_type (struct gdbarch *gdbarch)
builtin_type (gdbarch)->builtin_func_ptr);
/* struct _PEB_LDR_DATA */
- peb_ldr_type = arch_composite_type (gdbarch, NULL, TYPE_CODE_STRUCT);
- peb_ldr_type->set_name (xstrdup ("peb_ldr_data"));
+ peb_ldr_type = arch_composite_type (gdbarch, "peb_ldr_data",
+ TYPE_CODE_STRUCT);
append_composite_type_field (peb_ldr_type, "length", dword32_type);
append_composite_type_field (peb_ldr_type, "initialized", dword32_type);
@@ -319,8 +317,7 @@ windows_get_tlb_type (struct gdbarch *gdbarch)
/* struct process environment block */
- peb_type = arch_composite_type (gdbarch, NULL, TYPE_CODE_STRUCT);
- peb_type->set_name (xstrdup ("peb"));
+ peb_type = arch_composite_type (gdbarch, "peb", TYPE_CODE_STRUCT);
/* First bytes contain several flags. */
append_composite_type_field (peb_type, "flags", dword_ptr_type);
@@ -338,8 +335,7 @@ windows_get_tlb_type (struct gdbarch *gdbarch)
/* struct thread information block */
- tib_type = arch_composite_type (gdbarch, NULL, TYPE_CODE_STRUCT);
- tib_type->set_name (xstrdup ("tib"));
+ tib_type = arch_composite_type (gdbarch, "tib", TYPE_CODE_STRUCT);
/* uint32_t current_seh; %fs:0x0000 */
append_composite_type_field (tib_type, "current_seh", seh_ptr_type);
--
2.55.0
next prev parent reply other threads:[~2026-08-13 16:19 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-13 16:18 [PATCH 1/2] gdb/linux-tdep: clearer variable names in linux_get_siginfo_type Simon Marchi
2026-08-13 16:18 ` Simon Marchi [this message]
2026-08-21 15:23 ` [PATCH 2/2] gdb: pass type name directly to arch_composite_type Tom Tromey
2026-08-21 15:20 ` [PATCH 1/2] gdb/linux-tdep: clearer variable names in linux_get_siginfo_type Tom Tromey
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260813161905.345483-2-simon.marchi@efficios.com \
--to=simon.marchi@efficios.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox