blob: ada4419c932631da1e62a1dda49926a35e252db8 [file] [log] [blame]
njn810086f2002-11-14 12:42:47 +00001
2/*--------------------------------------------------------------------*/
nethercote7cc9c232004-01-21 15:08:04 +00003/*--- Stuff relating to tool data structures. ---*/
njn810086f2002-11-14 12:42:47 +00004/*--- vg_needs.c ---*/
5/*--------------------------------------------------------------------*/
6
7/*
njnb9c427c2004-12-01 14:14:42 +00008 This file is part of Valgrind, a dynamic binary instrumentation
9 framework.
njn810086f2002-11-14 12:42:47 +000010
njn53612422005-03-12 16:22:54 +000011 Copyright (C) 2000-2005 Nicholas Nethercote
njn0e1b5142003-04-15 14:58:06 +000012 njn25@cam.ac.uk
njn810086f2002-11-14 12:42:47 +000013
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
nethercotef1e5e152004-09-01 23:58:16 +000032#include "core.h"
njn810086f2002-11-14 12:42:47 +000033
34
35/* ---------------------------------------------------------------------
nethercote7cc9c232004-01-21 15:08:04 +000036 Tool data structure initialisation
njn810086f2002-11-14 12:42:47 +000037 ------------------------------------------------------------------ */
38
39/* Init with default values. */
40VgDetails VG_(details) = {
sewardjc0d8f682002-11-30 00:49:43 +000041 .name = NULL,
42 .version = NULL,
43 .description = NULL,
44 .copyright_author = NULL,
45 .bug_reports_to = NULL,
njn120281f2003-02-03 12:20:07 +000046 .avg_translation_sizeB = VG_DEFAULT_TRANS_SIZEB,
njn810086f2002-11-14 12:42:47 +000047};
48
49VgNeeds VG_(needs) = {
50 .core_errors = False,
njn95ec8702004-11-22 16:46:13 +000051 .tool_errors = False,
njn810086f2002-11-14 12:42:47 +000052 .libc_freeres = False,
njn810086f2002-11-14 12:42:47 +000053 .basic_block_discards = False,
njnabb14ad2004-11-24 16:57:16 +000054 .no_longer_used_1 = False,
njn810086f2002-11-14 12:42:47 +000055 .command_line_options = False,
56 .client_requests = False,
njn37624a72004-11-22 20:37:42 +000057 .no_longer_used_0 = False,
njn810086f2002-11-14 12:42:47 +000058 .syscall_wrapper = False,
njn810086f2002-11-14 12:42:47 +000059 .sanity_checks = False,
60 .data_syms = False,
fitzhardinge98abfc72003-12-16 02:05:15 +000061 .shadow_memory = False,
njn810086f2002-11-14 12:42:47 +000062};
63
64/* static */
65void VG_(sanity_check_needs) ( void)
66{
67#define CHECK_NOT(var, value) \
68 if ((var)==(value)) { \
nethercote137bc552003-11-14 17:47:54 +000069 VG_(printf)("\nTool error: `%s' not initialised\n", \
njn810086f2002-11-14 12:42:47 +000070 VG__STRING(var)); \
njn67993252004-11-22 18:02:32 +000071 VG_(tool_panic)("Uninitialised details field\n"); \
njn810086f2002-11-14 12:42:47 +000072 }
73
njn120281f2003-02-03 12:20:07 +000074 /* Ones that must be set */
njn810086f2002-11-14 12:42:47 +000075 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
fitzhardinge98abfc72003-12-16 02:05:15 +000081 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)())
njnd3040452003-05-19 15:04:06 +000087 {
nethercote137bc552003-11-14 17:47:54 +000088 VG_(printf)("\nTool error: one of the specialised `new_mem_stack_n'\n"
njn9b007f62003-04-07 14:40:25 +000089 "events tracked, but not the generic `new_mem_stack' one.\n");
njn67993252004-11-22 18:02:32 +000090 VG_(tool_panic)("`new_mem_stack' should be defined\n");
njn9b007f62003-04-07 14:40:25 +000091 }
92
fitzhardinge98abfc72003-12-16 02:05:15 +000093 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)())
njnd3040452003-05-19 15:04:06 +000099 {
nethercote137bc552003-11-14 17:47:54 +0000100 VG_(printf)("\nTool error: one of the specialised `die_mem_stack_n'\n"
njn9b007f62003-04-07 14:40:25 +0000101 "events tracked, but not the generic `die_mem_stack' one.\n");
njn67993252004-11-22 18:02:32 +0000102 VG_(tool_panic)("`die_mem_stack' should be defined\n");
njn9b007f62003-04-07 14:40:25 +0000103 }
104
fitzhardinge98abfc72003-12-16 02:05:15 +0000105 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
nethercote32214332004-10-09 18:50:16 +0000110 VG_(printf)("\nTool error: tool didn't allocate shadow memory, but apparently "
fitzhardinge98abfc72003-12-16 02:05:15 +0000111 "needs it.\n");
njn26f02512004-11-22 18:33:15 +0000112 VG_(tool_panic)("VG_(needs).shadow_memory need should be set to match TL_(shadow_ratio)\n");
fitzhardinge98abfc72003-12-16 02:05:15 +0000113 }
114
njn810086f2002-11-14 12:42:47 +0000115#undef CHECK_NOT
njn810086f2002-11-14 12:42:47 +0000116}
117
118/*--------------------------------------------------------------------*/
119/* Setting details */
120
121/* Use macro because they're so repetitive */
sewardjc0d8f682002-11-30 00:49:43 +0000122#define DETAILS(type, detail) \
123 extern void VG_(details_##detail)(type detail) \
124 { \
125 VG_(details).detail = detail; \
njn810086f2002-11-14 12:42:47 +0000126 }
127
sewardjc0d8f682002-11-30 00:49:43 +0000128DETAILS(Char*, name)
129DETAILS(Char*, version)
130DETAILS(Char*, description)
131DETAILS(Char*, copyright_author)
132DETAILS(Char*, bug_reports_to)
njn120281f2003-02-03 12:20:07 +0000133DETAILS(UInt, avg_translation_sizeB)
njn810086f2002-11-14 12:42:47 +0000134
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
145NEEDS(libc_freeres)
146NEEDS(core_errors)
njn95ec8702004-11-22 16:46:13 +0000147NEEDS(tool_errors)
njn810086f2002-11-14 12:42:47 +0000148NEEDS(basic_block_discards)
njn810086f2002-11-14 12:42:47 +0000149NEEDS(command_line_options)
150NEEDS(client_requests)
njn810086f2002-11-14 12:42:47 +0000151NEEDS(syscall_wrapper)
njn810086f2002-11-14 12:42:47 +0000152NEEDS(sanity_checks)
153NEEDS(data_syms)
fitzhardinge98abfc72003-12-16 02:05:15 +0000154NEEDS(shadow_memory)
njnfdc28af2003-02-24 10:36:48 +0000155
njn810086f2002-11-14 12:42:47 +0000156/*--------------------------------------------------------------------*/
njn810086f2002-11-14 12:42:47 +0000157/*--- end vg_needs.c ---*/
158/*--------------------------------------------------------------------*/
159
160