[2/2] darwin: Don't use sbrk
Commit Message
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(-)
Comments
On 07/04/2018 05:30 AM, Simon Marchi wrote:
> This patch gets rid of this warning on macOS:
>
> 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.
>
> --- 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;
>
Suggest adding a comment here based on what you had in the intro:
/* 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
Thanks,
Pedro Alves
On 2018-07-04 06:49, Pedro Alves wrote:
> On 07/04/2018 05:30 AM, Simon Marchi wrote:
>> This patch gets rid of this warning on macOS:
>>
>
>> 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.
>>
>
>> --- 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;
>>
>
> Suggest adding a comment here based on what you had in the intro:
>
> /* 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. */
Of course, that's a good idea. Otherwise somebody will curse in 10
years, wondering why we did this, just like we did for the #if
__APPLE_CC__ in gettext :). I'm pushing with that added, thanks for
providing the comment.
Simon
@@ -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 */
@@ -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
@@ -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;
@@ -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