njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 1 | |
| 2 | /*--------------------------------------------------------------------*/ |
nethercote | 7cc9c23 | 2004-01-21 15:08:04 +0000 | [diff] [blame] | 3 | /*--- Stuff relating to tool data structures. ---*/ |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 4 | /*--- vg_needs.c ---*/ |
| 5 | /*--------------------------------------------------------------------*/ |
| 6 | |
| 7 | /* |
njn | b9c427c | 2004-12-01 14:14:42 +0000 | [diff] [blame] | 8 | This file is part of Valgrind, a dynamic binary instrumentation |
| 9 | framework. |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 10 | |
njn | 5361242 | 2005-03-12 16:22:54 +0000 | [diff] [blame] | 11 | Copyright (C) 2000-2005 Nicholas Nethercote |
njn | 0e1b514 | 2003-04-15 14:58:06 +0000 | [diff] [blame] | 12 | njn25@cam.ac.uk |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 13 | |
| 14 | This program is free software; you can redistribute it and/or |
| 15 | modify it under the terms of the GNU General Public License as |
| 16 | published by the Free Software Foundation; either version 2 of the |
| 17 | License, or (at your option) any later version. |
| 18 | |
| 19 | This program is distributed in the hope that it will be useful, but |
| 20 | WITHOUT ANY WARRANTY; without even the implied warranty of |
| 21 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 22 | General Public License for more details. |
| 23 | |
| 24 | You should have received a copy of the GNU General Public License |
| 25 | along with this program; if not, write to the Free Software |
| 26 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA |
| 27 | 02111-1307, USA. |
| 28 | |
| 29 | The GNU General Public License is contained in the file COPYING. |
| 30 | */ |
| 31 | |
nethercote | f1e5e15 | 2004-09-01 23:58:16 +0000 | [diff] [blame] | 32 | #include "core.h" |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 33 | |
| 34 | |
| 35 | /* --------------------------------------------------------------------- |
nethercote | 7cc9c23 | 2004-01-21 15:08:04 +0000 | [diff] [blame] | 36 | Tool data structure initialisation |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 37 | ------------------------------------------------------------------ */ |
| 38 | |
| 39 | /* Init with default values. */ |
| 40 | VgDetails VG_(details) = { |
sewardj | c0d8f68 | 2002-11-30 00:49:43 +0000 | [diff] [blame] | 41 | .name = NULL, |
| 42 | .version = NULL, |
| 43 | .description = NULL, |
| 44 | .copyright_author = NULL, |
| 45 | .bug_reports_to = NULL, |
njn | 120281f | 2003-02-03 12:20:07 +0000 | [diff] [blame] | 46 | .avg_translation_sizeB = VG_DEFAULT_TRANS_SIZEB, |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 47 | }; |
| 48 | |
| 49 | VgNeeds VG_(needs) = { |
| 50 | .core_errors = False, |
njn | 95ec870 | 2004-11-22 16:46:13 +0000 | [diff] [blame] | 51 | .tool_errors = False, |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 52 | .libc_freeres = False, |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 53 | .basic_block_discards = False, |
njn | abb14ad | 2004-11-24 16:57:16 +0000 | [diff] [blame] | 54 | .no_longer_used_1 = False, |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 55 | .command_line_options = False, |
| 56 | .client_requests = False, |
njn | 37624a7 | 2004-11-22 20:37:42 +0000 | [diff] [blame] | 57 | .no_longer_used_0 = False, |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 58 | .syscall_wrapper = False, |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 59 | .sanity_checks = False, |
| 60 | .data_syms = False, |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 61 | .shadow_memory = False, |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 62 | }; |
| 63 | |
| 64 | /* static */ |
| 65 | void VG_(sanity_check_needs) ( void) |
| 66 | { |
| 67 | #define CHECK_NOT(var, value) \ |
| 68 | if ((var)==(value)) { \ |
nethercote | 137bc55 | 2003-11-14 17:47:54 +0000 | [diff] [blame] | 69 | VG_(printf)("\nTool error: `%s' not initialised\n", \ |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 70 | VG__STRING(var)); \ |
njn | 6799325 | 2004-11-22 18:02:32 +0000 | [diff] [blame] | 71 | VG_(tool_panic)("Uninitialised details field\n"); \ |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 72 | } |
| 73 | |
njn | 120281f | 2003-02-03 12:20:07 +0000 | [diff] [blame] | 74 | /* Ones that must be set */ |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 75 | CHECK_NOT(VG_(details).name, NULL); |
| 76 | /* Nb: .version can be NULL */ |
| 77 | CHECK_NOT(VG_(details).description, NULL); |
| 78 | CHECK_NOT(VG_(details).copyright_author, NULL); |
| 79 | CHECK_NOT(VG_(details).bug_reports_to, NULL); |
| 80 | |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 81 | if ( (VG_(defined_new_mem_stack_4)() || |
| 82 | VG_(defined_new_mem_stack_8)() || |
| 83 | VG_(defined_new_mem_stack_12)() || |
| 84 | VG_(defined_new_mem_stack_16)() || |
| 85 | VG_(defined_new_mem_stack_32)()) && |
| 86 | ! VG_(defined_new_mem_stack)()) |
njn | d304045 | 2003-05-19 15:04:06 +0000 | [diff] [blame] | 87 | { |
nethercote | 137bc55 | 2003-11-14 17:47:54 +0000 | [diff] [blame] | 88 | VG_(printf)("\nTool error: one of the specialised `new_mem_stack_n'\n" |
njn | 9b007f6 | 2003-04-07 14:40:25 +0000 | [diff] [blame] | 89 | "events tracked, but not the generic `new_mem_stack' one.\n"); |
njn | 6799325 | 2004-11-22 18:02:32 +0000 | [diff] [blame] | 90 | VG_(tool_panic)("`new_mem_stack' should be defined\n"); |
njn | 9b007f6 | 2003-04-07 14:40:25 +0000 | [diff] [blame] | 91 | } |
| 92 | |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 93 | if ( (VG_(defined_die_mem_stack_4)() || |
| 94 | VG_(defined_die_mem_stack_8)() || |
| 95 | VG_(defined_die_mem_stack_12)() || |
| 96 | VG_(defined_die_mem_stack_16)() || |
| 97 | VG_(defined_die_mem_stack_32)()) && |
| 98 | ! VG_(defined_die_mem_stack)()) |
njn | d304045 | 2003-05-19 15:04:06 +0000 | [diff] [blame] | 99 | { |
nethercote | 137bc55 | 2003-11-14 17:47:54 +0000 | [diff] [blame] | 100 | VG_(printf)("\nTool error: one of the specialised `die_mem_stack_n'\n" |
njn | 9b007f6 | 2003-04-07 14:40:25 +0000 | [diff] [blame] | 101 | "events tracked, but not the generic `die_mem_stack' one.\n"); |
njn | 6799325 | 2004-11-22 18:02:32 +0000 | [diff] [blame] | 102 | VG_(tool_panic)("`die_mem_stack' should be defined\n"); |
njn | 9b007f6 | 2003-04-07 14:40:25 +0000 | [diff] [blame] | 103 | } |
| 104 | |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 105 | if (VG_(needs).shadow_memory != (VG_(get_shadow_size)() != 0)) { |
| 106 | if (VG_(get_shadow_size)() != 0) |
| 107 | VG_(printf)("\nTool error: tool allocated shadow memory, but apparently doesn't " |
| 108 | "need it.\n"); |
| 109 | else |
nethercote | 3221433 | 2004-10-09 18:50:16 +0000 | [diff] [blame] | 110 | VG_(printf)("\nTool error: tool didn't allocate shadow memory, but apparently " |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 111 | "needs it.\n"); |
njn | 26f0251 | 2004-11-22 18:33:15 +0000 | [diff] [blame] | 112 | VG_(tool_panic)("VG_(needs).shadow_memory need should be set to match TL_(shadow_ratio)\n"); |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 113 | } |
| 114 | |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 115 | #undef CHECK_NOT |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 116 | } |
| 117 | |
| 118 | /*--------------------------------------------------------------------*/ |
| 119 | /* Setting details */ |
| 120 | |
| 121 | /* Use macro because they're so repetitive */ |
sewardj | c0d8f68 | 2002-11-30 00:49:43 +0000 | [diff] [blame] | 122 | #define DETAILS(type, detail) \ |
| 123 | extern void VG_(details_##detail)(type detail) \ |
| 124 | { \ |
| 125 | VG_(details).detail = detail; \ |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 126 | } |
| 127 | |
sewardj | c0d8f68 | 2002-11-30 00:49:43 +0000 | [diff] [blame] | 128 | DETAILS(Char*, name) |
| 129 | DETAILS(Char*, version) |
| 130 | DETAILS(Char*, description) |
| 131 | DETAILS(Char*, copyright_author) |
| 132 | DETAILS(Char*, bug_reports_to) |
njn | 120281f | 2003-02-03 12:20:07 +0000 | [diff] [blame] | 133 | DETAILS(UInt, avg_translation_sizeB) |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 134 | |
| 135 | /*--------------------------------------------------------------------*/ |
| 136 | /* Setting needs */ |
| 137 | |
| 138 | /* Use macro because they're so repetitive */ |
| 139 | #define NEEDS(need) \ |
| 140 | extern void VG_(needs_##need)(void) \ |
| 141 | { \ |
| 142 | VG_(needs).need = True; \ |
| 143 | } |
| 144 | |
| 145 | NEEDS(libc_freeres) |
| 146 | NEEDS(core_errors) |
njn | 95ec870 | 2004-11-22 16:46:13 +0000 | [diff] [blame] | 147 | NEEDS(tool_errors) |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 148 | NEEDS(basic_block_discards) |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 149 | NEEDS(command_line_options) |
| 150 | NEEDS(client_requests) |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 151 | NEEDS(syscall_wrapper) |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 152 | NEEDS(sanity_checks) |
| 153 | NEEDS(data_syms) |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 154 | NEEDS(shadow_memory) |
njn | fdc28af | 2003-02-24 10:36:48 +0000 | [diff] [blame] | 155 | |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 156 | /*--------------------------------------------------------------------*/ |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 157 | /*--- end vg_needs.c ---*/ |
| 158 | /*--------------------------------------------------------------------*/ |
| 159 | |
| 160 | |