lldb::TargetSP Host::GetDummyTarget (lldb_private::Debugger &debugger) { static TargetSP dummy_target; if (!dummy_target) { Error err = debugger.GetTargetList().CreateTarget(debugger, FileSpec(), Host::GetTargetTriple().AsCString(), false, NULL, dummy_target); } return dummy_target; }
lldb::TargetSP Host::GetDummyTarget (lldb_private::Debugger &debugger) { static TargetSP g_dummy_target_sp; // FIXME: Maybe the dummy target should be per-Debugger if (!g_dummy_target_sp || !g_dummy_target_sp->IsValid()) { ArchSpec arch(Target::GetDefaultArchitecture()); if (!arch.IsValid()) arch = HostInfo::GetArchitecture(); Error err = debugger.GetTargetList().CreateTarget(debugger, NULL, arch.GetTriple().getTriple().c_str(), false, NULL, g_dummy_target_sp); } return g_dummy_target_sp; }
lldb::ProcessSP PlatformRemoteGDBServer::DebugProcess (lldb_private::ProcessLaunchInfo &launch_info, lldb_private::Debugger &debugger, lldb_private::Target *target, // Can be NULL, if NULL create a new target, else use existing one lldb_private::Listener &listener, lldb_private::Error &error) { lldb::ProcessSP process_sp; if (IsRemote()) { if (IsConnected()) { lldb::pid_t debugserver_pid = LLDB_INVALID_PROCESS_ID; ArchSpec remote_arch = GetRemoteSystemArchitecture(); llvm::Triple &remote_triple = remote_arch.GetTriple(); uint16_t port = 0; if (remote_triple.getVendor() == llvm::Triple::Apple && remote_triple.getOS() == llvm::Triple::IOS) { // When remote debugging to iOS, we use a USB mux that always talks // to localhost, so we will need the remote debugserver to accept connections // only from localhost, no matter what our current hostname is port = m_gdb_client.LaunchGDBserverAndGetPort(debugserver_pid, "127.0.0.1"); } else { // All other hosts should use their actual hostname port = m_gdb_client.LaunchGDBserverAndGetPort(debugserver_pid, NULL); } if (port == 0) { error.SetErrorStringWithFormat ("unable to launch a GDB server on '%s'", GetHostname ()); } else { if (target == NULL) { TargetSP new_target_sp; error = debugger.GetTargetList().CreateTarget (debugger, NULL, NULL, false, NULL, new_target_sp); target = new_target_sp.get(); } else error.Clear(); if (target && error.Success()) { debugger.GetTargetList().SetSelectedTarget(target); // The darwin always currently uses the GDB remote debugger plug-in // so even when debugging locally we are debugging remotely! process_sp = target->CreateProcess (listener, "gdb-remote", NULL); if (process_sp) { char connect_url[256]; const char *override_hostname = getenv("LLDB_PLATFORM_REMOTE_GDB_SERVER_HOSTNAME"); const char *port_offset_c_str = getenv("LLDB_PLATFORM_REMOTE_GDB_SERVER_PORT_OFFSET"); int port_offset = port_offset_c_str ? ::atoi(port_offset_c_str) : 0; const int connect_url_len = ::snprintf (connect_url, sizeof(connect_url), "connect://%s:%u", override_hostname ? override_hostname : GetHostname (), port + port_offset); assert (connect_url_len < (int)sizeof(connect_url)); error = process_sp->ConnectRemote (NULL, connect_url); if (error.Success()) error = process_sp->Launch(launch_info); else if (debugserver_pid != LLDB_INVALID_PROCESS_ID) m_gdb_client.KillSpawnedProcess(debugserver_pid); } } } } else { error.SetErrorString("not connected to remote gdb server"); } } return process_sp; }
void JuliaEventHandlerLoop() { lldb_private::Listener& listener(m_dbg->GetListener()); lldb_private::ConstString broadcaster_class_target(lldb_private::Target::GetStaticBroadcasterClass()); lldb_private::ConstString broadcaster_class_process(lldb_private::Process::GetStaticBroadcasterClass()); lldb_private::ConstString broadcaster_class_thread(lldb_private::Thread::GetStaticBroadcasterClass()); lldb_private::BroadcastEventSpec target_event_spec (broadcaster_class_target, lldb_private::Target::eBroadcastBitBreakpointChanged); lldb_private::BroadcastEventSpec process_event_spec (broadcaster_class_process, lldb_private::Process::eBroadcastBitStateChanged | lldb_private::Process::eBroadcastBitSTDOUT | lldb_private::Process::eBroadcastBitSTDERR); lldb_private::BroadcastEventSpec thread_event_spec (broadcaster_class_thread, lldb_private::Thread::eBroadcastBitStackChanged | lldb_private::Thread::eBroadcastBitThreadSelected ); listener.StartListeningForEventSpec (*m_dbg, target_event_spec); listener.StartListeningForEventSpec (*m_dbg, process_event_spec); listener.StartListeningForEventSpec (*m_dbg, thread_event_spec); listener.StartListeningForEvents (&m_dbg->GetCommandInterpreter(), lldb_private::CommandInterpreter::eBroadcastBitQuitCommandReceived | lldb_private::CommandInterpreter::eBroadcastBitAsynchronousOutputData | lldb_private::CommandInterpreter::eBroadcastBitAsynchronousErrorData ); m_sync_broadcaster.BroadcastEvent(eBroadcastBitEventThreadIsListening); bool done = false; while (!done) { lldb::EventSP event_sp; if (listener.WaitForEvent(NULL, event_sp)) { if (event_sp) { lldb_private::Broadcaster *broadcaster = event_sp->GetBroadcaster(); if (broadcaster) { uint32_t event_type = event_sp->GetType(); lldb_private::ConstString broadcaster_class (broadcaster->GetBroadcasterClass()); if (broadcaster_class == broadcaster_class_process) { lldb::StreamSP output_stream_sp = m_dbg->GetAsyncOutputStream(); HandleProcessStateChangedEvent(event_sp,output_stream_sp.get()); } else if (broadcaster_class == broadcaster_class_target) { if (lldb_private::Breakpoint::BreakpointEventData::GetEventDataFromEvent(event_sp.get())) { m_dbg->HandleBreakpointEvent (event_sp); } } else if (broadcaster_class == broadcaster_class_thread) { //m_dbg->HandleThreadEvent (event_sp); } else if (broadcaster == &m_dbg->GetCommandInterpreter()) { if (event_type & lldb_private::CommandInterpreter::eBroadcastBitQuitCommandReceived) { done = true; } else if (event_type & lldb_private::CommandInterpreter::eBroadcastBitAsynchronousErrorData) { const char *data = reinterpret_cast<const char *>(lldb_private::EventDataBytes::GetBytesFromEvent (event_sp.get())); if (data && data[0]) { lldb::StreamSP error_sp (m_dbg->GetAsyncErrorStream()); if (error_sp) { error_sp->PutCString(data); error_sp->Flush(); } } } else if (event_type & lldb_private::CommandInterpreter::eBroadcastBitAsynchronousOutputData) { const char *data = reinterpret_cast<const char *>(lldb_private::EventDataBytes::GetBytesFromEvent (event_sp.get())); if (data && data[0]) { lldb::StreamSP output_sp (m_dbg->GetAsyncOutputStream()); if (output_sp) { output_sp->PutCString(data); output_sp->Flush(); } } } } } } } } }