Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ using namespace lldb;
using namespace lldb_private;
using namespace lldb_private::process_gdb_remote;

static int id = 0;

// GDBRemoteCommunication constructor
GDBRemoteCommunication::GDBRemoteCommunication(llvm::StringRef name)
: Communication(),
Expand All @@ -54,7 +56,7 @@ GDBRemoteCommunication::GDBRemoteCommunication(llvm::StringRef name)
#endif
m_echo_number(0), m_supports_qEcho(eLazyBoolCalculate), m_history(512),
m_send_acks(true), m_is_platform(false),
m_compression_type(CompressionType::None), m_listen_url(), m_name(name) {
m_compression_type(CompressionType::None), m_listen_url(), m_name((name + std::to_string(id++)).str()) {
}

// Destructor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -917,6 +917,8 @@ lldb::pid_t GDBRemoteCommunicationClient::GetCurrentProcessID(bool allow_lazy) {
}

llvm::Error GDBRemoteCommunicationClient::LaunchProcess(const Args &args) {
m_launch_response.reset();

if (!args.GetArgumentAtIndex(0))
return llvm::createStringError(llvm::inconvertibleErrorCode(),
"Nothing to launch");
Expand All @@ -935,6 +937,8 @@ llvm::Error GDBRemoteCommunicationClient::LaunchProcess(const Args &args) {
return llvm::createStringError(llvm::inconvertibleErrorCode(),
"Sending vRun packet failed");

m_launch_response = response;

if (response.IsErrorResponse())
return response.GetStatus().ToError();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "lldb/Utility/GDBRemote.h"
#include "lldb/Utility/GPUGDBRemotePackets.h"
#include "lldb/Utility/ProcessInfo.h"
#include "lldb/Utility/StringExtractorGDBRemote.h"
#include "lldb/Utility/StructuredData.h"
#include "lldb/Utility/TraceGDBRemotePackets.h"
#include "lldb/Utility/UUID.h"
Expand Down Expand Up @@ -270,6 +271,10 @@ class GDBRemoteCommunicationClient : public GDBRemoteClientBase {
bool HasAnyVContSupport() { return GetVContSupported('a'); }

bool GetStopReply(StringExtractorGDBRemote &response);

std::optional<StringExtractorGDBRemote> GetLaunchResponse() {
return m_launch_response;
}

bool GetThreadStopInfo(lldb::tid_t tid, StringExtractorGDBRemote &response);

Expand Down Expand Up @@ -659,6 +664,7 @@ class GDBRemoteCommunicationClient : public GDBRemoteClientBase {
bool m_qXfer_memory_map_loaded = false;
// Used to pass a file descriptor from the GDB server back to the client.
std::optional<int> m_file_passing_fd;
std::optional<StringExtractorGDBRemote> m_launch_response;
bool GetCurrentProcessInfo(bool allow_lazy_pid = true);

bool GetGDBServerVersion();
Expand Down
13 changes: 10 additions & 3 deletions lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//===----------------------------------------------------------------------===//

#include "lldb/Host/Config.h"
#include "lldb/lldb-enumerations.h"

#include <cerrno>
#include <cstdlib>
Expand Down Expand Up @@ -821,7 +822,14 @@ Status ProcessGDBRemote::DoLaunch(lldb_private::Module *exe_module,
}

StringExtractorGDBRemote response;
if (m_gdb_comm.GetStopReply(response)) {
if (m_gdb_comm.GetLaunchResponse()) {
auto launch_response = *m_gdb_comm.GetLaunchResponse();
if (launch_response.GetChar() == 'T' || launch_response.GetChar() == 'S') {
response = launch_response;
}
}

if (response.IsNormalResponse() || m_gdb_comm.GetStopReply(response)) {
SetLastStopPacket(response);

const ArchSpec &process_arch = m_gdb_comm.GetProcessArchitecture();
Expand Down Expand Up @@ -6397,8 +6405,7 @@ void ProcessGDBRemote::SyncState::SetStateStopped(uint64_t stop_id) {

void ProcessGDBRemote::SyncState::DidResume() {
Log *log = GetLog(GDBRLog::Plugin);
std::lock_guard<std::mutex> guard(m_mutex);
m_state = lldb::eStateRunning;
SetStateImpl(m_stop_id.value_or(0), lldb::eStateRunning);
LLDB_LOG(log, "pid = {}, SyncState::{}() m_stop_id = {}, m_state = {}",
m_process.GetID(), __FUNCTION__, m_stop_id,
StateAsCString(m_state.value_or(lldb::eStateInvalid)));
Expand Down
26 changes: 17 additions & 9 deletions lldb/tools/lldb-server/Plugins/AMDGPU/LLDBServerPluginAMDGPU.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ bool LLDBServerPluginAMDGPU::initRocm() {
}

bool LLDBServerPluginAMDGPU::processGPUEvent() {
LLDB_LOGF(GetLog(GDBRLog::Plugin), "processGPUEvent");
LLDB_LOGF(GetLog(GDBRLog::Plugin), "processGPUEvent start");
char buf[256];
ssize_t bytesRead = 0;
bool result = false;
Expand All @@ -257,6 +257,7 @@ bool LLDBServerPluginAMDGPU::processGPUEvent() {
assert(status == AMD_DBGAPI_STATUS_SUCCESS);
break;
} while (true);
LLDB_LOGF(GetLog(GDBRLog::Plugin), "processGPUEvent end (result=%d)", result);
return result;
}

Expand Down Expand Up @@ -364,8 +365,12 @@ LLDBServerPluginAMDGPU::CreateConnection() {
}

std::optional<GPUActions> LLDBServerPluginAMDGPU::NativeProcessIsStopping() {
static bool initialized = false;
Log *log = GetLog(GDBRLog::Plugin);
if (!m_is_connected) {
LLDB_LOGF(log, "%s called: %d", __FUNCTION__, initialized);
if (!initialized) {
LLDB_LOGF(log, "%s initializing", __FUNCTION__);
initialized = true;
initRocm();
ProcessManagerAMDGPU *manager =
(ProcessManagerAMDGPU *)m_process_manager_up.get();
Expand Down Expand Up @@ -590,8 +595,8 @@ LLDBServerPluginAMDGPU::BreakpointWasHit(GPUPluginBreakpointHitArgs &args) {
const auto bp_identifier = args.breakpoint.identifier;
llvm::raw_string_ostream os(json_string);
os << toJSON(args);
LLDB_LOGF(log, "LLDBServerPluginAMDGPU::BreakpointWasHit(\"%s\"):\nJSON:\n%s",
bp_identifier.c_str(), json_string.c_str());
LLDB_LOGF(log, "LLDBServerPluginAMDGPU::BreakpointWasHit(\"%d\"):\nJSON:\n%s",
bp_identifier, json_string.c_str());

GPUPluginBreakpointHitResponse response;
response.actions.plugin_name = GetPluginName();
Expand All @@ -613,11 +618,14 @@ LLDBServerPluginAMDGPU::BreakpointWasHit(GPUPluginBreakpointHitArgs &args) {
bool success = HandleGPUInternalBreakpointHit(m_gpu_internal_bp.value());
assert(success);
if (GetGPUProcess()->HasDyldChangesToReport()) {
response.actions.wait_for_gpu_process_to_resume = true;
auto *process = m_gdb_server->GetCurrentProcess();
ThreadAMDGPU *thread = (ThreadAMDGPU *)process->GetCurrentThread();
thread->SetStopReason(lldb::eStopReasonDynamicLoader);
process->Halt();
if (GetGPUProcess()->IsRunning()) {
response.actions.wait_for_gpu_process_to_resume = true;
response.actions.stop_id = GetGPUProcess()->GetNextStopID();
auto *process = m_gdb_server->GetCurrentProcess();
ThreadAMDGPU *thread = (ThreadAMDGPU *)process->GetCurrentThread();
thread->SetStopReason(lldb::eStopReasonDynamicLoader);
process->Halt();
}
}
}
return response;
Expand Down