Show HN: Unbug – Rust macros for programmatically invoking breakpoints
https://github.com/greymattergames/unbugBy BrainBacon at
This project is inspired by some of the asserts in Unreal engine.Due to reliance on core_intrinsics it is necessary to develop using nightly Rust, but there are stubs in place so a production build will not require nightly.
I recently released version 0.2 which includes no_std support and adds optional log message arguments to the ensure macro.
JoshTriplett | 3 comments | 17 hours ago
Also, this is providing motivation to want to stabilize a breakpoint mechanism, perhaps `core::arch::breakpoint()`. I'm going to propose an API Change Proposal (ACP) to the libs-api team to see if we can provide that in stable Rust.
amluto | 2 comments | 14 hours ago
If Rust’s standard library does this, please consider using int3;nop instead.
JoshTriplett | 0 comments | 14 hours ago
In Rust, we're using the `llvm.debugtrap` intrinsic. Does that DTRT?
rep_lodsb | 1 comment | 12 hours ago
There is another encoding (CD 03), but no assembler should emit it. It used to be possible for adversarial code to confuse debug interrupt handlers with this, but this should be fixed now.
amluto | 0 comments | 9 hours ago
int3 is a "trap". continue will resume execution at the instruction after int3, as intended. But backtrace should, by some ill-defined magic, generate the backtrace as though RIP was (saved RIP - 1). And the condition for doing this isn't something that is (AFAIK) representable at all in GCC's worldview. Sure, GCC knows, or at least ought to know [0], that it gained control because of vector 3, and the Intel and AMD manuals say that vector 3 is a trap. But there isn't a bit in memory or anything you would see in 'info regs' that will say "hey, this is a 'trap', and backtraces and such should be done as though RIP was actually RIP-1".
Maybe the right solution would be to split the program counter, from the perspective of the debugger, into two fields: program counter for backtracing, and program counter for resumption.
And yes, I know that GCC gets this wrong. Been there, seen the failures. I have not checked, but I expect that LLDB works exactly like GCC in this regard.
[0] ptrace on Linux exposes the vector number, somewhat awkwardly. Or you can infer it from the fact that the signal was SIGTRAP.
estebank | 0 comments | 12 hours ago
BrainBacon | 1 comment | 16 hours ago
amluto | 1 comment | 14 hours ago
> Additonally, debugging may not land on the macro statements themselves.
See my comment above, and give int3;nop a try.
BrainBacon | 1 comment | 14 hours ago
BrainBacon | 0 comments | 7 hours ago
merksoftworks | 1 comment | 13 hours ago
Theoretically you could generate debug scripts with a macro and embed them with
#![debugger_visualizer(gdb_script_file = "../foo.py")]
but I haven't seen anyone go through the trouble.landr0id | 0 comments | 11 hours ago
xobs | 0 comments | 16 hours ago
nathanwh | 1 comment | 9 hours ago
BrainBacon | 1 comment | 8 hours ago
nathanwh | 0 comments | 2 hours ago
thramp | 2 comments | 16 hours ago
BrainBacon | 0 comments | 16 hours ago
BrainBacon | 0 comments | 16 hours ago
dboreham | 0 comments | 14 hours ago
ewuhic | 1 comment | 11 hours ago
BrainBacon | 0 comments | 8 hours ago
revskill | 3 comments | 17 hours ago
nindalf | 1 comment | 17 hours ago
A minority use the nightly build for various reasons: a feature that hasn't reached stable yet, or because they want to help test the nightly releases and prevent bugs from reaching stable.
jtrueb | 2 comments | 17 hours ago
Only recently have I had some projects switching to stable after their required features stabilized.
JoshTriplett | 0 comments | 17 hours ago
89.4% of users surveyed use stable. 31.1% use nightly, but there's overlap there (e.g. I use nightly to try out new things but don't build things that depend on nightly). Only 11.5% of people say they use a crate that requires it.
littlestymaar | 0 comments | 12 hours ago
While this used to be very common back then (in 2016-18 many things where progressively stabilized and you had cornerstone libraries switching to stable at almost every release) it hasn't been so for the past 5 years.
Rust gets way less “exciting” new features nowadays, as the language has settled a lot (there are still moving parts, but they are the minority not the norm).
landr0id | 0 comments | 11 hours ago
Per https://dev-doc.rust-lang.org/nightly/unstable-book/library-...
>This feature is internal to the Rust compiler and is not intended for general use.
dvtkrlbs | 2 comments | 17 hours ago
kookamamie | 0 comments | 11 hours ago
johnisgood | 2 comments | 17 hours ago
traxys | 1 comment | 17 hours ago
johnisgood | 1 comment | 17 hours ago
do_not_redeem | 1 comment | 16 hours ago
> BREAKPOINTS REQUIRE ENABLING THE EXPERIMENTAL core_intrinsics FEATURE
johnisgood | 1 comment | 16 hours ago
I like your username.
GolDDranks | 0 comments | 15 hours ago
monocasa | 0 comments | 17 hours ago
That obviously only works for non-library uses of nightly.