2 /* This demonstrates a stack overrun bug that exp-ptrcheck found while
3 running Valgrind itself (self hosting). As at 12 Sept 08 this bug
4 is still in Valgrind. */
11 typedef unsigned long long int ULong;
12 typedef unsigned int UInt;
13 typedef signed int Int;
16 /* ---------------------------------------------------------------------
18 ------------------------------------------------------------------ */
20 /* This part excerpted from coregrind/m_libcbase.c */
22 // Percentify n/m with d decimal places. Includes the '%' symbol at the end.
23 // Right justifies in 'buf'.
24 void VG_percentify(ULong n, ULong m, UInt d, Int n_buf, char buf[])
31 // Have to generate the format string in order to be flexible about
32 // the width of the field.
33 sprintf(fmt, "%%-%ds", n_buf);
34 // fmt is now "%<n_buf>s" where <d> is 1,2,3...
35 sprintf(buf, fmt, "--%");
42 sprintf(buf, "%lld%%", p1);
47 case 1: ex = 10; break;
48 case 2: ex = 100; break;
49 case 3: ex = 1000; break;
51 /* was: VG_(tool_panic)("Currently can only handle 3 decimal places"); */
53 p2 = ((100*n*ex) / m) % ex;
54 // Have to generate the format string in order to be flexible about
55 // the width of the post-decimal-point part.
56 sprintf(fmt, "%%lld.%%0%dlld%%%%", d);
57 // fmt is now "%lld.%0<d>lld%%" where <d> is 1,2,3...
58 sprintf(buf, fmt, p1, p2);
63 if (space < 0) space = 0; /* Allow for v. small field_width */
66 /* Right justify in field */
67 for ( ; i >= 0; i--) buf[i + space] = buf[i];
68 for (i = 0; i < space; i++) buf[i] = ' ';
72 /*------------------------------------------------------------*/
74 /*------------------------------------------------------------*/
76 /* This part excerpted from coregrind/m_translate.c */
78 static UInt n_SP_updates_fast = 0;
79 static UInt n_SP_updates_generic_known = 0;
80 static UInt n_SP_updates_generic_unknown = 0;
82 void VG_print_translation_stats ( void )
85 UInt n_SP_updates = n_SP_updates_fast + n_SP_updates_generic_known
86 + n_SP_updates_generic_unknown;
87 VG_percentify(n_SP_updates_fast, n_SP_updates, 1, 6, buf);
89 "translate: fast SP updates identified: %'u (%s)\n",
90 n_SP_updates_fast, buf );
92 VG_percentify(n_SP_updates_generic_known, n_SP_updates, 1, 6, buf);
94 "translate: generic_known SP updates identified: %'u (%s)\n",
95 n_SP_updates_generic_known, buf );
97 VG_percentify(n_SP_updates_generic_unknown, n_SP_updates, 1, 6, buf);
99 "translate: generic_unknown SP updates identified: %'u (%s)\n",
100 n_SP_updates_generic_unknown, buf );
107 VG_print_translation_stats();