[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
|
|
|
//===-- StreamFile.cpp ----------------------------------------------------===//
|
2010-06-09 00:52:24 +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
|
2010-06-09 00:52:24 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "lldb/Core/StreamFile.h"
|
2018-11-03 06:34:51 +08:00
|
|
|
#include "lldb/Host/FileSystem.h"
|
2019-09-27 01:54:59 +08:00
|
|
|
#include "lldb/Utility/Log.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2011-02-09 09:08:52 +08:00
|
|
|
#include <stdio.h>
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
using namespace lldb;
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
2011-02-09 09:08:52 +08:00
|
|
|
StreamFile::StreamFile(uint32_t flags, uint32_t addr_size, ByteOrder byte_order)
|
2019-09-27 01:54:59 +08:00
|
|
|
: Stream(flags, addr_size, byte_order) {
|
|
|
|
m_file_sp = std::make_shared<File>();
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2019-09-27 01:54:59 +08:00
|
|
|
StreamFile::StreamFile(int fd, bool transfer_ownership) : Stream() {
|
|
|
|
m_file_sp =
|
2019-10-03 12:31:46 +08:00
|
|
|
std::make_shared<NativeFile>(fd, File::eOpenOptionWrite, transfer_ownership);
|
2019-09-27 01:54:59 +08:00
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2019-09-27 01:54:59 +08:00
|
|
|
StreamFile::StreamFile(FILE *fh, bool transfer_ownership) : Stream() {
|
2019-10-03 12:31:46 +08:00
|
|
|
m_file_sp = std::make_shared<NativeFile>(fh, transfer_ownership);
|
2019-09-27 01:54:59 +08:00
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2019-10-15 04:15:34 +08:00
|
|
|
StreamFile::StreamFile(const char *path, File::OpenOptions options,
|
|
|
|
uint32_t permissions)
|
2019-09-27 01:54:59 +08:00
|
|
|
: Stream() {
|
|
|
|
auto file = FileSystem::Instance().Open(FileSpec(path), options, permissions);
|
|
|
|
if (file)
|
|
|
|
m_file_sp = std::move(file.get());
|
|
|
|
else {
|
|
|
|
// TODO refactor this so the error gets popagated up instead of logged here.
|
|
|
|
LLDB_LOG_ERROR(GetLogIfAllCategoriesSet(LIBLLDB_LOG_HOST), file.takeError(),
|
|
|
|
"Cannot open {1}: {0}", path);
|
|
|
|
m_file_sp = std::make_shared<File>();
|
|
|
|
}
|
2018-11-03 06:34:51 +08:00
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
StreamFile::~StreamFile() {}
|
2011-02-05 14:37:53 +08:00
|
|
|
|
2019-09-27 01:54:59 +08:00
|
|
|
void StreamFile::Flush() { m_file_sp->Flush(); }
|
2010-06-09 00:52:24 +08:00
|
|
|
|
Add byte counting mechanism to LLDB's Stream class.
Summary:
This patch allows LLDB's Stream class to count the bytes it has written to so far.
There are two major motivations for this patch:
The first one is that this will allow us to get rid of all the handwritten byte counting code
we have in LLDB so far. Examples for this are pretty much all functions in LLDB that
take a Stream to write to and return a size_t, which usually represents the bytes written.
By moving to this centralized byte counting mechanism, we hopefully can avoid some
tricky errors that happen when some code forgets to count the written bytes while
writing something to a stream.
The second motivation is that this is needed for the migration away from LLDB's `Stream`
and towards LLVM's `raw_ostream`. My current plan is to start offering a fake raw_ostream
class that just forwards to a LLDB Stream.
However, for this raw_ostream wrapper we need to fulfill the raw_ostream interface with
LLDB's Stream, which currently lacks the ability to count the bytes written so far (which
raw_ostream exposes by it's `tell()` method). By adding this functionality it is trivial to start
rolling out our raw_ostream wrapper (and then eventually completely move to raw_ostream).
Also, once this fake raw_ostream is available, we can start replacing our own code writing
to LLDB's Stream by LLVM code writing to raw_ostream. The best example for this is the
LEB128 encoding we currently ship, which can be replaced with by LLVM's version which
accepts an raw_ostream.
From the point of view of the pure source changes this test does, we essentially just renamed
the Write implementation in Stream to `WriteImpl` while the `Write` method everyone is using
to write its raw bytes is now just forwarding and counting the written bytes.
Reviewers: labath, davide
Reviewed By: labath
Subscribers: JDevlieghere, lldb-commits
Differential Revision: https://reviews.llvm.org/D50159
llvm-svn: 338733
2018-08-03 00:38:34 +08:00
|
|
|
size_t StreamFile::WriteImpl(const void *s, size_t length) {
|
2019-09-27 01:54:59 +08:00
|
|
|
m_file_sp->Write(s, length);
|
2011-02-09 09:08:52 +08:00
|
|
|
return length;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|