[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
|
|
|
//===-- SystemInitializerCommon.cpp ---------------------------------------===//
|
2015-04-01 05:03:22 +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
|
2015-04-01 05:03:22 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "lldb/Initialization/SystemInitializerCommon.h"
|
|
|
|
|
|
|
|
#include "Plugins/Process/gdb-remote/ProcessGDBRemoteLog.h"
|
2018-11-01 05:49:27 +08:00
|
|
|
#include "lldb/Host/FileSystem.h"
|
2015-04-01 05:03:22 +08:00
|
|
|
#include "lldb/Host/Host.h"
|
2019-04-10 12:57:18 +08:00
|
|
|
#include "lldb/Host/Socket.h"
|
2017-03-04 04:56:28 +08:00
|
|
|
#include "lldb/Utility/Log.h"
|
2020-08-22 15:36:32 +08:00
|
|
|
#include "lldb/Utility/ReproducerProvider.h"
|
2017-06-29 22:32:17 +08:00
|
|
|
#include "lldb/Utility/Timer.h"
|
2019-06-13 12:35:22 +08:00
|
|
|
#include "lldb/lldb-private.h"
|
2015-04-01 05:03:22 +08:00
|
|
|
|
2017-03-22 01:26:55 +08:00
|
|
|
#if defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__)
|
2015-04-01 05:03:22 +08:00
|
|
|
#include "Plugins/Process/POSIX/ProcessPOSIXLog.h"
|
|
|
|
#endif
|
|
|
|
|
2019-05-03 03:25:18 +08:00
|
|
|
#if defined(_WIN32)
|
2015-10-29 02:21:45 +08:00
|
|
|
#include "Plugins/Process/Windows/Common/ProcessWindowsLog.h"
|
Add support for reading line tables from PDB files.
PDB is Microsoft's debug information format, and although we
cannot yet generate it, we still must be able to consume it.
Reason for this is that debug information for system libraries
(e.g. kernel32, C Runtime Library, etc) only have debug info
in PDB format, so in order to be able to support debugging
of system code, we must support it.
Currently this code should compile on every platform, but on
non-Windows platforms the PDB plugin will return 0 capabilities,
meaning that for now PDB is only supported on Windows. This
may change in the future, but the API is designed in such a way
that this will require few (if any) changes on the LLDB side.
In the future we can just flip a switch and everything will
work.
This patch only adds support for line tables. It does not return
information about functions, types, global variables, or anything
else. This functionality will be added in a followup patch.
Differential Revision: http://reviews.llvm.org/D17363
Reviewed by: Greg Clayton
llvm-svn: 262528
2016-03-03 06:05:52 +08:00
|
|
|
#include "lldb/Host/windows/windows.h"
|
2019-08-07 02:20:43 +08:00
|
|
|
#include <crtdbg.h>
|
2015-04-01 05:03:22 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "llvm/Support/TargetSelect.h"
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
using namespace lldb_private;
|
2018-12-04 01:28:29 +08:00
|
|
|
using namespace lldb_private::repro;
|
2015-04-01 05:03:22 +08:00
|
|
|
|
[lldb] Fix shared library directory computation on windows
Our code for locating the shared library directory works via dladdr (or
the windows equivalent) to locate the path of an address known to reside
in liblldb. This works great for C++ programs, but there's a catch.
When (lib)lldb is used from python (like in our test suite), this dladdr
call will return a path to the _lldb.so (or such) file in the python
directory. To compensate for this, we have code which attempts to
resolve this symlink, to ensure we get the canonical location. However,
here's the second catch.
On windows, this file is not a symlink (but a copy), so this logic
fails. Since most of our other paths are derived from the liblldb
location, all of these paths will be wrong, when running the test suite.
One effect of this was the failure to find lldb-server in D96202.
To fix this issue, I add some windows-specific code to locate the
liblldb directory. Since it cannot rely on symlinks, it works by
manually walking the directory tree -- essentially doing the opposite of
what we do when computing the python directory.
To avoid python leaking back into the host code, I implement this with
the help of a callback which can be passed to HostInfo::Initialize in
order to assist with the directory location. The callback lives inside
the python plugin.
I also strenghten the existing path test to ensure the returned path is
the right one.
Differential Revision: https://reviews.llvm.org/D96779
2021-02-16 04:51:32 +08:00
|
|
|
SystemInitializerCommon::SystemInitializerCommon(
|
|
|
|
HostInfo::SharedLibraryDirectoryHelper *helper)
|
|
|
|
: m_shlib_dir_helper(helper) {}
|
2015-04-01 05:03:22 +08:00
|
|
|
|
|
|
|
SystemInitializerCommon::~SystemInitializerCommon() {}
|
|
|
|
|
2020-08-21 06:07:27 +08:00
|
|
|
/// Initialize the FileSystem based on the current reproducer mode.
|
|
|
|
static llvm::Error InitializeFileSystem() {
|
|
|
|
auto &r = repro::Reproducer::Instance();
|
|
|
|
if (repro::Loader *loader = r.GetLoader()) {
|
|
|
|
FileSpec vfs_mapping = loader->GetFile<FileProvider::Info>();
|
|
|
|
if (vfs_mapping) {
|
|
|
|
if (llvm::Error e = FileSystem::Initialize(vfs_mapping))
|
|
|
|
return e;
|
|
|
|
} else {
|
|
|
|
FileSystem::Initialize();
|
|
|
|
}
|
|
|
|
|
2020-08-21 07:19:17 +08:00
|
|
|
// Set the current working directory form the reproducer.
|
|
|
|
llvm::Expected<std::string> working_dir =
|
|
|
|
repro::GetDirectoryFrom<WorkingDirectoryProvider>(loader);
|
|
|
|
if (!working_dir)
|
|
|
|
return working_dir.takeError();
|
2020-08-21 06:07:27 +08:00
|
|
|
if (std::error_code ec = FileSystem::Instance()
|
|
|
|
.GetVirtualFileSystem()
|
2020-08-21 07:19:17 +08:00
|
|
|
->setCurrentWorkingDirectory(*working_dir)) {
|
2020-08-21 06:07:27 +08:00
|
|
|
return llvm::errorCodeToError(ec);
|
|
|
|
}
|
|
|
|
|
2020-08-21 07:19:17 +08:00
|
|
|
// Set the home directory from the reproducer.
|
|
|
|
llvm::Expected<std::string> home_dir =
|
|
|
|
repro::GetDirectoryFrom<HomeDirectoryProvider>(loader);
|
|
|
|
if (!home_dir)
|
|
|
|
return home_dir.takeError();
|
|
|
|
FileSystem::Instance().SetHomeDirectory(*home_dir);
|
|
|
|
|
2020-08-21 06:07:27 +08:00
|
|
|
return llvm::Error::success();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (repro::Generator *g = r.GetGenerator()) {
|
|
|
|
repro::VersionProvider &vp = g->GetOrCreate<repro::VersionProvider>();
|
|
|
|
vp.SetVersion(lldb_private::GetVersion());
|
|
|
|
|
|
|
|
repro::FileProvider &fp = g->GetOrCreate<repro::FileProvider>();
|
|
|
|
FileSystem::Initialize(fp.GetFileCollector());
|
|
|
|
|
2020-09-03 11:48:50 +08:00
|
|
|
fp.RecordInterestingDirectory(
|
|
|
|
g->GetOrCreate<repro::WorkingDirectoryProvider>().GetDirectory());
|
|
|
|
fp.RecordInterestingDirectory(
|
|
|
|
g->GetOrCreate<repro::HomeDirectoryProvider>().GetDirectory());
|
2020-08-21 06:07:27 +08:00
|
|
|
|
|
|
|
return llvm::Error::success();
|
|
|
|
}
|
|
|
|
|
|
|
|
FileSystem::Initialize();
|
|
|
|
return llvm::Error::success();
|
|
|
|
}
|
|
|
|
|
2019-02-22 06:26:16 +08:00
|
|
|
llvm::Error SystemInitializerCommon::Initialize() {
|
2019-05-03 03:25:18 +08:00
|
|
|
#if defined(_WIN32)
|
2015-04-01 05:03:22 +08:00
|
|
|
const char *disable_crash_dialog_var = getenv("LLDB_DISABLE_CRASH_DIALOG");
|
|
|
|
if (disable_crash_dialog_var &&
|
|
|
|
llvm::StringRef(disable_crash_dialog_var).equals_lower("true")) {
|
|
|
|
// This will prevent Windows from displaying a dialog box requiring user
|
|
|
|
// interaction when
|
|
|
|
// LLDB crashes. This is mostly useful when automating LLDB, for example
|
|
|
|
// via the test
|
|
|
|
// suite, so that a crash in LLDB does not prevent completion of the test
|
|
|
|
// suite.
|
|
|
|
::SetErrorMode(GetErrorMode() | SEM_FAILCRITICALERRORS |
|
|
|
|
SEM_NOGPFAULTERRORBOX);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2015-04-01 05:03:22 +08:00
|
|
|
_CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG);
|
|
|
|
_CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG);
|
|
|
|
_CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG);
|
|
|
|
_CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);
|
|
|
|
_CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDERR);
|
|
|
|
_CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2019-02-22 06:26:16 +08:00
|
|
|
// If the reproducer wasn't initialized before, we can safely assume it's
|
|
|
|
// off.
|
|
|
|
if (!Reproducer::Initialized()) {
|
|
|
|
if (auto e = Reproducer::Initialize(ReproducerMode::Off, llvm::None))
|
|
|
|
return e;
|
|
|
|
}
|
2018-12-04 01:28:29 +08:00
|
|
|
|
2020-08-21 06:07:27 +08:00
|
|
|
if (auto e = InitializeFileSystem())
|
|
|
|
return e;
|
2019-01-30 04:36:38 +08:00
|
|
|
|
2017-10-24 03:41:17 +08:00
|
|
|
Log::Initialize();
|
[lldb] Fix shared library directory computation on windows
Our code for locating the shared library directory works via dladdr (or
the windows equivalent) to locate the path of an address known to reside
in liblldb. This works great for C++ programs, but there's a catch.
When (lib)lldb is used from python (like in our test suite), this dladdr
call will return a path to the _lldb.so (or such) file in the python
directory. To compensate for this, we have code which attempts to
resolve this symlink, to ensure we get the canonical location. However,
here's the second catch.
On windows, this file is not a symlink (but a copy), so this logic
fails. Since most of our other paths are derived from the liblldb
location, all of these paths will be wrong, when running the test suite.
One effect of this was the failure to find lldb-server in D96202.
To fix this issue, I add some windows-specific code to locate the
liblldb directory. Since it cannot rely on symlinks, it works by
manually walking the directory tree -- essentially doing the opposite of
what we do when computing the python directory.
To avoid python leaking back into the host code, I implement this with
the help of a callback which can be passed to HostInfo::Initialize in
order to assist with the directory location. The callback lives inside
the python plugin.
I also strenghten the existing path test to ensure the returned path is
the right one.
Differential Revision: https://reviews.llvm.org/D96779
2021-02-16 04:51:32 +08:00
|
|
|
HostInfo::Initialize(m_shlib_dir_helper);
|
2019-04-10 12:57:18 +08:00
|
|
|
|
|
|
|
llvm::Error error = Socket::Initialize();
|
|
|
|
if (error)
|
|
|
|
return error;
|
|
|
|
|
2020-12-22 05:41:57 +08:00
|
|
|
LLDB_SCOPED_TIMER();
|
2015-04-01 05:03:22 +08:00
|
|
|
|
|
|
|
process_gdb_remote::ProcessGDBRemoteLog::Initialize();
|
|
|
|
|
2017-03-22 01:26:55 +08:00
|
|
|
#if defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__)
|
2017-02-23 18:33:16 +08:00
|
|
|
ProcessPOSIXLog::Initialize();
|
2015-04-01 05:03:22 +08:00
|
|
|
#endif
|
2019-05-03 03:25:18 +08:00
|
|
|
#if defined(_WIN32)
|
2015-04-11 00:18:08 +08:00
|
|
|
ProcessWindowsLog::Initialize();
|
|
|
|
#endif
|
2018-12-04 01:28:29 +08:00
|
|
|
|
|
|
|
return llvm::Error::success();
|
2015-04-01 05:03:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void SystemInitializerCommon::Terminate() {
|
2020-12-22 05:41:57 +08:00
|
|
|
LLDB_SCOPED_TIMER();
|
2015-04-01 05:03:22 +08:00
|
|
|
|
2019-05-03 03:25:18 +08:00
|
|
|
#if defined(_WIN32)
|
2015-05-08 05:39:33 +08:00
|
|
|
ProcessWindowsLog::Terminate();
|
|
|
|
#endif
|
|
|
|
|
2019-04-10 12:57:18 +08:00
|
|
|
Socket::Terminate();
|
2016-02-20 03:20:44 +08:00
|
|
|
HostInfo::Terminate();
|
2017-03-15 17:06:58 +08:00
|
|
|
Log::DisableAllLogChannels();
|
2018-11-01 05:49:27 +08:00
|
|
|
FileSystem::Terminate();
|
2018-12-04 01:28:29 +08:00
|
|
|
Reproducer::Terminate();
|
2015-04-01 05:03:22 +08:00
|
|
|
}
|