LWN: Comments on "How to fix an ancient GDB problem" https://lwn.net/Articles/909496/ This is a special feed containing comments posted to the individual LWN article titled "How to fix an ancient GDB problem". en-us Mon, 08 Sep 2025 05:46:41 +0000 Mon, 08 Sep 2025 05:46:41 +0000 https://www.rssboard.org/rss-specification lwn@lwn.net How to fix an ancient GDB problem https://lwn.net/Articles/915433/ https://lwn.net/Articles/915433/ Hi-Angel <div class="FormattedComment"> <span class="QuotedText">&gt; Back when v2 was posted to the list last year, someone tested it with PipeWire specifically, and confirmed it works there.</span><br> <p> That was me. The patchset still haven't been merged…? Oh, my :c<br> </div> Fri, 18 Nov 2022 21:04:28 +0000 Since only 2007? https://lwn.net/Articles/911090/ https://lwn.net/Articles/911090/ rmano <div class="FormattedComment"> This one wins... <a rel="nofollow" href="https://bugzilla.mozilla.org/show_bug.cgi?id=377621">https://bugzilla.mozilla.org/show_bug.cgi?id=377621</a> ;-)<br> <p> </div> Thu, 13 Oct 2022 20:40:35 +0000 How to fix an ancient GDB problem https://lwn.net/Articles/910261/ https://lwn.net/Articles/910261/ palves <div class="FormattedComment"> <font class="QuotedText">&gt; When attaching to a running process, you just have to hit Ctrl+C in the terminal running GDB, as before. This mode of </font><br> <font class="QuotedText">&gt; operation hasn&#x27;t really suffered from these problems, as far as I understand it.</font><br> <p> When you attach to process running in another terminal, and hit Ctrl-C in the terminal running GDB, that Ctrl-C is turned into a SIGINT sent to GDB. So that half of the problem does not exist in that scenario, GDB sees the SIGINT first, not the inferior. However, currently, in &quot;I am attached&quot; scenario, GDB forwards that SIGINT to the target process, using plain &quot;kill(pid, SIGINT)&quot;, and then relies on ptrace intercepting that SIGINT. If the target process blocks SIGINT, then you&#x27;re back to square 1. To get that scenario working properly, we stil need part of the proposal in place, specifically the part about pausing the target process in a different way, with SIGSTOP.<br> <p> </div> Tue, 04 Oct 2022 11:52:03 +0000 How to fix an ancient GDB problem https://lwn.net/Articles/910203/ https://lwn.net/Articles/910203/ palves <div class="FormattedComment"> <font class="QuotedText">&gt; My personal experience with a possibly-related bug: when debugging programs which handle Ctrl+C themselves </font><br> <font class="QuotedText">&gt; (like PipeWire and Audacious), pressing Ctrl+C will trigger the app&#x27;s graceful shutdown process </font><br> <font class="QuotedText">&gt; (terminating execution) rather than breaking into the debugger like I want. Will the changes to gdb fix this issue?</font><br> <p> Back when v2 was posted to the list last year, someone tested it with PipeWire specifically, and confirmed it works there.<br> <p> From <a rel="nofollow" href="https://inbox.sourceware.org/gdb-patches/1c54ccee2e4a2980b0a0e5b7e50818970662afc2.camel@yandex.ru/">https://inbox.sourceware.org/gdb-patches/1c54ccee2e4a2980...</a> :<br> <p> <font class="QuotedText">&gt;&gt; &quot;I was recently fixing some bug in Pipewire. To be exact, I was working on</font><br> <font class="QuotedText">&gt;&gt; `pipewire-media-session` (one of daemons that Pipewire is comprised of). Process</font><br> <font class="QuotedText">&gt;&gt; of debugging basically included setting breakpoints somewhere, then hopefully</font><br> <font class="QuotedText">&gt;&gt; triggering the breakpoint, then inspecting the state. Nothing unusual.</font><br> <font class="QuotedText">&gt;&gt;</font><br> <font class="QuotedText">&gt;&gt; So, the thing that was slowing me down and annoying is that I couldn&#x27;t just</font><br> <font class="QuotedText">&gt;&gt; pause the debuggee through the usual means of ^C, then add a breakpoint.</font><br> <font class="QuotedText">&gt;&gt; Pressing ^C was causing the process to exit!</font><br> <font class="QuotedText">&gt;&gt;</font><br> <font class="QuotedText">&gt;&gt; Pipewire project seems to have a number of various daemons, and all of them set</font><br> <font class="QuotedText">&gt;&gt; SIGINT handlers (judging by git-grepping for SIGINT). So basically, it is hard</font><br> <font class="QuotedText">&gt;&gt; to debug Pipewire with GDB due to GDB not being able to interactively pause the</font><br> <font class="QuotedText">&gt;&gt; process.</font><br> <font class="QuotedText">&gt;&gt;</font><br> <font class="QuotedText">&gt;&gt; Now, I tested the patchset, and I confirm it solves the problem! GDB built from</font><br> <font class="QuotedText">&gt;&gt; the palves&#x27; branch pauses pipewire-media-session correctly on ^C! &quot;</font><br> <p> ..<br> <p> <font class="QuotedText">&gt; Also is &quot;a GDB command that allows the user to specify which key should interrupt the process</font><br> <font class="QuotedText">&gt; and return to the GDB prompt&quot; already present, or will it be added in the rewrite?</font><br> <p> It does not exist yet. It will be added in the next version of the patches.<br> </div> Mon, 03 Oct 2022 18:30:05 +0000 why blocking sigint ? https://lwn.net/Articles/910193/ https://lwn.net/Articles/910193/ iabervon <div class="FormattedComment"> If you&#x27;re really just going to set a flag, the fact that a blocked signal is pending is effectively a flag that the kernel handles for you without any fuss and without interrupting syscalls. If you install a signal handler, you get to find out how well your program handles getting a ton of short writes or EINTR in a critical section when the user hammers ctrl-c. Your program should handle it well, but that path is probably not being exercised at all under normal operation.<br> </div> Mon, 03 Oct 2022 18:06:23 +0000 why blocking sigint ? https://lwn.net/Articles/909985/ https://lwn.net/Articles/909985/ NYKevin <div class="FormattedComment"> Signal handlers suck, because they can only call fully reentrant functions. It is often desirable to run code on a &quot;real&quot; stack (i.e. not from the signal handler), at which point you might decide to forego the signal handler altogether, by doing one of the following instead:<br> <p> * Make a signalfd(2) and add it to your main event loop&#x27;s select(2)/poll(2)/etc. call.<br> * Make a dedicated &quot;handle the signals&quot; thread, block all the signals you care about (including SIGINT), and call sigwaitinfo(2) from that thread.<br> <p> You might also block signals for a short time while the thread or process is holding a mutex, in cases where this could cause deadlock or violate an invariant.<br> <p> Frankly, there is absolutely nothing in either POSIX or Linux to suggest that blocking signals is &quot;wrong&quot; so long as the process actually responds to them in a valid and appropriate way. SIGINT means &quot;please stop what you&#x27;re doing,&quot; not &quot;please push a weird extra frame on the stack so the debugger can break in.&quot;<br> </div> Fri, 30 Sep 2022 19:52:33 +0000 How to fix an ancient GDB problem https://lwn.net/Articles/909973/ https://lwn.net/Articles/909973/ ballombe <div class="FormattedComment"> <font class="QuotedText">&gt; My personal experience with a possibly-related bug: when debugging programs which handle Ctrl+C themselves (like PipeWire and Audacious), pressing Ctrl+C will trigger the app&#x27;s graceful shutdown process (terminating execution) rather than breaking into the debugger like I want. Will the changes to gdb fix this issue?</font><br> <p> Unlikely. Usually &#x27;graceful shutdown&#x27; is implemented by forking and waiting for the child to terminate (or crash).<br> This means that you are running gdb against the wrong program, so of course you do not get anything useful.<br> You need to tell gdb to follow the fork.<br> </div> Fri, 30 Sep 2022 15:58:02 +0000 why blocking sigint ? https://lwn.net/Articles/909971/ https://lwn.net/Articles/909971/ farnz <p>Yes, but this also requires competent programmers, as opposed to people who flail around until they find something that fixes the reported bug (users killing the program with Ctrl-C when it can't safely be interrupted without triggering a full DB recheck). Fri, 30 Sep 2022 15:17:37 +0000 why blocking sigint ? https://lwn.net/Articles/909969/ https://lwn.net/Articles/909969/ ballombe <div class="FormattedComment"> <font class="QuotedText">&gt; A proper fix was to replace this with a signal handler, and teach the critical sections to check to see if there had been a SIGINT while they were in progress (exiting immediately once you were out of the ). </font><br> <p> Yes, that is how my project does it too. Just adds a signal handler that set some flag, and check the flag when leaving the critical section. Much nicer than blocking SIGINT.<br> </div> Fri, 30 Sep 2022 15:15:41 +0000 why blocking sigint ? https://lwn.net/Articles/909967/ https://lwn.net/Articles/909967/ farnz <p>I've worked on a codebase that blocked SIGINT whenever it entered a critical section, and unblocked it afterwards. This was a poor way to avoid being killed by the end user hitting Ctrl-C to escape the program at an inopportune moment (not least because it didn't account for Ctrl-\ or Ctrl-Z), but it worked well enough for the use case in question, since users just spammed Ctrl-C until it died. <p>A proper fix was to replace this with a signal handler, and teach the critical sections to check to see if there had been a SIGINT while they were in progress (exiting immediately once you were out of the critical section). But that took maintenance work being done for other reasons - it wasn't something that was going to get fixed until I had to do some work to port to a new OS. Fri, 30 Sep 2022 14:46:21 +0000 How to fix an ancient GDB problem https://lwn.net/Articles/909956/ https://lwn.net/Articles/909956/ leromarinvit <div class="FormattedComment"> That would actually be useful I think. Some time ago, I half-seriously looked into in-kernel ways to colorize stderr (so as to include programs that don&#x27;t use glibc, so LD_PRELOAD tricks don&#x27;t work), and BPF would be a nice, non-intrusive (at least for the actual colorization logic) solution if it had the capabilities.<br> <p> Since the tty code can&#x27;t be built as a module, the only other way to achieve what I wanted would either require rebuilding the kernel (which I&#x27;m usually too lazy for) or ugly runtime patching.<br> </div> Fri, 30 Sep 2022 14:43:15 +0000 why blocking sigint ? https://lwn.net/Articles/909948/ https://lwn.net/Articles/909948/ ballombe <div class="FormattedComment"> Why would a program blocks SIGINT ?<br> I can understand installing a signal handler, but blocking it outright ?<br> This does not seems very user friendly.<br> </div> Fri, 30 Sep 2022 14:13:00 +0000 How to fix an ancient GDB problem https://lwn.net/Articles/909931/ https://lwn.net/Articles/909931/ fw <div class="FormattedComment"> When attaching to a running process, you just have to hit Ctrl+C in the terminal running GDB, as before. This mode of operation hasn&#x27;t really suffered from these problems, as far as I understand it.<br> </div> Fri, 30 Sep 2022 13:51:40 +0000 How to fix an ancient GDB problem https://lwn.net/Articles/909927/ https://lwn.net/Articles/909927/ gray_-_wolf <div class="FormattedComment"> I would assume this will work only when starting new process and not when attaching to existing one?<br> </div> Fri, 30 Sep 2022 13:19:12 +0000 How to fix an ancient GDB problem https://lwn.net/Articles/909926/ https://lwn.net/Articles/909926/ gray_-_wolf <div class="FormattedComment"> I&#x27;ve encountered this too (when trying to debug segfaulting of guile itself). Yet another option (that I&#x27;ve used) is to just continue over the initial segfault. Worked for me.<br> </div> Fri, 30 Sep 2022 13:17:25 +0000 How to fix an ancient GDB problem https://lwn.net/Articles/909906/ https://lwn.net/Articles/909906/ kleptog <div class="FormattedComment"> Sounds like what we really need is is to be able to attach an eBPF program to the PTY that can manipulate the I/O and customise the signal handling/generation.<br> <p> I&#x27;m only half joking.<br> </div> Fri, 30 Sep 2022 08:24:06 +0000 How to fix an ancient GDB problem https://lwn.net/Articles/909905/ https://lwn.net/Articles/909905/ rwmj <div class="FormattedComment"> Perhaps I misunderstand how this works, but if GDB connects to or disconnects from an existing process is it able to change the process&#x27;s terminal to the new pty and then reset it back to the regular terminal later?<br> </div> Fri, 30 Sep 2022 07:53:40 +0000 How to fix an ancient GDB problem https://lwn.net/Articles/909903/ https://lwn.net/Articles/909903/ fw The segfault when running GDB under GDB might come from Guile support, or more precisely, from the Boehm-Demers-Weiser garbage collector library Guile uses: in some version, that library probes mapping boundaries, deliberately triggering segfaults, rather than enumerating shared objects using the <code>dl_iterate_phdr</code> function. If that's indeed the problem you could build GDB without Guile support, or apply this <a href="https://github.com/ivmai/bdwgc/commit/c9b3ca8fab74673b8cf5d89cf6d2b5a4375c0732">garbage collector patch</a>. Fri, 30 Sep 2022 07:36:55 +0000 How to fix an ancient GDB problem https://lwn.net/Articles/909893/ https://lwn.net/Articles/909893/ nyanpasu64 <div class="FormattedComment"> My personal experience with a possibly-related bug: when debugging programs which handle Ctrl+C themselves (like PipeWire and Audacious), pressing Ctrl+C will trigger the app&#x27;s graceful shutdown process (terminating execution) rather than breaking into the debugger like I want. Will the changes to gdb fix this issue?<br> <p> Also is &quot;a GDB command that allows the user to specify which key should interrupt the process and return to the GDB prompt&quot; already present, or will it be added in the rewrite?<br> </div> Fri, 30 Sep 2022 02:53:04 +0000 How to fix an ancient GDB problem https://lwn.net/Articles/909886/ https://lwn.net/Articles/909886/ dullfire <div class="FormattedComment"> Wow. I&#x27;ve long felt gdb to be extremely unstable. I suspect much of it was this bug. I have tried digging into the issues... however getting into cases were gdb segfaults... And attempting to run gdb under gdb yields the top level gdb segfault... is NOT a happy place to be (the segfaults are definitely unrelated to this... and sadly I never managed to figure out was causing them).<br> <p> <p> Anyhow, This is sure to make my debugging time less of &quot;fury/anguish at my debugging tools&quot;. Thanks for the explanation and write up. <br> </div> Thu, 29 Sep 2022 22:41:51 +0000