[PATCH 1/2] gdb/linux-tdep: clearer variable names in linux_get_siginfo_type
Simon Marchi <[email protected]>
| Newsgroups | gmane.comp.gdb.patches |
|---|---|
| Message-ID | <[email protected]> |
Instead of reusing the single variable `type`, use distinct variables
for the various types created. I find it more readable this way, it's
easier to track what's being added to what.
Do other cleanups at the same time, like NULL -> nullptr, removing some
`struct` keywords, and moving variable declarations to the point of
first use.
Change-Id: I846df0d4ad2208b768465c14abdc5422cc16bd07
---
gdb/linux-tdep.c | 154 +++++++++++++++++++++++++----------------------
1 file changed, 83 insertions(+), 71 deletions(-)
diff --git a/gdb/linux-tdep.c b/gdb/linux-tdep.c
index 23e43ba5c5f9..fa9e5cb6f4d9 100644
--- a/gdb/linux-tdep.c
+++ b/gdb/linux-tdep.c
@@ -268,58 +268,54 @@ get_linux_inferior_data (inferior *inf)
/* Implementation of gdbarch_get_siginfo_type. */
-static struct type *
+static type *
linux_get_siginfo_type (struct gdbarch *gdbarch)
{
- struct linux_gdbarch_data *linux_gdbarch_data;
- struct type *void_ptr_type;
- struct type *uid_type, *pid_type;
- struct type *sigval_type, *clock_type;
- struct type *siginfo_type, *sifields_type;
- struct type *type;
+ linux_gdbarch_data *linux_gdbarch_data = get_linux_gdbarch_data (gdbarch);
- linux_gdbarch_data = get_linux_gdbarch_data (gdbarch);
- if (linux_gdbarch_data->siginfo_type != NULL)
+ if (linux_gdbarch_data->siginfo_type != nullptr)
return linux_gdbarch_data->siginfo_type;
type_allocator alloc (gdbarch);
const struct builtin_type *builtin_types = builtin_type (gdbarch);
- struct type *int_type = builtin_types->builtin_int;
- struct type *uint_type = builtin_types->builtin_unsigned_int;
- struct type *long_type = builtin_types->builtin_long;
-
- void_ptr_type = lookup_pointer_type (builtin_type (gdbarch)->builtin_void);
+ type *int_type = builtin_types->builtin_int;
+ type *uint_type = builtin_types->builtin_unsigned_int;
+ type *long_type = builtin_types->builtin_long;
+ type *void_ptr_type
+ = lookup_pointer_type (builtin_type (gdbarch)->builtin_void);
/* sival_t */
- sigval_type = arch_composite_type (gdbarch, NULL, TYPE_CODE_UNION);
- sigval_type->set_name (xstrdup ("sigval_t"));
- append_composite_type_field (sigval_type, "sival_int", int_type);
- append_composite_type_field (sigval_type, "sival_ptr", void_ptr_type);
+ type *sigval_union_type = arch_composite_type (gdbarch, nullptr,
+ 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);
/* __pid_t */
- pid_type = alloc.new_type (TYPE_CODE_TYPEDEF,
- int_type->length () * TARGET_CHAR_BIT,
- "__pid_t");
+ type *pid_type = alloc.new_type (TYPE_CODE_TYPEDEF,
+ int_type->length () * TARGET_CHAR_BIT,
+ "__pid_t");
pid_type->set_target_type (int_type);
pid_type->set_target_is_stub (true);
/* __uid_t */
- uid_type = alloc.new_type (TYPE_CODE_TYPEDEF,
- uint_type->length () * TARGET_CHAR_BIT,
- "__uid_t");
+ type *uid_type = alloc.new_type (TYPE_CODE_TYPEDEF,
+ uint_type->length () * TARGET_CHAR_BIT,
+ "__uid_t");
uid_type->set_target_type (uint_type);
uid_type->set_target_is_stub (true);
/* __clock_t */
- clock_type = alloc.new_type (TYPE_CODE_TYPEDEF,
- long_type->length () * TARGET_CHAR_BIT,
- "__clock_t");
+ type *clock_type = alloc.new_type (TYPE_CODE_TYPEDEF,
+ long_type->length () * TARGET_CHAR_BIT,
+ "__clock_t");
clock_type->set_target_type (long_type);
clock_type->set_target_is_stub (true);
/* _sifields */
- sifields_type = arch_composite_type (gdbarch, NULL, TYPE_CODE_UNION);
+ type *sifields_union_type = arch_composite_type (gdbarch, nullptr,
+ TYPE_CODE_UNION);
{
const int si_max_size = 128;
@@ -331,70 +327,86 @@ linux_get_siginfo_type (struct gdbarch *gdbarch)
si_pad_size = (si_max_size / size_of_int) - 4;
else
si_pad_size = (si_max_size / size_of_int) - 3;
- append_composite_type_field (sifields_type, "_pad",
+
+ append_composite_type_field (sifields_union_type, "_pad",
init_vector_type (int_type, si_pad_size));
}
/* _kill */
- type = arch_composite_type (gdbarch, NULL, TYPE_CODE_STRUCT);
- append_composite_type_field (type, "si_pid", pid_type);
- append_composite_type_field (type, "si_uid", uid_type);
- append_composite_type_field (sifields_type, "_kill", type);
+ type *kill_struct_type = arch_composite_type (gdbarch, nullptr,
+ TYPE_CODE_STRUCT);
+ append_composite_type_field (kill_struct_type, "si_pid", pid_type);
+ append_composite_type_field (kill_struct_type, "si_uid", uid_type);
+ append_composite_type_field (sifields_union_type, "_kill", kill_struct_type);
/* _timer */
- type = arch_composite_type (gdbarch, NULL, TYPE_CODE_STRUCT);
- append_composite_type_field (type, "si_tid", int_type);
- append_composite_type_field (type, "si_overrun", int_type);
- append_composite_type_field (type, "si_sigval", sigval_type);
- append_composite_type_field (sifields_type, "_timer", type);
+ type *timer_struct_type = arch_composite_type (gdbarch, nullptr,
+ TYPE_CODE_STRUCT);
+ append_composite_type_field (timer_struct_type, "si_tid", int_type);
+ append_composite_type_field (timer_struct_type, "si_overrun", int_type);
+ append_composite_type_field (timer_struct_type, "si_sigval",
+ sigval_union_type);
+ append_composite_type_field (sifields_union_type, "_timer",
+ timer_struct_type);
/* _rt */
- type = arch_composite_type (gdbarch, NULL, TYPE_CODE_STRUCT);
- append_composite_type_field (type, "si_pid", pid_type);
- append_composite_type_field (type, "si_uid", uid_type);
- append_composite_type_field (type, "si_sigval", sigval_type);
- append_composite_type_field (sifields_type, "_rt", type);
+ type *rt_struct_type = arch_composite_type (gdbarch, nullptr,
+ TYPE_CODE_STRUCT);
+ append_composite_type_field (rt_struct_type, "si_pid", pid_type);
+ append_composite_type_field (rt_struct_type, "si_uid", uid_type);
+ append_composite_type_field (rt_struct_type, "si_sigval", sigval_union_type);
+ append_composite_type_field (sifields_union_type, "_rt", rt_struct_type);
/* _sigchld */
- type = arch_composite_type (gdbarch, NULL, TYPE_CODE_STRUCT);
- append_composite_type_field (type, "si_pid", pid_type);
- append_composite_type_field (type, "si_uid", uid_type);
- append_composite_type_field (type, "si_status", int_type);
- append_composite_type_field (type, "si_utime", clock_type);
- append_composite_type_field (type, "si_stime", clock_type);
- append_composite_type_field (sifields_type, "_sigchld", type);
+ type *sigchld_struct_type = arch_composite_type (gdbarch, nullptr,
+ TYPE_CODE_STRUCT);
+ append_composite_type_field (sigchld_struct_type, "si_pid", pid_type);
+ append_composite_type_field (sigchld_struct_type, "si_uid", uid_type);
+ append_composite_type_field (sigchld_struct_type, "si_status", int_type);
+ append_composite_type_field (sigchld_struct_type, "si_utime", clock_type);
+ append_composite_type_field (sigchld_struct_type, "si_stime", clock_type);
+ append_composite_type_field (sifields_union_type, "_sigchld",
+ sigchld_struct_type);
/* _sigfault */
- type = arch_composite_type (gdbarch, NULL, TYPE_CODE_STRUCT);
- append_composite_type_field (type, "si_addr", void_ptr_type);
- append_composite_type_field (sifields_type, "_sigfault", type);
+ type *sigfault_struct_type = arch_composite_type (gdbarch, nullptr,
+ TYPE_CODE_STRUCT);
+ append_composite_type_field (sigfault_struct_type, "si_addr", void_ptr_type);
+ append_composite_type_field (sifields_union_type, "_sigfault",
+ sigfault_struct_type);
/* _sigpoll */
- type = arch_composite_type (gdbarch, NULL, TYPE_CODE_STRUCT);
- append_composite_type_field (type, "si_band", long_type);
- append_composite_type_field (type, "si_fd", int_type);
- append_composite_type_field (sifields_type, "_sigpoll", type);
+ type *sigpoll_struct_type = arch_composite_type (gdbarch, NULL,
+ TYPE_CODE_STRUCT);
+ append_composite_type_field (sigpoll_struct_type, "si_band", long_type);
+ append_composite_type_field (sigpoll_struct_type, "si_fd", int_type);
+ append_composite_type_field (sifields_union_type, "_sigpoll",
+ sigpoll_struct_type);
/* _sigsys */
- type = arch_composite_type (gdbarch, NULL, TYPE_CODE_STRUCT);
- append_composite_type_field (type, "_call_addr", void_ptr_type);
- append_composite_type_field (type, "_syscall", int_type);
- append_composite_type_field (type, "_arch", uint_type);
- append_composite_type_field (sifields_type, "_sigsys", type);
+ type *sigsys_struct_type = arch_composite_type (gdbarch, nullptr,
+ TYPE_CODE_STRUCT);
+ append_composite_type_field (sigsys_struct_type, "_call_addr",
+ void_ptr_type);
+ append_composite_type_field (sigsys_struct_type, "_syscall", int_type);
+ append_composite_type_field (sigsys_struct_type, "_arch", uint_type);
+ append_composite_type_field (sifields_union_type, "_sigsys",
+ sigsys_struct_type);
/* struct siginfo */
- siginfo_type = arch_composite_type (gdbarch, NULL, TYPE_CODE_STRUCT);
- siginfo_type->set_name (xstrdup ("siginfo"));
- 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);
- append_composite_type_field_aligned (siginfo_type,
- "_sifields", sifields_type,
+ type *siginfo_struct_type = arch_composite_type (gdbarch, nullptr,
+ 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);
+ append_composite_type_field_aligned (siginfo_struct_type, "_sifields",
+ sifields_union_type,
long_type->length ());
- linux_gdbarch_data->siginfo_type = siginfo_type;
+ linux_gdbarch_data->siginfo_type = siginfo_struct_type;
- return siginfo_type;
+ return siginfo_struct_type;
}
/* Return true if the target is running on uClinux instead of normal
base-commit: 1686e21559a7812ebbc05f57372cc30880768bf7
--
2.55.0