Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [RFA] patch to add 'maint profile-gdb' command
@ 2001-09-10  0:30 Jason Molenda
  2001-09-10  8:48 ` Andrew Cagney
  0 siblings, 1 reply; 64+ messages in thread
From: Jason Molenda @ 2001-09-10  0:30 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

This is a refresh of Tom Tromey's gdb profiling patch, originally here:
	http://sources.redhat.com/ml/gdb-patches/2000-q1/msg00022.html

Instead of profiling all of gdb, Tom's patch lets you profile a
specific command (or commands).  You enable profiling with the
'maint profile-gdb on' before the command(s) of interest, and
'maint profile-gdb off' (or exit) when you're finished.

configure and config.in both need to be regenerated after applying
this patch.  Your build must be compiled with --enable-profiling
for this feature to be enabled.

My only comments on this patch are (1) the documentation entry
could note that your gmon.out file will be overwritten each time
gdb is started, even if you don't do a profile-gdb on command[1], and
(2) the configure.in check for $enable_profiling could be embedded
in the AC_ARG_ENABLE() autoconf call.  It doesn't make any practical
difference, but it looks like tradition in gdb's configure.in is
to include this code inside the AC_ARG_ENABLE call.

 [1]  A bit of profiling happens before it can be turned
      off in captured_main().  This initial profiling will overwrite
      away any existing gmon.out.  At least it does with the gprof
      on Linux and FreeBSD systems.

No testsuite regressions are added with this patch.

This patch does not require approval for the 5.1 branch - it is
not something end users have cause to enable.

This patch does add a couple of ifdefs in main.c, aint.c to guard
the code, but this is necessary.  Obviously you can't compile in
profiling all the time (performance, portability), and you can't
make calls to the profiling system calls if you aren't compiling
-pg.

Jason
From jason-swarelist@molenda.com Mon Sep 10 00:36:00 2001
From: Jason Molenda <jason-swarelist@molenda.com>
To: gdb-patches@sources.redhat.com
Subject: Typeo in NEWS
Date: Mon, 10 Sep 2001 00:36:00 -0000
Message-id: <20010910003611.A22499@shell17.ba.best.com>
X-SW-Source: 2001-09/msg00126.html
Content-length: 249

The NEWS file claims that gdb's code has been converted to "ANS/ISO C".
It should either be "ANSI/ISO C", or more correctly, just "ISO C".  

I won't argue strenuously for "ISO" over "ANSI/ISO", but the patch
I'm including implements the latter.

J
From eliz@is.elta.co.il Mon Sep 10 00:50:00 2001
From: Eli Zaretskii <eliz@is.elta.co.il>
To: Jason Molenda <jason-swarelist@molenda.com>
Cc: gdb-patches@sources.redhat.com, Tom Tromey <tromey@cygnus.com>
Subject: Re: [RFA] patch to add 'maint profile-gdb' command
Date: Mon, 10 Sep 2001 00:50:00 -0000
Message-id: <Pine.SUN.3.91.1010910094003.18194H-100000@is>
References: <20010910003022.A21681@shell17.ba.best.com>
X-SW-Source: 2001-09/msg00127.html
Content-length: 1698

On Mon, 10 Sep 2001, Jason Molenda wrote:

> This is a refresh of Tom Tromey's gdb profiling patch, originally here:
> 	http://sources.redhat.com/ml/gdb-patches/2000-q1/msg00022.html

Thanks!  I think it's a very useful feature, but I have a few minor 
comments.

> My only comments on this patch are (1) the documentation entry
> could note that your gmon.out file will be overwritten each time
> gdb is started, even if you don't do a profile-gdb on command[1], and
> (2) the configure.in check for $enable_profiling could be embedded
> in the AC_ARG_ENABLE() autoconf call.  It doesn't make any practical
> difference, but it looks like tradition in gdb's configure.in is
> to include this code inside the AC_ARG_ENABLE call.
> 
>  [1]  A bit of profiling happens before it can be turned
>       off in captured_main().  This initial profiling will overwrite
>       away any existing gmon.out.  At least it does with the gprof
>       on Linux and FreeBSD systems.

Isn't it better to use monstartup instead of moncontrol and -pg?  It 
looks like using monstartup could solve several problems:

  - you don't overwrite gmon.out unless you actually profile
  - you can link without -pg
  - you can make this option available by default, since it is invisible 
    unless you actually profile (I dislike features that require a 
    rebuild to become available)

We will have to add Autoconf tests to see if monstartup is available, but 
I think using moncontrol if --enable-profiling is given is not safe 
enough anyway.

In addition, I think the commands this patch adds should be documented in 
gdb.texinfo as well, since all commands one can type at GDB's prompt 
should be described there.


^ permalink raw reply	[flat|nested] 64+ messages in thread
* Re: [4/7] Adjust the ttrace target (HP-UX) to always register the main thread
@ 2008-08-08 17:24 Pedro Alves
  2008-08-08 18:34 ` ttrace: Protocal error John David Anglin
  0 siblings, 1 reply; 64+ messages in thread
From: Pedro Alves @ 2008-08-08 17:24 UTC (permalink / raw)
  To: gdb-patches; +Cc: John David Anglin

[-- Attachment #1: Type: text/plain, Size: 1239 bytes --]

Thanks a lot John,

On Friday 08 August 2008 17:40:13, John David Anglin wrote:

> (gdb) bt
> #0  0x000c9960 in inf_ttrace_delete_dying_threads_callback
> (info=0x4007bdb0, arg=0x0) at ../../src/gdb/inf-ttrace.c:828
> #1  0x0008b640 in iterate_over_threads (
>     callback=@0x4001a712: 0xc9940
> <inf_ttrace_delete_dying_threads_callback>, data=0x0) at
> ../../src/gdb/thread.c:338
> #2  0x000c98e0 in inf_ttrace_resume (ptid=
>       {pid = 0, lwp = 16961, tid = 7024758}, step=1073949720,
>     signal=TARGET_SIGNAL_0) at ../../src/gdb/inf-ttrace.c:854
> #3  0x000a3390 in target_resume (ptid={pid = 0, lwp = 16961, tid =
> 7024758}, step=0, signal=TARGET_SIGNAL_0) at ../../src/gdb/target.c:1789 #4
>  0x00087f88 in resume (step=0, sig=TARGET_SIGNAL_0)
>     at ../../src/gdb/infrun.c:1123
> #5  0x000c6db8 in startup_inferior (ntraps=1074249136)

I wasn't setting the private thread info in the main thread
in inf_ttrace_wait, when getting there from a fork_inferior; but, I
was setting it on inf_ttrace_attach.  Since this is a
!target_attach_no_wait target (there's always a target_wait
after an attach), I just moved the setting of the private
info always to inf_ttrace_wait.

Could you check this version please?

-- 
Pedro Alves

[-- Attachment #2: 004-ttrace_always_a_thread.diff --]
[-- Type: text/x-diff, Size: 5618 bytes --]

2008-08-08  Pedro Alves  <pedro@codesourcery.com>

	* inf-ttrace.c (inf_ttrace_follow_fork): Register the main thread
	of the child fork.
	(inf_ttrace_attach): Add the main thread.
	(inf_ttrace_resume_callback): Check for exited threads.  Adjust
	for always a thread.
	(inf_ttrace_wait): Decorate the main thread's ptid with lwp info
	using thread_change_ptid, and set its private data.  Don't add the
	main thread here.
	(inf_ttrace_pid_to_str): Adjust.

---
 gdb/inf-ttrace.c |   86 +++++++++++++++++++++++++++++++++++--------------------
 1 file changed, 55 insertions(+), 31 deletions(-)

Index: src/gdb/inf-ttrace.c
===================================================================
--- src.orig/gdb/inf-ttrace.c	2008-08-08 13:43:19.000000000 +0100
+++ src/gdb/inf-ttrace.c	2008-08-08 18:17:50.000000000 +0100
@@ -513,10 +513,22 @@ Detaching after fork from child process 
 
   if (follow_child)
     {
+      struct thread_info *ti;
+
       /* The child will start out single-threaded.  */
-      inf_ttrace_num_lwps = 0;
+      inf_ttrace_num_lwps = 1;
       inf_ttrace_num_lwps_in_syscall = 0;
 
+      /* Delete parent.  */
+      delete_thread_silent (ptid_build (pid, lwpid, 0));
+
+      /* Add child.  inferior_ptid was already set above.  */
+      ti = add_thread_silent (inferior_ptid);
+      ti->private =
+	xmalloc (sizeof (struct inf_ttrace_private_thread_info));
+      memset (ti->private, 0,
+	      sizeof (struct inf_ttrace_private_thread_info));
+
       /* Reset breakpoints in the child as appropriate.  */
       follow_inferior_reset_breakpoints ();
     }
@@ -721,8 +733,13 @@ inf_ttrace_attach (char *args, int from_
 	      (uintptr_t)&tte, sizeof tte, 0) == -1)
     perror_with_name (("ttrace"));
 
-  inferior_ptid = pid_to_ptid (pid);
   push_target (ttrace_ops_hack);
+
+  /* We'll bump inf_ttrace_num_lwps up and add the private data to the
+     thread as soon as we get to inf_ttrace_wait.  At this point, we
+     don't have lwpid info yet.  */
+  inferior_ptid = pid_to_ptid (pid);
+  add_thread_silent (inferior_ptid);
 }
 
 static void
@@ -787,7 +804,7 @@ inf_ttrace_kill (void)
 static int
 inf_ttrace_resume_callback (struct thread_info *info, void *arg)
 {
-  if (!ptid_equal (info->ptid, inferior_ptid))
+  if (!ptid_equal (info->ptid, inferior_ptid) && !is_exited (info->ptid))
     {
       pid_t pid = ptid_get_pid (info->ptid);
       lwpid_t lwpid = ptid_get_lwp (info->ptid);
@@ -824,7 +841,7 @@ inf_ttrace_resume (ptid_t ptid, int step
   if (ttrace (request, pid, lwpid, TT_NOPC, sig, 0) == -1)
     perror_with_name (("ttrace"));
 
-  if (ptid_equal (ptid, minus_one_ptid) && inf_ttrace_num_lwps > 0)
+  if (ptid_equal (ptid, minus_one_ptid))
     {
       /* Let all the other threads run too.  */
       iterate_over_threads (inf_ttrace_resume_callback, NULL);
@@ -886,6 +903,30 @@ inf_ttrace_wait (ptid_t ptid, struct tar
 
   ptid = ptid_build (tts.tts_pid, tts.tts_lwpid, 0);
 
+  if (inf_ttrace_num_lwps == 0)
+    {
+      struct thread_info *ti;
+
+      inf_ttrace_num_lwps = 1;
+
+      /* This is the earliest we hear about the lwp member of
+	 INFERIOR_PTID, after an attach or fork_inferior.  */
+      gdb_assert (ptid_get_lwp (inferior_ptid) == 0);
+
+      /* We haven't set the private member on the main thread yet.  Do
+	 it now.  */
+      ti = find_thread_pid (inferior_ptid);
+      gdb_assert (ti != NULL && ti->private == NULL);
+      ti->private =
+	xmalloc (sizeof (struct inf_ttrace_private_thread_info));
+      memset (ti->private, 0,
+	      sizeof (struct inf_ttrace_private_thread_info));
+
+      /* Notify the core that this ptid changed.  This changes
+	 inferior_ptid as well.  */
+      thread_change_ptid (inferior_ptid, ptid);
+    }
+
   switch (tts.tts_event)
     {
 #ifdef TTEVT_BPT_SSTEP
@@ -958,17 +999,6 @@ inf_ttrace_wait (ptid_t ptid, struct tar
     case TTEVT_LWP_CREATE:
       lwpid = tts.tts_u.tts_thread.tts_target_lwpid;
       ptid = ptid_build (tts.tts_pid, lwpid, 0);
-      if (inf_ttrace_num_lwps == 0)
-	{
-	  /* Now that we're going to be multi-threaded, add the
-	     original thread to the list first.  */
-	  ti = add_thread (ptid_build (tts.tts_pid, tts.tts_lwpid, 0));
-	  ti->private =
-	    xmalloc (sizeof (struct inf_ttrace_private_thread_info));
-	  memset (ti->private, 0,
-		  sizeof (struct inf_ttrace_private_thread_info));
-	  inf_ttrace_num_lwps++;
-	}
       ti = add_thread (ptid);
       ti->private =
 	xmalloc (sizeof (struct inf_ttrace_private_thread_info));
@@ -1045,11 +1075,6 @@ inf_ttrace_wait (ptid_t ptid, struct tar
   if (ttrace (TT_PROC_STOP, tts.tts_pid, 0, 0, 0, 0) == -1)
     perror_with_name (("ttrace"));
 
-  /* HACK: Twiddle INFERIOR_PTID such that the initial thread of a
-     process isn't recognized as a new thread.  */
-  if (ptid_get_lwp (inferior_ptid) == 0)
-    inferior_ptid = ptid;
-
   return ptid;
 }
 
@@ -1128,18 +1153,17 @@ inf_ttrace_thread_alive (ptid_t ptid)
 static char *
 inf_ttrace_pid_to_str (ptid_t ptid)
 {
-  if (inf_ttrace_num_lwps > 0)
-    {
-      pid_t pid = ptid_get_pid (ptid);
-      lwpid_t lwpid = ptid_get_lwp (ptid);
-      static char buf[128];
-
-      xsnprintf (buf, sizeof buf, "process %ld, lwp %ld",
-		 (long)pid, (long)lwpid);
-      return buf;
-    }
+  pid_t pid = ptid_get_pid (ptid);
+  lwpid_t lwpid = ptid_get_lwp (ptid);
+  static char buf[128];
 
-  return normal_pid_to_str (ptid);
+  if (lwpid == 0)
+    xsnprintf (buf, sizeof buf, "process %ld",
+	       (long) pid);
+  else
+    xsnprintf (buf, sizeof buf, "process %ld, lwp %ld",
+	       (long) pid, (long) lwpid);
+  return buf;
 }
 \f
 

^ permalink raw reply	[flat|nested] 64+ messages in thread

end of thread, other threads:[~2008-09-15  2:24 UTC | newest]

Thread overview: 64+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-09-10  0:30 [RFA] patch to add 'maint profile-gdb' command Jason Molenda
2001-09-10  8:48 ` Andrew Cagney
2001-09-10  8:58   ` Eli Zaretskii
2001-09-10  9:04     ` Andrew Cagney
2001-09-10 11:52   ` Jason Molenda
2001-09-10 13:43     ` Eli Zaretskii
2001-09-10 13:59       ` Jason Molenda
2001-09-11  0:38         ` Eli Zaretskii
     [not found]           ` <no.id>
1999-06-15 20:10             ` Missing routines: gdb/top.c John David Anglin
2001-09-11  1:37             ` [RFA] patch to add 'maint profile-gdb' command Jason Molenda
2001-09-11  1:57               ` Eli Zaretskii
2001-09-12  0:00             ` Jason Molenda
2001-09-12  6:00               ` Eli Zaretskii
2001-09-12  7:42                 ` Jason Molenda
2001-09-12  9:06                   ` Eli Zaretskii
2001-09-12 11:58                     ` Tom Tromey
2001-09-12 13:16                       ` Jason Molenda
2008-08-06 19:24             ` [patch] Don't set DT_HP_DEBUG_PRIVATE in solib-pa64.c John David Anglin
2008-08-06 19:49               ` Mark Kettenis
2008-08-06 20:09                 ` John David Anglin
2008-08-06 23:10                 ` John David Anglin
2008-08-07 21:39               ` [patch] Only force private mapping of shared libraries in solib-som.c on HP-UX 10 and earlier John David Anglin
2008-08-08 10:48                 ` Joel Brobecker
2008-08-08 15:34                   ` John David Anglin
2008-08-09 14:37                     ` Joel Brobecker
2008-08-09 18:59                       ` John David Anglin
2008-08-08 19:30             ` ttrace: Protocal error John David Anglin
2008-08-08 20:16               ` John David Anglin
2008-08-09 14:52                 ` Pedro Alves
2008-08-09 15:34                   ` John David Anglin
2008-08-09 18:49                   ` John David Anglin
2008-08-09 22:45                     ` Pedro Alves
2008-08-09 22:46                   ` Pedro Alves
2008-08-09 22:51                     ` Pedro Alves
2008-08-09 23:19                       ` John David Anglin
2008-08-09 22:48                   ` Pedro Alves
2008-08-09 14:53                 ` Joel Brobecker
2008-08-09 23:40             ` John David Anglin
2008-08-10  0:46             ` [4/7] Adjust the ttrace target (HP-UX) to always register the John David Anglin
2008-09-15  2:08             ` [PATCH] Fix dwarf register column to gdb register mapping John David Anglin
2008-09-15  2:24             ` [PATCH] Fix hppa_linux_sigtramp_frame_unwind_cache John David Anglin
2001-09-12 11:28     ` [RFA] patch to add 'maint profile-gdb' command Andrew Cagney
2001-09-12 11:43     ` Andrew Cagney
2001-09-16 17:45       ` [RFA] Version 2 of " Jason Molenda
     [not found]         ` <200109170536.HAA21988@is.elta.co.il>
2001-09-17 15:08           ` Michael Snyder
2001-09-17 22:43           ` Andrew Cagney
2001-09-17 23:59             ` Eli Zaretskii
2001-09-24 13:33               ` Jason Molenda
2001-09-24 14:41                 ` Andrew Cagney
2001-09-24 14:58                   ` Eli Zaretskii
2001-09-24 15:13                     ` Andrew Cagney
2001-09-24 14:53                 ` Eli Zaretskii
2001-09-17 22:39         ` Andrew Cagney
2001-09-18 17:52           ` Fernando Nasser
2001-09-18 17:56             ` Andrew Cagney
2001-09-19  7:11               ` Fernando Nasser
2001-09-19  7:28                 ` Eli Zaretskii
2001-09-19  9:29                   ` Fernando Nasser
2001-09-19 11:30                     ` Eli Zaretskii
2001-09-19 11:41                     ` Andrew Cagney
2001-09-19 11:53                     ` Kevin Buettner
2008-08-08 17:24 [4/7] Adjust the ttrace target (HP-UX) to always register the main thread Pedro Alves
2008-08-08 18:34 ` ttrace: Protocal error John David Anglin
2008-08-08 20:02   ` Pedro Alves
2008-08-08 20:49     ` John David Anglin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox