Skip to content

Commit 2ed751b

Browse files
author
Greg Clayton
committed
Changed the emulate instruction function to take emulate options which
are defined as enumerations. Current bits include: eEmulateInstructionOptionAutoAdvancePC eEmulateInstructionOptionIgnoreConditions Modified the EmulateInstruction class to have a few more pure virtuals that can help clients understand how many instructions the emulator can handle: virtual bool SupportsEmulatingIntructionsOfType (InstructionType inst_type) = 0; Where instruction types are defined as: //------------------------------------------------------------------ /// Instruction types //------------------------------------------------------------------ typedef enum InstructionType { eInstructionTypeAny, // Support for any instructions at all (at least one) eInstructionTypePrologueEpilogue, // All prologue and epilogue instructons that push and pop register values and modify sp/fp eInstructionTypePCModifying, // Any instruction that modifies the program counter/instruction pointer eInstructionTypeAll // All instructions of any kind } InstructionType; This allows use to tell what an emulator can do and also allows us to request these abilities when we are finding the plug-in interface. Added the ability for an EmulateInstruction class to get the register names for any registers that are part of the emulation. This helps with being able to dump and log effectively. The UnwindAssembly class now stores the architecture it was created with in case it is needed later in the unwinding process. Added a function that can tell us DWARF register names for ARM that goes along with the source/Utility/ARM_DWARF_Registers.h file: source/Utility/ARM_DWARF_Registers.c Took some of plug-ins out of the lldb_private namespace. llvm-svn: 130189
1 parent 80cb3cb commit 2ed751b

31 files changed

+944
-414
lines changed

lldb/include/lldb/API/SBInstruction.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class SBInstruction
5353
GetDescription (lldb::SBStream &description);
5454

5555
bool
56-
EmulateWithFrame (lldb::SBFrame &frame, bool auto_advance_pc);
56+
EmulateWithFrame (lldb::SBFrame &frame, uint32_t evaluate_options);
5757

5858
bool
5959
DumpEmulation (const char * triple); // triple is to specify the architecture, e.g. 'armv6' or 'arm-apple-darwin'

lldb/include/lldb/Core/Disassembler.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ class Instruction
8686

8787
bool
8888
Emulate (const ArchSpec &arch,
89-
bool auto_advance_pc,
89+
uint32_t evaluate_options,
9090
void *baton,
9191
EmulateInstruction::ReadMemory read_mem_callback,
9292
EmulateInstruction::WriteMemory write_mem_calback,

lldb/include/lldb/Core/EmulateInstruction.h

+51-41
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,9 @@ class EmulateInstruction :
8686
public:
8787

8888
static EmulateInstruction*
89-
FindPlugin (const ArchSpec &arch, const char *plugin_name);
89+
FindPlugin (const ArchSpec &arch,
90+
InstructionType supported_inst_type,
91+
const char *plugin_name);
9092

9193
enum ContextType
9294
{
@@ -366,45 +368,43 @@ class EmulateInstruction :
366368
static void
367369
PrintContext (const char *context_type, const Context &context);
368370

369-
typedef size_t (*ReadMemory) (void *baton,
371+
typedef size_t (*ReadMemory) (EmulateInstruction *instruction,
372+
void *baton,
370373
const Context &context,
371374
lldb::addr_t addr,
372375
void *dst,
373376
size_t length);
374377

375-
typedef size_t (*WriteMemory) (void *baton,
378+
typedef size_t (*WriteMemory) (EmulateInstruction *instruction,
379+
void *baton,
376380
const Context &context,
377381
lldb::addr_t addr,
378382
const void *dst,
379383
size_t length);
380384

381-
typedef bool (*ReadRegister) (void *baton,
385+
typedef bool (*ReadRegister) (EmulateInstruction *instruction,
386+
void *baton,
382387
uint32_t reg_kind,
383388
uint32_t reg_num,
384389
uint64_t &reg_value);
385390

386-
typedef bool (*WriteRegister) (void *baton,
391+
typedef bool (*WriteRegister) (EmulateInstruction *instruction,
392+
void *baton,
387393
const Context &context,
388394
uint32_t reg_kind,
389395
uint32_t reg_num,
390396
uint64_t reg_value);
391397

392-
EmulateInstruction (lldb::ByteOrder byte_order,
393-
uint32_t addr_byte_size,
394-
const ArchSpec &arch,
395-
void *baton,
396-
ReadMemory read_mem_callback,
397-
WriteMemory write_mem_callback,
398-
ReadRegister read_reg_callback,
399-
WriteRegister write_reg_callback);
400-
401-
EmulateInstruction (lldb::ByteOrder byte_order,
402-
uint32_t addr_byte_size,
403-
const ArchSpec &arch);
398+
EmulateInstruction (const ArchSpec &arch);
404399

405400
virtual ~EmulateInstruction()
406401
{
407402
}
403+
//----------------------------------------------------------------------
404+
// Mandatory overrides
405+
//----------------------------------------------------------------------
406+
virtual bool
407+
SupportsEmulatingIntructionsOfType (InstructionType inst_type) = 0;
408408

409409
virtual bool
410410
SetTargetTriple (const ArchSpec &arch) = 0;
@@ -413,21 +413,20 @@ class EmulateInstruction :
413413
ReadInstruction () = 0;
414414

415415
virtual bool
416-
SetInstruction (const Opcode &insn_opcode, const Address &inst_addr) = 0;
417-
418-
virtual bool
419-
EvaluateInstruction () = 0;
416+
EvaluateInstruction (uint32_t evaluate_options) = 0;
420417

421418
virtual bool
422419
TestEmulation (Stream *out_stream, ArchSpec &arch, OptionValueDictionary *test_data) = 0;
420+
421+
virtual const char *
422+
GetRegisterName (uint32_t reg_kind, uint32_t reg_num) = 0;
423+
//----------------------------------------------------------------------
424+
// Optional overrides
425+
//----------------------------------------------------------------------
426+
virtual bool
427+
SetInstruction (const Opcode &insn_opcode, const Address &inst_addr, Target *target);
423428

424-
bool
425-
GetAdvancePC () { return m_advance_pc; }
426-
427-
void
428-
SetAdvancePC (bool value) { m_advance_pc = value; }
429-
430-
static void
429+
static const char *
431430
TranslateRegister (uint32_t reg_kind, uint32_t reg_num, std::string &reg_name);
432431

433432
uint64_t
@@ -458,73 +457,87 @@ class EmulateInstruction :
458457
uint32_t
459458
GetAddressByteSize () const
460459
{
461-
return m_addr_byte_size;
460+
return m_arch.GetAddressByteSize();
462461
}
463462

464463
lldb::ByteOrder
465464
GetByteOrder () const
466465
{
467-
return m_byte_order;
466+
return m_arch.GetByteOrder();
468467
}
469468

470469
const Opcode &
471470
GetOpcode () const
472471
{
473472
return m_opcode;
474473
}
474+
475+
const ArchSpec &
476+
GetArchitecture () const
477+
{
478+
return m_arch;
479+
}
475480

476481

477482
static size_t
478-
ReadMemoryFrame (void *baton,
483+
ReadMemoryFrame (EmulateInstruction *instruction,
484+
void *baton,
479485
const Context &context,
480486
lldb::addr_t addr,
481487
void *dst,
482488
size_t length);
483489

484490
static size_t
485-
WriteMemoryFrame (void *baton,
491+
WriteMemoryFrame (EmulateInstruction *instruction,
492+
void *baton,
486493
const Context &context,
487494
lldb::addr_t addr,
488495
const void *dst,
489496
size_t length);
490497

491498
static bool
492-
ReadRegisterFrame (void *baton,
499+
ReadRegisterFrame (EmulateInstruction *instruction,
500+
void *baton,
493501
uint32_t reg_kind,
494502
uint32_t reg_num,
495503
uint64_t &reg_value);
496504

497505

498506
static bool
499-
WriteRegisterFrame (void *baton,
507+
WriteRegisterFrame (EmulateInstruction *instruction,
508+
void *baton,
500509
const Context &context,
501510
uint32_t reg_kind,
502511
uint32_t reg_num,
503512
uint64_t reg_value);
504513

505514
static size_t
506-
ReadMemoryDefault (void *baton,
515+
ReadMemoryDefault (EmulateInstruction *instruction,
516+
void *baton,
507517
const Context &context,
508518
lldb::addr_t addr,
509519
void *dst,
510520
size_t length);
511521

512522
static size_t
513-
WriteMemoryDefault (void *baton,
523+
WriteMemoryDefault (EmulateInstruction *instruction,
524+
void *baton,
514525
const Context &context,
515526
lldb::addr_t addr,
516527
const void *dst,
517528
size_t length);
518529

519530
static bool
520-
ReadRegisterDefault (void *baton,
531+
ReadRegisterDefault (EmulateInstruction *instruction,
532+
void *baton,
521533
uint32_t reg_kind,
522534
uint32_t reg_num,
523535
uint64_t &reg_value);
524536

525537

526538
static bool
527-
WriteRegisterDefault (void *baton,
539+
WriteRegisterDefault (EmulateInstruction *instruction,
540+
void *baton,
528541
const Context &context,
529542
uint32_t reg_kind,
530543
uint32_t reg_num,
@@ -553,8 +566,6 @@ class EmulateInstruction :
553566

554567

555568
protected:
556-
lldb::ByteOrder m_byte_order;
557-
uint32_t m_addr_byte_size;
558569
ArchSpec m_arch;
559570
void * m_baton;
560571
ReadMemory m_read_mem_callback;
@@ -563,7 +574,6 @@ class EmulateInstruction :
563574
WriteRegister m_write_reg_callback;
564575
lldb::addr_t m_opcode_pc;
565576
Opcode m_opcode;
566-
bool m_advance_pc;
567577
//------------------------------------------------------------------
568578
// For EmulateInstruction only
569579
//------------------------------------------------------------------

lldb/include/lldb/Target/ArchDefaultUnwindPlan.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ class ArchDefaultUnwindPlan :
2424
~ArchDefaultUnwindPlan();
2525

2626
virtual lldb::UnwindPlanSP
27-
GetArchDefaultUnwindPlan (Thread& thread, Address current_pc) = 0;
27+
GetArchDefaultUnwindPlan (Thread& thread,
28+
const Address &current_pc) = 0;
2829

2930
static lldb::ArchDefaultUnwindPlanSP
3031
FindPlugin (const ArchSpec &arch);

lldb/include/lldb/Target/UnwindAssembly.h

+5-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#define utility_UnwindAssembly_h_
1212

1313
#include "lldb/lldb-private.h"
14+
#include "lldb/Core/ArchSpec.h"
1415
#include "lldb/Core/PluginInterface.h"
1516

1617
namespace lldb_private {
@@ -43,8 +44,11 @@ class UnwindAssembly :
4344
Address& first_non_prologue_insn) = 0;
4445

4546
protected:
46-
UnwindAssembly();
47+
UnwindAssembly (const ArchSpec &arch);
48+
ArchSpec m_arch;
49+
4750
private:
51+
UnwindAssembly(); // Outlaw default constructor
4852
DISALLOW_COPY_AND_ASSIGN (UnwindAssembly);
4953
};
5054

lldb/include/lldb/lldb-enumerations.h

+7
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,13 @@ namespace lldb {
457457

458458
} SectionType;
459459

460+
typedef enum EmulateInstructionOptions
461+
{
462+
eEmulateInstructionOptionNone = (0u),
463+
eEmulateInstructionOptionAutoAdvancePC = (1u << 0),
464+
eEmulateInstructionOptionIgnoreConditions = (1u << 1)
465+
} EmulateInstructionOptions;
466+
460467
} // namespace lldb
461468

462469

lldb/include/lldb/lldb-private-enumerations.h

+13
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,19 @@ typedef enum NameMatchType
204204
} NameMatchType;
205205

206206

207+
//------------------------------------------------------------------
208+
/// Instruction types
209+
//------------------------------------------------------------------
210+
typedef enum InstructionType
211+
{
212+
eInstructionTypeAny, // Support for any instructions at all (at least one)
213+
eInstructionTypePrologueEpilogue, // All prologue and epilogue instructons that push and pop register values and modify sp/fp
214+
eInstructionTypePCModifying, // Any instruction that modifies the program counter/instruction pointer
215+
eInstructionTypeAll // All instructions of any kind
216+
217+
} InstructionType;
218+
219+
207220
} // namespace lldb
208221

209222

lldb/include/lldb/lldb-private-interfaces.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ namespace lldb_private
2222
typedef ObjectContainer* (*ObjectContainerCreateInstance) (Module* module, lldb::DataBufferSP& dataSP, const FileSpec *file, lldb::addr_t offset, lldb::addr_t length);
2323
typedef ObjectFile* (*ObjectFileCreateInstance) (Module* module, lldb::DataBufferSP& dataSP, const FileSpec* file, lldb::addr_t offset, lldb::addr_t length);
2424
typedef LogChannel* (*LogChannelCreateInstance) ();
25-
typedef EmulateInstruction * (*EmulateInstructionCreateInstance) (const ArchSpec &arch);
25+
typedef EmulateInstruction * (*EmulateInstructionCreateInstance) (const ArchSpec &arch, InstructionType inst_type);
2626
typedef LanguageRuntime *(*LanguageRuntimeCreateInstance) (Process *process, lldb::LanguageType language);
2727
typedef Platform* (*PlatformCreateInstance) ();
2828
typedef Process* (*ProcessCreateInstance) (Target &target, Listener &listener);

lldb/lldb.xcodeproj/project.pbxproj

+4
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,7 @@
404404
26DE20611161902700A093E2 /* SBBlock.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 26DE20601161902600A093E2 /* SBBlock.cpp */; };
405405
26DE20631161904200A093E2 /* SBLineEntry.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 26DE20621161904200A093E2 /* SBLineEntry.cpp */; };
406406
26DE20651161904E00A093E2 /* SBSymbol.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 26DE20641161904E00A093E2 /* SBSymbol.cpp */; };
407+
26ECA04313665FED008D1F18 /* ARM_DWARF_Registers.c in Sources */ = {isa = PBXBuildFile; fileRef = 26ECA04213665FED008D1F18 /* ARM_DWARF_Registers.c */; };
407408
26F5C27710F3D9E4009D5894 /* Driver.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 26F5C27310F3D9E4009D5894 /* Driver.cpp */; };
408409
26F5C27810F3D9E4009D5894 /* IOChannel.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 26F5C27510F3D9E4009D5894 /* IOChannel.cpp */; };
409410
26F5C32510F3DF23009D5894 /* libpython.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 26F5C32410F3DF23009D5894 /* libpython.dylib */; };
@@ -1043,6 +1044,7 @@
10431044
26E3EEF811A994E800FBADB6 /* RegisterContextMacOSXFrameBackchain.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = RegisterContextMacOSXFrameBackchain.h; path = Utility/RegisterContextMacOSXFrameBackchain.h; sourceTree = "<group>"; };
10441045
26E6902E129C6BD500DDECD9 /* ClangExternalASTSourceCallbacks.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ClangExternalASTSourceCallbacks.h; path = include/lldb/Symbol/ClangExternalASTSourceCallbacks.h; sourceTree = "<group>"; };
10451046
26E69030129C6BEF00DDECD9 /* ClangExternalASTSourceCallbacks.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ClangExternalASTSourceCallbacks.cpp; path = source/Symbol/ClangExternalASTSourceCallbacks.cpp; sourceTree = "<group>"; };
1047+
26ECA04213665FED008D1F18 /* ARM_DWARF_Registers.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = ARM_DWARF_Registers.c; path = source/Utility/ARM_DWARF_Registers.c; sourceTree = "<group>"; };
10461048
26F5C26A10F3D9A4009D5894 /* lldb */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = lldb; sourceTree = BUILT_PRODUCTS_DIR; };
10471049
26F5C27210F3D9E4009D5894 /* lldb-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = "lldb-Info.plist"; path = "tools/driver/lldb-Info.plist"; sourceTree = "<group>"; };
10481050
26F5C27310F3D9E4009D5894 /* Driver.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = Driver.cpp; path = tools/driver/Driver.cpp; sourceTree = "<group>"; };
@@ -1761,6 +1763,7 @@
17611763
4C2FAE2E135E3A70001EDE44 /* SharedCluster.h */,
17621764
261B5A5311C3F2AD00AABD0A /* SharingPtr.h */,
17631765
26F996A7119B79C300412154 /* ARM_DWARF_Registers.h */,
1766+
26ECA04213665FED008D1F18 /* ARM_DWARF_Registers.c */,
17641767
26F996A8119B79C300412154 /* ARM_GCC_Registers.h */,
17651768
2660D9F611922A1300958FBD /* StringExtractor.cpp */,
17661769
2660D9F711922A1300958FBD /* StringExtractor.h */,
@@ -3231,6 +3234,7 @@
32313234
2692BA231366150100F9E14D /* ArchVolatileRegs-x86.cpp in Sources */,
32323235
263E949F13661AEA00E7D1CE /* UnwindAssembly-x86.cpp in Sources */,
32333236
264D8D5013661BD7003A368F /* UnwindAssembly.cpp in Sources */,
3237+
26ECA04313665FED008D1F18 /* ARM_DWARF_Registers.c in Sources */,
32343238
);
32353239
runOnlyForDeploymentPostprocessing = 0;
32363240
};

lldb/lldb.xcodeproj/xcshareddata/xcschemes/lldb-tool.xcscheme

-4
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,6 @@
7474
<LaunchAction
7575
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
7676
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
77-
displayScaleIsEnabled = "NO"
78-
displayScale = "1.00"
7977
launchStyle = "0"
8078
useCustomWorkingDirectory = "YES"
8179
customWorkingDirectory = "/Volumes/work/gclayton/Documents/src/lldb/build/Debug"
@@ -131,8 +129,6 @@
131129
</AdditionalOptions>
132130
</LaunchAction>
133131
<ProfileAction
134-
displayScaleIsEnabled = "NO"
135-
displayScale = "1.00"
136132
shouldUseLaunchSchemeArgsEnv = "YES"
137133
savedToolIdentifier = ""
138134
useCustomWorkingDirectory = "NO"

lldb/source/API/SBInstruction.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ SBInstruction::Print (FILE *out)
116116
}
117117

118118
bool
119-
SBInstruction::EmulateWithFrame (lldb::SBFrame &frame, bool auto_advance_pc)
119+
SBInstruction::EmulateWithFrame (lldb::SBFrame &frame, uint32_t evaluate_options)
120120
{
121121
if (m_opaque_sp && frame.get())
122122
{
@@ -126,7 +126,7 @@ SBInstruction::EmulateWithFrame (lldb::SBFrame &frame, bool auto_advance_pc)
126126
lldb_private::ArchSpec arch = target->GetArchitecture();
127127

128128
return m_opaque_sp->Emulate (arch,
129-
auto_advance_pc,
129+
evaluate_options,
130130
(void *) frame.get(),
131131
&lldb_private::EmulateInstruction::ReadMemoryFrame,
132132
&lldb_private::EmulateInstruction::WriteMemoryFrame,

0 commit comments

Comments
 (0)