145 Commits

Author SHA1 Message Date
Nicholas Nethercote
ce82c07580 Cleaned up reading of debug info a bit.
Renamed:
  VG_(read_procselfmaps_contents)() --> VG_(read_procselfmaps)()
  VG_(read_procselfmaps)()          --> VG_(parse_procselfmaps)()
  VG_(read_symbols)()               --> VG_(read_all_symbols)()
  VG_(read_symtab_callback)()       --> VG_(read_seg_symbols)()

Removed the Bool 'read_from_file' arg from (what is now)
VG_(parse_procselfmaps)().  If /proc/self/maps needs to be read beforehand, the
code calls (what is now) VG_(read_procselfmaps)() before.  Still using the
static buffer which is not nice but good enough.

More importantly, I split up VG_(new_exe_segment)() into
VG_(new_exeseg_startup)() and VG_(new_exeseg_mmap)().  This is because at
startup, we were stupidly calling VG_(read_symbols)() for every exe seg, which
parses /proc/self/maps completely in order to load the debug info/symbols for
the exe seg (and any others we haven't already got the symbols for).  Despite
the fact that the startup code reads /proc/self/maps to know which segments are
there at startup.  In other words, we were reading /proc/self/maps several
times more often than necessary, and there were nested reads, which Stephan
Kulow's recent depth patch fixed (but in a pretty hacky way;  this commit fixes
it properly).  So VG_(new_exeseg_startup)() now doesn't cause /proc/self/maps
to be re-read.  Unfortunately we do have to re-read /proc/self/maps for mmap(),
because we don't know the filename from the mmap() call (only the file
descriptor, which isn't enough).


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@1830
2003-09-25 17:54:11 +00:00
Dirk Mueller
612b8daeac fix compiler warnings
git-svn-id: svn://svn.valgrind.org/valgrind/trunk@1823
2003-09-18 01:39:50 +00:00
Nicholas Nethercote
c0f0059bf7 Added some skin-visible functions that give skins a bit more control over
how stack snapshots are taken and printed;  they can be used in preference
to VG_(get_ExeContext)() and VG_(pp_ExeContext)().  These are used by
Massif, my heap profiling skin.

Changed --num-callers to allow a backtrace size of 1.

Added code so that when Valgrind fails to disassemble an instruction, the
instructions line/file and address are printed out, which makes it easier to
work out where and what it is.  Required the stack snapshot changes above.

MERGE TO STABLE?


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@1819
2003-09-16 07:41:43 +00:00
Julian Seward
439cee2a05 Increase VG_N_FORKHANDLERSTACK from 2 to 4. For reasons known only to
itself, pth_atfork1 and 2 fail on R H 7.3 for a size-2 stack, but only
with certain skins.  Don't ask me.


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@1789
2003-07-26 17:49:58 +00:00
Nicholas Nethercote
0f871c249c A big commit size-wise, but small concept-wise: removed the ThreadState type
from skin's view, replacing all instances with ThreadId.  Much cleaner.  Had to
change the way VG_(get_ExeContext)() worked a little.  Changed the core/skin
major interface because this breaks the old version.  Also fixed a few minor
related things here and there.


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@1782
2003-07-24 08:45:32 +00:00
Julian Seward
53220a1cbb Use init_ExeContext_storage instead of relying (unintentionally) on
properties of 'static'.  Also, de-globalise this function.  Some days
I really yearn for a proper module system in C.  Come back Haskell,
all is forgiven :-)


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@1781
2003-07-23 23:01:11 +00:00
Julian Seward
f7f560b8e1 Add patch from Sami Liedes <sliedes@cc.hut.fi> making GDB use more flexible:
--gdb-path=/path/to/gdb   allows running some alternate GDB
--input-fd=<n>            allows reading input from some fd other than stdin
I even updated the docs :-)


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@1754
2003-07-13 10:54:33 +00:00
Julian Seward
dd2abcb8e0 In vg_memory.c, startup_segment_callback, fix initialisation ordering
problem which caused the leak checker to misbehave following recent
PLT-bypass workaround.

In short, it is an error to announce to the skin, segments found which
belong to the low-level memory manager, because the skin may then mark
them as accessible to the client.  This is wrong, and the client
should only acquire accessible memory via malloc etc and stack
movement.  Now we carefully avoid mentioning any segment belonging to
the low level memory manager.

Take the opportunity to improve VG_(within_m_state_static) so that it
also detects pointers within the thread table.  This can reduce the
number of blocks the leak checker spuriously thinks are still
reachable.


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@1751
2003-07-12 12:11:39 +00:00
Julian Seward
e4397da1ca A bit of cleaning up now that symbol table reading is no longer optional.
git-svn-id: svn://svn.valgrind.org/valgrind/trunk@1745
2003-07-10 23:31:27 +00:00
Julian Seward
1f01517ca3 Add a new mechanism for intercepting calls, which doesn't depend on
the vagaries of the dynamic linker.  In particular this has been
devised so as to work around errno/h_errno/resolver-state misbehaviour
caused by excessive PLT bypassing in glibc-2.3.2: we need to intercept
calls to __errno_location(), __h_errno_location() and __res_state(),
in threaded programs, but we can't always do that because some calls
made internally within glibc-2.3.2 bypass the PLT.

New mechanism is:

- In vg_symtab2.c, VG_(setup_code_redirect_table), search the
  symbol tables to find the entry points of the above functions,
  and find the corresponding entry points replacements in our
  vg_libpthread.c.  Put these pairs into a table,
  VG_(code_redirect_table).

- In vg_translate.c, VG_(translate), consult the table each time
  a translation is made, and if a hit is found, translate from
  the substitute address instead.

This seems to make corecheck/tests/res_search work properly,
although for some as-yet unknown reason breaks the corecheck
skin.  All other skins appear unaffected.

One unfortunate effect is that the lazy debug info scheme is now
nullified, since we always need to read debug info in order to
generate the redirection table.


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@1743
2003-07-10 00:17:58 +00:00
Dirk Mueller
faf02201e5 spelling fixes
git-svn-id: svn://svn.valgrind.org/valgrind/trunk@1715
2003-07-04 16:18:15 +00:00
Nicholas Nethercote
180b70ed03 Doubled VG_N_WAITING_FDS from 10 to 20. Joshua Moore-Oliva
<josh@chatgris.com> hit his head on it a while ago.


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@1710
2003-06-29 10:18:48 +00:00
Julian Seward
1019b15bec When exiting with VgSrc_BbsDone (switching back to real CPU because
block execution count exceeded, debugging only), restore the signal
state before switching back rather than after.  I no longer understand
why it had to be done afterwards.  This simplifies vg_startup.S a bit.


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@1686
2003-06-14 11:57:59 +00:00
Nicholas Nethercote
9025dfb57d Added support for 'lahf', the twin of 'sahf' which was already implemented.
Tested briefly, seems to work.


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@1668
2003-06-03 13:38:51 +00:00
Nicholas Nethercote
136a5e69d5 This commit fixes up the handling of shadow registers quite a bit.
Removed the SK_(written_shadow_regs_values)() function.  Instead, skins that
use shadow regs can track the `post_regs_write_init' event, and set the shadow
regs from within it.  This is much more flexible, since it allows each shadow
register to be set to a separate value if necessary.  It also matches the new
shadow-reg-change events described below.

In the core, there were some places where the shadow regs were changed, and
skins had no way of knowing about it, which was a problem for some skins.
So I added a bunch of new events to notify skins about these:

  post_reg_write_syscall_return
  post_reg_write_deliver_signal
  post_reg_write_pthread_return
  post_reg_write_clientreq_return
  post_reg_write_clientcall_return

Any skin that uses shadow regs should almost certainly track these events.  The
post_reg_write_clientcall_return allows a skin to tailor the shadow reg of the
return value of a CLIENTCALL'd function appropriately;  this is especially
useful when replacing malloc() et al.

Defined some macros that should be used *whenever the core changes the value of
a shadow register* :

  SET_SYSCALL_RETVAL
  SET_SIGNAL_EDX          (maybe should be SET_SIGNAL_RETVAL? ... not sure)
  SET_SIGNAL_ESP
  SET_CLREQ_RETVAL
  SET_CLCALL_RETVAL
  SET_PTHREQ_ESP
  SET_PTHREQ_RETVAL

These replace all the old SET_EAX and SET_EDX macros, and are added in a few
places where the shadow-reg update was missing.

Added shadow registers to the machine state saved/restored when signal handlers
are pushed/popped (they were missing).

Added skin-callable functions VG_(set_return_from_syscall_shadow)() and
VG_(get_exit_status_shadow)() which are useful and abstract away from which
registers the results are in.

Also, poll() changes %ebx (it's first argument) sometimes, I don't know why.
So we notify skins about that too (with the `post_reg_write_syscall_return'
event, which isn't ideal I guess...)


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@1642
2003-05-19 15:04:06 +00:00
Nicholas Nethercote
96c3404d77 Fixed suppression reading so that you can specify up to four "fun:" or "obj:"
lines (it was 3 due to a bug).

Also removed VG_(get_suppressions)() which wasn't being used, and changed
VG_(exitcode) to an Int, as it should be.


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@1628
2003-05-12 20:40:13 +00:00
Julian Seward
c82b1c580f Increase VG_N_CLEANUPSTACK to 16.
git-svn-id: svn://svn.valgrind.org/valgrind/trunk@1588
2003-05-04 13:02:10 +00:00
Julian Seward
c873dac6c4 Unchain translations when doing VALGRIND_DISCARD_TRANSLATIONS. Otherwise
the tt/tc are left in an inconsistent state afterwards.  (Adam Gundy
<arg@cyberscience.com>)


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@1586
2003-05-04 12:32:56 +00:00
Nicholas Nethercote
90ef0ac1d6 Moved the CLIENT_tstCALL[0123] requests out of valgrind.h into vg_skin.h,
because there was no point exposing them to clients, as they don't know the
ThreadState type.

Also, removed the LOGMESSAGE request type, replaced it with calls to
VG_(message) via the generic VALGRIND_NON_SIMD_CALL2.

In fact, almost every single pthread client request could be removed in this
same way.  That would result in less code, which would be nice... yeah, real
nice.


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@1584
2003-05-02 17:53:54 +00:00
Nicholas Nethercote
4bf271eb18 Added "_W" suffix to stack sizes to indicate they are in words.
git-svn-id: svn://svn.valgrind.org/valgrind/trunk@1578
2003-05-01 08:06:41 +00:00
Nicholas Nethercote
d2457b59af Removed magic numbers for VG_(stack) size and VG_(sigstack) size, made into
#defined constants.  I hope I got all the right places.  I also hope that they
can be different sizes;  experiments seem to indicate so.  Also if I reduce the
size of the main stack at all below its current 10000 I get problems, but that
was happening before anyway, I think.

Julian, you may want to sanity check this.


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@1577
2003-04-30 20:49:10 +00:00
Julian Seward
23ae8adf30 Extend the state components in VG_(m_state_static) and VG_(baseBlock)
to include the SSE/SSE2 architectural state.  Automagically detect
at startup, in vg_startup.S, whether or not this is a SSE-enabled
CPU and act accordingly.  All subsequent FPU/SSE state transfers
between the simulated and real machine are then done either with
fsave/frstor (as before) or fxsave/fxrstor (the SSE equivalents).

Fragile and fiddly; (1) the SSE state needs to be stored on a 16-byte
boundary, and (2) certain bits in the saved MXCSR reg in a state
written by fxsave need to be anded out before we can safely restore
using fxrstor.

It does appear to work.  I'd appreciate people trying it out on
various CPUs to establish whether the SSE / not-SSE check works
right, and/or anything else is broken.

Unfortunately makes some programs run significantly slower.
I don't know why.  Perhaps due to copying around more processor
state than there was before (SSE state is 512 bytes, FPU state
was only 108).  I will look into this.


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@1574
2003-04-29 23:50:00 +00:00
Julian Seward
4efd705c4b Fix threading problems on glibc-2.3.2 or later. Note this is *not*
NPTL support.

The behaviour of weak vs strong symbols seems to have changed in
glibc-2.3.2.  This caused problems in coregrind/vg_intercept.c,
wherein strong symbols in vg_libpthread.c were intended to
override weak symbols in vg_intercept.c, in order to give alternative
thread-safe implementations of some functions, poll(), select(), etc.

The change involves moving the nonblocking implementations of poll, etc
into vg_intercept.c, renaming them to (eg)  VGR_(poll), and routing
all calls to poll to VGR_(poll) [dually for other such fns].  This
means even single-threaded programs now use these functions, but
that doesn't strike me as harmful.

MERGE TO STABLE, if it doesn't break anything


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@1559
2003-04-26 20:11:15 +00:00
Julian Seward
68c23c28d2 Record the correct address of the initial thread's stack, as determined
by the initial scan of /proc/self/maps, so that we correctly identify
addresses in it.  This fix is thanks to Dirk Mueller.


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@1550
2003-04-23 21:18:52 +00:00
Nicholas Nethercote
e7b23faa99 Implemented malloc_usable_size(), which was used in a program written by
Frederic Delley <fdelley@cisco.com>.

This required also adding VG_(arena_payload_szB)().


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@1540
2003-04-22 22:45:55 +00:00
Nicholas Nethercote
1b48c55fc5 Added two client requests: VALGRIND_COUNT_ERRORS and VALGRIND_COUNT_LEAKS.
The first returns the number of errors found so far, and is a core request.
The second returns the number of bytes found
reachable/dubious/leaked/suppressed by all leak checks so far, for Memcheck and
Addrcheck.

Both are useful for using Valgrind in regression test suites where multiple
tests are present in a single file -- one can run Valgrind with no output
(using --logfile-fd=-1) and use the requests after each test to determine if
any errors happened.

Had to rename and make public vg_n_errs_found --> VG_(n_errs_found) to do so.
Nb: leak errors are not counted as errors for the purposes of
VALGRIND_COUNT_ERRORS.  This was decided as the best thing to do after
discussion with Olly Betts, who original suggested these changes.

Pulled out common client request code shared between Memcheck and Addrcheck.

Added a regression test for this.

Added some documentation too.


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@1533
2003-04-21 13:24:40 +00:00
Nicholas Nethercote
ac7027c441 Updated copyright notices for 2003. Only 4 months late.
git-svn-id: svn://svn.valgrind.org/valgrind/trunk@1526
2003-04-15 14:58:06 +00:00
Nicholas Nethercote
982fa6481a -----------------------------------------------------------------------------
overview
-----------------------------------------------------------------------------
Previously Valgrind had its own versions of malloc() et al that replaced
glibc's.  This is necessary for various reasons for Memcheck, but isn't needed,
and was actually detrimental, to some other skins.  I never managed to treat
this satisfactorily w.r.t the core/skin split.

Now I have.  If a skin needs to know about malloc() et al, it must provide its
own replacements.  But because this is not uncommon, the core provides a module
vg_replace_malloc.c which a skin can link with, which provides skeleton
definitions, to reduce the amount of work a skin must do.  The skeletons handle
the transfer of control from the simd CPU to the real CPU, and also the
--alignment, --sloppy-malloc and --trace-malloc options.  These skeleton
definitions subsequently call functions SK_(malloc), SK_(free), etc, which the
skin must define;  in these functions the skin can do the things it needs to do
about tracking heap blocks.

For skins that track extra info about malloc'd blocks -- previously done with
ShadowChunks -- there is a new file vg_hashtable.c that implements a
generic-ish hash table (using dodgy C-style inheritance using struct overlays)
which allows skins to continue doing this fairly easily.

Skins can also replace other functions too, eg. Memcheck has its own versions
of strcpy(), memcpy(), etc.

Overall, it's slightly more work now for skins that need to replace malloc(),
but other skins don't have to use Valgrind's malloc(), so they're getting a
"purer" program run, which is good, and most of the remaining rough edges from
the core/skin split have been removed.

-----------------------------------------------------------------------------
details
-----------------------------------------------------------------------------
Moved malloc() et al intercepts from vg_clientfuncs.c into vg_replace_malloc.c.
Skins can link to it if they want to replace malloc() and friends;  it does
some stuff then passes control to SK_(malloc)() et al which the skin must
define.  They can call VG_(cli_malloc)() and VG_(cli_free)() to do the actual
allocation/deallocation.  Redzone size for the client (the CLIENT arena) is
specified by the static variable VG_(vg_malloc_redzone_szB).
vg_replace_malloc.c thus represents a kind of "mantle" level service.

To get automake to build vg_replace_malloc.o, had to resort to a similar trick
as used for the demangler -- ask for a "no install" library (which is never
used) to be built from it.

Note that all malloc, calloc, realloc, builtin_new, builtin_vec_new, memalign
are now aware of --alignment, when running on simd CPU or real CPU.

This means the new_mem_heap, die_mem_heap, copy_mem_heap and ban_mem_heap
events no longer exist, since the core doesn't control malloc() any more, and
skins can watch for these events themselves.

This required moving all the ShadowChunk stuff out of the core, which meant
the sizeof_shadow_block ``need'' could be removed, yay -- it was a horrible
hack.  Now ShadowChunks are done with a generic HashTable type, in
vg_hashtable.c, which skins can "inherit from" (in a dodgy C-only fashion by
using structs with similar layouts).  Also, the free_list stuff was all moved
as a part of this.  Also, VgAllocKind was moved out of core into
Memcheck/Addrcheck and renamed MAC_AllocKind.

Moved these options out of core into vg_replace_malloc.c:
    --trace-malloc
    --sloppy-malloc
    --alignment

The alternative_free ``need'' could go, too, since Memcheck is now in complete
control of free(), yay -- another horribility.

The bad_free and free_mismatch events could go too, since they're now not
detected by core, yay -- yet another horribility.

Moved malloc() et al wrappers for Memcheck out of vg_clientmalloc.c into
mac_malloc_wrappers.c.  Helgrind has its own wrappers now too.

Introduced VG_USERREQ__CLIENT_CALL[123] client requests.  When a skin function
is operating on the simd CPU, this will call a given function and run it on the
real CPU.  The macros VG_NON_SIMD_CALL[123] in valgrind.h present a cleaner
interface to actually use.  Also introduce analogues of these that pass 'tst'
from the scheduler as the first arg to the called function -- needed for
MC_(client_malloc)() et al.

Fiddled with USERREQ_{MALLOC,FREE} etc. in vg_scheduler.c; they call
SK_({malloc,free})() which by default call VG_(cli_malloc)() -- can't call
glibc's malloc() here.  All the other default SK_(calloc)() etc. instantly
panic; there's a lock variable to ensure that the default SK_({malloc,free})()
are only called from the scheduler, which prevents a skin from forgetting to
override SK_({malloc,free})().  Got rid of the unused USERREQ_CALLOC,
USERREQ_BUILTIN_NEW, etc.

Moved special versions of strcpy/strlen, etc, memcpy() and memchr() into
mac_replace_strmem.c -- they are only necessary for memcheck, because the
hyper-optimised normal glibc versions confuse it, and for memcpy() etc. overlap
checking.

Also added dst/src overlap checks to strcpy(), memcpy(), strcat().  They are
reported not as proper errors, but just with single line warnings, as for silly
args to malloc() et al;  this is mainly because they're on the simulated CPU
and proper error handling would be a pain;  hopefully they're rare enough to
not be a problem.  The strcpy check is done after the copy, because it would
require counting the length of the string beforehand.  Also added strncpy() and
strncat(), which have overlap checks too.  Note that addrcheck doesn't do
overlap checking.

Put USERREQ__LOGMESSAGE in vg_skin.h to do the overlap check error messages.

After removing malloc() et al and strcpy() et al out of vg_clientfuncs.c, moved
the remaining three things (sigsuspend, VG_(__libc_freeres_wrapper),
__errno_location) into vg_intercept.c, since it contains things that run on the
simulated CPU too.  Removed vg_clientfuncs.c altogether.

Moved regression test "malloc3" out of corecheck into memcheck, since corecheck
no longer looks for silly (eg. negative) args to malloc().

Removed the m_eip, m_esp, m_ebp fields from the `Error' type.  They were being
set up, and then read immediately only once, only if GDB attachment was done.
So now they're just being held in local variables.  This saves 12 bytes per
Error.

Made replacement calloc() check for --sloppy-malloc;  previously it didn't.

Added "silly" negative size arg check to realloc(), it didn't have one.

Changed VG_(read_selfprocmaps)() so it can parse the file directly, or from a
previously read buffer.  Buffer can be filled with the new
VG_(read_selfprocmaps_contents)().  Using this at start-up to snapshot
/proc/self/maps before the skins do anything, and then parsing it once they
have done their setup stuff.  Skins can now safely call VG_(malloc)() in
SK_({pre,post}_clo_init)() without the mmap'd superblock erroneously being
identified as client memory.

Changed the --help usage message slightly, now divided into four sections: core
normal, skin normal, core debugging, skin debugging.  Changed the interface for
the command_line_options need slightly -- now two functions, VG_(print_usage)()
and VG_(print_debug_usage)(), and they do the printing themselves, instead of
just returning a string -- that's more flexible.

Removed DEBUG_CLIENTMALLOC code, it wasn't being used and was a pain.

Added a regression test testing leak suppressions (nanoleak_supp), and another
testing strcpy/memcpy/etc overlap warnings (overlap).

Also changed Addrcheck to link with the files shared with Memcheck, rather than
#including the .c files directly.

Commoned up a little more shared Addrcheck/Memcheck code, for the usage
message, and initialisation/finalisation.

Added a Bool param to VG_(unique_error)() dictating whether it should allow
GDB to be attached; for leak checks, because we don't want to attach GDB on
leak errors (causes seg faults).  A bit hacky, but it will do.

Had to change lots of the expected outputs from regression files now that
malloc() et al are in vg_replace_malloc.c rather than vg_clientfuncs.c.


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@1524
2003-04-15 13:03:23 +00:00
Nicholas Nethercote
594c7fc446 This commit moves some skin-specific stuff out of core, and generally
neatens other things up.

Also, it adds the --gen-suppressions option for automatically generating
suppressions for each error.

Note that it changes the core/skin interface:
SK_(dup_extra_and_update)() is replaced by SK_(update_extra)(), and
SK_(get_error_name)() and SK_(print_extra_suppression_info)() are added.


-----------------------------------------------------------------------------
details
-----------------------------------------------------------------------------
Removed ac_common.c -- it just #included another .c file;  moved the
#include into ac_main.c.

Introduced "mac_" prefixes for files shared between Addrcheck and Memcheck,
to make it clearer which code is shared.  Also using a "MAC_" prefix for
functions and variables and types that are shared.  Addrcheck doesn't see
the "MC_" prefix at all.

Factored out almost-identical mc_describe_addr() and describe_addr()
(AddrCheck's version) into MAC_(describe_addr)().

Got rid of the "pp_ExeContext" closure passed to SK_(pp_SkinError)(), it
wasn't really necessary.

Introduced MAC_(pp_shared_SkinError)() for the error printing code shared by
Addrcheck and Memcheck.  Fixed some bogus stuff in Addrcheck error messages
about "uninitialised bytes" (there because of an imperfect conversion from
Memcheck).

Moved the leak checker out of core (vg_memory.c), into mac_leakcheck.c.
 - This meant the hacky way of recording Leak errors, which was different to
   normal errors, could be changed to something better:  introduced a
   function VG_(unique_error)(), which unlike VG_(maybe_record_error)() just
   prints the error (unless suppressed) but doesn't record it.  Used for
   leaks;  a much better solution all round as it allowed me to remove a lot
   of almost-identical code from leak handling (is_suppressible_leak(),
   leaksupp_matches_callers()).

 - As part of this, changed the horrible SK_(dup_extra_and_update) into the
   slightly less horrible SK_(update_extra), which returns the size of the
   `extra' part for the core to duplicate.

 - Also renamed it from VG_(generic_detect_memory_leaks)() to
   MAC_(do_detect_memory_leaks).  In making the code nicer w.r.t suppressions
   and error reporting, I tied it a bit more closely to Memcheck/Addrcheck,
   and got rid of some of the args.  It's not really "generic" any more, but
   then it never really was.  (This could be undone, but there doesn't seem
   to be much point.)

STREQ and STREQN were #defined in several places, and in two different ways.
Made global macros VG_STREQ, VG_CLO_STREQ and VG_CLO_STREQN in vg_skin.h.

Added the --gen-suppressions code.  This required adding the functions
SK_(get_error_name)() and SK_(print_extra_suppression_info)() for skins that
use the error handling need.

Added documentation for --gen-suppressions, and fixed some other minor document
problems.

Various other minor related changes too.


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@1517
2003-04-08 00:08:52 +00:00
Nicholas Nethercote
f360d3a384 -----------------------------------------------------------------------------
overview
-----------------------------------------------------------------------------
This commit introduces an optimisation that speeds up Memcheck by roughly
-3 -- 28%, and Addrcheck by 1 -- 36%, at least for the SPEC2000 benchmarks on
my 1400MHz Athlon.

Basic idea: that handling of A/V bit updates on %esp-adjustments was quite
sub-optimal -- for each "PUT ESP", a function was called that computed the
delta from the old and new ESPs, and then called a looping function to deal
with it.

Improvements:

  1. most of the time, the delta can be seen from the code.  So there's no need
     to compute it.

  2. when the delta is known, we can directly call a skin function to handle it.

  3. we can specialise for certain common cases (eg. +/- 4, 8, 12, 16, 32),
     including having unrolled loops for these.

This slightly bloats UCode because of setting up args for the call, and for
updating ESP in code (previously was done in the called C function).  Eg. for
`date' the code expansion ratio goes from 14.2 --> 14.6.  But it's much faster.

Note that skins don't have to use the specialised cases, they can just
define the ordinary case if they want;  the specialised cases are only used
if present.

-----------------------------------------------------------------------------
details
-----------------------------------------------------------------------------
Removed addrcheck/ac_common.c, put its (minimal) contents in ac_main.c.

Updated the major interface version, because this change isn't binary
compatible with the old core/skin interface.

Removed the hooks {new,die}_mem_stack_aligned, replaced with the better
{new,die}_mem_stack_{4,8,12,16,32}.  Still have the generic {die,new}_mem_stack
hooks.  These are called directly from UCode, thanks to a new pass that occurs
between instrumentation and register allocation (but only if the skin uses
these stack-adjustment hooks).  VG_(unknown_esp_update)() is called from UCode
for the generic case;  it determines if it's a stack switch, and calls the
generic {new,die}_stack_mem hooks accordingly.  This meant
synth_handle_esp_assignment() could be removed.

The new %esp-delta computation phase is in vg_translate.c.

In Memcheck and Addrcheck, added functions for updating the A and V bits of a
single aligned word and a single aligned doubleword.  These are called from the
specialised functions new_mem_stack_4, etc.  Could remove the one for the old
hooks new_mem_stack_aligned and die_mem_stack_aligned.

In mc_common.h, added a big macro containing the definitions of new_mem_stack_4
et al.  It's ``instantiated'' separately by Memcheck and Addrcheck.  The macro
is a bit klugey, but I did it that way because speed is vital for these
functions, so eg. a function pointer would have slowed things down.

Updated the built-in profiling events appropriately for the changes (removed
one old event, added a new one;  finding their names is left as an exercise for
the reader).

Fixed memory event profiling in {Addr,Mem}check, which had rotted.

A few other minor things.


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@1510
2003-04-07 14:40:25 +00:00
Julian Seward
a071ba39cb A minimal set of changes to make it work on Red Hat 9, at least in the
interim.  All hats off to Graydon Hoare for this, plus to whoever
devised the LD_ASSUME_KERNEL trapdoor.

This does not provide NPTL support.  Instead it turns out we can ask
for the old LinuxThreads interface to be used (wonderful!)

Other than that we have to deal with kernels with SYSINFO pages at the
top of memory.  No big deal, apparently.

MERGE TO STABLE


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@1508
2003-04-06 12:23:27 +00:00
Julian Seward
481944a72c startup_segment_callback: Get rid of completely pointless check re
ASSUMED_EXE_BASE.  This is now pointless, and causes problems for people
using Clearcase, since it seems their shared objects may not follow
the convention that they end in .so.

MERGE TO STABLE


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@1458
2003-03-15 20:01:21 +00:00
Nicholas Nethercote
08f8bf00c2 Added two new events: pre_deliver_signal and post_deliver_signal.
git-svn-id: svn://svn.valgrind.org/valgrind/trunk@1434
2003-02-24 10:36:48 +00:00
Julian Seward
2b039db360 Further cleanups re new method for finding the stack segment at
startup.


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@1423
2003-02-23 01:41:17 +00:00
Nicholas Nethercote
3d007bbf9a Fixed a minor bug -- the condition for determining whether
VG_(handle_esp_assignment)() was needed by a skin (and thus whether to register
it in the baseBlock) was different to that used when determining whether to
call it in code generation... so it could be (attempted to be) called having
not been registered.

Fixed this by consistifying the conditions, using a function
VG_(need_to_handle_esp_assignment)() that is used in both places.  The bug
hadn't been found previously because no existing skin exercised the mismatched
conditions in conflicting ways.

Also took VG_(track).post_mem_write out of consideration because it's no longer
important (due to a change in how stack switching is detected).

----
Improved the error message for when a helper can't be found in the baseBlock --
now looks up the debug info to tell you the name of the not-found function.

----
Increased the number of noncompact helpers allowed from 8 to 24

----
Removed a magic number that was hardcoded all over the place, introducing
VG_MAX_REGS_USED for the size of the arrays needed by VG_(get_reg_usage)()

----
Also added these functions

   VG_(get_archreg)()
   VG_(get_thread_archreg)()
   VG_(get_thread_shadow_archreg)()
   VG_(set_thread_shadow_archreg)()

which can be useful for skins.


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@1419
2003-02-10 10:17:26 +00:00
Nicholas Nethercote
e96c064080 Made VGOFF_(helper_idiv_64_32) and all the similar helper offsets visible to
skins, so they can determine which helper is being called for CALLM
instructions.


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@1415
2003-02-03 12:33:31 +00:00
Nicholas Nethercote
94e46fbb49 Made the setting of VG_(details).avg_translation_sizeB optional, defaulting to
100 bytes (added VG_DEFAULT_TRANS_SIZEB).  Took the now-unnecessary settings
out of Nulgrind and CoreCheck.  Also made .avg_translation_sizeB a UInt (from
an Int), to avoid possibility of negatives.


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@1413
2003-02-03 12:20:07 +00:00
Nicholas Nethercote
c8a14631c3 Renamed VG_(nameCondcode)() as VG_(name_UCondcode)() to make it consistent
with similar functions, and made it visible to skins (useful).

Also bumped up the skin interface minor version number due to this change; this
bumping will cover any other binary-compatible changes between now and the next
release (after 1.9.3).


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@1410
2003-02-03 11:17:46 +00:00
Nicholas Nethercote
57dbd484b8 Two minor changes:
- When recording errors, VG_(dup_extra_and_update)() previously was only
    called if the 'extra' field was non-NULL.  Now it's always called.
    This is for two reasons:

      a. The 'extra' field could be holding a non-pointer value that just
         happens to be 0
      b. The skin might want to update the error, even if it doesn't use
         the 'extra' field.

    A pretty minor change that shouldn't upset anybody.

  - Made the ExeContext 'where' field of an error visible to skins, by
    adding VG_(get_error_where)().  This can be useful, eg. for comparing
    errors for equality.


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@1406
2003-01-28 19:59:38 +00:00
Julian Seward
79a981783a Implement suppressions for leak checks, which is a fairly frequently
asked-for feature.

A leak-check suppression looks like any other, and has the name 'Leak':

{
   example-leak-suppression
   Memcheck,Addrcheck:Leak
   fun:malloc
   fun:foo
   fun:main
}

Fitting this into the core/skin split proved very tricky.  Problem is
we want to scan the suppressions list to find Leak suppressions, but

- The core code can't do it because LeakSupp is a skin-specific
  suppression kind.

- The skin code can't do it because most (all) of the types and
  structures for the suppressions are private to the core.

Eventual "solution" (least-worst thing I could think of) is for the
skins using the leak checker to pass it the value of LeakSupp.
Even that isn't really clean because the skins consider it a value
of type MemCheckSuppKind but the core thinks it must be a
CoreSuppKind, and the two are not to be reconciled.  So I kludged
around this by casting it to a UInt.

Nick, perhaps you know some way to smooth this out?

Apart from that all changes are straightforward.


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@1390
2002-12-26 01:53:45 +00:00
Julian Seward
a8c2b4c7de Merge patch from JeremyF:
66-illegal-instr

When translation encounters an illegal instruction, emit a call to an
illegal instruction rather than giving up altogether. Some programs
check for CPU capabilities by actually trying them out, so we want to
match a dumb Pentium's behaviour a little better.

It still prints the message, so it won't hide actual illegal or
mis-parsed instructions.  I was hoping this might make the Nvidia
drivers realize they're running on a pre-MMX P5, but apparently they
just won't take that as an answer.  It does make the virtual CPU
behave a little more like a real CPU though.


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@1370
2002-12-14 23:59:09 +00:00
Julian Seward
685745d038 Get rid of the flag --fast-jcc; it's wired-on by default. Assumes that
pushf/popf is catastrophically expensive on most target CPUs, which is
certainly true for P3 and Athlon and I assume (but not checked) P4.


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@1351
2002-12-08 22:24:59 +00:00
Julian Seward
9903164536 Merge patches from JeremyF, to do lazy eflags updating:
- D flag is seperated from the rest (OSZCAP)

- Minimise transfers between real and simulated %eflags since these
  are very expensive.

61-special-d

Make the D flag special. Store it separately in the baseblock rather
than in EFLAGs. This is because it is used almost completely unlike
the other flags, and mashing them together just makes maintaining
eflags hard.

62-lazy-eflags

Implements lazy eflags save and restore. Helps a lot.

Hopefully more documentation to follow.


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@1346
2002-12-08 18:20:01 +00:00
Julian Seward
a162e85544 Change the way INCEIP is done. Instead of emitting add insns, keep
track of the current %EIP value and write it to memory at an INCEIP.
Uses JeremyF's idea of only writing the lowest 8 bits if the upper 24
are unchanged since the previous write.  [might this cause probls
to do with write combining on high-performance CPUs?  To be checked
out.]

On a simple program running a small inner loop, this gets about 2/3
the benefits of removing INCEIPs altogether, compared with the add-insn
scheme.

I tried a much more complex scheme too, in which we do analysis to
remove as many INCEIPs as possible if it is possible to show that
there will be no EIP reads in between them.  This seemed to make
almost no improvement on real programs (kate, xedit) and adds some
code and slows down the code generator, so I don't think it's worth
the hassle.


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@1343
2002-12-01 19:40:49 +00:00
Julian Seward
bf0d5036da Merge patch from JeremyF:
50-fast-cond

Implement Julian's idea for fast conditional jumps. Rather than fully
restoring the eflags register with an expensive push-popf pair, just
test the flag bits directly out of the base block. Faster, and smaller
code too!


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@1339
2002-11-30 15:01:01 +00:00
Julian Seward
dd1838f1f5 Merge in a somewhat modified patch version of Jeremy Fitzhardinge's
translation chaining patch.

47-chained-bb

This implements basic-block chaining. Rather than always going through
the dispatch loop, a BB may jump directly to a successor BB if it is
present in the translation cache.

When the BB's code is first generated, the jumps to the successor BBs
are filled with undefined instructions. When the BB is inserted into
the translation cache, the undefined instructions are replaced with a
call to VG_(patch_me). When VG_(patch_me) is called, it looks up the
desired target address in the fast translation cache. If present, it
backpatches the call to patch_me with a jump to the translated target
BB. If the fast lookup fails, it falls back into the normal dispatch
loop.

When the parts of the translation cache are discarded, all translations
are unchained, so as to ensure we don't have direct jumps to code which
has been thrown away.

This optimisation only has effect on direct jumps; indirect jumps
(including returns) still go through the dispatch loop.  The -v stats
indicate a worst-case rate of about 16% of jumps having to go via the
slow mechanism.  This will be a combination of function returns and
genuine indirect jumps.

Certain parts of the dispatch loop's actions have to be moved into
each basic block; namely: updating the virtual EIP and keeping track
of the basic block counter.

At present, basic block chaining seems to improve performance by up to
25% with --skin=none.  Gains for skins adding more instrumentation
will be correspondingly smaller.

There is a command line option: --chain-bb=yes|no (defaults to yes).


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@1336
2002-11-30 14:00:47 +00:00
Julian Seward
31fb0482e7 Complete integration of the new code management (sectored FIFO) story.
This commit adds stats gathering / printing (use -v -v), and selection
of sector size decided by asking skins, via
VG_(details).avg_translation_sizeB, the average size of their
translations.


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@1334
2002-11-30 00:49:43 +00:00
Julian Seward
205244f4f1 Complete overhaul of the storage of translations to properly support
translation chaining.  The old LRU system has gone, since it required
marking each translation each time it was used -- simulating a
reference bit.  This is unacceptably expensive.

New scheme uses FIFO discard.  TC is split into a variable number
(currently 8) parts.  When all 8 parts are full, the oldest is
discarded and reused for allocation.  This somewhat guards against
discarding recently-made translations and performs well in practice.

TT entries are simplified: the orig and trans size fields are now
stored in the TC, not in the TT.  The TC entries are "self
describing", so it is possible to scan forwards through the TC entries
and rebuild the TT from them.  TC entries are now word-aligned.

VG_(tt_fast) entries now point to TC entries, not TT entries.

The main dispatch loop now is 2 insns shorter since there's no need to
mark the current epoch on each TT entry as it is used.  For that
matter, there's no longer any need for the notion of a current epoch
anyway.

It's all a great deal simpler than the old scheme, and it seems
significantly faster too.


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@1333
2002-11-29 01:02:45 +00:00
Nicholas Nethercote
7cf2e186e3 Lots of changes to future-proof the core/skin interface, making it less likely
that changes will cause binary incompatibilities.  Mostly done by hiding naked
structs with function calls.

Structs hidden in this way were: UCodeBlock, SkinSupp and SkinError (which were
merged back with CoreSupp and CoreError into single types Supp and Error),
ShadowChunk, VgDetails, VgNeeds and VgTrackEvents.  The last three are the most
important ones, as they are (I think) the most likely to change.

Suitable get()/set() methods were defined for each one.  The way UCodeBlocks
are copied for instrumentation by skins is a little different now, using
setup_UCodeBlock.  Had to add a few other functions here n there.  Changed
how SK_(complete_shadow_chunk) works a bit.

Added a file coregrind/vg_needs.c which contains all the get/set functions.
It's pretty simple.

The changes are not totally ideal -- eg. ShadowChunks has get()/set() methods
for its `next' field which arguably shouldn't be exposed (betraying the fact
that it's a linked list), and the get()/set() methods are a bit cumbersome at
times, esp. for `Error' because the fields are accessed quite a few times, and
the treatment of Supps and Errors is a bit inconsistent (but they are used in
different ways), and sizeof_shadow_blocks is still a hack.  But still better
than naked structs.  And one advantage is that a bit of sanity checking can be
performed by the get()/set() methods, as is done for VG_({get,set}_sc_extra)()
to make sure no reading/writing occurs outside the allowed area.

I didn't do it for UInstr, because its fields are accessed directly in lots and
lots of spots, which would have been a great big pain and I was a little
worried about overhead of calling lots of extra functions, although in practice
translation times are small enough that it probably doesn't matter.

Updated the example skin and the docs, too, hurrah.


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@1314
2002-11-14 12:42:47 +00:00
Julian Seward
0cefc40a95 Merge patch from JeremyF:
22-mutex-destroy-unlock:

It seems that glibc assumes in its internal use of pthreads that
destroying a lock implicity unlocks it. This patch handles this case
so that lock ownership tracking is accurate.

Also handles the case of the dyanmic linker wanting to do locking
before Valgrind has started up. vg_libpthread now implements toy
lock/unlock functions to keep it happy and leave the locks in a
sensible state. Implements some untested code to handle the case where
a lock is taken before Valgrind is running but released afterwards.


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@1297
2002-11-13 21:57:52 +00:00