blob: d61a2f531ac3df7170e1e4129bb9d64af9e4469c [file] [log] [blame]
Todd Fialaaf245d12014-06-30 21:05:18 +00001//===-- 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
Chaoren Lin2fe1d0a2015-02-03 01:51:38 +000010#include "lldb/Host/common/NativeBreakpoint.h"
Todd Fialaaf245d12014-06-30 21:05:18 +000011
Todd Fialaaf245d12014-06-30 21:05:18 +000012#include "lldb/Core/Error.h"
13#include "lldb/Core/Log.h"
Kate Stoneb9c1b512016-09-06 20:57:50 +000014#include "lldb/lldb-defines.h"
Todd Fialaaf245d12014-06-30 21:05:18 +000015
16using namespace lldb_private;
17
Kate Stoneb9c1b512016-09-06 20:57:50 +000018NativeBreakpoint::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");
Todd Fialaaf245d12014-06-30 21:05:18 +000021}
22
Kate Stoneb9c1b512016-09-06 20:57:50 +000023NativeBreakpoint::~NativeBreakpoint() {}
24
25void 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);
Todd Fialaaf245d12014-06-30 21:05:18 +000033}
34
Kate Stoneb9c1b512016-09-06 20:57:50 +000035int32_t NativeBreakpoint::DecRef() {
36 --m_ref_count;
Todd Fialaaf245d12014-06-30 21:05:18 +000037
Kate Stoneb9c1b512016-09-06 20:57:50 +000038 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
47Error NativeBreakpoint::Enable() {
48 Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_BREAKPOINTS));
49
50 if (m_enabled) {
51 // We're already enabled. Just log and exit.
Todd Fialaaf245d12014-06-30 21:05:18 +000052 if (log)
Kate Stoneb9c1b512016-09-06 20:57:50 +000053 log->Printf("NativeBreakpoint::%s addr = 0x%" PRIx64
54 " already enabled, ignoring.",
55 __FUNCTION__, m_addr);
Mehdi Aminic1edf562016-11-11 04:29:25 +000056 return Error();
Kate Stoneb9c1b512016-09-06 20:57:50 +000057 }
58
59 // Log and enable.
60 if (log)
61 log->Printf("NativeBreakpoint::%s addr = 0x%" PRIx64 " enabling...",
62 __FUNCTION__, m_addr);
63
64 Error 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;
Todd Fialaaf245d12014-06-30 21:05:18 +000077}
78
Kate Stoneb9c1b512016-09-06 20:57:50 +000079Error NativeBreakpoint::Disable() {
80 Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_BREAKPOINTS));
Todd Fialaaf245d12014-06-30 21:05:18 +000081
Kate Stoneb9c1b512016-09-06 20:57:50 +000082 if (!m_enabled) {
83 // We're already disabled. Just log and exit.
Todd Fialaaf245d12014-06-30 21:05:18 +000084 if (log)
Kate Stoneb9c1b512016-09-06 20:57:50 +000085 log->Printf("NativeBreakpoint::%s addr = 0x%" PRIx64
86 " already disabled, ignoring.",
87 __FUNCTION__, m_addr);
Mehdi Aminic1edf562016-11-11 04:29:25 +000088 return Error();
Kate Stoneb9c1b512016-09-06 20:57:50 +000089 }
Todd Fialaaf245d12014-06-30 21:05:18 +000090
Kate Stoneb9c1b512016-09-06 20:57:50 +000091 // Log and disable.
92 if (log)
93 log->Printf("NativeBreakpoint::%s addr = 0x%" PRIx64 " disabling...",
94 __FUNCTION__, m_addr);
Todd Fialaaf245d12014-06-30 21:05:18 +000095
Kate Stoneb9c1b512016-09-06 20:57:50 +000096 Error error = DoDisable();
97 if (error.Success()) {
98 m_enabled = false;
Todd Fialaaf245d12014-06-30 21:05:18 +000099 if (log)
Kate Stoneb9c1b512016-09-06 20:57:50 +0000100 log->Printf("NativeBreakpoint::%s addr = 0x%" PRIx64 " disable SUCCESS.",
101 __FUNCTION__, m_addr);
102 } else {
Todd Fialaaf245d12014-06-30 21:05:18 +0000103 if (log)
Kate Stoneb9c1b512016-09-06 20:57:50 +0000104 log->Printf("NativeBreakpoint::%s addr = 0x%" PRIx64 " disable FAIL: %s",
105 __FUNCTION__, m_addr, error.AsCString());
106 }
Todd Fialaaf245d12014-06-30 21:05:18 +0000107
Kate Stoneb9c1b512016-09-06 20:57:50 +0000108 return error;
Todd Fialaaf245d12014-06-30 21:05:18 +0000109}