@@ -746,108 +746,69 @@ lldb::pid_t GDBRemoteCommunicationClient::GetCurrentProcessID(bool allow_lazy) {
746
746
return LLDB_INVALID_PROCESS_ID;
747
747
}
748
748
749
- bool GDBRemoteCommunicationClient::GetLaunchSuccess (std::string &error_str) {
750
- error_str.clear ();
751
- StringExtractorGDBRemote response;
752
- if (SendPacketAndWaitForResponse (" qLaunchSuccess" , response) ==
753
- PacketResult::Success) {
754
- if (response.IsOKResponse ())
755
- return true ;
756
- // GDB does not implement qLaunchSuccess -- but if we used vRun,
757
- // then we already received a successful launch indication via stop
758
- // reason.
759
- if (response.IsUnsupportedResponse () && m_supports_vRun)
760
- return true ;
761
- if (response.GetChar () == ' E' ) {
762
- // A string the describes what failed when launching...
763
- error_str = std::string (response.GetStringRef ().substr (1 ));
764
- } else {
765
- error_str.assign (" unknown error occurred launching process" );
749
+ llvm::Error GDBRemoteCommunicationClient::LaunchProcess (const Args &args) {
750
+ if (!args.GetArgumentAtIndex (0 ))
751
+ return llvm::createStringError (llvm::inconvertibleErrorCode (),
752
+ " Nothing to launch" );
753
+ // try vRun first
754
+ if (m_supports_vRun) {
755
+ StreamString packet;
756
+ packet.PutCString (" vRun" );
757
+ for (const Args::ArgEntry &arg : args) {
758
+ packet.PutChar (' ;' );
759
+ packet.PutStringAsRawHex8 (arg.ref ());
766
760
}
767
- } else {
768
- error_str.assign (" timed out waiting for app to launch" );
769
- }
770
- return false ;
771
- }
772
761
773
- int GDBRemoteCommunicationClient::SendArgumentsPacket (
774
- const ProcessLaunchInfo &launch_info) {
775
- // Since we don't get the send argv0 separate from the executable path, we
776
- // need to make sure to use the actual executable path found in the
777
- // launch_info...
778
- std::vector<const char *> argv;
779
- FileSpec exe_file = launch_info.GetExecutableFile ();
780
- std::string exe_path;
781
- const char *arg = nullptr ;
782
- const Args &launch_args = launch_info.GetArguments ();
783
- if (exe_file)
784
- exe_path = exe_file.GetPath (false );
785
- else {
786
- arg = launch_args.GetArgumentAtIndex (0 );
787
- if (arg)
788
- exe_path = arg;
789
- }
790
- if (!exe_path.empty ()) {
791
- argv.push_back (exe_path.c_str ());
792
- for (uint32_t i = 1 ; (arg = launch_args.GetArgumentAtIndex (i)) != nullptr ;
793
- ++i) {
794
- if (arg)
795
- argv.push_back (arg);
796
- }
797
- }
798
- if (!argv.empty ()) {
799
- // try vRun first
800
- if (m_supports_vRun) {
801
- StreamString packet;
802
- packet.PutCString (" vRun" );
803
- for (const char *arg : argv) {
804
- packet.PutChar (' ;' );
805
- packet.PutBytesAsRawHex8 (arg, strlen (arg));
806
- }
762
+ StringExtractorGDBRemote response;
763
+ if (SendPacketAndWaitForResponse (packet.GetString (), response) !=
764
+ PacketResult::Success)
765
+ return llvm::createStringError (llvm::inconvertibleErrorCode (),
766
+ " Sending vRun packet failed" );
807
767
808
- StringExtractorGDBRemote response;
809
- if (SendPacketAndWaitForResponse (packet.GetString (), response) !=
810
- PacketResult::Success)
811
- return -1 ;
768
+ if (response.IsErrorResponse ())
769
+ return response.GetStatus ().ToError ();
812
770
813
- if (response.IsErrorResponse ()) {
814
- uint8_t error = response.GetError ();
815
- if (error)
816
- return error;
817
- return -1 ;
818
- }
819
- // vRun replies with a stop reason packet
820
- // FIXME: right now we just discard the packet and LLDB queries
821
- // for stop reason again
822
- if (!response.IsUnsupportedResponse ())
823
- return 0 ;
771
+ // vRun replies with a stop reason packet
772
+ // FIXME: right now we just discard the packet and LLDB queries
773
+ // for stop reason again
774
+ if (!response.IsUnsupportedResponse ())
775
+ return llvm::Error::success ();
824
776
825
- m_supports_vRun = false ;
826
- }
777
+ m_supports_vRun = false ;
778
+ }
827
779
828
- // fallback to A
829
- StreamString packet;
830
- packet.PutChar (' A' );
831
- for (size_t i = 0 , n = argv.size (); i < n; ++i) {
832
- arg = argv[i];
833
- const int arg_len = strlen (arg);
834
- if (i > 0 )
835
- packet.PutChar (' ,' );
836
- packet.Printf (" %i,%i," , arg_len * 2 , (int )i);
837
- packet.PutBytesAsRawHex8 (arg, arg_len);
838
- }
780
+ // fallback to A
781
+ StreamString packet;
782
+ packet.PutChar (' A' );
783
+ llvm::ListSeparator LS (" ," );
784
+ for (const auto &arg : llvm::enumerate (args)) {
785
+ packet << LS;
786
+ packet.Format (" {0},{1}," , arg.value ().ref ().size () * 2 , arg.index ());
787
+ packet.PutStringAsRawHex8 (arg.value ().ref ());
788
+ }
839
789
840
- StringExtractorGDBRemote response;
841
- if (SendPacketAndWaitForResponse (packet.GetString (), response) ==
842
- PacketResult::Success) {
843
- if (response.IsOKResponse ())
844
- return 0 ;
845
- uint8_t error = response.GetError ();
846
- if (error)
847
- return error;
848
- }
790
+ StringExtractorGDBRemote response;
791
+ if (SendPacketAndWaitForResponse (packet.GetString (), response) !=
792
+ PacketResult::Success) {
793
+ return llvm::createStringError (llvm::inconvertibleErrorCode (),
794
+ " Sending A packet failed" );
849
795
}
850
- return -1 ;
796
+ if (!response.IsOKResponse ())
797
+ return response.GetStatus ().ToError ();
798
+
799
+ if (SendPacketAndWaitForResponse (" qLaunchSuccess" , response) !=
800
+ PacketResult::Success) {
801
+ return llvm::createStringError (llvm::inconvertibleErrorCode (),
802
+ " Sending qLaunchSuccess packet failed" );
803
+ }
804
+ if (response.IsOKResponse ())
805
+ return llvm::Error::success ();
806
+ if (response.GetChar () == ' E' ) {
807
+ return llvm::createStringError (llvm::inconvertibleErrorCode (),
808
+ response.GetStringRef ().substr (1 ));
809
+ }
810
+ return llvm::createStringError (llvm::inconvertibleErrorCode (),
811
+ " unknown error occurred launching process" );
851
812
}
852
813
853
814
int GDBRemoteCommunicationClient::SendEnvironment (const Environment &env) {
0 commit comments