Skip to content

Report a clear error when program is a native executable or other non-bytecode file - #95

Open
tmcgilchrist wants to merge 4 commits into
hackwaly:masterfrom
tmcgilchrist:bad_magic_error
Open

Report a clear error when program is a native executable or other non-bytecode file#95
tmcgilchrist wants to merge 4 commits into
hackwaly:masterfrom
tmcgilchrist:bad_magic_error

Conversation

@tmcgilchrist

Copy link
Copy Markdown
Collaborator

Gives issues like #33 a more user friendly error message.

On top of #93

Add four scenarios on top of the existing scopes/frames tests:

- test_stepping drives next/stepIn/stepOut and records where the
  debuggee lands, using stack depth as the stable signal so the test
  does not depend on exactly which line each step snaps to.
- test_values renders one local per shape of value (ints, floats, chars,
  strings, bools, unit, boxed ints, lists, arrays, tuples, options,
  records, variants, closures, lazies) and expands the structured ones a
  level. The fixture references every local so none is dropped as unused.
- test_heap stops inside a closure and reads the Heap scope, i.e. the
  variables captured from the enclosing scope. This exercises
  Value_scope.iter_compenv_heap, which is version-conditional in the same
  way the Globals scope was in hackwaly#74.
- test_events exercises Code_module.find_event/find_events directly,
  without a debuggee, and records how each source line maps to a debug
  event. It documents the current mapping, including the lines that are
  not breakpointable and the backward snap noted in KNOWN_ISSUES.md.

The dap_client helper gains stepping commands and value expansion that
fetches named and indexed children separately, with a filter, the way an
editor does. debugger.ml re-exports the symbol-table modules so the
event-mapping test can reach them.
The variables request handler asserted that a value had no indexed
children when the request omitted the filter field, and raised
Assert_failure for an array. The DAP spec says an omitted filter returns
both named and indexed children, so this is a valid request.
Loading a non-bytecode file now fails with a message that names the
file, says earlybird debugs bytecode not native executables, and tells
the user to build with ocamlc -g or a dune (modes byte) target and
point program at the .bc. A dedicated Not_ocaml_bytecode exception
with a registered printer keeps the message unwrapped when the adapter
surfaces it.
Comment on lines 60 to +77
if%lwt Lwt.return (magic <> Config.exec_magic_number) then
Lwt.fail_invalid_arg "Bad magic";%lwt
Lwt.fail
(Not_ocaml_bytecode
(Printf.sprintf
"%s is not an OCaml bytecode executable. earlybird debugs \
bytecode programs, not native executables. Compile with \
`ocamlc -g` or a dune `(modes byte)` target and set \"program\" \
to the resulting .bc file."
file));%lwt

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't this also trigger when it is an OCaml bytecode executable but built with a different version of the compiler?

@sim642 sim642 added the enhancement New feature or request label Jul 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants