aboutsummaryrefslogtreecommitdiff
path: root/gdbsupport
diff options
context:
space:
mode:
authorPedro Alves <pedro@palves.net>2022-10-17 17:12:20 +0100
committerPedro Alves <pedro@palves.net>2022-10-19 15:32:36 +0100
commitf34652de0b68c4ee3050828b43a2839b852b5821 (patch)
tree851720f14f2ac022c3e82428254edf161d619e91 /gdbsupport
parent5c831a3c7f3ca98d6aba1200353311e1a1f84c70 (diff)
downloadgdb-f34652de0b68c4ee3050828b43a2839b852b5821.zip
gdb-f34652de0b68c4ee3050828b43a2839b852b5821.tar.gz
gdb-f34652de0b68c4ee3050828b43a2839b852b5821.tar.bz2
internal_error: remove need to pass __FILE__/__LINE__
Currently, every internal_error call must be passed __FILE__/__LINE__ explicitly, like: internal_error (__FILE__, __LINE__, "foo %d", var); The need to pass in explicit __FILE__/__LINE__ is there probably because the function predates widespread and portable variadic macros availability. We can use variadic macros nowadays, and in fact, we already use them in several places, including the related gdb_assert_not_reached. So this patch renames the internal_error function to something else, and then reimplements internal_error as a variadic macro that expands __FILE__/__LINE__ itself. The result is that we now should call internal_error like so: internal_error ("foo %d", var); Likewise for internal_warning. The patch adjusts all calls sites. 99% of the adjustments were done with a perl/sed script. The non-mechanical changes are in gdbsupport/errors.h, gdbsupport/gdb_assert.h, and gdb/gdbarch.py. Approved-By: Simon Marchi <simon.marchi@efficios.com> Change-Id: Ia6f372c11550ca876829e8fd85048f4502bdcf06
Diffstat (limited to 'gdbsupport')
-rw-r--r--gdbsupport/btrace-common.cc10
-rw-r--r--gdbsupport/common-exceptions.cc10
-rw-r--r--gdbsupport/common-utils.cc2
-rw-r--r--gdbsupport/errors.cc4
-rw-r--r--gdbsupport/errors.h18
-rw-r--r--gdbsupport/event-loop.cc3
-rw-r--r--gdbsupport/gdb_assert.h8
-rw-r--r--gdbsupport/print-utils.cc11
8 files changed, 35 insertions, 31 deletions
diff --git a/gdbsupport/btrace-common.cc b/gdbsupport/btrace-common.cc
index ace0413..d3f4fa4 100644
--- a/gdbsupport/btrace-common.cc
+++ b/gdbsupport/btrace-common.cc
@@ -38,7 +38,7 @@ btrace_format_string (enum btrace_format format)
return _("Intel Processor Trace");
}
- internal_error (__FILE__, __LINE__, _("Unknown branch trace format"));
+ internal_error (_("Unknown branch trace format"));
}
/* See btrace-common.h. */
@@ -58,7 +58,7 @@ btrace_format_short_string (enum btrace_format format)
return "pt";
}
- internal_error (__FILE__, __LINE__, _("Unknown branch trace format"));
+ internal_error (_("Unknown branch trace format"));
}
/* See btrace-common.h. */
@@ -82,7 +82,7 @@ btrace_data::fini ()
return;
}
- internal_error (__FILE__, __LINE__, _("Unkown branch trace format."));
+ internal_error (_("Unkown branch trace format."));
}
/* See btrace-common.h. */
@@ -102,7 +102,7 @@ btrace_data::empty () const
return (variant.pt.size == 0);
}
- internal_error (__FILE__, __LINE__, _("Unkown branch trace format."));
+ internal_error (_("Unkown branch trace format."));
}
/* See btrace-common.h. */
@@ -187,5 +187,5 @@ btrace_data_append (struct btrace_data *dst,
return 0;
}
- internal_error (__FILE__, __LINE__, _("Unkown branch trace format."));
+ internal_error (_("Unkown branch trace format."));
}
diff --git a/gdbsupport/common-exceptions.cc b/gdbsupport/common-exceptions.cc
index 2d686c4..a9bda75 100644
--- a/gdbsupport/common-exceptions.cc
+++ b/gdbsupport/common-exceptions.cc
@@ -74,7 +74,7 @@ exceptions_state_mc (enum catcher_action action)
catchers.front ().state = CATCHER_RUNNING;
return 1;
default:
- internal_error (__FILE__, __LINE__, _("bad state"));
+ internal_error (_("bad state"));
}
case CATCHER_RUNNING:
switch (action)
@@ -90,7 +90,7 @@ exceptions_state_mc (enum catcher_action action)
/* See also throw_exception. */
return 1;
default:
- internal_error (__FILE__, __LINE__, _("bad switch"));
+ internal_error (_("bad switch"));
}
case CATCHER_RUNNING_1:
switch (action)
@@ -106,7 +106,7 @@ exceptions_state_mc (enum catcher_action action)
/* See also throw_exception. */
return 1;
default:
- internal_error (__FILE__, __LINE__, _("bad switch"));
+ internal_error (_("bad switch"));
}
case CATCHER_ABORTING:
switch (action)
@@ -119,10 +119,10 @@ exceptions_state_mc (enum catcher_action action)
return 0;
}
default:
- internal_error (__FILE__, __LINE__, _("bad state"));
+ internal_error (_("bad state"));
}
default:
- internal_error (__FILE__, __LINE__, _("bad switch"));
+ internal_error (_("bad switch"));
}
}
diff --git a/gdbsupport/common-utils.cc b/gdbsupport/common-utils.cc
index 2b69e0b..3658ffc 100644
--- a/gdbsupport/common-utils.cc
+++ b/gdbsupport/common-utils.cc
@@ -54,7 +54,7 @@ xstrvprintf (const char *format, va_list ap)
status (the printed length) with a non-NULL buffer should never
happen, but just to be sure. */
if (ret == NULL || status < 0)
- internal_error (__FILE__, __LINE__, _("vasprintf call failed"));
+ internal_error (_("vasprintf call failed"));
return gdb::unique_xmalloc_ptr<char> (ret);
}
diff --git a/gdbsupport/errors.cc b/gdbsupport/errors.cc
index b98d015..7464df3 100644
--- a/gdbsupport/errors.cc
+++ b/gdbsupport/errors.cc
@@ -50,7 +50,7 @@ error (const char *fmt, ...)
/* See gdbsupport/errors.h. */
void
-internal_error (const char *file, int line, const char *fmt, ...)
+internal_error_loc (const char *file, int line, const char *fmt, ...)
{
va_list ap;
@@ -62,7 +62,7 @@ internal_error (const char *file, int line, const char *fmt, ...)
/* See gdbsupport/errors.h. */
void
-internal_warning (const char *file, int line, const char *fmt, ...)
+internal_warning_loc (const char *file, int line, const char *fmt, ...)
{
va_list ap;
diff --git a/gdbsupport/errors.h b/gdbsupport/errors.h
index 9a671d3..5a92578 100644
--- a/gdbsupport/errors.h
+++ b/gdbsupport/errors.h
@@ -48,13 +48,18 @@ extern void verror (const char *fmt, va_list args)
functions do not return. An error message is constructed using
a printf- or vprintf-style argument list. FILE and LINE
indicate the file and line number where the programming error
- was detected. The function "internal_verror" must be provided
+ was detected. Most client code should call the internal_error
+ wrapper macro instead, which expands the source location
+ automatically. The function "internal_verror" must be provided
by the client. */
-extern void internal_error (const char *file, int line,
- const char *fmt, ...)
+extern void internal_error_loc (const char *file, int line,
+ const char *fmt, ...)
ATTRIBUTE_NORETURN ATTRIBUTE_PRINTF (3, 4);
+#define internal_error(fmt, ...) \
+ internal_error_loc (__FILE__, __LINE__, fmt, ##__VA_ARGS__)
+
extern void internal_verror (const char *file, int line,
const char *fmt, va_list args)
ATTRIBUTE_NORETURN ATTRIBUTE_PRINTF (3, 0);
@@ -66,10 +71,13 @@ extern void internal_verror (const char *file, int line,
argument list. The function "internal_vwarning" must be provided
by the client. */
-extern void internal_warning (const char *file, int line,
- const char *fmt, ...)
+extern void internal_warning_loc (const char *file, int line,
+ const char *fmt, ...)
ATTRIBUTE_PRINTF (3, 4);
+#define internal_warning(fmt, ...) \
+ internal_warning_loc (__FILE__, __LINE__, fmt, ##__VA_ARGS__)
+
extern void internal_vwarning (const char *file, int line,
const char *fmt, va_list args)
ATTRIBUTE_PRINTF (3, 0);
diff --git a/gdbsupport/event-loop.cc b/gdbsupport/event-loop.cc
index 9418855..b1a5c1a 100644
--- a/gdbsupport/event-loop.cc
+++ b/gdbsupport/event-loop.cc
@@ -221,8 +221,7 @@ gdb_do_one_event (int mstimeout)
res = check_async_event_handlers ();
break;
default:
- internal_error (__FILE__, __LINE__,
- "unexpected event_source_head %d",
+ internal_error ("unexpected event_source_head %d",
event_source_head);
}
diff --git a/gdbsupport/gdb_assert.h b/gdbsupport/gdb_assert.h
index 074d2e7..e1444d5 100644
--- a/gdbsupport/gdb_assert.h
+++ b/gdbsupport/gdb_assert.h
@@ -38,14 +38,14 @@
/* This prints an "Assertion failed" message, asking the user if they
want to continue, dump core, or just exit. */
#define gdb_assert_fail(assertion, file, line, function) \
- internal_error (file, line, _("%s: Assertion `%s' failed."), \
- function, assertion)
+ internal_error_loc (file, line, _("%s: Assertion `%s' failed."), \
+ function, assertion)
/* The canonical form of gdb_assert (0).
MESSAGE is a string to include in the error message. */
#define gdb_assert_not_reached(message, ...) \
- internal_error (__FILE__, __LINE__, _("%s: " message), __func__, \
- ##__VA_ARGS__)
+ internal_error_loc (__FILE__, __LINE__, _("%s: " message), __func__, \
+ ##__VA_ARGS__)
#endif /* COMMON_GDB_ASSERT_H */
diff --git a/gdbsupport/print-utils.cc b/gdbsupport/print-utils.cc
index 7bbb6de..a1b245e 100644
--- a/gdbsupport/print-utils.cc
+++ b/gdbsupport/print-utils.cc
@@ -73,8 +73,7 @@ decimal2str (const char *sign, ULONGEST addr, int width)
temp[2], temp[1], temp[0]);
break;
default:
- internal_error (__FILE__, __LINE__,
- _("failed internal consistency check"));
+ internal_error (_("failed internal consistency check"));
}
return str;
@@ -116,8 +115,7 @@ octal2str (ULONGEST addr, int width)
temp[2], temp[1], temp[0]);
break;
default:
- internal_error (__FILE__, __LINE__,
- _("failed internal consistency check"));
+ internal_error (_("failed internal consistency check"));
}
return str;
@@ -246,7 +244,7 @@ hex_string_custom (LONGEST num, int width)
if (hex_len > width)
width = hex_len;
if (width + 2 >= PRINT_CELL_SIZE)
- internal_error (__FILE__, __LINE__, _("\
+ internal_error (_("\
hex_string_custom: insufficient space to store result"));
strcpy (result_end - width - 2, "0x");
@@ -296,8 +294,7 @@ int_string (LONGEST val, int radix, int is_signed, int width,
return result + 1;
}
default:
- internal_error (__FILE__, __LINE__,
- _("failed internal consistency check"));
+ internal_error (_("failed internal consistency check"));
}
}