Repository navigation
Support running native debuggers in ocamltest - #13199
Conversation
MisterDA
left a comment
There was a problem hiding this comment.
Minor comments.
- Is it necessary to introduce the
dev_nullvariable? I don't ever recall hearing about an Unix where it's not/dev/null(POSIX defines/dev/null). ThePath to /dev/nulldescription is redundant, maybePath to the null deviceis a better wording? and would also be portable to Windows where the null device is simply calledNUL. Note that we also haveFilename.nullin the standard library. - You could use
if ! command -v <the_command> &> /dev/null; thenin the scripts instead ofwhich. - You could add a new line at the end of all new files, some of them are missing them. It's generally a bit nicer to interact with them.
|
Thanks a lot for the prompt and nice review, @MisterDA!
Antonin Décimo (2024/05/27 03:40 -0700):
1. Is it necessary to introduce the `dev_null` variable? I don't ever
recall hearing about an Unix where it's not `/dev/null` (POSIX defines
`/dev/null`). The `Path to /dev/null` description is redundant, maybe
`Path to the null device` is a better wording? and would also be
portable to Windows where the null device is simply called `NUL`. Note
that we also have
[`Filename.null`](https://v2.ocaml.org/api/Filename.html#VALnull) in
the standard library.
It's because ocamltest's API does not make it easy, at the moment, to
redirect to files directly. To redirect to something, you have to
provide the name of a variable thtat ocntains the name of the file you
want to redirect to.
Also as you mention, the predefined content of the variable could be
OS-specific, that wouldn't be easy to achieve.
|
|
Moving to Draft status, I have discovered issues with CI permissions and repeatability of generated symbols, that need fixing before this is mergable. |
|
Okay thanks a lot for letting us know!
Will you please post here again to make sure we know the code is ready
to be reviewed?
|
8f9c188 to
b004ef2
Compare
|
This change introduces the ability to run GDB or LLDB (what I'm calling native debuggers) to ocamltest. The main changes are in the first four commits. 8f9c188 provides a hopefully compelling example of what can be done with native debugger support. The fixes in #13271 #13261 #13241 are all checked with this test and provide future scope for validating more debugging features work. @gasche @kayceesrk At the moment the test is implemented with tools we already use in the build scripts (sed and shell) with all the drawbacks of cross platform shell scripting. In future these tests could rely on LLDB/GDB python support to implement tests. |
| @@ -0,0 +1,15 @@ | |||
| break *(&caml_start_program+0) | |||
There was a problem hiding this comment.
Curious detail here with gdb when setting a breakpoint using just br caml_start_program GDB was setting the actual breakpoint at some offset from that symbol in the assembly. On AMD64 it was directly on that symbol but for ARM64 it is at caml_start_program+4 and for RISC-V it ends up at caml_start_program+40. So I have used an offset here. If you remove it then the GDB session on RISC-V is incorrect as we re-enter via caml_callback_asm and jump_to_caml label which incorrectly hits that breakpoint.
|
Many thanks for the work! At this stage I have three observations:
|
gasche
left a comment
There was a problem hiding this comment.
I just had a look, this looks okay to me, but I don't understand your intent regarding how to check that gdb or lldb are available. What I see is that you started with a boolean action lldb, but commented it out, for gdb there is a shell script to check availability (no action) and for lldb I don't see any availability-checking code. (The tests refer to a lldb_test.py file but I cannot find it in the PR itself, how does that work?)
| let make = try Sys.getenv "MAKE" with Not_found -> "make" in | ||
| let initial_environment = Environments.from_bindings | ||
| [ | ||
| Builtin_variables.dev_null, "/dev/null"; |
There was a problem hiding this comment.
On Windows my understanding is that /dev/null is not available but NUL works as a null sink. (You only use this variable in tests that are disabled on windows, but it is available more widely so maybe we should try to get it right.)
There was a problem hiding this comment.
Honestly, my focus is on improving native Unix debugger and I have no plans to work on debugging for Windows in the near future. Plus I don't have access to an environment to test Windows changes right or really know what I'm doing on Windows in general.
IF there is a simple change to get Windows support here I can apply it. Otherwise I would ask to leave Windows support as a future task.
b004ef2 to
f31cd9a
Compare
|
@shindere answers inline below.
It already does this, it will print out "Debugging program %s with %s" based on the program and debugger used.
I used the distinction of native vs bytecode based on the compiler backends.
41ab0f0 moves all the debugger related code into separate modules. Using |
|
Many thanks for the refactoring work, @tmcgilchrist. Studying the code, I think there is room for further simplification |
f31cd9a to
35ecbb0
Compare
Basic support for running LLDB and GDB against OCaml programs in the testsuite.
Co-authored-by: Sébastien Hinderer <seb@tarides.com>
Co-authored-by: Sébastien Hinderer <seb@tarides.com>
35ecbb0 to
82b4349
Compare
Using Python script API to validate setting break points and backtraces, which allows common behaviour across platforms. Also check lldb and gdb versions across platforms, older versions of XCode on AMD64 are problematic with OCaml name mangled symbols.
82b4349 to
4df4ad0
Compare
|
The new tests have been failing on amd64+ubuntu and arm64 on the Inria CI due to mismatched line numbers and mangling. |
|
It's not clear from your report how to fix the output sanitizer, (putting myself in the shoes of someone willing to fix this, theoretically) could you include examples of the output on these CI machines? |
|
I have a pending fix to tweak the .c line numbers as this is also hitting one of my PRs; however I can't fix the lldb oracles because the lldb tests also depend on a particular python module (embedded_interpreter) which I can't seem to find ATM. |
|
See #13477. |
|
There's a few more fixes required to the python / sed to make this more general on top of #13477. While I work on that please consider disabling the tests if they are causing problems. @Octachron if you could include linux distro, gdb and lldb version numbers along with the failing tests that would help. I've mainly tested my work on recent Ubnutu 22.04/24.04 distros |
|
@tmcgilchrist , this information is available on the inria CI at https://ci.inria.fr/ocaml (on which you have access rights as far as I can see). |
|
Thank you @Octachron I do have access and have found the right logs. |
|
Miod Vallat (2024/09/25 07:19 -0700):
however I can't fix the lldb oracles because
the lldb tests also depend on a particular python module
(embedded_interpreter) which I can't seem to find ATM.
In case you didn't find it meanwhile, on debian at least this seems to
be rpovided by each python3-lldb-{version} package, and there is also a
python3-lldb package that I expect pulls the right lldb-version-specific
package.
|
|
At some point we will need to make sure the GitHub runners do have gdb and Is that something you could easily help with, @MisterDA? |
|
@shindere I'll include installing gdb and lldb for Linux in my PR that I'm working on. |
This change introduces the ability to run native debuggers (LLDB and GDB) as part of the ocaml testsuite.
GBD and LLDB both provide Python APIs for interacting with the debugger. This makes it possible to write Python scripted tests, e.g. setting breakpoints, inspecting stack frames and looking up symbol information. In particular LLDB has a test suite for the Python API https://github.com/llvm/llvm-project/tree/main/lldb/test/API with many useful examples of what is possible.
Of course you can still provide CLI arguments to the debugger, with some extra work to sanitize the output
to remove machine information (hex-addresses, process ids, file paths etc). For that I've re-used the existing awk dependency which should be sufficient for the Unix platforms that will be initially supported.
Having support in ocamltest for LLDB and GDB will help ensure that any future changes don't break the debugging experience and more tests can be written in Python to exercise OCaml debugging functionality.
6d101c0 is a small refactor to make the existing bytecode debugger tests use
debugger_scriptas the name of the commands file to run against the debugger. To run a debugger test you would have:debugger_scriptto point to the commands and choose which debugger to run (gdb|lldb|ocamldebug).This change should be taken as a whole with the commits squashed before merging.