-
Notifications
You must be signed in to change notification settings - Fork 3k
Experimental debugger API #9604
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
CT Test Results 38 files 1 003 suites 7h 26m 30s ⏱️ For more details on these failures, see this check. Results for commit 1fb9829. ♻️ This comment has been updated with latest results. To speed up review, make sure that you have read Contributing to Erlang/OTP and that all checks pass. See the TESTING and DEVELOPMENT HowTo guides for details about how to run test locally. Artifacts// Erlang/OTP Github Action Bot |
I've pushed a fixup commit with mainly documentation fixes. |
4921f0a
to
93f4ca9
Compare
|
Summary: This imports the latest version of [#9604](erlang/otp#9604). In particular, it is rebased on top of [#9646](erlang/otp#9646), that extended the `debug_line` instruction with an atom to distinguish the "entry" marker and the actual lines. Reviewed By: TD5 Differential Revision: D72258205 fbshipit-source-id: 1bdd29b37ce867b6c2b6b330b6c1a865b046baf0
Summary: We update the toolchain to the latest version of [#9604](erlang/otp#9604), which fixes the build for ARM. Diff of changes [here](https://github.com/jcpetruzza/otp/compare/edb-2025-04-03..edb-2025-04-01) Reviewed By: TD5 Differential Revision: D72394516 fbshipit-source-id: 755f9afa91a95099fd9037d6a51d36f003196e52
For security, we have a policy that only members of the OTP team are allowed to add BEAM files to primary bootstrap or |
I've revised the last commit to adhere to our comment conventions and force-pushed. |
I've force-pushed a new version, where I have:
|
We add a new erl_debugger module to the kernel application, that will provides an API for writing debuggers. Here we set up the general interface, with a stub for "setting a breakpoint" as the only debugging primitive. In the next commits we first implement the "breakpoint" primitive, and later add additional ones. About the general design: - A node needs to have debugging support enabled on startup with the `+D` option and this can't be enabled afterwards. This gives admins a way to prevent processes from blocking on prod due to an accidental debugger usage, etc. - Debugging primitives based on code instrumentation can be individually enabled/disabled, etc. - A debugger is an Erlang process; there can be at most one debugger process per node. - The system will communicate with the debugger process via `debugger_events` messages. For now we introduce only one message for notifying that a process hit a breakpoint
On module loading, `debug_line` are currently ignored. Now, when debugger support is enabled (and the line-breakpoint instrumentation enabled), we emit a `i_debug_line` instruction. For now, we only use it to add entries to the line-table, the actual breakpoint instrumentation is introduced next.
The logic was duplicated and out of sync. We want to add another internal function for dealing with breakpoints, so better to have all in one place
Added to our daily builds. |
This PR does not build on Windows (see the unsuccessful tests above). It seems to be because of this new line in
The culprit seems to be the use of I suggest that you replace all your new uses of |
@bjorng Interesting, I'll fix (need to get some windows box where I can test it first) |
It turns out that Regarding the |
@bjorng Thanks for the quick fix! |
So now it seems to build on all platforms. Unfortunately, we had multiple core dumps in our daily builds. Here is one of them:
This happens for a debug-enabled runtime with perf support. The layout of the stack is different when perf-support is enabled. |
I'll look into this, thanks! |
I've now examined another core dump. It turns out that I've pushed a fixup commit that calls
The runtime system needs to be started in the following way:
If running on a Mac (and possibly when compiling the runtime system with
|
@bjorng Re the
Running it as follows, crashes on 90% of the runs for me:
Looking into the perf one now |
Added two fixups: 1) cleanup in a testcase to workaround the hibernation bug above, 2) handle FP with perf enabled for inspecting the stack. Breakpoints are not working correctly with perf enabled, looking into that now |
f6c02ff
to
60edf71
Compare
Pushed fix for line-breakpoints with perf enabled |
Pushed further fixes to ensure erl_debugger_SUITE passes on emu flavor as well |
One more fixup: handle correctly setting/clearing breakpoints on a deleted module |
Summary: We bumpt the toolchain to the latest version of the [#9604](erlang/otp#9604) Main changes: * Formatting changes * Fixes build on windows * Workaround issue in VM related to hibernated processes and code purging * Fix issues when running with perf support * Fix issues when running with flavor `emu` * Fix issue setting/clearing breakpoints on deleted module Full list of changes [here](https://github.com/jcpetruzza/otp/compare/edb-2025-04-03..edb-2025-04-14) Reviewed By: alanz Differential Revision: D72969015 fbshipit-source-id: 0bca3514ae30a07b91b37ed41a089439a67e34b7
Thanks! Added to our daily builds. |
We add trampolines on each debug_line instruction, similar to the ones used on function entry. The main difference is that we need to save all live X-registers on the stack before calling `erts_internal:breakpoint/4`, and thus may require a GC.
We want to reuse the logic currently use to flip beakpoints for tracing, etc. However, at the moment, the functions where this happens not only change the code, but also set some flags value that are specific to those cases... We factor out this part of the code to their own functions. In doing so, we observe that for x86-64, the code was referring to `BEAM_ASM_FUNC_PROLOGUE_SIZE` to determine the offset to use when "disabling" a breakpoint that doesn't seem relevant. The value is indeed 6 (see, e.g., the assertion on the "enabling" case), and this corresponds to: - 1 byte for the NOP 0x90 due to call alignment - 1 byte for the opcode of a `CALL` - 4 bytes for the 32-bit offset of the call target
This PR is the complement to #9334 (adding the
debug_line
instruction) and together with #8670 (pausing proc timers) add the support on the VM that drives the new edb debugger.These are main parts of the PR:
A new
+D
emulator flag is added. When given, the VM becomes "debuggable", which means that when modules are loaded, thedebug_line
instruction is instrumented similar to what is currently done for tracing-breakpoints, so that one can enable and disable breakpoints on that particular lines.An experimental
erl_debugger
module is added, with a new debugging API. Essentially, it allows a single, local, process to be registered as the "debugger" process for the node. This process is the one that will receive messages notifying that a process hit a breakpoint. This way, we can decouple debugger implementations that consume this API (like edb) from OTP itself.The
erl_debugger
module also exposes new BIFs to inspect X and Y registers of a suspended process. Together with the new code-information BIFs added in Add support for debug information for a native debugger #9334, this let's a debugger show the values of variables in scope for a suspended process.