[lldb][NFC] Fix all formatting errors in .cpp file headers
Summary:
A *.cpp file header in LLDB (and in LLDB) should like this:
```
//===-- TestUtilities.cpp -------------------------------------------------===//
```
However in LLDB most of our source files have arbitrary changes to this format and
these changes are spreading through LLDB as folks usually just use the existing
source files as templates for their new files (most notably the unnecessary
editor language indicator `-*- C++ -*-` is spreading and in every review
someone is pointing out that this is wrong, resulting in people pointing out that this
is done in the same way in other files).
This patch removes most of these inconsistencies including the editor language indicators,
all the different missing/additional '-' characters, files that center the file name, missing
trailing `===//` (mostly caused by clang-format breaking the line).
Reviewers: aprantl, espindola, jfb, shafik, JDevlieghere
Reviewed By: JDevlieghere
Subscribers: dexonsmith, wuzish, emaste, sdardis, nemanjai, kbarton, MaskRay, atanasyan, arphaman, jfb, abidh, jsji, JDevlieghere, usaxena95, lldb-commits
Tags: #lldb
Differential Revision: https://reviews.llvm.org/D73258
2020-01-24 15:23:27 +08:00
|
|
|
//===-- HostProcessPosix.cpp ----------------------------------------------===//
|
2014-08-28 04:15:30 +08:00
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2014-08-28 04:15:30 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2014-10-15 05:55:08 +08:00
|
|
|
#include "lldb/Host/Host.h"
|
2014-08-28 04:15:30 +08:00
|
|
|
#include "lldb/Host/FileSystem.h"
|
|
|
|
#include "lldb/Host/posix/HostProcessPosix.h"
|
|
|
|
|
|
|
|
#include "llvm/ADT/STLExtras.h"
|
|
|
|
|
2017-07-18 21:14:01 +08:00
|
|
|
#include <csignal>
|
2014-08-28 04:15:30 +08:00
|
|
|
#include <limits.h>
|
2017-07-18 21:14:01 +08:00
|
|
|
#include <unistd.h>
|
2014-08-28 04:15:30 +08:00
|
|
|
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
2014-09-12 06:22:16 +08:00
|
|
|
namespace {
|
|
|
|
const int kInvalidPosixProcess = 0;
|
|
|
|
}
|
2014-08-28 04:44:26 +08:00
|
|
|
|
2014-08-28 04:15:30 +08:00
|
|
|
HostProcessPosix::HostProcessPosix()
|
2014-09-12 06:22:16 +08:00
|
|
|
: HostNativeProcessBase(kInvalidPosixProcess) {}
|
2014-08-28 04:15:30 +08:00
|
|
|
|
2014-09-12 06:42:58 +08:00
|
|
|
HostProcessPosix::HostProcessPosix(lldb::process_t process)
|
|
|
|
: HostNativeProcessBase(process) {}
|
|
|
|
|
2014-08-28 04:15:30 +08:00
|
|
|
HostProcessPosix::~HostProcessPosix() {}
|
|
|
|
|
2017-05-12 12:51:55 +08:00
|
|
|
Status HostProcessPosix::Signal(int signo) const {
|
2014-09-12 06:22:16 +08:00
|
|
|
if (m_process == kInvalidPosixProcess) {
|
2017-05-12 12:51:55 +08:00
|
|
|
Status error;
|
2014-08-28 04:15:30 +08:00
|
|
|
error.SetErrorString("HostProcessPosix refers to an invalid process");
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2014-09-12 06:22:16 +08:00
|
|
|
return HostProcessPosix::Signal(m_process, signo);
|
2014-08-28 04:15:30 +08:00
|
|
|
}
|
|
|
|
|
2017-05-12 12:51:55 +08:00
|
|
|
Status HostProcessPosix::Signal(lldb::process_t process, int signo) {
|
|
|
|
Status error;
|
2014-08-28 04:15:30 +08:00
|
|
|
|
2014-09-12 06:22:16 +08:00
|
|
|
if (-1 == ::kill(process, signo))
|
2014-08-28 04:15:30 +08:00
|
|
|
error.SetErrorToErrno();
|
|
|
|
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2017-05-12 12:51:55 +08:00
|
|
|
Status HostProcessPosix::Terminate() { return Signal(SIGKILL); }
|
2014-09-12 06:22:16 +08:00
|
|
|
|
2017-05-12 12:51:55 +08:00
|
|
|
Status HostProcessPosix::GetMainModule(FileSpec &file_spec) const {
|
|
|
|
Status error;
|
2014-08-28 04:15:30 +08:00
|
|
|
|
|
|
|
// Use special code here because proc/[pid]/exe is a symbolic link.
|
|
|
|
char link_path[PATH_MAX];
|
2015-05-30 03:52:29 +08:00
|
|
|
if (snprintf(link_path, PATH_MAX, "/proc/%" PRIu64 "/exe", m_process) != 1) {
|
|
|
|
error.SetErrorString("Unable to build /proc/<pid>/exe string");
|
2014-08-28 04:15:30 +08:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2018-11-02 05:05:36 +08:00
|
|
|
error = FileSystem::Instance().Readlink(FileSpec(link_path), file_spec);
|
2014-08-28 04:15:30 +08:00
|
|
|
if (!error.Success())
|
|
|
|
return error;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2014-08-28 04:15:30 +08:00
|
|
|
// If the binary has been deleted, the link name has " (deleted)" appended.
|
|
|
|
// Remove if there.
|
2015-05-30 03:52:29 +08:00
|
|
|
if (file_spec.GetFilename().GetStringRef().endswith(" (deleted)")) {
|
|
|
|
const char *filename = file_spec.GetFilename().GetCString();
|
2014-08-28 04:15:30 +08:00
|
|
|
static const size_t deleted_len = strlen(" (deleted)");
|
|
|
|
const size_t len = file_spec.GetFilename().GetLength();
|
2015-05-30 03:52:29 +08:00
|
|
|
file_spec.GetFilename().SetCStringWithLength(filename, len - deleted_len);
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2014-09-12 06:22:16 +08:00
|
|
|
return error;
|
2014-08-28 04:15:30 +08:00
|
|
|
}
|
|
|
|
|
2014-09-12 06:42:58 +08:00
|
|
|
lldb::pid_t HostProcessPosix::GetProcessId() const { return m_process; }
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2014-08-28 04:15:30 +08:00
|
|
|
bool HostProcessPosix::IsRunning() const {
|
2014-10-01 00:56:40 +08:00
|
|
|
if (m_process == kInvalidPosixProcess)
|
|
|
|
return false;
|
|
|
|
|
2014-08-28 04:15:30 +08:00
|
|
|
// Send this process the null signal. If it succeeds the process is running.
|
2017-05-12 12:51:55 +08:00
|
|
|
Status error = Signal(0);
|
2014-08-28 04:15:30 +08:00
|
|
|
return error.Success();
|
|
|
|
}
|
2014-10-15 05:55:08 +08:00
|
|
|
|
2019-07-08 15:07:05 +08:00
|
|
|
llvm::Expected<HostThread> HostProcessPosix::StartMonitoring(
|
2016-05-12 00:59:04 +08:00
|
|
|
const Host::MonitorChildProcessCallback &callback, bool monitor_signals) {
|
|
|
|
return Host::StartMonitoringChildProcess(callback, m_process,
|
|
|
|
monitor_signals);
|
2014-10-15 05:55:08 +08:00
|
|
|
}
|