summaryrefslogtreecommitdiff
path: root/source/Plugins/Process
diff options
context:
space:
mode:
Diffstat (limited to 'source/Plugins/Process')
-rw-r--r--source/Plugins/Process/CMakeLists.txt2
-rw-r--r--source/Plugins/Process/Darwin/CFString.cpp11
-rw-r--r--source/Plugins/Process/Darwin/DarwinProcessLauncher.cpp58
-rw-r--r--source/Plugins/Process/Darwin/MachException.cpp35
-rw-r--r--source/Plugins/Process/Darwin/NativeProcessDarwin.cpp163
-rw-r--r--source/Plugins/Process/Darwin/NativeProcessDarwin.h22
-rw-r--r--source/Plugins/Process/Darwin/NativeThreadDarwin.cpp54
-rw-r--r--source/Plugins/Process/Darwin/NativeThreadListDarwin.cpp69
-rw-r--r--source/Plugins/Process/FreeBSD/CMakeLists.txt4
-rw-r--r--source/Plugins/Process/FreeBSD/FreeBSDThread.cpp69
-rw-r--r--source/Plugins/Process/FreeBSD/FreeBSDThread.h2
-rw-r--r--source/Plugins/Process/FreeBSD/POSIXStopInfo.h6
-rw-r--r--source/Plugins/Process/FreeBSD/ProcessFreeBSD.cpp35
-rw-r--r--source/Plugins/Process/FreeBSD/ProcessMonitor.cpp138
-rw-r--r--source/Plugins/Process/FreeBSD/ProcessMonitor.h23
-rw-r--r--source/Plugins/Process/FreeBSD/RegisterContextPOSIX.h4
-rw-r--r--source/Plugins/Process/FreeBSD/RegisterContextPOSIXProcessMonitor_arm.cpp2
-rw-r--r--source/Plugins/Process/FreeBSD/RegisterContextPOSIXProcessMonitor_mips64.cpp8
-rw-r--r--source/Plugins/Process/FreeBSD/RegisterContextPOSIXProcessMonitor_powerpc.cpp6
-rw-r--r--source/Plugins/Process/FreeBSD/RegisterContextPOSIXProcessMonitor_x86.cpp32
-rw-r--r--source/Plugins/Process/Linux/CMakeLists.txt4
-rw-r--r--source/Plugins/Process/Linux/NativeProcessLinux.cpp384
-rw-r--r--source/Plugins/Process/Linux/NativeProcessLinux.h20
-rw-r--r--source/Plugins/Process/Linux/NativeRegisterContextLinux_arm.cpp44
-rw-r--r--source/Plugins/Process/Linux/NativeRegisterContextLinux_arm.h4
-rw-r--r--source/Plugins/Process/Linux/NativeRegisterContextLinux_arm64.cpp21
-rw-r--r--source/Plugins/Process/Linux/NativeRegisterContextLinux_arm64.h4
-rw-r--r--source/Plugins/Process/Linux/NativeRegisterContextLinux_mips64.cpp9
-rw-r--r--source/Plugins/Process/Linux/NativeRegisterContextLinux_ppc64le.cpp17
-rw-r--r--source/Plugins/Process/Linux/NativeRegisterContextLinux_ppc64le.h4
-rw-r--r--source/Plugins/Process/Linux/NativeRegisterContextLinux_s390x.cpp10
-rwxr-xr-xsource/Plugins/Process/Linux/NativeRegisterContextLinux_x86_64.cpp42
-rw-r--r--source/Plugins/Process/Linux/NativeThreadLinux.cpp8
-rw-r--r--source/Plugins/Process/Linux/ProcessorTrace.h2
-rw-r--r--source/Plugins/Process/Linux/SingleStepCheck.cpp6
-rw-r--r--source/Plugins/Process/MacOSX-Kernel/CommunicationKDP.cpp67
-rw-r--r--source/Plugins/Process/MacOSX-Kernel/ProcessKDP.cpp57
-rw-r--r--source/Plugins/Process/MacOSX-Kernel/ThreadKDP.cpp18
-rw-r--r--source/Plugins/Process/NetBSD/CMakeLists.txt4
-rw-r--r--source/Plugins/Process/NetBSD/NativeProcessNetBSD.cpp61
-rw-r--r--source/Plugins/Process/NetBSD/NativeProcessNetBSD.h6
-rw-r--r--source/Plugins/Process/NetBSD/NativeRegisterContextNetBSD_x86_64.cpp17
-rw-r--r--source/Plugins/Process/POSIX/CMakeLists.txt3
-rw-r--r--source/Plugins/Process/POSIX/CrashReason.cpp3
-rw-r--r--source/Plugins/Process/Utility/CMakeLists.txt3
-rw-r--r--source/Plugins/Process/Utility/DynamicRegisterInfo.cpp94
-rw-r--r--source/Plugins/Process/Utility/DynamicRegisterInfo.h23
-rw-r--r--source/Plugins/Process/Utility/HistoryThread.h6
-rw-r--r--source/Plugins/Process/Utility/InstructionUtils.h3
-rw-r--r--source/Plugins/Process/Utility/RegisterContextDarwinConstants.h26
-rw-r--r--source/Plugins/Process/Utility/RegisterContextDarwin_arm.cpp21
-rw-r--r--source/Plugins/Process/Utility/RegisterContextDarwin_arm64.cpp25
-rw-r--r--source/Plugins/Process/Utility/RegisterContextDarwin_i386.cpp24
-rw-r--r--source/Plugins/Process/Utility/RegisterContextDarwin_x86_64.cpp12
-rw-r--r--source/Plugins/Process/Utility/RegisterContextLLDB.cpp329
-rw-r--r--source/Plugins/Process/Utility/RegisterContextMacOSXFrameBackchain.cpp14
-rw-r--r--source/Plugins/Process/Utility/RegisterContextMemory.cpp6
-rw-r--r--source/Plugins/Process/Utility/RegisterContextPOSIX_arm.cpp15
-rw-r--r--source/Plugins/Process/Utility/RegisterContextPOSIX_arm64.cpp15
-rw-r--r--source/Plugins/Process/Utility/RegisterContextPOSIX_mips64.cpp17
-rw-r--r--source/Plugins/Process/Utility/RegisterContextPOSIX_powerpc.cpp15
-rw-r--r--source/Plugins/Process/Utility/RegisterContextPOSIX_ppc64le.cpp14
-rw-r--r--source/Plugins/Process/Utility/RegisterContextPOSIX_s390x.cpp4
-rw-r--r--source/Plugins/Process/Utility/RegisterContextPOSIX_x86.cpp8
-rw-r--r--source/Plugins/Process/Utility/RegisterInfoInterface.h2
-rw-r--r--source/Plugins/Process/Utility/RegisterInfos_ppc64.h331
-rw-r--r--source/Plugins/Process/Utility/StopInfoMachException.cpp57
-rw-r--r--source/Plugins/Process/Utility/ThreadMemory.cpp2
-rw-r--r--source/Plugins/Process/Utility/UnwindLLDB.cpp147
-rw-r--r--source/Plugins/Process/Utility/UnwindLLDB.h1
-rw-r--r--source/Plugins/Process/Utility/UnwindMacOSXFrameBackchain.cpp8
-rw-r--r--source/Plugins/Process/Utility/lldb-ppc64-register-enums.h139
-rw-r--r--source/Plugins/Process/Windows/Common/CMakeLists.txt3
-rw-r--r--source/Plugins/Process/Windows/Common/DebuggerThread.cpp62
-rw-r--r--source/Plugins/Process/Windows/Common/ProcessWindows.cpp196
-rw-r--r--source/Plugins/Process/Windows/Common/TargetThreadWindows.cpp76
-rw-r--r--source/Plugins/Process/Windows/Common/TargetThreadWindows.h7
-rw-r--r--source/Plugins/Process/Windows/Common/x64/RegisterContextWindows_x64.cpp61
-rw-r--r--source/Plugins/Process/Windows/Common/x86/RegisterContextWindows_x86.cpp29
-rw-r--r--source/Plugins/Process/elf-core/CMakeLists.txt2
-rw-r--r--source/Plugins/Process/elf-core/ProcessElfCore.cpp55
-rw-r--r--source/Plugins/Process/elf-core/RegisterContextPOSIXCore_mips64.cpp2
-rw-r--r--source/Plugins/Process/elf-core/RegisterContextPOSIXCore_x86_64.cpp4
-rw-r--r--source/Plugins/Process/elf-core/ThreadElfCore.cpp31
-rw-r--r--source/Plugins/Process/elf-core/ThreadElfCore.h2
-rw-r--r--source/Plugins/Process/gdb-remote/GDBRemoteClientBase.cpp59
-rw-r--r--source/Plugins/Process/gdb-remote/GDBRemoteClientBase.h5
-rw-r--r--source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp203
-rw-r--r--source/Plugins/Process/gdb-remote/GDBRemoteCommunication.h9
-rw-r--r--source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp322
-rw-r--r--source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h21
-rw-r--r--source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp2
-rw-r--r--source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.h4
-rw-r--r--source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp85
-rw-r--r--source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp116
-rw-r--r--source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp55
-rw-r--r--source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp140
-rw-r--r--source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp784
-rw-r--r--source/Plugins/Process/gdb-remote/ProcessGDBRemote.h17
-rw-r--r--source/Plugins/Process/gdb-remote/ThreadGDBRemote.cpp46
-rw-r--r--source/Plugins/Process/mach-core/CMakeLists.txt2
-rw-r--r--source/Plugins/Process/mach-core/ProcessMachCore.cpp136
-rw-r--r--source/Plugins/Process/mach-core/ThreadMachCore.cpp12
-rw-r--r--source/Plugins/Process/minidump/CMakeLists.txt2
-rw-r--r--source/Plugins/Process/minidump/MinidumpParser.cpp206
-rw-r--r--source/Plugins/Process/minidump/MinidumpParser.h14
-rw-r--r--source/Plugins/Process/minidump/MinidumpTypes.cpp46
-rw-r--r--source/Plugins/Process/minidump/MinidumpTypes.h15
-rw-r--r--source/Plugins/Process/minidump/ProcessMinidump.cpp102
-rw-r--r--source/Plugins/Process/minidump/ProcessMinidump.h2
110 files changed, 3216 insertions, 2638 deletions
diff --git a/source/Plugins/Process/CMakeLists.txt b/source/Plugins/Process/CMakeLists.txt
index 62abd75a43b69..fdeb211fe7a20 100644
--- a/source/Plugins/Process/CMakeLists.txt
+++ b/source/Plugins/Process/CMakeLists.txt
@@ -11,9 +11,9 @@ elseif (CMAKE_SYSTEM_NAME MATCHES "Windows")
add_subdirectory(Windows/Common)
elseif (CMAKE_SYSTEM_NAME MATCHES "Darwin")
add_subdirectory(MacOSX-Kernel)
- add_subdirectory(mach-core)
endif()
add_subdirectory(gdb-remote)
add_subdirectory(Utility)
add_subdirectory(elf-core)
+add_subdirectory(mach-core)
add_subdirectory(minidump)
diff --git a/source/Plugins/Process/Darwin/CFString.cpp b/source/Plugins/Process/Darwin/CFString.cpp
index 84ad56774d7c4..b87afe9991816 100644
--- a/source/Plugins/Process/Darwin/CFString.cpp
+++ b/source/Plugins/Process/Darwin/CFString.cpp
@@ -91,9 +91,8 @@ const char *CFString::UTF8(std::string &str) {
return CFString::UTF8(get(), str);
}
-// Static function that puts a copy of the UTF8 contents of CF_STR into STR
-// and returns the C string pointer that is contained in STR when successful,
-// else
+// Static function that puts a copy of the UTF8 contents of CF_STR into STR and
+// returns the C string pointer that is contained in STR when successful, else
// NULL is returned. This allows the std::string parameter to own the extracted
// string,
// and also allows that string to be returned as a C string pointer that can be
@@ -120,9 +119,9 @@ const char *CFString::UTF8(CFStringRef cf_str, std::string &str) {
// Static function that puts a copy of the file system representation of CF_STR
// into STR and returns the C string pointer that is contained in STR when
-// successful, else NULL is returned. This allows the std::string parameter
-// to own the extracted string, and also allows that string to be returned as
-// a C string pointer that can be used.
+// successful, else NULL is returned. This allows the std::string parameter to
+// own the extracted string, and also allows that string to be returned as a C
+// string pointer that can be used.
const char *CFString::FileSystemRepresentation(CFStringRef cf_str,
std::string &str) {
diff --git a/source/Plugins/Process/Darwin/DarwinProcessLauncher.cpp b/source/Plugins/Process/Darwin/DarwinProcessLauncher.cpp
index 6b3d5f6c117fe..95659725ce2ec 100644
--- a/source/Plugins/Process/Darwin/DarwinProcessLauncher.cpp
+++ b/source/Plugins/Process/Darwin/DarwinProcessLauncher.cpp
@@ -142,8 +142,8 @@ static Status ForkChildForPTraceDebugging(const char *path, char const *argv[],
}
// Use a fork that ties the child process's stdin/out/err to a pseudo
- // terminal so we can read it in our MachProcess::STDIOThread
- // as unbuffered io.
+ // terminal so we can read it in our MachProcess::STDIOThread as unbuffered
+ // io.
PseudoTerminal pty;
char fork_error[256];
memset(fork_error, 0, sizeof(fork_error));
@@ -167,12 +167,12 @@ static Status ForkChildForPTraceDebugging(const char *path, char const *argv[],
// Get BSD signals as mach exceptions.
::ptrace(PT_SIGEXC, 0, 0, 0);
- // If our parent is setgid, lets make sure we don't inherit those
- // extra powers due to nepotism.
+ // If our parent is setgid, lets make sure we don't inherit those extra
+ // powers due to nepotism.
if (::setgid(getgid()) == 0) {
- // Let the child have its own process group. We need to execute
- // this call in both the child and parent to avoid a race
- // condition between the two processes.
+ // Let the child have its own process group. We need to execute this call
+ // in both the child and parent to avoid a race condition between the two
+ // processes.
// Set the child process group to match its pid.
::setpgid(0, 0);
@@ -183,23 +183,22 @@ static Status ForkChildForPTraceDebugging(const char *path, char const *argv[],
// Turn this process into the given executable.
::execv(path, (char *const *)argv);
}
- // Exit with error code. Child process should have taken
- // over in above exec call and if the exec fails it will
- // exit the child process below.
+ // Exit with error code. Child process should have taken over in above exec
+ // call and if the exec fails it will exit the child process below.
::exit(127);
} else {
//--------------------------------------------------------------
// Parent process
//--------------------------------------------------------------
- // Let the child have its own process group. We need to execute
- // this call in both the child and parent to avoid a race condition
- // between the two processes.
+ // Let the child have its own process group. We need to execute this call
+ // in both the child and parent to avoid a race condition between the two
+ // processes.
// Set the child process group to match its pid
::setpgid(*pid, *pid);
if (pty_fd) {
- // Release our master pty file descriptor so the pty class doesn't
- // close it and so we can continue to use it in our STDIO thread
+ // Release our master pty file descriptor so the pty class doesn't close
+ // it and so we can continue to use it in our STDIO thread
*pty_fd = pty.ReleaseMasterFileDescriptor();
}
}
@@ -302,8 +301,7 @@ static Status PosixSpawnChildForPTraceDebugging(const char *path,
return error;
}
- // Ensure we clean up the spawnattr structure however we exit this
- // function.
+ // Ensure we clean up the spawnattr structure however we exit this function.
std::unique_ptr<posix_spawnattr_t, int (*)(posix_spawnattr_t *)> spawnattr_up(
&attr, ::posix_spawnattr_destroy);
@@ -332,9 +330,9 @@ static Status PosixSpawnChildForPTraceDebugging(const char *path,
#if !defined(__arm__)
- // We don't need to do this for ARM, and we really shouldn't now that we
- // have multiple CPU subtypes and no posix_spawnattr call that allows us
- // to set which CPU subtype to launch...
+ // We don't need to do this for ARM, and we really shouldn't now that we have
+ // multiple CPU subtypes and no posix_spawnattr call that allows us to set
+ // which CPU subtype to launch...
cpu_type_t desired_cpu_type = launch_info.GetArchitecture().GetMachOCPUType();
if (desired_cpu_type != LLDB_INVALID_CPUTYPE) {
size_t ocount = 0;
@@ -374,10 +372,10 @@ static Status PosixSpawnChildForPTraceDebugging(const char *path,
int (*)(posix_spawn_file_actions_t *)>
file_actions_up(&file_actions, ::posix_spawn_file_actions_destroy);
- // We assume the caller has setup the file actions appropriately. We
- // are not in the business of figuring out what we really need here.
- // lldb-server will have already called FinalizeFileActions() as well
- // to button these up properly.
+ // We assume the caller has setup the file actions appropriately. We are not
+ // in the business of figuring out what we really need here. lldb-server will
+ // have already called FinalizeFileActions() as well to button these up
+ // properly.
const size_t num_actions = launch_info.GetNumFileActions();
for (size_t action_index = 0; action_index < num_actions; ++action_index) {
const FileAction *const action =
@@ -533,8 +531,8 @@ Status LaunchInferior(ProcessLaunchInfo &launch_info, int *pty_master_fd,
if (error.Success()) {
launch_info.SetProcessID(static_cast<lldb::pid_t>(pid));
} else {
- // Reset any variables that might have been set during a failed
- // launch attempt.
+ // Reset any variables that might have been set during a failed launch
+ // attempt.
if (pty_master_fd)
*pty_master_fd = -1;
@@ -616,8 +614,8 @@ Status LaunchInferior(ProcessLaunchInfo &launch_info, int *pty_master_fd,
if (pty_master_fd)
*pty_master_fd = launch_info.GetPTY().ReleaseMasterFileDescriptor();
} else {
- // Reset any variables that might have been set during a failed
- // launch attempt.
+ // Reset any variables that might have been set during a failed launch
+ // attempt.
if (pty_master_fd)
*pty_master_fd = -1;
@@ -636,8 +634,8 @@ Status LaunchInferior(ProcessLaunchInfo &launch_info, int *pty_master_fd,
}
if (launch_info.GetProcessID() == LLDB_INVALID_PROCESS_ID) {
- // If we don't have a valid process ID and no one has set the error,
- // then return a generic error.
+ // If we don't have a valid process ID and no one has set the error, then
+ // return a generic error.
if (error.Success())
error.SetErrorStringWithFormat("%s(): failed to launch, no reason "
"specified",
diff --git a/source/Plugins/Process/Darwin/MachException.cpp b/source/Plugins/Process/Darwin/MachException.cpp
index 9f5920753d68d..353f2df321395 100644
--- a/source/Plugins/Process/Darwin/MachException.cpp
+++ b/source/Plugins/Process/Darwin/MachException.cpp
@@ -92,8 +92,6 @@ extern "C" kern_return_t catch_mach_exception_raise_state_identity(
(uint64_t)(exc_data_count > 0 ? exc_data[0] : 0xBADDBADD),
(uint64_t)(exc_data_count > 1 ? exc_data[1] : 0xBADDBADD));
}
- mach_port_deallocate(mach_task_self(), task_port);
- mach_port_deallocate(mach_task_self(), thread_port);
return KERN_FAILURE;
}
@@ -249,20 +247,19 @@ bool MachException::Message::CatchExceptionRaise(task_t task) {
bool success = false;
state.task_port = task;
g_message = &state;
- // The exc_server function is the MIG generated server handling function
- // to handle messages from the kernel relating to the occurrence of an
- // exception in a thread. Such messages are delivered to the exception port
- // set via thread_set_exception_ports or task_set_exception_ports. When an
- // exception occurs in a thread, the thread sends an exception message to
- // its exception port, blocking in the kernel waiting for the receipt of a
- // reply. The exc_server function performs all necessary argument handling
- // for this kernel message and calls catch_exception_raise,
- // catch_exception_raise_state or catch_exception_raise_state_identity,
- // which should handle the exception. If the called routine returns
- // KERN_SUCCESS, a reply message will be sent, allowing the thread to
- // continue from the point of the exception; otherwise, no reply message
- // is sent and the called routine must have dealt with the exception
- // thread directly.
+ // The exc_server function is the MIG generated server handling function to
+ // handle messages from the kernel relating to the occurrence of an exception
+ // in a thread. Such messages are delivered to the exception port set via
+ // thread_set_exception_ports or task_set_exception_ports. When an exception
+ // occurs in a thread, the thread sends an exception message to its exception
+ // port, blocking in the kernel waiting for the receipt of a reply. The
+ // exc_server function performs all necessary argument handling for this
+ // kernel message and calls catch_exception_raise,
+ // catch_exception_raise_state or catch_exception_raise_state_identity, which
+ // should handle the exception. If the called routine returns KERN_SUCCESS, a
+ // reply message will be sent, allowing the thread to continue from the point
+ // of the exception; otherwise, no reply message is sent and the called
+ // routine must have dealt with the exception thread directly.
if (mach_exc_server(&exc_msg.hdr, &reply_msg.hdr)) {
success = true;
} else {
@@ -385,9 +382,9 @@ Status MachException::PortInfo::Save(task_t task) {
log->Printf("MachException::PortInfo::%s(task = 0x%4.4x)", __FUNCTION__,
task);
- // Be careful to be able to have debugserver built on a newer OS than what
- // it is currently running on by being able to start with all exceptions
- // and back off to just what is supported on the current system
+ // Be careful to be able to have debugserver built on a newer OS than what it
+ // is currently running on by being able to start with all exceptions and
+ // back off to just what is supported on the current system
mask = LLDB_EXC_MASK;
count = (sizeof(ports) / sizeof(ports[0]));
diff --git a/source/Plugins/Process/Darwin/NativeProcessDarwin.cpp b/source/Plugins/Process/Darwin/NativeProcessDarwin.cpp
index 518f0d2da4f29..3505443abcb0a 100644
--- a/source/Plugins/Process/Darwin/NativeProcessDarwin.cpp
+++ b/source/Plugins/Process/Darwin/NativeProcessDarwin.cpp
@@ -104,8 +104,8 @@ Status NativeProcessProtocol::Launch(
return error;
}
- // Finalize the processing needed to debug the launched process with
- // a NativeProcessDarwin instance.
+ // Finalize the processing needed to debug the launched process with a
+ // NativeProcessDarwin instance.
error = np_darwin_sp->FinalizeLaunch(launch_flavor, mainloop);
if (!error.Success()) {
if (log)
@@ -194,9 +194,9 @@ Status NativeProcessDarwin::FinalizeLaunch(LaunchFlavor launch_flavor,
"mach exception port monitor thread: %s",
__FUNCTION__, error.AsCString());
- // Terminate the inferior process. There's nothing meaningful we can
- // do if we can't receive signals and exceptions. Since we launched
- // the process, it's fair game for us to kill it.
+ // Terminate the inferior process. There's nothing meaningful we can do if
+ // we can't receive signals and exceptions. Since we launched the process,
+ // it's fair game for us to kill it.
::ptrace(PT_KILL, m_pid, 0, 0);
SetState(eStateExited);
@@ -243,9 +243,9 @@ Status NativeProcessDarwin::FinalizeLaunch(LaunchFlavor launch_flavor,
}
if (TaskPortForProcessID(error) == TASK_NULL) {
- // We failed to get the task for our process ID which is bad.
- // Kill our process; otherwise, it will be stopped at the entry
- // point and get reparented to someone else and never go away.
+ // We failed to get the task for our process ID which is bad. Kill our
+ // process; otherwise, it will be stopped at the entry point and get
+ // reparented to someone else and never go away.
if (log)
log->Printf("NativeProcessDarwin::%s(): could not get task port "
"for process, sending SIGKILL and exiting: %s",
@@ -277,9 +277,9 @@ bool NativeProcessDarwin::ProcessUsingBackBoard() const {
return false;
}
-// Called by the exception thread when an exception has been received from
-// our process. The exception message is completely filled and the exception
-// data has already been copied.
+// Called by the exception thread when an exception has been received from our
+// process. The exception message is completely filled and the exception data
+// has already been copied.
void NativeProcessDarwin::ExceptionMessageReceived(
const MachException::Message &message) {
Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS | LIBLLDB_LOG_VERBOSE));
@@ -290,8 +290,8 @@ void NativeProcessDarwin::ExceptionMessageReceived(
SuspendTask();
}
- // Use a locker to automatically unlock our mutex in case of exceptions
- // Add the exception to our internal exception stack
+ // Use a locker to automatically unlock our mutex in case of exceptions Add
+ // the exception to our internal exception stack
m_exception_messages.push_back(message);
if (log)
@@ -324,13 +324,12 @@ void *NativeProcessDarwin::DoExceptionThread() {
// Ensure we don't get CPU starved.
MaybeRaiseThreadPriority();
- // We keep a count of the number of consecutive exceptions received so
- // we know to grab all exceptions without a timeout. We do this to get a
- // bunch of related exceptions on our exception port so we can process
- // then together. When we have multiple threads, we can get an exception
- // per thread and they will come in consecutively. The main loop in this
- // thread can stop periodically if needed to service things related to this
- // process.
+ // We keep a count of the number of consecutive exceptions received so we
+ // know to grab all exceptions without a timeout. We do this to get a bunch
+ // of related exceptions on our exception port so we can process then
+ // together. When we have multiple threads, we can get an exception per
+ // thread and they will come in consecutively. The main loop in this thread
+ // can stop periodically if needed to service things related to this process.
//
// [did we lose some words here?]
//
@@ -338,15 +337,15 @@ void *NativeProcessDarwin::DoExceptionThread() {
// 0 our exception port. After we get one exception, we then will use the
// MACH_RCV_TIMEOUT option with a zero timeout to grab all other current
// exceptions for our process. After we have received the last pending
- // exception, we will get a timeout which enables us to then notify
- // our main thread that we have an exception bundle available. We then wait
- // for the main thread to tell this exception thread to start trying to get
+ // exception, we will get a timeout which enables us to then notify our main
+ // thread that we have an exception bundle available. We then wait for the
+ // main thread to tell this exception thread to start trying to get
// exceptions messages again and we start again with a mach_msg read with
// infinite timeout.
//
// We choose to park a thread on this, rather than polling, because the
- // polling is expensive. On devices, we need to minimize overhead caused
- // by the process monitor.
+ // polling is expensive. On devices, we need to minimize overhead caused by
+ // the process monitor.
uint32_t num_exceptions_received = 0;
Status error;
task_t task = m_task;
@@ -359,8 +358,7 @@ void *NativeProcessDarwin::DoExceptionThread() {
CFReleaser<SBSWatchdogAssertionRef> watchdog;
if (process->ProcessUsingSpringBoard()) {
- // Request a renewal for every 60 seconds if we attached using
- // SpringBoard.
+ // Request a renewal for every 60 seconds if we attached using SpringBoard.
watchdog.reset(::SBSWatchdogAssertionCreateForPID(nullptr, pid, 60));
if (log)
log->Printf("::SBSWatchdogAssertionCreateForPID(NULL, %4.4x, 60) "
@@ -401,18 +399,18 @@ void *NativeProcessDarwin::DoExceptionThread() {
}
#endif // #ifdef WITH_BKS
- // Do we want to use a weak pointer to the NativeProcessDarwin here, in
- // which case we can guarantee we don't whack the process monitor if we
- // race between this thread and the main one on shutdown?
+ // Do we want to use a weak pointer to the NativeProcessDarwin here, in which
+ // case we can guarantee we don't whack the process monitor if we race
+ // between this thread and the main one on shutdown?
while (IsExceptionPortValid()) {
::pthread_testcancel();
MachException::Message exception_message;
if (num_exceptions_received > 0) {
- // We don't want a timeout here, just receive as many exceptions as
- // we can since we already have one. We want to get all currently
- // available exceptions for this task at once.
+ // We don't want a timeout here, just receive as many exceptions as we
+ // can since we already have one. We want to get all currently available
+ // exceptions for this task at once.
error = exception_message.Receive(
GetExceptionPort(),
MACH_RCV_MSG | MACH_RCV_INTERRUPT | MACH_RCV_TIMEOUT, 0);
@@ -424,8 +422,8 @@ void *NativeProcessDarwin::DoExceptionThread() {
MACH_RCV_TIMEOUT,
periodic_timeout);
} else {
- // We don't need to parse all current exceptions or stop
- // periodically, just wait for an exception forever.
+ // We don't need to parse all current exceptions or stop periodically,
+ // just wait for an exception forever.
error = exception_message.Receive(GetExceptionPort(),
MACH_RCV_MSG | MACH_RCV_INTERRUPT, 0);
}
@@ -462,8 +460,8 @@ void *NativeProcessDarwin::DoExceptionThread() {
__FUNCTION__);
continue;
} else {
- // The inferior task is no longer valid. Time to exit as
- // the process has gone away.
+ // The inferior task is no longer valid. Time to exit as the process
+ // has gone away.
if (log)
log->Printf("NativeProcessDarwin::%s(): the inferior task "
"has exited, and so will we...",
@@ -476,18 +474,17 @@ void *NativeProcessDarwin::DoExceptionThread() {
// We timed out when waiting for exceptions.
if (num_exceptions_received > 0) {
- // We were receiving all current exceptions with a timeout of
- // zero. It is time to go back to our normal looping mode.
+ // We were receiving all current exceptions with a timeout of zero.
+ // It is time to go back to our normal looping mode.
num_exceptions_received = 0;
- // Notify our main thread we have a complete exception message
- // bundle available. Get the possibly updated task port back
- // from the process in case we exec'ed and our task port
- // changed.
+ // Notify our main thread we have a complete exception message bundle
+ // available. Get the possibly updated task port back from the
+ // process in case we exec'ed and our task port changed.
task = ExceptionMessageBundleComplete();
- // In case we use a timeout value when getting exceptions,
- // make sure our task is still valid.
+ // In case we use a timeout value when getting exceptions, make sure
+ // our task is still valid.
if (IsTaskValid(task)) {
// Task is still ok.
if (log)
@@ -496,8 +493,8 @@ void *NativeProcessDarwin::DoExceptionThread() {
__FUNCTION__);
continue;
} else {
- // The inferior task is no longer valid. Time to exit as
- // the process has gone away.
+ // The inferior task is no longer valid. Time to exit as the
+ // process has gone away.
if (log)
log->Printf("NativeProcessDarwin::%s(): the inferior "
"task has exited, and so will we...",
@@ -534,10 +531,8 @@ void *NativeProcessDarwin::DoExceptionThread() {
// TODO: change SBSWatchdogAssertionRelease to SBSWatchdogAssertionCancel
// when we
// all are up and running on systems that support it. The SBS framework has
- // a #define
- // that will forward SBSWatchdogAssertionRelease to
- // SBSWatchdogAssertionCancel for now
- // so it should still build either way.
+ // a #define that will forward SBSWatchdogAssertionRelease to
+ // SBSWatchdogAssertionCancel for now so it should still build either way.
DNBLogThreadedIf(LOG_TASK, "::SBSWatchdogAssertionRelease(%p)",
watchdog.get());
::SBSWatchdogAssertionRelease(watchdog.get());
@@ -728,8 +723,8 @@ task_t NativeProcessDarwin::ExceptionMessageBundleComplete() {
const int signo = m_exception_messages[i].state.SoftSignal();
if (signo == SIGTRAP) {
// SIGTRAP could mean that we exec'ed. We need to check the
- // dyld all_image_infos.infoArray to see if it is NULL and if
- // so, say that we exec'ed.
+ // dyld all_image_infos.infoArray to see if it is NULL and if so, say
+ // that we exec'ed.
const addr_t aii_addr = GetDYLDAllImageInfosAddress(error);
if (aii_addr == LLDB_INVALID_ADDRESS)
break;
@@ -744,12 +739,12 @@ task_t NativeProcessDarwin::ExceptionMessageBundleComplete() {
bytes_read); // #bytes read
if (read_error.Success() && (bytes_read == 4)) {
if (info_array_count == 0) {
- // We got the all infos address, and there are zero
- // entries. We think we exec'd.
+ // We got the all infos address, and there are zero entries. We
+ // think we exec'd.
m_did_exec = true;
- // Force the task port to update itself in case the
- // task port changed after exec
+ // Force the task port to update itself in case the task port
+ // changed after exec
const task_t old_task = m_task;
const bool force_update = true;
const task_t new_task = TaskPortForProcessID(error, force_update);
@@ -810,8 +805,7 @@ task_t NativeProcessDarwin::ExceptionMessageBundleComplete() {
// 4 - We might need to resume if we stopped only with the
// interrupt signal that we never handled.
if (m_auto_resume_signo != 0) {
- // Only auto_resume if we stopped with _only_ the interrupt
- // signal.
+ // Only auto_resume if we stopped with _only_ the interrupt signal.
if (num_task_exceptions == 1) {
auto_resume = true;
if (log)
@@ -831,8 +825,8 @@ task_t NativeProcessDarwin::ExceptionMessageBundleComplete() {
}
}
- // Let all threads recover from stopping and do any clean up based
- // on the previous thread state (if any).
+ // Let all threads recover from stopping and do any clean up based on the
+ // previous thread state (if any).
m_thread_list.ProcessDidStop(*this);
// Let each thread know of any exceptions
@@ -863,8 +857,8 @@ task_t NativeProcessDarwin::ExceptionMessageBundleComplete() {
// TODO - need to hook up event system here. !!!!
#if 0
// Wait for the eEventProcessRunningStateChanged event to be reset
- // before changing state to stopped to avoid race condition with
- // very fast start/stops.
+ // before changing state to stopped to avoid race condition with very
+ // fast start/stops.
struct timespec timeout;
//DNBTimer::OffsetTimeOfDay(&timeout, 0, 250 * 1000); // Wait for 250 ms
@@ -889,12 +883,12 @@ Status NativeProcessDarwin::StartWaitpidThread(MainLoop &main_loop) {
Status error;
Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS));
- // Strategy: create a thread that sits on waitpid(), waiting for the
- // inferior process to die, reaping it in the process. Arrange for
- // the thread to have a pipe file descriptor that it can send a byte
- // over when the waitpid completes. Have the main loop have a read
- // object for the other side of the pipe, and have the callback for
- // the read do the process termination message sending.
+ // Strategy: create a thread that sits on waitpid(), waiting for the inferior
+ // process to die, reaping it in the process. Arrange for the thread to have
+ // a pipe file descriptor that it can send a byte over when the waitpid
+ // completes. Have the main loop have a read object for the other side of
+ // the pipe, and have the callback for the read do the process termination
+ // message sending.
// Create a single-direction communication channel.
const bool child_inherits = false;
@@ -1025,8 +1019,8 @@ void *NativeProcessDarwin::DoWaitpidThread() {
}
}
- // We should never exit as long as our child process is alive. If we
- // get here, something completely unexpected went wrong and we should exit.
+ // We should never exit as long as our child process is alive. If we get
+ // here, something completely unexpected went wrong and we should exit.
if (log)
log->Printf(
"NativeProcessDarwin::%s(): internal error: waitpid thread "
@@ -1157,8 +1151,8 @@ task_t NativeProcessDarwin::TaskPortForProcessID(Status &error,
::usleep(usec_interval);
}
- // We failed to get the task for the inferior process.
- // Ensure that it is cleared out.
+ // We failed to get the task for the inferior process. Ensure that it is
+ // cleared out.
m_task = TASK_NULL;
}
return m_task;
@@ -1196,9 +1190,9 @@ Status NativeProcessDarwin::PrivateResume() {
}
// bool stepOverBreakInstruction = step;
- // Let the thread prepare to resume and see if any threads want us to
- // step over a breakpoint instruction (ProcessWillResume will modify
- // the value of stepOverBreakInstruction).
+ // Let the thread prepare to resume and see if any threads want us to step
+ // over a breakpoint instruction (ProcessWillResume will modify the value of
+ // stepOverBreakInstruction).
m_thread_list.ProcessWillResume(*this, m_thread_actions);
// Set our state accordingly
@@ -1254,8 +1248,8 @@ Status NativeProcessDarwin::ReplyToAllExceptions() {
error = message.Reply(m_pid, m_task, thread_reply_signal);
if (error.Fail() && log) {
- // We log any error here, but we don't stop the exception
- // response handling.
+ // We log any error here, but we don't stop the exception response
+ // handling.
log->Printf("NativeProcessDarwin::%s(): failed to reply to "
"exception: %s",
__FUNCTION__, error.AsCString());
@@ -1263,8 +1257,8 @@ Status NativeProcessDarwin::ReplyToAllExceptions() {
}
}
- // Erase all exception message as we should have used and replied
- // to them all already.
+ // Erase all exception message as we should have used and replied to them all
+ // already.
m_exception_messages.clear();
return error;
}
@@ -1292,8 +1286,8 @@ Status NativeProcessDarwin::ResumeTask() {
"0x%4.4x",
__FUNCTION__, m_task);
- // Get the BasicInfo struct to verify that we're suspended before we try
- // to resume the task.
+ // Get the BasicInfo struct to verify that we're suspended before we try to
+ // resume the task.
struct task_basic_info task_info;
error = GetTaskBasicInfo(m_task, &task_info);
if (error.Fail()) {
@@ -1304,9 +1298,8 @@ Status NativeProcessDarwin::ResumeTask() {
return error;
}
- // task_resume isn't counted like task_suspend calls are, so if the
- // task is not suspended, don't try and resume it since it is already
- // running
+ // task_resume isn't counted like task_suspend calls are, so if the task is
+ // not suspended, don't try and resume it since it is already running
if (task_info.suspend_count > 0) {
auto mach_err = ::task_resume(m_task);
error.SetError(mach_err, eErrorTypeMachKernel);
diff --git a/source/Plugins/Process/Darwin/NativeProcessDarwin.h b/source/Plugins/Process/Darwin/NativeProcessDarwin.h
index 649280c17a8f3..0b186fd7d80cd 100644
--- a/source/Plugins/Process/Darwin/NativeProcessDarwin.h
+++ b/source/Plugins/Process/Darwin/NativeProcessDarwin.h
@@ -43,10 +43,10 @@ class Scalar;
namespace process_darwin {
/// @class NativeProcessDarwin
-/// @brief Manages communication with the inferior (debugee) process.
+/// Manages communication with the inferior (debugee) process.
///
-/// Upon construction, this class prepares and launches an inferior
-/// process for debugging.
+/// Upon construction, this class prepares and launches an inferior process
+/// for debugging.
///
/// Changes in the inferior process state are broadcasted.
class NativeProcessDarwin : public NativeProcessProtocol {
@@ -205,10 +205,10 @@ private:
// -----------------------------------------------------------------
/// Finalize the launch.
///
- /// This method associates the NativeProcessDarwin instance with
- /// the host process that was just launched. It peforms actions
- /// like attaching a listener to the inferior exception port,
- /// ptracing the process, and the like.
+ /// This method associates the NativeProcessDarwin instance with the host
+ /// process that was just launched. It peforms actions like attaching a
+ /// listener to the inferior exception port, ptracing the process, and the
+ /// like.
///
/// @param[in] launch_flavor
/// The launch flavor that was used to launch the process.
@@ -263,8 +263,8 @@ private:
task_t TaskPortForProcessID(Status &error, bool force = false) const;
- /// Attaches to an existing process. Forms the
- /// implementation of Process::DoAttach.
+ /// Attaches to an existing process. Forms the implementation of
+ /// Process::DoAttach.
void AttachToInferior(MainLoop &mainloop, lldb::pid_t pid, Status &error);
::pid_t Attach(lldb::pid_t pid, Status &error);
@@ -323,8 +323,8 @@ private:
Status GetSignalInfo(lldb::tid_t tid, void *siginfo);
/// Writes the raw event message code (vis-a-vis PTRACE_GETEVENTMSG)
- /// corresponding to the given thread ID to the memory pointed to
- /// by @p message.
+ /// corresponding to the given thread ID to the memory pointed to by @p
+ /// message.
Status GetEventMessage(lldb::tid_t tid, unsigned long *message);
void NotifyThreadDeath(lldb::tid_t tid);
diff --git a/source/Plugins/Process/Darwin/NativeThreadDarwin.cpp b/source/Plugins/Process/Darwin/NativeThreadDarwin.cpp
index 07398ab7b6781..521c6d5c8fd03 100644
--- a/source/Plugins/Process/Darwin/NativeThreadDarwin.cpp
+++ b/source/Plugins/Process/Darwin/NativeThreadDarwin.cpp
@@ -30,8 +30,8 @@ uint64_t NativeThreadDarwin::GetGloballyUniqueThreadIDForMachPortID(
(thread_info_t)&tident, &tident_count);
if (mach_err != KERN_SUCCESS) {
// When we fail to get thread info for the supposed port, assume it is
- // really a globally unique thread id already, or return the best thing
- // we can, which is the thread port.
+ // really a globally unique thread id already, or return the best thing we
+ // can, which is the thread port.
return mach_port_id;
}
return tident.thread_id;
@@ -47,9 +47,9 @@ NativeThreadDarwin::NativeThreadDarwin(NativeProcessDarwin *process,
bool NativeThreadDarwin::GetIdentifierInfo() {
// Don't try to get the thread info once and cache it for the life of the
- // thread. It changes over time, for instance
- // if the thread name changes, then the thread_handle also changes... So you
- // have to refetch it every time.
+ // thread. It changes over time, for instance if the thread name changes,
+ // then the thread_handle also changes... So you have to refetch it every
+ // time.
mach_msg_type_number_t count = THREAD_IDENTIFIER_INFO_COUNT;
kern_return_t kret = ::thread_info(m_mach_thread_port, THREAD_IDENTIFIER_INFO,
(thread_info_t)&m_ident_info, &count);
@@ -137,16 +137,16 @@ bool NativeThreadDarwin::NotifyException(MachException::Data &exc) {
// TODO implement this.
#if 0
// Allow the arch specific protocol to process (MachException::Data &)exc
- // first before possible reassignment of m_stop_exception with exc.
- // See also MachThread::GetStopException().
+ // first before possible reassignment of m_stop_exception with exc. See
+ // also MachThread::GetStopException().
bool handled = m_arch_ap->NotifyException(exc);
if (m_stop_exception.IsValid())
{
// We may have more than one exception for a thread, but we need to
- // only remember the one that we will say is the reason we stopped.
- // We may have been single stepping and also gotten a signal exception,
- // so just remember the most pertinent one.
+ // only remember the one that we will say is the reason we stopped. We
+ // may have been single stepping and also gotten a signal exception, so
+ // just remember the most pertinent one.
if (m_stop_exception.IsBreakpoint())
m_stop_exception = exc;
}
@@ -170,8 +170,8 @@ bool NativeThreadDarwin::ShouldStop(bool &step_more) const {
if (bp)
{
- // This thread is sitting at a breakpoint, ask the breakpoint
- // if we should be stopping here.
+ // This thread is sitting at a breakpoint, ask the breakpoint if we
+ // should be stopping here.
return true;
}
else
@@ -181,11 +181,10 @@ bool NativeThreadDarwin::ShouldStop(bool &step_more) const {
step_more = true;
return false;
}
- // The thread state is used to let us know what the thread was
- // trying to do. MachThread::ThreadWillResume() will set the
- // thread state to various values depending if the thread was
- // the current thread and if it was to be single stepped, or
- // resumed.
+ // The thread state is used to let us know what the thread was trying
+ // to do. MachThread::ThreadWillResume() will set the thread state to
+ // various values depending if the thread was the current thread and if
+ // it was to be single stepped, or resumed.
if (GetState() == eStateRunning)
{
// If our state is running, then we should continue as we are in
@@ -194,8 +193,7 @@ bool NativeThreadDarwin::ShouldStop(bool &step_more) const {
}
else
{
- // Stop if we have any kind of valid exception for this
- // thread.
+ // Stop if we have any kind of valid exception for this thread.
if (GetStopException().IsValid())
return true;
}
@@ -209,17 +207,17 @@ bool NativeThreadDarwin::ShouldStop(bool &step_more) const {
void NativeThreadDarwin::ThreadDidStop() {
// TODO implement this.
#if 0
- // This thread has existed prior to resuming under debug nub control,
- // and has just been stopped. Do any cleanup that needs to be done
- // after running.
+ // This thread has existed prior to resuming under debug nub control, and
+ // has just been stopped. Do any cleanup that needs to be done after
+ // running.
- // The thread state and breakpoint will still have the same values
- // as they had prior to resuming the thread, so it makes it easy to check
- // if we were trying to step a thread, or we tried to resume while being
- // at a breakpoint.
+ // The thread state and breakpoint will still have the same values as they
+ // had prior to resuming the thread, so it makes it easy to check if we
+ // were trying to step a thread, or we tried to resume while being at a
+ // breakpoint.
- // When this method gets called, the process state is still in the
- // state it was in while running so we can act accordingly.
+ // When this method gets called, the process state is still in the state it
+ // was in while running so we can act accordingly.
m_arch_ap->ThreadDidStop();
diff --git a/source/Plugins/Process/Darwin/NativeThreadListDarwin.cpp b/source/Plugins/Process/Darwin/NativeThreadListDarwin.cpp
index 7d44adeec3753..4ff662e420972 100644
--- a/source/Plugins/Process/Darwin/NativeThreadListDarwin.cpp
+++ b/source/Plugins/Process/Darwin/NativeThreadListDarwin.cpp
@@ -308,8 +308,8 @@ uint32_t NativeThreadListDarwin::UpdateThreadList(NativeProcessDarwin &process,
__FUNCTION__, process.GetID(), update, process.GetStopID());
if (process.GetStopID() == 0) {
- // On our first stop, we'll record details like 32/64 bitness and
- // select the proper architecture implementation.
+ // On our first stop, we'll record details like 32/64 bitness and select
+ // the proper architecture implementation.
//
int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_PID, (int)process.GetID()};
@@ -358,9 +358,9 @@ uint32_t NativeThreadListDarwin::UpdateThreadList(NativeProcessDarwin &process,
if (thread_list_count > 0) {
collection currThreads;
size_t idx;
- // Iterator through the current thread list and see which threads
- // we already have in our list (keep them), which ones we don't
- // (add them), and which ones are not around anymore (remove them).
+ // Iterator through the current thread list and see which threads we
+ // already have in our list (keep them), which ones we don't (add them),
+ // and which ones are not around anymore (remove them).
for (idx = 0; idx < thread_list_count; ++idx) {
// Get the Mach thread port.
const ::thread_t mach_port_num = thread_list[idx];
@@ -373,18 +373,18 @@ uint32_t NativeThreadListDarwin::UpdateThreadList(NativeProcessDarwin &process,
// Retrieve the thread if it exists.
auto thread_sp = GetThreadByID(unique_thread_id);
if (thread_sp) {
- // We are already tracking it. Keep the existing native
- // thread instance.
+ // We are already tracking it. Keep the existing native thread
+ // instance.
currThreads.push_back(thread_sp);
} else {
- // We don't have a native thread instance for this thread.
- // Create it now.
+ // We don't have a native thread instance for this thread. Create it
+ // now.
thread_sp.reset(new NativeThreadDarwin(
&process, m_is_64_bit, unique_thread_id, mach_port_num));
- // Add the new thread regardless of its is user ready state.
- // Make sure the thread is ready to be displayed and shown
- // to users before we add this thread to our list...
+ // Add the new thread regardless of its is user ready state. Make
+ // sure the thread is ready to be displayed and shown to users before
+ // we add this thread to our list...
if (thread_sp->IsUserReady()) {
if (new_threads)
new_threads->push_back(thread_sp);
@@ -417,9 +417,9 @@ NativeThreadListDarwin::CurrentThread (MachThreadSP& thread_sp)
PTHREAD_MUTEX_LOCKER (locker, m_threads_mutex);
if (m_current_thread.get() == NULL)
{
- // Figure out which thread is going to be our current thread.
- // This is currently done by finding the first thread in the list
- // that has a valid exception.
+ // Figure out which thread is going to be our current thread. This is
+ // currently done by finding the first thread in the list that has a
+ // valid exception.
const size_t num_threads = m_threads.size();
for (uint32_t idx = 0; idx < num_threads; ++idx)
{
@@ -455,8 +455,8 @@ void NativeThreadListDarwin::ProcessWillResume(
NativeProcessDarwin &process, const ResumeActionList &thread_actions) {
std::lock_guard<std::recursive_mutex> locker(m_threads_mutex);
- // Update our thread list, because sometimes libdispatch or the kernel
- // will spawn threads while a task is suspended.
+ // Update our thread list, because sometimes libdispatch or the kernel will
+ // spawn threads while a task is suspended.
NativeThreadListDarwin::collection new_threads;
// TODO implement this.
@@ -489,7 +489,8 @@ void NativeThreadListDarwin::ProcessWillResume(
#if 0
DNBThreadResumeAction resume_new_threads = { -1U, eStateRunning, 0, INVALID_NUB_ADDRESS };
- // If we are planning to run only one thread, any new threads should be suspended.
+ // If we are planning to run only one thread, any new threads should be
+ // suspended.
if (run_one_thread)
resume_new_threads.state = eStateSuspended;
@@ -549,11 +550,11 @@ uint32_t NativeThreadListDarwin::ProcessDidStop(NativeProcessDarwin &process) {
}
//----------------------------------------------------------------------
-// Check each thread in our thread list to see if we should notify our
-// client of the current halt in execution.
+// Check each thread in our thread list to see if we should notify our client
+// of the current halt in execution.
//
-// Breakpoints can have callback functions associated with them than
-// can return true to stop, or false to continue executing the inferior.
+// Breakpoints can have callback functions associated with them than can return
+// true to stop, or false to continue executing the inferior.
//
// RETURNS
// true if we should stop and notify our clients
@@ -607,8 +608,9 @@ NativeThreadListDarwin::DisableHardwareBreakpoint (const DNBBreakpoint* bp) cons
return false;
}
-// DNBWatchpointSet() -> MachProcess::CreateWatchpoint() -> MachProcess::EnableWatchpoint()
-// -> NativeThreadListDarwin::EnableHardwareWatchpoint().
+// DNBWatchpointSet() -> MachProcess::CreateWatchpoint() ->
+// MachProcess::EnableWatchpoint() ->
+// NativeThreadListDarwin::EnableHardwareWatchpoint().
uint32_t
NativeThreadListDarwin::EnableHardwareWatchpoint (const DNBBreakpoint* wp) const
{
@@ -617,14 +619,16 @@ NativeThreadListDarwin::EnableHardwareWatchpoint (const DNBBreakpoint* wp) const
{
PTHREAD_MUTEX_LOCKER (locker, m_threads_mutex);
const size_t num_threads = m_threads.size();
- // On Mac OS X we have to prime the control registers for new threads. We do this
- // using the control register data for the first thread, for lack of a better way of choosing.
+ // On Mac OS X we have to prime the control registers for new threads.
+ // We do this using the control register data for the first thread, for
+ // lack of a better way of choosing.
bool also_set_on_task = true;
for (uint32_t idx = 0; idx < num_threads; ++idx)
{
if ((hw_index = m_threads[idx]->EnableHardwareWatchpoint(wp, also_set_on_task)) == INVALID_NUB_HW_INDEX)
{
- // We know that idx failed for some reason. Let's rollback the transaction for [0, idx).
+ // We know that idx failed for some reason. Let's rollback the
+ // transaction for [0, idx).
for (uint32_t i = 0; i < idx; ++i)
m_threads[i]->RollbackTransForHWP();
return INVALID_NUB_HW_INDEX;
@@ -647,14 +651,16 @@ NativeThreadListDarwin::DisableHardwareWatchpoint (const DNBBreakpoint* wp) cons
PTHREAD_MUTEX_LOCKER (locker, m_threads_mutex);
const size_t num_threads = m_threads.size();
- // On Mac OS X we have to prime the control registers for new threads. We do this
- // using the control register data for the first thread, for lack of a better way of choosing.
+ // On Mac OS X we have to prime the control registers for new threads.
+ // We do this using the control register data for the first thread, for
+ // lack of a better way of choosing.
bool also_set_on_task = true;
for (uint32_t idx = 0; idx < num_threads; ++idx)
{
if (!m_threads[idx]->DisableHardwareWatchpoint(wp, also_set_on_task))
{
- // We know that idx failed for some reason. Let's rollback the transaction for [0, idx).
+ // We know that idx failed for some reason. Let's rollback the
+ // transaction for [0, idx).
for (uint32_t i = 0; i < idx; ++i)
m_threads[i]->RollbackTransForHWP();
return false;
@@ -675,7 +681,8 @@ NativeThreadListDarwin::NumSupportedHardwareWatchpoints () const
{
PTHREAD_MUTEX_LOCKER (locker, m_threads_mutex);
const size_t num_threads = m_threads.size();
- // Use an arbitrary thread to retrieve the number of supported hardware watchpoints.
+ // Use an arbitrary thread to retrieve the number of supported hardware
+ // watchpoints.
if (num_threads)
return m_threads[0]->NumSupportedHardwareWatchpoints();
return 0;
diff --git a/source/Plugins/Process/FreeBSD/CMakeLists.txt b/source/Plugins/Process/FreeBSD/CMakeLists.txt
index 63855992d7088..c8301f350e076 100644
--- a/source/Plugins/Process/FreeBSD/CMakeLists.txt
+++ b/source/Plugins/Process/FreeBSD/CMakeLists.txt
@@ -1,7 +1,3 @@
-include_directories(.)
-include_directories(../POSIX)
-include_directories(../Utility)
-
add_lldb_library(lldbPluginProcessFreeBSD PLUGIN
ProcessFreeBSD.cpp
FreeBSDThread.cpp
diff --git a/source/Plugins/Process/FreeBSD/FreeBSDThread.cpp b/source/Plugins/Process/FreeBSD/FreeBSDThread.cpp
index e6557c2d58e03..3576a7f26f869 100644
--- a/source/Plugins/Process/FreeBSD/FreeBSDThread.cpp
+++ b/source/Plugins/Process/FreeBSD/FreeBSDThread.cpp
@@ -57,7 +57,7 @@ using namespace lldb_private;
FreeBSDThread::FreeBSDThread(Process &process, lldb::tid_t tid)
: Thread(process, tid), m_frame_ap(), m_breakpoint(),
- m_thread_name_valid(false), m_thread_name(), m_posix_thread(NULL) {
+ m_thread_name_valid(false), m_thread_name(), m_posix_thread(nullptr) {
Log *log(ProcessPOSIXLog::GetLogIfAllCategoriesSet(POSIX_LOG_THREAD));
LLDB_LOGV(log, "tid = {0}", tid);
@@ -69,15 +69,15 @@ FreeBSDThread::FreeBSDThread(Process &process, lldb::tid_t tid)
for (uint32_t wp_idx = 0; wp_idx < wp_size; wp_idx++) {
lldb::WatchpointSP wp = wp_list.GetByIndex(wp_idx);
if (wp.get() && wp->IsEnabled()) {
- // This watchpoint as been enabled; obviously this "new" thread
- // has been created since that watchpoint was enabled. Since
- // the POSIXBreakpointProtocol has yet to be initialized, its
- // m_watchpoints_initialized member will be FALSE. Attempting to
- // read the debug status register to determine if a watchpoint
- // has been hit would result in the zeroing of that register.
- // Since the active debug registers would have been cloned when
- // this thread was created, simply force the m_watchpoints_initized
- // member to TRUE and avoid resetting dr6 and dr7.
+ // This watchpoint as been enabled; obviously this "new" thread has been
+ // created since that watchpoint was enabled. Since the
+ // POSIXBreakpointProtocol has yet to be initialized, its
+ // m_watchpoints_initialized member will be FALSE. Attempting to read
+ // the debug status register to determine if a watchpoint has been hit
+ // would result in the zeroing of that register. Since the active debug
+ // registers would have been cloned when this thread was created, simply
+ // force the m_watchpoints_initized member to TRUE and avoid resetting
+ // dr6 and dr7.
GetPOSIXBreakpointProtocol()->ForceWatchpointsInitialized();
}
}
@@ -98,16 +98,15 @@ void FreeBSDThread::RefreshStateAfterStop() {
// context by the time this function gets called. The KDPRegisterContext
// class has been made smart enough to detect when it needs to invalidate
// which registers are valid by putting hooks in the register read and
- // register supply functions where they check the process stop ID and do
- // the right thing.
- // if (StateIsStoppedState(GetState())
+ // register supply functions where they check the process stop ID and do the
+ // right thing. if (StateIsStoppedState(GetState())
{
const bool force = false;
GetRegisterContext()->InvalidateIfNeeded(force);
}
}
-const char *FreeBSDThread::GetInfo() { return NULL; }
+const char *FreeBSDThread::GetInfo() { return nullptr; }
void FreeBSDThread::SetName(const char *name) {
m_thread_name_valid = (name && name[0]);
@@ -158,15 +157,15 @@ const char *FreeBSDThread::GetName() {
}
if (m_thread_name.empty())
- return NULL;
+ return nullptr;
return m_thread_name.c_str();
}
lldb::RegisterContextSP FreeBSDThread::GetRegisterContext() {
if (!m_reg_context_sp) {
- m_posix_thread = NULL;
+ m_posix_thread = nullptr;
- RegisterInfoInterface *reg_interface = NULL;
+ RegisterInfoInterface *reg_interface = nullptr;
const ArchSpec &target_arch = GetProcess()->GetTarget().GetArchitecture();
assert(target_arch.GetTriple().getOS() == llvm::Triple::FreeBSD);
@@ -282,7 +281,7 @@ bool FreeBSDThread::CalculateStopInfo() {
}
Unwind *FreeBSDThread::GetUnwinder() {
- if (m_unwinder_ap.get() == NULL)
+ if (!m_unwinder_ap)
m_unwinder_ap.reset(new UnwindLLDB(*this));
return m_unwinder_ap.get();
@@ -469,22 +468,19 @@ void FreeBSDThread::BreakNotify(const ProcessMessage &message) {
GetProcess()->GetBreakpointSiteList().FindByAddress(pc));
// If the breakpoint is for this thread, then we'll report the hit, but if it
- // is for another thread,
- // we create a stop reason with should_stop=false. If there is no breakpoint
- // location, then report
- // an invalid stop reason. We don't need to worry about stepping over the
- // breakpoint here, that will
- // be taken care of when the thread resumes and notices that there's a
+ // is for another thread, we create a stop reason with should_stop=false. If
+ // there is no breakpoint location, then report an invalid stop reason. We
+ // don't need to worry about stepping over the breakpoint here, that will be
+ // taken care of when the thread resumes and notices that there's a
// breakpoint under the pc.
if (bp_site) {
lldb::break_id_t bp_id = bp_site->GetID();
// If we have an operating system plug-in, we might have set a thread
- // specific breakpoint using the
- // operating system thread ID, so we can't make any assumptions about the
- // thread ID so we must always
- // report the breakpoint regardless of the thread.
+ // specific breakpoint using the operating system thread ID, so we can't
+ // make any assumptions about the thread ID so we must always report the
+ // breakpoint regardless of the thread.
if (bp_site->ValidForThisThread(this) ||
- GetProcess()->GetOperatingSystem() != NULL)
+ GetProcess()->GetOperatingSystem() != nullptr)
SetStopInfo(StopInfo::CreateStopReasonWithBreakpointSiteID(*this, bp_id));
else {
const bool should_stop = false;
@@ -541,15 +537,14 @@ void FreeBSDThread::TraceNotify(const ProcessMessage &message) {
lldb::BreakpointSiteSP bp_site(
GetProcess()->GetBreakpointSiteList().FindByAddress(pc));
- // If the current pc is a breakpoint site then set the StopInfo to Breakpoint.
- // Otherwise, set the StopInfo to Watchpoint or Trace.
- // If we have an operating system plug-in, we might have set a thread specific
- // breakpoint using the
- // operating system thread ID, so we can't make any assumptions about the
- // thread ID so we must always
- // report the breakpoint regardless of the thread.
+ // If the current pc is a breakpoint site then set the StopInfo to
+ // Breakpoint. Otherwise, set the StopInfo to Watchpoint or Trace. If we have
+ // an operating system plug-in, we might have set a thread specific
+ // breakpoint using the operating system thread ID, so we can't make any
+ // assumptions about the thread ID so we must always report the breakpoint
+ // regardless of the thread.
if (bp_site && (bp_site->ValidForThisThread(this) ||
- GetProcess()->GetOperatingSystem() != NULL))
+ GetProcess()->GetOperatingSystem() != nullptr))
SetStopInfo(StopInfo::CreateStopReasonWithBreakpointSiteID(
*this, bp_site->GetID()));
else {
diff --git a/source/Plugins/Process/FreeBSD/FreeBSDThread.h b/source/Plugins/Process/FreeBSD/FreeBSDThread.h
index 72e8464595527..c93cc4fbfd739 100644
--- a/source/Plugins/Process/FreeBSD/FreeBSDThread.h
+++ b/source/Plugins/Process/FreeBSD/FreeBSDThread.h
@@ -24,7 +24,7 @@ class POSIXBreakpointProtocol;
//------------------------------------------------------------------------------
// @class FreeBSDThread
-// @brief Abstraction of a FreeBSD thread.
+// Abstraction of a FreeBSD thread.
class FreeBSDThread : public lldb_private::Thread {
public:
//------------------------------------------------------------------
diff --git a/source/Plugins/Process/FreeBSD/POSIXStopInfo.h b/source/Plugins/Process/FreeBSD/POSIXStopInfo.h
index 96861852b38eb..ff3693107170b 100644
--- a/source/Plugins/Process/FreeBSD/POSIXStopInfo.h
+++ b/source/Plugins/Process/FreeBSD/POSIXStopInfo.h
@@ -17,7 +17,7 @@
//===----------------------------------------------------------------------===//
/// @class POSIXStopInfo
-/// @brief Simple base class for all POSIX-specific StopInfo objects.
+/// Simple base class for all POSIX-specific StopInfo objects.
///
class POSIXStopInfo : public lldb_private::StopInfo {
public:
@@ -27,7 +27,7 @@ public:
//===----------------------------------------------------------------------===//
/// @class POSIXLimboStopInfo
-/// @brief Represents the stop state of a process ready to exit.
+/// Represents the stop state of a process ready to exit.
///
class POSIXLimboStopInfo : public POSIXStopInfo {
public:
@@ -46,7 +46,7 @@ public:
//===----------------------------------------------------------------------===//
/// @class POSIXNewThreadStopInfo
-/// @brief Represents the stop state of process when a new thread is spawned.
+/// Represents the stop state of process when a new thread is spawned.
///
class POSIXNewThreadStopInfo : public POSIXStopInfo {
diff --git a/source/Plugins/Process/FreeBSD/ProcessFreeBSD.cpp b/source/Plugins/Process/FreeBSD/ProcessFreeBSD.cpp
index 7a937db49be0c..fa0bcea8f6bde 100644
--- a/source/Plugins/Process/FreeBSD/ProcessFreeBSD.cpp
+++ b/source/Plugins/Process/FreeBSD/ProcessFreeBSD.cpp
@@ -357,10 +357,10 @@ ProcessFreeBSD::GetFileSpec(const lldb_private::FileAction *file_action,
if (file_action && file_action->GetAction() == FileAction::eFileActionOpen) {
file_spec = file_action->GetFileSpec();
- // By default the stdio paths passed in will be pseudo-terminal
- // (/dev/pts). If so, convert to using a different default path
- // instead to redirect I/O to the debugger console. This should
- // also handle user overrides to /dev/null or a different file.
+ // By default the stdio paths passed in will be pseudo-terminal (/dev/pts).
+ // If so, convert to using a different default path instead to redirect I/O
+ // to the debugger console. This should also handle user overrides to
+ // /dev/null or a different file.
if (!file_spec || file_spec == dbg_pts_file_spec)
file_spec = default_file_spec;
}
@@ -407,9 +407,8 @@ Status ProcessFreeBSD::DoLaunch(Module *module,
m_monitor = new ProcessMonitor(
this, module, launch_info.GetArguments().GetConstArgumentVector(),
- launch_info.GetEnvironmentEntries().GetConstArgumentVector(),
- stdin_file_spec, stdout_file_spec, stderr_file_spec, working_dir,
- launch_info, error);
+ launch_info.GetEnvironment(), stdin_file_spec, stdout_file_spec,
+ stderr_file_spec, working_dir, launch_info, error);
m_module = module;
@@ -656,19 +655,19 @@ ProcessFreeBSD::GetSoftwareBreakpointTrapOpcode(BreakpointSite *bp_site) {
break;
case llvm::Triple::arm: {
- // The ARM reference recommends the use of 0xe7fddefe and 0xdefe
- // but the linux kernel does otherwise.
+ // The ARM reference recommends the use of 0xe7fddefe and 0xdefe but the
+ // linux kernel does otherwise.
static const uint8_t g_arm_breakpoint_opcode[] = {0xf0, 0x01, 0xf0, 0xe7};
static const uint8_t g_thumb_breakpoint_opcode[] = {0x01, 0xde};
lldb::BreakpointLocationSP bp_loc_sp(bp_site->GetOwnerAtIndex(0));
- AddressClass addr_class = eAddressClassUnknown;
+ AddressClass addr_class = AddressClass::eUnknown;
if (bp_loc_sp)
addr_class = bp_loc_sp->GetAddress().GetAddressClass();
- if (addr_class == eAddressClassCodeAlternateISA ||
- (addr_class == eAddressClassUnknown &&
+ if (addr_class == AddressClass::eCodeAlternateISA ||
+ (addr_class == AddressClass::eUnknown &&
bp_loc_sp->GetAddress().GetOffset() & 1)) {
opcode = g_thumb_breakpoint_opcode;
opcode_size = sizeof(g_thumb_breakpoint_opcode);
@@ -745,8 +744,8 @@ Status ProcessFreeBSD::EnableWatchpoint(Watchpoint *wp, bool notify) {
wp->SetEnabled(true, notify);
return error;
} else {
- // Watchpoint enabling failed on at least one
- // of the threads so roll back all of them
+ // Watchpoint enabling failed on at least one of the threads so roll
+ // back all of them
DisableWatchpoint(wp, false);
error.SetErrorString("Setting hardware watchpoint failed");
}
@@ -813,8 +812,8 @@ Status ProcessFreeBSD::GetWatchpointSupportInfo(uint32_t &num) {
Status ProcessFreeBSD::GetWatchpointSupportInfo(uint32_t &num, bool &after) {
Status error = GetWatchpointSupportInfo(num);
- // Watchpoints trigger and halt the inferior after
- // the corresponding instruction has been executed.
+ // Watchpoints trigger and halt the inferior after the corresponding
+ // instruction has been executed.
after = true;
return error;
}
@@ -1077,8 +1076,8 @@ Status ProcessFreeBSD::SetupSoftwareSingleStepping(lldb::tid_t tid) {
"Emulation was successful but PC wasn't updated");
next_pc = pc_it->second.GetAsUInt64();
} else if (pc_it == baton.m_register_values.end()) {
- // Emulate instruction failed and it haven't changed PC. Advance PC
- // with the size of the current opcode because the emulation of all
+ // Emulate instruction failed and it haven't changed PC. Advance PC with
+ // the size of the current opcode because the emulation of all
// PC modifying instruction should be successful. The failure most
// likely caused by a not supported instruction which don't modify PC.
next_pc =
diff --git a/source/Plugins/Process/FreeBSD/ProcessMonitor.cpp b/source/Plugins/Process/FreeBSD/ProcessMonitor.cpp
index bd06fa25f0a01..51fdf2e5ef33e 100644
--- a/source/Plugins/Process/FreeBSD/ProcessMonitor.cpp
+++ b/source/Plugins/Process/FreeBSD/ProcessMonitor.cpp
@@ -38,15 +38,11 @@
#include "ProcessFreeBSD.h"
#include "ProcessMonitor.h"
-extern "C" {
-extern char **environ;
-}
-
using namespace lldb;
using namespace lldb_private;
-// We disable the tracing of ptrace calls for integration builds to
-// avoid the additional indirection and checks.
+// We disable the tracing of ptrace calls for integration builds to avoid the
+// additional indirection and checks.
#ifndef LLDB_CONFIGURATION_BUILDANDINTEGRATION
// Wrapper for ptrace to catch errors and log calls.
@@ -65,9 +61,8 @@ const char *Get_PT_IO_OP(int op) {
}
}
-// Wrapper for ptrace to catch errors and log calls.
-// Note that ptrace sets errno on error because -1 is reserved as a valid
-// result.
+// Wrapper for ptrace to catch errors and log calls. Note that ptrace sets
+// errno on error because -1 is reserved as a valid result.
extern long PtraceWrapper(int req, lldb::pid_t pid, void *addr, int data,
const char *reqName, const char *file, int line) {
long int result;
@@ -134,8 +129,8 @@ extern long PtraceWrapper(int req, lldb::pid_t pid, void *addr, int data,
return result;
}
-// Wrapper for ptrace when logging is not required.
-// Sets errno to 0 prior to calling ptrace.
+// Wrapper for ptrace when logging is not required. Sets errno to 0 prior to
+// calling ptrace.
extern long PtraceWrapper(int req, lldb::pid_t pid, void *addr, int data) {
long result = 0;
errno = 0;
@@ -163,8 +158,10 @@ static size_t DoReadMemory(lldb::pid_t pid, lldb::addr_t vm_addr, void *buf,
pi_desc.piod_addr = buf;
pi_desc.piod_len = size;
- if (PTRACE(PT_IO, pid, (caddr_t)&pi_desc, 0) < 0)
+ if (PTRACE(PT_IO, pid, (caddr_t)&pi_desc, 0) < 0) {
error.SetErrorToErrno();
+ return 0;
+ }
return pi_desc.piod_len;
}
@@ -177,8 +174,10 @@ static size_t DoWriteMemory(lldb::pid_t pid, lldb::addr_t vm_addr,
pi_desc.piod_addr = (void *)buf;
pi_desc.piod_len = size;
- if (PTRACE(PT_IO, pid, (caddr_t)&pi_desc, 0) < 0)
+ if (PTRACE(PT_IO, pid, (caddr_t)&pi_desc, 0) < 0) {
error.SetErrorToErrno();
+ return 0;
+ }
return pi_desc.piod_len;
}
@@ -202,15 +201,16 @@ static bool EnsureFDFlags(int fd, int flags, Status &error) {
//------------------------------------------------------------------------------
/// @class Operation
-/// @brief Represents a ProcessMonitor operation.
+/// Represents a ProcessMonitor operation.
///
-/// Under FreeBSD, it is not possible to ptrace() from any other thread but the
-/// one that spawned or attached to the process from the start. Therefore, when
-/// a ProcessMonitor is asked to deliver or change the state of an inferior
-/// process the operation must be "funneled" to a specific thread to perform the
-/// task. The Operation class provides an abstract base for all services the
-/// ProcessMonitor must perform via the single virtual function Execute, thus
-/// encapsulating the code that needs to run in the privileged context.
+/// Under FreeBSD, it is not possible to ptrace() from any other thread but
+/// the one that spawned or attached to the process from the start.
+/// Therefore, when a ProcessMonitor is asked to deliver or change the state
+/// of an inferior process the operation must be "funneled" to a specific
+/// thread to perform the task. The Operation class provides an abstract base
+/// for all services the ProcessMonitor must perform via the single virtual
+/// function Execute, thus encapsulating the code that needs to run in the
+/// privileged context.
class Operation {
public:
virtual ~Operation() {}
@@ -219,7 +219,7 @@ public:
//------------------------------------------------------------------------------
/// @class ReadOperation
-/// @brief Implements ProcessMonitor::ReadMemory.
+/// Implements ProcessMonitor::ReadMemory.
class ReadOperation : public Operation {
public:
ReadOperation(lldb::addr_t addr, void *buff, size_t size, Status &error,
@@ -245,7 +245,7 @@ void ReadOperation::Execute(ProcessMonitor *monitor) {
//------------------------------------------------------------------------------
/// @class WriteOperation
-/// @brief Implements ProcessMonitor::WriteMemory.
+/// Implements ProcessMonitor::WriteMemory.
class WriteOperation : public Operation {
public:
WriteOperation(lldb::addr_t addr, const void *buff, size_t size,
@@ -271,7 +271,7 @@ void WriteOperation::Execute(ProcessMonitor *monitor) {
//------------------------------------------------------------------------------
/// @class ReadRegOperation
-/// @brief Implements ProcessMonitor::ReadRegisterValue.
+/// Implements ProcessMonitor::ReadRegisterValue.
class ReadRegOperation : public Operation {
public:
ReadRegOperation(lldb::tid_t tid, unsigned offset, unsigned size,
@@ -311,7 +311,7 @@ void ReadRegOperation::Execute(ProcessMonitor *monitor) {
//------------------------------------------------------------------------------
/// @class WriteRegOperation
-/// @brief Implements ProcessMonitor::WriteRegisterValue.
+/// Implements ProcessMonitor::WriteRegisterValue.
class WriteRegOperation : public Operation {
public:
WriteRegOperation(lldb::tid_t tid, unsigned offset,
@@ -344,7 +344,7 @@ void WriteRegOperation::Execute(ProcessMonitor *monitor) {
//------------------------------------------------------------------------------
/// @class ReadDebugRegOperation
-/// @brief Implements ProcessMonitor::ReadDebugRegisterValue.
+/// Implements ProcessMonitor::ReadDebugRegisterValue.
class ReadDebugRegOperation : public Operation {
public:
ReadDebugRegOperation(lldb::tid_t tid, unsigned offset, unsigned size,
@@ -379,7 +379,7 @@ void ReadDebugRegOperation::Execute(ProcessMonitor *monitor) {
//------------------------------------------------------------------------------
/// @class WriteDebugRegOperation
-/// @brief Implements ProcessMonitor::WriteDebugRegisterValue.
+/// Implements ProcessMonitor::WriteDebugRegisterValue.
class WriteDebugRegOperation : public Operation {
public:
WriteDebugRegOperation(lldb::tid_t tid, unsigned offset,
@@ -412,7 +412,7 @@ void WriteDebugRegOperation::Execute(ProcessMonitor *monitor) {
//------------------------------------------------------------------------------
/// @class ReadGPROperation
-/// @brief Implements ProcessMonitor::ReadGPR.
+/// Implements ProcessMonitor::ReadGPR.
class ReadGPROperation : public Operation {
public:
ReadGPROperation(lldb::tid_t tid, void *buf, bool &result)
@@ -439,7 +439,7 @@ void ReadGPROperation::Execute(ProcessMonitor *monitor) {
//------------------------------------------------------------------------------
/// @class ReadFPROperation
-/// @brief Implements ProcessMonitor::ReadFPR.
+/// Implements ProcessMonitor::ReadFPR.
class ReadFPROperation : public Operation {
public:
ReadFPROperation(lldb::tid_t tid, void *buf, bool &result)
@@ -462,7 +462,7 @@ void ReadFPROperation::Execute(ProcessMonitor *monitor) {
//------------------------------------------------------------------------------
/// @class WriteGPROperation
-/// @brief Implements ProcessMonitor::WriteGPR.
+/// Implements ProcessMonitor::WriteGPR.
class WriteGPROperation : public Operation {
public:
WriteGPROperation(lldb::tid_t tid, void *buf, bool &result)
@@ -485,7 +485,7 @@ void WriteGPROperation::Execute(ProcessMonitor *monitor) {
//------------------------------------------------------------------------------
/// @class WriteFPROperation
-/// @brief Implements ProcessMonitor::WriteFPR.
+/// Implements ProcessMonitor::WriteFPR.
class WriteFPROperation : public Operation {
public:
WriteFPROperation(lldb::tid_t tid, void *buf, bool &result)
@@ -508,7 +508,7 @@ void WriteFPROperation::Execute(ProcessMonitor *monitor) {
//------------------------------------------------------------------------------
/// @class ResumeOperation
-/// @brief Implements ProcessMonitor::Resume.
+/// Implements ProcessMonitor::Resume.
class ResumeOperation : public Operation {
public:
ResumeOperation(uint32_t signo, bool &result)
@@ -539,7 +539,7 @@ void ResumeOperation::Execute(ProcessMonitor *monitor) {
//------------------------------------------------------------------------------
/// @class SingleStepOperation
-/// @brief Implements ProcessMonitor::SingleStep.
+/// Implements ProcessMonitor::SingleStep.
class SingleStepOperation : public Operation {
public:
SingleStepOperation(uint32_t signo, bool &result)
@@ -567,7 +567,7 @@ void SingleStepOperation::Execute(ProcessMonitor *monitor) {
//------------------------------------------------------------------------------
/// @class LwpInfoOperation
-/// @brief Implements ProcessMonitor::GetLwpInfo.
+/// Implements ProcessMonitor::GetLwpInfo.
class LwpInfoOperation : public Operation {
public:
LwpInfoOperation(lldb::tid_t tid, void *info, bool &result, int &ptrace_err)
@@ -596,7 +596,7 @@ void LwpInfoOperation::Execute(ProcessMonitor *monitor) {
//------------------------------------------------------------------------------
/// @class ThreadSuspendOperation
-/// @brief Implements ProcessMonitor::ThreadSuspend.
+/// Implements ProcessMonitor::ThreadSuspend.
class ThreadSuspendOperation : public Operation {
public:
ThreadSuspendOperation(lldb::tid_t tid, bool suspend, bool &result)
@@ -616,7 +616,7 @@ void ThreadSuspendOperation::Execute(ProcessMonitor *monitor) {
//------------------------------------------------------------------------------
/// @class EventMessageOperation
-/// @brief Implements ProcessMonitor::GetEventMessage.
+/// Implements ProcessMonitor::GetEventMessage.
class EventMessageOperation : public Operation {
public:
EventMessageOperation(lldb::tid_t tid, unsigned long *message, bool &result)
@@ -646,7 +646,7 @@ void EventMessageOperation::Execute(ProcessMonitor *monitor) {
//------------------------------------------------------------------------------
/// @class KillOperation
-/// @brief Implements ProcessMonitor::Kill.
+/// Implements ProcessMonitor::Kill.
class KillOperation : public Operation {
public:
KillOperation(bool &result) : m_result(result) {}
@@ -668,7 +668,7 @@ void KillOperation::Execute(ProcessMonitor *monitor) {
//------------------------------------------------------------------------------
/// @class DetachOperation
-/// @brief Implements ProcessMonitor::Detach.
+/// Implements ProcessMonitor::Detach.
class DetachOperation : public Operation {
public:
DetachOperation(Status &result) : m_error(result) {}
@@ -695,13 +695,14 @@ ProcessMonitor::OperationArgs::~OperationArgs() { sem_destroy(&m_semaphore); }
ProcessMonitor::LaunchArgs::LaunchArgs(ProcessMonitor *monitor,
lldb_private::Module *module,
- char const **argv, char const **envp,
+ char const **argv, Environment env,
const FileSpec &stdin_file_spec,
const FileSpec &stdout_file_spec,
const FileSpec &stderr_file_spec,
const FileSpec &working_dir)
- : OperationArgs(monitor), m_module(module), m_argv(argv), m_envp(envp),
- m_stdin_file_spec(stdin_file_spec), m_stdout_file_spec(stdout_file_spec),
+ : OperationArgs(monitor), m_module(module), m_argv(argv),
+ m_env(std::move(env)), m_stdin_file_spec(stdin_file_spec),
+ m_stdout_file_spec(stdout_file_spec),
m_stderr_file_spec(stderr_file_spec), m_working_dir(working_dir) {}
ProcessMonitor::LaunchArgs::~LaunchArgs() {}
@@ -714,11 +715,10 @@ ProcessMonitor::AttachArgs::~AttachArgs() {}
//------------------------------------------------------------------------------
/// The basic design of the ProcessMonitor is built around two threads.
///
-/// One thread (@see SignalThread) simply blocks on a call to waitpid() looking
-/// for changes in the debugee state. When a change is detected a
+/// One thread (@see SignalThread) simply blocks on a call to waitpid()
+/// looking for changes in the debugee state. When a change is detected a
/// ProcessMessage is sent to the associated ProcessFreeBSD instance. This
-/// thread
-/// "drives" state changes in the debugger.
+/// thread "drives" state changes in the debugger.
///
/// The second thread (@see OperationThread) is responsible for two things 1)
/// launching or attaching to the inferior process, and then 2) servicing
@@ -726,7 +726,7 @@ ProcessMonitor::AttachArgs::~AttachArgs() {}
/// on the Operation class for more info as to why this is needed.
ProcessMonitor::ProcessMonitor(
ProcessFreeBSD *process, Module *module, const char *argv[],
- const char *envp[], const FileSpec &stdin_file_spec,
+ Environment env, const FileSpec &stdin_file_spec,
const FileSpec &stdout_file_spec, const FileSpec &stderr_file_spec,
const FileSpec &working_dir,
const lldb_private::ProcessLaunchInfo & /* launch_info */,
@@ -736,7 +736,7 @@ ProcessMonitor::ProcessMonitor(
using namespace std::placeholders;
std::unique_ptr<LaunchArgs> args(
- new LaunchArgs(this, module, argv, envp, stdin_file_spec,
+ new LaunchArgs(this, module, argv, std::move(env), stdin_file_spec,
stdout_file_spec, stderr_file_spec, working_dir));
sem_init(&m_operation_pending, 0, 0);
@@ -837,7 +837,6 @@ bool ProcessMonitor::Launch(LaunchArgs *args) {
ProcessMonitor *monitor = args->m_monitor;
ProcessFreeBSD &process = monitor->GetProcess();
const char **argv = args->m_argv;
- const char **envp = args->m_envp;
const FileSpec &stdin_file_spec = args->m_stdin_file_spec;
const FileSpec &stdout_file_spec = args->m_stdout_file_spec;
const FileSpec &stderr_file_spec = args->m_stderr_file_spec;
@@ -849,8 +848,8 @@ bool ProcessMonitor::Launch(LaunchArgs *args) {
::pid_t pid;
// Propagate the environment if one is not supplied.
- if (envp == NULL || envp[0] == NULL)
- envp = const_cast<const char **>(environ);
+ Environment::Envp envp =
+ (args->m_env.empty() ? Host::GetEnvironment() : args->m_env).getEnvp();
if ((pid = terminal.Fork(err_str, err_len)) == -1) {
args->m_error.SetErrorToGenericError();
@@ -875,9 +874,9 @@ bool ProcessMonitor::Launch(LaunchArgs *args) {
if (PTRACE(PT_TRACE_ME, 0, NULL, 0) < 0)
exit(ePtraceFailed);
- // terminal has already dupped the tty descriptors to stdin/out/err.
- // This closes original fd from which they were copied (and avoids
- // leaking descriptors to the debugged process.
+ // terminal has already dupped the tty descriptors to stdin/out/err. This
+ // closes original fd from which they were copied (and avoids leaking
+ // descriptors to the debugged process.
terminal.CloseSlaveFileDescriptor();
// Do not inherit setgid powers.
@@ -908,8 +907,7 @@ bool ProcessMonitor::Launch(LaunchArgs *args) {
exit(eChdirFailed);
// Execute. We should never return.
- execve(argv[0], const_cast<char *const *>(argv),
- const_cast<char *const *>(envp));
+ execve(argv[0], const_cast<char *const *>(argv), envp);
exit(eExecFailed);
}
@@ -1103,9 +1101,9 @@ ProcessMessage ProcessMonitor::MonitorSIGTRAP(ProcessMonitor *monitor,
break;
case (SIGTRAP /* | (PTRACE_EVENT_EXIT << 8) */): {
- // The inferior process is about to exit. Maintain the process in a
- // state of "limbo" until we are explicitly commanded to detach,
- // destroy, resume, etc.
+ // The inferior process is about to exit. Maintain the process in a state
+ // of "limbo" until we are explicitly commanded to detach, destroy, resume,
+ // etc.
unsigned long data = 0;
if (!monitor->GetEventMessage(tid, &data))
data = -1;
@@ -1160,8 +1158,8 @@ ProcessMessage ProcessMonitor::MonitorSignal(ProcessMonitor *monitor,
Log *log(ProcessPOSIXLog::GetLogIfAllCategoriesSet(POSIX_LOG_PROCESS));
// POSIX says that process behaviour is undefined after it ignores a SIGFPE,
- // SIGILL, SIGSEGV, or SIGBUS *unless* that signal was generated by a
- // kill(2) or raise(3). Similarly for tgkill(2) on FreeBSD.
+ // SIGILL, SIGSEGV, or SIGBUS *unless* that signal was generated by a kill(2)
+ // or raise(3). Similarly for tgkill(2) on FreeBSD.
//
// IOW, user generated signals never generate what we consider to be a
// "crash".
@@ -1197,8 +1195,8 @@ ProcessMessage ProcessMonitor::MonitorSignal(ProcessMonitor *monitor,
} // else; Use atleast si_signo info for other si_code
}
- // Everything else is "normal" and does not require any special action on
- // our part.
+ // Everything else is "normal" and does not require any special action on our
+ // part.
return ProcessMessage::Signal(tid, signo);
}
@@ -1424,14 +1422,14 @@ void ProcessMonitor::StopMonitor() {
}
// FIXME: On Linux, when a new thread is created, we receive to notifications,
-// (1) a SIGTRAP|PTRACE_EVENT_CLONE from the main process thread with the
-// child thread id as additional information, and (2) a SIGSTOP|SI_USER from
-// the new child thread indicating that it has is stopped because we attached.
-// We have no guarantee of the order in which these arrive, but we need both
-// before we are ready to proceed. We currently keep a list of threads which
-// have sent the initial SIGSTOP|SI_USER event. Then when we receive the
-// SIGTRAP|PTRACE_EVENT_CLONE notification, if the initial stop has not occurred
-// we call ProcessMonitor::WaitForInitialTIDStop() to wait for it.
+// (1) a SIGTRAP|PTRACE_EVENT_CLONE from the main process thread with the child
+// thread id as additional information, and (2) a SIGSTOP|SI_USER from the new
+// child thread indicating that it has is stopped because we attached. We have
+// no guarantee of the order in which these arrive, but we need both before we
+// are ready to proceed. We currently keep a list of threads which have sent
+// the initial SIGSTOP|SI_USER event. Then when we receive the
+// SIGTRAP|PTRACE_EVENT_CLONE notification, if the initial stop has not
+// occurred we call ProcessMonitor::WaitForInitialTIDStop() to wait for it.
//
// Right now, the above logic is in ProcessPOSIX, so we need a definition of
// this function in the FreeBSD ProcessMonitor implementation even if it isn't
diff --git a/source/Plugins/Process/FreeBSD/ProcessMonitor.h b/source/Plugins/Process/FreeBSD/ProcessMonitor.h
index 0963453a31b1e..1d3e2d746fa96 100644
--- a/source/Plugins/Process/FreeBSD/ProcessMonitor.h
+++ b/source/Plugins/Process/FreeBSD/ProcessMonitor.h
@@ -32,10 +32,10 @@ class ProcessFreeBSD;
class Operation;
/// @class ProcessMonitor
-/// @brief Manages communication with the inferior (debugee) process.
+/// Manages communication with the inferior (debugee) process.
///
-/// Upon construction, this class prepares and launches an inferior process for
-/// debugging.
+/// Upon construction, this class prepares and launches an inferior process
+/// for debugging.
///
/// Changes in the inferior process state are propagated to the associated
/// ProcessFreeBSD instance by calling ProcessFreeBSD::SendMessage with the
@@ -48,7 +48,7 @@ public:
/// Launches an inferior process ready for debugging. Forms the
/// implementation of Process::DoLaunch.
ProcessMonitor(ProcessFreeBSD *process, lldb_private::Module *module,
- char const *argv[], char const *envp[],
+ char const *argv[], lldb_private::Environment env,
const lldb_private::FileSpec &stdin_file_spec,
const lldb_private::FileSpec &stdout_file_spec,
const lldb_private::FileSpec &stderr_file_spec,
@@ -74,8 +74,7 @@ public:
/// standard error of this debugee. Even if stderr and stdout were
/// redirected on launch it may still happen that data is available on this
/// descriptor (if the inferior process opens /dev/tty, for example). This
- /// descriptor is
- /// closed after a call to StopMonitor().
+ /// descriptor is closed after a call to StopMonitor().
///
/// If this monitor was attached to an existing process this method returns
/// -1.
@@ -95,8 +94,8 @@ public:
size_t WriteMemory(lldb::addr_t vm_addr, const void *buf, size_t size,
lldb_private::Status &error);
- /// Reads the contents from the register identified by the given (architecture
- /// dependent) offset.
+ /// Reads the contents from the register identified by the given
+ /// (architecture dependent) offset.
///
/// This method is provided for use by RegisterContextFreeBSD derivatives.
bool ReadRegisterValue(lldb::tid_t tid, unsigned offset, const char *reg_name,
@@ -215,11 +214,11 @@ private:
/// @class LauchArgs
///
- /// @brief Simple structure to pass data to the thread responsible for
- /// launching a child process.
+ /// Simple structure to pass data to the thread responsible for launching a
+ /// child process.
struct LaunchArgs : OperationArgs {
LaunchArgs(ProcessMonitor *monitor, lldb_private::Module *module,
- char const **argv, char const **envp,
+ char const **argv, lldb_private::Environment env,
const lldb_private::FileSpec &stdin_file_spec,
const lldb_private::FileSpec &stdout_file_spec,
const lldb_private::FileSpec &stderr_file_spec,
@@ -229,7 +228,7 @@ private:
lldb_private::Module *m_module; // The executable image to launch.
char const **m_argv; // Process arguments.
- char const **m_envp; // Process environment.
+ lldb_private::Environment m_env; // Process environment.
const lldb_private::FileSpec m_stdin_file_spec; // Redirect stdin or empty.
const lldb_private::FileSpec
m_stdout_file_spec; // Redirect stdout or empty.
diff --git a/source/Plugins/Process/FreeBSD/RegisterContextPOSIX.h b/source/Plugins/Process/FreeBSD/RegisterContextPOSIX.h
index 4ff5121bac130..b1b44e71de460 100644
--- a/source/Plugins/Process/FreeBSD/RegisterContextPOSIX.h
+++ b/source/Plugins/Process/FreeBSD/RegisterContextPOSIX.h
@@ -13,14 +13,14 @@
// C Includes
// C++ Includes
// Other libraries and framework includes
-#include "RegisterInfoInterface.h"
+#include "Plugins/Process/Utility/RegisterInfoInterface.h"
#include "lldb/Target/RegisterContext.h"
#include "lldb/Utility/ArchSpec.h"
//------------------------------------------------------------------------------
/// @class POSIXBreakpointProtocol
///
-/// @brief Extends RegisterClass with a few virtual operations useful on POSIX.
+/// Extends RegisterClass with a few virtual operations useful on POSIX.
class POSIXBreakpointProtocol {
public:
POSIXBreakpointProtocol() { m_watchpoints_initialized = false; }
diff --git a/source/Plugins/Process/FreeBSD/RegisterContextPOSIXProcessMonitor_arm.cpp b/source/Plugins/Process/FreeBSD/RegisterContextPOSIXProcessMonitor_arm.cpp
index 59d42b9ad72e5..8ddc253aea5d6 100644
--- a/source/Plugins/Process/FreeBSD/RegisterContextPOSIXProcessMonitor_arm.cpp
+++ b/source/Plugins/Process/FreeBSD/RegisterContextPOSIXProcessMonitor_arm.cpp
@@ -14,7 +14,7 @@
#include "ProcessFreeBSD.h"
#include "ProcessMonitor.h"
#include "RegisterContextPOSIXProcessMonitor_arm.h"
-#include "RegisterContextPOSIX_arm.h"
+#include "Plugins/Process/Utility/RegisterContextPOSIX_arm.h"
using namespace lldb_private;
using namespace lldb;
diff --git a/source/Plugins/Process/FreeBSD/RegisterContextPOSIXProcessMonitor_mips64.cpp b/source/Plugins/Process/FreeBSD/RegisterContextPOSIXProcessMonitor_mips64.cpp
index b911ee2220155..734167e1fc98f 100644
--- a/source/Plugins/Process/FreeBSD/RegisterContextPOSIXProcessMonitor_mips64.cpp
+++ b/source/Plugins/Process/FreeBSD/RegisterContextPOSIXProcessMonitor_mips64.cpp
@@ -130,14 +130,14 @@ bool RegisterContextPOSIXProcessMonitor_mips64::ReadRegister(
bool success = ReadRegister(full_reg, value);
if (success) {
- // If our read was not aligned (for ah,bh,ch,dh), shift our returned value
- // one byte to the right.
+ // If our read was not aligned (for ah,bh,ch,dh), shift our returned
+ // value one byte to the right.
if (is_subreg && (reg_info->byte_offset & 0x1))
value.SetUInt64(value.GetAsUInt64() >> 8);
// If our return byte size was greater than the return value reg size,
- // then
- // use the type specified by reg_info rather than the uint64_t default
+ // then use the type specified by reg_info rather than the uint64_t
+ // default
if (value.GetByteSize() > reg_info->byte_size)
value.SetType(reg_info);
}
diff --git a/source/Plugins/Process/FreeBSD/RegisterContextPOSIXProcessMonitor_powerpc.cpp b/source/Plugins/Process/FreeBSD/RegisterContextPOSIXProcessMonitor_powerpc.cpp
index bc1d4df89fc8a..5cc6cd2906291 100644
--- a/source/Plugins/Process/FreeBSD/RegisterContextPOSIXProcessMonitor_powerpc.cpp
+++ b/source/Plugins/Process/FreeBSD/RegisterContextPOSIXProcessMonitor_powerpc.cpp
@@ -14,7 +14,7 @@
#include "ProcessFreeBSD.h"
#include "ProcessMonitor.h"
#include "RegisterContextPOSIXProcessMonitor_powerpc.h"
-#include "RegisterContextPOSIX_powerpc.h"
+#include "Plugins/Process/Utility/RegisterContextPOSIX_powerpc.h"
using namespace lldb_private;
using namespace lldb;
@@ -140,8 +140,8 @@ bool RegisterContextPOSIXProcessMonitor_powerpc::ReadRegister(
if (success) {
// If our return byte size was greater than the return value reg size,
- // then
- // use the type specified by reg_info rather than the uint64_t default
+ // then use the type specified by reg_info rather than the uint64_t
+ // default
if (value.GetByteSize() > reg_info->byte_size)
value.SetType(reg_info);
}
diff --git a/source/Plugins/Process/FreeBSD/RegisterContextPOSIXProcessMonitor_x86.cpp b/source/Plugins/Process/FreeBSD/RegisterContextPOSIXProcessMonitor_x86.cpp
index 4608520dba409..7db7f803b371a 100644
--- a/source/Plugins/Process/FreeBSD/RegisterContextPOSIXProcessMonitor_x86.cpp
+++ b/source/Plugins/Process/FreeBSD/RegisterContextPOSIXProcessMonitor_x86.cpp
@@ -193,14 +193,14 @@ bool RegisterContextPOSIXProcessMonitor_x86_64::ReadRegister(
bool success = ReadRegister(full_reg, value);
if (success) {
- // If our read was not aligned (for ah,bh,ch,dh), shift our returned value
- // one byte to the right.
+ // If our read was not aligned (for ah,bh,ch,dh), shift our returned
+ // value one byte to the right.
if (is_subreg && (reg_info->byte_offset & 0x1))
value.SetUInt64(value.GetAsUInt64() >> 8);
// If our return byte size was greater than the return value reg size,
- // then
- // use the type specified by reg_info rather than the uint64_t default
+ // then use the type specified by reg_info rather than the uint64_t
+ // default
if (value.GetByteSize() > reg_info->byte_size)
value.SetType(reg_info);
}
@@ -221,7 +221,8 @@ bool RegisterContextPOSIXProcessMonitor_x86_64::ReadRegister(
value.SetBytes(m_fpr.fxsave.xmm[reg - m_reg_info.first_xmm].bytes,
reg_info->byte_size, byte_order);
if (reg >= m_reg_info.first_ymm && reg <= m_reg_info.last_ymm) {
- // Concatenate ymm using the register halves in xmm.bytes and ymmh.bytes
+ // Concatenate ymm using the register halves in xmm.bytes and
+ // ymmh.bytes
if (GetFPRType() == eXSAVE && CopyXSTATEtoYMM(reg, byte_order))
value.SetBytes(m_ymm_set.ymm[reg - m_reg_info.first_ymm].bytes,
reg_info->byte_size, byte_order);
@@ -233,11 +234,10 @@ bool RegisterContextPOSIXProcessMonitor_x86_64::ReadRegister(
return false;
}
- // Get pointer to m_fpr.fxsave variable and set the data from it.
- // Byte offsets of all registers are calculated wrt 'UserArea' structure.
- // However, ReadFPR() reads fpu registers {using ptrace(PT_GETFPREGS,..)}
- // and stores them in 'm_fpr' (of type FPR structure). To extract values of
- // fpu
+ // Get pointer to m_fpr.fxsave variable and set the data from it. Byte
+ // offsets of all registers are calculated wrt 'UserArea' structure. However,
+ // ReadFPR() reads fpu registers {using ptrace(PT_GETFPREGS,..)} and stores
+ // them in 'm_fpr' (of type FPR structure). To extract values of fpu
// registers, m_fpr should be read at byte offsets calculated wrt to FPR
// structure.
@@ -299,12 +299,12 @@ bool RegisterContextPOSIXProcessMonitor_x86_64::WriteRegister(
return false;
}
} else {
- // Get pointer to m_fpr.fxsave variable and set the data to it.
- // Byte offsets of all registers are calculated wrt 'UserArea' structure.
- // However, WriteFPR() takes m_fpr (of type FPR structure) and writes only
- // fpu
- // registers using ptrace(PT_SETFPREGS,..) API. Hence fpu registers should
- // be written in m_fpr at byte offsets calculated wrt FPR structure.
+ // Get pointer to m_fpr.fxsave variable and set the data to it. Byte
+ // offsets of all registers are calculated wrt 'UserArea' structure.
+ // However, WriteFPR() takes m_fpr (of type FPR structure) and writes
+ // only fpu registers using ptrace(PT_SETFPREGS,..) API. Hence fpu
+ // registers should be written in m_fpr at byte offsets calculated wrt
+ // FPR structure.
// Since, FPR structure is also one of the member of UserArea structure.
// byte_offset(fpu wrt FPR) = byte_offset(fpu wrt UserArea) -
diff --git a/source/Plugins/Process/Linux/CMakeLists.txt b/source/Plugins/Process/Linux/CMakeLists.txt
index 390dbd9ff8bf6..b4b4c401a271f 100644
--- a/source/Plugins/Process/Linux/CMakeLists.txt
+++ b/source/Plugins/Process/Linux/CMakeLists.txt
@@ -1,7 +1,3 @@
-include_directories(.)
-include_directories(../POSIX)
-include_directories(../Utility)
-
add_lldb_library(lldbPluginProcessLinux PLUGIN
NativeProcessLinux.cpp
NativeRegisterContextLinux.cpp
diff --git a/source/Plugins/Process/Linux/NativeProcessLinux.cpp b/source/Plugins/Process/Linux/NativeProcessLinux.cpp
index 136af361af296..3fb886e1c7a3a 100644
--- a/source/Plugins/Process/Linux/NativeProcessLinux.cpp
+++ b/source/Plugins/Process/Linux/NativeProcessLinux.cpp
@@ -245,13 +245,15 @@ NativeProcessLinux::Factory::Launch(ProcessLaunchInfo &launch_info,
}
LLDB_LOG(log, "inferior started, now in stopped state");
- ArchSpec arch;
- if ((status = ResolveProcessArchitecture(pid, arch)).Fail())
- return status.ToError();
+ ProcessInstanceInfo Info;
+ if (!Host::GetProcessInfo(pid, Info)) {
+ return llvm::make_error<StringError>("Cannot get process architecture",
+ llvm::inconvertibleErrorCode());
+ }
// Set the architecture to the exe architecture.
LLDB_LOG(log, "pid = {0:x}, detected architecture {1}", pid,
- arch.GetArchitectureName());
+ Info.GetArchitecture().GetArchitectureName());
status = SetDefaultPtraceOpts(pid);
if (status.Fail()) {
@@ -261,7 +263,7 @@ NativeProcessLinux::Factory::Launch(ProcessLaunchInfo &launch_info,
return std::unique_ptr<NativeProcessLinux>(new NativeProcessLinux(
pid, launch_info.GetPTY().ReleaseMasterFileDescriptor(), native_delegate,
- arch, mainloop, {pid}));
+ Info.GetArchitecture(), mainloop, {pid}));
}
llvm::Expected<std::unique_ptr<NativeProcessProtocol>>
@@ -272,17 +274,18 @@ NativeProcessLinux::Factory::Attach(
LLDB_LOG(log, "pid = {0:x}", pid);
// Retrieve the architecture for the running process.
- ArchSpec arch;
- Status status = ResolveProcessArchitecture(pid, arch);
- if (!status.Success())
- return status.ToError();
+ ProcessInstanceInfo Info;
+ if (!Host::GetProcessInfo(pid, Info)) {
+ return llvm::make_error<StringError>("Cannot get process architecture",
+ llvm::inconvertibleErrorCode());
+ }
auto tids_or = NativeProcessLinux::Attach(pid);
if (!tids_or)
return tids_or.takeError();
return std::unique_ptr<NativeProcessLinux>(new NativeProcessLinux(
- pid, -1, native_delegate, arch, mainloop, *tids_or));
+ pid, -1, native_delegate, Info.GetArchitecture(), mainloop, *tids_or));
}
// -----------------------------------------------------------------------------
@@ -334,8 +337,8 @@ llvm::Expected<std::vector<::pid_t>> NativeProcessLinux::Attach(::pid_t pid) {
// Attach to the requested process.
// An attach will cause the thread to stop with a SIGSTOP.
if ((status = PtraceWrapper(PTRACE_ATTACH, tid)).Fail()) {
- // No such thread. The thread may have exited.
- // More error handling may be needed.
+ // No such thread. The thread may have exited. More error handling
+ // may be needed.
if (status.GetError() == ESRCH) {
it = tids_to_attach.erase(it);
continue;
@@ -345,11 +348,11 @@ llvm::Expected<std::vector<::pid_t>> NativeProcessLinux::Attach(::pid_t pid) {
int wpid =
llvm::sys::RetryAfterSignal(-1, ::waitpid, tid, nullptr, __WALL);
- // Need to use __WALL otherwise we receive an error with errno=ECHLD
- // At this point we should have a thread stopped if waitpid succeeds.
+ // Need to use __WALL otherwise we receive an error with errno=ECHLD At
+ // this point we should have a thread stopped if waitpid succeeds.
if (wpid < 0) {
- // No such thread. The thread may have exited.
- // More error handling may be needed.
+ // No such thread. The thread may have exited. More error handling
+ // may be needed.
if (errno == ESRCH) {
it = tids_to_attach.erase(it);
continue;
@@ -394,8 +397,8 @@ Status NativeProcessLinux::SetDefaultPtraceOpts(lldb::pid_t pid) {
// appropriate ptrace flags here (PTRACE_O_TRACEFORK, PTRACE_O_TRACEVFORK)
ptrace_opts |= PTRACE_O_TRACECLONE;
- // Have the tracer notify us before execve returns
- // (needed to disable legacy SIGTRAP generation)
+ // Have the tracer notify us before execve returns (needed to disable legacy
+ // SIGTRAP generation)
ptrace_opts |= PTRACE_O_TRACEEXEC;
return PtraceWrapper(PTRACE_SETOPTIONS, pid, nullptr, (void *)ptrace_opts);
@@ -435,8 +438,8 @@ void NativeProcessLinux::MonitorCallback(lldb::pid_t pid, bool exited,
auto thread_sp = GetThreadByID(pid);
if (!thread_sp) {
- // Normally, the only situation when we cannot find the thread is if we have
- // just received a new thread notification. This is indicated by
+ // Normally, the only situation when we cannot find the thread is if we
+ // have just received a new thread notification. This is indicated by
// GetSignalInfo() returning si_code == SI_USER and si_pid == 0
LLDB_LOG(log, "received notification about an unknown tid {0}.", pid);
@@ -468,15 +471,15 @@ void NativeProcessLinux::MonitorCallback(lldb::pid_t pid, bool exited,
MonitorSignal(info, *thread_sp, exited);
} else {
if (info_err.GetError() == EINVAL) {
- // This is a group stop reception for this tid.
- // We can reach here if we reinject SIGSTOP, SIGSTP, SIGTTIN or SIGTTOU
- // into the tracee, triggering the group-stop mechanism. Normally
- // receiving these would stop the process, pending a SIGCONT. Simulating
- // this state in a debugger is hard and is generally not needed (one use
- // case is debugging background task being managed by a shell). For
- // general use, it is sufficient to stop the process in a signal-delivery
- // stop which happens before the group stop. This done by MonitorSignal
- // and works correctly for all signals.
+ // This is a group stop reception for this tid. We can reach here if we
+ // reinject SIGSTOP, SIGSTP, SIGTTIN or SIGTTOU into the tracee,
+ // triggering the group-stop mechanism. Normally receiving these would
+ // stop the process, pending a SIGCONT. Simulating this state in a
+ // debugger is hard and is generally not needed (one use case is
+ // debugging background task being managed by a shell). For general use,
+ // it is sufficient to stop the process in a signal-delivery stop which
+ // happens before the group stop. This done by MonitorSignal and works
+ // correctly for all signals.
LLDB_LOG(log,
"received a group stop for pid {0} tid {1}. Transparent "
"handling of group stops not supported, resuming the "
@@ -502,8 +505,8 @@ void NativeProcessLinux::MonitorCallback(lldb::pid_t pid, bool exited,
if (is_main_thread) {
// Notify the delegate - our process is not available but appears to
- // have been killed outside
- // our control. Is eStateExited the right exit state in this case?
+ // have been killed outside our control. Is eStateExited the right
+ // exit state in this case?
SetExitStatus(status, true);
SetState(StateType::eStateExited, true);
} else {
@@ -572,19 +575,14 @@ void NativeProcessLinux::MonitorSIGTRAP(const siginfo_t &info,
switch (info.si_code) {
// TODO: these two cases are required if we want to support tracing of the
- // inferiors' children. We'd need this to debug a monitor.
- // case (SIGTRAP | (PTRACE_EVENT_FORK << 8)):
- // case (SIGTRAP | (PTRACE_EVENT_VFORK << 8)):
+ // inferiors' children. We'd need this to debug a monitor. case (SIGTRAP |
+ // (PTRACE_EVENT_FORK << 8)): case (SIGTRAP | (PTRACE_EVENT_VFORK << 8)):
case (SIGTRAP | (PTRACE_EVENT_CLONE << 8)): {
// This is the notification on the parent thread which informs us of new
- // thread
- // creation.
- // We don't want to do anything with the parent thread so we just resume it.
- // In case we
- // want to implement "break on thread creation" functionality, we would need
- // to stop
- // here.
+ // thread creation. We don't want to do anything with the parent thread so
+ // we just resume it. In case we want to implement "break on thread
+ // creation" functionality, we would need to stop here.
unsigned long event_message = 0;
if (GetEventMessage(thread.GetID(), &event_message).Fail()) {
@@ -634,10 +632,10 @@ void NativeProcessLinux::MonitorSIGTRAP(const siginfo_t &info,
}
case (SIGTRAP | (PTRACE_EVENT_EXIT << 8)): {
- // The inferior process or one of its threads is about to exit.
- // We don't want to do anything with the thread so we just resume it. In
- // case we want to implement "break on thread exit" functionality, we would
- // need to stop here.
+ // The inferior process or one of its threads is about to exit. We don't
+ // want to do anything with the thread so we just resume it. In case we
+ // want to implement "break on thread exit" functionality, we would need to
+ // stop here.
unsigned long data = 0;
if (GetEventMessage(thread.GetID(), &data).Fail())
@@ -655,8 +653,8 @@ void NativeProcessLinux::MonitorSIGTRAP(const siginfo_t &info,
// Due to a kernel bug, we may sometimes get this stop after the inferior
// gets a SIGKILL. This confuses our state tracking logic in
// ResumeThread(), since normally, we should not be receiving any ptrace
- // events while the inferior is stopped. This makes sure that the inferior
- // is resumed and exits normally.
+ // events while the inferior is stopped. This makes sure that the
+ // inferior is resumed and exits normally.
state = eStateRunning;
}
ResumeThread(thread, state, LLDB_INVALID_SIGNAL_NUMBER);
@@ -702,8 +700,8 @@ void NativeProcessLinux::MonitorSIGTRAP(const siginfo_t &info,
case SI_KERNEL:
#if defined __mips__
- // For mips there is no special signal for watchpoint
- // So we check for watchpoint in kernel trap
+ // For mips there is no special signal for watchpoint So we check for
+ // watchpoint in kernel trap
{
// If a watchpoint was hit, report it
uint32_t wp_index;
@@ -779,8 +777,8 @@ void NativeProcessLinux::MonitorWatchpoint(NativeThreadLinux &thread,
LLDB_LOG(log, "received watchpoint event, pid = {0}, wp_index = {1}",
thread.GetID(), wp_index);
- // Mark the thread as stopped at watchpoint.
- // The address is at (lldb::addr_t)info->si_addr if we need it.
+ // Mark the thread as stopped at watchpoint. The address is at
+ // (lldb::addr_t)info->si_addr if we need it.
thread.SetStoppedByWatchpoint(wp_index);
// We need to tell all other running threads before we notify the delegate
@@ -796,8 +794,8 @@ void NativeProcessLinux::MonitorSignal(const siginfo_t &info,
Log *log(ProcessPOSIXLog::GetLogIfAllCategoriesSet(POSIX_LOG_PROCESS));
// POSIX says that process behaviour is undefined after it ignores a SIGFPE,
- // SIGILL, SIGSEGV, or SIGBUS *unless* that signal was generated by a
- // kill(2) or raise(3). Similarly for tgkill(2) on Linux.
+ // SIGILL, SIGSEGV, or SIGBUS *unless* that signal was generated by a kill(2)
+ // or raise(3). Similarly for tgkill(2) on Linux.
//
// IOW, user generated signals never generate what we consider to be a
// "crash".
@@ -816,22 +814,22 @@ void NativeProcessLinux::MonitorSignal(const siginfo_t &info,
// This is a tgkill()-based stop.
LLDB_LOG(log, "pid {0} tid {1}, thread stopped", GetID(), thread.GetID());
- // Check that we're not already marked with a stop reason.
- // Note this thread really shouldn't already be marked as stopped - if we
- // were, that would imply that the kernel signaled us with the thread
- // stopping which we handled and marked as stopped, and that, without an
- // intervening resume, we received another stop. It is more likely that we
- // are missing the marking of a run state somewhere if we find that the
- // thread was marked as stopped.
+ // Check that we're not already marked with a stop reason. Note this thread
+ // really shouldn't already be marked as stopped - if we were, that would
+ // imply that the kernel signaled us with the thread stopping which we
+ // handled and marked as stopped, and that, without an intervening resume,
+ // we received another stop. It is more likely that we are missing the
+ // marking of a run state somewhere if we find that the thread was marked
+ // as stopped.
const StateType thread_state = thread.GetState();
if (!StateIsStoppedState(thread_state, false)) {
// An inferior thread has stopped because of a SIGSTOP we have sent it.
// Generally, these are not important stops and we don't want to report
// them as they are just used to stop other threads when one thread (the
// one with the *real* stop reason) hits a breakpoint (watchpoint,
- // etc...). However, in the case of an asynchronous Interrupt(), this *is*
- // the real stop reason, so we leave the signal intact if this is the
- // thread that was chosen as the triggering thread.
+ // etc...). However, in the case of an asynchronous Interrupt(), this
+ // *is* the real stop reason, so we leave the signal intact if this is
+ // the thread that was chosen as the triggering thread.
if (m_pending_notification_tid != LLDB_INVALID_THREAD_ID) {
if (m_pending_notification_tid == thread.GetID())
thread.SetStoppedBySignal(SIGSTOP, &info);
@@ -860,8 +858,8 @@ void NativeProcessLinux::MonitorSignal(const siginfo_t &info,
return;
}
- // Check if debugger should stop at this signal or just ignore it
- // and resume the inferior.
+ // Check if debugger should stop at this signal or just ignore it and resume
+ // the inferior.
if (m_signals_to_ignore.find(signo) != m_signals_to_ignore.end()) {
ResumeThread(thread, thread.GetState(), signo);
return;
@@ -912,9 +910,9 @@ static bool ReadRegisterCallback(EmulateInstruction *instruction, void *baton,
return true;
}
- // The emulator only fill in the dwarf regsiter numbers (and in some case
- // the generic register numbers). Get the full register info from the
- // register context based on the dwarf register numbers.
+ // The emulator only fill in the dwarf regsiter numbers (and in some case the
+ // generic register numbers). Get the full register info from the register
+ // context based on the dwarf register numbers.
const RegisterInfo *full_reg_info =
emulator_baton->m_reg_context.GetRegisterInfo(
eRegisterKindDWARF, reg_info->kinds[eRegisterKindDWARF]);
@@ -998,8 +996,8 @@ NativeProcessLinux::SetupSoftwareSingleStepping(NativeThreadLinux &thread) {
else
next_flags = ReadFlags(register_context);
} else if (pc_it == baton.m_register_values.end()) {
- // Emulate instruction failed and it haven't changed PC. Advance PC
- // with the size of the current opcode because the emulation of all
+ // Emulate instruction failed and it haven't changed PC. Advance PC with
+ // the size of the current opcode because the emulation of all
// PC modifying instruction should be successful. The failure most
// likely caused by a not supported instruction which don't modify PC.
next_pc = register_context.GetPC() + emulator_ap->GetOpcode().GetByteSize();
@@ -1030,8 +1028,8 @@ NativeProcessLinux::SetupSoftwareSingleStepping(NativeThreadLinux &thread) {
error = SetSoftwareBreakpoint(next_pc, 0);
}
- // If setting the breakpoint fails because next_pc is out of
- // the address space, ignore it and let the debugee segfault.
+ // If setting the breakpoint fails because next_pc is out of the address
+ // space, ignore it and let the debugee segfault.
if (error.GetError() == EIO || error.GetError() == EFAULT) {
return Status();
} else if (error.Fail())
@@ -1162,8 +1160,8 @@ Status NativeProcessLinux::Signal(int signo) {
}
Status NativeProcessLinux::Interrupt() {
- // Pick a running thread (or if none, a not-dead stopped thread) as
- // the chosen thread that will be the stop-reason thread.
+ // Pick a running thread (or if none, a not-dead stopped thread) as the
+ // chosen thread that will be the stop-reason thread.
Log *log(ProcessPOSIXLog::GetLogIfAllCategoriesSet(POSIX_LOG_PROCESS));
NativeThreadProtocol *running_thread = nullptr;
@@ -1171,15 +1169,15 @@ Status NativeProcessLinux::Interrupt() {
LLDB_LOG(log, "selecting running thread for interrupt target");
for (const auto &thread : m_threads) {
- // If we have a running or stepping thread, we'll call that the
- // target of the interrupt.
+ // If we have a running or stepping thread, we'll call that the target of
+ // the interrupt.
const auto thread_state = thread->GetState();
if (thread_state == eStateRunning || thread_state == eStateStepping) {
running_thread = thread.get();
break;
} else if (!stopped_thread && StateIsStoppedState(thread_state, true)) {
- // Remember the first non-dead stopped thread. We'll use that as a backup
- // if there are no running threads.
+ // Remember the first non-dead stopped thread. We'll use that as a
+ // backup if there are no running threads.
stopped_thread = thread.get();
}
}
@@ -1248,9 +1246,8 @@ ParseMemoryRegionInfoFromProcMapsLine(llvm::StringRef &maps_line,
StringExtractor line_extractor(maps_line);
// Format: {address_start_hex}-{address_end_hex} perms offset dev inode
- // pathname
- // perms: rwxp (letter is present if set, '-' if not, final character is
- // p=private, s=shared).
+ // pathname perms: rwxp (letter is present if set, '-' if not, final
+ // character is p=private, s=shared).
// Parse out the starting address
lldb::addr_t start_address = line_extractor.GetHexMaxU64(false, 0);
@@ -1331,8 +1328,8 @@ Status NativeProcessLinux::GetMemoryRegionInfo(lldb::addr_t load_addr,
// the virtual address space,
// with no perms if it is not mapped.
- // Use an approach that reads memory regions from /proc/{pid}/maps.
- // Assume proc maps entries are in ascending order.
+ // Use an approach that reads memory regions from /proc/{pid}/maps. Assume
+ // proc maps entries are in ascending order.
// FIXME assert if we find differently.
if (m_supports_mem_region == LazyBool::eLazyBoolNo) {
@@ -1383,10 +1380,8 @@ Status NativeProcessLinux::GetMemoryRegionInfo(lldb::addr_t load_addr,
}
// If we made it here, we didn't find an entry that contained the given
- // address. Return the
- // load_addr as start and the amount of bytes betwwen load address and the end
- // of the memory as
- // size.
+ // address. Return the load_addr as start and the amount of bytes betwwen
+ // load address and the end of the memory as size.
range_info.GetRange().SetRangeBase(load_addr);
range_info.GetRange().SetRangeEnd(LLDB_INVALID_ADDRESS);
range_info.SetReadable(MemoryRegionInfo::OptionalBool::eNo);
@@ -1431,8 +1426,8 @@ Status NativeProcessLinux::PopulateMemoryRegionCache() {
if (m_mem_region_cache.empty()) {
// No entries after attempting to read them. This shouldn't happen if
- // /proc/{pid}/maps is supported. Assume we don't support map entries
- // via procfs.
+ // /proc/{pid}/maps is supported. Assume we don't support map entries via
+ // procfs.
m_supports_mem_region = LazyBool::eLazyBoolNo;
LLDB_LOG(log,
"failed to find any procfs maps entries, assuming no support "
@@ -1459,8 +1454,8 @@ void NativeProcessLinux::DoStopIDBumped(uint32_t newBumpId) {
Status NativeProcessLinux::AllocateMemory(size_t size, uint32_t permissions,
lldb::addr_t &addr) {
// FIXME implementing this requires the equivalent of
-// InferiorCallPOSIX::InferiorCallMmap, which depends on
-// functional ThreadPlans working with Native*Protocol.
+// InferiorCallPOSIX::InferiorCallMmap, which depends on functional ThreadPlans
+// working with Native*Protocol.
#if 1
return Status("not implemented yet");
#else
@@ -1475,8 +1470,7 @@ Status NativeProcessLinux::AllocateMemory(size_t size, uint32_t permissions,
prot |= eMmapProtExec;
// TODO implement this directly in NativeProcessLinux
- // (and lift to NativeProcessPOSIX if/when that class is
- // refactored out).
+ // (and lift to NativeProcessPOSIX if/when that class is refactored out).
if (InferiorCallMmap(this, addr, 0, size, prot,
eMmapFlagsAnon | eMmapFlagsPrivate, -1, 0)) {
m_addr_to_mmap_size[addr] = size;
@@ -1502,10 +1496,9 @@ lldb::addr_t NativeProcessLinux::GetSharedLibraryInfoAddress() {
}
size_t NativeProcessLinux::UpdateThreads() {
- // The NativeProcessLinux monitoring threads are always up to date
- // with respect to thread state and they keep the thread list
- // populated properly. All this method needs to do is return the
- // thread count.
+ // The NativeProcessLinux monitoring threads are always up to date with
+ // respect to thread state and they keep the thread list populated properly.
+ // All this method needs to do is return the thread count.
return m_threads.size();
}
@@ -1515,7 +1508,6 @@ Status NativeProcessLinux::GetSoftwareBreakpointPCOffset(
// set per architecture. Need ARM, MIPS support here.
static const uint8_t g_i386_opcode[] = {0xCC};
static const uint8_t g_s390x_opcode[] = {0x00, 0x01};
- static const uint8_t g_ppc64le_opcode[] = {0x08, 0x00, 0xe0, 0x7f}; // trap
switch (m_arch.GetMachine()) {
case llvm::Triple::x86:
@@ -1527,16 +1519,13 @@ Status NativeProcessLinux::GetSoftwareBreakpointPCOffset(
actual_opcode_size = static_cast<uint32_t>(sizeof(g_s390x_opcode));
return Status();
- case llvm::Triple::ppc64le:
- actual_opcode_size = static_cast<uint32_t>(sizeof(g_ppc64le_opcode));
- return Status();
-
case llvm::Triple::arm:
case llvm::Triple::aarch64:
case llvm::Triple::mips64:
case llvm::Triple::mips64el:
case llvm::Triple::mips:
case llvm::Triple::mipsel:
+ case llvm::Triple::ppc64le:
// On these architectures the PC don't get updated for breakpoint hits
actual_opcode_size = 0;
return Status();
@@ -1633,161 +1622,11 @@ Status NativeProcessLinux::GetSoftwareBreakpointTrapOpcode(
}
}
-#if 0
-ProcessMessage::CrashReason
-NativeProcessLinux::GetCrashReasonForSIGSEGV(const siginfo_t *info)
-{
- ProcessMessage::CrashReason reason;
- assert(info->si_signo == SIGSEGV);
-
- reason = ProcessMessage::eInvalidCrashReason;
-
- switch (info->si_code)
- {
- default:
- assert(false && "unexpected si_code for SIGSEGV");
- break;
- case SI_KERNEL:
- // Linux will occasionally send spurious SI_KERNEL codes.
- // (this is poorly documented in sigaction)
- // One way to get this is via unaligned SIMD loads.
- reason = ProcessMessage::eInvalidAddress; // for lack of anything better
- break;
- case SEGV_MAPERR:
- reason = ProcessMessage::eInvalidAddress;
- break;
- case SEGV_ACCERR:
- reason = ProcessMessage::ePrivilegedAddress;
- break;
- }
-
- return reason;
-}
-#endif
-
-#if 0
-ProcessMessage::CrashReason
-NativeProcessLinux::GetCrashReasonForSIGILL(const siginfo_t *info)
-{
- ProcessMessage::CrashReason reason;
- assert(info->si_signo == SIGILL);
-
- reason = ProcessMessage::eInvalidCrashReason;
-
- switch (info->si_code)
- {
- default:
- assert(false && "unexpected si_code for SIGILL");
- break;
- case ILL_ILLOPC:
- reason = ProcessMessage::eIllegalOpcode;
- break;
- case ILL_ILLOPN:
- reason = ProcessMessage::eIllegalOperand;
- break;
- case ILL_ILLADR:
- reason = ProcessMessage::eIllegalAddressingMode;
- break;
- case ILL_ILLTRP:
- reason = ProcessMessage::eIllegalTrap;
- break;
- case ILL_PRVOPC:
- reason = ProcessMessage::ePrivilegedOpcode;
- break;
- case ILL_PRVREG:
- reason = ProcessMessage::ePrivilegedRegister;
- break;
- case ILL_COPROC:
- reason = ProcessMessage::eCoprocessorError;
- break;
- case ILL_BADSTK:
- reason = ProcessMessage::eInternalStackError;
- break;
- }
-
- return reason;
-}
-#endif
-
-#if 0
-ProcessMessage::CrashReason
-NativeProcessLinux::GetCrashReasonForSIGFPE(const siginfo_t *info)
-{
- ProcessMessage::CrashReason reason;
- assert(info->si_signo == SIGFPE);
-
- reason = ProcessMessage::eInvalidCrashReason;
-
- switch (info->si_code)
- {
- default:
- assert(false && "unexpected si_code for SIGFPE");
- break;
- case FPE_INTDIV:
- reason = ProcessMessage::eIntegerDivideByZero;
- break;
- case FPE_INTOVF:
- reason = ProcessMessage::eIntegerOverflow;
- break;
- case FPE_FLTDIV:
- reason = ProcessMessage::eFloatDivideByZero;
- break;
- case FPE_FLTOVF:
- reason = ProcessMessage::eFloatOverflow;
- break;
- case FPE_FLTUND:
- reason = ProcessMessage::eFloatUnderflow;
- break;
- case FPE_FLTRES:
- reason = ProcessMessage::eFloatInexactResult;
- break;
- case FPE_FLTINV:
- reason = ProcessMessage::eFloatInvalidOperation;
- break;
- case FPE_FLTSUB:
- reason = ProcessMessage::eFloatSubscriptRange;
- break;
- }
-
- return reason;
-}
-#endif
-
-#if 0
-ProcessMessage::CrashReason
-NativeProcessLinux::GetCrashReasonForSIGBUS(const siginfo_t *info)
-{
- ProcessMessage::CrashReason reason;
- assert(info->si_signo == SIGBUS);
-
- reason = ProcessMessage::eInvalidCrashReason;
-
- switch (info->si_code)
- {
- default:
- assert(false && "unexpected si_code for SIGBUS");
- break;
- case BUS_ADRALN:
- reason = ProcessMessage::eIllegalAlignment;
- break;
- case BUS_ADRERR:
- reason = ProcessMessage::eIllegalAddress;
- break;
- case BUS_OBJERR:
- reason = ProcessMessage::eHardwareError;
- break;
- }
-
- return reason;
-}
-#endif
-
Status NativeProcessLinux::ReadMemory(lldb::addr_t addr, void *buf, size_t size,
size_t &bytes_read) {
if (ProcessVmReadvSupported()) {
// The process_vm_readv path is about 50 times faster than ptrace api. We
- // want to use
- // this syscall if it is supported.
+ // want to use this syscall if it is supported.
const ::pid_t pid = GetID();
@@ -2094,12 +1933,11 @@ Status NativeProcessLinux::ResumeThread(NativeThreadLinux &thread,
Log *const log = ProcessPOSIXLog::GetLogIfAllCategoriesSet(POSIX_LOG_THREAD);
LLDB_LOG(log, "tid: {0}", thread.GetID());
- // Before we do the resume below, first check if we have a pending
- // stop notification that is currently waiting for
- // all threads to stop. This is potentially a buggy situation since
- // we're ostensibly waiting for threads to stop before we send out the
- // pending notification, and here we are resuming one before we send
- // out the pending stop notification.
+ // Before we do the resume below, first check if we have a pending stop
+ // notification that is currently waiting for all threads to stop. This is
+ // potentially a buggy situation since we're ostensibly waiting for threads
+ // to stop before we send out the pending notification, and here we are
+ // resuming one before we send out the pending stop notification.
if (m_pending_notification_tid != LLDB_INVALID_THREAD_ID) {
LLDB_LOG(log,
"about to resume tid {0} per explicit request but we have a "
@@ -2108,8 +1946,8 @@ Status NativeProcessLinux::ResumeThread(NativeThreadLinux &thread,
thread.GetID(), m_pending_notification_tid);
}
- // Request a resume. We expect this to be synchronous and the system
- // to reflect it is running after this completes.
+ // Request a resume. We expect this to be synchronous and the system to
+ // reflect it is running after this completes.
switch (state) {
case eStateRunning: {
const auto resume_result = thread.Resume(signo);
@@ -2138,8 +1976,8 @@ void NativeProcessLinux::StopRunningThreads(const lldb::tid_t triggering_tid) {
m_pending_notification_tid = triggering_tid;
- // Request a stop for all the thread stops that need to be stopped
- // and are not already known to be stopped.
+ // Request a stop for all the thread stops that need to be stopped and are
+ // not already known to be stopped.
for (const auto &thread : m_threads) {
if (StateIsRunningState(thread->GetState()))
static_cast<NativeThreadLinux *>(thread.get())->RequestStop();
@@ -2185,8 +2023,7 @@ void NativeProcessLinux::ThreadWasCreated(NativeThreadLinux &thread) {
if (m_pending_notification_tid != LLDB_INVALID_THREAD_ID &&
StateIsRunningState(thread.GetState())) {
// We will need to wait for this new thread to stop as well before firing
- // the
- // notification.
+ // the notification.
thread.RequestStop();
}
}
@@ -2222,9 +2059,8 @@ void NativeProcessLinux::SigchldHandler() {
}
}
-// Wrapper for ptrace to catch errors and log calls.
-// Note that ptrace sets errno on error because -1 can be a valid result (i.e.
-// for PTRACE_PEEK*)
+// Wrapper for ptrace to catch errors and log calls. Note that ptrace sets
+// errno on error because -1 can be a valid result (i.e. for PTRACE_PEEK*)
Status NativeProcessLinux::PtraceWrapper(int req, lldb::pid_t pid, void *addr,
void *data, size_t data_size,
long *result) {
@@ -2422,8 +2258,8 @@ Status NativeProcessLinux::StopTracingForThread(lldb::tid_t thread) {
}
if (iter->second->GetTraceID() == m_pt_proces_trace_id) {
- // traceid maps to the whole process so we have to erase it from the
- // thread group.
+ // traceid maps to the whole process so we have to erase it from the thread
+ // group.
LLDB_LOG(log, "traceid maps to process");
m_pt_traced_thread_group.erase(thread);
}
@@ -2474,8 +2310,8 @@ Status NativeProcessLinux::StopProcessorTracingOnThread(lldb::user_id_t traceid,
if (thread == LLDB_INVALID_THREAD_ID) {
for (auto& iter : m_processor_trace_monitor) {
if (iter.second->GetTraceID() == traceid) {
- // Stopping a trace instance for an individual thread
- // hence there will only be one traceid that can match.
+ // Stopping a trace instance for an individual thread hence there will
+ // only be one traceid that can match.
m_processor_trace_monitor.erase(iter.first);
return error;
}
@@ -2505,8 +2341,8 @@ Status NativeProcessLinux::StopProcessorTracingOnThread(lldb::user_id_t traceid,
LLDB_LOG(log, "UID - {0} , Thread -{1}", traceid, thread);
if (traceid == m_pt_proces_trace_id) {
- // traceid maps to the whole process so we have to erase it from the
- // thread group.
+ // traceid maps to the whole process so we have to erase it from the thread
+ // group.
LLDB_LOG(log, "traceid maps to process");
m_pt_traced_thread_group.erase(thread);
}
diff --git a/source/Plugins/Process/Linux/NativeProcessLinux.h b/source/Plugins/Process/Linux/NativeProcessLinux.h
index f078c1ac30e2a..1c2f786e8d697 100644
--- a/source/Plugins/Process/Linux/NativeProcessLinux.h
+++ b/source/Plugins/Process/Linux/NativeProcessLinux.h
@@ -31,10 +31,10 @@ class Scalar;
namespace process_linux {
/// @class NativeProcessLinux
-/// @brief Manages communication with the inferior (debugee) process.
+/// Manages communication with the inferior (debugee) process.
///
-/// Upon construction, this class prepares and launches an inferior process for
-/// debugging.
+/// Upon construction, this class prepares and launches an inferior process
+/// for debugging.
///
/// Changes in the inferior process state are broadcasted.
class NativeProcessLinux : public NativeProcessProtocol {
@@ -184,20 +184,6 @@ private:
Status SetupSoftwareSingleStepping(NativeThreadLinux &thread);
-#if 0
- static ::ProcessMessage::CrashReason
- GetCrashReasonForSIGSEGV(const siginfo_t *info);
-
- static ::ProcessMessage::CrashReason
- GetCrashReasonForSIGILL(const siginfo_t *info);
-
- static ::ProcessMessage::CrashReason
- GetCrashReasonForSIGFPE(const siginfo_t *info);
-
- static ::ProcessMessage::CrashReason
- GetCrashReasonForSIGBUS(const siginfo_t *info);
-#endif
-
bool HasThreadNoLock(lldb::tid_t thread_id);
bool StopTrackingThread(lldb::tid_t thread_id);
diff --git a/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm.cpp b/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm.cpp
index cb05416cb6c33..7492916846209 100644
--- a/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm.cpp
+++ b/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm.cpp
@@ -184,14 +184,14 @@ NativeRegisterContextLinux_arm::ReadRegister(const RegisterInfo *reg_info,
error = ReadRegisterRaw(full_reg, reg_value);
if (error.Success()) {
- // If our read was not aligned (for ah,bh,ch,dh), shift our returned value
- // one byte to the right.
+ // If our read was not aligned (for ah,bh,ch,dh), shift our returned
+ // value one byte to the right.
if (is_subreg && (reg_info->byte_offset & 0x1))
reg_value.SetUInt64(reg_value.GetAsUInt64() >> 8);
// If our return byte size was greater than the return value reg size,
- // then
- // use the type specified by reg_info rather than the uint64_t default
+ // then use the type specified by reg_info rather than the uint64_t
+ // default
if (reg_value.GetByteSize() > reg_info->byte_size)
reg_value.SetType(reg_info);
}
@@ -558,8 +558,8 @@ uint32_t NativeRegisterContextLinux_arm::SetHardwareWatchpoint(
uint32_t control_value = 0, wp_index = 0, addr_word_offset = 0, byte_mask = 0;
lldb::addr_t real_addr = addr;
- // Check if we are setting watchpoint other than read/write/access
- // Also update watchpoint flag to match Arm write-read bit configuration.
+ // Check if we are setting watchpoint other than read/write/access Also
+ // update watchpoint flag to match Arm write-read bit configuration.
switch (watch_flags) {
case 1:
watch_flags = 2;
@@ -579,9 +579,9 @@ uint32_t NativeRegisterContextLinux_arm::SetHardwareWatchpoint(
if (size == 0 || size > 4)
return LLDB_INVALID_INDEX32;
- // Check 4-byte alignment for hardware watchpoint target address.
- // Below is a hack to recalculate address and size in order to
- // make sure we can watch non 4-byte alligned addresses as well.
+ // Check 4-byte alignment for hardware watchpoint target address. Below is a
+ // hack to recalculate address and size in order to make sure we can watch
+ // non 4-byte alligned addresses as well.
if (addr & 0x03) {
uint8_t watch_mask = (addr & 0x03) + size;
@@ -874,12 +874,10 @@ Status NativeRegisterContextLinux_arm::DoReadRegisterValue(
uint32_t offset, const char *reg_name, uint32_t size,
RegisterValue &value) {
// PTRACE_PEEKUSER don't work in the aarch64 linux kernel used on android
- // devices (always return
- // "Bad address"). To avoid using PTRACE_PEEKUSER we read out the full GPR
- // register set instead.
- // This approach is about 4 times slower but the performance overhead is
- // negligible in
- // comparision to processing time in lldb-server.
+ // devices (always return "Bad address"). To avoid using PTRACE_PEEKUSER we
+ // read out the full GPR register set instead. This approach is about 4 times
+ // slower but the performance overhead is negligible in comparision to
+ // processing time in lldb-server.
assert(offset % 4 == 0 && "Try to write a register with unaligned offset");
if (offset + sizeof(uint32_t) > sizeof(m_gpr_arm))
return Status("Register isn't fit into the size of the GPR area");
@@ -895,13 +893,10 @@ Status NativeRegisterContextLinux_arm::DoReadRegisterValue(
Status NativeRegisterContextLinux_arm::DoWriteRegisterValue(
uint32_t offset, const char *reg_name, const RegisterValue &value) {
// PTRACE_POKEUSER don't work in the aarch64 linux kernel used on android
- // devices (always return
- // "Bad address"). To avoid using PTRACE_POKEUSER we read out the full GPR
- // register set, modify
- // the requested register and write it back. This approach is about 4 times
- // slower but the
- // performance overhead is negligible in comparision to processing time in
- // lldb-server.
+ // devices (always return "Bad address"). To avoid using PTRACE_POKEUSER we
+ // read out the full GPR register set, modify the requested register and
+ // write it back. This approach is about 4 times slower but the performance
+ // overhead is negligible in comparision to processing time in lldb-server.
assert(offset % 4 == 0 && "Try to write a register with unaligned offset");
if (offset + sizeof(uint32_t) > sizeof(m_gpr_arm))
return Status("Register isn't fit into the size of the GPR area");
@@ -915,9 +910,8 @@ Status NativeRegisterContextLinux_arm::DoWriteRegisterValue(
// will clear thumb bit of new PC if we are already in thumb mode; that is
// CPSR thumb mode bit is set.
if (offset / sizeof(uint32_t) == gpr_pc_arm) {
- // Check if we are already in thumb mode and
- // thumb bit of current PC is read out to be zero and
- // thumb bit of next PC is read out to be one.
+ // Check if we are already in thumb mode and thumb bit of current PC is
+ // read out to be zero and thumb bit of next PC is read out to be one.
if ((m_gpr_arm[gpr_cpsr_arm] & 0x20) && !(m_gpr_arm[gpr_pc_arm] & 0x01) &&
(value.GetAsUInt32() & 0x01)) {
reg_value &= (~1ull);
diff --git a/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm.h b/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm.h
index 40e3b80eda743..d0b068550a9ee 100644
--- a/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm.h
+++ b/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm.h
@@ -42,7 +42,7 @@ public:
Status WriteAllRegisterValues(const lldb::DataBufferSP &data_sp) override;
//------------------------------------------------------------------
- // Hardware breakpoints/watchpoint mangement functions
+ // Hardware breakpoints/watchpoint management functions
//------------------------------------------------------------------
uint32_t NumSupportedHardwareBreakpoints() override;
@@ -140,7 +140,7 @@ private:
// occurred.
lldb::addr_t real_addr; // Address value that should cause target to stop.
uint32_t control; // Breakpoint/watchpoint control value.
- uint32_t refcount; // Serves as enable/disable and refernce counter.
+ uint32_t refcount; // Serves as enable/disable and reference counter.
};
struct DREG m_hbr_regs[16]; // Arm native linux hardware breakpoints
diff --git a/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm64.cpp b/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm64.cpp
index c483260a5b2c8..41fe446f728c7 100644
--- a/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm64.cpp
+++ b/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm64.cpp
@@ -28,8 +28,7 @@
#include "Plugins/Process/Utility/RegisterInfoPOSIX_arm64.h"
// System includes - They have to be included after framework includes because
-// they define some
-// macros which collide with variable names in other modules
+// they define some macros which collide with variable names in other modules
#include <sys/socket.h>
// NT_PRSTATUS and NT_FPREGSET definition
#include <elf.h>
@@ -207,14 +206,14 @@ NativeRegisterContextLinux_arm64::ReadRegister(const RegisterInfo *reg_info,
error = ReadRegisterRaw(full_reg, reg_value);
if (error.Success()) {
- // If our read was not aligned (for ah,bh,ch,dh), shift our returned value
- // one byte to the right.
+ // If our read was not aligned (for ah,bh,ch,dh), shift our returned
+ // value one byte to the right.
if (is_subreg && (reg_info->byte_offset & 0x1))
reg_value.SetUInt64(reg_value.GetAsUInt64() >> 8);
// If our return byte size was greater than the return value reg size,
- // then
- // use the type specified by reg_info rather than the uint64_t default
+ // then use the type specified by reg_info rather than the uint64_t
+ // default
if (reg_value.GetByteSize() > reg_info->byte_size)
reg_value.SetType(reg_info);
}
@@ -562,8 +561,8 @@ uint32_t NativeRegisterContextLinux_arm64::SetHardwareWatchpoint(
uint32_t control_value = 0, wp_index = 0;
lldb::addr_t real_addr = addr;
- // Check if we are setting watchpoint other than read/write/access
- // Also update watchpoint flag to match AArch64 write-read bit configuration.
+ // Check if we are setting watchpoint other than read/write/access Also
+ // update watchpoint flag to match AArch64 write-read bit configuration.
switch (watch_flags) {
case 1:
watch_flags = 2;
@@ -581,9 +580,9 @@ uint32_t NativeRegisterContextLinux_arm64::SetHardwareWatchpoint(
if (size != 1 && size != 2 && size != 4 && size != 8)
return LLDB_INVALID_INDEX32;
- // Check 8-byte alignment for hardware watchpoint target address.
- // Below is a hack to recalculate address and size in order to
- // make sure we can watch non 8-byte alligned addresses as well.
+ // Check 8-byte alignment for hardware watchpoint target address. Below is a
+ // hack to recalculate address and size in order to make sure we can watch
+ // non 8-byte alligned addresses as well.
if (addr & 0x07) {
uint8_t watch_mask = (addr & 0x07) + size;
diff --git a/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm64.h b/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm64.h
index ab3c881ead598..c859d4249d053 100644
--- a/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm64.h
+++ b/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm64.h
@@ -42,7 +42,7 @@ public:
Status WriteAllRegisterValues(const lldb::DataBufferSP &data_sp) override;
//------------------------------------------------------------------
- // Hardware breakpoints/watchpoint mangement functions
+ // Hardware breakpoints/watchpoint management functions
//------------------------------------------------------------------
uint32_t NumSupportedHardwareBreakpoints() override;
@@ -140,7 +140,7 @@ private:
// occurred.
lldb::addr_t real_addr; // Address value that should cause target to stop.
uint32_t control; // Breakpoint/watchpoint control value.
- uint32_t refcount; // Serves as enable/disable and refernce counter.
+ uint32_t refcount; // Serves as enable/disable and reference counter.
};
struct DREG m_hbr_regs[16]; // Arm native linux hardware breakpoints
diff --git a/source/Plugins/Process/Linux/NativeRegisterContextLinux_mips64.cpp b/source/Plugins/Process/Linux/NativeRegisterContextLinux_mips64.cpp
index 32c04a4374e62..69194b3c06630 100644
--- a/source/Plugins/Process/Linux/NativeRegisterContextLinux_mips64.cpp
+++ b/source/Plugins/Process/Linux/NativeRegisterContextLinux_mips64.cpp
@@ -140,9 +140,9 @@ NativeRegisterContextLinux_mips64::NativeRegisterContextLinux_mips64(
break;
}
- // Initialize m_iovec to point to the buffer and buffer size
- // using the conventions of Berkeley style UIO structures, as required
- // by PTRACE extensions.
+ // Initialize m_iovec to point to the buffer and buffer size using the
+ // conventions of Berkeley style UIO structures, as required by PTRACE
+ // extensions.
m_iovec.iov_base = &m_msa;
m_iovec.iov_len = sizeof(MSA_linux_mips);
@@ -337,7 +337,8 @@ lldb_private::Status NativeRegisterContextLinux_mips64::WriteRegister(
uint8_t byte_size = reg_info->byte_size;
lldbassert(reg_info->byte_offset < sizeof(UserArea));
- // Initialise the FP and MSA buffers by reading all co-processor 1 registers
+ // Initialise the FP and MSA buffers by reading all co-processor 1
+ // registers
ReadCP1();
if (IsFPR(reg_index)) {
diff --git a/source/Plugins/Process/Linux/NativeRegisterContextLinux_ppc64le.cpp b/source/Plugins/Process/Linux/NativeRegisterContextLinux_ppc64le.cpp
index ea854dfa1dc6d..6aa4af64ab51b 100644
--- a/source/Plugins/Process/Linux/NativeRegisterContextLinux_ppc64le.cpp
+++ b/source/Plugins/Process/Linux/NativeRegisterContextLinux_ppc64le.cpp
@@ -26,8 +26,7 @@
#include "Plugins/Process/Utility/RegisterInfoPOSIX_ppc64le.h"
// System includes - They have to be included after framework includes because
-// they define some
-// macros which collide with variable names in other modules
+// they define some macros which collide with variable names in other modules
#include <sys/socket.h>
#include <elf.h>
#include <asm/ptrace.h>
@@ -50,6 +49,7 @@ static const uint32_t g_gpr_regnums_ppc64le[] = {
gpr_pc_ppc64le, gpr_msr_ppc64le, gpr_origr3_ppc64le, gpr_ctr_ppc64le,
gpr_lr_ppc64le, gpr_xer_ppc64le, gpr_cr_ppc64le, gpr_softe_ppc64le,
gpr_trap_ppc64le,
+ LLDB_INVALID_REGNUM // register sets need to end with this flag
};
static const uint32_t g_fpr_regnums_ppc64le[] = {
@@ -62,6 +62,7 @@ static const uint32_t g_fpr_regnums_ppc64le[] = {
fpr_f24_ppc64le, fpr_f25_ppc64le, fpr_f26_ppc64le, fpr_f27_ppc64le,
fpr_f28_ppc64le, fpr_f29_ppc64le, fpr_f30_ppc64le, fpr_f31_ppc64le,
fpr_fpscr_ppc64le,
+ LLDB_INVALID_REGNUM // register sets need to end with this flag
};
static const uint32_t g_vmx_regnums_ppc64le[] = {
@@ -74,6 +75,7 @@ static const uint32_t g_vmx_regnums_ppc64le[] = {
vmx_vr24_ppc64le, vmx_vr25_ppc64le, vmx_vr26_ppc64le, vmx_vr27_ppc64le,
vmx_vr28_ppc64le, vmx_vr29_ppc64le, vmx_vr30_ppc64le, vmx_vr31_ppc64le,
vmx_vscr_ppc64le, vmx_vrsave_ppc64le,
+ LLDB_INVALID_REGNUM // register sets need to end with this flag
};
static const uint32_t g_vsx_regnums_ppc64le[] = {
@@ -93,6 +95,7 @@ static const uint32_t g_vsx_regnums_ppc64le[] = {
vsx_vs52_ppc64le, vsx_vs53_ppc64le, vsx_vs54_ppc64le, vsx_vs55_ppc64le,
vsx_vs56_ppc64le, vsx_vs57_ppc64le, vsx_vs58_ppc64le, vsx_vs59_ppc64le,
vsx_vs60_ppc64le, vsx_vs61_ppc64le, vsx_vs62_ppc64le, vsx_vs63_ppc64le,
+ LLDB_INVALID_REGNUM // register sets need to end with this flag
};
namespace {
@@ -565,8 +568,8 @@ uint32_t NativeRegisterContextLinux_ppc64le::SetHardwareWatchpoint(
lldb::addr_t real_addr = addr;
uint32_t rw_mode = 0;
- // Check if we are setting watchpoint other than read/write/access
- // Update watchpoint flag to match ppc64le write-read bit configuration.
+ // Check if we are setting watchpoint other than read/write/access Update
+ // watchpoint flag to match ppc64le write-read bit configuration.
switch (watch_flags) {
case eWatchpointKindWrite:
rw_mode = PPC_BREAKPOINT_TRIGGER_WRITE;
@@ -587,9 +590,9 @@ uint32_t NativeRegisterContextLinux_ppc64le::SetHardwareWatchpoint(
if (size != 1 && size != 2 && size != 4 && size != 8)
return LLDB_INVALID_INDEX32;
- // Check 8-byte alignment for hardware watchpoint target address.
- // Below is a hack to recalculate address and size in order to
- // make sure we can watch non 8-byte alligned addresses as well.
+ // Check 8-byte alignment for hardware watchpoint target address. Below is a
+ // hack to recalculate address and size in order to make sure we can watch
+ // non 8-byte alligned addresses as well.
if (addr & 0x07) {
addr_t begin = llvm::alignDown(addr, 8);
diff --git a/source/Plugins/Process/Linux/NativeRegisterContextLinux_ppc64le.h b/source/Plugins/Process/Linux/NativeRegisterContextLinux_ppc64le.h
index bb25af80d02cd..2c4471962ad0d 100644
--- a/source/Plugins/Process/Linux/NativeRegisterContextLinux_ppc64le.h
+++ b/source/Plugins/Process/Linux/NativeRegisterContextLinux_ppc64le.h
@@ -19,7 +19,7 @@
#include "Plugins/Process/Utility/lldb-ppc64le-register-enums.h"
#define DECLARE_REGISTER_INFOS_PPC64LE_STRUCT
-#include "RegisterInfos_ppc64le.h"
+#include "Plugins/Process/Utility/RegisterInfos_ppc64le.h"
#undef DECLARE_REGISTER_INFOS_PPC64LE_STRUCT
namespace lldb_private {
@@ -49,7 +49,7 @@ public:
Status WriteAllRegisterValues(const lldb::DataBufferSP &data_sp) override;
//------------------------------------------------------------------
- // Hardware watchpoint mangement functions
+ // Hardware watchpoint management functions
//------------------------------------------------------------------
uint32_t NumSupportedHardwareWatchpoints() override;
diff --git a/source/Plugins/Process/Linux/NativeRegisterContextLinux_s390x.cpp b/source/Plugins/Process/Linux/NativeRegisterContextLinux_s390x.cpp
index 021394ab154b5..36da2b001054b 100644
--- a/source/Plugins/Process/Linux/NativeRegisterContextLinux_s390x.cpp
+++ b/source/Plugins/Process/Linux/NativeRegisterContextLinux_s390x.cpp
@@ -10,7 +10,7 @@
#if defined(__s390x__) && defined(__linux__)
#include "NativeRegisterContextLinux_s390x.h"
-
+#include "Plugins/Process/Linux/NativeProcessLinux.h"
#include "lldb/Core/RegisterValue.h"
#include "lldb/Host/HostInfo.h"
#include "lldb/Utility/DataBufferHeap.h"
@@ -372,10 +372,10 @@ Status NativeRegisterContextLinux_s390x::ReadAllRegisterValues(
DoReadRegisterSet(NT_S390_SYSTEM_CALL, dst, 4);
dst += 4;
- // To enable inferior function calls while the process is stopped in
- // an interrupted system call, we need to clear the system call flag.
- // It will be restored to its original value by WriteAllRegisterValues.
- // Again we ignore error if the regset is unsupported.
+ // To enable inferior function calls while the process is stopped in an
+ // interrupted system call, we need to clear the system call flag. It will be
+ // restored to its original value by WriteAllRegisterValues. Again we ignore
+ // error if the regset is unsupported.
uint32_t system_call = 0;
DoWriteRegisterSet(NT_S390_SYSTEM_CALL, &system_call, 4);
diff --git a/source/Plugins/Process/Linux/NativeRegisterContextLinux_x86_64.cpp b/source/Plugins/Process/Linux/NativeRegisterContextLinux_x86_64.cpp
index 84ffe9b6e4202..87f4b8da053ee 100755
--- a/source/Plugins/Process/Linux/NativeRegisterContextLinux_x86_64.cpp
+++ b/source/Plugins/Process/Linux/NativeRegisterContextLinux_x86_64.cpp
@@ -329,9 +329,9 @@ NativeRegisterContextLinux_x86_64::NativeRegisterContextLinux_x86_64(
break;
}
- // Initialize m_iovec to point to the buffer and buffer size
- // using the conventions of Berkeley style UIO structures, as required
- // by PTRACE extensions.
+ // Initialize m_iovec to point to the buffer and buffer size using the
+ // conventions of Berkeley style UIO structures, as required by PTRACE
+ // extensions.
m_iovec.iov_base = &m_fpr;
m_iovec.iov_len = sizeof(m_fpr);
@@ -420,14 +420,14 @@ NativeRegisterContextLinux_x86_64::ReadRegister(const RegisterInfo *reg_info,
error = ReadRegisterRaw(full_reg, reg_value);
if (error.Success()) {
- // If our read was not aligned (for ah,bh,ch,dh), shift our returned value
- // one byte to the right.
+ // If our read was not aligned (for ah,bh,ch,dh), shift our returned
+ // value one byte to the right.
if (is_subreg && (reg_info->byte_offset & 0x1))
reg_value.SetUInt64(reg_value.GetAsUInt64() >> 8);
// If our return byte size was greater than the return value reg size,
- // then
- // use the type specified by reg_info rather than the uint64_t default
+ // then use the type specified by reg_info rather than the uint64_t
+ // default
if (reg_value.GetByteSize() > reg_info->byte_size)
reg_value.SetType(reg_info);
}
@@ -448,7 +448,8 @@ NativeRegisterContextLinux_x86_64::ReadRegister(const RegisterInfo *reg_info,
reg_value.SetBytes(m_fpr.fxsave.xmm[reg - m_reg_info.first_xmm].bytes,
reg_info->byte_size, byte_order);
if (reg >= m_reg_info.first_ymm && reg <= m_reg_info.last_ymm) {
- // Concatenate ymm using the register halves in xmm.bytes and ymmh.bytes
+ // Concatenate ymm using the register halves in xmm.bytes and
+ // ymmh.bytes
if (CopyXSTATEtoYMM(reg, byte_order))
reg_value.SetBytes(m_ymm_set.ymm[reg - m_reg_info.first_ymm].bytes,
reg_info->byte_size, byte_order);
@@ -492,8 +493,7 @@ NativeRegisterContextLinux_x86_64::ReadRegister(const RegisterInfo *reg_info,
// Byte offsets of all registers are calculated wrt 'UserArea' structure.
// However, ReadFPR() reads fpu registers {using ptrace(PTRACE_GETFPREGS,..)}
// and stores them in 'm_fpr' (of type FPR structure). To extract values of
- // fpu
- // registers, m_fpr should be read at byte offsets calculated wrt to FPR
+ // fpu registers, m_fpr should be read at byte offsets calculated wrt to FPR
// structure.
// Since, FPR structure is also one of the member of UserArea structure.
@@ -599,11 +599,10 @@ Status NativeRegisterContextLinux_x86_64::WriteRegister(
// Get pointer to m_fpr.fxsave variable and set the data to it.
// Byte offsets of all registers are calculated wrt 'UserArea' structure.
- // However, WriteFPR() takes m_fpr (of type FPR structure) and writes only
- // fpu
- // registers using ptrace(PTRACE_SETFPREGS,..) API. Hence fpu registers
- // should
- // be written in m_fpr at byte offsets calculated wrt FPR structure.
+ // However, WriteFPR() takes m_fpr (of type FPR structure) and writes
+ // only fpu registers using ptrace(PTRACE_SETFPREGS,..) API. Hence fpu
+ // registers should be written in m_fpr at byte offsets calculated wrt
+ // FPR structure.
// Since, FPR structure is also one of the member of UserArea structure.
// byte_offset(fpu wrt FPR) = byte_offset(fpu wrt UserArea) -
@@ -1093,8 +1092,7 @@ Status NativeRegisterContextLinux_x86_64::SetHardwareWatchpointWithIndex(
if (error.Fail())
return error;
- // for watchpoints 0, 1, 2, or 3, respectively,
- // set bits 1, 3, 5, or 7
+ // for watchpoints 0, 1, 2, or 3, respectively, set bits 1, 3, 5, or 7
uint64_t enable_bit = 1 << (2 * wp_index);
// set bits 16-17, 20-21, 24-25, or 28-29
@@ -1132,8 +1130,8 @@ bool NativeRegisterContextLinux_x86_64::ClearHardwareWatchpoint(
RegisterValue reg_value;
- // for watchpoints 0, 1, 2, or 3, respectively,
- // clear bits 0, 1, 2, or 3 of the debug status register (DR6)
+ // for watchpoints 0, 1, 2, or 3, respectively, clear bits 0, 1, 2, or 3 of
+ // the debug status register (DR6)
Status error = ReadRegisterRaw(m_reg_info.first_dr + 6, reg_value);
if (error.Fail())
return false;
@@ -1143,9 +1141,9 @@ bool NativeRegisterContextLinux_x86_64::ClearHardwareWatchpoint(
if (error.Fail())
return false;
- // for watchpoints 0, 1, 2, or 3, respectively,
- // clear bits {0-1,16-19}, {2-3,20-23}, {4-5,24-27}, or {6-7,28-31}
- // of the debug control register (DR7)
+ // for watchpoints 0, 1, 2, or 3, respectively, clear bits {0-1,16-19},
+ // {2-3,20-23}, {4-5,24-27}, or {6-7,28-31} of the debug control register
+ // (DR7)
error = ReadRegisterRaw(m_reg_info.first_dr + 7, reg_value);
if (error.Fail())
return false;
diff --git a/source/Plugins/Process/Linux/NativeThreadLinux.cpp b/source/Plugins/Process/Linux/NativeThreadLinux.cpp
index 0db3bd56b8e4c..4ab2a9ae62454 100644
--- a/source/Plugins/Process/Linux/NativeThreadLinux.cpp
+++ b/source/Plugins/Process/Linux/NativeThreadLinux.cpp
@@ -211,8 +211,8 @@ Status NativeThreadLinux::Resume(uint32_t signo) {
m_stop_info.reason = StopReason::eStopReasonNone;
m_stop_description.clear();
- // If watchpoints have been set, but none on this thread,
- // then this is a new thread. So set all existing watchpoints.
+ // If watchpoints have been set, but none on this thread, then this is a new
+ // thread. So set all existing watchpoints.
if (m_watchpoint_index_map.empty()) {
NativeProcessLinux &process = GetProcess();
@@ -263,8 +263,8 @@ Status NativeThreadLinux::SingleStep(uint32_t signo) {
data = signo;
// If hardware single-stepping is not supported, we just do a continue. The
- // breakpoint on the
- // next instruction has been setup in NativeProcessLinux::Resume.
+ // breakpoint on the next instruction has been setup in
+ // NativeProcessLinux::Resume.
return NativeProcessLinux::PtraceWrapper(
GetProcess().SupportHardwareSingleStepping() ? PTRACE_SINGLESTEP
: PTRACE_CONT,
diff --git a/source/Plugins/Process/Linux/ProcessorTrace.h b/source/Plugins/Process/Linux/ProcessorTrace.h
index 6603c7d604784..6fd918c2bb58a 100644
--- a/source/Plugins/Process/Linux/ProcessorTrace.h
+++ b/source/Plugins/Process/Linux/ProcessorTrace.h
@@ -34,7 +34,7 @@ namespace process_linux {
// a key to the tracing instance and trace manipulations could be
// performed using the trace id.
//
-// The traace id could map to trace instances for a group of threads
+// The trace id could map to trace instances for a group of threads
// (spanning to all the threads in the process) or a single thread.
// The kernel interface for us is the perf_event_open.
// ---------------------------------------------------------------------
diff --git a/source/Plugins/Process/Linux/SingleStepCheck.cpp b/source/Plugins/Process/Linux/SingleStepCheck.cpp
index 251cb4b2f10ae..c57a2daf22757 100644
--- a/source/Plugins/Process/Linux/SingleStepCheck.cpp
+++ b/source/Plugins/Process/Linux/SingleStepCheck.cpp
@@ -59,9 +59,9 @@ struct ChildDeleter {
bool WorkaroundNeeded() {
// We shall spawn a child, and use it to verify the debug capabilities of the
- // cpu. We shall iterate through the cpus, bind the child to each one in turn,
- // and verify that single-stepping works on that cpu. A workaround is needed
- // if we find at least one broken cpu.
+ // cpu. We shall iterate through the cpus, bind the child to each one in
+ // turn, and verify that single-stepping works on that cpu. A workaround is
+ // needed if we find at least one broken cpu.
Log *log = ProcessPOSIXLog::GetLogIfAllCategoriesSet(POSIX_LOG_THREAD);
::pid_t child_pid = fork();
diff --git a/source/Plugins/Process/MacOSX-Kernel/CommunicationKDP.cpp b/source/Plugins/Process/MacOSX-Kernel/CommunicationKDP.cpp
index 3d9f498b1e9ac..116155d9a2324 100644
--- a/source/Plugins/Process/MacOSX-Kernel/CommunicationKDP.cpp
+++ b/source/Plugins/Process/MacOSX-Kernel/CommunicationKDP.cpp
@@ -59,15 +59,6 @@ bool CommunicationKDP::SendRequestPacket(
return SendRequestPacketNoLock(request_packet);
}
-#if 0
-typedef struct {
- uint8_t request; // Either: CommandType | ePacketTypeRequest, or CommandType | ePacketTypeReply
- uint8_t sequence;
- uint16_t length; // Length of entire packet including this header
- uint32_t key; // Session key
-} kdp_hdr_t;
-#endif
-
void CommunicationKDP::MakeRequestPacketHeader(CommandType request_type,
PacketStreamType &request_packet,
uint16_t request_length) {
@@ -127,16 +118,14 @@ bool CommunicationKDP::SendRequestAndGetReply(
}
} else if (reply_sequence_id > request_sequence_id) {
// Sequence ID was greater than the sequence ID of the packet we
- // sent, something
- // is really wrong...
+ // sent, something is really wrong...
reply_packet.Clear();
return false;
} else {
- // The reply sequence ID was less than our current packet's sequence
- // ID
- // so we should keep trying to get a response because this was a
- // response
- // for a previous packet that we must have retried.
+ // The reply sequence ID was less than our current packet's
+ // sequence ID so we should keep trying to get a response because
+ // this was a response for a previous packet that we must have
+ // retried.
}
} else {
// Break and retry sending the packet as we didn't get a response due
@@ -186,7 +175,7 @@ bool CommunicationKDP::GetSequenceMutex(
bool CommunicationKDP::WaitForNotRunningPrivate(
const std::chrono::microseconds &timeout) {
- return m_is_running.WaitForValueEqualTo(false, timeout, NULL);
+ return m_is_running.WaitForValueEqualTo(false, timeout);
}
size_t
@@ -324,9 +313,9 @@ bool CommunicationKDP::CheckForPacket(const uint8_t *src, size_t src_len,
offset = 2;
const uint16_t length = packet.GetU16(&offset);
if (length <= bytes_available) {
- // We have an entire packet ready, we need to copy the data
- // bytes into a buffer that will be owned by the packet and
- // erase the bytes from our communcation buffer "m_bytes"
+ // We have an entire packet ready, we need to copy the data bytes into
+ // a buffer that will be owned by the packet and erase the bytes from
+ // our communcation buffer "m_bytes"
packet.SetData(DataBufferSP(new DataBufferHeap(&m_bytes[0], length)));
m_bytes.erase(0, length);
@@ -341,8 +330,8 @@ bool CommunicationKDP::CheckForPacket(const uint8_t *src, size_t src_len,
} break;
default:
- // Unrecognized reply command byte, erase this byte and try to get back on
- // track
+ // Unrecognized reply command byte, erase this byte and try to get back
+ // on track
if (log)
log->Printf("CommunicationKDP::%s: tossing junk byte: 0x%2.2x",
__FUNCTION__, (uint8_t)m_bytes[0]);
@@ -436,34 +425,6 @@ bool CommunicationKDP::SendRequestVersion() {
return false;
}
-#if 0 // Disable KDP_IMAGEPATH for now, it seems to hang the KDP connection...
-const char *
-CommunicationKDP::GetImagePath ()
-{
- if (m_image_path.empty())
- SendRequestImagePath();
- return m_image_path.c_str();
-}
-
-bool
-CommunicationKDP::SendRequestImagePath ()
-{
- PacketStreamType request_packet (Stream::eBinary, m_addr_byte_size, m_byte_order);
- const CommandType command = KDP_IMAGEPATH;
- const uint32_t command_length = 8;
- MakeRequestPacketHeader (command, request_packet, command_length);
- DataExtractor reply_packet;
- if (SendRequestAndGetReply (command, request_packet, reply_packet))
- {
- const char *path = reply_packet.PeekCStr(8);
- if (path && path[0])
- m_kernel_version.assign (path);
- return true;
- }
- return false;
-}
-#endif
-
uint32_t CommunicationKDP::GetCPUMask() {
if (!HostInfoIsValid())
SendRequestHostInfo();
@@ -495,7 +456,7 @@ lldb_private::UUID CommunicationKDP::GetUUID() {
if (uuid_str.size() < 32)
return uuid;
- if (uuid.SetFromCString(uuid_str.c_str()) == 0) {
+ if (uuid.SetFromStringRef(uuid_str) == 0) {
UUID invalid_uuid;
return invalid_uuid;
}
@@ -1245,8 +1206,8 @@ uint32_t CommunicationKDP::SendRequestReadRegisters(uint32_t cpu,
if (src) {
::memcpy(dst, src, bytes_to_copy);
error.Clear();
- // Return the number of bytes we could have returned regardless if
- // we copied them or not, just so we know when things don't match up
+ // Return the number of bytes we could have returned regardless if we
+ // copied them or not, just so we know when things don't match up
return src_len;
}
}
diff --git a/source/Plugins/Process/MacOSX-Kernel/ProcessKDP.cpp b/source/Plugins/Process/MacOSX-Kernel/ProcessKDP.cpp
index f01f1ace583cb..2e707ab2e3633 100644
--- a/source/Plugins/Process/MacOSX-Kernel/ProcessKDP.cpp
+++ b/source/Plugins/Process/MacOSX-Kernel/ProcessKDP.cpp
@@ -172,10 +172,10 @@ ProcessKDP::ProcessKDP(TargetSP target_sp, ListenerSP listener_sp)
//----------------------------------------------------------------------
ProcessKDP::~ProcessKDP() {
Clear();
- // We need to call finalize on the process before destroying ourselves
- // to make sure all of the broadcaster cleanup goes as planned. If we
- // destruct this class, then Process::~Process() might have problems
- // trying to fully destroy the broadcaster.
+ // We need to call finalize on the process before destroying ourselves to
+ // make sure all of the broadcaster cleanup goes as planned. If we destruct
+ // this class, then Process::~Process() might have problems trying to fully
+ // destroy the broadcaster.
Finalize();
}
@@ -226,9 +226,9 @@ bool ProcessKDP::GetHostArchitecture(ArchSpec &arch) {
Status ProcessKDP::DoConnectRemote(Stream *strm, llvm::StringRef remote_url) {
Status error;
- // Don't let any JIT happen when doing KDP as we can't allocate
- // memory and we don't want to be mucking with threads that might
- // already be handling exceptions
+ // Don't let any JIT happen when doing KDP as we can't allocate memory and we
+ // don't want to be mucking with threads that might already be handling
+ // exceptions
SetCanJIT(false);
if (remote_url.empty()) {
@@ -282,16 +282,15 @@ Status ProcessKDP::DoConnectRemote(Stream *strm, llvm::StringRef remote_url) {
if (m_comm.RemoteIsEFI()) {
// Select an invalid plugin name for the dynamic loader so one
- // doesn't get used
- // since EFI does its own manual loading via python scripting
+ // doesn't get used since EFI does its own manual loading via
+ // python scripting
static ConstString g_none_dynamic_loader("none");
m_dyld_plugin_name = g_none_dynamic_loader;
if (kernel_uuid.IsValid()) {
- // If EFI passed in a UUID= try to lookup UUID
- // The slide will not be provided. But the UUID
- // lookup will be used to launch EFI debug scripts
- // from the dSYM, that can load all of the symbols.
+ // If EFI passed in a UUID= try to lookup UUID The slide will not
+ // be provided. But the UUID lookup will be used to launch EFI
+ // debug scripts from the dSYM, that can load all of the symbols.
ModuleSpec module_spec;
module_spec.GetUUID() = kernel_uuid;
module_spec.GetArchitecture() = target.GetArchitecture();
@@ -386,7 +385,7 @@ ProcessKDP::DoAttachToProcessWithID(lldb::pid_t attach_pid,
const ProcessAttachInfo &attach_info) {
Status error;
error.SetErrorString(
- "attach to process by ID is not suppported in kdp remote debugging");
+ "attach to process by ID is not supported in kdp remote debugging");
return error;
}
@@ -395,7 +394,7 @@ ProcessKDP::DoAttachToProcessWithName(const char *process_name,
const ProcessAttachInfo &attach_info) {
Status error;
error.SetErrorString(
- "attach to process by name is not suppported in kdp remote debugging");
+ "attach to process by name is not supported in kdp remote debugging");
return error;
}
@@ -443,8 +442,8 @@ Status ProcessKDP::DoResume() {
StateAsCString(thread_resume_state));
switch (thread_resume_state) {
case eStateSuspended:
- // Nothing to do here when a thread will stay suspended
- // we just leave the CPU mask bit set to zero for the thread
+ // Nothing to do here when a thread will stay suspended we just leave the
+ // CPU mask bit set to zero for the thread
if (log)
log->Printf("ProcessKDP::DoResume() = suspended???");
break;
@@ -535,8 +534,8 @@ bool ProcessKDP::UpdateThreadList(ThreadList &old_thread_list,
}
void ProcessKDP::RefreshStateAfterStop() {
- // Let all threads recover from stopping and do any clean up based
- // on the previous thread state (if any).
+ // Let all threads recover from stopping and do any clean up based on the
+ // previous thread state (if any).
m_thread_list.RefreshStateAfterStop();
}
@@ -545,9 +544,9 @@ Status ProcessKDP::DoHalt(bool &caused_stop) {
if (m_comm.IsRunning()) {
if (m_destroy_in_process) {
- // If we are attemping to destroy, we need to not return an error to
- // Halt or DoDestroy won't get called.
- // We are also currently running, so send a process stopped event
+ // If we are attempting to destroy, we need to not return an error to Halt
+ // or DoDestroy won't get called. We are also currently running, so send
+ // a process stopped event
SetPrivateState(eStateStopped);
} else {
error.SetErrorString("KDP cannot interrupt a running kernel");
@@ -563,8 +562,8 @@ Status ProcessKDP::DoDetach(bool keep_stopped) {
log->Printf("ProcessKDP::DoDetach(keep_stopped = %i)", keep_stopped);
if (m_comm.IsRunning()) {
- // We are running and we can't interrupt a running kernel, so we need
- // to just close the connection to the kernel and hope for the best
+ // We are running and we can't interrupt a running kernel, so we need to
+ // just close the connection to the kernel and hope for the best
} else {
// If we are going to keep the target stopped, then don't send the
// disconnect message.
@@ -647,14 +646,14 @@ size_t ProcessKDP::DoWriteMemory(addr_t addr, const void *buf, size_t size,
lldb::addr_t ProcessKDP::DoAllocateMemory(size_t size, uint32_t permissions,
Status &error) {
error.SetErrorString(
- "memory allocation not suppported in kdp remote debugging");
+ "memory allocation not supported in kdp remote debugging");
return LLDB_INVALID_ADDRESS;
}
Status ProcessKDP::DoDeallocateMemory(lldb::addr_t addr) {
Status error;
error.SetErrorString(
- "memory deallocation not suppported in kdp remote debugging");
+ "memory deallocation not supported in kdp remote debugging");
return error;
}
@@ -701,14 +700,14 @@ Status ProcessKDP::DisableBreakpointSite(BreakpointSite *bp_site) {
Status ProcessKDP::EnableWatchpoint(Watchpoint *wp, bool notify) {
Status error;
error.SetErrorString(
- "watchpoints are not suppported in kdp remote debugging");
+ "watchpoints are not supported in kdp remote debugging");
return error;
}
Status ProcessKDP::DisableWatchpoint(Watchpoint *wp, bool notify) {
Status error;
error.SetErrorString(
- "watchpoints are not suppported in kdp remote debugging");
+ "watchpoints are not supported in kdp remote debugging");
return error;
}
@@ -717,7 +716,7 @@ void ProcessKDP::Clear() { m_thread_list.Clear(); }
Status ProcessKDP::DoSignal(int signo) {
Status error;
error.SetErrorString(
- "sending signals is not suppported in kdp remote debugging");
+ "sending signals is not supported in kdp remote debugging");
return error;
}
diff --git a/source/Plugins/Process/MacOSX-Kernel/ThreadKDP.cpp b/source/Plugins/Process/MacOSX-Kernel/ThreadKDP.cpp
index 1902cc492ff4f..7fca0fc24fdbf 100644
--- a/source/Plugins/Process/MacOSX-Kernel/ThreadKDP.cpp
+++ b/source/Plugins/Process/MacOSX-Kernel/ThreadKDP.cpp
@@ -52,11 +52,11 @@ ThreadKDP::~ThreadKDP() {
const char *ThreadKDP::GetName() {
if (m_thread_name.empty())
- return NULL;
+ return nullptr;
return m_thread_name.c_str();
}
-const char *ThreadKDP::GetQueueName() { return NULL; }
+const char *ThreadKDP::GetQueueName() { return nullptr; }
void ThreadKDP::RefreshStateAfterStop() {
// Invalidate all registers in our register context. We don't set "force" to
@@ -65,8 +65,8 @@ void ThreadKDP::RefreshStateAfterStop() {
// context by the time this function gets called. The KDPRegisterContext
// class has been made smart enough to detect when it needs to invalidate
// which registers are valid by putting hooks in the register read and
- // register supply functions where they check the process stop ID and do
- // the right thing.
+ // register supply functions where they check the process stop ID and do the
+ // right thing.
const bool force = false;
lldb::RegisterContextSP reg_ctx_sp(GetRegisterContext());
if (reg_ctx_sp)
@@ -79,8 +79,8 @@ void ThreadKDP::Dump(Log *log, uint32_t index) {}
bool ThreadKDP::ShouldStop(bool &step_more) { return true; }
lldb::RegisterContextSP ThreadKDP::GetRegisterContext() {
- if (m_reg_context_sp.get() == NULL)
- m_reg_context_sp = CreateRegisterContextForFrame(NULL);
+ if (!m_reg_context_sp)
+ m_reg_context_sp = CreateRegisterContextForFrame(nullptr);
return m_reg_context_sp;
}
@@ -119,7 +119,7 @@ ThreadKDP::CreateRegisterContextForFrame(StackFrame *frame) {
}
} else {
Unwind *unwinder = GetUnwinder();
- if (unwinder)
+ if (unwinder != nullptr)
reg_ctx_sp = unwinder->CreateRegisterContextForFrame(frame);
}
return reg_ctx_sp;
@@ -151,8 +151,8 @@ void ThreadKDP::SetStopInfoFrom_KDP_EXCEPTION(
const uint32_t exc_type = exc_reply_packet.GetU32(&offset);
const uint32_t exc_code = exc_reply_packet.GetU32(&offset);
const uint32_t exc_subcode = exc_reply_packet.GetU32(&offset);
- // We have to make a copy of the stop info because the thread list
- // will iterate through the threads and clear all stop infos..
+ // We have to make a copy of the stop info because the thread list will
+ // iterate through the threads and clear all stop infos..
// Let the StopInfoMachException::CreateStopReasonWithMachException()
// function update the PC if needed as we might hit a software breakpoint
diff --git a/source/Plugins/Process/NetBSD/CMakeLists.txt b/source/Plugins/Process/NetBSD/CMakeLists.txt
index 5b2cef8b847be..92a6014ced07a 100644
--- a/source/Plugins/Process/NetBSD/CMakeLists.txt
+++ b/source/Plugins/Process/NetBSD/CMakeLists.txt
@@ -1,7 +1,3 @@
-include_directories(.)
-include_directories(../POSIX)
-include_directories(../Utility)
-
add_lldb_library(lldbPluginProcessNetBSD PLUGIN
NativeProcessNetBSD.cpp
NativeRegisterContextNetBSD.cpp
diff --git a/source/Plugins/Process/NetBSD/NativeProcessNetBSD.cpp b/source/Plugins/Process/NetBSD/NativeProcessNetBSD.cpp
index 387f04afa5b46..1a4cb21d000e0 100644
--- a/source/Plugins/Process/NetBSD/NativeProcessNetBSD.cpp
+++ b/source/Plugins/Process/NetBSD/NativeProcessNetBSD.cpp
@@ -24,8 +24,7 @@
#include "llvm/Support/Errno.h"
// System includes - They have to be included after framework includes because
-// they define some
-// macros which collide with variable names in other modules
+// they define some macros which collide with variable names in other modules
// clang-format off
#include <sys/types.h>
#include <sys/ptrace.h>
@@ -93,17 +92,19 @@ NativeProcessNetBSD::Factory::Launch(ProcessLaunchInfo &launch_info,
}
LLDB_LOG(log, "inferior started, now in stopped state");
- ArchSpec arch;
- if ((status = ResolveProcessArchitecture(pid, arch)).Fail())
- return status.ToError();
+ ProcessInstanceInfo Info;
+ if (!Host::GetProcessInfo(pid, Info)) {
+ return llvm::make_error<StringError>("Cannot get process architecture",
+ llvm::inconvertibleErrorCode());
+ }
// Set the architecture to the exe architecture.
LLDB_LOG(log, "pid = {0:x}, detected architecture {1}", pid,
- arch.GetArchitectureName());
+ Info.GetArchitecture().GetArchitectureName());
std::unique_ptr<NativeProcessNetBSD> process_up(new NativeProcessNetBSD(
pid, launch_info.GetPTY().ReleaseMasterFileDescriptor(), native_delegate,
- arch, mainloop));
+ Info.GetArchitecture(), mainloop));
status = process_up->ReinitializeThreads();
if (status.Fail())
@@ -111,7 +112,7 @@ NativeProcessNetBSD::Factory::Launch(ProcessLaunchInfo &launch_info,
for (const auto &thread : process_up->m_threads)
static_cast<NativeThreadNetBSD &>(*thread).SetStoppedBySignal(SIGSTOP);
- process_up->SetState(StateType::eStateStopped);
+ process_up->SetState(StateType::eStateStopped, false);
return std::move(process_up);
}
@@ -124,15 +125,16 @@ NativeProcessNetBSD::Factory::Attach(
LLDB_LOG(log, "pid = {0:x}", pid);
// Retrieve the architecture for the running process.
- ArchSpec arch;
- Status status = ResolveProcessArchitecture(pid, arch);
- if (!status.Success())
- return status.ToError();
+ ProcessInstanceInfo Info;
+ if (!Host::GetProcessInfo(pid, Info)) {
+ return llvm::make_error<StringError>("Cannot get process architecture",
+ llvm::inconvertibleErrorCode());
+ }
- std::unique_ptr<NativeProcessNetBSD> process_up(
- new NativeProcessNetBSD(pid, -1, native_delegate, arch, mainloop));
+ std::unique_ptr<NativeProcessNetBSD> process_up(new NativeProcessNetBSD(
+ pid, -1, native_delegate, Info.GetArchitecture(), mainloop));
- status = process_up->Attach();
+ Status status = process_up->Attach();
if (!status.Success())
return status.ToError();
@@ -349,8 +351,8 @@ NativeProcessNetBSD::FixupBreakpointPCAsNeeded(NativeThreadNetBSD &thread) {
return error;
} else
LLDB_LOG(log, "breakpoint size: {0}", breakpoint_size);
- // First try probing for a breakpoint at a software breakpoint location: PC
- // - breakpoint size.
+ // First try probing for a breakpoint at a software breakpoint location: PC -
+ // breakpoint size.
const lldb::addr_t initial_pc_addr =
context.GetPCfromBreakpointLocation();
lldb::addr_t breakpoint_addr = initial_pc_addr;
@@ -559,8 +561,8 @@ Status NativeProcessNetBSD::GetMemoryRegionInfo(lldb::addr_t load_addr,
"descending memory map entries detected, unexpected");
prev_base_address = proc_entry_info.GetRange().GetRangeBase();
UNUSED_IF_ASSERT_DISABLED(prev_base_address);
- // If the target address comes before this entry, indicate distance to
- // next region.
+ // If the target address comes before this entry, indicate distance to next
+ // region.
if (load_addr < proc_entry_info.GetRange().GetRangeBase()) {
range_info.GetRange().SetRangeBase(load_addr);
range_info.GetRange().SetByteSize(
@@ -579,9 +581,8 @@ Status NativeProcessNetBSD::GetMemoryRegionInfo(lldb::addr_t load_addr,
// parsed.
}
// If we made it here, we didn't find an entry that contained the given
- // address. Return the
- // load_addr as start and the amount of bytes betwwen load address and the
- // end of the memory as size.
+ // address. Return the load_addr as start and the amount of bytes betwwen
+ // load address and the end of the memory as size.
range_info.GetRange().SetRangeBase(load_addr);
range_info.GetRange().SetRangeEnd(LLDB_INVALID_ADDRESS);
range_info.SetReadable(MemoryRegionInfo::OptionalBool::eNo);
@@ -641,8 +642,8 @@ Status NativeProcessNetBSD::PopulateMemoryRegionCache() {
free(vm);
if (m_mem_region_cache.empty()) {
- // No entries after attempting to read them. This shouldn't happen.
- // Assume we don't support map entries.
+ // No entries after attempting to read them. This shouldn't happen. Assume
+ // we don't support map entries.
LLDB_LOG(log, "failed to find any vmmap entries, assuming no support "
"for memory region metadata retrieval");
m_supports_mem_region = LazyBool::eLazyBoolNo;
@@ -778,8 +779,8 @@ Status NativeProcessNetBSD::Attach() {
return status;
int wstatus;
- // Need to use WALLSIG otherwise we receive an error with errno=ECHLD
- // At this point we should have a thread stopped if waitpid succeeds.
+ // Need to use WALLSIG otherwise we receive an error with errno=ECHLD At this
+ // point we should have a thread stopped if waitpid succeeds.
if ((wstatus = waitpid(m_pid, NULL, WALLSIG)) < 0)
return Status(errno, eErrorTypePOSIX);
@@ -871,13 +872,13 @@ NativeProcessNetBSD::GetAuxvData() const {
*/
size_t auxv_size = 100 * sizeof(AuxInfo);
- ErrorOr<std::unique_ptr<MemoryBuffer>> buf =
- llvm::MemoryBuffer::getNewMemBuffer(auxv_size);
+ ErrorOr<std::unique_ptr<WritableMemoryBuffer>> buf =
+ llvm::WritableMemoryBuffer::getNewMemBuffer(auxv_size);
struct ptrace_io_desc io;
io.piod_op = PIOD_READ_AUXV;
io.piod_offs = 0;
- io.piod_addr = const_cast<void *>(static_cast<const void *>(buf.get()->getBufferStart()));
+ io.piod_addr = static_cast<void *>(buf.get()->getBufferStart());
io.piod_len = auxv_size;
Status error = NativeProcessNetBSD::PtraceWrapper(PT_IO, GetID(), &io);
@@ -888,7 +889,7 @@ NativeProcessNetBSD::GetAuxvData() const {
if (io.piod_len < 1)
return std::error_code(ECANCELED, std::generic_category());
- return buf;
+ return std::move(buf);
}
Status NativeProcessNetBSD::ReinitializeThreads() {
diff --git a/source/Plugins/Process/NetBSD/NativeProcessNetBSD.h b/source/Plugins/Process/NetBSD/NativeProcessNetBSD.h
index 7090fce34fc9c..142f74ecf1947 100644
--- a/source/Plugins/Process/NetBSD/NativeProcessNetBSD.h
+++ b/source/Plugins/Process/NetBSD/NativeProcessNetBSD.h
@@ -20,10 +20,10 @@
namespace lldb_private {
namespace process_netbsd {
/// @class NativeProcessNetBSD
-/// @brief Manages communication with the inferior (debugee) process.
+/// Manages communication with the inferior (debugee) process.
///
-/// Upon construction, this class prepares and launches an inferior process for
-/// debugging.
+/// Upon construction, this class prepares and launches an inferior process
+/// for debugging.
///
/// Changes in the inferior process state are broadcasted.
class NativeProcessNetBSD : public NativeProcessProtocol {
diff --git a/source/Plugins/Process/NetBSD/NativeRegisterContextNetBSD_x86_64.cpp b/source/Plugins/Process/NetBSD/NativeRegisterContextNetBSD_x86_64.cpp
index 347c15ae5b239..16b6f2c52dd5e 100644
--- a/source/Plugins/Process/NetBSD/NativeRegisterContextNetBSD_x86_64.cpp
+++ b/source/Plugins/Process/NetBSD/NativeRegisterContextNetBSD_x86_64.cpp
@@ -161,8 +161,8 @@ static RegisterInfoInterface *
CreateRegisterInfoInterface(const ArchSpec &target_arch) {
assert((HostInfo::GetArchitecture().GetAddressByteSize() == 8) &&
"Register setting path assumes this is a 64-bit host");
- // X86_64 hosts know how to work with 64-bit and 32-bit EXEs using the
- // x86_64 register context.
+ // X86_64 hosts know how to work with 64-bit and 32-bit EXEs using the x86_64
+ // register context.
return new RegisterContextNetBSD_x86_64(target_arch);
}
@@ -805,8 +805,7 @@ Status NativeRegisterContextNetBSD_x86_64::SetHardwareWatchpointWithIndex(
if (error.Fail())
return error;
- // for watchpoints 0, 1, 2, or 3, respectively,
- // set bits 1, 3, 5, or 7
+ // for watchpoints 0, 1, 2, or 3, respectively, set bits 1, 3, 5, or 7
uint64_t enable_bit = 1 << (2 * wp_index);
// set bits 16-17, 20-21, 24-25, or 28-29
@@ -845,8 +844,8 @@ bool NativeRegisterContextNetBSD_x86_64::ClearHardwareWatchpoint(
RegisterValue reg_value;
- // for watchpoints 0, 1, 2, or 3, respectively,
- // clear bits 0, 1, 2, or 3 of the debug status register (DR6)
+ // for watchpoints 0, 1, 2, or 3, respectively, clear bits 0, 1, 2, or 3 of
+ // the debug status register (DR6)
const RegisterInfo *const reg_info_dr6 =
GetRegisterInfoAtIndex(lldb_dr6_x86_64);
Status error = ReadRegister(reg_info_dr6, reg_value);
@@ -858,9 +857,9 @@ bool NativeRegisterContextNetBSD_x86_64::ClearHardwareWatchpoint(
if (error.Fail())
return false;
- // for watchpoints 0, 1, 2, or 3, respectively,
- // clear bits {0-1,16-19}, {2-3,20-23}, {4-5,24-27}, or {6-7,28-31}
- // of the debug control register (DR7)
+ // for watchpoints 0, 1, 2, or 3, respectively, clear bits {0-1,16-19},
+ // {2-3,20-23}, {4-5,24-27}, or {6-7,28-31} of the debug control register
+ // (DR7)
const RegisterInfo *const reg_info_dr7 =
GetRegisterInfoAtIndex(lldb_dr7_x86_64);
error = ReadRegister(reg_info_dr7, reg_value);
diff --git a/source/Plugins/Process/POSIX/CMakeLists.txt b/source/Plugins/Process/POSIX/CMakeLists.txt
index d9a4508df0a34..f058e01c74394 100644
--- a/source/Plugins/Process/POSIX/CMakeLists.txt
+++ b/source/Plugins/Process/POSIX/CMakeLists.txt
@@ -1,6 +1,3 @@
-include_directories(.)
-include_directories(../Utility)
-
add_lldb_library(lldbPluginProcessPOSIX PLUGIN
CrashReason.cpp
ProcessMessage.cpp
diff --git a/source/Plugins/Process/POSIX/CrashReason.cpp b/source/Plugins/Process/POSIX/CrashReason.cpp
index 864418c900310..4b24d31226a99 100644
--- a/source/Plugins/Process/POSIX/CrashReason.cpp
+++ b/source/Plugins/Process/POSIX/CrashReason.cpp
@@ -47,8 +47,7 @@ CrashReason GetCrashReasonForSIGSEGV(const siginfo_t &info) {
#ifdef SI_KERNEL
case SI_KERNEL:
// Some platforms will occasionally send nonstandard spurious SI_KERNEL
- // codes.
- // One way to get this is via unaligned SIMD loads.
+ // codes. One way to get this is via unaligned SIMD loads.
return CrashReason::eInvalidAddress; // for lack of anything better
#endif
case SEGV_MAPERR:
diff --git a/source/Plugins/Process/Utility/CMakeLists.txt b/source/Plugins/Process/Utility/CMakeLists.txt
index 3780fb5e4c18d..b43756acea634 100644
--- a/source/Plugins/Process/Utility/CMakeLists.txt
+++ b/source/Plugins/Process/Utility/CMakeLists.txt
@@ -1,5 +1,3 @@
-include_directories(../../../Utility/)
-
add_lldb_library(lldbPluginProcessUtility PLUGIN
DynamicRegisterInfo.cpp
FreeBSDSignals.cpp
@@ -60,7 +58,6 @@ add_lldb_library(lldbPluginProcessUtility PLUGIN
lldbSymbol
lldbTarget
lldbUtility
- lldbPluginProcessElfCore
LINK_COMPONENTS
Support
)
diff --git a/source/Plugins/Process/Utility/DynamicRegisterInfo.cpp b/source/Plugins/Process/Utility/DynamicRegisterInfo.cpp
index 61e5bf4481d6a..5f34e9915edee 100644
--- a/source/Plugins/Process/Utility/DynamicRegisterInfo.cpp
+++ b/source/Plugins/Process/Utility/DynamicRegisterInfo.cpp
@@ -12,6 +12,7 @@
#include "lldb/Core/StreamFile.h"
#include "lldb/DataFormatters/FormatManager.h"
#include "lldb/Host/StringConvert.h"
+#include "lldb/Interpreter/OptionArgParser.h"
#include "lldb/Utility/ArchSpec.h"
#include "lldb/Utility/RegularExpression.h"
#include "lldb/Utility/StringExtractor.h"
@@ -20,21 +21,42 @@
using namespace lldb;
using namespace lldb_private;
-DynamicRegisterInfo::DynamicRegisterInfo()
- : m_regs(), m_sets(), m_set_reg_nums(), m_set_names(), m_value_regs_map(),
- m_invalidate_regs_map(), m_dynamic_reg_size_map(),
- m_reg_data_byte_size(0), m_finalized(false) {}
-
DynamicRegisterInfo::DynamicRegisterInfo(
const lldb_private::StructuredData::Dictionary &dict,
- const lldb_private::ArchSpec &arch)
- : m_regs(), m_sets(), m_set_reg_nums(), m_set_names(), m_value_regs_map(),
- m_invalidate_regs_map(), m_dynamic_reg_size_map(),
- m_reg_data_byte_size(0), m_finalized(false) {
+ const lldb_private::ArchSpec &arch) {
SetRegisterInfo(dict, arch);
}
-DynamicRegisterInfo::~DynamicRegisterInfo() {}
+DynamicRegisterInfo::DynamicRegisterInfo(DynamicRegisterInfo &&info) {
+ MoveFrom(std::move(info));
+}
+
+DynamicRegisterInfo &
+DynamicRegisterInfo::operator=(DynamicRegisterInfo &&info) {
+ MoveFrom(std::move(info));
+ return *this;
+}
+
+void DynamicRegisterInfo::MoveFrom(DynamicRegisterInfo &&info) {
+ m_regs = std::move(info.m_regs);
+ m_sets = std::move(info.m_sets);
+ m_set_reg_nums = std::move(info.m_set_reg_nums);
+ m_set_names = std::move(info.m_set_names);
+ m_value_regs_map = std::move(info.m_value_regs_map);
+ m_invalidate_regs_map = std::move(info.m_invalidate_regs_map);
+ m_dynamic_reg_size_map = std::move(info.m_dynamic_reg_size_map);
+
+ m_reg_data_byte_size = info.m_reg_data_byte_size;
+ m_finalized = info.m_finalized;
+
+ if (m_finalized) {
+ const size_t num_sets = m_sets.size();
+ for (size_t set = 0; set < num_sets; ++set)
+ m_sets[set].registers = m_set_reg_nums[set].data();
+ }
+
+ info.Clear();
+}
size_t
DynamicRegisterInfo::SetRegisterInfo(const StructuredData::Dictionary &dict,
@@ -44,13 +66,9 @@ DynamicRegisterInfo::SetRegisterInfo(const StructuredData::Dictionary &dict,
if (dict.GetValueForKeyAsArray("sets", sets)) {
const uint32_t num_sets = sets->GetSize();
for (uint32_t i = 0; i < num_sets; ++i) {
- llvm::StringRef set_name_str;
ConstString set_name;
- if (sets->GetItemAtIndexAsString(i, set_name_str))
- set_name.SetString(set_name_str);
- if (set_name) {
- RegisterSet new_set = {set_name.AsCString(), NULL, 0, NULL};
- m_sets.push_back(new_set);
+ if (sets->GetItemAtIndexAsString(i, set_name) && !set_name.IsEmpty()) {
+ m_sets.push_back({ set_name.AsCString(), NULL, 0, NULL });
} else {
Clear();
printf("error: register sets must have valid names\n");
@@ -59,6 +77,7 @@ DynamicRegisterInfo::SetRegisterInfo(const StructuredData::Dictionary &dict,
}
m_set_reg_nums.resize(m_sets.size());
}
+
StructuredData::Array *regs = nullptr;
if (!dict.GetValueForKeyAsArray("registers", regs))
return 0;
@@ -76,8 +95,8 @@ DynamicRegisterInfo::SetRegisterInfo(const StructuredData::Dictionary &dict,
return 0;
}
- // { 'name':'rcx' , 'bitsize' : 64, 'offset' : 16, 'encoding':'uint'
- // , 'format':'hex' , 'set': 0, 'ehframe' : 2,
+ // { 'name':'rcx' , 'bitsize' : 64, 'offset' : 16,
+ // 'encoding':'uint' , 'format':'hex' , 'set': 0, 'ehframe' : 2,
// 'dwarf' : 2, 'generic':'arg4', 'alt-name':'arg4', },
RegisterInfo reg_info;
std::vector<uint32_t> value_regs;
@@ -102,14 +121,11 @@ DynamicRegisterInfo::SetRegisterInfo(const StructuredData::Dictionary &dict,
const ByteOrder byte_order = arch.GetByteOrder();
if (reg_info.byte_offset == UINT32_MAX) {
- // No offset for this register, see if the register has a value expression
- // which indicates this register is part of another register. Value
- // expressions
- // are things like "rax[31:0]" which state that the current register's
- // value
- // is in a concrete register "rax" in bits 31:0. If there is a value
- // expression
- // we can calculate the offset
+ // No offset for this register, see if the register has a value
+ // expression which indicates this register is part of another register.
+ // Value expressions are things like "rax[31:0]" which state that the
+ // current register's value is in a concrete register "rax" in bits 31:0.
+ // If there is a value expression we can calculate the offset
bool success = false;
llvm::StringRef slice_str;
if (reg_info_dict->GetValueForKeyAsString("slice", slice_str, nullptr)) {
@@ -141,7 +157,7 @@ DynamicRegisterInfo::SetRegisterInfo(const StructuredData::Dictionary &dict,
ConstString containing_reg_name(reg_name_str);
- RegisterInfo *containing_reg_info =
+ const RegisterInfo *containing_reg_info =
GetRegisterInfo(containing_reg_name);
if (containing_reg_info) {
const uint32_t max_bit = containing_reg_info->byte_size * 8;
@@ -210,7 +226,7 @@ DynamicRegisterInfo::SetRegisterInfo(const StructuredData::Dictionary &dict,
ConstString composite_reg_name;
if (composite_reg_list->GetItemAtIndexAsString(
composite_idx, composite_reg_name, nullptr)) {
- RegisterInfo *composite_reg_info =
+ const RegisterInfo *composite_reg_info =
GetRegisterInfo(composite_reg_name);
if (composite_reg_info) {
composite_offset = std::min(composite_offset,
@@ -286,7 +302,8 @@ DynamicRegisterInfo::SetRegisterInfo(const StructuredData::Dictionary &dict,
llvm::StringRef format_str;
if (reg_info_dict->GetValueForKeyAsString("format", format_str, nullptr)) {
- if (Args::StringToFormat(format_str.str().c_str(), reg_info.format, NULL)
+ if (OptionArgParser::ToFormat(format_str.str().c_str(), reg_info.format,
+ NULL)
.Fail()) {
Clear();
printf("error: invalid 'format' value in register dictionary\n");
@@ -349,7 +366,7 @@ DynamicRegisterInfo::SetRegisterInfo(const StructuredData::Dictionary &dict,
uint64_t invalidate_reg_num;
if (invalidate_reg_list->GetItemAtIndexAsString(
idx, invalidate_reg_name)) {
- RegisterInfo *invalidate_reg_info =
+ const RegisterInfo *invalidate_reg_info =
GetRegisterInfo(invalidate_reg_name);
if (invalidate_reg_info) {
m_invalidate_regs_map[i].push_back(
@@ -437,7 +454,7 @@ void DynamicRegisterInfo::Finalize(const ArchSpec &arch) {
for (size_t set = 0; set < num_sets; ++set) {
assert(m_sets.size() == m_set_reg_nums.size());
m_sets[set].num_registers = m_set_reg_nums[set].size();
- m_sets[set].registers = &m_set_reg_nums[set][0];
+ m_sets[set].registers = m_set_reg_nums[set].data();
}
// sort and unique all value registers and make sure each is terminated with
@@ -492,8 +509,7 @@ void DynamicRegisterInfo::Finalize(const ArchSpec &arch) {
}
// sort and unique all invalidate registers and make sure each is terminated
- // with
- // LLDB_INVALID_REGNUM
+ // with LLDB_INVALID_REGNUM
for (reg_to_regs_map::iterator pos = m_invalidate_regs_map.begin(),
end = m_invalidate_regs_map.end();
pos != end; ++pos) {
@@ -517,8 +533,8 @@ void DynamicRegisterInfo::Finalize(const ArchSpec &arch) {
m_regs[i].invalidate_regs = NULL;
}
- // Check if we need to automatically set the generic registers in case
- // they weren't set
+ // Check if we need to automatically set the generic registers in case they
+ // weren't set
bool generic_regs_specified = false;
for (const auto &reg : m_regs) {
if (reg.kinds[eRegisterKindGeneric] != LLDB_INVALID_REGNUM) {
@@ -730,11 +746,11 @@ void DynamicRegisterInfo::Dump() const {
}
}
-lldb_private::RegisterInfo *DynamicRegisterInfo::GetRegisterInfo(
- const lldb_private::ConstString &reg_name) {
+const lldb_private::RegisterInfo *DynamicRegisterInfo::GetRegisterInfo(
+ const lldb_private::ConstString &reg_name) const {
for (auto &reg_info : m_regs) {
- // We can use pointer comparison since we used a ConstString to set
- // the "name" member in AddRegister()
+ // We can use pointer comparison since we used a ConstString to set the
+ // "name" member in AddRegister()
if (reg_info.name == reg_name.GetCString()) {
return &reg_info;
}
diff --git a/source/Plugins/Process/Utility/DynamicRegisterInfo.h b/source/Plugins/Process/Utility/DynamicRegisterInfo.h
index 228acfbed4eee..acb3e3eb8a84e 100644
--- a/source/Plugins/Process/Utility/DynamicRegisterInfo.h
+++ b/source/Plugins/Process/Utility/DynamicRegisterInfo.h
@@ -23,12 +23,18 @@
class DynamicRegisterInfo {
public:
- DynamicRegisterInfo();
+ DynamicRegisterInfo() = default;
DynamicRegisterInfo(const lldb_private::StructuredData::Dictionary &dict,
const lldb_private::ArchSpec &arch);
- virtual ~DynamicRegisterInfo();
+ virtual ~DynamicRegisterInfo() = default;
+
+ DynamicRegisterInfo(DynamicRegisterInfo &) = delete;
+ void operator=(DynamicRegisterInfo &) = delete;
+
+ DynamicRegisterInfo(DynamicRegisterInfo &&info);
+ DynamicRegisterInfo &operator=(DynamicRegisterInfo &&info);
size_t SetRegisterInfo(const lldb_private::StructuredData::Dictionary &dict,
const lldb_private::ArchSpec &arch);
@@ -75,8 +81,10 @@ protected:
typedef std::vector<uint8_t> dwarf_opcode;
typedef std::map<uint32_t, dwarf_opcode> dynamic_reg_size_map;
- lldb_private::RegisterInfo *
- GetRegisterInfo(const lldb_private::ConstString &reg_name);
+ const lldb_private::RegisterInfo *
+ GetRegisterInfo(const lldb_private::ConstString &reg_name) const;
+
+ void MoveFrom(DynamicRegisterInfo &&info);
reg_collection m_regs;
set_collection m_sets;
@@ -85,9 +93,8 @@ protected:
reg_to_regs_map m_value_regs_map;
reg_to_regs_map m_invalidate_regs_map;
dynamic_reg_size_map m_dynamic_reg_size_map;
- size_t m_reg_data_byte_size; // The number of bytes required to store all
- // registers
- bool m_finalized;
+ size_t m_reg_data_byte_size = 0u; // The number of bytes required to store
+ // all registers
+ bool m_finalized = false;
};
-
#endif // lldb_DynamicRegisterInfo_h_
diff --git a/source/Plugins/Process/Utility/HistoryThread.h b/source/Plugins/Process/Utility/HistoryThread.h
index 363ba26696377..7675a95246a7e 100644
--- a/source/Plugins/Process/Utility/HistoryThread.h
+++ b/source/Plugins/Process/Utility/HistoryThread.h
@@ -29,13 +29,13 @@ namespace lldb_private {
//----------------------------------------------------------------------
/// @class HistoryThread HistoryThread.h "HistoryThread.h"
-/// @brief A thread object representing a backtrace from a previous point in the
+/// A thread object representing a backtrace from a previous point in the
/// process execution
///
/// This subclass of Thread is used to provide a backtrace from earlier in
/// process execution. It is given a backtrace list of pc addresses and
-/// optionally a stop_id of when those pc addresses were collected, and it will
-/// create stack frames for them.
+/// optionally a stop_id of when those pc addresses were collected, and it
+/// will create stack frames for them.
//----------------------------------------------------------------------
class HistoryThread : public lldb_private::Thread {
diff --git a/source/Plugins/Process/Utility/InstructionUtils.h b/source/Plugins/Process/Utility/InstructionUtils.h
index e422a96200c80..186d525ce499c 100644
--- a/source/Plugins/Process/Utility/InstructionUtils.h
+++ b/source/Plugins/Process/Utility/InstructionUtils.h
@@ -10,6 +10,9 @@
#ifndef lldb_InstructionUtils_h_
#define lldb_InstructionUtils_h_
+#include <cassert>
+#include <cstdint>
+
// Common utilities for manipulating instruction bit fields.
namespace lldb_private {
diff --git a/source/Plugins/Process/Utility/RegisterContextDarwinConstants.h b/source/Plugins/Process/Utility/RegisterContextDarwinConstants.h
new file mode 100644
index 0000000000000..ff57464be2def
--- /dev/null
+++ b/source/Plugins/Process/Utility/RegisterContextDarwinConstants.h
@@ -0,0 +1,26 @@
+//===-- RegisterContextDarwinConstants.h ------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLDB_REGISTERCONTEXTDARWINCONSTANTS_H
+#define LLDB_REGISTERCONTEXTDARWINCONSTANTS_H
+
+namespace lldb_private {
+
+/// Constants returned by various RegisterContextDarwin_*** functions.
+#ifndef KERN_SUCCESS
+#define KERN_SUCCESS 0
+#endif
+
+#ifndef KERN_INVALID_ARGUMENT
+#define KERN_INVALID_ARGUMENT 4
+#endif
+
+} // namespace lldb_private
+
+#endif // LLDB_REGISTERCONTEXTDARWINCONSTANTS_H
diff --git a/source/Plugins/Process/Utility/RegisterContextDarwin_arm.cpp b/source/Plugins/Process/Utility/RegisterContextDarwin_arm.cpp
index 64a697ff53c89..5d9ff02fafdd2 100644
--- a/source/Plugins/Process/Utility/RegisterContextDarwin_arm.cpp
+++ b/source/Plugins/Process/Utility/RegisterContextDarwin_arm.cpp
@@ -7,13 +7,8 @@
//
//===----------------------------------------------------------------------===//
-#if defined(__APPLE__)
-
#include "RegisterContextDarwin_arm.h"
-
-// C Includes
-#include <mach/mach_types.h>
-#include <mach/thread_act.h>
+#include "RegisterContextDarwinConstants.h"
// C++ Includes
// Other libraries and framework includes
@@ -34,7 +29,7 @@
#endif
// Project includes
-#include "ARM_DWARF_Registers.h"
+#include "Utility/ARM_DWARF_Registers.h"
#include "Utility/ARM_ehframe_Registers.h"
#include "llvm/ADT/STLExtras.h"
@@ -968,9 +963,9 @@ const size_t k_num_fpu_registers = llvm::array_lengthof(g_fpu_regnums);
const size_t k_num_exc_registers = llvm::array_lengthof(g_exc_regnums);
//----------------------------------------------------------------------
-// Register set definitions. The first definitions at register set index
-// of zero is for all registers, followed by other registers sets. The
-// register information for the all register set need not be filled in.
+// Register set definitions. The first definitions at register set index of
+// zero is for all registers, followed by other registers sets. The register
+// information for the all register set need not be filled in.
//----------------------------------------------------------------------
static const RegisterSet g_reg_sets[] = {
{
@@ -1510,7 +1505,7 @@ uint32_t RegisterContextDarwin_arm::ConvertRegisterKindToRegisterNumber(
}
uint32_t RegisterContextDarwin_arm::NumSupportedHardwareBreakpoints() {
-#if defined(__arm__)
+#if defined(__APPLE__) && defined(__arm__)
// Set the init value to something that will let us know that we need to
// autodetect how many breakpoints are supported dynamically...
static uint32_t g_num_supported_hw_breakpoints = UINT32_MAX;
@@ -1642,7 +1637,7 @@ bool RegisterContextDarwin_arm::ClearHardwareBreakpoint(uint32_t hw_index) {
}
uint32_t RegisterContextDarwin_arm::NumSupportedHardwareWatchpoints() {
-#if defined(__arm__)
+#if defined(__APPLE__) && defined(__arm__)
// Set the init value to something that will let us know that we need to
// autodetect how many watchpoints are supported dynamically...
static uint32_t g_num_supported_hw_watchpoints = UINT32_MAX;
@@ -1766,5 +1761,3 @@ bool RegisterContextDarwin_arm::ClearHardwareWatchpoint(uint32_t hw_index) {
}
return false;
}
-
-#endif
diff --git a/source/Plugins/Process/Utility/RegisterContextDarwin_arm64.cpp b/source/Plugins/Process/Utility/RegisterContextDarwin_arm64.cpp
index 344c08965fad5..03ce7ef9f5240 100644
--- a/source/Plugins/Process/Utility/RegisterContextDarwin_arm64.cpp
+++ b/source/Plugins/Process/Utility/RegisterContextDarwin_arm64.cpp
@@ -8,14 +8,8 @@
//
//===----------------------------------------------------------------------===//
-#if defined(__APPLE__)
-
#include "RegisterContextDarwin_arm64.h"
-
-// C Includes
-#include <mach/mach_types.h>
-#include <mach/thread_act.h>
-#include <sys/sysctl.h>
+#include "RegisterContextDarwinConstants.h"
// C++ Includes
// Other libraries and framework includes
@@ -39,7 +33,7 @@
#endif
// Project includes
-#include "ARM64_DWARF_Registers.h"
+#include "Utility/ARM64_DWARF_Registers.h"
using namespace lldb;
using namespace lldb_private;
@@ -149,9 +143,9 @@ const size_t k_num_fpu_registers = llvm::array_lengthof(g_fpu_regnums);
const size_t k_num_exc_registers = llvm::array_lengthof(g_exc_regnums);
//----------------------------------------------------------------------
-// Register set definitions. The first definitions at register set index
-// of zero is for all registers, followed by other registers sets. The
-// register information for the all register set need not be filled in.
+// Register set definitions. The first definitions at register set index of
+// zero is for all registers, followed by other registers sets. The register
+// information for the all register set need not be filled in.
//----------------------------------------------------------------------
static const RegisterSet g_reg_sets[] = {
{
@@ -299,8 +293,9 @@ int RegisterContextDarwin_arm64::WriteRegisterSet(uint32_t set) {
void RegisterContextDarwin_arm64::LogDBGRegisters(Log *log, const DBG &dbg) {
if (log) {
for (uint32_t i = 0; i < 16; i++)
- log->Printf("BVR%-2u/BCR%-2u = { 0x%8.8llx, 0x%8.8llx } WVR%-2u/WCR%-2u "
- "= { 0x%8.8llx, 0x%8.8llx }",
+ log->Printf("BVR%-2u/BCR%-2u = { 0x%8.8" PRIu64 ", 0x%8.8" PRIu64
+ " } WVR%-2u/WCR%-2u "
+ "= { 0x%8.8" PRIu64 ", 0x%8.8" PRIu64 " }",
i, i, dbg.bvr[i], dbg.bcr[i], i, i, dbg.wvr[i], dbg.wcr[i]);
}
}
@@ -921,7 +916,7 @@ uint32_t RegisterContextDarwin_arm64::ConvertRegisterKindToRegisterNumber(
}
uint32_t RegisterContextDarwin_arm64::NumSupportedHardwareWatchpoints() {
-#if defined(__arm64__) || defined(__aarch64__)
+#if defined(__APPLE__) && (defined(__arm64__) || defined(__aarch64__))
// autodetect how many watchpoints are supported dynamically...
static uint32_t g_num_supported_hw_watchpoints = UINT32_MAX;
if (g_num_supported_hw_watchpoints == UINT32_MAX) {
@@ -1043,5 +1038,3 @@ bool RegisterContextDarwin_arm64::ClearHardwareWatchpoint(uint32_t hw_index) {
}
return false;
}
-
-#endif
diff --git a/source/Plugins/Process/Utility/RegisterContextDarwin_i386.cpp b/source/Plugins/Process/Utility/RegisterContextDarwin_i386.cpp
index c818fad9ac0e5..24414211d9aa8 100644
--- a/source/Plugins/Process/Utility/RegisterContextDarwin_i386.cpp
+++ b/source/Plugins/Process/Utility/RegisterContextDarwin_i386.cpp
@@ -147,9 +147,9 @@ enum {
sizeof(RegisterContextDarwin_i386::FPU))
// These macros will auto define the register name, alt name, register size,
-// register offset, encoding, format and native register. This ensures that
-// the register state structures are defined correctly and have the correct
-// sizes and offsets.
+// register offset, encoding, format and native register. This ensures that the
+// register state structures are defined correctly and have the correct sizes
+// and offsets.
#define DEFINE_GPR(reg, alt) \
#reg, alt, sizeof(((RegisterContextDarwin_i386::GPR *) NULL)->reg), \
GPR_OFFSET(reg), eEncodingUint, eFormatHex
@@ -464,9 +464,9 @@ const size_t k_num_fpu_registers = llvm::array_lengthof(g_fpu_regnums);
const size_t k_num_exc_registers = llvm::array_lengthof(g_exc_regnums);
//----------------------------------------------------------------------
-// Register set definitions. The first definitions at register set index
-// of zero is for all registers, followed by other registers sets. The
-// register information for the all register set need not be filled in.
+// Register set definitions. The first definitions at register set index of
+// zero is for all registers, followed by other registers sets. The register
+// information for the all register set need not be filled in.
//----------------------------------------------------------------------
static const RegisterSet g_reg_sets[] = {
{
@@ -680,8 +680,7 @@ bool RegisterContextDarwin_i386::ReadRegister(const RegisterInfo *reg_info,
case fpu_stmm6:
case fpu_stmm7:
// These values don't fit into scalar types,
- // RegisterContext::ReadRegisterBytes() must be used for these
- // registers
+ // RegisterContext::ReadRegisterBytes() must be used for these registers
//::memcpy (reg_value.value.vector.uint8, fpu.stmm[reg - fpu_stmm0].bytes,
//10);
return false;
@@ -695,8 +694,7 @@ bool RegisterContextDarwin_i386::ReadRegister(const RegisterInfo *reg_info,
case fpu_xmm6:
case fpu_xmm7:
// These values don't fit into scalar types,
- // RegisterContext::ReadRegisterBytes()
- // must be used for these registers
+ // RegisterContext::ReadRegisterBytes() must be used for these registers
//::memcpy (reg_value.value.vector.uint8, fpu.xmm[reg - fpu_xmm0].bytes,
//16);
return false;
@@ -799,8 +797,7 @@ bool RegisterContextDarwin_i386::WriteRegister(const RegisterInfo *reg_info,
case fpu_stmm6:
case fpu_stmm7:
// These values don't fit into scalar types,
- // RegisterContext::ReadRegisterBytes()
- // must be used for these registers
+ // RegisterContext::ReadRegisterBytes() must be used for these registers
::memcpy(fpu.stmm[reg - fpu_stmm0].bytes, value.GetBytes(),
value.GetByteSize());
return false;
@@ -814,8 +811,7 @@ bool RegisterContextDarwin_i386::WriteRegister(const RegisterInfo *reg_info,
case fpu_xmm6:
case fpu_xmm7:
// These values don't fit into scalar types,
- // RegisterContext::ReadRegisterBytes()
- // must be used for these registers
+ // RegisterContext::ReadRegisterBytes() must be used for these registers
::memcpy(fpu.xmm[reg - fpu_xmm0].bytes, value.GetBytes(),
value.GetByteSize());
return false;
diff --git a/source/Plugins/Process/Utility/RegisterContextDarwin_x86_64.cpp b/source/Plugins/Process/Utility/RegisterContextDarwin_x86_64.cpp
index 50e7292f86b1c..ecad8240b2944 100644
--- a/source/Plugins/Process/Utility/RegisterContextDarwin_x86_64.cpp
+++ b/source/Plugins/Process/Utility/RegisterContextDarwin_x86_64.cpp
@@ -165,9 +165,9 @@ enum ehframe_dwarf_regnums {
sizeof(RegisterContextDarwin_x86_64::FPU))
// These macros will auto define the register name, alt name, register size,
-// register offset, encoding, format and native register. This ensures that
-// the register state structures are defined correctly and have the correct
-// sizes and offsets.
+// register offset, encoding, format and native register. This ensures that the
+// register state structures are defined correctly and have the correct sizes
+// and offsets.
#define DEFINE_GPR(reg, alt) \
#reg, alt, sizeof(((RegisterContextDarwin_x86_64::GPR *) NULL)->reg), \
GPR_OFFSET(reg), eEncodingUint, eFormatHex
@@ -525,9 +525,9 @@ const size_t k_num_fpu_registers = llvm::array_lengthof(g_fpu_regnums);
const size_t k_num_exc_registers = llvm::array_lengthof(g_exc_regnums);
//----------------------------------------------------------------------
-// Register set definitions. The first definitions at register set index
-// of zero is for all registers, followed by other registers sets. The
-// register information for the all register set need not be filled in.
+// Register set definitions. The first definitions at register set index of
+// zero is for all registers, followed by other registers sets. The register
+// information for the all register set need not be filled in.
//----------------------------------------------------------------------
static const RegisterSet g_reg_sets[] = {
{
diff --git a/source/Plugins/Process/Utility/RegisterContextLLDB.cpp b/source/Plugins/Process/Utility/RegisterContextLLDB.cpp
index 5435a02433aba..ba9a8071bcfbc 100644
--- a/source/Plugins/Process/Utility/RegisterContextLLDB.cpp
+++ b/source/Plugins/Process/Utility/RegisterContextLLDB.cpp
@@ -104,8 +104,7 @@ bool RegisterContextLLDB::IsUnwindPlanValidForCurrentPC(
}
// Initialize a RegisterContextLLDB which is the first frame of a stack -- the
-// zeroth frame or currently
-// executing frame.
+// zeroth frame or currently executing frame.
void RegisterContextLLDB::InitializeZerothFrame() {
Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_UNWIND));
@@ -131,25 +130,26 @@ void RegisterContextLLDB::InitializeZerothFrame() {
// Let ABIs fixup code addresses to make sure they are valid. In ARM ABIs
// this will strip bit zero in case we read a PC from memory or from the LR.
// (which would be a no-op in frame 0 where we get it from the register set,
- // but still a good idea to make the call here for other ABIs that may exist.)
+ // but still a good idea to make the call here for other ABIs that may
+ // exist.)
ABI *abi = process->GetABI().get();
if (abi)
current_pc = abi->FixCodeAddress(current_pc);
- // Initialize m_current_pc, an Address object, based on current_pc, an addr_t.
+ // Initialize m_current_pc, an Address object, based on current_pc, an
+ // addr_t.
m_current_pc.SetLoadAddress(current_pc, &process->GetTarget());
// If we don't have a Module for some reason, we're not going to find
- // symbol/function information - just
- // stick in some reasonable defaults and hope we can unwind past this frame.
+ // symbol/function information - just stick in some reasonable defaults and
+ // hope we can unwind past this frame.
ModuleSP pc_module_sp(m_current_pc.GetModule());
if (!m_current_pc.IsValid() || !pc_module_sp) {
UnwindLogMsg("using architectural default unwind method");
}
// We require either a symbol or function in the symbols context to be
- // successfully
- // filled in or this context is of no use to us.
+ // successfully filled in or this context is of no use to us.
const uint32_t resolve_scope = eSymbolContextFunction | eSymbolContextSymbol;
if (pc_module_sp.get() && (pc_module_sp->ResolveSymbolContextForAddress(
m_current_pc, resolve_scope, m_sym_ctx) &
@@ -180,18 +180,17 @@ void RegisterContextLLDB::InitializeZerothFrame() {
}
// If we were able to find a symbol/function, set addr_range to the bounds of
- // that symbol/function.
- // else treat the current pc value as the start_pc and record no offset.
+ // that symbol/function. else treat the current pc value as the start_pc and
+ // record no offset.
if (addr_range.GetBaseAddress().IsValid()) {
m_start_pc = addr_range.GetBaseAddress();
if (m_current_pc.GetSection() == m_start_pc.GetSection()) {
m_current_offset = m_current_pc.GetOffset() - m_start_pc.GetOffset();
} else if (m_current_pc.GetModule() == m_start_pc.GetModule()) {
- // This means that whatever symbol we kicked up isn't really correct
- // --- we should not cross section boundaries ... We really should NULL
- // out
- // the function/symbol in this case unless there is a bad assumption
- // here due to inlined functions?
+ // This means that whatever symbol we kicked up isn't really correct ---
+ // we should not cross section boundaries ... We really should NULL out
+ // the function/symbol in this case unless there is a bad assumption here
+ // due to inlined functions?
m_current_offset =
m_current_pc.GetFileAddress() - m_start_pc.GetFileAddress();
}
@@ -266,8 +265,7 @@ void RegisterContextLLDB::InitializeZerothFrame() {
}
// Initialize a RegisterContextLLDB for the non-zeroth frame -- rely on the
-// RegisterContextLLDB "below" it
-// to provide things like its current pc value.
+// RegisterContextLLDB "below" it to provide things like its current pc value.
void RegisterContextLLDB::InitializeNonZerothFrame() {
Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_UNWIND));
@@ -333,8 +331,8 @@ void RegisterContextLLDB::InitializeNonZerothFrame() {
m_current_pc.SetLoadAddress(pc, &process->GetTarget(), allow_section_end);
// If we don't have a Module for some reason, we're not going to find
- // symbol/function information - just
- // stick in some reasonable defaults and hope we can unwind past this frame.
+ // symbol/function information - just stick in some reasonable defaults and
+ // hope we can unwind past this frame.
ModuleSP pc_module_sp(m_current_pc.GetModule());
if (!m_current_pc.IsValid() || !pc_module_sp) {
UnwindLogMsg("using architectural default unwind method");
@@ -345,12 +343,10 @@ void RegisterContextLLDB::InitializeNonZerothFrame() {
if (process->GetLoadAddressPermissions(pc, permissions) &&
(permissions & ePermissionsExecutable) == 0) {
// If this is the second frame off the stack, we may have unwound the
- // first frame
- // incorrectly. But using the architecture default unwind plan may get us
- // back on
- // track -- albeit possibly skipping a real frame. Give this frame a
- // clearly-invalid
- // pc and see if we can get any further.
+ // first frame incorrectly. But using the architecture default unwind
+ // plan may get us back on track -- albeit possibly skipping a real
+ // frame. Give this frame a clearly-invalid pc and see if we can get any
+ // further.
if (GetNextFrame().get() && GetNextFrame()->IsValid() &&
GetNextFrame()->IsFrameZero()) {
UnwindLogMsg("had a pc of 0x%" PRIx64 " which is not in executable "
@@ -359,8 +355,8 @@ void RegisterContextLLDB::InitializeNonZerothFrame() {
(uint64_t)pc);
m_frame_type = eSkipFrame;
} else {
- // anywhere other than the second frame, a non-executable pc means we're
- // off in the weeds -- stop now.
+ // anywhere other than the second frame, a non-executable pc means
+ // we're off in the weeds -- stop now.
m_frame_type = eNotAValidFrame;
UnwindLogMsg("pc is in a non-executable section of memory and this "
"isn't the 2nd frame in the stack walk.");
@@ -399,8 +395,7 @@ void RegisterContextLLDB::InitializeNonZerothFrame() {
}
// m_cfa should point into the stack memory; if we can query memory
- // region permissions,
- // see if the memory is allocated & readable.
+ // region permissions, see if the memory is allocated & readable.
if (process->GetLoadAddressPermissions(m_cfa, permissions) &&
(permissions & ePermissionsReadable) == 0) {
m_frame_type = eNotAValidFrame;
@@ -435,19 +430,18 @@ void RegisterContextLLDB::InitializeNonZerothFrame() {
bool resolve_tail_call_address = false; // m_current_pc can be one past the
// address range of the function...
- // If the saved pc does not point to a function/symbol because it is
- // beyond the bounds of the correct function and there's no symbol there,
- // we do *not* want ResolveSymbolContextForAddress to back up the pc by 1,
- // because then we might not find the correct unwind information later.
- // Instead, let ResolveSymbolContextForAddress fail, and handle the case
- // via decr_pc_and_recompute_addr_range below.
+ // If the saved pc does not point to a function/symbol because it is beyond
+ // the bounds of the correct function and there's no symbol there, we do
+ // *not* want ResolveSymbolContextForAddress to back up the pc by 1, because
+ // then we might not find the correct unwind information later. Instead, let
+ // ResolveSymbolContextForAddress fail, and handle the case via
+ // decr_pc_and_recompute_addr_range below.
const uint32_t resolve_scope = eSymbolContextFunction | eSymbolContextSymbol;
uint32_t resolved_scope = pc_module_sp->ResolveSymbolContextForAddress(
m_current_pc, resolve_scope, m_sym_ctx, resolve_tail_call_address);
// We require either a symbol or function in the symbols context to be
- // successfully
- // filled in or this context is of no use to us.
+ // successfully filled in or this context is of no use to us.
if (resolve_scope & resolved_scope) {
m_sym_ctx_valid = true;
}
@@ -476,8 +470,7 @@ void RegisterContextLLDB::InitializeNonZerothFrame() {
decr_pc_and_recompute_addr_range = true;
// Or if we're in the middle of the stack (and not "above" an asynchronous
- // event like sigtramp),
- // and our "current" pc is the start of a function...
+ // event like sigtramp), and our "current" pc is the start of a function...
if (GetNextFrame()->m_frame_type != eTrapHandlerFrame &&
GetNextFrame()->m_frame_type != eDebuggerFrame &&
(!m_sym_ctx_valid ||
@@ -488,9 +481,8 @@ void RegisterContextLLDB::InitializeNonZerothFrame() {
}
// We need to back up the pc by 1 byte and re-search for the Symbol to handle
- // the case where the "saved pc"
- // value is pointing to the next function, e.g. if a function ends with a CALL
- // instruction.
+ // the case where the "saved pc" value is pointing to the next function, e.g.
+ // if a function ends with a CALL instruction.
// FIXME this may need to be an architectural-dependent behavior; if so we'll
// need to add a member function
// to the ABI plugin and consult that.
@@ -516,9 +508,9 @@ void RegisterContextLLDB::InitializeNonZerothFrame() {
GetSymbolOrFunctionName(m_sym_ctx).AsCString(""));
}
- // If we were able to find a symbol/function, set addr_range_ptr to the bounds
- // of that symbol/function.
- // else treat the current pc value as the start_pc and record no offset.
+ // If we were able to find a symbol/function, set addr_range_ptr to the
+ // bounds of that symbol/function. else treat the current pc value as the
+ // start_pc and record no offset.
if (addr_range.GetBaseAddress().IsValid()) {
m_start_pc = addr_range.GetBaseAddress();
m_current_offset = pc - m_start_pc.GetLoadAddress(&process->GetTarget());
@@ -553,9 +545,8 @@ void RegisterContextLLDB::InitializeNonZerothFrame() {
RegisterKind row_register_kind = eRegisterKindGeneric;
// Try to get by with just the fast UnwindPlan if possible - the full
- // UnwindPlan may be expensive to get
- // (e.g. if we have to parse the entire eh_frame section of an ObjectFile for
- // the first time.)
+ // UnwindPlan may be expensive to get (e.g. if we have to parse the entire
+ // eh_frame section of an ObjectFile for the first time.)
if (m_fast_unwind_plan_sp &&
m_fast_unwind_plan_sp->PlanValidAtAddress(m_current_pc)) {
@@ -616,16 +607,14 @@ void RegisterContextLLDB::InitializeNonZerothFrame() {
bool RegisterContextLLDB::CheckIfLoopingStack() {
// If we have a bad stack setup, we can get the same CFA value multiple times
- // -- or even
- // more devious, we can actually oscillate between two CFA values. Detect that
- // here and
- // break out to avoid a possible infinite loop in lldb trying to unwind the
- // stack.
- // To detect when we have the same CFA value multiple times, we compare the
+ // -- or even more devious, we can actually oscillate between two CFA values.
+ // Detect that here and break out to avoid a possible infinite loop in lldb
+ // trying to unwind the stack. To detect when we have the same CFA value
+ // multiple times, we compare the
// CFA of the current
// frame with the 2nd next frame because in some specail case (e.g. signal
- // hanlders, hand
- // written assembly without ABI compiance) we can have 2 frames with the same
+ // hanlders, hand written assembly without ABI compiance) we can have 2
+ // frames with the same
// CFA (in theory we
// can have arbitrary number of frames with the same CFA, but more then 2 is
// very very unlikely)
@@ -734,15 +723,12 @@ UnwindPlanSP RegisterContextLLDB::GetFullUnwindPlanForFrame() {
}
// If we've done a jmp 0x0 / bl 0x0 (called through a null function pointer)
- // so the pc is 0x0
- // in the zeroth frame, we need to use the "unwind at first instruction" arch
- // default UnwindPlan
- // Also, if this Process can report on memory region attributes, any
- // non-executable region means
- // we jumped through a bad function pointer - handle the same way as 0x0.
- // Note, if we have a symbol context & a symbol, we don't want to follow this
- // code path. This is
- // for jumping to memory regions without any information available.
+ // so the pc is 0x0 in the zeroth frame, we need to use the "unwind at first
+ // instruction" arch default UnwindPlan Also, if this Process can report on
+ // memory region attributes, any non-executable region means we jumped
+ // through a bad function pointer - handle the same way as 0x0. Note, if we
+ // have a symbol context & a symbol, we don't want to follow this code path.
+ // This is for jumping to memory regions without any information available.
if ((!m_sym_ctx_valid ||
(m_sym_ctx.function == NULL && m_sym_ctx.symbol == NULL)) &&
@@ -780,12 +766,10 @@ UnwindPlanSP RegisterContextLLDB::GetFullUnwindPlanForFrame() {
}
// No FuncUnwinders available for this pc (stripped function symbols, lldb
- // could not augment its
- // function table with another source, like LC_FUNCTION_STARTS or eh_frame in
- // ObjectFileMachO).
- // See if eh_frame or the .ARM.exidx tables have unwind information for this
- // address, else fall
- // back to the architectural default unwind.
+ // could not augment its function table with another source, like
+ // LC_FUNCTION_STARTS or eh_frame in ObjectFileMachO). See if eh_frame or the
+ // .ARM.exidx tables have unwind information for this address, else fall back
+ // to the architectural default unwind.
if (!func_unwinders_sp) {
m_frame_type = eNormalFrame;
@@ -793,7 +777,8 @@ UnwindPlanSP RegisterContextLLDB::GetFullUnwindPlanForFrame() {
!m_current_pc.IsValid())
return arch_default_unwind_plan_sp;
- // Even with -fomit-frame-pointer, we can try eh_frame to get back on track.
+ // Even with -fomit-frame-pointer, we can try eh_frame to get back on
+ // track.
DWARFCallFrameInfo *eh_frame =
pc_module_sp->GetObjectFile()->GetUnwindTable().GetEHFrameInfo();
if (eh_frame) {
@@ -819,11 +804,10 @@ UnwindPlanSP RegisterContextLLDB::GetFullUnwindPlanForFrame() {
}
// If we're in _sigtramp(), unwinding past this frame requires special
- // knowledge. On Mac OS X this knowledge
- // is properly encoded in the eh_frame section, so prefer that if available.
- // On other platforms we may need to provide a platform-specific UnwindPlan
- // which encodes the details of
- // how to unwind out of sigtramp.
+ // knowledge. On Mac OS X this knowledge is properly encoded in the eh_frame
+ // section, so prefer that if available. On other platforms we may need to
+ // provide a platform-specific UnwindPlan which encodes the details of how to
+ // unwind out of sigtramp.
if (m_frame_type == eTrapHandlerFrame && process) {
m_fast_unwind_plan_sp.reset();
unwind_plan_sp = func_unwinders_sp->GetEHFrameUnwindPlan(
@@ -835,24 +819,19 @@ UnwindPlanSP RegisterContextLLDB::GetFullUnwindPlanForFrame() {
}
// Ask the DynamicLoader if the eh_frame CFI should be trusted in this frame
- // even when it's frame zero
- // This comes up if we have hand-written functions in a Module and
- // hand-written eh_frame. The assembly
- // instruction inspection may fail and the eh_frame CFI were probably written
- // with some care to do the
- // right thing. It'd be nice if there was a way to ask the eh_frame directly
- // if it is asynchronous
- // (can be trusted at every instruction point) or synchronous (the normal case
- // - only at call sites).
+ // even when it's frame zero This comes up if we have hand-written functions
+ // in a Module and hand-written eh_frame. The assembly instruction
+ // inspection may fail and the eh_frame CFI were probably written with some
+ // care to do the right thing. It'd be nice if there was a way to ask the
+ // eh_frame directly if it is asynchronous (can be trusted at every
+ // instruction point) or synchronous (the normal case - only at call sites).
// But there is not.
if (process && process->GetDynamicLoader() &&
process->GetDynamicLoader()->AlwaysRelyOnEHUnwindInfo(m_sym_ctx)) {
// We must specifically call the GetEHFrameUnwindPlan() method here --
- // normally we would
- // call GetUnwindPlanAtCallSite() -- because CallSite may return an unwind
- // plan sourced from
- // either eh_frame (that's what we intend) or compact unwind (this won't
- // work)
+ // normally we would call GetUnwindPlanAtCallSite() -- because CallSite may
+ // return an unwind plan sourced from either eh_frame (that's what we
+ // intend) or compact unwind (this won't work)
unwind_plan_sp = func_unwinders_sp->GetEHFrameUnwindPlan(
process->GetTarget(), m_current_offset_backed_up_one);
if (unwind_plan_sp && unwind_plan_sp->PlanValidAtAddress(m_current_pc)) {
@@ -871,22 +850,16 @@ UnwindPlanSP RegisterContextLLDB::GetFullUnwindPlanForFrame() {
if (unwind_plan_sp && unwind_plan_sp->PlanValidAtAddress(m_current_pc)) {
if (unwind_plan_sp->GetSourcedFromCompiler() == eLazyBoolNo) {
// We probably have an UnwindPlan created by inspecting assembly
- // instructions. The
- // assembly profilers work really well with compiler-generated functions
- // but hand-
- // written assembly can be problematic. We set the eh_frame based unwind
- // plan as our
- // fallback unwind plan if instruction emulation doesn't work out even
- // for non call
- // sites if it is available and use the architecture default unwind plan
- // if it is
+ // instructions. The assembly profilers work really well with compiler-
+ // generated functions but hand- written assembly can be problematic.
+ // We set the eh_frame based unwind plan as our fallback unwind plan if
+ // instruction emulation doesn't work out even for non call sites if it
+ // is available and use the architecture default unwind plan if it is
// not available. The eh_frame unwind plan is more reliable even on non
- // call sites
- // then the architecture default plan and for hand written assembly code
- // it is often
- // written in a way that it valid at all location what helps in the most
- // common
- // cases when the instruction emulation fails.
+ // call sites then the architecture default plan and for hand written
+ // assembly code it is often written in a way that it valid at all
+ // location what helps in the most common cases when the instruction
+ // emulation fails.
UnwindPlanSP call_site_unwind_plan =
func_unwinders_sp->GetUnwindPlanAtCallSite(
process->GetTarget(), m_current_offset_backed_up_one);
@@ -919,9 +892,8 @@ UnwindPlanSP RegisterContextLLDB::GetFullUnwindPlanForFrame() {
}
// We'd prefer to use an UnwindPlan intended for call sites when we're at a
- // call site but if we've
- // struck out on that, fall back to using the non-call-site assembly
- // inspection UnwindPlan if possible.
+ // call site but if we've struck out on that, fall back to using the non-
+ // call-site assembly inspection UnwindPlan if possible.
if (process) {
unwind_plan_sp = func_unwinders_sp->GetUnwindPlanAtNonCallSite(
process->GetTarget(), m_thread, m_current_offset_backed_up_one);
@@ -929,19 +901,14 @@ UnwindPlanSP RegisterContextLLDB::GetFullUnwindPlanForFrame() {
if (unwind_plan_sp &&
unwind_plan_sp->GetSourcedFromCompiler() == eLazyBoolNo) {
// We probably have an UnwindPlan created by inspecting assembly
- // instructions. The assembly
- // profilers work really well with compiler-generated functions but hand-
- // written assembly
- // can be problematic. We set the eh_frame based unwind plan as our fallback
- // unwind plan if
+ // instructions. The assembly profilers work really well with compiler-
+ // generated functions but hand- written assembly can be problematic. We
+ // set the eh_frame based unwind plan as our fallback unwind plan if
// instruction emulation doesn't work out even for non call sites if it is
- // available and use
- // the architecture default unwind plan if it is not available. The eh_frame
- // unwind plan is
- // more reliable even on non call sites then the architecture default plan
- // and for hand
- // written assembly code it is often written in a way that it valid at all
- // location what
+ // available and use the architecture default unwind plan if it is not
+ // available. The eh_frame unwind plan is more reliable even on non call
+ // sites then the architecture default plan and for hand written assembly
+ // code it is often written in a way that it valid at all location what
// helps in the most common cases when the instruction emulation fails.
UnwindPlanSP call_site_unwind_plan =
func_unwinders_sp->GetUnwindPlanAtCallSite(
@@ -963,8 +930,8 @@ UnwindPlanSP RegisterContextLLDB::GetFullUnwindPlanForFrame() {
}
// If we're on the first instruction of a function, and we have an
- // architectural default UnwindPlan
- // for the initial instruction of a function, use that.
+ // architectural default UnwindPlan for the initial instruction of a
+ // function, use that.
if (m_current_offset_backed_up_one == 0) {
unwind_plan_sp =
func_unwinders_sp->GetUnwindPlanArchitectureDefaultAtFunctionEntry(
@@ -1115,12 +1082,10 @@ bool RegisterContextLLDB::IsValid() const {
}
// After the final stack frame in a stack walk we'll get one invalid
-// (eNotAValidFrame) stack frame --
-// one past the end of the stack walk. But higher-level code will need to tell
-// the differnece between
-// "the unwind plan below this frame failed" versus "we successfully completed
-// the stack walk" so
-// this method helps to disambiguate that.
+// (eNotAValidFrame) stack frame -- one past the end of the stack walk. But
+// higher-level code will need to tell the differnece between "the unwind plan
+// below this frame failed" versus "we successfully completed the stack walk"
+// so this method helps to disambiguate that.
bool RegisterContextLLDB::IsTrapHandlerFrame() const {
return m_frame_type == eTrapHandlerFrame;
@@ -1129,12 +1094,10 @@ bool RegisterContextLLDB::IsTrapHandlerFrame() const {
// A skip frame is a bogus frame on the stack -- but one where we're likely to
// find a real frame farther
// up the stack if we keep looking. It's always the second frame in an unwind
-// (i.e. the first frame after
-// frame zero) where unwinding can be the trickiest. Ideally we'll mark up this
-// frame in some way so the
-// user knows we're displaying bad data and we may have skipped one frame of
-// their real program in the
-// process of getting back on track.
+// (i.e. the first frame after frame zero) where unwinding can be the
+// trickiest. Ideally we'll mark up this frame in some way so the user knows
+// we're displaying bad data and we may have skipped one frame of their real
+// program in the process of getting back on track.
bool RegisterContextLLDB::IsSkipFrame() const {
return m_frame_type == eSkipFrame;
@@ -1231,8 +1194,8 @@ RegisterContextLLDB::SavedLocationForRegister(
RegisterNumber return_address_reg;
// If we're fetching the saved pc and this UnwindPlan defines a
- // ReturnAddress register (e.g. lr on arm),
- // look for the return address register number in the UnwindPlan's row.
+ // ReturnAddress register (e.g. lr on arm), look for the return address
+ // register number in the UnwindPlan's row.
if (pc_regnum.IsValid() && pc_regnum == regnum &&
m_full_unwind_plan_sp->GetReturnAddressRegister() !=
LLDB_INVALID_REGNUM) {
@@ -1272,10 +1235,8 @@ RegisterContextLLDB::SavedLocationForRegister(
}
// This is frame 0 and we're retrieving the PC and it's saved in a Return
- // Address register and
- // it hasn't been saved anywhere yet -- that is, it's still live in the
- // actual register.
- // Handle this specially.
+ // Address register and it hasn't been saved anywhere yet -- that is,
+ // it's still live in the actual register. Handle this specially.
if (have_unwindplan_regloc == false && return_address_reg.IsValid() &&
IsFrameZero()) {
@@ -1298,22 +1259,18 @@ RegisterContextLLDB::SavedLocationForRegister(
}
// If this architecture stores the return address in a register (it
- // defines a Return Address register)
- // and we're on a non-zero stack frame and the Full UnwindPlan says that
- // the pc is stored in the
+ // defines a Return Address register) and we're on a non-zero stack frame
+ // and the Full UnwindPlan says that the pc is stored in the
// RA registers (e.g. lr on arm), then we know that the full unwindplan is
// not trustworthy -- this
// is an impossible situation and the instruction emulation code has
- // likely been misled.
- // If this stack frame meets those criteria, we need to throw away the
- // Full UnwindPlan that the
- // instruction emulation came up with and fall back to the architecture's
- // Default UnwindPlan so
- // the stack walk can get past this point.
+ // likely been misled. If this stack frame meets those criteria, we need
+ // to throw away the Full UnwindPlan that the instruction emulation came
+ // up with and fall back to the architecture's Default UnwindPlan so the
+ // stack walk can get past this point.
// Special note: If the Full UnwindPlan was generated from the compiler,
- // don't second-guess it
- // when we're at a call site location.
+ // don't second-guess it when we're at a call site location.
// arch_default_ra_regnum is the return address register # in the Full
// UnwindPlan register numbering
@@ -1376,11 +1333,10 @@ RegisterContextLLDB::SavedLocationForRegister(
ExecutionContext exe_ctx(m_thread.shared_from_this());
Process *process = exe_ctx.GetProcessPtr();
if (have_unwindplan_regloc == false) {
- // If the UnwindPlan failed to give us an unwind location for this register,
- // we may be able to fall back
- // to some ABI-defined default. For example, some ABIs allow to determine
- // the caller's SP via the CFA.
- // Also, the ABI may set volatile registers to the undefined state.
+ // If the UnwindPlan failed to give us an unwind location for this
+ // register, we may be able to fall back to some ABI-defined default. For
+ // example, some ABIs allow to determine the caller's SP via the CFA. Also,
+ // the ABI may set volatile registers to the undefined state.
ABI *abi = process ? process->GetABI().get() : NULL;
if (abi) {
const RegisterInfo *reg_info =
@@ -1558,24 +1514,19 @@ RegisterContextLLDB::SavedLocationForRegister(
// TryFallbackUnwindPlan() -- this method is a little tricky.
//
// When this is called, the frame above -- the caller frame, the "previous"
-// frame --
-// is invalid or bad.
+// frame -- is invalid or bad.
//
-// Instead of stopping the stack walk here, we'll try a different UnwindPlan and
-// see
-// if we can get a valid frame above us.
+// Instead of stopping the stack walk here, we'll try a different UnwindPlan
+// and see if we can get a valid frame above us.
//
// This most often happens when an unwind plan based on assembly instruction
-// inspection
-// is not correct -- mostly with hand-written assembly functions or functions
-// where the
-// stack frame is set up "out of band", e.g. the kernel saved the register
-// context and
-// then called an asynchronous trap handler like _sigtramp.
+// inspection is not correct -- mostly with hand-written assembly functions or
+// functions where the stack frame is set up "out of band", e.g. the kernel
+// saved the register context and then called an asynchronous trap handler like
+// _sigtramp.
//
// Often in these cases, if we just do a dumb stack walk we'll get past this
-// tricky
-// frame and our usual techniques can continue to be used.
+// tricky frame and our usual techniques can continue to be used.
bool RegisterContextLLDB::TryFallbackUnwindPlan() {
if (m_fallback_unwind_plan_sp.get() == nullptr)
@@ -1591,15 +1542,13 @@ bool RegisterContextLLDB::TryFallbackUnwindPlan() {
}
// If a compiler generated unwind plan failed, trying the arch default
- // unwindplan
- // isn't going to do any better.
+ // unwindplan isn't going to do any better.
if (m_full_unwind_plan_sp->GetSourcedFromCompiler() == eLazyBoolYes)
return false;
- // Get the caller's pc value and our own CFA value.
- // Swap in the fallback unwind plan, re-fetch the caller's pc value and CFA
- // value.
- // If they're the same, then the fallback unwind plan provides no benefit.
+ // Get the caller's pc value and our own CFA value. Swap in the fallback
+ // unwind plan, re-fetch the caller's pc value and CFA value. If they're the
+ // same, then the fallback unwind plan provides no benefit.
RegisterNumber pc_regnum(m_thread, eRegisterKindGeneric,
LLDB_REGNUM_GENERIC_PC);
@@ -1622,23 +1571,18 @@ bool RegisterContextLLDB::TryFallbackUnwindPlan() {
}
// This is a tricky wrinkle! If SavedLocationForRegister() detects a really
- // impossible
- // register location for the full unwind plan, it may call
- // ForceSwitchToFallbackUnwindPlan()
- // which in turn replaces the full unwindplan with the fallback... in short,
- // we're done,
- // we're using the fallback UnwindPlan.
- // We checked if m_fallback_unwind_plan_sp was nullptr at the top -- the only
- // way it
- // became nullptr since then is via SavedLocationForRegister().
+ // impossible register location for the full unwind plan, it may call
+ // ForceSwitchToFallbackUnwindPlan() which in turn replaces the full
+ // unwindplan with the fallback... in short, we're done, we're using the
+ // fallback UnwindPlan. We checked if m_fallback_unwind_plan_sp was nullptr
+ // at the top -- the only way it became nullptr since then is via
+ // SavedLocationForRegister().
if (m_fallback_unwind_plan_sp.get() == nullptr)
return true;
// Switch the full UnwindPlan to be the fallback UnwindPlan. If we decide
- // this isn't
- // working, we need to restore.
- // We'll also need to save & restore the value of the m_cfa ivar. Save is
- // down below a bit in 'old_cfa'.
+ // this isn't working, we need to restore. We'll also need to save & restore
+ // the value of the m_cfa ivar. Save is down below a bit in 'old_cfa'.
UnwindPlanSP original_full_unwind_plan_sp = m_full_unwind_plan_sp;
addr_t old_cfa = m_cfa;
@@ -2049,10 +1993,9 @@ bool RegisterContextLLDB::ReadPC(addr_t &pc) {
// A pc value of 0 or 1 is impossible in the middle of the stack -- it
// indicates the end of a stack walk.
// On the currently executing frame (or such a frame interrupted
- // asynchronously by sigtramp et al) this may
- // occur if code has jumped through a NULL pointer -- we want to be able to
- // unwind past that frame to help
- // find the bug.
+ // asynchronously by sigtramp et al) this may occur if code has jumped
+ // through a NULL pointer -- we want to be able to unwind past that frame
+ // to help find the bug.
ProcessSP process_sp (m_thread.GetProcess());
if (process_sp)
diff --git a/source/Plugins/Process/Utility/RegisterContextMacOSXFrameBackchain.cpp b/source/Plugins/Process/Utility/RegisterContextMacOSXFrameBackchain.cpp
index 2d24bdaed2cd0..77c1bea348515 100644
--- a/source/Plugins/Process/Utility/RegisterContextMacOSXFrameBackchain.cpp
+++ b/source/Plugins/Process/Utility/RegisterContextMacOSXFrameBackchain.cpp
@@ -19,7 +19,7 @@
#include "lldb/Utility/DataExtractor.h"
#include "lldb/Utility/StreamString.h"
// Project includes
-#include "Utility/StringExtractorGDBRemote.h"
+#include "lldb/Utility/StringExtractorGDBRemote.h"
using namespace lldb;
using namespace lldb_private;
@@ -139,8 +139,8 @@ bool RegisterContextMacOSXFrameBackchain::ReadRegister(
bool RegisterContextMacOSXFrameBackchain::WriteRegister(
const RegisterInfo *reg_info, const RegisterValue &value) {
- // Not supported yet. We could easily add support for this by remembering
- // the address of each entry (it would need to be part of the cursor)
+ // Not supported yet. We could easily add support for this by remembering the
+ // address of each entry (it would need to be part of the cursor)
return false;
}
@@ -154,10 +154,10 @@ bool RegisterContextMacOSXFrameBackchain::ReadAllRegisterValues(
bool RegisterContextMacOSXFrameBackchain::WriteAllRegisterValues(
const lldb::DataBufferSP &data_sp) {
- // Since this class doesn't respond to "ReadAllRegisterValues()", it must
- // not have been the one that saved all the register values. So we just let
- // the thread's register context (the register context for frame zero) do
- // the writing.
+ // Since this class doesn't respond to "ReadAllRegisterValues()", it must not
+ // have been the one that saved all the register values. So we just let the
+ // thread's register context (the register context for frame zero) do the
+ // writing.
return m_thread.GetRegisterContext()->WriteAllRegisterValues(data_sp);
}
diff --git a/source/Plugins/Process/Utility/RegisterContextMemory.cpp b/source/Plugins/Process/Utility/RegisterContextMemory.cpp
index 8f0dfd2a5b50c..76189ea781dee 100644
--- a/source/Plugins/Process/Utility/RegisterContextMemory.cpp
+++ b/source/Plugins/Process/Utility/RegisterContextMemory.cpp
@@ -32,9 +32,9 @@ RegisterContextMemory::RegisterContextMemory(Thread &thread,
addr_t reg_data_addr)
: RegisterContext(thread, concrete_frame_idx), m_reg_infos(reg_infos),
m_reg_valid(), m_reg_data(), m_reg_data_addr(reg_data_addr) {
- // Resize our vector of bools to contain one bool for every register.
- // We will use these boolean values to know when a register value
- // is valid in m_reg_data.
+ // Resize our vector of bools to contain one bool for every register. We will
+ // use these boolean values to know when a register value is valid in
+ // m_reg_data.
const size_t num_regs = reg_infos.GetNumRegisters();
assert(num_regs > 0);
m_reg_valid.resize(num_regs);
diff --git a/source/Plugins/Process/Utility/RegisterContextPOSIX_arm.cpp b/source/Plugins/Process/Utility/RegisterContextPOSIX_arm.cpp
index bb3509330eece..352e251e3b647 100644
--- a/source/Plugins/Process/Utility/RegisterContextPOSIX_arm.cpp
+++ b/source/Plugins/Process/Utility/RegisterContextPOSIX_arm.cpp
@@ -13,6 +13,7 @@
#include "lldb/Core/RegisterValue.h"
#include "lldb/Core/Scalar.h"
+#include "lldb/Target/Process.h"
#include "lldb/Target/Target.h"
#include "lldb/Target/Thread.h"
#include "lldb/Utility/DataBufferHeap.h"
@@ -20,7 +21,6 @@
#include "lldb/Utility/Endian.h"
#include "llvm/Support/Compiler.h"
-#include "Plugins/Process/elf-core/ProcessElfCore.h"
#include "RegisterContextPOSIX_arm.h"
using namespace lldb;
@@ -107,11 +107,6 @@ RegisterContextPOSIX_arm::RegisterContextPOSIX_arm(
}
::memset(&m_fpr, 0, sizeof m_fpr);
-
- // elf-core yet to support ReadFPR()
- lldb::ProcessSP base = CalculateProcess();
- if (base.get()->GetPluginName() == ProcessElfCore::GetPluginNameStatic())
- return;
}
RegisterContextPOSIX_arm::~RegisterContextPOSIX_arm() {}
@@ -142,8 +137,8 @@ size_t RegisterContextPOSIX_arm::GetGPRSize() {
const lldb_private::RegisterInfo *RegisterContextPOSIX_arm::GetRegisterInfo() {
// Commonly, this method is overridden and g_register_infos is copied and
- // specialized.
- // So, use GetRegisterInfo() rather than g_register_infos in this scope.
+ // specialized. So, use GetRegisterInfo() rather than g_register_infos in
+ // this scope.
return m_register_info_ap->GetRegisterInfo();
}
@@ -199,8 +194,8 @@ bool RegisterContextPOSIX_arm::IsRegisterSetAvailable(size_t set_index) {
return set_index < k_num_register_sets;
}
-// Used when parsing DWARF and EH frame information and any other
-// object file sections that contain register numbers in them.
+// Used when parsing DWARF and EH frame information and any other object file
+// sections that contain register numbers in them.
uint32_t RegisterContextPOSIX_arm::ConvertRegisterKindToRegisterNumber(
lldb::RegisterKind kind, uint32_t num) {
const uint32_t num_regs = GetRegisterCount();
diff --git a/source/Plugins/Process/Utility/RegisterContextPOSIX_arm64.cpp b/source/Plugins/Process/Utility/RegisterContextPOSIX_arm64.cpp
index 89384c8f5190b..3ff93cde23473 100644
--- a/source/Plugins/Process/Utility/RegisterContextPOSIX_arm64.cpp
+++ b/source/Plugins/Process/Utility/RegisterContextPOSIX_arm64.cpp
@@ -13,6 +13,7 @@
#include "lldb/Core/RegisterValue.h"
#include "lldb/Core/Scalar.h"
+#include "lldb/Target/Process.h"
#include "lldb/Target/Target.h"
#include "lldb/Target/Thread.h"
#include "lldb/Utility/DataBufferHeap.h"
@@ -20,7 +21,6 @@
#include "lldb/Utility/Endian.h"
#include "llvm/Support/Compiler.h"
-#include "Plugins/Process/elf-core/ProcessElfCore.h"
#include "RegisterContextPOSIX_arm64.h"
using namespace lldb;
@@ -126,11 +126,6 @@ RegisterContextPOSIX_arm64::RegisterContextPOSIX_arm64(
}
::memset(&m_fpr, 0, sizeof m_fpr);
-
- // elf-core yet to support ReadFPR()
- lldb::ProcessSP base = CalculateProcess();
- if (base.get()->GetPluginName() == ProcessElfCore::GetPluginNameStatic())
- return;
}
RegisterContextPOSIX_arm64::~RegisterContextPOSIX_arm64() {}
@@ -162,8 +157,8 @@ size_t RegisterContextPOSIX_arm64::GetGPRSize() {
const lldb_private::RegisterInfo *
RegisterContextPOSIX_arm64::GetRegisterInfo() {
// Commonly, this method is overridden and g_register_infos is copied and
- // specialized.
- // So, use GetRegisterInfo() rather than g_register_infos in this scope.
+ // specialized. So, use GetRegisterInfo() rather than g_register_infos in
+ // this scope.
return m_register_info_ap->GetRegisterInfo();
}
@@ -219,8 +214,8 @@ bool RegisterContextPOSIX_arm64::IsRegisterSetAvailable(size_t set_index) {
return set_index < k_num_register_sets;
}
-// Used when parsing DWARF and EH frame information and any other
-// object file sections that contain register numbers in them.
+// Used when parsing DWARF and EH frame information and any other object file
+// sections that contain register numbers in them.
uint32_t RegisterContextPOSIX_arm64::ConvertRegisterKindToRegisterNumber(
lldb::RegisterKind kind, uint32_t num) {
const uint32_t num_regs = GetRegisterCount();
diff --git a/source/Plugins/Process/Utility/RegisterContextPOSIX_mips64.cpp b/source/Plugins/Process/Utility/RegisterContextPOSIX_mips64.cpp
index 6a55947ba5c2e..98d1e6fa8817a 100644
--- a/source/Plugins/Process/Utility/RegisterContextPOSIX_mips64.cpp
+++ b/source/Plugins/Process/Utility/RegisterContextPOSIX_mips64.cpp
@@ -13,6 +13,7 @@
#include "lldb/Core/RegisterValue.h"
#include "lldb/Core/Scalar.h"
+#include "lldb/Target/Process.h"
#include "lldb/Target/Target.h"
#include "lldb/Target/Thread.h"
#include "lldb/Utility/DataBufferHeap.h"
@@ -20,11 +21,10 @@
#include "lldb/Utility/Endian.h"
#include "llvm/Support/Compiler.h"
-#include "Plugins/Process/elf-core/ProcessElfCore.h"
#include "RegisterContextPOSIX_mips64.h"
#include "RegisterContextFreeBSD_mips64.h"
#include "RegisterContextLinux_mips64.h"
-#include "RegisterContextLinux_mips.h"
+#include "RegisterContextLinux_mips.h"
using namespace lldb_private;
using namespace lldb;
@@ -59,11 +59,6 @@ RegisterContextPOSIX_mips64::RegisterContextPOSIX_mips64(
static_cast<uint32_t>(m_registers_count[gpr_registers_count] +
m_registers_count[fpr_registers_count] +
m_registers_count[msa_registers_count]));
-
- // elf-core yet to support ReadFPR()
- ProcessSP base = CalculateProcess();
- if (base.get()->GetPluginName() == ProcessElfCore::GetPluginNameStatic())
- return;
}
RegisterContextPOSIX_mips64::~RegisterContextPOSIX_mips64() {}
@@ -92,8 +87,8 @@ size_t RegisterContextPOSIX_mips64::GetGPRSize() {
const RegisterInfo *RegisterContextPOSIX_mips64::GetRegisterInfo() {
// Commonly, this method is overridden and g_register_infos is copied and
- // specialized.
- // So, use GetRegisterInfo() rather than g_register_infos in this scope.
+ // specialized. So, use GetRegisterInfo() rather than g_register_infos in
+ // this scope.
return m_register_info_ap->GetRegisterInfo();
}
@@ -172,8 +167,8 @@ bool RegisterContextPOSIX_mips64::IsRegisterSetAvailable(size_t set_index) {
return (set_index < num_sets);
}
-// Used when parsing DWARF and EH frame information and any other
-// object file sections that contain register numbers in them.
+// Used when parsing DWARF and EH frame information and any other object file
+// sections that contain register numbers in them.
uint32_t RegisterContextPOSIX_mips64::ConvertRegisterKindToRegisterNumber(
lldb::RegisterKind kind, uint32_t num) {
const uint32_t num_regs = m_num_registers;
diff --git a/source/Plugins/Process/Utility/RegisterContextPOSIX_powerpc.cpp b/source/Plugins/Process/Utility/RegisterContextPOSIX_powerpc.cpp
index c2b73e2261658..9f0552539723f 100644
--- a/source/Plugins/Process/Utility/RegisterContextPOSIX_powerpc.cpp
+++ b/source/Plugins/Process/Utility/RegisterContextPOSIX_powerpc.cpp
@@ -14,6 +14,7 @@
#include "lldb/Core/RegisterValue.h"
#include "lldb/Core/Scalar.h"
+#include "lldb/Target/Process.h"
#include "lldb/Target/Target.h"
#include "lldb/Target/Thread.h"
#include "lldb/Utility/DataBufferHeap.h"
@@ -21,7 +22,6 @@
#include "lldb/Utility/Endian.h"
#include "llvm/Support/Compiler.h"
-#include "Plugins/Process/elf-core/ProcessElfCore.h"
#include "RegisterContextPOSIX_powerpc.h"
using namespace lldb_private;
@@ -95,11 +95,6 @@ RegisterContextPOSIX_powerpc::RegisterContextPOSIX_powerpc(
RegisterInfoInterface *register_info)
: RegisterContext(thread, concrete_frame_idx) {
m_register_info_ap.reset(register_info);
-
- // elf-core yet to support ReadFPR()
- ProcessSP base = CalculateProcess();
- if (base.get()->GetPluginName() == ProcessElfCore::GetPluginNameStatic())
- return;
}
RegisterContextPOSIX_powerpc::~RegisterContextPOSIX_powerpc() {}
@@ -129,8 +124,8 @@ size_t RegisterContextPOSIX_powerpc::GetGPRSize() {
const RegisterInfo *RegisterContextPOSIX_powerpc::GetRegisterInfo() {
// Commonly, this method is overridden and g_register_infos is copied and
- // specialized.
- // So, use GetRegisterInfo() rather than g_register_infos in this scope.
+ // specialized. So, use GetRegisterInfo() rather than g_register_infos in
+ // this scope.
return m_register_info_ap->GetRegisterInfo();
}
@@ -181,8 +176,8 @@ bool RegisterContextPOSIX_powerpc::IsRegisterSetAvailable(size_t set_index) {
return (set_index < num_sets);
}
-// Used when parsing DWARF and EH frame information and any other
-// object file sections that contain register numbers in them.
+// Used when parsing DWARF and EH frame information and any other object file
+// sections that contain register numbers in them.
uint32_t RegisterContextPOSIX_powerpc::ConvertRegisterKindToRegisterNumber(
lldb::RegisterKind kind, uint32_t num) {
const uint32_t num_regs = GetRegisterCount();
diff --git a/source/Plugins/Process/Utility/RegisterContextPOSIX_ppc64le.cpp b/source/Plugins/Process/Utility/RegisterContextPOSIX_ppc64le.cpp
index de410f063b536..41ae5ec6b51a7 100644
--- a/source/Plugins/Process/Utility/RegisterContextPOSIX_ppc64le.cpp
+++ b/source/Plugins/Process/Utility/RegisterContextPOSIX_ppc64le.cpp
@@ -13,6 +13,7 @@
#include "lldb/Core/RegisterValue.h"
#include "lldb/Core/Scalar.h"
+#include "lldb/Target/Process.h"
#include "lldb/Target/Target.h"
#include "lldb/Target/Thread.h"
#include "lldb/Utility/DataBufferHeap.h"
@@ -20,7 +21,6 @@
#include "lldb/Utility/Endian.h"
#include "llvm/Support/Compiler.h"
-#include "Plugins/Process/elf-core/ProcessElfCore.h"
#include "RegisterContextPOSIX_ppc64le.h"
using namespace lldb_private;
@@ -117,10 +117,6 @@ RegisterContextPOSIX_ppc64le::RegisterContextPOSIX_ppc64le(
RegisterInfoInterface *register_info)
: RegisterContext(thread, concrete_frame_idx) {
m_register_info_ap.reset(register_info);
-
- ProcessSP base = CalculateProcess();
- if (base.get()->GetPluginName() == ProcessElfCore::GetPluginNameStatic())
- return;
}
void RegisterContextPOSIX_ppc64le::InvalidateAllRegisters() {}
@@ -146,8 +142,8 @@ size_t RegisterContextPOSIX_ppc64le::GetGPRSize() {
const RegisterInfo *RegisterContextPOSIX_ppc64le::GetRegisterInfo() {
// Commonly, this method is overridden and g_register_infos is copied and
- // specialized.
- // So, use GetRegisterInfo() rather than g_register_infos in this scope.
+ // specialized. So, use GetRegisterInfo() rather than g_register_infos in
+ // this scope.
return m_register_info_ap->GetRegisterInfo();
}
@@ -198,8 +194,8 @@ bool RegisterContextPOSIX_ppc64le::IsRegisterSetAvailable(size_t set_index) {
return (set_index < num_sets);
}
-// Used when parsing DWARF and EH frame information and any other
-// object file sections that contain register numbers in them.
+// Used when parsing DWARF and EH frame information and any other object file
+// sections that contain register numbers in them.
uint32_t RegisterContextPOSIX_ppc64le::ConvertRegisterKindToRegisterNumber(
lldb::RegisterKind kind, uint32_t num) {
const uint32_t num_regs = GetRegisterCount();
diff --git a/source/Plugins/Process/Utility/RegisterContextPOSIX_s390x.cpp b/source/Plugins/Process/Utility/RegisterContextPOSIX_s390x.cpp
index b3365ee2f098e..662ac38405ef9 100644
--- a/source/Plugins/Process/Utility/RegisterContextPOSIX_s390x.cpp
+++ b/source/Plugins/Process/Utility/RegisterContextPOSIX_s390x.cpp
@@ -174,8 +174,8 @@ lldb::ByteOrder RegisterContextPOSIX_s390x::GetByteOrder() {
return byte_order;
}
-// Used when parsing DWARF and EH frame information and any other
-// object file sections that contain register numbers in them.
+// Used when parsing DWARF and EH frame information and any other object file
+// sections that contain register numbers in them.
uint32_t RegisterContextPOSIX_s390x::ConvertRegisterKindToRegisterNumber(
lldb::RegisterKind kind, uint32_t num) {
const uint32_t num_regs = GetRegisterCount();
diff --git a/source/Plugins/Process/Utility/RegisterContextPOSIX_x86.cpp b/source/Plugins/Process/Utility/RegisterContextPOSIX_x86.cpp
index 41cec8add9875..d2a06e1b7897f 100644
--- a/source/Plugins/Process/Utility/RegisterContextPOSIX_x86.cpp
+++ b/source/Plugins/Process/Utility/RegisterContextPOSIX_x86.cpp
@@ -414,8 +414,8 @@ size_t RegisterContextPOSIX_x86::GetFXSAVEOffset() {
const RegisterInfo *RegisterContextPOSIX_x86::GetRegisterInfo() {
// Commonly, this method is overridden and g_register_infos is copied and
- // specialized.
- // So, use GetRegisterInfo() rather than g_register_infos in this scope.
+ // specialized. So, use GetRegisterInfo() rather than g_register_infos in
+ // this scope.
return m_register_info_ap->GetRegisterInfo();
}
@@ -531,8 +531,8 @@ bool RegisterContextPOSIX_x86::IsRegisterSetAvailable(size_t set_index) {
return (set_index < num_sets);
}
-// Used when parsing DWARF and EH frame information and any other
-// object file sections that contain register numbers in them.
+// Used when parsing DWARF and EH frame information and any other object file
+// sections that contain register numbers in them.
uint32_t RegisterContextPOSIX_x86::ConvertRegisterKindToRegisterNumber(
lldb::RegisterKind kind, uint32_t num) {
const uint32_t num_regs = GetRegisterCount();
diff --git a/source/Plugins/Process/Utility/RegisterInfoInterface.h b/source/Plugins/Process/Utility/RegisterInfoInterface.h
index 1894b53681224..5d7ad89ad3949 100644
--- a/source/Plugins/Process/Utility/RegisterInfoInterface.h
+++ b/source/Plugins/Process/Utility/RegisterInfoInterface.h
@@ -19,7 +19,7 @@ namespace lldb_private {
///------------------------------------------------------------------------------
/// @class RegisterInfoInterface
///
-/// @brief RegisterInfo interface to patch RegisterInfo structure for archs.
+/// RegisterInfo interface to patch RegisterInfo structure for archs.
///------------------------------------------------------------------------------
class RegisterInfoInterface {
public:
diff --git a/source/Plugins/Process/Utility/RegisterInfos_ppc64.h b/source/Plugins/Process/Utility/RegisterInfos_ppc64.h
new file mode 100644
index 0000000000000..69f00e4ba8852
--- /dev/null
+++ b/source/Plugins/Process/Utility/RegisterInfos_ppc64.h
@@ -0,0 +1,331 @@
+//===-- RegisterInfos_ppc64.h -----------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifdef DECLARE_REGISTER_INFOS_PPC64_STRUCT
+
+// C Includes
+#include <stddef.h>
+
+// Computes the offset of the given GPR_PPC64 in the user data area.
+#define GPR_PPC64_OFFSET(regname) (offsetof(GPR_PPC64, regname))
+#define FPR_PPC64_OFFSET(regname) (offsetof(FPR_PPC64, regname) \
+ + sizeof(GPR_PPC64))
+#define VMX_PPC64_OFFSET(regname) (offsetof(VMX_PPC64, regname) \
+ + sizeof(GPR_PPC64) + sizeof(FPR_PPC64))
+#define GPR_PPC64_SIZE(regname) (sizeof(((GPR_PPC64 *)NULL)->regname))
+
+#include "Utility/PPC64_DWARF_Registers.h"
+#include "lldb-ppc64-register-enums.h"
+
+// Note that the size and offset will be updated by platform-specific classes.
+#define DEFINE_GPR_PPC64(reg, alt, lldb_kind) \
+ { \
+ #reg, alt, GPR_PPC64_SIZE(reg), GPR_PPC64_OFFSET(reg), lldb::eEncodingUint,\
+ lldb::eFormatHex, \
+ {ppc64_dwarf::dwarf_##reg##_ppc64, \
+ ppc64_dwarf::dwarf_##reg##_ppc64, \
+ lldb_kind, \
+ LLDB_INVALID_REGNUM, \
+ gpr_##reg##_ppc64 }, \
+ NULL, NULL, NULL, 0 \
+ }
+#define DEFINE_FPR_PPC64(reg, alt, lldb_kind) \
+ { \
+#reg, alt, 8, FPR_PPC64_OFFSET(reg), lldb::eEncodingIEEE754, \
+ lldb::eFormatFloat, \
+ {ppc64_dwarf::dwarf_##reg##_ppc64, \
+ ppc64_dwarf::dwarf_##reg##_ppc64, lldb_kind, LLDB_INVALID_REGNUM, \
+ fpr_##reg##_ppc64 }, \
+ NULL, NULL, NULL, 0 \
+ }
+#define DEFINE_VMX_PPC64(reg, lldb_kind) \
+ { \
+#reg, NULL, 16, VMX_PPC64_OFFSET(reg), lldb::eEncodingVector, \
+ lldb::eFormatVectorOfUInt32, \
+ {ppc64_dwarf::dwarf_##reg##_ppc64, \
+ ppc64_dwarf::dwarf_##reg##_ppc64, lldb_kind, LLDB_INVALID_REGNUM, \
+ vmx_##reg##_ppc64 }, \
+ NULL, NULL, NULL, 0 \
+ }
+
+// General purpose registers.
+// EH_Frame, Generic, Process Plugin
+#define PPC64_REGS \
+ DEFINE_GPR_PPC64(r0, NULL, LLDB_INVALID_REGNUM) \
+ , DEFINE_GPR_PPC64(r1, "sp", LLDB_REGNUM_GENERIC_SP), \
+ DEFINE_GPR_PPC64(r2, NULL, LLDB_INVALID_REGNUM), \
+ DEFINE_GPR_PPC64(r3, "arg1", LLDB_REGNUM_GENERIC_ARG1), \
+ DEFINE_GPR_PPC64(r4, "arg2", LLDB_REGNUM_GENERIC_ARG2), \
+ DEFINE_GPR_PPC64(r5, "arg3", LLDB_REGNUM_GENERIC_ARG3), \
+ DEFINE_GPR_PPC64(r6, "arg4", LLDB_REGNUM_GENERIC_ARG4), \
+ DEFINE_GPR_PPC64(r7, "arg5", LLDB_REGNUM_GENERIC_ARG5), \
+ DEFINE_GPR_PPC64(r8, "arg6", LLDB_REGNUM_GENERIC_ARG6), \
+ DEFINE_GPR_PPC64(r9, "arg7", LLDB_REGNUM_GENERIC_ARG7), \
+ DEFINE_GPR_PPC64(r10, "arg8", LLDB_REGNUM_GENERIC_ARG8), \
+ DEFINE_GPR_PPC64(r11, NULL, LLDB_INVALID_REGNUM), \
+ DEFINE_GPR_PPC64(r12, NULL, LLDB_INVALID_REGNUM), \
+ DEFINE_GPR_PPC64(r13, NULL, LLDB_INVALID_REGNUM), \
+ DEFINE_GPR_PPC64(r14, NULL, LLDB_INVALID_REGNUM), \
+ DEFINE_GPR_PPC64(r15, NULL, LLDB_INVALID_REGNUM), \
+ DEFINE_GPR_PPC64(r16, NULL, LLDB_INVALID_REGNUM), \
+ DEFINE_GPR_PPC64(r17, NULL, LLDB_INVALID_REGNUM), \
+ DEFINE_GPR_PPC64(r18, NULL, LLDB_INVALID_REGNUM), \
+ DEFINE_GPR_PPC64(r19, NULL, LLDB_INVALID_REGNUM), \
+ DEFINE_GPR_PPC64(r20, NULL, LLDB_INVALID_REGNUM), \
+ DEFINE_GPR_PPC64(r21, NULL, LLDB_INVALID_REGNUM), \
+ DEFINE_GPR_PPC64(r22, NULL, LLDB_INVALID_REGNUM), \
+ DEFINE_GPR_PPC64(r23, NULL, LLDB_INVALID_REGNUM), \
+ DEFINE_GPR_PPC64(r24, NULL, LLDB_INVALID_REGNUM), \
+ DEFINE_GPR_PPC64(r25, NULL, LLDB_INVALID_REGNUM), \
+ DEFINE_GPR_PPC64(r26, NULL, LLDB_INVALID_REGNUM), \
+ DEFINE_GPR_PPC64(r27, NULL, LLDB_INVALID_REGNUM), \
+ DEFINE_GPR_PPC64(r28, NULL, LLDB_INVALID_REGNUM), \
+ DEFINE_GPR_PPC64(r29, NULL, LLDB_INVALID_REGNUM), \
+ DEFINE_GPR_PPC64(r30, NULL, LLDB_INVALID_REGNUM), \
+ DEFINE_GPR_PPC64(r31, NULL, LLDB_INVALID_REGNUM), \
+ DEFINE_GPR_PPC64(cr, "cr", LLDB_REGNUM_GENERIC_FLAGS), \
+ DEFINE_GPR_PPC64(msr, "msr", LLDB_INVALID_REGNUM), \
+ DEFINE_GPR_PPC64(xer, "xer", LLDB_INVALID_REGNUM), \
+ DEFINE_GPR_PPC64(lr, "lr", LLDB_REGNUM_GENERIC_RA), \
+ DEFINE_GPR_PPC64(ctr, "ctr", LLDB_INVALID_REGNUM), \
+ DEFINE_GPR_PPC64(pc, "pc", LLDB_REGNUM_GENERIC_PC), \
+ DEFINE_FPR_PPC64(f0, NULL, LLDB_INVALID_REGNUM), \
+ DEFINE_FPR_PPC64(f1, NULL, LLDB_INVALID_REGNUM), \
+ DEFINE_FPR_PPC64(f2, NULL, LLDB_INVALID_REGNUM), \
+ DEFINE_FPR_PPC64(f3, NULL, LLDB_INVALID_REGNUM), \
+ DEFINE_FPR_PPC64(f4, NULL, LLDB_INVALID_REGNUM), \
+ DEFINE_FPR_PPC64(f5, NULL, LLDB_INVALID_REGNUM), \
+ DEFINE_FPR_PPC64(f6, NULL, LLDB_INVALID_REGNUM), \
+ DEFINE_FPR_PPC64(f7, NULL, LLDB_INVALID_REGNUM), \
+ DEFINE_FPR_PPC64(f8, NULL, LLDB_INVALID_REGNUM), \
+ DEFINE_FPR_PPC64(f9, NULL, LLDB_INVALID_REGNUM), \
+ DEFINE_FPR_PPC64(f10, NULL, LLDB_INVALID_REGNUM), \
+ DEFINE_FPR_PPC64(f11, NULL, LLDB_INVALID_REGNUM), \
+ DEFINE_FPR_PPC64(f12, NULL, LLDB_INVALID_REGNUM), \
+ DEFINE_FPR_PPC64(f13, NULL, LLDB_INVALID_REGNUM), \
+ DEFINE_FPR_PPC64(f14, NULL, LLDB_INVALID_REGNUM), \
+ DEFINE_FPR_PPC64(f15, NULL, LLDB_INVALID_REGNUM), \
+ DEFINE_FPR_PPC64(f16, NULL, LLDB_INVALID_REGNUM), \
+ DEFINE_FPR_PPC64(f17, NULL, LLDB_INVALID_REGNUM), \
+ DEFINE_FPR_PPC64(f18, NULL, LLDB_INVALID_REGNUM), \
+ DEFINE_FPR_PPC64(f19, NULL, LLDB_INVALID_REGNUM), \
+ DEFINE_FPR_PPC64(f20, NULL, LLDB_INVALID_REGNUM), \
+ DEFINE_FPR_PPC64(f21, NULL, LLDB_INVALID_REGNUM), \
+ DEFINE_FPR_PPC64(f22, NULL, LLDB_INVALID_REGNUM), \
+ DEFINE_FPR_PPC64(f23, NULL, LLDB_INVALID_REGNUM), \
+ DEFINE_FPR_PPC64(f24, NULL, LLDB_INVALID_REGNUM), \
+ DEFINE_FPR_PPC64(f25, NULL, LLDB_INVALID_REGNUM), \
+ DEFINE_FPR_PPC64(f26, NULL, LLDB_INVALID_REGNUM), \
+ DEFINE_FPR_PPC64(f27, NULL, LLDB_INVALID_REGNUM), \
+ DEFINE_FPR_PPC64(f28, NULL, LLDB_INVALID_REGNUM), \
+ DEFINE_FPR_PPC64(f29, NULL, LLDB_INVALID_REGNUM), \
+ DEFINE_FPR_PPC64(f30, NULL, LLDB_INVALID_REGNUM), \
+ DEFINE_FPR_PPC64(f31, NULL, LLDB_INVALID_REGNUM), \
+ {"fpscr", \
+ NULL, \
+ 8, \
+ FPR_PPC64_OFFSET(fpscr), \
+ lldb::eEncodingUint, \
+ lldb::eFormatHex, \
+ {ppc64_dwarf::dwarf_fpscr_ppc64, \
+ ppc64_dwarf::dwarf_fpscr_ppc64, LLDB_INVALID_REGNUM, \
+ LLDB_INVALID_REGNUM, fpr_fpscr_ppc64}, \
+ NULL, \
+ NULL, \
+ NULL, \
+ 0}, \
+ DEFINE_VMX_PPC64(vr0, LLDB_INVALID_REGNUM), \
+ DEFINE_VMX_PPC64(vr1, LLDB_INVALID_REGNUM), \
+ DEFINE_VMX_PPC64(vr2, LLDB_INVALID_REGNUM), \
+ DEFINE_VMX_PPC64(vr3, LLDB_INVALID_REGNUM), \
+ DEFINE_VMX_PPC64(vr4, LLDB_INVALID_REGNUM), \
+ DEFINE_VMX_PPC64(vr5, LLDB_INVALID_REGNUM), \
+ DEFINE_VMX_PPC64(vr6, LLDB_INVALID_REGNUM), \
+ DEFINE_VMX_PPC64(vr7, LLDB_INVALID_REGNUM), \
+ DEFINE_VMX_PPC64(vr8, LLDB_INVALID_REGNUM), \
+ DEFINE_VMX_PPC64(vr9, LLDB_INVALID_REGNUM), \
+ DEFINE_VMX_PPC64(vr10, LLDB_INVALID_REGNUM), \
+ DEFINE_VMX_PPC64(vr11, LLDB_INVALID_REGNUM), \
+ DEFINE_VMX_PPC64(vr12, LLDB_INVALID_REGNUM), \
+ DEFINE_VMX_PPC64(vr13, LLDB_INVALID_REGNUM), \
+ DEFINE_VMX_PPC64(vr14, LLDB_INVALID_REGNUM), \
+ DEFINE_VMX_PPC64(vr15, LLDB_INVALID_REGNUM), \
+ DEFINE_VMX_PPC64(vr16, LLDB_INVALID_REGNUM), \
+ DEFINE_VMX_PPC64(vr17, LLDB_INVALID_REGNUM), \
+ DEFINE_VMX_PPC64(vr18, LLDB_INVALID_REGNUM), \
+ DEFINE_VMX_PPC64(vr19, LLDB_INVALID_REGNUM), \
+ DEFINE_VMX_PPC64(vr20, LLDB_INVALID_REGNUM), \
+ DEFINE_VMX_PPC64(vr21, LLDB_INVALID_REGNUM), \
+ DEFINE_VMX_PPC64(vr22, LLDB_INVALID_REGNUM), \
+ DEFINE_VMX_PPC64(vr23, LLDB_INVALID_REGNUM), \
+ DEFINE_VMX_PPC64(vr24, LLDB_INVALID_REGNUM), \
+ DEFINE_VMX_PPC64(vr25, LLDB_INVALID_REGNUM), \
+ DEFINE_VMX_PPC64(vr26, LLDB_INVALID_REGNUM), \
+ DEFINE_VMX_PPC64(vr27, LLDB_INVALID_REGNUM), \
+ DEFINE_VMX_PPC64(vr28, LLDB_INVALID_REGNUM), \
+ DEFINE_VMX_PPC64(vr29, LLDB_INVALID_REGNUM), \
+ DEFINE_VMX_PPC64(vr30, LLDB_INVALID_REGNUM), \
+ DEFINE_VMX_PPC64(vr31, LLDB_INVALID_REGNUM), \
+ {"vscr", \
+ NULL, \
+ 4, \
+ VMX_PPC64_OFFSET(vscr), \
+ lldb::eEncodingUint, \
+ lldb::eFormatHex, \
+ {ppc64_dwarf::dwarf_vscr_ppc64, ppc64_dwarf::dwarf_vscr_ppc64, \
+ LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, vmx_vscr_ppc64}, \
+ NULL, \
+ NULL, \
+ NULL, \
+ 0}, \
+ {"vrsave", \
+ NULL, \
+ 4, \
+ VMX_PPC64_OFFSET(vrsave), \
+ lldb::eEncodingUint, \
+ lldb::eFormatHex, \
+ {ppc64_dwarf::dwarf_vrsave_ppc64, \
+ ppc64_dwarf::dwarf_vrsave_ppc64, LLDB_INVALID_REGNUM, \
+ LLDB_INVALID_REGNUM, vmx_vrsave_ppc64}, \
+ NULL, \
+ NULL, \
+ NULL, \
+ 0}, /* */
+
+typedef struct _GPR_PPC64 {
+ uint64_t r0;
+ uint64_t r1;
+ uint64_t r2;
+ uint64_t r3;
+ uint64_t r4;
+ uint64_t r5;
+ uint64_t r6;
+ uint64_t r7;
+ uint64_t r8;
+ uint64_t r9;
+ uint64_t r10;
+ uint64_t r11;
+ uint64_t r12;
+ uint64_t r13;
+ uint64_t r14;
+ uint64_t r15;
+ uint64_t r16;
+ uint64_t r17;
+ uint64_t r18;
+ uint64_t r19;
+ uint64_t r20;
+ uint64_t r21;
+ uint64_t r22;
+ uint64_t r23;
+ uint64_t r24;
+ uint64_t r25;
+ uint64_t r26;
+ uint64_t r27;
+ uint64_t r28;
+ uint64_t r29;
+ uint64_t r30;
+ uint64_t r31;
+ uint64_t cr;
+ uint64_t msr;
+ uint64_t xer;
+ uint64_t lr;
+ uint64_t ctr;
+ uint64_t pc;
+ uint64_t pad[3];
+} GPR_PPC64;
+
+typedef struct _FPR_PPC64 {
+ uint64_t f0;
+ uint64_t f1;
+ uint64_t f2;
+ uint64_t f3;
+ uint64_t f4;
+ uint64_t f5;
+ uint64_t f6;
+ uint64_t f7;
+ uint64_t f8;
+ uint64_t f9;
+ uint64_t f10;
+ uint64_t f11;
+ uint64_t f12;
+ uint64_t f13;
+ uint64_t f14;
+ uint64_t f15;
+ uint64_t f16;
+ uint64_t f17;
+ uint64_t f18;
+ uint64_t f19;
+ uint64_t f20;
+ uint64_t f21;
+ uint64_t f22;
+ uint64_t f23;
+ uint64_t f24;
+ uint64_t f25;
+ uint64_t f26;
+ uint64_t f27;
+ uint64_t f28;
+ uint64_t f29;
+ uint64_t f30;
+ uint64_t f31;
+ uint64_t fpscr;
+} FPR_PPC64;
+
+typedef struct _VMX_PPC64 {
+ uint32_t vr0[4];
+ uint32_t vr1[4];
+ uint32_t vr2[4];
+ uint32_t vr3[4];
+ uint32_t vr4[4];
+ uint32_t vr5[4];
+ uint32_t vr6[4];
+ uint32_t vr7[4];
+ uint32_t vr8[4];
+ uint32_t vr9[4];
+ uint32_t vr10[4];
+ uint32_t vr11[4];
+ uint32_t vr12[4];
+ uint32_t vr13[4];
+ uint32_t vr14[4];
+ uint32_t vr15[4];
+ uint32_t vr16[4];
+ uint32_t vr17[4];
+ uint32_t vr18[4];
+ uint32_t vr19[4];
+ uint32_t vr20[4];
+ uint32_t vr21[4];
+ uint32_t vr22[4];
+ uint32_t vr23[4];
+ uint32_t vr24[4];
+ uint32_t vr25[4];
+ uint32_t vr26[4];
+ uint32_t vr27[4];
+ uint32_t vr28[4];
+ uint32_t vr29[4];
+ uint32_t vr30[4];
+ uint32_t vr31[4];
+ uint32_t pad[2];
+ uint32_t vscr[2];
+ uint32_t vrsave;
+} VMX_PPC64;
+
+
+static lldb_private::RegisterInfo g_register_infos_ppc64[] = {
+ PPC64_REGS
+};
+
+static_assert((sizeof(g_register_infos_ppc64) /
+ sizeof(g_register_infos_ppc64[0])) ==
+ k_num_registers_ppc64,
+ "g_register_infos_powerpc64 has wrong number of register infos");
+
+#undef DEFINE_FPR_PPC64
+#undef DEFINE_GPR_PPC64
+#undef DEFINE_VMX_PPC64
+
+#endif // DECLARE_REGISTER_INFOS_PPC64_STRUCT
diff --git a/source/Plugins/Process/Utility/StopInfoMachException.cpp b/source/Plugins/Process/Utility/StopInfoMachException.cpp
index 3e860874183cf..3dbfe611e7133 100644
--- a/source/Plugins/Process/Utility/StopInfoMachException.cpp
+++ b/source/Plugins/Process/Utility/StopInfoMachException.cpp
@@ -356,8 +356,8 @@ StopInfoSP StopInfoMachException::CreateStopReasonWithMachException(
if (exc_code == 0x10003) // EXC_SOFT_SIGNAL
{
if (exc_sub_code == 5) {
- // On MacOSX, a SIGTRAP can signify that a process has called
- // exec, so we should check with our dynamic loader to verify.
+ // On MacOSX, a SIGTRAP can signify that a process has called exec,
+ // so we should check with our dynamic loader to verify.
ProcessSP process_sp(thread.GetProcess());
if (process_sp) {
DynamicLoader *dynamic_loader = process_sp->GetDynamicLoader();
@@ -403,10 +403,8 @@ StopInfoSP StopInfoMachException::CreateStopReasonWithMachException(
if (!exc_sub_code) {
// This looks like a plain trap.
// Have to check if there is a breakpoint here as well. When you
- // single-step onto a trap,
- // the single step stops you not to trap. Since we also do that
- // check below, let's just use
- // that logic.
+ // single-step onto a trap, the single step stops you not to trap.
+ // Since we also do that check below, let's just use that logic.
is_actual_breakpoint = true;
is_trace_if_actual_breakpoint_missing = true;
} else {
@@ -419,8 +417,8 @@ StopInfoSP StopInfoMachException::CreateStopReasonWithMachException(
(lldb::addr_t)exc_sub_code);
if (wp_sp && wp_sp->IsEnabled()) {
// Debugserver may piggyback the hardware index of the fired
- // watchpoint in the exception data.
- // Set the hardware index if that's the case.
+ // watchpoint in the exception data. Set the hardware index if
+ // that's the case.
if (exc_data_count >= 3)
wp_sp->SetHardwareIndex((uint32_t)exc_sub_sub_code);
return StopInfo::CreateStopReasonWithWatchpointID(thread,
@@ -450,16 +448,15 @@ StopInfoSP StopInfoMachException::CreateStopReasonWithMachException(
if (exc_code == 0x102) // EXC_ARM_DA_DEBUG
{
// It's a watchpoint, then, if the exc_sub_code indicates a
- // known/enabled
- // data break address from our watchpoint list.
+ // known/enabled data break address from our watchpoint list.
lldb::WatchpointSP wp_sp;
if (target)
wp_sp = target->GetWatchpointList().FindByAddress(
(lldb::addr_t)exc_sub_code);
if (wp_sp && wp_sp->IsEnabled()) {
// Debugserver may piggyback the hardware index of the fired
- // watchpoint in the exception data.
- // Set the hardware index if that's the case.
+ // watchpoint in the exception data. Set the hardware index if
+ // that's the case.
if (exc_data_count >= 3)
wp_sp->SetHardwareIndex((uint32_t)exc_sub_sub_code);
return StopInfo::CreateStopReasonWithWatchpointID(thread,
@@ -473,9 +470,9 @@ StopInfoSP StopInfoMachException::CreateStopReasonWithMachException(
is_actual_breakpoint = true;
is_trace_if_actual_breakpoint_missing = true;
} else if (exc_code == 0) // FIXME not EXC_ARM_BREAKPOINT but a kernel
- // is currently returning this so accept it as
- // indicating a breakpoint until the kernel is
- // fixed
+ // is currently returning this so accept it
+ // as indicating a breakpoint until the
+ // kernel is fixed
{
is_actual_breakpoint = true;
is_trace_if_actual_breakpoint_missing = true;
@@ -493,16 +490,15 @@ StopInfoSP StopInfoMachException::CreateStopReasonWithMachException(
if (exc_code == 0x102) // EXC_ARM_DA_DEBUG
{
// It's a watchpoint, then, if the exc_sub_code indicates a
- // known/enabled
- // data break address from our watchpoint list.
+ // known/enabled data break address from our watchpoint list.
lldb::WatchpointSP wp_sp;
if (target)
wp_sp = target->GetWatchpointList().FindByAddress(
(lldb::addr_t)exc_sub_code);
if (wp_sp && wp_sp->IsEnabled()) {
// Debugserver may piggyback the hardware index of the fired
- // watchpoint in the exception data.
- // Set the hardware index if that's the case.
+ // watchpoint in the exception data. Set the hardware index if
+ // that's the case.
if (exc_data_count >= 3)
wp_sp->SetHardwareIndex((uint32_t)exc_sub_sub_code);
return StopInfo::CreateStopReasonWithWatchpointID(thread,
@@ -514,8 +510,7 @@ StopInfoSP StopInfoMachException::CreateStopReasonWithMachException(
return StopInfo::CreateStopReasonToTrace(thread);
}
// It looks like exc_sub_code has the 4 bytes of the instruction that
- // triggered the
- // exception, i.e. our breakpoint opcode
+ // triggered the exception, i.e. our breakpoint opcode
is_actual_breakpoint = exc_code == 1;
break;
}
@@ -534,23 +529,21 @@ StopInfoSP StopInfoMachException::CreateStopReasonWithMachException(
if (process_sp)
bp_site_sp = process_sp->GetBreakpointSiteList().FindByAddress(pc);
if (bp_site_sp && bp_site_sp->IsEnabled()) {
- // Update the PC if we were asked to do so, but only do
- // so if we find a breakpoint that we know about cause
- // this could be a trap instruction in the code
+ // Update the PC if we were asked to do so, but only do so if we find
+ // a breakpoint that we know about cause this could be a trap
+ // instruction in the code
if (pc_decrement > 0 && adjust_pc_if_needed)
reg_ctx_sp->SetPC(pc);
// If the breakpoint is for this thread, then we'll report the hit,
- // but if it is for another thread,
- // we can just report no reason. We don't need to worry about
- // stepping over the breakpoint here, that
+ // but if it is for another thread, we can just report no reason. We
+ // don't need to worry about stepping over the breakpoint here, that
// will be taken care of when the thread resumes and notices that
- // there's a breakpoint under the pc.
- // If we have an operating system plug-in, we might have set a thread
- // specific breakpoint using the
+ // there's a breakpoint under the pc. If we have an operating system
+ // plug-in, we might have set a thread specific breakpoint using the
// operating system thread ID, so we can't make any assumptions about
- // the thread ID so we must always
- // report the breakpoint regardless of the thread.
+ // the thread ID so we must always report the breakpoint regardless
+ // of the thread.
if (bp_site_sp->ValidForThisThread(&thread) ||
thread.GetProcess()->GetOperatingSystem() != NULL)
return StopInfo::CreateStopReasonWithBreakpointSiteID(
diff --git a/source/Plugins/Process/Utility/ThreadMemory.cpp b/source/Plugins/Process/Utility/ThreadMemory.cpp
index 5ff928c69e591..0c7c195815a46 100644
--- a/source/Plugins/Process/Utility/ThreadMemory.cpp
+++ b/source/Plugins/Process/Utility/ThreadMemory.cpp
@@ -62,7 +62,7 @@ ThreadMemory::CreateRegisterContextForFrame(StackFrame *frame) {
reg_ctx_sp = GetRegisterContext();
} else {
Unwind *unwinder = GetUnwinder();
- if (unwinder)
+ if (unwinder != nullptr)
reg_ctx_sp = unwinder->CreateRegisterContextForFrame(frame);
}
return reg_ctx_sp;
diff --git a/source/Plugins/Process/Utility/UnwindLLDB.cpp b/source/Plugins/Process/Utility/UnwindLLDB.cpp
index 2b34bddd90b2f..55559f07f1e5a 100644
--- a/source/Plugins/Process/Utility/UnwindLLDB.cpp
+++ b/source/Plugins/Process/Utility/UnwindLLDB.cpp
@@ -132,16 +132,12 @@ UnwindLLDB::CursorSP UnwindLLDB::GetOneMoreFrame(ABI *abi) {
// We want to detect an unwind that cycles erroneously and stop backtracing.
// Don't want this maximum unwind limit to be too low -- if you have a
- // backtrace
- // with an "infinitely recursing" bug, it will crash when the stack blows out
- // and the first 35,000 frames are uninteresting - it's the top most 5 frames
- // that
- // you actually care about. So you can't just cap the unwind at 10,000 or
- // something.
- // Realistically anything over around 200,000 is going to blow out the stack
- // space.
- // If we're still unwinding at that point, we're probably never going to
- // finish.
+ // backtrace with an "infinitely recursing" bug, it will crash when the stack
+ // blows out and the first 35,000 frames are uninteresting - it's the top
+ // most 5 frames that you actually care about. So you can't just cap the
+ // unwind at 10,000 or something. Realistically anything over around 200,000
+ // is going to blow out the stack space. If we're still unwinding at that
+ // point, we're probably never going to finish.
if (cur_idx > 300000) {
if (log)
log->Printf("%*sFrame %d unwound too many frames, assuming unwind has "
@@ -152,13 +148,12 @@ UnwindLLDB::CursorSP UnwindLLDB::GetOneMoreFrame(ABI *abi) {
if (reg_ctx_sp.get() == NULL) {
// If the RegisterContextLLDB has a fallback UnwindPlan, it will switch to
- // that and return
- // true. Subsequent calls to TryFallbackUnwindPlan() will return false.
+ // that and return true. Subsequent calls to TryFallbackUnwindPlan() will
+ // return false.
if (prev_frame->reg_ctx_lldb_sp->TryFallbackUnwindPlan()) {
// TryFallbackUnwindPlan for prev_frame succeeded and updated
- // reg_ctx_lldb_sp field of
- // prev_frame. However, cfa field of prev_frame still needs to be updated.
- // Hence updating it.
+ // reg_ctx_lldb_sp field of prev_frame. However, cfa field of prev_frame
+ // still needs to be updated. Hence updating it.
if (!(prev_frame->reg_ctx_lldb_sp->GetCFA(prev_frame->cfa)))
return nullptr;
@@ -172,15 +167,13 @@ UnwindLLDB::CursorSP UnwindLLDB::GetOneMoreFrame(ABI *abi) {
}
if (!reg_ctx_sp->IsValid()) {
- // We failed to get a valid RegisterContext.
- // See if the regctx below this on the stack has a fallback unwind plan it
- // can use.
- // Subsequent calls to TryFallbackUnwindPlan() will return false.
+ // We failed to get a valid RegisterContext. See if the regctx below this
+ // on the stack has a fallback unwind plan it can use. Subsequent calls to
+ // TryFallbackUnwindPlan() will return false.
if (prev_frame->reg_ctx_lldb_sp->TryFallbackUnwindPlan()) {
// TryFallbackUnwindPlan for prev_frame succeeded and updated
- // reg_ctx_lldb_sp field of
- // prev_frame. However, cfa field of prev_frame still needs to be updated.
- // Hence updating it.
+ // reg_ctx_lldb_sp field of prev_frame. However, cfa field of prev_frame
+ // still needs to be updated. Hence updating it.
if (!(prev_frame->reg_ctx_lldb_sp->GetCFA(prev_frame->cfa)))
return nullptr;
@@ -195,13 +188,12 @@ UnwindLLDB::CursorSP UnwindLLDB::GetOneMoreFrame(ABI *abi) {
}
if (!reg_ctx_sp->GetCFA(cursor_sp->cfa)) {
// If the RegisterContextLLDB has a fallback UnwindPlan, it will switch to
- // that and return
- // true. Subsequent calls to TryFallbackUnwindPlan() will return false.
+ // that and return true. Subsequent calls to TryFallbackUnwindPlan() will
+ // return false.
if (prev_frame->reg_ctx_lldb_sp->TryFallbackUnwindPlan()) {
// TryFallbackUnwindPlan for prev_frame succeeded and updated
- // reg_ctx_lldb_sp field of
- // prev_frame. However, cfa field of prev_frame still needs to be updated.
- // Hence updating it.
+ // reg_ctx_lldb_sp field of prev_frame. However, cfa field of prev_frame
+ // still needs to be updated. Hence updating it.
if (!(prev_frame->reg_ctx_lldb_sp->GetCFA(prev_frame->cfa)))
return nullptr;
@@ -216,27 +208,21 @@ UnwindLLDB::CursorSP UnwindLLDB::GetOneMoreFrame(ABI *abi) {
}
if (abi && !abi->CallFrameAddressIsValid(cursor_sp->cfa)) {
// On Mac OS X, the _sigtramp asynchronous signal trampoline frame may not
- // have
- // its (constructed) CFA aligned correctly -- don't do the abi alignment
- // check for
- // these.
+ // have its (constructed) CFA aligned correctly -- don't do the abi
+ // alignment check for these.
if (reg_ctx_sp->IsTrapHandlerFrame() == false) {
// See if we can find a fallback unwind plan for THIS frame. It may be
// that the UnwindPlan we're using for THIS frame was bad and gave us a
- // bad CFA.
- // If that's not it, then see if we can change the UnwindPlan for the
- // frame
- // below us ("NEXT") -- see if using that other UnwindPlan gets us a
- // better
- // unwind state.
+ // bad CFA. If that's not it, then see if we can change the UnwindPlan
+ // for the frame below us ("NEXT") -- see if using that other UnwindPlan
+ // gets us a better unwind state.
if (reg_ctx_sp->TryFallbackUnwindPlan() == false ||
reg_ctx_sp->GetCFA(cursor_sp->cfa) == false ||
abi->CallFrameAddressIsValid(cursor_sp->cfa) == false) {
if (prev_frame->reg_ctx_lldb_sp->TryFallbackUnwindPlan()) {
// TryFallbackUnwindPlan for prev_frame succeeded and updated
- // reg_ctx_lldb_sp field of
- // prev_frame. However, cfa field of prev_frame still needs to be
- // updated. Hence updating it.
+ // reg_ctx_lldb_sp field of prev_frame. However, cfa field of
+ // prev_frame still needs to be updated. Hence updating it.
if (!(prev_frame->reg_ctx_lldb_sp->GetCFA(prev_frame->cfa)))
return nullptr;
@@ -259,13 +245,12 @@ UnwindLLDB::CursorSP UnwindLLDB::GetOneMoreFrame(ABI *abi) {
}
if (!reg_ctx_sp->ReadPC(cursor_sp->start_pc)) {
// If the RegisterContextLLDB has a fallback UnwindPlan, it will switch to
- // that and return
- // true. Subsequent calls to TryFallbackUnwindPlan() will return false.
+ // that and return true. Subsequent calls to TryFallbackUnwindPlan() will
+ // return false.
if (prev_frame->reg_ctx_lldb_sp->TryFallbackUnwindPlan()) {
// TryFallbackUnwindPlan for prev_frame succeeded and updated
- // reg_ctx_lldb_sp field of
- // prev_frame. However, cfa field of prev_frame still needs to be updated.
- // Hence updating it.
+ // reg_ctx_lldb_sp field of prev_frame. However, cfa field of prev_frame
+ // still needs to be updated. Hence updating it.
if (!(prev_frame->reg_ctx_lldb_sp->GetCFA(prev_frame->cfa)))
return nullptr;
@@ -280,13 +265,12 @@ UnwindLLDB::CursorSP UnwindLLDB::GetOneMoreFrame(ABI *abi) {
}
if (abi && !abi->CodeAddressIsValid(cursor_sp->start_pc)) {
// If the RegisterContextLLDB has a fallback UnwindPlan, it will switch to
- // that and return
- // true. Subsequent calls to TryFallbackUnwindPlan() will return false.
+ // that and return true. Subsequent calls to TryFallbackUnwindPlan() will
+ // return false.
if (prev_frame->reg_ctx_lldb_sp->TryFallbackUnwindPlan()) {
// TryFallbackUnwindPlan for prev_frame succeeded and updated
- // reg_ctx_lldb_sp field of
- // prev_frame. However, cfa field of prev_frame still needs to be updated.
- // Hence updating it.
+ // reg_ctx_lldb_sp field of prev_frame. However, cfa field of prev_frame
+ // still needs to be updated. Hence updating it.
if (!(prev_frame->reg_ctx_lldb_sp->GetCFA(prev_frame->cfa)))
return nullptr;
@@ -320,13 +304,12 @@ void UnwindLLDB::UpdateUnwindPlanForFirstFrameIfInvalid(ABI *abi) {
CursorSP old_m_candidate_frame = m_candidate_frame;
// Try to unwind 2 more frames using the Unwinder. It uses Full UnwindPlan
- // and if Full UnwindPlan fails, then uses FallBack UnwindPlan. Also
- // update the cfa of Frame 0 (if required).
+ // and if Full UnwindPlan fails, then uses FallBack UnwindPlan. Also update
+ // the cfa of Frame 0 (if required).
AddOneMoreFrame(abi);
- // Remove all the frames added by above function as the purpose of
- // using above function was just to check whether Unwinder of Frame 0
- // works or not.
+ // Remove all the frames added by above function as the purpose of using
+ // above function was just to check whether Unwinder of Frame 0 works or not.
for (uint32_t i = 1; i < m_frames.size(); i++)
m_frames.pop_back();
@@ -362,51 +345,44 @@ bool UnwindLLDB::AddOneMoreFrame(ABI *abi) {
m_frames.push_back(new_frame);
- // If we can get one more frame further then accept that we get back a correct
- // frame.
+ // If we can get one more frame further then accept that we get back a
+ // correct frame.
m_candidate_frame = GetOneMoreFrame(abi);
if (m_candidate_frame)
return true;
// We can't go further from the frame returned by GetOneMore frame. Lets try
- // to get a
- // different frame with using the fallback unwind plan.
+ // to get a different frame with using the fallback unwind plan.
if (!m_frames[m_frames.size() - 2]
->reg_ctx_lldb_sp->TryFallbackUnwindPlan()) {
// We don't have a valid fallback unwind plan. Accept the frame as it is.
- // This is a
- // valid situation when we are at the bottom of the stack.
+ // This is a valid situation when we are at the bottom of the stack.
return true;
}
// Remove the possibly incorrect frame from the frame list and try to add a
- // different one with
- // the newly selected fallback unwind plan.
+ // different one with the newly selected fallback unwind plan.
m_frames.pop_back();
CursorSP new_frame_v2 = GetOneMoreFrame(abi);
if (new_frame_v2 == nullptr) {
// We haven't got a new frame from the fallback unwind plan. Accept the
- // frame from the
- // original unwind plan. This is a valid situation when we are at the bottom
- // of the stack.
+ // frame from the original unwind plan. This is a valid situation when we
+ // are at the bottom of the stack.
m_frames.push_back(new_frame);
return true;
}
// Push the new frame to the list and try to continue from this frame. If we
- // can get a new frame
- // then accept it as the correct one.
+ // can get a new frame then accept it as the correct one.
m_frames.push_back(new_frame_v2);
m_candidate_frame = GetOneMoreFrame(abi);
if (m_candidate_frame) {
// If control reached here then TryFallbackUnwindPlan had succeeded for
- // Cursor::m_frames[m_frames.size() - 2].
- // It also succeeded to Unwind next 2 frames i.e. m_frames[m_frames.size() -
- // 1] and a frame after that.
- // For Cursor::m_frames[m_frames.size() - 2], reg_ctx_lldb_sp field was
- // already updated during TryFallbackUnwindPlan
- // call above. However, cfa field still needs to be updated. Hence updating
- // it here and then returning.
+ // Cursor::m_frames[m_frames.size() - 2]. It also succeeded to Unwind next
+ // 2 frames i.e. m_frames[m_frames.size() - 1] and a frame after that. For
+ // Cursor::m_frames[m_frames.size() - 2], reg_ctx_lldb_sp field was already
+ // updated during TryFallbackUnwindPlan call above. However, cfa field
+ // still needs to be updated. Hence updating it here and then returning.
if (!(m_frames[m_frames.size() - 2]->reg_ctx_lldb_sp->GetCFA(
m_frames[m_frames.size() - 2]->cfa)))
return false;
@@ -414,8 +390,7 @@ bool UnwindLLDB::AddOneMoreFrame(ABI *abi) {
}
// The new frame hasn't helped in unwinding. Fall back to the original one as
- // the default unwind
- // plan is usually more reliable then the fallback one.
+ // the default unwind plan is usually more reliable then the fallback one.
m_frames.pop_back();
m_frames.push_back(new_frame);
return true;
@@ -486,10 +461,9 @@ bool UnwindLLDB::SearchForSavedLocationForRegister(
if (static_cast<size_t>(frame_num) >= m_frames.size())
return false;
- // Never interrogate more than one level while looking for the saved pc value.
- // If the value
- // isn't saved by frame_num, none of the frames lower on the stack will have a
- // useful value.
+ // Never interrogate more than one level while looking for the saved pc
+ // value. If the value isn't saved by frame_num, none of the frames lower on
+ // the stack will have a useful value.
if (pc_reg) {
UnwindLLDB::RegisterSearchResult result;
result = m_frames[frame_num]->reg_ctx_lldb_sp->SavedLocationForRegister(
@@ -505,8 +479,7 @@ bool UnwindLLDB::SearchForSavedLocationForRegister(
lldb_regnum, regloc);
// We descended down to the live register context aka stack frame 0 and are
- // reading the value
- // out of a live register.
+ // reading the value out of a live register.
if (result == UnwindLLDB::RegisterSearchResult::eRegisterFound &&
regloc.type ==
UnwindLLDB::RegisterLocation::eRegisterInLiveRegisterContext) {
@@ -514,11 +487,9 @@ bool UnwindLLDB::SearchForSavedLocationForRegister(
}
// If we have unwind instructions saying that register N is saved in
- // register M in the middle of
- // the stack (and N can equal M here, meaning the register was not used in
- // this function), then
- // change the register number we're looking for to M and keep looking for a
- // concrete location
+ // register M in the middle of the stack (and N can equal M here, meaning
+ // the register was not used in this function), then change the register
+ // number we're looking for to M and keep looking for a concrete location
// down the stack, or an actual value from a live RegisterContext at frame
// 0.
if (result == UnwindLLDB::RegisterSearchResult::eRegisterFound &&
diff --git a/source/Plugins/Process/Utility/UnwindLLDB.h b/source/Plugins/Process/Utility/UnwindLLDB.h
index 3f84649aa05f8..3d1f85a3dec3f 100644
--- a/source/Plugins/Process/Utility/UnwindLLDB.h
+++ b/source/Plugins/Process/Utility/UnwindLLDB.h
@@ -17,6 +17,7 @@
// Other libraries and framework includes
// Project includes
#include "lldb/Symbol/FuncUnwinders.h"
+#include "lldb/Symbol/SymbolContext.h"
#include "lldb/Symbol/UnwindPlan.h"
#include "lldb/Target/RegisterContext.h"
#include "lldb/Target/Unwind.h"
diff --git a/source/Plugins/Process/Utility/UnwindMacOSXFrameBackchain.cpp b/source/Plugins/Process/Utility/UnwindMacOSXFrameBackchain.cpp
index d831011cb6612..2115b4e179c08 100644
--- a/source/Plugins/Process/Utility/UnwindMacOSXFrameBackchain.cpp
+++ b/source/Plugins/Process/Utility/UnwindMacOSXFrameBackchain.cpp
@@ -133,8 +133,8 @@ size_t UnwindMacOSXFrameBackchain::GetStackFrameData_i386(
if (addr_range_ptr) {
if (first_frame->GetFrameCodeAddress() ==
addr_range_ptr->GetBaseAddress()) {
- // We are at the first instruction, so we can recover the
- // previous PC by dereferencing the SP
+ // We are at the first instruction, so we can recover the previous PC
+ // by dereferencing the SP
lldb::addr_t first_frame_sp = reg_ctx->GetSP(0);
// Read the real second frame return address into frame.pc
if (first_frame_sp &&
@@ -224,8 +224,8 @@ size_t UnwindMacOSXFrameBackchain::GetStackFrameData_x86_64(
if (addr_range_ptr) {
if (first_frame->GetFrameCodeAddress() ==
addr_range_ptr->GetBaseAddress()) {
- // We are at the first instruction, so we can recover the
- // previous PC by dereferencing the SP
+ // We are at the first instruction, so we can recover the previous PC
+ // by dereferencing the SP
lldb::addr_t first_frame_sp = reg_ctx->GetSP(0);
// Read the real second frame return address into frame.pc
if (process->ReadMemory(first_frame_sp, &frame.pc, sizeof(frame.pc),
diff --git a/source/Plugins/Process/Utility/lldb-ppc64-register-enums.h b/source/Plugins/Process/Utility/lldb-ppc64-register-enums.h
new file mode 100644
index 0000000000000..9ea81c00b6668
--- /dev/null
+++ b/source/Plugins/Process/Utility/lldb-ppc64-register-enums.h
@@ -0,0 +1,139 @@
+//===-- lldb-ppc64-register-enums.h ---------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef lldb_ppc64_register_enums_h
+#define lldb_ppc64_register_enums_h
+
+// LLDB register codes (e.g. RegisterKind == eRegisterKindLLDB)
+
+// ---------------------------------------------------------------------------
+// Internal codes for all ppc64 registers.
+// ---------------------------------------------------------------------------
+enum {
+ k_first_gpr_ppc64,
+ gpr_r0_ppc64 = k_first_gpr_ppc64,
+ gpr_r1_ppc64,
+ gpr_r2_ppc64,
+ gpr_r3_ppc64,
+ gpr_r4_ppc64,
+ gpr_r5_ppc64,
+ gpr_r6_ppc64,
+ gpr_r7_ppc64,
+ gpr_r8_ppc64,
+ gpr_r9_ppc64,
+ gpr_r10_ppc64,
+ gpr_r11_ppc64,
+ gpr_r12_ppc64,
+ gpr_r13_ppc64,
+ gpr_r14_ppc64,
+ gpr_r15_ppc64,
+ gpr_r16_ppc64,
+ gpr_r17_ppc64,
+ gpr_r18_ppc64,
+ gpr_r19_ppc64,
+ gpr_r20_ppc64,
+ gpr_r21_ppc64,
+ gpr_r22_ppc64,
+ gpr_r23_ppc64,
+ gpr_r24_ppc64,
+ gpr_r25_ppc64,
+ gpr_r26_ppc64,
+ gpr_r27_ppc64,
+ gpr_r28_ppc64,
+ gpr_r29_ppc64,
+ gpr_r30_ppc64,
+ gpr_r31_ppc64,
+ gpr_cr_ppc64,
+ gpr_msr_ppc64,
+ gpr_xer_ppc64,
+ gpr_lr_ppc64,
+ gpr_ctr_ppc64,
+ gpr_pc_ppc64,
+ k_last_gpr_ppc64 = gpr_pc_ppc64,
+
+ k_first_fpr_ppc64,
+ fpr_f0_ppc64 = k_first_fpr_ppc64,
+ fpr_f1_ppc64,
+ fpr_f2_ppc64,
+ fpr_f3_ppc64,
+ fpr_f4_ppc64,
+ fpr_f5_ppc64,
+ fpr_f6_ppc64,
+ fpr_f7_ppc64,
+ fpr_f8_ppc64,
+ fpr_f9_ppc64,
+ fpr_f10_ppc64,
+ fpr_f11_ppc64,
+ fpr_f12_ppc64,
+ fpr_f13_ppc64,
+ fpr_f14_ppc64,
+ fpr_f15_ppc64,
+ fpr_f16_ppc64,
+ fpr_f17_ppc64,
+ fpr_f18_ppc64,
+ fpr_f19_ppc64,
+ fpr_f20_ppc64,
+ fpr_f21_ppc64,
+ fpr_f22_ppc64,
+ fpr_f23_ppc64,
+ fpr_f24_ppc64,
+ fpr_f25_ppc64,
+ fpr_f26_ppc64,
+ fpr_f27_ppc64,
+ fpr_f28_ppc64,
+ fpr_f29_ppc64,
+ fpr_f30_ppc64,
+ fpr_f31_ppc64,
+ fpr_fpscr_ppc64,
+ k_last_fpr_ppc64 = fpr_fpscr_ppc64,
+
+ k_first_vmx_ppc64,
+ vmx_vr0_ppc64 = k_first_vmx_ppc64,
+ vmx_vr1_ppc64,
+ vmx_vr2_ppc64,
+ vmx_vr3_ppc64,
+ vmx_vr4_ppc64,
+ vmx_vr5_ppc64,
+ vmx_vr6_ppc64,
+ vmx_vr7_ppc64,
+ vmx_vr8_ppc64,
+ vmx_vr9_ppc64,
+ vmx_vr10_ppc64,
+ vmx_vr11_ppc64,
+ vmx_vr12_ppc64,
+ vmx_vr13_ppc64,
+ vmx_vr14_ppc64,
+ vmx_vr15_ppc64,
+ vmx_vr16_ppc64,
+ vmx_vr17_ppc64,
+ vmx_vr18_ppc64,
+ vmx_vr19_ppc64,
+ vmx_vr20_ppc64,
+ vmx_vr21_ppc64,
+ vmx_vr22_ppc64,
+ vmx_vr23_ppc64,
+ vmx_vr24_ppc64,
+ vmx_vr25_ppc64,
+ vmx_vr26_ppc64,
+ vmx_vr27_ppc64,
+ vmx_vr28_ppc64,
+ vmx_vr29_ppc64,
+ vmx_vr30_ppc64,
+ vmx_vr31_ppc64,
+ vmx_vscr_ppc64,
+ vmx_vrsave_ppc64,
+ k_last_vmx_ppc64 = vmx_vrsave_ppc64,
+
+ k_num_registers_ppc64,
+ k_num_gpr_registers_ppc64 = k_last_gpr_ppc64 - k_first_gpr_ppc64 + 1,
+ k_num_fpr_registers_ppc64 = k_last_fpr_ppc64 - k_first_fpr_ppc64 + 1,
+ k_num_vmx_registers_ppc64 = k_last_vmx_ppc64 - k_first_vmx_ppc64 + 1,
+};
+
+#endif // #ifndef lldb_ppc64_register_enums_h
diff --git a/source/Plugins/Process/Windows/Common/CMakeLists.txt b/source/Plugins/Process/Windows/Common/CMakeLists.txt
index 009a289bae399..0926290861833 100644
--- a/source/Plugins/Process/Windows/Common/CMakeLists.txt
+++ b/source/Plugins/Process/Windows/Common/CMakeLists.txt
@@ -1,6 +1,3 @@
-include_directories(.)
-include_directories(../../Utility)
-
set(PROC_WINDOWS_COMMON_SOURCES
DebuggerThread.cpp
LocalDebugDelegate.cpp
diff --git a/source/Plugins/Process/Windows/Common/DebuggerThread.cpp b/source/Plugins/Process/Windows/Common/DebuggerThread.cpp
index ac9e65c3c1083..ad43551a4c6db 100644
--- a/source/Plugins/Process/Windows/Common/DebuggerThread.cpp
+++ b/source/Plugins/Process/Windows/Common/DebuggerThread.cpp
@@ -112,8 +112,7 @@ lldb::thread_result_t DebuggerThread::DebuggerThreadAttachRoutine(void *data) {
lldb::thread_result_t DebuggerThread::DebuggerThreadLaunchRoutine(
const ProcessLaunchInfo &launch_info) {
// Grab a shared_ptr reference to this so that we know it won't get deleted
- // until after the
- // thread routine has exited.
+ // until after the thread routine has exited.
std::shared_ptr<DebuggerThread> this_ref(shared_from_this());
Log *log = ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_PROCESS);
@@ -124,14 +123,11 @@ lldb::thread_result_t DebuggerThread::DebuggerThreadLaunchRoutine(
ProcessLauncherWindows launcher;
HostProcess process(launcher.LaunchProcess(launch_info, error));
// If we couldn't create the process, notify waiters immediately. Otherwise
- // enter the debug
- // loop and wait until we get the create process debug notification. Note
- // that if the process
- // was created successfully, we can throw away the process handle we got from
- // CreateProcess
- // because Windows will give us another (potentially more useful?) handle when
- // it sends us the
- // CREATE_PROCESS_DEBUG_EVENT.
+ // enter the debug loop and wait until we get the create process debug
+ // notification. Note that if the process was created successfully, we can
+ // throw away the process handle we got from CreateProcess because Windows
+ // will give us another (potentially more useful?) handle when it sends us
+ // the CREATE_PROCESS_DEBUG_EVENT.
if (error.Success())
DebugLoop();
else
@@ -143,8 +139,7 @@ lldb::thread_result_t DebuggerThread::DebuggerThreadLaunchRoutine(
lldb::thread_result_t DebuggerThread::DebuggerThreadAttachRoutine(
lldb::pid_t pid, const ProcessAttachInfo &attach_info) {
// Grab a shared_ptr reference to this so that we know it won't get deleted
- // until after the
- // thread routine has exited.
+ // until after the thread routine has exited.
std::shared_ptr<DebuggerThread> this_ref(shared_from_this());
Log *log = ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_PROCESS);
@@ -157,11 +152,9 @@ lldb::thread_result_t DebuggerThread::DebuggerThreadAttachRoutine(
return 0;
}
- // The attach was successful, enter the debug loop. From here on out, this is
- // no different than
- // a create process operation, so all the same comments in DebugLaunch should
- // apply from this
- // point out.
+ // The attach was successful, enter the debug loop. From here on out, this
+ // is no different than a create process operation, so all the same comments
+ // in DebugLaunch should apply from this point out.
DebugLoop();
return 0;
@@ -188,21 +181,25 @@ Status DebuggerThread::StopDebugging(bool terminate) {
lldb::process_t handle = m_process.GetNativeProcess().GetSystemHandle();
if (terminate) {
- // Initiate the termination before continuing the exception, so that the
- // next debug
- // event we get is the exit process event, and not some other event.
- BOOL terminate_suceeded = TerminateProcess(handle, 0);
- LLDB_LOG(log,
- "calling TerminateProcess({0}, 0) (inferior={1}), success={2}",
- handle, pid, terminate_suceeded);
+ if (handle != nullptr && handle != LLDB_INVALID_PROCESS) {
+ // Initiate the termination before continuing the exception, so that the
+ // next debug event we get is the exit process event, and not some other
+ // event.
+ BOOL terminate_suceeded = TerminateProcess(handle, 0);
+ LLDB_LOG(log,
+ "calling TerminateProcess({0}, 0) (inferior={1}), success={2}",
+ handle, pid, terminate_suceeded);
+ } else {
+ LLDB_LOG(log,
+ "NOT calling TerminateProcess because the inferior is not valid ({0}, 0) (inferior={1})",
+ handle, pid);
+ }
}
// If we're stuck waiting for an exception to continue (e.g. the user is at a
- // breakpoint
- // messing around in the debugger), continue it now. But only AFTER calling
- // TerminateProcess
- // to make sure that the very next call to WaitForDebugEvent is an exit
- // process event.
+ // breakpoint messing around in the debugger), continue it now. But only
+ // AFTER calling TerminateProcess to make sure that the very next call to
+ // WaitForDebugEvent is an exit process event.
if (m_active_exception.get()) {
LLDB_LOG(log, "masking active exception");
ContinueAsyncException(ExceptionResult::MaskException);
@@ -355,8 +352,7 @@ DebuggerThread::HandleExceptionEvent(const EXCEPTION_DEBUG_INFO &info,
}
// Don't perform any blocking operations while we're shutting down. That
- // will
- // cause TerminateProcess -> WaitForSingleObject to time out.
+ // will cause TerminateProcess -> WaitForSingleObject to time out.
return ExceptionResult::SendToApplication;
}
@@ -373,8 +369,8 @@ DebuggerThread::HandleExceptionEvent(const EXCEPTION_DEBUG_INFO &info,
m_exception_pred.SetValue(result, eBroadcastNever);
LLDB_LOG(log, "waiting for ExceptionPred != BreakInDebugger");
- m_exception_pred.WaitForValueNotEqualTo(ExceptionResult::BreakInDebugger,
- result);
+ result = *m_exception_pred.WaitForValueNotEqualTo(
+ ExceptionResult::BreakInDebugger);
LLDB_LOG(log, "got ExceptionPred = {0}", (int)m_exception_pred.GetValue());
return result;
diff --git a/source/Plugins/Process/Windows/Common/ProcessWindows.cpp b/source/Plugins/Process/Windows/Common/ProcessWindows.cpp
index a1c9cfaed41cb..b14081f76617d 100644
--- a/source/Plugins/Process/Windows/Common/ProcessWindows.cpp
+++ b/source/Plugins/Process/Windows/Common/ProcessWindows.cpp
@@ -77,8 +77,8 @@ std::string GetProcessExecutableName(DWORD pid) {
namespace lldb_private {
// We store a pointer to this class in the ProcessWindows, so that we don't
-// expose Windows-specific types and implementation details from a public header
-// file.
+// expose Windows-specific types and implementation details from a public
+// header file.
class ProcessWindowsData {
public:
ProcessWindowsData(bool stop_at_entry) : m_stop_at_entry(stop_at_entry) {
@@ -186,9 +186,9 @@ Status ProcessWindows::DoDetach(bool keep_stopped) {
StateType private_state;
{
// Acquire the lock only long enough to get the DebuggerThread.
- // StopDebugging() will trigger a call back into ProcessWindows which
- // will also acquire the lock. Thus we have to release the lock before
- // calling StopDebugging().
+ // StopDebugging() will trigger a call back into ProcessWindows which will
+ // also acquire the lock. Thus we have to release the lock before calling
+ // StopDebugging().
llvm::sys::ScopedLock lock(m_mutex);
private_state = GetPrivateState();
@@ -228,14 +228,22 @@ Status ProcessWindows::DoDetach(bool keep_stopped) {
Status ProcessWindows::DoLaunch(Module *exe_module,
ProcessLaunchInfo &launch_info) {
- // Even though m_session_data is accessed here, it is before a debugger thread
- // has been
- // kicked off. So there's no race conditions, and it shouldn't be necessary
- // to acquire
- // the mutex.
+ // Even though m_session_data is accessed here, it is before a debugger
+ // thread has been kicked off. So there's no race conditions, and it
+ // shouldn't be necessary to acquire the mutex.
Log *log = ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_PROCESS);
Status result;
+
+ FileSpec working_dir = launch_info.GetWorkingDirectory();
+ namespace fs = llvm::sys::fs;
+ if (working_dir && (!working_dir.ResolvePath() ||
+ !fs::is_directory(working_dir.GetPath()))) {
+ result.SetErrorStringWithFormat("No such file or directory: %s",
+ working_dir.GetCString());
+ return result;
+ }
+
if (!launch_info.GetFlags().Test(eLaunchFlagDebug)) {
StreamString stream;
stream.Printf("ProcessWindows unable to launch '%s'. ProcessWindows can "
@@ -251,7 +259,6 @@ Status ProcessWindows::DoLaunch(Module *exe_module,
bool stop_at_entry = launch_info.GetFlags().Test(eLaunchFlagStopAtEntry);
m_session_data.reset(new ProcessWindowsData(stop_at_entry));
- SetPrivateState(eStateLaunching);
DebugDelegateSP delegate(new LocalDebugDelegate(shared_from_this()));
m_session_data->m_debugger.reset(new DebuggerThread(delegate));
DebuggerThreadSP debugger = m_session_data->m_debugger;
@@ -276,12 +283,10 @@ Status ProcessWindows::DoLaunch(Module *exe_module,
launch_info.GetExecutableFile().GetPath());
// We've hit the initial stop. If eLaunchFlagsStopAtEntry was specified, the
- // private state
- // should already be set to eStateStopped as a result of hitting the initial
- // breakpoint. If
- // it was not set, the breakpoint should have already been resumed from and
- // the private state
- // should already be eStateRunning.
+ // private state should already be set to eStateStopped as a result of
+ // hitting the initial breakpoint. If it was not set, the breakpoint should
+ // have already been resumed from and the private state should already be
+ // eStateRunning.
launch_info.SetProcessID(process.GetProcessId());
SetID(process.GetProcessId());
@@ -322,12 +327,10 @@ ProcessWindows::DoAttachToProcessWithID(lldb::pid_t pid,
LLDB_LOG(log, "successfully attached to process with pid={0}", process_id);
// We've hit the initial stop. If eLaunchFlagsStopAtEntry was specified, the
- // private state
- // should already be set to eStateStopped as a result of hitting the initial
- // breakpoint. If
- // it was not set, the breakpoint should have already been resumed from and
- // the private state
- // should already be eStateRunning.
+ // private state should already be set to eStateStopped as a result of
+ // hitting the initial breakpoint. If it was not set, the breakpoint should
+ // have already been resumed from and the private state should already be
+ // eStateRunning.
SetID(process.GetProcessId());
return error;
}
@@ -346,22 +349,35 @@ Status ProcessWindows::DoResume() {
ExceptionRecordSP active_exception =
m_session_data->m_debugger->GetActiveException().lock();
if (active_exception) {
- // Resume the process and continue processing debug events. Mask
- // the exception so that from the process's view, there is no
- // indication that anything happened.
+ // Resume the process and continue processing debug events. Mask the
+ // exception so that from the process's view, there is no indication that
+ // anything happened.
m_session_data->m_debugger->ContinueAsyncException(
ExceptionResult::MaskException);
}
LLDB_LOG(log, "resuming {0} threads.", m_thread_list.GetSize());
+ bool failed = false;
for (uint32_t i = 0; i < m_thread_list.GetSize(); ++i) {
auto thread = std::static_pointer_cast<TargetThreadWindows>(
m_thread_list.GetThreadAtIndex(i));
- thread->DoResume();
+ Status result = thread->DoResume();
+ if (result.Fail()) {
+ failed = true;
+ LLDB_LOG(
+ log,
+ "Trying to resume thread at index {0}, but failed with error {1}.",
+ i, result);
+ }
}
- SetPrivateState(eStateRunning);
+ if (failed) {
+ error.SetErrorString("ProcessWindows::DoResume failed");
+ return error;
+ } else {
+ SetPrivateState(eStateRunning);
+ }
} else {
LLDB_LOG(log, "error: process %I64u is in state %u. Returning...",
m_session_data->m_debugger->GetProcess().GetProcessId(),
@@ -376,10 +392,9 @@ Status ProcessWindows::DoDestroy() {
StateType private_state;
{
// Acquire this lock inside an inner scope, only long enough to get the
- // DebuggerThread.
- // StopDebugging() will trigger a call back into ProcessWindows which will
- // acquire the lock
- // again, so we need to not deadlock.
+ // DebuggerThread. StopDebugging() will trigger a call back into
+ // ProcessWindows which will acquire the lock again, so we need to not
+ // deadlock.
llvm::sys::ScopedLock lock(m_mutex);
private_state = GetPrivateState();
@@ -461,8 +476,9 @@ void ProcessWindows::RefreshStateAfterStop() {
m_session_data->m_debugger->GetActiveException();
ExceptionRecordSP active_exception = exception_record.lock();
if (!active_exception) {
- LLDB_LOG(log, "there is no active exception in process {0}. Why is the "
- "process stopped?",
+ LLDB_LOG(log,
+ "there is no active exception in process {0}. Why is the "
+ "process stopped?",
m_session_data->m_debugger->GetProcess().GetProcessId());
return;
}
@@ -479,8 +495,9 @@ void ProcessWindows::RefreshStateAfterStop() {
const uint64_t pc = register_context->GetPC();
BreakpointSiteSP site(GetBreakpointSiteList().FindByAddress(pc));
if (site && site->ValidForThisThread(stop_thread.get())) {
- LLDB_LOG(log, "Single-stepped onto a breakpoint in process {0} at "
- "address {1:x} with breakpoint site {2}",
+ LLDB_LOG(log,
+ "Single-stepped onto a breakpoint in process {0} at "
+ "address {1:x} with breakpoint site {2}",
m_session_data->m_debugger->GetProcess().GetProcessId(), pc,
site->GetID());
stop_info = StopInfo::CreateStopReasonWithBreakpointSiteID(*stop_thread,
@@ -502,22 +519,25 @@ void ProcessWindows::RefreshStateAfterStop() {
BreakpointSiteSP site(GetBreakpointSiteList().FindByAddress(pc));
if (site) {
- LLDB_LOG(log, "detected breakpoint in process {0} at address {1:x} with "
- "breakpoint site {2}",
+ LLDB_LOG(log,
+ "detected breakpoint in process {0} at address {1:x} with "
+ "breakpoint site {2}",
m_session_data->m_debugger->GetProcess().GetProcessId(), pc,
site->GetID());
if (site->ValidForThisThread(stop_thread.get())) {
- LLDB_LOG(log, "Breakpoint site {0} is valid for this thread ({1:x}), "
- "creating stop info.",
+ LLDB_LOG(log,
+ "Breakpoint site {0} is valid for this thread ({1:x}), "
+ "creating stop info.",
site->GetID(), stop_thread->GetID());
stop_info = StopInfo::CreateStopReasonWithBreakpointSiteID(
*stop_thread, site->GetID());
register_context->SetPC(pc);
} else {
- LLDB_LOG(log, "Breakpoint site {0} is not valid for this thread, "
- "creating empty stop info.",
+ LLDB_LOG(log,
+ "Breakpoint site {0} is not valid for this thread, "
+ "creating empty stop info.",
site->GetID());
}
stop_thread->SetStopInfo(stop_info);
@@ -558,8 +578,8 @@ bool ProcessWindows::CanDebug(lldb::TargetSP target_sp,
ModuleSP exe_module_sp(target_sp->GetExecutableModule());
if (exe_module_sp.get())
return exe_module_sp->GetFileSpec().Exists();
- // However, if there is no executable module, we return true since we might be
- // preparing to attach.
+ // However, if there is no executable module, we return true since we might
+ // be preparing to attach.
return true;
}
@@ -589,8 +609,8 @@ bool ProcessWindows::UpdateThreadList(ThreadList &old_thread_list,
}
}
- // Also add all the threads that are new since the last time we broke into the
- // debugger.
+ // Also add all the threads that are new since the last time we broke into
+ // the debugger.
for (const auto &thread_info : m_session_data->m_new_threads) {
ThreadSP thread(new TargetThreadWindows(*this, thread_info.second));
thread->SetID(thread_info.first);
@@ -639,8 +659,13 @@ size_t ProcessWindows::DoReadMemory(lldb::addr_t vm_addr, void *buf,
SIZE_T bytes_read = 0;
if (!ReadProcessMemory(process.GetNativeProcess().GetSystemHandle(), addr,
buf, size, &bytes_read)) {
+ // Reading from the process can fail for a number of reasons - set the
+ // error code and make sure that the number of bytes read is set back to 0
+ // because in some scenarios the value of bytes_read returned from the API
+ // is garbage.
error.SetError(GetLastError(), eErrorTypeWin32);
LLDB_LOG(log, "reading failed with error: {0}", error);
+ bytes_read = 0;
}
return bytes_read;
}
@@ -699,11 +724,9 @@ Status ProcessWindows::GetMemoryRegionInfo(lldb::addr_t vm_addr,
SIZE_T result = ::VirtualQueryEx(handle, addr, &mem_info, sizeof(mem_info));
if (result == 0) {
if (::GetLastError() == ERROR_INVALID_PARAMETER) {
- // ERROR_INVALID_PARAMETER is returned if VirtualQueryEx is called with an
- // address
- // past the highest accessible address. We should return a range from the
- // vm_addr
- // to LLDB_INVALID_ADDRESS
+ // ERROR_INVALID_PARAMETER is returned if VirtualQueryEx is called with
+ // an address past the highest accessible address. We should return a
+ // range from the vm_addr to LLDB_INVALID_ADDRESS
info.GetRange().SetRangeBase(vm_addr);
info.GetRange().SetRangeEnd(LLDB_INVALID_ADDRESS);
info.SetReadable(MemoryRegionInfo::eNo);
@@ -713,8 +736,9 @@ Status ProcessWindows::GetMemoryRegionInfo(lldb::addr_t vm_addr,
return error;
} else {
error.SetError(::GetLastError(), eErrorTypeWin32);
- LLDB_LOG(log, "VirtualQueryEx returned error {0} while getting memory "
- "region info for address {1:x}",
+ LLDB_LOG(log,
+ "VirtualQueryEx returned error {0} while getting memory "
+ "region info for address {1:x}",
error, vm_addr);
return error;
}
@@ -744,10 +768,8 @@ Status ProcessWindows::GetMemoryRegionInfo(lldb::addr_t vm_addr,
info.SetMapped(MemoryRegionInfo::eYes);
} else {
// In the unmapped case we need to return the distance to the next block of
- // memory.
- // VirtualQueryEx nearly does that except that it gives the distance from
- // the start
- // of the page containing vm_addr.
+ // memory. VirtualQueryEx nearly does that except that it gives the
+ // distance from the start of the page containing vm_addr.
SYSTEM_INFO data;
GetSystemInfo(&data);
DWORD page_offset = vm_addr % data.dwPageSize;
@@ -757,8 +779,9 @@ Status ProcessWindows::GetMemoryRegionInfo(lldb::addr_t vm_addr,
}
error.SetError(::GetLastError(), eErrorTypeWin32);
- LLDB_LOGV(log, "Memory region info for address {0}: readable={1}, "
- "executable={2}, writable={3}",
+ LLDB_LOGV(log,
+ "Memory region info for address {0}: readable={1}, "
+ "executable={2}, writable={3}",
vm_addr, info.GetReadable(), info.GetExecutable(),
info.GetWritable());
return error;
@@ -779,7 +802,7 @@ void ProcessWindows::OnExitProcess(uint32_t exit_code) {
Log *log = ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_PROCESS);
LLDB_LOG(log, "Process {0} exited with code {1}", GetID(), exit_code);
- TargetSP target = m_target_sp.lock();
+ TargetSP target = CalculateTarget();
if (target) {
ModuleSP executable_module = target->GetExecutableModule();
ModuleList unloaded_modules;
@@ -825,10 +848,9 @@ void ProcessWindows::OnDebuggerConnected(lldb::addr_t image_base) {
GetTarget().ModulesDidLoad(loaded_modules);
// Add the main executable module to the list of pending module loads. We
- // can't call
- // GetTarget().ModulesDidLoad() here because we still haven't returned from
- // DoLaunch() / DoAttach() yet
- // so the target may not have set the process instance to `this` yet.
+ // can't call GetTarget().ModulesDidLoad() here because we still haven't
+ // returned from DoLaunch() / DoAttach() yet so the target may not have set
+ // the process instance to `this` yet.
llvm::sys::ScopedLock lock(m_mutex);
const HostThreadWindows &wmain_thread =
debugger->GetMainThread().GetNativeThread();
@@ -845,15 +867,14 @@ ProcessWindows::OnDebugException(bool first_chance,
// FIXME: Without this check, occasionally when running the test suite there
// is
// an issue where m_session_data can be null. It's not clear how this could
- // happen
- // but it only surfaces while running the test suite. In order to properly
- // diagnose
- // this, we probably need to first figure allow the test suite to print out
- // full
- // lldb logs, and then add logging to the process plugin.
+ // happen but it only surfaces while running the test suite. In order to
+ // properly diagnose this, we probably need to first figure allow the test
+ // suite to print out full lldb logs, and then add logging to the process
+ // plugin.
if (!m_session_data) {
- LLDB_LOG(log, "Debugger thread reported exception {0:x} at address {1:x}, "
- "but there is no session.",
+ LLDB_LOG(log,
+ "Debugger thread reported exception {0:x} at address {1:x}, "
+ "but there is no session.",
record.GetExceptionCode(), record.GetExceptionAddress());
return ExceptionResult::SendToApplication;
}
@@ -887,8 +908,9 @@ ProcessWindows::OnDebugException(bool first_chance,
SetPrivateState(eStateStopped);
break;
default:
- LLDB_LOG(log, "Debugger thread reported exception {0:x} at address {1:x} "
- "(first_chance={2})",
+ LLDB_LOG(log,
+ "Debugger thread reported exception {0:x} at address {1:x} "
+ "(first_chance={2})",
record.GetExceptionCode(), record.GetExceptionAddress(),
first_chance);
// For non-breakpoints, give the application a chance to handle the
@@ -929,9 +951,8 @@ void ProcessWindows::OnExitThread(lldb::tid_t thread_id, uint32_t exit_code) {
void ProcessWindows::OnLoadDll(const ModuleSpec &module_spec,
lldb::addr_t module_addr) {
// Confusingly, there is no Target::AddSharedModule. Instead, calling
- // GetSharedModule() with
- // a new module will add it to the module list and return a corresponding
- // ModuleSP.
+ // GetSharedModule() with a new module will add it to the module list and
+ // return a corresponding ModuleSP.
Status error;
ModuleSP module = GetTarget().GetSharedModule(module_spec, &error);
bool load_addr_changed = false;
@@ -961,17 +982,16 @@ void ProcessWindows::OnDebuggerError(const Status &error, uint32_t type) {
Log *log = ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_PROCESS);
if (m_session_data->m_initial_stop_received) {
- // This happened while debugging. Do we shutdown the debugging session, try
- // to continue, or do something else?
- LLDB_LOG(log, "Error {0} occurred during debugging. Unexpected behavior "
- "may result. {1}",
+ // This happened while debugging. Do we shutdown the debugging session,
+ // try to continue, or do something else?
+ LLDB_LOG(log,
+ "Error {0} occurred during debugging. Unexpected behavior "
+ "may result. {1}",
error.GetError(), error);
} else {
// If we haven't actually launched the process yet, this was an error
- // launching the
- // process. Set the internal error and signal the initial stop event so
- // that the DoLaunch
- // method wakes up and returns a failure.
+ // launching the process. Set the internal error and signal the initial
+ // stop event so that the DoLaunch method wakes up and returns a failure.
m_session_data->m_launch_error = error;
::SetEvent(m_session_data->m_initial_stop_event);
LLDB_LOG(
@@ -1001,9 +1021,9 @@ Status ProcessWindows::WaitForDebuggerConnection(DebuggerThreadSP debugger,
}
// The Windows page protection bits are NOT independent masks that can be
-// bitwise-ORed together. For example, PAGE_EXECUTE_READ is not
-// (PAGE_EXECUTE | PAGE_READ). To test for an access type, it's necessary to
-// test for any of the bits that provide that access type.
+// bitwise-ORed together. For example, PAGE_EXECUTE_READ is not (PAGE_EXECUTE
+// | PAGE_READ). To test for an access type, it's necessary to test for any of
+// the bits that provide that access type.
bool ProcessWindows::IsPageReadable(uint32_t protect) {
return (protect & PAGE_NOACCESS) == 0;
}
diff --git a/source/Plugins/Process/Windows/Common/TargetThreadWindows.cpp b/source/Plugins/Process/Windows/Common/TargetThreadWindows.cpp
index a4d60303877e0..3903280918cc8 100644
--- a/source/Plugins/Process/Windows/Common/TargetThreadWindows.cpp
+++ b/source/Plugins/Process/Windows/Common/TargetThreadWindows.cpp
@@ -16,10 +16,10 @@
#include "lldb/Utility/Log.h"
#include "lldb/Utility/Logging.h"
+#include "Plugins/Process/Utility/UnwindLLDB.h"
#include "ProcessWindows.h"
#include "ProcessWindowsLog.h"
#include "TargetThreadWindows.h"
-#include "UnwindLLDB.h"
#if defined(_WIN64)
#include "x64/RegisterContextWindows_x64.h"
@@ -33,7 +33,7 @@ using namespace lldb_private;
TargetThreadWindows::TargetThreadWindows(ProcessWindows &process,
const HostThread &thread)
: Thread(process, thread.GetNativeThread().GetThreadId()),
- m_host_thread(thread) {}
+ m_thread_reg_ctx_sp(), m_host_thread(thread) {}
TargetThreadWindows::~TargetThreadWindows() { DestroyThread(); }
@@ -49,40 +49,53 @@ void TargetThreadWindows::DidStop() {}
RegisterContextSP TargetThreadWindows::GetRegisterContext() {
if (!m_reg_context_sp)
- m_reg_context_sp = CreateRegisterContextForFrameIndex(0);
+ m_reg_context_sp = CreateRegisterContextForFrame(nullptr);
return m_reg_context_sp;
}
RegisterContextSP
TargetThreadWindows::CreateRegisterContextForFrame(StackFrame *frame) {
- return CreateRegisterContextForFrameIndex(frame->GetConcreteFrameIndex());
-}
-
-RegisterContextSP
-TargetThreadWindows::CreateRegisterContextForFrameIndex(uint32_t idx) {
- if (!m_reg_context_sp) {
- ArchSpec arch = HostInfo::GetArchitecture();
- switch (arch.GetMachine()) {
- case llvm::Triple::x86:
+ RegisterContextSP reg_ctx_sp;
+ uint32_t concrete_frame_idx = 0;
+ Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_THREAD));
+
+ if (frame)
+ concrete_frame_idx = frame->GetConcreteFrameIndex();
+
+ if (concrete_frame_idx == 0) {
+ if (!m_thread_reg_ctx_sp) {
+ ArchSpec arch = HostInfo::GetArchitecture();
+ switch (arch.GetMachine()) {
+ case llvm::Triple::x86:
#if defined(_WIN64)
-// FIXME: This is a Wow64 process, create a RegisterContextWindows_Wow64
+ // FIXME: This is a Wow64 process, create a RegisterContextWindows_Wow64
+ LLDB_LOG(log, "This is a Wow64 process, we should create a "
+ "RegisterContextWindows_Wow64, but we don't.");
#else
- m_reg_context_sp.reset(new RegisterContextWindows_x86(*this, idx));
+ m_thread_reg_ctx_sp.reset(
+ new RegisterContextWindows_x86(*this, concrete_frame_idx));
#endif
- break;
- case llvm::Triple::x86_64:
+ break;
+ case llvm::Triple::x86_64:
#if defined(_WIN64)
- m_reg_context_sp.reset(new RegisterContextWindows_x64(*this, idx));
+ m_thread_reg_ctx_sp.reset(
+ new RegisterContextWindows_x64(*this, concrete_frame_idx));
#else
-// LLDB is 32-bit, but the target process is 64-bit. We probably can't debug
-// this.
+ LLDB_LOG(log, "LLDB is 32-bit, but the target process is 64-bit.");
#endif
- default:
- break;
+ default:
+ break;
+ }
}
+ reg_ctx_sp = m_thread_reg_ctx_sp;
+ } else {
+ Unwind *unwinder = GetUnwinder();
+ if (unwinder != nullptr)
+ reg_ctx_sp = unwinder->CreateRegisterContextForFrame(frame);
}
- return m_reg_context_sp;
+
+ return reg_ctx_sp;
}
bool TargetThreadWindows::CalculateStopInfo() {
@@ -93,16 +106,16 @@ bool TargetThreadWindows::CalculateStopInfo() {
Unwind *TargetThreadWindows::GetUnwinder() {
// FIXME: Implement an unwinder based on the Windows unwinder exposed through
// DIA SDK.
- if (m_unwinder_ap.get() == NULL)
+ if (!m_unwinder_ap)
m_unwinder_ap.reset(new UnwindLLDB(*this));
return m_unwinder_ap.get();
}
-bool TargetThreadWindows::DoResume() {
+Status TargetThreadWindows::DoResume() {
StateType resume_state = GetTemporaryResumeState();
StateType current_state = GetState();
if (resume_state == current_state)
- return true;
+ return Status();
if (resume_state == eStateStepping) {
uint32_t flags_index =
@@ -118,8 +131,17 @@ bool TargetThreadWindows::DoResume() {
DWORD previous_suspend_count = 0;
HANDLE thread_handle = m_host_thread.GetNativeThread().GetSystemHandle();
do {
+ // ResumeThread returns -1 on error, or the thread's *previous* suspend
+ // count on success. This means that the return value is 1 when the thread
+ // was restarted. Note that DWORD is an unsigned int, so we need to
+ // explicitly compare with -1.
previous_suspend_count = ::ResumeThread(thread_handle);
- } while (previous_suspend_count > 0);
+
+ if (previous_suspend_count == (DWORD)-1)
+ return Status(::GetLastError(), eErrorTypeWin32);
+
+ } while (previous_suspend_count > 1);
}
- return true;
+
+ return Status();
}
diff --git a/source/Plugins/Process/Windows/Common/TargetThreadWindows.h b/source/Plugins/Process/Windows/Common/TargetThreadWindows.h
index 8b4e3dfdda4a9..952c0f55b57f3 100644
--- a/source/Plugins/Process/Windows/Common/TargetThreadWindows.h
+++ b/source/Plugins/Process/Windows/Common/TargetThreadWindows.h
@@ -37,15 +37,14 @@ public:
bool CalculateStopInfo() override;
Unwind *GetUnwinder() override;
- bool DoResume();
+ Status DoResume();
HostThread GetHostThread() const { return m_host_thread; }
private:
- lldb::RegisterContextSP CreateRegisterContextForFrameIndex(uint32_t idx);
-
+ lldb::RegisterContextSP m_thread_reg_ctx_sp;
HostThread m_host_thread;
};
-}
+} // namespace lldb_private
#endif
diff --git a/source/Plugins/Process/Windows/Common/x64/RegisterContextWindows_x64.cpp b/source/Plugins/Process/Windows/Common/x64/RegisterContextWindows_x64.cpp
index e64bade5ff907..4aa6c785f83c4 100644
--- a/source/Plugins/Process/Windows/Common/x64/RegisterContextWindows_x64.cpp
+++ b/source/Plugins/Process/Windows/Common/x64/RegisterContextWindows_x64.cpp
@@ -14,9 +14,9 @@
#include "lldb/lldb-private-types.h"
#include "RegisterContextWindows_x64.h"
-#include "RegisterContext_x86.h"
+#include "Plugins/Process/Utility/RegisterContext_x86.h"
#include "TargetThreadWindows.h"
-#include "lldb-x86-register-enums.h"
+#include "Plugins/Process/Utility/lldb-x86-register-enums.h"
#include "llvm/ADT/STLExtras.h"
@@ -29,14 +29,11 @@ using namespace lldb_private;
namespace {
// This enum defines the layout of the global RegisterInfo array. This is
-// necessary because
-// lldb register sets are defined in terms of indices into the register array.
-// As such, the
-// order of RegisterInfos defined in global registers array must match the order
-// defined here.
-// When defining the register set layouts, these values can appear in an
-// arbitrary order, and that
-// determines the order that register values are displayed in a dump.
+// necessary because lldb register sets are defined in terms of indices into
+// the register array. As such, the order of RegisterInfos defined in global
+// registers array must match the order defined here. When defining the
+// register set layouts, these values can appear in an arbitrary order, and
+// that determines the order that register values are displayed in a dump.
enum RegisterIndex {
eRegisterIndexRax,
eRegisterIndexRbx,
@@ -44,6 +41,8 @@ enum RegisterIndex {
eRegisterIndexRdx,
eRegisterIndexRdi,
eRegisterIndexRsi,
+ eRegisterIndexRbp,
+ eRegisterIndexRsp,
eRegisterIndexR8,
eRegisterIndexR9,
eRegisterIndexR10,
@@ -52,8 +51,6 @@ enum RegisterIndex {
eRegisterIndexR13,
eRegisterIndexR14,
eRegisterIndexR15,
- eRegisterIndexRbp,
- eRegisterIndexRsp,
eRegisterIndexRip,
eRegisterIndexRflags
};
@@ -96,6 +93,16 @@ RegisterInfo g_register_infos[] = {
LLDB_INVALID_REGNUM, lldb_rsi_x86_64},
nullptr,
nullptr},
+ {DEFINE_GPR(rbp, "fp"),
+ {dwarf_rbp_x86_64, dwarf_rbp_x86_64, LLDB_REGNUM_GENERIC_FP,
+ LLDB_INVALID_REGNUM, lldb_rbp_x86_64},
+ nullptr,
+ nullptr},
+ {DEFINE_GPR(rsp, "sp"),
+ {dwarf_rsp_x86_64, dwarf_rsp_x86_64, LLDB_REGNUM_GENERIC_SP,
+ LLDB_INVALID_REGNUM, lldb_rsp_x86_64},
+ nullptr,
+ nullptr},
{DEFINE_GPR(r8, nullptr),
{dwarf_r8_x86_64, dwarf_r8_x86_64, LLDB_INVALID_REGNUM,
LLDB_INVALID_REGNUM, lldb_r8_x86_64},
@@ -136,16 +143,6 @@ RegisterInfo g_register_infos[] = {
LLDB_INVALID_REGNUM, lldb_r15_x86_64},
nullptr,
nullptr},
- {DEFINE_GPR(rbp, "fp"),
- {dwarf_rbp_x86_64, dwarf_rbp_x86_64, LLDB_REGNUM_GENERIC_FP,
- LLDB_INVALID_REGNUM, lldb_rbp_x86_64},
- nullptr,
- nullptr},
- {DEFINE_GPR(rsp, "sp"),
- {dwarf_rsp_x86_64, dwarf_rsp_x86_64, LLDB_REGNUM_GENERIC_SP,
- LLDB_INVALID_REGNUM, lldb_rsp_x86_64},
- nullptr,
- nullptr},
{DEFINE_GPR(rip, "pc"),
{dwarf_rip_x86_64, dwarf_rip_x86_64, LLDB_REGNUM_GENERIC_PC,
LLDB_INVALID_REGNUM, lldb_rip_x86_64},
@@ -165,10 +162,10 @@ static size_t k_num_register_infos = llvm::array_lengthof(g_register_infos);
uint32_t g_gpr_reg_indices[] = {
eRegisterIndexRax, eRegisterIndexRbx, eRegisterIndexRcx,
eRegisterIndexRdx, eRegisterIndexRdi, eRegisterIndexRsi,
- eRegisterIndexR8, eRegisterIndexR9, eRegisterIndexR10,
- eRegisterIndexR11, eRegisterIndexR12, eRegisterIndexR13,
- eRegisterIndexR14, eRegisterIndexR15, eRegisterIndexRbp,
- eRegisterIndexRsp, eRegisterIndexRip, eRegisterIndexRflags};
+ eRegisterIndexRbp, eRegisterIndexRsp, eRegisterIndexR8,
+ eRegisterIndexR9, eRegisterIndexR10, eRegisterIndexR11,
+ eRegisterIndexR12, eRegisterIndexR13, eRegisterIndexR14,
+ eRegisterIndexR15, eRegisterIndexRip, eRegisterIndexRflags};
RegisterSet g_register_sets[] = {
{"General Purpose Registers", "gpr",
@@ -209,6 +206,9 @@ bool RegisterContextWindows_x64::ReadRegister(const RegisterInfo *reg_info,
if (!CacheAllRegisterValues())
return false;
+ if (reg_info == nullptr)
+ return false;
+
switch (reg_info->kinds[eRegisterKindLLDB]) {
case lldb_rax_x86_64:
reg_value.SetUInt64(m_context.Rax);
@@ -270,11 +270,10 @@ bool RegisterContextWindows_x64::ReadRegister(const RegisterInfo *reg_info,
bool RegisterContextWindows_x64::WriteRegister(const RegisterInfo *reg_info,
const RegisterValue &reg_value) {
- // Since we cannot only write a single register value to the inferior, we need
- // to make sure
- // our cached copy of the register values are fresh. Otherwise when writing
- // EAX, for example,
- // we may also overwrite some other register with a stale value.
+ // Since we cannot only write a single register value to the inferior, we
+ // need to make sure our cached copy of the register values are fresh.
+ // Otherwise when writing EAX, for example, we may also overwrite some other
+ // register with a stale value.
if (!CacheAllRegisterValues())
return false;
diff --git a/source/Plugins/Process/Windows/Common/x86/RegisterContextWindows_x86.cpp b/source/Plugins/Process/Windows/Common/x86/RegisterContextWindows_x86.cpp
index f56836de4a673..fd486f3d08298 100644
--- a/source/Plugins/Process/Windows/Common/x86/RegisterContextWindows_x86.cpp
+++ b/source/Plugins/Process/Windows/Common/x86/RegisterContextWindows_x86.cpp
@@ -15,9 +15,9 @@
#include "ProcessWindowsLog.h"
#include "RegisterContextWindows_x86.h"
-#include "RegisterContext_x86.h"
+#include "Plugins/Process/Utility/RegisterContext_x86.h"
#include "TargetThreadWindows.h"
-#include "lldb-x86-register-enums.h"
+#include "Plugins/Process/Utility/lldb-x86-register-enums.h"
#include "llvm/ADT/STLExtras.h"
@@ -30,14 +30,11 @@ using namespace lldb_private;
namespace {
// This enum defines the layout of the global RegisterInfo array. This is
-// necessary because
-// lldb register sets are defined in terms of indices into the register array.
-// As such, the
-// order of RegisterInfos defined in global registers array must match the order
-// defined here.
-// When defining the register set layouts, these values can appear in an
-// arbitrary order, and that
-// determines the order that register values are displayed in a dump.
+// necessary because lldb register sets are defined in terms of indices into
+// the register array. As such, the order of RegisterInfos defined in global
+// registers array must match the order defined here. When defining the
+// register set layouts, these values can appear in an arbitrary order, and
+// that determines the order that register values are displayed in a dump.
enum RegisterIndex {
eRegisterIndexEax,
eRegisterIndexEbx,
@@ -179,6 +176,9 @@ bool RegisterContextWindows_x86::ReadRegister(const RegisterInfo *reg_info,
if (!CacheAllRegisterValues())
return false;
+ if (reg_info == nullptr)
+ return false;
+
uint32_t reg = reg_info->kinds[eRegisterKindLLDB];
switch (reg) {
case lldb_eax_i386:
@@ -212,11 +212,10 @@ bool RegisterContextWindows_x86::ReadRegister(const RegisterInfo *reg_info,
bool RegisterContextWindows_x86::WriteRegister(const RegisterInfo *reg_info,
const RegisterValue &reg_value) {
- // Since we cannot only write a single register value to the inferior, we need
- // to make sure
- // our cached copy of the register values are fresh. Otherwise when writing
- // EAX, for example,
- // we may also overwrite some other register with a stale value.
+ // Since we cannot only write a single register value to the inferior, we
+ // need to make sure our cached copy of the register values are fresh.
+ // Otherwise when writing EAX, for example, we may also overwrite some other
+ // register with a stale value.
if (!CacheAllRegisterValues())
return false;
diff --git a/source/Plugins/Process/elf-core/CMakeLists.txt b/source/Plugins/Process/elf-core/CMakeLists.txt
index 3082c73f6dda7..9b6739824c066 100644
--- a/source/Plugins/Process/elf-core/CMakeLists.txt
+++ b/source/Plugins/Process/elf-core/CMakeLists.txt
@@ -1,5 +1,3 @@
-include_directories(../Utility)
-
add_lldb_library(lldbPluginProcessElfCore PLUGIN
ProcessElfCore.cpp
ThreadElfCore.cpp
diff --git a/source/Plugins/Process/elf-core/ProcessElfCore.cpp b/source/Plugins/Process/elf-core/ProcessElfCore.cpp
index 7d6a0c9ad2df0..7bb7b72eaac18 100644
--- a/source/Plugins/Process/elf-core/ProcessElfCore.cpp
+++ b/source/Plugins/Process/elf-core/ProcessElfCore.cpp
@@ -56,9 +56,9 @@ lldb::ProcessSP ProcessElfCore::CreateInstance(lldb::TargetSP target_sp,
const FileSpec *crash_file) {
lldb::ProcessSP process_sp;
if (crash_file) {
- // Read enough data for a ELF32 header or ELF64 header
- // Note: Here we care about e_type field only, so it is safe
- // to ignore possible presence of the header extension.
+ // Read enough data for a ELF32 header or ELF64 header Note: Here we care
+ // about e_type field only, so it is safe to ignore possible presence of
+ // the header extension.
const size_t header_size = sizeof(llvm::ELF::Elf64_Ehdr);
auto data_sp = DataBufferLLVM::CreateSliceFromPath(crash_file->GetPath(),
@@ -107,10 +107,10 @@ ProcessElfCore::ProcessElfCore(lldb::TargetSP target_sp,
//----------------------------------------------------------------------
ProcessElfCore::~ProcessElfCore() {
Clear();
- // We need to call finalize on the process before destroying ourselves
- // to make sure all of the broadcaster cleanup goes as planned. If we
- // destruct this class, then Process::~Process() might have problems
- // trying to fully destroy the broadcaster.
+ // We need to call finalize on the process before destroying ourselves to
+ // make sure all of the broadcaster cleanup goes as planned. If we destruct
+ // this class, then Process::~Process() might have problems trying to fully
+ // destroy the broadcaster.
Finalize();
}
@@ -206,8 +206,8 @@ Status ProcessElfCore::DoLoadCore() {
m_core_range_infos.Sort();
}
- // Even if the architecture is set in the target, we need to override
- // it to match the core file which is always single arch.
+ // Even if the architecture is set in the target, we need to override it to
+ // match the core file which is always single arch.
ArchSpec arch(m_core_module_sp->GetArchitecture());
ArchSpec target_arch = GetTarget().GetArchitecture();
@@ -241,8 +241,7 @@ Status ProcessElfCore::DoLoadCore() {
}
// Core files are useless without the main executable. See if we can locate
- // the main
- // executable using data we found in the core file notes.
+ // the main executable using data we found in the core file notes.
lldb::ModuleSP exe_module_sp = GetTarget().GetExecutableModule();
if (!exe_module_sp) {
// The first entry in the NT_FILE might be our executable
@@ -250,7 +249,8 @@ Status ProcessElfCore::DoLoadCore() {
ModuleSpec exe_module_spec;
exe_module_spec.GetArchitecture() = arch;
exe_module_spec.GetFileSpec().SetFile(
- m_nt_file_entries[0].path.GetCString(), false);
+ m_nt_file_entries[0].path.GetCString(), false,
+ FileSpec::Style::native);
if (exe_module_spec.GetFileSpec()) {
exe_module_sp = GetTarget().GetSharedModule(exe_module_spec);
if (exe_module_sp)
@@ -297,8 +297,8 @@ bool ProcessElfCore::IsAlive() { return true; }
//------------------------------------------------------------------
size_t ProcessElfCore::ReadMemory(lldb::addr_t addr, void *buf, size_t size,
Status &error) {
- // Don't allow the caching that lldb_private::Process::ReadMemory does
- // since in core files we have it all cached our our core file anyway.
+ // Don't allow the caching that lldb_private::Process::ReadMemory does since
+ // in core files we have it all cached our our core file anyway.
return DoReadMemory(addr, buf, size, error);
}
@@ -368,17 +368,18 @@ size_t ProcessElfCore::DoReadMemory(lldb::addr_t addr, void *buf, size_t size,
lldb::addr_t bytes_left =
0; // Number of bytes available in the core file from the given address
- // Don't proceed if core file doesn't contain the actual data for this address range.
+ // Don't proceed if core file doesn't contain the actual data for this
+ // address range.
if (file_start == file_end)
return 0;
- // Figure out how many on-disk bytes remain in this segment
- // starting at the given offset
+ // Figure out how many on-disk bytes remain in this segment starting at the
+ // given offset
if (file_end > file_start + offset)
bytes_left = file_end - (file_start + offset);
- // Figure out how many bytes we need to zero-fill if we are
- // reading more bytes than available in the on-disk segment
+ // Figure out how many bytes we need to zero-fill if we are reading more
+ // bytes than available in the on-disk segment
if (bytes_to_read > bytes_left) {
zero_fill_size = bytes_to_read - bytes_left;
bytes_to_read = bytes_left;
@@ -551,8 +552,8 @@ llvm::Error ProcessElfCore::parseFreeBSDNotes(llvm::ArrayRef<CoreNote> notes) {
llvm::Error ProcessElfCore::parseNetBSDNotes(llvm::ArrayRef<CoreNote> notes) {
ThreadData thread_data;
for (const auto &note : notes) {
- // NetBSD per-thread information is stored in notes named
- // "NetBSD-CORE@nnn" so match on the initial part of the string.
+ // NetBSD per-thread information is stored in notes named "NetBSD-CORE@nnn"
+ // so match on the initial part of the string.
if (!llvm::StringRef(note.info.n_name).startswith("NetBSD-CORE"))
continue;
@@ -585,8 +586,8 @@ llvm::Error ProcessElfCore::parseNetBSDNotes(llvm::ArrayRef<CoreNote> notes) {
llvm::Error ProcessElfCore::parseOpenBSDNotes(llvm::ArrayRef<CoreNote> notes) {
ThreadData thread_data;
for (const auto &note : notes) {
- // OpenBSD per-thread information is stored in notes named
- // "OpenBSD@nnn" so match on the initial part of the string.
+ // OpenBSD per-thread information is stored in notes named "OpenBSD@nnn" so
+ // match on the initial part of the string.
if (!llvm::StringRef(note.info.n_name).startswith("OpenBSD"))
continue;
@@ -665,7 +666,7 @@ llvm::Error ProcessElfCore::parseLinuxNotes(llvm::ArrayRef<CoreNote> notes) {
Status status = prpsinfo.Parse(note.data, arch);
if (status.Fail())
return status.ToError();
- thread_data.name = prpsinfo.pr_fname;
+ thread_data.name.assign (prpsinfo.pr_fname, strnlen (prpsinfo.pr_fname, sizeof (prpsinfo.pr_fname)));
SetID(prpsinfo.pr_pid);
break;
}
@@ -749,9 +750,9 @@ ArchSpec ProcessElfCore::GetArchitecture() {
ArchSpec target_arch = GetTarget().GetArchitecture();
arch.MergeFrom(target_arch);
- // On MIPS there is no way to differentiate betwenn 32bit and 64bit core files
- // and this information can't be merged in from the target arch so we fail
- // back to unconditionally returning the target arch in this config.
+ // On MIPS there is no way to differentiate betwenn 32bit and 64bit core
+ // files and this information can't be merged in from the target arch so we
+ // fail back to unconditionally returning the target arch in this config.
if (target_arch.IsMIPS()) {
return target_arch;
}
diff --git a/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_mips64.cpp b/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_mips64.cpp
index e252b5a35e9c8..532a1f5c0831c 100644
--- a/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_mips64.cpp
+++ b/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_mips64.cpp
@@ -56,7 +56,7 @@ bool RegisterContextCorePOSIX_mips64::ReadRegister(const RegisterInfo *reg_info,
if (IsGPR(reg_info->kinds[lldb::eRegisterKindLLDB])) {
if (reg_info->byte_size == 4 && !(arch.GetMachine() == llvm::Triple::mips64el))
// In case of 32bit core file, the register data are placed at 4 byte
- // offset.
+ // offset.
offset = offset / 2;
v = m_gpr.GetMaxU64(&offset, reg_info->byte_size);
value = v;
diff --git a/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_x86_64.cpp b/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_x86_64.cpp
index a5c7ffda1da56..a1f26d52444bb 100644
--- a/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_x86_64.cpp
+++ b/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_x86_64.cpp
@@ -60,8 +60,8 @@ bool RegisterContextCorePOSIX_x86_64::ReadRegister(const RegisterInfo *reg_info,
const uint8_t *src;
size_t offset;
const size_t fxsave_offset = reg_info->byte_offset - GetFXSAVEOffset();
- // make the offset relative to the beginning of the FXSAVE structure
- // because this is the data that we have (not the entire UserArea)
+ // make the offset relative to the beginning of the FXSAVE structure because
+ // this is the data that we have (not the entire UserArea)
if (m_gpregset && reg_info->byte_offset < GetGPRSize()) {
src = m_gpregset.get();
diff --git a/source/Plugins/Process/elf-core/ThreadElfCore.cpp b/source/Plugins/Process/elf-core/ThreadElfCore.cpp
index 10c1ed288b2c5..d9b90c8e902e7 100644
--- a/source/Plugins/Process/elf-core/ThreadElfCore.cpp
+++ b/source/Plugins/Process/elf-core/ThreadElfCore.cpp
@@ -55,16 +55,9 @@ void ThreadElfCore::RefreshStateAfterStop() {
GetRegisterContext()->InvalidateIfNeeded(false);
}
-void ThreadElfCore::ClearStackFrames() {
- Unwind *unwinder = GetUnwinder();
- if (unwinder)
- unwinder->Clear();
- Thread::ClearStackFrames();
-}
-
RegisterContextSP ThreadElfCore::GetRegisterContext() {
- if (m_reg_context_sp.get() == NULL) {
- m_reg_context_sp = CreateRegisterContextForFrame(NULL);
+ if (!m_reg_context_sp) {
+ m_reg_context_sp = CreateRegisterContextForFrame(nullptr);
}
return m_reg_context_sp;
}
@@ -84,7 +77,7 @@ ThreadElfCore::CreateRegisterContextForFrame(StackFrame *frame) {
ProcessElfCore *process = static_cast<ProcessElfCore *>(GetProcess().get());
ArchSpec arch = process->GetArchitecture();
- RegisterInfoInterface *reg_interface = NULL;
+ RegisterInfoInterface *reg_interface = nullptr;
switch (arch.GetTriple().getOS()) {
case llvm::Triple::FreeBSD: {
@@ -234,8 +227,10 @@ ThreadElfCore::CreateRegisterContextForFrame(StackFrame *frame) {
}
reg_ctx_sp = m_thread_reg_ctx_sp;
- } else if (m_unwinder_ap.get()) {
- reg_ctx_sp = m_unwinder_ap->CreateRegisterContextForFrame(frame);
+ } else {
+ Unwind *unwinder = GetUnwinder();
+ if (unwinder != nullptr)
+ reg_ctx_sp = unwinder->CreateRegisterContextForFrame(frame);
}
return reg_ctx_sp;
}
@@ -292,8 +287,8 @@ Status ELFLinuxPrStatus::Parse(const DataExtractor &data,
return error;
}
- // Read field by field to correctly account for endianess
- // of both the core dump and the platform running lldb.
+ // Read field by field to correctly account for endianess of both the core
+ // dump and the platform running lldb.
offset_t offset = 0;
si_signo = data.GetU32(&offset);
si_code = data.GetU32(&offset);
@@ -340,7 +335,7 @@ size_t ELFLinuxPrPsInfo::GetSize(const lldb_private::ArchSpec &arch) {
return sizeof(ELFLinuxPrPsInfo);
return mips_linux_pr_psinfo_size_o32_n32;
}
-
+
switch (arch.GetCore()) {
case lldb_private::ArchSpec::eCore_s390x_generic:
case lldb_private::ArchSpec::eCore_x86_64_x86_64:
@@ -382,9 +377,9 @@ Status ELFLinuxPrPsInfo::Parse(const DataExtractor &data,
pr_uid = data.GetU32(&offset);
pr_gid = data.GetU32(&offset);
} else {
- // 16 bit on 32 bit platforms, 32 bit on 64 bit platforms
- pr_uid = data.GetMaxU64(&offset, data.GetAddressByteSize() >> 1);
- pr_gid = data.GetMaxU64(&offset, data.GetAddressByteSize() >> 1);
+ // 16 bit on 32 bit platforms, 32 bit on 64 bit platforms
+ pr_uid = data.GetMaxU64(&offset, data.GetAddressByteSize() >> 1);
+ pr_gid = data.GetMaxU64(&offset, data.GetAddressByteSize() >> 1);
}
pr_pid = data.GetU32(&offset);
diff --git a/source/Plugins/Process/elf-core/ThreadElfCore.h b/source/Plugins/Process/elf-core/ThreadElfCore.h
index 335f698dbb248..167fd6edc4ce3 100644
--- a/source/Plugins/Process/elf-core/ThreadElfCore.h
+++ b/source/Plugins/Process/elf-core/ThreadElfCore.h
@@ -146,8 +146,6 @@ public:
lldb::RegisterContextSP
CreateRegisterContextForFrame(lldb_private::StackFrame *frame) override;
- void ClearStackFrames() override;
-
static bool ThreadIDIsValid(lldb::tid_t thread) { return thread != 0; }
const char *GetName() override {
diff --git a/source/Plugins/Process/gdb-remote/GDBRemoteClientBase.cpp b/source/Plugins/Process/gdb-remote/GDBRemoteClientBase.cpp
index 4d4a4f8c5c7a8..4e20b56fb111b 100644
--- a/source/Plugins/Process/gdb-remote/GDBRemoteClientBase.cpp
+++ b/source/Plugins/Process/gdb-remote/GDBRemoteClientBase.cpp
@@ -109,16 +109,14 @@ StateType GDBRemoteClientBase::SendContinuePacketAndWaitForResponse(
const bool should_stop = ShouldStop(signals, response);
response.SetFilePos(0);
- // The packet we should resume with. In the future
- // we should check our thread list and "do the right thing"
- // for new threads that show up while we stop and run async
- // packets. Setting the packet to 'c' to continue all threads
- // is the right thing to do 99.99% of the time because if a
- // thread was single stepping, and we sent an interrupt, we
- // will notice above that we didn't stop due to an interrupt
- // but stopped due to stepping and we would _not_ continue.
- // This packet may get modified by the async actions (e.g. to send a
- // signal).
+ // The packet we should resume with. In the future we should check our
+ // thread list and "do the right thing" for new threads that show up
+ // while we stop and run async packets. Setting the packet to 'c' to
+ // continue all threads is the right thing to do 99.99% of the time
+ // because if a thread was single stepping, and we sent an interrupt, we
+ // will notice above that we didn't stop due to an interrupt but stopped
+ // due to stepping and we would _not_ continue. This packet may get
+ // modified by the async actions (e.g. to send a signal).
m_continue_packet = 'c';
cont_lock.unlock();
@@ -177,6 +175,30 @@ GDBRemoteClientBase::SendPacketAndWaitForResponse(
}
GDBRemoteCommunication::PacketResult
+GDBRemoteClientBase::SendPacketAndReceiveResponseWithOutputSupport(
+ llvm::StringRef payload, StringExtractorGDBRemote &response,
+ bool send_async,
+ llvm::function_ref<void(llvm::StringRef)> output_callback) {
+ Lock lock(*this, send_async);
+ if (!lock) {
+ if (Log *log =
+ ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_PROCESS))
+ log->Printf("GDBRemoteClientBase::%s failed to get mutex, not sending "
+ "packet '%.*s' (send_async=%d)",
+ __FUNCTION__, int(payload.size()), payload.data(),
+ send_async);
+ return PacketResult::ErrorSendFailed;
+ }
+
+ PacketResult packet_result = SendPacketNoLock(payload);
+ if (packet_result != PacketResult::Success)
+ return packet_result;
+
+ return ReadPacketWithOutputSupport(response, GetPacketTimeout(), true,
+ output_callback);
+}
+
+GDBRemoteCommunication::PacketResult
GDBRemoteClientBase::SendPacketAndWaitForResponseNoLock(
llvm::StringRef payload, StringExtractorGDBRemote &response) {
PacketResult packet_result = SendPacketNoLock(payload);
@@ -239,19 +261,16 @@ bool GDBRemoteClientBase::ShouldStop(const UnixSignals &signals,
if (m_async_count == 0)
return true; // We were not interrupted. The process stopped on its own.
- // Older debugserver stubs (before April 2016) can return two
- // stop-reply packets in response to a ^C packet.
- // Additionally, all debugservers still return two stop replies if
- // the inferior stops due to some other reason before the remote
- // stub manages to interrupt it. We need to wait for this
- // additional packet to make sure the packet sequence does not get
- // skewed.
+ // Older debugserver stubs (before April 2016) can return two stop-reply
+ // packets in response to a ^C packet. Additionally, all debugservers still
+ // return two stop replies if the inferior stops due to some other reason
+ // before the remote stub manages to interrupt it. We need to wait for this
+ // additional packet to make sure the packet sequence does not get skewed.
StringExtractorGDBRemote extra_stop_reply_packet;
ReadPacket(extra_stop_reply_packet, milliseconds(100), false);
- // Interrupting is typically done using SIGSTOP or SIGINT, so if
- // the process stops with some other signal, we definitely want to
- // stop.
+ // Interrupting is typically done using SIGSTOP or SIGINT, so if the process
+ // stops with some other signal, we definitely want to stop.
const uint8_t signo = response.GetHexU8(UINT8_MAX);
if (signo != signals.GetSignalNumberFromName("SIGSTOP") &&
signo != signals.GetSignalNumberFromName("SIGINT"))
diff --git a/source/Plugins/Process/gdb-remote/GDBRemoteClientBase.h b/source/Plugins/Process/gdb-remote/GDBRemoteClientBase.h
index 2646405c9b916..3d84ce0ebe188 100644
--- a/source/Plugins/Process/gdb-remote/GDBRemoteClientBase.h
+++ b/source/Plugins/Process/gdb-remote/GDBRemoteClientBase.h
@@ -48,6 +48,11 @@ public:
StringExtractorGDBRemote &response,
bool send_async);
+ PacketResult SendPacketAndReceiveResponseWithOutputSupport(
+ llvm::StringRef payload, StringExtractorGDBRemote &response,
+ bool send_async,
+ llvm::function_ref<void(llvm::StringRef)> output_callback);
+
bool SendvContPacket(llvm::StringRef payload,
StringExtractorGDBRemote &response);
diff --git a/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp b/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp
index 949cf19db658a..c335b60028619 100644
--- a/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp
+++ b/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp
@@ -150,9 +150,8 @@ GDBRemoteCommunication::~GDBRemoteCommunication() {
Disconnect();
}
- // Stop the communications read thread which is used to parse all
- // incoming packets. This function will block until the read
- // thread returns.
+ // Stop the communications read thread which is used to parse all incoming
+ // packets. This function will block until the read thread returns.
if (m_read_thread_enabled)
StopReadThread();
}
@@ -217,12 +216,10 @@ GDBRemoteCommunication::SendPacketNoLock(llvm::StringRef payload) {
}
}
- // If logging was just enabled and we have history, then dump out what
- // we have to the log so we get the historical context. The Dump() call
- // that
+ // If logging was just enabled and we have history, then dump out what we
+ // have to the log so we get the historical context. The Dump() call that
// logs all of the packet will set a boolean so that we don't dump this
- // more
- // than once
+ // more than once
if (!m_history.DidDumpToLog())
m_history.Dump(log);
@@ -275,6 +272,23 @@ GDBRemoteCommunication::PacketResult GDBRemoteCommunication::GetAck() {
}
GDBRemoteCommunication::PacketResult
+GDBRemoteCommunication::ReadPacketWithOutputSupport(
+ StringExtractorGDBRemote &response, Timeout<std::micro> timeout,
+ bool sync_on_timeout,
+ llvm::function_ref<void(llvm::StringRef)> output_callback) {
+ auto result = ReadPacket(response, timeout, sync_on_timeout);
+ while (result == PacketResult::Success && response.IsNormalResponse() &&
+ response.PeekChar() == 'O') {
+ response.GetChar();
+ std::string output;
+ if (response.GetHexByteString(output))
+ output_callback(output);
+ result = ReadPacket(response, timeout, sync_on_timeout);
+ }
+ return result;
+}
+
+GDBRemoteCommunication::PacketResult
GDBRemoteCommunication::ReadPacket(StringExtractorGDBRemote &response,
Timeout<std::micro> timeout,
bool sync_on_timeout) {
@@ -286,8 +300,8 @@ GDBRemoteCommunication::ReadPacket(StringExtractorGDBRemote &response,
// This function is called when a packet is requested.
// A whole packet is popped from the packet queue and returned to the caller.
-// Packets are placed into this queue from the communication read thread.
-// See GDBRemoteCommunication::AppendBytesToCache.
+// Packets are placed into this queue from the communication read thread. See
+// GDBRemoteCommunication::AppendBytesToCache.
GDBRemoteCommunication::PacketResult
GDBRemoteCommunication::PopPacketFromQueue(StringExtractorGDBRemote &response,
Timeout<std::micro> timeout) {
@@ -407,11 +421,9 @@ GDBRemoteCommunication::WaitForPacketNoLock(StringExtractorGDBRemote &packet,
break;
} else if (successful_responses == 1) {
// We got something else back as the first successful
- // response, it probably is
- // the response to the packet we actually wanted, so copy it
- // over if this
- // is the first success and continue to try to get the qEcho
- // response
+ // response, it probably is the response to the packet we
+ // actually wanted, so copy it over if this is the first
+ // success and continue to try to get the qEcho response
packet = echo_response;
got_actual_response = true;
}
@@ -424,14 +436,13 @@ GDBRemoteCommunication::WaitForPacketNoLock(StringExtractorGDBRemote &packet,
}
// We weren't able to sync back up with the server, we must abort
- // otherwise
- // all responses might not be from the right packets...
+ // otherwise all responses might not be from the right packets...
if (sync_success) {
// We timed out, but were able to recover
if (got_actual_response) {
// We initially timed out, but we did get a response that came in
- // before the successful
- // reply to our qEcho packet, so lets say everything is fine...
+ // before the successful reply to our qEcho packet, so lets say
+ // everything is fine...
return PacketResult::Success;
}
} else {
@@ -473,10 +484,9 @@ bool GDBRemoteCommunication::DecompressPacket() {
size_t pkt_size = m_bytes.size();
- // Smallest possible compressed packet is $N#00 - an uncompressed empty reply,
- // most commonly indicating
- // an unsupported packet. Anything less than 5 characters, it's definitely
- // not a compressed packet.
+ // Smallest possible compressed packet is $N#00 - an uncompressed empty
+ // reply, most commonly indicating an unsupported packet. Anything less than
+ // 5 characters, it's definitely not a compressed packet.
if (pkt_size < 5)
return true;
@@ -505,17 +515,15 @@ bool GDBRemoteCommunication::DecompressPacket() {
1; // The first character of the two hex checksum characters
// Normally size_of_first_packet == m_bytes.size() but m_bytes may contain
- // multiple packets.
- // size_of_first_packet is the size of the initial packet which we'll replace
- // with the decompressed
- // version of, leaving the rest of m_bytes unmodified.
+ // multiple packets. size_of_first_packet is the size of the initial packet
+ // which we'll replace with the decompressed version of, leaving the rest of
+ // m_bytes unmodified.
size_t size_of_first_packet = hash_mark_idx + 3;
// Compressed packets ("$C") start with a base10 number which is the size of
- // the uncompressed payload,
- // then a : and then the compressed data. e.g. $C1024:<binary>#00
- // Update content_start and content_length to only include the <binary> part
- // of the packet.
+ // the uncompressed payload, then a : and then the compressed data. e.g.
+ // $C1024:<binary>#00 Update content_start and content_length to only include
+ // the <binary> part of the packet.
uint64_t decompressed_bufsize = ULONG_MAX;
if (m_bytes[1] == 'C') {
@@ -564,15 +572,14 @@ bool GDBRemoteCommunication::DecompressPacket() {
}
if (m_bytes[1] == 'N') {
- // This packet was not compressed -- delete the 'N' character at the
- // start and the packet may be processed as-is.
+ // This packet was not compressed -- delete the 'N' character at the start
+ // and the packet may be processed as-is.
m_bytes.erase(1, 1);
return true;
}
- // Reverse the gdb-remote binary escaping that was done to the compressed text
- // to
- // guard characters like '$', '#', '}', etc.
+ // Reverse the gdb-remote binary escaping that was done to the compressed
+ // text to guard characters like '$', '#', '}', etc.
std::vector<uint8_t> unescaped_content;
unescaped_content.reserve(content_length);
size_t i = content_start;
@@ -613,12 +620,10 @@ bool GDBRemoteCommunication::DecompressPacket() {
else if (m_compression_type == CompressionType::LZMA)
compression_type = COMPRESSION_LZMA;
- // If we have the expected size of the decompressed payload, we can allocate
- // the right-sized buffer and do it. If we don't have that information,
- // we'll
- // need to try decoding into a big buffer and if the buffer wasn't big
- // enough,
- // increase it and try again.
+ // If we have the expected size of the decompressed payload, we can
+ // allocate the right-sized buffer and do it. If we don't have that
+ // information, we'll need to try decoding into a big buffer and if the
+ // buffer wasn't big enough, increase it and try again.
if (decompressed_bufsize != ULONG_MAX && decompressed_buffer != nullptr) {
decompressed_bytes = compression_decode_buffer(
@@ -706,9 +711,8 @@ GDBRemoteCommunication::CheckForPacket(const uint8_t *src, size_t src_len,
// Parse up the packets into gdb remote packets
if (!m_bytes.empty()) {
- // end_idx must be one past the last valid packet byte. Start
- // it off with an invalid value that is the same as the current
- // index.
+ // end_idx must be one past the last valid packet byte. Start it off with
+ // an invalid value that is the same as the current index.
size_t content_start = 0;
size_t content_length = 0;
size_t total_length = 0;
@@ -743,7 +747,8 @@ GDBRemoteCommunication::CheckForPacket(const uint8_t *src, size_t src_len,
checksum_idx = hash_pos + 1;
// Skip the dollar sign
content_start = 1;
- // Don't include the # in the content or the $ in the content length
+ // Don't include the # in the content or the $ in the content
+ // length
content_length = hash_pos - 1;
total_length =
@@ -757,11 +762,10 @@ GDBRemoteCommunication::CheckForPacket(const uint8_t *src, size_t src_len,
break;
default: {
- // We have an unexpected byte and we need to flush all bad
- // data that is in m_bytes, so we need to find the first
- // byte that is a '+' (ACK), '-' (NACK), \x03 (CTRL+C interrupt),
- // or '$' character (start of packet header) or of course,
- // the end of the data in m_bytes...
+ // We have an unexpected byte and we need to flush all bad data that is
+ // in m_bytes, so we need to find the first byte that is a '+' (ACK), '-'
+ // (NACK), \x03 (CTRL+C interrupt), or '$' character (start of packet
+ // header) or of course, the end of the data in m_bytes...
const size_t bytes_len = m_bytes.size();
bool done = false;
uint32_t idx;
@@ -802,16 +806,14 @@ GDBRemoteCommunication::CheckForPacket(const uint8_t *src, size_t src_len,
if (log) {
// If logging was just enabled and we have history, then dump out what
// we have to the log so we get the historical context. The Dump() call
- // that
- // logs all of the packet will set a boolean so that we don't dump this
- // more
- // than once
+ // that logs all of the packet will set a boolean so that we don't dump
+ // this more than once
if (!m_history.DidDumpToLog())
m_history.Dump(log);
bool binary = false;
- // Only detect binary for packets that start with a '$' and have a '#CC'
- // checksum
+ // Only detect binary for packets that start with a '$' and have a
+ // '#CC' checksum
if (m_bytes[0] == '$' && total_length > 4) {
for (size_t i = 0; !binary && i < total_length; ++i) {
unsigned char c = m_bytes[i];
@@ -834,8 +836,8 @@ GDBRemoteCommunication::CheckForPacket(const uint8_t *src, size_t src_len,
// Remove binary escaped bytes when displaying the packet...
const char ch = m_bytes[i];
if (ch == 0x7d) {
- // 0x7d is the escape character. The next character is to
- // be XOR'd with 0x20.
+ // 0x7d is the escape character. The next character is to be
+ // XOR'd with 0x20.
const char escapee = m_bytes[++i] ^ 0x20;
strm.Printf("%2.2x", escapee);
} else {
@@ -863,26 +865,25 @@ GDBRemoteCommunication::CheckForPacket(const uint8_t *src, size_t src_len,
// Clear packet_str in case there is some existing data in it.
packet_str.clear();
- // Copy the packet from m_bytes to packet_str expanding the
- // run-length encoding in the process.
- // Reserve enough byte for the most common case (no RLE used)
+ // Copy the packet from m_bytes to packet_str expanding the run-length
+ // encoding in the process. Reserve enough byte for the most common case
+ // (no RLE used)
packet_str.reserve(m_bytes.length());
for (std::string::const_iterator c = m_bytes.begin() + content_start;
c != m_bytes.begin() + content_end; ++c) {
if (*c == '*') {
- // '*' indicates RLE. Next character will give us the
- // repeat count and previous character is what is to be
- // repeated.
+ // '*' indicates RLE. Next character will give us the repeat count
+ // and previous character is what is to be repeated.
char char_to_repeat = packet_str.back();
// Number of time the previous character is repeated
int repeat_count = *++c + 3 - ' ';
- // We have the char_to_repeat and repeat_count. Now push
- // it in the packet.
+ // We have the char_to_repeat and repeat_count. Now push it in the
+ // packet.
for (int i = 0; i < repeat_count; ++i)
packet_str.push_back(char_to_repeat);
} else if (*c == 0x7d) {
- // 0x7d is the escape character. The next character is to
- // be XOR'd with 0x20.
+ // 0x7d is the escape character. The next character is to be XOR'd
+ // with 0x20.
char escapee = *++c ^ 0x20;
packet_str.push_back(escapee);
} else {
@@ -897,7 +898,8 @@ GDBRemoteCommunication::CheckForPacket(const uint8_t *src, size_t src_len,
if (GetSendAcks()) {
const char *packet_checksum_cstr = &m_bytes[checksum_idx];
char packet_checksum = strtol(packet_checksum_cstr, NULL, 16);
- char actual_checksum = CalculcateChecksum(packet_str);
+ char actual_checksum = CalculcateChecksum(
+ llvm::StringRef(m_bytes).slice(content_start, content_end));
success = packet_checksum == actual_checksum;
if (!success) {
if (log)
@@ -991,11 +993,12 @@ Status GDBRemoteCommunication::StartDebugserverProcess(
char debugserver_path[PATH_MAX];
FileSpec &debugserver_file_spec = launch_info.GetExecutableFile();
- // Always check to see if we have an environment override for the path
- // to the debugserver to use and use it if we do.
+ // Always check to see if we have an environment override for the path to the
+ // debugserver to use and use it if we do.
const char *env_debugserver_path = getenv("LLDB_DEBUGSERVER_PATH");
if (env_debugserver_path) {
- debugserver_file_spec.SetFile(env_debugserver_path, false);
+ debugserver_file_spec.SetFile(env_debugserver_path, false,
+ FileSpec::Style::native);
if (log)
log->Printf("GDBRemoteCommunication::%s() gdb-remote stub exe path set "
"from environment variable: %s",
@@ -1004,10 +1007,9 @@ Status GDBRemoteCommunication::StartDebugserverProcess(
debugserver_file_spec = g_debugserver_file_spec;
bool debugserver_exists = debugserver_file_spec.Exists();
if (!debugserver_exists) {
- // The debugserver binary is in the LLDB.framework/Resources
- // directory.
- if (HostInfo::GetLLDBPath(ePathTypeSupportExecutableDir,
- debugserver_file_spec)) {
+ // The debugserver binary is in the LLDB.framework/Resources directory.
+ debugserver_file_spec = HostInfo::GetSupportExeDir();
+ if (debugserver_file_spec) {
debugserver_file_spec.AppendPathComponent(DEBUGSERVER_BASENAME);
debugserver_exists = debugserver_file_spec.Exists();
if (debugserver_exists) {
@@ -1031,8 +1033,7 @@ Status GDBRemoteCommunication::StartDebugserverProcess(
__FUNCTION__, debugserver_file_spec.GetPath().c_str());
}
// Don't cache the platform specific GDB server binary as it could
- // change
- // from platform to platform
+ // change from platform to platform
g_debugserver_file_spec.Clear();
}
}
@@ -1080,14 +1081,14 @@ Status GDBRemoteCommunication::StartDebugserverProcess(
// once data is written to the pipe, debug server is up and running.
Pipe socket_pipe;
- // port is null when debug server should listen on domain socket -
- // we're not interested in port value but rather waiting for debug server
- // to become available.
+ // port is null when debug server should listen on domain socket - we're
+ // not interested in port value but rather waiting for debug server to
+ // become available.
if (pass_comm_fd == -1) {
if (url) {
-// Create a temporary file to get the stdout/stderr and redirect the
-// output of the command into this file. We will later read this file
-// if all goes well and fill the data into "command_output_ptr"
+// Create a temporary file to get the stdout/stderr and redirect the output of
+// the command into this file. We will later read this file if all goes well
+// and fill the data into "command_output_ptr"
#if defined(__APPLE__)
// Binding to port zero, we need to figure out what port it ends up
// using using a named pipe...
@@ -1120,8 +1121,7 @@ Status GDBRemoteCommunication::StartDebugserverProcess(
#endif
} else {
// No host and port given, so lets listen on our end and make the
- // debugserver
- // connect to us..
+ // debugserver connect to us..
error = StartListenThread("127.0.0.1", 0);
if (error.Fail()) {
if (log)
@@ -1134,7 +1134,7 @@ Status GDBRemoteCommunication::StartDebugserverProcess(
ConnectionFileDescriptor *connection =
(ConnectionFileDescriptor *)GetConnection();
// Wait for 10 seconds to resolve the bound port
- uint16_t port_ = connection->GetListeningPort(10);
+ uint16_t port_ = connection->GetListeningPort(std::chrono::seconds(10));
if (port_ > 0) {
char port_cstr[32];
snprintf(port_cstr, sizeof(port_cstr), "127.0.0.1:%i", port_);
@@ -1206,11 +1206,7 @@ Status GDBRemoteCommunication::StartDebugserverProcess(
}
// Copy the current environment to the gdbserver/debugserver instance
- StringList env;
- if (Host::GetEnvironment(env)) {
- for (size_t i = 0; i < env.GetSize(); ++i)
- launch_info.GetEnvironmentEntries().AppendArgument(env[i]);
- }
+ launch_info.GetEnvironment() = Host::GetEnvironment();
// Close STDIN, STDOUT and STDERR.
launch_info.AppendCloseFileAction(STDIN_FILENO);
@@ -1327,14 +1323,11 @@ GDBRemoteCommunication::ScopedTimeout::~ScopedTimeout() {
}
// This function is called via the Communications class read thread when bytes
-// become available
-// for this connection. This function will consume all incoming bytes and try to
-// parse whole
-// packets as they become available. Full packets are placed in a queue, so that
-// all packet
-// requests can simply pop from this queue. Async notification packets will be
-// dispatched
-// immediately to the ProcessGDBRemote Async thread via an event.
+// become available for this connection. This function will consume all
+// incoming bytes and try to parse whole packets as they become available. Full
+// packets are placed in a queue, so that all packet requests can simply pop
+// from this queue. Async notification packets will be dispatched immediately
+// to the ProcessGDBRemote Async thread via an event.
void GDBRemoteCommunication::AppendBytesToCache(const uint8_t *bytes,
size_t len, bool broadcast,
lldb::ConnectionStatus status) {
@@ -1343,8 +1336,8 @@ void GDBRemoteCommunication::AppendBytesToCache(const uint8_t *bytes,
while (true) {
PacketType type = CheckForPacket(bytes, len, packet);
- // scrub the data so we do not pass it back to CheckForPacket
- // on future passes of the loop
+ // scrub the data so we do not pass it back to CheckForPacket on future
+ // passes of the loop
bytes = nullptr;
len = 0;
@@ -1368,8 +1361,8 @@ void GDBRemoteCommunication::AppendBytesToCache(const uint8_t *bytes,
// put this packet into an event
const char *pdata = packet.GetStringRef().c_str();
- // as the communication class, we are a broadcaster and the
- // async thread is tuned to listen to us
+ // as the communication class, we are a broadcaster and the async thread
+ // is tuned to listen to us
BroadcastEvent(eBroadcastBitGdbReadThreadGotNotify,
new EventDataBytes(pdata));
}
diff --git a/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.h b/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.h
index ecc9386e49c7d..67796e4c61ef2 100644
--- a/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.h
+++ b/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.h
@@ -24,10 +24,10 @@
#include "lldb/Core/Listener.h"
#include "lldb/Host/HostThread.h"
#include "lldb/Host/Predicate.h"
-#include "lldb/Interpreter/Args.h"
+#include "lldb/Utility/Args.h"
#include "lldb/lldb-public.h"
-#include "Utility/StringExtractorGDBRemote.h"
+#include "lldb/Utility/StringExtractorGDBRemote.h"
namespace lldb_private {
namespace process_gdb_remote {
@@ -232,6 +232,11 @@ protected:
PacketResult ReadPacket(StringExtractorGDBRemote &response,
Timeout<std::micro> timeout, bool sync_on_timeout);
+ PacketResult ReadPacketWithOutputSupport(
+ StringExtractorGDBRemote &response, Timeout<std::micro> timeout,
+ bool sync_on_timeout,
+ llvm::function_ref<void(llvm::StringRef)> output_callback);
+
// Pop a packet from the queue in a thread safe manner
PacketResult PopPacketFromQueue(StringExtractorGDBRemote &response,
Timeout<std::micro> timeout);
diff --git a/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp b/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
index 867f57c475cec..c8b59d5d236b9 100644
--- a/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
+++ b/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
@@ -21,11 +21,12 @@
#include "lldb/Core/ModuleSpec.h"
#include "lldb/Core/State.h"
#include "lldb/Host/HostInfo.h"
-#include "lldb/Interpreter/Args.h"
+#include "lldb/Host/XML.h"
#include "lldb/Symbol/Symbol.h"
#include "lldb/Target/MemoryRegionInfo.h"
#include "lldb/Target/Target.h"
#include "lldb/Target/UnixSignals.h"
+#include "lldb/Utility/Args.h"
#include "lldb/Utility/DataBufferHeap.h"
#include "lldb/Utility/JSON.h"
#include "lldb/Utility/LLDBAssert.h"
@@ -35,8 +36,8 @@
// Project includes
#include "ProcessGDBRemote.h"
#include "ProcessGDBRemoteLog.h"
-#include "Utility/StringExtractorGDBRemote.h"
#include "lldb/Host/Config.h"
+#include "lldb/Utility/StringExtractorGDBRemote.h"
#include "llvm/ADT/StringSwitch.h"
@@ -81,6 +82,7 @@ GDBRemoteCommunicationClient::GDBRemoteCommunicationClient()
m_supports_qXfer_libraries_read(eLazyBoolCalculate),
m_supports_qXfer_libraries_svr4_read(eLazyBoolCalculate),
m_supports_qXfer_features_read(eLazyBoolCalculate),
+ m_supports_qXfer_memory_map_read(eLazyBoolCalculate),
m_supports_augmented_libraries_svr4_read(eLazyBoolCalculate),
m_supports_jThreadExtendedInfo(eLazyBoolCalculate),
m_supports_jLoadedDynamicLibrariesInfos(eLazyBoolCalculate),
@@ -98,12 +100,12 @@ GDBRemoteCommunicationClient::GDBRemoteCommunicationClient()
m_curr_pid(LLDB_INVALID_PROCESS_ID), m_curr_tid(LLDB_INVALID_THREAD_ID),
m_curr_tid_run(LLDB_INVALID_THREAD_ID),
m_num_supported_hardware_watchpoints(0), m_host_arch(), m_process_arch(),
- m_os_version_major(UINT32_MAX), m_os_version_minor(UINT32_MAX),
- m_os_version_update(UINT32_MAX), m_os_build(), m_os_kernel(),
- m_hostname(), m_gdb_server_name(), m_gdb_server_version(UINT32_MAX),
- m_default_packet_timeout(0), m_max_packet_size(0),
- m_qSupported_response(), m_supported_async_json_packets_is_valid(false),
- m_supported_async_json_packets_sp() {}
+ m_os_build(), m_os_kernel(), m_hostname(), m_gdb_server_name(),
+ m_gdb_server_version(UINT32_MAX), m_default_packet_timeout(0),
+ m_max_packet_size(0), m_qSupported_response(),
+ m_supported_async_json_packets_is_valid(false),
+ m_supported_async_json_packets_sp(), m_qXfer_memory_map(),
+ m_qXfer_memory_map_loaded(false) {}
//----------------------------------------------------------------------
// Destructor
@@ -116,8 +118,8 @@ GDBRemoteCommunicationClient::~GDBRemoteCommunicationClient() {
bool GDBRemoteCommunicationClient::HandshakeWithServer(Status *error_ptr) {
ResetDiscoverableSettings(false);
- // Start the read thread after we send the handshake ack since if we
- // fail to send the handshake ack, there is no reason to continue...
+ // Start the read thread after we send the handshake ack since if we fail to
+ // send the handshake ack, there is no reason to continue...
if (SendAck()) {
// Wait for any responses that might have been queued up in the remote
// GDB server and flush them all
@@ -127,9 +129,9 @@ bool GDBRemoteCommunicationClient::HandshakeWithServer(Status *error_ptr) {
packet_result = ReadPacket(response, milliseconds(10), false);
// The return value from QueryNoAckModeSupported() is true if the packet
- // was sent and _any_ response (including UNIMPLEMENTED) was received),
- // or false if no response was received. This quickly tells us if we have
- // a live connection to a remote GDB server...
+ // was sent and _any_ response (including UNIMPLEMENTED) was received), or
+ // false if no response was received. This quickly tells us if we have a
+ // live connection to a remote GDB server...
if (QueryNoAckModeSupported()) {
return true;
} else {
@@ -192,6 +194,13 @@ bool GDBRemoteCommunicationClient::GetQXferFeaturesReadSupported() {
return m_supports_qXfer_features_read == eLazyBoolYes;
}
+bool GDBRemoteCommunicationClient::GetQXferMemoryMapReadSupported() {
+ if (m_supports_qXfer_memory_map_read == eLazyBoolCalculate) {
+ GetRemoteQSupported();
+ }
+ return m_supports_qXfer_memory_map_read == eLazyBoolYes;
+}
+
uint64_t GDBRemoteCommunicationClient::GetRemoteMaxPacketSize() {
if (m_max_packet_size == 0) {
GetRemoteQSupported();
@@ -205,9 +214,8 @@ bool GDBRemoteCommunicationClient::QueryNoAckModeSupported() {
m_supports_not_sending_acks = eLazyBoolNo;
// This is the first real packet that we'll send in a debug session and it
- // may take a little
- // longer than normal to receive a reply. Wait at least 6 seconds for a
- // reply to this packet.
+ // may take a little longer than normal to receive a reply. Wait at least
+ // 6 seconds for a reply to this packet.
ScopedTimeout timeout(*this, std::max(GetPacketTimeout(), seconds(6)));
@@ -296,6 +304,7 @@ void GDBRemoteCommunicationClient::ResetDiscoverableSettings(bool did_exec) {
m_supports_qXfer_libraries_read = eLazyBoolCalculate;
m_supports_qXfer_libraries_svr4_read = eLazyBoolCalculate;
m_supports_qXfer_features_read = eLazyBoolCalculate;
+ m_supports_qXfer_memory_map_read = eLazyBoolCalculate;
m_supports_augmented_libraries_svr4_read = eLazyBoolCalculate;
m_supports_qProcessInfoPID = true;
m_supports_qfProcessInfo = true;
@@ -313,9 +322,7 @@ void GDBRemoteCommunicationClient::ResetDiscoverableSettings(bool did_exec) {
m_qSymbol_requests_done = false;
m_supports_qModuleInfo = true;
m_host_arch.Clear();
- m_os_version_major = UINT32_MAX;
- m_os_version_minor = UINT32_MAX;
- m_os_version_update = UINT32_MAX;
+ m_os_version = llvm::VersionTuple();
m_os_build.clear();
m_os_kernel.clear();
m_hostname.clear();
@@ -329,8 +336,8 @@ void GDBRemoteCommunicationClient::ResetDiscoverableSettings(bool did_exec) {
m_supports_jModulesInfo = true;
}
- // These flags should be reset when we first connect to a GDB server
- // and when our inferior process execs
+ // These flags should be reset when we first connect to a GDB server and when
+ // our inferior process execs
m_qProcessInfo_is_valid = eLazyBoolCalculate;
m_process_arch.Clear();
}
@@ -342,6 +349,7 @@ void GDBRemoteCommunicationClient::GetRemoteQSupported() {
m_supports_qXfer_libraries_svr4_read = eLazyBoolNo;
m_supports_augmented_libraries_svr4_read = eLazyBoolNo;
m_supports_qXfer_features_read = eLazyBoolNo;
+ m_supports_qXfer_memory_map_read = eLazyBoolNo;
m_max_packet_size = UINT64_MAX; // It's supposed to always be there, but if
// not, we assume no limit
@@ -361,8 +369,7 @@ void GDBRemoteCommunicationClient::GetRemoteQSupported() {
const char *response_cstr = response.GetStringRef().c_str();
// Hang on to the qSupported packet, so that platforms can do custom
- // configuration of the transport before attaching/launching the
- // process.
+ // configuration of the transport before attaching/launching the process.
m_qSupported_response = response_cstr;
if (::strstr(response_cstr, "qXfer:auxv:read+"))
@@ -377,9 +384,12 @@ void GDBRemoteCommunicationClient::GetRemoteQSupported() {
m_supports_qXfer_libraries_read = eLazyBoolYes;
if (::strstr(response_cstr, "qXfer:features:read+"))
m_supports_qXfer_features_read = eLazyBoolYes;
+ if (::strstr(response_cstr, "qXfer:memory-map:read+"))
+ m_supports_qXfer_memory_map_read = eLazyBoolYes;
// Look for a list of compressions in the features list e.g.
- // qXfer:features:read+;PacketSize=20000;qEcho+;SupportedCompressions=zlib-deflate,lzma
+ // qXfer:features:read+;PacketSize=20000;qEcho+;SupportedCompressions=zlib-
+ // deflate,lzma
const char *features_list = ::strstr(response_cstr, "qXfer:features:");
if (features_list) {
const char *compressions =
@@ -543,9 +553,8 @@ GDBRemoteCommunicationClient::SendThreadSpecificPacketAndWaitForResponse(
return SendPacketAndWaitForResponseNoLock(payload.GetString(), response);
}
-// Check if the target supports 'p' packet. It sends out a 'p'
-// packet and checks the response. A normal packet will tell us
-// that support is available.
+// Check if the target supports 'p' packet. It sends out a 'p' packet and
+// checks the response. A normal packet will tell us that support is available.
//
// Takes a valid thread ID because p needs to apply to a thread.
bool GDBRemoteCommunicationClient::GetpPacketSupported(lldb::tid_t tid) {
@@ -600,8 +609,8 @@ bool GDBRemoteCommunicationClient::GetThreadExtendedInfoSupported() {
void GDBRemoteCommunicationClient::EnableErrorStringInPacket() {
if (m_supports_error_string_reply == eLazyBoolCalculate) {
StringExtractorGDBRemote response;
- // We try to enable error strings in remote packets
- // but if we fail, we just work in the older way.
+ // We try to enable error strings in remote packets but if we fail, we just
+ // work in the older way.
m_supports_error_string_reply = eLazyBoolNo;
if (SendPacketAndWaitForResponse("QEnableErrorStrings", response, false) ==
PacketResult::Success) {
@@ -715,12 +724,10 @@ lldb::pid_t GDBRemoteCommunicationClient::GetCurrentProcessID(bool allow_lazy) {
return m_curr_pid;
} else {
// If we don't get a response for qProcessInfo, check if $qC gives us a
- // result.
- // $qC only returns a real process id on older debugserver and lldb-platform
- // stubs.
- // The gdb remote protocol documents $qC as returning the thread id, which
- // newer
- // debugserver and lldb-gdbserver stubs return correctly.
+ // result. $qC only returns a real process id on older debugserver and
+ // lldb-platform stubs. The gdb remote protocol documents $qC as returning
+ // the thread id, which newer debugserver and lldb-gdbserver stubs return
+ // correctly.
StringExtractorGDBRemote response;
if (SendPacketAndWaitForResponse("qC", response, false) ==
PacketResult::Success) {
@@ -775,8 +782,8 @@ bool GDBRemoteCommunicationClient::GetLaunchSuccess(std::string &error_str) {
int GDBRemoteCommunicationClient::SendArgumentsPacket(
const ProcessLaunchInfo &launch_info) {
// Since we don't get the send argv0 separate from the executable path, we
- // need to
- // make sure to use the actual executable path found in the launch_info...
+ // need to make sure to use the actual executable path found in the
+ // launch_info...
std::vector<const char *> argv;
FileSpec exe_file = launch_info.GetExecutableFile();
std::string exe_path;
@@ -822,6 +829,15 @@ int GDBRemoteCommunicationClient::SendArgumentsPacket(
return -1;
}
+int GDBRemoteCommunicationClient::SendEnvironment(const Environment &env) {
+ for (const auto &KV : env) {
+ int r = SendEnvironmentPacket(Environment::compose(KV).c_str());
+ if (r != 0)
+ return r;
+ }
+ return 0;
+}
+
int GDBRemoteCommunicationClient::SendEnvironmentPacket(
char const *name_equal_value) {
if (name_equal_value && name_equal_value[0]) {
@@ -925,18 +941,9 @@ int GDBRemoteCommunicationClient::SendLaunchEventDataPacket(
return -1;
}
-bool GDBRemoteCommunicationClient::GetOSVersion(uint32_t &major,
- uint32_t &minor,
- uint32_t &update) {
- if (GetHostInfo()) {
- if (m_os_version_major != UINT32_MAX) {
- major = m_os_version_major;
- minor = m_os_version_minor;
- update = m_os_version_update;
- return true;
- }
- }
- return false;
+llvm::VersionTuple GDBRemoteCommunicationClient::GetOSVersion() {
+ GetHostInfo();
+ return m_os_version;
}
bool GDBRemoteCommunicationClient::GetOSBuildString(std::string &s) {
@@ -1199,9 +1206,7 @@ bool GDBRemoteCommunicationClient::GetHostInfo(bool force) {
// "version" key instead of
// "os_version"...
{
- Args::StringToVersion(value, m_os_version_major, m_os_version_minor,
- m_os_version_update);
- if (m_os_version_major != UINT32_MAX)
+ if (!m_os_version.tryParse(value))
++num_keys_decoded;
} else if (name.equals("watchpoint_exceptions_received")) {
m_watchpoints_trigger_after_instruction =
@@ -1451,7 +1456,8 @@ Status GDBRemoteCommunicationClient::GetMemoryRegionInfo(
UNUSED_IF_ASSERT_DISABLED(packet_len);
StringExtractorGDBRemote response;
if (SendPacketAndWaitForResponse(packet, response, false) ==
- PacketResult::Success) {
+ PacketResult::Success &&
+ response.GetResponseType() == StringExtractorGDBRemote::eResponse) {
llvm::StringRef name;
llvm::StringRef value;
addr_t addr_value = LLDB_INVALID_ADDRESS;
@@ -1527,8 +1533,134 @@ Status GDBRemoteCommunicationClient::GetMemoryRegionInfo(
if (m_supports_memory_region_info == eLazyBoolNo) {
error.SetErrorString("qMemoryRegionInfo is not supported");
}
- if (error.Fail())
- region_info.Clear();
+
+ // Try qXfer:memory-map:read to get region information not included in
+ // qMemoryRegionInfo
+ MemoryRegionInfo qXfer_region_info;
+ Status qXfer_error = GetQXferMemoryMapRegionInfo(addr, qXfer_region_info);
+
+ if (error.Fail()) {
+ // If qMemoryRegionInfo failed, but qXfer:memory-map:read succeeded, use
+ // the qXfer result as a fallback
+ if (qXfer_error.Success()) {
+ region_info = qXfer_region_info;
+ error.Clear();
+ } else {
+ region_info.Clear();
+ }
+ } else if (qXfer_error.Success()) {
+ // If both qMemoryRegionInfo and qXfer:memory-map:read succeeded, and if
+ // both regions are the same range, update the result to include the flash-
+ // memory information that is specific to the qXfer result.
+ if (region_info.GetRange() == qXfer_region_info.GetRange()) {
+ region_info.SetFlash(qXfer_region_info.GetFlash());
+ region_info.SetBlocksize(qXfer_region_info.GetBlocksize());
+ }
+ }
+ return error;
+}
+
+Status GDBRemoteCommunicationClient::GetQXferMemoryMapRegionInfo(
+ lldb::addr_t addr, MemoryRegionInfo &region) {
+ Status error = LoadQXferMemoryMap();
+ if (!error.Success())
+ return error;
+ for (const auto &map_region : m_qXfer_memory_map) {
+ if (map_region.GetRange().Contains(addr)) {
+ region = map_region;
+ return error;
+ }
+ }
+ error.SetErrorString("Region not found");
+ return error;
+}
+
+Status GDBRemoteCommunicationClient::LoadQXferMemoryMap() {
+
+ Status error;
+
+ if (m_qXfer_memory_map_loaded)
+ // Already loaded, return success
+ return error;
+
+ if (!XMLDocument::XMLEnabled()) {
+ error.SetErrorString("XML is not supported");
+ return error;
+ }
+
+ if (!GetQXferMemoryMapReadSupported()) {
+ error.SetErrorString("Memory map is not supported");
+ return error;
+ }
+
+ std::string xml;
+ lldb_private::Status lldberr;
+ if (!ReadExtFeature(ConstString("memory-map"), ConstString(""), xml,
+ lldberr)) {
+ error.SetErrorString("Failed to read memory map");
+ return error;
+ }
+
+ XMLDocument xml_document;
+
+ if (!xml_document.ParseMemory(xml.c_str(), xml.size())) {
+ error.SetErrorString("Failed to parse memory map xml");
+ return error;
+ }
+
+ XMLNode map_node = xml_document.GetRootElement("memory-map");
+ if (!map_node) {
+ error.SetErrorString("Invalid root node in memory map xml");
+ return error;
+ }
+
+ m_qXfer_memory_map.clear();
+
+ map_node.ForEachChildElement([this](const XMLNode &memory_node) -> bool {
+ if (!memory_node.IsElement())
+ return true;
+ if (memory_node.GetName() != "memory")
+ return true;
+ auto type = memory_node.GetAttributeValue("type", "");
+ uint64_t start;
+ uint64_t length;
+ if (!memory_node.GetAttributeValueAsUnsigned("start", start))
+ return true;
+ if (!memory_node.GetAttributeValueAsUnsigned("length", length))
+ return true;
+ MemoryRegionInfo region;
+ region.GetRange().SetRangeBase(start);
+ region.GetRange().SetByteSize(length);
+ if (type == "rom") {
+ region.SetReadable(MemoryRegionInfo::eYes);
+ this->m_qXfer_memory_map.push_back(region);
+ } else if (type == "ram") {
+ region.SetReadable(MemoryRegionInfo::eYes);
+ region.SetWritable(MemoryRegionInfo::eYes);
+ this->m_qXfer_memory_map.push_back(region);
+ } else if (type == "flash") {
+ region.SetFlash(MemoryRegionInfo::eYes);
+ memory_node.ForEachChildElement(
+ [&region](const XMLNode &prop_node) -> bool {
+ if (!prop_node.IsElement())
+ return true;
+ if (prop_node.GetName() != "property")
+ return true;
+ auto propname = prop_node.GetAttributeValue("name", "");
+ if (propname == "blocksize") {
+ uint64_t blocksize;
+ if (prop_node.GetElementTextAsUnsigned(blocksize))
+ region.SetBlocksize(blocksize);
+ }
+ return true;
+ });
+ this->m_qXfer_memory_map.push_back(region);
+ }
+ return true;
+ });
+
+ m_qXfer_memory_map_loaded = true;
+
return error;
}
@@ -1585,13 +1717,13 @@ GDBRemoteCommunicationClient::GetWatchpointsTriggerAfterInstruction(
Status error;
llvm::Triple::ArchType atype = arch.GetMachine();
- // we assume watchpoints will happen after running the relevant opcode
- // and we only want to override this behavior if we have explicitly
- // received a qHostInfo telling us otherwise
+ // we assume watchpoints will happen after running the relevant opcode and we
+ // only want to override this behavior if we have explicitly received a
+ // qHostInfo telling us otherwise
if (m_qHostInfo_is_valid != eLazyBoolYes) {
// On targets like MIPS and ppc64le, watchpoint exceptions are always
- // generated before the instruction is executed. The connected target
- // may not support qHostInfo or qWatchpointSupportInfo packets.
+ // generated before the instruction is executed. The connected target may
+ // not support qHostInfo or qWatchpointSupportInfo packets.
if (atype == llvm::Triple::mips || atype == llvm::Triple::mipsel ||
atype == llvm::Triple::mips64 || atype == llvm::Triple::mips64el ||
atype == llvm::Triple::ppc64le)
@@ -1789,11 +1921,12 @@ bool GDBRemoteCommunicationClient::DecodeProcessInfoResponse(
process_info.GetArchitecture().SetTriple(triple.c_str());
} else if (name.equals("name")) {
StringExtractor extractor(value);
- // The process name from ASCII hex bytes since we can't
- // control the characters in a process name
+ // The process name from ASCII hex bytes since we can't control the
+ // characters in a process name
std::string name;
extractor.GetHexByteString(name);
- process_info.GetExecutableFile().SetFile(name, false);
+ process_info.GetExecutableFile().SetFile(name, false,
+ FileSpec::Style::native);
} else if (name.equals("cputype")) {
value.getAsInteger(0, cpu);
} else if (name.equals("cpusubtype")) {
@@ -2046,8 +2179,8 @@ uint32_t GDBRemoteCommunicationClient::FindProcesses(
}
}
StringExtractorGDBRemote response;
- // Increase timeout as the first qfProcessInfo packet takes a long time
- // on Android. The value of 1min was arrived at empirically.
+ // Increase timeout as the first qfProcessInfo packet takes a long time on
+ // Android. The value of 1min was arrived at empirically.
ScopedTimeout timeout(*this, minutes(1));
if (SendPacketAndWaitForResponse(packet.GetString(), response, false) ==
PacketResult::Success) {
@@ -2081,8 +2214,8 @@ bool GDBRemoteCommunicationClient::GetUserName(uint32_t uid,
PacketResult::Success) {
if (response.IsNormalResponse()) {
// Make sure we parsed the right number of characters. The response is
- // the hex encoded user name and should make up the entire packet.
- // If there are any non-hex ASCII bytes, the length won't match below..
+ // the hex encoded user name and should make up the entire packet. If
+ // there are any non-hex ASCII bytes, the length won't match below..
if (response.GetHexByteString(name) * 2 ==
response.GetStringRef().size())
return true;
@@ -2108,8 +2241,8 @@ bool GDBRemoteCommunicationClient::GetGroupName(uint32_t gid,
PacketResult::Success) {
if (response.IsNormalResponse()) {
// Make sure we parsed the right number of characters. The response is
- // the hex encoded group name and should make up the entire packet.
- // If there are any non-hex ASCII bytes, the length won't match below..
+ // the hex encoded group name and should make up the entire packet. If
+ // there are any non-hex ASCII bytes, the length won't match below..
if (response.GetHexByteString(name) * 2 ==
response.GetStringRef().size())
return true;
@@ -2335,8 +2468,8 @@ bool GDBRemoteCommunicationClient::LaunchGDBServer(
// Make the GDB server we launch only accept connections from this host
stream.Printf("host:%s;", hostname.c_str());
} else {
- // Make the GDB server we launch accept connections from any host since we
- // can't figure out the hostname
+ // Make the GDB server we launch accept connections from any host since
+ // we can't figure out the hostname
stream.Printf("host:*;");
}
}
@@ -2650,13 +2783,16 @@ lldb_private::Status GDBRemoteCommunicationClient::RunShellCommand(
// process to exit
std::string
*command_output, // Pass NULL if you don't want the command output
- uint32_t
- timeout_sec) // Timeout in seconds to wait for shell program to finish
-{
+ const Timeout<std::micro> &timeout) {
lldb_private::StreamString stream;
stream.PutCString("qPlatform_shell:");
stream.PutBytesAsRawHex8(command, strlen(command));
stream.PutChar(',');
+ uint32_t timeout_sec = UINT32_MAX;
+ if (timeout) {
+ // TODO: Use chrono version of std::ceil once c++17 is available.
+ timeout_sec = std::ceil(std::chrono::duration<double>(*timeout).count());
+ }
stream.PutHex32(timeout_sec);
if (working_dir) {
std::string path{working_dir.GetPath(false)};
@@ -3125,9 +3261,8 @@ bool GDBRemoteCommunicationClient::SaveRegisterState(lldb::tid_t tid,
bool GDBRemoteCommunicationClient::RestoreRegisterState(lldb::tid_t tid,
uint32_t save_id) {
// We use the "m_supports_QSaveRegisterState" variable here because the
- // QSaveRegisterState and QRestoreRegisterState packets must both be supported
- // in
- // order to be useful
+ // QSaveRegisterState and QRestoreRegisterState packets must both be
+ // supported in order to be useful
if (m_supports_QSaveRegisterState == eLazyBoolNo)
return false;
@@ -3406,7 +3541,7 @@ bool GDBRemoteCommunicationClient::GetModuleInfo(
StringExtractor extractor(value);
std::string uuid;
extractor.GetHexByteString(uuid);
- module_spec.GetUUID().SetFromCString(uuid.c_str(), uuid.size() / 2);
+ module_spec.GetUUID().SetFromStringRef(uuid, uuid.size() / 2);
} else if (name == "triple") {
StringExtractor extractor(value);
std::string triple;
@@ -3523,8 +3658,8 @@ GDBRemoteCommunicationClient::GetModulesInfo(
// query the target remote for extended information using the qXfer packet
//
-// example: object='features', annex='target.xml', out=<xml output>
-// return: 'true' on success
+// example: object='features', annex='target.xml', out=<xml output> return:
+// 'true' on success
// 'false' on failure (err set)
bool GDBRemoteCommunicationClient::ReadExtFeature(
const lldb_private::ConstString object,
@@ -3631,10 +3766,9 @@ bool GDBRemoteCommunicationClient::ReadExtFeature(
void GDBRemoteCommunicationClient::ServeSymbolLookups(
lldb_private::Process *process) {
- // Set to true once we've resolved a symbol to an address for the remote stub.
- // If we get an 'OK' response after this, the remote stub doesn't need any
- // more
- // symbols and we can stop asking.
+ // Set to true once we've resolved a symbol to an address for the remote
+ // stub. If we get an 'OK' response after this, the remote stub doesn't need
+ // any more symbols and we can stop asking.
bool symbol_response_provided = false;
// Is this the initial qSymbol:: packet?
@@ -3659,8 +3793,8 @@ void GDBRemoteCommunicationClient::ServeSymbolLookups(
first_qsymbol_query = false;
if (response.IsUnsupportedResponse()) {
- // qSymbol is not supported by the current GDB server we are connected
- // to
+ // qSymbol is not supported by the current GDB server we are
+ // connected to
m_supports_qSymbol = false;
return;
} else {
@@ -3725,10 +3859,8 @@ void GDBRemoteCommunicationClient::ServeSymbolLookups(
}
}
// This is the normal path where our symbol lookup was successful
- // and we want
- // to send a packet with the new symbol value and see if another
- // lookup needs to be
- // done.
+ // and we want to send a packet with the new symbol value and see
+ // if another lookup needs to be done.
// Change "packet" to contain the requested symbol value and name
packet.Clear();
@@ -3763,8 +3895,7 @@ void GDBRemoteCommunicationClient::ServeSymbolLookups(
StructuredData::Array *
GDBRemoteCommunicationClient::GetSupportedStructuredDataPlugins() {
if (!m_supported_async_json_packets_is_valid) {
- // Query the server for the array of supported asynchronous JSON
- // packets.
+ // Query the server for the array of supported asynchronous JSON packets.
m_supported_async_json_packets_is_valid = true;
Log *log(ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_PROCESS));
@@ -3778,8 +3909,8 @@ GDBRemoteCommunicationClient::GetSupportedStructuredDataPlugins() {
StructuredData::ParseJSON(response.GetStringRef());
if (m_supported_async_json_packets_sp &&
!m_supported_async_json_packets_sp->GetAsArray()) {
- // We were returned something other than a JSON array. This
- // is invalid. Clear it out.
+ // We were returned something other than a JSON array. This is
+ // invalid. Clear it out.
if (log)
log->Printf("GDBRemoteCommunicationClient::%s(): "
"QSupportedAsyncJSONPackets returned invalid "
@@ -3837,8 +3968,7 @@ Status GDBRemoteCommunicationClient::ConfigureRemoteStructuredData(
return error;
}
- // Build command: Configure{type_name}: serialized config
- // data.
+ // Build command: Configure{type_name}: serialized config data.
StreamGDBRemote stream;
stream.PutCString("QConfigure");
stream.PutCString(type_name.AsCString());
diff --git a/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h b/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h
index ba67b82463987..cf1d249768d7a 100644
--- a/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h
+++ b/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h
@@ -121,6 +121,7 @@ public:
/// response was received.
//------------------------------------------------------------------
int SendEnvironmentPacket(char const *name_equal_value);
+ int SendEnvironment(const Environment &env);
int SendLaunchArchPacket(const char *arch);
@@ -265,7 +266,7 @@ public:
bool GetDefaultThreadId(lldb::tid_t &tid);
- bool GetOSVersion(uint32_t &major, uint32_t &minor, uint32_t &update);
+ llvm::VersionTuple GetOSVersion();
bool GetOSBuildString(std::string &s);
@@ -354,6 +355,8 @@ public:
bool GetQXferFeaturesReadSupported();
+ bool GetQXferMemoryMapReadSupported();
+
LazyBool SupportsAllocDeallocMemory() // const
{
// Uncomment this to have lldb pretend the debug server doesn't respond to
@@ -401,8 +404,7 @@ public:
// the process to exit
std::string
*command_output, // Pass nullptr if you don't want the command output
- uint32_t timeout_sec); // Timeout in seconds to wait for shell program to
- // finish
+ const Timeout<std::micro> &timeout);
bool CalculateMD5(const FileSpec &file_spec, uint64_t &high, uint64_t &low);
@@ -544,6 +546,7 @@ protected:
LazyBool m_supports_qXfer_libraries_read;
LazyBool m_supports_qXfer_libraries_svr4_read;
LazyBool m_supports_qXfer_features_read;
+ LazyBool m_supports_qXfer_memory_map_read;
LazyBool m_supports_augmented_libraries_svr4_read;
LazyBool m_supports_jThreadExtendedInfo;
LazyBool m_supports_jLoadedDynamicLibrariesInfos;
@@ -570,9 +573,7 @@ protected:
ArchSpec m_host_arch;
ArchSpec m_process_arch;
- uint32_t m_os_version_major;
- uint32_t m_os_version_minor;
- uint32_t m_os_version_update;
+ llvm::VersionTuple m_os_version;
std::string m_os_build;
std::string m_os_kernel;
std::string m_hostname;
@@ -587,6 +588,9 @@ protected:
bool m_supported_async_json_packets_is_valid;
lldb_private::StructuredData::ObjectSP m_supported_async_json_packets_sp;
+ std::vector<MemoryRegionInfo> m_qXfer_memory_map;
+ bool m_qXfer_memory_map_loaded;
+
bool GetCurrentProcessInfo(bool allow_lazy_pid = true);
bool GetGDBServerVersion();
@@ -609,6 +613,11 @@ protected:
llvm::MutableArrayRef<uint8_t> &buffer,
size_t offset);
+ Status LoadQXferMemoryMap();
+
+ Status GetQXferMemoryMapRegionInfo(lldb::addr_t addr,
+ MemoryRegionInfo &region);
+
private:
DISALLOW_COPY_AND_ASSIGN(GDBRemoteCommunicationClient);
};
diff --git a/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp b/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp
index 4be92b79fd1a9..4fc1fc7a1964e 100644
--- a/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp
+++ b/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp
@@ -19,8 +19,8 @@
// Project includes
#include "ProcessGDBRemoteLog.h"
-#include "Utility/StringExtractorGDBRemote.h"
#include "lldb/Utility/StreamString.h"
+#include "lldb/Utility/StringExtractorGDBRemote.h"
using namespace lldb;
using namespace lldb_private;
diff --git a/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.h b/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.h
index a35352480040b..880caacd64149 100644
--- a/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.h
+++ b/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.h
@@ -57,8 +57,8 @@ protected:
bool m_exit_now; // use in asynchronous handling to indicate process should
// exit.
- bool m_send_error_strings; // If the client enables this then
- // we will send error strings as well.
+ bool m_send_error_strings = false; // If the client enables this then
+ // we will send error strings as well.
PacketResult Handle_QErrorStringEnable(StringExtractorGDBRemote &packet);
diff --git a/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp b/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp
index 3cf6b8ac07b24..c5b478378faa4 100644
--- a/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp
+++ b/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp
@@ -28,7 +28,7 @@
#include "lldb/Host/FileSystem.h"
#include "lldb/Host/Host.h"
#include "lldb/Host/HostInfo.h"
-#include "lldb/Interpreter/Args.h"
+#include "lldb/Interpreter/OptionArgParser.h"
#include "lldb/Symbol/ObjectFile.h"
#include "lldb/Target/FileAction.h"
#include "lldb/Target/Platform.h"
@@ -36,13 +36,14 @@
#include "lldb/Utility/Endian.h"
#include "lldb/Utility/JSON.h"
#include "lldb/Utility/Log.h"
+#include "lldb/Utility/SafeMachO.h"
#include "lldb/Utility/StreamGDBRemote.h"
#include "lldb/Utility/StreamString.h"
#include "llvm/ADT/Triple.h"
// Project includes
#include "ProcessGDBRemoteLog.h"
-#include "Utility/StringExtractorGDBRemote.h"
+#include "lldb/Utility/StringExtractorGDBRemote.h"
#ifdef __ANDROID__
#include "lldb/Host/android/HostInfoAndroid.h"
@@ -218,12 +219,15 @@ GDBRemoteCommunicationServerCommon::Handle_qHostInfo(
if (sub != LLDB_INVALID_CPUTYPE)
response.Printf("cpusubtype:%u;", sub);
- if (cpu == ArchSpec::kCore_arm_any) {
+ if (cpu == llvm::MachO::CPU_TYPE_ARM
+ || cpu == llvm::MachO::CPU_TYPE_ARM64) {
// Indicate the OS type.
#if defined(TARGET_OS_TV) && TARGET_OS_TV == 1
response.PutCString("ostype:tvos;");
#elif defined(TARGET_OS_WATCH) && TARGET_OS_WATCH == 1
response.PutCString("ostype:watchos;");
+#elif defined(TARGET_OS_BRIDGE) && TARGET_OS_BRIDGE == 1
+ response.PutCString("ostype:bridgeos;");
#else
response.PutCString("ostype:ios;");
#endif
@@ -265,19 +269,10 @@ GDBRemoteCommunicationServerCommon::Handle_qHostInfo(
break;
}
- uint32_t major = UINT32_MAX;
- uint32_t minor = UINT32_MAX;
- uint32_t update = UINT32_MAX;
- if (HostInfo::GetOSVersion(major, minor, update)) {
- if (major != UINT32_MAX) {
- response.Printf("os_version:%u", major);
- if (minor != UINT32_MAX) {
- response.Printf(".%u", minor);
- if (update != UINT32_MAX)
- response.Printf(".%u", update);
- }
- response.PutChar(';');
- }
+ llvm::VersionTuple version = HostInfo::GetOSVersion();
+ if (!version.empty()) {
+ response.Format("os_version:{0}", version.getAsString());
+ response.PutChar(';');
}
std::string s;
@@ -295,9 +290,9 @@ GDBRemoteCommunicationServerCommon::Handle_qHostInfo(
#if defined(__APPLE__)
#if defined(__arm__) || defined(__arm64__) || defined(__aarch64__)
- // For iOS devices, we are connected through a USB Mux so we never pretend
- // to actually have a hostname as far as the remote lldb that is connecting
- // to this lldb-platform is concerned
+ // For iOS devices, we are connected through a USB Mux so we never pretend to
+ // actually have a hostname as far as the remote lldb that is connecting to
+ // this lldb-platform is concerned
response.PutCString("hostname:");
response.PutCStringAsRawHex8("127.0.0.1");
response.PutChar(';');
@@ -357,7 +352,8 @@ GDBRemoteCommunicationServerCommon::Handle_qfProcessInfo(
StringExtractor extractor(value);
std::string file;
extractor.GetHexByteString(file);
- match_info.GetProcessInfo().GetExecutableFile().SetFile(file, false);
+ match_info.GetProcessInfo().GetExecutableFile().SetFile(
+ file, false, FileSpec::Style::native);
} else if (key.equals("name_match")) {
NameMatch name_match = llvm::StringSwitch<NameMatch>(value)
.Case("equals", NameMatch::Equals)
@@ -401,7 +397,7 @@ GDBRemoteCommunicationServerCommon::Handle_qfProcessInfo(
match_info.GetProcessInfo().SetEffectiveGroupID(gid);
} else if (key.equals("all_users")) {
match_info.SetMatchAllUsers(
- Args::StringToBoolean(value, false, &success));
+ OptionArgParser::ToBoolean(value, false, &success));
} else if (key.equals("triple")) {
match_info.GetProcessInfo().GetArchitecture() =
HostInfo::GetAugmentedArchSpec(value);
@@ -415,8 +411,8 @@ GDBRemoteCommunicationServerCommon::Handle_qfProcessInfo(
}
if (Host::FindProcesses(match_info, m_proc_infos)) {
- // We found something, return the first item by calling the get
- // subsequent process info packet handler...
+ // We found something, return the first item by calling the get subsequent
+ // process info packet handler...
return Handle_qsProcessInfo(packet);
}
return SendErrorResponse(3);
@@ -731,14 +727,13 @@ GDBRemoteCommunicationServerCommon::Handle_qPlatform_shell(
if (packet.GetChar() == ',') {
// FIXME: add timeout to qPlatform_shell packet
// uint32_t timeout = packet.GetHexMaxU32(false, 32);
- uint32_t timeout = 10;
if (packet.GetChar() == ',')
packet.GetHexByteString(working_dir);
int status, signo;
std::string output;
- Status err =
- Host::RunShellCommand(path.c_str(), FileSpec{working_dir, true},
- &status, &signo, &output, timeout);
+ Status err = Host::RunShellCommand(
+ path.c_str(), FileSpec{working_dir, true}, &status, &signo, &output,
+ std::chrono::seconds(10));
StreamGDBRemote response;
if (err.Fail()) {
response.PutCString("F,");
@@ -945,8 +940,7 @@ GDBRemoteCommunicationServerCommon::Handle_QEnvironment(
packet.SetFilePos(::strlen("QEnvironment:"));
const uint32_t bytes_left = packet.GetBytesLeft();
if (bytes_left > 0) {
- m_process_launch_info.GetEnvironmentEntries().AppendArgument(
- llvm::StringRef::withNullAsEmpty(packet.Peek()));
+ m_process_launch_info.GetEnvironment().insert(packet.Peek());
return SendOKResponse();
}
return SendErrorResponse(12);
@@ -960,7 +954,7 @@ GDBRemoteCommunicationServerCommon::Handle_QEnvironmentHexEncoded(
if (bytes_left > 0) {
std::string str;
packet.GetHexByteString(str);
- m_process_launch_info.GetEnvironmentEntries().AppendArgument(str);
+ m_process_launch_info.GetEnvironment().insert(str);
return SendOKResponse();
}
return SendErrorResponse(12);
@@ -981,11 +975,11 @@ GDBRemoteCommunicationServerCommon::Handle_QLaunchArch(
GDBRemoteCommunication::PacketResult
GDBRemoteCommunicationServerCommon::Handle_A(StringExtractorGDBRemote &packet) {
- // The 'A' packet is the most over designed packet ever here with
- // redundant argument indexes, redundant argument lengths and needed hex
- // encoded argument string values. Really all that is needed is a comma
- // separated hex encoded argument value list, but we will stay true to the
- // documented version of the 'A' packet here...
+ // The 'A' packet is the most over designed packet ever here with redundant
+ // argument indexes, redundant argument lengths and needed hex encoded
+ // argument string values. Really all that is needed is a comma separated hex
+ // encoded argument value list, but we will stay true to the documented
+ // version of the 'A' packet here...
Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PROCESS));
int actual_arg_index = 0;
@@ -993,8 +987,8 @@ GDBRemoteCommunicationServerCommon::Handle_A(StringExtractorGDBRemote &packet) {
packet.SetFilePos(1); // Skip the 'A'
bool success = true;
while (success && packet.GetBytesLeft() > 0) {
- // Decode the decimal argument string length. This length is the
- // number of hex nibbles in the argument string value.
+ // Decode the decimal argument string length. This length is the number of
+ // hex nibbles in the argument string value.
const uint32_t arg_len = packet.GetU32(UINT32_MAX);
if (arg_len == UINT32_MAX)
success = false;
@@ -1003,8 +997,8 @@ GDBRemoteCommunicationServerCommon::Handle_A(StringExtractorGDBRemote &packet) {
if (packet.GetChar() != ',')
success = false;
else {
- // Decode the argument index. We ignore this really because
- // who would really send down the arguments in a random order???
+ // Decode the argument index. We ignore this really because who would
+ // really send down the arguments in a random order???
const uint32_t arg_idx = packet.GetU32(UINT32_MAX);
if (arg_idx == UINT32_MAX)
success = false;
@@ -1013,9 +1007,9 @@ GDBRemoteCommunicationServerCommon::Handle_A(StringExtractorGDBRemote &packet) {
if (packet.GetChar() != ',')
success = false;
else {
- // Decode the argument string value from hex bytes
- // back into a UTF8 string and make sure the length
- // matches the one supplied in the packet
+ // Decode the argument string value from hex bytes back into a UTF8
+ // string and make sure the length matches the one supplied in the
+ // packet
std::string arg;
if (packet.GetHexByteStringFixedLength(arg, arg_len) !=
(arg_len / 2))
@@ -1029,7 +1023,8 @@ GDBRemoteCommunicationServerCommon::Handle_A(StringExtractorGDBRemote &packet) {
if (success) {
if (arg_idx == 0)
- m_process_launch_info.GetExecutableFile().SetFile(arg, false);
+ m_process_launch_info.GetExecutableFile().SetFile(
+ arg, false, FileSpec::Style::native);
m_process_launch_info.GetArguments().AppendArgument(arg);
if (log)
log->Printf("LLGSPacketHandler::%s added arg %d: \"%s\"",
@@ -1254,8 +1249,8 @@ void GDBRemoteCommunicationServerCommon::
// Nothing.
break;
}
- // In case of MIPS64, pointer size is depend on ELF ABI
- // For N32 the pointer size is 4 and for N64 it is 8
+ // In case of MIPS64, pointer size is depend on ELF ABI For N32 the pointer
+ // size is 4 and for N64 it is 8
std::string abi = proc_arch.GetTargetABI();
if (!abi.empty())
response.Printf("elf_abi:%s;", abi.c_str());
diff --git a/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp b/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp
index 32741c2404e22..50392fa389562 100644
--- a/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp
+++ b/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp
@@ -33,9 +33,9 @@
#include "lldb/Host/common/NativeProcessProtocol.h"
#include "lldb/Host/common/NativeRegisterContext.h"
#include "lldb/Host/common/NativeThreadProtocol.h"
-#include "lldb/Interpreter/Args.h"
#include "lldb/Target/FileAction.h"
#include "lldb/Target/MemoryRegionInfo.h"
+#include "lldb/Utility/Args.h"
#include "lldb/Utility/DataBuffer.h"
#include "lldb/Utility/Endian.h"
#include "lldb/Utility/JSON.h"
@@ -49,7 +49,7 @@
// Project includes
#include "ProcessGDBRemote.h"
#include "ProcessGDBRemoteLog.h"
-#include "Utility/StringExtractorGDBRemote.h"
+#include "lldb/Utility/StringExtractorGDBRemote.h"
using namespace lldb;
using namespace lldb_private;
@@ -236,16 +236,15 @@ Status GDBRemoteCommunicationServerLLGS::LaunchProcess() {
m_debugged_process_up = std::move(*process_or);
}
- // Handle mirroring of inferior stdout/stderr over the gdb-remote protocol
- // as needed.
- // llgs local-process debugging may specify PTY paths, which will make these
- // file actions non-null
- // process launch -i/e/o will also make these file actions non-null
- // nullptr means that the traffic is expected to flow over gdb-remote protocol
+ // Handle mirroring of inferior stdout/stderr over the gdb-remote protocol as
+ // needed. llgs local-process debugging may specify PTY paths, which will
+ // make these file actions non-null process launch -i/e/o will also make
+ // these file actions non-null nullptr means that the traffic is expected to
+ // flow over gdb-remote protocol
if (should_forward_stdio) {
// nullptr means it's not redirected to file or pty (in case of LLGS local)
- // at least one of stdio will be transferred pty<->gdb-remote
- // we need to give the pty master handle to this object to read and/or write
+ // at least one of stdio will be transferred pty<->gdb-remote we need to
+ // give the pty master handle to this object to read and/or write
LLDB_LOG(log,
"pid = {0}: setting up stdout/stderr redirection via $O "
"gdb-remote commands",
@@ -291,7 +290,7 @@ Status GDBRemoteCommunicationServerLLGS::AttachToProcess(lldb::pid_t pid) {
// else.
if (m_debugged_process_up &&
m_debugged_process_up->GetID() != LLDB_INVALID_PROCESS_ID)
- return Status("cannot attach to a process %" PRIu64
+ return Status("cannot attach to process %" PRIu64
" when another process with pid %" PRIu64
" is being debugged.",
pid, m_debugged_process_up->GetID());
@@ -410,8 +409,8 @@ static JSONObject::SP GetRegistersAsJSON(NativeThreadProtocol &thread) {
JSONObject::SP register_object_sp = std::make_shared<JSONObject>();
#ifdef LLDB_JTHREADSINFO_FULL_REGISTER_SET
- // Expedite all registers in the first register set (i.e. should be GPRs) that
- // are not contained in other registers.
+ // Expedite all registers in the first register set (i.e. should be GPRs)
+ // that are not contained in other registers.
const RegisterSet *reg_set_p = reg_ctx_sp->GetRegisterSet(0);
if (!reg_set_p)
return nullptr;
@@ -420,8 +419,7 @@ static JSONObject::SP GetRegistersAsJSON(NativeThreadProtocol &thread) {
uint32_t reg_num = *reg_num_p;
#else
// Expedite only a couple of registers until we figure out why sending
- // registers is
- // expensive.
+ // registers is expensive.
static const uint32_t k_expedited_registers[] = {
LLDB_REGNUM_GENERIC_PC, LLDB_REGNUM_GENERIC_SP, LLDB_REGNUM_GENERIC_FP,
LLDB_REGNUM_GENERIC_RA, LLDB_INVALID_REGNUM};
@@ -595,8 +593,7 @@ GDBRemoteCommunicationServerLLGS::SendStopReplyPacketForThread(
return SendErrorResponse(52);
// FIXME implement register handling for exec'd inferiors.
- // if (tid_stop_info.reason == eStopReasonExec)
- // {
+ // if (tid_stop_info.reason == eStopReasonExec) {
// const bool force = true;
// InitializeRegisters(force);
// }
@@ -633,14 +630,14 @@ GDBRemoteCommunicationServerLLGS::SendStopReplyPacketForThread(
response.PutChar(';');
}
- // If a 'QListThreadsInStopReply' was sent to enable this feature, we
- // will send all thread IDs back in the "threads" key whose value is
- // a list of hex thread IDs separated by commas:
+ // If a 'QListThreadsInStopReply' was sent to enable this feature, we will
+ // send all thread IDs back in the "threads" key whose value is a list of hex
+ // thread IDs separated by commas:
// "threads:10a,10b,10c;"
- // This will save the debugger from having to send a pair of qfThreadInfo
- // and qsThreadInfo packets, but it also might take a lot of room in the
- // stop reply packet, so it must be enabled only on systems where there
- // are no limits on packet lengths.
+ // This will save the debugger from having to send a pair of qfThreadInfo and
+ // qsThreadInfo packets, but it also might take a lot of room in the stop
+ // reply packet, so it must be enabled only on systems where there are no
+ // limits on packet lengths.
if (m_list_threads_in_stop_reply) {
response.PutCString("threads:");
@@ -655,12 +652,11 @@ GDBRemoteCommunicationServerLLGS::SendStopReplyPacketForThread(
}
response.PutChar(';');
- // Include JSON info that describes the stop reason for any threads
- // that actually have stop reasons. We use the new "jstopinfo" key
- // whose values is hex ascii JSON that contains the thread IDs
- // thread stop info only for threads that have stop reasons. Only send
- // this if we have more than one thread otherwise this packet has all
- // the info it needs.
+ // Include JSON info that describes the stop reason for any threads that
+ // actually have stop reasons. We use the new "jstopinfo" key whose values
+ // is hex ascii JSON that contains the thread IDs thread stop info only for
+ // threads that have stop reasons. Only send this if we have more than one
+ // thread otherwise this packet has all the info it needs.
if (thread_index > 0) {
const bool threads_with_valid_stop_info_only = true;
JSONArray::SP threads_info_sp = GetJSONThreadsInfo(
@@ -806,8 +802,8 @@ void GDBRemoteCommunicationServerLLGS::HandleInferiorState_Exited(
__FUNCTION__, process->GetID());
}
- // Close the pipe to the inferior terminal i/o if we launched it
- // and set one up.
+ // Close the pipe to the inferior terminal i/o if we launched it and set one
+ // up.
MaybeCloseInferiorTerminalConnection();
// We are ready to exit the debug monitor.
@@ -823,8 +819,7 @@ void GDBRemoteCommunicationServerLLGS::HandleInferiorState_Stopped(
if (log)
log->Printf("GDBRemoteCommunicationServerLLGS::%s called", __FUNCTION__);
- // Send the stop reason unless this is the stop after the
- // launch or attach.
+ // Send the stop reason unless this is the stop after the launch or attach.
switch (m_inferior_prev_state) {
case eStateLaunching:
case eStateAttaching:
@@ -859,13 +854,11 @@ void GDBRemoteCommunicationServerLLGS::ProcessStateChanged(
break;
case StateType::eStateStopped:
- // Make sure we get all of the pending stdout/stderr from the inferior
- // and send it to the lldb host before we send the state change
- // notification
+ // Make sure we get all of the pending stdout/stderr from the inferior and
+ // send it to the lldb host before we send the state change notification
SendProcessOutput();
// Then stop the forwarding, so that any late output (see llvm.org/pr25652)
- // does not
- // interfere with our protocol.
+ // does not interfere with our protocol.
StopSTDIOForwarding();
HandleInferiorState_Stopped(process);
break;
@@ -1287,8 +1280,8 @@ GDBRemoteCommunicationServerLLGS::Handle_qC(StringExtractorGDBRemote &packet) {
(m_debugged_process_up->GetID() == LLDB_INVALID_PROCESS_ID))
return SendErrorResponse(68);
- // Make sure we set the current thread so g and p packets return
- // the data the gdb will expect.
+ // Make sure we set the current thread so g and p packets return the data the
+ // gdb will expect.
lldb::tid_t tid = m_debugged_process_up->GetCurrentThreadID();
SetCurrentThreadID(tid);
@@ -1397,10 +1390,9 @@ GDBRemoteCommunicationServerLLGS::Handle_C(StringExtractorGDBRemote &packet) {
Status error;
// We have two branches: what to do if a continue thread is specified (in
- // which case we target
- // sending the signal to that thread), or when we don't have a continue thread
- // set (in which
- // case we send a signal to the process).
+ // which case we target sending the signal to that thread), or when we don't
+ // have a continue thread set (in which case we send a signal to the
+ // process).
// TODO discuss with Greg Clayton, make sure this makes sense.
@@ -1639,8 +1631,8 @@ GDBRemoteCommunicationServerLLGS::SendStopReasonForState(
case eStateStopped:
case eStateCrashed: {
lldb::tid_t tid = m_debugged_process_up->GetCurrentThreadID();
- // Make sure we set the current thread so g and p packets return
- // the data the gdb will expect.
+ // Make sure we set the current thread so g and p packets return the data
+ // the gdb will expect.
SetCurrentThreadID(tid);
return SendStopReplyPacketForThread(tid);
}
@@ -2043,9 +2035,8 @@ GDBRemoteCommunicationServerLLGS::Handle_P(StringExtractorGDBRemote &packet) {
return SendErrorResponse(0x47);
}
- // The dwarf expression are evaluate on host site
- // which may cause register size to change
- // Hence the reg_size may not be same as reg_info->bytes_size
+ // The dwarf expression are evaluate on host site which may cause register
+ // size to change Hence the reg_size may not be same as reg_info->bytes_size
if ((reg_size != reg_info->byte_size) &&
!(reg_info->dynamic_size_dwarf_expr_bytes)) {
return SendIllFormedResponse(packet, "P packet register size is incorrect");
@@ -2376,10 +2367,9 @@ GDBRemoteCommunicationServerLLGS::Handle_qMemoryRegionInfoSupported(
Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PROCESS));
// Currently only the NativeProcessProtocol knows if it can handle a
- // qMemoryRegionInfoSupported
- // request, but we're not guaranteed to be attached to a process. For now
- // we'll assume the
- // client only asks this when a process is being debugged.
+ // qMemoryRegionInfoSupported request, but we're not guaranteed to be
+ // attached to a process. For now we'll assume the client only asks this
+ // when a process is being debugged.
// Ensure we have a process running; otherwise, we can't figure this out
// since we won't have a NativeProcessProtocol.
@@ -2670,8 +2660,7 @@ GDBRemoteCommunicationServerLLGS::Handle_s(StringExtractorGDBRemote &packet) {
}
// We first try to use a continue thread id. If any one or any all set, use
- // the current thread.
- // Bail out if we don't have a thread id.
+ // the current thread. Bail out if we don't have a thread id.
lldb::tid_t tid = GetContinueThreadID();
if (tid == 0 || tid == LLDB_INVALID_THREAD_ID)
tid = GetCurrentThreadID();
@@ -2935,7 +2924,7 @@ GDBRemoteCommunicationServerLLGS::Handle_vAttach(
log->Printf("GDBRemoteCommunicationServerLLGS::%s failed to attach to "
"pid %" PRIu64 ": %s\n",
__FUNCTION__, pid, error.AsCString());
- return SendErrorResponse(0x01);
+ return SendErrorResponse(error);
}
// Notify we attached by sending a stop packet.
@@ -3093,8 +3082,8 @@ GDBRemoteCommunicationServerLLGS::Handle_QPassSignals(
std::vector<int> signals;
packet.SetFilePos(strlen("QPassSignals:"));
- // Read sequence of hex signal numbers divided by a semicolon and
- // optionally spaces.
+ // Read sequence of hex signal numbers divided by a semicolon and optionally
+ // spaces.
while (packet.GetBytesLeft() > 0) {
int signal = packet.GetS32(-1, 16);
if (signal < 0)
@@ -3154,8 +3143,7 @@ NativeThreadProtocol *GDBRemoteCommunicationServerLLGS::GetThreadFromSuffix(
return nullptr;
// If the client hasn't asked for thread suffix support, there will not be a
- // thread suffix.
- // Use the current thread in that case.
+ // thread suffix. Use the current thread in that case.
if (!m_thread_suffix_supported) {
const lldb::tid_t current_tid = GetCurrentThreadID();
if (current_tid == LLDB_INVALID_THREAD_ID)
@@ -3201,9 +3189,9 @@ NativeThreadProtocol *GDBRemoteCommunicationServerLLGS::GetThreadFromSuffix(
lldb::tid_t GDBRemoteCommunicationServerLLGS::GetCurrentThreadID() const {
if (m_current_tid == 0 || m_current_tid == LLDB_INVALID_THREAD_ID) {
- // Use whatever the debug process says is the current thread id
- // since the protocol either didn't specify or specified we want
- // any/all threads marked as the current thread.
+ // Use whatever the debug process says is the current thread id since the
+ // protocol either didn't specify or specified we want any/all threads
+ // marked as the current thread.
if (!m_debugged_process_up)
return LLDB_INVALID_THREAD_ID;
return m_debugged_process_up->GetCurrentThreadID();
diff --git a/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp b/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp
index 04ed9d704e137..26e28a900320a 100644
--- a/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp
+++ b/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp
@@ -14,6 +14,7 @@
// C Includes
// C++ Includes
#include <chrono>
+#include <csignal>
#include <cstring>
#include <mutex>
#include <sstream>
@@ -38,7 +39,7 @@
#include "lldb/Utility/UriParser.h"
// Project includes
-#include "Utility/StringExtractorGDBRemote.h"
+#include "lldb/Utility/StringExtractorGDBRemote.h"
using namespace lldb;
using namespace lldb_private;
@@ -101,11 +102,11 @@ Status GDBRemoteCommunicationServerPlatform::LaunchGDBServer(
if (port == UINT16_MAX)
port = GetNextAvailablePort();
- // Spawn a new thread to accept the port that gets bound after
- // binding to port 0 (zero).
+ // Spawn a new thread to accept the port that gets bound after binding to
+ // port 0 (zero).
- // ignore the hostname send from the remote end, just use the ip address
- // that we're currently communicating with as the hostname
+ // ignore the hostname send from the remote end, just use the ip address that
+ // we're currently communicating with as the hostname
// Spawn a debugserver and try to get the port it listens to.
ProcessLaunchInfo debugserver_launch_info;
@@ -116,8 +117,8 @@ Status GDBRemoteCommunicationServerPlatform::LaunchGDBServer(
if (log)
log->Printf("Launching debugserver with: %s:%u...", hostname.c_str(), port);
- // Do not run in a new session so that it can not linger after the
- // platform closes.
+ // Do not run in a new session so that it can not linger after the platform
+ // closes.
debugserver_launch_info.SetLaunchInSeparateProcessGroup(false);
debugserver_launch_info.SetMonitorProcessCallback(
std::bind(&GDBRemoteCommunicationServerPlatform::DebugserverProcessReaped,
@@ -170,8 +171,8 @@ GDBRemoteCommunicationServerPlatform::Handle_qLaunchGDBServer(
#ifdef _WIN32
return SendErrorResponse(9);
#else
- // Spawn a local debugserver as a platform so we can then attach or launch
- // a process...
+ // Spawn a local debugserver as a platform so we can then attach or launch a
+ // process...
Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PLATFORM));
if (log)
@@ -259,8 +260,7 @@ GDBRemoteCommunicationServerPlatform::Handle_qKillSpawnedProcess(
lldb::pid_t pid = packet.GetU64(LLDB_INVALID_PROCESS_ID);
- // verify that we know anything about this pid.
- // Scope for locker
+ // verify that we know anything about this pid. Scope for locker
{
std::lock_guard<std::recursive_mutex> guard(m_spawned_pids_mutex);
if (m_spawned_pids.find(pid) == m_spawned_pids.end()) {
@@ -306,8 +306,8 @@ bool GDBRemoteCommunicationServerPlatform::KillSpawnedProcess(lldb::pid_t pid) {
return true;
}
- // the launched process still lives. Now try killing it again,
- // this time with an unblockable signal.
+ // the launched process still lives. Now try killing it again, this time
+ // with an unblockable signal.
Host::Kill(pid, SIGKILL);
for (size_t i = 0; i < 10; ++i) {
@@ -321,8 +321,7 @@ bool GDBRemoteCommunicationServerPlatform::KillSpawnedProcess(lldb::pid_t pid) {
usleep(10000);
}
- // check one more time after the final usleep
- // Scope for locker
+ // check one more time after the final usleep Scope for locker
{
std::lock_guard<std::recursive_mutex> guard(m_spawned_pids_mutex);
if (m_spawned_pids.find(pid) == m_spawned_pids.end())
@@ -389,14 +388,13 @@ GDBRemoteCommunicationServerPlatform::Handle_qC(
StreamString response;
response.Printf("QC%" PRIx64, pid);
- // If we launch a process and this GDB server is acting as a platform,
- // then we need to clear the process launch state so we can start
- // launching another process. In order to launch a process a bunch or
- // packets need to be sent: environment packets, working directory,
- // disable ASLR, and many more settings. When we launch a process we
- // then need to know when to clear this information. Currently we are
- // selecting the 'qC' packet as that packet which seems to make the most
- // sense.
+ // If we launch a process and this GDB server is acting as a platform, then
+ // we need to clear the process launch state so we can start launching
+ // another process. In order to launch a process a bunch or packets need to
+ // be sent: environment packets, working directory, disable ASLR, and many
+ // more settings. When we launch a process we then need to know when to clear
+ // this information. Currently we are selecting the 'qC' packet as that
+ // packet which seems to make the most sense.
if (pid != LLDB_INVALID_PROCESS_ID) {
m_process_launch_info.Clear();
}
@@ -445,9 +443,8 @@ Status GDBRemoteCommunicationServerPlatform::LaunchProcess() {
return Status("%s: no process command line specified to launch",
__FUNCTION__);
- // specify the process monitor if not already set. This should
- // generally be what happens since we need to reap started
- // processes.
+ // specify the process monitor if not already set. This should generally be
+ // what happens since we need to reap started processes.
if (!m_process_launch_info.GetMonitorProcessCallback())
m_process_launch_info.SetMonitorProcessCallback(
std::bind(
@@ -466,8 +463,8 @@ Status GDBRemoteCommunicationServerPlatform::LaunchProcess() {
m_process_launch_info.GetArguments().GetArgumentAtIndex(0),
m_process_launch_info.GetProcessID());
- // add to list of spawned processes. On an lldb-gdbserver, we
- // would expect there to be only one.
+ // add to list of spawned processes. On an lldb-gdbserver, we would expect
+ // there to be only one.
const auto pid = m_process_launch_info.GetProcessID();
if (pid != LLDB_INVALID_PROCESS_ID) {
// add to spawned pids
@@ -537,7 +534,7 @@ const FileSpec &GDBRemoteCommunicationServerPlatform::GetDomainSocketDir() {
if (domainsocket_dir_env != nullptr)
g_domainsocket_dir = FileSpec(domainsocket_dir_env, false);
else
- HostInfo::GetLLDBPath(ePathTypeLLDBTempSystemDir, g_domainsocket_dir);
+ g_domainsocket_dir = HostInfo::GetProcessTempDir();
});
return g_domainsocket_dir;
diff --git a/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp b/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp
index e418deee01f3d..07dab751f4b90 100644
--- a/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp
+++ b/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp
@@ -25,7 +25,7 @@
#include "ThreadGDBRemote.h"
#include "Utility/ARM_DWARF_Registers.h"
#include "Utility/ARM_ehframe_Registers.h"
-#include "Utility/StringExtractorGDBRemote.h"
+#include "lldb/Utility/StringExtractorGDBRemote.h"
using namespace lldb;
using namespace lldb_private;
@@ -39,9 +39,9 @@ GDBRemoteRegisterContext::GDBRemoteRegisterContext(
GDBRemoteDynamicRegisterInfo &reg_info, bool read_all_at_once)
: RegisterContext(thread, concrete_frame_idx), m_reg_info(reg_info),
m_reg_valid(), m_reg_data(), m_read_all_at_once(read_all_at_once) {
- // Resize our vector of bools to contain one bool for every register.
- // We will use these boolean values to know when a register value
- // is valid in m_reg_data.
+ // Resize our vector of bools to contain one bool for every register. We will
+ // use these boolean values to know when a register value is valid in
+ // m_reg_data.
m_reg_valid.resize(reg_info.GetNumRegisters());
// Make a heap based buffer that is big enough to store all registers
@@ -119,8 +119,8 @@ bool GDBRemoteRegisterContext::PrivateSetRegisterValue(
if (success) {
SetRegisterIsValid(reg, true);
} else if (data.size() > 0) {
- // Only set register is valid to false if we copied some bytes, else
- // leave it as it was.
+ // Only set register is valid to false if we copied some bytes, else leave
+ // it as it was.
SetRegisterIsValid(reg, false);
}
return success;
@@ -133,11 +133,9 @@ bool GDBRemoteRegisterContext::PrivateSetRegisterValue(uint32_t reg,
return false;
// Early in process startup, we can get a thread that has an invalid byte
- // order
- // because the process hasn't been completely set up yet (see the ctor where
- // the
- // byte order is setfrom the process). If that's the case, we can't set the
- // value here.
+ // order because the process hasn't been completely set up yet (see the ctor
+ // where the byte order is setfrom the process). If that's the case, we
+ // can't set the value here.
if (m_reg_data.GetByteOrder() == eByteOrderInvalid) {
return false;
}
@@ -149,8 +147,7 @@ bool GDBRemoteRegisterContext::PrivateSetRegisterValue(uint32_t reg,
DataExtractor data(buffer_sp, endian::InlHostByteOrder(), sizeof(void *));
// If our register context and our register info disagree, which should never
- // happen, don't
- // overwrite past the end of the buffer.
+ // happen, don't overwrite past the end of the buffer.
if (m_reg_data.GetByteSize() < reg_info->byte_offset + reg_info->byte_size)
return false;
@@ -219,8 +216,7 @@ bool GDBRemoteRegisterContext::ReadRegisterBytes(const RegisterInfo *reg_info,
}
if (reg_info->value_regs) {
// Process this composite register request by delegating to the
- // constituent
- // primordial registers.
+ // constituent primordial registers.
// Index of the primordial register.
bool success = true;
@@ -228,8 +224,8 @@ bool GDBRemoteRegisterContext::ReadRegisterBytes(const RegisterInfo *reg_info,
const uint32_t prim_reg = reg_info->value_regs[idx];
if (prim_reg == LLDB_INVALID_REGNUM)
break;
- // We have a valid primordial register as our constituent.
- // Grab the corresponding register info.
+ // We have a valid primordial register as our constituent. Grab the
+ // corresponding register info.
const RegisterInfo *prim_reg_info = GetRegisterInfoAtIndex(prim_reg);
if (prim_reg_info == NULL)
success = false;
@@ -242,8 +238,7 @@ bool GDBRemoteRegisterContext::ReadRegisterBytes(const RegisterInfo *reg_info,
if (success) {
// If we reach this point, all primordial register requests have
- // succeeded.
- // Validate this composite register.
+ // succeeded. Validate this composite register.
SetRegisterIsValid(reg_info, true);
}
} else {
@@ -262,16 +257,14 @@ bool GDBRemoteRegisterContext::ReadRegisterBytes(const RegisterInfo *reg_info,
reg_info->byte_offset + reg_info->byte_size);
#endif
// If our register context and our register info disagree, which should
- // never happen, don't
- // read past the end of the buffer.
+ // never happen, don't read past the end of the buffer.
if (m_reg_data.GetByteSize() < reg_info->byte_offset + reg_info->byte_size)
return false;
- // If we aren't extracting into our own buffer (which
- // only happens when this function is called from
- // ReadRegisterValue(uint32_t, Scalar&)) then
- // we transfer bytes from our buffer into the data
- // buffer that was passed in
+ // If we aren't extracting into our own buffer (which only happens when
+ // this function is called from ReadRegisterValue(uint32_t, Scalar&)) then
+ // we transfer bytes from our buffer into the data buffer that was passed
+ // in
data.SetByteOrder(m_reg_data.GetByteOrder());
data.SetData(m_reg_data, reg_info->byte_offset, reg_info->byte_size);
@@ -321,8 +314,7 @@ bool GDBRemoteRegisterContext::WriteRegisterBytes(const RegisterInfo *reg_info,
#endif
// If our register context and our register info disagree, which should never
- // happen, don't
- // overwrite past the end of the buffer.
+ // happen, don't overwrite past the end of the buffer.
if (m_reg_data.GetByteSize() < reg_info->byte_offset + reg_info->byte_size)
return false;
@@ -358,12 +350,10 @@ bool GDBRemoteRegisterContext::WriteRegisterBytes(const RegisterInfo *reg_info,
bool success = true;
if (reg_info->value_regs) {
- // This register is part of another register. In this case we read the
- // actual
- // register data for any "value_regs", and once all that data is read,
- // we will
- // have enough data in our register context bytes for the value of
- // this register
+ // This register is part of another register. In this case we read
+ // the actual register data for any "value_regs", and once all that
+ // data is read, we will have enough data in our register context
+ // bytes for the value of this register
// Invalidate this composite register first.
@@ -371,8 +361,8 @@ bool GDBRemoteRegisterContext::WriteRegisterBytes(const RegisterInfo *reg_info,
const uint32_t reg = reg_info->value_regs[idx];
if (reg == LLDB_INVALID_REGNUM)
break;
- // We have a valid primordial register as our constituent.
- // Grab the corresponding register info.
+ // We have a valid primordial register as our constituent. Grab the
+ // corresponding register info.
const RegisterInfo *value_reg_info = GetRegisterInfoAtIndex(reg);
if (value_reg_info == NULL)
success = false;
@@ -385,8 +375,7 @@ bool GDBRemoteRegisterContext::WriteRegisterBytes(const RegisterInfo *reg_info,
}
// Check if writing this register will invalidate any other register
- // values?
- // If so, invalidate them
+ // values? If so, invalidate them
if (reg_info->invalidate_regs) {
for (uint32_t idx = 0, reg = reg_info->invalidate_regs[0];
reg != LLDB_INVALID_REGNUM;
@@ -548,26 +537,22 @@ bool GDBRemoteRegisterContext::WriteAllRegisterValues(
return true;
uint32_t num_restored = 0;
- // We need to manually go through all of the registers and
- // restore them manually
+ // We need to manually go through all of the registers and restore them
+ // manually
DataExtractor restore_data(data_sp, m_reg_data.GetByteOrder(),
m_reg_data.GetAddressByteSize());
const RegisterInfo *reg_info;
- // The g packet contents may either include the slice registers (registers
- // defined in
- // terms of other registers, e.g. eax is a subset of rax) or not. The
- // slice registers
- // should NOT be in the g packet, but some implementations may incorrectly
- // include them.
+ // The g packet contents may either include the slice registers
+ // (registers defined in terms of other registers, e.g. eax is a subset
+ // of rax) or not. The slice registers should NOT be in the g packet,
+ // but some implementations may incorrectly include them.
//
// If the slice registers are included in the packet, we must step over
- // the slice registers
- // when parsing the packet -- relying on the RegisterInfo byte_offset
- // field would be incorrect.
- // If the slice registers are not included, then using the byte_offset
- // values into the
+ // the slice registers when parsing the packet -- relying on the
+ // RegisterInfo byte_offset field would be incorrect. If the slice
+ // registers are not included, then using the byte_offset values into the
// data buffer is the best way to find individual register values.
uint64_t size_including_slice_registers = 0;
@@ -591,21 +576,17 @@ bool GDBRemoteRegisterContext::WriteAllRegisterValues(
} else if (size_not_including_slice_registers ==
restore_data.GetByteSize()) {
// The size of the packet is the same as concatenating all of the
- // registers sequentially,
- // skipping the slice registers
+ // registers sequentially, skipping the slice registers
use_byte_offset_into_buffer = true;
} else if (size_including_slice_registers == restore_data.GetByteSize()) {
// The slice registers are present in the packet (when they shouldn't
- // be).
- // Don't try to use the RegisterInfo byte_offset into the restore_data,
- // it will
- // point to the wrong place.
+ // be). Don't try to use the RegisterInfo byte_offset into the
+ // restore_data, it will point to the wrong place.
use_byte_offset_into_buffer = false;
} else {
// None of our expected sizes match the actual g packet data we're
- // looking at.
- // The most conservative approach here is to use the running total byte
- // offset.
+ // looking at. The most conservative approach here is to use the
+ // running total byte offset.
use_byte_offset_into_buffer = false;
}
@@ -664,11 +645,9 @@ bool GDBRemoteRegisterContext::WriteAllRegisterValues(
if (reg_info->value_regs) // skip registers that are slices of real
// registers
continue;
- // Skip the fpsr and fpcr floating point status/control register writing
- // to
- // work around a bug in an older version of debugserver that would lead
- // to
- // register context corruption when writing fpsr/fpcr.
+ // Skip the fpsr and fpcr floating point status/control register
+ // writing to work around a bug in an older version of debugserver that
+ // would lead to register context corruption when writing fpsr/fpcr.
if (arm64_debugserver && (strcmp(reg_info->name, "fpsr") == 0 ||
strcmp(reg_info->name, "fpcr") == 0)) {
continue;
@@ -752,8 +731,8 @@ void GDBRemoteDynamicRegisterInfo::HardcodeARMRegisters(bool from_scratch) {
static uint32_t g_q14_regs[] = {71, 72, LLDB_INVALID_REGNUM}; // (d28, d29)
static uint32_t g_q15_regs[] = {73, 74, LLDB_INVALID_REGNUM}; // (d30, d31)
- // This is our array of composite registers, with each element coming from the
- // above register mappings.
+ // This is our array of composite registers, with each element coming from
+ // the above register mappings.
static uint32_t *g_composites[] = {
g_d0_regs, g_d1_regs, g_d2_regs, g_d3_regs, g_d4_regs, g_d5_regs,
g_d6_regs, g_d7_regs, g_d8_regs, g_d9_regs, g_d10_regs, g_d11_regs,
@@ -884,21 +863,17 @@ void GDBRemoteDynamicRegisterInfo::HardcodeARMRegisters(bool from_scratch) {
if (from_scratch) {
// Calculate the offsets of the registers
// Note that the layout of the "composite" registers (d0-d15 and q0-q15)
- // which comes after the
- // "primordial" registers is important. This enables us to calculate the
- // offset of the composite
- // register by using the offset of its first primordial register. For
- // example, to calculate the
- // offset of q0, use s0's offset.
+ // which comes after the "primordial" registers is important. This enables
+ // us to calculate the offset of the composite register by using the offset
+ // of its first primordial register. For example, to calculate the offset
+ // of q0, use s0's offset.
if (g_register_infos[2].byte_offset == 0) {
uint32_t byte_offset = 0;
for (i = 0; i < num_registers; ++i) {
// For primordial registers, increment the byte_offset by the byte_size
- // to arrive at the
- // byte_offset for the next register. Otherwise, we have a composite
- // register whose
- // offset can be calculated by consulting the offset of its first
- // primordial register.
+ // to arrive at the byte_offset for the next register. Otherwise, we
+ // have a composite register whose offset can be calculated by
+ // consulting the offset of its first primordial register.
if (!g_register_infos[i].value_regs) {
g_register_infos[i].byte_offset = byte_offset;
byte_offset += g_register_infos[i].byte_size;
@@ -933,8 +908,8 @@ void GDBRemoteDynamicRegisterInfo::HardcodeARMRegisters(bool from_scratch) {
RegisterInfo *g_comp_register_infos = g_register_infos + num_common_regs;
// First we need to validate that all registers that we already have match
- // the non composite regs.
- // If so, then we can add the registers, else we need to bail
+ // the non composite regs. If so, then we can add the registers, else we
+ // need to bail
bool match = true;
if (num_dynamic_regs == num_common_regs) {
for (i = 0; match && i < num_dynamic_regs; ++i) {
@@ -970,9 +945,8 @@ void GDBRemoteDynamicRegisterInfo::HardcodeARMRegisters(bool from_scratch) {
// Find a matching primordial register info entry.
if (reg_info && reg_info->name &&
::strcasecmp(reg_info->name, reg_name) == 0) {
- // The name matches the existing primordial entry.
- // Find and assign the offset, and then add this composite
- // register entry.
+ // The name matches the existing primordial entry. Find and
+ // assign the offset, and then add this composite register entry.
g_comp_register_infos[i].byte_offset = reg_info->byte_offset;
name.SetCString(g_comp_register_infos[i].name);
AddRegister(g_comp_register_infos[i], name, alt_name,
diff --git a/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp b/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
index 35d02c15ab85b..b3d33b19bd666 100644
--- a/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
+++ b/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
@@ -24,6 +24,7 @@
// C++ Includes
#include <algorithm>
+#include <csignal>
#include <map>
#include <mutex>
#include <sstream>
@@ -46,11 +47,11 @@
#include "lldb/Host/Symbols.h"
#include "lldb/Host/ThreadLauncher.h"
#include "lldb/Host/XML.h"
-#include "lldb/Interpreter/Args.h"
#include "lldb/Interpreter/CommandInterpreter.h"
#include "lldb/Interpreter/CommandObject.h"
#include "lldb/Interpreter/CommandObjectMultiword.h"
#include "lldb/Interpreter/CommandReturnObject.h"
+#include "lldb/Interpreter/OptionArgParser.h"
#include "lldb/Interpreter/OptionGroupBoolean.h"
#include "lldb/Interpreter/OptionGroupUInt64.h"
#include "lldb/Interpreter/OptionValueProperties.h"
@@ -59,10 +60,12 @@
#include "lldb/Symbol/ObjectFile.h"
#include "lldb/Target/ABI.h"
#include "lldb/Target/DynamicLoader.h"
+#include "lldb/Target/MemoryRegionInfo.h"
#include "lldb/Target/SystemRuntime.h"
#include "lldb/Target/Target.h"
#include "lldb/Target/TargetList.h"
#include "lldb/Target/ThreadPlanCallFunction.h"
+#include "lldb/Utility/Args.h"
#include "lldb/Utility/CleanUp.h"
#include "lldb/Utility/FileSpec.h"
#include "lldb/Utility/StreamString.h"
@@ -77,8 +80,8 @@
#include "ProcessGDBRemote.h"
#include "ProcessGDBRemoteLog.h"
#include "ThreadGDBRemote.h"
-#include "Utility/StringExtractorGDBRemote.h"
#include "lldb/Host/Host.h"
+#include "lldb/Utility/StringExtractorGDBRemote.h"
#include "llvm/ADT/StringSwitch.h"
#include "llvm/Support/Threading.h"
@@ -91,11 +94,11 @@ using namespace lldb_private::process_gdb_remote;
namespace lldb {
// Provide a function that can easily dump the packet history if we know a
-// ProcessGDBRemote * value (which we can get from logs or from debugging).
-// We need the function in the lldb namespace so it makes it into the final
+// ProcessGDBRemote * value (which we can get from logs or from debugging). We
+// need the function in the lldb namespace so it makes it into the final
// executable since the LLDB shared library only exports stuff in the lldb
-// namespace. This allows you to attach with a debugger and call this
-// function and get the packet history dumped to a file.
+// namespace. This allows you to attach with a debugger and call this function
+// and get the packet history dumped to a file.
void DumpProcessGDBRemotePacketHistory(void *p, const char *path) {
StreamFile strm;
Status error(strm.GetFile().Open(path, File::eOpenOptionWrite |
@@ -158,8 +161,8 @@ static const ProcessKDPPropertiesSP &GetGlobalPluginProperties() {
} // anonymous namespace end
// TODO Randomly assigning a port is unsafe. We should get an unused
-// ephemeral port from the kernel and make sure we reserve it before passing
-// it to debugserver.
+// ephemeral port from the kernel and make sure we reserve it before passing it
+// to debugserver.
#if defined(__APPLE__)
#define LOW_PORT (IPPORT_RESERVED)
@@ -233,8 +236,8 @@ bool ProcessGDBRemote::CanDebug(lldb::TargetSP target_sp,
}
return exe_module->GetFileSpec().Exists();
}
- // However, if there is no executable module, we return true since we might be
- // preparing to attach.
+ // However, if there is no executable module, we return true since we might
+ // be preparing to attach.
return true;
}
@@ -256,7 +259,8 @@ ProcessGDBRemote::ProcessGDBRemote(lldb::TargetSP target_sp,
m_addr_to_mmap_size(), m_thread_create_bp_sp(),
m_waiting_for_attach(false), m_destroy_tried_resuming(false),
m_command_sp(), m_breakpoint_pc_offset(0),
- m_initial_tid(LLDB_INVALID_THREAD_ID) {
+ m_initial_tid(LLDB_INVALID_THREAD_ID), m_allow_flash_writes(false),
+ m_erased_flash_ranges() {
m_async_broadcaster.SetEventName(eBroadcastBitAsyncThreadShouldExit,
"async thread should exit");
m_async_broadcaster.SetEventName(eBroadcastBitAsyncContinue,
@@ -299,17 +303,16 @@ ProcessGDBRemote::ProcessGDBRemote(lldb::TargetSP target_sp,
ProcessGDBRemote::~ProcessGDBRemote() {
// m_mach_process.UnregisterNotificationCallbacks (this);
Clear();
- // We need to call finalize on the process before destroying ourselves
- // to make sure all of the broadcaster cleanup goes as planned. If we
- // destruct this class, then Process::~Process() might have problems
- // trying to fully destroy the broadcaster.
+ // We need to call finalize on the process before destroying ourselves to
+ // make sure all of the broadcaster cleanup goes as planned. If we destruct
+ // this class, then Process::~Process() might have problems trying to fully
+ // destroy the broadcaster.
Finalize();
- // The general Finalize is going to try to destroy the process and that SHOULD
- // shut down the async thread. However, if we don't kill it it will get
- // stranded and
- // its connection will go away so when it wakes up it will crash. So kill it
- // for sure here.
+ // The general Finalize is going to try to destroy the process and that
+ // SHOULD shut down the async thread. However, if we don't kill it it will
+ // get stranded and its connection will go away so when it wakes up it will
+ // crash. So kill it for sure here.
StopAsyncThread();
KillDebugserverProcess();
}
@@ -368,8 +371,7 @@ bool ProcessGDBRemote::ParsePythonTargetDefinition(
}
// If the remote stub didn't give us eh_frame or DWARF register numbers for a
-// register,
-// see if the ABI can provide them.
+// register, see if the ABI can provide them.
// DWARF and eh_frame register numbers are defined as a part of the ABI.
static void AugmentRegisterInfoViaABI(RegisterInfo &reg_info,
ConstString reg_name, ABISP abi_sp) {
@@ -422,9 +424,9 @@ void ProcessGDBRemote::BuildDynamicRegisterInfo(bool force) {
m_register_info.Clear();
- // Check if qHostInfo specified a specific packet timeout for this connection.
- // If so then lets update our setting so the user knows what the timeout is
- // and can see it.
+ // Check if qHostInfo specified a specific packet timeout for this
+ // connection. If so then lets update our setting so the user knows what the
+ // timeout is and can see it.
const auto host_packet_timeout = m_gdb_comm.GetHostDefaultPacketTimeout();
if (host_packet_timeout > std::chrono::seconds(0)) {
GetGlobalPluginProperties()->SetPacketTimeout(host_packet_timeout.count());
@@ -531,7 +533,7 @@ void ProcessGDBRemote::BuildDynamicRegisterInfo(bool force) {
reg_info.encoding = encoding;
} else if (name.equals("format")) {
Format format = eFormatInvalid;
- if (Args::StringToFormat(value.str().c_str(), format, NULL)
+ if (OptionArgParser::ToFormat(value.str().c_str(), format, NULL)
.Success())
reg_info.format = format;
else {
@@ -596,10 +598,8 @@ void ProcessGDBRemote::BuildDynamicRegisterInfo(bool force) {
}
// We have to make a temporary ABI here, and not use the GetABI because
- // this code
- // gets called in DidAttach, when the target architecture (and
- // consequently the ABI we'll get from
- // the process) may be wrong.
+ // this code gets called in DidAttach, when the target architecture
+ // (and consequently the ABI we'll get from the process) may be wrong.
ABISP abi_to_use = ABI::FindPlugin(shared_from_this(), arch_to_use);
AugmentRegisterInfoViaABI(reg_info, reg_name, abi_to_use);
@@ -620,9 +620,9 @@ void ProcessGDBRemote::BuildDynamicRegisterInfo(bool force) {
// We didn't get anything if the accumulated reg_num is zero. See if we are
// debugging ARM and fill with a hard coded register set until we can get an
- // updated debugserver down on the devices.
- // On the other hand, if the accumulated reg_num is positive, see if we can
- // add composite registers to the existing primordial ones.
+ // updated debugserver down on the devices. On the other hand, if the
+ // accumulated reg_num is positive, see if we can add composite registers to
+ // the existing primordial ones.
bool from_scratch = (m_register_info.GetNumRegisters() == 0);
if (!target_arch.IsValid()) {
@@ -669,9 +669,8 @@ Status ProcessGDBRemote::DoConnectRemote(Stream *strm,
lldb::pid_t pid = m_gdb_comm.GetCurrentProcessID();
if (pid == LLDB_INVALID_PROCESS_ID) {
- // We don't have a valid process ID, so note that we are connected
- // and could now request to launch or attach, or get remote process
- // listings...
+ // We don't have a valid process ID, so note that we are connected and
+ // could now request to launch or attach, or get remote process listings...
SetPrivateState(eStateConnected);
} else {
// We have a valid process
@@ -721,7 +720,8 @@ Status ProcessGDBRemote::DoConnectRemote(Stream *strm,
if (error.Success() && !GetTarget().GetArchitecture().IsValid() &&
m_gdb_comm.GetHostArchitecture().IsValid()) {
- // Prefer the *process'* architecture over that of the *host*, if available.
+ // Prefer the *process'* architecture over that of the *host*, if
+ // available.
if (m_gdb_comm.GetProcessArchitecture().IsValid())
GetTarget().SetArchitecture(m_gdb_comm.GetProcessArchitecture());
else
@@ -800,8 +800,8 @@ Status ProcessGDBRemote::DoLaunch(Module *exe_module,
const bool disable_stdio = (launch_flags & eLaunchFlagDisableSTDIO) != 0;
if (stdin_file_spec || disable_stdio) {
- // the inferior will be reading stdin from the specified file
- // or stdio is completely disabled
+ // the inferior will be reading stdin from the specified file or stdio is
+ // completely disabled
m_stdin_forward = false;
} else {
m_stdin_forward = true;
@@ -824,11 +824,14 @@ Status ProcessGDBRemote::DoLaunch(Module *exe_module,
if (disable_stdio) {
// set to /dev/null unless redirected to a file above
if (!stdin_file_spec)
- stdin_file_spec.SetFile(FileSystem::DEV_NULL, false);
+ stdin_file_spec.SetFile(FileSystem::DEV_NULL, false,
+ FileSpec::Style::native);
if (!stdout_file_spec)
- stdout_file_spec.SetFile(FileSystem::DEV_NULL, false);
+ stdout_file_spec.SetFile(FileSystem::DEV_NULL, false,
+ FileSpec::Style::native);
if (!stderr_file_spec)
- stderr_file_spec.SetFile(FileSystem::DEV_NULL, false);
+ stderr_file_spec.SetFile(FileSystem::DEV_NULL, false,
+ FileSpec::Style::native);
} else if (platform_sp && platform_sp->IsHost()) {
// If the debugserver is local and we aren't disabling STDIO, lets use
// a pseudo terminal to instead of relying on the 'O' packets for stdio
@@ -888,16 +891,7 @@ Status ProcessGDBRemote::DoLaunch(Module *exe_module,
}
// Send the environment and the program + arguments after we connect
- const Args &environment = launch_info.GetEnvironmentEntries();
- if (environment.GetArgumentCount()) {
- size_t num_environment_entries = environment.GetArgumentCount();
- for (size_t i = 0; i < num_environment_entries; ++i) {
- const char *env_entry = environment.GetArgumentAtIndex(i);
- if (env_entry == NULL ||
- m_gdb_comm.SendEnvironmentPacket(env_entry) != 0)
- break;
- }
- }
+ m_gdb_comm.SendEnvironment(launch_info.GetEnvironment());
{
// Scope for the scoped timeout object
@@ -1004,16 +998,15 @@ Status ProcessGDBRemote::ConnectToDebugserver(llvm::StringRef connect_url) {
return error;
}
- // Start the communications read thread so all incoming data can be
- // parsed into packets and queued as they arrive.
+ // Start the communications read thread so all incoming data can be parsed
+ // into packets and queued as they arrive.
if (GetTarget().GetNonStopModeEnabled())
m_gdb_comm.StartReadThread();
- // We always seem to be able to open a connection to a local port
- // so we need to make sure we can then send data to it. If we can't
- // then we aren't actually connected to anything, so try and do the
- // handshake with the remote GDB server and make sure that goes
- // alright.
+ // We always seem to be able to open a connection to a local port so we need
+ // to make sure we can then send data to it. If we can't then we aren't
+ // actually connected to anything, so try and do the handshake with the
+ // remote GDB server and make sure that goes alright.
if (!m_gdb_comm.HandshakeWithServer(&error)) {
m_gdb_comm.Disconnect();
if (error.Success())
@@ -1055,9 +1048,9 @@ void ProcessGDBRemote::DidLaunchOrAttach(ArchSpec &process_arch) {
// See if the GDB server supports the qHostInfo information
- // See if the GDB server supports the qProcessInfo packet, if so
- // prefer that over the Host information as it will be more specific
- // to our process.
+ // See if the GDB server supports the qProcessInfo packet, if so prefer
+ // that over the Host information as it will be more specific to our
+ // process.
const ArchSpec &remote_process_arch = m_gdb_comm.GetProcessArchitecture();
if (remote_process_arch.IsValid()) {
@@ -1102,9 +1095,8 @@ void ProcessGDBRemote::DidLaunchOrAttach(ArchSpec &process_arch) {
// architectures.
// You can have an armv6 executable, and if the host is armv7, then the
// system will load the best possible architecture for all shared
- // libraries
- // it has, so we really need to take the remote host architecture as our
- // defacto architecture in this case.
+ // libraries it has, so we really need to take the remote host
+ // architecture as our defacto architecture in this case.
if ((process_arch.GetMachine() == llvm::Triple::arm ||
process_arch.GetMachine() == llvm::Triple::thumb) &&
@@ -1150,14 +1142,14 @@ void ProcessGDBRemote::DidLaunchOrAttach(ArchSpec &process_arch) {
? target_arch.GetTriple().getTriple().c_str()
: "<null>");
} else {
- // The target doesn't have a valid architecture yet, set it from
- // the architecture we got from the remote GDB server
+ // The target doesn't have a valid architecture yet, set it from the
+ // architecture we got from the remote GDB server
GetTarget().SetArchitecture(process_arch);
}
}
- // Find out which StructuredDataPlugins are supported by the
- // debug monitor. These plugins transmit data over async $J packets.
+ // Find out which StructuredDataPlugins are supported by the debug monitor.
+ // These plugins transmit data over async $J packets.
auto supported_packets_array =
m_gdb_comm.GetSupportedStructuredDataPlugins();
if (supported_packets_array)
@@ -1365,9 +1357,9 @@ Status ProcessGDBRemote::DoResume() {
continue_packet_error = true;
if (continue_packet_error) {
- // Either no vCont support, or we tried to use part of the vCont
- // packet that wasn't supported by the remote GDB server.
- // We need to try and make a simple packet that can do our continue
+ // Either no vCont support, or we tried to use part of the vCont packet
+ // that wasn't supported by the remote GDB server. We need to try and
+ // make a simple packet that can do our continue
const size_t num_continue_c_tids = m_continue_c_tids.size();
const size_t num_continue_C_tids = m_continue_C_tids.size();
const size_t num_continue_s_tids = m_continue_s_tids.size();
@@ -1394,11 +1386,10 @@ Status ProcessGDBRemote::DoResume() {
const int continue_signo = m_continue_C_tids.front().second;
// Only one thread is continuing
if (num_continue_C_tids > 1) {
- // More that one thread with a signal, yet we don't have
- // vCont support and we are being asked to resume each
- // thread with a signal, we need to make sure they are
- // all the same signal, or we can't issue the continue
- // accurately with the current support...
+ // More that one thread with a signal, yet we don't have vCont
+ // support and we are being asked to resume each thread with a
+ // signal, we need to make sure they are all the same signal, or we
+ // can't issue the continue accurately with the current support...
if (num_continue_C_tids > 1) {
continue_packet_error = false;
for (size_t i = 1; i < m_continue_C_tids.size(); ++i) {
@@ -1532,7 +1523,6 @@ void ProcessGDBRemote::ClearThreadIDList() {
size_t
ProcessGDBRemote::UpdateThreadIDsFromStopReplyThreadsValue(std::string &value) {
m_thread_ids.clear();
- m_thread_pcs.clear();
size_t comma_pos;
lldb::tid_t tid;
while ((comma_pos = value.find(',')) != std::string::npos) {
@@ -1675,9 +1665,8 @@ bool ProcessGDBRemote::UpdateThreadList(ThreadList &old_thread_list,
}
}
- // Whatever that is left in old_thread_list_copy are not
- // present in new_thread_list. Remove non-existent threads from internal id
- // table.
+ // Whatever that is left in old_thread_list_copy are not present in
+ // new_thread_list. Remove non-existent threads from internal id table.
size_t old_num_thread_ids = old_thread_list_copy.GetSize(false);
for (size_t i = 0; i < old_num_thread_ids; i++) {
ThreadSP old_thread_sp(old_thread_list_copy.GetThreadAtIndex(i, false));
@@ -1738,12 +1727,11 @@ bool ProcessGDBRemote::CalculateThreadStopInfo(ThreadGDBRemote *thread) {
return true;
// See if we got thread stop info for any threads valid stop info reasons
- // threads
- // via the "jstopinfo" packet stop reply packet key/value pair?
+ // threads via the "jstopinfo" packet stop reply packet key/value pair?
if (m_jstopinfo_sp) {
// If we have "jstopinfo" then we have stop descriptions for all threads
- // that have stop reasons, and if there is no entry for a thread, then
- // it has no stop reason.
+ // that have stop reasons, and if there is no entry for a thread, then it
+ // has no stop reason.
thread->GetRegisterContext()->InvalidateIfNeeded(true);
if (!GetThreadStopInfoFromJSON(thread, m_jstopinfo_sp)) {
thread->SetStopInfo(StopInfoSP());
@@ -1771,9 +1759,8 @@ ThreadSP ProcessGDBRemote::SetThreadStopInfo(
if (tid != LLDB_INVALID_THREAD_ID) {
// Scope for "locker" below
{
- // m_thread_list_real does have its own mutex, but we need to
- // hold onto the mutex between the call to
- // m_thread_list_real.FindThreadByID(...)
+ // m_thread_list_real does have its own mutex, but we need to hold onto
+ // the mutex between the call to m_thread_list_real.FindThreadByID(...)
// and the m_thread_list_real.AddThread(...) so it doesn't change on us
std::lock_guard<std::recursive_mutex> guard(
m_thread_list_real.GetMutex());
@@ -1827,10 +1814,9 @@ ThreadSP ProcessGDBRemote::SetThreadStopInfo(
if (!thread_sp->StopInfoIsUpToDate()) {
thread_sp->SetStopInfo(StopInfoSP());
// If there's a memory thread backed by this thread, we need to use it
- // to calcualte StopInfo.
- ThreadSP memory_thread_sp =
- m_thread_list.FindThreadByProtocolID(thread_sp->GetProtocolID());
- if (memory_thread_sp)
+ // to calculate StopInfo.
+ if (ThreadSP memory_thread_sp =
+ m_thread_list.GetBackingThread(thread_sp))
thread_sp = memory_thread_sp;
if (exc_type != 0) {
@@ -1852,9 +1838,9 @@ ThreadSP ProcessGDBRemote::SetThreadStopInfo(
->GetBreakpointSiteList()
.FindByAddress(pc);
- // If the current pc is a breakpoint site then the StopInfo should
- // be set to Breakpoint
- // Otherwise, it will be set to Trace.
+ // If the current pc is a breakpoint site then the StopInfo
+ // should be set to Breakpoint Otherwise, it will be set to
+ // Trace.
if (bp_site_sp &&
bp_site_sp->ValidForThisThread(thread_sp.get())) {
thread_sp->SetStopInfo(
@@ -1871,11 +1857,10 @@ ThreadSP ProcessGDBRemote::SetThreadStopInfo(
.FindByAddress(pc);
if (bp_site_sp) {
// If the breakpoint is for this thread, then we'll report the
- // hit, but if it is for another thread,
- // we can just report no reason. We don't need to worry about
- // stepping over the breakpoint here, that
- // will be taken care of when the thread resumes and notices
- // that there's a breakpoint under the pc.
+ // hit, but if it is for another thread, we can just report no
+ // reason. We don't need to worry about stepping over the
+ // breakpoint here, that will be taken care of when the thread
+ // resumes and notices that there's a breakpoint under the pc.
handled = true;
if (bp_site_sp->ValidForThisThread(thread_sp.get())) {
thread_sp->SetStopInfo(
@@ -1937,13 +1922,10 @@ ThreadSP ProcessGDBRemote::SetThreadStopInfo(
pc);
// If the current pc is a breakpoint site then the StopInfo should
- // be set to Breakpoint
- // even though the remote stub did not set it as such. This can
- // happen when
- // the thread is involuntarily interrupted (e.g. due to stops on
- // other
- // threads) just as it is about to execute the breakpoint
- // instruction.
+ // be set to Breakpoint even though the remote stub did not set it
+ // as such. This can happen when the thread is involuntarily
+ // interrupted (e.g. due to stops on other threads) just as it is
+ // about to execute the breakpoint instruction.
if (bp_site_sp && bp_site_sp->ValidForThisThread(thread_sp.get())) {
thread_sp->SetStopInfo(
StopInfo::CreateStopReasonWithBreakpointSiteID(
@@ -1965,11 +1947,10 @@ ThreadSP ProcessGDBRemote::SetThreadStopInfo(
if (bp_site_sp) {
// If the breakpoint is for this thread, then we'll report the
- // hit, but if it is for another thread,
- // we can just report no reason. We don't need to worry about
- // stepping over the breakpoint here, that
- // will be taken care of when the thread resumes and notices
- // that there's a breakpoint under the pc.
+ // hit, but if it is for another thread, we can just report no
+ // reason. We don't need to worry about stepping over the
+ // breakpoint here, that will be taken care of when the thread
+ // resumes and notices that there's a breakpoint under the pc.
if (bp_site_sp->ValidForThisThread(thread_sp.get())) {
if (m_breakpoint_pc_offset != 0)
thread_sp->GetRegisterContext()->SetPC(pc);
@@ -1982,8 +1963,7 @@ ThreadSP ProcessGDBRemote::SetThreadStopInfo(
}
} else {
// If we were stepping then assume the stop was the result of
- // the trace. If we were
- // not stepping then report the SIGTRAP.
+ // the trace. If we were not stepping then report the SIGTRAP.
// FIXME: We are still missing the case where we single step
// over a trap instruction.
if (thread_sp->GetTemporaryResumeState() == eStateStepping)
@@ -2178,15 +2158,15 @@ StateType ProcessGDBRemote::SetThreadStopInfo(StringExtractor &stop_packet) {
switch (stop_type) {
case 'T':
case 'S': {
- // This is a bit of a hack, but is is required. If we did exec, we
- // need to clear our thread lists and also know to rebuild our dynamic
- // register info before we lookup and threads and populate the expedited
- // register values so we need to know this right away so we can cleanup
- // and update our registers.
+ // This is a bit of a hack, but is is required. If we did exec, we need to
+ // clear our thread lists and also know to rebuild our dynamic register
+ // info before we lookup and threads and populate the expedited register
+ // values so we need to know this right away so we can cleanup and update
+ // our registers.
const uint32_t stop_id = GetStopID();
if (stop_id == 0) {
- // Our first stop, make sure we have a process ID, and also make
- // sure we know about our registers
+ // Our first stop, make sure we have a process ID, and also make sure we
+ // know about our registers
if (GetID() == LLDB_INVALID_PROCESS_ID) {
lldb::pid_t pid = m_gdb_comm.GetCurrentProcessID();
if (pid != LLDB_INVALID_PROCESS_ID)
@@ -2232,8 +2212,7 @@ StateType ProcessGDBRemote::SetThreadStopInfo(StringExtractor &stop_packet) {
m_thread_ids.clear();
// A comma separated list of all threads in the current
- // process that includes the thread for this stop reply
- // packet
+ // process that includes the thread for this stop reply packet
lldb::tid_t tid;
while (!value.empty()) {
llvm::StringRef tid_str;
@@ -2245,8 +2224,7 @@ StateType ProcessGDBRemote::SetThreadStopInfo(StringExtractor &stop_packet) {
} else if (key.compare("thread-pcs") == 0) {
m_thread_pcs.clear();
// A comma separated list of all threads in the current
- // process that includes the thread for this stop reply
- // packet
+ // process that includes the thread for this stop reply packet
lldb::addr_t pc;
while (!value.empty()) {
llvm::StringRef pc_str;
@@ -2298,13 +2276,10 @@ StateType ProcessGDBRemote::SetThreadStopInfo(StringExtractor &stop_packet) {
desc_extractor.GetHexByteString(description);
} else if (key.compare("memory") == 0) {
// Expedited memory. GDB servers can choose to send back expedited
- // memory
- // that can populate the L1 memory cache in the process so that things
- // like
- // the frame pointer backchain can be expedited. This will help stack
- // backtracing be more efficient by not having to send as many memory
- // read
- // requests down the remote GDB server.
+ // memory that can populate the L1 memory cache in the process so that
+ // things like the frame pointer backchain can be expedited. This will
+ // help stack backtracing be more efficient by not having to send as
+ // many memory read requests down the remote GDB server.
// Key/value pair format: memory:<addr>=<bytes>;
// <addr> is a number whose base will be interpreted by the prefix:
@@ -2356,7 +2331,8 @@ StateType ProcessGDBRemote::SetThreadStopInfo(StringExtractor &stop_packet) {
if (tid == LLDB_INVALID_THREAD_ID) {
// A thread id may be invalid if the response is old style 'S' packet
// which does not provide the
- // thread information. So update the thread list and choose the first one.
+ // thread information. So update the thread list and choose the first
+ // one.
UpdateThreadIDList();
if (!m_thread_ids.empty()) {
@@ -2389,9 +2365,9 @@ void ProcessGDBRemote::RefreshStateAfterStop() {
m_thread_ids.clear();
m_thread_pcs.clear();
- // Set the thread stop info. It might have a "threads" key whose value is
- // a list of all thread IDs in the current process, so m_thread_ids might
- // get set.
+ // Set the thread stop info. It might have a "threads" key whose value is a
+ // list of all thread IDs in the current process, so m_thread_ids might get
+ // set.
// Scope for the lock
{
@@ -2422,8 +2398,8 @@ void ProcessGDBRemote::RefreshStateAfterStop() {
m_initial_tid = LLDB_INVALID_THREAD_ID;
}
- // Let all threads recover from stopping and do any clean up based
- // on the previous thread state (if any).
+ // Let all threads recover from stopping and do any clean up based on the
+ // previous thread state (if any).
m_thread_list_real.RefreshStateAfterStop();
}
@@ -2431,8 +2407,8 @@ Status ProcessGDBRemote::DoHalt(bool &caused_stop) {
Status error;
if (m_public_state.GetValue() == eStateAttaching) {
- // We are being asked to halt during an attach. We need to just close
- // our file handle and debugserver will go away, and we can be done...
+ // We are being asked to halt during an attach. We need to just close our
+ // file handle and debugserver will go away, and we can be done...
m_gdb_comm.Disconnect();
} else
caused_stop = m_gdb_comm.Interrupt();
@@ -2475,31 +2451,24 @@ Status ProcessGDBRemote::DoDestroy() {
log->Printf("ProcessGDBRemote::DoDestroy()");
// There is a bug in older iOS debugservers where they don't shut down the
- // process
- // they are debugging properly. If the process is sitting at a breakpoint or
- // an exception,
- // this can cause problems with restarting. So we check to see if any of our
- // threads are stopped
- // at a breakpoint, and if so we remove all the breakpoints, resume the
- // process, and THEN
- // destroy it again.
+ // process they are debugging properly. If the process is sitting at a
+ // breakpoint or an exception, this can cause problems with restarting. So
+ // we check to see if any of our threads are stopped at a breakpoint, and if
+ // so we remove all the breakpoints, resume the process, and THEN destroy it
+ // again.
//
// Note, we don't have a good way to test the version of debugserver, but I
- // happen to know that
- // the set of all the iOS debugservers which don't support
- // GetThreadSuffixSupported() and that of
- // the debugservers with this bug are equal. There really should be a better
- // way to test this!
+ // happen to know that the set of all the iOS debugservers which don't
+ // support GetThreadSuffixSupported() and that of the debugservers with this
+ // bug are equal. There really should be a better way to test this!
//
// We also use m_destroy_tried_resuming to make sure we only do this once, if
- // we resume and then halt and
- // get called here to destroy again and we're still at a breakpoint or
- // exception, then we should
- // just do the straight-forward kill.
+ // we resume and then halt and get called here to destroy again and we're
+ // still at a breakpoint or exception, then we should just do the straight-
+ // forward kill.
//
// And of course, if we weren't able to stop the process by the time we get
- // here, it isn't
- // necessary (or helpful) to do any of this.
+ // here, it isn't necessary (or helpful) to do any of this.
if (!m_gdb_comm.GetThreadSuffixSupported() &&
m_public_state.GetValue() != eStateRunning) {
@@ -2514,9 +2483,8 @@ Status ProcessGDBRemote::DoDestroy() {
"destroy once already, not doing it again.");
} else {
// At present, the plans are discarded and the breakpoints disabled
- // Process::Destroy,
- // but we really need it to happen here and it doesn't matter if we do
- // it twice.
+ // Process::Destroy, but we really need it to happen here and it
+ // doesn't matter if we do it twice.
m_thread_list.DiscardThreadPlans();
DisableAllBreakpointSites();
@@ -2553,12 +2521,11 @@ Status ProcessGDBRemote::DoDestroy() {
m_destroy_tried_resuming = true;
// If we are going to run again before killing, it would be good to
- // suspend all the threads
- // before resuming so they won't get into more trouble. Sadly, for
- // the threads stopped with
- // the breakpoint or exception, the exception doesn't get cleared if
- // it is suspended, so we do
- // have to run the risk of letting those threads proceed a bit.
+ // suspend all the threads before resuming so they won't get into
+ // more trouble. Sadly, for the threads stopped with the breakpoint
+ // or exception, the exception doesn't get cleared if it is
+ // suspended, so we do have to run the risk of letting those threads
+ // proceed a bit.
{
std::lock_guard<std::recursive_mutex> guard(threads.GetMutex());
@@ -2605,17 +2572,14 @@ Status ProcessGDBRemote::DoDestroy() {
if (packet_cmd == 'W' || packet_cmd == 'X') {
#if defined(__APPLE__)
// For Native processes on Mac OS X, we launch through the Host
- // Platform, then hand the process off
- // to debugserver, which becomes the parent process through
- // "PT_ATTACH". Then when we go to kill
- // the process on Mac OS X we call ptrace(PT_KILL) to kill it, then we
- // call waitpid which returns
- // with no error and the correct status. But amusingly enough that
- // doesn't seem to actually reap
+ // Platform, then hand the process off to debugserver, which becomes
+ // the parent process through "PT_ATTACH". Then when we go to kill
+ // the process on Mac OS X we call ptrace(PT_KILL) to kill it, then
+ // we call waitpid which returns with no error and the correct
+ // status. But amusingly enough that doesn't seem to actually reap
// the process, but instead it is left around as a Zombie. Probably
- // the kernel is in the process of
- // switching ownership back to lldb which was the original parent, and
- // gets confused in the handoff.
+ // the kernel is in the process of switching ownership back to lldb
+ // which was the original parent, and gets confused in the handoff.
// Anyway, so call waitpid here to finally reap it.
PlatformSP platform_sp(GetTarget().GetPlatform());
if (platform_sp && platform_sp->IsHost()) {
@@ -2687,9 +2651,8 @@ void ProcessGDBRemote::SetLastStopPacket(
if (GetTarget().GetNonStopModeEnabled() == false)
m_stop_packet_stack.clear();
- // Add this stop packet to the stop packet stack
- // This stack will get popped and examined when we switch to the
- // Stopped state
+ // Add this stop packet to the stop packet stack This stack will get popped
+ // and examined when we switch to the Stopped state
m_stop_packet_stack.push_back(response);
}
}
@@ -2721,12 +2684,11 @@ addr_t ProcessGDBRemote::GetImageInfoAddress() {
}
void ProcessGDBRemote::WillPublicStop() {
- // See if the GDB remote client supports the JSON threads info.
- // If so, we gather stop info for all threads, expedited registers,
- // expedited memory, runtime queue information (iOS and MacOSX only),
- // and more. Expediting memory will help stack backtracing be much
- // faster. Expediting registers will make sure we don't have to read
- // the thread registers for GPRs.
+ // See if the GDB remote client supports the JSON threads info. If so, we
+ // gather stop info for all threads, expedited registers, expedited memory,
+ // runtime queue information (iOS and MacOSX only), and more. Expediting
+ // memory will help stack backtracing be much faster. Expediting registers
+ // will make sure we don't have to read the thread registers for GPRs.
m_jthreadsinfo_sp = m_gdb_comm.GetThreadsInfo();
if (m_jthreadsinfo_sp) {
@@ -2776,14 +2738,13 @@ size_t ProcessGDBRemote::DoReadMemory(addr_t addr, void *buf, size_t size,
error.Clear();
if (binary_memory_read) {
// The lower level GDBRemoteCommunication packet receive layer has
- // already de-quoted any
- // 0x7d character escaping that was present in the packet
+ // already de-quoted any 0x7d character escaping that was present in
+ // the packet
size_t data_received_size = response.GetBytesLeft();
if (data_received_size > size) {
// Don't write past the end of BUF if the remote debug server gave us
- // too
- // much data for some reason.
+ // too much data for some reason.
data_received_size = size;
}
memcpy(buf, response.GetStringRef().data(), data_received_size);
@@ -2807,6 +2768,145 @@ size_t ProcessGDBRemote::DoReadMemory(addr_t addr, void *buf, size_t size,
return 0;
}
+Status ProcessGDBRemote::WriteObjectFile(
+ std::vector<ObjectFile::LoadableData> entries) {
+ Status error;
+ // Sort the entries by address because some writes, like those to flash
+ // memory, must happen in order of increasing address.
+ std::stable_sort(
+ std::begin(entries), std::end(entries),
+ [](const ObjectFile::LoadableData a, const ObjectFile::LoadableData b) {
+ return a.Dest < b.Dest;
+ });
+ m_allow_flash_writes = true;
+ error = Process::WriteObjectFile(entries);
+ if (error.Success())
+ error = FlashDone();
+ else
+ // Even though some of the writing failed, try to send a flash done if some
+ // of the writing succeeded so the flash state is reset to normal, but
+ // don't stomp on the error status that was set in the write failure since
+ // that's the one we want to report back.
+ FlashDone();
+ m_allow_flash_writes = false;
+ return error;
+}
+
+bool ProcessGDBRemote::HasErased(FlashRange range) {
+ auto size = m_erased_flash_ranges.GetSize();
+ for (size_t i = 0; i < size; ++i)
+ if (m_erased_flash_ranges.GetEntryAtIndex(i)->Contains(range))
+ return true;
+ return false;
+}
+
+Status ProcessGDBRemote::FlashErase(lldb::addr_t addr, size_t size) {
+ Status status;
+
+ MemoryRegionInfo region;
+ status = GetMemoryRegionInfo(addr, region);
+ if (!status.Success())
+ return status;
+
+ // The gdb spec doesn't say if erasures are allowed across multiple regions,
+ // but we'll disallow it to be safe and to keep the logic simple by worring
+ // about only one region's block size. DoMemoryWrite is this function's
+ // primary user, and it can easily keep writes within a single memory region
+ if (addr + size > region.GetRange().GetRangeEnd()) {
+ status.SetErrorString("Unable to erase flash in multiple regions");
+ return status;
+ }
+
+ uint64_t blocksize = region.GetBlocksize();
+ if (blocksize == 0) {
+ status.SetErrorString("Unable to erase flash because blocksize is 0");
+ return status;
+ }
+
+ // Erasures can only be done on block boundary adresses, so round down addr
+ // and round up size
+ lldb::addr_t block_start_addr = addr - (addr % blocksize);
+ size += (addr - block_start_addr);
+ if ((size % blocksize) != 0)
+ size += (blocksize - size % blocksize);
+
+ FlashRange range(block_start_addr, size);
+
+ if (HasErased(range))
+ return status;
+
+ // We haven't erased the entire range, but we may have erased part of it.
+ // (e.g., block A is already erased and range starts in A and ends in B). So,
+ // adjust range if necessary to exclude already erased blocks.
+ if (!m_erased_flash_ranges.IsEmpty()) {
+ // Assuming that writes and erasures are done in increasing addr order,
+ // because that is a requirement of the vFlashWrite command. Therefore, we
+ // only need to look at the last range in the list for overlap.
+ const auto &last_range = *m_erased_flash_ranges.Back();
+ if (range.GetRangeBase() < last_range.GetRangeEnd()) {
+ auto overlap = last_range.GetRangeEnd() - range.GetRangeBase();
+ // overlap will be less than range.GetByteSize() or else HasErased()
+ // would have been true
+ range.SetByteSize(range.GetByteSize() - overlap);
+ range.SetRangeBase(range.GetRangeBase() + overlap);
+ }
+ }
+
+ StreamString packet;
+ packet.Printf("vFlashErase:%" PRIx64 ",%" PRIx64, range.GetRangeBase(),
+ (uint64_t)range.GetByteSize());
+
+ StringExtractorGDBRemote response;
+ if (m_gdb_comm.SendPacketAndWaitForResponse(packet.GetString(), response,
+ true) ==
+ GDBRemoteCommunication::PacketResult::Success) {
+ if (response.IsOKResponse()) {
+ m_erased_flash_ranges.Insert(range, true);
+ } else {
+ if (response.IsErrorResponse())
+ status.SetErrorStringWithFormat("flash erase failed for 0x%" PRIx64,
+ addr);
+ else if (response.IsUnsupportedResponse())
+ status.SetErrorStringWithFormat("GDB server does not support flashing");
+ else
+ status.SetErrorStringWithFormat(
+ "unexpected response to GDB server flash erase packet '%s': '%s'",
+ packet.GetData(), response.GetStringRef().c_str());
+ }
+ } else {
+ status.SetErrorStringWithFormat("failed to send packet: '%s'",
+ packet.GetData());
+ }
+ return status;
+}
+
+Status ProcessGDBRemote::FlashDone() {
+ Status status;
+ // If we haven't erased any blocks, then we must not have written anything
+ // either, so there is no need to actually send a vFlashDone command
+ if (m_erased_flash_ranges.IsEmpty())
+ return status;
+ StringExtractorGDBRemote response;
+ if (m_gdb_comm.SendPacketAndWaitForResponse("vFlashDone", response, true) ==
+ GDBRemoteCommunication::PacketResult::Success) {
+ if (response.IsOKResponse()) {
+ m_erased_flash_ranges.Clear();
+ } else {
+ if (response.IsErrorResponse())
+ status.SetErrorStringWithFormat("flash done failed");
+ else if (response.IsUnsupportedResponse())
+ status.SetErrorStringWithFormat("GDB server does not support flashing");
+ else
+ status.SetErrorStringWithFormat(
+ "unexpected response to GDB server flash done packet: '%s'",
+ response.GetStringRef().c_str());
+ }
+ } else {
+ status.SetErrorStringWithFormat("failed to send flash done packet");
+ }
+ return status;
+}
+
size_t ProcessGDBRemote::DoWriteMemory(addr_t addr, const void *buf,
size_t size, Status &error) {
GetMaxMemorySize();
@@ -2819,10 +2919,33 @@ size_t ProcessGDBRemote::DoWriteMemory(addr_t addr, const void *buf,
size = max_memory_size;
}
- StreamString packet;
- packet.Printf("M%" PRIx64 ",%" PRIx64 ":", addr, (uint64_t)size);
- packet.PutBytesAsRawHex8(buf, size, endian::InlHostByteOrder(),
- endian::InlHostByteOrder());
+ StreamGDBRemote packet;
+
+ MemoryRegionInfo region;
+ Status region_status = GetMemoryRegionInfo(addr, region);
+
+ bool is_flash =
+ region_status.Success() && region.GetFlash() == MemoryRegionInfo::eYes;
+
+ if (is_flash) {
+ if (!m_allow_flash_writes) {
+ error.SetErrorString("Writing to flash memory is not allowed");
+ return 0;
+ }
+ // Keep the write within a flash memory region
+ if (addr + size > region.GetRange().GetRangeEnd())
+ size = region.GetRange().GetRangeEnd() - addr;
+ // Flash memory must be erased before it can be written
+ error = FlashErase(addr, size);
+ if (!error.Success())
+ return 0;
+ packet.Printf("vFlashWrite:%" PRIx64 ":", addr);
+ packet.PutEscapedBytes(buf, size);
+ } else {
+ packet.Printf("M%" PRIx64 ",%" PRIx64 ":", addr, (uint64_t)size);
+ packet.PutBytesAsRawHex8(buf, size, endian::InlHostByteOrder(),
+ endian::InlHostByteOrder());
+ }
StringExtractorGDBRemote response;
if (m_gdb_comm.SendPacketAndWaitForResponse(packet.GetString(), response,
true) ==
@@ -2918,8 +3041,8 @@ Status ProcessGDBRemote::DoDeallocateMemory(lldb::addr_t addr) {
switch (supported) {
case eLazyBoolCalculate:
- // We should never be deallocating memory without allocating memory
- // first so we should never get eLazyBoolCalculate
+ // We should never be deallocating memory without allocating memory first
+ // so we should never get eLazyBoolCalculate
error.SetErrorString(
"tried to deallocate memory without ever allocating memory");
break;
@@ -2991,18 +3114,14 @@ Status ProcessGDBRemote::EnableBreakpointSite(BreakpointSite *bp_site) {
const size_t bp_op_size = GetSoftwareBreakpointTrapOpcode(bp_site);
// SupportsGDBStoppointPacket() simply checks a boolean, indicating if this
- // breakpoint type
- // is supported by the remote stub. These are set to true by default, and
- // later set to false
- // only after we receive an unimplemented response when sending a breakpoint
- // packet. This means
- // initially that unless we were specifically instructed to use a hardware
- // breakpoint, LLDB will
- // attempt to set a software breakpoint. HardwareRequired() also queries a
- // boolean variable which
- // indicates if the user specifically asked for hardware breakpoints. If true
- // then we will
- // skip over software breakpoints.
+ // breakpoint type is supported by the remote stub. These are set to true by
+ // default, and later set to false only after we receive an unimplemented
+ // response when sending a breakpoint packet. This means initially that
+ // unless we were specifically instructed to use a hardware breakpoint, LLDB
+ // will attempt to set a software breakpoint. HardwareRequired() also queries
+ // a boolean variable which indicates if the user specifically asked for
+ // hardware breakpoints. If true then we will skip over software
+ // breakpoints.
if (m_gdb_comm.SupportsGDBStoppointPacket(eBreakpointSoftware) &&
(!bp_site->HardwareRequired())) {
// Try to send off a software breakpoint packet ($Z0)
@@ -3015,19 +3134,14 @@ Status ProcessGDBRemote::EnableBreakpointSite(BreakpointSite *bp_site) {
return error;
}
- // SendGDBStoppointTypePacket() will return an error if it was unable to set
- // this
- // breakpoint. We need to differentiate between a error specific to placing
- // this breakpoint
- // or if we have learned that this breakpoint type is unsupported. To do
- // this, we
- // must test the support boolean for this breakpoint type to see if it now
- // indicates that
- // this breakpoint type is unsupported. If they are still supported then we
- // should return
+ // SendGDBStoppointTypePacket() will return an error if it was unable to
+ // set this breakpoint. We need to differentiate between a error specific
+ // to placing this breakpoint or if we have learned that this breakpoint
+ // type is unsupported. To do this, we must test the support boolean for
+ // this breakpoint type to see if it now indicates that this breakpoint
+ // type is unsupported. If they are still supported then we should return
// with the error code. If they are now unsupported, then we would like to
- // fall through
- // and try another form of breakpoint.
+ // fall through and try another form of breakpoint.
if (m_gdb_comm.SupportsGDBStoppointPacket(eBreakpointSoftware)) {
if (error_no != UINT8_MAX)
error.SetErrorStringWithFormat(
@@ -3038,21 +3152,18 @@ Status ProcessGDBRemote::EnableBreakpointSite(BreakpointSite *bp_site) {
}
// We reach here when software breakpoints have been found to be
- // unsupported. For future
- // calls to set a breakpoint, we will not attempt to set a breakpoint with a
- // type that is
- // known not to be supported.
+ // unsupported. For future calls to set a breakpoint, we will not attempt
+ // to set a breakpoint with a type that is known not to be supported.
if (log)
log->Printf("Software breakpoints are unsupported");
// So we will fall through and try a hardware breakpoint
}
- // The process of setting a hardware breakpoint is much the same as above. We
- // check the
- // supported boolean for this breakpoint type, and if it is thought to be
- // supported then we
- // will try to set this breakpoint with a hardware breakpoint.
+ // The process of setting a hardware breakpoint is much the same as above.
+ // We check the supported boolean for this breakpoint type, and if it is
+ // thought to be supported then we will try to set this breakpoint with a
+ // hardware breakpoint.
if (m_gdb_comm.SupportsGDBStoppointPacket(eBreakpointHardware)) {
// Try to send off a hardware breakpoint packet ($Z1)
uint8_t error_no = m_gdb_comm.SendGDBStoppointTypePacket(
@@ -3094,8 +3205,8 @@ Status ProcessGDBRemote::EnableBreakpointSite(BreakpointSite *bp_site) {
return error;
}
- // As a last resort we want to place a manual breakpoint. An instruction
- // is placed into the process memory using memory write packets.
+ // As a last resort we want to place a manual breakpoint. An instruction is
+ // placed into the process memory using memory write packets.
return EnableSoftwareBreakpoint(bp_site);
}
@@ -3225,10 +3336,9 @@ Status ProcessGDBRemote::DisableWatchpoint(Watchpoint *wp, bool notify) {
log->Printf("ProcessGDBRemote::DisableWatchpoint (watchID = %" PRIu64
") addr = 0x%8.8" PRIx64 " -- SUCCESS (already disabled)",
watchID, (uint64_t)addr);
- // See also 'class WatchpointSentry' within StopInfo.cpp.
- // This disabling attempt might come from the user-supplied actions, we'll
- // route it in order for
- // the watchpoint object to intelligently process this action.
+ // See also 'class WatchpointSentry' within StopInfo.cpp. This disabling
+ // attempt might come from the user-supplied actions, we'll route it in
+ // order for the watchpoint object to intelligently process this action.
wp->SetEnabled(false, notify);
return error;
}
@@ -3313,8 +3423,8 @@ Status ProcessGDBRemote::LaunchAndConnectToDebugserver(
static FileSpec g_debugserver_file_spec;
ProcessLaunchInfo debugserver_launch_info;
- // Make debugserver run in its own session so signals generated by
- // special terminal key sequences (^C) don't affect debugserver.
+ // Make debugserver run in its own session so signals generated by special
+ // terminal key sequences (^C) don't affect debugserver.
debugserver_launch_info.SetLaunchInSeparateProcessGroup(true);
const std::weak_ptr<ProcessGDBRemote> this_wp =
@@ -3325,27 +3435,22 @@ Status ProcessGDBRemote::LaunchAndConnectToDebugserver(
int communication_fd = -1;
#ifdef USE_SOCKETPAIR_FOR_LOCAL_CONNECTION
- // Auto close the sockets we might open up unless everything goes OK. This
- // helps us not leak file descriptors when things go wrong.
- lldb_utility::CleanUp<int, int> our_socket(-1, -1, close);
- lldb_utility::CleanUp<int, int> gdb_socket(-1, -1, close);
-
// Use a socketpair on non-Windows systems for security and performance
// reasons.
- {
- int sockets[2]; /* the pair of socket descriptors */
- if (socketpair(AF_UNIX, SOCK_STREAM, 0, sockets) == -1) {
- error.SetErrorToErrno();
- return error;
- }
-
- our_socket.set(sockets[0]);
- gdb_socket.set(sockets[1]);
+ int sockets[2]; /* the pair of socket descriptors */
+ if (socketpair(AF_UNIX, SOCK_STREAM, 0, sockets) == -1) {
+ error.SetErrorToErrno();
+ return error;
}
+ int our_socket = sockets[0];
+ int gdb_socket = sockets[1];
+ CleanUp cleanup_our(close, our_socket);
+ CleanUp cleanup_gdb(close, gdb_socket);
+
// Don't let any child processes inherit our communication socket
- SetCloexecFlag(our_socket.get());
- communication_fd = gdb_socket.get();
+ SetCloexecFlag(our_socket);
+ communication_fd = gdb_socket;
#endif
error = m_gdb_comm.StartDebugserverProcess(
@@ -3359,10 +3464,10 @@ Status ProcessGDBRemote::LaunchAndConnectToDebugserver(
if (m_debugserver_pid != LLDB_INVALID_PROCESS_ID) {
#ifdef USE_SOCKETPAIR_FOR_LOCAL_CONNECTION
- // Our process spawned correctly, we can now set our connection to use our
- // end of the socket pair
- m_gdb_comm.SetConnection(
- new ConnectionFileDescriptor(our_socket.release(), true));
+ // Our process spawned correctly, we can now set our connection to use
+ // our end of the socket pair
+ cleanup_our.disable();
+ m_gdb_comm.SetConnection(new ConnectionFileDescriptor(our_socket, true));
#endif
StartAsyncThread();
}
@@ -3377,9 +3482,9 @@ Status ProcessGDBRemote::LaunchAndConnectToDebugserver(
}
if (m_gdb_comm.IsConnected()) {
- // Finish the connection process by doing the handshake without connecting
- // (send NULL URL)
- ConnectToDebugserver("");
+ // Finish the connection process by doing the handshake without
+ // connecting (send NULL URL)
+ error = ConnectToDebugserver("");
} else {
error.SetErrorString("connection failed");
}
@@ -3393,8 +3498,8 @@ bool ProcessGDBRemote::MonitorDebugserverProcess(
int signo, // Zero for no signal
int exit_status // Exit value of process if signal is zero
) {
- // "debugserver_pid" argument passed in is the process ID for
- // debugserver that we are tracking...
+ // "debugserver_pid" argument passed in is the process ID for debugserver
+ // that we are tracking...
Log *log(ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_PROCESS));
const bool handled = true;
@@ -3410,12 +3515,12 @@ bool ProcessGDBRemote::MonitorDebugserverProcess(
if (!process_sp || process_sp->m_debugserver_pid != debugserver_pid)
return handled;
- // Sleep for a half a second to make sure our inferior process has
- // time to set its exit status before we set it incorrectly when
- // both the debugserver and the inferior process shut down.
+ // Sleep for a half a second to make sure our inferior process has time to
+ // set its exit status before we set it incorrectly when both the debugserver
+ // and the inferior process shut down.
usleep(500000);
- // If our process hasn't yet exited, debugserver might have died.
- // If the process did exit, then we are reaping it.
+ // If our process hasn't yet exited, debugserver might have died. If the
+ // process did exit, then we are reaping it.
const StateType state = process_sp->GetState();
if (state != eStateInvalid && state != eStateUnloaded &&
@@ -3438,8 +3543,8 @@ bool ProcessGDBRemote::MonitorDebugserverProcess(
process_sp->SetExitStatus(-1, error_str);
}
- // Debugserver has exited we need to let our ProcessGDBRemote
- // know that it no longer has a debugserver instance
+ // Debugserver has exited we need to let our ProcessGDBRemote know that it no
+ // longer has a debugserver instance
process_sp->m_debugserver_pid = LLDB_INVALID_PROCESS_ID;
return handled;
}
@@ -3529,10 +3634,9 @@ bool ProcessGDBRemote::HandleNotifyPacket(StringExtractorGDBRemote &packet) {
// check for more stop reasons
HandleStopReplySequence();
- // if the process is stopped then we need to fake a resume
- // so that we can stop properly with the new break. This
- // is possible due to SetPrivateState() broadcasting the
- // state change as a side effect.
+ // if the process is stopped then we need to fake a resume so that we can
+ // stop properly with the new break. This is possible due to
+ // SetPrivateState() broadcasting the state change as a side effect.
if (GetPrivateState() == lldb::StateType::eStateStopped) {
SetPrivateState(lldb::StateType::eStateRunning);
}
@@ -3605,12 +3709,11 @@ thread_result_t ProcessGDBRemote::AsyncThread(void *arg) {
response);
// We need to immediately clear the thread ID list so we are sure
- // to get a valid list of threads.
- // The thread ID list might be contained within the "response", or
- // the stop reply packet that
+ // to get a valid list of threads. The thread ID list might be
+ // contained within the "response", or the stop reply packet that
// caused the stop. So clear it now before we give the stop reply
- // packet to the process
- // using the process->SetLastStopPacket()...
+ // packet to the process using the
+ // process->SetLastStopPacket()...
process->ClearThreadIDList();
switch (stop_state) {
@@ -3647,17 +3750,14 @@ thread_result_t ProcessGDBRemote::AsyncThread(void *arg) {
// Check to see if we were trying to attach and if we got back
// the "E87" error code from debugserver -- this indicates that
// the process is not debuggable. Return a slightly more
- // helpful
- // error message about why the attach failed.
+ // helpful error message about why the attach failed.
if (::strstr(continue_cstr, "vAttach") != NULL &&
response.GetError() == 0x87) {
process->SetExitStatus(-1, "cannot attach to process due to "
"System Integrity Protection");
- }
- // E01 code from vAttach means that the attach failed
- if (::strstr(continue_cstr, "vAttach") != NULL &&
- response.GetError() == 0x1) {
- process->SetExitStatus(-1, "unable to attach");
+ } else if (::strstr(continue_cstr, "vAttach") != NULL &&
+ response.GetStatus().Fail()) {
+ process->SetExitStatus(-1, response.GetStatus().AsCString());
} else {
process->SetExitStatus(-1, "lost connection");
}
@@ -3769,8 +3869,8 @@ Status ProcessGDBRemote::UpdateAutomaticSignalFiltering() {
Log *log(ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_PROCESS));
LLDB_LOG(log, "Check if need to update ignored signals");
- // QPassSignals package is not supported by the server,
- // there is no way we can ignore any signals on server side.
+ // QPassSignals package is not supported by the server, there is no way we
+ // can ignore any signals on server side.
if (!m_gdb_comm.GetQPassSignalsSupported())
return Status();
@@ -3894,9 +3994,9 @@ ProcessGDBRemote::GetExtendedInfoForThread(lldb::tid_t tid) {
// FIXME the final character of a JSON dictionary, '}', is the escape
// character in gdb-remote binary mode. lldb currently doesn't escape
- // these characters in its packet output -- so we add the quoted version
- // of the } character here manually in case we talk to a debugserver which
- // un-escapes the characters at packet read time.
+ // these characters in its packet output -- so we add the quoted version of
+ // the } character here manually in case we talk to a debugserver which un-
+ // escapes the characters at packet read time.
packet << (char)(0x7d ^ 0x20);
StringExtractorGDBRemote response;
@@ -3966,9 +4066,9 @@ ProcessGDBRemote::GetLoadedDynamicLibrariesInfos_sender(
// FIXME the final character of a JSON dictionary, '}', is the escape
// character in gdb-remote binary mode. lldb currently doesn't escape
- // these characters in its packet output -- so we add the quoted version
- // of the } character here manually in case we talk to a debugserver which
- // un-escapes the characters at packet read time.
+ // these characters in its packet output -- so we add the quoted version of
+ // the } character here manually in case we talk to a debugserver which un-
+ // escapes the characters at packet read time.
packet << (char)(0x7d ^ 0x20);
StringExtractorGDBRemote response;
@@ -3999,9 +4099,9 @@ StructuredData::ObjectSP ProcessGDBRemote::GetSharedCacheInfo() {
// FIXME the final character of a JSON dictionary, '}', is the escape
// character in gdb-remote binary mode. lldb currently doesn't escape
- // these characters in its packet output -- so we add the quoted version
- // of the } character here manually in case we talk to a debugserver which
- // un-escapes the characters at packet read time.
+ // these characters in its packet output -- so we add the quoted version of
+ // the } character here manually in case we talk to a debugserver which un-
+ // escapes the characters at packet read time.
packet << (char)(0x7d ^ 0x20);
StringExtractorGDBRemote response;
@@ -4026,14 +4126,14 @@ Status ProcessGDBRemote::ConfigureStructuredData(
return m_gdb_comm.ConfigureRemoteStructuredData(type_name, config_sp);
}
-// Establish the largest memory read/write payloads we should use.
-// If the remote stub has a max packet size, stay under that size.
+// Establish the largest memory read/write payloads we should use. If the
+// remote stub has a max packet size, stay under that size.
//
-// If the remote stub's max packet size is crazy large, use a
-// reasonable largeish default.
+// If the remote stub's max packet size is crazy large, use a reasonable
+// largeish default.
//
-// If the remote stub doesn't advertise a max packet size, use a
-// conservative default.
+// If the remote stub doesn't advertise a max packet size, use a conservative
+// default.
void ProcessGDBRemote::GetMaxMemorySize() {
const uint64_t reasonable_largeish_default = 128 * 1024;
@@ -4045,15 +4145,15 @@ void ProcessGDBRemote::GetMaxMemorySize() {
// Save the stub's claimed maximum packet size
m_remote_stub_max_memory_size = stub_max_size;
- // Even if the stub says it can support ginormous packets,
- // don't exceed our reasonable largeish default packet size.
+ // Even if the stub says it can support ginormous packets, don't exceed
+ // our reasonable largeish default packet size.
if (stub_max_size > reasonable_largeish_default) {
stub_max_size = reasonable_largeish_default;
}
- // Memory packet have other overheads too like Maddr,size:#NN
- // Instead of calculating the bytes taken by size and addr every
- // time, we take a maximum guess here.
+ // Memory packet have other overheads too like Maddr,size:#NN Instead of
+ // calculating the bytes taken by size and addr every time, we take a
+ // maximum guess here.
if (stub_max_size > 70)
stub_max_size -= 32 + 32 + 6;
else {
@@ -4140,13 +4240,8 @@ void ProcessGDBRemote::PrefetchModuleSpecs(
}
}
-bool ProcessGDBRemote::GetHostOSVersion(uint32_t &major, uint32_t &minor,
- uint32_t &update) {
- if (m_gdb_comm.GetOSVersion(major, minor, update))
- return true;
- // We failed to get the host OS version, defer to the base
- // implementation to correctly invalidate the arguments.
- return Process::GetHostOSVersion(major, minor, update);
+llvm::VersionTuple ProcessGDBRemote::GetHostOSVersion() {
+ return m_gdb_comm.GetOSVersion();
}
namespace {
@@ -4237,7 +4332,7 @@ bool ParseRegisters(XMLNode feature_node, GdbServerTargetInfo &target_info,
} else if (name == "format") {
format_set = true;
Format format = eFormatInvalid;
- if (Args::StringToFormat(value.data(), format, NULL).Success())
+ if (OptionArgParser::ToFormat(value.data(), format, NULL).Success())
reg_info.format = format;
else if (value == "vector-sint8")
reg_info.format = eFormatVectorOfSInt8;
@@ -4311,8 +4406,8 @@ bool ParseRegisters(XMLNode feature_node, GdbServerTargetInfo &target_info,
}
// Only update the register set name if we didn't get a "reg_set"
+ // attribute. "set_name" will be empty if we didn't have a "reg_set"
// attribute.
- // "set_name" will be empty if we didn't have a "reg_set" attribute.
if (!set_name && !gdb_group.empty())
set_name.SetCString(gdb_group.c_str());
@@ -4339,8 +4434,8 @@ bool ParseRegisters(XMLNode feature_node, GdbServerTargetInfo &target_info,
} // namespace {}
-// query the target of gdb-remote for extended target information
-// return: 'true' on success
+// query the target of gdb-remote for extended target information return:
+// 'true' on success
// 'false' on failure
bool ProcessGDBRemote::GetGDBServerRegisterInfo(ArchSpec &arch_to_use) {
// Make sure LLDB has an XML parser it can use first
@@ -4409,15 +4504,27 @@ bool ProcessGDBRemote::GetGDBServerRegisterInfo(ArchSpec &arch_to_use) {
return true; // Keep iterating through all children of the target_node
});
+ // If the target.xml includes an architecture entry like
+ // <architecture>i386:x86-64</architecture> (seen from VMWare ESXi)
+ // <architecture>arm</architecture> (seen from Segger JLink on unspecified arm board)
+ // use that if we don't have anything better.
+ if (!arch_to_use.IsValid() && !target_info.arch.empty()) {
+ if (target_info.arch == "i386:x86-64")
+ {
+ // We don't have any information about vendor or OS.
+ arch_to_use.SetTriple("x86_64--");
+ GetTarget().MergeArchitecture(arch_to_use);
+ }
+ }
+
// Initialize these outside of ParseRegisters, since they should not be
// reset inside each include feature
uint32_t cur_reg_num = 0;
uint32_t reg_offset = 0;
- // Don't use Process::GetABI, this code gets called from DidAttach, and in
- // that context we haven't
- // set the Target's architecture yet, so the ABI is also potentially
- // incorrect.
+ // Don't use Process::GetABI, this code gets called from DidAttach, and
+ // in that context we haven't set the Target's architecture yet, so the
+ // ABI is also potentially incorrect.
ABISP abi_to_use_sp = ABI::FindPlugin(shared_from_this(), arch_to_use);
for (auto &feature_node : feature_nodes) {
ParseRegisters(feature_node, target_info, this->m_register_info,
@@ -4758,8 +4865,8 @@ void ProcessGDBRemote::ModulesDidLoad(ModuleList &module_list) {
// do anything
Process::ModulesDidLoad(module_list);
- // After loading shared libraries, we can ask our remote GDB server if
- // it needs any symbols.
+ // After loading shared libraries, we can ask our remote GDB server if it
+ // needs any symbols.
m_gdb_comm.ServeSymbolLookups(this);
}
@@ -4817,8 +4924,8 @@ std::string ProcessGDBRemote::HarmonizeThreadIdsForProfileData(
has_used_usec = true;
usec_value.getAsInteger(0, curr_used_usec);
} else {
- // We didn't find what we want, it is probably
- // an older version. Bail out.
+ // We didn't find what we want, it is probably an older version. Bail
+ // out.
profileDataExtractor.SetFilePos(input_file_pos);
}
}
@@ -4840,8 +4947,8 @@ std::string ProcessGDBRemote::HarmonizeThreadIdsForProfileData(
((real_used_usec > 0) || (HasAssignedIndexIDToThread(thread_id)));
if (good_first_time || good_subsequent_time) {
- // We try to avoid doing too many index id reservation,
- // resulting in fast increase of index ids.
+ // We try to avoid doing too many index id reservation, resulting in
+ // fast increase of index ids.
output_stream << name << ":";
int32_t index_id = AssignIndexIDToThread(thread_id);
@@ -4892,7 +4999,7 @@ ParseStructuredDataPacket(llvm::StringRef packet) {
if (!packet.consume_front(s_async_json_packet_prefix)) {
if (log) {
log->Printf(
- "GDBRemoteCommmunicationClientBase::%s() received $J packet "
+ "GDBRemoteCommunicationClientBase::%s() received $J packet "
"but was not a StructuredData packet: packet starts with "
"%s",
__FUNCTION__,
@@ -4901,8 +5008,7 @@ ParseStructuredDataPacket(llvm::StringRef packet) {
return StructuredData::ObjectSP();
}
- // This is an asynchronous JSON packet, destined for a
- // StructuredDataPlugin.
+ // This is an asynchronous JSON packet, destined for a StructuredDataPlugin.
StructuredData::ObjectSP json_sp = StructuredData::ParseJSON(packet);
if (log) {
if (json_sp) {
@@ -5137,8 +5243,9 @@ public:
~CommandObjectProcessGDBRemotePacketMonitor() {}
- bool DoExecute(const char *command, CommandReturnObject &result) override {
- if (command == NULL || command[0] == '\0') {
+ bool DoExecute(llvm::StringRef command,
+ CommandReturnObject &result) override {
+ if (command.empty()) {
result.AppendErrorWithFormat("'%s' takes a command string argument",
m_cmd_name.c_str());
result.SetStatus(eReturnStatusFailed);
@@ -5150,14 +5257,15 @@ public:
if (process) {
StreamString packet;
packet.PutCString("qRcmd,");
- packet.PutBytesAsRawHex8(command, strlen(command));
+ packet.PutBytesAsRawHex8(command.data(), command.size());
bool send_async = true;
StringExtractorGDBRemote response;
- process->GetGDBRemote().SendPacketAndWaitForResponse(
- packet.GetString(), response, send_async);
- result.SetStatus(eReturnStatusSuccessFinishResult);
Stream &output_strm = result.GetOutputStream();
+ process->GetGDBRemote().SendPacketAndReceiveResponseWithOutputSupport(
+ packet.GetString(), response, send_async,
+ [&output_strm](llvm::StringRef output) { output_strm << output; });
+ result.SetStatus(eReturnStatusSuccessFinishResult);
output_strm.Printf(" packet: %s\n", packet.GetData());
const std::string &response_str = response.GetStringRef();
diff --git a/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h b/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h
index 42d1c4ecd6663..45bb2d4c28e71 100644
--- a/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h
+++ b/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h
@@ -144,6 +144,9 @@ public:
size_t DoReadMemory(lldb::addr_t addr, void *buf, size_t size,
Status &error) override;
+ Status
+ WriteObjectFile(std::vector<ObjectFile::LoadableData> entries) override;
+
size_t DoWriteMemory(lldb::addr_t addr, const void *buf, size_t size,
Status &error) override;
@@ -214,8 +217,7 @@ public:
void PrefetchModuleSpecs(llvm::ArrayRef<FileSpec> module_file_specs,
const llvm::Triple &triple) override;
- bool GetHostOSVersion(uint32_t &major, uint32_t &minor,
- uint32_t &update) override;
+ llvm::VersionTuple GetHostOSVersion() override;
size_t LoadModules(LoadedModuleInfoList &module_list) override;
@@ -302,6 +304,11 @@ protected:
int64_t m_breakpoint_pc_offset;
lldb::tid_t m_initial_tid; // The initial thread ID, given by stub on attach
+ bool m_allow_flash_writes;
+ using FlashRangeVector = lldb_private::RangeVector<lldb::addr_t, size_t>;
+ using FlashRange = FlashRangeVector::Entry;
+ FlashRangeVector m_erased_flash_ranges;
+
//----------------------------------------------------------------------
// Accessors
//----------------------------------------------------------------------
@@ -408,6 +415,12 @@ protected:
Status UpdateAutomaticSignalFiltering() override;
+ Status FlashErase(lldb::addr_t addr, size_t size);
+
+ Status FlashDone();
+
+ bool HasErased(FlashRange range);
+
private:
//------------------------------------------------------------------
// For ProcessGDBRemote only
diff --git a/source/Plugins/Process/gdb-remote/ThreadGDBRemote.cpp b/source/Plugins/Process/gdb-remote/ThreadGDBRemote.cpp
index 27dd03bfc7bc5..a525c16b9f135 100644
--- a/source/Plugins/Process/gdb-remote/ThreadGDBRemote.cpp
+++ b/source/Plugins/Process/gdb-remote/ThreadGDBRemote.cpp
@@ -24,7 +24,7 @@
#include "ProcessGDBRemote.h"
#include "ProcessGDBRemoteLog.h"
-#include "Utility/StringExtractorGDBRemote.h"
+#include "lldb/Utility/StringExtractorGDBRemote.h"
using namespace lldb;
using namespace lldb_private;
@@ -55,7 +55,7 @@ ThreadGDBRemote::~ThreadGDBRemote() {
const char *ThreadGDBRemote::GetName() {
if (m_thread_name.empty())
- return NULL;
+ return nullptr;
return m_thread_name.c_str();
}
@@ -80,10 +80,9 @@ void ThreadGDBRemote::SetQueueInfo(std::string &&queue_name,
const char *ThreadGDBRemote::GetQueueName() {
// If our cached queue info is valid, then someone called
- // ThreadGDBRemote::SetQueueInfo(...)
- // with valid information that was gleaned from the stop reply packet. In this
- // case we trust
- // that the info is valid in m_dispatch_queue_name without refetching it
+ // ThreadGDBRemote::SetQueueInfo(...) with valid information that was gleaned
+ // from the stop reply packet. In this case we trust that the info is valid
+ // in m_dispatch_queue_name without refetching it
if (CachedQueueInfoIsValid()) {
if (m_dispatch_queue_name.empty())
return nullptr;
@@ -110,15 +109,14 @@ const char *ThreadGDBRemote::GetQueueName() {
return m_dispatch_queue_name.c_str();
}
}
- return NULL;
+ return nullptr;
}
QueueKind ThreadGDBRemote::GetQueueKind() {
// If our cached queue info is valid, then someone called
- // ThreadGDBRemote::SetQueueInfo(...)
- // with valid information that was gleaned from the stop reply packet. In this
- // case we trust
- // that the info is valid in m_dispatch_queue_name without refetching it
+ // ThreadGDBRemote::SetQueueInfo(...) with valid information that was gleaned
+ // from the stop reply packet. In this case we trust that the info is valid
+ // in m_dispatch_queue_name without refetching it
if (CachedQueueInfoIsValid()) {
return m_queue_kind;
}
@@ -141,10 +139,9 @@ QueueKind ThreadGDBRemote::GetQueueKind() {
queue_id_t ThreadGDBRemote::GetQueueID() {
// If our cached queue info is valid, then someone called
- // ThreadGDBRemote::SetQueueInfo(...)
- // with valid information that was gleaned from the stop reply packet. In this
- // case we trust
- // that the info is valid in m_dispatch_queue_name without refetching it
+ // ThreadGDBRemote::SetQueueInfo(...) with valid information that was gleaned
+ // from the stop reply packet. In this case we trust that the info is valid
+ // in m_dispatch_queue_name without refetching it
if (CachedQueueInfoIsValid())
return m_queue_serial_number;
@@ -275,11 +272,11 @@ void ThreadGDBRemote::RefreshStateAfterStop() {
// Invalidate all registers in our register context. We don't set "force" to
// true because the stop reply packet might have had some register values
// that were expedited and these will already be copied into the register
- // context by the time this function gets called. The GDBRemoteRegisterContext
- // class has been made smart enough to detect when it needs to invalidate
- // which registers are valid by putting hooks in the register read and
- // register supply functions where they check the process stop ID and do
- // the right thing.
+ // context by the time this function gets called. The
+ // GDBRemoteRegisterContext class has been made smart enough to detect when
+ // it needs to invalidate which registers are valid by putting hooks in the
+ // register read and register supply functions where they check the process
+ // stop ID and do the right thing.
const bool force = false;
GetRegisterContext()->InvalidateIfNeeded(force);
}
@@ -292,8 +289,8 @@ void ThreadGDBRemote::Dump(Log *log, uint32_t index) {}
bool ThreadGDBRemote::ShouldStop(bool &step_more) { return true; }
lldb::RegisterContextSP ThreadGDBRemote::GetRegisterContext() {
- if (m_reg_context_sp.get() == NULL)
- m_reg_context_sp = CreateRegisterContextForFrame(NULL);
+ if (!m_reg_context_sp)
+ m_reg_context_sp = CreateRegisterContextForFrame(nullptr);
return m_reg_context_sp;
}
@@ -310,7 +307,8 @@ ThreadGDBRemote::CreateRegisterContextForFrame(StackFrame *frame) {
if (process_sp) {
ProcessGDBRemote *gdb_process =
static_cast<ProcessGDBRemote *>(process_sp.get());
- // read_all_registers_at_once will be true if 'p' packet is not supported.
+ // read_all_registers_at_once will be true if 'p' packet is not
+ // supported.
bool read_all_registers_at_once =
!gdb_process->GetGDBRemote().GetpPacketSupported(GetID());
reg_ctx_sp.reset(new GDBRemoteRegisterContext(
@@ -319,7 +317,7 @@ ThreadGDBRemote::CreateRegisterContextForFrame(StackFrame *frame) {
}
} else {
Unwind *unwinder = GetUnwinder();
- if (unwinder)
+ if (unwinder != nullptr)
reg_ctx_sp = unwinder->CreateRegisterContextForFrame(frame);
}
return reg_ctx_sp;
diff --git a/source/Plugins/Process/mach-core/CMakeLists.txt b/source/Plugins/Process/mach-core/CMakeLists.txt
index 18f6ff581ea32..e79cd82c92a67 100644
--- a/source/Plugins/Process/mach-core/CMakeLists.txt
+++ b/source/Plugins/Process/mach-core/CMakeLists.txt
@@ -1,5 +1,3 @@
-include_directories(../Utility)
-
add_lldb_library(lldbPluginProcessMachCore PLUGIN
ProcessMachCore.cpp
ThreadMachCore.cpp
diff --git a/source/Plugins/Process/mach-core/ProcessMachCore.cpp b/source/Plugins/Process/mach-core/ProcessMachCore.cpp
index d21651b77ee0c..bfa35ed506a96 100644
--- a/source/Plugins/Process/mach-core/ProcessMachCore.cpp
+++ b/source/Plugins/Process/mach-core/ProcessMachCore.cpp
@@ -35,7 +35,7 @@
// Project includes
#include "ProcessMachCore.h"
-#include "StopInfoMachException.h"
+#include "Plugins/Process/Utility/StopInfoMachException.h"
#include "ThreadMachCore.h"
// Needed for the plug-in names for the dynamic loaders.
@@ -91,11 +91,10 @@ bool ProcessMachCore::CanDebug(lldb::TargetSP target_sp,
// For now we are just making sure the file exists for a given module
if (!m_core_module_sp && m_core_file.Exists()) {
- // Don't add the Target's architecture to the ModuleSpec - we may be working
- // with a core file that doesn't have the correct cpusubtype in the header
- // but we should still try to use it -
- // ModuleSpecList::FindMatchingModuleSpec
- // enforces a strict arch mach.
+ // Don't add the Target's architecture to the ModuleSpec - we may be
+ // working with a core file that doesn't have the correct cpusubtype in the
+ // header but we should still try to use it -
+ // ModuleSpecList::FindMatchingModuleSpec enforces a strict arch mach.
ModuleSpec core_module_spec(m_core_file);
Status error(ModuleList::GetSharedModule(core_module_spec, m_core_module_sp,
NULL, NULL, NULL));
@@ -125,10 +124,10 @@ ProcessMachCore::ProcessMachCore(lldb::TargetSP target_sp,
//----------------------------------------------------------------------
ProcessMachCore::~ProcessMachCore() {
Clear();
- // We need to call finalize on the process before destroying ourselves
- // to make sure all of the broadcaster cleanup goes as planned. If we
- // destruct this class, then Process::~Process() might have problems
- // trying to fully destroy the broadcaster.
+ // We need to call finalize on the process before destroying ourselves to
+ // make sure all of the broadcaster cleanup goes as planned. If we destruct
+ // this class, then Process::~Process() might have problems trying to fully
+ // destroy the broadcaster.
Finalize();
}
@@ -162,11 +161,10 @@ bool ProcessMachCore::GetDynamicLoaderAddress(lldb::addr_t addr) {
// header.magic, header.filetype);
if (header.magic == llvm::MachO::MH_MAGIC ||
header.magic == llvm::MachO::MH_MAGIC_64) {
- // Check MH_EXECUTABLE to see if we can find the mach image
- // that contains the shared library list. The dynamic loader
- // (dyld) is what contains the list for user applications,
- // and the mach kernel contains a global that has the list
- // of kexts to load
+ // Check MH_EXECUTABLE to see if we can find the mach image that contains
+ // the shared library list. The dynamic loader (dyld) is what contains the
+ // list for user applications, and the mach kernel contains a global that
+ // has the list of kexts to load
switch (header.filetype) {
case llvm::MachO::MH_DYLINKER:
// printf("0x%16.16" PRIx64 ": file_type = MH_DYLINKER\n", vaddr);
@@ -272,13 +270,10 @@ Status ProcessMachCore::DoLoadCore() {
} else {
m_core_aranges.Append(range_entry);
}
- // Some core files don't fill in the permissions correctly. If that is the
- // case
- // assume read + execute so clients don't think the memory is not
- // readable,
- // or executable. The memory isn't writable since this plug-in doesn't
- // implement
- // DoWriteMemory.
+ // Some core files don't fill in the permissions correctly. If that is
+ // the case assume read + execute so clients don't think the memory is
+ // not readable, or executable. The memory isn't writable since this
+ // plug-in doesn't implement DoWriteMemory.
uint32_t permissions = section->GetPermissions();
if (permissions == 0)
permissions = lldb::ePermissionsReadable | lldb::ePermissionsExecutable;
@@ -309,8 +304,8 @@ Status ProcessMachCore::DoLoadCore() {
}
// This checks for the presence of an LC_IDENT string in a core file;
- // LC_IDENT is very obsolete and should not be used in new code, but
- // if the load command is present, let's use the contents.
+ // LC_IDENT is very obsolete and should not be used in new code, but if the
+ // load command is present, let's use the contents.
std::string corefile_identifier = core_objfile->GetIdentifierString();
if (found_main_binary_definitively == false
&& corefile_identifier.find("Darwin Kernel") != std::string::npos) {
@@ -319,7 +314,7 @@ Status ProcessMachCore::DoLoadCore() {
if (corefile_identifier.find("UUID=") != std::string::npos) {
size_t p = corefile_identifier.find("UUID=") + strlen("UUID=");
std::string uuid_str = corefile_identifier.substr(p, 36);
- uuid.SetFromCString(uuid_str.c_str());
+ uuid.SetFromStringRef(uuid_str);
}
if (corefile_identifier.find("stext=") != std::string::npos) {
size_t p = corefile_identifier.find("stext=") + strlen("stext=");
@@ -342,16 +337,12 @@ Status ProcessMachCore::DoLoadCore() {
if (found_main_binary_definitively == false
&& (m_dyld_addr == LLDB_INVALID_ADDRESS
|| m_mach_kernel_addr == LLDB_INVALID_ADDRESS)) {
- // We need to locate the main executable in the memory ranges
- // we have in the core file. We need to search for both a user-process dyld
- // binary
+ // We need to locate the main executable in the memory ranges we have in
+ // the core file. We need to search for both a user-process dyld binary
// and a kernel binary in memory; we must look at all the pages in the
- // binary so
- // we don't miss one or the other. Step through all memory segments
- // searching for
- // a kernel binary and for a user process dyld -- we'll decide which to
- // prefer
- // later if both are present.
+ // binary so we don't miss one or the other. Step through all memory
+ // segments searching for a kernel binary and for a user process dyld --
+ // we'll decide which to prefer later if both are present.
const size_t num_core_aranges = m_core_aranges.GetSize();
for (size_t i = 0; i < num_core_aranges; ++i) {
@@ -369,13 +360,10 @@ Status ProcessMachCore::DoLoadCore() {
if (found_main_binary_definitively == false
&& m_mach_kernel_addr != LLDB_INVALID_ADDRESS) {
// In the case of multiple kernel images found in the core file via
- // exhaustive
- // search, we may not pick the correct one. See if the
- // DynamicLoaderDarwinKernel's
- // search heuristics might identify the correct one.
- // Most of the time, I expect the address from SearchForDarwinKernel() will
- // be the
- // same as the address we found via exhaustive search.
+ // exhaustive search, we may not pick the correct one. See if the
+ // DynamicLoaderDarwinKernel's search heuristics might identify the correct
+ // one. Most of the time, I expect the address from SearchForDarwinKernel()
+ // will be the same as the address we found via exhaustive search.
if (GetTarget().GetArchitecture().IsValid() == false &&
m_core_module_sp.get()) {
@@ -383,13 +371,11 @@ Status ProcessMachCore::DoLoadCore() {
}
// SearchForDarwinKernel will end up calling back into this this class in
- // the GetImageInfoAddress
- // method which will give it the m_mach_kernel_addr/m_dyld_addr it already
- // has. Save that aside
- // and set m_mach_kernel_addr/m_dyld_addr to an invalid address temporarily
- // so
- // DynamicLoaderDarwinKernel does a real search for the kernel using its own
- // heuristics.
+ // the GetImageInfoAddress method which will give it the
+ // m_mach_kernel_addr/m_dyld_addr it already has. Save that aside and set
+ // m_mach_kernel_addr/m_dyld_addr to an invalid address temporarily so
+ // DynamicLoaderDarwinKernel does a real search for the kernel using its
+ // own heuristics.
addr_t saved_mach_kernel_addr = m_mach_kernel_addr;
addr_t saved_user_dyld_addr = m_dyld_addr;
@@ -410,8 +396,8 @@ Status ProcessMachCore::DoLoadCore() {
}
}
- // If we found both a user-process dyld and a kernel binary, we need to decide
- // which to prefer.
+ // If we found both a user-process dyld and a kernel binary, we need to
+ // decide which to prefer.
if (GetCorefilePreference() == eKernelCorefile) {
if (m_mach_kernel_addr != LLDB_INVALID_ADDRESS) {
if (log)
@@ -444,18 +430,13 @@ Status ProcessMachCore::DoLoadCore() {
if (m_dyld_plugin_name != DynamicLoaderMacOSXDYLD::GetPluginNameStatic()) {
// For non-user process core files, the permissions on the core file
- // segments are usually
- // meaningless, they may be just "read", because we're dealing with kernel
- // coredumps or
- // early startup coredumps and the dumper is grabbing pages of memory
- // without knowing
- // what they are. If they aren't marked as "exeuctable", that can break the
- // unwinder
- // which will check a pc value to see if it is in an executable segment and
- // stop the
+ // segments are usually meaningless, they may be just "read", because we're
+ // dealing with kernel coredumps or early startup coredumps and the dumper
+ // is grabbing pages of memory without knowing what they are. If they
+ // aren't marked as "exeuctable", that can break the unwinder which will
+ // check a pc value to see if it is in an executable segment and stop the
// backtrace early if it is not ("executable" and "unknown" would both be
- // fine, but
- // "not executable" will break the unwinder).
+ // fine, but "not executable" will break the unwinder).
size_t core_range_infos_size = m_core_range_infos.GetSize();
for (size_t i = 0; i < core_range_infos_size; i++) {
VMRangeToPermissions::Entry *ent =
@@ -464,8 +445,8 @@ Status ProcessMachCore::DoLoadCore() {
}
}
- // Even if the architecture is set in the target, we need to override
- // it to match the core file which is always single arch.
+ // Even if the architecture is set in the target, we need to override it to
+ // match the core file which is always single arch.
ArchSpec arch(m_core_module_sp->GetArchitecture());
if (arch.GetCore() == ArchSpec::eCore_x86_32_i486) {
arch = Platform::GetAugmentedArchSpec(GetTarget().GetPlatform().get(), "i386");
@@ -488,8 +469,7 @@ bool ProcessMachCore::UpdateThreadList(ThreadList &old_thread_list,
ThreadList &new_thread_list) {
if (old_thread_list.GetSize(false) == 0) {
// Make up the thread the first time this is called so we can setup our one
- // and only
- // core thread state.
+ // and only core thread state.
ObjectFile *core_objfile = m_core_module_sp->GetObjectFile();
if (core_objfile) {
@@ -508,8 +488,8 @@ bool ProcessMachCore::UpdateThreadList(ThreadList &old_thread_list,
}
void ProcessMachCore::RefreshStateAfterStop() {
- // Let all threads recover from stopping and do any clean up based
- // on the previous thread state (if any).
+ // Let all threads recover from stopping and do any clean up based on the
+ // previous thread state (if any).
m_thread_list.RefreshStateAfterStop();
// SetThreadStopInfo (m_last_stop_packet);
}
@@ -529,8 +509,8 @@ bool ProcessMachCore::WarnBeforeDetach() const { return false; }
//------------------------------------------------------------------
size_t ProcessMachCore::ReadMemory(addr_t addr, void *buf, size_t size,
Status &error) {
- // Don't allow the caching that lldb_private::Process::ReadMemory does
- // since in core files we have it all cached our our core file anyway.
+ // Don't allow the caching that lldb_private::Process::ReadMemory does since
+ // in core files we have it all cached our our core file anyway.
return DoReadMemory(addr, buf, size, error);
}
@@ -546,19 +526,17 @@ size_t ProcessMachCore::DoReadMemory(addr_t addr, void *buf, size_t size,
// Address Size File off File size
// ---------- ---------- ---------- ----------
// LC_SEGMENT 0x000f6000 0x00001000 0x1d509ee8 0x00001000 --- --- 0
- // 0x00000000 __TEXT
- // LC_SEGMENT 0x0f600000 0x00100000 0x1d50aee8 0x00100000 --- --- 0
- // 0x00000000 __TEXT
- // LC_SEGMENT 0x000f7000 0x00001000 0x1d60aee8 0x00001000 --- --- 0
- // 0x00000000 __TEXT
+ // 0x00000000 __TEXT LC_SEGMENT 0x0f600000 0x00100000 0x1d50aee8 0x00100000
+ // --- --- 0 0x00000000 __TEXT LC_SEGMENT 0x000f7000 0x00001000
+ // 0x1d60aee8 0x00001000 --- --- 0 0x00000000 __TEXT
//
// Any if the user executes the following command:
//
// (lldb) mem read 0xf6ff0
//
- // We would attempt to read 32 bytes from 0xf6ff0 but would only
- // get 16 unless we loop through consecutive memory ranges that are
- // contiguous in the address space, but not in the file data.
+ // We would attempt to read 32 bytes from 0xf6ff0 but would only get 16
+ // unless we loop through consecutive memory ranges that are contiguous in
+ // the address space, but not in the file data.
//----------------------------------------------------------------------
while (bytes_read < size) {
const addr_t curr_addr = addr + bytes_read;
@@ -641,8 +619,8 @@ void ProcessMachCore::Initialize() {
}
addr_t ProcessMachCore::GetImageInfoAddress() {
- // If we found both a user-process dyld and a kernel binary, we need to decide
- // which to prefer.
+ // If we found both a user-process dyld and a kernel binary, we need to
+ // decide which to prefer.
if (GetCorefilePreference() == eKernelCorefile) {
if (m_mach_kernel_addr != LLDB_INVALID_ADDRESS) {
return m_mach_kernel_addr;
diff --git a/source/Plugins/Process/mach-core/ThreadMachCore.cpp b/source/Plugins/Process/mach-core/ThreadMachCore.cpp
index 2b44105c13b1a..c262dd47f9787 100644
--- a/source/Plugins/Process/mach-core/ThreadMachCore.cpp
+++ b/source/Plugins/Process/mach-core/ThreadMachCore.cpp
@@ -43,7 +43,7 @@ ThreadMachCore::~ThreadMachCore() { DestroyThread(); }
const char *ThreadMachCore::GetName() {
if (m_thread_name.empty())
- return NULL;
+ return nullptr;
return m_thread_name.c_str();
}
@@ -54,8 +54,8 @@ void ThreadMachCore::RefreshStateAfterStop() {
// context by the time this function gets called. The KDPRegisterContext
// class has been made smart enough to detect when it needs to invalidate
// which registers are valid by putting hooks in the register read and
- // register supply functions where they check the process stop ID and do
- // the right thing.
+ // register supply functions where they check the process stop ID and do the
+ // right thing.
const bool force = false;
GetRegisterContext()->InvalidateIfNeeded(force);
}
@@ -63,8 +63,8 @@ void ThreadMachCore::RefreshStateAfterStop() {
bool ThreadMachCore::ThreadIDIsValid(lldb::tid_t thread) { return thread != 0; }
lldb::RegisterContextSP ThreadMachCore::GetRegisterContext() {
- if (m_reg_context_sp.get() == NULL)
- m_reg_context_sp = CreateRegisterContextForFrame(NULL);
+ if (!m_reg_context_sp)
+ m_reg_context_sp = CreateRegisterContextForFrame(nullptr);
return m_reg_context_sp;
}
@@ -89,7 +89,7 @@ ThreadMachCore::CreateRegisterContextForFrame(StackFrame *frame) {
reg_ctx_sp = m_thread_reg_ctx_sp;
} else {
Unwind *unwinder = GetUnwinder();
- if (unwinder)
+ if (unwinder != nullptr)
reg_ctx_sp = unwinder->CreateRegisterContextForFrame(frame);
}
return reg_ctx_sp;
diff --git a/source/Plugins/Process/minidump/CMakeLists.txt b/source/Plugins/Process/minidump/CMakeLists.txt
index 61ce16830c9b9..b898ee1aa1444 100644
--- a/source/Plugins/Process/minidump/CMakeLists.txt
+++ b/source/Plugins/Process/minidump/CMakeLists.txt
@@ -1,5 +1,3 @@
-include_directories(../Utility)
-
add_lldb_library(lldbPluginProcessMinidump PLUGIN
MinidumpTypes.cpp
MinidumpParser.cpp
diff --git a/source/Plugins/Process/minidump/MinidumpParser.cpp b/source/Plugins/Process/minidump/MinidumpParser.cpp
index 36350fdb63986..9a979335e99e1 100644
--- a/source/Plugins/Process/minidump/MinidumpParser.cpp
+++ b/source/Plugins/Process/minidump/MinidumpParser.cpp
@@ -14,10 +14,13 @@
// Other libraries and framework includes
#include "lldb/Target/MemoryRegionInfo.h"
+#include "lldb/Utility/LLDBAssert.h"
// C includes
// C++ includes
+#include <algorithm>
#include <map>
+#include <vector>
using namespace lldb_private;
using namespace minidump;
@@ -27,47 +30,11 @@ MinidumpParser::Create(const lldb::DataBufferSP &data_buf_sp) {
if (data_buf_sp->GetByteSize() < sizeof(MinidumpHeader)) {
return llvm::None;
}
-
- llvm::ArrayRef<uint8_t> header_data(data_buf_sp->GetBytes(),
- sizeof(MinidumpHeader));
- const MinidumpHeader *header = MinidumpHeader::Parse(header_data);
-
- if (header == nullptr) {
- return llvm::None;
- }
-
- lldb::offset_t directory_list_offset = header->stream_directory_rva;
- // check if there is enough data for the parsing of the directory list
- if ((directory_list_offset +
- sizeof(MinidumpDirectory) * header->streams_count) >
- data_buf_sp->GetByteSize()) {
- return llvm::None;
- }
-
- const MinidumpDirectory *directory = nullptr;
- Status error;
- llvm::ArrayRef<uint8_t> directory_data(
- data_buf_sp->GetBytes() + directory_list_offset,
- sizeof(MinidumpDirectory) * header->streams_count);
- llvm::DenseMap<uint32_t, MinidumpLocationDescriptor> directory_map;
-
- for (uint32_t i = 0; i < header->streams_count; ++i) {
- error = consumeObject(directory_data, directory);
- if (error.Fail()) {
- return llvm::None;
- }
- directory_map[static_cast<const uint32_t>(directory->stream_type)] =
- directory->location;
- }
-
- return MinidumpParser(data_buf_sp, header, std::move(directory_map));
+ return MinidumpParser(data_buf_sp);
}
-MinidumpParser::MinidumpParser(
- const lldb::DataBufferSP &data_buf_sp, const MinidumpHeader *header,
- llvm::DenseMap<uint32_t, MinidumpLocationDescriptor> &&directory_map)
- : m_data_sp(data_buf_sp), m_header(header), m_directory_map(directory_map) {
-}
+MinidumpParser::MinidumpParser(const lldb::DataBufferSP &data_buf_sp)
+ : m_data_sp(data_buf_sp) {}
llvm::ArrayRef<uint8_t> MinidumpParser::GetData() {
return llvm::ArrayRef<uint8_t>(m_data_sp->GetBytes(),
@@ -96,6 +63,31 @@ llvm::Optional<std::string> MinidumpParser::GetMinidumpString(uint32_t rva) {
return parseMinidumpString(arr_ref);
}
+UUID MinidumpParser::GetModuleUUID(const MinidumpModule *module) {
+ auto cv_record =
+ GetData().slice(module->CV_record.rva, module->CV_record.data_size);
+
+ // Read the CV record signature
+ const llvm::support::ulittle32_t *signature = nullptr;
+ Status error = consumeObject(cv_record, signature);
+ if (error.Fail())
+ return UUID();
+
+ const CvSignature cv_signature =
+ static_cast<CvSignature>(static_cast<const uint32_t>(*signature));
+
+ if (cv_signature == CvSignature::Pdb70) {
+ // PDB70 record
+ const CvRecordPdb70 *pdb70_uuid = nullptr;
+ Status error = consumeObject(cv_record, pdb70_uuid);
+ if (!error.Fail())
+ return UUID::fromData(pdb70_uuid, sizeof(*pdb70_uuid));
+ } else if (cv_signature == CvSignature::ElfBuildId)
+ return UUID::fromData(cv_record);
+
+ return UUID();
+}
+
llvm::ArrayRef<MinidumpThread> MinidumpParser::GetThreads() {
llvm::ArrayRef<uint8_t> data = GetStream(MinidumpStreamType::ThreadList);
@@ -115,12 +107,12 @@ MinidumpParser::GetThreadContext(const MinidumpThread &td) {
llvm::ArrayRef<uint8_t>
MinidumpParser::GetThreadContextWow64(const MinidumpThread &td) {
- // On Windows, a 32-bit process can run on a 64-bit machine under
- // WOW64. If the minidump was captured with a 64-bit debugger, then
- // the CONTEXT we just grabbed from the mini_dump_thread is the one
- // for the 64-bit "native" process rather than the 32-bit "guest"
- // process we care about. In this case, we can get the 32-bit CONTEXT
- // from the TEB (Thread Environment Block) of the 64-bit process.
+ // On Windows, a 32-bit process can run on a 64-bit machine under WOW64. If
+ // the minidump was captured with a 64-bit debugger, then the CONTEXT we just
+ // grabbed from the mini_dump_thread is the one for the 64-bit "native"
+ // process rather than the 32-bit "guest" process we care about. In this
+ // case, we can get the 32-bit CONTEXT from the TEB (Thread Environment
+ // Block) of the 64-bit process.
auto teb_mem = GetMemory(td.teb, sizeof(TEB64));
if (teb_mem.empty())
return {};
@@ -130,9 +122,9 @@ MinidumpParser::GetThreadContextWow64(const MinidumpThread &td) {
if (error.Fail())
return {};
- // Slot 1 of the thread-local storage in the 64-bit TEB points to a
- // structure that includes the 32-bit CONTEXT (after a ULONG).
- // See: https://msdn.microsoft.com/en-us/library/ms681670.aspx
+ // Slot 1 of the thread-local storage in the 64-bit TEB points to a structure
+ // that includes the 32-bit CONTEXT (after a ULONG). See:
+ // https://msdn.microsoft.com/en-us/library/ms681670.aspx
auto context =
GetMemory(wow64teb->tls_slots[1] + 4, sizeof(MinidumpContext_x86_32));
if (context.size() < sizeof(MinidumpContext_x86_32))
@@ -334,10 +326,10 @@ MinidumpParser::FindMemoryRange(lldb::addr_t addr) {
}
}
- // Some Minidumps have a Memory64ListStream that captures all the heap
- // memory (full-memory Minidumps). We can't exactly use the same loop as
- // above, because the Minidump uses slightly different data structures to
- // describe those
+ // Some Minidumps have a Memory64ListStream that captures all the heap memory
+ // (full-memory Minidumps). We can't exactly use the same loop as above,
+ // because the Minidump uses slightly different data structures to describe
+ // those
if (!data64.empty()) {
llvm::ArrayRef<MinidumpMemoryDescriptor64> memory64_list;
@@ -377,8 +369,8 @@ llvm::ArrayRef<uint8_t> MinidumpParser::GetMemory(lldb::addr_t addr,
return {};
// There's at least some overlap between the beginning of the desired range
- // (addr) and the current range. Figure out where the overlap begins and
- // how much overlap there is.
+ // (addr) and the current range. Figure out where the overlap begins and how
+ // much overlap there is.
const size_t offset = addr - range->start;
@@ -456,3 +448,109 @@ MinidumpParser::GetMemoryRegionInfo(lldb::addr_t load_addr) {
// appear truncated.
return info;
}
+
+Status MinidumpParser::Initialize() {
+ Status error;
+
+ lldbassert(m_directory_map.empty());
+
+ llvm::ArrayRef<uint8_t> header_data(m_data_sp->GetBytes(),
+ sizeof(MinidumpHeader));
+ const MinidumpHeader *header = MinidumpHeader::Parse(header_data);
+ if (header == nullptr) {
+ error.SetErrorString("invalid minidump: can't parse the header");
+ return error;
+ }
+
+ // A minidump without at least one stream is clearly ill-formed
+ if (header->streams_count == 0) {
+ error.SetErrorString("invalid minidump: no streams present");
+ return error;
+ }
+
+ struct FileRange {
+ uint32_t offset = 0;
+ uint32_t size = 0;
+
+ FileRange(uint32_t offset, uint32_t size) : offset(offset), size(size) {}
+ uint32_t end() const { return offset + size; }
+ };
+
+ const uint32_t file_size = m_data_sp->GetByteSize();
+
+ // Build a global minidump file map, checking for:
+ // - overlapping streams/data structures
+ // - truncation (streams pointing past the end of file)
+ std::vector<FileRange> minidump_map;
+
+ // Add the minidump header to the file map
+ if (sizeof(MinidumpHeader) > file_size) {
+ error.SetErrorString("invalid minidump: truncated header");
+ return error;
+ }
+ minidump_map.emplace_back( 0, sizeof(MinidumpHeader) );
+
+ // Add the directory entries to the file map
+ FileRange directory_range(header->stream_directory_rva,
+ header->streams_count *
+ sizeof(MinidumpDirectory));
+ if (directory_range.end() > file_size) {
+ error.SetErrorString("invalid minidump: truncated streams directory");
+ return error;
+ }
+ minidump_map.push_back(directory_range);
+
+ // Parse stream directory entries
+ llvm::ArrayRef<uint8_t> directory_data(
+ m_data_sp->GetBytes() + directory_range.offset, directory_range.size);
+ for (uint32_t i = 0; i < header->streams_count; ++i) {
+ const MinidumpDirectory *directory_entry = nullptr;
+ error = consumeObject(directory_data, directory_entry);
+ if (error.Fail())
+ return error;
+ if (directory_entry->stream_type == 0) {
+ // Ignore dummy streams (technically ill-formed, but a number of
+ // existing minidumps seem to contain such streams)
+ if (directory_entry->location.data_size == 0)
+ continue;
+ error.SetErrorString("invalid minidump: bad stream type");
+ return error;
+ }
+ // Update the streams map, checking for duplicate stream types
+ if (!m_directory_map
+ .insert({directory_entry->stream_type, directory_entry->location})
+ .second) {
+ error.SetErrorString("invalid minidump: duplicate stream type");
+ return error;
+ }
+ // Ignore the zero-length streams for layout checks
+ if (directory_entry->location.data_size != 0) {
+ minidump_map.emplace_back(directory_entry->location.rva,
+ directory_entry->location.data_size);
+ }
+ }
+
+ // Sort the file map ranges by start offset
+ std::sort(minidump_map.begin(), minidump_map.end(),
+ [](const FileRange &a, const FileRange &b) {
+ return a.offset < b.offset;
+ });
+
+ // Check for overlapping streams/data structures
+ for (size_t i = 1; i < minidump_map.size(); ++i) {
+ const auto &prev_range = minidump_map[i - 1];
+ if (prev_range.end() > minidump_map[i].offset) {
+ error.SetErrorString("invalid minidump: overlapping streams");
+ return error;
+ }
+ }
+
+ // Check for streams past the end of file
+ const auto &last_range = minidump_map.back();
+ if (last_range.end() > file_size) {
+ error.SetErrorString("invalid minidump: truncated stream");
+ return error;
+ }
+
+ return error;
+}
diff --git a/source/Plugins/Process/minidump/MinidumpParser.h b/source/Plugins/Process/minidump/MinidumpParser.h
index b7329ffc00289..49b1eef14de58 100644
--- a/source/Plugins/Process/minidump/MinidumpParser.h
+++ b/source/Plugins/Process/minidump/MinidumpParser.h
@@ -17,6 +17,7 @@
#include "lldb/Utility/ArchSpec.h"
#include "lldb/Utility/DataBuffer.h"
#include "lldb/Utility/Status.h"
+#include "lldb/Utility/UUID.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/DenseMap.h"
@@ -54,6 +55,8 @@ public:
llvm::Optional<std::string> GetMinidumpString(uint32_t rva);
+ UUID GetModuleUUID(const MinidumpModule* module);
+
llvm::ArrayRef<MinidumpThread> GetThreads();
llvm::ArrayRef<uint8_t> GetThreadContext(const MinidumpThread &td);
@@ -86,14 +89,15 @@ public:
llvm::Optional<MemoryRegionInfo> GetMemoryRegionInfo(lldb::addr_t);
+ // Perform consistency checks and initialize internal data structures
+ Status Initialize();
+
+private:
+ MinidumpParser(const lldb::DataBufferSP &data_buf_sp);
+
private:
lldb::DataBufferSP m_data_sp;
- const MinidumpHeader *m_header;
llvm::DenseMap<uint32_t, MinidumpLocationDescriptor> m_directory_map;
-
- MinidumpParser(
- const lldb::DataBufferSP &data_buf_sp, const MinidumpHeader *header,
- llvm::DenseMap<uint32_t, MinidumpLocationDescriptor> &&directory_map);
};
} // end namespace minidump
diff --git a/source/Plugins/Process/minidump/MinidumpTypes.cpp b/source/Plugins/Process/minidump/MinidumpTypes.cpp
index 24ce3f94c0941..049704ba80caf 100644
--- a/source/Plugins/Process/minidump/MinidumpTypes.cpp
+++ b/source/Plugins/Process/minidump/MinidumpTypes.cpp
@@ -33,9 +33,6 @@ const MinidumpHeader *MinidumpHeader::Parse(llvm::ArrayRef<uint8_t> &data) {
version != MinidumpHeaderConstants::Version)
return nullptr;
- // TODO check for max number of streams ?
- // TODO more sanity checks ?
-
return header;
}
@@ -44,19 +41,23 @@ llvm::Optional<std::string>
lldb_private::minidump::parseMinidumpString(llvm::ArrayRef<uint8_t> &data) {
std::string result;
- const uint32_t *source_length;
- Status error = consumeObject(data, source_length);
- if (error.Fail() || *source_length > data.size() || *source_length % 2 != 0)
+ const uint32_t *source_length_ptr;
+ Status error = consumeObject(data, source_length_ptr);
+
+ // Copy non-aligned source_length data into aligned memory.
+ uint32_t source_length;
+ std::memcpy(&source_length, source_length_ptr, sizeof(source_length));
+
+ if (error.Fail() || source_length > data.size() || source_length % 2 != 0)
return llvm::None;
auto source_start = reinterpret_cast<const llvm::UTF16 *>(data.data());
- // source_length is the length of the string in bytes
- // we need the length of the string in UTF-16 characters/code points (16 bits
- // per char)
- // that's why it's divided by 2
- const auto source_end = source_start + (*source_length) / 2;
+ // source_length is the length of the string in bytes we need the length of
+ // the string in UTF-16 characters/code points (16 bits per char) that's why
+ // it's divided by 2
+ const auto source_end = source_start + source_length / 2;
// resize to worst case length
- result.resize(UNI_MAX_UTF8_BYTES_PER_CODE_POINT * (*source_length) / 2);
+ result.resize(UNI_MAX_UTF8_BYTES_PER_CODE_POINT * source_length / 2);
auto result_start = reinterpret_cast<llvm::UTF8 *>(&result[0]);
const auto result_end = result_start + result.size();
llvm::ConvertUTF16toUTF8(&source_start, source_end, &result_start, result_end,
@@ -80,11 +81,17 @@ const MinidumpThread *MinidumpThread::Parse(llvm::ArrayRef<uint8_t> &data) {
llvm::ArrayRef<MinidumpThread>
MinidumpThread::ParseThreadList(llvm::ArrayRef<uint8_t> &data) {
+ const auto orig_size = data.size();
const llvm::support::ulittle32_t *thread_count;
Status error = consumeObject(data, thread_count);
if (error.Fail() || *thread_count * sizeof(MinidumpThread) > data.size())
return {};
+ // Compilers might end up padding an extra 4 bytes depending on how the
+ // structure is padded by the compiler and the #pragma pack settings.
+ if (4 + *thread_count * sizeof(MinidumpThread) < orig_size)
+ data = data.drop_front(4);
+
return llvm::ArrayRef<MinidumpThread>(
reinterpret_cast<const MinidumpThread *>(data.data()), *thread_count);
}
@@ -156,12 +163,17 @@ const MinidumpModule *MinidumpModule::Parse(llvm::ArrayRef<uint8_t> &data) {
llvm::ArrayRef<MinidumpModule>
MinidumpModule::ParseModuleList(llvm::ArrayRef<uint8_t> &data) {
-
+ const auto orig_size = data.size();
const llvm::support::ulittle32_t *modules_count;
Status error = consumeObject(data, modules_count);
if (error.Fail() || *modules_count * sizeof(MinidumpModule) > data.size())
return {};
-
+
+ // Compilers might end up padding an extra 4 bytes depending on how the
+ // structure is padded by the compiler and the #pragma pack settings.
+ if (4 + *modules_count * sizeof(MinidumpModule) < orig_size)
+ data = data.drop_front(4);
+
return llvm::ArrayRef<MinidumpModule>(
reinterpret_cast<const MinidumpModule *>(data.data()), *modules_count);
}
@@ -179,11 +191,17 @@ MinidumpExceptionStream::Parse(llvm::ArrayRef<uint8_t> &data) {
llvm::ArrayRef<MinidumpMemoryDescriptor>
MinidumpMemoryDescriptor::ParseMemoryList(llvm::ArrayRef<uint8_t> &data) {
+ const auto orig_size = data.size();
const llvm::support::ulittle32_t *mem_ranges_count;
Status error = consumeObject(data, mem_ranges_count);
if (error.Fail() ||
*mem_ranges_count * sizeof(MinidumpMemoryDescriptor) > data.size())
return {};
+
+ // Compilers might end up padding an extra 4 bytes depending on how the
+ // structure is padded by the compiler and the #pragma pack settings.
+ if (4 + *mem_ranges_count * sizeof(MinidumpMemoryDescriptor) < orig_size)
+ data = data.drop_front(4);
return llvm::makeArrayRef(
reinterpret_cast<const MinidumpMemoryDescriptor *>(data.data()),
diff --git a/source/Plugins/Process/minidump/MinidumpTypes.h b/source/Plugins/Process/minidump/MinidumpTypes.h
index 6de4f55a769d8..e83089865b9e0 100644
--- a/source/Plugins/Process/minidump/MinidumpTypes.h
+++ b/source/Plugins/Process/minidump/MinidumpTypes.h
@@ -43,6 +43,21 @@ enum class MinidumpHeaderConstants : uint32_t {
};
+enum class CvSignature : uint32_t {
+ Pdb70 = 0x53445352, // RSDS
+ ElfBuildId = 0x4270454c, // BpEL (Breakpad/Crashpad minidumps)
+};
+
+// Reference:
+// https://crashpad.chromium.org/doxygen/structcrashpad_1_1CodeViewRecordPDB70.html
+struct CvRecordPdb70 {
+ uint8_t Uuid[16];
+ llvm::support::ulittle32_t Age;
+ // char PDBFileName[];
+};
+static_assert(sizeof(CvRecordPdb70) == 20,
+ "sizeof CvRecordPdb70 is not correct!");
+
// Reference:
// https://msdn.microsoft.com/en-us/library/windows/desktop/ms680394.aspx
enum class MinidumpStreamType : uint32_t {
diff --git a/source/Plugins/Process/minidump/ProcessMinidump.cpp b/source/Plugins/Process/minidump/ProcessMinidump.cpp
index d4d65c044eabe..b43f22382eaca 100644
--- a/source/Plugins/Process/minidump/ProcessMinidump.cpp
+++ b/source/Plugins/Process/minidump/ProcessMinidump.cpp
@@ -19,6 +19,7 @@
#include "lldb/Core/State.h"
#include "lldb/Target/DynamicLoader.h"
#include "lldb/Target/MemoryRegionInfo.h"
+#include "lldb/Target/SectionLoadList.h"
#include "lldb/Target/Target.h"
#include "lldb/Target/UnixSignals.h"
#include "lldb/Utility/DataBufferLLVM.h"
@@ -31,9 +32,56 @@
// C includes
// C++ includes
+using namespace lldb;
using namespace lldb_private;
using namespace minidump;
+//------------------------------------------------------------------
+/// A placeholder module used for minidumps, where the original
+/// object files may not be available (so we can't parse the object
+/// files to extract the set of sections/segments)
+///
+/// This placeholder module has a single synthetic section (.module_image)
+/// which represents the module memory range covering the whole module.
+//------------------------------------------------------------------
+class PlaceholderModule : public Module {
+public:
+ PlaceholderModule(const ModuleSpec &module_spec) :
+ Module(module_spec.GetFileSpec(), module_spec.GetArchitecture()) {
+ if (module_spec.GetUUID().IsValid())
+ SetUUID(module_spec.GetUUID());
+ }
+
+ // Creates a synthetic module section covering the whole module image (and
+ // sets the section load address as well)
+ void CreateImageSection(const MinidumpModule *module, Target& target) {
+ const ConstString section_name(".module_image");
+ lldb::SectionSP section_sp(new Section(
+ shared_from_this(), // Module to which this section belongs.
+ nullptr, // ObjectFile
+ 0, // Section ID.
+ section_name, // Section name.
+ eSectionTypeContainer, // Section type.
+ module->base_of_image, // VM address.
+ module->size_of_image, // VM size in bytes of this section.
+ 0, // Offset of this section in the file.
+ module->size_of_image, // Size of the section as found in the file.
+ 12, // Alignment of the section (log2)
+ 0, // Flags for this section.
+ 1)); // Number of host bytes per target byte
+ section_sp->SetPermissions(ePermissionsExecutable | ePermissionsReadable);
+ GetSectionList()->AddSection(section_sp);
+ target.GetSectionLoadList().SetSectionLoadAddress(
+ section_sp, module->base_of_image);
+ }
+
+ ObjectFile *GetObjectFile() override { return nullptr; }
+
+ SectionList *GetSectionList() override {
+ return Module::GetUnifiedSectionList();
+ }
+};
+
ConstString ProcessMinidump::GetPluginNameStatic() {
static ConstString g_name("minidump");
return g_name;
@@ -57,7 +105,7 @@ lldb::ProcessSP ProcessMinidump::CreateInstance(lldb::TargetSP target_sp,
if (!DataPtr)
return nullptr;
- assert(DataPtr->GetByteSize() == header_size);
+ lldbassert(DataPtr->GetByteSize() == header_size);
// first, only try to parse the header, beacuse we need to be fast
llvm::ArrayRef<uint8_t> HeaderBytes = DataPtr->GetData();
@@ -92,10 +140,10 @@ ProcessMinidump::ProcessMinidump(lldb::TargetSP target_sp,
ProcessMinidump::~ProcessMinidump() {
Clear();
- // We need to call finalize on the process before destroying ourselves
- // to make sure all of the broadcaster cleanup goes as planned. If we
- // destruct this class, then Process::~Process() might have problems
- // trying to fully destroy the broadcaster.
+ // We need to call finalize on the process before destroying ourselves to
+ // make sure all of the broadcaster cleanup goes as planned. If we destruct
+ // this class, then Process::~Process() might have problems trying to fully
+ // destroy the broadcaster.
Finalize();
}
@@ -116,10 +164,29 @@ void ProcessMinidump::Terminate() {
Status ProcessMinidump::DoLoadCore() {
Status error;
+ // Minidump parser initialization & consistency checks
+ error = m_minidump_parser.Initialize();
+ if (error.Fail())
+ return error;
+
+ // Do we support the minidump's architecture?
+ ArchSpec arch = GetArchitecture();
+ switch (arch.GetMachine()) {
+ case llvm::Triple::x86:
+ case llvm::Triple::x86_64:
+ // supported
+ break;
+
+ default:
+ error.SetErrorStringWithFormat("unsupported minidump architecture: %s",
+ arch.GetArchitectureName());
+ return error;
+ }
+
m_thread_list = m_minidump_parser.GetThreads();
m_active_exception = m_minidump_parser.GetExceptionStream();
ReadModuleList();
- GetTarget().SetArchitecture(GetArchitecture());
+ GetTarget().SetArchitecture(arch);
llvm::Optional<lldb::pid_t> pid = m_minidump_parser.GetPid();
if (!pid) {
@@ -185,8 +252,8 @@ bool ProcessMinidump::WarnBeforeDetach() const { return false; }
size_t ProcessMinidump::ReadMemory(lldb::addr_t addr, void *buf, size_t size,
Status &error) {
- // Don't allow the caching that lldb_private::Process::ReadMemory does
- // since we have it all cached in our dump file anyway.
+ // Don't allow the caching that lldb_private::Process::ReadMemory does since
+ // we have it all cached in our dump file anyway.
return DoReadMemory(addr, buf, size, error);
}
@@ -276,12 +343,25 @@ void ProcessMinidump::ReadModuleList() {
m_is_wow64 = true;
}
- const auto file_spec = FileSpec(name.getValue(), true);
- ModuleSpec module_spec = file_spec;
+ const auto uuid = m_minidump_parser.GetModuleUUID(module);
+ const auto file_spec =
+ FileSpec(name.getValue(), true, GetArchitecture().GetTriple());
+ ModuleSpec module_spec(file_spec, uuid);
Status error;
lldb::ModuleSP module_sp = GetTarget().GetSharedModule(module_spec, &error);
if (!module_sp || error.Fail()) {
- continue;
+ // We failed to locate a matching local object file. Fortunately, the
+ // minidump format encodes enough information about each module's memory
+ // range to allow us to create placeholder modules.
+ //
+ // This enables most LLDB functionality involving address-to-module
+ // translations (ex. identifing the module for a stack frame PC) and
+ // modules/sections commands (ex. target modules list, ...)
+ auto placeholder_module =
+ std::make_shared<PlaceholderModule>(module_spec);
+ placeholder_module->CreateImageSection(module, GetTarget());
+ module_sp = placeholder_module;
+ GetTarget().GetImages().Append(module_sp);
}
if (log) {
diff --git a/source/Plugins/Process/minidump/ProcessMinidump.h b/source/Plugins/Process/minidump/ProcessMinidump.h
index 4b91d1ba396a4..d65ada9009a7e 100644
--- a/source/Plugins/Process/minidump/ProcessMinidump.h
+++ b/source/Plugins/Process/minidump/ProcessMinidump.h
@@ -61,6 +61,8 @@ public:
uint32_t GetPluginVersion() override;
+ SystemRuntime *GetSystemRuntime() override { return nullptr; }
+
Status DoDestroy() override;
void RefreshStateAfterStop() override;