public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] gdbsupport: remove FUNCTION_NAME
@ 2021-11-13  2:12 Simon Marchi
  2021-11-16 20:09 ` Tom Tromey
  0 siblings, 1 reply; 3+ messages in thread
From: Simon Marchi @ 2021-11-13  2:12 UTC (permalink / raw)
  To: gdb-patches

__func__ is standard C++11:

    https://en.cppreference.com/w/cpp/language/function

Also, in C++11, __func__ expands to the demangled function name, so the
mention in the comment above FUNCTION_NAME doesn't apply anymore.
Finally, in places where FUNCTION_NAME is used, I think it's enough to
print the function name, no need to print the whole signature.
Therefore, I propose to just remove FUNCTION_NAME and update users to
use the standard __func__.

Change-Id: I778f28155422b044402442dc18d42d0cded1017d
---
 gdb/darwin-nat.h          |  8 +-------
 gdbsupport/common-utils.h | 20 --------------------
 gdbsupport/gdb_assert.h   | 15 ++-------------
 3 files changed, 3 insertions(+), 40 deletions(-)

diff --git a/gdb/darwin-nat.h b/gdb/darwin-nat.h
index 0e5951d47c8e..9d6b0c530bde 100644
--- a/gdb/darwin-nat.h
+++ b/gdb/darwin-nat.h
@@ -200,14 +200,8 @@ extern mach_port_t darwin_port_set;
 /* A copy of mach_host_self ().  */
 extern mach_port_t darwin_host_self;
 
-/* FUNCTION_NAME is defined in common-utils.h (or not).  */
-#ifdef FUNCTION_NAME
 #define MACH_CHECK_ERROR(ret) \
-  mach_check_error (ret, __FILE__, __LINE__, FUNCTION_NAME)
-#else
-#define MACH_CHECK_ERROR(ret) \
-  mach_check_error (ret, __FILE__, __LINE__, "??")
-#endif
+  mach_check_error (ret, __FILE__, __LINE__, __func__)
 
 extern void mach_check_error (kern_return_t ret, const char *file,
 			      unsigned int line, const char *func);
diff --git a/gdbsupport/common-utils.h b/gdbsupport/common-utils.h
index 224e1f312226..9381217f5821 100644
--- a/gdbsupport/common-utils.h
+++ b/gdbsupport/common-utils.h
@@ -23,27 +23,7 @@
 #include <string>
 #include <vector>
 #include "gdbsupport/byte-vector.h"
-
 #include "poison.h"
-
-/* If possible, define FUNCTION_NAME, a macro containing the name of
-   the function being defined.  Since this macro may not always be
-   defined, all uses must be protected by appropriate macro definition
-   checks (Eg: "#ifdef FUNCTION_NAME").
-
-   Version 2.4 and later of GCC define a magical variable `__PRETTY_FUNCTION__'
-   which contains the name of the function currently being defined.
-   This is broken in G++ before version 2.6.
-   C9x has a similar variable called __func__, but prefer the GCC one since
-   it demangles C++ function names.  */
-#if (GCC_VERSION >= 2004)
-#define FUNCTION_NAME		__PRETTY_FUNCTION__
-#else
-#if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L
-#define FUNCTION_NAME		__func__  /* ARI: func */
-#endif
-#endif
-
 #include "gdb_string_view.h"
 
 /* xmalloc(), xrealloc() and xcalloc() have already been declared in
diff --git a/gdbsupport/gdb_assert.h b/gdbsupport/gdb_assert.h
index 00553a786135..bc8ad7b5dc4e 100644
--- a/gdbsupport/gdb_assert.h
+++ b/gdbsupport/gdb_assert.h
@@ -33,29 +33,18 @@
 
 #define gdb_assert(expr)                                                      \
   ((void) ((expr) ? 0 :                                                       \
-	   (gdb_assert_fail (#expr, __FILE__, __LINE__, FUNCTION_NAME), 0)))
+	   (gdb_assert_fail (#expr, __FILE__, __LINE__, __func__), 0)))
 
 /* This prints an "Assertion failed" message, asking the user if they
    want to continue, dump core, or just exit.  */
-#if defined (FUNCTION_NAME)
 #define gdb_assert_fail(assertion, file, line, function)                      \
   internal_error (file, line, _("%s: Assertion `%s' failed."),                \
 		  function, assertion)
-#else
-#define gdb_assert_fail(assertion, file, line, function)                      \
-  internal_error (file, line, _("Assertion `%s' failed."),                    \
-		  assertion)
-#endif
 
 /* The canonical form of gdb_assert (0).
    MESSAGE is a string to include in the error message.  */
 
-#if defined (FUNCTION_NAME)
-#define gdb_assert_not_reached(message) \
-  internal_error (__FILE__, __LINE__, "%s: %s", FUNCTION_NAME, _(message))
-#else
 #define gdb_assert_not_reached(message) \
-  internal_error (__FILE__, __LINE__, _(message))
-#endif
+  internal_error (__FILE__, __LINE__, "%s: %s", __func__, _(message))
 
 #endif /* COMMON_GDB_ASSERT_H */
-- 
2.33.1


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

* Re: [PATCH] gdbsupport: remove FUNCTION_NAME
  2021-11-13  2:12 [PATCH] gdbsupport: remove FUNCTION_NAME Simon Marchi
@ 2021-11-16 20:09 ` Tom Tromey
  2021-11-16 20:37   ` Simon Marchi
  0 siblings, 1 reply; 3+ messages in thread
From: Tom Tromey @ 2021-11-16 20:09 UTC (permalink / raw)
  To: Simon Marchi via Gdb-patches

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

Simon> __func__ is standard C++11:
Simon>     https://en.cppreference.com/w/cpp/language/function

Simon> Also, in C++11, __func__ expands to the demangled function name, so the
Simon> mention in the comment above FUNCTION_NAME doesn't apply anymore.
Simon> Finally, in places where FUNCTION_NAME is used, I think it's enough to
Simon> print the function name, no need to print the whole signature.
Simon> Therefore, I propose to just remove FUNCTION_NAME and update users to
Simon> use the standard __func__.

Looks reasonable to me.

Tom

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

* Re: [PATCH] gdbsupport: remove FUNCTION_NAME
  2021-11-16 20:09 ` Tom Tromey
@ 2021-11-16 20:37   ` Simon Marchi
  0 siblings, 0 replies; 3+ messages in thread
From: Simon Marchi @ 2021-11-16 20:37 UTC (permalink / raw)
  To: Tom Tromey, Simon Marchi via Gdb-patches

On 2021-11-16 3:09 p.m., Tom Tromey wrote:
>>>>>> "Simon" == Simon Marchi via Gdb-patches <gdb-patches@sourceware.org> writes:
> 
> Simon> __func__ is standard C++11:
> Simon>     https://en.cppreference.com/w/cpp/language/function
> 
> Simon> Also, in C++11, __func__ expands to the demangled function name, so the
> Simon> mention in the comment above FUNCTION_NAME doesn't apply anymore.
> Simon> Finally, in places where FUNCTION_NAME is used, I think it's enough to
> Simon> print the function name, no need to print the whole signature.
> Simon> Therefore, I propose to just remove FUNCTION_NAME and update users to
> Simon> use the standard __func__.
> 
> Looks reasonable to me.
> 
> Tom
> 


Thanks, pushed.

Simon

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

end of thread, other threads:[~2021-11-16 20:37 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-13  2:12 [PATCH] gdbsupport: remove FUNCTION_NAME Simon Marchi
2021-11-16 20:09 ` Tom Tromey
2021-11-16 20:37   ` 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).