LLDB mainline
ProcessWindows.cpp
Go to the documentation of this file.
1//===-- ProcessWindows.cpp ------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#include "ProcessWindows.h"
10
11// Windows includes
13#include <psapi.h>
14
16#include "lldb/Core/IOHandler.h"
17#include "lldb/Core/Module.h"
20#include "lldb/Core/Section.h"
22#include "lldb/Host/HostInfo.h"
25#include "lldb/Host/Pipe.h"
33#include "lldb/Target/Target.h"
35#include "lldb/Utility/Log.h"
36#include "lldb/Utility/State.h"
37
38#include "llvm/Support/ConvertUTF.h"
39#include "llvm/Support/ErrorExtras.h"
40#include "llvm/Support/Format.h"
41#include "llvm/Support/Threading.h"
42#include "llvm/Support/raw_ostream.h"
43
44#include "DebuggerThread.h"
45#include "ExceptionRecord.h"
46#include "ForwardDecl.h"
47#include "LocalDebugDelegate.h"
48#include "ProcessWindowsLog.h"
49#include "TargetThreadWindows.h"
50
51using namespace lldb;
52using namespace lldb_private;
53
54LLDB_PLUGIN_DEFINE_ADV(ProcessWindows, ProcessWindowsCommon)
55
56namespace {
57std::string GetProcessExecutableName(HANDLE process_handle) {
58 std::vector<wchar_t> file_name;
59 DWORD file_name_size = MAX_PATH; // first guess, not an absolute limit
60 DWORD copied = 0;
61 do {
62 file_name_size *= 2;
63 file_name.resize(file_name_size);
64 copied = ::GetModuleFileNameExW(process_handle, nullptr, file_name.data(),
65 file_name_size);
66 } while (copied >= file_name_size);
67 file_name.resize(copied);
68 std::string result;
69 llvm::convertWideToUTF8(file_name.data(), result);
70 return result;
71}
72
73std::string GetProcessExecutableName(DWORD pid) {
74 std::string file_name;
75 HANDLE process_handle =
76 ::OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, pid);
77 if (process_handle != nullptr) {
78 file_name = GetProcessExecutableName(process_handle);
79 ::CloseHandle(process_handle);
80 }
81 return file_name;
82}
83} // anonymous namespace
84
85namespace lldb_private {
86
88 lldb::ListenerSP listener_sp,
89 const FileSpec *crash_file_path,
90 bool can_connect) {
91 if (crash_file_path)
92 return nullptr; // Cannot create a Windows process from a crash_file.
93 return ProcessSP(new ProcessWindows(target_sp, listener_sp));
94}
95
96static bool ShouldUseLLDBServer() {
97 llvm::StringRef use_lldb_server = ::getenv("LLDB_USE_LLDB_SERVER");
98 return use_lldb_server.equals_insensitive("on") ||
99 use_lldb_server.equals_insensitive("yes") ||
100 use_lldb_server.equals_insensitive("1") ||
101 use_lldb_server.equals_insensitive("true");
102}
103
110
115
117 return "Process plugin for Windows";
118}
119
120// Constructors and destructors.
121
123 lldb::ListenerSP listener_sp)
124 : lldb_private::Process(target_sp, listener_sp),
126 RegisterContextWindows::GetNumHardwareBreakpointSlots(),
128
130
132 if (bp_site->HardwareRequired())
133 return Status::FromErrorString("Hardware breakpoints are not supported.");
134
136 LLDB_LOG(log, "bp_site = {0:x}, id={1}, addr={2:x}", bp_site,
137 bp_site->GetID(), bp_site->GetLoadAddress());
138
140 if (!error.Success())
141 LLDB_LOG(log, "error: {0}", error);
142 return error;
143}
144
147 LLDB_LOG(log, "bp_site = {0:x}, id={1}, addr={2:x}", bp_site,
148 bp_site->GetID(), bp_site->GetLoadAddress());
149
151
152 if (!error.Success())
153 LLDB_LOG(log, "error: {0}", error);
154 return error;
155}
156
160 StateType private_state = GetPrivateState();
161 if (private_state != eStateExited && private_state != eStateDetached) {
162 if (!keep_stopped) {
163 // if the thread is suspended by lldb, we have to resume threads before
164 // detaching process. When we do after DetachProcess(), thread handles
165 // become invalid so we do before detach.
166 if (private_state == eStateStopped || private_state == eStateCrashed) {
167 LLDB_LOG(log, "process {0} is in state {1}. Resuming for detach...",
168 m_session_data->m_debugger->GetProcess().GetProcessId(),
170
171 LLDB_LOG(log, "resuming {0} threads for detach.",
172 m_thread_list.GetSize());
173
174 bool failed = false;
175 for (uint32_t i = 0; i < m_thread_list.GetSize(); ++i) {
176 auto thread = std::static_pointer_cast<TargetThreadWindows>(
177 m_thread_list.GetThreadAtIndex(i));
178 Status result = thread->DoResume();
179 if (result.Fail()) {
180 failed = true;
181 LLDB_LOG(log,
182 "Trying to resume thread at index {0}, but failed with "
183 "error {1}.",
184 i, result);
185 }
186 }
187
188 if (failed) {
189 error = Status::FromErrorString("Resuming Threads for Detach failed");
190 }
191 }
192 }
193
195 if (error.Success())
197 else
198 LLDB_LOG(log, "Detaching process error: {0}", error);
199 } else {
201 "error: process {0} in state = {1}, but "
202 "cannot detach it in this state.",
203 GetID(), private_state);
204 LLDB_LOG(log, "error: {0}", error);
205 }
206 return error;
207}
208
210 ProcessLaunchInfo &launch_info) {
212 DebugDelegateSP delegate(new LocalDebugDelegate(shared_from_this()));
213 error = LaunchProcess(launch_info, delegate);
214 if (error.Success())
215 SetID(launch_info.GetProcessID());
216 m_pty = launch_info.TakePTY();
217 return error;
218}
219
220Status
222 const ProcessAttachInfo &attach_info) {
223 DebugDelegateSP delegate(new LocalDebugDelegate(shared_from_this()));
224 Status error = AttachProcess(pid, attach_info, delegate);
225 if (error.Success())
227 return error;
228}
229
232 llvm::sys::ScopedLock lock(m_mutex);
233
234 if (direction == RunDirection::eRunReverse) {
236 "{0} does not support reverse execution of processes", GetPluginName());
237 }
238
240
241 StateType private_state = GetPrivateState();
242 if (private_state == eStateStopped || private_state == eStateCrashed) {
243 LLDB_LOG(log, "process {0} is in state {1}. Resuming...",
244 m_session_data->m_debugger->GetProcess().GetProcessId(),
246
247 LLDB_LOG(log, "resuming {0} threads.", m_thread_list.GetSize());
248
249 bool failed = false;
250 for (uint32_t i = 0; i < m_thread_list.GetSize(); ++i) {
251 auto thread = std::static_pointer_cast<TargetThreadWindows>(
252 m_thread_list.GetThreadAtIndex(i));
253 Status result = thread->DoResume();
254 if (result.Fail()) {
255 failed = true;
256 LLDB_LOG(
257 log,
258 "Trying to resume thread at index {0}, but failed with error {1}.",
259 i, result);
260 }
261 }
262
263 if (failed) {
264 error = Status::FromErrorString("ProcessWindows::DoResume failed");
265 } else {
267 }
268
269 ExceptionRecordSP active_exception =
270 m_session_data->m_debugger->GetActiveException().lock();
271 if (active_exception) {
272 // Resume the process and continue processing debug events. Mask the
273 // exception so that from the process's view, there is no indication that
274 // anything happened.
275 m_session_data->m_debugger->ContinueAsyncException(
277 }
278 } else {
279 LLDB_LOG(log, "error: process {0} is in state {1}. Returning...",
280 m_session_data->m_debugger->GetProcess().GetProcessId(),
282 }
283 return error;
284}
285
287 StateType private_state = GetPrivateState();
288 return DestroyProcess(private_state);
289}
290
291Status ProcessWindows::DoHalt(bool &caused_stop) {
292 StateType state = GetPrivateState();
293 if (state != eStateStopped)
294 return HaltProcess(caused_stop);
295 caused_stop = false;
296 return Status();
297}
298
300 ArchSpec arch_spec;
301 DidAttach(arch_spec);
302}
303
305 llvm::sys::ScopedLock lock(m_mutex);
306
307 // The initial stop won't broadcast the state change event, so account for
308 // that here.
310 m_session_data->m_stop_at_entry)
312}
313
314static void
315DumpAdditionalExceptionInformation(llvm::raw_ostream &stream,
316 const ExceptionRecordSP &exception) {
317 // Decode additional exception information for specific exception types based
318 // on
319 // https://docs.microsoft.com/en-us/windows/desktop/api/winnt/ns-winnt-_exception_record
320
321 const int addr_min_width = 2 + 8; // "0x" + 4 address bytes
322
323 const std::vector<ULONG_PTR> &args = exception->GetExceptionArguments();
324 switch (exception->GetExceptionCode()) {
325 case EXCEPTION_ACCESS_VIOLATION: {
326 if (args.size() < 2)
327 break;
328
329 stream << ": ";
330 const int access_violation_code = args[0];
331 const lldb::addr_t access_violation_address = args[1];
332 switch (access_violation_code) {
333 case 0:
334 stream << "Access violation reading";
335 break;
336 case 1:
337 stream << "Access violation writing";
338 break;
339 case 8:
340 stream << "User-mode data execution prevention (DEP) violation at";
341 break;
342 default:
343 stream << "Unknown access violation (code " << access_violation_code
344 << ") at";
345 break;
346 }
347 stream << " location "
348 << llvm::format_hex(access_violation_address, addr_min_width);
349 break;
350 }
351 case EXCEPTION_IN_PAGE_ERROR: {
352 if (args.size() < 3)
353 break;
354
355 stream << ": ";
356 const int page_load_error_code = args[0];
357 const lldb::addr_t page_load_error_address = args[1];
358 const DWORD underlying_code = args[2];
359 switch (page_load_error_code) {
360 case 0:
361 stream << "In page error reading";
362 break;
363 case 1:
364 stream << "In page error writing";
365 break;
366 case 8:
367 stream << "User-mode data execution prevention (DEP) violation at";
368 break;
369 default:
370 stream << "Unknown page loading error (code " << page_load_error_code
371 << ") at";
372 break;
373 }
374 stream << " location "
375 << llvm::format_hex(page_load_error_address, addr_min_width)
376 << " (status code " << llvm::format_hex(underlying_code, 8) << ")";
377 break;
378 }
379 }
380}
381
384 llvm::sys::ScopedLock lock(m_mutex);
385
386 if (!m_session_data) {
387 LLDB_LOG(log, "no active session. Returning...");
388 return;
389 }
390
391 m_thread_list.RefreshStateAfterStop();
392
393 std::weak_ptr<ExceptionRecord> exception_record =
394 m_session_data->m_debugger->GetActiveException();
395 ExceptionRecordSP active_exception = exception_record.lock();
396 if (!active_exception) {
397 LLDB_LOG(log,
398 "there is no active exception in process {0}. Why is the "
399 "process stopped?",
400 m_session_data->m_debugger->GetProcess().GetProcessId());
401 return;
402 }
403
404 StopInfoSP stop_info;
405 m_thread_list.SetSelectedThreadByID(active_exception->GetThreadID());
406 ThreadSP stop_thread = m_thread_list.GetSelectedThread();
407 if (!stop_thread)
408 return;
409
410 RegisterContextSP register_context = stop_thread->GetRegisterContext();
411 uint64_t pc = register_context->GetPC();
412
413 // If we're at a BreakpointSite, mark this as an Unexecuted Breakpoint.
414 // We'll clear that state if we've actually executed the breakpoint.
415 BreakpointSiteSP site(GetBreakpointSiteList().FindByAddress(pc));
416 if (site && IsBreakpointSitePhysicallyEnabled(*site))
417 stop_thread->SetThreadStoppedAtUnexecutedBP(pc);
418
419 switch (active_exception->GetExceptionCode()) {
420 case EXCEPTION_SINGLE_STEP: {
421 auto *reg_ctx = static_cast<RegisterContextWindows *>(
422 stop_thread->GetRegisterContext().get());
423 uint32_t slot_id = reg_ctx->GetTriggeredHardwareBreakpointSlotId();
424 if (slot_id != LLDB_INVALID_INDEX32) {
425 int id = m_watchpoint_ids[slot_id];
426 LLDB_LOG(log,
427 "Single-stepped onto a watchpoint in process {0} at address "
428 "{1:x} with watchpoint {2}",
429 m_session_data->m_debugger->GetProcess().GetProcessId(), pc, id);
430
431 stop_info = StopInfo::CreateStopReasonWithWatchpointID(*stop_thread, id);
432 stop_thread->SetStopInfo(stop_info);
433
434 return;
435 }
436
437 LLDB_LOG(log, "single stepping thread {0}", stop_thread->GetID());
438 stop_info = StopInfo::CreateStopReasonToTrace(*stop_thread);
439 stop_thread->SetStopInfo(stop_info);
440
441 return;
442 }
443
444 case EXCEPTION_BREAKPOINT: {
445 int breakpoint_size = 1;
446 switch (GetTarget().GetArchitecture().GetMachine()) {
447 case llvm::Triple::aarch64:
448 breakpoint_size = 4;
449 break;
450
451 case llvm::Triple::arm:
452 case llvm::Triple::thumb:
453 breakpoint_size = 2;
454 break;
455
456 case llvm::Triple::x86:
457 case llvm::Triple::x86_64:
458 breakpoint_size = 1;
459 break;
460
461 default:
462 LLDB_LOG(log, "Unknown breakpoint size for architecture");
463 break;
464 }
465
466 // The current PC is AFTER the BP opcode, on all architectures.
467 pc = register_context->GetPC() - breakpoint_size;
468
470 if (site) {
471 LLDB_LOG(log,
472 "detected breakpoint in process {0} at address {1:x} with "
473 "breakpoint site {2}",
474 m_session_data->m_debugger->GetProcess().GetProcessId(), pc,
475 site->GetID());
476
477 stop_thread->SetThreadHitBreakpointSite();
478 if (site->ValidForThisThread(*stop_thread)) {
479 LLDB_LOG(log,
480 "Breakpoint site {0} is valid for this thread ({1:x}), "
481 "creating stop info.",
482 site->GetID(), stop_thread->GetID());
483
485 *stop_thread, site->GetID());
486 register_context->SetPC(pc);
487 } else {
488 LLDB_LOG(log,
489 "Breakpoint site {0} is not valid for this thread, "
490 "creating empty stop info.",
491 site->GetID());
492 }
493 stop_thread->SetStopInfo(stop_info);
494 return;
495 } else {
496 // The thread hit a hard-coded breakpoint like an `int 3` or
497 // `__debugbreak()`.
498 LLDB_LOG(log,
499 "No breakpoint site matches for this thread. __debugbreak()? "
500 "Creating stop info with the exception.");
501 // FALLTHROUGH: We'll treat this as a generic exception record in the
502 // default case.
503 [[fallthrough]];
504 }
505 }
506
507 default: {
508 std::string desc;
509 llvm::raw_string_ostream desc_stream(desc);
510 desc_stream << "Exception "
511 << llvm::format_hex(active_exception->GetExceptionCode(), 8)
512 << " encountered at address "
513 << llvm::format_hex(active_exception->GetExceptionAddress(), 8);
514 DumpAdditionalExceptionInformation(desc_stream, active_exception);
515
516 stop_info =
517 StopInfo::CreateStopReasonWithException(*stop_thread, desc.c_str());
518 stop_thread->SetStopInfo(stop_info);
519 LLDB_LOG(log, "{0}", desc);
520 return;
521 }
522 }
523}
524
526 bool plugin_specified_by_name) {
527 if (plugin_specified_by_name)
528 return true;
529
530 // For now we are just making sure the file exists for a given module
531 ModuleSP exe_module_sp(target_sp->GetExecutableModule());
532 if (exe_module_sp.get())
533 return FileSystem::Instance().Exists(exe_module_sp->GetFileSpec());
534 // However, if there is no executable module, we return true since we might
535 // be preparing to attach.
536 return true;
537}
538
540 ThreadList &new_thread_list) {
542 // Add all the threads that were previously running and for which we did not
543 // detect a thread exited event.
544 int new_size = 0;
545 int continued_threads = 0;
546 int exited_threads = 0;
547 int new_threads = 0;
548
549 for (ThreadSP old_thread : old_thread_list.Threads()) {
550 lldb::tid_t old_thread_id = old_thread->GetID();
551 auto exited_thread_iter =
552 m_session_data->m_exited_threads.find(old_thread_id);
553 if (exited_thread_iter == m_session_data->m_exited_threads.end()) {
554 new_thread_list.AddThread(old_thread);
555 ++new_size;
556 ++continued_threads;
557 LLDB_LOG_VERBOSE(log, "Thread {0} was running and is still running.",
558 old_thread_id);
559 } else {
560 LLDB_LOG_VERBOSE(log, "Thread {0} was running and has exited.",
561 old_thread_id);
562 ++exited_threads;
563 }
564 }
565
566 // Also add all the threads that are new since the last time we broke into
567 // the debugger.
568 for (const auto &thread_info : m_session_data->m_new_threads) {
569 new_thread_list.AddThread(thread_info.second);
570 ++new_size;
571 ++new_threads;
572 LLDB_LOG_VERBOSE(log, "Thread {0} is new since last update.",
573 thread_info.first);
574 }
575
576 LLDB_LOG(log, "{0} new threads, {1} old threads, {2} exited threads.",
577 new_threads, continued_threads, exited_threads);
578
579 m_session_data->m_new_threads.clear();
580 m_session_data->m_exited_threads.clear();
581
582 return new_size > 0;
583}
584
586 StateType state = GetPrivateState();
587 switch (state) {
588 case eStateCrashed:
589 case eStateDetached:
590 case eStateUnloaded:
591 case eStateExited:
592 case eStateInvalid:
593 return false;
594 default:
595 return true;
596 }
597}
598
600 return HostInfo::GetArchitecture();
601}
602
604 size_t size, Status &error) {
605 size_t bytes_read = 0;
606 error = ProcessDebugger::ReadMemory(vm_addr, buf, size, bytes_read);
607 return bytes_read;
608}
609
610size_t ProcessWindows::DoWriteMemory(lldb::addr_t vm_addr, const void *buf,
611 size_t size, Status &error) {
612 size_t bytes_written = 0;
613 error = ProcessDebugger::WriteMemory(vm_addr, buf, size, bytes_written);
614 return bytes_written;
615}
616
617lldb::addr_t ProcessWindows::DoAllocateMemory(size_t size, uint32_t permissions,
618 Status &error) {
620 error = ProcessDebugger::AllocateMemory(size, permissions, vm_addr);
621 return vm_addr;
622}
623
627
632
634 Target &target = GetTarget();
635 ObjectFile *obj_file = target.GetExecutableModule()->GetObjectFile();
636 Address addr = obj_file->GetImageInfoAddress(&target);
637 if (addr.IsValid())
638 return addr.GetLoadAddress(&target);
639 else
641}
642
649
650void ProcessWindows::OnExitProcess(uint32_t exit_code) {
651 // No need to acquire the lock since m_session_data isn't accessed.
653 LLDB_LOG(log, "Process {0} exited with code {1}", GetID(), exit_code);
654
655 if (m_pty) {
657 m_pty->SetStopping(true);
658 m_pty->Close();
659 m_stdio_communication.InterruptRead();
660 m_stdio_communication.StopReadThread();
661 }
662
663 TargetSP target = CalculateTarget();
664 if (target) {
665 ModuleSP executable_module = target->GetExecutableModule();
666 ModuleList unloaded_modules;
667 unloaded_modules.Append(executable_module);
668 target->ModulesDidUnload(unloaded_modules, true);
669 }
670
671 SetExitStatus(exit_code, /*exit_string=*/"");
673
675}
676
678 if (!m_stdio_communication.ReadThreadIsRunning())
679 return;
680 m_stdio_communication.SynchronizeWithReadThread();
681 if (!m_pty || m_pty->GetMode() != PseudoConsole::Mode::ConPTY)
682 return;
683
684 HANDLE pipe = m_pty->GetSTDOUTHandle();
685 for (int consec_empty = 0; consec_empty < 3;) {
686 if (!m_stdio_communication.ReadThreadIsRunning())
687 break;
688 DWORD avail = 0;
689 // PeekNamedPipe is thread safe.
690 if (!::PeekNamedPipe(pipe, nullptr, 0, nullptr, &avail, nullptr))
691 break;
692 if (avail > 0) {
693 consec_empty = 0;
694 m_stdio_communication.SynchronizeWithReadThread();
695 } else {
696 ++consec_empty;
697 if (consec_empty < 3)
698 ::SleepEx(1, FALSE);
699 }
700 }
701}
702
704 DebuggerThreadSP debugger = m_session_data->m_debugger;
706 LLDB_LOG(log, "Debugger connected to process {0}. Image base = {1:x}",
707 debugger->GetProcess().GetProcessId(), image_base);
708
709 ModuleSP module;
710 // During attach, we won't have the executable module, so find it now.
711 const DWORD pid = debugger->GetProcess().GetProcessId();
712 const std::string file_name = GetProcessExecutableName(pid);
713 if (file_name.empty()) {
714 return;
715 }
716
717 FileSpec executable_file(file_name);
718 FileSystem::Instance().Resolve(executable_file);
719 ModuleSpec module_spec(executable_file);
721 module =
722 GetTarget().GetOrCreateModule(module_spec, true /* notify */, &error);
723 if (!module) {
724 return;
725 }
726
728
729 if (auto dyld = GetDynamicLoader())
730 dyld->OnLoadModule(module, ModuleSpec(), image_base);
731
732 // Add the main executable module to the list of pending module loads. We
733 // can't call GetTarget().ModulesDidLoad() here because we still haven't
734 // returned from DoLaunch() / DoAttach() yet so the target may not have set
735 // the process instance to `this` yet.
736 llvm::sys::ScopedLock lock(m_mutex);
737
738 const HostThread &host_main_thread = debugger->GetMainThread();
739 ThreadSP main_thread =
740 std::make_shared<TargetThreadWindows>(*this, host_main_thread);
741
742 tid_t id = host_main_thread.GetNativeThread().GetThreadId();
743 main_thread->SetID(id);
744
745 m_session_data->m_new_threads[id] = main_thread;
746}
747
750 const ExceptionRecord &record) {
752 llvm::sys::ScopedLock lock(m_mutex);
753
754 // FIXME: Without this check, occasionally when running the test suite there
755 // is
756 // an issue where m_session_data can be null. It's not clear how this could
757 // happen but it only surfaces while running the test suite. In order to
758 // properly diagnose this, we probably need to first figure allow the test
759 // suite to print out full lldb logs, and then add logging to the process
760 // plugin.
761 if (!m_session_data) {
762 LLDB_LOG(log,
763 "Debugger thread reported exception {0:x} at address {1:x}, "
764 "but there is no session.",
765 record.GetExceptionCode(), record.GetExceptionAddress());
767 }
768
769 if (!first_chance) {
770 // Not any second chance exception is an application crash by definition.
771 // It may be an expression evaluation crash.
774 }
775
777 switch (record.GetExceptionCode()) {
778 case EXCEPTION_BREAKPOINT:
779 // Handle breakpoints at the first chance.
781
782 if (!m_session_data->m_initial_stop_received) {
783 LLDB_LOG(
784 log,
785 "Hit loader breakpoint at address {0:x}, setting initial stop event.",
786 record.GetExceptionAddress());
787 m_session_data->m_initial_stop_received = true;
788 ::SetEvent(m_session_data->m_initial_stop_event);
789 } else {
790 LLDB_LOG(log, "Hit non-loader breakpoint at address {0:x}.",
791 record.GetExceptionAddress());
792 }
793 // Drain any in-flight process output before announcing the stop. The I/O
794 // reader thread and this debug-event thread run concurrently. Without
795 // synchronization the eBroadcastBitStateChanged(Stopped) event can reach
796 // the Debugger event thread before the preceding eBroadcastBitSTDOUT
797 // events.
800 break;
801 case EXCEPTION_SINGLE_STEP:
805 break;
806 default:
807 LLDB_LOG(log,
808 "Debugger thread reported exception {0:x} at address {1:x} "
809 "(first_chance={2})",
810 record.GetExceptionCode(), record.GetExceptionAddress(),
811 first_chance);
812 // For non-breakpoints, give the application a chance to handle the
813 // exception first.
814 if (first_chance)
816 else
818 }
819
820 return result;
821}
822
824 llvm::sys::ScopedLock lock(m_mutex);
825
826 ThreadSP thread = std::make_shared<TargetThreadWindows>(*this, new_thread);
827
828 const HostNativeThread &native_new_thread = new_thread.GetNativeThread();
829 tid_t id = native_new_thread.GetThreadId();
830 thread->SetID(id);
831
832 m_session_data->m_new_threads[id] = thread;
833
834 for (const std::map<int, WatchpointInfo>::value_type &p : m_watchpoints) {
835 auto *reg_ctx = static_cast<RegisterContextWindows *>(
836 thread->GetRegisterContext().get());
837 reg_ctx->AddHardwareBreakpoint(p.second.slot_id, p.second.address,
838 p.second.size, p.second.read,
839 p.second.write);
840 }
841}
842
843void ProcessWindows::OnExitThread(lldb::tid_t thread_id, uint32_t exit_code) {
844 llvm::sys::ScopedLock lock(m_mutex);
845
846 // On a forced termination, we may get exit thread events after the session
847 // data has been cleaned up.
848 if (!m_session_data)
849 return;
850
851 // A thread may have started and exited before the debugger stopped allowing a
852 // refresh.
853 // Just remove it from the new threads list in that case.
854 auto iter = m_session_data->m_new_threads.find(thread_id);
855 if (iter != m_session_data->m_new_threads.end())
856 m_session_data->m_new_threads.erase(iter);
857 else
858 m_session_data->m_exited_threads.insert(thread_id);
859}
860
861void ProcessWindows::OnLoadDll(const ModuleSpec &module_spec,
862 lldb::addr_t module_addr) {
863 if (auto dyld = GetDynamicLoader())
864 dyld->OnLoadModule(nullptr, module_spec, module_addr);
865}
866
868 if (auto dyld = GetDynamicLoader())
869 dyld->OnUnloadModule(module_addr);
870}
871
873 bool is_unicode,
874 uint16_t length_lower_word) {
876
877 llvm::SmallVector<char, 256> buffer;
878 llvm::Error err =
879 ReadDebugString(debug_string_addr, is_unicode, length_lower_word, buffer);
880 if (err) {
881 LLDB_LOG_ERROR(log, std::move(err),
882 "Failed to read debug string at {1:x} (size & 0xffff={2}, "
883 "unicode={3}): {0}",
884 debug_string_addr, length_lower_word, is_unicode);
885 return;
886 }
887 if (buffer.empty())
888 return;
889
890 if (is_unicode) {
891 assert(buffer.size() % 2 == 0);
892 llvm::ArrayRef<unsigned short> utf16(
893 reinterpret_cast<const unsigned short *>(buffer.data()),
894 buffer.size() / 2);
895 std::string out;
896 if (!llvm::convertUTF16ToUTF8String(utf16, out)) {
897 LLDB_LOG(log, "Debug string is not valid Utf 16");
898 return;
899 }
900
901 AppendSTDOUT(out.data(), out.size());
902 } else {
903 AppendSTDOUT(buffer.data(), buffer.size());
904 }
905}
906
907llvm::Error
908ProcessWindows::ReadDebugString(lldb::addr_t debug_string_addr, bool is_unicode,
909 uint16_t length_lower_word,
911 if (is_unicode && length_lower_word % 2 != 0)
912 return llvm::createStringError(
913 "Utf16 string can't have uneven size in bytes");
914
915 const auto is_zero_terminated = [&] {
916 // The zero terminator is always at the end of the buffer.
917 if (is_unicode)
918 return output.size() >= 2 && output.back() == 0 &&
919 output[output.size() - 2] == 0;
920
921 return !output.empty() && output.back() == 0;
922 };
923
924 // Read at most 1 MiB ((1 << 16) * 16 - 1 Bytes) since we don't know the exact
925 // size of the string. We know that `strlen(string) & 0xffff ==
926 // length_lower_word`, so we read in chunks until we reach the terminator:
927 // - 0: `length_lower_word` Bytes
928 // - 1..16: 64 KiB (= 2^16 Bytes)
929 size_t start = length_lower_word == 0 ? 1 : 0;
930 for (size_t i = start; i < 16; ++i) {
931 output.resize_for_overwrite(length_lower_word + i * (1 << 16));
932 size_t chunk_size = i == 0 ? length_lower_word : (1 << 16);
933 lldb::addr_t addr = debug_string_addr + output.size_in_bytes() - chunk_size;
934
936 size_t bytes_read =
937 DoReadMemory(addr, output.end() - chunk_size, chunk_size, error);
938 if (error.Fail())
939 return error.takeError();
940
941 if (bytes_read != chunk_size) {
942 return llvm::createStringErrorV(
943 "Expected to read {0} bytes, but read {1}", chunk_size, bytes_read);
944 }
945
946 if (is_zero_terminated())
947 break;
948 }
949
950 if (!is_zero_terminated())
951 return llvm::createStringError("String is 1 MiB or larger");
952
953 // Remove null terminator.
954 output.pop_back_n(is_unicode ? 2 : 1);
955 return llvm::Error::success();
956}
957
958void ProcessWindows::OnDebuggerError(const Status &error, uint32_t type) {
959 llvm::sys::ScopedLock lock(m_mutex);
961
962 if (m_session_data->m_initial_stop_received) {
963 // This happened while debugging. Do we shutdown the debugging session,
964 // try to continue, or do something else?
965 LLDB_LOG(log,
966 "Error {0} occurred during debugging. Unexpected behavior "
967 "may result. {1}",
968 error.GetError(), error);
969 } else {
970 // If we haven't actually launched the process yet, this was an error
971 // launching the process. Set the internal error and signal the initial
972 // stop event so that the DoLaunch method wakes up and returns a failure.
973 m_session_data->m_launch_error = error.Clone();
974 ::SetEvent(m_session_data->m_initial_stop_event);
975 LLDB_LOG(
976 log,
977 "Error {0} occurred launching the process before the initial stop. {1}",
978 error.GetError(), error);
979 return;
980 }
981}
982
986
987std::optional<DWORD> ProcessWindows::GetActiveExceptionCode() const {
988 if (!m_session_data || !m_session_data->m_debugger)
989 return std::nullopt;
990 auto exc = m_session_data->m_debugger->GetActiveException().lock();
991 if (!exc)
992 return std::nullopt;
993 return exc->GetExceptionCode();
994}
995
998
999 if (wp_sp->IsEnabled()) {
1000 wp_sp->SetEnabled(true, notify);
1001 return error;
1002 }
1003
1004 WatchpointInfo info;
1005 for (info.slot_id = 0;
1007 info.slot_id++)
1009 break;
1012 "Can't find free slot for watchpoint %i", wp_sp->GetID());
1013 return error;
1014 }
1015 info.address = wp_sp->GetLoadAddress();
1016 info.size = wp_sp->GetByteSize();
1017 info.read = wp_sp->WatchpointRead();
1018 info.write = wp_sp->WatchpointWrite() || wp_sp->WatchpointModify();
1019
1020 for (unsigned i = 0U; i < m_thread_list.GetSize(); i++) {
1021 Thread *thread = m_thread_list.GetThreadAtIndex(i).get();
1022 auto *reg_ctx = static_cast<RegisterContextWindows *>(
1023 thread->GetRegisterContext().get());
1024 if (!reg_ctx->AddHardwareBreakpoint(info.slot_id, info.address, info.size,
1025 info.read, info.write)) {
1027 "Can't enable watchpoint %i on thread 0x%llx", wp_sp->GetID(),
1028 thread->GetID());
1029 break;
1030 }
1031 }
1032 if (error.Fail()) {
1033 for (unsigned i = 0U; i < m_thread_list.GetSize(); i++) {
1034 Thread *thread = m_thread_list.GetThreadAtIndex(i).get();
1035 auto *reg_ctx = static_cast<RegisterContextWindows *>(
1036 thread->GetRegisterContext().get());
1037 reg_ctx->RemoveHardwareBreakpoint(info.slot_id);
1038 }
1039 return error;
1040 }
1041
1042 m_watchpoints[wp_sp->GetID()] = info;
1043 m_watchpoint_ids[info.slot_id] = wp_sp->GetID();
1044
1045 wp_sp->SetEnabled(true, notify);
1046
1047 return error;
1048}
1049
1051 Status error;
1052
1053 if (!wp_sp->IsEnabled()) {
1054 wp_sp->SetEnabled(false, notify);
1055 return error;
1056 }
1057
1058 auto it = m_watchpoints.find(wp_sp->GetID());
1059 if (it == m_watchpoints.end()) {
1061 "Info about watchpoint %i is not found", wp_sp->GetID());
1062 return error;
1063 }
1064
1065 for (unsigned i = 0U; i < m_thread_list.GetSize(); i++) {
1066 Thread *thread = m_thread_list.GetThreadAtIndex(i).get();
1067 auto *reg_ctx = static_cast<RegisterContextWindows *>(
1068 thread->GetRegisterContext().get());
1069 if (!reg_ctx->RemoveHardwareBreakpoint(it->second.slot_id)) {
1071 "Can't disable watchpoint %i on thread 0x%llx", wp_sp->GetID(),
1072 thread->GetID());
1073 break;
1074 }
1075 }
1076 if (error.Fail())
1077 return error;
1078
1079 m_watchpoint_ids[it->second.slot_id] = LLDB_INVALID_BREAK_ID;
1080 m_watchpoints.erase(it);
1081
1082 wp_sp->SetEnabled(false, notify);
1083
1084 return error;
1085}
1086
1088public:
1090 : IOHandler(process->GetTarget().GetDebugger(),
1092 m_process(process),
1093 m_read_file(GetInputFD(), File::eOpenOptionReadOnly, false),
1094 m_write_file(conpty_input),
1096 CreateEvent(/*lpEventAttributes=*/nullptr, /*bManualReset=*/FALSE,
1097 /*bInitialState=*/FALSE, /*lpName=*/nullptr)) {}
1098
1100 if (m_interrupt_event != INVALID_HANDLE_VALUE)
1101 ::CloseHandle(m_interrupt_event);
1102 }
1103
1104 void SetIsRunning(bool running) {
1105 std::lock_guard<std::mutex> guard(m_mutex);
1106 SetIsDone(!running);
1107 m_is_running = running;
1108 }
1109
1110 /// Peek the console for input. If it has any, drain the pipe until text input
1111 /// is found or the pipe is empty.
1112 ///
1113 /// \param hStdin
1114 /// The handle to the standard input's pipe.
1115 ///
1116 /// \return
1117 /// true if the pipe has text input.
1118 llvm::Expected<bool> ConsoleHasTextInput(const HANDLE hStdin) {
1119 // Check if there are already characters buffered. Pressing enter counts as
1120 // 2 characters '\r\n' and only one of them is a keyDown event.
1121 DWORD bytesAvailable = 0;
1122 if (PeekNamedPipe(hStdin, nullptr, 0, nullptr, &bytesAvailable, nullptr)) {
1123 if (bytesAvailable > 0)
1124 return true;
1125 }
1126
1127 while (true) {
1128 INPUT_RECORD inputRecord;
1129 DWORD numRead = 0;
1130 if (!PeekConsoleInput(hStdin, &inputRecord, 1, &numRead))
1131 return llvm::createStringError("failed to peek standard input");
1132
1133 if (numRead == 0)
1134 return false;
1135
1136 if (inputRecord.EventType == KEY_EVENT &&
1137 inputRecord.Event.KeyEvent.bKeyDown &&
1138 inputRecord.Event.KeyEvent.uChar.AsciiChar != 0)
1139 return true;
1140
1141 if (!ReadConsoleInput(hStdin, &inputRecord, 1, &numRead))
1142 return llvm::createStringError("failed to read standard input");
1143 }
1144 }
1145
1146 void Run() override {
1147 if (!m_read_file.IsValid() || m_write_file == INVALID_HANDLE_VALUE) {
1148 SetIsDone(true);
1149 return;
1150 }
1151
1152 SetIsDone(false);
1153 SetIsRunning(true);
1154
1155 HANDLE hStdin = m_read_file.GetWaitableHandle();
1156 HANDLE waitHandles[2] = {hStdin, m_interrupt_event};
1157
1158 DWORD consoleMode;
1159 bool isConsole = GetConsoleMode(hStdin, &consoleMode) != 0;
1160 // With ENABLE_LINE_INPUT, ReadFile returns only when a carriage return is
1161 // read. This will block lldb in ReadFile until the user hits enter. Save
1162 // the previous console mode to restore it later and remove
1163 // ENABLE_LINE_INPUT.
1164 DWORD oldConsoleMode = consoleMode;
1165 SetConsoleMode(hStdin,
1166 consoleMode & ~ENABLE_LINE_INPUT & ~ENABLE_ECHO_INPUT);
1167
1168 while (true) {
1169 {
1170 std::lock_guard<std::mutex> guard(m_mutex);
1171 if (GetIsDone())
1172 goto exit_loop;
1173 }
1174
1175 DWORD result = WaitForMultipleObjects(2, waitHandles, FALSE, INFINITE);
1176 switch (result) {
1177 case WAIT_FAILED:
1178 goto exit_loop;
1179 case WAIT_OBJECT_0: {
1180 if (isConsole) {
1181 auto hasInputOrErr = ConsoleHasTextInput(hStdin);
1182 if (!hasInputOrErr) {
1184 LLDB_LOG_ERROR(log, hasInputOrErr.takeError(),
1185 "failed to process debuggee's IO: {0}");
1186 goto exit_loop;
1187 }
1188
1189 // If no text input is ready, go back to waiting.
1190 if (!*hasInputOrErr)
1191 continue;
1192 }
1193
1194 char ch = 0;
1195 DWORD read = 0;
1196 if (!ReadFile(hStdin, &ch, 1, &read, nullptr) || read != 1)
1197 goto exit_loop;
1198
1199 DWORD written = 0;
1200 if (!WriteFile(m_write_file, &ch, 1, &written, nullptr) || written != 1)
1201 goto exit_loop;
1202 break;
1203 }
1204 case WAIT_OBJECT_0 + 1: {
1205 ControlOp op = m_pending_op.exchange(eControlOpNone);
1206 if (op == eControlOpQuit)
1207 goto exit_loop;
1208 if (op == eControlOpInterrupt &&
1209 StateIsRunningState(m_process->GetState()))
1210 m_process->SendAsyncInterrupt();
1211 break;
1212 }
1213 default:
1214 goto exit_loop;
1215 }
1216 }
1217
1218 exit_loop:;
1219 SetIsRunning(false);
1220 SetIsDone(true);
1221 SetConsoleMode(hStdin, oldConsoleMode);
1222 }
1223
1224 void Cancel() override {
1225 std::lock_guard<std::mutex> guard(m_mutex);
1226 SetIsDone(true);
1227 if (m_is_running) {
1229 ::SetEvent(m_interrupt_event);
1230 }
1231 }
1232
1233 bool Interrupt() override {
1234 if (m_active) {
1236 ::SetEvent(m_interrupt_event);
1237 return true;
1238 }
1239 if (StateIsRunningState(m_process->GetState())) {
1240 m_process->SendAsyncInterrupt();
1241 return true;
1242 }
1243 return false;
1244 }
1245
1246 void GotEOF() override {}
1247
1248private:
1254
1256 /// Read from this file (usually actual STDIN for LLDB)
1258 /// Write to this file (usually the primary pty for getting io to debuggee)
1259 HANDLE m_write_file = INVALID_HANDLE_VALUE;
1260 HANDLE m_interrupt_event = INVALID_HANDLE_VALUE;
1261 std::atomic<ControlOp> m_pending_op{eControlOpNone};
1262 std::mutex m_mutex;
1263 bool m_is_running = false;
1264};
1265
1267 if (m_pty == nullptr)
1268 return;
1269 m_stdio_communication.SetConnection(
1270 std::make_unique<ConnectionConPTY>(m_pty));
1271 if (m_stdio_communication.IsConnected()) {
1272 m_stdio_communication.SetReadThreadBytesReceivedCallback(
1274 m_stdio_communication.StartReadThread();
1275
1276 // Now read thread is set up, set up input reader.
1277 {
1278 std::lock_guard<std::mutex> guard(m_process_input_reader_mutex);
1280 m_process_input_reader = std::make_shared<IOHandlerProcessSTDIOWindows>(
1281 this, m_pty->GetSTDINHandle());
1282 }
1283 }
1284}
1285} // namespace lldb_private
static llvm::raw_ostream & error(Stream &strm)
#define LLDB_LOG(log,...)
The LLDB_LOG* macros defined below are the way to emit log messages.
Definition Log.h:364
#define LLDB_LOG_ERROR(log, error,...)
Definition Log.h:394
#define LLDB_LOG_VERBOSE(log,...)
Definition Log.h:371
#define LLDB_PLUGIN_DEFINE_ADV(ClassName, PluginName)
void * HANDLE
A section + offset based address class.
Definition Address.h:62
lldb::addr_t GetLoadAddress(Target *target) const
Get the load address.
Definition Address.cpp:301
bool IsValid() const
Check if the object state is valid.
Definition Address.h:355
An architecture specification class.
Definition ArchSpec.h:32
Class that manages the actual breakpoint that will be inserted into the running program.
static DynamicLoader * FindPlugin(Process *process, llvm::StringRef plugin_name)
Find a dynamic loader plugin for a given process.
lldb::addr_t GetExceptionAddress() const
A file utility class.
Definition FileSpec.h:57
bool Exists(const FileSpec &file_spec) const
Returns whether the given file exists.
static FileSystem & Instance()
void Resolve(llvm::SmallVectorImpl< char > &path, bool force_make_absolute=false)
Resolve path to make it canonical.
An abstract base class for files.
Definition FileBase.h:34
HostNativeThread & GetNativeThread()
NativeFile m_read_file
Read from this file (usually actual STDIN for LLDB)
llvm::Expected< bool > ConsoleHasTextInput(const HANDLE hStdin)
Peek the console for input.
HANDLE m_write_file
Write to this file (usually the primary pty for getting io to debuggee)
IOHandlerProcessSTDIOWindows(Process *process, HANDLE conpty_input)
Debugger & GetDebugger()
Definition IOHandler.h:130
IOHandler(Debugger &debugger, IOHandler::Type type)
Definition IOHandler.cpp:55
void SetIsDone(bool b)
Definition IOHandler.h:81
A collection class for Module objects.
Definition ModuleList.h:125
void Append(const lldb::ModuleSP &module_sp, bool notify=true)
Append a module to the module list.
A class that describes an executable image and its associated object and symbol files.
Definition Module.h:91
A plug-in interface definition class for object file parsers.
Definition ObjectFile.h:46
virtual lldb_private::Address GetImageInfoAddress(Target *target)
Similar to Process::GetImageInfoAddress().
Definition ObjectFile.h:442
static bool RegisterPlugin(llvm::StringRef name, llvm::StringRef description, ABICreateInstance create_callback)
static bool UnregisterPlugin(ABICreateInstance create_callback)
Status WriteMemory(lldb::addr_t addr, const void *buf, size_t size, size_t &bytes_written)
Status DestroyProcess(lldb::StateType process_state)
Status LaunchProcess(ProcessLaunchInfo &launch_info, DebugDelegateSP delegate)
Status GetMemoryRegionInfo(lldb::addr_t load_addr, MemoryRegionInfo &range_info)
std::unique_ptr< ProcessWindowsData > m_session_data
Status AllocateMemory(size_t size, uint32_t permissions, lldb::addr_t &addr)
Status AttachProcess(lldb::pid_t pid, const ProcessAttachInfo &attach_info, DebugDelegateSP delegate)
lldb::pid_t GetDebuggedProcessId() const
Status ReadMemory(lldb::addr_t addr, void *buf, size_t size, size_t &bytes_read)
virtual void OnExitProcess(uint32_t exit_code)
Status HaltProcess(bool &caused_stop)
Status DeallocateMemory(lldb::addr_t addr)
lldb::pid_t GetProcessID() const
Definition ProcessInfo.h:68
std::shared_ptr< PTY > TakePTY()
void OnLoadDll(const ModuleSpec &module_spec, lldb::addr_t module_addr) override
ProcessWindows(lldb::TargetSP target_sp, lldb::ListenerSP listener_sp)
bool DoUpdateThreadList(ThreadList &old_thread_list, ThreadList &new_thread_list) override
Update the thread list following process plug-in's specific logic.
void RefreshStateAfterStop() override
Currently called as part of ShouldStop.
void OnDebuggerConnected(lldb::addr_t image_base) override
Status DoDeallocateMemory(lldb::addr_t ptr) override
Actually deallocate memory in the process.
std::shared_ptr< PTY > m_pty
Status EnableBreakpointSite(BreakpointSite *bp_site) override
void DrainProcessStdout()
Block until the stdio read thread has surfaced everything currently buffered in the ConPTY/pipe to th...
void DidLaunch() override
Called after launching a process.
std::optional< uint32_t > GetWatchpointSlotCount() override
Get the number of watchpoints supported by this target.
Status DoResume(lldb::RunDirection direction) override
Resumes all of a process's threads as configured using the Thread run control functions.
void OnUnloadDll(lldb::addr_t module_addr) override
DynamicLoaderWindowsDYLD * GetDynamicLoader() override
Get the dynamic loader plug-in for this process.
void OnDebugString(lldb::addr_t debug_string_addr, bool is_unicode, uint16_t length_lower_word) override
Status DisableWatchpoint(lldb::WatchpointSP wp_sp, bool notify=true) override
bool IsAlive() override
Check if a process is still alive.
Status DoGetMemoryRegionInfo(lldb::addr_t vm_addr, MemoryRegionInfo &info) override
DoGetMemoryRegionInfo is called by GetMemoryRegionInfo after it has removed non address bits from loa...
void OnCreateThread(const HostThread &thread) override
static llvm::StringRef GetPluginDescriptionStatic()
size_t DoWriteMemory(lldb::addr_t vm_addr, const void *buf, size_t size, Status &error) override
Actually do the writing of memory to a process.
llvm::StringRef GetPluginName() override
Status DoLaunch(Module *exe_module, ProcessLaunchInfo &launch_info) override
Launch a new process.
size_t DoReadMemory(lldb::addr_t vm_addr, void *buf, size_t size, Status &error) override
Actually do the reading of memory from a process.
bool CanDebug(lldb::TargetSP target_sp, bool plugin_specified_by_name) override
Check if a plug-in instance can debug the file in module.
static llvm::StringRef GetPluginNameStatic()
llvm::Error ReadDebugString(lldb::addr_t debug_string_addr, bool is_unicode, uint16_t length_lower_word, llvm::SmallVectorImpl< char > &output)
void DidAttach(lldb_private::ArchSpec &arch_spec) override
Called after attaching a process.
void OnExitProcess(uint32_t exit_code) override
static lldb::ProcessSP CreateInstance(lldb::TargetSP target_sp, lldb::ListenerSP listener_sp, const FileSpec *, bool can_connect)
void OnExitThread(lldb::tid_t thread_id, uint32_t exit_code) override
Status DoAttachToProcessWithID(lldb::pid_t pid, const lldb_private::ProcessAttachInfo &attach_info) override
Attach to an existing process using a process ID.
lldb::addr_t GetImageInfoAddress() override
Get the image information address for the current process.
ExceptionResult OnDebugException(bool first_chance, const ExceptionRecord &record) override
std::map< lldb::break_id_t, WatchpointInfo > m_watchpoints
std::optional< DWORD > GetActiveExceptionCode() const
Returns the exception code of the active (current) debug exception, or std::nullopt if there is no ac...
void OnDebuggerError(const Status &error, uint32_t type) override
ArchSpec GetSystemArchitecture() override
Get the system architecture for this process.
Status DoDetach(bool keep_stopped) override
Detaches from a running or stopped process.
std::vector< lldb::break_id_t > m_watchpoint_ids
lldb::addr_t DoAllocateMemory(size_t size, uint32_t permissions, Status &error) override
Actually allocate memory in the process.
Status DisableBreakpointSite(BreakpointSite *bp_site) override
Status DoHalt(bool &caused_stop) override
Halts a running process.
Status EnableWatchpoint(lldb::WatchpointSP wp_sp, bool notify=true) override
A plug-in interface definition class for debugging a process.
Definition Process.h:357
lldb::IOHandlerSP m_process_input_reader
Definition Process.h:3528
std::mutex m_process_input_reader_mutex
Definition Process.h:3529
StopPointSiteList< lldb_private::BreakpointSite > & GetBreakpointSiteList()
Definition Process.cpp:1561
virtual Status DisableSoftwareBreakpoint(BreakpointSite *bp_site)
Definition Process.cpp:1931
lldb::pid_t GetID() const
Returns the pid of the process or LLDB_INVALID_PROCESS_ID if there is no known pid.
Definition Process.h:540
Process(lldb::TargetSP target_sp, lldb::ListenerSP listener_sp)
Construct with a shared pointer to a target, and the Process listener.
Definition Process.cpp:451
lldb::StateType GetPrivateState() const
Definition Process.h:3438
lldb::DynamicLoaderUP m_dyld_up
Definition Process.h:3516
bool IsBreakpointSitePhysicallyEnabled(const BreakpointSite &site)
Definition Process.cpp:1666
void AppendSTDOUT(const char *s, size_t len)
Definition Process.cpp:4856
lldb::TargetSP CalculateTarget() override
Definition Process.cpp:4822
virtual Status EnableSoftwareBreakpoint(BreakpointSite *bp_site)
Definition Process.cpp:1851
void SetID(lldb::pid_t new_pid)
Sets the stored pid.
Definition Process.h:545
friend class Target
Definition Process.h:363
virtual bool SetExitStatus(int exit_status, llvm::StringRef exit_string)
Set accessor for the process exit status (return code).
Definition Process.cpp:1044
static void STDIOReadThreadBytesReceived(void *baton, const void *src, size_t src_len)
Definition Process.cpp:4956
void SetPrivateState(lldb::StateType state)
Definition Process.cpp:1402
ThreadList m_thread_list
The threads for this process as the user will see them.
Definition Process.h:3489
ThreadedCommunication m_stdio_communication
Definition Process.h:3530
friend class ThreadList
Definition Process.h:364
Target & GetTarget()
Get the target object pointer for this module.
Definition Process.h:1255
static constexpr uint32_t GetNumHardwareBreakpointSlots()
bool AddHardwareBreakpoint(uint32_t slot, lldb::addr_t address, uint32_t size, bool read, bool write)
An error handling class.
Definition Status.h:118
static Status FromErrorStringWithFormat(const char *format,...) __attribute__((format(printf
Definition Status.cpp:106
static Status FromErrorString(const char *str)
Definition Status.h:141
bool Fail() const
Test for error condition.
Definition Status.cpp:293
static Status static Status FromErrorStringWithFormatv(const char *format, Args &&...args)
Definition Status.h:151
static lldb::StopInfoSP CreateStopReasonToTrace(Thread &thread)
static lldb::StopInfoSP CreateStopReasonWithWatchpointID(Thread &thread, lldb::break_id_t watch_id, bool silently_continue=false)
static lldb::StopInfoSP CreateStopReasonWithException(Thread &thread, const char *description)
static lldb::StopInfoSP CreateStopReasonWithBreakpointSiteID(Thread &thread, lldb::break_id_t break_id)
StopPointSiteSP FindByAddress(lldb::addr_t addr)
Returns a shared pointer to the site at address addr.
lldb::break_id_t GetID() const
virtual lldb::addr_t GetLoadAddress() const
lldb::ModuleSP GetExecutableModule()
Gets the module for the main executable.
Definition Target.cpp:1593
void SetExecutableModule(lldb::ModuleSP &module_sp, LoadDependentFiles load_dependent_files=eLoadDependentsDefault)
Set the main executable module.
Definition Target.cpp:1626
void AddThread(const lldb::ThreadSP &thread_sp)
virtual ThreadIterable Threads()
#define LLDB_INVALID_BREAK_ID
#define LLDB_INVALID_INDEX32
#define LLDB_INVALID_ADDRESS
A class that represents a running process on the host machine.
Log * GetLog(Cat mask)
Retrieve the Log object for the channel associated with the given log enum.
Definition Log.h:327
HostThreadPosix HostNativeThread
std::shared_ptr< DebuggerThread > DebuggerThreadSP
Definition ForwardDecl.h:36
bool StateIsRunningState(lldb::StateType state)
Check if a state represents a state where the process or thread is running.
Definition State.cpp:68
NativeFilePosix NativeFile
Definition File.h:29
std::shared_ptr< IDebugDelegate > DebugDelegateSP
Definition ForwardDecl.h:35
std::shared_ptr< ExceptionRecord > ExceptionRecordSP
Definition ForwardDecl.h:37
static void DumpAdditionalExceptionInformation(llvm::raw_ostream &stream, const ExceptionRecordSP &exception)
static bool ShouldUseLLDBServer()
std::shared_ptr< lldb_private::BreakpointSite > BreakpointSiteSP
RunDirection
Execution directions.
std::shared_ptr< lldb_private::Thread > ThreadSP
StateType
Process and Thread States.
@ eStateUnloaded
Process is object is valid, but not currently loaded.
@ eStateDetached
Process has been detached and can't be examined.
@ eStateStopped
Process or thread is stopped and can be examined.
@ eStateRunning
Process or thread is running and can't be examined.
@ eStateExited
Process has exited and can't be examined.
@ eStateCrashed
Process or thread has crashed and can be examined.
std::shared_ptr< lldb_private::Process > ProcessSP
uint64_t pid_t
Definition lldb-types.h:83
std::shared_ptr< lldb_private::Watchpoint > WatchpointSP
std::shared_ptr< lldb_private::Listener > ListenerSP
std::shared_ptr< lldb_private::StopInfo > StopInfoSP
uint64_t addr_t
Definition lldb-types.h:80
std::shared_ptr< lldb_private::Target > TargetSP
std::shared_ptr< lldb_private::RegisterContext > RegisterContextSP
uint64_t tid_t
Definition lldb-types.h:84
std::shared_ptr< lldb_private::Module > ModuleSP