Raphael Isemann | 8081428 | 2020-01-24 08:23:27 +0100 | [diff] [blame] | 1 | //===-- SBBlock.cpp -------------------------------------------------------===// |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 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 |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | #include "lldb/API/SBBlock.h" |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame] | 10 | #include "SBReproducerPrivate.h" |
Greg Clayton | 8f7180b | 2011-09-26 07:11:27 +0000 | [diff] [blame] | 11 | #include "lldb/API/SBAddress.h" |
Greg Clayton | 95897c6 | 2010-09-07 04:20:48 +0000 | [diff] [blame] | 12 | #include "lldb/API/SBFileSpec.h" |
Greg Clayton | 5569e64 | 2012-02-06 01:44:54 +0000 | [diff] [blame] | 13 | #include "lldb/API/SBFrame.h" |
Caroline Tice | dde9cff | 2010-09-20 05:20:02 +0000 | [diff] [blame] | 14 | #include "lldb/API/SBStream.h" |
Greg Clayton | 5569e64 | 2012-02-06 01:44:54 +0000 | [diff] [blame] | 15 | #include "lldb/API/SBValue.h" |
Greg Clayton | 8f7180b | 2011-09-26 07:11:27 +0000 | [diff] [blame] | 16 | #include "lldb/Core/AddressRange.h" |
Greg Clayton | 5569e64 | 2012-02-06 01:44:54 +0000 | [diff] [blame] | 17 | #include "lldb/Core/ValueObjectVariable.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 18 | #include "lldb/Symbol/Block.h" |
Greg Clayton | 95897c6 | 2010-09-07 04:20:48 +0000 | [diff] [blame] | 19 | #include "lldb/Symbol/Function.h" |
Caroline Tice | dde9cff | 2010-09-20 05:20:02 +0000 | [diff] [blame] | 20 | #include "lldb/Symbol/SymbolContext.h" |
Greg Clayton | 5569e64 | 2012-02-06 01:44:54 +0000 | [diff] [blame] | 21 | #include "lldb/Symbol/VariableList.h" |
Jason Molenda | b57e4a1 | 2013-11-04 09:33:30 +0000 | [diff] [blame] | 22 | #include "lldb/Target/StackFrame.h" |
Greg Clayton | 5569e64 | 2012-02-06 01:44:54 +0000 | [diff] [blame] | 23 | #include "lldb/Target/Target.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 24 | |
| 25 | using namespace lldb; |
Greg Clayton | 95897c6 | 2010-09-07 04:20:48 +0000 | [diff] [blame] | 26 | using namespace lldb_private; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 27 | |
Konrad Kleine | 248a130 | 2019-05-23 11:14:47 +0000 | [diff] [blame] | 28 | SBBlock::SBBlock() : m_opaque_ptr(nullptr) { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame] | 29 | LLDB_RECORD_CONSTRUCTOR_NO_ARGS(SBBlock); |
| 30 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 31 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 32 | SBBlock::SBBlock(lldb_private::Block *lldb_object_ptr) |
| 33 | : m_opaque_ptr(lldb_object_ptr) {} |
| 34 | |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame] | 35 | SBBlock::SBBlock(const SBBlock &rhs) : m_opaque_ptr(rhs.m_opaque_ptr) { |
| 36 | LLDB_RECORD_CONSTRUCTOR(SBBlock, (const lldb::SBBlock &), rhs); |
| 37 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 38 | |
| 39 | const SBBlock &SBBlock::operator=(const SBBlock &rhs) { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame] | 40 | LLDB_RECORD_METHOD(const lldb::SBBlock &, |
| 41 | SBBlock, operator=,(const lldb::SBBlock &), rhs); |
| 42 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 43 | m_opaque_ptr = rhs.m_opaque_ptr; |
Jonas Devlieghere | 306809f | 2019-04-03 21:31:22 +0000 | [diff] [blame] | 44 | return LLDB_RECORD_RESULT(*this); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 45 | } |
| 46 | |
Konrad Kleine | 248a130 | 2019-05-23 11:14:47 +0000 | [diff] [blame] | 47 | SBBlock::~SBBlock() { m_opaque_ptr = nullptr; } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 48 | |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame] | 49 | bool SBBlock::IsValid() const { |
| 50 | LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBBlock, IsValid); |
Pavel Labath | 7f5237b | 2019-03-11 13:58:46 +0000 | [diff] [blame] | 51 | return this->operator bool(); |
| 52 | } |
| 53 | SBBlock::operator bool() const { |
| 54 | LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBBlock, operator bool); |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame] | 55 | |
Konrad Kleine | 248a130 | 2019-05-23 11:14:47 +0000 | [diff] [blame] | 56 | return m_opaque_ptr != nullptr; |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame] | 57 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 58 | |
| 59 | bool SBBlock::IsInlined() const { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame] | 60 | LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBBlock, IsInlined); |
| 61 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 62 | if (m_opaque_ptr) |
Konrad Kleine | 248a130 | 2019-05-23 11:14:47 +0000 | [diff] [blame] | 63 | return m_opaque_ptr->GetInlinedFunctionInfo() != nullptr; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 64 | return false; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 65 | } |
| 66 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 67 | const char *SBBlock::GetInlinedName() const { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame] | 68 | LLDB_RECORD_METHOD_CONST_NO_ARGS(const char *, SBBlock, GetInlinedName); |
| 69 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 70 | if (m_opaque_ptr) { |
| 71 | const InlineFunctionInfo *inlined_info = |
| 72 | m_opaque_ptr->GetInlinedFunctionInfo(); |
| 73 | if (inlined_info) { |
Alex Langford | 22b0448 | 2020-01-30 21:55:18 -0800 | [diff] [blame] | 74 | return inlined_info->GetName().AsCString(nullptr); |
Greg Clayton | 95897c6 | 2010-09-07 04:20:48 +0000 | [diff] [blame] | 75 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 76 | } |
Konrad Kleine | 248a130 | 2019-05-23 11:14:47 +0000 | [diff] [blame] | 77 | return nullptr; |
Greg Clayton | 95897c6 | 2010-09-07 04:20:48 +0000 | [diff] [blame] | 78 | } |
| 79 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 80 | SBFileSpec SBBlock::GetInlinedCallSiteFile() const { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame] | 81 | LLDB_RECORD_METHOD_CONST_NO_ARGS(lldb::SBFileSpec, SBBlock, |
| 82 | GetInlinedCallSiteFile); |
| 83 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 84 | SBFileSpec sb_file; |
| 85 | if (m_opaque_ptr) { |
| 86 | const InlineFunctionInfo *inlined_info = |
| 87 | m_opaque_ptr->GetInlinedFunctionInfo(); |
| 88 | if (inlined_info) |
| 89 | sb_file.SetFileSpec(inlined_info->GetCallSite().GetFile()); |
| 90 | } |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame] | 91 | return LLDB_RECORD_RESULT(sb_file); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 92 | } |
| 93 | |
| 94 | uint32_t SBBlock::GetInlinedCallSiteLine() const { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame] | 95 | LLDB_RECORD_METHOD_CONST_NO_ARGS(uint32_t, SBBlock, GetInlinedCallSiteLine); |
| 96 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 97 | if (m_opaque_ptr) { |
| 98 | const InlineFunctionInfo *inlined_info = |
| 99 | m_opaque_ptr->GetInlinedFunctionInfo(); |
| 100 | if (inlined_info) |
| 101 | return inlined_info->GetCallSite().GetLine(); |
| 102 | } |
| 103 | return 0; |
| 104 | } |
| 105 | |
| 106 | uint32_t SBBlock::GetInlinedCallSiteColumn() const { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame] | 107 | LLDB_RECORD_METHOD_CONST_NO_ARGS(uint32_t, SBBlock, GetInlinedCallSiteColumn); |
| 108 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 109 | if (m_opaque_ptr) { |
| 110 | const InlineFunctionInfo *inlined_info = |
| 111 | m_opaque_ptr->GetInlinedFunctionInfo(); |
| 112 | if (inlined_info) |
| 113 | return inlined_info->GetCallSite().GetColumn(); |
| 114 | } |
| 115 | return 0; |
| 116 | } |
| 117 | |
| 118 | void SBBlock::AppendVariables(bool can_create, bool get_parent_variables, |
| 119 | lldb_private::VariableList *var_list) { |
| 120 | if (IsValid()) { |
| 121 | bool show_inline = true; |
| 122 | m_opaque_ptr->AppendVariables(can_create, get_parent_variables, show_inline, |
| 123 | [](Variable *) { return true; }, var_list); |
| 124 | } |
| 125 | } |
| 126 | |
| 127 | SBBlock SBBlock::GetParent() { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame] | 128 | LLDB_RECORD_METHOD_NO_ARGS(lldb::SBBlock, SBBlock, GetParent); |
| 129 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 130 | SBBlock sb_block; |
| 131 | if (m_opaque_ptr) |
| 132 | sb_block.m_opaque_ptr = m_opaque_ptr->GetParent(); |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame] | 133 | return LLDB_RECORD_RESULT(sb_block); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | lldb::SBBlock SBBlock::GetContainingInlinedBlock() { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame] | 137 | LLDB_RECORD_METHOD_NO_ARGS(lldb::SBBlock, SBBlock, GetContainingInlinedBlock); |
| 138 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 139 | SBBlock sb_block; |
| 140 | if (m_opaque_ptr) |
| 141 | sb_block.m_opaque_ptr = m_opaque_ptr->GetContainingInlinedBlock(); |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame] | 142 | return LLDB_RECORD_RESULT(sb_block); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 143 | } |
| 144 | |
| 145 | SBBlock SBBlock::GetSibling() { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame] | 146 | LLDB_RECORD_METHOD_NO_ARGS(lldb::SBBlock, SBBlock, GetSibling); |
| 147 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 148 | SBBlock sb_block; |
| 149 | if (m_opaque_ptr) |
| 150 | sb_block.m_opaque_ptr = m_opaque_ptr->GetSibling(); |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame] | 151 | return LLDB_RECORD_RESULT(sb_block); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 152 | } |
| 153 | |
| 154 | SBBlock SBBlock::GetFirstChild() { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame] | 155 | LLDB_RECORD_METHOD_NO_ARGS(lldb::SBBlock, SBBlock, GetFirstChild); |
| 156 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 157 | SBBlock sb_block; |
| 158 | if (m_opaque_ptr) |
| 159 | sb_block.m_opaque_ptr = m_opaque_ptr->GetFirstChild(); |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame] | 160 | return LLDB_RECORD_RESULT(sb_block); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 161 | } |
| 162 | |
| 163 | lldb_private::Block *SBBlock::GetPtr() { return m_opaque_ptr; } |
| 164 | |
| 165 | void SBBlock::SetPtr(lldb_private::Block *block) { m_opaque_ptr = block; } |
| 166 | |
| 167 | bool SBBlock::GetDescription(SBStream &description) { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame] | 168 | LLDB_RECORD_METHOD(bool, SBBlock, GetDescription, (lldb::SBStream &), |
| 169 | description); |
| 170 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 171 | Stream &strm = description.ref(); |
| 172 | |
| 173 | if (m_opaque_ptr) { |
| 174 | lldb::user_id_t id = m_opaque_ptr->GetID(); |
| 175 | strm.Printf("Block: {id: %" PRIu64 "} ", id); |
| 176 | if (IsInlined()) { |
| 177 | strm.Printf(" (inlined, '%s') ", GetInlinedName()); |
Greg Clayton | 95897c6 | 2010-09-07 04:20:48 +0000 | [diff] [blame] | 178 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 179 | lldb_private::SymbolContext sc; |
| 180 | m_opaque_ptr->CalculateSymbolContext(&sc); |
| 181 | if (sc.function) { |
| 182 | m_opaque_ptr->DumpAddressRanges( |
| 183 | &strm, |
| 184 | sc.function->GetAddressRange().GetBaseAddress().GetFileAddress()); |
Greg Clayton | 95897c6 | 2010-09-07 04:20:48 +0000 | [diff] [blame] | 185 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 186 | } else |
| 187 | strm.PutCString("No value"); |
| 188 | |
| 189 | return true; |
Greg Clayton | 95897c6 | 2010-09-07 04:20:48 +0000 | [diff] [blame] | 190 | } |
| 191 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 192 | uint32_t SBBlock::GetNumRanges() { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame] | 193 | LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBBlock, GetNumRanges); |
| 194 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 195 | if (m_opaque_ptr) |
| 196 | return m_opaque_ptr->GetNumRanges(); |
| 197 | return 0; |
| 198 | } |
| 199 | |
| 200 | lldb::SBAddress SBBlock::GetRangeStartAddress(uint32_t idx) { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame] | 201 | LLDB_RECORD_METHOD(lldb::SBAddress, SBBlock, GetRangeStartAddress, (uint32_t), |
| 202 | idx); |
| 203 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 204 | lldb::SBAddress sb_addr; |
| 205 | if (m_opaque_ptr) { |
| 206 | AddressRange range; |
| 207 | if (m_opaque_ptr->GetRangeAtIndex(idx, range)) { |
| 208 | sb_addr.ref() = range.GetBaseAddress(); |
Greg Clayton | 95897c6 | 2010-09-07 04:20:48 +0000 | [diff] [blame] | 209 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 210 | } |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame] | 211 | return LLDB_RECORD_RESULT(sb_addr); |
Greg Clayton | 95897c6 | 2010-09-07 04:20:48 +0000 | [diff] [blame] | 212 | } |
| 213 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 214 | lldb::SBAddress SBBlock::GetRangeEndAddress(uint32_t idx) { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame] | 215 | LLDB_RECORD_METHOD(lldb::SBAddress, SBBlock, GetRangeEndAddress, (uint32_t), |
| 216 | idx); |
| 217 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 218 | lldb::SBAddress sb_addr; |
| 219 | if (m_opaque_ptr) { |
| 220 | AddressRange range; |
| 221 | if (m_opaque_ptr->GetRangeAtIndex(idx, range)) { |
| 222 | sb_addr.ref() = range.GetBaseAddress(); |
| 223 | sb_addr.ref().Slide(range.GetByteSize()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 224 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 225 | } |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame] | 226 | return LLDB_RECORD_RESULT(sb_addr); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 227 | } |
| 228 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 229 | uint32_t SBBlock::GetRangeIndexForBlockAddress(lldb::SBAddress block_addr) { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame] | 230 | LLDB_RECORD_METHOD(uint32_t, SBBlock, GetRangeIndexForBlockAddress, |
| 231 | (lldb::SBAddress), block_addr); |
| 232 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 233 | if (m_opaque_ptr && block_addr.IsValid()) { |
| 234 | return m_opaque_ptr->GetRangeIndexContainingAddress(block_addr.ref()); |
| 235 | } |
| 236 | |
| 237 | return UINT32_MAX; |
Greg Clayton | 95897c6 | 2010-09-07 04:20:48 +0000 | [diff] [blame] | 238 | } |
| 239 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 240 | lldb::SBValueList SBBlock::GetVariables(lldb::SBFrame &frame, bool arguments, |
| 241 | bool locals, bool statics, |
| 242 | lldb::DynamicValueType use_dynamic) { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame] | 243 | LLDB_RECORD_METHOD( |
| 244 | lldb::SBValueList, SBBlock, GetVariables, |
| 245 | (lldb::SBFrame &, bool, bool, bool, lldb::DynamicValueType), frame, |
| 246 | arguments, locals, statics, use_dynamic); |
| 247 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 248 | Block *block = GetPtr(); |
| 249 | SBValueList value_list; |
| 250 | if (block) { |
| 251 | StackFrameSP frame_sp(frame.GetFrameSP()); |
| 252 | VariableListSP variable_list_sp(block->GetBlockVariableList(true)); |
Greg Clayton | 8f7180b | 2011-09-26 07:11:27 +0000 | [diff] [blame] | 253 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 254 | if (variable_list_sp) { |
| 255 | const size_t num_variables = variable_list_sp->GetSize(); |
| 256 | if (num_variables) { |
| 257 | for (size_t i = 0; i < num_variables; ++i) { |
| 258 | VariableSP variable_sp(variable_list_sp->GetVariableAtIndex(i)); |
| 259 | if (variable_sp) { |
| 260 | bool add_variable = false; |
| 261 | switch (variable_sp->GetScope()) { |
| 262 | case eValueTypeVariableGlobal: |
| 263 | case eValueTypeVariableStatic: |
| 264 | case eValueTypeVariableThreadLocal: |
| 265 | add_variable = statics; |
| 266 | break; |
Greg Clayton | 95897c6 | 2010-09-07 04:20:48 +0000 | [diff] [blame] | 267 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 268 | case eValueTypeVariableArgument: |
| 269 | add_variable = arguments; |
| 270 | break; |
Greg Clayton | 95897c6 | 2010-09-07 04:20:48 +0000 | [diff] [blame] | 271 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 272 | case eValueTypeVariableLocal: |
| 273 | add_variable = locals; |
| 274 | break; |
Greg Clayton | 4838131 | 2010-10-30 04:51:46 +0000 | [diff] [blame] | 275 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 276 | default: |
| 277 | break; |
Greg Clayton | 5569e64 | 2012-02-06 01:44:54 +0000 | [diff] [blame] | 278 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 279 | if (add_variable) { |
| 280 | if (frame_sp) { |
| 281 | lldb::ValueObjectSP valobj_sp( |
| 282 | frame_sp->GetValueObjectForFrameVariable(variable_sp, |
| 283 | eNoDynamicValues)); |
| 284 | SBValue value_sb; |
| 285 | value_sb.SetSP(valobj_sp, use_dynamic); |
| 286 | value_list.Append(value_sb); |
| 287 | } |
Greg Clayton | 5569e64 | 2012-02-06 01:44:54 +0000 | [diff] [blame] | 288 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 289 | } |
Greg Clayton | 5569e64 | 2012-02-06 01:44:54 +0000 | [diff] [blame] | 290 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 291 | } |
| 292 | } |
| 293 | } |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame] | 294 | return LLDB_RECORD_RESULT(value_list); |
Greg Clayton | 5569e64 | 2012-02-06 01:44:54 +0000 | [diff] [blame] | 295 | } |
| 296 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 297 | lldb::SBValueList SBBlock::GetVariables(lldb::SBTarget &target, bool arguments, |
| 298 | bool locals, bool statics) { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame] | 299 | LLDB_RECORD_METHOD(lldb::SBValueList, SBBlock, GetVariables, |
| 300 | (lldb::SBTarget &, bool, bool, bool), target, arguments, |
| 301 | locals, statics); |
| 302 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 303 | Block *block = GetPtr(); |
| 304 | |
| 305 | SBValueList value_list; |
| 306 | if (block) { |
| 307 | TargetSP target_sp(target.GetSP()); |
| 308 | |
| 309 | VariableListSP variable_list_sp(block->GetBlockVariableList(true)); |
| 310 | |
| 311 | if (variable_list_sp) { |
| 312 | const size_t num_variables = variable_list_sp->GetSize(); |
| 313 | if (num_variables) { |
| 314 | for (size_t i = 0; i < num_variables; ++i) { |
| 315 | VariableSP variable_sp(variable_list_sp->GetVariableAtIndex(i)); |
| 316 | if (variable_sp) { |
| 317 | bool add_variable = false; |
| 318 | switch (variable_sp->GetScope()) { |
| 319 | case eValueTypeVariableGlobal: |
| 320 | case eValueTypeVariableStatic: |
| 321 | case eValueTypeVariableThreadLocal: |
| 322 | add_variable = statics; |
| 323 | break; |
| 324 | |
| 325 | case eValueTypeVariableArgument: |
| 326 | add_variable = arguments; |
| 327 | break; |
| 328 | |
| 329 | case eValueTypeVariableLocal: |
| 330 | add_variable = locals; |
| 331 | break; |
| 332 | |
| 333 | default: |
| 334 | break; |
| 335 | } |
| 336 | if (add_variable) { |
| 337 | if (target_sp) |
| 338 | value_list.Append( |
| 339 | ValueObjectVariable::Create(target_sp.get(), variable_sp)); |
| 340 | } |
| 341 | } |
| 342 | } |
| 343 | } |
| 344 | } |
| 345 | } |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame] | 346 | return LLDB_RECORD_RESULT(value_list); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 347 | } |
Michal Gorny | ae211ec | 2019-03-19 17:13:13 +0000 | [diff] [blame] | 348 | |
| 349 | namespace lldb_private { |
| 350 | namespace repro { |
| 351 | |
| 352 | template <> |
| 353 | void RegisterMethods<SBBlock>(Registry &R) { |
| 354 | LLDB_REGISTER_CONSTRUCTOR(SBBlock, ()); |
| 355 | LLDB_REGISTER_CONSTRUCTOR(SBBlock, (const lldb::SBBlock &)); |
| 356 | LLDB_REGISTER_METHOD(const lldb::SBBlock &, |
| 357 | SBBlock, operator=,(const lldb::SBBlock &)); |
| 358 | LLDB_REGISTER_METHOD_CONST(bool, SBBlock, IsValid, ()); |
| 359 | LLDB_REGISTER_METHOD_CONST(bool, SBBlock, operator bool, ()); |
| 360 | LLDB_REGISTER_METHOD_CONST(bool, SBBlock, IsInlined, ()); |
| 361 | LLDB_REGISTER_METHOD_CONST(const char *, SBBlock, GetInlinedName, ()); |
| 362 | LLDB_REGISTER_METHOD_CONST(lldb::SBFileSpec, SBBlock, |
| 363 | GetInlinedCallSiteFile, ()); |
| 364 | LLDB_REGISTER_METHOD_CONST(uint32_t, SBBlock, GetInlinedCallSiteLine, ()); |
| 365 | LLDB_REGISTER_METHOD_CONST(uint32_t, SBBlock, GetInlinedCallSiteColumn, ()); |
| 366 | LLDB_REGISTER_METHOD(lldb::SBBlock, SBBlock, GetParent, ()); |
| 367 | LLDB_REGISTER_METHOD(lldb::SBBlock, SBBlock, GetContainingInlinedBlock, ()); |
| 368 | LLDB_REGISTER_METHOD(lldb::SBBlock, SBBlock, GetSibling, ()); |
| 369 | LLDB_REGISTER_METHOD(lldb::SBBlock, SBBlock, GetFirstChild, ()); |
| 370 | LLDB_REGISTER_METHOD(bool, SBBlock, GetDescription, (lldb::SBStream &)); |
| 371 | LLDB_REGISTER_METHOD(uint32_t, SBBlock, GetNumRanges, ()); |
| 372 | LLDB_REGISTER_METHOD(lldb::SBAddress, SBBlock, GetRangeStartAddress, |
| 373 | (uint32_t)); |
| 374 | LLDB_REGISTER_METHOD(lldb::SBAddress, SBBlock, GetRangeEndAddress, |
| 375 | (uint32_t)); |
| 376 | LLDB_REGISTER_METHOD(uint32_t, SBBlock, GetRangeIndexForBlockAddress, |
| 377 | (lldb::SBAddress)); |
| 378 | LLDB_REGISTER_METHOD( |
| 379 | lldb::SBValueList, SBBlock, GetVariables, |
| 380 | (lldb::SBFrame &, bool, bool, bool, lldb::DynamicValueType)); |
| 381 | LLDB_REGISTER_METHOD(lldb::SBValueList, SBBlock, GetVariables, |
| 382 | (lldb::SBTarget &, bool, bool, bool)); |
| 383 | } |
| 384 | |
| 385 | } |
| 386 | } |