File: WatchpointResourceList.cpp

package info (click to toggle)
llvm-toolchain-18 1%3A18.1.8-18
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,908,340 kB
  • sloc: cpp: 6,667,937; ansic: 1,440,452; asm: 883,619; python: 230,549; objc: 76,880; f90: 74,238; lisp: 35,989; pascal: 16,571; sh: 10,229; perl: 7,459; ml: 5,047; awk: 3,523; makefile: 2,987; javascript: 2,149; xml: 892; fortran: 649; cs: 573
file content (114 lines) | stat: -rw-r--r-- 3,601 bytes parent folder | download
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
//===-- WatchpointResourceList.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 "lldb/Breakpoint/WatchpointResourceList.h"
#include "lldb/Breakpoint/WatchpointResource.h"
#include "lldb/Utility/LLDBLog.h"
#include "lldb/Utility/Log.h"

using namespace lldb;
using namespace lldb_private;

WatchpointResourceList::WatchpointResourceList() : m_resources(), m_mutex() {}

WatchpointResourceList::~WatchpointResourceList() { Clear(); }

wp_resource_id_t
WatchpointResourceList::Add(const WatchpointResourceSP &wp_res_sp) {
  Log *log = GetLog(LLDBLog::Watchpoints);
  std::lock_guard<std::mutex> guard(m_mutex);
  LLDB_LOGF(log, "WatchpointResourceList::Add(addr 0x%" PRIx64 " size %zu)",
            wp_res_sp->GetLoadAddress(), wp_res_sp->GetByteSize());

  m_resources.push_back(wp_res_sp);
  return wp_res_sp->GetID();
}

bool WatchpointResourceList::Remove(wp_resource_id_t id) {
  std::lock_guard<std::mutex> guard(m_mutex);
  Log *log = GetLog(LLDBLog::Watchpoints);
  for (collection::iterator pos = m_resources.begin(); pos != m_resources.end();
       ++pos) {
    if ((*pos)->GetID() == id) {
      LLDB_LOGF(log,
                "WatchpointResourceList::Remove(addr 0x%" PRIx64 " size %zu)",
                (*pos)->GetLoadAddress(), (*pos)->GetByteSize());
      m_resources.erase(pos);
      return true;
    }
  }
  return false;
}

bool WatchpointResourceList::RemoveByAddress(addr_t addr) {
  std::lock_guard<std::mutex> guard(m_mutex);
  Log *log = GetLog(LLDBLog::Watchpoints);
  for (collection::iterator pos = m_resources.begin(); pos != m_resources.end();
       ++pos) {
    if ((*pos)->Contains(addr)) {
      LLDB_LOGF(log,
                "WatchpointResourceList::RemoveByAddress(addr 0x%" PRIx64
                " size %zu)",
                (*pos)->GetLoadAddress(), (*pos)->GetByteSize());
      m_resources.erase(pos);
      return true;
    }
  }
  return false;
}

WatchpointResourceSP WatchpointResourceList::FindByAddress(addr_t addr) {
  std::lock_guard<std::mutex> guard(m_mutex);
  for (WatchpointResourceSP wp_res_sp : m_resources)
    if (wp_res_sp->Contains(addr))
      return wp_res_sp;
  return {};
}

WatchpointResourceSP
WatchpointResourceList::FindByWatchpointSP(WatchpointSP &wp_sp) {
  return FindByWatchpoint(wp_sp.get());
}

WatchpointResourceSP
WatchpointResourceList::FindByWatchpoint(const Watchpoint *wp) {
  std::lock_guard<std::mutex> guard(m_mutex);
  for (WatchpointResourceSP wp_res_sp : m_resources)
    if (wp_res_sp->ConstituentsContains(wp))
      return wp_res_sp;
  return {};
}

WatchpointResourceSP WatchpointResourceList::FindByID(wp_resource_id_t id) {
  std::lock_guard<std::mutex> guard(m_mutex);
  for (WatchpointResourceSP wp_res_sp : m_resources)
    if (wp_res_sp->GetID() == id)
      return wp_res_sp;
  return {};
}

uint32_t WatchpointResourceList::GetSize() {
  std::lock_guard<std::mutex> guard(m_mutex);
  return m_resources.size();
}

lldb::WatchpointResourceSP
WatchpointResourceList::GetResourceAtIndex(uint32_t idx) {
  std::lock_guard<std::mutex> guard(m_mutex);
  if (idx < m_resources.size())
    return m_resources[idx];

  return {};
}

void WatchpointResourceList::Clear() {
  std::lock_guard<std::mutex> guard(m_mutex);
  m_resources.clear();
}

std::mutex &WatchpointResourceList::GetMutex() { return m_mutex; }