main.c revision d579eb63ae5b8d8c65917b341e8c19a4df710606
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* Dump an elf file.
*/
#include <fcntl.h>
#include <stdio.h>
#include <libelf.h>
#include <link.h>
#include <stdarg.h>
#include <unistd.h>
#include <libgen.h>
#include <libintl.h>
#include <locale.h>
#include <errno.h>
#include <strings.h>
#include <debug.h>
#include <conv.h>
#include <msg.h>
#include <_elfdump.h>
const char *
{
}
/*
* Determine whether a symbol name should be demangled.
*/
const char *
{
if (flags & FLG_DEMANGLE)
return (Elf_demangle_name(name));
else
return ((char *)name);
}
/*
* Define our own standard error routine.
*/
void
{
}
/*
* The full usage message
*/
static void
{
}
static void
{
else
}
static void
int wfd)
{
/*
* Determine if the archive symbol table itself is required.
*/
/*
* Get the archive symbol table.
*/
/*
* The arsym could be 0 even though there was no error.
* Print the error message only when there was
* real error from elf_getarsym().
*/
return;
}
}
/*
* Print the archive symbol table only when the archive symbol
* table exists and it was requested to print.
*/
if (arsym) {
char index[MAXNDXSIZE];
/*
* Print out all the symbol entries.
*/
/*
* For each object obtain an elf descriptor so that we
* can establish the members name. Note, we have had
* archives where the archive header has not been
* obtainable so be lenient with errors.
*/
if (_elf)
arhdr = 0;
ELF_C_READ, elf)) == 0) {
arhdr = 0;
arhdr = 0;
}
if (offset == 0)
}
/* LINTED */
MSG_INTL(MSG_STR_NULL)));
else
/* LINTED */
}
if (_elf)
/*
* If we only need the archive symbol table return.
*/
return;
/*
* Reset elf descriptor in preparation for processing each
* member.
*/
if (offset)
}
/*
* Process each object within the archive.
*/
char name[MAXPATHLEN];
return;
}
case ELF_K_AR:
break;
case ELF_K_ELF:
break;
default:
break;
}
}
}
}
int
{
/*
* If we're on a 64-bit kernel, try to exec a full 64-bit version of
* the binary. If successful, conv_check_native() won't return.
*/
/*
* Establish locale.
*/
opterr = 0;
switch (var) {
case 'C':
flags |= FLG_DEMANGLE;
break;
case 'c':
break;
case 'd':
flags |= FLG_DYNAMIC;
break;
case 'e':
break;
case 'G':
break;
case 'g':
break;
case 'H':
break;
case 'h':
break;
case 'i':
flags |= FLG_INTERP;
break;
case 'k':
flags |= FLG_CHECKSUM;
break;
case 'l':
flags |= FLG_LONGNAME;
break;
case 'm':
break;
case 'N':
break;
case 'n':
break;
case 'p':
break;
case 'r':
break;
case 'S':
break;
case 's':
flags |= FLG_SYMBOLS;
break;
case 'u':
flags |= FLG_UNWIND;
break;
case 'v':
flags |= FLG_VERSIONS;
break;
case 'w':
break;
case 'y':
flags |= FLG_SYMINFO;
break;
case '?':
detail_usage();
return (1);
default:
break;
}
}
/*
* Validate any arguments.
*/
flags |= FLG_EVERYTHING;
return (1);
}
}
return (1);
}
/*
* If the -l/-C option is specified, set up the liblddbg.so.
*/
if (flags & FLG_LONGNAME)
if (flags & FLG_DEMANGLE)
/*
* If the -w option has indicated an output file open it. It's
* arguable whether this option has much use when multiple files are
* being processed.
*/
if (wname) {
0666)) < 0) {
wfd = 0;
}
}
/*
* Open the input file and initialize the elf interface.
*/
continue;
}
(void) elf_version(EV_CURRENT);
continue;
}
if (var > 1)
case ELF_K_AR:
break;
case ELF_K_ELF:
break;
default:
break;
}
}
if (wfd)
return (0);
}