tags:

views:

61

answers:

1

Two related questions

  1. After I run a program how can I see what machine code got executed?
  2. Moreover does perl execution convert the whole pl and its modules to machine code or just the part it executes?
+10  A: 

Perl is an interpreted language. A more detailed look at how Perl works shows that perl has some features of compilers, some of interpreters. For more info see the introduction to perlrun and the compiler section of perlguts.

Perl is compiled into a set of opcodes that are executed by a virtual machine that is part of the perl binary. You can see these opcodes by using a tool like B::Concise.

If you want to see actual processor specific instructions, you are going to have to do some serious black magic. You could run perl on a special virtual machine that is configured to record all instructions executed by a given executable.

Another possible approach is to use B::C to create a compiled C version of your Perl script. You can then examine the native compiled code.

daotoad
[strace](http://en.wikipedia.org/wiki/strace) / [DTrace](http://en.wikipedia.org/wiki/dtrace) are helpful, too. They work on the system call level.
daxim
Faster (http://search.cpan.org/perldoc?Faster) might be interesting to look at as well (since it on the fly converts a Perl program into an XS one, it is probably possible to hack it to show how it is doing it)
Eric Strom