blob: baad2a32bf5e105f39c4f8da55d233f822dc582a [file] [log] [blame]
njn810086f2002-11-14 12:42:47 +00001
2/*--------------------------------------------------------------------*/
3/*--- Stuff relating to skin data structures. ---*/
4/*--- vg_needs.c ---*/
5/*--------------------------------------------------------------------*/
6
7/*
8 This file is part of Valgrind, an extensible x86 protected-mode
9 emulator for monitoring program execution on x86-Unixes.
10
nethercotebb1c9912004-01-04 16:43:23 +000011 Copyright (C) 2000-2004 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
32#include "vg_include.h"
33
34
35/* ---------------------------------------------------------------------
36 Skin data structure initialisation
37 ------------------------------------------------------------------ */
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,
51 .skin_errors = False,
52 .libc_freeres = False,
njn810086f2002-11-14 12:42:47 +000053 .basic_block_discards = False,
54 .shadow_regs = False,
55 .command_line_options = False,
56 .client_requests = False,
57 .extended_UCode = False,
58 .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)); \
njn120281f2003-02-03 12:20:07 +000071 VG_(skin_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");
90 VG_(skin_panic)("`new_mem_stack' should be defined\n");
91 }
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");
102 VG_(skin_panic)("`die_mem_stack' should be defined\n");
103 }
104
fitzhardinge98abfc72003-12-16 02:05:15 +0000105 if ( (VG_(defined_post_reg_write_syscall_return)() ||
106 VG_(defined_post_reg_write_deliver_signal)() ||
107 VG_(defined_post_reg_write_pthread_return)() ||
108 VG_(defined_post_reg_write_clientreq_return)() ||
109 VG_(defined_post_reg_write_clientcall_return)()) &&
njnd3040452003-05-19 15:04:06 +0000110 ! VG_(needs).shadow_regs)
111 {
nethercote137bc552003-11-14 17:47:54 +0000112 VG_(printf)("\nTool error: one of the `post_reg_write'\n"
njnd3040452003-05-19 15:04:06 +0000113 "events tracked, but `shadow_regs' need not set.\n");
114 VG_(skin_panic)("`shadow_regs' should be set\n");
115 }
116
fitzhardinge98abfc72003-12-16 02:05:15 +0000117 if (VG_(needs).shadow_memory != (VG_(get_shadow_size)() != 0)) {
118 if (VG_(get_shadow_size)() != 0)
119 VG_(printf)("\nTool error: tool allocated shadow memory, but apparently doesn't "
120 "need it.\n");
121 else
122 VG_(printf)("\nTool error: tool didn't allocated shadow memory, but apparently "
123 "needs it.\n");
124 VG_(skin_panic)("VG_(needs).shadow_memory need should be set to match SK_(shadow_ratio)\n");
125 }
126
njn810086f2002-11-14 12:42:47 +0000127#undef CHECK_NOT
128#undef INVALID_Bool
129}
130
131/*--------------------------------------------------------------------*/
132/* Setting details */
133
134/* Use macro because they're so repetitive */
sewardjc0d8f682002-11-30 00:49:43 +0000135#define DETAILS(type, detail) \
136 extern void VG_(details_##detail)(type detail) \
137 { \
138 VG_(details).detail = detail; \
njn810086f2002-11-14 12:42:47 +0000139 }
140
sewardjc0d8f682002-11-30 00:49:43 +0000141DETAILS(Char*, name)
142DETAILS(Char*, version)
143DETAILS(Char*, description)
144DETAILS(Char*, copyright_author)
145DETAILS(Char*, bug_reports_to)
njn120281f2003-02-03 12:20:07 +0000146DETAILS(UInt, avg_translation_sizeB)
njn810086f2002-11-14 12:42:47 +0000147
148/*--------------------------------------------------------------------*/
149/* Setting needs */
150
151/* Use macro because they're so repetitive */
152#define NEEDS(need) \
153 extern void VG_(needs_##need)(void) \
154 { \
155 VG_(needs).need = True; \
156 }
157
158NEEDS(libc_freeres)
159NEEDS(core_errors)
160NEEDS(skin_errors)
161NEEDS(basic_block_discards)
162NEEDS(shadow_regs)
163NEEDS(command_line_options)
164NEEDS(client_requests)
165NEEDS(extended_UCode)
166NEEDS(syscall_wrapper)
njn810086f2002-11-14 12:42:47 +0000167NEEDS(sanity_checks)
168NEEDS(data_syms)
fitzhardinge98abfc72003-12-16 02:05:15 +0000169NEEDS(shadow_memory)
njnfdc28af2003-02-24 10:36:48 +0000170
njn810086f2002-11-14 12:42:47 +0000171/*--------------------------------------------------------------------*/
172/* UCodeBlocks */
173
174Int VG_(get_num_instrs) ( UCodeBlock* cb )
175{
176 return cb->used;
177}
178
179Int VG_(get_num_temps) ( UCodeBlock* cb )
180{
181 return cb->nextTemp;
182}
183
184UInstr* VG_(get_instr) ( UCodeBlock* cb, Int i )
185{
186 return & cb->instrs[i];
187}
188
189UInstr* VG_(get_last_instr) ( UCodeBlock* cb )
190{
191 return & cb->instrs[cb->used-1];
192}
193
194/*--------------------------------------------------------------------*/
195/* Suppressions */
196
197SuppKind VG_(get_supp_kind) ( Supp* su )
198{
199 return su->skind;
200}
201
202Char* VG_(get_supp_string) ( Supp* su )
203{
204 return su->string;
205}
206
207void* VG_(get_supp_extra) ( Supp* su )
208{
209 return su->extra;
210}
211
212
213void VG_(set_supp_kind) ( Supp* su, SuppKind skind )
214{
215 su->skind = skind;
216}
217
218void VG_(set_supp_string) ( Supp* su, Char* string )
219{
220 su->string = string;
221}
222
223void VG_(set_supp_extra) ( Supp* su, void* extra )
224{
225 su->extra = extra;
226}
227
228/*--------------------------------------------------------------------*/
229/* Errors */
230
njnae17bec2003-01-28 19:59:38 +0000231ExeContext* VG_(get_error_where) ( Error* err )
232{
njn6d57f7d2003-02-06 08:17:08 +0000233 return err->where;
njnae17bec2003-01-28 19:59:38 +0000234}
235
njn810086f2002-11-14 12:42:47 +0000236ErrorKind VG_(get_error_kind) ( Error* err )
237{
238 return err->ekind;
239}
240
241Addr VG_(get_error_address) ( Error* err )
242{
243 return err->addr;
244}
245
246Char* VG_(get_error_string) ( Error* err )
247{
248 return err->string;
249}
250
251void* VG_(get_error_extra) ( Error* err )
252{
253 return err->extra;
254}
255
256/*--------------------------------------------------------------------*/
njn810086f2002-11-14 12:42:47 +0000257/*--- end vg_needs.c ---*/
258/*--------------------------------------------------------------------*/
259
260