aboutsummaryrefslogtreecommitdiff
path: root/packages/Python/lldbsuite/test/api/multithreaded/test_listener_event_process_state.cpp
blob: a79c5cb2a08bc79d95feaeddcdd2a07a1d381ea8 (plain) (blame)
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

// LLDB C++ API Test: verify the event description as obtained by calling
// SBEvent::GetCStringFromEvent that is received by an
// SBListener object registered with a process with a breakpoint.

#include <atomic>
#include <iostream>
#include <string>
#include <thread>

#include "lldb-headers.h"

#include "common.h"

using namespace lldb;
using namespace std;

// listener thread control
extern atomic<bool> g_done;

multithreaded_queue<string> g_frame_functions;

extern SBListener g_listener;

void listener_func() {
  while (!g_done) {
    SBEvent event;
    bool got_event = g_listener.WaitForEvent(1, event);
    if (got_event) {
      if (!event.IsValid())
        throw Exception("event is not valid in listener thread");
        // send process description
        SBProcess process = SBProcess::GetProcessFromEvent(event);
        SBStream description;

        for (int i = 0; i < process.GetNumThreads(); ++i) {
            // send each thread description
            SBThread thread = process.GetThreadAtIndex(i);
            // send each frame function name
            uint32_t num_frames = thread.GetNumFrames();
            for(int j = 0; j < num_frames; ++j) {
                const char* function_name = thread.GetFrameAtIndex(j).GetSymbol().GetName();
                if (function_name)
                    g_frame_functions.push(string(function_name));
            }
        }
    }
  }
}

void check_listener(SBDebugger &dbg) {
  // check thread description
  bool got_description = false;
  string func_name = g_frame_functions.pop(5, got_description);
  
  if(got_description == false)
    throw Exception("Expected at least one frame function");
}