From owner-svn-src-all@FreeBSD.ORG Wed Jul 14 17:16:25 2010 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 9F0BB106566C; Wed, 14 Jul 2010 17:16:25 +0000 (UTC) (envelope-from attilio@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 8E0E58FC15; Wed, 14 Jul 2010 17:16:25 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id o6EHGPww028690; Wed, 14 Jul 2010 17:16:25 GMT (envelope-from attilio@svn.freebsd.org) Received: (from attilio@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o6EHGPga028685; Wed, 14 Jul 2010 17:16:25 GMT (envelope-from attilio@svn.freebsd.org) Message-Id: <201007141716.o6EHGPga028685@svn.freebsd.org> From: Attilio Rao Date: Wed, 14 Jul 2010 17:16:25 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r210063 - head/usr.bin/gcore X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 14 Jul 2010 17:16:25 -0000 Author: attilio Date: Wed Jul 14 17:16:25 2010 New Revision: 210063 URL: http://svn.freebsd.org/changeset/base/210063 Log: 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. This might be used very carefully as, among the reported segments, there could be memory mapped areas that could be vital to program execution. Sponsored by: Sandvine Incorporated Discussed with: kib Reviewed by: emaste Tested by: Sandvine Incorporated MFC after: 2 weeks Modified: head/usr.bin/gcore/elfcore.c head/usr.bin/gcore/extern.h head/usr.bin/gcore/gcore.1 head/usr.bin/gcore/gcore.c Modified: head/usr.bin/gcore/elfcore.c ============================================================================== --- head/usr.bin/gcore/elfcore.c Wed Jul 14 16:31:22 2010 (r210062) +++ head/usr.bin/gcore/elfcore.c Wed Jul 14 17:16:25 2010 (r210063) @@ -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: head/usr.bin/gcore/extern.h ============================================================================== --- head/usr.bin/gcore/extern.h Wed Jul 14 16:31:22 2010 (r210062) +++ head/usr.bin/gcore/extern.h Wed Jul 14 17:16:25 2010 (r210063) @@ -34,8 +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 sflag; +extern int pflags; Modified: head/usr.bin/gcore/gcore.1 ============================================================================== --- head/usr.bin/gcore/gcore.1 Wed Jul 14 16:31:22 2010 (r210062) +++ head/usr.bin/gcore/gcore.1 Wed Jul 14 17:16:25 2010 (r210063) @@ -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. . +.It Fl f +Dumps all the available segments, excluding only the malformed ones and +un-dumpable ones. Differently from the default invocation, it also dumps +device-mapped and sglist-mapped areas that may invalidate the state of +some transactions. This flag, then, may be used very carefully, when the +full behaviour of the application is full-understood and the fallouts can +be easilly controlled. .It Fl s Stop the process while gathering the core image, and resume it when done. Modified: head/usr.bin/gcore/gcore.c ============================================================================== --- head/usr.bin/gcore/gcore.c Wed Jul 14 16:31:22 2010 (r210062) +++ head/usr.bin/gcore/gcore.c Wed Jul 14 17:16:25 2010 (r210063) @@ -71,7 +71,7 @@ __FBSDID("$FreeBSD$"); #include #include "extern.h" -int sflag; +int pflags; static void killed(int); static void usage(void) __dead2; @@ -89,15 +89,18 @@ main(int argc, char *argv[]) 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();