blob: 359eb520b5f7f7c8fd86339f2719640aa6912ffc [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.
sewardj8b635a42004-11-22 19:01:47 +000027IRBB*, instrument, IRBB* bb, VexGuestLayout* layout, IRType hWordTy
fitzhardinge7e343cd2003-12-16 02:14:00 +000028
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## ------------------------------------------------------------------
njn95ec8702004-11-22 16:46:13 +000041## VG_(needs).tool_errors
fitzhardinge7e343cd2003-12-16 02:14:00 +000042
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.
njnb126f732004-11-22 17:57:07 +000049Bool, eq_Error, VgRes res, Error* e1, Error* e2
fitzhardinge7e343cd2003-12-16 02:14:00 +000050
51## Print error context.
njnb126f732004-11-22 17:57:07 +000052void, pp_Error, Error* err
fitzhardinge7e343cd2003-12-16 02:14:00 +000053
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
njn26f02512004-11-22 18:33:15 +000056## result of TL_(eq_Error)()). This saves time when errors are ignored.
fitzhardinge7e343cd2003-12-16 02:14:00 +000057## 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
njn26f02512004-11-22 18:33:15 +000080## TL_(recognised_suppression)().
fitzhardinge7e343cd2003-12-16 02:14:00 +000081Char*, 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
njn26f02512004-11-22 18:33:15 +000085## TL_(read_extra_suppression_info)().
fitzhardinge7e343cd2003-12-16 02:14:00 +000086void, 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
njnfc26ff92004-11-22 19:12:49 +0000120## to VG_USERREQ_TOOL_BASE('X', 'Y'), where 'X' and 'Y' form a suitable two
fitzhardinge7e343cd2003-12-16 02:14:00 +0000121## character identification for the string. The second and subsequent
122## requests should follow.
123
njnfc26ff92004-11-22 19:12:49 +0000124## This function should use the VG_IS_TOOL_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.
nethercoted1b64b22004-11-04 18:22:28 +0000130Bool, handle_client_request, ThreadId tid, UWord* arg_block, UWord* ret
fitzhardinge7e343cd2003-12-16 02:14:00 +0000131
132
133## ------------------------------------------------------------------
fitzhardinge7e343cd2003-12-16 02:14:00 +0000134## VG_(needs).syscall_wrapper
135
136## If either of the pre_ functions malloc() something to return, the
137## corresponding post_ function had better free() it!
138
njn31ebc3f2004-11-22 19:57:39 +0000139void, pre_syscall, ThreadId tid, UInt syscallno
140void, post_syscall, ThreadId tid, UInt syscallno, Int res
fitzhardinge7e343cd2003-12-16 02:14:00 +0000141
142
143## ---------------------------------------------------------------------
144## VG_(needs).sanity_checks
145
njn26f02512004-11-22 18:33:15 +0000146## Can be useful for ensuring a tool's correctness. TL_(cheap_sanity_check)
147## is called very frequently; TL_(expensive_sanity_check) is called less
fitzhardinge7e343cd2003-12-16 02:14:00 +0000148## frequently and can be more involved.
149Bool, cheap_sanity_check
150Bool, expensive_sanity_check
151
152
153## ================================================================================
154## Event tracking functions
155:track
156
157## Events happening in core to track. To be notified, pass a callback
158## function to the appropriate function. To ignore an event, don't do
159## anything (default is for events to be ignored).
160
161## Note that most events aren't passed a ThreadId. To find out the ThreadId
162## of the affected thread, use VG_(get_current_or_recent_tid)(). For the
163## ones passed a ThreadId, use that instead, since
164## VG_(get_current_or_recent_tid)() might not give the right ThreadId in
165## that case.
166
nethercote996901a2004-08-03 13:29:09 +0000167## Memory events (Nb: to track heap allocation/freeing, a tool must replace
fitzhardinge7e343cd2003-12-16 02:14:00 +0000168## malloc() et al. See above how to do this.)
169
170## These ones occur at startup, upon some signals, and upon some syscalls
nethercote451eae92004-11-02 13:06:32 +0000171void, new_mem_startup, Addr a, SizeT len, Bool rr, Bool ww, Bool xx
172void, new_mem_stack_signal, Addr a, SizeT len
173void, new_mem_brk, Addr a, SizeT len
174void, new_mem_mmap, Addr a, SizeT len, Bool rr, Bool ww, Bool xx
fitzhardinge7e343cd2003-12-16 02:14:00 +0000175
nethercote451eae92004-11-02 13:06:32 +0000176void, copy_mem_remap, Addr from, Addr to, SizeT len
177void, change_mem_mprotect, Addr a, SizeT len, Bool rr, Bool ww, Bool xx
178void, die_mem_stack_signal, Addr a, SizeT len
179void, die_mem_brk, Addr a, SizeT len
180void, die_mem_munmap, Addr a, SizeT len
fitzhardinge7e343cd2003-12-16 02:14:00 +0000181
nethercote996901a2004-08-03 13:29:09 +0000182## These ones are called when %esp changes. A tool could track these itself
fitzhardinge7e343cd2003-12-16 02:14:00 +0000183## (except for ban_mem_stack) but it's much easier to use the core's help.
184
185## The specialised ones are called in preference to the general one, if they
186## are defined. These functions are called a lot if they are used, so
187## specialising can optimise things significantly. If any of the
188## specialised cases are defined, the general case must be defined too.
189
nethercoteeec46302004-08-23 15:06:23 +0000190## Nb: they must all use the REGPARM(n) attribute.
fitzhardinge7e343cd2003-12-16 02:14:00 +0000191void, new_mem_stack_4, Addr new_ESP
192void, new_mem_stack_8, Addr new_ESP
193void, new_mem_stack_12, Addr new_ESP
194void, new_mem_stack_16, Addr new_ESP
195void, new_mem_stack_32, Addr new_ESP
nethercote451eae92004-11-02 13:06:32 +0000196void, new_mem_stack, Addr a, SizeT len
fitzhardinge7e343cd2003-12-16 02:14:00 +0000197
198void, die_mem_stack_4, Addr die_ESP
199void, die_mem_stack_8, Addr die_ESP
200void, die_mem_stack_12, Addr die_ESP
201void, die_mem_stack_16, Addr die_ESP
202void, die_mem_stack_32, Addr die_ESP
nethercote451eae92004-11-02 13:06:32 +0000203void, die_mem_stack, Addr a, SizeT len
fitzhardinge7e343cd2003-12-16 02:14:00 +0000204
205## Used for redzone at end of thread stacks
nethercote451eae92004-11-02 13:06:32 +0000206void, ban_mem_stack, Addr a, SizeT len
fitzhardinge7e343cd2003-12-16 02:14:00 +0000207
208## These ones occur around syscalls, signal handling, etc
nethercote451eae92004-11-02 13:06:32 +0000209void, pre_mem_read, CorePart part, ThreadId tid, Char* s, Addr a, SizeT size
fitzhardinge7e343cd2003-12-16 02:14:00 +0000210void, pre_mem_read_asciiz, CorePart part, ThreadId tid, Char* s, Addr a
nethercote451eae92004-11-02 13:06:32 +0000211void, pre_mem_write, CorePart part, ThreadId tid, Char* s, Addr a, SizeT size
fitzhardinge7e343cd2003-12-16 02:14:00 +0000212## Not implemented yet -- have to add in lots of places, which is a
213## pain. Won't bother unless/until there's a need.
nethercote451eae92004-11-02 13:06:32 +0000214## void (*post_mem_read) ( ThreadState* tst, Char* s, Addr a, SizeT size );
215void, post_mem_write, Addr a, SizeT size
fitzhardinge7e343cd2003-12-16 02:14:00 +0000216
217
218## Register events -- if `shadow_regs' need is set, all should probably be
219## used. Use VG_(set_thread_shadow_archreg)() to set the shadow of the
220## changed register.
221
nethercote8b76fe52004-11-08 19:20:09 +0000222void, pre_reg_read, CorePart part, ThreadId tid, Char* s, UInt reg, SizeT size
223
fitzhardinge7e343cd2003-12-16 02:14:00 +0000224## Use VG_(set_shadow_archreg)() to set the eight general purpose regs,
225## and use VG_(set_shadow_eflags)() to set eflags.
226void, post_regs_write_init, void
227
228## Use VG_(set_thread_shadow_archreg)() to set the shadow regs for these
229## events.
230void, post_reg_write_syscall_return, ThreadId tid, UInt reg
231void, post_reg_write_deliver_signal, ThreadId tid, UInt reg
232void, post_reg_write_pthread_return, ThreadId tid, UInt reg
233void, post_reg_write_clientreq_return, ThreadId tid, UInt reg
nethercote996901a2004-08-03 13:29:09 +0000234## This one is called for malloc() et al if they are replaced by a tool.
fitzhardinge7e343cd2003-12-16 02:14:00 +0000235void, post_reg_write_clientcall_return, ThreadId tid, UInt reg, Addr f
236
237
238## Scheduler events (not exhaustive)
239void, thread_run, ThreadId tid
240
241
242## Thread events (not exhaustive)
243
244## Called during thread create, before the new thread has run any
245## instructions (or touched any memory).
246void, post_thread_create, ThreadId tid, ThreadId child
247void, post_thread_join, ThreadId joiner, ThreadId joinee
248
249
250## Mutex events (not exhaustive)
251## "void *mutex" is really a pthread_mutex *
252
253## Called before a thread can block while waiting for a mutex (called
254## regardless of whether the thread will block or not).
255void, pre_mutex_lock, ThreadId tid, void* mutex
256## Called once the thread actually holds the mutex (always paired with
257## pre_mutex_lock).
258void, post_mutex_lock, ThreadId tid, void* mutex
259## Called after a thread has released a mutex (no need for a corresponding
260## pre_mutex_unlock, because unlocking can't block).
261void, post_mutex_unlock, ThreadId tid, void* mutex
262
263## Signal events (not exhaustive)
264
265## ... pre_send_signal, post_send_signal ...
266
267## Called before a signal is delivered; `alt_stack' indicates if it is
268## delivered on an alternative stack.
269void, pre_deliver_signal, ThreadId tid, Int sigNo, Bool alt_stack
270## Called after a signal is delivered. Nb: unfortunately, if the signal
271## handler longjmps, this won't be called.
272void, post_deliver_signal, ThreadId tid, Int sigNo
273
274
275## Others... condition variable...
276## ...
277
278## Shadow memory management
279void, init_shadow_page, Addr p
280
281## ================================================================================
282## malloc and friends
283:malloc
nethercote7ac7f7b2004-11-02 12:36:02 +0000284void*, malloc, SizeT n
285void*, __builtin_new, SizeT n
286void*, __builtin_vec_new, SizeT n
287void*, memalign, SizeT align, SizeT n
288void*, calloc, SizeT nmemb, SizeT n
fitzhardinge7e343cd2003-12-16 02:14:00 +0000289void, free, void* p
290void, __builtin_delete, void* p
291void, __builtin_vec_delete, void* p
nethercote7ac7f7b2004-11-02 12:36:02 +0000292void*, realloc, void* p, SizeT size