Commit Graph

54 Commits

Author SHA1 Message Date
Julian Seward
4ec7e413eb Increase thread scheduling quantum from 20000 bbs to 50000 bbs.
git-svn-id: svn://svn.valgrind.org/valgrind/trunk@328
2002-05-28 11:27:31 +00:00
Julian Seward
6b9ba9848a Fix various problems with new thread start / stop / detach stuff.
git-svn-id: svn://svn.valgrind.org/valgrind/trunk@327
2002-05-28 11:00:01 +00:00
Julian Seward
fbd9d9f778 DO NOT UPDATE! COMPILES BUT DOESN'T WORK.
Major overhaul to the way thread startup and exit is done.  Removes some
ugly gunk in the scheduler, and adds support for thread detaching and
cancellation.


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@326
2002-05-28 01:36:45 +00:00
Julian Seward
297db5c10c Implement sigaltstack. Most of the logic is copied more-or-less
verbatim from the Linux kernel sources, which has to be a good thing.


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@309
2002-05-22 23:34:20 +00:00
Julian Seward
cce8a3ebd3 Implement pthread_yield.
git-svn-id: svn://svn.valgrind.org/valgrind/trunk@308
2002-05-22 13:17:31 +00:00
Julian Seward
96b04d4f30 Fix fork/exec stuff so it works again. We have to mangle LD_LIBRARY_PATH
as well as LD_PRELOAD, so as to make our libpthread.so go out of scope
when a child which we don't want to trace, is exec'd.  Otherwise the
child can wind up being connected to our libpthread.so but not to
valgrind.so, which is an unworkable combination; you have to be connected
to both or neither.


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@291
2002-05-18 13:14:17 +00:00
Julian Seward
6610ca19b3 Remove existing non-working support for self-modifying code, and instead
add a simple compromise, in which the client can notify valgrind
that certain code address ranges are invalid and should be retranslated.
This is done using the VALGRIND_DISCARD_TRANSLATIONS macro in valgrind.h.

At the same time take the opportunity to close the potentially fatal
loophole that translations for executable segments were not being
discarded when those segments were munmapped.  They are now.

Documentation updated.


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@274
2002-05-16 11:06:21 +00:00
Julian Seward
30199fec47 In accordance with "build one to throw away, you will anyway (tm)",
throw away the old signals simulation and more or less start again
from scratch.  vg_signals.c is nearly a complete rewrite.  In fact
this is now the third generation of the signals simulation.

The purpose of this is to properly support signals in threads -- a
nightmare combination.  pthread_sigmask, pthread_kill and sigwait
are now alledged to work as POSIX requires.

In the process, throw away confusing and conceptually muddled old
implementation and replace with something which is more verbose but
conceptually cleaner, simpler and easier to argue is correct.

* When the client does sigaction/sigprocmask et al, the resulting
  changes are stored verbatim in SCSS -- the Static Client Signal State.
  So SCSS is the state the client believes the kernel is in.

* Every time SCSS changes, we recalculate the state the kernel
  *should* be in so that our signal simulation works.  This is the
  SKSS -- Static Kernel Signal State.  The kernel state is then
  updated accordingly.  By diffing the new and old SKSSs, the
  number of real system calls made is minimised.

* The dynamic state of the client's signals is stored in DCSS
  -- Dynamic Client Signal State.  This just records which signals
  are pending for which threads.

The big advantage of this scheme over the previous is that the SCSS ->
SKSS mapping is made explicit and gathered all in one place, rather
than spread out in a confusing way and done implicitly.  That makes it
all lot easier to decide if the mapping, which is really the heart of
the signals simulation, is correct or not.


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@271
2002-05-15 21:13:39 +00:00
Julian Seward
0ba6f33e4f Add support for pthread_sigmask() and sigwait(). All absolutely
horrible, especially the latter.


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@266
2002-05-13 00:16:03 +00:00
Julian Seward
d6920d2b5c Fix spelling mistake: wierd*hacks --> weird*hacks
Also add a testcase.


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@265
2002-05-12 10:52:16 +00:00
Julian Seward
2943666eb5 In order to catch timeout events on fds which are readable and which
have been ioctl(TCSETA)'d with a VTIMEout, we appear to need to ask if
the fd is writable, for some reason.  Ask me not why.  Since this is
strange and potentially troublesome we only do it if the user asks
specially, by specifying --wierd-hacks=ioctl-VTIME.


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@264
2002-05-12 03:00:17 +00:00
Julian Seward
46111c06e3 Kernel 2.4 / glibc 2.2.X build fixes for recent startup changes.
git-svn-id: svn://svn.valgrind.org/valgrind/trunk@259
2002-05-10 22:31:40 +00:00
Julian Seward
6a123a63ea Build fixes for Red Hat 6.2.
git-svn-id: svn://svn.valgrind.org/valgrind/trunk@248
2002-05-10 00:46:59 +00:00
Julian Seward
5bf4e3319d Remove valgrind's use of libc-supplied stat() and sbrk(). Now the only
sysbols we need from libc are __umoddi3 and __udivdi3 ; other than that
valgrind.so is completely self-contained.


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@244
2002-05-09 17:38:13 +00:00
Julian Seward
9bcb60e01a Complain about NVidia's libGL.so also when an 0x8C opcode is encountered.
git-svn-id: svn://svn.valgrind.org/valgrind/trunk@235
2002-05-08 01:58:18 +00:00
Julian Seward
ef33a1672e Improvements to the error-collecting machinery:
- Don't waste a potentially huge amount of time calling describe_addr
  on addresses in errors we aren't going to show.

- If an invalid address is just below %ESP, say that it might be due
  to a gcc bug.  Increase the window in which this is allowed to
  1024 bytes below %ESP.


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@229
2002-05-08 00:32:50 +00:00
Julian Seward
37f7143de6 Minor profiling improvements. Add a couple of cost centers.
git-svn-id: svn://svn.valgrind.org/valgrind/trunk@223
2002-05-07 09:25:30 +00:00
Julian Seward
3a27858aea Change the way Valgrind exits.
Until now, valgrind waited for ld.so to call the .fini code in
valgrind.so, and took this as its cue to switch back to the real CPU
for the rest of the journey.

This is a problem if ld.so subsequently calls other .so's .fini code
and threading is in use, because they do pthread_* calls which cannot
be handled by valgrind's libpthread.so without valgrind actually being
active.

So we ignore the call to valgrind's .fini code, and run the program
all the way up to the point where it calls syscall exit() to
disappear.  This makes the order in which the .fini sections are run
irrelevant, since Valgrind has control during all of them, and so
threading facilities are still available for all of them.

This change means Mozilla 1.0RC1 now exits a lot more cleanly than it
did.


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@201
2002-05-03 19:09:05 +00:00
Julian Seward
78998c4d1a Ensure that values returned to the client from pthread operations are
marked as defined, so as to avoid spurious uninit-value errors.


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@185
2002-05-01 03:24:23 +00:00
Julian Seward
6ea4c1c677 Increase default thread stack size to 64k and institute crude
overflow checks in scheduler_sanity().


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@183
2002-05-01 02:28:01 +00:00
Julian Seward
cd4b1c10a2 Reinstate use of VG_(do_sanity_checks), although at a lower frequency
than before.  Turns out they were wasting 25-50% of total execution
time in valgrinds of the 200203XX vintage.  Apologies, KDE hackers!


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@182
2002-05-01 01:58:35 +00:00
Nicholas Nethercote
fcc45a9e85 New files:
- vg_cachesim.c
  - vg_cachesim_{I1,D1,L2}.c
  - vg_annotate.in
  - vg_cachegen.in

Changes to existing files:

  - valgrind/valgrind.in, added option:

        --cachesim=no|yes       [no]

  - Makefile/Makefile.am:
        * added vg_cachesim.c to valgrind_so_SOURCES var
        * added vg_cachesim_I1.c, vg_cachesim_D1.c, vg_cachesim_L2.c to
          noinst_HEADERS var
        * added vg_annotate, vg_cachegen to 'bin_SCRIPTS' var, and added empty
          targets for them

  - vg_main.c:
        * added two offsets for cache sim functions (put in positions 17a,17b)
        * added option handling (detection of --cachesim=yes which turns off of
          --instrument);
        * added calls to cachesim initialisation/finalisation functions

  - vg_mylibc: added some system call wrappers (for chmod, open_write, etc) for
    file writing

  - vg_symtab2.c:
        * allow it to read symbols if either of --instrument or --cachesim is
          used
        * made vg_symtab2.c:vg_what_{line,fn}_is_this extern, renaming it as
          VG_(what_line_is_this) (and added to vg_include.h)
        * completely rewrote the read loop in vg_read_lib_symbols, fixing
          several bugs.  Much better now, although probably not perfect.  It's
          also relatively fragile -- I'm using the "die immediately if anything
          unexpected happens" approach.

  - vg_to_ucode.c:
        * in VG_(disBB), patching in x86 instruction size into extra4b field of
          JMP instructions at the end of basic blocks if --cachesim=yes.
          Shifted things around to do this;  also had to fiddle around with
          single-step stuff to get this to work, by not sticking extra JMPs on
          the end of the single-instruction block if there was already one
          there (to avoid breaking an assertion in vg_cachesim.c).  Did a
          similar thing to avoid an extra JMP on huge basic blocks that are
          split.

  - vg_translate.c:
        * if --cachesim=yes call the cachesim instrumentation phase
        * made some functions extern and renamed:
                allocCodeBlock() --> VG_(allocCodeBlock)()
                freeCodeBlock()  --> VG_(freeCodeBlock)()
                copyUInstr()     --> VG_(copyUInstr)()
          (added to vg_include.h too)

  - vg_include.c: declared
        * cachesim offsets
        * exports of vg_cachesim.c
        * added four new profiling events (increasing VGP_M_CCS to 24 -- I kept
          the spare ones)
        * added comment about UInstr.extra4b field being used for instr size in
          JMPs for cache simulation

  - docs/manual.html:
        * Added --cachesim option to section 2.5.
        * Added cache profiling stuff as section 7.


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@168
2002-04-29 16:03:24 +00:00
Julian Seward
f36ab7016f adjust error count thresholds
git-svn-id: svn://svn.valgrind.org/valgrind/trunk@140
2002-04-24 21:24:18 +00:00
Julian Seward
1a257661de VG_(maybe_add_context): also stop collecting errors when the total
number (in contrast to the total number of _different_) of them
gets too high.


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@139
2002-04-24 21:03:47 +00:00
Julian Seward
9bb983694b - Fast-track pthread_mutex_trylock(), even though programs which use
it extensively are probably badly designed -- they are polling.

- VG_(deliver_signals): return a Bool indicating if any signals
  really were delivered.  Used only to try and reduce excessive
  frequency of system sanity checks.


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@135
2002-04-24 19:51:31 +00:00
Julian Seward
b3a47aa615 Allow more slack with VG_STARTUP_STACK_MASK. Also increase some
table sizes, for Galeon.


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@131
2002-04-24 14:44:23 +00:00
Julian Seward
e009a193da minor tweaks to constants
git-svn-id: svn://svn.valgrind.org/valgrind/trunk@122
2002-04-24 02:19:36 +00:00
Julian Seward
5b220c8d4c Fix total b0rkage of signal handling caused by stupidly giving the
same value to VG_USERREQ__READ_MILLISECOND_TIMER and
VG_USERREQ__SIGNAL_RETURNS.  Duh.


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@120
2002-04-24 01:17:42 +00:00
Julian Seward
418902218c Various upgrades, with the effect that mozilla now runs, although
it has tremendous performance problems.

* Implement pthread_key_{create,delete} and pthread_{set,get}specific.

* Implement pthread_cond_timedwait.  A nuisance.

* New timer infrastructure, based on the RDTSC instruction.  This
  allows fast, accurate time measurement without swamping the host with
  gettimeofday() syscalls.

There's something definitely screwy about the scheduler, making opera
run slowly and mozilla run unbelievably slowly.  To be investigated.


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@119
2002-04-23 16:52:51 +00:00
Julian Seward
1eea9acdea GDB-attach cleanups. Have our own system() so we don't have to use
glibc's, and tell the user if starting GDB failed for some reason.


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@115
2002-04-21 22:03:07 +00:00
Julian Seward
6fb071300e Make the GDB-attach stuff thread-aware, and work (at least partially)
when running multithreaded.  Can still cause crashes (assertion failures)
when GDB exits.  I think it that's due to my use of libc's system()
call; should roll my own.


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@111
2002-04-21 13:05:34 +00:00
Julian Seward
51ab497158 Add pthread_mutex_trylock, and add various other hacks to try and make
Mozilla work.


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@107
2002-04-21 00:13:57 +00:00
Julian Seward
e39f3f644a Add fairly complete, and apparently working, support for condition
variables.


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@102
2002-04-20 13:53:23 +00:00
Julian Seward
7b0247aace VG_(record_free_error) / VG_(record_freemismatch_error) are called
by the scheduler, not by generated code.  So pass in the relevant
ThreadState*; don't get it from VG_(get_current_tid)().


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@101
2002-04-19 15:43:37 +00:00
Julian Seward
1f17043004 Continue trying to extract myself from the pthread_mutex_* swamp.
Fall back to a compromise position, which makes my mutex implementation
initialiser- and structure-compatible with LinuxThreads, and ditto the
upcoming condition var implementation.  In particular this means that
((ThreadId)0) is an invalid thread ID, so vg_threads[0] is never used,
and vg_threads[1] specially denotes the "main" thread.

Remove the scheme of having a linked list of threads waiting on
each mutex.  It is too difficult to get the right semantics for
when a signal is delivered to a thread blocked in pthread_mutex_lock().
Instead, use the old scheme of each thread stating with its .waited_on_mx
field, which mutex it is waiting for.  This makes pthread_mutex_unlock()
less efficient, but at least it all works.


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@100
2002-04-19 14:40:57 +00:00
Julian Seward
3d7ec5ac90 Simply and rationalise pthread_mutex implementation, in preparation
for implementation of condition variables.

* Use the native pthread_mutex_t directly; we no longer have our own
  VgMutex type nor a fixed array of them.

* Give ThreadState a new field q_next :: ThreadId, used to make a
  linked list of threads waiting on a mutex, or condition variable.


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@99
2002-04-18 22:38:41 +00:00
Julian Seward
f6f515f0b8 Yay! Opera (6.0TP2) now works.
Various enhancements:

* Make the error message system more thread-aware.

* Fix stupid bug in do_pthread_create causing incorrect initial
  %ESP values sometimes.

* Fix various other minor things needed to make opera work.

Performance of threaded apps is pretty terrible.  This needs
looking into.


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@98
2002-04-18 11:37:52 +00:00
Julian Seward
fda47ff910 Show backtraces for all threads in vg_assert, VG_(panic) and
VG_(unimplemented).  In future this will not be enabled by default due
to the danger of recursion of assertion failures.


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@92
2002-04-17 19:35:12 +00:00
Julian Seward
fe8ade38b8 Change --trace-pthread= flag to accept none|some|all, for finer level
of pthread event tracing.  And allow this info to be passed across to
the client, where vg_libpthread.c uses it to also control verbosity.


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@91
2002-04-16 22:50:32 +00:00
Julian Seward
93b2c2ed95 Get rid of the muraroa.demon.co.uk references since that account is
soon to disappear.


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@83
2002-04-16 02:51:05 +00:00
Julian Seward
43ca0bb6f4 Get rid of the --client-perms= flag. Valgrind now depends critically
on the client-request subsystem, and disabling it is no longer a
sensible thing to do.

Also: in the manual, mention flags --trace-sched= and --trace-pthread=.


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@79
2002-04-16 01:55:18 +00:00
Julian Seward
0f38b1975c Get rid of the old bt/bts/btr/btc implementation.
Turns out these insns are also available as Grp8 extensions, with
literal bit-offset values.  Nuisance.  I've #if 0'd out the old code
which implements them since am too lazy to fix them properly, and I
can't find any cases of their use anyway.  I'll wait until someone
yelps.


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@75
2002-04-15 18:36:39 +00:00
Julian Seward
8138f264e0 Plumb the right %EIP and %EBP values through to VG_(get_ExeContext)
now that we have the additional complication of multiple threads.


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@64
2002-04-14 04:16:48 +00:00
Julian Seward
d8e7eaed15 Take notice of SA_RESTART flags on signals, so as to deal (at least
partially properly) with blocking system calls interrupted by signals.


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@62
2002-04-14 02:29:29 +00:00
Julian Seward
ac45cc3e38 Write return address for threads in assembly so we can reliably
grab their return values.


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@58
2002-04-13 00:08:51 +00:00
Julian Seward
4248ca0b0a Cleanup of the dispatch mechanism. Now syscall returns and the final
request to shutdown valgrind are done with the client request
mechanism too.  This is much better than having to check all
call/return addresses.


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@57
2002-04-12 23:24:59 +00:00
Julian Seward
c59b539faf Clean up debug printing for scheduler / pthreads. Two new flags,
--trace-sched=no|yes and --trace-pthread=no|yes, if you really want
to see tons of gory details.


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@55
2002-04-12 20:12:20 +00:00
Julian Seward
7a36f60133 Mega-merge of my last 2 weeks hacking. This basically does the groundwork
for pthread_* support.  Major changes:

* Valgrind now contains a (skeletal!) user-space pthreads
  implementation.  The exciting bits are in new file vg_scheduler.c.
  This contains thread management and scheduling, including nasty crud
  to do with making some syscalls (read,write,nanosleep) nonblocking.
  Also implementation of pthread_ functions: create join
  mutex_{create,destroy,lock,unlock} and cancel.

* As a side effect of the above, major improvements to signal handling
  and to the client-request machinery.  This is now used to intercept
  malloc/free etc too; the hacky way this is done before is gone.
  Another side effect is that vg_dispatch.S is greatly simplified.
  Also, the horrible hacks to do with delivering signals to threads
  blocked in syscalls are gone, since the new mechanisms cover this case
  easily.


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@52
2002-04-12 11:12:52 +00:00
Julian Seward
2ec0ebd9dc Add experimental omission of V-bits for address values, using
--check-addrVs=no.  The default behaviour, =yes, is the original
behaviour.  So far this is undocumented.


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@32
2002-03-25 00:07:36 +00:00
Julian Seward
5b1ca0492b Detect FPU instructions which set %EFLAGS and mark the resulting
UInstrs accordingly.  Fixes a bug in the simulated CPU in which the
results of f{u}comi{p} FPU insns were ignored, potentially leading to
wrong program behaviour.  This will only have happened to people using
P6/P7/K7 class CPUs.


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@30
2002-03-24 13:52:19 +00:00