Skip to content

Commit

Permalink
Wrong unmarshaling of function pointers in debugger mode (#10709)
Browse files Browse the repository at this point in the history
In debugger mode, closures sent by the debuggee have their code pointer
modified so that it points to the `function_placeholder` code in
debugger/main.ml.

This modification was performed incorrectly: the whole closure for
`function_placeholder` was used as the code pointer for the
unmarshalled closure.

This commit implements the correct operation: the code pointer from
`function_placeholder` is used as code pointer for the unmarshaled
closure.

Also: raise a more informative exception when custom printer invokes
closure from debuggee.

Fixes: #9214
  • Loading branch information
xavierleroy committed Oct 19, 2021
1 parent f442361 commit cc9ae80
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
7 changes: 7 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,11 @@ Working version

### Bug fixes:

- #9214, #10709: Wrong unmarshaling of function pointers in debugger mode.
This was causing ocamldebug to crash when running some user-defined printers.
(Xavier Leroy, report by Rehan Malak, review by Gabriel Scherer and
Vincent Laviron)

- #10473: Add CFI directives to RISC-V runtime and asmcomp.
This allows stacktraces to work in gdb through C and OCaml calls.
(Edwin Török, review by Nicolás Ojeda Bär and Xavier Leroy)
Expand Down Expand Up @@ -298,6 +303,8 @@ Working version
implementation of stat
(Antonin Décimo, review by David Allsopp)



OCaml 4.13 maintenance branch
-----------------------------

Expand Down
2 changes: 1 addition & 1 deletion debugger/main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ let speclist = [
]

let function_placeholder () =
raise Not_found
failwith "custom printer tried to invoke a function from the debuggee"

let report report_error error =
eprintf "Debugger [version %s] environment error:@ @[@;%a@]@.;"
Expand Down
3 changes: 2 additions & 1 deletion runtime/intern.c
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,8 @@ static void intern_rec(value *dest)
const value * function_placeholder =
caml_named_value ("Debugger.function_placeholder");
if (function_placeholder != NULL) {
v = *function_placeholder;
/* Use the code pointer from the "placeholder" function */
v = (value) Code_val(*function_placeholder);
} else {
intern_cleanup();
intern_bad_code_pointer(digest);
Expand Down

0 comments on commit cc9ae80

Please sign in to comment.