blob: 051ce8f20f46c34cba5aeedb494ff0bc23b4500f [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
12#include "lldb/Core/Args.h"
13#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 {
30 uint32_t log_mask = log->GetMask().GetAllFlagBits();
31 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;
62 else if (::strcasestr (arg, "break") == arg ) flag_bits |= GDBR_LOG_BREAKPOINTS;
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 if (got_unknown_category == false)
77 {
78 got_unknown_category = true;
79 ListLogCategories (feedback_strm);
80 }
81 }
82 }
83 if (flag_bits == 0)
84 flag_bits = GDBR_LOG_DEFAULT;
85 g_log->GetMask().SetAllFlagBits(flag_bits);
86 g_log->GetOptions().SetAllFlagBits(log_options);
87 }
88 return g_log;
89}
90
91void
92ProcessGDBRemoteLog::ListLogCategories (Stream *strm)
93{
94 strm->Printf("Logging categories for '%s':\n"
95 "\tall - turn on all available logging categories\n"
96 "\tbreak - log breakpoints\n"
97 "\tdefault - enable the default set of logging categories for liblldb\n"
98 "\tpackets - log gdb remote packets\n"
99 "\tmemory - log memory reads and writes\n"
100 "\tdata-short - log memory bytes for memory reads and writes for short transactions only\n"
101 "\tdata-long - log memory bytes for memory reads and writes for all transactions\n"
102 "\tprocess - log process events and activities\n"
103 "\tthread - log thread events and activities\n"
104 "\tstep - log step related activities\n"
105 "\tverbose - enable verbose loggging\n"
106 "\twatch - log watchpoint related activities\n", ProcessGDBRemote::GetPluginNameStatic());
107}
108
109
110void
111ProcessGDBRemoteLog::LogIf (uint32_t mask, const char *format, ...)
112{
113 Log *log = ProcessGDBRemoteLog::GetLogIfAllCategoriesSet (mask);
114 if (log)
115 {
116 va_list args;
117 va_start (args, format);
118 log->VAPrintf (format, args);
119 va_end (args);
120 }
121}