Ravitheja Addepally | d5d8d91 | 2017-04-26 08:48:50 +0000 | [diff] [blame] | 1 | //===-- SBTraceOptions.cpp --------------------------------------*- C++ -*-===// |
| 2 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
Ravitheja Addepally | d5d8d91 | 2017-04-26 08:48:50 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | #include "lldb/API/SBTraceOptions.h" |
| 10 | #include "lldb/API/SBError.h" |
| 11 | #include "lldb/API/SBStructuredData.h" |
Ravitheja Addepally | d5d8d91 | 2017-04-26 08:48:50 +0000 | [diff] [blame] | 12 | #include "lldb/Core/StructuredDataImpl.h" |
Pavel Labath | 38d0632 | 2017-06-29 14:32:17 +0000 | [diff] [blame] | 13 | #include "lldb/Utility/Log.h" |
| 14 | #include "lldb/Utility/TraceOptions.h" |
Ravitheja Addepally | d5d8d91 | 2017-04-26 08:48:50 +0000 | [diff] [blame] | 15 | |
Jonas Devlieghere | 796ac80 | 2019-02-11 23:13:08 +0000 | [diff] [blame^] | 16 | #include <memory> |
| 17 | |
Ravitheja Addepally | d5d8d91 | 2017-04-26 08:48:50 +0000 | [diff] [blame] | 18 | using namespace lldb; |
| 19 | using namespace lldb_private; |
| 20 | |
| 21 | SBTraceOptions::SBTraceOptions() { |
Jonas Devlieghere | 796ac80 | 2019-02-11 23:13:08 +0000 | [diff] [blame^] | 22 | m_traceoptions_sp = std::make_shared<TraceOptions>(); |
Ravitheja Addepally | d5d8d91 | 2017-04-26 08:48:50 +0000 | [diff] [blame] | 23 | } |
| 24 | |
| 25 | lldb::TraceType SBTraceOptions::getType() const { |
| 26 | if (m_traceoptions_sp) |
| 27 | return m_traceoptions_sp->getType(); |
| 28 | return lldb::TraceType::eTraceTypeNone; |
| 29 | } |
| 30 | |
| 31 | uint64_t SBTraceOptions::getTraceBufferSize() const { |
| 32 | if (m_traceoptions_sp) |
| 33 | return m_traceoptions_sp->getTraceBufferSize(); |
| 34 | return 0; |
| 35 | } |
| 36 | |
| 37 | lldb::SBStructuredData SBTraceOptions::getTraceParams(lldb::SBError &error) { |
| 38 | error.Clear(); |
| 39 | const lldb_private::StructuredData::DictionarySP dict_obj = |
| 40 | m_traceoptions_sp->getTraceParams(); |
| 41 | lldb::SBStructuredData structData; |
| 42 | if (dict_obj && structData.m_impl_up) |
| 43 | structData.m_impl_up->SetObjectSP(dict_obj->shared_from_this()); |
| 44 | else |
| 45 | error.SetErrorString("Empty trace params"); |
| 46 | return structData; |
| 47 | } |
| 48 | |
| 49 | uint64_t SBTraceOptions::getMetaDataBufferSize() const { |
| 50 | if (m_traceoptions_sp) |
| 51 | return m_traceoptions_sp->getTraceBufferSize(); |
| 52 | return 0; |
| 53 | } |
| 54 | |
| 55 | void SBTraceOptions::setTraceParams(lldb::SBStructuredData ¶ms) { |
| 56 | if (m_traceoptions_sp && params.m_impl_up) { |
| 57 | StructuredData::ObjectSP obj_sp = params.m_impl_up->GetObjectSP(); |
| 58 | if (obj_sp && obj_sp->GetAsDictionary() != nullptr) |
| 59 | m_traceoptions_sp->setTraceParams( |
| 60 | std::static_pointer_cast<StructuredData::Dictionary>(obj_sp)); |
| 61 | } |
| 62 | return; |
| 63 | } |
| 64 | |
| 65 | void SBTraceOptions::setType(lldb::TraceType type) { |
| 66 | if (m_traceoptions_sp) |
| 67 | m_traceoptions_sp->setType(type); |
| 68 | } |
| 69 | |
| 70 | void SBTraceOptions::setTraceBufferSize(uint64_t size) { |
| 71 | if (m_traceoptions_sp) |
| 72 | m_traceoptions_sp->setTraceBufferSize(size); |
| 73 | } |
| 74 | |
| 75 | void SBTraceOptions::setMetaDataBufferSize(uint64_t size) { |
| 76 | if (m_traceoptions_sp) |
| 77 | m_traceoptions_sp->setMetaDataBufferSize(size); |
| 78 | } |
| 79 | |
| 80 | bool SBTraceOptions::IsValid() { |
| 81 | if (m_traceoptions_sp) |
| 82 | return true; |
| 83 | return false; |
| 84 | } |
| 85 | |
| 86 | void SBTraceOptions::setThreadID(lldb::tid_t thread_id) { |
| 87 | if (m_traceoptions_sp) |
| 88 | m_traceoptions_sp->setThreadID(thread_id); |
| 89 | } |
| 90 | |
| 91 | lldb::tid_t SBTraceOptions::getThreadID() { |
| 92 | if (m_traceoptions_sp) |
| 93 | return m_traceoptions_sp->getThreadID(); |
| 94 | return LLDB_INVALID_THREAD_ID; |
| 95 | } |