@@ -1083,14 +1083,16 @@ void lldb_finished_handler(int signum)
1083
1083
_exit (WEXITSTATUS (status));
1084
1084
}
1085
1085
1086
- void bring_process_to_foreground () {
1086
+ pid_t bring_process_to_foreground () {
1087
+ pid_t fgpid = tcgetpgrp (STDIN_FILENO);
1087
1088
if (setpgid (0 , 0 ) == -1 )
1088
1089
perror (" setpgid failed" );
1089
1090
1090
1091
signal (SIGTTOU, SIG_IGN);
1091
1092
if (tcsetpgrp (STDIN_FILENO, getpid ()) == -1 )
1092
1093
perror (" tcsetpgrp failed" );
1093
1094
signal (SIGTTOU, SIG_DFL);
1095
+ return fgpid;
1094
1096
}
1095
1097
1096
1098
void setup_dummy_pipe_on_stdin (int pfd[2 ]) {
@@ -1140,12 +1142,12 @@ void launch_debugger(AMDeviceRef device, CFURLRef url) {
1140
1142
signal (SIGHUP, SIG_DFL);
1141
1143
signal (SIGLLDB, SIG_DFL);
1142
1144
child = getpid ();
1143
-
1145
+ pid_t oldfgpid = 0 ;
1144
1146
int pfd[2 ] = {-1 , -1 };
1145
1147
if (isatty (STDIN_FILENO))
1146
1148
// If we are running on a terminal, then we need to bring process to foreground for input
1147
1149
// to work correctly on lldb's end.
1148
- bring_process_to_foreground ();
1150
+ oldfgpid = bring_process_to_foreground ();
1149
1151
else
1150
1152
// If lldb is running in a non terminal environment, then it freaks out spamming "^D" and
1151
1153
// "quit". It seems this is caused by read() on stdin returning EOF in lldb. To hack around
@@ -1169,6 +1171,10 @@ void launch_debugger(AMDeviceRef device, CFURLRef url) {
1169
1171
1170
1172
// Notify parent we're exiting
1171
1173
kill (parent, SIGLLDB);
1174
+
1175
+ if (oldfgpid) {
1176
+ tcsetpgrp (STDIN_FILENO, oldfgpid);
1177
+ }
1172
1178
// Pass lldb exit code
1173
1179
_exit (WEXITSTATUS (status));
1174
1180
} else if (pid > 0 ) {
0 commit comments