@@ -677,133 +677,143 @@ Status ProcessGDBRemote::DoLaunch(lldb_private::Module *exe_module,
677
677
// LLDB_LOG_OPTION_PREPEND_PROC_AND_THREAD);
678
678
// ::LogSetLogFile ("/dev/stdout");
679
679
680
- error = EstablishConnectionIfNeeded (launch_info);
681
- if (error.Success ()) {
682
- PseudoTerminal pty;
683
- const bool disable_stdio = (launch_flags & eLaunchFlagDisableSTDIO) != 0 ;
684
-
685
- PlatformSP platform_sp (GetTarget ().GetPlatform ());
686
- if (disable_stdio) {
687
- // set to /dev/null unless redirected to a file above
688
- if (!stdin_file_spec)
689
- stdin_file_spec.SetFile (FileSystem::DEV_NULL,
690
- FileSpec::Style::native);
691
- if (!stdout_file_spec)
692
- stdout_file_spec.SetFile (FileSystem::DEV_NULL,
693
- FileSpec::Style::native);
694
- if (!stderr_file_spec)
695
- stderr_file_spec.SetFile (FileSystem::DEV_NULL,
696
- FileSpec::Style::native);
697
- } else if (platform_sp && platform_sp->IsHost ()) {
698
- // If the debugserver is local and we aren't disabling STDIO, lets use
699
- // a pseudo terminal to instead of relying on the 'O' packets for stdio
700
- // since 'O' packets can really slow down debugging if the inferior
701
- // does a lot of output.
702
- if ((!stdin_file_spec || !stdout_file_spec || !stderr_file_spec) &&
703
- !errorToBool (pty.OpenFirstAvailablePrimary (O_RDWR | O_NOCTTY))) {
704
- FileSpec secondary_name (pty.GetSecondaryName ());
680
+ ObjectFile *object_file = exe_module->GetObjectFile ();
681
+ if (object_file) {
682
+ error = EstablishConnectionIfNeeded (launch_info);
683
+ if (error.Success ()) {
684
+ PseudoTerminal pty;
685
+ const bool disable_stdio = (launch_flags & eLaunchFlagDisableSTDIO) != 0 ;
705
686
687
+ PlatformSP platform_sp (GetTarget ().GetPlatform ());
688
+ if (disable_stdio) {
689
+ // set to /dev/null unless redirected to a file above
706
690
if (!stdin_file_spec)
707
- stdin_file_spec = secondary_name;
708
-
691
+ stdin_file_spec. SetFile (FileSystem::DEV_NULL,
692
+ FileSpec::Style::native);
709
693
if (!stdout_file_spec)
710
- stdout_file_spec = secondary_name;
711
-
694
+ stdout_file_spec. SetFile (FileSystem::DEV_NULL,
695
+ FileSpec::Style::native);
712
696
if (!stderr_file_spec)
713
- stderr_file_spec = secondary_name;
697
+ stderr_file_spec.SetFile (FileSystem::DEV_NULL,
698
+ FileSpec::Style::native);
699
+ } else if (platform_sp && platform_sp->IsHost ()) {
700
+ // If the debugserver is local and we aren't disabling STDIO, lets use
701
+ // a pseudo terminal to instead of relying on the 'O' packets for stdio
702
+ // since 'O' packets can really slow down debugging if the inferior
703
+ // does a lot of output.
704
+ if ((!stdin_file_spec || !stdout_file_spec || !stderr_file_spec) &&
705
+ !errorToBool (pty.OpenFirstAvailablePrimary (O_RDWR | O_NOCTTY))) {
706
+ FileSpec secondary_name (pty.GetSecondaryName ());
707
+
708
+ if (!stdin_file_spec)
709
+ stdin_file_spec = secondary_name;
710
+
711
+ if (!stdout_file_spec)
712
+ stdout_file_spec = secondary_name;
713
+
714
+ if (!stderr_file_spec)
715
+ stderr_file_spec = secondary_name;
716
+ }
717
+ LLDB_LOGF (
718
+ log,
719
+ " ProcessGDBRemote::%s adjusted STDIO paths for local platform "
720
+ " (IsHost() is true) using secondary: stdin=%s, stdout=%s, "
721
+ " stderr=%s" ,
722
+ __FUNCTION__,
723
+ stdin_file_spec ? stdin_file_spec.GetCString () : " <null>" ,
724
+ stdout_file_spec ? stdout_file_spec.GetCString () : " <null>" ,
725
+ stderr_file_spec ? stderr_file_spec.GetCString () : " <null>" );
714
726
}
715
- LLDB_LOGF (
716
- log,
717
- " ProcessGDBRemote::%s adjusted STDIO paths for local platform "
718
- " (IsHost() is true) using secondary: stdin=%s, stdout=%s, "
719
- " stderr=%s" ,
720
- __FUNCTION__,
721
- stdin_file_spec ? stdin_file_spec.GetCString () : " <null>" ,
722
- stdout_file_spec ? stdout_file_spec.GetCString () : " <null>" ,
723
- stderr_file_spec ? stderr_file_spec.GetCString () : " <null>" );
724
- }
725
727
726
- LLDB_LOGF (log,
727
- " ProcessGDBRemote::%s final STDIO paths after all "
728
- " adjustments: stdin=%s, stdout=%s, stderr=%s" ,
729
- __FUNCTION__,
730
- stdin_file_spec ? stdin_file_spec.GetCString () : " <null>" ,
731
- stdout_file_spec ? stdout_file_spec.GetCString () : " <null>" ,
732
- stderr_file_spec ? stderr_file_spec.GetCString () : " <null>" );
733
-
734
- if (stdin_file_spec)
735
- m_gdb_comm.SetSTDIN (stdin_file_spec);
736
- if (stdout_file_spec)
737
- m_gdb_comm.SetSTDOUT (stdout_file_spec);
738
- if (stderr_file_spec)
739
- m_gdb_comm.SetSTDERR (stderr_file_spec);
740
-
741
- m_gdb_comm.SetDisableASLR (launch_flags & eLaunchFlagDisableASLR);
742
- m_gdb_comm.SetDetachOnError (launch_flags & eLaunchFlagDetachOnError);
743
-
744
- m_gdb_comm.SendLaunchArchPacket (
745
- GetTarget ().GetArchitecture ().GetArchitectureName ());
746
-
747
- const char *launch_event_data = launch_info.GetLaunchEventData ();
748
- if (launch_event_data != nullptr && *launch_event_data != ' \0 ' )
749
- m_gdb_comm.SendLaunchEventDataPacket (launch_event_data);
750
-
751
- if (working_dir) {
752
- m_gdb_comm.SetWorkingDir (working_dir);
753
- }
728
+ LLDB_LOGF (log,
729
+ " ProcessGDBRemote::%s final STDIO paths after all "
730
+ " adjustments: stdin=%s, stdout=%s, stderr=%s" ,
731
+ __FUNCTION__,
732
+ stdin_file_spec ? stdin_file_spec.GetCString () : " <null>" ,
733
+ stdout_file_spec ? stdout_file_spec.GetCString () : " <null>" ,
734
+ stderr_file_spec ? stderr_file_spec.GetCString () : " <null>" );
754
735
755
- // Send the environment and the program + arguments after we connect
756
- m_gdb_comm.SendEnvironment (launch_info.GetEnvironment ());
736
+ if (stdin_file_spec)
737
+ m_gdb_comm.SetSTDIN (stdin_file_spec);
738
+ if (stdout_file_spec)
739
+ m_gdb_comm.SetSTDOUT (stdout_file_spec);
740
+ if (stderr_file_spec)
741
+ m_gdb_comm.SetSTDERR (stderr_file_spec);
757
742
758
- {
759
- // Scope for the scoped timeout object
760
- GDBRemoteCommunication::ScopedTimeout timeout (m_gdb_comm,
761
- std::chrono::seconds (10 ));
762
-
763
- int arg_packet_err = m_gdb_comm.SendArgumentsPacket (launch_info);
764
- if (arg_packet_err == 0 ) {
765
- std::string error_str;
766
- if (m_gdb_comm.GetLaunchSuccess (error_str)) {
767
- SetID (m_gdb_comm.GetCurrentProcessID ());
743
+ m_gdb_comm.SetDisableASLR (launch_flags & eLaunchFlagDisableASLR);
744
+ m_gdb_comm.SetDetachOnError (launch_flags & eLaunchFlagDetachOnError);
745
+
746
+ m_gdb_comm.SendLaunchArchPacket (
747
+ GetTarget ().GetArchitecture ().GetArchitectureName ());
748
+
749
+ const char *launch_event_data = launch_info.GetLaunchEventData ();
750
+ if (launch_event_data != nullptr && *launch_event_data != ' \0 ' )
751
+ m_gdb_comm.SendLaunchEventDataPacket (launch_event_data);
752
+
753
+ if (working_dir) {
754
+ m_gdb_comm.SetWorkingDir (working_dir);
755
+ }
756
+
757
+ // Send the environment and the program + arguments after we connect
758
+ m_gdb_comm.SendEnvironment (launch_info.GetEnvironment ());
759
+
760
+ {
761
+ // Scope for the scoped timeout object
762
+ GDBRemoteCommunication::ScopedTimeout timeout (m_gdb_comm,
763
+ std::chrono::seconds (10 ));
764
+
765
+ int arg_packet_err = m_gdb_comm.SendArgumentsPacket (launch_info);
766
+ if (arg_packet_err == 0 ) {
767
+ std::string error_str;
768
+ if (m_gdb_comm.GetLaunchSuccess (error_str)) {
769
+ SetID (m_gdb_comm.GetCurrentProcessID ());
770
+ } else {
771
+ error.SetErrorString (error_str.c_str ());
772
+ }
768
773
} else {
769
- error.SetErrorString (error_str.c_str ());
774
+ error.SetErrorStringWithFormat (" 'A' packet returned an error: %i" ,
775
+ arg_packet_err);
770
776
}
771
- } else {
772
- error.SetErrorStringWithFormat (" 'A' packet returned an error: %i" ,
773
- arg_packet_err);
774
777
}
775
- }
776
778
777
- if (GetID () == LLDB_INVALID_PROCESS_ID) {
778
- LLDB_LOGF (log, " failed to connect to debugserver: %s" ,
779
- error.AsCString ());
780
- KillDebugserverProcess ();
781
- return error;
782
- }
779
+ if (GetID () == LLDB_INVALID_PROCESS_ID) {
780
+ LLDB_LOGF (log, " failed to connect to debugserver: %s" ,
781
+ error.AsCString ());
782
+ KillDebugserverProcess ();
783
+ return error;
784
+ }
783
785
784
- StringExtractorGDBRemote response;
785
- if (m_gdb_comm.GetStopReply (response)) {
786
- SetLastStopPacket (response);
786
+ StringExtractorGDBRemote response;
787
+ if (m_gdb_comm.GetStopReply (response)) {
788
+ SetLastStopPacket (response);
787
789
788
- const ArchSpec &process_arch = m_gdb_comm.GetProcessArchitecture ();
790
+ const ArchSpec &process_arch = m_gdb_comm.GetProcessArchitecture ();
789
791
790
- if (process_arch.IsValid ()) {
791
- GetTarget ().MergeArchitecture (process_arch);
792
- } else {
793
- const ArchSpec &host_arch = m_gdb_comm.GetHostArchitecture ();
794
- if (host_arch.IsValid ())
795
- GetTarget ().MergeArchitecture (host_arch);
796
- }
792
+ if (process_arch.IsValid ()) {
793
+ GetTarget ().MergeArchitecture (process_arch);
794
+ } else {
795
+ const ArchSpec &host_arch = m_gdb_comm.GetHostArchitecture ();
796
+ if (host_arch.IsValid ())
797
+ GetTarget ().MergeArchitecture (host_arch);
798
+ }
797
799
798
- SetPrivateState (SetThreadStopInfo (response));
800
+ SetPrivateState (SetThreadStopInfo (response));
799
801
800
- if (!disable_stdio) {
801
- if (pty.GetPrimaryFileDescriptor () != PseudoTerminal::invalid_fd)
802
- SetSTDIOFileDescriptor (pty.ReleasePrimaryFileDescriptor ());
802
+ if (!disable_stdio) {
803
+ if (pty.GetPrimaryFileDescriptor () != PseudoTerminal::invalid_fd)
804
+ SetSTDIOFileDescriptor (pty.ReleasePrimaryFileDescriptor ());
805
+ }
803
806
}
807
+ } else {
808
+ LLDB_LOGF (log, " failed to connect to debugserver: %s" , error.AsCString ());
804
809
}
805
810
} else {
806
- LLDB_LOGF (log, " failed to connect to debugserver: %s" , error.AsCString ());
811
+ // Set our user ID to an invalid process ID.
812
+ SetID (LLDB_INVALID_PROCESS_ID);
813
+ error.SetErrorStringWithFormat (
814
+ " failed to get object file from '%s' for arch %s" ,
815
+ exe_module->GetFileSpec ().GetFilename ().AsCString (),
816
+ exe_module->GetArchitecture ().GetArchitectureName ());
807
817
}
808
818
return error;
809
819
}
0 commit comments