darwin: Don't use sbrk
authorSimon Marchi <simon.marchi@polymtl.ca>
Wed, 4 Jul 2018 16:40:25 +0000 (12:40 -0400)
committerSimon Marchi <simon.marchi@ericsson.com>
Wed, 4 Jul 2018 16:40:25 +0000 (12:40 -0400)
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/ChangeLog
gdb/common/common-defs.h
gdb/main.c
gdb/maint.c
gdb/top.c

index cc09755794664976079ff81db27daa32d1c0d5f8..d2319c06d5257420f181dcd3bb8a159e6286ba60 100644 (file)
@@ -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.
index eb0ec214926c1ef2983adfe14f7b5deb8ec0012a..80f1ff4f5609f96fb89b053e7fd8f65b863283cb 100644 (file)
 /* 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 */
index 9694af2426995769fff8aedcde26ecbf5edaa7b0..e925128a426346d5586765371fa1b7c908c640d7 100644 (file)
@@ -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
index a8a1fcbc29968f98208690c27a67c4ccd08d3ad0..5d4701cfaccac14b6cce98ab1cb12f6328f2bf0f 100644 (file)
@@ -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;
index fdef3e0d0bf2cfcd54d19d84e73b3abcbe8a82b7..de1a335e40a44c80a75c9ab8ccd0d7c4259084bb 100644 (file)
--- 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
 
This page took 0.033201 seconds and 4 git commands to generate.