2010-06-09 00:52:24 +08:00
|
|
|
//===-- SBEvent.cpp ---------------------------------------------*- C++ -*-===//
|
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// 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
|
2010-06-09 00:52:24 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2010-06-09 15:44:37 +08:00
|
|
|
#include "lldb/API/SBEvent.h"
|
2019-03-06 08:06:00 +08:00
|
|
|
#include "SBReproducerPrivate.h"
|
2010-06-09 15:44:37 +08:00
|
|
|
#include "lldb/API/SBBroadcaster.h"
|
2010-09-20 13:20:02 +08:00
|
|
|
#include "lldb/API/SBStream.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
#include "lldb/Breakpoint/Breakpoint.h"
|
|
|
|
#include "lldb/Core/StreamFile.h"
|
|
|
|
#include "lldb/Interpreter/CommandInterpreter.h"
|
|
|
|
#include "lldb/Target/Process.h"
|
2017-02-03 05:39:50 +08:00
|
|
|
#include "lldb/Utility/ConstString.h"
|
2018-12-14 23:59:49 +08:00
|
|
|
#include "lldb/Utility/Event.h"
|
2017-02-03 05:39:50 +08:00
|
|
|
#include "lldb/Utility/Stream.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
using namespace lldb;
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
[lldb] NFC modernize codebase with modernize-use-nullptr
Summary:
NFC = [[ https://llvm.org/docs/Lexicon.html#nfc | Non functional change ]]
This commit is the result of modernizing the LLDB codebase by using
`nullptr` instread of `0` or `NULL`. See
https://clang.llvm.org/extra/clang-tidy/checks/modernize-use-nullptr.html
for more information.
This is the command I ran and I to fix and format the code base:
```
run-clang-tidy.py \
-header-filter='.*' \
-checks='-*,modernize-use-nullptr' \
-fix ~/dev/llvm-project/lldb/.* \
-format \
-style LLVM \
-p ~/llvm-builds/debug-ninja-gcc
```
NOTE: There were also changes to `llvm/utils/unittest` but I did not
include them because I felt that maybe this library shall be updated in
isolation somehow.
NOTE: I know this is a rather large commit but it is a nobrainer in most
parts.
Reviewers: martong, espindola, shafik, #lldb, JDevlieghere
Reviewed By: JDevlieghere
Subscribers: arsenm, jvesely, nhaehnle, hiraditya, JDevlieghere, teemperor, rnkovacs, emaste, kubamracek, nemanjai, ki.stfu, javed.absar, arichardson, kbarton, jrtc27, MaskRay, atanasyan, dexonsmith, arphaman, jfb, jsji, jdoerfert, lldb-commits, llvm-commits
Tags: #lldb, #llvm
Differential Revision: https://reviews.llvm.org/D61847
llvm-svn: 361484
2019-05-23 19:14:47 +08:00
|
|
|
SBEvent::SBEvent() : m_event_sp(), m_opaque_ptr(nullptr) {
|
2019-03-06 08:06:00 +08:00
|
|
|
LLDB_RECORD_CONSTRUCTOR_NO_ARGS(SBEvent);
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
SBEvent::SBEvent(uint32_t event_type, const char *cstr, uint32_t cstr_len)
|
|
|
|
: m_event_sp(new Event(event_type, new EventDataBytes(cstr, cstr_len))),
|
2019-03-06 08:06:00 +08:00
|
|
|
m_opaque_ptr(m_event_sp.get()) {
|
|
|
|
LLDB_RECORD_CONSTRUCTOR(SBEvent, (uint32_t, const char *, uint32_t),
|
|
|
|
event_type, cstr, cstr_len);
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
SBEvent::SBEvent(EventSP &event_sp)
|
2019-03-06 08:06:00 +08:00
|
|
|
: m_event_sp(event_sp), m_opaque_ptr(event_sp.get()) {
|
|
|
|
LLDB_RECORD_CONSTRUCTOR(SBEvent, (lldb::EventSP &), event_sp);
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2019-03-06 08:06:00 +08:00
|
|
|
SBEvent::SBEvent(Event *event_ptr) : m_event_sp(), m_opaque_ptr(event_ptr) {
|
|
|
|
LLDB_RECORD_CONSTRUCTOR(SBEvent, (lldb_private::Event *), event_ptr);
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2014-09-30 07:17:18 +08:00
|
|
|
SBEvent::SBEvent(const SBEvent &rhs)
|
2019-03-06 08:06:00 +08:00
|
|
|
: m_event_sp(rhs.m_event_sp), m_opaque_ptr(rhs.m_opaque_ptr) {
|
|
|
|
LLDB_RECORD_CONSTRUCTOR(SBEvent, (const lldb::SBEvent &), rhs);
|
|
|
|
}
|
2014-09-30 07:17:18 +08:00
|
|
|
|
2010-11-06 07:17:00 +08:00
|
|
|
const SBEvent &SBEvent::operator=(const SBEvent &rhs) {
|
2019-03-06 08:06:00 +08:00
|
|
|
LLDB_RECORD_METHOD(const lldb::SBEvent &,
|
|
|
|
SBEvent, operator=,(const lldb::SBEvent &), rhs);
|
|
|
|
|
2010-11-06 07:17:00 +08:00
|
|
|
if (this != &rhs) {
|
|
|
|
m_event_sp = rhs.m_event_sp;
|
|
|
|
m_opaque_ptr = rhs.m_opaque_ptr;
|
|
|
|
}
|
2019-04-04 05:31:22 +08:00
|
|
|
return LLDB_RECORD_RESULT(*this);
|
2010-11-06 07:17:00 +08:00
|
|
|
}
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
SBEvent::~SBEvent() {}
|
|
|
|
|
|
|
|
const char *SBEvent::GetDataFlavor() {
|
2019-03-06 08:06:00 +08:00
|
|
|
LLDB_RECORD_METHOD_NO_ARGS(const char *, SBEvent, GetDataFlavor);
|
|
|
|
|
2010-06-23 09:19:29 +08:00
|
|
|
Event *lldb_event = get();
|
2010-06-09 00:52:24 +08:00
|
|
|
if (lldb_event) {
|
2010-12-06 03:21:02 +08:00
|
|
|
EventData *event_data = lldb_event->GetData();
|
|
|
|
if (event_data)
|
|
|
|
return lldb_event->GetData()->GetFlavor().AsCString();
|
|
|
|
}
|
[lldb] NFC modernize codebase with modernize-use-nullptr
Summary:
NFC = [[ https://llvm.org/docs/Lexicon.html#nfc | Non functional change ]]
This commit is the result of modernizing the LLDB codebase by using
`nullptr` instread of `0` or `NULL`. See
https://clang.llvm.org/extra/clang-tidy/checks/modernize-use-nullptr.html
for more information.
This is the command I ran and I to fix and format the code base:
```
run-clang-tidy.py \
-header-filter='.*' \
-checks='-*,modernize-use-nullptr' \
-fix ~/dev/llvm-project/lldb/.* \
-format \
-style LLVM \
-p ~/llvm-builds/debug-ninja-gcc
```
NOTE: There were also changes to `llvm/utils/unittest` but I did not
include them because I felt that maybe this library shall be updated in
isolation somehow.
NOTE: I know this is a rather large commit but it is a nobrainer in most
parts.
Reviewers: martong, espindola, shafik, #lldb, JDevlieghere
Reviewed By: JDevlieghere
Subscribers: arsenm, jvesely, nhaehnle, hiraditya, JDevlieghere, teemperor, rnkovacs, emaste, kubamracek, nemanjai, ki.stfu, javed.absar, arichardson, kbarton, jrtc27, MaskRay, atanasyan, dexonsmith, arphaman, jfb, jsji, jdoerfert, lldb-commits, llvm-commits
Tags: #lldb, #llvm
Differential Revision: https://reviews.llvm.org/D61847
llvm-svn: 361484
2019-05-23 19:14:47 +08:00
|
|
|
return nullptr;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t SBEvent::GetType() const {
|
2019-03-06 08:06:00 +08:00
|
|
|
LLDB_RECORD_METHOD_CONST_NO_ARGS(uint32_t, SBEvent, GetType);
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2010-06-23 09:19:29 +08:00
|
|
|
const Event *lldb_event = get();
|
2010-10-26 11:11:13 +08:00
|
|
|
uint32_t event_type = 0;
|
2010-06-09 00:52:24 +08:00
|
|
|
if (lldb_event)
|
2010-06-23 09:19:29 +08:00
|
|
|
event_type = lldb_event->GetType();
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2012-02-16 14:50:00 +08:00
|
|
|
return event_type;
|
|
|
|
}
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
SBBroadcaster SBEvent::GetBroadcaster() const {
|
2019-03-06 08:06:00 +08:00
|
|
|
LLDB_RECORD_METHOD_CONST_NO_ARGS(lldb::SBBroadcaster, SBEvent,
|
|
|
|
GetBroadcaster);
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
SBBroadcaster broadcaster;
|
|
|
|
const Event *lldb_event = get();
|
|
|
|
if (lldb_event)
|
2010-10-31 11:01:06 +08:00
|
|
|
broadcaster.reset(lldb_event->GetBroadcaster(), false);
|
2019-03-06 08:06:00 +08:00
|
|
|
return LLDB_RECORD_RESULT(broadcaster);
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
const char *SBEvent::GetBroadcasterClass() const {
|
2019-03-06 08:06:00 +08:00
|
|
|
LLDB_RECORD_METHOD_CONST_NO_ARGS(const char *, SBEvent, GetBroadcasterClass);
|
|
|
|
|
2010-06-23 09:19:29 +08:00
|
|
|
const Event *lldb_event = get();
|
2010-06-09 00:52:24 +08:00
|
|
|
if (lldb_event)
|
|
|
|
return lldb_event->GetBroadcaster()->GetBroadcasterClass().AsCString();
|
2016-09-07 04:57:50 +08:00
|
|
|
else
|
2012-02-16 14:50:00 +08:00
|
|
|
return "unknown class";
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2010-10-26 11:11:13 +08:00
|
|
|
|
|
|
|
bool SBEvent::BroadcasterMatchesPtr(const SBBroadcaster *broadcaster) {
|
2019-03-06 08:06:00 +08:00
|
|
|
LLDB_RECORD_METHOD(bool, SBEvent, BroadcasterMatchesPtr,
|
|
|
|
(const lldb::SBBroadcaster *), broadcaster);
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
if (broadcaster)
|
2010-10-26 11:11:13 +08:00
|
|
|
return BroadcasterMatchesRef(*broadcaster);
|
2016-09-07 04:57:50 +08:00
|
|
|
return false;
|
|
|
|
}
|
2010-10-26 11:11:13 +08:00
|
|
|
|
2014-04-04 12:06:10 +08:00
|
|
|
bool SBEvent::BroadcasterMatchesRef(const SBBroadcaster &broadcaster) {
|
2019-03-06 08:06:00 +08:00
|
|
|
LLDB_RECORD_METHOD(bool, SBEvent, BroadcasterMatchesRef,
|
|
|
|
(const lldb::SBBroadcaster &), broadcaster);
|
2010-10-26 11:11:13 +08:00
|
|
|
|
2010-06-23 09:19:29 +08:00
|
|
|
Event *lldb_event = get();
|
2010-10-26 11:11:13 +08:00
|
|
|
bool success = false;
|
2010-06-09 00:52:24 +08:00
|
|
|
if (lldb_event)
|
2010-10-26 11:11:13 +08:00
|
|
|
success = lldb_event->BroadcasterIs(broadcaster.get());
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
|
|
|
|
return success;
|
|
|
|
}
|
|
|
|
|
2010-06-23 09:19:29 +08:00
|
|
|
void SBEvent::Clear() {
|
2019-03-06 08:06:00 +08:00
|
|
|
LLDB_RECORD_METHOD_NO_ARGS(void, SBEvent, Clear);
|
|
|
|
|
2010-11-06 07:17:00 +08:00
|
|
|
Event *lldb_event = get();
|
2012-02-16 14:50:00 +08:00
|
|
|
if (lldb_event)
|
2010-11-06 07:17:00 +08:00
|
|
|
lldb_event->Clear();
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2010-06-23 09:19:29 +08:00
|
|
|
EventSP &SBEvent::GetSP() const { return m_event_sp; }
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
Event *SBEvent::get() const {
|
2010-06-23 09:19:29 +08:00
|
|
|
// There is a dangerous accessor call GetSharedPtr which can be used, so if
|
2010-06-09 00:52:24 +08:00
|
|
|
// we have anything valid in m_event_sp, we must use that since if it gets
|
|
|
|
// used by a function that puts something in there, then it won't update
|
2010-11-06 07:17:00 +08:00
|
|
|
// m_opaque_ptr...
|
2010-06-09 00:52:24 +08:00
|
|
|
if (m_event_sp)
|
2010-11-06 07:17:00 +08:00
|
|
|
m_opaque_ptr = m_event_sp.get();
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2010-11-06 07:17:00 +08:00
|
|
|
return m_opaque_ptr;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2010-06-23 09:19:29 +08:00
|
|
|
void SBEvent::reset(EventSP &event_sp) {
|
|
|
|
m_event_sp = event_sp;
|
2010-11-06 07:17:00 +08:00
|
|
|
m_opaque_ptr = m_event_sp.get();
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void SBEvent::reset(Event *event_ptr) {
|
2010-11-06 07:17:00 +08:00
|
|
|
m_opaque_ptr = event_ptr;
|
2010-06-23 09:19:29 +08:00
|
|
|
m_event_sp.reset();
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2010-06-23 09:19:29 +08:00
|
|
|
bool SBEvent::IsValid() const {
|
2019-03-06 08:06:00 +08:00
|
|
|
LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBEvent, IsValid);
|
Add "operator bool" to SB APIs
Summary:
Our python version of the SB API has (the python equivalent of)
operator bool, but the C++ version doesn't.
This is because our python operators are added by modify-python-lldb.py,
which performs postprocessing on the swig-generated interface files.
In this patch, I add the "operator bool" to all SB classes which have an
IsValid method (which is the same logic used by modify-python-lldb.py).
This way, we make the two interfaces more constent, and it allows us to
rely on swig's automatic syntesis of python __nonzero__ methods instead
of doing manual fixups.
Reviewers: zturner, jingham, clayborg, jfb, serge-sans-paille
Subscribers: jdoerfert, lldb-commits
Differential Revision: https://reviews.llvm.org/D58792
llvm-svn: 355824
2019-03-11 21:58:46 +08:00
|
|
|
return this->operator bool();
|
|
|
|
}
|
|
|
|
SBEvent::operator bool() const {
|
|
|
|
LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBEvent, operator bool);
|
2019-03-06 08:06:00 +08:00
|
|
|
|
2018-05-01 00:49:04 +08:00
|
|
|
// Do NOT use m_opaque_ptr directly!!! Must use the SBEvent::get() accessor.
|
|
|
|
// See comments in SBEvent::get()....
|
[lldb] NFC modernize codebase with modernize-use-nullptr
Summary:
NFC = [[ https://llvm.org/docs/Lexicon.html#nfc | Non functional change ]]
This commit is the result of modernizing the LLDB codebase by using
`nullptr` instread of `0` or `NULL`. See
https://clang.llvm.org/extra/clang-tidy/checks/modernize-use-nullptr.html
for more information.
This is the command I ran and I to fix and format the code base:
```
run-clang-tidy.py \
-header-filter='.*' \
-checks='-*,modernize-use-nullptr' \
-fix ~/dev/llvm-project/lldb/.* \
-format \
-style LLVM \
-p ~/llvm-builds/debug-ninja-gcc
```
NOTE: There were also changes to `llvm/utils/unittest` but I did not
include them because I felt that maybe this library shall be updated in
isolation somehow.
NOTE: I know this is a rather large commit but it is a nobrainer in most
parts.
Reviewers: martong, espindola, shafik, #lldb, JDevlieghere
Reviewed By: JDevlieghere
Subscribers: arsenm, jvesely, nhaehnle, hiraditya, JDevlieghere, teemperor, rnkovacs, emaste, kubamracek, nemanjai, ki.stfu, javed.absar, arichardson, kbarton, jrtc27, MaskRay, atanasyan, dexonsmith, arphaman, jfb, jsji, jdoerfert, lldb-commits, llvm-commits
Tags: #lldb, #llvm
Differential Revision: https://reviews.llvm.org/D61847
llvm-svn: 361484
2019-05-23 19:14:47 +08:00
|
|
|
return SBEvent::get() != nullptr;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
const char *SBEvent::GetCStringFromEvent(const SBEvent &event) {
|
2019-03-06 08:06:00 +08:00
|
|
|
LLDB_RECORD_STATIC_METHOD(const char *, SBEvent, GetCStringFromEvent,
|
|
|
|
(const lldb::SBEvent &), event);
|
|
|
|
|
2010-06-23 09:19:29 +08:00
|
|
|
return reinterpret_cast<const char *>(
|
|
|
|
EventDataBytes::GetBytesFromEvent(event.get()));
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2010-09-20 13:20:02 +08:00
|
|
|
bool SBEvent::GetDescription(SBStream &description) {
|
2019-03-06 08:06:00 +08:00
|
|
|
LLDB_RECORD_METHOD(bool, SBEvent, GetDescription, (lldb::SBStream &),
|
|
|
|
description);
|
|
|
|
|
2011-11-13 14:57:31 +08:00
|
|
|
Stream &strm = description.ref();
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2010-09-20 13:20:02 +08:00
|
|
|
if (get()) {
|
|
|
|
m_opaque_ptr->Dump(&strm);
|
2016-09-07 04:57:50 +08:00
|
|
|
} else
|
2011-11-13 14:57:31 +08:00
|
|
|
strm.PutCString("No value");
|
|
|
|
|
2010-09-20 13:20:02 +08:00
|
|
|
return true;
|
|
|
|
}
|
2010-10-26 11:11:13 +08:00
|
|
|
|
|
|
|
bool SBEvent::GetDescription(SBStream &description) const {
|
2019-03-06 08:06:00 +08:00
|
|
|
LLDB_RECORD_METHOD_CONST(bool, SBEvent, GetDescription, (lldb::SBStream &),
|
|
|
|
description);
|
|
|
|
|
2011-11-13 14:57:31 +08:00
|
|
|
Stream &strm = description.ref();
|
|
|
|
|
2010-10-29 12:59:35 +08:00
|
|
|
if (get()) {
|
2011-11-13 14:57:31 +08:00
|
|
|
m_opaque_ptr->Dump(&strm);
|
2010-10-26 11:11:13 +08:00
|
|
|
} else
|
2011-11-13 14:57:31 +08:00
|
|
|
strm.PutCString("No value");
|
2010-10-26 11:11:13 +08:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2019-03-20 01:13:13 +08:00
|
|
|
|
|
|
|
namespace lldb_private {
|
|
|
|
namespace repro {
|
|
|
|
|
|
|
|
template <>
|
|
|
|
void RegisterMethods<SBEvent>(Registry &R) {
|
|
|
|
LLDB_REGISTER_CONSTRUCTOR(SBEvent, ());
|
|
|
|
LLDB_REGISTER_CONSTRUCTOR(SBEvent, (uint32_t, const char *, uint32_t));
|
|
|
|
LLDB_REGISTER_CONSTRUCTOR(SBEvent, (lldb::EventSP &));
|
|
|
|
LLDB_REGISTER_CONSTRUCTOR(SBEvent, (lldb_private::Event *));
|
|
|
|
LLDB_REGISTER_CONSTRUCTOR(SBEvent, (const lldb::SBEvent &));
|
|
|
|
LLDB_REGISTER_METHOD(const lldb::SBEvent &,
|
|
|
|
SBEvent, operator=,(const lldb::SBEvent &));
|
|
|
|
LLDB_REGISTER_METHOD(const char *, SBEvent, GetDataFlavor, ());
|
|
|
|
LLDB_REGISTER_METHOD_CONST(uint32_t, SBEvent, GetType, ());
|
|
|
|
LLDB_REGISTER_METHOD_CONST(lldb::SBBroadcaster, SBEvent, GetBroadcaster,
|
|
|
|
());
|
|
|
|
LLDB_REGISTER_METHOD_CONST(const char *, SBEvent, GetBroadcasterClass, ());
|
|
|
|
LLDB_REGISTER_METHOD(bool, SBEvent, BroadcasterMatchesPtr,
|
|
|
|
(const lldb::SBBroadcaster *));
|
|
|
|
LLDB_REGISTER_METHOD(bool, SBEvent, BroadcasterMatchesRef,
|
|
|
|
(const lldb::SBBroadcaster &));
|
|
|
|
LLDB_REGISTER_METHOD(void, SBEvent, Clear, ());
|
|
|
|
LLDB_REGISTER_METHOD_CONST(bool, SBEvent, IsValid, ());
|
|
|
|
LLDB_REGISTER_METHOD_CONST(bool, SBEvent, operator bool, ());
|
|
|
|
LLDB_REGISTER_STATIC_METHOD(const char *, SBEvent, GetCStringFromEvent,
|
|
|
|
(const lldb::SBEvent &));
|
|
|
|
LLDB_REGISTER_METHOD(bool, SBEvent, GetDescription, (lldb::SBStream &));
|
|
|
|
LLDB_REGISTER_METHOD_CONST(bool, SBEvent, GetDescription,
|
|
|
|
(lldb::SBStream &));
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|