/*
* 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 2010 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#include <stdio.h>
#include <fcntl.h>
#include <stdarg.h>
#include <dlfcn.h>
#include <unistd.h>
#include <string.h>
#include <thread.h>
#include <debug.h>
#include <conv.h>
#include "_rtld.h"
#include "_elf.h"
#include "msg.h"
/*
* Enable diagnostic output. All debugging functions reside in the linker
* debugging library liblddbg.so which is lazy loaded when required.
*/
int
{
const char *ofile;
/*
* If we're running secure, only allow debugging if ld.so.1 itself is
* owned by root and has its mode setuid. Fail silently.
*/
return (1);
/*
* As Dbg_setup() will effectively lazy load the necessary support
* libraries, make sure ld.so.1 is initialized for plt relocations.
*/
if (elf_rtld_load() == 0)
return (1);
/*
* Call the debugging setup routine. This function verifies the
* debugging tokens provided and returns a mask indicating the debugging
* categories selected. The mask effectively enables calls to the
* debugging library.
*/
return (0);
/*
* Obtain the process id.
*/
/*
* If an LD_DEBUG_OUTPUT file was specified then we need to direct all
* diagnostics to the specified file. Add the process id as a file
* suffix so that multiple processes that inherit the same debugging
* environment variable don't fight over the same file.
*
* If LD_DEBUG_OUTPUT is not specified, and the output=file token
* was, then we direct all diagnostics to that file. Unlike
* LD_DEBUG_OUTPUT, we do not add the process id suffix. This
* is more convenient for interactive use.
*
* If neither redirection option is present, we send debugging
* output to stderr. Note that the caller will not be able
* to pipe or redirect this output at the shell level. libc
* has not yet initialized things to make that possible.
*/
} else {
dbg_add_pid = 1;
}
if (dbg_file) {
const char *file;
if (dbg_add_pid) {
} else {
}
if (dbg_fd == -1) {
return (0);
}
} else {
/*
* The default is to direct debugging to the stderr.
*/
dbg_fd = 2;
}
/*
* the debugging file descriptor is still available once the
* application has been entered.
*/
/*
* Now that the output file is established, identify the linker
* package, and generate help output if the user specified the
* debug help token.
*/
Dbg_version();
Dbg_help();
return (1);
}
/*
* Return True (1) if dbg_print() should produce output for the
* specified link-map list, and False (0) otherwise.
*/
static int
{
const char *str;
/*
* The LDSO link-map list is a special case, requiring
* an explicit user request.
*/
/*
* Approve special cases:
* - The link-map list has no name
* - lmid=all was set
* - lmid=alt was set, and this is not the BASE linkmap
*/
return (1);
/*
* If there is no list of specific link-map list names to check,
* then approval depends on lmid={ldso|alt} not being specified.
*/
(DBG_E_LMID_LDSO | DBG_E_LMID_ALT)) == 0);
/*
* Compare the link-map list name against the list of approved names
*/
return (1);
/* Output for this linkmap is denied */
return (0);
}
/*
* All diagnostic requests are funneled to this routine.
*/
/* PRINTFLIKE2 */
void
{
/*
* Knock off any newline indicator to signify that a diagnostic has
* been processed.
*/
/*
* If debugging has been isolated to individual link-map lists,
* determine whether this request originates from a link-map list that
* is being monitored.
*/
return;
/*
* If we're in the application make sure the debugging file descriptor
* same descriptor).
*/
if (rtld_flags & RT_FL_APPLIC) {
if (dbg_file) {
/*
* If the user specified output file has been
* disconnected try and reconnect to it.
*/
const char *file;
if (dbg_add_pid) {
pid);
} else {
}
0)) == -1) {
return;
}
} else {
/*
* If stderr has been stolen from us simply
* turn debugging off.
*/
return;
}
}
}
/*
* Obtain the process id.
*/
/*
* Each time ld.so.1 is entered, the diagnostic times are reset. It is
* useful to convey this reset as part of our diagnostics, but only if
* other diagnostics will follow. If a reset has preceded this
* diagnostic, print a division line.
*/
if (DBG_ISRESET()) {
DBG_OFFRESET();
if (lml)
else
}
/*
* Reestablish the buffer for standard printing.
*/
/*
* Establish any diagnostic prefix strings.
*/
if (lml)
else
}
if (DBG_ISTIME()) {
if (DBG_ISTTIME()) {
}
if (DBG_ISDTIME()) {
}
DBG_DELTATIME = new;
}
}
if (rtld_flags & RT_FL_THREADS) {
}
/*
* Format the message and print it.
*/
}