# ocamlrun: make debugging executable magic number issues easier #1793

Closed

## Conversation

Projects
None yet
5 participants
Contributor

### shindere commented May 22, 2018

 First, this PR provides a more precise error message in the case where the magic number of an executable bytecode file differs from the one expected by the runtime. Instead of the "bad bytecode" message, bothe the expected and encountered magic nubmers are reported. Second, two command-line options are added to ocamlrun: -m: print the magic number of the executable given as argument and exit -M: print the magic number expected by this version of the runtime These changes turn out to be useful when debugging the compiler's bootstrap process. Finally, this PR relies on #1787 which should hence be merged first.

### xclerc reviewed May 22, 2018

 @@ -63,6 +63,11 @@ in the "OCAMLRUNPARAM" environment variable (see below). Search the directory \var{dir} for dynamically-loaded libraries, in addition to the standard search path (see section~\ref{s-ocamlrun-dllpath}). \item["-m"] Print the magic number of the byte-code executable given as argument

#### xclerc May 22, 2018

Contributor

This file seems to use "bytecode" rather than "byte-code".

### shindereforce-pushed the shindere:improve-exe-magic-number-handling branch from c2d3c17 to 7000f67May 22, 2018

Contributor Author

### shindere commented May 22, 2018

 Many thanks for your prompt feedback, @xclerc! I have just pushed an updated version of the branch, taking your comment into account.
Contributor

### xavierleroy commented May 23, 2018

 Now that #1787 is merged, it would help review if you'd rebase this GPR.

### shindereforce-pushed the shindere:improve-exe-magic-number-handling branch from 7000f67 to 062ce06May 23, 2018

Contributor Author

### shindere commented May 23, 2018

 Xavier Leroy (2018/05/23 08:54 -0700): Now that #1787 is merged, it would help review if you'd rebase this GPR. Sure, done.
Member

### gasche commented May 23, 2018

 Note: this is related to #463, but completely orthogonal as far as I can tell, as that PR wasn't touching the C code at all.

### shindere added some commits May 15, 2018

 runtime: improve error reporting when given an exe with a wrong magic… 
… number

The error message includes both the expected and the encountered
magic numbers.
 2458792 
 Add the -m and -M command-line options to ocamlrun 
- -m shows the magic number of the bytecode executable given as argument

- -M shows the magic number this runtime expects
 2e7ec17 

Member

### damiendoligez left a comment

 Approved modulo a small change to the printf line.

### shindere deleted the shindere:improve-exe-magic-number-handling branch May 25, 2018

Contributor Author

### shindere commented May 25, 2018

 Comment taken into account and PR merged. As a follow-up to this PR and the live exchange with @damiendoligez during the review, I also pushed 6f1c070 which improves the printing of the version number in the runtime.