24 ms·
Things you can do with a debugger but not with print debugging
- swaits 1y agoAuthor missed one of the best features: easy access to hardware breakpoints. Breaking on a memory read or write, either a raw address or via a symbol, is one of the most time saving debugging tools I know.
- yakshaving_jgt 1y agoIs there somewhere where this approach is described in more detail?
- lock1 1y agoSearch for "watchpoint debugging". Usually in most garbage-collected environments, it just observes & breaks on symbols though, not raw addresses. Vscode (or an editor with ADP support) supports unconditional breakpoints, watchpoints, and logpoints (observe & log values to the debug console).
- SAI_Peregrinus 1y agoWhat watchpoints observe depends on the device & environment. E.g. for ARM Cortex-M MCUs, the (optional but very common) Data Watchpoint and Trace Unit (DWT) provides 1 or 4 watchpoints by using hardware comparators. They operate on raw addresses, since they work at the machine code level. They issue a debug interrupt when the comparator matches the address & operation (read/write), which the debug probe (J-Link, ST-Link, or other such probe) detects & forwards to the debugger (GDB, LLDB, etc.). Hardware watchpoints are extremely useful for debugging memory corruption in embedded systems, since they bypass the code running on the device under test entirely.
- jesse__ 1y agoVery roughly, hardware watchpoints are memory addresses you ask the processor to issue an "event" for when they're read from, written to, or executed. This event is processed by the kernel, and passed through to the debugger, which breaks execution of the program on the instruction that issued the read/write/exec. A concrete use case for this is catching memory corruption. If your program corrupts a known piece of memory, just set a hardware watchpoint on that memory address and BOOM, the debugger breaks execution on exactly the line that's responsible for the corruption. It's a fucking godsend sometimes.
- coderatlarge 1y agowindbg used to offer scripting capabilities that teams could use to trigger validation of any number of internal data structures essentially at every breakpoint or watchpoint trigger. it was a tremendous way to detect subtle state corruption. and sharing scripts across teams was also a way to share knowledge of a complex binary that was often not encoded in asserts or other aspects of the codebase.
- bpye 1y agoThis still exists? You can also use JavaScript to script/extend and there is a native code API too. Note: I do work at MSFT, I have used these capabilities but I’m not on the debugger team. https://learn.microsoft.com/en-us/windows-hardware/drivers/debugger/javascript-debugger-scripting https://learn.microsoft.com/en-us/windows-hardware/drivers/d... https://www.timdbg.com/posts/whats-the-target-model/ https://www.timdbg.com/posts/whats-the-target-model/ https://github.com/microsoft/WinDbg-Samples/tree/master https://github.com/microsoft/WinDbg-Samples/tree/master
- coderatlarge 1y agothanks for the pointers glad to hear it’s all still there i haven’t seen this type of capability used in too many companies tbh and it seems like a lot of opportunity to improve stability and debugging speed and even code exploration/learning (did i break something ?)
- delta_p_delta_x 1y agoWinDbg also has time-travel/record-replay debugging.
- coderatlarge 1y agothat sounds like a super-powerful feature especially for multithreaded debugging though i’ve never used anything like it.
- jesse__ 1y agoOh my god, same. This literally catches bugs with a smoking gun in their hand in a way that's completely impossible with printf. I'd upvote this 100 times if I could.
- sherincall 1y ago> completely impossible with printf Not printf exactly, but I've found bugs with a combination of mprotect, userfaultfd and backtrace_symbols when I couldn't use HW breakpoints. Basically, mark a set of pages as non-writable so that any writes trigger a pagefault, then register yourself as a pagefault handler for those and see who is doing the write, apply the write and move on. You can do this with LD_PRELOAD without even recompiling the debugee.
- jesse__ 1y agoOh yeah, I've done that trick before, it's quite handy. Sometimes catches bugs that would be tricky to find with watchpoints. I wrote an allocator that allocates an extra page either before or after the users allocation, and aligns the user allocation such that it is as close as possible (while respecting user-requested alignment) to butting up against that extra page (marked PROT_NONE). Can catch underflows or overflows with this method, but not both simultaneously. Very handy from time to time.
- antonchekhov 1y agoBack in the early '90s, I was a big fan of the C/C++ debugging library "electric fence" (written by Bruce Perens) - it was a malloc() implementation that used mmap() to set the pages of the returned buffer such that any writes in that region (and even read accesses!) caused a segfault to happen, and the program halts, so you can examine the stack. It was a godsend.
- praptak 1y agoFrom the same toolbox: expression watch. Set a watch on the invariant being violated (say "bufpos < buflen") and get a breakpoint the moment it changes.
- roca 1y agoEspecially with combined with reverse-execution in rr or UndoDB!
- AndyKelley 1y agoCombined with time travel it's mind-blowing. Stumble upon some corrupted memory? Just put a watch point on it, and run the program backwards. Two weeks just turned into two minutes.
- mwcz 1y agoWhat time traveling debugger(s) do you recommend? I'm a regular GDB user and keep meaning to try rr.
- AndyKelley 1y agoSince you're already a GDB user, rr will probably feel comfortably familiar. https://rr-project.org/ https://rr-project.org/ already has enough example usage to get you going on the home page right there.
- adgjlsfhk1 1y agorr is excellent. the only problem is it doesn't work for Windows
- delta_p_delta_x 1y agoIt's a little odd to use GDB on Windows. Have you considered either the Visual Studio debugger, or WinDbg? WinDbg has time travel debugging, and is arguably 'more excellent': https://learn.microsoft.com/en-gb/windows-hardware/drivers/debuggercmds/time-travel-debugging-overview https://learn.microsoft.com/en-gb/windows-hardware/drivers/d...
- hippo22 1y agoMost languages let you print the stack, so you can easily see the stack using print debugging. Anecdotally, dynamic expressions are impossibly slow in the cases I’ve tried them. As the author mentions, there are also a number of cases where debuggers don’t work. Personally, I’m going to reach for the tool that always works vs. sometimes works.
- nchmy 1y agobut can you go back in the stack and inspect the variables and related functions there in print debugging?
- truetraveller 1y agoThis is something that does not require a debugger perse. this is something that can be implemented by a "smart" log. beside the log entry there might be a button to see the trace + state at those points. could even allow log() to have an option for this.
- nananana9 1y agoBut you have to 1. stop the program 2. edit it to add the new log 3. rebuild the program 4. run it 5. get the program to the same state to trigger the log 3. can take quite a while on some projects, and 5. can take quite a while too for long-running programs. And then you see the result of what you printed, figure out you need something else as well, and repeat. Instead you can just trigger a breakpoint and inspect the entire program's state.
- pavon 1y agoFor 3, printf debugging is often faster for me because it only requires an incremental rebuild. Whereas with gdb, it is very likely that the release build doesn't show me what I want to see, so I need to do a full debug build from scratch which takes much longer, and sometimes no longer replicates the bug.
- old_bayes 1y agoIt may sound obvious to folks who already use a debugger, but in my experience a decent chunk of people don't use them because they just don't know about them. Spread the good word!
- nchmy 1y agoyeah, tons dont know they exist. But there's also a lot of people - new and veteran - who are just allergic to them, for various reasons. Setting up a debugger is the very first thing i do when i start working with a new language, and always use it to explore the code on new projects.
- giveita 1y agoWith VSCode it's often a 10 minute job to set up. We are spoiled! Back in the VS days using a Microsoft stack it was just there. Click to add breakpoint then F5.
- deleted 1y ago[deleted]
- nchmy 1y agowhen i first started programming, with php, it took me literally weeks to figure out how to get xdebug set up. (pro tip: just use DDEV - it makes it all simple). Not a second of that was a waste because xdebug (like all debuggers) is just that amazing.
- DrSiemer 1y agoThese days I'll just dump all relevant code into an LLM and have it explained to me instantly. Being able to ask questions about the parts that are unclear (or just plain wrong) is so much easier than trying to cram the entire thing into my brain RAM. In my experience it actually helps me learn faster too, since I rarely get stumped on random gotcha's anymore.
- nchmy 1y ago
- gigel82 1y agoI am surprised all the time in this industry how many software engineers still debug with printf. It's entirely baffling how senior / staff folks in FAANG can get there without this essential skill.
- mjevans 1y agoGood print statements can become future logging entries for when software ships and debugging statements need to be turned on without source code access.
- giveita 1y agoYeah and by good print statement you mean use a structured logging lib?
- spacechild1 1y agoI think nobody is arguing against logging. However, printf-debugging typically means that you are inserting temporary printf statements to debug a specific issue. In that case, you can just use tracepoints instead (if your debugger supports them).
- happytoexplain 1y agoImagine I posted the bell curve meme with "print debugging" on both ends.
- thr0w 1y agoNo way, sorry. The bug you're trying to squash isn't complicated enough if print statements are as valuable as a debugger. And I get what you're after - this is coming from someone who regularly uses `grep` to answer questions faster than my clients' dopey ETL/DB setups.
- MangoToupe 1y agoComplicated enough for what?
- jasonjmcghee 1y agoEvery engineer should understand how to use a debugger and a time profiler (one that gives a call tree). Knowing how to do memory profiling is incredibly valuable too. So many problems can be solved with these. And then there's some more specialized tooling depending on what you're doing that can be a huge help. For SQL, the query planner and index hit/miss / full table scan. And things like valgrind or similar for cache hit/miss. Proper observability (spans/ traces) for APIs... Knowing that the tools exist and how to use them can be the difference between software and great software. Though system design / architecture is very important as well.
- lock1 1y agoSo, uh, everything is important, and every engineer must know everything then? I mean, don't get me wrong, I do agree engineers should at least be aware of the existence of debuggers & profilers and what problems they can solve. It's just that not all the stuff you've said belongs in the "must know" category. I don't think you'll need valgrind or query planning in web frontend tasks. Knowing them won't hurt though.
- h4ch1 1y agoI can tell you for a fact a lot of budding web developers don't even know a Javascript debugger exists, let alone something as complex/powerful as Valgrind. All of these are useful skills in your toolkit that give you a way of reasoning about programs. Sure you can plop console.logs everywhere to figure out control/program flow but when you have a much more powerful tool specifically built for this purpose, wouldn't you, as an engineer, attempt to optimize your troubleshooting process?
- lock1 1y agoYeah, it's quite sad, considering it's already built-in on all major browsers. And it's not even hard to open it, like a click away on devtools tab. But I think promoting profilers is much more important than debuggers. Far too many people I know are too eager to jump on "optimization" just because some API is too slow without profiling it first.
- smlavine 1y agoIt's not a silver bullet, but Visual Studio is leaps and bounds ahead of gdb et. al. for debugging C/C++ code. "Attach to process" and being able to just click a window is so easy when debugging a large Windows app.
- jesse__ 1y agolol, agree to disagree here. While the interface to gdb is annoying, there are many gui frontend alternatives. VS, on the other hand, gets worse with every release. It is intolerably slow and buggy at this point. It used to be a fantastic piece of software, and is now a fantastic pile of shit.
- cenamus 1y agoAny recommendations on gdb frontends? Have tried with emacs, but I just really enjoy the point and click stuff, emacs keybinds don't work for me there.
- spacechild1 1y agoIMO the GDB frontend in QtCreator is quite nice.
- jesse__ 1y agoGitHub.com/nakst/gf
- westurner 1y agoFrom https://news.ycombinator.com/item?id=35710350 https://news.ycombinator.com/item?id=35710350 : > ... py-list, py-up and py-down, py-bt, py-print, and py-locals GDB commands > [ DDD, pyclewn (vim), trepan3k, Voltron, gdbghidra ] gdbghidra: https://github.com/Comsecuris/gdbghidra https://github.com/Comsecuris/gdbghidra radare2: https://github.com/radareorg/radare2 https://github.com/radareorg/radare2 voltron: https://github.com/snare/voltron https://github.com/snare/voltron And from https://news.ycombinator.com/item?id=41943521 https://news.ycombinator.com/item?id=41943521 : > pyvmidbg (libVMI + GDB) But that's archived. There's a QEMU gdbstub GDB interface. To print registers with GDB: info reg info all-registers i r a
- squirrellous 1y agoIME console-based debuggers work great for single-threaded code without a lot of console output. They don't work that well otherwise. GUI-based debuggers can probably fix both of those issues. I just haven't really tried them as much. pdb is great for python, though.
- MrDarcy 1y agoI frequently use the go debugger to debug concurrent go routines. I haven’t found it any different than single threaded debugging. I simply use conditional break points to break when whatever go routine happens to be working on the struct I care about. Is there more to the issue?
- squirrellous 1y agoThinking back, the issue I had with multi-threaded code was two-fold: - Things like "continue", "step" are no longer a faithful reproduction of what the program does in real time, so it's more difficult to understand the program's behavior. Some timing-related bugs simplify disappear under a debugger. - There's usually some background thread that's logging things to console, which reduces to problem 2 in my comment. I haven't used Go that much. I imagine since goroutines are such a cornerstone of the language, the go debugger must have some nifty features to support multi-(green)-threaded debugging?
- ajross 1y agoMeh. None of these sway me. I'm a die hard printf() debugger and always will be. But I do use debuggers regularly, for circumstances where printf() isn't quite up to the task. And there really are only two such categories (neither of which appear in the linked article!): 1. Code where the granularity of state change is smaller than a function call. Sometimes you actually have to step through things one instruction at a time, and I'm lucky enough to have such problems to solve. You can't debug your assembly with printf(), basically[1a]. 2. State changes that can't be easily isolated. Sometimes you want to log when something change but can't for the life of you figure out when it's changing. Debuggers have watchpoints. But... that's really it. If I'm not hitting one of those I'm not reaching for the debugger. Logging is just faster, because you type it in right at the code you're already reading. [1a] Though there's a caveat: sometimes you need to write assembly and don't even have anything like a printk. Bootstrap code for a new device is a blast. You just try stuff like writing one byte to a UART address or setting one GPIO pin as the first instructions and hope it works, then use that one bit of output to pull the rest up.
- smlavine 1y agoDo you use snippets or something to help speed this up? Manually typing `printf("longvarname=%s secondvarname=%d\n", longvarname, secondvarname);` adds up over a debugging session, compared to a graphical debugger setup with well-chosen breakpoints, watches etc.
- MangoToupe 1y agoLLMs have mostly made this trivial, plus you have the added benefit of being able to iteratively dump out more each run.
- truetraveller 1y agoThe first thing I always do is define log. It's bonkers to use console.log() for js. a simple window.log=console.log. Secondly, in your example, no need to label the names. This is almost always understood by context. So, pretty manageable. e.g. in JS: log(`${longvarname}, ${secondvarname}`)
- 1y ago
- VikingCoder 1y agoI have counter-points to several of these... But this one is my favorite (This didn't go very far, but I loved the idea of it...): I once wrote a program that opened up all of my code, and at every single code curly brace, it added a macro call, and a guid. void main() { DEBUGVIKINGCODER("72111b10c07b4a959510562a295cb2ac"); ... } I had to avoid doing that inside other macros, or inside Struct or Class definitions, enums, etc. But it wasn't hard, and it was a pretty sizeable codebase. The DEBUGVIKINGCODER macro, or whatever I called it, was a no-op in release. But in Debug or testing builds, would do something like: DebugVikingCoder coder##__LINE__("72111b10c07b4a959510562a295cb2ac"); (Using the right macros to append __LINE__ to the variable, so there's no collisions.) The constructor for DebugVikingCoder used a thread-local variable to write to a file (named after the thread id). It would write, essentially, Enter 72111b10c07b4a959510562a295cb2ac (epoch time) The destructor, when that scope was exited, would write to the same file: Exit 72111b10c07b4a959510562a295cb2ac (epoch time) So when I'd run the program, I'd get a directory full of files, one per thread. Then I wrote another program that would read those all up, and would also read the code, and learn the File Name, Line Number of every GUID... And, in Visual Studio, this tool program would print to the Output window, the File Name and Line Number, of every call and return. And, in Visual Studio, you can step forward AND BACK in this Output window, and if you format it correctly, it'll open the file at that point, too. So I could step forwards and backwards, through the code, to see who called where, etc. I could search in this Output window to jump to the function call I was looking for, and then walk backwards... Then I added some code that would compare one run to another, and argued we could use that to figure out which of our automated tests formed a "basis set" to execute all of our code... And to recommend which automated tests we should run, based on past analysis. In addition to being able to time calls to functions, of course. So then I added printing out some variables... And printing out lines in the middle of functions, when I wanted to time a section... And if people respected the GUIDs, making a new one when they forked code, and leaving it alone if they moved code, we could have tracked how unit tests and other automation changed over time. That got me really wishing that every new call scope really did have a GUID, in all the code we write... And I wished that it was essentially hidden from the developers, because who wants to see that? But, wow, it'd be nice if it was there. I know there are debuggers that can go backwards and forwards in time... But I feel like being able to compare runs, over weeks and months, as the code is changing, is an under-appreciated objective.
- makeitdouble 1y agoWhile a debugger is of high value, having access to a REPL also covers the major use cases. In particular, REPL tools will work on remote session, on pre-production servers etc. _if_ the code base is organized in a somewhat modular way, it can be more pleasant than a debugger at times. Makes me wonder if the state of debugging improved in PHP land. It was mostly unusable for batch process debugging, or when the server memory wasn't infinite, which is kinda the case most of the time for us mere mortals.
- never_inline 1y agoI am the author of the posted flamebait. I agree. I use IPython / JShell REPLs often when the code is not finished and I have to call a random function without entrypoint. In fact its possible to jump to the graphical debugger from the Python REPL when running locally. PyCharm has this feature natively. In VSCode you can use a simple workaround like this: https://mahesh-hegde.github.io/posts/vscode-ipython-debugging/ https://mahesh-hegde.github.io/posts/vscode-ipython-debuggin...
- untrimmed 1y agoHonestly, I feel like the print vs. debugger debate isn't about the tool, it's about the mindset. Print statements feel like you're just trying to patch a leak, while the debugger is about understanding the plumbing. I’m starting to think relying only on print is a symptom of not truly wanting to understand the system you're working in.
- someone_jain_ 1y agohttps://lemire.me/blog/2016/06/21/i-do-not-use-a-debugger/ https://lemire.me/blog/2016/06/21/i-do-not-use-a-debugger/ A bit of counterpoint here
- willtemperley 1y agoI'm unconvinced with this article. Whilst obviously a smart guy, I don't think Lemire really works on the same problems most of us do. Looking at his posts and publications it's generally high peformance work on problems that are small in scope. I suspect most people actually work on far bigger projects than he does! Neither do I see from that arctile that he's actually used a modern debugger to its full potential. I rarely step through code in slow motion, but sometimes it's great to see program state. If there are thousands of files in a project I don't know well, I can put breakpoints to test hypotheses about my understanding.
- kstrauser 1y agoInteresting POV. I see it exactly the opposite: using a debugger most of the time feels like trying to see the current state of things without understanding what set of inputs led to it. Print debugging feels more like trying to understand the actual program logic that got us to this point, based on a few choice clues. I’m not saying you’re wrong or I’m right, just that we have diametric opposite opinions on this.
- ahartmetz 1y agoCall stacks and reading code give very different views of the codebase. The debugger tells you what's happening, reading tells you what can happen in many situations at once. You can generalize or focus, respectively, but their strengths and weaknesses remain. Readable code, though, is written with the reading view in mind.
- bagels 1y ago"you can’t use them when your application is running on remote environments" This isn't always the case. Maybe it's really hard in a lot of cases, but it's always not impossible.
- makeitdouble 1y agoI read it as dealing with applications you only get shell access to and can't forward ports.
- bluishgreen 1y agoThere are two kinds of bugs: the rare, tricky race conditions and the everyday “oh shucks” ones. The rare ones show up maybe 1% of the time—they demand a debugger, careful tracing, and detective work. The “oh shucks” kind where I am half sure what it is when I see the shape of the exception message from across the room - that is all the rest of the time. A simple print statement usually does the trick for this kind. Leave us be. We know what we’re doing.
- BobbyTables2 1y agoFully agree. If I find myself using a debugger it’s usually one two things: - freshly written low level assembly code that isn’t working - basic userspace app crash (in C) where whipping out gdb is faster than adding prints and recompiling. Even never needed a debugger for complex kernel drivers — just prints.
- ehnto 1y agoI guess I struggle to see how it's easier to print debug, if the debugger is right there I find it way faster. Perhaps the debugging experience in different languages and IDEs is the elephant in the room, and we are all just talking past eachother.
- prerok 1y agoIndeed, depends on deployment and type of application. If the customer has their own deployment of the app (on their own server or computer), then all you have to go with, when they report a problem, are logs. Of course, you also have to have a way to obtain those logs. In such cases, it's way better for the developers to also never use debugger, because they are then forced to ensure during development that logs do contain sufficient information to pinpoint a problem. Using a debugger also already means that you can reproduce the problem yourself, which is already half of the solution :)
- AlotOfReading 1y agoOne from work: another team is willing to support exactly two build modes in their projects: release mode, or full debug info for everything. Loading the full debug info into a debugger takes 30m+ and will fail if the computer goes to sleep midway through. I just debug release mode instead, where print debug is usually nicer than a debugger without symbols. I could fix the situation other ways, but a non-reversible debugger doesn't justify the effort for me.
- zem 1y agothings I can do with print statements but not a debugger: trace the flow of several values across a program, seeing their values at several different times and execution points in a single screen.
- sfpotter 1y agoIt isn't either/or. Good programmers know how to use both and know how to choose the appropriate tool for the job.
- z_open 1y agoprinting is never the appropriate tool. You can make your debugger print something when that line of code is reached anyway and automatically continue if you want. So what's the point of pritntf? It's just less information and features.
- ahartmetz 1y agoLet me enumerate. Printf survives debugger restarts, shows up in git diff, usually messes less with the timing, can be exchanged with coworkers or deployed to users and be toggled with logging rules, has the full power of the programming language, the output is easier to run "diff" on to compare runs, works in CI containers, has no problems with mixed language environments... As far as I'm concerned, breakpoints and backtraces, especially of crashes, are the superpower of debuggers. Where they are not immediately applicable, I usually don't bother.
- horsawlarway 1y agoNah. Print debugging optimizes for timing detail and fidelity. Debuggers optimize for data detail, at the expense of timing detail and fidelity. In my opinion - timing & order of events is actually more meaningful. I often don't need the extra data detail, and the debugger is going to change timing in meaningful ways. Both are skills - both have their place. Know when logs are useful, know when debuggers are useful. Don't get stuck in the fallacy of "The one true way!" - that's the only thing I can promise is bullshit. If you've never debugged a problem that goes away when a debugger is attached - you're woefully unprepared to have this conversation (It's much rarer, but I can even talk about times where adding a single print line was enough to change timing and make the issue harder to reproduce). At the very least - with prints you get a tangible record of the order of operations during a reproduction. It doesn't go away, I don't have to remember how many times I've hit continue, I don't have to worry about whether pausing at this breakpoint is changing the world (and it is, because other things keep chugging - the network doesn't give a fuck that you're paused at a break point).
- dh2022 1y agoTwo of the benefits listed (call stack and catch exceptions at the source) are available in logging as well. A good logging framework lets you add the method name, source file and line number for the logging call-after a few debugging sessions you will construct the call stack quite easily. And C# at least lets you print the exception call stack from where it was thrown. I agree that adhoc dynamic expression evaluation at run time is very useful and can only be done in a debugger.
- troupo 1y agoDon't show the discussion to John Carmack. He's baffled why people are so allergic to debuggers: https://youtu.be/tzr7hRXcwkw?si=beXGdoePRkbgfTtL https://youtu.be/tzr7hRXcwkw?si=beXGdoePRkbgfTtL
- tayo42 1y agoI'm pretty sure in that interview at some point he realized becasue the debugger experience for developers using Linux sucks compared to Windows where he does most of his work. Alot of programmers work in a Linux environment. It seems like windows, ide and languages are all pretty nicely integrated together?
- troupo 1y ago> It seems like windows, ide and languages are all pretty nicely integrated together? Not only, and not really. After all, for all its warts Visual Studio is still a decent debugger for C/C++. IntelliJ has pretty good debuggers across all of their IDEs for almost all languages (including things like automatically downloading and/or decompiling sources when you step into external libraries). Even browsers ship with built-in debuggers (and Chrome's is really good). I still see a lot of people (including my colleagues) often spend inordinate amounts of time console.log'ing when just stepping though the program would suffice. I think it's the question of culture: people are so used to using subpar tools, they can't even imagine what a good one may look like. And these tools constantly evolve. Here's RAD Debugger by Ryan Fleury: https://threadreaderapp.com/thread/1920345634026238106.html https://threadreaderapp.com/thread/1920345634026238106.html
- jasonjmcghee 1y agoSomething I haven't seen discussed here that is another type of debugging that can be very useful is historical / offline debugging. Kind of a hybrid of logging and standard debugging. "everything" is logged and you can go spelunk. For example: https://rr-project.org/ https://rr-project.org/
- smj-edison 1y agoI've loved working with rr! Unfortunately the most recent project I've been contributing to breaks it (honestly it might just be Ubuntu, as it works on my arch install, but doesn't work when deployed where I need to test it).
- cluckindan 1y agoPrint debugging is historical / offline debugging, just ad-hoc instead of systemic. The ”debug” package on npm is something in between, as it requires inserting debug statements but they are hidden from output unless an envvar like DEBUG=scope.subscope.*,otherscope is used.
- willtemperley 1y agoThis is refreshing. I get triggered by people writing "I don't use a debugger because I'm too smart to need one". Some other things I'd add: Some debuggers allow you to add actions. For example logging at the breakpoint is great if I can't modify the source, plus there's nothing to revert afterward. This just scratches the surface. Some debuggers allow you to see entire GPU workloads, view textures etc. Debuggers are extremely useful for exploring and helping edit code. I can't be the only person that sprinkles breakpoints during development which helps me visualise code flow and quickly jump between source locations. They're not just for debugging.
- t_mahmood 1y agoMaybe someone can give me idea, how can I debug this particular rust app, which is extremely annoying. It's a one of Rustdesk. It won't run if I compile with debug info. I think it's due to a 3rd party proprietary library. So, to run the app I have to use release profile, with debug info stripped. So, when I fire up gdb, I can't see any function information or anything, and it has so many system calls it's really difficult to follow through blindly. So, what is the best way to handle this?
- mrugge 1y agoclaude code cli
- yrand 1y agoCould you expand on what you meant? I'm curious. Not related to OP, but debugging is often about finding where an invariant is broken, so it feels like using LLM to navigate a debugging loop may be useful as it's not a complicated but repetitive task. However in the morning I struggle to imagine how to do that.
- mrugge 1y agoI use claude code all day long to debug gnarly legacy code. Sometimes in languages I barely know. It works great especially as a second opinion or to get unstuck. It is very fun but can be addictive and exhausting.
- mrugge 1y agoMore specifically I will stub out a simple unit test by hand to zoom in on where I think the issue is. It then turns into an exhilarating and wild ride from there.
- tomjakubowski 1y agoYou can add debug info to release builds. In Cargo.toml: [profile.release] debug = true https://doc.rust-lang.org/cargo/reference/profiles.html#debug https://doc.rust-lang.org/cargo/reference/profiles.html#debu...
- sharts 1y agoWhat’s a good debugger for bash?
- complex_pi 1y agoset -x
- fsniper 1y agoPrint debugging is, checking patient's life signs, eye color, blood pressure, skin inflammation and so on. However using debuggers are like putting the patient through an MRI machine. It can provide you very advanced diagnostic information, but it's expensive, time consuming, requires specialized hardware and education. Alike medicinal doctors it's easier and logical to use the basics until absolutely necessary.
- never_inline 1y agoDidn't expect this to blow up, and now I realize it's bit of a flame bait topic, haha.
- m463 1y agodebuggers are hard to use outside of userland. For really hairy bugs in programs that can't be stopped (kernel/drivers/realtime, etc) logging works. And when it doesn't, like when you can't do I/O or switching of any kind, log non-blocking to a buffer that is dumped elsewhere. also, related. It is harder than it should be to debug the linux kernel. Just getting a symboled stack trace is ridiculously hard.
- ofrzeta 1y agoYou can debug the kernel with kgdb https://linuxlink.timesys.com/docs/how_to_use_kgdb https://linuxlink.timesys.com/docs/how_to_use_kgdb There is even KGDBoE to debug over the network.
- m463 1y agoI wasn't saying you can't debug the kernel. I was saying that for practical purposes, debugging the kernel is needlessly hard. As one example, say you are running the current ubuntu. A kernel panic will give you a bunch of hex addresses. How do you get a symbol'd backtrace of the kernel panic? (if you can't get that easily, running kgdb won't let you do symbolic debugging either)
- inglor_cz 1y agoI don't really get the hate that debuggers sometimes get from old hands. "Who needs screwdrivers if we always used knives?" - You can still use your knife, but screwdriver is a useful tool. It seems to me that this is one of the many phenomena where people want to judge and belittle their peers over something completely trivial. Personally, I get the appeal of printing out debugging information, especially if some bug is rare and happens in unpredictable times (such as when you are sleeping). But the amount of info you get this way is necessarily lower than what can be gleaned from a debugger.
- user3939382 1y agoDon’t tell Primeagen. Although he’s right about debugging sprawling systems in Prod. I’d argue the stateful architecture of these apps is the root cause.
- 7bit 1y agoAnd that's why I never learned Elixir, despite being an interesting languge with an awesome web Framework, Phoenix. The fact that there ist No Debugger is super unfortunate
- eviks 1y ago> Some would’ve also heard about time travel debuggers (TTD) which let you step back in time. But most languages do not have a mature TTD implementation. So I am not writing about that. Shame as that's likely the only option with significant universal UX advantage vs. sprinkling prints...
- SAI_Peregrinus 1y agoWatchpoints (breakpoint that triggers when a given memory address is read/written/both) are the other huge UX advantage over prints. They're not quite as universal: you can almost always "print" by blinking an LED even if you don't have the luxury of a UART or other console, and some extremely low-end MCUs don't have any sort of watchpoints, but almost everything else does. A watchpoint that logs which source line wrote to the address in question & continues execution automatically is one of the easiest ways to debug memory corruption.
- MangoToupe 1y agoI think the obvious benefit of a debugger is the ability to introspect when you have the misfortune of investigating the behavior of a binary rather than source code. In the vast, vast majority other instances, it is more desirable (to me) to encode evidence of investigation in the source itself. This has all the other benefits of source code—you can persist it, share it, let ai play with it, fork it, commit it to source control, use git bisect, etc. There are a few other instances where the interaction offers notable benefits—bugs in the compiler, debugging assembly, access to registers, a half-completed runtime or standard library that occludes access to state so that you might print it. If you have the misfortune of working with C or C++, you have the benefit of breaking on memory access—but I tend to file this in the "half-completed runtime" category. There are also a few "heisenbugs" that may actually prevent the bug from occurring by using print itself; but I've only run into this I think twice. This is also possible with the debugger, but I've only run into that once. The only way out of that mess is careful reasoning, and i recommend printing the code out and using a pen. I also strongly suspect that preference for print debugging vs interactive debuggers comes down to internal conception of the runtime and aesthetic preference. I abhor debuggers—especially thosr in IDEs. I think they tend to reimplement the runtime of a language a second time, except with more bugs and a less intuitive interface. But I have the wherewithal to realize that this is ultimately a preference.
- coldtea 1y agoCases where I absolutely need to do these things to solve a bug: 0% Maybe 0.1%
- binary132 1y agoI would add to that list the important point that in a large codebase rebuilding after changing a line of code can take a very long time. In fact this is one of the most important reasons to get familiar with your debugger.
- jonhohle 1y agoI don’t mind using a debugger, but one of the advantages to printed debugging is that it is universal. I work on a project with code in five languages (6 if you count the build system, 7 if you add shell scripts). Two of them I know the debugger very well. One of them I might be able to get by. One of the others I might have use the debugger once and the last I’ve never touched. printf debugging works in all of them, even the build system and shell scripts. A debugger can be great, no question about it, even for remote debugging. In my experience, I’ve seen fewer people effectively debug unfamiliar systems quickly.
- jbverschoor 1y agoThat’s just bc most tooling is utter crap, except for Java+eclipse
- wheybags 1y agoIn my experience, conditional breakpoints are so unreliable, that I just dont bother trying to use them. When I need one I add code like if (condition) print(""); Then add a breakpoint on the print. Calling print ensures the line with the breakpoint won't be optimised out (rarely matters as I'm normally debugging in... debug mode, but it's just a reflex at this point, and I need to put something in there)
- fluoridation 1y agoIn my experience, they're not unreliable, but they do massively slow down the application being debugged. I often do what you suggest, except with __debugbreak() (which compiles to int3).
- ziml77 1y agoI love debuggers but yeah conditional breakpoints are pretty bad. I tend to need to conditionally break when the same code is being called repeatedly with different inputs where only one of them causes the problem. The conditional breakpoint slows things down so much that I'd probably turn to dust before it ever actually halted execution. And I work in C#, so I have no clue why there's no option to inject the condition and a call to Debugger.Break() and then have the JIT recompile the function live. It would actually make conditional breakpoints usable!
- perryizgr8 1y agoThe really hard bugs are those that disappear if you make changes to the binary, like adding a print.
- karl_gluck 1y agoThere was a time when I built games entirely using Visual Studio 6 Edit and Continue. These were the days when debuggers were reliable. Nowadays, I treat the debugger’s output like a best guess: it’s probably right about local variable values and the call stack, but it sometimes has nothing useful to say, and very occasionally is actively misleading.
- jesse__ 1y agoThe 'actively misleading' part is a real killer. I've gone down deep, dark rat holes a couple times because the debugger lied to me. I'm 100% in the "use the debugger" camp, but I sure wish they felt a bit more solid. I haven't used one for a long time that wasn't pretty buggy.
- scotty79 1y agoThings you can do with print debugging but not with most debuggers. Watch expressions with history of values. Especially aggregate history of multiple watch expressions.
- iaalm 1y agoWhile I enjoy using debuggers and find them valuable tools, the reality is that many environments have network or security constraints that make debugging significantly more challenging than simply using logs.
- sriram_malhar 1y ago"Thinking before debugging" ... advice from Rob Pike about Ken Thompson's approach. https://www.informit.com/articles/article.aspx?p=1941206 https://www.informit.com/articles/article.aspx?p=1941206
- deleted 1y ago[deleted]