]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/source/Host/common/NativeBreakpoint.cpp
MFC r345805: Unify SCSI_STATUS_BUSY retry handling with other cases.
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / source / Host / common / NativeBreakpoint.cpp
1 //===-- NativeBreakpoint.cpp ------------------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #include "lldb/Host/common/NativeBreakpoint.h"
11
12 #include "lldb/Utility/Log.h"
13 #include "lldb/Utility/Status.h"
14 #include "lldb/lldb-defines.h"
15
16 using namespace lldb_private;
17
18 NativeBreakpoint::NativeBreakpoint(lldb::addr_t addr)
19     : m_addr(addr), m_ref_count(1), m_enabled(true) {
20   assert(addr != LLDB_INVALID_ADDRESS && "breakpoint set for invalid address");
21 }
22
23 NativeBreakpoint::~NativeBreakpoint() {}
24
25 void NativeBreakpoint::AddRef() {
26   ++m_ref_count;
27
28   Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_BREAKPOINTS));
29   if (log)
30     log->Printf("NativeBreakpoint::%s addr = 0x%" PRIx64
31                 " bumped up, new ref count %" PRIu32,
32                 __FUNCTION__, m_addr, m_ref_count);
33 }
34
35 int32_t NativeBreakpoint::DecRef() {
36   --m_ref_count;
37
38   Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_BREAKPOINTS));
39   if (log)
40     log->Printf("NativeBreakpoint::%s addr = 0x%" PRIx64
41                 " ref count decremented, new ref count %" PRIu32,
42                 __FUNCTION__, m_addr, m_ref_count);
43
44   return m_ref_count;
45 }
46
47 Status NativeBreakpoint::Enable() {
48   Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_BREAKPOINTS));
49
50   if (m_enabled) {
51     // We're already enabled. Just log and exit.
52     if (log)
53       log->Printf("NativeBreakpoint::%s addr = 0x%" PRIx64
54                   " already enabled, ignoring.",
55                   __FUNCTION__, m_addr);
56     return Status();
57   }
58
59   // Log and enable.
60   if (log)
61     log->Printf("NativeBreakpoint::%s addr = 0x%" PRIx64 " enabling...",
62                 __FUNCTION__, m_addr);
63
64   Status error = DoEnable();
65   if (error.Success()) {
66     m_enabled = true;
67     if (log)
68       log->Printf("NativeBreakpoint::%s addr = 0x%" PRIx64 " enable SUCCESS.",
69                   __FUNCTION__, m_addr);
70   } else {
71     if (log)
72       log->Printf("NativeBreakpoint::%s addr = 0x%" PRIx64 " enable FAIL: %s",
73                   __FUNCTION__, m_addr, error.AsCString());
74   }
75
76   return error;
77 }
78
79 Status NativeBreakpoint::Disable() {
80   Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_BREAKPOINTS));
81
82   if (!m_enabled) {
83     // We're already disabled. Just log and exit.
84     if (log)
85       log->Printf("NativeBreakpoint::%s addr = 0x%" PRIx64
86                   " already disabled, ignoring.",
87                   __FUNCTION__, m_addr);
88     return Status();
89   }
90
91   // Log and disable.
92   if (log)
93     log->Printf("NativeBreakpoint::%s addr = 0x%" PRIx64 " disabling...",
94                 __FUNCTION__, m_addr);
95
96   Status error = DoDisable();
97   if (error.Success()) {
98     m_enabled = false;
99     if (log)
100       log->Printf("NativeBreakpoint::%s addr = 0x%" PRIx64 " disable SUCCESS.",
101                   __FUNCTION__, m_addr);
102   } else {
103     if (log)
104       log->Printf("NativeBreakpoint::%s addr = 0x%" PRIx64 " disable FAIL: %s",
105                   __FUNCTION__, m_addr, error.AsCString());
106   }
107
108   return error;
109 }