@@ -994,14 +994,16 @@ void lldb_finished_handler(int signum)
994
994
_exit (WEXITSTATUS (status));
995
995
}
996
996
997
- void bring_process_to_foreground () {
997
+ pid_t bring_process_to_foreground () {
998
+ pid_t fgpid = tcgetpgrp (STDIN_FILENO);
998
999
if (setpgid (0 , 0 ) == -1 )
999
1000
perror (" setpgid failed" );
1000
1001
1001
1002
signal (SIGTTOU, SIG_IGN);
1002
1003
if (tcsetpgrp (STDIN_FILENO, getpid ()) == -1 )
1003
1004
perror (" tcsetpgrp failed" );
1004
1005
signal (SIGTTOU, SIG_DFL);
1006
+ return fgpid;
1005
1007
}
1006
1008
1007
1009
void setup_dummy_pipe_on_stdin (int pfd[2 ]) {
@@ -1051,12 +1053,12 @@ void launch_debugger(AMDeviceRef device, CFURLRef url) {
1051
1053
signal (SIGHUP, SIG_DFL);
1052
1054
signal (SIGLLDB, SIG_DFL);
1053
1055
child = getpid ();
1054
-
1056
+ pid_t oldfgpid = 0 ;
1055
1057
int pfd[2 ] = {-1 , -1 };
1056
- if (isatty (STDIN_FILENO))
1058
+ if (interactive && isatty (STDIN_FILENO))
1057
1059
// If we are running on a terminal, then we need to bring process to foreground for input
1058
1060
// to work correctly on lldb's end.
1059
- bring_process_to_foreground ();
1061
+ oldfgpid = bring_process_to_foreground ();
1060
1062
else
1061
1063
// If lldb is running in a non terminal environment, then it freaks out spamming "^D" and
1062
1064
// "quit". It seems this is caused by read() on stdin returning EOF in lldb. To hack around
@@ -1080,6 +1082,10 @@ void launch_debugger(AMDeviceRef device, CFURLRef url) {
1080
1082
1081
1083
// Notify parent we're exiting
1082
1084
kill (parent, SIGLLDB);
1085
+
1086
+ if (oldfgpid) {
1087
+ tcsetpgrp (STDIN_FILENO, oldfgpid);
1088
+ }
1083
1089
// Pass lldb exit code
1084
1090
_exit (WEXITSTATUS (status));
1085
1091
} else if (pid > 0 ) {
0 commit comments