Print this page
2676 'mdb -f vmdump.0' ignores the -f
Reviewed by: Robert Mustacchi <rm@joyent.com>
Reviewed by: Richard Lowe <richlowe@richlowe.net>
Reviewed by: Gary Mills <gary_mills@fastmail.fm>


   4  * The contents of this file are subject to the terms of the
   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 /*
  22  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
  23  * Use is subject to license terms.

  24  */
  25 
  26 #include <sys/types.h>
  27 #include <sys/mman.h>
  28 #include <sys/priocntl.h>
  29 #include <sys/rtpriocntl.h>
  30 #include <sys/resource.h>
  31 #include <sys/termios.h>
  32 #include <sys/param.h>
  33 #include <sys/regset.h>
  34 #include <sys/frame.h>
  35 #include <sys/stack.h>
  36 #include <sys/reg.h>
  37 
  38 #include <libproc.h>
  39 #include <libscf.h>
  40 #include <alloca.h>
  41 #include <unistd.h>
  42 #include <string.h>
  43 #include <stdlib.h>


 786          * Find the first argument that is not a special "-" token.  If one is
 787          * found, we will examine this file and make some inferences below.
 788          */
 789         for (c = 0; c < tgt_argc && strcmp(tgt_argv[c], "-") == 0; c++)
 790                 continue;
 791 
 792         if (c < tgt_argc) {
 793                 Elf32_Ehdr ehdr;
 794                 mdb_io_t *io;
 795 
 796                 /*
 797                  * If special "-" tokens preceded an argument, shift the entire
 798                  * argument list to the left to remove the leading "-" args.
 799                  */
 800                 if (c > 0) {
 801                         bcopy(&tgt_argv[c], tgt_argv,
 802                             sizeof (const char *) * (tgt_argc - c));
 803                         tgt_argc -= c;
 804                 }
 805 



 806                 /*
 807                  * If we just have an object file name, and that file doesn't
 808                  * exist, and it's a string of digits, infer it to be a
 809                  * sequence number referring to a pair of crash dump files.
 810                  */
 811                 if (tgt_argc == 1 && access(tgt_argv[0], F_OK) == -1 &&
 812                     strisnum(tgt_argv[0])) {
 813 
 814                         size_t len = strlen(tgt_argv[0]) + 8;
 815                         const char *object = tgt_argv[0];
 816 
 817                         tgt_argv[0] = mdb_alloc(len, UM_SLEEP);
 818                         tgt_argv[1] = mdb_alloc(len, UM_SLEEP);
 819 
 820                         (void) strcpy((char *)tgt_argv[0], "unix.");
 821                         (void) strcat((char *)tgt_argv[0], object);
 822                         (void) strcpy((char *)tgt_argv[1], "vmcore.");
 823                         (void) strcat((char *)tgt_argv[1], object);
 824 
 825                         if (access(tgt_argv[0], F_OK) == -1 &&


 849                 /*
 850                  * Check for a single vmdump.N compressed dump file,
 851                  * and give a helpful message.
 852                  */
 853                 if (tgt_argc == 1) {
 854                         if (mdb_kvm_is_compressed_dump(io)) {
 855                                 mdb_iob_printf(mdb.m_err,
 856                                     "cannot open compressed dump; "
 857                                     "decompress using savecore -f %s\n",
 858                                     tgt_argv[0]);
 859                                 terminate(0);
 860                         }
 861                 }
 862 
 863                 /*
 864                  * If the target is unknown or is not the rawfile target, do
 865                  * a gelf_check to determine if the file is an ELF file.  If
 866                  * it is not and the target is unknown, use the rawfile tgt.
 867                  * Otherwise an ELF-based target is needed, so we must abort.
 868                  */
 869                 if (tgt_ctor != mdb_rawfile_tgt_create &&
 870                     mdb_gelf_check(io, &ehdr, ET_NONE) == -1) {
 871                         if (tgt_ctor != NULL) {
 872                                 (void) mdb_gelf_check(io, &ehdr, ET_EXEC);
 873                                 mdb_io_destroy(io);
 874                                 terminate(1);
 875                         } else
 876                                 tgt_ctor = mdb_rawfile_tgt_create;
 877                 }
 878 
 879                 mdb_io_destroy(io);
 880 
 881                 if (identify_xvm_file(tgt_argv[0], &longmode) == 1 &&
 882                     !fflag) {
 883 #ifdef _LP64
 884                         if (!longmode)
 885                                 goto reexec;
 886 #else
 887                         if (longmode)
 888                                 goto reexec;
 889 #endif
 890                         tgt_ctor = mdb_kvm_tgt_create;
 891                         goto tcreate;
 892                 }
 893 
 894                 if (tgt_ctor == mdb_rawfile_tgt_create)
 895                         goto tcreate; /* skip re-exec and just create target */
 896 
 897                 /*
 898                  * The object file turned out to be a user core file (ET_CORE),
 899                  * and no other arguments were specified, swap 0 and 1.  The
 900                  * proc target will infer the executable for us.
 901                  */
 902                 if (ehdr.e_type == ET_CORE) {
 903                         tgt_argv[tgt_argc++] = tgt_argv[0];
 904                         tgt_argv[0] = NULL;
 905                         tgt_ctor = mdb_proc_tgt_create;
 906                 }
 907 
 908                 /*
 909                  * If tgt_argv[1] is filled in, open it up and determine if it
 910                  * is a vmcore file.  If it is, gelf_check will fail and we
 911                  * set tgt_ctor to 'kvm'; otherwise we use the default.
 912                  */
 913                 if (tgt_argc > 1 && strcmp(tgt_argv[1], "-") != 0 &&
 914                     tgt_argv[0] != NULL && pidarg == NULL) {
 915                         Elf32_Ehdr chdr;
 916 




   4  * The contents of this file are subject to the terms of the
   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 /*
  22  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
  23  * Use is subject to license terms.
  24  * Copyright 2012, Josef 'Jeff' Sipek <jeffpc@31bits.net>. All rights reserved.
  25  */
  26 
  27 #include <sys/types.h>
  28 #include <sys/mman.h>
  29 #include <sys/priocntl.h>
  30 #include <sys/rtpriocntl.h>
  31 #include <sys/resource.h>
  32 #include <sys/termios.h>
  33 #include <sys/param.h>
  34 #include <sys/regset.h>
  35 #include <sys/frame.h>
  36 #include <sys/stack.h>
  37 #include <sys/reg.h>
  38 
  39 #include <libproc.h>
  40 #include <libscf.h>
  41 #include <alloca.h>
  42 #include <unistd.h>
  43 #include <string.h>
  44 #include <stdlib.h>


 787          * Find the first argument that is not a special "-" token.  If one is
 788          * found, we will examine this file and make some inferences below.
 789          */
 790         for (c = 0; c < tgt_argc && strcmp(tgt_argv[c], "-") == 0; c++)
 791                 continue;
 792 
 793         if (c < tgt_argc) {
 794                 Elf32_Ehdr ehdr;
 795                 mdb_io_t *io;
 796 
 797                 /*
 798                  * If special "-" tokens preceded an argument, shift the entire
 799                  * argument list to the left to remove the leading "-" args.
 800                  */
 801                 if (c > 0) {
 802                         bcopy(&tgt_argv[c], tgt_argv,
 803                             sizeof (const char *) * (tgt_argc - c));
 804                         tgt_argc -= c;
 805                 }
 806 
 807                 if (fflag)
 808                         goto tcreate; /* skip re-exec and just create target */
 809 
 810                 /*
 811                  * If we just have an object file name, and that file doesn't
 812                  * exist, and it's a string of digits, infer it to be a
 813                  * sequence number referring to a pair of crash dump files.
 814                  */
 815                 if (tgt_argc == 1 && access(tgt_argv[0], F_OK) == -1 &&
 816                     strisnum(tgt_argv[0])) {
 817 
 818                         size_t len = strlen(tgt_argv[0]) + 8;
 819                         const char *object = tgt_argv[0];
 820 
 821                         tgt_argv[0] = mdb_alloc(len, UM_SLEEP);
 822                         tgt_argv[1] = mdb_alloc(len, UM_SLEEP);
 823 
 824                         (void) strcpy((char *)tgt_argv[0], "unix.");
 825                         (void) strcat((char *)tgt_argv[0], object);
 826                         (void) strcpy((char *)tgt_argv[1], "vmcore.");
 827                         (void) strcat((char *)tgt_argv[1], object);
 828 
 829                         if (access(tgt_argv[0], F_OK) == -1 &&


 853                 /*
 854                  * Check for a single vmdump.N compressed dump file,
 855                  * and give a helpful message.
 856                  */
 857                 if (tgt_argc == 1) {
 858                         if (mdb_kvm_is_compressed_dump(io)) {
 859                                 mdb_iob_printf(mdb.m_err,
 860                                     "cannot open compressed dump; "
 861                                     "decompress using savecore -f %s\n",
 862                                     tgt_argv[0]);
 863                                 terminate(0);
 864                         }
 865                 }
 866 
 867                 /*
 868                  * If the target is unknown or is not the rawfile target, do
 869                  * a gelf_check to determine if the file is an ELF file.  If
 870                  * it is not and the target is unknown, use the rawfile tgt.
 871                  * Otherwise an ELF-based target is needed, so we must abort.
 872                  */
 873                 if (mdb_gelf_check(io, &ehdr, ET_NONE) == -1) {

 874                         if (tgt_ctor != NULL) {
 875                                 (void) mdb_gelf_check(io, &ehdr, ET_EXEC);
 876                                 mdb_io_destroy(io);
 877                                 terminate(1);
 878                         } else
 879                                 tgt_ctor = mdb_rawfile_tgt_create;
 880                 }
 881 
 882                 mdb_io_destroy(io);
 883 
 884                 if (identify_xvm_file(tgt_argv[0], &longmode) == 1) {

 885 #ifdef _LP64
 886                         if (!longmode)
 887                                 goto reexec;
 888 #else
 889                         if (longmode)
 890                                 goto reexec;
 891 #endif
 892                         tgt_ctor = mdb_kvm_tgt_create;
 893                         goto tcreate;
 894                 }
 895 



 896                 /*
 897                  * The object file turned out to be a user core file (ET_CORE),
 898                  * and no other arguments were specified, swap 0 and 1.  The
 899                  * proc target will infer the executable for us.
 900                  */
 901                 if (ehdr.e_type == ET_CORE) {
 902                         tgt_argv[tgt_argc++] = tgt_argv[0];
 903                         tgt_argv[0] = NULL;
 904                         tgt_ctor = mdb_proc_tgt_create;
 905                 }
 906 
 907                 /*
 908                  * If tgt_argv[1] is filled in, open it up and determine if it
 909                  * is a vmcore file.  If it is, gelf_check will fail and we
 910                  * set tgt_ctor to 'kvm'; otherwise we use the default.
 911                  */
 912                 if (tgt_argc > 1 && strcmp(tgt_argv[1], "-") != 0 &&
 913                     tgt_argv[0] != NULL && pidarg == NULL) {
 914                         Elf32_Ehdr chdr;
 915