Coverage Report

Created: 2022-01-15 10:30

/Users/buildslave/jenkins/workspace/coverage/llvm-project/lldb/source/Host/common/FileAction.cpp
Line
Count
Source (jump to first uncovered line)
1
//===-- FileAction.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 <fcntl.h>
10
11
#include "lldb/Host/FileAction.h"
12
#include "lldb/Host/PosixApi.h"
13
#include "lldb/Utility/Stream.h"
14
15
using namespace lldb_private;
16
17
// FileAction member functions
18
19
57.1k
FileAction::FileAction() : m_file_spec() {}
20
21
37.9k
void FileAction::Clear() {
22
37.9k
  m_action = eFileActionNone;
23
37.9k
  m_fd = -1;
24
37.9k
  m_arg = -1;
25
37.9k
  m_file_spec.Clear();
26
37.9k
}
27
28
19.1k
llvm::StringRef FileAction::GetPath() const { return m_file_spec.GetCString(); }
29
30
19
const FileSpec &FileAction::GetFileSpec() const { return m_file_spec; }
31
32
bool FileAction::Open(int fd, const FileSpec &file_spec, bool read,
33
46.2k
                      bool write) {
34
46.2k
  if ((read || 
write30.6k
) && fd >= 0 && file_spec) {
35
19.1k
    m_action = eFileActionOpen;
36
19.1k
    m_fd = fd;
37
19.1k
    if (read && 
write6.57k
)
38
0
      m_arg = O_NOCTTY | O_CREAT | O_RDWR;
39
19.1k
    else if (read)
40
6.57k
      m_arg = O_NOCTTY | O_RDONLY;
41
12.6k
    else
42
12.6k
      m_arg = O_NOCTTY | O_CREAT | O_WRONLY;
43
19.1k
    m_file_spec = file_spec;
44
19.1k
    return true;
45
27.0k
  } else {
46
27.0k
    Clear();
47
27.0k
  }
48
27.0k
  return false;
49
46.2k
}
50
51
7.75k
bool FileAction::Close(int fd) {
52
7.75k
  Clear();
53
7.75k
  if (fd >= 0) {
54
7.75k
    m_action = eFileActionClose;
55
7.75k
    m_fd = fd;
56
7.75k
  }
57
7.75k
  return m_fd >= 0;
58
7.75k
}
59
60
3.13k
bool FileAction::Duplicate(int fd, int dup_fd) {
61
3.13k
  Clear();
62
3.13k
  if (fd >= 0 && dup_fd >= 0) {
63
3.13k
    m_action = eFileActionDuplicate;
64
3.13k
    m_fd = fd;
65
3.13k
    m_arg = dup_fd;
66
3.13k
  }
67
3.13k
  return m_fd >= 0;
68
3.13k
}
69
70
0
void FileAction::Dump(Stream &stream) const {
71
0
  stream.PutCString("file action: ");
72
0
  switch (m_action) {
73
0
  case eFileActionClose:
74
0
    stream.Printf("close fd %d", m_fd);
75
0
    break;
76
0
  case eFileActionDuplicate:
77
0
    stream.Printf("duplicate fd %d to %d", m_fd, m_arg);
78
0
    break;
79
0
  case eFileActionNone:
80
0
    stream.PutCString("no action");
81
0
    break;
82
0
  case eFileActionOpen:
83
0
    stream.Printf("open fd %d with '%s', OFLAGS = 0x%x", m_fd,
84
0
                  m_file_spec.GetCString(), m_arg);
85
0
    break;
86
0
  }
87
0
}