blob: deba9495102a93d3e16d8bfb6250fcac8e55cbed [file] [log] [blame]
sewardj024598e2008-09-18 14:43:05 +00001
2/*--------------------------------------------------------------------*/
3/*--- Ptrcheck: a pointer-use checker. ---*/
4/*--- This file coordinates the h_ and sg_ subtools. ---*/
5/*--- pc_main.c ---*/
6/*--------------------------------------------------------------------*/
7
8/*
9 This file is part of Ptrcheck, a Valgrind tool for checking pointer
10 use in programs.
11
12 Copyright (C) 2008-2008 OpenWorks Ltd
13 info@open-works.co.uk
14
15 This program is free software; you can redistribute it and/or
16 modify it under the terms of the GNU General Public License as
17 published by the Free Software Foundation; either version 2 of the
18 License, or (at your option) any later version.
19
20 This program is distributed in the hope that it will be useful, but
21 WITHOUT ANY WARRANTY; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23 General Public License for more details.
24
25 You should have received a copy of the GNU General Public License
26 along with this program; if not, write to the Free Software
27 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
28 02111-1307, USA.
29
30 The GNU General Public License is contained in the file COPYING.
31
32 Neither the names of the U.S. Department of Energy nor the
33 University of California nor the names of its contributors may be
34 used to endorse or promote products derived from this software
35 without prior written permission.
36*/
37
38#include "pub_tool_basics.h"
39#include "pub_tool_libcassert.h"
40#include "pub_tool_execontext.h"
41#include "pub_tool_tooliface.h"
42#include "pub_tool_options.h"
43
44//#include "h_list.h" // Seg
45#include "sg_main.h"
46#include "pc_common.h"
47#include "h_main.h"
48
49
50//////////////////////////////////////////////////////////////
51// //
52// //
53// //
54//////////////////////////////////////////////////////////////
55
56
57//////////////////////////////////////////////////////////////
58// //
59// main //
60// //
61//////////////////////////////////////////////////////////////
62
63static void pc_fini ( Int exitcode ) {
64 h_fini( exitcode );
65 sg_fini( exitcode );
66}
67
68static void pc_die_mem_stack ( Addr old_SP, SizeT len ) {
69 /* h_die_mem_stack( old_SP, len ); */
70 sg_die_mem_stack( old_SP, len );
71}
72
73static
74void pc_pre_thread_ll_create ( ThreadId parent, ThreadId child ) {
75 /* h_pre_thread_ll_create(); */
76 sg_pre_thread_ll_create(parent,child);
77}
78
79static void pc_pre_thread_first_insn ( ThreadId tid ) {
80 /* h_pre_thread_first_insn(tid); */
81 sg_pre_thread_first_insn(tid);
82}
83
84static
85void pc_new_mem_mmap ( Addr a, SizeT len,
86 Bool rr, Bool ww, Bool xx, ULong di_handle )
87{
88 h_new_mem_mmap(a, len, rr, ww, xx, di_handle);
89 sg_new_mem_mmap(a, len, rr, ww, xx, di_handle);
90}
91
92static
93void pc_new_mem_startup ( Addr a, SizeT len,
94 Bool rr, Bool ww, Bool xx, ULong di_handle )
95{
96 h_new_mem_startup(a, len, rr, ww, xx, di_handle);
97 sg_new_mem_startup(a, len, rr, ww, xx, di_handle);
98}
99
100static void pc_die_mem_munmap ( Addr a, SizeT len ) {
101 h_die_mem_munmap(a, len);
102 sg_die_mem_munmap(a, len);
103}
104
105static void pc_pre_mem_read ( CorePart part, ThreadId tid, Char* s,
106 Addr base, SizeT size ) {
107 h_pre_mem_access(part, tid, s, base, size );
108 /* sg_pre_mem_read(part, tid, s, base, size); */
109}
110
111static void pc_pre_mem_read_asciiz ( CorePart part, ThreadId tid,
112 Char* s, Addr lo )
113{
114 h_pre_mem_read_asciiz(part, tid, s, lo);
115 /* sg_pre_mem_read_asciiz(part, tid, s, lo); */
116}
117
118static void pc_pre_mem_write ( CorePart part, ThreadId tid, Char* s,
119 Addr base, SizeT size ) {
120 h_pre_mem_access(part, tid, s, base, size);
121 /* sg_pre_mem_write(part, tid, s, base, size); */
122}
123
124static void pc_post_clo_init ( void )
125{
126 h_post_clo_init();
127 sg_post_clo_init();
128}
129
130static void pc_pre_clo_init(void)
131{
132 VG_(details_name) ("exp-ptrcheck");
133 VG_(details_version) (NULL);
134 VG_(details_description) ("a heap, stack & global array "
135 "overrun detector");
136 VG_(details_copyright_author)(
137 "Copyright (C) 2003-2008, and GNU GPL'd, by OpenWorks Ltd et al.");
138 VG_(details_bug_reports_to) (VG_BUGS_TO);
139
140 VG_(basic_tool_funcs) (pc_post_clo_init,
141 h_instrument,
142 pc_fini);
143
144 VG_(needs_malloc_replacement)( h_replace_malloc,
145 h_replace___builtin_new,
146 h_replace___builtin_vec_new,
147 h_replace_memalign,
148 h_replace_calloc,
149 h_replace_free,
150 h_replace___builtin_delete,
151 h_replace___builtin_vec_delete,
152 h_replace_realloc,
153 0 /* no need for client heap redzones */ );
154
155 VG_(needs_var_info) ();
156
157 VG_(needs_core_errors) ();
158 VG_(needs_tool_errors) (pc_eq_Error,
159 pc_pp_Error,
160 True,/*show TIDs for errors*/
161 pc_update_Error_extra,
162 pc_is_recognised_suppression,
163 pc_read_extra_suppression_info,
164 pc_error_matches_suppression,
165 pc_get_error_name,
166 pc_print_extra_suppression_info);
167
168 VG_(needs_syscall_wrapper)( h_pre_syscall,
169 h_post_syscall );
170
171 VG_(needs_command_line_options)( pc_process_cmd_line_options,
172 pc_print_usage,
173 pc_print_debug_usage );
174
175 VG_(track_die_mem_stack) ( pc_die_mem_stack );
176 VG_(track_pre_thread_ll_create) ( pc_pre_thread_ll_create );
177 VG_(track_pre_thread_first_insn)( pc_pre_thread_first_insn );
178
179 VG_(track_new_mem_mmap) ( pc_new_mem_mmap );
180 VG_(track_new_mem_startup) ( pc_new_mem_startup);
181 VG_(track_die_mem_munmap) ( pc_die_mem_munmap );
182
183 VG_(track_pre_mem_read) ( pc_pre_mem_read );
184 VG_(track_pre_mem_read_asciiz) ( pc_pre_mem_read_asciiz );
185 VG_(track_pre_mem_write) ( pc_pre_mem_write );
186
187 VG_(track_post_reg_write_clientcall_return) ( h_post_reg_write_clientcall );
188 VG_(track_post_reg_write)( h_post_reg_write_demux );
189
190 h_pre_clo_init();
191 sg_pre_clo_init();
192
193 VG_(clo_vex_control).iropt_unroll_thresh = 0;
194 VG_(clo_vex_control).guest_chase_thresh = 0;
195}
196
197VG_DETERMINE_INTERFACE_VERSION(pc_pre_clo_init)
198
199
200/*--------------------------------------------------------------------*/
201/*--- end pc_main.c ---*/
202/*--------------------------------------------------------------------*/