clang -cc1 -cc1 -triple x86_64-pc-linux-gnu -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name FifoFiles.cpp -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -analyzer-config-compatibility-mode=true -mrelocation-model pic -pic-level 2 -mframe-pointer=none -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -ffunction-sections -fdata-sections -fcoverage-compilation-dir=/build/llvm-toolchain-snapshot-15~++20220420111733+e13d2efed663/build-llvm/tools/clang/stage2-bins -resource-dir /usr/lib/llvm-15/lib/clang/15.0.0 -D HAVE_ROUND -D _DEBUG -D _GNU_SOURCE -D __STDC_CONSTANT_MACROS -D __STDC_FORMAT_MACROS -D __STDC_LIMIT_MACROS -I tools/lldb/tools/lldb-vscode -I /build/llvm-toolchain-snapshot-15~++20220420111733+e13d2efed663/lldb/tools/lldb-vscode -I /build/llvm-toolchain-snapshot-15~++20220420111733+e13d2efed663/lldb/include -I tools/lldb/include -I include -I /build/llvm-toolchain-snapshot-15~++20220420111733+e13d2efed663/llvm/include -I /usr/include/python3.9 -I /build/llvm-toolchain-snapshot-15~++20220420111733+e13d2efed663/clang/include -I tools/lldb/../clang/include -I /usr/include/libxml2 -D _FORTIFY_SOURCE=2 -D NDEBUG -U NDEBUG -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/10/../../../../include/x86_64-linux-gnu/c++/10 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/backward -internal-isystem /usr/lib/llvm-15/lib/clang/15.0.0/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/10/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -fmacro-prefix-map=/build/llvm-toolchain-snapshot-15~++20220420111733+e13d2efed663/build-llvm/tools/clang/stage2-bins=build-llvm/tools/clang/stage2-bins -fmacro-prefix-map=/build/llvm-toolchain-snapshot-15~++20220420111733+e13d2efed663/= -fcoverage-prefix-map=/build/llvm-toolchain-snapshot-15~++20220420111733+e13d2efed663/build-llvm/tools/clang/stage2-bins=build-llvm/tools/clang/stage2-bins -fcoverage-prefix-map=/build/llvm-toolchain-snapshot-15~++20220420111733+e13d2efed663/= -O3 -Wno-unused-command-line-argument -Wno-unused-parameter -Wwrite-strings -Wno-missing-field-initializers -Wno-long-long -Wno-maybe-uninitialized -Wno-class-memaccess -Wno-redundant-move -Wno-pessimizing-move -Wno-noexcept-type -Wno-comment -Wno-deprecated-declarations -Wno-unknown-pragmas -Wno-strict-aliasing -Wno-stringop-truncation -std=c++14 -fdeprecated-macro -fdebug-compilation-dir=/build/llvm-toolchain-snapshot-15~++20220420111733+e13d2efed663/build-llvm/tools/clang/stage2-bins -fdebug-prefix-map=/build/llvm-toolchain-snapshot-15~++20220420111733+e13d2efed663/build-llvm/tools/clang/stage2-bins=build-llvm/tools/clang/stage2-bins -fdebug-prefix-map=/build/llvm-toolchain-snapshot-15~++20220420111733+e13d2efed663/= -ferror-limit 19 -fvisibility-inlines-hidden -stack-protector 2 -fgnuc-version=4.2.1 -fcolor-diagnostics -vectorize-loops -vectorize-slp -analyzer-output=html -analyzer-config stable-report-filename=true -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/scan-build-2022-04-20-140412-16051-1 -x c++ /build/llvm-toolchain-snapshot-15~++20220420111733+e13d2efed663/lldb/tools/lldb-vscode/FifoFiles.cpp
1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | #include "FifoFiles.h" |
10 | |
11 | #if !defined(_WIN32) |
12 | #include <sys/stat.h> |
13 | #include <sys/types.h> |
14 | #include <unistd.h> |
15 | #endif |
16 | |
17 | #include <chrono> |
18 | #include <fstream> |
19 | #include <future> |
20 | #include <thread> |
21 | |
22 | #include "llvm/Support/FileSystem.h" |
23 | |
24 | #include "lldb/lldb-defines.h" |
25 | |
26 | using namespace llvm; |
27 | |
28 | namespace lldb_vscode { |
29 | |
30 | FifoFile::FifoFile(StringRef path) : m_path(path) {} |
31 | |
32 | FifoFile::~FifoFile() { |
33 | #if !defined(_WIN32) |
34 | unlink(m_path.c_str()); |
35 | #endif |
36 | } |
37 | |
38 | Expected<std::shared_ptr<FifoFile>> CreateFifoFile(StringRef path) { |
39 | #if defined(_WIN32) |
40 | return createStringError(inconvertibleErrorCode(), "Unimplemented"); |
41 | #else |
42 | if (int err = mkfifo(path.data(), 0600)) |
43 | return createStringError(std::error_code(err, std::generic_category()), |
44 | "Couldn't create fifo file: %s", path.data()); |
45 | return std::make_shared<FifoFile>(path); |
46 | #endif |
47 | } |
48 | |
49 | FifoFileIO::FifoFileIO(StringRef fifo_file, StringRef other_endpoint_name) |
50 | : m_fifo_file(fifo_file), m_other_endpoint_name(other_endpoint_name) {} |
51 | |
52 | Expected<json::Value> FifoFileIO::ReadJSON(std::chrono::milliseconds timeout) { |
53 | |
54 | |
55 | Optional<std::string> line; |
56 | std::future<void> *future = |
57 | new std::future<void>(std::async(std::launch::async, [&]() { |
| |
58 | std::ifstream reader(m_fifo_file, std::ifstream::in); |
59 | std::string buffer; |
60 | std::getline(reader, buffer); |
61 | if (!buffer.empty()) |
62 | line = buffer; |
63 | })); |
64 | if (future->wait_for(timeout) == std::future_status::timeout || |
65 | !line.hasValue()) |
66 | return createStringError(inconvertibleErrorCode(), |
| 2 | | Potential leak of memory pointed to by 'future' |
|
67 | "Timed out trying to get messages from the " + |
68 | m_other_endpoint_name); |
69 | delete future; |
70 | return json::parse(*line); |
71 | } |
72 | |
73 | Error FifoFileIO::SendJSON(const json::Value &json, |
74 | std::chrono::milliseconds timeout) { |
75 | bool done = false; |
76 | std::future<void> *future = |
77 | new std::future<void>(std::async(std::launch::async, [&]() { |
78 | std::ofstream writer(m_fifo_file, std::ofstream::out); |
79 | writer << JSONToString(json) << std::endl; |
80 | done = true; |
81 | })); |
82 | if (future->wait_for(timeout) == std::future_status::timeout || !done) { |
83 | return createStringError(inconvertibleErrorCode(), |
84 | "Timed out trying to send messages to the " + |
85 | m_other_endpoint_name); |
86 | } |
87 | delete future; |
88 | return Error::success(); |
89 | } |
90 | |
91 | } |