1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
|
//===-- SBTarget.cpp --------------------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "lldb/API/SBTarget.h"
#include "lldb/lldb-include.h"
#include "lldb/API/SBFileSpec.h"
#include "lldb/API/SBModule.h"
#include "lldb/API/SBStream.h"
#include "lldb/Breakpoint/BreakpointID.h"
#include "lldb/Breakpoint/BreakpointIDList.h"
#include "lldb/Breakpoint/BreakpointList.h"
#include "lldb/Breakpoint/BreakpointLocation.h"
#include "lldb/Core/Address.h"
#include "lldb/Core/AddressResolver.h"
#include "lldb/Core/AddressResolverName.h"
#include "lldb/Interpreter/Args.h"
#include "lldb/Core/ArchSpec.h"
#include "lldb/Core/Debugger.h"
#include "lldb/Core/Disassembler.h"
#include "lldb/Core/FileSpec.h"
#include "lldb/Core/Log.h"
#include "lldb/Core/RegularExpression.h"
#include "lldb/Core/SearchFilter.h"
#include "lldb/Core/STLUtils.h"
#include "lldb/Target/Process.h"
#include "lldb/Target/Target.h"
#include "lldb/Target/TargetList.h"
#include "lldb/Interpreter/CommandReturnObject.h"
#include "../source/Commands/CommandObjectBreakpoint.h"
#include "lldb/API/SBDebugger.h"
#include "lldb/API/SBProcess.h"
#include "lldb/API/SBListener.h"
#include "lldb/API/SBBreakpoint.h"
using namespace lldb;
using namespace lldb_private;
#define DEFAULT_DISASM_BYTE_SIZE 32
//----------------------------------------------------------------------
// SBTarget constructor
//----------------------------------------------------------------------
SBTarget::SBTarget ()
{
}
SBTarget::SBTarget (const SBTarget& rhs) :
m_opaque_sp (rhs.m_opaque_sp)
{
Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
if (log)
{
SBStream sstr;
GetDescription (sstr, lldb::eDescriptionLevelBrief);
log->Printf ("SBTarget::SBTarget (rhs.sp=%p) => SBTarget(%p): %s",
rhs.m_opaque_sp.get(), m_opaque_sp.get(), sstr.GetData());
}
}
SBTarget::SBTarget(const TargetSP& target_sp) :
m_opaque_sp (target_sp)
{
Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
if (log)
{
SBStream sstr;
GetDescription (sstr, lldb::eDescriptionLevelBrief);
log->Printf ("SBTarget::SBTarget (target_sp=%p) => SBTarget(%p): '%s'",
target_sp.get(), m_opaque_sp.get(), sstr.GetData());
}
}
const SBTarget&
SBTarget::Assign (const SBTarget& rhs)
{
Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
if (log)
log->Printf ("SBTarget(%p)::Assign (rhs.sp=%p)", m_opaque_sp.get(), rhs.m_opaque_sp.get());
if (this != &rhs)
{
m_opaque_sp = rhs.m_opaque_sp;
}
return *this;
}
//----------------------------------------------------------------------
// Destructor
//----------------------------------------------------------------------
SBTarget::~SBTarget()
{
}
bool
SBTarget::IsValid () const
{
return m_opaque_sp.get() != NULL;
}
SBProcess
SBTarget::GetProcess ()
{
Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
SBProcess sb_process;
if (m_opaque_sp)
sb_process.SetProcess (m_opaque_sp->GetProcessSP());
if (log)
{
SBStream sstr;
sb_process.GetDescription (sstr);
log->Printf ("SBTarget(%p)::GetProcess () => SBProcess(%p): %s", m_opaque_sp.get(),
sb_process.get(), sstr.GetData());
}
return sb_process;
}
SBDebugger
SBTarget::GetDebugger () const
{
SBDebugger debugger;
if (m_opaque_sp)
debugger.reset (m_opaque_sp->GetDebugger().GetSP());
return debugger;
}
// DEPRECATED
SBProcess
SBTarget::CreateProcess ()
{
Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
SBProcess sb_process;
if (m_opaque_sp)
sb_process.SetProcess (m_opaque_sp->CreateProcess (m_opaque_sp->GetDebugger().GetListener()));
if (log)
{
SBStream sstr;
sb_process.GetDescription (sstr);
log->Printf ("SBTarget(%p)::CreateProcess () => SBProcess(%p): %s", m_opaque_sp.get(),
sb_process.get(), sstr.GetData());
}
return sb_process;
}
SBProcess
SBTarget::LaunchProcess
(
char const **argv,
char const **envp,
const char *tty,
uint32_t launch_flags,
bool stop_at_entry
)
{
Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
if (log)
log->Printf ("SBTarget(%p)::LaunchProcess (argv=%p, envp=%p, tty='%s', launch_flags=%d, stop_at_entry=%i)",
m_opaque_sp.get(), argv, envp, tty, launch_flags, stop_at_entry);
SBError sb_error;
SBProcess sb_process = Launch (argv, envp, tty, launch_flags, stop_at_entry, sb_error);
if (log)
{
SBStream sstr;
sb_process.GetDescription (sstr);
log->Printf ("SBTarget(%p)::LaunchProcess (...) => SBProcess(%p): %s",
m_opaque_sp.get(), sb_process.get(), sstr.GetData());
}
return sb_process;
}
SBProcess
SBTarget::Launch
(
char const **argv,
char const **envp,
const char *tty,
uint32_t launch_flags,
bool stop_at_entry,
SBError &error
)
{
Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
if (log)
{
log->Printf ("SBTarget(%p)::Launch (argv=%p, envp=%p, tty='%s', launch_flags=%d, stop_at_entry=%i, &error (%p))...",
m_opaque_sp.get(), argv, envp, tty, launch_flags, stop_at_entry, error.get());
}
SBProcess sb_process;
if (m_opaque_sp)
{
// DEPRECATED, this will change when CreateProcess is removed...
if (m_opaque_sp->GetProcessSP())
{
sb_process.SetProcess(m_opaque_sp->GetProcessSP());
}
else
{
// When launching, we always want to create a new process When
// SBTarget::CreateProcess is removed, this will always happen.
sb_process.SetProcess (m_opaque_sp->CreateProcess (m_opaque_sp->GetDebugger().GetListener()));
}
if (sb_process.IsValid())
{
error.SetError (sb_process->Launch (argv, envp, launch_flags, tty, tty, tty));
if (error.Success())
{
// We we are stopping at the entry point, we can return now!
if (stop_at_entry)
return sb_process;
// Make sure we are stopped at the entry
StateType state = sb_process->WaitForProcessToStop (NULL);
if (state == eStateStopped)
{
// resume the process to skip the entry point
error.SetError (sb_process->Resume());
if (error.Success())
{
// If we are doing synchronous mode, then wait for the
// process to stop yet again!
if (m_opaque_sp->GetDebugger().GetAsyncExecution () == false)
sb_process->WaitForProcessToStop (NULL);
}
}
}
}
else
{
error.SetErrorString ("unable to create lldb_private::Process");
}
}
else
{
error.SetErrorString ("SBTarget is invalid");
}
if (log)
{
SBStream sstr;
sb_process.GetDescription (sstr);
log->Printf ("SBTarget(%p)::Launch (...) => SBProceess(%p): %s",
m_opaque_sp.get(), sb_process.get(), sstr.GetData());
}
return sb_process;
}
lldb::SBProcess
SBTarget::AttachToProcessWithID
(
lldb::pid_t pid,// The process ID to attach to
SBError& error // An error explaining what went wrong if attach fails
)
{
SBProcess sb_process;
if (m_opaque_sp)
{
// DEPRECATED, this will change when CreateProcess is removed...
if (m_opaque_sp->GetProcessSP())
{
sb_process.SetProcess(m_opaque_sp->GetProcessSP());
}
else
{
// When launching, we always want to create a new process When
// SBTarget::CreateProcess is removed, this will always happen.
sb_process.SetProcess (m_opaque_sp->CreateProcess (m_opaque_sp->GetDebugger().GetListener()));
}
if (sb_process.IsValid())
{
error.SetError (sb_process->Attach (pid));
}
else
{
error.SetErrorString ("unable to create lldb_private::Process");
}
}
else
{
error.SetErrorString ("SBTarget is invalid");
}
return sb_process;
}
lldb::SBProcess
SBTarget::AttachToProcessWithName
(
const char *name, // basename of process to attach to
bool wait_for, // if true wait for a new instance of "name" to be launched
SBError& error // An error explaining what went wrong if attach fails
)
{
SBProcess sb_process;
if (m_opaque_sp)
{
// DEPRECATED, this will change when CreateProcess is removed...
if (m_opaque_sp->GetProcessSP())
{
sb_process.SetProcess(m_opaque_sp->GetProcessSP());
}
else
{
// When launching, we always want to create a new process When
// SBTarget::CreateProcess is removed, this will always happen.
sb_process.SetProcess (m_opaque_sp->CreateProcess (m_opaque_sp->GetDebugger().GetListener()));
}
if (sb_process.IsValid())
{
error.SetError (sb_process->Attach (name, wait_for));
}
else
{
error.SetErrorString ("unable to create lldb_private::Process");
}
}
else
{
error.SetErrorString ("SBTarget is invalid");
}
return sb_process;
}
SBFileSpec
SBTarget::GetExecutable ()
{
Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
SBFileSpec exe_file_spec;
if (m_opaque_sp)
{
ModuleSP exe_module_sp (m_opaque_sp->GetExecutableModule ());
if (exe_module_sp)
exe_file_spec.SetFileSpec (exe_module_sp->GetFileSpec());
}
if (log)
{
if (exe_file_spec.Exists())
{
SBStream sstr;
exe_file_spec.GetDescription (sstr);
log->Printf ("SBTarget(%p)::GetExecutable () => SBFileSpec(%p): %s", m_opaque_sp.get(),
exe_file_spec.get(), sstr.GetData());
}
else
log->Printf ("SBTarget(%p)::GetExecutable () => SBFileSpec (%p): Unable to find valid file",
m_opaque_sp.get(), exe_file_spec.get());
}
return exe_file_spec;
}
bool
SBTarget::DeleteTargetFromList (TargetList *list)
{
if (m_opaque_sp)
return list->DeleteTarget (m_opaque_sp);
else
return false;
}
bool
SBTarget::operator == (const SBTarget &rhs) const
{
return m_opaque_sp.get() == rhs.m_opaque_sp.get();
}
bool
SBTarget::operator != (const SBTarget &rhs) const
{
return m_opaque_sp.get() != rhs.m_opaque_sp.get();
}
lldb_private::Target *
SBTarget::operator ->() const
{
return m_opaque_sp.get();
}
lldb_private::Target *
SBTarget::get() const
{
return m_opaque_sp.get();
}
void
SBTarget::reset (const lldb::TargetSP& target_sp)
{
m_opaque_sp = target_sp;
}
SBBreakpoint
SBTarget::BreakpointCreateByLocation (const char *file, uint32_t line)
{
Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
SBBreakpoint sb_bp;
if (file != NULL && line != 0)
sb_bp = BreakpointCreateByLocation (SBFileSpec (file), line);
if (log)
{
SBStream sstr;
sb_bp.GetDescription (sstr);
log->Printf("SBTarget(%p)::BreakpointCreateByLocation (file='%s', line=%d) => SBBreakpoint(%p): %s", m_opaque_sp.get(), file, line, sb_bp.get(), sstr.GetData());
}
return sb_bp;
}
SBBreakpoint
SBTarget::BreakpointCreateByLocation (const SBFileSpec &sb_file_spec, uint32_t line)
{
Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
SBBreakpoint sb_bp;
if (m_opaque_sp.get() && line != 0)
*sb_bp = m_opaque_sp->CreateBreakpoint (NULL, *sb_file_spec, line, true, false);
if (log)
{
SBStream sstr;
sb_bp.GetDescription (sstr);
log->Printf ("SBTarget(%p)::BreakpointCreateByLocation (sb_file_spec.ap=%p, line=%d) => "
"SBBreakpoint(%p): %s", m_opaque_sp.get(), sb_file_spec.get(), line, sb_bp.get(),
sstr.GetData());
}
return sb_bp;
}
SBBreakpoint
SBTarget::BreakpointCreateByName (const char *symbol_name, const char *module_name)
{
Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
SBBreakpoint sb_bp;
if (m_opaque_sp.get() && symbol_name && symbol_name[0])
{
if (module_name && module_name[0])
{
FileSpec module_file_spec(module_name, false);
*sb_bp = m_opaque_sp->CreateBreakpoint (&module_file_spec, symbol_name, eFunctionNameTypeFull | eFunctionNameTypeBase, false);
}
else
{
*sb_bp = m_opaque_sp->CreateBreakpoint (NULL, symbol_name, eFunctionNameTypeFull | eFunctionNameTypeBase, false);
}
}
if (log)
{
SBStream sstr;
sb_bp.GetDescription (sstr);
log->Printf ("SBTarget(%p)::BreakpointCreateByName (symbol_name='%s', module_name='%s') => "
"SBBreakpoint(%p): %s", m_opaque_sp.get(), symbol_name, module_name, sb_bp.get(),
sstr.GetData());
}
return sb_bp;
}
SBBreakpoint
SBTarget::BreakpointCreateByRegex (const char *symbol_name_regex, const char *module_name)
{
Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
SBBreakpoint sb_bp;
if (m_opaque_sp.get() && symbol_name_regex && symbol_name_regex[0])
{
RegularExpression regexp(symbol_name_regex);
if (module_name && module_name[0])
{
FileSpec module_file_spec(module_name, false);
*sb_bp = m_opaque_sp->CreateBreakpoint (&module_file_spec, regexp, false);
}
else
{
*sb_bp = m_opaque_sp->CreateBreakpoint (NULL, regexp, false);
}
}
if (log)
{
SBStream sstr;
sb_bp.GetDescription (sstr);
log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (symbol_name_regex='%s', module_name='%s') "
"=> SBBreakpoint(%p): %s", m_opaque_sp.get(), symbol_name_regex, module_name,
sb_bp.get(), sstr.GetData());
}
return sb_bp;
}
SBBreakpoint
SBTarget::BreakpointCreateByAddress (addr_t address)
{
Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
SBBreakpoint sb_bp;
if (m_opaque_sp.get())
*sb_bp = m_opaque_sp->CreateBreakpoint (address, false);
if (log)
{
SBStream sstr;
sb_bp.GetDescription (sstr);
log->Printf ("SBTarget(%p)::BreakpointCreateByAddress (%p, address=%p) => "
"SBBreakpoint(%p): %s", m_opaque_sp.get(), address, sb_bp.get(), sstr.GetData());
}
return sb_bp;
}
SBBreakpoint
SBTarget::FindBreakpointByID (break_id_t bp_id)
{
Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
SBBreakpoint sb_breakpoint;
if (m_opaque_sp && bp_id != LLDB_INVALID_BREAK_ID)
*sb_breakpoint = m_opaque_sp->GetBreakpointByID (bp_id);
if (log)
{
SBStream sstr;
sb_breakpoint.GetDescription (sstr);
log->Printf ("SBTarget(%p)::FindBreakpointByID (bp_id=%d) => SBBreakpoint(%p): %s",
m_opaque_sp.get(), (uint32_t) bp_id, sb_breakpoint.get(), sstr.GetData());
}
return sb_breakpoint;
}
uint32_t
SBTarget::GetNumBreakpoints () const
{
if (m_opaque_sp)
return m_opaque_sp->GetBreakpointList().GetSize();
return 0;
}
SBBreakpoint
SBTarget::GetBreakpointAtIndex (uint32_t idx) const
{
SBBreakpoint sb_breakpoint;
if (m_opaque_sp)
*sb_breakpoint = m_opaque_sp->GetBreakpointList().GetBreakpointAtIndex(idx);
return sb_breakpoint;
}
bool
SBTarget::BreakpointDelete (break_id_t bp_id)
{
Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
bool result = false;
if (m_opaque_sp)
result = m_opaque_sp->RemoveBreakpointByID (bp_id);
if (log)
{
log->Printf ("SBTarget(%p)::BreakpointDelete (bp_id=%d) => %i", m_opaque_sp.get(), (uint32_t) bp_id, result);
}
return result;
}
bool
SBTarget::EnableAllBreakpoints ()
{
if (m_opaque_sp)
{
m_opaque_sp->EnableAllBreakpoints ();
return true;
}
return false;
}
bool
SBTarget::DisableAllBreakpoints ()
{
if (m_opaque_sp)
{
m_opaque_sp->DisableAllBreakpoints ();
return true;
}
return false;
}
bool
SBTarget::DeleteAllBreakpoints ()
{
if (m_opaque_sp)
{
m_opaque_sp->RemoveAllBreakpoints ();
return true;
}
return false;
}
uint32_t
SBTarget::GetNumModules () const
{
Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
uint32_t num = 0;
if (m_opaque_sp)
num = m_opaque_sp->GetImages().GetSize();
if (log)
log->Printf ("SBTarget(%p)::GetNumModules () => %d", m_opaque_sp.get(), num);
return num;
}
void
SBTarget::Clear ()
{
Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
if (log)
log->Printf ("SBTarget(%p)::Clear ()", m_opaque_sp.get());
m_opaque_sp.reset();
}
SBModule
SBTarget::FindModule (const SBFileSpec &sb_file_spec)
{
SBModule sb_module;
if (m_opaque_sp && sb_file_spec.IsValid())
sb_module.SetModule (m_opaque_sp->GetImages().FindFirstModuleForFileSpec (*sb_file_spec, NULL));
return sb_module;
}
SBModule
SBTarget::GetModuleAtIndex (uint32_t idx)
{
Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
SBModule sb_module;
if (m_opaque_sp)
sb_module.SetModule(m_opaque_sp->GetImages().GetModuleAtIndex(idx));
if (log)
{
SBStream sstr;
sb_module.GetDescription (sstr);
log->Printf ("SBTarget(%p)::GetModuleAtIndex (idx=%d) => SBModule(%p): %s",
m_opaque_sp.get(), idx, sb_module.get(), sstr.GetData());
}
return sb_module;
}
SBBroadcaster
SBTarget::GetBroadcaster () const
{
Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
SBBroadcaster broadcaster(m_opaque_sp.get(), false);
if (log)
log->Printf ("SBTarget(%p)::GetBroadcaster () => SBBroadcaster(%p)",
m_opaque_sp.get(), broadcaster.get());
return broadcaster;
}
void
SBTarget::Disassemble (lldb::addr_t start_addr, lldb::addr_t end_addr, const char *module_name)
{
if (start_addr == LLDB_INVALID_ADDRESS)
return;
FILE *out = m_opaque_sp->GetDebugger().GetOutputFileHandle();
if (out == NULL)
return;
if (m_opaque_sp)
{
ModuleSP module_sp;
if (module_name != NULL)
{
FileSpec module_file_spec (module_name, false);
module_sp = m_opaque_sp->GetImages().FindFirstModuleForFileSpec (module_file_spec, NULL);
}
AddressRange range;
// Make sure the process object is alive if we have one (it might be
// created but we might not be launched yet).
Process *sb_process = m_opaque_sp->GetProcessSP().get();
if (sb_process && !sb_process->IsAlive())
sb_process = NULL;
// If we are given a module, then "start_addr" is a file address in
// that module.
if (module_sp)
{
if (!module_sp->ResolveFileAddress (start_addr, range.GetBaseAddress()))
range.GetBaseAddress().SetOffset(start_addr);
}
else if (m_opaque_sp->GetSectionLoadList().IsEmpty() == false)
{
// We don't have a module, se we need to figure out if "start_addr"
// resolves to anything in a running process.
if (!m_opaque_sp->GetSectionLoadList().ResolveLoadAddress (start_addr, range.GetBaseAddress()))
range.GetBaseAddress().SetOffset(start_addr);
}
else
{
if (m_opaque_sp->GetImages().ResolveFileAddress (start_addr, range.GetBaseAddress()))
range.GetBaseAddress().SetOffset(start_addr);
}
// For now, we need a process; the disassembly functions insist. If we don't have one already,
// make one.
ExecutionContext exe_ctx;
if (sb_process)
sb_process->CalculateExecutionContext(exe_ctx);
else
m_opaque_sp->CalculateExecutionContext(exe_ctx);
if (end_addr == LLDB_INVALID_ADDRESS || end_addr < start_addr)
range.SetByteSize( DEFAULT_DISASM_BYTE_SIZE);
else
range.SetByteSize(end_addr - start_addr);
StreamFile out_stream (out);
Disassembler::Disassemble (m_opaque_sp->GetDebugger(),
m_opaque_sp->GetArchitecture(),
exe_ctx,
range,
3,
false,
out_stream);
}
}
void
SBTarget::Disassemble (const char *function_name, const char *module_name)
{
if (function_name == NULL)
return;
FILE *out = m_opaque_sp->GetDebugger().GetOutputFileHandle();
if (out == NULL)
return;
if (m_opaque_sp)
{
Disassembler *disassembler = Disassembler::FindPlugin (m_opaque_sp->GetArchitecture());
if (disassembler == NULL)
return;
ModuleSP module_sp;
if (module_name != NULL)
{
FileSpec module_file_spec (module_name, false);
module_sp = m_opaque_sp->GetImages().FindFirstModuleForFileSpec (module_file_spec, NULL);
}
ExecutionContext exe_ctx;
// Make sure the process object is alive if we have one (it might be
// created but we might not be launched yet).
Process *sb_process = m_opaque_sp->GetProcessSP().get();
if (sb_process && !sb_process->IsAlive())
sb_process = NULL;
if (sb_process)
sb_process->CalculateExecutionContext(exe_ctx);
else
m_opaque_sp->CalculateExecutionContext(exe_ctx);
StreamFile out_stream (out);
Disassembler::Disassemble (m_opaque_sp->GetDebugger(),
m_opaque_sp->GetArchitecture(),
exe_ctx,
ConstString (function_name),
module_sp.get(),
3,
false,
out_stream);
}
}
bool
SBTarget::GetDescription (SBStream &description, lldb::DescriptionLevel description_level)
{
if (m_opaque_sp)
{
description.ref();
m_opaque_sp->Dump (description.get(), description_level);
}
else
description.Printf ("No value");
return true;
}
bool
SBTarget::GetDescription (SBStream &description, lldb::DescriptionLevel description_level) const
{
if (m_opaque_sp)
{
description.ref();
m_opaque_sp->Dump (description.get(), description_level);
}
else
description.Printf ("No value");
return true;
}
|