Print this page
10132 smatch fixes for MDB
Reviewed by: Andy Fiddaman <andy@omniosce.org>


   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 2008 Sun Microsystems, Inc.  All rights reserved.
  23  * Use is subject to license terms.
  24  */
  25 




  26 #include <sys/elf.h>
  27 #include <sys/elf_SPARC.h>
  28 
  29 #include <libproc.h>
  30 #include <libctf.h>
  31 #include <stdlib.h>
  32 #include <string.h>
  33 #include <fcntl.h>
  34 #include <errno.h>
  35 
  36 #include <mdb/mdb_string.h>
  37 #include <mdb/mdb_argvec.h>
  38 #include <mdb/mdb_nv.h>
  39 #include <mdb/mdb_fmt.h>
  40 #include <mdb/mdb_target.h>
  41 #include <mdb/mdb_err.h>
  42 #include <mdb/mdb_debug.h>
  43 #include <mdb/mdb_conf.h>
  44 #include <mdb/mdb_module.h>
  45 #include <mdb/mdb_modapi.h>


 768                         return (DCMD_ERR);
 769                 }
 770 
 771                 if (optf & NM_SORT_NAME)
 772                         qsort(syms, nsyms, sizeof (nm_sym_t), nm_compare_name);
 773                 else
 774                         qsort(syms, nsyms, sizeof (nm_sym_t), nm_compare_val);
 775         }
 776 
 777         if ((optf & (NM_PRVSYM | NM_PRTASGN)) == (NM_PRVSYM | NM_PRTASGN))
 778                 callback = nm_asgn;
 779         else if (optf & NM_UNDEF)
 780                 callback = nm_undef;
 781         else
 782                 callback = nm_any;
 783 
 784         if (optf & (NM_SORT_NAME | NM_SORT_VALUE)) {
 785                 for (symp = syms; nsyms-- != 0; symp++) {
 786                         nii.nii_fp = symp->nm_fp;
 787 
 788                         callback(&nii, &symp->nm_sym, symp->nm_name,
 789                             &symp->nm_si, symp->nm_object);
 790                 }
 791 
 792         } else {
 793                 if (optf & NM_PRVSYM) {
 794                         nm_gelf_symtab_iter(mdb.m_prsym, object, MDB_TGT_PRVSYM,
 795                             callback, &nii);
 796 
 797                 } else if (nm_symbol_iter(object, which, type, callback, &nii)
 798                     == -1) {
 799                         mdb_warn("failed to iterate over symbols");
 800                         return (DCMD_ERR);
 801                 }
 802         }
 803 
 804         return (DCMD_OK);
 805 }
 806 
 807 int
 808 cmd_nmadd(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)




   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 2008 Sun Microsystems, Inc.  All rights reserved.
  23  * Use is subject to license terms.
  24  */
  25 
  26 /*
  27  * Copyright (c) 2018, Joyent, Inc.
  28  */
  29 
  30 #include <sys/elf.h>
  31 #include <sys/elf_SPARC.h>
  32 
  33 #include <libproc.h>
  34 #include <libctf.h>
  35 #include <stdlib.h>
  36 #include <string.h>
  37 #include <fcntl.h>
  38 #include <errno.h>
  39 
  40 #include <mdb/mdb_string.h>
  41 #include <mdb/mdb_argvec.h>
  42 #include <mdb/mdb_nv.h>
  43 #include <mdb/mdb_fmt.h>
  44 #include <mdb/mdb_target.h>
  45 #include <mdb/mdb_err.h>
  46 #include <mdb/mdb_debug.h>
  47 #include <mdb/mdb_conf.h>
  48 #include <mdb/mdb_module.h>
  49 #include <mdb/mdb_modapi.h>


 772                         return (DCMD_ERR);
 773                 }
 774 
 775                 if (optf & NM_SORT_NAME)
 776                         qsort(syms, nsyms, sizeof (nm_sym_t), nm_compare_name);
 777                 else
 778                         qsort(syms, nsyms, sizeof (nm_sym_t), nm_compare_val);
 779         }
 780 
 781         if ((optf & (NM_PRVSYM | NM_PRTASGN)) == (NM_PRVSYM | NM_PRTASGN))
 782                 callback = nm_asgn;
 783         else if (optf & NM_UNDEF)
 784                 callback = nm_undef;
 785         else
 786                 callback = nm_any;
 787 
 788         if (optf & (NM_SORT_NAME | NM_SORT_VALUE)) {
 789                 for (symp = syms; nsyms-- != 0; symp++) {
 790                         nii.nii_fp = symp->nm_fp;
 791 
 792                         (void) callback(&nii, &symp->nm_sym, symp->nm_name,
 793                             &symp->nm_si, symp->nm_object);
 794                 }
 795 
 796         } else {
 797                 if (optf & NM_PRVSYM) {
 798                         nm_gelf_symtab_iter(mdb.m_prsym, object, MDB_TGT_PRVSYM,
 799                             callback, &nii);
 800 
 801                 } else if (nm_symbol_iter(object, which, type, callback, &nii)
 802                     == -1) {
 803                         mdb_warn("failed to iterate over symbols");
 804                         return (DCMD_ERR);
 805                 }
 806         }
 807 
 808         return (DCMD_OK);
 809 }
 810 
 811 int
 812 cmd_nmadd(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)