Added a new makefile setting that can be set in LLDB makefiles: USE_LIBCPP. This will enable libc++ support.

Improved the makefile "clean" to include deleting all ".d.[0-9]+" files.

Added options to the "lldb/examples/lookup" example and made it build using the LLDB_BUILD_DIR. If this is not set, it will default to "/Applications/Xcode.app/Contents/SharedFrameworks" on Darwin.

Added options to the "lldb/examples/function" example and made it build using the LLDB_BUILD_DIR.

llvm-svn: 183949
This commit is contained in:
Greg Clayton 2013-06-13 21:27:14 +00:00
parent 1d4c540688
commit 1767a73bc8
5 changed files with 186 additions and 44 deletions

View file

@ -2,11 +2,15 @@ LEVEL = ../../test/make
CXX_SOURCES := main.cpp
EXE := lldb-functions
USE_LIBCPP := 1
MY_OS = $(shell uname -s)
CXXFLAGS += -std=gnu++11 -stdlib=libc++
ifeq "$(MY_OS)" "Darwin"
LD_EXTRAS ?= -framework LLDB -Wl,-rpath,/Applications/Xcode.app/Contents/SharedFrameworks
FRAMEWORK_INCLUDES=-F/Applications/Xcode.app/Contents/SharedFrameworks
LLDB_BUILD_DIR ?= /Applications/Xcode.app/Contents/SharedFrameworks
LD_EXTRAS ?= -framework LLDB -Wl,-rpath,"$(LLDB_BUILD_DIR)"
FRAMEWORK_INCLUDES=-F"$(LLDB_BUILD_DIR)"
else
LD_EXTRAS ?= $(LLDB_BUILD_DIR)/_lldb.so
endif

View file

@ -10,7 +10,20 @@
#include <stdint.h>
#include <stdlib.h>
#if defined(__APPLE__)
#include <LLDB/LLDB.h>
#else
#include "LLDB/SBBlock.h"
#include "LLDB/SBCompileUnit.h"
#include "LLDB/SBDebugger.h"
#include "LLDB/SBFunction.h"
#include "LLDB/SBModule.h"
#include "LLDB/SBStream.h"
#include "LLDB/SBSymbol.h"
#include "LLDB/SBTarget.h"
#include "LLDB/SBThread.h"
#include "LLDB/SBProcess.h"
#endif
using namespace lldb;

View file

@ -1,11 +1,15 @@
LEVEL = ../../test/make
CXX_SOURCES := main.cpp
EXE := lldb-lookup
USE_LIBCPP := 1
MY_OS = $(shell uname -s)
ifeq "$(MY_OS)" "Darwin"
LD_EXTRAS ?= -framework LLDB
FRAMEWORK_INCLUDES=-F/Volumes/data/lldb/svn/trunk/build/Debug
LLDB_BUILD_DIR ?= /Applications/Xcode.app/Contents/SharedFrameworks
LD_EXTRAS ?= -framework LLDB -Wl,-rpath,"$(LLDB_BUILD_DIR)"
FRAMEWORK_INCLUDES=-F"$(LLDB_BUILD_DIR)"
else
LD_EXTRAS ?= $(LLDB_BUILD_DIR)/_lldb.so
endif

View file

@ -7,18 +7,27 @@
//
//===----------------------------------------------------------------------===//
#include <getopt.h>
#include <stdint.h>
#include <stdlib.h>
#if defined(__APPLE__)
#include <LLDB/LLDB.h>
#else
#include "LLDB/SBBlock.h"
#include "LLDB/SBCompileUnit.h"
#include "LLDB/SBDebugger.h"
#include "LLDB/SBFunction.h"
#include "LLDB/SBModule.h"
#include "LLDB/SBStream.h"
#include "LLDB/SBSymbol.h"
#include "LLDB/SBTarget.h"
#include "LLDB/SBThread.h"
#include "LLDB/SBProcess.h"
#endif
#include <string>
#include <vector>
using namespace lldb;
@ -50,38 +59,154 @@ public:
SBDebugger::Terminate();
}
};
static struct option g_long_options[] =
{
{ "help", no_argument, NULL, 'h' },
{ "verbose", no_argument, NULL, 'v' },
{ "arch", required_argument, NULL, 'a' },
{ "platform", required_argument, NULL, 'p' },
{ NULL, 0, NULL, 0 }
};
#define PROGRAM_NAME "lldb-lookup"
void
usage ()
{
puts (
"NAME\n"
" " PROGRAM_NAME " -- symbolicate addresses using lldb.\n"
"\n"
"SYNOPSIS\n"
" " PROGRAM_NAME " [[--arch=<ARCH>] [--platform=<PLATFORM>] [--verbose] [--help] --] <PATH> <ADDRESS> [<ADDRESS>....]\n"
"\n"
"DESCRIPTION\n"
" Loads the executable pointed to by <PATH> and looks up and <ADDRESS>\n"
" arguments\n"
"\n"
"EXAMPLE\n"
" " PROGRAM_NAME " --arch=x86_64 -- /usr/lib/dyld 0x100000000\n"
);
exit(0);
}
int
main (int argc, char const *argv[])
{
// Use a sentry object to properly initialize/terminate LLDB.
LLDBSentry sentry;
if (argc < 3)
exit (1);
// The first argument is the file path we want to look something up in
const char *exe_file_path = argv[1];
// The second argument in the address that we want to lookup
lldb::addr_t file_addr = strtoull (argv[2], NULL, 0);
// Create a debugger instance so we can create a target
SBDebugger debugger (SBDebugger::Create());
if (debugger.IsValid())
// Create a debugger instance so we can create a target
if (!debugger.IsValid())
fprintf (stderr, "error: failed to create a debugger object\n");
bool show_usage = false;
bool verbose = false;
const char *arch = NULL;
const char *platform = NULL;
std::string short_options("h?");
for (const struct option *opt = g_long_options; opt->name; ++opt)
{
if (isprint(opt->val))
{
short_options.append(1, (char)opt->val);
switch (opt->has_arg)
{
case no_argument:
break;
case required_argument:
short_options.append(1, ':');
break;
case optional_argument:
short_options.append(2, ':');
break;
}
}
}
#ifdef __GLIBC__
optind = 0;
#else
optreset = 1;
optind = 1;
#endif
char ch;
while ((ch = getopt_long_only(argc, (char * const *)argv, short_options.c_str(), g_long_options, 0)) != -1)
{
switch (ch)
{
case 0:
break;
case 'a':
if (arch != NULL)
{
fprintf (stderr, "error: the --arch option can only be specified once\n");
exit(1);
}
arch = optarg;
break;
case 'p':
platform = optarg;
break;
case 'v':
verbose = true;
break;
case 'h':
case '?':
default:
show_usage = true;
break;
}
}
argc -= optind;
argv += optind;
if (show_usage || argc < 2)
usage();
int arg_idx = 0;
// The first argument is the file path we want to look something up in
const char *exe_file_path = argv[arg_idx];
const char *addr_cstr;
const bool add_dependent_libs = false;
SBError error;
SBStream strm;
strm.RedirectToFileHandle (stdout, false);
while ((addr_cstr = argv[++arg_idx]) != NULL)
{
// The second argument in the address that we want to lookup
lldb::addr_t file_addr = strtoull (addr_cstr, NULL, 0);
// Create a target using the executable.
SBTarget target (debugger.CreateTargetWithFileAndArch (exe_file_path, "i386"));
SBTarget target = debugger.CreateTarget (exe_file_path,
arch,
platform,
add_dependent_libs,
error);
if (!error.Success())
{
fprintf (stderr, "error: %s\n", error.GetCString());
exit(1);
}
printf ("%sLooking up 0x%llx in '%s':\n", (arg_idx > 1) ? "\n" : "", file_addr, exe_file_path);
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));
// Take a file virtual address and resolve it to a section offset
// address that can be used to do a symbol lookup by address
SBAddress addr = module.ResolveFileAddress (file_addr);
if (addr.IsValid())
bool success = addr.IsValid() && addr.GetSection().IsValid();
if (success)
{
// We can resolve a section offset address in the module
// and only ask for what we need. You can logical or together
@ -91,28 +216,17 @@ main (int argc, char const *argv[])
//
// NOTE: the less you ask for, the less LLDB will parse as
// LLDB does partial parsing on just about everything.
SBSymbolContext symbol_context (module.ResolveSymbolContextForAddress (addr, eSymbolContextEverything));
SBCompileUnit comp_unit (symbol_context.GetCompileUnit());
if (comp_unit.IsValid())
{
}
SBFunction function (symbol_context.GetFunction());
if (function.IsValid())
{
}
SBBlock block (symbol_context.GetBlock());
if (block.IsValid())
{
}
SBLineEntry line_entry (symbol_context.GetLineEntry());
if (line_entry.IsValid())
{
}
SBSymbol symbol (symbol_context.GetSymbol());
if (symbol.IsValid())
{
}
SBSymbolContext sc (module.ResolveSymbolContextForAddress (addr, eSymbolContextEverything));
strm.Printf (" Address: %s + 0x%llx\n Summary: ", addr.GetSection().GetName (), addr.GetOffset());
addr.GetDescription (strm);
strm.Printf ("\n");
if (verbose)
sc.GetDescription (strm);
}
else
{
printf ("error: 0x%llx does not resolve to a valid file address in '%s'\n", file_addr, exe_file_path);
}
}
}

View file

@ -117,12 +117,19 @@ cxx_linker = $(if $(findstring clang,$(1)), $(subst clang,clang++,$(1)), $(if $(
ifeq (1,$(USE_LIBSTDCPP))
# Clang requires an extra flag: -stdlib=libstdc++
ifneq (,$(findstring clang,$(CC)))
CFLAGS += -stdlib=libstdc++
CXXFLAGS += -stdlib=libstdc++
LDFLAGS += -stdlib=libstdc++
endif
endif
ifeq (1,$(USE_LIBCPP))
# Clang requires an extra flag: -stdlib=libstdc++
ifneq (,$(findstring clang,$(CC)))
CXXFLAGS += -stdlib=libc++
LDFLAGS += -stdlib=libc++
endif
endif
#----------------------------------------------------------------------
# dylib settings
#----------------------------------------------------------------------
@ -333,9 +340,9 @@ dsym: $(DSYM)
all: $(EXE) $(DSYM)
clean::
ifeq "$(DYLIB_NAME)" ""
rm -rf "$(EXE)" "$(DSYM)" $(OBJECTS) $(PREREQS) $(ARCHIVE_NAME) $(ARCHIVE_OBJECTS)
rm -rf "$(EXE)" "$(DSYM)" $(OBJECTS) $(PREREQS) $(ARCHIVE_NAME) $(ARCHIVE_OBJECTS) *.d.[0-9] *.d.[0-9][0-9] *.d.[0-9][0-9][0-9] *.d.[0-9][0-9][0-9][0-9] *.d.[0-9][0-9][0-9][0-9][0-9]
else
rm -rf "$(EXE)" "$(DSYM)" $(OBJECTS) $(PREREQS) $(ARCHIVE_NAME) $(ARCHIVE_OBJECTS) $(DYLIB_OBJECTS) $(DYLIB_PREREQS) $(DYLIB_FILENAME) $(DYLIB_FILENAME).dSYM
rm -rf "$(EXE)" "$(DSYM)" $(OBJECTS) $(PREREQS) $(ARCHIVE_NAME) $(ARCHIVE_OBJECTS) $(DYLIB_OBJECTS) $(DYLIB_PREREQS) $(DYLIB_FILENAME) $(DYLIB_FILENAME).dSYM *.d.[0-9] *.d.[0-9][0-9] *.d.[0-9][0-9][0-9] *.d.[0-9][0-9][0-9][0-9] *.d.[0-9][0-9][0-9][0-9][0-9]
endif
#----------------------------------------------------------------------