News for hackers. Stuff that matters.
Re:Speeding up the Rust edit-build-run cycle by ryangs on Thursday November 14, 2024 @03:03PM (#42140559)
>Debug information tends to be large and linking it slows down linking quite considerably. If you’re like many developers and you generally use println for debugging and rarely or never use an actual debugger, then this is wasted time.

Interesting. Is this true? In my work (java/kotlin, primarily in app code on a server, occasional postgres or frontend js/react stuff), I'm almost always reaching for a debugger as an enormously more powerful tool than println debugging. My tests are essentially the println, and if they fail for any interesting reason I'll want the debugger.

Re:Speeding up the Rust edit-build-run cycle by bluGill on Thursday November 14, 2024 @03:34PM (#42140898)
Depends on the developer. in the Practice of Programming https://en.m.wikipedia.org/wiki/The_Practice_of_Programming by Brian W. Kernighan and Rob Pike they say they use debuggers only to get a stack trace from a core dump and use printf for everything else. You can disagree but those are known very good programmers.
Re:Speeding up the Rust edit-build-run cycle by dgfitz on Thursday November 14, 2024 @03:35PM (#42140915)
What if the program doesn’t crash? It just black-boxes the data incorrectly? I can find that error infinitely faster with a debugger.
Re:Speeding up the Rust edit-build-run cycle by grey-area on Thursday November 14, 2024 @03:49PM (#42141062)
Your existing logs will tell you roughly where and you just insert some more log lines to check the state of the data.

Depends how fast your build/run cycle is and how many different prcocesses/threads whether a debugger will be faster/easier but a lot of it just comes down to preference. Most time spent debugging for me at least is spent thinking about the probable cause then choosing what state to look at.

Re:Speeding up the Rust edit-build-run cycle by dgfitz on Thursday November 14, 2024 @06:34PM (#42142456)
Logs are gold. Parsing logs can be very exhausting.
Re:Speeding up the Rust edit-build-run cycle by bluGill on Thursday November 14, 2024 @03:38PM (#42140941)
They use printf. Which they claim is faster.
Re:Speeding up the Rust edit-build-run cycle by dgfitz on Thursday November 14, 2024 @05:01PM (#42141689)
I'm not against printf at all, my lifetime commit history is evidence of that. Do you also think that in the case of a coredump not existing, that printf is faster? Sincere question. I'm having an internal argument with myself about it at the moment and some outside perspective would be most welcome.
Re:Speeding up the Rust edit-build-run cycle by bluGill on Thursday November 14, 2024 @07:54PM (#42142959)
Most of my time with printf degugging is spent trying to reason about the code not compiling.

though you should note that I'm repeating their claims. What I think is hidden.

Re:Speeding up the Rust edit-build-run cycle by ehaliewicz2 on Thursday November 14, 2024 @05:40PM (#42141963)
printf isn't faster if you want to single step through code to find math precision errors.

I've had to do that on a embedded system that didn't support debugging. It was hell.

Re:Speeding up the Rust edit-build-run cycle by dgfitz on Thursday November 14, 2024 @06:55PM (#42142609)
I’ve always wondered why embedded devs make less than “JavaScript-FOTM” devs.
Re:Speeding up the Rust edit-build-run cycle by flohofwoe on Friday November 15, 2024 @03:45AM (#42145022)
Faster than pressing F9 (to set a breakpoint on the current line) and then F5 (to start into the debugger)?

Printf-debugging has its uses, but they are very niche (for instance when you don't have access to a properly integrated debugger). Logging on the other hand is useful, but logs are only one small piece of the puzzle in the overall debugging workflow - usually only for debugging problems that slipped into production and when your code runs on a server (as opposed to a user machine).

Re:Speeding up the Rust edit-build-run cycle by hibbelig on Friday November 15, 2024 @07:49AM (#42146438)
It’s very interesting. I’ve tried to observe myself. It seems that if I can see a breakpoint somewhere and then examine state and then see what the problem is, a debugger is great.

If, however, it’s something where I need to examine state at multiple times in the execution, I lose track in my mind of the state I’ve seen before. This is where print debugging shines: I can see how state evolved over time and spot trends.

Re:Speeding up the Rust edit-build-run cycle by dietr1ch on Thursday November 14, 2024 @04:19PM (#42141338)
Printf debugging excels on environments where there's already good logging. Here I just need to pinpoint where in my logs things have already gone wrong and work my way backwards a bit.

You could do the same with a debugger setting up a breakpoint, but the logs can better surface key application-level decisions made in the process to get to the current bad state.

On a debugger I need to wind back on all functions, which it might get awful as some of them might be likely correct library calls that you need to skip over when going back in time, but that will take a huge portion of the functions called before the breakpoint. I don't think it's impossible to do with a debugger, but logging sort of bypasses the process of telling the debugger what's relevant so it can hide the rest, and it might already be in your codebase, but there's no equivalent annotations already there in the code to help the debugger understand what's important.

To me printf helps surfacing the relevant application-level process to get to a broken state, and debuggers help understand hairy situations where things have gone wrong at a lower level, say missing fields or memory corruption, but these days with safer languages lower level issues should be way less frequent.

---

On a side-note, it doesn't help debuggers that going back in time was really hard with variable-length instructions. I might be wrong here, but it took a while until `rr` came out.

I do think that complexities like that resulted in spending too much time dealing with hairy details instead of improving the UI for debugging.

Re:Speeding up the Rust edit-build-run cycle by dgfitz on Thursday November 14, 2024 @06:33PM (#42142444)
I appreciate your candor.

I really value debuggers. I have spent probably half my career solving problems that weren’t possible to solve with a debugger. When I can fall back on it, it helps me personally quite a bit.

Re:Speeding up the Rust edit-build-run cycle by dietr1ch on Thursday November 14, 2024 @07:06PM (#42142674)
I find them amazing, it's just that printf is unreasonably good given how cheap it is.

If I had the symbols, metadata, powerful debugger engine and a polished UI, I'll take that over printf everyday, but in the average situation printf is just too strong when fighting in mud.

Re:Speeding up the Rust edit-build-run cycle by kaba0 on Friday November 15, 2024 @03:38AM (#42144976)
Why not both? For any sufficiently complex app you will have some form of logging either way, and then you can further pinpoint the issue with a debugger.

Also, debuggers can do live evaluation of expressions, or do stuff like conditional breakpoints, or they can just simply add additional logs themselves. They are a very powerful utility.

Re:Speeding up the Rust edit-build-run cycle by canucker2016 on Thursday November 14, 2024 @05:26PM (#42141871)
But what source code debuggers did they have available?

Other than gdb, I can't name any Unix C source code debuggers. I believe they were working on Unix before GDB was created (wikipedia says gdb was created in 1986 - https://en.wikipedia.org/wiki/Gdb).

Plan 9 has acid, but from the man page and english manual, the debugger is closer to cli/tui than gui.

see https://9fans.github.io/plan9port/man/man1/acid.html and https://plan9.io/sys/doc/acid.html

Re:Speeding up the Rust edit-build-run cycle by rascul on Thursday November 14, 2024 @08:40PM (#42143179)
Looks like there was an adb in 1979 which is supposedly the successor to db.

https://en.wikipedia.org/wiki/Advanced_Debugger

Re:Speeding up the Rust edit-build-run cycle by fiedzia on Thursday November 14, 2024 @03:54PM (#42141102)
Debugging in Rust is substantially less common for me (and probably not only for me) because it is less often needed and more difficult - many things that are accessible in interpreted world don't exist in native binary.

I do care about usable tracebacks in error reports though.

Re:Speeding up the Rust edit-build-run cycle by nicce on Thursday November 14, 2024 @06:32PM (#42142439)
Main challenge with debuggers in Rust is to map the data correctly into the complex type system. For this reason I rarely use debuggers, becase dbg! is superior in that sense.
Re:Speeding up the Rust edit-build-run cycle by Animats on Thursday November 14, 2024 @03:55PM (#42141110)
The only time I use a debugger with Rust is when unsafe code in some library crate messes up. My own code has no "unsafe". I have debug symbols on and a panic catcher that displays a backtrace in a popup window. That covers most cases.

Rust development is mostly fixing compile errors, anyway. Once it compiles, it often works the first time. What matters is compile time for error compiles, which is pretty good.

Incremental compile time for my metaverse client is 1 minute 8 seconds in release mode. That's OK. Takes longer to test a new version.

Re:Speeding up the Rust edit-build-run cycle by flohofwoe on Friday November 15, 2024 @03:14AM (#42144866)
Debuggers are not only useful for actual debugging as in 'finding and fixing bugs', they are basically interactive program state explorers. Also "once it compiles, it works" is true for every programming language unless you're a complete newbie. The interesting bugs usually only manifest after your code is hammered by actual users and/or realworld data.
Re:Speeding up the Rust edit-build-run cycle by pepa65 on Friday November 15, 2024 @05:55AM (#42145730)
You're obviously not a Rust programmer.
Re:Speeding up the Rust edit-build-run cycle by flohofwoe on Friday November 15, 2024 @07:19AM (#42146233)
Rust only protects from a very small subset of bugs (memory corruption issues and data races) but not from logic bugs which are far more common.
Re:Speeding up the Rust edit-build-run cycle by Animats on Friday November 15, 2024 @04:30PM (#42151334)
Rust protects against undefined behavior. This is enough that programs either panic in a well-defined way, or continue to run well enough that logging works.
Re:Speeding up the Rust edit-build-run cycle by flohofwoe on Saturday November 16, 2024 @05:54AM (#42155768)
Not having UB isn't exactly unique to Rust though (Rust does have some UB btw it's just not as easy to encounter as in C or C++).
Re:Speeding up the Rust edit-build-run cycle by Aurornis on Thursday November 14, 2024 @03:08PM (#42140606)
println debugging is where everyone starts. Some people never graduate to knowing how to use a debugger.

Debugging through log data still has a place, of course. However, trying to do all of your debugging through println is so much harder, even though it feels easier than learning to use a debugger.

Re:Speeding up the Rust edit-build-run cycle by stouset on Thursday November 14, 2024 @03:16PM (#42140709)
I am comfortable using a debugger, but println debugging is easy, fast, and disproportionately effective for most of my debugging in practice.

I reach for a “real” debugger when necessary, but that’s less than 5% of the time.

Re:Speeding up the Rust edit-build-run cycle by flohofwoe on Friday November 15, 2024 @03:56AM (#42145082)
I wonder, do you use a separate debugger, or a debugger that's integrated into your IDE? "Reaching for a debugger" is just pressing F5 in an IDE.

E.g. I keep wondering whether the split between people who can't live without debuggers vs people who rarely use debuggers is actually people who use IDEs versus people who don't.

Re:Speeding up the Rust edit-build-run cycle by hibbelig on Friday November 15, 2024 @07:56AM (#42146483)
Data point: I develop in Java and I use IntelliJ. I run everything in debug mode. So it’s really easy for me to enter the debugger.

But I find that if I have to step around more than a handful of times to find the issue then I forget what happened five steps ago. So I teach for print debugging quite often.

Re:Speeding up the Rust edit-build-run cycle by stouset on Friday November 15, 2024 @07:41PM (#42153044)
I use VS Code, and there's an extension that provides a debugger for the languages I use.
Re:Speeding up the Rust edit-build-run cycle by 0x457 on Thursday November 14, 2024 @03:12PM (#42140672)
To be fair, if your code is multithreaded and sensitive to pauses, it becomes harder to debug with a debugger.

Ultimately, if you have a good logging setup and kinda know where the issue is a quick log message could be faster than debugging if all you want to do is look a variable value.

Re:Speeding up the Rust edit-build-run cycle by pjmlp on Thursday November 14, 2024 @04:39PM (#42141510)
That is where OS tracing like DTrace and ETW come into play, which can then be loaded into a debugging session.
Re:Speeding up the Rust edit-build-run cycle by kaba0 on Friday November 15, 2024 @03:41AM (#42144999)
Logging can change timing issues though. There are too many cases where an added log statement "fixed" a race condition, simply by altering the timing/adding some form of synchronization inherent in the logging library.
Re:Speeding up the Rust edit-build-run cycle by hibbelig on Friday November 15, 2024 @07:57AM (#42146489)
That’s true but boy howdy does pausing the program at a breakpoint change timing!
Re:Speeding up the Rust edit-build-run cycle by robdar on Thursday November 14, 2024 @08:39PM (#42143177)
printed/println debugging works if you wrote the code or have a good idea of where to go.

I frequently find myself debugging large unfamiliar code bases, and typically it’s much easier to stick a breakpoint in and start following where it goes rather than blindly start instrumenting with print statements and hoping that you picked the right code path.

Re:Speeding up the Rust edit-build-run cycle by toast0 on Thursday November 14, 2024 @04:26PM (#42141396)
I trained in the cout school of debugging. I can use a debugger, and sometimes do, but it's really hard to use a debugger effectively when you're also dealing with concurrency and network clients. Maybe one day, I'll learn how to use one of the time traveling debuggers and then I can record the problem and then step through it to debug it.
Re:Speeding up the Rust edit-build-run cycle by dgunay on Thursday November 14, 2024 @04:28PM (#42141419)
I use the debugger fairly regularly, though for me I'm on a stack where friction is minimal. In Go w/ VS Code, you can just write a test, set your breakpoints, hit "debug test", and you're in there in probably less than 20 seconds.

I am like you though, I don't typically resort to it immediately if I think I can figure out the problem with a quick log. And the times where I've not had access to a debugger with good UX, this tipping point can get pushed quite far out.

Re:Speeding up the Rust edit-build-run cycle by jesse__ on Thursday November 14, 2024 @04:55PM (#42141634)
I came here to write exactly this .. if I was drinking something I would have spit it everywhere laughing when I read it.

I guess 'many developers' here probably refers to web developers who don't use the debugger, cause it's mostly useless/perpetually broken in JS land ..? I rely heavily on the debugger; can't imagine how people work without one.

Re:Speeding up the Rust edit-build-run cycle by bippihippi1 on Thursday November 14, 2024 @04:57PM (#42141655)
when you write async JS code the debugger essentially adds no value over printing
Re:Speeding up the Rust edit-build-run cycle by flohofwoe on Friday November 15, 2024 @03:41AM (#42144996)
Not in my experience, async JS/TS code is perfectly fine debuggable (at least with setting a breakpoint here and there).
Re:Speeding up the Rust edit-build-run cycle by bippihippi1 on Monday November 18, 2024 @12:26PM (#42174649)
the callstacks are hard to read and watching variables across context boundaries is difficult. yea you can pause the program with the debugger, but doing so doesn't give much of a picture of how the program is functioning. I've found seeing the prints from all the 'threads' gives a better sense of what's happening
Re:Speeding up the Rust edit-build-run cycle by flohofwoe on Friday November 15, 2024 @03:40AM (#42144989)
The debuggers integrated into web browsers are actually really good, about the same level as most IDE-integrated debuggers.
Re:Speeding up the Rust edit-build-run cycle by eddd-ddde on Friday November 15, 2024 @12:40PM (#42149070)
Ironically the JS debugger is the only one I ever use because it's the only one that "just works".
Re:Speeding up the Rust edit-build-run cycle by eminence32 on Thursday November 14, 2024 @04:59PM (#42141670)
In my experience Java debuggers are exceptionally powerful, much more so than what I've seen from C/C++/Rust debuggers.

If I'm debugging some complicated TomEE application that might take 2 minutes to start up, then I'm absolutely reaching to an IntelliJ debugger as one of my first tools.

If I'm debugging some small command line application in Rust that will take 100ms to exhibit the failure mode, there's a very good chance that adding a println debug statement is what I'll try first

Re:Speeding up the Rust edit-build-run cycle by freeone3000 on Thursday November 14, 2024 @05:02PM (#42141699)
CLion adds the power of IntelliJ debuggers to Rust. It works exceptionally well.
Re:Speeding up the Rust edit-build-run cycle by nicce on Thursday November 14, 2024 @06:30PM (#42142418)
Do you have more information about this?

Last time I debugged Rust with CLion/RustRover, the debugger was the same as VSCode uses.

Re:Speeding up the Rust edit-build-run cycle by freeone3000 on Thursday November 14, 2024 @07:24PM (#42142773)
Sure. It’s got breakpoints, and conditional breakpoints, using the same engine as IntelliJ. It’s got evaluate, it’s got expression and count conditionals, it’s got rewind. It has the standard locals view.

Rust support has improved in 2024 pretty strongly (before this year it just shelled out to lldb); the expr parser and more importantly the variable viewer are greatly improved since January.

Re:Speeding up the Rust edit-build-run cycle by gooosle on Thursday November 14, 2024 @06:25PM (#42142382)
Does it support evaluating code, in context, while debugging?
Re:Speeding up the Rust edit-build-run cycle by freeone3000 on Thursday November 14, 2024 @07:21PM (#42142753)
Yes*, mostly

It can do any single expression, and the results are better than lldb, but it can’t do multiple statements and not everything in Rust can be one expression; you can’t use {} here

Re:Speeding up the Rust edit-build-run cycle by flohofwoe on Friday November 15, 2024 @03:11AM (#42144852)
> much more so than what I've seen from C/C++/Rust debuggers.

...have you ever used the Visual Studio integrated debugger for C/C++ instead of 'raw' gdb/lldb without a UI frontend?

Re:Speeding up the Rust edit-build-run cycle by kaba0 on Friday November 15, 2024 @03:32AM (#42144950)
I mean, even then c/CPP will optimize out stuff and you won't get as nice one-to-one mapping as you do with eg. Java.
Re:Speeding up the Rust edit-build-run cycle by flohofwoe on Friday November 15, 2024 @03:43AM (#42145010)
That's why the debug build config one uses during development only does little to no optimizations.
Re:Speeding up the Rust edit-build-run cycle by kaba0 on Friday November 15, 2024 @03:47AM (#42145038)
My point is that even that little can sometimes lead to less pleasant experiences, like stepping half a function's body ahead.
Re:Speeding up the Rust edit-build-run cycle by flohofwoe on Friday November 15, 2024 @03:58AM (#42145100)
Hmm, I've only seen that in some 'new-ish' languages sometimes (like currently Zig), which I think is a compiler bug when generating debug info. In C/C++ I see such random stepping only when trying to debug an optimized program.
Re:Speeding up the Rust edit-build-run cycle by flohofwoe on Friday November 15, 2024 @03:10AM (#42144848)
I also don't get it, debuggers as integral part of the programming workflow are a productivity multiplier. It does seem to be a fairly popular opinion in some programmer circles that step-debugging is useless, but I guess they never really used a properly integrated debugger to begin with (not a surprise tbh if all they know is gdb in the terminal).
Re:Speeding up the Rust edit-build-run cycle by pjmlp on Friday November 15, 2024 @05:45AM (#42145670)
That is why I found so great that Carmack's opinion on debuggers is similar to ours, at least there is some hope to educate the crowds that worship Carmack's achievements.
Re:Speeding up the Rust edit-build-run cycle by johnisgood on Friday November 15, 2024 @08:48AM (#42146898)
Is that crowd getting bigger or smaller though? When he worked for id Software, he was pretty popular in my circle of friends, because we were playing ioquake3 forks that we kept making mods for and so forth.
Re:Speeding up the Rust edit-build-run cycle by pjmlp on Friday November 15, 2024 @10:22AM (#42147701)
I would say among the folks that care about game development and graphics programming, people still listen to him with attention.

Outside that circle, maybe not.

Re:Speeding up the Rust edit-build-run cycle by jcelerier on Friday November 15, 2024 @12:21PM (#42148858)
In c++ for debugging a mid-sized app, gdb will sometime take up to 5 min to start (assuming no remote symbol cache used). On fairly powerful hardware - i7 13000-something, 64g of RAM. I have the time to do 15 compile-edit-run cycles adding prints in that time span before I have even reached main() in it. (And I really tried every optimisation, gdb-index, caches, split DWARF etc. It jus is absolutely mind bogglingly slow and sometimes will even just crash when reaching a breakpoint. Same for lldb. Those are just not reliable tools. And I'm not even talking of the MSVS debugger which I once timed to take 18 minutes from "start debugging" to actually showing a window with all the symbol server stuff.
Re:Speeding up the Rust edit-build-run cycle by SleepyMyroslav on Friday November 15, 2024 @03:02PM (#42150335)
Vs story does not match my experience for AAA game projects. First vs always had start debugging without loading any symbols at all. 2nd one can load each one module on demand. 3rd local file cache for symbol servers can be very much warm (ie have most of needed symbols in RAM). 4th if your project is stuck on old Vs version you can still debug with latest version of debugger in many cases. Ie for us there are no limits of how many versions of vs dev has on their pc. It might be only available if org has volume deals with Ms though.

Downloading symbols for first time from network symbol server is long but its not part of debugging cycle, at least after 1st run.

Re:Speeding up the Rust edit-build-run cycle by agent281 on Saturday November 16, 2024 @11:36AM (#42157258)
I work in data engineering. I tend to do println debugging because the production data sets are not available from my machine. I tend to prefer REPL or notebook driven development from a computer that is connected to the production environment.