From patchwork Wed Aug 6 15:58:03 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gary Benson X-Patchwork-Id: 2331 Received: (qmail 3084 invoked by alias); 6 Aug 2014 16:49:35 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 3063 invoked by uid 89); 6 Aug 2014 16:49:35 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.4 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Wed, 06 Aug 2014 16:49:33 +0000 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s76FwCd2006616 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Wed, 6 Aug 2014 11:58:12 -0400 Received: from blade.nx (ovpn-116-90.ams2.redhat.com [10.36.116.90]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s76FwA9I026307 for ; Wed, 6 Aug 2014 11:58:11 -0400 Received: from blade.nx (localhost [127.0.0.1]) by blade.nx (Postfix) with ESMTP id 3E65F2640E3 for ; Wed, 6 Aug 2014 16:58:10 +0100 (BST) From: Gary Benson To: gdb-patches@sourceware.org Subject: [PATCH 1/6] Straightforward fatal to internal_error conversions Date: Wed, 6 Aug 2014 16:58:03 +0100 Message-Id: <1407340688-13721-2-git-send-email-gbenson@redhat.com> In-Reply-To: <1407340688-13721-1-git-send-email-gbenson@redhat.com> References: <1407340688-13721-1-git-send-email-gbenson@redhat.com> X-IsSubscribed: yes This commit replaces most of the calls to fatal that represent internal errors with calls to internal_error, either directly or via gdb_assert and gdb_assert_not_reached. gdb/gdbserver/ 2014-08-06 Gary Benson * inferiors.c (get_thread_process): Replace check with gdb_assert. * linux-low.c (linux_wait_for_event_filtered): Replace fatal with internal_error. (linux_resume_one_lwp): Likewise. * linux-x86-low.c (x86_siginfo_fixup): Replace checks with gdb_assert. * mem-break.c (raw_bkpt_type_to_target_hw_bp_type): Replace fatal with internal_error. * regcache.c (get_thread_regcache): Replace check with gdb_assert. (init_register_cache): Replace fatal with gdb_assert_not_reached. (find_register_by_name): Replace fatal with internal_error. (find_regno): Likewise. * tdesc.c (init_target_desc): Replace check with gdb_assert. * thread-db.c (thread_db_create_event): Likewise. (thread_db_load_search): Likewise. (try_thread_db_load_1): Likewise. * tracepoint.c (get_jump_space_head): Replace fatal with internal_error. (claim_trampoline_space): Likewise. (have_fast_tracepoint_trampoline_buffer): Likewise. (cmd_qtstart): Likewise. (stop_tracing): Likewise. (fast_tracepoint_collecting): Likewise. (target_malloc): Likewise. (download_tracepoint): Likewise. (download_trace_state_variables): Replace check with gdb_assert. (upload_fast_traceframes): Replace fatal with internal_error. --- gdb/gdbserver/ChangeLog | 30 ++++++++++++++ gdb/gdbserver/inferiors.c | 4 +- gdb/gdbserver/linux-low.c | 13 +++++- gdb/gdbserver/linux-x86-low.c | 6 +-- gdb/gdbserver/mem-break.c | 3 +- gdb/gdbserver/regcache.c | 13 +++--- gdb/gdbserver/tdesc.c | 3 +- gdb/gdbserver/thread-db.c | 9 +--- gdb/gdbserver/tracepoint.c | 88 +++++++++++++++++++++++++++++------------ 9 files changed, 117 insertions(+), 52 deletions(-) diff --git a/gdb/gdbserver/inferiors.c b/gdb/gdbserver/inferiors.c index 48d7700..d75c810 100644 --- a/gdb/gdbserver/inferiors.c +++ b/gdb/gdbserver/inferiors.c @@ -356,8 +356,6 @@ get_thread_process (struct thread_info *thread) struct process_info * current_process (void) { - if (current_inferior == NULL) - fatal ("Current inferior requested, but current_inferior is NULL\n"); - + gdb_assert (current_inferior != NULL); return get_thread_process (current_inferior); } diff --git a/gdb/gdbserver/linux-low.c b/gdb/gdbserver/linux-low.c index e65e276..4eaf2d2 100644 --- a/gdb/gdbserver/linux-low.c +++ b/gdb/gdbserver/linux-low.c @@ -2030,7 +2030,11 @@ linux_wait_for_event_filtered (ptid_t wait_ptid, ptid_t filter_ptid, if (requested_child->suspended && requested_child->status_pending_p) - fatal ("requesting an event out of a suspended child?"); + { + internal_error (__FILE__, __LINE__, + "requesting an event out of a" + " suspended child?"); + } if (requested_child->status_pending_p) { @@ -3436,8 +3440,11 @@ linux_resume_one_lwp (struct lwp_info *lwp, if (can_hardware_single_step ()) step = 1; else - fatal ("moving out of jump pad single-stepping" - " not implemented on this target"); + { + internal_error (__FILE__, __LINE__, + "moving out of jump pad single-stepping" + " not implemented on this target"); + } /* Postpone any pending signal. It was enqueued above. */ signal = 0; diff --git a/gdb/gdbserver/linux-x86-low.c b/gdb/gdbserver/linux-x86-low.c index 850ed7c..7f32ea3 100644 --- a/gdb/gdbserver/linux-x86-low.c +++ b/gdb/gdbserver/linux-x86-low.c @@ -1228,8 +1228,7 @@ x86_siginfo_fixup (siginfo_t *native, void *inf, int direction) /* Is the inferior 32-bit? If so, then fixup the siginfo object. */ if (!is_64bit_tdesc ()) { - if (sizeof (siginfo_t) != sizeof (compat_siginfo_t)) - fatal ("unexpected difference in siginfo"); + gdb_assert (sizeof (siginfo_t) == sizeof (compat_siginfo_t)); if (direction == 0) compat_siginfo_from_siginfo ((struct compat_siginfo *) inf, native); @@ -1241,8 +1240,7 @@ x86_siginfo_fixup (siginfo_t *native, void *inf, int direction) /* No fixup for native x32 GDB. */ else if (!is_elf64 && sizeof (void *) == 8) { - if (sizeof (siginfo_t) != sizeof (compat_x32_siginfo_t)) - fatal ("unexpected difference in siginfo"); + gdb_assert (sizeof (siginfo_t) == sizeof (compat_x32_siginfo_t)); if (direction == 0) compat_x32_siginfo_from_siginfo ((struct compat_x32_siginfo *) inf, diff --git a/gdb/gdbserver/mem-break.c b/gdb/gdbserver/mem-break.c index 2ce3ab2..07f9b20 100644 --- a/gdb/gdbserver/mem-break.c +++ b/gdb/gdbserver/mem-break.c @@ -189,7 +189,8 @@ raw_bkpt_type_to_target_hw_bp_type (enum raw_bkpt_type raw_type) case raw_bkpt_type_access_wp: return hw_access; default: - fatal ("bad raw breakpoing type %d", (int) raw_type); + internal_error (__FILE__, __LINE__, + "bad raw breakpoint type %d", (int) raw_type); } } diff --git a/gdb/gdbserver/regcache.c b/gdb/gdbserver/regcache.c index db99f8c..7868f1f 100644 --- a/gdb/gdbserver/regcache.c +++ b/gdb/gdbserver/regcache.c @@ -45,8 +45,7 @@ get_thread_regcache (struct thread_info *thread, int fetch) { struct process_info *proc = get_thread_process (thread); - if (proc->tdesc == NULL) - fatal ("no target description"); + gdb_assert (proc->tdesc != NULL); regcache = new_register_cache (proc->tdesc); set_inferior_regcache_data (thread, regcache); @@ -130,7 +129,7 @@ init_register_cache (struct regcache *regcache, regcache->register_status = xcalloc (1, tdesc->num_registers); gdb_assert (REG_UNAVAILABLE == 0); #else - fatal ("init_register_cache: can't allocate memory from the heap"); + gdb_assert_not_reached ("can't allocate memory from the heap"); #endif } else @@ -243,8 +242,8 @@ find_register_by_name (const struct target_desc *tdesc, const char *name) for (i = 0; i < tdesc->num_registers; i++) if (strcmp (name, tdesc->reg_defs[i].name) == 0) return &tdesc->reg_defs[i]; - fatal ("Unknown register %s requested", name); - return 0; + internal_error (__FILE__, __LINE__, "Unknown register %s requested", + name); } int @@ -255,8 +254,8 @@ find_regno (const struct target_desc *tdesc, const char *name) for (i = 0; i < tdesc->num_registers; i++) if (strcmp (name, tdesc->reg_defs[i].name) == 0) return i; - fatal ("Unknown register %s requested", name); - return -1; + internal_error (__FILE__, __LINE__, "Unknown register %s requested", + name); } struct reg * diff --git a/gdb/gdbserver/tdesc.c b/gdb/gdbserver/tdesc.c index 9710128..0c56f5c 100644 --- a/gdb/gdbserver/tdesc.c +++ b/gdb/gdbserver/tdesc.c @@ -35,8 +35,7 @@ init_target_desc (struct target_desc *tdesc) /* Make sure PBUFSIZ is large enough to hold a full register packet. */ - if (2 * tdesc->registers_size + 32 > PBUFSIZ) - fatal ("Register packet size exceeds PBUFSIZ."); + gdb_assert (2 * tdesc->registers_size + 32 <= PBUFSIZ); } #ifndef IN_PROCESS_AGENT diff --git a/gdb/gdbserver/thread-db.c b/gdb/gdbserver/thread-db.c index d69c9e4..eabfe20 100644 --- a/gdb/gdbserver/thread-db.c +++ b/gdb/gdbserver/thread-db.c @@ -193,8 +193,7 @@ thread_db_create_event (CORE_ADDR where) struct lwp_info *lwp; struct thread_db *thread_db = current_process ()->private->thread_db; - if (thread_db->td_ta_event_getmsg_p == NULL) - fatal ("unexpected thread_db->td_ta_event_getmsg_p == NULL"); + gdb_assert (thread_db->td_ta_event_getmsg_p != NULL); if (debug_threads) debug_printf ("Thread creation event.\n"); @@ -561,8 +560,7 @@ thread_db_load_search (void) struct thread_db *tdb; struct process_info *proc = current_process (); - if (proc->private->thread_db != NULL) - fatal ("unexpected: proc->private->thread_db != NULL"); + gdb_assert (proc->private->thread_db == NULL); tdb = xcalloc (1, sizeof (*tdb)); proc->private->thread_db = tdb; @@ -607,8 +605,7 @@ try_thread_db_load_1 (void *handle) struct thread_db *tdb; struct process_info *proc = current_process (); - if (proc->private->thread_db != NULL) - fatal ("unexpected: proc->private->thread_db != NULL"); + gdb_assert (proc->private->thread_db == NULL); tdb = xcalloc (1, sizeof (*tdb)); proc->private->thread_db = tdb; diff --git a/gdb/gdbserver/tracepoint.c b/gdb/gdbserver/tracepoint.c index 7c4b291..92c26aa 100644 --- a/gdb/gdbserver/tracepoint.c +++ b/gdb/gdbserver/tracepoint.c @@ -2943,7 +2943,10 @@ get_jump_space_head (void) { if (read_inferior_data_pointer (ipa_sym_addrs.addr_gdb_jump_pad_buffer, &gdb_jump_pad_head)) - fatal ("error extracting jump_pad_buffer"); + { + internal_error (__FILE__, __LINE__, + "error extracting jump_pad_buffer"); + } } return gdb_jump_pad_head; @@ -2974,15 +2977,15 @@ claim_trampoline_space (ULONGEST used, CORE_ADDR *trampoline) if (read_inferior_data_pointer (ipa_sym_addrs.addr_gdb_trampoline_buffer, &trampoline_buffer_tail)) { - fatal ("error extracting trampoline_buffer"); - return 0; + internal_error (__FILE__, __LINE__, + "error extracting trampoline_buffer"); } if (read_inferior_data_pointer (ipa_sym_addrs.addr_gdb_trampoline_buffer_end, &trampoline_buffer_head)) { - fatal ("error extracting trampoline_buffer_end"); - return 0; + internal_error (__FILE__, __LINE__, + "error extracting trampoline_buffer_end"); } } @@ -3017,8 +3020,8 @@ have_fast_tracepoint_trampoline_buffer (char *buf) if (read_inferior_data_pointer (ipa_sym_addrs.addr_gdb_trampoline_buffer_end, &trampoline_end)) { - fatal ("error extracting trampoline_buffer_end"); - return 0; + internal_error (__FILE__, __LINE__, + "error extracting trampoline_buffer_end"); } if (buf) @@ -3028,8 +3031,8 @@ have_fast_tracepoint_trampoline_buffer (char *buf) if (read_inferior_data_pointer (ipa_sym_addrs.addr_gdb_trampoline_buffer_error, &errbuf)) { - fatal ("error extracting errbuf"); - return 0; + internal_error (__FILE__, __LINE__, + "error extracting errbuf"); } read_inferior_memory (errbuf, (unsigned char *) buf, 100); @@ -3371,14 +3374,25 @@ cmd_qtstart (char *packet) if (agent_loaded_p ()) { if (write_inferior_integer (ipa_sym_addrs.addr_tracing, 1)) - fatal ("Error setting tracing variable in lib"); + { + internal_error (__FILE__, __LINE__, + "Error setting tracing variable in lib"); + } if (write_inferior_data_pointer (ipa_sym_addrs.addr_stopping_tracepoint, 0)) - fatal ("Error clearing stopping_tracepoint variable in lib"); + { + internal_error (__FILE__, __LINE__, + "Error clearing stopping_tracepoint variable" + " in lib"); + } if (write_inferior_integer (ipa_sym_addrs.addr_trace_buffer_is_full, 0)) - fatal ("Error clearing trace_buffer_is_full variable in lib"); + { + internal_error (__FILE__, __LINE__, + "Error clearing trace_buffer_is_full variable" + " in lib"); + } stop_tracing_bkpt = set_breakpoint_at (ipa_sym_addrs.addr_stop_tracing, stop_tracing_handler); @@ -3430,7 +3444,10 @@ stop_tracing (void) if (agent_loaded_p ()) { if (write_inferior_integer (ipa_sym_addrs.addr_tracing, 0)) - fatal ("Error clearing tracing variable in lib"); + { + internal_error (__FILE__, __LINE__, + "Error clearing tracing variable in lib"); + } } tracing_stop_time = get_timestamp (); @@ -5608,17 +5625,29 @@ fast_tracepoint_collecting (CORE_ADDR thread_area, if (read_inferior_data_pointer (ipa_sym_addrs.addr_gdb_jump_pad_buffer, &ipa_gdb_jump_pad_buffer)) - fatal ("error extracting `gdb_jump_pad_buffer'"); + { + internal_error (__FILE__, __LINE__, + "error extracting `gdb_jump_pad_buffer'"); + } if (read_inferior_data_pointer (ipa_sym_addrs.addr_gdb_jump_pad_buffer_end, &ipa_gdb_jump_pad_buffer_end)) - fatal ("error extracting `gdb_jump_pad_buffer_end'"); + { + internal_error (__FILE__, __LINE__, + "error extracting `gdb_jump_pad_buffer_end'"); + } if (read_inferior_data_pointer (ipa_sym_addrs.addr_gdb_trampoline_buffer, &ipa_gdb_trampoline_buffer)) - fatal ("error extracting `gdb_trampoline_buffer'"); + { + internal_error (__FILE__, __LINE__, + "error extracting `gdb_trampoline_buffer'"); + } if (read_inferior_data_pointer (ipa_sym_addrs.addr_gdb_trampoline_buffer_end, &ipa_gdb_trampoline_buffer_end)) - fatal ("error extracting `gdb_trampoline_buffer_end'"); + { + internal_error (__FILE__, __LINE__, + "error extracting `gdb_trampoline_buffer_end'"); + } if (ipa_gdb_jump_pad_buffer <= stop_pc && stop_pc < ipa_gdb_jump_pad_buffer_end) @@ -5938,7 +5967,10 @@ target_malloc (ULONGEST size) /* We have the pointer *address*, need what it points to. */ if (read_inferior_data_pointer (ipa_sym_addrs.addr_gdb_tp_heap_buffer, &target_tp_heap)) - fatal ("could get target heap head pointer"); + { + internal_error (__FILE__, __LINE__, + "couldn't get target heap head pointer"); + } } ptr = target_tp_heap; @@ -6162,7 +6194,10 @@ download_tracepoint (struct tracepoint *tpoint) if (read_inferior_data_pointer (tp_prev->obj_addr_on_target + offsetof (struct tracepoint, next), &tp_prev_target_next_addr)) - fatal ("error reading `tp_prev->next'"); + { + internal_error (__FILE__, __LINE__, + "error reading `tp_prev->next'"); + } /* tpoint->next = tp_prev->next */ write_inferior_data_ptr (tpoint->obj_addr_on_target @@ -6239,10 +6274,7 @@ download_trace_state_variables (void) name_addr); } - if (tsv->getter != NULL) - { - fatal ("what to do with these?"); - } + gdb_assert (tsv->getter == NULL); } if (prev_ptr != 0) @@ -6415,9 +6447,13 @@ upload_fast_traceframes (void) error ("Uploading: couldn't read traceframe at %s\n", paddress (tf)); if (ipa_tframe.tpnum == 0) - fatal ("Uploading: No (more) fast traceframes, but " - "ipa_traceframe_count == %u??\n", - ipa_traceframe_write_count - ipa_traceframe_read_count); + { + internal_error (__FILE__, __LINE__, + "Uploading: No (more) fast traceframes, but" + " ipa_traceframe_count == %u??\n", + ipa_traceframe_write_count + - ipa_traceframe_read_count); + } /* Note that this will be incorrect for multi-location tracepoints... */