On 06/02/2021 07:59, Muhui Jiang wrote:

I am new to Valgrind and have some questions about the principles of Valgrind.

According to the manual, https://valgrind.org/docs/manual/manual-core.html#manual-core.whatdoes <https://valgrind.org/docs/manual/manual-core.html#manual-core.whatdoes>
"Your program is then run on a synthetic CPU provided by the Valgrind core."
"Valgrind simulates every single instruction your program executes"

I am curious that as a binary instrumentation framework, why Valgrind needs to simulate the CPU and instruction execution. It seems that the host and guest architecture must be the same due to the multiple syscalls.  If so, why not use the host CPU to run the translated binary directly instead of simulation? Simulated instruction execution might be different from the execution on physical devices.

It does run on the native CPU because valfrind is a JIT that converts
the original instructions to an internal form which it analyses and
instruments and then converts the instrumented code back into native
code which is then run on the real processor.

But from the point of view of the program it is running on valgrind's
emulated CPU and can only use those instructions and features which
valgrind knows how to emulate.

The other question is that what part is simulated for a CPU except for the instruction execution. Are the memory model, cache, and registers all simulated/emulated. Any suggestions and comments are welcome. Many Thanks

The cache is simulated in parallel for cachegrind/callgrind in order
to generate estimated statistics for cache hit/misses.

Tom

--
Tom Hughes (t...@compton.nu)
http://compton.nu/


_______________________________________________
Valgrind-users mailing list
Valgrind-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/valgrind-users

Reply via email to