2294 Commits

Author SHA1 Message Date
Paul Floyd
a7d86da0f6 regtest: fix warning in memalign_args and add debug info to sized_aligned_new_delete_args 2023-03-08 08:59:38 +01:00
Paul Floyd
18ca012c08 Fix compile failure on Linux
Use SizeT rather than size_t
Also make tests quieter with -q
2023-03-07 23:19:04 +01:00
Paul Floyd
114c528dab Add 32bit version of sized_aligned_new_delete_args expected
Asl add some parens to shut up clangd
2023-03-07 22:58:57 +01:00
Paul Floyd
ceee3e8922 Add checks to all new / delete overload arguments 2023-03-07 22:47:19 +01:00
Paul Floyd
b2ca91d669 Darwin regtest: again, forgot to delete errno
Setting errno on Darwin not supported on Valgrind.
2023-03-05 17:22:59 +01:00
Paul Floyd
0fecf3914d Darwin regtest: remove test that aligned_alloc fails with huge alignment
Needs more debugging.
2023-03-05 17:20:23 +01:00
Paul Floyd
b07d068887 Linux musl: one more iteration for aligned_alloc, assert in wrong place 2023-03-05 16:49:12 +01:00
Paul Floyd
e99cd3c6a3 Linux musl: corrections for aligned_alloc test 2023-03-05 16:43:25 +01:00
Paul Floyd
afb5867858 Solaris regtest: final iteration for aligned_alloc 2023-03-05 16:24:44 +01:00
Paul Floyd
fd20bb9c67 Make aligned_alloc behave more like the underlying platform aligned_alloc
This is the third part of
Bug 466104 aligned_alloc problems, part 1

Shouldn't affect Linux glibc.
2023-03-05 15:25:51 +01:00
Paul Floyd
25ebadbdd7 Linux PPC regtest: forgot to add the new expected 2023-03-01 08:20:46 +01:00
Paul Floyd
663bb2ed65 Linux PPC regtest: add a specific expected for memalign_args
The number of errors for arguments that gets triggered depends
on how GCC optimzes and generates code for the vg_replace_malloc.c
wrappers. PPC seems to trigger more than amd64.
2023-03-01 08:18:09 +01:00
Paul Floyd
3d8c35bbfd Darwin regtest: no malloc.h header on Darwin 2023-03-01 07:42:43 +01:00
Paul Floyd
33ce1bf1cb Change behaviour of posix_memalign for Solaris
It returns NULL and 0 status whilst most other platforms
allocatae some undefined amount of memory (which is allowed
by posix).

Update the posix_memalign test as well.

Finally remove some clang warnings about alignment.
2023-02-28 21:21:05 +01:00
Paul Floyd
e862c6f3d2 Make memalign behave more like the underlying platform memalign
This is the first part of
Bug 466104 aligned_alloc problems, part 1

The bulk of this change is try try to get memalign to be more
platform aware. Previously the Valgrind implementation only
reflected the glibc implementation. That meant non-power of
two alignment values would silently get bumped up to the
next largest power of two. Most other platforms return NULL
and set errno to EINVAL.

There are a few other changes. A couple of the other aligned alloc
functions like valloc were caling the Valgrind memalign. This meant
that there weould be an extra Valgrind memalign in any error
callstacks. Now these functions call the allocator directly.

The memcheck memalign2 testcase has been redone. The memalign
parts moved out to per-platform versions and the tescase
itdelf renamed to posix_memalign, since that is all that is left.
I also modified the testcase so that it checks that the
memalign calls check for non-NULL returns, and on platforms
that set errno that it is correctly set. Previously the
test only worked on non-glibc because NULL & alignment is
zero.  The platform versions have been tested on glibc,
MUSL, FreeBSD and OpenIndiana and should hopefully run OK
both under memcheck and standalone.

There is stil quite a lot that is NOT done

1. I'm not certain that implementations allocate more memory
   and/or use a wider alignment. It doesn't help that almost
   universally the memalign implementations are badly
   documented, undocumented or buggy.
2. We don't handle very large alignment requests well.
   Most implementations will fail and set EINVAL if the
   alignment is over half the memory space. Valgrind will
   core panic if an aligmnt of over 16Mbytes is requested.
3. We don't generate any memcheck errors for invalid values
   of alignment. That's planned in Part 2.
4. The code is static and fixed at compile time. That means that
   if you are using MUSL with a glibc-built Valgrind you
   will still get glibc memalign behaviour.
   I'll wait to see if there are any requests before trying
   to make the behaviour selectable at runtime.
2023-02-28 13:46:08 +01:00
Paul Floyd
5cf51ca2f6 And here is the updated expected for FreeBSD scalar x86 mknodat 2023-02-25 16:12:14 +01:00
Paul Floyd
615336329b Small update to FreeBSD x86 scalar expected 2023-02-25 16:08:40 +01:00
Paul Floyd
7136cd9876 musl regtest : fix warnings and badly initialized struct msghdr 2023-02-21 23:05:22 +01:00
Paul Floyd
a6101db692 Try to correct configure script for warning flags with values
Some -W flags come with and without an =
(usually for warning levels)
But some only have the form -Wfoo=42 and -Wno-foo
2023-02-21 22:05:13 +01:00
Paul Floyd
fe008c8739 regtest: remove compiler warnings with clang 2023-02-19 10:10:59 +01:00
Paul Floyd
9fb974c359 Regtest: rationalize filters for new/delete 2023-02-05 12:50:13 +01:00
Paul Floyd
0eb7257254 Darwin regtest: add filtering for zone functions and realloc
For test of C++17 new/delete variations
2023-02-05 11:35:28 +01:00
Paul Floyd
a4e5942b32 Remove warning caused by D demangle testcase 2023-01-30 21:13:13 +01:00
Mark Wielaard
42d35e6d2a bug464969_d_demangle.cpp: Always print "Xa"
bug464969_d_demangle depends on producing an error about an
uninitialized variable. But it prints something different
to stdout based on the value of that variable. Which can
produce failures. Make sure to always print the same thing
to stdout.
2023-01-30 10:27:35 +01:00
Paul Floyd
82282a6676 Bug 464969 - D language demangling
Patch from witold.baryluk@gmail.com

(also added a testcase)
2023-01-29 22:07:52 +01:00
Paul Floyd
f7e4bb4af2 Bug 382034 - Testcases build fixes for musl 2023-01-27 08:42:06 +01:00
Paul Floyd
0df691f9d9 Linux regtest: forgot prereq test for scalar_openat2 2023-01-27 07:40:31 +01:00
Paul Floyd
c15993dcb4 FreeBSD: start adding more checks for /proc
Also add a couple of expecteds.
2023-01-22 21:48:51 +01:00
Paul Floyd
5d38764204 Bug 464476 - Firefox fails to start under Valgrind
On FreeBSD, Firefox uses the kern.proc.pathname.PID sysctl
to get the binary path (where PID can be the actual pid
or -1). The user path is /usr/local/bin/firefox which is
a symlink to /usr/local/lib/firefox/firefox.

This was failing because we were not handling this MIB.
That meant that the sysctl returned the path for the
binary of the running tool (e.g.,
/home/paulf/scratch/valgrind/memcheck/memcheck-amd64-freebsd).
Firefox looks for files in the same directory.
Since it was the wrong directory it failed to find them and
exited.

I also noticed a lot of _umtx_op errors. On analysis they
are spurious. The wake ops take an "obj" argument, a pointer
to a variable. They only use the address as a key for
lookups and don't read the contents.
2023-01-21 17:55:09 +01:00
Paul Floyd
36b9fea113 Linux regtest: openat2 not available on older systems
The x86-linux/scalar testcase fas failing to compile.
So split out openat2 into a separate test with a condfigure test.
2023-01-10 21:00:22 +01:00
Paul Floyd
99dfad28a5 Cleanup warnings
Now no warnings on Fedora 36
For a short while
2023-01-09 23:57:01 +01:00
Paul Floyd
1cea0e151b Cleanup of warnings, mostly -Wno-unused-but-set-variable 2023-01-08 17:51:37 +01:00
Philippe Waroquiers
39a063513c Implement front end GDB commands for Valgrind gdbserver monitor commands.
This commit implements in python a set of GDB commands corresponding to the
Valgrind gdbserver monitor commands.

Basically, the idea is that one GDB command is defined for each valgrind
gdbserver subcommand and will generate and send a monitor command to valgrind.

The python code is auto-loaded by GDB as soon as GDB observes that the valgrind
preload core shared lib is loaded (e.g. vgpreload_core-amd64-linux.so).
This automatic loading is done thanks to the .debug_gdb_scripts section
added in vg_preloaded.c file.

Sadly, the auto-load only happens once valgrind has started to execute the code
of ld that loads this vg_preload file.

I have tried 2 approaches to have the python code auto-loaded when attaching at
startup to valgrind:
  * have valgrind gdbserver reporting first to GDB that the executable file is
    the tool executable (with a .debug_gdb_scripts section) and then reporting
    the real (guest) executable file.
    The drawback of this approach is that it triggers a warning/question in GDB
    according to the GDB setting 'set exec-file-mismatch'.
  * have valgrind gdbserver pretending to be multiprocess enabled, and report
    a fake process using the tool executable with a .debug_gdb_scripts section.
    The drawback of this is that this always creates a second inferior in GDB,
    which will be confusing.

Possibly, we might complete the below message :
  ==2984378== (action at startup) vgdb me ...
  ==2984378==
  ==2984378== TO DEBUG THIS PROCESS USING GDB: start GDB like this
  ==2984378==   /path/to/gdb /home/philippe/valgrind/littleprogs/some_mem
  ==2984378== and then give GDB the following command
  ==2984378==   target remote | /home/philippe/valgrind/git/improve/Inst/libexec/valgrind/../../bin/vgdb --pid=2984378
  ==2984378== --pid is optional if only one valgrind process is running

with:
  ==2984378== GDB valgrind python specific commands will be auto-loaded when execution begins.
  ==2984378== Alternatively, you might load it before with the GDB command:
  ==2984378==   source /abs/path/to/valgrind/install/libexec/valgrind/valgrind-monitor.py

The following GDB setting traces the monitor commands sent by a GDB valgrind
command to the valgrind gdbserver:
  set debug valgrind-execute-monitor on

How to use the new GDB valgrind commands?
-----------------------------------------

The usage of the GDB front end commands is compatible with the
monitor command as accepted today by Valgrind.

For example, the memcheck monitor command "xb' has the following usage:
 xb <addr> [<len>]

With some piece of code:
   'char some_mem [5];'
xb can be used the following way:
  (gdb) print &some_mem
  (gdb) $2 = (char (*)[5]) 0x1ffefffe8b
  (gdb) monitor xb 0x1ffefffe8b 5
  		    ff	  ff	  ff	  ff	  ff
  0x4A43040:	  0x00	0x00	0x00	0x00	0x00
  (gdb)

The same action can be done with the new GDB 'memcheck xb' command:
  (gdb) memcheck xb 0x1ffefffe8b 5
  		    ff	  ff	  ff	  ff	  ff
  0x1FFEFFFE8B:	  0x00	0x00	0x00	0x00	0x00
  (gdb)

At this point, you might ask yourself: "what is the interest ?".

Using GDB valgrind commands provides several advantages compared to
the valgrind gdbserver monitor commands.

Evaluation of arguments by GDB:
-------------------------------
For relevant arguments, the GDB command will evaluate its arguments using
the usual GDB evaluation logic, for example, instead of printing/copying
the address and size of 'some_mem', the following will work:
  (gdb) memcheck xb &some_mem sizeof(some_mem)
  		    ff	  ff	  ff	  ff	  ff
  0x1FFEFFFE8B:	  0x00	0x00	0x00	0x00	0x00
  (gdb)

or:
  (gdb) p some_mem
  $4 = "\000\000\000\000"
  (gdb) memcheck xb &$4
  		    ff	  ff	  ff	  ff	  ff
  0x1FFEFFFE8B:	  0x00	0x00	0x00	0x00	0x00
  (gdb)

This is both easier to use interactively and easier to use in GDB scripts,
as you can directly use variable names in the GDB valgrind commands.

Command completion by GDB:
--------------------------
The usual command completion in GDB will work for the GDB valgrind commands.
For example, typing TAB after the letter 'l' in:
  (gdb) valgrind v.info l
will show the 2 "valgrind v.info" subcommands:
  last_error  location
  (gdb) valgrind v.info l

Note that as usual, GDB will recognise a command as soon as it is unambiguous.

Usual help and apropos support by GDB:
--------------------------------------
The Valgrind gdbserver provides an online help using:
  (gdb) monitor help
However, this gives the help for all monitor commands, and is not searchable.
GDB provides a better help and documentation search.
For example, the following commands can be used to get various help
or search the GDB Valgrind command online documentation:
   help valgrind
   help memcheck
   help helgrind
   help callgrind
   help massif
to get help about the general valgrind commands or the tool specific commands.

Examples of searching the online documentation:
  apropos valgrind.*location
  apropos -v validity
  apropos -v leak

User can define aliases for the valgrind commands:
--------------------------------------------------
The following aliases are predefined:
  v and vg for valgrind
  mc for memcheck
  hg for helgrind
  cg for callgrind
  ms for massif

So, the following will be equivalent:
   (gdb) valgrind v.info location &some_mem
   (gdb) v v.i lo &some_mem
   (gdb) alias Vl = valgrind v.info location
   (gdb) Vl &some_mem

Thanks to Hassan El Karouni for the help in factorising the python
code common to all valgrind python commands using a decorator.
2023-01-08 16:00:57 +01:00
Philippe Waroquiers
3a046ec1c1 Avoid doing mempool specific leak search activities if there are no mempools
For most memcheck users, no mempools are used, but the leak search logic
was doing in any case special handling, leading to useless work such as
sorting again an already sorted array and making a copy of an array without
modifying it.

This slightly optimises the perf reg tests of memcheck.
perl perf/vg_perf --tools=memcheck --vg=. --vg=../trunk_untouched perf
-- Running  tests in perf ----------------------------------------------
-- bigcode1 --
bigcode1 .         :0.08s  me: 3.0s (38.1x, -----)
bigcode1 trunk_untouched:0.08s  me: 3.1s (38.6x, -1.3%)
-- bigcode2 --
bigcode2 .         :0.07s  me: 7.4s (105.9x, -----)
bigcode2 trunk_untouched:0.07s  me: 7.5s (107.4x, -1.5%)
-- bz2 --
bz2      .         :0.40s  me: 5.2s (12.9x, -----)
bz2      trunk_untouched:0.40s  me: 5.4s (13.6x, -5.0%)
-- fbench --
fbench   .         :0.15s  me: 2.8s (18.8x, -----)
fbench   trunk_untouched:0.15s  me: 2.9s (19.0x, -1.1%)
-- ffbench --
ffbench  .         :0.16s  me: 2.7s (16.8x, -----)
ffbench  trunk_untouched:0.16s  me: 2.7s (17.1x, -1.9%)
-- heap --
heap     .         :0.06s  me: 4.0s (66.5x, -----)
heap     trunk_untouched:0.06s  me: 4.1s (68.7x, -3.3%)
-- heap_pdb4 --
heap_pdb4 .         :0.07s  me: 6.2s (89.1x, -----)
heap_pdb4 trunk_untouched:0.07s  me: 6.6s (94.9x, -6.4%)
-- many-loss-records --
many-loss-records .         :0.01s  me: 1.2s (122.0x, -----)
many-loss-records trunk_untouched:0.01s  me: 1.2s (125.0x, -2.5%)
-- many-xpts --
many-xpts .         :0.03s  me: 1.2s (41.7x, -----)
many-xpts trunk_untouched:0.03s  me: 1.3s (43.7x, -4.8%)
-- memrw --
memrw    .         :0.06s  me: 1.2s (19.8x, -----)
memrw    trunk_untouched:0.06s  me: 1.2s (20.2x, -1.7%)
-- sarp --
sarp     .         :0.02s  me: 1.8s (91.5x, -----)
sarp     trunk_untouched:0.02s  me: 2.1s (103.5x,-13.1%)
-- tinycc --
tinycc   .         :0.11s  me: 7.1s (64.4x, -----)
tinycc   trunk_untouched:0.11s  me: 7.1s (64.3x,  0.1%)
-- Finished tests in perf ----------------------------------------------

== 12 programs, 24 timings =================
2023-01-08 11:50:07 +01:00
Paul Floyd
2c93baf53a Bug 433873 - openat2 syscall unimplemented on Linux
This syscall is not exposed via glibc, so there is only an
addition to the scalar test.
2023-01-06 21:27:01 +01:00
Julian Seward
d99a6f70e2 Memcheck: handle origin data for 8-/16-bit shadow stores a bit more accurately.
With origin tracking enabled, 8- and 16-bit stores could sometimes lose origin
info unnecessarily.  This patch removes this avoidable lossage.  (Since MC
only stores 1 origin value for each 32-bit word of address space, there is
still unavoidable lossage of origins in some cases; this patch does not help
in those cases since it's a fundamental design limitation.)
2023-01-04 16:32:03 +01:00
Philippe Waroquiers
f6fcc74a68 Allows to only output "new" loss records when doing a leak search.
In the memcheck monitor 'leak_search', add a "new" keyword corresponding
to the delta leak search mode LCD_New.

Add a new client request VALGRIND_DO_NEW_LEAK_CHECK.

When doing a delta leak search, new loss records are marked with "new"
(whatever the delta leak search mode).

Note that trailing white spaces were removed in mc_main.c.
A much small diff can be looked at by using the -w diff option.
2022-12-30 20:56:47 +01:00
Paul Floyd
9acdd79b69 Disable some memcheck tests on FreeBSD
Fail due to differences in DWARF varinfo generated by clang
compared to GCC. No fix in perspective.
2022-12-26 11:06:32 +01:00
Paul Floyd
29cfa77b23 FreeBSD: enable PERF_FAST_LOADV for x86 and cleanup for clangd
clangd doesn't like asm, prefers __asm__
some hicpp-braces-around-statements fixes
2022-12-25 09:25:01 +01:00
Bart Van Assche
1845f51728 Revert "syscall"
Revert an incomplete commit that got published accidentally.
2022-12-24 16:49:56 -08:00
Bart Van Assche
2bd7f70421 syscall 2022-12-24 08:18:01 -08:00
Paul Floyd
5b52408406 Bug 462830 - WARNING: unhandled amd64-freebsd syscall: 474
Add syscall wrappers for sctp_generic_recvmsg and sctp_generic_sendmsg
on FreeBSD.
2022-12-22 23:08:45 +01:00
Paul Floyd
ac6d9faf4b Bug 351857 - confusing error message about valid command line option
Added code to handle missing "=something".
2022-11-12 21:02:07 +01:00
Paul Floyd
2dde5c405b Bug 131186 - writev reports error in (vector[...])
Use the index rather than ...
Also done for readv.
2022-10-12 08:34:51 +02:00
Paul Floyd
5ee9e7687e Update valinfo5 FreeBSD expected
Slightly less diffs wrt the main one now with llvm 13 and FreeBSD 13.1
2022-09-18 21:20:12 +02:00
Mark Wielaard
74e180e3c4 Add memmem memcheck tests
Ensure that memmem behaves as expected and doesn't yield memcheck false
positives.
2022-07-07 14:24:39 +02:00
Paul Floyd
9f27d8fbc7 Bug-456171 [PATCH] FreeBSD: Don't record address errors when accessing the 'kern.ps_strings' sysctl struct
There is quite a lot of stuff here.

The problem is that setproctitle and kern.ps_strings were using the Valgrind host auxv
rather than the guest. The proposed patch would have just ignored those memory ranges.

I've gone a fair bit further than that
1. refactored the initimg code for building the client auxv. Previously we were
   simply ignoring any non-scalar entries. Now we copy most of thse as well.
   That means that 'strtab' built on the client stack no longet only contains
   strings, at can also now contain binary structures. Note I was a bit
   concerned that there may be some alignment issues, but I haven't seen any
   problems so far.
2. Added intercepts to sysctl and sysctlbyname for kern.ps_strings, then find
   AT_PS_STRINGS from the client auxv that is now usable from step 1.
3. Some refactoring of sysctl and sysctlbyname syscall wrappers. More to do
   there!
4. Added a setproctitle testcase (that also tests the sysctls).
5. Updated the auxv testcase now that more AT_* entries are handled.
2022-07-03 13:05:54 +02:00
Mark Wielaard
022dfeee73 Fix memcheck/tests/amd64-freebsd/Makefile.am EXTRA_DIST reallocf
EXTRA_DIST included reallocf.stderr.out, should have been
reallocf.stderr.exp.
2022-06-18 15:30:59 +02:00
Paul Floyd
3f5fcd59da Fix a few issues with reallocf and add a FreeBSD amd64 regtest
1. new_size is size_t (unsigned) and can't be negative
2. NULL not returned when the size is 0 and the memory freed
3. set ENOMEM if the allocation fails (but this time NULL does
   get returned)
2022-06-17 13:52:45 +02:00
Paul Floyd
7844752299 Bug 452802 Handle lld 9+ split RW PT_LOAD segments correctly
Many changes mostly related to modifying VG_(di_notify_mmap)( Addr a, Bool allow_SkFileV, Int use_fd )
so that instead of triggering debuginfo reading after seeing one RX PT_LOAD and 1 RW PT_LOAD it
can handle either 1 or 2 RW PT_LOADs.
2022-06-09 22:03:04 +02:00