The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 1 | /* |
David 'Digit' Turner | 5c73464 | 2010-01-20 12:36:51 -0800 | [diff] [blame] | 2 | * Copyright (C) 2008-2010 The Android Open Source Project |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 3 | * All rights reserved. |
| 4 | * |
| 5 | * Redistribution and use in source and binary forms, with or without |
| 6 | * modification, are permitted provided that the following conditions |
| 7 | * are met: |
| 8 | * * Redistributions of source code must retain the above copyright |
| 9 | * notice, this list of conditions and the following disclaimer. |
| 10 | * * Redistributions in binary form must reproduce the above copyright |
| 11 | * notice, this list of conditions and the following disclaimer in |
| 12 | * the documentation and/or other materials provided with the |
| 13 | * distribution. |
| 14 | * |
| 15 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 16 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 17 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
| 18 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
| 19 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
| 21 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS |
| 22 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
| 23 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
| 24 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT |
| 25 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 26 | * SUCH DAMAGE. |
| 27 | */ |
| 28 | |
| 29 | #ifndef _LINKER_DEBUG_H_ |
| 30 | #define _LINKER_DEBUG_H_ |
| 31 | |
| 32 | #include <stdio.h> |
| 33 | |
David 'Digit' Turner | 5c73464 | 2010-01-20 12:36:51 -0800 | [diff] [blame] | 34 | #ifndef LINKER_DEBUG |
| 35 | #error LINKER_DEBUG should be defined to either 1 or 0 in Android.mk |
| 36 | #endif |
| 37 | |
| 38 | /* set LINKER_DEBUG_TO_LOG to 1 to send the logs to logcat, |
| 39 | * or 0 to use stdout instead. |
| 40 | */ |
| 41 | #define LINKER_DEBUG_TO_LOG 1 |
| 42 | #define TRACE_DEBUG 1 |
| 43 | #define DO_TRACE_LOOKUP 1 |
| 44 | #define DO_TRACE_RELO 1 |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 45 | #define TIMING 0 |
| 46 | #define STATS 0 |
| 47 | #define COUNT_PAGES 0 |
| 48 | |
| 49 | /********************************************************************* |
| 50 | * You shouldn't need to modify anything below unless you are adding |
| 51 | * more debugging information. |
| 52 | * |
| 53 | * To enable/disable specific debug options, change the defines above |
| 54 | *********************************************************************/ |
| 55 | |
| 56 | |
| 57 | /*********************************************************************/ |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 58 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 59 | /* Only use printf() during debugging. We have seen occasional memory |
| 60 | * corruption when the linker uses printf(). |
| 61 | */ |
| 62 | #if LINKER_DEBUG |
David 'Digit' Turner | 5c73464 | 2010-01-20 12:36:51 -0800 | [diff] [blame] | 63 | #include "linker_format.h" |
Nick Kralevich | 3697b52 | 2012-08-24 13:40:25 -0700 | [diff] [blame] | 64 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 65 | extern int debug_verbosity; |
David 'Digit' Turner | 5c73464 | 2010-01-20 12:36:51 -0800 | [diff] [blame] | 66 | #if LINKER_DEBUG_TO_LOG |
| 67 | extern int format_log(int, const char *, const char *, ...); |
Elliott Hughes | bedfe38 | 2012-08-14 14:07:59 -0700 | [diff] [blame] | 68 | #define _PRINTVF(v,x...) \ |
David 'Digit' Turner | 5c73464 | 2010-01-20 12:36:51 -0800 | [diff] [blame] | 69 | do { \ |
| 70 | if (debug_verbosity > (v)) format_log(5-(v),"linker",x); \ |
Dima Zavin | 2e85579 | 2009-05-20 18:28:09 -0700 | [diff] [blame] | 71 | } while (0) |
David 'Digit' Turner | 5c73464 | 2010-01-20 12:36:51 -0800 | [diff] [blame] | 72 | #else /* !LINKER_DEBUG_TO_LOG */ |
| 73 | extern int format_fd(int, const char *, ...); |
Elliott Hughes | bedfe38 | 2012-08-14 14:07:59 -0700 | [diff] [blame] | 74 | #define _PRINTVF(v,x...) \ |
David 'Digit' Turner | 5c73464 | 2010-01-20 12:36:51 -0800 | [diff] [blame] | 75 | do { \ |
| 76 | if (debug_verbosity > (v)) format_fd(1, x); \ |
| 77 | } while (0) |
| 78 | #endif /* !LINKER_DEBUG_TO_LOG */ |
Nick Kralevich | 3697b52 | 2012-08-24 13:40:25 -0700 | [diff] [blame] | 79 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 80 | #else /* !LINKER_DEBUG */ |
| 81 | #define _PRINTVF(v,f,x...) do {} while(0) |
| 82 | #endif /* LINKER_DEBUG */ |
| 83 | |
Elliott Hughes | bedfe38 | 2012-08-14 14:07:59 -0700 | [diff] [blame] | 84 | #define PRINT(x...) _PRINTVF(-1, x) |
| 85 | #define INFO(x...) _PRINTVF(0, x) |
| 86 | #define TRACE(x...) _PRINTVF(1, x) |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 87 | #define WARN(fmt,args...) \ |
Elliott Hughes | bedfe38 | 2012-08-14 14:07:59 -0700 | [diff] [blame] | 88 | _PRINTVF(-1, "%s:%d| WARNING: " fmt, __FILE__, __LINE__, ## args) |
Dima Zavin | 2e85579 | 2009-05-20 18:28:09 -0700 | [diff] [blame] | 89 | #define ERROR(fmt,args...) \ |
Elliott Hughes | bedfe38 | 2012-08-14 14:07:59 -0700 | [diff] [blame] | 90 | _PRINTVF(-1, "%s:%d| ERROR: " fmt, __FILE__, __LINE__, ## args) |
Dima Zavin | 2e85579 | 2009-05-20 18:28:09 -0700 | [diff] [blame] | 91 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 92 | |
| 93 | #if TRACE_DEBUG |
Elliott Hughes | bedfe38 | 2012-08-14 14:07:59 -0700 | [diff] [blame] | 94 | #define DEBUG(x...) _PRINTVF(2, "DEBUG: " x) |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 95 | #else /* !TRACE_DEBUG */ |
| 96 | #define DEBUG(x...) do {} while (0) |
| 97 | #endif /* TRACE_DEBUG */ |
| 98 | |
| 99 | #if LINKER_DEBUG |
| 100 | #define TRACE_TYPE(t,x...) do { if (DO_TRACE_##t) { TRACE(x); } } while (0) |
| 101 | #else /* !LINKER_DEBUG */ |
| 102 | #define TRACE_TYPE(t,x...) do {} while (0) |
| 103 | #endif /* LINKER_DEBUG */ |
| 104 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 105 | #if TIMING |
| 106 | #undef WARN |
| 107 | #define WARN(x...) do {} while (0) |
| 108 | #endif /* TIMING */ |
| 109 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 110 | #define DEBUG_DUMP_PHDR(phdr, name, pid) do { \ |
| 111 | DEBUG("%5d %s (phdr = 0x%08x)\n", (pid), (name), (unsigned)(phdr)); \ |
| 112 | DEBUG("\t\tphdr->offset = 0x%08x\n", (unsigned)((phdr)->p_offset)); \ |
| 113 | DEBUG("\t\tphdr->p_vaddr = 0x%08x\n", (unsigned)((phdr)->p_vaddr)); \ |
| 114 | DEBUG("\t\tphdr->p_paddr = 0x%08x\n", (unsigned)((phdr)->p_paddr)); \ |
| 115 | DEBUG("\t\tphdr->p_filesz = 0x%08x\n", (unsigned)((phdr)->p_filesz)); \ |
| 116 | DEBUG("\t\tphdr->p_memsz = 0x%08x\n", (unsigned)((phdr)->p_memsz)); \ |
| 117 | DEBUG("\t\tphdr->p_flags = 0x%08x\n", (unsigned)((phdr)->p_flags)); \ |
| 118 | DEBUG("\t\tphdr->p_align = 0x%08x\n", (unsigned)((phdr)->p_align)); \ |
| 119 | } while (0) |
| 120 | |
| 121 | #endif /* _LINKER_DEBUG_H_ */ |