diff options
Diffstat (limited to 'gdb/nat')
43 files changed, 1404 insertions, 1585 deletions
diff --git a/gdb/nat/aarch64-hw-point.c b/gdb/nat/aarch64-hw-point.c index dd0ffc3..8e6de15 100644 --- a/gdb/nat/aarch64-hw-point.c +++ b/gdb/nat/aarch64-hw-point.c @@ -24,7 +24,7 @@ /* For kernel_supports_any_contiguous_range. */ #include "aarch64-linux-hw-point.h" #else -#define kernel_supports_any_contiguous_range true +#define kernel_supports_any_contiguous_range true #endif /* Number of hardware breakpoints/watchpoints the target supports. @@ -67,7 +67,7 @@ aarch64_watchpoint_length (unsigned int ctrl) mask >>= 1; if (mask != 0) - error (_("Unexpected hardware watchpoint length register value 0x%x"), + error (_ ("Unexpected hardware watchpoint length register value 0x%x"), DR_CONTROL_MASK (ctrl)); return retval; @@ -78,7 +78,8 @@ aarch64_watchpoint_length (unsigned int ctrl) breakpoint/watchpoint control register. */ static unsigned int -aarch64_point_encode_ctrl_reg (enum target_hw_bp_type type, int offset, int len) +aarch64_point_encode_ctrl_reg (enum target_hw_bp_type type, int offset, + int len) { unsigned int ctrl, ttype; @@ -101,7 +102,7 @@ aarch64_point_encode_ctrl_reg (enum target_hw_bp_type type, int offset, int len) ttype = 0; break; default: - perror_with_name (_("Unrecognized breakpoint/watchpoint type")); + perror_with_name (_ ("Unrecognized breakpoint/watchpoint type")); } ctrl = ttype << 3; @@ -137,8 +138,7 @@ aarch64_point_is_aligned (ptid_t ptid, int is_watchpoint, CORE_ADDR addr, alignment = AARCH64_HWP_ALIGNMENT; else { - struct regcache *regcache - = get_thread_regcache_for_ptid (ptid); + struct regcache *regcache = get_thread_regcache_for_ptid (ptid); /* Set alignment to 2 only if the current process is 32-bit, since thumb instruction can be 2-byte aligned. Otherwise, set @@ -152,10 +152,9 @@ aarch64_point_is_aligned (ptid_t ptid, int is_watchpoint, CORE_ADDR addr, if (addr & (alignment - 1)) return 0; - if ((!kernel_supports_any_contiguous_range - && len != 8 && len != 4 && len != 2 && len != 1) - || (kernel_supports_any_contiguous_range - && (len < 1 || len > 8))) + if ((!kernel_supports_any_contiguous_range && len != 8 && len != 4 + && len != 2 && len != 1) + || (kernel_supports_any_contiguous_range && (len < 1 || len > 8))) return 0; return 1; @@ -246,12 +245,12 @@ aarch64_align_watchpoint (CORE_ADDR addr, int len, CORE_ADDR *aligned_addr_p, { /* Find the smallest valid length that is large enough to accommodate this watchpoint. */ - static const unsigned char - aligned_len_array[AARCH64_HWP_MAX_LEN_PER_REG] = - { 1, 2, 4, 4, 8, 8, 8, 8 }; + static const unsigned char aligned_len_array[AARCH64_HWP_MAX_LEN_PER_REG] + = { 1, 2, 4, 4, 8, 8, 8, 8 }; aligned_len = (kernel_supports_any_contiguous_range - ? len : aligned_len_array[offset + len - 1]); + ? len + : aligned_len_array[offset + len - 1]); addr += len; len = 0; } @@ -276,9 +275,8 @@ aarch64_align_watchpoint (CORE_ADDR addr, int len, CORE_ADDR *aligned_addr_p, static int aarch64_dr_state_insert_one_point (ptid_t ptid, struct aarch64_debug_reg_state *state, - enum target_hw_bp_type type, - CORE_ADDR addr, int offset, int len, - CORE_ADDR addr_orig) + enum target_hw_bp_type type, CORE_ADDR addr, + int offset, int len, CORE_ADDR addr_orig) { int i, idx, num_regs, is_watchpoint; unsigned int ctrl, *dr_ctrl_p, *dr_ref_count; @@ -357,9 +355,8 @@ aarch64_dr_state_insert_one_point (ptid_t ptid, static int aarch64_dr_state_remove_one_point (ptid_t ptid, struct aarch64_debug_reg_state *state, - enum target_hw_bp_type type, - CORE_ADDR addr, int offset, int len, - CORE_ADDR addr_orig) + enum target_hw_bp_type type, CORE_ADDR addr, + int offset, int len, CORE_ADDR addr_orig) { int i, num_regs, is_watchpoint; unsigned int ctrl, *dr_ctrl_p, *dr_ref_count; @@ -431,11 +428,11 @@ aarch64_handle_breakpoint (enum target_hw_bp_type type, CORE_ADDR addr, However when GDB follows the parent process and detach breakpoints from child process, inferior_ptid is the child ptid, but the child inferior doesn't exist in GDB's view yet. */ - if (!aarch64_point_is_aligned (ptid, 0 /* is_watchpoint */ , addr, len)) + if (!aarch64_point_is_aligned (ptid, 0 /* is_watchpoint */, addr, len)) return -1; - return aarch64_dr_state_insert_one_point (ptid, state, type, addr, 0, len, - -1); + return aarch64_dr_state_insert_one_point (ptid, state, type, addr, 0, + len, -1); } else return aarch64_dr_state_remove_one_point (ptid, state, type, addr, 0, len, @@ -446,9 +443,8 @@ aarch64_handle_breakpoint (enum target_hw_bp_type type, CORE_ADDR addr, from that it is an aligned watchpoint to be handled. */ static int -aarch64_handle_aligned_watchpoint (enum target_hw_bp_type type, - CORE_ADDR addr, int len, int is_insert, - ptid_t ptid, +aarch64_handle_aligned_watchpoint (enum target_hw_bp_type type, CORE_ADDR addr, + int len, int is_insert, ptid_t ptid, struct aarch64_debug_reg_state *state) { if (is_insert) @@ -521,7 +517,7 @@ aarch64_handle_watchpoint (enum target_hw_bp_type type, CORE_ADDR addr, int len, int is_insert, ptid_t ptid, struct aarch64_debug_reg_state *state) { - if (aarch64_point_is_aligned (ptid, 1 /* is_watchpoint */ , addr, len)) + if (aarch64_point_is_aligned (ptid, 1 /* is_watchpoint */, addr, len)) return aarch64_handle_aligned_watchpoint (type, addr, len, is_insert, ptid, state); else @@ -540,7 +536,8 @@ aarch64_any_set_debug_regs_state (aarch64_debug_reg_state *state, return false; const CORE_ADDR *addr = watchpoint ? state->dr_addr_wp : state->dr_addr_bp; - const unsigned int *ctrl = watchpoint ? state->dr_ctrl_wp : state->dr_ctrl_bp; + const unsigned int *ctrl + = watchpoint ? state->dr_ctrl_wp : state->dr_ctrl_bp; for (int i = 0; i < count; i++) if (addr[i] != 0 || ctrl[i] != 0) @@ -553,32 +550,34 @@ aarch64_any_set_debug_regs_state (aarch64_debug_reg_state *state, void aarch64_show_debug_reg_state (struct aarch64_debug_reg_state *state, - const char *func, CORE_ADDR addr, - int len, enum target_hw_bp_type type) + const char *func, CORE_ADDR addr, int len, + enum target_hw_bp_type type) { int i; debug_printf ("%s", func); if (addr || len) - debug_printf (" (addr=0x%08lx, len=%d, type=%s)", - (unsigned long) addr, len, - type == hw_write ? "hw-write-watchpoint" - : (type == hw_read ? "hw-read-watchpoint" - : (type == hw_access ? "hw-access-watchpoint" - : (type == hw_execute ? "hw-breakpoint" - : "??unknown??")))); + debug_printf ( + " (addr=0x%08lx, len=%d, type=%s)", (unsigned long) addr, len, + type == hw_write + ? "hw-write-watchpoint" + : (type == hw_read + ? "hw-read-watchpoint" + : (type == hw_access + ? "hw-access-watchpoint" + : (type == hw_execute ? "hw-breakpoint" : "??unknown??")))); debug_printf (":\n"); debug_printf ("\tBREAKPOINTs:\n"); for (i = 0; i < aarch64_num_bp_regs; i++) - debug_printf ("\tBP%d: addr=%s, ctrl=0x%08x, ref.count=%d\n", - i, core_addr_to_string_nz (state->dr_addr_bp[i]), + debug_printf ("\tBP%d: addr=%s, ctrl=0x%08x, ref.count=%d\n", i, + core_addr_to_string_nz (state->dr_addr_bp[i]), state->dr_ctrl_bp[i], state->dr_ref_count_bp[i]); debug_printf ("\tWATCHPOINTs:\n"); for (i = 0; i < aarch64_num_wp_regs; i++) - debug_printf ("\tWP%d: addr=%s (orig=%s), ctrl=0x%08x, ref.count=%d\n", - i, core_addr_to_string_nz (state->dr_addr_wp[i]), + debug_printf ("\tWP%d: addr=%s (orig=%s), ctrl=0x%08x, ref.count=%d\n", i, + core_addr_to_string_nz (state->dr_addr_wp[i]), core_addr_to_string_nz (state->dr_addr_orig_wp[i]), state->dr_ctrl_wp[i], state->dr_ref_count_wp[i]); } diff --git a/gdb/nat/aarch64-hw-point.h b/gdb/nat/aarch64-hw-point.h index 13ec0c5..ca5dadc 100644 --- a/gdb/nat/aarch64-hw-point.h +++ b/gdb/nat/aarch64-hw-point.h @@ -68,8 +68,8 @@ The TYPE field is ignored for breakpoints. */ -#define DR_CONTROL_ENABLED(ctrl) (((ctrl) & 0x1) == 1) -#define DR_CONTROL_MASK(ctrl) (((ctrl) >> 5) & 0xff) +#define DR_CONTROL_ENABLED(ctrl) (((ctrl) &0x1) == 1) +#define DR_CONTROL_MASK(ctrl) (((ctrl) >> 5) & 0xff) /* Structure for managing the hardware breakpoint/watchpoint resources. DR_ADDR_* stores the address, DR_CTRL_* stores the control register @@ -118,8 +118,8 @@ bool aarch64_any_set_debug_regs_state (aarch64_debug_reg_state *state, bool watchpoint); void aarch64_show_debug_reg_state (struct aarch64_debug_reg_state *state, - const char *func, CORE_ADDR addr, - int len, enum target_hw_bp_type type); + const char *func, CORE_ADDR addr, int len, + enum target_hw_bp_type type); int aarch64_region_ok_for_watchpoint (CORE_ADDR addr, int len); diff --git a/gdb/nat/aarch64-linux-hw-point.c b/gdb/nat/aarch64-linux-hw-point.c index 096c34f..a980e45 100644 --- a/gdb/nat/aarch64-linux-hw-point.c +++ b/gdb/nat/aarch64-linux-hw-point.c @@ -63,18 +63,17 @@ debug_reg_change_callback (struct lwp_info *lwp, int is_watchpoint, { debug_printf ("debug_reg_change_callback: \n\tOn entry:\n"); debug_printf ("\ttid%d, dr_changed_bp=0x%s, " - "dr_changed_wp=0x%s\n", tid, - phex (info->dr_changed_bp, 8), + "dr_changed_wp=0x%s\n", + tid, phex (info->dr_changed_bp, 8), phex (info->dr_changed_wp, 8)); } - dr_changed_ptr = is_watchpoint ? &info->dr_changed_wp - : &info->dr_changed_bp; + dr_changed_ptr = is_watchpoint ? &info->dr_changed_wp : &info->dr_changed_bp; dr_changed = *dr_changed_ptr; gdb_assert (idx >= 0 && (idx <= (is_watchpoint ? aarch64_num_wp_regs - : aarch64_num_bp_regs))); + : aarch64_num_bp_regs))); /* The actual update is done later just before resuming the lwp, we just mark that one register pair needs updating. */ @@ -89,8 +88,8 @@ debug_reg_change_callback (struct lwp_info *lwp, int is_watchpoint, if (show_debug_regs) { debug_printf ("\tOn exit:\n\ttid%d, dr_changed_bp=0x%s, " - "dr_changed_wp=0x%s\n", tid, - phex (info->dr_changed_bp, 8), + "dr_changed_wp=0x%s\n", + tid, phex (info->dr_changed_bp, 8), phex (info->dr_changed_wp, 8)); } @@ -103,17 +102,14 @@ debug_reg_change_callback (struct lwp_info *lwp, int is_watchpoint, when the thread is resumed. */ void -aarch64_notify_debug_reg_change (ptid_t ptid, - int is_watchpoint, unsigned int idx) +aarch64_notify_debug_reg_change (ptid_t ptid, int is_watchpoint, + unsigned int idx) { ptid_t pid_ptid = ptid_t (ptid.pid ()); - iterate_over_lwps (pid_ptid, [=] (struct lwp_info *info) - { - return debug_reg_change_callback (info, - is_watchpoint, - idx); - }); + iterate_over_lwps (pid_ptid, [=] (struct lwp_info *info) { + return debug_reg_change_callback (info, is_watchpoint, idx); + }); } /* Reconfigure STATE to be compatible with Linux kernels with the PR @@ -176,8 +172,8 @@ aarch64_downgrade_regs (struct aarch64_debug_reg_state *state) registers with data from *STATE. */ void -aarch64_linux_set_debug_regs (struct aarch64_debug_reg_state *state, - int tid, int watchpoint) +aarch64_linux_set_debug_regs (struct aarch64_debug_reg_state *state, int tid, + int watchpoint) { int i, count; struct iovec iov; @@ -202,8 +198,7 @@ aarch64_linux_set_debug_regs (struct aarch64_debug_reg_state *state, } if (ptrace (PTRACE_SETREGSET, tid, - watchpoint ? NT_ARM_HW_WATCH : NT_ARM_HW_BREAK, - (void *) &iov)) + watchpoint ? NT_ARM_HW_WATCH : NT_ARM_HW_BREAK, (void *) &iov)) { /* Handle Linux kernels with the PR external/20207 bug. */ if (watchpoint && errno == EINVAL @@ -214,7 +209,7 @@ aarch64_linux_set_debug_regs (struct aarch64_debug_reg_state *state, aarch64_linux_set_debug_regs (state, tid, watchpoint); return; } - error (_("Unexpected error setting hardware debug registers")); + error (_ ("Unexpected error setting hardware debug registers")); } } @@ -255,16 +250,16 @@ aarch64_linux_get_debug_reg_capacity (int tid) aarch64_num_wp_regs = AARCH64_DEBUG_NUM_SLOTS (dreg_state.dbg_info); if (aarch64_num_wp_regs > AARCH64_HWP_MAX_NUM) { - warning (_("Unexpected number of hardware watchpoint registers" - " reported by ptrace, got %d, expected %d."), + warning (_ ("Unexpected number of hardware watchpoint registers" + " reported by ptrace, got %d, expected %d."), aarch64_num_wp_regs, AARCH64_HWP_MAX_NUM); aarch64_num_wp_regs = AARCH64_HWP_MAX_NUM; } } else { - warning (_("Unable to determine the number of hardware watchpoints" - " available.")); + warning (_ ("Unable to determine the number of hardware watchpoints" + " available.")); aarch64_num_wp_regs = 0; } @@ -275,16 +270,16 @@ aarch64_linux_get_debug_reg_capacity (int tid) aarch64_num_bp_regs = AARCH64_DEBUG_NUM_SLOTS (dreg_state.dbg_info); if (aarch64_num_bp_regs > AARCH64_HBP_MAX_NUM) { - warning (_("Unexpected number of hardware breakpoint registers" - " reported by ptrace, got %d, expected %d."), + warning (_ ("Unexpected number of hardware breakpoint registers" + " reported by ptrace, got %d, expected %d."), aarch64_num_bp_regs, AARCH64_HBP_MAX_NUM); aarch64_num_bp_regs = AARCH64_HBP_MAX_NUM; } } else { - warning (_("Unable to determine the number of hardware breakpoints" - " available.")); + warning (_ ("Unable to determine the number of hardware breakpoints" + " available.")); aarch64_num_bp_regs = 0; } } diff --git a/gdb/nat/aarch64-linux-hw-point.h b/gdb/nat/aarch64-linux-hw-point.h index 83a0a09..9ef1b04 100644 --- a/gdb/nat/aarch64-linux-hw-point.h +++ b/gdb/nat/aarch64-linux-hw-point.h @@ -30,9 +30,8 @@ | RESERVED | RESERVED | DEBUG_ARCH | NUM_SLOTS | +---------------+--------------+---------------+---------------+ */ - /* Macros to extract fields from the hardware debug information word. */ -#define AARCH64_DEBUG_NUM_SLOTS(x) ((x) & 0xff) +#define AARCH64_DEBUG_NUM_SLOTS(x) ((x) &0xff) #define AARCH64_DEBUG_ARCH(x) (((x) >> 8) & 0xff) /* Each bit of a variable of this type is used to indicate whether a @@ -60,27 +59,30 @@ typedef ULONGEST dr_changed_t; /* Set each of the lower M bits of X to 1; assert X is wide enough. */ -#define DR_MARK_ALL_CHANGED(x, m) \ - do \ - { \ - gdb_assert (sizeof ((x)) * 8 >= (m)); \ - (x) = (((dr_changed_t)1 << (m)) - 1); \ - } while (0) - -#define DR_MARK_N_CHANGED(x, n) \ - do \ - { \ - (x) |= ((dr_changed_t)1 << (n)); \ - } while (0) - -#define DR_CLEAR_CHANGED(x) \ - do \ - { \ - (x) = 0; \ - } while (0) +#define DR_MARK_ALL_CHANGED(x, m) \ + do \ + { \ + gdb_assert (sizeof ((x)) * 8 >= (m)); \ + (x) = (((dr_changed_t) 1 << (m)) - 1); \ + } \ + while (0) + +#define DR_MARK_N_CHANGED(x, n) \ + do \ + { \ + (x) |= ((dr_changed_t) 1 << (n)); \ + } \ + while (0) + +#define DR_CLEAR_CHANGED(x) \ + do \ + { \ + (x) = 0; \ + } \ + while (0) #define DR_HAS_CHANGED(x) ((x) != 0) -#define DR_N_HAS_CHANGED(x, n) ((x) & ((dr_changed_t)1 << (n))) +#define DR_N_HAS_CHANGED(x, n) ((x) & ((dr_changed_t) 1 << (n))) /* Per-thread arch-specific data we want to keep. */ diff --git a/gdb/nat/aarch64-linux.c b/gdb/nat/aarch64-linux.c index 6c8a78f..e35b5cb 100644 --- a/gdb/nat/aarch64-linux.c +++ b/gdb/nat/aarch64-linux.c @@ -208,7 +208,7 @@ aarch64_siginfo_from_compat_siginfo (siginfo_t *to, compat_siginfo_t *from) default: to->si_pid = from->cpt_si_pid; to->si_uid = from->cpt_si_uid; - to->si_ptr = (void* ) (intptr_t) from->cpt_si_ptr; + to->si_ptr = (void *) (intptr_t) from->cpt_si_ptr; break; } } @@ -218,9 +218,8 @@ aarch64_siginfo_from_compat_siginfo (siginfo_t *to, compat_siginfo_t *from) storage (or its descriptor). */ ps_err_e -aarch64_ps_get_thread_area (struct ps_prochandle *ph, - lwpid_t lwpid, int idx, void **base, - int is_64bit_p) +aarch64_ps_get_thread_area (struct ps_prochandle *ph, lwpid_t lwpid, int idx, + void **base, int is_64bit_p) { struct iovec iovec; uint64_t reg64; diff --git a/gdb/nat/aarch64-linux.h b/gdb/nat/aarch64-linux.h index 391c66c..c0f2eb3 100644 --- a/gdb/nat/aarch64-linux.h +++ b/gdb/nat/aarch64-linux.h @@ -114,9 +114,9 @@ typedef struct compat_siginfo #define cpt_si_fd _sifields._sigpoll._fd void aarch64_siginfo_from_compat_siginfo (siginfo_t *to, - compat_siginfo_t *from); + compat_siginfo_t *from); void aarch64_compat_siginfo_from_siginfo (compat_siginfo_t *to, - siginfo_t *from); + siginfo_t *from); void aarch64_linux_prepare_to_resume (struct lwp_info *lwp); @@ -125,9 +125,8 @@ void aarch64_linux_new_thread (struct lwp_info *lwp); /* Function to call when a thread is being deleted. */ void aarch64_linux_delete_thread (struct arch_lwp_info *arch_lwp); -ps_err_e aarch64_ps_get_thread_area (struct ps_prochandle *ph, - lwpid_t lwpid, int idx, void **base, - int is_64bit_p); +ps_err_e aarch64_ps_get_thread_area (struct ps_prochandle *ph, lwpid_t lwpid, + int idx, void **base, int is_64bit_p); /* Return the number of TLS registers in the NT_ARM_TLS set. This is only used for aarch64 state. */ diff --git a/gdb/nat/aarch64-mte-linux-ptrace.c b/gdb/nat/aarch64-mte-linux-ptrace.c index a7be454..95e3b6f 100644 --- a/gdb/nat/aarch64-mte-linux-ptrace.c +++ b/gdb/nat/aarch64-mte-linux-ptrace.c @@ -38,15 +38,15 @@ aarch64_mte_linux_peek_error (int error) switch (error) { case EIO: - perror_with_name (_("PEEKMTETAGS not supported")); + perror_with_name (_ ("PEEKMTETAGS not supported")); break; case EFAULT: - perror_with_name (_("Couldn't fetch allocation tags")); + perror_with_name (_ ("Couldn't fetch allocation tags")); break; case EOPNOTSUPP: - perror_with_name (_("PROT_MTE not enabled for requested address")); + perror_with_name (_ ("PROT_MTE not enabled for requested address")); default: - perror_with_name (_("Unknown MTE error")); + perror_with_name (_ ("Unknown MTE error")); break; } } @@ -60,15 +60,15 @@ aarch64_mte_linux_poke_error (int error) switch (error) { case EIO: - perror_with_name (_("POKEMTETAGS not supported")); + perror_with_name (_ ("POKEMTETAGS not supported")); break; case EFAULT: - perror_with_name (_("Couldn't store allocation tags")); + perror_with_name (_ ("Couldn't store allocation tags")); break; case EOPNOTSUPP: - perror_with_name (_("PROT_MTE not enabled for requested address")); + perror_with_name (_ ("PROT_MTE not enabled for requested address")); default: - perror_with_name (_("Unknown MTE error")); + perror_with_name (_ ("Unknown MTE error")); break; } } @@ -112,8 +112,8 @@ bool aarch64_mte_fetch_memtags (int tid, CORE_ADDR address, size_t len, gdb::byte_vector &tags) { - size_t ntags = aarch64_mte_get_tag_granules (address, len, - AARCH64_MTE_GRANULE_SIZE); + size_t ntags + = aarch64_mte_get_tag_granules (address, len, AARCH64_MTE_GRANULE_SIZE); /* If the memory range contains no tags, nothing left to do. */ if (ntags == 0) @@ -169,8 +169,8 @@ aarch64_mte_store_memtags (int tid, CORE_ADDR address, size_t len, return true; /* Get the number of tags we need to write. */ - size_t ntags = aarch64_mte_get_tag_granules (address, len, - AARCH64_MTE_GRANULE_SIZE); + size_t ntags + = aarch64_mte_get_tag_granules (address, len, AARCH64_MTE_GRANULE_SIZE); /* If the memory range contains no tags, nothing left to do. */ if (ntags == 0) @@ -182,9 +182,9 @@ aarch64_mte_store_memtags (int tid, CORE_ADDR address, size_t len, /* Write all the tags, AARCH64_MTE_TAGS_MAX_SIZE blocks at a time. */ while (!done_writing) { - gdb::byte_vector t = prepare_tag_vector (ntags - tags_written, tags, - tags_written, - AARCH64_MTE_TAGS_MAX_SIZE); + gdb::byte_vector t + = prepare_tag_vector (ntags - tags_written, tags, tags_written, + AARCH64_MTE_TAGS_MAX_SIZE); struct iovec iovec; iovec.iov_base = t.data (); diff --git a/gdb/nat/aarch64-mte-linux-ptrace.h b/gdb/nat/aarch64-mte-linux-ptrace.h index ec99e13..26a5ff7 100644 --- a/gdb/nat/aarch64-mte-linux-ptrace.h +++ b/gdb/nat/aarch64-mte-linux-ptrace.h @@ -23,11 +23,11 @@ /* MTE allocation tag access */ #ifndef PTRACE_PEEKMTETAGS -#define PTRACE_PEEKMTETAGS 33 +#define PTRACE_PEEKMTETAGS 33 #endif #ifndef PTRACE_POKEMTETAGS -#define PTRACE_POKEMTETAGS 34 +#define PTRACE_POKEMTETAGS 34 #endif /* Maximum number of tags to pass at once to the kernel. */ diff --git a/gdb/nat/aarch64-sve-linux-ptrace.c b/gdb/nat/aarch64-sve-linux-ptrace.c index 5114653..970453a 100644 --- a/gdb/nat/aarch64-sve-linux-ptrace.c +++ b/gdb/nat/aarch64-sve-linux-ptrace.c @@ -53,7 +53,7 @@ aarch64_sve_get_vq (int tid) if (!sve_vl_valid (header.vl)) { - warning (_("Invalid SVE state from kernel; SVE disabled.")); + warning (_ ("Invalid SVE state from kernel; SVE disabled.")); return 0; } @@ -126,7 +126,7 @@ aarch64_sve_get_sveregs (int tid) uint64_t vq = aarch64_sve_get_vq (tid); if (vq == 0) - perror_with_name (_("Unable to fetch SVE register header")); + perror_with_name (_ ("Unable to fetch SVE register header")); /* A ptrace call with NT_ARM_SVE will return a header followed by either a dump of all the SVE and FP registers, or an fpsimd structure (identical to @@ -138,7 +138,7 @@ aarch64_sve_get_sveregs (int tid) iovec.iov_base = buf.get (); if (ptrace (PTRACE_GETREGSET, tid, NT_ARM_SVE, &iovec) < 0) - perror_with_name (_("Unable to fetch SVE registers")); + perror_with_name (_ ("Unable to fetch SVE registers")); return buf; } @@ -176,7 +176,7 @@ aarch64_sve_regs_copy_to_reg_buf (struct reg_buffer_common *reg_buf, /* Sanity check the data in the header. */ if (!sve_vl_valid (header->vl) || SVE_PT_SIZE (vq, header->flags) != header->size) - error (_("Invalid SVE header from kernel.")); + error (_ ("Invalid SVE header from kernel.")); /* Update VG. Note, the registers in the regcache will already be of the correct length. */ @@ -220,7 +220,7 @@ aarch64_sve_regs_copy_to_reg_buf (struct reg_buffer_common *reg_buf, gdb_byte *reg = (gdb_byte *) alloca (SVE_PT_SVE_ZREG_SIZE (vq)); struct user_fpsimd_state *fpsimd - = (struct user_fpsimd_state *)(base + SVE_PT_FPSIMD_OFFSET); + = (struct user_fpsimd_state *) (base + SVE_PT_FPSIMD_OFFSET); /* Make sure we have a zeroed register buffer. We will need the zero padding below. */ @@ -263,7 +263,7 @@ aarch64_sve_regs_copy_from_reg_buf (const struct reg_buffer_common *reg_buf, /* Sanity check the data in the header. */ if (!sve_vl_valid (header->vl) || SVE_PT_SIZE (vq, header->flags) != header->size) - error (_("Invalid SVE header from kernel.")); + error (_ ("Invalid SVE header from kernel.")); if (!HAS_SVE_STATE (*header)) { @@ -277,7 +277,7 @@ aarch64_sve_regs_copy_from_reg_buf (const struct reg_buffer_common *reg_buf, bool has_sve_state = false; gdb_byte *reg = (gdb_byte *) alloca (SVE_PT_SVE_ZREG_SIZE (vq)); struct user_fpsimd_state *fpsimd - = (struct user_fpsimd_state *)(base + SVE_PT_FPSIMD_OFFSET); + = (struct user_fpsimd_state *) (base + SVE_PT_FPSIMD_OFFSET); memset (reg, 0, SVE_PT_SVE_ZREG_SIZE (vq)); @@ -295,15 +295,14 @@ aarch64_sve_regs_copy_from_reg_buf (const struct reg_buffer_common *reg_buf, if (!has_sve_state) for (int i = 0; i < AARCH64_SVE_P_REGS_NUM; i++) { - has_sve_state |= reg_buf->raw_compare (AARCH64_SVE_P0_REGNUM + i, - reg, 0); + has_sve_state + |= reg_buf->raw_compare (AARCH64_SVE_P0_REGNUM + i, reg, 0); if (has_sve_state) break; } if (!has_sve_state) - has_sve_state |= reg_buf->raw_compare (AARCH64_SVE_FFR_REGNUM, - reg, 0); + has_sve_state |= reg_buf->raw_compare (AARCH64_SVE_FFR_REGNUM, reg, 0); /* If no SVE state exists, then use the existing fpsimd structure to write out state and return. */ @@ -360,7 +359,7 @@ aarch64_sve_regs_copy_from_reg_buf (const struct reg_buffer_common *reg_buf, memcpy (base + SVE_PT_SVE_FPCR_OFFSET (vq), &fpsimd->fpcr, sizeof (uint32_t)); - for (int i = AARCH64_SVE_Z_REGS_NUM; i >= 0 ; i--) + for (int i = AARCH64_SVE_Z_REGS_NUM; i >= 0; i--) { memcpy (base + SVE_PT_SVE_ZREG_OFFSET (vq, i), &fpsimd->vregs[i], sizeof (__int128_t)); @@ -388,5 +387,4 @@ aarch64_sve_regs_copy_from_reg_buf (const struct reg_buffer_common *reg_buf, if (REG_VALID == reg_buf->get_register_status (AARCH64_FPCR_REGNUM)) reg_buf->raw_collect (AARCH64_FPCR_REGNUM, base + SVE_PT_SVE_FPCR_OFFSET (vq)); - } diff --git a/gdb/nat/aarch64-sve-linux-ptrace.h b/gdb/nat/aarch64-sve-linux-ptrace.h index 9539e19..483a0fd 100644 --- a/gdb/nat/aarch64-sve-linux-ptrace.h +++ b/gdb/nat/aarch64-sve-linux-ptrace.h @@ -59,8 +59,9 @@ extern std::unique_ptr<gdb_byte[]> aarch64_sve_get_sveregs (int tid); /* Put the registers from linux structure buf into register buffer. Assumes the vector lengths in the register buffer match the size in the kernel. */ -extern void aarch64_sve_regs_copy_to_reg_buf (struct reg_buffer_common *reg_buf, - const void *buf); +extern void +aarch64_sve_regs_copy_to_reg_buf (struct reg_buffer_common *reg_buf, + const void *buf); /* Put the registers from register buffer into linux structure buf. Assumes the vector lengths in the register buffer match the size in the kernel. */ diff --git a/gdb/nat/aarch64-sve-linux-sigcontext.h b/gdb/nat/aarch64-sve-linux-sigcontext.h index aba3c15..d3c2fd2 100644 --- a/gdb/nat/aarch64-sve-linux-sigcontext.h +++ b/gdb/nat/aarch64-sve-linux-sigcontext.h @@ -19,12 +19,13 @@ #ifndef NAT_AARCH64_SVE_LINUX_SIGCONTEXT_H #define NAT_AARCH64_SVE_LINUX_SIGCONTEXT_H -#define SVE_MAGIC 0x53564501 +#define SVE_MAGIC 0x53564501 -struct sve_context { - struct _aarch64_ctx head; - __u16 vl; - __u16 __reserved[3]; +struct sve_context +{ + struct _aarch64_ctx head; + __u16 vl; + __u16 __reserved[3]; }; /* @@ -35,19 +36,19 @@ struct sve_context { * See linux/Documentation/arm64/sve.txt for a description of the VL/VQ * terminology. */ -#define SVE_VQ_BYTES 16 /* number of bytes per quadword */ +#define SVE_VQ_BYTES 16 /* number of bytes per quadword */ -#define SVE_VQ_MIN 1 -#define SVE_VQ_MAX 512 +#define SVE_VQ_MIN 1 +#define SVE_VQ_MAX 512 -#define SVE_VL_MIN (SVE_VQ_MIN * SVE_VQ_BYTES) -#define SVE_VL_MAX (SVE_VQ_MAX * SVE_VQ_BYTES) +#define SVE_VL_MIN (SVE_VQ_MIN * SVE_VQ_BYTES) +#define SVE_VL_MAX (SVE_VQ_MAX * SVE_VQ_BYTES) -#define SVE_NUM_ZREGS 32 -#define SVE_NUM_PREGS 16 +#define SVE_NUM_ZREGS 32 +#define SVE_NUM_PREGS 16 #define sve_vl_valid(vl) \ - ((vl) % SVE_VQ_BYTES == 0 && (vl) >= SVE_VL_MIN && (vl) <= SVE_VL_MAX) + ((vl) % SVE_VQ_BYTES == 0 && (vl) >= SVE_VL_MIN && (vl) <= SVE_VL_MAX) /* * If the SVE registers are currently live for the thread at signal delivery, @@ -100,59 +101,59 @@ struct sve_context { * Additional data might be appended in the future. */ -#define SVE_SIG_ZREG_SIZE(vq) ((__u32)(vq) * SVE_VQ_BYTES) -#define SVE_SIG_PREG_SIZE(vq) ((__u32)(vq) * (SVE_VQ_BYTES / 8)) -#define SVE_SIG_FFR_SIZE(vq) SVE_SIG_PREG_SIZE(vq) +#define SVE_SIG_ZREG_SIZE(vq) ((__u32) (vq) *SVE_VQ_BYTES) +#define SVE_SIG_PREG_SIZE(vq) ((__u32) (vq) * (SVE_VQ_BYTES / 8)) +#define SVE_SIG_FFR_SIZE(vq) SVE_SIG_PREG_SIZE (vq) -#define SVE_SIG_REGS_OFFSET \ - ((sizeof(struct sve_context) + (SVE_VQ_BYTES - 1)) \ - / SVE_VQ_BYTES * SVE_VQ_BYTES) +#define SVE_SIG_REGS_OFFSET \ + ((sizeof (struct sve_context) + (SVE_VQ_BYTES - 1)) / SVE_VQ_BYTES \ + * SVE_VQ_BYTES) -#define SVE_SIG_ZREGS_OFFSET SVE_SIG_REGS_OFFSET +#define SVE_SIG_ZREGS_OFFSET SVE_SIG_REGS_OFFSET #define SVE_SIG_ZREG_OFFSET(vq, n) \ - (SVE_SIG_ZREGS_OFFSET + SVE_SIG_ZREG_SIZE(vq) * (n)) + (SVE_SIG_ZREGS_OFFSET + SVE_SIG_ZREG_SIZE (vq) * (n)) #define SVE_SIG_ZREGS_SIZE(vq) \ - (SVE_SIG_ZREG_OFFSET(vq, SVE_NUM_ZREGS) - SVE_SIG_ZREGS_OFFSET) + (SVE_SIG_ZREG_OFFSET (vq, SVE_NUM_ZREGS) - SVE_SIG_ZREGS_OFFSET) #define SVE_SIG_PREGS_OFFSET(vq) \ - (SVE_SIG_ZREGS_OFFSET + SVE_SIG_ZREGS_SIZE(vq)) + (SVE_SIG_ZREGS_OFFSET + SVE_SIG_ZREGS_SIZE (vq)) #define SVE_SIG_PREG_OFFSET(vq, n) \ - (SVE_SIG_PREGS_OFFSET(vq) + SVE_SIG_PREG_SIZE(vq) * (n)) + (SVE_SIG_PREGS_OFFSET (vq) + SVE_SIG_PREG_SIZE (vq) * (n)) #define SVE_SIG_PREGS_SIZE(vq) \ - (SVE_SIG_PREG_OFFSET(vq, SVE_NUM_PREGS) - SVE_SIG_PREGS_OFFSET(vq)) + (SVE_SIG_PREG_OFFSET (vq, SVE_NUM_PREGS) - SVE_SIG_PREGS_OFFSET (vq)) #define SVE_SIG_FFR_OFFSET(vq) \ - (SVE_SIG_PREGS_OFFSET(vq) + SVE_SIG_PREGS_SIZE(vq)) + (SVE_SIG_PREGS_OFFSET (vq) + SVE_SIG_PREGS_SIZE (vq)) #define SVE_SIG_REGS_SIZE(vq) \ - (SVE_SIG_FFR_OFFSET(vq) + SVE_SIG_FFR_SIZE(vq) - SVE_SIG_REGS_OFFSET) + (SVE_SIG_FFR_OFFSET (vq) + SVE_SIG_FFR_SIZE (vq) - SVE_SIG_REGS_OFFSET) -#define SVE_SIG_CONTEXT_SIZE(vq) (SVE_SIG_REGS_OFFSET + SVE_SIG_REGS_SIZE(vq)) +#define SVE_SIG_CONTEXT_SIZE(vq) (SVE_SIG_REGS_OFFSET + SVE_SIG_REGS_SIZE (vq)) /* SVE/FP/SIMD state (NT_ARM_SVE) */ -struct user_sve_header { - __u32 size; /* total meaningful regset content in bytes */ - __u32 max_size; /* maximum possible size for this thread */ - __u16 vl; /* current vector length */ - __u16 max_vl; /* maximum possible vector length */ - __u16 flags; - __u16 __reserved; +struct user_sve_header +{ + __u32 size; /* total meaningful regset content in bytes */ + __u32 max_size; /* maximum possible size for this thread */ + __u16 vl; /* current vector length */ + __u16 max_vl; /* maximum possible vector length */ + __u16 flags; + __u16 __reserved; }; /* Definitions for user_sve_header.flags: */ -#define SVE_PT_REGS_MASK (1 << 0) +#define SVE_PT_REGS_MASK (1 << 0) -#define SVE_PT_REGS_FPSIMD 0 -#define SVE_PT_REGS_SVE SVE_PT_REGS_MASK +#define SVE_PT_REGS_FPSIMD 0 +#define SVE_PT_REGS_SVE SVE_PT_REGS_MASK /* * Common SVE_PT_* flags: * These must be kept in sync with prctl interface in <linux/ptrace.h> */ -#define SVE_PT_VL_INHERIT (PR_SVE_VL_INHERIT >> 16) -#define SVE_PT_VL_ONEXEC (PR_SVE_SET_VL_ONEXEC >> 16) - +#define SVE_PT_VL_INHERIT (PR_SVE_VL_INHERIT >> 16) +#define SVE_PT_VL_ONEXEC (PR_SVE_SET_VL_ONEXEC >> 16) /* * The remainder of the SVE state follows struct user_sve_header. The @@ -165,9 +166,9 @@ struct user_sve_header { */ /* Offset from the start of struct user_sve_header to the register data */ -#define SVE_PT_REGS_OFFSET \ - ((sizeof(struct user_sve_header) + (SVE_VQ_BYTES - 1)) \ - / SVE_VQ_BYTES * SVE_VQ_BYTES) +#define SVE_PT_REGS_OFFSET \ + ((sizeof (struct user_sve_header) + (SVE_VQ_BYTES - 1)) / SVE_VQ_BYTES \ + * SVE_VQ_BYTES) /* * The register data content and layout depends on the value of the @@ -184,9 +185,9 @@ struct user_sve_header { * sizeof(struct user_fpsimd_state). */ -#define SVE_PT_FPSIMD_OFFSET SVE_PT_REGS_OFFSET +#define SVE_PT_FPSIMD_OFFSET SVE_PT_REGS_OFFSET -#define SVE_PT_FPSIMD_SIZE(vq, flags) (sizeof(struct user_fpsimd_state)) +#define SVE_PT_FPSIMD_SIZE(vq, flags) (sizeof (struct user_fpsimd_state)) /* * (flags & SVE_PT_REGS_MASK) == SVE_PT_REGS_SVE case: @@ -213,55 +214,51 @@ struct user_sve_header { * Additional data might be appended in the future. */ -#define SVE_PT_SVE_ZREG_SIZE(vq) SVE_SIG_ZREG_SIZE(vq) -#define SVE_PT_SVE_PREG_SIZE(vq) SVE_SIG_PREG_SIZE(vq) -#define SVE_PT_SVE_FFR_SIZE(vq) SVE_SIG_FFR_SIZE(vq) -#define SVE_PT_SVE_FPSR_SIZE sizeof(__u32) -#define SVE_PT_SVE_FPCR_SIZE sizeof(__u32) +#define SVE_PT_SVE_ZREG_SIZE(vq) SVE_SIG_ZREG_SIZE (vq) +#define SVE_PT_SVE_PREG_SIZE(vq) SVE_SIG_PREG_SIZE (vq) +#define SVE_PT_SVE_FFR_SIZE(vq) SVE_SIG_FFR_SIZE (vq) +#define SVE_PT_SVE_FPSR_SIZE sizeof (__u32) +#define SVE_PT_SVE_FPCR_SIZE sizeof (__u32) #define __SVE_SIG_TO_PT(offset) \ - ((offset) - SVE_SIG_REGS_OFFSET + SVE_PT_REGS_OFFSET) + ((offset) -SVE_SIG_REGS_OFFSET + SVE_PT_REGS_OFFSET) -#define SVE_PT_SVE_OFFSET SVE_PT_REGS_OFFSET +#define SVE_PT_SVE_OFFSET SVE_PT_REGS_OFFSET -#define SVE_PT_SVE_ZREGS_OFFSET \ - __SVE_SIG_TO_PT(SVE_SIG_ZREGS_OFFSET) +#define SVE_PT_SVE_ZREGS_OFFSET __SVE_SIG_TO_PT (SVE_SIG_ZREGS_OFFSET) #define SVE_PT_SVE_ZREG_OFFSET(vq, n) \ - __SVE_SIG_TO_PT(SVE_SIG_ZREG_OFFSET(vq, n)) + __SVE_SIG_TO_PT (SVE_SIG_ZREG_OFFSET (vq, n)) #define SVE_PT_SVE_ZREGS_SIZE(vq) \ - (SVE_PT_SVE_ZREG_OFFSET(vq, SVE_NUM_ZREGS) - SVE_PT_SVE_ZREGS_OFFSET) + (SVE_PT_SVE_ZREG_OFFSET (vq, SVE_NUM_ZREGS) - SVE_PT_SVE_ZREGS_OFFSET) -#define SVE_PT_SVE_PREGS_OFFSET(vq) \ - __SVE_SIG_TO_PT(SVE_SIG_PREGS_OFFSET(vq)) +#define SVE_PT_SVE_PREGS_OFFSET(vq) __SVE_SIG_TO_PT (SVE_SIG_PREGS_OFFSET (vq)) #define SVE_PT_SVE_PREG_OFFSET(vq, n) \ - __SVE_SIG_TO_PT(SVE_SIG_PREG_OFFSET(vq, n)) + __SVE_SIG_TO_PT (SVE_SIG_PREG_OFFSET (vq, n)) #define SVE_PT_SVE_PREGS_SIZE(vq) \ - (SVE_PT_SVE_PREG_OFFSET(vq, SVE_NUM_PREGS) - \ - SVE_PT_SVE_PREGS_OFFSET(vq)) + (SVE_PT_SVE_PREG_OFFSET (vq, SVE_NUM_PREGS) - SVE_PT_SVE_PREGS_OFFSET (vq)) -#define SVE_PT_SVE_FFR_OFFSET(vq) \ - __SVE_SIG_TO_PT(SVE_SIG_FFR_OFFSET(vq)) +#define SVE_PT_SVE_FFR_OFFSET(vq) __SVE_SIG_TO_PT (SVE_SIG_FFR_OFFSET (vq)) -#define SVE_PT_SVE_FPSR_OFFSET(vq) \ - ((SVE_PT_SVE_FFR_OFFSET(vq) + SVE_PT_SVE_FFR_SIZE(vq) + \ - (SVE_VQ_BYTES - 1)) \ - / SVE_VQ_BYTES * SVE_VQ_BYTES) +#define SVE_PT_SVE_FPSR_OFFSET(vq) \ + ((SVE_PT_SVE_FFR_OFFSET (vq) + SVE_PT_SVE_FFR_SIZE (vq) \ + + (SVE_VQ_BYTES - 1)) \ + / SVE_VQ_BYTES * SVE_VQ_BYTES) #define SVE_PT_SVE_FPCR_OFFSET(vq) \ - (SVE_PT_SVE_FPSR_OFFSET(vq) + SVE_PT_SVE_FPSR_SIZE) + (SVE_PT_SVE_FPSR_OFFSET (vq) + SVE_PT_SVE_FPSR_SIZE) /* * Any future extension appended after FPCR must be aligned to the next * 128-bit boundary. */ -#define SVE_PT_SVE_SIZE(vq, flags) \ - ((SVE_PT_SVE_FPCR_OFFSET(vq) + SVE_PT_SVE_FPCR_SIZE \ - - SVE_PT_SVE_OFFSET + (SVE_VQ_BYTES - 1)) \ - / SVE_VQ_BYTES * SVE_VQ_BYTES) +#define SVE_PT_SVE_SIZE(vq, flags) \ + ((SVE_PT_SVE_FPCR_OFFSET (vq) + SVE_PT_SVE_FPCR_SIZE - SVE_PT_SVE_OFFSET \ + + (SVE_VQ_BYTES - 1)) \ + / SVE_VQ_BYTES * SVE_VQ_BYTES) -#define SVE_PT_SIZE(vq, flags) \ - (((flags) & SVE_PT_REGS_MASK) == SVE_PT_REGS_SVE ? \ - SVE_PT_SVE_OFFSET + SVE_PT_SVE_SIZE(vq, flags) \ - : SVE_PT_FPSIMD_OFFSET + SVE_PT_FPSIMD_SIZE(vq, flags)) +#define SVE_PT_SIZE(vq, flags) \ + (((flags) &SVE_PT_REGS_MASK) == SVE_PT_REGS_SVE \ + ? SVE_PT_SVE_OFFSET + SVE_PT_SVE_SIZE (vq, flags) \ + : SVE_PT_FPSIMD_OFFSET + SVE_PT_FPSIMD_SIZE (vq, flags)) #endif /* NAT_AARCH64_SVE_LINUX_SIGCONTEXT_H */ diff --git a/gdb/nat/amd64-linux-siginfo.c b/gdb/nat/amd64-linux-siginfo.c index 00bb5e5..a9a34d6 100644 --- a/gdb/nat/amd64-linux-siginfo.c +++ b/gdb/nat/amd64-linux-siginfo.c @@ -60,6 +60,7 @@ struct nat_siginfo_t union { int _pad[((128 / sizeof (int)) - 4)]; + /* kill() */ struct { @@ -98,6 +99,7 @@ struct nat_siginfo_t { nat_uptr_t _addr; short int _addr_lsb; + struct { nat_uptr_t _lower; @@ -187,6 +189,7 @@ struct compat_siginfo_t { unsigned int _addr; short int _addr_lsb; + struct { unsigned int _lower; @@ -293,7 +296,7 @@ struct __attribute__ ((__aligned__ (8))) compat_x32_siginfo_t #endif #ifndef SEGV_BNDERR -#define SEGV_BNDERR 3 +#define SEGV_BNDERR 3 #endif /* The type of the siginfo object the kernel returns in @@ -333,8 +336,7 @@ compat_siginfo_from_siginfo (compat_siginfo_t *to, const siginfo_t *from) #ifndef __ILP32__ /* The struct compat_x32_siginfo_t doesn't contain cpt_si_lower/cpt_si_upper. */ - else if (to->si_code == SEGV_BNDERR - && to->si_signo == SIGSEGV) + else if (to->si_code == SEGV_BNDERR && to->si_signo == SIGSEGV) { to->cpt_si_addr = from_ptrace.cpt_si_addr; to->cpt_si_lower = from_ptrace.cpt_si_lower; @@ -503,9 +505,6 @@ compat_x32_siginfo_from_siginfo (compat_x32_siginfo_t *to, } } - - - /* Convert the compatible x32 siginfo into system siginfo. */ static void siginfo_from_compat_x32_siginfo (siginfo_t *to, @@ -591,11 +590,9 @@ amd64_linux_siginfo_fixup_common (siginfo_t *ptrace, gdb_byte *inf, else if (mode == FIXUP_X32) { if (direction == 0) - compat_x32_siginfo_from_siginfo ((compat_x32_siginfo_t *) inf, - ptrace); + compat_x32_siginfo_from_siginfo ((compat_x32_siginfo_t *) inf, ptrace); else - siginfo_from_compat_x32_siginfo (ptrace, - (compat_x32_siginfo_t *) inf); + siginfo_from_compat_x32_siginfo (ptrace, (compat_x32_siginfo_t *) inf); return 1; } diff --git a/gdb/nat/amd64-linux-siginfo.h b/gdb/nat/amd64-linux-siginfo.h index 498cb2e..c98458b 100644 --- a/gdb/nat/amd64-linux-siginfo.h +++ b/gdb/nat/amd64-linux-siginfo.h @@ -20,7 +20,7 @@ #ifndef NAT_AMD64_LINUX_SIGINFO_H #define NAT_AMD64_LINUX_SIGINFO_H -#include <signal.h> /* For siginfo_t. */ +#include <signal.h> /* For siginfo_t. */ /* When GDB is built as a 64-bit application on Linux, the PTRACE_GETSIGINFO data is always presented in 64-bit layout. Since @@ -40,13 +40,12 @@ 32 / X32 siginfo -> nat_siginfo -> buffer (to the kernel) */ - /* Kind of siginfo fixup to be performed. */ enum amd64_siginfo_fixup_mode { - FIXUP_32 = 1, /* Fixup for 32bit. */ - FIXUP_X32 = 2 /* Fixup for x32. */ + FIXUP_32 = 1, /* Fixup for 32bit. */ + FIXUP_X32 = 2 /* Fixup for x32. */ }; /* Common code for performing the fixup of the siginfo. */ diff --git a/gdb/nat/fork-inferior.c b/gdb/nat/fork-inferior.c index 968983b..75ccd30 100644 --- a/gdb/nat/fork-inferior.c +++ b/gdb/nat/fork-inferior.c @@ -36,6 +36,7 @@ extern char **environ; class execv_argv { public: + /* EXEC_FILE is the file to run. ALLARGS is a string containing the arguments to the program. If starting with a shell, SHELL_FILE is the shell to run. Otherwise, SHELL_FILE is NULL. */ @@ -48,25 +49,21 @@ public: that the execv functions expect. Note that it is guaranteed that the execv functions do not modify the argv[] array nor the strings to which the array point. */ - char **argv () - { - return const_cast<char **> (&m_argv[0]); - } + char **argv () { return const_cast<char **> (&m_argv[0]); } private: + DISABLE_COPY_AND_ASSIGN (execv_argv); /* Helper methods for constructing the argument vector. */ /* Used when building an argv for a straight execv call, without going via the shell. */ - void init_for_no_shell (const char *exec_file, - const std::string &allargs); + void init_for_no_shell (const char *exec_file, const std::string &allargs); /* Used when building an argv for execing a shell that execs the child program. */ - void init_for_shell (const char *exec_file, - const std::string &allargs, + void init_for_shell (const char *exec_file, const std::string &allargs, const char *shell_file); /* The argument vector built. Holds non-owning pointers. Elements @@ -93,7 +90,6 @@ void execv_argv::init_for_no_shell (const char *exec_file, const std::string &allargs) { - /* Save/work with a copy stored in our storage. The pointers pushed to M_ARGV point directly into M_STORAGE, which is modified in place with the necessary NULL terminators. This avoids N heap @@ -160,8 +156,7 @@ escape_bang_in_quoted_argument (const char *shell_file) /* See declaration. */ -execv_argv::execv_argv (const char *exec_file, - const std::string &allargs, +execv_argv::execv_argv (const char *exec_file, const std::string &allargs, const char *shell_file) { if (shell_file == NULL) @@ -173,8 +168,7 @@ execv_argv::execv_argv (const char *exec_file, /* See declaration. */ void -execv_argv::init_for_shell (const char *exec_file, - const std::string &allargs, +execv_argv::init_for_shell (const char *exec_file, const std::string &allargs, const char *shell_file) { const char *exec_wrapper = get_exec_wrapper (); @@ -232,7 +226,7 @@ execv_argv::init_for_shell (const char *exec_file, } ++p; } - end_scan: +end_scan: if (need_to_quote) { shell_command += '\''; @@ -268,10 +262,9 @@ pid_t fork_inferior (const char *exec_file_arg, const std::string &allargs, char **env, void (*traceme_fun) (), gdb::function_view<void (int)> init_trace_fun, - void (*pre_trace_fun) (), - const char *shell_file_arg, - void (*exec_fun)(const char *file, char * const *argv, - char * const *env)) + void (*pre_trace_fun) (), const char *shell_file_arg, + void (*exec_fun) (const char *file, char *const *argv, + char *const *env)) { pid_t pid; /* Set debug_fork then attach to the child while it sleeps, to debug. */ @@ -339,7 +332,7 @@ fork_inferior (const char *exec_file_arg, const std::string &allargs, if (pre_trace_fun != NULL) (*pre_trace_fun) (); - /* Create the child process. Since the child process is going to + /* Create the child process. Since the child process is going to exec(3) shortly afterwards, try to reduce the overhead by calling vfork(2). However, if PRE_TRACE_FUN is non-null, it's likely that this optimization won't work since there's too much @@ -449,8 +442,7 @@ fork_inferior (const char *exec_file_arg, const std::string &allargs, ptid_t startup_inferior (process_stratum_target *proc_target, pid_t pid, int ntraps, - struct target_waitstatus *last_waitstatus, - ptid_t *last_ptid) + struct target_waitstatus *last_waitstatus, ptid_t *last_ptid) { int pending_execs = ntraps; int terminal_initted = 0; @@ -492,44 +484,44 @@ startup_inferior (process_stratum_target *proc_target, pid_t pid, int ntraps, switch (ws.kind ()) { - case TARGET_WAITKIND_SPURIOUS: - case TARGET_WAITKIND_LOADED: - case TARGET_WAITKIND_FORKED: - case TARGET_WAITKIND_VFORKED: - case TARGET_WAITKIND_SYSCALL_ENTRY: - case TARGET_WAITKIND_SYSCALL_RETURN: - /* Ignore gracefully during startup of the inferior. */ - switch_to_thread (proc_target, event_ptid); - break; + case TARGET_WAITKIND_SPURIOUS: + case TARGET_WAITKIND_LOADED: + case TARGET_WAITKIND_FORKED: + case TARGET_WAITKIND_VFORKED: + case TARGET_WAITKIND_SYSCALL_ENTRY: + case TARGET_WAITKIND_SYSCALL_RETURN: + /* Ignore gracefully during startup of the inferior. */ + switch_to_thread (proc_target, event_ptid); + break; - case TARGET_WAITKIND_SIGNALLED: - target_terminal::ours (); - target_mourn_inferior (event_ptid); - error (_("During startup program terminated with signal %s, %s."), - gdb_signal_to_name (ws.sig ()), - gdb_signal_to_string (ws.sig ())); - return resume_ptid; - - case TARGET_WAITKIND_EXITED: - target_terminal::ours (); - target_mourn_inferior (event_ptid); - if (ws.exit_status ()) - error (_("During startup program exited with code %d."), - ws.exit_status ()); - else - error (_("During startup program exited normally.")); - return resume_ptid; - - case TARGET_WAITKIND_EXECD: - /* Handle EXEC signals as if they were SIGTRAP signals. */ - resume_signal = GDB_SIGNAL_TRAP; - switch_to_thread (proc_target, event_ptid); - break; + case TARGET_WAITKIND_SIGNALLED: + target_terminal::ours (); + target_mourn_inferior (event_ptid); + error (_ ("During startup program terminated with signal %s, %s."), + gdb_signal_to_name (ws.sig ()), + gdb_signal_to_string (ws.sig ())); + return resume_ptid; + + case TARGET_WAITKIND_EXITED: + target_terminal::ours (); + target_mourn_inferior (event_ptid); + if (ws.exit_status ()) + error (_ ("During startup program exited with code %d."), + ws.exit_status ()); + else + error (_ ("During startup program exited normally.")); + return resume_ptid; - case TARGET_WAITKIND_STOPPED: - resume_signal = ws.sig (); - switch_to_thread (proc_target, event_ptid); - break; + case TARGET_WAITKIND_EXECD: + /* Handle EXEC signals as if they were SIGTRAP signals. */ + resume_signal = GDB_SIGNAL_TRAP; + switch_to_thread (proc_target, event_ptid); + break; + + case TARGET_WAITKIND_STOPPED: + resume_signal = ws.sig (); + switch_to_thread (proc_target, event_ptid); + break; } if (resume_signal != GDB_SIGNAL_TRAP) diff --git a/gdb/nat/fork-inferior.h b/gdb/nat/fork-inferior.h index 67c7650..c83dff9 100644 --- a/gdb/nat/fork-inferior.h +++ b/gdb/nat/fork-inferior.h @@ -40,22 +40,17 @@ struct process_stratum_target; /* This function is NOT reentrant. Some of the variables have been made static to ensure that they survive the vfork call. */ -extern pid_t fork_inferior (const char *exec_file_arg, - const std::string &allargs, - char **env, void (*traceme_fun) (), - gdb::function_view<void (int)> init_trace_fun, - void (*pre_trace_fun) (), - const char *shell_file_arg, - void (*exec_fun) (const char *file, - char * const *argv, - char * const *env)); +extern pid_t fork_inferior ( + const char *exec_file_arg, const std::string &allargs, char **env, + void (*traceme_fun) (), gdb::function_view<void (int)> init_trace_fun, + void (*pre_trace_fun) (), const char *shell_file_arg, + void (*exec_fun) (const char *file, char *const *argv, char *const *env)); /* Accept NTRAPS traps from the inferior. Return the ptid of the inferior being started. */ -extern ptid_t startup_inferior (process_stratum_target *proc_target, - pid_t pid, int ntraps, - struct target_waitstatus *mystatus, +extern ptid_t startup_inferior (process_stratum_target *proc_target, pid_t pid, + int ntraps, struct target_waitstatus *mystatus, ptid_t *myptid); /* Perform any necessary tasks before a fork/vfork takes place. ARGS @@ -78,13 +73,13 @@ extern void gdb_flush_out_err (); /* Report an error that happened when starting to trace the inferior (i.e., when the "traceme_fun" callback is called on fork_inferior) and bail out. This function does not return. */ -extern void trace_start_error (const char *fmt, ...) - ATTRIBUTE_NORETURN ATTRIBUTE_PRINTF (1, 2); +extern void trace_start_error (const char *fmt, ...) ATTRIBUTE_NORETURN + ATTRIBUTE_PRINTF (1, 2); /* Like "trace_start_error", but the error message is constructed by combining STRING with the system error message for errno. This function does not return. */ -extern void trace_start_error_with_name (const char *string) - ATTRIBUTE_NORETURN; +extern void +trace_start_error_with_name (const char *string) ATTRIBUTE_NORETURN; #endif /* NAT_FORK_INFERIOR_H */ diff --git a/gdb/nat/gdb_ptrace.h b/gdb/nat/gdb_ptrace.h index a5e3725..c9ddcbb 100644 --- a/gdb/nat/gdb_ptrace.h +++ b/gdb/nat/gdb_ptrace.h @@ -31,40 +31,40 @@ common ptrace requests. */ #ifdef HAVE_PTRACE_H -# include <ptrace.h> +#include <ptrace.h> #elif defined(HAVE_SYS_PTRACE_H) -# include <sys/ptrace.h> +#include <sys/ptrace.h> #endif /* No need to include <unistd.h> since it's already included by "defs.h". */ #ifndef PT_TRACE_ME -# define PT_TRACE_ME 0 +#define PT_TRACE_ME 0 #endif #ifndef PT_READ_I -# define PT_READ_I 1 /* Read word in child's I space. */ +#define PT_READ_I 1 /* Read word in child's I space. */ #endif #ifndef PT_READ_D -# define PT_READ_D 2 /* Read word in child's D space. */ +#define PT_READ_D 2 /* Read word in child's D space. */ #endif #ifndef PT_READ_U -# define PT_READ_U 3 /* Read word in child's U space. */ +#define PT_READ_U 3 /* Read word in child's U space. */ #endif #ifndef PT_WRITE_I -# define PT_WRITE_I 4 /* Write word in child's I space. */ +#define PT_WRITE_I 4 /* Write word in child's I space. */ #endif #ifndef PT_WRITE_D -# define PT_WRITE_D 5 /* Write word in child's D space. */ +#define PT_WRITE_D 5 /* Write word in child's D space. */ #endif #ifndef PT_WRITE_U -# define PT_WRITE_U 6 /* Write word in child's U space. */ +#define PT_WRITE_U 6 /* Write word in child's U space. */ #endif /* HP-UX doesn't define PT_CONTINUE and PT_STEP. Instead of those two @@ -73,37 +73,37 @@ which apparently is what is wanted by the HP-UX native code. */ #ifndef PT_CONTINUE -# ifdef PT_CONTIN1 -# define PT_CONTINUE PT_CONTIN1 -# else -# define PT_CONTINUE 7 /* Continue the child. */ -# endif +#ifdef PT_CONTIN1 +#define PT_CONTINUE PT_CONTIN1 +#else +#define PT_CONTINUE 7 /* Continue the child. */ +#endif #endif #ifndef PT_KILL -# define PT_KILL 8 /* Kill the child process. */ +#define PT_KILL 8 /* Kill the child process. */ #endif #ifndef PT_STEP -# ifdef PT_SINGLE1 -# define PT_STEP PT_SINGLE1 -# else -# define PT_STEP 9 /* Single step the child. */ -# endif +#ifdef PT_SINGLE1 +#define PT_STEP PT_SINGLE1 +#else +#define PT_STEP 9 /* Single step the child. */ +#endif #endif /* Not all systems support attaching and detaching. */ #ifndef PT_ATTACH -# ifdef PTRACE_ATTACH -# define PT_ATTACH PTRACE_ATTACH -# endif +#ifdef PTRACE_ATTACH +#define PT_ATTACH PTRACE_ATTACH +#endif #endif #ifndef PT_DETACH -# ifdef PTRACE_DETACH -# define PT_DETACH PTRACE_DETACH -# endif +#ifdef PTRACE_DETACH +#define PT_DETACH PTRACE_DETACH +#endif #endif /* For systems such as HP/UX that do not provide PT_SYSCALL, define it @@ -114,11 +114,11 @@ and there is probably no special request that we would be required to use when resuming the execution of our program. */ #ifndef PT_SYSCALL -# ifdef PTRACE_SYSCALL -# define PT_SYSCALL PTRACE_SYSCALL +#ifdef PTRACE_SYSCALL +#define PT_SYSCALL PTRACE_SYSCALL #else -# define PT_SYSCALL PT_CONTINUE -# endif +#define PT_SYSCALL PT_CONTINUE +#endif #endif /* Some systems, at least AIX and HP-UX have a ptrace with five @@ -127,19 +127,17 @@ zero. */ #ifdef PTRACE_TYPE_ARG5 -# ifdef HAVE_PTRACE64 -# define ptrace(request, pid, addr, data) \ - ptrace64 (request, pid, addr, data, 0) -# undef PTRACE_TYPE_ARG3 -# define PTRACE_TYPE_ARG3 long long -# else -# define ptrace(request, pid, addr, data) \ - ptrace (request, pid, addr, data, 0) -# endif +#ifdef HAVE_PTRACE64 +#define ptrace(request, pid, addr, data) ptrace64 (request, pid, addr, data, 0) +#undef PTRACE_TYPE_ARG3 +#define PTRACE_TYPE_ARG3 long long +#else +#define ptrace(request, pid, addr, data) ptrace (request, pid, addr, data, 0) +#endif #else /* Wrapper that avoids adding a pointless cast to all callers. */ -# define ptrace(request, pid, addr, data) \ - ptrace ((PTRACE_TYPE_ARG1) request, pid, addr, data) +#define ptrace(request, pid, addr, data) \ + ptrace ((PTRACE_TYPE_ARG1) request, pid, addr, data) #endif #endif /* NAT_GDB_PTRACE_H */ diff --git a/gdb/nat/gdb_thread_db.h b/gdb/nat/gdb_thread_db.h index 413176c..9e682bf 100644 --- a/gdb/nat/gdb_thread_db.h +++ b/gdb/nat/gdb_thread_db.h @@ -39,15 +39,15 @@ typedef td_err_e (td_init_ftype) (void); -typedef td_err_e (td_ta_new_ftype) (struct ps_prochandle * ps, +typedef td_err_e (td_ta_new_ftype) (struct ps_prochandle *ps, td_thragent_t **ta); typedef td_err_e (td_ta_delete_ftype) (td_thragent_t *ta_p); typedef td_err_e (td_ta_map_lwp2thr_ftype) (const td_thragent_t *ta, lwpid_t lwpid, td_thrhandle_t *th); typedef td_err_e (td_ta_thr_iter_ftype) (const td_thragent_t *ta, - td_thr_iter_f *callback, void *cbdata_p, - td_thr_state_e state, int ti_pri, - sigset_t *ti_sigmask_p, + td_thr_iter_f *callback, + void *cbdata_p, td_thr_state_e state, + int ti_pri, sigset_t *ti_sigmask_p, unsigned int ti_user_flags); typedef td_err_e (td_ta_event_addr_ftype) (const td_thragent_t *ta, td_event_e event, td_notify_t *ptr); @@ -65,12 +65,13 @@ typedef td_err_e (td_thr_event_enable_ftype) (const td_thrhandle_t *th, typedef td_err_e (td_thr_tls_get_addr_ftype) (const td_thrhandle_t *th, psaddr_t map_address, - size_t offset, psaddr_t *address); + size_t offset, + psaddr_t *address); typedef td_err_e (td_thr_tlsbase_ftype) (const td_thrhandle_t *th, unsigned long int modid, psaddr_t *base); -typedef const char ** (td_symbol_list_ftype) (void); +typedef const char **(td_symbol_list_ftype) (void); typedef td_err_e (td_ta_delete_ftype) (td_thragent_t *); #endif /* NAT_GDB_THREAD_DB_H */ diff --git a/gdb/nat/glibc_thread_db.h b/gdb/nat/glibc_thread_db.h index 598805d..825693d 100644 --- a/gdb/nat/glibc_thread_db.h +++ b/gdb/nat/glibc_thread_db.h @@ -27,7 +27,6 @@ #include <sys/types.h> #include <sys/procfs.h> - /* Error codes of the library. */ typedef enum { @@ -54,11 +53,10 @@ typedef enum TD_NOXREGS, /* X register set not available for given thread. */ TD_TLSDEFER, /* Thread has not yet allocated TLS for given module. */ TD_NOTALLOC = TD_TLSDEFER, - TD_VERSION, /* Version if libpthread and libthread_db do not match. */ - TD_NOTLS /* There is no TLS segment in the given module. */ + TD_VERSION, /* Version if libpthread and libthread_db do not match. */ + TD_NOTLS /* There is no TLS segment in the given module. */ } td_err_e; - /* Possible thread states. TD_THR_ANY_STATE is a pseudo-state used to select threads regardless of state in td_ta_thr_iter(). */ typedef enum @@ -82,7 +80,6 @@ typedef enum TD_THR_SYSTEM } td_thr_type_e; - /* Types of the debugging library. */ /* Handle for a process. This type is opaque. */ @@ -95,21 +92,18 @@ typedef struct td_thrhandle psaddr_t th_unique; } td_thrhandle_t; - /* Forward declaration of a type defined by and for the dynamic linker. */ struct link_map; - /* Flags for `td_ta_thr_iter'. */ -#define TD_THR_ANY_USER_FLAGS 0xffffffff -#define TD_THR_LOWEST_PRIORITY -20 -#define TD_SIGNO_MASK NULL - +#define TD_THR_ANY_USER_FLAGS 0xffffffff +#define TD_THR_LOWEST_PRIORITY -20 +#define TD_SIGNO_MASK NULL -#define TD_EVENTSIZE 2 -#define BT_UISHIFT 5 /* log base 2 of BT_NBIPUI, to extract word index */ -#define BT_NBIPUI (1 << BT_UISHIFT) /* n bits per uint */ -#define BT_UIMASK (BT_NBIPUI - 1) /* to extract bit index */ +#define TD_EVENTSIZE 2 +#define BT_UISHIFT 5 /* log base 2 of BT_NBIPUI, to extract word index */ +#define BT_NBIPUI (1 << BT_UISHIFT) /* n bits per uint */ +#define BT_UIMASK (BT_NBIPUI - 1) /* to extract bit index */ /* Bitmask of enabled events. */ typedef struct td_thr_events @@ -118,24 +112,26 @@ typedef struct td_thr_events } td_thr_events_t; /* Event set manipulation macros. */ -#define __td_eventmask(n) \ - (UINT32_C (1) << (((n) - 1) & BT_UIMASK)) -#define __td_eventword(n) \ - ((UINT32_C ((n) - 1)) >> BT_UISHIFT) - -#define td_event_emptyset(setp) \ - do { \ - int __i; \ - for (__i = TD_EVENTSIZE; __i > 0; --__i) \ - (setp)->event_bits[__i - 1] = 0; \ - } while (0) - -#define td_event_fillset(setp) \ - do { \ - int __i; \ - for (__i = TD_EVENTSIZE; __i > 0; --__i) \ - (setp)->event_bits[__i - 1] = UINT32_C (0xffffffff); \ - } while (0) +#define __td_eventmask(n) (UINT32_C (1) << (((n) -1) & BT_UIMASK)) +#define __td_eventword(n) ((UINT32_C ((n) -1)) >> BT_UISHIFT) + +#define td_event_emptyset(setp) \ + do \ + { \ + int __i; \ + for (__i = TD_EVENTSIZE; __i > 0; --__i) \ + (setp)->event_bits[__i - 1] = 0; \ + } \ + while (0) + +#define td_event_fillset(setp) \ + do \ + { \ + int __i; \ + for (__i = TD_EVENTSIZE; __i > 0; --__i) \ + (setp)->event_bits[__i - 1] = UINT32_C (0xffffffff); \ + } \ + while (0) #define td_event_addset(setp, n) \ (((setp)->event_bits[__td_eventword (n)]) |= __td_eventmask (n)) @@ -144,10 +140,10 @@ typedef struct td_thr_events #define td_eventismember(setp, n) \ (__td_eventmask (n) & ((setp)->event_bits[__td_eventword (n)])) #if TD_EVENTSIZE == 2 -# define td_eventisempty(setp) \ +#define td_eventisempty(setp) \ (!((setp)->event_bits[0]) && !((setp)->event_bits[1])) #else -# error "td_eventisempty must be changed to match TD_EVENTSIZE" +#error "td_eventisempty must be changed to match TD_EVENTSIZE" #endif /* Events reportable by the thread implementation. */ @@ -171,124 +167,118 @@ typedef enum TD_TIMEOUT, /* Conditional variable wait timed out. */ TD_MIN_EVENT_NUM = TD_READY, TD_MAX_EVENT_NUM = TD_TIMEOUT, - TD_EVENTS_ENABLE = 31 /* Event reporting enabled. */ + TD_EVENTS_ENABLE = 31 /* Event reporting enabled. */ } td_event_e; /* Values representing the different ways events are reported. */ typedef enum { - NOTIFY_BPT, /* User must insert breakpoint at u.bptaddr. */ - NOTIFY_AUTOBPT, /* Breakpoint at u.bptaddr is automatically + NOTIFY_BPT, /* User must insert breakpoint at u.bptaddr. */ + NOTIFY_AUTOBPT, /* Breakpoint at u.bptaddr is automatically inserted. */ - NOTIFY_SYSCALL /* System call u.syscallno will be invoked. */ + NOTIFY_SYSCALL /* System call u.syscallno will be invoked. */ } td_notify_e; /* Description how event type is reported. */ typedef struct td_notify { - td_notify_e type; /* Way the event is reported. */ + td_notify_e type; /* Way the event is reported. */ + union { - psaddr_t bptaddr; /* Address of breakpoint. */ - int syscallno; /* Number of system call used. */ + psaddr_t bptaddr; /* Address of breakpoint. */ + int syscallno; /* Number of system call used. */ } u; } td_notify_t; /* Structure used to report event. */ typedef struct td_event_msg { - td_event_e event; /* Event type being reported. */ - const td_thrhandle_t *th_p; /* Thread reporting the event. */ + td_event_e event; /* Event type being reported. */ + const td_thrhandle_t *th_p; /* Thread reporting the event. */ + union { -# if 0 +#if 0 td_synchandle_t *sh; /* Handle of synchronization object. */ #endif - uintptr_t data; /* Event specific data. */ + uintptr_t data; /* Event specific data. */ } msg; } td_event_msg_t; /* Structure containing event data available in each thread structure. */ typedef struct { - td_thr_events_t eventmask; /* Mask of enabled events. */ - td_event_e eventnum; /* Number of last event. */ - void *eventdata; /* Data associated with event. */ + td_thr_events_t eventmask; /* Mask of enabled events. */ + td_event_e eventnum; /* Number of last event. */ + void *eventdata; /* Data associated with event. */ } td_eventbuf_t; - /* Gathered statistics about the process. */ typedef struct td_ta_stats { - int nthreads; /* Total number of threads in use. */ - int r_concurrency; /* Concurrency level requested by user. */ - int nrunnable_num; /* Average runnable threads, numerator. */ - int nrunnable_den; /* Average runnable threads, denominator. */ - int a_concurrency_num; /* Achieved concurrency level, numerator. */ - int a_concurrency_den; /* Achieved concurrency level, denominator. */ - int nlwps_num; /* Average number of processes in use, + int nthreads; /* Total number of threads in use. */ + int r_concurrency; /* Concurrency level requested by user. */ + int nrunnable_num; /* Average runnable threads, numerator. */ + int nrunnable_den; /* Average runnable threads, denominator. */ + int a_concurrency_num; /* Achieved concurrency level, numerator. */ + int a_concurrency_den; /* Achieved concurrency level, denominator. */ + int nlwps_num; /* Average number of processes in use, numerator. */ - int nlwps_den; /* Average number of processes in use, + int nlwps_den; /* Average number of processes in use, denominator. */ - int nidle_num; /* Average number of idling processes, + int nidle_num; /* Average number of idling processes, numerator. */ - int nidle_den; /* Average number of idling processes, + int nidle_den; /* Average number of idling processes, denominator. */ } td_ta_stats_t; - /* Since Sun's library is based on Solaris threads we have to define a few types to map them to POSIX threads. */ typedef pthread_t thread_t; typedef pthread_key_t thread_key_t; - /* Callback for iteration over threads. */ typedef int td_thr_iter_f (const td_thrhandle_t *, void *); /* Callback for iteration over thread local data. */ typedef int td_key_iter_f (thread_key_t, void (*) (void *), void *); - - /* Forward declaration. This has to be defined by the user. */ struct ps_prochandle; - /* Information about the thread. */ typedef struct td_thrinfo { - td_thragent_t *ti_ta_p; /* Process handle. */ - unsigned int ti_user_flags; /* Unused. */ - thread_t ti_tid; /* Thread ID returned by + td_thragent_t *ti_ta_p; /* Process handle. */ + unsigned int ti_user_flags; /* Unused. */ + thread_t ti_tid; /* Thread ID returned by pthread_create(). */ - char *ti_tls; /* Pointer to thread-local data. */ - psaddr_t ti_startfunc; /* Start function passed to + char *ti_tls; /* Pointer to thread-local data. */ + psaddr_t ti_startfunc; /* Start function passed to pthread_create(). */ - psaddr_t ti_stkbase; /* Base of thread's stack. */ - long int ti_stksize; /* Size of thread's stack. */ - psaddr_t ti_ro_area; /* Unused. */ - int ti_ro_size; /* Unused. */ - td_thr_state_e ti_state; /* Thread state. */ - unsigned char ti_db_suspended; /* Nonzero if suspended by debugger. */ - td_thr_type_e ti_type; /* Type of the thread (system vs + psaddr_t ti_stkbase; /* Base of thread's stack. */ + long int ti_stksize; /* Size of thread's stack. */ + psaddr_t ti_ro_area; /* Unused. */ + int ti_ro_size; /* Unused. */ + td_thr_state_e ti_state; /* Thread state. */ + unsigned char ti_db_suspended; /* Nonzero if suspended by debugger. */ + td_thr_type_e ti_type; /* Type of the thread (system vs user thread). */ - intptr_t ti_pc; /* Unused. */ - intptr_t ti_sp; /* Unused. */ - short int ti_flags; /* Unused. */ - int ti_pri; /* Thread priority. */ - lwpid_t ti_lid; /* Kernel PID for this thread. */ - sigset_t ti_sigmask; /* Signal mask. */ - unsigned char ti_traceme; /* Nonzero if event reporting + intptr_t ti_pc; /* Unused. */ + intptr_t ti_sp; /* Unused. */ + short int ti_flags; /* Unused. */ + int ti_pri; /* Thread priority. */ + lwpid_t ti_lid; /* Kernel PID for this thread. */ + sigset_t ti_sigmask; /* Signal mask. */ + unsigned char ti_traceme; /* Nonzero if event reporting enabled. */ - unsigned char ti_preemptflag; /* Unused. */ - unsigned char ti_pirecflag; /* Unused. */ - sigset_t ti_pending; /* Set of pending signals. */ - td_thr_events_t ti_events; /* Set of enabled events. */ + unsigned char ti_preemptflag; /* Unused. */ + unsigned char ti_pirecflag; /* Unused. */ + sigset_t ti_pending; /* Set of pending signals. */ + td_thr_events_t ti_events; /* Set of enabled events. */ } td_thrinfo_t; - - /* Prototypes for exported library functions. */ /* Initialize the thread debug support library. */ @@ -324,7 +314,6 @@ extern td_err_e td_ta_map_id2thr (const td_thragent_t *__ta, pthread_t __pt, extern td_err_e td_ta_map_lwp2thr (const td_thragent_t *__ta, lwpid_t __lwpid, td_thrhandle_t *__th); - /* Call for each thread in a process associated with TA the callback function CALLBACK. */ extern td_err_e td_ta_thr_iter (const td_thragent_t *__ta, @@ -337,7 +326,6 @@ extern td_err_e td_ta_thr_iter (const td_thragent_t *__ta, extern td_err_e td_ta_tsd_iter (const td_thragent_t *__ta, td_key_iter_f *__ki, void *__p); - /* Get event address for EVENT. */ extern td_err_e td_ta_event_addr (const td_thragent_t *__ta, td_event_e __event, td_notify_t *__ptr); @@ -354,11 +342,9 @@ extern td_err_e td_ta_clear_event (const td_thragent_t *__ta, extern td_err_e td_ta_event_getmsg (const td_thragent_t *__ta, td_event_msg_t *__msg); - /* Set suggested concurrency level for process associated with TA. */ extern td_err_e td_ta_setconcurrency (const td_thragent_t *__ta, int __level); - /* Enable collecting statistics for process associated with TA. */ extern td_err_e td_ta_enable_stats (const td_thragent_t *__ta, int __enable); @@ -369,7 +355,6 @@ extern td_err_e td_ta_reset_stats (const td_thragent_t *__ta); extern td_err_e td_ta_get_stats (const td_thragent_t *__ta, td_ta_stats_t *__statsp); - /* Validate that TH is a thread handle. */ extern td_err_e td_thr_validate (const td_thrhandle_t *__th); @@ -403,18 +388,15 @@ extern td_err_e td_thr_setgregs (const td_thrhandle_t *__th, extern td_err_e td_thr_setxregs (const td_thrhandle_t *__th, const void *__addr); - /* Get address of the given module's TLS storage area for the given thread. */ extern td_err_e td_thr_tlsbase (const td_thrhandle_t *__th, - unsigned long int __modid, - psaddr_t *__base); + unsigned long int __modid, psaddr_t *__base); /* Get address of thread local variable. */ extern td_err_e td_thr_tls_get_addr (const td_thrhandle_t *__th, psaddr_t __map_address, size_t __offset, psaddr_t *__address); - /* Enable reporting for EVENT for thread TH. */ extern td_err_e td_thr_event_enable (const td_thrhandle_t *__th, int __event); @@ -430,11 +412,9 @@ extern td_err_e td_thr_clear_event (const td_thrhandle_t *__th, extern td_err_e td_thr_event_getmsg (const td_thrhandle_t *__th, td_event_msg_t *__msg); - /* Set priority of thread TH. */ extern td_err_e td_thr_setprio (const td_thrhandle_t *__th, int __prio); - /* Set pending signals for thread TH. */ extern td_err_e td_thr_setsigpending (const td_thrhandle_t *__th, unsigned char __n, const sigset_t *__ss); @@ -443,12 +423,10 @@ extern td_err_e td_thr_setsigpending (const td_thrhandle_t *__th, extern td_err_e td_thr_sigsetmask (const td_thrhandle_t *__th, const sigset_t *__ss); - /* Return thread local data associated with key TK in thread TH. */ extern td_err_e td_thr_tsd (const td_thrhandle_t *__th, const thread_key_t __tk, void **__data); - /* Suspend execution of thread TH. */ extern td_err_e td_thr_dbsuspend (const td_thrhandle_t *__th); diff --git a/gdb/nat/linux-btrace.c b/gdb/nat/linux-btrace.c index c5b3f1c..138a6e3 100644 --- a/gdb/nat/linux-btrace.c +++ b/gdb/nat/linux-btrace.c @@ -277,7 +277,7 @@ perf_event_sample_ok (const struct perf_event_sample *sample) part at the end and its upper part at the beginning of the buffer. */ static std::vector<btrace_block> * -perf_event_read_bts (struct btrace_target_info* tinfo, const uint8_t *begin, +perf_event_read_bts (struct btrace_target_info *tinfo, const uint8_t *begin, const uint8_t *end, const uint8_t *start, size_t size) { std::vector<btrace_block> *btrace = new std::vector<btrace_block>; @@ -338,7 +338,7 @@ perf_event_read_bts (struct btrace_target_info* tinfo, const uint8_t *begin, if (!perf_event_sample_ok (psample)) { - warning (_("Branch trace may be incomplete.")); + warning (_ ("Branch trace may be incomplete.")); break; } @@ -432,19 +432,21 @@ diagnose_perf_event_open_fail () errno = 0; gdb_file_up file = gdb_fopen_cloexec (filename, "r"); if (file.get () == nullptr) - error (_("Failed to open %s (%s). Your system does not support " - "process recording."), filename, safe_strerror (errno)); + error (_ ("Failed to open %s (%s). Your system does not support " + "process recording."), + filename, safe_strerror (errno)); int level, found = fscanf (file.get (), "%d", &level); if (found == 1 && level > 2) - error (_("You do not have permission to record the process. " - "Try setting %s to 2 or less."), filename); + error (_ ("You do not have permission to record the process. " + "Try setting %s to 2 or less."), + filename); } break; } - error (_("Failed to start recording: %s"), safe_strerror (errno)); + error (_ ("Failed to start recording: %s"), safe_strerror (errno)); } /* Enable branch tracing in BTS format. */ @@ -458,10 +460,10 @@ linux_enable_bts (ptid_t ptid, const struct btrace_config_bts *conf) int pid, pg; if (!cpu_supports_bts ()) - error (_("BTS support has been disabled for the target cpu.")); + error (_ ("BTS support has been disabled for the target cpu.")); - gdb::unique_xmalloc_ptr<btrace_target_info> tinfo - (XCNEW (btrace_target_info)); + gdb::unique_xmalloc_ptr<btrace_target_info> tinfo ( + XCNEW (btrace_target_info)); tinfo->ptid = ptid; tinfo->conf.format = BTRACE_FORMAT_BTS; @@ -530,13 +532,13 @@ linux_enable_bts (ptid_t ptid, const struct btrace_config_bts *conf) } if (pages == 0) - error (_("Failed to map trace buffer: %s."), safe_strerror (errno)); + error (_ ("Failed to map trace buffer: %s."), safe_strerror (errno)); - struct perf_event_mmap_page *header = (struct perf_event_mmap_page *) - data.get (); + struct perf_event_mmap_page *header + = (struct perf_event_mmap_page *) data.get (); data_offset = PAGE_SIZE; -#if defined (PERF_ATTR_SIZE_VER5) +#if defined(PERF_ATTR_SIZE_VER5) if (offsetof (struct perf_event_mmap_page, data_size) <= header->size) { __u64 data_size; @@ -548,7 +550,7 @@ linux_enable_bts (ptid_t ptid, const struct btrace_config_bts *conf) /* Check for overflows. */ if ((__u64) size != data_size) - error (_("Failed to determine trace buffer size.")); + error (_ ("Failed to determine trace buffer size.")); } #endif /* defined (PERF_ATTR_SIZE_VER5) */ @@ -563,7 +565,7 @@ linux_enable_bts (ptid_t ptid, const struct btrace_config_bts *conf) return tinfo.release (); } -#if defined (PERF_ATTR_SIZE_VER5) +#if defined(PERF_ATTR_SIZE_VER5) /* Determine the event type. */ @@ -580,21 +582,23 @@ perf_event_pt_event_type () case EACCES: case EFAULT: case EPERM: - error (_("Failed to open %s (%s). You do not have permission " - "to use Intel PT."), filename, safe_strerror (errno)); + error (_ ("Failed to open %s (%s). You do not have permission " + "to use Intel PT."), + filename, safe_strerror (errno)); case ENOTDIR: case ENOENT: - error (_("Failed to open %s (%s). Your system does not support " - "Intel PT."), filename, safe_strerror (errno)); + error (_ ("Failed to open %s (%s). Your system does not support " + "Intel PT."), + filename, safe_strerror (errno)); default: - error (_("Failed to open %s: %s."), filename, safe_strerror (errno)); + error (_ ("Failed to open %s: %s."), filename, safe_strerror (errno)); } int type, found = fscanf (file.get (), "%d", &type); if (found != 1) - error (_("Failed to read the PT event type from %s."), filename); + error (_ ("Failed to read the PT event type from %s."), filename); return type; } @@ -612,8 +616,8 @@ linux_enable_pt (ptid_t ptid, const struct btrace_config_pt *conf) if (pid == 0) pid = ptid.pid (); - gdb::unique_xmalloc_ptr<btrace_target_info> tinfo - (XCNEW (btrace_target_info)); + gdb::unique_xmalloc_ptr<btrace_target_info> tinfo ( + XCNEW (btrace_target_info)); tinfo->ptid = ptid; tinfo->conf.format = BTRACE_FORMAT_PT; @@ -635,10 +639,10 @@ linux_enable_pt (ptid_t ptid, const struct btrace_config_pt *conf) scoped_mmap data (nullptr, PAGE_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd.get (), 0); if (data.get () == MAP_FAILED) - error (_("Failed to map trace user page: %s."), safe_strerror (errno)); + error (_ ("Failed to map trace user page: %s."), safe_strerror (errno)); - struct perf_event_mmap_page *header = (struct perf_event_mmap_page *) - data.get (); + struct perf_event_mmap_page *header + = (struct perf_event_mmap_page *) data.get (); header->aux_offset = header->data_offset + header->data_size; @@ -685,7 +689,7 @@ linux_enable_pt (ptid_t ptid, const struct btrace_config_pt *conf) } if (pages == 0) - error (_("Failed to map trace buffer: %s."), safe_strerror (errno)); + error (_ ("Failed to map trace buffer: %s."), safe_strerror (errno)); pt->pt.size = aux.size (); pt->pt.mem = (const uint8_t *) aux.release (); @@ -703,7 +707,7 @@ linux_enable_pt (ptid_t ptid, const struct btrace_config_pt *conf) static struct btrace_target_info * linux_enable_pt (ptid_t ptid, const struct btrace_config_pt *conf) { - error (_("Intel Processor Trace support was disabled at compile time.")); + error (_ ("Intel Processor Trace support was disabled at compile time.")); } #endif /* !defined (PERF_ATTR_SIZE_VER5) */ @@ -716,10 +720,10 @@ linux_enable_btrace (ptid_t ptid, const struct btrace_config *conf) switch (conf->format) { case BTRACE_FORMAT_NONE: - error (_("Bad branch trace format.")); + error (_ ("Bad branch trace format.")); default: - error (_("Unknown branch trace format.")); + error (_ ("Unknown branch trace format.")); case BTRACE_FORMAT_BTS: return linux_enable_bts (ptid, &conf->bts); @@ -734,7 +738,7 @@ linux_enable_btrace (ptid_t ptid, const struct btrace_config *conf) static enum btrace_error linux_disable_bts (struct btrace_tinfo_bts *tinfo) { - munmap((void *) tinfo->header, tinfo->bts.size + PAGE_SIZE); + munmap ((void *) tinfo->header, tinfo->bts.size + PAGE_SIZE); close (tinfo->file); return BTRACE_ERR_NONE; @@ -745,8 +749,8 @@ linux_disable_bts (struct btrace_tinfo_bts *tinfo) static enum btrace_error linux_disable_pt (struct btrace_tinfo_pt *tinfo) { - munmap((void *) tinfo->pt.mem, tinfo->pt.size); - munmap((void *) tinfo->header, PAGE_SIZE); + munmap ((void *) tinfo->pt.mem, tinfo->pt.size); + munmap ((void *) tinfo->header, PAGE_SIZE); close (tinfo->file); return BTRACE_ERR_NONE; @@ -785,8 +789,7 @@ linux_disable_btrace (struct btrace_target_info *tinfo) static enum btrace_error linux_read_bts (struct btrace_data_bts *btrace, - struct btrace_target_info *tinfo, - enum btrace_read_type type) + struct btrace_target_info *tinfo, enum btrace_read_type type) { struct perf_event_buffer *pevent; const uint8_t *begin, *end, *start; @@ -887,8 +890,7 @@ linux_fill_btrace_pt_config (struct btrace_data_pt_config *conf) given by TINFO into BTRACE using the TYPE reading method. */ static enum btrace_error -linux_read_pt (struct btrace_data_pt *btrace, - struct btrace_target_info *tinfo, +linux_read_pt (struct btrace_data_pt *btrace, struct btrace_target_info *tinfo, enum btrace_read_type type) { struct perf_event_buffer *pt; @@ -914,7 +916,7 @@ linux_read_pt (struct btrace_data_pt *btrace, return BTRACE_ERR_NONE; } - internal_error (_("Unknown btrace read type.")); + internal_error (_ ("Unknown btrace read type.")); } /* See linux-btrace.h. */ @@ -945,7 +947,7 @@ linux_read_btrace (struct btrace_data *btrace, return linux_read_pt (&btrace->variant.pt, tinfo, type); } - internal_error (_("Unkown branch trace format.")); + internal_error (_ ("Unkown branch trace format.")); } /* See linux-btrace.h. */ diff --git a/gdb/nat/linux-btrace.h b/gdb/nat/linux-btrace.h index ab69647..56fa7f4 100644 --- a/gdb/nat/linux-btrace.h +++ b/gdb/nat/linux-btrace.h @@ -24,7 +24,7 @@ #include "gdbsupport/btrace-common.h" #if HAVE_LINUX_PERF_EVENT_H -# include <linux/perf_event.h> +#include <linux/perf_event.h> #endif struct target_ops; @@ -104,7 +104,7 @@ struct btrace_target_info /* See to_enable_btrace in target.h. */ extern struct btrace_target_info * - linux_enable_btrace (ptid_t ptid, const struct btrace_config *conf); +linux_enable_btrace (ptid_t ptid, const struct btrace_config *conf); /* See to_disable_btrace in target.h. */ extern enum btrace_error linux_disable_btrace (struct btrace_target_info *ti); @@ -116,6 +116,6 @@ extern enum btrace_error linux_read_btrace (struct btrace_data *btrace, /* See to_btrace_conf in target.h. */ extern const struct btrace_config * - linux_btrace_conf (const struct btrace_target_info *); +linux_btrace_conf (const struct btrace_target_info *); #endif /* NAT_LINUX_BTRACE_H */ diff --git a/gdb/nat/linux-namespaces.c b/gdb/nat/linux-namespaces.c index 4b1fee1..f398129 100644 --- a/gdb/nat/linux-namespaces.c +++ b/gdb/nat/linux-namespaces.c @@ -97,8 +97,7 @@ linux_ns_filename (struct linux_ns *ns, int pid) static char filename[PATH_MAX]; gdb_assert (pid > 0); - xsnprintf (filename, sizeof (filename), "/proc/%d/ns/%s", pid, - ns->filename); + xsnprintf (filename, sizeof (filename), "/proc/%d/ns/%s", pid, ns->filename); return filename; } @@ -109,15 +108,9 @@ linux_ns_filename (struct linux_ns *ns, int pid) static struct linux_ns * linux_ns_get_namespace (enum linux_ns_type type) { - static struct linux_ns namespaces[NUM_LINUX_NS_TYPES] = - { - { "ipc" }, - { "mnt" }, - { "net" }, - { "pid" }, - { "user" }, - { "uts" }, - }; + static struct linux_ns namespaces[NUM_LINUX_NS_TYPES] = { + { "ipc" }, { "mnt" }, { "net" }, { "pid" }, { "user" }, { "uts" }, + }; struct linux_ns *ns; gdb_assert (type >= 0 && type < NUM_LINUX_NS_TYPES); @@ -220,58 +213,57 @@ linux_ns_same (pid_t pid, enum linux_ns_type type) /* Mount namespace helper message types. */ enum mnsh_msg_type - { - /* A communication error occurred. Receipt of this message +{ + /* A communication error occurred. Receipt of this message by either end will cause an assertion failure in the main process. */ - MNSH_MSG_ERROR, + MNSH_MSG_ERROR, - /* Requests, sent from the main process to the helper. */ + /* Requests, sent from the main process to the helper. */ - /* A request that the helper call setns. Arguments should + /* A request that the helper call setns. Arguments should be passed in FD and INT1. Helper should respond with a MNSH_RET_INT. */ - MNSH_REQ_SETNS, + MNSH_REQ_SETNS, - /* A request that the helper call open. Arguments should + /* A request that the helper call open. Arguments should be passed in BUF, INT1 and INT2. The filename (in BUF) should include a terminating NUL character. The helper should respond with a MNSH_RET_FD. */ - MNSH_REQ_OPEN, + MNSH_REQ_OPEN, - /* A request that the helper call unlink. The single + /* A request that the helper call unlink. The single argument (the filename) should be passed in BUF, and should include a terminating NUL character. The helper should respond with a MNSH_RET_INT. */ - MNSH_REQ_UNLINK, + MNSH_REQ_UNLINK, - /* A request that the helper call readlink. The single + /* A request that the helper call readlink. The single argument (the filename) should be passed in BUF, and should include a terminating NUL character. The helper should respond with a MNSH_RET_INTSTR. */ - MNSH_REQ_READLINK, + MNSH_REQ_READLINK, - /* Responses, sent to the main process from the helper. */ + /* Responses, sent to the main process from the helper. */ - /* Return an integer in INT1 and errno in INT2. */ - MNSH_RET_INT, + /* Return an integer in INT1 and errno in INT2. */ + MNSH_RET_INT, - /* Return a file descriptor in FD if one was opened or an + /* Return a file descriptor in FD if one was opened or an integer in INT1 otherwise. Return errno in INT2. */ - MNSH_RET_FD, + MNSH_RET_FD, - /* Return an integer in INT1, errno in INT2, and optionally + /* Return an integer in INT1, errno in INT2, and optionally some data in BUF. */ - MNSH_RET_INTSTR, - }; + MNSH_RET_INTSTR, +}; /* Print a string representation of a message using debug_printf. This function is not async-signal-safe so should never be called from the helper. */ static void -mnsh_debug_print_message (enum mnsh_msg_type type, - int fd, int int1, int int2, +mnsh_debug_print_message (enum mnsh_msg_type type, int fd, int int1, int int2, const void *buf, int bufsiz) { gdb_byte *c = (gdb_byte *) buf; @@ -334,9 +326,8 @@ static void mnsh_maybe_mourn_peer (void); main process and the helper so must be async-signal-safe. */ static ssize_t -mnsh_send_message (int sock, enum mnsh_msg_type type, - int fd, int int1, int int2, - const void *buf, int bufsiz) +mnsh_send_message (int sock, enum mnsh_msg_type type, int fd, int int1, + int int2, const void *buf, int bufsiz) { struct msghdr msg; struct iovec iov[4]; @@ -363,7 +354,7 @@ mnsh_send_message (int sock, enum mnsh_msg_type type, memcpy (iov[3].iov_base, buf, bufsiz); iov[3].iov_len = bufsiz; - msg.msg_iovlen ++; + msg.msg_iovlen++; } /* Attach FD if supplied. */ @@ -409,9 +400,8 @@ mnsh_send_message (int sock, enum mnsh_msg_type type, async-signal-safe. */ static ssize_t -mnsh_recv_message (int sock, enum mnsh_msg_type *type, - int *fd, int *int1, int *int2, - void *buf, int bufsiz) +mnsh_recv_message (int sock, enum mnsh_msg_type *type, int *fd, int *int1, + int *int2, void *buf, int bufsiz) { struct msghdr msg; struct iovec iov[4]; @@ -469,10 +459,8 @@ mnsh_recv_message (int sock, enum mnsh_msg_type *type, /* Unpack the file descriptor if supplied. */ cmsg = CMSG_FIRSTHDR (&msg); - if (cmsg != NULL - && cmsg->cmsg_len == CMSG_LEN (sizeof (int)) - && cmsg->cmsg_level == SOL_SOCKET - && cmsg->cmsg_type == SCM_RIGHTS) + if (cmsg != NULL && cmsg->cmsg_len == CMSG_LEN (sizeof (int)) + && cmsg->cmsg_level == SOL_SOCKET && cmsg->cmsg_type == SCM_RIGHTS) memcpy (fd, CMSG_DATA (cmsg), sizeof (int)); else *fd = -1; @@ -494,15 +482,12 @@ mnsh_recv_message (int sock, enum mnsh_msg_type *type, #define mnsh_return_int(sock, result, error) \ mnsh_send_message (sock, MNSH_RET_INT, -1, result, error, NULL, 0) -#define mnsh_return_fd(sock, fd, error) \ - mnsh_send_message (sock, MNSH_RET_FD, \ - (fd) < 0 ? -1 : (fd), \ - (fd) < 0 ? (fd) : 0, \ - error, NULL, 0) +#define mnsh_return_fd(sock, fd, error) \ + mnsh_send_message (sock, MNSH_RET_FD, (fd) < 0 ? -1 : (fd), \ + (fd) < 0 ? (fd) : 0, error, NULL, 0) #define mnsh_return_intstr(sock, result, buf, bufsiz, error) \ - mnsh_send_message (sock, MNSH_RET_INTSTR, -1, result, error, \ - buf, bufsiz) + mnsh_send_message (sock, MNSH_RET_INTSTR, -1, result, error, buf, bufsiz) /* Handle a MNSH_REQ_SETNS message. Must be async-signal-safe. */ @@ -517,8 +502,7 @@ mnsh_handle_setns (int sock, int fd, int nstype) /* Handle a MNSH_REQ_OPEN message. Must be async-signal-safe. */ static ssize_t -mnsh_handle_open (int sock, const char *filename, - int flags, mode_t mode) +mnsh_handle_open (int sock, const char *filename, int flags, mode_t mode) { scoped_fd fd = gdb_open_cloexec (filename, flags, mode); return mnsh_return_fd (sock, fd.get (), errno); @@ -542,9 +526,7 @@ mnsh_handle_readlink (int sock, const char *filename) char buf[PATH_MAX]; int len = readlink (filename, buf, sizeof (buf)); - return mnsh_return_intstr (sock, len, - buf, len < 0 ? 0 : len, - errno); + return mnsh_return_intstr (sock, len, buf, len < 0 ? 0 : len, errno); } /* The helper process. Never returns. Must be async-signal-safe. */ @@ -561,9 +543,8 @@ mnsh_main (int sock) char buf[PATH_MAX]; ssize_t size, response = -1; - size = mnsh_recv_message (sock, &type, - &fd, &int1, &int2, - buf, sizeof (buf)); + size = mnsh_recv_message (sock, &type, &fd, &int1, &int2, buf, + sizeof (buf)); if (size >= 0 && size < sizeof (buf)) { @@ -604,8 +585,7 @@ mnsh_main (int sock) if (size < 0) size = 0; - mnsh_send_message (sock, MNSH_MSG_ERROR, - -1, int1, int2, buf, size); + mnsh_send_message (sock, MNSH_MSG_ERROR, -1, int1, int2, buf, size); } } } @@ -732,23 +712,23 @@ mnsh_maybe_mourn_peer (void) else if (pid == -1) { if (errno == ECHILD) - warning (_("mount namespace helper vanished?")); + warning (_ ("mount namespace helper vanished?")); else - internal_warning (_("unhandled error %d"), errno); + internal_warning (_ ("unhandled error %d"), errno); } else if (pid == helper->pid) { if (WIFEXITED (status)) - warning (_("mount namespace helper exited with status %d"), + warning (_ ("mount namespace helper exited with status %d"), WEXITSTATUS (status)); else if (WIFSIGNALED (status)) - warning (_("mount namespace helper killed by signal %d"), + warning (_ ("mount namespace helper killed by signal %d"), WTERMSIG (status)); else - internal_warning (_("unhandled status %d"), status); + internal_warning (_ ("unhandled status %d"), status); } else - internal_warning (_("unknown pid %d"), pid); + internal_warning (_ ("unknown pid %d"), pid); /* Something unrecoverable happened. */ helper->pid = -1; @@ -758,20 +738,19 @@ mnsh_maybe_mourn_peer (void) /* Shortcuts for sending messages to the helper. */ #define mnsh_send_setns(helper, fd, nstype) \ - mnsh_send_message (helper->sock, MNSH_REQ_SETNS, fd, nstype, 0, \ - NULL, 0) + mnsh_send_message (helper->sock, MNSH_REQ_SETNS, fd, nstype, 0, NULL, 0) -#define mnsh_send_open(helper, filename, flags, mode) \ - mnsh_send_message (helper->sock, MNSH_REQ_OPEN, -1, flags, mode, \ - filename, strlen (filename) + 1) +#define mnsh_send_open(helper, filename, flags, mode) \ + mnsh_send_message (helper->sock, MNSH_REQ_OPEN, -1, flags, mode, filename, \ + strlen (filename) + 1) -#define mnsh_send_unlink(helper, filename) \ - mnsh_send_message (helper->sock, MNSH_REQ_UNLINK, -1, 0, 0, \ - filename, strlen (filename) + 1) +#define mnsh_send_unlink(helper, filename) \ + mnsh_send_message (helper->sock, MNSH_REQ_UNLINK, -1, 0, 0, filename, \ + strlen (filename) + 1) -#define mnsh_send_readlink(helper, filename) \ - mnsh_send_message (helper->sock, MNSH_REQ_READLINK, -1, 0, 0, \ - filename, strlen (filename) + 1) +#define mnsh_send_readlink(helper, filename) \ + mnsh_send_message (helper->sock, MNSH_REQ_READLINK, -1, 0, 0, filename, \ + strlen (filename) + 1) /* Receive a message from the helper. Issue an assertion failure if the message isn't a correctly-formatted MNSH_RET_INT. Set RESULT @@ -786,9 +765,8 @@ mnsh_recv_int (struct linux_mnsh *helper, int *result, int *error) ssize_t size; int fd; - size = mnsh_recv_message (helper->sock, &type, &fd, - result, error, - buf, sizeof (buf)); + size = mnsh_recv_message (helper->sock, &type, &fd, result, error, buf, + sizeof (buf)); if (size < 0) return -1; @@ -812,9 +790,8 @@ mnsh_recv_fd (struct linux_mnsh *helper, int *fd, int *error) ssize_t size; int result; - size = mnsh_recv_message (helper->sock, &type, fd, - &result, error, - buf, sizeof (buf)); + size = mnsh_recv_message (helper->sock, &type, fd, &result, error, buf, + sizeof (buf)); if (size < 0) return -1; @@ -837,17 +814,15 @@ mnsh_recv_fd (struct linux_mnsh *helper, int *fd, int *error) Set errno and return -1 on error. */ static ssize_t -mnsh_recv_intstr (struct linux_mnsh *helper, - int *result, int *error, +mnsh_recv_intstr (struct linux_mnsh *helper, int *result, int *error, void *buf, int bufsiz) { enum mnsh_msg_type type; ssize_t size; int fd; - size = mnsh_recv_message (helper->sock, &type, &fd, - result, error, - buf, bufsiz); + size + = mnsh_recv_message (helper->sock, &type, &fd, result, error, buf, bufsiz); if (size < 0) return -1; @@ -861,18 +836,18 @@ mnsh_recv_intstr (struct linux_mnsh *helper, /* Return values for linux_mntns_access_fs. */ enum mnsh_fs_code - { - /* Something went wrong, errno is set. */ - MNSH_FS_ERROR = -1, +{ + /* Something went wrong, errno is set. */ + MNSH_FS_ERROR = -1, - /* The main process is in the correct mount namespace. + /* The main process is in the correct mount namespace. The caller should access the filesystem directly. */ - MNSH_FS_DIRECT, + MNSH_FS_DIRECT, - /* The helper is in the correct mount namespace. + /* The helper is in the correct mount namespace. The caller should access the filesystem via the helper. */ - MNSH_FS_HELPER - }; + MNSH_FS_HELPER +}; /* Return a value indicating how the caller should access the mount namespace of process PID. */ @@ -898,11 +873,11 @@ linux_mntns_access_fs (pid_t pid) return MNSH_FS_ERROR; SCOPE_EXIT - { - int save_errno = errno; - close (fd); - errno = save_errno; - }; + { + int save_errno = errno; + close (fd); + errno = save_errno; + }; if (fstat (fd, &sb) != 0) return MNSH_FS_ERROR; @@ -948,8 +923,8 @@ linux_mntns_access_fs (pid_t pid) /* See nat/linux-namespaces.h. */ int -linux_mntns_open_cloexec (pid_t pid, const char *filename, - int flags, mode_t mode) +linux_mntns_open_cloexec (pid_t pid, const char *filename, int flags, + mode_t mode) { enum mnsh_fs_code access = linux_mntns_access_fs (pid); struct linux_mnsh *helper; @@ -1015,8 +990,8 @@ linux_mntns_unlink (pid_t pid, const char *filename) /* See nat/linux-namespaces.h. */ ssize_t -linux_mntns_readlink (pid_t pid, const char *filename, - char *buf, size_t bufsiz) +linux_mntns_readlink (pid_t pid, const char *filename, char *buf, + size_t bufsiz) { enum mnsh_fs_code access = linux_mntns_access_fs (pid); struct linux_mnsh *helper; diff --git a/gdb/nat/linux-namespaces.h b/gdb/nat/linux-namespaces.h index a45b99c..0a32a1b 100644 --- a/gdb/nat/linux-namespaces.h +++ b/gdb/nat/linux-namespaces.h @@ -27,28 +27,28 @@ extern bool debug_linux_namespaces; /* Enumeration of Linux namespace types. */ enum linux_ns_type - { - /* IPC namespace: System V IPC, POSIX message queues. */ - LINUX_NS_IPC, +{ + /* IPC namespace: System V IPC, POSIX message queues. */ + LINUX_NS_IPC, - /* Mount namespace: mount points. */ - LINUX_NS_MNT, + /* Mount namespace: mount points. */ + LINUX_NS_MNT, - /* Network namespace: network devices, stacks, ports, etc. */ - LINUX_NS_NET, + /* Network namespace: network devices, stacks, ports, etc. */ + LINUX_NS_NET, - /* PID namespace: process IDs. */ - LINUX_NS_PID, + /* PID namespace: process IDs. */ + LINUX_NS_PID, - /* User namespace: user and group IDs. */ - LINUX_NS_USER, + /* User namespace: user and group IDs. */ + LINUX_NS_USER, - /* UTS namespace: hostname and NIS domain name. */ - LINUX_NS_UTS, + /* UTS namespace: hostname and NIS domain name. */ + LINUX_NS_UTS, - /* Number of Linux namespaces. */ - NUM_LINUX_NS_TYPES - }; + /* Number of Linux namespaces. */ + NUM_LINUX_NS_TYPES +}; /* Return nonzero if process PID has the same TYPE namespace as the calling process, or if the kernel does not support TYPE namespaces diff --git a/gdb/nat/linux-nat.h b/gdb/nat/linux-nat.h index aebb7de..84b937f 100644 --- a/gdb/nat/linux-nat.h +++ b/gdb/nat/linux-nat.h @@ -52,9 +52,9 @@ typedef int (iterate_over_lwps_ftype) (struct lwp_info *lwp); LWP immediately. Otherwise return NULL. This function must be provided by the client. */ -extern struct lwp_info *iterate_over_lwps - (ptid_t filter, - gdb::function_view<iterate_over_lwps_ftype> callback); +extern struct lwp_info * +iterate_over_lwps (ptid_t filter, + gdb::function_view<iterate_over_lwps_ftype> callback); /* Return the ptid of LWP. */ diff --git a/gdb/nat/linux-osdata.c b/gdb/nat/linux-osdata.c index 2a16017..39ebe5e 100644 --- a/gdb/nat/linux-osdata.c +++ b/gdb/nat/linux-osdata.c @@ -45,14 +45,14 @@ so that reading pid values embedded in /proc works consistently. */ -typedef long long PID_T; +typedef long long PID_T; /* Define TIME_T to be at least as large as time_t, so that reading time values embedded in /proc works consistently. */ typedef long long TIME_T; -#define MAX_PID_T_STRLEN (sizeof ("-9223372036854775808") - 1) +#define MAX_PID_T_STRLEN (sizeof ("-9223372036854775808") - 1) /* Returns the CPU core that thread PTID is currently running on. */ @@ -64,8 +64,8 @@ linux_common_core_of_thread (ptid_t ptid) char filename[sizeof ("/proc//task//stat") + 2 * MAX_PID_T_STRLEN]; int core; - sprintf (filename, "/proc/%lld/task/%lld/stat", - (PID_T) ptid.pid (), (PID_T) ptid.lwp ()); + sprintf (filename, "/proc/%lld/task/%lld/stat", (PID_T) ptid.pid (), + (PID_T) ptid.lwp ()); gdb::optional<std::string> content = read_text_file_to_string (filename); if (!content.has_value ()) @@ -122,7 +122,8 @@ command_from_pid (char *command, int maxlen, PID_T pid) if (items_read == 2 && pid == stat_pid) { cmd[strlen (cmd) - 1] = '\0'; /* Remove trailing parenthesis. */ - strncpy (command, cmd + 1, maxlen); /* Ignore leading parenthesis. */ + strncpy (command, cmd + 1, + maxlen); /* Ignore leading parenthesis. */ } } else @@ -155,7 +156,8 @@ commandline_from_pid (PID_T pid) if (read_bytes) { - commandline = (char *) xrealloc (commandline, len + read_bytes + 1); + commandline + = (char *) xrealloc (commandline, len + read_bytes + 1); memcpy (commandline + len, buf, read_bytes); len += read_bytes; } @@ -250,13 +252,12 @@ get_cores_used_by_process (PID_T pid, int *cores, const int num_cores) PID_T tid; int core; - if (!isdigit (dp->d_name[0]) - || NAMELEN (dp) > MAX_PID_T_STRLEN) + if (!isdigit (dp->d_name[0]) || NAMELEN (dp) > MAX_PID_T_STRLEN) continue; sscanf (dp->d_name, "%lld", &tid); - core = linux_common_core_of_thread (ptid_t ((pid_t) pid, - (pid_t) tid)); + core + = linux_common_core_of_thread (ptid_t ((pid_t) pid, (pid_t) tid)); if (core >= 0 && core < num_cores) { @@ -356,8 +357,7 @@ linux_xfer_osdata_processes () std::string cores_str; int i; - if (!isdigit (dp->d_name[0]) - || NAMELEN (dp) > MAX_PID_T_STRLEN) + if (!isdigit (dp->d_name[0]) || NAMELEN (dp) > MAX_PID_T_STRLEN) continue; sscanf (dp->d_name, "%lld", &pid); @@ -384,18 +384,15 @@ linux_xfer_osdata_processes () xfree (cores); - string_xml_appendf - (buffer, - "<item>" - "<column name=\"pid\">%lld</column>" - "<column name=\"user\">%s</column>" - "<column name=\"command\">%s</column>" - "<column name=\"cores\">%s</column>" - "</item>", - pid, - user, - command_line ? command_line : "", - cores_str.c_str()); + string_xml_appendf (buffer, + "<item>" + "<column name=\"pid\">%lld</column>" + "<column name=\"user\">%s</column>" + "<column name=\"command\">%s</column>" + "<column name=\"cores\">%s</column>" + "</item>", + pid, user, command_line ? command_line : "", + cores_str.c_str ()); xfree (command_line); } @@ -413,17 +410,16 @@ linux_xfer_osdata_processes () struct pid_pgid_entry { pid_pgid_entry (PID_T pid_, PID_T pgid_) - : pid (pid_), pgid (pgid_) - {} + : pid (pid_), + pgid (pgid_) + { + } /* Return true if this pid is the leader of its process group. */ - bool is_leader () const - { - return pid == pgid; - } + bool is_leader () const { return pid == pgid; } - bool operator< (const pid_pgid_entry &other) const + bool operator<(const pid_pgid_entry &other) const { /* Sort by PGID. */ if (this->pgid != other.pgid) @@ -467,8 +463,7 @@ linux_xfer_osdata_processgroups () { PID_T pid, pgid; - if (!isdigit (dp->d_name[0]) - || NAMELEN (dp) > MAX_PID_T_STRLEN) + if (!isdigit (dp->d_name[0]) || NAMELEN (dp) > MAX_PID_T_STRLEN) continue; sscanf (dp->d_name, "%lld", &pid); @@ -493,18 +488,15 @@ linux_xfer_osdata_processgroups () command_from_pid (leader_command, sizeof (leader_command), pgid); command_line = commandline_from_pid (pid); - string_xml_appendf - (buffer, - "<item>" - "<column name=\"pgid\">%lld</column>" - "<column name=\"leader command\">%s</column>" - "<column name=\"pid\">%lld</column>" - "<column name=\"command line\">%s</column>" - "</item>", - pgid, - leader_command, - pid, - command_line ? command_line : ""); + string_xml_appendf (buffer, + "<item>" + "<column name=\"pgid\">%lld</column>" + "<column name=\"leader command\">%s</column>" + "<column name=\"pid\">%lld</column>" + "<column name=\"command line\">%s</column>" + "</item>", + pgid, leader_command, pid, + command_line ? command_line : ""); xfree (command_line); } @@ -538,10 +530,8 @@ linux_xfer_osdata_threads () || NAMELEN (dp) > sizeof ("4294967295") - 1) continue; - xsnprintf (procentry, sizeof (procentry), "/proc/%s", - dp->d_name); - if (stat (procentry, &statbuf) == 0 - && S_ISDIR (statbuf.st_mode)) + xsnprintf (procentry, sizeof (procentry), "/proc/%s", dp->d_name); + if (stat (procentry, &statbuf) == 0 && S_ISDIR (statbuf.st_mode)) { DIR *dirp2; PID_T pid; @@ -571,18 +561,15 @@ linux_xfer_osdata_threads () tid = atoi (dp2->d_name); core = linux_common_core_of_thread (ptid_t (pid, tid)); - string_xml_appendf - (buffer, - "<item>" - "<column name=\"pid\">%lld</column>" - "<column name=\"command\">%s</column>" - "<column name=\"tid\">%lld</column>" - "<column name=\"core\">%d</column>" - "</item>", - pid, - command, - tid, - core); + string_xml_appendf ( + buffer, + "<item>" + "<column name=\"pid\">%lld</column>" + "<column name=\"command\">%s</column>" + "<column name=\"tid\">%lld</column>" + "<column name=\"core\">%d</column>" + "</item>", + pid, command, tid, core); } closedir (dirp2); @@ -648,10 +635,8 @@ linux_xfer_osdata_cpus () first_item = 0; } - string_xml_appendf (buffer, - "<column name=\"%s\">%s</column>", - key, - value); + string_xml_appendf (buffer, "<column name=\"%s\">%s</column>", + key, value); } } while (!feof (fp.get ())); @@ -688,10 +673,8 @@ linux_xfer_osdata_fds () || NAMELEN (dp) > sizeof ("4294967295") - 1) continue; - xsnprintf (procentry, sizeof (procentry), "/proc/%s", - dp->d_name); - if (stat (procentry, &statbuf) == 0 - && S_ISDIR (statbuf.st_mode)) + xsnprintf (procentry, sizeof (procentry), "/proc/%s", dp->d_name); + if (stat (procentry, &statbuf) == 0 && S_ISDIR (statbuf.st_mode)) { DIR *dirp2; PID_T pid; @@ -700,8 +683,7 @@ linux_xfer_osdata_fds () pid = atoi (dp->d_name); command_from_pid (command, sizeof (command), pid); - std::string pathname - = string_printf ("/proc/%s/fd", dp->d_name); + std::string pathname = string_printf ("/proc/%s/fd", dp->d_name); dirp2 = opendir (pathname.c_str ()); if (dirp2) @@ -719,23 +701,20 @@ linux_xfer_osdata_fds () std::string fdname = string_printf ("%s/%s", pathname.c_str (), dp2->d_name); - rslt = readlink (fdname.c_str (), buf, - sizeof (buf) - 1); + rslt = readlink (fdname.c_str (), buf, sizeof (buf) - 1); if (rslt >= 0) buf[rslt] = '\0'; - string_xml_appendf - (buffer, - "<item>" - "<column name=\"pid\">%s</column>" - "<column name=\"command\">%s</column>" - "<column name=\"file descriptor\">%s</column>" - "<column name=\"name\">%s</column>" - "</item>", - dp->d_name, - command, - dp2->d_name, - (rslt >= 0 ? buf : dp2->d_name)); + string_xml_appendf ( + buffer, + "<item>" + "<column name=\"pid\">%s</column>" + "<column name=\"command\">%s</column>" + "<column name=\"file descriptor\">%s</column>" + "<column name=\"name\">%s</column>" + "</item>", + dp->d_name, command, dp2->d_name, + (rslt >= 0 ? buf : dp2->d_name)); } closedir (dirp2); @@ -757,7 +736,8 @@ static const char * format_socket_state (unsigned char state) { /* Copied from include/net/tcp_states.h in the Linux kernel sources. */ - enum { + enum + { TCP_ESTABLISHED = 1, TCP_SYN_SENT, TCP_SYN_RECV, @@ -801,11 +781,11 @@ format_socket_state (unsigned char state) } union socket_addr - { - struct sockaddr sa; - struct sockaddr_in sin; - struct sockaddr_in6 sin6; - }; +{ + struct sockaddr sa; + struct sockaddr_in sin; + struct sockaddr_in6 sin6; +}; /* Auxiliary function used by linux_xfer_osdata_isocket. Formats information for all open internet sockets of type FAMILY on the @@ -843,11 +823,10 @@ print_sockets (unsigned short family, int tcp, std::string &buffer) #endif result = sscanf (buf, - "%*d: %32[0-9A-F]:%X %32[0-9A-F]:%X %X %*X:%*X %*X:%*X %*X %d %*d %*u %*s\n", - local_address, &local_port, - remote_address, &remote_port, - &state, - &uid); + "%*d: %32[0-9A-F]:%X %32[0-9A-F]:%X %X %*X:%*X " + "%*X:%*X %*X %d %*d %*u %*s\n", + local_address, &local_port, remote_address, + &remote_port, &state, &uid); if (result == 6) { @@ -894,46 +873,41 @@ print_sockets (unsigned short family, int tcp, std::string &buffer) locaddr.sa.sa_family = remaddr.sa.sa_family = family; - result = getnameinfo (&locaddr.sa, addr_size, - local_address, sizeof (local_address), - local_service, sizeof (local_service), + result = getnameinfo (&locaddr.sa, addr_size, local_address, + sizeof (local_address), local_service, + sizeof (local_service), NI_NUMERICHOST | NI_NUMERICSERV - | (tcp ? 0 : NI_DGRAM)); + | (tcp ? 0 : NI_DGRAM)); if (result) continue; - result = getnameinfo (&remaddr.sa, addr_size, - remote_address, - sizeof (remote_address), - remote_service, - sizeof (remote_service), - NI_NUMERICHOST | NI_NUMERICSERV - | (tcp ? 0 : NI_DGRAM)); + result + = getnameinfo (&remaddr.sa, addr_size, remote_address, + sizeof (remote_address), remote_service, + sizeof (remote_service), + NI_NUMERICHOST | NI_NUMERICSERV + | (tcp ? 0 : NI_DGRAM)); if (result) continue; user_from_uid (user, sizeof (user), uid); - string_xml_appendf - (buffer, - "<item>" - "<column name=\"local address\">%s</column>" - "<column name=\"local port\">%s</column>" - "<column name=\"remote address\">%s</column>" - "<column name=\"remote port\">%s</column>" - "<column name=\"state\">%s</column>" - "<column name=\"user\">%s</column>" - "<column name=\"family\">%s</column>" - "<column name=\"protocol\">%s</column>" - "</item>", - local_address, - local_service, - remote_address, - remote_service, - format_socket_state (state), - user, - (family == AF_INET) ? "INET" : "INET6", - tcp ? "STREAM" : "DGRAM"); + string_xml_appendf ( + buffer, + "<item>" + "<column name=\"local address\">%s</column>" + "<column name=\"local port\">%s</column>" + "<column name=\"remote address\">%s</column>" + "<column name=\"remote port\">%s</column>" + "<column name=\"state\">%s</column>" + "<column name=\"user\">%s</column>" + "<column name=\"family\">%s</column>" + "<column name=\"protocol\">%s</column>" + "</item>", + local_address, local_service, remote_address, + remote_service, format_socket_state (state), user, + (family == AF_INET) ? "INET" : "INET6", + tcp ? "STREAM" : "DGRAM"); } } } @@ -1023,13 +997,10 @@ linux_xfer_osdata_shm () unsigned int perms; int items_read; - items_read = sscanf (buf, - "%d %d %o %d %lld %lld %d %u %u %u %u %lld %lld %lld", - &key, &shmid, &perms, &size, - &cpid, &lpid, - &nattch, - &uid, &gid, &cuid, &cgid, - &atime, &dtime, &ctime); + items_read = sscanf ( + buf, "%d %d %o %d %lld %lld %d %u %u %u %u %lld %lld %lld", + &key, &shmid, &perms, &size, &cpid, &lpid, &nattch, &uid, &gid, + &cuid, &cgid, &atime, &dtime, &ctime); if (items_read == 14) { @@ -1050,38 +1021,26 @@ linux_xfer_osdata_shm () time_from_time_t (dtime_str, sizeof (dtime_str), dtime); time_from_time_t (ctime_str, sizeof (ctime_str), ctime); - string_xml_appendf - (buffer, - "<item>" - "<column name=\"key\">%d</column>" - "<column name=\"shmid\">%d</column>" - "<column name=\"permissions\">%o</column>" - "<column name=\"size\">%d</column>" - "<column name=\"creator command\">%s</column>" - "<column name=\"last op. command\">%s</column>" - "<column name=\"num attached\">%d</column>" - "<column name=\"user\">%s</column>" - "<column name=\"group\">%s</column>" - "<column name=\"creator user\">%s</column>" - "<column name=\"creator group\">%s</column>" - "<column name=\"last shmat() time\">%s</column>" - "<column name=\"last shmdt() time\">%s</column>" - "<column name=\"last shmctl() time\">%s</column>" - "</item>", - key, - shmid, - perms, - size, - ccmd, - lcmd, - nattch, - user, - group, - cuser, - cgroup, - atime_str, - dtime_str, - ctime_str); + string_xml_appendf ( + buffer, + "<item>" + "<column name=\"key\">%d</column>" + "<column name=\"shmid\">%d</column>" + "<column name=\"permissions\">%o</column>" + "<column name=\"size\">%d</column>" + "<column name=\"creator command\">%s</column>" + "<column name=\"last op. command\">%s</column>" + "<column name=\"num attached\">%d</column>" + "<column name=\"user\">%s</column>" + "<column name=\"group\">%s</column>" + "<column name=\"creator user\">%s</column>" + "<column name=\"creator group\">%s</column>" + "<column name=\"last shmat() time\">%s</column>" + "<column name=\"last shmdt() time\">%s</column>" + "<column name=\"last shmctl() time\">%s</column>" + "</item>", + key, shmid, perms, size, ccmd, lcmd, nattch, user, group, + cuser, cgroup, atime_str, dtime_str, ctime_str); } } } @@ -1118,11 +1077,9 @@ linux_xfer_osdata_sem () TIME_T otime, ctime; int items_read; - items_read = sscanf (buf, - "%d %d %o %u %d %d %d %d %lld %lld", - &key, &semid, &perms, &nsems, - &uid, &gid, &cuid, &cgid, - &otime, &ctime); + items_read = sscanf (buf, "%d %d %o %u %d %d %d %d %lld %lld", + &key, &semid, &perms, &nsems, &uid, &gid, + &cuid, &cgid, &otime, &ctime); if (items_read == 10) { @@ -1138,30 +1095,22 @@ linux_xfer_osdata_sem () time_from_time_t (otime_str, sizeof (otime_str), otime); time_from_time_t (ctime_str, sizeof (ctime_str), ctime); - string_xml_appendf - (buffer, - "<item>" - "<column name=\"key\">%d</column>" - "<column name=\"semid\">%d</column>" - "<column name=\"permissions\">%o</column>" - "<column name=\"num semaphores\">%u</column>" - "<column name=\"user\">%s</column>" - "<column name=\"group\">%s</column>" - "<column name=\"creator user\">%s</column>" - "<column name=\"creator group\">%s</column>" - "<column name=\"last semop() time\">%s</column>" - "<column name=\"last semctl() time\">%s</column>" - "</item>", - key, - semid, - perms, - nsems, - user, - group, - cuser, - cgroup, - otime_str, - ctime_str); + string_xml_appendf ( + buffer, + "<item>" + "<column name=\"key\">%d</column>" + "<column name=\"semid\">%d</column>" + "<column name=\"permissions\">%o</column>" + "<column name=\"num semaphores\">%u</column>" + "<column name=\"user\">%s</column>" + "<column name=\"group\">%s</column>" + "<column name=\"creator user\">%s</column>" + "<column name=\"creator group\">%s</column>" + "<column name=\"last semop() time\">%s</column>" + "<column name=\"last semctl() time\">%s</column>" + "</item>", + key, semid, perms, nsems, user, group, cuser, cgroup, + otime_str, ctime_str); } } } @@ -1199,11 +1148,10 @@ linux_xfer_osdata_msg () TIME_T stime, rtime, ctime; int items_read; - items_read = sscanf (buf, - "%d %d %o %u %u %lld %lld %d %d %d %d %lld %lld %lld", - &key, &msqid, &perms, &cbytes, &qnum, - &lspid, &lrpid, &uid, &gid, &cuid, &cgid, - &stime, &rtime, &ctime); + items_read = sscanf ( + buf, "%d %d %o %u %u %lld %lld %d %d %d %d %lld %lld %lld", + &key, &msqid, &perms, &cbytes, &qnum, &lspid, &lrpid, &uid, + &gid, &cuid, &cgid, &stime, &rtime, &ctime); if (items_read == 14) { @@ -1224,38 +1172,26 @@ linux_xfer_osdata_msg () time_from_time_t (rtime_str, sizeof (rtime_str), rtime); time_from_time_t (ctime_str, sizeof (ctime_str), ctime); - string_xml_appendf - (buffer, - "<item>" - "<column name=\"key\">%d</column>" - "<column name=\"msqid\">%d</column>" - "<column name=\"permissions\">%o</column>" - "<column name=\"num used bytes\">%u</column>" - "<column name=\"num messages\">%u</column>" - "<column name=\"last msgsnd() command\">%s</column>" - "<column name=\"last msgrcv() command\">%s</column>" - "<column name=\"user\">%s</column>" - "<column name=\"group\">%s</column>" - "<column name=\"creator user\">%s</column>" - "<column name=\"creator group\">%s</column>" - "<column name=\"last msgsnd() time\">%s</column>" - "<column name=\"last msgrcv() time\">%s</column>" - "<column name=\"last msgctl() time\">%s</column>" - "</item>", - key, - msqid, - perms, - cbytes, - qnum, - lscmd, - lrcmd, - user, - group, - cuser, - cgroup, - stime_str, - rtime_str, - ctime_str); + string_xml_appendf ( + buffer, + "<item>" + "<column name=\"key\">%d</column>" + "<column name=\"msqid\">%d</column>" + "<column name=\"permissions\">%o</column>" + "<column name=\"num used bytes\">%u</column>" + "<column name=\"num messages\">%u</column>" + "<column name=\"last msgsnd() command\">%s</column>" + "<column name=\"last msgrcv() command\">%s</column>" + "<column name=\"user\">%s</column>" + "<column name=\"group\">%s</column>" + "<column name=\"creator user\">%s</column>" + "<column name=\"creator group\">%s</column>" + "<column name=\"last msgsnd() time\">%s</column>" + "<column name=\"last msgrcv() time\">%s</column>" + "<column name=\"last msgctl() time\">%s</column>" + "</item>", + key, msqid, perms, cbytes, qnum, lscmd, lrcmd, user, group, + cuser, cgroup, stime_str, rtime_str, ctime_str); } } } @@ -1328,11 +1264,7 @@ linux_xfer_osdata_modules () "<column name=\"status\">%s</column>" "<column name=\"address\">%llx</column>" "</item>", - name, - size, - uses, - dependencies, - status, + name, size, uses, dependencies, status, address); } } @@ -1346,37 +1278,37 @@ linux_xfer_osdata_modules () static std::string linux_xfer_osdata_info_os_types (); -static struct osdata_type { +static struct osdata_type +{ const char *type; const char *title; const char *description; std::string (*take_snapshot) (); std::string buffer; -} osdata_table[] = { - { "types", "Types", "Listing of info os types you can list", - linux_xfer_osdata_info_os_types }, - { "cpus", "CPUs", "Listing of all cpus/cores on the system", - linux_xfer_osdata_cpus }, - { "files", "File descriptors", "Listing of all file descriptors", - linux_xfer_osdata_fds }, - { "modules", "Kernel modules", "Listing of all loaded kernel modules", - linux_xfer_osdata_modules }, - { "msg", "Message queues", "Listing of all message queues", - linux_xfer_osdata_msg }, - { "processes", "Processes", "Listing of all processes", - linux_xfer_osdata_processes }, - { "procgroups", "Process groups", "Listing of all process groups", - linux_xfer_osdata_processgroups }, - { "semaphores", "Semaphores", "Listing of all semaphores", - linux_xfer_osdata_sem }, - { "shm", "Shared-memory regions", "Listing of all shared-memory regions", - linux_xfer_osdata_shm }, - { "sockets", "Sockets", "Listing of all internet-domain sockets", - linux_xfer_osdata_isockets }, - { "threads", "Threads", "Listing of all threads", - linux_xfer_osdata_threads }, - { NULL, NULL, NULL } -}; +} osdata_table[] + = { { "types", "Types", "Listing of info os types you can list", + linux_xfer_osdata_info_os_types }, + { "cpus", "CPUs", "Listing of all cpus/cores on the system", + linux_xfer_osdata_cpus }, + { "files", "File descriptors", "Listing of all file descriptors", + linux_xfer_osdata_fds }, + { "modules", "Kernel modules", "Listing of all loaded kernel modules", + linux_xfer_osdata_modules }, + { "msg", "Message queues", "Listing of all message queues", + linux_xfer_osdata_msg }, + { "processes", "Processes", "Listing of all processes", + linux_xfer_osdata_processes }, + { "procgroups", "Process groups", "Listing of all process groups", + linux_xfer_osdata_processgroups }, + { "semaphores", "Semaphores", "Listing of all semaphores", + linux_xfer_osdata_sem }, + { "shm", "Shared-memory regions", "Listing of all shared-memory regions", + linux_xfer_osdata_shm }, + { "sockets", "Sockets", "Listing of all internet-domain sockets", + linux_xfer_osdata_isockets }, + { "threads", "Threads", "Listing of all threads", + linux_xfer_osdata_threads }, + { NULL, NULL, NULL } }; /* Collect data about all types info os can show in BUFFER. */ @@ -1393,8 +1325,7 @@ linux_xfer_osdata_info_os_types () "<column name=\"Description\">%s</column>" "<column name=\"Title\">%s</column>" "</item>", - osdata_table[i].type, - osdata_table[i].description, + osdata_table[i].type, osdata_table[i].description, osdata_table[i].title); buffer += "</osdata>\n"; @@ -1402,13 +1333,12 @@ linux_xfer_osdata_info_os_types () return buffer; } - /* Copies up to LEN bytes in READBUF from offset OFFSET in OSD->BUFFER. If OFFSET is zero, first calls OSD->TAKE_SNAPSHOT. */ static LONGEST -common_getter (struct osdata_type *osd, - gdb_byte *readbuf, ULONGEST offset, ULONGEST len) +common_getter (struct osdata_type *osd, gdb_byte *readbuf, ULONGEST offset, + ULONGEST len) { gdb_assert (readbuf); @@ -1426,7 +1356,6 @@ common_getter (struct osdata_type *osd, memcpy (readbuf, &osd->buffer[offset], len); return len; - } LONGEST @@ -1435,8 +1364,7 @@ linux_common_xfer_osdata (const char *annex, gdb_byte *readbuf, { if (!annex || *annex == '\0') { - return common_getter (&osdata_table[0], - readbuf, offset, len); + return common_getter (&osdata_table[0], readbuf, offset, len); } else { @@ -1445,8 +1373,7 @@ linux_common_xfer_osdata (const char *annex, gdb_byte *readbuf, for (i = 0; osdata_table[i].type; ++i) { if (strcmp (annex, osdata_table[i].type) == 0) - return common_getter (&osdata_table[i], - readbuf, offset, len); + return common_getter (&osdata_table[i], readbuf, offset, len); } return 0; diff --git a/gdb/nat/linux-personality.c b/gdb/nat/linux-personality.c index c2ae725..6e021fa 100644 --- a/gdb/nat/linux-personality.c +++ b/gdb/nat/linux-personality.c @@ -22,14 +22,14 @@ #include <sys/personality.h> -# if !HAVE_DECL_ADDR_NO_RANDOMIZE -# define ADDR_NO_RANDOMIZE 0x0040000 -# endif /* ! HAVE_DECL_ADDR_NO_RANDOMIZE */ +#if !HAVE_DECL_ADDR_NO_RANDOMIZE +#define ADDR_NO_RANDOMIZE 0x0040000 +#endif /* ! HAVE_DECL_ADDR_NO_RANDOMIZE */ /* See comment on nat/linux-personality.h. */ maybe_disable_address_space_randomization:: -maybe_disable_address_space_randomization (int disable_randomization) + maybe_disable_address_space_randomization (int disable_randomization) : m_personality_set (false), m_personality_orig (0) { @@ -42,22 +42,23 @@ maybe_disable_address_space_randomization (int disable_randomization) m_personality_set = true; personality (m_personality_orig | ADDR_NO_RANDOMIZE); } - if (errno != 0 || (m_personality_set - && !(personality (0xffffffff) & ADDR_NO_RANDOMIZE))) - warning (_("Error disabling address space randomization: %s"), + if (errno != 0 + || (m_personality_set + && !(personality (0xffffffff) & ADDR_NO_RANDOMIZE))) + warning (_ ("Error disabling address space randomization: %s"), safe_strerror (errno)); } } maybe_disable_address_space_randomization:: -~maybe_disable_address_space_randomization () + ~maybe_disable_address_space_randomization () { if (m_personality_set) { errno = 0; personality (m_personality_orig); if (errno != 0) - warning (_("Error restoring address space randomization: %s"), + warning (_ ("Error restoring address space randomization: %s"), safe_strerror (errno)); } } diff --git a/gdb/nat/linux-procfs.c b/gdb/nat/linux-procfs.c index 9c2d1be..3e883e6 100644 --- a/gdb/nat/linux-procfs.c +++ b/gdb/nat/linux-procfs.c @@ -37,7 +37,7 @@ linux_proc_get_int (pid_t lwpid, const char *field, int warn) if (status_file == NULL) { if (warn) - warning (_("unable to open /proc file '%s'"), buf); + warning (_ ("unable to open /proc file '%s'"), buf); return -1; } @@ -117,7 +117,6 @@ parse_proc_status_state (const char *state) return PROC_STATE_UNKNOWN; } - /* Fill in STATE, a buffer with BUFFER_SIZE bytes with the 'State' line of /proc/PID/status. Returns -1 on failure to open the /proc file, 1 if the line is found, and 0 if not found. If WARN, warn on @@ -134,7 +133,7 @@ linux_proc_pid_get_state (pid_t pid, int warn, enum proc_state *state) if (procfile == NULL) { if (warn) - warning (_("unable to open /proc file '%s'"), buffer); + warning (_ ("unable to open /proc file '%s'"), buffer); return -1; } @@ -234,7 +233,7 @@ linux_proc_pid_is_zombie (pid_t pid) const char * linux_proc_tid_get_name (ptid_t ptid) { -#define TASK_COMM_LEN 16 /* As defined in the kernel's sched.h. */ +#define TASK_COMM_LEN 16 /* As defined in the kernel's sched.h. */ static char comm_buf[TASK_COMM_LEN]; char comm_path[100]; @@ -242,8 +241,8 @@ linux_proc_tid_get_name (ptid_t ptid) pid_t pid = ptid.pid (); pid_t tid = ptid.lwp_p () ? ptid.lwp () : ptid.pid (); - xsnprintf (comm_path, sizeof (comm_path), - "/proc/%ld/task/%ld/comm", (long) pid, (long) tid); + xsnprintf (comm_path, sizeof (comm_path), "/proc/%ld/task/%ld/comm", + (long) pid, (long) tid); gdb_file_up comm_file = gdb_fopen_cloexec (comm_path, "r"); if (comm_file == NULL) @@ -287,7 +286,7 @@ linux_proc_attach_tgid_threads (pid_t pid, dir = opendir (pathname); if (dir == NULL) { - warning (_("Could not open /proc/%ld/task."), (long) pid); + warning (_ ("Could not open /proc/%ld/task."), (long) pid); return; } @@ -372,5 +371,5 @@ linux_proc_init_warnings () struct stat st; if (stat ("/proc/self", &st) != 0) - warning (_("/proc is not accessible.")); + warning (_ ("/proc is not accessible.")); } diff --git a/gdb/nat/linux-ptrace.c b/gdb/nat/linux-ptrace.c index f312779..d8bb6d9 100644 --- a/gdb/nat/linux-ptrace.c +++ b/gdb/nat/linux-ptrace.c @@ -40,14 +40,13 @@ linux_ptrace_attach_fail_reason (pid_t pid) std::string result; if (tracerpid > 0) - string_appendf (result, - _("process %d is already traced by process %d"), + string_appendf (result, _ ("process %d is already traced by process %d"), (int) pid, (int) tracerpid); if (linux_proc_pid_is_zombie_nowarn (pid)) string_appendf (result, - _("process %d is a zombie - the process has already " - "terminated"), + _ ("process %d is a zombie - the process has already " + "terminated"), (int) pid); return result; @@ -89,8 +88,8 @@ kill_child (pid_t child, const char *who) if (kill (child, SIGKILL) != 0) { - warning (_("%s: failed to kill child pid %ld %s"), - who, (long) child, safe_strerror (errno)); + warning (_ ("%s: failed to kill child pid %ld %s"), who, (long) child, + safe_strerror (errno)); return; } @@ -98,15 +97,15 @@ kill_child (pid_t child, const char *who) got_pid = my_waitpid (child, &kill_status, 0); if (got_pid != child) { - warning (_("%s: " - "kill waitpid returned %ld: %s"), + warning (_ ("%s: " + "kill waitpid returned %ld: %s"), who, (long) got_pid, safe_strerror (errno)); return; } if (!WIFSIGNALED (kill_status)) { - warning (_("%s: " - "kill status %d is not WIFSIGNALED!"), + warning (_ ("%s: " + "kill status %d is not WIFSIGNALED!"), who, kill_status); return; } @@ -127,12 +126,11 @@ linux_ptrace_test_ret_to_nx (void) int status; elf_gregset_t regs; - return_address - = (gdb_byte *) mmap (NULL, 2, PROT_READ | PROT_WRITE, - MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); + return_address = (gdb_byte *) mmap (NULL, 2, PROT_READ | PROT_WRITE, + MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); if (return_address == MAP_FAILED) { - warning (_("linux_ptrace_test_ret_to_nx: Cannot mmap: %s"), + warning (_ ("linux_ptrace_test_ret_to_nx: Cannot mmap: %s"), safe_strerror (errno)); return; } @@ -144,7 +142,7 @@ linux_ptrace_test_ret_to_nx (void) switch (child) { case -1: - warning (_("linux_ptrace_test_ret_to_nx: Cannot fork: %s"), + warning (_ ("linux_ptrace_test_ret_to_nx: Cannot fork: %s"), safe_strerror (errno)); return; @@ -152,7 +150,7 @@ linux_ptrace_test_ret_to_nx (void) l = ptrace (PTRACE_TRACEME, 0, (PTRACE_TYPE_ARG3) NULL, (PTRACE_TYPE_ARG4) NULL); if (l != 0) - warning (_("linux_ptrace_test_ret_to_nx: Cannot PTRACE_TRACEME: %s"), + warning (_ ("linux_ptrace_test_ret_to_nx: Cannot PTRACE_TRACEME: %s"), safe_strerror (errno)); else { @@ -161,16 +159,19 @@ linux_ptrace_test_ret_to_nx (void) ".globl linux_ptrace_test_ret_to_nx_instr;" "linux_ptrace_test_ret_to_nx_instr:" "ret" - : : "r" (return_address) : "memory"); + : + : "r"(return_address) + : "memory"); #elif defined __x86_64__ asm volatile ("pushq %0;" ".globl linux_ptrace_test_ret_to_nx_instr;" "linux_ptrace_test_ret_to_nx_instr:" "ret" - : : "r" ((uint64_t) (uintptr_t) return_address) + : + : "r"((uint64_t) (uintptr_t) return_address) : "memory"); #else -# error "!__i386__ && !__x86_64__" +#error "!__i386__ && !__x86_64__" #endif gdb_assert_not_reached ("asm block did not terminate"); } @@ -182,7 +183,7 @@ linux_ptrace_test_ret_to_nx (void) got_pid = waitpid (child, &status, 0); if (got_pid != child) { - warning (_("linux_ptrace_test_ret_to_nx: waitpid returned %ld: %s"), + warning (_ ("linux_ptrace_test_ret_to_nx: waitpid returned %ld: %s"), (long) got_pid, safe_strerror (errno)); return; } @@ -190,17 +191,18 @@ linux_ptrace_test_ret_to_nx (void) if (WIFSIGNALED (status)) { if (WTERMSIG (status) != SIGKILL) - warning (_("linux_ptrace_test_ret_to_nx: WTERMSIG %d is not SIGKILL!"), - (int) WTERMSIG (status)); + warning ( + _ ("linux_ptrace_test_ret_to_nx: WTERMSIG %d is not SIGKILL!"), + (int) WTERMSIG (status)); else - warning (_("Cannot call inferior functions, Linux kernel PaX " - "protection forbids return to non-executable pages!")); + warning (_ ("Cannot call inferior functions, Linux kernel PaX " + "protection forbids return to non-executable pages!")); return; } if (!WIFSTOPPED (status)) { - warning (_("linux_ptrace_test_ret_to_nx: status %d is not WIFSTOPPED!"), + warning (_ ("linux_ptrace_test_ret_to_nx: status %d is not WIFSTOPPED!"), status); kill_child (child, "linux_ptrace_test_ret_to_nx"); return; @@ -209,17 +211,18 @@ linux_ptrace_test_ret_to_nx (void) /* We may get SIGSEGV due to missing PROT_EXEC of the return_address. */ if (WSTOPSIG (status) != SIGTRAP && WSTOPSIG (status) != SIGSEGV) { - warning (_("linux_ptrace_test_ret_to_nx: " - "WSTOPSIG %d is neither SIGTRAP nor SIGSEGV!"), + warning (_ ("linux_ptrace_test_ret_to_nx: " + "WSTOPSIG %d is neither SIGTRAP nor SIGSEGV!"), (int) WSTOPSIG (status)); kill_child (child, "linux_ptrace_test_ret_to_nx"); return; } if (ptrace (PTRACE_GETREGS, child, (PTRACE_TYPE_ARG3) 0, - (PTRACE_TYPE_ARG4) ®s) < 0) + (PTRACE_TYPE_ARG4) ®s) + < 0) { - warning (_("linux_ptrace_test_ret_to_nx: Cannot PTRACE_GETREGS: %s"), + warning (_ ("linux_ptrace_test_ret_to_nx: Cannot PTRACE_GETREGS: %s"), safe_strerror (errno)); } #if defined __i386__ @@ -227,7 +230,7 @@ linux_ptrace_test_ret_to_nx (void) #elif defined __x86_64__ pc = (gdb_byte *) (uintptr_t) regs[RIP]; #else -# error "!__i386__ && !__x86_64__" +#error "!__i386__ && !__x86_64__" #endif kill_child (child, "linux_ptrace_test_ret_to_nx"); @@ -247,13 +250,13 @@ linux_ptrace_test_ret_to_nx (void) } if ((void (*) (void)) pc != &linux_ptrace_test_ret_to_nx_instr) - warning (_("linux_ptrace_test_ret_to_nx: PC %p is neither near return " - "address %p nor is the return instruction %p!"), + warning (_ ("linux_ptrace_test_ret_to_nx: PC %p is neither near return " + "address %p nor is the return instruction %p!"), pc, return_address, &linux_ptrace_test_ret_to_nx_instr); else - warning (_("Cannot call inferior functions on this system - " - "Linux kernel with broken i386 NX (non-executable pages) " - "support detected!")); + warning (_ ("Cannot call inferior functions on this system - " + "Linux kernel with broken i386 NX (non-executable pages) " + "support detected!")); #endif /* defined __i386__ || defined __x86_64__ */ } @@ -276,18 +279,18 @@ linux_fork_to_function (gdb_byte *child_stack, int (*function) (void *)) #if defined(__UCLIBC__) && defined(HAS_NOMMU) #define STACK_SIZE 4096 - if (child_stack == NULL) - child_stack = (gdb_byte *) xmalloc (STACK_SIZE * 4); + if (child_stack == NULL) + child_stack = (gdb_byte *) xmalloc (STACK_SIZE * 4); /* Use CLONE_VM instead of fork, to support uClinux (no MMU). */ #ifdef __ia64__ - child_pid = __clone2 (function, child_stack, STACK_SIZE, - CLONE_VM | SIGCHLD, child_stack + STACK_SIZE * 2); -#else /* !__ia64__ */ - child_pid = clone (function, child_stack + STACK_SIZE, - CLONE_VM | SIGCHLD, child_stack + STACK_SIZE * 2); + child_pid = __clone2 (function, child_stack, STACK_SIZE, CLONE_VM | SIGCHLD, + child_stack + STACK_SIZE * 2); +#else /* !__ia64__ */ + child_pid = clone (function, child_stack + STACK_SIZE, CLONE_VM | SIGCHLD, + child_stack + STACK_SIZE * 2); #endif /* !__ia64__ */ -#else /* !defined(__UCLIBC) && defined(HAS_NOMMU) */ +#else /* !defined(__UCLIBC) && defined(HAS_NOMMU) */ child_pid = fork (); if (child_pid == 0) @@ -327,12 +330,8 @@ linux_check_ptrace_features (void) /* Initialize the options. We consider that these options are always supported. */ supported_ptrace_options - = (PTRACE_O_TRACESYSGOOD - | PTRACE_O_TRACECLONE - | PTRACE_O_TRACEFORK - | PTRACE_O_TRACEVFORK - | PTRACE_O_TRACEVFORKDONE - | PTRACE_O_TRACEEXEC); + = (PTRACE_O_TRACESYSGOOD | PTRACE_O_TRACECLONE | PTRACE_O_TRACEFORK + | PTRACE_O_TRACEVFORK | PTRACE_O_TRACEVFORKDONE | PTRACE_O_TRACEEXEC); /* Fork a child so we can do some testing. The child will call linux_child_function and will get traced. The child will @@ -344,10 +343,10 @@ linux_check_ptrace_features (void) if (ret == -1) perror_with_name (("waitpid")); else if (ret != child_pid) - error (_("linux_check_ptrace_features: waitpid: unexpected result %d."), + error (_ ("linux_check_ptrace_features: waitpid: unexpected result %d."), ret); - if (! WIFSTOPPED (status)) - error (_("linux_check_ptrace_features: waitpid: unexpected status %d."), + if (!WIFSTOPPED (status)) + error (_ ("linux_check_ptrace_features: waitpid: unexpected status %d."), status); linux_test_for_exitkill (child_pid); @@ -443,6 +442,5 @@ linux_wstatus_maybe_breakpoint (int wstat) && (WSTOPSIG (wstat) == SIGTRAP /* SIGILL and SIGSEGV are also treated as traps in case a breakpoint is inserted at the current PC. */ - || WSTOPSIG (wstat) == SIGILL - || WSTOPSIG (wstat) == SIGSEGV)); + || WSTOPSIG (wstat) == SIGILL || WSTOPSIG (wstat) == SIGSEGV)); } diff --git a/gdb/nat/linux-ptrace.h b/gdb/nat/linux-ptrace.h index 19f4736..b965a92 100644 --- a/gdb/nat/linux-ptrace.h +++ b/gdb/nat/linux-ptrace.h @@ -40,61 +40,61 @@ struct buffer; #endif #ifndef PTRACE_GETSIGINFO -# define PTRACE_GETSIGINFO 0x4202 -# define PTRACE_SETSIGINFO 0x4203 +#define PTRACE_GETSIGINFO 0x4202 +#define PTRACE_SETSIGINFO 0x4203 #endif /* PTRACE_GETSIGINF */ #ifndef PTRACE_GETREGSET -#define PTRACE_GETREGSET 0x4204 +#define PTRACE_GETREGSET 0x4204 #endif #ifndef PTRACE_SETREGSET -#define PTRACE_SETREGSET 0x4205 +#define PTRACE_SETREGSET 0x4205 #endif /* If the system headers did not provide the constants, hard-code the normal values. */ #ifndef PTRACE_EVENT_FORK -#define PTRACE_SETOPTIONS 0x4200 -#define PTRACE_GETEVENTMSG 0x4201 +#define PTRACE_SETOPTIONS 0x4200 +#define PTRACE_GETEVENTMSG 0x4201 /* options set using PTRACE_SETOPTIONS */ -#define PTRACE_O_TRACESYSGOOD 0x00000001 -#define PTRACE_O_TRACEFORK 0x00000002 -#define PTRACE_O_TRACEVFORK 0x00000004 -#define PTRACE_O_TRACECLONE 0x00000008 -#define PTRACE_O_TRACEEXEC 0x00000010 -#define PTRACE_O_TRACEVFORKDONE 0x00000020 -#define PTRACE_O_TRACEEXIT 0x00000040 +#define PTRACE_O_TRACESYSGOOD 0x00000001 +#define PTRACE_O_TRACEFORK 0x00000002 +#define PTRACE_O_TRACEVFORK 0x00000004 +#define PTRACE_O_TRACECLONE 0x00000008 +#define PTRACE_O_TRACEEXEC 0x00000010 +#define PTRACE_O_TRACEVFORKDONE 0x00000020 +#define PTRACE_O_TRACEEXIT 0x00000040 /* Wait extended result codes for the above trace options. */ -#define PTRACE_EVENT_FORK 1 -#define PTRACE_EVENT_VFORK 2 -#define PTRACE_EVENT_CLONE 3 -#define PTRACE_EVENT_EXEC 4 -#define PTRACE_EVENT_VFORK_DONE 5 -#define PTRACE_EVENT_EXIT 6 +#define PTRACE_EVENT_FORK 1 +#define PTRACE_EVENT_VFORK 2 +#define PTRACE_EVENT_CLONE 3 +#define PTRACE_EVENT_EXEC 4 +#define PTRACE_EVENT_VFORK_DONE 5 +#define PTRACE_EVENT_EXIT 6 #endif /* PTRACE_EVENT_FORK */ #ifndef PTRACE_O_EXITKILL /* Only defined in Linux Kernel 3.8 or later. */ -#define PTRACE_O_EXITKILL 0x00100000 +#define PTRACE_O_EXITKILL 0x00100000 #endif #if (defined __bfin__ || defined __frv__ || defined __sh__) \ - && !defined PTRACE_GETFDPIC -#define PTRACE_GETFDPIC 31 -#define PTRACE_GETFDPIC_EXEC 0 -#define PTRACE_GETFDPIC_INTERP 1 + && !defined PTRACE_GETFDPIC +#define PTRACE_GETFDPIC 31 +#define PTRACE_GETFDPIC_EXEC 0 +#define PTRACE_GETFDPIC_INTERP 1 #endif /* We can't always assume that this flag is available, but all systems with the ptrace event handlers also have __WALL, so it's safe to use in some contexts. */ #ifndef __WALL -#define __WALL 0x40000000 /* Wait for any child. */ +#define __WALL 0x40000000 /* Wait for any child. */ #endif /* True if whether a breakpoint/watchpoint triggered can be determined @@ -159,21 +159,21 @@ struct buffer; The generic Linux target code should use GDB_ARCH_IS_TRAP_* instead of TRAP_* to abstract out these peculiarities. */ #if defined __i386__ || defined __x86_64__ -# define GDB_ARCH_IS_TRAP_BRKPT(X) ((X) == SI_KERNEL) -# define GDB_ARCH_IS_TRAP_HWBKPT(X) ((X) == TRAP_HWBKPT) +#define GDB_ARCH_IS_TRAP_BRKPT(X) ((X) == SI_KERNEL) +#define GDB_ARCH_IS_TRAP_HWBKPT(X) ((X) == TRAP_HWBKPT) #elif defined __powerpc__ -# define GDB_ARCH_IS_TRAP_BRKPT(X) ((X) == SI_KERNEL || (X) == TRAP_BRKPT) -# define GDB_ARCH_IS_TRAP_HWBKPT(X) ((X) == TRAP_HWBKPT) +#define GDB_ARCH_IS_TRAP_BRKPT(X) ((X) == SI_KERNEL || (X) == TRAP_BRKPT) +#define GDB_ARCH_IS_TRAP_HWBKPT(X) ((X) == TRAP_HWBKPT) #elif defined __mips__ -# define GDB_ARCH_IS_TRAP_BRKPT(X) ((X) == SI_KERNEL || (X) == TRAP_BRKPT) -# define GDB_ARCH_IS_TRAP_HWBKPT(X) ((X) == SI_KERNEL || (X) == TRAP_HWBKPT) +#define GDB_ARCH_IS_TRAP_BRKPT(X) ((X) == SI_KERNEL || (X) == TRAP_BRKPT) +#define GDB_ARCH_IS_TRAP_HWBKPT(X) ((X) == SI_KERNEL || (X) == TRAP_HWBKPT) #else -# define GDB_ARCH_IS_TRAP_BRKPT(X) ((X) == TRAP_BRKPT) -# define GDB_ARCH_IS_TRAP_HWBKPT(X) ((X) == TRAP_HWBKPT) +#define GDB_ARCH_IS_TRAP_BRKPT(X) ((X) == TRAP_BRKPT) +#define GDB_ARCH_IS_TRAP_HWBKPT(X) ((X) == TRAP_HWBKPT) #endif #ifndef TRAP_HWBKPT -# define TRAP_HWBKPT 4 +#define TRAP_HWBKPT 4 #endif extern std::string linux_ptrace_attach_fail_reason (pid_t pid); @@ -181,7 +181,8 @@ extern std::string linux_ptrace_attach_fail_reason (pid_t pid); /* Find all possible reasons we could have failed to attach to PTID and return them as a string. ERR is the error PTRACE_ATTACH failed with (an errno). */ -extern std::string linux_ptrace_attach_fail_reason_string (ptid_t ptid, int err); +extern std::string linux_ptrace_attach_fail_reason_string (ptid_t ptid, + int err); extern void linux_ptrace_init_warnings (void); extern void linux_check_ptrace_features (void); diff --git a/gdb/nat/linux-waitpid.c b/gdb/nat/linux-waitpid.c index b10f333..f7f751e 100644 --- a/gdb/nat/linux-waitpid.c +++ b/gdb/nat/linux-waitpid.c @@ -40,8 +40,7 @@ status_to_str (int status) strsignal (WSTOPSIG (status))); } else if (WIFSIGNALED (status)) - return string_printf ("%s - %s (terminated)", - strsigno (WTERMSIG (status)), + return string_printf ("%s - %s (terminated)", strsigno (WTERMSIG (status)), strsignal (WTERMSIG (status))); else return string_printf ("%d (exited)", WEXITSTATUS (status)); diff --git a/gdb/nat/mips-linux-watch.c b/gdb/nat/mips-linux-watch.c index 5b2b48a..fb64093 100644 --- a/gdb/nat/mips-linux-watch.c +++ b/gdb/nat/mips-linux-watch.c @@ -32,7 +32,7 @@ mips_linux_watch_get_irw_mask (struct pt_watch_regs *regs, int n) case pt_watch_style_mips64: return regs->mips64.watch_masks[n] & IRW_MASK; default: - internal_error (_("Unrecognized watch register style")); + internal_error (_ ("Unrecognized watch register style")); } } @@ -49,7 +49,7 @@ get_reg_mask (struct pt_watch_regs *regs, int n) case pt_watch_style_mips64: return regs->mips64.watch_masks[n] & ~IRW_MASK; default: - internal_error (_("Unrecognized watch register style")); + internal_error (_ ("Unrecognized watch register style")); } } @@ -65,7 +65,7 @@ mips_linux_watch_get_num_valid (struct pt_watch_regs *regs) case pt_watch_style_mips64: return regs->mips64.num_valid; default: - internal_error (_("Unrecognized watch register style")); + internal_error (_ ("Unrecognized watch register style")); } } @@ -82,7 +82,7 @@ mips_linux_watch_get_watchlo (struct pt_watch_regs *regs, int n) case pt_watch_style_mips64: return regs->mips64.watchlo[n]; default: - internal_error (_("Unrecognized watch register style")); + internal_error (_ ("Unrecognized watch register style")); } } @@ -104,7 +104,7 @@ mips_linux_watch_set_watchlo (struct pt_watch_regs *regs, int n, regs->mips64.watchlo[n] = value; break; default: - internal_error (_("Unrecognized watch register style")); + internal_error (_ ("Unrecognized watch register style")); } } @@ -121,7 +121,7 @@ mips_linux_watch_get_watchhi (struct pt_watch_regs *regs, int n) case pt_watch_style_mips64: return regs->mips64.watchhi[n]; default: - internal_error (_("Unrecognized watch register style")); + internal_error (_ ("Unrecognized watch register style")); } } @@ -141,7 +141,7 @@ mips_linux_watch_set_watchhi (struct pt_watch_regs *regs, int n, regs->mips64.watchhi[n] = value; break; default: - internal_error (_("Unrecognized watch register style")); + internal_error (_ ("Unrecognized watch register style")); } } @@ -226,8 +226,8 @@ fill_mask (CORE_ADDR mask) is IRW. Return 1 on success, 0 on failure. */ int -mips_linux_watch_try_one_watch (struct pt_watch_regs *regs, - CORE_ADDR addr, int len, uint32_t irw) +mips_linux_watch_try_one_watch (struct pt_watch_regs *regs, CORE_ADDR addr, + int len, uint32_t irw) { CORE_ADDR base_addr, last_byte, break_addr, segment_len; CORE_ADDR mask_bits, t_low; @@ -259,8 +259,7 @@ mips_linux_watch_try_one_watch (struct pt_watch_regs *regs, for (i = 0; i < mips_linux_watch_get_num_valid (regs); i++) { t_low = mips_linux_watch_get_watchlo (regs, i); - if (t_low == 0 - && irw == (mips_linux_watch_get_irw_mask (regs, i) & irw)) + if (t_low == 0 && irw == (mips_linux_watch_get_irw_mask (regs, i) & irw)) { if (mask_bits <= (get_reg_mask (regs, i) | IRW_MASK)) { diff --git a/gdb/nat/mips-linux-watch.h b/gdb/nat/mips-linux-watch.h index c38669e..fb108f0 100644 --- a/gdb/nat/mips-linux-watch.h +++ b/gdb/nat/mips-linux-watch.h @@ -27,10 +27,11 @@ have hardware watchpoint-related structures. Define them below. */ #ifndef PTRACE_GET_WATCH_REGS -# define PTRACE_GET_WATCH_REGS 0xd0 -# define PTRACE_SET_WATCH_REGS 0xd1 +#define PTRACE_GET_WATCH_REGS 0xd0 +#define PTRACE_SET_WATCH_REGS 0xd1 -enum pt_watch_style { +enum pt_watch_style +{ pt_watch_style_mips32, pt_watch_style_mips64 }; @@ -67,6 +68,7 @@ struct mips64_watch_regs struct pt_watch_regs { enum pt_watch_style style; + union { struct mips32_watch_regs mips32; @@ -106,8 +108,8 @@ void mips_linux_watch_set_watchlo (struct pt_watch_regs *regs, int n, uint32_t mips_linux_watch_get_watchhi (struct pt_watch_regs *regs, int n); void mips_linux_watch_set_watchhi (struct pt_watch_regs *regs, int n, uint16_t value); -int mips_linux_watch_try_one_watch (struct pt_watch_regs *regs, - CORE_ADDR addr, int len, uint32_t irw); +int mips_linux_watch_try_one_watch (struct pt_watch_regs *regs, CORE_ADDR addr, + int len, uint32_t irw); void mips_linux_watch_populate_regs (struct mips_watchpoint *current_watches, struct pt_watch_regs *regs); uint32_t mips_linux_watch_type_to_irw (enum target_hw_bp_type type); diff --git a/gdb/nat/netbsd-nat.c b/gdb/nat/netbsd-nat.c index 143721b..7751e2f 100644 --- a/gdb/nat/netbsd-nat.c +++ b/gdb/nat/netbsd-nat.c @@ -38,7 +38,7 @@ const char * pid_to_exec_file (pid_t pid) { static char buf[PATH_MAX]; - int mib[4] = {CTL_KERN, KERN_PROC_ARGS, pid, KERN_PROC_PATHNAME}; + int mib[4] = { CTL_KERN, KERN_PROC_ARGS, pid, KERN_PROC_PATHNAME }; size_t buflen = sizeof (buf); if (::sysctl (mib, ARRAY_SIZE (mib), buf, &buflen, NULL, 0) != 0) return NULL; @@ -53,11 +53,11 @@ pid_to_exec_file (pid_t pid) and the number of threads does not change between two sysctl () calls. */ static bool -netbsd_thread_lister (const pid_t pid, - gdb::function_view<bool (const struct kinfo_lwp *)> - callback) +netbsd_thread_lister ( + const pid_t pid, + gdb::function_view<bool (const struct kinfo_lwp *)> callback) { - int mib[5] = {CTL_KERN, KERN_LWP, pid, sizeof (struct kinfo_lwp), 0}; + int mib[5] = { CTL_KERN, KERN_LWP, pid, sizeof (struct kinfo_lwp), 0 }; size_t size; if (sysctl (mib, ARRAY_SIZE (mib), NULL, &size, NULL, 0) == -1 || size == 0) @@ -65,8 +65,8 @@ netbsd_thread_lister (const pid_t pid, mib[4] = size / sizeof (size_t); - gdb::unique_xmalloc_ptr<struct kinfo_lwp[]> kl - ((struct kinfo_lwp *) xcalloc (size, 1)); + gdb::unique_xmalloc_ptr<struct kinfo_lwp[]> kl ((struct kinfo_lwp *) + xcalloc (size, 1)); if (sysctl (mib, ARRAY_SIZE (mib), kl.get (), &size, NULL, 0) == -1 || size == 0) @@ -77,21 +77,19 @@ netbsd_thread_lister (const pid_t pid, struct kinfo_lwp *l = &kl[i]; /* Return true if the specified thread is alive. */ - auto lwp_alive - = [] (struct kinfo_lwp *lwp) + auto lwp_alive = [] (struct kinfo_lwp *lwp) { + switch (lwp->l_stat) { - switch (lwp->l_stat) - { - case LSSLEEP: - case LSRUN: - case LSONPROC: - case LSSTOP: - case LSSUSPENDED: - return true; - default: - return false; - } - }; + case LSSLEEP: + case LSRUN: + case LSONPROC: + case LSSTOP: + case LSSUSPENDED: + return true; + default: + return false; + } + }; /* Ignore embryonic or demised threads. */ if (!lwp_alive (l)) @@ -112,11 +110,7 @@ thread_alive (ptid_t ptid) pid_t pid = ptid.pid (); lwpid_t lwp = ptid.lwp (); - auto fn - = [=] (const struct kinfo_lwp *kl) - { - return kl->l_lid == lwp; - }; + auto fn = [=] (const struct kinfo_lwp *kl) { return kl->l_lid == lwp; }; return netbsd_thread_lister (pid, fn); } @@ -131,16 +125,14 @@ thread_name (ptid_t ptid) static char buf[KI_LNAMELEN] = {}; - auto fn - = [=] (const struct kinfo_lwp *kl) + auto fn = [=] (const struct kinfo_lwp *kl) { + if (kl->l_lid == lwp) { - if (kl->l_lid == lwp) - { - xsnprintf (buf, sizeof buf, "%s", kl->l_name); - return true; - } - return false; - }; + xsnprintf (buf, sizeof buf, "%s", kl->l_name); + return true; + } + return false; + }; if (netbsd_thread_lister (pid, fn)) return buf; @@ -153,13 +145,11 @@ thread_name (ptid_t ptid) void for_each_thread (pid_t pid, gdb::function_view<void (ptid_t)> callback) { - auto fn - = [=, &callback] (const struct kinfo_lwp *kl) - { - ptid_t ptid = ptid_t (pid, kl->l_lid, 0); - callback (ptid); - return false; - }; + auto fn = [=, &callback] (const struct kinfo_lwp *kl) { + ptid_t ptid = ptid_t (pid, kl->l_lid, 0); + callback (ptid); + return false; + }; netbsd_thread_lister (pid, fn); } @@ -227,8 +217,8 @@ write_memory (pid_t pid, unsigned const char *writebuf, CORE_ADDR offset, { do { - io.piod_addr = (void *)(writebuf + bytes_written); - io.piod_offs = (void *)(offset + bytes_written); + io.piod_addr = (void *) (writebuf + bytes_written); + io.piod_offs = (void *) (offset + bytes_written); errno = 0; int rv = ptrace (PT_IO, pid, &io, 0); @@ -255,8 +245,8 @@ write_memory (pid_t pid, unsigned const char *writebuf, CORE_ADDR offset, /* See netbsd-nat.h. */ int -read_memory (pid_t pid, unsigned char *readbuf, CORE_ADDR offset, - size_t len, size_t *xfered_len) +read_memory (pid_t pid, unsigned char *readbuf, CORE_ADDR offset, size_t len, + size_t *xfered_len) { struct ptrace_io_desc io; io.piod_op = PIOD_READ_D; @@ -269,7 +259,7 @@ read_memory (pid_t pid, unsigned char *readbuf, CORE_ADDR offset, { do { - io.piod_offs = (void *)(offset + bytes_read); + io.piod_offs = (void *) (offset + bytes_read); io.piod_addr = readbuf + bytes_read; int rv = ptrace (PT_IO, pid, &io, 0); @@ -290,4 +280,4 @@ read_memory (pid_t pid, unsigned char *readbuf, CORE_ADDR offset, return 0; } -} +} // namespace netbsd_nat diff --git a/gdb/nat/netbsd-nat.h b/gdb/nat/netbsd-nat.h index 1295cb2..2b8b1cb 100644 --- a/gdb/nat/netbsd-nat.h +++ b/gdb/nat/netbsd-nat.h @@ -89,6 +89,6 @@ extern int write_memory (pid_t pid, unsigned const char *writebuf, extern int read_memory (pid_t pid, unsigned char *readbuf, CORE_ADDR offset, size_t len, size_t *xfered_len); -} +} // namespace netbsd_nat #endif diff --git a/gdb/nat/ppc-linux.h b/gdb/nat/ppc-linux.h index c84f914..ac23a8d 100644 --- a/gdb/nat/ppc-linux.h +++ b/gdb/nat/ppc-linux.h @@ -37,7 +37,7 @@ #define PPC_FEATURE_BOOKE 0x00008000 #endif #ifndef PPC_FEATURE_HAS_DFP -#define PPC_FEATURE_HAS_DFP 0x00000400 /* Decimal Floating Point. */ +#define PPC_FEATURE_HAS_DFP 0x00000400 /* Decimal Floating Point. */ #endif #ifndef PPC_FEATURE_HAS_VSX #define PPC_FEATURE_HAS_VSX 0x00000080 diff --git a/gdb/nat/riscv-linux-tdesc.c b/gdb/nat/riscv-linux-tdesc.c index d676233..f09a909 100644 --- a/gdb/nat/riscv-linux-tdesc.c +++ b/gdb/nat/riscv-linux-tdesc.c @@ -28,7 +28,7 @@ /* Work around glibc header breakage causing ELF_NFPREG not to be usable. */ #ifndef NFPREG -# define NFPREG 33 +#define NFPREG 33 #endif /* See nat/riscv-linux-tdesc.h. */ @@ -47,7 +47,7 @@ riscv_linux_read_features (int tid) features.flen = 0; /* How much worth of f-registers can we fetch if any? */ - for (flen = sizeof (regs.__f.__f[0]); ; flen *= 2) + for (flen = sizeof (regs.__f.__f[0]);; flen *= 2) { size_t regset_size; struct iovec iov; @@ -60,8 +60,8 @@ riscv_linux_read_features (int tid) iov.iov_base = ®s; iov.iov_len = regset_size; - if (ptrace (PTRACE_GETREGSET, tid, NT_FPREGSET, - (PTRACE_TYPE_ARG3) &iov) == -1) + if (ptrace (PTRACE_GETREGSET, tid, NT_FPREGSET, (PTRACE_TYPE_ARG3) &iov) + == -1) { switch (errno) { @@ -70,7 +70,7 @@ riscv_linux_read_features (int tid) case EIO: break; default: - perror_with_name (_("Couldn't get registers")); + perror_with_name (_ ("Couldn't get registers")); break; } } diff --git a/gdb/nat/windows-nat.c b/gdb/nat/windows-nat.c index 8028494..c9f7e7f 100644 --- a/gdb/nat/windows-nat.c +++ b/gdb/nat/windows-nat.c @@ -74,9 +74,9 @@ DeleteProcThreadAttributeList_ftype *DeleteProcThreadAttributeList; /* Note that 'debug_events' must be locally defined in the relevant functions. */ -#define DEBUG_EVENTS(fmt, ...) \ +#define DEBUG_EVENTS(fmt, ...) \ debug_prefixed_printf_cond (debug_events, "windows events", fmt, \ - ## __VA_ARGS__) + ##__VA_ARGS__) void windows_thread_info::suspend () @@ -95,7 +95,7 @@ windows_thread_info::suspend () We can get Invalid Handle (6) if the main thread has exited. */ if (err != ERROR_INVALID_HANDLE && err != ERROR_ACCESS_DENIED) - warning (_("SuspendThread (tid=0x%x) failed. (winerr %u: %s)"), + warning (_ ("SuspendThread (tid=0x%x) failed. (winerr %u: %s)"), (unsigned) tid, (unsigned) err, strwinerror (err)); suspended = -1; } @@ -113,8 +113,9 @@ windows_thread_info::resume () if (ResumeThread (h) == (DWORD) -1) { DWORD err = GetLastError (); - warning (_("warning: ResumeThread (tid=0x%x) failed. (winerr %u: %s)"), - (unsigned) tid, (unsigned) err, strwinerror (err)); + warning ( + _ ("warning: ResumeThread (tid=0x%x) failed. (winerr %u: %s)"), + (unsigned) tid, (unsigned) err, strwinerror (err)); } } suspended = 0; @@ -138,13 +139,12 @@ windows_thread_info::thread_name () character. It seems better to just reject bad conversions here. */ BOOL used_default = FALSE; - gdb::unique_xmalloc_ptr<char> new_name - ((char *) xmalloc (needed)); - if (WideCharToMultiByte (CP_ACP, 0, value, -1, - new_name.get (), needed, - nullptr, &used_default) == needed - && !used_default - && strlen (new_name.get ()) > 0) + gdb::unique_xmalloc_ptr<char> new_name ((char *) + xmalloc (needed)); + if (WideCharToMultiByte (CP_ACP, 0, value, -1, new_name.get (), + needed, nullptr, &used_default) + == needed + && !used_default && strlen (new_name.get ()) > 0) name = std::move (new_name); } LocalFree (value); @@ -176,8 +176,7 @@ windows_process_info::get_exec_module_filename (char *exe_name_ret, #ifdef __x86_64__ if (wow64_process) { - if (!EnumProcessModulesEx (handle, - &dh_buf, sizeof (HMODULE), &cbNeeded, + if (!EnumProcessModulesEx (handle, &dh_buf, sizeof (HMODULE), &cbNeeded, LIST_MODULES_32BIT) || !cbNeeded) return 0; @@ -185,13 +184,12 @@ windows_process_info::get_exec_module_filename (char *exe_name_ret, else #endif { - if (!EnumProcessModules (handle, - &dh_buf, sizeof (HMODULE), &cbNeeded) + if (!EnumProcessModules (handle, &dh_buf, sizeof (HMODULE), &cbNeeded) || !cbNeeded) return 0; } - /* We know the executable is always first in the list of modules, + /* We know the executable is always first in the list of modules, which we just fetched. So no need to fetch more. */ #ifdef __CYGWIN__ @@ -199,32 +197,32 @@ windows_process_info::get_exec_module_filename (char *exe_name_ret, /* Cygwin prefers that the path be in /x/y/z format, so extract the filename into a temporary buffer first, and then convert it to POSIX format into the destination buffer. */ - wchar_t *pathbuf = (wchar_t *) alloca (exe_name_max_len * sizeof (wchar_t)); + wchar_t *pathbuf + = (wchar_t *) alloca (exe_name_max_len * sizeof (wchar_t)); - len = GetModuleFileNameEx (handle, - dh_buf, pathbuf, exe_name_max_len); + len = GetModuleFileNameEx (handle, dh_buf, pathbuf, exe_name_max_len); if (len == 0) { unsigned err = (unsigned) GetLastError (); - error (_("Error getting executable filename (error %u): %s"), - err, strwinerror (err)); + error (_ ("Error getting executable filename (error %u): %s"), err, + strwinerror (err)); } if (cygwin_conv_path (CCP_WIN_W_TO_POSIX, pathbuf, exe_name_ret, - exe_name_max_len) < 0) - error (_("Error converting executable filename to POSIX: %d."), errno); + exe_name_max_len) + < 0) + error (_ ("Error converting executable filename to POSIX: %d."), errno); } #else - len = GetModuleFileNameEx (handle, - dh_buf, exe_name_ret, exe_name_max_len); + len = GetModuleFileNameEx (handle, dh_buf, exe_name_ret, exe_name_max_len); if (len == 0) { unsigned err = (unsigned) GetLastError (); - error (_("Error getting executable filename (error %u): %s"), - err, strwinerror (err)); + error (_ ("Error getting executable filename (error %u): %s"), err, + strwinerror (err)); } #endif - return 1; /* success */ + return 1; /* success */ } const char * @@ -237,10 +235,10 @@ windows_process_info::pid_to_exec_file (int pid) char procexe[sizeof ("/proc/4294967295/exe")]; xsnprintf (procexe, sizeof (procexe), "/proc/%u/exe", pid); - nchars = readlink (procexe, path, sizeof(path)); + nchars = readlink (procexe, path, sizeof (path)); if (nchars > 0 && nchars < sizeof (path)) { - path[nchars] = '\0'; /* Got it */ + path[nchars] = '\0'; /* Got it */ return path; } #endif @@ -281,10 +279,9 @@ get_image_name (HANDLE h, void *address, int unicode) /* See if we could read the address of a string, and that the address isn't null. */ - if (!ReadProcessMemory (h, address, &address_ptr, - sizeof (address_ptr), &done) - || done != sizeof (address_ptr) - || !address_ptr) + if (!ReadProcessMemory (h, address, &address_ptr, sizeof (address_ptr), + &done) + || done != sizeof (address_ptr) || !address_ptr) return NULL; /* Find the length of the string. */ @@ -302,8 +299,8 @@ get_image_name (HANDLE h, void *address, int unicode) #ifdef __CYGWIN__ wcstombs (buf, unicode_address, MAX_PATH); #else - WideCharToMultiByte (CP_ACP, 0, unicode_address, len, buf, sizeof buf, - 0, 0); + WideCharToMultiByte (CP_ACP, 0, unicode_address, len, buf, sizeof buf, 0, + 0); #endif } @@ -328,9 +325,9 @@ windows_process_info::handle_ms_vc_exception (const EXCEPTION_RECORD *rec) if (named_thread_id == (DWORD) -1) named_thread_id = current_event.dwThreadId; - named_thread = thread_rec (ptid_t (current_event.dwProcessId, - named_thread_id, 0), - DONT_INVALIDATE_CONTEXT); + named_thread + = thread_rec (ptid_t (current_event.dwProcessId, named_thread_id, 0), + DONT_INVALIDATE_CONTEXT); if (named_thread != NULL) { int thread_name_len; @@ -359,10 +356,11 @@ handle_exception_result windows_process_info::handle_exception (struct target_waitstatus *ourstatus, bool debug_exceptions) { -#define DEBUG_EXCEPTION_SIMPLE(x) if (debug_exceptions) \ - debug_printf ("gdb: Target exception %s at %s\n", x, \ - host_address_to_string (\ - current_event.u.Exception.ExceptionRecord.ExceptionAddress)) +#define DEBUG_EXCEPTION_SIMPLE(x) \ + if (debug_exceptions) \ + debug_printf ("gdb: Target exception %s at %s\n", x, \ + host_address_to_string (current_event.u.Exception \ + .ExceptionRecord.ExceptionAddress)) EXCEPTION_RECORD *rec = ¤t_event.u.Exception.ExceptionRecord; DWORD code = rec->ExceptionCode; @@ -436,7 +434,8 @@ windows_process_info::handle_exception (struct target_waitstatus *ourstatus, on startup, first a BREAKPOINT for the 64bit ntdll.dll, then a WX86_BREAKPOINT for the 32bit ntdll.dll. Here we only care about the WX86_BREAKPOINT's. */ - DEBUG_EXCEPTION_SIMPLE ("EXCEPTION_BREAKPOINT - ignore_first_breakpoint"); + DEBUG_EXCEPTION_SIMPLE ( + "EXCEPTION_BREAKPOINT - ignore_first_breakpoint"); ourstatus->set_spurious (); ignore_first_breakpoint = false; break; @@ -494,13 +493,14 @@ windows_process_info::handle_exception (struct target_waitstatus *ourstatus, result = HANDLE_EXCEPTION_IGNORED; break; } - /* treat improperly formed exception as unknown */ - /* FALLTHROUGH */ + /* treat improperly formed exception as unknown */ + /* FALLTHROUGH */ default: /* Treat unhandled first chance exceptions specially. */ if (current_event.u.Exception.dwFirstChance) return HANDLE_EXCEPTION_UNHANDLED; - debug_printf ("gdb: unknown target exception 0x%08x at %s\n", + debug_printf ( + "gdb: unknown target exception 0x%08x at %s\n", (unsigned) current_event.u.Exception.ExceptionRecord.ExceptionCode, host_address_to_string ( current_event.u.Exception.ExceptionRecord.ExceptionAddress)); @@ -529,16 +529,17 @@ windows_process_info::add_dll (LPVOID load_addr) #ifdef __x86_64__ if (wow64_process) { - if (EnumProcessModulesEx (handle, &dummy_hmodule, - sizeof (HMODULE), &cb_needed, - LIST_MODULES_32BIT) == 0) + if (EnumProcessModulesEx (handle, &dummy_hmodule, sizeof (HMODULE), + &cb_needed, LIST_MODULES_32BIT) + == 0) return; } else #endif { - if (EnumProcessModules (handle, &dummy_hmodule, - sizeof (HMODULE), &cb_needed) == 0) + if (EnumProcessModules (handle, &dummy_hmodule, sizeof (HMODULE), + &cb_needed) + == 0) return; } @@ -549,16 +550,15 @@ windows_process_info::add_dll (LPVOID load_addr) #ifdef __x86_64__ if (wow64_process) { - if (EnumProcessModulesEx (handle, hmodules, - cb_needed, &cb_needed, - LIST_MODULES_32BIT) == 0) + if (EnumProcessModulesEx (handle, hmodules, cb_needed, &cb_needed, + LIST_MODULES_32BIT) + == 0) return; } else #endif { - if (EnumProcessModules (handle, hmodules, - cb_needed, &cb_needed) == 0) + if (EnumProcessModules (handle, hmodules, cb_needed, &cb_needed) == 0) return; } @@ -590,7 +590,6 @@ windows_process_info::add_dll (LPVOID load_addr) convert_syswow_dir = true; } - } for (i = 1; i < (int) (cb_needed / sizeof (HMODULE)); i++) { @@ -602,12 +601,12 @@ windows_process_info::add_dll (LPVOID load_addr) char dll_name[MAX_PATH]; #endif const char *name; - if (GetModuleInformation (handle, hmodules[i], - &mi, sizeof (mi)) == 0) + if (GetModuleInformation (handle, hmodules[i], &mi, sizeof (mi)) == 0) continue; - if (GetModuleFileNameEx (handle, hmodules[i], - dll_name, sizeof (dll_name)) == 0) + if (GetModuleFileNameEx (handle, hmodules[i], dll_name, + sizeof (dll_name)) + == 0) continue; #ifdef __USEWIDE wcstombs (dll_name_mb, dll_name, MAX_PATH); @@ -625,7 +624,7 @@ windows_process_info::add_dll (LPVOID load_addr) { syswow_dll_path = syswow_dir; syswow_dll_path += name + system_dir_len; - name = syswow_dll_path.c_str(); + name = syswow_dll_path.c_str (); } /* Record the DLL if either LOAD_ADDR is NULL or the address @@ -702,8 +701,7 @@ gdb::optional<pending_stop> windows_process_info::fetch_pending_stop (bool debug_events) { gdb::optional<pending_stop> result; - for (auto iter = pending_stops.begin (); - iter != pending_stops.end (); + for (auto iter = pending_stops.begin (); iter != pending_stops.end (); ++iter) { if (desired_stop_thread_id == -1 @@ -731,12 +729,11 @@ continue_last_debug_event (DWORD continue_status, bool debug_events) DEBUG_EVENTS ("ContinueDebugEvent (cpid=%d, ctid=0x%x, %s)", (unsigned) last_wait_event.dwProcessId, (unsigned) last_wait_event.dwThreadId, - continue_status == DBG_CONTINUE ? - "DBG_CONTINUE" : "DBG_EXCEPTION_NOT_HANDLED"); + continue_status == DBG_CONTINUE ? "DBG_CONTINUE" + : "DBG_EXCEPTION_NOT_HANDLED"); return ContinueDebugEvent (last_wait_event.dwProcessId, - last_wait_event.dwThreadId, - continue_status); + last_wait_event.dwThreadId, continue_status); } /* See nat/windows-nat.h. */ @@ -759,10 +756,11 @@ wait_for_debug_event (DEBUG_EVENT *event, DWORD timeout) /* Pick one of the symbols as a sentinel. */ #ifdef PROCESS_CREATION_MITIGATION_POLICY_FORCE_RELOCATE_IMAGES_ALWAYS_OFF -static_assert ((PROCESS_CREATION_MITIGATION_POLICY_FORCE_RELOCATE_IMAGES_ALWAYS_OFF - | PROCESS_CREATION_MITIGATION_POLICY_BOTTOM_UP_ASLR_ALWAYS_OFF) - == relocate_aslr_flags, - "check that ASLR flag values are correct"); +static_assert ( + (PROCESS_CREATION_MITIGATION_POLICY_FORCE_RELOCATE_IMAGES_ALWAYS_OFF + | PROCESS_CREATION_MITIGATION_POLICY_BOTTOM_UP_ASLR_ALWAYS_OFF) + == relocate_aslr_flags, + "check that ASLR flag values are correct"); static_assert (PROC_THREAD_ATTRIBUTE_MITIGATION_POLICY == mitigation_policy, "check that mitigation policy value is correct"); @@ -779,11 +777,9 @@ static_assert (PROC_THREAD_ATTRIBUTE_MITIGATION_POLICY == mitigation_policy, template<typename FUNC, typename CHAR, typename INFO> BOOL create_process_wrapper (FUNC *do_create_process, const CHAR *image, - CHAR *command_line, DWORD flags, - void *environment, const CHAR *cur_dir, - bool no_randomization, - INFO *startup_info, - PROCESS_INFORMATION *process_info) + CHAR *command_line, DWORD flags, void *environment, + const CHAR *cur_dir, bool no_randomization, + INFO *startup_info, PROCESS_INFORMATION *process_info) { if (no_randomization && disable_randomization_available ()) { @@ -800,9 +796,9 @@ create_process_wrapper (FUNC *do_create_process, const CHAR *image, gdb_lpproc_thread_attribute_list lpAttributeList; }; -# ifndef EXTENDED_STARTUPINFO_PRESENT -# define EXTENDED_STARTUPINFO_PRESENT 0x00080000 -# endif +#ifndef EXTENDED_STARTUPINFO_PRESENT +#define EXTENDED_STARTUPINFO_PRESENT 0x00080000 +#endif gdb_extended_info info_ex {}; @@ -815,28 +811,24 @@ create_process_wrapper (FUNC *do_create_process, const CHAR *image, InitializeProcThreadAttributeList (nullptr, 1, 0, &size); info_ex.lpAttributeList = (gdb_lpproc_thread_attribute_list) alloca (size); - InitializeProcThreadAttributeList (info_ex.lpAttributeList, - 1, 0, &size); + InitializeProcThreadAttributeList (info_ex.lpAttributeList, 1, 0, + &size); gdb::optional<BOOL> return_value; DWORD attr_flags = relocate_aslr_flags; if (!UpdateProcThreadAttribute (info_ex.lpAttributeList, 0, - mitigation_policy, - &attr_flags, - sizeof (attr_flags), - nullptr, nullptr)) + mitigation_policy, &attr_flags, + sizeof (attr_flags), nullptr, + nullptr)) tried_and_failed = true; else { - BOOL result = do_create_process (image, command_line, - nullptr, nullptr, - TRUE, - (flags - | EXTENDED_STARTUPINFO_PRESENT), - environment, - cur_dir, - &info_ex.StartupInfo, - process_info); + BOOL result + = do_create_process (image, command_line, nullptr, nullptr, + TRUE, + (flags | EXTENDED_STARTUPINFO_PRESENT), + environment, cur_dir, + &info_ex.StartupInfo, process_info); if (result) return_value = result; else if (GetLastError () == ERROR_INVALID_PARAMETER) @@ -852,26 +844,22 @@ create_process_wrapper (FUNC *do_create_process, const CHAR *image, } } - return do_create_process (image, - command_line, /* command line */ - nullptr, /* Security */ - nullptr, /* thread */ - TRUE, /* inherit handles */ - flags, /* start flags */ - environment, /* environment */ - cur_dir, /* current directory */ - startup_info, - process_info); + return do_create_process (image, command_line, /* command line */ + nullptr, /* Security */ + nullptr, /* thread */ + TRUE, /* inherit handles */ + flags, /* start flags */ + environment, /* environment */ + cur_dir, /* current directory */ + startup_info, process_info); } /* See nat/windows-nat.h. */ BOOL create_process (const char *image, char *command_line, DWORD flags, - void *environment, const char *cur_dir, - bool no_randomization, - STARTUPINFOA *startup_info, - PROCESS_INFORMATION *process_info) + void *environment, const char *cur_dir, bool no_randomization, + STARTUPINFOA *startup_info, PROCESS_INFORMATION *process_info) { return create_process_wrapper (CreateProcessA, image, command_line, flags, environment, cur_dir, no_randomization, @@ -885,8 +873,7 @@ create_process (const char *image, char *command_line, DWORD flags, BOOL create_process (const wchar_t *image, wchar_t *command_line, DWORD flags, void *environment, const wchar_t *cur_dir, - bool no_randomization, - STARTUPINFOW *startup_info, + bool no_randomization, STARTUPINFOW *startup_info, PROCESS_INFORMATION *process_info) { return create_process_wrapper (CreateProcessW, image, command_line, flags, @@ -927,7 +914,7 @@ bad_GetConsoleFontSize (HANDLE w, DWORD nFont) size.Y = 12; return size; } - + /* See windows-nat.h. */ bool @@ -946,8 +933,7 @@ initialize_loadable () bool result = true; HMODULE hm = NULL; -#define GPA(m, func) \ - func = (func ## _ftype *) GetProcAddress (m, #func) +#define GPA(m, func) func = (func##_ftype *) GetProcAddress (m, #func) hm = LoadLibrary (TEXT ("kernel32.dll")); if (hm) @@ -1000,8 +986,8 @@ initialize_loadable () GPA (hm, GetModuleFileNameExW); } - if (!EnumProcessModules || !GetModuleInformation - || !GetModuleFileNameExA || !GetModuleFileNameExW) + if (!EnumProcessModules || !GetModuleInformation || !GetModuleFileNameExA + || !GetModuleFileNameExW) { /* Set variables to dummy versions of these processes if the function wasn't found in psapi.dll. */ @@ -1040,4 +1026,4 @@ initialize_loadable () return result; } -} +} // namespace windows_nat diff --git a/gdb/nat/windows-nat.h b/gdb/nat/windows-nat.h index e3ea7db..d6725de 100644 --- a/gdb/nat/windows-nat.h +++ b/gdb/nat/windows-nat.h @@ -101,7 +101,6 @@ struct windows_thread_info gdb::unique_xmalloc_ptr<char> name; }; - /* Possible values to pass to 'thread_rec'. */ enum thread_disposition_type { @@ -177,14 +176,14 @@ struct windows_process_info bool ignore_first_breakpoint = false; #endif - /* Find a thread record given a thread id. THREAD_DISPOSITION controls whether the thread is suspended, and whether the context is invalidated. This function must be supplied by the embedding application. */ virtual windows_thread_info *thread_rec (ptid_t ptid, - thread_disposition_type disposition) = 0; + thread_disposition_type disposition) + = 0; /* Handle OUTPUT_DEBUG_STRING_EVENT from child process. Updates OURSTATUS and returns the thread id if this represents a thread @@ -194,7 +193,8 @@ struct windows_process_info a Cygwin signal. Otherwise just print the string as a warning. This function must be supplied by the embedding application. */ - virtual int handle_output_debug_string (struct target_waitstatus *ourstatus) = 0; + virtual int handle_output_debug_string (struct target_waitstatus *ourstatus) + = 0; /* Handle a DLL load event. @@ -224,8 +224,9 @@ struct windows_process_info virtual bool handle_access_violation (const EXCEPTION_RECORD *rec) = 0; - handle_exception_result handle_exception - (struct target_waitstatus *ourstatus, bool debug_exceptions); + handle_exception_result + handle_exception (struct target_waitstatus *ourstatus, + bool debug_exceptions); /* Call to indicate that a DLL was loaded. */ @@ -298,52 +299,48 @@ extern BOOL wait_for_debug_event (DEBUG_EVENT *event, DWORD timeout); "disable randomization" feature can be implemented in a single place. */ -extern BOOL create_process (const char *image, char *command_line, - DWORD flags, void *environment, - const char *cur_dir, - bool no_randomization, - STARTUPINFOA *startup_info, +extern BOOL create_process (const char *image, char *command_line, DWORD flags, + void *environment, const char *cur_dir, + bool no_randomization, STARTUPINFOA *startup_info, PROCESS_INFORMATION *process_info); #ifdef __CYGWIN__ extern BOOL create_process (const wchar_t *image, wchar_t *command_line, DWORD flags, void *environment, - const wchar_t *cur_dir, - bool no_randomization, + const wchar_t *cur_dir, bool no_randomization, STARTUPINFOW *startup_info, PROCESS_INFORMATION *process_info); #endif /* __CYGWIN__ */ -#define AdjustTokenPrivileges dyn_AdjustTokenPrivileges -#define DebugActiveProcessStop dyn_DebugActiveProcessStop -#define DebugBreakProcess dyn_DebugBreakProcess -#define DebugSetProcessKillOnExit dyn_DebugSetProcessKillOnExit +#define AdjustTokenPrivileges dyn_AdjustTokenPrivileges +#define DebugActiveProcessStop dyn_DebugActiveProcessStop +#define DebugBreakProcess dyn_DebugBreakProcess +#define DebugSetProcessKillOnExit dyn_DebugSetProcessKillOnExit #undef EnumProcessModules -#define EnumProcessModules dyn_EnumProcessModules +#define EnumProcessModules dyn_EnumProcessModules #undef EnumProcessModulesEx -#define EnumProcessModulesEx dyn_EnumProcessModulesEx +#define EnumProcessModulesEx dyn_EnumProcessModulesEx #undef GetModuleInformation -#define GetModuleInformation dyn_GetModuleInformation +#define GetModuleInformation dyn_GetModuleInformation #undef GetModuleFileNameExA -#define GetModuleFileNameExA dyn_GetModuleFileNameExA +#define GetModuleFileNameExA dyn_GetModuleFileNameExA #undef GetModuleFileNameExW -#define GetModuleFileNameExW dyn_GetModuleFileNameExW -#define LookupPrivilegeValueA dyn_LookupPrivilegeValueA -#define OpenProcessToken dyn_OpenProcessToken -#define GetConsoleFontSize dyn_GetConsoleFontSize -#define GetCurrentConsoleFont dyn_GetCurrentConsoleFont -#define Wow64SuspendThread dyn_Wow64SuspendThread -#define Wow64GetThreadContext dyn_Wow64GetThreadContext -#define Wow64SetThreadContext dyn_Wow64SetThreadContext -#define Wow64GetThreadSelectorEntry dyn_Wow64GetThreadSelectorEntry -#define GenerateConsoleCtrlEvent dyn_GenerateConsoleCtrlEvent +#define GetModuleFileNameExW dyn_GetModuleFileNameExW +#define LookupPrivilegeValueA dyn_LookupPrivilegeValueA +#define OpenProcessToken dyn_OpenProcessToken +#define GetConsoleFontSize dyn_GetConsoleFontSize +#define GetCurrentConsoleFont dyn_GetCurrentConsoleFont +#define Wow64SuspendThread dyn_Wow64SuspendThread +#define Wow64GetThreadContext dyn_Wow64GetThreadContext +#define Wow64SetThreadContext dyn_Wow64SetThreadContext +#define Wow64GetThreadSelectorEntry dyn_Wow64GetThreadSelectorEntry +#define GenerateConsoleCtrlEvent dyn_GenerateConsoleCtrlEvent #define InitializeProcThreadAttributeList dyn_InitializeProcThreadAttributeList #define UpdateProcThreadAttribute dyn_UpdateProcThreadAttribute #define DeleteProcThreadAttributeList dyn_DeleteProcThreadAttributeList typedef BOOL WINAPI (AdjustTokenPrivileges_ftype) (HANDLE, BOOL, - PTOKEN_PRIVILEGES, - DWORD, PTOKEN_PRIVILEGES, - PDWORD); + PTOKEN_PRIVILEGES, DWORD, + PTOKEN_PRIVILEGES, PDWORD); extern AdjustTokenPrivileges_ftype *AdjustTokenPrivileges; typedef BOOL WINAPI (DebugActiveProcessStop_ftype) (DWORD); @@ -370,11 +367,11 @@ typedef BOOL WINAPI (GetModuleInformation_ftype) (HANDLE, HMODULE, extern GetModuleInformation_ftype *GetModuleInformation; typedef DWORD WINAPI (GetModuleFileNameExA_ftype) (HANDLE, HMODULE, LPSTR, - DWORD); + DWORD); extern GetModuleFileNameExA_ftype *GetModuleFileNameExA; -typedef DWORD WINAPI (GetModuleFileNameExW_ftype) (HANDLE, HMODULE, - LPWSTR, DWORD); +typedef DWORD WINAPI (GetModuleFileNameExW_ftype) (HANDLE, HMODULE, LPWSTR, + DWORD); extern GetModuleFileNameExW_ftype *GetModuleFileNameExW; typedef BOOL WINAPI (LookupPrivilegeValueA_ftype) (LPCSTR, LPCSTR, PLUID); @@ -413,19 +410,20 @@ extern GenerateConsoleCtrlEvent_ftype *GenerateConsoleCtrlEvent; Windows 8. */ typedef void *gdb_lpproc_thread_attribute_list; -typedef BOOL WINAPI (InitializeProcThreadAttributeList_ftype) - (gdb_lpproc_thread_attribute_list lpAttributeList, - DWORD dwAttributeCount, DWORD dwFlags, PSIZE_T lpSize); -extern InitializeProcThreadAttributeList_ftype *InitializeProcThreadAttributeList; +typedef BOOL WINAPI (InitializeProcThreadAttributeList_ftype) ( + gdb_lpproc_thread_attribute_list lpAttributeList, DWORD dwAttributeCount, + DWORD dwFlags, PSIZE_T lpSize); +extern InitializeProcThreadAttributeList_ftype + *InitializeProcThreadAttributeList; -typedef BOOL WINAPI (UpdateProcThreadAttribute_ftype) - (gdb_lpproc_thread_attribute_list lpAttributeList, - DWORD dwFlags, DWORD_PTR Attribute, PVOID lpValue, SIZE_T cbSize, - PVOID lpPreviousValue, PSIZE_T lpReturnSize); +typedef BOOL WINAPI (UpdateProcThreadAttribute_ftype) ( + gdb_lpproc_thread_attribute_list lpAttributeList, DWORD dwFlags, + DWORD_PTR Attribute, PVOID lpValue, SIZE_T cbSize, PVOID lpPreviousValue, + PSIZE_T lpReturnSize); extern UpdateProcThreadAttribute_ftype *UpdateProcThreadAttribute; -typedef void WINAPI (DeleteProcThreadAttributeList_ftype) - (gdb_lpproc_thread_attribute_list lpAttributeList); +typedef void WINAPI (DeleteProcThreadAttributeList_ftype) ( + gdb_lpproc_thread_attribute_list lpAttributeList); extern DeleteProcThreadAttributeList_ftype *DeleteProcThreadAttributeList; /* Return true if it's possible to disable randomization on this @@ -438,6 +436,6 @@ extern bool disable_randomization_available (); extern bool initialize_loadable (); -} +} // namespace windows_nat #endif diff --git a/gdb/nat/x86-cpuid.h b/gdb/nat/x86-cpuid.h index 0955afb..d4c1105 100644 --- a/gdb/nat/x86-cpuid.h +++ b/gdb/nat/x86-cpuid.h @@ -30,9 +30,8 @@ unsupported cpuid level. Pointers may be non-null. */ static __inline int -x86_cpuid (unsigned int __level, - unsigned int *__eax, unsigned int *__ebx, - unsigned int *__ecx, unsigned int *__edx) +x86_cpuid (unsigned int __level, unsigned int *__eax, unsigned int *__ebx, + unsigned int *__ecx, unsigned int *__edx) { unsigned int __scratch; @@ -51,9 +50,8 @@ x86_cpuid (unsigned int __level, #else static __inline int -x86_cpuid (unsigned int __level, - unsigned int *__eax, unsigned int *__ebx, - unsigned int *__ecx, unsigned int *__edx) +x86_cpuid (unsigned int __level, unsigned int *__eax, unsigned int *__ebx, + unsigned int *__ecx, unsigned int *__edx) { return 0; } diff --git a/gdb/nat/x86-dregs.c b/gdb/nat/x86-dregs.c index 731093d..ca07d0f 100644 --- a/gdb/nat/x86-dregs.c +++ b/gdb/nat/x86-dregs.c @@ -104,28 +104,28 @@ x86_get_debug_register_length () /* DR7 Debug Control register fields. */ /* How many bits to skip in DR7 to get to R/W and LEN fields. */ -#define DR_CONTROL_SHIFT 16 +#define DR_CONTROL_SHIFT 16 /* How many bits in DR7 per R/W and LEN field for each watchpoint. */ -#define DR_CONTROL_SIZE 4 +#define DR_CONTROL_SIZE 4 /* Watchpoint/breakpoint read/write fields in DR7. */ -#define DR_RW_EXECUTE (0x0) /* Break on instruction execution. */ -#define DR_RW_WRITE (0x1) /* Break on data writes. */ -#define DR_RW_READ (0x3) /* Break on data reads or writes. */ +#define DR_RW_EXECUTE (0x0) /* Break on instruction execution. */ +#define DR_RW_WRITE (0x1) /* Break on data writes. */ +#define DR_RW_READ (0x3) /* Break on data reads or writes. */ /* This is here for completeness. No platform supports this functionality yet (as of March 2001). Note that the DE flag in the CR4 register needs to be set to support this. */ #ifndef DR_RW_IORW -#define DR_RW_IORW (0x2) /* Break on I/O reads or writes. */ +#define DR_RW_IORW (0x2) /* Break on I/O reads or writes. */ #endif /* Watchpoint/breakpoint length fields in DR7. The 2-bit left shift is so we could OR this with the read/write field defined above. */ -#define DR_LEN_1 (0x0 << 2) /* 1-byte region watch or breakpoint. */ -#define DR_LEN_2 (0x1 << 2) /* 2-byte region watch. */ -#define DR_LEN_4 (0x3 << 2) /* 4-byte region watch. */ -#define DR_LEN_8 (0x2 << 2) /* 8-byte region watch (AMD64). */ +#define DR_LEN_1 (0x0 << 2) /* 1-byte region watch or breakpoint. */ +#define DR_LEN_2 (0x1 << 2) /* 2-byte region watch. */ +#define DR_LEN_4 (0x3 << 2) /* 4-byte region watch. */ +#define DR_LEN_8 (0x2 << 2) /* 8-byte region watch (AMD64). */ /* Local and Global Enable flags in DR7. @@ -138,29 +138,29 @@ x86_get_debug_register_length () Currently, all watchpoint are locally enabled. If you need to enable them globally, read the comment which pertains to this in x86_insert_aligned_watchpoint below. */ -#define DR_LOCAL_ENABLE_SHIFT 0 /* Extra shift to the local enable bit. */ -#define DR_GLOBAL_ENABLE_SHIFT 1 /* Extra shift to the global enable bit. */ -#define DR_ENABLE_SIZE 2 /* Two enable bits per debug register. */ +#define DR_LOCAL_ENABLE_SHIFT 0 /* Extra shift to the local enable bit. */ +#define DR_GLOBAL_ENABLE_SHIFT 1 /* Extra shift to the global enable bit. */ +#define DR_ENABLE_SIZE 2 /* Two enable bits per debug register. */ /* Local and global exact breakpoint enable flags (a.k.a. slowdown flags). These are only required on i386, to allow detection of the exact instruction which caused a watchpoint to break; i486 and later processors do that automatically. We set these flags for backwards compatibility. */ -#define DR_LOCAL_SLOWDOWN (0x100) -#define DR_GLOBAL_SLOWDOWN (0x200) +#define DR_LOCAL_SLOWDOWN (0x100) +#define DR_GLOBAL_SLOWDOWN (0x200) /* Fields reserved by Intel. This includes the GD (General Detect Enable) flag, which causes a debug exception to be generated when a MOV instruction accesses one of the debug registers. FIXME: My Intel manual says we should use 0xF800, not 0xFC00. */ -#define DR_CONTROL_RESERVED (0xFC00) +#define DR_CONTROL_RESERVED (0xFC00) /* Auxiliary helper macros. */ /* A value that masks all fields in DR7 that are reserved by Intel. */ -#define X86_DR_CONTROL_MASK (~DR_CONTROL_RESERVED) +#define X86_DR_CONTROL_MASK (~DR_CONTROL_RESERVED) /* The I'th debug register is vacant if its Local and Global Enable bits are reset in the Debug Control register. */ @@ -168,79 +168,91 @@ x86_get_debug_register_length () (((state)->dr_control_mirror & (3 << (DR_ENABLE_SIZE * (i)))) == 0) /* Locally enable the break/watchpoint in the I'th debug register. */ -#define X86_DR_LOCAL_ENABLE(state, i) \ - do { \ - (state)->dr_control_mirror |= \ - (1 << (DR_LOCAL_ENABLE_SHIFT + DR_ENABLE_SIZE * (i))); \ - } while (0) +#define X86_DR_LOCAL_ENABLE(state, i) \ + do \ + { \ + (state)->dr_control_mirror \ + |= (1 << (DR_LOCAL_ENABLE_SHIFT + DR_ENABLE_SIZE * (i))); \ + } \ + while (0) /* Globally enable the break/watchpoint in the I'th debug register. */ -#define X86_DR_GLOBAL_ENABLE(state, i) \ - do { \ - (state)->dr_control_mirror |= \ - (1 << (DR_GLOBAL_ENABLE_SHIFT + DR_ENABLE_SIZE * (i))); \ - } while (0) +#define X86_DR_GLOBAL_ENABLE(state, i) \ + do \ + { \ + (state)->dr_control_mirror \ + |= (1 << (DR_GLOBAL_ENABLE_SHIFT + DR_ENABLE_SIZE * (i))); \ + } \ + while (0) /* Disable the break/watchpoint in the I'th debug register. */ -#define X86_DR_DISABLE(state, i) \ - do { \ - (state)->dr_control_mirror &= \ - ~(3 << (DR_ENABLE_SIZE * (i))); \ - } while (0) +#define X86_DR_DISABLE(state, i) \ + do \ + { \ + (state)->dr_control_mirror &= ~(3 << (DR_ENABLE_SIZE * (i))); \ + } \ + while (0) /* Set in DR7 the RW and LEN fields for the I'th debug register. */ -#define X86_DR_SET_RW_LEN(state, i, rwlen) \ - do { \ - (state)->dr_control_mirror &= \ - ~(0x0f << (DR_CONTROL_SHIFT + DR_CONTROL_SIZE * (i))); \ - (state)->dr_control_mirror |= \ - ((rwlen) << (DR_CONTROL_SHIFT + DR_CONTROL_SIZE * (i))); \ - } while (0) +#define X86_DR_SET_RW_LEN(state, i, rwlen) \ + do \ + { \ + (state)->dr_control_mirror \ + &= ~(0x0f << (DR_CONTROL_SHIFT + DR_CONTROL_SIZE * (i))); \ + (state)->dr_control_mirror \ + |= ((rwlen) << (DR_CONTROL_SHIFT + DR_CONTROL_SIZE * (i))); \ + } \ + while (0) /* Get from DR7 the RW and LEN fields for the I'th debug register. */ #define X86_DR_GET_RW_LEN(dr7, i) \ - (((dr7) \ - >> (DR_CONTROL_SHIFT + DR_CONTROL_SIZE * (i))) & 0x0f) + (((dr7) >> (DR_CONTROL_SHIFT + DR_CONTROL_SIZE * (i))) & 0x0f) /* Did the watchpoint whose address is in the I'th register break? */ #define X86_DR_WATCH_HIT(dr6, i) ((dr6) & (1 << (i))) /* Types of operations supported by x86_handle_nonaligned_watchpoint. */ -enum x86_wp_op_t { WP_INSERT, WP_REMOVE, WP_COUNT }; +enum x86_wp_op_t +{ + WP_INSERT, + WP_REMOVE, + WP_COUNT +}; /* Print the values of the mirrored debug registers. */ static void -x86_show_dr (struct x86_debug_reg_state *state, - const char *func, CORE_ADDR addr, - int len, enum target_hw_bp_type type) +x86_show_dr (struct x86_debug_reg_state *state, const char *func, + CORE_ADDR addr, int len, enum target_hw_bp_type type) { int i; debug_printf ("%s", func); if (addr || len) - debug_printf (" (addr=%s, len=%d, type=%s)", - phex (addr, 8), len, - type == hw_write ? "data-write" - : (type == hw_read ? "data-read" - : (type == hw_access ? "data-read/write" - : (type == hw_execute ? "instruction-execute" - /* FIXME: if/when I/O read/write + debug_printf (" (addr=%s, len=%d, type=%s)", phex (addr, 8), len, + type == hw_write + ? "data-write" + : (type == hw_read + ? "data-read" + : (type == hw_access + ? "data-read/write" + : (type == hw_execute + ? "instruction-execute" + /* FIXME: if/when I/O read/write watchpoints are supported, add them here. */ - : "??unknown??")))); + : "??unknown??")))); debug_printf (":\n"); debug_printf ("\tCONTROL (DR7): 0x%s\n", phex (state->dr_control_mirror, 8)); debug_printf ("\tSTATUS (DR6): 0x%s\n", phex (state->dr_status_mirror, 8)); ALL_DEBUG_ADDRESS_REGISTERS (i) - { - debug_printf ("\tDR%d: addr=0x%s, ref.count=%d\n", - i, phex (state->dr_mirror[i], - x86_get_debug_register_length ()), - state->dr_ref_count[i]); - } + { + debug_printf ("\tDR%d: addr=0x%s, ref.count=%d\n", i, + phex (state->dr_mirror[i], x86_get_debug_register_length ()), + state->dr_ref_count[i]); + } } /* Return the value of a 4-bit field for DR7 suitable for watching a @@ -254,45 +266,46 @@ x86_length_and_rw_bits (int len, enum target_hw_bp_type type) switch (type) { - case hw_execute: - rw = DR_RW_EXECUTE; - break; - case hw_write: - rw = DR_RW_WRITE; - break; - case hw_read: - internal_error (_("The i386 doesn't support " - "data-read watchpoints.\n")); - case hw_access: - rw = DR_RW_READ; - break; + case hw_execute: + rw = DR_RW_EXECUTE; + break; + case hw_write: + rw = DR_RW_WRITE; + break; + case hw_read: + internal_error (_ ("The i386 doesn't support " + "data-read watchpoints.\n")); + case hw_access: + rw = DR_RW_READ; + break; #if 0 /* Not yet supported. */ case hw_io_access: rw = DR_RW_IORW; break; #endif - default: - internal_error (_("\ + default: + internal_error (_ ("\ Invalid hardware breakpoint type %d in x86_length_and_rw_bits.\n"), - (int) type); + (int) type); } switch (len) { - case 1: - return (DR_LEN_1 | rw); - case 2: - return (DR_LEN_2 | rw); - case 4: - return (DR_LEN_4 | rw); - case 8: - if (TARGET_HAS_DR_LEN_8) - return (DR_LEN_8 | rw); - /* FALL THROUGH */ - default: - internal_error (_("\ -Invalid hardware breakpoint length %d in x86_length_and_rw_bits.\n"), len); + case 1: + return (DR_LEN_1 | rw); + case 2: + return (DR_LEN_2 | rw); + case 4: + return (DR_LEN_4 | rw); + case 8: + if (TARGET_HAS_DR_LEN_8) + return (DR_LEN_8 | rw); + /* FALL THROUGH */ + default: + internal_error (_ ("\ +Invalid hardware breakpoint length %d in x86_length_and_rw_bits.\n"), + len); } } @@ -315,22 +328,21 @@ x86_insert_aligned_watchpoint (struct x86_debug_reg_state *state, and the same RW and LEN definitions. If we find one, we can reuse it for this watchpoint as well (and save a register). */ ALL_DEBUG_ADDRESS_REGISTERS (i) - { - if (!X86_DR_VACANT (state, i) - && state->dr_mirror[i] == addr - && X86_DR_GET_RW_LEN (state->dr_control_mirror, i) == len_rw_bits) - { - state->dr_ref_count[i]++; - return 0; - } - } + { + if (!X86_DR_VACANT (state, i) && state->dr_mirror[i] == addr + && X86_DR_GET_RW_LEN (state->dr_control_mirror, i) == len_rw_bits) + { + state->dr_ref_count[i]++; + return 0; + } + } /* Next, look for a vacant debug register. */ ALL_DEBUG_ADDRESS_REGISTERS (i) - { - if (X86_DR_VACANT (state, i)) - break; - } + { + if (X86_DR_VACANT (state, i)) + break; + } /* No more debug registers! */ if (i >= DR_NADDR) @@ -370,28 +382,27 @@ x86_remove_aligned_watchpoint (struct x86_debug_reg_state *state, int all_vacant = 1; ALL_DEBUG_ADDRESS_REGISTERS (i) - { - if (!X86_DR_VACANT (state, i) - && state->dr_mirror[i] == addr - && X86_DR_GET_RW_LEN (state->dr_control_mirror, i) == len_rw_bits) - { - if (--state->dr_ref_count[i] == 0) /* No longer in use? */ - { - /* Reset our mirror. */ - state->dr_mirror[i] = 0; - X86_DR_DISABLE (state, i); - /* Even though not strictly necessary, clear out all + { + if (!X86_DR_VACANT (state, i) && state->dr_mirror[i] == addr + && X86_DR_GET_RW_LEN (state->dr_control_mirror, i) == len_rw_bits) + { + if (--state->dr_ref_count[i] == 0) /* No longer in use? */ + { + /* Reset our mirror. */ + state->dr_mirror[i] = 0; + X86_DR_DISABLE (state, i); + /* Even though not strictly necessary, clear out all bits in DR_CONTROL related to this debug register. Debug output is clearer when we don't have stale bits in place. This also allows the assertion below. */ - X86_DR_SET_RW_LEN (state, i, 0); - } - retval = 0; - } + X86_DR_SET_RW_LEN (state, i, 0); + } + retval = 0; + } - if (!X86_DR_VACANT (state, i)) - all_vacant = 0; - } + if (!X86_DR_VACANT (state, i)) + all_vacant = 0; + } if (all_vacant) { @@ -422,16 +433,15 @@ x86_handle_nonaligned_watchpoint (struct x86_debug_reg_state *state, int retval = 0; int max_wp_len = TARGET_HAS_DR_LEN_8 ? 8 : 4; - static const int size_try_array[8][8] = - { - {1, 1, 1, 1, 1, 1, 1, 1}, /* Trying size one. */ - {2, 1, 2, 1, 2, 1, 2, 1}, /* Trying size two. */ - {2, 1, 2, 1, 2, 1, 2, 1}, /* Trying size three. */ - {4, 1, 2, 1, 4, 1, 2, 1}, /* Trying size four. */ - {4, 1, 2, 1, 4, 1, 2, 1}, /* Trying size five. */ - {4, 1, 2, 1, 4, 1, 2, 1}, /* Trying size six. */ - {4, 1, 2, 1, 4, 1, 2, 1}, /* Trying size seven. */ - {8, 1, 2, 1, 4, 1, 2, 1}, /* Trying size eight. */ + static const int size_try_array[8][8] = { + { 1, 1, 1, 1, 1, 1, 1, 1 }, /* Trying size one. */ + { 2, 1, 2, 1, 2, 1, 2, 1 }, /* Trying size two. */ + { 2, 1, 2, 1, 2, 1, 2, 1 }, /* Trying size three. */ + { 4, 1, 2, 1, 4, 1, 2, 1 }, /* Trying size four. */ + { 4, 1, 2, 1, 4, 1, 2, 1 }, /* Trying size five. */ + { 4, 1, 2, 1, 4, 1, 2, 1 }, /* Trying size six. */ + { 4, 1, 2, 1, 4, 1, 2, 1 }, /* Trying size seven. */ + { 8, 1, 2, 1, 4, 1, 2, 1 }, /* Trying size eight. */ }; while (len > 0) @@ -461,7 +471,7 @@ x86_handle_nonaligned_watchpoint (struct x86_debug_reg_state *state, else if (what == WP_REMOVE) retval = x86_remove_aligned_watchpoint (state, addr, len_rw); else - internal_error (_("\ + internal_error (_ ("\ Invalid value %d of operation in x86_handle_nonaligned_watchpoint.\n"), (int) what); if (retval) @@ -485,12 +495,12 @@ x86_update_inferior_debug_regs (struct x86_debug_reg_state *state, int i; ALL_DEBUG_ADDRESS_REGISTERS (i) - { - if (X86_DR_VACANT (new_state, i) != X86_DR_VACANT (state, i)) - x86_dr_low_set_addr (new_state, i); - else - gdb_assert (new_state->dr_mirror[i] == state->dr_mirror[i]); - } + { + if (X86_DR_VACANT (new_state, i) != X86_DR_VACANT (state, i)) + x86_dr_low_set_addr (new_state, i); + else + gdb_assert (new_state->dr_mirror[i] == state->dr_mirror[i]); + } if (new_state->dr_control_mirror != state->dr_control_mirror) x86_dr_low_set_control (new_state); @@ -504,8 +514,7 @@ x86_update_inferior_debug_regs (struct x86_debug_reg_state *state, int x86_dr_insert_watchpoint (struct x86_debug_reg_state *state, - enum target_hw_bp_type type, - CORE_ADDR addr, int len) + enum target_hw_bp_type type, CORE_ADDR addr, int len) { int retval; /* Work on a local copy of the debug registers, and on success, @@ -519,16 +528,14 @@ x86_dr_insert_watchpoint (struct x86_debug_reg_state *state, && !(TARGET_HAS_DR_LEN_8 && len == 8)) || addr % len != 0) { - retval = x86_handle_nonaligned_watchpoint (&local_state, - WP_INSERT, - addr, len, type); + retval = x86_handle_nonaligned_watchpoint (&local_state, WP_INSERT, addr, + len, type); } else { unsigned len_rw = x86_length_and_rw_bits (len, type); - retval = x86_insert_aligned_watchpoint (&local_state, - addr, len_rw); + retval = x86_insert_aligned_watchpoint (&local_state, addr, len_rw); } if (retval == 0) @@ -546,8 +553,7 @@ x86_dr_insert_watchpoint (struct x86_debug_reg_state *state, int x86_dr_remove_watchpoint (struct x86_debug_reg_state *state, - enum target_hw_bp_type type, - CORE_ADDR addr, int len) + enum target_hw_bp_type type, CORE_ADDR addr, int len) { int retval; /* Work on a local copy of the debug registers, and on success, @@ -558,16 +564,14 @@ x86_dr_remove_watchpoint (struct x86_debug_reg_state *state, && !(TARGET_HAS_DR_LEN_8 && len == 8)) || addr % len != 0) { - retval = x86_handle_nonaligned_watchpoint (&local_state, - WP_REMOVE, - addr, len, type); + retval = x86_handle_nonaligned_watchpoint (&local_state, WP_REMOVE, addr, + len, type); } else { unsigned len_rw = x86_length_and_rw_bits (len, type); - retval = x86_remove_aligned_watchpoint (&local_state, - addr, len_rw); + retval = x86_remove_aligned_watchpoint (&local_state, addr, len_rw); } if (retval == 0) @@ -590,8 +594,8 @@ x86_dr_region_ok_for_watchpoint (struct x86_debug_reg_state *state, /* Compute how many aligned watchpoints we would need to cover this region. */ - nregs = x86_handle_nonaligned_watchpoint (state, WP_COUNT, - addr, len, hw_write); + nregs + = x86_handle_nonaligned_watchpoint (state, WP_COUNT, addr, len, hw_write); return nregs <= DR_NADDR ? 1 : 0; } @@ -644,29 +648,29 @@ x86_dr_stopped_data_address (struct x86_debug_reg_state *state, status = x86_dr_low_get_status (); ALL_DEBUG_ADDRESS_REGISTERS (i) - { - if (!X86_DR_WATCH_HIT (status, i)) - continue; + { + if (!X86_DR_WATCH_HIT (status, i)) + continue; - if (!control_p) - { - control = x86_dr_low_get_control (); - control_p = 1; - } + if (!control_p) + { + control = x86_dr_low_get_control (); + control_p = 1; + } - /* This second condition makes sure DRi is set up for a data + /* This second condition makes sure DRi is set up for a data watchpoint, not a hardware breakpoint. The reason is that GDB doesn't call the target_stopped_data_address method except for data watchpoints. In other words, I'm being paranoiac. */ - if (X86_DR_GET_RW_LEN (control, i) != 0) - { - addr = x86_dr_low_get_addr (i); - rc = 1; - if (show_debug_regs) - x86_show_dr (state, "watchpoint_hit", addr, -1, hw_write); - } - } + if (X86_DR_GET_RW_LEN (control, i) != 0) + { + addr = x86_dr_low_get_addr (i); + rc = 1; + if (show_debug_regs) + x86_show_dr (state, "watchpoint_hit", addr, -1, hw_write); + } + } if (show_debug_regs && addr == 0) x86_show_dr (state, "stopped_data_addr", 0, 0, hw_write); @@ -709,24 +713,24 @@ x86_dr_stopped_by_hw_breakpoint (struct x86_debug_reg_state *state) status = x86_dr_low_get_status (); ALL_DEBUG_ADDRESS_REGISTERS (i) - { - if (!X86_DR_WATCH_HIT (status, i)) - continue; - - if (!control_p) - { - control = x86_dr_low_get_control (); - control_p = 1; - } - - if (X86_DR_GET_RW_LEN (control, i) == 0) - { - addr = x86_dr_low_get_addr (i); - rc = 1; - if (show_debug_regs) - x86_show_dr (state, "watchpoint_hit", addr, -1, hw_execute); - } - } + { + if (!X86_DR_WATCH_HIT (status, i)) + continue; + + if (!control_p) + { + control = x86_dr_low_get_control (); + control_p = 1; + } + + if (X86_DR_GET_RW_LEN (control, i) == 0) + { + addr = x86_dr_low_get_addr (i); + rc = 1; + if (show_debug_regs) + x86_show_dr (state, "watchpoint_hit", addr, -1, hw_execute); + } + } return rc; } diff --git a/gdb/nat/x86-dregs.h b/gdb/nat/x86-dregs.h index 093a234..a7bcf08 100644 --- a/gdb/nat/x86-dregs.h +++ b/gdb/nat/x86-dregs.h @@ -32,46 +32,45 @@ counts, and allow to watch regions up to 16 bytes long (32 bytes on 64 bit hosts). */ - #include "gdbsupport/break-common.h" /* target_hw_bp_type */ /* Low-level function vector. */ struct x86_dr_low_type - { - /* Set the debug control (DR7) register to a given value for +{ + /* Set the debug control (DR7) register to a given value for all LWPs. May be NULL if the debug control register cannot be set. */ - void (*set_control) (unsigned long); + void (*set_control) (unsigned long); - /* Put an address into one debug register for all LWPs. May + /* Put an address into one debug register for all LWPs. May be NULL if debug registers cannot be set*/ - void (*set_addr) (int, CORE_ADDR); + void (*set_addr) (int, CORE_ADDR); - /* Return the address in a given debug register of the current + /* Return the address in a given debug register of the current LWP. */ - CORE_ADDR (*get_addr) (int); + CORE_ADDR (*get_addr) (int); - /* Return the value of the debug status (DR6) register for + /* Return the value of the debug status (DR6) register for current LWP. */ - unsigned long (*get_status) (void); + unsigned long (*get_status) (void); - /* Return the value of the debug control (DR7) register for + /* Return the value of the debug control (DR7) register for current LWP. */ - unsigned long (*get_control) (void); + unsigned long (*get_control) (void); - /* Number of bytes used for debug registers (4 or 8). */ - int debug_register_length; - }; + /* Number of bytes used for debug registers (4 or 8). */ + int debug_register_length; +}; extern struct x86_dr_low_type x86_dr_low; /* Debug registers' indices. */ #define DR_FIRSTADDR 0 -#define DR_LASTADDR 3 -#define DR_NADDR 4 /* The number of debug address registers. */ -#define DR_STATUS 6 /* Index of debug status register (DR6). */ -#define DR_CONTROL 7 /* Index of debug control register (DR7). */ +#define DR_LASTADDR 3 +#define DR_NADDR 4 /* The number of debug address registers. */ +#define DR_STATUS 6 /* Index of debug status register (DR6). */ +#define DR_CONTROL 7 /* Index of debug control register (DR7). */ /* Global state needed to track h/w watchpoints. */ @@ -103,16 +102,14 @@ extern struct x86_debug_reg_state *x86_debug_reg_state (pid_t pid); of the type TYPE. Return 0 on success, -1 on failure. */ extern int x86_dr_insert_watchpoint (struct x86_debug_reg_state *state, enum target_hw_bp_type type, - CORE_ADDR addr, - int len); + CORE_ADDR addr, int len); /* Remove a watchpoint that watched the memory region which starts at address ADDR, whose length is LEN bytes, and for accesses of the type TYPE. Return 0 on success, -1 on failure. */ extern int x86_dr_remove_watchpoint (struct x86_debug_reg_state *state, enum target_hw_bp_type type, - CORE_ADDR addr, - int len); + CORE_ADDR addr, int len); /* Return non-zero if we can watch a memory region that starts at address ADDR and whose length is LEN bytes. */ diff --git a/gdb/nat/x86-gcc-cpuid.h b/gdb/nat/x86-gcc-cpuid.h index 2f7390a..3f3650b 100644 --- a/gdb/nat/x86-gcc-cpuid.h +++ b/gdb/nat/x86-gcc-cpuid.h @@ -30,156 +30,153 @@ */ /* %ecx */ -#define bit_SSE3 (1 << 0) -#define bit_PCLMUL (1 << 1) -#define bit_LZCNT (1 << 5) -#define bit_SSSE3 (1 << 9) -#define bit_FMA (1 << 12) -#define bit_CMPXCHG16B (1 << 13) -#define bit_SSE4_1 (1 << 19) -#define bit_SSE4_2 (1 << 20) -#define bit_MOVBE (1 << 22) -#define bit_POPCNT (1 << 23) -#define bit_AES (1 << 25) -#define bit_XSAVE (1 << 26) -#define bit_OSXSAVE (1 << 27) -#define bit_AVX (1 << 28) -#define bit_F16C (1 << 29) -#define bit_RDRND (1 << 30) +#define bit_SSE3 (1 << 0) +#define bit_PCLMUL (1 << 1) +#define bit_LZCNT (1 << 5) +#define bit_SSSE3 (1 << 9) +#define bit_FMA (1 << 12) +#define bit_CMPXCHG16B (1 << 13) +#define bit_SSE4_1 (1 << 19) +#define bit_SSE4_2 (1 << 20) +#define bit_MOVBE (1 << 22) +#define bit_POPCNT (1 << 23) +#define bit_AES (1 << 25) +#define bit_XSAVE (1 << 26) +#define bit_OSXSAVE (1 << 27) +#define bit_AVX (1 << 28) +#define bit_F16C (1 << 29) +#define bit_RDRND (1 << 30) /* %edx */ -#define bit_CMPXCHG8B (1 << 8) -#define bit_CMOV (1 << 15) -#define bit_MMX (1 << 23) -#define bit_FXSAVE (1 << 24) -#define bit_SSE (1 << 25) -#define bit_SSE2 (1 << 26) +#define bit_CMPXCHG8B (1 << 8) +#define bit_CMOV (1 << 15) +#define bit_MMX (1 << 23) +#define bit_FXSAVE (1 << 24) +#define bit_SSE (1 << 25) +#define bit_SSE2 (1 << 26) /* Extended Features */ /* %ecx */ -#define bit_LAHF_LM (1 << 0) -#define bit_ABM (1 << 5) -#define bit_SSE4a (1 << 6) -#define bit_PRFCHW (1 << 8) -#define bit_XOP (1 << 11) -#define bit_LWP (1 << 15) -#define bit_FMA4 (1 << 16) -#define bit_TBM (1 << 21) -#define bit_MWAITX (1 << 29) +#define bit_LAHF_LM (1 << 0) +#define bit_ABM (1 << 5) +#define bit_SSE4a (1 << 6) +#define bit_PRFCHW (1 << 8) +#define bit_XOP (1 << 11) +#define bit_LWP (1 << 15) +#define bit_FMA4 (1 << 16) +#define bit_TBM (1 << 21) +#define bit_MWAITX (1 << 29) /* %edx */ #define bit_AVX5124VNNIW (1 << 2) #define bit_AVX5124FMAPS (1 << 3) -#define bit_MMXEXT (1 << 22) -#define bit_LM (1 << 29) -#define bit_3DNOWP (1 << 30) -#define bit_3DNOW (1 << 31) +#define bit_MMXEXT (1 << 22) +#define bit_LM (1 << 29) +#define bit_3DNOWP (1 << 30) +#define bit_3DNOW (1 << 31) /* %ebx. */ -#define bit_CLZERO (1 << 0) +#define bit_CLZERO (1 << 0) /* Extended Features (%eax == 7) */ /* %ebx */ -#define bit_FSGSBASE (1 << 0) -#define bit_BMI (1 << 3) -#define bit_HLE (1 << 4) -#define bit_AVX2 (1 << 5) -#define bit_BMI2 (1 << 8) -#define bit_RTM (1 << 11) -#define bit_MPX (1 << 14) -#define bit_AVX512F (1 << 16) -#define bit_AVX512DQ (1 << 17) -#define bit_RDSEED (1 << 18) -#define bit_ADX (1 << 19) -#define bit_AVX512IFMA (1 << 21) -#define bit_CLFLUSHOPT (1 << 23) -#define bit_CLWB (1 << 24) -#define bit_AVX512PF (1 << 26) -#define bit_AVX512ER (1 << 27) -#define bit_AVX512CD (1 << 28) -#define bit_SHA (1 << 29) -#define bit_AVX512BW (1 << 30) -#define bit_AVX512VL (1 << 31) +#define bit_FSGSBASE (1 << 0) +#define bit_BMI (1 << 3) +#define bit_HLE (1 << 4) +#define bit_AVX2 (1 << 5) +#define bit_BMI2 (1 << 8) +#define bit_RTM (1 << 11) +#define bit_MPX (1 << 14) +#define bit_AVX512F (1 << 16) +#define bit_AVX512DQ (1 << 17) +#define bit_RDSEED (1 << 18) +#define bit_ADX (1 << 19) +#define bit_AVX512IFMA (1 << 21) +#define bit_CLFLUSHOPT (1 << 23) +#define bit_CLWB (1 << 24) +#define bit_AVX512PF (1 << 26) +#define bit_AVX512ER (1 << 27) +#define bit_AVX512CD (1 << 28) +#define bit_SHA (1 << 29) +#define bit_AVX512BW (1 << 30) +#define bit_AVX512VL (1 << 31) /* %ecx */ -#define bit_PREFETCHWT1 (1 << 0) -#define bit_AVX512VBMI (1 << 1) -#define bit_PKU (1 << 3) -#define bit_OSPKE (1 << 4) +#define bit_PREFETCHWT1 (1 << 0) +#define bit_AVX512VBMI (1 << 1) +#define bit_PKU (1 << 3) +#define bit_OSPKE (1 << 4) /* XFEATURE_ENABLED_MASK register bits (%eax == 13, %ecx == 0) */ -#define bit_BNDREGS (1 << 3) -#define bit_BNDCSR (1 << 4) +#define bit_BNDREGS (1 << 3) +#define bit_BNDCSR (1 << 4) /* Extended State Enumeration Sub-leaf (%eax == 13, %ecx == 1) */ -#define bit_XSAVEOPT (1 << 0) -#define bit_XSAVEC (1 << 1) -#define bit_XSAVES (1 << 3) +#define bit_XSAVEOPT (1 << 0) +#define bit_XSAVEC (1 << 1) +#define bit_XSAVES (1 << 3) /* Signatures for different CPU implementations as returned in uses of cpuid with level 0. */ -#define signature_AMD_ebx 0x68747541 -#define signature_AMD_ecx 0x444d4163 -#define signature_AMD_edx 0x69746e65 +#define signature_AMD_ebx 0x68747541 +#define signature_AMD_ecx 0x444d4163 +#define signature_AMD_edx 0x69746e65 -#define signature_CENTAUR_ebx 0x746e6543 -#define signature_CENTAUR_ecx 0x736c7561 -#define signature_CENTAUR_edx 0x48727561 +#define signature_CENTAUR_ebx 0x746e6543 +#define signature_CENTAUR_ecx 0x736c7561 +#define signature_CENTAUR_edx 0x48727561 -#define signature_CYRIX_ebx 0x69727943 -#define signature_CYRIX_ecx 0x64616574 -#define signature_CYRIX_edx 0x736e4978 +#define signature_CYRIX_ebx 0x69727943 +#define signature_CYRIX_ecx 0x64616574 +#define signature_CYRIX_edx 0x736e4978 -#define signature_INTEL_ebx 0x756e6547 -#define signature_INTEL_ecx 0x6c65746e -#define signature_INTEL_edx 0x49656e69 +#define signature_INTEL_ebx 0x756e6547 +#define signature_INTEL_ecx 0x6c65746e +#define signature_INTEL_edx 0x49656e69 -#define signature_TM1_ebx 0x6e617254 -#define signature_TM1_ecx 0x55504361 -#define signature_TM1_edx 0x74656d73 +#define signature_TM1_ebx 0x6e617254 +#define signature_TM1_ecx 0x55504361 +#define signature_TM1_edx 0x74656d73 -#define signature_TM2_ebx 0x756e6547 -#define signature_TM2_ecx 0x3638784d -#define signature_TM2_edx 0x54656e69 +#define signature_TM2_ebx 0x756e6547 +#define signature_TM2_ecx 0x3638784d +#define signature_TM2_edx 0x54656e69 -#define signature_NSC_ebx 0x646f6547 -#define signature_NSC_ecx 0x43534e20 -#define signature_NSC_edx 0x79622065 +#define signature_NSC_ebx 0x646f6547 +#define signature_NSC_ecx 0x43534e20 +#define signature_NSC_edx 0x79622065 -#define signature_NEXGEN_ebx 0x4778654e -#define signature_NEXGEN_ecx 0x6e657669 -#define signature_NEXGEN_edx 0x72446e65 +#define signature_NEXGEN_ebx 0x4778654e +#define signature_NEXGEN_ecx 0x6e657669 +#define signature_NEXGEN_edx 0x72446e65 -#define signature_RISE_ebx 0x65736952 -#define signature_RISE_ecx 0x65736952 -#define signature_RISE_edx 0x65736952 +#define signature_RISE_ebx 0x65736952 +#define signature_RISE_ecx 0x65736952 +#define signature_RISE_edx 0x65736952 -#define signature_SIS_ebx 0x20536953 -#define signature_SIS_ecx 0x20536953 -#define signature_SIS_edx 0x20536953 +#define signature_SIS_ebx 0x20536953 +#define signature_SIS_ecx 0x20536953 +#define signature_SIS_edx 0x20536953 -#define signature_UMC_ebx 0x20434d55 -#define signature_UMC_ecx 0x20434d55 -#define signature_UMC_edx 0x20434d55 +#define signature_UMC_ebx 0x20434d55 +#define signature_UMC_ecx 0x20434d55 +#define signature_UMC_edx 0x20434d55 -#define signature_VIA_ebx 0x20414956 -#define signature_VIA_ecx 0x20414956 -#define signature_VIA_edx 0x20414956 +#define signature_VIA_ebx 0x20414956 +#define signature_VIA_ecx 0x20414956 +#define signature_VIA_edx 0x20414956 -#define signature_VORTEX_ebx 0x74726f56 -#define signature_VORTEX_ecx 0x436f5320 -#define signature_VORTEX_edx 0x36387865 +#define signature_VORTEX_ebx 0x74726f56 +#define signature_VORTEX_ecx 0x436f5320 +#define signature_VORTEX_edx 0x36387865 -#define __cpuid(level, a, b, c, d) \ - __asm__ ("cpuid\n\t" \ - : "=a" (a), "=b" (b), "=c" (c), "=d" (d) \ - : "0" (level)) - -#define __cpuid_count(level, count, a, b, c, d) \ - __asm__ ("cpuid\n\t" \ - : "=a" (a), "=b" (b), "=c" (c), "=d" (d) \ - : "0" (level), "2" (count)) +#define __cpuid(level, a, b, c, d) \ + __asm__ ("cpuid\n\t" : "=a"(a), "=b"(b), "=c"(c), "=d"(d) : "0"(level)) +#define __cpuid_count(level, count, a, b, c, d) \ + __asm__ ("cpuid\n\t" \ + : "=a"(a), "=b"(b), "=c"(c), "=d"(d) \ + : "0"(level), "2"(count)) /* Return highest supported input value for cpuid instruction. ext can be either 0x0 or 0x8000000 to return highest supported value for @@ -206,10 +203,10 @@ __get_cpuid_max (unsigned int __ext, unsigned int *__sig) "pushf{l|d}\n\t" "pop{l}\t%0\n\t" "popf{l|d}\n\t" - : "=&r" (__eax), "=&r" (__ebx) - : "i" (0x00200000)); + : "=&r"(__eax), "=&r"(__ebx) + : "i"(0x00200000)); #else -/* Host GCCs older than 3.0 weren't supporting Intel asm syntax + /* Host GCCs older than 3.0 weren't supporting Intel asm syntax nor alternatives in i386 code. */ __asm__ ("pushfl\n\t" "pushfl\n\t" @@ -221,8 +218,8 @@ __get_cpuid_max (unsigned int __ext, unsigned int *__sig) "pushfl\n\t" "popl\t%0\n\t" "popfl\n\t" - : "=&r" (__eax), "=&r" (__ebx) - : "i" (0x00200000)); + : "=&r"(__eax), "=&r"(__ebx) + : "i"(0x00200000)); #endif if (!((__eax ^ __ebx) & 0x00200000)) @@ -244,8 +241,7 @@ __get_cpuid_max (unsigned int __ext, unsigned int *__sig) unsupported cpuid leaf. All pointers are required to be non-null. */ static __inline int -__get_cpuid (unsigned int __leaf, - unsigned int *__eax, unsigned int *__ebx, +__get_cpuid (unsigned int __leaf, unsigned int *__eax, unsigned int *__ebx, unsigned int *__ecx, unsigned int *__edx) { unsigned int __ext = __leaf & 0x80000000; diff --git a/gdb/nat/x86-linux-dregs.c b/gdb/nat/x86-linux-dregs.c index a1d51ea..760acb3 100644 --- a/gdb/nat/x86-linux-dregs.c +++ b/gdb/nat/x86-linux-dregs.c @@ -49,7 +49,7 @@ x86_linux_dr_get (ptid_t ptid, int regnum) errno = 0; value = ptrace (PTRACE_PEEKUSER, tid, u_debugreg_offset (regnum), 0); if (errno != 0) - perror_with_name (_("Couldn't read debug register")); + perror_with_name (_ ("Couldn't read debug register")); return value; } @@ -67,7 +67,7 @@ x86_linux_dr_set (ptid_t ptid, int regnum, unsigned long value) errno = 0; ptrace (PTRACE_POKEUSER, tid, u_debugreg_offset (regnum), value); if (errno != 0) - perror_with_name (_("Couldn't write debug register")); + perror_with_name (_ ("Couldn't write debug register")); } /* Callback for iterate_over_lwps. Mark that our local mirror of @@ -147,8 +147,7 @@ x86_linux_update_debug_registers (struct lwp_info *lwp) if (lwp_debug_registers_changed (lwp)) { - struct x86_debug_reg_state *state - = x86_debug_reg_state (ptid.pid ()); + struct x86_debug_reg_state *state = x86_debug_reg_state (ptid.pid ()); int i; /* Prior to Linux kernel 2.6.33 commit @@ -160,15 +159,15 @@ x86_linux_update_debug_registers (struct lwp_info *lwp) x86_linux_dr_set (ptid, DR_CONTROL, 0); ALL_DEBUG_ADDRESS_REGISTERS (i) - if (state->dr_ref_count[i] > 0) - { - x86_linux_dr_set (ptid, i, state->dr_mirror[i]); + if (state->dr_ref_count[i] > 0) + { + x86_linux_dr_set (ptid, i, state->dr_mirror[i]); - /* If we're setting a watchpoint, any change the inferior + /* If we're setting a watchpoint, any change the inferior has made to its debug registers needs to be discarded to avoid x86_stopped_data_address getting confused. */ - clear_status = 1; - } + clear_status = 1; + } /* If DR_CONTROL is supposed to be zero then it's already set. */ if (state->dr_control_mirror != 0) @@ -177,7 +176,6 @@ x86_linux_update_debug_registers (struct lwp_info *lwp) lwp_set_debug_registers_changed (lwp, 0); } - if (clear_status - || lwp_stop_reason (lwp) == TARGET_STOPPED_BY_WATCHPOINT) + if (clear_status || lwp_stop_reason (lwp) == TARGET_STOPPED_BY_WATCHPOINT) x86_linux_dr_set (ptid, DR_STATUS, 0); } diff --git a/gdb/nat/x86-linux.h b/gdb/nat/x86-linux.h index edddbf4..f605426 100644 --- a/gdb/nat/x86-linux.h +++ b/gdb/nat/x86-linux.h @@ -26,8 +26,7 @@ changed since the values were last written to the thread. Nonzero indicates that a change has been made, zero indicates no change. */ -extern void lwp_set_debug_registers_changed (struct lwp_info *lwp, - int value); +extern void lwp_set_debug_registers_changed (struct lwp_info *lwp, int value); /* Return nonzero if our local mirror of LWP's debug registers has been changed since the values were last written to the thread, |