LLDB  mainline
SBInstructionList.cpp
Go to the documentation of this file.
1 //===-- SBInstructionList.cpp -----------------------------------*- C++ -*-===//
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 
10 #include "SBReproducerPrivate.h"
11 #include "lldb/API/SBAddress.h"
12 #include "lldb/API/SBInstruction.h"
13 #include "lldb/API/SBStream.h"
14 #include "lldb/Core/Disassembler.h"
15 #include "lldb/Core/Module.h"
17 #include "lldb/Utility/Stream.h"
18 
19 using namespace lldb;
20 using namespace lldb_private;
21 
24 }
25 
27  : m_opaque_sp(rhs.m_opaque_sp) {
29  rhs);
30 }
31 
36  SBInstructionList, operator=,(const lldb::SBInstructionList &), rhs);
37 
38  if (this != &rhs)
39  m_opaque_sp = rhs.m_opaque_sp;
40  return LLDB_RECORD_RESULT(*this);
41 }
42 
44 
47  return this->operator bool();
48 }
49 SBInstructionList::operator bool() const {
51 
52  return m_opaque_sp.get() != NULL;
53 }
54 
57 
58  if (m_opaque_sp)
59  return m_opaque_sp->GetInstructionList().GetSize();
60  return 0;
61 }
62 
66 
67  SBInstruction inst;
68  if (m_opaque_sp && idx < m_opaque_sp->GetInstructionList().GetSize())
69  inst.SetOpaque(
70  m_opaque_sp,
71  m_opaque_sp->GetInstructionList().GetInstructionAtIndex(idx));
72  return LLDB_RECORD_RESULT(inst);
73 }
74 
76  const SBAddress &end,
77  bool canSetBreakpoint) {
79  (const lldb::SBAddress &, const lldb::SBAddress &, bool),
80  start, end, canSetBreakpoint);
81 
82  size_t num_instructions = GetSize();
83  size_t i = 0;
84  SBAddress addr;
85  size_t lower_index = 0;
86  size_t upper_index = 0;
87  size_t instructions_to_skip = 0;
88  for (i = 0; i < num_instructions; ++i) {
90  if (start == addr)
91  lower_index = i;
92  if (end == addr)
93  upper_index = i;
94  }
95  if (canSetBreakpoint)
96  for (i = lower_index; i <= upper_index; ++i) {
98  if (!insn.CanSetBreakpoint())
99  ++instructions_to_skip;
100  }
101  return upper_index - lower_index - instructions_to_skip;
102 }
103 
106 
107  m_opaque_sp.reset();
108 }
109 
112  (lldb::SBInstruction), insn);
113 }
114 
115 void SBInstructionList::SetDisassembler(const lldb::DisassemblerSP &opaque_sp) {
116  m_opaque_sp = opaque_sp;
117 }
118 
119 void SBInstructionList::Print(FILE *out) {
120  LLDB_RECORD_METHOD(void, SBInstructionList, Print, (FILE *), out);
121 
122  if (out == NULL)
123  return;
124 }
125 
128  (lldb::SBStream &), description);
129 
130  if (m_opaque_sp) {
131  size_t num_instructions = GetSize();
132  if (num_instructions) {
133  // Call the ref() to make sure a stream is created if one deesn't exist
134  // already inside description...
135  Stream &sref = description.ref();
136  const uint32_t max_opcode_byte_size =
137  m_opaque_sp->GetInstructionList().GetMaxOpcocdeByteSize();
138  FormatEntity::Entry format;
139  FormatEntity::Parse("${addr}: ", format);
140  SymbolContext sc;
141  SymbolContext prev_sc;
142  for (size_t i = 0; i < num_instructions; ++i) {
143  Instruction *inst =
144  m_opaque_sp->GetInstructionList().GetInstructionAtIndex(i).get();
145  if (inst == NULL)
146  break;
147 
148  const Address &addr = inst->GetAddress();
149  prev_sc = sc;
150  ModuleSP module_sp(addr.GetModule());
151  if (module_sp) {
152  module_sp->ResolveSymbolContextForAddress(
153  addr, eSymbolContextEverything, sc);
154  }
155 
156  inst->Dump(&sref, max_opcode_byte_size, true, false, NULL, &sc,
157  &prev_sc, &format, 0);
158  sref.EOL();
159  }
160  return true;
161  }
162  }
163  return false;
164 }
165 
168  (const char *), triple);
169 
170  if (m_opaque_sp) {
171  size_t len = GetSize();
172  for (size_t i = 0; i < len; ++i) {
173  if (!GetInstructionAtIndex((uint32_t)i).DumpEmulation(triple))
174  return false;
175  }
176  }
177  return true;
178 }
179 
180 namespace lldb_private {
181 namespace repro {
182 
183 template <>
187  (const lldb::SBInstructionList &));
189  const lldb::SBInstructionList &,
190  SBInstructionList, operator=,(const lldb::SBInstructionList &));
192  LLDB_REGISTER_METHOD_CONST(bool, SBInstructionList, operator bool, ());
198  (const lldb::SBAddress &, const lldb::SBAddress &, bool));
202  LLDB_REGISTER_METHOD(void, SBInstructionList, Print, (FILE *));
204  (lldb::SBStream &));
206  DumpEmulationForAllInstructions, (const char *));
207 }
208 
209 }
210 }
The registry contains a unique mapping between functions and their ID.
lldb::SBInstruction GetInstructionAtIndex(uint32_t idx)
Enumerations for broadcasting.
Definition: SBLaunchInfo.h:14
#define LLDB_RECORD_CONSTRUCTOR_NO_ARGS(Class)
void SetOpaque(const lldb::DisassemblerSP &disasm_sp, const lldb::InstructionSP &inst_sp)
A stream class that can stream formatted output to a file.
Definition: Stream.h:28
bool DumpEmulationForAllInstructions(const char *triple)
Defines a symbol context baton that can be handed other debug core functions.
Definition: SymbolContext.h:33
virtual void Dump(Stream *s, uint32_t max_opcode_byte_size, bool show_address, bool show_bytes, const ExecutionContext *exe_ctx, const SymbolContext *sym_ctx, const SymbolContext *prev_sym_ctx, const FormatEntity::Entry *disassembly_addr_format, size_t max_address_text_size)
Dump the text representation of this Instruction to a Stream.
size_t GetInstructionsCount(const SBAddress &start, const SBAddress &end, bool canSetBreakpoint=false)
bool GetDescription(lldb::SBStream &description)
#define LLDB_REGISTER_CONSTRUCTOR(Class, Signature)
#define LLDB_RECORD_METHOD_NO_ARGS(Result, Class, Method)
Node * Parse(llvm::StringRef expr, llvm::BumpPtrAllocator &alloc)
Parse the given postfix expression.
#define LLDB_RECORD_CONSTRUCTOR(Class, Signature,...)
size_t EOL()
Output and End of Line character to the stream.
Definition: Stream.cpp:127
#define LLDB_RECORD_METHOD(Result, Class, Method, Signature,...)
void SetDisassembler(const lldb::DisassemblerSP &opaque_sp)
void AppendInstruction(lldb::SBInstruction inst)
A section + offset based address class.
Definition: Address.h:80
lldb_private::Stream & ref()
Definition: SBStream.cpp:162
const SBInstructionList & operator=(const SBInstructionList &rhs)
lldb::ModuleSP GetModule() const
Get accessor for the module for this address.
Definition: Address.cpp:264
void RegisterMethods< SBInstructionList >(Registry &R)
Definition: SBAddress.h:15
#define LLDB_REGISTER_METHOD(Result, Class, Method, Signature)
#define LLDB_RECORD_METHOD_CONST_NO_ARGS(Result, Class, Method)
#define LLDB_RECORD_RESULT(Result)
const Address & GetAddress() const
Definition: Disassembler.h:84
#define LLDB_REGISTER_METHOD_CONST(Result, Class, Method, Signature)