llvm-6502/include/llvm
Reid Kleckner 2763217fbd Implement the JIT side of the GDB JIT debugging interface. To enable this
feature, either build the JIT in debug mode to enable it by default or pass
-jit-emit-debug to lli.

Right now, the only debug information that this communicates to GDB is call
frame information, since it's already being generated to support exceptions in
the JIT.  Eventually, when DWARF generation isn't tied so tightly to AsmPrinter,
it will be easy to push that information to GDB through this interface.

Here's a step-by-step breakdown of how the feature works:

- The JIT generates the machine code and DWARF call frame info
  (.eh_frame/.debug_frame) for a function into memory.
- The JIT copies that info into an in-memory ELF file with a symbol for the
  function.
- The JIT creates a code entry pointing to the ELF buffer and adds it to a
  linked list hanging off of a global descriptor at a special symbol that GDB
  knows about.
- The JIT calls a function marked noinline that GDB knows about and has put an
  internal breakpoint in.
- GDB catches the breakpoint and reads the global descriptor to look for new
  code.
- When sees there is new code, it reads the ELF from the inferior's memory and
  adds it to itself as an object file.
- The JIT continues, and the next time we stop the program, we are able to
  produce a proper backtrace.

Consider running the following program through the JIT:

#include <stdio.h>
void baz(short z) {
  long w = z + 1;
  printf("%d, %x\n", w, *((int*)NULL));  // SEGFAULT here
}
void bar(short y) {
  int z = y + 1;
  baz(z);
}
void foo(char x) {
  short y = x + 1;
  bar(y);
}
int main(int argc, char** argv) {
  char x = 1;
  foo(x);
}

Here is a backtrace before this patch:
Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x2aaaabdfbd10 (LWP 25476)]
0x00002aaaabe7d1a8 in ?? ()
(gdb) bt
#0  0x00002aaaabe7d1a8 in ?? ()
#1  0x0000000000000003 in ?? ()
#2  0x0000000000000004 in ?? ()
#3  0x00032aaaabe7cfd0 in ?? ()
#4  0x00002aaaabe7d12c in ?? ()
#5  0x00022aaa00000003 in ?? ()
#6  0x00002aaaabe7d0aa in ?? ()
#7  0x01000002abe7cff0 in ?? ()
#8  0x00002aaaabe7d02c in ?? ()
#9  0x0100000000000001 in ?? ()
#10 0x00000000014388e0 in ?? ()
#11 0x00007fff00000001 in ?? ()
#12 0x0000000000b870a2 in llvm::JIT::runFunction (this=0x1405b70,
F=0x14024e0, ArgValues=@0x7fffffffe050)
   at /home/rnk/llvm-gdb/lib/ExecutionEngine/JIT/JIT.cpp:395
#13 0x0000000000baa4c5 in llvm::ExecutionEngine::runFunctionAsMain
(this=0x1405b70, Fn=0x14024e0, argv=@0x13f06f8, envp=0x7fffffffe3b0)
   at /home/rnk/llvm-gdb/lib/ExecutionEngine/ExecutionEngine.cpp:377
#14 0x00000000007ebd52 in main (argc=2, argv=0x7fffffffe398,
envp=0x7fffffffe3b0) at /home/rnk/llvm-gdb/tools/lli/lli.cpp:208

And a backtrace after this patch:
Program received signal SIGSEGV, Segmentation fault.
0x00002aaaabe7d1a8 in baz ()
(gdb) bt
#0  0x00002aaaabe7d1a8 in baz ()
#1  0x00002aaaabe7d12c in bar ()
#2  0x00002aaaabe7d0aa in foo ()
#3  0x00002aaaabe7d02c in main ()
#4  0x0000000000b870a2 in llvm::JIT::runFunction (this=0x1405b70,
F=0x14024e0, ArgValues=...)
   at /home/rnk/llvm-gdb/lib/ExecutionEngine/JIT/JIT.cpp:395
#5  0x0000000000baa4c5 in llvm::ExecutionEngine::runFunctionAsMain
(this=0x1405b70, Fn=0x14024e0, argv=..., envp=0x7fffffffe3c0)
   at /home/rnk/llvm-gdb/lib/ExecutionEngine/ExecutionEngine.cpp:377
#6  0x00000000007ebd52 in main (argc=2, argv=0x7fffffffe3a8,
envp=0x7fffffffe3c0) at /home/rnk/llvm-gdb/tools/lli/lli.cpp:208


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@82418 91177308-0d34-0410-b5e6-96231b3b80d8
2009-09-20 23:52:43 +00:00
..
ADT write rfind in terms of npos as daniel requested 2009-09-20 22:54:26 +00:00
Analysis Prefer super class constructor to explicit initialization. 2009-09-19 20:40:28 +00:00
Assembly Use MemoryBuffer::getBufferIdentifier() in the AsmPrinter instead 2009-09-08 22:20:35 +00:00
Bitcode Write and read metadata attachments. 2009-09-18 19:26:43 +00:00
CodeGen A few more tabs -> spaces. 2009-09-20 04:03:25 +00:00
CompilerDriver Distinguish between 'empty' and empty DAG marker. 2009-09-10 16:22:02 +00:00
Config re-apply r80197, now that iterator.h is not mentioned any more 2009-08-27 17:07:35 +00:00
Debugger Prune #includes from llvm/Linker.h and llvm/System/Path.h, 2009-08-23 22:45:37 +00:00
ExecutionEngine This void is implicit in C++. 2009-08-12 22:10:57 +00:00
MC Allow symbols to start from the digit if target requests it. This allows, e.g. pinning 2009-09-18 16:57:42 +00:00
Support smallvectorize getExtraOptionNames 2009-09-20 06:21:43 +00:00
System Get rid of GetProcessId in Win32/Program.inc. 2009-09-15 03:39:45 +00:00
Target Implement the JIT side of the GDB JIT debugging interface. To enable this 2009-09-20 23:52:43 +00:00
Transforms Add a new pass for doing late hoisting of floating-point and vector 2009-09-16 20:25:11 +00:00
AbstractTypeUser.h When a constant's type is refined, update the constant in place 2009-09-15 15:58:07 +00:00
Argument.h Initial update to VMCore to use Twines for string arguments. 2009-07-25 04:41:11 +00:00
Attributes.h Add an 'inline hint' attribute to represent source 2009-08-26 01:08:21 +00:00
AutoUpgrade.h Reapply 79977. 2009-08-28 23:24:31 +00:00
BasicBlock.h Add a comment. 2009-09-02 01:14:16 +00:00
CallGraphSCCPass.h Fix some nasty callgraph dangling pointer problems in 2009-08-31 00:19:58 +00:00
CallingConv.h
CMakeLists.txt
Constant.h Make LLVMContext and LLVMContextImpl classes instead of structs. 2009-08-11 17:45:13 +00:00
Constants.h Remove the default value for ConstantStruct::get's isPacked parameter and 2009-09-19 20:30:26 +00:00
DerivedTypes.h Actually privatize a IntegerTypes, and fix a few bugs exposed by this. 2009-08-13 23:27:32 +00:00
Function.h Retype from unsigned to CallingConv::ID accordingly. Approved by Bob Wilson. 2009-09-02 08:44:58 +00:00
GlobalAlias.h Public and private corrections, warned about by icc (#304). 2009-09-06 08:55:57 +00:00
GlobalValue.h Finish migrating VMCore to StringRef/Twine based APIs. 2009-07-25 06:02:13 +00:00
GlobalVariable.h Public and private corrections, warned about by icc (#304). 2009-09-06 08:55:57 +00:00
InlineAsm.h Finish migrating VMCore to StringRef/Twine based APIs. 2009-07-25 06:02:13 +00:00
InstrTypes.h Reappy r80998, now that the GlobalOpt bug that it exposed on MiniSAT is fixed. 2009-09-07 23:54:19 +00:00
Instruction.def
Instruction.h Rename Instruction::isIdenticalTo to Instruction::isIdenticalToWhenDefined, 2009-08-25 22:11:20 +00:00
Instructions.h Update malloc call creation code (AllocType is now the element type of the malloc, not the resulting type). 2009-09-18 19:20:02 +00:00
IntrinsicInst.h Reapply 79977. 2009-08-28 23:24:31 +00:00
Intrinsics.h Make LLVMContext and LLVMContextImpl classes instead of structs. 2009-08-11 17:45:13 +00:00
Intrinsics.td Reapply 79977. 2009-08-28 23:24:31 +00:00
IntrinsicsAlpha.td
IntrinsicsARM.td Add new intrinsics for Neon vldN_lane and vstN_lane operations. 2009-08-22 02:28:46 +00:00
IntrinsicsBlackfin.td Remove unneeded intrinsics from Blackfin backend. 2009-08-02 21:49:05 +00:00
IntrinsicsCellSPU.td
IntrinsicsPowerPC.td
IntrinsicsX86.td Add sse4.2 string/text processing intrinsics. We'll select these later. 2009-08-14 20:27:57 +00:00
IntrinsicsXCore.td
LinkAllPasses.h Add a new pass for doing late hoisting of floating-point and vector 2009-09-16 20:25:11 +00:00
LinkAllVMCore.h Push LLVMContexts through the IntegerType APIs. 2009-08-13 21:58:54 +00:00
Linker.h Prune #includes from llvm/Linker.h and llvm/System/Path.h, 2009-08-23 22:45:37 +00:00
LLVMContext.h Add llvm::Metadata to manage metadata used in a context. 2009-09-16 18:09:00 +00:00
Metadata.h Write and read metadata attachments. 2009-09-18 19:26:43 +00:00
Module.h remove the std::ostream version of module and type printing. 2009-08-23 04:52:46 +00:00
ModuleProvider.h
OperandTraits.h Public and private corrections, warned about by icc (#304). 2009-09-06 08:55:57 +00:00
Operator.h Reappy r80998, now that the GlobalOpt bug that it exposed on MiniSAT is fixed. 2009-09-07 23:54:19 +00:00
Pass.h Fix a typo in a comment. 2009-09-01 18:29:01 +00:00
PassAnalysisSupport.h
PassManager.h
PassManagers.h make -debug-pass=Executions show information about what call graph nodes 2009-09-15 05:03:04 +00:00
PassSupport.h Remove some unused fields. 2009-08-29 23:34:14 +00:00
SymbolTableListTraits.h
Type.h Clean up the minor mess I caused with removing iterator.h. I shall take care of 80-col violations and the FIXME later. (Thanks goodness that I live in another continent, so the monkeypox did not strike me :-) 2009-08-27 06:41:46 +00:00
TypeSymbolTable.h Don't search the entire type table just to delete a type by name. 2009-08-06 06:04:35 +00:00
Use.h eliminate all 80-col violations that I have introduced in my recent checkins (and some others more) 2009-08-27 23:44:33 +00:00
User.h
Value.h Add llvm::Metadata to manage metadata used in a context. 2009-09-16 18:09:00 +00:00
ValueSymbolTable.h revert r78048, it isn't worth using assertingvh here. 2009-08-04 23:07:12 +00:00