summaryrefslogtreecommitdiffstats
path: root/lldb/tools/debugserver/source/MacOSX/DarwinLog
diff options
context:
space:
mode:
authorKate Stone <katherine.stone@apple.com>2016-09-06 20:57:50 +0000
committerKate Stone <katherine.stone@apple.com>2016-09-06 20:57:50 +0000
commitb9c1b51e45b845debb76d8658edabca70ca56079 (patch)
treedfcb5a13ef2b014202340f47036da383eaee74aa /lldb/tools/debugserver/source/MacOSX/DarwinLog
parentd5aa73376966339caad04013510626ec2e42c760 (diff)
downloadbcm5719-llvm-b9c1b51e45b845debb76d8658edabca70ca56079.tar.gz
bcm5719-llvm-b9c1b51e45b845debb76d8658edabca70ca56079.zip
*** This commit represents a complete reformatting of the LLDB source code
*** to conform to clang-format’s LLVM style. This kind of mass change has *** two obvious implications: Firstly, merging this particular commit into a downstream fork may be a huge effort. Alternatively, it may be worth merging all changes up to this commit, performing the same reformatting operation locally, and then discarding the merge for this particular commit. The commands used to accomplish this reformatting were as follows (with current working directory as the root of the repository): find . \( -iname "*.c" -or -iname "*.cpp" -or -iname "*.h" -or -iname "*.mm" \) -exec clang-format -i {} + find . -iname "*.py" -exec autopep8 --in-place --aggressive --aggressive {} + ; The version of clang-format used was 3.9.0, and autopep8 was 1.2.4. Secondly, “blame” style tools will generally point to this commit instead of a meaningful prior commit. There are alternatives available that will attempt to look through this change and find the appropriate prior commit. YMMV. llvm-svn: 280751
Diffstat (limited to 'lldb/tools/debugserver/source/MacOSX/DarwinLog')
-rw-r--r--lldb/tools/debugserver/source/MacOSX/DarwinLog/ActivityStore.cpp8
-rw-r--r--lldb/tools/debugserver/source/MacOSX/DarwinLog/ActivityStore.h18
-rw-r--r--lldb/tools/debugserver/source/MacOSX/DarwinLog/ActivityStreamSPI.h241
-rw-r--r--lldb/tools/debugserver/source/MacOSX/DarwinLog/DarwinLogCollector.cpp1318
-rw-r--r--lldb/tools/debugserver/source/MacOSX/DarwinLog/DarwinLogCollector.h147
-rw-r--r--lldb/tools/debugserver/source/MacOSX/DarwinLog/DarwinLogTypes.h15
-rw-r--r--lldb/tools/debugserver/source/MacOSX/DarwinLog/LogFilter.cpp4
-rw-r--r--lldb/tools/debugserver/source/MacOSX/DarwinLog/LogFilter.h26
-rw-r--r--lldb/tools/debugserver/source/MacOSX/DarwinLog/LogFilterChain.cpp57
-rw-r--r--lldb/tools/debugserver/source/MacOSX/DarwinLog/LogFilterChain.h30
-rw-r--r--lldb/tools/debugserver/source/MacOSX/DarwinLog/LogFilterExactMatch.cpp74
-rw-r--r--lldb/tools/debugserver/source/MacOSX/DarwinLog/LogFilterExactMatch.h17
-rw-r--r--lldb/tools/debugserver/source/MacOSX/DarwinLog/LogFilterRegex.cpp151
-rw-r--r--lldb/tools/debugserver/source/MacOSX/DarwinLog/LogFilterRegex.h38
-rw-r--r--lldb/tools/debugserver/source/MacOSX/DarwinLog/LogMessage.cpp9
-rw-r--r--lldb/tools/debugserver/source/MacOSX/DarwinLog/LogMessage.h37
-rw-r--r--lldb/tools/debugserver/source/MacOSX/DarwinLog/LogMessageOsLog.cpp93
-rw-r--r--lldb/tools/debugserver/source/MacOSX/DarwinLog/LogMessageOsLog.h46
18 files changed, 997 insertions, 1332 deletions
diff --git a/lldb/tools/debugserver/source/MacOSX/DarwinLog/ActivityStore.cpp b/lldb/tools/debugserver/source/MacOSX/DarwinLog/ActivityStore.cpp
index e98a131512a..2cb653894db 100644
--- a/lldb/tools/debugserver/source/MacOSX/DarwinLog/ActivityStore.cpp
+++ b/lldb/tools/debugserver/source/MacOSX/DarwinLog/ActivityStore.cpp
@@ -9,10 +9,6 @@
#include "ActivityStore.h"
-ActivityStore::ActivityStore()
-{
-}
+ActivityStore::ActivityStore() {}
-ActivityStore::~ActivityStore()
-{
-}
+ActivityStore::~ActivityStore() {}
diff --git a/lldb/tools/debugserver/source/MacOSX/DarwinLog/ActivityStore.h b/lldb/tools/debugserver/source/MacOSX/DarwinLog/ActivityStore.h
index 2e998ba367c..35e0a85ad51 100644
--- a/lldb/tools/debugserver/source/MacOSX/DarwinLog/ActivityStore.h
+++ b/lldb/tools/debugserver/source/MacOSX/DarwinLog/ActivityStore.h
@@ -14,23 +14,17 @@
#include "ActivityStreamSPI.h"
-class ActivityStore
-{
+class ActivityStore {
public:
+ virtual ~ActivityStore();
- virtual
- ~ActivityStore();
+ virtual const char *GetActivityForID(os_activity_id_t activity_id) const = 0;
- virtual const char*
- GetActivityForID(os_activity_id_t activity_id) const = 0;
-
- virtual std::string
- GetActivityChainForID(os_activity_id_t activity_id) const = 0;
+ virtual std::string
+ GetActivityChainForID(os_activity_id_t activity_id) const = 0;
protected:
-
- ActivityStore();
-
+ ActivityStore();
};
#endif /* ActivityStore_h */
diff --git a/lldb/tools/debugserver/source/MacOSX/DarwinLog/ActivityStreamSPI.h b/lldb/tools/debugserver/source/MacOSX/DarwinLog/ActivityStreamSPI.h
index 4ddf13b3fcd..8aebc79e6ec 100644
--- a/lldb/tools/debugserver/source/MacOSX/DarwinLog/ActivityStreamSPI.h
+++ b/lldb/tools/debugserver/source/MacOSX/DarwinLog/ActivityStreamSPI.h
@@ -17,48 +17,45 @@
// 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
+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,
+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_TRACE_MESSAGE = 0x0300,
- OS_ACTIVITY_STREAM_TYPE_LOG_MESSAGE = 0x0400,
- OS_ACTIVITY_STREAM_TYPE_LEGACY_LOG_MESSAGE = 0x0480,
+ 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_SIGNPOST_BEGIN = 0x0601,
+ OS_ACTIVITY_STREAM_TYPE_SIGNPOST_END = 0x0602,
+ OS_ACTIVITY_STREAM_TYPE_SIGNPOST_EVENT = 0x0603,
- OS_ACTIVITY_STREAM_TYPE_STATEDUMP_EVENT = 0x0A00,
+ 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,
+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;
@@ -68,105 +65,104 @@ 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 \
-
+#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;
+ 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;
+ 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;
+ 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;
+ 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;
+ 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;
+ 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;
+ 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;
+ 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;
- };
+ 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
@@ -175,26 +171,21 @@ 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);
+ 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 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_resume_t)(os_activity_stream_t stream);
-typedef void
- (*os_activity_stream_cancel_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 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);
+typedef void (*os_activity_stream_set_event_handler_t)(
+ os_activity_stream_t stream, os_activity_stream_event_block_t block);
#endif /* ActivityStreamSPI_h */
diff --git a/lldb/tools/debugserver/source/MacOSX/DarwinLog/DarwinLogCollector.cpp b/lldb/tools/debugserver/source/MacOSX/DarwinLog/DarwinLogCollector.cpp
index 30f3e521669..982367092ed 100644
--- a/lldb/tools/debugserver/source/MacOSX/DarwinLog/DarwinLogCollector.cpp
+++ b/lldb/tools/debugserver/source/MacOSX/DarwinLog/DarwinLogCollector.cpp
@@ -16,9 +16,9 @@
#include <mutex>
#include <vector>
-#include "DarwinLogTypes.h"
#include "DNB.h"
#include "DNBLog.h"
+#include "DarwinLogTypes.h"
#include "LogFilterChain.h"
#include "LogFilterExactMatch.h"
#include "LogFilterRegex.h"
@@ -30,806 +30,668 @@
// Use an anonymous namespace for variables and methods that have no
// reason to leak out through the interface.
-namespace
-{
- /// Specify max depth that the activity parent-child chain will search
- /// back to get the full activity chain name. If we do more than this,
- /// we assume either we hit a loop or it's just too long.
- static const size_t MAX_ACTIVITY_CHAIN_DEPTH = 10;
-
- // Used to tap into and retrieve logs from target process.
- // (Consumer of os_log).
- static os_activity_stream_for_pid_t s_os_activity_stream_for_pid;
- static os_activity_stream_resume_t s_os_activity_stream_resume;
- static os_activity_stream_cancel_t s_os_activity_stream_cancel;
- static os_log_copy_formatted_message_t s_os_log_copy_formatted_message;
- static os_activity_stream_set_event_handler_t
+namespace {
+/// Specify max depth that the activity parent-child chain will search
+/// back to get the full activity chain name. If we do more than this,
+/// we assume either we hit a loop or it's just too long.
+static const size_t MAX_ACTIVITY_CHAIN_DEPTH = 10;
+
+// Used to tap into and retrieve logs from target process.
+// (Consumer of os_log).
+static os_activity_stream_for_pid_t s_os_activity_stream_for_pid;
+static os_activity_stream_resume_t s_os_activity_stream_resume;
+static os_activity_stream_cancel_t s_os_activity_stream_cancel;
+static os_log_copy_formatted_message_t s_os_log_copy_formatted_message;
+static os_activity_stream_set_event_handler_t
s_os_activity_stream_set_event_handler;
- bool
- LookupSPICalls()
- {
- static std::once_flag s_once_flag;
- static bool s_has_spi;
-
- std::call_once(s_once_flag, [] {
- s_os_activity_stream_for_pid = (os_activity_stream_for_pid_t)
- dlsym(RTLD_DEFAULT, "os_activity_stream_for_pid");
- s_os_activity_stream_resume = (os_activity_stream_resume_t)
- dlsym(RTLD_DEFAULT, "os_activity_stream_resume");
- s_os_activity_stream_cancel = (os_activity_stream_cancel_t)
- dlsym(RTLD_DEFAULT, "os_activity_stream_cancel");
- s_os_log_copy_formatted_message = (os_log_copy_formatted_message_t)
- dlsym(RTLD_DEFAULT, "os_log_copy_formatted_message");
- s_os_activity_stream_set_event_handler =
- (os_activity_stream_set_event_handler_t)
- dlsym(RTLD_DEFAULT, "os_activity_stream_set_event_handler");
-
- // We'll indicate we're all set if every function entry point
- // was found.
- s_has_spi =
- (s_os_activity_stream_for_pid != nullptr) &&
+bool LookupSPICalls() {
+ static std::once_flag s_once_flag;
+ static bool s_has_spi;
+
+ std::call_once(s_once_flag, [] {
+ s_os_activity_stream_for_pid = (os_activity_stream_for_pid_t)dlsym(
+ RTLD_DEFAULT, "os_activity_stream_for_pid");
+ s_os_activity_stream_resume = (os_activity_stream_resume_t)dlsym(
+ RTLD_DEFAULT, "os_activity_stream_resume");
+ s_os_activity_stream_cancel = (os_activity_stream_cancel_t)dlsym(
+ RTLD_DEFAULT, "os_activity_stream_cancel");
+ s_os_log_copy_formatted_message = (os_log_copy_formatted_message_t)dlsym(
+ RTLD_DEFAULT, "os_log_copy_formatted_message");
+ s_os_activity_stream_set_event_handler =
+ (os_activity_stream_set_event_handler_t)dlsym(
+ RTLD_DEFAULT, "os_activity_stream_set_event_handler");
+
+ // We'll indicate we're all set if every function entry point
+ // was found.
+ s_has_spi = (s_os_activity_stream_for_pid != nullptr) &&
(s_os_activity_stream_resume != nullptr) &&
(s_os_activity_stream_cancel != nullptr) &&
(s_os_log_copy_formatted_message != nullptr) &&
(s_os_activity_stream_set_event_handler != nullptr);
- if (s_has_spi)
- {
- DNBLogThreadedIf(LOG_DARWIN_LOG, "Found os_log SPI calls.");
- // Tell LogMessageOsLog how to format messages when search
- // criteria requires it.
- LogMessageOsLog::SetFormatterFunction(
- s_os_log_copy_formatted_message);
- }
- else
- {
- DNBLogThreadedIf(LOG_DARWIN_LOG, "Failed to find os_log SPI "
- "calls.");
- }
- });
-
- return s_has_spi;
+ if (s_has_spi) {
+ DNBLogThreadedIf(LOG_DARWIN_LOG, "Found os_log SPI calls.");
+ // Tell LogMessageOsLog how to format messages when search
+ // criteria requires it.
+ LogMessageOsLog::SetFormatterFunction(s_os_log_copy_formatted_message);
+ } else {
+ DNBLogThreadedIf(LOG_DARWIN_LOG, "Failed to find os_log SPI "
+ "calls.");
}
+ });
- using Mutex = std::mutex;
- static Mutex s_collector_mutex;
- static std::vector<DarwinLogCollectorSP> s_collectors;
+ return s_has_spi;
+}
- static void
- TrackCollector(const DarwinLogCollectorSP &collector_sp)
- {
- std::lock_guard<Mutex> locker(s_collector_mutex);
- if (std::find(s_collectors.begin(), s_collectors.end(), collector_sp)
- != s_collectors.end())
- {
- DNBLogThreadedIf(LOG_DARWIN_LOG,
- "attempted to add same collector multiple times");
- return;
- }
- s_collectors.push_back(collector_sp);
+using Mutex = std::mutex;
+static Mutex s_collector_mutex;
+static std::vector<DarwinLogCollectorSP> s_collectors;
+
+static void TrackCollector(const DarwinLogCollectorSP &collector_sp) {
+ std::lock_guard<Mutex> locker(s_collector_mutex);
+ if (std::find(s_collectors.begin(), s_collectors.end(), collector_sp) !=
+ s_collectors.end()) {
+ DNBLogThreadedIf(LOG_DARWIN_LOG,
+ "attempted to add same collector multiple times");
+ return;
+ }
+ s_collectors.push_back(collector_sp);
+}
+
+static void StopTrackingCollector(const DarwinLogCollectorSP &collector_sp) {
+ std::lock_guard<Mutex> locker(s_collector_mutex);
+ s_collectors.erase(
+ std::remove(s_collectors.begin(), s_collectors.end(), collector_sp),
+ s_collectors.end());
+}
+
+static DarwinLogCollectorSP FindCollectorForProcess(pid_t pid) {
+ std::lock_guard<Mutex> locker(s_collector_mutex);
+ for (const auto &collector_sp : s_collectors) {
+ if (collector_sp && (collector_sp->GetProcessID() == pid))
+ return collector_sp;
+ }
+ return DarwinLogCollectorSP();
+}
+
+static FilterTarget TargetStringToEnum(const std::string &filter_target_name) {
+ if (filter_target_name == "activity")
+ return eFilterTargetActivity;
+ else if (filter_target_name == "activity-chain")
+ return eFilterTargetActivityChain;
+ else if (filter_target_name == "category")
+ return eFilterTargetCategory;
+ else if (filter_target_name == "message")
+ return eFilterTargetMessage;
+ else if (filter_target_name == "subsystem")
+ return eFilterTargetSubsystem;
+ else
+ return eFilterTargetInvalid;
+}
+
+class Configuration {
+public:
+ Configuration(const JSONObject &config)
+ : m_is_valid(false),
+ m_activity_stream_flags(OS_ACTIVITY_STREAM_PROCESS_ONLY),
+ m_filter_chain_sp(nullptr) {
+ // Parse out activity stream flags
+ if (!ParseSourceFlags(config)) {
+ m_is_valid = false;
+ return;
}
- static void
- StopTrackingCollector(const DarwinLogCollectorSP &collector_sp)
- {
- std::lock_guard<Mutex> locker(s_collector_mutex);
- s_collectors.erase(std::remove(s_collectors.begin(), s_collectors.end(),
- collector_sp),
- s_collectors.end());
+ // Parse filter rules
+ if (!ParseFilterRules(config)) {
+ m_is_valid = false;
+ return;
}
- static DarwinLogCollectorSP
- FindCollectorForProcess(pid_t pid)
- {
- std::lock_guard<Mutex> locker(s_collector_mutex);
- for (const auto &collector_sp : s_collectors)
- {
- if (collector_sp && (collector_sp->GetProcessID() == pid))
- return collector_sp;
- }
- return DarwinLogCollectorSP();
+ // Everything worked.
+ m_is_valid = true;
+ }
+
+ bool ParseSourceFlags(const JSONObject &config) {
+ // Get the source-flags dictionary.
+ auto source_flags_sp = config.GetObject("source-flags");
+ if (!source_flags_sp)
+ return false;
+ if (!JSONObject::classof(source_flags_sp.get()))
+ return false;
+
+ const JSONObject &source_flags =
+ *static_cast<JSONObject *>(source_flags_sp.get());
+
+ // Parse out the flags.
+ bool include_any_process = false;
+ bool include_callstacks = false;
+ bool include_info_level = false;
+ bool include_debug_level = false;
+ bool live_stream = false;
+
+ if (!source_flags.GetObjectAsBool("any-process", include_any_process)) {
+ DNBLogThreadedIf(LOG_DARWIN_LOG, "Source-flag 'any-process' missing from "
+ "configuration.");
+ return false;
+ }
+ if (!source_flags.GetObjectAsBool("callstacks", include_callstacks)) {
+ // We currently suppress the availability of this on the lldb
+ // side. We include here for devices when we enable in the
+ // future.
+ // DNBLogThreadedIf(LOG_DARWIN_LOG,
+ // "Source-flag 'callstacks' missing from "
+ // "configuration.");
+
+ // OK. We just skip callstacks.
+ // return false;
+ }
+ if (!source_flags.GetObjectAsBool("info-level", include_info_level)) {
+ DNBLogThreadedIf(LOG_DARWIN_LOG, "Source-flag 'info-level' missing from "
+ "configuration.");
+ return false;
+ }
+ if (!source_flags.GetObjectAsBool("debug-level", include_debug_level)) {
+ DNBLogThreadedIf(LOG_DARWIN_LOG, "Source-flag 'debug-level' missing from "
+ "configuration.");
+ return false;
+ }
+ if (!source_flags.GetObjectAsBool("live-stream", live_stream)) {
+ DNBLogThreadedIf(LOG_DARWIN_LOG, "Source-flag 'live-stream' missing from "
+ "configuration.");
+ return false;
}
- static FilterTarget
- TargetStringToEnum(const std::string &filter_target_name)
- {
- if (filter_target_name == "activity")
- return eFilterTargetActivity;
- else if (filter_target_name == "activity-chain")
- return eFilterTargetActivityChain;
- else if (filter_target_name == "category")
- return eFilterTargetCategory;
- else if (filter_target_name == "message")
- return eFilterTargetMessage;
- else if (filter_target_name == "subsystem")
- return eFilterTargetSubsystem;
- else
- return eFilterTargetInvalid;
+ // Setup the SPI flags based on this.
+ m_activity_stream_flags = 0;
+ if (!include_any_process)
+ m_activity_stream_flags |= OS_ACTIVITY_STREAM_PROCESS_ONLY;
+ if (include_callstacks)
+ m_activity_stream_flags |= OS_ACTIVITY_STREAM_CALLSTACK;
+ if (include_info_level)
+ m_activity_stream_flags |= OS_ACTIVITY_STREAM_INFO;
+ if (include_debug_level)
+ m_activity_stream_flags |= OS_ACTIVITY_STREAM_DEBUG;
+ if (!live_stream)
+ m_activity_stream_flags |= OS_ACTIVITY_STREAM_BUFFERED;
+
+ DNBLogThreadedIf(LOG_DARWIN_LOG, "m_activity_stream_flags = 0x%03x",
+ m_activity_stream_flags);
+
+ return true;
+ }
+
+ bool ParseFilterRules(const JSONObject &config) {
+ // Retrieve the default rule.
+ bool filter_default_accept = true;
+ if (!config.GetObjectAsBool("filter-fall-through-accepts",
+ filter_default_accept)) {
+ DNBLogThreadedIf(LOG_DARWIN_LOG, "Setting 'filter-fall-through-accepts' "
+ "missing from configuration.");
+ return false;
}
+ m_filter_chain_sp.reset(new LogFilterChain(filter_default_accept));
+ DNBLogThreadedIf(LOG_DARWIN_LOG, "DarwinLog no-match rule: %s.",
+ filter_default_accept ? "accept" : "reject");
+
+ // If we don't have the filter-rules array, we're done.
+ auto filter_rules_sp = config.GetObject("filter-rules");
+ if (!filter_rules_sp) {
+ DNBLogThreadedIf(LOG_DARWIN_LOG,
+ "No 'filter-rules' config element, all log "
+ "entries will use the no-match action (%s).",
+ filter_default_accept ? "accept" : "reject");
+ return true;
+ }
+ if (!JSONArray::classof(filter_rules_sp.get()))
+ return false;
+ const JSONArray &rules_config =
+ *static_cast<JSONArray *>(filter_rules_sp.get());
+
+ // Create the filters.
+ for (auto &rule_sp : rules_config.m_elements) {
+ if (!JSONObject::classof(rule_sp.get()))
+ return false;
+ const JSONObject &rule_config = *static_cast<JSONObject *>(rule_sp.get());
- class Configuration
- {
- public:
+ // Get whether this filter accepts or rejects.
+ bool filter_accepts = true;
+ if (!rule_config.GetObjectAsBool("accept", filter_accepts)) {
+ DNBLogThreadedIf(LOG_DARWIN_LOG, "Filter 'accept' element missing.");
+ return false;
+ }
- Configuration(const JSONObject &config) :
- m_is_valid(false),
- m_activity_stream_flags(OS_ACTIVITY_STREAM_PROCESS_ONLY),
- m_filter_chain_sp(nullptr)
- {
- // Parse out activity stream flags
- if (!ParseSourceFlags(config))
- {
- m_is_valid = false;
- return;
- }
-
- // Parse filter rules
- if (!ParseFilterRules(config))
- {
- m_is_valid = false;
- return;
- }
-
- // Everything worked.
- m_is_valid = true;
- }
+ // Grab the target log field attribute for the match.
+ std::string target_attribute;
+ if (!rule_config.GetObjectAsString("attribute", target_attribute)) {
+ DNBLogThreadedIf(LOG_DARWIN_LOG, "Filter 'attribute' element missing.");
+ return false;
+ }
+ auto target_enum = TargetStringToEnum(target_attribute);
+ if (target_enum == eFilterTargetInvalid) {
+ DNBLogThreadedIf(LOG_DARWIN_LOG, "Filter attribute '%s' unsupported.",
+ target_attribute.c_str());
+ return false;
+ }
- bool
- ParseSourceFlags(const JSONObject &config)
- {
- // Get the source-flags dictionary.
- auto source_flags_sp = config.GetObject("source-flags");
- if (!source_flags_sp)
- return false;
- if (!JSONObject::classof(source_flags_sp.get()))
- return false;
-
- const JSONObject &source_flags =
- *static_cast<JSONObject*>(source_flags_sp.get());
-
- // Parse out the flags.
- bool include_any_process = false;
- bool include_callstacks = false;
- bool include_info_level = false;
- bool include_debug_level = false;
- bool live_stream = false;
-
- if (!source_flags.GetObjectAsBool("any-process",
- include_any_process))
- {
- DNBLogThreadedIf(LOG_DARWIN_LOG,
- "Source-flag 'any-process' missing from "
- "configuration.");
- return false;
- }
- if (!source_flags.GetObjectAsBool("callstacks",
- include_callstacks))
- {
- // We currently suppress the availability of this on the lldb
- // side. We include here for devices when we enable in the
- // future.
- // DNBLogThreadedIf(LOG_DARWIN_LOG,
- // "Source-flag 'callstacks' missing from "
- // "configuration.");
-
- // OK. We just skip callstacks.
- // return false;
- }
- if (!source_flags.GetObjectAsBool("info-level",
- include_info_level))
- {
- DNBLogThreadedIf(LOG_DARWIN_LOG,
- "Source-flag 'info-level' missing from "
- "configuration.");
- return false;
- }
- if (!source_flags.GetObjectAsBool("debug-level",
- include_debug_level))
- {
- DNBLogThreadedIf(LOG_DARWIN_LOG,
- "Source-flag 'debug-level' missing from "
- "configuration.");
- return false;
- }
- if (!source_flags.GetObjectAsBool("live-stream",
- live_stream))
- {
- DNBLogThreadedIf(LOG_DARWIN_LOG,
- "Source-flag 'live-stream' missing from "
- "configuration.");
- return false;
- }
-
- // Setup the SPI flags based on this.
- m_activity_stream_flags = 0;
- if (!include_any_process)
- m_activity_stream_flags |= OS_ACTIVITY_STREAM_PROCESS_ONLY;
- if (include_callstacks)
- m_activity_stream_flags |= OS_ACTIVITY_STREAM_CALLSTACK;
- if (include_info_level)
- m_activity_stream_flags |= OS_ACTIVITY_STREAM_INFO;
- if (include_debug_level)
- m_activity_stream_flags |= OS_ACTIVITY_STREAM_DEBUG;
- if (!live_stream)
- m_activity_stream_flags |= OS_ACTIVITY_STREAM_BUFFERED;
-
- DNBLogThreadedIf(LOG_DARWIN_LOG, "m_activity_stream_flags = 0x%03x",
- m_activity_stream_flags);
-
- return true;
+ // Handle operation-specific fields and filter creation.
+ std::string filter_type;
+ if (!rule_config.GetObjectAsString("type", filter_type)) {
+ DNBLogThreadedIf(LOG_DARWIN_LOG, "Filter 'type' element missing.");
+ return false;
+ }
+ DNBLogThreadedIf(LOG_DARWIN_LOG, "Reading filter of type '%s'",
+ filter_type.c_str());
+
+ LogFilterSP filter_sp;
+ if (filter_type == "regex") {
+ // Grab the regex for the match.
+ std::string regex;
+ if (!rule_config.GetObjectAsString("regex", regex)) {
+ DNBLogError("Regex filter missing 'regex' element.");
+ return false;
}
-
- bool
- ParseFilterRules(const JSONObject &config)
- {
- // Retrieve the default rule.
- bool filter_default_accept = true;
- if (!config.GetObjectAsBool("filter-fall-through-accepts",
- filter_default_accept))
- {
- DNBLogThreadedIf(LOG_DARWIN_LOG,
- "Setting 'filter-fall-through-accepts' "
- "missing from configuration.");
- return false;
- }
- m_filter_chain_sp.reset(new LogFilterChain(filter_default_accept));
- DNBLogThreadedIf(LOG_DARWIN_LOG,
- "DarwinLog no-match rule: %s.",
- filter_default_accept ? "accept" : "reject");
-
- // If we don't have the filter-rules array, we're done.
- auto filter_rules_sp = config.GetObject("filter-rules");
- if (!filter_rules_sp)
- {
- DNBLogThreadedIf(LOG_DARWIN_LOG,
- "No 'filter-rules' config element, all log "
- "entries will use the no-match action (%s).",
- filter_default_accept ? "accept" : "reject");
- return true;
- }
- if (!JSONArray::classof(filter_rules_sp.get()))
- return false;
- const JSONArray &rules_config =
- *static_cast<JSONArray*>(filter_rules_sp.get());
-
- // Create the filters.
- for (auto &rule_sp : rules_config.m_elements)
- {
- if (!JSONObject::classof(rule_sp.get()))
- return false;
- const JSONObject &rule_config = *static_cast<JSONObject*>
- (rule_sp.get());
-
- // Get whether this filter accepts or rejects.
- bool filter_accepts = true;
- if (!rule_config.GetObjectAsBool("accept", filter_accepts))
- {
- DNBLogThreadedIf(LOG_DARWIN_LOG,
- "Filter 'accept' element missing.");
- return false;
- }
-
- // Grab the target log field attribute for the match.
- std::string target_attribute;
- if (!rule_config.GetObjectAsString("attribute",
- target_attribute))
- {
- DNBLogThreadedIf(LOG_DARWIN_LOG,
- "Filter 'attribute' element missing.");
- return false;
- }
- auto target_enum = TargetStringToEnum(target_attribute);
- if (target_enum == eFilterTargetInvalid)
- {
- DNBLogThreadedIf(LOG_DARWIN_LOG,
- "Filter attribute '%s' unsupported.",
- target_attribute.c_str());
- return false;
- }
-
- // Handle operation-specific fields and filter creation.
- std::string filter_type;
- if (!rule_config.GetObjectAsString("type", filter_type))
- {
- DNBLogThreadedIf(LOG_DARWIN_LOG,
- "Filter 'type' element missing.");
- return false;
- }
- DNBLogThreadedIf(LOG_DARWIN_LOG,
- "Reading filter of type '%s'", filter_type
- .c_str());
-
- LogFilterSP filter_sp;
- if (filter_type == "regex")
- {
- // Grab the regex for the match.
- std::string regex;
- if (!rule_config.GetObjectAsString("regex",
- regex))
- {
- DNBLogError("Regex filter missing 'regex' element.");
- return false;
- }
- DNBLogThreadedIf(LOG_DARWIN_LOG,
- "regex for filter: \"%s\"", regex.c_str());
-
- // Create the regex filter.
- auto regex_filter =
- new LogFilterRegex(filter_accepts, target_enum, regex);
- filter_sp.reset(regex_filter);
-
- // Validate that the filter is okay.
- if (!regex_filter->IsValid())
- {
- DNBLogError("Invalid regex in filter: "
- "regex=\"%s\", error=%s",
- regex.c_str(),
- regex_filter->GetErrorAsCString());
- return false;
- }
- }
- else if (filter_type == "match")
- {
- // Grab the regex for the match.
- std::string exact_text;
- if (!rule_config.GetObjectAsString("exact_text",
- exact_text))
- {
- DNBLogError("Exact match filter missing "
- "'exact_text' element.");
- return false;
- }
-
- // Create the filter.
- filter_sp.reset(new LogFilterExactMatch(filter_accepts,
- target_enum,
- exact_text));
- }
-
- // Add the filter to the chain.
- m_filter_chain_sp->AppendFilter(filter_sp);
- }
- return true;
+ DNBLogThreadedIf(LOG_DARWIN_LOG, "regex for filter: \"%s\"",
+ regex.c_str());
+
+ // Create the regex filter.
+ auto regex_filter =
+ new LogFilterRegex(filter_accepts, target_enum, regex);
+ filter_sp.reset(regex_filter);
+
+ // Validate that the filter is okay.
+ if (!regex_filter->IsValid()) {
+ DNBLogError("Invalid regex in filter: "
+ "regex=\"%s\", error=%s",
+ regex.c_str(), regex_filter->GetErrorAsCString());
+ return false;
}
-
- bool
- IsValid() const
- {
- return m_is_valid;
+ } else if (filter_type == "match") {
+ // Grab the regex for the match.
+ std::string exact_text;
+ if (!rule_config.GetObjectAsString("exact_text", exact_text)) {
+ DNBLogError("Exact match filter missing "
+ "'exact_text' element.");
+ return false;
}
- os_activity_stream_flag_t
- GetActivityStreamFlags() const
- {
- return m_activity_stream_flags;
- }
+ // Create the filter.
+ filter_sp.reset(
+ new LogFilterExactMatch(filter_accepts, target_enum, exact_text));
+ }
- const LogFilterChainSP &
- GetLogFilterChain() const
- {
- return m_filter_chain_sp;
- }
+ // Add the filter to the chain.
+ m_filter_chain_sp->AppendFilter(filter_sp);
+ }
+ return true;
+ }
+
+ bool IsValid() const { return m_is_valid; }
- private:
+ os_activity_stream_flag_t GetActivityStreamFlags() const {
+ return m_activity_stream_flags;
+ }
- bool m_is_valid;
- os_activity_stream_flag_t m_activity_stream_flags;
- LogFilterChainSP m_filter_chain_sp;
+ const LogFilterChainSP &GetLogFilterChain() const {
+ return m_filter_chain_sp;
+ }
- };
+private:
+ bool m_is_valid;
+ os_activity_stream_flag_t m_activity_stream_flags;
+ LogFilterChainSP m_filter_chain_sp;
+};
}
-bool
-DarwinLogCollector::IsSupported()
-{
- // We're supported if we have successfully looked up the SPI entry points.
- return LookupSPICalls();
+bool DarwinLogCollector::IsSupported() {
+ // We're supported if we have successfully looked up the SPI entry points.
+ return LookupSPICalls();
}
-bool
-DarwinLogCollector::StartCollectingForProcess(nub_process_t pid,
- const JSONObject &config)
-{
- // If we're currently collecting for this process, kill the existing
- // collector.
- if (CancelStreamForProcess(pid))
- {
- DNBLogThreadedIf(LOG_DARWIN_LOG,
- "%s() killed existing DarwinLog collector for pid %d.",
- __FUNCTION__, pid);
+bool DarwinLogCollector::StartCollectingForProcess(nub_process_t pid,
+ const JSONObject &config) {
+ // If we're currently collecting for this process, kill the existing
+ // collector.
+ if (CancelStreamForProcess(pid)) {
+ DNBLogThreadedIf(LOG_DARWIN_LOG,
+ "%s() killed existing DarwinLog collector for pid %d.",
+ __FUNCTION__, pid);
+ }
+
+ // If the process isn't alive, we're done.
+ if (!DNBProcessIsAlive(pid)) {
+ DNBLogThreadedIf(LOG_DARWIN_LOG,
+ "%s() cannot collect for pid %d: process not alive.",
+ __FUNCTION__, pid);
+ return false;
+ }
+
+ // Validate the configuration.
+ auto spi_config = Configuration(config);
+ if (!spi_config.IsValid()) {
+ DNBLogThreadedIf(LOG_DARWIN_LOG,
+ "%s() invalid configuration, will not enable log "
+ "collection",
+ __FUNCTION__);
+ return false;
+ }
+
+ // Create the stream collector that will manage collected data
+ // for this pid.
+ DarwinLogCollectorSP collector_sp(
+ new DarwinLogCollector(pid, spi_config.GetLogFilterChain()));
+ std::weak_ptr<DarwinLogCollector> collector_wp(collector_sp);
+
+ // Setup the stream handling block.
+ os_activity_stream_block_t block =
+ ^bool(os_activity_stream_entry_t entry, int error) {
+ // Check if our collector is still alive.
+ DarwinLogCollectorSP inner_collector_sp = collector_wp.lock();
+ if (!inner_collector_sp)
+ return false;
+ return inner_collector_sp->HandleStreamEntry(entry, error);
+ };
+
+ os_activity_stream_event_block_t stream_event_block = ^void(
+ os_activity_stream_t stream, os_activity_stream_event_t event) {
+ switch (event) {
+ case OS_ACTIVITY_STREAM_EVENT_STARTED:
+ DNBLogThreadedIf(LOG_DARWIN_LOG,
+ "received stream event: "
+ "OS_ACTIVITY_STREAM_EVENT_STARTED, stream %p.",
+ (void *)stream);
+ break;
+ case OS_ACTIVITY_STREAM_EVENT_STOPPED:
+ DNBLogThreadedIf(LOG_DARWIN_LOG,
+ "received stream event: "
+ "OS_ACTIVITY_STREAM_EVENT_STOPPED, stream %p.",
+ (void *)stream);
+ break;
+ case OS_ACTIVITY_STREAM_EVENT_FAILED:
+ DNBLogThreadedIf(LOG_DARWIN_LOG,
+ "received stream event: "
+ "OS_ACTIVITY_STREAM_EVENT_FAILED, stream %p.",
+ (void *)stream);
+ break;
+ case OS_ACTIVITY_STREAM_EVENT_CHUNK_STARTED:
+ DNBLogThreadedIf(LOG_DARWIN_LOG,
+ "received stream event: "
+ "OS_ACTIVITY_STREAM_EVENT_CHUNK_STARTED, stream %p.",
+ (void *)stream);
+ break;
+ case OS_ACTIVITY_STREAM_EVENT_CHUNK_FINISHED:
+ DNBLogThreadedIf(LOG_DARWIN_LOG,
+ "received stream event: "
+ "OS_ACTIVITY_STREAM_EVENT_CHUNK_FINISHED, stream %p.",
+ (void *)stream);
+ break;
}
+ };
- // If the process isn't alive, we're done.
- if (!DNBProcessIsAlive(pid))
- {
- DNBLogThreadedIf(LOG_DARWIN_LOG,
- "%s() cannot collect for pid %d: process not alive.",
- __FUNCTION__, pid);
- return false;
- }
+ // Create the stream.
+ os_activity_stream_t activity_stream = (*s_os_activity_stream_for_pid)(
+ pid, spi_config.GetActivityStreamFlags(), block);
+ collector_sp->SetActivityStream(activity_stream);
- // Validate the configuration.
- auto spi_config = Configuration(config);
- if (!spi_config.IsValid())
- {
- DNBLogThreadedIf(LOG_DARWIN_LOG,
- "%s() invalid configuration, will not enable log "
- "collection", __FUNCTION__);
- return false;
- }
+ // Specify the stream-related event handler.
+ (*s_os_activity_stream_set_event_handler)(activity_stream,
+ stream_event_block);
- // Create the stream collector that will manage collected data
- // for this pid.
- DarwinLogCollectorSP collector_sp(new DarwinLogCollector(pid,
- spi_config.GetLogFilterChain()));
- std::weak_ptr<DarwinLogCollector> collector_wp(collector_sp);
+ // Start the stream.
+ (*s_os_activity_stream_resume)(activity_stream);
- // Setup the stream handling block.
- os_activity_stream_block_t block = ^bool (os_activity_stream_entry_t entry,
- int error) {
- // Check if our collector is still alive.
- DarwinLogCollectorSP inner_collector_sp = collector_wp.lock();
- if (!inner_collector_sp)
- return false;
- return inner_collector_sp->HandleStreamEntry(entry, error);
- };
-
- os_activity_stream_event_block_t stream_event_block =
- ^void (os_activity_stream_t stream, os_activity_stream_event_t event) {
- switch (event)
- {
- case OS_ACTIVITY_STREAM_EVENT_STARTED:
- DNBLogThreadedIf(LOG_DARWIN_LOG, "received stream event: "
- "OS_ACTIVITY_STREAM_EVENT_STARTED, stream %p.",
- (void*)stream);
- break;
- case OS_ACTIVITY_STREAM_EVENT_STOPPED:
- DNBLogThreadedIf(LOG_DARWIN_LOG, "received stream event: "
- "OS_ACTIVITY_STREAM_EVENT_STOPPED, stream %p.",
- (void*)stream);
- break;
- case OS_ACTIVITY_STREAM_EVENT_FAILED:
- DNBLogThreadedIf(LOG_DARWIN_LOG, "received stream event: "
- "OS_ACTIVITY_STREAM_EVENT_FAILED, stream %p.",
- (void*)stream);
- break;
- case OS_ACTIVITY_STREAM_EVENT_CHUNK_STARTED:
- DNBLogThreadedIf(LOG_DARWIN_LOG, "received stream event: "
- "OS_ACTIVITY_STREAM_EVENT_CHUNK_STARTED, stream %p.",
- (void*)stream);
- break;
- case OS_ACTIVITY_STREAM_EVENT_CHUNK_FINISHED:
- DNBLogThreadedIf(LOG_DARWIN_LOG, "received stream event: "
- "OS_ACTIVITY_STREAM_EVENT_CHUNK_FINISHED, stream %p.",
- (void*)stream);
- break;
- }
- };
-
- // Create the stream.
- os_activity_stream_t activity_stream =
- (*s_os_activity_stream_for_pid)(pid,
- spi_config.GetActivityStreamFlags(),
- block);
- collector_sp->SetActivityStream(activity_stream);
-
- // Specify the stream-related event handler.
- (*s_os_activity_stream_set_event_handler)(
- activity_stream, stream_event_block);
-
- // Start the stream.
- (*s_os_activity_stream_resume)(activity_stream);
-
- TrackCollector(collector_sp);
- return true;
+ TrackCollector(collector_sp);
+ return true;
}
DarwinLogEventVector
-DarwinLogCollector::GetEventsForProcess(nub_process_t pid)
-{
- auto collector_sp = FindCollectorForProcess(pid);
- if (!collector_sp)
- {
- // We're not tracking a stream for this process.
- return DarwinLogEventVector();
- }
-
- return collector_sp->RemoveEvents();
+DarwinLogCollector::GetEventsForProcess(nub_process_t pid) {
+ auto collector_sp = FindCollectorForProcess(pid);
+ if (!collector_sp) {
+ // We're not tracking a stream for this process.
+ return DarwinLogEventVector();
+ }
+
+ return collector_sp->RemoveEvents();
}
-bool
-DarwinLogCollector::CancelStreamForProcess(nub_process_t pid)
-{
- auto collector_sp = FindCollectorForProcess(pid);
- if (!collector_sp)
- {
- // We're not tracking a stream for this process.
- return false;
- }
+bool DarwinLogCollector::CancelStreamForProcess(nub_process_t pid) {
+ auto collector_sp = FindCollectorForProcess(pid);
+ if (!collector_sp) {
+ // We're not tracking a stream for this process.
+ return false;
+ }
- collector_sp->CancelActivityStream();
- StopTrackingCollector(collector_sp);
+ collector_sp->CancelActivityStream();
+ StopTrackingCollector(collector_sp);
- return true;
+ return true;
}
-const char*
-DarwinLogCollector::GetActivityForID(os_activity_id_t activity_id) const
-{
- auto find_it = m_activity_map.find(activity_id);
- return (find_it != m_activity_map.end()) ?
- find_it->second.m_name.c_str() :
- nullptr;
+const char *
+DarwinLogCollector::GetActivityForID(os_activity_id_t activity_id) const {
+ auto find_it = m_activity_map.find(activity_id);
+ return (find_it != m_activity_map.end()) ? find_it->second.m_name.c_str()
+ : nullptr;
}
/// Retrieve the full parent-child chain for activity names. These
/// can be arbitrarily deep. This method assumes the caller has already
/// locked the activity mutex.
-void
-DarwinLogCollector::GetActivityChainForID_internal(os_activity_id_t activity_id,
- std::string &result,
- size_t depth) const
-{
- if (depth > MAX_ACTIVITY_CHAIN_DEPTH)
- {
- // Terminating condition - too deeply nested.
- return;
- }
- else if (activity_id == 0)
- {
- // Terminating condition - no activity.
- return;
- }
-
- auto find_it = m_activity_map.find(activity_id);
- if (find_it == m_activity_map.end())
- {
- //Terminating condition - no data for activity_id.
- return;
- }
-
- // Activity name becomes parent activity name chain + ':' + our activity
- // name.
- GetActivityChainForID_internal(find_it->second.m_parent_id, result,
- depth + 1);
- if (!result.empty())
- result += ':';
- result += find_it->second.m_name;
+void DarwinLogCollector::GetActivityChainForID_internal(
+ os_activity_id_t activity_id, std::string &result, size_t depth) const {
+ if (depth > MAX_ACTIVITY_CHAIN_DEPTH) {
+ // Terminating condition - too deeply nested.
+ return;
+ } else if (activity_id == 0) {
+ // Terminating condition - no activity.
+ return;
+ }
+
+ auto find_it = m_activity_map.find(activity_id);
+ if (find_it == m_activity_map.end()) {
+ // Terminating condition - no data for activity_id.
+ return;
+ }
+
+ // Activity name becomes parent activity name chain + ':' + our activity
+ // name.
+ GetActivityChainForID_internal(find_it->second.m_parent_id, result,
+ depth + 1);
+ if (!result.empty())
+ result += ':';
+ result += find_it->second.m_name;
}
std::string
-DarwinLogCollector::GetActivityChainForID(os_activity_id_t activity_id) const
-{
- std::string result;
- {
- std::lock_guard<std::mutex> locker(m_activity_info_mutex);
- GetActivityChainForID_internal(activity_id, result, 1);
- }
- return result;
+DarwinLogCollector::GetActivityChainForID(os_activity_id_t activity_id) const {
+ std::string result;
+ {
+ std::lock_guard<std::mutex> locker(m_activity_info_mutex);
+ GetActivityChainForID_internal(activity_id, result, 1);
+ }
+ return result;
}
DarwinLogCollector::DarwinLogCollector(nub_process_t pid,
- const LogFilterChainSP &filter_chain_sp):
- ActivityStore(),
- m_pid(pid),
- m_activity_stream(0),
- m_events(),
- m_events_mutex(),
- m_filter_chain_sp(filter_chain_sp),
- m_activity_info_mutex(),
- m_activity_map()
-{
+ const LogFilterChainSP &filter_chain_sp)
+ : ActivityStore(), m_pid(pid), m_activity_stream(0), m_events(),
+ m_events_mutex(), m_filter_chain_sp(filter_chain_sp),
+ m_activity_info_mutex(), m_activity_map() {}
+
+DarwinLogCollector::~DarwinLogCollector() {
+ // Cancel the stream.
+ if (m_activity_stream) {
+ DNBLogThreadedIf(LOG_DARWIN_LOG, "tearing down activity stream "
+ "collector for %d",
+ m_pid);
+ (*s_os_activity_stream_cancel)(m_activity_stream);
+ m_activity_stream = 0;
+ } else {
+ DNBLogThreadedIf(LOG_DARWIN_LOG, "no stream to tear down for %d", m_pid);
+ }
}
-DarwinLogCollector::~DarwinLogCollector()
-{
- // Cancel the stream.
- if (m_activity_stream)
- {
- DNBLogThreadedIf(LOG_DARWIN_LOG, "tearing down activity stream "
- "collector for %d", m_pid);
- (*s_os_activity_stream_cancel)(m_activity_stream);
- m_activity_stream = 0;
- }
- else
- {
- DNBLogThreadedIf(LOG_DARWIN_LOG, "no stream to tear down for %d",
- m_pid);
- }
+void DarwinLogCollector::SignalDataAvailable() {
+ RNBRemoteSP remoteSP(g_remoteSP);
+ if (!remoteSP) {
+ // We're done. This is unexpected.
+ StopTrackingCollector(shared_from_this());
+ return;
+ }
+
+ RNBContext &ctx = remoteSP->Context();
+ ctx.Events().SetEvents(RNBContext::event_darwin_log_data_available);
+ // Wait for the main thread to consume this notification if it requested
+ // we wait for it.
+ ctx.Events().WaitForResetAck(RNBContext::event_darwin_log_data_available);
+}
+
+void DarwinLogCollector::SetActivityStream(
+ os_activity_stream_t activity_stream) {
+ m_activity_stream = activity_stream;
}
-void
-DarwinLogCollector::SignalDataAvailable()
-{
- RNBRemoteSP remoteSP(g_remoteSP);
- if (!remoteSP)
- {
- // We're done. This is unexpected.
- StopTrackingCollector(shared_from_this());
- return;
+bool DarwinLogCollector::HandleStreamEntry(os_activity_stream_entry_t entry,
+ int error) {
+ if ((error == 0) && (entry != nullptr)) {
+ if (entry->pid != m_pid) {
+ // For now, skip messages not originating from our process.
+ // Later we might want to keep all messages related to an event
+ // that we're tracking, even when it came from another process,
+ // possibly doing work on our behalf.
+ return true;
}
- RNBContext& ctx = remoteSP->Context();
- ctx.Events().SetEvents(RNBContext::event_darwin_log_data_available);
- // Wait for the main thread to consume this notification if it requested
- // we wait for it.
- ctx.Events().WaitForResetAck(RNBContext::event_darwin_log_data_available);
-}
+ switch (entry->type) {
+ case OS_ACTIVITY_STREAM_TYPE_ACTIVITY_CREATE:
+ DNBLogThreadedIf(
+ LOG_DARWIN_LOG, "received activity create: "
+ "%s, creator aid %" PRIu64 ", unique_pid %" PRIu64
+ "(activity id=%" PRIu64 ", parent id=%" PRIu64 ")",
+ entry->activity_create.name, entry->activity_create.creator_aid,
+ entry->activity_create.unique_pid, entry->activity_id,
+ entry->parent_id);
+ {
+ std::lock_guard<std::mutex> locker(m_activity_info_mutex);
+ m_activity_map.insert(
+ std::make_pair(entry->activity_id,
+ ActivityInfo(entry->activity_create.name,
+ entry->activity_id, entry->parent_id)));
+ }
+ break;
+
+ case OS_ACTIVITY_STREAM_TYPE_ACTIVITY_TRANSITION:
+ DNBLogThreadedIf(
+ LOG_DARWIN_LOG, "received activity transition:"
+ "new aid: %" PRIu64 "(activity id=%" PRIu64
+ ", parent id=%" PRIu64 ", tid %" PRIu64 ")",
+ entry->activity_transition.transition_id, entry->activity_id,
+ entry->parent_id, entry->activity_transition.thread);
+ break;
+
+ case OS_ACTIVITY_STREAM_TYPE_LOG_MESSAGE: {
+ DNBLogThreadedIf(
+ LOG_DARWIN_LOG, "received log message: "
+ "(activity id=%" PRIu64 ", parent id=%" PRIu64 ", "
+ "tid %" PRIu64 "): format %s",
+ entry->activity_id, entry->parent_id, entry->log_message.thread,
+ entry->log_message.format ? entry->log_message.format
+ : "<invalid-format>");
+
+ // Do the real work here.
+ {
+ // Ensure our process is still alive. If not, we can
+ // cancel the collection.
+ if (!DNBProcessIsAlive(m_pid)) {
+ // We're outta here. This is the manner in which we
+ // stop collecting for a process.
+ StopTrackingCollector(shared_from_this());
+ return false;
+ }
-void
-DarwinLogCollector::SetActivityStream(os_activity_stream_t activity_stream)
-{
- m_activity_stream = activity_stream;
-}
+ LogMessageOsLog os_log_message(*this, *entry);
+ if (!m_filter_chain_sp ||
+ !m_filter_chain_sp->GetAcceptMessage(os_log_message)) {
+ // This log message was rejected by the filter,
+ // so stop processing it now.
+ return true;
+ }
-bool
-DarwinLogCollector::HandleStreamEntry(os_activity_stream_entry_t entry,
- int error)
-{
- if ((error == 0) && (entry != nullptr))
- {
- if (entry->pid != m_pid)
- {
- // For now, skip messages not originating from our process.
- // Later we might want to keep all messages related to an event
- // that we're tracking, even when it came from another process,
- // possibly doing work on our behalf.
- return true;
+ // Copy over the relevant bits from the message.
+ const struct os_log_message_s &log_message = entry->log_message;
+
+ DarwinLogEventSP message_sp(new DarwinLogEvent());
+ // Indicate this event is a log message event.
+ message_sp->AddStringItem("type", "log");
+
+ // Add the message contents (fully expanded).
+ // Consider expanding on the remote side.
+ // Then we don't pay for expansion until when it is
+ // used.
+ const char *message_text = os_log_message.GetMessage();
+ if (message_text)
+ message_sp->AddStringItem("message", message_text);
+
+ // Add some useful data fields.
+ message_sp->AddIntegerItem("timestamp", log_message.timestamp);
+
+ // Do we want to do all activity name resolution on this
+ // side? Maybe. For now, send IDs and ID->name mappings
+ // and fix this up on that side. Later, when we add
+ // debugserver-side filtering, we'll want to get the
+ // activity names over here, so we should probably
+ // just send them as resolved strings.
+ message_sp->AddIntegerItem("activity_id", entry->activity_id);
+ message_sp->AddIntegerItem("parent_id", entry->parent_id);
+ message_sp->AddIntegerItem("thread_id", log_message.thread);
+ if (log_message.subsystem && strlen(log_message.subsystem) > 0)
+ message_sp->AddStringItem("subsystem", log_message.subsystem);
+ if (log_message.category && strlen(log_message.category) > 0)
+ message_sp->AddStringItem("category", log_message.category);
+ if (entry->activity_id != 0) {
+ std::string activity_chain =
+ GetActivityChainForID(entry->activity_id);
+ if (!activity_chain.empty())
+ message_sp->AddStringItem("activity-chain", activity_chain);
}
- switch (entry->type)
+ // Add it to the list for later collection.
{
- case OS_ACTIVITY_STREAM_TYPE_ACTIVITY_CREATE:
- DNBLogThreadedIf(LOG_DARWIN_LOG, "received activity create: "
- "%s, creator aid %" PRIu64 ", unique_pid %" PRIu64
- "(activity id=%" PRIu64 ", parent id=%" PRIu64 ")",
- entry->activity_create.name,
- entry->activity_create.creator_aid,
- entry->activity_create.unique_pid, entry->activity_id,
- entry->parent_id
- );
- {
- std::lock_guard<std::mutex> locker(m_activity_info_mutex);
- m_activity_map.insert(std::make_pair(
- entry->activity_id,
- ActivityInfo(
- entry->activity_create.name,
- entry->activity_id,
- entry->parent_id)));
- }
- break;
-
- case OS_ACTIVITY_STREAM_TYPE_ACTIVITY_TRANSITION:
- DNBLogThreadedIf(LOG_DARWIN_LOG, "received activity transition:"
- "new aid: %" PRIu64 "(activity id=%" PRIu64
- ", parent id=%" PRIu64 ", tid %" PRIu64 ")",
- entry->activity_transition.transition_id,
- entry->activity_id, entry->parent_id,
- entry->activity_transition.thread);
- break;
-
- case OS_ACTIVITY_STREAM_TYPE_LOG_MESSAGE:
- {
- DNBLogThreadedIf(LOG_DARWIN_LOG, "received log message: "
- "(activity id=%" PRIu64 ", parent id=%" PRIu64 ", "
- "tid %" PRIu64 "): format %s",
- entry->activity_id, entry->parent_id,
- entry->log_message.thread,
- entry->log_message.format ? entry->log_message.format :
- "<invalid-format>");
-
- // Do the real work here.
- {
- // Ensure our process is still alive. If not, we can
- // cancel the collection.
- if (!DNBProcessIsAlive(m_pid))
- {
- // We're outta here. This is the manner in which we
- // stop collecting for a process.
- StopTrackingCollector(shared_from_this());
- return false;
- }
-
- LogMessageOsLog os_log_message(*this, *entry);
- if (!m_filter_chain_sp ||
- !m_filter_chain_sp->GetAcceptMessage(os_log_message))
- {
- // This log message was rejected by the filter,
- // so stop processing it now.
- return true;
- }
-
- // Copy over the relevant bits from the message.
- const struct os_log_message_s &log_message =
- entry->log_message;
-
- DarwinLogEventSP message_sp(new DarwinLogEvent());
- // Indicate this event is a log message event.
- message_sp->AddStringItem("type", "log");
-
- // Add the message contents (fully expanded).
- // Consider expanding on the remote side.
- // Then we don't pay for expansion until when it is
- // used.
- const char *message_text = os_log_message.GetMessage();
- if (message_text)
- message_sp->AddStringItem("message", message_text);
-
- // Add some useful data fields.
- message_sp->AddIntegerItem("timestamp",
- log_message.timestamp);
-
- // Do we want to do all activity name resolution on this
- // side? Maybe. For now, send IDs and ID->name mappings
- // and fix this up on that side. Later, when we add
- // debugserver-side filtering, we'll want to get the
- // activity names over here, so we should probably
- // just send them as resolved strings.
- message_sp->AddIntegerItem("activity_id",
- entry->activity_id);
- message_sp->AddIntegerItem("parent_id",
- entry->parent_id);
- message_sp->AddIntegerItem("thread_id",
- log_message.thread);
- if (log_message.subsystem && strlen(log_message.subsystem)
- > 0)
- message_sp->AddStringItem("subsystem",
- log_message.subsystem);
- if (log_message.category && strlen(log_message.category)
- > 0)
- message_sp->AddStringItem("category",
- log_message.category);
- if (entry->activity_id != 0)
- {
- std::string activity_chain =
- GetActivityChainForID(entry->activity_id);
- if (!activity_chain.empty())
- message_sp->AddStringItem("activity-chain",
- activity_chain);
- }
-
- // Add it to the list for later collection.
- {
- std::lock_guard<std::mutex> locker(m_events_mutex);
- m_events.push_back(message_sp);
- }
- SignalDataAvailable();
- }
- break;
- }
+ std::lock_guard<std::mutex> locker(m_events_mutex);
+ m_events.push_back(message_sp);
}
+ SignalDataAvailable();
+ }
+ break;
}
- else
- {
- DNBLogThreadedIf(LOG_DARWIN_LOG, "HandleStreamEntry: final call, "
- "error %d", error);
}
- return true;
+ } else {
+ DNBLogThreadedIf(LOG_DARWIN_LOG, "HandleStreamEntry: final call, "
+ "error %d",
+ error);
+ }
+ return true;
}
-DarwinLogEventVector
-DarwinLogCollector::RemoveEvents()
-{
- DarwinLogEventVector returned_events;
- {
- std::lock_guard<std::mutex> locker(m_events_mutex);
- returned_events.swap(m_events);
- }
- DNBLogThreadedIf(LOG_DARWIN_LOG, "DarwinLogCollector::%s(): removing %lu "
- "queued log entries", __FUNCTION__,
- returned_events.size());
- return returned_events;
+DarwinLogEventVector DarwinLogCollector::RemoveEvents() {
+ DarwinLogEventVector returned_events;
+ {
+ std::lock_guard<std::mutex> locker(m_events_mutex);
+ returned_events.swap(m_events);
+ }
+ DNBLogThreadedIf(LOG_DARWIN_LOG, "DarwinLogCollector::%s(): removing %lu "
+ "queued log entries",
+ __FUNCTION__, returned_events.size());
+ return returned_events;
}
-void
-DarwinLogCollector::CancelActivityStream()
-{
- if (!m_activity_stream)
- return;
+void DarwinLogCollector::CancelActivityStream() {
+ if (!m_activity_stream)
+ return;
- DNBLogThreadedIf(LOG_DARWIN_LOG, "DarwinLogCollector::%s(): canceling "
- "activity stream %p", __FUNCTION__,
- m_activity_stream);
- (*s_os_activity_stream_cancel)(m_activity_stream);
- m_activity_stream = nullptr;
+ DNBLogThreadedIf(LOG_DARWIN_LOG, "DarwinLogCollector::%s(): canceling "
+ "activity stream %p",
+ __FUNCTION__, m_activity_stream);
+ (*s_os_activity_stream_cancel)(m_activity_stream);
+ m_activity_stream = nullptr;
}
diff --git a/lldb/tools/debugserver/source/MacOSX/DarwinLog/DarwinLogCollector.h b/lldb/tools/debugserver/source/MacOSX/DarwinLog/DarwinLogCollector.h
index 8263423fce1..a7d4e8a774c 100644
--- a/lldb/tools/debugserver/source/MacOSX/DarwinLog/DarwinLogCollector.h
+++ b/lldb/tools/debugserver/source/MacOSX/DarwinLog/DarwinLogCollector.h
@@ -18,122 +18,97 @@
#include "ActivityStore.h"
#include "ActivityStreamSPI.h"
+#include "DNBDefs.h"
#include "DarwinLogEvent.h"
#include "DarwinLogInterfaces.h"
-#include "DNBDefs.h"
#include "JSON.h"
class DarwinLogCollector;
typedef std::shared_ptr<DarwinLogCollector> DarwinLogCollectorSP;
-class DarwinLogCollector:
- public std::enable_shared_from_this<DarwinLogCollector>,
- public ActivityStore
-{
+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 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();
+ //------------------------------------------------------------------
+ /// 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 StartCollectingForProcess(nub_process_t pid,
+ const JSONObject &config);
- static bool
- CancelStreamForProcess(nub_process_t pid);
+ static bool CancelStreamForProcess(nub_process_t pid);
- static DarwinLogEventVector
- GetEventsForProcess(nub_process_t pid);
+ static DarwinLogEventVector GetEventsForProcess(nub_process_t pid);
- ~DarwinLogCollector();
+ ~DarwinLogCollector();
- pid_t
- GetProcessID() const
- {
- return m_pid;
- }
+ 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;
+ //------------------------------------------------------------------
+ // 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;
- DarwinLogCollector() = delete;
- DarwinLogCollector(const DarwinLogCollector&) = delete;
- DarwinLogCollector &operator=(const DarwinLogCollector&) = delete;
-
- explicit
- DarwinLogCollector(nub_process_t pid,
- const LogFilterChainSP &filter_chain_sp);
+ explicit DarwinLogCollector(nub_process_t pid,
+ const LogFilterChainSP &filter_chain_sp);
- void
- SignalDataAvailable();
+ void SignalDataAvailable();
- void
- SetActivityStream(os_activity_stream_t activity_stream);
+ void SetActivityStream(os_activity_stream_t activity_stream);
- bool
- HandleStreamEntry(os_activity_stream_entry_t entry, int error);
+ bool HandleStreamEntry(os_activity_stream_entry_t entry, int error);
- DarwinLogEventVector
- RemoveEvents();
+ DarwinLogEventVector RemoveEvents();
- void
- CancelActivityStream();
+ void CancelActivityStream();
- void
- GetActivityChainForID_internal(os_activity_id_t activity_id,
- std::string &result, size_t depth) const;
+ 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)
- {
- }
+ 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;
- };
+ 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>;
+ 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;
+ 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;
+ /// 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 */
diff --git a/lldb/tools/debugserver/source/MacOSX/DarwinLog/DarwinLogTypes.h b/lldb/tools/debugserver/source/MacOSX/DarwinLog/DarwinLogTypes.h
index a090fba0c14..e285e732e56 100644
--- a/lldb/tools/debugserver/source/MacOSX/DarwinLog/DarwinLogTypes.h
+++ b/lldb/tools/debugserver/source/MacOSX/DarwinLog/DarwinLogTypes.h
@@ -10,14 +10,13 @@
#ifndef DarwinLogTypes_h
#define DarwinLogTypes_h
-enum FilterTarget
-{
- eFilterTargetInvalid,
- eFilterTargetActivity,
- eFilterTargetActivityChain,
- eFilterTargetCategory,
- eFilterTargetMessage,
- eFilterTargetSubsystem
+enum FilterTarget {
+ eFilterTargetInvalid,
+ eFilterTargetActivity,
+ eFilterTargetActivityChain,
+ eFilterTargetCategory,
+ eFilterTargetMessage,
+ eFilterTargetSubsystem
};
#endif /* DarwinLogTypes_h */
diff --git a/lldb/tools/debugserver/source/MacOSX/DarwinLog/LogFilter.cpp b/lldb/tools/debugserver/source/MacOSX/DarwinLog/LogFilter.cpp
index 80af86ec505..d78419d4661 100644
--- a/lldb/tools/debugserver/source/MacOSX/DarwinLog/LogFilter.cpp
+++ b/lldb/tools/debugserver/source/MacOSX/DarwinLog/LogFilter.cpp
@@ -9,6 +9,4 @@
#include "LogFilter.h"
-LogFilter::~LogFilter()
-{
-}
+LogFilter::~LogFilter() {}
diff --git a/lldb/tools/debugserver/source/MacOSX/DarwinLog/LogFilter.h b/lldb/tools/debugserver/source/MacOSX/DarwinLog/LogFilter.h
index 4d54394cb32..92caac29725 100644
--- a/lldb/tools/debugserver/source/MacOSX/DarwinLog/LogFilter.h
+++ b/lldb/tools/debugserver/source/MacOSX/DarwinLog/LogFilter.h
@@ -12,33 +12,19 @@
#include "DarwinLogInterfaces.h"
-class LogFilter
-{
+class LogFilter {
public:
+ virtual ~LogFilter();
- virtual
- ~LogFilter();
+ virtual bool DoesMatch(const LogMessage &message) const = 0;
- virtual bool
- DoesMatch(const LogMessage &message) const = 0;
-
- bool
- MatchesAreAccepted() const
- {
- return m_matches_accept;
- }
+ bool MatchesAreAccepted() const { return m_matches_accept; }
protected:
-
- LogFilter(bool matches_accept) :
- m_matches_accept(matches_accept)
- {
- }
+ LogFilter(bool matches_accept) : m_matches_accept(matches_accept) {}
private:
-
- bool m_matches_accept;
-
+ bool m_matches_accept;
};
#endif /* LogFilter_h */
diff --git a/lldb/tools/debugserver/source/MacOSX/DarwinLog/LogFilterChain.cpp b/lldb/tools/debugserver/source/MacOSX/DarwinLog/LogFilterChain.cpp
index 888fbd9bfb1..12fbe77a906 100644
--- a/lldb/tools/debugserver/source/MacOSX/DarwinLog/LogFilterChain.cpp
+++ b/lldb/tools/debugserver/source/MacOSX/DarwinLog/LogFilterChain.cpp
@@ -11,51 +11,32 @@
#include "LogFilter.h"
-LogFilterChain::LogFilterChain(bool default_accept) :
- m_filters(),
- m_default_accept(default_accept)
-{
-}
+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::AppendFilter(const LogFilterSP &filter_sp) {
+ if (filter_sp)
+ m_filters.push_back(filter_sp);
}
-void
-LogFilterChain::ClearFilterChain()
-{
- m_filters.clear();
-}
+void LogFilterChain::ClearFilterChain() { m_filters.clear(); }
-bool
-LogFilterChain::GetDefaultAccepts() const
-{
- return m_default_accept;
-}
+bool LogFilterChain::GetDefaultAccepts() const { return m_default_accept; }
-void
-LogFilterChain::SetDefaultAccepts(bool default_accept)
-{
- m_default_accept = 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();
- }
+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;
+ // None of the filters matched. Therefore, we do whatever the
+ // default fall-through rule says.
+ return m_default_accept;
}
diff --git a/lldb/tools/debugserver/source/MacOSX/DarwinLog/LogFilterChain.h b/lldb/tools/debugserver/source/MacOSX/DarwinLog/LogFilterChain.h
index 8774c15d98c..e4888361e71 100644
--- a/lldb/tools/debugserver/source/MacOSX/DarwinLog/LogFilterChain.h
+++ b/lldb/tools/debugserver/source/MacOSX/DarwinLog/LogFilterChain.h
@@ -7,7 +7,6 @@
//
//===----------------------------------------------------------------------===//
-
#ifndef LogFilterChain_h
#define LogFilterChain_h
@@ -15,34 +14,25 @@
#include "DarwinLogInterfaces.h"
-class LogFilterChain
-{
+class LogFilterChain {
public:
+ LogFilterChain(bool default_accept);
- LogFilterChain(bool default_accept);
-
- void
- AppendFilter(const LogFilterSP &filter_sp);
+ void AppendFilter(const LogFilterSP &filter_sp);
- void
- ClearFilterChain();
+ void ClearFilterChain();
- bool
- GetDefaultAccepts() const;
+ bool GetDefaultAccepts() const;
- void
- SetDefaultAccepts(bool default_accepts);
+ void SetDefaultAccepts(bool default_accepts);
- bool
- GetAcceptMessage(const LogMessage &message) const;
+ bool GetAcceptMessage(const LogMessage &message) const;
private:
+ using FilterVector = std::vector<LogFilterSP>;
- using FilterVector = std::vector<LogFilterSP>;
-
- FilterVector m_filters;
- bool m_default_accept;
-
+ FilterVector m_filters;
+ bool m_default_accept;
};
#endif /* LogFilterChain_hpp */
diff --git a/lldb/tools/debugserver/source/MacOSX/DarwinLog/LogFilterExactMatch.cpp b/lldb/tools/debugserver/source/MacOSX/DarwinLog/LogFilterExactMatch.cpp
index b85458618fd..c8034fe1f22 100644
--- a/lldb/tools/debugserver/source/MacOSX/DarwinLog/LogFilterExactMatch.cpp
+++ b/lldb/tools/debugserver/source/MacOSX/DarwinLog/LogFilterExactMatch.cpp
@@ -12,46 +12,38 @@
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)
-{
-}
+ 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;
- }
+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;
+ }
}
diff --git a/lldb/tools/debugserver/source/MacOSX/DarwinLog/LogFilterExactMatch.h b/lldb/tools/debugserver/source/MacOSX/DarwinLog/LogFilterExactMatch.h
index 131afaf234b..dd514bc8274 100644
--- a/lldb/tools/debugserver/source/MacOSX/DarwinLog/LogFilterExactMatch.h
+++ b/lldb/tools/debugserver/source/MacOSX/DarwinLog/LogFilterExactMatch.h
@@ -16,21 +16,16 @@
#include "DarwinLogTypes.h"
#include "LogFilter.h"
-class LogFilterExactMatch : public LogFilter
-{
+class LogFilterExactMatch : public LogFilter {
public:
+ LogFilterExactMatch(bool match_accepts, FilterTarget filter_target,
+ const std::string &match_text);
- LogFilterExactMatch(bool match_accepts, FilterTarget filter_target,
- const std::string &match_text);
-
- bool
- DoesMatch(const LogMessage &message) const override;
+ bool DoesMatch(const LogMessage &message) const override;
private:
-
- const FilterTarget m_filter_target;
- const std::string m_match_text;
-
+ const FilterTarget m_filter_target;
+ const std::string m_match_text;
};
#endif
diff --git a/lldb/tools/debugserver/source/MacOSX/DarwinLog/LogFilterRegex.cpp b/lldb/tools/debugserver/source/MacOSX/DarwinLog/LogFilterRegex.cpp
index 128c7514493..d21ce81c832 100644
--- a/lldb/tools/debugserver/source/MacOSX/DarwinLog/LogFilterRegex.cpp
+++ b/lldb/tools/debugserver/source/MacOSX/DarwinLog/LogFilterRegex.cpp
@@ -7,7 +7,6 @@
//
//===----------------------------------------------------------------------===//
-
#include "LogFilterRegex.h"
#include "DNBLog.h"
@@ -19,100 +18,80 @@
// everywhere.
//----------------------------------------------------------------------
#if defined(REG_ENHANCED)
-#define DEFAULT_COMPILE_FLAGS (REG_ENHANCED|REG_EXTENDED)
+#define DEFAULT_COMPILE_FLAGS (REG_ENHANCED | REG_EXTENDED)
#else
#define DEFAULT_COMPILE_FLAGS (REG_EXTENDED)
#endif
-LogFilterRegex::LogFilterRegex(bool match_accepts,
- FilterTarget filter_target,
- const std::string &regex) :
- LogFilter(match_accepts),
- m_filter_target(filter_target),
- m_regex_text(regex),
- m_regex(),
- m_is_valid(false),
- m_error_text()
-{
- // Clear it.
- memset(&m_regex, 0, sizeof(m_regex));
+LogFilterRegex::LogFilterRegex(bool match_accepts, FilterTarget filter_target,
+ const std::string &regex)
+ : LogFilter(match_accepts), m_filter_target(filter_target),
+ m_regex_text(regex), m_regex(), m_is_valid(false), m_error_text() {
+ // Clear it.
+ memset(&m_regex, 0, sizeof(m_regex));
- // Compile it.
- if (!regex.empty())
- {
- auto comp_err = ::regcomp(&m_regex, regex.c_str(),
- DEFAULT_COMPILE_FLAGS);
- m_is_valid = (comp_err == 0);
- if (!m_is_valid)
- {
- char buffer[256];
- buffer[0] = '\0';
- ::regerror(comp_err, &m_regex, buffer, sizeof(buffer));
- m_error_text = buffer;
- }
+ // Compile it.
+ if (!regex.empty()) {
+ auto comp_err = ::regcomp(&m_regex, regex.c_str(), DEFAULT_COMPILE_FLAGS);
+ m_is_valid = (comp_err == 0);
+ if (!m_is_valid) {
+ char buffer[256];
+ buffer[0] = '\0';
+ ::regerror(comp_err, &m_regex, buffer, sizeof(buffer));
+ m_error_text = buffer;
}
+ }
}
-LogFilterRegex::~LogFilterRegex()
-{
- if (m_is_valid)
- {
- // Free the regex internals.
- regfree(&m_regex);
- }
+LogFilterRegex::~LogFilterRegex() {
+ if (m_is_valid) {
+ // Free the regex internals.
+ regfree(&m_regex);
+ }
}
-bool
-LogFilterRegex::DoesMatch(const LogMessage &message) const
-{
- switch (m_filter_target)
- {
- case eFilterTargetActivity:
- // Empty fields never match a condition.
- if (!message.HasActivity())
- return false;
- return ::regexec(&m_regex, message.GetActivity(), 0, nullptr, 0)
- == 0;
- case eFilterTargetActivityChain:
- // Empty fields never match a condition.
- if (!message.HasActivity())
- return false;
- return ::regexec(&m_regex, message.GetActivityChain().c_str(), 0,
- nullptr, 0) == 0;
- case eFilterTargetCategory:
- // Empty fields never match a condition.
- if (!message.HasCategory())
- return false;
- return ::regexec(&m_regex, message.GetCategory(), 0, nullptr,
- 0) == 0;
- case eFilterTargetMessage:
- {
- const char *message_text = message.GetMessage();
- if (!message_text)
- {
- DNBLogThreadedIf(LOG_DARWIN_LOG, "LogFilterRegex: regex "
- "\"%s\" no match due to nullptr message.",
- m_regex_text.c_str());
- return false;
- }
-
- bool match = ::regexec(&m_regex, message_text, 0,
- nullptr, 0) == 0;
- DNBLogThreadedIf(LOG_DARWIN_LOG, "LogFilterRegex: regex "
- "\"%s\" %s message \"%s\".",
- m_regex_text.c_str(),
- match ? "matches" : "does not match",
- message_text);
- return match;
- }
- case eFilterTargetSubsystem:
- // Empty fields never match a condition.
- if (!message.HasSubsystem())
- return false;
- return ::regexec(&m_regex, message.GetSubsystem(), 0, nullptr,
- 0) == 0;
- default:
- // We don't know this type.
- return false;
+bool LogFilterRegex::DoesMatch(const LogMessage &message) const {
+ switch (m_filter_target) {
+ case eFilterTargetActivity:
+ // Empty fields never match a condition.
+ if (!message.HasActivity())
+ return false;
+ return ::regexec(&m_regex, message.GetActivity(), 0, nullptr, 0) == 0;
+ case eFilterTargetActivityChain:
+ // Empty fields never match a condition.
+ if (!message.HasActivity())
+ return false;
+ return ::regexec(&m_regex, message.GetActivityChain().c_str(), 0, nullptr,
+ 0) == 0;
+ case eFilterTargetCategory:
+ // Empty fields never match a condition.
+ if (!message.HasCategory())
+ return false;
+ return ::regexec(&m_regex, message.GetCategory(), 0, nullptr, 0) == 0;
+ case eFilterTargetMessage: {
+ const char *message_text = message.GetMessage();
+ if (!message_text) {
+ DNBLogThreadedIf(LOG_DARWIN_LOG,
+ "LogFilterRegex: regex "
+ "\"%s\" no match due to nullptr message.",
+ m_regex_text.c_str());
+ return false;
}
+
+ bool match = ::regexec(&m_regex, message_text, 0, nullptr, 0) == 0;
+ DNBLogThreadedIf(LOG_DARWIN_LOG, "LogFilterRegex: regex "
+ "\"%s\" %s message \"%s\".",
+ m_regex_text.c_str(), match ? "matches" : "does not match",
+ message_text);
+ return match;
+ }
+ case eFilterTargetSubsystem:
+ // Empty fields never match a condition.
+ if (!message.HasSubsystem())
+ return false;
+ return ::regexec(&m_regex, message.GetSubsystem(), 0, nullptr, 0) == 0;
+ default:
+ // We don't know this type.
+ return false;
+ }
}
diff --git a/lldb/tools/debugserver/source/MacOSX/DarwinLog/LogFilterRegex.h b/lldb/tools/debugserver/source/MacOSX/DarwinLog/LogFilterRegex.h
index 796a62500ff..4a5939217f0 100644
--- a/lldb/tools/debugserver/source/MacOSX/DarwinLog/LogFilterRegex.h
+++ b/lldb/tools/debugserver/source/MacOSX/DarwinLog/LogFilterRegex.h
@@ -7,7 +7,6 @@
//
//===----------------------------------------------------------------------===//
-
#ifndef LogFilterRegex_h
#define LogFilterRegex_h
@@ -21,38 +20,25 @@
#include "DarwinLogTypes.h"
#include "LogFilter.h"
-class LogFilterRegex : public LogFilter
-{
+class LogFilterRegex : public LogFilter {
public:
+ LogFilterRegex(bool match_accepts, FilterTarget filter_target,
+ const std::string &regex);
- LogFilterRegex(bool match_accepts, FilterTarget filter_target,
- const std::string &regex);
-
- virtual
- ~LogFilterRegex();
+ virtual ~LogFilterRegex();
- bool
- IsValid() const
- {
- return m_is_valid;
- }
+ bool IsValid() const { return m_is_valid; }
- const char*
- GetErrorAsCString() const
- {
- return m_error_text.c_str();
- }
+ const char *GetErrorAsCString() const { return m_error_text.c_str(); }
- bool
- DoesMatch(const LogMessage &message) const override;
+ bool DoesMatch(const LogMessage &message) const override;
private:
-
- const FilterTarget m_filter_target;
- const std::string m_regex_text;
- regex_t m_regex;
- bool m_is_valid;
- std::string m_error_text;
+ const FilterTarget m_filter_target;
+ const std::string m_regex_text;
+ regex_t m_regex;
+ bool m_is_valid;
+ std::string m_error_text;
};
#endif /* LogFilterSubsystemRegex_hpp */
diff --git a/lldb/tools/debugserver/source/MacOSX/DarwinLog/LogMessage.cpp b/lldb/tools/debugserver/source/MacOSX/DarwinLog/LogMessage.cpp
index d98bb3de3c1..5a31087f231 100644
--- a/lldb/tools/debugserver/source/MacOSX/DarwinLog/LogMessage.cpp
+++ b/lldb/tools/debugserver/source/MacOSX/DarwinLog/LogMessage.cpp
@@ -7,13 +7,8 @@
//
//===----------------------------------------------------------------------===//
-
#include "LogMessage.h"
-LogMessage::LogMessage()
-{
-}
+LogMessage::LogMessage() {}
-LogMessage::~LogMessage()
-{
-}
+LogMessage::~LogMessage() {}
diff --git a/lldb/tools/debugserver/source/MacOSX/DarwinLog/LogMessage.h b/lldb/tools/debugserver/source/MacOSX/DarwinLog/LogMessage.h
index 0ec2b4277a4..bbc975133ec 100644
--- a/lldb/tools/debugserver/source/MacOSX/DarwinLog/LogMessage.h
+++ b/lldb/tools/debugserver/source/MacOSX/DarwinLog/LogMessage.h
@@ -12,42 +12,29 @@
#include <string>
-class LogMessage
-{
+class LogMessage {
public:
+ virtual ~LogMessage();
- virtual
- ~LogMessage();
+ virtual bool HasActivity() const = 0;
- virtual bool
- HasActivity() const = 0;
+ virtual const char *GetActivity() const = 0;
- virtual const char*
- GetActivity() const = 0;
+ virtual std::string GetActivityChain() const = 0;
- virtual std::string
- GetActivityChain() const = 0;
+ virtual bool HasCategory() const = 0;
- virtual bool
- HasCategory() const = 0;
+ virtual const char *GetCategory() const = 0;
- virtual const char*
- GetCategory() const = 0;
+ virtual bool HasSubsystem() const = 0;
- virtual bool
- HasSubsystem() const = 0;
+ virtual const char *GetSubsystem() const = 0;
- virtual const char*
- GetSubsystem() const = 0;
-
- // This can be expensive, so once we ask for it, we'll cache the result.
- virtual const char*
- GetMessage() const = 0;
+ // This can be expensive, so once we ask for it, we'll cache the result.
+ virtual const char *GetMessage() const = 0;
protected:
-
- LogMessage();
-
+ LogMessage();
};
#endif /* LogMessage_h */
diff --git a/lldb/tools/debugserver/source/MacOSX/DarwinLog/LogMessageOsLog.cpp b/lldb/tools/debugserver/source/MacOSX/DarwinLog/LogMessageOsLog.cpp
index f3b6e443918..91347eaf12c 100644
--- a/lldb/tools/debugserver/source/MacOSX/DarwinLog/LogMessageOsLog.cpp
+++ b/lldb/tools/debugserver/source/MacOSX/DarwinLog/LogMessageOsLog.cpp
@@ -12,84 +12,57 @@
#include "ActivityStore.h"
#include "ActivityStreamSPI.h"
-namespace
-{
- static os_log_copy_formatted_message_t s_log_copy_formatted_message;
+namespace {
+static os_log_copy_formatted_message_t s_log_copy_formatted_message;
}
-void
-LogMessageOsLog::SetFormatterFunction(os_log_copy_formatted_message_t
- format_func)
-{
- s_log_copy_formatted_message = format_func;
+void LogMessageOsLog::SetFormatterFunction(
+ os_log_copy_formatted_message_t format_func) {
+ s_log_copy_formatted_message = format_func;
}
LogMessageOsLog::LogMessageOsLog(const ActivityStore &activity_store,
- ActivityStreamEntry &entry) :
- LogMessage(),
- m_activity_store(activity_store),
- m_entry(entry),
- m_message()
-{
-}
+ ActivityStreamEntry &entry)
+ : LogMessage(), m_activity_store(activity_store), m_entry(entry),
+ m_message() {}
-bool
-LogMessageOsLog::HasActivity() const
-{
- return m_entry.activity_id != 0;
-}
+bool LogMessageOsLog::HasActivity() const { return m_entry.activity_id != 0; }
-const char*
-LogMessageOsLog::GetActivity() const
-{
- return m_activity_store.GetActivityForID(m_entry.activity_id);
+const char *LogMessageOsLog::GetActivity() const {
+ return m_activity_store.GetActivityForID(m_entry.activity_id);
}
-std::string
-LogMessageOsLog::GetActivityChain() const
-{
- return m_activity_store.GetActivityChainForID(m_entry.activity_id);
+std::string LogMessageOsLog::GetActivityChain() const {
+ return m_activity_store.GetActivityChainForID(m_entry.activity_id);
}
-bool
-LogMessageOsLog::HasCategory() const
-{
- return m_entry.log_message.category &&
- (m_entry.log_message.category[0] != 0);
+bool LogMessageOsLog::HasCategory() const {
+ return m_entry.log_message.category && (m_entry.log_message.category[0] != 0);
}
-const char*
-LogMessageOsLog::GetCategory() const
-{
- return m_entry.log_message.category;
+const char *LogMessageOsLog::GetCategory() const {
+ return m_entry.log_message.category;
}
-bool
-LogMessageOsLog::HasSubsystem() const
-{
- return m_entry.log_message.subsystem &&
- (m_entry.log_message.subsystem[0] != 0);
+bool LogMessageOsLog::HasSubsystem() const {
+ return m_entry.log_message.subsystem &&
+ (m_entry.log_message.subsystem[0] != 0);
}
-const char*
-LogMessageOsLog::GetSubsystem() const
-{
- return m_entry.log_message.subsystem;
+const char *LogMessageOsLog::GetSubsystem() const {
+ return m_entry.log_message.subsystem;
}
-const char*
-LogMessageOsLog::GetMessage() const
-{
- if (m_message.empty())
- {
- std::unique_ptr<char[]> formatted_message(
- s_log_copy_formatted_message(&m_entry.log_message));
- if (formatted_message)
- m_message = formatted_message.get();
- // else
- // TODO log
- }
+const char *LogMessageOsLog::GetMessage() const {
+ if (m_message.empty()) {
+ std::unique_ptr<char[]> formatted_message(
+ s_log_copy_formatted_message(&m_entry.log_message));
+ if (formatted_message)
+ m_message = formatted_message.get();
+ // else
+ // TODO log
+ }
- // This is safe to return as we're not modifying it once we've formatted it.
- return m_message.c_str();
+ // This is safe to return as we're not modifying it once we've formatted it.
+ return m_message.c_str();
}
diff --git a/lldb/tools/debugserver/source/MacOSX/DarwinLog/LogMessageOsLog.h b/lldb/tools/debugserver/source/MacOSX/DarwinLog/LogMessageOsLog.h
index 7c02059fc57..18103e03159 100644
--- a/lldb/tools/debugserver/source/MacOSX/DarwinLog/LogMessageOsLog.h
+++ b/lldb/tools/debugserver/source/MacOSX/DarwinLog/LogMessageOsLog.h
@@ -7,7 +7,6 @@
//
//===----------------------------------------------------------------------===//
-
#ifndef LogMessageOsLog_h
#define LogMessageOsLog_h
@@ -26,48 +25,35 @@ using ActivityStreamEntry = struct os_activity_stream_entry_s;
/// outlive this LogMessageOsLog entry.
// -----------------------------------------------------------------------------
-class LogMessageOsLog : public LogMessage
-{
+class LogMessageOsLog : public LogMessage {
public:
+ static void SetFormatterFunction(os_log_copy_formatted_message_t format_func);
- static void
- SetFormatterFunction(os_log_copy_formatted_message_t format_func);
-
- LogMessageOsLog(const ActivityStore &activity_store,
- ActivityStreamEntry &entry);
+ LogMessageOsLog(const ActivityStore &activity_store,
+ ActivityStreamEntry &entry);
- // API methods
+ // API methods
- bool
- HasActivity() const override;
+ bool HasActivity() const override;
- const char*
- GetActivity() const override;
+ const char *GetActivity() const override;
- std::string
- GetActivityChain() const override;
+ std::string GetActivityChain() const override;
- bool
- HasCategory() const override;
+ bool HasCategory() const override;
- const char*
- GetCategory() const override;
+ const char *GetCategory() const override;
- bool
- HasSubsystem() const override;
+ bool HasSubsystem() const override;
- const char*
- GetSubsystem() const override;
+ const char *GetSubsystem() const override;
- const char*
- GetMessage() const override;
+ const char *GetMessage() const override;
private:
-
- const ActivityStore &m_activity_store;
- ActivityStreamEntry &m_entry;
- mutable std::string m_message;
-
+ const ActivityStore &m_activity_store;
+ ActivityStreamEntry &m_entry;
+ mutable std::string m_message;
};
#endif /* LogMessageOsLog_h */
OpenPOWER on IntegriCloud