From gclayton at apple.com Mon Jul 12 18:11:00 2010 From: gclayton at apple.com (Greg Clayton) Date: Mon, 12 Jul 2010 23:11:00 -0000 Subject: [Lldb-commits] [lldb] r108208 - /lldb/trunk/source/Plugins/Makefile Message-ID: <20100712231100.4A25C2A6C12C@llvm.org> Author: gclayton Date: Mon Jul 12 18:11:00 2010 New Revision: 108208 URL: http://llvm.org/viewvc/llvm-project?rev=108208&view=rev Log: Don't build the SymbolVendor/MacOSX when not building on Darwin. Modified: lldb/trunk/source/Plugins/Makefile Modified: lldb/trunk/source/Plugins/Makefile URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Makefile?rev=108208&r1=108207&r2=108208&view=diff ============================================================================== --- lldb/trunk/source/Plugins/Makefile (original) +++ lldb/trunk/source/Plugins/Makefile Mon Jul 12 18:11:00 2010 @@ -12,10 +12,10 @@ include $(LLDB_LEVEL)/../../Makefile.config -DIRS := ABI/MacOSX-i386 ABI/SysV-x86_64 Disassembler/llvm ObjectContainer/BSD-Archive ObjectFile/ELF SymbolFile/DWARF SymbolFile/Symtab SymbolVendor/MacOSX +DIRS := ABI/MacOSX-i386 ABI/SysV-x86_64 Disassembler/llvm ObjectContainer/BSD-Archive ObjectFile/ELF SymbolFile/DWARF SymbolFile/Symtab ifeq ($(HOST_OS),Darwin) - DIRS += DynamicLoader/MacOSX-DYLD ObjectContainer/Universal-Mach-O ObjectFile/Mach-O Process/gdb-remote Process/Utility + DIRS += DynamicLoader/MacOSX-DYLD ObjectContainer/Universal-Mach-O ObjectFile/Mach-O Process/gdb-remote Process/Utility SymbolVendor/MacOSX endif include $(LLDB_LEVEL)/Makefile From gclayton at apple.com Mon Jul 12 18:14:00 2010 From: gclayton at apple.com (Greg Clayton) Date: Mon, 12 Jul 2010 23:14:00 -0000 Subject: [Lldb-commits] [lldb] r108210 - in /lldb/trunk: lib/Makefile source/Expression/ClangResultSynthesizer.cpp source/Interpreter/Makefile source/Makefile tools/driver/Makefile Message-ID: <20100712231400.6D8A42A6C12C@llvm.org> Author: gclayton Date: Mon Jul 12 18:14:00 2010 New Revision: 108210 URL: http://llvm.org/viewvc/llvm-project?rev=108210&view=rev Log: Patch from Jean-Daniel Dupas: Makefile patch to explicitly use PROJ_SRC_DIR when required. It fixes build when obj dir is not source dir. I also fixed a build warning in ClangResultSynthesizer.cpp. Modified: lldb/trunk/lib/Makefile lldb/trunk/source/Expression/ClangResultSynthesizer.cpp lldb/trunk/source/Interpreter/Makefile lldb/trunk/source/Makefile lldb/trunk/tools/driver/Makefile Modified: lldb/trunk/lib/Makefile URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/lib/Makefile?rev=108210&r1=108209&r2=108210&view=diff ============================================================================== --- lldb/trunk/lib/Makefile (original) +++ lldb/trunk/lib/Makefile Mon Jul 12 18:14:00 2010 @@ -87,7 +87,7 @@ LLVMLibsOptions += -F/System/Library/Frameworks -F/System/Library/PrivateFrameworks LLVMLibsOptions += -framework Foundation -framework CoreFoundation LLVMLibsOptions += -framework DebugSymbols -lpython2.6 -lobjc - LLVMLibsOptions += -Wl,-exported_symbols_list -Wl,$(LLDB_LEVEL)/resources/lldb-framework-exports + LLVMLibsOptions += -Wl,-exported_symbols_list -Wl,"$(PROJ_SRC_DIR)/$(LLDB_LEVEL)/resources/lldb-framework-exports" # Mac OS X 10.4 and earlier tools do not allow a second -install_name on command line DARWIN_VERS := $(shell echo $(TARGET_TRIPLE) | sed 's/.*darwin\([0-9]*\).*/\1/') ifneq ($(DARWIN_VERS),8) Modified: lldb/trunk/source/Expression/ClangResultSynthesizer.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/ClangResultSynthesizer.cpp?rev=108210&r1=108209&r2=108210&view=diff ============================================================================== --- lldb/trunk/source/Expression/ClangResultSynthesizer.cpp (original) +++ lldb/trunk/source/Expression/ClangResultSynthesizer.cpp Mon Jul 12 18:14:00 2010 @@ -27,10 +27,11 @@ using namespace lldb_private; ClangResultSynthesizer::ClangResultSynthesizer(ASTConsumer *passthrough) : - m_passthrough(passthrough), - m_passthrough_sema(NULL), - m_sema(NULL), - m_ast_context(NULL) + m_ast_context (NULL), + m_passthrough (passthrough), + m_passthrough_sema (NULL), + m_sema (NULL), + m_action (NULL) { if (!m_passthrough) return; Modified: lldb/trunk/source/Interpreter/Makefile URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/Makefile?rev=108210&r1=108209&r2=108210&view=diff ============================================================================== --- lldb/trunk/source/Interpreter/Makefile (original) +++ lldb/trunk/source/Interpreter/Makefile Mon Jul 12 18:14:00 2010 @@ -20,5 +20,5 @@ PYTHON_DIR := $(LLDB_BIN_DIR) LLDBWrapPython.cpp: - swig -c++ -shadow -python -I"$(LLDB_LEVEL)/include" -I./. -outdir "$(LLDB_BIN_DIR)" -o LLDBWrapPython.cpp "$(LLDB_LEVEL)/scripts/lldb.swig" - cp embedded_interpreter.py "$(PYTHON_DIR)" + swig -c++ -shadow -python -I"$(PROJ_SRC_DIR)/$(LLDB_LEVEL)/include" -I./. -outdir "$(LLDB_BIN_DIR)" -o LLDBWrapPython.cpp "$(PROJ_SRC_DIR)/$(LLDB_LEVEL)/scripts/lldb.swig" + cp "$(PROJ_SRC_DIR)/embedded_interpreter.py" "$(PYTHON_DIR)" Modified: lldb/trunk/source/Makefile URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Makefile?rev=108210&r1=108209&r2=108210&view=diff ============================================================================== --- lldb/trunk/source/Makefile (original) +++ lldb/trunk/source/Makefile Mon Jul 12 18:14:00 2010 @@ -16,5 +16,5 @@ include $(LLDB_LEVEL)/Makefile -LLDB_vers.c: $(LLDB_LEVEL)/scripts/generate-vers.pl $(LLDB_LEVEL)/lldb.xcodeproj/project.pbxproj - $(LLDB_LEVEL)/scripts/generate-vers.pl $(LLDB_LEVEL)/lldb.xcodeproj/project.pbxproj > LLDB_vers.c +LLDB_vers.c: $(PROJ_SRC_DIR)/$(LLDB_LEVEL)/scripts/generate-vers.pl $(PROJ_SRC_DIR)/$(LLDB_LEVEL)/lldb.xcodeproj/project.pbxproj + "$(PROJ_SRC_DIR)/$(LLDB_LEVEL)/scripts/generate-vers.pl" "$(PROJ_SRC_DIR)/$(LLDB_LEVEL)/lldb.xcodeproj/project.pbxproj" > LLDB_vers.c Modified: lldb/trunk/tools/driver/Makefile URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/driver/Makefile?rev=108210&r1=108209&r2=108210&view=diff ============================================================================== --- lldb/trunk/tools/driver/Makefile (original) +++ lldb/trunk/tools/driver/Makefile Mon Jul 12 18:14:00 2010 @@ -19,7 +19,7 @@ ifeq ($(HOST_OS),Darwin) LD.Flags += -Wl,-rpath, at loader_path/../lib/ - LD.Flags += -Wl,-sectcreate -Wl,__TEXT -Wl,__info_plist -Wl,lldb-Info.plist + LD.Flags += -Wl,-sectcreate -Wl,__TEXT -Wl,__info_plist -Wl,"$(PROJ_SRC_DIR)/lldb-Info.plist" endif ifeq ($(HOST_OS),Linux) From gclayton at apple.com Tue Jul 13 13:49:01 2010 From: gclayton at apple.com (Greg Clayton) Date: Tue, 13 Jul 2010 11:49:01 -0700 Subject: [Lldb-commits] LLVM Makefile.rules has been patched Message-ID: If you want to try and build LLDB using the LLVM make system, you should be able to now after this LLVM commit: Committed revision 108255. Greg Clayton From gclayton at apple.com Tue Jul 13 15:57:42 2010 From: gclayton at apple.com (Greg Clayton) Date: Tue, 13 Jul 2010 20:57:42 -0000 Subject: [Lldb-commits] [lldb] r108271 - in /lldb/trunk: lldb.runcontext lldb.xcworkspace/ Message-ID: <20100713205742.199742A6C12C@llvm.org> Author: gclayton Date: Tue Jul 13 15:57:41 2010 New Revision: 108271 URL: http://llvm.org/viewvc/llvm-project?rev=108271&view=rev Log: Removed Xcode project files that aren't needed right now. Removed: lldb/trunk/lldb.runcontext lldb/trunk/lldb.xcworkspace/ Removed: lldb/trunk/lldb.runcontext URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/lldb.runcontext?rev=108270&view=auto ============================================================================== --- lldb/trunk/lldb.runcontext (original) +++ lldb/trunk/lldb.runcontext (removed) @@ -1,49 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - From scallanan at apple.com Tue Jul 13 16:41:46 2010 From: scallanan at apple.com (Sean Callanan) Date: Tue, 13 Jul 2010 21:41:46 -0000 Subject: [Lldb-commits] [lldb] r108279 - in /lldb/trunk: include/lldb/Expression/ClangExpressionDeclMap.h include/lldb/Expression/IRForTarget.h lldb.xcodeproj/project.pbxproj source/Expression/ClangExpression.cpp source/Expression/ClangExpressionDeclMap.cpp source/Expression/IRForTarget.cpp Message-ID: <20100713214147.01E712A6C12D@llvm.org> Author: spyffe Date: Tue Jul 13 16:41:46 2010 New Revision: 108279 URL: http://llvm.org/viewvc/llvm-project?rev=108279&view=rev Log: "expr -i" now performs the required transforms to prepare the IR for JIT compilation. We still need to do the JIT compilation and move the arguments in/out of target memory. Modified: lldb/trunk/include/lldb/Expression/ClangExpressionDeclMap.h lldb/trunk/include/lldb/Expression/IRForTarget.h lldb/trunk/lldb.xcodeproj/project.pbxproj lldb/trunk/source/Expression/ClangExpression.cpp lldb/trunk/source/Expression/ClangExpressionDeclMap.cpp lldb/trunk/source/Expression/IRForTarget.cpp Modified: lldb/trunk/include/lldb/Expression/ClangExpressionDeclMap.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Expression/ClangExpressionDeclMap.h?rev=108279&r1=108278&r2=108279&view=diff ============================================================================== --- lldb/trunk/include/lldb/Expression/ClangExpressionDeclMap.h (original) +++ lldb/trunk/include/lldb/Expression/ClangExpressionDeclMap.h Tue Jul 13 16:41:46 2010 @@ -27,6 +27,10 @@ class DeclContext; } +namespace llvm { + class Value; +} + namespace lldb_private { class Function; @@ -43,6 +47,20 @@ bool GetIndexForDecl (uint32_t &index, const clang::Decl *decl); + // Interface for IRForTarget + bool AddValueToStruct (llvm::Value *value, + const clang::NamedDecl *decl, + size_t size, + off_t alignment); + bool DoStructLayout (); + bool GetStructInfo (uint32_t &num_elements, + size_t &size, + off_t &alignment); + bool GetStructElement (const clang::NamedDecl *&decl, + llvm::Value *&value, + off_t &offset, + uint32_t index); + // Interface for DwarfExpression Value *GetValueForIndex (uint32_t index); @@ -57,12 +75,28 @@ Value *m_value; /* owned by ClangExpressionDeclMap */ }; + struct StructMember + { + const clang::NamedDecl *m_decl; + llvm::Value *m_value; + off_t m_offset; + size_t m_size; + off_t m_alignment; + }; + typedef std::vector TupleVector; typedef TupleVector::iterator TupleIterator; + typedef std::vector StructMemberVector; + typedef StructMemberVector::iterator StructMemberIterator; + TupleVector m_tuples; + StructMemberVector m_members; ExecutionContext *m_exe_ctx; SymbolContext *m_sym_ctx; /* owned by ClangExpressionDeclMap */ + off_t m_struct_alignment; + size_t m_struct_size; + bool m_struct_laid_out; void AddOneVariable(NameSearchContext &context, Variable *var); void AddOneFunction(NameSearchContext &context, Function *fun); Modified: lldb/trunk/include/lldb/Expression/IRForTarget.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Expression/IRForTarget.h?rev=108279&r1=108278&r2=108279&view=diff ============================================================================== --- lldb/trunk/include/lldb/Expression/IRForTarget.h (original) +++ lldb/trunk/include/lldb/Expression/IRForTarget.h Tue Jul 13 16:41:46 2010 @@ -11,11 +11,13 @@ #define liblldb_IRForTarget_h_ #include "llvm/Pass.h" -#include "llvm/PassManager.h" namespace llvm { class BasicBlock; + class Function; class Module; + class TargetData; + class Value; } namespace lldb_private { @@ -26,16 +28,25 @@ { public: IRForTarget(const void *pid, - lldb_private::ClangExpressionDeclMap *decl_map); + lldb_private::ClangExpressionDeclMap *decl_map, + const llvm::TargetData *target_data); ~IRForTarget(); bool runOnModule(llvm::Module &M); void assignPassManager(llvm::PMStack &PMS, llvm::PassManagerType T = llvm::PMT_ModulePassManager); llvm::PassManagerType getPotentialPassManagerType() const; private: - bool runOnBasicBlock(llvm::BasicBlock &BB); + bool MaybeHandleVariable(llvm::Module &M, + lldb_private::ClangExpressionDeclMap *DM, + llvm::Value *V, + bool Store); + bool runOnBasicBlock(llvm::Module &M, + llvm::BasicBlock &BB); + bool replaceVariables(llvm::Module &M, + llvm::Function *F); lldb_private::ClangExpressionDeclMap *m_decl_map; + const llvm::TargetData *m_target_data; }; #endif \ No newline at end of file Modified: lldb/trunk/lldb.xcodeproj/project.pbxproj URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/lldb.xcodeproj/project.pbxproj?rev=108279&r1=108278&r2=108279&view=diff ============================================================================== --- lldb/trunk/lldb.xcodeproj/project.pbxproj (original) +++ lldb/trunk/lldb.xcodeproj/project.pbxproj Tue Jul 13 16:41:46 2010 @@ -2252,6 +2252,9 @@ buildConfigurationList = 1DEB91EF08733DB70010E9CD /* Build configuration list for PBXProject "lldb" */; compatibilityVersion = "Xcode 3.1"; hasScannedForEncodings = 1; + knownRegions = ( + en, + ); mainGroup = 08FB7794FE84155DC02AAC07 /* lldb */; projectDirPath = ""; projectReferences = ( Modified: lldb/trunk/source/Expression/ClangExpression.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/ClangExpression.cpp?rev=108279&r1=108278&r2=108279&view=diff ============================================================================== --- lldb/trunk/source/Expression/ClangExpression.cpp (original) +++ lldb/trunk/source/Expression/ClangExpression.cpp Tue Jul 13 16:41:46 2010 @@ -50,6 +50,7 @@ #include "llvm/System/DynamicLibrary.h" #include "llvm/System/Host.h" #include "llvm/System/Signals.h" +#include "llvm/Target/TargetRegistry.h" #include "llvm/Target/TargetSelect.h" // Project includes @@ -240,6 +241,9 @@ m_clang_ap->getLangOpts().CPlusPlus = true; m_clang_ap->getLangOpts().ObjC1 = true; m_clang_ap->getLangOpts().ThreadsafeStatics = false; + + // Set CodeGen options + m_clang_ap->getCodeGenOpts().EmitDeclMetadata = true; // Disable some warnings. m_clang_ap->getDiagnosticOpts().Warnings.push_back("no-unused-value"); @@ -250,7 +254,6 @@ // 3. Set up various important bits of infrastructure. m_clang_ap->createDiagnostics(0, 0); - m_clang_ap->getLangOpts().CPlusPlus = true; // Create the target instance. m_clang_ap->setTarget(TargetInfo::CreateTargetInfo(m_clang_ap->getDiagnostics(), @@ -294,7 +297,7 @@ { // HACK: for now we have to make a function body around our expression // since there is no way to parse a single expression line in LLVM/Clang. - std::string func_expr("extern \"C\" void ___clang_expr()\n{\n\t"); + std::string func_expr("extern \"C\" void ___clang_expr(void *___clang_arg)\n{\n\t"); func_expr.append(expr_text); func_expr.append(";\n}"); return ParseBareExpression (func_expr, stream, add_result_var); @@ -513,7 +516,23 @@ return 1; } - IRForTarget ir_for_target("IR for target", m_decl_map); + llvm::Triple target_triple = m_clang_ap->getTarget().getTriple(); + + std::string err; + + const llvm::Target *target = llvm::TargetRegistry::lookupTarget(m_target_triple, err); + + if (!target) + { + if (log) + log->Printf("Couldn't find a target for %s", m_target_triple.c_str()); + + return 1; + } + + std::auto_ptr target_machine(target->createTargetMachine(m_target_triple, "")); + + IRForTarget ir_for_target("IR for target", m_decl_map, target_machine->getTargetData()); return ir_for_target.runOnModule(*module); } Modified: lldb/trunk/source/Expression/ClangExpressionDeclMap.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/ClangExpressionDeclMap.cpp?rev=108279&r1=108278&r2=108279&view=diff ============================================================================== --- lldb/trunk/source/Expression/ClangExpressionDeclMap.cpp (original) +++ lldb/trunk/source/Expression/ClangExpressionDeclMap.cpp Tue Jul 13 16:41:46 2010 @@ -38,7 +38,8 @@ using namespace clang; ClangExpressionDeclMap::ClangExpressionDeclMap(ExecutionContext *exe_ctx) : - m_exe_ctx(exe_ctx) + m_exe_ctx(exe_ctx), + m_struct_laid_out(false) { if (exe_ctx && exe_ctx->frame) m_sym_ctx = new SymbolContext(exe_ctx->frame->GetSymbolContext(lldb::eSymbolContextEverything)); @@ -77,6 +78,105 @@ return false; } +// Interface for IRForTarget + +bool +ClangExpressionDeclMap::AddValueToStruct (llvm::Value *value, + const clang::NamedDecl *decl, + size_t size, + off_t alignment) +{ + m_struct_laid_out = false; + + StructMemberIterator iter; + + for (iter = m_members.begin(); + iter != m_members.end(); + ++iter) + { + if (iter->m_decl == decl) + return true; + } + + StructMember member; + + member.m_value = value; + member.m_decl = decl; + member.m_offset = 0; + member.m_size = size; + member.m_alignment = alignment; + + m_members.push_back(member); + + return true; +} + +bool +ClangExpressionDeclMap::DoStructLayout () +{ + if (m_struct_laid_out) + return true; + + StructMemberIterator iter; + + off_t cursor = 0; + + m_struct_alignment = 0; + m_struct_size = 0; + + for (iter = m_members.begin(); + iter != m_members.end(); + ++iter) + { + if (iter == m_members.begin()) + m_struct_alignment = iter->m_alignment; + + if (cursor % iter->m_alignment) + cursor += (iter->m_alignment - (cursor % iter->m_alignment)); + + iter->m_offset = cursor; + cursor += iter->m_size; + } + + m_struct_size = cursor; + + m_struct_laid_out = true; + return true; +} + +bool ClangExpressionDeclMap::GetStructInfo (uint32_t &num_elements, + size_t &size, + off_t &alignment) +{ + if (!m_struct_laid_out) + return false; + + num_elements = m_members.size(); + size = m_struct_size; + alignment = m_struct_alignment; + + return true; +} + +bool +ClangExpressionDeclMap::GetStructElement (const clang::NamedDecl *&decl, + llvm::Value *&value, + off_t &offset, + uint32_t index) +{ + if (!m_struct_laid_out) + return false; + + if (index >= m_members.size()) + return false; + + decl = m_members[index].m_decl; + value = m_members[index].m_value; + offset = m_members[index].m_offset; + + return true; +} + // Interface for DwarfExpression Value *ClangExpressionDeclMap::GetValueForIndex (uint32_t index) Modified: lldb/trunk/source/Expression/IRForTarget.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/IRForTarget.cpp?rev=108279&r1=108278&r2=108279&view=diff ============================================================================== --- lldb/trunk/source/Expression/IRForTarget.cpp (original) +++ lldb/trunk/source/Expression/IRForTarget.cpp Tue Jul 13 16:41:46 2010 @@ -11,7 +11,11 @@ #include "llvm/Support/raw_ostream.h" #include "llvm/InstrTypes.h" +#include "llvm/Instructions.h" #include "llvm/Module.h" +#include "llvm/Target/TargetData.h" + +#include "clang/AST/ASTContext.h" #include "lldb/Core/dwarf.h" #include "lldb/Core/Log.h" @@ -24,9 +28,11 @@ using namespace llvm; IRForTarget::IRForTarget(const void *pid, - lldb_private::ClangExpressionDeclMap *decl_map) : + lldb_private::ClangExpressionDeclMap *decl_map, + const llvm::TargetData *target_data) : ModulePass(pid), - m_decl_map(decl_map) + m_decl_map(decl_map), + m_target_data(target_data) { } @@ -34,38 +40,177 @@ { } -bool -IRForTarget::runOnBasicBlock(BasicBlock &BB) +static clang::NamedDecl * +DeclForGlobalValue(llvm::Module &module, + llvm::GlobalValue *global_value) +{ + NamedMDNode *named_metadata = module.getNamedMetadata("clang.global.decl.ptrs"); + + if (!named_metadata) + return NULL; + + unsigned num_nodes = named_metadata->getNumOperands(); + unsigned node_index; + + for (node_index = 0; + node_index < num_nodes; + ++node_index) + { + MDNode *metadata_node = named_metadata->getOperand(node_index); + + if (!metadata_node) + return NULL; + + if (metadata_node->getNumOperands() != 2) + return NULL; + + if (metadata_node->getOperand(0) != global_value) + continue; + + ConstantInt *constant_int = dyn_cast(metadata_node->getOperand(1)); + + if (!constant_int) + return NULL; + + uintptr_t ptr = constant_int->getZExtValue(); + + return reinterpret_cast(ptr); + } + + return NULL; +} + +bool +IRForTarget::MaybeHandleVariable(Module &M, + lldb_private::ClangExpressionDeclMap *DM, + llvm::Value *V, + bool Store) { lldb_private::Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS); + + if (GlobalVariable *global_variable = dyn_cast(V)) + { + clang::NamedDecl *named_decl = DeclForGlobalValue(M, global_variable); + + const llvm::Type *value_type = global_variable->getType(); + size_t value_size = m_target_data->getTypeStoreSize(value_type); + off_t value_alignment = m_target_data->getPrefTypeAlignment(value_type); + + if (named_decl && !DM->AddValueToStruct(V, named_decl, value_size, value_alignment)) + return false; + } + + return true; +} + +bool +IRForTarget::runOnBasicBlock(Module &M, BasicBlock &BB) +{ ///////////////////////////////////////////////////////////////////////// // Prepare the current basic block for execution in the remote process // + llvm::BasicBlock::iterator ii; + + for (ii = BB.begin(); + ii != BB.end(); + ++ii) + { + Instruction &inst = *ii; + + if (LoadInst *load = dyn_cast(&inst)) + if (!MaybeHandleVariable(M, m_decl_map, load->getPointerOperand(), false)) + return false; + + if (StoreInst *store = dyn_cast(&inst)) + if (!MaybeHandleVariable(M, m_decl_map, store->getPointerOperand(), false)) + return false; + } + + return true; +} + +static std::string PrintValue(llvm::Value *V, bool truncate = false) +{ + std::string s; + raw_string_ostream rso(s); + V->print(rso); + rso.flush(); + if (truncate) + s.resize(s.length() - 1); + return s; +} + +bool +IRForTarget::replaceVariables(Module &M, Function *F) +{ + lldb_private::Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS); + + m_decl_map->DoStructLayout(); + + if (log) + log->Printf("Element arrangement:"); + + uint32_t num_elements; + uint32_t element_index; + + size_t size; + off_t alignment; + + if (!m_decl_map->GetStructInfo (num_elements, size, alignment)) + return false; + + Function::arg_iterator iter(F->getArgumentList().begin()); + + if (iter == F->getArgumentList().end()) + return false; + + llvm::Argument *argument = iter; + + if (!argument->getName().equals("___clang_arg")) + return false; + if (log) + log->Printf("Arg: %s", PrintValue(argument).c_str()); + + llvm::BasicBlock &entry_block(F->getEntryBlock()); + llvm::Instruction *first_entry_instruction(entry_block.getFirstNonPHIOrDbg()); + + if (!first_entry_instruction) + return false; + + LLVMContext &context(M.getContext()); + const IntegerType *offset_type(Type::getInt32Ty(context)); + + if (!offset_type) + return false; + + for (element_index = 0; element_index < num_elements; ++element_index) { - log->Printf("Preparing basic block %s:", - BB.hasName() ? BB.getNameStr().c_str() : "[anonymous]"); + const clang::NamedDecl *decl; + llvm::Value *value; + off_t offset; - llvm::BasicBlock::iterator ii; + if (!m_decl_map->GetStructElement (decl, value, offset, element_index)) + return false; - for (ii = BB.begin(); - ii != BB.end(); - ++ii) - { - llvm::Instruction &inst = *ii; - - std::string s; - raw_string_ostream os(s); - - inst.print(os); - - if (log) - log->Printf(" %s", s.c_str()); - } + if (log) + log->Printf(" %s (%s) placed at %d", + decl->getIdentifier()->getNameStart(), + PrintValue(value, true).c_str(), + offset); + + ConstantInt *offset_int(ConstantInt::getSigned(offset_type, offset)); + GetElementPtrInst *get_element_ptr = GetElementPtrInst::Create(argument, offset_int, "", first_entry_instruction); + BitCastInst *bit_cast = new BitCastInst(get_element_ptr, value->getType(), "", first_entry_instruction); + + value->replaceAllUsesWith(bit_cast); } + if (log) + log->Printf("Total structure [align %d, size %d]", alignment, size); + return true; } @@ -90,7 +235,24 @@ bbi != function->end(); ++bbi) { - runOnBasicBlock(*bbi); + if (!runOnBasicBlock(M, *bbi)) + return false; + } + + if (!replaceVariables(M, function)) + return false; + + if (log) + { + for (bbi = function->begin(); + bbi != function->end(); + ++bbi) + { + log->Printf("Rewrote basic block %s for running: \n%s", + bbi->hasName() ? bbi->getNameStr().c_str() : "[anonymous]", + PrintValue(bbi).c_str()); + } + } return true; @@ -98,7 +260,7 @@ void IRForTarget::assignPassManager(PMStack &PMS, - PassManagerType T) + PassManagerType T) { } From gclayton at apple.com Tue Jul 13 17:06:06 2010 From: gclayton at apple.com (Greg Clayton) Date: Tue, 13 Jul 2010 22:06:06 -0000 Subject: [Lldb-commits] [lldb] r108285 - in /lldb/trunk: lldb.xcodeproj/project.pbxproj llvm.zip scripts/build-llvm.pl Message-ID: <20100713220606.5F21D2A6C12C@llvm.org> Author: gclayton Date: Tue Jul 13 17:06:06 2010 New Revision: 108285 URL: http://llvm.org/viewvc/llvm-project?rev=108285&view=rev Log: Updated to latest llvm from July 13th, 2010 at 13:00. Modified: lldb/trunk/lldb.xcodeproj/project.pbxproj lldb/trunk/llvm.zip lldb/trunk/scripts/build-llvm.pl Modified: lldb/trunk/lldb.xcodeproj/project.pbxproj URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/lldb.xcodeproj/project.pbxproj?rev=108285&r1=108284&r2=108285&view=diff ============================================================================== --- lldb/trunk/lldb.xcodeproj/project.pbxproj (original) +++ lldb/trunk/lldb.xcodeproj/project.pbxproj Tue Jul 13 17:06:06 2010 @@ -2918,7 +2918,7 @@ "$(LLVM_BUILD_DIR)", ); LLVM_BUILD_DIR = "$(DERIVED_FILE_DIR)/llvm.build"; - LLVM_CONFIGURATION = Release; + LLVM_CONFIGURATION = "Release+Asserts"; OTHER_CFLAGS = ( "-DFOR_DYLD=0", "-DSUPPORT_REMOTE_UNWINDING", Modified: lldb/trunk/llvm.zip URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/llvm.zip?rev=108285&r1=108284&r2=108285&view=diff ============================================================================== Binary files - no diff available. Modified: lldb/trunk/scripts/build-llvm.pl URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/build-llvm.pl?rev=108285&r1=108284&r2=108285&view=diff ============================================================================== --- lldb/trunk/scripts/build-llvm.pl (original) +++ lldb/trunk/scripts/build-llvm.pl Tue Jul 13 17:06:06 2010 @@ -25,7 +25,7 @@ our $llvm_configuration = $ENV{LLVM_CONFIGURATION}; -our $llvm_revision = "'{2010-07-07T08:00}'"; +our $llvm_revision = "'{2010-07-13T13:00}'"; our $llvm_source_dir = "$ENV{SRCROOT}"; our $cc = "$ENV{DEVELOPER_BIN_DIR}/gcc-4.2"; our $cxx = "$ENV{DEVELOPER_BIN_DIR}/g++-4.2"; From gclayton at apple.com Tue Jul 13 17:26:45 2010 From: gclayton at apple.com (Greg Clayton) Date: Tue, 13 Jul 2010 22:26:45 -0000 Subject: [Lldb-commits] [lldb] r108289 - in /lldb/trunk: lldb.xcodeproj/project.pbxproj scripts/build-llvm.pl source/Expression/IRForTarget.cpp Message-ID: <20100713222645.74BE02A6C12C@llvm.org> Author: gclayton Date: Tue Jul 13 17:26:45 2010 New Revision: 108289 URL: http://llvm.org/viewvc/llvm-project?rev=108289&view=rev Log: Removed unused variable "log". Fixed the llvm build for Mac OS X builds to look in llvm/lib/Release+Asserts output directory for all configurations (Debug, Release, BuildAndIntegration). Modified: lldb/trunk/lldb.xcodeproj/project.pbxproj lldb/trunk/scripts/build-llvm.pl lldb/trunk/source/Expression/IRForTarget.cpp Modified: lldb/trunk/lldb.xcodeproj/project.pbxproj URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/lldb.xcodeproj/project.pbxproj?rev=108289&r1=108288&r2=108289&view=diff ============================================================================== --- lldb/trunk/lldb.xcodeproj/project.pbxproj (original) +++ lldb/trunk/lldb.xcodeproj/project.pbxproj Tue Jul 13 17:26:45 2010 @@ -2756,7 +2756,7 @@ "$(LLVM_BUILD_DIR)", ); LLVM_BUILD_DIR = "$(SRCROOT)/llvm"; - LLVM_CONFIGURATION = Release; + LLVM_CONFIGURATION = "Release+Asserts"; OTHER_CFLAGS = ( "-DFOR_DYLD=0", "-DSUPPORT_REMOTE_UNWINDING", @@ -2809,7 +2809,7 @@ "$(LLVM_BUILD_DIR)", ); LLVM_BUILD_DIR = "$(SRCROOT)/llvm"; - LLVM_CONFIGURATION = Release; + LLVM_CONFIGURATION = "Release+Asserts"; OTHER_CFLAGS = ( "-DFOR_DYLD=0", "-DSUPPORT_REMOTE_UNWINDING", Modified: lldb/trunk/scripts/build-llvm.pl URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/build-llvm.pl?rev=108289&r1=108288&r2=108289&view=diff ============================================================================== --- lldb/trunk/scripts/build-llvm.pl (original) +++ lldb/trunk/scripts/build-llvm.pl Tue Jul 13 17:26:45 2010 @@ -395,6 +395,10 @@ print FILES "$archive_fullpath\n"; } } + else + { + print "warning: archive doesn't exist: '$archive_fullpath'\n"; + } } close (FILES); do_command ("libtool -static -o '$arch_output_file' -filelist '$files'"); Modified: lldb/trunk/source/Expression/IRForTarget.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/IRForTarget.cpp?rev=108289&r1=108288&r2=108289&view=diff ============================================================================== --- lldb/trunk/source/Expression/IRForTarget.cpp (original) +++ lldb/trunk/source/Expression/IRForTarget.cpp Tue Jul 13 17:26:45 2010 @@ -86,8 +86,6 @@ llvm::Value *V, bool Store) { - lldb_private::Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS); - if (GlobalVariable *global_variable = dyn_cast(V)) { clang::NamedDecl *named_decl = DeclForGlobalValue(M, global_variable); From wilsons at start.ca Tue Jul 13 18:07:23 2010 From: wilsons at start.ca (Stephen Wilson) Date: Tue, 13 Jul 2010 23:07:23 -0000 Subject: [Lldb-commits] [lldb] r108292 - in /lldb/trunk/source: Plugins/ObjectFile/ELF/ELFHeader.cpp Plugins/ObjectFile/ELF/ELFHeader.h Plugins/ObjectFile/ELF/ObjectFileELF.cpp Plugins/ObjectFile/ELF/ObjectFileELF.h Plugins/ObjectFile/ELF/ObjectFileELF64.cpp Plugins/ObjectFile/ELF/ObjectFileELF64.h lldb.cpp Message-ID: <20100713230723.D798F2A6C12C@llvm.org> Author: wilsons Date: Tue Jul 13 18:07:23 2010 New Revision: 108292 URL: http://llvm.org/viewvc/llvm-project?rev=108292&view=rev Log: Combine 32 and 64 bit ELF readers. This patch provides a generic ELF reader plugin to handle both 32 and 64 bit formats. Added: lldb/trunk/source/Plugins/ObjectFile/ELF/ELFHeader.cpp lldb/trunk/source/Plugins/ObjectFile/ELF/ELFHeader.h lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp - copied, changed from r108290, lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF64.cpp lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF.h - copied, changed from r108290, lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF64.h Removed: lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF64.cpp lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF64.h Modified: lldb/trunk/source/lldb.cpp Added: lldb/trunk/source/Plugins/ObjectFile/ELF/ELFHeader.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ObjectFile/ELF/ELFHeader.cpp?rev=108292&view=auto ============================================================================== --- lldb/trunk/source/Plugins/ObjectFile/ELF/ELFHeader.cpp (added) +++ lldb/trunk/source/Plugins/ObjectFile/ELF/ELFHeader.cpp Tue Jul 13 18:07:23 2010 @@ -0,0 +1,302 @@ +//===-- ELFHeader.cpp ----------------------------------------- -*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include + +#include "lldb/Core/DataExtractor.h" + +#include "ELFHeader.h" + +using namespace elf; +using namespace lldb; +using namespace llvm::ELF; + +//------------------------------------------------------------------------------ +// Static utility functions. +// +// GetMaxU64 and GetMaxS64 wrap the similarly named methods from DataExtractor +// with error handling code and provide for parsing a sequence of values. +static bool +GetMaxU64(const lldb_private::DataExtractor &data, + uint32_t *offset, uint64_t *value, uint32_t byte_size) +{ + const uint32_t saved_offset = *offset; + *value = data.GetMaxU64(offset, byte_size); + return *offset != saved_offset; +} + +static bool +GetMaxU64(const lldb_private::DataExtractor &data, + uint32_t *offset, uint64_t *value, uint32_t byte_size, + uint32_t count) +{ + uint32_t saved_offset = *offset; + + for (uint32_t i = 0; i < count; ++i, ++value) + { + if (GetMaxU64(data, offset, value, byte_size) == false) + { + *offset = saved_offset; + return false; + } + } + return true; +} + +static bool +GetMaxS64(const lldb_private::DataExtractor &data, + uint32_t *offset, int64_t *value, uint32_t byte_size) +{ + const uint32_t saved_offset = *offset; + *value = data.GetMaxS64(offset, byte_size); + return *offset != saved_offset; +} + +static bool +GetMaxS64(const lldb_private::DataExtractor &data, + uint32_t *offset, int64_t *value, uint32_t byte_size, + uint32_t count) +{ + uint32_t saved_offset = *offset; + + for (uint32_t i = 0; i < count; ++i, ++value) + { + if (GetMaxS64(data, offset, value, byte_size) == false) + { + *offset = saved_offset; + return false; + } + } + return true; +} + +//------------------------------------------------------------------------------ +// ELFHeader + +ELFHeader::ELFHeader() +{ + memset(this, 0, sizeof(ELFHeader)); +} + +ByteOrder +ELFHeader::GetByteOrder() const +{ + if (e_ident[EI_DATA] == ELFDATA2MSB) + return eByteOrderBig; + if (e_ident[EI_DATA] == ELFDATA2LSB) + return eByteOrderLittle; + return eByteOrderInvalid; +} + +bool +ELFHeader::Parse(lldb_private::DataExtractor &data, uint32_t *offset) +{ + // Read e_ident. This provides byte order and address size info. + if (data.GetU8(offset, &e_ident, EI_NIDENT) == NULL) + return false; + + const unsigned byte_size = Is32Bit() ? 4 : 8; + data.SetByteOrder(GetByteOrder()); + data.SetAddressByteSize(byte_size); + + // Read e_type and e_machine. + if (data.GetU16(offset, &e_type, 2) == NULL) + return false; + + // Read e_version. + if (data.GetU32(offset, &e_version, 1) == NULL) + return false; + + // Read e_entry, e_phoff and e_shoff. + if (GetMaxU64(data, offset, &e_entry, byte_size, 3) == false) + return false; + + // Read e_flags. + if (data.GetU32(offset, &e_flags, 1) == NULL) + return false; + + // Read e_ehsize, e_phentsize, e_phnum, e_shentsize, e_shnum and + // e_shstrndx. + if (data.GetU16(offset, &e_ehsize, 6) == NULL) + return false; + + return true; +} + +bool +ELFHeader::MagicBytesMatch(const uint8_t *magic) +{ + return memcmp(magic, ElfMagic, strlen(ElfMagic)) == 0; +} + +unsigned +ELFHeader::AddressSizeInBytes(const uint8_t *magic) +{ + unsigned address_size = 0; + + switch (magic[EI_CLASS]) + { + case ELFCLASS32: + address_size = 4; + break; + + case ELFCLASS64: + address_size = 8; + break; + } + return address_size; +} + +//------------------------------------------------------------------------------ +// ELFSectionHeader + +ELFSectionHeader::ELFSectionHeader() +{ + memset(this, 0, sizeof(ELFSectionHeader)); +} + +bool +ELFSectionHeader::Parse(const lldb_private::DataExtractor &data, + uint32_t *offset) +{ + const unsigned byte_size = data.GetAddressByteSize(); + + // Read sh_name and sh_type. + if (data.GetU32(offset, &sh_name, 2) == NULL) + return false; + + // Read sh_flags. + if (GetMaxU64(data, offset, &sh_flags, byte_size) == false) + return false; + + // Read sh_addr, sh_off and sh_size. + if (GetMaxU64(data, offset, &sh_addr, byte_size, 3) == false) + return false; + + // Read sh_link and sh_info. + if (data.GetU32(offset, &sh_link, 2) == NULL) + return false; + + // Read sh_addralign and sh_entsize. + if (GetMaxU64(data, offset, &sh_addralign, byte_size, 2) == false) + return false; + + return true; +} + +//------------------------------------------------------------------------------ +// ELFSymbol + +ELFSymbol::ELFSymbol() +{ + memset(this, 0, sizeof(ELFSymbol)); +} + +bool +ELFSymbol::Parse(const lldb_private::DataExtractor &data, uint32_t *offset) +{ + const unsigned byte_size = data.GetAddressByteSize(); + const bool parsing_32 = byte_size == 4; + + // Read st_name. + if (data.GetU32(offset, &st_name, 1) == NULL) + return false; + + if (parsing_32) + { + // Read st_value and st_size. + if (GetMaxU64(data, offset, &st_value, byte_size, 2) == false) + return false; + + // Read st_info and st_other. + if (data.GetU8(offset, &st_info, 2) == NULL) + return false; + + // Read st_shndx. + if (data.GetU16(offset, &st_shndx, 1) == NULL) + return false; + } + else + { + // Read st_info and st_other. + if (data.GetU8(offset, &st_info, 2) == NULL) + return false; + + // Read st_shndx. + if (data.GetU16(offset, &st_shndx, 1) == NULL) + return false; + + // Read st_value and st_size. + if (data.GetU64(offset, &st_value, 2) == NULL) + return false; + } + return true; +} + +//------------------------------------------------------------------------------ +// ELFProgramHeader + +ELFProgramHeader::ELFProgramHeader() +{ + memset(this, 0, sizeof(ELFProgramHeader)); +} + +bool +ELFProgramHeader::Parse(const lldb_private::DataExtractor &data, + uint32_t *offset) +{ + const uint32_t byte_size = data.GetAddressByteSize(); + const bool parsing_32 = byte_size == 4; + + // Read p_type; + if (data.GetU32(offset, &p_type, 1) == NULL) + return false; + + if (parsing_32) { + // Read p_offset, p_vaddr, p_paddr, p_filesz and p_memsz. + if (GetMaxU64(data, offset, &p_offset, byte_size, 5) == false) + return false; + + // Read p_flags. + if (data.GetU32(offset, &p_flags, 1) == NULL) + return false; + + // Read p_align. + if (GetMaxU64(data, offset, &p_align, byte_size) == false) + return false; + } + else { + // Read p_flags. + if (data.GetU32(offset, &p_flags, 1) == NULL) + return false; + + // Read p_offset, p_vaddr, p_paddr, p_filesz, p_memsz and p_align. + if (GetMaxU64(data, offset, &p_offset, byte_size, 6) == false) + return false; + } + + return true; +} + +//------------------------------------------------------------------------------ +// ELFDynamic + +ELFDynamic::ELFDynamic() +{ + memset(this, 0, sizeof(ELFDynamic)); +} + +bool +ELFDynamic::Parse(const lldb_private::DataExtractor &data, uint32_t *offset) +{ + const unsigned byte_size = data.GetAddressByteSize(); + return GetMaxS64(data, offset, &d_tag, byte_size, 2); +} + + Added: lldb/trunk/source/Plugins/ObjectFile/ELF/ELFHeader.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ObjectFile/ELF/ELFHeader.h?rev=108292&view=auto ============================================================================== --- lldb/trunk/source/Plugins/ObjectFile/ELF/ELFHeader.h (added) +++ lldb/trunk/source/Plugins/ObjectFile/ELF/ELFHeader.h Tue Jul 13 18:07:23 2010 @@ -0,0 +1,295 @@ +//===-- ELFHeader.h ------------------------------------------- -*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +/// @file +/// @brief Generic structures and typedefs for ELF files. +/// +/// This file provides definitions for the various entities comprising an ELF +/// file. The structures are generic in the sense that they do not correspond +/// to the exact binary layout of an ELF, but can be used to hold the +/// information present in both 32 and 64 bit variants of the format. Each +/// entity provides a \c Parse method which is capable of transparently reading +/// both 32 and 64 bit instances of the object. +//===----------------------------------------------------------------------===// + +#ifndef liblldb_ELFHeader_h_ +#define liblldb_ELFHeader_h_ + +#include "llvm/Support/ELF.h" + +#include "lldb/lldb-enumerations.h" + +namespace lldb_private +{ +class DataExtractor; +} // End namespace lldb_private. + +namespace elf +{ + +//------------------------------------------------------------------------------ +/// @name ELF type definitions. +/// +/// Types used to represent the various components of ELF structures. All types +/// are signed or unsigned integral types wide enough to hold values from both +/// 32 and 64 bit ELF variants. +//@{ +typedef uint64_t elf_addr; +typedef uint64_t elf_off; +typedef uint16_t elf_half; +typedef uint32_t elf_word; +typedef int32_t elf_sword; +typedef uint64_t elf_size; +typedef uint64_t elf_xword; +typedef int64_t elf_sxword; +//@} + +//------------------------------------------------------------------------------ +/// @class ELFHeader +/// @brief Generic representation of an ELF file header. +/// +/// This object is used to identify the general attributes on an ELF file and to +/// locate additional sections within the file. +struct ELFHeader +{ + unsigned char e_ident[llvm::ELF::EI_NIDENT]; ///< ELF file identification. + elf_addr e_entry; ///< Virtual address program entry point. + elf_off e_phoff; ///< File offset of program header table. + elf_off e_shoff; ///< File offset of section header table. + elf_word e_flags; ///< Processor specific flags. + elf_word e_version; ///< Version of object file (always 1). + elf_half e_type; ///< Object file type. + elf_half e_machine; ///< Target architecture. + elf_half e_ehsize; ///< Byte size of the ELF header. + elf_half e_phentsize; ///< Size of a program header table entry. + elf_half e_phnum; ///< Number of program header entrys. + elf_half e_shentsize; ///< Size of a section header table entry. + elf_half e_shnum; ///< Number of section header entrys. + elf_half e_shstrndx; ///< String table section index. + + ELFHeader(); + + //-------------------------------------------------------------------------- + /// Returns true if this is a 32 bit ELF file header. + /// + /// @return + /// True if this is a 32 bit ELF file header. + bool Is32Bit() const { + return e_ident[llvm::ELF::EI_CLASS] == llvm::ELF::ELFCLASS32; + } + + //-------------------------------------------------------------------------- + /// Returns true if this is a 64 bit ELF file header. + /// + /// @return + /// True if this is a 64 bit ELF file header. + bool Is64Bit() const { + return e_ident[llvm::ELF::EI_CLASS] == llvm::ELF::ELFCLASS64; + } + + //-------------------------------------------------------------------------- + /// The byte order of this ELF file header. + /// + /// @return + /// The byte order of this ELF file as described by the header. + lldb::ByteOrder + GetByteOrder() const; + + //-------------------------------------------------------------------------- + /// Parse an ELFSectionHeader entry starting at position \p offset and + /// update the data extractor with the address size and byte order + /// attributes as defined by the header. + /// + /// @param[in,out] data + /// The DataExtractor to read from. Updated with the address size and + /// byte order attributes appropriate to this header. + /// + /// @param[in,out] offset + /// Pointer to an offset in the data. On return the offset will be + /// advanced by the number of bytes read. + /// + /// @return + /// True if the ELFSectionHeader was successfully read and false + /// otherwise. + bool + Parse(lldb_private::DataExtractor &data, uint32_t *offset); + + //-------------------------------------------------------------------------- + /// Examines at most EI_NIDENT bytes starting from the given pointer and + /// determines if the magic ELF identification exists. + /// + /// @return + /// True if the given sequence of bytes identifies an ELF file. + static bool + MagicBytesMatch(const uint8_t *magic); + + //-------------------------------------------------------------------------- + /// Examines at most EI_NIDENT bytes starting from the given address and + /// determines the address size of the underlying ELF file. This function + /// should only be called on an pointer for which MagicBytesMatch returns + /// true. + /// + /// @return + /// The number of bytes forming an address in the ELF file (either 4 or + /// 8), else zero if the address size could not be determined. + static unsigned + AddressSizeInBytes(const uint8_t *magic); +}; + +//------------------------------------------------------------------------------ +/// @class ELFSectionHeader +/// @brief Generic representation of an ELF section header. +struct ELFSectionHeader +{ + elf_word sh_name; ///< Section name string index. + elf_word sh_type; ///< Section type. + elf_xword sh_flags; ///< Section attributes. + elf_addr sh_addr; ///< Virtual address of the section in memory. + elf_off sh_offset; ///< Start of section from beginning of file. + elf_xword sh_size; ///< Number of bytes occupied in the file. + elf_word sh_link; ///< Index of associated section. + elf_word sh_info; ///< Extra section info (overloaded). + elf_xword sh_addralign; ///< Power of two alignment constraint. + elf_xword sh_entsize; ///< Byte size of each section entry. + + ELFSectionHeader(); + + //-------------------------------------------------------------------------- + /// Parse an ELFSectionHeader entry from the given DataExtracter starting at + /// position \p offset. + /// + /// @param[in] data + /// The DataExtractor to read from. The address size of the extractor + /// determines if a 32 or 64 bit object should be read. + /// + /// @param[in,out] offset + /// Pointer to an offset in the data. On return the offset will be + /// advanced by the number of bytes read. + /// + /// @return + /// True if the ELFSectionHeader was successfully read and false + /// otherwise. + bool + Parse(const lldb_private::DataExtractor &data, uint32_t *offset); +}; + +//------------------------------------------------------------------------------ +/// @class ELFProgramHeader +/// @brief Generic representation of an ELF program header. +struct ELFProgramHeader +{ + elf_word p_type; ///< Type of program segement. + elf_word p_flags; ///< Segement attibutes. + elf_off p_offset; ///< Start of segment from begining of file. + elf_addr p_vaddr; ///< Virtual address of segment in memory. + elf_addr p_paddr; ///< Physical address (for non-VM systems). + elf_xword p_filesz; ///< Byte size of the segment in file. + elf_xword p_memsz; ///< Byte size of the segment in memory. + elf_xword p_align; ///< Segement alignement constraint. + + ELFProgramHeader(); + + /// Parse an ELFProgramHeader entry from the given DataExtracter starting at + /// position \p offset. The address size of the DataExtracter determines if + /// a 32 or 64 bit object is to be parsed. + /// + /// @param[in] data + /// The DataExtractor to read from. The address size of the extractor + /// determines if a 32 or 64 bit object should be read. + /// + /// @param[in,out] offset + /// Pointer to an offset in the data. On return the offset will be + /// advanced by the number of bytes read. + /// + /// @return + /// True if the ELFProgramHeader was successfully read and false + /// otherwise. + bool + Parse(const lldb_private::DataExtractor &data, uint32_t *offset); +}; + +//------------------------------------------------------------------------------ +/// @class ELFSymbol +/// @brief Represents a symbol within an ELF symbol table. +struct ELFSymbol +{ + elf_addr st_value; ///< Absolute or relocatable address. + elf_xword st_size; ///< Size of the symbol or zero. + elf_word st_name; ///< Symbol name string index. + unsigned char st_info; ///< Symbol type and binding attributes. + unsigned char st_other; ///< Reserved for future use. + elf_half st_shndx; ///< Section to which this symbol applies. + + ELFSymbol(); + + /// Returns the binding attribute of the st_info member. + unsigned char getBinding() const { return st_info >> 4; } + + /// Returns the type attribute of the st_info member. + unsigned char getType() const { return st_info & 0x0F; } + + /// Sets the bining and type of the st_info member. + void setBindingAndType(unsigned char binding, unsigned char type) { + st_info = (binding << 4) + (type & 0x0F); + } + + /// Parse an ELFSymbol entry from the given DataExtracter starting at + /// position \p offset. The address size of the DataExtracter determines if + /// a 32 or 64 bit object is to be parsed. + /// + /// @param[in] data + /// The DataExtractor to read from. The address size of the extractor + /// determines if a 32 or 64 bit object should be read. + /// + /// @param[in,out] offset + /// Pointer to an offset in the data. On return the offset will be + /// advanced by the number of bytes read. + /// + /// @return + /// True if the ELFSymbol was successfully read and false otherwise. + bool + Parse(const lldb_private::DataExtractor &data, uint32_t *offset); +}; + +//------------------------------------------------------------------------------ +/// @class ELFDynamic +/// @brief Represents an entry in an ELF dynamic table. +struct ELFDynamic +{ + elf_sxword d_tag; ///< Type of dynamic table entry. + union + { + elf_xword d_val; ///< Integer value of the table entry. + elf_addr d_ptr; ///< Pointer value of the table entry. + }; + + ELFDynamic(); + + /// Parse an ELFDynamic entry from the given DataExtracter starting at + /// position \p offset. The address size of the DataExtracter determines if + /// a 32 or 64 bit object is to be parsed. + /// + /// @param[in] data + /// The DataExtractor to read from. The address size of the extractor + /// determines if a 32 or 64 bit object should be read. + /// + /// @param[in,out] offset + /// Pointer to an offset in the data. On return the offset will be + /// advanced by the number of bytes read. + /// + /// @return + /// True if the ELFDynamic entry was successfully read and false + /// otherwise. + bool + Parse(const lldb_private::DataExtractor &data, uint32_t *offset); +}; + +} // End namespace elf. + +#endif // #ifndef liblldb_ELFHeader_h_ Copied: lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp (from r108290, lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF64.cpp) URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp?p2=lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp&p1=lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF64.cpp&r1=108290&r2=108292&rev=108292&view=diff ============================================================================== --- lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF64.cpp (original) +++ lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp Tue Jul 13 18:07:23 2010 @@ -1,4 +1,4 @@ -//===-- ObjectFileELF64.cpp ----------------------------------- -*- C++ -*-===// +//===-- ObjectFileELF.cpp ------------------------------------- -*- C++ -*-===// // // The LLVM Compiler Infrastructure // @@ -7,10 +7,9 @@ // //===----------------------------------------------------------------------===// -#include "ObjectFileELF64.h" +#include "ObjectFileELF.h" #include - #include #include "lldb/Core/DataBuffer.h" @@ -25,9 +24,14 @@ using namespace lldb; using namespace lldb_private; +using namespace elf; +using namespace llvm::ELF; +//------------------------------------------------------------------ +// Static methods. +//------------------------------------------------------------------ void -ObjectFileELF64::Initialize() +ObjectFileELF::Initialize() { PluginManager::RegisterPlugin(GetPluginNameStatic(), GetPluginDescriptionStatic(), @@ -35,63 +39,94 @@ } void -ObjectFileELF64::Terminate() +ObjectFileELF::Terminate() { PluginManager::UnregisterPlugin(CreateInstance); } const char * -ObjectFileELF64::GetPluginNameStatic() +ObjectFileELF::GetPluginNameStatic() { - return "object-file.elf64"; + return "object-file.elf"; } const char * -ObjectFileELF64::GetPluginDescriptionStatic() +ObjectFileELF::GetPluginDescriptionStatic() { - return "ELF object file reader (64-bit)."; + return "ELF object file reader."; } ObjectFile * -ObjectFileELF64::CreateInstance(Module *module, - DataBufferSP &dataSP, - const FileSpec *file, addr_t offset, - addr_t length) -{ - if (ObjectFileELF64::MagicBytesMatch(dataSP)) - { - std::auto_ptr objfile_ap( - new ObjectFileELF64(module, dataSP, file, offset, length)); - if (objfile_ap->ParseHeader()) - return objfile_ap.release(); - } - return NULL; -} - -bool -ObjectFileELF64::MagicBytesMatch(DataBufferSP& data_sp) +ObjectFileELF::CreateInstance(Module *module, + DataBufferSP &data_sp, + const FileSpec *file, addr_t offset, + addr_t length) { - if (data_sp && data_sp->GetByteSize() > EI_PAD) + if (data_sp && data_sp->GetByteSize() > (llvm::ELF::EI_NIDENT + offset)) { - const uint8_t* magic = data_sp->GetBytes(); - if (magic != NULL) + const uint8_t *magic = data_sp->GetBytes() + offset; + if (ELFHeader::MagicBytesMatch(magic)) { - bool have_magic = (magic[EI_MAG0] == 0x7f && - magic[EI_MAG1] == 'E' && - magic[EI_MAG2] == 'L' && - magic[EI_MAG3] == 'F'); - - bool have_64bit = magic[EI_CLASS] == ELFCLASS64; - - return have_magic && have_64bit; + unsigned address_size = ELFHeader::AddressSizeInBytes(magic); + if (address_size == 4 || address_size == 8) + { + std::auto_ptr objfile_ap( + new ObjectFileELF(module, data_sp, file, offset, length)); + if (objfile_ap->ParseHeader()) + return objfile_ap.release(); + } } } - return false; + return NULL; +} + +//------------------------------------------------------------------ +// PluginInterface protocol +//------------------------------------------------------------------ +const char * +ObjectFileELF::GetPluginName() +{ + return "ObjectFileELF"; } -ObjectFileELF64::ObjectFileELF64(Module* module, DataBufferSP& dataSP, - const FileSpec* file, addr_t offset, - addr_t length) +const char * +ObjectFileELF::GetShortPluginName() +{ + return GetPluginNameStatic(); +} + +uint32_t +ObjectFileELF::GetPluginVersion() +{ + return m_plugin_version; +} + +void +ObjectFileELF::GetPluginCommandHelp(const char *command, Stream *strm) +{ +} + +Error +ObjectFileELF::ExecutePluginCommand(Args &command, Stream *strm) +{ + Error error; + error.SetErrorString("No plug-in commands are currently supported."); + return error; +} + +Log * +ObjectFileELF::EnablePluginLogging(Stream *strm, Args &command) +{ + return NULL; +} + +//------------------------------------------------------------------ +// ObjectFile protocol +//------------------------------------------------------------------ + +ObjectFileELF::ObjectFileELF(Module* module, DataBufferSP& dataSP, + const FileSpec* file, addr_t offset, + addr_t length) : ObjectFile(module, file, offset, length, dataSP), m_header(), m_program_headers(), @@ -106,13 +141,12 @@ ::memset(&m_header, 0, sizeof(m_header)); } - -ObjectFileELF64::~ObjectFileELF64() +ObjectFileELF::~ObjectFileELF() { } ByteOrder -ObjectFileELF64::GetByteOrder() const +ObjectFileELF::GetByteOrder() const { if (m_header.e_ident[EI_DATA] == ELFDATA2MSB) return eByteOrderBig; @@ -122,65 +156,39 @@ } size_t -ObjectFileELF64::GetAddressByteSize() const +ObjectFileELF::GetAddressByteSize() const { return m_data.GetAddressByteSize(); } unsigned -ObjectFileELF64::SectionIndex(const SectionHeaderCollIter &I) +ObjectFileELF::SectionIndex(const SectionHeaderCollIter &I) { return std::distance(m_section_headers.begin(), I) + 1; } unsigned -ObjectFileELF64::SectionIndex(const SectionHeaderCollConstIter &I) const +ObjectFileELF::SectionIndex(const SectionHeaderCollConstIter &I) const { return std::distance(m_section_headers.begin(), I) + 1; } bool -ObjectFileELF64::ParseHeader() +ObjectFileELF::ParseHeader() { - m_data.SetAddressByteSize(8); uint32_t offset = GetOffset(); - if (m_data.GetU8(&offset, m_header.e_ident, EI_NIDENT) == NULL) - return false; - - m_data.SetByteOrder(GetByteOrder()); - - // Read e_type and e_machine. - if (m_data.GetU16(&offset, &m_header.e_type, 2) == NULL) - return false; - - // Read e_version. - if (m_data.GetU32(&offset, &m_header.e_version, 1) == NULL) - return false; - - // Read e_entry, e_phoff and e_shoff. - if (m_data.GetU64(&offset, &m_header.e_entry, 3) == NULL) - return false; - - // Read e_flags. - if (m_data.GetU32(&offset, &m_header.e_flags, 1) == NULL) - return false; - - // Read e_ehsize, e_phentsize, e_phnum, e_shentsize, e_shnum and e_shstrndx. - if (m_data.GetU16(&offset, &m_header.e_ehsize, 6) == NULL) - return false; - - return true; + return m_header.Parse(m_data, &offset); } bool -ObjectFileELF64::GetUUID(UUID* uuid) +ObjectFileELF::GetUUID(UUID* uuid) { // FIXME: Return MD5 sum here. See comment in ObjectFile.h. return false; } uint32_t -ObjectFileELF64::GetDependentModules(FileSpecList &files) +ObjectFileELF::GetDependentModules(FileSpecList &files) { size_t num_modules = ParseDependentModules(); uint32_t num_specs = 0; @@ -198,7 +206,7 @@ // ParseDependentModules //---------------------------------------------------------------------- size_t -ObjectFileELF64::ParseDependentModules() +ObjectFileELF::ParseDependentModules() { if (m_filespec_ap.get()) return m_filespec_ap->GetSize(); @@ -241,24 +249,22 @@ if (dynsym->ReadSectionDataFromObjectFile(this, dynsym_data) && dynstr->ReadSectionDataFromObjectFile(this, dynstr_data)) { - Elf64_Dyn symbol; - const unsigned num_syms = dynsym_data.GetByteSize() / sizeof(Elf64_Dyn); + ELFDynamic symbol; + const unsigned section_size = dynsym_data.GetByteSize(); unsigned offset = 0; // The only type of entries we are concerned with are tagged DT_NEEDED, // yielding the name of a required library. - for (unsigned i = 0; i < num_syms; ++i) + while (offset < section_size) { - if (!dynsym_data.ValidOffsetForDataOfSize(offset, sizeof(Elf64_Dyn))) + if (!symbol.Parse(dynsym_data, &offset)) break; - symbol.d_tag = dynsym_data.GetU64(&offset); - symbol.d_un.d_val = dynsym_data.GetU64(&offset); - if (symbol.d_tag != DT_NEEDED) continue; - const char *lib_name = dynstr_data.PeekCStr(symbol.d_un.d_val); + uint32_t str_index = static_cast(symbol.d_val); + const char *lib_name = dynstr_data.PeekCStr(str_index); m_filespec_ap->Append(FileSpec(lib_name)); } } @@ -270,7 +276,7 @@ // ParseProgramHeaders //---------------------------------------------------------------------- size_t -ObjectFileELF64::ParseProgramHeaders() +ObjectFileELF::ParseProgramHeaders() { // We have already parsed the program headers if (!m_program_headers.empty()) @@ -285,7 +291,7 @@ return 0; const size_t ph_size = m_header.e_phnum * m_header.e_phentsize; - const Elf64_Off ph_offset = m_offset + m_header.e_phoff; + const elf_off ph_offset = m_offset + m_header.e_phoff; DataBufferSP buffer_sp(m_file.ReadFileContents(ph_offset, ph_size)); if (buffer_sp.get() == NULL || buffer_sp->GetByteSize() != ph_size) @@ -298,8 +304,8 @@ uint32_t offset; for (idx = 0, offset = 0; idx < m_header.e_phnum; ++idx) { - if (data.GetU32(&offset, &m_program_headers[idx], 8) == NULL) - return 0; + if (m_program_headers[idx].Parse(data, &offset) == false) + break; } if (idx < m_program_headers.size()) @@ -312,7 +318,7 @@ // ParseSectionHeaders //---------------------------------------------------------------------- size_t -ObjectFileELF64::ParseSectionHeaders() +ObjectFileELF::ParseSectionHeaders() { // We have already parsed the section headers if (!m_section_headers.empty()) @@ -327,7 +333,7 @@ return 0; const size_t sh_size = m_header.e_shnum * m_header.e_shentsize; - const Elf64_Off sh_offset = m_offset + m_header.e_shoff; + const elf_off sh_offset = m_offset + m_header.e_shoff; DataBufferSP buffer_sp(m_file.ReadFileContents(sh_offset, sh_size)); if (buffer_sp.get() == NULL || buffer_sp->GetByteSize() != sh_size) @@ -341,20 +347,7 @@ uint32_t offset; for (idx = 0, offset = 0; idx < m_header.e_shnum; ++idx) { - // Read sh_name and sh_type. - if (data.GetU32(&offset, &m_section_headers[idx].sh_name, 2) == NULL) - break; - - // Read sh_flags, sh_addr, sh_offset and sh_size. - if (data.GetU64(&offset, &m_section_headers[idx].sh_flags, 4) == NULL) - break; - - // Read sh_link and sh_info. - if (data.GetU32(&offset, &m_section_headers[idx].sh_link, 2) == NULL) - break; - - // Read sh_addralign and sh_entsize. - if (data.GetU64(&offset, &m_section_headers[idx].sh_addralign, 2) == NULL) + if (m_section_headers[idx].Parse(data, &offset) == false) break; } if (idx < m_section_headers.size()) @@ -364,13 +357,15 @@ } size_t -ObjectFileELF64::GetSectionHeaderStringTable() +ObjectFileELF::GetSectionHeaderStringTable() { if (m_shstr_data.GetByteSize() == 0) { - if (m_header.e_shstrndx && m_header.e_shstrndx < m_section_headers.size()) + const unsigned strtab_idx = m_header.e_shstrndx; + + if (strtab_idx && strtab_idx < m_section_headers.size()) { - const Elf64_Shdr &sheader = m_section_headers[m_header.e_shstrndx]; + const ELFSectionHeader &sheader = m_section_headers[strtab_idx]; const size_t byte_size = sheader.sh_size; const Elf64_Off offset = m_offset + sheader.sh_offset; DataBufferSP buffer_sp(m_file.ReadFileContents(offset, byte_size)); @@ -384,11 +379,11 @@ return m_shstr_data.GetByteSize(); } -uint32_t -ObjectFileELF64::GetSectionIndexByName(const char *name) +lldb::user_id_t +ObjectFileELF::GetSectionIndexByName(const char *name) { if (!(ParseSectionHeaders() && GetSectionHeaderStringTable())) - return UINT32_MAX; + return 0; // Search the collection of section headers for one with a matching name. for (SectionHeaderCollIter I = m_section_headers.begin(); @@ -397,7 +392,7 @@ const char *sectionName = m_shstr_data.PeekCStr(I->sh_name); if (!sectionName) - return UINT32_MAX; + return 0; if (strcmp(name, sectionName) != 0) continue; @@ -405,11 +400,11 @@ return SectionIndex(I); } - return UINT32_MAX; + return 0; } SectionList * -ObjectFileELF64::GetSectionList() +ObjectFileELF::GetSectionList() { if (m_sections_ap.get()) return m_sections_ap.get(); @@ -421,7 +416,7 @@ for (SectionHeaderCollIter I = m_section_headers.begin(); I != m_section_headers.end(); ++I) { - const Elf64_Shdr &header = *I; + const ELFSectionHeader &header = *I; ConstString name(m_shstr_data.PeekCStr(header.sh_name)); uint64_t size = header.sh_type == SHT_NOBITS ? 0 : header.sh_size; @@ -447,14 +442,14 @@ static void ParseSymbols(Symtab *symtab, SectionList *section_list, - const Elf64_Shdr &symtab_shdr, + const ELFSectionHeader &symtab_shdr, const DataExtractor &symtab_data, const DataExtractor &strtab_data) { - assert (sizeof(Elf64_Sym) == symtab_shdr.sh_entsize); - const unsigned numSymbols = symtab_data.GetByteSize() / sizeof(Elf64_Sym); - unsigned offset = 0; - Elf64_Sym symbol; + ELFSymbol symbol; + uint32_t offset = 0; + const unsigned numSymbols = + symtab_data.GetByteSize() / symtab_shdr.sh_entsize; static ConstString text_section_name(".text"); static ConstString init_section_name(".init"); @@ -470,16 +465,9 @@ for (unsigned i = 0; i < numSymbols; ++i) { - if (!symtab_data.ValidOffsetForDataOfSize(offset, sizeof(Elf64_Sym))) + if (symbol.Parse(symtab_data, &offset) == false) break; - symbol.st_name = symtab_data.GetU32(&offset); - symbol.st_info = symtab_data.GetU8(&offset); - symbol.st_other = symtab_data.GetU8(&offset); - symbol.st_shndx = symtab_data.GetU16(&offset); - symbol.st_value = symtab_data.GetU64(&offset); - symbol.st_size = symtab_data.GetU64(&offset); - Section *symbol_section = NULL; SymbolType symbol_type = eSymbolTypeInvalid; Elf64_Half symbol_idx = symbol.st_shndx; @@ -497,7 +485,7 @@ break; } - switch (ELF_ST_TYPE(symbol.st_info)) + switch (symbol.getType()) { default: case STT_NOTYPE: @@ -558,30 +546,30 @@ if (symbol_section != NULL) symbol_value -= symbol_section->GetFileAddress(); const char *symbol_name = strtab_data.PeekCStr(symbol.st_name); - bool is_global = ELF_ST_BIND(symbol.st_info) == STB_GLOBAL; + bool is_global = symbol.getBinding() == STB_GLOBAL; uint32_t flags = symbol.st_other << 8 | symbol.st_info; Symbol dc_symbol( i, // ID is the original symbol table index. - symbol_name, // symbol name. + symbol_name, // Symbol name. false, // Is the symbol name mangled? - symbol_type, // type of this symbol + symbol_type, // Type of this symbol is_global, // Is this globally visible? false, // Is this symbol debug info? false, // Is this symbol a trampoline? false, // Is this symbol artificial? symbol_section, // Section in which this symbol is defined or null. symbol_value, // Offset in section or symbol value. - symbol.st_size, // size in bytes of this symbol. + symbol.st_size, // Size in bytes of this symbol. flags); // Symbol flags. symtab->AddSymbol(dc_symbol); } } void -ObjectFileELF64::ParseSymbolTable(Symtab *symbol_table, - const Elf64_Shdr &symtab_hdr, - user_id_t symtab_id) +ObjectFileELF::ParseSymbolTable(Symtab *symbol_table, + const ELFSectionHeader &symtab_hdr, + user_id_t symtab_id) { assert(symtab_hdr.sh_type == SHT_SYMTAB || symtab_hdr.sh_type == SHT_DYNSYM); @@ -610,7 +598,7 @@ } Symtab * -ObjectFileELF64::GetSymtab() +ObjectFileELF::GetSymtab() { if (m_symtab_ap.get()) return m_symtab_ap.get(); @@ -625,9 +613,9 @@ for (SectionHeaderCollIter I = m_section_headers.begin(); I != m_section_headers.end(); ++I) { - if (I->sh_type == SHT_SYMTAB || I->sh_type == SHT_DYNSYM) + if (I->sh_type == SHT_SYMTAB) { - const Elf64_Shdr &symtab_section = *I; + const ELFSectionHeader &symtab_section = *I; user_id_t section_id = SectionIndex(I); ParseSymbolTable(symbol_table, symtab_section, section_id); } @@ -641,9 +629,9 @@ // // Dump the specifics of the runtime file container (such as any headers // segments, sections, etc). -// ---------------------------------------------------------------------- +//---------------------------------------------------------------------- void -ObjectFileELF64::Dump(Stream *s) +ObjectFileELF::Dump(Stream *s) { DumpELFHeader(s, m_header); s->EOL(); @@ -668,9 +656,8 @@ // Dump the ELF header to the specified output stream //---------------------------------------------------------------------- void -ObjectFileELF64::DumpELFHeader(Stream *s, const Elf64_Ehdr& header) +ObjectFileELF::DumpELFHeader(Stream *s, const ELFHeader &header) { - s->PutCString("ELF Header\n"); s->Printf("e_ident[EI_MAG0 ] = 0x%2.2x\n", header.e_ident[EI_MAG0]); s->Printf("e_ident[EI_MAG1 ] = 0x%2.2x '%c'\n", @@ -690,9 +677,9 @@ DumpELFHeader_e_type(s, header.e_type); s->Printf("\ne_machine = 0x%4.4x\n", header.e_machine); s->Printf("e_version = 0x%8.8x\n", header.e_version); - s->Printf("e_entry = 0x%8.8x\n", header.e_entry); - s->Printf("e_phoff = 0x%8.8x\n", header.e_phoff); - s->Printf("e_shoff = 0x%8.8x\n", header.e_shoff); + s->Printf("e_entry = 0x%8.8lx\n", header.e_entry); + s->Printf("e_phoff = 0x%8.8lx\n", header.e_phoff); + s->Printf("e_shoff = 0x%8.8lx\n", header.e_shoff); s->Printf("e_flags = 0x%8.8x\n", header.e_flags); s->Printf("e_ehsize = 0x%4.4x\n", header.e_ehsize); s->Printf("e_phentsize = 0x%4.4x\n", header.e_phentsize); @@ -708,7 +695,7 @@ // Dump an token value for the ELF header member e_type //---------------------------------------------------------------------- void -ObjectFileELF64::DumpELFHeader_e_type(Stream *s, Elf64_Half e_type) +ObjectFileELF::DumpELFHeader_e_type(Stream *s, elf_half e_type) { switch (e_type) { @@ -728,7 +715,7 @@ // Dump an token value for the ELF header member e_ident[EI_DATA] //---------------------------------------------------------------------- void -ObjectFileELF64::DumpELFHeader_e_ident_EI_DATA(Stream *s, unsigned char ei_data) +ObjectFileELF::DumpELFHeader_e_ident_EI_DATA(Stream *s, unsigned char ei_data) { switch (ei_data) { @@ -747,12 +734,12 @@ // Dump a single ELF program header to the specified output stream //---------------------------------------------------------------------- void -ObjectFileELF64::DumpELFProgramHeader(Stream *s, const Elf64_Phdr &ph) +ObjectFileELF::DumpELFProgramHeader(Stream *s, const ELFProgramHeader &ph) { DumpELFProgramHeader_p_type(s, ph.p_type); - s->Printf(" %8.8x %8.8x %8.8x %8.8x %8.8x %8.8x (", - ph.p_offset, ph.p_vaddr, ph.p_paddr, ph.p_filesz, ph.p_memsz, - ph.p_flags); + s->Printf(" %8.8lx %8.8lx %8.8lx", ph.p_offset, ph.p_vaddr, ph.p_paddr); + s->Printf(" %8.8lx %8.8lx %8.8lx (", ph.p_filesz, ph.p_memsz, ph.p_flags); + DumpELFProgramHeader_p_flags(s, ph.p_flags); s->Printf(") %8.8x", ph.p_align); } @@ -764,7 +751,7 @@ // describes the type of the program header // ---------------------------------------------------------------------- void -ObjectFileELF64::DumpELFProgramHeader_p_type(Stream *s, Elf64_Word p_type) +ObjectFileELF::DumpELFProgramHeader_p_type(Stream *s, elf_word p_type) { const int kStrWidth = 10; switch (p_type) @@ -789,7 +776,7 @@ // Dump an token value for the ELF program header member p_flags //---------------------------------------------------------------------- void -ObjectFileELF64::DumpELFProgramHeader_p_flags(Stream *s, Elf64_Word p_flags) +ObjectFileELF::DumpELFProgramHeader_p_flags(Stream *s, elf_word p_flags) { *s << ((p_flags & PF_X) ? "PF_X" : " ") << (((p_flags & PF_X) && (p_flags & PF_W)) ? '+' : ' ') @@ -804,7 +791,7 @@ // Dump all of the ELF program header to the specified output stream //---------------------------------------------------------------------- void -ObjectFileELF64::DumpELFProgramHeaders(Stream *s) +ObjectFileELF::DumpELFProgramHeaders(Stream *s) { if (ParseProgramHeaders()) { @@ -819,7 +806,7 @@ I != m_program_headers.end(); ++I, ++idx) { s->Printf("[%2u] ", idx); - ObjectFileELF64::DumpELFProgramHeader(s, *I); + ObjectFileELF::DumpELFProgramHeader(s, *I); s->EOL(); } } @@ -831,15 +818,15 @@ // Dump a single ELF section header to the specified output stream //---------------------------------------------------------------------- void -ObjectFileELF64::DumpELFSectionHeader(Stream *s, const Elf64_Shdr &sh) +ObjectFileELF::DumpELFSectionHeader(Stream *s, const ELFSectionHeader &sh) { s->Printf("%8.8x ", sh.sh_name); DumpELFSectionHeader_sh_type(s, sh.sh_type); - s->Printf(" %8.8x (", sh.sh_flags); + s->Printf(" %8.8lx (", sh.sh_flags); DumpELFSectionHeader_sh_flags(s, sh.sh_flags); - s->Printf(") %8.8x %8.8x %8.8x %8.8x %8.8x %8.8x %8.8x", - sh.sh_addr, sh.sh_offset, sh.sh_size, sh.sh_link, sh.sh_info, - sh.sh_addralign, sh.sh_entsize); + s->Printf(") %8.8lx %8.8lx %8.8lx", sh.sh_addr, sh.sh_offset, sh.sh_size); + s->Printf(" %8.8x %8.8x", sh.sh_link, sh.sh_info); + s->Printf(" %8.8lx %8.8lx", sh.sh_addralign, sh.sh_entsize); } //---------------------------------------------------------------------- @@ -849,7 +836,7 @@ // describes the type of the section //---------------------------------------------------------------------- void -ObjectFileELF64::DumpELFSectionHeader_sh_type(Stream *s, Elf64_Word sh_type) +ObjectFileELF::DumpELFSectionHeader_sh_type(Stream *s, elf_word sh_type) { const int kStrWidth = 12; switch (sh_type) @@ -882,7 +869,7 @@ // Dump an token value for the ELF section header member sh_flags //---------------------------------------------------------------------- void -ObjectFileELF64::DumpELFSectionHeader_sh_flags(Stream *s, Elf64_Word sh_flags) +ObjectFileELF::DumpELFSectionHeader_sh_flags(Stream *s, elf_word sh_flags) { *s << ((sh_flags & SHF_WRITE) ? "WRITE" : " ") << (((sh_flags & SHF_WRITE) && (sh_flags & SHF_ALLOC)) ? '+' : ' ') @@ -897,7 +884,7 @@ // Dump all of the ELF section header to the specified output stream //---------------------------------------------------------------------- void -ObjectFileELF64::DumpELFSectionHeaders(Stream *s) +ObjectFileELF::DumpELFSectionHeaders(Stream *s) { if (!(ParseSectionHeaders() && GetSectionHeaderStringTable())) return; @@ -915,7 +902,7 @@ I != m_section_headers.end(); ++I, ++idx) { s->Printf("[%2u] ", idx); - ObjectFileELF64::DumpELFSectionHeader(s, *I); + ObjectFileELF::DumpELFSectionHeader(s, *I); const char* section_name = m_shstr_data.PeekCStr(I->sh_name); if (section_name) *s << ' ' << section_name << "\n"; @@ -923,7 +910,7 @@ } void -ObjectFileELF64::DumpDependentModules(lldb_private::Stream *s) +ObjectFileELF::DumpDependentModules(lldb_private::Stream *s) { size_t num_modules = ParseDependentModules(); @@ -939,7 +926,7 @@ } bool -ObjectFileELF64::GetTargetTriple(ConstString &target_triple) +ObjectFileELF::GetTargetTriple(ConstString &target_triple) { static ConstString g_target_triple; @@ -976,42 +963,3 @@ return true; } -//------------------------------------------------------------------ -// PluginInterface protocol -//------------------------------------------------------------------ -const char * -ObjectFileELF64::GetPluginName() -{ - return "ObjectFileELF64"; -} - -const char * -ObjectFileELF64::GetShortPluginName() -{ - return GetPluginNameStatic(); -} - -uint32_t -ObjectFileELF64::GetPluginVersion() -{ - return 1; -} - -void -ObjectFileELF64::GetPluginCommandHelp (const char *command, Stream *strm) -{ -} - -Error -ObjectFileELF64::ExecutePluginCommand (Args &command, Stream *strm) -{ - Error error; - error.SetErrorString("No plug-in commands are currently supported."); - return error; -} - -Log * -ObjectFileELF64::EnablePluginLogging (Stream *strm, Args &command) -{ - return NULL; -} Copied: lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF.h (from r108290, lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF64.h) URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF.h?p2=lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF.h&p1=lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF64.h&r1=108290&r2=108292&rev=108292&view=diff ============================================================================== --- lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF64.h (original) +++ lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF.h Tue Jul 13 18:07:23 2010 @@ -1,4 +1,4 @@ -//===-- ObjectFileELF64.h ------------------------------------- -*- C++ -*-===// +//===-- ObjectFileELF.h --------------------------------------- -*- C++ -*-===// // // The LLVM Compiler Infrastructure // @@ -7,8 +7,8 @@ // //===----------------------------------------------------------------------===// -#ifndef liblldb_ObjectFileELF64_h_ -#define liblldb_ObjectFileELF64_h_ +#ifndef liblldb_ObjectFileELF_h_ +#define liblldb_ObjectFileELF_h_ #include #include @@ -17,13 +17,15 @@ #include "lldb/Core/FileSpec.h" #include "lldb/Symbol/ObjectFile.h" -#include "elf.h" +#include "ELFHeader.h" -//---------------------------------------------------------------------- -// This class needs to be hidden as eventually belongs in a plugin that -// will export the ObjectFile protocol -//---------------------------------------------------------------------- -class ObjectFileELF64 : +//------------------------------------------------------------------------------ +/// @class ObjectFileELF +/// @brief Generic ELF object file reader. +/// +/// This class provides a generic ELF (32/64 bit) reader plugin implementing the +/// ObjectFile protocol. +class ObjectFileELF : public lldb_private::ObjectFile { public: @@ -49,20 +51,34 @@ lldb::addr_t offset, lldb::addr_t length); - static bool - MagicBytesMatch(lldb::DataBufferSP& dataSP); - //------------------------------------------------------------------ - // Member Functions + // PluginInterface protocol //------------------------------------------------------------------ - ObjectFileELF64(lldb_private::Module* module, - lldb::DataBufferSP& dataSP, - const lldb_private::FileSpec* file, - lldb::addr_t offset, - lldb::addr_t length); + virtual const char * + GetPluginName(); + + virtual const char * + GetShortPluginName(); + + virtual uint32_t + GetPluginVersion(); + virtual void + GetPluginCommandHelp(const char *command, lldb_private::Stream *strm); + + virtual lldb_private::Error + ExecutePluginCommand(lldb_private::Args &command, + lldb_private::Stream *strm); + + virtual lldb_private::Log * + EnablePluginLogging(lldb_private::Stream *strm, + lldb_private::Args &command); + + //------------------------------------------------------------------ + // ObjectFile Protocol. + //------------------------------------------------------------------ virtual - ~ObjectFileELF64(); + ~ObjectFileELF(); virtual bool ParseHeader(); @@ -91,119 +107,144 @@ virtual uint32_t GetDependentModules(lldb_private::FileSpecList& files); - //------------------------------------------------------------------ - // PluginInterface protocol - //------------------------------------------------------------------ - virtual const char * - GetPluginName(); - - virtual const char * - GetShortPluginName(); - - virtual uint32_t - GetPluginVersion(); - - virtual void - GetPluginCommandHelp(const char *command, lldb_private::Stream *strm); - - virtual lldb_private::Error - ExecutePluginCommand(lldb_private::Args &command, - lldb_private::Stream *strm); - - virtual lldb_private::Log * - EnablePluginLogging(lldb_private::Stream *strm, - lldb_private::Args &command); +private: + ObjectFileELF(lldb_private::Module* module, + lldb::DataBufferSP& dataSP, + const lldb_private::FileSpec* file, + lldb::addr_t offset, + lldb::addr_t length); -protected: - typedef std::vector ProgramHeaderColl; + typedef std::vector ProgramHeaderColl; typedef ProgramHeaderColl::iterator ProgramHeaderCollIter; typedef ProgramHeaderColl::const_iterator ProgramHeaderCollConstIter; - typedef std::vector SectionHeaderColl; + typedef std::vector SectionHeaderColl; typedef SectionHeaderColl::iterator SectionHeaderCollIter; typedef SectionHeaderColl::const_iterator SectionHeaderCollConstIter; - Elf64_Ehdr m_header; + /// Version of this reader common to all plugins based on this class. + static const uint32_t m_plugin_version = 1; + + /// ELF file header. + elf::ELFHeader m_header; + + /// Collection of program headers. ProgramHeaderColl m_program_headers; + + /// Collection of section headers. SectionHeaderColl m_section_headers; + + /// List of sections present in this ELF object file. mutable std::auto_ptr m_sections_ap; + + /// Table of all non-dynamic symbols present in this object file. mutable std::auto_ptr m_symtab_ap; - mutable std::auto_ptr m_filespec_ap; - lldb_private::DataExtractor m_shstr_data; - size_t - ParseSections(); + /// List of file specifications corresponding to the modules (shared + /// libraries) on which this object file depends. + mutable std::auto_ptr m_filespec_ap; - size_t - ParseSymtab(bool minimize); + /// Data extractor holding the string table used to resolve section names. + lldb_private::DataExtractor m_shstr_data; -private: - // Returns the 1 based index of a section header. + /// Returns a 1 based index of the given section header. unsigned SectionIndex(const SectionHeaderCollIter &I); + /// Returns a 1 based index of the given section header. unsigned SectionIndex(const SectionHeaderCollConstIter &I) const; - // ELF header dump routines + /// Parses all section headers present in this object file and populates + /// m_program_headers. This method will compute the header list only once. + /// Returns the number of headers parsed. + size_t + ParseProgramHeaders(); + + /// Parses all section headers present in this object file and populates + /// m_section_headers. This method will compute the header list only once. + /// Returns the number of headers parsed. + size_t + ParseSectionHeaders(); + + /// Scans the dynamic section and locates all dependent modules (shared + /// libaries) populating m_filespec_ap. This method will compute the + /// dependent module list only once. Returns the number of dependent + /// modules parsed. + size_t + ParseDependentModules(); + + /// Populates m_symtab_ap will all non-dynamic linker symbols. This method + /// will parse the symbols only once. Returns the number of symbols parsed. + void + ParseSymbolTable(lldb_private::Symtab *symbol_table, + const elf::ELFSectionHeader &symtab_section, + lldb::user_id_t symtab_id); + + /// Loads the section name string table into m_shstr_data. Returns the + /// number of bytes constituting the table. + size_t + GetSectionHeaderStringTable(); + + /// Utility method for looking up a section given its name. Returns the + /// index of the corresponding section or zero if no section with the given + /// name can be found (note that section indices are always 1 based, and so + /// section index 0 is never valid). + lldb::user_id_t + GetSectionIndexByName(const char *name); + + /// @name ELF header dump routines + //@{ static void - DumpELFHeader(lldb_private::Stream *s, const Elf64_Ehdr& header); + DumpELFHeader(lldb_private::Stream *s, const elf::ELFHeader& header); static void - DumpELFHeader_e_ident_EI_DATA(lldb_private::Stream *s, + DumpELFHeader_e_ident_EI_DATA(lldb_private::Stream *s, unsigned char ei_data); static void - DumpELFHeader_e_type(lldb_private::Stream *s, Elf64_Half e_type); + DumpELFHeader_e_type(lldb_private::Stream *s, elf::elf_half e_type); + //@} - // ELF program header dump routines + /// @name ELF program header dump routines + //@{ void DumpELFProgramHeaders(lldb_private::Stream *s); static void - DumpELFProgramHeader(lldb_private::Stream *s, const Elf64_Phdr &ph); + DumpELFProgramHeader(lldb_private::Stream *s, + const elf::ELFProgramHeader &ph); static void - DumpELFProgramHeader_p_type(lldb_private::Stream *s, Elf64_Word p_type); + DumpELFProgramHeader_p_type(lldb_private::Stream *s, elf::elf_word p_type); static void - DumpELFProgramHeader_p_flags(lldb_private::Stream *s, Elf64_Word p_flags); + DumpELFProgramHeader_p_flags(lldb_private::Stream *s, + elf::elf_word p_flags); + //@} - // ELF section header dump routines + /// @name ELF section header dump routines + //@{ void DumpELFSectionHeaders(lldb_private::Stream *s); static void - DumpELFSectionHeader(lldb_private::Stream *s, const Elf64_Shdr& sh); + DumpELFSectionHeader(lldb_private::Stream *s, + const elf::ELFSectionHeader& sh); static void - DumpELFSectionHeader_sh_type(lldb_private::Stream *s, Elf64_Word sh_type); + DumpELFSectionHeader_sh_type(lldb_private::Stream *s, + elf::elf_word sh_type); static void - DumpELFSectionHeader_sh_flags(lldb_private::Stream *s, Elf64_Word sh_flags); + DumpELFSectionHeader_sh_flags(lldb_private::Stream *s, + elf::elf_word sh_flags); + //@} + /// ELF dependent module dump routine. void DumpDependentModules(lldb_private::Stream *s); - size_t - ParseProgramHeaders(); - - size_t - ParseSectionHeaders(); - - size_t - ParseDependentModules(); - - void - ParseSymbolTable(lldb_private::Symtab *symbol_table, - const Elf64_Shdr &symtab_section, - lldb::user_id_t symtab_id); - - size_t - GetSectionHeaderStringTable(); - - uint32_t - GetSectionIndexByName(const char *name); }; -#endif // #ifndef liblldb_ObjectFileELF64_h_ +#endif // #ifndef liblldb_ObjectFileELF_h_ Removed: lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF64.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF64.cpp?rev=108291&view=auto ============================================================================== --- lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF64.cpp (original) +++ lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF64.cpp (removed) @@ -1,1017 +0,0 @@ -//===-- ObjectFileELF64.cpp ----------------------------------- -*- C++ -*-===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -#include "ObjectFileELF64.h" - -#include - -#include - -#include "lldb/Core/DataBuffer.h" -#include "lldb/Core/Error.h" -#include "lldb/Core/FileSpecList.h" -#include "lldb/Core/PluginManager.h" -#include "lldb/Core/Section.h" -#include "lldb/Core/Stream.h" - -#define CASE_AND_STREAM(s, def, width) \ - case def: s->Printf("%-*s", width, #def); break; - -using namespace lldb; -using namespace lldb_private; - -void -ObjectFileELF64::Initialize() -{ - PluginManager::RegisterPlugin(GetPluginNameStatic(), - GetPluginDescriptionStatic(), - CreateInstance); -} - -void -ObjectFileELF64::Terminate() -{ - PluginManager::UnregisterPlugin(CreateInstance); -} - -const char * -ObjectFileELF64::GetPluginNameStatic() -{ - return "object-file.elf64"; -} - -const char * -ObjectFileELF64::GetPluginDescriptionStatic() -{ - return "ELF object file reader (64-bit)."; -} - -ObjectFile * -ObjectFileELF64::CreateInstance(Module *module, - DataBufferSP &dataSP, - const FileSpec *file, addr_t offset, - addr_t length) -{ - if (ObjectFileELF64::MagicBytesMatch(dataSP)) - { - std::auto_ptr objfile_ap( - new ObjectFileELF64(module, dataSP, file, offset, length)); - if (objfile_ap->ParseHeader()) - return objfile_ap.release(); - } - return NULL; -} - -bool -ObjectFileELF64::MagicBytesMatch(DataBufferSP& data_sp) -{ - if (data_sp && data_sp->GetByteSize() > EI_PAD) - { - const uint8_t* magic = data_sp->GetBytes(); - if (magic != NULL) - { - bool have_magic = (magic[EI_MAG0] == 0x7f && - magic[EI_MAG1] == 'E' && - magic[EI_MAG2] == 'L' && - magic[EI_MAG3] == 'F'); - - bool have_64bit = magic[EI_CLASS] == ELFCLASS64; - - return have_magic && have_64bit; - } - } - return false; -} - -ObjectFileELF64::ObjectFileELF64(Module* module, DataBufferSP& dataSP, - const FileSpec* file, addr_t offset, - addr_t length) - : ObjectFile(module, file, offset, length, dataSP), - m_header(), - m_program_headers(), - m_section_headers(), - m_sections_ap(), - m_symtab_ap(), - m_filespec_ap(), - m_shstr_data() -{ - if (file) - m_file = *file; - ::memset(&m_header, 0, sizeof(m_header)); -} - - -ObjectFileELF64::~ObjectFileELF64() -{ -} - -ByteOrder -ObjectFileELF64::GetByteOrder() const -{ - if (m_header.e_ident[EI_DATA] == ELFDATA2MSB) - return eByteOrderBig; - if (m_header.e_ident[EI_DATA] == ELFDATA2LSB) - return eByteOrderLittle; - return eByteOrderInvalid; -} - -size_t -ObjectFileELF64::GetAddressByteSize() const -{ - return m_data.GetAddressByteSize(); -} - -unsigned -ObjectFileELF64::SectionIndex(const SectionHeaderCollIter &I) -{ - return std::distance(m_section_headers.begin(), I) + 1; -} - -unsigned -ObjectFileELF64::SectionIndex(const SectionHeaderCollConstIter &I) const -{ - return std::distance(m_section_headers.begin(), I) + 1; -} - -bool -ObjectFileELF64::ParseHeader() -{ - m_data.SetAddressByteSize(8); - uint32_t offset = GetOffset(); - if (m_data.GetU8(&offset, m_header.e_ident, EI_NIDENT) == NULL) - return false; - - m_data.SetByteOrder(GetByteOrder()); - - // Read e_type and e_machine. - if (m_data.GetU16(&offset, &m_header.e_type, 2) == NULL) - return false; - - // Read e_version. - if (m_data.GetU32(&offset, &m_header.e_version, 1) == NULL) - return false; - - // Read e_entry, e_phoff and e_shoff. - if (m_data.GetU64(&offset, &m_header.e_entry, 3) == NULL) - return false; - - // Read e_flags. - if (m_data.GetU32(&offset, &m_header.e_flags, 1) == NULL) - return false; - - // Read e_ehsize, e_phentsize, e_phnum, e_shentsize, e_shnum and e_shstrndx. - if (m_data.GetU16(&offset, &m_header.e_ehsize, 6) == NULL) - return false; - - return true; -} - -bool -ObjectFileELF64::GetUUID(UUID* uuid) -{ - // FIXME: Return MD5 sum here. See comment in ObjectFile.h. - return false; -} - -uint32_t -ObjectFileELF64::GetDependentModules(FileSpecList &files) -{ - size_t num_modules = ParseDependentModules(); - uint32_t num_specs = 0; - - for (unsigned i = 0; i < num_modules; ++i) - { - if (files.AppendIfUnique(m_filespec_ap->GetFileSpecAtIndex(i))) - num_specs++; - } - - return num_specs; -} - -//---------------------------------------------------------------------- -// ParseDependentModules -//---------------------------------------------------------------------- -size_t -ObjectFileELF64::ParseDependentModules() -{ - if (m_filespec_ap.get()) - return m_filespec_ap->GetSize(); - - m_filespec_ap.reset(new FileSpecList()); - - if (!(ParseSectionHeaders() && GetSectionHeaderStringTable())) - return 0; - - // Locate the dynamic table. - user_id_t dynsym_id = 0; - user_id_t dynstr_id = 0; - for (SectionHeaderCollIter I = m_section_headers.begin(); - I != m_section_headers.end(); ++I) - { - if (I->sh_type == SHT_DYNAMIC) - { - dynsym_id = SectionIndex(I); - dynstr_id = I->sh_link + 1; // Section ID's are 1 based. - break; - } - } - - if (!(dynsym_id && dynstr_id)) - return 0; - - SectionList *section_list = GetSectionList(); - if (!section_list) - return 0; - - // Resolve and load the dynamic table entries and corresponding string - // table. - Section *dynsym = section_list->FindSectionByID(dynsym_id).get(); - Section *dynstr = section_list->FindSectionByID(dynstr_id).get(); - if (!(dynsym && dynstr)) - return 0; - - DataExtractor dynsym_data; - DataExtractor dynstr_data; - if (dynsym->ReadSectionDataFromObjectFile(this, dynsym_data) && - dynstr->ReadSectionDataFromObjectFile(this, dynstr_data)) - { - Elf64_Dyn symbol; - const unsigned num_syms = dynsym_data.GetByteSize() / sizeof(Elf64_Dyn); - unsigned offset = 0; - - // The only type of entries we are concerned with are tagged DT_NEEDED, - // yielding the name of a required library. - for (unsigned i = 0; i < num_syms; ++i) - { - if (!dynsym_data.ValidOffsetForDataOfSize(offset, sizeof(Elf64_Dyn))) - break; - - symbol.d_tag = dynsym_data.GetU64(&offset); - symbol.d_un.d_val = dynsym_data.GetU64(&offset); - - if (symbol.d_tag != DT_NEEDED) - continue; - - const char *lib_name = dynstr_data.PeekCStr(symbol.d_un.d_val); - m_filespec_ap->Append(FileSpec(lib_name)); - } - } - - return m_filespec_ap->GetSize(); -} - -//---------------------------------------------------------------------- -// ParseProgramHeaders -//---------------------------------------------------------------------- -size_t -ObjectFileELF64::ParseProgramHeaders() -{ - // We have already parsed the program headers - if (!m_program_headers.empty()) - return m_program_headers.size(); - - // If there are no program headers to read we are done. - if (m_header.e_phnum == 0) - return 0; - - m_program_headers.resize(m_header.e_phnum); - if (m_program_headers.size() != m_header.e_phnum) - return 0; - - const size_t ph_size = m_header.e_phnum * m_header.e_phentsize; - const Elf64_Off ph_offset = m_offset + m_header.e_phoff; - DataBufferSP buffer_sp(m_file.ReadFileContents(ph_offset, ph_size)); - - if (buffer_sp.get() == NULL || buffer_sp->GetByteSize() != ph_size) - return 0; - - DataExtractor data(buffer_sp, m_data.GetByteOrder(), - m_data.GetAddressByteSize()); - - uint32_t idx; - uint32_t offset; - for (idx = 0, offset = 0; idx < m_header.e_phnum; ++idx) - { - if (data.GetU32(&offset, &m_program_headers[idx], 8) == NULL) - return 0; - } - - if (idx < m_program_headers.size()) - m_program_headers.resize(idx); - - return m_program_headers.size(); -} - -//---------------------------------------------------------------------- -// ParseSectionHeaders -//---------------------------------------------------------------------- -size_t -ObjectFileELF64::ParseSectionHeaders() -{ - // We have already parsed the section headers - if (!m_section_headers.empty()) - return m_section_headers.size(); - - // If there are no section headers we are done. - if (m_header.e_shnum == 0) - return 0; - - m_section_headers.resize(m_header.e_shnum); - if (m_section_headers.size() != m_header.e_shnum) - return 0; - - const size_t sh_size = m_header.e_shnum * m_header.e_shentsize; - const Elf64_Off sh_offset = m_offset + m_header.e_shoff; - DataBufferSP buffer_sp(m_file.ReadFileContents(sh_offset, sh_size)); - - if (buffer_sp.get() == NULL || buffer_sp->GetByteSize() != sh_size) - return 0; - - DataExtractor data(buffer_sp, - m_data.GetByteOrder(), - m_data.GetAddressByteSize()); - - uint32_t idx; - uint32_t offset; - for (idx = 0, offset = 0; idx < m_header.e_shnum; ++idx) - { - // Read sh_name and sh_type. - if (data.GetU32(&offset, &m_section_headers[idx].sh_name, 2) == NULL) - break; - - // Read sh_flags, sh_addr, sh_offset and sh_size. - if (data.GetU64(&offset, &m_section_headers[idx].sh_flags, 4) == NULL) - break; - - // Read sh_link and sh_info. - if (data.GetU32(&offset, &m_section_headers[idx].sh_link, 2) == NULL) - break; - - // Read sh_addralign and sh_entsize. - if (data.GetU64(&offset, &m_section_headers[idx].sh_addralign, 2) == NULL) - break; - } - if (idx < m_section_headers.size()) - m_section_headers.resize(idx); - - return m_section_headers.size(); -} - -size_t -ObjectFileELF64::GetSectionHeaderStringTable() -{ - if (m_shstr_data.GetByteSize() == 0) - { - if (m_header.e_shstrndx && m_header.e_shstrndx < m_section_headers.size()) - { - const Elf64_Shdr &sheader = m_section_headers[m_header.e_shstrndx]; - const size_t byte_size = sheader.sh_size; - const Elf64_Off offset = m_offset + sheader.sh_offset; - DataBufferSP buffer_sp(m_file.ReadFileContents(offset, byte_size)); - - if (buffer_sp.get() == NULL || buffer_sp->GetByteSize() != byte_size) - return 0; - - m_shstr_data.SetData(buffer_sp); - } - } - return m_shstr_data.GetByteSize(); -} - -uint32_t -ObjectFileELF64::GetSectionIndexByName(const char *name) -{ - if (!(ParseSectionHeaders() && GetSectionHeaderStringTable())) - return UINT32_MAX; - - // Search the collection of section headers for one with a matching name. - for (SectionHeaderCollIter I = m_section_headers.begin(); - I != m_section_headers.end(); ++I) - { - const char *sectionName = m_shstr_data.PeekCStr(I->sh_name); - - if (!sectionName) - return UINT32_MAX; - - if (strcmp(name, sectionName) != 0) - continue; - - return SectionIndex(I); - } - - return UINT32_MAX; -} - -SectionList * -ObjectFileELF64::GetSectionList() -{ - if (m_sections_ap.get()) - return m_sections_ap.get(); - - if (ParseSectionHeaders() && GetSectionHeaderStringTable()) - { - m_sections_ap.reset(new SectionList()); - - for (SectionHeaderCollIter I = m_section_headers.begin(); - I != m_section_headers.end(); ++I) - { - const Elf64_Shdr &header = *I; - - ConstString name(m_shstr_data.PeekCStr(header.sh_name)); - uint64_t size = header.sh_type == SHT_NOBITS ? 0 : header.sh_size; - - SectionSP section(new Section( - 0, // Parent section. - GetModule(), // Module to which this section belongs. - SectionIndex(I), // Section ID. - name, // Section name. - eSectionTypeOther, // FIXME: Fill in as appropriate. - header.sh_addr, // VM address. - header.sh_size, // VM size in bytes of this section. - header.sh_offset, // Offset of this section in the file. - size, // Size of the section as found in the file. - header.sh_flags)); // Flags for this section. - - m_sections_ap->AddSection(section); - } - } - - return m_sections_ap.get(); -} - -static void -ParseSymbols(Symtab *symtab, SectionList *section_list, - const Elf64_Shdr &symtab_shdr, - const DataExtractor &symtab_data, - const DataExtractor &strtab_data) -{ - assert (sizeof(Elf64_Sym) == symtab_shdr.sh_entsize); - const unsigned numSymbols = symtab_data.GetByteSize() / sizeof(Elf64_Sym); - unsigned offset = 0; - Elf64_Sym symbol; - - static ConstString text_section_name(".text"); - static ConstString init_section_name(".init"); - static ConstString fini_section_name(".fini"); - static ConstString ctors_section_name(".ctors"); - static ConstString dtors_section_name(".dtors"); - - static ConstString data_section_name(".data"); - static ConstString rodata_section_name(".rodata"); - static ConstString rodata1_section_name(".rodata1"); - static ConstString data2_section_name(".data1"); - static ConstString bss_section_name(".bss"); - - for (unsigned i = 0; i < numSymbols; ++i) - { - if (!symtab_data.ValidOffsetForDataOfSize(offset, sizeof(Elf64_Sym))) - break; - - symbol.st_name = symtab_data.GetU32(&offset); - symbol.st_info = symtab_data.GetU8(&offset); - symbol.st_other = symtab_data.GetU8(&offset); - symbol.st_shndx = symtab_data.GetU16(&offset); - symbol.st_value = symtab_data.GetU64(&offset); - symbol.st_size = symtab_data.GetU64(&offset); - - Section *symbol_section = NULL; - SymbolType symbol_type = eSymbolTypeInvalid; - Elf64_Half symbol_idx = symbol.st_shndx; - - switch (symbol_idx) - { - case SHN_ABS: - symbol_type = eSymbolTypeAbsolute; - break; - case SHN_UNDEF: - symbol_type = eSymbolTypeUndefined; - break; - default: - symbol_section = section_list->GetSectionAtIndex(symbol_idx).get(); - break; - } - - switch (ELF_ST_TYPE(symbol.st_info)) - { - default: - case STT_NOTYPE: - // The symbol's type is not specified. - break; - - case STT_OBJECT: - // The symbol is associated with a data object, such as a variable, - // an array, etc. - symbol_type = eSymbolTypeData; - break; - - case STT_FUNC: - // The symbol is associated with a function or other executable code. - symbol_type = eSymbolTypeCode; - break; - - case STT_SECTION: - // The symbol is associated with a section. Symbol table entries of - // this type exist primarily for relocation and normally have - // STB_LOCAL binding. - break; - - case STT_FILE: - // Conventionally, the symbol's name gives the name of the source - // file associated with the object file. A file symbol has STB_LOCAL - // binding, its section index is SHN_ABS, and it precedes the other - // STB_LOCAL symbols for the file, if it is present. - symbol_type = eSymbolTypeObjectFile; - break; - } - - if (symbol_type == eSymbolTypeInvalid) - { - if (symbol_section) - { - const ConstString §_name = symbol_section->GetName(); - if (sect_name == text_section_name || - sect_name == init_section_name || - sect_name == fini_section_name || - sect_name == ctors_section_name || - sect_name == dtors_section_name) - { - symbol_type = eSymbolTypeCode; - } - else if (sect_name == data_section_name || - sect_name == data2_section_name || - sect_name == rodata_section_name || - sect_name == rodata1_section_name || - sect_name == bss_section_name) - { - symbol_type = eSymbolTypeData; - } - } - } - - uint64_t symbol_value = symbol.st_value; - if (symbol_section != NULL) - symbol_value -= symbol_section->GetFileAddress(); - const char *symbol_name = strtab_data.PeekCStr(symbol.st_name); - bool is_global = ELF_ST_BIND(symbol.st_info) == STB_GLOBAL; - uint32_t flags = symbol.st_other << 8 | symbol.st_info; - - Symbol dc_symbol( - i, // ID is the original symbol table index. - symbol_name, // symbol name. - false, // Is the symbol name mangled? - symbol_type, // type of this symbol - is_global, // Is this globally visible? - false, // Is this symbol debug info? - false, // Is this symbol a trampoline? - false, // Is this symbol artificial? - symbol_section, // Section in which this symbol is defined or null. - symbol_value, // Offset in section or symbol value. - symbol.st_size, // size in bytes of this symbol. - flags); // Symbol flags. - symtab->AddSymbol(dc_symbol); - } -} - -void -ObjectFileELF64::ParseSymbolTable(Symtab *symbol_table, - const Elf64_Shdr &symtab_hdr, - user_id_t symtab_id) -{ - assert(symtab_hdr.sh_type == SHT_SYMTAB || - symtab_hdr.sh_type == SHT_DYNSYM); - - // Parse in the section list if needed. - SectionList *section_list = GetSectionList(); - if (!section_list) - return; - - // Section ID's are ones based. - user_id_t strtab_id = symtab_hdr.sh_link + 1; - - Section *symtab = section_list->FindSectionByID(symtab_id).get(); - Section *strtab = section_list->FindSectionByID(strtab_id).get(); - if (symtab && strtab) - { - DataExtractor symtab_data; - DataExtractor strtab_data; - if (symtab->ReadSectionDataFromObjectFile(this, symtab_data) && - strtab->ReadSectionDataFromObjectFile(this, strtab_data)) - { - ParseSymbols(symbol_table, section_list, symtab_hdr, - symtab_data, strtab_data); - } - } -} - -Symtab * -ObjectFileELF64::GetSymtab() -{ - if (m_symtab_ap.get()) - return m_symtab_ap.get(); - - Symtab *symbol_table = new Symtab(this); - m_symtab_ap.reset(symbol_table); - - if (!(ParseSectionHeaders() && GetSectionHeaderStringTable())) - return symbol_table; - - // Locate and parse all linker symbol tables. - for (SectionHeaderCollIter I = m_section_headers.begin(); - I != m_section_headers.end(); ++I) - { - if (I->sh_type == SHT_SYMTAB || I->sh_type == SHT_DYNSYM) - { - const Elf64_Shdr &symtab_section = *I; - user_id_t section_id = SectionIndex(I); - ParseSymbolTable(symbol_table, symtab_section, section_id); - } - } - - return symbol_table; -} - -//===----------------------------------------------------------------------===// -// Dump -// -// Dump the specifics of the runtime file container (such as any headers -// segments, sections, etc). -// ---------------------------------------------------------------------- -void -ObjectFileELF64::Dump(Stream *s) -{ - DumpELFHeader(s, m_header); - s->EOL(); - DumpELFProgramHeaders(s); - s->EOL(); - DumpELFSectionHeaders(s); - s->EOL(); - SectionList *section_list = GetSectionList(); - if (section_list) - section_list->Dump(s, NULL, true); - Symtab *symtab = GetSymtab(); - if (symtab) - symtab->Dump(s, NULL); - s->EOL(); - DumpDependentModules(s); - s->EOL(); -} - -//---------------------------------------------------------------------- -// DumpELFHeader -// -// Dump the ELF header to the specified output stream -//---------------------------------------------------------------------- -void -ObjectFileELF64::DumpELFHeader(Stream *s, const Elf64_Ehdr& header) -{ - - s->PutCString("ELF Header\n"); - s->Printf("e_ident[EI_MAG0 ] = 0x%2.2x\n", header.e_ident[EI_MAG0]); - s->Printf("e_ident[EI_MAG1 ] = 0x%2.2x '%c'\n", - header.e_ident[EI_MAG1], header.e_ident[EI_MAG1]); - s->Printf("e_ident[EI_MAG2 ] = 0x%2.2x '%c'\n", - header.e_ident[EI_MAG2], header.e_ident[EI_MAG2]); - s->Printf("e_ident[EI_MAG3 ] = 0x%2.2x '%c'\n", - header.e_ident[EI_MAG3], header.e_ident[EI_MAG3]); - - s->Printf("e_ident[EI_CLASS ] = 0x%2.2x\n", header.e_ident[EI_CLASS]); - s->Printf("e_ident[EI_DATA ] = 0x%2.2x ", header.e_ident[EI_DATA]); - DumpELFHeader_e_ident_EI_DATA(s, header.e_ident[EI_DATA]); - s->Printf ("\ne_ident[EI_VERSION] = 0x%2.2x\n", header.e_ident[EI_VERSION]); - s->Printf ("e_ident[EI_PAD ] = 0x%2.2x\n", header.e_ident[EI_PAD]); - - s->Printf("e_type = 0x%4.4x ", header.e_type); - DumpELFHeader_e_type(s, header.e_type); - s->Printf("\ne_machine = 0x%4.4x\n", header.e_machine); - s->Printf("e_version = 0x%8.8x\n", header.e_version); - s->Printf("e_entry = 0x%8.8x\n", header.e_entry); - s->Printf("e_phoff = 0x%8.8x\n", header.e_phoff); - s->Printf("e_shoff = 0x%8.8x\n", header.e_shoff); - s->Printf("e_flags = 0x%8.8x\n", header.e_flags); - s->Printf("e_ehsize = 0x%4.4x\n", header.e_ehsize); - s->Printf("e_phentsize = 0x%4.4x\n", header.e_phentsize); - s->Printf("e_phnum = 0x%4.4x\n", header.e_phnum); - s->Printf("e_shentsize = 0x%4.4x\n", header.e_shentsize); - s->Printf("e_shnum = 0x%4.4x\n", header.e_shnum); - s->Printf("e_shstrndx = 0x%4.4x\n", header.e_shstrndx); -} - -//---------------------------------------------------------------------- -// DumpELFHeader_e_type -// -// Dump an token value for the ELF header member e_type -//---------------------------------------------------------------------- -void -ObjectFileELF64::DumpELFHeader_e_type(Stream *s, Elf64_Half e_type) -{ - switch (e_type) - { - case ET_NONE: *s << "ET_NONE"; break; - case ET_REL: *s << "ET_REL"; break; - case ET_EXEC: *s << "ET_EXEC"; break; - case ET_DYN: *s << "ET_DYN"; break; - case ET_CORE: *s << "ET_CORE"; break; - default: - break; - } -} - -//---------------------------------------------------------------------- -// DumpELFHeader_e_ident_EI_DATA -// -// Dump an token value for the ELF header member e_ident[EI_DATA] -//---------------------------------------------------------------------- -void -ObjectFileELF64::DumpELFHeader_e_ident_EI_DATA(Stream *s, unsigned char ei_data) -{ - switch (ei_data) - { - case ELFDATANONE: *s << "ELFDATANONE"; break; - case ELFDATA2LSB: *s << "ELFDATA2LSB - Little Endian"; break; - case ELFDATA2MSB: *s << "ELFDATA2MSB - Big Endian"; break; - default: - break; - } -} - - -//---------------------------------------------------------------------- -// DumpELFProgramHeader -// -// Dump a single ELF program header to the specified output stream -//---------------------------------------------------------------------- -void -ObjectFileELF64::DumpELFProgramHeader(Stream *s, const Elf64_Phdr &ph) -{ - DumpELFProgramHeader_p_type(s, ph.p_type); - s->Printf(" %8.8x %8.8x %8.8x %8.8x %8.8x %8.8x (", - ph.p_offset, ph.p_vaddr, ph.p_paddr, ph.p_filesz, ph.p_memsz, - ph.p_flags); - DumpELFProgramHeader_p_flags(s, ph.p_flags); - s->Printf(") %8.8x", ph.p_align); -} - -//---------------------------------------------------------------------- -// DumpELFProgramHeader_p_type -// -// Dump an token value for the ELF program header member p_type which -// describes the type of the program header -// ---------------------------------------------------------------------- -void -ObjectFileELF64::DumpELFProgramHeader_p_type(Stream *s, Elf64_Word p_type) -{ - const int kStrWidth = 10; - switch (p_type) - { - CASE_AND_STREAM(s, PT_NULL , kStrWidth); - CASE_AND_STREAM(s, PT_LOAD , kStrWidth); - CASE_AND_STREAM(s, PT_DYNAMIC , kStrWidth); - CASE_AND_STREAM(s, PT_INTERP , kStrWidth); - CASE_AND_STREAM(s, PT_NOTE , kStrWidth); - CASE_AND_STREAM(s, PT_SHLIB , kStrWidth); - CASE_AND_STREAM(s, PT_PHDR , kStrWidth); - default: - s->Printf("0x%8.8x%*s", p_type, kStrWidth - 10, ""); - break; - } -} - - -//---------------------------------------------------------------------- -// DumpELFProgramHeader_p_flags -// -// Dump an token value for the ELF program header member p_flags -//---------------------------------------------------------------------- -void -ObjectFileELF64::DumpELFProgramHeader_p_flags(Stream *s, Elf64_Word p_flags) -{ - *s << ((p_flags & PF_X) ? "PF_X" : " ") - << (((p_flags & PF_X) && (p_flags & PF_W)) ? '+' : ' ') - << ((p_flags & PF_W) ? "PF_W" : " ") - << (((p_flags & PF_W) && (p_flags & PF_R)) ? '+' : ' ') - << ((p_flags & PF_R) ? "PF_R" : " "); -} - -//---------------------------------------------------------------------- -// DumpELFProgramHeaders -// -// Dump all of the ELF program header to the specified output stream -//---------------------------------------------------------------------- -void -ObjectFileELF64::DumpELFProgramHeaders(Stream *s) -{ - if (ParseProgramHeaders()) - { - s->PutCString("Program Headers\n"); - s->PutCString("IDX p_type p_offset p_vaddr p_paddr " - "p_filesz p_memsz p_flags p_align\n"); - s->PutCString("==== ---------- -------- -------- -------- " - "-------- -------- ------------------------- --------\n"); - - uint32_t idx = 0; - for (ProgramHeaderCollConstIter I = m_program_headers.begin(); - I != m_program_headers.end(); ++I, ++idx) - { - s->Printf("[%2u] ", idx); - ObjectFileELF64::DumpELFProgramHeader(s, *I); - s->EOL(); - } - } -} - -//---------------------------------------------------------------------- -// DumpELFSectionHeader -// -// Dump a single ELF section header to the specified output stream -//---------------------------------------------------------------------- -void -ObjectFileELF64::DumpELFSectionHeader(Stream *s, const Elf64_Shdr &sh) -{ - s->Printf("%8.8x ", sh.sh_name); - DumpELFSectionHeader_sh_type(s, sh.sh_type); - s->Printf(" %8.8x (", sh.sh_flags); - DumpELFSectionHeader_sh_flags(s, sh.sh_flags); - s->Printf(") %8.8x %8.8x %8.8x %8.8x %8.8x %8.8x %8.8x", - sh.sh_addr, sh.sh_offset, sh.sh_size, sh.sh_link, sh.sh_info, - sh.sh_addralign, sh.sh_entsize); -} - -//---------------------------------------------------------------------- -// DumpELFSectionHeader_sh_type -// -// Dump an token value for the ELF section header member sh_type which -// describes the type of the section -//---------------------------------------------------------------------- -void -ObjectFileELF64::DumpELFSectionHeader_sh_type(Stream *s, Elf64_Word sh_type) -{ - const int kStrWidth = 12; - switch (sh_type) - { - CASE_AND_STREAM(s, SHT_NULL , kStrWidth); - CASE_AND_STREAM(s, SHT_PROGBITS , kStrWidth); - CASE_AND_STREAM(s, SHT_SYMTAB , kStrWidth); - CASE_AND_STREAM(s, SHT_STRTAB , kStrWidth); - CASE_AND_STREAM(s, SHT_RELA , kStrWidth); - CASE_AND_STREAM(s, SHT_HASH , kStrWidth); - CASE_AND_STREAM(s, SHT_DYNAMIC , kStrWidth); - CASE_AND_STREAM(s, SHT_NOTE , kStrWidth); - CASE_AND_STREAM(s, SHT_NOBITS , kStrWidth); - CASE_AND_STREAM(s, SHT_REL , kStrWidth); - CASE_AND_STREAM(s, SHT_SHLIB , kStrWidth); - CASE_AND_STREAM(s, SHT_DYNSYM , kStrWidth); - CASE_AND_STREAM(s, SHT_LOPROC , kStrWidth); - CASE_AND_STREAM(s, SHT_HIPROC , kStrWidth); - CASE_AND_STREAM(s, SHT_LOUSER , kStrWidth); - CASE_AND_STREAM(s, SHT_HIUSER , kStrWidth); - default: - s->Printf("0x%8.8x%*s", sh_type, kStrWidth - 10, ""); - break; - } -} - -//---------------------------------------------------------------------- -// DumpELFSectionHeader_sh_flags -// -// Dump an token value for the ELF section header member sh_flags -//---------------------------------------------------------------------- -void -ObjectFileELF64::DumpELFSectionHeader_sh_flags(Stream *s, Elf64_Word sh_flags) -{ - *s << ((sh_flags & SHF_WRITE) ? "WRITE" : " ") - << (((sh_flags & SHF_WRITE) && (sh_flags & SHF_ALLOC)) ? '+' : ' ') - << ((sh_flags & SHF_ALLOC) ? "ALLOC" : " ") - << (((sh_flags & SHF_ALLOC) && (sh_flags & SHF_EXECINSTR)) ? '+' : ' ') - << ((sh_flags & SHF_EXECINSTR) ? "EXECINSTR" : " "); -} - -//---------------------------------------------------------------------- -// DumpELFSectionHeaders -// -// Dump all of the ELF section header to the specified output stream -//---------------------------------------------------------------------- -void -ObjectFileELF64::DumpELFSectionHeaders(Stream *s) -{ - if (!(ParseSectionHeaders() && GetSectionHeaderStringTable())) - return; - - s->PutCString("Section Headers\n"); - s->PutCString("IDX name type flags " - "addr offset size link info addralgn " - "entsize Name\n"); - s->PutCString("==== -------- ------------ -------------------------------- " - "-------- -------- -------- -------- -------- -------- " - "-------- ====================\n"); - - uint32_t idx = 0; - for (SectionHeaderCollConstIter I = m_section_headers.begin(); - I != m_section_headers.end(); ++I, ++idx) - { - s->Printf("[%2u] ", idx); - ObjectFileELF64::DumpELFSectionHeader(s, *I); - const char* section_name = m_shstr_data.PeekCStr(I->sh_name); - if (section_name) - *s << ' ' << section_name << "\n"; - } -} - -void -ObjectFileELF64::DumpDependentModules(lldb_private::Stream *s) -{ - size_t num_modules = ParseDependentModules(); - - if (num_modules > 0) - { - s->PutCString("Dependent Modules:\n"); - for (unsigned i = 0; i < num_modules; ++i) - { - const FileSpec &spec = m_filespec_ap->GetFileSpecAtIndex(i); - s->Printf(" %s\n", spec.GetFilename().GetCString()); - } - } -} - -bool -ObjectFileELF64::GetTargetTriple(ConstString &target_triple) -{ - static ConstString g_target_triple; - - if (g_target_triple) - { - target_triple = g_target_triple; - return true; - } - - std::string triple; - switch (m_header.e_machine) - { - default: - assert(false && "Unexpected machine type."); - break; - case EM_SPARC: triple.assign("sparc-"); break; - case EM_386: triple.assign("i386-"); break; - case EM_68K: triple.assign("68k-"); break; - case EM_88K: triple.assign("88k-"); break; - case EM_860: triple.assign("i860-"); break; - case EM_MIPS: triple.assign("mips-"); break; - case EM_PPC: triple.assign("powerpc-"); break; - case EM_PPC64: triple.assign("powerpc64-"); break; - case EM_ARM: triple.assign("arm-"); break; - case EM_X86_64: triple.assign("x86_64-"); break; - } - // TODO: determine if there is a vendor in the ELF? Default to "linux" for now - triple += "linux-"; - // TODO: determine if there is an OS in the ELF? Default to "gnu" for now - triple += "gnu"; - g_target_triple.SetCString(triple.c_str()); - target_triple = g_target_triple; - - return true; -} - -//------------------------------------------------------------------ -// PluginInterface protocol -//------------------------------------------------------------------ -const char * -ObjectFileELF64::GetPluginName() -{ - return "ObjectFileELF64"; -} - -const char * -ObjectFileELF64::GetShortPluginName() -{ - return GetPluginNameStatic(); -} - -uint32_t -ObjectFileELF64::GetPluginVersion() -{ - return 1; -} - -void -ObjectFileELF64::GetPluginCommandHelp (const char *command, Stream *strm) -{ -} - -Error -ObjectFileELF64::ExecutePluginCommand (Args &command, Stream *strm) -{ - Error error; - error.SetErrorString("No plug-in commands are currently supported."); - return error; -} - -Log * -ObjectFileELF64::EnablePluginLogging (Stream *strm, Args &command) -{ - return NULL; -} Removed: lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF64.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF64.h?rev=108291&view=auto ============================================================================== --- lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF64.h (original) +++ lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF64.h (removed) @@ -1,209 +0,0 @@ -//===-- ObjectFileELF64.h ------------------------------------- -*- C++ -*-===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -#ifndef liblldb_ObjectFileELF64_h_ -#define liblldb_ObjectFileELF64_h_ - -#include -#include - -#include "lldb/lldb-private.h" -#include "lldb/Core/FileSpec.h" -#include "lldb/Symbol/ObjectFile.h" - -#include "elf.h" - -//---------------------------------------------------------------------- -// This class needs to be hidden as eventually belongs in a plugin that -// will export the ObjectFile protocol -//---------------------------------------------------------------------- -class ObjectFileELF64 : - public lldb_private::ObjectFile -{ -public: - //------------------------------------------------------------------ - // Static Functions - //------------------------------------------------------------------ - static void - Initialize(); - - static void - Terminate(); - - static const char * - GetPluginNameStatic(); - - static const char * - GetPluginDescriptionStatic(); - - static lldb_private::ObjectFile * - CreateInstance(lldb_private::Module* module, - lldb::DataBufferSP& dataSP, - const lldb_private::FileSpec* file, - lldb::addr_t offset, - lldb::addr_t length); - - static bool - MagicBytesMatch(lldb::DataBufferSP& dataSP); - - //------------------------------------------------------------------ - // Member Functions - //------------------------------------------------------------------ - ObjectFileELF64(lldb_private::Module* module, - lldb::DataBufferSP& dataSP, - const lldb_private::FileSpec* file, - lldb::addr_t offset, - lldb::addr_t length); - - virtual - ~ObjectFileELF64(); - - virtual bool - ParseHeader(); - - virtual lldb::ByteOrder - GetByteOrder() const; - - virtual size_t - GetAddressByteSize() const; - - virtual lldb_private::Symtab * - GetSymtab(); - - virtual lldb_private::SectionList * - GetSectionList(); - - virtual void - Dump(lldb_private::Stream *s); - - virtual bool - GetTargetTriple(lldb_private::ConstString &target_triple); - - virtual bool - GetUUID(lldb_private::UUID* uuid); - - virtual uint32_t - GetDependentModules(lldb_private::FileSpecList& files); - - //------------------------------------------------------------------ - // PluginInterface protocol - //------------------------------------------------------------------ - virtual const char * - GetPluginName(); - - virtual const char * - GetShortPluginName(); - - virtual uint32_t - GetPluginVersion(); - - virtual void - GetPluginCommandHelp(const char *command, lldb_private::Stream *strm); - - virtual lldb_private::Error - ExecutePluginCommand(lldb_private::Args &command, - lldb_private::Stream *strm); - - virtual lldb_private::Log * - EnablePluginLogging(lldb_private::Stream *strm, - lldb_private::Args &command); - -protected: - typedef std::vector ProgramHeaderColl; - typedef ProgramHeaderColl::iterator ProgramHeaderCollIter; - typedef ProgramHeaderColl::const_iterator ProgramHeaderCollConstIter; - - typedef std::vector SectionHeaderColl; - typedef SectionHeaderColl::iterator SectionHeaderCollIter; - typedef SectionHeaderColl::const_iterator SectionHeaderCollConstIter; - - Elf64_Ehdr m_header; - ProgramHeaderColl m_program_headers; - SectionHeaderColl m_section_headers; - mutable std::auto_ptr m_sections_ap; - mutable std::auto_ptr m_symtab_ap; - mutable std::auto_ptr m_filespec_ap; - lldb_private::DataExtractor m_shstr_data; - - size_t - ParseSections(); - - size_t - ParseSymtab(bool minimize); - -private: - // Returns the 1 based index of a section header. - unsigned - SectionIndex(const SectionHeaderCollIter &I); - - unsigned - SectionIndex(const SectionHeaderCollConstIter &I) const; - - // ELF header dump routines - static void - DumpELFHeader(lldb_private::Stream *s, const Elf64_Ehdr& header); - - static void - DumpELFHeader_e_ident_EI_DATA(lldb_private::Stream *s, - unsigned char ei_data); - - static void - DumpELFHeader_e_type(lldb_private::Stream *s, Elf64_Half e_type); - - // ELF program header dump routines - void - DumpELFProgramHeaders(lldb_private::Stream *s); - - static void - DumpELFProgramHeader(lldb_private::Stream *s, const Elf64_Phdr &ph); - - static void - DumpELFProgramHeader_p_type(lldb_private::Stream *s, Elf64_Word p_type); - - static void - DumpELFProgramHeader_p_flags(lldb_private::Stream *s, Elf64_Word p_flags); - - // ELF section header dump routines - void - DumpELFSectionHeaders(lldb_private::Stream *s); - - static void - DumpELFSectionHeader(lldb_private::Stream *s, const Elf64_Shdr& sh); - - static void - DumpELFSectionHeader_sh_type(lldb_private::Stream *s, Elf64_Word sh_type); - - static void - DumpELFSectionHeader_sh_flags(lldb_private::Stream *s, Elf64_Word sh_flags); - - void - DumpDependentModules(lldb_private::Stream *s); - - size_t - ParseProgramHeaders(); - - size_t - ParseSectionHeaders(); - - size_t - ParseDependentModules(); - - void - ParseSymbolTable(lldb_private::Symtab *symbol_table, - const Elf64_Shdr &symtab_section, - lldb::user_id_t symtab_id); - - size_t - GetSectionHeaderStringTable(); - - uint32_t - GetSectionIndexByName(const char *name); -}; - -#endif // #ifndef liblldb_ObjectFileELF64_h_ Modified: lldb/trunk/source/lldb.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/lldb.cpp?rev=108292&r1=108291&r2=108292&view=diff ============================================================================== --- lldb/trunk/source/lldb.cpp (original) +++ lldb/trunk/source/lldb.cpp Tue Jul 13 18:07:23 2010 @@ -19,7 +19,6 @@ #include "Plugins/SymbolVendor/MacOSX/SymbolVendorMacOSX.h" #include "Plugins/ObjectContainer/BSD-Archive/ObjectContainerBSDArchive.h" #include "Plugins/ObjectFile/ELF/ObjectFileELF.h" -#include "Plugins/ObjectFile/ELF/ObjectFileELF64.h" #include "Plugins/SymbolFile/DWARF/SymbolFileDWARF.h" #include "Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h" #include "Plugins/SymbolFile/Symtab/SymbolFileSymtab.h" @@ -56,7 +55,6 @@ DisassemblerLLVM::Initialize(); ObjectContainerBSDArchive::Initialize(); ObjectFileELF::Initialize(); - ObjectFileELF64::Initialize(); SymbolVendorMacOSX::Initialize(); SymbolFileDWARF::Initialize(); SymbolFileDWARFDebugMap::Initialize(); @@ -86,7 +84,6 @@ DisassemblerLLVM::Terminate(); ObjectContainerBSDArchive::Terminate(); ObjectFileELF::Terminate(); - ObjectFileELF64::Terminate(); SymbolVendorMacOSX::Terminate(); SymbolFileDWARF::Terminate(); SymbolFileDWARFDebugMap::Terminate(); From wilsons at start.ca Tue Jul 13 18:09:42 2010 From: wilsons at start.ca (Stephen Wilson) Date: Tue, 13 Jul 2010 23:09:42 -0000 Subject: [Lldb-commits] [lldb] r108293 - /lldb/trunk/source/Plugins/ObjectFile/ELF/elf.h Message-ID: <20100713230942.B13B52A6C12C@llvm.org> Author: wilsons Date: Tue Jul 13 18:09:42 2010 New Revision: 108293 URL: http://llvm.org/viewvc/llvm-project?rev=108293&view=rev Log: Remove our local ELF definitions and rely on llvm/Support/ELF.h instead. Removed: lldb/trunk/source/Plugins/ObjectFile/ELF/elf.h Removed: lldb/trunk/source/Plugins/ObjectFile/ELF/elf.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ObjectFile/ELF/elf.h?rev=108292&view=auto ============================================================================== --- lldb/trunk/source/Plugins/ObjectFile/ELF/elf.h (original) +++ lldb/trunk/source/Plugins/ObjectFile/ELF/elf.h (removed) @@ -1,376 +0,0 @@ -//===-- elf.h ---------------------------------------------------*- C++ -*-===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -#ifndef __elf_h__ -#define __elf_h__ - -//---------------------------------------------------------------------- -// Typedefs for ELF32. -//---------------------------------------------------------------------- -typedef uint16_t Elf32_Half; -typedef uint32_t Elf32_Word; -typedef int32_t Elf32_Sword; -typedef uint32_t Elf32_Addr; -typedef uint32_t Elf32_Off; - -//---------------------------------------------------------------------- -// Typedefs for ELF64. -//---------------------------------------------------------------------- -typedef uint16_t Elf64_Half; -typedef uint32_t Elf64_Word; -typedef int32_t Elf64_Sword; -typedef uint64_t Elf64_Xword; -typedef int64_t Elf64_Sxword; -typedef uint64_t Elf64_Addr; -typedef uint64_t Elf64_Off; - -#define EI_NIDENT 16 - -//---------------------------------------------------------------------- -// ELF Headers -//---------------------------------------------------------------------- -typedef struct Elf32_Ehdr_Tag -{ - unsigned char e_ident[EI_NIDENT]; - Elf32_Half e_type; - Elf32_Half e_machine; - Elf32_Word e_version; - Elf32_Addr e_entry; - Elf32_Off e_phoff; - Elf32_Off e_shoff; - Elf32_Word e_flags; - Elf32_Half e_ehsize; - Elf32_Half e_phentsize; - Elf32_Half e_phnum; - Elf32_Half e_shentsize; - Elf32_Half e_shnum; - Elf32_Half e_shstrndx; -} Elf32_Ehdr; - -typedef struct Elf64_Ehdr_Tag -{ - unsigned char e_ident[EI_NIDENT]; - Elf64_Half e_type; - Elf64_Half e_machine; - Elf64_Word e_version; - Elf64_Addr e_entry; - Elf64_Off e_phoff; - Elf64_Off e_shoff; - Elf64_Word e_flags; - Elf64_Half e_ehsize; - Elf64_Half e_phentsize; - Elf64_Half e_phnum; - Elf64_Half e_shentsize; - Elf64_Half e_shnum; - Elf64_Half e_shstrndx; -} Elf64_Ehdr; - -//---------------------------------------------------------------------- -// e_type -// -// This member identifies the object file type. -//---------------------------------------------------------------------- -#define ET_NONE 0 // No file type -#define ET_REL 1 // Relocatable file -#define ET_EXEC 2 // Executable file -#define ET_DYN 3 // Shared object file -#define ET_CORE 4 // Core file -#define ET_LOPROC 0xff00 // Processor-specific -#define ET_HIPROC 0xffff // Processor-specific - -//---------------------------------------------------------------------- -// e_machine -// -// Machine Type -//---------------------------------------------------------------------- -#define EM_NONE 0 // No machine -#define EM_M32 1 // AT&T WE 32100 -#define EM_SPARC 2 // SPARC -#define EM_386 3 // Intel 80386 -#define EM_68K 4 // Motorola 68000 -#define EM_88K 5 // Motorola 88000 -#define EM_860 7 // Intel 80860 -#define EM_MIPS 8 // MIPS RS3000 -#define EM_PPC 20 // PowerPC -#define EM_PPC64 21 // PowerPC64 -#define EM_ARM 40 // ARM -#define EM_X86_64 62 // AMD x86-64 - - -//---------------------------------------------------------------------- -// e_ident indexes -//---------------------------------------------------------------------- -#define EI_MAG0 0 // File identification -#define EI_MAG1 1 // File identification -#define EI_MAG2 2 // File identification -#define EI_MAG3 3 // File identification -#define EI_CLASS 4 // File class -#define EI_DATA 5 // Data encoding -#define EI_VERSION 6 // File version -#define EI_PAD 7 // Start of padding bytes - -//---------------------------------------------------------------------- -// EI_CLASS definitions -//---------------------------------------------------------------------- -#define ELFCLASS32 1 // 32-bit object file -#define ELFCLASS64 2 // 64-bit object file - -//---------------------------------------------------------------------- -// EI_DATA definitions -//---------------------------------------------------------------------- -#define ELFDATANONE 0 // Invalid data encoding -#define ELFDATA2LSB 1 // Little Endian -#define ELFDATA2MSB 2 // Big Endian - -//---------------------------------------------------------------------- -// Section Headers -//---------------------------------------------------------------------- -typedef struct Elf32_Shdr_Tag -{ - Elf32_Word sh_name; - Elf32_Word sh_type; - Elf32_Word sh_flags; - Elf32_Addr sh_addr; - Elf32_Off sh_offset; - Elf32_Word sh_size; - Elf32_Word sh_link; - Elf32_Word sh_info; - Elf32_Word sh_addralign; - Elf32_Word sh_entsize; -} Elf32_Shdr; - -typedef struct Elf64_Shdr_Tag -{ - Elf64_Word sh_name; - Elf64_Word sh_type; - Elf64_Xword sh_flags; - Elf64_Addr sh_addr; - Elf64_Off sh_offset; - Elf64_Xword sh_size; - Elf64_Word sh_link; - Elf64_Word sh_info; - Elf64_Xword sh_addralign; - Elf64_Xword sh_entsize; -} Elf64_Shdr; - -//---------------------------------------------------------------------- -// Section Types (sh_type) -//---------------------------------------------------------------------- -#define SHT_NULL 0 -#define SHT_PROGBITS 1 -#define SHT_SYMTAB 2 -#define SHT_STRTAB 3 -#define SHT_RELA 4 -#define SHT_HASH 5 -#define SHT_DYNAMIC 6 -#define SHT_NOTE 7 -#define SHT_NOBITS 8 -#define SHT_REL 9 -#define SHT_SHLIB 10 -#define SHT_DYNSYM 11 -#define SHT_LOPROC 0x70000000 -#define SHT_HIPROC 0x7fffffff -#define SHT_LOUSER 0x80000000 -#define SHT_HIUSER 0xffffffff - -//---------------------------------------------------------------------- -// Special Section Indexes -//---------------------------------------------------------------------- -#define SHN_UNDEF 0 -#define SHN_LORESERVE 0xff00 -#define SHN_LOPROC 0xff00 -#define SHN_HIPROC 0xff1f -#define SHN_ABS 0xfff1 -#define SHN_COMMON 0xfff2 -#define SHN_HIRESERVE 0xffff - -//---------------------------------------------------------------------- -// Section Attribute Flags (sh_flags) -//---------------------------------------------------------------------- -#define SHF_WRITE 0x1 -#define SHF_ALLOC 0x2 -#define SHF_EXECINSTR 0x4 -#define SHF_MASKPROC 0xf0000000 - - -//---------------------------------------------------------------------- -// Symbol Table Entry Headers -//---------------------------------------------------------------------- -typedef struct Elf32_Sym_Tag -{ - Elf32_Word st_name; - Elf32_Addr st_value; - Elf32_Word st_size; - unsigned char st_info; - unsigned char st_other; - Elf32_Half st_shndx; -} Elf32_Sym; - -typedef struct Elf64_Sym_Tag -{ - Elf64_Word st_name; - unsigned char st_info; - unsigned char st_other; - Elf64_Half st_shndx; - Elf64_Addr st_value; - Elf64_Xword st_size; -} Elf64_Sym; - -//---------------------------------------------------------------------- -// Accessors to the binding and type bits in the st_info field of a -// symbol table entry. Valid for both 32 and 64 bit variations. -//---------------------------------------------------------------------- -#define ELF_ST_BIND(i) ((i)>>4) -#define ELF_ST_TYPE(i) ((i)&0xf) -#define ELF_ST_INFO(b,t) (((b)<<4)+((t)&0xf)) - -// ST_BIND -#define STB_LOCAL 0 -#define STB_GLOBAL 1 -#define STB_WEAK 2 -#define STB_LOPROC 13 -#define STB_HIPROC 15 - -// ST_TYPE -#define STT_NOTYPE 0 -#define STT_OBJECT 1 -#define STT_FUNC 2 -#define STT_SECTION 3 -#define STT_FILE 4 -#define STT_LOPROC 13 -#define STT_HIPROC 15 - - -//---------------------------------------------------------------------- -// Relocation Entries -//---------------------------------------------------------------------- -typedef struct Elf32_Rel_Tag -{ - Elf32_Addr r_offset; - Elf32_Word r_info; -} Elf32_Rel; - -typedef struct Elf32_Rela_Tag -{ - Elf32_Addr r_offset; - Elf32_Word r_info; - Elf32_Sword r_addend; -} Elf32_Rela; - -typedef struct Elf64_Rel_Tag -{ - Elf64_Addr r_offset; - Elf64_Word r_info; -} Elf64_Rel; - -typedef struct Elf64_Rela_Tag -{ - Elf64_Addr r_offset; - Elf64_Word r_info; - Elf64_Sword r_addend; -} Elf64_Rela; - -#define ELF32_R_SYM(i) ((i)>>8) -#define ELF32_R_TYPE(i) ((unsignedchar)(i)) -#define ELF32_R_INFO(s,t) (((s)<<8)+(unsignedchar)(t)) - -//---------------------------------------------------------------------- -// Dynamic Table Entry Headers -//---------------------------------------------------------------------- -typedef struct Elf64_Dyn_Tag -{ - Elf64_Sxword d_tag; - union - { - Elf64_Xword d_val; - Elf64_Addr d_ptr; - } d_un; -} Elf64_Dyn; - -#define DT_NULL 0 // Marks end of dynamic array. -#define DT_NEEDED 1 // String table offset of needed library. -#define DT_PLTRELSZ 2 // Size of relocation entries in PLT. -#define DT_PLTGOT 3 // Address associated with linkage table. -#define DT_HASH 4 // Address of symbolic hash table. -#define DT_STRTAB 5 // Address of dynamic string table. -#define DT_SYMTAB 6 // Address of dynamic symbol table. -#define DT_RELA 7 // Address of relocation table (Rela entries). -#define DT_RELASZ 8 // Size of Rela relocation table. -#define DT_RELAENT 9 // Size of a Rela relocation entry. -#define DT_STRSZ 10 // Total size of the string table. -#define DT_SYMENT 11 // Size of a symbol table entry. -#define DT_INIT 12 // Address of initialization function. -#define DT_FINI 13 // Address of termination function. -#define DT_SONAME 14 // String table offset of a shared objects name. -#define DT_RPATH 15 // String table offset of library search path. -#define DT_SYMBOLIC 16 // Changes symbol resolution algorithm. -#define DT_REL 17 // Address of relocation table (Rel entries). -#define DT_RELSZ 18 // Size of Rel relocation table. -#define DT_RELENT 19 // Size of a Rel relocation entry. -#define DT_PLTREL 20 // Type of relocation entry used for linking. -#define DT_DEBUG 21 // Reserved for debugger. -#define DT_TEXTREL 22 // Relocations exist for non-writable segements. -#define DT_JMPREL 23 // Address of relocations associated with PLT. -#define DT_BIND_NOW 24 // Process all relocations before execution. -#define DT_INIT_ARRAY 25 // Pointer to array of initialization functions. -#define DT_FINI_ARRAY 26 // Pointer to array of termination functions. -#define DT_INIT_ARRAYSZ 27 // Size of DT_INIT_ARRAY. -#define DT_FINI_ARRAYSZ 28 // Size of DT_FINI_ARRAY. -#define DT_LOOS 0x60000000 // Start of environment specific tags. -#define DT_HIOS 0x6FFFFFFF // End of environment specific tags. -#define DT_LOPROC 0x70000000 // Start of processor specific tags. -#define DT_HIPROC 0x7FFFFFFF // End of processor specific tags. - - -//---------------------------------------------------------------------- -// Program Headers -//---------------------------------------------------------------------- -typedef struct Elf32_Phdr_Tag -{ - Elf32_Word p_type; - Elf32_Off p_offset; - Elf32_Addr p_vaddr; - Elf32_Addr p_paddr; - Elf32_Word p_filesz; - Elf32_Word p_memsz; - Elf32_Word p_flags; - Elf32_Word p_align; -} Elf32_Phdr; - -typedef struct Elf64_Phdr_Tag -{ - Elf64_Word p_type; - Elf64_Off p_offset; - Elf64_Addr p_vaddr; - Elf64_Addr p_paddr; - Elf64_Word p_filesz; - Elf64_Word p_memsz; - Elf64_Word p_flags; - Elf64_Word p_align; -} Elf64_Phdr; - -//---------------------------------------------------------------------- -// Program Header Type (p_type) -//---------------------------------------------------------------------- -#define PT_NULL 0 -#define PT_LOAD 1 -#define PT_DYNAMIC 2 -#define PT_INTERP 3 -#define PT_NOTE 4 -#define PT_SHLIB 5 -#define PT_PHDR 6 -#define PT_LOPROC 0x70000000 -#define PT_HIPROC 0x7fffffff - -#define PF_X (1 << 0) // executable -#define PF_W (1 << 1) // writable -#define PF_R (1 << 2) // readable - - -#endif // __elf_h__ From gclayton at apple.com Tue Jul 13 19:18:16 2010 From: gclayton at apple.com (Greg Clayton) Date: Wed, 14 Jul 2010 00:18:16 -0000 Subject: [Lldb-commits] [lldb] r108299 - in /lldb/trunk: include/lldb/Expression/ include/lldb/Interpreter/ lldb.xcodeproj/ source/API/ source/Commands/ source/Core/ source/Expression/ source/Interpreter/ source/Plugins/DynamicLoader/MacOSX-DYLD/ source/Plugins/Process/Utility/libunwind/src/ source/Plugins/SymbolFile/DWARF/ source/Symbol/ source/Target/ tools/driver/ Message-ID: <20100714001816.68EAD2A6C12C@llvm.org> Author: gclayton Date: Tue Jul 13 19:18:15 2010 New Revision: 108299 URL: http://llvm.org/viewvc/llvm-project?rev=108299&view=rev Log: I enabled some extra warnings for hidden local variables and for hidden virtual functions and caught some things and did some general code cleanup. Modified: lldb/trunk/include/lldb/Expression/ClangASTSource.h lldb/trunk/include/lldb/Interpreter/ScriptInterpreter.h lldb/trunk/lldb.xcodeproj/project.pbxproj lldb/trunk/source/API/SBThread.cpp lldb/trunk/source/Commands/CommandObjectBreakpointCommand.cpp lldb/trunk/source/Commands/CommandObjectImage.cpp lldb/trunk/source/Commands/CommandObjectProcess.cpp lldb/trunk/source/Commands/CommandObjectThread.cpp lldb/trunk/source/Core/Address.cpp lldb/trunk/source/Core/InputReader.cpp lldb/trunk/source/Core/ValueObject.cpp lldb/trunk/source/Expression/ClangExpression.cpp lldb/trunk/source/Expression/ClangFunction.cpp lldb/trunk/source/Interpreter/Args.cpp lldb/trunk/source/Interpreter/Options.cpp lldb/trunk/source/Interpreter/ScriptInterpreter.cpp lldb/trunk/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp lldb/trunk/source/Plugins/DynamicLoader/MacOSX-DYLD/ObjCTrampolineHandler.cpp lldb/trunk/source/Plugins/Process/Utility/libunwind/src/UnwindCursor.hpp lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp lldb/trunk/source/Symbol/ClangASTContext.cpp lldb/trunk/source/Symbol/DWARFCallFrameInfo.cpp lldb/trunk/source/Symbol/Type.cpp lldb/trunk/source/Target/ThreadList.cpp lldb/trunk/source/Target/ThreadPlan.cpp lldb/trunk/tools/driver/Driver.cpp lldb/trunk/tools/driver/IOChannel.cpp Modified: lldb/trunk/include/lldb/Expression/ClangASTSource.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Expression/ClangASTSource.h?rev=108299&r1=108298&r2=108299&view=diff ============================================================================== --- lldb/trunk/include/lldb/Expression/ClangASTSource.h (original) +++ lldb/trunk/include/lldb/Expression/ClangASTSource.h Tue Jul 13 19:18:15 2010 @@ -21,10 +21,10 @@ public: friend struct NameSearchContext; - ClangASTSource(clang::ASTContext &Context, - ClangExpressionDeclMap &DeclMap) : - Context(Context), - DeclMap(DeclMap) {} + ClangASTSource(clang::ASTContext &context, + ClangExpressionDeclMap &declMap) : + Context(context), + DeclMap(declMap) {} ~ClangASTSource(); clang::Decl *GetExternalDecl(uint32_t); @@ -49,14 +49,14 @@ clang::DeclarationName &Name; const clang::DeclContext *DC; - NameSearchContext (ClangASTSource &ASTSource, - llvm::SmallVectorImpl &Decls, - clang::DeclarationName &Name, - const clang::DeclContext *DC) : - ASTSource(ASTSource), - Decls(Decls), - Name(Name), - DC(DC) {} + NameSearchContext (ClangASTSource &astSource, + llvm::SmallVectorImpl &decls, + clang::DeclarationName &name, + const clang::DeclContext *dc) : + ASTSource(astSource), + Decls(decls), + Name(name), + DC(dc) {} clang::ASTContext *GetASTContext(); clang::NamedDecl *AddVarDecl(void *type); Modified: lldb/trunk/include/lldb/Interpreter/ScriptInterpreter.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Interpreter/ScriptInterpreter.h?rev=108299&r1=108298&r2=108299&view=diff ============================================================================== --- lldb/trunk/include/lldb/Interpreter/ScriptInterpreter.h (original) +++ lldb/trunk/include/lldb/Interpreter/ScriptInterpreter.h Tue Jul 13 19:18:15 2010 @@ -73,8 +73,9 @@ } virtual void - CollectDataForBreakpointCommandCallback (BreakpointOptions *bp_options, - CommandReturnObject &result); + CollectDataForBreakpointCommandCallback (CommandInterpreter &interpreter, + BreakpointOptions *bp_options, + CommandReturnObject &result); const char * GetScriptInterpreterPtyName (); Modified: lldb/trunk/lldb.xcodeproj/project.pbxproj URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/lldb.xcodeproj/project.pbxproj?rev=108299&r1=108298&r2=108299&view=diff ============================================================================== --- lldb/trunk/lldb.xcodeproj/project.pbxproj (original) +++ lldb/trunk/lldb.xcodeproj/project.pbxproj Tue Jul 13 19:18:15 2010 @@ -2700,6 +2700,7 @@ LLDB_CONFIGURATION_DEBUG, ); GCC_WARN_ABOUT_RETURN_TYPE = YES; + GCC_WARN_HIDDEN_VIRTUAL_FUNCTIONS = YES; GCC_WARN_UNUSED_VARIABLE = YES; ONLY_ACTIVE_ARCH = YES; PREBINDING = NO; @@ -2722,6 +2723,7 @@ LLDB_CONFIGURATION_RELEASE, ); GCC_WARN_ABOUT_RETURN_TYPE = YES; + GCC_WARN_HIDDEN_VIRTUAL_FUNCTIONS = YES; GCC_WARN_UNUSED_VARIABLE = YES; PREBINDING = NO; VALID_ARCHS = "x86_64 i386"; @@ -2850,6 +2852,7 @@ LLDB_CONFIGURATION_BUILD_AND_INTEGRATION, ); GCC_WARN_ABOUT_RETURN_TYPE = YES; + GCC_WARN_HIDDEN_VIRTUAL_FUNCTIONS = YES; GCC_WARN_UNUSED_VARIABLE = YES; PREBINDING = NO; VALID_ARCHS = "x86_64 i386"; Modified: lldb/trunk/source/API/SBThread.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBThread.cpp?rev=108299&r1=108298&r2=108299&view=diff ============================================================================== --- lldb/trunk/source/API/SBThread.cpp (original) +++ lldb/trunk/source/API/SBThread.cpp Tue Jul 13 19:18:15 2010 @@ -100,7 +100,6 @@ } else { - const char *stop_desc = NULL; size_t stop_desc_len = 0; switch (thread_stop_info.GetStopReason()) { Modified: lldb/trunk/source/Commands/CommandObjectBreakpointCommand.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectBreakpointCommand.cpp?rev=108299&r1=108298&r2=108299&view=diff ============================================================================== --- lldb/trunk/source/Commands/CommandObjectBreakpointCommand.cpp (original) +++ lldb/trunk/source/Commands/CommandObjectBreakpointCommand.cpp Tue Jul 13 19:18:15 2010 @@ -258,12 +258,15 @@ { if (m_options.m_use_script_language) { - interpreter.GetScriptInterpreter()->CollectDataForBreakpointCommandCallback (bp_loc_sp->GetLocationOptions(), - result); + interpreter.GetScriptInterpreter()->CollectDataForBreakpointCommandCallback (interpreter, + bp_loc_sp->GetLocationOptions(), + result); } else { - CollectDataForBreakpointCommandCallback (interpreter, bp_loc_sp->GetLocationOptions(), result); + CollectDataForBreakpointCommandCallback (interpreter, + bp_loc_sp->GetLocationOptions(), + result); } } } @@ -271,12 +274,15 @@ { if (m_options.m_use_script_language) { - interpreter.GetScriptInterpreter()->CollectDataForBreakpointCommandCallback (bp->GetOptions(), - result); + interpreter.GetScriptInterpreter()->CollectDataForBreakpointCommandCallback (interpreter, + bp->GetOptions(), + result); } else { - CollectDataForBreakpointCommandCallback (interpreter, bp->GetOptions(), result); + CollectDataForBreakpointCommandCallback (interpreter, + bp->GetOptions(), + result); } } } Modified: lldb/trunk/source/Commands/CommandObjectImage.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectImage.cpp?rev=108299&r1=108298&r2=108299&view=diff ============================================================================== --- lldb/trunk/source/Commands/CommandObjectImage.cpp (original) +++ lldb/trunk/source/Commands/CommandObjectImage.cpp Tue Jul 13 19:18:15 2010 @@ -1395,9 +1395,9 @@ if (num_matching_modules > 0) { - for (size_t i=0; iGetID()); if (synchronous_execution) { - StateType state = process->WaitForProcessToStop (NULL); + state = process->WaitForProcessToStop (NULL); result.SetDidChangeProcessState (true); result.AppendMessageWithFormat ("Process %i %s\n", process->GetID(), StateAsCString (state)); Modified: lldb/trunk/source/Commands/CommandObjectThread.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectThread.cpp?rev=108299&r1=108298&r2=108299&view=diff ============================================================================== --- lldb/trunk/source/Commands/CommandObjectThread.cpp (original) +++ lldb/trunk/source/Commands/CommandObjectThread.cpp Tue Jul 13 19:18:15 2010 @@ -760,7 +760,7 @@ result.AppendMessageWithFormat ("Resuming process %i\n", process->GetID()); if (synchronous_execution) { - StateType state = process->WaitForProcessToStop (NULL); + state = process->WaitForProcessToStop (NULL); result.SetDidChangeProcessState (true); result.AppendMessageWithFormat ("Process %i %s\n", process->GetID(), StateAsCString (state)); @@ -827,7 +827,7 @@ { case 't': { - uint32_t m_thread_idx = Args::StringToUInt32 (option_arg, LLDB_INVALID_INDEX32); + m_thread_idx = Args::StringToUInt32 (option_arg, LLDB_INVALID_INDEX32); if (m_thread_idx == LLDB_INVALID_INDEX32) { error.SetErrorStringWithFormat ("Invalid thread index '%s'.\n", option_arg); Modified: lldb/trunk/source/Core/Address.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/Address.cpp?rev=108299&r1=108298&r2=108299&view=diff ============================================================================== --- lldb/trunk/source/Core/Address.cpp (original) +++ lldb/trunk/source/Core/Address.cpp Tue Jul 13 19:18:15 2010 @@ -628,7 +628,6 @@ if (so_addr.IsSectionOffset()) { lldb_private::SymbolContext pointer_sc; - Target *target = exe_scope->CalculateTarget(); if (target) { target->GetImages().ResolveSymbolContextForAddress (so_addr, Modified: lldb/trunk/source/Core/InputReader.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/InputReader.cpp?rev=108299&r1=108298&r2=108299&view=diff ============================================================================== --- lldb/trunk/source/Core/InputReader.cpp (original) +++ lldb/trunk/source/Core/InputReader.cpp Tue Jul 13 19:18:15 2010 @@ -196,7 +196,6 @@ { const char *line_start = bytes; const char *end_line = NULL; - const char *end = bytes + bytes_len; while (p < end) { const char ch = *p; Modified: lldb/trunk/source/Core/ValueObject.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/ValueObject.cpp?rev=108299&r1=108298&r2=108299&view=diff ============================================================================== --- lldb/trunk/source/Core/ValueObject.cpp (original) +++ lldb/trunk/source/Core/ValueObject.cpp Tue Jul 13 19:18:15 2010 @@ -540,7 +540,7 @@ lldb::Encoding encoding = Type::GetEncoding (GetOpaqueClangQualType(), count); char *end = NULL; - size_t byte_size = GetByteSize(); + const size_t byte_size = GetByteSize(); switch (encoding) { case eEncodingInvalid: @@ -580,7 +580,6 @@ case eEncodingIEEE754: { - const size_t byte_size = GetByteSize(); const off_t byte_offset = GetByteOffset(); uint8_t *dst = const_cast(m_data.PeekData(byte_offset, byte_size)); if (dst != NULL) Modified: lldb/trunk/source/Expression/ClangExpression.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/ClangExpression.cpp?rev=108299&r1=108298&r2=108299&view=diff ============================================================================== --- lldb/trunk/source/Expression/ClangExpression.cpp (original) +++ lldb/trunk/source/Expression/ClangExpression.cpp Tue Jul 13 19:18:15 2010 @@ -583,15 +583,15 @@ // For now I only write functions with no stubs, globals, exception tables, // etc. So I only need to write the functions. - size_t size = 0; + size_t alloc_size = 0; std::map::iterator fun_pos, fun_end = m_jit_mm_ptr->m_functions.end(); for (fun_pos = m_jit_mm_ptr->m_functions.begin(); fun_pos != fun_end; fun_pos++) { - size += (*fun_pos).second - (*fun_pos).first; + alloc_size += (*fun_pos).second - (*fun_pos).first; } Error error; - lldb::addr_t target_addr = exc_context.process->AllocateMemory (size, lldb::ePermissionsReadable|lldb::ePermissionsExecutable, error); + lldb::addr_t target_addr = exc_context.process->AllocateMemory (alloc_size, lldb::ePermissionsReadable|lldb::ePermissionsExecutable, error); if (target_addr == LLDB_INVALID_ADDRESS) return false; Modified: lldb/trunk/source/Expression/ClangFunction.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/ClangFunction.cpp?rev=108299&r1=108298&r2=108299&view=diff ============================================================================== --- lldb/trunk/source/Expression/ClangFunction.cpp (original) +++ lldb/trunk/source/Expression/ClangFunction.cpp Tue Jul 13 19:18:15 2010 @@ -552,7 +552,7 @@ { timeout_ptr = NULL; - lldb::StateType stop_state = process->WaitForStateChangedEvents (timeout_ptr, event_sp); + stop_state = process->WaitForStateChangedEvents (timeout_ptr, event_sp); if (stop_state == lldb::eStateInvalid) { errors.Printf ("Got an invalid stop state after halt."); Modified: lldb/trunk/source/Interpreter/Args.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/Args.cpp?rev=108299&r1=108298&r2=108299&view=diff ============================================================================== --- lldb/trunk/source/Interpreter/Args.cpp (original) +++ lldb/trunk/source/Interpreter/Args.cpp Tue Jul 13 19:18:15 2010 @@ -454,7 +454,6 @@ Args::ParseOptions (Options &options) { StreamString sstr; - int i; Error error; struct option *long_options = options.GetLongOptions(); if (long_options == NULL) @@ -463,7 +462,7 @@ return error; } - for (i=0; long_options[i].name != NULL; ++i) + for (int i=0; long_options[i].name != NULL; ++i) { if (long_options[i].flag == NULL) { @@ -950,7 +949,6 @@ ) { StreamString sstr; - int i; struct option *long_options = options.GetLongOptions(); option_element_vector.clear(); @@ -963,7 +961,7 @@ // to suppress error messages. sstr << ":"; - for (i = 0; long_options[i].name != NULL; ++i) + for (int i = 0; long_options[i].name != NULL; ++i) { if (long_options[i].flag == NULL) { Modified: lldb/trunk/source/Interpreter/Options.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/Options.cpp?rev=108299&r1=108298&r2=108299&view=diff ============================================================================== --- lldb/trunk/source/Interpreter/Options.cpp (original) +++ lldb/trunk/source/Interpreter/Options.cpp Tue Jul 13 19:18:15 2010 @@ -570,9 +570,9 @@ // within the option group they belong to. char opt_str[3] = {'-', 'a', '\0'}; - for (int i = 0 ; opt_defs[i].short_option != 0 ; i++) + for (int j = 0 ; opt_defs[j].short_option != 0 ; j++) { - opt_str[1] = opt_defs[i].short_option; + opt_str[1] = opt_defs[j].short_option; matches.AppendString (opt_str); } return true; @@ -580,10 +580,10 @@ else if (opt_defs_index == OptionArgElement::eBareDoubleDash) { std::string full_name ("--"); - for (int i = 0 ; opt_defs[i].short_option != 0 ; i++) + for (int j = 0 ; opt_defs[j].short_option != 0 ; j++) { full_name.erase(full_name.begin() + 2, full_name.end()); - full_name.append (opt_defs[i].long_option); + full_name.append (opt_defs[j].long_option); matches.AppendString (full_name.c_str()); } return true; @@ -619,18 +619,18 @@ if (cur_opt_str && strlen (cur_opt_str) > 2 && cur_opt_str[0] == '-' && cur_opt_str[1] == '-') { - for (int i = 0 ; opt_defs[i].short_option != 0 ; i++) + for (int j = 0 ; opt_defs[j].short_option != 0 ; j++) { - if (strstr(opt_defs[i].long_option, cur_opt_str + 2) == opt_defs[i].long_option) + if (strstr(opt_defs[j].long_option, cur_opt_str + 2) == opt_defs[j].long_option) { std::string full_name ("--"); - full_name.append (opt_defs[i].long_option); + full_name.append (opt_defs[j].long_option); // The options definitions table has duplicates because of the // way the grouping information is stored, so only add once. bool duplicate = false; - for (int j = 0; j < matches.GetSize(); j++) + for (int k = 0; k < matches.GetSize(); k++) { - if (matches.GetStringAtIndex(j) == full_name) + if (matches.GetStringAtIndex(k) == full_name) { duplicate = true; break; Modified: lldb/trunk/source/Interpreter/ScriptInterpreter.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/ScriptInterpreter.cpp?rev=108299&r1=108298&r2=108299&view=diff ============================================================================== --- lldb/trunk/source/Interpreter/ScriptInterpreter.cpp (original) +++ lldb/trunk/source/Interpreter/ScriptInterpreter.cpp Tue Jul 13 19:18:15 2010 @@ -54,6 +54,7 @@ void ScriptInterpreter::CollectDataForBreakpointCommandCallback ( + CommandInterpreter &interpreter, BreakpointOptions *bp_options, CommandReturnObject &result ) Modified: lldb/trunk/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp?rev=108299&r1=108298&r2=108299&view=diff ============================================================================== --- lldb/trunk/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp (original) +++ lldb/trunk/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp Tue Jul 13 19:18:15 2010 @@ -505,7 +505,6 @@ { Mutex::Locker locker(m_mutex); uint32_t idx; - Error error; uint32_t i = 0; DYLDImageInfo::collection old_dyld_all_image_infos; old_dyld_all_image_infos.swap(m_dyld_image_infos); Modified: lldb/trunk/source/Plugins/DynamicLoader/MacOSX-DYLD/ObjCTrampolineHandler.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/DynamicLoader/MacOSX-DYLD/ObjCTrampolineHandler.cpp?rev=108299&r1=108298&r2=108299&view=diff ============================================================================== --- lldb/trunk/source/Plugins/DynamicLoader/MacOSX-DYLD/ObjCTrampolineHandler.cpp (original) +++ lldb/trunk/source/Plugins/DynamicLoader/MacOSX-DYLD/ObjCTrampolineHandler.cpp Tue Jul 13 19:18:15 2010 @@ -245,7 +245,7 @@ StreamString errors; { // Scope for mutex locker: - Mutex::Locker (m_impl_function_mutex); + Mutex::Locker locker(m_impl_function_mutex); if (!m_impl_function.get()) { m_impl_function.reset(new ClangFunction(process->GetTargetTriple().GetCString(), @@ -257,7 +257,6 @@ unsigned num_errors = m_impl_function->CompileFunction(errors); if (num_errors) { - Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP); if (log) log->Printf ("Error compiling function: \"%s\".", errors.GetData()); return ret_plan_sp; @@ -266,7 +265,6 @@ errors.Clear(); if (!m_impl_function->WriteFunctionWrapper(exec_ctx, errors)) { - Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP); if (log) log->Printf ("Error Inserting function: \"%s\".", errors.GetData()); return ret_plan_sp; Modified: lldb/trunk/source/Plugins/Process/Utility/libunwind/src/UnwindCursor.hpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Utility/libunwind/src/UnwindCursor.hpp?rev=108299&r1=108298&r2=108299&view=diff ============================================================================== --- lldb/trunk/source/Plugins/Process/Utility/libunwind/src/UnwindCursor.hpp (original) +++ lldb/trunk/source/Plugins/Process/Utility/libunwind/src/UnwindCursor.hpp Tue Jul 13 19:18:15 2010 @@ -551,12 +551,12 @@ const UnwindSectionIndexArray topIndex(fAddressSpace, unwindSectionStart + sectionHeader.indexSectionOffset()); uint32_t low = 0; uint32_t high = sectionHeader.indexCount(); - const uint32_t last = high - 1; + const uint32_t last_section_header = high - 1; while ( low < high ) { uint32_t mid = (low + high)/2; //if ( log ) fprintf(stderr, "\tmid=%d, low=%d, high=%d, *mid=0x%08X\n", mid, low, high, topIndex.functionOffset(mid)); if ( topIndex.functionOffset(mid) <= targetFunctionOffset ) { - if ( (mid == last) || (topIndex.functionOffset(mid+1) > targetFunctionOffset) ) { + if ( (mid == last_section_header) || (topIndex.functionOffset(mid+1) > targetFunctionOffset) ) { low = mid; break; } @@ -589,8 +589,8 @@ // binary search looks for entry with e where index[e].offset <= pc < index[e+1].offset if ( log ) fprintf(stderr, "\tbinary search for targetFunctionOffset=0x%08llX in regular page starting at secondLevelAddr=0x%llX\n", (uint64_t)targetFunctionOffset, (uint64_t)secondLevelAddr); - uint32_t low = 0; - uint32_t high = pageHeader.entryCount(); + low = 0; + high = pageHeader.entryCount(); while ( low < high ) { uint32_t mid = (low + high)/2; if ( pageIndex.functionOffset(mid) <= targetFunctionOffset ) { @@ -632,13 +632,13 @@ const uint32_t targetFunctionPageOffset = targetFunctionOffset - firstLevelFunctionOffset; // binary search looks for entry with e where index[e].offset <= pc < index[e+1].offset if ( log ) fprintf(stderr, "\tbinary search of compressed page starting at secondLevelAddr=0x%llX\n", (uint64_t)secondLevelAddr); - uint32_t low = 0; - const uint32_t last = pageHeader.entryCount() - 1; - uint32_t high = pageHeader.entryCount(); + low = 0; + const uint32_t last_page_header = pageHeader.entryCount() - 1; + high = pageHeader.entryCount(); while ( low < high ) { uint32_t mid = (low + high)/2; if ( pageIndex.functionOffset(mid) <= targetFunctionPageOffset ) { - if ( (mid == last) || (pageIndex.functionOffset(mid+1) > targetFunctionPageOffset) ) { + if ( (mid == last_page_header) || (pageIndex.functionOffset(mid+1) > targetFunctionPageOffset) ) { low = mid; break; } @@ -651,7 +651,7 @@ } } funcStart = pageIndex.functionOffset(low) + firstLevelFunctionOffset + mh; - if ( low < last ) + if ( low < last_page_header ) funcEnd = pageIndex.functionOffset(low+1) + firstLevelFunctionOffset + mh; else funcEnd = firstLevelNextPageFunctionOffset + mh; @@ -683,8 +683,8 @@ if ( encoding & UNWIND_HAS_LSDA ) { UnwindSectionLsdaArray lsdaIndex(fAddressSpace, lsdaArrayStartAddr); uint32_t funcStartOffset = funcStart - mh; - uint32_t low = 0; - uint32_t high = (lsdaArrayEndAddr-lsdaArrayStartAddr)/sizeof(unwind_info_section_header_lsda_index_entry); + low = 0; + high = (lsdaArrayEndAddr-lsdaArrayStartAddr)/sizeof(unwind_info_section_header_lsda_index_entry); // binary search looks for entry with exact match for functionOffset if ( log ) fprintf(stderr, "\tbinary search of lsda table for targetFunctionOffset=0x%08X\n", funcStartOffset); while ( low < high ) { @@ -904,6 +904,9 @@ class RemoteUnwindCursor : UnwindCursor { public: + using UnwindCursor::getReg; + using UnwindCursor::getFloatReg; + typedef typename A::pint_t pint_t; RemoteUnwindCursor(A& as, unw_context_t* regs, void* arg); virtual bool validReg(int); Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp?rev=108299&r1=108298&r2=108299&view=diff ============================================================================== --- lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp (original) +++ lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp Tue Jul 13 19:18:15 2010 @@ -25,8 +25,8 @@ extern int g_verbose; -DWARFCompileUnit::DWARFCompileUnit(SymbolFileDWARF* m_dwarf2Data) : - m_dwarf2Data ( m_dwarf2Data ), +DWARFCompileUnit::DWARFCompileUnit(SymbolFileDWARF* dwarf2Data) : + m_dwarf2Data ( dwarf2Data ), m_offset ( DW_INVALID_OFFSET ), m_length ( 0 ), m_version ( 0 ), @@ -603,8 +603,6 @@ if (num_attributes > 0) { uint32_t i; - - dw_tag_t tag = die.Tag(); is_variable = tag == DW_TAG_variable; @@ -733,8 +731,8 @@ bool is_method = false; if (parent) { - dw_tag_t tag = parent->Tag(); - if (tag == DW_TAG_class_type || tag == DW_TAG_structure_type) + dw_tag_t parent_tag = parent->Tag(); + if (parent_tag == DW_TAG_class_type || parent_tag == DW_TAG_structure_type) { is_method = true; } @@ -748,9 +746,9 @@ parent = specification_die->GetParent(); if (parent) { - tag = parent->Tag(); + parent_tag = parent->Tag(); - if (tag == DW_TAG_class_type || tag == DW_TAG_structure_type) + if (parent_tag == DW_TAG_class_type || parent_tag == DW_TAG_structure_type) is_method = true; } } Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp?rev=108299&r1=108298&r2=108299&view=diff ============================================================================== --- lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp (original) +++ lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp Tue Jul 13 19:18:15 2010 @@ -3192,7 +3192,7 @@ void *pointee_clang_type = pointee_type->GetOpaqueClangQualType(); void *class_clang_type = class_type->GetOpaqueClangQualType(); - void *clang_type = type_list->GetClangASTContext().CreateMemberPointerType(pointee_clang_type, class_clang_type); + clang_type = type_list->GetClangASTContext().CreateMemberPointerType(pointee_clang_type, class_clang_type); size_t byte_size = ClangASTContext::GetTypeBitSize(type_list->GetClangASTContext().getASTContext(), clang_type) / 8; Modified: lldb/trunk/source/Symbol/ClangASTContext.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/ClangASTContext.cpp?rev=108299&r1=108298&r2=108299&view=diff ============================================================================== --- lldb/trunk/source/Symbol/ClangASTContext.cpp (original) +++ lldb/trunk/source/Symbol/ClangASTContext.cpp Tue Jul 13 19:18:15 2010 @@ -1493,7 +1493,6 @@ decl_name.getAsOpaquePtr(), paths)) { - uint32_t child_idx; CXXBasePaths::const_paths_iterator path, path_end = paths.end(); for (path = paths.begin(); path != path_end; ++path) { Modified: lldb/trunk/source/Symbol/DWARFCallFrameInfo.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/DWARFCallFrameInfo.cpp?rev=108299&r1=108298&r2=108299&view=diff ============================================================================== --- lldb/trunk/source/Symbol/DWARFCallFrameInfo.cpp (original) +++ lldb/trunk/source/Symbol/DWARFCallFrameInfo.cpp Tue Jul 13 19:18:15 2010 @@ -664,8 +664,7 @@ while (m_cfi_data.ValidOffsetForDataOfSize(offset, 8)) { const dw_offset_t curr_offset = offset; - const uint32_t length = m_cfi_data.GetU32(&offset); - const dw_offset_t next_offset = offset + length; + const dw_offset_t next_offset = offset + m_cfi_data.GetU32(&offset); const dw_offset_t cie_id = m_cfi_data.GetU32(&offset); bool is_fde = for_eh_frame ? cie_id != 0 : cie_id != UINT32_MAX; Modified: lldb/trunk/source/Symbol/Type.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/Type.cpp?rev=108299&r1=108298&r2=108299&view=diff ============================================================================== --- lldb/trunk/source/Symbol/Type.cpp (original) +++ lldb/trunk/source/Symbol/Type.cpp Tue Jul 13 19:18:15 2010 @@ -399,7 +399,7 @@ else buf.resize (256); - lldb_private::DataExtractor data(buf.data(), buf.size(), exe_ctx->process->GetByteOrder(), 4); + lldb_private::DataExtractor cstr_data(buf.data(), buf.size(), exe_ctx->process->GetByteOrder(), 4); buf.back() = '\0'; size_t bytes_read; size_t total_cstr_len = 0; @@ -411,7 +411,7 @@ break; if (total_cstr_len == 0) s->PutCString (" \""); - data.Dump(s, 0, lldb::eFormatChar, 1, len, UINT32_MAX, LLDB_INVALID_ADDRESS, 0, 0); + cstr_data.Dump(s, 0, lldb::eFormatChar, 1, len, UINT32_MAX, LLDB_INVALID_ADDRESS, 0, 0); total_cstr_len += len; if (len < buf.size()) break; Modified: lldb/trunk/source/Target/ThreadList.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/ThreadList.cpp?rev=108299&r1=108298&r2=108299&view=diff ============================================================================== --- lldb/trunk/source/Target/ThreadList.cpp (original) +++ lldb/trunk/source/Target/ThreadList.cpp Tue Jul 13 19:18:15 2010 @@ -45,7 +45,7 @@ { // Lock both mutexes to make sure neither side changes anyone on us // while the assignement occurs - Mutex::Locker locker_this(m_threads_mutex); + Mutex::Locker locker_lhs(m_threads_mutex); Mutex::Locker locker_rhs(rhs.m_threads_mutex); m_process = rhs.m_process; m_stop_id = rhs.m_stop_id; Modified: lldb/trunk/source/Target/ThreadPlan.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/ThreadPlan.cpp?rev=108299&r1=108298&r2=108299&view=diff ============================================================================== --- lldb/trunk/source/Target/ThreadPlan.cpp (original) +++ lldb/trunk/source/Target/ThreadPlan.cpp Tue Jul 13 19:18:15 2010 @@ -66,21 +66,21 @@ bool ThreadPlan::IsPlanComplete () { - Mutex::Locker (m_plan_complete_mutex); + Mutex::Locker locker(m_plan_complete_mutex); return m_plan_complete; } void ThreadPlan::SetPlanComplete () { - Mutex::Locker (m_plan_complete_mutex); + Mutex::Locker locker(m_plan_complete_mutex); m_plan_complete = true; } bool ThreadPlan::MischiefManaged () { - Mutex::Locker (m_plan_complete_mutex); + Mutex::Locker locker(m_plan_complete_mutex); m_plan_complete = true; return true; } Modified: lldb/trunk/tools/driver/Driver.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/driver/Driver.cpp?rev=108299&r1=108298&r2=108299&view=diff ============================================================================== --- lldb/trunk/tools/driver/Driver.cpp (original) +++ lldb/trunk/tools/driver/Driver.cpp Tue Jul 13 19:18:15 2010 @@ -1220,7 +1220,7 @@ if (!iochannel_thread_exited) { - SBEvent event; + event.Clear(); listener.GetNextEventForBroadcasterWithType (*m_io_channel_ap, IOChannel::eBroadcastBitThreadDidExit, event); Modified: lldb/trunk/tools/driver/IOChannel.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/driver/IOChannel.cpp?rev=108299&r1=108298&r2=108299&view=diff ============================================================================== --- lldb/trunk/tools/driver/IOChannel.cpp (original) +++ lldb/trunk/tools/driver/IOChannel.cpp Tue Jul 13 19:18:15 2010 @@ -101,7 +101,7 @@ { for (int i = 1; i < num_elements; i++) { - const char *completion_str = completions.GetStringAtIndex(i); + completion_str = completions.GetStringAtIndex(i); OutWrite("\n\t", 2); OutWrite(completion_str, strlen (completion_str)); } @@ -119,7 +119,7 @@ endpoint = num_elements; for (; cur_pos < endpoint; cur_pos++) { - const char *completion_str = completions.GetStringAtIndex(cur_pos); + completion_str = completions.GetStringAtIndex(cur_pos); OutWrite("\n\t", 2); OutWrite(completion_str, strlen (completion_str)); } From gclayton at apple.com Tue Jul 13 19:20:31 2010 From: gclayton at apple.com (Greg Clayton) Date: Wed, 14 Jul 2010 00:20:31 -0000 Subject: [Lldb-commits] [lldb] r108300 - /lldb/trunk/lldb.xcodeproj/project.pbxproj Message-ID: <20100714002032.0372B2A6C12C@llvm.org> Author: gclayton Date: Tue Jul 13 19:20:31 2010 New Revision: 108300 URL: http://llvm.org/viewvc/llvm-project?rev=108300&view=rev Log: Fixed Xcode project to deal with recent ELF plug-in changes. Modified: lldb/trunk/lldb.xcodeproj/project.pbxproj Modified: lldb/trunk/lldb.xcodeproj/project.pbxproj URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/lldb.xcodeproj/project.pbxproj?rev=108300&r1=108299&r2=108300&view=diff ============================================================================== --- lldb/trunk/lldb.xcodeproj/project.pbxproj (original) +++ lldb/trunk/lldb.xcodeproj/project.pbxproj Tue Jul 13 19:20:31 2010 @@ -58,10 +58,10 @@ 26680336116005EF008E1FE4 /* SBBreakpointLocation.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9AF16CC7114086A1007A7B3F /* SBBreakpointLocation.cpp */; }; 26680337116005F1008E1FE4 /* SBBreakpoint.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9AF16A9C11402D5B007A7B3F /* SBBreakpoint.cpp */; }; 2668035C11601108008E1FE4 /* LLDB.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 26680207115FD0ED008E1FE4 /* LLDB.framework */; }; - 26A9641011E52C8800EE609E /* ObjectFileELF64.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 26A9640E11E52C8800EE609E /* ObjectFileELF64.cpp */; }; - 26A9641111E52C8800EE609E /* ObjectFileELF64.h in Headers */ = {isa = PBXBuildFile; fileRef = 26A9640F11E52C8800EE609E /* ObjectFileELF64.h */; }; 26B42B1F1187A92B0079C8C8 /* lldb-include.h in Headers */ = {isa = PBXBuildFile; fileRef = 26B42B1E1187A92B0079C8C8 /* lldb-include.h */; settings = {ATTRIBUTES = (Public, ); }; }; 26B42C4D1187ABA50079C8C8 /* LLDB.h in Headers */ = {isa = PBXBuildFile; fileRef = 26B42C4C1187ABA50079C8C8 /* LLDB.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 26D27C9F11ED3A4E0024D721 /* ELFHeader.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 26D27C9D11ED3A4E0024D721 /* ELFHeader.cpp */; }; + 26D27CA011ED3A4E0024D721 /* ELFHeader.h in Headers */ = {isa = PBXBuildFile; fileRef = 26D27C9E11ED3A4E0024D721 /* ELFHeader.h */; }; 26D5B06511B07550009A862E /* StoppointCallbackContext.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 26BC7E0910F1B83100F91463 /* StoppointCallbackContext.cpp */; }; 26D5B06611B07550009A862E /* Breakpoint.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 26BC7E0A10F1B83100F91463 /* Breakpoint.cpp */; }; 26D5B06711B07550009A862E /* BreakpointID.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 26BC7E0B10F1B83100F91463 /* BreakpointID.cpp */; }; @@ -417,7 +417,6 @@ 260C897D10F57C5600BB2B04 /* DynamicLoaderMacOSXDYLDLog.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DynamicLoaderMacOSXDYLDLog.h; sourceTree = ""; }; 260C898010F57C5600BB2B04 /* ObjectContainerUniversalMachO.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ObjectContainerUniversalMachO.cpp; sourceTree = ""; }; 260C898110F57C5600BB2B04 /* ObjectContainerUniversalMachO.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ObjectContainerUniversalMachO.h; sourceTree = ""; }; - 260C898410F57C5600BB2B04 /* elf.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = elf.h; sourceTree = ""; }; 260C898510F57C5600BB2B04 /* ObjectFileELF.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ObjectFileELF.cpp; sourceTree = ""; }; 260C898610F57C5600BB2B04 /* ObjectFileELF.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ObjectFileELF.h; sourceTree = ""; }; 260C898810F57C5600BB2B04 /* ObjectFileMachO.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ObjectFileMachO.cpp; sourceTree = ""; }; @@ -547,8 +546,6 @@ 26A3B4AC1181454800381BC2 /* ObjectContainerBSDArchive.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ObjectContainerBSDArchive.cpp; sourceTree = ""; }; 26A3B4AD1181454800381BC2 /* ObjectContainerBSDArchive.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ObjectContainerBSDArchive.h; sourceTree = ""; }; 26A4EEB511682AAC007A372A /* LLDBWrapPython.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = LLDBWrapPython.cpp; path = source/LLDBWrapPython.cpp; sourceTree = ""; }; - 26A9640E11E52C8800EE609E /* ObjectFileELF64.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ObjectFileELF64.cpp; sourceTree = ""; }; - 26A9640F11E52C8800EE609E /* ObjectFileELF64.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ObjectFileELF64.h; sourceTree = ""; }; 26B167A41123BF5500DC7B4F /* ThreadSafeValue.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ThreadSafeValue.h; path = include/lldb/Core/ThreadSafeValue.h; sourceTree = ""; }; 26B42B1E1187A92B0079C8C8 /* lldb-include.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "lldb-include.h"; path = "include/lldb/lldb-include.h"; sourceTree = ""; }; 26B42C4C1187ABA50079C8C8 /* LLDB.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = LLDB.h; path = include/lldb/API/LLDB.h; sourceTree = ""; }; @@ -844,6 +841,8 @@ 26D0DD5310FE555900271C65 /* BreakpointResolverAddress.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = BreakpointResolverAddress.cpp; path = source/Breakpoint/BreakpointResolverAddress.cpp; sourceTree = ""; }; 26D0DD5410FE555900271C65 /* BreakpointResolverFileLine.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = BreakpointResolverFileLine.cpp; path = source/Breakpoint/BreakpointResolverFileLine.cpp; sourceTree = ""; }; 26D0DD5510FE555900271C65 /* BreakpointResolverName.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = BreakpointResolverName.cpp; path = source/Breakpoint/BreakpointResolverName.cpp; sourceTree = ""; }; + 26D27C9D11ED3A4E0024D721 /* ELFHeader.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ELFHeader.cpp; sourceTree = ""; }; + 26D27C9E11ED3A4E0024D721 /* ELFHeader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ELFHeader.h; sourceTree = ""; }; 26DAFD9711529BC7005A394E /* ExecutionContextScope.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ExecutionContextScope.h; path = include/lldb/Target/ExecutionContextScope.h; sourceTree = ""; }; 26DE1E6911616C2E00A093E2 /* lldb-forward-rtti.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "lldb-forward-rtti.h"; path = "include/lldb/lldb-forward-rtti.h"; sourceTree = ""; }; 26DE1E6A11616C2E00A093E2 /* lldb-forward.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "lldb-forward.h"; path = "include/lldb/lldb-forward.h"; sourceTree = ""; }; @@ -1200,11 +1199,10 @@ 260C898310F57C5600BB2B04 /* ELF */ = { isa = PBXGroup; children = ( - 260C898410F57C5600BB2B04 /* elf.h */, + 26D27C9E11ED3A4E0024D721 /* ELFHeader.h */, + 26D27C9D11ED3A4E0024D721 /* ELFHeader.cpp */, 260C898610F57C5600BB2B04 /* ObjectFileELF.h */, 260C898510F57C5600BB2B04 /* ObjectFileELF.cpp */, - 26A9640F11E52C8800EE609E /* ObjectFileELF64.h */, - 26A9640E11E52C8800EE609E /* ObjectFileELF64.cpp */, ); path = ELF; sourceTree = ""; @@ -2196,7 +2194,7 @@ 49DA743511DE6BB2006AEF7E /* IRToDWARF.h in Headers */, 49307AB211DEA4F20081F992 /* IRForTarget.h in Headers */, 4C5DBBC911E3FEC60035160F /* CommandObjectCommands.h in Headers */, - 26A9641111E52C8800EE609E /* ObjectFileELF64.h in Headers */, + 26D27CA011ED3A4E0024D721 /* ELFHeader.h in Headers */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -2649,7 +2647,7 @@ 49DA743011DE6A5A006AEF7E /* IRToDWARF.cpp in Sources */, 49307AAE11DEA4D90081F992 /* IRForTarget.cpp in Sources */, 4C5DBBC811E3FEC60035160F /* CommandObjectCommands.cpp in Sources */, - 26A9641011E52C8800EE609E /* ObjectFileELF64.cpp in Sources */, + 26D27C9F11ED3A4E0024D721 /* ELFHeader.cpp in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; From jingham at apple.com Tue Jul 13 21:25:06 2010 From: jingham at apple.com (Jim Ingham) Date: Wed, 14 Jul 2010 02:25:06 -0000 Subject: [Lldb-commits] [lldb] r108311 - /lldb/trunk/source/Target/ThreadPlanStepInRange.cpp Message-ID: <20100714022506.DCF992A6C12C@llvm.org> Author: jingham Date: Tue Jul 13 21:25:06 2010 New Revision: 108311 URL: http://llvm.org/viewvc/llvm-project?rev=108311&view=rev Log: Stepping through a trampoline should do "stop others" unless All Threads is requested. Modified: lldb/trunk/source/Target/ThreadPlanStepInRange.cpp Modified: lldb/trunk/source/Target/ThreadPlanStepInRange.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/ThreadPlanStepInRange.cpp?rev=108311&r1=108310&r2=108311&view=diff ============================================================================== --- lldb/trunk/source/Target/ThreadPlanStepInRange.cpp (original) +++ lldb/trunk/source/Target/ThreadPlanStepInRange.cpp Tue Jul 13 21:25:06 2010 @@ -101,8 +101,11 @@ ThreadPlan* new_plan = NULL; + // Stepping through should be done stopping other threads in general, since we're setting a breakpoint and + // continuing... + bool stop_others; - if (m_stop_others == lldb::eOnlyThisThread) + if (m_stop_others != lldb::eAllThreads) stop_others = true; else stop_others = false; From jingham at apple.com Tue Jul 13 21:27:20 2010 From: jingham at apple.com (Jim Ingham) Date: Wed, 14 Jul 2010 02:27:20 -0000 Subject: [Lldb-commits] [lldb] r108312 - /lldb/trunk/source/Target/ThreadList.cpp Message-ID: <20100714022720.BFEDF2A6C12C@llvm.org> Author: jingham Date: Tue Jul 13 21:27:20 2010 New Revision: 108312 URL: http://llvm.org/viewvc/llvm-project?rev=108312&view=rev Log: Don't call PrepareForResume on threads that aren't going to get a chance to run this time around. Modified: lldb/trunk/source/Target/ThreadList.cpp Modified: lldb/trunk/source/Target/ThreadList.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/ThreadList.cpp?rev=108312&r1=108311&r2=108312&view=diff ============================================================================== --- lldb/trunk/source/Target/ThreadList.cpp (original) +++ lldb/trunk/source/Target/ThreadList.cpp Tue Jul 13 21:27:20 2010 @@ -314,15 +314,44 @@ m_process->UpdateThreadListIfNeeded(); collection::iterator pos, end = m_threads.end(); - - // Give all the threads a last chance to set up their state before we - // negotiate who is actually going to get a chance to run... + // See if any thread wants to run stopping others. If it does, then we won't + // setup the other threads for resume, since they aren't going to get a chance + // to run. This is necessary because the SetupForResume might add "StopOthers" + // plans which would then get to be part of the who-gets-to-run negotiation, but + // they're coming in after the fact, and the threads that are already set up should + // take priority. + + bool wants_solo_run = false; + for (pos = m_threads.begin(); pos != end; ++pos) - (*pos)->SetupForResume (); + { + if ((*pos)->GetResumeState() != eStateSuspended && + (*pos)->GetCurrentPlan()->StopOthers()) + { + wants_solo_run = true; + break; + } + } + + // Give all the threads that are likely to run a last chance to set up their state before we + // negotiate who is actually going to get a chance to run... + // Don't set to resume suspended threads, and if any thread wanted to stop others, only + // call setup on the threads that request StopOthers... + + for (pos = m_threads.begin(); pos != end; ++pos) + { + if ((*pos)->GetResumeState() != eStateSuspended + && (!wants_solo_run || (*pos)->GetCurrentPlan()->StopOthers())) + { + (*pos)->SetupForResume (); + } + } + // Now go through the threads and see if any thread wants to run just itself. // if so then pick one and run it. + ThreadList run_me_only_list (m_process); run_me_only_list.SetStopID(m_process->GetStopID()); From scallanan at apple.com Wed Jul 14 18:40:29 2010 From: scallanan at apple.com (Sean Callanan) Date: Wed, 14 Jul 2010 23:40:29 -0000 Subject: [Lldb-commits] [lldb] r108380 - in /lldb/trunk/source: Commands/CommandObjectExpression.cpp Expression/IRForTarget.cpp Message-ID: <20100714234029.34FF22A6C12C@llvm.org> Author: spyffe Date: Wed Jul 14 18:40:29 2010 New Revision: 108380 URL: http://llvm.org/viewvc/llvm-project?rev=108380&view=rev Log: Fixes to the IR generator in the expression parser to correctly unfold constant-folded global variables. Also added code to JIT the expression. Simple expressions are now JIT compiled successfully. Modified: lldb/trunk/source/Commands/CommandObjectExpression.cpp lldb/trunk/source/Expression/IRForTarget.cpp Modified: lldb/trunk/source/Commands/CommandObjectExpression.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectExpression.cpp?rev=108380&r1=108379&r2=108380&view=diff ============================================================================== --- lldb/trunk/source/Commands/CommandObjectExpression.cpp (original) +++ lldb/trunk/source/Commands/CommandObjectExpression.cpp Wed Jul 14 18:40:29 2010 @@ -270,122 +270,158 @@ log->Printf("Code cannot be interpreted and must be run in the target."); success = clang_expr.PrepareIRForTarget (expr_local_vars); } + + if (!success) + { + error_stream.PutCString ("error: expression couldn't be converted to IR\n"); + return false; + } + + if (canInterpret) + { + // TODO interpret IR + return false; + } + else + { + if (!clang_expr.JITFunction (m_exe_ctx, "___clang_expr")) + { + error_stream.PutCString ("error: IR could not be JIT compiled\n"); + return false; + } + + if (!clang_expr.WriteJITCode (m_exe_ctx)) + { + error_stream.PutCString ("error: JIT code could not be written to the target\n"); + return false; + } + + lldb::addr_t function_address(clang_expr.GetFunctionAddress ("___clang_expr")); + + if (function_address == LLDB_INVALID_ADDRESS) + { + error_stream.PutCString ("JIT compiled code's address couldn't be found\n"); + return false; + } + + log->Printf("Function is at 0x%llx", (uint64_t)function_address); + } } else { success = (clang_expr.ConvertExpressionToDWARF (expr_local_vars, dwarf_opcodes) == 0); - } - - if (!success) - { - error_stream.PutCString ("error: expression couldn't be translated to DWARF\n"); - return false; - } - - ////////////////////////////////////////// - // Evaluate the generated DWARF opcodes - // - - DataExtractor dwarf_opcodes_data (dwarf_opcodes.GetData (), dwarf_opcodes.GetSize (), eByteOrderHost, 8); - DWARFExpression dwarf_expr (dwarf_opcodes_data, 0, dwarf_opcodes_data.GetByteSize (), NULL); - - dwarf_expr.SetExpressionLocalVariableList(&expr_local_vars); - - if (log) - { - StreamString stream_string; - log->PutCString ("Expression parsed ok, dwarf opcodes:"); + if (!success) + { + error_stream.PutCString ("error: expression couldn't be translated to DWARF\n"); + return false; + } - stream_string.PutCString ("\n"); - stream_string.IndentMore (); - dwarf_expr.GetDescription (&stream_string, lldb::eDescriptionLevelVerbose); - stream_string.IndentLess (); - stream_string.EOL (); + ////////////////////////////////////////// + // Evaluate the generated DWARF opcodes + // + + DataExtractor dwarf_opcodes_data (dwarf_opcodes.GetData (), dwarf_opcodes.GetSize (), eByteOrderHost, 8); + DWARFExpression dwarf_expr (dwarf_opcodes_data, 0, dwarf_opcodes_data.GetByteSize (), NULL); + + dwarf_expr.SetExpressionLocalVariableList(&expr_local_vars); + + if (log) + { + StreamString stream_string; + + log->PutCString ("Expression parsed ok, dwarf opcodes:"); + + stream_string.PutCString ("\n"); + stream_string.IndentMore (); + dwarf_expr.GetDescription (&stream_string, lldb::eDescriptionLevelVerbose); + stream_string.IndentLess (); + stream_string.EOL (); + + log->PutCString (stream_string.GetString ().c_str ()); + } + + clang::ASTContext *ast_context = clang_expr.GetASTContext (); + Value expr_result; + Error expr_error; + success = dwarf_expr.Evaluate (&m_exe_ctx, ast_context, NULL, expr_result, &expr_error); + + if (!success) + { + error_stream.Printf ("error: couldn't evaluate DWARF expression: %s\n", expr_error.AsCString ()); + return false; + } + + /////////////////////////////////////// + // Interpret the result and print it + // + + lldb::Format format = m_options.format; + + // Resolve any values that are possible + expr_result.ResolveValue (&m_exe_ctx, ast_context); + + if (expr_result.GetContextType () == Value::eContextTypeInvalid && + expr_result.GetValueType () == Value::eValueTypeScalar && + format == eFormatDefault) + { + // The expression result is just a scalar with no special formatting + expr_result.GetScalar ().GetValue (&output_stream, m_options.show_types); + output_stream.EOL (); + return true; + } + + // The expression result is more complext and requires special handling + DataExtractor data; + expr_error = expr_result.GetValueAsData (&m_exe_ctx, ast_context, data, 0); + + if (!expr_error.Success ()) + { + error_stream.Printf ("error: couldn't resolve result value: %s\n", expr_error.AsCString ()); + return false; + } + + if (format == eFormatDefault) + format = expr_result.GetValueDefaultFormat (); + + void *clang_type = expr_result.GetValueOpaqueClangQualType (); + + if (clang_type) + { + if (m_options.show_types) + Type::DumpClangTypeName (&output_stream, clang_type); + + Type::DumpValue (&m_exe_ctx, // The execution context for memory and variable access + ast_context, // The ASTContext that the clang type belongs to + clang_type, // The opaque clang type we want to dump that value of + &output_stream, // Stream to dump to + format, // Format to use when dumping + data, // A buffer containing the bytes for the clang type + 0, // Byte offset within "data" where value is + data.GetByteSize (), // Size in bytes of the value we are dumping + 0, // Bitfield bit size + 0, // Bitfield bit offset + m_options.show_types, // Show types? + m_options.show_summary, // Show summary? + m_options.debug, // Debug logging output? + UINT32_MAX); // Depth to dump in case this is an aggregate type + } + else + { + data.Dump (&output_stream, // Stream to dump to + 0, // Byte offset within "data" + format, // Format to use when dumping + data.GetByteSize (), // Size in bytes of each item we are dumping + 1, // Number of items to dump + UINT32_MAX, // Number of items per line + LLDB_INVALID_ADDRESS, // Invalid address, don't show any offset/address context + 0, // Bitfield bit size + 0); // Bitfield bit offset + } + output_stream.EOL(); - log->PutCString (stream_string.GetString ().c_str ()); - } - - clang::ASTContext *ast_context = clang_expr.GetASTContext (); - Value expr_result; - Error expr_error; - success = dwarf_expr.Evaluate (&m_exe_ctx, ast_context, NULL, expr_result, &expr_error); - - if (!success) - { - error_stream.Printf ("error: couldn't evaluate DWARF expression: %s\n", expr_error.AsCString ()); - return false; - } - - /////////////////////////////////////// - // Interpret the result and print it - // - - lldb::Format format = m_options.format; - - // Resolve any values that are possible - expr_result.ResolveValue (&m_exe_ctx, ast_context); - - if (expr_result.GetContextType () == Value::eContextTypeInvalid && - expr_result.GetValueType () == Value::eValueTypeScalar && - format == eFormatDefault) - { - // The expression result is just a scalar with no special formatting - expr_result.GetScalar ().GetValue (&output_stream, m_options.show_types); - output_stream.EOL (); return true; } - - // The expression result is more complext and requires special handling - DataExtractor data; - expr_error = expr_result.GetValueAsData (&m_exe_ctx, ast_context, data, 0); - - if (!expr_error.Success ()) - { - error_stream.Printf ("error: couldn't resolve result value: %s\n", expr_error.AsCString ()); - return false; - } - - if (format == eFormatDefault) - format = expr_result.GetValueDefaultFormat (); - - void *clang_type = expr_result.GetValueOpaqueClangQualType (); - - if (clang_type) - { - if (m_options.show_types) - Type::DumpClangTypeName (&output_stream, clang_type); - - Type::DumpValue (&m_exe_ctx, // The execution context for memory and variable access - ast_context, // The ASTContext that the clang type belongs to - clang_type, // The opaque clang type we want to dump that value of - &output_stream, // Stream to dump to - format, // Format to use when dumping - data, // A buffer containing the bytes for the clang type - 0, // Byte offset within "data" where value is - data.GetByteSize (), // Size in bytes of the value we are dumping - 0, // Bitfield bit size - 0, // Bitfield bit offset - m_options.show_types, // Show types? - m_options.show_summary, // Show summary? - m_options.debug, // Debug logging output? - UINT32_MAX); // Depth to dump in case this is an aggregate type - } - else - { - data.Dump (&output_stream, // Stream to dump to - 0, // Byte offset within "data" - format, // Format to use when dumping - data.GetByteSize (), // Size in bytes of each item we are dumping - 1, // Number of items to dump - UINT32_MAX, // Number of items per line - LLDB_INVALID_ADDRESS, // Invalid address, don't show any offset/address context - 0, // Bitfield bit size - 0); // Bitfield bit offset - } - output_stream.EOL(); - - return true; } bool Modified: lldb/trunk/source/Expression/IRForTarget.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/IRForTarget.cpp?rev=108380&r1=108379&r2=108380&view=diff ============================================================================== --- lldb/trunk/source/Expression/IRForTarget.cpp (original) +++ lldb/trunk/source/Expression/IRForTarget.cpp Wed Jul 14 18:40:29 2010 @@ -129,7 +129,8 @@ return true; } -static std::string PrintValue(llvm::Value *V, bool truncate = false) +static std::string +PrintValue(llvm::Value *V, bool truncate = false) { std::string s; raw_string_ostream rso(s); @@ -140,6 +141,109 @@ return s; } +// UnfoldConstant operates on a constant [C] which has just been replaced with a value +// [new_value]. We assume that new_value has been properly placed early in the function, +// most likely somewhere in front of the first instruction in the entry basic block +// [first_entry_instruction]. +// +// UnfoldConstant reads through the uses of C and replaces C in those uses with new_value. +// Where those uses are constants, the function generates new instructions to compute the +// result of the new, non-constant expression and places them before first_entry_instruction. +// These instructions replace the constant uses, so UnfoldConstant calls itself recursively +// for those. + +static bool +UnfoldConstant(llvm::Constant *C, llvm::Value *new_value, llvm::Instruction *first_entry_instruction) +{ + lldb_private::Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS); + + Value::use_iterator ui; + + for (ui = C->use_begin(); + ui != C->use_end(); + ++ui) + { + User *user = *ui; + + if (Constant *constant = dyn_cast(user)) + { + // synthesize a new non-constant equivalent of the constant + + if (ConstantExpr *constant_expr = dyn_cast(constant)) + { + switch (constant_expr->getOpcode()) + { + default: + if (log) + log->Printf("Unhandled constant expression type: %s", PrintValue(constant_expr).c_str()); + return false; + case Instruction::BitCast: + { + // UnaryExpr + // OperandList[0] is value + + Value *s = constant_expr->getOperand(0); + + if (s == C) + s = new_value; + + BitCastInst *bit_cast(new BitCastInst(s, C->getType(), "", first_entry_instruction)); + + UnfoldConstant(constant_expr, bit_cast, first_entry_instruction); + } + break; + case Instruction::GetElementPtr: + { + // GetElementPtrConstantExpr + // OperandList[0] is base + // OperandList[1]... are indices + + Value *ptr = constant_expr->getOperand(0); + + if (ptr == C) + ptr = new_value; + + SmallVector indices; + + unsigned operand_index; + unsigned num_operands = constant_expr->getNumOperands(); + + for (operand_index = 1; + operand_index < num_operands; + ++operand_index) + { + Value *operand = constant_expr->getOperand(operand_index); + + if (operand == C) + operand = new_value; + + indices.push_back(operand); + } + + GetElementPtrInst *get_element_ptr(GetElementPtrInst::Create(ptr, indices.begin(), indices.end(), "", first_entry_instruction)); + + UnfoldConstant(constant_expr, get_element_ptr, first_entry_instruction); + } + break; + } + } + else + { + if (log) + log->Printf("Unhandled constant type: %s", PrintValue(constant).c_str()); + return false; + } + } + else + { + // simple fall-through case for non-constants + user->replaceUsesOfWith(C, new_value); + } + } + + return true; +} + bool IRForTarget::replaceVariables(Module &M, Function *F) { @@ -203,7 +307,10 @@ GetElementPtrInst *get_element_ptr = GetElementPtrInst::Create(argument, offset_int, "", first_entry_instruction); BitCastInst *bit_cast = new BitCastInst(get_element_ptr, value->getType(), "", first_entry_instruction); - value->replaceAllUsesWith(bit_cast); + if (Constant *constant = dyn_cast(value)) + UnfoldConstant(constant, bit_cast, first_entry_instruction); + else + value->replaceAllUsesWith(bit_cast); } if (log) From gclayton at apple.com Thu Jul 15 13:05:20 2010 From: gclayton at apple.com (Greg Clayton) Date: Thu, 15 Jul 2010 18:05:20 -0000 Subject: [Lldb-commits] [lldb] r108432 - /lldb/trunk/llvm.zip Message-ID: <20100715180521.031432A6C12C@llvm.org> Author: gclayton Date: Thu Jul 15 13:05:20 2010 New Revision: 108432 URL: http://llvm.org/viewvc/llvm-project?rev=108432&view=rev Log: Updated ELF.h in the llvm.zip to have the new needed defines (EI_NIDENT, e_ident, EI_CLASS to name a few). Modified: lldb/trunk/llvm.zip Modified: lldb/trunk/llvm.zip URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/llvm.zip?rev=108432&r1=108431&r2=108432&view=diff ============================================================================== Binary files - no diff available. From scallanan at apple.com Thu Jul 15 17:30:52 2010 From: scallanan at apple.com (Sean Callanan) Date: Thu, 15 Jul 2010 22:30:52 -0000 Subject: [Lldb-commits] [lldb] r108467 - in /lldb/trunk: include/lldb/Symbol/ClangASTContext.h source/Symbol/ClangASTContext.cpp Message-ID: <20100715223052.3DB5A2A6C12C@llvm.org> Author: spyffe Date: Thu Jul 15 17:30:52 2010 New Revision: 108467 URL: http://llvm.org/viewvc/llvm-project?rev=108467&view=rev Log: Added a function to test whether two types are the same. Modified: lldb/trunk/include/lldb/Symbol/ClangASTContext.h lldb/trunk/source/Symbol/ClangASTContext.cpp Modified: lldb/trunk/include/lldb/Symbol/ClangASTContext.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Symbol/ClangASTContext.h?rev=108467&r1=108466&r2=108467&view=diff ============================================================================== --- lldb/trunk/include/lldb/Symbol/ClangASTContext.h (original) +++ lldb/trunk/include/lldb/Symbol/ClangASTContext.h Thu Jul 15 17:30:52 2010 @@ -109,6 +109,18 @@ clang::ASTContext *source_context, void * clang_type); + static bool + AreTypesSame(clang::ASTContext *ast_context, + void *type1, + void *type2); + + bool + AreTypesSame(void *type1, + void *type2) + { + return ClangASTContext::AreTypesSame(m_ast_context_ap.get(), type1, type2); + } + //------------------------------------------------------------------ // CVR modifiers //------------------------------------------------------------------ Modified: lldb/trunk/source/Symbol/ClangASTContext.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/ClangASTContext.cpp?rev=108467&r1=108466&r2=108467&view=diff ============================================================================== --- lldb/trunk/source/Symbol/ClangASTContext.cpp (original) +++ lldb/trunk/source/Symbol/ClangASTContext.cpp Thu Jul 15 17:30:52 2010 @@ -672,6 +672,15 @@ return ret.getAsOpaquePtr(); } +static bool +AreTypesSame(clang::ASTContext *ast_context, + void *type1, + void *type2) +{ + return ast_context->hasSameType(QualType::getFromOpaquePtr(type1), + QualType::getFromOpaquePtr(type2)); +} + #pragma mark CVR modifiers void * From scallanan at apple.com Thu Jul 15 19:00:27 2010 From: scallanan at apple.com (Sean Callanan) Date: Fri, 16 Jul 2010 00:00:27 -0000 Subject: [Lldb-commits] [lldb] r108483 - /lldb/trunk/source/Symbol/ClangASTContext.cpp Message-ID: <20100716000027.B9D082A6C12C@llvm.org> Author: spyffe Date: Thu Jul 15 19:00:27 2010 New Revision: 108483 URL: http://llvm.org/viewvc/llvm-project?rev=108483&view=rev Log: Oops, didn't define AreTypesSame correctly. Modified: lldb/trunk/source/Symbol/ClangASTContext.cpp Modified: lldb/trunk/source/Symbol/ClangASTContext.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/ClangASTContext.cpp?rev=108483&r1=108482&r2=108483&view=diff ============================================================================== --- lldb/trunk/source/Symbol/ClangASTContext.cpp (original) +++ lldb/trunk/source/Symbol/ClangASTContext.cpp Thu Jul 15 19:00:27 2010 @@ -672,8 +672,8 @@ return ret.getAsOpaquePtr(); } -static bool -AreTypesSame(clang::ASTContext *ast_context, +bool +ClangASTContext::AreTypesSame(clang::ASTContext *ast_context, void *type1, void *type2) { From scallanan at apple.com Thu Jul 15 19:09:47 2010 From: scallanan at apple.com (Sean Callanan) Date: Fri, 16 Jul 2010 00:09:47 -0000 Subject: [Lldb-commits] [lldb] r108485 - in /lldb/trunk: include/lldb/Expression/ClangExpressionDeclMap.h source/Commands/CommandObjectExpression.cpp source/Expression/ClangExpressionDeclMap.cpp source/Expression/IRForTarget.cpp Message-ID: <20100716000947.27BD32A6C12C@llvm.org> Author: spyffe Date: Thu Jul 15 19:09:46 2010 New Revision: 108485 URL: http://llvm.org/viewvc/llvm-project?rev=108485&view=rev Log: Wrote the code that looks at a context to see if the variables in that context allow a particular JIT compiled expression to run in that context. Modified: lldb/trunk/include/lldb/Expression/ClangExpressionDeclMap.h lldb/trunk/source/Commands/CommandObjectExpression.cpp lldb/trunk/source/Expression/ClangExpressionDeclMap.cpp lldb/trunk/source/Expression/IRForTarget.cpp Modified: lldb/trunk/include/lldb/Expression/ClangExpressionDeclMap.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Expression/ClangExpressionDeclMap.h?rev=108485&r1=108484&r2=108485&view=diff ============================================================================== --- lldb/trunk/include/lldb/Expression/ClangExpressionDeclMap.h (original) +++ lldb/trunk/include/lldb/Expression/ClangExpressionDeclMap.h Thu Jul 15 19:09:46 2010 @@ -25,6 +25,7 @@ namespace clang { class DeclarationName; class DeclContext; + class QualType; } namespace llvm { @@ -33,6 +34,7 @@ namespace lldb_private { +class Error; class Function; class NameSearchContext; class Variable; @@ -50,6 +52,8 @@ // Interface for IRForTarget bool AddValueToStruct (llvm::Value *value, const clang::NamedDecl *decl, + std::string &name, + void *type, size_t size, off_t alignment); bool DoStructLayout (); @@ -64,6 +68,10 @@ // Interface for DwarfExpression Value *GetValueForIndex (uint32_t index); + // Interface for CommandObjectExpression + lldb::addr_t Materialize(ExecutionContext *exe_ctx, + Error &error); + // Interface for ClangASTSource void GetDecls (NameSearchContext &context, const char *name); @@ -72,13 +80,17 @@ struct Tuple { const clang::NamedDecl *m_decl; + clang::ASTContext *m_ast_context; + void *m_orig_type; Value *m_value; /* owned by ClangExpressionDeclMap */ }; struct StructMember { - const clang::NamedDecl *m_decl; - llvm::Value *m_value; + const clang::NamedDecl *m_decl; + llvm::Value *m_value; + std::string m_name; + void *m_type; off_t m_offset; size_t m_size; off_t m_alignment; @@ -97,9 +109,17 @@ off_t m_struct_alignment; size_t m_struct_size; bool m_struct_laid_out; - + lldb::addr_t m_materialized_location; + void AddOneVariable(NameSearchContext &context, Variable *var); void AddOneFunction(NameSearchContext &context, Function *fun); + + bool MaterializeOneVariable(ExecutionContext &exe_ctx, + const SymbolContext &sym_ctx, + const char *name, + void *type, + clang::ASTContext *ast_context, + lldb::addr_t addr); }; } // namespace lldb_private Modified: lldb/trunk/source/Commands/CommandObjectExpression.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectExpression.cpp?rev=108485&r1=108484&r2=108485&view=diff ============================================================================== --- lldb/trunk/source/Commands/CommandObjectExpression.cpp (original) +++ lldb/trunk/source/Commands/CommandObjectExpression.cpp Thu Jul 15 19:09:46 2010 @@ -304,8 +304,22 @@ return false; } - log->Printf("Function is at 0x%llx", (uint64_t)function_address); + Error err; + + lldb::addr_t struct_address = expr_decl_map.Materialize(&m_exe_ctx, err); + + if (struct_address == LLDB_INVALID_ADDRESS) + { + error_stream.Printf ("Couldn't materialize struct: %s\n", err.AsCString("unknown error")); + return false; + } + + log->Printf("Function address : 0x%llx", (uint64_t)function_address); + log->Printf("Structure address : 0x%llx", (uint64_t)struct_address); } + + return true; + } else { Modified: lldb/trunk/source/Expression/ClangExpressionDeclMap.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/ClangExpressionDeclMap.cpp?rev=108485&r1=108484&r2=108485&view=diff ============================================================================== --- lldb/trunk/source/Expression/ClangExpressionDeclMap.cpp (original) +++ lldb/trunk/source/Expression/ClangExpressionDeclMap.cpp Thu Jul 15 19:09:46 2010 @@ -15,6 +15,7 @@ // Project includes #include "lldb/lldb-private.h" #include "lldb/Core/Address.h" +#include "lldb/Core/Error.h" #include "lldb/Core/Log.h" #include "lldb/Core/Module.h" #include "lldb/Expression/ClangASTSource.h" @@ -27,19 +28,17 @@ #include "lldb/Symbol/TypeList.h" #include "lldb/Symbol/Variable.h" #include "lldb/Symbol/VariableList.h" +#include "lldb/Target/Process.h" #include "lldb/Target/StackFrame.h" #include "lldb/Target/ExecutionContext.h" -#define DEBUG_PRINTF(...) \ - if (log) \ - log->Printf(__VA_ARGS__) - using namespace lldb_private; using namespace clang; ClangExpressionDeclMap::ClangExpressionDeclMap(ExecutionContext *exe_ctx) : m_exe_ctx(exe_ctx), - m_struct_laid_out(false) + m_struct_laid_out(false), + m_materialized_location(0) { if (exe_ctx && exe_ctx->frame) m_sym_ctx = new SymbolContext(exe_ctx->frame->GetSymbolContext(lldb::eSymbolContextEverything)); @@ -83,6 +82,8 @@ bool ClangExpressionDeclMap::AddValueToStruct (llvm::Value *value, const clang::NamedDecl *decl, + std::string &name, + void *type, size_t size, off_t alignment) { @@ -102,6 +103,8 @@ member.m_value = value; member.m_decl = decl; + member.m_name = name; + member.m_type = type; member.m_offset = 0; member.m_size = size; member.m_alignment = alignment; @@ -187,6 +190,136 @@ return m_tuples[index].m_value; } +// Interface for CommandObjectExpression +lldb::addr_t +ClangExpressionDeclMap::Materialize (ExecutionContext *exe_ctx, Error &err) +{ + if (!m_struct_laid_out) + { + err.SetErrorString("Structure hasn't been laid out yet"); + return LLDB_INVALID_ADDRESS; + } + + if (m_materialized_location) + { + exe_ctx->process->DeallocateMemory(m_materialized_location); + m_materialized_location = 0; + } + + if (!exe_ctx) + { + err.SetErrorString("Received null execution context"); + return LLDB_INVALID_ADDRESS; + } + + const SymbolContext &sym_ctx(exe_ctx->frame->GetSymbolContext(lldb::eSymbolContextEverything)); + + StructMemberIterator iter; + + lldb::addr_t mem = exe_ctx->process->AllocateMemory(m_struct_alignment + m_struct_size, + lldb::ePermissionsReadable | lldb::ePermissionsWritable, + err); + + if (mem == LLDB_INVALID_ADDRESS) + return LLDB_INVALID_ADDRESS; + + m_materialized_location = mem; + + lldb::addr_t aligned_mem = mem; + + if (aligned_mem % m_struct_alignment) + { + aligned_mem += (m_struct_alignment - (aligned_mem % m_struct_alignment)); + } + + for (iter = m_members.begin(); + iter != m_members.end(); + ++iter) + { + uint32_t tuple_index; + + if (!GetIndexForDecl(tuple_index, iter->m_decl)) + continue; + + Tuple &tuple(m_tuples[tuple_index]); + + MaterializeOneVariable(*exe_ctx, sym_ctx, iter->m_name.c_str(), tuple.m_orig_type, tuple.m_ast_context, aligned_mem + iter->m_offset); + } + + return aligned_mem; +} + +bool +ClangExpressionDeclMap::MaterializeOneVariable(ExecutionContext &exe_ctx, + const SymbolContext &sym_ctx, + const char *name, + void *type, + clang::ASTContext *ast_context, + lldb::addr_t addr) +{ + Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS); + + Function *function(m_sym_ctx->function); + Block *block(m_sym_ctx->block); + + if (!function || !block) + { + if (log) + log->Printf("function = %p, block = %p", function, block); + return false; + } + + BlockList& blocks(function->GetBlocks(true)); + + lldb::user_id_t current_block_id; + + for (current_block_id = block->GetID(); + current_block_id != Block::InvalidID; + current_block_id = blocks.GetParent(current_block_id)) + { + Block *current_block(blocks.GetBlockByID(current_block_id)); + + lldb::VariableListSP var_list = current_block->GetVariableList(false, true); + + if (!var_list) + continue; + + lldb::VariableSP var = var_list->FindVariable(ConstString(name)); + + if (!var) + continue; + + // var->GetType()->GetClangAST() is the program's AST context and holds + // var->GetType()->GetOpaqueClangQualType(). + + // type is m_type for one of the struct members, which was added by + // AddValueToStruct. That type was extracted from the AST context of + // the compiler in IRForTarget. The original for the type was copied + // out of the program's AST context by AddOneVariable. + + // The key here is: we know when we copied a type, and for what Decl we + // did it. So we need for each struct Tuple to keep the type that we + // found, and which AST context we found it in. Then we can look up + // m_decl in m_tuples. + + if (ast_context == var->GetType()->GetClangAST()) + { + if (!ClangASTContext::AreTypesSame(ast_context, type, var->GetType()->GetOpaqueClangQualType())) + continue; + } + else + { + if (log) + log->PutCString("Skipping a candidate variable because of different AST contexts"); + continue; + } + + + } + + return true; +} + // Interface for ClangASTSource void ClangExpressionDeclMap::GetDecls(NameSearchContext &context, @@ -194,7 +327,8 @@ { Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS); - DEBUG_PRINTF("Hunting for a definition for %s", name); + if (log) + log->Printf("Hunting for a definition for %s", name); // Back out in all cases where we're not fully initialized if (!m_exe_ctx || !m_exe_ctx->frame || !m_sym_ctx) @@ -205,7 +339,8 @@ if (!function || !block) { - DEBUG_PRINTF("function = %p, block = %p", function, block); + if (log) + log->Printf("function = %p, block = %p", function, block); return; } @@ -247,7 +382,8 @@ if (!compile_unit) { - DEBUG_PRINTF("compile_unit = %p", compile_unit); + if (log) + log->Printf("compile_unit = %p", compile_unit); return; } @@ -276,7 +412,8 @@ if (!var_type) { - DEBUG_PRINTF("Skipped a definition because it has no type"); + if (log) + log->PutCString("Skipped a definition because it has no type"); return; } @@ -284,7 +421,8 @@ if (!var_opaque_type) { - DEBUG_PRINTF("Skipped a definition because it has no Clang type"); + if (log) + log->PutCString("Skipped a definition because it has no Clang type"); return; } @@ -294,7 +432,8 @@ if (!type_list) { - DEBUG_PRINTF("Skipped a definition because the type has no associated type list"); + if (log) + log->PutCString("Skipped a definition because the type has no associated type list"); return; } @@ -302,7 +441,8 @@ if (!exe_ast_ctx) { - DEBUG_PRINTF("There is no AST context for the current execution context"); + if (log) + log->PutCString("There is no AST context for the current execution context"); return; } @@ -312,11 +452,14 @@ if (!var_location_expr.Evaluate(m_exe_ctx, exe_ast_ctx, NULL, *var_location.get(), &err)) { - DEBUG_PRINTF("Error evaluating location: %s", err.AsCString()); + if (log) + log->Printf("Error evaluating location: %s", err.AsCString()); return; } - void *copied_type = ClangASTContext::CopyType(context.GetASTContext(), type_list->GetClangASTContext().getASTContext(), var_opaque_type); + clang::ASTContext *var_ast_context = type_list->GetClangASTContext().getASTContext(); + + void *copied_type = ClangASTContext::CopyType(context.GetASTContext(), var_ast_context, var_opaque_type); if (var_location.get()->GetContextType() == Value::eContextTypeInvalid) var_location.get()->SetContext(Value::eContextTypeOpaqueClangQualType, copied_type); @@ -346,12 +489,15 @@ Tuple tuple; - tuple.m_decl = var_decl; - tuple.m_value = var_location.release(); + tuple.m_decl = var_decl; + tuple.m_value = var_location.release(); + tuple.m_orig_type = var_opaque_type; + tuple.m_ast_context = var_ast_context; m_tuples.push_back(tuple); - DEBUG_PRINTF("Found variable"); + if (log) + log->PutCString("Found variable"); } void @@ -364,7 +510,8 @@ if (!fun_type) { - DEBUG_PRINTF("Skipped a function because it has no type"); + if (log) + log->PutCString("Skipped a function because it has no type"); return; } @@ -372,7 +519,8 @@ if (!fun_opaque_type) { - DEBUG_PRINTF("Skipped a function because it has no Clang type"); + if (log) + log->PutCString("Skipped a function because it has no Clang type"); return; } @@ -384,16 +532,20 @@ fun_location->GetScalar() = load_addr; TypeList *type_list = fun_type->GetTypeList(); - void *copied_type = ClangASTContext::CopyType(context.GetASTContext(), type_list->GetClangASTContext().getASTContext(), fun_opaque_type); + clang::ASTContext *fun_ast_context = type_list->GetClangASTContext().getASTContext(); + void *copied_type = ClangASTContext::CopyType(context.GetASTContext(), fun_ast_context, fun_opaque_type); NamedDecl *fun_decl = context.AddFunDecl(copied_type); Tuple tuple; - tuple.m_decl = fun_decl; - tuple.m_value = fun_location.release(); + tuple.m_decl = fun_decl; + tuple.m_value = fun_location.release(); + tuple.m_orig_type = fun_opaque_type; + tuple.m_ast_context = fun_ast_context; m_tuples.push_back(tuple); - DEBUG_PRINTF("Found function"); + if (log) + log->PutCString("Found function"); } Modified: lldb/trunk/source/Expression/IRForTarget.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/IRForTarget.cpp?rev=108485&r1=108484&r2=108485&view=diff ============================================================================== --- lldb/trunk/source/Expression/IRForTarget.cpp (original) +++ lldb/trunk/source/Expression/IRForTarget.cpp Thu Jul 15 19:09:46 2010 @@ -90,12 +90,26 @@ { clang::NamedDecl *named_decl = DeclForGlobalValue(M, global_variable); + std::string name = named_decl->getName().str(); + + void *qual_type = NULL; + + if (clang::ValueDecl *value_decl = dyn_cast(named_decl)) + qual_type = value_decl->getType().getAsOpaquePtr(); + else + return false; + const llvm::Type *value_type = global_variable->getType(); size_t value_size = m_target_data->getTypeStoreSize(value_type); off_t value_alignment = m_target_data->getPrefTypeAlignment(value_type); - if (named_decl && !DM->AddValueToStruct(V, named_decl, value_size, value_alignment)) + if (named_decl && !DM->AddValueToStruct(V, + named_decl, + name, + qual_type, + value_size, + value_alignment)) return false; } From benny.kra at googlemail.com Fri Jul 16 07:32:33 2010 From: benny.kra at googlemail.com (Benjamin Kramer) Date: Fri, 16 Jul 2010 12:32:33 -0000 Subject: [Lldb-commits] [lldb] r108524 - in /lldb/trunk/source/Target: Thread.cpp ThreadPlan.cpp ThreadPlanCallFunction.cpp ThreadPlanStepInstruction.cpp ThreadPlanStepOut.cpp Message-ID: <20100716123233.392A72A6C12C@llvm.org> Author: d0k Date: Fri Jul 16 07:32:33 2010 New Revision: 108524 URL: http://llvm.org/viewvc/llvm-project?rev=108524&view=rev Log: Fix constructor initialization order. Patch by Bill Lynch. Modified: lldb/trunk/source/Target/Thread.cpp lldb/trunk/source/Target/ThreadPlan.cpp lldb/trunk/source/Target/ThreadPlanCallFunction.cpp lldb/trunk/source/Target/ThreadPlanStepInstruction.cpp lldb/trunk/source/Target/ThreadPlanStepOut.cpp Modified: lldb/trunk/source/Target/Thread.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Thread.cpp?rev=108524&r1=108523&r2=108524&view=diff ============================================================================== --- lldb/trunk/source/Target/Thread.cpp (original) +++ lldb/trunk/source/Target/Thread.cpp Fri Jul 16 07:32:33 2010 @@ -36,9 +36,9 @@ Thread::Thread (Process &process, lldb::tid_t tid) : UserID (tid), + m_process (process), m_index_id (process.GetNextThreadIndexID ()), m_reg_context_sp (), - m_process (process), m_state (eStateUnloaded), m_plan_stack (), m_immediate_plan_stack(), @@ -90,8 +90,8 @@ Thread::StopInfo::StopInfo(Thread *thread) : m_reason (eStopReasonInvalid), - m_description (), m_thread (thread), + m_description (), m_details () { m_description[0] = '\0'; Modified: lldb/trunk/source/Target/ThreadPlan.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/ThreadPlan.cpp?rev=108524&r1=108523&r2=108524&view=diff ============================================================================== --- lldb/trunk/source/Target/ThreadPlan.cpp (original) +++ lldb/trunk/source/Target/ThreadPlan.cpp Fri Jul 16 07:32:33 2010 @@ -24,14 +24,14 @@ // ThreadPlan constructor //---------------------------------------------------------------------- ThreadPlan::ThreadPlan(ThreadPlanKind kind, const char *name, Thread &thread, Vote stop_vote, Vote run_vote) : + m_thread (thread), + m_stop_vote (stop_vote), + m_run_vote (run_vote), m_kind (kind), m_name (name), - m_thread (thread), - m_plan_complete(false), m_plan_complete_mutex (Mutex::eMutexTypeRecursive), + m_plan_complete (false), m_plan_private (false), - m_stop_vote (stop_vote), - m_run_vote (run_vote), m_okay_to_discard (false) { SetID (GetNextID()); Modified: lldb/trunk/source/Target/ThreadPlanCallFunction.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/ThreadPlanCallFunction.cpp?rev=108524&r1=108523&r2=108524&view=diff ============================================================================== --- lldb/trunk/source/Target/ThreadPlanCallFunction.cpp (original) +++ lldb/trunk/source/Target/ThreadPlanCallFunction.cpp Fri Jul 16 07:32:33 2010 @@ -36,12 +36,12 @@ bool stop_other_threads, bool discard_on_error) : ThreadPlan (ThreadPlan::eKindCallFunction, "Call function plan", thread, eVoteNoOpinion, eVoteNoOpinion), - m_valid(false), - m_process(thread.GetProcess()), + m_valid (false), + m_stop_other_threads (stop_other_threads), m_arg_addr (arg), m_args (NULL), - m_thread(thread), - m_stop_other_threads(stop_other_threads) + m_process (thread.GetProcess()), + m_thread (thread) { SetOkayToDiscard (discard_on_error); @@ -90,12 +90,12 @@ bool stop_other_threads, bool discard_on_error) : ThreadPlan (ThreadPlan::eKindCallFunction, "Call function plan", thread, eVoteNoOpinion, eVoteNoOpinion), - m_valid(false), - m_process(thread.GetProcess()), + m_valid (false), + m_stop_other_threads (stop_other_threads), m_arg_addr (0), m_args (&args), - m_thread(thread), - m_stop_other_threads(stop_other_threads) + m_process (thread.GetProcess()), + m_thread (thread) { SetOkayToDiscard (discard_on_error); Modified: lldb/trunk/source/Target/ThreadPlanStepInstruction.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/ThreadPlanStepInstruction.cpp?rev=108524&r1=108523&r2=108524&view=diff ============================================================================== --- lldb/trunk/source/Target/ThreadPlanStepInstruction.cpp (original) +++ lldb/trunk/source/Target/ThreadPlanStepInstruction.cpp Fri Jul 16 07:32:33 2010 @@ -39,9 +39,10 @@ ) : ThreadPlan (ThreadPlan::eKindStepInstruction, "Step over single instruction", thread, stop_vote, run_vote), m_instruction_addr (0), + m_stop_other_threads (stop_other_threads), m_step_over (step_over), - m_stack_depth(0), - m_stop_other_threads (stop_other_threads){ + m_stack_depth (0) +{ m_instruction_addr = m_thread.GetRegisterContext()->GetPC(0); m_stack_depth = m_thread.GetStackFrameCount(); } Modified: lldb/trunk/source/Target/ThreadPlanStepOut.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/ThreadPlanStepOut.cpp?rev=108524&r1=108523&r2=108524&view=diff ============================================================================== --- lldb/trunk/source/Target/ThreadPlanStepOut.cpp (original) +++ lldb/trunk/source/Target/ThreadPlanStepOut.cpp Fri Jul 16 07:32:33 2010 @@ -39,9 +39,9 @@ ThreadPlan (ThreadPlan::eKindStepOut, "Step out", thread, stop_vote, run_vote), m_step_from_context (context), m_step_from_insn (LLDB_INVALID_ADDRESS), + m_return_bp_id (LLDB_INVALID_BREAK_ID), m_return_addr (LLDB_INVALID_ADDRESS), m_first_insn (first_insn), - m_return_bp_id(LLDB_INVALID_BREAK_ID), m_stop_others (stop_others) { m_step_from_insn = m_thread.GetRegisterContext()->GetPC(0); From gclayton at apple.com Fri Jul 16 13:28:27 2010 From: gclayton at apple.com (Greg Clayton) Date: Fri, 16 Jul 2010 18:28:27 -0000 Subject: [Lldb-commits] [lldb] r108544 - /lldb/trunk/source/Expression/ClangASTSource.cpp Message-ID: <20100716182827.DF4A32A6C12C@llvm.org> Author: gclayton Date: Fri Jul 16 13:28:27 2010 New Revision: 108544 URL: http://llvm.org/viewvc/llvm-project?rev=108544&view=rev Log: Fixed a copyright header. Modified: lldb/trunk/source/Expression/ClangASTSource.cpp Modified: lldb/trunk/source/Expression/ClangASTSource.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/ClangASTSource.cpp?rev=108544&r1=108543&r2=108544&view=diff ============================================================================== --- lldb/trunk/source/Expression/ClangASTSource.cpp (original) +++ lldb/trunk/source/Expression/ClangASTSource.cpp Fri Jul 16 13:28:27 2010 @@ -1,11 +1,12 @@ -/* - * ClangASTSource.cpp - * lldb - * - * Created by John McCall on 6/1/10. - * Copyright 2010 Apple. All rights reserved. - * - */ +//===-- ClangASTSource.cpp ---------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + #include "clang/AST/ASTContext.h" #include "lldb/Expression/ClangASTSource.h" From neeracher at apple.com Fri Jul 16 18:50:10 2010 From: neeracher at apple.com (Matthias Neeracher) Date: Sat, 17 Jul 2010 01:50:10 +0200 Subject: [Lldb-commits] Proposed patch: hardcode sed path in build script Message-ID: <172F1974-2F62-455D-9816-4E4ACB335A40@apple.com> lldb would not build on my machine because I had GNU sed installed and it appears that has a slightly different command line syntax. This is easily fixed by hardcoding sed as /usr/bin/sed in the script. Matthias -------------- next part -------------- A non-text attachment was scrubbed... Name: sed.patch Type: application/octet-stream Size: 952 bytes Desc: not available Url : http://lists.cs.uiuc.edu/pipermail/lldb-commits/attachments/20100717/697510f8/attachment.obj From jingham at apple.com Fri Jul 16 19:25:08 2010 From: jingham at apple.com (Jim Ingham) Date: Sat, 17 Jul 2010 00:25:08 -0000 Subject: [Lldb-commits] [lldb] r108580 - /lldb/trunk/lldb.xcodeproj/project.pbxproj Message-ID: <20100717002508.AFE9F2A6C12C@llvm.org> Author: jingham Date: Fri Jul 16 19:25:08 2010 New Revision: 108580 URL: http://llvm.org/viewvc/llvm-project?rev=108580&view=rev Log: Patch from Mattias to specify the system sed on Mac OS X. Modified: lldb/trunk/lldb.xcodeproj/project.pbxproj Modified: lldb/trunk/lldb.xcodeproj/project.pbxproj URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/lldb.xcodeproj/project.pbxproj?rev=108580&r1=108579&r2=108580&view=diff ============================================================================== --- lldb/trunk/lldb.xcodeproj/project.pbxproj (original) +++ lldb/trunk/lldb.xcodeproj/project.pbxproj Fri Jul 16 19:25:08 2010 @@ -2303,7 +2303,7 @@ ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "cd \"${TARGET_BUILD_DIR}/${PUBLIC_HEADERS_FOLDER_PATH}\"\nfor file in *.h\ndo\n\tsed -i '' 's/\\(#include\\)[ ]*\"lldb\\/\\(API\\/\\)\\{0,1\\}\\(.*\\)\"/\\1 /1' \"$file\"\n\tsed -i '' 's|/1' \"$file\"\n\t/usr/bin/sed -i '' 's| An embedded and charset-unspecified text was scrubbed... Name: break-id.patch Url: http://lists.cs.uiuc.edu/pipermail/lldb-commits/attachments/20100716/daaa1417/attachment.pl From scallanan at apple.com Fri Jul 16 19:43:37 2010 From: scallanan at apple.com (Sean Callanan) Date: Sat, 17 Jul 2010 00:43:37 -0000 Subject: [Lldb-commits] [lldb] r108596 - in /lldb/trunk: include/lldb/Expression/ClangExpressionDeclMap.h source/Expression/ClangExpressionDeclMap.cpp Message-ID: <20100717004337.7F5352A6C12C@llvm.org> Author: spyffe Date: Fri Jul 16 19:43:37 2010 New Revision: 108596 URL: http://llvm.org/viewvc/llvm-project?rev=108596&view=rev Log: Added the necessary code to copy variables used by an expression into the struct prepared for the JIT compiled code to use. Modified: lldb/trunk/include/lldb/Expression/ClangExpressionDeclMap.h lldb/trunk/source/Expression/ClangExpressionDeclMap.cpp Modified: lldb/trunk/include/lldb/Expression/ClangExpressionDeclMap.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Expression/ClangExpressionDeclMap.h?rev=108596&r1=108595&r2=108596&view=diff ============================================================================== --- lldb/trunk/include/lldb/Expression/ClangExpressionDeclMap.h (original) +++ lldb/trunk/include/lldb/Expression/ClangExpressionDeclMap.h Fri Jul 16 19:43:37 2010 @@ -111,6 +111,17 @@ bool m_struct_laid_out; lldb::addr_t m_materialized_location; + Variable *FindVariableInScope(const SymbolContext &sym_ctx, + const char *name, + void *type = NULL, + clang::ASTContext *ast_context = NULL); + + Value *GetVariableValue(ExecutionContext &exe_ctx, + Variable *var, + clang::ASTContext *target_ast_context = NULL, + void **opaque_type = NULL, + clang::ASTContext **found_ast_context = NULL); + void AddOneVariable(NameSearchContext &context, Variable *var); void AddOneFunction(NameSearchContext &context, Function *fun); @@ -119,7 +130,8 @@ const char *name, void *type, clang::ASTContext *ast_context, - lldb::addr_t addr); + lldb::addr_t addr, + Error &err); }; } // namespace lldb_private Modified: lldb/trunk/source/Expression/ClangExpressionDeclMap.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/ClangExpressionDeclMap.cpp?rev=108596&r1=108595&r2=108596&view=diff ============================================================================== --- lldb/trunk/source/Expression/ClangExpressionDeclMap.cpp (original) +++ lldb/trunk/source/Expression/ClangExpressionDeclMap.cpp Fri Jul 16 19:43:37 2010 @@ -194,6 +194,8 @@ lldb::addr_t ClangExpressionDeclMap::Materialize (ExecutionContext *exe_ctx, Error &err) { + Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS); + if (!m_struct_laid_out) { err.SetErrorString("Structure hasn't been laid out yet"); @@ -238,24 +240,34 @@ { uint32_t tuple_index; - if (!GetIndexForDecl(tuple_index, iter->m_decl)) + if (!GetIndexForDecl(tuple_index, iter->m_decl)) + { + if (iter->m_name.find("___clang_expr_result") == std::string::npos) + { + err.SetErrorStringWithFormat("Unexpected variable %s", iter->m_name.c_str()); + return false; + } + + if (log) + log->Printf("Found special result variable %s", iter->m_name.c_str()); + continue; + } Tuple &tuple(m_tuples[tuple_index]); - MaterializeOneVariable(*exe_ctx, sym_ctx, iter->m_name.c_str(), tuple.m_orig_type, tuple.m_ast_context, aligned_mem + iter->m_offset); + if (!MaterializeOneVariable(*exe_ctx, sym_ctx, iter->m_name.c_str(), tuple.m_orig_type, tuple.m_ast_context, aligned_mem + iter->m_offset, err)) + return false; } return aligned_mem; } -bool -ClangExpressionDeclMap::MaterializeOneVariable(ExecutionContext &exe_ctx, - const SymbolContext &sym_ctx, - const char *name, - void *type, - clang::ASTContext *ast_context, - lldb::addr_t addr) +Variable* +ClangExpressionDeclMap::FindVariableInScope(const SymbolContext &sym_ctx, + const char *name, + void *type, + clang::ASTContext *ast_context) { Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS); @@ -266,11 +278,13 @@ { if (log) log->Printf("function = %p, block = %p", function, block); - return false; + return NULL; } BlockList& blocks(function->GetBlocks(true)); + ConstString name_cs(name); + lldb::user_id_t current_block_id; for (current_block_id = block->GetID(); @@ -284,7 +298,7 @@ if (!var_list) continue; - lldb::VariableSP var = var_list->FindVariable(ConstString(name)); + lldb::VariableSP var = var_list->FindVariable(name_cs); if (!var) continue; @@ -297,10 +311,13 @@ // the compiler in IRForTarget. The original for the type was copied // out of the program's AST context by AddOneVariable. - // The key here is: we know when we copied a type, and for what Decl we - // did it. So we need for each struct Tuple to keep the type that we - // found, and which AST context we found it in. Then we can look up - // m_decl in m_tuples. + // So that we can compare these two without having to copy back + // something we already had in the original AST context, we maintain + // m_orig_type and m_ast_context (which are passed into + // MaterializeOneVariable by Materialize) for each variable. + + if (!type) + return var.get(); if (ast_context == var->GetType()->GetClangAST()) { @@ -314,7 +331,114 @@ continue; } + return var.get(); + } + + { + CompileUnit *compile_unit = m_sym_ctx->comp_unit; + + if (!compile_unit) + { + if (log) + log->Printf("compile_unit = %p", compile_unit); + return NULL; + } + + lldb::VariableListSP var_list = compile_unit->GetVariableList(true); + + if (!var_list) + return NULL; + + lldb::VariableSP var = var_list->FindVariable(name_cs); + + if (!var) + return NULL; + + if (!type) + return var.get(); + + if (ast_context == var->GetType()->GetClangAST()) + { + if (!ClangASTContext::AreTypesSame(ast_context, type, var->GetType()->GetOpaqueClangQualType())) + return NULL; + } + else + { + if (log) + log->PutCString("Skipping a candidate variable because of different AST contexts"); + return NULL; + } + + return var.get(); + } + + return NULL; +} + +bool +ClangExpressionDeclMap::MaterializeOneVariable(ExecutionContext &exe_ctx, + const SymbolContext &sym_ctx, + const char *name, + void *type, + clang::ASTContext *ast_context, + lldb::addr_t addr, + Error &err) +{ + Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS); + + Variable *var = FindVariableInScope(sym_ctx, name, type, ast_context); + + if (!var) + { + err.SetErrorStringWithFormat("Couldn't find %s with appropriate type", name); + return false; + } + + log->Printf("Materializing %s with type %p", name, type); + std::auto_ptr location_value(GetVariableValue(exe_ctx, + var, + ast_context)); + + if (!location_value.get()) + { + err.SetErrorStringWithFormat("Couldn't get value for %s", name); + return false; + } + + if (location_value->GetValueType() == Value::eValueTypeLoadAddress) + { + lldb::addr_t src_addr = location_value->GetScalar().ULongLong(); + + size_t bit_size = ClangASTContext::GetTypeBitSize(ast_context, type); + size_t byte_size = bit_size % 8 ? ((bit_size + 8) / 8) : (bit_size / 8); + + DataBufferHeap data; + data.SetByteSize(byte_size); + + Error error; + if (exe_ctx.process->ReadMemory (src_addr, data.GetBytes(), byte_size, error) != byte_size) + { + err.SetErrorStringWithFormat ("Couldn't read a composite type from the target: %s", error.AsCString()); + return false; + } + + if (exe_ctx.process->WriteMemory (addr, data.GetBytes(), byte_size, error) != byte_size) + { + err.SetErrorStringWithFormat ("Couldn't write a composite type to the target: %s", error.AsCString()); + return false; + } + + if (log) + log->Printf("Copied from 0x%llx to 0x%llx", (uint64_t)src_addr, (uint64_t)addr); + } + else + { + StreamString ss; + + location_value->Dump(&ss); + + err.SetErrorStringWithFormat("%s has a value of unhandled type: %s", name, ss.GetString().c_str()); } return true; @@ -335,76 +459,33 @@ return; Function *function = m_sym_ctx->function; - Block *block = m_sym_ctx->block; - if (!function || !block) + if (!function) { if (log) - log->Printf("function = %p, block = %p", function, block); + log->Printf("Can't evaluate an expression when not in a function"); return; } - BlockList& blocks = function->GetBlocks(true); - - lldb::user_id_t current_block_id = block->GetID(); - ConstString name_cs(name); Function *fn = m_sym_ctx->FindFunctionByName(name_cs.GetCString()); if (fn) - { AddOneFunction(context, fn); - } - - for (current_block_id = block->GetID(); - current_block_id != Block::InvalidID; - current_block_id = blocks.GetParent(current_block_id)) - { - Block *current_block = blocks.GetBlockByID(current_block_id); - - lldb::VariableListSP var_list = current_block->GetVariableList(false, true); - - if (!var_list) - continue; - - lldb::VariableSP var = var_list->FindVariable(name_cs); - - if (!var) - continue; - - AddOneVariable(context, var.get()); - return; - } + + Variable *var = FindVariableInScope(*m_sym_ctx, name); - { - CompileUnit *compile_unit = m_sym_ctx->comp_unit; - - if (!compile_unit) - { - if (log) - log->Printf("compile_unit = %p", compile_unit); - return; - } - - lldb::VariableListSP var_list = compile_unit->GetVariableList(true); - - if (!var_list) - return; - - lldb::VariableSP var = var_list->FindVariable(name_cs); - - if (!var) - return; - - AddOneVariable(context, var.get()); - return; - } + if (var) + AddOneVariable(context, var); } - -void -ClangExpressionDeclMap::AddOneVariable(NameSearchContext &context, - Variable* var) + +Value * +ClangExpressionDeclMap::GetVariableValue(ExecutionContext &exe_ctx, + Variable *var, + clang::ASTContext *target_ast_context, + void **opaque_type, + clang::ASTContext **found_ast_context) { Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS); @@ -414,7 +495,7 @@ { if (log) log->PutCString("Skipped a definition because it has no type"); - return; + return NULL; } void *var_opaque_type = var_type->GetOpaqueClangQualType(); @@ -423,18 +504,16 @@ { if (log) log->PutCString("Skipped a definition because it has no Clang type"); - return; + return NULL; } - DWARFExpression &var_location_expr = var->LocationExpression(); - TypeList *type_list = var_type->GetTypeList(); if (!type_list) { if (log) log->PutCString("Skipped a definition because the type has no associated type list"); - return; + return NULL; } clang::ASTContext *exe_ast_ctx = type_list->GetClangASTContext().getASTContext(); @@ -443,40 +522,47 @@ { if (log) log->PutCString("There is no AST context for the current execution context"); - return; + return NULL; } + DWARFExpression &var_location_expr = var->LocationExpression(); + std::auto_ptr var_location(new Value); Error err; - if (!var_location_expr.Evaluate(m_exe_ctx, exe_ast_ctx, NULL, *var_location.get(), &err)) + if (!var_location_expr.Evaluate(&exe_ctx, exe_ast_ctx, NULL, *var_location.get(), &err)) { if (log) log->Printf("Error evaluating location: %s", err.AsCString()); - return; + return NULL; } clang::ASTContext *var_ast_context = type_list->GetClangASTContext().getASTContext(); - void *copied_type = ClangASTContext::CopyType(context.GetASTContext(), var_ast_context, var_opaque_type); + void *type_to_use; + + if (target_ast_context) + type_to_use = ClangASTContext::CopyType(target_ast_context, var_ast_context, var_opaque_type); + else + type_to_use = var_opaque_type; if (var_location.get()->GetContextType() == Value::eContextTypeInvalid) - var_location.get()->SetContext(Value::eContextTypeOpaqueClangQualType, copied_type); + var_location.get()->SetContext(Value::eContextTypeOpaqueClangQualType, type_to_use); if (var_location.get()->GetValueType() == Value::eValueTypeFileAddress) { SymbolContext var_sc; var->CalculateSymbolContext(&var_sc); - + if (!var_sc.module_sp) - return; + return NULL; ObjectFile *object_file = var_sc.module_sp->GetObjectFile(); if (!object_file) - return; - + return NULL; + Address so_addr(var_location->GetScalar().ULongLong(), object_file->GetSectionList()); lldb::addr_t load_addr = so_addr.GetLoadAddress(m_exe_ctx->process); @@ -485,12 +571,36 @@ var_location->SetValueType(Value::eValueTypeLoadAddress); } - NamedDecl *var_decl = context.AddVarDecl(copied_type); + if (opaque_type) + *opaque_type = var_opaque_type; + + if (found_ast_context) + *found_ast_context = var_ast_context; + + return var_location.release(); +} + +void +ClangExpressionDeclMap::AddOneVariable(NameSearchContext &context, + Variable* var) +{ + Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS); + + void *var_opaque_type = NULL; + clang::ASTContext *var_ast_context = NULL; + + Value *var_location = GetVariableValue(*m_exe_ctx, + var, + context.GetASTContext(), + &var_opaque_type, + &var_ast_context); + + NamedDecl *var_decl = context.AddVarDecl(var_opaque_type); Tuple tuple; tuple.m_decl = var_decl; - tuple.m_value = var_location.release(); + tuple.m_value = var_location; tuple.m_orig_type = var_opaque_type; tuple.m_ast_context = var_ast_context; From jingham at apple.com Fri Jul 16 19:53:23 2010 From: jingham at apple.com (Jim Ingham) Date: Fri, 16 Jul 2010 17:53:23 -0700 Subject: [Lldb-commits] [PATCH] Use break_id_t instead of user_id_t In-Reply-To: References: Message-ID: <574884B4-8C31-48F6-8F07-3E725052141F@apple.com> Yup, thanks. Jim On Jul 16, 2010, at 5:43 PM, Stephen Wilson wrote: > Hi all, > > This patch changes Process::CreateBreakpointSite to return a break_id_t > instead of a user_id_t. Also, update ResolveBreakpointSite to check > for invalid breakpoint ID's using the proper magic constant. > > OK to apply? > > Take care, > Steve > > > _______________________________________________ > lldb-commits mailing list > lldb-commits at cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/lldb-commits From wilsons at start.ca Fri Jul 16 19:56:13 2010 From: wilsons at start.ca (Stephen Wilson) Date: Sat, 17 Jul 2010 00:56:13 -0000 Subject: [Lldb-commits] [lldb] r108598 - in /lldb/trunk: include/lldb/Target/Process.h source/Breakpoint/BreakpointLocation.cpp source/Target/Process.cpp Message-ID: <20100717005613.627612A6C12C@llvm.org> Author: wilsons Date: Fri Jul 16 19:56:13 2010 New Revision: 108598 URL: http://llvm.org/viewvc/llvm-project?rev=108598&view=rev Log: Have Process::CreateBreakpointSite return a break_id_t instead of a user_id_t. Also, update BreakpointLocation::ResolveBreakpointSite to check for invalid breakpoint ID's using the proper magic constant. Modified: lldb/trunk/include/lldb/Target/Process.h lldb/trunk/source/Breakpoint/BreakpointLocation.cpp lldb/trunk/source/Target/Process.cpp Modified: lldb/trunk/include/lldb/Target/Process.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/Process.h?rev=108598&r1=108597&r2=108598&view=diff ============================================================================== --- lldb/trunk/include/lldb/Target/Process.h (original) +++ lldb/trunk/include/lldb/Target/Process.h Fri Jul 16 19:56:13 2010 @@ -1170,7 +1170,7 @@ Error ClearBreakpointSiteByID (lldb::user_id_t break_id); - lldb::user_id_t + lldb::break_id_t CreateBreakpointSite (lldb::BreakpointLocationSP &owner, bool use_hardware); Modified: lldb/trunk/source/Breakpoint/BreakpointLocation.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Breakpoint/BreakpointLocation.cpp?rev=108598&r1=108597&r2=108598&view=diff ============================================================================== --- lldb/trunk/source/Breakpoint/BreakpointLocation.cpp (original) +++ lldb/trunk/source/Breakpoint/BreakpointLocation.cpp Fri Jul 16 19:56:13 2010 @@ -229,9 +229,9 @@ BreakpointLocationSP myself_sp(m_owner.GetLocationSP (this)); - lldb::user_id_t new_id = process->CreateBreakpointSite (myself_sp, false); + lldb::break_id_t new_id = process->CreateBreakpointSite (myself_sp, false); - if (new_id == LLDB_INVALID_UID) + if (new_id == LLDB_INVALID_BREAK_ID) { Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS); if (log) Modified: lldb/trunk/source/Target/Process.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Process.cpp?rev=108598&r1=108597&r2=108598&view=diff ============================================================================== --- lldb/trunk/source/Target/Process.cpp (original) +++ lldb/trunk/source/Target/Process.cpp Fri Jul 16 19:56:13 2010 @@ -522,7 +522,7 @@ return error; } -lldb::user_id_t +lldb::break_id_t Process::CreateBreakpointSite (BreakpointLocationSP &owner, bool use_hardware) { const addr_t load_addr = owner->GetAddress().GetLoadAddress (this);