LLDB mainline
Materializer.cpp
Go to the documentation of this file.
1//===-- Materializer.cpp --------------------------------------------------===//
2//
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
6//
7//===----------------------------------------------------------------------===//
8
12#include "lldb/Symbol/Symbol.h"
13#include "lldb/Symbol/Type.h"
18#include "lldb/Target/Target.h"
19#include "lldb/Target/Thread.h"
21#include "lldb/Utility/Log.h"
25#include "lldb/lldb-forward.h"
26
27#include <memory>
28#include <optional>
29
30using namespace lldb_private;
31
32// FIXME: these should be retrieved from the target
33// instead of being hard-coded. Currently we
34// assume that persistent vars are materialized
35// as references, and thus pick the size of a
36// 64-bit pointer.
37static constexpr uint32_t g_default_var_alignment = 8;
38static constexpr uint32_t g_default_var_byte_size = 8;
39
41 uint32_t size = entity.GetSize();
42 uint32_t alignment = entity.GetAlignment();
43
44 uint32_t ret;
45
46 if (m_current_offset == 0)
47 m_struct_alignment = alignment;
48
49 if (m_current_offset % alignment)
50 m_current_offset += (alignment - (m_current_offset % alignment));
51
52 ret = m_current_offset;
53
54 m_current_offset += size;
55
56 return ret;
57}
58
60public:
63 : Entity(), m_persistent_variable_sp(persistent_variable_sp),
64 m_delegate(delegate) {
65 // Hard-coding to maximum size of a pointer since persistent variables are
66 // materialized by reference
69 }
70
73
74 // Allocate a spare memory area to store the persistent variable's
75 // contents.
76
77 const bool zero_memory = false;
79 const uint64_t malloc_size =
80 llvm::expectedToOptional(m_persistent_variable_sp->GetByteSize())
81 .value_or(0);
82 auto address_or_error = map.Malloc(
83 malloc_size, 8, lldb::ePermissionsReadable | lldb::ePermissionsWritable,
84 IRMemoryMap::eAllocationPolicyMirror, zero_memory, &used_policy);
85 if (!address_or_error) {
87 "couldn't allocate a memory area to store %s: %s",
88 m_persistent_variable_sp->GetName().GetCString(),
89 toString(address_or_error.takeError()).c_str());
90 return;
91 }
92 lldb::addr_t mem = *address_or_error;
93
95 log, "Allocated 0x%" PRIx64 "bytes for %s (0x%" PRIx64 ") successfully",
96 malloc_size, m_persistent_variable_sp->GetName().GetCString(), mem);
97
98 // Put the location of the spare memory into the live data of the
99 // ValueObject.
100
103 m_persistent_variable_sp->GetCompilerType(),
105 map.GetAddressByteSize());
106
107 if (used_policy == IRMemoryMap::eAllocationPolicyMirror) {
108 if (m_persistent_variable_sp->m_flags &
110 // Clear the flag if the variable will never be deallocated.
111 Status leak_error;
112 map.Leak(mem, leak_error);
113 m_persistent_variable_sp->m_flags &=
114 ~ExpressionVariable::EVNeedsAllocation;
115 }
116 } else {
117 // If we cannot allocate memory in the process,
118 // - clear the 'EVKeepInTarget' flag to ensure that 'm_live_sp' is reset
119 // during dematerialization,
120 m_persistent_variable_sp->m_flags &= ~ExpressionVariable::EVKeepInTarget;
121 // - set the 'EVNeedsFreezeDry' flag so that the value is copied to
122 // 'm_frozen_sp' during dematerialization.
124 }
125
126 // Write the contents of the variable to the area.
127
128 Status write_error;
129
130 map.WriteMemory(
131 mem, m_persistent_variable_sp->GetValueBytes(),
132 llvm::expectedToOptional(m_persistent_variable_sp->GetByteSize())
133 .value_or(0),
134 write_error);
135
136 if (!write_error.Success()) {
138 "couldn't write {0} to the target: {1}",
139 m_persistent_variable_sp->GetName(), write_error.AsCString());
140 return;
141 }
142 }
143
145 Status deallocate_error;
146
147 lldb::ValueObjectSP live_valobj_sp =
148 m_persistent_variable_sp->GetLiveObject();
149 map.Free((lldb::addr_t)live_valobj_sp->GetValue().GetScalar().ULongLong(),
150 deallocate_error);
151
152 live_valobj_sp.reset();
153
154 if (!deallocate_error.Success()) {
156 "couldn't deallocate memory for %s: %s",
157 m_persistent_variable_sp->GetName().GetCString(),
158 deallocate_error.AsCString());
159 }
160 }
161
163 lldb::addr_t process_address, Status &err) override {
165
166 const lldb::addr_t load_addr = process_address + m_offset;
167
168 LLDB_LOG(log,
169 "EntityPersistentVariable::Materialize [address = {0:x}, m_name = "
170 "{1}, m_flags = {2:x}]",
171 (uint64_t)load_addr, m_persistent_variable_sp->GetName(),
172 m_persistent_variable_sp->m_flags);
173
174 if (m_persistent_variable_sp->m_flags &
176 MakeAllocation(map, err);
177 m_persistent_variable_sp->m_flags |=
179
180 if (!err.Success())
181 return;
182 }
183
184 lldb::ValueObjectSP live_valobj_sp =
185 m_persistent_variable_sp->GetLiveObject();
186 if ((m_persistent_variable_sp->m_flags &
188 live_valobj_sp) ||
189 m_persistent_variable_sp->m_flags &
191 Status write_error;
192
193 map.WriteScalarToMemory(load_addr, live_valobj_sp->GetValue().GetScalar(),
194 map.GetAddressByteSize(), write_error);
195
196 if (!write_error.Success()) {
198 "couldn't write the location of {0} to memory: {1}",
199 m_persistent_variable_sp->GetName(), write_error.AsCString());
200 }
201 } else {
203 "no materialization happened for persistent variable {0}",
204 m_persistent_variable_sp->GetName());
205 return;
206 }
207 }
208
210 lldb::addr_t process_address, lldb::addr_t frame_top,
211 lldb::addr_t frame_bottom, Status &err) override {
213
214 const lldb::addr_t load_addr = process_address + m_offset;
215
216 LLDB_LOG(log,
217 "EntityPersistentVariable::Dematerialize [address = {0:x}, m_name "
218 "= {1}, m_flags = {2}]",
219 (uint64_t)process_address + m_offset,
220 m_persistent_variable_sp->GetName(),
221 m_persistent_variable_sp->m_flags);
222
223 if (m_delegate) {
224 m_delegate->DidDematerialize(m_persistent_variable_sp);
225 }
226
227 lldb::ValueObjectSP live_valobj_sp =
228 m_persistent_variable_sp->GetLiveObject();
229 if ((m_persistent_variable_sp->m_flags &
231 (m_persistent_variable_sp->m_flags &
233 if (m_persistent_variable_sp->m_flags &
235 !live_valobj_sp) {
236 // If the reference comes from the program, then the
237 // ClangExpressionVariable's live variable data hasn't been set up yet.
238 // Do this now.
239
240 lldb::addr_t location;
241 Status read_error;
242
243 map.ReadPointerFromMemory(&location, load_addr, read_error);
244
245 if (!read_error.Success()) {
247 "couldn't read the address of program-allocated variable %s: %s",
248 m_persistent_variable_sp->GetName().GetCString(),
249 read_error.AsCString());
250 return;
251 }
252
255 m_persistent_variable_sp->GetCompilerType(),
256 m_persistent_variable_sp->GetName(), location, eAddressTypeLoad,
257 llvm::expectedToOptional(m_persistent_variable_sp->GetByteSize())
258 .value_or(0));
259
260 if (frame_top != LLDB_INVALID_ADDRESS &&
261 frame_bottom != LLDB_INVALID_ADDRESS && location >= frame_bottom &&
262 location <= frame_top) {
263 // If the variable is resident in the stack frame created by the
264 // expression, then it cannot be relied upon to stay around. We
265 // treat it as needing reallocation.
266 m_persistent_variable_sp->m_flags |=
268 m_persistent_variable_sp->m_flags |=
270 m_persistent_variable_sp->m_flags |=
272 m_persistent_variable_sp->m_flags &=
273 ~ExpressionVariable::EVIsProgramReference;
274 }
275 }
276
277 if (!live_valobj_sp) {
279 "couldn't find the memory area used to store %s",
280 m_persistent_variable_sp->GetName().GetCString());
281 return;
282 }
283
284 lldb::addr_t mem = live_valobj_sp->GetValue().GetScalar().ULongLong();
285
286 if (live_valobj_sp->GetValue().GetValueAddressType() !=
289 "the address of the memory area for %s is in an incorrect format",
290 m_persistent_variable_sp->GetName().GetCString());
291 return;
292 }
293
294 if (m_persistent_variable_sp->m_flags &
296 m_persistent_variable_sp->m_flags &
298 LLDB_LOGF(log, "Dematerializing %s from 0x%" PRIx64 " (size = %llu)",
299 m_persistent_variable_sp->GetName().GetCString(),
300 (uint64_t)mem,
301 (unsigned long long)llvm::expectedToOptional(
302 m_persistent_variable_sp->GetByteSize())
303 .value_or(0));
304
305 // Read the contents of the spare memory area
306
307 m_persistent_variable_sp->ValueUpdated();
308
309 Status read_error;
310
311 map.ReadMemory(
312 m_persistent_variable_sp->GetValueBytes(), mem,
313 llvm::expectedToOptional(m_persistent_variable_sp->GetByteSize())
314 .value_or(0),
315 read_error);
316
317 if (!read_error.Success()) {
319 "couldn't read the contents of %s from memory: %s",
320 m_persistent_variable_sp->GetName().GetCString(),
321 read_error.AsCString());
322 return;
323 }
324 m_persistent_variable_sp->m_flags &=
325 ~ExpressionVariable::EVNeedsFreezeDry;
326 }
327 } else {
329 "no dematerialization happened for persistent variable {0}",
330 m_persistent_variable_sp->GetName());
331 return;
332 }
333
334 if (m_persistent_variable_sp->m_flags &
336 !(m_persistent_variable_sp->m_flags &
338 DestroyAllocation(map, err);
339 if (!err.Success())
340 return;
341 }
342 }
343
344 void DumpToLog(IRMemoryMap &map, lldb::addr_t process_address,
345 Log *log) override {
346 StreamString dump_stream;
347
348 Status err;
349
350 const lldb::addr_t load_addr = process_address + m_offset;
351
352 dump_stream.Format("{0:x}: EntityPersistentVariable ({1})\n", load_addr,
353 m_persistent_variable_sp->GetName());
354
355 {
356 dump_stream.PutCString("Pointer:\n");
357
358 DataBufferHeap data(m_size, 0);
359
360 map.ReadMemory(data.GetBytes(), load_addr, m_size, err);
361
362 if (!err.Success()) {
363 dump_stream.PutCString(" <could not be read>\n");
364 } else {
365 DumpHexBytes(&dump_stream, data.GetBytes(), data.GetByteSize(), 16,
366 load_addr);
367
368 dump_stream.PutChar('\n');
369 }
370 }
371
372 {
373 dump_stream.PutCString("Target:\n");
374
375 lldb::addr_t target_address;
376
377 map.ReadPointerFromMemory(&target_address, load_addr, err);
378
379 if (!err.Success()) {
380 dump_stream.PutCString(" <could not be read>\n");
381 } else {
382 DataBufferHeap data(
383 llvm::expectedToOptional(m_persistent_variable_sp->GetByteSize())
384 .value_or(0),
385 0);
386
387 map.ReadMemory(
388 data.GetBytes(), target_address,
389 llvm::expectedToOptional(m_persistent_variable_sp->GetByteSize())
390 .value_or(0),
391 err);
392
393 if (!err.Success()) {
394 dump_stream.PutCString(" <could not be read>\n");
395 } else {
396 DumpHexBytes(&dump_stream, data.GetBytes(), data.GetByteSize(), 16,
397 target_address);
398
399 dump_stream.PutChar('\n');
400 }
401 }
402 }
403
404 log->PutString(dump_stream.GetString());
405 }
406
407 void Wipe(IRMemoryMap &map, lldb::addr_t process_address) override {}
408
409private:
412};
413
415 lldb::ExpressionVariableSP &persistent_variable_sp,
416 PersistentVariableDelegate *delegate, Status &err) {
417 EntityVector::iterator iter = m_entities.insert(m_entities.end(), EntityUP());
418 *iter = std::make_unique<EntityPersistentVariable>(persistent_variable_sp,
419 delegate);
420 uint32_t ret = AddStructMember(**iter);
421 (*iter)->SetOffset(ret);
422 return ret;
423}
424
425/// Base class for materialization of Variables and ValueObjects.
426///
427/// Subclasses specify how to obtain the Value which is to be
428/// materialized.
430public:
431 virtual ~EntityVariableBase() = default;
432
434 // Hard-coding to maximum size of a pointer since all variables are
435 // materialized by reference
438 }
439
441 lldb::addr_t process_address, Status &err) override {
443
444 const lldb::addr_t load_addr = process_address + m_offset;
445 LLDB_LOGF(log,
446 "EntityVariable::Materialize [address = 0x%" PRIx64
447 ", m_variable_sp = %s]",
448 (uint64_t)load_addr, GetName().GetCString());
449
450 ExecutionContextScope *scope = frame_sp.get();
451
452 if (!scope)
453 scope = map.GetBestExecutionContextScope();
454
455 lldb::ValueObjectSP valobj_sp = SetupValueObject(scope);
456
457 if (!valobj_sp) {
459 "couldn't get a value object for variable {0}", GetName());
460 return;
461 }
462
463 Status valobj_error = valobj_sp->GetError().Clone();
464
465 if (valobj_error.Fail()) {
467 "couldn't get the value of variable {0}: {1}", GetName(),
468 valobj_error.AsCString());
469 return;
470 }
471
472 if (m_is_reference) {
473 DataExtractor valobj_extractor;
474 Status extract_error;
475 valobj_sp->GetData(valobj_extractor, extract_error);
476
477 if (!extract_error.Success()) {
479 "couldn't read contents of reference variable {0}: {1}", GetName(),
480 extract_error.AsCString());
481 return;
482 }
483
484 lldb::offset_t offset = 0;
485 lldb::addr_t reference_addr = valobj_extractor.GetAddress(&offset);
486
487 Status write_error;
488 map.WritePointerToMemory(load_addr, reference_addr, write_error);
489
490 if (!write_error.Success()) {
492 "couldn't write the contents of reference variable {} to memory: "
493 "{}",
494 GetName(), write_error.AsCString());
495 return;
496 }
497 } else {
498 lldb::addr_t addr_of_valobj =
499 valobj_sp->GetAddressOf(/*scalar_is_load_address=*/false).address;
500 if (addr_of_valobj != LLDB_INVALID_ADDRESS) {
501 Status write_error;
502 map.WritePointerToMemory(load_addr, addr_of_valobj, write_error);
503
504 if (!write_error.Success()) {
506 "couldn't write the address of variable {0} to memory: {1}",
507 GetName(), write_error.AsCString());
508 return;
509 }
510 } else if (valobj_sp->HasNoStorage()) {
511 // Without a location, a variable whose type occupies no memory has no
512 // data to copy into a temporary region. A null pointer serves as its
513 // address, because the expression never accesses any of its bytes.
514 Status write_error;
515 map.WritePointerToMemory(load_addr, 0, write_error);
516 if (!write_error.Success()) {
518 "couldn't write the address of variable {0} to memory: {1}",
519 GetName(), write_error.AsCString());
520 return;
521 }
522 } else {
523 DataExtractor data;
524 Status extract_error;
525 valobj_sp->GetData(data, extract_error);
526 if (!extract_error.Success()) {
528 "couldn't get the value of {0}: {1}", GetName(),
529 extract_error.AsCString());
530 return;
531 }
532
535 "trying to create a temporary region for {0} but one exists",
536 GetName());
537 return;
538 }
539
540 if (data.GetByteSize() <
541 llvm::expectedToOptional(GetByteSize(scope)).value_or(0)) {
542 if (data.GetByteSize() == 0 && !LocationExpressionIsValid()) {
544 "the variable '{0}' has no location, "
545 "it may have been optimized out",
546 GetName());
547 } else {
549 "size of variable {0} ({1}) is larger than the ValueObject's "
550 "size ({2})",
551 GetName(),
552 llvm::expectedToOptional(GetByteSize(scope)).value_or(0),
553 data.GetByteSize());
554 }
555 return;
556 }
557
558 std::optional<size_t> opt_bit_align = GetTypeBitAlign(scope);
559 if (!opt_bit_align) {
561 "can't get the type alignment for {0}", GetName());
562 return;
563 }
564
565 size_t byte_align = (*opt_bit_align + 7) / 8;
566
567 const bool zero_memory = false;
568 if (auto address_or_error = map.Malloc(
569 data.GetByteSize(), byte_align,
570 lldb::ePermissionsReadable | lldb::ePermissionsWritable,
572 m_temporary_allocation = *address_or_error;
573 } else {
575 "couldn't allocate a temporary region for {0}: {1}", GetName(),
576 toString(address_or_error.takeError()));
577 return;
578 }
579
581
582 m_original_data = std::make_shared<DataBufferHeap>(data.GetDataStart(),
583 data.GetByteSize());
584
585 Status write_error;
586
588 data.GetByteSize(), write_error);
589
590 if (!write_error.Success()) {
592 "couldn't write to the temporary region for {0}: {1}", GetName(),
593 write_error.AsCString());
594 return;
595 }
596
597 Status pointer_write_error;
598
600 pointer_write_error);
601
602 if (!pointer_write_error.Success()) {
604 "couldn't write the address of the temporary region for {0}: {1}",
605 GetName(), pointer_write_error.AsCString());
606 }
607 }
608 }
609 }
610
612 lldb::addr_t process_address, lldb::addr_t frame_top,
613 lldb::addr_t frame_bottom, Status &err) override {
615
616 const lldb::addr_t load_addr = process_address + m_offset;
617 LLDB_LOG(
618 log,
619 "EntityVariable::Dematerialize [address = {0:x}, m_variable_sp = {1}]",
620 (uint64_t)load_addr, GetName());
621
623 ExecutionContextScope *scope = frame_sp.get();
624
625 if (!scope)
626 scope = map.GetBestExecutionContextScope();
627
628 lldb::ValueObjectSP valobj_sp = SetupValueObject(scope);
629
630 if (!valobj_sp) {
632 "couldn't get a value object for variable {0}", GetName());
633 return;
634 }
635
637
638 Status extract_error;
639
640 map.GetMemoryData(
642 llvm::expectedToOptional(valobj_sp->GetByteSize()).value_or(0),
643 extract_error);
644
645 if (!extract_error.Success()) {
647 "couldn't get the data for variable {0}", GetName());
648 return;
649 }
650
651 bool actually_write = true;
652
653 if (m_original_data) {
654 if ((data.GetByteSize() == m_original_data->GetByteSize()) &&
655 !memcmp(m_original_data->GetBytes(), data.GetDataStart(),
656 data.GetByteSize())) {
657 actually_write = false;
658 }
659 }
660
661 Status set_error;
662
663 if (actually_write) {
664 valobj_sp->SetData(data, set_error);
665
666 if (!set_error.Success()) {
668 "couldn't write the new contents of {0} back into the variable",
669 GetName());
670 return;
671 }
672 }
673
674 Status free_error;
675
676 map.Free(m_temporary_allocation, free_error);
677
678 if (!free_error.Success()) {
680 "couldn't free the temporary region for {0}: {1}", GetName(),
681 free_error.AsCString());
682 return;
683 }
684
685 m_original_data.reset();
688 }
689 }
690
691 void DumpToLog(IRMemoryMap &map, lldb::addr_t process_address,
692 Log *log) override {
693 StreamString dump_stream;
694
695 const lldb::addr_t load_addr = process_address + m_offset;
696 dump_stream.Printf("0x%" PRIx64 ": EntityVariable\n", load_addr);
697
698 Status err;
699
701
702 {
703 dump_stream.PutCString("Pointer:\n");
704
705 DataBufferHeap data(m_size, 0);
706
707 map.ReadMemory(data.GetBytes(), load_addr, m_size, err);
708
709 if (!err.Success()) {
710 dump_stream.PutCString(" <could not be read>\n");
711 } else {
712 DataExtractor extractor(data.GetBytes(), data.GetByteSize(),
713 map.GetByteOrder(), map.GetAddressByteSize());
714
715 DumpHexBytes(&dump_stream, data.GetBytes(), data.GetByteSize(), 16,
716 load_addr);
717
718 lldb::offset_t offset = 0;
719
720 ptr = extractor.GetAddress(&offset);
721
722 dump_stream.PutChar('\n');
723 }
724 }
725
727 dump_stream.PutCString("Points to process memory:\n");
728 } else {
729 dump_stream.PutCString("Temporary allocation:\n");
730 }
731
732 if (ptr == LLDB_INVALID_ADDRESS) {
733 dump_stream.PutCString(" <could not be be found>\n");
734 } else {
736
739
740 if (!err.Success()) {
741 dump_stream.PutCString(" <could not be read>\n");
742 } else {
743 DumpHexBytes(&dump_stream, data.GetBytes(), data.GetByteSize(), 16,
744 load_addr);
745
746 dump_stream.PutChar('\n');
747 }
748 }
749
750 log->PutString(dump_stream.GetString());
751 }
752
753 void Wipe(IRMemoryMap &map, lldb::addr_t process_address) override {
755 Status free_error;
756
757 map.Free(m_temporary_allocation, free_error);
758
761 }
762 }
763
764private:
765 virtual ConstString GetName() const = 0;
766
767 /// Creates and returns ValueObject tied to this variable
768 /// and prepares Entity for materialization.
769 ///
770 /// Called each time the Materializer (de)materializes a
771 /// variable. We re-create the ValueObject based on the
772 /// current ExecutionContextScope since clients such as
773 /// conditional breakpoints may materialize the same
774 /// EntityVariable multiple times with different frames.
775 ///
776 /// Each subsequent use of the EntityVariableBase interface
777 /// will query the newly created ValueObject until this
778 /// function is called again.
779 virtual lldb::ValueObjectSP
781
782 /// Returns size in bytes of the type associated with this variable
783 ///
784 /// \returns On success, returns byte size of the type associated
785 /// with this variable. Returns std::nullopt otherwise.
786 virtual llvm::Expected<uint64_t>
788
789 /// Returns 'true' if the location expression associated with this variable
790 /// is valid.
791 virtual bool LocationExpressionIsValid() const = 0;
792
793 /// Returns alignment of the type associated with this variable in bits.
794 ///
795 /// \returns On success, returns alignment in bits for the type associated
796 /// with this variable. Returns std::nullopt otherwise.
797 virtual std::optional<size_t>
799
800protected:
801 bool m_is_reference = false;
805};
806
807/// Represents an Entity constructed from a VariableSP.
808///
809/// This class is used for materialization of variables for which
810/// the user has a VariableSP on hand. The ValueObject is then
811/// derived from the associated DWARF location expression when needed
812/// by the Materializer.
814public:
815 EntityVariable(lldb::VariableSP &variable_sp) : m_variable_sp(variable_sp) {
817 m_variable_sp->GetType()->GetForwardCompilerType().IsReferenceType();
818 }
819
820 ConstString GetName() const override { return m_variable_sp->GetName(); }
821
823 assert(m_variable_sp != nullptr);
825 }
826
827 llvm::Expected<uint64_t>
828 GetByteSize(ExecutionContextScope *scope) const override {
829 return m_variable_sp->GetType()->GetByteSize(scope);
830 }
831
832 bool LocationExpressionIsValid() const override {
833 return m_variable_sp->LocationExpressionList().IsValid();
834 }
835
836 std::optional<size_t>
837 GetTypeBitAlign(ExecutionContextScope *scope) const override {
838 return m_variable_sp->GetType()->GetLayoutCompilerType().GetTypeBitAlign(
839 scope);
840 }
841
842private:
843 lldb::VariableSP m_variable_sp; ///< Variable that this entity is based on.
844};
845
846/// Represents an Entity constructed from a VariableSP.
847///
848/// This class is used for materialization of variables for
849/// which the user does not have a VariableSP available (e.g.,
850/// when materializing ivars).
852public:
854 : m_name(name), m_valobj_provider(std::move(provider)) {
855 assert(m_valobj_provider);
856 }
857
858 ConstString GetName() const override { return m_name; }
859
863
864 if (m_valobj_sp)
865 m_is_reference = m_valobj_sp->GetCompilerType().IsReferenceType();
866
867 return m_valobj_sp;
868 }
869
870 llvm::Expected<uint64_t>
871 GetByteSize(ExecutionContextScope *scope) const override {
872 if (m_valobj_sp)
873 return m_valobj_sp->GetCompilerType().GetByteSize(scope);
874
875 return llvm::createStringError("no value object");
876 }
877
878 bool LocationExpressionIsValid() const override {
879 if (m_valobj_sp)
880 return m_valobj_sp->GetError().Success();
881
882 return false;
883 }
884
885 std::optional<size_t>
886 GetTypeBitAlign(ExecutionContextScope *scope) const override {
887 if (m_valobj_sp)
888 return m_valobj_sp->GetCompilerType().GetTypeBitAlign(scope);
889
890 return {};
891 }
892
893private:
897};
898
900 EntityVector::iterator iter = m_entities.insert(m_entities.end(), EntityUP());
901 *iter = std::make_unique<EntityVariable>(variable_sp);
902 uint32_t ret = AddStructMember(**iter);
903 (*iter)->SetOffset(ret);
904 return ret;
905}
906
908 ValueObjectProviderTy valobj_provider,
909 Status &err) {
910 assert(valobj_provider);
911 EntityVector::iterator iter = m_entities.insert(m_entities.end(), EntityUP());
912 *iter = std::make_unique<EntityValueObject>(name, std::move(valobj_provider));
913 uint32_t ret = AddStructMember(**iter);
914 (*iter)->SetOffset(ret);
915 return ret;
916}
917
919public:
920 EntityResultVariable(const CompilerType &type, bool is_program_reference,
921 bool keep_in_memory,
923 : Entity(), m_type(type), m_is_program_reference(is_program_reference),
924 m_keep_in_memory(keep_in_memory), m_delegate(delegate) {
925 // Hard-coding to maximum size of a pointer since all results are
926 // materialized by reference
929 }
930
932 lldb::addr_t process_address, Status &err) override {
936 "Trying to create a temporary region for the result "
937 "but one exists");
938 return;
939 }
940
941 const lldb::addr_t load_addr = process_address + m_offset;
942
943 ExecutionContextScope *exe_scope = frame_sp.get();
944 if (!exe_scope)
945 exe_scope = map.GetBestExecutionContextScope();
946
947 auto byte_size_or_err = m_type.GetByteSize(exe_scope);
948 if (!byte_size_or_err) {
949 err = Status::FromError(byte_size_or_err.takeError());
950 return;
951 }
952 auto byte_size = *byte_size_or_err;
953
954 std::optional<size_t> opt_bit_align = m_type.GetTypeBitAlign(exe_scope);
955 if (!opt_bit_align) {
957 "can't get the alignment of type \"{0}\"", m_type.GetTypeName());
958 return;
959 }
960
961 size_t byte_align = (*opt_bit_align + 7) / 8;
962
963 const bool zero_memory = true;
964 if (auto address_or_error = map.Malloc(
965 byte_size, byte_align,
966 lldb::ePermissionsReadable | lldb::ePermissionsWritable,
968 m_temporary_allocation = *address_or_error;
969 } else {
971 "couldn't allocate a temporary region for the result: %s",
972 toString(address_or_error.takeError()).c_str());
973 return;
974 }
975
976 m_temporary_allocation_size = byte_size;
977
978 Status pointer_write_error;
979
981 pointer_write_error);
982
983 if (!pointer_write_error.Success()) {
985 "couldn't write the address of the "
986 "temporary region for the result: %s",
987 pointer_write_error.AsCString());
988 }
989 }
990 }
991
993 lldb::addr_t process_address, lldb::addr_t frame_top,
994 lldb::addr_t frame_bottom, Status &err) override {
995 err.Clear();
996
997 ExecutionContextScope *exe_scope = frame_sp.get();
998 if (!exe_scope)
999 exe_scope = map.GetBestExecutionContextScope();
1000
1001 if (!exe_scope) {
1003 "Couldn't dematerialize a result variable: invalid "
1004 "execution context scope");
1005 return;
1006 }
1007
1008 lldb::addr_t address;
1009 Status read_error;
1010 const lldb::addr_t load_addr = process_address + m_offset;
1011
1012 map.ReadPointerFromMemory(&address, load_addr, read_error);
1013
1014 if (!read_error.Success()) {
1016 "Couldn't dematerialize a result variable: couldn't "
1017 "read its address");
1018 return;
1019 }
1020
1021 lldb::TargetSP target_sp = exe_scope->CalculateTarget();
1022
1023 if (!target_sp) {
1025 "Couldn't dematerialize a result variable: no target");
1026 return;
1027 }
1028
1029 auto type_system_or_err =
1030 target_sp->GetScratchTypeSystemForLanguage(m_type.GetMinimumLanguage());
1031
1032 if (auto error = type_system_or_err.takeError()) {
1034 "Couldn't dematerialize a result variable: "
1035 "couldn't get the corresponding type "
1036 "system: %s",
1037 llvm::toString(std::move(error)).c_str());
1038 return;
1039 }
1040 auto ts = *type_system_or_err;
1041 if (!ts) {
1043 "Couldn't dematerialize a result variable: "
1044 "couldn't corresponding type system is "
1045 "no longer live.");
1046 return;
1047 }
1048 PersistentExpressionState *persistent_state =
1049 ts->GetPersistentExpressionState();
1050
1051 if (!persistent_state) {
1053 "Couldn't dematerialize a result variable: "
1054 "corresponding type system doesn't handle persistent "
1055 "variables");
1056 return;
1057 }
1058
1059 ConstString name = m_delegate
1060 ? m_delegate->GetName()
1061 : persistent_state->GetNextPersistentVariableName();
1062
1064 exe_scope, name, m_type, map.GetByteOrder(), map.GetAddressByteSize());
1065
1066 if (!ret) {
1068 "couldn't dematerialize a result variable: failed to make persistent "
1069 "variable {0}",
1070 name);
1071 return;
1072 }
1073
1074 lldb::ProcessSP process_sp =
1076
1077 if (m_delegate) {
1078 m_delegate->DidDematerialize(ret);
1079 }
1080
1081 bool can_persist = m_is_program_reference &&
1082 !(address >= frame_bottom && address < frame_top);
1083
1084 if (can_persist && m_keep_in_memory) {
1085 ret->m_live_sp = ValueObjectConstResult::Create(exe_scope, m_type, name,
1086 address, eAddressTypeLoad,
1087 map.GetAddressByteSize());
1088 }
1089
1090 ret->ValueUpdated();
1091
1092 const size_t pvar_byte_size =
1093 llvm::expectedToOptional(ret->GetByteSize()).value_or(0);
1094 uint8_t *pvar_data = ret->GetValueBytes();
1095
1096 map.ReadMemory(pvar_data, address, pvar_byte_size, read_error);
1097
1098 if (!read_error.Success()) {
1100 "Couldn't dematerialize a result variable: couldn't read its memory");
1101 return;
1102 }
1103
1104 if (!can_persist || !m_keep_in_memory) {
1106
1108 Status free_error;
1109 map.Free(m_temporary_allocation, free_error);
1110 }
1111 } else {
1112 ret->m_flags |= m_is_program_reference
1115 }
1116
1119 }
1120
1121 void DumpToLog(IRMemoryMap &map, lldb::addr_t process_address,
1122 Log *log) override {
1123 StreamString dump_stream;
1124
1125 const lldb::addr_t load_addr = process_address + m_offset;
1126
1127 dump_stream.Printf("0x%" PRIx64 ": EntityResultVariable\n", load_addr);
1128
1129 Status err;
1130
1132
1133 {
1134 dump_stream.PutCString("Pointer:\n");
1135
1136 DataBufferHeap data(m_size, 0);
1137
1138 map.ReadMemory(data.GetBytes(), load_addr, m_size, err);
1139
1140 if (!err.Success()) {
1141 dump_stream.PutCString(" <could not be read>\n");
1142 } else {
1143 DataExtractor extractor(data.GetBytes(), data.GetByteSize(),
1144 map.GetByteOrder(), map.GetAddressByteSize());
1145
1146 DumpHexBytes(&dump_stream, data.GetBytes(), data.GetByteSize(), 16,
1147 load_addr);
1148
1149 lldb::offset_t offset = 0;
1150
1151 ptr = extractor.GetAddress(&offset);
1152
1153 dump_stream.PutChar('\n');
1154 }
1155 }
1156
1158 dump_stream.PutCString("Points to process memory:\n");
1159 } else {
1160 dump_stream.PutCString("Temporary allocation:\n");
1161 }
1162
1163 if (ptr == LLDB_INVALID_ADDRESS) {
1164 dump_stream.PutCString(" <could not be be found>\n");
1165 } else {
1167
1170
1171 if (!err.Success()) {
1172 dump_stream.PutCString(" <could not be read>\n");
1173 } else {
1174 DumpHexBytes(&dump_stream, data.GetBytes(), data.GetByteSize(), 16,
1175 load_addr);
1176
1177 dump_stream.PutChar('\n');
1178 }
1179 }
1180
1181 log->PutString(dump_stream.GetString());
1182 }
1183
1184 void Wipe(IRMemoryMap &map, lldb::addr_t process_address) override {
1186 Status free_error;
1187
1188 map.Free(m_temporary_allocation, free_error);
1189 }
1190
1193 }
1194
1195private:
1197 /// This is used both to control whether this result entity can (and should)
1198 /// track the value in inferior memory, as well as to control whether LLDB
1199 /// needs to allocate memory for the variable during materialization.
1202
1206};
1207
1209 bool is_program_reference,
1210 bool keep_in_memory,
1212 Status &err) {
1213 EntityVector::iterator iter = m_entities.insert(m_entities.end(), EntityUP());
1214 *iter = std::make_unique<EntityResultVariable>(type, is_program_reference,
1215 keep_in_memory, delegate);
1216 uint32_t ret = AddStructMember(**iter);
1217 (*iter)->SetOffset(ret);
1218 return ret;
1219}
1220
1222public:
1223 EntitySymbol(const Symbol &symbol) : Entity(), m_symbol(symbol) {
1224 // Hard-coding to maximum size of a symbol
1227 }
1228
1230 lldb::addr_t process_address, Status &err) override {
1232
1233 const lldb::addr_t load_addr = process_address + m_offset;
1234
1235 LLDB_LOG(log, "EntitySymbol::Materialize [address = {0:x}, m_symbol = {1}]",
1236 (uint64_t)load_addr, m_symbol.GetName());
1237
1238 const Address sym_address = m_symbol.GetAddress();
1239
1240 ExecutionContextScope *exe_scope = frame_sp.get();
1241 if (!exe_scope)
1242 exe_scope = map.GetBestExecutionContextScope();
1243
1244 lldb::TargetSP target_sp;
1245
1246 if (exe_scope)
1247 target_sp = map.GetBestExecutionContextScope()->CalculateTarget();
1248
1249 if (!target_sp) {
1251 "couldn't resolve symbol {0} because there is no target",
1252 m_symbol.GetName());
1253 return;
1254 }
1255
1256 lldb::addr_t resolved_address = sym_address.GetLoadAddress(target_sp.get());
1257
1258 if (resolved_address == LLDB_INVALID_ADDRESS)
1259 resolved_address = sym_address.GetFileAddress();
1260
1261 Status pointer_write_error;
1262
1263 map.WritePointerToMemory(load_addr, resolved_address, pointer_write_error);
1264
1265 if (!pointer_write_error.Success()) {
1267 "couldn't write the address of symbol {0}: {1}", m_symbol.GetName(),
1268 pointer_write_error.AsCString());
1269 return;
1270 }
1271 }
1272
1274 lldb::addr_t process_address, lldb::addr_t frame_top,
1275 lldb::addr_t frame_bottom, Status &err) override {
1277
1278 const lldb::addr_t load_addr = process_address + m_offset;
1279
1280 LLDB_LOG(log,
1281 "EntitySymbol::Dematerialize [address = {0:x}, m_symbol = {1}]",
1282 (uint64_t)load_addr, m_symbol.GetName());
1283
1284 // no work needs to be done
1285 }
1286
1287 void DumpToLog(IRMemoryMap &map, lldb::addr_t process_address,
1288 Log *log) override {
1289 StreamString dump_stream;
1290
1291 Status err;
1292
1293 const lldb::addr_t load_addr = process_address + m_offset;
1294
1295 dump_stream.Format("{0:x}: EntitySymbol ({1})\n", load_addr,
1296 m_symbol.GetName());
1297
1298 {
1299 dump_stream.PutCString("Pointer:\n");
1300
1301 DataBufferHeap data(m_size, 0);
1302
1303 map.ReadMemory(data.GetBytes(), load_addr, m_size, err);
1304
1305 if (!err.Success()) {
1306 dump_stream.PutCString(" <could not be read>\n");
1307 } else {
1308 DumpHexBytes(&dump_stream, data.GetBytes(), data.GetByteSize(), 16,
1309 load_addr);
1310
1311 dump_stream.PutChar('\n');
1312 }
1313 }
1314
1315 log->PutString(dump_stream.GetString());
1316 }
1317
1318 void Wipe(IRMemoryMap &map, lldb::addr_t process_address) override {}
1319
1320private:
1322};
1323
1324uint32_t Materializer::AddSymbol(const Symbol &symbol_sp, Status &err) {
1325 EntityVector::iterator iter = m_entities.insert(m_entities.end(), EntityUP());
1326 *iter = std::make_unique<EntitySymbol>(symbol_sp);
1327 uint32_t ret = AddStructMember(**iter);
1328 (*iter)->SetOffset(ret);
1329 return ret;
1330}
1331
1333public:
1334 EntityRegister(const RegisterInfo &register_info)
1335 : Entity(), m_register_info(register_info) {
1336 // Hard-coding alignment conservatively
1337 m_size = m_register_info.byte_size;
1338 m_alignment = m_register_info.byte_size;
1339 }
1340
1342 lldb::addr_t process_address, Status &err) override {
1344
1345 const lldb::addr_t load_addr = process_address + m_offset;
1346
1347 LLDB_LOGF(log,
1348 "EntityRegister::Materialize [address = 0x%" PRIx64
1349 ", m_register_info = %s]",
1350 (uint64_t)load_addr, m_register_info.name);
1351
1352 RegisterValue reg_value;
1353
1354 if (!frame_sp.get()) {
1356 "couldn't materialize register %s without a stack frame",
1357 m_register_info.name);
1358 return;
1359 }
1360
1361 lldb::RegisterContextSP reg_context_sp = frame_sp->GetRegisterContext();
1362
1363 if (!reg_context_sp->ReadRegister(&m_register_info, reg_value)) {
1365 "couldn't read the value of register %s", m_register_info.name);
1366 return;
1367 }
1368
1369 if (reg_value.GetByteSize() != m_register_info.byte_size) {
1371 "data for register %s had size %llu but we expected %llu",
1372 m_register_info.name, (unsigned long long)reg_value.GetByteSize(),
1373 (unsigned long long)m_register_info.byte_size);
1374 return;
1375 }
1376
1377 lldb_private::DataBufferHeap buf(reg_value.GetByteSize(), 0);
1378 reg_value.GetAsMemoryData(m_register_info, buf.GetBytes(),
1379 buf.GetByteSize(), map.GetByteOrder(), err);
1380 if (!err.Success())
1381 return;
1382
1383 m_register_contents = std::make_shared<DataBufferHeap>(buf);
1384
1385 Status write_error;
1386
1387 map.WriteMemory(load_addr, buf.GetBytes(), reg_value.GetByteSize(),
1388 write_error);
1389
1390 if (!write_error.Success()) {
1392 "couldn't write the contents of register %s: %s",
1393 m_register_info.name, write_error.AsCString());
1394 return;
1395 }
1396 }
1397
1399 lldb::addr_t process_address, lldb::addr_t frame_top,
1400 lldb::addr_t frame_bottom, Status &err) override {
1402
1403 const lldb::addr_t load_addr = process_address + m_offset;
1404
1405 LLDB_LOGF(log,
1406 "EntityRegister::Dematerialize [address = 0x%" PRIx64
1407 ", m_register_info = %s]",
1408 (uint64_t)load_addr, m_register_info.name);
1409
1410 Status extract_error;
1411
1412 DataExtractor register_data;
1413
1414 if (!frame_sp.get()) {
1416 "couldn't dematerialize register %s without a stack frame",
1417 m_register_info.name);
1418 return;
1419 }
1420
1421 lldb::RegisterContextSP reg_context_sp = frame_sp->GetRegisterContext();
1422
1423 map.GetMemoryData(register_data, load_addr, m_register_info.byte_size,
1424 extract_error);
1425
1426 if (!extract_error.Success()) {
1428 "couldn't get the data for register %s: %s", m_register_info.name,
1429 extract_error.AsCString());
1430 return;
1431 }
1432
1433 if (!memcmp(register_data.GetDataStart(), m_register_contents->GetBytes(),
1434 register_data.GetByteSize())) {
1435 // No write required, and in particular we avoid errors if the register
1436 // wasn't writable
1437
1438 m_register_contents.reset();
1439 return;
1440 }
1441
1442 m_register_contents.reset();
1443
1444 RegisterValue register_value(register_data.GetData(),
1445 register_data.GetByteOrder());
1446
1447 if (!reg_context_sp->WriteRegister(&m_register_info, register_value)) {
1449 "couldn't write the value of register %s", m_register_info.name);
1450 return;
1451 }
1452 }
1453
1454 void DumpToLog(IRMemoryMap &map, lldb::addr_t process_address,
1455 Log *log) override {
1456 StreamString dump_stream;
1457
1458 Status err;
1459
1460 const lldb::addr_t load_addr = process_address + m_offset;
1461
1462 dump_stream.Printf("0x%" PRIx64 ": EntityRegister (%s)\n", load_addr,
1463 m_register_info.name);
1464
1465 {
1466 dump_stream.PutCString("Value:\n");
1467
1468 DataBufferHeap data(m_size, 0);
1469
1470 map.ReadMemory(data.GetBytes(), load_addr, m_size, err);
1471
1472 if (!err.Success()) {
1473 dump_stream.PutCString(" <could not be read>\n");
1474 } else {
1475 DumpHexBytes(&dump_stream, data.GetBytes(), data.GetByteSize(), 16,
1476 load_addr);
1477
1478 dump_stream.PutChar('\n');
1479 }
1480 }
1481
1482 log->PutString(dump_stream.GetString());
1483 }
1484
1485 void Wipe(IRMemoryMap &map, lldb::addr_t process_address) override {}
1486
1487private:
1490};
1491
1492uint32_t Materializer::AddRegister(const RegisterInfo &register_info,
1493 Status &err) {
1494 EntityVector::iterator iter = m_entities.insert(m_entities.end(), EntityUP());
1495 *iter = std::make_unique<EntityRegister>(register_info);
1496 uint32_t ret = AddStructMember(**iter);
1497 (*iter)->SetOffset(ret);
1498 return ret;
1499}
1500
1502 DematerializerSP dematerializer_sp = m_dematerializer_wp.lock();
1503
1504 if (dematerializer_sp)
1505 dematerializer_sp->Wipe();
1506}
1507
1510 lldb::addr_t process_address, Status &error) {
1511 ExecutionContextScope *exe_scope = frame_sp.get();
1512 if (!exe_scope)
1513 exe_scope = map.GetBestExecutionContextScope();
1514
1515 DematerializerSP dematerializer_sp = m_dematerializer_wp.lock();
1516
1517 if (dematerializer_sp) {
1518 error =
1519 Status::FromErrorString("Couldn't materialize: already materialized");
1520 }
1521
1522 DematerializerSP ret(
1523 new Dematerializer(*this, frame_sp, map, process_address));
1524
1525 if (!exe_scope) {
1526 error =
1527 Status::FromErrorString("Couldn't materialize: target doesn't exist");
1528 }
1529
1530 for (EntityUP &entity_up : m_entities) {
1531 entity_up->Materialize(frame_sp, map, process_address, error);
1532
1533 if (!error.Success())
1534 return DematerializerSP();
1535 }
1536
1537 if (Log *log = GetLog(LLDBLog::Expressions)) {
1538 LLDB_LOGF(
1539 log,
1540 "Materializer::Materialize (frame_sp = %p, process_address = 0x%" PRIx64
1541 ") materialized:",
1542 static_cast<void *>(frame_sp.get()), process_address);
1543 for (EntityUP &entity_up : m_entities)
1544 entity_up->DumpToLog(map, process_address, log);
1545 }
1546
1547 m_dematerializer_wp = ret;
1548
1549 return ret;
1550}
1551
1553 lldb::addr_t frame_bottom,
1554 lldb::addr_t frame_top) {
1555 lldb::StackFrameSP frame_sp;
1556
1557 lldb::ThreadSP thread_sp = m_thread_wp.lock();
1558 if (thread_sp)
1559 frame_sp = thread_sp->GetFrameWithStackID(m_stack_id);
1560
1561 ExecutionContextScope *exe_scope = frame_sp.get();
1562 if (!exe_scope)
1563 exe_scope = m_map->GetBestExecutionContextScope();
1564
1565 if (!IsValid()) {
1567 "Couldn't dematerialize: invalid dematerializer");
1568 }
1569
1570 if (!exe_scope) {
1571 error = Status::FromErrorString("Couldn't dematerialize: target is gone");
1572 } else {
1573 if (Log *log = GetLog(LLDBLog::Expressions)) {
1574 LLDB_LOGF(log,
1575 "Materializer::Dematerialize (frame_sp = %p, process_address "
1576 "= 0x%" PRIx64 ") about to dematerialize:",
1577 static_cast<void *>(frame_sp.get()), m_process_address);
1578 for (EntityUP &entity_up : m_materializer->m_entities)
1579 entity_up->DumpToLog(*m_map, m_process_address, log);
1580 }
1581
1582 for (EntityUP &entity_up : m_materializer->m_entities) {
1583 entity_up->Dematerialize(frame_sp, *m_map, m_process_address, frame_top,
1584 frame_bottom, error);
1585
1586 if (!error.Success())
1587 break;
1588 }
1589 }
1590
1591 Wipe();
1592}
1593
1595 if (!IsValid())
1596 return;
1597
1598 for (EntityUP &entity_up : m_materializer->m_entities) {
1599 entity_up->Wipe(*m_map, m_process_address);
1600 }
1601
1602 m_materializer = nullptr;
1603 m_map = nullptr;
1605}
1606
1608 default;
1610 default;
static llvm::raw_ostream & error(Stream &strm)
#define LLDB_LOG(log,...)
The LLDB_LOG* macros defined below are the way to emit log messages.
Definition Log.h:375
#define LLDB_LOGF(log,...)
Definition Log.h:389
static constexpr uint32_t g_default_var_byte_size
static constexpr uint32_t g_default_var_alignment
static llvm::StringRef GetName(XcodeSDK::Type type)
Definition XcodeSDK.cpp:21
Materializer::PersistentVariableDelegate * m_delegate
lldb::ExpressionVariableSP m_persistent_variable_sp
void DestroyAllocation(IRMemoryMap &map, Status &err)
void Materialize(lldb::StackFrameSP &frame_sp, IRMemoryMap &map, lldb::addr_t process_address, Status &err) override
void MakeAllocation(IRMemoryMap &map, Status &err)
void Dematerialize(lldb::StackFrameSP &frame_sp, IRMemoryMap &map, lldb::addr_t process_address, lldb::addr_t frame_top, lldb::addr_t frame_bottom, Status &err) override
void Wipe(IRMemoryMap &map, lldb::addr_t process_address) override
void DumpToLog(IRMemoryMap &map, lldb::addr_t process_address, Log *log) override
EntityPersistentVariable(lldb::ExpressionVariableSP &persistent_variable_sp, Materializer::PersistentVariableDelegate *delegate)
void Materialize(lldb::StackFrameSP &frame_sp, IRMemoryMap &map, lldb::addr_t process_address, Status &err) override
void DumpToLog(IRMemoryMap &map, lldb::addr_t process_address, Log *log) override
void Dematerialize(lldb::StackFrameSP &frame_sp, IRMemoryMap &map, lldb::addr_t process_address, lldb::addr_t frame_top, lldb::addr_t frame_bottom, Status &err) override
RegisterInfo m_register_info
void Wipe(IRMemoryMap &map, lldb::addr_t process_address) override
lldb::DataBufferSP m_register_contents
EntityRegister(const RegisterInfo &register_info)
void Dematerialize(lldb::StackFrameSP &frame_sp, IRMemoryMap &map, lldb::addr_t process_address, lldb::addr_t frame_top, lldb::addr_t frame_bottom, Status &err) override
void DumpToLog(IRMemoryMap &map, lldb::addr_t process_address, Log *log) override
Materializer::PersistentVariableDelegate * m_delegate
bool m_is_program_reference
This is used both to control whether this result entity can (and should) track the value in inferior ...
EntityResultVariable(const CompilerType &type, bool is_program_reference, bool keep_in_memory, Materializer::PersistentVariableDelegate *delegate)
void Materialize(lldb::StackFrameSP &frame_sp, IRMemoryMap &map, lldb::addr_t process_address, Status &err) override
void Wipe(IRMemoryMap &map, lldb::addr_t process_address) override
lldb::addr_t m_temporary_allocation
EntitySymbol(const Symbol &symbol)
void DumpToLog(IRMemoryMap &map, lldb::addr_t process_address, Log *log) override
void Wipe(IRMemoryMap &map, lldb::addr_t process_address) override
void Materialize(lldb::StackFrameSP &frame_sp, IRMemoryMap &map, lldb::addr_t process_address, Status &err) override
void Dematerialize(lldb::StackFrameSP &frame_sp, IRMemoryMap &map, lldb::addr_t process_address, lldb::addr_t frame_top, lldb::addr_t frame_bottom, Status &err) override
ConstString GetName() const override
ValueObjectProviderTy m_valobj_provider
lldb::ValueObjectSP m_valobj_sp
bool LocationExpressionIsValid() const override
Returns 'true' if the location expression associated with this variable is valid.
std::optional< size_t > GetTypeBitAlign(ExecutionContextScope *scope) const override
Returns alignment of the type associated with this variable in bits.
llvm::Expected< uint64_t > GetByteSize(ExecutionContextScope *scope) const override
Returns size in bytes of the type associated with this variable.
lldb::ValueObjectSP SetupValueObject(ExecutionContextScope *scope) override
Creates and returns ValueObject tied to this variable and prepares Entity for materialization.
EntityValueObject(ConstString name, ValueObjectProviderTy provider)
lldb::DataBufferSP m_original_data
size_t m_temporary_allocation_size
lldb::addr_t m_temporary_allocation
void Materialize(lldb::StackFrameSP &frame_sp, IRMemoryMap &map, lldb::addr_t process_address, Status &err) override
virtual ~EntityVariableBase()=default
void Wipe(IRMemoryMap &map, lldb::addr_t process_address) override
void DumpToLog(IRMemoryMap &map, lldb::addr_t process_address, Log *log) override
virtual std::optional< size_t > GetTypeBitAlign(ExecutionContextScope *scope) const =0
Returns alignment of the type associated with this variable in bits.
virtual ConstString GetName() const =0
virtual bool LocationExpressionIsValid() const =0
Returns 'true' if the location expression associated with this variable is valid.
virtual lldb::ValueObjectSP SetupValueObject(ExecutionContextScope *scope)=0
Creates and returns ValueObject tied to this variable and prepares Entity for materialization.
virtual llvm::Expected< uint64_t > GetByteSize(ExecutionContextScope *scope) const =0
Returns size in bytes of the type associated with this variable.
void Dematerialize(lldb::StackFrameSP &frame_sp, IRMemoryMap &map, lldb::addr_t process_address, lldb::addr_t frame_top, lldb::addr_t frame_bottom, Status &err) override
ConstString GetName() const override
std::optional< size_t > GetTypeBitAlign(ExecutionContextScope *scope) const override
Returns alignment of the type associated with this variable in bits.
lldb::ValueObjectSP SetupValueObject(ExecutionContextScope *scope) override
Creates and returns ValueObject tied to this variable and prepares Entity for materialization.
bool LocationExpressionIsValid() const override
Returns 'true' if the location expression associated with this variable is valid.
lldb::VariableSP m_variable_sp
Variable that this entity is based on.
llvm::Expected< uint64_t > GetByteSize(ExecutionContextScope *scope) const override
Returns size in bytes of the type associated with this variable.
EntityVariable(lldb::VariableSP &variable_sp)
A section + offset based address class.
Definition Address.h:62
lldb::addr_t GetLoadAddress(Target *target) const
Get the load address.
Definition Address.cpp:303
lldb::addr_t GetFileAddress() const
Get the file address.
Definition Address.cpp:283
Generic representation of a type in a programming language.
A uniqued constant string class.
Definition ConstString.h:40
A subclass of DataBuffer that stores a data buffer on the heap.
lldb::offset_t GetByteSize() const override
Get the number of bytes in the data buffer.
An data extractor class.
virtual const void * GetData(lldb::offset_t *offset_ptr, lldb::offset_t length) const
Extract length bytes from *offset_ptr.
virtual uint64_t GetByteSize() const
Get the number of bytes contained in this object.
uint64_t GetAddress(lldb::offset_t *offset_ptr) const
Extract an address from *offset_ptr.
const uint8_t * GetDataStart() const
Get the data start pointer.
lldb::ByteOrder GetByteOrder() const
Get the current byte order value.
"lldb/Target/ExecutionContextScope.h" Inherit from this if your object can reconstruct its execution ...
virtual lldb::StackFrameSP CalculateStackFrame()=0
virtual lldb::ProcessSP CalculateProcess()=0
virtual lldb::TargetSP CalculateTarget()=0
@ EVIsLLDBAllocated
This variable is resident in a location specifically allocated for it by LLDB in the target process.
@ EVNeedsFreezeDry
Copy from m_live_sp to m_frozen_sp during dematerialization.
@ EVNeedsAllocation
Space for this variable has yet to be allocated in the target process.
@ EVIsProgramReference
This variable is a reference to a (possibly invalid) area managed by the target program.
@ EVKeepInTarget
Keep the allocation after the expression is complete rather than freeze drying its contents and freei...
Encapsulates memory that may exist in the process but must also be available in the host process.
Definition IRMemoryMap.h:35
void Free(lldb::addr_t process_address, Status &error)
lldb::ByteOrder GetByteOrder()
llvm::Expected< lldb::addr_t > Malloc(size_t size, uint8_t alignment, uint32_t permissions, AllocationPolicy policy, bool zero_memory, AllocationPolicy *used_policy=nullptr)
void ReadPointerFromMemory(lldb::addr_t *address, lldb::addr_t process_address, Status &error)
ExecutionContextScope * GetBestExecutionContextScope() const
void GetMemoryData(DataExtractor &extractor, lldb::addr_t process_address, size_t size, Status &error)
void WritePointerToMemory(lldb::addr_t process_address, lldb::addr_t pointer, Status &error)
void WriteScalarToMemory(lldb::addr_t process_address, Scalar &scalar, size_t size, Status &error)
void Leak(lldb::addr_t process_address, Status &error)
void WriteMemory(lldb::addr_t process_address, const uint8_t *bytes, size_t size, Status &error)
void ReadMemory(uint8_t *bytes, lldb::addr_t process_address, size_t size, Status &error)
@ eAllocationPolicyMirror
The intent is that this allocation exist both in the host and the process and have the same content i...
Definition IRMemoryMap.h:47
void PutString(llvm::StringRef str)
Definition Log.cpp:164
void Dematerialize(Status &err, lldb::addr_t frame_top, lldb::addr_t frame_bottom)
uint32_t AddResultVariable(const CompilerType &type, bool is_lvalue, bool keep_in_memory, PersistentVariableDelegate *delegate, Status &err)
uint32_t AddStructMember(Entity &entity)
std::unique_ptr< Entity > EntityUP
std::shared_ptr< Dematerializer > DematerializerSP
DematerializerSP Materialize(lldb::StackFrameSP &frame_sp, IRMemoryMap &map, lldb::addr_t process_address, Status &err)
uint32_t AddSymbol(const Symbol &symbol_sp, Status &err)
uint32_t AddRegister(const RegisterInfo &register_info, Status &err)
DematerializerWP m_dematerializer_wp
uint32_t AddValueObject(ConstString name, ValueObjectProviderTy valobj_provider, Status &err)
Create entity from supplied ValueObject and count it as a member of the materialized struct.
uint32_t AddPersistentVariable(lldb::ExpressionVariableSP &persistent_variable_sp, PersistentVariableDelegate *delegate, Status &err)
uint32_t AddVariable(lldb::VariableSP &variable_sp, Status &err)
virtual lldb::ExpressionVariableSP CreatePersistentVariable(const lldb::ValueObjectSP &valobj_sp)=0
virtual ConstString GetNextPersistentVariableName(bool is_error=false)=0
Return a new persistent variable name with the specified prefix.
uint32_t GetAsMemoryData(const RegisterInfo &reg_info, void *dst, uint32_t dst_len, lldb::ByteOrder dst_byte_order, Status &error) const
An error handling class.
Definition Status.h:118
void Clear()
Clear the object state.
Definition Status.cpp:214
static Status FromErrorStringWithFormat(const char *format,...) __attribute__((format(printf
Definition Status.cpp:106
static Status FromErrorString(const char *str)
Definition Status.h:141
bool Fail() const
Test for error condition.
Definition Status.cpp:293
const char * AsCString(const char *default_error_str="unknown error") const
Get the error string associated with the current error.
Definition Status.cpp:194
static Status static Status FromErrorStringWithFormatv(const char *format, Args &&...args)
Definition Status.h:151
static Status FromError(llvm::Error error)
Avoid using this in new code. Migrate APIs to llvm::Expected instead.
Definition Status.cpp:136
bool Success() const
Test for success condition.
Definition Status.cpp:303
llvm::StringRef GetString() const
void Format(const char *format, Args &&... args)
Forwards the arguments to llvm::formatv and writes to the stream.
Definition Stream.h:370
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
Definition Stream.cpp:134
size_t PutCString(llvm::StringRef cstr)
Output a C string to the stream.
Definition Stream.cpp:63
size_t PutChar(char ch)
Definition Stream.cpp:131
static lldb::ValueObjectSP Create(ExecutionContextScope *exe_scope, lldb::ByteOrder byte_order, uint32_t addr_byte_size, lldb::addr_t address=LLDB_INVALID_ADDRESS, ValueObjectManager *manager=nullptr)
These routines create ValueObjectConstResult ValueObjects from various data sources.
static lldb::ValueObjectSP Create(ExecutionContextScope *exe_scope, const lldb::VariableSP &var_sp)
uint8_t * GetBytes()
Get a pointer to the data.
Definition DataBuffer.h:108
#define LLDB_INVALID_ADDRESS
A class that represents a running process on the host machine.
Log * GetLog(Cat mask)
Retrieve the Log object for the channel associated with the given log enum.
Definition Log.h:338
std::function< lldb::ValueObjectSP(ConstString, StackFrame *)> ValueObjectProviderTy
Functor that returns a ValueObjectSP for a variable given its name and the StackFrame of interest.
void DumpHexBytes(Stream *s, const void *src, size_t src_len, uint32_t bytes_per_line, lldb::addr_t base_addr)
@ eAddressTypeLoad
Address is an address as in the current target inferior process.
std::string toString(FormatterBytecode::OpCodes op)
std::shared_ptr< lldb_private::StackFrame > StackFrameSP
std::shared_ptr< lldb_private::Thread > ThreadSP
std::shared_ptr< lldb_private::ValueObject > ValueObjectSP
std::shared_ptr< lldb_private::ExpressionVariable > ExpressionVariableSP
uint64_t offset_t
Definition lldb-types.h:86
std::shared_ptr< lldb_private::Process > ProcessSP
std::shared_ptr< lldb_private::Variable > VariableSP
std::shared_ptr< lldb_private::DataBuffer > DataBufferSP
uint64_t addr_t
Definition lldb-types.h:80
std::shared_ptr< lldb_private::Target > TargetSP
std::shared_ptr< lldb_private::RegisterContext > RegisterContextSP
Every register is described in detail including its name, alternate name (optional),...