public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] gdb: replace some calls to internal_error with gdb_assert
@ 2020-04-02 17:48 Simon Marchi
  2020-04-02 19:34 ` Tom Tromey
  0 siblings, 1 reply; 3+ messages in thread
From: Simon Marchi @ 2020-04-02 17:48 UTC (permalink / raw)
  To: gdb-patches

There are a few spots using the pattern:

  if (condition)
    internal_error (__FILE__, __LINE__,
		    _("failed internal consistency check"));

The message brings no value, since it's pretty the description of a
failed assertion.  Replace a few of these that are obvious with
gdb_assert.

gdb/ChangeLog:

	* exec.c (build_section_table): Replace internal_error with
	gdb_assert.
	(section_table_xfer_memory_partial): Likewise.
	* mdebugread.c (parse_partial_symbols): Likewise.
	* psymtab.c (lookup_partial_symbol): Likewise.
	* utils.c (wrap_here): Likewise.
---
 gdb/exec.c       | 10 ++++------
 gdb/mdebugread.c |  5 ++---
 gdb/psymtab.c    | 11 +++++------
 gdb/utils.c      |  4 +---
 4 files changed, 12 insertions(+), 18 deletions(-)

diff --git a/gdb/exec.c b/gdb/exec.c
index 68bca1be1773..c885709c94e4 100644
--- a/gdb/exec.c
+++ b/gdb/exec.c
@@ -619,9 +619,9 @@ build_section_table (struct bfd *some_bfd, struct target_section **start,
   *start = XNEWVEC (struct target_section, count);
   *end = *start;
   bfd_map_over_sections (some_bfd, add_to_section_table, (char *) end);
-  if (*end > *start + count)
-    internal_error (__FILE__, __LINE__,
-		    _("failed internal consistency check"));
+
+  gdb_assert (*end <= *start + count);
+
   /* We could realloc the table, but it probably loses for most files.  */
   return 0;
 }
@@ -916,9 +916,7 @@ section_table_xfer_memory_partial (gdb_byte *readbuf, const gdb_byte *writebuf,
   ULONGEST memaddr = offset;
   ULONGEST memend = memaddr + len;
 
-  if (len == 0)
-    internal_error (__FILE__, __LINE__,
-		    _("failed internal consistency check"));
+  gdb_assert (len != 0);
 
   for (p = sections; p < sections_end; p++)
     {
diff --git a/gdb/mdebugread.c b/gdb/mdebugread.c
index bac6fd6c4656..5dfd80de1923 100644
--- a/gdb/mdebugread.c
+++ b/gdb/mdebugread.c
@@ -3576,9 +3576,8 @@ parse_partial_symbols (minimal_symbol_reader &reader,
 	      CORE_ADDR svalue;
 	      short section;
 
-	      if (ext_ptr->ifd != f_idx)
-		internal_error (__FILE__, __LINE__,
-				_("failed internal consistency check"));
+	      gdb_assert (ext_ptr->ifd == f_idx);
+
 	      psh = &ext_ptr->asym;
 
 	      /* Do not add undefined symbols to the partial symbol table.  */
diff --git a/gdb/psymtab.c b/gdb/psymtab.c
index 26c55e9bd334..129eecb06711 100644
--- a/gdb/psymtab.c
+++ b/gdb/psymtab.c
@@ -683,9 +683,9 @@ lookup_partial_symbol (struct objfile *objfile,
       while (top > bottom)
 	{
 	  center = bottom + (top - bottom) / 2;
-	  if (!(center < top))
-	    internal_error (__FILE__, __LINE__,
-			    _("failed internal consistency check"));
+
+	  gdb_assert (center < top);
+
 	  if (strcmp_iw_ordered ((*center)->ginfo.search_name (),
 				 lookup_name.c_str ()) >= 0)
 	    {
@@ -696,9 +696,8 @@ lookup_partial_symbol (struct objfile *objfile,
 	      bottom = center + 1;
 	    }
 	}
-      if (!(top == bottom))
-	internal_error (__FILE__, __LINE__,
-			_("failed internal consistency check"));
+
+      gdb_assert (top == bottom);
 
       /* For `case_sensitivity == case_sensitive_off' strcmp_iw_ordered will
 	 search more exactly than what matches SYMBOL_MATCHES_SEARCH_NAME.  */
diff --git a/gdb/utils.c b/gdb/utils.c
index 0b470120a22f..bda6bbf5b0e7 100644
--- a/gdb/utils.c
+++ b/gdb/utils.c
@@ -1578,9 +1578,7 @@ void
 wrap_here (const char *indent)
 {
   /* This should have been allocated, but be paranoid anyway.  */
-  if (!filter_initialized)
-    internal_error (__FILE__, __LINE__,
-		    _("failed internal consistency check"));
+  gdb_assert (filter_initialized);
 
   flush_wrap_buffer (gdb_stdout);
   if (chars_per_line == UINT_MAX)	/* No line overflow checking.  */
-- 
2.26.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] gdb: replace some calls to internal_error with gdb_assert
  2020-04-02 17:48 [PATCH] gdb: replace some calls to internal_error with gdb_assert Simon Marchi
@ 2020-04-02 19:34 ` Tom Tromey
  2020-04-02 19:44   ` Simon Marchi
  0 siblings, 1 reply; 3+ messages in thread
From: Tom Tromey @ 2020-04-02 19:34 UTC (permalink / raw)
  To: Simon Marchi via Gdb-patches

>>>>> "Simon" == Simon Marchi via Gdb-patches <gdb-patches@sourceware.org> writes:

Simon> 	* exec.c (build_section_table): Replace internal_error with
Simon> 	gdb_assert.
Simon> 	(section_table_xfer_memory_partial): Likewise.
Simon> 	* mdebugread.c (parse_partial_symbols): Likewise.
Simon> 	* psymtab.c (lookup_partial_symbol): Likewise.
Simon> 	* utils.c (wrap_here): Likewise.

Looks good to me.

Tom

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] gdb: replace some calls to internal_error with gdb_assert
  2020-04-02 19:34 ` Tom Tromey
@ 2020-04-02 19:44   ` Simon Marchi
  0 siblings, 0 replies; 3+ messages in thread
From: Simon Marchi @ 2020-04-02 19:44 UTC (permalink / raw)
  To: Tom Tromey, Simon Marchi via Gdb-patches

On 2020-04-02 3:34 p.m., Tom Tromey wrote:
>>>>>> "Simon" == Simon Marchi via Gdb-patches <gdb-patches@sourceware.org> writes:
> 
> Simon> 	* exec.c (build_section_table): Replace internal_error with
> Simon> 	gdb_assert.
> Simon> 	(section_table_xfer_memory_partial): Likewise.
> Simon> 	* mdebugread.c (parse_partial_symbols): Likewise.
> Simon> 	* psymtab.c (lookup_partial_symbol): Likewise.
> Simon> 	* utils.c (wrap_here): Likewise.
> 
> Looks good to me.
> 
> Tom
> 

Thanks, I pushed it.

Simon

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-04-02 19:44 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-02 17:48 [PATCH] gdb: replace some calls to internal_error with gdb_assert Simon Marchi
2020-04-02 19:34 ` Tom Tromey
2020-04-02 19:44   ` Simon Marchi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).