Fix examples/lookup/main.cpp.

Patch to fix the main.cpp compile error submitted by Dmitry Vyukov <dvyukov@google.com>.
Also add a Makefile, plus some modification to main.cpp.

llvm-svn: 150990
This commit is contained in:
Johnny Chen 2012-02-20 21:39:21 +00:00
parent 6ecb6a6b7f
commit 216d93a6a7
2 changed files with 34 additions and 14 deletions

View File

@ -0,0 +1,13 @@
LEVEL = ../../test/make
CXX_SOURCES := main.cpp
MY_OS = $(shell uname -s)
ifeq "$(MY_OS)" "Darwin"
LD_EXTRAS ?= -framework LLDB
FRAMEWORK_INCLUDES=-F/Volumes/data/lldb/svn/trunk/build/Debug
else
LD_EXTRAS ?= $(LLDB_BUILD_DIR)/_lldb.so
endif
include $(LEVEL)/Makefile.rules

View File

@ -10,15 +10,15 @@
#include <stdint.h>
#include <stdlib.h>
#include "lldb/API/SBBlock.h"
#include "lldb/API/SBCompileUnit.h"
#include "lldb/API/SBDebugger.h"
#include "lldb/API/SBFunction.h"
#include "lldb/API/SBModule.h"
#include "lldb/API/SBSymbol.h"
#include "lldb/API/SBTarget.h"
#include "lldb/API/SBThread.h"
#include "lldb/API/SBProcess.h"
#include "LLDB/SBBlock.h"
#include "LLDB/SBCompileUnit.h"
#include "LLDB/SBDebugger.h"
#include "LLDB/SBFunction.h"
#include "LLDB/SBModule.h"
#include "LLDB/SBSymbol.h"
#include "LLDB/SBTarget.h"
#include "LLDB/SBThread.h"
#include "LLDB/SBProcess.h"
using namespace lldb;
@ -29,6 +29,14 @@ using namespace lldb;
// and find all symbol context objects (if any) for that address:
// compile unit, function, deepest block, line table entry and the
// symbol.
//
// To build the program, type (while in this directory):
//
// $ make
//
// then:
//
// $ DYLD_FRAMEWORK_PATH=/Volumes/data/lldb/svn/ToT/build/Debug ./a.out executable_path file_address
//----------------------------------------------------------------------
int
main (int argc, char const *argv[])
@ -44,9 +52,6 @@ main (int argc, char const *argv[])
// The second argument in the address that we want to lookup
lldb::addr_t file_addr = strtoull (argv[2], NULL, 0);
// Make a file spec out of our executable path
SBFileSpec exe_file_spec (exe_file_path);
// Create a debugger instance so we can create a target
SBDebugger debugger (SBDebugger::Create());
@ -57,12 +62,14 @@ main (int argc, char const *argv[])
if (target.IsValid())
{
// Find the executable module so we can do a lookup inside it
SBFileSpec exe_file_spec (exe_file_path, true);
SBModule module (target.FindModule (exe_file_spec));
SBAddress addr;
// Take a file virtual address and resolve it to a section offset
// address that can be used to do a symbol lookup by address
if (module.ResolveFileAddress (file_addr, addr))
SBAddress addr = module.ResolveFileAddress (file_addr);
if (addr.IsValid())
{
// We can resolve a section offset address in the module
// and only ask for what we need. You can logical or together