blob: 5a7348636e40ec384b6ffe2548c49aba08b0fa55 [file] [log] [blame]
Chris Lattner24943d22010-06-08 16:52:24 +00001//===-- ProcessGDBRemoteLog.cpp ---------------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#include "ProcessGDBRemoteLog.h"
11
Jim Ingham84cdc152010-06-15 19:49:27 +000012#include "lldb/Interpreter/Args.h"
Chris Lattner24943d22010-06-08 16:52:24 +000013#include "lldb/Core/StreamFile.h"
14
15#include "ProcessGDBRemote.h"
16
17using namespace lldb;
18using namespace lldb_private;
19
20
21static Log* g_log = NULL; // Leak for now as auto_ptr was being cleaned up
22 // by global constructors before other threads
23 // were done with it.
24Log *
25ProcessGDBRemoteLog::GetLogIfAllCategoriesSet (uint32_t mask)
26{
27 Log *log = g_log;
28 if (log && mask)
29 {
Greg Claytonf3d0b0c2010-10-27 03:32:59 +000030 uint32_t log_mask = log->GetMask().Get();
Chris Lattner24943d22010-06-08 16:52:24 +000031 if ((log_mask & mask) != mask)
32 return NULL;
33 }
34 return log;
35}
36
37void
38ProcessGDBRemoteLog::DisableLog ()
39{
40 if (g_log)
41 {
42 delete g_log;
43 g_log = NULL;
44 }
45}
46
47Log *
48ProcessGDBRemoteLog::EnableLog (StreamSP &log_stream_sp, uint32_t log_options, Args &args, Stream *feedback_strm)
49{
50 DisableLog ();
51 g_log = new Log (log_stream_sp);
52 if (g_log)
53 {
54 uint32_t flag_bits = 0;
55 bool got_unknown_category = false;
56 const size_t argc = args.GetArgumentCount();
57 for (size_t i=0; i<argc; ++i)
58 {
59 const char *arg = args.GetArgumentAtIndex(i);
60
61 if (::strcasecmp (arg, "all") == 0 ) flag_bits |= GDBR_LOG_ALL;
Greg Claytonb4d1d332010-09-03 21:14:27 +000062 else if (::strcasecmp (arg, "async") == 0 ) flag_bits |= GDBR_LOG_ASYNC;
Chris Lattner24943d22010-06-08 16:52:24 +000063 else if (::strcasestr (arg, "break") == arg ) flag_bits |= GDBR_LOG_BREAKPOINTS;
Greg Claytonb4d1d332010-09-03 21:14:27 +000064 else if (::strcasestr (arg, "comm") == arg ) flag_bits |= GDBR_LOG_COMM;
Chris Lattner24943d22010-06-08 16:52:24 +000065 else if (::strcasecmp (arg, "default") == 0 ) flag_bits |= GDBR_LOG_DEFAULT;
66 else if (::strcasecmp (arg, "packets") == 0 ) flag_bits |= GDBR_LOG_PACKETS;
67 else if (::strcasecmp (arg, "memory") == 0 ) flag_bits |= GDBR_LOG_MEMORY;
68 else if (::strcasecmp (arg, "data-short") == 0 ) flag_bits |= GDBR_LOG_MEMORY_DATA_SHORT;
69 else if (::strcasecmp (arg, "data-long") == 0 ) flag_bits |= GDBR_LOG_MEMORY_DATA_LONG;
70 else if (::strcasecmp (arg, "process") == 0 ) flag_bits |= GDBR_LOG_PROCESS;
71 else if (::strcasecmp (arg, "step") == 0 ) flag_bits |= GDBR_LOG_STEP;
72 else if (::strcasecmp (arg, "thread") == 0 ) flag_bits |= GDBR_LOG_THREAD;
73 else if (::strcasecmp (arg, "verbose") == 0 ) flag_bits |= GDBR_LOG_VERBOSE;
74 else if (::strcasestr (arg, "watch") == arg ) flag_bits |= GDBR_LOG_WATCHPOINTS;
75 else
76 {
77 feedback_strm->Printf("error: unrecognized log category '%s'\n", arg);
78 if (got_unknown_category == false)
79 {
80 got_unknown_category = true;
81 ListLogCategories (feedback_strm);
82 }
83 }
84 }
85 if (flag_bits == 0)
86 flag_bits = GDBR_LOG_DEFAULT;
Greg Claytonf3d0b0c2010-10-27 03:32:59 +000087 g_log->GetMask().Reset(flag_bits);
88 g_log->GetOptions().Reset(log_options);
Chris Lattner24943d22010-06-08 16:52:24 +000089 }
90 return g_log;
91}
92
93void
94ProcessGDBRemoteLog::ListLogCategories (Stream *strm)
95{
96 strm->Printf("Logging categories for '%s':\n"
97 "\tall - turn on all available logging categories\n"
Greg Claytonb4d1d332010-09-03 21:14:27 +000098 "\tasync - log asynchronous activity\n"
Chris Lattner24943d22010-06-08 16:52:24 +000099 "\tbreak - log breakpoints\n"
Greg Claytonb4d1d332010-09-03 21:14:27 +0000100 "\tcommunication - log communication activity\n"
Chris Lattner24943d22010-06-08 16:52:24 +0000101 "\tdefault - enable the default set of logging categories for liblldb\n"
102 "\tpackets - log gdb remote packets\n"
103 "\tmemory - log memory reads and writes\n"
104 "\tdata-short - log memory bytes for memory reads and writes for short transactions only\n"
105 "\tdata-long - log memory bytes for memory reads and writes for all transactions\n"
106 "\tprocess - log process events and activities\n"
107 "\tthread - log thread events and activities\n"
108 "\tstep - log step related activities\n"
109 "\tverbose - enable verbose loggging\n"
110 "\twatch - log watchpoint related activities\n", ProcessGDBRemote::GetPluginNameStatic());
111}
112
113
114void
115ProcessGDBRemoteLog::LogIf (uint32_t mask, const char *format, ...)
116{
117 Log *log = ProcessGDBRemoteLog::GetLogIfAllCategoriesSet (mask);
118 if (log)
119 {
120 va_list args;
121 va_start (args, format);
122 log->VAPrintf (format, args);
123 va_end (args);
124 }
125}