This is the mail archive of the gdb-patches@sources.redhat.com mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

[RFA] Version 2 of patch to add 'maint profile-gdb' command


Here is a minor rewrite of the profiling patch.  I removed the
PARAMS, fixed the NEWS entry, and added a check for moncontrol()
with -pg - if this fails to compile (as it fails on sources.redhat.com),
an error message is spit out and the configure aborts.  If a warning
is desirable, it's a minor change from calling AC_MSG_ERROR to
AC_MSG_WARN, but I found that to be too subtle in my testing (the
warning was lost among the configure output and people would be
confused why their --enable-profiling gdb isn't actually profiling.)
I amended the gdbint.texinfo documentation to note that the gmon.out
file is overwritten each time gdb is started.

The one notable change I did not incorporate was compiling with
-pg, linking without -pg, and using monstartup() to enable the
profiling.  I have two problems with this - one, I _suspect_ (but
I do not know for certain) that linking without -pg and just calling
monstartup() is going to be unportable.  The second problem is
that, off-hand, I don't know how a program should determine the
start and end addresses of its TEXT section portably (which are
required to use monstartup).

I agree that using monstartup() would be convenient, as developers
would not constantly overwrite their existing gmon.out file whenever
they start gdb, but I'd like to see this patch committed and someone
who understands the mechanisms of profiling across different systems
could tackle it in the future.  In my opinion, monstartup() as a nice
refinement which a motivated person could tackle in the future.  I'd
rather not complicate the basic feature with this at this point.
This patch was written nearly two years ago - it'd be good to get
it integrated.

NB - autoconf and autoheader must both be run after applying this patch.

Thanks for your help,

Jason
2000-01-16  Tom Tromey  <tromey@cygnus.com>

        * maint.c (maint_profile_gdb): New function.
        (_initialize_maint_cmds): Add `profile-gdb' command if profiling
        enabled.
        * main.c (captured_main): Call moncontrol if profiling enabled.
        * config.in, configure: Rebuilt.
        * configure.in: Added --enable-profiling.  Define PROFILE_CFLAGS
        and ENABLE_PROFILE as appropriate.
        * acconfig.h (ENABLE_PROFILE): Added.
        * Makefile.in (PROFILE_CFLAGS): Define as @PROFILE_CFLAGS@.
        * gdbint.texinfo (Profiling GDB): New node.
        * NEWS: Mention --enable-profiling.
        * gdb.base/selftest.exp (do_steps_and_nexts): Account for
        possible `moncontrol' call at startup.

Index: Makefile.in
===================================================================
RCS file: /cvs/src/src/gdb/Makefile.in,v
retrieving revision 1.115
diff -u -p -r1.115 Makefile.in
--- Makefile.in	7 Sep 2001 21:27:35 -0000	1.115
+++ Makefile.in	17 Sep 2001 00:34:13 -0000
@@ -314,7 +314,7 @@ GDB_CFLAGS = -I. -I$(srcdir) -I$(srcdir)
 # M{H,T}_CFLAGS, if defined, have host- and target-dependent CFLAGS
 # from the config directory.
 GLOBAL_CFLAGS = $(MT_CFLAGS) $(MH_CFLAGS)
-#PROFILE_CFLAGS = -pg
+PROFILE_CFLAGS = @PROFILE_CFLAGS@
 
 # CFLAGS is specifically reserved for setting from the command line
 # when running make.  I.E.  "make CFLAGS=-Wmissing-prototypes".
Index: NEWS
===================================================================
RCS file: /cvs/src/src/gdb/NEWS,v
retrieving revision 1.33
diff -u -p -r1.33 NEWS
--- NEWS	10 Sep 2001 18:13:17 -0000	1.33
+++ NEWS	17 Sep 2001 00:34:15 -0000
@@ -1,6 +1,15 @@
 		What has changed in GDB?
 	     (Organized release by release)
 
+*** Changes since GDB 5.1:
+
+* Profiling for gdb
+
+If gdb is configured with `--enable-profiling', then gdb is built with
+`-pg' and a new `maintenance profile-gdb' command is created.  This
+command can be used to enable or disable profiling, making it possible
+to profile a single command or set of commands.
+
 *** Changes since GDB 5.0:
 
 * New native configurations
Index: acconfig.h
===================================================================
RCS file: /cvs/src/src/gdb/acconfig.h,v
retrieving revision 1.16
diff -u -p -r1.16 acconfig.h
--- acconfig.h	31 Mar 2001 18:09:02 -0000	1.16
+++ acconfig.h	17 Sep 2001 00:34:15 -0000
@@ -170,3 +170,6 @@
 
 /* nativefile */
 #undef GDB_NM_FILE
+
+/* Define if profiling support should be enabled.  */
+#undef ENABLE_PROFILE
Index: configure.in
===================================================================
RCS file: /cvs/src/src/gdb/configure.in,v
retrieving revision 1.72
diff -u -p -r1.72 configure.in
--- configure.in	6 Sep 2001 20:59:18 -0000	1.72
+++ configure.in	17 Sep 2001 00:34:20 -0000
@@ -46,6 +46,7 @@ CONFIG_DEPS=
 CONFIG_SRCS=
 CONFIG_INITS=
 ENABLE_CFLAGS=
+PROFILE_CFLAGS=
 CONFIG_ALL=
 CONFIG_CLEAN=
 CONFIG_INSTALL=
@@ -654,6 +655,25 @@ if test $want_uiout = true; then
    UIOUT_CFLAGS="-DUI_OUT=1"
 fi
 
+AC_ARG_ENABLE(profiling,
+[  --enable-profiling      Turn on profiling of gdb])
+
+if test "$enable_profiling" = yes; then
+   PROFILE_CFLAGS=-pg
+   OLD_CFLAGS="$CFLAGS"
+   OLD_LDFLAGS="$LDFLAGS"
+   CFLAGS="$CFLAGS $PROFILE_CFLAGS"
+   LDFLAGS="$LDFLAGS $PROFILE_CFLAGS"
+
+   AC_CHECK_FUNC(moncontrol, 
+     AC_DEFINE(ENABLE_PROFILE),
+     AC_MSG_ERROR(moncontrol necessary to use --enable-profiling.);
+     PROFILE_CFLAGS=
+   )
+   CFLAGS="$OLD_CFLAGS"
+   LDFLAGS="$OLD_LDFLAGS"
+fi
+
 AC_ARG_ENABLE(tui,
 [  --enable-tui            Enable full-screen terminal user interface],
 [
@@ -1109,6 +1129,7 @@ AC_SUBST(IGNORE_SIM)
 AC_SUBST(IGNORE_SIM_OBS)
 
 AC_SUBST(ENABLE_CFLAGS)
+AC_SUBST(PROFILE_CFLAGS)
 
 AC_SUBST(CONFIG_OBS)
 AC_SUBST(CONFIG_LIB_OBS)
Index: main.c
===================================================================
RCS file: /cvs/src/src/gdb/main.c,v
retrieving revision 1.12
diff -u -p -r1.12 main.c
--- main.c	14 Jul 2001 18:59:07 -0000	1.12
+++ main.c	17 Sep 2001 00:34:21 -0000
@@ -158,6 +158,10 @@ captured_main (void *data)
 
   long time_at_startup = get_run_time ();
 
+#ifdef ENABLE_PROFILE
+  moncontrol (0);
+#endif
+
   START_PROGRESS (argv[0], 0);
 
 #ifdef MPW
Index: maint.c
===================================================================
RCS file: /cvs/src/src/gdb/maint.c,v
retrieving revision 1.15
diff -u -p -r1.15 maint.c
--- maint.c	11 Apr 2001 01:01:04 -0000	1.15
+++ maint.c	17 Sep 2001 00:34:21 -0000
@@ -60,6 +60,11 @@ static void maintenance_print_command (c
 
 static void maintenance_do_deprecate (char *, int);
 
+#ifdef ENABLE_PROFILE
+static void maint_profile_gdb (char *, int);
+#endif
+
+
 /* Set this to the maximum number of seconds to wait instead of waiting forever
    in target_wait().  If this timer times out, then it generates an error and
    the command is aborted.  This replaces most of the need for timeouts in the
@@ -266,6 +271,26 @@ maintenance_print_statistics (char *args
   print_symbol_bcache_statistics ();
 }
 
+/* "maintenance profile-gdb <on|off>"  */
+static void
+maint_profile_gdb (char *arg, int from_tty)
+{
+#ifdef ENABLE_PROFILE
+  int val;
+  if (arg == NULL || ! *arg)
+    error ("requires argument (\"on\" or \"off\")");
+  if (! strcmp (arg, "on"))
+    val = 1;
+  else if (! strcmp (arg, "off"))
+    val = 0;
+  else
+    error ("unrecognized argument; must be \"on\" or \"off\"");
+  moncontrol (val);
+#else
+  error ("gdb was not configured with --enable-profiling");
+#endif
+}
+
 void
 maintenance_print_architecture (char *args, int from_tty)
 {
@@ -512,6 +537,12 @@ itself a SIGQUIT signal.",
 	   "Give GDB an internal error.\n\
 Cause GDB to behave as if an internal error was detected.",
 	   &maintenancelist);
+
+#ifdef ENABLE_PROFILE
+  add_cmd ("profile-gdb", class_maintenance, maint_profile_gdb,
+	   "Enable or disable profiling.",
+	   &maintenancelist);
+#endif
 
   add_cmd ("demangle", class_maintenance, maintenance_demangle,
 	   "Demangle a C++ mangled name.\n\
Index: doc/gdbint.texinfo
===================================================================
RCS file: /cvs/src/src/gdb/doc/gdbint.texinfo,v
retrieving revision 1.39
diff -u -p -r1.39 gdbint.texinfo
--- doc/gdbint.texinfo	8 Sep 2001 10:53:45 -0000	1.39
+++ doc/gdbint.texinfo	17 Sep 2001 00:34:26 -0000
@@ -4888,6 +4888,7 @@ appear anywhere else in the directory.
 @menu
 * Getting Started::		Getting started working on @value{GDBN}
 * Debugging GDB::		Debugging @value{GDBN} with itself
+* Profiling GDB::               Profiling GDB
 @end menu
 
 @node Getting Started,,, Hints
@@ -4998,6 +4999,35 @@ routines for your local machine where th
 
 Also, make sure that you've either compiled @value{GDBN} with your local cc, or
 have run @code{fixincludes} if you are compiling with gcc.
+
+@node Profiling GDB,,, Hints
+
+@section Profiling GDB
+
+GDB contains some support for profiling itself.  Currently this support
+is rudimentary.
+
+You can configure GDB with @samp{--enable-profiling}.  This does two
+things.  First, it arranges for GDB to be compiled and linked with
+@samp{-pg}.  (This might not work on all platforms; feel free to submit
+patches to fix this for your platform.)  Second, this configure flag
+arranges for the @code{maint profile-gdb} command to be enabled.
+
+@code{maint profile-gdb} takes a single argument, which must be
+@samp{on} or @samp{off}.  This command enables or disables profiling of
+gdb, and can be used to limit profiling to a chosen set of user
+commands.
+
+Note that when configured this way, GDB disables profiling in
+@code{main}.  If you want to profile GDB's initialization code, you will
+have to arrange to build GDB with @code{-pg} but without
+@samp{ENABLE_PROFILE} defined.  
+
+On most systems, a gdb configured with @samp{--enable-profiling} will
+overwrite the profiling log file (often @code{gmon.out}) every time gdb
+is started.  If you have a record of important profiling information in
+your @code{gmon.out} file, be sure to move it to a safe location before
+starting gdb again.
 
 @section Submitting Patches
 
Index: testsuite/gdb.base/selftest.exp
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/gdb.base/selftest.exp,v
retrieving revision 1.2
diff -u -p -r1.2 selftest.exp
--- testsuite/gdb.base/selftest.exp	6 Mar 2001 08:21:51 -0000	1.2
+++ testsuite/gdb.base/selftest.exp	17 Sep 2001 00:34:27 -0000
@@ -99,6 +99,10 @@ proc do_steps_and_nexts {} {
 		set description "next over get_run_time and everything it calls"
 		set command "next"
 	    }
+	    -re ".*moncontrol.*$gdb_prompt $" {
+		set description "next over moncontrol"
+		set command "next"
+	    }
 	    -re ".*START_PROGRESS.*$gdb_prompt $" {
 		set description "next over START_PROGRESS and everything it calls"
 		set command "next"

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]