blob: 42c9b7900768cdec3b82a70114d49fa6f262a4bd [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
njn8b8cecd2004-11-22 20:25:56 +000010## These are the parameterised functions in the core. Some/all default
11## definitions are overridden by the 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
njnae13f102005-03-12 06:23:46 +000020## Do initialisation that can be done before command line processing.
21void, pre_clo_init
22
fitzhardinge7e343cd2003-12-16 02:14:00 +000023## Do initialisation that can only be done after command line processing.
24void, post_clo_init
25
26## Instrument a basic block. Must be a true function, ie. the same input
27## always results in the same output, because basic blocks can be
28## retranslated. Unless you're doing something really strange...
sewardjd54babf2005-03-21 00:55:49 +000029IRBB*, instrument, IRBB* bb, VexGuestLayout* layout, IRType gWordTy, IRType hWordTy
fitzhardinge7e343cd2003-12-16 02:14:00 +000030
31## Finish up, print out any results, etc. `exitcode' is program's exit
njnabb14ad2004-11-24 16:57:16 +000032## code. The shadow can be found with VG_(get_exit_status_shadow)().
fitzhardinge7e343cd2003-12-16 02:14:00 +000033void, fini, Int exitcode
34
35
36## ------------------------------------------------------------------
37## VG_(needs).core_errors
38
39## (none needed)
40
41## ------------------------------------------------------------------
njn95ec8702004-11-22 16:46:13 +000042## VG_(needs).tool_errors
fitzhardinge7e343cd2003-12-16 02:14:00 +000043
44## Identify if two errors are equal, or equal enough. `res' indicates how
45## close is "close enough". `res' should be passed on as necessary, eg. if
46## the Error's `extra' part contains an ExeContext, `res' should be
47## passed to VG_(eq_ExeContext)() if the ExeContexts are considered. Other
48## than that, probably don't worry about it unless you have lots of very
49## similar errors occurring.
njnb126f732004-11-22 17:57:07 +000050Bool, eq_Error, VgRes res, Error* e1, Error* e2
fitzhardinge7e343cd2003-12-16 02:14:00 +000051
52## Print error context.
njnb126f732004-11-22 17:57:07 +000053void, pp_Error, Error* err
fitzhardinge7e343cd2003-12-16 02:14:00 +000054
55## Should fill in any details that could be postponed until after the
56## decision whether to ignore the error (ie. details not affecting the
njn26f02512004-11-22 18:33:15 +000057## result of TL_(eq_Error)()). This saves time when errors are ignored.
fitzhardinge7e343cd2003-12-16 02:14:00 +000058## Yuk.
59
60## Return value: must be the size of the `extra' part in bytes -- used by
61## the core to make a copy.
62UInt, update_extra, Error* err
63
64## Return value indicates recognition. If recognised, must set skind using
65## VG_(set_supp_kind)().
66Bool, recognised_suppression, Char* name, Supp* su
67
68## Read any extra info for this suppression kind. Most likely for filling
69## in the `extra' and `string' parts (with VG_(set_supp_{extra, string})())
70## of a suppression if necessary. Should return False if a syntax error
71## occurred, True otherwise.
72Bool, read_extra_suppression_info, Int fd, Char* buf, Int nBuf, Supp* su
73
74## This should just check the kinds match and maybe some stuff in the
75## `string' and `extra' field if appropriate (using VG_(get_supp_*)() to
76## get the relevant suppression parts).
77Bool, error_matches_suppression, Error* err, Supp* su
78
79## This should return the suppression name, for --gen-suppressions, or NULL
80## if that error type cannot be suppressed. This is the inverse of
njn26f02512004-11-22 18:33:15 +000081## TL_(recognised_suppression)().
fitzhardinge7e343cd2003-12-16 02:14:00 +000082Char*, get_error_name, Error* err
83
84## This should print any extra info for the error, for --gen-suppressions,
85## including the newline. This is the inverse of
njn26f02512004-11-22 18:33:15 +000086## TL_(read_extra_suppression_info)().
fitzhardinge7e343cd2003-12-16 02:14:00 +000087void, print_extra_suppression_info, Error* err
88
89
90## ------------------------------------------------------------------
91## VG_(needs).basic_block_discards
92
93## Should discard any information that pertains to specific basic blocks
94## or instructions within the address range given.
nethercote928a5f72004-11-03 18:10:37 +000095void, discard_basic_block_info, Addr a, SizeT size
fitzhardinge7e343cd2003-12-16 02:14:00 +000096
97
98## ------------------------------------------------------------------
fitzhardinge7e343cd2003-12-16 02:14:00 +000099## VG_(needs).command_line_options
100
101## Return True if option was recognised. Presumably sets some state to
102## record the option as well.
103Bool, process_cmd_line_option, Char* argv
104
nethercote996901a2004-08-03 13:29:09 +0000105## Print out command line usage for options for normal tool operation.
fitzhardinge7e343cd2003-12-16 02:14:00 +0000106void, print_usage
107
nethercote996901a2004-08-03 13:29:09 +0000108## Print out command line usage for options for debugging the tool.
fitzhardinge7e343cd2003-12-16 02:14:00 +0000109void, print_debug_usage
110
111## ------------------------------------------------------------------
112## VG_(needs).client_requests
113
114## If using client requests, the number of the first request should be equal
njnfc26ff92004-11-22 19:12:49 +0000115## to VG_USERREQ_TOOL_BASE('X', 'Y'), where 'X' and 'Y' form a suitable two
fitzhardinge7e343cd2003-12-16 02:14:00 +0000116## character identification for the string. The second and subsequent
117## requests should follow.
118
njnfc26ff92004-11-22 19:12:49 +0000119## This function should use the VG_IS_TOOL_USERREQ macro (in
nethercote996901a2004-08-03 13:29:09 +0000120## include/valgrind.h) to first check if it's a request for this tool. Then
fitzhardinge7e343cd2003-12-16 02:14:00 +0000121## should handle it if it's recognised (and return True), or return False if
122## not recognised. arg_block[0] holds the request number, any further args
123## from the request are in arg_block[1..]. 'ret' is for the return value...
124## it should probably be filled, if only with 0.
nethercoted1b64b22004-11-04 18:22:28 +0000125Bool, handle_client_request, ThreadId tid, UWord* arg_block, UWord* ret
fitzhardinge7e343cd2003-12-16 02:14:00 +0000126
127
128## ------------------------------------------------------------------
fitzhardinge7e343cd2003-12-16 02:14:00 +0000129## VG_(needs).syscall_wrapper
130
131## If either of the pre_ functions malloc() something to return, the
132## corresponding post_ function had better free() it!
133
njn31ebc3f2004-11-22 19:57:39 +0000134void, pre_syscall, ThreadId tid, UInt syscallno
135void, post_syscall, ThreadId tid, UInt syscallno, Int res
fitzhardinge7e343cd2003-12-16 02:14:00 +0000136
137
138## ---------------------------------------------------------------------
139## VG_(needs).sanity_checks
140
njn26f02512004-11-22 18:33:15 +0000141## Can be useful for ensuring a tool's correctness. TL_(cheap_sanity_check)
142## is called very frequently; TL_(expensive_sanity_check) is called less
fitzhardinge7e343cd2003-12-16 02:14:00 +0000143## frequently and can be more involved.
144Bool, cheap_sanity_check
145Bool, expensive_sanity_check
146
147
148## ================================================================================
149## Event tracking functions
150:track
151
152## Events happening in core to track. To be notified, pass a callback
153## function to the appropriate function. To ignore an event, don't do
njnd4795be2004-11-24 11:57:51 +0000154## anything (the default is for events to be ignored).
fitzhardinge7e343cd2003-12-16 02:14:00 +0000155
njnd4795be2004-11-24 11:57:51 +0000156## Note that most events aren't passed a ThreadId. If the event is one called
157## from generated code (eg. new_mem_stack_*), you can use
njn7400cfa2005-03-20 18:23:11 +0000158## VG_(get_running_tid)() to find it. Otherwise, it has to be passed in,
njnd4795be2004-11-24 11:57:51 +0000159## as in pre_mem_read, and so the event signature will require changing.
fitzhardinge7e343cd2003-12-16 02:14:00 +0000160
nethercote996901a2004-08-03 13:29:09 +0000161## Memory events (Nb: to track heap allocation/freeing, a tool must replace
fitzhardinge7e343cd2003-12-16 02:14:00 +0000162## malloc() et al. See above how to do this.)
163
164## These ones occur at startup, upon some signals, and upon some syscalls
nethercote451eae92004-11-02 13:06:32 +0000165void, new_mem_startup, Addr a, SizeT len, Bool rr, Bool ww, Bool xx
166void, new_mem_stack_signal, Addr a, SizeT len
167void, new_mem_brk, Addr a, SizeT len
168void, new_mem_mmap, Addr a, SizeT len, Bool rr, Bool ww, Bool xx
fitzhardinge7e343cd2003-12-16 02:14:00 +0000169
nethercote451eae92004-11-02 13:06:32 +0000170void, copy_mem_remap, Addr from, Addr to, SizeT len
171void, change_mem_mprotect, Addr a, SizeT len, Bool rr, Bool ww, Bool xx
172void, die_mem_stack_signal, Addr a, SizeT len
173void, die_mem_brk, Addr a, SizeT len
174void, die_mem_munmap, Addr a, SizeT len
fitzhardinge7e343cd2003-12-16 02:14:00 +0000175
nethercote996901a2004-08-03 13:29:09 +0000176## These ones are called when %esp changes. A tool could track these itself
fitzhardinge7e343cd2003-12-16 02:14:00 +0000177## (except for ban_mem_stack) but it's much easier to use the core's help.
178
179## The specialised ones are called in preference to the general one, if they
180## are defined. These functions are called a lot if they are used, so
181## specialising can optimise things significantly. If any of the
182## specialised cases are defined, the general case must be defined too.
183
njn9fb73db2005-03-27 01:55:21 +0000184## Nb: they must all use the VGA_REGPARM(n) attribute.
185VGA_REGPARM(1) void, new_mem_stack_4, Addr new_ESP
186VGA_REGPARM(1) void, new_mem_stack_8, Addr new_ESP
187VGA_REGPARM(1) void, new_mem_stack_12, Addr new_ESP
188VGA_REGPARM(1) void, new_mem_stack_16, Addr new_ESP
189VGA_REGPARM(1) void, new_mem_stack_32, Addr new_ESP
nethercote451eae92004-11-02 13:06:32 +0000190void, new_mem_stack, Addr a, SizeT len
fitzhardinge7e343cd2003-12-16 02:14:00 +0000191
njn9fb73db2005-03-27 01:55:21 +0000192VGA_REGPARM(1) void, die_mem_stack_4, Addr die_ESP
193VGA_REGPARM(1) void, die_mem_stack_8, Addr die_ESP
194VGA_REGPARM(1) void, die_mem_stack_12, Addr die_ESP
195VGA_REGPARM(1) void, die_mem_stack_16, Addr die_ESP
196VGA_REGPARM(1) void, die_mem_stack_32, Addr die_ESP
nethercote451eae92004-11-02 13:06:32 +0000197void, die_mem_stack, Addr a, SizeT len
fitzhardinge7e343cd2003-12-16 02:14:00 +0000198
199## Used for redzone at end of thread stacks
nethercote451eae92004-11-02 13:06:32 +0000200void, ban_mem_stack, Addr a, SizeT len
fitzhardinge7e343cd2003-12-16 02:14:00 +0000201
202## These ones occur around syscalls, signal handling, etc
njncf45fd42004-11-24 16:30:22 +0000203void, pre_mem_read, CorePart part, ThreadId tid, Char* s, Addr a, SizeT size
204void, pre_mem_read_asciiz,CorePart part, ThreadId tid, Char* s, Addr a
205void, pre_mem_write, CorePart part, ThreadId tid, Char* s, Addr a, SizeT size
206void, post_mem_write, CorePart part, ThreadId tid, Addr a, SizeT size
fitzhardinge7e343cd2003-12-16 02:14:00 +0000207
208
njnabb14ad2004-11-24 16:57:16 +0000209## Register events. Use VG_(set_shadow_state_area)() to set the shadow regs
210## for these events.
njncf45fd42004-11-24 16:30:22 +0000211
212void, pre_reg_read, CorePart part, ThreadId tid, Char* s, OffT guest_state_offset, SizeT size
213void, post_reg_write, CorePart part, ThreadId tid, OffT guest_state_offset, SizeT size
214
nethercote996901a2004-08-03 13:29:09 +0000215## This one is called for malloc() et al if they are replaced by a tool.
njncf45fd42004-11-24 16:30:22 +0000216void, post_reg_write_clientcall_return, ThreadId tid, OffT guest_state_offset, SizeT size, Addr f
fitzhardinge7e343cd2003-12-16 02:14:00 +0000217
218
219## Scheduler events (not exhaustive)
220void, thread_run, ThreadId tid
221
222
223## Thread events (not exhaustive)
224
225## Called during thread create, before the new thread has run any
226## instructions (or touched any memory).
227void, post_thread_create, ThreadId tid, ThreadId child
228void, post_thread_join, ThreadId joiner, ThreadId joinee
229
230
231## Mutex events (not exhaustive)
232## "void *mutex" is really a pthread_mutex *
233
234## Called before a thread can block while waiting for a mutex (called
235## regardless of whether the thread will block or not).
236void, pre_mutex_lock, ThreadId tid, void* mutex
237## Called once the thread actually holds the mutex (always paired with
238## pre_mutex_lock).
239void, post_mutex_lock, ThreadId tid, void* mutex
240## Called after a thread has released a mutex (no need for a corresponding
241## pre_mutex_unlock, because unlocking can't block).
242void, post_mutex_unlock, ThreadId tid, void* mutex
243
244## Signal events (not exhaustive)
245
246## ... pre_send_signal, post_send_signal ...
247
248## Called before a signal is delivered; `alt_stack' indicates if it is
249## delivered on an alternative stack.
250void, pre_deliver_signal, ThreadId tid, Int sigNo, Bool alt_stack
251## Called after a signal is delivered. Nb: unfortunately, if the signal
252## handler longjmps, this won't be called.
253void, post_deliver_signal, ThreadId tid, Int sigNo
254
255
256## Others... condition variable...
257## ...
258
259## Shadow memory management
260void, init_shadow_page, Addr p
261
262## ================================================================================
263## malloc and friends
264:malloc
sewardj2a99cf62004-11-24 10:44:19 +0000265void*, malloc, ThreadId tid, SizeT n
266void*, __builtin_new, ThreadId tid, SizeT n
267void*, __builtin_vec_new, ThreadId tid, SizeT n
268void*, memalign, ThreadId tid, SizeT align, SizeT n
269void*, calloc, ThreadId tid, SizeT nmemb, SizeT n
270void, free, ThreadId tid, void* p
271void, __builtin_delete, ThreadId tid, void* p
272void, __builtin_vec_delete, ThreadId tid, void* p
273void*, realloc, ThreadId tid, void* p, SizeT size