Skip to content

Commit aca9129

Browse files
committed
Adjusting logging statements.
1 parent 1b896fb commit aca9129

File tree

2 files changed

+68
-67
lines changed

2 files changed

+68
-67
lines changed

lldb/tools/lldb-dap/EventHelper.cpp

Lines changed: 66 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -121,75 +121,76 @@ void SendProcessEvent(DAP &dap, LaunchMethod launch_method) {
121121
// is stopped.
122122
void SendThreadStoppedEvent(DAP &dap) {
123123
lldb::SBProcess process = dap.target.GetProcess();
124-
if (process.IsValid()) {
125-
auto state = process.GetState();
126-
if (state == lldb::eStateStopped) {
127-
llvm::DenseSet<lldb::tid_t> old_thread_ids;
128-
old_thread_ids.swap(dap.thread_ids);
129-
uint32_t stop_id = process.GetStopID();
130-
const uint32_t num_threads = process.GetNumThreads();
131-
132-
// First make a pass through the threads to see if the focused thread
133-
// has a stop reason. In case the focus thread doesn't have a stop
134-
// reason, remember the first thread that has a stop reason so we can
135-
// set it as the focus thread if below if needed.
136-
lldb::tid_t first_tid_with_reason = LLDB_INVALID_THREAD_ID;
137-
uint32_t num_threads_with_reason = 0;
138-
bool focus_thread_exists = false;
139-
for (uint32_t thread_idx = 0; thread_idx < num_threads; ++thread_idx) {
140-
lldb::SBThread thread = process.GetThreadAtIndex(thread_idx);
141-
const lldb::tid_t tid = thread.GetThreadID();
142-
const bool has_reason = ThreadHasStopReason(thread);
143-
// If the focus thread doesn't have a stop reason, clear the thread ID
144-
if (tid == dap.focus_tid) {
145-
focus_thread_exists = true;
146-
if (!has_reason)
147-
dap.focus_tid = LLDB_INVALID_THREAD_ID;
148-
}
149-
if (has_reason) {
150-
++num_threads_with_reason;
151-
if (first_tid_with_reason == LLDB_INVALID_THREAD_ID)
152-
first_tid_with_reason = tid;
153-
}
154-
}
124+
if (!process.IsValid()) {
125+
LLDB_LOG(GetLog(DAPLog::Protocol),
126+
"error: SendThreadStoppedEvent() invalid process");
127+
return;
128+
}
155129

156-
// We will have cleared dap.focus_tid if the focus thread doesn't have
157-
// a stop reason, so if it was cleared, or wasn't set, or doesn't exist,
158-
// then set the focus thread to the first thread with a stop reason.
159-
if (!focus_thread_exists || dap.focus_tid == LLDB_INVALID_THREAD_ID)
160-
dap.focus_tid = first_tid_with_reason;
161-
162-
// If no threads stopped with a reason, then report the first one so
163-
// we at least let the UI know we stopped.
164-
if (num_threads_with_reason == 0) {
165-
lldb::SBThread thread = process.GetThreadAtIndex(0);
166-
dap.focus_tid = thread.GetThreadID();
167-
dap.SendJSON(CreateThreadStopped(dap, thread, stop_id));
168-
} else {
169-
for (uint32_t thread_idx = 0; thread_idx < num_threads; ++thread_idx) {
170-
lldb::SBThread thread = process.GetThreadAtIndex(thread_idx);
171-
dap.thread_ids.insert(thread.GetThreadID());
172-
if (ThreadHasStopReason(thread)) {
173-
dap.SendJSON(CreateThreadStopped(dap, thread, stop_id));
174-
}
175-
}
176-
}
130+
auto state = process.GetState();
131+
if (state != lldb::eStateStopped) {
132+
LLDB_LOG(GetLog(DAPLog::Protocol),
133+
"error: SendThreadStoppedEvent() when process isn't stopped ({0})",
134+
lldb::SBDebugger::StateAsCString(state));
135+
return;
136+
}
177137

178-
for (auto tid : old_thread_ids) {
179-
auto end = dap.thread_ids.end();
180-
auto pos = dap.thread_ids.find(tid);
181-
if (pos == end)
182-
SendThreadExitedEvent(dap, tid);
183-
}
184-
} else {
185-
LLDB_LOG(GetLog(DAPLog::Protocol),
186-
"error: SendThreadStoppedEvent() when process"
187-
" isn't stopped ({0})",
188-
lldb::SBDebugger::StateAsCString(state));
138+
llvm::DenseSet<lldb::tid_t> old_thread_ids;
139+
old_thread_ids.swap(dap.thread_ids);
140+
uint32_t stop_id = process.GetStopID();
141+
const uint32_t num_threads = process.GetNumThreads();
142+
143+
// First make a pass through the threads to see if the focused thread
144+
// has a stop reason. In case the focus thread doesn't have a stop
145+
// reason, remember the first thread that has a stop reason so we can
146+
// set it as the focus thread if below if needed.
147+
lldb::tid_t first_tid_with_reason = LLDB_INVALID_THREAD_ID;
148+
uint32_t num_threads_with_reason = 0;
149+
bool focus_thread_exists = false;
150+
for (uint32_t thread_idx = 0; thread_idx < num_threads; ++thread_idx) {
151+
lldb::SBThread thread = process.GetThreadAtIndex(thread_idx);
152+
const lldb::tid_t tid = thread.GetThreadID();
153+
const bool has_reason = ThreadHasStopReason(thread);
154+
// If the focus thread doesn't have a stop reason, clear the thread ID
155+
if (tid == dap.focus_tid) {
156+
focus_thread_exists = true;
157+
if (!has_reason)
158+
dap.focus_tid = LLDB_INVALID_THREAD_ID;
159+
}
160+
if (has_reason) {
161+
++num_threads_with_reason;
162+
if (first_tid_with_reason == LLDB_INVALID_THREAD_ID)
163+
first_tid_with_reason = tid;
189164
}
165+
}
166+
167+
// We will have cleared dap.focus_tid if the focus thread doesn't have
168+
// a stop reason, so if it was cleared, or wasn't set, or doesn't exist,
169+
// then set the focus thread to the first thread with a stop reason.
170+
if (!focus_thread_exists || dap.focus_tid == LLDB_INVALID_THREAD_ID)
171+
dap.focus_tid = first_tid_with_reason;
172+
173+
// If no threads stopped with a reason, then report the first one so
174+
// we at least let the UI know we stopped.
175+
if (num_threads_with_reason == 0) {
176+
lldb::SBThread thread = process.GetThreadAtIndex(0);
177+
dap.focus_tid = thread.GetThreadID();
178+
dap.SendJSON(CreateThreadStopped(dap, thread, stop_id));
190179
} else {
191-
LLDB_LOG(GetLog(DAPLog::Protocol),
192-
"error: SendThreadStoppedEvent() invalid process");
180+
for (uint32_t thread_idx = 0; thread_idx < num_threads; ++thread_idx) {
181+
lldb::SBThread thread = process.GetThreadAtIndex(thread_idx);
182+
dap.thread_ids.insert(thread.GetThreadID());
183+
if (ThreadHasStopReason(thread)) {
184+
dap.SendJSON(CreateThreadStopped(dap, thread, stop_id));
185+
}
186+
}
187+
}
188+
189+
for (auto tid : old_thread_ids) {
190+
auto end = dap.thread_ids.end();
191+
auto pos = dap.thread_ids.find(tid);
192+
if (pos == end)
193+
SendThreadExitedEvent(dap, tid);
193194
}
194195
dap.RunStopCommands();
195196
}

lldb/tools/lldb-dap/lldb-dap.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ serveConnection(const Socket::SocketProtocol &protocol, const std::string &name,
308308
&clientCount](
309309
std::unique_ptr<Socket> sock) {
310310
std::string name = llvm::formatv("client_{0}", clientCount++).str();
311-
LLDB_LOG(GetLog(DAPLog::Connection), "client ({0}) connected", name);
311+
LLDB_LOG(GetLog(DAPLog::Connection), "{0} connected", name);
312312

313313
lldb::IOObjectSP io(std::move(sock));
314314

@@ -338,7 +338,7 @@ serveConnection(const Socket::SocketProtocol &protocol, const std::string &name,
338338
"DAP session error: ");
339339
}
340340

341-
LLDB_LOG(GetLog(DAPLog::Connection), "client ({0}) closed", name);
341+
LLDB_LOG(GetLog(DAPLog::Connection), "{0} closed", name);
342342

343343
std::unique_lock<std::mutex> lock(dap_sessions_mutex);
344344
dap_sessions.erase(io.get());

0 commit comments

Comments
 (0)