From owner-freebsd-current Mon Aug 24 02:18:44 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id CAA23815 for freebsd-current-outgoing; Mon, 24 Aug 1998 02:18:44 -0700 (PDT) (envelope-from owner-freebsd-current@FreeBSD.ORG) Received: from baerenklau.de.freebsd.org (baerenklau.de.freebsd.org [195.185.195.14]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id CAA23809 for ; Mon, 24 Aug 1998 02:18:41 -0700 (PDT) (envelope-from wosch@panke.de.freebsd.org) Received: (from uucp@localhost) by baerenklau.de.freebsd.org (8.8.8/8.8.8) with UUCP id LAA10715 for current@freebsd.org; Mon, 24 Aug 1998 11:17:55 +0200 (CEST) (envelope-from wosch@panke.de.freebsd.org) Received: (from wosch@localhost) by campa.panke.de (8.8.8/8.8.8) id VAA04727; Sun, 23 Aug 1998 21:06:24 +0200 (MET DST) (envelope-from wosch) Date: Sun, 23 Aug 1998 21:06:24 +0200 (MET DST) Message-Id: <199808231906.VAA04727@campa.panke.de> From: Wolfram Schneider To: current@FreeBSD.ORG Subject: file segment sizes of a core dump MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit Sender: owner-freebsd-current@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG I added an option to size(1) which print the file segment sizes of a core dump. For example: $ ./size /bin/sh text data bss dec hex 294912 12288 35656 342856 53b48 $ ./size -c sh.core text data bss dec hex 294912 69632 131072 495616 79000 If nobody objects I will commit the change. Index: size.1 =================================================================== RCS file: /usr/cvs/src/usr.bin/size/size.1,v retrieving revision 1.3 diff -u -r1.3 size.1 --- size.1 1997/08/11 07:28:18 1.3 +++ size.1 1998/08/23 17:13:04 @@ -39,6 +39,7 @@ .Nd display object file segment sizes (text, data and bss) .Sh SYNOPSIS .Nm size +.Op Fl c .Op Ar object_file ... .Sh DESCRIPTION .Nm Size @@ -52,8 +53,20 @@ .Nm attempts to report on the file .Pa a.out . +.Pp +The options are as follows: +.Bl -tag -width indent +.It Fl c +Print the size of a +.Ar core dump +file instead a +.Ar object_file . +.El +.Pp .Sh SEE ALSO +.Xr gcore 1 .Xr a.out 5 +.Xr core 5 .Sh HISTORY A .Nm Index: size.c =================================================================== RCS file: /usr/cvs/src/usr.bin/size/size.c,v retrieving revision 1.4 diff -u -r1.4 size.c --- size.c 1998/07/06 21:01:32 1.4 +++ size.c 1998/08/23 18:58:03 @@ -47,6 +47,9 @@ #include #include +#include +#include +#include #include #include #include @@ -57,6 +60,8 @@ int show __P((int, char *)); static void usage __P((void)); +int coredumpsize; /* run as coredumpsize(1) command */ + int main(argc, argv) int argc; @@ -64,8 +69,11 @@ { int ch, eval; - while ((ch = getopt(argc, argv, "")) != -1) + while ((ch = getopt(argc, argv, "c")) != -1) switch(ch) { + case 'c': + coredumpsize = 1; + break; case '?': default: usage(); @@ -90,6 +98,8 @@ { static int first = 1; struct exec head; + struct user user; + struct stat stat; u_long total; int fd; @@ -97,20 +107,47 @@ warn("%s", name); return (1); } - if (read(fd, &head, sizeof(head)) != sizeof(head) || N_BADMAG(head)) { - (void)close(fd); - warnx("%s: not in a.out format", name); - return (1); + + if (!coredumpsize) { + if (read(fd, &head, sizeof(head)) != sizeof(head) || + N_BADMAG(head)) { + (void)close(fd); + warnx("%s: not in a.out format", name); + return (1); + } + } else { + if (read(fd, &user, sizeof(user)) != sizeof(user) || + fstat(fd, &stat) == -1) { + (void)close(fd); + warnx("%s: not in core format", name); + return (1); + } + if (stat.st_size < ptoa(UPAGES + user.u_dsize + user.u_ssize)) { + warnx("%s: seems not to be a valid core dump file", name); + close(fd); + return(1); + } } (void)close(fd); if (first) { first = 0; (void)printf("text\tdata\tbss\tdec\thex\n"); + } + + if (!coredumpsize) { + total = head.a_text + head.a_data + head.a_bss; + (void)printf("%lu\t%lu\t%lu\t%lu\t%lx", (u_long)head.a_text, + (u_long)head.a_data, (u_long)head.a_bss, total, total); + } else { + total = ptoa(user.u_tsize) + ptoa(user.u_dsize) + + ptoa(user.u_ssize); + (void)printf("%lu\t%lu\t%lu\t%lu\t%lx", + (u_long)ptoa(user.u_tsize), + (u_long)ptoa(user.u_dsize), + (u_long)ptoa(user.u_ssize), total, total); } - total = head.a_text + head.a_data + head.a_bss; - (void)printf("%lu\t%lu\t%lu\t%lu\t%lx", (u_long)head.a_text, - (u_long)head.a_data, (u_long)head.a_bss, total, total); + if (count > 1) (void)printf("\t%s", name); (void)printf("\n"); @@ -120,6 +157,6 @@ static void usage() { - (void)fprintf(stderr, "usage: size [file ...]\n"); + (void)fprintf(stderr, "usage: size [-c] [file ...]\n"); exit(1); } -- Wolfram Schneider http://www.freebsd.org/~w/ To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-current" in the body of the message