public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Simon Marchi <simon.marchi@polymtl.ca>
To: gdb-patches@sourceware.org
Cc: tom@tromey.com,	Simon Marchi <simon.marchi@polymtl.ca>
Subject: [PATCH 2/2] darwin: Don't use sbrk
Date: Wed, 04 Jul 2018 04:31:00 -0000	[thread overview]
Message-ID: <20180704043033.29212-2-simon.marchi@polymtl.ca> (raw)
In-Reply-To: <20180704043033.29212-1-simon.marchi@polymtl.ca>

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.
---
 gdb/common/common-defs.h | 4 ++++
 gdb/main.c               | 2 +-
 gdb/maint.c              | 4 ++--
 gdb/top.c                | 2 +-
 4 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/gdb/common/common-defs.h b/gdb/common/common-defs.h
index eb0ec214926c..8209e13943d7 100644
--- a/gdb/common/common-defs.h
+++ b/gdb/common/common-defs.h
@@ -105,4 +105,8 @@
 /* String containing the current directory (what getwd would return).  */
 extern char *current_directory;
 
+#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 9694af242699..e925128a4263 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 a8a1fcbc2996..5d4701cfacca 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 fdef3e0d0bf2..de1a335e40a4 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
 
-- 
2.17.1

  reply	other threads:[~2018-07-04  4:31 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-07-04  4:31 [PATCH 1/2] darwin: Silence syscall deprecated declaration warning Simon Marchi
2018-07-04  4:31 ` Simon Marchi [this message]
2018-07-04 10:49   ` [PATCH 2/2] darwin: Don't use sbrk Pedro Alves
2018-07-04 16:41     ` Simon Marchi
2018-07-04 10:31 ` [PATCH 1/2] darwin: Silence syscall deprecated declaration warning Pedro Alves
2018-07-04 16:39   ` Simon Marchi
2018-07-05 16:12     ` Pedro Alves

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180704043033.29212-2-simon.marchi@polymtl.ca \
    --to=simon.marchi@polymtl.ca \
    --cc=gdb-patches@sourceware.org \
    --cc=tom@tromey.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).