blob: 776ffeb36d64642f2b795febbbc609a9ab46349f [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
Caroline Tice926060e2010-10-29 21:48:37 +000038ProcessGDBRemoteLog::DeleteLog ()
Chris Lattner24943d22010-06-08 16:52:24 +000039{
40 if (g_log)
41 {
42 delete g_log;
43 g_log = NULL;
44 }
45}
46
Caroline Tice926060e2010-10-29 21:48:37 +000047void
48ProcessGDBRemoteLog::DisableLog (Args &args, Stream *feedback_strm)
49{
50 if (g_log)
51 {
52 uint32_t flag_bits = g_log->GetMask().Get();
53 const size_t argc = args.GetArgumentCount ();
54 for (size_t i = 0; i < argc; ++i)
55 {
56 const char *arg = args.GetArgumentAtIndex (i);
57
58
59 if (::strcasecmp (arg, "all") == 0 ) flag_bits &= ~GDBR_LOG_ALL;
60 else if (::strcasecmp (arg, "async") == 0 ) flag_bits &= ~GDBR_LOG_ASYNC;
61 else if (::strcasestr (arg, "break") == arg ) flag_bits &= ~GDBR_LOG_BREAKPOINTS;
62 else if (::strcasestr (arg, "comm") == arg ) flag_bits &= ~GDBR_LOG_COMM;
63 else if (::strcasecmp (arg, "default") == 0 ) flag_bits &= ~GDBR_LOG_DEFAULT;
64 else if (::strcasecmp (arg, "packets") == 0 ) flag_bits &= ~GDBR_LOG_PACKETS;
65 else if (::strcasecmp (arg, "memory") == 0 ) flag_bits &= ~GDBR_LOG_MEMORY;
66 else if (::strcasecmp (arg, "data-short") == 0 ) flag_bits &= ~GDBR_LOG_MEMORY_DATA_SHORT;
67 else if (::strcasecmp (arg, "data-long") == 0 ) flag_bits &= ~GDBR_LOG_MEMORY_DATA_LONG;
68 else if (::strcasecmp (arg, "process") == 0 ) flag_bits &= ~GDBR_LOG_PROCESS;
69 else if (::strcasecmp (arg, "step") == 0 ) flag_bits &= ~GDBR_LOG_STEP;
70 else if (::strcasecmp (arg, "thread") == 0 ) flag_bits &= ~GDBR_LOG_THREAD;
71 else if (::strcasecmp (arg, "verbose") == 0 ) flag_bits &= ~GDBR_LOG_VERBOSE;
72 else if (::strcasestr (arg, "watch") == arg ) flag_bits &= ~GDBR_LOG_WATCHPOINTS;
73 else
74 {
75 feedback_strm->Printf("error: unrecognized log category '%s'\n", arg);
76 ListLogCategories (feedback_strm);
77 }
78
79 }
80
81 if (flag_bits == 0)
82 DeleteLog();
83 else
84 g_log->GetMask().Reset (flag_bits);
85 }
86
87 return;
88}
89
Chris Lattner24943d22010-06-08 16:52:24 +000090Log *
91ProcessGDBRemoteLog::EnableLog (StreamSP &log_stream_sp, uint32_t log_options, Args &args, Stream *feedback_strm)
92{
Caroline Tice926060e2010-10-29 21:48:37 +000093 DeleteLog ();
Chris Lattner24943d22010-06-08 16:52:24 +000094 g_log = new Log (log_stream_sp);
95 if (g_log)
96 {
97 uint32_t flag_bits = 0;
98 bool got_unknown_category = false;
99 const size_t argc = args.GetArgumentCount();
100 for (size_t i=0; i<argc; ++i)
101 {
102 const char *arg = args.GetArgumentAtIndex(i);
103
104 if (::strcasecmp (arg, "all") == 0 ) flag_bits |= GDBR_LOG_ALL;
Greg Claytonb4d1d332010-09-03 21:14:27 +0000105 else if (::strcasecmp (arg, "async") == 0 ) flag_bits |= GDBR_LOG_ASYNC;
Chris Lattner24943d22010-06-08 16:52:24 +0000106 else if (::strcasestr (arg, "break") == arg ) flag_bits |= GDBR_LOG_BREAKPOINTS;
Greg Claytonb4d1d332010-09-03 21:14:27 +0000107 else if (::strcasestr (arg, "comm") == arg ) flag_bits |= GDBR_LOG_COMM;
Chris Lattner24943d22010-06-08 16:52:24 +0000108 else if (::strcasecmp (arg, "default") == 0 ) flag_bits |= GDBR_LOG_DEFAULT;
109 else if (::strcasecmp (arg, "packets") == 0 ) flag_bits |= GDBR_LOG_PACKETS;
110 else if (::strcasecmp (arg, "memory") == 0 ) flag_bits |= GDBR_LOG_MEMORY;
111 else if (::strcasecmp (arg, "data-short") == 0 ) flag_bits |= GDBR_LOG_MEMORY_DATA_SHORT;
112 else if (::strcasecmp (arg, "data-long") == 0 ) flag_bits |= GDBR_LOG_MEMORY_DATA_LONG;
113 else if (::strcasecmp (arg, "process") == 0 ) flag_bits |= GDBR_LOG_PROCESS;
114 else if (::strcasecmp (arg, "step") == 0 ) flag_bits |= GDBR_LOG_STEP;
115 else if (::strcasecmp (arg, "thread") == 0 ) flag_bits |= GDBR_LOG_THREAD;
116 else if (::strcasecmp (arg, "verbose") == 0 ) flag_bits |= GDBR_LOG_VERBOSE;
117 else if (::strcasestr (arg, "watch") == arg ) flag_bits |= GDBR_LOG_WATCHPOINTS;
118 else
119 {
120 feedback_strm->Printf("error: unrecognized log category '%s'\n", arg);
121 if (got_unknown_category == false)
122 {
123 got_unknown_category = true;
124 ListLogCategories (feedback_strm);
125 }
126 }
127 }
128 if (flag_bits == 0)
129 flag_bits = GDBR_LOG_DEFAULT;
Greg Claytonf3d0b0c2010-10-27 03:32:59 +0000130 g_log->GetMask().Reset(flag_bits);
131 g_log->GetOptions().Reset(log_options);
Chris Lattner24943d22010-06-08 16:52:24 +0000132 }
133 return g_log;
134}
135
136void
137ProcessGDBRemoteLog::ListLogCategories (Stream *strm)
138{
139 strm->Printf("Logging categories for '%s':\n"
140 "\tall - turn on all available logging categories\n"
Greg Claytonb4d1d332010-09-03 21:14:27 +0000141 "\tasync - log asynchronous activity\n"
Chris Lattner24943d22010-06-08 16:52:24 +0000142 "\tbreak - log breakpoints\n"
Greg Claytonb4d1d332010-09-03 21:14:27 +0000143 "\tcommunication - log communication activity\n"
Chris Lattner24943d22010-06-08 16:52:24 +0000144 "\tdefault - enable the default set of logging categories for liblldb\n"
145 "\tpackets - log gdb remote packets\n"
146 "\tmemory - log memory reads and writes\n"
147 "\tdata-short - log memory bytes for memory reads and writes for short transactions only\n"
148 "\tdata-long - log memory bytes for memory reads and writes for all transactions\n"
149 "\tprocess - log process events and activities\n"
150 "\tthread - log thread events and activities\n"
151 "\tstep - log step related activities\n"
152 "\tverbose - enable verbose loggging\n"
153 "\twatch - log watchpoint related activities\n", ProcessGDBRemote::GetPluginNameStatic());
154}
155
156
157void
158ProcessGDBRemoteLog::LogIf (uint32_t mask, const char *format, ...)
159{
160 Log *log = ProcessGDBRemoteLog::GetLogIfAllCategoriesSet (mask);
161 if (log)
162 {
163 va_list args;
164 va_start (args, format);
165 log->VAPrintf (format, args);
166 va_end (args);
167 }
168}