This is the mail archive of the
gdb-cvs@sourceware.org
mailing list for the GDB project.
[binutils-gdb] darwin: Don't use sbrk
- From: Simon Marchi <simark at sourceware dot org>
- To: gdb-cvs at sourceware dot org
- Date: 4 Jul 2018 16:42:21 -0000
- Subject: [binutils-gdb] darwin: Don't use sbrk
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=6242c6a690ce8e18aad711103902bfff00cc2757
commit 6242c6a690ce8e18aad711103902bfff00cc2757
Author: Simon Marchi <simon.marchi@polymtl.ca>
Date: Wed Jul 4 12:40:25 2018 -0400
darwin: Don't use sbrk
This patch gets rid of this warning on macOS:
CXX main.o
/Users/simark/src/binutils-gdb/gdb/main.c:492:27: error: 'sbrk' is deprecated [-Werror,-Wdeprecated-declarations]
lim_at_start = (char *) sbrk (0);
^
/usr/include/unistd.h:585:1: note: 'sbrk' has been explicitly marked deprecated here
__deprecated __WATCHOS_PROHIBITED __TVOS_PROHIBITED
^
/usr/include/sys/cdefs.h:176:37: note: expanded from macro '__deprecated'
#define __deprecated __attribute__((deprecated))
^
sbrk on macOS is not useful for our purposes, since sbrk(0) always
returns the same value. From what I read, brk/sbrk on macOS is just an
emulation, it always returns a pointer in a 4MB section reserved for
that.
So instead of letting users use "maint set per-command space on" and
print silly results, I think we should just disable that feature for
this platform (as we do for platforms that don't have sbrk).
I defined a HAVE_USEFUL_SBRK macro and used that instead of HAVE_SBRK.
gdb/ChangeLog:
* common/common-defs.h (HAVE_USEFUL_SBRK): Define.
* main.c: Use HAVE_USEFUL_SBRK instead of HAVE_SBRK.
* maint.c: Likewise.
* top.c: Likewise.
Diff:
---
gdb/ChangeLog | 7 +++++++
gdb/common/common-defs.h | 9 +++++++++
gdb/main.c | 2 +-
gdb/maint.c | 4 ++--
gdb/top.c | 2 +-
5 files changed, 20 insertions(+), 4 deletions(-)
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index cc09755..d2319c0 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,10 @@
+2018-07-04 Simon Marchi <simon.marchi@polymtl.ca>
+
+ * common/common-defs.h (HAVE_USEFUL_SBRK): Define.
+ * main.c: Use HAVE_USEFUL_SBRK instead of HAVE_SBRK.
+ * maint.c: Likewise.
+ * top.c: Likewise.
+
2018-07-04 Joel Brobecker <brobecker@adacore.com>
* NEWS: Create a new section for the next release branch.
diff --git a/gdb/common/common-defs.h b/gdb/common/common-defs.h
index eb0ec21..80f1ff4 100644
--- a/gdb/common/common-defs.h
+++ b/gdb/common/common-defs.h
@@ -105,4 +105,13 @@
/* String containing the current directory (what getwd would return). */
extern char *current_directory;
+/* sbrk on macOS is not useful for our purposes, since sbrk(0) always
+ returns the same value. brk/sbrk on macOS is just an emulation
+ that always returns a pointer to a 4MB section reserved for
+ that. */
+
+#if defined (HAVE_SBRK) && !__APPLE__
+#define HAVE_USEFUL_SBRK 1
+#endif
+
#endif /* COMMON_DEFS_H */
diff --git a/gdb/main.c b/gdb/main.c
index 9694af2..e925128 100644
--- a/gdb/main.c
+++ b/gdb/main.c
@@ -487,7 +487,7 @@ captured_main_1 (struct captured_main_args *context)
int save_auto_load;
struct objfile *objfile;
-#ifdef HAVE_SBRK
+#ifdef HAVE_USEFUL_SBRK
/* Set this before constructing scoped_command_stats. */
lim_at_start = (char *) sbrk (0);
#endif
diff --git a/gdb/maint.c b/gdb/maint.c
index a8a1fcb..5d4701c 100644
--- a/gdb/maint.c
+++ b/gdb/maint.c
@@ -828,7 +828,7 @@ scoped_command_stats::~scoped_command_stats ()
if (m_space_enabled && per_command_space)
{
-#ifdef HAVE_SBRK
+#ifdef HAVE_USEFUL_SBRK
char *lim = (char *) sbrk (0);
long space_now = lim - lim_at_start;
@@ -866,7 +866,7 @@ scoped_command_stats::scoped_command_stats (bool msg_type)
{
if (!m_msg_type || per_command_space)
{
-#ifdef HAVE_SBRK
+#ifdef HAVE_USEFUL_SBRK
char *lim = (char *) sbrk (0);
m_start_space = lim - lim_at_start;
m_space_enabled = 1;
diff --git a/gdb/top.c b/gdb/top.c
index fdef3e0..de1a335 100644
--- a/gdb/top.c
+++ b/gdb/top.c
@@ -171,7 +171,7 @@ int remote_timeout = 2;
int remote_debug = 0;
/* Sbrk location on entry to main. Used for statistics only. */
-#ifdef HAVE_SBRK
+#ifdef HAVE_USEFUL_SBRK
char *lim_at_start;
#endif