SlideShare a Scribd company logo
1 of 36
Download to read offline
Redesigning GDB's Ctrl-C
handling
GNU Cauldron 2022
Pedro Alves
2 |
Cautionary Statement
This presentation contains forward-looking statements concerning Advanced Micro Devices, Inc. (AMD) such AMD’s vision, mission and focus; AMD’s market
opportunity and total addressable markets; AMD’s technology and architecture roadmaps; the features, functionality, performance, availability, timing and expected
benefits of future AMD products and product roadmaps; AMD’s path forward in data center, PCs and gaming; AMD’s market and financial momentum; and the
expected benefits from the acquisition of Xilinx, Inc., which are made pursuant to the Safe Harbor provisions of the Private Securities Litigation Reform Act of 1995.
Forward-looking statements are commonly identified by words such as "would," "may," "expects," "believes," "plans," "intends," "projects" and other terms with
similar meaning. Investors are cautioned that the forward-looking statements in this presentation are based on current beliefs, assumptions and expectations, speak
only as of the date of this presentation and involve risks and uncertainties that could cause actual results to differ materially from current expectations. Such
statements are subject to certain known and unknown risks and uncertainties, many of which are difficult to predict and generally beyond AMD's control, that could
cause actual results and other future events to differ materially from those expressed in, or implied or projected by, the forward-looking information and statements.
Investors are urged to review in detail the risks and uncertainties in AMD’s Securities and Exchange Commission filings, including but not limited to AMD’s most
recent reports on Forms 10-K and 10-Q. AMD does not assume, and hereby disclaims, any obligation to update forward-looking statements made in this
presentation, except as may be required by law.
3 |
Problem statement & Outline
On GNU/Linux GDB, it is not possible to use Ctrl-C to interrupt programs that block SIGINT:
• Type Ctrl-C => nothing happens, the debug session gets stuck
• In some cases, it is not possible to get back the prompt
Talk outline:
• Explain why that does not work
• Why this turned out important for the AMD GPU target
• The plan to fix it
4 |
First, a quick Unix process model primer
• A session is UNIX's way of grouping processes that share a controlling tty
• A session can have a controlling tty ("teletype", aka, terminal)
• A session contains process groups
• A process group contains processes
• At most one process group in a session can be a foreground process group
• Typing the interrupt character on a tty => kernel sends SIGINT to:
• all processes of the foreground process group
• in the session (if any)
• which has that tty as controlling tty
• The default interrupt character is ^C (Ctrl-C)
• Can change with e.g., "$ stty intr ^G"
5 |
SIGINT blocked example
int main () {
/* Block SIGINT. */
sigset_t new_mask;
sigaddset (&new_mask, SIGINT);
sigprocmask (SIG_BLOCK, &new_mask, NULL);
while (true) {
sleep (1);
}
}
(gdb) r
Starting program: sigint-blocked
^C^C^C
*nothing*
6 |
sigwait example
int main () {
/* Block SIGINT. */
sigset_t new_mask;
sigaddset (&new_mask, SIGINT);
sigprocmask (SIG_BLOCK, &new_mask, NULL);
/* Make sigwait wait for all signals. */
sigset_t signal_set;
int sig;
sigfillset (&signal_set);
sigwait (&signal_set, &sig);
}
(gdb) r
Starting program: sigwait
^C
[Inferior 1 (process 2585683)
exited normally]
(gdb)
Same thing with signalfd
Bug 9425 - When using "sigwait" GDB doesn'ttrap SIGINT.
Ctrl+C terminates program when should break gdb
First reported on 2007-09-20:
https://sourceware.org/bugzilla/show_bug.cgi?id=9425
Rejected as kernel problem:
https://bugzilla.kernel.org/show_bug.cgi?id=9039#c1
7 |
What is Ctrl-C supposed to be under GDB?
Ctrl-C has "supervisor" role in GDB
• GDB action vs action on inferior
Ctrl-C when running under GDB is:
• "please ask GDB to stop the program so I can inspect it"
• not: "kill the program" (as in, send-signal-kill)
Note how default is to not pass SIGINT => consistent with above view:
• 'c' after Ctrl-C resumes inferior rather than killing it
• must explicitly use 'kill' or 'signal' after a Ctrl-C to interrupt the child process (vs just stop it)
8 |
Problem is consequence of how GDB implements Ctrl-C
• When GDB spawns a new process, it:
• starts the process in the same terminal as GDB
• puts it in a new process group
• makes that the foreground process group in the session
• When the process is running, e.g., after "continue"
• GDB put the inferior's process group in the foreground
• the user types Ctrl-C - kernel sends a SIGINT to the foreground process group (the inferior)
• GDB intercepts the SIGINT via ptrace before inferior sees it
• GDB stops all the other threads of the inferior (if all-stop)
• GDB presents the "Program received SIGINT" stop to the user
• If SIGINT is masked out, signal is left pending, not delivered
• If program is using sigwait, a pending SIGINT is consumed, but not delivered
9 |
GDB / Inferior share terminal (GDB juggles terminal settings)
GDB
Inferior
process
GDB's
terminal
fork()/exec()
stdout
stderr
stdin
User
keyboard input
terminal output • GDB and inferior share the session / terminal
• GDB puts inferior in a new process group
• GDB saves/restores gdb/inferior terminal settings appropriately
stdout
stderr
stdin
10 |
Inferior
process
GDB / Inferior share terminal (GDB in foreground)
GDB
GDB's
terminal
2. SIGINT
aborts/quits
current
command
User
1. Ctrl-C • GDB is in the foreground (user can type GDB commands)
• Readline terminal settings apply
• Ctrl-C => SIGINT to GDB
• SIGINT handler sets global quit_flag flag
• Mainline code calls QUIT macro, which aborts current command
• QUIT macro calls sprinkled throughout GDB, in loops
11 |
GDB / Inferior share terminal (Inferior in foreground)
GDB
Inferior
process
GDB's
terminal
User
1. Ctrl-C
0. After "(gdb) c":
• GDB restores inferior terminal settings
• Inferior is put in the foreground
• Ctrl-C results in SIGINT sent to inferior
2. SIGINT
Kernel sends SIGINT to
terminal's foreground progress
group
3. SIGCHLD
• ptrace intercepts SIGINT, stops thread, and
wakes ptracer via SIGCHLD
• gdb:
1. calls waitpid and learns about SIGINT
stop
2. stops all threads (if all-stop mode)
3. presents "Program received SIGINT"
4. saves inferior terminal settings
5. restores its own terminal settings
6. puts itself in foreground (back to
previous slide)
12 |
GDB / Inferior share terminal (Inferior in foreground, SIGINT blocked)
GDB
Inferior
process
GDB's
terminal
User
1. Ctrl-C
0. After "(gdb) c", and SIGINT is blocked in inferior:
• GDB restores inferior terminal settings
• Inferior is put in the foreground
• Ctrl-C results in SIGINT pending in inferior, but not delivered
2. SIGINT
Kernel sends SIGINT to terminal's foreground progress group
But, signal remains pending, never delivered...
Thus, ptrace never intercepts it
13 |
GDB / Inferior share terminal (Inferior in foreground, sigwait)
GDB
Inferior
process
GDB's
terminal
User
1. Ctrl-C
0. After "(gdb) c", and inferior uses sigwait:
• GDB restores inferior terminal settings
• Inferior is put in the foreground
• Ctrl-C results in SIGINT queued in inferior, but not delivered
2. SIGINT
Kernel sends SIGINT to terminal's foreground progress group
sigwait consumes pending signal, technically signal is never delivered...
Thus, ptrace does not intercept it
14 |
Ctrl-C and AMDGPU – why important?
(gdb) info threads
Id Target Id Frame
1 Thread ... (LWP 476966) main () from libhsa-runtime64.so.1
2 Thread ... (LWP 476969) in ioctl () at syscall-template.S:78
4 Thread ... (LWP 477504) in ioctl () at syscall-template.S:78
* 5 AMDGPU Wave 1:1:1:1 (0,0,0)/0 my_kernel () at kernel.cc:41
…
• Kernel sends SIGINT to process (host side)
• But all host threads are stopped
• ptrace will not intercept the SIGINT, until a
host thread is resumed, and the
signal delivered
• But user does not have prompt, so, hang...
(gdb) set scheduler-locking on
(gdb) thread 5 # a GPU thread
(gdb) c
^C^C^C^C^C^C^C^C^C^C^C
* nothing, no way to get back the prompt *
15 |
The Fix – give inferiors their own tty
Make SIGINT always reach GDB first, not the inferior
Put inferiors in their own terminal/session created by GDB
• no need to juggle inferior terminal's settings
That is:
• GDB creates a pseudo-terminal (pty) master/slave pair
• GDB makes the inferior run with the pty slave as its terminal
• GDB pumps output/input on the pty master end.
Since:
• inferior has own session/terminal => GDB's remains the foreground process in its terminal
• Ctrl-C SIGINT always reaches GDB first, since GDB is in the terminal's foreground
GDB is then free to handle SIGINT and interrupting the program any way it sees fit
16 |
Before: GDB / Inferior share terminal
GDB
Inferior
process
GDB's
terminal
fork()/exec()
stdout
stderr
stdin
User
keyboard input
terminal output • GDB and inferior share the session / terminal
• GDB puts inferior in a new process group
• GDB saves/restores gdb/inferior terminal settings appropriately
stdout
stderr
stdin
17 |
After: Inferior is given its own terminal (GDB forwards I/O)
GDB
Inferior
process
Pseudo terminal
slave
(/dev/pts/...)
Pseudo terminal
master
GDB's
terminal
fork()/exec()
stdout
stderr
stdin
stdout
stderr
stdin
write()
read()
User
keyboard input
terminal output • Inferior PTY has its own terminal settings, GDB doesn't need to
save/restore them
• GDB's tty must be in raw mode when forwarding input/output, so
that escape codes, rn, etc. are fully forwarded uninterpreted
18 |
Ctrl-C in GDB's terminal always reaches GDB
GDB
Inferior
process
Pseudo terminal
slave
(/dev/pts/...)
GDB's
terminal
3. GDB
stops process
2. SIGINT
User
1. Ctrl-C
• Inferior is in foreground of its own terminal
• GDB is in foreground of its own terminal
(More about stopping inferior later)
19 |
I/O forwarding (output)
1. Open an unused pty master/slave pair using standard posix_openpt / grantpt / unlockpt
2. Start inferior with pty slave as terminal (as if "(gdb) tty $PTY_SLAVE_NAME")
3. Register master end of pty in the event loop
• inferior writes to its terminal
=> event loop wakes up and handler flushes inferior output to GDB's stdout
That handles output. But what about input?
20 |
I/O forwarding (input)
Input when GDB has the prompt != Input when the inferior is running
GDB already has logic to switch terminal modes at the right spots depending on
whether GDB or the inferior "have the terminal":
a) target_terminal::inferior() -> child_terminal_inferior()
1. Set stdin to raw mode
2. Register stdin-forwarder handler in the event loop
b) target_terminal::ours() -> child_terminal_ours()
1. Delete stdin-forwarder handler from the event loop and restore readline terminal settings
2. async_enable_stdin later re-installs GDB's normal stdin->readline event-loop handler, when it's time to show the
prompt
21 |
How to tell GDB to spawn inferior in GDB's terminal?
Still useful to be able to tell GDB to spawn inferior in same terminal & session as GDB (like today)
• Say, you want to run + detach, and let the detached inferior continue printing to the terminal
POSIX says "/dev/tty" => terminal for the current process
=> special-casing "set inferior-tty /dev/tty" seemed like an obvious choice
Leaves "(gdb) set inferior-tty" with no arguments free for a different behavior
=> whatever is the default in the platform
22 |
GDB controls when inferior output is flushed to the screen
(gdb) c &
Continuing.
(gdb) help
List of classes of commands:
aliases -- User-defined aliases of other commands.
Hello world!
breakpoints -- Making program stop at certain points.
data -- Examining data.
…
(gdb)
(gdb) c &
Continuing.
(gdb) help
List of classes of commands:
aliases -- User-defined aliases of other commands.
breakpoints -- Making program stop at certain points.
data -- Examining data.
…
(gdb)
Hello world!
Avoids inferior output being interspersed with GDB's output (background/non-stop mode)
• Inferior output is never flushed while GDB is printing something itself
• E.g., "help" while inferior is running
Before: After:
23 |
TUI & inferior output flushing
With the TUI:
• could hook in tui_puts, instead of inferior outputting to screen directly
• we could even redirect inferior I/O to its own TUI window if we wanted
• no more need for Ctrl-L to refresh the screen
Debugging curses programs with the TUI would no longer work as today, though
=> ASCII escape sequence wouldn't be interpreted by the TUI's command window...
Unless... we made TUI's command window a real terminal emulator. :-)
=> TUI within the TUI within the TUI?
Still, that limitation wouldn't seem too important for non-gdb hackers?
=> "(gdb) tty /dev/tty"
=> or, run the curses inferior in its own terminal window
24 |
One last problem: session leaders and SIGHUP
Session leaders have special properties:
• session leader exits => SIGHUP to all processes in the foreground process group
Recall primer:
• In Unix every process belongs to a process group which in turn belongs to a session
• Session (SID) → Process Group (PGID) → Process (PID)
More:
• The first process in the process group becomes the process group leader
• The first process in the session becomes the session leader
• Every session can have one TTY associated with it
• Only a session leader can take control of a TTY
25 |
The follow-fork SIGHUP problem
pts/1 pts/2 pts/2
| | |
gdb---fork_parent---fork_child
|
session leader
If the spawned inferior is the session leader itself, and,
- it forks, and,
- if the parent (the session leader) exits,
=> the child gets a SIGHUP (and likely dies)
26 |
After:
1. gdb
|
pts/1
2. gdb(1)---gdb(2)
3. gdb(1)---gdb(2)---gdb(3)
4. gdb(1)---gdb(2)---shell(3)
session leader
|
5. gdb(1)---gdb(2)---inf(3)
| | |
pts/1 pts/2 pts/2
SIGHUP: The fix – apply double-fork technique
Before:
1. gdb(1)
|
pts/1
2. gdb(1)---gdb(2)
3. gdb(1)---shell(2)
4. gdb(1)---inferior(2)
| |
pts/1 pts/1
Make GDB insert a process between
itself and the inferior it first runs, whose
only job is to be the session leader. Akin
to double-fork technique for daemonizing.
Before:
• GDB forks
• child GDB execs the shell
• shell execs the final inferior program
After:
• GDB forks
• child GDB forks again, and parent
becomes session leader process
• grandchild GDB execs the shell
• shell execs the final inferior program
27 |
SIGHUP: The fix, follow-fork scenario
pts/1 pts/2 pts/2 pts/2
| | | |
gdb---gdb---fork_parent---fork_child
|
session leader
Make GDB insert an extra process between itself and
the inferior it first runs, whose only job is to be the
session leader.
Session leader process is not ptraced
Session leader process stays around until both:
1. its child exits
2. gdb closes the inferior's terminal
(It doesn't exit after #1 as there may still be grandchildren
attached to its session)
28 |
The run+detach SIGHUP problem
pts/1 pts/2
| |
gdb- X -inferior
|
session leader
1. (gdb) run
2. (gdb) detach
3. GDB destroys the inferior's terminal (pts/2)
4. detached inferior is session leader and loses terminal
and so gets SIGHUP (and usually dies)
Surprising number of GDB testcases do "run" + "detach"
29 |
SIGHUP: The fix, detach scenario
pts/1 pts/2 pts/2
| | |
gdb- X -gdb---inferior
|
session leader
1. (gdb) run
2. (gdb) detach
3. GDB destroys the inferior's terminal (pts/2)
4. detached inferior remains alive but loses terminal so
output goes nowhere
Detached process no longer gets SIGHUP. Output is lost,
but we could make GDB warn in this situation ("inferior
will lose terminal. Are you sure you want to detach?").
If you really want to be able to run + detach + continue
seeing inferior output, then you really want to run the
inferior in gdb's terminal, as before. You can do that with:
(gdb) tty /dev/tty
This disables the spawning of the extra session-leader
process and reactivates the gdb/inferior terminal settings
juggling.
30 |
Still need to stop inferiors that block SIGINT
Now GDB always sees the Ctrl-C request
We still have the original problem, though – cannot stop inferior with SIGINT if inferior blocks SIGINT
31 |
Fix: Stop inferiors with SIGSTOP
Make GDB stop the inferior with SIGSTOP instead => SIGSTOP is special and cannot be blocked
User-visible behavior change in all-stop mode -- with Ctrl-C, instead of:
Thread 1 "threads" received signal SIGINT, Interrupt.
You'll get:
Thread 1 "threads" stopped.
Which is what you already got with the "interrupt" command in non-stop mode
You can still pass a SIGINT to the program, using:(gdb) signal SIGINT
32 |
Stop inferior with SIGSTOP, continued
The stopping is done from common code, via the existing target_stop
1. Ctrl-C to GDB -> sets quit flag
2. Default quit handler marks infrun event handler for Ctrl-C [new]
3. Infrun's new ctrl-c event handler:
a) if all-stop mode:
1. Synchronously stops all threads
2. If possible, keeps focus on the previously-selected thread [new, not possible before]
3. Presents stop via normal_stop
b) if non-stop mode:
1. Asynchronously stops one thread [preserving behavior], preferentially previously-selected thread [new]
Could change the non-stop behavior: Drop to prompt without stopping anything? Stop the world? Other?
33 |
Upstreaming status
Last version sent to gdb-patches here (2021-06-14):
[PATCH v2 00/16] Interrupting programs that block/ignore SIGINT
https://inbox.sourceware.org/gdb-patches/20210614212410.1612666-1-pedro@palves.net/
Also in the users/palves/ctrl-c branch on sourceware:
https://sourceware.org/git/?p=binutils-gdb.git;a=shortlog;h=refs/heads/users/palves/ctrl-c
Updated series should appear on gdb-patches soon™
34 |
Disclaimer & Attribution
©2022 Advanced Micro Devices, Inc. All rights reserved.
AMD, the AMD Arrow logo, AMD Instinct™, AMD ROCm™, Radeon™, and combinations thereof are trademarks of Advanced Micro Devices, Inc. Other product
names used in this publication are for identification purposes only and may be trademarks of their respective companies.
The information presented in this document is for informational purposes only and may contain technical inaccuracies, omissions, and typographical errors. The
information contained herein is subject to change and may be rendered inaccurate releases, for many reasons, including but not limited to product and roadmap
changes, component and motherboard version changes, new model and/or product differences between differing manufacturers, software changes, BIOS flashes,
firmware upgrades, or the like. Any computer system has risks of security vulnerabilities that cannot be completely prevented or mitigated. AMD assumes no
obligation to update or otherwise correct or revise this information. However, AMD reserves the right to revise this informat
ion and to make changes from time to
time to the content hereof without obligation of AMD to notify any person of such revisions or changes.
THIS INFORMATION IS PROVIDED 'AS IS." AMD MAKES NO REPRESENTATIONS OR WARRANTIES WITH RESPECTTO THE CONTENTS HEREOF AND
ASSUMES NO RESPONSIBILITY FOR ANY INACCURACIES, ERRORS, OR OMISSIONS THAT MAY APPEAR IN THIS INFORMATION. AMD SPECIFICALLY
DISCLAIMS ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY
, OR FITNESS FOR ANY PARTICULAR PURPOSE. IN NO EVENT
WILL AMD BE LIABLE TO ANY PERSON FOR ANY RELIANCE, DIRECT, INDIRECT, SPECIAL, OR OTHER CONSEQUENTIAL DAMAGES ARISING FROM THE
USE OF ANY INFORMATION CONTAINED HEREIN, EVEN IF AMD IS EXPRESSLYADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
36 |
The end, time for questions
Redesigning GDB's Ctrl-C handling

More Related Content

Similar to Ctrl-C redesign for gcc cauldron in 2022 in prague

UWE Linux Boot Camp 2007: Hacking embedded Linux on the cheap
UWE Linux Boot Camp 2007: Hacking embedded Linux on the cheapUWE Linux Boot Camp 2007: Hacking embedded Linux on the cheap
UWE Linux Boot Camp 2007: Hacking embedded Linux on the cheapedlangley
 
Let's trace Linux Lernel with KGDB @ COSCUP 2021
Let's trace Linux Lernel with KGDB @ COSCUP 2021Let's trace Linux Lernel with KGDB @ COSCUP 2021
Let's trace Linux Lernel with KGDB @ COSCUP 2021Jian-Hong Pan
 
Advanced Debugging with GDB
Advanced Debugging with GDBAdvanced Debugging with GDB
Advanced Debugging with GDBDavid Khosid
 
LAS16-403 - GDB Linux Kernel Awareness
LAS16-403 - GDB Linux Kernel Awareness LAS16-403 - GDB Linux Kernel Awareness
LAS16-403 - GDB Linux Kernel Awareness Peter Griffin
 
LAS16-403: GDB Linux Kernel Awareness
LAS16-403: GDB Linux Kernel AwarenessLAS16-403: GDB Linux Kernel Awareness
LAS16-403: GDB Linux Kernel AwarenessLinaro
 
Challenges in GPU compilers
Challenges in GPU compilersChallenges in GPU compilers
Challenges in GPU compilersAnastasiaStulova
 
Debugging Modern C++ Application with Gdb
Debugging Modern C++ Application with GdbDebugging Modern C++ Application with Gdb
Debugging Modern C++ Application with GdbSenthilKumar Selvaraj
 
gdb-tutorial.pdf
gdb-tutorial.pdfgdb-tutorial.pdf
gdb-tutorial.pdfligi14
 
Session1 j2me introduction
Session1  j2me introductionSession1  j2me introduction
Session1 j2me introductionmuthusvm
 
Embedded systems development Defcon 19
Embedded systems development Defcon 19Embedded systems development Defcon 19
Embedded systems development Defcon 19Rodrigo Almeida
 
Graphics Programming OpenGL & GLUT in Code::Blocks
Graphics Programming OpenGL & GLUT in Code::BlocksGraphics Programming OpenGL & GLUT in Code::Blocks
Graphics Programming OpenGL & GLUT in Code::BlocksBudditha Hettige
 
3 Open-Source-SYCL-Intel-Khronos-EVS-Workshop_May19.pdf
3 Open-Source-SYCL-Intel-Khronos-EVS-Workshop_May19.pdf3 Open-Source-SYCL-Intel-Khronos-EVS-Workshop_May19.pdf
3 Open-Source-SYCL-Intel-Khronos-EVS-Workshop_May19.pdfJunZhao68
 
GPGPU: что это такое и для чего. Александр Титов. CoreHard Spring 2019
GPGPU: что это такое и для чего. Александр Титов. CoreHard Spring 2019GPGPU: что это такое и для чего. Александр Титов. CoreHard Spring 2019
GPGPU: что это такое и для чего. Александр Титов. CoreHard Spring 2019corehard_by
 
Debugging embedded devices using GDB
Debugging embedded devices using GDBDebugging embedded devices using GDB
Debugging embedded devices using GDBChris Simmonds
 
2-GPGPU-Sim-Overview.pptx
2-GPGPU-Sim-Overview.pptx2-GPGPU-Sim-Overview.pptx
2-GPGPU-Sim-Overview.pptxYonggangLiu3
 
Avoiding Catastrophic Performance Loss
Avoiding Catastrophic Performance LossAvoiding Catastrophic Performance Loss
Avoiding Catastrophic Performance Lossbasisspace
 
CNC 3-Axis Stepper Motor Shield
CNC 3-Axis Stepper Motor ShieldCNC 3-Axis Stepper Motor Shield
CNC 3-Axis Stepper Motor Shieldhandson28
 

Similar to Ctrl-C redesign for gcc cauldron in 2022 in prague (20)

UWE Linux Boot Camp 2007: Hacking embedded Linux on the cheap
UWE Linux Boot Camp 2007: Hacking embedded Linux on the cheapUWE Linux Boot Camp 2007: Hacking embedded Linux on the cheap
UWE Linux Boot Camp 2007: Hacking embedded Linux on the cheap
 
Let's trace Linux Lernel with KGDB @ COSCUP 2021
Let's trace Linux Lernel with KGDB @ COSCUP 2021Let's trace Linux Lernel with KGDB @ COSCUP 2021
Let's trace Linux Lernel with KGDB @ COSCUP 2021
 
Advanced Debugging with GDB
Advanced Debugging with GDBAdvanced Debugging with GDB
Advanced Debugging with GDB
 
LAS16-403 - GDB Linux Kernel Awareness
LAS16-403 - GDB Linux Kernel Awareness LAS16-403 - GDB Linux Kernel Awareness
LAS16-403 - GDB Linux Kernel Awareness
 
LAS16-403: GDB Linux Kernel Awareness
LAS16-403: GDB Linux Kernel AwarenessLAS16-403: GDB Linux Kernel Awareness
LAS16-403: GDB Linux Kernel Awareness
 
Challenges in GPU compilers
Challenges in GPU compilersChallenges in GPU compilers
Challenges in GPU compilers
 
Debugging Modern C++ Application with Gdb
Debugging Modern C++ Application with GdbDebugging Modern C++ Application with Gdb
Debugging Modern C++ Application with Gdb
 
gdb-tutorial.pdf
gdb-tutorial.pdfgdb-tutorial.pdf
gdb-tutorial.pdf
 
Session1 j2me introduction
Session1  j2me introductionSession1  j2me introduction
Session1 j2me introduction
 
Gpgpu
GpgpuGpgpu
Gpgpu
 
Embedded systems development Defcon 19
Embedded systems development Defcon 19Embedded systems development Defcon 19
Embedded systems development Defcon 19
 
Graphics Programming OpenGL & GLUT in Code::Blocks
Graphics Programming OpenGL & GLUT in Code::BlocksGraphics Programming OpenGL & GLUT in Code::Blocks
Graphics Programming OpenGL & GLUT in Code::Blocks
 
3 Open-Source-SYCL-Intel-Khronos-EVS-Workshop_May19.pdf
3 Open-Source-SYCL-Intel-Khronos-EVS-Workshop_May19.pdf3 Open-Source-SYCL-Intel-Khronos-EVS-Workshop_May19.pdf
3 Open-Source-SYCL-Intel-Khronos-EVS-Workshop_May19.pdf
 
GPGPU: что это такое и для чего. Александр Титов. CoreHard Spring 2019
GPGPU: что это такое и для чего. Александр Титов. CoreHard Spring 2019GPGPU: что это такое и для чего. Александр Титов. CoreHard Spring 2019
GPGPU: что это такое и для чего. Александр Титов. CoreHard Spring 2019
 
Debugging embedded devices using GDB
Debugging embedded devices using GDBDebugging embedded devices using GDB
Debugging embedded devices using GDB
 
2-GPGPU-Sim-Overview.pptx
2-GPGPU-Sim-Overview.pptx2-GPGPU-Sim-Overview.pptx
2-GPGPU-Sim-Overview.pptx
 
CADM4.pptx
CADM4.pptxCADM4.pptx
CADM4.pptx
 
Avoiding Catastrophic Performance Loss
Avoiding Catastrophic Performance LossAvoiding Catastrophic Performance Loss
Avoiding Catastrophic Performance Loss
 
CNC 3-Axis Stepper Motor Shield
CNC 3-Axis Stepper Motor ShieldCNC 3-Axis Stepper Motor Shield
CNC 3-Axis Stepper Motor Shield
 
Introduction to Blackfin BF532 DSP
Introduction to Blackfin BF532 DSPIntroduction to Blackfin BF532 DSP
Introduction to Blackfin BF532 DSP
 

More from ssuser866937

GNU Toolchain Infrastructure at gcc cauldron
GNU Toolchain Infrastructure at gcc cauldronGNU Toolchain Infrastructure at gcc cauldron
GNU Toolchain Infrastructure at gcc cauldronssuser866937
 
cauldron-2022-docs-bof at gcc cauldron in 2022
cauldron-2022-docs-bof at gcc cauldron in 2022cauldron-2022-docs-bof at gcc cauldron in 2022
cauldron-2022-docs-bof at gcc cauldron in 2022ssuser866937
 
Cauldron_2022_ctf_frame at gcc cauldron 2022 in prague
Cauldron_2022_ctf_frame at gcc cauldron 2022 in pragueCauldron_2022_ctf_frame at gcc cauldron 2022 in prague
Cauldron_2022_ctf_frame at gcc cauldron 2022 in praguessuser866937
 
BoF-OpenMP-OpenACC-Offloading-Cauldron2022.pdf
BoF-OpenMP-OpenACC-Offloading-Cauldron2022.pdfBoF-OpenMP-OpenACC-Offloading-Cauldron2022.pdf
BoF-OpenMP-OpenACC-Offloading-Cauldron2022.pdfssuser866937
 
2022-ranger-update-Cauldron for gcc versions
2022-ranger-update-Cauldron for gcc versions2022-ranger-update-Cauldron for gcc versions
2022-ranger-update-Cauldron for gcc versionsssuser866937
 
2022 Cauldron Value Numbering for gcc versions
2022 Cauldron Value Numbering for gcc versions2022 Cauldron Value Numbering for gcc versions
2022 Cauldron Value Numbering for gcc versionsssuser866937
 
2022-Cauldron-If-Conversion-for-a-Partially-Predicated-VLIW-Architecture.pdf
2022-Cauldron-If-Conversion-for-a-Partially-Predicated-VLIW-Architecture.pdf2022-Cauldron-If-Conversion-for-a-Partially-Predicated-VLIW-Architecture.pdf
2022-Cauldron-If-Conversion-for-a-Partially-Predicated-VLIW-Architecture.pdfssuser866937
 
2022 Cauldron analyzer talk from david malcolm
2022 Cauldron analyzer talk from david malcolm2022 Cauldron analyzer talk from david malcolm
2022 Cauldron analyzer talk from david malcolmssuser866937
 
cs.ds-2211.13454.pdf
cs.ds-2211.13454.pdfcs.ds-2211.13454.pdf
cs.ds-2211.13454.pdfssuser866937
 

More from ssuser866937 (9)

GNU Toolchain Infrastructure at gcc cauldron
GNU Toolchain Infrastructure at gcc cauldronGNU Toolchain Infrastructure at gcc cauldron
GNU Toolchain Infrastructure at gcc cauldron
 
cauldron-2022-docs-bof at gcc cauldron in 2022
cauldron-2022-docs-bof at gcc cauldron in 2022cauldron-2022-docs-bof at gcc cauldron in 2022
cauldron-2022-docs-bof at gcc cauldron in 2022
 
Cauldron_2022_ctf_frame at gcc cauldron 2022 in prague
Cauldron_2022_ctf_frame at gcc cauldron 2022 in pragueCauldron_2022_ctf_frame at gcc cauldron 2022 in prague
Cauldron_2022_ctf_frame at gcc cauldron 2022 in prague
 
BoF-OpenMP-OpenACC-Offloading-Cauldron2022.pdf
BoF-OpenMP-OpenACC-Offloading-Cauldron2022.pdfBoF-OpenMP-OpenACC-Offloading-Cauldron2022.pdf
BoF-OpenMP-OpenACC-Offloading-Cauldron2022.pdf
 
2022-ranger-update-Cauldron for gcc versions
2022-ranger-update-Cauldron for gcc versions2022-ranger-update-Cauldron for gcc versions
2022-ranger-update-Cauldron for gcc versions
 
2022 Cauldron Value Numbering for gcc versions
2022 Cauldron Value Numbering for gcc versions2022 Cauldron Value Numbering for gcc versions
2022 Cauldron Value Numbering for gcc versions
 
2022-Cauldron-If-Conversion-for-a-Partially-Predicated-VLIW-Architecture.pdf
2022-Cauldron-If-Conversion-for-a-Partially-Predicated-VLIW-Architecture.pdf2022-Cauldron-If-Conversion-for-a-Partially-Predicated-VLIW-Architecture.pdf
2022-Cauldron-If-Conversion-for-a-Partially-Predicated-VLIW-Architecture.pdf
 
2022 Cauldron analyzer talk from david malcolm
2022 Cauldron analyzer talk from david malcolm2022 Cauldron analyzer talk from david malcolm
2022 Cauldron analyzer talk from david malcolm
 
cs.ds-2211.13454.pdf
cs.ds-2211.13454.pdfcs.ds-2211.13454.pdf
cs.ds-2211.13454.pdf
 

Recently uploaded

Call Girls in Uttam Nagar Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Uttam Nagar Delhi 💯Call Us 🔝8264348440🔝Call Girls in Uttam Nagar Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Uttam Nagar Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
Russian Call Girls in Kolkata Samaira 🤌 8250192130 🚀 Vip Call Girls Kolkata
Russian Call Girls in Kolkata Samaira 🤌  8250192130 🚀 Vip Call Girls KolkataRussian Call Girls in Kolkata Samaira 🤌  8250192130 🚀 Vip Call Girls Kolkata
Russian Call Girls in Kolkata Samaira 🤌 8250192130 🚀 Vip Call Girls Kolkataanamikaraghav4
 
On Starlink, presented by Geoff Huston at NZNOG 2024
On Starlink, presented by Geoff Huston at NZNOG 2024On Starlink, presented by Geoff Huston at NZNOG 2024
On Starlink, presented by Geoff Huston at NZNOG 2024APNIC
 
VIP Kolkata Call Girls Salt Lake 8250192130 Available With Room
VIP Kolkata Call Girls Salt Lake 8250192130 Available With RoomVIP Kolkata Call Girls Salt Lake 8250192130 Available With Room
VIP Kolkata Call Girls Salt Lake 8250192130 Available With Roomgirls4nights
 
VIP Call Girls Pune Madhuri 8617697112 Independent Escort Service Pune
VIP Call Girls Pune Madhuri 8617697112 Independent Escort Service PuneVIP Call Girls Pune Madhuri 8617697112 Independent Escort Service Pune
VIP Call Girls Pune Madhuri 8617697112 Independent Escort Service PuneCall girls in Ahmedabad High profile
 
10.pdfMature Call girls in Dubai +971563133746 Dubai Call girls
10.pdfMature Call girls in Dubai +971563133746 Dubai Call girls10.pdfMature Call girls in Dubai +971563133746 Dubai Call girls
10.pdfMature Call girls in Dubai +971563133746 Dubai Call girlsstephieert
 
FULL ENJOY Call Girls In Mayur Vihar Delhi Contact Us 8377087607
FULL ENJOY Call Girls In Mayur Vihar Delhi Contact Us 8377087607FULL ENJOY Call Girls In Mayur Vihar Delhi Contact Us 8377087607
FULL ENJOY Call Girls In Mayur Vihar Delhi Contact Us 8377087607dollysharma2066
 
'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...
'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...
'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...APNIC
 
Russian Call Girls Thane Swara 8617697112 Independent Escort Service Thane
Russian Call Girls Thane Swara 8617697112 Independent Escort Service ThaneRussian Call Girls Thane Swara 8617697112 Independent Escort Service Thane
Russian Call Girls Thane Swara 8617697112 Independent Escort Service ThaneCall girls in Ahmedabad High profile
 
Low Rate Call Girls Kolkata Avani 🤌 8250192130 🚀 Vip Call Girls Kolkata
Low Rate Call Girls Kolkata Avani 🤌  8250192130 🚀 Vip Call Girls KolkataLow Rate Call Girls Kolkata Avani 🤌  8250192130 🚀 Vip Call Girls Kolkata
Low Rate Call Girls Kolkata Avani 🤌 8250192130 🚀 Vip Call Girls Kolkataanamikaraghav4
 
Packaging the Monolith - PHP Tek 2024 (Breaking it down one bite at a time)
Packaging the Monolith - PHP Tek 2024 (Breaking it down one bite at a time)Packaging the Monolith - PHP Tek 2024 (Breaking it down one bite at a time)
Packaging the Monolith - PHP Tek 2024 (Breaking it down one bite at a time)Dana Luther
 
Call Girls In Saket Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Saket Delhi 💯Call Us 🔝8264348440🔝Call Girls In Saket Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Saket Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
Hot Service (+9316020077 ) Goa Call Girls Real Photos and Genuine Service
Hot Service (+9316020077 ) Goa  Call Girls Real Photos and Genuine ServiceHot Service (+9316020077 ) Goa  Call Girls Real Photos and Genuine Service
Hot Service (+9316020077 ) Goa Call Girls Real Photos and Genuine Servicesexy call girls service in goa
 
VIP Kolkata Call Girl Dum Dum 👉 8250192130 Available With Room
VIP Kolkata Call Girl Dum Dum 👉 8250192130  Available With RoomVIP Kolkata Call Girl Dum Dum 👉 8250192130  Available With Room
VIP Kolkata Call Girl Dum Dum 👉 8250192130 Available With Roomdivyansh0kumar0
 
AWS Community DAY Albertini-Ellan Cloud Security (1).pptx
AWS Community DAY Albertini-Ellan Cloud Security (1).pptxAWS Community DAY Albertini-Ellan Cloud Security (1).pptx
AWS Community DAY Albertini-Ellan Cloud Security (1).pptxellan12
 
How is AI changing journalism? (v. April 2024)
How is AI changing journalism? (v. April 2024)How is AI changing journalism? (v. April 2024)
How is AI changing journalism? (v. April 2024)Damian Radcliffe
 
₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...
₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...
₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...Diya Sharma
 

Recently uploaded (20)

Call Girls in Uttam Nagar Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Uttam Nagar Delhi 💯Call Us 🔝8264348440🔝Call Girls in Uttam Nagar Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Uttam Nagar Delhi 💯Call Us 🔝8264348440🔝
 
Russian Call Girls in Kolkata Samaira 🤌 8250192130 🚀 Vip Call Girls Kolkata
Russian Call Girls in Kolkata Samaira 🤌  8250192130 🚀 Vip Call Girls KolkataRussian Call Girls in Kolkata Samaira 🤌  8250192130 🚀 Vip Call Girls Kolkata
Russian Call Girls in Kolkata Samaira 🤌 8250192130 🚀 Vip Call Girls Kolkata
 
On Starlink, presented by Geoff Huston at NZNOG 2024
On Starlink, presented by Geoff Huston at NZNOG 2024On Starlink, presented by Geoff Huston at NZNOG 2024
On Starlink, presented by Geoff Huston at NZNOG 2024
 
VIP Kolkata Call Girls Salt Lake 8250192130 Available With Room
VIP Kolkata Call Girls Salt Lake 8250192130 Available With RoomVIP Kolkata Call Girls Salt Lake 8250192130 Available With Room
VIP Kolkata Call Girls Salt Lake 8250192130 Available With Room
 
VIP Call Girls Pune Madhuri 8617697112 Independent Escort Service Pune
VIP Call Girls Pune Madhuri 8617697112 Independent Escort Service PuneVIP Call Girls Pune Madhuri 8617697112 Independent Escort Service Pune
VIP Call Girls Pune Madhuri 8617697112 Independent Escort Service Pune
 
10.pdfMature Call girls in Dubai +971563133746 Dubai Call girls
10.pdfMature Call girls in Dubai +971563133746 Dubai Call girls10.pdfMature Call girls in Dubai +971563133746 Dubai Call girls
10.pdfMature Call girls in Dubai +971563133746 Dubai Call girls
 
FULL ENJOY Call Girls In Mayur Vihar Delhi Contact Us 8377087607
FULL ENJOY Call Girls In Mayur Vihar Delhi Contact Us 8377087607FULL ENJOY Call Girls In Mayur Vihar Delhi Contact Us 8377087607
FULL ENJOY Call Girls In Mayur Vihar Delhi Contact Us 8377087607
 
'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...
'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...
'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...
 
Russian Call Girls Thane Swara 8617697112 Independent Escort Service Thane
Russian Call Girls Thane Swara 8617697112 Independent Escort Service ThaneRussian Call Girls Thane Swara 8617697112 Independent Escort Service Thane
Russian Call Girls Thane Swara 8617697112 Independent Escort Service Thane
 
Low Rate Call Girls Kolkata Avani 🤌 8250192130 🚀 Vip Call Girls Kolkata
Low Rate Call Girls Kolkata Avani 🤌  8250192130 🚀 Vip Call Girls KolkataLow Rate Call Girls Kolkata Avani 🤌  8250192130 🚀 Vip Call Girls Kolkata
Low Rate Call Girls Kolkata Avani 🤌 8250192130 🚀 Vip Call Girls Kolkata
 
Model Call Girl in Jamuna Vihar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in  Jamuna Vihar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in  Jamuna Vihar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Jamuna Vihar Delhi reach out to us at 🔝9953056974🔝
 
Packaging the Monolith - PHP Tek 2024 (Breaking it down one bite at a time)
Packaging the Monolith - PHP Tek 2024 (Breaking it down one bite at a time)Packaging the Monolith - PHP Tek 2024 (Breaking it down one bite at a time)
Packaging the Monolith - PHP Tek 2024 (Breaking it down one bite at a time)
 
Call Girls In Saket Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Saket Delhi 💯Call Us 🔝8264348440🔝Call Girls In Saket Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Saket Delhi 💯Call Us 🔝8264348440🔝
 
Hot Service (+9316020077 ) Goa Call Girls Real Photos and Genuine Service
Hot Service (+9316020077 ) Goa  Call Girls Real Photos and Genuine ServiceHot Service (+9316020077 ) Goa  Call Girls Real Photos and Genuine Service
Hot Service (+9316020077 ) Goa Call Girls Real Photos and Genuine Service
 
Rohini Sector 6 Call Girls Delhi 9999965857 @Sabina Saikh No Advance
Rohini Sector 6 Call Girls Delhi 9999965857 @Sabina Saikh No AdvanceRohini Sector 6 Call Girls Delhi 9999965857 @Sabina Saikh No Advance
Rohini Sector 6 Call Girls Delhi 9999965857 @Sabina Saikh No Advance
 
VIP Kolkata Call Girl Dum Dum 👉 8250192130 Available With Room
VIP Kolkata Call Girl Dum Dum 👉 8250192130  Available With RoomVIP Kolkata Call Girl Dum Dum 👉 8250192130  Available With Room
VIP Kolkata Call Girl Dum Dum 👉 8250192130 Available With Room
 
AWS Community DAY Albertini-Ellan Cloud Security (1).pptx
AWS Community DAY Albertini-Ellan Cloud Security (1).pptxAWS Community DAY Albertini-Ellan Cloud Security (1).pptx
AWS Community DAY Albertini-Ellan Cloud Security (1).pptx
 
How is AI changing journalism? (v. April 2024)
How is AI changing journalism? (v. April 2024)How is AI changing journalism? (v. April 2024)
How is AI changing journalism? (v. April 2024)
 
₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...
₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...
₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...
 
Dwarka Sector 26 Call Girls | Delhi | 9999965857 🫦 Vanshika Verma More Our Se...
Dwarka Sector 26 Call Girls | Delhi | 9999965857 🫦 Vanshika Verma More Our Se...Dwarka Sector 26 Call Girls | Delhi | 9999965857 🫦 Vanshika Verma More Our Se...
Dwarka Sector 26 Call Girls | Delhi | 9999965857 🫦 Vanshika Verma More Our Se...
 

Ctrl-C redesign for gcc cauldron in 2022 in prague

  • 1. Redesigning GDB's Ctrl-C handling GNU Cauldron 2022 Pedro Alves
  • 2. 2 | Cautionary Statement This presentation contains forward-looking statements concerning Advanced Micro Devices, Inc. (AMD) such AMD’s vision, mission and focus; AMD’s market opportunity and total addressable markets; AMD’s technology and architecture roadmaps; the features, functionality, performance, availability, timing and expected benefits of future AMD products and product roadmaps; AMD’s path forward in data center, PCs and gaming; AMD’s market and financial momentum; and the expected benefits from the acquisition of Xilinx, Inc., which are made pursuant to the Safe Harbor provisions of the Private Securities Litigation Reform Act of 1995. Forward-looking statements are commonly identified by words such as "would," "may," "expects," "believes," "plans," "intends," "projects" and other terms with similar meaning. Investors are cautioned that the forward-looking statements in this presentation are based on current beliefs, assumptions and expectations, speak only as of the date of this presentation and involve risks and uncertainties that could cause actual results to differ materially from current expectations. Such statements are subject to certain known and unknown risks and uncertainties, many of which are difficult to predict and generally beyond AMD's control, that could cause actual results and other future events to differ materially from those expressed in, or implied or projected by, the forward-looking information and statements. Investors are urged to review in detail the risks and uncertainties in AMD’s Securities and Exchange Commission filings, including but not limited to AMD’s most recent reports on Forms 10-K and 10-Q. AMD does not assume, and hereby disclaims, any obligation to update forward-looking statements made in this presentation, except as may be required by law.
  • 3. 3 | Problem statement & Outline On GNU/Linux GDB, it is not possible to use Ctrl-C to interrupt programs that block SIGINT: • Type Ctrl-C => nothing happens, the debug session gets stuck • In some cases, it is not possible to get back the prompt Talk outline: • Explain why that does not work • Why this turned out important for the AMD GPU target • The plan to fix it
  • 4. 4 | First, a quick Unix process model primer • A session is UNIX's way of grouping processes that share a controlling tty • A session can have a controlling tty ("teletype", aka, terminal) • A session contains process groups • A process group contains processes • At most one process group in a session can be a foreground process group • Typing the interrupt character on a tty => kernel sends SIGINT to: • all processes of the foreground process group • in the session (if any) • which has that tty as controlling tty • The default interrupt character is ^C (Ctrl-C) • Can change with e.g., "$ stty intr ^G"
  • 5. 5 | SIGINT blocked example int main () { /* Block SIGINT. */ sigset_t new_mask; sigaddset (&new_mask, SIGINT); sigprocmask (SIG_BLOCK, &new_mask, NULL); while (true) { sleep (1); } } (gdb) r Starting program: sigint-blocked ^C^C^C *nothing*
  • 6. 6 | sigwait example int main () { /* Block SIGINT. */ sigset_t new_mask; sigaddset (&new_mask, SIGINT); sigprocmask (SIG_BLOCK, &new_mask, NULL); /* Make sigwait wait for all signals. */ sigset_t signal_set; int sig; sigfillset (&signal_set); sigwait (&signal_set, &sig); } (gdb) r Starting program: sigwait ^C [Inferior 1 (process 2585683) exited normally] (gdb) Same thing with signalfd Bug 9425 - When using "sigwait" GDB doesn'ttrap SIGINT. Ctrl+C terminates program when should break gdb First reported on 2007-09-20: https://sourceware.org/bugzilla/show_bug.cgi?id=9425 Rejected as kernel problem: https://bugzilla.kernel.org/show_bug.cgi?id=9039#c1
  • 7. 7 | What is Ctrl-C supposed to be under GDB? Ctrl-C has "supervisor" role in GDB • GDB action vs action on inferior Ctrl-C when running under GDB is: • "please ask GDB to stop the program so I can inspect it" • not: "kill the program" (as in, send-signal-kill) Note how default is to not pass SIGINT => consistent with above view: • 'c' after Ctrl-C resumes inferior rather than killing it • must explicitly use 'kill' or 'signal' after a Ctrl-C to interrupt the child process (vs just stop it)
  • 8. 8 | Problem is consequence of how GDB implements Ctrl-C • When GDB spawns a new process, it: • starts the process in the same terminal as GDB • puts it in a new process group • makes that the foreground process group in the session • When the process is running, e.g., after "continue" • GDB put the inferior's process group in the foreground • the user types Ctrl-C - kernel sends a SIGINT to the foreground process group (the inferior) • GDB intercepts the SIGINT via ptrace before inferior sees it • GDB stops all the other threads of the inferior (if all-stop) • GDB presents the "Program received SIGINT" stop to the user • If SIGINT is masked out, signal is left pending, not delivered • If program is using sigwait, a pending SIGINT is consumed, but not delivered
  • 9. 9 | GDB / Inferior share terminal (GDB juggles terminal settings) GDB Inferior process GDB's terminal fork()/exec() stdout stderr stdin User keyboard input terminal output • GDB and inferior share the session / terminal • GDB puts inferior in a new process group • GDB saves/restores gdb/inferior terminal settings appropriately stdout stderr stdin
  • 10. 10 | Inferior process GDB / Inferior share terminal (GDB in foreground) GDB GDB's terminal 2. SIGINT aborts/quits current command User 1. Ctrl-C • GDB is in the foreground (user can type GDB commands) • Readline terminal settings apply • Ctrl-C => SIGINT to GDB • SIGINT handler sets global quit_flag flag • Mainline code calls QUIT macro, which aborts current command • QUIT macro calls sprinkled throughout GDB, in loops
  • 11. 11 | GDB / Inferior share terminal (Inferior in foreground) GDB Inferior process GDB's terminal User 1. Ctrl-C 0. After "(gdb) c": • GDB restores inferior terminal settings • Inferior is put in the foreground • Ctrl-C results in SIGINT sent to inferior 2. SIGINT Kernel sends SIGINT to terminal's foreground progress group 3. SIGCHLD • ptrace intercepts SIGINT, stops thread, and wakes ptracer via SIGCHLD • gdb: 1. calls waitpid and learns about SIGINT stop 2. stops all threads (if all-stop mode) 3. presents "Program received SIGINT" 4. saves inferior terminal settings 5. restores its own terminal settings 6. puts itself in foreground (back to previous slide)
  • 12. 12 | GDB / Inferior share terminal (Inferior in foreground, SIGINT blocked) GDB Inferior process GDB's terminal User 1. Ctrl-C 0. After "(gdb) c", and SIGINT is blocked in inferior: • GDB restores inferior terminal settings • Inferior is put in the foreground • Ctrl-C results in SIGINT pending in inferior, but not delivered 2. SIGINT Kernel sends SIGINT to terminal's foreground progress group But, signal remains pending, never delivered... Thus, ptrace never intercepts it
  • 13. 13 | GDB / Inferior share terminal (Inferior in foreground, sigwait) GDB Inferior process GDB's terminal User 1. Ctrl-C 0. After "(gdb) c", and inferior uses sigwait: • GDB restores inferior terminal settings • Inferior is put in the foreground • Ctrl-C results in SIGINT queued in inferior, but not delivered 2. SIGINT Kernel sends SIGINT to terminal's foreground progress group sigwait consumes pending signal, technically signal is never delivered... Thus, ptrace does not intercept it
  • 14. 14 | Ctrl-C and AMDGPU – why important? (gdb) info threads Id Target Id Frame 1 Thread ... (LWP 476966) main () from libhsa-runtime64.so.1 2 Thread ... (LWP 476969) in ioctl () at syscall-template.S:78 4 Thread ... (LWP 477504) in ioctl () at syscall-template.S:78 * 5 AMDGPU Wave 1:1:1:1 (0,0,0)/0 my_kernel () at kernel.cc:41 … • Kernel sends SIGINT to process (host side) • But all host threads are stopped • ptrace will not intercept the SIGINT, until a host thread is resumed, and the signal delivered • But user does not have prompt, so, hang... (gdb) set scheduler-locking on (gdb) thread 5 # a GPU thread (gdb) c ^C^C^C^C^C^C^C^C^C^C^C * nothing, no way to get back the prompt *
  • 15. 15 | The Fix – give inferiors their own tty Make SIGINT always reach GDB first, not the inferior Put inferiors in their own terminal/session created by GDB • no need to juggle inferior terminal's settings That is: • GDB creates a pseudo-terminal (pty) master/slave pair • GDB makes the inferior run with the pty slave as its terminal • GDB pumps output/input on the pty master end. Since: • inferior has own session/terminal => GDB's remains the foreground process in its terminal • Ctrl-C SIGINT always reaches GDB first, since GDB is in the terminal's foreground GDB is then free to handle SIGINT and interrupting the program any way it sees fit
  • 16. 16 | Before: GDB / Inferior share terminal GDB Inferior process GDB's terminal fork()/exec() stdout stderr stdin User keyboard input terminal output • GDB and inferior share the session / terminal • GDB puts inferior in a new process group • GDB saves/restores gdb/inferior terminal settings appropriately stdout stderr stdin
  • 17. 17 | After: Inferior is given its own terminal (GDB forwards I/O) GDB Inferior process Pseudo terminal slave (/dev/pts/...) Pseudo terminal master GDB's terminal fork()/exec() stdout stderr stdin stdout stderr stdin write() read() User keyboard input terminal output • Inferior PTY has its own terminal settings, GDB doesn't need to save/restore them • GDB's tty must be in raw mode when forwarding input/output, so that escape codes, rn, etc. are fully forwarded uninterpreted
  • 18. 18 | Ctrl-C in GDB's terminal always reaches GDB GDB Inferior process Pseudo terminal slave (/dev/pts/...) GDB's terminal 3. GDB stops process 2. SIGINT User 1. Ctrl-C • Inferior is in foreground of its own terminal • GDB is in foreground of its own terminal (More about stopping inferior later)
  • 19. 19 | I/O forwarding (output) 1. Open an unused pty master/slave pair using standard posix_openpt / grantpt / unlockpt 2. Start inferior with pty slave as terminal (as if "(gdb) tty $PTY_SLAVE_NAME") 3. Register master end of pty in the event loop • inferior writes to its terminal => event loop wakes up and handler flushes inferior output to GDB's stdout That handles output. But what about input?
  • 20. 20 | I/O forwarding (input) Input when GDB has the prompt != Input when the inferior is running GDB already has logic to switch terminal modes at the right spots depending on whether GDB or the inferior "have the terminal": a) target_terminal::inferior() -> child_terminal_inferior() 1. Set stdin to raw mode 2. Register stdin-forwarder handler in the event loop b) target_terminal::ours() -> child_terminal_ours() 1. Delete stdin-forwarder handler from the event loop and restore readline terminal settings 2. async_enable_stdin later re-installs GDB's normal stdin->readline event-loop handler, when it's time to show the prompt
  • 21. 21 | How to tell GDB to spawn inferior in GDB's terminal? Still useful to be able to tell GDB to spawn inferior in same terminal & session as GDB (like today) • Say, you want to run + detach, and let the detached inferior continue printing to the terminal POSIX says "/dev/tty" => terminal for the current process => special-casing "set inferior-tty /dev/tty" seemed like an obvious choice Leaves "(gdb) set inferior-tty" with no arguments free for a different behavior => whatever is the default in the platform
  • 22. 22 | GDB controls when inferior output is flushed to the screen (gdb) c & Continuing. (gdb) help List of classes of commands: aliases -- User-defined aliases of other commands. Hello world! breakpoints -- Making program stop at certain points. data -- Examining data. … (gdb) (gdb) c & Continuing. (gdb) help List of classes of commands: aliases -- User-defined aliases of other commands. breakpoints -- Making program stop at certain points. data -- Examining data. … (gdb) Hello world! Avoids inferior output being interspersed with GDB's output (background/non-stop mode) • Inferior output is never flushed while GDB is printing something itself • E.g., "help" while inferior is running Before: After:
  • 23. 23 | TUI & inferior output flushing With the TUI: • could hook in tui_puts, instead of inferior outputting to screen directly • we could even redirect inferior I/O to its own TUI window if we wanted • no more need for Ctrl-L to refresh the screen Debugging curses programs with the TUI would no longer work as today, though => ASCII escape sequence wouldn't be interpreted by the TUI's command window... Unless... we made TUI's command window a real terminal emulator. :-) => TUI within the TUI within the TUI? Still, that limitation wouldn't seem too important for non-gdb hackers? => "(gdb) tty /dev/tty" => or, run the curses inferior in its own terminal window
  • 24. 24 | One last problem: session leaders and SIGHUP Session leaders have special properties: • session leader exits => SIGHUP to all processes in the foreground process group Recall primer: • In Unix every process belongs to a process group which in turn belongs to a session • Session (SID) → Process Group (PGID) → Process (PID) More: • The first process in the process group becomes the process group leader • The first process in the session becomes the session leader • Every session can have one TTY associated with it • Only a session leader can take control of a TTY
  • 25. 25 | The follow-fork SIGHUP problem pts/1 pts/2 pts/2 | | | gdb---fork_parent---fork_child | session leader If the spawned inferior is the session leader itself, and, - it forks, and, - if the parent (the session leader) exits, => the child gets a SIGHUP (and likely dies)
  • 26. 26 | After: 1. gdb | pts/1 2. gdb(1)---gdb(2) 3. gdb(1)---gdb(2)---gdb(3) 4. gdb(1)---gdb(2)---shell(3) session leader | 5. gdb(1)---gdb(2)---inf(3) | | | pts/1 pts/2 pts/2 SIGHUP: The fix – apply double-fork technique Before: 1. gdb(1) | pts/1 2. gdb(1)---gdb(2) 3. gdb(1)---shell(2) 4. gdb(1)---inferior(2) | | pts/1 pts/1 Make GDB insert a process between itself and the inferior it first runs, whose only job is to be the session leader. Akin to double-fork technique for daemonizing. Before: • GDB forks • child GDB execs the shell • shell execs the final inferior program After: • GDB forks • child GDB forks again, and parent becomes session leader process • grandchild GDB execs the shell • shell execs the final inferior program
  • 27. 27 | SIGHUP: The fix, follow-fork scenario pts/1 pts/2 pts/2 pts/2 | | | | gdb---gdb---fork_parent---fork_child | session leader Make GDB insert an extra process between itself and the inferior it first runs, whose only job is to be the session leader. Session leader process is not ptraced Session leader process stays around until both: 1. its child exits 2. gdb closes the inferior's terminal (It doesn't exit after #1 as there may still be grandchildren attached to its session)
  • 28. 28 | The run+detach SIGHUP problem pts/1 pts/2 | | gdb- X -inferior | session leader 1. (gdb) run 2. (gdb) detach 3. GDB destroys the inferior's terminal (pts/2) 4. detached inferior is session leader and loses terminal and so gets SIGHUP (and usually dies) Surprising number of GDB testcases do "run" + "detach"
  • 29. 29 | SIGHUP: The fix, detach scenario pts/1 pts/2 pts/2 | | | gdb- X -gdb---inferior | session leader 1. (gdb) run 2. (gdb) detach 3. GDB destroys the inferior's terminal (pts/2) 4. detached inferior remains alive but loses terminal so output goes nowhere Detached process no longer gets SIGHUP. Output is lost, but we could make GDB warn in this situation ("inferior will lose terminal. Are you sure you want to detach?"). If you really want to be able to run + detach + continue seeing inferior output, then you really want to run the inferior in gdb's terminal, as before. You can do that with: (gdb) tty /dev/tty This disables the spawning of the extra session-leader process and reactivates the gdb/inferior terminal settings juggling.
  • 30. 30 | Still need to stop inferiors that block SIGINT Now GDB always sees the Ctrl-C request We still have the original problem, though – cannot stop inferior with SIGINT if inferior blocks SIGINT
  • 31. 31 | Fix: Stop inferiors with SIGSTOP Make GDB stop the inferior with SIGSTOP instead => SIGSTOP is special and cannot be blocked User-visible behavior change in all-stop mode -- with Ctrl-C, instead of: Thread 1 "threads" received signal SIGINT, Interrupt. You'll get: Thread 1 "threads" stopped. Which is what you already got with the "interrupt" command in non-stop mode You can still pass a SIGINT to the program, using:(gdb) signal SIGINT
  • 32. 32 | Stop inferior with SIGSTOP, continued The stopping is done from common code, via the existing target_stop 1. Ctrl-C to GDB -> sets quit flag 2. Default quit handler marks infrun event handler for Ctrl-C [new] 3. Infrun's new ctrl-c event handler: a) if all-stop mode: 1. Synchronously stops all threads 2. If possible, keeps focus on the previously-selected thread [new, not possible before] 3. Presents stop via normal_stop b) if non-stop mode: 1. Asynchronously stops one thread [preserving behavior], preferentially previously-selected thread [new] Could change the non-stop behavior: Drop to prompt without stopping anything? Stop the world? Other?
  • 33. 33 | Upstreaming status Last version sent to gdb-patches here (2021-06-14): [PATCH v2 00/16] Interrupting programs that block/ignore SIGINT https://inbox.sourceware.org/gdb-patches/20210614212410.1612666-1-pedro@palves.net/ Also in the users/palves/ctrl-c branch on sourceware: https://sourceware.org/git/?p=binutils-gdb.git;a=shortlog;h=refs/heads/users/palves/ctrl-c Updated series should appear on gdb-patches soon™
  • 34. 34 | Disclaimer & Attribution ©2022 Advanced Micro Devices, Inc. All rights reserved. AMD, the AMD Arrow logo, AMD Instinct™, AMD ROCm™, Radeon™, and combinations thereof are trademarks of Advanced Micro Devices, Inc. Other product names used in this publication are for identification purposes only and may be trademarks of their respective companies. The information presented in this document is for informational purposes only and may contain technical inaccuracies, omissions, and typographical errors. The information contained herein is subject to change and may be rendered inaccurate releases, for many reasons, including but not limited to product and roadmap changes, component and motherboard version changes, new model and/or product differences between differing manufacturers, software changes, BIOS flashes, firmware upgrades, or the like. Any computer system has risks of security vulnerabilities that cannot be completely prevented or mitigated. AMD assumes no obligation to update or otherwise correct or revise this information. However, AMD reserves the right to revise this informat ion and to make changes from time to time to the content hereof without obligation of AMD to notify any person of such revisions or changes. THIS INFORMATION IS PROVIDED 'AS IS." AMD MAKES NO REPRESENTATIONS OR WARRANTIES WITH RESPECTTO THE CONTENTS HEREOF AND ASSUMES NO RESPONSIBILITY FOR ANY INACCURACIES, ERRORS, OR OMISSIONS THAT MAY APPEAR IN THIS INFORMATION. AMD SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY , OR FITNESS FOR ANY PARTICULAR PURPOSE. IN NO EVENT WILL AMD BE LIABLE TO ANY PERSON FOR ANY RELIANCE, DIRECT, INDIRECT, SPECIAL, OR OTHER CONSEQUENTIAL DAMAGES ARISING FROM THE USE OF ANY INFORMATION CONTAINED HEREIN, EVEN IF AMD IS EXPRESSLYADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
  • 35.
  • 36. 36 | The end, time for questions Redesigning GDB's Ctrl-C handling