Straightforward fatal to internal_error conversions
authorGary Benson <gbenson@redhat.com>
Wed, 6 Aug 2014 10:56:25 +0000 (11:56 +0100)
committerGary Benson <gbenson@redhat.com>
Thu, 28 Aug 2014 14:06:45 +0000 (15:06 +0100)
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/ChangeLog:

* 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
gdb/gdbserver/inferiors.c
gdb/gdbserver/linux-low.c
gdb/gdbserver/linux-x86-low.c
gdb/gdbserver/mem-break.c
gdb/gdbserver/regcache.c
gdb/gdbserver/tdesc.c
gdb/gdbserver/thread-db.c
gdb/gdbserver/tracepoint.c

index 8d42982f9ae584bf8bc6d112160a35da795fc700..778500faed1e04a470f2095031e79aca4ee7f649 100644 (file)
@@ -1,3 +1,33 @@
+2014-08-28  Gary Benson  <gbenson@redhat.com>
+
+       * 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.
+
 2014-08-19  Tom Tromey  <tromey@redhat.com>
            Gary Benson  <gbenson@redhat.com>
 
index 608a99736db3b890f79981753300b5fa39e1f734..29a07e06d100f76c714002c615a2d57f10d85118 100644 (file)
@@ -355,8 +355,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);
 }
index 543987a8dc39376b86286c12ec942fbb85fbfe89..f8b3e68ff2c13daec1a34a0df5a8d1a4ccff0875 100644 (file)
@@ -2026,7 +2026,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)
        {
@@ -3432,8 +3436,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;
index 7a8a47323869fc1fffb67415bf1a172ac44b0aa4..a47fcbe6f69ab9899c312b09fc6b7ef1bd8c3ae9 100644 (file)
@@ -1227,8 +1227,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);
@@ -1240,8 +1239,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,
index 2ce3ab2f9b6153b30845640dbf2b0a06e4c8e6c4..07f9b20b56f6afe50ac510e1525d9956fe630c75 100644 (file)
@@ -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);
     }
 }
 
index 916a47994a48ed590c73e9ef1a574edf60edf160..fda206944e69409693517824cc8006e636d1f6eb 100644 (file)
@@ -41,8 +41,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);
@@ -126,7 +125,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
@@ -239,8 +238,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
@@ -251,8 +250,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 *
index 971012803370b2e2223401b2923a3dea178af590..0c56f5c3e86415f8de62d1129ce15270d0948952 100644 (file)
@@ -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
index d69c9e43f81f89f8f338a047e4480834e1625fd9..eabfe20720450fa4ca58699d3d95c4b343aa1405 100644 (file)
@@ -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;
index 302b9c7f430407967a17bc280c15fcad87ae49cc..a9a406241c971bab964e9a511ffd762e4c765d56 100644 (file)
@@ -2942,7 +2942,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;
@@ -2973,15 +2976,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");
        }
     }
 
@@ -3016,8 +3019,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)
@@ -3027,8 +3030,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);
@@ -3370,14 +3373,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);
@@ -3429,7 +3443,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 ();
@@ -5607,17 +5624,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)
@@ -5937,7 +5966,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;
@@ -6161,7 +6193,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
@@ -6238,10 +6273,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)
@@ -6414,9 +6446,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...  */