Skip to content

Commit ff9e596

Browse files
committed
[lldb] Expose diagnostic events through the SB API
Expose diagnostic events through the SB API. Unlike the progress events, I opted to use a SBStructuredData so that we can add fields in the future. Differential revision: https://reviews.llvm.org/D121818
1 parent 74cf857 commit ff9e596

File tree

6 files changed

+129
-2
lines changed

6 files changed

+129
-2
lines changed

lldb/bindings/interface/SBDebugger.i

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,9 @@ class SBDebugger
119119
public:
120120
enum
121121
{
122-
eBroadcastBitProgress = (1 << 0)
122+
eBroadcastBitProgress = (1 << 0),
123+
eBroadcastBitWarning = (1 << 1),
124+
eBroadcastBitError = (1 << 2),
123125
};
124126

125127

@@ -129,6 +131,8 @@ public:
129131
uint64_t &OUTPUT,
130132
bool &OUTPUT);
131133

134+
static lldb::SBStructuredData GetDiagnosticFromEvent(const lldb::SBEvent &event);
135+
132136
SBBroadcaster GetBroadcaster();
133137

134138
static void

lldb/include/lldb/API/SBDebugger.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,11 @@ class LLDB_API SBInputReader {
3333

3434
class LLDB_API SBDebugger {
3535
public:
36-
FLAGS_ANONYMOUS_ENUM(){eBroadcastBitProgress = (1 << 0)};
36+
FLAGS_ANONYMOUS_ENUM(){
37+
eBroadcastBitProgress = (1 << 0),
38+
eBroadcastBitWarning = (1 << 1),
39+
eBroadcastBitError = (1 << 2),
40+
};
3741

3842
SBDebugger();
3943

@@ -79,6 +83,9 @@ class LLDB_API SBDebugger {
7983
uint64_t &completed, uint64_t &total,
8084
bool &is_debugger_specific);
8185

86+
static lldb::SBStructuredData
87+
GetDiagnosticFromEvent(const lldb::SBEvent &event);
88+
8289
lldb::SBDebugger &operator=(const lldb::SBDebugger &rhs);
8390

8491
static void Initialize();

lldb/include/lldb/Core/DebuggerEvents.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ class DiagnosticEventData : public EventData {
5959
~DiagnosticEventData() {}
6060

6161
const std::string &GetMessage() const { return m_message; }
62+
bool IsDebuggerSpecific() const { return m_debugger_specific; }
6263
Type GetType() const { return m_type; }
6364

6465
llvm::StringRef GetPrefix() const;

lldb/source/API/SBDebugger.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,26 @@ const char *SBDebugger::GetProgressFromEvent(const lldb::SBEvent &event,
164164
return progress_data->GetMessage().c_str();
165165
}
166166

167+
lldb::SBStructuredData
168+
SBDebugger::GetDiagnosticFromEvent(const lldb::SBEvent &event) {
169+
LLDB_INSTRUMENT_VA(event);
170+
171+
const DiagnosticEventData *diagnostic_data =
172+
DiagnosticEventData::GetEventDataFromEvent(event.get());
173+
if (!diagnostic_data)
174+
return {};
175+
176+
auto dictionary = std::make_unique<StructuredData::Dictionary>();
177+
dictionary->AddStringItem("message", diagnostic_data->GetMessage());
178+
dictionary->AddStringItem("type", diagnostic_data->GetPrefix());
179+
dictionary->AddBooleanItem("debugger_specific",
180+
diagnostic_data->IsDebuggerSpecific());
181+
182+
SBStructuredData data;
183+
data.m_impl_up->SetObjectSP(std::move(dictionary));
184+
return data;
185+
}
186+
167187
SBBroadcaster SBDebugger::GetBroadcaster() {
168188
LLDB_INSTRUMENT_VA(this);
169189
SBBroadcaster broadcaster(&m_opaque_sp->GetBroadcaster(), false);
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
"""
2+
Test that we are able to broadcast and receive diagnostic events from lldb
3+
"""
4+
import lldb
5+
from lldbsuite.test.lldbtest import *
6+
from lldbsuite.test.decorators import *
7+
import lldbsuite.test.lldbutil as lldbutil
8+
import threading
9+
10+
11+
class TestDiagnosticReporting(TestBase):
12+
13+
mydir = TestBase.compute_mydir(__file__)
14+
15+
eBroadcastBitStopDiagnosticThread = (1 << 0)
16+
17+
def setUp(self):
18+
TestBase.setUp(self)
19+
self.diagnostic_events = []
20+
21+
def fetch_events(self):
22+
event = lldb.SBEvent()
23+
24+
done = False
25+
while not done:
26+
if self.listener.WaitForEvent(1, event):
27+
event_mask = event.GetType()
28+
if event.BroadcasterMatchesRef(self.test_broadcaster):
29+
if event_mask & self.eBroadcastBitStopDiagnosticThread:
30+
done = True
31+
elif event.BroadcasterMatchesRef(self.diagnostic_broadcaster):
32+
self.diagnostic_events.append(
33+
lldb.SBDebugger.GetDiagnosticFromEvent(event))
34+
35+
def test_dwarf_symbol_loading_diagnostic_report(self):
36+
"""Test that we are able to fetch diagnostic events"""
37+
self.listener = lldb.SBListener("lldb.diagnostic.listener")
38+
self.test_broadcaster = lldb.SBBroadcaster('lldb.broadcaster.test')
39+
self.listener.StartListeningForEvents(
40+
self.test_broadcaster, self.eBroadcastBitStopDiagnosticThread)
41+
42+
self.diagnostic_broadcaster = self.dbg.GetBroadcaster()
43+
self.diagnostic_broadcaster.AddListener(
44+
self.listener, lldb.SBDebugger.eBroadcastBitWarning)
45+
self.diagnostic_broadcaster.AddListener(
46+
self.listener, lldb.SBDebugger.eBroadcastBitError)
47+
48+
listener_thread = threading.Thread(target=self.fetch_events)
49+
listener_thread.start()
50+
51+
self.yaml2obj("minidump.yaml", self.getBuildArtifact("minidump.core"))
52+
53+
self.dbg.CreateTarget(None)
54+
self.target = self.dbg.GetSelectedTarget()
55+
self.process = self.target.LoadCore(
56+
self.getBuildArtifact("minidump.core"))
57+
58+
self.test_broadcaster.BroadcastEventByType(
59+
self.eBroadcastBitStopDiagnosticThread)
60+
listener_thread.join()
61+
62+
self.assertEquals(len(self.diagnostic_events), 1)
63+
64+
diagnostic_event = self.diagnostic_events[0]
65+
self.assertEquals(
66+
diagnostic_event.GetValueForKey("type").GetStringValue(100),
67+
"warning")
68+
self.assertEquals(
69+
diagnostic_event.GetValueForKey("message").GetStringValue(100),
70+
"unable to retrieve process ID from minidump file, setting process ID to 1"
71+
)
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
--- !minidump
2+
Streams:
3+
- Type: ThreadList
4+
Threads:
5+
- Thread Id: 0x00003E81
6+
Context: 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000B0010000000000033000000000000000000000006020100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000010A234EBFC7F000010A234EBFC7F00000000000000000000F09C34EBFC7F0000C0A91ABCE97F00000000000000000000A0163FBCE97F00004602000000000000921C40000000000030A434EBFC7F000000000000000000000000000000000000C61D4000000000007F0300000000000000000000000000000000000000000000801F0000FFFF0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000FFFF00FFFFFFFFFFFFFF00FFFFFFFF25252525252525252525252525252525000000000000000000000000000000000000000000000000000000000000000000FFFF00FFFFFFFFFFFFFF00FFFFFFFF0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000FF00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
7+
Stack:
8+
Start of Memory Range: 0x00007FFCEB34A000
9+
Content: ''
10+
- Type: ModuleList
11+
Modules:
12+
- Base of Image: 0x0000000000400000
13+
Size of Image: 0x00017000
14+
Module Name: 'a.out'
15+
CodeView Record: ''
16+
- Type: SystemInfo
17+
Processor Arch: AMD64
18+
Platform ID: Linux
19+
CSD Version: 'Linux 3.13'
20+
CPU:
21+
Vendor ID: GenuineIntel
22+
Version Info: 0x00000000
23+
Feature Info: 0x00000000
24+
...

0 commit comments

Comments
 (0)