Commit Graph

293 Commits

Author SHA1 Message Date
Ulrich Weigand 91a2ad182d Fix ARM instruction emulation tests on big-endian systems
Running the ARM instruction emulation test on a big-endian system
would fail, since the code doesn't respect endianness properly.

In EmulateInstructionARM::TestEmulation, code assumes that an
instruction opcode read in from the test file is in target byte
order, but it was in fact read in in host byte order.

More difficult to fix, the EmulationStateARM structure models
the overlapping sregs and dregs by a union in _sd_regs.  This
only works correctly if the host is a little-endian system.
I've removed the union in favor of a simple array containing
the 32 sregs, and changed any code accessing dregs to explicitly
use the correct two sregs overlaying that dreg in the proper
target order.

Also, the EmulationStateARM::ReadPseudoMemory and WritePseudoMemory
track memory as a map of uint32_t values in host byte order, and
implement 64-bit memory accessing by splitting them up into two
uint32_t ones.  However, callers expect memory contents to be
provided in the form of a byte array (in target byte order).
This means the uint32_t contents need to be byte-swapped on
BE systems, and when splitting up a 64-bit access into two 32-bit
ones, byte order has to be respected.

Differential Revision: http://reviews.llvm.org/D18984

llvm-svn: 266314
2016-04-14 14:34:19 +00:00
Ulrich Weigand b00ef10b70 Make Scalar::GetBytes and RegisterValue::GetBytes const
Scalar::GetBytes provides a non-const access to the underlying bytes
of the scalar value, supposedly allowing for modification of those
bytes.  However, even with the current implementation, this is not
really possible.  For floating-point scalars, the pointer returned
by GetBytes refers to a temporary copy; modifications to that copy
will be simply ignored.  For integer scalars, the pointer refers
to internal memory of the APInt implementation, which isn't
supposed to be directly modifyable; GetBytes simply casts aways
the const-ness of the pointer ...

With my upcoming patch to fix Scalar::GetBytes for big-endian
systems, this problem is going to get worse, since there we need
temporary copies even for some integer scalars.  Therefore, this
patch makes Scalar::GetBytes const, fixing all those problems.

As a follow-on change, RegisterValues::GetBytes must be made const
as well.  This in turn means that the way of initializing a
RegisterValue by doing a SetType followed by writing to GetBytes
no longer works.  Instead, I've changed SetValueFromData to do
the equivalent of SetType itself, and then re-implemented
SetFromMemoryData to work on top of SetValueFromData. 

There is still a need for RegisterValue::SetType, since some
platform-specific code uses it to reinterpret the contents of
an already filled RegisterValue.  To make this usage work in
all cases (even changing from a type implemented via Scalar
to a type implemented as a byte buffer), SetType now simply
copies the old contents out, and then reloads the RegisterValue
from this data using the new type via SetValueFromData.

This in turn means that there is no remaining caller of
Scalar::SetType, so it can be removed.

The only other follow-on change was in MIPS EmulateInstruction
code, where some uses of RegisterValue::GetBytes could be made
const trivially.

Differential Revision: http://reviews.llvm.org/D18980

llvm-svn: 266310
2016-04-14 14:31:08 +00:00
Jason Molenda 583b1a8a1b Consolidate the knowledge of what arm cores are always executing
in thumb mode into one method in ArchSpec, replace checks for
specific cores in the disassembler with calls to this.  Also call
this from the arm instruction emulation code.

The determination of whether a given ArchSpec is thumb-only is still
a bit of a hack, but at least the hack is consolidated into a single
place.  In my original version of this patch http://reviews.llvm.org/D13578
I was calling into llvm's feature arm feature tables to make this
determination, like

#include "llvm/Support/TargetRegistry.h"
#include "llvm/MC/MCSubtargetInfo.h"
#include "llvm/../../lib/Target/ARM/ARMGenRegisterInfo.inc"
#include "llvm/../../lib/Target/ARM/ARMFeatures.h"

[...]

        std::string triple (GetTriple().getTriple());
        const char *cpu = "";
        const char *features_str = "";
        const llvm::Target *curr_target = llvm::TargetRegistry::lookupTarget(triple.c_str(), Error);
        std::unique_ptr<llvm::MCSubtargetInfo> subtarget_info_up (curr_target->createMCSubtargetInfo(triple.c_str(), cpu, features_str));
        if (subtarget_info_up->getFeatureBits()[llvm::ARM::FeatureNoARM])
        {
            return true;
        }

but those tables are post-llvm-build generated and linking against them
for all of our different build system methods was a big hiccup that I
haven't had time to revisit convincingly.

I'll keep that reviews.llvm.org patch around to remind myself that I
need to take another run at linking against the necessary tables 
again in llvm.

<rdar://problem/23022803> 

llvm-svn: 265377
2016-04-05 05:01:30 +00:00
Greg Clayton cec91ef921 Fix all of the unannotated switch cases to annotate the fall through or do the right thing and break.
llvm-svn: 261950
2016-02-26 01:20:20 +00:00
Tamas Berghammer 10e9923841 Fix handling of the arm IT instruction in the unwinder
The IT instruction can specify condition code for up to 4 consecutive
instruction and it is used quite often by clang in epilogues causing
an issue when trying to unwind from locations covered by the IT
instruction and for locatins inmediately after the IT instruction.

Changes made to fix it:
* Introduce the concept of conditional instruction block what is a list
  of consecutive instructions with the same condition. We update the
  unwind information during the conditional instruction block and when
  we reach the end of it (first instruction with a differemt condition)
  then we restore the unwind information we had before the condition.
* Fix a bug in the ARM instruction emulator where neither PC nor the
  ITSTATE was advanced when we reached an instruction what we can't
  decode.

After the change we have no regression on android-arm running the
regular test suit and TestStandardUnwind also passes when running it
with clang as the compiler (previously it failed on an IT instruction).

Differential revision: http://reviews.llvm.org/D16814

llvm-svn: 260368
2016-02-10 10:42:13 +00:00
Tamas Berghammer 8e18fe6e54 Fix single stepping over the IT instruction
The ARM instruction emulator had 2 bugs related to the handling of the
IT instruction causing an error in single stepping:
* We haven't initialized the IT mask from the CPSR so if the last
  instruction of the IT block is a branch and the condition is false
  then the emulator evaluated the branch what resulted in an incorrect
  pc for the next instruction.
* The ITSTATE was advanced before the execution of each instruction. As
  a result the emulator was using the condition of following instruction
  in every case. The ITSTATE should be edvanced after the execution of
  an instruction except after an IT instruction.

Differential revision: http://reviews.llvm.org/D16772

llvm-svn: 259509
2016-02-02 14:32:11 +00:00
Eugene Zelenko c33088f41e Remove autoconf support from source directories.
Differential revision: http://reviews.llvm.org/D16662

llvm-svn: 259098
2016-01-28 22:05:24 +00:00
Benjamin Kramer 79dad1d056 Update for LLVM change
llvm-svn: 258819
2016-01-26 16:45:00 +00:00
Zachary Turner a505be4e5d Fix some compiler warnings with MSVC 2015.
llvm-svn: 257671
2016-01-13 21:22:00 +00:00
Bhushan D. Attarde 2be2c9a6ce [LLDB][MIPS] Merge emulation of similar instructions for MIPS64
SUMMARY:
    This patch merges emulation of similar instructions into a single function (wherever possible) to remove code duplication.
    
    Reviewers: clayborg
    Subscribers: mohit.bhakkad, sagar, jaydeep, lldb-commits
    Differential Revision: http://reviews.llvm.org/D16051

llvm-svn: 257442
2016-01-12 03:56:58 +00:00
Bhushan D. Attarde 6fd916cd0c Fix build warnings after rL256915
llvm-svn: 256929
2016-01-06 12:08:22 +00:00
Bhushan D. Attarde f2be8df54b [LLDB][MIPS32]Merge emulation of similar instructions
SUMMARY:
    This patch merges emulation of similar instructions into a single function (wherever possible) to remove code duplication.
    
    Reviewers: clayborg
    Subscribers: mohit.bhakkad, sagar, jaydeep, lldb-commits
    Differential Revision: http://reviews.llvm.org/D15886

llvm-svn: 256915
2016-01-06 05:44:02 +00:00
Tamas Berghammer fde63cad6b Fix emulation of the thumb str instruction
llvm-svn: 256147
2015-12-21 12:06:36 +00:00
Tamas Berghammer 6517b004b2 Fix the emulation of arm strd instruction
The incorrect instruction emulation caused issues in the stack unwinding
code when strd was used to push 2 register to the stack with writeback.

llvm-svn: 256000
2015-12-18 15:35:08 +00:00
Jason Molenda a814f704d3 Add support for the new (added last week) llvm::Triple::WatchOS and ::TvOS
in places where we check for Triple::IOS.  They're mostly the same as far
as lldb is conerned.
.
Also add a base cass implementation for Process::IsAlive - Greg added this 
last year but it didn't get upstreamed.

llvm-svn: 252227
2015-11-05 23:03:44 +00:00
Eugene Zelenko 4c3f2b9446 Fix Clang-tidy modernize-use-override warnings in some files in source/Plugins; other minor fixes.
Differential Revision: http://reviews.llvm.org/D13916

llvm-svn: 250872
2015-10-21 01:03:30 +00:00
Saleem Abdulrasool 8b8d2a4d99 Silence some -Wunused-but-set-variable with gcc 5.2.0
Cleanup some unused variables.  NFC.

llvm-svn: 250661
2015-10-18 19:34:31 +00:00
Tamas Berghammer 75cb3c5077 Make use of lldv::Triple::isAndroid
It is a new function added to the llvm::Triple class to simplify the
checking if we are targeting android to clean up the confusion between
android being an OS or an environment.

llvm-svn: 250286
2015-10-14 10:29:17 +00:00
Mohit K. Bhakkad 87ef39a6a8 [LLDB][MIPS64] Adding mips64 reaturn address register for unwind plan
llvm-svn: 250267
2015-10-14 05:20:03 +00:00
Mohit K. Bhakkad 8087745c47 Addressing warning due to rL249651
llvm-svn: 249809
2015-10-09 06:34:52 +00:00
Mohit K. Bhakkad e990bfe117 [LLDB][MIPS] microMIPS load/store instruction emulation for hardware watchpoints
Reviewers: clayborg.
Subscribers: jaydeep, bhushan, sagar, nitesh.jain, lldb-commits.
Differential Revision: http://reviews.llvm.org/D13493

llvm-svn: 249651
2015-10-08 03:34:11 +00:00
Bruce Mitchener 39eb9de757 Remove GetShortPluginName.
Summary: This was deprecated and removed.

Reviewers: clayborg

Subscribers: lldb-commits

Differential Revision: http://reviews.llvm.org/D13463

llvm-svn: 249452
2015-10-06 20:15:27 +00:00
Bruce Mitchener b810314825 Fix virtual/override warnings in new MIPS code.
Reviewers: bhushan, tberghammer

Subscribers: lldb-commits

Differential Revision: http://reviews.llvm.org/D13462

llvm-svn: 249405
2015-10-06 14:19:32 +00:00
Bhushan D. Attarde f55a0a47cf [MIPS] Emulate microMIPS instructions
SUMMARY:
    This patch includes:

    1. Emulation of prologue/epilogue and branch instructions for microMIPS.
    2. Setting up alternate disassembler (to be used for microMIPS).
       So there will be two disassembler instances, one for microMIPS and other for MIPS.
       Appropriate disassembler will be used based on the address class of instruction address.

    3. Some of the branch instructions does not have fixed sized delay slot, that means delay slot instruction can be of 2-byte or 4-byte.
       For this "m_next_inst_size" has been introduced which stores the size of next instruction (i.e size of delay slot instruction in case of branch).
       This can be used wherever the size of next instruction is required.

    4. A minor change to use mips32 register names instead of mips64 names.
    
    Reviewers: clayborg, tberghammer
    Subscribers: mohit.bhakkad, sagar, jaydeep, nitesh.jain, lldb-commits
    Differential Revision: http://reviews.llvm.org/D13282 

llvm-svn: 249381
2015-10-06 08:52:08 +00:00
Tamas Berghammer 3f934e4b13 Fix register names in EmulateInstructionMIPS.cpp
llvm-svn: 248281
2015-09-22 15:04:39 +00:00
Sagar Thakur af368f6e88 [MIPS32] Emulate MSA instructions for MIPS32
This patch adds MSA branch instruction emulation for MIPS32.

Reviewers: tberghammer, jaydeep
Subscribers: mohit.bhakkad, bhushan, nitesh.jain
Differential: http://reviews.llvm.org/D12898
llvm-svn: 248277
2015-09-22 13:57:11 +00:00
Jason Molenda 63bd0db071 Clean up register naming conventions inside lldb.
"gcc" register numbers are now correctly referred to as "ehframe"
register numbers.  In almost all cases, ehframe and dwarf register
numbers are identical (the one exception is i386 darwin where ehframe
regnums were incorrect).

The old "gdb" register numbers, which I incorrectly thought were
stabs register numbers, are now referred to as "Process Plugin"
register numbers.  This is the register numbering scheme that the
remote process controller stub (lldb-server, gdbserver, core file
support, kdp server, remote jtag devices, etc) uses to refer to the
registers.  The process plugin register numbers may not be contiguous
- there are remote jtag devices that have gaps in their register
numbering schemes.

I removed all of the enums for "gdb" register numbers that we had
in lldb - these were meaningless - and I put LLDB_INVALID_REGNUM
in all of the register tables for the Process Plugin regnum slot.

This change is almost entirely mechnical; the one actual change in
here is to ProcessGDBRemote.cpp's ParseRegisters() which parses the
qXfer:features:read:target.xml response.  As it parses register
definitions from the xml, it will assign sequential numbers as the
eRegisterKindLLDB numbers (the lldb register numberings must be
sequential, without any gaps) and if the xml file specifies register
numbers, those will be used as the eRegisterKindProcessPlugin
register numbers (and those may have gaps).  A J-Link jtag device's
target.xml does contain a gap in register numbers, and it only 
specifies the register numbers for the registers after that gap.
The device supports many different ARM boards and probably selects
different part of its register file as appropriate.

http://reviews.llvm.org/D12791
<rdar://problem/22623262> 

llvm-svn: 247741
2015-09-15 23:20:34 +00:00
Mohit K. Bhakkad a73239f860 [LLDB][MIPS] MIPS load/store instruction emulation for hardware watchpoints
Reviewers: clayborg.
Subscribers: jaydeep, bhushan, sagar, nitesh.jain, lldb-commits.
Differential Revision: http://reviews.llvm.org/D12670

llvm-svn: 247129
2015-09-09 10:17:58 +00:00
Bruce Mitchener db25a7a245 [cmake] Remove LLVM_NO_RTTI.
Summary:
This doesn't exist in other LLVM projects any longer and doesn't
do anything.

Reviewers: chaoren, labath

Subscribers: emaste, tberghammer, lldb-commits, danalbert

Differential Revision: http://reviews.llvm.org/D12586

llvm-svn: 246749
2015-09-03 08:46:55 +00:00
Sagar Thakur 66089382d9 [MIPS64] Emulate MSA branch instructions
This patch adds MSA branch instruction emulation for MIPS64.

Reviewers: tberghammer, jaydeep
Subscribers: tberghammer, lldb-commits, nitesh.jain, mohit.bhakkad (Mohit Bhakkad), bhushan (Bhushan Attarde)
Differential: http://reviews.llvm.org/D12356
llvm-svn: 246745
2015-09-03 03:57:44 +00:00
Tamas Berghammer f5d3e66bf5 Fix assertion failure caused by r245546
Change the way EmulateInstruction::eContextPopRegisterOffStack handled
in UnwindAssemblyInstEmulation::WriteRegister to accomodate for
additional cases when eContextPopRegisterOffStack (pop PC/FLAGS).

llvm-svn: 245690
2015-08-21 10:49:09 +00:00
Tamas Berghammer 99c40e673a Improve instruction emulation based stack unwinding
On ARM there is no difference petween a pop and a load instruction so
a register can be loaded multiple times during the function. Add check
to threat the load as a restore only if it do the restore from the
same location where the register was saved.

Differential revision: http://reviews.llvm.org/D11947

llvm-svn: 245546
2015-08-20 09:09:01 +00:00
Sagar Thakur 789da6678e [LLDB][MIPS] Fix offsets of all register sets and add MSA regset and FRE=1 mode support
This patch :

- Fixes offsets of all register sets for Mips.
- Adds MSA register set and FRE=1 mode support for FP register set.
- Separates lldb register numbers and register infos of freebsd/mips64 from linux/mips64.
- Re-orders the register numbers of all kinds for mips to be consistent with freebsd order of register numbers.

Reviewers: jaydeep, clayborg, jasonmolenda, ovyalov, emaste
Subscribers: tberghammer, ovyalov, emaste, mohit.bhakkad, nitesh.jain, bhushan
Differential: http://reviews.llvm.org/D10919
llvm-svn: 245217
2015-08-17 13:40:17 +00:00
Jaydeep Patil 831435042e [LLDB][MIPS] Handle false positives for MIPS hardware watchpoints
SUMMARY:
    Last 3bits of the watchpoint address are masked by the kernel. For example, n is 
    at 0x120010d00 and m is 0x120010d04. When a watchpoint is set at m, then watch 
    exception is generated even when n is read/written. To handle this case, instruction 
    at PC is emulated to find the base address of the load/store instruction. This address 
    is then appended to the description of the stop-info packet. Client then reads this 
    information to check whether the user has set a watchpoint on this address.
    
    Reviewers: jingham, clayborg
    Subscribers: nitesh.jain, mohit.bhakkad, sagar, bhushan and lldb-commits
    Differential Revision: http://reviews.llvm.org/D11672

llvm-svn: 244864
2015-08-13 03:44:09 +00:00
Oleksiy Vyalov 9dcdd2ee03 Revert r244308 since it's introducing test regressions on Linux:
- TestLldbGdbServer.py both clang & gcc, i386 and x86_64
 - TestConstVariables.py gcc, i386 and x86_64
 - 112 failures clang, i386

llvm-svn: 244514
2015-08-10 21:49:50 +00:00
Sagar Thakur d754890047 [LLDB][MIPS] Fix offsets of all register sets and add MSA regset and FRE=1 mode support
This change :

    - Fixes offsets of all register sets for Mips.
    - Adds MSA register set and FRE=1 mode support for FP register set.
    - Separates lldb register numbers and register infos of freebsd/mips64 from linux/mips64.
    - Re-orders the register numbers of all kinds for mips to be consistent with freebsd order of register numbers.
    - Eliminates ENABLE_128_BIT_SUPPORT and union ValueData from Scalar.cpp and uses llvm::APInt and llvm::APFloat for all integer and floating point types.

Reviewers : emaste, jaydeep, clayborg
Subscribers : emaste, mohit.bhakkad, nitesh.jain, bhushan
Differential : http://reviews.llvm.org/D10919

llvm-svn: 244308
2015-08-07 06:39:38 +00:00
Tamas Berghammer e3a182c052 Fix read/write context in EmulateInstructionARM strd/ldrd
llvm-svn: 243521
2015-07-29 15:15:42 +00:00
Tamas Berghammer e98e3f6325 Remove non-utf-8 characters from EmulateInstructionARM
llvm-svn: 243520
2015-07-29 15:14:37 +00:00
Greg Clayton 06cdc198fe Fix warnings related to virtual functions not being marked as override.
llvm-svn: 242918
2015-07-22 18:16:05 +00:00
Tamas Berghammer c7959f7c69 Improve aarch64 instruction emulation
* Add emulation for STR/LDR immediate instructions
* Cleanup existing emulation code

llvm-svn: 242671
2015-07-20 13:52:50 +00:00
Tamas Berghammer 022622f1d4 Improve conditional opcode handling in emulation based unwinding
Don't chane the CFI information when a conditional instruction
is emulated (eg.: popeq {r0, pc}) because the CFI for the next
instruction should be the same as the CFI for the current instruction.

Differential revision: http://reviews.llvm.org/D11258

llvm-svn: 242519
2015-07-17 11:44:14 +00:00
Jaydeep Patil 501a781998 [LLDB][MIPS] Detect MIPS application specific extensions like micromips
SUMMARY:
    The patch detects MIPS application specific extensions (ASE) like micromips by reading 
    ELF header.e_flags and SHT_MIPS_ABIFLAGS section. MIPS triple does not contain ASE 
    information like micromips, mips16, DSP, MSA etc. These can be read from header.e_flags 
    or SHT_MIPS_ABIFLAGS section.
    
    Reviewers: clayborg
    Subscribers: mohit.bhakkad, sagar, lldb-commits
    Differential Revision: http://reviews.llvm.org/D11133

llvm-svn: 242381
2015-07-16 03:51:55 +00:00
Keno Fischer 2069de9813 [Makefiles] Align library names with CMake build
Summary: This aligns the library names used by the Makefile build to be the same as those create by the CMake build to make switching between the two easier. The only major difficulty was lldbHost which was one library in the CMake system and several in the Makefile system. Most of the other changes are trivial renames.

Reviewers: labath

Subscribers: emaste, tberghammer, lldb-commits

Differential Revision: http://reviews.llvm.org/D11154

llvm-svn: 242196
2015-07-14 20:25:19 +00:00
Tamas Berghammer 67ec5458a7 Add branch emulation to aarch64 instruction emulator
The emulation of the branches are required by the new stack
unwinding logic to reinstantiate the prologue at the right place.

Differential revision: http://reviews.llvm.org/D10702

llvm-svn: 240769
2015-06-26 09:41:32 +00:00
Ed Maste ff666dcbef Remove unused variable
llvm-svn: 240547
2015-06-24 15:27:35 +00:00
Tamas Berghammer 44ff9ccede Improve instruction emulation based stack unwinding on ARM
* Add and fix the emulation of several instruction.
* Disable frame pointer usage on Android.
* Specify return address register for the unwind plan instead of explict
  tracking the value of RA.
* Replace prologue detection heuristics (unreliable in several cases)
  with a logic to follow the branch instructions and restore the CFI
  value based on them. The target address for a branch should have the
  same CFI as the source address (if they are in the same function).
* Handle symbols in ELF files where the symbol size is not specified
  with calcualting their size based on the next symbol (already done
  in MachO files).
* Fix architecture in FuncUnwinders with filling up the inforamtion
  missing from the object file with the architecture of the target.
* Add code to read register wehn the value is set to "IsSame" as it
  meanse the value of a register in the parent frame is the same as the
  value in the current frame.

Differential revision: http://reviews.llvm.org/D10447

llvm-svn: 240533
2015-06-24 11:27:32 +00:00
Jaydeep Patil c60c94528c [LLDB][MIPS] MIPS32 branch emulation and single-stepping
SUMMARY:
    This patch implements
      1. Emulation of MIPS32 branch instructions
      2. Enable single-stepping for MIPS32 instructions
      3. Correction in emulation of MIPS64 branch instructions with delay slot
      4. Adjust breakpoint address when breakpoint is hit in a forbidden slot of compact branch instruction
    
    Reviewers: clayborg
    Subscribers: mohit.bhakkad, sagar, bhushan, lldb-commits, emaste, nitesh.jain
    Differential Revision: http://reviews.llvm.org/D10596

llvm-svn: 240373
2015-06-23 03:37:08 +00:00
Jaydeep Patil 30952b200b Test Commit
llvm-svn: 240280
2015-06-22 13:58:30 +00:00
Mohit K. Bhakkad 58975e82d4 A correction in rL239996
llvm-svn: 239998
2015-06-18 07:12:25 +00:00
Mohit K. Bhakkad 276a930eda [LLDB][MIPS] Emulation of MIPS64 floating-point branch instructions
Patch by Jaydeep Patil

SUMMARY:
1. Added emulation of MIPS64 floating-point branch instructions
2. Updated GetRegisterInfo to recognize floating-point registers
3. Provided CPU information while creating createMCSubtargetInfo in disassembler
4. Bug fix in emulation of JIC and JIALC
5. Correct identification of breakpoint when set in a delay slot of a branch instruction

Reviewers: clayborg
Subscribers: bhushan, mohit.bhakkad, sagar, nitesh.jain, lldb-commits.
Differential Revision: http://reviews.llvm.org/D10355

llvm-svn: 239996
2015-06-18 06:03:27 +00:00