19 ms·
Print Debugging Should Go Away
- sdevonoes 6y agoPrint debugging requires zero configuration. So, for "easy" debugging sessions, I will use print debugging (it does work using plain Vim!). For more serious debugging, sure, a proper debugger is the way to go.
- commandlinefan 6y agoIf you're in an IDE, though, you can use logpoints rather than breakpoints and have the best of both worlds - "print" debugging without the need to recompile to test (and without having to remember to delete the print statement when you're finished with it).
- simiones 6y agoEven if you're in an IDE, the debugger will often require configuration if the app is not running directly on your local setup. This can range from rather trivial (run app in debug mode, connect to debug port) to rather complex (change the docker image for your app to include a debugger service of some kind).
- commandlinefan 6y agoOk, but isn't that true of print debugging too? Wherever the application is running, you have to recompile and redeploy it.
- simiones 6y agoSure, but I'm talking about more than that. For example, my Go microservices run in containers built like this: FROM scratch COPY --from=build-container /go/bin/the-binary /go/bin/the-binary So, the final container only contains my Go binary and nothing else. If I add some debug logging, I just rebuild my binary, rebuild the container, and re-deploy. However, if I want to debug this, I need to use a different container that includes Go delve (the Go debugger) and any dependencies it relies on, possibly open some extra ports, deploy that container instead of the standard one etc.
- fullstop 6y agoIn the Linux Kernel I'm still using printk and I don't see that changing any time soon.
- joezydeco 6y agoPernosco currently targets C, C++, Ada, Rust and V8 JS (e.g. node.js) applications that run on x86 Linux and work with rr. Cortex-M developer here. Let me know when you support bare metal.
- db48x 6y agoThat’s an interesting point. The way RR works is that it intercepts syscalls, records the execution point of the program that generated the syscall, records the arguments to the syscall, and the kernel’s response. During playback, it intercepts those syscalls, but instead of sending them to the kernel it just supplies the recorded response instead. It also records several hardware performance counters that were added to Intel CPUs over a decade ago to ensure that it can stop the playback of the program at the correct points reliably. It could also do this purely by single–stepping the program, but that would be horribly slow. For an embedded system, or for debugging the Linux kernel itself, this doesn’t work. The kernel doesn’t make syscalls, and your embedded system might not even have a kernel to make syscalls to. And your hardware probably doesn’t have the right performance counters; AMD cpus only got equivalent capabilities quite recently. On the other hand, perhaps you could capture and record interrupts instead of syscalls. Maybe the performance counters on the Cortex–M cpu could be made to work for RR’s purposes (I’m just assuming it has some performance counters; I haven’t checked). But that would take a lot of work, and most people just want to be notified when someone else has completed the work.
- rcxdude 6y agoCortex processors have a tracing functionality which allows capturing the entire instruction and data stream of the processor, allowing rr-style debugging. The main problem is this is almost always a very high-bandwidth stream which required dedicated pins on the microcontroller and a specialised (and usually expensive) adapter to collect. I've never actually seen it used, I don't know how many embedded developers actually use it (the only place I've heard tell of it being used is inside ARM). It's possible there's some configuration which only records the minimal trace needed to reconstruct the trace later in a way that is accessible to the software running on the chip (allowing extracting the data without needing a debugger attached), but I've not seen it, and the details of this functionality seem to vary substantially across different devices.
- matthewaveryusa 6y agoI'm 100% in the camp that print statements are terrible for debugging, and I never use them as a debugging tool for my personal projects or on my local box. However here is why, despite something like gdb/rr being the best tool for the job, I fallback to print statements for most code that's shared beyond my personal scope: - Works in any programming language. - Works in programming languages that aren't easy to debug with gdb out of the box without setup. - Works if you're trying to figure out why a problem is occurring without a core dump - Other developers understand how it works -- I find that there's no reasonable expectation that a developer knows how to use gdb. - Works on systems you only have log access to -- true for production systems that have sensitive customer data. So instead of debugging in two different ways, I've submitted myself to print statements -- tragedy of the commons I guess.
- anovikov 6y agoAdd one big thing: log debugging is convenient when debugging something with concurrency. When stopping on a breakpoint isn't an option.
- db48x 6y agoYou really should try recording with RR; you can play the recording back afterwards, stopping anywhere you want and resuming execution or even running the program backwards to go back to something you missed the first time. You can record it on the server and replay it on your laptop. You can record your tests and send recordings of your test failures to your bug tracker for efficient bug fixing.
- jcranmer 6y agoMy recollection, though, is that RR can only do single-core debugging, and it doesn't help with issues that involve multiple cores stomping on each other in multiple threads.
- db48x 6y agoSometimes that’s true, though you’ve stated it imprecisely. RR emulates pthreads in userspace, converting your multithreaded programs to run in a single thread. It does context switching between your threads much as the OS would if you had only one CPU core, but there is no true concurrency. This can hide some problems that are the result of race conditions, making them never show up in any of your recordings. If the problem doesn’t show up in any recordings, then RR isn’t going to help you debug them. However, RR does have a mitigation for this, called chaos mode. In chaos mode it doesn’t schedule your threads fairly. It randomly starves some threads, not allowing them to be scheduled, or interrupts them before their usual time slice is up. This can make it easier to capture race conditions in a recording, though it isn’t perfect. You should give it a try some time.
- amne 6y agoIgnorance is bliss!
- hallway_monitor 6y agoDebugging is one of the key skills all devs must master. Visual studio has one of the best debuggers I've used and it's still not perfect. That said, the title is still clickbait and print debugging will probably always have its place.
- ehnto 6y agoI am surprised anyone still wants to use print debugging. Certainly it's required sometimes, and sometimes it's the quickest easiest option. I use a mix. But the level of insight a good debugger gives you at a glance is not possible to achieve with print debugging, and I hate when I don't have access to a debugger, it's so cumbersome. Inside significantly complex programs, plopping a breakpoint and then climbing the recorded stack frames gives you a snapshot of the program at all calls all the way up the stack. It lets me find information in a matter of moments instead of minutes. You can run commands right there in the current moment of the program you paused on, and you can even change values to what you think they should be and let it run to make sure your assumption is correct and your fix will actually work. Instead of running the program ten times in a row to debug, I do all that in one go, and I can let my curiosity run wild as I poke and prod the program as I see fit. For programs that take a while to run during development, it's not even feasible to print debug. If you're waiting 1-5 minutes to run the program, and it takes you 5 goes, you've blown nearly half an hour twiddling your thumbs. Quite frankly if you were on my team and not using decent debuggers to troubleshoot, I'd have a chat. You and I are both on the clock, use your tools and get it done! Caveat: Some debuggers suck, and print debugging is less painful, but still painful.
- theamk 6y agoDo you ever have to deal with concurrency or external services? Trying to debug a program which is making an RPC call will likely cause the remote service to timeout and fail by the time you resume program, ruining your experience. And there is also classical logic/algorithms problems: your program did not crash, but after 50 iterations of the main loop, the result set is empty. With prints, you get it all on screen and stare at the intermediate progress for a few minutes. With debugger, you can set a breakpoint... and then you have to hit "continue" 50 times, trying to remember what the values were 20 steps ago.
- ehnto 6y agoYou do have to work around concurrency sometimes, it will obviously depend entirely on your stack but for me there is usually way to still get a debugger on the thread I want. For your second point, logic/algorithmic problems are when the debugger shines the most. If you don't know where the problem is, you can put a breakpoint somewhere you know is after the problem then climb back up the recorded stack frames to find the issue. If the issue is in a loop, you can put in a conditional watcher to only break when your condition is met, or just set a breakpoint one line after the loop and inspect the loop result right there. The most useful part of debugging is the ability to rapidly excercise your "aha" moments. When you print debug, you see the issue and go "Aha!" now you have to go verify with another print. If I see the issue in a debugger, I go "Aha!" and then immediately get to look at the variable or variables I've discovered is part of the problem. I want to make sure it's clear that I don't think print debugging is useless, it's got it's moments of usefulness. I just don't understand how someone would not want to take advantage of an advanced debugger when it's available. They are so powerful, it would be like watching a mechanic use a pair of pliers when they have access to an impact gun.
- falsaberN1 6y agoYou can pry my debug prints from my cold, dead hands. I get the point this person is making, but at times (and depending on language) it's the fastest and most efficient option. "Oh, the value is not what I expected" -> fix -> "value is good after testing, can remove the debug print". It's not elegant, yes, but it does the job with zero preparation and works for every language. Now if things are so hopeless the debug print doesn't even work, then yes, get a proper debugger.
- chii 6y agoThe fact that you _know_ where or which variable it is, and know where to put the print in order to see the value indicates that the bug is either trivial, or that you already have an idea of where the bug is! I argue that printf debugging is more difficult if you dont know _what_ is incorrect, or if you dont know where a value is being changed. Stepping through your code is a great way to find out. To me, actual stepped debugging is like having a print statement for every single line in the code base.
- falsaberN1 6y agoYou aren't wrong, but you do need a debugger to be available, and it's not the case with every language, unfortunately.
- stinos 6y agoI argue that printf debugging is more difficult if you dont know _what_ is incorrect Or even impossible? I use print debugging often, not even only in cases where there's no step debugging possible and/or I'm too lazy to fire up a config/software which allows debugging, but from time to time I encounter bugs which I really can't even begin to imagine how terribly awkward it would be without step debugging. For example: finding a bug in a mark&sweep garbage collector written in C which only occurred in certain LTO builds. To get a picture of the problem I stepped through assembly code while looking at certain memory locations, regsiters, the C stack, and some related variables. How would one tackle that with print debugging? Plus the print statements would affect the very thing being debugged? That should be fun. Not to mention the effort it took to even be able to reach the exact code location where all of this happened. Would almost require to randomly sprinkle print statements all over the place.
- theamk 6y agoWhile I agree with author that record-and-replay debuggers are nice, I don't think they will ever entirely go away. Those debuggers are ultimate "trace loggers", logging each statement and variable -- and thus they have inevitable overhead. I can see how replay debuggers work with programs like Firefox, where you start with a few megabytes of input data and have a working set of a few hundred megs -- but there are programs with much higher memory/io usage out there. Something as simple as "download a few gigs of data from internet and calculate its hash" will require enough trace to record all data downloaded, which would make the overhead huge.
- db48x 6y agoA program running under RR generally only runs about 40% slower than normal, which is often unnoticeable. The recordings are usually smaller than you would expect too; the largest one I have is 74GB, though that was because the program read in a whole lot of data. I didn’t record it reading in the whole 400+GB file… most of them are under 200MB. Actually, about 60% of them are less than a single megabyte. There must be a power–law thing going on there. Still, disk space is cheap; I may have to delete that recording one day but there’s plenty more disk space available.
- simiones 6y agoAs far as I understand, rr forces your program to run single-threaded while recording, so the performance overhead would be arbitrarily high depending on your degree of actual parallelism.
- db48x 6y agoNot exactly. Your program will still have threads, but RR intercepts the pthreads API and runs all your threads in a single OS thread; it handles context switches between your threads as if your computer only had a single CPU core. This does mean that the overhead can be much higher than 40%! The 40% number is for a program like Firefox, that might jump up to 16 active threads to render a webpage, but also had to idle for 50ms while it waited for the TCP connection to start up. I found that it was also a reasonable estimate for Reposurgeon, which is written in Go and uses concurrency during some repository operations, and when doing garbage collection. Other parts cannot be parallelized at all, so it balances out. I never measured that very precisely though; it would take anywhere from seconds to minutes to run a test without RR (depending on the data I loaded, etc), and only somewhat longer with RR.
- apetrovic 6y agoCan we imagine a future where we're using both a hammer and a screwdriver, depending on situation, without hammer-only and screwdriver-only people yelling at each other?
- VectorLock 6y agoIf only there were some kind of forum where people could debate which situations are most appropriate for screwdriver and which are most appropriate for hammer and respect each others opinions while learning new things.
- bogwog 6y ago> and respect each others opinions while learning new things. So basically, this hypothetical forum is not on the internet.
- jjoonathan 6y agoIf I hadn't frequently been given the back of a screw driver and tasked with banging in a nail, I wouldn't be complaining. I just want a $2 hammer on the shelf, is that so much to ask?
- marcosdumay 6y agoHum... Let's not pretend that the discourse has been dominated for decades by people claiming that print-debuging should go away and that anybody using it is incompetent, and that the reaction was nearly all people just saying "nope, that's stupid, print debug if perfectly fine" without any complaint about anything else. It's perfectly fine for you to want a step-based debugger. In fact, if there's anything not fine is that you should probably want more than that, but don't even get to see better tools around. It's great that somebody took the time to develop better tools and is trying to sell it... But, let's stop attacking print, because it's a perfectly fine tool.
- db48x 6y agoI agree with the sentiment, but the analogy is not a perfect one. Hammers and screwdrivers are alike in that they are both simple tools that do different jobs. Meanwhile we’re talking about tools that do the same job, but of different capabilities. Log or printf debugging is like a shovel, RR is like a steam shovel, and Pernosco is almost like the entire railroad logistics system set up by John Stevens for digging out the Panama canal. He completely rebuilt the rail system so that trains were moving past the shovels in the cuts continuously. Each shovel would simply unload dirt on whatever train car was closest. The trains in the cut moved slowly and never stopped, so there was always a car available. At the fill sites where the dirt was unloaded, he built what was effectively a huge plow system that would scrape the dirt off of the flat–bed cars all in one go (The French just had hundreds of men climb into the cars with shovels to dig the dirt out of the cars, effectively handling every shovel–full twice). The result was like a continuous conveyor belt over 50 miles long. He also built towns, stores, machine shops, water treatment and sewage systems for the towns at either end of the canal, and allowed Gorgas to virtually eliminate mosquitoes from the canal zone. Pernosco is more like the entire logistics system than the steam shovel, though there are still a few rough edges and some features that I wish it had.
- oconnor663 6y agoCan anyone recommend a youtube video of someone using rr effectively? I've used it a few times, and enjoyed it, but I feel limited by my beginner gdb skills. I think I need to watch someone more experienced.
- db48x 6y agoThat’s an excellent idea. Debuggers certainly need better documentation, and guided tours are a good way to teach skills. Some of the Mozilla folks did livestreams of their development work on Firefox, including debugging sessions. I haven’t watched any lately, but you might search them out. If they kept it up then they might be using RR now, instead of just GDB. Here’s a demo video for Pernosco: https://robert.ocallahan.org/2019/10/pernosco-demo-video.html https://robert.ocallahan.org/2019/10/pernosco-demo-video.htm... Pernosco is based on RR, but this probably won’t teach you anything about using RR, since the UI is so different. But it was a memorable one because Brendan Gregg produced a really good tutorial for GDB, where he debugged a real problem in a real program (instead of a made–up problem in a program written just to have a made–up problem inserted into it). The Pernosco demo debugs the same problem in the same program, so comparing the two can be quite easy. I would like to see someone the same type of tutorial for RR, and for other debuggers that people like.
- nromiun 6y agoThe primary reason I use print debugging because the UI is consistent across all languages and environments. You can literally just learn the hello world program of any language or environment (like the Linux kernel) and you are ready to use print debugging. Compare this to debuggers, you have to learn the special syntax of the debugger, which is usually very different to the host language, and only then can you start doing some actual debugging. > If the software industry took debugging seriously — instead of just grumbling about the tools and reverting to print debugging (or, at best, building a polished implementation of the features debuggers have had since the 1980s) — and invested accordingly we could make enormous strides, and not many people would feel the need to resort to print debugging. This doesn't make any sense, people don't "revert" or "resort" to print debugging, they use print debugging because it is so much simpler compared to debuggers. Print debugging is already as simple as it gets, you can't cut any complexity by adding a new tool.
- incrudible 6y ago> Compare this to debuggers, you have to learn the special syntax of the debugger... In VS Code, you get the basic visual debugger UI that has been around for decades, to observe variables, set breakpoints, move about the stack, and step through the code. This works for pretty much all major languages. It's dead simple and easy to learn. It even works over SSH. Now, if you insist on doing everything through a terminal, nothing will save you from a miserable debugging experience.
- Joker_vD 6y agoYeah... every time I tried to use GDB from the terminal, I always felt like I was trying to edit text with ed. Sure, people actually did that, but holy fatcats, even vi would be so much better. You'd think that one of the points of the debugger is to let you easily inspect the program's state, but the default interface is very adept at hiding it.
- db48x 6y agoThe secret to using GDB is to type “layout split” or “layout asm” as your first command.
- spion 6y agoThe best feature about print debugging is that it works in the vast majority of environments and languages and is trivial to get.
- runawaybottle 6y agoPrint lines also comes with the natural flow of the program, so you have the added benefit of fixing something in a strong way with print line debugging. If you make any wrong assumptions about freezing a program at a certain spot with a debugger ... I’m not sure, I guess I’m super biased about the simplicity of a good sharp kitchen knife.
- mousepilot 6y agoPrint debugging also lets me debug precisely how I want, across all languages that allow display of a value at a particular point in code. I'm not dissing folks who like the debuggers, but I think theres always going to be some folks who prefer one method over the other. "Print Debugging Should Go Away" is awful presumptive in suggesting that the author is an exclusive authority on how other people go about their workday. I mean the guy probably doesn't even know me.
- db48x 6y agoCarrying water from a well to your house in a bucket every day should go away too. Buckets are fine if they’re all you’ve got, but there’s a reason people install plumbing. More than one, I should say. The difference is that people have proven to be extremely quick to spend time and money on installing plumbing, but these days hardly anyone spends much time improving their editor or other tools. Some companies, like Microsoft, are rich enough to employ dozens or hundreds of engineers on VSCode, and then give it away for free in order to build good–will with a whole generation of programmers. I’m given to understand that Google has teams devoted to developer experience, who spend their time sharping the tools used by Googlers so that most Googlers won’t need to. But most of us don’t spend much time improving our tools, and we mostly can’t buy better ones. It may be presumptuous, but I agree with Roc. If we spend more time on our tools, then print debugging _will_ go away. Not because we’ve forced you to use terrible tools, but because the tools will be so much better than print debugging that you’ll voluntarily start using them.
- mousepilot 6y agosure, but doesn't that sort of require me to believe print debugging is the same as carrying water from a well? I'm happy that debuggers work for folks who like them, and I'm not above using one but for me, the plain old fashioned bandwidth and flexibility I can achieve with logged output just seems to have natural advantages in situations that I seem to find my way into. I'm not saying that "debuggers should go away" because I'm not going to presume that I know what works in someone elses situation, but it seems like this article is actually doing the exact same thing to me. Everyone on that "side" seems to be more emphatic that "print debugging should go away" (the very title), yet for the most part, I'm not seeing print debugger types demanding that interactive debuggers should go away. So there's a disparity in those two attitudes, that implies some advantages on one side or the other, wouldn't it be more productive to list the advantages and let the merits of each approach win out in each situation we programmers find ourselves in? Not to mention my "vendor paranoia", I mean the guy already is making my agent orange act up by almost titling his article "the way mousepilot works should go away," that isn't exactly the sales pitch thats gonna win me over.
- divingdragon 6y agoFor embedded microcontrollers, I don't think there is anything to really replace print debugging. Especially when the program interacts with external electronics components.
- brainwipe 6y agoI spent two hours debugging React in IE and still think print debugging should be the last resort, not your goto.
- henrik_w 6y agoI'm not sure if the post applies debugging in production systems or only when developing. For production systems it was not always possible to use a debugger, and you need logging there anyway, so finding bugs by looking at the logs has worked well for me. Not sure if that counts as print debugging. Some reasons why using a debugger in prod was hard: - knowing where to start. With logs, you get a picture of what has happened. - not stopping threads - not everybody can do it, but everybody can look at logs. Wrote more about it here: https://henrikwarne.com/2014/01/01/finding-bugs-debugger-versus-logging/ https://henrikwarne.com/2014/01/01/finding-bugs-debugger-ver... -
- js8 6y agoIn my head, there is this (incomplete) concept that I call "functional debugging" (for a lack of a better term). Current debuggers are oriented very imperatively, i.e. here's what's bound to happen and here you see it happening, step by step. I would like a debugger that would let me set up some query about the evaluation inside the program, for example, find me all input data in this test run that caused the output of a given function/expression to be such and such (possibly another data set produced during the debugging). Find me what are the typical inputs to the function. And so on. One of the ideas would be instead of having breakpoints set to a place of execution, they would be set to passed values or program state. This is much more sensible in the world of functional programming, and processing of large amounts of data. I can imagine a system like that to replace print debugging for me, but until then.. I find it easier to print.
- rasz 6y agoIll settle for ability to rewind. Whats the difference between console.log(somevariable) and breaking on that variable if the outcome is the same - me rewriting and running again?
- db48x 6y agoPernosco is that debugger. It builds a huge database of every recorded state of the program, and lets you query it. Here’s an example: https://pernos.co/about/expressions/ https://pernos.co/about/expressions/ Notice how the user clicked on a line number, and a window opened that shows every execution of that line. It’s not a breakpoint where you see only a single point in time; instead you see all the points in time. He then types in an expression, printing the value of the named variable at every single one of those points. Lastly, he types in a condition expression, narrowing the list to examine just the calls for a specific object.
- vagrantJin 6y agoI just a console.log statement not long ago! It just works. I agree that sometmes it's an obtuse method of finding a bug but it works.
- teachingassist 6y agoRelevant XKCD: "Is it worth the time?" https://xkcd.com/1205/ https://xkcd.com/1205/ It's still unclear to me that learning an interactive debugger would save me any time at all. Figuring out where I need to judiciously place print statements also helps me to figure out the code in front of me.
- Jtsummers 6y agoIf it lets you avoid recompilation, it's very likely it could save you a significant amount of time. I really learned GDB for an embedded Linux system where it took 5-10 minutes to compile and 5-10 more minutes to load the updated build and then you have to restart the whole device. I don't really feel like spending 20 minutes (worst case) or even 10 minutes (best case) to get to, hopefully, the right printf. Make a build with debug symbols, load it, run it with a debugger attached [0], maybe restart a few times to recreate the error path (which might have to be done with printfs as well). And once that process was established and written down (extra build target, half page of instructions on getting things properly configured for our environment) it became much, much faster than print debugging. [0] https://en.wikipedia.org/wiki/Gdbserver https://en.wikipedia.org/wiki/Gdbserver
- scoutt 6y agoI might be spoiled, since I started working on Windows using Visual Studio back in 1996. The debugger always seemed a fundamental part of developing (an learning to develop) applications. 10 years later, I was still being spoiled while building Windows CE OS images. There you had KITL to debug (over serial, ethernet or USB) the OS in real time from the IDE. When none of that worked, I purchased myself a Lauterbach probe (6K USD). The debugger IDE is the ugliest thing ever, but it's the most powerful tool around for embedded. Some years later I entered into kernel (Linux) building for embedded. When asked the guru what's there to debug the kernel, the answer I got was "printf". Man, I laughed so hard until I saw his "I'm being serious" face. Then I get used to it, but I still hate it. Again, some years later, I have to build Android images. Again, skimming through thousands of log messages thanks to dmesg and logcat... I still hate it. It seems archaic. The better moments of my current work is going bare-metal, debugging with an IDE, with my 15 euro JTAG plus OpenOCD and Eclipse. I couldn't be happier. In fact, for bare-metal embedded, there is no other way around. There is no printf. You can have it with semihosting or a serial port, but it's painful... it messes up with my timings. I need to debug using an IDE. And GDB from the command line... come on... it's 2021. It can be avoided. Even when I started with Rust for embedded I wanted a full debugging IDE (which I didn't find yet). I want to see how things get arranged in memory (how does a slice or enum look in memory? and, is it possible no one checked this before?) side-to-side with generated assembler. TL;DR, my opinion is that printf might be fine for some desktop development, but as a "I don't have any else to try" resource.
- SadWebDeveloper 6y agoSetting up a debugging environment is painfully difficult and time consuming that even the most pro-efficient devs (testers/qa) on debugging don't even bother wasting time. This is the only thing that visual studio does better than any IDE on the market... zero-config debug, even some mature IDE's like jetbrains ones still to this day don't have zero-config debug, it always take some external and obscure configuration to get things right.
- dahart 6y agoI feel like this doesn’t really make a case for why (or how) print debugging should go away. I absolutely buy the argument that debugging tools can do the same job, and that they can improve, but that’s not a reason to avoid prints at all costs. For me, the biggest hurdle to using a debugger is having to stop and re-learn how to use it. I reach for print sometimes only because I can’t remember the command line for the python debugger off the top of my head, or I can’t remember how to inspect a hex value in gdb. Yes it’s only a quick Google search away, but I can try the print without searching Google. Perhaps irrationally, having a long list of good debuggers I’ve never used like rr and Pernosco and others actually semi-consciously causes me to want to use them less because of the time investment required to figure them out (and repeatedly, like it has in the past with other debuggers.) There are hundreds of tools that I’m not using to their full potential for my job. Anyway, it’s silly to pretend we can’t have both. I land heavily on the side of using a good debugger whenever I can, and yet I still use prints all the time for quick & easy debugging. It’s silly to suggest that print debugging could ever go away; it can’t unless you want to remove print statements. One thing both this article and the one on print debugging the other day completely fail to address is debugging embedded systems and GPUs, where both types of debugging are much harder. Try debugging your shader on ShaderToy.com - neither method is available.
- throwaway894345 6y agoWith some discipline, you can also make those debug statements bonafide log statements, which you will likely need for production anyway. You can't do this with a debugger (although you can attach a debugger in certain circumstances, it is rare in production, it's not a complete solution, and it may violate compliance).
- dahart 6y agoAbsolutely, once a project hits a certain size, I can attest to the value of taking some time to establish a logger with a verbosity knob and command line control. Making it as easy to use as a print statement, but with a default quiet setting, means I can more easily plan and multiply the value of my efforts printing things. Plus, a good logging system works in release builds where a debugger might not.
- tqwhite 6y agoI have not read anything more dumb than this in a long time. The article fundamentally says, "Print debugging is not as good as magical tools will be if anyone ever makes them." What's annoying is that he's wrong. Print debugging is awesome and good. It allows one to explore flow and data. It allows intuitive, multi-pronged examination of a program. It can easily be combined with all the tools the programming language offers. It is incredibly easy to use. It is the same 'UI' everywhere – and it is available – in all languages. I rarely see something this bad make it onto the main page of Hacker News.
- incrudible 6y ago> The article fundamentally says, "Print debugging is not as good as magical tools will be if anyone ever makes them." ...except he did make some of those magical tools. This blog post is an advertisement for them. > Print debugging is awesome and good. It allows one to explore flow and data. It's the most primitive way to do that, which just happens to be "good enough" in many cases. This hinders the improvement of existing tools. This is also true for debuggers, they have been stagnant for decades. It's probably part of the same trend that pushed UNIX to domination despite being so primitive: It is cheap, portable and already ubiquitous.
- egberts1 6y agoSo bad, we need occasional reminders to re-examine our debugging methodology.
- closeparen 6y agoI think it’s generally pretty sad when people are plodding along with much worse tools than they could feasibly have. I’m not sure “walking should go away” but it is not great when people have to walk for hours to go a few miles, in a universe where bicycles also exist.
- deleted 6y ago[deleted]
- reportgunner 6y agoAlso print debugging adds zero dependencies.
- thrwaeasddsaf 6y agoSo does rr work on arm yet? Nope. Back to good old printf. On a realated note, the number of times I've had gdb crash on arm is so ridiculous that I don't really bother with it unless I absolutely have to.
- db48x 6y agoIt makes me sad to hear people say things like this. Did you debug GDB to see why it was crashing?
- rcxdude 6y agoThe saddest command I've ever typed was 'gdb gdb qtcreator', where inside qtcreator I was trying to debug using gdb. qtcreator was crashing when I tried to do that, and gdb was crashing when I tried to debug qtcreator crashing, and eventually I located a bug in gdb (which it turned out had been patched in a later version). It was a massive waste of my time and way off into yak shaving territory that I should have abandoned long before. Embedded debugging is a pile of woe as well, in my experience. On the current system I'm working on, with 4 different chips using 2 different architectures, 3-4 different JTAG adaptors and different vendors gdb integrations, none of the debugging interfaces work reliably. If you can get the software to start running under the debugger, usually the first breakpoint will get hit correctly. If you're lucky it'll even continue running after you restart it from that breakpoint. The next breakpoint is even less likely to work, let along actually being able to trace out the path of some code. In theory on one of the architectures the interface understands freertos threads, but that just reduces the odds of a successfull breakpoint even lower (and you can forget about support on the other ones).
- db48x 6y ago> It was a massive waste of my time and way off into yak shaving territory that I should have abandoned long before. I don’t know if I agree with you there. I suppose you did waste your time, since the bug turned out to already be fixed, but every crash has to be investigated by somebody. Otherwise, the wouldn’t get fixed. If they don’t get fixed, they simply waste everyone’s time, over and over again. The sad statement above was that the commenter saw a crash in a tool, and gave up instead of investigating. Thank you for not giving up when you were in the same situation! > Embedded debugging is a pile of woe as well I’ve never done anything of note on embedded platforms, but it certainly sounds like it. You would think that you could pay the vendors for better tools, but it sounds like they all just do the bare minimum, or they just do the bare minimum for anyone who doesn’t pay through the nose.
- rini17 6y agoOmniscient tools typically require recompilation or reconfiguring of the world which introduces their own bugs and is prone to failure. Better to use a language which has these included, is there any?
- db48x 6y agoI disagree. RR can record any binary; it doesn’t require you to recompile the binary with any sort of instrumentation.
- rini17 6y agoWell, gdb promised to be able to record/replay too, did not work for me for anything nontrivial, noone bothered with the bugreport for years, left a bitter aftertaste. I'm reluctant to sink more time into trying attempts to fix C debugging. (https://bugs.gentoo.org/578194 https://bugs.gentoo.org/578194)
- db48x 6y agoEven when GDB’s record and replay works, it’s terribly slow. I hope that one day GDB has features equivalent to Pernsoco, but putting a breakpoint after every single instruction is not going to scale. I hope you’ll give RR a try; it’s been fantastic for me. (rr-project.org)
- roca 6y agogdb's implementation of record-and-replay is terrible and to some extent poisoned the well :-(.
- vladimirralev 6y agoPrint debugging is perhaps just a sloppy version of debug logging. I can't quite tell if the author is arguing against DEBUG/TRACE logging which is the gold standard in debugging, particularly in low reproducibility and multi-threaded/actor-based systems or systems with many 3rd party dependencies.
- _pmf_ 6y ago> Many people prefer print debugging over interactive debugging tools. I don't "prefer" print debugging over interactive debugging tools. I need something that works reliably, repeatably and with as much difference from the production build as possible. gdb fails for me in all of these ways. I would prefer a working debugger, yes.
- perryizgr8 6y agoI hate print debugging. But the C/C++ gods in my workplace, who designed the whole system love it. So they did not care to make it easy for people like me to use debuggers. I am not skilled enough to figure out the exact incantations to run that will put in the correct symbols in the correct place such that gdb will pick them up. So I use print debugging exclusively.
- papito 6y agoThe author of this article should go away. When I saw how to set breakpoints in Node, that was the end of it.
- cptskippy 6y agoThe author starts out with a a simple statement: > Many people prefer print debugging over interactive debugging tools. Then explains that eventually developers come around to debugging. He explains all the advantages debuggers have while simultaneously touting his own tools. Then he blames adoption on the lack of engineering effort put into overcoming teething problems and calls for platform vendors to better support debuggers. I feel like the author is living in a vacuum and has no idea how most developers work. Watching his demo for Pernosco makes my eyes bleed. The steps he takes for debugging a crashing Python App are: 1) Reproduce bug and capture with rr 2) Transmit capture to Pernosco 3) Wait Minutes for an Email to arrive. 4) Follow link in Email to Web based Debugger 5) Review Core Call Stack and Assembly for your Python App. If it gets to the point where I need to review core call stacks or assembly to figure out why my code is crashing then I'm probably just going to rewrite it. For most developers writing line of business Apps or scripts to parse data and shove it in a DB, the errors you encounter don't require inspecting CPU registers or walking through assembly. They boil down to a misunderstanding about an object state or contents that's quickly rectified by runtime inspection which is why print statements work so well. By the time the author got to step 4 of his Pernosco demo, most developers using Print Debugging would have fixed their bug and been on to the next one.
- EamonnMR 6y ago> [Most bugs] boil down to a misunderstanding about an object state or contents that's quickly rectified by runtime inspection which is why print statements work so well. This, in particular, is why print debugging won't go away.
- roca 6y agoPerhaps the bug we chose to demo there is not representative of most bugs, but the underlying bug is in C code and Brendan Gregg, the person who debugged it "for real", debugged it using gdb. The erroneous state in this case is in ncurses, packaged as a system library, so using print debugging here would require building ncurses from source and wedging that into LLVM/Python somehow. So no, I don't believe your claim.
- 6y ago
- d0liver 6y agoSurprised nobody has posted this: https://lwn.net/2000/0914/a/lt-debugger.php3 https://lwn.net/2000/0914/a/lt-debugger.php3. The big problem with debuggers in general is that they encourage you to repair bad stuff rather than to create good stuff. When you reach for a debugger or a print statement, you're essentially saying to the machine, "I don't know how this code works, please tell me" and neither vehicle can really do that; all they can do is tell you what happened in a particular run. On the other hand, reading code can tell you how it works. However, frequently we have trouble reading and understanding which can often be resolved by seeing an output and properly generalizing a conclusion based on what you've read. But, you don't need to see a lot of output to answer a specific question. Odds are good that if you feel you need to see a lot of output then what you're doing is debugging a particular run rather than debugging the program itself. IMO, there is a big exception here when you want to understand the shape of data in a duck typed language. In that case, dumping an entire object can be useful just to see the shape of you data. This is something you could glean from reading but it generally doesn't change from one run to the next and is frequently left undocumented.
- dorian-graph 6y ago> The big problem with debuggers in general is that they encourage you to repair bad stuff rather than to create good stuff. Is that verifiable true?
- d0liver 6y agoYes? I think we all agree that the point of a debugger is to repair stuff that's broken, right? Do you actively read and improve the surrounding body of code while you use the debugger? If so, what do you get out of the debugger?
- imtringued 6y agoThat's not an argument against debuggers, it's an argument in favor of more machine verification e.g. through strict type checking. The expectation that we must understand every single line in a codebase to avoid minor mistakes like null pointers is a bit too much.
- taylodl 6y agoPrint debugging is fine in an environment where the edit/compile/run cycle is fast or doesn't even exist. In fact it's probably the easiest way to debug in such environments. What I've been thinking about is a code generation tool where I can specify the variable(s) I want to watch and it takes the original code as input and produces code with traces everywhere that variable is referenced or modified. If you're going to do print debugging then let's go all the way!
- decebalus1 6y agoThis Type Of Blog Spam Should Go Away
- tantaman 6y agoThe print statement is persisted in your code so you can easily see where you've been with `hg/git diff`. Using a debugger I find myself repeating the same steps over and over again that I would have done/written once via print debugging. That and once my system is deployed and I need to debug issues in production I'm relying on logs which are effectively print statements. So why would I want my dev debug and production debug flows to diverge? Doing print debugging gives me experience in what sort of information is useful to log as well as what is loggable.
- amarant 6y agoMan discussions in this thread really seem to be between those who know their debugger, and those who don't and doesn't want to learn. Is there anyone out there who is actually familiar with a debugger for the tool they're using and still prefer print debugging? No? That settles that then...
- friend-monoid 6y agoComing from embedded Linux programming, I gotta say sometimes (for easier problems) the overhead in altering the init and spinning up a gdbserver is too much; just pushing a few prints to debug something is easier. However - just having learned about rr, which seems like an amazing tool - I think that can breakpoint might change...
- simiones 6y agoDoes "print debugging" include debug logging? If yes, then I think it's absurd to claim that debuggers can replace debug logging entirely. I for one use both print debugging and actual debuggers (I've used the C# VS debugger, windbg, Java debugging in Eclipse, NetBeans, and IntelliJ, CLI gdb and pdb, Emacs GUD for gdb, pdb and Go delve, Emacs edb and the CCL debugger from SLIME). Sometimes it's awesome to point a debugger at a core dump and fix a year-old memory leak, or just see windbg point out a deadlock involving 5 locks in 2 different processes. Other times it's awesome to interpret debug logs and figure out a how a flow in a customer setup got interleaved and produced a race condition two weeks ago, which is causing a crash today.
- amarant 6y agoNo no, that's not what I meant at all. I meant print debugging can't replace the debugger. Of course a debugger can't replace the need for logs entirely!
- simiones 6y agoOh, then we are agreed! The article is in fact claiming that a debugger can replace print debugging entirely, that's why I read your comment in this same vein.
- HumblyTossed 6y agoPut your nose back down. Print debugging has its place. Just like a lot of other tools for debugging.
- flohofwoe 6y agoI agree (somewhat) that print debugging shouldn't be praised over interactive debugging, but when you write a revolutionary new debugger like rr, please please build a good UI workflow first, and make it work at least on Windows and macOS too. For instance, from a "time travelling debugger" I would expect some sort of graphical time line view, where I can immediately see where on the timeline I am currently, and jump back and forth while inspecting program state and memory in UI panels. A good UI is the most important part of a debugger, and the area with the most potential for improvement (Visual Studio is generally praised as the best debugger around, but when you think about it, the UI is archaic, yet it's the best we have). Without a good debugging UI and intuitive workflows, it's no wonder people are falling back to printf-debugging.
- petschge 6y agoUsing a "proper" debugger on a supercomputer tends to be super tricky and the correct setup tends to depend on the machine. And even if you have a debugger attached to all 100k MPI processes, where do you look? And if you try to debug a production run you certainly don't have enough RAM left over for a time travel debugger like rr. The "bad" print debugging still works at that scale. Sure, once you have understood the problem well enough that you can reproduce it on a single node within a couple of minutes a "proper" debugger can be very useful. But you need to get to that point first. And no core dumps are not a "solves everything solution" either. A) because dumping the entire 1500 TB of memory to disk takes a lot of time and B) because bugs can trash the stack, leading to misleading stack traces.
- ac42 6y agoThere's a similar war between logging and tracing. Tracing promises to give you everything you ever wanted to do with your logs and then botches it by sampling the data so you can't correlate anymore, or you don't sample and suffocate in data just as with logging but without the benefits. For debuggers it's probably the same: if they make the assumption that you need less than complete freedom in instrumenting the code, you will need print and if they don't assume that, they likely are harder to use than the language itself.
- vbsteven 6y agoI don't want to contribute to the printf vs debugger polarization that seems to be going on. But what I would like to mention: The first thing I do after `git clone` and getting the build working is spend a couple minutes trying to get a debugger working, preferably using the IDE debugger. Usually it's pretty simple and it works out of the box. Sometimes it requires fiddling a bit with debug ports and cli arguments (legacy Tomcat applications) or making sure sourcemaps are available (web frontend dev). If I can't get it working within 15 minutes, printf it is. But in most higher level projects it's usually a trivial initial time investment that pays off in the long run.
- unity1001 6y agoPrint debugger is the debugger which you carry with yourself to anywhere, any infrastructure, any codebase, any language, any organization. It just works, and it works everywhere. That's why people use it. Surely, if your work involves working in a certain stack permanently with a certain set of tools, definitely a dedicated debugger could improve your debugging. But for people who work with a large array of technologies and languages, especially senior developers who have to switch back and forth in between stacks - especially if they occupy a lead or man role in their org - that's not feasible. But print just works. Additionally print debug is the program telling you how things are without something else interacting with it. Leave aside not having to go through creating breakpoints and then going through them slowly one by one (god). You just place a print in a suspected location and run the program hands off. It doesnt trigger. Ok. You go to the other half of the potentially affected code. Put the print in there. Ha! it triggers. Then you repeat the process again, closing down on affected bit fast. Its a binary search pattern, and its fast. With debugger you have to create a mini program (thought-out breakpoints) to go through the actual execution of the code from the start.
- citrin_ru 6y agoGood debug logs have a value beyond software debugging by its developers - they are useful for ops too. More than a few times nginx and postfix debug logs allowed me to see how requests are processed and find a mistake which would be hard to spot just by looking at the config. Debug logs can be enabled for requests from configured IP even on a server with high load if traffic from the IP is low; rr I assume has no such option.
- ben509 6y agoMost of my unit tests have print statements in them, permanently, because I usually know what things I expect will break. There's a ton of utility in being able to understand a problem by reading a transcript. That's print debugging, and it's not going anywhere as long as unit tests are around.
- mathgladiator 6y agoNot going to ever happen because print debugging eventually gets formalized into logging and metrics as a best practice. My bias here is infrastructure, and you simply can't attach a debugger to a running production process to slow down customers. At core, debuggers are an educational tool for new developers or inexperienced developers. Experienced developers will add metrics, assertions, and logs to the code which will make print debugging mostly redundant.
- ffhhj 6y agoThis article is an ad that doesn't even mention the real issues with print debugging: 1. Sometimes the information you can print about an object is not complete due to console memory constraints, depth of the information, dereferencing, formatting, etc. So you will have to come back again and print more ranges of that information, and format the data to understand it. 2. Logging takes "a lot" time if you are working on high performace algorithms. Then it will be dangerous to forget removing a print. 3. Prints can leak security information. 4. In web browser consoles you get a live print of objects, not snapshots. That said, print is my favorite debugging method, but I constantly search and remove them, specially on release.
- true_religion 6y agoRecord-and-replay debuggers are amazing. My best debugging experience is still smalltalk from decades ago. You get an error unwind the code, edit live values, then hit run from any point in your code old or new and it’ll go on from there. You can even edit your call stack manually, save the stack manually and restart it later on any machine. RR probably is pretty similar for nodeJS but I haven’t had a chance to use it. Is it a game changer?
- juancn 6y agoIt will never go away. I work on servers that are 150 to 200ms away in terms of latency. They're impossible to do interactive debugging on them (well not impossible, but really unpleasant). Debuggers are not latency aware, they suck at it, they assume the debugged process is close to the UI showing the tooling, close in terms of latency and bandwidth. Granted, most of the debugging is local, but sometimes replicating the environment so you can reproduce the issue is impossible or at least really time consuming, so remote debugging is a must, and when that happens, print debugging tends to win.
- marto1 6y agoAnd it won't right along with fundamental CS paradigms like functional programming. Useful ideas tend to be sticky because well...they are useful. This one has been around long before computers existed and the chances of it going away are low to none. Note: Heck, even Java will probably stick around for quite a while ¯\_(ツ)_/¯
- gpsx 6y agoI bet the author uses print debug statements some times.
- sigg3 6y agosed "s/should/will not/"
- deleted 6y ago[deleted]
- alo75 6y agoecho "Never!";
- twirlock 6y agoYou should have a theory of your software system. That should be part of the design. Step debuggers are fine, but you shouldn't need clippy to come tell you how the system works. There should be situations where it is a waste of time.
- AnimalMuppet 6y agoFor those who do use print debugging, and are in Java, here's a trick that is occasionally helpful: When you know you're getting to a function, but you don't know how, create an exception in that function, print the stack trace, and then don't throw the exception.
- tmccrary55 6y agoWhile I much prefer debuggers, I've never had a print statement "crash" and stop working. But I've had debugger crashes or weirdness where they stop working in every language and debugger option I've ever used (gdb, lldb, MS debugger, JVM, Rust, V8, etc).
- chadlavi 6y agoconsole.log("no");
- musicale 6y agoLogs are useful, since they tend to be easy to analyze and aggregate. However, if you are logging the entire state of the program over time then you're probably better off using an omniscient replay debugger.
- imtringued 6y agoI'm not against using a debugger, however one benefit print debugging is that you can print out intermediate states in a loop and look over all of them at once. Using a debugger would require stepping until you find the wrong iteration.
- xbgnx 6y agoI personally think the future of debugging is tracing experience like this - https://www.youtube.com/watch?v=4vtKRE9an_I https://www.youtube.com/watch?v=4vtKRE9an_I
- rurban 6y agoPrint debugging is called debug tracing. And it will never go away. It's not used for debugging mostly, but to analyse traces. Several systems cannot even use debugging. Such as realtime, kernel or embedded. The only tool they have is debug tracing. Looking at logs. I've worked years only looking at logs, tons of logs from tons of connected real-time systems. Writing tons of log analysis tools. I love debuggers, but debuggers are a rare luxury to have. In many cases we even added embedded shells (read-eval-print loops, lua, picoc, ...) into embedded systems to query its state. Similar to a debugger, but also completely different. You should also not forget LED debugging. Sometimes you only have two LED's.