blob: b80077083d441811d5cc708b01f5126d3997e9cf [file] [log] [blame]
fitzhardinge7e343cd2003-12-16 02:14:00 +00001# Tool interface functions
2# The format for an interface function definition is:
3# return_type, func_name, type arg, type arg
4# If the function has no arguments, specify no arguments (rather than void)
5#
6# Comments starting with "##" are turned into C comments in the output
7#
8# Lines starting with : set the prefix
9
10## These are the parameterised functions in the core. The default definitions
nethercote996901a2004-08-03 13:29:09 +000011## are overridden by LD_PRELOADed tool version. At the very least, a tool
fitzhardinge7e343cd2003-12-16 02:14:00 +000012## must define the fundamental template functions. Depending on what needs
13## are set, extra template functions will be used too. Functions are
14## grouped under the needs that govern their use.
15
16:tool
17## ------------------------------------------------------------------
18## Fundamental template functions
19
20## Do initialisation that can only be done after command line processing.
21void, post_clo_init
22
23## Instrument a basic block. Must be a true function, ie. the same input
24## always results in the same output, because basic blocks can be
25## retranslated. Unless you're doing something really strange...
26## 'orig_addr' is the address of the first instruction in the block.
27UCodeBlock*, instrument, UCodeBlock* cb, Addr orig_addr
28
29## Finish up, print out any results, etc. `exitcode' is program's exit
30## code. The shadow (if the `shadow_regs' need is set) can be found with
nethercote15218bd2004-09-11 15:11:47 +000031## VG_(get_exit_status_shadow)().
fitzhardinge7e343cd2003-12-16 02:14:00 +000032void, fini, Int exitcode
33
34
35## ------------------------------------------------------------------
36## VG_(needs).core_errors
37
38## (none needed)
39
40## ------------------------------------------------------------------
41## VG_(needs).skin_errors
42
43## Identify if two errors are equal, or equal enough. `res' indicates how
44## close is "close enough". `res' should be passed on as necessary, eg. if
45## the Error's `extra' part contains an ExeContext, `res' should be
46## passed to VG_(eq_ExeContext)() if the ExeContexts are considered. Other
47## than that, probably don't worry about it unless you have lots of very
48## similar errors occurring.
49Bool, eq_SkinError, VgRes res, Error* e1, Error* e2
50
51## Print error context.
52void, pp_SkinError, Error* err
53
54## Should fill in any details that could be postponed until after the
55## decision whether to ignore the error (ie. details not affecting the
56## result of SK_(eq_SkinError)()). This saves time when errors are ignored.
57## Yuk.
58
59## Return value: must be the size of the `extra' part in bytes -- used by
60## the core to make a copy.
61UInt, update_extra, Error* err
62
63## Return value indicates recognition. If recognised, must set skind using
64## VG_(set_supp_kind)().
65Bool, recognised_suppression, Char* name, Supp* su
66
67## Read any extra info for this suppression kind. Most likely for filling
68## in the `extra' and `string' parts (with VG_(set_supp_{extra, string})())
69## of a suppression if necessary. Should return False if a syntax error
70## occurred, True otherwise.
71Bool, read_extra_suppression_info, Int fd, Char* buf, Int nBuf, Supp* su
72
73## This should just check the kinds match and maybe some stuff in the
74## `string' and `extra' field if appropriate (using VG_(get_supp_*)() to
75## get the relevant suppression parts).
76Bool, error_matches_suppression, Error* err, Supp* su
77
78## This should return the suppression name, for --gen-suppressions, or NULL
79## if that error type cannot be suppressed. This is the inverse of
80## SK_(recognised_suppression)().
81Char*, get_error_name, Error* err
82
83## This should print any extra info for the error, for --gen-suppressions,
84## including the newline. This is the inverse of
85## SK_(read_extra_suppression_info)().
86void, print_extra_suppression_info, Error* err
87
88
89## ------------------------------------------------------------------
90## VG_(needs).basic_block_discards
91
92## Should discard any information that pertains to specific basic blocks
93## or instructions within the address range given.
nethercote928a5f72004-11-03 18:10:37 +000094void, discard_basic_block_info, Addr a, SizeT size
fitzhardinge7e343cd2003-12-16 02:14:00 +000095
96
97## ------------------------------------------------------------------
98## VG_(needs).shadow_regs
99
100## No functions must be defined, but the post_reg[s]_write_* events should
101## be tracked.
102
103## ------------------------------------------------------------------
104## VG_(needs).command_line_options
105
106## Return True if option was recognised. Presumably sets some state to
107## record the option as well.
108Bool, process_cmd_line_option, Char* argv
109
nethercote996901a2004-08-03 13:29:09 +0000110## Print out command line usage for options for normal tool operation.
fitzhardinge7e343cd2003-12-16 02:14:00 +0000111void, print_usage
112
nethercote996901a2004-08-03 13:29:09 +0000113## Print out command line usage for options for debugging the tool.
fitzhardinge7e343cd2003-12-16 02:14:00 +0000114void, print_debug_usage
115
116## ------------------------------------------------------------------
117## VG_(needs).client_requests
118
119## If using client requests, the number of the first request should be equal
120## to VG_USERREQ_SKIN_BASE('X', 'Y'), where 'X' and 'Y' form a suitable two
121## character identification for the string. The second and subsequent
122## requests should follow.
123
124## This function should use the VG_IS_SKIN_USERREQ macro (in
nethercote996901a2004-08-03 13:29:09 +0000125## include/valgrind.h) to first check if it's a request for this tool. Then
fitzhardinge7e343cd2003-12-16 02:14:00 +0000126## should handle it if it's recognised (and return True), or return False if
127## not recognised. arg_block[0] holds the request number, any further args
128## from the request are in arg_block[1..]. 'ret' is for the return value...
129## it should probably be filled, if only with 0.
130Bool, handle_client_request, ThreadId tid, UInt* arg_block, UInt* ret
131
132
133## ------------------------------------------------------------------
134## VG_(needs).extends_UCode
135
136## 'X' prefix indicates eXtended UCode.
137Int, get_Xreg_usage, UInstr* u, Tag tag, Int* regs, Bool* isWrites
138void, emit_XUInstr, UInstr* u, RRegSet regs_live_before
139Bool, sane_XUInstr, Bool beforeRA, Bool beforeLiveness, UInstr* u
140Char *, name_XUOpcode, Opcode opc
141void, pp_XUInstr, UInstr* u
142
143
144## ------------------------------------------------------------------
145## VG_(needs).syscall_wrapper
146
147## If either of the pre_ functions malloc() something to return, the
148## corresponding post_ function had better free() it!
149
150void *, pre_syscall, ThreadId tid, UInt syscallno, Bool is_blocking
151void, post_syscall, ThreadId tid, UInt syscallno, void* pre_result, Int res, Bool is_blocking
152
153
154## ---------------------------------------------------------------------
155## VG_(needs).sanity_checks
156
nethercote996901a2004-08-03 13:29:09 +0000157## Can be useful for ensuring a tool's correctness. SK_(cheap_sanity_check)
fitzhardinge7e343cd2003-12-16 02:14:00 +0000158## is called very frequently; SK_(expensive_sanity_check) is called less
159## frequently and can be more involved.
160Bool, cheap_sanity_check
161Bool, expensive_sanity_check
162
163
164## ================================================================================
165## Event tracking functions
166:track
167
168## Events happening in core to track. To be notified, pass a callback
169## function to the appropriate function. To ignore an event, don't do
170## anything (default is for events to be ignored).
171
172## Note that most events aren't passed a ThreadId. To find out the ThreadId
173## of the affected thread, use VG_(get_current_or_recent_tid)(). For the
174## ones passed a ThreadId, use that instead, since
175## VG_(get_current_or_recent_tid)() might not give the right ThreadId in
176## that case.
177
nethercote996901a2004-08-03 13:29:09 +0000178## Memory events (Nb: to track heap allocation/freeing, a tool must replace
fitzhardinge7e343cd2003-12-16 02:14:00 +0000179## malloc() et al. See above how to do this.)
180
181## These ones occur at startup, upon some signals, and upon some syscalls
nethercote451eae92004-11-02 13:06:32 +0000182void, new_mem_startup, Addr a, SizeT len, Bool rr, Bool ww, Bool xx
183void, new_mem_stack_signal, Addr a, SizeT len
184void, new_mem_brk, Addr a, SizeT len
185void, new_mem_mmap, Addr a, SizeT len, Bool rr, Bool ww, Bool xx
fitzhardinge7e343cd2003-12-16 02:14:00 +0000186
nethercote451eae92004-11-02 13:06:32 +0000187void, copy_mem_remap, Addr from, Addr to, SizeT len
188void, change_mem_mprotect, Addr a, SizeT len, Bool rr, Bool ww, Bool xx
189void, die_mem_stack_signal, Addr a, SizeT len
190void, die_mem_brk, Addr a, SizeT len
191void, die_mem_munmap, Addr a, SizeT len
fitzhardinge7e343cd2003-12-16 02:14:00 +0000192
nethercote996901a2004-08-03 13:29:09 +0000193## These ones are called when %esp changes. A tool could track these itself
fitzhardinge7e343cd2003-12-16 02:14:00 +0000194## (except for ban_mem_stack) but it's much easier to use the core's help.
195
196## The specialised ones are called in preference to the general one, if they
197## are defined. These functions are called a lot if they are used, so
198## specialising can optimise things significantly. If any of the
199## specialised cases are defined, the general case must be defined too.
200
nethercoteeec46302004-08-23 15:06:23 +0000201## Nb: they must all use the REGPARM(n) attribute.
fitzhardinge7e343cd2003-12-16 02:14:00 +0000202void, new_mem_stack_4, Addr new_ESP
203void, new_mem_stack_8, Addr new_ESP
204void, new_mem_stack_12, Addr new_ESP
205void, new_mem_stack_16, Addr new_ESP
206void, new_mem_stack_32, Addr new_ESP
nethercote451eae92004-11-02 13:06:32 +0000207void, new_mem_stack, Addr a, SizeT len
fitzhardinge7e343cd2003-12-16 02:14:00 +0000208
209void, die_mem_stack_4, Addr die_ESP
210void, die_mem_stack_8, Addr die_ESP
211void, die_mem_stack_12, Addr die_ESP
212void, die_mem_stack_16, Addr die_ESP
213void, die_mem_stack_32, Addr die_ESP
nethercote451eae92004-11-02 13:06:32 +0000214void, die_mem_stack, Addr a, SizeT len
fitzhardinge7e343cd2003-12-16 02:14:00 +0000215
216## Used for redzone at end of thread stacks
nethercote451eae92004-11-02 13:06:32 +0000217void, ban_mem_stack, Addr a, SizeT len
fitzhardinge7e343cd2003-12-16 02:14:00 +0000218
219## These ones occur around syscalls, signal handling, etc
nethercote451eae92004-11-02 13:06:32 +0000220void, pre_mem_read, CorePart part, ThreadId tid, Char* s, Addr a, SizeT size
fitzhardinge7e343cd2003-12-16 02:14:00 +0000221void, pre_mem_read_asciiz, CorePart part, ThreadId tid, Char* s, Addr a
nethercote451eae92004-11-02 13:06:32 +0000222void, pre_mem_write, CorePart part, ThreadId tid, Char* s, Addr a, SizeT size
fitzhardinge7e343cd2003-12-16 02:14:00 +0000223## Not implemented yet -- have to add in lots of places, which is a
224## pain. Won't bother unless/until there's a need.
nethercote451eae92004-11-02 13:06:32 +0000225## void (*post_mem_read) ( ThreadState* tst, Char* s, Addr a, SizeT size );
226void, post_mem_write, Addr a, SizeT size
fitzhardinge7e343cd2003-12-16 02:14:00 +0000227
228
229## Register events -- if `shadow_regs' need is set, all should probably be
230## used. Use VG_(set_thread_shadow_archreg)() to set the shadow of the
231## changed register.
232
233## Use VG_(set_shadow_archreg)() to set the eight general purpose regs,
234## and use VG_(set_shadow_eflags)() to set eflags.
235void, post_regs_write_init, void
236
237## Use VG_(set_thread_shadow_archreg)() to set the shadow regs for these
238## events.
239void, post_reg_write_syscall_return, ThreadId tid, UInt reg
240void, post_reg_write_deliver_signal, ThreadId tid, UInt reg
241void, post_reg_write_pthread_return, ThreadId tid, UInt reg
242void, post_reg_write_clientreq_return, ThreadId tid, UInt reg
nethercote996901a2004-08-03 13:29:09 +0000243## This one is called for malloc() et al if they are replaced by a tool.
fitzhardinge7e343cd2003-12-16 02:14:00 +0000244void, post_reg_write_clientcall_return, ThreadId tid, UInt reg, Addr f
245
246
247## Scheduler events (not exhaustive)
248void, thread_run, ThreadId tid
249
250
251## Thread events (not exhaustive)
252
253## Called during thread create, before the new thread has run any
254## instructions (or touched any memory).
255void, post_thread_create, ThreadId tid, ThreadId child
256void, post_thread_join, ThreadId joiner, ThreadId joinee
257
258
259## Mutex events (not exhaustive)
260## "void *mutex" is really a pthread_mutex *
261
262## Called before a thread can block while waiting for a mutex (called
263## regardless of whether the thread will block or not).
264void, pre_mutex_lock, ThreadId tid, void* mutex
265## Called once the thread actually holds the mutex (always paired with
266## pre_mutex_lock).
267void, post_mutex_lock, ThreadId tid, void* mutex
268## Called after a thread has released a mutex (no need for a corresponding
269## pre_mutex_unlock, because unlocking can't block).
270void, post_mutex_unlock, ThreadId tid, void* mutex
271
272## Signal events (not exhaustive)
273
274## ... pre_send_signal, post_send_signal ...
275
276## Called before a signal is delivered; `alt_stack' indicates if it is
277## delivered on an alternative stack.
278void, pre_deliver_signal, ThreadId tid, Int sigNo, Bool alt_stack
279## Called after a signal is delivered. Nb: unfortunately, if the signal
280## handler longjmps, this won't be called.
281void, post_deliver_signal, ThreadId tid, Int sigNo
282
283
284## Others... condition variable...
285## ...
286
287## Shadow memory management
288void, init_shadow_page, Addr p
289
290## ================================================================================
291## malloc and friends
292:malloc
nethercote7ac7f7b2004-11-02 12:36:02 +0000293void*, malloc, SizeT n
294void*, __builtin_new, SizeT n
295void*, __builtin_vec_new, SizeT n
296void*, memalign, SizeT align, SizeT n
297void*, calloc, SizeT nmemb, SizeT n
fitzhardinge7e343cd2003-12-16 02:14:00 +0000298void, free, void* p
299void, __builtin_delete, void* p
300void, __builtin_vec_delete, void* p
nethercote7ac7f7b2004-11-02 12:36:02 +0000301void*, realloc, void* p, SizeT size