Commit Graph

34 Commits

Author SHA1 Message Date
Ewan Crawford 90ff791141 Expression evaluation, a new ThreadPlanCallFunctionUsingABI for executing a function call on target via register manipulation
For Hexagon we want to be able to call functions during debugging, however currently lldb only supports this when there is JIT support. 
Although emulation using IR interpretation is an alternative, it is currently limited in that it can't make function calls.

In this patch we have extended the IR interpreter so that it can execute a function call on the target using register manipulation. 
To do this we need to handle the Call IR instruction, passing arguments to a new thread plan and collecting any return values to pass back into the IR interpreter. 

The new thread plan is needed to call an alternative ABI interface of "ABI::PerpareTrivialCall()", allowing more detailed information about arguments and return values.

Reviewers: jingham, spyffe

Subscribers: emaste, lldb-commits, ted, ADodds, deepak2427

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

llvm-svn: 242137
2015-07-14 10:56:58 +00:00
Zachary Turner 3ddcd314f2 Dont' use a random probe & alloc strategy for the IRMemoryMap.
The current strategy for host allocation is to choose a random
address and attempt to allocate there, eventually failing if the
allocation cannot be satisfied.

The C standard only guarantees that RAND_MAX >= 32767, so for
platforms that use a very small RAND_MAX allocations will fail
with very high probability.  On such platforms (Windows is one),
you can reproduce this trivially by running lldb, typing "expr (3)"
and then hitting enter you see a failure.  Failures generally
happen with a frequency of about 1 failure every 5 evaluations.

There is no good reason that allocations need to look like "real"
pointers, so this patch changes the allocation scheme to simply
jump straight to the end and grab a free chunk of memory.

Reviewed By: Sean Callanan

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

llvm-svn: 212630
2014-07-09 16:42:27 +00:00
Sylvestre Ledru ceab3ac375 remove trailing whitespace + remove some useless comments
llvm-svn: 212411
2014-07-06 17:54:58 +00:00
Todd Fiala af245d115b Add lldb-gdbserver support for Linux x86_64.
This change brings in lldb-gdbserver (llgs) specifically for Linux x86_64.
(More architectures coming soon).

Not every debugserver option is covered yet.  Currently
the lldb-gdbserver command line can start unattached,
start attached to a pid (process-name attach not supported yet),
or accept lldb attaching and launching a process or connecting
by process id.

The history of this large change can be found here:
https://github.com/tfiala/lldb/tree/dev-tfiala-native-protocol-linux-x86_64

Until mid/late April, I was not sharing the work and continued
to rebase it off of head (developed via id tfiala@google.com).  I switched over to
user todd.fiala@gmail.com in the middle, and once I went to github, I did
merges rather than rebasing so I could share with others.

llvm-svn: 212069
2014-06-30 21:05:18 +00:00
Zachary Turner cfcd7914da Fix silly compilation error.
llvm-svn: 211728
2014-06-25 18:40:58 +00:00
Zachary Turner 1536244594 Fix a bug in the IRMemoryMap which generated bogus allocations.
Previously, only the starting locations of the candidate interval
and the existing interval were compared.  To correctly detect
range intersections, it is necessary to compare the entire range
of both intervals against each other.

Reviewed by: scallanan

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

llvm-svn: 211726
2014-06-25 18:37:19 +00:00
Greg Clayton 23f8c95a44 JITed functions can now have debug info and be debugged with debug and source info:
(lldb) b puts
(lldb) expr -g -i0 -- (int)puts("hello")

First we will stop at the entry point of the expression before it runs, then we can step over a few times and hit the breakpoint in "puts", then we can continue and finishing stepping and fininsh the expression.

Main features:
- New ObjectFileJIT class that can be easily created for JIT functions
- debug info can now be enabled when parsing expressions
- source for any function that is run throught the JIT is now saved in LLDB process specific temp directory and cleaned up on exit
- "expr -g --" allows you to single step through your expression function with source code

<rdar://problem/16382881>

llvm-svn: 204682
2014-03-24 23:10:19 +00:00
Sean Callanan 9bbf3cd3d7 Hardened against reads in the IRMemoryMap that
exceed the bounds of the backing memory.

<rdar://problem/16088322>

llvm-svn: 202899
2014-03-04 21:56:11 +00:00
Virgile Bello b2f1fb2943 MingW compilation (windows). Includes various refactoring to improve portability.
llvm-svn: 189107
2013-08-23 12:44:05 +00:00
Michael Sartain 6fea779c29 Initialize m_leak member variable.
llvm-svn: 187822
2013-08-06 22:21:08 +00:00
Sean Callanan 70cac8fd81 Remove the process's reservation cache and don't
bother checking if a region is safe to use.  In
cases where regions need to be synthesized rather
than properly allocated, the memory reads required
to determine whether the area is used are

- insufficient, because intermediate locations
  could be in use, and

- unsafe, because on some platforms reading from
  memory can trigger events.

All this only makes a difference on platforms
where memory allocation in the target is impossible.
Behavior on platforms where it is possible should
stay the same.

<rdar://problem/14023970>

llvm-svn: 185046
2013-06-27 00:10:26 +00:00
Sean Callanan ad7cc466d7 Fixed a problem in the expression parser that
caused the IR interpreter not to work if the
process had finished running.

<rdar://problem/14124301>

llvm-svn: 184125
2013-06-17 21:19:31 +00:00
Greg Clayton e86cef633b Fixed printf build warning.
llvm-svn: 183250
2013-06-04 21:30:42 +00:00
Matt Kopec ef14371d3f Fix various build warnings.
llvm-svn: 183140
2013-06-03 18:00:07 +00:00
Sean Callanan fbf5c682cb Fixed a bug where persistent variables did not
live as long as they needed to.  This led to
equality tests involving persistent variables
often failing or succeeding when they had no
business doing so.

To do this, I introduced the ability for a
memory allocation to "leak" - that is, to
persist in the process beyond the lifetime of
the expression.  Hand-declared persistent
variables do this now.

<rdar://problem/13956311>

llvm-svn: 182528
2013-05-22 22:49:06 +00:00
Sean Callanan bb77704cd1 Added a per-process cache for reserved memory
regions that aren't actually allocated in the
process.  This cache is used by the expression
parser if the underlying process doesn't support
memory allocation, to avoid needless repeated
searches for unused address ranges.

Also fixed a silly bug in IRMemoryMap where it
would continue searching even after it found a
valid region.

<rdar://problem/13866629>

llvm-svn: 182028
2013-05-16 17:30:37 +00:00
Jim Ingham 5c42d8a87c Fixed a few obvious errors pointed out by the static analyzer.
llvm-svn: 181911
2013-05-15 18:27:08 +00:00
Sean Callanan df56540a58 Performance optimizations to ClangUserExpression,
mostly related to management of the stack frame
for the interpreter.

  - First, if the expression can be interpreted,
    allocate the stack frame in the target process
    (to make sure pointers are valid) but only
    read/write to the copy in the host's memory.

  - Second, keep the memory allocations for the
    stack frame and the materialized struct as
    member variables of ClangUserExpression.  This
    avoids memory allocations and deallocations
    each time the expression runs.

<rdar://problem/13043685>

llvm-svn: 180664
2013-04-27 02:19:33 +00:00
Matt Kopec 750dcc3323 Change Malloc to request an aligned memory size.
This fixes a problem on Linux where allocated memory would get overun in some use cases (ie. in TestExprs2.py).

llvm-svn: 180614
2013-04-26 17:48:01 +00:00
Sean Callanan d2562509a5 Simplified the management of the data buffer for
an Allocation to reduce heap fragmentation and
make the code less brittle (and to make some
buildbots happier).

llvm-svn: 179868
2013-04-19 17:44:40 +00:00
Sean Callanan 7d71e5677e Reverted 179810, which breaks the expression
parser.

llvm-svn: 179832
2013-04-19 02:42:00 +00:00
Sean Callanan bb9945f447 Made IRMemoryMap::FindSpace a little cleverer,
and made attempts to allocate memory in the process
fall back to FindSpace and just allocate memory on
the host (but with real-looking pointers, hence
FindSpace) if the process doesn't allow allocation.
This allows expressions to run on processes that don't
support allocation, like core files.

This introduces an extremely rare potential problem:
If all of the following are true:

- The Process doesn't support allocation;

- the user writes an expression that refers to an
  address that does not yet map to anything, or is
  dynamically generated (e.g., the result of calling
  a function); and

- the randomly-selected address for the static data
  for that specific expression runs into the
  address the user was expecting to work with;

then dereferencing the pointer later results
in the user seeing something unexpected.  This is
unlikely but possible; as a future piece of work,
we should have processes be able to hint to the
expression parser where it can allocate temporary data
of this kind.

llvm-svn: 179827
2013-04-19 01:51:24 +00:00
Greg Clayton d850685e01 Try and unblock issue found in: http://lab.llvm.org:8011/builders/lldb-x86_64-linux/builds/3564
llvm-svn: 179810
2013-04-18 22:59:51 +00:00
Sean Callanan 1582ee6840 This commit changes the way LLDB executes user
expressions.  

Previously, ClangUserExpression assumed that if
there was a constant result for an expression 
then it could be determined during parsing.  In
particular, the IRInterpreter ran while parser
state (in particular, ClangExpressionDeclMap) 
was present.  This approach is flawed, because
the IRInterpreter actually is capable of using
external variables, and hence the result might
be different each run.  Until now, we papered
over this flaw by re-parsing the expression each
time we ran it.

I have rewritten the IRInterpreter to be 
completely independent of the ClangExpressionDeclMap.
Instead of special-casing external variable lookup,
which ties the IRInterpreter closely to LLDB,
we now interpret the exact same IR that the JIT
would see.  This IR assumes that materialization
has occurred; hence the recent implementation of the
Materializer, which does not require parser state
(in the form of ClangExpressionDeclMap) to be 
present.

Materialization, interpretation, and dematerialization
are now all independent of parsing.  This means that
in theory we can parse expressions once and run them
many times.  I have three outstanding tasks before
shutting this down:

    - First, I will ensure that all of this works with
      core files.  Core files have a Process but do not
      allow allocating memory, which currently confuses
      materialization.

    - Second, I will make expression breakpoint 
      conditions remember their ClangUserExpression and
      re-use it.

    - Third, I will tear out all the redundant code
      (for example, materialization logic in
      ClangExpressionDeclMap) that is no longer used.

While implementing this fix, I also found a bug in
IRForTarget's handling of floating-point constants.  
This should be fixed.

llvm-svn: 179801
2013-04-18 22:06:33 +00:00
Greg Clayton e0c64e15a4 Try to unbreak the lldb-x86_64-linux buildbot after recent std::auto_ptr/std::unique_ptr changes.
llvm-svn: 179799
2013-04-18 22:01:06 +00:00
Sean Callanan 08052afa2d Updated the IRInterpreter to work with an
IRMemoryMap rather than through its own memory
abstraction.  This considerably simplifies the
code, and makes it possible to run the
IRInterpreter multiple times on an already-parsed
expression in the absence of a ClangExpressionDeclMap.

Changes include:

  - ClangExpressionDeclMap's interface methods
    for the IRInterpreter now take IRMemoryMap
    arguments.  They are not long for this world,
    however, since the IRInterpreter will soon be
    working with materialized variables.

  - As mentioned above, removed the Memory class
    from the IR interpreter altogether.  It had a
    few functions that remain useful, such as
    keeping track of Values that have been placed
    in memory, so I moved those into methods on
    InterpreterStackFrame.

  - Changed IRInterpreter to work with lldb::addr_t
    rather than Memory::Region as its primary
    currency.

  - Fixed a bug in the IRMemoryMap where it did not
    report correct address byte size and byte order
    if no process was present, because it was using
    Target::GetDefaultArchitecture() rather than
    Target::GetArchitecture().

  - Made IRMemoryMap methods clear the Errors they
    receive before running.  Having to do this by
    hand is just annoying.

The testsuite seems happy with these changes, but
please let me know if you see problems (especially
in use cases without a process).

llvm-svn: 179675
2013-04-17 07:50:58 +00:00
Sean Callanan 14b1bae5ee Flipped the big switch: LLDB now uses the new
Materializer for all expressions that need to
run in the target.  This includes the following
changes:

- Removed a bunch of (de-)materialization code
  from ClangExpressionDeclMap and assumed the
  presence of a Materializer where we previously
  had a fallback.

- Ensured that an IRMemoryMap is passed into
  ClangExpressionDeclMap::Materialize().

- Fixed object ownership on LLVMContext; it is
  now owned by the IRExecutionUnit, since the
  Module and the ExecutionEngine both depend on
  its existence.

- Fixed a few bugs in IRMemoryMap and the
  Materializer that showed up during testing.

llvm-svn: 179649
2013-04-16 23:25:35 +00:00
Sean Callanan 2d37e5a5a5 Added logging to each entity in the Materializer
to make debugging easier when things go wrong.

llvm-svn: 179576
2013-04-15 22:48:23 +00:00
Sean Callanan c8c5b8dcd7 Fixed a few bugs in IRMemoryMap:
- If an allocation is mirrored between the host
  and the process, update the host's version
  before returning a DataExtractor pointing to
  it.

- If anyone attempts to access memory in a
  process/target that does not have a corresponding
  allocation, try accessing the memory directly
  before erroring out.

llvm-svn: 179561
2013-04-15 21:35:52 +00:00
Sean Callanan b024d87822 Audited the existing Materializer code to ensure
that it works in the absence of a process.  Codepaths
in the Materializer now use the best execution context
scope available to them.

llvm-svn: 179539
2013-04-15 17:12:47 +00:00
Sean Callanan 458ae1c6eb Now that ValueObjects permit writing, made the
Materializer use that API when dematerializing
variables.

llvm-svn: 179443
2013-04-13 02:06:42 +00:00
Sean Callanan f8043fa527 Implemented materialization and dematerialization
for variables in the new Materializer.  This is
much easier now that the ValueObject API is solid.

I still have to implement reading bytes into a
ValueObject, but committing what I have so far.

This code is not yet used, so there will be fixes
when I switch the expression parser over to use the
new Materializer.

llvm-svn: 179416
2013-04-12 21:40:34 +00:00
Sean Callanan 35005f768e Replicated the materialization logic for persistent
variables in the Materializer.  We don't use this
code yet, but will soon once the other materializers
are online.

llvm-svn: 179390
2013-04-12 18:10:34 +00:00
Sean Callanan 5a1af4e63a Factored out memory access into the target process
from IRExecutionUnit into a superclass called
IRMemoryMap.  IRMemoryMap handles all reading and
writing, ensuring that areas are kept track of and
memory is properly cached (and deleted).

Also fixed several cases where we would simply leak
binary data in the target process over time.  Now
the expression objects explicitly own their
IRExecutionUnit and delete it when they go away.  This
is why I had to modify ClangUserExpression,
ClangUtilityFunction, and ClangFunction.

As a side effect of this, I am removing the JIT
mutex for an IRMemoryMap.  If it turns out that we
need this mutex, I'll add it in then, but right now
it's just adding complexity.

This is part of a more general project to make
expressions fully reusable.  The next step is to
make materialization and dematerialization use
the IRMemoryMap API rather than writing and
reading directly from the process's memory. 
This will allow the IR interpreter to use the
same data, but in the host's memory, without having
to use a different set of pointers.

llvm-svn: 178832
2013-04-05 02:22:57 +00:00