From johnny.chen at apple.com Mon Jun 28 15:55:57 2010 From: johnny.chen at apple.com (Johnny Chen) Date: Mon, 28 Jun 2010 20:55:57 -0000 Subject: [Lldb-commits] [lldb] r107066 - /lldb/trunk/test/help/TestHelp.py Message-ID: <20100628205557.E92A32A6C12C@llvm.org> Author: johnny Date: Mon Jun 28 15:55:57 2010 New Revision: 107066 URL: http://llvm.org/viewvc/llvm-project?rev=107066&view=rev Log: Added test for a previously fixed bug where invoking lldb command from an emacs shell and issuing 'help' would hang (was actually infinitely looping). Modified: lldb/trunk/test/help/TestHelp.py Modified: lldb/trunk/test/help/TestHelp.py URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/help/TestHelp.py?rev=107066&r1=107065&r2=107066&view=diff ============================================================================== --- lldb/trunk/test/help/TestHelp.py (original) +++ lldb/trunk/test/help/TestHelp.py Mon Jun 28 15:55:57 2010 @@ -18,7 +18,18 @@ def test_simplehelp(self): """A simple test of 'help' command and its output.""" res = lldb.SBCommandReturnObject() - self.ci.HandleCommand("help", res, False) + self.ci.HandleCommand("help", res) + self.assertTrue(res.Succeeded()) + self.assertTrue(res.GetOutput().startswith( + 'The following is a list of built-in, permanent debugger commands')) + #print res.GetOutput() + + def test_help_should_not_hang_emacsshell(self): + """'set term-width 0' should not hang the help command.""" + res = lldb.SBCommandReturnObject() + self.ci.HandleCommand("set term-width 0", res) + self.assertTrue(res.Succeeded()) + self.ci.HandleCommand("help", res) self.assertTrue(res.Succeeded()) self.assertTrue(res.GetOutput().startswith( 'The following is a list of built-in, permanent debugger commands')) From gclayton at apple.com Mon Jun 28 16:30:43 2010 From: gclayton at apple.com (Greg Clayton) Date: Mon, 28 Jun 2010 21:30:43 -0000 Subject: [Lldb-commits] [lldb] r107075 - in /lldb/trunk: include/lldb/ include/lldb/Breakpoint/ include/lldb/Core/ include/lldb/Symbol/ include/lldb/Target/ lldb.xcodeproj/ source/Breakpoint/ source/Commands/ source/Core/ source/Plugins/SymbolFile/DWARF/ source/Plugins/SymbolFile/Symtab/ source/Symbol/ source/Target/ tools/driver/ Message-ID: <20100628213043.E54EC2A6C12C@llvm.org> Author: gclayton Date: Mon Jun 28 16:30:43 2010 New Revision: 107075 URL: http://llvm.org/viewvc/llvm-project?rev=107075&view=rev Log: Added function name types to allow us to set breakpoints by name more intelligently. The four name types we currently have are: eFunctionNameTypeFull = (1 << 1), // The function name. // For C this is the same as just the name of the function // For C++ this is the demangled version of the mangled name. // For ObjC this is the full function signature with the + or // - and the square brackets and the class and selector eFunctionNameTypeBase = (1 << 2), // The function name only, no namespaces or arguments and no class // methods or selectors will be searched. eFunctionNameTypeMethod = (1 << 3), // Find function by method name (C++) with no namespace or arguments eFunctionNameTypeSelector = (1 << 4) // Find function by selector name (ObjC) names this allows much more flexibility when setting breakoints: (lldb) breakpoint set --name main --basename (lldb) breakpoint set --name main --fullname (lldb) breakpoint set --name main --method (lldb) breakpoint set --name main --selector The default: (lldb) breakpoint set --name main will inspect the name "main" and look for any parens, or if the name starts with "-[" or "+[" and if any are found then a full name search will happen. Else a basename search will be the default. Fixed some command option structures so not all options are required when they shouldn't be. Cleaned up the breakpoint output summary. Made the "image lookup --address " output much more verbose so it shows all the important symbol context results. Added a GetDescription method to many of the SymbolContext objects for the more verbose output. Modified: lldb/trunk/include/lldb/Breakpoint/BreakpointResolverName.h lldb/trunk/include/lldb/Core/Module.h lldb/trunk/include/lldb/Core/ModuleList.h lldb/trunk/include/lldb/Core/VMRange.h lldb/trunk/include/lldb/Symbol/Block.h lldb/trunk/include/lldb/Symbol/CompileUnit.h lldb/trunk/include/lldb/Symbol/Function.h lldb/trunk/include/lldb/Symbol/LineEntry.h lldb/trunk/include/lldb/Symbol/Symbol.h lldb/trunk/include/lldb/Symbol/SymbolContext.h lldb/trunk/include/lldb/Symbol/SymbolFile.h lldb/trunk/include/lldb/Symbol/SymbolVendor.h lldb/trunk/include/lldb/Symbol/Type.h lldb/trunk/include/lldb/Target/Target.h lldb/trunk/include/lldb/lldb-enumerations.h lldb/trunk/lldb.xcodeproj/project.pbxproj lldb/trunk/source/Breakpoint/Breakpoint.cpp lldb/trunk/source/Breakpoint/BreakpointOptions.cpp lldb/trunk/source/Breakpoint/BreakpointResolverAddress.cpp lldb/trunk/source/Breakpoint/BreakpointResolverFileLine.cpp lldb/trunk/source/Breakpoint/BreakpointResolverName.cpp lldb/trunk/source/Commands/CommandObjectBreakpoint.cpp lldb/trunk/source/Commands/CommandObjectBreakpoint.h lldb/trunk/source/Commands/CommandObjectCall.cpp lldb/trunk/source/Commands/CommandObjectDisassemble.cpp lldb/trunk/source/Commands/CommandObjectExpression.cpp lldb/trunk/source/Commands/CommandObjectImage.cpp lldb/trunk/source/Commands/CommandObjectThread.cpp lldb/trunk/source/Core/Address.cpp lldb/trunk/source/Core/AddressResolverName.cpp lldb/trunk/source/Core/Module.cpp lldb/trunk/source/Core/ModuleList.cpp lldb/trunk/source/Core/SearchFilter.cpp lldb/trunk/source/Core/VMRange.cpp lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.h lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h lldb/trunk/source/Plugins/SymbolFile/Symtab/SymbolFileSymtab.cpp lldb/trunk/source/Plugins/SymbolFile/Symtab/SymbolFileSymtab.h lldb/trunk/source/Symbol/Block.cpp lldb/trunk/source/Symbol/CompileUnit.cpp lldb/trunk/source/Symbol/Declaration.cpp lldb/trunk/source/Symbol/Function.cpp lldb/trunk/source/Symbol/LineEntry.cpp lldb/trunk/source/Symbol/LineTable.cpp lldb/trunk/source/Symbol/Symbol.cpp lldb/trunk/source/Symbol/SymbolContext.cpp lldb/trunk/source/Symbol/SymbolVendor.cpp lldb/trunk/source/Symbol/Type.cpp lldb/trunk/source/Target/Target.cpp lldb/trunk/tools/driver/Driver.cpp Modified: lldb/trunk/include/lldb/Breakpoint/BreakpointResolverName.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Breakpoint/BreakpointResolverName.h?rev=107075&r1=107074&r2=107075&view=diff ============================================================================== --- lldb/trunk/include/lldb/Breakpoint/BreakpointResolverName.h (original) +++ lldb/trunk/include/lldb/Breakpoint/BreakpointResolverName.h Mon Jun 28 16:30:43 2010 @@ -30,17 +30,18 @@ public: BreakpointResolverName (Breakpoint *bkpt, - const char *func_name, - Breakpoint::MatchType type = Breakpoint::Exact); + const char *name, + uint32_t name_type_mask, + Breakpoint::MatchType type); // Creates a function breakpoint by regular expression. Takes over control of the lifespan of func_regex. BreakpointResolverName (Breakpoint *bkpt, - RegularExpression &func_regex); + RegularExpression &func_regex); BreakpointResolverName (Breakpoint *bkpt, - const char *class_name, - const char *method, - Breakpoint::MatchType type); + const char *class_name, + const char *method, + Breakpoint::MatchType type); virtual ~BreakpointResolverName (); @@ -62,6 +63,7 @@ protected: ConstString m_func_name; + uint32_t m_func_name_type_mask; // See FunctionNameType ConstString m_class_name; // FIXME: Not used yet. The idea would be to stop on methods of this class. RegularExpression m_regex; Breakpoint::MatchType m_match_type; Modified: lldb/trunk/include/lldb/Core/Module.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/Module.h?rev=107075&r1=107074&r2=107075&view=diff ============================================================================== --- lldb/trunk/include/lldb/Core/Module.h (original) +++ lldb/trunk/include/lldb/Core/Module.h Mon Jun 28 16:30:43 2010 @@ -157,6 +157,12 @@ /// @param[in] name /// The name of the function we are looking for. /// + /// @param[in] name_type_mask + /// A bit mask of bits that indicate what kind of names should + /// be used when doing the lookup. Bits include fully qualified + /// names, base names, C++ methods, or ObjC selectors. + /// See FunctionNameType for more details. + /// /// @param[in] append /// If \b true, any matches will be appended to \a /// variable_list, else matches replace the contents of @@ -170,7 +176,7 @@ /// The number of matches added to \a sc_list. //------------------------------------------------------------------ uint32_t - FindFunctions (const ConstString &name, bool append, SymbolContextList& sc_list); + FindFunctions (const ConstString &name, uint32_t name_type_mask, bool append, SymbolContextList& sc_list); //------------------------------------------------------------------ /// Find functions by name. Modified: lldb/trunk/include/lldb/Core/ModuleList.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/ModuleList.h?rev=107075&r1=107074&r2=107075&view=diff ============================================================================== --- lldb/trunk/include/lldb/Core/ModuleList.h (original) +++ lldb/trunk/include/lldb/Core/ModuleList.h Mon Jun 28 16:30:43 2010 @@ -144,6 +144,12 @@ /// @param[in] name /// The name of the function we are looking for. /// + /// @param[in] name_type_mask + /// A bit mask of bits that indicate what kind of names should + /// be used when doing the lookup. Bits include fully qualified + /// names, base names, C++ methods, or ObjC selectors. + /// See FunctionNameType for more details. + /// /// @param[out] sc_list /// A symbol context list that gets filled in with all of the /// matches. @@ -153,6 +159,7 @@ //------------------------------------------------------------------ size_t FindFunctions (const ConstString &name, + uint32_t name_type_mask, SymbolContextList &sc_list); //------------------------------------------------------------------ Modified: lldb/trunk/include/lldb/Core/VMRange.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/VMRange.h?rev=107075&r1=107074&r2=107075&view=diff ============================================================================== --- lldb/trunk/include/lldb/Core/VMRange.h (original) +++ lldb/trunk/include/lldb/Core/VMRange.h Mon Jun 28 16:30:43 2010 @@ -112,7 +112,7 @@ } void - Dump(Stream *s, lldb::addr_t base_addr = 0) const; + Dump (Stream *s, lldb::addr_t base_addr = 0, uint32_t addr_width = 8) const; class ValueInRangeUnaryPredicate { Modified: lldb/trunk/include/lldb/Symbol/Block.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Symbol/Block.h?rev=107075&r1=107074&r2=107075&view=diff ============================================================================== --- lldb/trunk/include/lldb/Symbol/Block.h (original) +++ lldb/trunk/include/lldb/Symbol/Block.h Mon Jun 28 16:30:43 2010 @@ -213,6 +213,11 @@ virtual void DumpSymbolContext(Stream *s); + void + GetDescription (Stream *s, + lldb::DescriptionLevel level, + Process *process) const; + //------------------------------------------------------------------ /// Get the parent block's UID. /// @@ -243,6 +248,37 @@ lldb::user_id_t GetFirstChildUID () const; + + //------------------------------------------------------------------ + /// Get the parent block. + /// + /// @return + /// The parent block pointer, or NULL if this block has no + /// parent. + //------------------------------------------------------------------ + Block * + GetParent () const; + + //------------------------------------------------------------------ + /// Get the sibling block. + /// + /// @return + /// The sibling block pointer, or NULL if this block has no + /// sibling. + //------------------------------------------------------------------ + Block * + GetSibling () const; + + //------------------------------------------------------------------ + /// Get the first child block. + /// + /// @return + /// The first child block pointer, or NULL if this block has no + /// children. + //------------------------------------------------------------------ + Block * + GetFirstChild () const; + //------------------------------------------------------------------ /// Get the variable list for this block and optionally all child /// blocks if \a get_child_variables is \b true. Modified: lldb/trunk/include/lldb/Symbol/CompileUnit.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Symbol/CompileUnit.h?rev=107075&r1=107074&r2=107075&view=diff ============================================================================== --- lldb/trunk/include/lldb/Symbol/CompileUnit.h (original) +++ lldb/trunk/include/lldb/Symbol/CompileUnit.h Mon Jun 28 16:30:43 2010 @@ -135,6 +135,10 @@ virtual void DumpSymbolContext(Stream *s); + + void + GetDescription(Stream *s, lldb::DescriptionLevel level) const; + //------------------------------------------------------------------ /// Get a shared pointer to a function in this compile unit by /// index. Modified: lldb/trunk/include/lldb/Symbol/Function.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Symbol/Function.h?rev=107075&r1=107074&r2=107075&view=diff ============================================================================== --- lldb/trunk/include/lldb/Symbol/Function.h (original) +++ lldb/trunk/include/lldb/Symbol/Function.h Mon Jun 28 16:30:43 2010 @@ -451,6 +451,9 @@ const CompileUnit* GetCompileUnit() const; + void + GetDescription(Stream *s, lldb::DescriptionLevel level, Process *process); + //------------------------------------------------------------------ /// Get accessor for the frame base location. /// Modified: lldb/trunk/include/lldb/Symbol/LineEntry.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Symbol/LineEntry.h?rev=107075&r1=107074&r2=107075&view=diff ============================================================================== --- lldb/trunk/include/lldb/Symbol/LineEntry.h (original) +++ lldb/trunk/include/lldb/Symbol/LineEntry.h Mon Jun 28 16:30:43 2010 @@ -87,8 +87,12 @@ Dump (Stream *s, Process *process, bool show_file, Address::DumpStyle style, Address::DumpStyle fallback_style, bool show_range) const; bool - GetDescription (Stream *s, lldb::DescriptionLevel level, CompileUnit* cu, Process *process) const; - + GetDescription (Stream *s, + lldb::DescriptionLevel level, + CompileUnit* cu, + Process *process, + bool show_address_only) const; + //------------------------------------------------------------------ /// Dumps information specific to a process that stops at this /// line entry to the supplied stream \a s. Modified: lldb/trunk/include/lldb/Symbol/Symbol.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Symbol/Symbol.h?rev=107075&r1=107074&r2=107075&view=diff ============================================================================== --- lldb/trunk/include/lldb/Symbol/Symbol.h (original) +++ lldb/trunk/include/lldb/Symbol/Symbol.h Mon Jun 28 16:30:43 2010 @@ -106,6 +106,9 @@ void SetFlags (uint32_t flags) { m_flags = flags; } + void + GetDescription (Stream *s, lldb::DescriptionLevel level, Process *process) const; + Function * GetFunction (); Modified: lldb/trunk/include/lldb/Symbol/SymbolContext.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Symbol/SymbolContext.h?rev=107075&r1=107074&r2=107075&view=diff ============================================================================== --- lldb/trunk/include/lldb/Symbol/SymbolContext.h (original) +++ lldb/trunk/include/lldb/Symbol/SymbolContext.h Mon Jun 28 16:30:43 2010 @@ -184,6 +184,12 @@ bool GetAddressRange (uint32_t scope, AddressRange &range) const; + + void + GetDescription(Stream *s, + lldb::DescriptionLevel level, + Process *process) const; + //------------------------------------------------------------------ /// Find a function matching the given name, working out from this /// symbol context. Modified: lldb/trunk/include/lldb/Symbol/SymbolFile.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Symbol/SymbolFile.h?rev=107075&r1=107074&r2=107075&view=diff ============================================================================== --- lldb/trunk/include/lldb/Symbol/SymbolFile.h (original) +++ lldb/trunk/include/lldb/Symbol/SymbolFile.h Mon Jun 28 16:30:43 2010 @@ -75,7 +75,7 @@ virtual uint32_t ResolveSymbolContext (const FileSpec& file_spec, uint32_t line, bool check_inlines, uint32_t resolve_scope, SymbolContextList& sc_list) = 0; virtual uint32_t FindGlobalVariables (const ConstString &name, bool append, uint32_t max_matches, VariableList& variables) = 0; virtual uint32_t FindGlobalVariables (const RegularExpression& regex, bool append, uint32_t max_matches, VariableList& variables) = 0; - virtual uint32_t FindFunctions (const ConstString &name, bool append, SymbolContextList& sc_list) = 0; + virtual uint32_t FindFunctions (const ConstString &name, uint32_t name_type_mask, bool append, SymbolContextList& sc_list) = 0; virtual uint32_t FindFunctions (const RegularExpression& regex, bool append, SymbolContextList& sc_list) = 0; // virtual uint32_t FindTypes (const SymbolContext& sc, const ConstString &name, bool append, uint32_t max_matches, Type::Encoding encoding, lldb::user_id_t udt_uid, TypeList& types) = 0; // virtual uint32_t FindTypes (const SymbolContext& sc, const RegularExpression& regex, bool append, uint32_t max_matches, Type::Encoding encoding, lldb::user_id_t udt_uid, TypeList& types) = 0; Modified: lldb/trunk/include/lldb/Symbol/SymbolVendor.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Symbol/SymbolVendor.h?rev=107075&r1=107074&r2=107075&view=diff ============================================================================== --- lldb/trunk/include/lldb/Symbol/SymbolVendor.h (original) +++ lldb/trunk/include/lldb/Symbol/SymbolVendor.h Mon Jun 28 16:30:43 2010 @@ -110,6 +110,7 @@ virtual uint32_t FindFunctions(const ConstString &name, + uint32_t name_type_mask, bool append, SymbolContextList& sc_list); Modified: lldb/trunk/include/lldb/Symbol/Type.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Symbol/Type.h?rev=107075&r1=107074&r2=107075&view=diff ============================================================================== --- lldb/trunk/include/lldb/Symbol/Type.h (original) +++ lldb/trunk/include/lldb/Symbol/Type.h Mon Jun 28 16:30:43 2010 @@ -58,6 +58,10 @@ void DumpTypeName(Stream *s); + + void + GetDescription (Stream *s, lldb::DescriptionLevel level, bool show_name); + SymbolFile * GetSymbolFile() { Modified: lldb/trunk/include/lldb/Target/Target.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/Target.h?rev=107075&r1=107074&r2=107075&view=diff ============================================================================== --- lldb/trunk/include/lldb/Target/Target.h (original) +++ lldb/trunk/include/lldb/Target/Target.h Mon Jun 28 16:30:43 2010 @@ -138,6 +138,7 @@ lldb::BreakpointSP CreateBreakpoint (FileSpec *containingModule, const char *func_name, + uint32_t func_name_type_mask, bool internal = false); // Use this to create a general breakpoint: Modified: lldb/trunk/include/lldb/lldb-enumerations.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/lldb-enumerations.h?rev=107075&r1=107074&r2=107075&view=diff ============================================================================== --- lldb/trunk/include/lldb/lldb-enumerations.h (original) +++ lldb/trunk/include/lldb/lldb-enumerations.h Mon Jun 28 16:30:43 2010 @@ -390,6 +390,20 @@ kNumArchTypes } ArchitectureType; +typedef enum FunctionNameType +{ + eFunctionNameTypeNone = 0, + eFunctionNameTypeFull = (1 << 1), // The function name. + // For C this is the same as just the name of the function + // For C++ this is the demangled version of the mangled name. + // For ObjC this is the full function signature with the + or + // - and the square brackets and the class and selector + eFunctionNameTypeBase = (1 << 2), // The function name only, no namespaces or arguments and no class + // methods or selectors will be searched. + eFunctionNameTypeMethod = (1 << 3), // Find function by method name (C++) with no namespace or arguments + eFunctionNameTypeSelector = (1 << 4) // Find function by selector name (ObjC) names +} FunctionNameType; + } // namespace lldb Modified: lldb/trunk/lldb.xcodeproj/project.pbxproj URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/lldb.xcodeproj/project.pbxproj?rev=107075&r1=107074&r2=107075&view=diff ============================================================================== --- lldb/trunk/lldb.xcodeproj/project.pbxproj (original) +++ lldb/trunk/lldb.xcodeproj/project.pbxproj Mon Jun 28 16:30:43 2010 @@ -1621,6 +1621,8 @@ 26BC7E9310F1B85900F91463 /* StreamString.cpp */, 9A35765E116E76A700E8ED2F /* StringList.h */, 9A35765F116E76B900E8ED2F /* StringList.cpp */, + 26B167A41123BF5500DC7B4F /* ThreadSafeValue.h */, + 263FEDA5112CC1DA00E4C208 /* ThreadSafeSTLMap.h */, 26BC7D7E10F1B77400F91463 /* Timer.h */, 26BC7E9610F1B85900F91463 /* Timer.cpp */, 26BC7D7F10F1B77400F91463 /* TTYState.h */, @@ -1628,6 +1630,8 @@ 268A813F115B19D000F645B0 /* UniqueCStringMap.h */, 26BC7D8010F1B77400F91463 /* UserID.h */, 26BC7E9810F1B85900F91463 /* UserID.cpp */, + 26C81CA411335651004BDC5A /* UUID.h */, + 26C81CA511335651004BDC5A /* UUID.cpp */, 26BC7D8110F1B77400F91463 /* Value.h */, 26BC7E9910F1B85900F91463 /* Value.cpp */, 26BC7D8210F1B77400F91463 /* ValueObject.h */, @@ -1642,10 +1646,6 @@ 26BC7E9D10F1B85900F91463 /* ValueObjectVariable.cpp */, 26BC7D8610F1B77400F91463 /* VMRange.h */, 26BC7E9E10F1B85900F91463 /* VMRange.cpp */, - 26B167A41123BF5500DC7B4F /* ThreadSafeValue.h */, - 263FEDA5112CC1DA00E4C208 /* ThreadSafeSTLMap.h */, - 26C81CA411335651004BDC5A /* UUID.h */, - 26C81CA511335651004BDC5A /* UUID.cpp */, ); name = Core; sourceTree = ""; Modified: lldb/trunk/source/Breakpoint/Breakpoint.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Breakpoint/Breakpoint.cpp?rev=107075&r1=107074&r2=107075&view=diff ============================================================================== --- lldb/trunk/source/Breakpoint/Breakpoint.cpp (original) +++ lldb/trunk/source/Breakpoint/Breakpoint.cpp Mon Jun 28 16:30:43 2010 @@ -349,17 +349,9 @@ Breakpoint::GetDescription (Stream *s, lldb::DescriptionLevel level, bool show_locations) { assert (s != NULL); - StreamString filter_strm; - - - s->Printf("%i ", GetID()); + s->Printf("%i: ", GetID()); GetResolverDescription (s); - GetFilterDescription (&filter_strm); - if (filter_strm.GetString().compare ("No Filter") != 0) - { - s->Printf (", "); - GetFilterDescription (s); - } + GetFilterDescription (s); const uint32_t num_locations = GetNumLocations (); const uint32_t num_resolved_locations = GetNumResolvedLocations (); @@ -370,14 +362,13 @@ case lldb::eDescriptionLevelFull: if (num_locations > 0) { - s->Printf(" with %u location%s", num_locations, num_locations > 1 ? "s" : ""); + s->Printf(", locations = %u", num_locations); if (num_resolved_locations > 0) - s->Printf(" (%u resolved)", num_resolved_locations); - s->PutChar(';'); + s->Printf(", resolved = %u", num_resolved_locations); } else { - s->Printf(" with 0 locations (Pending Breakpoint)."); + s->Printf(", locations = 0 (pending)"); } GetOptions()->GetDescription(s, level); @@ -400,7 +391,6 @@ if (show_locations) { - s->EOL(); s->IndentMore(); for (int i = 0; i < GetNumLocations(); ++i) { @@ -409,7 +399,6 @@ s->EOL(); } s->IndentLess(); - } } Modified: lldb/trunk/source/Breakpoint/BreakpointOptions.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Breakpoint/BreakpointOptions.cpp?rev=107075&r1=107074&r2=107075&view=diff ============================================================================== --- lldb/trunk/source/Breakpoint/BreakpointOptions.cpp (original) +++ lldb/trunk/source/Breakpoint/BreakpointOptions.cpp Mon Jun 28 16:30:43 2010 @@ -234,10 +234,7 @@ if (level != eDescriptionLevelBrief) s->EOL(); m_callback_baton_sp->GetDescription (s, level); - } - else if (level == eDescriptionLevelBrief) - s->PutCString ("commands: no "); - + } } void @@ -247,10 +244,7 @@ if (level == eDescriptionLevelBrief) { - if (data && data->user_source.GetSize() > 0) - s->PutCString("commands: yes "); - else - s->PutCString("commands: no "); + s->Printf (", commands = %s", (data && data->user_source.GetSize() > 0) ? "yes" : "no"); return; } Modified: lldb/trunk/source/Breakpoint/BreakpointResolverAddress.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Breakpoint/BreakpointResolverAddress.cpp?rev=107075&r1=107074&r2=107075&view=diff ============================================================================== --- lldb/trunk/source/Breakpoint/BreakpointResolverAddress.cpp (original) +++ lldb/trunk/source/Breakpoint/BreakpointResolverAddress.cpp Mon Jun 28 16:30:43 2010 @@ -100,7 +100,7 @@ void BreakpointResolverAddress::GetDescription (Stream *s) { - s->PutCString ("Address breakpoint: "); + s->PutCString ("address = "); m_addr.Dump(s, m_breakpoint->GetTarget().GetProcessSP().get(), Address::DumpStyleLoadAddress, Address::DumpStyleModuleWithFileAddress); } Modified: lldb/trunk/source/Breakpoint/BreakpointResolverFileLine.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Breakpoint/BreakpointResolverFileLine.cpp?rev=107075&r1=107074&r2=107075&view=diff ============================================================================== --- lldb/trunk/source/Breakpoint/BreakpointResolverFileLine.cpp (original) +++ lldb/trunk/source/Breakpoint/BreakpointResolverFileLine.cpp Mon Jun 28 16:30:43 2010 @@ -111,7 +111,7 @@ void BreakpointResolverFileLine::GetDescription (Stream *s) { - s->Printf ("File and line breakpoint - file: \"%s\" line: %u", m_file_spec.GetFilename().AsCString(), m_line_number); + s->Printf ("file ='%s', line = %u", m_file_spec.GetFilename().AsCString(), m_line_number); } void Modified: lldb/trunk/source/Breakpoint/BreakpointResolverName.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Breakpoint/BreakpointResolverName.cpp?rev=107075&r1=107074&r2=107075&view=diff ============================================================================== --- lldb/trunk/source/Breakpoint/BreakpointResolverName.cpp (original) +++ lldb/trunk/source/Breakpoint/BreakpointResolverName.cpp Mon Jun 28 16:30:43 2010 @@ -25,11 +25,13 @@ ( Breakpoint *bkpt, const char *func_name, + uint32_t func_name_type_mask, Breakpoint::MatchType type ) : BreakpointResolver (bkpt), m_func_name (func_name), - m_class_name (NULL), + m_func_name_type_mask (func_name_type_mask), + m_class_name (), m_regex (), m_match_type (type) { @@ -94,45 +96,47 @@ { SymbolContextList func_list; SymbolContextList sym_list; - + bool skip_prologue = true; uint32_t i; bool new_location; SymbolContext sc; Address break_addr; assert (m_breakpoint != NULL); - + Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS); - + if (m_class_name) { if (log) log->Warning ("Class/method function specification not supported yet.\n"); return Searcher::eCallbackReturnStop; } - + switch (m_match_type) { - case Breakpoint::Exact: - if (context.module_sp) - { - context.module_sp->FindSymbolsWithNameAndType (m_func_name, eSymbolTypeCode, sym_list); - context.module_sp->FindFunctions (m_func_name, false, func_list); - } - break; - case Breakpoint::Regexp: - if (context.module_sp) - { - context.module_sp->FindSymbolsMatchingRegExAndType (m_regex, eSymbolTypeCode, sym_list); - context.module_sp->FindFunctions (m_regex, true, func_list); - } - break; - case Breakpoint::Glob: - if (log) - log->Warning ("glob is not supported yet."); - break; + case Breakpoint::Exact: + if (context.module_sp) + { + if (m_func_name_type_mask & (eFunctionNameTypeBase | eFunctionNameTypeFull)) + context.module_sp->FindSymbolsWithNameAndType (m_func_name, eSymbolTypeCode, sym_list); + context.module_sp->FindFunctions (m_func_name, m_func_name_type_mask, false, func_list); + } + break; + case Breakpoint::Regexp: + if (context.module_sp) + { + if (m_func_name_type_mask & (eFunctionNameTypeBase | eFunctionNameTypeFull)) + context.module_sp->FindSymbolsMatchingRegExAndType (m_regex, eSymbolTypeCode, sym_list); + context.module_sp->FindFunctions (m_regex, true, func_list); + } + break; + case Breakpoint::Glob: + if (log) + log->Warning ("glob is not supported yet."); + break; } - + // Remove any duplicates between the funcion list and the symbol list if (func_list.GetSize()) { @@ -140,7 +144,7 @@ { if (func_list.GetContextAtIndex(i, sc) == false) continue; - + if (sc.function == NULL) continue; uint32_t j = 0; @@ -158,11 +162,11 @@ } } } - + j++; } } - + for (i = 0; i < func_list.GetSize(); i++) { if (func_list.GetContextAtIndex(i, sc)) @@ -176,7 +180,7 @@ if (prologue_byte_size) break_addr.SetOffset(break_addr.GetOffset() + prologue_byte_size); } - + if (filter.AddressPasses(break_addr)) { BreakpointLocationSP bp_loc_sp (m_breakpoint->AddLocation(break_addr, &new_location)); @@ -194,7 +198,7 @@ } } } - + for (i = 0; i < sym_list.GetSize(); i++) { if (sym_list.GetContextAtIndex(i, sc)) @@ -202,14 +206,14 @@ if (sc.symbol && sc.symbol->GetAddressRangePtr()) { break_addr = sc.symbol->GetAddressRangePtr()->GetBaseAddress(); - + if (skip_prologue) { const uint32_t prologue_byte_size = sc.symbol->GetPrologueByteSize(); if (prologue_byte_size) break_addr.SetOffset(break_addr.GetOffset() + prologue_byte_size); } - + if (filter.AddressPasses(break_addr)) { BreakpointLocationSP bp_loc_sp (m_breakpoint->AddLocation(break_addr, &new_location)); @@ -236,12 +240,10 @@ void BreakpointResolverName::GetDescription (Stream *s) { - s->PutCString("Breakpoint by name: "); - if (m_match_type == Breakpoint::Regexp) - s->Printf("'%s' (regular expression)", m_regex.GetText()); + s->Printf("regex = '%s'", m_regex.GetText()); else - s->Printf("'%s'", m_func_name.AsCString()); + s->Printf("name = '%s'", m_func_name.AsCString()); } void Modified: lldb/trunk/source/Commands/CommandObjectBreakpoint.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectBreakpoint.cpp?rev=107075&r1=107074&r2=107075&view=diff ============================================================================== --- lldb/trunk/source/Commands/CommandObjectBreakpoint.cpp (original) +++ lldb/trunk/source/Commands/CommandObjectBreakpoint.cpp Mon Jun 28 16:30:43 2010 @@ -52,6 +52,7 @@ m_column (0), m_ignore_inlines (false), m_func_name (), + m_func_name_type_mask (0), m_func_regexp (), m_modules (), m_load_addr(), @@ -70,31 +71,28 @@ lldb::OptionDefinition CommandObjectBreakpointSet::CommandOptions::g_option_table[] = { - { LLDB_OPT_SET_ALL, false, "shlib", 's', required_argument, NULL, CommandCompletions::eModuleCompletion, "", + { LLDB_OPT_SET_ALL, false, "shlib", 's', required_argument, NULL, CommandCompletions::eModuleCompletion, "", "Set the breakpoint only in this shared library (can use this option multiple times for multiple shlibs)."}, - { LLDB_OPT_SET_ALL, false, "ignore_inlines", 'i', no_argument, NULL, 0, NULL, - "Ignore inlined subroutines when setting the breakppoint." }, - - { LLDB_OPT_SET_ALL, false, "ignore_count", 'k', required_argument, NULL, 0, NULL, + { LLDB_OPT_SET_ALL, false, "ignore_count", 'k', required_argument, NULL, 0, "", "Set the number of times this breakpoint is sKipped before stopping." }, - { LLDB_OPT_SET_ALL, false, "thread_index", 'x', required_argument, NULL, NULL, "", + { LLDB_OPT_SET_ALL, false, "thread_index", 'x', required_argument, NULL, NULL, "", "The breakpoint stops only for the thread whose indeX matches this argument."}, - { LLDB_OPT_SET_ALL, false, "thread_id", 't', required_argument, NULL, NULL, "", + { LLDB_OPT_SET_ALL, false, "thread_id", 't', required_argument, NULL, NULL, "", "The breakpoint stops only for the thread whose TID matches this argument."}, - { LLDB_OPT_SET_ALL, false, "thread_name", 'T', required_argument, NULL, NULL, "", + { LLDB_OPT_SET_ALL, false, "thread_name", 'T', required_argument, NULL, NULL, "", "The breakpoint stops only for the thread whose thread name matches this argument."}, - { LLDB_OPT_SET_ALL, false, "queue_name", 'q', required_argument, NULL, NULL, "", + { LLDB_OPT_SET_ALL, false, "queue_name", 'q', required_argument, NULL, NULL, "", "The breakpoint stops only for threads in the queue whose name is given by this argument."}, - { LLDB_OPT_SET_1, false, "file", 'f', required_argument, NULL, CommandCompletions::eSourceFileCompletion, "", + { LLDB_OPT_SET_1, false, "file", 'f', required_argument, NULL, CommandCompletions::eSourceFileCompletion, "", "Set the breakpoint by source location in this particular file."}, - { LLDB_OPT_SET_1, true, "line", 'l', required_argument, NULL, 0, "", + { LLDB_OPT_SET_1, true, "line", 'l', required_argument, NULL, 0, "", "Set the breakpoint by source location at this particular line."}, // Comment out this option for the moment, as we don't actually use it, but will in the future. @@ -102,12 +100,24 @@ // { 0, false, "column", 'c', required_argument, NULL, "", // "Set the breakpoint by source location at this particular column."}, - { LLDB_OPT_SET_2, true, "address", 'a', required_argument, NULL, 0, "
", + { LLDB_OPT_SET_2, true, "address", 'a', required_argument, NULL, 0, "
", "Set the breakpoint by address, at the specified address."}, - { LLDB_OPT_SET_3, true, "name", 'n', required_argument, NULL, CommandCompletions::eSymbolCompletion, "", + { LLDB_OPT_SET_3, true, "name", 'n', required_argument, NULL, CommandCompletions::eSymbolCompletion, "", "Set the breakpoint by function name." }, + { LLDB_OPT_SET_3, false, "basename", 'b', no_argument, NULL, 0, NULL, + "Used in conjuction with --name to search function basenames." }, + + { LLDB_OPT_SET_3, false, "fullname", 'F', no_argument, NULL, 0, NULL, + "Used in conjuction with --name to search fully qualified function names. For C++ this means namespaces and all arguemnts, and for Objective C this means a full function prototype with class and selector." }, + + { LLDB_OPT_SET_3, false, "selector", 'S', no_argument, NULL, 0, NULL, + "Used in conjuction with --name to search objective C selector names." }, + + { LLDB_OPT_SET_3, false, "method", 'm', no_argument, NULL, 0, NULL, + "Used in conjuction with --name to search objective C selector C++ method names." }, + { LLDB_OPT_SET_4, true, "func_regex", 'r', required_argument, NULL, 0, "", "Set the breakpoint by function name, evaluating a regular-expression to find the function name(s)." }, @@ -140,21 +150,39 @@ case 'c': m_column = Args::StringToUInt32 (option_arg, 0); break; + case 'f': m_filename = option_arg; break; - case 'i': - m_ignore_inlines = true; - break; + case 'l': m_line_num = Args::StringToUInt32 (option_arg, 0); break; + case 'n': m_func_name = option_arg; break; + + case 'b': + m_func_name_type_mask |= eFunctionNameTypeBase; + break; + + case 'F': + m_func_name_type_mask |= eFunctionNameTypeFull; + break; + + case 'S': + m_func_name_type_mask |= eFunctionNameTypeSelector; + break; + + case 'm': + m_func_name_type_mask |= eFunctionNameTypeMethod; + break; + case 'r': m_func_regexp = option_arg; break; + case 's': { m_modules.push_back (std::string (option_arg)); @@ -204,8 +232,8 @@ m_filename.clear(); m_line_num = 0; m_column = 0; - m_ignore_inlines = false; m_func_name.clear(); + m_func_name_type_mask = 0; m_func_regexp.clear(); m_load_addr = LLDB_INVALID_ADDRESS; m_modules.clear(); @@ -357,32 +385,50 @@ case eSetTypeAddress: // Breakpoint by address bp = target->CreateBreakpoint (m_options.m_load_addr, false).get(); break; + case eSetTypeFunctionName: // Breakpoint by function name - if (use_module) { - for (int i = 0; i < num_modules; ++i) + uint32_t name_type_mask = m_options.m_func_name_type_mask; + + if (name_type_mask == 0) { - module.SetFile(m_options.m_modules[i].c_str()); - bp = target->CreateBreakpoint (&module, m_options.m_func_name.c_str()).get(); - if (bp) - { - StreamString &output_stream = result.GetOutputStream(); - output_stream.Printf ("Breakpoint created: "); - bp->GetDescription(&output_stream, lldb::eDescriptionLevelBrief); - output_stream.EOL(); - result.SetStatus (eReturnStatusSuccessFinishResult); - } + + if (m_options.m_func_name.find('(') != std::string::npos || + m_options.m_func_name.find("-[") == 0 || + m_options.m_func_name.find("+[") == 0) + name_type_mask |= eFunctionNameTypeFull; else + name_type_mask |= eFunctionNameTypeBase; + } + + + if (use_module) + { + for (int i = 0; i < num_modules; ++i) { - result.AppendErrorWithFormat("Breakpoint creation failed: No breakpoint created in module '%s'.\n", - m_options.m_modules[i].c_str()); - result.SetStatus (eReturnStatusFailed); + module.SetFile(m_options.m_modules[i].c_str()); + bp = target->CreateBreakpoint (&module, m_options.m_func_name.c_str(), name_type_mask, Breakpoint::Exact).get(); + if (bp) + { + StreamString &output_stream = result.GetOutputStream(); + output_stream.Printf ("Breakpoint created: "); + bp->GetDescription(&output_stream, lldb::eDescriptionLevelBrief); + output_stream.EOL(); + result.SetStatus (eReturnStatusSuccessFinishResult); + } + else + { + result.AppendErrorWithFormat("Breakpoint creation failed: No breakpoint created in module '%s'.\n", + m_options.m_modules[i].c_str()); + result.SetStatus (eReturnStatusFailed); + } } } + else + bp = target->CreateBreakpoint (NULL, m_options.m_func_name.c_str(), name_type_mask, Breakpoint::Exact).get(); } - else - bp = target->CreateBreakpoint (NULL, m_options.m_func_name.c_str()).get(); break; + case eSetTypeFunctionRegexp: // Breakpoint by regular expression function name { RegularExpression regexp(m_options.m_func_regexp.c_str()); @@ -412,6 +458,7 @@ bp = target->CreateBreakpoint (NULL, regexp).get(); } break; + default: break; } Modified: lldb/trunk/source/Commands/CommandObjectBreakpoint.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectBreakpoint.h?rev=107075&r1=107074&r2=107075&view=diff ============================================================================== --- lldb/trunk/source/Commands/CommandObjectBreakpoint.h (original) +++ lldb/trunk/source/Commands/CommandObjectBreakpoint.h Mon Jun 28 16:30:43 2010 @@ -98,10 +98,11 @@ // Instance variables to hold the values for command options. std::string m_filename; - unsigned int m_line_num; - unsigned int m_column; + uint32_t m_line_num; + uint32_t m_column; bool m_ignore_inlines; std::string m_func_name; + uint32_t m_func_name_type_mask; std::string m_func_regexp; lldb::addr_t m_load_addr; STLStringArray m_modules; Modified: lldb/trunk/source/Commands/CommandObjectCall.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectCall.cpp?rev=107075&r1=107074&r2=107075&view=diff ============================================================================== --- lldb/trunk/source/Commands/CommandObjectCall.cpp (original) +++ lldb/trunk/source/Commands/CommandObjectCall.cpp Mon Jun 28 16:30:43 2010 @@ -295,7 +295,7 @@ lldb::OptionDefinition CommandObjectCall::CommandOptions::g_option_table[] = { -{ LLDB_OPT_SET_1, true, "language", 'l', required_argument, NULL, 0, "[c|c++|objc|objc++]", "Sets the language to use when parsing the expression."}, +{ LLDB_OPT_SET_1, false, "language", 'l', required_argument, NULL, 0, "[c|c++|objc|objc++]", "Sets the language to use when parsing the expression."}, { LLDB_OPT_SET_1, false, "format", 'f', required_argument, NULL, 0, "[ [bool|b] | [bin] | [char|c] | [oct|o] | [dec|i|d|u] | [hex|x] | [float|f] | [cstr|s] ]", "Specify the format that the expression output should use."}, { LLDB_OPT_SET_1, false, "debug", 'g', no_argument, NULL, 0, NULL, "Enable verbose debug logging of the expression parsing and evaluation."}, { LLDB_OPT_SET_1, false, "noexecute", 'n', no_argument, NULL, 0, "no execute", "Only JIT and copy the wrapper & arguments, but don't execute."}, Modified: lldb/trunk/source/Commands/CommandObjectDisassemble.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectDisassemble.cpp?rev=107075&r1=107074&r2=107075&view=diff ============================================================================== --- lldb/trunk/source/Commands/CommandObjectDisassemble.cpp (original) +++ lldb/trunk/source/Commands/CommandObjectDisassemble.cpp Mon Jun 28 16:30:43 2010 @@ -389,7 +389,9 @@ { SymbolContextList sc_list; - if (target->GetImages().FindFunctions(name, sc_list)) + if (target->GetImages().FindFunctions(name, + eFunctionNameTypeBase | eFunctionNameTypeFull | eFunctionNameTypeMethod | eFunctionNameTypeSelector, + sc_list)) { Disassemble (interpreter, result, disassembler, sc_list); } Modified: lldb/trunk/source/Commands/CommandObjectExpression.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectExpression.cpp?rev=107075&r1=107074&r2=107075&view=diff ============================================================================== --- lldb/trunk/source/Commands/CommandObjectExpression.cpp (original) +++ lldb/trunk/source/Commands/CommandObjectExpression.cpp Mon Jun 28 16:30:43 2010 @@ -456,7 +456,7 @@ lldb::OptionDefinition CommandObjectExpression::CommandOptions::g_option_table[] = { -{ LLDB_OPT_SET_ALL, true, "language", 'l', required_argument, NULL, 0, "[c|c++|objc|objc++]", "Sets the language to use when parsing the expression."}, +{ LLDB_OPT_SET_ALL, false, "language", 'l', required_argument, NULL, 0, "[c|c++|objc|objc++]", "Sets the language to use when parsing the expression."}, { LLDB_OPT_SET_ALL, false, "format", 'f', required_argument, NULL, 0, "[ [bool|b] | [bin] | [char|c] | [oct|o] | [dec|i|d|u] | [hex|x] | [float|f] | [cstr|s] ]", "Specify the format that the expression output should use."}, { LLDB_OPT_SET_ALL, false, "debug", 'g', no_argument, NULL, 0, NULL, "Enable verbose debug logging of the expression parsing and evaluation."}, { LLDB_OPT_SET_ALL, false, "use-ir", 'i', no_argument, NULL, 0, NULL, "[Temporary] Instructs the expression evaluator to use IR instead of ASTs."}, Modified: lldb/trunk/source/Commands/CommandObjectImage.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectImage.cpp?rev=107075&r1=107074&r2=107075&view=diff ============================================================================== --- lldb/trunk/source/Commands/CommandObjectImage.cpp (original) +++ lldb/trunk/source/Commands/CommandObjectImage.cpp Mon Jun 28 16:30:43 2010 @@ -227,9 +227,12 @@ strm.Printf("0x%llx: ", addr); ExecutionContextScope *exe_scope = interpreter.GetDebugger().GetExecutionContext().GetBestExecutionContextScope(); - if (so_addr.Dump (&strm, exe_scope, Address::DumpStyleSectionNameOffset)) - strm.PutCString(": "); + strm.IndentMore(); + strm.Indent (" Address: "); + so_addr.Dump (&strm, exe_scope, Address::DumpStyleSectionNameOffset); + strm.EOL(); so_addr.Dump (&strm, exe_scope, Address::DumpStyleResolvedDescription); + strm.IndentLess(); return true; } @@ -347,7 +350,7 @@ else { ConstString function_name(name); - num_matches = symbol_vendor->FindFunctions(function_name, true, sc_list); + num_matches = symbol_vendor->FindFunctions(function_name, eFunctionNameTypeBase | eFunctionNameTypeFull | eFunctionNameTypeMethod | eFunctionNameTypeSelector, true, sc_list); } if (num_matches) Modified: lldb/trunk/source/Commands/CommandObjectThread.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectThread.cpp?rev=107075&r1=107074&r2=107075&view=diff ============================================================================== --- lldb/trunk/source/Commands/CommandObjectThread.cpp (original) +++ lldb/trunk/source/Commands/CommandObjectThread.cpp Mon Jun 28 16:30:43 2010 @@ -619,8 +619,8 @@ lldb::OptionDefinition CommandObjectThreadStepWithTypeAndScope::CommandOptions::g_option_table[] = { -{ LLDB_OPT_SET_1, true, "avoid_no_debug", 'a', required_argument, NULL, 0, "", "Should step-in step over functions with no debug information"}, -{ LLDB_OPT_SET_1, true, "run_mode", 'm', required_argument, g_tri_running_mode, 0, "", "Determine how to run other threads while stepping this one"}, +{ LLDB_OPT_SET_1, false, "avoid_no_debug", 'a', required_argument, NULL, 0, "", "Should step-in step over functions with no debug information"}, +{ LLDB_OPT_SET_1, false, "run_mode", 'm', required_argument, g_tri_running_mode, 0, "", "Determine how to run other threads while stepping this one"}, { 0, false, NULL, 0, 0, NULL, 0, NULL, NULL } }; @@ -1060,9 +1060,9 @@ lldb::OptionDefinition CommandObjectThreadUntil::CommandOptions::g_option_table[] = { -{ LLDB_OPT_SET_1, true, "frame", 'f', required_argument, NULL, 0, "", "Frame index for until operation - defaults to 0"}, -{ LLDB_OPT_SET_1, true, "thread", 't', required_argument, NULL, 0, "", "Thread index for the thread for until operation"}, -{ LLDB_OPT_SET_1, true, "run_mode", 'm', required_argument, g_duo_running_mode, 0, "", "Determine how to run other threads while stepping this one"}, +{ LLDB_OPT_SET_1, false, "frame", 'f', required_argument, NULL, 0, "", "Frame index for until operation - defaults to 0"}, +{ LLDB_OPT_SET_1, false, "thread", 't', required_argument, NULL, 0, "", "Thread index for the thread for until operation"}, +{ LLDB_OPT_SET_1, false, "run_mode",'m', required_argument, g_duo_running_mode, 0, "","Determine how to run other threads while stepping this one"}, { 0, false, NULL, 0, 0, NULL, 0, NULL, NULL } }; Modified: lldb/trunk/source/Core/Address.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/Address.cpp?rev=107075&r1=107074&r2=107075&view=diff ============================================================================== --- lldb/trunk/source/Core/Address.cpp (original) +++ lldb/trunk/source/Core/Address.cpp Mon Jun 28 16:30:43 2010 @@ -629,7 +629,10 @@ { // We have a function or a symbol from the same // sections as this address. + s->Indent(" Summary: "); sc.DumpStopContext(s, process, *this, false); + s->EOL(); + sc.GetDescription(s, eDescriptionLevelBrief, process); } else { Modified: lldb/trunk/source/Core/AddressResolverName.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/AddressResolverName.cpp?rev=107075&r1=107074&r2=107075&view=diff ============================================================================== --- lldb/trunk/source/Core/AddressResolverName.cpp (original) +++ lldb/trunk/source/Core/AddressResolverName.cpp Mon Jun 28 16:30:43 2010 @@ -107,15 +107,24 @@ case AddressResolver::Exact: if (context.module_sp) { - context.module_sp->FindSymbolsWithNameAndType (m_func_name, eSymbolTypeCode, sym_list); - context.module_sp->FindFunctions (m_func_name, false, func_list); + context.module_sp->FindSymbolsWithNameAndType (m_func_name, + eSymbolTypeCode, + sym_list); + context.module_sp->FindFunctions (m_func_name, + eFunctionNameTypeBase | eFunctionNameTypeFull | eFunctionNameTypeMethod | eFunctionNameTypeSelector, + false, + func_list); } break; case AddressResolver::Regexp: if (context.module_sp) { - context.module_sp->FindSymbolsMatchingRegExAndType (m_regex, eSymbolTypeCode, sym_list); - context.module_sp->FindFunctions (m_regex, true, func_list); + context.module_sp->FindSymbolsMatchingRegExAndType (m_regex, + eSymbolTypeCode, + sym_list); + context.module_sp->FindFunctions (m_regex, + true, + func_list); } break; case AddressResolver::Glob: Modified: lldb/trunk/source/Core/Module.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/Module.cpp?rev=107075&r1=107074&r2=107075&view=diff ============================================================================== --- lldb/trunk/source/Core/Module.cpp (original) +++ lldb/trunk/source/Core/Module.cpp Mon Jun 28 16:30:43 2010 @@ -286,11 +286,11 @@ } uint32_t -Module::FindFunctions(const ConstString &name, bool append, SymbolContextList& sc_list) +Module::FindFunctions(const ConstString &name, uint32_t name_type_mask, bool append, SymbolContextList& sc_list) { SymbolVendor *symbols = GetSymbolVendor (); if (symbols) - return symbols->FindFunctions(name, append, sc_list); + return symbols->FindFunctions(name, name_type_mask, append, sc_list); return 0; } Modified: lldb/trunk/source/Core/ModuleList.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/ModuleList.cpp?rev=107075&r1=107074&r2=107075&view=diff ============================================================================== --- lldb/trunk/source/Core/ModuleList.cpp (original) +++ lldb/trunk/source/Core/ModuleList.cpp Mon Jun 28 16:30:43 2010 @@ -126,14 +126,14 @@ } size_t -ModuleList::FindFunctions (const ConstString &name, SymbolContextList &sc_list) +ModuleList::FindFunctions (const ConstString &name, uint32_t name_type_mask, SymbolContextList &sc_list) { sc_list.Clear(); Mutex::Locker locker(m_modules_mutex); collection::const_iterator pos, end = m_modules.end(); for (pos = m_modules.begin(); pos != end; ++pos) { - (*pos)->FindFunctions (name, true, sc_list); + (*pos)->FindFunctions (name, name_type_mask, true, sc_list); } return sc_list.GetSize(); } Modified: lldb/trunk/source/Core/SearchFilter.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/SearchFilter.cpp?rev=107075&r1=107074&r2=107075&view=diff ============================================================================== --- lldb/trunk/source/Core/SearchFilter.cpp (original) +++ lldb/trunk/source/Core/SearchFilter.cpp Mon Jun 28 16:30:43 2010 @@ -113,7 +113,6 @@ void SearchFilter::GetDescription (Stream *s) { - s->PutCString("No Filter"); } void @@ -415,7 +414,7 @@ void SearchFilterByModule::GetDescription (Stream *s) { - s->PutCString("In module "); + s->PutCString(", module = "); if (s->GetVerbose()) { char buffer[2048]; Modified: lldb/trunk/source/Core/VMRange.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/VMRange.cpp?rev=107075&r1=107074&r2=107075&view=diff ============================================================================== --- lldb/trunk/source/Core/VMRange.cpp (original) +++ lldb/trunk/source/Core/VMRange.cpp Mon Jun 28 16:30:43 2010 @@ -42,9 +42,9 @@ void -VMRange::Dump(Stream *s, lldb::addr_t offset) const +VMRange::Dump(Stream *s, lldb::addr_t offset, uint32_t addr_width) const { - s->AddressRange(offset + GetBaseAddress(), offset + GetEndAddress(), sizeof (addr_t)); + s->AddressRange(offset + GetBaseAddress(), offset + GetEndAddress(), addr_width); } bool 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=107075&r1=107074&r2=107075&view=diff ============================================================================== --- lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp (original) +++ lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp Mon Jun 28 16:30:43 2010 @@ -14,6 +14,7 @@ #include "DWARFDebugAbbrev.h" #include "DWARFDebugAranges.h" +#include "DWARFDebugInfo.h" #include "DWARFDIECollection.h" #include "DWARFFormValue.h" #include "LogChannelDWARF.h" @@ -549,13 +550,14 @@ void DWARFCompileUnit::Index ( - lldb_private::UniqueCStringMap& name_to_function_die, - lldb_private::UniqueCStringMap& name_to_inlined_die, - lldb_private::UniqueCStringMap& name_to_global_die, - lldb_private::UniqueCStringMap& name_to_type_die + lldb_private::UniqueCStringMap& base_name_to_function_die, + lldb_private::UniqueCStringMap& full_name_to_function_die, + lldb_private::UniqueCStringMap& method_name_to_function_die, + lldb_private::UniqueCStringMap& selector_name_to_function_die, + lldb_private::UniqueCStringMap& name_to_type_die, + lldb_private::UniqueCStringMap& name_to_global_die ) { - const DataExtractor* debug_str = &m_dwarf2Data->get_debug_str_data(); DWARFDebugInfoEntry::const_iterator pos; @@ -597,6 +599,7 @@ bool has_address = false; bool has_location = false; bool is_global_or_static_variable = false; + dw_offset_t specification_die_offset = DW_INVALID_OFFSET; const size_t num_attributes = die.GetAttributes(m_dwarf2Data, this, attributes); if (num_attributes > 0) { @@ -685,6 +688,11 @@ } } break; + + case DW_AT_specification: + if (attributes.ExtractFormValueAtIndex(m_dwarf2Data, i, form_value)) + specification_die_offset = form_value.Reference(this); + break; } } } @@ -694,7 +702,7 @@ case DW_TAG_subprogram: if (has_address) { - if (name && name[0]) + if (name) { if ((name[0] == '-' || name[0] == '+') && name[1] == '[') { @@ -716,24 +724,58 @@ // accelerator tables size_t method_name_len = name_len - (method_name - name) - 1; ConstString method_const_str (method_name, method_name_len); - name_to_function_die.Append(method_const_str.AsCString(), die.GetOffset()); + selector_name_to_function_die.Append(method_const_str.AsCString(), die.GetOffset()); + } + } + } + // If we have a mangled name, then the DW_AT_name attribute + // is usually the method name without the class or any parameters + const DWARFDebugInfoEntry *parent = die.GetParent(); + bool is_method = false; + if (parent) + { + dw_tag_t tag = parent->Tag(); + if (tag == DW_TAG_class_type || tag == DW_TAG_structure_type) + { + is_method = true; + } + else + { + if (mangled && specification_die_offset != DW_INVALID_OFFSET) + { + const DWARFDebugInfoEntry *specification_die = m_dwarf2Data->DebugInfo()->GetDIEPtr (specification_die_offset, NULL); + if (specification_die) + { + parent = specification_die->GetParent(); + if (parent) + { + tag = parent->Tag(); + + if (tag == DW_TAG_class_type || tag == DW_TAG_structure_type) + is_method = true; + } + } } } } - name_to_function_die.Append(ConstString(name).AsCString(), die.GetOffset()); + + if (is_method) + method_name_to_function_die.Append(ConstString(name).AsCString(), die.GetOffset()); + else + base_name_to_function_die.Append(ConstString(name).AsCString(), die.GetOffset()); } - if (mangled && mangled[0]) - name_to_function_die.Append(ConstString(mangled).AsCString(), die.GetOffset()); + if (mangled) + full_name_to_function_die.Append(ConstString(mangled).AsCString(), die.GetOffset()); } break; case DW_TAG_inlined_subroutine: if (has_address) { - if (name && name[0]) - name_to_inlined_die.Append(ConstString(name).AsCString(), die.GetOffset()); - if (mangled && mangled[0]) - name_to_inlined_die.Append(ConstString(mangled).AsCString(), die.GetOffset()); + if (name) + base_name_to_function_die.Append(ConstString(name).AsCString(), die.GetOffset()); + if (mangled) + full_name_to_function_die.Append(ConstString(mangled).AsCString(), die.GetOffset()); } break; Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.h?rev=107075&r1=107074&r2=107075&view=diff ============================================================================== --- lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.h (original) +++ lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.h Mon Jun 28 16:30:43 2010 @@ -142,10 +142,13 @@ } void - Index (lldb_private::UniqueCStringMap& name_to_function_die, - lldb_private::UniqueCStringMap& name_to_inlined_die, - lldb_private::UniqueCStringMap& name_to_global_die, - lldb_private::UniqueCStringMap& name_to_type_die); + Index (lldb_private::UniqueCStringMap& base_name_to_function_die, + lldb_private::UniqueCStringMap& full_name_to_function_die, + lldb_private::UniqueCStringMap& method_name_to_function_die, + lldb_private::UniqueCStringMap& selector_name_to_function_die, + lldb_private::UniqueCStringMap& name_to_type_die, + lldb_private::UniqueCStringMap& name_to_global_die); + protected: SymbolFileDWARF* m_dwarf2Data; 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=107075&r1=107074&r2=107075&view=diff ============================================================================== --- lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp (original) +++ lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp Mon Jun 28 16:30:43 2010 @@ -229,8 +229,10 @@ m_aranges(), m_info(), m_line(), - m_name_to_function_die(), - m_name_to_inlined_die(), + m_base_name_to_function_die(), + m_full_name_to_function_die(), + m_method_name_to_function_die(), + m_selector_name_to_function_die(), m_name_to_global_die(), m_name_to_type_die(), m_indexed(false), @@ -1778,8 +1780,10 @@ bool clear_dies = cu->ExtractDIEsIfNeeded (false) > 1; - cu->Index (m_name_to_function_die, - m_name_to_inlined_die, + cu->Index (m_base_name_to_function_die, + m_full_name_to_function_die, + m_method_name_to_function_die, + m_selector_name_to_function_die, m_name_to_global_die, m_name_to_type_die); @@ -1789,8 +1793,10 @@ cu->ClearDIEs (true); } - m_name_to_function_die.Sort(); - m_name_to_inlined_die.Sort(); + m_base_name_to_function_die.Sort(); + m_full_name_to_function_die.Sort(); + m_method_name_to_function_die.Sort(); + m_selector_name_to_function_die.Sort(); m_name_to_global_die.Sort(); m_name_to_type_die.Sort(); } @@ -1893,33 +1899,20 @@ } -uint32_t -SymbolFileDWARF::FindFunctions(const ConstString &name, bool append, SymbolContextList& sc_list) +void +SymbolFileDWARF::FindFunctions +( + const ConstString &name, + UniqueCStringMap &name_to_die, + SymbolContextList& sc_list +) { - Timer scoped_timer (__PRETTY_FUNCTION__, - "SymbolFileDWARF::FindFunctions (name = '%s')", - name.AsCString()); - - std::vector die_offsets; - - // If we aren't appending the results to this list, then clear the list - if (!append) - sc_list.Clear(); - - // Remember how many sc_list are in the list before we search in case - // we are appending the results to a variable list. - uint32_t original_size = sc_list.GetSize(); - - // Index the DWARF if we haven't already - if (!m_indexed) - Index (); - const UniqueCStringMap::Entry *entry; SymbolContext sc; - for (entry = m_name_to_function_die.FindFirstValueForName (name.AsCString()); + for (entry = name_to_die.FindFirstValueForName (name.AsCString()); entry != NULL; - entry = m_name_to_function_die.FindNextValueForName (name.AsCString(), entry)) + entry = name_to_die.FindNextValueForName (name.AsCString(), entry)) { DWARFCompileUnitSP cu_sp; const DWARFDebugInfoEntry* die = DebugInfo()->GetDIEPtr (entry->value, &cu_sp); @@ -1943,6 +1936,47 @@ } } +} + +uint32_t +SymbolFileDWARF::FindFunctions +( + const ConstString &name, + uint32_t name_type_mask, + bool append, + SymbolContextList& sc_list +) +{ + Timer scoped_timer (__PRETTY_FUNCTION__, + "SymbolFileDWARF::FindFunctions (name = '%s')", + name.AsCString()); + + std::vector die_offsets; + + // If we aren't appending the results to this list, then clear the list + if (!append) + sc_list.Clear(); + + // Remember how many sc_list are in the list before we search in case + // we are appending the results to a variable list. + uint32_t original_size = sc_list.GetSize(); + + // Index the DWARF if we haven't already + if (!m_indexed) + Index (); + + if (name_type_mask & eFunctionNameTypeBase) + FindFunctions (name, m_base_name_to_function_die, sc_list); + + if (name_type_mask & eFunctionNameTypeFull) + FindFunctions (name, m_full_name_to_function_die, sc_list); + + if (name_type_mask & eFunctionNameTypeMethod) + FindFunctions (name, m_method_name_to_function_die, sc_list); + + if (name_type_mask & eFunctionNameTypeSelector) + FindFunctions (name, m_selector_name_to_function_die, sc_list); + // Return the number of variable that were appended to the list return sc_list.GetSize() - original_size; } @@ -1971,14 +2005,14 @@ // Create the pubnames information so we can quickly lookup external symbols by name // Create the pubnames information so we can quickly lookup external symbols by name - const size_t num_entries = m_name_to_function_die.GetSize(); + const size_t num_entries = m_full_name_to_function_die.GetSize(); SymbolContext sc; for (size_t i=0; iGetDIEPtr (die_offset, &cu_sp); Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h?rev=107075&r1=107074&r2=107075&view=diff ============================================================================== --- lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h (original) +++ lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h Mon Jun 28 16:30:43 2010 @@ -97,7 +97,7 @@ virtual uint32_t ResolveSymbolContext (const lldb_private::FileSpec& file_spec, uint32_t line, bool check_inlines, uint32_t resolve_scope, lldb_private::SymbolContextList& sc_list); virtual uint32_t FindGlobalVariables(const lldb_private::ConstString &name, bool append, uint32_t max_matches, lldb_private::VariableList& variables); virtual uint32_t FindGlobalVariables(const lldb_private::RegularExpression& regex, bool append, uint32_t max_matches, lldb_private::VariableList& variables); - virtual uint32_t FindFunctions(const lldb_private::ConstString &name, bool append, lldb_private::SymbolContextList& sc_list); + virtual uint32_t FindFunctions(const lldb_private::ConstString &name, uint32_t name_type_mask, bool append, lldb_private::SymbolContextList& sc_list); virtual uint32_t FindFunctions(const lldb_private::RegularExpression& regex, bool append, lldb_private::SymbolContextList& sc_list); // virtual uint32_t FindTypes(const lldb_private::SymbolContext& sc, const lldb_private::ConstString &name, bool append, uint32_t max_matches, lldb::Type::Encoding encoding, lldb::user_id_t udt_uid, lldb_private::TypeList& types); // virtual uint32_t FindTypes(const lldb_private::SymbolContext& sc, const lldb_private::RegularExpression& regex, bool append, uint32_t max_matches, lldb::Type::Encoding encoding, lldb::user_id_t udt_uid, lldb_private::TypeList& types); @@ -277,6 +277,11 @@ uint32_t& byte_stride, uint32_t& bit_stride); + void FindFunctions( + const lldb_private::ConstString &name, + lldb_private::UniqueCStringMap &name_to_die, + lldb_private::SymbolContextList& sc_list); + lldb_private::Type* GetUniquedTypeForDIEOffset(dw_offset_t type_die_offset, lldb::TypeSP& owning_type_sp, int32_t child_type, uint32_t idx, bool safe); lldb::TypeSP GetTypeForDIE(DWARFCompileUnit *cu, const DWARFDebugInfoEntry* die, lldb::TypeSP& owning_type_sp, int32_t child_type, uint32_t idx); // uint32_t FindTypes(std::vector die_offsets, uint32_t max_matches, Type::Encoding encoding, lldb::user_id_t udt_uid, TypeList& types); @@ -303,8 +308,10 @@ std::auto_ptr m_aranges; std::auto_ptr m_info; std::auto_ptr m_line; - lldb_private::UniqueCStringMap m_name_to_function_die; // All concrete functions - lldb_private::UniqueCStringMap m_name_to_inlined_die; // All inlined functions + lldb_private::UniqueCStringMap m_base_name_to_function_die; // All concrete functions + lldb_private::UniqueCStringMap m_full_name_to_function_die; // All concrete functions + lldb_private::UniqueCStringMap m_method_name_to_function_die; // All inlined functions + lldb_private::UniqueCStringMap m_selector_name_to_function_die; // All method names for functions of classes lldb_private::UniqueCStringMap m_name_to_global_die; // Global and static variables lldb_private::UniqueCStringMap m_name_to_type_die; // All type DIE offsets bool m_indexed; Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp?rev=107075&r1=107074&r2=107075&view=diff ============================================================================== --- lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp (original) +++ lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp Mon Jun 28 16:30:43 2010 @@ -763,7 +763,7 @@ } uint32_t -SymbolFileDWARFDebugMap::FindFunctions(const ConstString &name, bool append, SymbolContextList& sc_list) +SymbolFileDWARFDebugMap::FindFunctions(const ConstString &name, uint32_t name_type_mask, bool append, SymbolContextList& sc_list) { Timer scoped_timer (__PRETTY_FUNCTION__, "SymbolFileDWARFDebugMap::FindFunctions (name = %s)", @@ -788,7 +788,7 @@ { SymbolFileDWARF *oso_dwarf = GetSymbolFileByOSOIndex (oso_idx); if (oso_dwarf) - oso_dwarf->FindFunctions(name, true, sc_list); + oso_dwarf->FindFunctions(name, name_type_mask, true, sc_list); } } // Stream s(stdout); Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h?rev=107075&r1=107074&r2=107075&view=diff ============================================================================== --- lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h (original) +++ lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h Mon Jun 28 16:30:43 2010 @@ -64,7 +64,7 @@ virtual uint32_t ResolveSymbolContext (const lldb_private::FileSpec& file_spec, uint32_t line, bool check_inlines, uint32_t resolve_scope, lldb_private::SymbolContextList& sc_list); virtual uint32_t FindGlobalVariables (const lldb_private::ConstString &name, bool append, uint32_t max_matches, lldb_private::VariableList& variables); virtual uint32_t FindGlobalVariables (const lldb_private::RegularExpression& regex, bool append, uint32_t max_matches, lldb_private::VariableList& variables); - virtual uint32_t FindFunctions (const lldb_private::ConstString &name, bool append, lldb_private::SymbolContextList& sc_list); + virtual uint32_t FindFunctions (const lldb_private::ConstString &name, uint32_t name_type_mask, bool append, lldb_private::SymbolContextList& sc_list); virtual uint32_t FindFunctions (const lldb_private::RegularExpression& regex, bool append, lldb_private::SymbolContextList& sc_list); // virtual uint32_t FindTypes (const lldb_private::SymbolContext& sc, const ConstString &name, bool append, uint32_t max_matches, Type::Encoding encoding, lldb::user_id_t udt_uid, TypeList& types); // virtual uint32_t FindTypes (const lldb_private::SymbolContext& sc, const RegularExpression& regex, bool append, uint32_t max_matches, Type::Encoding encoding, lldb::user_id_t udt_uid, TypeList& types); Modified: lldb/trunk/source/Plugins/SymbolFile/Symtab/SymbolFileSymtab.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/Symtab/SymbolFileSymtab.cpp?rev=107075&r1=107074&r2=107075&view=diff ============================================================================== --- lldb/trunk/source/Plugins/SymbolFile/Symtab/SymbolFileSymtab.cpp (original) +++ lldb/trunk/source/Plugins/SymbolFile/Symtab/SymbolFileSymtab.cpp Mon Jun 28 16:30:43 2010 @@ -308,7 +308,7 @@ } uint32_t -SymbolFileSymtab::FindFunctions(const ConstString &name, bool append, SymbolContextList& sc_list) +SymbolFileSymtab::FindFunctions(const ConstString &name, uint32_t name_type_mask, bool append, SymbolContextList& sc_list) { Timer scoped_timer (__PRETTY_FUNCTION__, "SymbolFileSymtab::FindFunctions (name = '%s')", Modified: lldb/trunk/source/Plugins/SymbolFile/Symtab/SymbolFileSymtab.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/Symtab/SymbolFileSymtab.h?rev=107075&r1=107074&r2=107075&view=diff ============================================================================== --- lldb/trunk/source/Plugins/SymbolFile/Symtab/SymbolFileSymtab.h (original) +++ lldb/trunk/source/Plugins/SymbolFile/Symtab/SymbolFileSymtab.h Mon Jun 28 16:30:43 2010 @@ -87,7 +87,7 @@ FindGlobalVariables(const lldb_private::RegularExpression& regex, bool append, uint32_t max_matches, lldb_private::VariableList& variables); virtual uint32_t - FindFunctions(const lldb_private::ConstString &name, bool append, lldb_private::SymbolContextList& sc_list); + FindFunctions(const lldb_private::ConstString &name, uint32_t name_type_mask, bool append, lldb_private::SymbolContextList& sc_list); virtual uint32_t FindFunctions(const lldb_private::RegularExpression& regex, bool append, lldb_private::SymbolContextList& sc_list); Modified: lldb/trunk/source/Symbol/Block.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/Block.cpp?rev=107075&r1=107074&r2=107075&view=diff ============================================================================== --- lldb/trunk/source/Symbol/Block.cpp (original) +++ lldb/trunk/source/Symbol/Block.cpp Mon Jun 28 16:30:43 2010 @@ -57,6 +57,30 @@ } void +Block::GetDescription(Stream *s, lldb::DescriptionLevel level, Process *process) const +{ + size_t num_ranges = m_ranges.size(); + if (num_ranges) + { + + addr_t base_addr = LLDB_INVALID_ADDRESS; + if (process) + base_addr = m_block_list->GetAddressRange().GetBaseAddress().GetLoadAddress(process); + if (base_addr == LLDB_INVALID_ADDRESS) + base_addr = m_block_list->GetAddressRange().GetBaseAddress().GetFileAddress(); + + s->Printf("range%s = ", num_ranges > 1 ? "s" : ""); + std::vector::const_iterator pos, end = m_ranges.end(); + for (pos = m_ranges.begin(); pos != end; ++pos) + pos->Dump(s, base_addr, 4); + } + *s << ", id = " << ((const UserID&)*this); + + if (m_inlineInfoSP.get() != NULL) + m_inlineInfoSP->Dump(s); +} + +void Block::Dump(Stream *s, addr_t base_addr, int32_t depth, bool show_context) const { if (depth < 0) @@ -69,12 +93,10 @@ s->Printf("%.*p: ", (int)sizeof(void*) * 2, this); s->Indent(); *s << "Block" << ((const UserID&)*this); - user_id_t parentID = GetParentUID(); - const Block* parent_block = NULL; - if (parentID != Block::InvalidID) + const Block* parent_block = GetParent(); + if (parent_block) { - parent_block = m_block_list->GetBlockByID(parentID); - s->Printf(", parent = {0x%8.8x}", parentID); + s->Printf(", parent = {0x%8.8x}", parent_block->GetID()); } if (m_inlineInfoSP.get() != NULL) m_inlineInfoSP->Dump(s); @@ -128,10 +150,7 @@ void Block::DumpStopContext (Stream *s, const SymbolContext *sc) { - user_id_t parentID = GetParentUID(); - Block* parent_block = NULL; - if (parentID != Block::InvalidID) - parent_block = m_block_list->GetBlockByID(parentID); + Block* parent_block = GetParent(); InlineFunctionInfo* inline_info = InlinedFunctionInfo (); if (inline_info) @@ -256,6 +275,24 @@ } +Block * +Block::GetParent () const +{ + return m_block_list->GetBlockByID (m_block_list->GetParent(GetID())); +} + +Block * +Block::GetSibling () const +{ + return m_block_list->GetBlockByID (m_block_list->GetSibling(GetID())); +} + +Block * +Block::GetFirstChild () const +{ + return m_block_list->GetBlockByID (m_block_list->GetFirstChild(GetID())); +} + user_id_t Block::GetParentUID() const { @@ -455,7 +492,7 @@ const Block * BlockList::GetBlockByID(user_id_t blockID) const { - if (m_blocks.empty()) + if (m_blocks.empty() || blockID == Block::InvalidID) return NULL; if (blockID == Block::RootID) @@ -471,7 +508,7 @@ Block * BlockList::GetBlockByID(user_id_t blockID) { - if (m_blocks.empty()) + if (m_blocks.empty() || blockID == Block::InvalidID) return NULL; if (blockID == Block::RootID) @@ -584,16 +621,13 @@ if (get_child_variables) { - user_id_t block_id = GetFirstChildUID(); - while (block_id != Block::InvalidID) + Block *child_block = GetFirstChild(); + while (child_block) { - Block *child_block = m_block_list->GetBlockByID(block_id); - assert(child_block); VariableListSP child_block_variable_list(child_block->GetVariableList(get_child_variables, can_create)); if (child_block_variable_list.get()) variable_list_sp->AddVariables(child_block_variable_list.get()); - - block_id = child_block->GetSiblingUID(); + child_block = child_block->GetSibling(); } } } @@ -615,13 +649,9 @@ if (get_parent_variables) { - user_id_t parentID = GetParentUID(); - if (parentID != Block::InvalidID) - { - Block* parent_block = m_block_list->GetBlockByID(parentID); - if (parent_block) - num_variables_added += parent_block->AppendVariables (can_create, get_parent_variables, variable_list); - } + Block* parent_block = GetParent(); + if (parent_block) + num_variables_added += parent_block->AppendVariables (can_create, get_parent_variables, variable_list); } return num_variables_added; } Modified: lldb/trunk/source/Symbol/CompileUnit.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/CompileUnit.cpp?rev=107075&r1=107074&r2=107075&view=diff ============================================================================== --- lldb/trunk/source/Symbol/CompileUnit.cpp (original) +++ lldb/trunk/source/Symbol/CompileUnit.cpp Mon Jun 28 16:30:43 2010 @@ -65,6 +65,13 @@ } +void +CompileUnit::GetDescription(Stream *s, lldb::DescriptionLevel level) const +{ + *s << '"' << (const FileSpec&)*this << "\", id = " << (const UserID&)*this + << ", language = " << (const Language&)*this; +} + //---------------------------------------------------------------------- // Dump the current contents of this object. No functions that cause on Modified: lldb/trunk/source/Symbol/Declaration.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/Declaration.cpp?rev=107075&r1=107074&r2=107075&view=diff ============================================================================== --- lldb/trunk/source/Symbol/Declaration.cpp (original) +++ lldb/trunk/source/Symbol/Declaration.cpp Mon Jun 28 16:30:43 2010 @@ -61,12 +61,11 @@ { if (m_file) { - *s << ", decl = '" << m_file; + *s << ", decl = " << m_file; if (m_line > 0) s->Printf(":%u", m_line); if (m_column > 0) s->Printf(":%u", m_column); - s->PutChar('\''); } else { Modified: lldb/trunk/source/Symbol/Function.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/Function.cpp?rev=107075&r1=107074&r2=107075&view=diff ============================================================================== --- lldb/trunk/source/Symbol/Function.cpp (original) +++ lldb/trunk/source/Symbol/Function.cpp Mon Jun 28 16:30:43 2010 @@ -261,6 +261,16 @@ return m_comp_unit; } + +void +Function::GetDescription(Stream *s, lldb::DescriptionLevel level, Process *process) +{ + Type* func_type = GetType(); + *s << '"' << func_type->GetName() << "\", id = " << (const UserID&)*this; + *s << ", range = "; + GetAddressRange().Dump(s, process, Address::DumpStyleLoadAddress, Address::DumpStyleModuleWithFileAddress); +} + void Function::Dump(Stream *s, bool show_context) const { Modified: lldb/trunk/source/Symbol/LineEntry.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/LineEntry.cpp?rev=107075&r1=107074&r2=107075&view=diff ============================================================================== --- lldb/trunk/source/Symbol/LineEntry.cpp (original) +++ lldb/trunk/source/Symbol/LineEntry.cpp Mon Jun 28 16:30:43 2010 @@ -118,14 +118,12 @@ fallback_style)) return false; } + if (show_file) + *s << ", file = " << file; if (line) s->Printf(", line = %u", line); if (column) s->Printf(", column = %u", column); - if (show_file) - { - *s << ", file = " << file; - } if (is_start_of_statement) *s << ", is_start_of_statement = TRUE"; @@ -144,13 +142,22 @@ } bool -LineEntry::GetDescription (Stream *s, lldb::DescriptionLevel level, CompileUnit* cu, Process *process) const +LineEntry::GetDescription (Stream *s, lldb::DescriptionLevel level, CompileUnit* cu, Process *process, bool show_address_only) const { if (level == lldb::eDescriptionLevelBrief || level == lldb::eDescriptionLevelFull) { // Show address only - range.GetBaseAddress().Dump(s, process, Address::DumpStyleLoadAddress, Address::DumpStyleFileAddress); + if (show_address_only) + { + s->PutCString ("address = "); + range.GetBaseAddress().Dump(s, process, Address::DumpStyleLoadAddress, Address::DumpStyleFileAddress); + } + else + { + s->PutCString ("range = "); + range.Dump(s, process, Address::DumpStyleLoadAddress, Address::DumpStyleFileAddress); + } if (file) *s << ' ' << file; Modified: lldb/trunk/source/Symbol/LineTable.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/LineTable.cpp?rev=107075&r1=107074&r2=107075&view=diff ============================================================================== --- lldb/trunk/source/Symbol/LineTable.cpp (original) +++ lldb/trunk/source/Symbol/LineTable.cpp Mon Jun 28 16:30:43 2010 @@ -324,7 +324,7 @@ for (size_t idx = 0; idx < count; ++idx) { ConvertEntryAtIndexToLineEntry (idx, line_entry); - line_entry.GetDescription (s, level, m_comp_unit, process); + line_entry.GetDescription (s, level, m_comp_unit, process, true); s->EOL(); } } Modified: lldb/trunk/source/Symbol/Symbol.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/Symbol.cpp?rev=107075&r1=107074&r2=107075&view=diff ============================================================================== --- lldb/trunk/source/Symbol/Symbol.cpp (original) +++ lldb/trunk/source/Symbol/Symbol.cpp Mon Jun 28 16:30:43 2010 @@ -168,6 +168,26 @@ } void +Symbol::GetDescription (Stream *s, lldb::DescriptionLevel level, Process *process) const +{ + *s << '"' << m_mangled.GetName() << "\", id = " << (const UserID&)*this; + const Section *section = m_addr_range.GetBaseAddress().GetSection(); + if (section != NULL) + { + if (m_addr_range.GetByteSize() > 0) + { + s->PutCString(", range = "); + m_addr_range.Dump(s, process, Address::DumpStyleLoadAddress, Address::DumpStyleModuleWithFileAddress); + } + else + { + s->PutCString(", address = "); + m_addr_range.GetBaseAddress().Dump(s, process, Address::DumpStyleLoadAddress, Address::DumpStyleModuleWithFileAddress); + } + } +} + +void Symbol::Dump(Stream *s, Process *process, uint32_t index) const { // s->Printf("%.*p: ", (int)sizeof(void*) * 2, this); Modified: lldb/trunk/source/Symbol/SymbolContext.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/SymbolContext.cpp?rev=107075&r1=107074&r2=107075&view=diff ============================================================================== --- lldb/trunk/source/Symbol/SymbolContext.cpp (original) +++ lldb/trunk/source/Symbol/SymbolContext.cpp Mon Jun 28 16:30:43 2010 @@ -8,12 +8,13 @@ //===----------------------------------------------------------------------===// #include "lldb/Symbol/SymbolContext.h" -#include "lldb/Symbol/CompileUnit.h" + #include "lldb/Core/Module.h" +#include "lldb/Symbol/CompileUnit.h" #include "lldb/Symbol/ObjectFile.h" #include "lldb/Symbol/Symbol.h" -#include "lldb/Target/Target.h" #include "lldb/Symbol/SymbolVendor.h" +#include "lldb/Target/Target.h" using namespace lldb; using namespace lldb_private; @@ -169,6 +170,81 @@ } void +SymbolContext::GetDescription(Stream *s, lldb::DescriptionLevel level, Process *process) const +{ + if (module_sp) + { + s->Indent(" Module: \""); + module_sp->GetFileSpec().Dump(s); + s->PutChar('"'); + s->EOL(); + } + + if (comp_unit != NULL) + { + s->Indent("CompileUnit: "); + comp_unit->GetDescription (s, level); + s->EOL(); + } + + if (function != NULL) + { + s->Indent(" Function: "); + function->GetDescription (s, level, process); + s->EOL(); + + Type *func_type = function->GetType(); + if (func_type) + { + s->Indent(" FuncType: "); + func_type->GetDescription (s, level, false); + s->EOL(); + } + } + + if (block != NULL) + { + std::vector blocks; + blocks.push_back (block); + Block *parent_block = block->GetParent(); + + while (parent_block) + { + blocks.push_back (parent_block); + parent_block = parent_block->GetParent(); + } + std::vector::reverse_iterator pos; + std::vector::reverse_iterator begin = blocks.rbegin(); + std::vector::reverse_iterator end = blocks.rend(); + for (pos = begin; pos != end; ++pos) + { + if (pos == begin) + s->Indent(" Blocks: "); + else + s->Indent(" "); + (*pos)->GetDescription(s, level, process); + s->EOL(); + } + } + + if (line_entry.IsValid()) + { + s->Indent(" LineEntry: "); + line_entry.GetDescription (s, level, comp_unit, process, false); + s->EOL(); + } + + if (symbol != NULL) + { + s->Indent(" Symbol: "); + symbol->GetDescription(s, level, process); + s->EOL(); + } +} + + + +void SymbolContext::Dump(Stream *s, Process *process) const { *s << (void *)this << ": "; @@ -178,48 +254,45 @@ s->EOL(); s->IndentMore(); s->Indent(); - *s << "Module = " << (void *)module_sp.get() << ' '; + *s << "Module = " << (void *)module_sp.get() << ' '; if (module_sp) module_sp->GetFileSpec().Dump(s); s->EOL(); s->Indent(); *s << "CompileUnit = " << (void *)comp_unit; if (comp_unit != NULL) - *s << " {" << comp_unit->GetID() << "} " << *(dynamic_cast (comp_unit)); + *s << " {0x" << comp_unit->GetID() << "} " << *(dynamic_cast (comp_unit)); s->EOL(); s->Indent(); - *s << "Function = " << (void *)function; + *s << "Function = " << (void *)function; if (function != NULL) { - *s << " {" << function->GetID() << "} ";/// << function->GetType()->GetName(); -// Type* func_type = function->Type(); -// if (func_type) -// { -// s->EOL(); -// const UserDefType* func_udt = func_type->GetUserDefinedType().get(); -// if (func_udt) -// { -// s->IndentMore(); -// func_udt->Dump(s, func_type); -// s->IndentLess(); -// } -// } + *s << " {0x" << function->GetID() << "} " << function->GetType()->GetName() << ", address-range = "; + function->GetAddressRange().Dump(s, process, Address::DumpStyleLoadAddress, Address::DumpStyleModuleWithFileAddress); + s->EOL(); + s->Indent(); + Type* func_type = function->GetType(); + if (func_type) + { + *s << " Type = "; + func_type->Dump (s, false); + } } s->EOL(); s->Indent(); - *s << "Block = " << (void *)block; + *s << "Block = " << (void *)block; if (block != NULL) - *s << " {" << block->GetID() << '}'; + *s << " {0x" << block->GetID() << '}'; // Dump the block and pass it a negative depth to we print all the parent blocks //if (block != NULL) // block->Dump(s, function->GetFileAddress(), INT_MIN); s->EOL(); s->Indent(); - *s << "LineEntry = "; + *s << "LineEntry = "; line_entry.Dump (s, process, true, Address::DumpStyleLoadAddress, Address::DumpStyleModuleWithFileAddress, true); s->EOL(); s->Indent(); - *s << "Symbol = " << (void *)symbol; + *s << "Symbol = " << (void *)symbol; if (symbol != NULL && symbol->GetMangled()) *s << ' ' << symbol->GetMangled().GetName().AsCString(); s->EOL(); @@ -313,7 +386,7 @@ if (module_sp != NULL) { SymbolContextList sc_matches; - if (module_sp->FindFunctions (name_const_str, false, sc_matches) > 0) + if (module_sp->FindFunctions (name_const_str, eFunctionNameTypeBase | eFunctionNameTypeFull, false, sc_matches) > 0) { SymbolContext sc; sc_matches.GetContextAtIndex (0, sc); @@ -324,7 +397,7 @@ if (target_sp) { SymbolContextList sc_matches; - if (target_sp->GetImages().FindFunctions (name_const_str, sc_matches) > 0) + if (target_sp->GetImages().FindFunctions (name_const_str, eFunctionNameTypeBase | eFunctionNameTypeFull, sc_matches) > 0) { SymbolContext sc; sc_matches.GetContextAtIndex (0, sc); Modified: lldb/trunk/source/Symbol/SymbolVendor.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/SymbolVendor.cpp?rev=107075&r1=107074&r2=107075&view=diff ============================================================================== --- lldb/trunk/source/Symbol/SymbolVendor.cpp (original) +++ lldb/trunk/source/Symbol/SymbolVendor.cpp Mon Jun 28 16:30:43 2010 @@ -234,11 +234,11 @@ } uint32_t -SymbolVendor::FindFunctions(const ConstString &name, bool append, SymbolContextList& sc_list) +SymbolVendor::FindFunctions(const ConstString &name, uint32_t name_type_mask, bool append, SymbolContextList& sc_list) { Mutex::Locker locker(m_mutex); if (m_sym_file_ap.get()) - return m_sym_file_ap->FindFunctions(name, append, sc_list); + return m_sym_file_ap->FindFunctions(name, name_type_mask, append, sc_list); return 0; } Modified: lldb/trunk/source/Symbol/Type.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/Type.cpp?rev=107075&r1=107074&r2=107075&view=diff ============================================================================== --- lldb/trunk/source/Symbol/Type.cpp (original) +++ lldb/trunk/source/Symbol/Type.cpp Mon Jun 28 16:30:43 2010 @@ -97,6 +97,81 @@ void +lldb_private::Type::GetDescription (Stream *s, lldb::DescriptionLevel level, bool show_name) +{ + if (show_name) + { + if (m_name) + *s << '\"' << m_name << "\", "; + } + + *s << "id = " << (const UserID&)*this; + + if (m_byte_size != 0) + s->Printf(", byte-size = %zu", m_byte_size); + + m_decl.Dump(s); + + clang::QualType qual_type(clang::QualType::getFromOpaquePtr(m_clang_qual_type)); + + if (qual_type.getTypePtr()) + { + *s << ", type = "; + + clang::TagType *tag_type = dyn_cast(qual_type.getTypePtr()); + clang::TagDecl *tag_decl = NULL; + if (tag_type) + tag_decl = tag_type->getDecl(); + + if (tag_decl) + { + s->EOL(); + s->EOL(); + tag_decl->print(llvm::fouts(), 0); + s->EOL(); + } + else + { + const clang::TypedefType *typedef_type = qual_type->getAs(); + if (typedef_type) + { + const clang::TypedefDecl *typedef_decl = typedef_type->getDecl(); + std::string clang_typedef_name (typedef_decl->getQualifiedNameAsString()); + if (!clang_typedef_name.empty()) + *s << ' ' << clang_typedef_name.c_str(); + } + else + { + // We have a clang type, lets show it + clang::ASTContext *ast_context = GetClangAST(); + if (ast_context) + { + std::string clang_type_name(qual_type.getAsString()); + if (!clang_type_name.empty()) + *s << ' ' << clang_type_name.c_str(); + } + } + } + } + else if (m_encoding_uid != LLDB_INVALID_UID) + { + *s << ", type_uid = " << m_encoding_uid; + switch (m_encoding_uid_type) + { + case eIsTypeWithUID: s->PutCString(" (unresolved type)"); break; + case eIsConstTypeWithUID: s->PutCString(" (unresolved const type)"); break; + case eIsRestrictTypeWithUID: s->PutCString(" (unresolved restrict type)"); break; + case eIsVolatileTypeWithUID: s->PutCString(" (unresolved volatile type)"); break; + case eTypedefToTypeWithUID: s->PutCString(" (unresolved typedef)"); break; + case ePointerToTypeWithUID: s->PutCString(" (unresolved pointer)"); break; + case eLValueReferenceToTypeWithUID: s->PutCString(" (unresolved L value reference)"); break; + case eRValueReferenceToTypeWithUID: s->PutCString(" (unresolved R value reference)"); break; + } + } +} + + +void lldb_private::Type::Dump (Stream *s, bool show_context) { s->Printf("%.*p: ", (int)sizeof(void*) * 2, this); @@ -148,16 +223,12 @@ else { // We have a clang type, lets show it - TypeList *type_list = GetTypeList(); - if (type_list) + clang::ASTContext *ast_context = GetClangAST(); + if (ast_context) { - clang::ASTContext *ast_context = GetClangAST(); - if (ast_context) - { - std::string clang_type_name(qual_type.getAsString()); - if (!clang_type_name.empty()) - *s << " (" << clang_type_name.c_str() << ')'; - } + std::string clang_type_name(qual_type.getAsString()); + if (!clang_type_name.empty()) + *s << " (" << clang_type_name.c_str() << ')'; } } } Modified: lldb/trunk/source/Target/Target.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Target.cpp?rev=107075&r1=107074&r2=107075&view=diff ============================================================================== --- lldb/trunk/source/Target/Target.cpp (original) +++ lldb/trunk/source/Target/Target.cpp Mon Jun 28 16:30:43 2010 @@ -179,11 +179,16 @@ } BreakpointSP -Target::CreateBreakpoint (FileSpec *containingModule, const char *func_name, bool internal) +Target::CreateBreakpoint (FileSpec *containingModule, const char *func_name, uint32_t func_name_type_mask, bool internal) { - SearchFilterSP filter_sp(GetSearchFilterForModule (containingModule)); - BreakpointResolverSP resolver_sp (new BreakpointResolverName (NULL, func_name)); - return CreateBreakpoint (filter_sp, resolver_sp, internal); + BreakpointSP bp_sp; + if (func_name) + { + SearchFilterSP filter_sp(GetSearchFilterForModule (containingModule)); + BreakpointResolverSP resolver_sp (new BreakpointResolverName (NULL, func_name, func_name_type_mask, Breakpoint::Exact)); + bp_sp = CreateBreakpoint (filter_sp, resolver_sp, internal); + } + return bp_sp; } Modified: lldb/trunk/tools/driver/Driver.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/driver/Driver.cpp?rev=107075&r1=107074&r2=107075&view=diff ============================================================================== --- lldb/trunk/tools/driver/Driver.cpp (original) +++ lldb/trunk/tools/driver/Driver.cpp Mon Jun 28 16:30:43 2010 @@ -49,13 +49,13 @@ static lldb::OptionDefinition g_options[] = { - { LLDB_OPT_SET_1, true, "help", 'h', no_argument, NULL, NULL, NULL, + { LLDB_OPT_SET_1, true, "help", 'h', no_argument, NULL, NULL, NULL, "Prints out the usage information for the LLDB debugger." }, - { LLDB_OPT_SET_2, true, "version", 'v', no_argument, NULL, NULL, NULL, + { LLDB_OPT_SET_2, true, "version", 'v', no_argument, NULL, NULL, NULL, "Prints out the current version number of the LLDB debugger." }, - { LLDB_OPT_SET_3, false, "arch", 'a', required_argument, NULL, NULL, "", + { LLDB_OPT_SET_3, true, "arch", 'a', required_argument, NULL, NULL, "", "Tells the debugger to use the specified architecture when starting and running the program. must be one of the architectures for which the program was compiled." }, { LLDB_OPT_SET_3 | LLDB_OPT_SET_4, false, "script-language",'l', required_argument, NULL, NULL, "", @@ -67,11 +67,11 @@ { LLDB_OPT_SET_3 | LLDB_OPT_SET_4, false, "source", 's', required_argument, NULL, NULL, "", "Tells the debugger to read in and execute the file , which should contain lldb commands." }, - { LLDB_OPT_SET_3, false, "file", 'f', required_argument, NULL, NULL, "", + { LLDB_OPT_SET_3, true, "file", 'f', required_argument, NULL, NULL, "", "Tells the debugger to use the file as the program to be debugged." }, - { LLDB_OPT_SET_4, false, "crash-log", 'c', required_argument, NULL, NULL, "", - "Load executable images from a crash log for symbolication." }, +// { LLDB_OPT_SET_4, true, "crash-log", 'c', required_argument, NULL, NULL, "", +// "Load executable images from a crash log for symbolication." }, { 0, false, NULL, 0, 0, NULL, NULL, NULL, NULL } }; From gclayton at apple.com Mon Jun 28 18:51:11 2010 From: gclayton at apple.com (Greg Clayton) Date: Mon, 28 Jun 2010 23:51:11 -0000 Subject: [Lldb-commits] [lldb] r107100 - in /lldb/trunk: include/lldb/Core/ModuleList.h include/lldb/Core/Section.h source/Commands/CommandObjectImage.cpp source/Core/ModuleList.cpp source/Core/Section.cpp source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp Message-ID: <20100628235112.10DDB2A6C12C@llvm.org> Author: gclayton Date: Mon Jun 28 18:51:11 2010 New Revision: 107100 URL: http://llvm.org/viewvc/llvm-project?rev=107100&view=rev Log: Fixed debug map in executable + DWARF in .o debugging on Mac OS X. Added the ability to dump any file in the global module cache using any of the "image dump" commands. This allows us to dump the .o files that are used with DWARF + .o since they don't belong the the target list for the current target. Modified: lldb/trunk/include/lldb/Core/ModuleList.h lldb/trunk/include/lldb/Core/Section.h lldb/trunk/source/Commands/CommandObjectImage.cpp lldb/trunk/source/Core/ModuleList.cpp lldb/trunk/source/Core/Section.cpp lldb/trunk/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp Modified: lldb/trunk/include/lldb/Core/ModuleList.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/ModuleList.h?rev=107100&r1=107099&r2=107100&view=diff ============================================================================== --- lldb/trunk/include/lldb/Core/ModuleList.h (original) +++ lldb/trunk/include/lldb/Core/ModuleList.h Mon Jun 28 18:51:11 2010 @@ -327,6 +327,13 @@ lldb::ModuleSP *old_module_sp_ptr, bool *did_create_ptr); + static size_t + FindSharedModules (const FileSpec& in_file_spec, + const ArchSpec& arch, + const UUID *uuid_ptr, + const ConstString *object_name_ptr, + ModuleList &matching_module_list); + protected: //------------------------------------------------------------------ // Class typedefs. Modified: lldb/trunk/include/lldb/Core/Section.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/Section.h?rev=107100&r1=107099&r2=107100&view=diff ============================================================================== --- lldb/trunk/include/lldb/Core/Section.h (original) +++ lldb/trunk/include/lldb/Core/Section.h Mon Jun 28 18:51:11 2010 @@ -51,9 +51,6 @@ lldb::SectionSP FindSectionByName (const ConstString §ion_dstr) const; -// lldb::SectionSP -// FindSectionByNames (const char *sect, ...) const; - lldb::SectionSP FindSectionByID (lldb::user_id_t sect_id) const; @@ -71,7 +68,10 @@ // Get the number of sections in this list only size_t - GetSize () const; + GetSize () const + { + return m_sections.size(); + } // Get the number of sections in this list, and any contained child sections size_t @@ -122,10 +122,16 @@ ContainsFileAddress (lldb::addr_t vm_addr) const; SectionList& - GetChildren (); + GetChildren () + { + return m_children; + } const SectionList& - GetChildren () const; + GetChildren () const + { + return m_children; + } void Dump (Stream *s, Process *process) const; @@ -140,31 +146,70 @@ ResolveContainedAddress (lldb::addr_t offset, Address &so_addr) const; uint64_t - GetFileOffset () const; + GetFileOffset () const + { + return m_file_offset; + } + + void + SetFileOffset (uint64_t file_offset) + { + m_file_offset = file_offset; + } uint64_t - GetFileSize () const; + GetFileSize () const + { + return m_file_size; + } + + void + SetFileSize (uint64_t file_size) + { + m_file_size = file_size; + } lldb::addr_t GetFileAddress () const; lldb::addr_t - GetOffset () const; + GetOffset () const + { + // This section has a parent which means m_file_addr is an offset. + if (m_parent) + return m_file_addr; - lldb::addr_t - GetByteSize () const; + // This section has no parent, so there is no offset to be had + return 0; + } - void - SetByteSize (lldb::addr_t byte_size); + lldb::addr_t + GetByteSize () const + { + return m_byte_size; + } + + void + SetByteSize (lldb::addr_t byte_size) + { + m_byte_size = byte_size; + } + size_t GetSectionDataFromImage (const DataExtractor& image_data, DataExtractor& section_data) const; bool - IsFake() const; + IsFake() const + { + return m_fake; + } void - SetIsFake(bool fake); + SetIsFake(bool fake) + { + m_fake = fake; + } bool IsDescendant (const Section *section); @@ -191,10 +236,16 @@ ContainsLinkedFileAddress (lldb::addr_t vm_addr) const; const Section * - GetLinkedSection () const; + GetLinkedSection () const + { + return m_linked_section; + } uint64_t - GetLinkedOffset () const; + GetLinkedOffset () const + { + return m_linked_offset; + } lldb::addr_t GetLinkedFileAddress () const; Modified: lldb/trunk/source/Commands/CommandObjectImage.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectImage.cpp?rev=107100&r1=107099&r2=107100&view=diff ============================================================================== --- lldb/trunk/source/Commands/CommandObjectImage.cpp (original) +++ lldb/trunk/source/Commands/CommandObjectImage.cpp Mon Jun 28 18:51:11 2010 @@ -544,8 +544,18 @@ { FileSpec image_file(arg_cstr); ModuleList matching_modules; - const size_t num_matching_modules = target->GetImages().FindModules(&image_file, NULL, NULL, NULL, matching_modules); + size_t num_matching_modules = target->GetImages().FindModules(&image_file, NULL, NULL, NULL, matching_modules); + // Not found in our module list for our target, check the main + // shared module list in case it is a extra file used somewhere + // else + if (num_matching_modules == 0) + num_matching_modules = ModuleList::FindSharedModules (image_file, + target->GetArchitecture(), + NULL, + NULL, + matching_modules); + if (num_matching_modules > 0) { for (size_t i=0; iGetImages().FindModules(&image_file, NULL, NULL, NULL, matching_modules); + size_t num_matching_modules = target->GetImages().FindModules(&image_file, NULL, NULL, NULL, matching_modules); + // Not found in our module list for our target, check the main + // shared module list in case it is a extra file used somewhere + // else + if (num_matching_modules == 0) + num_matching_modules = ModuleList::FindSharedModules (image_file, + target->GetArchitecture(), + NULL, + NULL, + matching_modules); + if (num_matching_modules > 0) { for (size_t i=0; iGetImages().FindModules(&image_file, NULL, NULL, NULL, matching_modules); + size_t num_matching_modules = target->GetImages().FindModules(&image_file, NULL, NULL, NULL, matching_modules); + // Not found in our module list for our target, check the main + // shared module list in case it is a extra file used somewhere + // else + if (num_matching_modules == 0) + num_matching_modules = ModuleList::FindSharedModules (image_file, + target->GetArchitecture(), + NULL, + NULL, + matching_modules); + if (num_matching_modules > 0) { for (size_t i=0; iGetImages().FindModules(&image_file, NULL, NULL, NULL, matching_modules); + size_t num_matching_modules = target->GetImages().FindModules(&image_file, NULL, NULL, NULL, matching_modules); + // Not found in our module list for our target, check the main + // shared module list in case it is a extra file used somewhere + // else + if (num_matching_modules == 0) + num_matching_modules = ModuleList::FindSharedModules (image_file, + target->GetArchitecture(), + NULL, + NULL, + matching_modules); + if (num_matching_modules > 0) { for (size_t i=0; iGetChildren().Slide (-slide_amount, false); segment->SetByteSize (curr_seg_max_addr - sect64_min_addr); } + + // Grow the section size as needed. + if (sect64.offset) + { + const lldb::addr_t segment_min_file_offset = segment->GetFileOffset(); + const lldb::addr_t segment_max_file_offset = segment_min_file_offset + segment->GetFileSize(); + + const lldb::addr_t section_min_file_offset = sect64.offset; + const lldb::addr_t section_max_file_offset = section_min_file_offset + sect64.size; + const lldb::addr_t new_file_offset = std::min (section_min_file_offset, segment_min_file_offset); + const lldb::addr_t new_file_size = std::max (section_max_file_offset, segment_max_file_offset) - new_file_offset; + segment->SetFileOffset (new_file_offset); + segment->SetFileSize (new_file_size); + } } else { From gclayton at apple.com Mon Jun 28 20:42:03 2010 From: gclayton at apple.com (Greg Clayton) Date: Tue, 29 Jun 2010 01:42:03 -0000 Subject: [Lldb-commits] [lldb] r107118 - /lldb/trunk/source/API/SBTarget.cpp Message-ID: <20100629014203.3DCDB2A6C12C@llvm.org> Author: gclayton Date: Mon Jun 28 20:42:03 2010 New Revision: 107118 URL: http://llvm.org/viewvc/llvm-project?rev=107118&view=rev Log: A little code cleanup to not create an script bridging object just to feed the private object back to another internal function. Modified: lldb/trunk/source/API/SBTarget.cpp Modified: lldb/trunk/source/API/SBTarget.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBTarget.cpp?rev=107118&r1=107117&r2=107118&view=diff ============================================================================== --- lldb/trunk/source/API/SBTarget.cpp (original) +++ lldb/trunk/source/API/SBTarget.cpp Mon Jun 28 20:42:03 2010 @@ -110,11 +110,8 @@ SBProcess sb_process; if (m_opaque_sp) - { - SBListener sb_listener (m_opaque_sp->GetDebugger().GetListener()); - if (sb_listener.IsValid()) - sb_process.SetProcess (m_opaque_sp->CreateProcess (*sb_listener)); - } + sb_process.SetProcess (m_opaque_sp->CreateProcess (m_opaque_sp->GetDebugger().GetListener())); + return sb_process; } From johnny.chen at apple.com Tue Jun 29 14:44:17 2010 From: johnny.chen at apple.com (Johnny Chen) Date: Tue, 29 Jun 2010 19:44:17 -0000 Subject: [Lldb-commits] [lldb] r107198 - in /lldb/trunk/test: dotest.py help/TestHelp.py Message-ID: <20100629194417.0E8352A6C12C@llvm.org> Author: johnny Date: Tue Jun 29 14:44:16 2010 New Revision: 107198 URL: http://llvm.org/viewvc/llvm-project?rev=107198&view=rev Log: For the time being, let's bracket the test runner within the lldb.SBDebugger.Initialize()/Terminate() pair. Change TestHelp.py to use synchronous debugging, which is easier to work with. Modified: lldb/trunk/test/dotest.py lldb/trunk/test/help/TestHelp.py Modified: lldb/trunk/test/dotest.py URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/dotest.py?rev=107198&r1=107197&r2=107198&view=diff ============================================================================== --- lldb/trunk/test/dotest.py (original) +++ lldb/trunk/test/dotest.py Tue Jun 29 14:44:16 2010 @@ -129,4 +129,12 @@ os.path.walk(testdir, visit, 'Test') # Now that we have loaded all the test cases, run the whole test suite. + +# For the time being, let's bracket the test runner within the +# lldb.SBDebugger.Initialize()/Terminate() pair. +import lldb +lldb.SBDebugger.Initialize() + unittest.TextTestRunner(verbosity=verbose).run(suite) + +lldb.SBDebugger.Terminate() Modified: lldb/trunk/test/help/TestHelp.py URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/help/TestHelp.py?rev=107198&r1=107197&r2=107198&view=diff ============================================================================== --- lldb/trunk/test/help/TestHelp.py (original) +++ lldb/trunk/test/help/TestHelp.py Tue Jun 29 14:44:16 2010 @@ -7,7 +7,7 @@ def setUp(self): self.debugger = lldb.SBDebugger.Create() - self.debugger.SetAsync(True) + self.debugger.SetAsync(False) self.ci = self.debugger.GetCommandInterpreter() if not self.ci: raise Exception('Could not get the command interpreter') @@ -37,4 +37,6 @@ if __name__ == '__main__': + lldb.SBDebugger.Initialize() unittest.main() + lldb.SBDebugger.Terminate() From johnny.chen at apple.com Tue Jun 29 18:10:39 2010 From: johnny.chen at apple.com (Johnny Chen) Date: Tue, 29 Jun 2010 23:10:39 -0000 Subject: [Lldb-commits] [lldb] r107220 - in /lldb/trunk/test: array_types/TestArrayTypes.py array_types/main.c dotest.py help/TestHelp.py Message-ID: <20100629231039.C8D672A6C12C@llvm.org> Author: johnny Date: Tue Jun 29 18:10:39 2010 New Revision: 107220 URL: http://llvm.org/viewvc/llvm-project?rev=107220&view=rev Log: Added TestArrayTypes.py for test/array_types directory. Also modified dotest.py so that it sets the LLDB_TEST environment variable so that individual test cases can locate their supporting files correctly. Added: lldb/trunk/test/array_types/TestArrayTypes.py Modified: lldb/trunk/test/array_types/main.c lldb/trunk/test/dotest.py lldb/trunk/test/help/TestHelp.py Added: lldb/trunk/test/array_types/TestArrayTypes.py URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/array_types/TestArrayTypes.py?rev=107220&view=auto ============================================================================== --- lldb/trunk/test/array_types/TestArrayTypes.py (added) +++ lldb/trunk/test/array_types/TestArrayTypes.py Tue Jun 29 18:10:39 2010 @@ -0,0 +1,79 @@ +"""Test breakpoint by file/line number; and list variables with array types.""" + +import os +import lldb +import unittest + +class TestArrayTypes(unittest.TestCase): + + def setUp(self): + # Save old working directory. + self.oldcwd = os.getcwd() + # Change current working directory if ${LLDB_TEST} is defined. + if ("LLDB_TEST" in os.environ): + os.chdir(os.path.join(os.environ["LLDB_TEST"], "array_types")); + self.dbg = lldb.SBDebugger.Create() + self.dbg.SetAsync(False) + self.ci = self.dbg.GetCommandInterpreter() + if not self.ci: + raise Exception('Could not get the command interpreter') + + def tearDown(self): + # Restore old working directory. + os.chdir(self.oldcwd) + + def test_array_types(self): + """Test 'variable list var_name' on some variables with array types.""" + res = lldb.SBCommandReturnObject() + self.ci.HandleCommand("file a.out", res) + self.assertTrue(res.Succeeded()) + self.ci.HandleCommand("breakpoint set -f main.c -l 42", res) + self.assertTrue(res.Succeeded()) + self.assertTrue(res.GetOutput().startswith( + "Breakpoint created: 1: file ='main.c', line = 42, locations = 1")) + + self.ci.HandleCommand("run", res) + self.assertTrue(res.Succeeded()) + + self.ci.HandleCommand("breakpoint list", res) + self.assertTrue(res.Succeeded()) + self.assertTrue(res.GetOutput().find('resolved, hit count = 1')) + + self.ci.HandleCommand("thread list", res) + self.assertTrue(res.Succeeded()) + self.assertTrue(res.GetOutput().find('state is Stopped') and + res.GetOutput().find('stop reason = breakpoint')) + + self.ci.HandleCommand("variable list strings", res); + self.assertTrue(res.Succeeded()) + self.assertTrue(res.GetOutput().startswith('(char *[4])') and + res.GetOutput().find('(char *) strings[0]') and + res.GetOutput().find('(char *) strings[1]') and + res.GetOutput().find('(char *) strings[2]') and + res.GetOutput().find('(char *) strings[3]') and + res.GetOutput().find('Hello') and + res.GetOutput().find('Hola') and + res.GetOutput().find('Bonjour') and + res.GetOutput().find('Guten Tag')) + + self.ci.HandleCommand("variable list char_16", res); + self.assertTrue(res.Succeeded()) + self.assertTrue(res.GetOutput().find('(char) char_16[0]') and + res.GetOutput().find('(char) char_16[15]')) + + self.ci.HandleCommand("variable list ushort_matrix", res); + self.assertTrue(res.Succeeded()) + self.assertTrue(res.GetOutput().startswith('(unsigned short [2][3])')) + + self.ci.HandleCommand("variable list long_6", res); + self.assertTrue(res.Succeeded()) + self.assertTrue(res.GetOutput().startswith('(long [6])')) + + self.ci.HandleCommand("continue", res) + self.assertTrue(res.Succeeded()) + + +if __name__ == '__main__': + lldb.SBDebugger.Initialize() + unittest.main() + lldb.SBDebugger.Terminate() Modified: lldb/trunk/test/array_types/main.c URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/array_types/main.c?rev=107220&r1=107219&r2=107220&view=diff ============================================================================== --- lldb/trunk/test/array_types/main.c (original) +++ lldb/trunk/test/array_types/main.c Tue Jun 29 18:10:39 2010 @@ -27,7 +27,7 @@ short short_4[4] = { 1,2,3,4 }; short short_matrix[1][2] = { {1,2} }; unsigned short ushort_4[4] = { 1,2,3,4 }; - short ushort_matrix[2][3] = { + unsigned short ushort_matrix[2][3] = { { 1, 2, 3}, {11,22,33} }; Modified: lldb/trunk/test/dotest.py URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/dotest.py?rev=107220&r1=107219&r2=107220&view=diff ============================================================================== --- lldb/trunk/test/dotest.py (original) +++ lldb/trunk/test/dotest.py Tue Jun 29 18:10:39 2010 @@ -42,6 +42,9 @@ and: args : specify a list of directory names to search for python Test*.py scripts if empty, search from the curret working directory, instead + +Running of this script also sets up the LLDB_TEST environment variable so that +individual test cases can locate their supporting files correctly. """ @@ -54,6 +57,8 @@ print "This script expects to reside in lldb's test directory." sys.exit(-1) + os.environ["LLDB_TEST"] = testPath + base = os.path.abspath(os.path.join(testPath, os.pardir)) dbgPath = os.path.join(base, 'build', 'Debug', 'LLDB.framework', 'Resources', 'Python') Modified: lldb/trunk/test/help/TestHelp.py URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/help/TestHelp.py?rev=107220&r1=107219&r2=107220&view=diff ============================================================================== --- lldb/trunk/test/help/TestHelp.py (original) +++ lldb/trunk/test/help/TestHelp.py Tue Jun 29 18:10:39 2010 @@ -1,19 +1,26 @@ """Test lldb help command.""" +import os import lldb import unittest class TestHelpCommand(unittest.TestCase): def setUp(self): - self.debugger = lldb.SBDebugger.Create() - self.debugger.SetAsync(False) - self.ci = self.debugger.GetCommandInterpreter() + # Save old working directory. + self.oldcwd = os.getcwd() + # Change current working directory if ${LLDB_TEST} is defined. + if ("LLDB_TEST" in os.environ): + os.chdir(os.path.join(os.environ["LLDB_TEST"], "help")); + self.dbg = lldb.SBDebugger.Create() + self.dbg.SetAsync(False) + self.ci = self.dbg.GetCommandInterpreter() if not self.ci: raise Exception('Could not get the command interpreter') def tearDown(self): - pass + # Restore old working directory. + os.chdir(self.oldcwd) def test_simplehelp(self): """A simple test of 'help' command and its output.""" @@ -22,7 +29,6 @@ self.assertTrue(res.Succeeded()) self.assertTrue(res.GetOutput().startswith( 'The following is a list of built-in, permanent debugger commands')) - #print res.GetOutput() def test_help_should_not_hang_emacsshell(self): """'set term-width 0' should not hang the help command.""" @@ -33,7 +39,6 @@ self.assertTrue(res.Succeeded()) self.assertTrue(res.GetOutput().startswith( 'The following is a list of built-in, permanent debugger commands')) - #print res.GetOutput() if __name__ == '__main__': From johnny.chen at apple.com Tue Jun 29 18:17:15 2010 From: johnny.chen at apple.com (Johnny Chen) Date: Tue, 29 Jun 2010 23:17:15 -0000 Subject: [Lldb-commits] [lldb] r107221 - in /lldb/trunk/test: dotest.py help/TestHelp.py Message-ID: <20100629231715.F2ED02A6C12C@llvm.org> Author: johnny Date: Tue Jun 29 18:17:15 2010 New Revision: 107221 URL: http://llvm.org/viewvc/llvm-project?rev=107221&view=rev Log: Add some delay before calling SBDebugger.Terminate(). Modified: lldb/trunk/test/dotest.py lldb/trunk/test/help/TestHelp.py Modified: lldb/trunk/test/dotest.py URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/dotest.py?rev=107221&r1=107220&r2=107221&view=diff ============================================================================== --- lldb/trunk/test/dotest.py (original) +++ lldb/trunk/test/dotest.py Tue Jun 29 18:17:15 2010 @@ -16,6 +16,7 @@ import os import sys +import time import unittest # @@ -142,4 +143,6 @@ unittest.TextTestRunner(verbosity=verbose).run(suite) +# Add some delay before calling SBDebugger.Terminate(). +time.sleep(1) lldb.SBDebugger.Terminate() Modified: lldb/trunk/test/help/TestHelp.py URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/help/TestHelp.py?rev=107221&r1=107220&r2=107221&view=diff ============================================================================== --- lldb/trunk/test/help/TestHelp.py (original) +++ lldb/trunk/test/help/TestHelp.py Tue Jun 29 18:17:15 2010 @@ -31,7 +31,7 @@ 'The following is a list of built-in, permanent debugger commands')) def test_help_should_not_hang_emacsshell(self): - """'set term-width 0' should not hang the help command.""" + """Command 'set term-width 0' should not hang the help command.""" res = lldb.SBCommandReturnObject() self.ci.HandleCommand("set term-width 0", res) self.assertTrue(res.Succeeded()) From jingham at apple.com Wed Jun 30 00:02:46 2010 From: jingham at apple.com (Jim Ingham) Date: Wed, 30 Jun 2010 05:02:46 -0000 Subject: [Lldb-commits] [lldb] r107247 - in /lldb/trunk: include/lldb/Interpreter/ source/Commands/ source/Interpreter/ Message-ID: <20100630050246.AC78B2A6C12C@llvm.org> Author: jingham Date: Wed Jun 30 00:02:46 2010 New Revision: 107247 URL: http://llvm.org/viewvc/llvm-project?rev=107247&view=rev Log: Add a source file completer to the CommandCompleters. Add a way for the completers to say whether the completed argument should have a space inserted after is or not. Added the file name completer to the "file" command. Modified: lldb/trunk/include/lldb/Interpreter/CommandCompletions.h lldb/trunk/include/lldb/Interpreter/CommandInterpreter.h lldb/trunk/include/lldb/Interpreter/CommandObject.h lldb/trunk/include/lldb/Interpreter/CommandObjectMultiword.h lldb/trunk/include/lldb/Interpreter/Options.h lldb/trunk/source/Commands/CommandCompletions.cpp lldb/trunk/source/Commands/CommandObjectFile.cpp lldb/trunk/source/Commands/CommandObjectFile.h lldb/trunk/source/Commands/CommandObjectHelp.cpp lldb/trunk/source/Commands/CommandObjectHelp.h lldb/trunk/source/Commands/CommandObjectImage.cpp lldb/trunk/source/Commands/CommandObjectMultiword.cpp lldb/trunk/source/Interpreter/CommandInterpreter.cpp lldb/trunk/source/Interpreter/CommandObject.cpp lldb/trunk/source/Interpreter/Options.cpp Modified: lldb/trunk/include/lldb/Interpreter/CommandCompletions.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Interpreter/CommandCompletions.h?rev=107247&r1=107246&r2=107247&view=diff ============================================================================== --- lldb/trunk/include/lldb/Interpreter/CommandCompletions.h (original) +++ lldb/trunk/include/lldb/Interpreter/CommandCompletions.h Wed Jun 30 00:02:46 2010 @@ -34,15 +34,17 @@ int match_start_point, // This is the point in the list of matches that you should start returning elements int max_return_elements, // This is the number of matches requested. lldb_private::SearchFilter *searcher,// A search filter to limit the search... + bool &word_complete, lldb_private::StringList &matches); // The array of matches we return. typedef enum { - eNoCompletion = 0, - eSourceFileCompletion = (1 << 0), - eDiskFileCompletion = (1 << 1), - eSymbolCompletion = (1 << 2), - eModuleCompletion = (1 << 3), - eCustomCompletion = (1 << 4) // This item serves two purposes. It is the last element in the enum, + eNoCompletion = 0, + eSourceFileCompletion = (1 << 0), + eDiskFileCompletion = (1 << 1), + eDiskDirectoryCompletion = (1 << 2), + eSymbolCompletion = (1 << 3), + eModuleCompletion = (1 << 4), + eCustomCompletion = (1 << 5) // This item serves two purposes. It is the last element in the enum, // so you can add custom enums starting from here in your Option class. // Also if you & in this bit the base code will not process the option. @@ -60,17 +62,36 @@ int match_start_point, int max_return_elements, SearchFilter *searcher, + bool &word_complete, StringList &matches); //---------------------------------------------------------------------- // These are the generic completer functions: //---------------------------------------------------------------------- static int + DiskFiles (CommandInterpreter &interpreter, + const char *partial_file_name, + int match_start_point, + int max_return_elements, + SearchFilter *searcher, + bool &word_complete, + StringList &matches); + static int + DiskDirectories (CommandInterpreter &interpreter, + const char *partial_file_name, + int match_start_point, + int max_return_elements, + SearchFilter *searcher, + bool &word_complete, + StringList &matches); + + static int SourceFiles (CommandInterpreter &interpreter, const char *partial_file_name, int match_start_point, int max_return_elements, SearchFilter *searcher, + bool &word_complete, StringList &matches); static int @@ -79,6 +100,7 @@ int match_start_point, int max_return_elements, SearchFilter *searcher, + bool &word_complete, lldb_private::StringList &matches); static int @@ -87,6 +109,7 @@ int match_start_point, int max_return_elements, SearchFilter *searcher, + bool &word_complete, lldb_private::StringList &matches); //---------------------------------------------------------------------- Modified: lldb/trunk/include/lldb/Interpreter/CommandInterpreter.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Interpreter/CommandInterpreter.h?rev=107247&r1=107246&r2=107247&view=diff ============================================================================== --- lldb/trunk/include/lldb/Interpreter/CommandInterpreter.h (original) +++ lldb/trunk/include/lldb/Interpreter/CommandInterpreter.h Wed Jun 30 00:02:46 2010 @@ -116,6 +116,8 @@ // This version just returns matches, and doesn't compute the substring. It is here so the // Help command can call it for the first argument. + // word_complete tells whether a the completions are considered a "complete" response (so the + // completer should complete the quote & put a space after the word. int HandleCompletionMatches (Args &input, @@ -123,6 +125,7 @@ int &cursor_char_position, int match_start_point, int max_return_elements, + bool &word_complete, StringList &matches); Modified: lldb/trunk/include/lldb/Interpreter/CommandObject.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Interpreter/CommandObject.h?rev=107247&r1=107246&r2=107247&view=diff ============================================================================== --- lldb/trunk/include/lldb/Interpreter/CommandObject.h (original) +++ lldb/trunk/include/lldb/Interpreter/CommandObject.h Wed Jun 30 00:02:46 2010 @@ -122,13 +122,46 @@ static int AddNamesMatchingPartialString (CommandMap &in_map, const char *cmd_str, StringList &matches); - // The input array contains a parsed version of the line. The insertion - // point is given by cursor_index (the index in input of the word containing - // the cursor) and cursor_char_position (the position of the cursor in that word.) - // This default version handles calling option argument completions and then calls - // HandleArgumentCompletion if the cursor is on an argument, not an option. - // Don't override this method, override HandleArgumentCompletion instead unless - // you have special reasons. + //------------------------------------------------------------------ + /// The input array contains a parsed version of the line. The insertion + /// point is given by cursor_index (the index in input of the word containing + /// the cursor) and cursor_char_position (the position of the cursor in that word.) + /// This default version handles calling option argument completions and then calls + /// HandleArgumentCompletion if the cursor is on an argument, not an option. + /// Don't override this method, override HandleArgumentCompletion instead unless + /// you have special reasons. + /// + /// @param[in] interpreter + /// The command interpreter doing the completion. + /// + /// @param[in] input + /// The command line parsed into words + /// + /// @param[in] cursor_index + /// The index in \ainput of the word in which the cursor lies. + /// + /// @param[in] cursor_char_pos + /// The character position of the cursor in its argument word. + /// + /// @param[in] match_start_point + /// @param[in] match_return_elements + /// FIXME: Not yet implemented... If there is a match that is expensive to compute, these are + /// here to allow you to compute the completions in batches. Start the completion from \amatch_start_point, + /// and return \amatch_return_elements elements. + /// + /// @param[out] word_complete + /// \btrue if this is a complete option value (a space will be inserted after the + /// completion.) \bfalse otherwise. + /// + /// @param[out] matches + /// The array of matches returned. + /// + /// FIXME: This is the wrong return value, since we also need to make a distinction between + /// total number of matches, and the window the user wants returned. + /// + /// @return + /// \btrue if we were in an option, \bfalse otherwise. + //------------------------------------------------------------------ virtual int HandleCompletion (CommandInterpreter &interpreter, Args &input, @@ -136,13 +169,48 @@ int &cursor_char_position, int match_start_point, int max_return_elements, + bool &word_complete, StringList &matches); - // The input array contains a parsed version of the line. The insertion - // point is given by cursor_index (the index in input of the word containing - // the cursor) and cursor_char_position (the position of the cursor in that word.) - // We've constructed the map of options and their arguments as well if that is - // helpful for the completion. + //------------------------------------------------------------------ + /// The input array contains a parsed version of the line. The insertion + /// point is given by cursor_index (the index in input of the word containing + /// the cursor) and cursor_char_position (the position of the cursor in that word.) + /// We've constructed the map of options and their arguments as well if that is + /// helpful for the completion. + /// + /// @param[in] interpreter + /// The command interpreter doing the completion. + /// + /// @param[in] input + /// The command line parsed into words + /// + /// @param[in] cursor_index + /// The index in \ainput of the word in which the cursor lies. + /// + /// @param[in] cursor_char_pos + /// The character position of the cursor in its argument word. + /// + /// @param[in] opt_element_vector + /// The results of the options parse of \a input. + /// + /// @param[in] match_start_point + /// @param[in] match_return_elements + /// See CommandObject::HandleCompletions for a description of how these work. + /// + /// @param[out] word_complete + /// \btrue if this is a complete option value (a space will be inserted after the + /// completion.) \bfalse otherwise. + /// + /// @param[out] matches + /// The array of matches returned. + /// + /// FIXME: This is the wrong return value, since we also need to make a distinction between + /// total number of matches, and the window the user wants returned. + /// + /// @return + /// \btrue if we were in an option, \bfalse otherwise. + //------------------------------------------------------------------ virtual int HandleArgumentCompletion (CommandInterpreter &interpreter, @@ -152,6 +220,7 @@ OptionElementVector &opt_element_vector, int match_start_point, int max_return_elements, + bool &word_complete, StringList &matches) { return 0; Modified: lldb/trunk/include/lldb/Interpreter/CommandObjectMultiword.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Interpreter/CommandObjectMultiword.h?rev=107247&r1=107246&r2=107247&view=diff ============================================================================== --- lldb/trunk/include/lldb/Interpreter/CommandObjectMultiword.h (original) +++ lldb/trunk/include/lldb/Interpreter/CommandObjectMultiword.h Wed Jun 30 00:02:46 2010 @@ -64,6 +64,7 @@ int &cursor_char_position, int match_start_point, int max_return_elements, + bool &word_complete, StringList &matches); CommandObject::CommandMap m_subcommand_dict; Modified: lldb/trunk/include/lldb/Interpreter/Options.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Interpreter/Options.h?rev=107247&r1=107246&r2=107247&view=diff ============================================================================== --- lldb/trunk/include/lldb/Interpreter/Options.h (original) +++ lldb/trunk/include/lldb/Interpreter/Options.h Wed Jun 30 00:02:46 2010 @@ -208,6 +208,10 @@ /// @param[in] interpreter /// The interpreter that's doing the completing. /// + /// @param[out] word_complete + /// \btrue if this is a complete option value (a space will be inserted after the + /// completion.) \bfalse otherwise. + /// /// @param[out] matches /// The array of matches returned. /// @@ -225,12 +229,16 @@ int char_pos, int match_start_point, int max_return_elements, + bool &word_complete, lldb_private::StringList &matches); //------------------------------------------------------------------ /// Handles the generic bits of figuring out whether we are in an option, and if so completing /// it. /// + /// @param[in] interpreter + /// The command interpreter doing the completion. + /// /// @param[in] input /// The command line parsed into words /// @@ -250,8 +258,9 @@ /// @param[in] match_return_elements /// See CommandObject::HandleCompletions for a description of how these work. /// - /// @param[in] interpreter - /// The interpreter that's doing the completing. + /// @param[out] word_complete + /// \btrue if this is a complete option value (a space will be inserted after the + /// completion.) \bfalse otherwise. /// /// @param[out] matches /// The array of matches returned. @@ -271,6 +280,7 @@ int opt_element_index, int match_start_point, int max_return_elements, + bool &word_complete, StringList &matches); protected: Modified: lldb/trunk/source/Commands/CommandCompletions.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandCompletions.cpp?rev=107247&r1=107246&r2=107247&view=diff ============================================================================== --- lldb/trunk/source/Commands/CommandCompletions.cpp (original) +++ lldb/trunk/source/Commands/CommandCompletions.cpp Wed Jun 30 00:02:46 2010 @@ -9,6 +9,11 @@ // C Includes +#include +#include +#include +#include + // C++ Includes // Other libraries and framework includes // Project includes @@ -24,12 +29,13 @@ CommandCompletions::CommonCompletionElement CommandCompletions::g_common_completions[] = { - {eCustomCompletion, NULL}, - {eSourceFileCompletion, CommandCompletions::SourceFiles}, - {eDiskFileCompletion, NULL}, - {eSymbolCompletion, CommandCompletions::Symbols}, - {eModuleCompletion, CommandCompletions::Modules}, - {eNoCompletion, NULL} // This one has to be last in the list. + {eCustomCompletion, NULL}, + {eSourceFileCompletion, CommandCompletions::SourceFiles}, + {eDiskFileCompletion, CommandCompletions::DiskFiles}, + {eDiskDirectoryCompletion, CommandCompletions::DiskDirectories}, + {eSymbolCompletion, CommandCompletions::Symbols}, + {eModuleCompletion, CommandCompletions::Modules}, + {eNoCompletion, NULL} // This one has to be last in the list. }; bool @@ -41,6 +47,7 @@ int match_start_point, int max_return_elements, SearchFilter *searcher, + bool &word_complete, StringList &matches ) { @@ -62,6 +69,7 @@ match_start_point, max_return_elements, searcher, + word_complete, matches); } } @@ -76,9 +84,11 @@ int match_start_point, int max_return_elements, SearchFilter *searcher, + bool &word_complete, StringList &matches ) { + word_complete = true; // Find some way to switch "include support files..." SourceFileCompleter completer (interpreter, false, @@ -100,6 +110,216 @@ return matches.GetSize(); } +static int +DiskFilesOrDirectories +( + const char *partial_file_name, + bool only_directories, + bool &saw_directory, + StringList &matches +) +{ + // I'm going to use the "glob" function with GLOB_TILDE for user directory expansion. + // If it is not defined on your host system, you'll need to implement it yourself... + + int partial_name_len = strlen(partial_file_name); + + if (partial_name_len >= PATH_MAX) + return matches.GetSize(); + + // This copy of the string will be cut up into the directory part, and the remainder. end_ptr + // below will point to the place of the remainder in this string. Then when we've resolved the + // containing directory, and opened it, we'll read the directory contents and overwrite the + // partial_name_copy starting from end_ptr with each of the matches. Thus we will preserve + // the form the user originally typed. + + char partial_name_copy[PATH_MAX]; + bcopy (partial_file_name, partial_name_copy, partial_name_len); + partial_name_copy[partial_name_len] = '\0'; + + // We'll need to save a copy of the remainder for comparision, which we do here. + char remainder[PATH_MAX]; + + // end_ptr will point past the last / in partial_name_copy, or if there is no slash to the beginning of the string. + char *end_ptr; + + end_ptr = strrchr(partial_name_copy, '/'); + + // This will store the resolved form of the containing directory + char containing_part[PATH_MAX]; + + if (end_ptr == NULL) + { + // There's no directory. If the thing begins with a "~" then this is a bare + // user name. + if (*partial_name_copy == '~') + { + // Nothing here but the user name. We could just put a slash on the end, + // but for completeness sake we'll glob the user name and only put a slash + // on the end if it exists. + glob_t glob_buf; + if (glob (partial_name_copy, GLOB_TILDE, NULL, &glob_buf) != 0) + return matches.GetSize(); + + //The thing exists, put a '/' on the end, and return it... + // FIXME: complete user names here: + partial_name_copy[partial_name_len] = '/'; + partial_name_copy[partial_name_len+1] = '\0'; + matches.AppendString(partial_name_copy); + globfree(&glob_buf); + saw_directory == true; + return matches.GetSize(); + } + else + { + // The containing part is the CWD, and the whole string is the remainder. + containing_part[0] = '.'; + containing_part[1] = '\0'; + strcpy(remainder, partial_name_copy); + end_ptr = partial_name_copy; + } + } + else + { + if (end_ptr == partial_name_copy) + { + // We're completing a file or directory in the root volume. + containing_part[0] = '/'; + containing_part[1] = '\0'; + } + else + { + size_t len = end_ptr - partial_name_copy; + memcpy(containing_part, partial_name_copy, len); + containing_part[len] = '\0'; + } + // Push end_ptr past the final "/" and set remainder. + end_ptr++; + strcpy(remainder, end_ptr); + } + + // Look for a user name in the containing part, and if it's there, glob containing_part and stick the + // result back into the containing_part: + + if (*partial_name_copy == '~') + { + glob_t glob_buf; + + // User name doesn't exist, we're not getting any further... + if (glob (containing_part, GLOB_TILDE, NULL, &glob_buf) != 0) + return matches.GetSize(); + + if (glob_buf.gl_pathc != 1) + { + // I'm not really sure how this would happen? + globfree(&glob_buf); + return matches.GetSize(); + } + strcpy(containing_part, glob_buf.gl_pathv[0]); + globfree(&glob_buf); + } + + // Okay, containing_part is now the directory we want to open and look for files: + + DIR *dir_stream; + + dir_stream = opendir(containing_part); + if (dir_stream == NULL) + return matches.GetSize(); + + struct dirent *dirent_buf; + + size_t baselen = end_ptr - partial_name_copy; + + while ((dirent_buf = readdir(dir_stream)) != NULL) + { + char *name = dirent_buf->d_name; + + // Omit ".", ".." and any . files if the match string doesn't start with . + if (name[0] == '.') + { + if (name[1] == '\0') + continue; + else if (name[1] == '.' && name[2] == '\0') + continue; + else if (remainder[0] != '.') + continue; + } + + if (remainder[0] == '\0' || strstr(dirent_buf->d_name, remainder) == name) + { + if (strlen(name) + baselen >= PATH_MAX) + continue; + + strcpy(end_ptr, name); + + bool isa_directory = false; + if (dirent_buf->d_type & DT_DIR) + isa_directory = true; + else if (dirent_buf->d_type & DT_LNK) + { + struct stat stat_buf; + if ((stat(partial_name_copy, &stat_buf) == 0) && (stat_buf.st_mode & S_IFDIR)) + isa_directory = true; + } + + if (isa_directory) + { + saw_directory = true; + size_t len = strlen(partial_name_copy); + partial_name_copy[len] = '/'; + partial_name_copy[len + 1] = '\0'; + } + if (only_directories && !isa_directory) + continue; + matches.AppendString(partial_name_copy); + } + } + + return matches.GetSize(); +} + +int +CommandCompletions::DiskFiles +( + CommandInterpreter &interpreter, + const char *partial_file_name, + int match_start_point, + int max_return_elements, + SearchFilter *searcher, + bool &word_complete, + StringList &matches +) +{ + + int ret_val = DiskFilesOrDirectories (partial_file_name, + false, + word_complete, + matches); + word_complete = !word_complete; + return ret_val; +} + +int +CommandCompletions::DiskDirectories +( + CommandInterpreter &interpreter, + const char *partial_file_name, + int match_start_point, + int max_return_elements, + SearchFilter *searcher, + bool &word_complete, + StringList &matches +) +{ + int ret_val = DiskFilesOrDirectories (partial_file_name, + true, + word_complete, + matches); + word_complete = false; + return ret_val; +} + int CommandCompletions::Modules ( @@ -108,9 +328,11 @@ int match_start_point, int max_return_elements, SearchFilter *searcher, + bool &word_complete, StringList &matches ) { + word_complete = true; ModuleCompleter completer (interpreter, partial_file_name, match_start_point, @@ -138,8 +360,10 @@ int match_start_point, int max_return_elements, SearchFilter *searcher, + bool &word_complete, StringList &matches) { + word_complete = true; SymbolCompleter completer (interpreter, partial_file_name, match_start_point, Modified: lldb/trunk/source/Commands/CommandObjectFile.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectFile.cpp?rev=107247&r1=107246&r2=107247&view=diff ============================================================================== --- lldb/trunk/source/Commands/CommandObjectFile.cpp (original) +++ lldb/trunk/source/Commands/CommandObjectFile.cpp Wed Jun 30 00:02:46 2010 @@ -19,6 +19,7 @@ #include "lldb/Core/Debugger.h" #include "lldb/Interpreter/CommandInterpreter.h" #include "lldb/Interpreter/CommandReturnObject.h" +#include "lldb/Interpreter/CommandCompletions.h" #include "lldb/Target/Process.h" using namespace lldb; @@ -166,3 +167,29 @@ return result.Succeeded(); } + +int +CommandObjectFile::HandleArgumentCompletion (CommandInterpreter &interpreter, + Args &input, + int &cursor_index, + int &cursor_char_position, + OptionElementVector &opt_element_vector, + int match_start_point, + int max_return_elements, + bool &word_complete, + StringList &matches) +{ + std::string completion_str (input.GetArgumentAtIndex(cursor_index)); + completion_str.erase (cursor_char_position); + + CommandCompletions::InvokeCommonCompletionCallbacks (interpreter, + CommandCompletions::eDiskFileCompletion, + completion_str.c_str(), + match_start_point, + max_return_elements, + NULL, + word_complete, + matches); + return matches.GetSize(); + +} \ No newline at end of file Modified: lldb/trunk/source/Commands/CommandObjectFile.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectFile.h?rev=107247&r1=107246&r2=107247&view=diff ============================================================================== --- lldb/trunk/source/Commands/CommandObjectFile.h (original) +++ lldb/trunk/source/Commands/CommandObjectFile.h Wed Jun 30 00:02:46 2010 @@ -67,6 +67,18 @@ ArchSpec m_arch; }; + + virtual int + HandleArgumentCompletion (CommandInterpreter &interpreter, + Args &input, + int &cursor_index, + int &cursor_char_position, + OptionElementVector &opt_element_vector, + int match_start_point, + int max_return_elements, + bool &word_complete, + StringList &matches); + private: CommandOptions m_options; Modified: lldb/trunk/source/Commands/CommandObjectHelp.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectHelp.cpp?rev=107247&r1=107246&r2=107247&view=diff ============================================================================== --- lldb/trunk/source/Commands/CommandObjectHelp.cpp (original) +++ lldb/trunk/source/Commands/CommandObjectHelp.cpp Wed Jun 30 00:02:46 2010 @@ -144,19 +144,22 @@ int &cursor_char_position, int match_start_point, int max_return_elements, + bool &word_complete, StringList &matches ) { // Return the completions of the commands in the help system: if (cursor_index == 0) { - return interpreter.HandleCompletionMatches(input, cursor_index, cursor_char_position, match_start_point, max_return_elements, matches); + return interpreter.HandleCompletionMatches(input, cursor_index, cursor_char_position, match_start_point, + max_return_elements, word_complete, matches); } else { CommandObject *cmd_obj = interpreter.GetCommandObject (input.GetArgumentAtIndex(0), true, false); input.Shift(); cursor_index--; - return cmd_obj->HandleCompletion (interpreter, input, cursor_index, cursor_char_position, match_start_point, max_return_elements, matches); + return cmd_obj->HandleCompletion (interpreter, input, cursor_index, cursor_char_position, match_start_point, + max_return_elements, word_complete, matches); } } Modified: lldb/trunk/source/Commands/CommandObjectHelp.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectHelp.h?rev=107247&r1=107246&r2=107247&view=diff ============================================================================== --- lldb/trunk/source/Commands/CommandObjectHelp.h (original) +++ lldb/trunk/source/Commands/CommandObjectHelp.h Wed Jun 30 00:02:46 2010 @@ -43,6 +43,7 @@ int &cursor_char_position, int match_start_point, int max_return_elements, + bool &word_complete, StringList &matches); }; Modified: lldb/trunk/source/Commands/CommandObjectImage.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectImage.cpp?rev=107247&r1=107246&r2=107247&view=diff ============================================================================== --- lldb/trunk/source/Commands/CommandObjectImage.cpp (original) +++ lldb/trunk/source/Commands/CommandObjectImage.cpp Wed Jun 30 00:02:46 2010 @@ -422,6 +422,7 @@ OptionElementVector &opt_element_vector, int match_start_point, int max_return_elements, + bool &word_complete, StringList &matches) { // Arguments are the standard module completer. @@ -434,6 +435,7 @@ match_start_point, max_return_elements, NULL, + word_complete, matches); return matches.GetSize(); } @@ -463,6 +465,7 @@ OptionElementVector &opt_element_vector, int match_start_point, int max_return_elements, + bool word_complete, StringList &matches) { // Arguments are the standard source file completer. @@ -475,6 +478,7 @@ match_start_point, max_return_elements, NULL, + word_complete, matches); return matches.GetSize(); } Modified: lldb/trunk/source/Commands/CommandObjectMultiword.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectMultiword.cpp?rev=107247&r1=107246&r2=107247&view=diff ============================================================================== --- lldb/trunk/source/Commands/CommandObjectMultiword.cpp (original) +++ lldb/trunk/source/Commands/CommandObjectMultiword.cpp Wed Jun 30 00:02:46 2010 @@ -219,9 +219,14 @@ int &cursor_char_position, int match_start_point, int max_return_elements, + bool &word_complete, StringList &matches ) { + // Any of the command matches will provide a complete word, otherwise the individual + // completers will override this. + word_complete = true; + if (cursor_index == 0) { CommandObject::AddNamesMatchingPartialString (m_subcommand_dict, @@ -245,7 +250,8 @@ input, cursor_index, cursor_char_position, match_start_point, - max_return_elements, + max_return_elements, + word_complete, matches); } else @@ -273,7 +279,8 @@ cursor_index, cursor_char_position, match_start_point, - max_return_elements, + max_return_elements, + word_complete, matches); } Modified: lldb/trunk/source/Interpreter/CommandInterpreter.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/CommandInterpreter.cpp?rev=107247&r1=107246&r2=107247&view=diff ============================================================================== --- lldb/trunk/source/Interpreter/CommandInterpreter.cpp (original) +++ lldb/trunk/source/Interpreter/CommandInterpreter.cpp Wed Jun 30 00:02:46 2010 @@ -653,11 +653,13 @@ int num_matches; int cursor_index = command_args.GetArgumentCount() - 1; int cursor_char_position = strlen (command_args.GetArgumentAtIndex(command_args.GetArgumentCount() - 1)); + bool word_complete; num_matches = HandleCompletionMatches (command_args, cursor_index, cursor_char_position, 0, -1, + word_complete, matches); if (num_matches > 0) @@ -692,11 +694,15 @@ int &cursor_char_position, int match_start_point, int max_return_elements, + bool &word_complete, StringList &matches) { int num_command_matches = 0; bool include_aliases = true; bool look_for_subcommand = false; + + // For any of the command completions a unique match will be a complete word. + word_complete = true; if (cursor_index == -1) { @@ -743,7 +749,8 @@ cursor_index, cursor_char_position, match_start_point, - max_return_elements, + max_return_elements, + word_complete, matches); } } @@ -781,11 +788,13 @@ // Only max_return_elements == -1 is supported at present: assert (max_return_elements == -1); + bool word_complete; num_command_matches = HandleCompletionMatches (parsed_line, cursor_index, cursor_char_position, match_start_point, - max_return_elements, + max_return_elements, + word_complete, matches); if (num_command_matches <= 0) @@ -809,7 +818,8 @@ int partial_name_len = command_partial_str.size(); // If we matched a unique single command, add a space... - if (num_command_matches == 1) + // Only do this if the completer told us this was a complete word, however... + if (num_command_matches == 1 && word_complete) { char quote_char = parsed_line.GetArgumentQuoteCharAtIndex(cursor_index); if (quote_char != '\0') Modified: lldb/trunk/source/Interpreter/CommandObject.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/CommandObject.cpp?rev=107247&r1=107246&r2=107247&view=diff ============================================================================== --- lldb/trunk/source/Interpreter/CommandObject.cpp (original) +++ lldb/trunk/source/Interpreter/CommandObject.cpp Wed Jun 30 00:02:46 2010 @@ -304,6 +304,7 @@ int &cursor_char_position, int match_start_point, int max_return_elements, + bool &word_complete, StringList &matches ) { @@ -345,6 +346,7 @@ cursor_char_position, match_start_point, max_return_elements, + word_complete, matches); if (handled_by_options) return matches.GetSize(); @@ -358,6 +360,7 @@ opt_element_vector, match_start_point, max_return_elements, + word_complete, matches); } } Modified: lldb/trunk/source/Interpreter/Options.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/Options.cpp?rev=107247&r1=107246&r2=107247&view=diff ============================================================================== --- lldb/trunk/source/Interpreter/Options.cpp (original) +++ lldb/trunk/source/Interpreter/Options.cpp Wed Jun 30 00:02:46 2010 @@ -538,9 +538,12 @@ int char_pos, int match_start_point, int max_return_elements, + bool &word_complete, lldb_private::StringList &matches ) { + word_complete = true; + // For now we just scan the completions to see if the cursor position is in // an option or its argument. Otherwise we'll call HandleArgumentCompletion. // In the future we can use completion to validate options as well if we want. @@ -658,6 +661,7 @@ i, match_start_point, max_return_elements, + word_complete, matches); return true; } @@ -688,6 +692,7 @@ int opt_element_index, int match_start_point, int max_return_elements, + bool &word_complete, lldb_private::StringList &matches ) { @@ -754,6 +759,7 @@ match_start_point, max_return_elements, filter_ap.get(), + word_complete, matches); } From benny.kra at googlemail.com Wed Jun 30 08:43:47 2010 From: benny.kra at googlemail.com (Benjamin Kramer) Date: Wed, 30 Jun 2010 13:43:47 -0000 Subject: [Lldb-commits] [lldb] r107281 - /lldb/trunk/source/Commands/CommandCompletions.cpp Message-ID: <20100630134347.3E25B2A6C12C@llvm.org> Author: d0k Date: Wed Jun 30 08:43:47 2010 New Revision: 107281 URL: http://llvm.org/viewvc/llvm-project?rev=107281&view=rev Log: Fix an obvious typo and replace deprecated bcopy(3) with memcpy(3). Modified: lldb/trunk/source/Commands/CommandCompletions.cpp Modified: lldb/trunk/source/Commands/CommandCompletions.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandCompletions.cpp?rev=107281&r1=107280&r2=107281&view=diff ============================================================================== --- lldb/trunk/source/Commands/CommandCompletions.cpp (original) +++ lldb/trunk/source/Commands/CommandCompletions.cpp Wed Jun 30 08:43:47 2010 @@ -134,7 +134,7 @@ // the form the user originally typed. char partial_name_copy[PATH_MAX]; - bcopy (partial_file_name, partial_name_copy, partial_name_len); + memcpy(partial_name_copy, partial_file_name, partial_name_len); partial_name_copy[partial_name_len] = '\0'; // We'll need to save a copy of the remainder for comparision, which we do here. @@ -167,7 +167,7 @@ partial_name_copy[partial_name_len+1] = '\0'; matches.AppendString(partial_name_copy); globfree(&glob_buf); - saw_directory == true; + saw_directory = true; return matches.GetSize(); } else From ctice at apple.com Wed Jun 30 11:22:25 2010 From: ctice at apple.com (Caroline Tice) Date: Wed, 30 Jun 2010 16:22:25 -0000 Subject: [Lldb-commits] [lldb] r107287 - in /lldb/trunk: include/lldb/API/SBDebugger.h include/lldb/Core/Debugger.h scripts/Python/append-debugger-id.py scripts/Python/build-swig-Python.sh scripts/lldb.swig source/API/SBDebugger.cpp source/Core/Debugger.cpp source/Interpreter/ScriptInterpreterPython.cpp Message-ID: <20100630162225.625D42A6C12C@llvm.org> Author: ctice Date: Wed Jun 30 11:22:25 2010 New Revision: 107287 URL: http://llvm.org/viewvc/llvm-project?rev=107287&view=rev Log: Add a unique ID to each debugger instance. Add functions to look up debugger by id Add global variable to lldb python module, to hold debugger id Modify embedded Python interpreter to update the global variable with the id of its current debugger. Modify the char ** typemap definition in lldb.swig to accept 'None' (for NULL) as a valid value. The point of all this is so that, when you drop into the embedded interpreter from the command interpreter (or when doing Python-based breakpoint commands), there is a way for the Python side to find/get the correct debugger instance ( by checking debugger_unique_id, then calling SBDebugger::FindDebuggerWithID on it). Added: lldb/trunk/scripts/Python/append-debugger-id.py Modified: lldb/trunk/include/lldb/API/SBDebugger.h lldb/trunk/include/lldb/Core/Debugger.h lldb/trunk/scripts/Python/build-swig-Python.sh lldb/trunk/scripts/lldb.swig lldb/trunk/source/API/SBDebugger.cpp lldb/trunk/source/Core/Debugger.cpp lldb/trunk/source/Interpreter/ScriptInterpreterPython.cpp Modified: lldb/trunk/include/lldb/API/SBDebugger.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBDebugger.h?rev=107287&r1=107286&r2=107287&view=diff ============================================================================== --- lldb/trunk/include/lldb/API/SBDebugger.h (original) +++ lldb/trunk/include/lldb/API/SBDebugger.h Wed Jun 30 11:22:25 2010 @@ -129,6 +129,9 @@ void PushInputReader (lldb::SBInputReader &reader); + static SBDebugger + FindDebuggerWithID (int id); + private: // Use the static function: SBDebugger::Create(); Modified: lldb/trunk/include/lldb/Core/Debugger.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/Debugger.h?rev=107287&r1=107286&r2=107287&view=diff ============================================================================== --- lldb/trunk/include/lldb/Core/Debugger.h (original) +++ lldb/trunk/include/lldb/Core/Debugger.h Wed Jun 30 11:22:25 2010 @@ -21,6 +21,7 @@ #include "lldb/Core/Listener.h" #include "lldb/Core/StreamFile.h" #include "lldb/Core/SourceManager.h" +#include "lldb/Core/UserID.h" #include "lldb/Target/ExecutionContext.h" #include "lldb/Target/TargetList.h" @@ -32,7 +33,8 @@ /// /// Provides a global root objects for the debugger core. //---------------------------------------------------------------------- -class Debugger +class Debugger : + public UserID { public: @@ -139,6 +141,9 @@ void UpdateExecutionContext (ExecutionContext *override_context); + static lldb::DebuggerSP + FindDebuggerWithID (lldb::user_id_t id); + protected: static void @@ -165,7 +170,7 @@ std::stack m_input_readers; std::string m_input_reader_data; - + private: // Use Debugger::CreateInstance() to get a shared pointer to a new Added: lldb/trunk/scripts/Python/append-debugger-id.py URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/Python/append-debugger-id.py?rev=107287&view=auto ============================================================================== --- lldb/trunk/scripts/Python/append-debugger-id.py (added) +++ lldb/trunk/scripts/Python/append-debugger-id.py Wed Jun 30 11:22:25 2010 @@ -0,0 +1,27 @@ +# +# append-debugger-id.py +# +# This script adds a global variable, 'debugger_unique_id' to the lldb +# module (which was automatically generated via running swig), and +# initializes it to 0. +# + +import sys + +if len (sys.argv) != 2: + output_name = "./lldb.py" +else: + output_name = sys.argv[1] + "/lldb.py" + +# print "output_name is '" + output_name + "'" + +try: + f_out = open (output_name, 'a') +except IOError: + print "Error: Unable to open file for appending: " + output_name +else: + f_out.write ("debugger_unique_id = 0\n"); + try: + f_out.close() + except IOError: + print "Error occurred while close file." Modified: lldb/trunk/scripts/Python/build-swig-Python.sh URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/Python/build-swig-Python.sh?rev=107287&r1=107286&r2=107287&view=diff ============================================================================== --- lldb/trunk/scripts/Python/build-swig-Python.sh (original) +++ lldb/trunk/scripts/Python/build-swig-Python.sh Wed Jun 30 11:22:25 2010 @@ -127,3 +127,10 @@ swig -c++ -shadow -python -I"${SRC_ROOT}/include" -I./. -outdir "${CONFIG_BUILD_DIR}" -o "${swig_output_file}" "${swig_input_file}" +# Append global variable to lldb Python module. + +current_dir=`pwd` +if [ -f "${current_dir}/append-debugger-id.py" ] +then + python ${current_dir}/append-debugger-id.py ${CONFIG_BUILD_DIR} +fi Modified: lldb/trunk/scripts/lldb.swig URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/lldb.swig?rev=107287&r1=107286&r2=107287&view=diff ============================================================================== --- lldb/trunk/scripts/lldb.swig (original) +++ lldb/trunk/scripts/lldb.swig Wed Jun 30 11:22:25 2010 @@ -43,6 +43,8 @@ } } $1[i] = 0; + } else if ($input == Py_None) { + $1 = NULL; } else { PyErr_SetString(PyExc_TypeError,"not a list"); return NULL; Modified: lldb/trunk/source/API/SBDebugger.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBDebugger.cpp?rev=107287&r1=107286&r2=107287&view=diff ============================================================================== --- lldb/trunk/source/API/SBDebugger.cpp (original) +++ lldb/trunk/source/API/SBDebugger.cpp Wed Jun 30 11:22:25 2010 @@ -51,7 +51,6 @@ return debugger; } - SBDebugger::SBDebugger () : m_opaque_sp () { @@ -549,3 +548,12 @@ } +SBDebugger +SBDebugger::FindDebuggerWithID (int id) +{ + SBDebugger sb_debugger; + lldb::DebuggerSP debugger_sp = Debugger::FindDebuggerWithID (id); + if (debugger_sp) + sb_debugger.reset (debugger_sp); + return sb_debugger; +} Modified: lldb/trunk/source/Core/Debugger.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/Debugger.cpp?rev=107287&r1=107286&r2=107287&view=diff ============================================================================== --- lldb/trunk/source/Core/Debugger.cpp (original) +++ lldb/trunk/source/Core/Debugger.cpp Wed Jun 30 11:22:25 2010 @@ -24,6 +24,8 @@ static uint32_t g_shared_debugger_refcount = 0; +static lldb::user_id_t g_unique_id = 1; + void Debugger::Initialize () { @@ -115,6 +117,7 @@ Debugger::Debugger () : + UserID (g_unique_id++), m_input_comm("debugger.input"), m_input_file (), m_output_file (), @@ -491,3 +494,21 @@ } } +DebuggerSP +Debugger::FindDebuggerWithID (lldb::user_id_t id) +{ + lldb::DebuggerSP debugger_sp; + + Mutex::Locker locker (GetDebuggerListMutex ()); + DebuggerList &debugger_list = GetDebuggerList(); + DebuggerList::iterator pos, end = debugger_list.end(); + for (pos = debugger_list.begin(); pos != end; ++pos) + { + if ((*pos).get()->GetID() == id) + { + debugger_sp = *pos; + break; + } + } + return debugger_sp; +} Modified: lldb/trunk/source/Interpreter/ScriptInterpreterPython.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/ScriptInterpreterPython.cpp?rev=107287&r1=107286&r2=107287&view=diff ============================================================================== --- lldb/trunk/source/Interpreter/ScriptInterpreterPython.cpp (original) +++ lldb/trunk/source/Interpreter/ScriptInterpreterPython.cpp Wed Jun 30 11:22:25 2010 @@ -238,6 +238,10 @@ PyRun_SimpleString ("new_mode[3] = new_mode[3] | ECHO | ICANON"); PyRun_SimpleString ("new_mode[6][VEOF] = 255"); PyRun_SimpleString ("tcsetattr (new_stdin, TCSANOW, new_mode)"); + + run_string.Clear(); + run_string.Printf ("debugger_unique_id = %d", interpreter.GetDebugger().GetID()); + PyRun_SimpleString (run_string.GetData()); } From johnny.chen at apple.com Wed Jun 30 14:19:14 2010 From: johnny.chen at apple.com (Johnny Chen) Date: Wed, 30 Jun 2010 12:19:14 -0700 Subject: [Lldb-commits] [lldb] r107287 - in /lldb/trunk: include/lldb/API/SBDebugger.h include/lldb/Core/Debugger.h scripts/Python/append-debugger-id.py scripts/Python/build-swig-Python.sh scripts/lldb.swig source/API/SBDebugger.cpp source/Core/Debugger.cpp source/Interpreter/ScriptInterpreterPython.cpp In-Reply-To: <20100630162225.625D42A6C12C@llvm.org> References: <20100630162225.625D42A6C12C@llvm.org> Message-ID: <041BB92E-A4E6-4B87-A37F-D2E2F52B71E1@apple.com> Hi Caroline, Is the following usage of FindDebuggerWithID() correct? Does SBDebugger.Initialize() need to make sure that lldb.debugger_unique_id is sane? python Python 2.6.1 (r261:67515, Feb 11 2010, 00:51:29) [GCC 4.2.1 (Apple Inc. build 5646)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import lldb import lldb >>> lldb.SBDebugger.Initialize() lldb.SBDebugger.Initialize() >>> dbg = lldb.SBDebugger.FindDebuggerWithID(lldb.debugger_unique_id) dbg = lldb.SBDebugger.FindDebuggerWithID(lldb.debugger_unique_id) >>> ci = dbg.GetCommandInterpreter() ci = dbg.GetCommandInterpreter() >>> res = res = lldb.SBCommandReturnObject() res = res = lldb.SBCommandReturnObject() >>> dbg.SetAsync(False) dbg.SetAsync(False) >>> ci.HandleCommand("help", res) ci.HandleCommand("help", res) 6 >>> dbg.IsValid() dbg.IsValid() False >>> On Jun 30, 2010, at 9:22 AM, Caroline Tice wrote: > Author: ctice > Date: Wed Jun 30 11:22:25 2010 > New Revision: 107287 > > URL: http://llvm.org/viewvc/llvm-project?rev=107287&view=rev > Log: > Add a unique ID to each debugger instance. > Add functions to look up debugger by id > Add global variable to lldb python module, to hold debugger id > Modify embedded Python interpreter to update the global variable with the > id of its current debugger. > Modify the char ** typemap definition in lldb.swig to accept 'None' (for NULL) > as a valid value. > > The point of all this is so that, when you drop into the embedded interpreter > from the command interpreter (or when doing Python-based breakpoint commands), > there is a way for the Python side to find/get the correct debugger > instance ( by checking debugger_unique_id, then calling > SBDebugger::FindDebuggerWithID on it). > > > Added: > lldb/trunk/scripts/Python/append-debugger-id.py > Modified: > lldb/trunk/include/lldb/API/SBDebugger.h > lldb/trunk/include/lldb/Core/Debugger.h > lldb/trunk/scripts/Python/build-swig-Python.sh > lldb/trunk/scripts/lldb.swig > lldb/trunk/source/API/SBDebugger.cpp > lldb/trunk/source/Core/Debugger.cpp > lldb/trunk/source/Interpreter/ScriptInterpreterPython.cpp > > Modified: lldb/trunk/include/lldb/API/SBDebugger.h > URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBDebugger.h?rev=107287&r1=107286&r2=107287&view=diff > ============================================================================== > --- lldb/trunk/include/lldb/API/SBDebugger.h (original) > +++ lldb/trunk/include/lldb/API/SBDebugger.h Wed Jun 30 11:22:25 2010 > @@ -129,6 +129,9 @@ > void > PushInputReader (lldb::SBInputReader &reader); > > + static SBDebugger > + FindDebuggerWithID (int id); > + > private: > > // Use the static function: SBDebugger::Create(); > > Modified: lldb/trunk/include/lldb/Core/Debugger.h > URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/Debugger.h?rev=107287&r1=107286&r2=107287&view=diff > ============================================================================== > --- lldb/trunk/include/lldb/Core/Debugger.h (original) > +++ lldb/trunk/include/lldb/Core/Debugger.h Wed Jun 30 11:22:25 2010 > @@ -21,6 +21,7 @@ > #include "lldb/Core/Listener.h" > #include "lldb/Core/StreamFile.h" > #include "lldb/Core/SourceManager.h" > +#include "lldb/Core/UserID.h" > #include "lldb/Target/ExecutionContext.h" > #include "lldb/Target/TargetList.h" > > @@ -32,7 +33,8 @@ > /// > /// Provides a global root objects for the debugger core. > //---------------------------------------------------------------------- > -class Debugger > +class Debugger : > + public UserID > { > public: > > @@ -139,6 +141,9 @@ > void > UpdateExecutionContext (ExecutionContext *override_context); > > + static lldb::DebuggerSP > + FindDebuggerWithID (lldb::user_id_t id); > + > protected: > > static void > @@ -165,7 +170,7 @@ > > std::stack m_input_readers; > std::string m_input_reader_data; > - > + > private: > > // Use Debugger::CreateInstance() to get a shared pointer to a new > > Added: lldb/trunk/scripts/Python/append-debugger-id.py > URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/Python/append-debugger-id.py?rev=107287&view=auto > ============================================================================== > --- lldb/trunk/scripts/Python/append-debugger-id.py (added) > +++ lldb/trunk/scripts/Python/append-debugger-id.py Wed Jun 30 11:22:25 2010 > @@ -0,0 +1,27 @@ > +# > +# append-debugger-id.py > +# > +# This script adds a global variable, 'debugger_unique_id' to the lldb > +# module (which was automatically generated via running swig), and > +# initializes it to 0. > +# > + > +import sys > + > +if len (sys.argv) != 2: > + output_name = "./lldb.py" > +else: > + output_name = sys.argv[1] + "/lldb.py" > + > +# print "output_name is '" + output_name + "'" > + > +try: > + f_out = open (output_name, 'a') > +except IOError: > + print "Error: Unable to open file for appending: " + output_name > +else: > + f_out.write ("debugger_unique_id = 0\n"); > + try: > + f_out.close() > + except IOError: > + print "Error occurred while close file." > > Modified: lldb/trunk/scripts/Python/build-swig-Python.sh > URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/Python/build-swig-Python.sh?rev=107287&r1=107286&r2=107287&view=diff > ============================================================================== > --- lldb/trunk/scripts/Python/build-swig-Python.sh (original) > +++ lldb/trunk/scripts/Python/build-swig-Python.sh Wed Jun 30 11:22:25 2010 > @@ -127,3 +127,10 @@ > > swig -c++ -shadow -python -I"${SRC_ROOT}/include" -I./. -outdir "${CONFIG_BUILD_DIR}" -o "${swig_output_file}" "${swig_input_file}" > > +# Append global variable to lldb Python module. > + > +current_dir=`pwd` > +if [ -f "${current_dir}/append-debugger-id.py" ] > +then > + python ${current_dir}/append-debugger-id.py ${CONFIG_BUILD_DIR} > +fi > > Modified: lldb/trunk/scripts/lldb.swig > URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/lldb.swig?rev=107287&r1=107286&r2=107287&view=diff > ============================================================================== > --- lldb/trunk/scripts/lldb.swig (original) > +++ lldb/trunk/scripts/lldb.swig Wed Jun 30 11:22:25 2010 > @@ -43,6 +43,8 @@ > } > } > $1[i] = 0; > + } else if ($input == Py_None) { > + $1 = NULL; > } else { > PyErr_SetString(PyExc_TypeError,"not a list"); > return NULL; > > Modified: lldb/trunk/source/API/SBDebugger.cpp > URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBDebugger.cpp?rev=107287&r1=107286&r2=107287&view=diff > ============================================================================== > --- lldb/trunk/source/API/SBDebugger.cpp (original) > +++ lldb/trunk/source/API/SBDebugger.cpp Wed Jun 30 11:22:25 2010 > @@ -51,7 +51,6 @@ > return debugger; > } > > - > SBDebugger::SBDebugger () : > m_opaque_sp () > { > @@ -549,3 +548,12 @@ > } > > > +SBDebugger > +SBDebugger::FindDebuggerWithID (int id) > +{ > + SBDebugger sb_debugger; > + lldb::DebuggerSP debugger_sp = Debugger::FindDebuggerWithID (id); > + if (debugger_sp) > + sb_debugger.reset (debugger_sp); > + return sb_debugger; > +} > > Modified: lldb/trunk/source/Core/Debugger.cpp > URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/Debugger.cpp?rev=107287&r1=107286&r2=107287&view=diff > ============================================================================== > --- lldb/trunk/source/Core/Debugger.cpp (original) > +++ lldb/trunk/source/Core/Debugger.cpp Wed Jun 30 11:22:25 2010 > @@ -24,6 +24,8 @@ > > static uint32_t g_shared_debugger_refcount = 0; > > +static lldb::user_id_t g_unique_id = 1; > + > void > Debugger::Initialize () > { > @@ -115,6 +117,7 @@ > > > Debugger::Debugger () : > + UserID (g_unique_id++), > m_input_comm("debugger.input"), > m_input_file (), > m_output_file (), > @@ -491,3 +494,21 @@ > } > } > > +DebuggerSP > +Debugger::FindDebuggerWithID (lldb::user_id_t id) > +{ > + lldb::DebuggerSP debugger_sp; > + > + Mutex::Locker locker (GetDebuggerListMutex ()); > + DebuggerList &debugger_list = GetDebuggerList(); > + DebuggerList::iterator pos, end = debugger_list.end(); > + for (pos = debugger_list.begin(); pos != end; ++pos) > + { > + if ((*pos).get()->GetID() == id) > + { > + debugger_sp = *pos; > + break; > + } > + } > + return debugger_sp; > +} > > Modified: lldb/trunk/source/Interpreter/ScriptInterpreterPython.cpp > URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/ScriptInterpreterPython.cpp?rev=107287&r1=107286&r2=107287&view=diff > ============================================================================== > --- lldb/trunk/source/Interpreter/ScriptInterpreterPython.cpp (original) > +++ lldb/trunk/source/Interpreter/ScriptInterpreterPython.cpp Wed Jun 30 11:22:25 2010 > @@ -238,6 +238,10 @@ > PyRun_SimpleString ("new_mode[3] = new_mode[3] | ECHO | ICANON"); > PyRun_SimpleString ("new_mode[6][VEOF] = 255"); > PyRun_SimpleString ("tcsetattr (new_stdin, TCSANOW, new_mode)"); > + > + run_string.Clear(); > + run_string.Printf ("debugger_unique_id = %d", interpreter.GetDebugger().GetID()); > + PyRun_SimpleString (run_string.GetData()); > } > > > > > _______________________________________________ > lldb-commits mailing list > lldb-commits at cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/lldb-commits From johnny.chen at apple.com Wed Jun 30 15:43:35 2010 From: johnny.chen at apple.com (Johnny Chen) Date: Wed, 30 Jun 2010 20:43:35 -0000 Subject: [Lldb-commits] [lldb] r107318 - /lldb/trunk/test/bitfields/main.c Message-ID: <20100630204335.821CA2A6C12C@llvm.org> Author: johnny Date: Wed Jun 30 15:43:35 2010 New Revision: 107318 URL: http://llvm.org/viewvc/llvm-project?rev=107318&view=rev Log: Fixed a typo. Modified: lldb/trunk/test/bitfields/main.c Modified: lldb/trunk/test/bitfields/main.c URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/bitfields/main.c?rev=107318&r1=107317&r2=107318&view=diff ============================================================================== --- lldb/trunk/test/bitfields/main.c (original) +++ lldb/trunk/test/bitfields/main.c Wed Jun 30 15:43:35 2010 @@ -38,7 +38,7 @@ for (i=0; i<(1<<7); i++) bits.b7 = i; //// break $source:$line for (i=0; i<(1<<4); i++) - bits.b4 = i; //// break $source:$line + bits.four = i; //// break $source:$line return 0; //// continue } From ctice at apple.com Wed Jun 30 16:04:20 2010 From: ctice at apple.com (Caroline Tice) Date: Wed, 30 Jun 2010 14:04:20 -0700 Subject: [Lldb-commits] [lldb] r107287 - in /lldb/trunk: include/lldb/API/SBDebugger.h include/lldb/Core/Debugger.h scripts/Python/append-debugger-id.py scripts/Python/build-swig-Python.sh scripts/lldb.swig source/API/SBDebugger.cpp source/Core/Debugger.cpp source/Interpreter/ScriptInterpreterPython.cpp In-Reply-To: <041BB92E-A4E6-4B87-A37F-D2E2F52B71E1@apple.com> References: <20100630162225.625D42A6C12C@llvm.org> <041BB92E-A4E6-4B87-A37F-D2E2F52B71E1@apple.com> Message-ID: <8DB3B909-FD1B-4BC2-9A79-5631EBF738EA@apple.com> No, it is not actually correct. The debugger_unique_id gets initialized to zero, which means "there is no current debugger; if you want one you need to create one". You should always check the value of debugger_unique_id before trying to find the debugger; if the id is zero, then there is no debugger to find. Whenever you are using the lldb python module directly from Unix (or Linux or whatever), you should expect that the debugger_unique_id is probably zero, and you should expect to have to call lldb.SBDebugger.Create() to create a debugger instance. When running the command-line debugger of lldb (or lldb from inside Xcode), the debugger instance has already been created by the command-line debugger (or Xcode), and you want to be able to find and use the already created instance of the debugger. When the command-line debugger starts up the script interpreter, it updates the value of debugger_unique_id in the lldb python module to reflect the id of the existing debugger. Then when you use the 'script' command or the 'breakpoint add' command from the command interpreter to slip into python-mode, you can use SBDebugger.FindDebuggerWithID (debugger_unique_id) to get the right instance of the debugger. Of course, just to be on the safe side, you should still check to make sure the id isn't zero... Let me know if this is still not clear... -- Caroline ctice at apple.com On Jun 30, 2010, at 12:19 PM, Johnny Chen wrote: > Hi Caroline, > > Is the following usage of FindDebuggerWithID() correct? > Does SBDebugger.Initialize() need to make sure that lldb.debugger_unique_id is sane? > > python > Python 2.6.1 (r261:67515, Feb 11 2010, 00:51:29) > [GCC 4.2.1 (Apple Inc. build 5646)] on darwin > Type "help", "copyright", "credits" or "license" for more information. >>>> import lldb > import lldb >>>> lldb.SBDebugger.Initialize() > lldb.SBDebugger.Initialize() >>>> dbg = lldb.SBDebugger.FindDebuggerWithID(lldb.debugger_unique_id) > dbg = lldb.SBDebugger.FindDebuggerWithID(lldb.debugger_unique_id) >>>> ci = dbg.GetCommandInterpreter() > ci = dbg.GetCommandInterpreter() >>>> res = res = lldb.SBCommandReturnObject() > res = res = lldb.SBCommandReturnObject() >>>> dbg.SetAsync(False) > dbg.SetAsync(False) >>>> ci.HandleCommand("help", res) > ci.HandleCommand("help", res) > 6 >>>> dbg.IsValid() > dbg.IsValid() > False >>>> > > On Jun 30, 2010, at 9:22 AM, Caroline Tice wrote: > >> Author: ctice >> Date: Wed Jun 30 11:22:25 2010 >> New Revision: 107287 >> >> URL: http://llvm.org/viewvc/llvm-project?rev=107287&view=rev >> Log: >> Add a unique ID to each debugger instance. >> Add functions to look up debugger by id >> Add global variable to lldb python module, to hold debugger id >> Modify embedded Python interpreter to update the global variable with the >> id of its current debugger. >> Modify the char ** typemap definition in lldb.swig to accept 'None' (for NULL) >> as a valid value. >> >> The point of all this is so that, when you drop into the embedded interpreter >> from the command interpreter (or when doing Python-based breakpoint commands), >> there is a way for the Python side to find/get the correct debugger >> instance ( by checking debugger_unique_id, then calling >> SBDebugger::FindDebuggerWithID on it). >> >> >> Added: >> lldb/trunk/scripts/Python/append-debugger-id.py >> Modified: >> lldb/trunk/include/lldb/API/SBDebugger.h >> lldb/trunk/include/lldb/Core/Debugger.h >> lldb/trunk/scripts/Python/build-swig-Python.sh >> lldb/trunk/scripts/lldb.swig >> lldb/trunk/source/API/SBDebugger.cpp >> lldb/trunk/source/Core/Debugger.cpp >> lldb/trunk/source/Interpreter/ScriptInterpreterPython.cpp >> >> Modified: lldb/trunk/include/lldb/API/SBDebugger.h >> URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBDebugger.h?rev=107287&r1=107286&r2=107287&view=diff >> ============================================================================== >> --- lldb/trunk/include/lldb/API/SBDebugger.h (original) >> +++ lldb/trunk/include/lldb/API/SBDebugger.h Wed Jun 30 11:22:25 2010 >> @@ -129,6 +129,9 @@ >> void >> PushInputReader (lldb::SBInputReader &reader); >> >> + static SBDebugger >> + FindDebuggerWithID (int id); >> + >> private: >> >> // Use the static function: SBDebugger::Create(); >> >> Modified: lldb/trunk/include/lldb/Core/Debugger.h >> URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/Debugger.h?rev=107287&r1=107286&r2=107287&view=diff >> ============================================================================== >> --- lldb/trunk/include/lldb/Core/Debugger.h (original) >> +++ lldb/trunk/include/lldb/Core/Debugger.h Wed Jun 30 11:22:25 2010 >> @@ -21,6 +21,7 @@ >> #include "lldb/Core/Listener.h" >> #include "lldb/Core/StreamFile.h" >> #include "lldb/Core/SourceManager.h" >> +#include "lldb/Core/UserID.h" >> #include "lldb/Target/ExecutionContext.h" >> #include "lldb/Target/TargetList.h" >> >> @@ -32,7 +33,8 @@ >> /// >> /// Provides a global root objects for the debugger core. >> //---------------------------------------------------------------------- >> -class Debugger >> +class Debugger : >> + public UserID >> { >> public: >> >> @@ -139,6 +141,9 @@ >> void >> UpdateExecutionContext (ExecutionContext *override_context); >> >> + static lldb::DebuggerSP >> + FindDebuggerWithID (lldb::user_id_t id); >> + >> protected: >> >> static void >> @@ -165,7 +170,7 @@ >> >> std::stack m_input_readers; >> std::string m_input_reader_data; >> - >> + >> private: >> >> // Use Debugger::CreateInstance() to get a shared pointer to a new >> >> Added: lldb/trunk/scripts/Python/append-debugger-id.py >> URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/Python/append-debugger-id.py?rev=107287&view=auto >> ============================================================================== >> --- lldb/trunk/scripts/Python/append-debugger-id.py (added) >> +++ lldb/trunk/scripts/Python/append-debugger-id.py Wed Jun 30 11:22:25 2010 >> @@ -0,0 +1,27 @@ >> +# >> +# append-debugger-id.py >> +# >> +# This script adds a global variable, 'debugger_unique_id' to the lldb >> +# module (which was automatically generated via running swig), and >> +# initializes it to 0. >> +# >> + >> +import sys >> + >> +if len (sys.argv) != 2: >> + output_name = "./lldb.py" >> +else: >> + output_name = sys.argv[1] + "/lldb.py" >> + >> +# print "output_name is '" + output_name + "'" >> + >> +try: >> + f_out = open (output_name, 'a') >> +except IOError: >> + print "Error: Unable to open file for appending: " + output_name >> +else: >> + f_out.write ("debugger_unique_id = 0\n"); >> + try: >> + f_out.close() >> + except IOError: >> + print "Error occurred while close file." >> >> Modified: lldb/trunk/scripts/Python/build-swig-Python.sh >> URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/Python/build-swig-Python.sh?rev=107287&r1=107286&r2=107287&view=diff >> ============================================================================== >> --- lldb/trunk/scripts/Python/build-swig-Python.sh (original) >> +++ lldb/trunk/scripts/Python/build-swig-Python.sh Wed Jun 30 11:22:25 2010 >> @@ -127,3 +127,10 @@ >> >> swig -c++ -shadow -python -I"${SRC_ROOT}/include" -I./. -outdir "${CONFIG_BUILD_DIR}" -o "${swig_output_file}" "${swig_input_file}" >> >> +# Append global variable to lldb Python module. >> + >> +current_dir=`pwd` >> +if [ -f "${current_dir}/append-debugger-id.py" ] >> +then >> + python ${current_dir}/append-debugger-id.py ${CONFIG_BUILD_DIR} >> +fi >> >> Modified: lldb/trunk/scripts/lldb.swig >> URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/lldb.swig?rev=107287&r1=107286&r2=107287&view=diff >> ============================================================================== >> --- lldb/trunk/scripts/lldb.swig (original) >> +++ lldb/trunk/scripts/lldb.swig Wed Jun 30 11:22:25 2010 >> @@ -43,6 +43,8 @@ >> } >> } >> $1[i] = 0; >> + } else if ($input == Py_None) { >> + $1 = NULL; >> } else { >> PyErr_SetString(PyExc_TypeError,"not a list"); >> return NULL; >> >> Modified: lldb/trunk/source/API/SBDebugger.cpp >> URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBDebugger.cpp?rev=107287&r1=107286&r2=107287&view=diff >> ============================================================================== >> --- lldb/trunk/source/API/SBDebugger.cpp (original) >> +++ lldb/trunk/source/API/SBDebugger.cpp Wed Jun 30 11:22:25 2010 >> @@ -51,7 +51,6 @@ >> return debugger; >> } >> >> - >> SBDebugger::SBDebugger () : >> m_opaque_sp () >> { >> @@ -549,3 +548,12 @@ >> } >> >> >> +SBDebugger >> +SBDebugger::FindDebuggerWithID (int id) >> +{ >> + SBDebugger sb_debugger; >> + lldb::DebuggerSP debugger_sp = Debugger::FindDebuggerWithID (id); >> + if (debugger_sp) >> + sb_debugger.reset (debugger_sp); >> + return sb_debugger; >> +} >> >> Modified: lldb/trunk/source/Core/Debugger.cpp >> URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/Debugger.cpp?rev=107287&r1=107286&r2=107287&view=diff >> ============================================================================== >> --- lldb/trunk/source/Core/Debugger.cpp (original) >> +++ lldb/trunk/source/Core/Debugger.cpp Wed Jun 30 11:22:25 2010 >> @@ -24,6 +24,8 @@ >> >> static uint32_t g_shared_debugger_refcount = 0; >> >> +static lldb::user_id_t g_unique_id = 1; >> + >> void >> Debugger::Initialize () >> { >> @@ -115,6 +117,7 @@ >> >> >> Debugger::Debugger () : >> + UserID (g_unique_id++), >> m_input_comm("debugger.input"), >> m_input_file (), >> m_output_file (), >> @@ -491,3 +494,21 @@ >> } >> } >> >> +DebuggerSP >> +Debugger::FindDebuggerWithID (lldb::user_id_t id) >> +{ >> + lldb::DebuggerSP debugger_sp; >> + >> + Mutex::Locker locker (GetDebuggerListMutex ()); >> + DebuggerList &debugger_list = GetDebuggerList(); >> + DebuggerList::iterator pos, end = debugger_list.end(); >> + for (pos = debugger_list.begin(); pos != end; ++pos) >> + { >> + if ((*pos).get()->GetID() == id) >> + { >> + debugger_sp = *pos; >> + break; >> + } >> + } >> + return debugger_sp; >> +} >> >> Modified: lldb/trunk/source/Interpreter/ScriptInterpreterPython.cpp >> URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/ScriptInterpreterPython.cpp?rev=107287&r1=107286&r2=107287&view=diff >> ============================================================================== >> --- lldb/trunk/source/Interpreter/ScriptInterpreterPython.cpp (original) >> +++ lldb/trunk/source/Interpreter/ScriptInterpreterPython.cpp Wed Jun 30 11:22:25 2010 >> @@ -238,6 +238,10 @@ >> PyRun_SimpleString ("new_mode[3] = new_mode[3] | ECHO | ICANON"); >> PyRun_SimpleString ("new_mode[6][VEOF] = 255"); >> PyRun_SimpleString ("tcsetattr (new_stdin, TCSANOW, new_mode)"); >> + >> + run_string.Clear(); >> + run_string.Printf ("debugger_unique_id = %d", interpreter.GetDebugger().GetID()); >> + PyRun_SimpleString (run_string.GetData()); >> } >> >> >> >> >> _______________________________________________ >> lldb-commits mailing list >> lldb-commits at cs.uiuc.edu >> http://lists.cs.uiuc.edu/mailman/listinfo/lldb-commits > From johnny.chen at apple.com Wed Jun 30 17:16:25 2010 From: johnny.chen at apple.com (Johnny Chen) Date: Wed, 30 Jun 2010 22:16:25 -0000 Subject: [Lldb-commits] [lldb] r107330 - in /lldb/trunk/test: array_types/TestArrayTypes.py class_types/TestClassTypes.py Message-ID: <20100630221625.82AC72A6C12C@llvm.org> Author: johnny Date: Wed Jun 30 17:16:25 2010 New Revision: 107330 URL: http://llvm.org/viewvc/llvm-project?rev=107330&view=rev Log: Added TestClassTypes.py to test setting a breakpoint on a class constructor and do 'variable list this' command when stopped. Applied some cleanup on TestArrayTypes.py. In particular, specify the absolute path to the object file in order not to confuse the debugger. Added: lldb/trunk/test/class_types/TestClassTypes.py Modified: lldb/trunk/test/array_types/TestArrayTypes.py Modified: lldb/trunk/test/array_types/TestArrayTypes.py URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/array_types/TestArrayTypes.py?rev=107330&r1=107329&r2=107330&view=diff ============================================================================== --- lldb/trunk/test/array_types/TestArrayTypes.py (original) +++ lldb/trunk/test/array_types/TestArrayTypes.py Wed Jun 30 17:16:25 2010 @@ -25,8 +25,10 @@ def test_array_types(self): """Test 'variable list var_name' on some variables with array types.""" res = lldb.SBCommandReturnObject() - self.ci.HandleCommand("file a.out", res) + exe = os.path.join(os.getcwd(), "a.out") + self.ci.HandleCommand("file " + exe, res) self.assertTrue(res.Succeeded()) + self.ci.HandleCommand("breakpoint set -f main.c -l 42", res) self.assertTrue(res.Succeeded()) self.assertTrue(res.GetOutput().startswith( @@ -46,15 +48,16 @@ self.ci.HandleCommand("variable list strings", res); self.assertTrue(res.Succeeded()) - self.assertTrue(res.GetOutput().startswith('(char *[4])') and - res.GetOutput().find('(char *) strings[0]') and - res.GetOutput().find('(char *) strings[1]') and - res.GetOutput().find('(char *) strings[2]') and - res.GetOutput().find('(char *) strings[3]') and - res.GetOutput().find('Hello') and - res.GetOutput().find('Hola') and - res.GetOutput().find('Bonjour') and - res.GetOutput().find('Guten Tag')) + output = res.GetOutput() + self.assertTrue(output.startswith('(char *[4])') and + output.find('(char *) strings[0]') and + output.find('(char *) strings[1]') and + output.find('(char *) strings[2]') and + output.find('(char *) strings[3]') and + output.find('Hello') and + output.find('Hola') and + output.find('Bonjour') and + output.find('Guten Tag')) self.ci.HandleCommand("variable list char_16", res); self.assertTrue(res.Succeeded()) Added: lldb/trunk/test/class_types/TestClassTypes.py URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/class_types/TestClassTypes.py?rev=107330&view=auto ============================================================================== --- lldb/trunk/test/class_types/TestClassTypes.py (added) +++ lldb/trunk/test/class_types/TestClassTypes.py Wed Jun 30 17:16:25 2010 @@ -0,0 +1,60 @@ +"""Test breakpoint on a class constructor; and variable list the this object.""" + +import os +import lldb +import unittest + +class TestClassTypes(unittest.TestCase): + + def setUp(self): + # Save old working directory. + self.oldcwd = os.getcwd() + # Change current working directory if ${LLDB_TEST} is defined. + if ("LLDB_TEST" in os.environ): + os.chdir(os.path.join(os.environ["LLDB_TEST"], "class_types")); + self.dbg = lldb.SBDebugger.Create() + self.dbg.SetAsync(False) + self.ci = self.dbg.GetCommandInterpreter() + if not self.ci: + raise Exception('Could not get the command interpreter') + + def tearDown(self): + # Restore old working directory. + os.chdir(self.oldcwd) + + def test_class_types(self): + """Test 'variable list this' when stopped on a class constructor.""" + res = lldb.SBCommandReturnObject() + exe = os.path.join(os.getcwd(), "a.out") + self.ci.HandleCommand("file " + exe, res) + self.assertTrue(res.Succeeded()) + + self.ci.HandleCommand("breakpoint set -f main.cpp -l 73", res) + self.assertTrue(res.Succeeded()) + self.assertTrue(res.GetOutput().startswith( + "Breakpoint created: 1: file ='main.cpp', line = 73, locations = 1")) + + self.ci.HandleCommand("run", res) + self.assertTrue(res.Succeeded()) + + self.ci.HandleCommand("breakpoint list", res) + self.assertTrue(res.Succeeded()) + self.assertTrue(res.GetOutput().find('resolved, hit count = 1')) + + self.ci.HandleCommand("thread list", res) + self.assertTrue(res.Succeeded()) + self.assertTrue(res.GetOutput().find('state is Stopped') and + res.GetOutput().find('stop reason = breakpoint')) + + self.ci.HandleCommand("variable list this", res); + self.assertTrue(res.Succeeded()) + self.assertTrue(res.GetOutput().startswith('(class C *const) this = ')) + + self.ci.HandleCommand("continue", res) + self.assertTrue(res.Succeeded()) + + +if __name__ == '__main__': + lldb.SBDebugger.Initialize() + unittest.main() + lldb.SBDebugger.Terminate() From johnny.chen at apple.com Wed Jun 30 17:22:37 2010 From: johnny.chen at apple.com (Johnny Chen) Date: Wed, 30 Jun 2010 22:22:37 -0000 Subject: [Lldb-commits] [lldb] r107333 - in /lldb/trunk/test: array_types/TestArrayTypes.py class_types/TestClassTypes.py Message-ID: <20100630222237.5E1842A6C12C@llvm.org> Author: johnny Date: Wed Jun 30 17:22:37 2010 New Revision: 107333 URL: http://llvm.org/viewvc/llvm-project?rev=107333&view=rev Log: Added comments. Modified: lldb/trunk/test/array_types/TestArrayTypes.py lldb/trunk/test/class_types/TestClassTypes.py Modified: lldb/trunk/test/array_types/TestArrayTypes.py URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/array_types/TestArrayTypes.py?rev=107333&r1=107332&r2=107333&view=diff ============================================================================== --- lldb/trunk/test/array_types/TestArrayTypes.py (original) +++ lldb/trunk/test/array_types/TestArrayTypes.py Wed Jun 30 17:22:37 2010 @@ -29,6 +29,7 @@ self.ci.HandleCommand("file " + exe, res) self.assertTrue(res.Succeeded()) + # Break on line 42 inside main(). self.ci.HandleCommand("breakpoint set -f main.c -l 42", res) self.assertTrue(res.Succeeded()) self.assertTrue(res.GetOutput().startswith( @@ -37,15 +38,19 @@ self.ci.HandleCommand("run", res) self.assertTrue(res.Succeeded()) + # The breakpoint should have a hit count of 1. self.ci.HandleCommand("breakpoint list", res) self.assertTrue(res.Succeeded()) self.assertTrue(res.GetOutput().find('resolved, hit count = 1')) + # And the stop reason of the thread should be breakpoint. self.ci.HandleCommand("thread list", res) self.assertTrue(res.Succeeded()) self.assertTrue(res.GetOutput().find('state is Stopped') and res.GetOutput().find('stop reason = breakpoint')) + # Issue 'variable list' command on several array-type variables. + self.ci.HandleCommand("variable list strings", res); self.assertTrue(res.Succeeded()) output = res.GetOutput() Modified: lldb/trunk/test/class_types/TestClassTypes.py URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/class_types/TestClassTypes.py?rev=107333&r1=107332&r2=107333&view=diff ============================================================================== --- lldb/trunk/test/class_types/TestClassTypes.py (original) +++ lldb/trunk/test/class_types/TestClassTypes.py Wed Jun 30 17:22:37 2010 @@ -29,6 +29,7 @@ self.ci.HandleCommand("file " + exe, res) self.assertTrue(res.Succeeded()) + # Break on the ctor function of class C. self.ci.HandleCommand("breakpoint set -f main.cpp -l 73", res) self.assertTrue(res.Succeeded()) self.assertTrue(res.GetOutput().startswith( @@ -37,15 +38,18 @@ self.ci.HandleCommand("run", res) self.assertTrue(res.Succeeded()) + # The breakpoint should have a hit count of 1. self.ci.HandleCommand("breakpoint list", res) self.assertTrue(res.Succeeded()) self.assertTrue(res.GetOutput().find('resolved, hit count = 1')) + # And the stop reason of the thread should be breakpoint. self.ci.HandleCommand("thread list", res) self.assertTrue(res.Succeeded()) self.assertTrue(res.GetOutput().find('state is Stopped') and res.GetOutput().find('stop reason = breakpoint')) + # We should be stopped on the ctor function of class C. self.ci.HandleCommand("variable list this", res); self.assertTrue(res.Succeeded()) self.assertTrue(res.GetOutput().startswith('(class C *const) this = ')) From gclayton at apple.com Wed Jun 30 18:03:03 2010 From: gclayton at apple.com (Greg Clayton) Date: Wed, 30 Jun 2010 23:03:03 -0000 Subject: [Lldb-commits] [lldb] r107350 - in /lldb/trunk: include/lldb/API/ include/lldb/Core/ include/lldb/Target/ source/API/ source/Commands/ source/Core/ source/Plugins/Disassembler/llvm/ source/Symbol/ source/Target/ Message-ID: <20100630230303.8406A2A6C12C@llvm.org> Author: gclayton Date: Wed Jun 30 18:03:03 2010 New Revision: 107350 URL: http://llvm.org/viewvc/llvm-project?rev=107350&view=rev Log: Centralized all disassembly into static functions in source/Core/Disassembler.cpp. Added the ability to read memory from the target's object files when we aren't running, so disassembling works before you run! Cleaned up the API to lldb_private::Target::ReadMemory(). Cleaned up the API to the Disassembler to use actual "lldb_private::Address" objects instead of just an "addr_t". This is nice because the Address objects when resolved carry along their section and module which can get us the object file. This allows Target::ReadMemory to be used when we are not running. Added a new lldb_private::Address dump style: DumpStyleDetailedSymbolContext This will show a full breakdown of what an address points to. To see some sample output, execute a "image lookup --address ". Fixed SymbolContext::DumpStopContext(...) to not require a live process in order to be able to print function and symbol offsets. Modified: lldb/trunk/include/lldb/API/SBTarget.h lldb/trunk/include/lldb/Core/Address.h lldb/trunk/include/lldb/Core/Disassembler.h lldb/trunk/include/lldb/Core/FileSpec.h lldb/trunk/include/lldb/Core/Section.h lldb/trunk/include/lldb/Target/Target.h lldb/trunk/source/API/SBTarget.cpp lldb/trunk/source/Commands/CommandObjectDisassemble.cpp lldb/trunk/source/Commands/CommandObjectDisassemble.h lldb/trunk/source/Commands/CommandObjectImage.cpp lldb/trunk/source/Core/Address.cpp lldb/trunk/source/Core/Disassembler.cpp lldb/trunk/source/Core/FileSpec.cpp lldb/trunk/source/Core/Section.cpp lldb/trunk/source/Plugins/Disassembler/llvm/DisassemblerLLVM.cpp lldb/trunk/source/Plugins/Disassembler/llvm/DisassemblerLLVM.h lldb/trunk/source/Symbol/SymbolContext.cpp lldb/trunk/source/Target/StackFrame.cpp lldb/trunk/source/Target/Target.cpp Modified: lldb/trunk/include/lldb/API/SBTarget.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBTarget.h?rev=107350&r1=107349&r2=107350&view=diff ============================================================================== --- lldb/trunk/include/lldb/API/SBTarget.h (original) +++ lldb/trunk/include/lldb/API/SBTarget.h Wed Jun 30 18:03:03 2010 @@ -122,7 +122,8 @@ //Disassemble (); void - Disassemble (lldb::addr_t file_address_start, lldb::addr_t file_address_end = LLDB_INVALID_ADDRESS, + Disassemble (lldb::addr_t start_address, + lldb::addr_t end_address = LLDB_INVALID_ADDRESS, const char *module_name = NULL); void Modified: lldb/trunk/include/lldb/Core/Address.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/Address.h?rev=107350&r1=107349&r2=107350&view=diff ============================================================================== --- lldb/trunk/include/lldb/Core/Address.h (original) +++ lldb/trunk/include/lldb/Core/Address.h Wed Jun 30 18:03:03 2010 @@ -82,7 +82,12 @@ ///< \code /// // address for printf in libSystem.B.dylib as a load address /// 0x00007fff8306bcff \endcode - DumpStyleResolvedDescription ///< Display the name that an address resolves to + DumpStyleResolvedDescription, ///< Display the details about what an address resolves to. This can + ///< be anything from a symbol context summary (module, function/symbol, + ///< and file and line), to information about what the pointer points to + ///< if the address is in a section (section of pointers, c strings, etc). + DumpStyleDetailedSymbolContext ///< Detailed symbol context information for an address for all symbol + ///< context members. } DumpStyle; //------------------------------------------------------------------ @@ -221,7 +226,8 @@ Dump (Stream *s, ExecutionContextScope *exe_scope, DumpStyle style, - DumpStyle fallback_style = DumpStyleInvalid) const; + DumpStyle fallback_style = DumpStyleInvalid, + uint32_t addr_byte_size = UINT32_MAX) const; //------------------------------------------------------------------ /// Dump a debug description of this object to a Stream. Modified: lldb/trunk/include/lldb/Core/Disassembler.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/Disassembler.h?rev=107350&r1=107349&r2=107350&view=diff ============================================================================== --- lldb/trunk/include/lldb/Core/Disassembler.h (original) +++ lldb/trunk/include/lldb/Core/Disassembler.h Wed Jun 30 18:03:03 2010 @@ -42,8 +42,13 @@ GetByteSize() const = 0; virtual void - Dump (Stream *s, lldb::addr_t base_address, DataExtractor *bytes, uint32_t bytes_offset, const lldb_private::ExecutionContext exe_ctx, bool raw) = 0; - + Dump (Stream *s, + Address *address, + const DataExtractor *bytes, + uint32_t bytes_offset, + const ExecutionContext &exe_ctx, + bool raw) = 0; + virtual bool DoesBranch () const = 0; @@ -89,7 +94,36 @@ Disassemble (Debugger &debugger, const ArchSpec &arch, const ExecutionContext &exe_ctx, - uint32_t mixed_context_lines, + const AddressRange &range, + uint32_t num_mixed_context_lines, + bool show_bytes, + Stream &strm); + + static size_t + Disassemble (Debugger &debugger, + const ArchSpec &arch, + const ExecutionContext &exe_ctx, + SymbolContextList &sc_list, + uint32_t num_mixed_context_lines, + bool show_bytes, + Stream &strm); + + static bool + Disassemble (Debugger &debugger, + const ArchSpec &arch, + const ExecutionContext &exe_ctx, + const ConstString &name, + Module *module, + uint32_t num_mixed_context_lines, + bool show_bytes, + Stream &strm); + + static bool + Disassemble (Debugger &debugger, + const ArchSpec &arch, + const ExecutionContext &exe_ctx, + uint32_t num_mixed_context_lines, + bool show_bytes, Stream &strm); //------------------------------------------------------------------ @@ -102,17 +136,14 @@ size_t ParseInstructions (const ExecutionContext *exe_ctx, - lldb::AddressType addr_type, - lldb::addr_t addr, - size_t byte_size, + const AddressRange &range, DataExtractor& data); virtual size_t - ParseInstructions (const DataExtractor& data, - uint32_t data_offset, - uint32_t num_instructions, - lldb::addr_t base_addr) = 0; - + DecodeInstructions (const DataExtractor& data, + uint32_t data_offset, + uint32_t num_instructions) = 0; + InstructionList & GetInstructionList (); Modified: lldb/trunk/include/lldb/Core/FileSpec.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/FileSpec.h?rev=107350&r1=107349&r2=107350&view=diff ============================================================================== --- lldb/trunk/include/lldb/Core/FileSpec.h (original) +++ lldb/trunk/include/lldb/Core/FileSpec.h Wed Jun 30 18:03:03 2010 @@ -392,6 +392,9 @@ lldb::DataBufferSP ReadFileContents (off_t offset = 0, size_t length = SIZE_MAX) const; + size_t + ReadFileContents (off_t file_offset, void *dst, size_t dst_len) const; + //------------------------------------------------------------------ /// Change the file specificed with a new path. /// Modified: lldb/trunk/include/lldb/Core/Section.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/Section.h?rev=107350&r1=107349&r2=107350&view=diff ============================================================================== --- lldb/trunk/include/lldb/Core/Section.h (original) +++ lldb/trunk/include/lldb/Core/Section.h Wed Jun 30 18:03:03 2010 @@ -218,6 +218,9 @@ MemoryMapSectionDataFromObjectFile (const ObjectFile* file, DataExtractor& section_data) const; size_t + ReadSectionDataFromObjectFile (const ObjectFile* objfile, off_t section_offset, void *dst, size_t dst_len) const; + + size_t ReadSectionDataFromObjectFile (const ObjectFile* file, DataExtractor& section_data) const; ConstString& Modified: lldb/trunk/include/lldb/Target/Target.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/Target.h?rev=107350&r1=107349&r2=107350&view=diff ============================================================================== --- lldb/trunk/include/lldb/Target/Target.h (original) +++ lldb/trunk/include/lldb/Target/Target.h Wed Jun 30 18:03:03 2010 @@ -264,13 +264,11 @@ GetTargetTriple (ConstString &target_triple); size_t - ReadMemory (lldb::AddressType addr_type, - lldb::addr_t addr, - void *buf, - size_t size, - Error &error, - ObjectFile* objfile = NULL); - + ReadMemory (const Address& addr, + void *dst, + size_t dst_len, + Error &error); + //------------------------------------------------------------------ // lldb::ExecutionContextScope pure virtual functions //------------------------------------------------------------------ Modified: lldb/trunk/source/API/SBTarget.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBTarget.cpp?rev=107350&r1=107349&r2=107350&view=diff ============================================================================== --- lldb/trunk/source/API/SBTarget.cpp (original) +++ lldb/trunk/source/API/SBTarget.cpp Wed Jun 30 18:03:03 2010 @@ -384,9 +384,9 @@ } void -SBTarget::Disassemble (lldb::addr_t file_address_start, lldb::addr_t file_address_end, const char *module_name) +SBTarget::Disassemble (lldb::addr_t start_addr, lldb::addr_t end_addr, const char *module_name) { - if (file_address_start == LLDB_INVALID_ADDRESS) + if (start_addr == LLDB_INVALID_ADDRESS) return; FILE *out = m_opaque_sp->GetDebugger().GetOutputFileHandle(); @@ -395,61 +395,65 @@ if (m_opaque_sp) { - SBModule module; + ModuleSP module_sp; if (module_name != NULL) { - SBFileSpec file_spec (module_name); - module = FindModule (file_spec); + FileSpec module_file_spec (module_name); + module_sp = m_opaque_sp->GetImages().FindFirstModuleForFileSpec (module_file_spec, NULL); + } + + AddressRange range; + + // Make sure the process object is alive if we have one (it might be + // created but we might not be launched yet). + Process *process = m_opaque_sp->GetProcessSP().get(); + if (process && !process->IsAlive()) + process = NULL; + + // If we are given a module, then "start_addr" is a file address in + // that module. + if (module_sp) + { + if (!module_sp->ResolveFileAddress (start_addr, range.GetBaseAddress())) + range.GetBaseAddress().SetOffset(start_addr); + } + else if (process) + { + // We don't have a module, se we need to figure out if "start_addr" + // resolves to anything in a running process. + if (!process->ResolveLoadAddress(start_addr, range.GetBaseAddress())) + range.GetBaseAddress().SetOffset(start_addr); + } + else + { + if (m_opaque_sp->GetImages().ResolveFileAddress (start_addr, range.GetBaseAddress())) + range.GetBaseAddress().SetOffset(start_addr); } - ArchSpec arch (m_opaque_sp->GetArchitecture()); - if (!arch.IsValid()) - return; - Disassembler *disassembler = Disassembler::FindPlugin (arch); - if (disassembler == NULL) - return; // For now, we need a process; the disassembly functions insist. If we don't have one already, // make one. - SBProcess process = GetProcess(); - if (! process.IsValid()) - process = CreateProcess(); - - ExecutionContext exe_context (process.get()); - - if (file_address_end == LLDB_INVALID_ADDRESS - || file_address_end < file_address_start) - file_address_end = file_address_start + DEFAULT_DISASM_BYTE_SIZE; - - // TO BE FIXED: SOMEHOW WE NEED TO SPECIFY/USE THE MODULE, IF THE USER SPECIFIED ONE. I'M NOT - // SURE HOW TO DO THAT AT THE MOMENT. WE ALSO NEED TO FIGURE OUT WHAT TO DO IF THERE ARE MULTIPLE - // MODULES CONTAINING THE SPECIFIED ADDRESSES (E.G. THEY HAVEN'T ALL LOADED & BEEN GIVEN UNIQUE - // ADDRESSES YET). - - DataExtractor data; - size_t bytes_disassembled = disassembler->ParseInstructions (&exe_context, eAddressTypeLoad, - file_address_start, - file_address_end - file_address_start, data); + ExecutionContext exe_ctx; - if (bytes_disassembled > 0) - { - size_t num_instructions = disassembler->GetInstructionList().GetSize(); - uint32_t offset = 0; - StreamFile out_stream (out); - - for (size_t i = 0; i < num_instructions; ++i) - { - Disassembler::Instruction *inst = disassembler->GetInstructionList().GetInstructionAtIndex (i); - if (inst) - { - lldb::addr_t cur_addr = file_address_start + offset; - size_t inst_byte_size = inst->GetByteSize(); - inst->Dump (&out_stream, cur_addr, &data, offset, exe_context, false); - out_stream.EOL(); - offset += inst_byte_size; - } - } - } + if (process) + process->Calculate(exe_ctx); + else + m_opaque_sp->Calculate(exe_ctx); + + if (end_addr == LLDB_INVALID_ADDRESS || end_addr < start_addr) + range.SetByteSize( DEFAULT_DISASM_BYTE_SIZE); + else + range.SetByteSize(end_addr - start_addr); + + StreamFile out_stream (out); + + Disassembler::Disassemble (m_opaque_sp->GetDebugger(), + m_opaque_sp->GetArchitecture(), + exe_ctx, + range, + 3, + false, + out_stream); } } @@ -465,102 +469,40 @@ if (m_opaque_sp) { - SBModule module; - - if (module_name != NULL) - { - SBFileSpec file_spec (module_name); - module = FindModule (file_spec); - } - - ArchSpec arch (m_opaque_sp->GetArchitecture()); - if (!arch.IsValid()) - return; - - Disassembler *disassembler = Disassembler::FindPlugin (arch); + Disassembler *disassembler = Disassembler::FindPlugin (m_opaque_sp->GetArchitecture()); if (disassembler == NULL) return; - // For now, we need a process; the disassembly functions insist. If we don't have one already, - // make one. - - SBProcess process = GetProcess(); - if (! process.IsValid() - || process.GetProcessID() == 0) - { - fprintf (out, "Cannot disassemble functions until after process has launched.\n"); - return; - } - - ExecutionContext exe_context (process.get()); - - FileSpec *containing_module = NULL; - + ModuleSP module_sp; if (module_name != NULL) - containing_module = new FileSpec (module_name); - - SearchFilterSP filter_sp (m_opaque_sp->GetSearchFilterForModule (containing_module)); - AddressResolverSP resolver_sp (new AddressResolverName (function_name)); - - resolver_sp->ResolveAddress (*filter_sp); - - size_t num_matches_found = resolver_sp->GetNumberOfAddresses(); - - if (num_matches_found == 1) { - DataExtractor data; - - AddressRange func_addresses = resolver_sp->GetAddressRangeAtIndex (0); - Address start_addr = func_addresses.GetBaseAddress(); - lldb::addr_t num_bytes = func_addresses.GetByteSize(); - - lldb::addr_t addr = LLDB_INVALID_ADDRESS; - size_t bytes_disassembled = 0; - - - if (process.GetProcessID() == 0) - { - // Leave this branch in for now, but it should not be reached, since we exit above if the PID is 0. - addr = start_addr.GetFileAddress (); - bytes_disassembled = disassembler->ParseInstructions (&exe_context, eAddressTypeFile, addr, - num_bytes, data); - - } - else - { - addr = start_addr.GetLoadAddress (process.get()); - bytes_disassembled = disassembler->ParseInstructions (&exe_context, eAddressTypeLoad, addr, - num_bytes, data); - - } - - if (bytes_disassembled > 0) - { - size_t num_instructions = disassembler->GetInstructionList().GetSize(); - uint32_t offset = 0; - StreamFile out_stream (out); - - for (size_t i = 0; i < num_instructions; ++i) - { - Disassembler::Instruction *inst = disassembler->GetInstructionList().GetInstructionAtIndex (i); - if (inst) - { - lldb::addr_t cur_addr = addr + offset; - size_t inst_byte_size = inst->GetByteSize(); - inst->Dump (&out_stream, cur_addr, &data, offset, exe_context, false); - out_stream.EOL(); - offset += inst_byte_size; - } - } - } + FileSpec module_file_spec (module_name); + module_sp = m_opaque_sp->GetImages().FindFirstModuleForFileSpec (module_file_spec, NULL); } - else if (num_matches_found > 1) - { - // TO BE FIXED: Eventually we want to list/disassemble all functions found. - fprintf (out, "Function '%s' was found in multiple modules; please specify the desired module name.\n", - function_name); - } - else - fprintf (out, "Function '%s' was not found.\n", function_name); + + ExecutionContext exe_ctx; + + // Make sure the process object is alive if we have one (it might be + // created but we might not be launched yet). + Process *process = m_opaque_sp->GetProcessSP().get(); + if (process && !process->IsAlive()) + process = NULL; + + if (process) + process->Calculate(exe_ctx); + else + m_opaque_sp->Calculate(exe_ctx); + + + StreamFile out_stream (out); + + Disassembler::Disassemble (m_opaque_sp->GetDebugger(), + m_opaque_sp->GetArchitecture(), + exe_ctx, + ConstString (function_name), + module_sp.get(), + 3, + false, + out_stream); } } Modified: lldb/trunk/source/Commands/CommandObjectDisassemble.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectDisassemble.cpp?rev=107350&r1=107349&r2=107350&view=diff ============================================================================== --- lldb/trunk/source/Commands/CommandObjectDisassemble.cpp (original) +++ lldb/trunk/source/Commands/CommandObjectDisassemble.cpp Wed Jun 30 18:03:03 2010 @@ -152,135 +152,6 @@ { } -void -CommandObjectDisassemble::Disassemble -( - CommandInterpreter &interpreter, - CommandReturnObject &result, - Disassembler *disassembler, - const SymbolContextList &sc_list -) -{ - const size_t count = sc_list.GetSize(); - SymbolContext sc; - AddressRange range; - for (size_t i=0; i= end_addr) - end_addr = addr + DEFAULT_DISASM_BYTE_SIZE; - - ExecutionContext exe_ctx (interpreter.GetDebugger().GetExecutionContext()); - DataExtractor data; - size_t bytes_disassembled = disassembler->ParseInstructions (&exe_ctx, eAddressTypeLoad, addr, end_addr - addr, data); - if (bytes_disassembled == 0) - { - // Nothing got disassembled... - } - else - { - // We got some things disassembled... - size_t num_instructions = disassembler->GetInstructionList().GetSize(); - uint32_t offset = 0; - Stream &output_stream = result.GetOutputStream(); - SymbolContext sc; - SymbolContext prev_sc; - AddressRange sc_range; - if (m_options.show_mixed) - output_stream.IndentMore (); - - for (size_t i=0; iGetInstructionList().GetInstructionAtIndex (i); - if (inst) - { - lldb::addr_t curr_addr = addr + offset; - if (m_options.show_mixed) - { - Process *process = interpreter.GetDebugger().GetExecutionContext().process; - if (!sc_range.ContainsLoadAddress (curr_addr, process)) - { - prev_sc = sc; - Address curr_so_addr; - if (process && process->ResolveLoadAddress (curr_addr, curr_so_addr)) - { - if (curr_so_addr.GetSection()) - { - Module *module = curr_so_addr.GetSection()->GetModule(); - uint32_t resolved_mask = module->ResolveSymbolContextForAddress(curr_so_addr, eSymbolContextEverything, sc); - if (resolved_mask) - { - sc.GetAddressRange (eSymbolContextEverything, sc_range); - if (sc != prev_sc) - { - if (offset != 0) - output_stream.EOL(); - - sc.DumpStopContext(&output_stream, process, curr_so_addr); - output_stream.EOL(); - if (sc.comp_unit && sc.line_entry.IsValid()) - { - interpreter.GetDebugger().GetSourceManager().DisplaySourceLinesWithLineNumbers ( - sc.line_entry.file, - sc.line_entry.line, - m_options.num_lines_context, - m_options.num_lines_context, - m_options.num_lines_context ? "->" : "", - &output_stream); - } - } - } - } - } - } - } - if (m_options.show_mixed) - output_stream.IndentMore (); - output_stream.Indent(); - size_t inst_byte_size = inst->GetByteSize(); - inst->Dump(&output_stream, curr_addr, m_options.show_bytes ? &data : NULL, offset, exe_ctx, m_options.raw); - output_stream.EOL(); - offset += inst_byte_size; - if (m_options.show_mixed) - output_stream.IndentLess (); - } - else - { - break; - } - } - if (m_options.show_mixed) - output_stream.IndentLess (); - - } -} - bool CommandObjectDisassemble::Execute ( @@ -316,100 +187,95 @@ result.SetStatus (eReturnStatusSuccessFinishResult); - lldb::addr_t addr = LLDB_INVALID_ADDRESS; - lldb::addr_t end_addr = LLDB_INVALID_ADDRESS; - ConstString name; - const size_t argc = command.GetArgumentCount(); - if (argc != 0) + if (command.GetArgumentCount() != 0) { result.AppendErrorWithFormat ("\"disassemble\" doesn't take any arguments.\n"); result.SetStatus (eReturnStatusFailed); return false; } - - if (m_options.m_start_addr != LLDB_INVALID_ADDRESS) + ExecutionContext exe_ctx(interpreter.GetDebugger().GetExecutionContext()); + + if (m_options.show_mixed && m_options.num_lines_context == 0) + m_options.num_lines_context = 3; + + if (!m_options.m_func_name.empty()) { - addr = m_options.m_start_addr; - if (m_options.m_end_addr != LLDB_INVALID_ADDRESS) + ConstString name(m_options.m_func_name.c_str()); + + if (Disassembler::Disassemble (interpreter.GetDebugger(), + arch, + exe_ctx, + name, + NULL, // Module * + m_options.show_mixed ? m_options.num_lines_context : 0, + m_options.show_bytes, + result.GetOutputStream())) { - end_addr = m_options.m_end_addr; - if (end_addr < addr) - { - result.AppendErrorWithFormat ("End address before start address.\n"); - result.SetStatus (eReturnStatusFailed); - return false; - } + result.SetStatus (eReturnStatusSuccessFinishResult); } else - end_addr = addr + DEFAULT_DISASM_BYTE_SIZE; - } - else if (!m_options.m_func_name.empty()) - { - ConstString tmpname(m_options.m_func_name.c_str()); - name = tmpname; + { + result.AppendErrorWithFormat ("Unable to find symbol with name '%s'.\n", name.GetCString()); + result.SetStatus (eReturnStatusFailed); + } } else { - ExecutionContext exe_ctx(interpreter.GetDebugger().GetExecutionContext()); - if (exe_ctx.frame) + AddressRange range; + if (m_options.m_start_addr != LLDB_INVALID_ADDRESS) { - SymbolContext sc(exe_ctx.frame->GetSymbolContext(eSymbolContextFunction | eSymbolContextSymbol)); - if (sc.function) + range.GetBaseAddress().SetOffset (m_options.m_start_addr); + if (m_options.m_end_addr != LLDB_INVALID_ADDRESS) { - addr = sc.function->GetAddressRange().GetBaseAddress().GetLoadAddress(exe_ctx.process); - if (addr != LLDB_INVALID_ADDRESS) - end_addr = addr + sc.function->GetAddressRange().GetByteSize(); - } - else if (sc.symbol && sc.symbol->GetAddressRangePtr()) - { - addr = sc.symbol->GetAddressRangePtr()->GetBaseAddress().GetLoadAddress(exe_ctx.process); - if (addr != LLDB_INVALID_ADDRESS) + if (m_options.m_end_addr < m_options.m_start_addr) { - end_addr = addr + sc.symbol->GetAddressRangePtr()->GetByteSize(); - if (addr == end_addr) - end_addr += DEFAULT_DISASM_BYTE_SIZE; + result.AppendErrorWithFormat ("End address before start address.\n"); + result.SetStatus (eReturnStatusFailed); + return false; } + range.SetByteSize (m_options.m_end_addr - m_options.m_start_addr); } else - { - addr = exe_ctx.frame->GetPC().GetLoadAddress(exe_ctx.process); - if (addr != LLDB_INVALID_ADDRESS) - end_addr = addr + DEFAULT_DISASM_BYTE_SIZE; - } - } + range.SetByteSize (DEFAULT_DISASM_BYTE_SIZE); + } else { - result.AppendError ("invalid frame"); - result.SetStatus (eReturnStatusFailed); - return false; + if (exe_ctx.frame) + { + SymbolContext sc(exe_ctx.frame->GetSymbolContext(eSymbolContextFunction | eSymbolContextSymbol)); + if (sc.function) + range = sc.function->GetAddressRange(); + else if (sc.symbol && sc.symbol->GetAddressRangePtr()) + range = *sc.symbol->GetAddressRangePtr(); + else + range.GetBaseAddress() = exe_ctx.frame->GetPC(); + } + else + { + result.AppendError ("invalid frame"); + result.SetStatus (eReturnStatusFailed); + return false; + } } - } + if (range.GetByteSize() == 0) + range.SetByteSize(DEFAULT_DISASM_BYTE_SIZE); - if (!name.IsEmpty()) - { - SymbolContextList sc_list; - - if (target->GetImages().FindFunctions(name, - eFunctionNameTypeBase | eFunctionNameTypeFull | eFunctionNameTypeMethod | eFunctionNameTypeSelector, - sc_list)) - { - Disassemble (interpreter, result, disassembler, sc_list); - } - else if (target->GetImages().FindSymbolsWithNameAndType(name, eSymbolTypeCode, sc_list)) + if (Disassembler::Disassemble (interpreter.GetDebugger(), + arch, + exe_ctx, + range, + m_options.show_mixed ? m_options.num_lines_context : 0, + m_options.show_bytes, + result.GetOutputStream())) { - Disassemble (interpreter, result, disassembler, sc_list); + result.SetStatus (eReturnStatusSuccessFinishResult); } else { - result.AppendErrorWithFormat ("Unable to find symbol with name '%s'.\n", name.GetCString()); - result.SetStatus (eReturnStatusFailed); - return false; + result.AppendErrorWithFormat ("Failed to disassemble memory at 0x%8.8llx.\n", m_options.m_start_addr); + result.SetStatus (eReturnStatusFailed); } } - else - { - Disassemble (interpreter, result, disassembler, addr, end_addr); - } return result.Succeeded(); } Modified: lldb/trunk/source/Commands/CommandObjectDisassemble.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectDisassemble.h?rev=107350&r1=107349&r2=107350&view=diff ============================================================================== --- lldb/trunk/source/Commands/CommandObjectDisassemble.h (original) +++ lldb/trunk/source/Commands/CommandObjectDisassemble.h Wed Jun 30 18:03:03 2010 @@ -74,18 +74,6 @@ protected: CommandOptions m_options; - void - Disassemble (CommandInterpreter &interpreter, - CommandReturnObject &result, - Disassembler *disassembler, - lldb::addr_t addr, - lldb::addr_t end_addr); - - void - Disassemble (CommandInterpreter &interpreter, - CommandReturnObject &result, - Disassembler *disassembler, - const SymbolContextList &sc_list); }; } // namespace lldb_private Modified: lldb/trunk/source/Commands/CommandObjectImage.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectImage.cpp?rev=107350&r1=107349&r2=107350&view=diff ============================================================================== --- lldb/trunk/source/Commands/CommandObjectImage.cpp (original) +++ lldb/trunk/source/Commands/CommandObjectImage.cpp Wed Jun 30 18:03:03 2010 @@ -231,7 +231,11 @@ strm.Indent (" Address: "); so_addr.Dump (&strm, exe_scope, Address::DumpStyleSectionNameOffset); strm.EOL(); + strm.Indent (" Summary: "); so_addr.Dump (&strm, exe_scope, Address::DumpStyleResolvedDescription); + strm.EOL(); + if (so_addr.Dump (&strm, exe_scope, Address::DumpStyleDetailedSymbolContext)) + strm.EOL(); strm.IndentLess(); return true; } Modified: lldb/trunk/source/Core/Address.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/Address.cpp?rev=107350&r1=107349&r2=107350&view=diff ============================================================================== --- lldb/trunk/source/Core/Address.cpp (original) +++ lldb/trunk/source/Core/Address.cpp Wed Jun 30 18:03:03 2010 @@ -17,39 +17,57 @@ using namespace lldb; using namespace lldb_private; +//static size_t +//ReadBytes (ExecutionContextScope *exe_scope, const Address &address, void *dst, size_t dst_len) +//{ +// if (exe_scope == NULL) +// return 0; +// +// lldb::AddressType addr_type = eAddressTypeInvalid; +// addr_t addr = LLDB_INVALID_ADDRESS; +// +// Process *process = exe_scope->CalculateProcess(); +// +// if (process && process->IsAlive()) +// { +// addr = address.GetLoadAddress(process); +// if (addr != LLDB_INVALID_ADDRESS) +// addr_type = eAddressTypeLoad; +// } +// +// if (addr == LLDB_INVALID_ADDRESS) +// { +// addr = address.GetFileAddress(); +// if (addr != LLDB_INVALID_ADDRESS) +// addr_type = eAddressTypeFile; +// } +// +// if (addr_type == eAddressTypeInvalid) +// return false; +// +// Target *target = exe_scope->CalculateTarget(); +// if (target) +// { +// Error error; +// ObjectFile *objfile = NULL; +// if (address.GetModule()) +// objfile = address.GetModule()->GetObjectFile(); +// return target->ReadMemory (addr_type, addr, dst, dst_len, error, objfile); +// } +// return 0; +//} + static size_t ReadBytes (ExecutionContextScope *exe_scope, const Address &address, void *dst, size_t dst_len) { if (exe_scope == NULL) return 0; - lldb::AddressType addr_type = eAddressTypeInvalid; - addr_t addr = LLDB_INVALID_ADDRESS; - - Process *process = exe_scope->CalculateProcess(); - - if (process && process->IsAlive()) - { - addr = address.GetLoadAddress(process); - if (addr != LLDB_INVALID_ADDRESS) - addr_type = eAddressTypeLoad; - } - - if (addr == LLDB_INVALID_ADDRESS) - { - addr = address.GetFileAddress(); - if (addr != LLDB_INVALID_ADDRESS) - addr_type = eAddressTypeFile; - } - - if (addr_type == eAddressTypeInvalid) - return false; - Target *target = exe_scope->CalculateTarget(); if (target) { Error error; - return target->ReadMemory (addr_type, addr, dst, dst_len, error, NULL); + return target->ReadMemory (address, dst, dst_len, error); } return 0; } @@ -386,7 +404,7 @@ bool -Address::Dump (Stream *s, ExecutionContextScope *exe_scope, DumpStyle style, DumpStyle fallback_style) const +Address::Dump (Stream *s, ExecutionContextScope *exe_scope, DumpStyle style, DumpStyle fallback_style, uint32_t addr_size) const { // If the section was NULL, only load address is going to work. if (m_section == NULL) @@ -395,12 +413,17 @@ Process *process = NULL; if (exe_scope) process = exe_scope->CalculateProcess(); - int addr_size = sizeof (addr_t); - if (process) - addr_size = process->GetAddressByteSize (); + // If addr_byte_size is UINT32_MAX, then determine the correct address + // byte size for the process or default to the size of addr_t + if (addr_size == UINT32_MAX) + { + if (process) + addr_size = process->GetAddressByteSize (); + else + addr_size = sizeof(addr_t); + } lldb_private::Address so_addr; - switch (style) { case DumpStyleSectionNameOffset: @@ -411,12 +434,13 @@ } else { - s->Printf("0x%16.16llx", m_offset); + s->Address(m_offset, addr_size); } break; case DumpStyleSectionPointerOffset: - s->Printf("(Section *)%.*p + 0x%16.16llx", (int)sizeof(void*) * 2, m_section, m_offset); + s->Printf("(Section *)%.*p + ", (int)sizeof(void*) * 2, m_section); + s->Address(m_offset, addr_size); break; case DumpStyleModuleWithFileAddress: @@ -428,7 +452,7 @@ if (file_addr == LLDB_INVALID_ADDRESS) { if (fallback_style != DumpStyleInvalid) - return Dump (s, exe_scope, fallback_style); + return Dump (s, exe_scope, fallback_style, DumpStyleInvalid, addr_size); return false; } s->Address (file_addr, addr_size); @@ -443,7 +467,7 @@ if (load_addr == LLDB_INVALID_ADDRESS) { if (fallback_style != DumpStyleInvalid) - return Dump (s, exe_scope, fallback_style); + return Dump (s, exe_scope, fallback_style, DumpStyleInvalid, addr_size); return false; } s->Address (load_addr, addr_size); @@ -592,13 +616,17 @@ if (so_addr.IsSectionOffset()) { lldb_private::SymbolContext pointer_sc; - process->GetTarget().GetImages().ResolveSymbolContextForAddress (so_addr, - eSymbolContextEverything, - pointer_sc); - if (pointer_sc.function || pointer_sc.symbol) + Target *target = exe_scope->CalculateTarget(); + if (target) { - s->PutCString(": "); - pointer_sc.DumpStopContext(s, process, so_addr, false); + target->GetImages().ResolveSymbolContextForAddress (so_addr, + eSymbolContextEverything, + pointer_sc); + if (pointer_sc.function || pointer_sc.symbol) + { + s->PutCString(": "); + pointer_sc.DumpStopContext(s, process, so_addr, false); + } } } } @@ -629,10 +657,7 @@ { // We have a function or a symbol from the same // sections as this address. - s->Indent(" Summary: "); - sc.DumpStopContext(s, process, *this, false); - s->EOL(); - sc.GetDescription(s, eDescriptionLevelBrief, process); + sc.DumpStopContext(s, process, *this, true); } else { @@ -648,10 +673,45 @@ else { if (fallback_style != DumpStyleInvalid) - return Dump (s, exe_scope, fallback_style); + return Dump (s, exe_scope, fallback_style, DumpStyleInvalid, addr_size); return false; } break; + + case DumpStyleDetailedSymbolContext: + if (IsSectionOffset()) + { + lldb::AddressType addr_type = eAddressTypeLoad; + addr_t addr = GetLoadAddress (process); + if (addr == LLDB_INVALID_ADDRESS) + { + addr = GetFileAddress(); + addr_type = eAddressTypeFile; + } + + lldb_private::Module *module = GetModule(); + if (module) + { + lldb_private::SymbolContext sc; + module->ResolveSymbolContextForAddress(*this, eSymbolContextEverything, sc); + if (sc.function || sc.symbol) + { + if (sc.function == NULL && sc.symbol != NULL) + { + // If we have just a symbol make sure it is in the right section + if (sc.symbol->GetAddressRangePtr() && sc.symbol->GetAddressRangePtr()->GetBaseAddress().GetSection() == GetSection()) + { + sc.GetDescription(s, eDescriptionLevelBrief, process); + break; + } + } + } + } + } + if (fallback_style != DumpStyleInvalid) + return Dump (s, exe_scope, fallback_style, DumpStyleInvalid, addr_size); + return false; + break; } return true; Modified: lldb/trunk/source/Core/Disassembler.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/Disassembler.cpp?rev=107350&r1=107349&r2=107350&view=diff ============================================================================== --- lldb/trunk/source/Core/Disassembler.cpp (original) +++ lldb/trunk/source/Core/Disassembler.cpp Wed Jun 30 18:03:03 2010 @@ -52,53 +52,121 @@ return NULL; } -bool + + +size_t Disassembler::Disassemble ( Debugger &debugger, const ArchSpec &arch, const ExecutionContext &exe_ctx, - uint32_t mixed_context_lines, + SymbolContextList &sc_list, + uint32_t num_mixed_context_lines, + bool show_bytes, Stream &strm ) { - Disassembler *disassembler = Disassembler::FindPlugin(arch); - - if (disassembler) + size_t success_count = 0; + const size_t count = sc_list.GetSize(); + SymbolContext sc; + AddressRange range; + for (size_t i=0; iGetSymbolContext(eSymbolContextFunction | eSymbolContextSymbol)); - if (sc.function) + if (Disassemble (debugger, arch, exe_ctx, range, num_mixed_context_lines, show_bytes, strm)) { - addr = sc.function->GetAddressRange().GetBaseAddress().GetLoadAddress(exe_ctx.process); - if (addr != LLDB_INVALID_ADDRESS) - byte_size = sc.function->GetAddressRange().GetByteSize(); + ++success_count; + strm.EOL(); } - else if (sc.symbol && sc.symbol->GetAddressRangePtr()) + } + } + return success_count; +} + +bool +Disassembler::Disassemble +( + Debugger &debugger, + const ArchSpec &arch, + const ExecutionContext &exe_ctx, + const ConstString &name, + Module *module, + uint32_t num_mixed_context_lines, + bool show_bytes, + Stream &strm +) +{ + if (exe_ctx.target == NULL && name) + return false; + + SymbolContextList sc_list; + + if (module) + { + if (!module->FindFunctions (name, + eFunctionNameTypeBase | eFunctionNameTypeFull | eFunctionNameTypeMethod | eFunctionNameTypeSelector, + true, + sc_list)) + return false; + } + else + { + if (exe_ctx.target->GetImages().FindFunctions (name, + eFunctionNameTypeBase | eFunctionNameTypeFull | eFunctionNameTypeMethod | eFunctionNameTypeSelector, + sc_list)) + { + return Disassemble (debugger, arch, exe_ctx, sc_list, num_mixed_context_lines, show_bytes, strm); + } + else if (exe_ctx.target->GetImages().FindSymbolsWithNameAndType(name, eSymbolTypeCode, sc_list)) + { + return Disassemble (debugger, arch, exe_ctx, sc_list, num_mixed_context_lines, show_bytes, strm); + } + } + return false; +} + +bool +Disassembler::Disassemble +( + Debugger &debugger, + const ArchSpec &arch, + const ExecutionContext &exe_ctx, + const AddressRange &disasm_range, + uint32_t num_mixed_context_lines, + bool show_bytes, + Stream &strm +) +{ + if (disasm_range.GetByteSize()) + { + Disassembler *disassembler = Disassembler::FindPlugin(arch); + + if (disassembler) + { + AddressRange range(disasm_range); + + Process *process = exe_ctx.process; + + // If we weren't passed in a section offset address range, + // try and resolve it to something + if (range.GetBaseAddress().IsSectionOffset() == false) { - addr = sc.symbol->GetAddressRangePtr()->GetBaseAddress().GetLoadAddress(exe_ctx.process); - if (addr != LLDB_INVALID_ADDRESS) + if (process && process->IsAlive()) { - byte_size = sc.symbol->GetAddressRangePtr()->GetByteSize(); - if (byte_size == 0) - byte_size = DEFAULT_DISASM_BYTE_SIZE; + process->ResolveLoadAddress (range.GetBaseAddress().GetOffset(), range.GetBaseAddress()); + } + else if (exe_ctx.target) + { + exe_ctx.target->GetImages().ResolveFileAddress (range.GetBaseAddress().GetOffset(), range.GetBaseAddress()); } } - else - { - addr = exe_ctx.frame->GetPC().GetLoadAddress(exe_ctx.process); - if (addr != LLDB_INVALID_ADDRESS) - byte_size = DEFAULT_DISASM_BYTE_SIZE; - } - } - if (byte_size) - { + DataExtractor data; - size_t bytes_disassembled = disassembler->ParseInstructions (&exe_ctx, eAddressTypeLoad, addr, byte_size, data); + size_t bytes_disassembled = disassembler->ParseInstructions (&exe_ctx, range, data); if (bytes_disassembled == 0) { return false; @@ -111,63 +179,94 @@ SymbolContext sc; SymbolContext prev_sc; AddressRange sc_range; - if (mixed_context_lines) + if (num_mixed_context_lines) strm.IndentMore (); + + Address addr(range.GetBaseAddress()); + + // We extract the section to make sure we don't transition out + // of the current section when disassembling + const Section *addr_section = addr.GetSection(); + Module *range_module = range.GetBaseAddress().GetModule(); + for (size_t i=0; iGetInstructionList().GetInstructionAtIndex (i); if (inst) { - lldb::addr_t curr_addr = addr + offset; - if (mixed_context_lines) + addr_t file_addr = addr.GetFileAddress(); + if (addr_section == NULL || addr_section->ContainsFileAddress (file_addr) == false) { - if (!sc_range.ContainsLoadAddress (curr_addr, exe_ctx.process)) + if (range_module) + range_module->ResolveFileAddress (file_addr, addr); + else if (exe_ctx.target) + exe_ctx.target->GetImages().ResolveFileAddress (file_addr, addr); + + addr_section = addr.GetSection(); + } + + prev_sc = sc; + + if (addr_section) + { + Module *module = addr_section->GetModule(); + uint32_t resolved_mask = module->ResolveSymbolContextForAddress(addr, eSymbolContextEverything, sc); + if (resolved_mask) { - prev_sc = sc; - Address curr_so_addr; - Process *process = exe_ctx.process; - if (process && process->ResolveLoadAddress (curr_addr, curr_so_addr)) + if (prev_sc.function != sc.function || prev_sc.symbol != sc.symbol) { - if (curr_so_addr.GetSection()) + if (prev_sc.function || prev_sc.symbol) + strm.EOL(); + + strm << sc.module_sp->GetFileSpec().GetFilename(); + + if (sc.function) + strm << '`' << sc.function->GetMangled().GetName(); + else if (sc.symbol) + strm << '`' << sc.symbol->GetMangled().GetName(); + strm << ":\n"; + } + + if (num_mixed_context_lines && !sc_range.ContainsFileAddress (addr)) + { + sc.GetAddressRange (eSymbolContextEverything, sc_range); + + if (sc != prev_sc) { - Module *module = curr_so_addr.GetSection()->GetModule(); - uint32_t resolved_mask = module->ResolveSymbolContextForAddress(curr_so_addr, eSymbolContextEverything, sc); - if (resolved_mask) + if (offset != 0) + strm.EOL(); + + sc.DumpStopContext(&strm, process, addr); + + if (sc.comp_unit && sc.line_entry.IsValid()) { - sc.GetAddressRange (eSymbolContextEverything, sc_range); - if (sc != prev_sc) - { - if (offset != 0) - strm.EOL(); - - sc.DumpStopContext(&strm, process, curr_so_addr); - - if (sc.comp_unit && sc.line_entry.IsValid()) - { - debugger.GetSourceManager().DisplaySourceLinesWithLineNumbers ( - sc.line_entry.file, - sc.line_entry.line, - mixed_context_lines, - mixed_context_lines, - mixed_context_lines ? "->" : "", - &strm); - } - } + debugger.GetSourceManager().DisplaySourceLinesWithLineNumbers (sc.line_entry.file, + sc.line_entry.line, + num_mixed_context_lines, + num_mixed_context_lines, + num_mixed_context_lines ? "->" : "", + &strm); } } } } + else + { + sc.Clear(); + } } - if (mixed_context_lines) + if (num_mixed_context_lines) strm.IndentMore (); strm.Indent(); size_t inst_byte_size = inst->GetByteSize(); - //inst->Dump(&strm, curr_addr, &data, offset); // Do dump opcode bytes - inst->Dump(&strm, curr_addr, NULL, offset, exe_ctx, false); // Don't dump opcode bytes + inst->Dump(&strm, &addr, show_bytes ? &data : NULL, offset, exe_ctx, show_bytes); strm.EOL(); offset += inst_byte_size; - if (mixed_context_lines) + + addr.SetOffset (addr.GetOffset() + inst_byte_size); + + if (num_mixed_context_lines) strm.IndentLess (); } else @@ -175,7 +274,7 @@ break; } } - if (mixed_context_lines) + if (num_mixed_context_lines) strm.IndentLess (); } @@ -185,6 +284,42 @@ return false; } + +bool +Disassembler::Disassemble +( + Debugger &debugger, + const ArchSpec &arch, + const ExecutionContext &exe_ctx, + uint32_t num_mixed_context_lines, + bool show_bytes, + Stream &strm +) +{ + AddressRange range; + if (exe_ctx.frame) + { + SymbolContext sc(exe_ctx.frame->GetSymbolContext(eSymbolContextFunction | eSymbolContextSymbol)); + if (sc.function) + { + range = sc.function->GetAddressRange(); + } + else if (sc.symbol && sc.symbol->GetAddressRangePtr()) + { + range = *sc.symbol->GetAddressRangePtr(); + } + else + { + range.GetBaseAddress() = exe_ctx.frame->GetPC(); + } + + if (range.GetBaseAddress().IsValid() && range.GetByteSize() == 0) + range.SetByteSize (DEFAULT_DISASM_BYTE_SIZE); + } + + return Disassemble(debugger, arch, exe_ctx, range, num_mixed_context_lines, show_bytes, strm); +} + Disassembler::Instruction::Instruction() { } @@ -244,26 +379,39 @@ Disassembler::ParseInstructions ( const ExecutionContext *exe_ctx, - lldb::AddressType addr_type, - lldb::addr_t addr, - size_t byte_size, + const AddressRange &range, DataExtractor& data ) { - Process *process = exe_ctx->process; + Target *target = exe_ctx->target; - if (process == NULL) + const addr_t byte_size = range.GetByteSize(); + if (target == NULL || byte_size == 0 || !range.GetBaseAddress().IsValid()) return 0; - DataBufferSP data_sp(new DataBufferHeap (byte_size, '\0')); + DataBufferHeap *heap_buffer = new DataBufferHeap (byte_size, '\0'); + DataBufferSP data_sp(heap_buffer); Error error; - if (process->GetTarget().ReadMemory (addr_type, addr, data_sp->GetBytes(), data_sp->GetByteSize(), error, NULL)) + const size_t bytes_read = target->ReadMemory (range.GetBaseAddress(), heap_buffer->GetBytes(), heap_buffer->GetByteSize(), error); + + if (bytes_read > 0) { + if (bytes_read != heap_buffer->GetByteSize()) + heap_buffer->SetByteSize (bytes_read); + data.SetData(data_sp); - data.SetByteOrder(process->GetByteOrder()); - data.SetAddressByteSize(process->GetAddressByteSize()); - return ParseInstructions (data, 0, UINT32_MAX, addr); + if (exe_ctx->process) + { + data.SetByteOrder(exe_ctx->process->GetByteOrder()); + data.SetAddressByteSize(exe_ctx->process->GetAddressByteSize()); + } + else + { + data.SetByteOrder(target->GetArchitecture().GetDefaultEndian()); + data.SetAddressByteSize(target->GetArchitecture().GetAddressByteSize()); + } + return DecodeInstructions (data, 0, UINT32_MAX); } return 0; Modified: lldb/trunk/source/Core/FileSpec.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/FileSpec.cpp?rev=107350&r1=107349&r2=107350&view=diff ============================================================================== --- lldb/trunk/source/Core/FileSpec.cpp (original) +++ lldb/trunk/source/Core/FileSpec.cpp Wed Jun 30 18:03:03 2010 @@ -496,6 +496,41 @@ return m_filename.MemorySize() + m_directory.MemorySize(); } + +size_t +FileSpec::ReadFileContents (off_t file_offset, void *dst, size_t dst_len) const +{ + size_t bytes_read = 0; + char resolved_path[PATH_MAX]; + if (GetPath(resolved_path, sizeof(resolved_path))) + { + int fd = ::open (resolved_path, O_RDONLY, 0); + if (fd != -1) + { + struct stat file_stats; + if (::fstat (fd, &file_stats) == 0) + { + // Read bytes directly into our basic_string buffer + if (file_stats.st_size > 0) + { + off_t lseek_result = 0; + if (file_offset > 0) + lseek_result = ::lseek (fd, file_offset, SEEK_SET); + + if (lseek_result == file_offset) + { + ssize_t n = ::read (fd, dst, dst_len); + if (n >= 0) + bytes_read = n; + } + } + } + } + close(fd); + } + return bytes_read; +} + //------------------------------------------------------------------ // Returns a shared pointer to a data buffer that contains all or // part of the contents of a file. The data copies into a heap based @@ -508,7 +543,7 @@ // verified using the DataBuffer::GetByteSize() function. //------------------------------------------------------------------ DataBufferSP -FileSpec::ReadFileContents(off_t file_offset, size_t file_size) const +FileSpec::ReadFileContents (off_t file_offset, size_t file_size) const { DataBufferSP data_sp; char resolved_path[PATH_MAX]; @@ -520,7 +555,6 @@ struct stat file_stats; if (::fstat (fd, &file_stats) == 0) { - // Read bytes directly into our basic_string buffer if (file_stats.st_size > 0) { off_t lseek_result = 0; @@ -533,11 +567,13 @@ } else if (lseek_result == file_offset) { + const size_t bytes_left = file_stats.st_size - file_offset; + size_t num_bytes_to_read = file_size; + if (num_bytes_to_read > bytes_left) + num_bytes_to_read = bytes_left; + std::auto_ptr data_heap_ap; - if (file_stats.st_size < file_size) - data_heap_ap.reset(new DataBufferHeap(file_stats.st_size, '\0')); - else - data_heap_ap.reset(new DataBufferHeap(file_size, '\0')); + data_heap_ap.reset(new DataBufferHeap(num_bytes_to_read, '\0')); if (data_heap_ap.get()) { Modified: lldb/trunk/source/Core/Section.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/Section.cpp?rev=107350&r1=107349&r2=107350&view=diff ============================================================================== --- lldb/trunk/source/Core/Section.cpp (original) +++ lldb/trunk/source/Core/Section.cpp Wed Jun 30 18:03:03 2010 @@ -323,6 +323,22 @@ return false; } +size_t +Section::ReadSectionDataFromObjectFile (const ObjectFile* objfile, off_t section_offset, void *dst, size_t dst_len) const +{ + if (objfile && dst && dst_len) + { + const FileSpec& file = objfile->GetFileSpec(); + + if (file) + { + off_t section_file_offset = GetFileOffset() + objfile->GetOffset() + section_offset; + return file.ReadFileContents (section_file_offset, dst, dst_len); + } + } + return 0; +} + //---------------------------------------------------------------------- // Get the section data the file on disk //---------------------------------------------------------------------- @@ -340,11 +356,11 @@ if (section_file_size > 0) { off_t section_file_offset = GetFileOffset() + objfile->GetOffset(); - DataBufferSP sectionDataSP(file.ReadFileContents(section_file_offset, section_file_size)); + DataBufferSP section_data_sp(file.ReadFileContents(section_file_offset, section_file_size)); section_data.SetByteOrder(objfile->GetByteOrder()); section_data.SetAddressByteSize(objfile->GetAddressByteSize()); - return section_data.SetData (sectionDataSP); + return section_data.SetData (section_data_sp); } } return 0; @@ -364,10 +380,10 @@ if (section_file_size > 0) { off_t section_file_offset = GetFileOffset() + objfile->GetOffset(); - DataBufferSP sectionDataSP(file.MemoryMapFileContents(section_file_offset, section_file_size)); + DataBufferSP section_data_sp(file.MemoryMapFileContents(section_file_offset, section_file_size)); section_data.SetByteOrder(objfile->GetByteOrder()); section_data.SetAddressByteSize(objfile->GetAddressByteSize()); - return section_data.SetData (sectionDataSP); + return section_data.SetData (section_data_sp); } } return 0; Modified: lldb/trunk/source/Plugins/Disassembler/llvm/DisassemblerLLVM.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Disassembler/llvm/DisassemblerLLVM.cpp?rev=107350&r1=107349&r2=107350&view=diff ============================================================================== --- lldb/trunk/source/Plugins/Disassembler/llvm/DisassemblerLLVM.cpp (original) +++ lldb/trunk/source/Plugins/Disassembler/llvm/DisassemblerLLVM.cpp Wed Jun 30 18:03:03 2010 @@ -100,19 +100,27 @@ DisassemblerLLVM::Instruction::Dump ( Stream *s, - lldb::addr_t base_address, - DataExtractor *bytes, + lldb_private::Address *inst_addr_ptr, + const DataExtractor *bytes, uint32_t bytes_offset, - const lldb_private::ExecutionContext exe_ctx, + const lldb_private::ExecutionContext& exe_ctx, bool raw ) { const size_t opcodeColumnWidth = 7; const size_t operandColumnWidth = 25; + ExecutionContextScope *exe_scope = exe_ctx.GetBestExecutionContextScope(); // If we have an address, print it out - if (base_address != LLDB_INVALID_ADDRESS) - s->Printf("0x%llx: ", base_address); + if (inst_addr_ptr) + { + if (inst_addr_ptr->Dump (s, + exe_scope, + Address::DumpStyleLoadAddress, + Address::DumpStyleModuleWithFileAddress, + 0)) + s->PutCString(": "); + } // If we are supposed to show bytes, "bytes" will be non-NULL. if (bytes) @@ -131,9 +139,15 @@ int currentOpIndex = -1; - RegisterReaderArg rra(base_address + EDInstByteSize(m_inst), m_disassembler); - lldb_private::Process *process = exe_ctx.process; + addr_t base_addr = LLDB_INVALID_ADDRESS; + if (process && process->IsAlive()) + base_addr = inst_addr_ptr->GetLoadAddress (process); + if (base_addr == LLDB_INVALID_ADDRESS) + base_addr = inst_addr_ptr->GetFileAddress (); + + RegisterReaderArg rra(base_addr + EDInstByteSize(m_inst), m_disassembler); + bool printTokenized = false; @@ -228,13 +242,21 @@ } lldb_private::Address so_addr; - if (process) + if (process && process->IsAlive()) + { + if (process->ResolveLoadAddress (operand_value, so_addr)) + so_addr.Dump(&comment, exe_scope, Address::DumpStyleResolvedDescription, Address::DumpStyleSectionNameOffset); + } + else if (inst_addr_ptr) { - if (process->ResolveLoadAddress(operand_value, so_addr)) + Module *module = inst_addr_ptr->GetModule(); + if (module) { - so_addr.Dump(&comment, process, Address::DumpStyleResolvedDescription, Address::DumpStyleSectionNameOffset); + if (module->ResolveFileAddress (operand_value, so_addr)) + so_addr.Dump(&comment, exe_scope, Address::DumpStyleResolvedDescription, Address::DumpStyleSectionNameOffset); } } + } // EDEvaluateOperand } // EDOperandIsMemory } // EDGetOperand @@ -364,12 +386,11 @@ } size_t -DisassemblerLLVM::ParseInstructions +DisassemblerLLVM::DecodeInstructions ( const DataExtractor& data, uint32_t data_offset, - uint32_t num_instructions, - lldb::addr_t base_addr + uint32_t num_instructions ) { size_t total_inst_byte_size = 0; Modified: lldb/trunk/source/Plugins/Disassembler/llvm/DisassemblerLLVM.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Disassembler/llvm/DisassemblerLLVM.h?rev=107350&r1=107349&r2=107350&view=diff ============================================================================== --- lldb/trunk/source/Plugins/Disassembler/llvm/DisassemblerLLVM.h (original) +++ lldb/trunk/source/Plugins/Disassembler/llvm/DisassemblerLLVM.h Wed Jun 30 18:03:03 2010 @@ -32,10 +32,10 @@ void Dump (lldb_private::Stream *s, - lldb::addr_t base_address, - lldb_private::DataExtractor *bytes, + lldb_private::Address *instr_addr_ptr, + const lldb_private::DataExtractor *bytes, uint32_t bytes_offset, - const lldb_private::ExecutionContext exe_ctx, + const lldb_private::ExecutionContext& exe_ctx, bool raw); bool @@ -78,11 +78,10 @@ ~DisassemblerLLVM(); size_t - ParseInstructions (const lldb_private::DataExtractor& data, - uint32_t data_offset, - uint32_t num_instructions, - lldb::addr_t base_addr); - + DecodeInstructions (const lldb_private::DataExtractor& data, + uint32_t data_offset, + uint32_t num_instructions); + //------------------------------------------------------------------ // PluginInterface protocol //------------------------------------------------------------------ Modified: lldb/trunk/source/Symbol/SymbolContext.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/SymbolContext.cpp?rev=107350&r1=107349&r2=107350&view=diff ============================================================================== --- lldb/trunk/source/Symbol/SymbolContext.cpp (original) +++ lldb/trunk/source/Symbol/SymbolContext.cpp Wed Jun 30 18:03:03 2010 @@ -117,11 +117,6 @@ bool show_module ) const { - Process *process = NULL; - if (exe_scope) - process = exe_scope->CalculateProcess(); - addr_t load_addr = addr.GetLoadAddress (process); - if (show_module && module_sp) { *s << module_sp->GetFileSpec().GetFilename() << '`'; @@ -132,9 +127,9 @@ if (function->GetMangled().GetName()) function->GetMangled().GetName().Dump(s); - const addr_t func_load_addr = function->GetAddressRange().GetBaseAddress().GetLoadAddress(process); - if (load_addr > func_load_addr) - s->Printf(" + %llu", load_addr - func_load_addr); + const addr_t function_offset = addr.GetOffset() - function->GetAddressRange().GetBaseAddress().GetOffset(); + if (function_offset) + s->Printf(" + %llu", function_offset); if (block != NULL) { @@ -158,9 +153,9 @@ if (symbol->GetAddressRangePtr()) { - const addr_t sym_load_addr = symbol->GetAddressRangePtr()->GetBaseAddress().GetLoadAddress(process); - if (load_addr > sym_load_addr) - s->Printf(" + %llu", load_addr - sym_load_addr); + const addr_t symbol_offset = addr.GetOffset() - symbol->GetAddressRangePtr()->GetBaseAddress().GetOffset(); + if (symbol_offset) + s->Printf(" + %llu", symbol_offset); } } else Modified: lldb/trunk/source/Target/StackFrame.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/StackFrame.cpp?rev=107350&r1=107349&r2=107350&view=diff ============================================================================== --- lldb/trunk/source/Target/StackFrame.cpp (original) +++ lldb/trunk/source/Target/StackFrame.cpp Wed Jun 30 18:03:03 2010 @@ -181,6 +181,7 @@ target.GetArchitecture(), exe_ctx, 0, + false, m_disassembly); if (m_disassembly.GetSize() == 0) return NULL; Modified: lldb/trunk/source/Target/Target.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Target.cpp?rev=107350&r1=107349&r2=107350&view=diff ============================================================================== --- lldb/trunk/source/Target/Target.cpp (original) +++ lldb/trunk/source/Target/Target.cpp Wed Jun 30 18:03:03 2010 @@ -507,90 +507,170 @@ BroadcastEvent (eBroadcastBitModulesUnloaded, NULL); } + +//size_t +//Target::ReadMemory +//( +// lldb::AddressType addr_type, +// lldb::addr_t addr, +// void *dst, +// size_t dst_len, +// Error &error, +// ObjectFile* objfile +//) +//{ +// size_t bytes_read = 0; +// error.Clear(); +// switch (addr_type) +// { +// case eAddressTypeFile: +// if (objfile) +// { +// Address so_addr(addr, objfile->GetSectionList()); +// if (m_process_sp.get()) +// { +// // If we have an execution context with a process, lets try and +// // resolve the file address in "objfile" and read it from the +// // process +// lldb::addr_t load_addr = so_addr.GetLoadAddress(m_process_sp.get()); +// if (load_addr == LLDB_INVALID_ADDRESS) +// { +// if (objfile->GetFileSpec()) +// error.SetErrorStringWithFormat("0x%llx can't be resolved, %s in not currently loaded.\n", addr, objfile->GetFileSpec().GetFilename().AsCString()); +// else +// error.SetErrorStringWithFormat("0x%llx can't be resolved.\n", addr, objfile->GetFileSpec().GetFilename().AsCString()); +// } +// else +// { +// bytes_read = m_process_sp->ReadMemory(load_addr, dst, dst_len, error); +// if (bytes_read != dst_len) +// { +// if (error.Success()) +// { +// if (bytes_read == 0) +// error.SetErrorStringWithFormat("Read memory from 0x%llx failed.\n", load_addr); +// else +// error.SetErrorStringWithFormat("Only %zu of %zu bytes were read from memory at 0x%llx.\n", bytes_read, dst_len, load_addr); +// } +// } +// } +// } +// else +// { +// // Try and read the file based address from the object file's +// // section data. +// const Section *section = so_addr.GetSection(); +// if (section) +// return section->ReadSectionDataFromObjectFile(objfile, so_addr.GetOffset(), dst, dst_len); +// } +// } +// break; +// +// case eAddressTypeLoad: +// if (m_process_sp.get()) +// { +// bytes_read = m_process_sp->ReadMemory(addr, dst, dst_len, error); +// if (bytes_read != dst_len) +// { +// if (error.Success()) +// { +// if (bytes_read == 0) +// error.SetErrorStringWithFormat("Read memory from 0x%llx failed.\n", addr); +// else +// error.SetErrorStringWithFormat("Only %zu of %zu bytes were read from memory at 0x%llx.\n", bytes_read, dst_len, addr); +// } +// } +// } +// else +// error.SetErrorStringWithFormat("Need valid process to read load address.\n"); +// break; +// +// case eAddressTypeHost: +// // The address is an address in this process, so just copy it +// ::memcpy (dst, (uint8_t*)NULL + addr, dst_len); +// break; +// +// default: +// error.SetErrorStringWithFormat ("Unsupported lldb::AddressType value (%i).\n", addr_type); +// break; +// } +// return bytes_read; +//} + size_t Target::ReadMemory ( - lldb::AddressType addr_type, - lldb::addr_t addr, + const Address& addr, void *dst, size_t dst_len, - Error &error, - ObjectFile* objfile + Error &error ) { - size_t bytes_read = 0; error.Clear(); - switch (addr_type) + + bool process_is_valid = m_process_sp && m_process_sp->IsAlive(); + + Address resolved_addr(addr); + if (!resolved_addr.IsSectionOffset()) { - case eAddressTypeFile: - if (objfile) + if (process_is_valid) { - if (m_process_sp.get()) - { - // If we have an execution context with a process, lets try and - // resolve the file address in "objfile" and read it from the - // process - Address so_addr(addr, objfile->GetSectionList()); - lldb::addr_t load_addr = so_addr.GetLoadAddress(m_process_sp.get()); - if (load_addr == LLDB_INVALID_ADDRESS) - { - if (objfile->GetFileSpec()) - error.SetErrorStringWithFormat("0x%llx can't be resolved, %s in not currently loaded.\n", addr, objfile->GetFileSpec().GetFilename().AsCString()); - else - error.SetErrorStringWithFormat("0x%llx can't be resolved.\n", addr, objfile->GetFileSpec().GetFilename().AsCString()); - } - else - { - bytes_read = m_process_sp->ReadMemory(load_addr, dst, dst_len, error); - if (bytes_read != dst_len) - { - if (error.Success()) - { - if (bytes_read == 0) - error.SetErrorStringWithFormat("Read memory from 0x%llx failed.\n", load_addr); - else - error.SetErrorStringWithFormat("Only %zu of %zu bytes were read from memory at 0x%llx.\n", bytes_read, dst_len, load_addr); - } - } - } - } + m_process_sp->ResolveLoadAddress (addr.GetOffset(), resolved_addr); + } + else + { + m_images.ResolveFileAddress(addr.GetOffset(), resolved_addr); + } + } + + + if (process_is_valid) + { + lldb::addr_t load_addr = resolved_addr.GetLoadAddress(m_process_sp.get()); + if (load_addr == LLDB_INVALID_ADDRESS) + { + if (resolved_addr.GetModule() && resolved_addr.GetModule()->GetFileSpec()) + error.SetErrorStringWithFormat("%s[0x%llx] can't be resolved, %s in not currently loaded.\n", + resolved_addr.GetModule()->GetFileSpec().GetFilename().AsCString(), + resolved_addr.GetFileAddress()); else - { - // Try and read the file based address from the object file's - // section data. - } + error.SetErrorStringWithFormat("0x%llx can't be resolved.\n", resolved_addr.GetFileAddress()); } - break; - - case eAddressTypeLoad: - if (m_process_sp.get()) + else { - bytes_read = m_process_sp->ReadMemory(addr, dst, dst_len, error); + size_t bytes_read = m_process_sp->ReadMemory(load_addr, dst, dst_len, error); if (bytes_read != dst_len) { if (error.Success()) { if (bytes_read == 0) - error.SetErrorStringWithFormat("Read memory from 0x%llx failed.\n", addr); + error.SetErrorStringWithFormat("Read memory from 0x%llx failed.\n", load_addr); else - error.SetErrorStringWithFormat("Only %zu of %zu bytes were read from memory at 0x%llx.\n", bytes_read, dst_len, addr); + error.SetErrorStringWithFormat("Only %zu of %zu bytes were read from memory at 0x%llx.\n", bytes_read, dst_len, load_addr); } } + if (bytes_read) + return bytes_read; + // If the address is not section offset we have an address that + // doesn't resolve to any address in any currently loaded shared + // libaries and we failed to read memory so there isn't anything + // more we can do. If it is section offset, we might be able to + // read cached memory from the object file. + if (!resolved_addr.IsSectionOffset()) + return 0; } - else - error.SetErrorStringWithFormat("Need valid process to read load address.\n"); - break; - - case eAddressTypeHost: - // The address is an address in this process, so just copy it - ::memcpy (dst, (uint8_t*)NULL + addr, dst_len); - break; - - default: - error.SetErrorStringWithFormat ("Unsupported lldb::AddressType value (%i).\n", addr_type); - break; } - return bytes_read; + + const Section *section = resolved_addr.GetSection(); + if (section && section->GetModule()) + { + ObjectFile *objfile = section->GetModule()->GetObjectFile(); + return section->ReadSectionDataFromObjectFile (objfile, + resolved_addr.GetOffset(), + dst, + dst_len); + } + return 0; } From gclayton at apple.com Wed Jun 30 18:04:24 2010 From: gclayton at apple.com (Greg Clayton) Date: Wed, 30 Jun 2010 23:04:24 -0000 Subject: [Lldb-commits] [lldb] r107352 - /lldb/trunk/source/Target/Target.cpp Message-ID: <20100630230424.55E9E2A6C12C@llvm.org> Author: gclayton Date: Wed Jun 30 18:04:24 2010 New Revision: 107352 URL: http://llvm.org/viewvc/llvm-project?rev=107352&view=rev Log: Removed a commented out function and did a little reformatting. Modified: lldb/trunk/source/Target/Target.cpp Modified: lldb/trunk/source/Target/Target.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Target.cpp?rev=107352&r1=107351&r2=107352&view=diff ============================================================================== --- lldb/trunk/source/Target/Target.cpp (original) +++ lldb/trunk/source/Target/Target.cpp Wed Jun 30 18:04:24 2010 @@ -507,104 +507,8 @@ BroadcastEvent (eBroadcastBitModulesUnloaded, NULL); } - -//size_t -//Target::ReadMemory -//( -// lldb::AddressType addr_type, -// lldb::addr_t addr, -// void *dst, -// size_t dst_len, -// Error &error, -// ObjectFile* objfile -//) -//{ -// size_t bytes_read = 0; -// error.Clear(); -// switch (addr_type) -// { -// case eAddressTypeFile: -// if (objfile) -// { -// Address so_addr(addr, objfile->GetSectionList()); -// if (m_process_sp.get()) -// { -// // If we have an execution context with a process, lets try and -// // resolve the file address in "objfile" and read it from the -// // process -// lldb::addr_t load_addr = so_addr.GetLoadAddress(m_process_sp.get()); -// if (load_addr == LLDB_INVALID_ADDRESS) -// { -// if (objfile->GetFileSpec()) -// error.SetErrorStringWithFormat("0x%llx can't be resolved, %s in not currently loaded.\n", addr, objfile->GetFileSpec().GetFilename().AsCString()); -// else -// error.SetErrorStringWithFormat("0x%llx can't be resolved.\n", addr, objfile->GetFileSpec().GetFilename().AsCString()); -// } -// else -// { -// bytes_read = m_process_sp->ReadMemory(load_addr, dst, dst_len, error); -// if (bytes_read != dst_len) -// { -// if (error.Success()) -// { -// if (bytes_read == 0) -// error.SetErrorStringWithFormat("Read memory from 0x%llx failed.\n", load_addr); -// else -// error.SetErrorStringWithFormat("Only %zu of %zu bytes were read from memory at 0x%llx.\n", bytes_read, dst_len, load_addr); -// } -// } -// } -// } -// else -// { -// // Try and read the file based address from the object file's -// // section data. -// const Section *section = so_addr.GetSection(); -// if (section) -// return section->ReadSectionDataFromObjectFile(objfile, so_addr.GetOffset(), dst, dst_len); -// } -// } -// break; -// -// case eAddressTypeLoad: -// if (m_process_sp.get()) -// { -// bytes_read = m_process_sp->ReadMemory(addr, dst, dst_len, error); -// if (bytes_read != dst_len) -// { -// if (error.Success()) -// { -// if (bytes_read == 0) -// error.SetErrorStringWithFormat("Read memory from 0x%llx failed.\n", addr); -// else -// error.SetErrorStringWithFormat("Only %zu of %zu bytes were read from memory at 0x%llx.\n", bytes_read, dst_len, addr); -// } -// } -// } -// else -// error.SetErrorStringWithFormat("Need valid process to read load address.\n"); -// break; -// -// case eAddressTypeHost: -// // The address is an address in this process, so just copy it -// ::memcpy (dst, (uint8_t*)NULL + addr, dst_len); -// break; -// -// default: -// error.SetErrorStringWithFormat ("Unsupported lldb::AddressType value (%i).\n", addr_type); -// break; -// } -// return bytes_read; -//} - size_t -Target::ReadMemory -( - const Address& addr, - void *dst, - size_t dst_len, - Error &error -) +Target::ReadMemory (const Address& addr, void *dst, size_t dst_len, Error &error) { error.Clear(); From johnny.chen at apple.com Wed Jun 30 19:18:39 2010 From: johnny.chen at apple.com (Johnny Chen) Date: Thu, 01 Jul 2010 00:18:39 -0000 Subject: [Lldb-commits] [lldb] r107357 - in /lldb/trunk/test: array_types/TestArrayTypes.py class_types/TestClassTypes.py help/TestHelp.py Message-ID: <20100701001839.E4D202A6C12C@llvm.org> Author: johnny Date: Wed Jun 30 19:18:39 2010 New Revision: 107357 URL: http://llvm.org/viewvc/llvm-project?rev=107357&view=rev Log: Added some delay (100 ms) after executing each 'command interpreter' command; this seems to alleviate the intermittent failure observed while running the whole test suite. Modified: lldb/trunk/test/array_types/TestArrayTypes.py lldb/trunk/test/class_types/TestClassTypes.py lldb/trunk/test/help/TestHelp.py Modified: lldb/trunk/test/array_types/TestArrayTypes.py URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/array_types/TestArrayTypes.py?rev=107357&r1=107356&r2=107357&view=diff ============================================================================== --- lldb/trunk/test/array_types/TestArrayTypes.py (original) +++ lldb/trunk/test/array_types/TestArrayTypes.py Wed Jun 30 19:18:39 2010 @@ -1,6 +1,6 @@ """Test breakpoint by file/line number; and list variables with array types.""" -import os +import os, time import lldb import unittest @@ -13,6 +13,8 @@ if ("LLDB_TEST" in os.environ): os.chdir(os.path.join(os.environ["LLDB_TEST"], "array_types")); self.dbg = lldb.SBDebugger.Create() + if not self.dbg.IsValid(): + raise Exception('Invalid debugger instance') self.dbg.SetAsync(False) self.ci = self.dbg.GetCommandInterpreter() if not self.ci: @@ -27,24 +29,29 @@ res = lldb.SBCommandReturnObject() exe = os.path.join(os.getcwd(), "a.out") self.ci.HandleCommand("file " + exe, res) + time.sleep(0.1) self.assertTrue(res.Succeeded()) # Break on line 42 inside main(). self.ci.HandleCommand("breakpoint set -f main.c -l 42", res) + time.sleep(0.1) self.assertTrue(res.Succeeded()) self.assertTrue(res.GetOutput().startswith( "Breakpoint created: 1: file ='main.c', line = 42, locations = 1")) self.ci.HandleCommand("run", res) + time.sleep(0.1) self.assertTrue(res.Succeeded()) # The breakpoint should have a hit count of 1. self.ci.HandleCommand("breakpoint list", res) + time.sleep(0.1) self.assertTrue(res.Succeeded()) self.assertTrue(res.GetOutput().find('resolved, hit count = 1')) # And the stop reason of the thread should be breakpoint. self.ci.HandleCommand("thread list", res) + time.sleep(0.1) self.assertTrue(res.Succeeded()) self.assertTrue(res.GetOutput().find('state is Stopped') and res.GetOutput().find('stop reason = breakpoint')) @@ -52,6 +59,7 @@ # Issue 'variable list' command on several array-type variables. self.ci.HandleCommand("variable list strings", res); + time.sleep(0.1) self.assertTrue(res.Succeeded()) output = res.GetOutput() self.assertTrue(output.startswith('(char *[4])') and @@ -65,19 +73,23 @@ output.find('Guten Tag')) self.ci.HandleCommand("variable list char_16", res); + time.sleep(0.1) self.assertTrue(res.Succeeded()) self.assertTrue(res.GetOutput().find('(char) char_16[0]') and res.GetOutput().find('(char) char_16[15]')) self.ci.HandleCommand("variable list ushort_matrix", res); + time.sleep(0.1) self.assertTrue(res.Succeeded()) self.assertTrue(res.GetOutput().startswith('(unsigned short [2][3])')) self.ci.HandleCommand("variable list long_6", res); + time.sleep(0.1) self.assertTrue(res.Succeeded()) self.assertTrue(res.GetOutput().startswith('(long [6])')) self.ci.HandleCommand("continue", res) + time.sleep(0.1) self.assertTrue(res.Succeeded()) Modified: lldb/trunk/test/class_types/TestClassTypes.py URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/class_types/TestClassTypes.py?rev=107357&r1=107356&r2=107357&view=diff ============================================================================== --- lldb/trunk/test/class_types/TestClassTypes.py (original) +++ lldb/trunk/test/class_types/TestClassTypes.py Wed Jun 30 19:18:39 2010 @@ -1,6 +1,6 @@ """Test breakpoint on a class constructor; and variable list the this object.""" -import os +import os, time import lldb import unittest @@ -13,6 +13,8 @@ if ("LLDB_TEST" in os.environ): os.chdir(os.path.join(os.environ["LLDB_TEST"], "class_types")); self.dbg = lldb.SBDebugger.Create() + if not self.dbg.IsValid(): + raise Exception('Invalid debugger instance') self.dbg.SetAsync(False) self.ci = self.dbg.GetCommandInterpreter() if not self.ci: @@ -27,34 +29,41 @@ res = lldb.SBCommandReturnObject() exe = os.path.join(os.getcwd(), "a.out") self.ci.HandleCommand("file " + exe, res) + time.sleep(0.1) self.assertTrue(res.Succeeded()) # Break on the ctor function of class C. self.ci.HandleCommand("breakpoint set -f main.cpp -l 73", res) + time.sleep(0.1) self.assertTrue(res.Succeeded()) self.assertTrue(res.GetOutput().startswith( "Breakpoint created: 1: file ='main.cpp', line = 73, locations = 1")) self.ci.HandleCommand("run", res) + time.sleep(0.1) self.assertTrue(res.Succeeded()) # The breakpoint should have a hit count of 1. self.ci.HandleCommand("breakpoint list", res) + time.sleep(0.1) self.assertTrue(res.Succeeded()) self.assertTrue(res.GetOutput().find('resolved, hit count = 1')) # And the stop reason of the thread should be breakpoint. self.ci.HandleCommand("thread list", res) + time.sleep(0.1) self.assertTrue(res.Succeeded()) self.assertTrue(res.GetOutput().find('state is Stopped') and res.GetOutput().find('stop reason = breakpoint')) # We should be stopped on the ctor function of class C. self.ci.HandleCommand("variable list this", res); + time.sleep(0.1) self.assertTrue(res.Succeeded()) self.assertTrue(res.GetOutput().startswith('(class C *const) this = ')) self.ci.HandleCommand("continue", res) + time.sleep(0.1) self.assertTrue(res.Succeeded()) Modified: lldb/trunk/test/help/TestHelp.py URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/help/TestHelp.py?rev=107357&r1=107356&r2=107357&view=diff ============================================================================== --- lldb/trunk/test/help/TestHelp.py (original) +++ lldb/trunk/test/help/TestHelp.py Wed Jun 30 19:18:39 2010 @@ -1,6 +1,6 @@ """Test lldb help command.""" -import os +import os, time import lldb import unittest @@ -13,6 +13,8 @@ if ("LLDB_TEST" in os.environ): os.chdir(os.path.join(os.environ["LLDB_TEST"], "help")); self.dbg = lldb.SBDebugger.Create() + if not self.dbg.IsValid(): + raise Exception('Invalid debugger instance') self.dbg.SetAsync(False) self.ci = self.dbg.GetCommandInterpreter() if not self.ci: @@ -26,6 +28,7 @@ """A simple test of 'help' command and its output.""" res = lldb.SBCommandReturnObject() self.ci.HandleCommand("help", res) + time.sleep(0.1) self.assertTrue(res.Succeeded()) self.assertTrue(res.GetOutput().startswith( 'The following is a list of built-in, permanent debugger commands')) @@ -34,8 +37,10 @@ """Command 'set term-width 0' should not hang the help command.""" res = lldb.SBCommandReturnObject() self.ci.HandleCommand("set term-width 0", res) + time.sleep(0.1) self.assertTrue(res.Succeeded()) self.ci.HandleCommand("help", res) + time.sleep(0.1) self.assertTrue(res.Succeeded()) self.assertTrue(res.GetOutput().startswith( 'The following is a list of built-in, permanent debugger commands')) From daniel at zuster.org Wed Jun 30 19:40:56 2010 From: daniel at zuster.org (Daniel Dunbar) Date: Wed, 30 Jun 2010 17:40:56 -0700 Subject: [Lldb-commits] [lldb] r107357 - in /lldb/trunk/test: array_types/TestArrayTypes.py class_types/TestClassTypes.py help/TestHelp.py In-Reply-To: <20100701001839.E4D202A6C12C@llvm.org> References: <20100701001839.E4D202A6C12C@llvm.org> Message-ID: On Wed, Jun 30, 2010 at 5:18 PM, Johnny Chen wrote: > Author: johnny > Date: Wed Jun 30 19:18:39 2010 > New Revision: 107357 > > URL: http://llvm.org/viewvc/llvm-project?rev=107357&view=rev > Log: > Added some delay (100 ms) after executing each 'command interpreter' command; > this seems to alleviate the intermittent failure observed while running the > whole test suite. I would strongly recommend not going down this road. There are two big problems with adding arbitrary timeouts: 1. They are never "exactly right", and it is always possible that a loaded machine or some other hickup will give sporadic test failures. This is a real bane for automated testing, as it makes it hard to generate reliable reports that people will pay attention to. 2. Because most of the time the timeouts aren't needed, they end up making the test suite a lot slower than it needs to be. Our GDB buildbot hits this problem a lot and it is something I really would hope would be fixed with LLDB. Is it possible to debug the intermittent failure to find out exactly why it is failing, and add explicit coordination to resolve that, instead of using a timeout? - Daniel > > Modified: > ? ?lldb/trunk/test/array_types/TestArrayTypes.py > ? ?lldb/trunk/test/class_types/TestClassTypes.py > ? ?lldb/trunk/test/help/TestHelp.py > > Modified: lldb/trunk/test/array_types/TestArrayTypes.py > URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/array_types/TestArrayTypes.py?rev=107357&r1=107356&r2=107357&view=diff > ============================================================================== > --- lldb/trunk/test/array_types/TestArrayTypes.py (original) > +++ lldb/trunk/test/array_types/TestArrayTypes.py Wed Jun 30 19:18:39 2010 > @@ -1,6 +1,6 @@ > ?"""Test breakpoint by file/line number; and list variables with array types.""" > > -import os > +import os, time > ?import lldb > ?import unittest > > @@ -13,6 +13,8 @@ > ? ? ? ? if ("LLDB_TEST" in os.environ): > ? ? ? ? ? ? os.chdir(os.path.join(os.environ["LLDB_TEST"], "array_types")); > ? ? ? ? self.dbg = lldb.SBDebugger.Create() > + ? ? ? ?if not self.dbg.IsValid(): > + ? ? ? ? ? ?raise Exception('Invalid debugger instance') > ? ? ? ? self.dbg.SetAsync(False) > ? ? ? ? self.ci = self.dbg.GetCommandInterpreter() > ? ? ? ? if not self.ci: > @@ -27,24 +29,29 @@ > ? ? ? ? res = lldb.SBCommandReturnObject() > ? ? ? ? exe = os.path.join(os.getcwd(), "a.out") > ? ? ? ? self.ci.HandleCommand("file " + exe, res) > + ? ? ? ?time.sleep(0.1) > ? ? ? ? self.assertTrue(res.Succeeded()) > > ? ? ? ? # Break on line 42 inside main(). > ? ? ? ? self.ci.HandleCommand("breakpoint set -f main.c -l 42", res) > + ? ? ? ?time.sleep(0.1) > ? ? ? ? self.assertTrue(res.Succeeded()) > ? ? ? ? self.assertTrue(res.GetOutput().startswith( > ? ? ? ? ? ? "Breakpoint created: 1: file ='main.c', line = 42, locations = 1")) > > ? ? ? ? self.ci.HandleCommand("run", res) > + ? ? ? ?time.sleep(0.1) > ? ? ? ? self.assertTrue(res.Succeeded()) > > ? ? ? ? # The breakpoint should have a hit count of 1. > ? ? ? ? self.ci.HandleCommand("breakpoint list", res) > + ? ? ? ?time.sleep(0.1) > ? ? ? ? self.assertTrue(res.Succeeded()) > ? ? ? ? self.assertTrue(res.GetOutput().find('resolved, hit count = 1')) > > ? ? ? ? # And the stop reason of the thread should be breakpoint. > ? ? ? ? self.ci.HandleCommand("thread list", res) > + ? ? ? ?time.sleep(0.1) > ? ? ? ? self.assertTrue(res.Succeeded()) > ? ? ? ? self.assertTrue(res.GetOutput().find('state is Stopped') and > ? ? ? ? ? ? ? ? ? ? ? ? res.GetOutput().find('stop reason = breakpoint')) > @@ -52,6 +59,7 @@ > ? ? ? ? # Issue 'variable list' command on several array-type variables. > > ? ? ? ? self.ci.HandleCommand("variable list strings", res); > + ? ? ? ?time.sleep(0.1) > ? ? ? ? self.assertTrue(res.Succeeded()) > ? ? ? ? output = res.GetOutput() > ? ? ? ? self.assertTrue(output.startswith('(char *[4])') and > @@ -65,19 +73,23 @@ > ? ? ? ? ? ? ? ? ? ? ? ? output.find('Guten Tag')) > > ? ? ? ? self.ci.HandleCommand("variable list char_16", res); > + ? ? ? ?time.sleep(0.1) > ? ? ? ? self.assertTrue(res.Succeeded()) > ? ? ? ? self.assertTrue(res.GetOutput().find('(char) char_16[0]') and > ? ? ? ? ? ? ? ? ? ? ? ? res.GetOutput().find('(char) char_16[15]')) > > ? ? ? ? self.ci.HandleCommand("variable list ushort_matrix", res); > + ? ? ? ?time.sleep(0.1) > ? ? ? ? self.assertTrue(res.Succeeded()) > ? ? ? ? self.assertTrue(res.GetOutput().startswith('(unsigned short [2][3])')) > > ? ? ? ? self.ci.HandleCommand("variable list long_6", res); > + ? ? ? ?time.sleep(0.1) > ? ? ? ? self.assertTrue(res.Succeeded()) > ? ? ? ? self.assertTrue(res.GetOutput().startswith('(long [6])')) > > ? ? ? ? self.ci.HandleCommand("continue", res) > + ? ? ? ?time.sleep(0.1) > ? ? ? ? self.assertTrue(res.Succeeded()) > > > > Modified: lldb/trunk/test/class_types/TestClassTypes.py > URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/class_types/TestClassTypes.py?rev=107357&r1=107356&r2=107357&view=diff > ============================================================================== > --- lldb/trunk/test/class_types/TestClassTypes.py (original) > +++ lldb/trunk/test/class_types/TestClassTypes.py Wed Jun 30 19:18:39 2010 > @@ -1,6 +1,6 @@ > ?"""Test breakpoint on a class constructor; and variable list the this object.""" > > -import os > +import os, time > ?import lldb > ?import unittest > > @@ -13,6 +13,8 @@ > ? ? ? ? if ("LLDB_TEST" in os.environ): > ? ? ? ? ? ? os.chdir(os.path.join(os.environ["LLDB_TEST"], "class_types")); > ? ? ? ? self.dbg = lldb.SBDebugger.Create() > + ? ? ? ?if not self.dbg.IsValid(): > + ? ? ? ? ? ?raise Exception('Invalid debugger instance') > ? ? ? ? self.dbg.SetAsync(False) > ? ? ? ? self.ci = self.dbg.GetCommandInterpreter() > ? ? ? ? if not self.ci: > @@ -27,34 +29,41 @@ > ? ? ? ? res = lldb.SBCommandReturnObject() > ? ? ? ? exe = os.path.join(os.getcwd(), "a.out") > ? ? ? ? self.ci.HandleCommand("file " + exe, res) > + ? ? ? ?time.sleep(0.1) > ? ? ? ? self.assertTrue(res.Succeeded()) > > ? ? ? ? # Break on the ctor function of class C. > ? ? ? ? self.ci.HandleCommand("breakpoint set -f main.cpp -l 73", res) > + ? ? ? ?time.sleep(0.1) > ? ? ? ? self.assertTrue(res.Succeeded()) > ? ? ? ? self.assertTrue(res.GetOutput().startswith( > ? ? ? ? ? ? "Breakpoint created: 1: file ='main.cpp', line = 73, locations = 1")) > > ? ? ? ? self.ci.HandleCommand("run", res) > + ? ? ? ?time.sleep(0.1) > ? ? ? ? self.assertTrue(res.Succeeded()) > > ? ? ? ? # The breakpoint should have a hit count of 1. > ? ? ? ? self.ci.HandleCommand("breakpoint list", res) > + ? ? ? ?time.sleep(0.1) > ? ? ? ? self.assertTrue(res.Succeeded()) > ? ? ? ? self.assertTrue(res.GetOutput().find('resolved, hit count = 1')) > > ? ? ? ? # And the stop reason of the thread should be breakpoint. > ? ? ? ? self.ci.HandleCommand("thread list", res) > + ? ? ? ?time.sleep(0.1) > ? ? ? ? self.assertTrue(res.Succeeded()) > ? ? ? ? self.assertTrue(res.GetOutput().find('state is Stopped') and > ? ? ? ? ? ? ? ? ? ? ? ? res.GetOutput().find('stop reason = breakpoint')) > > ? ? ? ? # We should be stopped on the ctor function of class C. > ? ? ? ? self.ci.HandleCommand("variable list this", res); > + ? ? ? ?time.sleep(0.1) > ? ? ? ? self.assertTrue(res.Succeeded()) > ? ? ? ? self.assertTrue(res.GetOutput().startswith('(class C *const) this = ')) > > ? ? ? ? self.ci.HandleCommand("continue", res) > + ? ? ? ?time.sleep(0.1) > ? ? ? ? self.assertTrue(res.Succeeded()) > > > > Modified: lldb/trunk/test/help/TestHelp.py > URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/help/TestHelp.py?rev=107357&r1=107356&r2=107357&view=diff > ============================================================================== > --- lldb/trunk/test/help/TestHelp.py (original) > +++ lldb/trunk/test/help/TestHelp.py Wed Jun 30 19:18:39 2010 > @@ -1,6 +1,6 @@ > ?"""Test lldb help command.""" > > -import os > +import os, time > ?import lldb > ?import unittest > > @@ -13,6 +13,8 @@ > ? ? ? ? if ("LLDB_TEST" in os.environ): > ? ? ? ? ? ? os.chdir(os.path.join(os.environ["LLDB_TEST"], "help")); > ? ? ? ? self.dbg = lldb.SBDebugger.Create() > + ? ? ? ?if not self.dbg.IsValid(): > + ? ? ? ? ? ?raise Exception('Invalid debugger instance') > ? ? ? ? self.dbg.SetAsync(False) > ? ? ? ? self.ci = self.dbg.GetCommandInterpreter() > ? ? ? ? if not self.ci: > @@ -26,6 +28,7 @@ > ? ? ? ? """A simple test of 'help' command and its output.""" > ? ? ? ? res = lldb.SBCommandReturnObject() > ? ? ? ? self.ci.HandleCommand("help", res) > + ? ? ? ?time.sleep(0.1) > ? ? ? ? self.assertTrue(res.Succeeded()) > ? ? ? ? self.assertTrue(res.GetOutput().startswith( > ? ? ? ? ? ? 'The following is a list of built-in, permanent debugger commands')) > @@ -34,8 +37,10 @@ > ? ? ? ? """Command 'set term-width 0' should not hang the help command.""" > ? ? ? ? res = lldb.SBCommandReturnObject() > ? ? ? ? self.ci.HandleCommand("set term-width 0", res) > + ? ? ? ?time.sleep(0.1) > ? ? ? ? self.assertTrue(res.Succeeded()) > ? ? ? ? self.ci.HandleCommand("help", res) > + ? ? ? ?time.sleep(0.1) > ? ? ? ? self.assertTrue(res.Succeeded()) > ? ? ? ? self.assertTrue(res.GetOutput().startswith( > ? ? ? ? ? ? 'The following is a list of built-in, permanent debugger commands')) > > > _______________________________________________ > lldb-commits mailing list > lldb-commits at cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/lldb-commits > From gclayton at apple.com Wed Jun 30 20:26:43 2010 From: gclayton at apple.com (Greg Clayton) Date: Thu, 01 Jul 2010 01:26:43 -0000 Subject: [Lldb-commits] [lldb] r107366 - in /lldb/trunk: include/lldb/Core/Address.h source/Core/Address.cpp source/Plugins/Disassembler/llvm/DisassemblerLLVM.cpp Message-ID: <20100701012643.BD5ED2A6C12C@llvm.org> Author: gclayton Date: Wed Jun 30 20:26:43 2010 New Revision: 107366 URL: http://llvm.org/viewvc/llvm-project?rev=107366&view=rev Log: Fixed up disassembly to not emit the module name before all function names that are in the disassembly comments since most of them are in the same module (shared library). Fixed a crasher that could happen when disassembling special section data. Added an address dump style that shows the symbol context without the module (used in the disassembly code). Modified: lldb/trunk/include/lldb/Core/Address.h lldb/trunk/source/Core/Address.cpp lldb/trunk/source/Plugins/Disassembler/llvm/DisassemblerLLVM.cpp Modified: lldb/trunk/include/lldb/Core/Address.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/Address.h?rev=107366&r1=107365&r2=107366&view=diff ============================================================================== --- lldb/trunk/include/lldb/Core/Address.h (original) +++ lldb/trunk/include/lldb/Core/Address.h Wed Jun 30 20:26:43 2010 @@ -86,6 +86,7 @@ ///< be anything from a symbol context summary (module, function/symbol, ///< and file and line), to information about what the pointer points to ///< if the address is in a section (section of pointers, c strings, etc). + DumpStyleResolvedDescriptionNoModule, DumpStyleDetailedSymbolContext ///< Detailed symbol context information for an address for all symbol ///< context members. } DumpStyle; Modified: lldb/trunk/source/Core/Address.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/Address.cpp?rev=107366&r1=107365&r2=107366&view=diff ============================================================================== --- lldb/trunk/source/Core/Address.cpp (original) +++ lldb/trunk/source/Core/Address.cpp Wed Jun 30 20:26:43 2010 @@ -410,9 +410,13 @@ if (m_section == NULL) style = DumpStyleLoadAddress; + Target *target = NULL; Process *process = NULL; if (exe_scope) + { + target = exe_scope->CalculateTarget(); process = exe_scope->CalculateProcess(); + } // If addr_byte_size is UINT32_MAX, then determine the correct address // byte size for the process or default to the size of addr_t if (addr_size == UINT32_MAX) @@ -475,6 +479,7 @@ break; case DumpStyleResolvedDescription: + case DumpStyleResolvedDescriptionNoModule: if (IsSectionOffset()) { lldb::AddressType addr_type = eAddressTypeLoad; @@ -524,12 +529,12 @@ { if (ReadAddress (exe_scope, *this, pointer_size, so_addr)) { - if (so_addr.IsSectionOffset()) + if (target && so_addr.IsSectionOffset()) { lldb_private::SymbolContext func_sc; - process->GetTarget().GetImages().ResolveSymbolContextForAddress (so_addr, - eSymbolContextEverything, - func_sc); + target->GetImages().ResolveSymbolContextForAddress (so_addr, + eSymbolContextEverything, + func_sc); if (func_sc.function || func_sc.symbol) { showed_info = true; @@ -541,7 +546,7 @@ #endif Address cstr_addr(*this); cstr_addr.SetOffset(cstr_addr.GetOffset() + pointer_size); - func_sc.DumpStopContext(s, process, so_addr, true); + func_sc.DumpStopContext(s, exe_scope, so_addr, true); if (ReadAddress (exe_scope, cstr_addr, pointer_size, so_addr)) { #if VERBOSE_OUTPUT @@ -625,7 +630,7 @@ if (pointer_sc.function || pointer_sc.symbol) { s->PutCString(": "); - pointer_sc.DumpStopContext(s, process, so_addr, false); + pointer_sc.DumpStopContext(s, exe_scope, so_addr, false); } } } @@ -644,20 +649,24 @@ if (sc.function || sc.symbol) { bool show_stop_context = true; + bool show_module = (style == DumpStyleResolvedDescription); if (sc.function == NULL && sc.symbol != NULL) { // If we have just a symbol make sure it is in the right section if (sc.symbol->GetAddressRangePtr()) { if (sc.symbol->GetAddressRangePtr()->GetBaseAddress().GetSection() != GetSection()) + { + // don't show the module if the symbol is a trampoline symbol show_stop_context = false; + } } } if (show_stop_context) { // We have a function or a symbol from the same // sections as this address. - sc.DumpStopContext(s, process, *this, true); + sc.DumpStopContext(s, exe_scope, *this, show_module); } else { Modified: lldb/trunk/source/Plugins/Disassembler/llvm/DisassemblerLLVM.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Disassembler/llvm/DisassemblerLLVM.cpp?rev=107366&r1=107365&r2=107366&view=diff ============================================================================== --- lldb/trunk/source/Plugins/Disassembler/llvm/DisassemblerLLVM.cpp (original) +++ lldb/trunk/source/Plugins/Disassembler/llvm/DisassemblerLLVM.cpp Wed Jun 30 20:26:43 2010 @@ -245,7 +245,7 @@ if (process && process->IsAlive()) { if (process->ResolveLoadAddress (operand_value, so_addr)) - so_addr.Dump(&comment, exe_scope, Address::DumpStyleResolvedDescription, Address::DumpStyleSectionNameOffset); + so_addr.Dump(&comment, exe_scope, Address::DumpStyleResolvedDescriptionNoModule, Address::DumpStyleSectionNameOffset); } else if (inst_addr_ptr) { @@ -253,7 +253,7 @@ if (module) { if (module->ResolveFileAddress (operand_value, so_addr)) - so_addr.Dump(&comment, exe_scope, Address::DumpStyleResolvedDescription, Address::DumpStyleSectionNameOffset); + so_addr.Dump(&comment, exe_scope, Address::DumpStyleResolvedDescriptionNoModule, Address::DumpStyleSectionNameOffset); } } From clattner at apple.com Wed Jun 30 20:34:43 2010 From: clattner at apple.com (Chris Lattner) Date: Wed, 30 Jun 2010 18:34:43 -0700 Subject: [Lldb-commits] [lldb] r107357 - in /lldb/trunk/test: array_types/TestArrayTypes.py class_types/TestClassTypes.py help/TestHelp.py In-Reply-To: References: <20100701001839.E4D202A6C12C@llvm.org> Message-ID: On Jun 30, 2010, at 5:40 PM, Daniel Dunbar wrote: > On Wed, Jun 30, 2010 at 5:18 PM, Johnny Chen wrote: >> Author: johnny >> Date: Wed Jun 30 19:18:39 2010 >> New Revision: 107357 >> >> URL: http://llvm.org/viewvc/llvm-project?rev=107357&view=rev >> Log: >> Added some delay (100 ms) after executing each 'command interpreter' command; >> this seems to alleviate the intermittent failure observed while running the >> whole test suite. > > I would strongly recommend not going down this road. There are two big > problems with adding arbitrary timeouts: > 1. They are never "exactly right", and it is always possible that a > loaded machine or some other hickup will give sporadic test failures. > This is a real bane for automated testing, as it makes it hard to > generate reliable reports that people will pay attention to. > 2. Because most of the time the timeouts aren't needed, they end up > making the test suite a lot slower than it needs to be. Also: 3. This is probably papering over a race condition or some other serious bug that will continue to manifest. It would be much better to track the real problem down and fix it. -Chris From jingham at apple.com Wed Jun 30 20:48:54 2010 From: jingham at apple.com (Jim Ingham) Date: Thu, 01 Jul 2010 01:48:54 -0000 Subject: [Lldb-commits] [lldb] r107370 - /lldb/trunk/source/Core/FileSpec.cpp Message-ID: <20100701014854.1C3562A6C12C@llvm.org> Author: jingham Date: Wed Jun 30 20:48:53 2010 New Revision: 107370 URL: http://llvm.org/viewvc/llvm-project?rev=107370&view=rev Log: Moved the User Name expansion over to FileSpec, and converted it to use getpwname directly. Changed the file completion to deal with this, and FileSpec::Resolve now resolves all user names (not just ~/). Modified: lldb/trunk/source/Core/FileSpec.cpp Modified: lldb/trunk/source/Core/FileSpec.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/FileSpec.cpp?rev=107370&r1=107369&r2=107370&view=diff ============================================================================== --- lldb/trunk/source/Core/FileSpec.cpp (original) +++ lldb/trunk/source/Core/FileSpec.cpp Wed Jun 30 20:48:53 2010 @@ -9,12 +9,12 @@ #include -#include #include #include #include #include #include +#include #include @@ -42,18 +42,89 @@ static std::string g_tilde; if (g_tilde.empty()) { - glob_t globbuf; - if (::glob("~/", GLOB_TILDE, NULL, &globbuf) == 0) //success - { - g_tilde = globbuf.gl_pathv[0]; - ::globfree (&globbuf); - } + struct passwd *user_entry; + user_entry = getpwuid(geteuid()); + if (user_entry != NULL) + g_tilde = user_entry->pw_dir; + if (g_tilde.empty()) return NULL; } return g_tilde.c_str(); } +// Resolves the username part of a path of the form ~user/other/directories, and +// writes the result into dst_path. +// Returns 0 if there WAS a ~ in the path but the username couldn't be resolved. +// Otherwise returns the number of characters copied into dst_path. If the return +// is >= dst_len, then the resolved path is too long... +int +FileSpec::ResolveUsername (const char *src_path, char *dst_path, size_t dst_len) +{ + char user_home[PATH_MAX]; + const char *user_name; + + if (src_path == NULL || src_path[0] == '\0') + return 0; + + // If there's no ~, then just copy src_path straight to dst_path (they may be the same string...) + if (src_path[0] != '~') + { + int len = strlen (src_path); + if (len >= dst_len) + { + bcopy(src_path, dst_path, dst_len - 1); + dst_path[dst_len] = '\0'; + } + else + bcopy(src_path, dst_path, len + 1); + + return len; + } + + char *first_slash = strchr(src_path, '/'); + char remainder[PATH_MAX]; + + if (first_slash == NULL) + { + // The whole name is the username (minus the ~): + user_name = src_path + 1; + remainder[0] = '\0'; + } + else + { + int user_name_len = first_slash - src_path - 1; + memcpy(user_home, src_path + 1, user_name_len); + user_home[user_name_len] = '\0'; + user_name = user_home; + + strcpy(remainder, first_slash); + } + + if (user_name == NULL) + return 0; + // User name of "" means the current user... + + struct passwd *user_entry; + const char *home_dir; + + if (user_name[0] == '\0') + { + home_dir = GetCachedGlobTildeSlash(); + } + else + { + user_entry = getpwnam (user_name); + if (user_entry != NULL) + home_dir = user_entry->pw_dir; + } + + if (home_dir == NULL) + return 0; + else + return ::snprintf (dst_path, dst_len, "%s%s", home_dir, remainder); +} + int FileSpec::Resolve (const char *src_path, char *dst_path, size_t dst_len) { @@ -62,8 +133,15 @@ // Glob if needed for ~/, otherwise copy in case src_path is same as dst_path... char unglobbed_path[PATH_MAX]; - if (::strstr (src_path, "~/") == src_path) - ::snprintf(unglobbed_path, sizeof(unglobbed_path), "%s%s", GetCachedGlobTildeSlash(), src_path + 2); + if (src_path[0] == '~') + { + int return_count = ResolveUsername(src_path, unglobbed_path, sizeof(unglobbed_path)); + + // If we couldn't find the user referred to, or the resultant path was too long, + // then just copy over the src_path. + if (return_count == 0 || return_count >= sizeof(unglobbed_path)) + ::snprintf (unglobbed_path, sizeof(unglobbed_path), "%s", src_path); + } else ::snprintf(unglobbed_path, sizeof(unglobbed_path), "%s", src_path); From johnny.chen at apple.com Thu Jul 1 00:31:45 2010 From: johnny.chen at apple.com (Johnny Chen) Date: Thu, 01 Jul 2010 05:31:45 -0000 Subject: [Lldb-commits] [lldb] r107386 - in /lldb/trunk/test: array_types/TestArrayTypes.py class_types/TestClassTypes.py Message-ID: <20100701053145.1999C2A6C12C@llvm.org> Author: johnny Date: Thu Jul 1 00:31:44 2010 New Revision: 107386 URL: http://llvm.org/viewvc/llvm-project?rev=107386&view=rev Log: Removed most of the time delay introduced in the test scripts. Left some and added some print statements for debugging purpose. Modified: lldb/trunk/test/array_types/TestArrayTypes.py lldb/trunk/test/class_types/TestClassTypes.py Modified: lldb/trunk/test/array_types/TestArrayTypes.py URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/array_types/TestArrayTypes.py?rev=107386&r1=107385&r2=107386&view=diff ============================================================================== --- lldb/trunk/test/array_types/TestArrayTypes.py (original) +++ lldb/trunk/test/array_types/TestArrayTypes.py Thu Jul 1 00:31:44 2010 @@ -29,12 +29,10 @@ res = lldb.SBCommandReturnObject() exe = os.path.join(os.getcwd(), "a.out") self.ci.HandleCommand("file " + exe, res) - time.sleep(0.1) self.assertTrue(res.Succeeded()) # Break on line 42 inside main(). self.ci.HandleCommand("breakpoint set -f main.c -l 42", res) - time.sleep(0.1) self.assertTrue(res.Succeeded()) self.assertTrue(res.GetOutput().startswith( "Breakpoint created: 1: file ='main.c', line = 42, locations = 1")) @@ -43,23 +41,21 @@ time.sleep(0.1) self.assertTrue(res.Succeeded()) - # The breakpoint should have a hit count of 1. - self.ci.HandleCommand("breakpoint list", res) - time.sleep(0.1) - self.assertTrue(res.Succeeded()) - self.assertTrue(res.GetOutput().find('resolved, hit count = 1')) - - # And the stop reason of the thread should be breakpoint. + # The stop reason of the thread should be breakpoint. self.ci.HandleCommand("thread list", res) - time.sleep(0.1) + print "thread list ->", res.GetOutput() self.assertTrue(res.Succeeded()) self.assertTrue(res.GetOutput().find('state is Stopped') and res.GetOutput().find('stop reason = breakpoint')) + # The breakpoint should have a hit count of 1. + self.ci.HandleCommand("breakpoint list", res) + self.assertTrue(res.Succeeded()) + self.assertTrue(res.GetOutput().find('resolved, hit count = 1')) + # Issue 'variable list' command on several array-type variables. self.ci.HandleCommand("variable list strings", res); - time.sleep(0.1) self.assertTrue(res.Succeeded()) output = res.GetOutput() self.assertTrue(output.startswith('(char *[4])') and @@ -73,23 +69,19 @@ output.find('Guten Tag')) self.ci.HandleCommand("variable list char_16", res); - time.sleep(0.1) self.assertTrue(res.Succeeded()) self.assertTrue(res.GetOutput().find('(char) char_16[0]') and res.GetOutput().find('(char) char_16[15]')) self.ci.HandleCommand("variable list ushort_matrix", res); - time.sleep(0.1) self.assertTrue(res.Succeeded()) self.assertTrue(res.GetOutput().startswith('(unsigned short [2][3])')) self.ci.HandleCommand("variable list long_6", res); - time.sleep(0.1) self.assertTrue(res.Succeeded()) self.assertTrue(res.GetOutput().startswith('(long [6])')) self.ci.HandleCommand("continue", res) - time.sleep(0.1) self.assertTrue(res.Succeeded()) Modified: lldb/trunk/test/class_types/TestClassTypes.py URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/class_types/TestClassTypes.py?rev=107386&r1=107385&r2=107386&view=diff ============================================================================== --- lldb/trunk/test/class_types/TestClassTypes.py (original) +++ lldb/trunk/test/class_types/TestClassTypes.py Thu Jul 1 00:31:44 2010 @@ -29,12 +29,10 @@ res = lldb.SBCommandReturnObject() exe = os.path.join(os.getcwd(), "a.out") self.ci.HandleCommand("file " + exe, res) - time.sleep(0.1) self.assertTrue(res.Succeeded()) # Break on the ctor function of class C. self.ci.HandleCommand("breakpoint set -f main.cpp -l 73", res) - time.sleep(0.1) self.assertTrue(res.Succeeded()) self.assertTrue(res.GetOutput().startswith( "Breakpoint created: 1: file ='main.cpp', line = 73, locations = 1")) @@ -43,27 +41,24 @@ time.sleep(0.1) self.assertTrue(res.Succeeded()) - # The breakpoint should have a hit count of 1. - self.ci.HandleCommand("breakpoint list", res) - time.sleep(0.1) - self.assertTrue(res.Succeeded()) - self.assertTrue(res.GetOutput().find('resolved, hit count = 1')) - - # And the stop reason of the thread should be breakpoint. + # The stop reason of the thread should be breakpoint. self.ci.HandleCommand("thread list", res) - time.sleep(0.1) + print "thread list ->", res.GetOutput() self.assertTrue(res.Succeeded()) self.assertTrue(res.GetOutput().find('state is Stopped') and res.GetOutput().find('stop reason = breakpoint')) + # The breakpoint should have a hit count of 1. + self.ci.HandleCommand("breakpoint list", res) + self.assertTrue(res.Succeeded()) + self.assertTrue(res.GetOutput().find(' resolved, hit count = 1')) + # We should be stopped on the ctor function of class C. self.ci.HandleCommand("variable list this", res); - time.sleep(0.1) self.assertTrue(res.Succeeded()) self.assertTrue(res.GetOutput().startswith('(class C *const) this = ')) self.ci.HandleCommand("continue", res) - time.sleep(0.1) self.assertTrue(res.Succeeded()) From gclayton at apple.com Thu Jul 1 12:07:49 2010 From: gclayton at apple.com (Greg Clayton) Date: Thu, 01 Jul 2010 17:07:49 -0000 Subject: [Lldb-commits] [lldb] r107403 - in /lldb/trunk: include/lldb/Core/FileSpec.h source/Core/FileSpec.cpp Message-ID: <20100701170749.0FB7D2A6C12C@llvm.org> Author: gclayton Date: Thu Jul 1 12:07:48 2010 New Revision: 107403 URL: http://llvm.org/viewvc/llvm-project?rev=107403&view=rev Log: Added a missing static function prototype to FileSpec.h for ResolveUsername. Did a bit of code formatting and cleanup. Modified: lldb/trunk/include/lldb/Core/FileSpec.h lldb/trunk/source/Core/FileSpec.cpp Modified: lldb/trunk/include/lldb/Core/FileSpec.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/FileSpec.h?rev=107403&r1=107402&r2=107403&view=diff ============================================================================== --- lldb/trunk/include/lldb/Core/FileSpec.h (original) +++ lldb/trunk/include/lldb/Core/FileSpec.h Thu Jul 1 12:07:48 2010 @@ -23,8 +23,18 @@ /// @brief A file utility class. /// /// A file specification class that divides paths up into a directory -/// and filename. These string values of the paths are put into uniqued +/// and basename. These string values of the paths are put into uniqued /// string pools for fast comparisons and efficient memory usage. +/// +/// Another reason the paths are split into the directory and basename +/// is to allow efficient debugger searching. Often in a debugger the +/// user types in the basename of the file, for example setting a +/// breakpoint by file and line, or specifying a module (shared library) +/// to limit the scope in which to execute a command. The user rarely +/// types in a full path. When the paths are already split up, it makes +/// it easy for us to compare only the basenames of a lot of file +/// specifications without having to split up the file path each time +/// to get to the basename. //---------------------------------------------------------------------- class FileSpec { @@ -422,6 +432,9 @@ ReadFileLines (STLStringArray &lines); static int + ResolveUsername (const char *src_path, char *dst_path, size_t dst_len); + + static int Resolve (const char *src_path, char *dst_path, size_t dst_len); protected: Modified: lldb/trunk/source/Core/FileSpec.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/FileSpec.cpp?rev=107403&r1=107402&r2=107403&view=diff ============================================================================== --- lldb/trunk/source/Core/FileSpec.cpp (original) +++ lldb/trunk/source/Core/FileSpec.cpp Thu Jul 1 12:07:48 2010 @@ -66,23 +66,23 @@ if (src_path == NULL || src_path[0] == '\0') return 0; - + // If there's no ~, then just copy src_path straight to dst_path (they may be the same string...) if (src_path[0] != '~') { int len = strlen (src_path); if (len >= dst_len) { - bcopy(src_path, dst_path, dst_len - 1); - dst_path[dst_len] = '\0'; + ::bcopy (src_path, dst_path, dst_len - 1); + dst_path[dst_len] = '\0'; } else - bcopy(src_path, dst_path, len + 1); - + ::bcopy (src_path, dst_path, len + 1); + return len; } - char *first_slash = strchr(src_path, '/'); + char *first_slash = ::strchr (src_path, '/'); char remainder[PATH_MAX]; if (first_slash == NULL) @@ -94,13 +94,13 @@ else { int user_name_len = first_slash - src_path - 1; - memcpy(user_home, src_path + 1, user_name_len); + ::memcpy (user_home, src_path + 1, user_name_len); user_home[user_name_len] = '\0'; user_name = user_home; - strcpy(remainder, first_slash); + ::strcpy (remainder, first_slash); } - + if (user_name == NULL) return 0; // User name of "" means the current user... @@ -114,7 +114,7 @@ } else { - user_entry = getpwnam (user_name); + user_entry = ::getpwnam (user_name); if (user_entry != NULL) home_dir = user_entry->pw_dir; } From jingham at apple.com Thu Jul 1 13:05:02 2010 From: jingham at apple.com (Jim Ingham) Date: Thu, 01 Jul 2010 18:05:02 -0000 Subject: [Lldb-commits] [lldb] r107410 - /lldb/trunk/include/lldb/Core/FileSpec.h Message-ID: <20100701180502.8CE822A6C12C@llvm.org> Author: jingham Date: Thu Jul 1 13:05:02 2010 New Revision: 107410 URL: http://llvm.org/viewvc/llvm-project?rev=107410&view=rev Log: Missed one file in my last commit. Modified: lldb/trunk/include/lldb/Core/FileSpec.h Modified: lldb/trunk/include/lldb/Core/FileSpec.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/FileSpec.h?rev=107410&r1=107409&r2=107410&view=diff ============================================================================== --- lldb/trunk/include/lldb/Core/FileSpec.h (original) +++ lldb/trunk/include/lldb/Core/FileSpec.h Thu Jul 1 13:05:02 2010 @@ -436,6 +436,9 @@ static int Resolve (const char *src_path, char *dst_path, size_t dst_len); + + static int + ResolveUsername (const char *user_name, char *dst_buffer, size_t dst_len); protected: //------------------------------------------------------------------ From gclayton at apple.com Thu Jul 1 13:31:14 2010 From: gclayton at apple.com (Greg Clayton) Date: Thu, 01 Jul 2010 18:31:14 -0000 Subject: [Lldb-commits] [lldb] r107413 - /lldb/trunk/include/lldb/Core/FileSpec.h Message-ID: <20100701183114.2A1392A6C12C@llvm.org> Author: gclayton Date: Thu Jul 1 13:31:14 2010 New Revision: 107413 URL: http://llvm.org/viewvc/llvm-project?rev=107413&view=rev Log: Undid extra changes I already checked in. Modified: lldb/trunk/include/lldb/Core/FileSpec.h Modified: lldb/trunk/include/lldb/Core/FileSpec.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/FileSpec.h?rev=107413&r1=107412&r2=107413&view=diff ============================================================================== --- lldb/trunk/include/lldb/Core/FileSpec.h (original) +++ lldb/trunk/include/lldb/Core/FileSpec.h Thu Jul 1 13:31:14 2010 @@ -436,9 +436,6 @@ static int Resolve (const char *src_path, char *dst_path, size_t dst_len); - - static int - ResolveUsername (const char *user_name, char *dst_buffer, size_t dst_len); protected: //------------------------------------------------------------------ From scallanan at apple.com Thu Jul 1 15:08:22 2010 From: scallanan at apple.com (Sean Callanan) Date: Thu, 01 Jul 2010 20:08:22 -0000 Subject: [Lldb-commits] [lldb] r107419 - in /lldb/trunk: include/lldb/Expression/ClangExpression.h include/lldb/Expression/ClangResultSynthesizer.h lldb.xcodeproj/project.pbxproj source/Commands/CommandObjectExpression.cpp source/Expression/ClangExpression.cpp source/Expression/ClangResultSynthesizer.cpp Message-ID: <20100701200822.88E3C2A6C12C@llvm.org> Author: spyffe Date: Thu Jul 1 15:08:22 2010 New Revision: 107419 URL: http://llvm.org/viewvc/llvm-project?rev=107419&view=rev Log: Added a SemaConsumer that transforms the ASTs for an expression, adding code to put the value of the last expression (if there is one) into a variable and write the address of that variable to a global pointer. Added: lldb/trunk/include/lldb/Expression/ClangResultSynthesizer.h lldb/trunk/source/Expression/ClangResultSynthesizer.cpp Modified: lldb/trunk/include/lldb/Expression/ClangExpression.h lldb/trunk/lldb.xcodeproj/project.pbxproj lldb/trunk/source/Commands/CommandObjectExpression.cpp lldb/trunk/source/Expression/ClangExpression.cpp Modified: lldb/trunk/include/lldb/Expression/ClangExpression.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Expression/ClangExpression.h?rev=107419&r1=107418&r2=107419&view=diff ============================================================================== --- lldb/trunk/include/lldb/Expression/ClangExpression.h (original) +++ lldb/trunk/include/lldb/Expression/ClangExpression.h Thu Jul 1 15:08:22 2010 @@ -49,11 +49,15 @@ unsigned Compile(); unsigned - ParseExpression (const char *expr_text, Stream &stream); + ParseExpression (const char *expr_text, + Stream &stream, + bool add_result_var = false); unsigned - ParseBareExpression (llvm::StringRef expr_text, Stream &stream); - + ParseBareExpression (llvm::StringRef expr_text, + Stream &stream, + bool add_result_var = false); + unsigned ConvertExpressionToDWARF (ClangExpressionVariableList &expr_local_variable_list, StreamString &dwarf_opcode_strm); Added: lldb/trunk/include/lldb/Expression/ClangResultSynthesizer.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Expression/ClangResultSynthesizer.h?rev=107419&view=auto ============================================================================== --- lldb/trunk/include/lldb/Expression/ClangResultSynthesizer.h (added) +++ lldb/trunk/include/lldb/Expression/ClangResultSynthesizer.h Thu Jul 1 15:08:22 2010 @@ -0,0 +1,51 @@ +//===-- ClangResultSynthesizer.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_ClangResultSynthesizer_h_ +#define liblldb_ClangResultSynthesizer_h_ + +#include "clang/Sema/SemaConsumer.h" + +namespace clang { + class Action; +} + +namespace lldb_private { + +class ClangResultSynthesizer : public clang::SemaConsumer +{ +public: + ClangResultSynthesizer(clang::ASTConsumer *passthrough); + ~ClangResultSynthesizer(); + + void Initialize(clang::ASTContext &Context); + void HandleTopLevelDecl(clang::DeclGroupRef D); + void HandleTranslationUnit(clang::ASTContext &Ctx); + void HandleTagDeclDefinition(clang::TagDecl *D); + void CompleteTentativeDefinition(clang::VarDecl *D); + void HandleVTable(clang::CXXRecordDecl *RD, bool DefinitionRequired); + void PrintStats(); + + void InitializeSema(clang::Sema &S); + void ForgetSema(); +private: + void TransformTopLevelDecl(clang::Decl *D); + bool SynthesizeResult(clang::ASTContext &Ctx, + clang::FunctionDecl *FunDecl); + + clang::ASTContext *m_ast_context; + clang::ASTConsumer *m_passthrough; + clang::SemaConsumer *m_passthrough_sema; + clang::Sema *m_sema; + clang::Action *m_action; +}; + +} + +#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=107419&r1=107418&r2=107419&view=diff ============================================================================== --- lldb/trunk/lldb.xcodeproj/project.pbxproj (original) +++ lldb/trunk/lldb.xcodeproj/project.pbxproj Thu Jul 1 15:08:22 2010 @@ -328,6 +328,8 @@ 26F5C32D10F3DFDD009D5894 /* libtermcap.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 26F5C32B10F3DFDD009D5894 /* libtermcap.dylib */; }; 26F5C37510F3F61B009D5894 /* libobjc.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 26F5C37410F3F61B009D5894 /* libobjc.dylib */; }; 26F5C39110F3FA26009D5894 /* CoreFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 26F5C39010F3FA26009D5894 /* CoreFoundation.framework */; }; + 49A8A3A011D568A300AD3B68 /* ClangResultSynthesizer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 49A8A39F11D568A300AD3B68 /* ClangResultSynthesizer.cpp */; }; + 49A8A3A411D568BF00AD3B68 /* ClangResultSynthesizer.h in Headers */ = {isa = PBXBuildFile; fileRef = 49A8A3A311D568BF00AD3B68 /* ClangResultSynthesizer.h */; }; 49D7072711B5AD03001AD875 /* ClangASTSource.h in Headers */ = {isa = PBXBuildFile; fileRef = 49D7072611B5AD03001AD875 /* ClangASTSource.h */; }; 49D7072911B5AD11001AD875 /* ClangASTSource.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 49D7072811B5AD11001AD875 /* ClangASTSource.cpp */; settings = {COMPILER_FLAGS = "-fno-rtti"; }; }; 49F1A74611B3388F003ED505 /* ClangExpressionDeclMap.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 49F1A74511B3388F003ED505 /* ClangExpressionDeclMap.cpp */; }; @@ -896,6 +898,8 @@ 497E7B9D1188F6690065CCA1 /* ABI.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ABI.cpp; path = source/Target/ABI.cpp; sourceTree = ""; }; 499F381E11A5B3F300F5CE02 /* CommandObjectArgs.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CommandObjectArgs.h; path = source/Commands/CommandObjectArgs.h; sourceTree = ""; }; 499F381F11A5B3F300F5CE02 /* CommandObjectArgs.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CommandObjectArgs.cpp; path = source/Commands/CommandObjectArgs.cpp; sourceTree = ""; }; + 49A8A39F11D568A300AD3B68 /* ClangResultSynthesizer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ClangResultSynthesizer.cpp; path = source/Expression/ClangResultSynthesizer.cpp; sourceTree = ""; }; + 49A8A3A311D568BF00AD3B68 /* ClangResultSynthesizer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ClangResultSynthesizer.h; path = include/lldb/Expression/ClangResultSynthesizer.h; sourceTree = ""; }; 49BF48DC11ADF356008863BD /* ObjCObjectPrinter.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ObjCObjectPrinter.cpp; path = source/Target/ObjCObjectPrinter.cpp; sourceTree = ""; }; 49BF48E011ADF37D008863BD /* ObjCObjectPrinter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ObjCObjectPrinter.h; path = include/lldb/Target/ObjCObjectPrinter.h; sourceTree = ""; }; 49D7072611B5AD03001AD875 /* ClangASTSource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ClangASTSource.h; path = include/lldb/Expression/ClangASTSource.h; sourceTree = ""; }; @@ -1822,6 +1826,8 @@ 49F1A74511B3388F003ED505 /* ClangExpressionDeclMap.cpp */, 26BC7DC110F1B79500F91463 /* ClangExpressionVariable.h */, 26BC7ED610F1B86700F91463 /* ClangExpressionVariable.cpp */, + 49A8A3A311D568BF00AD3B68 /* ClangResultSynthesizer.h */, + 49A8A39F11D568A300AD3B68 /* ClangResultSynthesizer.cpp */, 26BC7DC210F1B79500F91463 /* ClangStmtVisitor.h */, 26BC7ED710F1B86700F91463 /* ClangStmtVisitor.cpp */, 26BC7DC310F1B79500F91463 /* DWARFExpression.h */, @@ -2177,6 +2183,7 @@ 49D7072711B5AD03001AD875 /* ClangASTSource.h in Headers */, 261B5A5511C3F2AD00AABD0A /* SharingPtr.h in Headers */, 4C08CDEC11C81F1E001610A8 /* ThreadSpec.h in Headers */, + 49A8A3A411D568BF00AD3B68 /* ClangResultSynthesizer.h in Headers */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -2625,6 +2632,7 @@ AF94005911C03F6500085DB9 /* SymbolVendor.cpp in Sources */, 261B5A5411C3F2AD00AABD0A /* SharingPtr.cpp in Sources */, 4C08CDE811C81EF8001610A8 /* ThreadSpec.cpp in Sources */, + 49A8A3A011D568A300AD3B68 /* ClangResultSynthesizer.cpp in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; Modified: lldb/trunk/source/Commands/CommandObjectExpression.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectExpression.cpp?rev=107419&r1=107418&r2=107419&view=diff ============================================================================== --- lldb/trunk/source/Commands/CommandObjectExpression.cpp (original) +++ lldb/trunk/source/Commands/CommandObjectExpression.cpp Thu Jul 1 15:08:22 2010 @@ -233,7 +233,7 @@ if (bare) num_errors = clang_expr.ParseBareExpression (llvm::StringRef (expr), error_stream); else - num_errors = clang_expr.ParseExpression (expr, error_stream); + num_errors = clang_expr.ParseExpression (expr, error_stream, m_options.use_ir); if (num_errors) { Modified: lldb/trunk/source/Expression/ClangExpression.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/ClangExpression.cpp?rev=107419&r1=107418&r2=107419&view=diff ============================================================================== --- lldb/trunk/source/Expression/ClangExpression.cpp (original) +++ lldb/trunk/source/Expression/ClangExpression.cpp Thu Jul 1 15:08:22 2010 @@ -38,6 +38,7 @@ #include "clang/Frontend/VerifyDiagnosticsClient.h" #include "clang/Lex/Preprocessor.h" #include "clang/Sema/ParseAST.h" +#include "clang/Sema/SemaConsumer.h" #include "llvm/ExecutionEngine/ExecutionEngine.h" #include "llvm/ExecutionEngine/JIT.h" #include "llvm/Module.h" @@ -53,6 +54,7 @@ #include "lldb/Core/Log.h" #include "lldb/Expression/ClangExpression.h" #include "lldb/Expression/ClangASTSource.h" +#include "lldb/Expression/ClangResultSynthesizer.h" #include "lldb/Expression/ClangStmtVisitor.h" #include "lldb/Symbol/ClangASTContext.h" #include "lldb/Expression/RecordingMemoryManager.h" @@ -279,19 +281,23 @@ } unsigned -ClangExpression::ParseExpression (const char *expr_text, Stream &stream) +ClangExpression::ParseExpression (const char *expr_text, + Stream &stream, + bool add_result_var) { // 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("void ___clang_expr()\n{\n\t"); + std::string func_expr("extern \"C\" void ___clang_expr()\n{\n\t"); func_expr.append(expr_text); func_expr.append(";\n}"); - return ParseBareExpression (func_expr, stream); + return ParseBareExpression (func_expr, stream, add_result_var); } unsigned -ClangExpression::ParseBareExpression (llvm::StringRef expr_text, Stream &stream) +ClangExpression::ParseBareExpression (llvm::StringRef expr_text, + Stream &stream, + bool add_result_var) { Mutex::Locker locker(GetClangMutex ()); @@ -354,7 +360,17 @@ // - CodeGeneration ASTConsumer (include/clang/ModuleBuilder.h), which will be passed in when you call... // - Call clang::ParseAST (in lib/Sema/ParseAST.cpp) to parse the buffer. The CodeGenerator will generate code for __dbg_expr. // - Once ParseAST completes, you can grab the llvm::Module from the CodeGenerator, which will have an llvm::Function you can hand off to the JIT. - ParseAST(m_clang_ap->getPreprocessor(), m_code_generator_ptr, m_clang_ap->getASTContext()); + + if (add_result_var) + { + ClangResultSynthesizer result_synthesizer(m_code_generator_ptr); + ParseAST(m_clang_ap->getPreprocessor(), &result_synthesizer, m_clang_ap->getASTContext()); + } + else + { + ParseAST(m_clang_ap->getPreprocessor(), m_code_generator_ptr, m_clang_ap->getASTContext()); + } + text_diagnostic_buffer.EndSourceFile(); @@ -413,7 +429,6 @@ return num_errors; } - static FrontendAction * CreateFrontendAction(CompilerInstance &CI) { @@ -471,41 +486,42 @@ return 1; } - llvm::Module::iterator fi; - - for (fi = module->begin(); - fi != module->end(); - ++fi) + llvm::Function* function = module->getFunction(StringRef("___clang_expr")); + + if (!function) { - llvm::Function &function = *fi; - if (log) - log->Printf("IR for %s:", function.getName().str().c_str()); + log->Printf("Couldn't find ___clang_expr() in the module"); + + return 1; + } + + if (log) + log->Printf("IR for %s:", function->getName().str().c_str()); + + llvm::Function::iterator bbi; + + for (bbi = function->begin(); + bbi != function->end(); + ++bbi) + { + llvm::BasicBlock &bb = *bbi; - llvm::Function::iterator bbi; + llvm::BasicBlock::iterator ii; - for (bbi = function.begin(); - bbi != function.end(); - ++bbi) + for (ii = bb.begin(); + ii != bb.end(); + ++ii) { - llvm::BasicBlock &bb = *bbi; - - llvm::BasicBlock::iterator ii; - - for (ii = bb.begin(); - ii != bb.end(); - ++ii) - { - llvm::Instruction &inst = *ii; - - std::string s; - llvm::raw_string_ostream os(s); - - inst.print(os); - - if (log) - log->Printf(" %s", s.c_str()); - } + llvm::Instruction &inst = *ii; + + std::string s; + llvm::raw_string_ostream os(s); + + inst.print(os); + + if (log) + log->Printf(" %s", s.c_str()); } } Added: lldb/trunk/source/Expression/ClangResultSynthesizer.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/ClangResultSynthesizer.cpp?rev=107419&view=auto ============================================================================== --- lldb/trunk/source/Expression/ClangResultSynthesizer.cpp (added) +++ lldb/trunk/source/Expression/ClangResultSynthesizer.cpp Thu Jul 1 15:08:22 2010 @@ -0,0 +1,341 @@ +//===-- ClangResultSynthesizer.cpp ------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "stdlib.h" +#include "clang/AST/ASTContext.h" +#include "clang/AST/Decl.h" +#include "clang/AST/DeclCXX.h" +#include "clang/AST/DeclGroup.h" +#include "clang/AST/Expr.h" +#include "clang/AST/Stmt.h" +#include "clang/Parse/Action.h" +#include "clang/Parse/Parser.h" +#include "clang/Parse/Scope.h" +#include "llvm/Support/Casting.h" +#include "llvm/Support/raw_ostream.h" +#include "lldb/Core/Log.h" +#include "lldb/Expression/ClangResultSynthesizer.h" + +using namespace llvm; +using namespace clang; +using namespace lldb_private; + +ClangResultSynthesizer::ClangResultSynthesizer(ASTConsumer *passthrough) : + m_passthrough(passthrough), + m_passthrough_sema(NULL), + m_sema(NULL), + m_ast_context(NULL) +{ + if (!m_passthrough) + return; + + m_passthrough_sema = dyn_cast(passthrough); +} + +ClangResultSynthesizer::~ClangResultSynthesizer() +{ +} + +void +ClangResultSynthesizer::Initialize(ASTContext &Context) +{ + m_ast_context = &Context; + + if (m_passthrough) + m_passthrough->Initialize(Context); +} + +void +ClangResultSynthesizer::TransformTopLevelDecl(Decl* D) +{ + LinkageSpecDecl *linkage_spec_decl = dyn_cast(D); + + if (linkage_spec_decl) + { + RecordDecl::decl_iterator decl_iterator; + + for (decl_iterator = linkage_spec_decl->decls_begin(); + decl_iterator != linkage_spec_decl->decls_end(); + ++decl_iterator) + { + TransformTopLevelDecl(*decl_iterator); + } + } + + FunctionDecl *function_decl = dyn_cast(D); + + if (m_ast_context && + function_decl && + !strcmp(function_decl->getNameAsCString(), + "___clang_expr")) + { + SynthesizeResult(*m_ast_context, function_decl); + } +} + +void +ClangResultSynthesizer::HandleTopLevelDecl(DeclGroupRef D) +{ + DeclGroupRef::iterator decl_iterator; + + for (decl_iterator = D.begin(); + decl_iterator != D.end(); + ++decl_iterator) + { + Decl *decl = *decl_iterator; + + TransformTopLevelDecl(decl); + } + + if (m_passthrough) + m_passthrough->HandleTopLevelDecl(D); +} + +bool +ClangResultSynthesizer::SynthesizeResult (ASTContext &Ctx, + FunctionDecl *FunDecl) +{ + Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS); + + if (!m_sema) + return false; + + FunctionDecl *function_decl = FunDecl; + + if (!function_decl) + return false; + + Stmt *function_body = function_decl->getBody(); + CompoundStmt *compound_stmt = dyn_cast(function_body); + + if (!compound_stmt) + return false; + + if (compound_stmt->body_empty()) + return false; + + Stmt **last_stmt_ptr = compound_stmt->body_end() - 1; + Stmt *last_stmt = *last_stmt_ptr; + + Expr *last_expr = dyn_cast(last_stmt); + + if (!last_expr) + // No auxiliary variable necessary; expression returns void + return true; + + QualType expr_qual_type = last_expr->getType(); + clang::Type *expr_type = expr_qual_type.getTypePtr(); + + if (!expr_type) + return false; + + if (expr_type->isVoidType()) + return true; + + if (log) + { + std::string s = expr_qual_type.getAsString(); + + log->Printf("Last statement's type: %s", s.c_str()); + } + + IdentifierInfo &result_id = Ctx.Idents.get("___clang_expr_result"); + + DeclContext *decl_context = function_decl->getDeclContext(); + + clang::VarDecl *result_decl = VarDecl::Create(Ctx, + function_decl, + SourceLocation(), + &result_id, + expr_qual_type, + NULL, + VarDecl::Static, + VarDecl::Static); + + if (!result_decl) + return false; + + function_decl->addDecl(result_decl); + + /////////////////////////////// + // call AddInitializerToDecl + // + + Parser::DeclPtrTy result_decl_ptr; + result_decl_ptr.set(result_decl); + + m_action->AddInitializerToDecl(result_decl_ptr, Parser::ExprArg(*m_action, last_expr)); + + ///////////////////////////////// + // call ConvertDeclToDeclGroup + // + + Parser::DeclGroupPtrTy result_decl_group_ptr; + + result_decl_group_ptr = m_action->ConvertDeclToDeclGroup(result_decl_ptr); + + //////////////////////// + // call ActOnDeclStmt + // + + Parser::OwningStmtResult result_initialization_stmt_result(m_action->ActOnDeclStmt(result_decl_group_ptr, + SourceLocation(), + SourceLocation())); + + + /////////////////////////////////////////////// + // Synthesize external void pointer variable + // + + IdentifierInfo &result_ptr_id = Ctx.Idents.get("___clang_expr_result_ptr"); + + clang::VarDecl *result_ptr_decl = VarDecl::Create(Ctx, + decl_context, + SourceLocation(), + &result_ptr_id, + Ctx.VoidPtrTy, + NULL, + VarDecl::Extern, + VarDecl::Extern); + + ///////////////////////////////////////////// + // Build a DeclRef for the result variable + // + + DeclRefExpr *result_decl_ref_expr = DeclRefExpr::Create(Ctx, + NULL, + SourceRange(), + result_decl, + SourceLocation(), + expr_qual_type); + + /////////////////////// + // call ActOnUnaryOp + // + + Scope my_scope(NULL, (Scope::BlockScope | Scope::FnScope | Scope::DeclScope)); + + Parser::DeclPtrTy result_ptr_decl_ptr; + result_ptr_decl_ptr.set(result_ptr_decl); + + Parser::OwningExprResult addressof_expr_result(m_action->ActOnUnaryOp(&my_scope, + SourceLocation(), + tok::amp, + Parser::ExprArg(*m_action, result_decl_ref_expr))); + + //////////////////////////////////////////// + // Build a DeclRef for the result pointer + // + + DeclRefExpr *result_ptr_decl_ref_expr = DeclRefExpr::Create(Ctx, + NULL, + SourceRange(), + result_ptr_decl, + SourceLocation(), + Ctx.VoidPtrTy); + + //////////////////////// + // call ActOnBinaryOp + // + + Parser::OwningExprResult assignment_expr_result(m_action->ActOnBinOp(&my_scope, + SourceLocation(), + tok::equal, + Parser::ExprArg(*m_action, result_ptr_decl_ref_expr), + Parser::ExprArg(*m_action, addressof_expr_result.take()))); + + //////////////////////////// + // call ActOnCompoundStmt + // + + void *stmts[2]; + + stmts[0] = result_initialization_stmt_result.take(); + stmts[1] = assignment_expr_result.take(); + + Parser::OwningStmtResult compound_stmt_result(m_action->ActOnCompoundStmt(SourceLocation(), + SourceLocation(), + Parser::MultiStmtArg(*m_action, stmts, 2), + false)); + + //////////////////////////////////////////////// + // replace the old statement with the new one + // + + *last_stmt_ptr = reinterpret_cast(compound_stmt_result.take()); + + if (log) + { + std::string s; + raw_string_ostream os(s); + + function_decl->print(os); + + os.flush(); + + log->Printf("Transformed function AST:\n%s", s.c_str()); + } + + return true; +} + +void +ClangResultSynthesizer::HandleTranslationUnit(ASTContext &Ctx) +{ + if (m_passthrough) + m_passthrough->HandleTranslationUnit(Ctx); +} + +void +ClangResultSynthesizer::HandleTagDeclDefinition(TagDecl *D) +{ + if (m_passthrough) + m_passthrough->HandleTagDeclDefinition(D); +} + +void +ClangResultSynthesizer::CompleteTentativeDefinition(VarDecl *D) +{ + if (m_passthrough) + m_passthrough->CompleteTentativeDefinition(D); +} + +void +ClangResultSynthesizer::HandleVTable(CXXRecordDecl *RD, bool DefinitionRequired) +{ + if (m_passthrough) + m_passthrough->HandleVTable(RD, DefinitionRequired); +} + +void +ClangResultSynthesizer::PrintStats() +{ + if (m_passthrough) + m_passthrough->PrintStats(); +} + +void +ClangResultSynthesizer::InitializeSema(Sema &S) +{ + m_sema = &S; + m_action = reinterpret_cast(m_sema); + + if (m_passthrough_sema) + m_passthrough_sema->InitializeSema(S); +} + +void +ClangResultSynthesizer::ForgetSema() +{ + m_sema = NULL; + m_action = NULL; + + if (m_passthrough_sema) + m_passthrough_sema->ForgetSema(); +} From johnny.chen at apple.com Thu Jul 1 17:52:57 2010 From: johnny.chen at apple.com (Johnny Chen) Date: Thu, 01 Jul 2010 22:52:57 -0000 Subject: [Lldb-commits] [lldb] r107445 - in /lldb/trunk/test: array_types/TestArrayTypes.py class_types/TestClassTypes.py dotest.py help/TestHelp.py Message-ID: <20100701225257.C87CA2A6C12C@llvm.org> Author: johnny Date: Thu Jul 1 17:52:57 2010 New Revision: 107445 URL: http://llvm.org/viewvc/llvm-project?rev=107445&view=rev Log: Turn on logging for debugging purposes if ${LLDB_LOG} environment variable is is defined. Use ${LLDB_LOG} to specify the log file. Create a singleton SBDebugger in the lldb namespace, that gets used when running the entire test suite. Modified: lldb/trunk/test/array_types/TestArrayTypes.py lldb/trunk/test/class_types/TestClassTypes.py lldb/trunk/test/dotest.py lldb/trunk/test/help/TestHelp.py Modified: lldb/trunk/test/array_types/TestArrayTypes.py URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/array_types/TestArrayTypes.py?rev=107445&r1=107444&r2=107445&view=diff ============================================================================== --- lldb/trunk/test/array_types/TestArrayTypes.py (original) +++ lldb/trunk/test/array_types/TestArrayTypes.py Thu Jul 1 17:52:57 2010 @@ -4,15 +4,19 @@ import lldb import unittest +main = False + class TestArrayTypes(unittest.TestCase): def setUp(self): + global main + # Save old working directory. self.oldcwd = os.getcwd() # Change current working directory if ${LLDB_TEST} is defined. if ("LLDB_TEST" in os.environ): os.chdir(os.path.join(os.environ["LLDB_TEST"], "array_types")); - self.dbg = lldb.SBDebugger.Create() + self.dbg = lldb.SBDebugger.Create() if main else lldb.DBG if not self.dbg.IsValid(): raise Exception('Invalid debugger instance') self.dbg.SetAsync(False) @@ -23,6 +27,7 @@ def tearDown(self): # Restore old working directory. os.chdir(self.oldcwd) + del self.dbg def test_array_types(self): """Test 'variable list var_name' on some variables with array types.""" @@ -87,5 +92,6 @@ if __name__ == '__main__': lldb.SBDebugger.Initialize() + main = True unittest.main() lldb.SBDebugger.Terminate() Modified: lldb/trunk/test/class_types/TestClassTypes.py URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/class_types/TestClassTypes.py?rev=107445&r1=107444&r2=107445&view=diff ============================================================================== --- lldb/trunk/test/class_types/TestClassTypes.py (original) +++ lldb/trunk/test/class_types/TestClassTypes.py Thu Jul 1 17:52:57 2010 @@ -4,15 +4,19 @@ import lldb import unittest +main = False + class TestClassTypes(unittest.TestCase): def setUp(self): + global main + # Save old working directory. self.oldcwd = os.getcwd() # Change current working directory if ${LLDB_TEST} is defined. if ("LLDB_TEST" in os.environ): os.chdir(os.path.join(os.environ["LLDB_TEST"], "class_types")); - self.dbg = lldb.SBDebugger.Create() + self.dbg = lldb.SBDebugger.Create() if main else lldb.DBG if not self.dbg.IsValid(): raise Exception('Invalid debugger instance') self.dbg.SetAsync(False) @@ -23,6 +27,7 @@ def tearDown(self): # Restore old working directory. os.chdir(self.oldcwd) + del self.dbg def test_class_types(self): """Test 'variable list this' when stopped on a class constructor.""" @@ -64,5 +69,6 @@ if __name__ == '__main__': lldb.SBDebugger.Initialize() + main = True unittest.main() lldb.SBDebugger.Terminate() Modified: lldb/trunk/test/dotest.py URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/dotest.py?rev=107445&r1=107444&r2=107445&view=diff ============================================================================== --- lldb/trunk/test/dotest.py (original) +++ lldb/trunk/test/dotest.py Thu Jul 1 17:52:57 2010 @@ -141,6 +141,20 @@ import lldb lldb.SBDebugger.Initialize() +# Create a singleton SBDebugger in the lldb namespace. +lldb.DBG = lldb.SBDebugger.Create() + +# Turn on logging for debugging purposes if ${LLDB_LOG} environment variable is +# is defined. Use ${LLDB_LOG} to specify the log file. +ci = lldb.DBG.GetCommandInterpreter() +res = lldb.SBCommandReturnObject() +if ("LLDB_LOG" in os.environ): + ci.HandleCommand( + "log enable -f " + os.environ["LLDB_LOG"] + " lldb default", res) + pass +if not res.Succeeded(): + raise Exception('log enable failed (check your LLDB_LOG env variable...') + unittest.TextTestRunner(verbosity=verbose).run(suite) # Add some delay before calling SBDebugger.Terminate(). Modified: lldb/trunk/test/help/TestHelp.py URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/help/TestHelp.py?rev=107445&r1=107444&r2=107445&view=diff ============================================================================== --- lldb/trunk/test/help/TestHelp.py (original) +++ lldb/trunk/test/help/TestHelp.py Thu Jul 1 17:52:57 2010 @@ -4,15 +4,19 @@ import lldb import unittest +main = False + class TestHelpCommand(unittest.TestCase): def setUp(self): + global main + # Save old working directory. self.oldcwd = os.getcwd() # Change current working directory if ${LLDB_TEST} is defined. if ("LLDB_TEST" in os.environ): os.chdir(os.path.join(os.environ["LLDB_TEST"], "help")); - self.dbg = lldb.SBDebugger.Create() + self.dbg = lldb.SBDebugger.Create() if main else lldb.DBG if not self.dbg.IsValid(): raise Exception('Invalid debugger instance') self.dbg.SetAsync(False) @@ -23,6 +27,7 @@ def tearDown(self): # Restore old working directory. os.chdir(self.oldcwd) + del self.dbg def test_simplehelp(self): """A simple test of 'help' command and its output.""" @@ -48,5 +53,6 @@ if __name__ == '__main__': lldb.SBDebugger.Initialize() + main = True unittest.main() lldb.SBDebugger.Terminate() From johnny.chen at apple.com Thu Jul 1 18:01:23 2010 From: johnny.chen at apple.com (Johnny Chen) Date: Thu, 01 Jul 2010 23:01:23 -0000 Subject: [Lldb-commits] [lldb] r107447 - /lldb/trunk/test/dotest.pl Message-ID: <20100701230123.9AC212A6C12C@llvm.org> Author: johnny Date: Thu Jul 1 18:01:23 2010 New Revision: 107447 URL: http://llvm.org/viewvc/llvm-project?rev=107447&view=rev Log: A dumber way to invoke the test suite. Use this script to visit each python test case under the specified directory and run python unittest.main() on each test case. Added: lldb/trunk/test/dotest.pl (with props) Added: lldb/trunk/test/dotest.pl URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/dotest.pl?rev=107447&view=auto ============================================================================== --- lldb/trunk/test/dotest.pl (added) +++ lldb/trunk/test/dotest.pl Thu Jul 1 18:01:23 2010 @@ -0,0 +1,43 @@ +#!/usr/bin/perl -w + +# +# Use this script to visit each python test case under the specified directory +# and invoke unittest.main() on each test case. +# + +use strict; +use FindBin; +use File::Find; +use File::Basename; +use Cwd; +use Cwd 'abs_path'; + +scalar(@ARGV) == 1 or die "Usage: dotest.pl testdir"; + +my $scriptDir = $FindBin::Bin; +my $baseDir = abs_path("$scriptDir/.."); +my $testDir = $ARGV[0]; + +my $dbgPath = "$baseDir/build/Debug/LLDB.framework/Resources/Python"; +my $relPath = "$baseDir/build/Release/LLDB.framework/Resources/Python"; +if (-d $dbgPath) { + $ENV{'PYTHONPATH'} = "$dbgPath"; +} elsif (-d $relPath) { + $ENV{'PYTHONPATH'} = "$relPath"; +} +#print("ENV{PYTHONPATH}=$ENV{'PYTHONPATH'}\n"); + +# Traverse the directory to find our python test cases. +find(\&handleFind, $testDir); + +sub handleFind { + my $foundFile = $File::Find::name; + my $dir = getcwd; + #print("foundFile: $foundFile\n"); + + # Test*.py is the naming pattern for our test cases. + if ($foundFile =~ /.*\/(Test.*\.py)$/) { + print("Running python $1 (cwd = $dir)...\n"); + system("python $1"); + } +} Propchange: lldb/trunk/test/dotest.pl ------------------------------------------------------------------------------ svn:executable = * From gclayton at apple.com Thu Jul 1 19:29:31 2010 From: gclayton at apple.com (Greg Clayton) Date: Fri, 02 Jul 2010 00:29:31 -0000 Subject: [Lldb-commits] [lldb] r107453 - /lldb/trunk/source/Core/Mangled.cpp Message-ID: <20100702002931.7C3202A6C12C@llvm.org> Author: gclayton Date: Thu Jul 1 19:29:31 2010 New Revision: 107453 URL: http://llvm.org/viewvc/llvm-project?rev=107453&view=rev Log: Removed the thread specific data that was being used for demangling since removing it didn't cause any performance loss, and leaks were showing up when run under instruments when we tried to re-use the buffer. We are now leak free and still just as performant. Modified: lldb/trunk/source/Core/Mangled.cpp Modified: lldb/trunk/source/Core/Mangled.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/Mangled.cpp?rev=107453&r1=107452&r2=107453&view=diff ============================================================================== --- lldb/trunk/source/Core/Mangled.cpp (original) +++ lldb/trunk/source/Core/Mangled.cpp Thu Jul 1 19:29:31 2010 @@ -118,40 +118,6 @@ } } -namespace -{ - //------------------------------------------------------------------ - // Convenience wrapper for __cxa_demangle. - //------------------------------------------------------------------ - class DemangleBuffer - { - char *m_demangle_buf; - size_t m_demangle_buf_len; - public: - DemangleBuffer () : m_demangle_buf (NULL), m_demangle_buf_len (0) {} - ~DemangleBuffer () - { - free (m_demangle_buf); - } - int Demangle (const char *mangled) - { - int status = 0; - m_demangle_buf = abi::__cxa_demangle(mangled, m_demangle_buf, - &m_demangle_buf_len, &status); - return status; - } - const char *GetBuffer () const { return m_demangle_buf; } - }; -} - -//---------------------------------------------------------------------- -// Used to delete the thread specific buffer when the thread exits. -//---------------------------------------------------------------------- -static void FreeDemangleBuffer (void *buf) -{ - delete static_cast (buf); -} - //---------------------------------------------------------------------- // Generate the demangled name on demand using this accessor. Code in // this class will need to use this accessor if it wishes to decode @@ -176,29 +142,12 @@ const char * mangled = m_mangled.AsCString(); if (mangled[0]) { - // The first time the demangling routine is called, it will - // return a buffer value and length and we will continue to - // re-use that buffer so we don't always have to malloc/free - // a buffer for each demangle. The buffer can be realloc'ed - // by abi::__cxa_demangle, so we need to make it thread - // specific. - - // Set up thread specific storage. - static pthread_key_t g_demangle_key = 0; - if (!g_demangle_key) - ::pthread_key_create (&g_demangle_key, FreeDemangleBuffer); - - DemangleBuffer *buf = static_cast ( - ::pthread_getspecific (g_demangle_key)); - if (!buf) // No buffer for this thread, create a new one. - { - buf = new DemangleBuffer (); - ::pthread_setspecific (g_demangle_key, buf); - } + char *demangled_name = abi::__cxa_demangle (mangled, NULL, NULL, NULL); - if (buf->Demangle (mangled) == 0) + if (demangled_name) { - m_demangled.SetCString(buf->GetBuffer()); + m_demangled.SetCString (demangled_name); + free (demangled_name); } else { From jingham at apple.com Thu Jul 1 19:45:55 2010 From: jingham at apple.com (Jim Ingham) Date: Fri, 02 Jul 2010 00:45:55 -0000 Subject: [Lldb-commits] [lldb] r107455 - in /lldb/trunk: include/lldb/Core/FileSpec.h source/Commands/CommandCompletions.cpp Message-ID: <20100702004555.A7D8D2A6C12C@llvm.org> Author: jingham Date: Thu Jul 1 19:45:55 2010 New Revision: 107455 URL: http://llvm.org/viewvc/llvm-project?rev=107455&view=rev Log: Remove duplicate def'n from FileSpec.h. Add user name completion to the file completer. Modified: lldb/trunk/include/lldb/Core/FileSpec.h lldb/trunk/source/Commands/CommandCompletions.cpp Modified: lldb/trunk/include/lldb/Core/FileSpec.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/FileSpec.h?rev=107455&r1=107454&r2=107455&view=diff ============================================================================== --- lldb/trunk/include/lldb/Core/FileSpec.h (original) +++ lldb/trunk/include/lldb/Core/FileSpec.h Thu Jul 1 19:45:55 2010 @@ -432,9 +432,6 @@ ReadFileLines (STLStringArray &lines); static int - ResolveUsername (const char *src_path, char *dst_path, size_t dst_len); - - static int Resolve (const char *src_path, char *dst_path, size_t dst_len); protected: Modified: lldb/trunk/source/Commands/CommandCompletions.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandCompletions.cpp?rev=107455&r1=107454&r2=107455&view=diff ============================================================================== --- lldb/trunk/source/Commands/CommandCompletions.cpp (original) +++ lldb/trunk/source/Commands/CommandCompletions.cpp Thu Jul 1 19:45:55 2010 @@ -13,6 +13,8 @@ #include #include #include +#include +#include // C++ Includes // Other libraries and framework includes @@ -22,6 +24,7 @@ #include "lldb/Core/FileSpecList.h" #include "lldb/Target/Target.h" #include "lldb/Interpreter/CommandCompletions.h" +#include "lldb/Core/FileSpec.h" using namespace lldb_private; @@ -155,20 +158,52 @@ if (*partial_name_copy == '~') { // Nothing here but the user name. We could just put a slash on the end, - // but for completeness sake we'll glob the user name and only put a slash + // but for completeness sake we'll resolve the user name and only put a slash // on the end if it exists. - glob_t glob_buf; - if (glob (partial_name_copy, GLOB_TILDE, NULL, &glob_buf) != 0) - return matches.GetSize(); - - //The thing exists, put a '/' on the end, and return it... - // FIXME: complete user names here: - partial_name_copy[partial_name_len] = '/'; - partial_name_copy[partial_name_len+1] = '\0'; - matches.AppendString(partial_name_copy); - globfree(&glob_buf); - saw_directory = true; - return matches.GetSize(); + char resolved_username[PATH_MAX]; + int resolved_username_len = FileSpec::ResolveUsername (partial_name_copy, resolved_username, + sizeof (resolved_username)); + + // Not sure how this would happen, a username longer than PATH_MAX? Still... + if (resolved_username_len >= sizeof (resolved_username)) + return matches.GetSize(); + else if (resolved_username_len == 0) + { + // The user name didn't resolve, let's look in the password database for matches. + // The user name database contains duplicates, and is not in alphabetical order, so + // we'll use a set to manage that for us. + + setpwent(); + struct passwd *user_entry; + const char *name_start = partial_name_copy + 1; + std::set name_list; + + while ((user_entry = getpwent()) != NULL) + { + if (strstr(user_entry->pw_name, name_start) == user_entry->pw_name) + { + std::string tmp_buf("~"); + tmp_buf.append(user_entry->pw_name); + tmp_buf.push_back('/'); + name_list.insert(tmp_buf); + saw_directory = true; + } + } + std::set::iterator pos, end = name_list.end(); + for (pos = name_list.begin(); pos != end; pos++) + { + matches.AppendString((*pos).c_str()); + } + return matches.GetSize(); + } + + //The thing exists, put a '/' on the end, and return it... + // FIXME: complete user names here: + partial_name_copy[partial_name_len] = '/'; + partial_name_copy[partial_name_len+1] = '\0'; + matches.AppendString(partial_name_copy); + saw_directory = true; + return matches.GetSize(); } else { @@ -198,25 +233,15 @@ strcpy(remainder, end_ptr); } - // Look for a user name in the containing part, and if it's there, glob containing_part and stick the + // Look for a user name in the containing part, and if it's there, resolve it and stick the // result back into the containing_part: if (*partial_name_copy == '~') { - glob_t glob_buf; - + int resolved_username_len = FileSpec::ResolveUsername(containing_part, containing_part, sizeof (containing_part)); // User name doesn't exist, we're not getting any further... - if (glob (containing_part, GLOB_TILDE, NULL, &glob_buf) != 0) + if (resolved_username_len = 0 || resolved_username_len >= sizeof (containing_part)) return matches.GetSize(); - - if (glob_buf.gl_pathc != 1) - { - // I'm not really sure how this would happen? - globfree(&glob_buf); - return matches.GetSize(); - } - strcpy(containing_part, glob_buf.gl_pathv[0]); - globfree(&glob_buf); } // Okay, containing_part is now the directory we want to open and look for files: @@ -246,6 +271,8 @@ continue; } + // If we found a directory, we put a "/" at the end of the name. + if (remainder[0] == '\0' || strstr(dirent_buf->d_name, remainder) == name) { if (strlen(name) + baselen >= PATH_MAX) From jingham at apple.com Thu Jul 1 19:57:26 2010 From: jingham at apple.com (Jim Ingham) Date: Fri, 02 Jul 2010 00:57:26 -0000 Subject: [Lldb-commits] [lldb] r107456 - /lldb/trunk/include/lldb/Core/FileSpec.h Message-ID: <20100702005726.4CB242A6C12C@llvm.org> Author: jingham Date: Thu Jul 1 19:57:26 2010 New Revision: 107456 URL: http://llvm.org/viewvc/llvm-project?rev=107456&view=rev Log: Resolve dueling commits... Plus add docs for Resolve & ResolveUsername. Modified: lldb/trunk/include/lldb/Core/FileSpec.h Modified: lldb/trunk/include/lldb/Core/FileSpec.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/FileSpec.h?rev=107456&r1=107455&r2=107456&view=diff ============================================================================== --- lldb/trunk/include/lldb/Core/FileSpec.h (original) +++ lldb/trunk/include/lldb/Core/FileSpec.h Thu Jul 1 19:57:26 2010 @@ -433,6 +433,10 @@ static int Resolve (const char *src_path, char *dst_path, size_t dst_len); + + int + ResolveUsername (const char *src_path, char *dst_path, size_t dst_len); + protected: //------------------------------------------------------------------ From jingham at apple.com Thu Jul 1 20:03:49 2010 From: jingham at apple.com (Jim Ingham) Date: Fri, 02 Jul 2010 01:03:49 -0000 Subject: [Lldb-commits] [lldb] r107457 - /lldb/trunk/include/lldb/Core/FileSpec.h Message-ID: <20100702010349.69B8F2A6C12C@llvm.org> Author: jingham Date: Thu Jul 1 20:03:49 2010 New Revision: 107457 URL: http://llvm.org/viewvc/llvm-project?rev=107457&view=rev Log: Remember to save first... Modified: lldb/trunk/include/lldb/Core/FileSpec.h Modified: lldb/trunk/include/lldb/Core/FileSpec.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/FileSpec.h?rev=107457&r1=107456&r2=107457&view=diff ============================================================================== --- lldb/trunk/include/lldb/Core/FileSpec.h (original) +++ lldb/trunk/include/lldb/Core/FileSpec.h Thu Jul 1 20:03:49 2010 @@ -431,10 +431,51 @@ bool ReadFileLines (STLStringArray &lines); + //------------------------------------------------------------------ + /// Resolves user name and links in \a src_path, and writes the output + /// to \a dst_path. Note if the path pointed to by \a src_path does not + /// exist, the contents of \a src_path will be copied to \a dst_path + /// unchanged. + /// + /// @param[in] src_path + /// Input path to be resolved. + /// + /// @param[in] dst_path + /// Buffer to store the resolved path. + /// + /// @param[in] dst_len + /// Size of the buffer pointed to by dst_path. + /// + /// @result + /// The number of characters required to write the resolved path. If the + /// resolved path doesn't fit in dst_len, dst_len-1 characters will + /// be written to \a dst_path, but the actual required length will still be returned. + //------------------------------------------------------------------ static int Resolve (const char *src_path, char *dst_path, size_t dst_len); - int + //------------------------------------------------------------------ + /// Resolves the user name at the beginning of \a src_path, and writes the output + /// to \a dst_path. Note, \a src_path can contain other path components after the + /// user name, they will be copied over, and if the path doesn't start with "~" it + /// will also be copied over to \a dst_path. + /// + /// @param[in] src_path + /// Input path to be resolved. + /// + /// @param[in] dst_path + /// Buffer to store the resolved path. + /// + /// @param[in] dst_len + /// Size of the buffer pointed to by dst_path. + /// + /// @result + /// The number of characters required to write the resolved path, or 0 if + /// the user name could not be found. If the + /// resolved path doesn't fit in dst_len, dst_len-1 characters will + /// be written to \a dst_path, but the actual required length will still be returned. + //------------------------------------------------------------------ + static int ResolveUsername (const char *src_path, char *dst_path, size_t dst_len); From gclayton at apple.com Thu Jul 1 20:29:14 2010 From: gclayton at apple.com (Greg Clayton) Date: Fri, 02 Jul 2010 01:29:14 -0000 Subject: [Lldb-commits] [lldb] r107459 - in /lldb/trunk: include/lldb/Symbol/ClangASTContext.h source/Plugins/Process/MacOSX-User/source/ProcessMacOSX.cpp source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp source/Symbol/ClangASTContext.cpp tools/debugserver/source/MacOSX/MachProcess.cpp Message-ID: <20100702012914.1E5952A6C12C@llvm.org> Author: gclayton Date: Thu Jul 1 20:29:13 2010 New Revision: 107459 URL: http://llvm.org/viewvc/llvm-project?rev=107459&view=rev Log: More leaks detection: - fixed 3 posix spawn attributes leaks - fixed us always leaking CXXBaseSpecifier objects when we create class base classes. Clang apparently copies the base classes we pass in. Fixed some code formatting in ClangASTContext.cpp. Modified: lldb/trunk/include/lldb/Symbol/ClangASTContext.h lldb/trunk/source/Plugins/Process/MacOSX-User/source/ProcessMacOSX.cpp lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp lldb/trunk/source/Symbol/ClangASTContext.cpp lldb/trunk/tools/debugserver/source/MacOSX/MachProcess.cpp Modified: lldb/trunk/include/lldb/Symbol/ClangASTContext.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Symbol/ClangASTContext.h?rev=107459&r1=107458&r2=107459&view=diff ============================================================================== --- lldb/trunk/include/lldb/Symbol/ClangASTContext.h (original) +++ lldb/trunk/include/lldb/Symbol/ClangASTContext.h Thu Jul 1 20:29:13 2010 @@ -33,12 +33,8 @@ //------------------------------------------------------------------ // Constructors and Destructors //------------------------------------------------------------------ -// ClangASTContext(Module *module); - ClangASTContext(const char *target_triple); -// ClangASTContext(const ConstString &target_triple); - ~ClangASTContext(); clang::ASTContext * @@ -131,40 +127,35 @@ //------------------------------------------------------------------ void * - CreateRecordType ( - const char *name, - int kind, - clang::DeclContext *decl_ctx); + CreateRecordType (const char *name, + int kind, + clang::DeclContext *decl_ctx); bool - AddFieldToRecordType ( - void * record_qual_type, - const char *name, - void * field_type, - int access, - uint32_t bitfield_bit_size); - + AddFieldToRecordType (void * record_qual_type, + const char *name, + void * field_type, + int access, + uint32_t bitfield_bit_size); + bool - FieldIsBitfield ( - clang::FieldDecl* field, - uint32_t& bitfield_bit_size); + FieldIsBitfield (clang::FieldDecl* field, + uint32_t& bitfield_bit_size); static bool - FieldIsBitfield ( - clang::ASTContext *ast_context, - clang::FieldDecl* field, - uint32_t& bitfield_bit_size); + FieldIsBitfield (clang::ASTContext *ast_context, + clang::FieldDecl* field, + uint32_t& bitfield_bit_size); static bool RecordHasFields (const clang::RecordDecl *record_decl); void - SetDefaultAccessForRecordFields ( - void * clang_qual_type, - int default_accessibility, - int *assigned_accessibilities, - size_t num_assigned_accessibilities); - + SetDefaultAccessForRecordFields (void * clang_qual_type, + int default_accessibility, + int *assigned_accessibilities, + size_t num_assigned_accessibilities); + //------------------------------------------------------------------ // Aggregate Types //------------------------------------------------------------------ @@ -172,37 +163,34 @@ IsAggregateType (void * clang_type); static uint32_t - GetNumChildren ( - void * clang_type, - bool omit_empty_base_classes); - - void * - GetChildClangTypeAtIndex ( - const char *parent_name, - void * parent_clang_type, - uint32_t idx, - bool transparent_pointers, - bool omit_empty_base_classes, - std::string& child_name, - uint32_t &child_byte_size, - int32_t &child_byte_offset, - uint32_t &child_bitfield_bit_size, - uint32_t &child_bitfield_bit_offset); + GetNumChildren (void * clang_type, + bool omit_empty_base_classes); + void * + GetChildClangTypeAtIndex (const char *parent_name, + void * parent_clang_type, + uint32_t idx, + bool transparent_pointers, + bool omit_empty_base_classes, + std::string& child_name, + uint32_t &child_byte_size, + int32_t &child_byte_offset, + uint32_t &child_bitfield_bit_size, + uint32_t &child_bitfield_bit_offset); + static void * - GetChildClangTypeAtIndex ( - clang::ASTContext *ast_context, - const char *parent_name, - void * parent_clang_type, - uint32_t idx, - bool transparent_pointers, - bool omit_empty_base_classes, - std::string& child_name, - uint32_t &child_byte_size, - int32_t &child_byte_offset, - uint32_t &child_bitfield_bit_size, - uint32_t &child_bitfield_bit_offset); - + GetChildClangTypeAtIndex (clang::ASTContext *ast_context, + const char *parent_name, + void * parent_clang_type, + uint32_t idx, + bool transparent_pointers, + bool omit_empty_base_classes, + std::string& child_name, + uint32_t &child_byte_size, + int32_t &child_byte_offset, + uint32_t &child_bitfield_bit_size, + uint32_t &child_bitfield_bit_offset); + // Lookup a child given a name. This function will match base class names // and member member names in "clang_type" only, not descendants. static uint32_t @@ -228,26 +216,27 @@ //------------------------------------------------------------------ bool - SetTagTypeKind ( - void * tag_qual_type, - int kind); + SetTagTypeKind (void * tag_qual_type, + int kind); //------------------------------------------------------------------ // C++ Base Classes //------------------------------------------------------------------ clang::CXXBaseSpecifier * - CreateBaseClassSpecifier ( - void * base_class_type, - int access, - bool is_virtual, - bool base_of_class); + CreateBaseClassSpecifier (void * base_class_type, + int access, + bool is_virtual, + bool base_of_class); + + static void + DeleteBaseClassSpecifiers (clang::CXXBaseSpecifier **base_classes, + unsigned num_base_classes); bool - SetBaseClassesForClassType ( - void * class_clang_type, - clang::CXXBaseSpecifier const * const *base_classes, - unsigned num_base_classes); + SetBaseClassesForClassType (void * class_clang_type, + clang::CXXBaseSpecifier const * const *base_classes, + unsigned num_base_classes); //------------------------------------------------------------------ // DeclContext Functions @@ -261,51 +250,45 @@ //------------------------------------------------------------------ clang::NamespaceDecl * - GetUniqueNamespaceDeclaration ( - const char *name, - const Declaration &decl, - clang::DeclContext *decl_ctx); + GetUniqueNamespaceDeclaration (const char *name, + const Declaration &decl, + clang::DeclContext *decl_ctx); //------------------------------------------------------------------ // Function Types //------------------------------------------------------------------ clang::FunctionDecl * - CreateFunctionDeclaration ( - const char *name, - void * function_Type, - int storage, - bool is_inline); - + CreateFunctionDeclaration (const char *name, + void * function_Type, + int storage, + bool is_inline); + void * - CreateFunctionType ( - void * result_type, - void **args, - unsigned num_args, - bool isVariadic, - unsigned TypeQuals); - + CreateFunctionType (void * result_type, + void **args, + unsigned num_args, + bool isVariadic, + unsigned TypeQuals); + clang::ParmVarDecl * - CreateParmeterDeclaration ( - const char *name, - void * return_type, - int storage); + CreateParmeterDeclaration (const char *name, + void * return_type, + int storage); void - SetFunctionParameters ( - clang::FunctionDecl *function_decl, - clang::ParmVarDecl **params, - unsigned num_params); + SetFunctionParameters (clang::FunctionDecl *function_decl, + clang::ParmVarDecl **params, + unsigned num_params); //------------------------------------------------------------------ // Array Types //------------------------------------------------------------------ void * - CreateArrayType ( - void * element_type, - size_t element_count, - uint32_t bit_stride); + CreateArrayType (void * element_type, + size_t element_count, + uint32_t bit_stride); //------------------------------------------------------------------ // Tag Declarations @@ -323,14 +306,13 @@ CreateEnumerationType (const Declaration &decl, const char *name); bool - AddEnumerationValueToEnumerationType ( - void * enum_qual_type, - void * enumerator_qual_type, - const Declaration &decl, - const char *name, - int64_t enum_value, - uint32_t enum_value_bit_size); - + AddEnumerationValueToEnumerationType (void * enum_qual_type, + void * enumerator_qual_type, + const Declaration &decl, + const char *name, + int64_t enum_value, + uint32_t enum_value_bit_size); + //------------------------------------------------------------------ // Pointers & References //------------------------------------------------------------------ @@ -375,10 +357,9 @@ // Typedefs //------------------------------------------------------------------ void * - CreateTypedefType ( - const char *name, - void * clang_type, - clang::DeclContext *decl_ctx); + CreateTypedefType (const char *name, + void * clang_type, + clang::DeclContext *decl_ctx); //------------------------------------------------------------------ // Type names @@ -390,11 +371,20 @@ IsFloatingPointType (void * clang_type, uint32_t &count, bool &is_complex); //static bool - //ConvertFloatValueToString (clang::ASTContext *ast_context, void * clang_type, const uint8_t* bytes, size_t byte_size, int apint_byte_order, std::string &float_str); - + //ConvertFloatValueToString (clang::ASTContext *ast_context, + // void * clang_type, + // const uint8_t* bytes, + // size_t byte_size, + // int apint_byte_order, + // std::string &float_str); + static size_t - ConvertStringToFloatValue (clang::ASTContext *ast_context, void * clang_type, const char *s, uint8_t *dst, size_t dst_size); - + ConvertStringToFloatValue (clang::ASTContext *ast_context, + void * clang_type, + const char *s, + uint8_t *dst, + size_t dst_size); + protected: //------------------------------------------------------------------ // Classes that inherit from ClangASTContext can see and modify these Modified: lldb/trunk/source/Plugins/Process/MacOSX-User/source/ProcessMacOSX.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/MacOSX-User/source/ProcessMacOSX.cpp?rev=107459&r1=107458&r2=107459&view=diff ============================================================================== --- lldb/trunk/source/Plugins/Process/MacOSX-User/source/ProcessMacOSX.cpp (original) +++ lldb/trunk/source/Plugins/Process/MacOSX-User/source/ProcessMacOSX.cpp Thu Jul 1 20:29:13 2010 @@ -1802,6 +1802,8 @@ if (err.Fail() || log) err.PutToLog(log, "::posix_spawnp ( pid => %i, path = '%s', file_actions = %p, attr = %p, argv = %p, envp = %p )", pid, path, NULL, &attr, argv, envp); } + + ::posix_spawnattr_destroy (&attr); // We have seen some cases where posix_spawnp was returning a valid // looking pid even when an error was returned, so clear it out Modified: lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp?rev=107459&r1=107458&r2=107459&view=diff ============================================================================== --- lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp (original) +++ lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp Thu Jul 1 20:29:13 2010 @@ -1869,6 +1869,9 @@ (char * const*)inferior_envp), eErrorTypePOSIX); + + ::posix_spawnattr_destroy (&attr); + if (file_actions_err.Success()) ::posix_spawn_file_actions_destroy (&file_actions); 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=107459&r1=107458&r2=107459&view=diff ============================================================================== --- lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp (original) +++ lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp Thu Jul 1 20:29:13 2010 @@ -2885,6 +2885,10 @@ { type_list->GetClangASTContext().SetBaseClassesForClassType (clang_type, base_classes.data(), base_classes.size()); } + + // Clang will copy each CXXBaseSpecifier in "base_classes" + // so we have to free them all. + ClangASTContext::DeleteBaseClassSpecifiers (base_classes.data(), base_classes.size()); } type_list->GetClangASTContext().CompleteTagDeclarationDefinition (clang_type); } Modified: lldb/trunk/source/Symbol/ClangASTContext.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/ClangASTContext.cpp?rev=107459&r1=107458&r2=107459&view=diff ============================================================================== --- lldb/trunk/source/Symbol/ClangASTContext.cpp (original) +++ lldb/trunk/source/Symbol/ClangASTContext.cpp Thu Jul 1 20:29:13 2010 @@ -201,38 +201,7 @@ // } } -//---------------------------------------------------------------------- -// ClangASTContext constructor -//---------------------------------------------------------------------- -//ClangASTContext::ClangASTContext(Module *module) : -// m_target_triple(), -// m_ast_context_ap(), -// m_language_options_ap(), -// m_source_manager_ap(), -// m_target_info_ap(), -// m_identifier_table_ap(), -// m_selector_table_ap(), -// m_builtins_ap() -//{ -// if (module) -// { -// ObjectFile * objfile = module->GetObjectFile(); -// if (objfile) -// objfile->GetTargetTriple(m_target_triple); -// } -//} -//ClangASTContext::ClangASTContext(const ConstString& target_triple) : -// m_target_triple(target_triple), -// m_ast_context_ap(), -// m_language_options_ap(), -// m_source_manager_ap(), -// m_target_info_ap(), -// m_identifier_table_ap(), -// m_selector_table_ap(), -// m_builtins_ap() -//{ -//} ClangASTContext::ClangASTContext(const char *target_triple) : m_target_triple(), m_ast_context_ap(), @@ -920,6 +889,16 @@ return NULL; } +void +ClangASTContext::DeleteBaseClassSpecifiers (CXXBaseSpecifier **base_classes, unsigned num_base_classes) +{ + for (unsigned i=0; iSetChildFileDescriptors(master_fd, master_fd, master_fd); } } + + ::posix_spawnattr_destroy (&attr); if (file_actions_valid) { From scallanan at apple.com Thu Jul 1 21:43:42 2010 From: scallanan at apple.com (Sean Callanan) Date: Fri, 02 Jul 2010 02:43:42 -0000 Subject: [Lldb-commits] [lldb] r107460 - in /lldb/trunk: include/lldb/Core/Stream.h source/Core/Stream.cpp Message-ID: <20100702024342.344EF2A6C12C@llvm.org> Author: spyffe Date: Thu Jul 1 21:43:42 2010 New Revision: 107460 URL: http://llvm.org/viewvc/llvm-project?rev=107460&view=rev Log: Added a method to get a stream's byte order. Modified: lldb/trunk/include/lldb/Core/Stream.h lldb/trunk/source/Core/Stream.cpp Modified: lldb/trunk/include/lldb/Core/Stream.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/Stream.h?rev=107460&r1=107459&r2=107460&view=diff ============================================================================== --- lldb/trunk/include/lldb/Core/Stream.h (original) +++ lldb/trunk/include/lldb/Core/Stream.h Thu Jul 1 21:43:42 2010 @@ -436,6 +436,15 @@ //------------------------------------------------------------------ const Flags& GetFlags() const; + + //------------------------------------------------------------------ + //// The byte order accessor. + //// + //// @return + //// The byte order. + //------------------------------------------------------------------ + lldb::ByteOrder + GetByteOrder() const; //------------------------------------------------------------------ /// Get the current indentation level. Modified: lldb/trunk/source/Core/Stream.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/Stream.cpp?rev=107460&r1=107459&r2=107460&view=diff ============================================================================== --- lldb/trunk/source/Core/Stream.cpp (original) +++ lldb/trunk/source/Core/Stream.cpp Thu Jul 1 21:43:42 2010 @@ -461,6 +461,16 @@ return m_flags; } +//------------------------------------------------------------------ +// The byte order get accessor +//------------------------------------------------------------------ + +lldb::ByteOrder +Stream::GetByteOrder() const +{ + return m_byte_order; +} + int Stream::PrintfAsRawHex8 (const char *format, ...) { From gclayton at apple.com Fri Jul 2 13:39:06 2010 From: gclayton at apple.com (Greg Clayton) Date: Fri, 02 Jul 2010 18:39:06 -0000 Subject: [Lldb-commits] [lldb] r107494 - in /lldb/trunk: include/lldb/Core/FileSpec.h llvm.zip scripts/build-llvm.pl source/Expression/ClangExpression.cpp source/Expression/ClangFunction.cpp Message-ID: <20100702183906.5F3A02A6C12C@llvm.org> Author: gclayton Date: Fri Jul 2 13:39:06 2010 New Revision: 107494 URL: http://llvm.org/viewvc/llvm-project?rev=107494&view=rev Log: Updated to llvm/clang from July 2, 2010 at 8:00AM. Modified: lldb/trunk/include/lldb/Core/FileSpec.h lldb/trunk/llvm.zip lldb/trunk/scripts/build-llvm.pl lldb/trunk/source/Expression/ClangExpression.cpp lldb/trunk/source/Expression/ClangFunction.cpp Modified: lldb/trunk/include/lldb/Core/FileSpec.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/FileSpec.h?rev=107494&r1=107493&r2=107494&view=diff ============================================================================== --- lldb/trunk/include/lldb/Core/FileSpec.h (original) +++ lldb/trunk/include/lldb/Core/FileSpec.h Fri Jul 2 13:39:06 2010 @@ -435,7 +435,7 @@ /// Resolves user name and links in \a src_path, and writes the output /// to \a dst_path. Note if the path pointed to by \a src_path does not /// exist, the contents of \a src_path will be copied to \a dst_path - /// unchanged. + /// unchanged. /// /// @param[in] src_path /// Input path to be resolved. Modified: lldb/trunk/llvm.zip URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/llvm.zip?rev=107494&r1=107493&r2=107494&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=107494&r1=107493&r2=107494&view=diff ============================================================================== --- lldb/trunk/scripts/build-llvm.pl (original) +++ lldb/trunk/scripts/build-llvm.pl Fri Jul 2 13:39:06 2010 @@ -25,7 +25,7 @@ our $llvm_configuration = $ENV{LLVM_CONFIGURATION}; -our $llvm_revision = "'{2010-06-13T06:00}'"; +our $llvm_revision = "'{2010-07-02T08: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"; Modified: lldb/trunk/source/Expression/ClangExpression.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/ClangExpression.cpp?rev=107494&r1=107493&r2=107494&view=diff ============================================================================== --- lldb/trunk/source/Expression/ClangExpression.cpp (original) +++ lldb/trunk/source/Expression/ClangExpression.cpp Fri Jul 2 13:39:06 2010 @@ -24,10 +24,11 @@ #include "clang/Basic/FileManager.h" #include "clang/Basic/TargetInfo.h" #include "clang/Basic/Version.h" +#include "clang/Checker/FrontendActions.h" +#include "clang/CodeGen/CodeGenAction.h" #include "clang/CodeGen/ModuleBuilder.h" #include "clang/Driver/CC1Options.h" #include "clang/Driver/OptTable.h" -#include "clang/Frontend/CodeGenAction.h" #include "clang/Frontend/CompilerInstance.h" #include "clang/Frontend/CompilerInvocation.h" #include "clang/Frontend/FrontendActions.h" @@ -37,6 +38,7 @@ #include "clang/Frontend/TextDiagnosticPrinter.h" #include "clang/Frontend/VerifyDiagnosticsClient.h" #include "clang/Lex/Preprocessor.h" +#include "clang/Rewrite/FrontendActions.h" #include "clang/Sema/ParseAST.h" #include "clang/Sema/SemaConsumer.h" #include "llvm/ExecutionEngine/ExecutionEngine.h" Modified: lldb/trunk/source/Expression/ClangFunction.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/ClangFunction.cpp?rev=107494&r1=107493&r2=107494&view=diff ============================================================================== --- lldb/trunk/source/Expression/ClangFunction.cpp (original) +++ lldb/trunk/source/Expression/ClangFunction.cpp Fri Jul 2 13:39:06 2010 @@ -11,15 +11,15 @@ // C Includes // C++ Includes // Other libraries and framework includes -#include "clang/Frontend/CodeGenAction.h" -#include "llvm/ExecutionEngine/ExecutionEngine.h" -#include "clang/Frontend/CompilerInstance.h" #include "clang/AST/ASTContext.h" #include "clang/AST/RecordLayout.h" -#include "llvm/ExecutionEngine/JIT.h" -#include "llvm/Module.h" +#include "clang/CodeGen/CodeGenAction.h" #include "clang/CodeGen/ModuleBuilder.h" +#include "clang/Frontend/CompilerInstance.h" #include "llvm/ADT/StringRef.h" +#include "llvm/ExecutionEngine/ExecutionEngine.h" +#include "llvm/ExecutionEngine/JIT.h" +#include "llvm/Module.h" // Project includes #include "lldb/Expression/ClangFunction.h" From eli.friedman at gmail.com Fri Jul 2 14:15:50 2010 From: eli.friedman at gmail.com (Eli Friedman) Date: Fri, 02 Jul 2010 19:15:50 -0000 Subject: [Lldb-commits] [lldb] r107499 - /lldb/trunk/source/Core/FileSpec.cpp Message-ID: <20100702191550.E59642A6C12C@llvm.org> Author: efriedma Date: Fri Jul 2 14:15:50 2010 New Revision: 107499 URL: http://llvm.org/viewvc/llvm-project?rev=107499&view=rev Log: Add const qualification; fixes error on gcc 4.4. Modified: lldb/trunk/source/Core/FileSpec.cpp Modified: lldb/trunk/source/Core/FileSpec.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/FileSpec.cpp?rev=107499&r1=107498&r2=107499&view=diff ============================================================================== --- lldb/trunk/source/Core/FileSpec.cpp (original) +++ lldb/trunk/source/Core/FileSpec.cpp Fri Jul 2 14:15:50 2010 @@ -82,7 +82,7 @@ return len; } - char *first_slash = ::strchr (src_path, '/'); + const char *first_slash = ::strchr (src_path, '/'); char remainder[PATH_MAX]; if (first_slash == NULL) From eli.friedman at gmail.com Fri Jul 2 14:28:45 2010 From: eli.friedman at gmail.com (Eli Friedman) Date: Fri, 02 Jul 2010 19:28:45 -0000 Subject: [Lldb-commits] [lldb] r107501 - in /lldb/trunk/source/Host/linux: ./ Host.cpp Symbols.cpp TimeValue.cpp Message-ID: <20100702192845.1C9162A6C12C@llvm.org> Author: efriedma Date: Fri Jul 2 14:28:44 2010 New Revision: 107501 URL: http://llvm.org/viewvc/llvm-project?rev=107501&view=rev Log: Add hacky, incomplete Linux host implementation; barely enough to allow compiling lldb. Someone else might try to improve it, though. :) Added: lldb/trunk/source/Host/linux/ lldb/trunk/source/Host/linux/Host.cpp - copied, changed from r105721, lldb/trunk/source/Host/macosx/Host.mm lldb/trunk/source/Host/linux/Symbols.cpp lldb/trunk/source/Host/linux/TimeValue.cpp - copied unchanged from r105814, lldb/trunk/source/Host/macosx/TimeValue.cpp Copied: lldb/trunk/source/Host/linux/Host.cpp (from r105721, lldb/trunk/source/Host/macosx/Host.mm) URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/linux/Host.cpp?p2=lldb/trunk/source/Host/linux/Host.cpp&p1=lldb/trunk/source/Host/macosx/Host.mm&r1=105721&r2=107501&rev=107501&view=diff ============================================================================== --- lldb/trunk/source/Host/macosx/Host.mm (original) +++ lldb/trunk/source/Host/linux/Host.cpp Fri Jul 2 14:28:44 2010 @@ -9,24 +9,16 @@ #include #include -#include -#include #include #include #include #include +#include +#include #include #include -#include - -#include - -#include "CFCBundle.h" -#include "CFCReleaser.h" -#include "CFCString.h" - #include "lldb/Host/Host.h" #include "lldb/Core/ArchSpec.h" #include "lldb/Core/ConstString.h" @@ -82,7 +74,7 @@ lldb::pid_t Host::GetCurrentThreadID() { - return ::mach_thread_self(); + return pthread_self(); } @@ -90,6 +82,7 @@ Host::GetArchitecture () { static ArchSpec g_host_arch; +#if 0 if (!g_host_arch.IsValid()) { uint32_t cputype, cpusubtype; @@ -114,6 +107,9 @@ } } } +#else + g_host_arch.SetArch(7u, 144u); +#endif return g_host_arch; } @@ -123,10 +119,14 @@ static ConstString g_vendor; if (!g_vendor) { +#if 0 char ostype[64]; size_t len = sizeof(ostype); if (::sysctlbyname("kern.ostype", &ostype, &len, NULL, 0) == 0) g_vendor.SetCString (ostype); +#else + g_vendor.SetCString("gnu"); +#endif } return g_vendor; } @@ -134,7 +134,7 @@ const ConstString & Host::GetOSString() { - static ConstString g_os_string("apple"); + static ConstString g_os_string("linux"); return g_os_string; } @@ -160,60 +160,16 @@ return g_host_triple; } -class MacOSXDarwinThread -{ -public: - MacOSXDarwinThread(const char *thread_name) : - m_pool (nil) - { - // Register our thread with the collector if garbage collection is enabled. - if (objc_collectingEnabled()) - { -#if MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_5 - // On Leopard and earlier there is no way objc_registerThreadWithCollector - // function, so we do it manually. - auto_zone_register_thread(auto_zone()); -#else - // On SnowLoepard and later we just call the thread registration function. - objc_registerThreadWithCollector(); -#endif - } - else - { - m_pool = [[NSAutoreleasePool alloc] init]; - } - - - Host::SetThreadName (LLDB_INVALID_PROCESS_ID, LLDB_INVALID_THREAD_ID, thread_name); - } - - ~MacOSXDarwinThread() - { - if (m_pool) - [m_pool release]; - } - - static void PThreadDestructor (void *v) - { - delete (MacOSXDarwinThread*)v; - } - -protected: - NSAutoreleasePool * m_pool; -private: - DISALLOW_COPY_AND_ASSIGN (MacOSXDarwinThread); -}; - static pthread_once_t g_thread_create_once = PTHREAD_ONCE_INIT; static pthread_key_t g_thread_create_key = 0; static void InitThreadCreated() { - ::pthread_key_create (&g_thread_create_key, MacOSXDarwinThread::PThreadDestructor); + ::pthread_key_create (&g_thread_create_key, 0); } -typedef struct HostThreadCreateInfo +struct HostThreadCreateInfo { std::string thread_name; thread_func_t thread_fptr; @@ -305,7 +261,7 @@ ::pthread_once (&g_thread_create_once, InitThreadCreated); if (g_thread_create_key) { - ::pthread_setspecific (g_thread_create_key, new MacOSXDarwinThread(thread_name)); + //::pthread_setspecific (g_thread_create_key, new MacOSXDarwinThread(thread_name)); } } @@ -446,6 +402,7 @@ static FileSpec g_program_filepsec; if (!g_program_filepsec) { +#if 0 std::string program_fullpath; program_fullpath.resize (PATH_MAX); // If DST is NULL, then return the number of bytes needed. @@ -461,6 +418,7 @@ } if (err == 0) g_program_filepsec.SetFile(program_fullpath.data()); +#endif } return g_program_filepsec; } @@ -483,6 +441,7 @@ bool Host::ResolveExecutableInBundle (FileSpec *file) { +#if 0 if (file->GetFileType () == FileSpec::eFileTypeDirectory) { char path[PATH_MAX]; @@ -500,10 +459,11 @@ } } } +#endif return false; } -typedef struct MonitorInfo +struct MonitorInfo { int handle; pthread_t thread; @@ -554,7 +514,7 @@ Mutex::Locker locker(&g_monitor_map_mutex); if (!g_monitor_thread) { - pid_t wait_pid = -1; + ::pid_t wait_pid = -1; g_monitor_thread = ThreadCreate ("", MonitorChildProcessThreadFunction, &wait_pid, @@ -640,7 +600,7 @@ if (log) log->Printf ("%s (arg = %p) thread starting...", function, arg); - const pid_t wait_pid = -1;//*((pid_t*)arg); + const ::pid_t wait_pid = -1;//*((pid_t*)arg); int status = -1; const int options = 0; struct rusage *rusage = NULL; @@ -722,7 +682,7 @@ } else { - status_cstr = "(???)"; + status_cstr = "(???"")"; } if (log) Added: lldb/trunk/source/Host/linux/Symbols.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/linux/Symbols.cpp?rev=107501&view=auto ============================================================================== --- lldb/trunk/source/Host/linux/Symbols.cpp (added) +++ lldb/trunk/source/Host/linux/Symbols.cpp Fri Jul 2 14:28:44 2010 @@ -0,0 +1,27 @@ +//===-- Symbols.cpp ---------------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "lldb/Host/Symbols.h" + +using namespace lldb; +using namespace lldb_private; + +FileSpec +Symbols::LocateExecutableObjectFile (const FileSpec *exec_fspec, const ArchSpec* arch, const UUID *uuid) +{ + // FIXME: Proper impliementation? + return FileSpec(); +} + +FileSpec +Symbols::LocateExecutableSymbolFile (const FileSpec *exec_fspec, const ArchSpec* arch, const UUID *uuid) +{ + // FIXME: Proper impliementation? + return FileSpec(); +} From eli.friedman at gmail.com Fri Jul 2 14:38:10 2010 From: eli.friedman at gmail.com (Eli Friedman) Date: Fri, 02 Jul 2010 19:38:10 -0000 Subject: [Lldb-commits] [lldb] r107502 - /lldb/trunk/source/Host/linux/Host.cpp Message-ID: <20100702193810.D2F042A6C12C@llvm.org> Author: efriedma Date: Fri Jul 2 14:38:10 2010 New Revision: 107502 URL: http://llvm.org/viewvc/llvm-project?rev=107502&view=rev Log: Implement GetProgramFileSpec(). Modified: lldb/trunk/source/Host/linux/Host.cpp Modified: lldb/trunk/source/Host/linux/Host.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/linux/Host.cpp?rev=107502&r1=107501&r2=107502&view=diff ============================================================================== --- lldb/trunk/source/Host/linux/Host.cpp (original) +++ lldb/trunk/source/Host/linux/Host.cpp Fri Jul 2 14:38:10 2010 @@ -402,23 +402,10 @@ static FileSpec g_program_filepsec; if (!g_program_filepsec) { -#if 0 - std::string program_fullpath; - program_fullpath.resize (PATH_MAX); - // If DST is NULL, then return the number of bytes needed. - uint32_t len = program_fullpath.size(); - int err = _NSGetExecutablePath ((char *)program_fullpath.data(), &len); - if (err < 0) - { - // The path didn't fit in the buffer provided, increase its size - // and try again - program_fullpath.resize(len); - len = program_fullpath.size(); - err = _NSGetExecutablePath ((char *)program_fullpath.data(), &len); - } - if (err == 0) - g_program_filepsec.SetFile(program_fullpath.data()); -#endif + char exe_path[PATH_MAX]; + ssize_t len = readlink("/proc/self/exe", exe_path, sizeof(exe_path)); + if (len >= 0) + g_program_filepsec = FileSpec(exe_path); } return g_program_filepsec; } From johnny.chen at apple.com Fri Jul 2 15:35:23 2010 From: johnny.chen at apple.com (Johnny Chen) Date: Fri, 02 Jul 2010 20:35:23 -0000 Subject: [Lldb-commits] [lldb] r107508 - /lldb/trunk/test/dotest.py Message-ID: <20100702203523.961FE2A6C12C@llvm.org> Author: johnny Date: Fri Jul 2 15:35:23 2010 New Revision: 107508 URL: http://llvm.org/viewvc/llvm-project?rev=107508&view=rev Log: Fixed logic error; checking return status and raising exception should only be done if the environment variable LLDB_LOG is defined. Modified: lldb/trunk/test/dotest.py Modified: lldb/trunk/test/dotest.py URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/dotest.py?rev=107508&r1=107507&r2=107508&view=diff ============================================================================== --- lldb/trunk/test/dotest.py (original) +++ lldb/trunk/test/dotest.py Fri Jul 2 15:35:23 2010 @@ -151,9 +151,8 @@ if ("LLDB_LOG" in os.environ): ci.HandleCommand( "log enable -f " + os.environ["LLDB_LOG"] + " lldb default", res) - pass -if not res.Succeeded(): - raise Exception('log enable failed (check your LLDB_LOG env variable...') + if not res.Succeeded(): + raise Exception('log enable failed (check your LLDB_LOG env variable...') unittest.TextTestRunner(verbosity=verbose).run(suite) From scallanan at apple.com Fri Jul 2 16:09:36 2010 From: scallanan at apple.com (Sean Callanan) Date: Fri, 02 Jul 2010 21:09:36 -0000 Subject: [Lldb-commits] [lldb] r107515 - in /lldb/trunk: include/lldb/Expression/IRToDWARF.h lldb.xcodeproj/project.pbxproj source/Expression/ClangExpression.cpp source/Expression/IRToDWARF.cpp Message-ID: <20100702210936.67E842A6C12F@llvm.org> Author: spyffe Date: Fri Jul 2 16:09:36 2010 New Revision: 107515 URL: http://llvm.org/viewvc/llvm-project?rev=107515&view=rev Log: Added the skeleton of a transformation pass to convert IR to DWARF. So far, this pass only performs a depth-first traversal of the IR, logging each basic block as it finds it. Added: lldb/trunk/include/lldb/Expression/IRToDWARF.h lldb/trunk/source/Expression/IRToDWARF.cpp Modified: lldb/trunk/lldb.xcodeproj/project.pbxproj lldb/trunk/source/Expression/ClangExpression.cpp Added: lldb/trunk/include/lldb/Expression/IRToDWARF.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Expression/IRToDWARF.h?rev=107515&view=auto ============================================================================== --- lldb/trunk/include/lldb/Expression/IRToDWARF.h (added) +++ lldb/trunk/include/lldb/Expression/IRToDWARF.h Fri Jul 2 16:09:36 2010 @@ -0,0 +1,49 @@ +//===-- IRToDWARF.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_IRToDWARF_h_ +#define liblldb_IRToDWARF_h_ + +#include "llvm/Pass.h" +#include "llvm/PassManager.h" + +namespace llvm { + class BasicBlock; + class Module; +} + +namespace lldb_private { + class ClangExpressionVariableList; + class ClangExpressionDeclMap; + class StreamString; +} + +class Relocator; + +class IRToDWARF : public llvm::ModulePass +{ +public: + IRToDWARF(const void *pid, + lldb_private::ClangExpressionVariableList &variable_list, + lldb_private::ClangExpressionDeclMap *decl_map, + lldb_private::StreamString &strm); + ~IRToDWARF(); + 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, Relocator &Relocator); + + lldb_private::ClangExpressionVariableList &m_variable_list; + lldb_private::ClangExpressionDeclMap *m_decl_map; + lldb_private::StreamString &m_strm; +}; + +#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=107515&r1=107514&r2=107515&view=diff ============================================================================== --- lldb/trunk/lldb.xcodeproj/project.pbxproj (original) +++ lldb/trunk/lldb.xcodeproj/project.pbxproj Fri Jul 2 16:09:36 2010 @@ -332,6 +332,8 @@ 49A8A3A411D568BF00AD3B68 /* ClangResultSynthesizer.h in Headers */ = {isa = PBXBuildFile; fileRef = 49A8A3A311D568BF00AD3B68 /* ClangResultSynthesizer.h */; }; 49D7072711B5AD03001AD875 /* ClangASTSource.h in Headers */ = {isa = PBXBuildFile; fileRef = 49D7072611B5AD03001AD875 /* ClangASTSource.h */; }; 49D7072911B5AD11001AD875 /* ClangASTSource.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 49D7072811B5AD11001AD875 /* ClangASTSource.cpp */; settings = {COMPILER_FLAGS = "-fno-rtti"; }; }; + 49DA743011DE6A5A006AEF7E /* IRToDWARF.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 49DA742F11DE6A5A006AEF7E /* IRToDWARF.cpp */; }; + 49DA743511DE6BB2006AEF7E /* IRToDWARF.h in Headers */ = {isa = PBXBuildFile; fileRef = 49DA743411DE6BB2006AEF7E /* IRToDWARF.h */; }; 49F1A74611B3388F003ED505 /* ClangExpressionDeclMap.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 49F1A74511B3388F003ED505 /* ClangExpressionDeclMap.cpp */; }; 49F1A74A11B338AE003ED505 /* ClangExpressionDeclMap.h in Headers */ = {isa = PBXBuildFile; fileRef = 49F1A74911B338AE003ED505 /* ClangExpressionDeclMap.h */; }; 4C08CDE811C81EF8001610A8 /* ThreadSpec.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4C08CDE711C81EF8001610A8 /* ThreadSpec.cpp */; }; @@ -904,6 +906,8 @@ 49BF48E011ADF37D008863BD /* ObjCObjectPrinter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ObjCObjectPrinter.h; path = include/lldb/Target/ObjCObjectPrinter.h; sourceTree = ""; }; 49D7072611B5AD03001AD875 /* ClangASTSource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ClangASTSource.h; path = include/lldb/Expression/ClangASTSource.h; sourceTree = ""; }; 49D7072811B5AD11001AD875 /* ClangASTSource.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ClangASTSource.cpp; path = source/Expression/ClangASTSource.cpp; sourceTree = ""; }; + 49DA742F11DE6A5A006AEF7E /* IRToDWARF.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = IRToDWARF.cpp; path = source/Expression/IRToDWARF.cpp; sourceTree = ""; }; + 49DA743411DE6BB2006AEF7E /* IRToDWARF.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = IRToDWARF.h; path = include/lldb/Expression/IRToDWARF.h; sourceTree = ""; }; 49EC3E98118F90AC00B1265E /* ThreadPlanCallFunction.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ThreadPlanCallFunction.cpp; path = source/Target/ThreadPlanCallFunction.cpp; sourceTree = ""; }; 49EC3E9C118F90D400B1265E /* ThreadPlanCallFunction.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ThreadPlanCallFunction.h; path = include/lldb/Target/ThreadPlanCallFunction.h; sourceTree = ""; }; 49F1A74511B3388F003ED505 /* ClangExpressionDeclMap.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ClangExpressionDeclMap.cpp; path = source/Expression/ClangExpressionDeclMap.cpp; sourceTree = ""; }; @@ -1832,6 +1836,8 @@ 26BC7ED710F1B86700F91463 /* ClangStmtVisitor.cpp */, 26BC7DC310F1B79500F91463 /* DWARFExpression.h */, 26BC7ED810F1B86700F91463 /* DWARFExpression.cpp */, + 49DA743411DE6BB2006AEF7E /* IRToDWARF.h */, + 49DA742F11DE6A5A006AEF7E /* IRToDWARF.cpp */, 4C98D3E1118FB98F00E575D0 /* RecordingMemoryManager.h */, 4C98D3DB118FB96F00E575D0 /* RecordingMemoryManager.cpp */, ); @@ -2184,6 +2190,7 @@ 261B5A5511C3F2AD00AABD0A /* SharingPtr.h in Headers */, 4C08CDEC11C81F1E001610A8 /* ThreadSpec.h in Headers */, 49A8A3A411D568BF00AD3B68 /* ClangResultSynthesizer.h in Headers */, + 49DA743511DE6BB2006AEF7E /* IRToDWARF.h in Headers */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -2633,6 +2640,7 @@ 261B5A5411C3F2AD00AABD0A /* SharingPtr.cpp in Sources */, 4C08CDE811C81EF8001610A8 /* ThreadSpec.cpp in Sources */, 49A8A3A011D568A300AD3B68 /* ClangResultSynthesizer.cpp in Sources */, + 49DA743011DE6A5A006AEF7E /* IRToDWARF.cpp in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; Modified: lldb/trunk/source/Expression/ClangExpression.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/ClangExpression.cpp?rev=107515&r1=107514&r2=107515&view=diff ============================================================================== --- lldb/trunk/source/Expression/ClangExpression.cpp (original) +++ lldb/trunk/source/Expression/ClangExpression.cpp Fri Jul 2 16:09:36 2010 @@ -58,6 +58,7 @@ #include "lldb/Expression/ClangASTSource.h" #include "lldb/Expression/ClangResultSynthesizer.h" #include "lldb/Expression/ClangStmtVisitor.h" +#include "lldb/Expression/IRToDWARF.h" #include "lldb/Symbol/ClangASTContext.h" #include "lldb/Expression/RecordingMemoryManager.h" #include "lldb/Target/ExecutionContext.h" @@ -473,7 +474,7 @@ } unsigned -ClangExpression::ConvertIRToDWARF (ClangExpressionVariableList &excpr_local_variable_list, +ClangExpression::ConvertIRToDWARF (ClangExpressionVariableList &expr_local_variable_list, StreamString &dwarf_opcode_strm) { Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS); @@ -488,46 +489,9 @@ return 1; } - llvm::Function* function = module->getFunction(StringRef("___clang_expr")); + IRToDWARF ir_to_dwarf("IR to DWARF", expr_local_variable_list, m_decl_map, dwarf_opcode_strm); - if (!function) - { - if (log) - log->Printf("Couldn't find ___clang_expr() in the module"); - - return 1; - } - - if (log) - log->Printf("IR for %s:", function->getName().str().c_str()); - - llvm::Function::iterator bbi; - - for (bbi = function->begin(); - bbi != function->end(); - ++bbi) - { - llvm::BasicBlock &bb = *bbi; - - llvm::BasicBlock::iterator ii; - - for (ii = bb.begin(); - ii != bb.end(); - ++ii) - { - llvm::Instruction &inst = *ii; - - std::string s; - llvm::raw_string_ostream os(s); - - inst.print(os); - - if (log) - log->Printf(" %s", s.c_str()); - } - } - - return 0; + return ir_to_dwarf.runOnModule(*module); } bool Added: lldb/trunk/source/Expression/IRToDWARF.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/IRToDWARF.cpp?rev=107515&view=auto ============================================================================== --- lldb/trunk/source/Expression/IRToDWARF.cpp (added) +++ lldb/trunk/source/Expression/IRToDWARF.cpp Fri Jul 2 16:09:36 2010 @@ -0,0 +1,222 @@ +//===-- IRToDWARF.cpp ---------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "lldb/Expression/IRToDWARF.h" + +#include "llvm/Support/raw_ostream.h" +#include "llvm/InstrTypes.h" +#include "llvm/Module.h" + +#include "lldb/Core/dwarf.h" +#include "lldb/Core/Log.h" +#include "lldb/Core/Scalar.h" +#include "lldb/Core/StreamString.h" +#include "lldb/Expression/ClangExpressionDeclMap.h" +#include "lldb/Expression/ClangExpressionVariable.h" + +#include + +using namespace llvm; + +IRToDWARF::IRToDWARF(const void *pid, + lldb_private::ClangExpressionVariableList &variable_list, + lldb_private::ClangExpressionDeclMap *decl_map, + lldb_private::StreamString &strm) : + ModulePass(pid), + m_variable_list(variable_list), + m_decl_map(decl_map), + m_strm(strm) +{ +} + +IRToDWARF::~IRToDWARF() +{ +} + +class Relocator +{ +public: + Relocator() + { + } + + ~Relocator() + { + } + + void MarkBasicBlock(BasicBlock *bb, uint16_t offset) + { + m_basic_blocks[bb] = offset; + } + + bool BasicBlockIsMarked(BasicBlock *bb) + { + return m_basic_blocks.find(bb) != m_basic_blocks.end(); + } + + void MarkRelocation(BasicBlock *bb, uint16_t offset) + { + m_relocations[offset] = bb; + } + + bool ResolveRelocations(lldb_private::StreamString &strm) + { + std::map::const_iterator iter; + + lldb_private::StreamString swapper(0, 32, strm.GetByteOrder()); + + // This array must be delete [] d at every exit + size_t temporary_bufsize = strm.GetSize(); + uint8_t *temporary_buffer(new uint8_t[temporary_bufsize]); + + memcpy(temporary_buffer, strm.GetData(), temporary_bufsize); + + for (iter = m_relocations.begin(); + iter != m_relocations.end(); + ++iter) + { + const std::pair &pair = *iter; + + uint16_t off = pair.first; + BasicBlock *bb = pair.second; + + if (m_basic_blocks.find(bb) == m_basic_blocks.end()) + { + delete [] temporary_buffer; + return false; + } + + uint16_t target_off = m_basic_blocks[bb]; + + int16_t relative = (int16_t)target_off - (int16_t)off; + + swapper.Clear(); + swapper << target_off; + + memcpy(temporary_buffer + off, swapper.GetData(), sizeof(uint16_t)); + } + + strm.Clear(); + strm.Write(temporary_buffer, temporary_bufsize); + + delete [] temporary_buffer; + return true; + } +private: + std::map m_basic_blocks; + std::map m_relocations; +}; + +bool +IRToDWARF::runOnBasicBlock(BasicBlock &BB, Relocator &R) +{ + lldb_private::Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS); + + /////////////////////////////////////// + // Mark the current block as visited + // + + size_t stream_size = m_strm.GetSize(); + + if (stream_size > 0xffff) + return false; + + uint16_t offset = stream_size & 0xffff; + + R.MarkBasicBlock(&BB, offset); + + //////////////////////////////////////////////// + // Translate the current basic block to DWARF + // + + if (log) + { + log->Printf("Translating a basic block:"); + + llvm::BasicBlock::iterator ii; + + 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()); + } + } + + ///////////////////////////////////////////////// + // Visit all successors we haven't visited yet + // + + TerminatorInst *arnold = BB.getTerminator(); + + if (!arnold) + return false; + + unsigned successor_index; + unsigned num_successors = arnold->getNumSuccessors(); + + for (successor_index = 0; + successor_index < num_successors; + ++successor_index) + { + BasicBlock *successor = arnold->getSuccessor(successor_index); + + if (!R.BasicBlockIsMarked(successor)) + { + if (!runOnBasicBlock(*successor, R)) + return false; + } + } + + return true; +} + +bool +IRToDWARF::runOnModule(Module &M) +{ + lldb_private::Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS); + + llvm::Function* function = M.getFunction(StringRef("___clang_expr")); + + if (!function) + { + if (log) + log->Printf("Couldn't find ___clang_expr() in the module"); + + return 1; + } + + Relocator relocator; + + llvm::BasicBlock ¤tBB = function->getEntryBlock(); + + runOnBasicBlock(currentBB, relocator); + + return relocator.ResolveRelocations(m_strm); +} + +void +IRToDWARF::assignPassManager(PMStack &PMS, + PassManagerType T) +{ +} + +PassManagerType +IRToDWARF::getPotentialPassManagerType() const +{ + return PMT_ModulePassManager; +} From scallanan at apple.com Fri Jul 2 16:28:36 2010 From: scallanan at apple.com (Sean Callanan) Date: Fri, 02 Jul 2010 21:28:36 -0000 Subject: [Lldb-commits] [lldb] r107518 - /lldb/trunk/source/Expression/IRToDWARF.cpp Message-ID: <20100702212836.0B57E2A6C12C@llvm.org> Author: spyffe Date: Fri Jul 2 16:28:35 2010 New Revision: 107518 URL: http://llvm.org/viewvc/llvm-project?rev=107518&view=rev Log: Small fixes to the DWARF relocator. Modified: lldb/trunk/source/Expression/IRToDWARF.cpp Modified: lldb/trunk/source/Expression/IRToDWARF.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/IRToDWARF.cpp?rev=107518&r1=107517&r2=107518&view=diff ============================================================================== --- lldb/trunk/source/Expression/IRToDWARF.cpp (original) +++ lldb/trunk/source/Expression/IRToDWARF.cpp Fri Jul 2 16:28:35 2010 @@ -97,9 +97,13 @@ int16_t relative = (int16_t)target_off - (int16_t)off; swapper.Clear(); - swapper << target_off; + swapper << relative; - memcpy(temporary_buffer + off, swapper.GetData(), sizeof(uint16_t)); + // off is intended to be the offset of the branch opcode (which is + // what the relative location is added to) so + // (temporary_buffer + off + 1) skips the opcode and writes to the + // relative location + memcpy(temporary_buffer + off + 1, swapper.GetData(), sizeof(uint16_t)); } strm.Clear(); From johnny.chen at apple.com Fri Jul 2 17:04:42 2010 From: johnny.chen at apple.com (Johnny Chen) Date: Fri, 02 Jul 2010 22:04:42 -0000 Subject: [Lldb-commits] [lldb] r107522 - /lldb/trunk/test/global_variables/TestGlobalVariables.py Message-ID: <20100702220442.A759C2A6C12C@llvm.org> Author: johnny Date: Fri Jul 2 17:04:42 2010 New Revision: 107522 URL: http://llvm.org/viewvc/llvm-project?rev=107522&view=rev Log: Add a test to show global variables and to verify that they do display as having global scopes. Added: lldb/trunk/test/global_variables/TestGlobalVariables.py Added: lldb/trunk/test/global_variables/TestGlobalVariables.py URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/global_variables/TestGlobalVariables.py?rev=107522&view=auto ============================================================================== --- lldb/trunk/test/global_variables/TestGlobalVariables.py (added) +++ lldb/trunk/test/global_variables/TestGlobalVariables.py Fri Jul 2 17:04:42 2010 @@ -0,0 +1,76 @@ +"""Show global variables and check that they do indeed have global scopes.""" + +import os, time +import lldb +import unittest + +main = False + +class TestClassTypes(unittest.TestCase): + + def setUp(self): + global main + + # Save old working directory. + self.oldcwd = os.getcwd() + # Change current working directory if ${LLDB_TEST} is defined. + if ("LLDB_TEST" in os.environ): + os.chdir(os.path.join(os.environ["LLDB_TEST"], "global_variables")); + self.dbg = lldb.SBDebugger.Create() if main else lldb.DBG + if not self.dbg.IsValid(): + raise Exception('Invalid debugger instance') + self.dbg.SetAsync(False) + self.ci = self.dbg.GetCommandInterpreter() + if not self.ci: + raise Exception('Could not get the command interpreter') + + def tearDown(self): + # Restore old working directory. + os.chdir(self.oldcwd) + del self.dbg + + def test_global_variables(self): + """Test 'variable list -s -a' which omits args and shows scopes.""" + res = lldb.SBCommandReturnObject() + exe = os.path.join(os.getcwd(), "a.out") + self.ci.HandleCommand("file " + exe, res) + self.assertTrue(res.Succeeded()) + + # Break inside the main. + self.ci.HandleCommand("breakpoint set -f main.c -l 20", res) + self.assertTrue(res.Succeeded()) + self.assertTrue(res.GetOutput().startswith( + "Breakpoint created: 1: file ='main.c', line = 20, locations = 1")) + + self.ci.HandleCommand("run", res) + time.sleep(0.1) + self.assertTrue(res.Succeeded()) + + # The stop reason of the thread should be breakpoint. + self.ci.HandleCommand("thread list", res) + print "thread list ->", res.GetOutput() + self.assertTrue(res.Succeeded()) + self.assertTrue(res.GetOutput().find('state is Stopped') and + res.GetOutput().find('stop reason = breakpoint')) + + # The breakpoint should have a hit count of 1. + self.ci.HandleCommand("breakpoint list", res) + self.assertTrue(res.Succeeded()) + self.assertTrue(res.GetOutput().find(' resolved, hit count = 1')) + + # Check that GLOBAL scopes are indicated for the variables. + self.ci.HandleCommand("variable list -s -a", res); + self.assertTrue(res.Succeeded()) + self.assertTrue(res.GetOutput().find('GLOBAL: g_file_static_cstr') and + res.GetOutput().find('GLOBAL: g_file_global_int') and + res.GetOutput().find('GLOBAL: g_file_global_cstr')) + + self.ci.HandleCommand("continue", res) + self.assertTrue(res.Succeeded()) + + +if __name__ == '__main__': + lldb.SBDebugger.Initialize() + main = True + unittest.main() + lldb.SBDebugger.Terminate() From johnny.chen at apple.com Fri Jul 2 17:12:25 2010 From: johnny.chen at apple.com (Johnny Chen) Date: Fri, 02 Jul 2010 22:12:25 -0000 Subject: [Lldb-commits] [lldb] r107525 - /lldb/trunk/test/global_variables/TestGlobalVariables.py Message-ID: <20100702221225.C78742A6C12C@llvm.org> Author: johnny Date: Fri Jul 2 17:12:25 2010 New Revision: 107525 URL: http://llvm.org/viewvc/llvm-project?rev=107525&view=rev Log: Also verified the values of global variables. Modified: lldb/trunk/test/global_variables/TestGlobalVariables.py Modified: lldb/trunk/test/global_variables/TestGlobalVariables.py URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/global_variables/TestGlobalVariables.py?rev=107525&r1=107524&r2=107525&view=diff ============================================================================== --- lldb/trunk/test/global_variables/TestGlobalVariables.py (original) +++ lldb/trunk/test/global_variables/TestGlobalVariables.py Fri Jul 2 17:12:25 2010 @@ -61,9 +61,13 @@ # Check that GLOBAL scopes are indicated for the variables. self.ci.HandleCommand("variable list -s -a", res); self.assertTrue(res.Succeeded()) - self.assertTrue(res.GetOutput().find('GLOBAL: g_file_static_cstr') and - res.GetOutput().find('GLOBAL: g_file_global_int') and - res.GetOutput().find('GLOBAL: g_file_global_cstr')) + output = res.GetOutput() + self.assertTrue(output.find('GLOBAL: g_file_static_cstr') and + output.find('g_file_static_cstr') and + output.find('GLOBAL: g_file_global_int') and + output.find('(int) 42') and + output.find('GLOBAL: g_file_global_cstr') and + output.find('g_file_global_cstr')) self.ci.HandleCommand("continue", res) self.assertTrue(res.Succeeded()) From scallanan at apple.com Fri Jul 2 17:22:28 2010 From: scallanan at apple.com (Sean Callanan) Date: Fri, 02 Jul 2010 22:22:28 -0000 Subject: [Lldb-commits] [lldb] r107528 - in /lldb/trunk/source/Expression: ClangExpression.cpp IRToDWARF.cpp Message-ID: <20100702222228.453322A6C12C@llvm.org> Author: spyffe Date: Fri Jul 2 17:22:28 2010 New Revision: 107528 URL: http://llvm.org/viewvc/llvm-project?rev=107528&view=rev Log: Fixes to improve logging (by printing basic block labels) and produce cleaner IR (by removing the thread-safe statics guards) Modified: lldb/trunk/source/Expression/ClangExpression.cpp lldb/trunk/source/Expression/IRToDWARF.cpp Modified: lldb/trunk/source/Expression/ClangExpression.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/ClangExpression.cpp?rev=107528&r1=107527&r2=107528&view=diff ============================================================================== --- lldb/trunk/source/Expression/ClangExpression.cpp (original) +++ lldb/trunk/source/Expression/ClangExpression.cpp Fri Jul 2 17:22:28 2010 @@ -236,6 +236,7 @@ // Our hook into Clang's lookup mechanism only works in C++. m_clang_ap->getLangOpts().CPlusPlus = true; m_clang_ap->getLangOpts().ObjC1 = true; + m_clang_ap->getLangOpts().ThreadsafeStatics = false; // Disable some warnings. m_clang_ap->getDiagnosticOpts().Warnings.push_back("no-unused-value"); Modified: lldb/trunk/source/Expression/IRToDWARF.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/IRToDWARF.cpp?rev=107528&r1=107527&r2=107528&view=diff ============================================================================== --- lldb/trunk/source/Expression/IRToDWARF.cpp (original) +++ lldb/trunk/source/Expression/IRToDWARF.cpp Fri Jul 2 17:22:28 2010 @@ -1,4 +1,4 @@ -//===-- IRToDWARF.cpp ---------------------------------------*- C++ -*-===// +//===-- IRToDWARF.cpp -------------------------------------------*- C++ -*-===// // // The LLVM Compiler Infrastructure // @@ -141,7 +141,8 @@ if (log) { - log->Printf("Translating a basic block:"); + log->Printf("Translating basic block %s:", + BB.hasName() ? BB.getNameStr().c_str() : "[anonymous]"); llvm::BasicBlock::iterator ii; From gclayton at apple.com Fri Jul 2 18:23:14 2010 From: gclayton at apple.com (Greg Clayton) Date: Fri, 02 Jul 2010 23:23:14 -0000 Subject: [Lldb-commits] [lldb] r107539 - in /lldb/trunk/source/Plugins/Process/Utility/libunwind/src: AssemblyParser.hpp RemoteProcInfo.hpp UnwindCursor.hpp libuwind.cxx Message-ID: <20100702232314.E92C42A6C12C@llvm.org> Author: gclayton Date: Fri Jul 2 18:23:14 2010 New Revision: 107539 URL: http://llvm.org/viewvc/llvm-project?rev=107539&view=rev Log: Plugged 4 more leaks in the libunwind code. One leaks is still left in as it is quite gnarly code and there is no good way to clean it up. I will have Jason look at a fix for this. Modified: lldb/trunk/source/Plugins/Process/Utility/libunwind/src/AssemblyParser.hpp lldb/trunk/source/Plugins/Process/Utility/libunwind/src/RemoteProcInfo.hpp lldb/trunk/source/Plugins/Process/Utility/libunwind/src/UnwindCursor.hpp lldb/trunk/source/Plugins/Process/Utility/libunwind/src/libuwind.cxx Modified: lldb/trunk/source/Plugins/Process/Utility/libunwind/src/AssemblyParser.hpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Utility/libunwind/src/AssemblyParser.hpp?rev=107539&r1=107538&r2=107539&view=diff ============================================================================== --- lldb/trunk/source/Plugins/Process/Utility/libunwind/src/AssemblyParser.hpp (original) +++ lldb/trunk/source/Plugins/Process/Utility/libunwind/src/AssemblyParser.hpp Fri Jul 2 18:23:14 2010 @@ -44,6 +44,8 @@ class AssemblyParse_x86 { public: + enum { kMaxInstructionByteSize = 32 }; + AssemblyParse_x86 (RemoteProcInfo& procinfo, unw_accessors_t *acc, unw_addr_space_t as, void *arg) : fArg(arg), fAccessors(acc), fAs(as), fRemoteProcInfo(procinfo) { fRegisterMap = fRemoteProcInfo.getRegisterMap(); if (fRemoteProcInfo.getTargetArch() == UNW_TARGET_X86_64) { @@ -76,7 +78,7 @@ private: void *fArg; - uint8_t* fCurInsnByteBuf; + uint8_t fCurInsnByteBuf[kMaxInstructionByteSize]; int fCurInsnSize; RemoteProcInfo& fRemoteProcInfo; RemoteRegisterMap *fRegisterMap; @@ -285,7 +287,7 @@ /* An error parsing the instruction; stop scanning. */ break; } - fCurInsnByteBuf = (uint8_t *) malloc (fCurInsnSize); + assert (fCurInsnSize <= kMaxInstructionByteSize); if (fRemoteProcInfo.getBytes (cur_addr, fCurInsnSize, fCurInsnByteBuf, fArg) == 0) return false; next_addr = cur_addr + fCurInsnSize; Modified: lldb/trunk/source/Plugins/Process/Utility/libunwind/src/RemoteProcInfo.hpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Utility/libunwind/src/RemoteProcInfo.hpp?rev=107539&r1=107538&r2=107539&view=diff ============================================================================== --- lldb/trunk/source/Plugins/Process/Utility/libunwind/src/RemoteProcInfo.hpp (original) +++ lldb/trunk/source/Plugins/Process/Utility/libunwind/src/RemoteProcInfo.hpp Fri Jul 2 18:23:14 2010 @@ -173,7 +173,7 @@ void addImage (uint64_t mh, uint64_t text_start, uint64_t text_end, uint64_t eh_frame, uint64_t eh_frame_len, uint64_t compact_unwind_start, uint64_t compact_unwind_len); bool addProfile (RemoteProcInfo* procinfo, unw_accessors_t *acc, unw_addr_space_t as, uint64_t start, uint64_t end, void *arg); RemoteUnwindProfile* findProfileByTextAddr (uint64_t pc); - void addMemBlob (RemoteMemoryBlob *blob); + bool addMemBlob (RemoteMemoryBlob *blob); uint8_t *getMemBlobMemory (uint64_t addr, int len); private: RemoteImages(); @@ -312,14 +312,25 @@ // as this is used today, the only duplication will be with the same // start address. -void RemoteImages::addMemBlob (RemoteMemoryBlob *blob) { - std::vector::iterator i; - for (i = fMemBlobs.begin(); i != fMemBlobs.end(); ++i) { - if (blob->getStartAddr() == (*i)->getStartAddr()) - return; +bool +RemoteImages::addMemBlob (RemoteMemoryBlob *blob) { + + if (fMemBlobs.empty()) + { + fMemBlobs.push_back(blob); + } + else + { + std::vector::iterator pos; + + pos = std::lower_bound (fMemBlobs.begin(), fMemBlobs.end(), blob); + + if (pos != fMemBlobs.end() && (*pos)->getStartAddr() == blob->getStartAddr()) + return false; + + fMemBlobs.insert (pos, blob); } - fMemBlobs.push_back(blob); - std::sort(fMemBlobs.begin(), fMemBlobs.end()); + return true; } uint8_t *RemoteImages::getMemBlobMemory (uint64_t addr, int len) { @@ -702,7 +713,7 @@ unw_addr_space_t wrap () { return (unw_addr_space_t) &fWrapper; } bool remoteIsLittleEndian () { return fLittleEndian; } unw_log_level_t getDebugLoggingLevel() { return fLogLevel; } - void addMemBlob (RemoteMemoryBlob *blob) { fImages.addMemBlob(blob); } + bool addMemBlob (RemoteMemoryBlob *blob) { return fImages.addMemBlob(blob); } unw_caching_policy_t getCachingPolicy() { return fCachingPolicy; } private: @@ -742,14 +753,16 @@ uint8_t *buf = (uint8_t*) malloc (compact_unwind_len); if (this->getBytes (compact_unwind, compact_unwind_len, buf, arg)) { RemoteMemoryBlob *b = new RemoteMemoryBlob(buf, free, compact_unwind, compact_unwind_len, mh, NULL); - fImages.addMemBlob (b); + if (fImages.addMemBlob (b) == false) + delete b; } } else if (eh_frame_len != 0) { logVerbose ("Creating RemoteMemoryBlob of eh_frame for image at mh 0x%llx, %lld bytes", mh, (uint64_t) compact_unwind_len); uint8_t *buf = (uint8_t*) malloc (eh_frame_len); if (this->getBytes (eh_frame, eh_frame_len, buf, arg)) { RemoteMemoryBlob *b = new RemoteMemoryBlob(buf, free, eh_frame, eh_frame_len, mh, NULL); - fImages.addMemBlob (b); + if (fImages.addMemBlob (b) == false) + delete b; } } } 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=107539&r1=107538&r2=107539&view=diff ============================================================================== --- lldb/trunk/source/Plugins/Process/Utility/libunwind/src/UnwindCursor.hpp (original) +++ lldb/trunk/source/Plugins/Process/Utility/libunwind/src/UnwindCursor.hpp Fri Jul 2 18:23:14 2010 @@ -1168,9 +1168,13 @@ // thing anyway so we might as well save it. uint8_t *eh_buf = (uint8_t *)malloc (eh_frame_len); if (UnwindCursor::fAddressSpace.getBytes (eh_frame_start, eh_frame_len, eh_buf) == 0) - return UNW_EUNSPEC; + { + free (eh_buf); + return UNW_EUNSPEC; + } RemoteMemoryBlob *ehmem = new RemoteMemoryBlob(eh_buf, free, eh_frame_start, eh_frame_len, mh, NULL); - procinfo->addMemBlob (ehmem); + if (procinfo->addMemBlob (ehmem) == false) + delete ehmem; } if (CFI_Parser::functionFuncBoundsViaFDE(UnwindCursor::fAddressSpace, eh_frame_start, eh_frame_len, func_bounds)) { @@ -1271,9 +1275,13 @@ // thing anyway so we might as well save it. uint8_t *eh_buf = (uint8_t *)malloc (eh_frame_len); if (UnwindCursor::fAddressSpace.getBytes (eh_frame_start, eh_frame_len, eh_buf) == 0) - return UNW_EUNSPEC; + { + free (eh_buf); + return UNW_EUNSPEC; + } RemoteMemoryBlob *ehmem = new RemoteMemoryBlob(eh_buf, free, eh_frame_start, eh_frame_len, mh, NULL); - procinfo->addMemBlob (ehmem); + if (procinfo->addMemBlob (ehmem) == false) + delete ehmem; } if (CFI_Parser::functionFuncBoundsViaFDE(UnwindCursor::fAddressSpace, eh_frame_start, eh_frame_len, func_bounds)) { procinfo->addFuncBounds(mh, func_bounds); Modified: lldb/trunk/source/Plugins/Process/Utility/libunwind/src/libuwind.cxx URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Utility/libunwind/src/libuwind.cxx?rev=107539&r1=107538&r2=107539&view=diff ============================================================================== --- lldb/trunk/source/Plugins/Process/Utility/libunwind/src/libuwind.cxx (original) +++ lldb/trunk/source/Plugins/Process/Utility/libunwind/src/libuwind.cxx Fri Jul 2 18:23:14 2010 @@ -235,25 +235,32 @@ // with the rest of the code here. switch ( remote->ras->getTargetArch() ) { case UNW_TARGET_I386: - { - Registers_x86 *r = new Registers_x86; + { + Registers_x86 r; + // LEAK: "addrSpace" is being leaked every time here with no easy solution. + // The address space is in the cursor and the cursor may get + // duplicated, though if it does get duplicated, it will just be + // memcpy'ed since unw_cursor_t is just a bunch of uint64_t types... OtherAddressSpace > *addrSpace = new OtherAddressSpace >(as, arg); - getRemoteContext (remote->ras, *r, arg); - unw_context_t *context = (unw_context_t*) r; + getRemoteContext (remote->ras, r, arg); + unw_context_t *context = (unw_context_t*) &r; new ((void*)cursor) RemoteUnwindCursor >, Registers_x86>(*addrSpace, context, arg); - break; - } + } break; case UNW_TARGET_X86_64: - { - Registers_x86_64 *r = new Registers_x86_64; + { + Registers_x86_64 r; + // LEAK: "addrSpace" is being leaked every time here with no easy solution. + // The address space is in the cursor and the cursor may get + // duplicated, though if it does get duplicated, it will just be + // memcpy'ed since unw_cursor_t is just a bunch of uint64_t types... OtherAddressSpace > *addrSpace = new OtherAddressSpace >(as, arg); - getRemoteContext (remote->ras, *r, arg); - unw_context_t *context = (unw_context_t*) r; + getRemoteContext (remote->ras, r, arg); + unw_context_t *context = (unw_context_t*) &r; new ((void*)cursor) RemoteUnwindCursor >, Registers_x86_64>(*addrSpace, context, arg); - break; - } - + } + break; + case UNW_TARGET_PPC: ABORT("ppc not supported for remote unwinds"); break; From johnny.chen at apple.com Fri Jul 2 18:50:38 2010 From: johnny.chen at apple.com (Johnny Chen) Date: Fri, 02 Jul 2010 23:50:38 -0000 Subject: [Lldb-commits] [lldb] r107545 - /lldb/trunk/test/function_types/TestFunctionTypes.py Message-ID: <20100702235038.208742A6C12C@llvm.org> Author: johnny Date: Fri Jul 2 18:50:37 2010 New Revision: 107545 URL: http://llvm.org/viewvc/llvm-project?rev=107545&view=rev Log: Test variable with function ptr type and that break on the function works. Added: lldb/trunk/test/function_types/TestFunctionTypes.py Added: lldb/trunk/test/function_types/TestFunctionTypes.py URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/function_types/TestFunctionTypes.py?rev=107545&view=auto ============================================================================== --- lldb/trunk/test/function_types/TestFunctionTypes.py (added) +++ lldb/trunk/test/function_types/TestFunctionTypes.py Fri Jul 2 18:50:37 2010 @@ -0,0 +1,90 @@ +"""Test variable with function ptr type and that break on the function works.""" + +import os, time +import lldb +import unittest + +main = False + +class TestClassTypes(unittest.TestCase): + + def setUp(self): + global main + + # Save old working directory. + self.oldcwd = os.getcwd() + # Change current working directory if ${LLDB_TEST} is defined. + if ("LLDB_TEST" in os.environ): + os.chdir(os.path.join(os.environ["LLDB_TEST"], "function_types")); + self.dbg = lldb.SBDebugger.Create() if main else lldb.DBG + if not self.dbg.IsValid(): + raise Exception('Invalid debugger instance') + self.dbg.SetAsync(False) + self.ci = self.dbg.GetCommandInterpreter() + if not self.ci: + raise Exception('Could not get the command interpreter') + + def tearDown(self): + # Restore old working directory. + os.chdir(self.oldcwd) + del self.dbg + + def test_function_types(self): + """Test 'callback' has function ptr type, then break on the function.""" + res = lldb.SBCommandReturnObject() + exe = os.path.join(os.getcwd(), "a.out") + self.ci.HandleCommand("file " + exe, res) + self.assertTrue(res.Succeeded()) + + # Break inside the main. + self.ci.HandleCommand("breakpoint set -f main.c -l 21", res) + self.assertTrue(res.Succeeded()) + self.assertTrue(res.GetOutput().startswith( + "Breakpoint created: 1: file ='main.c', line = 21, locations = 1")) + + self.ci.HandleCommand("run", res) + time.sleep(0.1) + self.assertTrue(res.Succeeded()) + + # The stop reason of the thread should be breakpoint. + self.ci.HandleCommand("thread list", res) + print "thread list ->", res.GetOutput() + self.assertTrue(res.Succeeded()) + self.assertTrue(res.GetOutput().find('state is Stopped') and + res.GetOutput().find('stop reason = breakpoint')) + + # The breakpoint should have a hit count of 1. + self.ci.HandleCommand("breakpoint list", res) + self.assertTrue(res.Succeeded()) + self.assertTrue(res.GetOutput().find(' resolved, hit count = 1')) + + # Check that the 'callback' variable display properly. + self.ci.HandleCommand("variable list callback", res); + self.assertTrue(res.Succeeded()) + output = res.GetOutput() + self.assertTrue(output.startswith('(int (*)(char const *)) callback =')) + + # And that we can break on the callback function. + self.ci.HandleCommand("breakpoint set -n string_not_empty", res); + self.assertTrue(res.Succeeded()) + self.ci.HandleCommand("continue", res) + self.assertTrue(res.Succeeded()) + + # Check that we do indeed stop on the string_not_empty function. + self.ci.HandleCommand("process status", res) + self.assertTrue(res.Succeeded()) + output = res.GetOutput() + #print "process status =", output + self.assertTrue(output.find('where = a.out`string_not_empty') and + output.find('main.c:12') and + output.find('stop reason = breakpoint')) + + self.ci.HandleCommand("continue", res) + self.assertTrue(res.Succeeded()) + + +if __name__ == '__main__': + lldb.SBDebugger.Initialize() + main = True + unittest.main() + lldb.SBDebugger.Terminate() From scallanan at apple.com Fri Jul 2 20:35:46 2010 From: scallanan at apple.com (Sean Callanan) Date: Sat, 03 Jul 2010 01:35:46 -0000 Subject: [Lldb-commits] [lldb] r107559 - in /lldb/trunk: include/lldb/Expression/ClangExpression.h include/lldb/Expression/IRForTarget.h lldb.xcodeproj/project.pbxproj source/Commands/CommandObjectExpression.cpp source/Expression/ClangExpression.cpp source/Expression/IRForTarget.cpp source/Expression/IRToDWARF.cpp Message-ID: <20100703013546.69FAA2A6C12C@llvm.org> Author: spyffe Date: Fri Jul 2 20:35:46 2010 New Revision: 107559 URL: http://llvm.org/viewvc/llvm-project?rev=107559&view=rev Log: Added the skeleton of an IR transformer that will prepare IR for execution in the target. Wired the expression command to use this IR transformer when conversion to DWARF fails, and wired conversion to DWARF to always fail (well, we don't generate any DWARF...) Added: lldb/trunk/include/lldb/Expression/IRForTarget.h lldb/trunk/source/Expression/IRForTarget.cpp Modified: lldb/trunk/include/lldb/Expression/ClangExpression.h lldb/trunk/lldb.xcodeproj/project.pbxproj lldb/trunk/source/Commands/CommandObjectExpression.cpp lldb/trunk/source/Expression/ClangExpression.cpp lldb/trunk/source/Expression/IRToDWARF.cpp Modified: lldb/trunk/include/lldb/Expression/ClangExpression.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Expression/ClangExpression.h?rev=107559&r1=107558&r2=107559&view=diff ============================================================================== --- lldb/trunk/include/lldb/Expression/ClangExpression.h (original) +++ lldb/trunk/include/lldb/Expression/ClangExpression.h Fri Jul 2 20:35:46 2010 @@ -62,9 +62,12 @@ ConvertExpressionToDWARF (ClangExpressionVariableList &expr_local_variable_list, StreamString &dwarf_opcode_strm); - unsigned + bool ConvertIRToDWARF (ClangExpressionVariableList &excpr_local_variable_list, StreamString &dwarf_opcode_strm); + + bool + PrepareIRForTarget (ClangExpressionVariableList &excpr_local_variable_list); bool JITFunction (const ExecutionContext &exc_context, const char *func_name); Added: lldb/trunk/include/lldb/Expression/IRForTarget.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Expression/IRForTarget.h?rev=107559&view=auto ============================================================================== --- lldb/trunk/include/lldb/Expression/IRForTarget.h (added) +++ lldb/trunk/include/lldb/Expression/IRForTarget.h Fri Jul 2 20:35:46 2010 @@ -0,0 +1,41 @@ +//===-- IRForTarget.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_IRForTarget_h_ +#define liblldb_IRForTarget_h_ + +#include "llvm/Pass.h" +#include "llvm/PassManager.h" + +namespace llvm { + class BasicBlock; + class Module; +} + +namespace lldb_private { + class ClangExpressionDeclMap; +} + +class IRForTarget : public llvm::ModulePass +{ +public: + IRForTarget(const void *pid, + lldb_private::ClangExpressionDeclMap *decl_map); + ~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); + + lldb_private::ClangExpressionDeclMap *m_decl_map; +}; + +#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=107559&r1=107558&r2=107559&view=diff ============================================================================== --- lldb/trunk/lldb.xcodeproj/project.pbxproj (original) +++ lldb/trunk/lldb.xcodeproj/project.pbxproj Fri Jul 2 20:35:46 2010 @@ -328,6 +328,8 @@ 26F5C32D10F3DFDD009D5894 /* libtermcap.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 26F5C32B10F3DFDD009D5894 /* libtermcap.dylib */; }; 26F5C37510F3F61B009D5894 /* libobjc.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 26F5C37410F3F61B009D5894 /* libobjc.dylib */; }; 26F5C39110F3FA26009D5894 /* CoreFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 26F5C39010F3FA26009D5894 /* CoreFoundation.framework */; }; + 49307AAE11DEA4D90081F992 /* IRForTarget.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 49307AAD11DEA4D90081F992 /* IRForTarget.cpp */; }; + 49307AB211DEA4F20081F992 /* IRForTarget.h in Headers */ = {isa = PBXBuildFile; fileRef = 49307AB111DEA4F20081F992 /* IRForTarget.h */; }; 49A8A3A011D568A300AD3B68 /* ClangResultSynthesizer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 49A8A39F11D568A300AD3B68 /* ClangResultSynthesizer.cpp */; }; 49A8A3A411D568BF00AD3B68 /* ClangResultSynthesizer.h in Headers */ = {isa = PBXBuildFile; fileRef = 49A8A3A311D568BF00AD3B68 /* ClangResultSynthesizer.h */; }; 49D7072711B5AD03001AD875 /* ClangASTSource.h in Headers */ = {isa = PBXBuildFile; fileRef = 49D7072611B5AD03001AD875 /* ClangASTSource.h */; }; @@ -890,6 +892,8 @@ 26F996A8119B79C300412154 /* ARM_GCC_Registers.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ARM_GCC_Registers.h; path = source/Utility/ARM_GCC_Registers.h; sourceTree = ""; }; 26FE25221146CADE00F4085A /* GDBRemoteCommunication.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = GDBRemoteCommunication.cpp; path = "source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp"; sourceTree = ""; }; 26FE25231146CADE00F4085A /* GDBRemoteCommunication.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = GDBRemoteCommunication.h; path = "source/Plugins/Process/gdb-remote/GDBRemoteCommunication.h"; sourceTree = ""; }; + 49307AAD11DEA4D90081F992 /* IRForTarget.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = IRForTarget.cpp; path = source/Expression/IRForTarget.cpp; sourceTree = ""; }; + 49307AB111DEA4F20081F992 /* IRForTarget.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = IRForTarget.h; path = include/lldb/Expression/IRForTarget.h; sourceTree = ""; }; 493C63F01189203300914D5E /* ABISysV_x86_64.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ABISysV_x86_64.h; path = "ABI/SysV-x86_64/ABISysV_x86_64.h"; sourceTree = ""; }; 493C63F11189203300914D5E /* ABISysV_x86_64.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ABISysV_x86_64.cpp; path = "ABI/SysV-x86_64/ABISysV_x86_64.cpp"; sourceTree = ""; }; 495BBACB119A0DBE00418BEA /* PathMappingList.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = PathMappingList.cpp; path = source/Target/PathMappingList.cpp; sourceTree = ""; }; @@ -1836,6 +1840,8 @@ 26BC7ED710F1B86700F91463 /* ClangStmtVisitor.cpp */, 26BC7DC310F1B79500F91463 /* DWARFExpression.h */, 26BC7ED810F1B86700F91463 /* DWARFExpression.cpp */, + 49307AB111DEA4F20081F992 /* IRForTarget.h */, + 49307AAD11DEA4D90081F992 /* IRForTarget.cpp */, 49DA743411DE6BB2006AEF7E /* IRToDWARF.h */, 49DA742F11DE6A5A006AEF7E /* IRToDWARF.cpp */, 4C98D3E1118FB98F00E575D0 /* RecordingMemoryManager.h */, @@ -2191,6 +2197,7 @@ 4C08CDEC11C81F1E001610A8 /* ThreadSpec.h in Headers */, 49A8A3A411D568BF00AD3B68 /* ClangResultSynthesizer.h in Headers */, 49DA743511DE6BB2006AEF7E /* IRToDWARF.h in Headers */, + 49307AB211DEA4F20081F992 /* IRForTarget.h in Headers */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -2641,6 +2648,7 @@ 4C08CDE811C81EF8001610A8 /* ThreadSpec.cpp in Sources */, 49A8A3A011D568A300AD3B68 /* ClangResultSynthesizer.cpp in Sources */, 49DA743011DE6A5A006AEF7E /* IRToDWARF.cpp in Sources */, + 49307AAE11DEA4D90081F992 /* IRForTarget.cpp in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; Modified: lldb/trunk/source/Commands/CommandObjectExpression.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectExpression.cpp?rev=107559&r1=107558&r2=107559&view=diff ============================================================================== --- lldb/trunk/source/Commands/CommandObjectExpression.cpp (original) +++ lldb/trunk/source/Commands/CommandObjectExpression.cpp Fri Jul 2 20:35:46 2010 @@ -252,11 +252,29 @@ ClangExpressionVariableList expr_local_vars; bool success; + bool canInterpret = false; if (m_options.use_ir) - success = (clang_expr.ConvertIRToDWARF (expr_local_vars, dwarf_opcodes) == 0); + { + canInterpret = clang_expr.ConvertIRToDWARF (expr_local_vars, dwarf_opcodes); + + if (canInterpret) + { + if (log) + log->Printf("Code can be interpreted."); + success = true; + } + else + { + if (log) + log->Printf("Code cannot be interpreted and must be run in the target."); + success = clang_expr.PrepareIRForTarget (expr_local_vars); + } + } else + { success = (clang_expr.ConvertExpressionToDWARF (expr_local_vars, dwarf_opcodes) == 0); + } if (!success) { Modified: lldb/trunk/source/Expression/ClangExpression.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/ClangExpression.cpp?rev=107559&r1=107558&r2=107559&view=diff ============================================================================== --- lldb/trunk/source/Expression/ClangExpression.cpp (original) +++ lldb/trunk/source/Expression/ClangExpression.cpp Fri Jul 2 20:35:46 2010 @@ -58,6 +58,7 @@ #include "lldb/Expression/ClangASTSource.h" #include "lldb/Expression/ClangResultSynthesizer.h" #include "lldb/Expression/ClangStmtVisitor.h" +#include "lldb/Expression/IRForTarget.h" #include "lldb/Expression/IRToDWARF.h" #include "lldb/Symbol/ClangASTContext.h" #include "lldb/Expression/RecordingMemoryManager.h" @@ -474,7 +475,7 @@ return 0; } -unsigned +bool ClangExpression::ConvertIRToDWARF (ClangExpressionVariableList &expr_local_variable_list, StreamString &dwarf_opcode_strm) { @@ -496,6 +497,26 @@ } bool +ClangExpression::PrepareIRForTarget (ClangExpressionVariableList &expr_local_variable_list) +{ + Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS); + + llvm::Module *module = m_code_generator_ptr->GetModule(); + + if (!module) + { + if (log) + log->Printf("IR doesn't contain a module"); + + return 1; + } + + IRForTarget ir_for_target("IR for target", m_decl_map); + + return ir_for_target.runOnModule(*module); +} + +bool ClangExpression::JITFunction (const ExecutionContext &exc_context, const char *name) { Added: lldb/trunk/source/Expression/IRForTarget.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/IRForTarget.cpp?rev=107559&view=auto ============================================================================== --- lldb/trunk/source/Expression/IRForTarget.cpp (added) +++ lldb/trunk/source/Expression/IRForTarget.cpp Fri Jul 2 20:35:46 2010 @@ -0,0 +1,109 @@ +//===-- IRForTarget.cpp -------------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "lldb/Expression/IRForTarget.h" + +#include "llvm/Support/raw_ostream.h" +#include "llvm/InstrTypes.h" +#include "llvm/Module.h" + +#include "lldb/Core/dwarf.h" +#include "lldb/Core/Log.h" +#include "lldb/Core/Scalar.h" +#include "lldb/Core/StreamString.h" +#include "lldb/Expression/ClangExpressionDeclMap.h" + +#include + +using namespace llvm; + +IRForTarget::IRForTarget(const void *pid, + lldb_private::ClangExpressionDeclMap *decl_map) : + ModulePass(pid), + m_decl_map(decl_map) +{ +} + +IRForTarget::~IRForTarget() +{ +} + +bool +IRForTarget::runOnBasicBlock(BasicBlock &BB) +{ + lldb_private::Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS); + + ///////////////////////////////////////////////////////////////////////// + // Prepare the current basic block for execution in the remote process + // + + if (log) + { + log->Printf("Preparing basic block %s:", + BB.hasName() ? BB.getNameStr().c_str() : "[anonymous]"); + + llvm::BasicBlock::iterator ii; + + 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()); + } + } + + return true; +} + +bool +IRForTarget::runOnModule(Module &M) +{ + lldb_private::Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS); + + llvm::Function* function = M.getFunction(StringRef("___clang_expr")); + + if (!function) + { + if (log) + log->Printf("Couldn't find ___clang_expr() in the module"); + + return false; + } + + llvm::Function::iterator bbi; + + for (bbi = function->begin(); + bbi != function->end(); + ++bbi) + { + runOnBasicBlock(*bbi); + } + + return true; +} + +void +IRForTarget::assignPassManager(PMStack &PMS, + PassManagerType T) +{ +} + +PassManagerType +IRForTarget::getPotentialPassManagerType() const +{ + return PMT_ModulePassManager; +} Modified: lldb/trunk/source/Expression/IRToDWARF.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/IRToDWARF.cpp?rev=107559&r1=107558&r2=107559&view=diff ============================================================================== --- lldb/trunk/source/Expression/IRToDWARF.cpp (original) +++ lldb/trunk/source/Expression/IRToDWARF.cpp Fri Jul 2 20:35:46 2010 @@ -207,9 +207,11 @@ Relocator relocator; - llvm::BasicBlock ¤tBB = function->getEntryBlock(); + if (!runOnBasicBlock(function->getEntryBlock(), relocator)) + return false; - runOnBasicBlock(currentBB, relocator); + // TEMPORARY: Fail in order to force execution in the target. + return false; return relocator.ResolveRelocations(m_strm); } From johnny.chen at apple.com Fri Jul 2 22:41:59 2010 From: johnny.chen at apple.com (Johnny Chen) Date: Sat, 03 Jul 2010 03:41:59 -0000 Subject: [Lldb-commits] [lldb] r107563 - in /lldb/trunk/test: array_types/TestArrayTypes.py class_types/TestClassTypes.py dotest.pl dotest.py function_types/TestFunctionTypes.py global_variables/TestGlobalVariables.py help/TestHelp.py lldbtest.py Message-ID: <20100703034159.3E26F2A6C12C@llvm.org> Author: johnny Date: Fri Jul 2 22:41:59 2010 New Revision: 107563 URL: http://llvm.org/viewvc/llvm-project?rev=107563&view=rev Log: Abstracted the lldb-specific unittest.TestCase.setUp()/tearDown() in a separate module lldbtest.py and refactored the existing test cases to derive from the abstract base class lldbtest.TestBase. MOdified the test driver (dotest.py and dotest.pl) to set up additional PYTHONPATH component for locating the lldbtest module, which sits in the same directory. Added: lldb/trunk/test/lldbtest.py Modified: lldb/trunk/test/array_types/TestArrayTypes.py lldb/trunk/test/class_types/TestClassTypes.py lldb/trunk/test/dotest.pl lldb/trunk/test/dotest.py lldb/trunk/test/function_types/TestFunctionTypes.py lldb/trunk/test/global_variables/TestGlobalVariables.py lldb/trunk/test/help/TestHelp.py Modified: lldb/trunk/test/array_types/TestArrayTypes.py URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/array_types/TestArrayTypes.py?rev=107563&r1=107562&r2=107563&view=diff ============================================================================== --- lldb/trunk/test/array_types/TestArrayTypes.py (original) +++ lldb/trunk/test/array_types/TestArrayTypes.py Fri Jul 2 22:41:59 2010 @@ -1,37 +1,17 @@ """Test breakpoint by file/line number; and list variables with array types.""" import os, time -import lldb import unittest +import lldb +import lldbtest -main = False - -class TestArrayTypes(unittest.TestCase): - - def setUp(self): - global main +class TestArrayTypes(lldbtest.TestBase): - # Save old working directory. - self.oldcwd = os.getcwd() - # Change current working directory if ${LLDB_TEST} is defined. - if ("LLDB_TEST" in os.environ): - os.chdir(os.path.join(os.environ["LLDB_TEST"], "array_types")); - self.dbg = lldb.SBDebugger.Create() if main else lldb.DBG - if not self.dbg.IsValid(): - raise Exception('Invalid debugger instance') - self.dbg.SetAsync(False) - self.ci = self.dbg.GetCommandInterpreter() - if not self.ci: - raise Exception('Could not get the command interpreter') - - def tearDown(self): - # Restore old working directory. - os.chdir(self.oldcwd) - del self.dbg + mydir = "array_types" def test_array_types(self): """Test 'variable list var_name' on some variables with array types.""" - res = lldb.SBCommandReturnObject() + res = self.res exe = os.path.join(os.getcwd(), "a.out") self.ci.HandleCommand("file " + exe, res) self.assertTrue(res.Succeeded()) @@ -92,6 +72,5 @@ if __name__ == '__main__': lldb.SBDebugger.Initialize() - main = True unittest.main() lldb.SBDebugger.Terminate() Modified: lldb/trunk/test/class_types/TestClassTypes.py URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/class_types/TestClassTypes.py?rev=107563&r1=107562&r2=107563&view=diff ============================================================================== --- lldb/trunk/test/class_types/TestClassTypes.py (original) +++ lldb/trunk/test/class_types/TestClassTypes.py Fri Jul 2 22:41:59 2010 @@ -1,37 +1,17 @@ """Test breakpoint on a class constructor; and variable list the this object.""" import os, time -import lldb import unittest +import lldb +import lldbtest -main = False - -class TestClassTypes(unittest.TestCase): - - def setUp(self): - global main +class TestClassTypes(lldbtest.TestBase): - # Save old working directory. - self.oldcwd = os.getcwd() - # Change current working directory if ${LLDB_TEST} is defined. - if ("LLDB_TEST" in os.environ): - os.chdir(os.path.join(os.environ["LLDB_TEST"], "class_types")); - self.dbg = lldb.SBDebugger.Create() if main else lldb.DBG - if not self.dbg.IsValid(): - raise Exception('Invalid debugger instance') - self.dbg.SetAsync(False) - self.ci = self.dbg.GetCommandInterpreter() - if not self.ci: - raise Exception('Could not get the command interpreter') - - def tearDown(self): - # Restore old working directory. - os.chdir(self.oldcwd) - del self.dbg + mydir = "class_types" def test_class_types(self): """Test 'variable list this' when stopped on a class constructor.""" - res = lldb.SBCommandReturnObject() + res = self.res exe = os.path.join(os.getcwd(), "a.out") self.ci.HandleCommand("file " + exe, res) self.assertTrue(res.Succeeded()) @@ -69,6 +49,5 @@ if __name__ == '__main__': lldb.SBDebugger.Initialize() - main = True unittest.main() lldb.SBDebugger.Terminate() Modified: lldb/trunk/test/dotest.pl URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/dotest.pl?rev=107563&r1=107562&r2=107563&view=diff ============================================================================== --- lldb/trunk/test/dotest.pl (original) +++ lldb/trunk/test/dotest.pl Fri Jul 2 22:41:59 2010 @@ -21,9 +21,9 @@ my $dbgPath = "$baseDir/build/Debug/LLDB.framework/Resources/Python"; my $relPath = "$baseDir/build/Release/LLDB.framework/Resources/Python"; if (-d $dbgPath) { - $ENV{'PYTHONPATH'} = "$dbgPath"; + $ENV{'PYTHONPATH'} = "$dbgPath:$scriptDir"; } elsif (-d $relPath) { - $ENV{'PYTHONPATH'} = "$relPath"; + $ENV{'PYTHONPATH'} = "$relPath:$scriptDir"; } #print("ENV{PYTHONPATH}=$ENV{'PYTHONPATH'}\n"); Modified: lldb/trunk/test/dotest.py URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/dotest.py?rev=107563&r1=107562&r2=107563&view=diff ============================================================================== --- lldb/trunk/test/dotest.py (original) +++ lldb/trunk/test/dotest.py Fri Jul 2 22:41:59 2010 @@ -53,14 +53,14 @@ """Add LLDB.framework/Resources/Python to the search paths for modules.""" # Get the directory containing the current script. - testPath = sys.path[0] - if not testPath.endswith('test'): + scriptPath = sys.path[0] + if not scriptPath.endswith('test'): print "This script expects to reside in lldb's test directory." sys.exit(-1) - os.environ["LLDB_TEST"] = testPath + os.environ["LLDB_TEST"] = scriptPath - base = os.path.abspath(os.path.join(testPath, os.pardir)) + base = os.path.abspath(os.path.join(scriptPath, os.pardir)) dbgPath = os.path.join(base, 'build', 'Debug', 'LLDB.framework', 'Resources', 'Python') relPath = os.path.join(base, 'build', 'Release', 'LLDB.framework', @@ -78,6 +78,7 @@ sys.exit(-1) sys.path.append(lldbPath) + sys.path.append(scriptPath) def initTestdirs(): Modified: lldb/trunk/test/function_types/TestFunctionTypes.py URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/function_types/TestFunctionTypes.py?rev=107563&r1=107562&r2=107563&view=diff ============================================================================== --- lldb/trunk/test/function_types/TestFunctionTypes.py (original) +++ lldb/trunk/test/function_types/TestFunctionTypes.py Fri Jul 2 22:41:59 2010 @@ -1,39 +1,21 @@ """Test variable with function ptr type and that break on the function works.""" import os, time -import lldb import unittest +import lldb +import lldbtest -main = False - -class TestClassTypes(unittest.TestCase): - - def setUp(self): - global main +class TestClassTypes(lldbtest.TestBase): - # Save old working directory. - self.oldcwd = os.getcwd() - # Change current working directory if ${LLDB_TEST} is defined. - if ("LLDB_TEST" in os.environ): - os.chdir(os.path.join(os.environ["LLDB_TEST"], "function_types")); - self.dbg = lldb.SBDebugger.Create() if main else lldb.DBG - if not self.dbg.IsValid(): - raise Exception('Invalid debugger instance') - self.dbg.SetAsync(False) - self.ci = self.dbg.GetCommandInterpreter() - if not self.ci: - raise Exception('Could not get the command interpreter') - - def tearDown(self): - # Restore old working directory. - os.chdir(self.oldcwd) - del self.dbg + mydir = "function_types" def test_function_types(self): """Test 'callback' has function ptr type, then break on the function.""" - res = lldb.SBCommandReturnObject() + res = self.res exe = os.path.join(os.getcwd(), "a.out") self.ci.HandleCommand("file " + exe, res) + print "os.getcwd(): ", os.getcwd() + print "file a.out :", res.GetOutput() self.assertTrue(res.Succeeded()) # Break inside the main. @@ -85,6 +67,5 @@ if __name__ == '__main__': lldb.SBDebugger.Initialize() - main = True unittest.main() lldb.SBDebugger.Terminate() Modified: lldb/trunk/test/global_variables/TestGlobalVariables.py URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/global_variables/TestGlobalVariables.py?rev=107563&r1=107562&r2=107563&view=diff ============================================================================== --- lldb/trunk/test/global_variables/TestGlobalVariables.py (original) +++ lldb/trunk/test/global_variables/TestGlobalVariables.py Fri Jul 2 22:41:59 2010 @@ -1,37 +1,17 @@ """Show global variables and check that they do indeed have global scopes.""" import os, time -import lldb import unittest +import lldb +import lldbtest -main = False - -class TestClassTypes(unittest.TestCase): - - def setUp(self): - global main +class TestClassTypes(lldbtest.TestBase): - # Save old working directory. - self.oldcwd = os.getcwd() - # Change current working directory if ${LLDB_TEST} is defined. - if ("LLDB_TEST" in os.environ): - os.chdir(os.path.join(os.environ["LLDB_TEST"], "global_variables")); - self.dbg = lldb.SBDebugger.Create() if main else lldb.DBG - if not self.dbg.IsValid(): - raise Exception('Invalid debugger instance') - self.dbg.SetAsync(False) - self.ci = self.dbg.GetCommandInterpreter() - if not self.ci: - raise Exception('Could not get the command interpreter') - - def tearDown(self): - # Restore old working directory. - os.chdir(self.oldcwd) - del self.dbg + mydir = "global_variables" def test_global_variables(self): """Test 'variable list -s -a' which omits args and shows scopes.""" - res = lldb.SBCommandReturnObject() + res = self.res exe = os.path.join(os.getcwd(), "a.out") self.ci.HandleCommand("file " + exe, res) self.assertTrue(res.Succeeded()) @@ -75,6 +55,5 @@ if __name__ == '__main__': lldb.SBDebugger.Initialize() - main = True unittest.main() lldb.SBDebugger.Terminate() Modified: lldb/trunk/test/help/TestHelp.py URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/help/TestHelp.py?rev=107563&r1=107562&r2=107563&view=diff ============================================================================== --- lldb/trunk/test/help/TestHelp.py (original) +++ lldb/trunk/test/help/TestHelp.py Fri Jul 2 22:41:59 2010 @@ -1,33 +1,13 @@ """Test lldb help command.""" import os, time -import lldb import unittest +import lldb +import lldbtest -main = False - -class TestHelpCommand(unittest.TestCase): - - def setUp(self): - global main +class TestHelpCommand(lldbtest.TestBase): - # Save old working directory. - self.oldcwd = os.getcwd() - # Change current working directory if ${LLDB_TEST} is defined. - if ("LLDB_TEST" in os.environ): - os.chdir(os.path.join(os.environ["LLDB_TEST"], "help")); - self.dbg = lldb.SBDebugger.Create() if main else lldb.DBG - if not self.dbg.IsValid(): - raise Exception('Invalid debugger instance') - self.dbg.SetAsync(False) - self.ci = self.dbg.GetCommandInterpreter() - if not self.ci: - raise Exception('Could not get the command interpreter') - - def tearDown(self): - # Restore old working directory. - os.chdir(self.oldcwd) - del self.dbg + mydir = "help" def test_simplehelp(self): """A simple test of 'help' command and its output.""" @@ -53,6 +33,5 @@ if __name__ == '__main__': lldb.SBDebugger.Initialize() - main = True unittest.main() lldb.SBDebugger.Terminate() Added: lldb/trunk/test/lldbtest.py URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/lldbtest.py?rev=107563&view=auto ============================================================================== --- lldb/trunk/test/lldbtest.py (added) +++ lldb/trunk/test/lldbtest.py Fri Jul 2 22:41:59 2010 @@ -0,0 +1,75 @@ +""" +LLDB module which provides the abstract base class of lldb test case. + +The concrete subclass can override lldbtest.TesBase in order to inherit the +common behavior for unitest.TestCase.setUp/tearDown implemented in this file. + +The subclass should override the attribute mydir in order for the python runtime +to locate the individual test cases when running as part of a large test suite +or when running each test case as a separate python invocation. + +./dotest.py provides a test driver which sets up the environment to run the +entire test suite. Users who want to run a test case on its own can specify the +LLDB_TEST and PYTHONPATH environment variables, for example: + +$ export LLDB_TEST=$PWD +$ export PYTHONPATH=/Volumes/data/lldb/svn/trunk/build/Debug/LLDB.framework/Resources/Python:$LLDB_TEST +$ echo $LLDB_TEST +/Volumes/data/lldb/svn/trunk/test +$ echo $PYTHONPATH +/Volumes/data/lldb/svn/trunk/build/Debug/LLDB.framework/Resources/Python:/Volumes/data/lldb/svn/trunk/test +$ python function_types/TestFunctionTypes.py +. +---------------------------------------------------------------------- +Ran 1 test in 0.363s + +OK +$ +""" + +import os +import unittest +import lldb + +class TestBase(unittest.TestCase): + """This LLDB abstract base class is meant to be subclassed.""" + + # The concrete subclass should override this attribute. + mydir = "" + + def setUp(self): + # Save old working directory. + self.oldcwd = os.getcwd() + + # Change current working directory if ${LLDB_TEST} is defined. + # See also dotest.py which sets up ${LLDB_TEST}. + if ("LLDB_TEST" in os.environ): + os.chdir(os.path.join(os.environ["LLDB_TEST"], self.mydir)); + + # Create the debugger instance if necessary. + try: + self.dbg = lldb.DBG + except NameError: + self.dbg = lldb.SBDebugger.Create() + except AttributeError: + self.dbg = lldb.SBDebugger.Create() + if not self.dbg.IsValid(): + raise Exception('Invalid debugger instance') + + # We want our debugger to be synchronous. + self.dbg.SetAsync(False) + + # Retrieve the associated command interpreter instance. + self.ci = self.dbg.GetCommandInterpreter() + if not self.ci: + raise Exception('Could not get the command interpreter') + + # And the result object. + self.res = lldb.SBCommandReturnObject() + + + def tearDown(self): + del self.dbg + + # Restore old working directory. + os.chdir(self.oldcwd) From johnny.chen at apple.com Sat Jul 3 15:41:42 2010 From: johnny.chen at apple.com (Johnny Chen) Date: Sat, 03 Jul 2010 20:41:42 -0000 Subject: [Lldb-commits] [lldb] r107575 - in /lldb/trunk/test: function_types/TestFunctionTypes.py lldbtest.py Message-ID: <20100703204142.BC4742A6C12C@llvm.org> Author: johnny Date: Sat Jul 3 15:41:42 2010 New Revision: 107575 URL: http://llvm.org/viewvc/llvm-project?rev=107575&view=rev Log: Make it fail fast if 'mydir' attribute is not overridden by subclasses of lldbtest.TestBase. Also removed some debug prints. Modified: lldb/trunk/test/function_types/TestFunctionTypes.py lldb/trunk/test/lldbtest.py Modified: lldb/trunk/test/function_types/TestFunctionTypes.py URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/function_types/TestFunctionTypes.py?rev=107575&r1=107574&r2=107575&view=diff ============================================================================== --- lldb/trunk/test/function_types/TestFunctionTypes.py (original) +++ lldb/trunk/test/function_types/TestFunctionTypes.py Sat Jul 3 15:41:42 2010 @@ -14,8 +14,6 @@ res = self.res exe = os.path.join(os.getcwd(), "a.out") self.ci.HandleCommand("file " + exe, res) - print "os.getcwd(): ", os.getcwd() - print "file a.out :", res.GetOutput() self.assertTrue(res.Succeeded()) # Break inside the main. Modified: lldb/trunk/test/lldbtest.py URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/lldbtest.py?rev=107575&r1=107574&r2=107575&view=diff ============================================================================== --- lldb/trunk/test/lldbtest.py (original) +++ lldb/trunk/test/lldbtest.py Sat Jul 3 15:41:42 2010 @@ -35,9 +35,12 @@ """This LLDB abstract base class is meant to be subclassed.""" # The concrete subclass should override this attribute. - mydir = "" + mydir = None def setUp(self): + # Fail fast if 'mydir' attribute is not overridden. + if not self.mydir or len(self.mydir) == 0: + raise Exception("Subclasses must override the 'mydir' attribute.") # Save old working directory. self.oldcwd = os.getcwd() @@ -49,10 +52,9 @@ # Create the debugger instance if necessary. try: self.dbg = lldb.DBG - except NameError: - self.dbg = lldb.SBDebugger.Create() except AttributeError: self.dbg = lldb.SBDebugger.Create() + if not self.dbg.IsValid(): raise Exception('Invalid debugger instance')