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