From: Richard Henderson <rth@twiddle.net>
To: gdb-patches@sources.redhat.com
Subject: [RFA] fix maint space
Date: Sun, 01 Jun 2003 07:03:00 -0000 [thread overview]
Message-ID: <20030601070258.GA29479@twiddle.net> (raw)
Seems awfully dangerous to depend on environ living at some
specific address. Indeed, for alpha-linux it lives in libc.so.
It would seem more robust to either
(1) Just cache the brk at the beginning of execution.
(2) Use a special statistics routine provided by the
malloc implementation, since the heap may be split
into discontiguous pieces.
Here I do the former. Ok?
r~
* top.h (lim_at_start): Declare.
* main.c (captured_main): Set it.
* top.c (lim_at_start): Define.
(command_loop): Use it instead of &environ.
* event-top.c (command_handler): Likewise.
Index: event-top.c
===================================================================
RCS file: /cvs/src/src/gdb/event-top.c,v
retrieving revision 1.26
diff -c -p -d -u -r1.26 event-top.c
--- event-top.c 12 Feb 2003 15:31:30 -0000 1.26
+++ event-top.c 1 Jun 2003 06:56:23 -0000
@@ -492,10 +492,8 @@ command_handler (char *command)
if (display_space)
{
#ifdef HAVE_SBRK
- extern char **environ;
char *lim = (char *) sbrk (0);
-
- space_at_cmd_start = (long) (lim - (char *) &environ);
+ space_at_cmd_start = lim - lim_at_start;
#endif
}
@@ -538,9 +536,8 @@ command_handler (char *command)
if (display_space)
{
#ifdef HAVE_SBRK
- extern char **environ;
char *lim = (char *) sbrk (0);
- long space_now = lim - (char *) &environ;
+ long space_now = lim - lim_at_start;
long space_diff = space_now - space_at_cmd_start;
printf_unfiltered ("Space used: %ld (%c%ld for this command)\n",
@@ -577,9 +574,8 @@ command_line_handler_continuation (struc
if (display_space)
{
#ifdef HAVE_SBRK
- extern char **environ;
char *lim = (char *) sbrk (0);
- long space_now = lim - (char *) &environ;
+ long space_now = lim - lim_at_start;
long space_diff = space_now - space_at_cmd_start;
printf_unfiltered ("Space used: %ld (%c%ld for this command)\n",
Index: main.c
===================================================================
RCS file: /cvs/src/src/gdb/main.c,v
retrieving revision 1.32
diff -c -p -d -u -r1.32 main.c
--- main.c 20 Mar 2003 22:25:16 -0000 1.32
+++ main.c 1 Jun 2003 06:56:24 -0000
@@ -168,6 +168,10 @@ captured_main (void *data)
/* This needs to happen before the first use of malloc. */
init_malloc (NULL);
+#ifdef HAVE_SBRK
+ lim_at_start = (char *) sbrk (0);
+#endif
+
#if defined (ALIGN_STACK_ON_STARTUP)
i = (int) &count & 0x3;
if (i != 0)
Index: top.c
===================================================================
RCS file: /cvs/src/src/gdb/top.c,v
retrieving revision 1.71
diff -c -p -d -u -r1.71 top.c
--- top.c 6 Feb 2003 01:19:12 -0000 1.71
+++ top.c 1 Jun 2003 06:56:26 -0000
@@ -171,6 +171,11 @@ int target_executing = 0;
/* Level of control structure. */
static int control_level;
+/* Sbrk location on entry to main. Used for statistics only. */
+#ifdef HAVE_SBRK
+char *lim_at_start;
+#endif
+
/* Signal to catch ^Z typed while reading a command: SIGTSTP or SIGCONT. */
#ifndef STOP_SIGNAL
@@ -782,10 +787,8 @@ command_loop (void)
if (display_space)
{
#ifdef HAVE_SBRK
- extern char **environ;
char *lim = (char *) sbrk (0);
-
- space_at_cmd_start = (long) (lim - (char *) &environ);
+ space_at_cmd_start = lim - lim_at_start;
#endif
}
@@ -805,9 +808,8 @@ command_loop (void)
if (display_space)
{
#ifdef HAVE_SBRK
- extern char **environ;
char *lim = (char *) sbrk (0);
- long space_now = lim - (char *) &environ;
+ long space_now = lim - lim_at_start;
long space_diff = space_now - space_at_cmd_start;
printf_unfiltered ("Space used: %ld (%c%ld for this command)\n",
Index: top.h
===================================================================
RCS file: /cvs/src/src/gdb/top.h,v
retrieving revision 1.7
diff -c -p -d -u -r1.7 top.h
--- top.h 19 Mar 2002 19:00:04 -0000 1.7
+++ top.h 1 Jun 2003 06:56:26 -0000
@@ -70,5 +70,6 @@ extern char *source_error;
extern char *source_pre_error;
extern int history_expansion_p;
extern int server_command;
+extern char *lim_at_start;
#endif
next reply other threads:[~2003-06-01 7:03 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-06-01 7:03 Richard Henderson [this message]
2003-06-02 14:16 ` Elena Zannoni
2003-06-02 15:56 ` Richard Henderson
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=20030601070258.GA29479@twiddle.net \
--to=rth@twiddle.net \
--cc=gdb-patches@sources.redhat.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