Coverage Report

Created: 2022-01-15 10:30

/Users/buildslave/jenkins/workspace/coverage/llvm-project/lldb/source/Core/StreamFile.cpp
Line
Count
Source (jump to first uncovered line)
1
//===-- StreamFile.cpp ----------------------------------------------------===//
2
//
3
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4
// See https://llvm.org/LICENSE.txt for license information.
5
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
//
7
//===----------------------------------------------------------------------===//
8
9
#include "lldb/Core/StreamFile.h"
10
#include "lldb/Host/FileSystem.h"
11
#include "lldb/Utility/Log.h"
12
13
#include <cstdio>
14
15
using namespace lldb;
16
using namespace lldb_private;
17
18
StreamFile::StreamFile(uint32_t flags, uint32_t addr_size, ByteOrder byte_order)
19
0
    : Stream(flags, addr_size, byte_order) {
20
0
  m_file_sp = std::make_shared<File>();
21
0
}
22
23
0
StreamFile::StreamFile(int fd, bool transfer_ownership) : Stream() {
24
0
  m_file_sp = std::make_shared<NativeFile>(fd, File::eOpenOptionWriteOnly,
25
0
                                           transfer_ownership);
26
0
}
27
28
11.9k
StreamFile::StreamFile(FILE *fh, bool transfer_ownership) : Stream() {
29
11.9k
  m_file_sp = std::make_shared<NativeFile>(fh, transfer_ownership);
30
11.9k
}
31
32
StreamFile::StreamFile(const char *path, File::OpenOptions options,
33
                       uint32_t permissions)
34
17
    : Stream() {
35
17
  auto file = FileSystem::Instance().Open(FileSpec(path), options, permissions);
36
17
  if (file)
37
17
    m_file_sp = std::move(file.get());
38
0
  else {
39
    // TODO refactor this so the error gets popagated up instead of logged here.
40
0
    LLDB_LOG_ERROR(GetLogIfAllCategoriesSet(LIBLLDB_LOG_HOST), file.takeError(),
41
0
                   "Cannot open {1}: {0}", path);
42
0
    m_file_sp = std::make_shared<File>();
43
0
  }
44
17
}
45
46
18.1k
StreamFile::~StreamFile() = default;
47
48
308
void StreamFile::Flush() { m_file_sp->Flush(); }
49
50
35.6k
size_t StreamFile::WriteImpl(const void *s, size_t length) {
51
35.6k
  m_file_sp->Write(s, length);
52
35.6k
  return length;
53
35.6k
}