Author: attilio
Date: Wed Jul 28 16:10:21 2010
New Revision: 210567
URL: http://svn.freebsd.org/changeset/base/210567

Log:
  MFC r210063, r210065:
  Fix the way the segments are included in the gcore outputs (with the
  default invokation):
  - Right now if segments are not writable are not included. Remove this.
  - Right now if a segment is mapped with NOCORE the check is not honoured.
     Change this by checking the newly added flag, from libutil,
     KVME_FLAG_NOCOREDUMP.
  
  Besides that, add a new flag (-f) that forces a 'full' dump of all the
  segments excluding just the malformed ones.
  
  Sponsored by: Sandvine Incorporated

Modified:
  stable/8/usr.bin/gcore/elfcore.c
  stable/8/usr.bin/gcore/extern.h
  stable/8/usr.bin/gcore/gcore.1
  stable/8/usr.bin/gcore/gcore.c
Directory Properties:
  stable/8/usr.bin/gcore/   (props changed)

Modified: stable/8/usr.bin/gcore/elfcore.c
==============================================================================
--- stable/8/usr.bin/gcore/elfcore.c    Wed Jul 28 15:55:14 2010        
(r210566)
+++ stable/8/usr.bin/gcore/elfcore.c    Wed Jul 28 16:10:21 2010        
(r210567)
@@ -488,12 +488,17 @@ readmap(pid_t pid)
                kve = &vmentl[i];
 
                /*
-                * Ignore segments of the wrong kind and ones which are not
-                * readable and writable.
+                * Ignore 'malformed' segments or ones representing memory
+                * mapping with MAP_NOCORE on.
+                * If the 'full' support is disabled, just dump the most
+                * meaningful data segments.
                 */
-               if ((kve->kve_protection & KVME_PROT_WRITE) == 0 ||
-                   (kve->kve_protection & KVME_PROT_READ) == 0 ||
-                   (kve->kve_type != KVME_TYPE_DEFAULT &&
+               if ((kve->kve_protection & KVME_PROT_READ) == 0 ||
+                   (kve->kve_flags & KVME_FLAG_NOCOREDUMP) != 0 ||
+                   kve->kve_type == KVME_TYPE_DEAD ||
+                   kve->kve_type == KVME_TYPE_UNKNOWN ||
+                   ((pflags & PFLAGS_FULL) == 0 &&
+                   kve->kve_type != KVME_TYPE_DEFAULT &&
                    kve->kve_type != KVME_TYPE_VNODE &&
                    kve->kve_type != KVME_TYPE_SWAP))
                        continue;

Modified: stable/8/usr.bin/gcore/extern.h
==============================================================================
--- stable/8/usr.bin/gcore/extern.h     Wed Jul 28 15:55:14 2010        
(r210566)
+++ stable/8/usr.bin/gcore/extern.h     Wed Jul 28 16:10:21 2010        
(r210567)
@@ -34,7 +34,11 @@
  * $FreeBSD$
  */
 
+#define        PFLAGS_FULL     0x01
+#define        PFLAGS_RESUME   0x02
+
 struct dumpers {
        int (*ident)(int efd, pid_t pid, char *binfile);
        void (*dump)(int efd, int fd, pid_t pid);
 };
+extern int pflags;

Modified: stable/8/usr.bin/gcore/gcore.1
==============================================================================
--- stable/8/usr.bin/gcore/gcore.1      Wed Jul 28 15:55:14 2010        
(r210566)
+++ stable/8/usr.bin/gcore/gcore.1      Wed Jul 28 16:10:21 2010        
(r210567)
@@ -32,7 +32,7 @@
 .\"    @(#)gcore.1     8.2 (Berkeley) 4/18/94
 .\" $FreeBSD$
 .\"
-.Dd November 18, 2009
+.Dd July 14, 2010
 .Dt GCORE 1
 .Os
 .Sh NAME
@@ -40,6 +40,7 @@
 .Nd get core images of running process
 .Sh SYNOPSIS
 .Nm
+.Op Fl f
 .Op Fl s
 .Op Fl c Ar core
 .Op Ar executable
@@ -61,6 +62,13 @@ The following options are available:
 .It Fl c
 Write the core file to the specified file instead of
 .Dq Pa core.<pid> .
+.It Fl f
+Dumps all the available segments, excluding only the malformed ones and
+un-dumpable ones. Unlike the default invocation, it also dumps
+device- and sglist-mapped areas that may invalidate the state of
+some transactions. This flag must be used very carefully, when the
+behavior of the application is fully understood and the fallouts can
+be easily controlled.
 .It Fl s
 Stop the process while gathering the core image, and resume it
 when done.

Modified: stable/8/usr.bin/gcore/gcore.c
==============================================================================
--- stable/8/usr.bin/gcore/gcore.c      Wed Jul 28 15:55:14 2010        
(r210566)
+++ stable/8/usr.bin/gcore/gcore.c      Wed Jul 28 16:10:21 2010        
(r210567)
@@ -72,6 +72,7 @@ __FBSDID("$FreeBSD$");
 #include <unistd.h>
 
 #include "extern.h"
+int pflags;
 
 static void    killed(int);
 static void    restart_target(void);
@@ -84,21 +85,24 @@ SET_DECLARE(dumpset, struct dumpers);
 int
 main(int argc, char *argv[])
 {
-       int ch, efd, fd, name[4], sflag;
+       int ch, efd, fd, name[4];
        char *binfile, *corefile;
        char passpath[MAXPATHLEN], fname[MAXPATHLEN];
        struct dumpers **d, *dumper;
        size_t len;
 
-       sflag = 0;
+       pflags = 0;
        corefile = NULL;
-        while ((ch = getopt(argc, argv, "c:s")) != -1) {
+        while ((ch = getopt(argc, argv, "c:fs")) != -1) {
                 switch (ch) {
                 case 'c':
                        corefile = optarg;
                         break;
+               case 'f':
+                       pflags |= PFLAGS_FULL;
+                       break;
                case 's':
-                       sflag = 1;
+                       pflags |= PFLAGS_RESUME;
                        break;
                default:
                        usage();
@@ -148,7 +152,7 @@ main(int argc, char *argv[])
        fd = open(corefile, O_RDWR|O_CREAT|O_TRUNC, DEFFILEMODE);
        if (fd < 0)
                err(1, "%s", corefile);
-       if (sflag) {
+       if ((pflags & PFLAGS_RESUME) != 0) {
                signal(SIGHUP, killed);
                signal(SIGINT, killed);
                signal(SIGTERM, killed);
_______________________________________________
svn-src-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to