blob: fedbc249735187779aad1bc0792825432e49f29f [file] [log] [blame]
Sean Callanan5a1af4e2013-04-05 02:22:57 +00001//===-- IRMemoryMap.cpp -----------------------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
Sean Callanan35005f72013-04-12 18:10:34 +000010#include "lldb/Core/DataBufferHeap.h"
11#include "lldb/Core/DataExtractor.h"
Sean Callanan5a1af4e2013-04-05 02:22:57 +000012#include "lldb/Core/Error.h"
13#include "lldb/Core/Log.h"
Sean Callanan35005f72013-04-12 18:10:34 +000014#include "lldb/Core/Scalar.h"
Sean Callanan5a1af4e2013-04-05 02:22:57 +000015#include "lldb/Expression/IRMemoryMap.h"
16#include "lldb/Target/Process.h"
Sean Callanan35005f72013-04-12 18:10:34 +000017#include "lldb/Target/Target.h"
Sean Callanan5a1af4e2013-04-05 02:22:57 +000018
19using namespace lldb_private;
20
Sean Callanan35005f72013-04-12 18:10:34 +000021IRMemoryMap::IRMemoryMap (lldb::TargetSP target_sp) :
Sean Callanan35005f72013-04-12 18:10:34 +000022 m_target_wp(target_sp)
Sean Callanan5a1af4e2013-04-05 02:22:57 +000023{
Sean Callananb024d872013-04-15 17:12:47 +000024 if (target_sp)
25 m_process_wp = target_sp->GetProcessSP();
Sean Callanan5a1af4e2013-04-05 02:22:57 +000026}
27
28IRMemoryMap::~IRMemoryMap ()
29{
30 lldb::ProcessSP process_sp = m_process_wp.lock();
31
32 if (process_sp)
33 {
34 for (AllocationMap::value_type &allocation : m_allocations)
35 {
36 if (allocation.second.m_policy == eAllocationPolicyMirror ||
37 allocation.second.m_policy == eAllocationPolicyHostOnly)
38 process_sp->DeallocateMemory(allocation.second.m_process_alloc);
39
40 if (lldb_private::Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS))
41 {
42 log->Printf("IRMemoryMap::~IRMemoryMap deallocated [0x%llx..0x%llx)",
43 (uint64_t)allocation.second.m_process_start,
44 (uint64_t)allocation.second.m_process_start + (uint64_t)allocation.second.m_size);
45 }
46 }
47 }
48}
49
50lldb::addr_t
51IRMemoryMap::FindSpace (size_t size)
52{
53 // Yup, this is just plain O(n) insertion. We'll use a range tree if we
54 // start caring.
55
56 lldb::addr_t remote_address = 0x1000; // skip first page of memory
57
58 for (AllocationMap::value_type &allocation : m_allocations)
59 {
60 if (remote_address < allocation.second.m_process_start &&
61 remote_address + size <= allocation.second.m_process_start)
62 return remote_address;
63
Sean Callanan08052af2013-04-17 07:50:58 +000064 remote_address = allocation.second.m_process_start + allocation.second.m_size;
Sean Callanan5a1af4e2013-04-05 02:22:57 +000065 }
66
67 if (remote_address + size < remote_address)
68 return LLDB_INVALID_ADDRESS; // massively unlikely
69
70 return remote_address;
71}
72
73bool
74IRMemoryMap::ContainsHostOnlyAllocations ()
75{
76 for (AllocationMap::value_type &allocation : m_allocations)
77 {
78 if (allocation.second.m_policy == eAllocationPolicyHostOnly)
79 return true;
80 }
81
82 return false;
83}
84
85IRMemoryMap::AllocationMap::iterator
86IRMemoryMap::FindAllocation (lldb::addr_t addr, size_t size)
87{
88 AllocationMap::iterator iter = m_allocations.lower_bound (addr);
89
Sean Callanan14b1bae2013-04-16 23:25:35 +000090 if (iter == m_allocations.end() ||
91 iter->first > addr)
Sean Callanan5a1af4e2013-04-05 02:22:57 +000092 {
93 if (iter == m_allocations.begin())
94 return m_allocations.end();
95 iter--;
96 }
97
98 if (iter->first <= addr && iter->first + iter->second.m_size >= addr + size)
99 return iter;
100
101 return m_allocations.end();
102}
103
Sean Callanan35005f72013-04-12 18:10:34 +0000104lldb::ByteOrder
105IRMemoryMap::GetByteOrder()
106{
107 lldb::ProcessSP process_sp = m_process_wp.lock();
108
109 if (process_sp)
110 return process_sp->GetByteOrder();
111
112 lldb::TargetSP target_sp = m_target_wp.lock();
113
114 if (target_sp)
Sean Callanan08052af2013-04-17 07:50:58 +0000115 return target_sp->GetArchitecture().GetByteOrder();
Sean Callanan35005f72013-04-12 18:10:34 +0000116
117 return lldb::eByteOrderInvalid;
118}
119
120uint32_t
121IRMemoryMap::GetAddressByteSize()
122{
123 lldb::ProcessSP process_sp = m_process_wp.lock();
124
125 if (process_sp)
126 return process_sp->GetAddressByteSize();
127
128 lldb::TargetSP target_sp = m_target_wp.lock();
129
130 if (target_sp)
Sean Callanan08052af2013-04-17 07:50:58 +0000131 return target_sp->GetArchitecture().GetAddressByteSize();
Sean Callanan35005f72013-04-12 18:10:34 +0000132
133 return UINT32_MAX;
134}
135
136ExecutionContextScope *
137IRMemoryMap::GetBestExecutionContextScope()
138{
139 lldb::ProcessSP process_sp = m_process_wp.lock();
140
141 if (process_sp)
142 return process_sp.get();
143
144 lldb::TargetSP target_sp = m_target_wp.lock();
145
146 if (target_sp)
147 return target_sp.get();
148
149 return NULL;
150}
151
Sean Callanan5a1af4e2013-04-05 02:22:57 +0000152lldb::addr_t
153IRMemoryMap::Malloc (size_t size, uint8_t alignment, uint32_t permissions, AllocationPolicy policy, Error &error)
154{
Sean Callanan08052af2013-04-17 07:50:58 +0000155 error.Clear();
156
Sean Callanan5a1af4e2013-04-05 02:22:57 +0000157 lldb::ProcessSP process_sp;
158 lldb::addr_t allocation_address = LLDB_INVALID_ADDRESS;
159 lldb::addr_t aligned_address = LLDB_INVALID_ADDRESS;
160
161 size_t allocation_size = (size ? size : 1) + alignment - 1;
162
163 switch (policy)
164 {
165 default:
166 error.SetErrorToGenericError();
167 error.SetErrorString("Couldn't malloc: invalid allocation policy");
168 return LLDB_INVALID_ADDRESS;
169 case eAllocationPolicyHostOnly:
170 allocation_address = FindSpace(allocation_size);
171 if (allocation_address == LLDB_INVALID_ADDRESS)
172 {
173 error.SetErrorToGenericError();
174 error.SetErrorString("Couldn't malloc: address space is full");
175 return LLDB_INVALID_ADDRESS;
176 }
177 break;
178 case eAllocationPolicyMirror:
179 if (ContainsHostOnlyAllocations())
180 {
181 error.SetErrorToGenericError();
182 error.SetErrorString("Couldn't malloc: host-only allocations are polluting the address space");
183 return LLDB_INVALID_ADDRESS;
184 }
185 process_sp = m_process_wp.lock();
186 if (process_sp)
187 {
188 allocation_address = process_sp->AllocateMemory(allocation_size, permissions, error);
189 if (!error.Success())
190 return LLDB_INVALID_ADDRESS;
191 }
192 else
193 {
194 allocation_address = FindSpace(allocation_size);
195 if (allocation_address == LLDB_INVALID_ADDRESS)
196 {
197 error.SetErrorToGenericError();
198 error.SetErrorString("Couldn't malloc: address space is full");
199 return LLDB_INVALID_ADDRESS;
200 }
201 }
202 break;
203 case eAllocationPolicyProcessOnly:
204 if (ContainsHostOnlyAllocations())
205 {
206 error.SetErrorToGenericError();
207 error.SetErrorString("Couldn't malloc: host-only allocations are polluting the address space");
208 return LLDB_INVALID_ADDRESS;
209 }
210 process_sp = m_process_wp.lock();
211 if (process_sp)
212 {
213 allocation_address = process_sp->AllocateMemory(allocation_size, permissions, error);
214 if (!error.Success())
215 return LLDB_INVALID_ADDRESS;
216 }
217 else
218 {
219 error.SetErrorToGenericError();
220 error.SetErrorString("Couldn't malloc: process doesn't exist, and this memory must be in the process");
221 return LLDB_INVALID_ADDRESS;
222 }
223 break;
224 }
225
226
227 lldb::addr_t mask = alignment - 1;
228 aligned_address = (allocation_address + mask) & (~mask);
229
230 Allocation &allocation(m_allocations[aligned_address]);
231
232 allocation.m_process_alloc = allocation_address;
233 allocation.m_process_start = aligned_address;
234 allocation.m_size = size;
235 allocation.m_permissions = permissions;
236 allocation.m_alignment = alignment;
237 allocation.m_policy = policy;
238
239 switch (policy)
240 {
241 default:
242 assert (0 && "We cannot reach this!");
243 case eAllocationPolicyHostOnly:
Greg Claytone0c64e12013-04-18 22:01:06 +0000244 allocation.m_data_ap.reset(new DataBufferHeap(size, 0));
Sean Callanan5a1af4e2013-04-05 02:22:57 +0000245 break;
246 case eAllocationPolicyProcessOnly:
247 break;
248 case eAllocationPolicyMirror:
Greg Claytone0c64e12013-04-18 22:01:06 +0000249 allocation.m_data_ap.reset(new DataBufferHeap(size, 0));
Sean Callanan5a1af4e2013-04-05 02:22:57 +0000250 break;
251 }
252
253 if (lldb_private::Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS))
254 {
255 const char * policy_string;
256
257 switch (policy)
258 {
259 default:
260 policy_string = "<invalid policy>";
261 break;
262 case eAllocationPolicyHostOnly:
263 policy_string = "eAllocationPolicyHostOnly";
264 break;
265 case eAllocationPolicyProcessOnly:
266 policy_string = "eAllocationPolicyProcessOnly";
267 break;
268 case eAllocationPolicyMirror:
269 policy_string = "eAllocationPolicyMirror";
270 break;
271 }
272
273 log->Printf("IRMemoryMap::Malloc (%llu, 0x%llx, 0x%llx, %s) -> 0x%llx",
274 (uint64_t)size,
275 (uint64_t)alignment,
276 (uint64_t)permissions,
277 policy_string,
278 aligned_address);
279 }
280
281 return aligned_address;
282}
283
284void
285IRMemoryMap::Free (lldb::addr_t process_address, Error &error)
286{
Sean Callanan08052af2013-04-17 07:50:58 +0000287 error.Clear();
288
Sean Callanan5a1af4e2013-04-05 02:22:57 +0000289 AllocationMap::iterator iter = m_allocations.find(process_address);
290
291 if (iter == m_allocations.end())
292 {
293 error.SetErrorToGenericError();
294 error.SetErrorString("Couldn't free: allocation doesn't exist");
295 return;
296 }
297
298 Allocation &allocation = iter->second;
299
300 switch (allocation.m_policy)
301 {
302 default:
303 case eAllocationPolicyHostOnly:
304 break;
305 case eAllocationPolicyMirror:
306 case eAllocationPolicyProcessOnly:
307 lldb::ProcessSP process_sp = m_process_wp.lock();
308 if (process_sp)
309 process_sp->DeallocateMemory(allocation.m_process_alloc);
310 }
311
312 if (lldb_private::Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS))
313 {
314 log->Printf("IRMemoryMap::Free (0x%llx) freed [0x%llx..0x%llx)",
315 (uint64_t)process_address,
316 iter->second.m_process_start,
317 iter->second.m_process_start + iter->second.m_size);
318 }
319
320 m_allocations.erase(iter);
321}
322
323void
324IRMemoryMap::WriteMemory (lldb::addr_t process_address, const uint8_t *bytes, size_t size, Error &error)
325{
Sean Callanan08052af2013-04-17 07:50:58 +0000326 error.Clear();
327
Sean Callanan5a1af4e2013-04-05 02:22:57 +0000328 AllocationMap::iterator iter = FindAllocation(process_address, size);
329
330 if (iter == m_allocations.end())
331 {
Sean Callananc8c5b8d2013-04-15 21:35:52 +0000332 lldb::ProcessSP process_sp = m_process_wp.lock();
333
334 if (process_sp)
335 {
336 process_sp->WriteMemory(process_address, bytes, size, error);
337 return;
338 }
339
Sean Callanan5a1af4e2013-04-05 02:22:57 +0000340 error.SetErrorToGenericError();
Sean Callananc8c5b8d2013-04-15 21:35:52 +0000341 error.SetErrorString("Couldn't write: no allocation contains the target range and the process doesn't exist");
Sean Callanan5a1af4e2013-04-05 02:22:57 +0000342 return;
343 }
344
345 Allocation &allocation = iter->second;
346
347 uint64_t offset = process_address - allocation.m_process_start;
348
349 lldb::ProcessSP process_sp;
350
351 switch (allocation.m_policy)
352 {
353 default:
354 error.SetErrorToGenericError();
355 error.SetErrorString("Couldn't write: invalid allocation policy");
356 return;
357 case eAllocationPolicyHostOnly:
Greg Claytone0c64e12013-04-18 22:01:06 +0000358 if (!allocation.m_data_ap.get())
Sean Callanan5a1af4e2013-04-05 02:22:57 +0000359 {
360 error.SetErrorToGenericError();
361 error.SetErrorString("Couldn't write: data buffer is empty");
362 return;
363 }
Greg Claytone0c64e12013-04-18 22:01:06 +0000364 ::memcpy (allocation.m_data_ap->GetBytes() + offset, bytes, size);
Sean Callanan5a1af4e2013-04-05 02:22:57 +0000365 break;
366 case eAllocationPolicyMirror:
Greg Claytone0c64e12013-04-18 22:01:06 +0000367 if (!allocation.m_data_ap.get())
Sean Callanan5a1af4e2013-04-05 02:22:57 +0000368 {
369 error.SetErrorToGenericError();
370 error.SetErrorString("Couldn't write: data buffer is empty");
371 return;
372 }
Greg Claytone0c64e12013-04-18 22:01:06 +0000373 ::memcpy (allocation.m_data_ap->GetBytes() + offset, bytes, size);
Sean Callanan5a1af4e2013-04-05 02:22:57 +0000374 process_sp = m_process_wp.lock();
375 if (process_sp)
376 {
377 process_sp->WriteMemory(process_address, bytes, size, error);
378 if (!error.Success())
379 return;
380 }
381 break;
382 case eAllocationPolicyProcessOnly:
383 process_sp = m_process_wp.lock();
384 if (process_sp)
385 {
386 process_sp->WriteMemory(process_address, bytes, size, error);
387 if (!error.Success())
388 return;
389 }
390 break;
391 }
392
393 if (lldb_private::Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS))
394 {
395 log->Printf("IRMemoryMap::WriteMemory (0x%llx, 0x%llx, 0x%lld) went to [0x%llx..0x%llx)",
396 (uint64_t)process_address,
397 (uint64_t)bytes,
398 (uint64_t)size,
399 (uint64_t)allocation.m_process_start,
400 (uint64_t)allocation.m_process_start + (uint64_t)allocation.m_size);
401 }
402}
403
404void
Sean Callanan35005f72013-04-12 18:10:34 +0000405IRMemoryMap::WriteScalarToMemory (lldb::addr_t process_address, Scalar &scalar, size_t size, Error &error)
Sean Callanan08052af2013-04-17 07:50:58 +0000406{
407 error.Clear();
408
Sean Callanan35005f72013-04-12 18:10:34 +0000409 if (size == UINT32_MAX)
410 size = scalar.GetByteSize();
411
412 if (size > 0)
413 {
414 uint8_t buf[32];
415 const size_t mem_size = scalar.GetAsMemoryData (buf, size, GetByteOrder(), error);
416 if (mem_size > 0)
417 {
418 return WriteMemory(process_address, buf, mem_size, error);
419 }
420 else
421 {
422 error.SetErrorToGenericError();
423 error.SetErrorString ("Couldn't write scalar: failed to get scalar as memory data");
424 }
425 }
426 else
427 {
428 error.SetErrorToGenericError();
429 error.SetErrorString ("Couldn't write scalar: its size was zero");
430 }
431 return;
432}
433
434void
Sean Callananf8043fa2013-04-12 21:40:34 +0000435IRMemoryMap::WritePointerToMemory (lldb::addr_t process_address, lldb::addr_t address, Error &error)
436{
Sean Callanan08052af2013-04-17 07:50:58 +0000437 error.Clear();
438
Sean Callananf8043fa2013-04-12 21:40:34 +0000439 Scalar scalar(address);
440
441 WriteScalarToMemory(process_address, scalar, GetAddressByteSize(), error);
442}
443
Sean Callananf8043fa2013-04-12 21:40:34 +0000444void
Sean Callanan5a1af4e2013-04-05 02:22:57 +0000445IRMemoryMap::ReadMemory (uint8_t *bytes, lldb::addr_t process_address, size_t size, Error &error)
446{
Sean Callanan08052af2013-04-17 07:50:58 +0000447 error.Clear();
448
Sean Callanan5a1af4e2013-04-05 02:22:57 +0000449 AllocationMap::iterator iter = FindAllocation(process_address, size);
450
451 if (iter == m_allocations.end())
452 {
Sean Callananc8c5b8d2013-04-15 21:35:52 +0000453 lldb::ProcessSP process_sp = m_process_wp.lock();
454
455 if (process_sp)
456 {
457 process_sp->ReadMemory(process_address, bytes, size, error);
458 return;
459 }
460
461 lldb::TargetSP target_sp = m_target_wp.lock();
462
463 if (target_sp)
464 {
465 Address absolute_address(process_address);
466 target_sp->ReadMemory(absolute_address, false, bytes, size, error);
467 return;
468 }
469
Sean Callanan5a1af4e2013-04-05 02:22:57 +0000470 error.SetErrorToGenericError();
Sean Callananc8c5b8d2013-04-15 21:35:52 +0000471 error.SetErrorString("Couldn't read: no allocation contains the target range, and neither the process nor the target exist");
Sean Callanan5a1af4e2013-04-05 02:22:57 +0000472 return;
473 }
474
475 Allocation &allocation = iter->second;
476
477 uint64_t offset = process_address - allocation.m_process_start;
478
479 lldb::ProcessSP process_sp;
480
481 switch (allocation.m_policy)
482 {
483 default:
484 error.SetErrorToGenericError();
485 error.SetErrorString("Couldn't read: invalid allocation policy");
486 return;
487 case eAllocationPolicyHostOnly:
Greg Claytone0c64e12013-04-18 22:01:06 +0000488 if (!allocation.m_data_ap.get())
Sean Callanan5a1af4e2013-04-05 02:22:57 +0000489 {
490 error.SetErrorToGenericError();
491 error.SetErrorString("Couldn't read: data buffer is empty");
492 return;
493 }
Greg Claytone0c64e12013-04-18 22:01:06 +0000494 ::memcpy (bytes, allocation.m_data_ap->GetBytes() + offset, size);
Sean Callanan5a1af4e2013-04-05 02:22:57 +0000495 break;
496 case eAllocationPolicyMirror:
497 process_sp = m_process_wp.lock();
498 if (process_sp)
499 {
500 process_sp->ReadMemory(process_address, bytes, size, error);
501 if (!error.Success())
502 return;
503 }
504 else
505 {
Greg Claytone0c64e12013-04-18 22:01:06 +0000506 if (!allocation.m_data_ap.get())
Sean Callanan5a1af4e2013-04-05 02:22:57 +0000507 {
508 error.SetErrorToGenericError();
509 error.SetErrorString("Couldn't read: data buffer is empty");
510 return;
511 }
Greg Claytone0c64e12013-04-18 22:01:06 +0000512 ::memcpy (bytes, allocation.m_data_ap->GetBytes() + offset, size);
Sean Callanan5a1af4e2013-04-05 02:22:57 +0000513 }
514 break;
515 case eAllocationPolicyProcessOnly:
516 process_sp = m_process_wp.lock();
517 if (process_sp)
518 {
519 process_sp->ReadMemory(process_address, bytes, size, error);
520 if (!error.Success())
521 return;
522 }
523 break;
524 }
525
526 if (lldb_private::Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS))
527 {
528 log->Printf("IRMemoryMap::ReadMemory (0x%llx, 0x%llx, 0x%lld) came from [0x%llx..0x%llx)",
529 (uint64_t)process_address,
530 (uint64_t)bytes,
531 (uint64_t)size,
532 (uint64_t)allocation.m_process_start,
533 (uint64_t)allocation.m_process_start + (uint64_t)allocation.m_size);
534 }
535}
Sean Callanan35005f72013-04-12 18:10:34 +0000536
537void
538IRMemoryMap::ReadScalarFromMemory (Scalar &scalar, lldb::addr_t process_address, size_t size, Error &error)
Sean Callanan08052af2013-04-17 07:50:58 +0000539{
540 error.Clear();
541
Sean Callanan35005f72013-04-12 18:10:34 +0000542 if (size > 0)
543 {
544 DataBufferHeap buf(size, 0);
545 ReadMemory(buf.GetBytes(), process_address, size, error);
546
547 if (!error.Success())
548 return;
549
550 DataExtractor extractor(buf.GetBytes(), buf.GetByteSize(), GetByteOrder(), GetAddressByteSize());
551
552 lldb::offset_t offset = 0;
553
554 switch (size)
555 {
556 default:
557 error.SetErrorToGenericError();
558 error.SetErrorStringWithFormat("Couldn't read scalar: unsupported size %lld", (unsigned long long)size);
559 return;
560 case 1: scalar = extractor.GetU8(&offset); break;
561 case 2: scalar = extractor.GetU16(&offset); break;
562 case 4: scalar = extractor.GetU32(&offset); break;
563 case 8: scalar = extractor.GetU64(&offset); break;
564 }
565 }
566 else
567 {
568 error.SetErrorToGenericError();
Sean Callanan458ae1c2013-04-13 02:06:42 +0000569 error.SetErrorString ("Couldn't read scalar: its size was zero");
Sean Callanan35005f72013-04-12 18:10:34 +0000570 }
571 return;
572}
573
Sean Callanan458ae1c2013-04-13 02:06:42 +0000574void
Sean Callanan2d37e5a2013-04-15 22:48:23 +0000575IRMemoryMap::ReadPointerFromMemory (lldb::addr_t *address, lldb::addr_t process_address, Error &error)
576{
Sean Callanan08052af2013-04-17 07:50:58 +0000577 error.Clear();
578
Sean Callanan2d37e5a2013-04-15 22:48:23 +0000579 Scalar pointer_scalar;
580 ReadScalarFromMemory(pointer_scalar, process_address, GetAddressByteSize(), error);
581
582 if (!error.Success())
583 return;
584
585 *address = pointer_scalar.ULongLong();
586
587 return;
588}
589
590void
Sean Callanan458ae1c2013-04-13 02:06:42 +0000591IRMemoryMap::GetMemoryData (DataExtractor &extractor, lldb::addr_t process_address, size_t size, Error &error)
592{
Sean Callanan08052af2013-04-17 07:50:58 +0000593 error.Clear();
594
Sean Callanan458ae1c2013-04-13 02:06:42 +0000595 if (size > 0)
596 {
597 AllocationMap::iterator iter = FindAllocation(process_address, size);
598
599 if (iter == m_allocations.end())
600 {
601 error.SetErrorToGenericError();
602 error.SetErrorStringWithFormat("Couldn't find an allocation containing [0x%llx..0x%llx)", (unsigned long long)process_address, (unsigned long long)(process_address + size));
603 return;
604 }
605
606 Allocation &allocation = iter->second;
607
608 switch (allocation.m_policy)
609 {
610 default:
611 error.SetErrorToGenericError();
612 error.SetErrorString("Couldn't get memory data: invalid allocation policy");
613 return;
614 case eAllocationPolicyProcessOnly:
615 error.SetErrorToGenericError();
616 error.SetErrorString("Couldn't get memory data: memory is only in the target");
617 return;
Sean Callanan458ae1c2013-04-13 02:06:42 +0000618 case eAllocationPolicyMirror:
Sean Callananc8c5b8d2013-04-15 21:35:52 +0000619 {
620 lldb::ProcessSP process_sp = m_process_wp.lock();
621
Greg Claytone0c64e12013-04-18 22:01:06 +0000622 if (!allocation.m_data_ap.get())
Sean Callananc8c5b8d2013-04-15 21:35:52 +0000623 {
624 error.SetErrorToGenericError();
625 error.SetErrorString("Couldn't get memory data: data buffer is empty");
626 return;
627 }
628 if (process_sp)
629 {
Greg Claytone0c64e12013-04-18 22:01:06 +0000630 process_sp->ReadMemory(allocation.m_process_start, allocation.m_data_ap->GetBytes(), allocation.m_data_ap->GetByteSize(), error);
Sean Callananc8c5b8d2013-04-15 21:35:52 +0000631 if (!error.Success())
632 return;
633 uint64_t offset = process_address - allocation.m_process_start;
Greg Claytone0c64e12013-04-18 22:01:06 +0000634 extractor = DataExtractor(allocation.m_data_ap->GetBytes() + offset, size, GetByteOrder(), GetAddressByteSize());
Sean Callananc8c5b8d2013-04-15 21:35:52 +0000635 return;
636 }
637 }
638 case eAllocationPolicyHostOnly:
Greg Claytone0c64e12013-04-18 22:01:06 +0000639 if (!allocation.m_data_ap.get())
Sean Callanan458ae1c2013-04-13 02:06:42 +0000640 {
641 error.SetErrorToGenericError();
642 error.SetErrorString("Couldn't get memory data: data buffer is empty");
643 return;
644 }
645 uint64_t offset = process_address - allocation.m_process_start;
Greg Claytone0c64e12013-04-18 22:01:06 +0000646 extractor = DataExtractor(allocation.m_data_ap->GetBytes() + offset, size, GetByteOrder(), GetAddressByteSize());
Sean Callanan458ae1c2013-04-13 02:06:42 +0000647 return;
648 }
649 }
650 else
651 {
652 error.SetErrorToGenericError();
653 error.SetErrorString ("Couldn't get memory data: its size was zero");
654 return;
655 }
656}
657
658