Support for specifying printf-like output specs to control the ldd output

as present in the new rtld version.

Obtained from: NetBSD
Reviewed by: nate, jdp
This commit is contained in:
peter 1996-10-01 01:34:32 +00:00
parent 23b0588846
commit 7ad318175d
4 changed files with 64 additions and 8 deletions

View File

@ -6,7 +6,8 @@
.Nd list dynamic object dependencies
.Sh SYNOPSIS
.Nm ldd
.Op Ar filename Ar ...
.Op Fl f Ar format
.Ar program ...
.Sh DESCRIPTION
.Nm ldd
displays all shared objects that are needed to run the given program.
@ -14,6 +15,16 @@ Contrary to nm(1), the list includes
.Dq indirect
depedencies that are the result of needed shared objects which themselves
depend on yet other shared objects.
.Pp
Zero, one or two
.Fl f
options may be given. The argument is a format string passed to
.Xr rtld 1
and allows customization of
.Nm ldd Ns 's
output. See
.Xr rtld 1
for a list of recognised conversion characters.
.Sh SEE ALSO
.Xr ld 1 ,
.Xr ld.so 1 ,

View File

@ -27,7 +27,7 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* $Id: ldd.c,v 1.4 1994/06/15 22:41:03 rich Exp $
* $Id: ldd.c,v 1.5 1994/12/23 22:31:31 nate Exp $
*/
#include <sys/types.h>
@ -58,11 +58,20 @@ main(argc, argv)
int argc;
char *argv[];
{
char *fmt1 = NULL, *fmt2 = NULL;
int rval;
int c;
while ((c = getopt(argc, argv, "")) != EOF) {
while ((c = getopt(argc, argv, "f:")) != EOF) {
switch (c) {
case 'f':
if (fmt1) {
if (fmt2)
errx(1, "Too many formats");
fmt2 = optarg;
} else
fmt1 = optarg;
break;
default:
usage();
/*NOTREACHED*/
@ -78,6 +87,10 @@ char *argv[];
/* ld.so magic */
setenv("LD_TRACE_LOADED_OBJECTS", "", 1);
if (fmt1)
setenv("LD_TRACE_LOADED_OBJECTS_FMT1", fmt1, 1);
if (fmt2)
setenv("LD_TRACE_LOADED_OBJECTS_FMT2", fmt2, 1);
rval = 0;
while (argc--) {
@ -106,7 +119,11 @@ char *argv[];
}
(void)close(fd);
printf("%s:\n", *argv);
setenv("LD_TRACE_LOADED_OBJECTS_PROGNAME", *argv, 1);
if (fmt1 == NULL && fmt2 == NULL)
/* Default formats */
printf("%s:\n", *argv);
fflush(stdout);
switch (fork()) {

View File

@ -6,7 +6,8 @@
.Nd list dynamic object dependencies
.Sh SYNOPSIS
.Nm ldd
.Op Ar filename Ar ...
.Op Fl f Ar format
.Ar program ...
.Sh DESCRIPTION
.Nm ldd
displays all shared objects that are needed to run the given program.
@ -14,6 +15,16 @@ Contrary to nm(1), the list includes
.Dq indirect
depedencies that are the result of needed shared objects which themselves
depend on yet other shared objects.
.Pp
Zero, one or two
.Fl f
options may be given. The argument is a format string passed to
.Xr rtld 1
and allows customization of
.Nm ldd Ns 's
output. See
.Xr rtld 1
for a list of recognised conversion characters.
.Sh SEE ALSO
.Xr ld 1 ,
.Xr ld.so 1 ,

View File

@ -27,7 +27,7 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* $Id: ldd.c,v 1.4 1994/06/15 22:41:03 rich Exp $
* $Id: ldd.c,v 1.5 1994/12/23 22:31:31 nate Exp $
*/
#include <sys/types.h>
@ -58,11 +58,20 @@ main(argc, argv)
int argc;
char *argv[];
{
char *fmt1 = NULL, *fmt2 = NULL;
int rval;
int c;
while ((c = getopt(argc, argv, "")) != EOF) {
while ((c = getopt(argc, argv, "f:")) != EOF) {
switch (c) {
case 'f':
if (fmt1) {
if (fmt2)
errx(1, "Too many formats");
fmt2 = optarg;
} else
fmt1 = optarg;
break;
default:
usage();
/*NOTREACHED*/
@ -78,6 +87,10 @@ char *argv[];
/* ld.so magic */
setenv("LD_TRACE_LOADED_OBJECTS", "", 1);
if (fmt1)
setenv("LD_TRACE_LOADED_OBJECTS_FMT1", fmt1, 1);
if (fmt2)
setenv("LD_TRACE_LOADED_OBJECTS_FMT2", fmt2, 1);
rval = 0;
while (argc--) {
@ -106,7 +119,11 @@ char *argv[];
}
(void)close(fd);
printf("%s:\n", *argv);
setenv("LD_TRACE_LOADED_OBJECTS_PROGNAME", *argv, 1);
if (fmt1 == NULL && fmt2 == NULL)
/* Default formats */
printf("%s:\n", *argv);
fflush(stdout);
switch (fork()) {