Greg Clayton | 0996003 | 2010-09-10 18:31:35 +0000 | [diff] [blame^] | 1 | //===-- main.cpp ------------------------------------------------*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #include <stdint.h> |
| 11 | #include <stdlib.h> |
| 12 | |
| 13 | #include "lldb/API/SBBlock.h" |
| 14 | #include "lldb/API/SBCompileUnit.h" |
| 15 | #include "lldb/API/SBDebugger.h" |
| 16 | #include "lldb/API/SBFunction.h" |
| 17 | #include "lldb/API/SBModule.h" |
| 18 | #include "lldb/API/SBSymbol.h" |
| 19 | #include "lldb/API/SBTarget.h" |
| 20 | #include "lldb/API/SBThread.h" |
| 21 | #include "lldb/API/SBProcess.h" |
| 22 | |
| 23 | using namespace lldb; |
| 24 | |
| 25 | //---------------------------------------------------------------------- |
| 26 | // This quick sample code shows how to create a debugger instance and |
| 27 | // create an "i386" executable target. Then we can lookup the executable |
| 28 | // module and resolve a file address into a section offset address, |
| 29 | // and find all symbol context objects (if any) for that address: |
| 30 | // compile unit, function, deepest block, line table entry and the |
| 31 | // symbol. |
| 32 | //---------------------------------------------------------------------- |
| 33 | int |
| 34 | main (int argc, char const *argv[]) |
| 35 | { |
| 36 | // Initialize LLDB |
| 37 | SBDebugger::Initialize(); |
| 38 | |
| 39 | if (argc < 3) |
| 40 | exit (1); |
| 41 | |
| 42 | // The first argument is the file path we want to look something up in |
| 43 | const char *exe_file_path = argv[1]; |
| 44 | // The second arguemnt in the address that we want to lookup |
| 45 | lldb::addr_t file_addr = strtoull (argv[2], NULL, 0); |
| 46 | |
| 47 | // Make a file spec out of our executable path |
| 48 | SBFileSpec exe_file_spec (exe_file_path); |
| 49 | |
| 50 | // Create a debugger instance so we can create a target |
| 51 | SBDebugger debugger (SBDebugger::Create()); |
| 52 | |
| 53 | if (debugger.IsValid()) |
| 54 | { |
| 55 | // Create a target using the executable. |
| 56 | SBTarget target (debugger.CreateTargetWithFileAndArch (exe_file_path, "i386")); |
| 57 | if (target.IsValid()) |
| 58 | { |
| 59 | // Find the executable module so we can do a lookup inside it |
| 60 | SBModule module (target.FindModule (exe_file_spec)); |
| 61 | SBAddress addr; |
| 62 | |
| 63 | // Take a file virtual address and resolve it to a section offset |
| 64 | // address that can be used to do a symbol lookup by address |
| 65 | if (module.ResolveFileAddress (file_addr, addr)) |
| 66 | { |
| 67 | // We can resolve a section offset address in the module |
| 68 | // and only ask for what we need. You can logical or together |
| 69 | // bits from the SymbolContextItem enumeration found in |
| 70 | // lldb-enumeration.h to request only what you want. Here we |
| 71 | // are asking for everything. |
| 72 | // |
| 73 | // NOTE: the less you ask for, the less LLDB will parse as |
| 74 | // LLDB does partial parsing on just about everything. |
| 75 | SBSymbolContext symbol_context (module.ResolveSymbolContextForAddress (addr, eSymbolContextEverything)); |
| 76 | |
| 77 | SBCompileUnit comp_unit (symbol_context.GetCompileUnit()); |
| 78 | if (comp_unit.IsValid()) |
| 79 | { |
| 80 | } |
| 81 | SBFunction function (symbol_context.GetFunction()); |
| 82 | if (function.IsValid()) |
| 83 | { |
| 84 | } |
| 85 | SBBlock block (symbol_context.GetBlock()); |
| 86 | if (block.IsValid()) |
| 87 | { |
| 88 | } |
| 89 | SBLineEntry line_entry (symbol_context.GetLineEntry()); |
| 90 | if (line_entry.IsValid()) |
| 91 | { |
| 92 | } |
| 93 | SBSymbol symbol (symbol_context.GetSymbol()); |
| 94 | if (symbol.IsValid()) |
| 95 | { |
| 96 | } |
| 97 | } |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | // Terminate LLDB |
| 102 | SBDebugger::Terminate(); |
| 103 | return 0; |
| 104 | } |
| 105 | |