CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
81 lines
3.1 KiB
C++
81 lines
3.1 KiB
C++
//===-- DAPLog.h ----------------------------------------------------------===//
|
|
//
|
|
// 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
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#ifndef LLDB_TOOLS_LLDB_DAP_DAPLOG_H
|
|
#define LLDB_TOOLS_LLDB_DAP_DAPLOG_H
|
|
|
|
#include "llvm/ADT/StringRef.h"
|
|
#include "llvm/Support/Error.h"
|
|
#include "llvm/Support/FormatVariadic.h"
|
|
#include "llvm/Support/raw_ostream.h"
|
|
#include <mutex>
|
|
#include <string>
|
|
|
|
// Write a message to log, if logging is enabled.
|
|
#define DAP_LOG(log, ...) \
|
|
do { \
|
|
::lldb_dap::Log &log_private = (log); \
|
|
log_private.Emit(::llvm::formatv(__VA_ARGS__).str(), __FILE__, __LINE__); \
|
|
} while (0)
|
|
|
|
// Write message to log, if error is set. In the log message refer to the error
|
|
// with {0}. Error is cleared regardless of whether logging is enabled.
|
|
#define DAP_LOG_ERROR(log, error, ...) \
|
|
do { \
|
|
::lldb_dap::Log &log_private = (log); \
|
|
::llvm::Error error_private = (error); \
|
|
if (error_private) \
|
|
log_private.Emit( \
|
|
::lldb_dap::FormatError(::std::move(error_private), __VA_ARGS__), \
|
|
__FILE__, __LINE__); \
|
|
} while (0)
|
|
|
|
namespace lldb_dap {
|
|
|
|
/// Log manages the lldb-dap log file, used with the corresponding `DAP_LOG` and
|
|
/// `DAP_LOG_ERROR` helpers.
|
|
class Log final {
|
|
public:
|
|
using Mutex = std::mutex;
|
|
|
|
Log(llvm::raw_ostream &stream, Mutex &mutex)
|
|
: m_stream(stream), m_mutex(mutex) {}
|
|
Log(llvm::StringRef prefix, const Log &log)
|
|
: m_prefix(prefix), m_stream(log.m_stream), m_mutex(log.m_mutex) {}
|
|
|
|
/// Retuns a new Log instance with the associated prefix for all messages.
|
|
inline Log WithPrefix(llvm::StringRef prefix) const {
|
|
std::string full_prefix =
|
|
m_prefix.empty() ? prefix.str() : m_prefix + prefix.str();
|
|
full_prefix += " ";
|
|
return Log(full_prefix, *this);
|
|
}
|
|
|
|
/// Emit writes a message to the underlying stream.
|
|
void Emit(llvm::StringRef message);
|
|
|
|
/// Emit writes a message to the underlying stream, including the file and
|
|
/// line the message originated from.
|
|
void Emit(llvm::StringRef message, llvm::StringRef file, size_t line);
|
|
|
|
private:
|
|
std::string m_prefix;
|
|
llvm::raw_ostream &m_stream;
|
|
Mutex &m_mutex;
|
|
};
|
|
|
|
template <typename... Args>
|
|
inline auto FormatError(llvm::Error error, const char *format, Args &&...args) {
|
|
return llvm::formatv(format, llvm::toString(std::move(error)),
|
|
std::forward<Args>(args)...)
|
|
.str();
|
|
}
|
|
} // namespace lldb_dap
|
|
|
|
#endif
|