Imported Upstream version 6.10.0.49

Former-commit-id: 1d6753294b2993e1fbf92de9366bb9544db4189b
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2020-01-16 16:38:04 +00:00
parent d94e79959b
commit 468663ddbb
48518 changed files with 2789335 additions and 61176 deletions

View File

@ -0,0 +1,80 @@
//===-- CFBundle.cpp --------------------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// Created by Greg Clayton on 1/16/08.
//
//===----------------------------------------------------------------------===//
#include "CFBundle.h"
#include "CFString.h"
//----------------------------------------------------------------------
// CFBundle constructor
//----------------------------------------------------------------------
CFBundle::CFBundle(const char *path)
: CFReleaser<CFBundleRef>(), m_bundle_url() {
if (path && path[0])
SetPath(path);
}
//----------------------------------------------------------------------
// CFBundle copy constructor
//----------------------------------------------------------------------
CFBundle::CFBundle(const CFBundle &rhs)
: CFReleaser<CFBundleRef>(rhs), m_bundle_url(rhs.m_bundle_url) {}
//----------------------------------------------------------------------
// CFBundle copy constructor
//----------------------------------------------------------------------
CFBundle &CFBundle::operator=(const CFBundle &rhs) {
if (this != &rhs)
*this = rhs;
return *this;
}
//----------------------------------------------------------------------
// Destructor
//----------------------------------------------------------------------
CFBundle::~CFBundle() {}
//----------------------------------------------------------------------
// Set the path for a bundle by supplying a
//----------------------------------------------------------------------
bool CFBundle::SetPath(const char *path) {
CFAllocatorRef alloc = kCFAllocatorDefault;
// Release our old bundle and ULR
reset(); // This class is a CFReleaser<CFBundleRef>
m_bundle_url.reset();
// Make a CFStringRef from the supplied path
CFString cf_path;
cf_path.SetFileSystemRepresentation(path);
if (cf_path.get()) {
// Make our Bundle URL
m_bundle_url.reset(::CFURLCreateWithFileSystemPath(
alloc, cf_path.get(), kCFURLPOSIXPathStyle, true));
if (m_bundle_url.get()) {
reset(::CFBundleCreate(alloc, m_bundle_url.get()));
}
}
return get() != NULL;
}
CFStringRef CFBundle::GetIdentifier() const {
CFBundleRef bundle = get();
if (bundle != NULL)
return ::CFBundleGetIdentifier(bundle);
return NULL;
}
CFURLRef CFBundle::CopyExecutableURL() const {
CFBundleRef bundle = get();
if (bundle != NULL)
return CFBundleCopyExecutableURL(bundle);
return NULL;
}

View File

@ -0,0 +1,38 @@
//===-- CFBundle.h ----------------------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// Created by Greg Clayton on 1/16/08.
//
//===----------------------------------------------------------------------===//
#ifndef __CFBundle_h__
#define __CFBundle_h__
#include "CFUtils.h"
class CFBundle : public CFReleaser<CFBundleRef> {
public:
//------------------------------------------------------------------
// Constructors and Destructors
//------------------------------------------------------------------
CFBundle(const char *path = NULL);
CFBundle(const CFBundle &rhs);
CFBundle &operator=(const CFBundle &rhs);
virtual ~CFBundle();
bool SetPath(const char *path);
CFStringRef GetIdentifier() const;
CFURLRef CopyExecutableURL() const;
protected:
CFReleaser<CFURLRef> m_bundle_url;
};
#endif // #ifndef __CFBundle_h__

View File

@ -0,0 +1,163 @@
//===-- CFString.cpp --------------------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// Created by Greg Clayton on 1/16/08.
//
//===----------------------------------------------------------------------===//
#include "CFString.h"
#include <glob.h>
#include <string>
//----------------------------------------------------------------------
// CFString constructor
//----------------------------------------------------------------------
CFString::CFString(CFStringRef s) : CFReleaser<CFStringRef>(s) {}
//----------------------------------------------------------------------
// CFString copy constructor
//----------------------------------------------------------------------
CFString::CFString(const CFString &rhs) : CFReleaser<CFStringRef>(rhs) {}
//----------------------------------------------------------------------
// CFString copy constructor
//----------------------------------------------------------------------
CFString &CFString::operator=(const CFString &rhs) {
if (this != &rhs)
*this = rhs;
return *this;
}
CFString::CFString(const char *cstr, CFStringEncoding cstr_encoding)
: CFReleaser<CFStringRef>() {
if (cstr && cstr[0]) {
reset(
::CFStringCreateWithCString(kCFAllocatorDefault, cstr, cstr_encoding));
}
}
//----------------------------------------------------------------------
// Destructor
//----------------------------------------------------------------------
CFString::~CFString() {}
const char *CFString::GetFileSystemRepresentation(std::string &s) {
return CFString::FileSystemRepresentation(get(), s);
}
CFStringRef CFString::SetFileSystemRepresentation(const char *path) {
CFStringRef new_value = NULL;
if (path && path[0])
new_value =
::CFStringCreateWithFileSystemRepresentation(kCFAllocatorDefault, path);
reset(new_value);
return get();
}
CFStringRef CFString::SetFileSystemRepresentationFromCFType(CFTypeRef cf_type) {
CFStringRef new_value = NULL;
if (cf_type != NULL) {
CFTypeID cf_type_id = ::CFGetTypeID(cf_type);
if (cf_type_id == ::CFStringGetTypeID()) {
// Retain since we are using the existing object
new_value = (CFStringRef)::CFRetain(cf_type);
} else if (cf_type_id == ::CFURLGetTypeID()) {
new_value =
::CFURLCopyFileSystemPath((CFURLRef)cf_type, kCFURLPOSIXPathStyle);
}
}
reset(new_value);
return get();
}
CFStringRef
CFString::SetFileSystemRepresentationAndExpandTilde(const char *path) {
std::string expanded_path;
if (CFString::GlobPath(path, expanded_path))
SetFileSystemRepresentation(expanded_path.c_str());
else
reset();
return get();
}
const char *CFString::UTF8(std::string &str) {
return CFString::UTF8(get(), str);
}
// Static function that puts a copy of the UTF8 contents of CF_STR into STR
// and returns the C string pointer that is contained in STR when successful,
// else
// NULL is returned. This allows the std::string parameter to own the extracted
// string,
// and also allows that string to be returned as a C string pointer that can be
// used.
const char *CFString::UTF8(CFStringRef cf_str, std::string &str) {
if (cf_str) {
const CFStringEncoding encoding = kCFStringEncodingUTF8;
CFIndex max_utf8_str_len = CFStringGetLength(cf_str);
max_utf8_str_len =
CFStringGetMaximumSizeForEncoding(max_utf8_str_len, encoding);
if (max_utf8_str_len > 0) {
str.resize(max_utf8_str_len);
if (!str.empty()) {
if (CFStringGetCString(cf_str, &str[0], str.size(), encoding)) {
str.resize(strlen(str.c_str()));
return str.c_str();
}
}
}
}
return NULL;
}
// Static function that puts a copy of the file system representation of CF_STR
// into STR and returns the C string pointer that is contained in STR when
// successful, else NULL is returned. This allows the std::string parameter
// to own the extracted string, and also allows that string to be returned as
// a C string pointer that can be used.
const char *CFString::FileSystemRepresentation(CFStringRef cf_str,
std::string &str) {
if (cf_str) {
CFIndex max_length =
::CFStringGetMaximumSizeOfFileSystemRepresentation(cf_str);
if (max_length > 0) {
str.resize(max_length);
if (!str.empty()) {
if (::CFStringGetFileSystemRepresentation(cf_str, &str[0],
str.size())) {
str.erase(::strlen(str.c_str()));
return str.c_str();
}
}
}
}
str.erase();
return NULL;
}
CFIndex CFString::GetLength() const {
CFStringRef str = get();
if (str)
return CFStringGetLength(str);
return 0;
}
const char *CFString::GlobPath(const char *path, std::string &expanded_path) {
glob_t globbuf;
if (::glob(path, GLOB_TILDE, NULL, &globbuf) == 0) {
expanded_path = globbuf.gl_pathv[0];
::globfree(&globbuf);
} else
expanded_path.clear();
return expanded_path.c_str();
}

View File

@ -0,0 +1,43 @@
//===-- CFString.h ----------------------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// Created by Greg Clayton on 1/16/08.
//
//===----------------------------------------------------------------------===//
#ifndef __CFString_h__
#define __CFString_h__
#include "CFUtils.h"
#include <iosfwd>
class CFString : public CFReleaser<CFStringRef> {
public:
//------------------------------------------------------------------
// Constructors and Destructors
//------------------------------------------------------------------
CFString(CFStringRef cf_str = NULL);
CFString(const char *s, CFStringEncoding encoding = kCFStringEncodingUTF8);
CFString(const CFString &rhs);
CFString &operator=(const CFString &rhs);
virtual ~CFString();
const char *GetFileSystemRepresentation(std::string &str);
CFStringRef SetFileSystemRepresentation(const char *path);
CFStringRef SetFileSystemRepresentationFromCFType(CFTypeRef cf_type);
CFStringRef SetFileSystemRepresentationAndExpandTilde(const char *path);
const char *UTF8(std::string &str);
CFIndex GetLength() const;
static const char *UTF8(CFStringRef cf_str, std::string &str);
static const char *FileSystemRepresentation(CFStringRef cf_str,
std::string &str);
static const char *GlobPath(const char *path, std::string &expanded_path);
};
#endif // #ifndef __CFString_h__

View File

@ -0,0 +1,78 @@
//===-- CFUtils.h -----------------------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// Created by Greg Clayton on 3/5/07.
//
//===----------------------------------------------------------------------===//
#ifndef __CFUtils_h__
#define __CFUtils_h__
#include <CoreFoundation/CoreFoundation.h>
#ifdef __cplusplus
//----------------------------------------------------------------------
// Templatized CF helper class that can own any CF pointer and will
// call CFRelease() on any valid pointer it owns unless that pointer is
// explicitly released using the release() member function.
//----------------------------------------------------------------------
template <class T> class CFReleaser {
public:
// Type names for the avlue
typedef T element_type;
// Constructors and destructors
CFReleaser(T ptr = NULL) : _ptr(ptr) {}
CFReleaser(const CFReleaser &copy) : _ptr(copy.get()) {
if (get())
::CFRetain(get());
}
virtual ~CFReleaser() { reset(); }
// Assignments
CFReleaser &operator=(const CFReleaser<T> &copy) {
if (copy != *this) {
// Replace our owned pointer with the new one
reset(copy.get());
// Retain the current pointer that we own
if (get())
::CFRetain(get());
}
}
// Get the address of the contained type
T *ptr_address() { return &_ptr; }
// Access the pointer itself
const T get() const { return _ptr; }
T get() { return _ptr; }
// Set a new value for the pointer and CFRelease our old
// value if we had a valid one.
void reset(T ptr = NULL) {
if (ptr != _ptr) {
if (_ptr != NULL)
::CFRelease(_ptr);
_ptr = ptr;
}
}
// Release ownership without calling CFRelease
T release() {
T tmp = _ptr;
_ptr = NULL;
return tmp;
}
private:
element_type _ptr;
};
#endif // #ifdef __cplusplus
#endif // #ifndef __CFUtils_h__

View File

@ -0,0 +1,23 @@
if("${CMAKE_OSX_ARCHITECTURES}" MATCHES ".*arm.*")
list(APPEND SOURCES arm/DNBArchImpl.cpp arm64/DNBArchImplARM64.cpp)
include_directories(${CURRENT_SOURCE_DIR}/arm ${CURRENT_SOURCE_DIR}/arm64)
endif()
if(NOT CMAKE_OSX_ARCHITECTURES OR "${CMAKE_OSX_ARCHITECTURES}" MATCHES ".*86.*")
list(APPEND SOURCES i386/DNBArchImplI386.cpp x86_64/DNBArchImplX86_64.cpp)
include_directories(${CURRENT_SOURCE_DIR}/i386 ${CURRENT_SOURCE_DIR}/x86_64)
endif()
if("${CMAKE_OSX_ARCHITECTURES}" MATCHES ".*ppc.*")
list(APPEND SOURCES ppc/DNBArchImpl.cpp)
include_directories(${CURRENT_SOURCE_DIR}/ppc)
endif()
add_subdirectory(DarwinLog)
include_directories(..)
include_directories(${LLDB_SOURCE_DIR}/tools/debugserver/source)
add_library(lldbDebugserverArchSupport
${SOURCES}
)

View File

@ -0,0 +1,14 @@
//===-- ActivityStore.cpp ---------------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "ActivityStore.h"
ActivityStore::ActivityStore() {}
ActivityStore::~ActivityStore() {}

View File

@ -0,0 +1,30 @@
//===-- ActivityStore.h -----------------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef ActivityStore_h
#define ActivityStore_h
#include <string>
#include "ActivityStreamSPI.h"
class ActivityStore {
public:
virtual ~ActivityStore();
virtual const char *GetActivityForID(os_activity_id_t activity_id) const = 0;
virtual std::string
GetActivityChainForID(os_activity_id_t activity_id) const = 0;
protected:
ActivityStore();
};
#endif /* ActivityStore_h */

View File

@ -0,0 +1,191 @@
//===-- ActivityStreamAPI.h -------------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef ActivityStreamSPI_h
#define ActivityStreamSPI_h
#include <sys/time.h>
#include <xpc/xpc.h>
#define OS_ACTIVITY_MAX_CALLSTACK 32
// Enums
enum {
OS_ACTIVITY_STREAM_PROCESS_ONLY = 0x00000001,
OS_ACTIVITY_STREAM_SKIP_DECODE = 0x00000002,
OS_ACTIVITY_STREAM_PAYLOAD = 0x00000004,
OS_ACTIVITY_STREAM_HISTORICAL = 0x00000008,
OS_ACTIVITY_STREAM_CALLSTACK = 0x00000010,
OS_ACTIVITY_STREAM_DEBUG = 0x00000020,
OS_ACTIVITY_STREAM_BUFFERED = 0x00000040,
OS_ACTIVITY_STREAM_NO_SENSITIVE = 0x00000080,
OS_ACTIVITY_STREAM_INFO = 0x00000100,
OS_ACTIVITY_STREAM_PROMISCUOUS = 0x00000200,
OS_ACTIVITY_STREAM_PRECISE_TIMESTAMPS = 0x00000200
};
typedef uint32_t os_activity_stream_flag_t;
enum {
OS_ACTIVITY_STREAM_TYPE_ACTIVITY_CREATE = 0x0201,
OS_ACTIVITY_STREAM_TYPE_ACTIVITY_TRANSITION = 0x0202,
OS_ACTIVITY_STREAM_TYPE_ACTIVITY_USERACTION = 0x0203,
OS_ACTIVITY_STREAM_TYPE_TRACE_MESSAGE = 0x0300,
OS_ACTIVITY_STREAM_TYPE_LOG_MESSAGE = 0x0400,
OS_ACTIVITY_STREAM_TYPE_LEGACY_LOG_MESSAGE = 0x0480,
OS_ACTIVITY_STREAM_TYPE_SIGNPOST_BEGIN = 0x0601,
OS_ACTIVITY_STREAM_TYPE_SIGNPOST_END = 0x0602,
OS_ACTIVITY_STREAM_TYPE_SIGNPOST_EVENT = 0x0603,
OS_ACTIVITY_STREAM_TYPE_STATEDUMP_EVENT = 0x0A00,
};
typedef uint32_t os_activity_stream_type_t;
enum {
OS_ACTIVITY_STREAM_EVENT_STARTED = 1,
OS_ACTIVITY_STREAM_EVENT_STOPPED = 2,
OS_ACTIVITY_STREAM_EVENT_FAILED = 3,
OS_ACTIVITY_STREAM_EVENT_CHUNK_STARTED = 4,
OS_ACTIVITY_STREAM_EVENT_CHUNK_FINISHED = 5,
};
typedef uint32_t os_activity_stream_event_t;
// Types
typedef uint64_t os_activity_id_t;
typedef struct os_activity_stream_s *os_activity_stream_t;
typedef struct os_activity_stream_entry_s *os_activity_stream_entry_t;
#define OS_ACTIVITY_STREAM_COMMON() \
uint64_t trace_id; \
uint64_t timestamp; \
uint64_t thread; \
const uint8_t *image_uuid; \
const char *image_path; \
struct timeval tv_gmt; \
struct timezone tz; \
uint32_t offset
typedef struct os_activity_stream_common_s {
OS_ACTIVITY_STREAM_COMMON();
} * os_activity_stream_common_t;
struct os_activity_create_s {
OS_ACTIVITY_STREAM_COMMON();
const char *name;
os_activity_id_t creator_aid;
uint64_t unique_pid;
};
struct os_activity_transition_s {
OS_ACTIVITY_STREAM_COMMON();
os_activity_id_t transition_id;
};
typedef struct os_log_message_s {
OS_ACTIVITY_STREAM_COMMON();
const char *format;
const uint8_t *buffer;
size_t buffer_sz;
const uint8_t *privdata;
size_t privdata_sz;
const char *subsystem;
const char *category;
uint32_t oversize_id;
uint8_t ttl;
bool persisted;
} * os_log_message_t;
typedef struct os_trace_message_v2_s {
OS_ACTIVITY_STREAM_COMMON();
const char *format;
const void *buffer;
size_t bufferLen;
xpc_object_t __unsafe_unretained payload;
} * os_trace_message_v2_t;
typedef struct os_activity_useraction_s {
OS_ACTIVITY_STREAM_COMMON();
const char *action;
bool persisted;
} * os_activity_useraction_t;
typedef struct os_signpost_s {
OS_ACTIVITY_STREAM_COMMON();
const char *format;
const uint8_t *buffer;
size_t buffer_sz;
const uint8_t *privdata;
size_t privdata_sz;
const char *subsystem;
const char *category;
uint64_t duration_nsec;
uint32_t callstack_depth;
uint64_t callstack[OS_ACTIVITY_MAX_CALLSTACK];
} * os_signpost_t;
typedef struct os_activity_statedump_s {
OS_ACTIVITY_STREAM_COMMON();
char *message;
size_t message_size;
char image_path_buffer[PATH_MAX];
} * os_activity_statedump_t;
struct os_activity_stream_entry_s {
os_activity_stream_type_t type;
// information about the process streaming the data
pid_t pid;
uint64_t proc_id;
const uint8_t *proc_imageuuid;
const char *proc_imagepath;
// the activity associated with this streamed event
os_activity_id_t activity_id;
os_activity_id_t parent_id;
union {
struct os_activity_stream_common_s common;
struct os_activity_create_s activity_create;
struct os_activity_transition_s activity_transition;
struct os_log_message_s log_message;
struct os_trace_message_v2_s trace_message;
struct os_activity_useraction_s useraction;
struct os_signpost_s signpost;
struct os_activity_statedump_s statedump;
};
};
// Blocks
typedef bool (^os_activity_stream_block_t)(os_activity_stream_entry_t entry,
int error);
typedef void (^os_activity_stream_event_block_t)(
os_activity_stream_t stream, os_activity_stream_event_t event);
// SPI entry point prototypes
typedef os_activity_stream_t (*os_activity_stream_for_pid_t)(
pid_t pid, os_activity_stream_flag_t flags,
os_activity_stream_block_t stream_block);
typedef void (*os_activity_stream_resume_t)(os_activity_stream_t stream);
typedef void (*os_activity_stream_cancel_t)(os_activity_stream_t stream);
typedef char *(*os_log_copy_formatted_message_t)(os_log_message_t log_message);
typedef void (*os_activity_stream_set_event_handler_t)(
os_activity_stream_t stream, os_activity_stream_event_block_t block);
#endif /* ActivityStreamSPI_h */

View File

@ -0,0 +1,15 @@
# Due to sources including headers like:
# #include "MacOSX/i386/DNBArchImplI386.h"
# we must include the grandparent directory...
include_directories(${LLDB_SOURCE_DIR}/tools/debugserver/source)
add_library(lldbDebugserverDarwin_DarwinLog
ActivityStore.cpp
DarwinLogCollector.cpp
LogFilter.cpp
LogFilterChain.cpp
LogFilterExactMatch.cpp
LogFilterRegex.cpp
LogMessage.cpp
LogMessageOsLog.cpp
)

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,114 @@
//===-- DarwinLogCollector.h ------------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef DarwinLogCollector_h
#define DarwinLogCollector_h
#include <sys/types.h>
#include <memory>
#include <mutex>
#include <unordered_map>
#include "ActivityStore.h"
#include "ActivityStreamSPI.h"
#include "DNBDefs.h"
#include "DarwinLogEvent.h"
#include "DarwinLogInterfaces.h"
#include "JSON.h"
class DarwinLogCollector;
typedef std::shared_ptr<DarwinLogCollector> DarwinLogCollectorSP;
class DarwinLogCollector
: public std::enable_shared_from_this<DarwinLogCollector>,
public ActivityStore {
public:
//------------------------------------------------------------------
/// Return whether the os_log and activity tracing SPI is available.
///
/// @return \b true if the activity stream support is available,
/// \b false otherwise.
//------------------------------------------------------------------
static bool IsSupported();
//------------------------------------------------------------------
/// Return a log function suitable for DNBLog to use as the internal
/// logging function.
///
/// @return a DNBLog-style logging function if IsSupported() returns
/// true; otherwise, returns nullptr.
//------------------------------------------------------------------
static DNBCallbackLog GetLogFunction();
static bool StartCollectingForProcess(nub_process_t pid,
const JSONObject &config);
static bool CancelStreamForProcess(nub_process_t pid);
static DarwinLogEventVector GetEventsForProcess(nub_process_t pid);
~DarwinLogCollector();
pid_t GetProcessID() const { return m_pid; }
//------------------------------------------------------------------
// ActivityStore API
//------------------------------------------------------------------
const char *GetActivityForID(os_activity_id_t activity_id) const override;
std::string
GetActivityChainForID(os_activity_id_t activity_id) const override;
private:
DarwinLogCollector() = delete;
DarwinLogCollector(const DarwinLogCollector &) = delete;
DarwinLogCollector &operator=(const DarwinLogCollector &) = delete;
explicit DarwinLogCollector(nub_process_t pid,
const LogFilterChainSP &filter_chain_sp);
void SignalDataAvailable();
void SetActivityStream(os_activity_stream_t activity_stream);
bool HandleStreamEntry(os_activity_stream_entry_t entry, int error);
DarwinLogEventVector RemoveEvents();
void CancelActivityStream();
void GetActivityChainForID_internal(os_activity_id_t activity_id,
std::string &result, size_t depth) const;
struct ActivityInfo {
ActivityInfo(const char *name, os_activity_id_t activity_id,
os_activity_id_t parent_activity_id)
: m_name(name), m_id(activity_id), m_parent_id(parent_activity_id) {}
const std::string m_name;
const os_activity_id_t m_id;
const os_activity_id_t m_parent_id;
};
using ActivityMap = std::unordered_map<os_activity_id_t, ActivityInfo>;
const nub_process_t m_pid;
os_activity_stream_t m_activity_stream;
DarwinLogEventVector m_events;
std::mutex m_events_mutex;
LogFilterChainSP m_filter_chain_sp;
/// Mutex to protect activity info (activity name and parent structures)
mutable std::mutex m_activity_info_mutex;
/// Map of activity id to ActivityInfo
ActivityMap m_activity_map;
};
#endif /* LogStreamCollector_h */

View File

@ -0,0 +1,27 @@
//===-- DarwinLogEvent.h ----------------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef DarwinLogEvent_h
#define DarwinLogEvent_h
#include <memory>
#include <vector>
#include "JSONGenerator.h"
// =============================================================================
/// Each discrete unit of information is described as an event, such as
/// the emission of a single log message.
// =============================================================================
using DarwinLogEvent = JSONGenerator::Dictionary;
using DarwinLogEventSP = std::shared_ptr<DarwinLogEvent>;
using DarwinLogEventVector = std::vector<DarwinLogEventSP>;
#endif

View File

@ -0,0 +1,25 @@
//===-- DarwinLogInterfaces.h -----------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef DarwinLogInterfaces_h
#define DarwinLogInterfaces_h
#include <memory>
class ActivityStore;
class LogFilter;
using LogFilterSP = std::shared_ptr<LogFilter>;
class LogFilterChain;
using LogFilterChainSP = std::shared_ptr<LogFilterChain>;
class LogMessage;
#endif /* DarwinLogInterfaces_h */

View File

@ -0,0 +1,22 @@
//===-- DarwinLogTypes.h ----------------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef DarwinLogTypes_h
#define DarwinLogTypes_h
enum FilterTarget {
eFilterTargetInvalid,
eFilterTargetActivity,
eFilterTargetActivityChain,
eFilterTargetCategory,
eFilterTargetMessage,
eFilterTargetSubsystem
};
#endif /* DarwinLogTypes_h */

View File

@ -0,0 +1,12 @@
//===-- LogFilter.cpp -------------------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "LogFilter.h"
LogFilter::~LogFilter() {}

View File

@ -0,0 +1,30 @@
//===-- LogFilter.h ---------------------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef LogFilter_h
#define LogFilter_h
#include "DarwinLogInterfaces.h"
class LogFilter {
public:
virtual ~LogFilter();
virtual bool DoesMatch(const LogMessage &message) const = 0;
bool MatchesAreAccepted() const { return m_matches_accept; }
protected:
LogFilter(bool matches_accept) : m_matches_accept(matches_accept) {}
private:
bool m_matches_accept;
};
#endif /* LogFilter_h */

View File

@ -0,0 +1,42 @@
//===-- LogFilterChain.cpp --------------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "LogFilterChain.h"
#include "LogFilter.h"
LogFilterChain::LogFilterChain(bool default_accept)
: m_filters(), m_default_accept(default_accept) {}
void LogFilterChain::AppendFilter(const LogFilterSP &filter_sp) {
if (filter_sp)
m_filters.push_back(filter_sp);
}
void LogFilterChain::ClearFilterChain() { m_filters.clear(); }
bool LogFilterChain::GetDefaultAccepts() const { return m_default_accept; }
void LogFilterChain::SetDefaultAccepts(bool default_accept) {
m_default_accept = default_accept;
}
bool LogFilterChain::GetAcceptMessage(const LogMessage &message) const {
for (auto filter_sp : m_filters) {
if (filter_sp->DoesMatch(message)) {
// This message matches this filter. If the filter accepts matches,
// this message matches; otherwise, it rejects matches.
return filter_sp->MatchesAreAccepted();
}
}
// None of the filters matched. Therefore, we do whatever the
// default fall-through rule says.
return m_default_accept;
}

View File

@ -0,0 +1,38 @@
//===-- LogFilterChain.h ----------------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef LogFilterChain_h
#define LogFilterChain_h
#include <vector>
#include "DarwinLogInterfaces.h"
class LogFilterChain {
public:
LogFilterChain(bool default_accept);
void AppendFilter(const LogFilterSP &filter_sp);
void ClearFilterChain();
bool GetDefaultAccepts() const;
void SetDefaultAccepts(bool default_accepts);
bool GetAcceptMessage(const LogMessage &message) const;
private:
using FilterVector = std::vector<LogFilterSP>;
FilterVector m_filters;
bool m_default_accept;
};
#endif /* LogFilterChain_hpp */

View File

@ -0,0 +1,49 @@
//===-- LogFilterExactMatch.cpp ---------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "LogFilterExactMatch.h"
#include "LogMessage.h"
LogFilterExactMatch::LogFilterExactMatch(bool match_accepts,
FilterTarget filter_target,
const std::string &match_text)
: LogFilter(match_accepts), m_filter_target(filter_target),
m_match_text(match_text) {}
bool LogFilterExactMatch::DoesMatch(const LogMessage &message) const {
switch (m_filter_target) {
case eFilterTargetActivity:
// Empty fields never match a condition.
if (!message.HasActivity())
return false;
return m_match_text == message.GetActivity();
case eFilterTargetActivityChain:
// Empty fields never match a condition.
if (!message.HasActivity())
return false;
return m_match_text == message.GetActivityChain();
case eFilterTargetCategory:
// Empty fields never match a condition.
if (!message.HasCategory())
return false;
return m_match_text == message.GetCategory();
case eFilterTargetMessage: {
const char *message_text = message.GetMessage();
return (message_text != nullptr) && (m_match_text == message_text);
}
case eFilterTargetSubsystem:
// Empty fields never match a condition.
if (!message.HasSubsystem())
return false;
return m_match_text == message.GetSubsystem();
default:
// We don't know this type.
return false;
}
}

Some files were not shown because too many files have changed in this diff Show More