linker_debug.h revision 0493a6f7be42e22d68e1d6ddb8eb2edaf818756f
11dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project/*
25c734644eebf8d01be1e86cbe20a111a5c5a2738David 'Digit' Turner * Copyright (C) 2008-2010 The Android Open Source Project
31dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * All rights reserved.
41dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project *
51dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * Redistribution and use in source and binary forms, with or without
61dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * modification, are permitted provided that the following conditions
71dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * are met:
81dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project *  * Redistributions of source code must retain the above copyright
91dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project *    notice, this list of conditions and the following disclaimer.
101dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project *  * Redistributions in binary form must reproduce the above copyright
111dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project *    notice, this list of conditions and the following disclaimer in
121dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project *    the documentation and/or other materials provided with the
131dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project *    distribution.
141dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project *
151dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
161dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
171dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
181dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
191dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
201dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
211dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
221dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
231dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
241dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
251dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
261dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * SUCH DAMAGE.
271dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project */
281dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
291dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#ifndef _LINKER_DEBUG_H_
301dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define _LINKER_DEBUG_H_
311dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
321dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#include <stdio.h>
331dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
340493a6f7be42e22d68e1d6ddb8eb2edaf818756fElliott Hughes// You can increase the verbosity of debug traces by defining the LD_DEBUG
350493a6f7be42e22d68e1d6ddb8eb2edaf818756fElliott Hughes// environment variable to a numeric value from 0 to 2 (corresponding to
360493a6f7be42e22d68e1d6ddb8eb2edaf818756fElliott Hughes// INFO, TRACE, and DEBUG calls in the source). This will only
370493a6f7be42e22d68e1d6ddb8eb2edaf818756fElliott Hughes// affect new processes being launched.
380493a6f7be42e22d68e1d6ddb8eb2edaf818756fElliott Hughes
390493a6f7be42e22d68e1d6ddb8eb2edaf818756fElliott Hughes// By default, traces are sent to logcat, with the "linker" tag. You can
400493a6f7be42e22d68e1d6ddb8eb2edaf818756fElliott Hughes// change this to go to stdout instead by setting the definition of
410493a6f7be42e22d68e1d6ddb8eb2edaf818756fElliott Hughes// LINKER_DEBUG_TO_LOG to 0.
425c734644eebf8d01be1e86cbe20a111a5c5a2738David 'Digit' Turner#define LINKER_DEBUG_TO_LOG  1
430493a6f7be42e22d68e1d6ddb8eb2edaf818756fElliott Hughes
445c734644eebf8d01be1e86cbe20a111a5c5a2738David 'Digit' Turner#define TRACE_DEBUG          1
455c734644eebf8d01be1e86cbe20a111a5c5a2738David 'Digit' Turner#define DO_TRACE_LOOKUP      1
465c734644eebf8d01be1e86cbe20a111a5c5a2738David 'Digit' Turner#define DO_TRACE_RELO        1
471dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define TIMING               0
481dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define STATS                0
491dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define COUNT_PAGES          0
501dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
511dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project/*********************************************************************
521dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * You shouldn't need to modify anything below unless you are adding
531dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * more debugging information.
541dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project *
551dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * To enable/disable specific debug options, change the defines above
561dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project *********************************************************************/
571dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
581dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
591dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project/*********************************************************************/
601dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
611e980b6bc8315d00a07312b25486531247abd98cElliott Hughes#include <private/debug_format.h>
623697b52605230d1479b662dceb27b4ef1fab0567Nick Kralevich
63650be4e584eeab3591b9e273bfd6d169eea60853Elliott Hughes__LIBC_HIDDEN__ extern int gLdDebugVerbosity;
64650be4e584eeab3591b9e273bfd6d169eea60853Elliott Hughes
655c734644eebf8d01be1e86cbe20a111a5c5a2738David 'Digit' Turner#if LINKER_DEBUG_TO_LOG
66bedfe38b8ba512dd6236c00e8b4a9b01c2bd1281Elliott Hughes#define _PRINTVF(v,x...)                                        \
675c734644eebf8d01be1e86cbe20a111a5c5a2738David 'Digit' Turner    do {                                                          \
68650be4e584eeab3591b9e273bfd6d169eea60853Elliott Hughes        if (gLdDebugVerbosity > (v)) __libc_format_log(5-(v),"linker",x);  \
695c734644eebf8d01be1e86cbe20a111a5c5a2738David 'Digit' Turner    } while (0)
705c734644eebf8d01be1e86cbe20a111a5c5a2738David 'Digit' Turner#else /* !LINKER_DEBUG_TO_LOG */
71bedfe38b8ba512dd6236c00e8b4a9b01c2bd1281Elliott Hughes#define _PRINTVF(v,x...)                           \
725c734644eebf8d01be1e86cbe20a111a5c5a2738David 'Digit' Turner    do {                                             \
73650be4e584eeab3591b9e273bfd6d169eea60853Elliott Hughes        if (gLdDebugVerbosity > (v)) __libc_format_fd(1, x);  \
742e85579c34047c305caf15fb0ebe02bf3d001d0eDima Zavin    } while (0)
755c734644eebf8d01be1e86cbe20a111a5c5a2738David 'Digit' Turner#endif /* !LINKER_DEBUG_TO_LOG */
763697b52605230d1479b662dceb27b4ef1fab0567Nick Kralevich
77bedfe38b8ba512dd6236c00e8b4a9b01c2bd1281Elliott Hughes#define PRINT(x...)          _PRINTVF(-1, x)
78bedfe38b8ba512dd6236c00e8b4a9b01c2bd1281Elliott Hughes#define INFO(x...)           _PRINTVF(0, x)
79bedfe38b8ba512dd6236c00e8b4a9b01c2bd1281Elliott Hughes#define TRACE(x...)          _PRINTVF(1, x)
801dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
811dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#if TRACE_DEBUG
82bedfe38b8ba512dd6236c00e8b4a9b01c2bd1281Elliott Hughes#define DEBUG(x...)          _PRINTVF(2, "DEBUG: " x)
831dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#else /* !TRACE_DEBUG */
841dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define DEBUG(x...)          do {} while (0)
851dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#endif /* TRACE_DEBUG */
861dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
871dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define TRACE_TYPE(t,x...)   do { if (DO_TRACE_##t) { TRACE(x); } } while (0)
881dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
891dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#endif /* _LINKER_DEBUG_H_ */
90