-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[lldb-dap] Updating the logging of lldb-dap to use existing LLDBLog. #129294
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
8d466e5
2ddb7a5
133ca86
1b896fb
aca9129
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| //===-- DAPLog.cpp --------------------------------------------------------===// | ||
| // | ||
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #include "DAPLog.h" | ||
|
|
||
| using namespace lldb_private; | ||
| using namespace lldb_dap; | ||
|
|
||
| static constexpr Log::Category g_categories[] = { | ||
| {{"transport"}, {"log DAP transport"}, DAPLog::Transport}, | ||
| {{"protocol"}, {"log protocol handling"}, DAPLog::Protocol}, | ||
| {{"connection"}, {"log connection handling"}, DAPLog::Connection}, | ||
| }; | ||
|
|
||
| static Log::Channel g_log_channel(g_categories, DAPLog::Transport | | ||
| DAPLog::Protocol | | ||
| DAPLog::Connection); | ||
|
|
||
| template <> Log::Channel &lldb_private::LogChannelFor<DAPLog>() { | ||
| return g_log_channel; | ||
| } | ||
|
|
||
| void lldb_dap::InitializeDAPChannel() { | ||
| Log::Register("lldb-dap", g_log_channel); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. does this mean, I could now run But... What would happen if I run
Is this something we can / should guard against?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tried to see if I could guard against this and heres some things I noticed. With the default (~ish) build flags, I made this a verbose log to help make this less likely to happen, although that doesn't truly prevent it from happening. But also, I think this is not as likely to come up with release builds because they tend to use the exported symbol list to only export some symbols from liblldb.(so,dylib,dll).
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I wonder whether that is a feature or a bug. Should the log helper be exported by
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe given the limitations of the lldb/Utility/Log.h I should make a different abstraction that improves logging instead, what do you think?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. except for this particular issue here, I think the lldb logging framework is exactly what we want. My preferred solution would be:
(1) would be straightforward to implement. If we agree that this is the right direction, I would like to address this right away. For (2), we could easily add a All in all, I am out of my depth here, though. I would like to hear what others think about it. CC @labath @JDevlieghere @walter-erquinigo
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Actually... it seems that such a mechanism already exists. We could probably use One downside is that after calling Then we could also go back to marking the
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (1) seems really like a beautiful idea. Currently we have to set some environment variables to have lldb-dap output its logs to a file, which is not great. It would be great if we can simply plug into the regular logger framework, just like the gdb-remote logs do. (2) Another alternative for this is to enable this only when writing logs to a text file. This would require some encapsulation for logging within lldb-dap, but it wouldn't be a bad idea. A default text file could also be used, as LLDB has a default logging folder set somewhere in the code. I thnk it writes to ~/.lldb.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think given this issue and some other issues related to using the LLDBLog API I think I may not go forward with this patch and revisit at a later date. I think lldb-dap could use some improvements to logging, instead of just passing a |
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| //===-- DAPLog.h ----------------------------------------------------------===// | ||
| // | ||
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #ifndef LLDB_TOOLS_LLDB_DAP_DAPLOG_H | ||
| #define LLDB_TOOLS_LLDB_DAP_DAPLOG_H | ||
|
|
||
| #include "lldb/Utility/Log.h" | ||
| #include "llvm/ADT/BitmaskEnum.h" | ||
|
|
||
| namespace lldb_dap { | ||
|
|
||
| enum class DAPLog : lldb_private::Log::MaskType { | ||
| Transport = lldb_private::Log::ChannelFlag<0>, | ||
| Protocol = lldb_private::Log::ChannelFlag<1>, | ||
| Connection = lldb_private::Log::ChannelFlag<2>, | ||
| LLVM_MARK_AS_BITMASK_ENUM(Connection), | ||
| }; | ||
|
|
||
| LLVM_ENABLE_BITMASK_ENUMS_IN_NAMESPACE(); | ||
|
|
||
| void InitializeDAPChannel(); | ||
|
|
||
| } // end namespace lldb_dap | ||
|
|
||
| namespace lldb_private { | ||
| template <> lldb_private::Log::Channel &LogChannelFor<lldb_dap::DAPLog>(); | ||
| } // namespace lldb_private | ||
|
|
||
| #endif |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,6 +8,7 @@ | |
|
|
||
| #include "EventHelper.h" | ||
| #include "DAP.h" | ||
| #include "DAPLog.h" | ||
| #include "JSONUtils.h" | ||
| #include "LLDBUtils.h" | ||
| #include "lldb/API/SBFileSpec.h" | ||
|
|
@@ -21,6 +22,9 @@ | |
| #endif | ||
| #endif | ||
|
|
||
| using namespace lldb_dap; | ||
| using namespace lldb_private; | ||
|
|
||
| namespace lldb_dap { | ||
|
|
||
| static void SendThreadExitedEvent(DAP &dap, lldb::tid_t tid) { | ||
|
|
@@ -178,15 +182,14 @@ void SendThreadStoppedEvent(DAP &dap) { | |
| SendThreadExitedEvent(dap, tid); | ||
| } | ||
| } else { | ||
| if (dap.log) | ||
| *dap.log << "error: SendThreadStoppedEvent() when process" | ||
| " isn't stopped (" | ||
| << lldb::SBDebugger::StateAsCString(state) << ')' << std::endl; | ||
| LLDB_LOG(GetLog(DAPLog::Protocol), | ||
| "error: SendThreadStoppedEvent() when process" | ||
| " isn't stopped ({0})", | ||
| lldb::SBDebugger::StateAsCString(state)); | ||
| } | ||
| } else { | ||
| if (dap.log) | ||
| *dap.log << "error: SendThreadStoppedEvent() invalid process" | ||
| << std::endl; | ||
| LLDB_LOG(GetLog(DAPLog::Protocol), | ||
| "error: SendThreadStoppedEvent() invalid process"); | ||
|
||
| } | ||
| dap.RunStopCommands(); | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.