1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
|
//===-- LogChannelDWARF.cpp ------------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "LogChannelDWARF.h"
#include "lldb/Interpreter/Args.h"
#include "lldb/Core/PluginManager.h"
#include "lldb/Core/StreamFile.h"
#include "SymbolFileDWARF.h"
using namespace lldb;
using namespace lldb_private;
// when the one and only logging channel is abled, then this will be non NULL.
static LogChannelDWARF* g_log_channel = NULL;
LogChannelDWARF::LogChannelDWARF () :
LogChannel ()
{
}
LogChannelDWARF::~LogChannelDWARF ()
{
}
void
LogChannelDWARF::Initialize()
{
PluginManager::RegisterPlugin (GetPluginNameStatic(),
GetPluginDescriptionStatic(),
LogChannelDWARF::CreateInstance);
}
void
LogChannelDWARF::Terminate()
{
PluginManager::UnregisterPlugin (LogChannelDWARF::CreateInstance);
}
LogChannel*
LogChannelDWARF::CreateInstance ()
{
return new LogChannelDWARF ();
}
const char *
LogChannelDWARF::GetPluginNameStatic()
{
return SymbolFileDWARF::GetPluginNameStatic();
}
const char *
LogChannelDWARF::GetPluginDescriptionStatic()
{
return "DWARF log channel for debugging plug-in issues.";
}
const char *
LogChannelDWARF::GetPluginName()
{
return GetPluginDescriptionStatic();
}
const char *
LogChannelDWARF::GetShortPluginName()
{
return GetPluginNameStatic();
}
uint32_t
LogChannelDWARF::GetPluginVersion()
{
return 1;
}
void
LogChannelDWARF::Delete ()
{
g_log_channel = NULL;
m_log_sp.reset();
}
void
LogChannelDWARF::Disable (const char **categories, Stream *feedback_strm)
{
if (!m_log_sp)
return;
g_log_channel = this;
uint32_t flag_bits = m_log_sp->GetMask().Get();
for (size_t i = 0; categories[i] != NULL; ++i)
{
const char *arg = categories[i];
if (::strcasecmp (arg, "all") == 0) flag_bits &= ~DWARF_LOG_ALL;
else if (::strcasecmp (arg, "info") == 0) flag_bits &= ~DWARF_LOG_DEBUG_INFO;
else if (::strcasecmp (arg, "line") == 0) flag_bits &= ~DWARF_LOG_DEBUG_LINE;
else if (::strcasecmp (arg, "pubnames") == 0) flag_bits &= ~DWARF_LOG_DEBUG_PUBNAMES;
else if (::strcasecmp (arg, "pubtypes") == 0) flag_bits &= ~DWARF_LOG_DEBUG_PUBTYPES;
else if (::strcasecmp (arg, "aranges") == 0) flag_bits &= ~DWARF_LOG_DEBUG_ARANGES;
else if (::strcasecmp (arg, "lookups") == 0) flag_bits &= ~DWARF_LOG_LOOKUPS;
else if (::strcasecmp (arg, "map") == 0) flag_bits &= ~DWARF_LOG_DEBUG_MAP;
else if (::strcasecmp (arg, "default") == 0) flag_bits &= ~DWARF_LOG_DEFAULT;
else if (::strncasecmp(arg, "comp", 4) == 0) flag_bits &= ~DWARF_LOG_TYPE_COMPLETION;
else
{
feedback_strm->Printf("error: unrecognized log category '%s'\n", arg);
ListCategories (feedback_strm);
}
}
if (flag_bits == 0)
Delete ();
else
m_log_sp->GetMask().Reset (flag_bits);
return;
}
bool
LogChannelDWARF::Enable
(
StreamSP &log_stream_sp,
uint32_t log_options,
Stream *feedback_strm, // Feedback stream for argument errors etc
const char **categories // The categories to enable within this logging stream, if empty, enable default set
)
{
Delete ();
m_log_sp.reset(new Log (log_stream_sp));
g_log_channel = this;
uint32_t flag_bits = 0;
bool got_unknown_category = false;
for (size_t i = 0; categories[i] != NULL; ++i)
{
const char *arg = categories[i];
if (::strcasecmp (arg, "all") == 0) flag_bits |= DWARF_LOG_ALL;
else if (::strcasecmp (arg, "info") == 0) flag_bits |= DWARF_LOG_DEBUG_INFO;
else if (::strcasecmp (arg, "line") == 0) flag_bits |= DWARF_LOG_DEBUG_LINE;
else if (::strcasecmp (arg, "pubnames") == 0) flag_bits |= DWARF_LOG_DEBUG_PUBNAMES;
else if (::strcasecmp (arg, "pubtypes") == 0) flag_bits |= DWARF_LOG_DEBUG_PUBTYPES;
else if (::strcasecmp (arg, "aranges") == 0) flag_bits |= DWARF_LOG_DEBUG_ARANGES;
else if (::strcasecmp (arg, "lookups") == 0) flag_bits |= DWARF_LOG_LOOKUPS;
else if (::strcasecmp (arg, "map") == 0) flag_bits |= DWARF_LOG_DEBUG_MAP;
else if (::strcasecmp (arg, "default") == 0) flag_bits |= DWARF_LOG_DEFAULT;
else if (::strncasecmp(arg, "comp", 4) == 0) flag_bits |= DWARF_LOG_TYPE_COMPLETION;
else
{
feedback_strm->Printf("error: unrecognized log category '%s'\n", arg);
if (got_unknown_category == false)
{
got_unknown_category = true;
ListCategories (feedback_strm);
}
}
}
if (flag_bits == 0)
flag_bits = DWARF_LOG_DEFAULT;
m_log_sp->GetMask().Reset(flag_bits);
m_log_sp->GetOptions().Reset(log_options);
return m_log_sp.get() != NULL;
}
void
LogChannelDWARF::ListCategories (Stream *strm)
{
strm->Printf ("Logging categories for '%s':\n"
" all - turn on all available logging categories\n"
" info - log the parsing if .debug_info\n"
" line - log the parsing if .debug_line\n"
" pubnames - log the parsing if .debug_pubnames\n"
" pubtypes - log the parsing if .debug_pubtypes\n"
" lookups - log any lookups that happen by name, regex, or address\n\n"
" completion - log struct/unions/class type completions\n\n"
" map - log insertions of object files into DWARF debug maps\n\n",
SymbolFileDWARF::GetPluginNameStatic());
}
LogSP
LogChannelDWARF::GetLog ()
{
if (g_log_channel)
return g_log_channel->m_log_sp;
return LogSP();
}
LogSP
LogChannelDWARF::GetLogIfAll (uint32_t mask)
{
if (g_log_channel && g_log_channel->m_log_sp)
{
if (g_log_channel->m_log_sp->GetMask().AllSet(mask))
return g_log_channel->m_log_sp;
}
return LogSP();
}
LogSP
LogChannelDWARF::GetLogIfAny (uint32_t mask)
{
if (g_log_channel && g_log_channel->m_log_sp)
{
if (g_log_channel->m_log_sp->GetMask().AnySet(mask))
return g_log_channel->m_log_sp;
}
return LogSP();
}
void
LogChannelDWARF::LogIf (uint32_t mask, const char *format, ...)
{
if (g_log_channel)
{
LogSP log_sp(g_log_channel->m_log_sp);
va_list args;
va_start (args, format);
log_sp->VAPrintf (format, args);
va_end (args);
}
}
|