blob: 2c2f59698227e9a20f68f3128aa120b42ffcedf1 [file] [log] [blame]
njnc9539842002-10-02 13:26:35 +00001
njn25e49d8e72002-09-23 09:36:25 +00002/*--------------------------------------------------------------------*/
njnd99644d2006-04-07 11:52:55 +00003/*--- An example Valgrind tool. lk_main.c ---*/
njn25e49d8e72002-09-23 09:36:25 +00004/*--------------------------------------------------------------------*/
5
6/*
nethercote137bc552003-11-14 17:47:54 +00007 This file is part of Lackey, an example Valgrind tool that does
njnd99644d2006-04-07 11:52:55 +00008 some simple program measurement and tracing.
njn25e49d8e72002-09-23 09:36:25 +00009
sewardj9ebd6e02007-01-08 06:01:59 +000010 Copyright (C) 2002-2007 Nicholas Nethercote
njn2bc10122005-05-08 02:10:27 +000011 njn@valgrind.org
njn25e49d8e72002-09-23 09:36:25 +000012
13 This program is free software; you can redistribute it and/or
14 modify it under the terms of the GNU General Public License as
15 published by the Free Software Foundation; either version 2 of the
16 License, or (at your option) any later version.
17
18 This program is distributed in the hope that it will be useful, but
19 WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 General Public License for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software
25 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
26 02111-1307, USA.
27
28 The GNU General Public License is contained in the file COPYING.
29*/
30
njnfd73ebb2005-12-30 22:39:58 +000031// This tool shows how to do some basic instrumentation.
32//
sewardj5d1c9012007-02-12 08:42:13 +000033// There are four kinds of instrumentation it can do. They can be turned
njnd99644d2006-04-07 11:52:55 +000034// on/off independently with command line options:
35//
36// * --basic-counts : do basic counts, eg. number of instructions
37// executed, jumps executed, etc.
38// * --detailed-counts: do more detailed counts: number of loads, stores
39// and ALU operations of different sizes.
40// * --trace-mem=yes: trace all (data) memory accesses.
sewardj5d1c9012007-02-12 08:42:13 +000041// * --trace-superblocks=yes:
42// trace all superblock entries. Mostly of interest
43// to the Valgrind developers.
njnd99644d2006-04-07 11:52:55 +000044//
45// The code for each kind of instrumentation is guarded by a clo_* variable:
sewardj5d1c9012007-02-12 08:42:13 +000046// clo_basic_counts, clo_detailed_counts, clo_trace_mem and clo_trace_sbs.
njnd99644d2006-04-07 11:52:55 +000047//
48// If you want to modify any of the instrumentation code, look for the code
49// that is guarded by the relevant clo_* variable (eg. clo_trace_mem)
50// If you're not interested in the other kinds of instrumentation you can
51// remove them. If you want to do more complex modifications, please read
52// VEX/pub/libvex_ir.h to understand the intermediate representation.
53//
54//
55// Specific Details about --trace-mem=yes
56// --------------------------------------
njneaf0ca92006-04-09 01:23:29 +000057// Lackey's --trace-mem code is a good starting point for building Valgrind
58// tools that act on memory loads and stores. It also could be used as is,
59// with its output used as input to a post-mortem processing step. However,
60// because memory traces can be very large, online analysis is generally
61// better.
njnfd73ebb2005-12-30 22:39:58 +000062//
njneaf0ca92006-04-09 01:23:29 +000063// It prints memory data access traces that look like this:
64//
sewardj5d1c9012007-02-12 08:42:13 +000065// I 0023C790,2 # instruction read at 0x0023C790 of size 2
66// I 0023C792,5
67// S BE80199C,4 # data store at 0xBE80199C of size 4
68// I 0025242B,3
69// L BE801950,4 # data load at 0xBE801950 of size 4
70// I 0023D476,7
71// M 0025747C,1 # data modify at 0x0025747C of size 1
72// I 0023DC20,2
73// L 00254962,1
74// L BE801FB3,1
75// I 00252305,1
76// L 00254AEB,1
77// S 00257998,1
njneaf0ca92006-04-09 01:23:29 +000078//
79// Every instruction executed has an "instr" event representing it.
80// Instructions that do memory accesses are followed by one or more "load",
81// "store" or "modify" events. Some instructions do more than one load or
82// store, as in the last two examples in the above trace.
83//
84// Here are some examples of x86 instructions that do different combinations
85// of loads, stores, and modifies.
86//
87// Instruction Memory accesses Event sequence
88// ----------- --------------- --------------
89// add %eax, %ebx No loads or stores instr
90//
91// movl (%eax), %ebx loads (%eax) instr, load
92//
93// movl %eax, (%ebx) stores (%ebx) instr, store
94//
95// incl (%ecx) modifies (%ecx) instr, modify
96//
97// cmpsb loads (%esi), loads(%edi) instr, load, load
98//
99// call*l (%edx) loads (%edx), stores -4(%esp) instr, load, store
100// pushl (%edx) loads (%edx), stores -4(%esp) instr, load, store
101// movsw loads (%esi), stores (%edi) instr, load, store
102//
103// Instructions using x86 "rep" prefixes are traced as if they are repeated
104// N times.
105//
106// Lackey with --trace-mem gives good traces, but they are not perfect, for
107// the following reasons:
108//
109// - It does not trace into the OS kernel, so system calls and other kernel
110// operations (eg. some scheduling and signal handling code) are ignored.
111//
njne8d217d2006-10-18 23:46:26 +0000112// - It could model loads and stores done at the system call boundary using
113// the pre_mem_read/post_mem_write events. For example, if you call
114// fstat() you know that the passed in buffer has been written. But it
115// currently does not do this.
116//
117// - Valgrind replaces some code (not much) with its own, notably parts of
118// code for scheduling operations and signal handling. This code is not
119// traced.
njneaf0ca92006-04-09 01:23:29 +0000120//
121// - There is no consideration of virtual-to-physical address mapping.
122// This may not matter for many purposes.
123//
124// - Valgrind modifies the instruction stream in some very minor ways. For
125// example, on x86 the bts, btc, btr instructions are incorrectly
126// considered to always touch memory (this is a consequence of these
127// instructions being very difficult to simulate).
128//
129// - Valgrind tools layout memory differently to normal programs, so the
130// addresses you get will not be typical. Thus Lackey (and all Valgrind
131// tools) is suitable for getting relative memory traces -- eg. if you
132// want to analyse locality of memory accesses -- but is not good if
133// absolute addresses are important.
134//
135// Despite all these warnings, Dullard's results should be good enough for a
136// wide range of purposes. For example, Cachegrind shares all the above
137// shortcomings and it is still useful.
njn9dd72772006-03-11 06:48:20 +0000138//
njnfd73ebb2005-12-30 22:39:58 +0000139// For further inspiration, you should look at cachegrind/cg_main.c which
njneaf0ca92006-04-09 01:23:29 +0000140// uses the same basic technique for tracing memory accesses, but also groups
141// events together for processing into twos and threes so that fewer C calls
142// are made and things run faster.
sewardj5d1c9012007-02-12 08:42:13 +0000143//
144// Specific Details about --trace-superblocks=yes
145// ----------------------------------------------
146// Valgrind splits code up into single entry, multiple exit blocks
147// known as superblocks. By itself, --trace-superblocks=yes just
148// prints a message as each superblock is run:
149//
150// SB 04013170
151// SB 04013177
152// SB 04013173
153// SB 04013177
154//
155// The hex number is the address of the first instruction in the
156// superblock. You can see the relationship more obviously if you use
157// --trace-superblocks=yes and --trace-mem=yes together. Then a "SB"
158// message at address X is immediately followed by an "instr:" message
159// for that address, as the first instruction in the block is
160// executed, for example:
161//
162// SB 04014073
163// I 04014073,3
164// L 7FEFFF7F8,8
165// I 04014076,4
166// I 0401407A,3
167// I 0401407D,3
168// I 04014080,3
169// I 04014083,6
170
njnfd73ebb2005-12-30 22:39:58 +0000171
njnc7561b92005-06-19 01:24:32 +0000172#include "pub_tool_basics.h"
njn43b9a8a2005-05-10 04:37:01 +0000173#include "pub_tool_tooliface.h"
njnf39e9a32005-06-12 02:43:17 +0000174#include "pub_tool_libcassert.h"
njn36a20fa2005-06-03 03:08:39 +0000175#include "pub_tool_libcprint.h"
sewardj7a26f022005-11-01 17:52:34 +0000176#include "pub_tool_debuginfo.h"
177#include "pub_tool_libcbase.h"
178#include "pub_tool_options.h"
sewardj5fed8c02005-12-23 12:56:11 +0000179#include "pub_tool_machine.h" // VG_(fnptr_to_fnentry)
sewardj7a26f022005-11-01 17:52:34 +0000180
njnd99644d2006-04-07 11:52:55 +0000181/*------------------------------------------------------------*/
182/*--- Command line options ---*/
183/*------------------------------------------------------------*/
sewardj7a26f022005-11-01 17:52:34 +0000184
njnd99644d2006-04-07 11:52:55 +0000185/* Command line options controlling instrumentation kinds, as described at
186 * the top of this file. */
187static Bool clo_basic_counts = True;
188static Bool clo_detailed_counts = False;
189static Bool clo_trace_mem = False;
sewardj5d1c9012007-02-12 08:42:13 +0000190static Bool clo_trace_sbs = False;
sewardj7a26f022005-11-01 17:52:34 +0000191
njnd99644d2006-04-07 11:52:55 +0000192/* The name of the function of which the number of calls (under
193 * --basic-counts=yes) is to be counted, with default. Override with command
194 * line option --fnname. */
195static Char* clo_fnname = "_dl_runtime_resolve";
sewardj7a26f022005-11-01 17:52:34 +0000196
197static Bool lk_process_cmd_line_option(Char* arg)
198{
njnd99644d2006-04-07 11:52:55 +0000199 VG_STR_CLO(arg, "--fnname", clo_fnname)
sewardj5d1c9012007-02-12 08:42:13 +0000200 else VG_BOOL_CLO(arg, "--basic-counts", clo_basic_counts)
201 else VG_BOOL_CLO(arg, "--detailed-counts", clo_detailed_counts)
202 else VG_BOOL_CLO(arg, "--trace-mem", clo_trace_mem)
203 else VG_BOOL_CLO(arg, "--trace-superblocks", clo_trace_sbs)
sewardj7a26f022005-11-01 17:52:34 +0000204 else
205 return False;
206
njnd99644d2006-04-07 11:52:55 +0000207 tl_assert(clo_fnname);
208 tl_assert(clo_fnname[0]);
sewardj7a26f022005-11-01 17:52:34 +0000209 return True;
210}
211
212static void lk_print_usage(void)
213{
214 VG_(printf)(
njnd99644d2006-04-07 11:52:55 +0000215" --basic-counts=no|yes count instructions, jumps, etc. [no]\n"
sewardj7a26f022005-11-01 17:52:34 +0000216" --detailed-counts=no|yes count loads, stores and alu ops [no]\n"
njnd99644d2006-04-07 11:52:55 +0000217" --trace-mem=no|yes trace all loads and stores [no]\n"
sewardj5d1c9012007-02-12 08:42:13 +0000218" --trace-superblocks=no|yes trace all superblock entries [no]\n"
njnd99644d2006-04-07 11:52:55 +0000219" --fnname=<name> count calls to <name> (only used if\n"
220" --basic-count=yes) [_dl_runtime_resolve]\n"
sewardj7a26f022005-11-01 17:52:34 +0000221 );
222}
223
224static void lk_print_debug_usage(void)
225{
njneaf0ca92006-04-09 01:23:29 +0000226 VG_(printf)(
227" (none)\n"
228 );
sewardj7a26f022005-11-01 17:52:34 +0000229}
230
njnd99644d2006-04-07 11:52:55 +0000231/*------------------------------------------------------------*/
njneaf0ca92006-04-09 01:23:29 +0000232/*--- Stuff for --basic-counts ---*/
njnd99644d2006-04-07 11:52:55 +0000233/*------------------------------------------------------------*/
njn25e49d8e72002-09-23 09:36:25 +0000234
njn25e49d8e72002-09-23 09:36:25 +0000235/* Nb: use ULongs because the numbers can get very big */
sewardj7a26f022005-11-01 17:52:34 +0000236static ULong n_func_calls = 0;
sewardj5d1c9012007-02-12 08:42:13 +0000237static ULong n_SBs_entered = 0;
238static ULong n_SBs_completed = 0;
njneaf0ca92006-04-09 01:23:29 +0000239static ULong n_IRStmts = 0;
sewardj7a26f022005-11-01 17:52:34 +0000240static ULong n_guest_instrs = 0;
241static ULong n_Jccs = 0;
242static ULong n_Jccs_untaken = 0;
weidendoba5b3b22007-02-16 11:13:53 +0000243static ULong n_IJccs = 0;
244static ULong n_IJccs_untaken = 0;
njn25e49d8e72002-09-23 09:36:25 +0000245
sewardj7a26f022005-11-01 17:52:34 +0000246static void add_one_func_call(void)
njn25e49d8e72002-09-23 09:36:25 +0000247{
sewardj7a26f022005-11-01 17:52:34 +0000248 n_func_calls++;
njn25e49d8e72002-09-23 09:36:25 +0000249}
250
sewardj5d1c9012007-02-12 08:42:13 +0000251static void add_one_SB_entered(void)
njn25e49d8e72002-09-23 09:36:25 +0000252{
sewardj5d1c9012007-02-12 08:42:13 +0000253 n_SBs_entered++;
sewardj7a26f022005-11-01 17:52:34 +0000254}
255
sewardj5d1c9012007-02-12 08:42:13 +0000256static void add_one_SB_completed(void)
sewardj7a26f022005-11-01 17:52:34 +0000257{
sewardj5d1c9012007-02-12 08:42:13 +0000258 n_SBs_completed++;
njn25e49d8e72002-09-23 09:36:25 +0000259}
260
sewardj7a26f022005-11-01 17:52:34 +0000261static void add_one_IRStmt(void)
njn25e49d8e72002-09-23 09:36:25 +0000262{
sewardj7a26f022005-11-01 17:52:34 +0000263 n_IRStmts++;
njn25e49d8e72002-09-23 09:36:25 +0000264}
265
sewardj9f649aa2004-11-22 20:38:40 +0000266static void add_one_guest_instr(void)
njn25e49d8e72002-09-23 09:36:25 +0000267{
sewardj9f649aa2004-11-22 20:38:40 +0000268 n_guest_instrs++;
njn25e49d8e72002-09-23 09:36:25 +0000269}
270
271static void add_one_Jcc(void)
272{
273 n_Jccs++;
274}
275
276static void add_one_Jcc_untaken(void)
277{
278 n_Jccs_untaken++;
279}
280
weidendoba5b3b22007-02-16 11:13:53 +0000281static void add_one_inverted_Jcc(void)
282{
283 n_IJccs++;
284}
285
286static void add_one_inverted_Jcc_untaken(void)
287{
288 n_IJccs_untaken++;
289}
290
njnd99644d2006-04-07 11:52:55 +0000291/*------------------------------------------------------------*/
njneaf0ca92006-04-09 01:23:29 +0000292/*--- Stuff for --detailed-counts ---*/
njnd99644d2006-04-07 11:52:55 +0000293/*------------------------------------------------------------*/
sewardj7a26f022005-11-01 17:52:34 +0000294
295/* --- Operations --- */
296
297typedef enum { OpLoad=0, OpStore=1, OpAlu=2 } Op;
298
299#define N_OPS 3
300
301
302/* --- Types --- */
303
304#define N_TYPES 9
305
306static Int type2index ( IRType ty )
njn25e49d8e72002-09-23 09:36:25 +0000307{
sewardj7a26f022005-11-01 17:52:34 +0000308 switch (ty) {
309 case Ity_I1: return 0;
310 case Ity_I8: return 1;
311 case Ity_I16: return 2;
312 case Ity_I32: return 3;
313 case Ity_I64: return 4;
314 case Ity_I128: return 5;
315 case Ity_F32: return 6;
316 case Ity_F64: return 7;
317 case Ity_V128: return 8;
318 default: tl_assert(0); break;
319 }
njn25e49d8e72002-09-23 09:36:25 +0000320}
321
njnab9c37e2007-08-27 22:18:58 +0000322static HChar* nameOfTypeIndex ( Int i )
sewardj7a26f022005-11-01 17:52:34 +0000323{
njnab9c37e2007-08-27 22:18:58 +0000324 switch (i) {
sewardj7a26f022005-11-01 17:52:34 +0000325 case 0: return "I1"; break;
326 case 1: return "I8"; break;
327 case 2: return "I16"; break;
328 case 3: return "I32"; break;
329 case 4: return "I64"; break;
330 case 5: return "I128"; break;
331 case 6: return "F32"; break;
332 case 7: return "F64"; break;
333 case 8: return "V128"; break;
334 default: tl_assert(0); break;
335 }
336}
njn25e49d8e72002-09-23 09:36:25 +0000337
njn25e49d8e72002-09-23 09:36:25 +0000338
sewardj7a26f022005-11-01 17:52:34 +0000339/* --- Counts --- */
njn25e49d8e72002-09-23 09:36:25 +0000340
sewardj7a26f022005-11-01 17:52:34 +0000341static ULong detailCounts[N_OPS][N_TYPES];
njn25e49d8e72002-09-23 09:36:25 +0000342
sewardj7a26f022005-11-01 17:52:34 +0000343/* The helper that is called from the instrumented code. */
344static VG_REGPARM(1)
345void increment_detail(ULong* detail)
346{
347 (*detail)++;
348}
njn25e49d8e72002-09-23 09:36:25 +0000349
sewardj7a26f022005-11-01 17:52:34 +0000350/* A helper that adds the instrumentation for a detail. */
sewardj5d1c9012007-02-12 08:42:13 +0000351static void instrument_detail(IRSB* sb, Op op, IRType type)
sewardj7a26f022005-11-01 17:52:34 +0000352{
353 IRDirty* di;
354 IRExpr** argv;
355 const UInt typeIx = type2index(type);
njn25e49d8e72002-09-23 09:36:25 +0000356
sewardj7a26f022005-11-01 17:52:34 +0000357 tl_assert(op < N_OPS);
358 tl_assert(typeIx < N_TYPES);
njn25e49d8e72002-09-23 09:36:25 +0000359
sewardj7a26f022005-11-01 17:52:34 +0000360 argv = mkIRExprVec_1( mkIRExpr_HWord( (HWord)&detailCounts[op][typeIx] ) );
sewardj5fed8c02005-12-23 12:56:11 +0000361 di = unsafeIRDirty_0_N( 1, "increment_detail",
362 VG_(fnptr_to_fnentry)( &increment_detail ),
363 argv);
sewardj5d1c9012007-02-12 08:42:13 +0000364 addStmtToIRSB( sb, IRStmt_Dirty(di) );
sewardj7a26f022005-11-01 17:52:34 +0000365}
njn25e49d8e72002-09-23 09:36:25 +0000366
sewardj7a26f022005-11-01 17:52:34 +0000367/* Summarize and print the details. */
sewardj7a26f022005-11-01 17:52:34 +0000368static void print_details ( void )
369{
370 Int typeIx;
371 VG_(message)(Vg_UserMsg,
372 " Type Loads Stores AluOps");
373 VG_(message)(Vg_UserMsg,
374 " -------------------------------------------");
375 for (typeIx = 0; typeIx < N_TYPES; typeIx++) {
376 VG_(message)(Vg_UserMsg,
377 " %4s %,12llu %,12llu %,12llu",
378 nameOfTypeIndex( typeIx ),
379 detailCounts[OpLoad ][typeIx],
380 detailCounts[OpStore][typeIx],
381 detailCounts[OpAlu ][typeIx]
382 );
383 }
384}
njn25e49d8e72002-09-23 09:36:25 +0000385
sewardj7a26f022005-11-01 17:52:34 +0000386
njnd99644d2006-04-07 11:52:55 +0000387/*------------------------------------------------------------*/
njneaf0ca92006-04-09 01:23:29 +0000388/*--- Stuff for --trace-mem ---*/
njnd99644d2006-04-07 11:52:55 +0000389/*------------------------------------------------------------*/
njnfd73ebb2005-12-30 22:39:58 +0000390
njneaf0ca92006-04-09 01:23:29 +0000391#define MAX_DSIZE 512
392
393typedef
394 IRExpr
395 IRAtom;
396
397typedef
398 enum { Event_Ir, Event_Dr, Event_Dw, Event_Dm }
399 EventKind;
400
401typedef
402 struct {
403 EventKind ekind;
404 IRAtom* addr;
405 Int size;
406 }
407 Event;
408
409/* Up to this many unnotified events are allowed. Must be at least two,
410 so that reads and writes to the same address can be merged into a modify.
411 Beyond that, larger numbers just potentially induce more spilling due to
412 extending live ranges of address temporaries. */
413#define N_EVENTS 4
414
415/* Maintain an ordered list of memory events which are outstanding, in
416 the sense that no IR has yet been generated to do the relevant
sewardj5d1c9012007-02-12 08:42:13 +0000417 helper calls. The SB is scanned top to bottom and memory events
njneaf0ca92006-04-09 01:23:29 +0000418 are added to the end of the list, merging with the most recent
419 notified event where possible (Dw immediately following Dr and
420 having the same size and EA can be merged).
421
422 This merging is done so that for architectures which have
423 load-op-store instructions (x86, amd64), the instr is treated as if
424 it makes just one memory reference (a modify), rather than two (a
425 read followed by a write at the same address).
426
427 At various points the list will need to be flushed, that is, IR
428 generated from it. That must happen before any possible exit from
429 the block (the end, or an IRStmt_Exit). Flushing also takes place
430 when there is no space to add a new event.
431
432 If we require the simulation statistics to be up to date with
433 respect to possible memory exceptions, then the list would have to
434 be flushed before each memory reference. That's a pain so we don't
435 bother.
436
437 Flushing the list consists of walking it start to end and emitting
438 instrumentation IR for each event, in the order in which they
439 appear. */
440
441static Event events[N_EVENTS];
442static Int events_used = 0;
443
444
445static VG_REGPARM(2) void trace_instr(Addr addr, SizeT size)
446{
njn8a7b41b2007-09-23 00:51:24 +0000447 VG_(printf)("I %08lx,%lu\n", addr, size);
njneaf0ca92006-04-09 01:23:29 +0000448}
449
njnfd73ebb2005-12-30 22:39:58 +0000450static VG_REGPARM(2) void trace_load(Addr addr, SizeT size)
451{
njn8a7b41b2007-09-23 00:51:24 +0000452 VG_(printf)(" L %08lx,%lu\n", addr, size);
njnfd73ebb2005-12-30 22:39:58 +0000453}
454
455static VG_REGPARM(2) void trace_store(Addr addr, SizeT size)
456{
njn8a7b41b2007-09-23 00:51:24 +0000457 VG_(printf)(" S %08lx,%lu\n", addr, size);
njneaf0ca92006-04-09 01:23:29 +0000458}
459
460static VG_REGPARM(2) void trace_modify(Addr addr, SizeT size)
461{
njn8a7b41b2007-09-23 00:51:24 +0000462 VG_(printf)(" M %08lx,%lu\n", addr, size);
njneaf0ca92006-04-09 01:23:29 +0000463}
464
465
sewardj5d1c9012007-02-12 08:42:13 +0000466static void flushEvents(IRSB* sb)
njneaf0ca92006-04-09 01:23:29 +0000467{
468 Int i;
469 Char* helperName;
470 void* helperAddr;
471 IRExpr** argv;
472 IRDirty* di;
473 Event* ev;
474
475 for (i = 0; i < events_used; i++) {
476
477 ev = &events[i];
478
479 // Decide on helper fn to call and args to pass it.
480 switch (ev->ekind) {
481 case Event_Ir: helperName = "trace_instr";
482 helperAddr = trace_instr; break;
483
484 case Event_Dr: helperName = "trace_load";
485 helperAddr = trace_load; break;
486
487 case Event_Dw: helperName = "trace_store";
488 helperAddr = trace_store; break;
489
490 case Event_Dm: helperName = "trace_modify";
491 helperAddr = trace_modify; break;
492 default:
493 tl_assert(0);
494 }
495
496 // Add the helper.
497 argv = mkIRExprVec_2( ev->addr, mkIRExpr_HWord( ev->size ) );
498 di = unsafeIRDirty_0_N( /*regparms*/2,
499 helperName, VG_(fnptr_to_fnentry)( helperAddr ),
500 argv );
sewardj5d1c9012007-02-12 08:42:13 +0000501 addStmtToIRSB( sb, IRStmt_Dirty(di) );
njneaf0ca92006-04-09 01:23:29 +0000502 }
503
504 events_used = 0;
505}
506
507// WARNING: If you aren't interested in instruction reads, you can omit the
508// code that adds calls to trace_instr() in flushEvents(). However, you
509// must still call this function, addEvent_Ir() -- it is necessary to add
510// the Ir events to the events list so that merging of paired load/store
511// events into modify events works correctly.
sewardj5d1c9012007-02-12 08:42:13 +0000512static void addEvent_Ir ( IRSB* sb, IRAtom* iaddr, UInt isize )
njneaf0ca92006-04-09 01:23:29 +0000513{
514 Event* evt;
njndbb9c8e2007-02-12 11:28:38 +0000515 tl_assert(clo_trace_mem);
njneaf0ca92006-04-09 01:23:29 +0000516 tl_assert( (VG_MIN_INSTR_SZB <= isize && isize <= VG_MAX_INSTR_SZB)
517 || VG_CLREQ_SZB == isize );
518 if (events_used == N_EVENTS)
sewardj5d1c9012007-02-12 08:42:13 +0000519 flushEvents(sb);
njneaf0ca92006-04-09 01:23:29 +0000520 tl_assert(events_used >= 0 && events_used < N_EVENTS);
521 evt = &events[events_used];
522 evt->ekind = Event_Ir;
523 evt->addr = iaddr;
524 evt->size = isize;
525 events_used++;
526}
527
528static
sewardj5d1c9012007-02-12 08:42:13 +0000529void addEvent_Dr ( IRSB* sb, IRAtom* daddr, Int dsize )
njneaf0ca92006-04-09 01:23:29 +0000530{
531 Event* evt;
njndbb9c8e2007-02-12 11:28:38 +0000532 tl_assert(clo_trace_mem);
njneaf0ca92006-04-09 01:23:29 +0000533 tl_assert(isIRAtom(daddr));
534 tl_assert(dsize >= 1 && dsize <= MAX_DSIZE);
535 if (events_used == N_EVENTS)
sewardj5d1c9012007-02-12 08:42:13 +0000536 flushEvents(sb);
njneaf0ca92006-04-09 01:23:29 +0000537 tl_assert(events_used >= 0 && events_used < N_EVENTS);
538 evt = &events[events_used];
539 evt->ekind = Event_Dr;
540 evt->addr = daddr;
541 evt->size = dsize;
542 events_used++;
543}
544
545static
sewardj5d1c9012007-02-12 08:42:13 +0000546void addEvent_Dw ( IRSB* sb, IRAtom* daddr, Int dsize )
njneaf0ca92006-04-09 01:23:29 +0000547{
548 Event* lastEvt;
549 Event* evt;
njndbb9c8e2007-02-12 11:28:38 +0000550 tl_assert(clo_trace_mem);
njneaf0ca92006-04-09 01:23:29 +0000551 tl_assert(isIRAtom(daddr));
552 tl_assert(dsize >= 1 && dsize <= MAX_DSIZE);
553
554 // Is it possible to merge this write with the preceding read?
555 lastEvt = &events[events_used-1];
556 if (events_used > 0
557 && lastEvt->ekind == Event_Dr
558 && lastEvt->size == dsize
559 && eqIRAtom(lastEvt->addr, daddr))
560 {
561 lastEvt->ekind = Event_Dm;
562 return;
563 }
564
565 // No. Add as normal.
566 if (events_used == N_EVENTS)
sewardj5d1c9012007-02-12 08:42:13 +0000567 flushEvents(sb);
njneaf0ca92006-04-09 01:23:29 +0000568 tl_assert(events_used >= 0 && events_used < N_EVENTS);
569 evt = &events[events_used];
570 evt->ekind = Event_Dw;
571 evt->size = dsize;
572 evt->addr = daddr;
573 events_used++;
njnfd73ebb2005-12-30 22:39:58 +0000574}
575
njnd99644d2006-04-07 11:52:55 +0000576
577/*------------------------------------------------------------*/
sewardj5d1c9012007-02-12 08:42:13 +0000578/*--- Stuff for --trace-superblocks ---*/
579/*------------------------------------------------------------*/
580
581static void trace_superblock(Addr addr)
582{
583 VG_(printf)("SB %08lx\n", addr);
584}
585
586
587/*------------------------------------------------------------*/
njnd99644d2006-04-07 11:52:55 +0000588/*--- Basic tool functions ---*/
589/*------------------------------------------------------------*/
sewardj7a26f022005-11-01 17:52:34 +0000590
591static void lk_post_clo_init(void)
592{
593 Int op, tyIx;
594
njnd99644d2006-04-07 11:52:55 +0000595 if (clo_detailed_counts) {
596 for (op = 0; op < N_OPS; op++)
597 for (tyIx = 0; tyIx < N_TYPES; tyIx++)
598 detailCounts[op][tyIx] = 0;
599 }
sewardj7a26f022005-11-01 17:52:34 +0000600}
601
sewardj4ba057c2005-10-18 12:04:18 +0000602static
sewardj0b9d74a2006-12-24 02:24:11 +0000603IRSB* lk_instrument ( VgCallbackClosure* closure,
sewardj5d1c9012007-02-12 08:42:13 +0000604 IRSB* sbIn,
sewardj461df9c2006-01-17 02:06:39 +0000605 VexGuestLayout* layout,
606 VexGuestExtents* vge,
607 IRType gWordTy, IRType hWordTy )
njn25e49d8e72002-09-23 09:36:25 +0000608{
njneaf0ca92006-04-09 01:23:29 +0000609 IRDirty* di;
610 Int i;
sewardj5d1c9012007-02-12 08:42:13 +0000611 IRSB* sbOut;
njneaf0ca92006-04-09 01:23:29 +0000612 Char fnname[100];
613 IRType type;
sewardj5d1c9012007-02-12 08:42:13 +0000614 IRTypeEnv* tyenv = sbIn->tyenv;
weidendoba5b3b22007-02-16 11:13:53 +0000615 Addr iaddr = 0, dst;
616 UInt ilen = 0;
617 Bool condition_inverted = False;
sewardjd54babf2005-03-21 00:55:49 +0000618
619 if (gWordTy != hWordTy) {
620 /* We don't currently support this case. */
621 VG_(tool_panic)("host/guest word size mismatch");
622 }
sewardj9f649aa2004-11-22 20:38:40 +0000623
sewardj5d1c9012007-02-12 08:42:13 +0000624 /* Set up SB */
625 sbOut = deepCopyIRSBExceptStmts(sbIn);
sewardj9f649aa2004-11-22 20:38:40 +0000626
sewardj7a26f022005-11-01 17:52:34 +0000627 // Copy verbatim any IR preamble preceding the first IMark
628 i = 0;
sewardj5d1c9012007-02-12 08:42:13 +0000629 while (i < sbIn->stmts_used && sbIn->stmts[i]->tag != Ist_IMark) {
630 addStmtToIRSB( sbOut, sbIn->stmts[i] );
sewardj7a26f022005-11-01 17:52:34 +0000631 i++;
sewardj9f649aa2004-11-22 20:38:40 +0000632 }
sewardj9f649aa2004-11-22 20:38:40 +0000633
njnd99644d2006-04-07 11:52:55 +0000634 if (clo_basic_counts) {
sewardj5d1c9012007-02-12 08:42:13 +0000635 /* Count this superblock. */
636 di = unsafeIRDirty_0_N( 0, "add_one_SB_entered",
637 VG_(fnptr_to_fnentry)( &add_one_SB_entered ),
njnd99644d2006-04-07 11:52:55 +0000638 mkIRExprVec_0() );
sewardj5d1c9012007-02-12 08:42:13 +0000639 addStmtToIRSB( sbOut, IRStmt_Dirty(di) );
640 }
641
642 if (clo_trace_sbs) {
643 /* Print this superblock's address. */
644 di = unsafeIRDirty_0_N(
645 0, "trace_superblock",
646 VG_(fnptr_to_fnentry)( &trace_superblock ),
647 mkIRExprVec_1( mkIRExpr_HWord( vge->base[0] ) )
648 );
649 addStmtToIRSB( sbOut, IRStmt_Dirty(di) );
njnd99644d2006-04-07 11:52:55 +0000650 }
sewardj9f649aa2004-11-22 20:38:40 +0000651
njneaf0ca92006-04-09 01:23:29 +0000652 if (clo_trace_mem) {
653 events_used = 0;
654 }
655
sewardj5d1c9012007-02-12 08:42:13 +0000656 for (/*use current i*/; i < sbIn->stmts_used; i++) {
657 IRStmt* st = sbIn->stmts[i];
sewardj7a26f022005-11-01 17:52:34 +0000658 if (!st || st->tag == Ist_NoOp) continue;
sewardj9f649aa2004-11-22 20:38:40 +0000659
njnd99644d2006-04-07 11:52:55 +0000660 if (clo_basic_counts) {
661 /* Count one VEX statement. */
662 di = unsafeIRDirty_0_N( 0, "add_one_IRStmt",
663 VG_(fnptr_to_fnentry)( &add_one_IRStmt ),
664 mkIRExprVec_0() );
sewardj5d1c9012007-02-12 08:42:13 +0000665 addStmtToIRSB( sbOut, IRStmt_Dirty(di) );
njnd99644d2006-04-07 11:52:55 +0000666 }
sewardj7a26f022005-11-01 17:52:34 +0000667
sewardj9f649aa2004-11-22 20:38:40 +0000668 switch (st->tag) {
njneaf0ca92006-04-09 01:23:29 +0000669 case Ist_NoOp:
670 case Ist_AbiHint:
671 case Ist_Put:
672 case Ist_PutI:
sewardj72d75132007-11-09 23:06:35 +0000673 case Ist_MBE:
sewardj5d1c9012007-02-12 08:42:13 +0000674 addStmtToIRSB( sbOut, st );
njneaf0ca92006-04-09 01:23:29 +0000675 break;
676
sewardj7a26f022005-11-01 17:52:34 +0000677 case Ist_IMark:
njnd99644d2006-04-07 11:52:55 +0000678 if (clo_basic_counts) {
weidendoba5b3b22007-02-16 11:13:53 +0000679 /* Needed to be able to check for inverted condition in Ist_Exit */
680 iaddr = st->Ist.IMark.addr;
681 ilen = st->Ist.IMark.len;
682
njnd99644d2006-04-07 11:52:55 +0000683 /* Count guest instruction. */
684 di = unsafeIRDirty_0_N( 0, "add_one_guest_instr",
685 VG_(fnptr_to_fnentry)( &add_one_guest_instr ),
686 mkIRExprVec_0() );
sewardj5d1c9012007-02-12 08:42:13 +0000687 addStmtToIRSB( sbOut, IRStmt_Dirty(di) );
njnd99644d2006-04-07 11:52:55 +0000688
689 /* An unconditional branch to a known destination in the
sewardj0b9d74a2006-12-24 02:24:11 +0000690 * guest's instructions can be represented, in the IRSB to
njnd99644d2006-04-07 11:52:55 +0000691 * instrument, by the VEX statements that are the
692 * translation of that known destination. This feature is
sewardj5d1c9012007-02-12 08:42:13 +0000693 * called 'SB chasing' and can be influenced by command
njnd99644d2006-04-07 11:52:55 +0000694 * line option --vex-guest-chase-thresh.
695 *
696 * To get an accurate count of the calls to a specific
sewardj5d1c9012007-02-12 08:42:13 +0000697 * function, taking SB chasing into account, we need to
njnd99644d2006-04-07 11:52:55 +0000698 * check for each guest instruction (Ist_IMark) if it is
699 * the entry point of a function.
700 */
701 tl_assert(clo_fnname);
702 tl_assert(clo_fnname[0]);
703 if (VG_(get_fnname_if_entry)(st->Ist.IMark.addr,
704 fnname, sizeof(fnname))
705 && 0 == VG_(strcmp)(fnname, clo_fnname)) {
706 di = unsafeIRDirty_0_N(
707 0, "add_one_func_call",
708 VG_(fnptr_to_fnentry)( &add_one_func_call ),
709 mkIRExprVec_0() );
sewardj5d1c9012007-02-12 08:42:13 +0000710 addStmtToIRSB( sbOut, IRStmt_Dirty(di) );
njnd99644d2006-04-07 11:52:55 +0000711 }
sewardj7a26f022005-11-01 17:52:34 +0000712 }
njnd99644d2006-04-07 11:52:55 +0000713 if (clo_trace_mem) {
njneaf0ca92006-04-09 01:23:29 +0000714 // WARNING: do not remove this function call, even if you
715 // aren't interested in instruction reads. See the comment
716 // above the function itself for more detail.
sewardj5d1c9012007-02-12 08:42:13 +0000717 addEvent_Ir( sbOut, mkIRExpr_HWord( (HWord)st->Ist.IMark.addr ),
njneaf0ca92006-04-09 01:23:29 +0000718 st->Ist.IMark.len );
njnfd73ebb2005-12-30 22:39:58 +0000719 }
sewardj5d1c9012007-02-12 08:42:13 +0000720 addStmtToIRSB( sbOut, st );
sewardj7a26f022005-11-01 17:52:34 +0000721 break;
722
sewardj0b9d74a2006-12-24 02:24:11 +0000723 case Ist_WrTmp:
njnfd73ebb2005-12-30 22:39:58 +0000724 // Add a call to trace_load() if --trace-mem=yes.
njnd99644d2006-04-07 11:52:55 +0000725 if (clo_trace_mem) {
sewardj0b9d74a2006-12-24 02:24:11 +0000726 IRExpr* data = st->Ist.WrTmp.data;
njnfd73ebb2005-12-30 22:39:58 +0000727 if (data->tag == Iex_Load) {
sewardj5d1c9012007-02-12 08:42:13 +0000728 addEvent_Dr( sbOut, data->Iex.Load.addr,
njneaf0ca92006-04-09 01:23:29 +0000729 sizeofIRType(data->Iex.Load.ty) );
njnfd73ebb2005-12-30 22:39:58 +0000730 }
731 }
njnd99644d2006-04-07 11:52:55 +0000732 if (clo_detailed_counts) {
sewardj0b9d74a2006-12-24 02:24:11 +0000733 IRExpr* expr = st->Ist.WrTmp.data;
sewardj5d1c9012007-02-12 08:42:13 +0000734 type = typeOfIRExpr(sbOut->tyenv, expr);
sewardj7a26f022005-11-01 17:52:34 +0000735 tl_assert(type != Ity_INVALID);
736 switch (expr->tag) {
737 case Iex_Load:
sewardj5d1c9012007-02-12 08:42:13 +0000738 instrument_detail( sbOut, OpLoad, type );
sewardj7a26f022005-11-01 17:52:34 +0000739 break;
740 case Iex_Unop:
741 case Iex_Binop:
sewardje91cea72006-02-08 19:32:02 +0000742 case Iex_Triop:
743 case Iex_Qop:
sewardj7a26f022005-11-01 17:52:34 +0000744 case Iex_Mux0X:
sewardj5d1c9012007-02-12 08:42:13 +0000745 instrument_detail( sbOut, OpAlu, type );
sewardj7a26f022005-11-01 17:52:34 +0000746 break;
747 default:
748 break;
749 }
750 }
sewardj5d1c9012007-02-12 08:42:13 +0000751 addStmtToIRSB( sbOut, st );
njneaf0ca92006-04-09 01:23:29 +0000752 break;
753
754 case Ist_Store:
755 if (clo_trace_mem) {
756 IRExpr* data = st->Ist.Store.data;
sewardj5d1c9012007-02-12 08:42:13 +0000757 addEvent_Dw( sbOut, st->Ist.Store.addr,
njneaf0ca92006-04-09 01:23:29 +0000758 sizeofIRType(typeOfIRExpr(tyenv, data)) );
759 }
760 if (clo_detailed_counts) {
sewardj5d1c9012007-02-12 08:42:13 +0000761 type = typeOfIRExpr(sbOut->tyenv, st->Ist.Store.data);
njneaf0ca92006-04-09 01:23:29 +0000762 tl_assert(type != Ity_INVALID);
sewardj5d1c9012007-02-12 08:42:13 +0000763 instrument_detail( sbOut, OpStore, type );
njneaf0ca92006-04-09 01:23:29 +0000764 }
sewardj5d1c9012007-02-12 08:42:13 +0000765 addStmtToIRSB( sbOut, st );
njneaf0ca92006-04-09 01:23:29 +0000766 break;
767
768 case Ist_Dirty: {
njndbb9c8e2007-02-12 11:28:38 +0000769 if (clo_trace_mem) {
770 Int dsize;
771 IRDirty* d = st->Ist.Dirty.details;
772 if (d->mFx != Ifx_None) {
773 // This dirty helper accesses memory. Collect the details.
774 tl_assert(d->mAddr != NULL);
775 tl_assert(d->mSize != 0);
776 dsize = d->mSize;
777 if (d->mFx == Ifx_Read || d->mFx == Ifx_Modify)
778 addEvent_Dr( sbOut, d->mAddr, dsize );
779 if (d->mFx == Ifx_Write || d->mFx == Ifx_Modify)
780 addEvent_Dw( sbOut, d->mAddr, dsize );
781 } else {
782 tl_assert(d->mAddr == NULL);
783 tl_assert(d->mSize == 0);
784 }
njneaf0ca92006-04-09 01:23:29 +0000785 }
sewardj5d1c9012007-02-12 08:42:13 +0000786 addStmtToIRSB( sbOut, st );
njneaf0ca92006-04-09 01:23:29 +0000787 break;
788 }
789
790 case Ist_Exit:
791 if (clo_basic_counts) {
weidendoba5b3b22007-02-16 11:13:53 +0000792 // The condition of a branch was inverted by VEX if a taken
793 // branch is in fact a fall trough according to client address
794 tl_assert(iaddr != 0);
795 dst = (sizeof(Addr) == 4) ? st->Ist.Exit.dst->Ico.U32 :
796 st->Ist.Exit.dst->Ico.U64;
797 condition_inverted = (dst == iaddr + ilen);
798
njneaf0ca92006-04-09 01:23:29 +0000799 /* Count Jcc */
weidendoba5b3b22007-02-16 11:13:53 +0000800 if (!condition_inverted)
801 di = unsafeIRDirty_0_N( 0, "add_one_Jcc",
njneaf0ca92006-04-09 01:23:29 +0000802 VG_(fnptr_to_fnentry)( &add_one_Jcc ),
803 mkIRExprVec_0() );
weidendoba5b3b22007-02-16 11:13:53 +0000804 else
805 di = unsafeIRDirty_0_N( 0, "add_one_inverted_Jcc",
806 VG_(fnptr_to_fnentry)( &add_one_inverted_Jcc ),
807 mkIRExprVec_0() );
808
sewardj5d1c9012007-02-12 08:42:13 +0000809 addStmtToIRSB( sbOut, IRStmt_Dirty(di) );
njneaf0ca92006-04-09 01:23:29 +0000810 }
811 if (clo_trace_mem) {
sewardj5d1c9012007-02-12 08:42:13 +0000812 flushEvents(sbOut);
njneaf0ca92006-04-09 01:23:29 +0000813 }
814
sewardj5d1c9012007-02-12 08:42:13 +0000815 addStmtToIRSB( sbOut, st ); // Original statement
njneaf0ca92006-04-09 01:23:29 +0000816
817 if (clo_basic_counts) {
818 /* Count non-taken Jcc */
weidendoba5b3b22007-02-16 11:13:53 +0000819 if (!condition_inverted)
820 di = unsafeIRDirty_0_N( 0, "add_one_Jcc_untaken",
njneaf0ca92006-04-09 01:23:29 +0000821 VG_(fnptr_to_fnentry)(
822 &add_one_Jcc_untaken ),
823 mkIRExprVec_0() );
weidendoba5b3b22007-02-16 11:13:53 +0000824 else
825 di = unsafeIRDirty_0_N( 0, "add_one_inverted_Jcc_untaken",
826 VG_(fnptr_to_fnentry)(
827 &add_one_inverted_Jcc_untaken ),
828 mkIRExprVec_0() );
829
sewardj5d1c9012007-02-12 08:42:13 +0000830 addStmtToIRSB( sbOut, IRStmt_Dirty(di) );
njneaf0ca92006-04-09 01:23:29 +0000831 }
sewardj9f649aa2004-11-22 20:38:40 +0000832 break;
833
834 default:
njneaf0ca92006-04-09 01:23:29 +0000835 tl_assert(0);
sewardj9f649aa2004-11-22 20:38:40 +0000836 }
837 }
838
njnd99644d2006-04-07 11:52:55 +0000839 if (clo_basic_counts) {
840 /* Count this basic block. */
sewardj5d1c9012007-02-12 08:42:13 +0000841 di = unsafeIRDirty_0_N( 0, "add_one_SB_completed",
842 VG_(fnptr_to_fnentry)( &add_one_SB_completed ),
njnd99644d2006-04-07 11:52:55 +0000843 mkIRExprVec_0() );
sewardj5d1c9012007-02-12 08:42:13 +0000844 addStmtToIRSB( sbOut, IRStmt_Dirty(di) );
njnd99644d2006-04-07 11:52:55 +0000845 }
sewardj7a26f022005-11-01 17:52:34 +0000846
njneaf0ca92006-04-09 01:23:29 +0000847 if (clo_trace_mem) {
sewardj5d1c9012007-02-12 08:42:13 +0000848 /* At the end of the sbIn. Flush outstandings. */
849 flushEvents(sbOut);
njneaf0ca92006-04-09 01:23:29 +0000850 }
851
sewardj5d1c9012007-02-12 08:42:13 +0000852 return sbOut;
njn25e49d8e72002-09-23 09:36:25 +0000853}
854
njn51d827b2005-05-09 01:02:08 +0000855static void lk_fini(Int exitcode)
njn25e49d8e72002-09-23 09:36:25 +0000856{
sewardj7a26f022005-11-01 17:52:34 +0000857 char percentify_buf[4]; /* Two digits, '%' and 0. */
858 const int percentify_size = sizeof(percentify_buf);
859 const int percentify_decs = 0;
860
njnd99644d2006-04-07 11:52:55 +0000861 tl_assert(clo_fnname);
862 tl_assert(clo_fnname[0]);
njn25e49d8e72002-09-23 09:36:25 +0000863
njnd99644d2006-04-07 11:52:55 +0000864 if (clo_basic_counts) {
weidendoba5b3b22007-02-16 11:13:53 +0000865 ULong total_Jccs = n_Jccs + n_IJccs;
866 ULong taken_Jccs = (n_Jccs - n_Jccs_untaken) + n_IJccs_untaken;
867
njnd99644d2006-04-07 11:52:55 +0000868 VG_(message)(Vg_UserMsg,
869 "Counted %,llu calls to %s()", n_func_calls, clo_fnname);
njn25e49d8e72002-09-23 09:36:25 +0000870
njnd99644d2006-04-07 11:52:55 +0000871 VG_(message)(Vg_UserMsg, "");
872 VG_(message)(Vg_UserMsg, "Jccs:");
weidendoba5b3b22007-02-16 11:13:53 +0000873 VG_(message)(Vg_UserMsg, " total: %,llu", total_Jccs);
874 VG_(percentify)(taken_Jccs, (total_Jccs ? total_Jccs : 1),
njnd99644d2006-04-07 11:52:55 +0000875 percentify_decs, percentify_size, percentify_buf);
876 VG_(message)(Vg_UserMsg, " taken: %,llu (%s)",
weidendoba5b3b22007-02-16 11:13:53 +0000877 taken_Jccs, percentify_buf);
njnd99644d2006-04-07 11:52:55 +0000878
879 VG_(message)(Vg_UserMsg, "");
880 VG_(message)(Vg_UserMsg, "Executed:");
sewardj5d1c9012007-02-12 08:42:13 +0000881 VG_(message)(Vg_UserMsg, " SBs entered: %,llu", n_SBs_entered);
882 VG_(message)(Vg_UserMsg, " SBs completed: %,llu", n_SBs_completed);
njnd99644d2006-04-07 11:52:55 +0000883 VG_(message)(Vg_UserMsg, " guest instrs: %,llu", n_guest_instrs);
884 VG_(message)(Vg_UserMsg, " IRStmts: %,llu", n_IRStmts);
885
886 VG_(message)(Vg_UserMsg, "");
887 VG_(message)(Vg_UserMsg, "Ratios:");
sewardj5d1c9012007-02-12 08:42:13 +0000888 tl_assert(n_SBs_entered); // Paranoia time.
889 VG_(message)(Vg_UserMsg, " guest instrs : SB entered = %3u : 10",
890 10 * n_guest_instrs / n_SBs_entered);
891 VG_(message)(Vg_UserMsg, " IRStmts : SB entered = %3u : 10",
892 10 * n_IRStmts / n_SBs_entered);
njnd99644d2006-04-07 11:52:55 +0000893 tl_assert(n_guest_instrs); // Paranoia time.
894 VG_(message)(Vg_UserMsg, " IRStmts : guest instr = %3u : 10",
895 10 * n_IRStmts / n_guest_instrs);
896 }
897
898 if (clo_detailed_counts) {
sewardj7a26f022005-11-01 17:52:34 +0000899 VG_(message)(Vg_UserMsg, "");
900 VG_(message)(Vg_UserMsg, "IR-level counts by type:");
901 print_details();
902 }
njn25e49d8e72002-09-23 09:36:25 +0000903
njnd99644d2006-04-07 11:52:55 +0000904 if (clo_basic_counts) {
905 VG_(message)(Vg_UserMsg, "");
906 VG_(message)(Vg_UserMsg, "Exit code: %d", exitcode);
907 }
njn25e49d8e72002-09-23 09:36:25 +0000908}
909
njn51d827b2005-05-09 01:02:08 +0000910static void lk_pre_clo_init(void)
911{
912 VG_(details_name) ("Lackey");
913 VG_(details_version) (NULL);
914 VG_(details_description) ("an example Valgrind tool");
915 VG_(details_copyright_author)(
sewardj9ebd6e02007-01-08 06:01:59 +0000916 "Copyright (C) 2002-2007, and GNU GPL'd, by Nicholas Nethercote.");
njn51d827b2005-05-09 01:02:08 +0000917 VG_(details_bug_reports_to) (VG_BUGS_TO);
sewardj40823562006-10-17 02:21:17 +0000918 VG_(details_avg_translation_sizeB) ( 200 );
njn51d827b2005-05-09 01:02:08 +0000919
920 VG_(basic_tool_funcs) (lk_post_clo_init,
921 lk_instrument,
922 lk_fini);
sewardj7a26f022005-11-01 17:52:34 +0000923 VG_(needs_command_line_options)(lk_process_cmd_line_option,
924 lk_print_usage,
925 lk_print_debug_usage);
njn51d827b2005-05-09 01:02:08 +0000926}
927
sewardj45f4e7c2005-09-27 19:20:21 +0000928VG_DETERMINE_INTERFACE_VERSION(lk_pre_clo_init)
fitzhardinge98abfc72003-12-16 02:05:15 +0000929
njn25e49d8e72002-09-23 09:36:25 +0000930/*--------------------------------------------------------------------*/
njn25cac76cb2002-09-23 11:21:57 +0000931/*--- end lk_main.c ---*/
njn25e49d8e72002-09-23 09:36:25 +0000932/*--------------------------------------------------------------------*/