debug.c revision 3dbfc80346c4b24f1337e411111b9521c729cf9e
/*
* 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 2008 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 "_rtld.h"
#include "_elf.h"
#include "msg.h"
static int dbg_fd; /* debugging output file descriptor */
/*
* Enable diagnostic output. All debugging functions reside in the linker
* debugging library liblddbg.so which is lazy loaded when required.
*/
{
/*
* 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 (0);
/*
* 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 (0);
/*
* 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 (ret);
/*
* 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 (dbg_file) {
char file[MAXPATHLEN];
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.
*/
return (ret);
}
static int
{
const char *str;
return (1);
}
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. Otherwise, process all link-map list diagnostics
* except those that originate from ld.so.1 processing its own
* dependencies.
*/
return;
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.
*/
char file[MAXPATHLEN];
0)) == -1) {
return;
}
} else {
/*
* If stderr has been stolen from us simply
* turn debugging off.
*/
return;
}
}
}
/*
* The getpid() call is a 'special' interface between ld.so.1 and dbx,
* because of this getpid() can't be called freely until after control
* has been given to the user program. Once the control has been given
* to the user program we know that the r_debug structure has been
* properly initialized for the debugger.
*/
if (rtld_flags & RT_FL_APPLIC)
else
if (lml)
else
}
if (rtld_flags & RT_FL_THREADS) {
}
/*
* Format the message and print it.
*/
}