From johnny.chen at apple.com Mon Sep 12 14:12:06 2011 From: johnny.chen at apple.com (Johnny Chen) Date: Mon, 12 Sep 2011 19:12:06 -0000 Subject: [Lldb-commits] [lldb] r139524 - in /lldb/trunk/source: Commands/CommandObjectFrame.cpp Interpreter/OptionGroupWatchpoint.cpp Message-ID: <20110912191206.DD8202A6C12C@llvm.org> Author: johnny Date: Mon Sep 12 14:12:06 2011 New Revision: 139524 URL: http://llvm.org/viewvc/llvm-project?rev=139524&view=rev Log: Fix a bug in OptionGroupWatchpoint.cpp where the '-w' option arg parsing result was not checked to effect an early error return. Plus add logic to 'frame variable' command object to check that when watchpoint option is on, only one variable with exact name (no regex) is specified as the sole command arg. Modified: lldb/trunk/source/Commands/CommandObjectFrame.cpp lldb/trunk/source/Interpreter/OptionGroupWatchpoint.cpp Modified: lldb/trunk/source/Commands/CommandObjectFrame.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectFrame.cpp?rev=139524&r1=139523&r2=139524&view=diff ============================================================================== --- lldb/trunk/source/Commands/CommandObjectFrame.cpp (original) +++ lldb/trunk/source/Commands/CommandObjectFrame.cpp Mon Sep 12 14:12:06 2011 @@ -414,6 +414,22 @@ if (variable_list) { + // If watching a variable, there are certain restrictions to be followed. + if (m_option_watchpoint.watch_variable) + { + if (command.GetArgumentCount() != 1) { + result.GetErrorStream().Printf("error: specify exactly one variable when using the '-w' option\n"); + result.SetStatus(eReturnStatusFailed); + return false; + } else if (m_option_variable.use_regex) { + result.GetErrorStream().Printf("error: specify your variable name exactly (no regex) when using the '-w' option\n"); + result.SetStatus(eReturnStatusFailed); + return false; + } + + // Things have checked out ok... + // m_option_watchpoint.watch_mode specifies the mode for watching. + } if (command.GetArgumentCount() > 0) { VariableList regex_var_list; Modified: lldb/trunk/source/Interpreter/OptionGroupWatchpoint.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/OptionGroupWatchpoint.cpp?rev=139524&r1=139523&r2=139524&view=diff ============================================================================== --- lldb/trunk/source/Interpreter/OptionGroupWatchpoint.cpp (original) +++ lldb/trunk/source/Interpreter/OptionGroupWatchpoint.cpp Mon Sep 12 14:12:06 2011 @@ -55,9 +55,10 @@ switch (short_option) { case 'w': { - watch_variable = false; OptionEnumValueElement *enum_values = g_option_table[option_idx].enum_values; watch_mode = (WatchMode) Args::StringToOptionEnum(option_arg, enum_values, 0, &watch_variable); + if (!watch_variable) + error.SetErrorStringWithFormat("Invalid option arg for '-w': '%s'.\n", option_arg); break; } default: From gclayton at apple.com Mon Sep 12 14:56:07 2011 From: gclayton at apple.com (Greg Clayton) Date: Mon, 12 Sep 2011 19:56:07 -0000 Subject: [Lldb-commits] [lldb] r139529 - /lldb/trunk/www/lldb-gdb.html Message-ID: <20110912195607.61A092A6C12C@llvm.org> Author: gclayton Date: Mon Sep 12 14:56:07 2011 New Revision: 139529 URL: http://llvm.org/viewvc/llvm-project?rev=139529&view=rev Log: Added GDB/LLDB commands for the "target stop-hook add" command. Modified: lldb/trunk/www/lldb-gdb.html Modified: lldb/trunk/www/lldb-gdb.html URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/www/lldb-gdb.html?rev=139529&r1=139528&r2=139529&view=diff ============================================================================== --- lldb/trunk/www/lldb-gdb.html (original) +++ lldb/trunk/www/lldb-gdb.html Mon Sep 12 14:56:07 2011 @@ -190,6 +190,43 @@ + Display a the variable "argc" and "argv" everytime you stop. + + + (lldb) target stop-hook add --one-liner "frame variable argc argv"
+ + + (gdb) display argc
+ (gdb) display argv
+ + + + Display a the variable "argc" and "argv" only when you stop in the function named main. + + + (lldb) target stop-hook add --name main --one-liner "frame variable argc argv"
+ + + + Display the variable "*this" only when you stop in c class named MyClass. + + + (lldb) target stop-hook add --classname MyClass --one-liner "frame variable *this"
+ + + + Backtrace and disassemble every time you stop. + + + (lldb) target stop-hook add"
+ Enter your stop hook command(s). Type 'DONE' to end.
+ > bt
+ > disassemble --pc
+ > DONE
+ Stop hook #1 added.
+ + +

From johnny.chen at apple.com Mon Sep 12 15:25:57 2011 From: johnny.chen at apple.com (Johnny Chen) Date: Mon, 12 Sep 2011 20:25:57 -0000 Subject: [Lldb-commits] [lldb] r139534 - /lldb/trunk/source/Commands/CommandObjectFrame.cpp Message-ID: <20110912202558.08F202A6C12C@llvm.org> Author: johnny Date: Mon Sep 12 15:25:57 2011 New Revision: 139534 URL: http://llvm.org/viewvc/llvm-project?rev=139534&view=rev Log: Fix indentations, add some comments. Modified: lldb/trunk/source/Commands/CommandObjectFrame.cpp Modified: lldb/trunk/source/Commands/CommandObjectFrame.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectFrame.cpp?rev=139534&r1=139533&r2=139534&view=diff ============================================================================== --- lldb/trunk/source/Commands/CommandObjectFrame.cpp (original) +++ lldb/trunk/source/Commands/CommandObjectFrame.cpp Mon Sep 12 15:25:57 2011 @@ -499,10 +499,10 @@ uint32_t expr_path_options = StackFrame::eExpressionPathOptionCheckPtrVsMember; lldb::VariableSP var_sp; valobj_sp = frame_sp->GetValueForVariableExpressionPath (name_cstr, - m_varobj_options.use_dynamic, - expr_path_options, - var_sp, - error); + m_varobj_options.use_dynamic, + expr_path_options, + var_sp, + error); if (valobj_sp) { if (m_option_variable.format != eFormatDefault) @@ -530,7 +530,7 @@ } } } - else + else // No command arg specified. Use variable_list, instead. { const uint32_t num_variables = variable_list->GetSize(); From gclayton at apple.com Mon Sep 12 18:21:58 2011 From: gclayton at apple.com (Greg Clayton) Date: Mon, 12 Sep 2011 23:21:58 -0000 Subject: [Lldb-commits] [lldb] r139557 - in /lldb/trunk/source: Expression/ Plugins/SymbolFile/DWARF/ Message-ID: <20110912232158.D13212A6C12C@llvm.org> Author: gclayton Date: Mon Sep 12 18:21:58 2011 New Revision: 139557 URL: http://llvm.org/viewvc/llvm-project?rev=139557&view=rev Log: Huge memory and performance improvements in the DWARF parser. Address ranges are now split up into two different tables: - one in DWARFDebugInfo that is compile unit specific - one in each DWARFCompileUnit that has exact function DIE offsets This helps keep the size of the aranges down since the main table will get uniqued and sorted and have consecutive ranges merged. We then only parse the compile unit one on demand once we have determined that a compile unit contains the address in question. We also now use the .debug_aranges section if there is one instead of always indexing the DWARF manually. NameToDIE now uses a UniqueCStringMap map instead of a std::map. std::map is very bulky as each node has 3 pointers and the key and value types. This gets our NameToDIE entry down to 12 bytes each instead of 48 which saves us a lot of memory when we have very large DWARF. DWARFDebugAranges now has a smaller footprint for each range it contains to save on memory. Modified: lldb/trunk/source/Expression/ClangUserExpression.cpp lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.h lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugAranges.cpp lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugAranges.h lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.cpp lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.h lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp lldb/trunk/source/Plugins/SymbolFile/DWARF/NameToDIE.cpp lldb/trunk/source/Plugins/SymbolFile/DWARF/NameToDIE.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 Modified: lldb/trunk/source/Expression/ClangUserExpression.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/ClangUserExpression.cpp?rev=139557&r1=139556&r2=139557&view=diff ============================================================================== --- lldb/trunk/source/Expression/ClangUserExpression.cpp (original) +++ lldb/trunk/source/Expression/ClangUserExpression.cpp Mon Sep 12 18:21:58 2011 @@ -79,6 +79,8 @@ void ClangUserExpression::ScanContext(ExecutionContext &exe_ctx) { + m_target = exe_ctx.target; + if (!exe_ctx.frame) return; @@ -87,8 +89,6 @@ if (!sym_ctx.function) return; - m_target = &exe_ctx.GetProcess()->GetTarget(); - clang::DeclContext *decl_context; if (sym_ctx.block && sym_ctx.block->GetInlinedFunctionInfo()) 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=139557&r1=139556&r2=139557&view=diff ============================================================================== --- lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp (original) +++ lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp Mon Sep 12 18:21:58 2011 @@ -30,16 +30,16 @@ extern int g_verbose; DWARFCompileUnit::DWARFCompileUnit(SymbolFileDWARF* dwarf2Data) : - m_dwarf2Data ( dwarf2Data ), - m_offset ( DW_INVALID_OFFSET ), - m_length ( 0 ), - m_version ( 0 ), - m_abbrevs ( NULL ), - m_addr_size ( DWARFCompileUnit::GetDefaultAddressSize() ), - m_base_addr ( 0 ), + m_dwarf2Data (dwarf2Data), + m_abbrevs (NULL), + m_user_data (NULL), m_die_array (), - m_aranges_ap (), - m_user_data ( NULL ) + m_func_aranges_ap (), + m_base_addr (0), + m_offset (DW_INVALID_OFFSET), + m_length (0), + m_version (0), + m_addr_size (DWARFCompileUnit::GetDefaultAddressSize()) { } @@ -53,7 +53,7 @@ m_addr_size = DWARFCompileUnit::GetDefaultAddressSize(); m_base_addr = 0; m_die_array.clear(); - m_aranges_ap.reset(); + m_func_aranges_ap.reset(); m_user_data = NULL; } @@ -324,6 +324,50 @@ g_default_addr_size = addr_size; } +void +DWARFCompileUnit::BuildAddressRangeTable (SymbolFileDWARF* dwarf2Data, + DWARFDebugAranges* debug_aranges, + bool clear_dies_if_already_not_parsed) +{ + // This function is usually called if there in no .debug_aranges section + // in order to produce a compile unit level set of address ranges that + // is accurate. If the DIEs weren't parsed, then we don't want all dies for + // all compile units to stay loaded when they weren't needed. So we can end + // up parsing the DWARF and then throwing them all away to keep memory usage + // down. + const bool clear_dies = ExtractDIEsIfNeeded (false) > 1; + + DIE()->BuildAddressRangeTable(dwarf2Data, this, debug_aranges); + + // Keep memory down by clearing DIEs if this generate function + // caused them to be parsed + if (clear_dies) + ClearDIEs (true); + +} + + +const DWARFDebugAranges & +DWARFCompileUnit::GetFunctionAranges () +{ + if (m_func_aranges_ap.get() == NULL) + { + m_func_aranges_ap.reset (new DWARFDebugAranges()); + Log *log = LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_ARANGES); + + if (log) + log->Printf ("DWARFCompileUnit::GetFunctionAranges() for \"%s/%s\" compile unit at 0x%8.8x", + m_dwarf2Data->GetObjectFile()->GetFileSpec().GetDirectory().GetCString(), + m_dwarf2Data->GetObjectFile()->GetFileSpec().GetFilename().GetCString(), + m_offset); + DIE()->BuildFunctionAddressRangeTable (m_dwarf2Data, this, m_func_aranges_ap.get()); + const bool minimize = false; + const uint32_t fudge_size = 0; + m_func_aranges_ap->Sort(minimize, fudge_size); + } + return *m_func_aranges_ap.get(); +} + bool DWARFCompileUnit::LookupAddress ( @@ -336,16 +380,13 @@ if (function_die_handle != NULL && DIE()) { - if (m_aranges_ap.get() == NULL) - { - m_aranges_ap.reset(new DWARFDebugAranges()); - m_die_array.front().BuildFunctionAddressRangeTable(m_dwarf2Data, this, m_aranges_ap.get()); - } + + const DWARFDebugAranges &func_aranges = GetFunctionAranges (); // Re-check the aranges auto pointer contents in case it was created above - if (m_aranges_ap.get() != NULL) + if (!func_aranges.IsEmpty()) { - *function_die_handle = GetDIEPtr(m_aranges_ap->FindAddress(address)); + *function_die_handle = GetDIEPtr(func_aranges.FindAddress(address)); if (*function_die_handle != NULL) { success = true; @@ -581,26 +622,20 @@ void -DWARFCompileUnit::Index -( - const uint32_t cu_idx, - NameToDIE& func_basenames, - NameToDIE& func_fullnames, - NameToDIE& func_methods, - NameToDIE& func_selectors, - NameToDIE& objc_class_selectors, - NameToDIE& globals, - NameToDIE& types, - NameToDIE& namespaces, - const DWARFDebugRanges *debug_ranges, - DWARFDebugAranges *aranges -) +DWARFCompileUnit::Index (const uint32_t cu_idx, + NameToDIE& func_basenames, + NameToDIE& func_fullnames, + NameToDIE& func_methods, + NameToDIE& func_selectors, + NameToDIE& objc_class_selectors, + NameToDIE& globals, + NameToDIE& types, + NameToDIE& namespaces) { const DataExtractor* debug_str = &m_dwarf2Data->get_debug_str_data(); const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (GetAddressByteSize()); - NameToDIE::Info die_info = { cu_idx, 0 }; DWARFDebugInfoEntry::const_iterator pos; DWARFDebugInfoEntry::const_iterator begin = m_die_array.begin(); DWARFDebugInfoEntry::const_iterator end = m_die_array.end(); @@ -640,9 +675,6 @@ bool has_address = false; bool has_location = false; bool is_global_or_static_variable = false; - dw_addr_t lo_pc = DW_INVALID_ADDRESS; - dw_addr_t hi_pc = DW_INVALID_ADDRESS; - DWARFDebugRanges::RangeList ranges; dw_offset_t specification_die_offset = DW_INVALID_OFFSET; const size_t num_attributes = die.GetAttributes(m_dwarf2Data, this, fixed_form_sizes, attributes); @@ -677,33 +709,8 @@ break; case DW_AT_low_pc: - has_address = true; - if (tag == DW_TAG_subprogram && attributes.ExtractFormValueAtIndex(m_dwarf2Data, i, form_value)) - { - lo_pc = form_value.Unsigned(); - } - break; - case DW_AT_high_pc: - has_address = true; - if (tag == DW_TAG_subprogram && attributes.ExtractFormValueAtIndex(m_dwarf2Data, i, form_value)) - { - hi_pc = form_value.Unsigned(); - } - break; - case DW_AT_ranges: - if (tag == DW_TAG_subprogram && attributes.ExtractFormValueAtIndex(m_dwarf2Data, i, form_value)) - { - if (debug_ranges) - { - debug_ranges->FindRanges(form_value.Unsigned(), ranges); - // All DW_AT_ranges are relative to the base address of the - // compile unit. We add the compile unit base address to make - // sure all the addresses are properly fixed up. - ranges.AddOffset(GetBaseAddress()); - } - } has_address = true; break; @@ -765,26 +772,8 @@ break; } } - - if (tag == DW_TAG_subprogram) - { - if (lo_pc != DW_INVALID_ADDRESS && hi_pc != DW_INVALID_ADDRESS) - { - aranges->AppendRange (m_offset, lo_pc, hi_pc); - } - else - { - for (uint32_t i=0, num_ranges = ranges.Size(); iAppendRange (m_offset, range->begin_offset, range->end_offset); - } - } - } } - die_info.die_idx = std::distance (begin, pos); - switch (tag) { case DW_TAG_subprogram: @@ -804,14 +793,14 @@ &objc_method_name, &objc_base_name)) { - objc_class_selectors.Insert(objc_class_name, die_info); + objc_class_selectors.Insert(objc_class_name, die.GetOffset()); - func_selectors.Insert (objc_method_name, die_info); + func_selectors.Insert (objc_method_name, die.GetOffset()); if (!objc_base_name.IsEmpty()) { - func_basenames.Insert (objc_base_name, die_info); - func_fullnames.Insert (objc_base_name, die_info); + func_basenames.Insert (objc_base_name, die.GetOffset()); + func_fullnames.Insert (objc_base_name, die.GetOffset()); } } } @@ -849,9 +838,9 @@ if (is_method) - func_methods.Insert (ConstString(name), die_info); + func_methods.Insert (ConstString(name), die.GetOffset()); else - func_basenames.Insert (ConstString(name), die_info); + func_basenames.Insert (ConstString(name), die.GetOffset()); } if (mangled_cstr) { @@ -862,9 +851,9 @@ if (name != mangled_cstr && ((mangled_cstr[0] == '_') || (::strcmp(name, mangled_cstr) != 0))) { Mangled mangled (mangled_cstr, true); - func_fullnames.Insert (mangled.GetMangledName(), die_info); + func_fullnames.Insert (mangled.GetMangledName(), die.GetOffset()); if (mangled.GetDemangledName()) - func_fullnames.Insert (mangled.GetDemangledName(), die_info); + func_fullnames.Insert (mangled.GetDemangledName(), die.GetOffset()); } } } @@ -874,7 +863,7 @@ if (has_address) { if (name) - func_basenames.Insert (ConstString(name), die_info); + func_basenames.Insert (ConstString(name), die.GetOffset()); if (mangled_cstr) { // Make sure our mangled name isn't the same string table entry @@ -884,9 +873,9 @@ if (name != mangled_cstr && ((mangled_cstr[0] == '_') || (::strcmp(name, mangled_cstr) != 0))) { Mangled mangled (mangled_cstr, true); - func_fullnames.Insert (mangled.GetMangledName(), die_info); + func_fullnames.Insert (mangled.GetMangledName(), die.GetOffset()); if (mangled.GetDemangledName()) - func_fullnames.Insert (mangled.GetDemangledName(), die_info); + func_fullnames.Insert (mangled.GetDemangledName(), die.GetOffset()); } } } @@ -903,19 +892,19 @@ case DW_TAG_typedef: if (name && is_declaration == false) { - types.Insert (ConstString(name), die_info); + types.Insert (ConstString(name), die.GetOffset()); } break; case DW_TAG_namespace: if (name) - namespaces.Insert (ConstString(name), die_info); + namespaces.Insert (ConstString(name), die.GetOffset()); break; case DW_TAG_variable: if (name && has_location && is_global_or_static_variable) { - globals.Insert (ConstString(name), die_info); + globals.Insert (ConstString(name), die.GetOffset()); // Be sure to include variables by their mangled and demangled // names if they have any since a variable can have a basename // "i", a mangled named "_ZN12_GLOBAL__N_11iE" and a demangled @@ -928,9 +917,9 @@ if (mangled_cstr && name != mangled_cstr && ((mangled_cstr[0] == '_') || (::strcmp(name, mangled_cstr) != 0))) { Mangled mangled (mangled_cstr, true); - globals.Insert (mangled.GetMangledName(), die_info); + globals.Insert (mangled.GetMangledName(), die.GetOffset()); if (mangled.GetDemangledName()) - globals.Insert (mangled.GetDemangledName(), die_info); + globals.Insert (mangled.GetDemangledName(), 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=139557&r1=139556&r2=139557&view=diff ============================================================================== --- lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.h (original) +++ lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.h Mon Sep 12 18:21:58 2011 @@ -7,11 +7,11 @@ // //===----------------------------------------------------------------------===// -#ifndef liblldb_DWARFCompileUnit_h_ +#ifndef SymbolFileDWARF_DWARFCompileUnit_h_ #define SymbolFileDWARF_DWARFCompileUnit_h_ -#include "SymbolFileDWARF.h" #include "DWARFDebugInfoEntry.h" +#include "SymbolFileDWARF.h" class NameToDIE; @@ -45,6 +45,9 @@ uint8_t GetAddressByteSize() const { return m_addr_size; } dw_addr_t GetBaseAddress() const { return m_base_addr; } void ClearDIEs(bool keep_compile_unit_die); + void BuildAddressRangeTable (SymbolFileDWARF* dwarf2Data, + DWARFDebugAranges* debug_aranges, + bool clear_dies_if_already_not_parsed); void SetBaseAddress(dw_addr_t base_addr) @@ -141,24 +144,22 @@ NameToDIE& objc_class_selectors, NameToDIE& globals, NameToDIE& types, - NameToDIE& namespaces, - const DWARFDebugRanges* debug_ranges, - DWARFDebugAranges *aranges); + NameToDIE& namespaces); + const DWARFDebugAranges & + GetFunctionAranges (); protected: SymbolFileDWARF* m_dwarf2Data; + const DWARFAbbreviationDeclarationSet *m_abbrevs; + void * m_user_data; + DWARFDebugInfoEntry::collection m_die_array; // The compile unit debug information entry item + std::auto_ptr m_func_aranges_ap; // A table similar to the .debug_aranges table, but this one points to the exact DW_TAG_subprogram DIEs + dw_addr_t m_base_addr; dw_offset_t m_offset; uint32_t m_length; uint16_t m_version; - const DWARFAbbreviationDeclarationSet* - m_abbrevs; uint8_t m_addr_size; - dw_addr_t m_base_addr; - DWARFDebugInfoEntry::collection - m_die_array; // The compile unit debug information entry item - std::auto_ptr m_aranges_ap; // A table similar to the .debug_aranges table, but this one points to the exact DW_TAG_subprogram DIEs - void * m_user_data; private: DISALLOW_COPY_AND_ASSIGN (DWARFCompileUnit); }; Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugAranges.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugAranges.cpp?rev=139557&r1=139556&r2=139557&view=diff ============================================================================== --- lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugAranges.cpp (original) +++ lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugAranges.cpp Mon Sep 12 18:21:58 2011 @@ -14,9 +14,11 @@ #include +#include "lldb/Core/Log.h" #include "lldb/Core/Stream.h" #include "lldb/Core/Timer.h" +#include "LogChannelDWARF.h" #include "SymbolFileDWARF.h" #include "DWARFDebugInfo.h" #include "DWARFCompileUnit.h" @@ -73,7 +75,7 @@ for (uint32_t i=0; (arange_desc_ptr = set.GetDescriptor(i)) != NULL; ++i) { range.lo_pc = arange_desc_ptr->address; - range.hi_pc = arange_desc_ptr->address + arange_desc_ptr->length; + range.length = arange_desc_ptr->length; // Insert each item in increasing address order so binary searching // can later be done! @@ -90,7 +92,7 @@ static void PrintRange(const DWARFDebugAranges::Range& range) { // Cast the address values in case the address type is compiled as 32 bit - printf("0x%8.8x: [0x%8.8llx - 0x%8.8llx)\n", range.offset, (long long)range.lo_pc, (long long)range.hi_pc); + printf("0x%8.8x: [0x%8.8llx - 0x%8.8llx)\n", range.offset, (long long)range.lo_pc, (long long)range.hi_pc()); } //---------------------------------------------------------------------- @@ -139,13 +141,14 @@ DWARFDebugInfo* debug_info = dwarf2Data->DebugInfo(); if (debug_info) { + const bool clear_dies_if_already_not_parsed = true; uint32_t cu_idx = 0; const uint32_t num_compile_units = dwarf2Data->GetNumCompileUnits(); for (cu_idx = 0; cu_idx < num_compile_units; ++cu_idx) { DWARFCompileUnit* cu = debug_info->GetCompileUnitAtIndex(cu_idx); if (cu) - cu->DIE()->BuildAddressRangeTable(dwarf2Data, cu, this); + cu->BuildAddressRangeTable(dwarf2Data, this, clear_dies_if_already_not_parsed); } } return !IsEmpty(); @@ -153,17 +156,23 @@ void -DWARFDebugAranges::Print() const +DWARFDebugAranges::Dump (Log *log) const { - puts("\n\nDWARFDebugAranges address range list is:\n"); - for_each(m_aranges.begin(), m_aranges.end(), PrintRange); + if (log == NULL) + return; + const uint32_t num_ranges = NumRanges(); + for (uint32_t i = 0; i < num_ranges; ++i) + { + const Range &range = m_aranges[i]; + log->Printf ("0x%8.8x: [0x%8.8llx - 0x%8.8llx)", range.offset, (uint64_t)range.lo_pc, (uint64_t)range.hi_pc()); + } } void DWARFDebugAranges::Range::Dump(Stream *s) const { - s->Printf("{0x%8.8x}: [0x%8.8llx - 0x%8.8llx)\n", offset, lo_pc, hi_pc); + s->Printf("{0x%8.8x}: [0x%8.8llx - 0x%8.8llx)\n", offset, lo_pc, hi_pc()); } //---------------------------------------------------------------------- @@ -232,57 +241,14 @@ // debug_ranges.AppendMax64(0, addr_size); // //} -// -//---------------------------------------------------------------------- -// ArangeSetContainsAddress -//---------------------------------------------------------------------- -class ArangeSetContainsAddress -{ -public: - ArangeSetContainsAddress (dw_addr_t the_address) : address(the_address), offset(DW_INVALID_OFFSET) {} - bool operator() (const DWARFDebugArangeSet& set) - { - offset = set.FindAddress(address); - return (offset != DW_INVALID_OFFSET); - } - const dw_addr_t address; - dw_offset_t offset; -}; - - -//---------------------------------------------------------------------- -// InsertRange -//---------------------------------------------------------------------- -void -DWARFDebugAranges::InsertRange(dw_offset_t offset, dw_addr_t low_pc, dw_addr_t high_pc) -{ - // Insert each item in increasing address order so binary searching - // can later be done! - DWARFDebugAranges::Range range(low_pc, high_pc, offset); - InsertRange(range); -} - -//---------------------------------------------------------------------- -// InsertRange -//---------------------------------------------------------------------- -void -DWARFDebugAranges::InsertRange(const DWARFDebugAranges::Range& range) -{ - // Insert each item in increasing address order so binary searching - // can later be done! - RangeColl::iterator insert_pos = lower_bound(m_aranges.begin(), m_aranges.end(), range, RangeLessThan); - m_aranges.insert(insert_pos, range); -} - - void DWARFDebugAranges::AppendRange (dw_offset_t offset, dw_addr_t low_pc, dw_addr_t high_pc) { if (!m_aranges.empty()) { - if (m_aranges.back().offset == offset && m_aranges.back().hi_pc == low_pc) + if (m_aranges.back().offset == offset && m_aranges.back().hi_pc() == low_pc) { - m_aranges.back().hi_pc = high_pc; + m_aranges.back().set_hi_pc(high_pc); return; } } @@ -290,49 +256,83 @@ } void -DWARFDebugAranges::Sort() +DWARFDebugAranges::Sort (bool minimize, uint32_t n) { Timer scoped_timer(__PRETTY_FUNCTION__, "%s this = %p", __PRETTY_FUNCTION__, this); + Log *log = LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_ARANGES); + const size_t orig_arange_size = m_aranges.size(); + if (log) + { + log->Printf ("DWARFDebugAranges::Sort(minimize = %u, n = %u) with %zu entries", minimize, n, orig_arange_size); + Dump (log); + } + + // Size of one? If so, no sorting is needed + if (orig_arange_size <= 1) + return; // Sort our address range entries std::stable_sort (m_aranges.begin(), m_aranges.end(), RangeLessThan); - // Merge all neighbouring ranges into a single range and remember the - // indices of all ranges merged. - const size_t old_size = m_aranges.size(); - std::vector merged; - for (size_t merge, cursor = 1; cursor < old_size; ++cursor) - { - merge = cursor - 1; - Range &r1 = m_aranges[merge]; - Range &r2 = m_aranges[cursor]; - - if (r1.hi_pc == r2.lo_pc && r1.offset == r2.offset) - { - r2.lo_pc = r1.lo_pc; - merged.push_back(merge); - } - } + + if (!minimize) + return; - if (merged.empty()) + // Most address ranges are contiguous from function to function + // so our new ranges will likely be smaller. We calculate the size + // of the new ranges since although std::vector objects can be resized, + // the will never reduce their allocated block size and free any excesss + // memory, so we might as well start a brand new collection so it is as + // small as possible. + + // First calculate the size of the new minimal arange vector + // so we don't have to do a bunch of re-allocations as we + // copy the new minimal stuff over to the new collection + size_t minimal_size = 1; + size_t i; + for (i=1; iPrintf ("DWARFDebugAranges::Sort() %zu entries after minimizing (%zu entries combined for %zu bytes saved)", + m_aranges.size(), delta, delta * sizeof(Range)); + Dump (log); + } } //---------------------------------------------------------------------- @@ -348,7 +348,7 @@ DWARFDebugAranges::RangeCollIterator end = m_aranges.end(); DWARFDebugAranges::RangeCollIterator pos = lower_bound(begin, end, range, RangeLessThan); - if ((pos != end) && (pos->lo_pc <= address && address < pos->hi_pc)) + if ((pos != end) && (pos->lo_pc <= address && address < pos->hi_pc())) { // printf("FindAddress(1) found 0x%8.8x in compile unit: 0x%8.8x\n", address, pos->offset); return pos->offset; @@ -356,7 +356,7 @@ else if (pos != begin) { --pos; - if ((pos->lo_pc <= address) && (address < pos->hi_pc)) + if ((pos->lo_pc <= address) && (address < pos->hi_pc())) { // printf("FindAddress(2) found 0x%8.8x in compile unit: 0x%8.8x\n", address, pos->offset); return (*pos).offset; @@ -384,10 +384,10 @@ { if ((pos != begin) && (pos->lo_pc != next_addr)) return false; - next_addr = pos->hi_pc; + next_addr = pos->hi_pc(); } lo_pc = m_aranges.front().lo_pc; // We checked for empty at the start of function so front() will be valid - hi_pc = m_aranges.back().hi_pc; // We checked for empty at the start of function so back() will be valid + hi_pc = m_aranges.back().hi_pc(); // We checked for empty at the start of function so back() will be valid return true; } @@ -398,7 +398,7 @@ return false; lo_pc = m_aranges.front().lo_pc; // We checked for empty at the start of function so front() will be valid - hi_pc = m_aranges.back().hi_pc; // We checked for empty at the start of function so back() will be valid + hi_pc = m_aranges.back().hi_pc(); // We checked for empty at the start of function so back() will be valid return true; } Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugAranges.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugAranges.h?rev=139557&r1=139556&r2=139557&view=diff ============================================================================== --- lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugAranges.h (original) +++ lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugAranges.h Mon Sep 12 18:21:58 2011 @@ -7,7 +7,7 @@ // //===----------------------------------------------------------------------===// -#ifndef liblldb_DWARFDebugAranges_h_ +#ifndef SymbolFileDWARF_DWARFDebugAranges_h_ #define SymbolFileDWARF_DWARFDebugAranges_h_ #include "DWARFDebugArangeSet.h" @@ -20,35 +20,60 @@ public: struct Range { - Range( - dw_addr_t _lo_pc = DW_INVALID_ADDRESS, - dw_addr_t _hi_pc = DW_INVALID_ADDRESS, - dw_offset_t _offset = DW_INVALID_OFFSET) : - lo_pc(_lo_pc), - hi_pc(_hi_pc), - offset(_offset) + explicit + Range (dw_addr_t lo = DW_INVALID_ADDRESS, + dw_addr_t hi = DW_INVALID_ADDRESS, + dw_offset_t off = DW_INVALID_OFFSET) : + lo_pc (lo), + length (hi-lo), + offset (off) { } void Clear() { - lo_pc = hi_pc = DW_INVALID_ADDRESS; + lo_pc = DW_INVALID_ADDRESS; + length = 0; offset = DW_INVALID_OFFSET; } - bool ValidRange() const + void + set_hi_pc (dw_addr_t hi_pc) { - return hi_pc > lo_pc; + if (hi_pc == DW_INVALID_ADDRESS || hi_pc <= lo_pc) + length = 0; + else + length = hi_pc - lo_pc; + } + dw_addr_t + hi_pc() const + { + if (length) + return lo_pc + length; + return DW_INVALID_ADDRESS; + } + bool + ValidRange() const + { + return length > 0; + } + + static bool + SortedOverlapCheck (const Range& curr_range, const Range& next_range, uint32_t n) + { + if (curr_range.offset != next_range.offset) + return false; + return curr_range.hi_pc() + n >= next_range.lo_pc; } bool Contains(const Range& range) const { - return lo_pc <= range.lo_pc && range.hi_pc <= hi_pc; + return lo_pc <= range.lo_pc && range.hi_pc() <= hi_pc(); } void Dump(lldb_private::Stream *s) const; dw_addr_t lo_pc; // Start of address range - dw_addr_t hi_pc; // End of address range (not including this address) + uint32_t length; // End of address range (not including this address) dw_offset_t offset; // Offset of the compile unit or die }; @@ -59,12 +84,10 @@ bool GetMaxRange(dw_addr_t& lo_pc, dw_addr_t& hi_pc) const; bool Extract(const lldb_private::DataExtractor &debug_aranges_data); bool Generate(SymbolFileDWARF* dwarf2Data); - void InsertRange (dw_offset_t cu_offset, dw_addr_t low_pc, dw_addr_t high_pc); - void InsertRange (const DWARFDebugAranges::Range& range); // Use append range multiple times and then call sort void AppendRange (dw_offset_t cu_offset, dw_addr_t low_pc, dw_addr_t high_pc); - void Sort(); + void Sort (bool minimize, uint32_t n); const Range* RangeAtIndex(uint32_t idx) const { @@ -72,7 +95,7 @@ return &m_aranges[idx]; return NULL; } - void Print() const; + void Dump (lldb_private::Log *log) const; dw_offset_t FindAddress(dw_addr_t address) const; bool IsEmpty() const { return m_aranges.empty(); } // void Dump(lldb_private::Stream *s); Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.cpp?rev=139557&r1=139556&r2=139557&view=diff ============================================================================== --- lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.cpp (original) +++ lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.cpp Mon Sep 12 18:21:58 2011 @@ -14,12 +14,15 @@ #include "lldb/Core/RegularExpression.h" #include "lldb/Core/Stream.h" +#include "lldb/Symbol/ObjectFile.h" +#include "DWARFDebugAranges.h" #include "DWARFDebugInfo.h" #include "DWARFCompileUnit.h" #include "DWARFDebugAranges.h" #include "DWARFDebugInfoEntry.h" #include "DWARFFormValue.h" +#include "LogChannelDWARF.h" using namespace lldb_private; using namespace std; @@ -29,7 +32,8 @@ //---------------------------------------------------------------------- DWARFDebugInfo::DWARFDebugInfo() : m_dwarf2Data(NULL), - m_compile_units() + m_compile_units(), + m_cu_aranges_ap () { } @@ -43,25 +47,60 @@ m_compile_units.clear(); } -//---------------------------------------------------------------------- -// BuildDIEAddressRangeTable -//---------------------------------------------------------------------- -bool -DWARFDebugInfo::BuildFunctionAddressRangeTable(DWARFDebugAranges* debug_aranges) + +DWARFDebugAranges & +DWARFDebugInfo::GetCompileUnitAranges () { - const uint32_t num_compile_units = GetNumCompileUnits(); - uint32_t idx; - for (idx = 0; idx < num_compile_units; ++idx) + if (m_cu_aranges_ap.get() == NULL && m_dwarf2Data) { - DWARFCompileUnit* cu = GetCompileUnitAtIndex (idx); - if (cu) + Log *log = LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_ARANGES); + + m_cu_aranges_ap.reset (new DWARFDebugAranges()); + const DataExtractor &debug_aranges_data = m_dwarf2Data->get_debug_aranges_data(); + if (debug_aranges_data.GetByteSize() > 0) { - cu->DIE()->BuildFunctionAddressRangeTable(m_dwarf2Data, cu, debug_aranges); + if (log) + log->Printf ("DWARFDebugInfo::GetCompileUnitAranges() for \"%s/%s\" from .debug_aranges", + m_dwarf2Data->GetObjectFile()->GetFileSpec().GetDirectory().GetCString(), + m_dwarf2Data->GetObjectFile()->GetFileSpec().GetFilename().GetCString()); + m_cu_aranges_ap->Extract (debug_aranges_data); + + } + else + { + if (log) + log->Printf ("DWARFDebugInfo::GetCompileUnitAranges() for \"%s/%s\" by parsing", + m_dwarf2Data->GetObjectFile()->GetFileSpec().GetDirectory().GetCString(), + m_dwarf2Data->GetObjectFile()->GetFileSpec().GetFilename().GetCString()); + const uint32_t num_compile_units = GetNumCompileUnits(); + uint32_t idx; + const bool clear_dies_if_already_not_parsed = true; + for (idx = 0; idx < num_compile_units; ++idx) + { + DWARFCompileUnit* cu = GetCompileUnitAtIndex(idx); + if (cu) + cu->BuildAddressRangeTable (m_dwarf2Data, m_cu_aranges_ap.get(), clear_dies_if_already_not_parsed); + } } + + // Sort with a fudge factor of 16 to make sure if we have a lot + // of functions in the compile unit whose end address if followed + // a start address that is "fudge_size" bytes close, it will combine + // the arange entries. This currently happens a lot on x86_64. This + // will help reduce the size of the aranges since sort will sort all + // of them and combine aranges that are consecutive for ranges in the + // same compile unit and we really don't need it to be all that + // accurate since we will get exact accuracy when we search the + // actual compile unit aranges which point to the exact range and + // the exact DIE offset of the function. + const bool minimize = true; + const uint32_t fudge_factor = 16; + m_cu_aranges_ap->Sort (minimize, fudge_factor); } - return !debug_aranges->IsEmpty(); + return *m_cu_aranges_ap.get(); } + //---------------------------------------------------------------------- // LookupAddress //---------------------------------------------------------------------- @@ -80,28 +119,9 @@ cu_sp = GetCompileUnit(hint_die_offset); else { - // Get a non const version of the address ranges - DWARFDebugAranges* debug_aranges = ((SymbolFileDWARF*)m_dwarf2Data)->DebugAranges(); - - if (debug_aranges != NULL) - { - // If we have an empty address ranges section, lets build a sorted - // table ourselves by going through all of the debug information so we - // can do quick subsequent searches. - - if (debug_aranges->IsEmpty()) - { - const uint32_t num_compile_units = GetNumCompileUnits(); - uint32_t idx; - for (idx = 0; idx < num_compile_units; ++idx) - { - DWARFCompileUnit* cu = GetCompileUnitAtIndex(idx); - if (cu) - cu->DIE()->BuildAddressRangeTable(m_dwarf2Data, cu, debug_aranges); - } - } - cu_sp = GetCompileUnit(debug_aranges->FindAddress(address)); - } + DWARFDebugAranges &cu_aranges = GetCompileUnitAranges (); + const dw_offset_t cu_offset = cu_aranges.FindAddress (address); + cu_sp = GetCompileUnit(cu_offset); } if (cu_sp.get()) @@ -613,7 +633,7 @@ range.lo_pc = die->GetAttributeValueAsUnsigned(dwarf2Data, cu, DW_AT_low_pc, DW_INVALID_ADDRESS); if (range.lo_pc != DW_INVALID_ADDRESS) { - range.hi_pc = die->GetAttributeValueAsUnsigned(dwarf2Data, cu, DW_AT_high_pc, DW_INVALID_ADDRESS); + range.set_hi_pc (die->GetAttributeValueAsUnsigned(dwarf2Data, cu, DW_AT_high_pc, DW_INVALID_ADDRESS)); if (s->GetVerbose()) { s->Printf("\n CU "); @@ -636,8 +656,8 @@ range.lo_pc = die->GetAttributeValueAsUnsigned(dwarf2Data, cu, DW_AT_low_pc, DW_INVALID_ADDRESS); if (range.lo_pc != DW_INVALID_ADDRESS) { - range.hi_pc = die->GetAttributeValueAsUnsigned(dwarf2Data, cu, DW_AT_high_pc, DW_INVALID_ADDRESS); - if (range.hi_pc != DW_INVALID_ADDRESS) + range.set_hi_pc (die->GetAttributeValueAsUnsigned(dwarf2Data, cu, DW_AT_high_pc, DW_INVALID_ADDRESS)); + if (range.hi_pc() != DW_INVALID_ADDRESS) { range.offset = die->GetOffset(); bool valid = range.ValidRange(); @@ -651,10 +671,6 @@ s->Printf(" ERROR: Invalid address range for function."); } } - - // Only add to our subroutine ranges if our compile unit has a valid address range - // if (valid && verifyInfo->die_ranges.size() >= 2 && verifyInfo->die_ranges[1].range.ValidRange()) - // verifyInfo->subroutine_ranges.InsertRange(range); } } break; @@ -665,8 +681,8 @@ range.lo_pc = die->GetAttributeValueAsUnsigned(dwarf2Data, cu, DW_AT_low_pc, DW_INVALID_ADDRESS); if (range.lo_pc != DW_INVALID_ADDRESS) { - range.hi_pc = die->GetAttributeValueAsUnsigned(dwarf2Data, cu, DW_AT_high_pc, DW_INVALID_ADDRESS); - if (range.hi_pc != DW_INVALID_ADDRESS) + range.set_hi_pc (die->GetAttributeValueAsUnsigned(dwarf2Data, cu, DW_AT_high_pc, DW_INVALID_ADDRESS)); + if (range.hi_pc() != DW_INVALID_ADDRESS) { range.offset = die->GetOffset(); bool valid = range.ValidRange(); Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.h?rev=139557&r1=139556&r2=139557&view=diff ============================================================================== --- lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.h (original) +++ lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.h Mon Sep 12 18:21:58 2011 @@ -7,7 +7,7 @@ // //===----------------------------------------------------------------------===// -#ifndef liblldb_DWARFDebugInfo_h_ +#ifndef SymbolFileDWARF_DWARFDebugInfo_h_ #define SymbolFileDWARF_DWARFDebugInfo_h_ #include @@ -36,7 +36,6 @@ DWARFDebugInfo(); void SetDwarfData(SymbolFileDWARF* dwarf2Data); - bool BuildFunctionAddressRangeTable(DWARFDebugAranges* debug_aranges); bool LookupAddress( const dw_addr_t address, @@ -70,12 +69,14 @@ eDumpFlag_ShowAncestors = (1<<2) // Show all parent DIEs when dumping single DIEs }; + DWARFDebugAranges & + GetCompileUnitAranges (); protected: SymbolFileDWARF* m_dwarf2Data; typedef std::vector CompileUnitColl; - CompileUnitColl m_compile_units; + std::auto_ptr m_cu_aranges_ap; // A quick address to compile unit table private: // All parsing needs to be done partially any managed by this class as accessors are called. Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp?rev=139557&r1=139556&r2=139557&view=diff ============================================================================== --- lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp (original) +++ lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp Mon Sep 12 18:21:58 2011 @@ -1843,7 +1843,7 @@ if (hi_pc != DW_INVALID_ADDRESS) { /// printf("BuildAddressRangeTable() 0x%8.8x: %30s: [0x%8.8x - 0x%8.8x)\n", m_offset, DW_TAG_value_to_name(tag), lo_pc, hi_pc); - debug_aranges->InsertRange(cu->GetOffset(), lo_pc, hi_pc); + debug_aranges->AppendRange (cu->GetOffset(), lo_pc, hi_pc); } } @@ -1885,7 +1885,7 @@ if (hi_pc != DW_INVALID_ADDRESS) { // printf("BuildAddressRangeTable() 0x%8.8x: [0x%16.16llx - 0x%16.16llx)\n", m_offset, lo_pc, hi_pc); // DEBUG ONLY - debug_aranges->InsertRange(GetOffset(), lo_pc, hi_pc); + debug_aranges->AppendRange (GetOffset(), lo_pc, hi_pc); } } Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/NameToDIE.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/NameToDIE.cpp?rev=139557&r1=139556&r2=139557&view=diff ============================================================================== --- lldb/trunk/source/Plugins/SymbolFile/DWARF/NameToDIE.cpp (original) +++ lldb/trunk/source/Plugins/SymbolFile/DWARF/NameToDIE.cpp Mon Sep 12 18:21:58 2011 @@ -23,335 +23,53 @@ using namespace lldb_private; void -NameToDIE::Insert (const ConstString& name, const Info &info) +NameToDIE::Finalize() { - m_collection.insert (std::make_pair(name.AsCString(), info)); + m_map.Sort (); + m_map.SizeToFit (); } -size_t -NameToDIE::Find (const ConstString &name, std::vector &info_array) const +void +NameToDIE::Insert (const ConstString& name, uint32_t die_offset) { - const char *name_cstr = name.AsCString(); - const size_t initial_info_array_size = info_array.size(); - collection::const_iterator pos, end = m_collection.end(); - for (pos = m_collection.lower_bound (name_cstr); pos != end && pos->first == name_cstr; ++pos) - { - info_array.push_back (pos->second); - } - return info_array.size() - initial_info_array_size; + m_map.Append(name.GetCString(), die_offset); } size_t -NameToDIE::Find (const RegularExpression& regex, std::vector &info_array) const +NameToDIE::Find (const ConstString &name, DIEArray &info_array) const { - const size_t initial_info_array_size = info_array.size(); - collection::const_iterator pos, end = m_collection.end(); - for (pos = m_collection.begin(); pos != end; ++pos) - { - if (regex.Execute(pos->first)) - info_array.push_back (pos->second); - } - return info_array.size() - initial_info_array_size; + return m_map.GetValues (name.GetCString(), info_array); } size_t -NameToDIE::FindAllEntriesForCompileUnitWithIndex (const uint32_t cu_idx, std::vector &info_array) const +NameToDIE::Find (const RegularExpression& regex, DIEArray &info_array) const { - const size_t initial_info_array_size = info_array.size(); - collection::const_iterator pos, end = m_collection.end(); - for (pos = m_collection.begin(); pos != end; ++pos) - { - if (cu_idx == pos->second.cu_idx) - info_array.push_back (pos->second); - } - return info_array.size() - initial_info_array_size; + return m_map.GetValues (regex, info_array); } -void -NameToDIE::Dump (Stream *s) -{ - collection::const_iterator pos, end = m_collection.end(); - for (pos = m_collection.begin(); pos != end; ++pos) - { - s->Printf("%p: 0x%8.8x 0x%8.8x \"%s\"\n", pos->first, pos->second.cu_idx, pos->second.die_idx, pos->first); +size_t +NameToDIE::FindAllEntriesForCompileUnit (uint32_t cu_offset, + uint32_t cu_end_offset, + DIEArray &info_array) const +{ + const size_t initial_size = info_array.size(); + const uint32_t size = m_map.GetSize(); + for (uint32_t i=0; i die_array; -}; - -typedef std::vector DIEArray; -typedef std::map NameToDIEArrayMap; - -struct HashBucketEntryCStr +void +NameToDIE::Dump (Stream *s) { - uint32_t - GetByteSize () const + const uint32_t size = m_map.GetSize(); + for (uint32_t i=0; isecond.size() + 1); - } - return byte_size; + const char *cstr = m_map.GetCStringAtIndex(i); + s->Printf("%p: {0x%8.8x} \"%s\"\n", cstr, m_map.GetValueAtIndexUnchecked(i), cstr); } - - NameToDIEArrayMap name_to_die; -}; - -static uint32_t -closest_power_2_less_than_n (uint32_t n) -{ - if (n) - return 0x80000000u >> __builtin_clz (n); - return 0; -} - -typedef struct HashEntry HashEntryType; - -void -NameToDIE::Hash (Stream *s, SymbolFileDWARF *dwarf) -{ -// if (m_collection.empty()) -// return; -// -// typedef std::vector hash_collection; -// hash_collection hash_entries; -// collection::const_iterator pos, end = m_collection.end(); -// for (pos = m_collection.begin(); pos != end; ++pos) -// { -// HashEntry entry = { dl_new_hash (pos->first), pos->second.cu_idx, pos->second.die_idx, pos->first }; -// hash_entries.push_back (entry); -// } -// -//// const DataExtractor &debug_str_data = dwarf->get_debug_str_data(); -// -//// uint32_t collisions = 0; -//// for (i=1; iPrintf("count = %u, collisions = %u\n", hash_entries_size, collisions); -// -//// for (i=0; iPrintf("0x%8.8x: cu = %8u, die = %8u, name = '%s'\n", -//// hash_entries[i].hash, -//// hash_entries[i].cu_idx, -//// hash_entries[i].die_idx, -//// hash_entries[i].name); -// DWARFDebugInfo *debug_info = dwarf->DebugInfo(); -// -// uint32_t num_buckets; -// if (hash_entries_size > 1024) -// num_buckets = closest_power_2_less_than_n (hash_entries_size/16); -// else if (hash_entries_size > 128) -// num_buckets = closest_power_2_less_than_n (hash_entries_size/8); -// else -// num_buckets = closest_power_2_less_than_n (hash_entries_size/4); -// if (num_buckets == 0) -// num_buckets = 1; -// -// //for (uint32_t power_2 = 0x10; power_2 <= hash_entries_size; power_2 <<= 1) -// { -//// if (num_buckets > 0x10 && num_buckets > hash_entries_size) -//// break; -// -// typedef std::vector uint32_array; -// typedef std::map HashBucketEntryMap; -// std::vector hash_buckets; -// hash_buckets.resize(num_buckets); -// -// uint32_t bucket_entry_empties = 0; -// uint32_t bucket_entry_single = 0; -// uint32_t bucket_entry_collisions = 0; -// uint32_t names_entry_single = 0; -// uint32_t names_entry_collisions = 0; -// //StreamString hash_file_data(Stream::eBinary, dwarf->GetObjectFile()->GetAddressByteSize(), dwarf->GetObjectFile()->GetByteSize()); -// -// // Write hash table header -//// hash_file_data.PutHex32 (1); // Version -//// hash_file_data.PutHex32 (4); // Sizeof bucket data -//// hash_file_data.PutHex32 (num_buckets); -//// hash_file_data.PutHex32 (0); // Flags -// -// s->Printf("HashHeader = { version = %u, bucket_info_size = %u, bucket_count = %u, flags = 0x%8.8x }\n", 1, (uint32_t)sizeof(HashBucketInfo), num_buckets, 0); -// -// for (i=0; iGetCompileUnitAtIndex (hash_entries[i].cu_idx); -// cu->ExtractDIEsIfNeeded(false); -// DWARFDebugInfoEntry *die = cu->GetDIEAtIndexUnchecked(hash_entries[i].die_idx); -// hash_buckets[bucket_idx][hash].name_to_die[hash_entries[i].name].push_back(die->GetOffset()); -// } -// uint32_t byte_size = sizeof(HashHeader); // Header -// uint32_t data_offset = 0; -// uint32_t num_bucket_entries; -// uint32_t bucket_data_size; -// // Now for each bucket we write the offset to the data for each bucket -// // The offset is currently a zero based offset from the end of this table -// // which is header.num_buckets * sizeof(uint32_t) long. -// for (i=0; ifirst) + pos->second.GetByteSize(); -// } -// if (bucket_data_size > 0) -// { -// // Offset to bucket data -//// hash_file_data.PutHex32 (data_offset); -// s->Printf("bucket[%u] {0x%8.8x}\n", i, data_offset); -// data_offset += bucket_data_size; -// } -// else -// { -// // Invalid offset that indicates an empty bucket -//// hash_file_data.PutHex32 (UINT32_MAX); -// s->Printf("bucket[%u] {0xFFFFFFFF}\n", i); -// ++bucket_entry_empties; -// } -// } -// -// // Now we write the bucket data for each bucket that corresponds to each bucket -// // offset from above. -// data_offset = 0; -// uint32_t total_num_name_entries = 0; -// uint32_t total_num_bucket_entries = 0; -// uint32_t total_non_empty_buckets = 0; -// for (i=0; iPrintf("0x%8.8x: BucketEntry:\n", data_offset, num_bucket_entries); -// bucket_data_size = 0; -// uint32_t num_bucket_entries = 0; -// HashBucketEntryMap::const_iterator pos, end = bucket_entry.end(); -// for (pos = bucket_entry.begin(); pos != end; ++pos) -// { -// ++num_bucket_entries; -// uint32_t hash_data_len = pos->second.GetByteSize(); -// s->Printf(" hash = 0x%8.8x, length = 0x%8.8x:\n", pos->first, hash_data_len); -//// hash_file_data.PutHex32 (pos->first); // Write the hash -//// hash_file_data.PutHex32 (hash_data_len); // The length of the data for this hash not including the length itself -// -// const HashBucketEntryCStr &hash_entry = pos->second; -// uint32_t num_name_entries = 0; -// NameToDIEArrayMap::const_iterator name_pos, name_end = hash_entry.name_to_die.end(); -// for (name_pos = hash_entry.name_to_die.begin(); name_pos != name_end; ++name_pos) -// { -// ++num_name_entries; -// ++total_num_name_entries; -// s->Printf(" name = %p '%s'\n", name_pos->first, name_pos->first); -//// hash_file_data.PutHex32 (pos->first); // Write the hash -//// hash_file_data.PutHex32 (hash_data_len); // The length of the data for this hash not including the length itself -// -// -// const uint32_t num_dies = name_pos->second.size(); -// s->Printf(" dies[%u] = { ", num_dies); -// for (uint32_t j=0; j < num_dies; ++j) -// s->Printf("0x%8.8x ", name_pos->second[j]); -// s->PutCString("}\n"); -// } -// if (num_name_entries == 1) -// ++names_entry_single; -// else if (num_name_entries > 1) -// ++names_entry_collisions; -// bucket_data_size += sizeof(pos->first) + hash_data_len; -// } -// data_offset += bucket_data_size; -// byte_size += bucket_data_size; -// total_num_bucket_entries += num_bucket_entries; -// if (num_bucket_entries == 1) -// ++bucket_entry_single; -// else if (num_bucket_entries > 1) -// ++bucket_entry_collisions; -// } -// -// s->Printf ("Trying size of %u buckets, %u items:\n", num_buckets, hash_entries_size); -// s->Printf ("buckets: empty = %u (%%%f)\n", bucket_entry_empties, ((float)bucket_entry_empties/(float)num_buckets) * 100.0f); -// s->Printf ("buckets: single = %u\n", bucket_entry_single); -// s->Printf ("buckets: multiple = %u (avg = %f entries/bucket, avg = %f entries/non-empty bucket)\n", -// bucket_entry_collisions, -// (float)total_num_bucket_entries / (float)num_buckets, -// (float)total_num_bucket_entries / (float)total_non_empty_buckets); -// s->Printf ("names : single = %u of %u\n", names_entry_single, total_num_name_entries); -// s->Printf ("names : multiple = %u of %u\n", names_entry_collisions, total_num_name_entries); -// s->Printf ("total byte size = %u\n", byte_size); -// s->PutCString ("\n----------------------------------------------------------------------\n\n"); -// } } Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/NameToDIE.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/NameToDIE.h?rev=139557&r1=139556&r2=139557&view=diff ============================================================================== --- lldb/trunk/source/Plugins/SymbolFile/DWARF/NameToDIE.h (original) +++ lldb/trunk/source/Plugins/SymbolFile/DWARF/NameToDIE.h Mon Sep 12 18:21:58 2011 @@ -10,24 +10,18 @@ #ifndef SymbolFileDWARF_NameToDIE_h_ #define SymbolFileDWARF_NameToDIE_h_ -#include -#include +#include "lldb/Core/UniqueCStringMap.h" #include "lldb/lldb-defines.h" class SymbolFileDWARF; +typedef std::vector DIEArray; + class NameToDIE { public: - typedef struct Info - { - uint32_t cu_idx; - uint32_t die_idx; - } Info; - - - NameToDIE () : - m_collection () + NameToDIE () : + m_map() { } @@ -39,27 +33,27 @@ Dump (lldb_private::Stream *s); void - Insert (const lldb_private::ConstString& name, const Info &info); - + Insert (const lldb_private::ConstString& name, uint32_t die_offset); + + void + Finalize(); + size_t Find (const lldb_private::ConstString &name, - std::vector &info_array) const; + DIEArray &info_array) const; size_t Find (const lldb_private::RegularExpression& regex, - std::vector &info_array) const; + DIEArray &info_array) const; size_t - FindAllEntriesForCompileUnitWithIndex (const uint32_t cu_idx, - std::vector &info_array) const; - - void - Hash (lldb_private::Stream *s, SymbolFileDWARF *dwarf); + FindAllEntriesForCompileUnit (uint32_t cu_offset, + uint32_t cu_end_offset, + DIEArray &info_array) const; protected: - typedef std::multimap collection; + lldb_private::UniqueCStringMap m_map; - collection m_collection; }; #endif // SymbolFileDWARF_NameToDIE_h_ 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=139557&r1=139556&r2=139557&view=diff ============================================================================== --- lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp (original) +++ lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp Mon Sep 12 18:21:58 2011 @@ -108,7 +108,7 @@ const char * SymbolFileDWARF::GetPluginNameStatic() { - return "symbol-file.dwarf2"; + return "dwarf"; } const char * @@ -163,17 +163,17 @@ m_debug_map_symfile (NULL), m_clang_tu_decl (NULL), m_flags(), - m_data_debug_abbrev(), - m_data_debug_frame(), - m_data_debug_info(), - m_data_debug_line(), - m_data_debug_loc(), - m_data_debug_ranges(), - m_data_debug_str(), + m_data_debug_abbrev (), + m_data_debug_aranges (), + m_data_debug_frame (), + m_data_debug_info (), + m_data_debug_line (), + m_data_debug_loc (), + m_data_debug_ranges (), + m_data_debug_str (), m_data_debug_names (), m_data_debug_types (), m_abbr(), - m_aranges(), m_info(), m_line(), m_debug_names (this, m_data_debug_names), @@ -413,6 +413,12 @@ } const DataExtractor& +SymbolFileDWARF::get_debug_aranges_data() +{ + return GetCachedSectionData (flagsGotDebugArangesData, eSectionTypeDWARFDebugAranges, m_data_debug_aranges); +} + +const DataExtractor& SymbolFileDWARF::get_debug_frame_data() { return GetCachedSectionData (flagsGotDebugFrameData, eSectionTypeDWARFDebugFrame, m_data_debug_frame); @@ -483,41 +489,6 @@ return m_abbr.get(); } -DWARFDebugAranges* -SymbolFileDWARF::DebugAranges() -{ - // It turns out that llvm-gcc doesn't generate .debug_aranges in .o files - // and we are already parsing all of the DWARF because the .debug_pubnames - // is useless (it only mentions symbols that are externally visible), so - // don't use the .debug_aranges section, we should be using a debug aranges - // we got from SymbolFileDWARF::Index(). - - if (!m_indexed) - Index(); - - -// if (m_aranges.get() == NULL) -// { -// Timer scoped_timer(__PRETTY_FUNCTION__, "%s this = %p", __PRETTY_FUNCTION__, this); -// m_aranges.reset(new DWARFDebugAranges()); -// if (m_aranges.get()) -// { -// const DataExtractor &debug_aranges_data = get_debug_aranges_data(); -// if (debug_aranges_data.GetByteSize() > 0) -// m_aranges->Extract(debug_aranges_data); -// else -// m_aranges->Generate(this); -// } -// } - return m_aranges.get(); -} - -const DWARFDebugAranges* -SymbolFileDWARF::DebugAranges() const -{ - return m_aranges.get(); -} - DWARFDebugInfo* SymbolFileDWARF::DebugInfo() @@ -1569,20 +1540,17 @@ { ConstString class_name (class_str.c_str()); - std::vector method_die_infos; - if (m_objc_class_selectors_index.Find (class_name, method_die_infos)) + DIEArray method_die_offsets; + if (m_objc_class_selectors_index.Find (class_name, method_die_offsets)) { + DWARFDebugInfo* debug_info = DebugInfo(); + DWARFCompileUnit* method_cu = NULL; - DWARFCompileUnit* prev_method_cu = NULL; - const size_t num_objc_methods = method_die_infos.size(); - for (size_t i=0;iGetCompileUnitAtIndex(method_die_infos[i].cu_idx); - - if (method_cu != prev_method_cu) - method_cu->ExtractDIEsIfNeeded (false); - - DWARFDebugInfoEntry *method_die = method_cu->GetDIEAtIndexUnchecked(method_die_infos[i].die_idx); + const dw_offset_t die_offset = method_die_offsets[i]; + DWARFDebugInfoEntry *method_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &method_cu); ResolveType (method_cu, method_die); } @@ -1722,11 +1690,10 @@ { lldb::addr_t file_vm_addr = so_addr.GetFileAddress(); - DWARFDebugAranges* debug_aranges = DebugAranges(); DWARFDebugInfo* debug_info = DebugInfo(); - if (debug_aranges) + if (debug_info) { - dw_offset_t cu_offset = debug_aranges->FindAddress(file_vm_addr); + dw_offset_t cu_offset = debug_info->GetCompileUnitAranges().FindAddress(file_vm_addr); if (cu_offset != DW_INVALID_OFFSET) { uint32_t cu_idx; @@ -1932,8 +1899,6 @@ DWARFDebugInfo* debug_info = DebugInfo(); if (debug_info) { - m_aranges.reset(new DWARFDebugAranges()); - uint32_t cu_idx = 0; const uint32_t num_compile_units = GetNumCompileUnits(); for (cu_idx = 0; cu_idx < num_compile_units; ++cu_idx) @@ -1950,9 +1915,7 @@ m_objc_class_selectors_index, m_global_index, m_type_index, - m_namespace_index, - DebugRanges(), - m_aranges.get()); + m_namespace_index); // Keep memory down by clearing DIEs if this generate function // caused them to be parsed @@ -1960,7 +1923,14 @@ curr_cu->ClearDIEs (true); } - m_aranges->Sort(); + m_function_basename_index.Finalize(); + m_function_fullname_index.Finalize(); + m_function_method_index.Finalize(); + m_function_selector_index.Finalize(); + m_objc_class_selectors_index.Finalize(); + m_global_index.Finalize(); + m_type_index.Finalize(); + m_namespace_index.Finalize(); #if defined (ENABLE_DEBUG_PRINTF) StreamFile s(stdout, false); @@ -2002,27 +1972,26 @@ sc.module_sp = m_obj_file->GetModule()->GetSP(); assert (sc.module_sp); - DWARFCompileUnit* curr_cu = NULL; - DWARFCompileUnit* prev_cu = NULL; + DWARFCompileUnit* dwarf_cu = NULL; const DWARFDebugInfoEntry* die = NULL; - std::vector die_info_array; - const size_t num_matches = m_global_index.Find(name, die_info_array); - for (size_t i=0; iGetCompileUnitAtIndex(die_info_array[i].cu_idx); - - if (curr_cu != prev_cu) - curr_cu->ExtractDIEsIfNeeded (false); - - die = curr_cu->GetDIEAtIndexUnchecked(die_info_array[i].die_idx); + DWARFDebugInfo* debug_info = DebugInfo(); + for (size_t i=0; iGetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); - sc.comp_unit = GetCompUnitForDWARFCompUnit(curr_cu, UINT32_MAX); - assert(sc.comp_unit != NULL); + sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX); + assert(sc.comp_unit != NULL); - ParseVariables(sc, curr_cu, LLDB_INVALID_ADDRESS, die, false, false, &variables); + ParseVariables(sc, dwarf_cu, LLDB_INVALID_ADDRESS, die, false, false, &variables); - if (variables.GetSize() - original_size >= max_matches) - break; + if (variables.GetSize() - original_size >= max_matches) + break; + } } // Return the number of variable that were appended to the list @@ -2052,27 +2021,25 @@ sc.module_sp = m_obj_file->GetModule()->GetSP(); assert (sc.module_sp); - DWARFCompileUnit* curr_cu = NULL; - DWARFCompileUnit* prev_cu = NULL; + DWARFCompileUnit* dwarf_cu = NULL; const DWARFDebugInfoEntry* die = NULL; - std::vector die_info_array; - const size_t num_matches = m_global_index.Find(regex, die_info_array); - for (size_t i=0; iGetCompileUnitAtIndex(die_info_array[i].cu_idx); - - if (curr_cu != prev_cu) - curr_cu->ExtractDIEsIfNeeded (false); - - die = curr_cu->GetDIEAtIndexUnchecked(die_info_array[i].die_idx); - - sc.comp_unit = GetCompUnitForDWARFCompUnit(curr_cu, UINT32_MAX); - assert(sc.comp_unit != NULL); + DWARFDebugInfo* debug_info = DebugInfo(); + for (size_t i=0; iGetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); + sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX); + assert(sc.comp_unit != NULL); - ParseVariables(sc, curr_cu, LLDB_INVALID_ADDRESS, die, false, false, &variables); + ParseVariables(sc, dwarf_cu, LLDB_INVALID_ADDRESS, die, false, false, &variables); - if (variables.GetSize() - original_size >= max_matches) - break; + if (variables.GetSize() - original_size >= max_matches) + break; + } } // Return the number of variable that were appended to the list @@ -2166,64 +2133,62 @@ sc.module_sp = m_obj_file->GetModule()->GetSP(); assert (sc.module_sp); - DWARFCompileUnit* curr_cu = NULL; - DWARFCompileUnit* prev_cu = NULL; + DWARFCompileUnit* dwarf_cu = NULL; const DWARFDebugInfoEntry* die = NULL; - std::vector die_info_array; - const size_t num_matches = name_to_die.Find (name, die_info_array); - for (size_t i=0; iGetCompileUnitAtIndex(die_info_array[i].cu_idx); - - if (curr_cu != prev_cu) - curr_cu->ExtractDIEsIfNeeded (false); - - die = curr_cu->GetDIEAtIndexUnchecked(die_info_array[i].die_idx); - - const DWARFDebugInfoEntry* inlined_die = NULL; - if (die->Tag() == DW_TAG_inlined_subroutine) - { - inlined_die = die; - - while ((die = die->GetParent()) != NULL) - { - if (die->Tag() == DW_TAG_subprogram) - break; - } - } - assert (die->Tag() == DW_TAG_subprogram); - if (GetFunction (curr_cu, die, sc)) + DWARFDebugInfo* debug_info = DebugInfo(); + for (size_t i=0; iGetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); + const DWARFDebugInfoEntry* inlined_die = NULL; + if (die->Tag() == DW_TAG_inlined_subroutine) { - sc.block = sc.function->GetBlock (true).FindBlockByID (inlined_die->GetOffset()); - assert (sc.block != NULL); - if (sc.block->GetStartAddress (addr) == false) - addr.Clear(); - } - else - { - sc.block = NULL; - addr = sc.function->GetAddressRange().GetBaseAddress(); + inlined_die = die; + + while ((die = die->GetParent()) != NULL) + { + if (die->Tag() == DW_TAG_subprogram) + break; + } } - - if (addr.IsValid()) + assert (die->Tag() == DW_TAG_subprogram); + if (GetFunction (dwarf_cu, die, sc)) { - - // We found the function, so we should find the line table - // and line table entry as well - LineTable *line_table = sc.comp_unit->GetLineTable(); - if (line_table == NULL) + Address addr; + // Parse all blocks if needed + if (inlined_die) { - if (ParseCompileUnitLineTable(sc)) - line_table = sc.comp_unit->GetLineTable(); + sc.block = sc.function->GetBlock (true).FindBlockByID (inlined_die->GetOffset()); + assert (sc.block != NULL); + if (sc.block->GetStartAddress (addr) == false) + addr.Clear(); + } + else + { + sc.block = NULL; + addr = sc.function->GetAddressRange().GetBaseAddress(); } - if (line_table != NULL) - line_table->FindLineEntryByAddress (addr, sc.line_entry); - sc_list.Append(sc); + if (addr.IsValid()) + { + + // We found the function, so we should find the line table + // and line table entry as well + LineTable *line_table = sc.comp_unit->GetLineTable(); + if (line_table == NULL) + { + if (ParseCompileUnitLineTable(sc)) + line_table = sc.comp_unit->GetLineTable(); + } + if (line_table != NULL) + line_table->FindLineEntryByAddress (addr, sc.line_entry); + + sc_list.Append(sc); + } } } } @@ -2246,64 +2211,63 @@ sc.module_sp = m_obj_file->GetModule()->GetSP(); assert (sc.module_sp); - DWARFCompileUnit* curr_cu = NULL; - DWARFCompileUnit* prev_cu = NULL; + DWARFCompileUnit* dwarf_cu = NULL; const DWARFDebugInfoEntry* die = NULL; - std::vector die_info_array; - const size_t num_matches = name_to_die.Find(regex, die_info_array); - for (size_t i=0; iGetCompileUnitAtIndex(die_info_array[i].cu_idx); - - if (curr_cu != prev_cu) - curr_cu->ExtractDIEsIfNeeded (false); - - die = curr_cu->GetDIEAtIndexUnchecked(die_info_array[i].die_idx); - - const DWARFDebugInfoEntry* inlined_die = NULL; - if (die->Tag() == DW_TAG_inlined_subroutine) - { - inlined_die = die; - - while ((die = die->GetParent()) != NULL) - { - if (die->Tag() == DW_TAG_subprogram) - break; - } - } - assert (die->Tag() == DW_TAG_subprogram); - if (GetFunction (curr_cu, die, sc)) + DWARFDebugInfo* debug_info = DebugInfo(); + for (size_t i=0; iGetBlock (true).FindBlockByID (inlined_die->GetOffset()); - assert (sc.block != NULL); - if (sc.block->GetStartAddress (addr) == false) - addr.Clear(); - } - else + const dw_offset_t die_offset = die_offsets[i]; + die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); + + const DWARFDebugInfoEntry* inlined_die = NULL; + if (die->Tag() == DW_TAG_inlined_subroutine) { - sc.block = NULL; - addr = sc.function->GetAddressRange().GetBaseAddress(); + inlined_die = die; + + while ((die = die->GetParent()) != NULL) + { + if (die->Tag() == DW_TAG_subprogram) + break; + } } - - if (addr.IsValid()) + assert (die->Tag() == DW_TAG_subprogram); + if (GetFunction (dwarf_cu, die, sc)) { - - // We found the function, so we should find the line table - // and line table entry as well - LineTable *line_table = sc.comp_unit->GetLineTable(); - if (line_table == NULL) + Address addr; + // Parse all blocks if needed + if (inlined_die) { - if (ParseCompileUnitLineTable(sc)) - line_table = sc.comp_unit->GetLineTable(); + sc.block = sc.function->GetBlock (true).FindBlockByID (inlined_die->GetOffset()); + assert (sc.block != NULL); + if (sc.block->GetStartAddress (addr) == false) + addr.Clear(); + } + else + { + sc.block = NULL; + addr = sc.function->GetAddressRange().GetBaseAddress(); } - if (line_table != NULL) - line_table->FindLineEntryByAddress (addr, sc.line_entry); - sc_list.Append(sc); + if (addr.IsValid()) + { + + // We found the function, so we should find the line table + // and line table entry as well + LineTable *line_table = sc.comp_unit->GetLineTable(); + if (line_table == NULL) + { + if (ParseCompileUnitLineTable(sc)) + line_table = sc.comp_unit->GetLineTable(); + } + if (line_table != NULL) + line_table->FindLineEntryByAddress (addr, sc.line_entry); + + sc_list.Append(sc); + } } } } @@ -2421,34 +2385,33 @@ Index (); const uint32_t initial_types_size = types.GetSize(); - DWARFCompileUnit* curr_cu = NULL; - DWARFCompileUnit* prev_cu = NULL; + DWARFCompileUnit* dwarf_cu = NULL; const DWARFDebugInfoEntry* die = NULL; - std::vector die_info_array; - const size_t num_matches = m_type_index.Find (name, die_info_array); - for (size_t i=0; iGetCompileUnitAtIndex(die_info_array[i].cu_idx); - - if (curr_cu != prev_cu) - curr_cu->ExtractDIEsIfNeeded (false); - - die = curr_cu->GetDIEAtIndexUnchecked(die_info_array[i].die_idx); - - Type *matching_type = ResolveType (curr_cu, die); - if (matching_type) + DWARFDebugInfo* debug_info = DebugInfo(); + for (size_t i=0; iFindType(matching_type->GetID())); - if (type_sp) - { - types.InsertUnique (type_sp); - if (types.GetSize() >= max_matches) - break; - } - else + const dw_offset_t die_offset = die_offsets[i]; + die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); + + Type *matching_type = ResolveType (dwarf_cu, die); + if (matching_type) { - fprintf (stderr, "error: can't find shared pointer for type 0x%8.8x.\n", matching_type->GetID()); + // We found a type pointer, now find the shared pointer form our type list + TypeSP type_sp (GetTypeList()->FindType(matching_type->GetID())); + if (type_sp) + { + types.InsertUnique (type_sp); + if (types.GetSize() >= max_matches) + break; + } + else + { + fprintf (stderr, "error: can't find shared pointer for type 0x%8.8x.\n", matching_type->GetID()); + } } } } @@ -2469,25 +2432,25 @@ if (!m_indexed) Index (); - DWARFCompileUnit* curr_cu = NULL; - DWARFCompileUnit* prev_cu = NULL; + + DWARFCompileUnit* dwarf_cu = NULL; const DWARFDebugInfoEntry* die = NULL; - std::vector die_info_array; - const size_t num_matches = m_namespace_index.Find (name, die_info_array); - for (size_t i=0; iGetCompileUnitAtIndex(die_info_array[i].cu_idx); - - if (curr_cu != prev_cu) - curr_cu->ExtractDIEsIfNeeded (false); - - die = curr_cu->GetDIEAtIndexUnchecked(die_info_array[i].die_idx); - - clang::NamespaceDecl *clang_namespace_decl = ResolveNamespaceDIE (curr_cu, die); - if (clang_namespace_decl) + DWARFDebugInfo* debug_info = DebugInfo(); + for (size_t i=0; iGetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); + + clang::NamespaceDecl *clang_namespace_decl = ResolveNamespaceDIE (dwarf_cu, die); + if (clang_namespace_decl) + { + namespace_decl.SetASTContext (GetClangASTContext().getASTContext()); + namespace_decl.SetNamespaceDecl (clang_namespace_decl); + } } } } @@ -3110,24 +3073,18 @@ Index (); const dw_tag_t type_tag = die->Tag(); - std::vector die_info_array; - const size_t num_matches = m_type_index.Find (type_name, die_info_array); - if (num_matches > 0) - { - DWARFCompileUnit* type_cu = NULL; - DWARFCompileUnit* curr_cu = cu; - DWARFDebugInfo *info = DebugInfo(); + + DWARFCompileUnit* type_cu = NULL; + const DWARFDebugInfoEntry* type_die = NULL; + DIEArray die_offsets; + const size_t num_matches = m_type_index.Find (type_name, die_offsets); + if (num_matches) + { + DWARFDebugInfo* debug_info = DebugInfo(); for (size_t i=0; iGetCompileUnitAtIndex (die_info_array[i].cu_idx); - - if (type_cu != curr_cu) - { - type_cu->ExtractDIEsIfNeeded (false); - curr_cu = type_cu; - } - - DWARFDebugInfoEntry *type_die = type_cu->GetDIEAtIndexUnchecked (die_info_array[i].die_idx); + const dw_offset_t die_offset = die_offsets[i]; + type_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &type_cu); if (type_die != die && type_die->Tag() == type_tag) { @@ -4254,15 +4211,25 @@ if (!m_indexed) Index (); - std::vector global_die_info_array; - const size_t num_globals = m_global_index.FindAllEntriesForCompileUnitWithIndex (cu_idx, global_die_info_array); - for (size_t idx=0; idxGetDIEAtIndexUnchecked(global_die_info_array[idx].die_idx), LLDB_INVALID_ADDRESS)); - if (var_sp) - { - variables->AddVariableIfUnique (var_sp); - ++vars_added; + DWARFCompileUnit* match_dwarf_cu = NULL; + const DWARFDebugInfoEntry* die = NULL; + DIEArray die_offsets; + const size_t num_matches = m_global_index.FindAllEntriesForCompileUnit (dwarf_cu->GetOffset(), + dwarf_cu->GetNextCompileUnitOffset(), + die_offsets); + if (num_matches) + { + DWARFDebugInfo* debug_info = DebugInfo(); + for (size_t i=0; iGetDIEPtrWithCompileUnitHint (die_offset, &match_dwarf_cu); + VariableSP var_sp (ParseVariableDIE(sc, dwarf_cu, die, LLDB_INVALID_ADDRESS)); + if (var_sp) + { + variables->AddVariableIfUnique (var_sp); + ++vars_added; + } } } } @@ -4694,24 +4661,23 @@ DWARFDebugInfo* info = DebugInfo(); - std::vector die_info_array; + DIEArray die_offsets; - size_t num_matches = m_type_index.Find (ConstString(name), die_info_array); + DWARFCompileUnit* dwarf_cu = NULL; + const DWARFDebugInfoEntry* die = NULL; + size_t num_matches = m_type_index.Find (ConstString(name), die_offsets); if (num_matches) { - for (int i = 0; - i < num_matches; - ++i) - { - DWARFCompileUnit* compile_unit = info->GetCompileUnitAtIndex(die_info_array[i].cu_idx); - compile_unit->ExtractDIEsIfNeeded (false); - const DWARFDebugInfoEntry *die = compile_unit->GetDIEAtIndexUnchecked(die_info_array[i].die_idx); - + for (size_t i = 0; i < num_matches; ++i) + { + const dw_offset_t die_offset = die_offsets[i]; + die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); + if (die->GetParent() != context_die) continue; - Type *matching_type = ResolveType (compile_unit, die); + Type *matching_type = ResolveType (dwarf_cu, die); lldb::clang_type_t type = matching_type->GetClangFullType(); clang::QualType qual_type = clang::QualType::getFromOpaquePtr(type); 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=139557&r1=139556&r2=139557&view=diff ============================================================================== --- lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h (original) +++ lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h Mon Sep 12 18:21:58 2011 @@ -7,8 +7,8 @@ // //===----------------------------------------------------------------------===// -#ifndef liblldb_SymbolFileDWARF_h_ -#define liblldb_SymbolFileDWARF_h_ +#ifndef SymbolFileDWARF_SymbolFileDWARF_h_ +#define SymbolFileDWARF_SymbolFileDWARF_h_ // C Includes // C++ Includes @@ -156,22 +156,20 @@ //virtual size_t GetCompUnitCount() = 0; //virtual CompUnitSP GetCompUnitAtIndex(size_t cu_idx) = 0; - const lldb_private::DataExtractor& get_debug_abbrev_data(); - const lldb_private::DataExtractor& get_debug_frame_data(); - const lldb_private::DataExtractor& get_debug_info_data(); - const lldb_private::DataExtractor& get_debug_line_data(); - const lldb_private::DataExtractor& get_debug_loc_data(); - const lldb_private::DataExtractor& get_debug_ranges_data(); - const lldb_private::DataExtractor& get_debug_str_data(); - const lldb_private::DataExtractor& get_debug_names_data(); - const lldb_private::DataExtractor& get_debug_types_data(); + const lldb_private::DataExtractor& get_debug_abbrev_data (); + const lldb_private::DataExtractor& get_debug_aranges_data (); + const lldb_private::DataExtractor& get_debug_frame_data (); + const lldb_private::DataExtractor& get_debug_info_data (); + const lldb_private::DataExtractor& get_debug_line_data (); + const lldb_private::DataExtractor& get_debug_loc_data (); + const lldb_private::DataExtractor& get_debug_ranges_data (); + const lldb_private::DataExtractor& get_debug_str_data (); + const lldb_private::DataExtractor& get_debug_names_data (); + const lldb_private::DataExtractor& get_debug_types_data (); DWARFDebugAbbrev* DebugAbbrev(); const DWARFDebugAbbrev* DebugAbbrev() const; - DWARFDebugAranges* DebugAranges(); - const DWARFDebugAranges*DebugAranges() const; - DWARFDebugInfo* DebugInfo(); const DWARFDebugInfo* DebugInfo() const; @@ -374,6 +372,7 @@ lldb_private::Flags m_flags; lldb_private::DataExtractor m_dwarf_data; lldb_private::DataExtractor m_data_debug_abbrev; + lldb_private::DataExtractor m_data_debug_aranges; lldb_private::DataExtractor m_data_debug_frame; lldb_private::DataExtractor m_data_debug_info; lldb_private::DataExtractor m_data_debug_line; @@ -386,7 +385,6 @@ // The auto_ptr items below are generated on demand if and when someone accesses // them through a non const version of this class. std::auto_ptr m_abbr; - std::auto_ptr m_aranges; std::auto_ptr m_info; std::auto_ptr m_line; HashedNameToDIE m_debug_names; @@ -417,4 +415,4 @@ ClangTypeToDIE m_forward_decl_clang_type_to_die; }; -#endif // liblldb_SymbolFileDWARF_h_ +#endif // SymbolFileDWARF_SymbolFileDWARF_h_ 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=139557&r1=139556&r2=139557&view=diff ============================================================================== --- lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp (original) +++ lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp Mon Sep 12 18:21:58 2011 @@ -44,7 +44,7 @@ const char * SymbolFileDWARFDebugMap::GetPluginNameStatic() { - return "symbol-file.dwarf2-debugmap"; + return "dwarf-debugmap"; } const char * From johnny.chen at apple.com Mon Sep 12 18:38:44 2011 From: johnny.chen at apple.com (Johnny Chen) Date: Mon, 12 Sep 2011 23:38:44 -0000 Subject: [Lldb-commits] [lldb] r139560 - in /lldb/trunk: include/lldb/Breakpoint/WatchpointLocation.h include/lldb/Interpreter/OptionGroupWatchpoint.h include/lldb/Target/Target.h include/lldb/lldb-enumerations.h source/Breakpoint/WatchpointLocation.cpp source/Commands/CommandObjectFrame.cpp source/Interpreter/CommandObject.cpp source/Interpreter/OptionGroupWatchpoint.cpp source/Target/Target.cpp Message-ID: <20110912233844.CBD542A6C12C@llvm.org> Author: johnny Date: Mon Sep 12 18:38:44 2011 New Revision: 139560 URL: http://llvm.org/viewvc/llvm-project?rev=139560&view=rev Log: Watchpoint WIP: o Rename from OptionGroupWatchpoint::WatchMode to OptionGroupWatchpoint::WatchType, and CommandArgumentType::eArgTypeWatchMode to CommandArgumentType::eArgTypeWatchType. Update the sources to reflect the change. o Add a CreateWatchpointLocation() method to Target class, which is currently not implmeneted (returns an empty WatchpointLocationSP object). Add logic to CommandObjectFrame::Execute() to exercise the added API for creating a watchpoint location. Modified: lldb/trunk/include/lldb/Breakpoint/WatchpointLocation.h lldb/trunk/include/lldb/Interpreter/OptionGroupWatchpoint.h lldb/trunk/include/lldb/Target/Target.h lldb/trunk/include/lldb/lldb-enumerations.h lldb/trunk/source/Breakpoint/WatchpointLocation.cpp lldb/trunk/source/Commands/CommandObjectFrame.cpp lldb/trunk/source/Interpreter/CommandObject.cpp lldb/trunk/source/Interpreter/OptionGroupWatchpoint.cpp lldb/trunk/source/Target/Target.cpp Modified: lldb/trunk/include/lldb/Breakpoint/WatchpointLocation.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Breakpoint/WatchpointLocation.h?rev=139560&r1=139559&r2=139560&view=diff ============================================================================== --- lldb/trunk/include/lldb/Breakpoint/WatchpointLocation.h (original) +++ lldb/trunk/include/lldb/Breakpoint/WatchpointLocation.h Mon Sep 12 18:38:44 2011 @@ -46,6 +46,7 @@ void SetWatchpointType (uint32_t type); bool BreakpointWasHit (StoppointCallbackContext *context); bool SetCallback (WatchpointHitCallback callback, void *callback_baton); + void GetDescription (Stream *s, lldb::DescriptionLevel level); void Dump (Stream *s) const; private: Modified: lldb/trunk/include/lldb/Interpreter/OptionGroupWatchpoint.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Interpreter/OptionGroupWatchpoint.h?rev=139560&r1=139559&r2=139560&view=diff ============================================================================== --- lldb/trunk/include/lldb/Interpreter/OptionGroupWatchpoint.h (original) +++ lldb/trunk/include/lldb/Interpreter/OptionGroupWatchpoint.h Mon Sep 12 18:38:44 2011 @@ -45,15 +45,18 @@ virtual void OptionParsingStarting (CommandInterpreter &interpreter); - typedef enum WatchMode { - eWatchInvalid, + // Note: + // eWatchRead == LLDB_WATCH_TYPE_EREAD; and + // eWatchWrite == LLDB_WATCH_TYPE_WRITE + typedef enum WatchType { + eWatchInvalid = 0, eWatchRead, eWatchWrite, eWatchReadWrite - } WatchMode; + } WatchType; bool watch_variable; - WatchMode watch_mode; + WatchType watch_type; private: DISALLOW_COPY_AND_ASSIGN(OptionGroupWatchpoint); Modified: lldb/trunk/include/lldb/Target/Target.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/Target.h?rev=139560&r1=139559&r2=139560&view=diff ============================================================================== --- lldb/trunk/include/lldb/Target/Target.h (original) +++ lldb/trunk/include/lldb/Target/Target.h Mon Sep 12 18:38:44 2011 @@ -280,6 +280,12 @@ lldb::BreakpointResolverSP &resolver_sp, bool internal = false); + // Use this to create a watchpoint location: + lldb::WatchpointLocationSP + CreateWatchpointLocation (lldb::addr_t addr, + size_t size, + uint32_t type); + WatchpointLocationList & GetWatchpointLocationList() { Modified: lldb/trunk/include/lldb/lldb-enumerations.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/lldb-enumerations.h?rev=139560&r1=139559&r2=139560&view=diff ============================================================================== --- lldb/trunk/include/lldb/lldb-enumerations.h (original) +++ lldb/trunk/include/lldb/lldb-enumerations.h Mon Sep 12 18:38:44 2011 @@ -408,7 +408,7 @@ eArgTypeWidth, eArgTypeNone, eArgTypePlatform, - eArgTypeWatchMode, + eArgTypeWatchType, eArgTypeLastArg // Always keep this entry as the last entry in this enumeration!! } CommandArgumentType; Modified: lldb/trunk/source/Breakpoint/WatchpointLocation.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Breakpoint/WatchpointLocation.cpp?rev=139560&r1=139559&r2=139560&view=diff ============================================================================== --- lldb/trunk/source/Breakpoint/WatchpointLocation.cpp (original) +++ lldb/trunk/source/Breakpoint/WatchpointLocation.cpp Mon Sep 12 18:38:44 2011 @@ -72,6 +72,13 @@ } void +WatchpointLocation::GetDescription (Stream *s, lldb::DescriptionLevel level) +{ + // FIXME: Add implmentation of GetDescription(). + return; +} + +void WatchpointLocation::Dump(Stream *s) const { if (s == NULL) Modified: lldb/trunk/source/Commands/CommandObjectFrame.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectFrame.cpp?rev=139560&r1=139559&r2=139560&view=diff ============================================================================== --- lldb/trunk/source/Commands/CommandObjectFrame.cpp (original) +++ lldb/trunk/source/Commands/CommandObjectFrame.cpp Mon Sep 12 18:38:44 2011 @@ -493,7 +493,7 @@ result.GetErrorStream().Printf ("error: unkown regex error when compiling '%s'\n", name_cstr); } } - else + else // No regex, either exact variable names or variable expressions. { Error error; uint32_t expr_path_options = StackFrame::eExpressionPathOptionCheckPtrVsMember; @@ -514,10 +514,34 @@ } if (summary_format_sp) valobj_sp->SetCustomSummaryFormat(summary_format_sp); - ValueObject::DumpValueObject (result.GetOutputStream(), + + Stream &output_stream = result.GetOutputStream(); + ValueObject::DumpValueObject (output_stream, valobj_sp.get(), valobj_sp->GetParent() ? name_cstr : NULL, options); + // Process watchpoint if necessary. + if (m_option_watchpoint.watch_variable) + { + lldb::addr_t addr = LLDB_INVALID_ADDRESS; + size_t size = 0; + uint32_t watch_type = m_option_watchpoint.watch_type; + WatchpointLocation *wp_loc = + exe_ctx.target->CreateWatchpointLocation(addr, size, watch_type).get(); + if (wp_loc) + { + output_stream.Printf("Watchpoint created: "); + wp_loc->GetDescription(&output_stream, lldb::eDescriptionLevelBrief); + output_stream.EOL(); + result.SetStatus(eReturnStatusSuccessFinishResult); + } + else + { + result.AppendErrorWithFormat("Watchpoint creation failed.\n"); + result.SetStatus(eReturnStatusFailed); + } + return (wp_loc != NULL); + } } else { Modified: lldb/trunk/source/Interpreter/CommandObject.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/CommandObject.cpp?rev=139560&r1=139559&r2=139560&view=diff ============================================================================== --- lldb/trunk/source/Interpreter/CommandObject.cpp (original) +++ lldb/trunk/source/Interpreter/CommandObject.cpp Mon Sep 12 18:38:44 2011 @@ -830,7 +830,7 @@ { eArgTypeWidth, "width", CommandCompletions::eNoCompletion, { NULL, false }, "Help text goes here." }, { eArgTypeNone, "none", CommandCompletions::eNoCompletion, { NULL, false }, "No help available for this." }, { eArgTypePlatform, "platform-name", CommandCompletions::ePlatformPluginCompletion, { NULL, false }, "The name of an installed platform plug-in . Type 'platform list' to see a complete list of installed platforms." }, - { eArgTypeWatchMode, "watch-mode", CommandCompletions::eNoCompletion, { NULL, false }, "Specify the mode for a watchpoint." } + { eArgTypeWatchType, "watch-type", CommandCompletions::eNoCompletion, { NULL, false }, "Specify the type for a watchpoint." } }; const CommandObject::ArgumentTableEntry* Modified: lldb/trunk/source/Interpreter/OptionGroupWatchpoint.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/OptionGroupWatchpoint.cpp?rev=139560&r1=139559&r2=139560&view=diff ============================================================================== --- lldb/trunk/source/Interpreter/OptionGroupWatchpoint.cpp (original) +++ lldb/trunk/source/Interpreter/OptionGroupWatchpoint.cpp Mon Sep 12 18:38:44 2011 @@ -20,7 +20,7 @@ using namespace lldb; using namespace lldb_private; -static OptionEnumValueElement g_watch_mode[] = +static OptionEnumValueElement g_watch_type[] = { { OptionGroupWatchpoint::eWatchRead, "read", "Watch for read"}, { OptionGroupWatchpoint::eWatchWrite, "write", "Watch for write"}, @@ -32,7 +32,7 @@ static OptionDefinition g_option_table[] = { - { LLDB_OPT_SET_1, false, "watch", 'w', required_argument, g_watch_mode, 0, eArgTypeWatchMode, "Determine how to watch a memory location (read, write, or read/write)."} + { LLDB_OPT_SET_1, false, "watch", 'w', required_argument, g_watch_type, 0, eArgTypeWatchType, "Determine how to watch a memory location (read, write, or read/write)."} }; @@ -56,7 +56,7 @@ { case 'w': { OptionEnumValueElement *enum_values = g_option_table[option_idx].enum_values; - watch_mode = (WatchMode) Args::StringToOptionEnum(option_arg, enum_values, 0, &watch_variable); + watch_type = (WatchType) Args::StringToOptionEnum(option_arg, enum_values, 0, &watch_variable); if (!watch_variable) error.SetErrorStringWithFormat("Invalid option arg for '-w': '%s'.\n", option_arg); break; @@ -73,7 +73,7 @@ OptionGroupWatchpoint::OptionParsingStarting (CommandInterpreter &interpreter) { watch_variable = false; - watch_mode = eWatchInvalid; + watch_type = eWatchInvalid; } Modified: lldb/trunk/source/Target/Target.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Target.cpp?rev=139560&r1=139559&r2=139560&view=diff ============================================================================== --- lldb/trunk/source/Target/Target.cpp (original) +++ lldb/trunk/source/Target/Target.cpp Mon Sep 12 18:38:44 2011 @@ -328,6 +328,15 @@ return bp_sp; } +// See also WatchpointLocation::SetWatchpointType() and OptionGroupWatchpoint::WatchType. +WatchpointLocationSP +Target::CreateWatchpointLocation(lldb::addr_t addr, size_t size, uint32_t type) +{ + WatchpointLocationSP wp_loc_sp; + if (addr == LLDB_INVALID_ADDRESS || size == 0 || GetProcessSP()) + return wp_loc_sp; +} + void Target::RemoveAllBreakpoints (bool internal_also) { From johnny.chen at apple.com Mon Sep 12 18:58:53 2011 From: johnny.chen at apple.com (Johnny Chen) Date: Mon, 12 Sep 2011 23:58:53 -0000 Subject: [Lldb-commits] [lldb] r139561 - /lldb/trunk/source/Commands/CommandObjectFrame.cpp Message-ID: <20110912235853.65DAB2A6C12C@llvm.org> Author: johnny Date: Mon Sep 12 18:58:53 2011 New Revision: 139561 URL: http://llvm.org/viewvc/llvm-project?rev=139561&view=rev Log: Remove an unnecessary 'else { ... }', which adds to vertical as well as horizontal spans, from CommandObjectFrame::Execute(). Modified: lldb/trunk/source/Commands/CommandObjectFrame.cpp Modified: lldb/trunk/source/Commands/CommandObjectFrame.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectFrame.cpp?rev=139561&r1=139560&r2=139561&view=diff ============================================================================== --- lldb/trunk/source/Commands/CommandObjectFrame.cpp (original) +++ lldb/trunk/source/Commands/CommandObjectFrame.cpp Mon Sep 12 18:58:53 2011 @@ -373,201 +373,197 @@ result.SetStatus (eReturnStatusFailed); return false; } - else + + Stream &s = result.GetOutputStream(); + + bool get_file_globals = true; + + // Be careful about the stack frame, if any summary formatter runs code, it might clear the StackFrameList + // for the thread. So hold onto a shared pointer to the frame so it stays alive. + + StackFrameSP frame_sp = exe_ctx.frame->GetSP(); + + VariableList *variable_list = frame_sp->GetVariableList (get_file_globals); + + VariableSP var_sp; + ValueObjectSP valobj_sp; + + const char *name_cstr = NULL; + size_t idx; + + SummaryFormatSP summary_format_sp; + if (!m_option_variable.summary.empty()) + DataVisualization::NamedSummaryFormats::GetSummaryFormat(ConstString(m_option_variable.summary.c_str()), summary_format_sp); + + ValueObject::DumpValueObjectOptions options; + + options.SetPointerDepth(m_varobj_options.ptr_depth) + .SetMaximumDepth(m_varobj_options.max_depth) + .SetShowTypes(m_varobj_options.show_types) + .SetShowLocation(m_varobj_options.show_location) + .SetUseObjectiveC(m_varobj_options.use_objc) + .SetUseDynamicType(m_varobj_options.use_dynamic) + .SetUseSyntheticValue((lldb::SyntheticValueType)m_varobj_options.use_synth) + .SetFlatOutput(m_varobj_options.flat_output) + .SetOmitSummaryDepth(m_varobj_options.no_summary_depth) + .SetIgnoreCap(m_varobj_options.ignore_cap); + + if (m_varobj_options.be_raw) + options.SetRawDisplay(true); + + if (variable_list) { - Stream &s = result.GetOutputStream(); + // If watching a variable, there are certain restrictions to be followed. + if (m_option_watchpoint.watch_variable) + { + if (command.GetArgumentCount() != 1) { + result.GetErrorStream().Printf("error: specify exactly one variable when using the '-w' option\n"); + result.SetStatus(eReturnStatusFailed); + return false; + } else if (m_option_variable.use_regex) { + result.GetErrorStream().Printf("error: specify your variable name exactly (no regex) when using the '-w' option\n"); + result.SetStatus(eReturnStatusFailed); + return false; + } - bool get_file_globals = true; - - // Be careful about the stack frame, if any summary formatter runs code, it might clear the StackFrameList - // for the thread. So hold onto a shared pointer to the frame so it stays alive. - - StackFrameSP frame_sp = exe_ctx.frame->GetSP(); - - VariableList *variable_list = frame_sp->GetVariableList (get_file_globals); - - VariableSP var_sp; - ValueObjectSP valobj_sp; - - const char *name_cstr = NULL; - size_t idx; - - SummaryFormatSP summary_format_sp; - if (!m_option_variable.summary.empty()) - DataVisualization::NamedSummaryFormats::GetSummaryFormat(ConstString(m_option_variable.summary.c_str()), summary_format_sp); - - ValueObject::DumpValueObjectOptions options; - - options.SetPointerDepth(m_varobj_options.ptr_depth) - .SetMaximumDepth(m_varobj_options.max_depth) - .SetShowTypes(m_varobj_options.show_types) - .SetShowLocation(m_varobj_options.show_location) - .SetUseObjectiveC(m_varobj_options.use_objc) - .SetUseDynamicType(m_varobj_options.use_dynamic) - .SetUseSyntheticValue((lldb::SyntheticValueType)m_varobj_options.use_synth) - .SetFlatOutput(m_varobj_options.flat_output) - .SetOmitSummaryDepth(m_varobj_options.no_summary_depth) - .SetIgnoreCap(m_varobj_options.ignore_cap); - - if (m_varobj_options.be_raw) - options.SetRawDisplay(true); - - if (variable_list) + // Things have checked out ok... + // m_option_watchpoint.watch_mode specifies the mode for watching. + } + if (command.GetArgumentCount() > 0) { - // If watching a variable, there are certain restrictions to be followed. - if (m_option_watchpoint.watch_variable) - { - if (command.GetArgumentCount() != 1) { - result.GetErrorStream().Printf("error: specify exactly one variable when using the '-w' option\n"); - result.SetStatus(eReturnStatusFailed); - return false; - } else if (m_option_variable.use_regex) { - result.GetErrorStream().Printf("error: specify your variable name exactly (no regex) when using the '-w' option\n"); - result.SetStatus(eReturnStatusFailed); - return false; - } + VariableList regex_var_list; - // Things have checked out ok... - // m_option_watchpoint.watch_mode specifies the mode for watching. - } - if (command.GetArgumentCount() > 0) + // If we have any args to the variable command, we will make + // variable objects from them... + for (idx = 0; (name_cstr = command.GetArgumentAtIndex(idx)) != NULL; ++idx) { - VariableList regex_var_list; - - // If we have any args to the variable command, we will make - // variable objects from them... - for (idx = 0; (name_cstr = command.GetArgumentAtIndex(idx)) != NULL; ++idx) + if (m_option_variable.use_regex) { - if (m_option_variable.use_regex) + const uint32_t regex_start_index = regex_var_list.GetSize(); + RegularExpression regex (name_cstr); + if (regex.Compile(name_cstr)) { - const uint32_t regex_start_index = regex_var_list.GetSize(); - RegularExpression regex (name_cstr); - if (regex.Compile(name_cstr)) + size_t num_matches = 0; + const size_t num_new_regex_vars = variable_list->AppendVariablesIfUnique(regex, + regex_var_list, + num_matches); + if (num_new_regex_vars > 0) { - size_t num_matches = 0; - const size_t num_new_regex_vars = variable_list->AppendVariablesIfUnique(regex, - regex_var_list, - num_matches); - if (num_new_regex_vars > 0) + for (uint32_t regex_idx = regex_start_index, end_index = regex_var_list.GetSize(); + regex_idx < end_index; + ++regex_idx) { - for (uint32_t regex_idx = regex_start_index, end_index = regex_var_list.GetSize(); - regex_idx < end_index; - ++regex_idx) + var_sp = regex_var_list.GetVariableAtIndex (regex_idx); + if (var_sp) { - var_sp = regex_var_list.GetVariableAtIndex (regex_idx); - if (var_sp) + valobj_sp = frame_sp->GetValueObjectForFrameVariable (var_sp, m_varobj_options.use_dynamic); + if (valobj_sp) { - valobj_sp = frame_sp->GetValueObjectForFrameVariable (var_sp, m_varobj_options.use_dynamic); - if (valobj_sp) - { - if (m_option_variable.format != eFormatDefault) - valobj_sp->SetFormat (m_option_variable.format); - - if (m_option_variable.show_decl && var_sp->GetDeclaration ().GetFile()) - { - bool show_fullpaths = false; - bool show_module = true; - if (var_sp->DumpDeclaration(&s, show_fullpaths, show_module)) - s.PutCString (": "); - } - if (summary_format_sp) - valobj_sp->SetCustomSummaryFormat(summary_format_sp); - ValueObject::DumpValueObject (result.GetOutputStream(), - valobj_sp.get(), - options); + if (m_option_variable.format != eFormatDefault) + valobj_sp->SetFormat (m_option_variable.format); + + if (m_option_variable.show_decl && var_sp->GetDeclaration ().GetFile()) + { + bool show_fullpaths = false; + bool show_module = true; + if (var_sp->DumpDeclaration(&s, show_fullpaths, show_module)) + s.PutCString (": "); } + if (summary_format_sp) + valobj_sp->SetCustomSummaryFormat(summary_format_sp); + ValueObject::DumpValueObject (result.GetOutputStream(), + valobj_sp.get(), + options); } } } - else if (num_matches == 0) - { - result.GetErrorStream().Printf ("error: no variables matched the regular expression '%s'.\n", name_cstr); - } } - else + else if (num_matches == 0) { - char regex_error[1024]; - if (regex.GetErrorAsCString(regex_error, sizeof(regex_error))) - result.GetErrorStream().Printf ("error: %s\n", regex_error); - else - result.GetErrorStream().Printf ("error: unkown regex error when compiling '%s'\n", name_cstr); + result.GetErrorStream().Printf ("error: no variables matched the regular expression '%s'.\n", name_cstr); } } - else // No regex, either exact variable names or variable expressions. + else { - Error error; - uint32_t expr_path_options = StackFrame::eExpressionPathOptionCheckPtrVsMember; - lldb::VariableSP var_sp; - valobj_sp = frame_sp->GetValueForVariableExpressionPath (name_cstr, - m_varobj_options.use_dynamic, - expr_path_options, - var_sp, - error); - if (valobj_sp) + char regex_error[1024]; + if (regex.GetErrorAsCString(regex_error, sizeof(regex_error))) + result.GetErrorStream().Printf ("error: %s\n", regex_error); + else + result.GetErrorStream().Printf ("error: unkown regex error when compiling '%s'\n", name_cstr); + } + } + else // No regex, either exact variable names or variable expressions. + { + Error error; + uint32_t expr_path_options = StackFrame::eExpressionPathOptionCheckPtrVsMember; + lldb::VariableSP var_sp; + valobj_sp = frame_sp->GetValueForVariableExpressionPath (name_cstr, + m_varobj_options.use_dynamic, + expr_path_options, + var_sp, + error); + if (valobj_sp) + { + if (m_option_variable.format != eFormatDefault) + valobj_sp->SetFormat (m_option_variable.format); + if (m_option_variable.show_decl && var_sp && var_sp->GetDeclaration ().GetFile()) { - if (m_option_variable.format != eFormatDefault) - valobj_sp->SetFormat (m_option_variable.format); - if (m_option_variable.show_decl && var_sp && var_sp->GetDeclaration ().GetFile()) + var_sp->GetDeclaration ().DumpStopContext (&s, false); + s.PutCString (": "); + } + if (summary_format_sp) + valobj_sp->SetCustomSummaryFormat(summary_format_sp); + + Stream &output_stream = result.GetOutputStream(); + ValueObject::DumpValueObject (output_stream, + valobj_sp.get(), + valobj_sp->GetParent() ? name_cstr : NULL, + options); + // Process watchpoint if necessary. + if (m_option_watchpoint.watch_variable) + { + lldb::addr_t addr = LLDB_INVALID_ADDRESS; + size_t size = 0; + uint32_t watch_type = m_option_watchpoint.watch_type; + WatchpointLocation *wp_loc = + exe_ctx.target->CreateWatchpointLocation(addr, size, watch_type).get(); + if (wp_loc) { - var_sp->GetDeclaration ().DumpStopContext (&s, false); - s.PutCString (": "); + output_stream.Printf("Watchpoint created: "); + wp_loc->GetDescription(&output_stream, lldb::eDescriptionLevelBrief); + output_stream.EOL(); + result.SetStatus(eReturnStatusSuccessFinishResult); } - if (summary_format_sp) - valobj_sp->SetCustomSummaryFormat(summary_format_sp); - - Stream &output_stream = result.GetOutputStream(); - ValueObject::DumpValueObject (output_stream, - valobj_sp.get(), - valobj_sp->GetParent() ? name_cstr : NULL, - options); - // Process watchpoint if necessary. - if (m_option_watchpoint.watch_variable) + else { - lldb::addr_t addr = LLDB_INVALID_ADDRESS; - size_t size = 0; - uint32_t watch_type = m_option_watchpoint.watch_type; - WatchpointLocation *wp_loc = - exe_ctx.target->CreateWatchpointLocation(addr, size, watch_type).get(); - if (wp_loc) - { - output_stream.Printf("Watchpoint created: "); - wp_loc->GetDescription(&output_stream, lldb::eDescriptionLevelBrief); - output_stream.EOL(); - result.SetStatus(eReturnStatusSuccessFinishResult); - } - else - { - result.AppendErrorWithFormat("Watchpoint creation failed.\n"); - result.SetStatus(eReturnStatusFailed); - } - return (wp_loc != NULL); + result.AppendErrorWithFormat("Watchpoint creation failed.\n"); + result.SetStatus(eReturnStatusFailed); } + return (wp_loc != NULL); } + } + else + { + const char *error_cstr = error.AsCString(NULL); + if (error_cstr) + result.GetErrorStream().Printf("error: %s\n", error_cstr); else - { - const char *error_cstr = error.AsCString(NULL); - if (error_cstr) - result.GetErrorStream().Printf("error: %s\n", error_cstr); - else - result.GetErrorStream().Printf ("error: unable to find any variable expression path that matches '%s'\n", name_cstr); - } + result.GetErrorStream().Printf ("error: unable to find any variable expression path that matches '%s'\n", name_cstr); } } } - else // No command arg specified. Use variable_list, instead. + } + else // No command arg specified. Use variable_list, instead. + { + const uint32_t num_variables = variable_list->GetSize(); + if (num_variables > 0) { - const uint32_t num_variables = variable_list->GetSize(); - - if (num_variables > 0) + for (uint32_t i=0; iGetVariableAtIndex(i); + bool dump_variable = true; + switch (var_sp->GetScope()) { - var_sp = variable_list->GetVariableAtIndex(i); - - bool dump_variable = true; - - switch (var_sp->GetScope()) - { case eValueTypeVariableGlobal: dump_variable = m_option_variable.show_globals; if (dump_variable && m_option_variable.show_scope) @@ -579,13 +575,13 @@ if (dump_variable && m_option_variable.show_scope) s.PutCString("STATIC: "); break; - + case eValueTypeVariableArgument: dump_variable = m_option_variable.show_args; if (dump_variable && m_option_variable.show_scope) s.PutCString(" ARG: "); break; - + case eValueTypeVariableLocal: dump_variable = m_option_variable.show_locals; if (dump_variable && m_option_variable.show_scope) @@ -594,44 +590,42 @@ default: break; - } - - if (dump_variable) + } + + if (dump_variable) + { + // Use the variable object code to make sure we are + // using the same APIs as the the public API will be + // using... + valobj_sp = frame_sp->GetValueObjectForFrameVariable (var_sp, + m_varobj_options.use_dynamic); + if (valobj_sp) { + if (m_option_variable.format != eFormatDefault) + valobj_sp->SetFormat (m_option_variable.format); - // Use the variable object code to make sure we are - // using the same APIs as the the public API will be - // using... - valobj_sp = frame_sp->GetValueObjectForFrameVariable (var_sp, - m_varobj_options.use_dynamic); - if (valobj_sp) + // When dumping all variables, don't print any variables + // that are not in scope to avoid extra unneeded output + if (valobj_sp->IsInScope ()) { - if (m_option_variable.format != eFormatDefault) - valobj_sp->SetFormat (m_option_variable.format); - - // When dumping all variables, don't print any variables - // that are not in scope to avoid extra unneeded output - if (valobj_sp->IsInScope ()) + if (m_option_variable.show_decl && var_sp->GetDeclaration ().GetFile()) { - if (m_option_variable.show_decl && var_sp->GetDeclaration ().GetFile()) - { - var_sp->GetDeclaration ().DumpStopContext (&s, false); - s.PutCString (": "); - } - if (summary_format_sp) - valobj_sp->SetCustomSummaryFormat(summary_format_sp); - ValueObject::DumpValueObject (result.GetOutputStream(), - valobj_sp.get(), - name_cstr, - options); + var_sp->GetDeclaration ().DumpStopContext (&s, false); + s.PutCString (": "); } + if (summary_format_sp) + valobj_sp->SetCustomSummaryFormat(summary_format_sp); + ValueObject::DumpValueObject (result.GetOutputStream(), + valobj_sp.get(), + name_cstr, + options); } } } } } - result.SetStatus (eReturnStatusSuccessFinishResult); } + result.SetStatus (eReturnStatusSuccessFinishResult); } if (m_interpreter.TruncationWarningNecessary()) From jingham at apple.com Mon Sep 12 19:29:56 2011 From: jingham at apple.com (Jim Ingham) Date: Tue, 13 Sep 2011 00:29:56 -0000 Subject: [Lldb-commits] [lldb] r139564 - in /lldb/trunk: include/lldb/API/ include/lldb/Core/ scripts/Python/interface/ source/API/ source/Core/ source/Target/ tools/driver/ Message-ID: <20110913002956.72A712A6C12C@llvm.org> Author: jingham Date: Mon Sep 12 19:29:56 2011 New Revision: 139564 URL: http://llvm.org/viewvc/llvm-project?rev=139564&view=rev Log: SBSourceManager now gets the real source manager either from the Debugger or Target. Also, move the SourceManager file cache into the debugger so it can be shared amongst the targets. Modified: lldb/trunk/include/lldb/API/SBDebugger.h lldb/trunk/include/lldb/API/SBFileSpec.h lldb/trunk/include/lldb/API/SBSourceManager.h lldb/trunk/include/lldb/API/SBStream.h lldb/trunk/include/lldb/API/SBTarget.h lldb/trunk/include/lldb/Core/Debugger.h lldb/trunk/include/lldb/Core/SourceManager.h lldb/trunk/scripts/Python/interface/SBDebugger.i lldb/trunk/scripts/Python/interface/SBTarget.i lldb/trunk/source/API/SBCommandInterpreter.cpp lldb/trunk/source/API/SBDebugger.cpp lldb/trunk/source/API/SBSourceManager.cpp lldb/trunk/source/API/SBTarget.cpp lldb/trunk/source/Core/Debugger.cpp lldb/trunk/source/Core/SourceManager.cpp lldb/trunk/source/Target/Target.cpp lldb/trunk/tools/driver/Driver.cpp Modified: lldb/trunk/include/lldb/API/SBDebugger.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBDebugger.h?rev=139564&r1=139563&r2=139564&view=diff ============================================================================== --- lldb/trunk/include/lldb/API/SBDebugger.h (original) +++ lldb/trunk/include/lldb/API/SBDebugger.h Mon Sep 12 19:29:56 2011 @@ -127,7 +127,7 @@ lldb::SBTarget GetSelectedTarget (); - lldb::SBSourceManager & + lldb::SBSourceManager GetSourceManager (); // REMOVE: just for a quick fix, need to expose platforms through @@ -234,6 +234,7 @@ friend class SBInputReader; friend class SBProcess; friend class SBTarget; + friend class SBSourceManager_impl; lldb::SBTarget FindTargetWithLLDBProcess (const lldb::ProcessSP &processSP); Modified: lldb/trunk/include/lldb/API/SBFileSpec.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBFileSpec.h?rev=139564&r1=139563&r2=139564&view=diff ============================================================================== --- lldb/trunk/include/lldb/API/SBFileSpec.h (original) +++ lldb/trunk/include/lldb/API/SBFileSpec.h Mon Sep 12 19:29:56 2011 @@ -63,7 +63,7 @@ friend class SBLineEntry; friend class SBModule; friend class SBProcess; - friend class SBSourceManager; + friend class SBSourceManager_impl; friend class SBThread; friend class SBTarget; Modified: lldb/trunk/include/lldb/API/SBSourceManager.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBSourceManager.h?rev=139564&r1=139563&r2=139564&view=diff ============================================================================== --- lldb/trunk/include/lldb/API/SBSourceManager.h (original) +++ lldb/trunk/include/lldb/API/SBSourceManager.h Mon Sep 12 19:29:56 2011 @@ -16,10 +16,14 @@ namespace lldb { +class SBSourceManager_impl; + class SBSourceManager { public: - SBSourceManager (const lldb::SBSourceManager &rhs); + SBSourceManager (const SBDebugger &debugger); + SBSourceManager (const SBTarget &target); + SBSourceManager (const SBSourceManager &rhs); ~SBSourceManager(); @@ -45,7 +49,7 @@ private: - lldb_private::SourceManager *m_opaque_ptr; + std::auto_ptr m_opaque_ap; }; } // namespace lldb Modified: lldb/trunk/include/lldb/API/SBStream.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBStream.h?rev=139564&r1=139563&r2=139564&view=diff ============================================================================== --- lldb/trunk/include/lldb/API/SBStream.h (original) +++ lldb/trunk/include/lldb/API/SBStream.h Mon Sep 12 19:29:56 2011 @@ -69,7 +69,7 @@ friend class SBInstruction; friend class SBInstructionList; friend class SBModule; - friend class SBSourceManager; + friend class SBSourceManager_impl; friend class SBSymbol; friend class SBSymbolContext; friend class SBTarget; Modified: lldb/trunk/include/lldb/API/SBTarget.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBTarget.h?rev=139564&r1=139563&r2=139564&view=diff ============================================================================== --- lldb/trunk/include/lldb/API/SBTarget.h (original) +++ lldb/trunk/include/lldb/API/SBTarget.h Mon Sep 12 19:29:56 2011 @@ -349,6 +349,9 @@ lldb::SBTypeList FindTypes (const char* type); + + SBSourceManager + GetSourceManager(); #ifndef SWIG bool @@ -375,6 +378,7 @@ friend class SBSymbol; friend class SBModule; friend class SBValue; + friend class SBSourceManager_impl; //------------------------------------------------------------------ // Constructors are private, use static Target::Create function to Modified: lldb/trunk/include/lldb/Core/Debugger.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/Debugger.h?rev=139564&r1=139563&r2=139564&view=diff ============================================================================== --- lldb/trunk/include/lldb/Core/Debugger.h (original) +++ lldb/trunk/include/lldb/Core/Debugger.h Mon Sep 12 19:29:56 2011 @@ -223,6 +223,8 @@ public UserID, public DebuggerInstanceSettings { +friend class SourceManager; // For GetSourceFileCache. + public: class SettingsController : public UserSettingsController @@ -342,16 +344,17 @@ return m_listener; } + // This returns the Debugger's scratch source manager. It won't be able to look up files in debug + // information, but it can look up files by absolute path and display them to you. + // To get the target's source manager, call GetSourceManager on the target instead. SourceManager & GetSourceManager () { - lldb::TargetSP selected_target = GetSelectedTarget(); - if (selected_target) - return selected_target->GetSourceManager(); - else - return m_source_manager; + return m_source_manager; } +public: + lldb::TargetSP GetSelectedTarget () { @@ -455,6 +458,12 @@ m_input_comm.Clear (); } + SourceManager::SourceFileCache & + GetSourceFileCache () + { + return m_source_file_cache; + } + Communication m_input_comm; StreamFile m_input_file; StreamFile m_output_file; @@ -463,6 +472,8 @@ PlatformList m_platform_list; Listener m_listener; SourceManager m_source_manager; // This is a scratch source manager that we return if we have no targets. + SourceManager::SourceFileCache m_source_file_cache; // All the source managers for targets created in this debugger used this shared + // source file cache. std::auto_ptr m_command_interpreter_ap; InputReaderStack m_input_reader_stack; Modified: lldb/trunk/include/lldb/Core/SourceManager.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/SourceManager.h?rev=139564&r1=139563&r2=139564&view=diff ============================================================================== --- lldb/trunk/include/lldb/Core/SourceManager.h (original) +++ lldb/trunk/include/lldb/Core/SourceManager.h Mon Sep 12 19:29:56 2011 @@ -26,9 +26,12 @@ { public: #ifndef SWIG + class File { + friend bool operator== (const SourceManager::File &lhs, const SourceManager::File &rhs); public: + File (const FileSpec &file_spec, Target *target); ~File(); @@ -52,7 +55,7 @@ { return m_file_spec; } - + protected: bool @@ -65,6 +68,28 @@ typedef std::vector LineOffsets; LineOffsets m_offsets; }; + +#endif // SWIG + + typedef lldb::SharedPtr::Type FileSP; + +#ifndef SWIG + + // The SourceFileCache class separates the source manager from the cache of source files, so the + // cache can be stored in the Debugger, but the source managers can be per target. + class SourceFileCache + { + public: + SourceFileCache () {}; + ~SourceFileCache() {}; + + void AddSourceFile (const FileSP &file_sp); + FileSP FindSourceFile (const FileSpec &file_spec) const; + + protected: + typedef std::map FileCache; + FileCache m_file_cache; + }; #endif @@ -73,11 +98,11 @@ //------------------------------------------------------------------ // A source manager can be made with a non-null target, in which case it can use the path remappings to find // source files that are not in their build locations. With no target it won't be able to do this. - SourceManager(Target *target); + SourceManager (Debugger &debugger); + SourceManager (Target &target); ~SourceManager(); - typedef lldb::SharedPtr::Type FileSP; FileSP GetLastFile () @@ -134,13 +159,13 @@ //------------------------------------------------------------------ // Classes that inherit from SourceManager can see and modify these //------------------------------------------------------------------ - typedef std::map FileCache; - FileCache m_file_cache; FileSP m_last_file_sp; uint32_t m_last_file_line; uint32_t m_last_file_context_before; uint32_t m_last_file_context_after; Target *m_target; + Debugger *m_debugger; + private: //------------------------------------------------------------------ // For SourceManager only @@ -148,6 +173,7 @@ DISALLOW_COPY_AND_ASSIGN (SourceManager); }; +bool operator== (const SourceManager::File &lhs, const SourceManager::File &rhs); } // namespace lldb_private #endif // liblldb_SourceManager_h_ Modified: lldb/trunk/scripts/Python/interface/SBDebugger.i URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/Python/interface/SBDebugger.i?rev=139564&r1=139563&r2=139564&view=diff ============================================================================== --- lldb/trunk/scripts/Python/interface/SBDebugger.i (original) +++ lldb/trunk/scripts/Python/interface/SBDebugger.i Mon Sep 12 19:29:56 2011 @@ -206,7 +206,7 @@ lldb::SBTarget GetSelectedTarget (); - lldb::SBSourceManager & + lldb::SBSourceManager GetSourceManager (); // REMOVE: just for a quick fix, need to expose platforms through Modified: lldb/trunk/scripts/Python/interface/SBTarget.i URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/Python/interface/SBTarget.i?rev=139564&r1=139563&r2=139564&view=diff ============================================================================== --- lldb/trunk/scripts/Python/interface/SBTarget.i (original) +++ lldb/trunk/scripts/Python/interface/SBTarget.i Mon Sep 12 19:29:56 2011 @@ -327,6 +327,9 @@ lldb::SBTypeList FindTypes (const char* type); + lldb::SBSourceManager + GetSourceManager (); + %feature("docstring", " //------------------------------------------------------------------ /// Find global and static variables by name. Modified: lldb/trunk/source/API/SBCommandInterpreter.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBCommandInterpreter.cpp?rev=139564&r1=139563&r2=139564&view=diff ============================================================================== --- lldb/trunk/source/API/SBCommandInterpreter.cpp (original) +++ lldb/trunk/source/API/SBCommandInterpreter.cpp Mon Sep 12 19:29:56 2011 @@ -18,7 +18,6 @@ #include "lldb/API/SBBroadcaster.h" #include "lldb/API/SBDebugger.h" #include "lldb/API/SBCommandReturnObject.h" -#include "lldb/API/SBSourceManager.h" #include "lldb/API/SBCommandInterpreter.h" #include "lldb/API/SBProcess.h" #include "lldb/API/SBTarget.h" Modified: lldb/trunk/source/API/SBDebugger.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBDebugger.cpp?rev=139564&r1=139563&r2=139564&view=diff ============================================================================== --- lldb/trunk/source/API/SBDebugger.cpp (original) +++ lldb/trunk/source/API/SBDebugger.cpp Mon Sep 12 19:29:56 2011 @@ -357,12 +357,11 @@ } } -SBSourceManager & +SBSourceManager SBDebugger::GetSourceManager () { - static SourceManager g_lldb_source_manager(NULL); - static SBSourceManager g_sb_source_manager (&g_lldb_source_manager); - return g_sb_source_manager; + SBSourceManager sb_source_manager (*this); + return sb_source_manager; } Modified: lldb/trunk/source/API/SBSourceManager.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBSourceManager.cpp?rev=139564&r1=139563&r2=139564&view=diff ============================================================================== --- lldb/trunk/source/API/SBSourceManager.cpp (original) +++ lldb/trunk/source/API/SBSourceManager.cpp Mon Sep 12 19:29:56 2011 @@ -7,41 +7,110 @@ // //===----------------------------------------------------------------------===// - +#include "lldb/API/SBDebugger.h" #include "lldb/API/SBSourceManager.h" +#include "lldb/API/SBTarget.h" #include "lldb/API/SBStream.h" #include "lldb/API/SBFileSpec.h" +#include "lldb/Core/Debugger.h" #include "lldb/Core/Stream.h" #include "lldb/Core/StreamFile.h" #include "lldb/Core/SourceManager.h" +#include "lldb/Target/Target.h" using namespace lldb; using namespace lldb_private; +class lldb::SBSourceManager_impl +{ +public: + SBSourceManager_impl (const SBDebugger &debugger) + { + m_debugger_sp = debugger.m_opaque_sp; + } + + SBSourceManager_impl (const SBTarget &target) + { + m_target_sp = target.m_opaque_sp; + } + + SBSourceManager_impl (const SBSourceManager_impl &rhs) + { + if (&rhs == this) + return; + m_debugger_sp = rhs.m_debugger_sp; + m_target_sp = rhs.m_target_sp; + } + + size_t + DisplaySourceLinesWithLineNumbers + ( + const SBFileSpec &file, + uint32_t line, + uint32_t context_before, + uint32_t context_after, + const char* current_line_cstr, + SBStream &s + ) + { + if (!file.IsValid()) + return 0; + + if (m_debugger_sp) + return m_debugger_sp->GetSourceManager().DisplaySourceLinesWithLineNumbers (*file, + line, + context_before, + context_after, + current_line_cstr, + s.m_opaque_ap.get()); + else if (m_target_sp) + return m_target_sp->GetSourceManager().DisplaySourceLinesWithLineNumbers (*file, + line, + context_before, + context_after, + current_line_cstr, + s.m_opaque_ap.get()); + else + return 0; + } + +private: + lldb::DebuggerSP m_debugger_sp; + lldb::TargetSP m_target_sp; + +}; -SBSourceManager::SBSourceManager (SourceManager* source_manager) : - m_opaque_ptr (source_manager) +SBSourceManager::SBSourceManager (const SBDebugger &debugger) { + m_opaque_ap.reset(new SBSourceManager_impl (debugger)); } -SBSourceManager::~SBSourceManager() +SBSourceManager::SBSourceManager (const SBTarget &target) { + m_opaque_ap.reset(new SBSourceManager_impl (target)); } -SBSourceManager::SBSourceManager(const SBSourceManager &rhs) : - m_opaque_ptr (rhs.m_opaque_ptr) +SBSourceManager::SBSourceManager (const SBSourceManager &rhs) { + if (&rhs == this) + return; + + m_opaque_ap.reset(new SBSourceManager_impl (*(rhs.m_opaque_ap.get()))); } -const SBSourceManager & -SBSourceManager::operator = (const SBSourceManager &rhs) +const lldb::SBSourceManager & +SBSourceManager::operator = (const lldb::SBSourceManager &rhs) { - m_opaque_ptr = rhs.m_opaque_ptr; + m_opaque_ap.reset (new SBSourceManager_impl (*(rhs.m_opaque_ap.get()))); return *this; } +SBSourceManager::~SBSourceManager() +{ +} + size_t SBSourceManager::DisplaySourceLinesWithLineNumbers ( @@ -53,20 +122,13 @@ SBStream &s ) { - if (m_opaque_ptr == NULL) - return 0; - - if (s.m_opaque_ap.get() == NULL) + if (m_opaque_ap.get() == NULL) return 0; - if (file.IsValid()) - { - return m_opaque_ptr->DisplaySourceLinesWithLineNumbers (*file, - line, - context_before, - context_after, - current_line_cstr, - s.m_opaque_ap.get()); - } - return 0; + return m_opaque_ap->DisplaySourceLinesWithLineNumbers (file, + line, + context_before, + context_after, + current_line_cstr, + s); } Modified: lldb/trunk/source/API/SBTarget.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBTarget.cpp?rev=139564&r1=139563&r2=139564&view=diff ============================================================================== --- lldb/trunk/source/API/SBTarget.cpp (original) +++ lldb/trunk/source/API/SBTarget.cpp Mon Sep 12 19:29:56 2011 @@ -16,6 +16,7 @@ #include "lldb/API/SBFileSpec.h" #include "lldb/API/SBListener.h" #include "lldb/API/SBModule.h" +#include "lldb/API/SBSourceManager.h" #include "lldb/API/SBProcess.h" #include "lldb/API/SBStream.h" #include "lldb/API/SBSymbolContextList.h" @@ -958,3 +959,9 @@ return sb_value_list; } +SBSourceManager +SBTarget::GetSourceManager() +{ + SBSourceManager source_manager (*this); + return source_manager; +} Modified: lldb/trunk/source/Core/Debugger.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/Debugger.cpp?rev=139564&r1=139563&r2=139564&view=diff ============================================================================== --- lldb/trunk/source/Core/Debugger.cpp (original) +++ lldb/trunk/source/Core/Debugger.cpp Mon Sep 12 19:29:56 2011 @@ -237,7 +237,8 @@ m_target_list (), m_platform_list (), m_listener ("lldb.Debugger"), - m_source_manager(NULL), + m_source_manager(*this), + m_source_file_cache(), m_command_interpreter_ap (new CommandInterpreter (*this, eScriptLanguageDefault, false)), m_input_reader_stack (), m_input_reader_data () Modified: lldb/trunk/source/Core/SourceManager.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/SourceManager.cpp?rev=139564&r1=139563&r2=139564&view=diff ============================================================================== --- lldb/trunk/source/Core/SourceManager.cpp (original) +++ lldb/trunk/source/Core/SourceManager.cpp Mon Sep 12 19:29:56 2011 @@ -14,6 +14,7 @@ // Other libraries and framework includes // Project includes #include "lldb/Core/DataBuffer.h" +#include "lldb/Core/Debugger.h" #include "lldb/Core/Stream.h" #include "lldb/Symbol/SymbolContext.h" #include "lldb/Target/Target.h" @@ -29,13 +30,24 @@ //---------------------------------------------------------------------- // SourceManager constructor //---------------------------------------------------------------------- -SourceManager::SourceManager(Target *target) : - m_file_cache (), +SourceManager::SourceManager(Target &target) : m_last_file_sp (), m_last_file_line (0), m_last_file_context_before (0), m_last_file_context_after (10), - m_target (target) + m_target (&target), + m_debugger(NULL) +{ + m_debugger = &(m_target->GetDebugger()); +} + +SourceManager::SourceManager(Debugger &debugger) : + m_last_file_sp (), + m_last_file_line (0), + m_last_file_context_before (0), + m_last_file_context_after (10), + m_target (NULL), + m_debugger (&debugger) { } @@ -70,13 +82,12 @@ SourceManager::GetFile (const FileSpec &file_spec) { FileSP file_sp; - FileCache::iterator pos = m_file_cache.find(file_spec); - if (pos != m_file_cache.end()) - file_sp = pos->second; - else + file_sp = m_debugger->GetSourceFileCache().FindSourceFile (file_spec); + if (!file_sp) { file_sp.reset (new File (file_spec, m_target)); - m_file_cache[file_spec] = file_sp; + + m_debugger->GetSourceFileCache().AddSourceFile(file_sp); } return file_sp; } @@ -92,6 +103,7 @@ const SymbolContextList *bp_locs ) { + size_t return_value = 0; if (line == 0) { if (m_last_file_line != 0 @@ -134,18 +146,21 @@ ::snprintf (prefix, sizeof (prefix), " "); } - s->Printf("%s%2.2s %-4u\t", + return_value += s->Printf("%s%2.2s %-4u\t", prefix, curr_line == line ? current_line_cstr : "", curr_line); - if (m_last_file_sp->DisplaySourceLines (curr_line, 0, 0, s) == 0) + size_t this_line_size = m_last_file_sp->DisplaySourceLines (curr_line, 0, 0, s); + if (this_line_size == 0) { m_last_file_line = UINT32_MAX; break; } + else + return_value += this_line_size; } } - return 0; + return return_value; } size_t @@ -181,7 +196,7 @@ { if (m_last_file_line == UINT32_MAX) return 0; - DisplaySourceLinesWithLineNumbersUsingLastFile (0, m_last_file_context_before, m_last_file_context_after, "", s, bp_locs); + return DisplaySourceLinesWithLineNumbersUsingLastFile (0, m_last_file_context_before, m_last_file_context_after, "", s, bp_locs); } return 0; } @@ -226,8 +241,57 @@ { if (!m_mod_time.IsValid()) { - if (target && target->GetSourcePathMap().RemapPath(file_spec.GetDirectory(), m_file_spec.GetDirectory())) - m_mod_time = file_spec.GetModificationTime(); + if (target) + { + if (!file_spec.GetDirectory() && file_spec.GetFilename()) + { + // If this is just a file name, lets see if we can find it in the target: + bool check_inlines = false; + SymbolContextList sc_list; + size_t num_matches = target->GetImages().ResolveSymbolContextForFilePath (file_spec.GetFilename().AsCString(), + 0, + check_inlines, + lldb::eSymbolContextModule | lldb::eSymbolContextCompUnit, + sc_list); + bool got_multiple = false; + if (num_matches != 0) + { + if (num_matches > 1) + { + SymbolContext sc; + FileSpec *test_cu_spec = NULL; + + for (unsigned i = 0; i < num_matches; i++) + { + sc_list.GetContextAtIndex(i, sc); + if (sc.comp_unit) + { + if (test_cu_spec) + { + if (test_cu_spec != static_cast (sc.comp_unit)) + got_multiple = true; + break; + } + else + test_cu_spec = sc.comp_unit; + } + } + } + if (!got_multiple) + { + SymbolContext sc; + sc_list.GetContextAtIndex (0, sc); + m_file_spec = static_cast(sc.comp_unit); + m_mod_time = m_file_spec.GetModificationTime(); + } + } + } + else + { + if (target->GetSourcePathMap().RemapPath(file_spec.GetDirectory(), m_file_spec.GetDirectory())) + m_mod_time = file_spec.GetModificationTime(); + } + } } if (m_mod_time.IsValid()) @@ -310,6 +374,26 @@ return FileSpec::Equal (m_file_spec, file_spec, false); } +bool +lldb_private::operator== (const SourceManager::File &lhs, const SourceManager::File &rhs) +{ + if (lhs.m_file_spec == rhs.m_file_spec) + { + if (lhs.m_mod_time.IsValid()) + { + if (rhs.m_mod_time.IsValid()) + return lhs.m_mod_time == rhs.m_mod_time; + else + return false; + } + else if (rhs.m_mod_time.IsValid()) + return false; + else + return true; + } + else + return false; +} bool SourceManager::File::CalculateLineOffsets (uint32_t line) @@ -372,3 +456,28 @@ } return false; } + +void +SourceManager::SourceFileCache::AddSourceFile (const FileSP &file_sp) +{ + FileSpec file_spec; + FileCache::iterator pos = m_file_cache.find(file_spec); + if (pos == m_file_cache.end()) + m_file_cache[file_spec] = file_sp; + else + { + if (file_sp != pos->second) + m_file_cache[file_spec] = file_sp; + } +} + +SourceManager::FileSP +SourceManager::SourceFileCache::FindSourceFile (const FileSpec &file_spec) const +{ + FileSP file_sp; + FileCache::const_iterator pos = m_file_cache.find(file_spec); + if (pos != m_file_cache.end()) + file_sp = pos->second; + return file_sp; +} + Modified: lldb/trunk/source/Target/Target.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Target.cpp?rev=139564&r1=139563&r2=139564&view=diff ============================================================================== --- lldb/trunk/source/Target/Target.cpp (original) +++ lldb/trunk/source/Target/Target.cpp Mon Sep 12 19:29:56 2011 @@ -59,7 +59,7 @@ m_image_search_paths (ImageSearchPathsChanged, this), m_scratch_ast_context_ap (NULL), m_persistent_variables (), - m_source_manager(this), + m_source_manager(*this), m_stop_hooks (), m_stop_hook_next_id (0), m_suppress_stop_hooks (false) Modified: lldb/trunk/tools/driver/Driver.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/driver/Driver.cpp?rev=139564&r1=139563&r2=139564&view=diff ============================================================================== --- lldb/trunk/tools/driver/Driver.cpp (original) +++ lldb/trunk/tools/driver/Driver.cpp Mon Sep 12 19:29:56 2011 @@ -29,7 +29,6 @@ #include "lldb/API/SBEvent.h" #include "lldb/API/SBHostOS.h" #include "lldb/API/SBListener.h" -#include "lldb/API/SBSourceManager.h" #include "lldb/API/SBStream.h" #include "lldb/API/SBTarget.h" #include "lldb/API/SBThread.h" From jmolenda at apple.com Mon Sep 12 19:52:59 2011 From: jmolenda at apple.com (Jason Molenda) Date: Tue, 13 Sep 2011 00:52:59 -0000 Subject: [Lldb-commits] [lldb] r139566 - /lldb/trunk/source/Host/macosx/Host.mm Message-ID: <20110913005259.D504B2A6C12C@llvm.org> Author: jmolenda Date: Mon Sep 12 19:52:59 2011 New Revision: 139566 URL: http://llvm.org/viewvc/llvm-project?rev=139566&view=rev Log: Change the macosx Host::FindProcesses() to include all processes (running under any uid) if lldb is being run as root. It might be better to handle this up at the ProcessInstanceInfoMatch class with its m_match_all_users ivar instead of down here... Modified: lldb/trunk/source/Host/macosx/Host.mm Modified: lldb/trunk/source/Host/macosx/Host.mm URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/macosx/Host.mm?rev=139566&r1=139565&r2=139566&view=diff ============================================================================== --- lldb/trunk/source/Host/macosx/Host.mm (original) +++ lldb/trunk/source/Host/macosx/Host.mm Mon Sep 12 19:52:59 2011 @@ -1095,6 +1095,10 @@ else kinfo_user_matches = kinfo.kp_eproc.e_pcred.p_ruid == our_uid; + // Special case, if lldb is being run as root we can attach to anything. + if (our_uid == 0) + kinfo_user_matches = true; + if (kinfo_user_matches == false || // Make sure the user is acceptable kinfo.kp_proc.p_pid == our_pid || // Skip this process kinfo.kp_proc.p_pid == 0 || // Skip kernel (kernel pid is zero) From jmolenda at apple.com Mon Sep 12 20:13:17 2011 From: jmolenda at apple.com (Jason Molenda) Date: Tue, 13 Sep 2011 01:13:17 -0000 Subject: [Lldb-commits] [lldb] r139567 - /lldb/trunk/source/Target/ThreadList.cpp Message-ID: <20110913011317.1F6892A6C12C@llvm.org> Author: jmolenda Date: Mon Sep 12 20:13:16 2011 New Revision: 139567 URL: http://llvm.org/viewvc/llvm-project?rev=139567&view=rev Log: In ThreadList::GetSelectedThread, handle the case where we have no valid threads - can happen if attaching to a process fails in a certain way. Modified: lldb/trunk/source/Target/ThreadList.cpp Modified: lldb/trunk/source/Target/ThreadList.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/ThreadList.cpp?rev=139567&r1=139566&r2=139567&view=diff ============================================================================== --- lldb/trunk/source/Target/ThreadList.cpp (original) +++ lldb/trunk/source/Target/ThreadList.cpp Mon Sep 12 20:13:16 2011 @@ -548,6 +548,8 @@ ThreadSP thread_sp = FindThreadByID(m_selected_tid); if (!thread_sp.get()) { + if (m_threads.size() == 0) + return thread_sp; m_selected_tid = m_threads[0]->GetID(); thread_sp = m_threads[0]; } From johnny.chen at apple.com Mon Sep 12 20:13:20 2011 From: johnny.chen at apple.com (Johnny Chen) Date: Tue, 13 Sep 2011 01:13:20 -0000 Subject: [Lldb-commits] [lldb] r139568 - /lldb/trunk/source/Breakpoint/WatchpointLocation.cpp Message-ID: <20110913011320.B54652A6C12D@llvm.org> Author: johnny Date: Mon Sep 12 20:13:20 2011 New Revision: 139568 URL: http://llvm.org/viewvc/llvm-project?rev=139568&view=rev Log: Add trivial implementation for GetDescription(). Modified: lldb/trunk/source/Breakpoint/WatchpointLocation.cpp Modified: lldb/trunk/source/Breakpoint/WatchpointLocation.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Breakpoint/WatchpointLocation.cpp?rev=139568&r1=139567&r2=139568&view=diff ============================================================================== --- lldb/trunk/source/Breakpoint/WatchpointLocation.cpp (original) +++ lldb/trunk/source/Breakpoint/WatchpointLocation.cpp Mon Sep 12 20:13:20 2011 @@ -74,7 +74,8 @@ void WatchpointLocation::GetDescription (Stream *s, lldb::DescriptionLevel level) { - // FIXME: Add implmentation of GetDescription(). + s->Printf(" "); + Dump(s); return; } From johnny.chen at apple.com Mon Sep 12 20:15:36 2011 From: johnny.chen at apple.com (Johnny Chen) Date: Tue, 13 Sep 2011 01:15:36 -0000 Subject: [Lldb-commits] [lldb] r139569 - /lldb/trunk/source/Target/Target.cpp Message-ID: <20110913011536.EB15B2A6C12C@llvm.org> Author: johnny Date: Mon Sep 12 20:15:36 2011 New Revision: 139569 URL: http://llvm.org/viewvc/llvm-project?rev=139569&view=rev Log: Fix compiler warning. 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=139569&r1=139568&r2=139569&view=diff ============================================================================== --- lldb/trunk/source/Target/Target.cpp (original) +++ lldb/trunk/source/Target/Target.cpp Mon Sep 12 20:15:36 2011 @@ -335,6 +335,9 @@ WatchpointLocationSP wp_loc_sp; if (addr == LLDB_INVALID_ADDRESS || size == 0 || GetProcessSP()) return wp_loc_sp; + + // FIXME: Add implmenetation. + return wp_loc_sp; } void From gclayton at apple.com Mon Sep 12 23:03:53 2011 From: gclayton at apple.com (Greg Clayton) Date: Tue, 13 Sep 2011 04:03:53 -0000 Subject: [Lldb-commits] [lldb] r139582 - /lldb/trunk/source/Expression/ClangExpressionDeclMap.cpp Message-ID: <20110913040353.1BF7A2A6C12C@llvm.org> Author: gclayton Date: Mon Sep 12 23:03:52 2011 New Revision: 139582 URL: http://llvm.org/viewvc/llvm-project?rev=139582&view=rev Log: Fixed some incorrect return values. Modified: lldb/trunk/source/Expression/ClangExpressionDeclMap.cpp Modified: lldb/trunk/source/Expression/ClangExpressionDeclMap.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/ClangExpressionDeclMap.cpp?rev=139582&r1=139581&r2=139582&view=diff ============================================================================== --- lldb/trunk/source/Expression/ClangExpressionDeclMap.cpp (original) +++ lldb/trunk/source/Expression/ClangExpressionDeclMap.cpp Mon Sep 12 23:03:52 2011 @@ -919,13 +919,13 @@ if (!m_struct_vars->m_struct_laid_out) { err.SetErrorString("Structure hasn't been laid out yet"); - return LLDB_INVALID_ADDRESS; + return false; } if (!exe_ctx.frame) { err.SetErrorString("Received null execution frame"); - return LLDB_INVALID_ADDRESS; + return false; } ClangPersistentVariables &persistent_vars = exe_ctx.target->GetPersistentVariables(); From johnny.chen at apple.com Tue Sep 13 13:30:59 2011 From: johnny.chen at apple.com (Johnny Chen) Date: Tue, 13 Sep 2011 18:30:59 -0000 Subject: [Lldb-commits] [lldb] r139614 - in /lldb/trunk/source: Commands/CommandObjectFrame.cpp Target/Target.cpp Message-ID: <20110913183059.A96872A6C12C@llvm.org> Author: johnny Date: Tue Sep 13 13:30:59 2011 New Revision: 139614 URL: http://llvm.org/viewvc/llvm-project?rev=139614&view=rev Log: Get the address and the size of the variable for passing to the Target::CreateWatchpointLocation() method. Modified: lldb/trunk/source/Commands/CommandObjectFrame.cpp lldb/trunk/source/Target/Target.cpp Modified: lldb/trunk/source/Commands/CommandObjectFrame.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectFrame.cpp?rev=139614&r1=139613&r2=139614&view=diff ============================================================================== --- lldb/trunk/source/Commands/CommandObjectFrame.cpp (original) +++ lldb/trunk/source/Commands/CommandObjectFrame.cpp Tue Sep 13 13:30:59 2011 @@ -522,8 +522,14 @@ // Process watchpoint if necessary. if (m_option_watchpoint.watch_variable) { - lldb::addr_t addr = LLDB_INVALID_ADDRESS; + AddressType addr_type; + lldb::addr_t addr = valobj_sp->GetAddressOf(false, &addr_type); size_t size = 0; + if (addr_type == eAddressTypeLoad) { + // We're in business. + // Find out the size of this variable. + size = valobj_sp->GetByteSize(); + } uint32_t watch_type = m_option_watchpoint.watch_type; WatchpointLocation *wp_loc = exe_ctx.target->CreateWatchpointLocation(addr, size, watch_type).get(); Modified: lldb/trunk/source/Target/Target.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Target.cpp?rev=139614&r1=139613&r2=139614&view=diff ============================================================================== --- lldb/trunk/source/Target/Target.cpp (original) +++ lldb/trunk/source/Target/Target.cpp Tue Sep 13 13:30:59 2011 @@ -333,7 +333,12 @@ Target::CreateWatchpointLocation(lldb::addr_t addr, size_t size, uint32_t type) { WatchpointLocationSP wp_loc_sp; - if (addr == LLDB_INVALID_ADDRESS || size == 0 || GetProcessSP()) + bool process_is_valid = m_process_sp && m_process_sp->IsAlive(); + if (!process_is_valid) + return wp_loc_sp; + if (addr == LLDB_INVALID_ADDRESS) + return wp_loc_sp; + if (size == 0) return wp_loc_sp; // FIXME: Add implmenetation. From jingham at apple.com Tue Sep 13 18:25:31 2011 From: jingham at apple.com (Jim Ingham) Date: Tue, 13 Sep 2011 23:25:31 -0000 Subject: [Lldb-commits] [lldb] r139665 - in /lldb/trunk: include/lldb/API/SBDebugger.h scripts/Python/interface/SBDebugger.i source/API/SBDebugger.cpp tools/driver/Driver.cpp tools/driver/Driver.h Message-ID: <20110913232531.D5A652A6C12C@llvm.org> Author: jingham Date: Tue Sep 13 18:25:31 2011 New Revision: 139665 URL: http://llvm.org/viewvc/llvm-project?rev=139665&view=rev Log: Adding "-n", "-p" and "-w" flags to the lldb command-line tool to allow attaching from the command line. Modified: lldb/trunk/include/lldb/API/SBDebugger.h lldb/trunk/scripts/Python/interface/SBDebugger.i lldb/trunk/source/API/SBDebugger.cpp lldb/trunk/tools/driver/Driver.cpp lldb/trunk/tools/driver/Driver.h Modified: lldb/trunk/include/lldb/API/SBDebugger.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBDebugger.h?rev=139665&r1=139664&r2=139665&view=diff ============================================================================== --- lldb/trunk/include/lldb/API/SBDebugger.h (original) +++ lldb/trunk/include/lldb/API/SBDebugger.h Tue Sep 13 18:25:31 2011 @@ -56,6 +56,9 @@ void SetAsync (bool b); + + bool + GetAsync (); void SkipLLDBInitFiles (bool b); @@ -127,6 +130,9 @@ lldb::SBTarget GetSelectedTarget (); + void + SetSelectedTarget (SBTarget& target); + lldb::SBSourceManager GetSourceManager (); Modified: lldb/trunk/scripts/Python/interface/SBDebugger.i URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/Python/interface/SBDebugger.i?rev=139665&r1=139664&r2=139665&view=diff ============================================================================== --- lldb/trunk/scripts/Python/interface/SBDebugger.i (original) +++ lldb/trunk/scripts/Python/interface/SBDebugger.i Tue Sep 13 18:25:31 2011 @@ -136,6 +136,9 @@ void SetAsync (bool b); + + bool + GetAsync (); void SkipLLDBInitFiles (bool b); @@ -206,6 +209,9 @@ lldb::SBTarget GetSelectedTarget (); + void + SetSelectedTarget (lldb::SBTarget &target); + lldb::SBSourceManager GetSourceManager (); Modified: lldb/trunk/source/API/SBDebugger.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBDebugger.cpp?rev=139665&r1=139664&r2=139665&view=diff ============================================================================== --- lldb/trunk/source/API/SBDebugger.cpp (original) +++ lldb/trunk/source/API/SBDebugger.cpp Tue Sep 13 18:25:31 2011 @@ -166,6 +166,15 @@ m_opaque_sp->SetAsyncExecution(b); } +bool +SBDebugger::GetAsync () +{ + if (m_opaque_sp) + return m_opaque_sp->GetAsyncExecution(); + else + return false; +} + void SBDebugger::SkipLLDBInitFiles (bool b) { @@ -642,6 +651,24 @@ } void +SBDebugger::SetSelectedTarget (SBTarget &sb_target) +{ + LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); + + if (m_opaque_sp) + { + m_opaque_sp->GetTargetList().SetSelectedTarget (sb_target.get()); + } + if (log) + { + SBStream sstr; + sb_target.GetDescription (sstr, eDescriptionLevelBrief); + log->Printf ("SBDebugger(%p)::SetSelectedTarget () => SBTarget(%p): %s", m_opaque_sp.get(), + sb_target.get(), sstr.GetData()); + } +} + +void SBDebugger::DispatchInput (void *baton, const void *data, size_t data_len) { LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); Modified: lldb/trunk/tools/driver/Driver.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/driver/Driver.cpp?rev=139665&r1=139664&r2=139665&view=diff ============================================================================== --- lldb/trunk/tools/driver/Driver.cpp (original) +++ lldb/trunk/tools/driver/Driver.cpp Tue Sep 13 18:25:31 2011 @@ -64,21 +64,27 @@ // pass it. } OptionDefinition; -#define LLDB_2_TO_4 LLDB_OPT_SET_2|LLDB_OPT_SET_3|LLDB_OPT_SET_4 +#define LLDB_3_TO_5 LLDB_OPT_SET_3|LLDB_OPT_SET_4|LLDB_OPT_SET_5 +#define LLDB_4_TO_5 LLDB_OPT_SET_4|LLDB_OPT_SET_5 + static OptionDefinition g_options[] = { - { LLDB_OPT_SET_1, true , "help" , 'h', no_argument , NULL, eArgTypeNone, "Prints out the usage information for the LLDB debugger." }, - { LLDB_OPT_SET_2, true , "version" , 'v', no_argument , NULL, eArgTypeNone, "Prints out the current version number of the LLDB debugger." }, - { LLDB_OPT_SET_3, true , "arch" , 'a', required_argument, NULL, eArgTypeArchitecture,"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, eArgTypeScriptLang,"Tells the debugger to use the specified scripting language for user-defined scripts, rather than the default. Valid scripting languages that can be specified include Python, Perl, Ruby and Tcl. Currently only the Python extensions have been implemented." }, - { LLDB_OPT_SET_3 | LLDB_OPT_SET_4, false, "debug" , 'd', no_argument , NULL, eArgTypeNone,"Tells the debugger to print out extra information for debugging itself." }, - { LLDB_OPT_SET_3 | LLDB_OPT_SET_4, false, "source" , 's', required_argument, NULL, eArgTypeFilename, "Tells the debugger to read in and execute the file , which should contain lldb commands." }, - { LLDB_OPT_SET_3, true , "file" , 'f', required_argument, NULL, eArgTypeFilename, "Tells the debugger to use the file as the program to be debugged." }, - { LLDB_2_TO_4, false, "editor" , 'e', no_argument , NULL, eArgTypeNone, "Tells the debugger to open source files using the host's \"external editor\" mechanism." }, - { LLDB_2_TO_4, false, "no-lldbinit" , 'n', no_argument , NULL, eArgTypeNone, "Do not automatically parse any '.lldbinit' files." }, - { 0, false, NULL , 0 , 0 , NULL, eArgTypeNone, NULL } + { LLDB_OPT_SET_1, true , "help" , 'h', no_argument , NULL, eArgTypeNone, "Prints out the usage information for the LLDB debugger." }, + { LLDB_OPT_SET_2, true , "version" , 'v', no_argument , NULL, eArgTypeNone, "Prints out the current version number of the LLDB debugger." }, + { LLDB_OPT_SET_3, true , "arch" , 'a', required_argument, NULL, eArgTypeArchitecture, "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, true , "file" , 'f', required_argument, NULL, eArgTypeFilename, "Tells the debugger to use the file as the program to be debugged." }, + { LLDB_OPT_SET_4, true , "attach-name" , 'n', required_argument, NULL, eArgTypeProcessName, "Tells the debugger to attach to a process with the given name." }, + { LLDB_OPT_SET_4, true , "wait-for" , 'w', no_argument , NULL, eArgTypeNone, "Tells the debugger to wait for a process with the given pid or name to launch before attaching." }, + { LLDB_OPT_SET_5, true , "attach-pid" , 'p', required_argument, NULL, eArgTypePid, "Tells the debugger to attach to a process with the given pid." }, + { LLDB_3_TO_5, false, "script-language", 'l', required_argument, NULL, eArgTypeScriptLang, "Tells the debugger to use the specified scripting language for user-defined scripts, rather than the default. Valid scripting languages that can be specified include Python, Perl, Ruby and Tcl. Currently only the Python extensions have been implemented." }, + { LLDB_3_TO_5, false, "debug" , 'd', no_argument , NULL, eArgTypeNone, "Tells the debugger to print out extra information for debugging itself." }, + { LLDB_3_TO_5, false, "source" , 's', required_argument, NULL, eArgTypeFilename, "Tells the debugger to read in and execute the file , which should contain lldb commands." }, + { LLDB_3_TO_5, false, "editor" , 'e', no_argument , NULL, eArgTypeNone, "Tells the debugger to open source files using the host's \"external editor\" mechanism." }, + { LLDB_3_TO_5, false, "no-lldbinit" , 'x', no_argument , NULL, eArgTypeNone, "Do not automatically parse any '.lldbinit' files." }, + { 0, false, NULL , 0 , 0 , NULL, eArgTypeNone, NULL } }; +static const uint32_t last_option_set_with_args = 2; Driver::Driver () : SBBroadcaster ("Driver"), @@ -259,7 +265,7 @@ } } } - if (!is_help_line) + if (!is_help_line && (opt_set <= last_option_set_with_args)) fprintf (out, " [[--] [ ...]]"); } @@ -358,6 +364,9 @@ m_print_version (false), m_print_help (false), m_use_external_editor(false), + m_wait_for(false), + m_process_name(), + m_process_pid(LLDB_INVALID_PROCESS_ID), m_seen_options() { } @@ -376,6 +385,9 @@ m_print_help = false; m_print_version = false; m_use_external_editor = false; + m_wait_for = false; + m_process_name.erase(); + m_process_pid = LLDB_INVALID_PROCESS_ID; } void @@ -561,7 +573,7 @@ m_option_data.m_use_external_editor = true; break; - case 'n': + case 'x': m_debugger.SkipLLDBInitFiles (true); m_debugger.SkipAppInitFiles (true); break; @@ -597,6 +609,23 @@ m_option_data.m_debug_mode = true; break; + case 'n': + m_option_data.m_process_name = optarg; + break; + + case 'w': + m_option_data.m_wait_for = true; + break; + + case 'p': + { + char *remainder; + m_option_data.m_process_pid = strtol (optarg, &remainder, 0); + if (remainder == optarg || *remainder != '\0') + error.SetErrorStringWithFormat ("Could not convert process PID: \"%s\" into a pid.", + optarg); + } + break; case 's': { SBFileSpec file(optarg); @@ -645,7 +674,7 @@ { // Handle crash log stuff here. } - else + else if (m_option_data.m_process_name.empty() && m_option_data.m_process_pid == LLDB_INVALID_PROCESS_ID) { // Any arguments that are left over after option parsing are for // the program. If a file was specified with -f then the filename @@ -668,6 +697,15 @@ } } + else + { + // Skip any options we consumed with getopt_long + argc -= optind; + argv += optind; + + if (argc > 0) + ::fprintf (out_fh, "Warning: program arguments are ignored when attaching.\n"); + } return error; } @@ -1202,7 +1240,10 @@ char arg_cstr[1024]; for (size_t arg_idx = 1; arg_idx < num_args; ++arg_idx) { - ::snprintf (arg_cstr, sizeof(arg_cstr), "settings append target.process.run-args \"%s\"", m_option_data.m_args[arg_idx].c_str()); + ::snprintf (arg_cstr, + sizeof(arg_cstr), + "settings append target.process.run-args \"%s\"", + m_option_data.m_args[arg_idx].c_str()); m_debugger.HandleCommand (arg_cstr); } } @@ -1225,7 +1266,42 @@ *m_io_channel_ap, IOChannel::eBroadcastBitThreadDidStart, event); - + // If we were asked to attach, then do that here: + // I'm going to use the command string rather than directly + // calling the API's because then I don't have to recode the + // event handling here. + if (!m_option_data.m_process_name.empty() + || m_option_data.m_process_pid != LLDB_INVALID_PROCESS_ID) + { + std::string command_str("process attach "); + if (m_option_data.m_process_pid != LLDB_INVALID_PROCESS_ID) + { + command_str.append("-p "); + char pid_buffer[32]; + ::snprintf (pid_buffer, sizeof(pid_buffer), "%d", m_option_data.m_process_pid); + command_str.append(pid_buffer); + } + else + { + command_str.append("-n \""); + command_str.append(m_option_data.m_process_name); + command_str.push_back('\"'); + if (m_option_data.m_wait_for) + command_str.append(" -w"); + } + + if (m_debugger.GetOutputFileHandle()) + ::fprintf (m_debugger.GetOutputFileHandle(), + "Attaching to process with:\n %s\n", + command_str.c_str()); + + // Force the attach to be synchronous: + bool orig_async = m_debugger.GetAsync(); + m_debugger.SetAsync(true); + m_debugger.HandleCommand(command_str.c_str()); + m_debugger.SetAsync(orig_async); + } + ReadyForCommand (); bool done = false; Modified: lldb/trunk/tools/driver/Driver.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/driver/Driver.h?rev=139665&r1=139664&r2=139665&view=diff ============================================================================== --- lldb/trunk/tools/driver/Driver.h (original) +++ lldb/trunk/tools/driver/Driver.h Tue Sep 13 18:25:31 2011 @@ -105,6 +105,9 @@ bool m_debug_mode; bool m_print_version; bool m_print_help; + bool m_wait_for; + std::string m_process_name; + lldb::pid_t m_process_pid; bool m_use_external_editor; // FIXME: When we have set/show variables we can remove this from here. typedef std::set OptionSet; OptionSet m_seen_options; From johnny.chen at apple.com Tue Sep 13 18:29:31 2011 From: johnny.chen at apple.com (Johnny Chen) Date: Tue, 13 Sep 2011 23:29:31 -0000 Subject: [Lldb-commits] [lldb] r139666 - in /lldb/trunk: include/lldb/Breakpoint/WatchpointLocation.h include/lldb/Breakpoint/WatchpointLocationList.h include/lldb/Interpreter/OptionGroupWatchpoint.h source/Breakpoint/WatchpointLocation.cpp source/Breakpoint/WatchpointLocationList.cpp source/Target/Target.cpp tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.cpp Message-ID: <20110913232931.809082A6C12C@llvm.org> Author: johnny Date: Tue Sep 13 18:29:31 2011 New Revision: 139666 URL: http://llvm.org/viewvc/llvm-project?rev=139666&view=rev Log: Watchpoint WIP: o WatchpointLocationList: Add a GetListMutex() method. o WatchpointLocation: Fix Dump() method where there was an extra % in the format string. o Target.cpp: Add implementation to CreateWatchpointLocation() to create and enable a watchpoint. o DNBArchImplX86_64.cpp: Fix bugs in SetWatchpoint()/ClearWatchpoint() where '==' was used, instead of '=', to assign/reset the data break address to a debug register. Also fix bugs where a by reference debug_state should have been used, not by value. Modified: lldb/trunk/include/lldb/Breakpoint/WatchpointLocation.h lldb/trunk/include/lldb/Breakpoint/WatchpointLocationList.h lldb/trunk/include/lldb/Interpreter/OptionGroupWatchpoint.h lldb/trunk/source/Breakpoint/WatchpointLocation.cpp lldb/trunk/source/Breakpoint/WatchpointLocationList.cpp lldb/trunk/source/Target/Target.cpp lldb/trunk/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.cpp Modified: lldb/trunk/include/lldb/Breakpoint/WatchpointLocation.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Breakpoint/WatchpointLocation.h?rev=139666&r1=139665&r2=139666&view=diff ============================================================================== --- lldb/trunk/include/lldb/Breakpoint/WatchpointLocation.h (original) +++ lldb/trunk/include/lldb/Breakpoint/WatchpointLocation.h Tue Sep 13 18:29:31 2011 @@ -29,7 +29,7 @@ { public: - WatchpointLocation (lldb::addr_t m_addr, size_t size, bool hardware); + WatchpointLocation (lldb::addr_t addr, size_t size, bool hardware = true); ~WatchpointLocation (); Modified: lldb/trunk/include/lldb/Breakpoint/WatchpointLocationList.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Breakpoint/WatchpointLocationList.h?rev=139666&r1=139665&r2=139666&view=diff ============================================================================== --- lldb/trunk/include/lldb/Breakpoint/WatchpointLocationList.h (original) +++ lldb/trunk/include/lldb/Breakpoint/WatchpointLocationList.h Tue Sep 13 18:29:31 2011 @@ -174,6 +174,15 @@ GetDescription (Stream *s, lldb::DescriptionLevel level); + //------------------------------------------------------------------ + /// Sets the passed in Locker to hold the Watchpoint Location List mutex. + /// + /// @param[in] locker + /// The locker object that is set. + //------------------------------------------------------------------ + void + GetListMutex (lldb_private::Mutex::Locker &locker); + protected: typedef std::map addr_map; Modified: lldb/trunk/include/lldb/Interpreter/OptionGroupWatchpoint.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Interpreter/OptionGroupWatchpoint.h?rev=139666&r1=139665&r2=139666&view=diff ============================================================================== --- lldb/trunk/include/lldb/Interpreter/OptionGroupWatchpoint.h (original) +++ lldb/trunk/include/lldb/Interpreter/OptionGroupWatchpoint.h Tue Sep 13 18:29:31 2011 @@ -46,7 +46,7 @@ OptionParsingStarting (CommandInterpreter &interpreter); // Note: - // eWatchRead == LLDB_WATCH_TYPE_EREAD; and + // eWatchRead == LLDB_WATCH_TYPE_READ; and // eWatchWrite == LLDB_WATCH_TYPE_WRITE typedef enum WatchType { eWatchInvalid = 0, Modified: lldb/trunk/source/Breakpoint/WatchpointLocation.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Breakpoint/WatchpointLocation.cpp?rev=139666&r1=139665&r2=139666&view=diff ============================================================================== --- lldb/trunk/source/Breakpoint/WatchpointLocation.cpp (original) +++ lldb/trunk/source/Breakpoint/WatchpointLocation.cpp Tue Sep 13 18:29:31 2011 @@ -85,7 +85,7 @@ if (s == NULL) return; - s->Printf("WatchpointLocation %u: tid = %4.4x addr = 0x%8.8llx size = %zu state = %s type = %s watchpoint (%s%s) hw_index = %i hit_count = %-4u ignore_count = %-4u callback = %8p baton = %8p", + s->Printf("WatchpointLocation %u: addr = 0x%8.8llx size = %zu state = %s type = %s watchpoint (%s%s) hw_index = %i hit_count = %-4u ignore_count = %-4u callback = %8p baton = %8p", GetID(), (uint64_t)m_addr, m_byte_size, Modified: lldb/trunk/source/Breakpoint/WatchpointLocationList.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Breakpoint/WatchpointLocationList.cpp?rev=139666&r1=139665&r2=139666&view=diff ============================================================================== --- lldb/trunk/source/Breakpoint/WatchpointLocationList.cpp (original) +++ lldb/trunk/source/Breakpoint/WatchpointLocationList.cpp Tue Sep 13 18:29:31 2011 @@ -188,3 +188,8 @@ } } +void +WatchpointLocationList::GetListMutex (Mutex::Locker &locker) +{ + return locker.Reset (m_mutex.GetMutex()); +} Modified: lldb/trunk/source/Target/Target.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Target.cpp?rev=139666&r1=139665&r2=139666&view=diff ============================================================================== --- lldb/trunk/source/Target/Target.cpp (original) +++ lldb/trunk/source/Target/Target.cpp Tue Sep 13 18:29:31 2011 @@ -341,7 +341,27 @@ if (size == 0) return wp_loc_sp; - // FIXME: Add implmenetation. + WatchpointLocationSP matched_sp = m_watchpoint_location_list.FindByAddress(addr); + if (matched_sp) + { + size_t old_size = wp_loc_sp->GetByteSize(); + uint32_t old_type = + (wp_loc_sp->WatchpointRead() ? LLDB_WATCH_TYPE_READ : 0) | + (wp_loc_sp->WatchpointWrite() ? LLDB_WATCH_TYPE_WRITE : 0); + // Return an empty watchpoint location if the same one exists already. + if (size == old_size && type == old_type) + return wp_loc_sp; + + // Nil the matched watchpoint location; we will be creating a new one. + m_process_sp->DisableWatchpoint(matched_sp.get()); + m_watchpoint_location_list.Remove(matched_sp->GetID()); + } + + WatchpointLocation *new_loc = new WatchpointLocation(addr, size); + new_loc->SetWatchpointType(type); + wp_loc_sp.reset(new_loc); + m_watchpoint_location_list.Add(wp_loc_sp); + m_process_sp->EnableWatchpoint(wp_loc_sp.get()); return wp_loc_sp; } Modified: lldb/trunk/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.cpp?rev=139666&r1=139665&r2=139666&view=diff ============================================================================== --- lldb/trunk/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.cpp (original) +++ lldb/trunk/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.cpp Tue Sep 13 18:29:31 2011 @@ -481,7 +481,7 @@ if (kret != KERN_SUCCESS) return; - DBG debug_state = m_state.context.dbg; + DBG &debug_state = m_state.context.dbg; bool need_reset = false; uint32_t i, num = NumSupportedHardwareWatchpoints(); for (i = 0; i < num; ++i) @@ -650,13 +650,13 @@ size_and_rw_bits(size, read, write) << (16+4*hw_index)); switch (hw_index) { case 0: - debug_state.__dr0 == addr; break; + debug_state.__dr0 = addr; break; case 1: - debug_state.__dr1 == addr; break; + debug_state.__dr1 = addr; break; case 2: - debug_state.__dr2 == addr; break; + debug_state.__dr2 = addr; break; case 3: - debug_state.__dr3 == addr; break; + debug_state.__dr3 = addr; break; default: assert(0 && "invalid hardware register index, must be one of 0, 1, 2, or 3"); } @@ -669,13 +669,13 @@ debug_state.__dr7 &= ~(3 << (2*hw_index)); switch (hw_index) { case 0: - debug_state.__dr0 == 0; break; + debug_state.__dr0 = 0; break; case 1: - debug_state.__dr1 == 0; break; + debug_state.__dr1 = 0; break; case 2: - debug_state.__dr2 == 0; break; + debug_state.__dr2 = 0; break; case 3: - debug_state.__dr3 == 0; break; + debug_state.__dr3 = 0; break; default: assert(0 && "invalid hardware register index, must be one of 0, 1, 2, or 3"); } @@ -759,7 +759,7 @@ // Check to make sure we have the needed hardware support uint32_t i = 0; - DBG debug_state = m_state.context.dbg; + DBG &debug_state = m_state.context.dbg; for (i = 0; i < num_hw_watchpoints; ++i) { if (IsWatchpointVacant(debug_state, i)) @@ -794,7 +794,7 @@ const uint32_t num_hw_points = NumSupportedHardwareWatchpoints(); if (kret == KERN_SUCCESS) { - DBG debug_state = m_state.context.dbg; + DBG &debug_state = m_state.context.dbg; if (hw_index < num_hw_points && !IsWatchpointVacant(debug_state, hw_index)) { // Modify our local copy of the debug state, first. @@ -820,7 +820,7 @@ DNBLogThreadedIf(LOG_WATCHPOINTS, "DNBArchImplX86_64::GetHardwareWatchpointHit() GetDBGState() => 0x%8.8x.", kret); if (kret == KERN_SUCCESS) { - DBG debug_state = m_state.context.dbg; + DBG &debug_state = m_state.context.dbg; uint32_t i, num = NumSupportedHardwareWatchpoints(); for (i = 0; i < num; ++i) { From johnny.chen at apple.com Tue Sep 13 18:43:18 2011 From: johnny.chen at apple.com (Johnny Chen) Date: Tue, 13 Sep 2011 23:43:18 -0000 Subject: [Lldb-commits] [lldb] r139667 - /lldb/trunk/tools/debugserver/source/MacOSX/i386/DNBArchImplI386.cpp Message-ID: <20110913234318.3B6E72A6C12C@llvm.org> Author: johnny Date: Tue Sep 13 18:43:18 2011 New Revision: 139667 URL: http://llvm.org/viewvc/llvm-project?rev=139667&view=rev Log: Update I386 DNB impl to fix the same errors as DNBArchImplX86_64: ('==' instead of '=') and (by value instead of by reference). Modified: lldb/trunk/tools/debugserver/source/MacOSX/i386/DNBArchImplI386.cpp Modified: lldb/trunk/tools/debugserver/source/MacOSX/i386/DNBArchImplI386.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/MacOSX/i386/DNBArchImplI386.cpp?rev=139667&r1=139666&r2=139667&view=diff ============================================================================== --- lldb/trunk/tools/debugserver/source/MacOSX/i386/DNBArchImplI386.cpp (original) +++ lldb/trunk/tools/debugserver/source/MacOSX/i386/DNBArchImplI386.cpp Tue Sep 13 18:43:18 2011 @@ -552,7 +552,7 @@ if (kret != KERN_SUCCESS) return; - DBG debug_state = m_state.context.dbg; + DBG &debug_state = m_state.context.dbg; bool need_reset = false; uint32_t i, num = NumSupportedHardwareWatchpoints(); for (i = 0; i < num; ++i) @@ -722,13 +722,13 @@ uint32_t addr_32 = addr & 0xffffffff; switch (hw_index) { case 0: - debug_state.__dr0 == addr_32; break; + debug_state.__dr0 = addr_32; break; case 1: - debug_state.__dr1 == addr_32; break; + debug_state.__dr1 = addr_32; break; case 2: - debug_state.__dr2 == addr_32; break; + debug_state.__dr2 = addr_32; break; case 3: - debug_state.__dr3 == addr_32; break; + debug_state.__dr3 = addr_32; break; default: assert(0 && "invalid hardware register index, must be one of 0, 1, 2, or 3"); } @@ -741,13 +741,13 @@ debug_state.__dr7 &= ~(3 << (2*hw_index)); switch (hw_index) { case 0: - debug_state.__dr0 == 0; break; + debug_state.__dr0 = 0; break; case 1: - debug_state.__dr1 == 0; break; + debug_state.__dr1 = 0; break; case 2: - debug_state.__dr2 == 0; break; + debug_state.__dr2 = 0; break; case 3: - debug_state.__dr3 == 0; break; + debug_state.__dr3 = 0; break; default: assert(0 && "invalid hardware register index, must be one of 0, 1, 2, or 3"); } @@ -831,7 +831,7 @@ // Check to make sure we have the needed hardware support uint32_t i = 0; - DBG debug_state = m_state.context.dbg; + DBG &debug_state = m_state.context.dbg; for (i = 0; i < num_hw_watchpoints; ++i) { if (IsWatchpointVacant(debug_state, i)) @@ -866,7 +866,7 @@ const uint32_t num_hw_points = NumSupportedHardwareWatchpoints(); if (kret == KERN_SUCCESS) { - DBG debug_state = m_state.context.dbg; + DBG &debug_state = m_state.context.dbg; if (hw_index < num_hw_points && !IsWatchpointVacant(debug_state, hw_index)) { // Modify our local copy of the debug state, first. @@ -892,7 +892,7 @@ DNBLogThreadedIf(LOG_WATCHPOINTS, "DNBArchImplI386::GetHardwareWatchpointHit() GetDBGState() => 0x%8.8x.", kret); if (kret == KERN_SUCCESS) { - DBG debug_state = m_state.context.dbg; + DBG &debug_state = m_state.context.dbg; uint32_t i, num = NumSupportedHardwareWatchpoints(); for (i = 0; i < num; ++i) { From johnny.chen at apple.com Tue Sep 13 19:26:03 2011 From: johnny.chen at apple.com (Johnny Chen) Date: Wed, 14 Sep 2011 00:26:03 -0000 Subject: [Lldb-commits] [lldb] r139673 - /lldb/trunk/source/Target/Target.cpp Message-ID: <20110914002603.809302A6C12C@llvm.org> Author: johnny Date: Tue Sep 13 19:26:03 2011 New Revision: 139673 URL: http://llvm.org/viewvc/llvm-project?rev=139673&view=rev Log: Add comments. 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=139673&r1=139672&r2=139673&view=diff ============================================================================== --- lldb/trunk/source/Target/Target.cpp (original) +++ lldb/trunk/source/Target/Target.cpp Tue Sep 13 19:26:03 2011 @@ -328,7 +328,8 @@ return bp_sp; } -// See also WatchpointLocation::SetWatchpointType() and OptionGroupWatchpoint::WatchType. +// See also WatchpointLocation::SetWatchpointType(uint32_t type) and +// the OptionGroupWatchpoint::WatchType enum type. WatchpointLocationSP Target::CreateWatchpointLocation(lldb::addr_t addr, size_t size, uint32_t type) { @@ -341,6 +342,9 @@ if (size == 0) return wp_loc_sp; + // Currently we only support one watchpoint location per address, with total + // number of watchpoint locations limited by the hardware which the inferior + // is running on. WatchpointLocationSP matched_sp = m_watchpoint_location_list.FindByAddress(addr); if (matched_sp) { From jingham at apple.com Tue Sep 13 20:01:48 2011 From: jingham at apple.com (Jim Ingham) Date: Wed, 14 Sep 2011 01:01:48 -0000 Subject: [Lldb-commits] [lldb] r139679 - /lldb/trunk/source/Target/Process.cpp Message-ID: <20110914010148.F16602A6C12C@llvm.org> Author: jingham Date: Tue Sep 13 20:01:48 2011 New Revision: 139679 URL: http://llvm.org/viewvc/llvm-project?rev=139679&view=rev Log: If we haven't gotten the architecture of the process we're attaching to by the time we get to the AttachCompletionHandler, do it before completing the attach. Modified: lldb/trunk/source/Target/Process.cpp Modified: lldb/trunk/source/Target/Process.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Process.cpp?rev=139679&r1=139678&r2=139679&view=diff ============================================================================== --- lldb/trunk/source/Target/Process.cpp (original) +++ lldb/trunk/source/Target/Process.cpp Tue Sep 13 20:01:48 2011 @@ -2167,6 +2167,25 @@ // lldb_private::Process subclasses must set the process must set // the new process ID. assert (m_process->GetID() != LLDB_INVALID_PROCESS_ID); + // We just attached, if we haven't gotten a valid architecture at this point we should do so now. + Target &target = m_process->GetTarget(); + if (!target.GetArchitecture().IsValid()) + { + // FIXME: We shouldn't be getting the Selected Platform, there should + // be a platform for the target, and we should get that. + PlatformSP platform_sp (target.GetDebugger().GetPlatformList().GetSelectedPlatform ()); + if (platform_sp) + { + ProcessInstanceInfo process_info; + platform_sp->GetProcessInfo (m_process->GetID(), process_info); + const ArchSpec &process_arch = process_info.GetArchitecture(); + if (process_arch.IsValid()) + { + // Set the architecture on the target. + target.SetArchitecture (process_arch); + } + } + } m_process->CompleteAttach (); return eEventActionSuccess; } From filcab+lldb-dev at gmail.com Wed Sep 14 13:13:06 2011 From: filcab+lldb-dev at gmail.com (Filipe Cabecinhas) Date: Wed, 14 Sep 2011 11:13:06 -0700 Subject: [Lldb-commits] [lldb-dev] FreeBSD fixes In-Reply-To: References: Message-ID: Hi, Sorry for the delay. I started doing some stuff withou replying. I was creating the Process plugin, but there are some problems, like repeated enumerations, and some other issues. To minimize syncing problems, it would be better for me to start changing DNB.h in-place (if it's possible), to use lldb's enumerations and other small fixes. At the same time I would be writing the Process plugin that uses libdebugnub. How do you suggest to organize the code? libdebugnub seems to hold as a library that we could use in lldb for the ProcessHostDebugger, but I'm not seeing a good place to put it (it's weird to put it in Core/, but it seems like the best place (or on the Plugin/Process/Utility/ or a Plugin/HostDebugger/Utility folders). What do you think? Regards, Filipe On Thu, Sep 8, 2011 at 16:18, Greg Clayton wrote: > > On Sep 8, 2011, at 3:58 PM, Filipe Cabecinhas wrote: > > > Hi, I tried sending this message earlier, but it seems it got lost along > the way. > > > > I'm re-sending the patch for allowing "target create" on the > remote-macosx platform and another patch to augment the FreeBSD platform and > make it like the Mac OS X platform. > > In order to make the FreeBSD platform we will have to, either implement a > local platform (like the Linux one) or implement debugserver on FreeBSD. I'm > leaning on the second solution as it would offer us remote debugging for > free. > > > > I just want to confirm something: Is debugserver portable? I'm supposing > debugserver is MacOSX specific, but I may be looking at the wrong parts of > the code. > > It is currently very specific. For porting to new systems, we should make > binary similar to the lldb-platform binary. It links against the innards of > lldb-core, and it also uses the GDBRemoteCommunicationServer class, which is > the GDB server side of the GDB remote protocol in LLDB. The > GDBRemoteCommunicationServer is a very clean interface and gets you all of > the supported packet management built in. It should be extended to do all of > the debugging stuff through an interface which is similar to the DNB.h. The > DNB.h is a very clean interface as well, but we should copy it, and make a > new version that is host agnostic (there are a few "#include " in > the DNB.h version). If we abstract all debugging for all systems though a > clean interface like the one in "DNB.h", then we can also have native > debugger plug-ins that use this interface and allows us to have a native > debugger plug-in, _and_ a remote debugger plug-in that use the exact same > debug code. > > So the steps as I see them: > - Copy DNB.h and remame it to HostDebugger.h and place it into LLDB core > code and use it as the basis for all local native debugging, both local and > remote > - Create a new Process plug-in named ProcessHostDebugger that would use the > new HostDebugger.h interface > - Use GDBRemoteCommunicationServer.h to implement a new GDB server binary > named "lldb-gdb-server" and have it link to lldb-core like lldb-platform > already does and have it use the "HostDebugger.h" to implement the debugging > inside GDBRemoteCommunicationServer or a subclass. > > We can look at the code in debugserver for reference, but I wouldn't use it > as the basis for any new GDB server implementations. > > Does this make sense? > > Greg > > > > > Thanks, > > > > Filipe > > > > > > > _______________________________________________ > > lldb-dev mailing list > > lldb-dev at cs.uiuc.edu > > http://lists.cs.uiuc.edu/mailman/listinfo/lldb-dev > > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.cs.uiuc.edu/pipermail/lldb-commits/attachments/20110914/c4c65265/attachment.html From gclayton at apple.com Wed Sep 14 14:38:14 2011 From: gclayton at apple.com (Greg Clayton) Date: Wed, 14 Sep 2011 12:38:14 -0700 Subject: [Lldb-commits] [lldb-dev] FreeBSD fixes In-Reply-To: References: Message-ID: <11F66E46-6077-483F-903B-72270F7D3785@apple.com> On Sep 14, 2011, at 11:13 AM, Filipe Cabecinhas wrote: > Hi, > > Sorry for the delay. I started doing some stuff withou replying. > > I was creating the Process plugin, but there are some problems, like repeated enumerations, and some other issues. To minimize syncing problems, it would be better for me to start changing DNB.h in-place (if it's possible), to use lldb's enumerations and other small fixes. Please don't change DNB.h in place, we currently use this for our remote debugging and we can't afford any side affects from any changes. It might be good to duplicate and rename the file, possibly to "NativeDebug.h" and move it into "Host" since this is a host debugging issue and the implemenatations are going to host specific and often require native headers in order to compile. We will want to change the DNB prefix on all functions to something else like LLDBHostDebug. > At the same time I would be writing the Process plugin that uses libdebugnub. Yeah, the DNB.h (or now "Host/NativeDebug.h"??) interface could also be placed into a dylib, or just linked in as a static library or using the .o files. > > How do you suggest to organize the code? libdebugnub seems to hold as a library that we could use in lldb for the ProcessHostDebugger, but I'm not seeing a good place to put it (it's weird to put it in Core/, but it seems like the best place (or on the Plugin/Process/Utility/ or a Plugin/HostDebugger/Utility folders). This would be a Host specific thing, so I would vote for "lldb/Host/NativeDebug.h" or "lldb/Host/Debug.h". > > What do you think? > > Regards, > > Filipe > > > On Thu, Sep 8, 2011 at 16:18, Greg Clayton wrote: > > On Sep 8, 2011, at 3:58 PM, Filipe Cabecinhas wrote: > > > Hi, I tried sending this message earlier, but it seems it got lost along the way. > > > > I'm re-sending the patch for allowing "target create" on the remote-macosx platform and another patch to augment the FreeBSD platform and make it like the Mac OS X platform. > > In order to make the FreeBSD platform we will have to, either implement a local platform (like the Linux one) or implement debugserver on FreeBSD. I'm leaning on the second solution as it would offer us remote debugging for free. > > > > I just want to confirm something: Is debugserver portable? I'm supposing debugserver is MacOSX specific, but I may be looking at the wrong parts of the code. > > It is currently very specific. For porting to new systems, we should make binary similar to the lldb-platform binary. It links against the innards of lldb-core, and it also uses the GDBRemoteCommunicationServer class, which is the GDB server side of the GDB remote protocol in LLDB. The GDBRemoteCommunicationServer is a very clean interface and gets you all of the supported packet management built in. It should be extended to do all of the debugging stuff through an interface which is similar to the DNB.h. The DNB.h is a very clean interface as well, but we should copy it, and make a new version that is host agnostic (there are a few "#include " in the DNB.h version). If we abstract all debugging for all systems though a clean interface like the one in "DNB.h", then we can also have native debugger plug-ins that use this interface and allows us to have a native debugger plug-in, _and_ a remote debugger plug-in that use the exact same debug code. > > So the steps as I see them: > - Copy DNB.h and remame it to HostDebugger.h and place it into LLDB core code and use it as the basis for all local native debugging, both local and remote > - Create a new Process plug-in named ProcessHostDebugger that would use the new HostDebugger.h interface > - Use GDBRemoteCommunicationServer.h to implement a new GDB server binary named "lldb-gdb-server" and have it link to lldb-core like lldb-platform already does and have it use the "HostDebugger.h" to implement the debugging inside GDBRemoteCommunicationServer or a subclass. > > We can look at the code in debugserver for reference, but I wouldn't use it as the basis for any new GDB server implementations. > > Does this make sense? > > Greg > > > > > Thanks, > > > > Filipe > > > > > > _______________________________________________ > > lldb-dev mailing list > > lldb-dev at cs.uiuc.edu > > http://lists.cs.uiuc.edu/mailman/listinfo/lldb-dev > > From johnny.chen at apple.com Wed Sep 14 15:23:45 2011 From: johnny.chen at apple.com (Johnny Chen) Date: Wed, 14 Sep 2011 20:23:45 -0000 Subject: [Lldb-commits] [lldb] r139724 - in /lldb/trunk/source: Breakpoint/WatchpointLocation.cpp Target/Target.cpp Message-ID: <20110914202345.CCC832A6C12C@llvm.org> Author: johnny Date: Wed Sep 14 15:23:45 2011 New Revision: 139724 URL: http://llvm.org/viewvc/llvm-project?rev=139724&view=rev Log: Add logging to Target::CreateWatchpointLocation() and fix some bug of using the wrong variable. Plus simplify WatchpointLocation::Dump() output. Modified: lldb/trunk/source/Breakpoint/WatchpointLocation.cpp lldb/trunk/source/Target/Target.cpp Modified: lldb/trunk/source/Breakpoint/WatchpointLocation.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Breakpoint/WatchpointLocation.cpp?rev=139724&r1=139723&r2=139724&view=diff ============================================================================== --- lldb/trunk/source/Breakpoint/WatchpointLocation.cpp (original) +++ lldb/trunk/source/Breakpoint/WatchpointLocation.cpp Wed Sep 14 15:23:45 2011 @@ -85,15 +85,13 @@ if (s == NULL) return; - s->Printf("WatchpointLocation %u: addr = 0x%8.8llx size = %zu state = %s type = %s watchpoint (%s%s) hw_index = %i hit_count = %-4u ignore_count = %-4u callback = %8p baton = %8p", + s->Printf("WatchpointLocation %u: addr = 0x%8.8llx size = %zu state = %s type = %s%s hit_count = %-4u ignore_count = %-4u callback = %8p baton = %8p", GetID(), (uint64_t)m_addr, m_byte_size, m_enabled ? "enabled " : "disabled", - IsHardware() ? "hardware" : "software", m_watch_read ? "r" : "", m_watch_write ? "w" : "", - GetHardwareIndex(), GetHitCount(), GetIgnoreCount(), m_callback, Modified: lldb/trunk/source/Target/Target.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Target.cpp?rev=139724&r1=139723&r2=139724&view=diff ============================================================================== --- lldb/trunk/source/Target/Target.cpp (original) +++ lldb/trunk/source/Target/Target.cpp Wed Sep 14 15:23:45 2011 @@ -333,6 +333,11 @@ WatchpointLocationSP Target::CreateWatchpointLocation(lldb::addr_t addr, size_t size, uint32_t type) { + LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS)); + if (log) + log->Printf("Target::%s (addr = 0x%8.8llx size = %zu type = %u)\n", + __FUNCTION__, addr, size, type); + WatchpointLocationSP wp_loc_sp; bool process_is_valid = m_process_sp && m_process_sp->IsAlive(); if (!process_is_valid) @@ -348,10 +353,10 @@ WatchpointLocationSP matched_sp = m_watchpoint_location_list.FindByAddress(addr); if (matched_sp) { - size_t old_size = wp_loc_sp->GetByteSize(); + size_t old_size = matched_sp->GetByteSize(); uint32_t old_type = - (wp_loc_sp->WatchpointRead() ? LLDB_WATCH_TYPE_READ : 0) | - (wp_loc_sp->WatchpointWrite() ? LLDB_WATCH_TYPE_WRITE : 0); + (matched_sp->WatchpointRead() ? LLDB_WATCH_TYPE_READ : 0) | + (matched_sp->WatchpointWrite() ? LLDB_WATCH_TYPE_WRITE : 0); // Return an empty watchpoint location if the same one exists already. if (size == old_size && type == old_type) return wp_loc_sp; @@ -362,10 +367,22 @@ } WatchpointLocation *new_loc = new WatchpointLocation(addr, size); + if (!new_loc) + printf("WatchpointLocation ctor failed, out of memory?\n"); + new_loc->SetWatchpointType(type); wp_loc_sp.reset(new_loc); m_watchpoint_location_list.Add(wp_loc_sp); - m_process_sp->EnableWatchpoint(wp_loc_sp.get()); + Error rc = m_process_sp->EnableWatchpoint(wp_loc_sp.get()); + if (rc.Success()) + wp_loc_sp->SetEnabled(true); + + if (log) + log->Printf("Target::%s (creation of watchpoint %s with id = %u)\n", + __FUNCTION__, + rc.Success() ? "succeeded" : "failed", + wp_loc_sp->GetID()); + return wp_loc_sp; } From johnny.chen at apple.com Wed Sep 14 17:20:15 2011 From: johnny.chen at apple.com (Johnny Chen) Date: Wed, 14 Sep 2011 22:20:15 -0000 Subject: [Lldb-commits] [lldb] r139746 - /lldb/trunk/source/Target/Target.cpp Message-ID: <20110914222015.3EBB62A6C12C@llvm.org> Author: johnny Date: Wed Sep 14 17:20:15 2011 New Revision: 139746 URL: http://llvm.org/viewvc/llvm-project?rev=139746&view=rev Log: Fix a bug where re-use of the same existing target-wise watchpoint did not work correctly. 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=139746&r1=139745&r2=139746&view=diff ============================================================================== --- lldb/trunk/source/Target/Target.cpp (original) +++ lldb/trunk/source/Target/Target.cpp Wed Sep 14 17:20:15 2011 @@ -342,9 +342,7 @@ bool process_is_valid = m_process_sp && m_process_sp->IsAlive(); if (!process_is_valid) return wp_loc_sp; - if (addr == LLDB_INVALID_ADDRESS) - return wp_loc_sp; - if (size == 0) + if (addr == LLDB_INVALID_ADDRESS || size == 0) return wp_loc_sp; // Currently we only support one watchpoint location per address, with total @@ -357,32 +355,36 @@ uint32_t old_type = (matched_sp->WatchpointRead() ? LLDB_WATCH_TYPE_READ : 0) | (matched_sp->WatchpointWrite() ? LLDB_WATCH_TYPE_WRITE : 0); - // Return an empty watchpoint location if the same one exists already. - if (size == old_size && type == old_type) - return wp_loc_sp; + // Return the existing watchpoint location if both size and type match. + if (size == old_size && type == old_type) { + wp_loc_sp = matched_sp; + wp_loc_sp->SetEnabled(false); + } else { + // Nil the matched watchpoint location; we will be creating a new one. + m_process_sp->DisableWatchpoint(matched_sp.get()); + m_watchpoint_location_list.Remove(matched_sp->GetID()); + } + } - // Nil the matched watchpoint location; we will be creating a new one. - m_process_sp->DisableWatchpoint(matched_sp.get()); - m_watchpoint_location_list.Remove(matched_sp->GetID()); + if (!wp_loc_sp) { + WatchpointLocation *new_loc = new WatchpointLocation(addr, size); + if (!new_loc) { + printf("WatchpointLocation ctor failed, out of memory?\n"); + return wp_loc_sp; + } + new_loc->SetWatchpointType(type); + wp_loc_sp.reset(new_loc); + m_watchpoint_location_list.Add(wp_loc_sp); } - WatchpointLocation *new_loc = new WatchpointLocation(addr, size); - if (!new_loc) - printf("WatchpointLocation ctor failed, out of memory?\n"); - - new_loc->SetWatchpointType(type); - wp_loc_sp.reset(new_loc); - m_watchpoint_location_list.Add(wp_loc_sp); Error rc = m_process_sp->EnableWatchpoint(wp_loc_sp.get()); - if (rc.Success()) - wp_loc_sp->SetEnabled(true); - if (log) log->Printf("Target::%s (creation of watchpoint %s with id = %u)\n", __FUNCTION__, rc.Success() ? "succeeded" : "failed", wp_loc_sp->GetID()); + if (rc.Fail()) wp_loc_sp.reset(); return wp_loc_sp; } From gclayton at apple.com Wed Sep 14 19:21:04 2011 From: gclayton at apple.com (Greg Clayton) Date: Thu, 15 Sep 2011 00:21:04 -0000 Subject: [Lldb-commits] [lldb] r139759 - /lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp Message-ID: <20110915002104.0E1EF2A6C12C@llvm.org> Author: gclayton Date: Wed Sep 14 19:21:03 2011 New Revision: 139759 URL: http://llvm.org/viewvc/llvm-project?rev=139759&view=rev Log: Set the OS in the triple correctly in response to the qHostInfo packet. Modified: lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp Modified: lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp?rev=139759&r1=139758&r2=139759&view=diff ============================================================================== --- lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp (original) +++ lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp Wed Sep 14 19:21:03 2011 @@ -949,7 +949,7 @@ if (!vendor_name.empty()) m_host_arch.GetTriple().setVendorName (llvm::StringRef (vendor_name)); if (!os_name.empty()) - m_host_arch.GetTriple().setVendorName (llvm::StringRef (os_name)); + m_host_arch.GetTriple().setOSName (llvm::StringRef (os_name)); } } From jmolenda at apple.com Wed Sep 14 19:44:34 2011 From: jmolenda at apple.com (Jason Molenda) Date: Thu, 15 Sep 2011 00:44:34 -0000 Subject: [Lldb-commits] [lldb] r139760 - in /lldb/trunk: include/lldb/Symbol/FuncUnwinders.h source/Plugins/ABI/MacOSX-arm/ABIMacOSX_arm.cpp source/Plugins/ABI/MacOSX-i386/ABIMacOSX_i386.cpp source/Plugins/ABI/SysV-x86_64/ABISysV_x86_64.cpp source/Plugins/Process/Utility/RegisterContextLLDB.cpp source/Symbol/FuncUnwinders.cpp Message-ID: <20110915004434.6F6882A6C12C@llvm.org> Author: jmolenda Date: Wed Sep 14 19:44:34 2011 New Revision: 139760 URL: http://llvm.org/viewvc/llvm-project?rev=139760&view=rev Log: Have the FuncUnwinder object request & provide an architecture-defined UnwindPlan for unwinding from the first instruction of an otherwise unknown function call (GetUnwindPlanArchitectureDefaultAtFunctionEntry()). Update RegisterContextLLDB::GetFullUnwindPlanForFrame() to detect the case of a frame 0 at address 0x0 which indicates that we jumped through a NULL function pointer. Use the ABI's FunctionEntryUnwindPlan to find the caller frame. These changes make it so lldb can identify the calling frame correctly in code like int main () { void (*f)(void) = 0; f(); } Modified: lldb/trunk/include/lldb/Symbol/FuncUnwinders.h lldb/trunk/source/Plugins/ABI/MacOSX-arm/ABIMacOSX_arm.cpp lldb/trunk/source/Plugins/ABI/MacOSX-i386/ABIMacOSX_i386.cpp lldb/trunk/source/Plugins/ABI/SysV-x86_64/ABISysV_x86_64.cpp lldb/trunk/source/Plugins/Process/Utility/RegisterContextLLDB.cpp lldb/trunk/source/Symbol/FuncUnwinders.cpp Modified: lldb/trunk/include/lldb/Symbol/FuncUnwinders.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Symbol/FuncUnwinders.h?rev=139760&r1=139759&r2=139760&view=diff ============================================================================== --- lldb/trunk/include/lldb/Symbol/FuncUnwinders.h (original) +++ lldb/trunk/include/lldb/Symbol/FuncUnwinders.h Wed Sep 14 19:44:34 2011 @@ -55,6 +55,9 @@ lldb::UnwindPlanSP GetUnwindPlanArchitectureDefault (lldb_private::Thread& thread); + lldb::UnwindPlanSP + GetUnwindPlanArchitectureDefaultAtFunctionEntry (lldb_private::Thread& thread); + Address& GetFirstNonPrologueInsn (Target& target); @@ -78,11 +81,14 @@ lldb::UnwindPlanSP m_unwind_plan_non_call_site_sp; lldb::UnwindPlanSP m_unwind_plan_fast_sp; lldb::UnwindPlanSP m_unwind_plan_arch_default_sp; + lldb::UnwindPlanSP m_unwind_plan_arch_default_at_func_entry_sp; bool m_tried_unwind_at_call_site:1, m_tried_unwind_at_non_call_site:1, m_tried_unwind_fast:1, - m_tried_unwind_arch_default:1; + m_tried_unwind_arch_default:1, + m_tried_unwind_arch_default_at_func_entry:1; + Address m_first_non_prologue_insn; Modified: lldb/trunk/source/Plugins/ABI/MacOSX-arm/ABIMacOSX_arm.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ABI/MacOSX-arm/ABIMacOSX_arm.cpp?rev=139760&r1=139759&r2=139760&view=diff ============================================================================== --- lldb/trunk/source/Plugins/ABI/MacOSX-arm/ABIMacOSX_arm.cpp (original) +++ lldb/trunk/source/Plugins/ABI/MacOSX-arm/ABIMacOSX_arm.cpp Wed Sep 14 19:44:34 2011 @@ -538,7 +538,7 @@ // All other registers are the same. - unwind_plan.SetSourceName (pluginName); + unwind_plan.SetSourceName ("arm at-func-entry default"); return true; } Modified: lldb/trunk/source/Plugins/ABI/MacOSX-i386/ABIMacOSX_i386.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ABI/MacOSX-i386/ABIMacOSX_i386.cpp?rev=139760&r1=139759&r2=139760&view=diff ============================================================================== --- lldb/trunk/source/Plugins/ABI/MacOSX-i386/ABIMacOSX_i386.cpp (original) +++ lldb/trunk/source/Plugins/ABI/MacOSX-i386/ABIMacOSX_i386.cpp Wed Sep 14 19:44:34 2011 @@ -803,7 +803,7 @@ row.SetCFAOffset (4); row.SetRegisterLocationToAtCFAPlusOffset(pc_reg_num, -4, false); unwind_plan.AppendRow (row); - unwind_plan.SetSourceName (pluginName); + unwind_plan.SetSourceName ("i386 at-func-entry default"); return true; } Modified: lldb/trunk/source/Plugins/ABI/SysV-x86_64/ABISysV_x86_64.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ABI/SysV-x86_64/ABISysV_x86_64.cpp?rev=139760&r1=139759&r2=139760&view=diff ============================================================================== --- lldb/trunk/source/Plugins/ABI/SysV-x86_64/ABISysV_x86_64.cpp (original) +++ lldb/trunk/source/Plugins/ABI/SysV-x86_64/ABISysV_x86_64.cpp Wed Sep 14 19:44:34 2011 @@ -661,7 +661,7 @@ row.SetCFAOffset (8); row.SetRegisterLocationToAtCFAPlusOffset(pc_reg_num, -8, false); unwind_plan.AppendRow (row); - unwind_plan.SetSourceName (pluginName); + unwind_plan.SetSourceName ("x86_64 at-func-entry default"); return true; } Modified: lldb/trunk/source/Plugins/Process/Utility/RegisterContextLLDB.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Utility/RegisterContextLLDB.cpp?rev=139760&r1=139759&r2=139760&view=diff ============================================================================== --- lldb/trunk/source/Plugins/Process/Utility/RegisterContextLLDB.cpp (original) +++ lldb/trunk/source/Plugins/Process/Utility/RegisterContextLLDB.cpp Wed Sep 14 19:44:34 2011 @@ -552,7 +552,19 @@ m_all_registers_available = true; } - // No Module for the current pc, try using the architecture default unwind. + // If we've done a jmp 0x0 / bl 0x0 (called through a null function pointer) so the pc is 0x0 + // in the zeroth frame, we need to use the "unwind at first instruction" arch default UnwindPlan + if (behaves_like_zeroth_frame + && m_current_pc.IsValid() + && m_current_pc.GetLoadAddress (&m_thread.GetProcess().GetTarget()) == 0) + { + unwind_plan_sp.reset (new UnwindPlan (lldb::eRegisterKindGeneric)); + abi->CreateFunctionEntryUnwindPlan(*unwind_plan_sp); + m_frame_type = eNormalFrame; + return unwind_plan_sp; + } + + // No Module fm_current_pc.GetLoadAddress (&m_thread.GetProcess().GetTarget()or the current pc, try using the architecture default unwind. if (!m_current_pc.IsValid() || m_current_pc.GetModule() == NULL || m_current_pc.GetModule()->GetObjectFile() == NULL) { m_frame_type = eNormalFrame; Modified: lldb/trunk/source/Symbol/FuncUnwinders.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/FuncUnwinders.cpp?rev=139760&r1=139759&r2=139760&view=diff ============================================================================== --- lldb/trunk/source/Symbol/FuncUnwinders.cpp (original) +++ lldb/trunk/source/Symbol/FuncUnwinders.cpp Wed Sep 14 19:44:34 2011 @@ -42,6 +42,7 @@ m_tried_unwind_at_non_call_site (false), m_tried_unwind_fast (false), m_tried_unwind_arch_default (false), + m_tried_unwind_arch_default_at_func_entry (false), m_first_non_prologue_insn() { } @@ -181,6 +182,43 @@ return m_unwind_plan_arch_default_sp; } +UnwindPlanSP +FuncUnwinders::GetUnwindPlanArchitectureDefaultAtFunctionEntry (Thread& thread) +{ + // Lock the mutex to ensure we can always give out the most appropriate + // information. We want to make sure if someone requests an unwind + // plan, that they get one and don't run into a race condition where one + // thread has started to create the unwind plan and has put it into + // the auto_ptr member variable, and have another thread enter this function + // and return the partially filled pointer contained in the auto_ptr. + // We also want to make sure that we lock out other unwind plans from + // being accessed until this one is done creating itself in case someone + // had some code like: + // UnwindPlan *best_unwind_plan = ...GetUnwindPlanAtCallSite (...) + // if (best_unwind_plan == NULL) + // best_unwind_plan = GetUnwindPlanAtNonCallSite (...) + Mutex::Locker locker (m_mutex); + if (m_tried_unwind_arch_default_at_func_entry == false && m_unwind_plan_arch_default_at_func_entry_sp.get() == NULL) + { + m_tried_unwind_arch_default_at_func_entry = true; + Address current_pc; + Target *target = thread.CalculateTarget(); + if (target) + { + ABI *abi = thread.GetProcess().GetABI().get(); + if (abi) + { + m_unwind_plan_arch_default_at_func_entry_sp.reset (new UnwindPlan (lldb::eRegisterKindGeneric)); + if (m_unwind_plan_arch_default_at_func_entry_sp) + abi->CreateFunctionEntryUnwindPlan(*m_unwind_plan_arch_default_at_func_entry_sp); + } + } + } + + return m_unwind_plan_arch_default_sp; +} + + Address& FuncUnwinders::GetFirstNonPrologueInsn (Target& target) { From jingham at apple.com Wed Sep 14 20:07:28 2011 From: jingham at apple.com (Jim Ingham) Date: Thu, 15 Sep 2011 01:07:28 -0000 Subject: [Lldb-commits] [lldb] r139761 - /lldb/trunk/include/lldb/Core/ArchSpec.h Message-ID: <20110915010728.A83BF2A6C12C@llvm.org> Author: jingham Date: Wed Sep 14 20:07:28 2011 New Revision: 139761 URL: http://llvm.org/viewvc/llvm-project?rev=139761&view=rev Log: Fix ArchSpec::operator== to take the Triple into account as well as the Core. Also make the constructors explicit. Modified: lldb/trunk/include/lldb/Core/ArchSpec.h Modified: lldb/trunk/include/lldb/Core/ArchSpec.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/ArchSpec.h?rev=139761&r1=139760&r2=139761&view=diff ============================================================================== --- lldb/trunk/include/lldb/Core/ArchSpec.h (original) +++ lldb/trunk/include/lldb/Core/ArchSpec.h Wed Sep 14 20:07:28 2011 @@ -112,7 +112,9 @@ /// Constructs an ArchSpec with properties consistent with the given /// Triple. //------------------------------------------------------------------ + explicit ArchSpec (const llvm::Triple &triple); + explicit ArchSpec (const char *triple_cstr, Platform *platform); //------------------------------------------------------------------ /// Constructor over architecture name. @@ -120,6 +122,7 @@ /// Constructs an ArchSpec with properties consistent with the given /// object type and architecture name. //------------------------------------------------------------------ + explicit ArchSpec (ArchitectureType arch_type, uint32_t cpu_type, uint32_t cpu_subtype); From jingham at apple.com Wed Sep 14 20:07:30 2011 From: jingham at apple.com (Jim Ingham) Date: Thu, 15 Sep 2011 01:07:30 -0000 Subject: [Lldb-commits] [lldb] r139762 - /lldb/trunk/source/Core/ArchSpec.cpp Message-ID: <20110915010730.8A8942A6C12D@llvm.org> Author: jingham Date: Wed Sep 14 20:07:30 2011 New Revision: 139762 URL: http://llvm.org/viewvc/llvm-project?rev=139762&view=rev Log: Fix ArchSpec::operator== to take the Triple into account as well as the Core. Also make the constructors explicit. Modified: lldb/trunk/source/Core/ArchSpec.cpp Modified: lldb/trunk/source/Core/ArchSpec.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/ArchSpec.cpp?rev=139762&r1=139761&r2=139762&view=diff ============================================================================== --- lldb/trunk/source/Core/ArchSpec.cpp (original) +++ lldb/trunk/source/Core/ArchSpec.cpp Wed Sep 14 20:07:30 2011 @@ -601,56 +601,78 @@ bool lldb_private::operator== (const ArchSpec& lhs, const ArchSpec& rhs) { + if (lhs.GetByteOrder() != rhs.GetByteOrder()) + return false; + const ArchSpec::Core lhs_core = lhs.GetCore (); const ArchSpec::Core rhs_core = rhs.GetCore (); + bool core_match = false; if (lhs_core == rhs_core) - return true; - - if (lhs_core == ArchSpec::kCore_any || rhs_core == ArchSpec::kCore_any) - return true; - - if (lhs_core == ArchSpec::kCore_arm_any) - { - if ((rhs_core >= ArchSpec::kCore_arm_first && rhs_core <= ArchSpec::kCore_arm_last) || (rhs_core == ArchSpec::kCore_arm_any)) - return true; - } - else if (rhs_core == ArchSpec::kCore_arm_any) - { - if ((lhs_core >= ArchSpec::kCore_arm_first && lhs_core <= ArchSpec::kCore_arm_last) || (lhs_core == ArchSpec::kCore_arm_any)) - return true; - } - else if (lhs_core == ArchSpec::kCore_x86_32_any) - { - if ((rhs_core >= ArchSpec::kCore_x86_32_first && rhs_core <= ArchSpec::kCore_x86_32_last) || (rhs_core == ArchSpec::kCore_x86_32_any)) - return true; - } - else if (rhs_core == ArchSpec::kCore_x86_32_any) - { - if ((lhs_core >= ArchSpec::kCore_x86_32_first && lhs_core <= ArchSpec::kCore_x86_32_last) || (lhs_core == ArchSpec::kCore_x86_32_any)) - return true; - } - else if (lhs_core == ArchSpec::kCore_ppc_any) - { - if ((rhs_core >= ArchSpec::kCore_ppc_first && rhs_core <= ArchSpec::kCore_ppc_last) || (rhs_core == ArchSpec::kCore_ppc_any)) - return true; - } - else if (rhs_core == ArchSpec::kCore_ppc_any) - { - if ((lhs_core >= ArchSpec::kCore_ppc_first && lhs_core <= ArchSpec::kCore_ppc_last) || (lhs_core == ArchSpec::kCore_ppc_any)) - return true; - } - else if (lhs_core == ArchSpec::kCore_ppc64_any) - { - if ((rhs_core >= ArchSpec::kCore_ppc64_first && rhs_core <= ArchSpec::kCore_ppc64_last) || (rhs_core == ArchSpec::kCore_ppc64_any)) - return true; - } - else if (rhs_core == ArchSpec::kCore_ppc64_any) + core_match = true; + else { - if ((lhs_core >= ArchSpec::kCore_ppc64_first && lhs_core <= ArchSpec::kCore_ppc64_last) || (lhs_core == ArchSpec::kCore_ppc64_any)) + + if (lhs_core == ArchSpec::kCore_any || rhs_core == ArchSpec::kCore_any) + core_match = true; + else + { + if (lhs_core == ArchSpec::kCore_arm_any) + { + if ((rhs_core >= ArchSpec::kCore_arm_first && rhs_core <= ArchSpec::kCore_arm_last) || (rhs_core == ArchSpec::kCore_arm_any)) + core_match = true; + } + else if (rhs_core == ArchSpec::kCore_arm_any) + { + if ((lhs_core >= ArchSpec::kCore_arm_first && lhs_core <= ArchSpec::kCore_arm_last) || (lhs_core == ArchSpec::kCore_arm_any)) + core_match = true; + } + else if (lhs_core == ArchSpec::kCore_x86_32_any) + { + if ((rhs_core >= ArchSpec::kCore_x86_32_first && rhs_core <= ArchSpec::kCore_x86_32_last) || (rhs_core == ArchSpec::kCore_x86_32_any)) + core_match = true; + } + else if (rhs_core == ArchSpec::kCore_x86_32_any) + { + if ((lhs_core >= ArchSpec::kCore_x86_32_first && lhs_core <= ArchSpec::kCore_x86_32_last) || (lhs_core == ArchSpec::kCore_x86_32_any)) + core_match = true; + } + else if (lhs_core == ArchSpec::kCore_ppc_any) + { + if ((rhs_core >= ArchSpec::kCore_ppc_first && rhs_core <= ArchSpec::kCore_ppc_last) || (rhs_core == ArchSpec::kCore_ppc_any)) + core_match = true; + } + else if (rhs_core == ArchSpec::kCore_ppc_any) + { + if ((lhs_core >= ArchSpec::kCore_ppc_first && lhs_core <= ArchSpec::kCore_ppc_last) || (lhs_core == ArchSpec::kCore_ppc_any)) + core_match = true; + } + else if (lhs_core == ArchSpec::kCore_ppc64_any) + { + if ((rhs_core >= ArchSpec::kCore_ppc64_first && rhs_core <= ArchSpec::kCore_ppc64_last) || (rhs_core == ArchSpec::kCore_ppc64_any)) + core_match = true; + } + else if (rhs_core == ArchSpec::kCore_ppc64_any) + { + if ((lhs_core >= ArchSpec::kCore_ppc64_first && lhs_core <= ArchSpec::kCore_ppc64_last) || (lhs_core == ArchSpec::kCore_ppc64_any)) + core_match = true; + } + } + } + if (!core_match) + return false; + else + { + const llvm::Triple &lhs_triple = lhs.GetTriple(); + const llvm::Triple &rhs_triple = rhs.GetTriple(); + if (lhs_triple.getVendor() != rhs_triple.getVendor() + || lhs_triple.getOS() != rhs_triple.getOS() + || lhs_triple.getArch() != rhs_triple.getArch() + || lhs_triple.getEnvironment() != rhs_triple.getEnvironment()) + return false; + else return true; } - return false; } bool From jingham at apple.com Wed Sep 14 20:08:57 2011 From: jingham at apple.com (Jim Ingham) Date: Thu, 15 Sep 2011 01:08:57 -0000 Subject: [Lldb-commits] [lldb] r139764 - /lldb/trunk/source/Commands/CommandObjectProcess.cpp Message-ID: <20110915010857.937612A6C12C@llvm.org> Author: jingham Date: Wed Sep 14 20:08:57 2011 New Revision: 139764 URL: http://llvm.org/viewvc/llvm-project?rev=139764&view=rev Log: Change the "attach" command to always wait synchronously for the target to stop. It's not very useful to return the prompt in mid-attach, and it makes reporting the result of the attach hard to do. Modified: lldb/trunk/source/Commands/CommandObjectProcess.cpp Modified: lldb/trunk/source/Commands/CommandObjectProcess.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectProcess.cpp?rev=139764&r1=139763&r2=139764&view=diff ============================================================================== --- lldb/trunk/source/Commands/CommandObjectProcess.cpp (original) +++ lldb/trunk/source/Commands/CommandObjectProcess.cpp Wed Sep 14 20:08:57 2011 @@ -562,7 +562,9 @@ CommandReturnObject &result) { Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); - bool synchronous_execution = m_interpreter.GetSynchronous (); + // N.B. The attach should be synchronous. It doesn't help much to get the prompt back between initiating the attach + // and the target actually stopping. So even if the interpreter is set to be asynchronous, we wait for the stop + // ourselves here. Process *process = m_interpreter.GetExecutionContext().process; StateType state = eStateInvalid; @@ -671,19 +673,11 @@ // Otherwise just return. // FIXME: in the async case it will now be possible to get to the command // interpreter with a state eStateAttaching. Make sure we handle that correctly. - if (synchronous_execution) - { - StateType state = process->WaitForProcessToStop (NULL); + StateType state = process->WaitForProcessToStop (NULL); - result.SetDidChangeProcessState (true); - result.AppendMessageWithFormat ("Process %i %s\n", process->GetID(), StateAsCString (state)); - result.SetStatus (eReturnStatusSuccessFinishNoResult); - } - else - { - result.SetDidChangeProcessState (true); - result.SetStatus (eReturnStatusSuccessFinishNoResult); - } + result.SetDidChangeProcessState (true); + result.AppendMessageWithFormat ("Process %i %s\n", process->GetID(), StateAsCString (state)); + result.SetStatus (eReturnStatusSuccessFinishNoResult); } else { @@ -731,20 +725,11 @@ error.AsCString()); result.SetStatus (eReturnStatusFailed); } - // See comment for synchronous_execution above. - if (synchronous_execution) - { - StateType state = process->WaitForProcessToStop (NULL); + StateType state = process->WaitForProcessToStop (NULL); - result.SetDidChangeProcessState (true); - result.AppendMessageWithFormat ("Process %i %s\n", process->GetID(), StateAsCString (state)); - result.SetStatus (eReturnStatusSuccessFinishNoResult); - } - else - { - result.SetDidChangeProcessState (true); - result.SetStatus (eReturnStatusSuccessFinishNoResult); - } + result.SetDidChangeProcessState (true); + result.AppendMessageWithFormat ("Process %i %s\n", process->GetID(), StateAsCString (state)); + result.SetStatus (eReturnStatusSuccessFinishNoResult); } else { From jingham at apple.com Wed Sep 14 20:10:17 2011 From: jingham at apple.com (Jim Ingham) Date: Thu, 15 Sep 2011 01:10:17 -0000 Subject: [Lldb-commits] [lldb] r139766 - /lldb/trunk/source/Target/Process.cpp Message-ID: <20110915011017.5355B2A6C12C@llvm.org> Author: jingham Date: Wed Sep 14 20:10:17 2011 New Revision: 139766 URL: http://llvm.org/viewvc/llvm-project?rev=139766&view=rev Log: Take out all the separate places in Attach where we were getting the target architecture, and move that but of functionality into CompleteAttach. Modified: lldb/trunk/source/Target/Process.cpp Modified: lldb/trunk/source/Target/Process.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Process.cpp?rev=139766&r1=139765&r2=139766&view=diff ============================================================================== --- lldb/trunk/source/Target/Process.cpp (original) +++ lldb/trunk/source/Target/Process.cpp Wed Sep 14 20:10:17 2011 @@ -2167,25 +2167,6 @@ // lldb_private::Process subclasses must set the process must set // the new process ID. assert (m_process->GetID() != LLDB_INVALID_PROCESS_ID); - // We just attached, if we haven't gotten a valid architecture at this point we should do so now. - Target &target = m_process->GetTarget(); - if (!target.GetArchitecture().IsValid()) - { - // FIXME: We shouldn't be getting the Selected Platform, there should - // be a platform for the target, and we should get that. - PlatformSP platform_sp (target.GetDebugger().GetPlatformList().GetSelectedPlatform ()); - if (platform_sp) - { - ProcessInstanceInfo process_info; - platform_sp->GetProcessInfo (m_process->GetID(), process_info); - const ArchSpec &process_arch = process_info.GetArchitecture(); - if (process_arch.IsValid()) - { - // Set the architecture on the target. - target.SetArchitecture (process_arch); - } - } - } m_process->CompleteAttach (); return eEventActionSuccess; } @@ -2220,21 +2201,6 @@ m_abi_sp.reset(); m_process_input_reader.reset(); - // Find the process and its architecture. Make sure it matches the architecture - // of the current Target, and if not adjust it. - - ProcessInstanceInfo process_info; - PlatformSP platform_sp (m_target.GetDebugger().GetPlatformList().GetSelectedPlatform ()); - if (platform_sp) - { - if (platform_sp->GetProcessInfo (attach_pid, process_info)) - { - const ArchSpec &process_arch = process_info.GetArchitecture(); - if (process_arch.IsValid()) - GetTarget().SetArchitecture(process_arch); - } - } - m_dyld_ap.reset(); m_os_ap.reset(); @@ -2278,7 +2244,9 @@ if (!wait_for_launch) { ProcessInstanceInfoList process_infos; - PlatformSP platform_sp (m_target.GetDebugger().GetPlatformList().GetSelectedPlatform ()); + PlatformSP platform_sp (m_target.GetPlatform ()); + assert (platform_sp.get()); + if (platform_sp) { ProcessInstanceInfoMatch match_info; @@ -2293,19 +2261,6 @@ { error.SetErrorStringWithFormat ("Could not find a process named %s\n", process_name); } - else - { - ProcessInstanceInfo process_info; - if (process_infos.GetInfoAtIndex (0, process_info)) - { - const ArchSpec &process_arch = process_info.GetArchitecture(); - if (process_arch.IsValid() && process_arch != GetTarget().GetArchitecture()) - { - // Set the architecture on the target. - GetTarget().SetArchitecture (process_arch); - } - } - } } else { @@ -2352,7 +2307,20 @@ // before we go looking for a dynamic loader plug-in. DidAttach(); - // We have complete the attach, now it is time to find the dynamic loader + // We just attached. If we have a platform, ask it for the process architecture, and if it isn't + // the same as the one we've already set, switch architectures. + PlatformSP platform_sp (m_target.GetPlatform ()); + assert (platform_sp.get()); + if (platform_sp) + { + ProcessInstanceInfo process_info; + platform_sp->GetProcessInfo (GetID(), process_info); + const ArchSpec &process_arch = process_info.GetArchitecture(); + if (process_arch.IsValid() && m_target.GetArchitecture() != process_arch) + m_target.SetArchitecture (process_arch); + } + + // We have completed the attach, now it is time to find the dynamic loader // plug-in m_dyld_ap.reset (DynamicLoader::FindPlugin(this, NULL)); if (m_dyld_ap.get()) From johnny.chen at apple.com Wed Sep 14 20:12:15 2011 From: johnny.chen at apple.com (Johnny Chen) Date: Thu, 15 Sep 2011 01:12:15 -0000 Subject: [Lldb-commits] [lldb] r139767 - /lldb/trunk/tools/debugserver/source/MacOSX/MachThread.cpp Message-ID: <20110915011215.8E1FC2A6C12C@llvm.org> Author: johnny Date: Wed Sep 14 20:12:15 2011 New Revision: 139767 URL: http://llvm.org/viewvc/llvm-project?rev=139767&view=rev Log: Modify MachThread::NotifyException() to allow the arch specific protocol to process the passed in (MachException::Data &)exc first before possible reassignment of the member m_stop_exception with exc. This allows lldb to stop at the watchpoint of a simple test program. Modified: lldb/trunk/tools/debugserver/source/MacOSX/MachThread.cpp Modified: lldb/trunk/tools/debugserver/source/MacOSX/MachThread.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/MacOSX/MachThread.cpp?rev=139767&r1=139766&r2=139767&view=diff ============================================================================== --- lldb/trunk/tools/debugserver/source/MacOSX/MachThread.cpp (original) +++ lldb/trunk/tools/debugserver/source/MacOSX/MachThread.cpp Wed Sep 14 20:12:15 2011 @@ -547,6 +547,10 @@ bool MachThread::NotifyException(MachException::Data& exc) { + // Allow the arch specific protocol to process (MachException::Data &)exc + // first before possible reassignment of m_stop_exception with exc. + bool handled = m_arch_ap->NotifyException(exc); + if (m_stop_exception.IsValid()) { // We may have more than one exception for a thread, but we need to @@ -560,32 +564,7 @@ { m_stop_exception = exc; } - bool handled = m_arch_ap->NotifyException(exc); - if (!handled) - { - handled = true; -// switch (exc.exc_type) -// { -// case EXC_BAD_ACCESS: -// break; -// case EXC_BAD_INSTRUCTION: -// break; -// case EXC_ARITHMETIC: -// break; -// case EXC_EMULATION: -// break; -// case EXC_SOFTWARE: -// break; -// case EXC_BREAKPOINT: -// break; -// case EXC_SYSCALL: -// break; -// case EXC_MACH_SYSCALL: -// break; -// case EXC_RPC_ALERT: -// break; -// } - } + return handled; } From scallanan at apple.com Wed Sep 14 21:13:08 2011 From: scallanan at apple.com (Sean Callanan) Date: Thu, 15 Sep 2011 02:13:08 -0000 Subject: [Lldb-commits] [lldb] r139772 - in /lldb/trunk: include/lldb/ include/lldb/Expression/ include/lldb/Target/ lldb.xcodeproj/ source/API/ source/Breakpoint/ source/Commands/ source/Expression/ source/Symbol/ source/Target/ Message-ID: <20110915021308.9ACC62A6C12C@llvm.org> Author: spyffe Date: Wed Sep 14 21:13:07 2011 New Revision: 139772 URL: http://llvm.org/viewvc/llvm-project?rev=139772&view=rev Log: This patch modifies the expression parser to allow it to execute expressions even in the absence of a process. This allows expressions to run in situations where the target cannot run -- e.g., to perform calculations based on type information, or to inspect a binary's static data. This modification touches the following files: lldb-private-enumerations.h Introduce a new enum specifying the policy for processing an expression. Some expressions should always be JITted, for example if they are functions that will be used over and over again. Some expressions should always be interpreted, for example if the target is unsafe to run. For most, it is acceptable to JIT them, but interpretation is preferable when possible. Target.[h,cpp] Have EvaluateExpression now accept the new enum. ClangExpressionDeclMap.[cpp,h] Add support for the IR interpreter and also make the ClangExpressionDeclMap more robust in the absence of a process. ClangFunction.[cpp,h] Add support for the new enum. IRInterpreter.[cpp,h] New implementation. ClangUserExpression.[cpp,h] Add support for the new enum, and for running expressions in the absence of a process. ClangExpression.h Remove references to the old DWARF-based method of evaluating expressions, because it has been superseded for now. ClangUtilityFunction.[cpp,h] Add support for the new enum. ClangExpressionParser.[cpp,h] Add support for the new enum, remove references to DWARF, and add support for checking whether the expression could be evaluated statically. IRForTarget.[h,cpp] Add support for the new enum, and add utility functions to support the interpreter. IRToDWARF.cpp Removed CommandObjectExpression.cpp Remove references to the obsolete -i option. Process.cpp Modify calls to ClangUserExpression::Evaluate to pass the correct enum (for dlopen/dlclose) SBValue.cpp Add support for the new enum. SBFrame.cpp Add support for he new enum. BreakpointOptions.cpp Add support for the new enum. Added: lldb/trunk/include/lldb/Expression/IRInterpreter.h lldb/trunk/source/Expression/IRInterpreter.cpp Removed: lldb/trunk/source/Expression/IRToDWARF.cpp Modified: lldb/trunk/include/lldb/Expression/ClangExpression.h lldb/trunk/include/lldb/Expression/ClangExpressionDeclMap.h lldb/trunk/include/lldb/Expression/ClangExpressionParser.h lldb/trunk/include/lldb/Expression/ClangFunction.h lldb/trunk/include/lldb/Expression/ClangUserExpression.h lldb/trunk/include/lldb/Expression/ClangUtilityFunction.h lldb/trunk/include/lldb/Expression/IRForTarget.h lldb/trunk/include/lldb/Target/Target.h lldb/trunk/include/lldb/lldb-private-enumerations.h lldb/trunk/lldb.xcodeproj/project.pbxproj lldb/trunk/source/API/SBFrame.cpp lldb/trunk/source/API/SBValue.cpp lldb/trunk/source/Breakpoint/BreakpointOptions.cpp lldb/trunk/source/Commands/CommandObjectExpression.cpp lldb/trunk/source/Expression/ClangExpressionDeclMap.cpp lldb/trunk/source/Expression/ClangExpressionParser.cpp lldb/trunk/source/Expression/ClangFunction.cpp lldb/trunk/source/Expression/ClangUserExpression.cpp lldb/trunk/source/Expression/ClangUtilityFunction.cpp lldb/trunk/source/Expression/IRForTarget.cpp lldb/trunk/source/Symbol/ClangASTImporter.cpp lldb/trunk/source/Target/Process.cpp lldb/trunk/source/Target/StopInfo.cpp lldb/trunk/source/Target/Target.cpp Modified: lldb/trunk/include/lldb/Expression/ClangExpression.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Expression/ClangExpression.h?rev=139772&r1=139771&r2=139772&view=diff ============================================================================== --- lldb/trunk/include/lldb/Expression/ClangExpression.h (original) +++ lldb/trunk/include/lldb/Expression/ClangExpression.h Wed Sep 14 21:13:07 2011 @@ -98,13 +98,6 @@ ASTTransformer (clang::ASTConsumer *passthrough) = 0; //------------------------------------------------------------------ - /// Return the stream that the parser should use to write DWARF - /// opcodes. - //------------------------------------------------------------------ - virtual StreamString & - DwarfOpcodeStream () = 0; - - //------------------------------------------------------------------ /// Flags //------------------------------------------------------------------ Modified: lldb/trunk/include/lldb/Expression/ClangExpressionDeclMap.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Expression/ClangExpressionDeclMap.h?rev=139772&r1=139771&r2=139772&view=diff ============================================================================== --- lldb/trunk/include/lldb/Expression/ClangExpressionDeclMap.h (original) +++ lldb/trunk/include/lldb/Expression/ClangExpressionDeclMap.h Wed Sep 14 21:13:07 2011 @@ -349,6 +349,130 @@ GetSymbolAddress (const ConstString &name); //------------------------------------------------------------------ + /// [Used by IRInterpreter] Get basic target information. + /// + /// @param[out] byte_order + /// The byte order of the target. + /// + /// @param[out] address_byte_size + /// The size of a pointer in bytes. + /// + /// @return + /// True if the information could be determined; false + /// otherwise. + //------------------------------------------------------------------ + struct TargetInfo + { + lldb::ByteOrder byte_order; + size_t address_byte_size; + + TargetInfo() : + byte_order(lldb::eByteOrderInvalid), + address_byte_size(0) + { + } + + bool IsValid() + { + return (byte_order != lldb::eByteOrderInvalid && + address_byte_size != 0); + } + }; + TargetInfo GetTargetInfo(); + + //------------------------------------------------------------------ + /// [Used by IRInterpreter] Write to the target. + /// + /// @param[in] addr + /// The address to write to. + /// + /// @param[in] data + /// The address of the data buffer to read from. + /// + /// @param[in] length + /// The amount of data to write, in bytes. + /// + /// @return + /// True if the write could be performed; false otherwise. + //------------------------------------------------------------------ + bool + WriteTarget (lldb_private::Value &value, + const uint8_t *data, + size_t length); + + //------------------------------------------------------------------ + /// [Used by IRInterpreter] Read from the target. + /// + /// @param[in] data + /// The address of the data buffer to write to. + /// + /// @param[in] addr + /// The address to read from. + /// + /// @param[in] length + /// The amount of data to read, in bytes. + /// + /// @return + /// True if the read could be performed; false otherwise. + //------------------------------------------------------------------ + bool + ReadTarget (uint8_t *data, + lldb_private::Value &value, + size_t length); + + //------------------------------------------------------------------ + /// [Used by IRInterpreter] Get the Value for a NamedDecl. + /// + /// @param[in] decl + /// The Decl whose value is to be found. + /// + /// @return + /// The value, or NULL. + //------------------------------------------------------------------ + lldb_private::Value + LookupDecl (clang::NamedDecl *decl); + + //------------------------------------------------------------------ + /// [Used by IRInterpreter] Returns true if the result is a + /// reference to data in the target, meaning it must be + /// dereferenced once more to get its data. + /// + /// @param[in] name + /// The name of the result. + /// + /// @return + /// True if the result is a reference; false otherwise (or on + /// error). + //------------------------------------------------------------------ + bool + ResultIsReference (const ConstString &name); + + //------------------------------------------------------------------ + /// [Used by IRInterpreter] Find the result persistent variable, + /// propagate the given value to it, and return it. + /// + /// @param[out] valobj + /// Set to the complete object. + /// + /// @param[in] value + /// A value indicating the location of the value's contents. + /// + /// @param[in] name + /// The name of the result. + /// + /// @param[in] type + /// The type of the data. + /// + /// @return + /// True on success; false otherwise. + //------------------------------------------------------------------ + bool + CompleteResultVariable (lldb::ClangExpressionVariableSP &valobj, + lldb_private::Value &value, + const ConstString &name, + lldb_private::TypeFromParser type); + + //------------------------------------------------------------------ /// [Used by CommandObjectExpression] Materialize the entire struct /// at a given address, which should be aligned as specified by /// GetStructInfo(). @@ -596,6 +720,7 @@ bool m_enable_lookups; ///< Set to true during parsing if we have found the first "$__lldb" name. bool m_ignore_lookups; ///< True during an import when we should be ignoring type lookups. std::auto_ptr m_ast_importer; ///< The importer used to import types on the parser's behalf. + TargetInfo m_target_info; ///< Basic information about the target. private: DISALLOW_COPY_AND_ASSIGN (ParserVars); }; @@ -742,6 +867,29 @@ const ConstString &name); //------------------------------------------------------------------ + /// Given a target, find a variable that matches the given name and + /// type. + /// + /// @param[in] target + /// The target to use as a basis for finding the variable. + /// + /// @param[in] name + /// The name as a plain C string. + /// + /// @param[in] type + /// The required type for the variable. This function may be called + /// during parsing, in which case we don't know its type; hence the + /// default. + /// + /// @return + /// The LLDB Variable found, or NULL if none was found. + //------------------------------------------------------------------ + lldb::VariableSP + FindGlobalVariable (Target &target, + const char *name, + TypeFromUser *type = NULL); + + //------------------------------------------------------------------ /// Get the value of a variable in a given execution context and return /// the associated Types if needed. /// Modified: lldb/trunk/include/lldb/Expression/ClangExpressionParser.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Expression/ClangExpressionParser.h?rev=139772&r1=139771&r2=139772&view=diff ============================================================================== --- lldb/trunk/include/lldb/Expression/ClangExpressionParser.h (original) +++ lldb/trunk/include/lldb/Expression/ClangExpressionParser.h Wed Sep 14 21:13:07 2011 @@ -73,20 +73,8 @@ Parse (Stream &stream); //------------------------------------------------------------------ - /// Convert the IR for an already-parsed expression to DWARF if possible. - /// - /// @param[in] dwarf_opcode_strm - /// The stream to place the resulting DWARF code into. - /// - /// @return - /// An error code indicating the success or failure of the operation. - /// Test with Success(). - //------------------------------------------------------------------ - Error - MakeDWARF (); - - //------------------------------------------------------------------ - /// JIT-compile the IR for an already-parsed expression. + /// Ready an already-parsed expression for execution, possibly + /// evaluating it statically. /// /// @param[out] func_allocation_addr /// The address which can be used to deallocate the code for this @@ -104,30 +92,36 @@ /// The execution context to write the function into. /// /// @param[in] data_allocator - /// If non-NULL, he static data allocator to use for literal strings. + /// If non-NULL, the static data allocator to use for literal strings. + /// + /// @param[out] evaluated_statically + /// Set to true if the expression could be interpreted statically; + /// untouched otherwise. /// /// @param[out] const_result /// If the result of the expression is constant, and the /// expression has no side effects, this is set to the result of the /// expression. /// - /// @param[in] jit_only_if_needed - /// True if the expression must be compiled, regardless of whether a - /// constant result could be extracted from the IR or no. + /// @param[in] execution_policy + /// Determines whether the expression must be JIT-compiled, must be + /// evaluated statically, or whether this decision may be made + /// opportunistically. /// /// @return /// An error code indicating the success or failure of the operation. /// Test with Success(). //------------------------------------------------------------------ Error - MakeJIT (lldb::addr_t &func_allocation_addr, - lldb::addr_t &func_addr, - lldb::addr_t &func_end, - ExecutionContext &exe_ctx, - IRForTarget::StaticDataAllocator *data_allocator, - lldb::ClangExpressionVariableSP &const_result, - bool jit_only_if_needed = false); - + PrepareForExecution (lldb::addr_t &func_allocation_addr, + lldb::addr_t &func_addr, + lldb::addr_t &func_end, + ExecutionContext &exe_ctx, + IRForTarget::StaticDataAllocator *data_allocator, + bool &evaluated_statically, + lldb::ClangExpressionVariableSP &const_result, + lldb_private::ExecutionPolicy execution_policy); + //------------------------------------------------------------------ /// Disassemble the machine code for a JITted function from the target /// process's memory and print the result to a stream. Modified: lldb/trunk/include/lldb/Expression/ClangFunction.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Expression/ClangFunction.h?rev=139772&r1=139771&r2=139772&view=diff ============================================================================== --- lldb/trunk/include/lldb/Expression/ClangFunction.h (original) +++ lldb/trunk/include/lldb/Expression/ClangFunction.h Wed Sep 14 21:13:07 2011 @@ -574,16 +574,6 @@ ASTTransformer (clang::ASTConsumer *passthrough); //------------------------------------------------------------------ - /// Return the stream that the parser should use to write DWARF - /// opcodes. - //------------------------------------------------------------------ - StreamString & - DwarfOpcodeStream () - { - return *((StreamString*)0); - } - - //------------------------------------------------------------------ /// Return true if validation code should be inserted into the /// expression. //------------------------------------------------------------------ Modified: lldb/trunk/include/lldb/Expression/ClangUserExpression.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Expression/ClangUserExpression.h?rev=139772&r1=139771&r2=139772&view=diff ============================================================================== --- lldb/trunk/include/lldb/Expression/ClangUserExpression.h (original) +++ lldb/trunk/include/lldb/Expression/ClangUserExpression.h Wed Sep 14 21:13:07 2011 @@ -83,6 +83,9 @@ /// The type that the expression should be coerced to. If NULL, /// inferred from the expression itself. /// + /// @param[in] execution_policy + /// Determines whether interpretation is possible or mandatory. + /// /// @param[in] keep_result_in_memory /// True if the resulting persistent variable should reside in /// target memory, if applicable. @@ -94,6 +97,7 @@ Parse (Stream &error_stream, ExecutionContext &exe_ctx, TypeFromUser desired_type, + lldb_private::ExecutionPolicy execution_policy, bool keep_result_in_memory); //------------------------------------------------------------------ @@ -227,13 +231,6 @@ ASTTransformer (clang::ASTConsumer *passthrough); //------------------------------------------------------------------ - /// Return the stream that the parser should use to write DWARF - /// opcodes. - //------------------------------------------------------------------ - StreamString & - DwarfOpcodeStream (); - - //------------------------------------------------------------------ /// Return true if validation code should be inserted into the /// expression. //------------------------------------------------------------------ @@ -259,6 +256,10 @@ /// @param[in] exe_ctx /// The execution context to use when evaluating the expression. /// + /// @param[in] execution_policy + /// Determines whether or not to try using the IR interpreter to + /// avoid running the expression on the parser. + /// /// @param[in] discard_on_error /// True if the thread's state should be restored in the case /// of an error. @@ -277,14 +278,16 @@ /// A Process::ExecutionResults value. eExecutionCompleted for success. //------------------------------------------------------------------ static ExecutionResults - Evaluate (ExecutionContext &exe_ctx, + Evaluate (ExecutionContext &exe_ctx, + lldb_private::ExecutionPolicy execution_policy, bool discard_on_error, const char *expr_cstr, const char *expr_prefix, lldb::ValueObjectSP &result_valobj_sp); static ExecutionResults - EvaluateWithError (ExecutionContext &exe_ctx, + EvaluateWithError (ExecutionContext &exe_ctx, + lldb_private::ExecutionPolicy execution_policy, bool discard_on_error, const char *expr_cstr, const char *expr_prefix, @@ -307,6 +310,12 @@ lldb::addr_t &object_ptr, lldb::addr_t &cmd_ptr); + bool + EvaluatedStatically () + { + return m_evaluated_statically; + } + std::string m_expr_text; ///< The text of the expression, as typed by the user std::string m_expr_prefix; ///< The text of the translation-level definitions, as provided by the user std::string m_transformed_text; ///< The text of the expression, as send to the parser @@ -314,7 +323,6 @@ std::auto_ptr m_expr_decl_map; ///< The map to use when parsing and materializing the expression. std::auto_ptr m_local_variables; ///< The local expression variables, if the expression is DWARF. - std::auto_ptr m_dwarf_opcodes; ///< The DWARF opcodes for the expression. May be NULL. std::auto_ptr m_data_allocator; ///< The allocator that the parser uses to place strings for use by JIT-compiled code. bool m_cplusplus; ///< True if the expression is compiled as a C++ member function (true if it was parsed when exe_ctx was in a C++ method). @@ -323,6 +331,7 @@ bool m_const_object; ///< True if "this" is const. Target *m_target; ///< The target for storing persistent data like types and variables. + bool m_evaluated_statically; ///< True if the expression could be evaluated statically; false otherwise. lldb::ClangExpressionVariableSP m_const_result; ///< The statically-computed result of the expression. NULL if it could not be computed statically or the expression has side effects. }; Modified: lldb/trunk/include/lldb/Expression/ClangUtilityFunction.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Expression/ClangUtilityFunction.h?rev=139772&r1=139771&r2=139772&view=diff ============================================================================== --- lldb/trunk/include/lldb/Expression/ClangUtilityFunction.h (original) +++ lldb/trunk/include/lldb/Expression/ClangUtilityFunction.h Wed Sep 14 21:13:07 2011 @@ -149,16 +149,6 @@ } //------------------------------------------------------------------ - /// Return the stream that the parser should use to write DWARF - /// opcodes. - //------------------------------------------------------------------ - StreamString & - DwarfOpcodeStream () - { - return *((StreamString*)NULL); - } - - //------------------------------------------------------------------ /// Return true if validation code should be inserted into the /// expression. //------------------------------------------------------------------ Modified: lldb/trunk/include/lldb/Expression/IRForTarget.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Expression/IRForTarget.h?rev=139772&r1=139771&r2=139772&view=diff ============================================================================== --- lldb/trunk/include/lldb/Expression/IRForTarget.h (original) +++ lldb/trunk/include/lldb/Expression/IRForTarget.h Wed Sep 14 21:13:07 2011 @@ -73,6 +73,10 @@ /// variables) should be resolved. If not, only external functions /// are resolved. /// + /// @param[in] execution_policy + /// Determines whether an IR interpreter can be used to statically + /// evaluate the expression. + /// /// @param[in] const_result /// This variable is populated with the statically-computed result /// of the function, if it has no side-effects and the result can @@ -89,6 +93,7 @@ //------------------------------------------------------------------ IRForTarget(lldb_private::ClangExpressionDeclMap *decl_map, bool resolve_vars, + lldb_private::ExecutionPolicy execution_policy, lldb::ClangExpressionVariableSP &const_result, StaticDataAllocator *data_allocator, lldb_private::Stream *error_stream, @@ -133,6 +138,18 @@ //------------------------------------------------------------------ virtual llvm::PassManagerType getPotentialPassManagerType() const; + + //------------------------------------------------------------------ + /// Checks whether the IR interpreter successfully interpreted the + /// expression. + /// + /// Returns true if it did; false otherwise. + //------------------------------------------------------------------ + bool + interpretSuccess () + { + return m_interpret_success; + } private: //------------------------------------------------------------------ @@ -236,16 +253,22 @@ //------------------------------------------------------------------ //------------------------------------------------------------------ - /// Set the constant result variable m_const_result to the provided - /// constant, assuming it can be evaluated. The result variable - /// will be reset to NULL later if the expression has side effects. + /// Find the NamedDecl corresponding to a Value. This interface is + /// exposed for the IR interpreter. + /// + /// @param[in] module + /// The module containing metadata to search /// /// @param[in] global /// The global entity to search for /// /// @return /// The corresponding variable declaration - //------------------------------------------------------------------ + //------------------------------------------------------------------ +public: + static clang::NamedDecl * + DeclForGlobal (const llvm::GlobalValue *global_val, llvm::Module *module); +private: clang::NamedDecl * DeclForGlobal (llvm::GlobalValue *global); @@ -549,8 +572,11 @@ /// Flags bool m_resolve_vars; ///< True if external variable references and persistent variable references should be resolved + lldb_private::ExecutionPolicy m_execution_policy; ///< True if the interpreter should be used to attempt to get a static result + bool m_interpret_success; ///< True if the interpreter successfully handled the whole expression std::string m_func_name; ///< The name of the function to translate lldb_private::ConstString m_result_name; ///< The name of the result variable ($0, $1, ...) + lldb_private::TypeFromParser m_result_type; ///< The type of the result variable. llvm::Module *m_module; ///< The module being processed, or NULL if that has not been determined yet. lldb_private::ClangExpressionDeclMap *m_decl_map; ///< The DeclMap containing the Decls StaticDataAllocator *m_data_allocator; ///< If non-NULL, the allocator to use for constant strings Added: lldb/trunk/include/lldb/Expression/IRInterpreter.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Expression/IRInterpreter.h?rev=139772&view=auto ============================================================================== --- lldb/trunk/include/lldb/Expression/IRInterpreter.h (added) +++ lldb/trunk/include/lldb/Expression/IRInterpreter.h Wed Sep 14 21:13:07 2011 @@ -0,0 +1,107 @@ +//===-- IRInterpreter.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_IRInterpreter_h_ +#define liblldb_IRInterpreter_h_ + +#include "lldb/lldb-public.h" +#include "lldb/Core/ConstString.h" +#include "lldb/Core/Stream.h" +#include "lldb/Symbol/TaggedASTType.h" +#include "llvm/Pass.h" + +namespace llvm { + class Function; + class Module; +} + +namespace lldb_private { + +class ClangExpressionDeclMap; + +} + +//---------------------------------------------------------------------- +/// @class IRInterpreter IRInterpreter.h "lldb/Expression/IRInterpreter.h" +/// @brief Attempt to interpret the function's code if it does not require +/// running the target. +/// +/// In some cases, the IR for an expression can be evaluated entirely +/// in the debugger, manipulating variables but not executing any code +/// in the target. The IRInterpreter attempts to do this. +//---------------------------------------------------------------------- +class IRInterpreter +{ +public: + //------------------------------------------------------------------ + /// Constructor + /// + /// @param[in] decl_map + /// The list of externally-referenced variables for the expression, + /// for use in looking up globals and allocating the argument + /// struct. See the documentation for ClangExpressionDeclMap. + /// + /// @param[in] error_stream + /// If non-NULL, a stream on which errors can be printed. + //------------------------------------------------------------------ + IRInterpreter(lldb_private::ClangExpressionDeclMap &decl_map, + lldb_private::Stream *error_stream); + + //------------------------------------------------------------------ + /// Destructor + //------------------------------------------------------------------ + ~IRInterpreter(); + + //------------------------------------------------------------------ + /// Run the IR interpreter on a single function + /// + /// @param[in] result + /// This variable is populated with the return value of the + /// function, if it could be interpreted completely. + /// + /// @param[in] result_name + /// The name of the result in the IR. If this name got a + /// value written to it as part of execution, then that value + /// will be used to create the result variable. + /// + /// @param[in] result_type + /// The type of the result. + /// + /// @param[in] llvm_function + /// The function to interpret. + /// + /// @param[in] llvm_module + /// The module containing the function. + /// + /// @return + /// True on success; false otherwise + //------------------------------------------------------------------ + bool + maybeRunOnFunction (lldb::ClangExpressionVariableSP &result, + const lldb_private::ConstString &result_name, + lldb_private::TypeFromParser result_type, + llvm::Function &llvm_function, + llvm::Module &llvm_module); +private: + /// Flags + lldb_private::ClangExpressionDeclMap &m_decl_map; ///< The DeclMap containing the Decls + lldb_private::Stream *m_error_stream; + + bool + supportsFunction (llvm::Function &llvm_function); + + bool + runOnFunction (lldb::ClangExpressionVariableSP &result, + const lldb_private::ConstString &result_name, + lldb_private::TypeFromParser result_type, + llvm::Function &llvm_function, + llvm::Module &llvm_module); +}; + +#endif Modified: lldb/trunk/include/lldb/Target/Target.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/Target.h?rev=139772&r1=139771&r2=139772&view=diff ============================================================================== --- lldb/trunk/include/lldb/Target/Target.h (original) +++ lldb/trunk/include/lldb/Target/Target.h Wed Sep 14 21:13:07 2011 @@ -600,6 +600,7 @@ ExecutionResults EvaluateExpression (const char *expression, StackFrame *frame, + lldb_private::ExecutionPolicy execution_policy, bool unwind_on_error, bool keep_in_memory, lldb::DynamicValueType use_dynamic, Modified: lldb/trunk/include/lldb/lldb-private-enumerations.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/lldb-private-enumerations.h?rev=139772&r1=139771&r2=139772&view=diff ============================================================================== --- lldb/trunk/include/lldb/lldb-private-enumerations.h (original) +++ lldb/trunk/include/lldb/lldb-private-enumerations.h Wed Sep 14 21:13:07 2011 @@ -214,6 +214,15 @@ eFormatCategoryItemRegexSynth = 0x0020 } FormatCategoryItem; +//------------------------------------------------------------------ +/// Expression execution policies +//------------------------------------------------------------------ +typedef enum { + eExecutionPolicyOnlyWhenNeeded, + eExecutionPolicyNever, + eExecutionPolicyAlways +} ExecutionPolicy; + } // namespace lldb Modified: lldb/trunk/lldb.xcodeproj/project.pbxproj URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/lldb.xcodeproj/project.pbxproj?rev=139772&r1=139771&r2=139772&view=diff ============================================================================== --- lldb/trunk/lldb.xcodeproj/project.pbxproj (original) +++ lldb/trunk/lldb.xcodeproj/project.pbxproj Wed Sep 14 21:13:07 2011 @@ -179,7 +179,6 @@ 2689006913353E0E00698AC0 /* ASTStructExtractor.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 491193501226386000578B7F /* ASTStructExtractor.cpp */; }; 2689006A13353E0E00698AC0 /* IRDynamicChecks.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 49CF9829122C70BD007A0B96 /* IRDynamicChecks.cpp */; }; 2689006B13353E0E00698AC0 /* IRForTarget.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 49307AAD11DEA4D90081F992 /* IRForTarget.cpp */; }; - 2689006C13353E0E00698AC0 /* IRToDWARF.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 49DA742F11DE6A5A006AEF7E /* IRToDWARF.cpp */; }; 2689006D13353E0E00698AC0 /* RecordingMemoryManager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4C98D3DB118FB96F00E575D0 /* RecordingMemoryManager.cpp */; }; 2689006E13353E1A00698AC0 /* File.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 260C6EA213011581005E16B0 /* File.cpp */; }; 2689006F13353E1A00698AC0 /* FileSpec.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 26FA43171301048600E71120 /* FileSpec.cpp */; }; @@ -330,7 +329,6 @@ 2689FFFB13353DB600698AC0 /* BreakpointLocationList.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 26BC7E1010F1B83100F91463 /* BreakpointLocationList.cpp */; }; 2689FFFD13353DB600698AC0 /* BreakpointOptions.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 26BC7E1110F1B83100F91463 /* BreakpointOptions.cpp */; }; 2689FFFF13353DB600698AC0 /* BreakpointResolver.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 26BC7E1210F1B83100F91463 /* BreakpointResolver.cpp */; }; - 268ED0A5140FF54200DE830F /* DataEncoder.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 268ED0A4140FF54200DE830F /* DataEncoder.cpp */; }; 268F9D53123AA15200B91E9B /* SBSymbolContextList.h in Headers */ = {isa = PBXBuildFile; fileRef = 268F9D52123AA15200B91E9B /* SBSymbolContextList.h */; settings = {ATTRIBUTES = (Public, ); }; }; 268F9D55123AA16600B91E9B /* SBSymbolContextList.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 268F9D54123AA16600B91E9B /* SBSymbolContextList.cpp */; }; 2690B3711381D5C300ECFBAE /* Memory.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2690B3701381D5C300ECFBAE /* Memory.cpp */; }; @@ -396,6 +394,9 @@ 26F5C37510F3F61B009D5894 /* libobjc.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 26F5C37410F3F61B009D5894 /* libobjc.dylib */; }; 26F5C39110F3FA26009D5894 /* CoreFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 26F5C39010F3FA26009D5894 /* CoreFoundation.framework */; }; 26F73062139D8FDB00FD51C7 /* History.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 26F73061139D8FDB00FD51C7 /* History.cpp */; }; + 496B015B1406DEB100F830D5 /* IRInterpreter.h in Headers */ = {isa = PBXBuildFile; fileRef = 496B015A1406DEB100F830D5 /* IRInterpreter.h */; }; + 49A71FE7141FFA5C00D59478 /* IRInterpreter.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 496B01581406DE8900F830D5 /* IRInterpreter.cpp */; }; + 49A71FE8141FFACF00D59478 /* DataEncoder.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 268ED0A4140FF54200DE830F /* DataEncoder.cpp */; }; 49C8507C1384A786007DB519 /* ProcessDataAllocator.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 49C850781384A0CA007DB519 /* ProcessDataAllocator.cpp */; }; 49D8FB3913B5598F00411094 /* ClangASTImporter.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 49D8FB3513B558DE00411094 /* ClangASTImporter.cpp */; }; 4C74CB6312288704006A8171 /* Carbon.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4C74CB6212288704006A8171 /* Carbon.framework */; }; @@ -1104,6 +1105,8 @@ 49445E341225AB6A00C11A81 /* ClangUserExpression.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ClangUserExpression.h; path = include/lldb/Expression/ClangUserExpression.h; sourceTree = ""; }; 495BBACB119A0DBE00418BEA /* PathMappingList.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = PathMappingList.cpp; path = source/Target/PathMappingList.cpp; sourceTree = ""; }; 495BBACF119A0DE700418BEA /* PathMappingList.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = PathMappingList.h; path = include/lldb/Target/PathMappingList.h; sourceTree = ""; }; + 496B01581406DE8900F830D5 /* IRInterpreter.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = IRInterpreter.cpp; path = source/Expression/IRInterpreter.cpp; sourceTree = ""; }; + 496B015A1406DEB100F830D5 /* IRInterpreter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = IRInterpreter.h; path = include/lldb/Expression/IRInterpreter.h; sourceTree = ""; }; 497C86BD122823D800B54702 /* ClangUtilityFunction.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ClangUtilityFunction.cpp; path = source/Expression/ClangUtilityFunction.cpp; sourceTree = ""; }; 497C86C1122823F300B54702 /* ClangUtilityFunction.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ClangUtilityFunction.h; path = include/lldb/Expression/ClangUtilityFunction.h; sourceTree = ""; }; 497E7B331188ED300065CCA1 /* ABI.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ABI.h; path = include/lldb/Target/ABI.h; sourceTree = ""; }; @@ -1123,8 +1126,6 @@ 49D7072811B5AD11001AD875 /* ClangASTSource.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ClangASTSource.cpp; path = source/Expression/ClangASTSource.cpp; sourceTree = ""; }; 49D8FB3513B558DE00411094 /* ClangASTImporter.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ClangASTImporter.cpp; path = source/Symbol/ClangASTImporter.cpp; sourceTree = ""; }; 49D8FB3713B5594900411094 /* ClangASTImporter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ClangASTImporter.h; path = include/lldb/Symbol/ClangASTImporter.h; 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 = ""; }; 49E45FA911F660DC008F7B28 /* ClangASTType.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ClangASTType.h; path = include/lldb/Symbol/ClangASTType.h; sourceTree = ""; }; 49E45FAD11F660FE008F7B28 /* ClangASTType.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ClangASTType.cpp; path = source/Symbol/ClangASTType.cpp; sourceTree = ""; }; 49EC3E98118F90AC00B1265E /* ThreadPlanCallFunction.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ThreadPlanCallFunction.cpp; path = source/Target/ThreadPlanCallFunction.cpp; sourceTree = ""; }; @@ -2280,8 +2281,8 @@ 49CF9829122C70BD007A0B96 /* IRDynamicChecks.cpp */, 49307AB111DEA4F20081F992 /* IRForTarget.h */, 49307AAD11DEA4D90081F992 /* IRForTarget.cpp */, - 49DA743411DE6BB2006AEF7E /* IRToDWARF.h */, - 49DA742F11DE6A5A006AEF7E /* IRToDWARF.cpp */, + 496B015A1406DEB100F830D5 /* IRInterpreter.h */, + 496B01581406DE8900F830D5 /* IRInterpreter.cpp */, 4C98D3E1118FB98F00E575D0 /* RecordingMemoryManager.h */, 4C98D3DB118FB96F00E575D0 /* RecordingMemoryManager.cpp */, 49C850761384A02F007DB519 /* ProcessDataAllocator.h */, @@ -2760,6 +2761,7 @@ isa = PBXHeadersBuildPhase; buildActionMask = 2147483647; files = ( + 496B015B1406DEB100F830D5 /* IRInterpreter.h in Headers */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -3151,7 +3153,6 @@ 2689006913353E0E00698AC0 /* ASTStructExtractor.cpp in Sources */, 2689006A13353E0E00698AC0 /* IRDynamicChecks.cpp in Sources */, 2689006B13353E0E00698AC0 /* IRForTarget.cpp in Sources */, - 2689006C13353E0E00698AC0 /* IRToDWARF.cpp in Sources */, 2689006D13353E0E00698AC0 /* RecordingMemoryManager.cpp in Sources */, 2689006E13353E1A00698AC0 /* File.cpp in Sources */, 2689006F13353E1A00698AC0 /* FileSpec.cpp in Sources */, @@ -3361,11 +3362,12 @@ 26274FA714030F79006BA130 /* DynamicLoaderDarwinKernel.cpp in Sources */, 94FA3DE01405D50400833217 /* ValueObjectConstResultChild.cpp in Sources */, 949ADF031406F648004833E1 /* ValueObjectConstResultImpl.cpp in Sources */, - 268ED0A5140FF54200DE830F /* DataEncoder.cpp in Sources */, 26A0DA4E140F7226006DA411 /* HashedNameToDIE.cpp in Sources */, B27318421416AC12006039C8 /* WatchpointLocationList.cpp in Sources */, 26E152261419CAD4007967D0 /* ObjectFilePECOFF.cpp in Sources */, B2462247141AD37D00F3D409 /* OptionGroupWatchpoint.cpp in Sources */, + 49A71FE7141FFA5C00D59478 /* IRInterpreter.cpp in Sources */, + 49A71FE8141FFACF00D59478 /* DataEncoder.cpp in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; Modified: lldb/trunk/source/API/SBFrame.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBFrame.cpp?rev=139772&r1=139771&r2=139772&view=diff ============================================================================== --- lldb/trunk/source/API/SBFrame.cpp (original) +++ lldb/trunk/source/API/SBFrame.cpp Wed Sep 14 21:13:07 2011 @@ -759,7 +759,8 @@ const bool keep_in_memory = false; exe_results = m_opaque_sp->GetThread().GetProcess().GetTarget().EvaluateExpression(expr, - m_opaque_sp.get(), + m_opaque_sp.get(), + eExecutionPolicyOnlyWhenNeeded, unwind_on_error, keep_in_memory, fetch_dynamic_value, Modified: lldb/trunk/source/API/SBValue.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBValue.cpp?rev=139772&r1=139771&r2=139772&view=diff ============================================================================== --- lldb/trunk/source/API/SBValue.cpp (original) +++ lldb/trunk/source/API/SBValue.cpp Wed Sep 14 21:13:07 2011 @@ -379,7 +379,10 @@ ValueObjectSP result_valobj_sp; m_opaque_sp->GetUpdatePoint().GetTargetSP()->EvaluateExpression (expression, m_opaque_sp->GetUpdatePoint().GetExecutionContextScope()->CalculateStackFrame(), - true, true, eNoDynamicValues, + eExecutionPolicyAlways, + true, // unwind on error + true, // keep in memory + eNoDynamicValues, result_valobj_sp); result_valobj_sp->SetName(ConstString(name)); result = SBValue(result_valobj_sp); Modified: lldb/trunk/source/Breakpoint/BreakpointOptions.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Breakpoint/BreakpointOptions.cpp?rev=139772&r1=139771&r2=139772&view=diff ============================================================================== --- lldb/trunk/source/Breakpoint/BreakpointOptions.cpp (original) +++ lldb/trunk/source/Breakpoint/BreakpointOptions.cpp Wed Sep 14 21:13:07 2011 @@ -199,7 +199,9 @@ ClangASTContext *ast_context = exe_ctx.target->GetScratchClangASTContext(); TypeFromUser bool_type(ast_context->GetBuiltInType_bool(), ast_context->getASTContext()); - if (!m_condition_ap->Parse (error_stream, exe_ctx, bool_type, false /* keep_in_memory */)) + const bool keep_in_memory = false; + + if (!m_condition_ap->Parse (error_stream, exe_ctx, bool_type, eExecutionPolicyAlways, keep_in_memory)) { // Errors mean we should stop. return NULL; Modified: lldb/trunk/source/Commands/CommandObjectExpression.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectExpression.cpp?rev=139772&r1=139771&r2=139772&view=diff ============================================================================== --- lldb/trunk/source/Commands/CommandObjectExpression.cpp (original) +++ lldb/trunk/source/Commands/CommandObjectExpression.cpp Wed Sep 14 21:13:07 2011 @@ -95,12 +95,13 @@ break; case 'u': - bool success; - unwind_on_error = Args::StringToBoolean(option_arg, true, &success); - if (!success) - error.SetErrorStringWithFormat("Could not convert \"%s\" to a boolean value.", option_arg); - break; - + { + bool success; + unwind_on_error = Args::StringToBoolean(option_arg, true, &success); + if (!success) + error.SetErrorStringWithFormat("Could not convert \"%s\" to a boolean value.", option_arg); + break; + } default: error.SetErrorStringWithFormat("Invalid short option character '%c'.\n", short_option); break; @@ -292,7 +293,13 @@ break; } - exe_results = m_exe_ctx.target->EvaluateExpression(expr, m_exe_ctx.frame, m_options.unwind_on_error, keep_in_memory, use_dynamic, result_valobj_sp); + exe_results = m_exe_ctx.target->EvaluateExpression(expr, + m_exe_ctx.frame, + eExecutionPolicyOnlyWhenNeeded, + m_options.unwind_on_error, + keep_in_memory, + use_dynamic, + result_valobj_sp); if (exe_results == eExecutionInterrupted && !m_options.unwind_on_error) { @@ -488,7 +495,6 @@ { LLDB_OPT_SET_2, false, "dynamic-value", 'd', required_argument, NULL, 0, eArgTypeBoolean, "Upcast the value resulting from the expression to its dynamic type if available."}, { LLDB_OPT_SET_ALL, false, "unwind-on-error", 'u', required_argument, NULL, 0, eArgTypeBoolean, "Clean up program state if the expression causes a crash, breakpoint hit or signal."}, { LLDB_OPT_SET_ALL, false, "debug", 'g', no_argument, NULL, 0, eArgTypeNone, "Enable verbose debug logging of the expression parsing and evaluation."}, -{ LLDB_OPT_SET_ALL, false, "use-ir", 'i', no_argument, NULL, 0, eArgTypeNone, "[Temporary] Instructs the expression evaluator to use IR instead of ASTs."}, { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL } }; Modified: lldb/trunk/source/Expression/ClangExpressionDeclMap.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/ClangExpressionDeclMap.cpp?rev=139772&r1=139771&r2=139772&view=diff ============================================================================== --- lldb/trunk/source/Expression/ClangExpressionDeclMap.cpp (original) +++ lldb/trunk/source/Expression/ClangExpressionDeclMap.cpp Wed Sep 14 21:13:07 2011 @@ -82,6 +82,8 @@ if (exe_ctx.target && !exe_ctx.target->GetScratchClangASTContext()) return false; + m_parser_vars->m_target_info = GetTargetInfo(); + return true; } @@ -118,6 +120,29 @@ // Interface for IRForTarget +ClangExpressionDeclMap::TargetInfo +ClangExpressionDeclMap::GetTargetInfo() +{ + assert (m_parser_vars.get()); + + TargetInfo ret; + + ExecutionContext *exe_ctx = m_parser_vars->m_exe_ctx; + + if (exe_ctx->process) + { + ret.byte_order = exe_ctx->process->GetByteOrder(); + ret.address_byte_size = exe_ctx->process->GetAddressByteSize(); + } + else if (exe_ctx->target) + { + ret.byte_order = exe_ctx->target->GetArchitecture().GetByteOrder(); + ret.address_byte_size = exe_ctx->target->GetArchitecture().GetAddressByteSize(); + } + + return ret; +} + const ConstString & ClangExpressionDeclMap::GetPersistentResultName () { @@ -146,12 +171,12 @@ type.GetASTContext(), type.GetOpaqueQualType()), context); - + if (!m_parser_vars->m_persistent_vars->CreatePersistentVariable (exe_ctx->GetBestExecutionContextScope (), name, user_type, - exe_ctx->process->GetByteOrder(), - exe_ctx->process->GetAddressByteSize())) + m_parser_vars->m_target_info.byte_order, + m_parser_vars->m_target_info.address_byte_size)) return lldb::ClangExpressionVariableSP(); ClangExpressionVariableSP pvar_sp (m_parser_vars->m_persistent_vars->GetVariable(name)); @@ -164,9 +189,7 @@ return lldb::ClangExpressionVariableSP(); uint64_t value64 = value.getLimitedValue(); - - ByteOrder byte_order = exe_ctx->process->GetByteOrder(); - + size_t num_val_bytes = sizeof(value64); size_t num_data_bytes = pvar_sp->GetByteSize(); @@ -182,7 +205,7 @@ uint64_t mask = 0xffll << shift; uint8_t cur_byte = (uint8_t)((value64 & mask) >> shift); - switch (byte_order) + switch (m_parser_vars->m_target_info.byte_order) { case eByteOrderBig: // High Low @@ -276,6 +299,59 @@ return pvar_sp; } +bool +ClangExpressionDeclMap::ResultIsReference (const ConstString &name) +{ + ClangExpressionVariableSP pvar_sp = m_parser_vars->m_persistent_vars->GetVariable(name); + + return (pvar_sp->m_flags & ClangExpressionVariable::EVIsProgramReference); +} + +bool +ClangExpressionDeclMap::CompleteResultVariable (lldb::ClangExpressionVariableSP &valobj, + lldb_private::Value &value, + const ConstString &name, + lldb_private::TypeFromParser type) +{ + assert (m_parser_vars.get()); + + ClangExpressionVariableSP pvar_sp = m_parser_vars->m_persistent_vars->GetVariable(name); + + if (!pvar_sp) + return false; + + if (pvar_sp->m_flags & ClangExpressionVariable::EVIsProgramReference && + !pvar_sp->m_live_sp) + { + // The reference comes from the program. We need to set up a live SP for it. + + pvar_sp->m_live_sp = ValueObjectConstResult::Create(m_parser_vars->m_exe_ctx->GetBestExecutionContextScope(), + pvar_sp->GetTypeFromUser().GetASTContext(), + pvar_sp->GetTypeFromUser().GetOpaqueQualType(), + pvar_sp->GetName(), + value.GetScalar().ULongLong(), + value.GetValueAddressType(), + pvar_sp->GetByteSize()); + } + + if (pvar_sp->m_flags & ClangExpressionVariable::EVNeedsFreezeDry) + { + pvar_sp->ValueUpdated(); + + const size_t pvar_byte_size = pvar_sp->GetByteSize(); + uint8_t *pvar_data = pvar_sp->GetValueBytes(); + + if (!ReadTarget(pvar_data, value, pvar_byte_size)) + return false; + + pvar_sp->m_flags &= ~(ClangExpressionVariable::EVNeedsFreezeDry); + } + + valobj = pvar_sp; + + return true; +} + bool ClangExpressionDeclMap::AddPersistentVariable ( @@ -297,12 +373,15 @@ parser_type.GetASTContext(), parser_type.GetOpaqueQualType()), context); + + if (!m_parser_vars->m_target_info.IsValid()) + return false; if (!m_parser_vars->m_persistent_vars->CreatePersistentVariable (exe_ctx->GetBestExecutionContextScope (), name, user_type, - exe_ctx->process->GetByteOrder(), - exe_ctx->process->GetAddressByteSize())) + m_parser_vars->m_target_info.byte_order, + m_parser_vars->m_target_info.address_byte_size)) return false; ClangExpressionVariableSP var_sp (m_parser_vars->m_persistent_vars->GetVariable(name)); @@ -653,6 +732,204 @@ return GetSymbolAddress(*m_parser_vars->m_exe_ctx->target, name); } +// Interface for IRInterpreter + +bool +ClangExpressionDeclMap::WriteTarget (lldb_private::Value &value, + const uint8_t *data, + size_t length) +{ + assert (m_parser_vars.get()); + + ExecutionContext *exe_ctx = m_parser_vars->m_exe_ctx; + + if (value.GetContextType() == Value::eContextTypeRegisterInfo) + { + if (!exe_ctx->process) + return false; + + RegisterContext *reg_ctx = exe_ctx->GetRegisterContext(); + RegisterInfo *reg_info = value.GetRegisterInfo(); + + if (!reg_ctx) + return false; + + lldb_private::RegisterValue reg_value; + Error err; + + if (!reg_value.SetFromMemoryData (reg_info, data, length, exe_ctx->process->GetByteOrder(), err)) + return false; + + return reg_ctx->WriteRegister(reg_info, reg_value); + } + else + { + switch (value.GetValueType()) + { + default: + return false; + case Value::eValueTypeFileAddress: + { + if (!exe_ctx->process) + return false; + + Address file_addr; + + if (!exe_ctx->target->GetImages().ResolveFileAddress((lldb::addr_t)value.GetScalar().ULongLong(), file_addr)) + return false; + + lldb::addr_t load_addr = file_addr.GetLoadAddress(exe_ctx->target); + + Error err; + exe_ctx->process->WriteMemory(load_addr, data, length, err); + + return err.Success(); + } + case Value::eValueTypeLoadAddress: + { + if (!exe_ctx->process) + return false; + + Error err; + exe_ctx->process->WriteMemory((lldb::addr_t)value.GetScalar().ULongLong(), data, length, err); + + return err.Success(); + } + case Value::eValueTypeHostAddress: + memcpy ((void *)value.GetScalar().ULongLong(), data, length); + return true; + case Value::eValueTypeScalar: + return false; + } + } +} + +bool +ClangExpressionDeclMap::ReadTarget (uint8_t *data, + lldb_private::Value &value, + size_t length) +{ + assert (m_parser_vars.get()); + + ExecutionContext *exe_ctx = m_parser_vars->m_exe_ctx; + + if (value.GetContextType() == Value::eContextTypeRegisterInfo) + { + if (!exe_ctx->process) + return false; + + RegisterContext *reg_ctx = exe_ctx->GetRegisterContext(); + RegisterInfo *reg_info = value.GetRegisterInfo(); + + if (!reg_ctx) + return false; + + lldb_private::RegisterValue reg_value; + Error err; + + if (!reg_ctx->ReadRegister(reg_info, reg_value)) + return false; + + return reg_value.GetAsMemoryData(reg_info, data, length, exe_ctx->process->GetByteOrder(), err); + } + else + { + switch (value.GetValueType()) + { + default: + return false; + case Value::eValueTypeFileAddress: + { + if (!exe_ctx->target) + return false; + + Address file_addr; + + if (!exe_ctx->target->GetImages().ResolveFileAddress((lldb::addr_t)value.GetScalar().ULongLong(), file_addr)) + return false; + + Error err; + exe_ctx->target->ReadMemory(file_addr, true, data, length, err); + + return err.Success(); + } + case Value::eValueTypeLoadAddress: + { + if (!exe_ctx->process) + return false; + + Error err; + exe_ctx->process->ReadMemory((lldb::addr_t)value.GetScalar().ULongLong(), data, length, err); + + return err.Success(); + } + case Value::eValueTypeHostAddress: + memcpy (data, (const void *)value.GetScalar().ULongLong(), length); + return true; + case Value::eValueTypeScalar: + return false; + } + } +} + +lldb_private::Value +ClangExpressionDeclMap::LookupDecl (clang::NamedDecl *decl) +{ + assert (m_parser_vars.get()); + + ExecutionContext exe_ctx = *m_parser_vars->m_exe_ctx; + + ClangExpressionVariableSP expr_var_sp (m_found_entities.GetVariable(decl)); + ClangExpressionVariableSP persistent_var_sp (m_parser_vars->m_persistent_vars->GetVariable(decl)); + + if (expr_var_sp) + { + const ConstString &name(expr_var_sp->GetName()); + TypeFromUser type(expr_var_sp->GetTypeFromUser()); + + if (m_parser_vars->m_exe_ctx->frame) + { + VariableSP var(FindVariableInScope (*exe_ctx.frame, name, &type)); + + if (var) + return *GetVariableValue(exe_ctx, var, NULL); + } + + if (m_parser_vars->m_exe_ctx->target) + { + VariableSP global(FindGlobalVariable (*exe_ctx.target, name.GetCString(), &type)); + + if (global) + return *GetVariableValue(exe_ctx, global, NULL); + + lldb::addr_t location_load_addr = GetSymbolAddress(*exe_ctx.target, name); + + if (location_load_addr != LLDB_INVALID_ADDRESS) + { + lldb_private::Value ret; + ret.SetValueType(Value::eValueTypeLoadAddress); + ret.SetContext(Value::eContextTypeInvalid, NULL); + ret.GetScalar() = location_load_addr; + return ret; + } + } + + return Value(); + } + else if (persistent_var_sp) + { + lldb_private::Value ret; + ret.SetValueType(Value::eValueTypeHostAddress); + ret.SetContext(Value::eContextTypeInvalid, NULL); + ret.GetScalar() = (lldb::addr_t)persistent_var_sp->GetValueBytes(); + return ret; + } + else + { + return Value(); + } +} + // Interface for CommandObjectExpression bool @@ -1630,8 +1907,8 @@ SymbolContextList sc_list; target.GetImages().FindSymbolsWithNameAndType(name, - eSymbolTypeData, - sc_list); + eSymbolTypeData, + sc_list); if (sc_list.GetSize()) { @@ -1644,7 +1921,67 @@ return NULL; } +// This is a callback used with Variable::GetValuesForVariableExpressionPath + +static uint32_t GetVariableCallback (void *baton, + const char *name, + VariableList &variable_list) +{ + Target *target = static_cast(baton); + if (target) + { + return target->GetImages().FindGlobalVariables (ConstString(name), + true, + UINT32_MAX, + variable_list); + } + return 0; +} + +lldb::VariableSP +ClangExpressionDeclMap::FindGlobalVariable +( + Target &target, + const char *name, + TypeFromUser *type +) +{ + VariableList vars; + ValueObjectList valobjs; + + Error error (Variable::GetValuesForVariableExpressionPath (name, + &target, + GetVariableCallback, + &target, + vars, + valobjs)); + + if (vars.GetSize()) + { + if (type) + { + for (size_t i = 0; i < vars.GetSize(); ++i) + { + VariableSP var_sp = vars.GetVariableAtIndex(i); + + if (type->GetASTContext() == var_sp->GetType()->GetClangAST()) + { + if (ClangASTContext::AreTypesSame(type->GetASTContext(), type->GetOpaqueQualType(), var_sp->GetType()->GetClangFullType())) + return var_sp; + } + } + } + else + { + return vars.GetVariableAtIndex(0); + } + } + + return VariableSP(); +} + // Interface for ClangASTSource + void ClangExpressionDeclMap::GetDecls (NameSearchContext &context, const ConstString &name) { @@ -1656,10 +1993,6 @@ if (log) log->Printf("Hunting for a definition for '%s'", name.GetCString()); - // Back out in all cases where we're not fully initialized - if (m_parser_vars->m_exe_ctx->frame == NULL) - return; - if (m_parser_vars->m_ignore_lookups) { if (log) @@ -1740,19 +2073,37 @@ ValueObjectSP valobj; VariableSP var; Error err; + bool found = false; - valobj = m_parser_vars->m_exe_ctx->frame->GetValueForVariableExpressionPath(name_unique_cstr, - eNoDynamicValues, - StackFrame::eExpressionPathOptionCheckPtrVsMember, - var, - err); - - // If we found a variable in scope, no need to pull up function names - if (err.Success() && var != NULL) + if (m_parser_vars->m_exe_ctx->frame) { - AddOneVariable(context, var); + valobj = m_parser_vars->m_exe_ctx->frame->GetValueForVariableExpressionPath(name_unique_cstr, + eNoDynamicValues, + StackFrame::eExpressionPathOptionCheckPtrVsMember, + var, + err); + + // If we found a variable in scope, no need to pull up function names + if (err.Success() && var != NULL) + { + AddOneVariable(context, var); + found = true; + } } - else + else if (m_parser_vars->m_exe_ctx->target) + { + var = FindGlobalVariable(*m_parser_vars->m_exe_ctx->target, + name_unique_cstr, + NULL); + + if (var) + { + AddOneVariable(context, var); + found = true; + } + } + + if (!found) { const bool include_symbols = true; const bool append = false; @@ -1781,6 +2132,7 @@ if (!found_specific) AddOneFunction(context, sym_ctx.function, NULL); found_specific = true; + found = true; } else if (sym_ctx.symbol) { @@ -1794,12 +2146,19 @@ if (!found_specific) { if (generic_symbol) + { AddOneFunction (context, NULL, generic_symbol); + found = true; + } else if (non_extern_symbol) + { AddOneFunction (context, NULL, non_extern_symbol); + found = true; + } } } - else + + if (!found) { // We couldn't find a variable or function for this. Now we'll hunt for a generic // data symbol, and -- if it is found -- treat it as a variable. @@ -1807,7 +2166,10 @@ Symbol *data_symbol = FindGlobalDataSymbol(*m_parser_vars->m_exe_ctx->target, name); if (data_symbol) + { AddOneGenericVariable(context, *data_symbol); + found = true; + } } } @@ -1829,15 +2191,19 @@ NamespaceDecl *clang_namespace_decl = AddNamespace(context, namespace_decl); if (clang_namespace_decl) clang_namespace_decl->setHasExternalLexicalStorage(); - } + } } else { static ConstString g_lldb_class_name ("$__lldb_class"); + if (name == g_lldb_class_name) { // Clang is looking for the type of "this" + if (!m_parser_vars->m_exe_ctx->frame) + return; + VariableList *vars = m_parser_vars->m_exe_ctx->frame->GetVariableList(false); if (!vars) @@ -1900,6 +2266,9 @@ { // Clang is looking for the type of "*self" + if (!m_parser_vars->m_exe_ctx->frame) + return; + VariableList *vars = m_parser_vars->m_exe_ctx->frame->GetVariableList(false); if (!vars) @@ -2213,8 +2582,11 @@ lldb::addr_t load_addr = so_addr.GetLoadAddress(exe_ctx.target); - var_location->GetScalar() = load_addr; - var_location->SetValueType(Value::eValueTypeLoadAddress); + if (load_addr != LLDB_INVALID_ADDRESS) + { + var_location->GetScalar() = load_addr; + var_location->SetValueType(Value::eValueTypeLoadAddress); + } } if (user_type) @@ -2229,7 +2601,7 @@ assert (m_parser_vars.get()); lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS)); - + TypeFromUser ut; TypeFromParser pt; @@ -2248,8 +2620,8 @@ ClangExpressionVariableSP entity(m_found_entities.CreateVariable (m_parser_vars->m_exe_ctx->GetBestExecutionContextScope (), entity_name, ut, - m_parser_vars->m_exe_ctx->process->GetByteOrder(), - m_parser_vars->m_exe_ctx->process->GetAddressByteSize())); + m_parser_vars->m_target_info.byte_order, + m_parser_vars->m_target_info.address_byte_size)); assert (entity.get()); entity->EnableParserVars(); entity->m_parser_vars->m_parser_type = pt; @@ -2331,8 +2703,8 @@ ClangExpressionVariableSP entity(m_found_entities.CreateVariable (m_parser_vars->m_exe_ctx->GetBestExecutionContextScope (), entity_name, user_type, - m_parser_vars->m_exe_ctx->process->GetByteOrder(), - m_parser_vars->m_exe_ctx->process->GetAddressByteSize())); + m_parser_vars->m_target_info.byte_order, + m_parser_vars->m_target_info.address_byte_size)); assert (entity.get()); std::auto_ptr symbol_location(new Value); @@ -2449,8 +2821,8 @@ NamedDecl *var_decl = context.AddVarDecl(parser_type.GetOpaqueQualType()); ClangExpressionVariableSP entity(m_found_entities.CreateVariable (m_parser_vars->m_exe_ctx->GetBestExecutionContextScope(), - m_parser_vars->m_exe_ctx->process->GetByteOrder(), - m_parser_vars->m_exe_ctx->process->GetAddressByteSize())); + m_parser_vars->m_target_info.byte_order, + m_parser_vars->m_target_info.address_byte_size)); assert (entity.get()); std::string decl_name(context.m_decl_name.getAsString()); entity->SetName (ConstString (decl_name.c_str())); @@ -2547,8 +2919,8 @@ fun_location->GetScalar() = load_addr; ClangExpressionVariableSP entity(m_found_entities.CreateVariable (m_parser_vars->m_exe_ctx->GetBestExecutionContextScope (), - m_parser_vars->m_exe_ctx->process->GetByteOrder(), - m_parser_vars->m_exe_ctx->process->GetAddressByteSize())); + m_parser_vars->m_target_info.byte_order, + m_parser_vars->m_target_info.address_byte_size)); assert (entity.get()); std::string decl_name(context.m_decl_name.getAsString()); entity->SetName(ConstString(decl_name.c_str())); Modified: lldb/trunk/source/Expression/ClangExpressionParser.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/ClangExpressionParser.cpp?rev=139772&r1=139771&r2=139772&view=diff ============================================================================== --- lldb/trunk/source/Expression/ClangExpressionParser.cpp (original) +++ lldb/trunk/source/Expression/ClangExpressionParser.cpp Wed Sep 14 21:13:07 2011 @@ -19,7 +19,6 @@ #include "lldb/Expression/ClangExpression.h" #include "lldb/Expression/ClangExpressionDeclMap.h" #include "lldb/Expression/IRDynamicChecks.h" -#include "lldb/Expression/IRToDWARF.h" #include "lldb/Expression/RecordingMemoryManager.h" #include "lldb/Target/ExecutionContext.h" #include "lldb/Target/ObjCLanguageRuntime.h" @@ -418,66 +417,14 @@ } Error -ClangExpressionParser::MakeDWARF () -{ - Error err; - - llvm::Module *module = m_code_generator->GetModule(); - - if (!module) - { - err.SetErrorToGenericError(); - err.SetErrorString("IR doesn't contain a module"); - return err; - } - - ClangExpressionVariableList *local_variables = m_expr.LocalVariables(); - ClangExpressionDeclMap *decl_map = m_expr.DeclMap(); - - if (!local_variables) - { - err.SetErrorToGenericError(); - err.SetErrorString("Can't convert an expression without a VariableList to DWARF"); - return err; - } - - if (!decl_map) - { - err.SetErrorToGenericError(); - err.SetErrorString("Can't convert an expression without a DeclMap to DWARF"); - return err; - } - - std::string function_name; - - if (!FindFunctionInModule(function_name, module, m_expr.FunctionName())) - { - err.SetErrorToGenericError(); - err.SetErrorStringWithFormat("Couldn't find %s() in the module", m_expr.FunctionName()); - return err; - } - - IRToDWARF ir_to_dwarf(*local_variables, decl_map, m_expr.DwarfOpcodeStream(), function_name.c_str()); - - if (!ir_to_dwarf.runOnModule(*module)) - { - err.SetErrorToGenericError(); - err.SetErrorString("Couldn't convert the expression to DWARF"); - return err; - } - - err.Clear(); - return err; -} - -Error -ClangExpressionParser::MakeJIT (lldb::addr_t &func_allocation_addr, - lldb::addr_t &func_addr, - lldb::addr_t &func_end, - ExecutionContext &exe_ctx, - IRForTarget::StaticDataAllocator *data_allocator, - lldb::ClangExpressionVariableSP &const_result, - bool jit_only_if_needed) +ClangExpressionParser::PrepareForExecution (lldb::addr_t &func_allocation_addr, + lldb::addr_t &func_addr, + lldb::addr_t &func_end, + ExecutionContext &exe_ctx, + IRForTarget::StaticDataAllocator *data_allocator, + bool &evaluated_statically, + lldb::ClangExpressionVariableSP &const_result, + ExecutionPolicy execution_policy) { func_allocation_addr = LLDB_INVALID_ADDRESS; func_addr = LLDB_INVALID_ADDRESS; @@ -520,8 +467,9 @@ if (exe_ctx.target) error_stream = &exe_ctx.target->GetDebugger().GetErrorStream(); - IRForTarget ir_for_target(decl_map, + IRForTarget ir_for_target(decl_map, m_expr.NeedsVariableResolution(), + execution_policy, const_result, data_allocator, error_stream, @@ -530,17 +478,25 @@ if (!ir_for_target.runOnModule(*module)) { err.SetErrorToGenericError(); - err.SetErrorString("Couldn't convert the expression to DWARF"); + err.SetErrorString("Couldn't prepare the expression for execution in the target"); return err; } - if (jit_only_if_needed && const_result.get()) + if (execution_policy != eExecutionPolicyAlways && ir_for_target.interpretSuccess()) { + evaluated_statically = true; err.Clear(); return err; } - if (m_expr.NeedsValidation() && exe_ctx.process->GetDynamicCheckers()) + if (!exe_ctx.process || execution_policy == eExecutionPolicyNever) + { + err.SetErrorToGenericError(); + err.SetErrorString("Execution needed to run in the target, but the target can't be run"); + return err; + } + + if (m_expr.NeedsValidation() && exe_ctx.process && exe_ctx.process->GetDynamicCheckers()) { IRDynamicChecks ir_dynamic_checks(*exe_ctx.process->GetDynamicCheckers(), function_name.c_str()); Modified: lldb/trunk/source/Expression/ClangFunction.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/ClangFunction.cpp?rev=139772&r1=139771&r2=139772&view=diff ============================================================================== --- lldb/trunk/source/Expression/ClangFunction.cpp (original) +++ lldb/trunk/source/Expression/ClangFunction.cpp Wed Sep 14 21:13:07 2011 @@ -253,7 +253,16 @@ lldb::ClangExpressionVariableSP const_result; - Error jit_error (m_parser->MakeJIT (m_jit_alloc, m_jit_start_addr, m_jit_end_addr, exe_ctx, NULL, const_result)); + bool evaluated_statically = false; // should stay that way + + Error jit_error (m_parser->PrepareForExecution (m_jit_alloc, + m_jit_start_addr, + m_jit_end_addr, + exe_ctx, + NULL, + evaluated_statically, + const_result, + eExecutionPolicyAlways)); if (!jit_error.Success()) return false; Modified: lldb/trunk/source/Expression/ClangUserExpression.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/ClangUserExpression.cpp?rev=139772&r1=139771&r2=139772&view=diff ============================================================================== --- lldb/trunk/source/Expression/ClangUserExpression.cpp (original) +++ lldb/trunk/source/Expression/ClangUserExpression.cpp Wed Sep 14 21:13:07 2011 @@ -53,6 +53,7 @@ m_objectivec (false), m_needs_object_ptr (false), m_const_object (false), + m_evaluated_statically (false), m_const_result (), m_target (NULL) { @@ -167,6 +168,7 @@ ClangUserExpression::Parse (Stream &error_stream, ExecutionContext &exe_ctx, TypeFromUser desired_type, + lldb_private::ExecutionPolicy execution_policy, bool keep_result_in_memory) { lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS)); @@ -279,39 +281,23 @@ return false; } - /////////////////////////////////////////////// - // Convert the output of the parser to DWARF + ////////////////////////////////////////////////////////////////////////////////////////// + // Prepare the output of the parser for execution, evaluating it statically if possible // - - m_dwarf_opcodes.reset(new StreamString); - m_dwarf_opcodes->SetByteOrder (lldb::endian::InlHostByteOrder()); - m_dwarf_opcodes->GetFlags ().Set (Stream::eBinary); - - m_local_variables.reset(new ClangExpressionVariableList()); - - Error dwarf_error = parser.MakeDWARF (); - - if (dwarf_error.Success()) - { - if (log) - log->Printf("Code can be interpreted."); - m_expr_decl_map->DidParse(); - - return true; - } - - ////////////////////////////////// - // JIT the output of the parser - // - - m_dwarf_opcodes.reset(); - - m_data_allocator.reset(new ProcessDataAllocator(*exe_ctx.process)); + if (execution_policy != eExecutionPolicyNever && exe_ctx.process) + m_data_allocator.reset(new ProcessDataAllocator(*exe_ctx.process)); - Error jit_error = parser.MakeJIT (m_jit_alloc, m_jit_start_addr, m_jit_end_addr, exe_ctx, m_data_allocator.get(), m_const_result, true); + Error jit_error = parser.PrepareForExecution (m_jit_alloc, + m_jit_start_addr, + m_jit_end_addr, + exe_ctx, + m_data_allocator.get(), + m_evaluated_statically, + m_const_result, + execution_policy); - if (log) + if (log && m_data_allocator.get()) { StreamString dump_string; m_data_allocator->Dump(dump_string); @@ -505,15 +491,7 @@ // expression, it's quite convenient to have these logs come out with the STEP log as well. lldb::LogSP log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_EXPRESSIONS | LIBLLDB_LOG_STEP)); - if (m_dwarf_opcodes.get()) - { - // TODO execute the JITted opcodes - - error_stream.Printf("We don't currently support executing DWARF expressions"); - - return eExecutionSetupError; - } - else if (m_jit_start_addr != LLDB_INVALID_ADDRESS) + if (m_jit_start_addr != LLDB_INVALID_ADDRESS) { lldb::addr_t struct_address; @@ -594,38 +572,31 @@ } else { - error_stream.Printf("Expression can't be run; neither DWARF nor a JIT compiled function is present"); + error_stream.Printf("Expression can't be run, because there is no JIT compiled function"); return eExecutionSetupError; } } -StreamString & -ClangUserExpression::DwarfOpcodeStream () -{ - if (!m_dwarf_opcodes.get()) - m_dwarf_opcodes.reset(new StreamString()); - - return *m_dwarf_opcodes.get(); -} - ExecutionResults -ClangUserExpression::Evaluate (ExecutionContext &exe_ctx, +ClangUserExpression::Evaluate (ExecutionContext &exe_ctx, + lldb_private::ExecutionPolicy execution_policy, bool discard_on_error, const char *expr_cstr, const char *expr_prefix, lldb::ValueObjectSP &result_valobj_sp) { Error error; - return EvaluateWithError (exe_ctx, discard_on_error, expr_cstr, expr_prefix, result_valobj_sp, error); + return EvaluateWithError (exe_ctx, execution_policy, discard_on_error, expr_cstr, expr_prefix, result_valobj_sp, error); } ExecutionResults -ClangUserExpression::EvaluateWithError (ExecutionContext &exe_ctx, - bool discard_on_error, - const char *expr_cstr, - const char *expr_prefix, - lldb::ValueObjectSP &result_valobj_sp, - Error &error) +ClangUserExpression::EvaluateWithError (ExecutionContext &exe_ctx, + lldb_private::ExecutionPolicy execution_policy, + bool discard_on_error, + const char *expr_cstr, + const char *expr_prefix, + lldb::ValueObjectSP &result_valobj_sp, + Error &error) { lldb::LogSP log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_EXPRESSIONS | LIBLLDB_LOG_STEP)); @@ -633,13 +604,18 @@ if (exe_ctx.process == NULL || exe_ctx.process->GetState() != lldb::eStateStopped) { - error.SetErrorString ("must have a stopped process to evaluate expressions."); + if (execution_policy == eExecutionPolicyAlways) + { + if (log) + log->Printf("== [ClangUserExpression::Evaluate] Expression may not run, but is not constant =="); - result_valobj_sp = ValueObjectConstResult::Create (NULL, error); - return eExecutionSetupError; + error.SetErrorString ("expression needed to run but couldn't"); + + return execution_results; + } } - - if (!exe_ctx.process->GetDynamicCheckers()) + + if (execution_policy != eExecutionPolicyNever && !exe_ctx.process->GetDynamicCheckers()) { if (log) log->Printf("== [ClangUserExpression::Evaluate] Installing dynamic checkers =="); @@ -672,7 +648,9 @@ if (log) log->Printf("== [ClangUserExpression::Evaluate] Parsing expression %s ==", expr_cstr); - if (!user_expression_sp->Parse (error_stream, exe_ctx, TypeFromUser(NULL, NULL), true)) + const bool keep_expression_in_memory = true; + + if (!user_expression_sp->Parse (error_stream, exe_ctx, TypeFromUser(NULL, NULL), execution_policy, keep_expression_in_memory)) { if (error_stream.GetString().empty()) error.SetErrorString ("expression failed to parse, unknown error"); @@ -683,14 +661,26 @@ { lldb::ClangExpressionVariableSP expr_result; - if (user_expression_sp->m_const_result.get()) + if (user_expression_sp->EvaluatedStatically()) { if (log) log->Printf("== [ClangUserExpression::Evaluate] Expression evaluated as a constant =="); - result_valobj_sp = user_expression_sp->m_const_result->GetValueObject(); + if (user_expression_sp->m_const_result) + result_valobj_sp = user_expression_sp->m_const_result->GetValueObject(); + else + error.SetError(ClangUserExpression::kNoResult, lldb::eErrorTypeGeneric); + execution_results = eExecutionCompleted; } + else if (execution_policy == eExecutionPolicyNever) + { + if (log) + log->Printf("== [ClangUserExpression::Evaluate] Expression may not run, but is not constant =="); + + if (error_stream.GetString().empty()) + error.SetErrorString ("expression needed to run but couldn't"); + } else { error_stream.GetString().clear(); Modified: lldb/trunk/source/Expression/ClangUtilityFunction.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/ClangUtilityFunction.cpp?rev=139772&r1=139771&r2=139772&view=diff ============================================================================== --- lldb/trunk/source/Expression/ClangUtilityFunction.cpp (original) +++ lldb/trunk/source/Expression/ClangUtilityFunction.cpp Wed Sep 14 21:13:07 2011 @@ -128,8 +128,16 @@ lldb::ClangExpressionVariableSP const_result; - - Error jit_error = parser.MakeJIT (m_jit_alloc, m_jit_start_addr, m_jit_end_addr, exe_ctx, m_data_allocator.get(), const_result); + bool evaluated_statically = false; // should stay that way + + Error jit_error = parser.PrepareForExecution (m_jit_alloc, + m_jit_start_addr, + m_jit_end_addr, + exe_ctx, + m_data_allocator.get(), + evaluated_statically, + const_result, + eExecutionPolicyAlways); if (log) { Modified: lldb/trunk/source/Expression/IRForTarget.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/IRForTarget.cpp?rev=139772&r1=139771&r2=139772&view=diff ============================================================================== --- lldb/trunk/source/Expression/IRForTarget.cpp (original) +++ lldb/trunk/source/Expression/IRForTarget.cpp Wed Sep 14 21:13:07 2011 @@ -1,4 +1,4 @@ -//===-- IRForTarget.cpp -------------------------------------------*- C++ -*-===// +//===-- IRForTarget.cpp -----------------------------------------*- C++ -*-===// // // The LLVM Compiler Infrastructure // @@ -26,6 +26,7 @@ #include "lldb/Core/Scalar.h" #include "lldb/Core/StreamString.h" #include "lldb/Expression/ClangExpressionDeclMap.h" +#include "lldb/Expression/IRInterpreter.h" #include "lldb/Host/Endian.h" #include "lldb/Symbol/ClangASTContext.h" @@ -45,12 +46,15 @@ IRForTarget::IRForTarget (lldb_private::ClangExpressionDeclMap *decl_map, bool resolve_vars, + lldb_private::ExecutionPolicy execution_policy, lldb::ClangExpressionVariableSP &const_result, StaticDataAllocator *data_allocator, lldb_private::Stream *error_stream, const char *func_name) : ModulePass(ID), m_resolve_vars(resolve_vars), + m_execution_policy(execution_policy), + m_interpret_success(false), m_func_name(func_name), m_module(NULL), m_decl_map(decl_map), @@ -309,12 +313,13 @@ return true; } + clang::NamedDecl * -IRForTarget::DeclForGlobal (GlobalValue *global_val) +IRForTarget::DeclForGlobal (const GlobalValue *global_val, Module *module) { lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS)); - NamedMDNode *named_metadata = m_module->getNamedMetadata("clang.global.decl.ptrs"); + NamedMDNode *named_metadata = module->getNamedMetadata("clang.global.decl.ptrs"); if (!named_metadata) return NULL; @@ -350,6 +355,12 @@ return NULL; } +clang::NamedDecl * +IRForTarget::DeclForGlobal (GlobalValue *global_val) +{ + return DeclForGlobal(global_val, m_module); +} + void IRForTarget::MaybeSetConstantResult (llvm::Constant *initializer, const lldb_private::ConstString &name, @@ -553,9 +564,7 @@ // Get the next available result name from m_decl_map and create the persistent // variable for it - - lldb_private::TypeFromParser result_decl_type; - + // If the result is an Lvalue, it is emitted as a pointer; see // ASTResultSynthesizer::SynthesizeBodyResult. if (m_result_is_pointer) @@ -577,19 +586,19 @@ clang::QualType element_qual_type = pointer_pointertype->getPointeeType(); - result_decl_type = lldb_private::TypeFromParser(element_qual_type.getAsOpaquePtr(), + m_result_type = lldb_private::TypeFromParser(element_qual_type.getAsOpaquePtr(), &result_decl->getASTContext()); } else { - result_decl_type = lldb_private::TypeFromParser(result_var->getType().getAsOpaquePtr(), + m_result_type = lldb_private::TypeFromParser(result_var->getType().getAsOpaquePtr(), &result_decl->getASTContext()); } if (log) { lldb_private::StreamString type_desc_stream; - result_decl_type.DumpTypeDescription(&type_desc_stream); + m_result_type.DumpTypeDescription(&type_desc_stream); log->Printf("Result decl type: \"%s\"", type_desc_stream.GetString().c_str()); } @@ -665,7 +674,7 @@ { MaybeSetConstantResult (initializer, m_result_name, - result_decl_type); + m_result_type); } StoreInst *synthesized_store = new StoreInst(initializer, @@ -677,9 +686,9 @@ } else { - if (!m_has_side_effects && lldb_private::ClangASTContext::IsPointerType (result_decl_type.GetOpaqueQualType())) + if (!m_has_side_effects && lldb_private::ClangASTContext::IsPointerType (m_result_type.GetOpaqueQualType())) { - MaybeSetCastResult (result_decl_type); + MaybeSetCastResult (m_result_type); } result_global->replaceAllUsesWith(new_result_global); @@ -688,7 +697,7 @@ if (!m_const_result) m_decl_map->AddPersistentVariable(result_decl, m_result_name, - result_decl_type, + m_result_type, true, m_result_is_pointer); @@ -2247,6 +2256,9 @@ bool IRForTarget::CompleteDataAllocation () { + if (!m_data_allocator) + return true; + lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS)); if (!m_data_allocator->GetStream().GetSize()) @@ -2335,9 +2347,49 @@ return false; } - - if (m_const_result) + + if (m_const_result && m_execution_policy != lldb_private::eExecutionPolicyAlways) + { + m_interpret_success = true; return true; + } + + for (bbi = function->begin(); + bbi != function->end(); + ++bbi) + { + if (!RemoveGuards(*bbi)) + { + if (log) + log->Printf("RemoveGuards() failed"); + + // RemoveGuards() reports its own errors, so we don't do so here + + return false; + } + + if (!RewritePersistentAllocs(*bbi)) + { + if (log) + log->Printf("RewritePersistentAllocs() failed"); + + // RewritePersistentAllocs() reports its own errors, so we don't do so here + + return false; + } + } + + if (m_decl_map && m_execution_policy != lldb_private::eExecutionPolicyAlways) + { + IRInterpreter interpreter (*m_decl_map, + m_error_stream); + + if (interpreter.maybeRunOnFunction(m_const_result, m_result_name, m_result_type, *function, llvm_module)) + { + m_interpret_success = true; + return true; + } + } if (log) { @@ -2379,34 +2431,10 @@ return false; } - ////////////////////////////////// - // Run basic-block level passes - // - for (bbi = function->begin(); bbi != function->end(); ++bbi) { - if (!RemoveGuards(*bbi)) - { - if (log) - log->Printf("RemoveGuards() failed"); - - // RemoveGuards() reports its own errors, so we don't do so here - - return false; - } - - if (!RewritePersistentAllocs(*bbi)) - { - if (log) - log->Printf("RewritePersistentAllocs() failed"); - - // RewritePersistentAllocs() reports its own errors, so we don't do so here - - return false; - } - if (!RewriteObjCSelectors(*bbi)) { if (log) Added: lldb/trunk/source/Expression/IRInterpreter.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/IRInterpreter.cpp?rev=139772&view=auto ============================================================================== --- lldb/trunk/source/Expression/IRInterpreter.cpp (added) +++ lldb/trunk/source/Expression/IRInterpreter.cpp Wed Sep 14 21:13:07 2011 @@ -0,0 +1,1391 @@ +//===-- IRInterpreter.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/Core/DataEncoder.h" +#include "lldb/Core/Log.h" +#include "lldb/Core/ValueObjectConstResult.h" +#include "lldb/Expression/ClangExpressionDeclMap.h" +#include "lldb/Expression/IRForTarget.h" +#include "lldb/Expression/IRInterpreter.h" + +#include "llvm/Constants.h" +#include "llvm/Function.h" +#include "llvm/Instructions.h" +#include "llvm/Module.h" +#include "llvm/Support/raw_ostream.h" +#include "llvm/Target/TargetData.h" + +#include + +using namespace llvm; + +IRInterpreter::IRInterpreter(lldb_private::ClangExpressionDeclMap &decl_map, + lldb_private::Stream *error_stream) : + m_decl_map(decl_map), + m_error_stream(error_stream) +{ + +} + +IRInterpreter::~IRInterpreter() +{ + +} + +static std::string +PrintValue(const Value *value, bool truncate = false) +{ + std::string s; + raw_string_ostream rso(s); + value->print(rso); + rso.flush(); + if (truncate) + s.resize(s.length() - 1); + + size_t offset; + while ((offset = s.find('\n')) != s.npos) + s.erase(offset, 1); + while (s[0] == ' ' || s[0] == '\t') + s.erase(0, 1); + + return s; +} + +static std::string +PrintType(const Type *type, bool truncate = false) +{ + std::string s; + raw_string_ostream rso(s); + type->print(rso); + rso.flush(); + if (truncate) + s.resize(s.length() - 1); + return s; +} + +typedef lldb::SharedPtr ::Type DataEncoderSP; +typedef lldb::SharedPtr ::Type DataExtractorSP; + +class Memory +{ +public: + typedef uint32_t index_t; + + struct Allocation + { + // m_virtual_address is always the address of the variable in the virtual memory + // space provided by Memory. + // + // m_origin is always non-NULL and describes the source of the data (possibly + // m_data if this allocation is the authoritative source). + // + // Possible value configurations: + // + // Allocation type getValueType() getContextType() m_origin->GetScalar() m_data + // ========================================================================================================================= + // FileAddress eValueTypeFileAddress eContextTypeInvalid A location in a binary NULL + // image + // + // LoadAddress eValueTypeLoadAddress eContextTypeInvalid A location in the target's NULL + // virtual memory + // + // Alloca eValueTypeHostAddress eContextTypeInvalid == m_data->GetBytes() Deleted at end of + // execution + // + // PersistentVar eValueTypeHostAddress eContextTypeClangType A persistent variable's NULL + // location in LLDB's memory + // + // Register [ignored] eContextTypeRegister [ignored] Flushed to the register + // at the end of execution + + lldb::addr_t m_virtual_address; + size_t m_extent; + lldb_private::Value m_origin; + lldb::DataBufferSP m_data; + + Allocation (lldb::addr_t virtual_address, + size_t extent, + lldb::DataBufferSP data) : + m_virtual_address(virtual_address), + m_extent(extent), + m_data(data) + { + } + + Allocation (const Allocation &allocation) : + m_virtual_address(allocation.m_virtual_address), + m_extent(allocation.m_extent), + m_origin(allocation.m_origin), + m_data(allocation.m_data) + { + } + }; + + typedef lldb::SharedPtr ::Type AllocationSP; + + struct Region + { + AllocationSP m_allocation; + uint64_t m_base; + uint64_t m_extent; + + Region () : + m_allocation(), + m_base(0), + m_extent(0) + { + } + + Region (AllocationSP allocation, uint64_t base, uint64_t extent) : + m_allocation(allocation), + m_base(base), + m_extent(extent) + { + } + + Region (const Region ®ion) : + m_allocation(region.m_allocation), + m_base(region.m_base), + m_extent(region.m_extent) + { + } + + bool IsValid () + { + return m_allocation != NULL; + } + + bool IsInvalid () + { + return m_allocation == NULL; + } + }; + + typedef std::vector MemoryMap; + +private: + lldb::addr_t m_addr_base; + lldb::addr_t m_addr_max; + MemoryMap m_memory; + lldb::ByteOrder m_byte_order; + lldb::addr_t m_addr_byte_size; + TargetData &m_target_data; + + lldb_private::ClangExpressionDeclMap &m_decl_map; + + MemoryMap::iterator LookupInternal (lldb::addr_t addr) + { + for (MemoryMap::iterator i = m_memory.begin(), e = m_memory.end(); + i != e; + ++i) + { + if ((*i)->m_virtual_address <= addr && + (*i)->m_virtual_address + (*i)->m_extent > addr) + return i; + } + + return m_memory.end(); + } + +public: + Memory (TargetData &target_data, + lldb_private::ClangExpressionDeclMap &decl_map, + lldb::addr_t alloc_start, + lldb::addr_t alloc_max) : + m_addr_base(alloc_start), + m_addr_max(alloc_max), + m_target_data(target_data), + m_decl_map(decl_map) + { + m_byte_order = (target_data.isLittleEndian() ? lldb::eByteOrderLittle : lldb::eByteOrderBig); + m_addr_byte_size = (target_data.getPointerSize()); + } + + Region Malloc (size_t size, size_t align) + { + lldb::DataBufferSP data(new lldb_private::DataBufferHeap(size, 0)); + + if (data) + { + index_t index = m_memory.size(); + + const size_t mask = (align - 1); + + m_addr_base += mask; + m_addr_base &= ~mask; + + if (m_addr_base + size < m_addr_base || + m_addr_base + size > m_addr_max) + return Region(); + + uint64_t base = m_addr_base; + + m_memory.push_back(AllocationSP(new Allocation(base, size, data))); + + m_addr_base += size; + + AllocationSP alloc = m_memory[index]; + + alloc->m_origin.GetScalar() = (unsigned long long)data->GetBytes(); + alloc->m_origin.SetContext(lldb_private::Value::eContextTypeInvalid, NULL); + alloc->m_origin.SetValueType(lldb_private::Value::eValueTypeHostAddress); + + return Region(alloc, base, size); + } + + return Region(); + } + + Region Malloc (Type *type) + { + return Malloc (m_target_data.getTypeAllocSize(type), + m_target_data.getPrefTypeAlignment(type)); + } + + Region Place (Type *type, lldb::addr_t base, lldb_private::Value &value) + { + index_t index = m_memory.size(); + size_t size = m_target_data.getTypeAllocSize(type); + + m_memory.push_back(AllocationSP(new Allocation(base, size, lldb::DataBufferSP()))); + + AllocationSP alloc = m_memory[index]; + + alloc->m_origin = value; + + return Region(alloc, base, size); + } + + void Free (lldb::addr_t addr) + { + MemoryMap::iterator i = LookupInternal (addr); + + if (i != m_memory.end()) + m_memory.erase(i); + } + + Region Lookup (lldb::addr_t addr, Type *type) + { + MemoryMap::iterator i = LookupInternal(addr); + + if (i == m_memory.end()) + return Region(); + + size_t size = m_target_data.getTypeStoreSize(type); + + return Region(*i, addr, size); + } + + DataEncoderSP GetEncoder (Region region) + { + if (region.m_allocation->m_origin.GetValueType() != lldb_private::Value::eValueTypeHostAddress) + return DataEncoderSP(); + + lldb::DataBufferSP buffer = region.m_allocation->m_data; + + if (!buffer) + return DataEncoderSP(); + + size_t base_offset = (size_t)(region.m_base - region.m_allocation->m_virtual_address); + + return DataEncoderSP(new lldb_private::DataEncoder(buffer->GetBytes() + base_offset, region.m_extent, m_byte_order, m_addr_byte_size)); + } + + DataExtractorSP GetExtractor (Region region) + { + if (region.m_allocation->m_origin.GetValueType() != lldb_private::Value::eValueTypeHostAddress) + return DataExtractorSP(); + + lldb::DataBufferSP buffer = region.m_allocation->m_data; + size_t base_offset = (size_t)(region.m_base - region.m_allocation->m_virtual_address); + + if (buffer) + return DataExtractorSP(new lldb_private::DataExtractor(buffer->GetBytes() + base_offset, region.m_extent, m_byte_order, m_addr_byte_size)); + else + return DataExtractorSP(new lldb_private::DataExtractor((uint8_t*)region.m_allocation->m_origin.GetScalar().ULongLong() + base_offset, region.m_extent, m_byte_order, m_addr_byte_size)); + } + + lldb_private::Value GetAccessTarget(lldb::addr_t addr) + { + MemoryMap::iterator i = LookupInternal(addr); + + if (i == m_memory.end()) + return lldb_private::Value(); + + lldb_private::Value target = (*i)->m_origin; + + if (target.GetContextType() == lldb_private::Value::eContextTypeRegisterInfo) + { + target.SetContext(lldb_private::Value::eContextTypeInvalid, NULL); + target.SetValueType(lldb_private::Value::eValueTypeHostAddress); + target.GetScalar() = (unsigned long long)(*i)->m_data->GetBytes(); + } + + target.GetScalar() += (addr - (*i)->m_virtual_address); + + return target; + } + + bool Write (lldb::addr_t addr, const uint8_t *data, size_t length) + { + lldb_private::Value target = GetAccessTarget(addr); + + return m_decl_map.WriteTarget(target, data, length); + } + + bool Read (uint8_t *data, lldb::addr_t addr, size_t length) + { + lldb_private::Value target = GetAccessTarget(addr); + + return m_decl_map.ReadTarget(data, target, length); + } + + std::string PrintData (lldb::addr_t addr, size_t length) + { + lldb_private::Value target = GetAccessTarget(addr); + + lldb_private::DataBufferHeap buf(length, 0); + + if (!m_decl_map.ReadTarget(buf.GetBytes(), target, length)) + return std::string(""); + + lldb_private::StreamString ss; + + for (size_t i = 0; i < length; i++) + { + if ((!(i & 0xf)) && i) + ss.Printf("%02hhx - ", buf.GetBytes()[i]); + else + ss.Printf("%02hhx ", buf.GetBytes()[i]); + } + + return ss.GetString(); + } + + std::string SummarizeRegion (Region ®ion) + { + lldb_private::StreamString ss; + + lldb_private::Value base = GetAccessTarget(region.m_base); + + ss.Printf("%llx [%s - %s %llx]", + region.m_base, + lldb_private::Value::GetValueTypeAsCString(base.GetValueType()), + lldb_private::Value::GetContextTypeAsCString(base.GetContextType()), + base.GetScalar().ULongLong()); + + ss.Printf(" %s", PrintData(region.m_base, region.m_extent).c_str()); + + return ss.GetString(); + } +}; + +class InterpreterStackFrame +{ +public: + typedef std::map ValueMap; + + ValueMap m_values; + Memory &m_memory; + TargetData &m_target_data; + lldb_private::ClangExpressionDeclMap &m_decl_map; + const BasicBlock *m_bb; + BasicBlock::const_iterator m_ii; + BasicBlock::const_iterator m_ie; + + lldb::ByteOrder m_byte_order; + size_t m_addr_byte_size; + + InterpreterStackFrame (TargetData &target_data, + Memory &memory, + lldb_private::ClangExpressionDeclMap &decl_map) : + m_target_data (target_data), + m_memory (memory), + m_decl_map (decl_map) + { + m_byte_order = (target_data.isLittleEndian() ? lldb::eByteOrderLittle : lldb::eByteOrderBig); + m_addr_byte_size = (target_data.getPointerSize()); + } + + void Jump (const BasicBlock *bb) + { + m_bb = bb; + m_ii = m_bb->begin(); + m_ie = m_bb->end(); + } + + bool Cache (Memory::AllocationSP allocation, Type *type) + { + if (allocation->m_origin.GetContextType() != lldb_private::Value::eContextTypeRegisterInfo) + return false; + + return m_decl_map.ReadTarget(allocation->m_data->GetBytes(), allocation->m_origin, allocation->m_data->GetByteSize()); + } + + std::string SummarizeValue (const Value *value) + { + lldb_private::StreamString ss; + + ss.Printf("%s", PrintValue(value).c_str()); + + ValueMap::iterator i = m_values.find(value); + + if (i != m_values.end()) + { + Memory::Region region = i->second; + + ss.Printf(" %s", m_memory.SummarizeRegion(region).c_str()); + } + + return ss.GetString(); + } + + bool AssignToMatchType (lldb_private::Scalar &scalar, uint64_t u64value, Type *type) + { + size_t type_size = m_target_data.getTypeStoreSize(type); + + switch (type_size) + { + case 1: + scalar = (uint8_t)u64value; + break; + case 2: + scalar = (uint16_t)u64value; + break; + case 4: + scalar = (uint32_t)u64value; + break; + case 8: + scalar = (uint64_t)u64value; + break; + default: + return false; + } + + return true; + } + + bool EvaluateValue (lldb_private::Scalar &scalar, const Value *value, Module &module) + { + const Constant *constant = dyn_cast(value); + + if (constant) + { + if (const ConstantInt *constant_int = dyn_cast(constant)) + { + return AssignToMatchType(scalar, constant_int->getLimitedValue(), value->getType()); + } + } + else + { + Memory::Region region = ResolveValue(value, module); + DataExtractorSP value_extractor = m_memory.GetExtractor(region); + + if (!value_extractor) + return false; + + size_t value_size = m_target_data.getTypeStoreSize(value->getType()); + + uint32_t offset = 0; + uint64_t u64value = value_extractor->GetMaxU64(&offset, value_size); + + return AssignToMatchType(scalar, u64value, value->getType()); + } + + return false; + } + + bool AssignValue (const Value *value, lldb_private::Scalar &scalar, Module &module) + { + Memory::Region region = ResolveValue (value, module); + + lldb_private::Scalar cast_scalar; + + if (!AssignToMatchType(cast_scalar, scalar.GetRawBits64(0), value->getType())) + return false; + + lldb_private::DataBufferHeap buf(cast_scalar.GetByteSize(), 0); + + lldb_private::Error err; + + if (!cast_scalar.GetAsMemoryData(buf.GetBytes(), buf.GetByteSize(), m_byte_order, err)) + return false; + + DataEncoderSP region_encoder = m_memory.GetEncoder(region); + + memcpy(region_encoder->GetDataStart(), buf.GetBytes(), buf.GetByteSize()); + + return true; + } + + bool ResolveConstant (Memory::Region ®ion, const Constant *constant) + { + size_t constant_size = m_target_data.getTypeStoreSize(constant->getType()); + + if (const ConstantInt *constant_int = dyn_cast(constant)) + { + const uint64_t *raw_data = constant_int->getValue().getRawData(); + return m_memory.Write(region.m_base, (const uint8_t*)raw_data, constant_size); + } + if (const ConstantFP *constant_fp = dyn_cast(constant)) + { + const uint64_t *raw_data = constant_fp->getValueAPF().bitcastToAPInt().getRawData(); + return m_memory.Write(region.m_base, (const uint8_t*)raw_data, constant_size); + } + + return false; + } + + Memory::Region ResolveValue (const Value *value, Module &module) + { + ValueMap::iterator i = m_values.find(value); + + if (i != m_values.end()) + return i->second; + + const GlobalValue *global_value = dyn_cast(value); + + // Attempt to resolve the value using the program's data. + // If it is, the values to be created are: + // + // data_region - a region of memory in which the variable's data resides. + // ref_region - a region of memory in which its address (i.e., &var) resides. + // In the JIT case, this region would be a member of the struct passed in. + // pointer_region - a region of memory in which the address of the pointer + // resides. This is an IR-level variable. + do + { + if (!global_value) + break; + + lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS)); + + clang::NamedDecl *decl = IRForTarget::DeclForGlobal(global_value, &module); + + if (!decl) + break; + + lldb_private::Value resolved_value = m_decl_map.LookupDecl(decl); + + if (resolved_value.GetScalar().GetType() != lldb_private::Scalar::e_void) + { + if (resolved_value.GetContextType() == lldb_private::Value::eContextTypeRegisterInfo) + { + Memory::Region data_region = m_memory.Malloc(value->getType()); + data_region.m_allocation->m_origin = resolved_value; + Memory::Region ref_region = m_memory.Malloc(value->getType()); + Memory::Region pointer_region = m_memory.Malloc(value->getType()); + + if (!Cache(data_region.m_allocation, value->getType())) + return Memory::Region(); + + if (ref_region.IsInvalid()) + return Memory::Region(); + + if (pointer_region.IsInvalid()) + return Memory::Region(); + + DataEncoderSP ref_encoder = m_memory.GetEncoder(ref_region); + + if (ref_encoder->PutAddress(0, data_region.m_base) == UINT32_MAX) + return Memory::Region(); + + DataEncoderSP pointer_encoder = m_memory.GetEncoder(pointer_region); + + if (pointer_encoder->PutAddress(0, ref_region.m_base) == UINT32_MAX) + return Memory::Region(); + + m_values[value] = pointer_region; + return pointer_region; + } + else if (isa(decl)) + { + if (log) + log->Printf("The interpreter does not handle function pointers at the moment"); + + return Memory::Region(); + } + else + { + Memory::Region data_region = m_memory.Place(value->getType(), resolved_value.GetScalar().ULongLong(), resolved_value); + Memory::Region ref_region = m_memory.Malloc(value->getType()); + Memory::Region pointer_region = m_memory.Malloc(value->getType()); + + if (ref_region.IsInvalid()) + return Memory::Region(); + + if (pointer_region.IsInvalid()) + return Memory::Region(); + + DataEncoderSP ref_encoder = m_memory.GetEncoder(ref_region); + + if (ref_encoder->PutAddress(0, data_region.m_base) == UINT32_MAX) + return Memory::Region(); + + DataEncoderSP pointer_encoder = m_memory.GetEncoder(pointer_region); + + if (pointer_encoder->PutAddress(0, ref_region.m_base) == UINT32_MAX) + return Memory::Region(); + + m_values[value] = pointer_region; + + if (log) + { + log->Printf("Made an allocation for %s", PrintValue(global_value).c_str()); + log->Printf(" Data contents : %s", m_memory.PrintData(data_region.m_base, data_region.m_extent).c_str()); + log->Printf(" Data region : %llx", (unsigned long long)data_region.m_base); + log->Printf(" Ref region : %llx", (unsigned long long)ref_region.m_base); + log->Printf(" Pointer region : %llx", (unsigned long long)pointer_region.m_base); + } + + return pointer_region; + } + } + } + while(0); + + // Fall back and allocate space [allocation type Alloca] + + Type *type = value->getType(); + + lldb::ValueSP backing_value(new lldb_private::Value); + + Memory::Region data_region = m_memory.Malloc(type); + data_region.m_allocation->m_origin.GetScalar() = (unsigned long long)data_region.m_allocation->m_data->GetBytes(); + data_region.m_allocation->m_origin.SetContext(lldb_private::Value::eContextTypeInvalid, NULL); + data_region.m_allocation->m_origin.SetValueType(lldb_private::Value::eValueTypeHostAddress); + + const Constant *constant = dyn_cast(value); + + do + { + if (!constant) + break; + + if (!ResolveConstant (data_region, constant)) + return Memory::Region(); + } + while(0); + + m_values[value] = data_region; + return data_region; + } + + bool ConstructResult (lldb::ClangExpressionVariableSP &result, + const GlobalValue *result_value, + const lldb_private::ConstString &result_name, + lldb_private::TypeFromParser result_type, + Module &module) + { + // The result_value resolves to P, a pointer to a region R containing the result data. + // If the result variable is a reference, the region R contains a pointer to the result R_final in the original process. + + if (!result_value) + return true; // There was no slot for a result ??? the expression doesn't return one. + + ValueMap::iterator i = m_values.find(result_value); + + if (i == m_values.end()) + return false; // There was a slot for the result, but we didn't write into it. + + Memory::Region P = i->second; + DataExtractorSP P_extractor = m_memory.GetExtractor(P); + + if (!P_extractor) + return false; + + Type *pointer_ty = result_value->getType(); + PointerType *pointer_ptr_ty = dyn_cast(pointer_ty); + if (!pointer_ptr_ty) + return false; + Type *R_ty = pointer_ptr_ty->getElementType(); + + uint32_t offset = 0; + lldb::addr_t pointer = P_extractor->GetAddress(&offset); + + Memory::Region R = m_memory.Lookup(pointer, R_ty); + + if (R.m_allocation->m_origin.GetValueType() != lldb_private::Value::eValueTypeHostAddress || + !R.m_allocation->m_data) + return false; + + lldb_private::Value base; + + if (m_decl_map.ResultIsReference(result_name)) + { + PointerType *R_ptr_ty = dyn_cast(R_ty); + if (!R_ptr_ty) + return false; + Type *R_final_ty = R_ptr_ty->getElementType(); + + DataExtractorSP R_extractor = m_memory.GetExtractor(R); + + if (!R_extractor) + return false; + + offset = 0; + lldb::addr_t R_pointer = R_extractor->GetAddress(&offset); + + Memory::Region R_final = m_memory.Lookup(R_pointer, R_final_ty); + + if (!R_final.m_allocation) + return false; + + base = R_final.m_allocation->m_origin; + base.GetScalar() += (R_final.m_base - R_final.m_allocation->m_virtual_address); + } + else + { + base.SetContext(lldb_private::Value::eContextTypeInvalid, NULL); + base.SetValueType(lldb_private::Value::eValueTypeHostAddress); + base.GetScalar() = (unsigned long long)R.m_allocation->m_data->GetBytes() + (R.m_base - R.m_allocation->m_virtual_address); + } + + return m_decl_map.CompleteResultVariable (result, base, result_name, result_type); + } +}; + +bool +IRInterpreter::maybeRunOnFunction (lldb::ClangExpressionVariableSP &result, + const lldb_private::ConstString &result_name, + lldb_private::TypeFromParser result_type, + Function &llvm_function, + Module &llvm_module) +{ + if (supportsFunction (llvm_function)) + return runOnFunction(result, + result_name, + result_type, + llvm_function, + llvm_module); + else + return false; +} + +bool +IRInterpreter::supportsFunction (Function &llvm_function) +{ + lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS)); + + for (Function::iterator bbi = llvm_function.begin(), bbe = llvm_function.end(); + bbi != bbe; + ++bbi) + { + for (BasicBlock::iterator ii = bbi->begin(), ie = bbi->end(); + ii != ie; + ++ii) + { + switch (ii->getOpcode()) + { + default: + { + if (log) + log->Printf("Unsupported instruction: %s", PrintValue(ii).c_str()); + return false; + } + case Instruction::Add: + case Instruction::Alloca: + case Instruction::BitCast: + case Instruction::Br: + case Instruction::GetElementPtr: + break; + case Instruction::ICmp: + { + ICmpInst *icmp_inst = dyn_cast(ii); + + if (!icmp_inst) + return false; + + switch (icmp_inst->getPredicate()) + { + default: + { + if (log) + log->Printf("Unsupported ICmp predicate: %s", PrintValue(ii).c_str()); + return false; + } + case CmpInst::ICMP_EQ: + case CmpInst::ICMP_NE: + case CmpInst::ICMP_UGT: + case CmpInst::ICMP_UGE: + case CmpInst::ICMP_ULT: + case CmpInst::ICMP_ULE: + case CmpInst::ICMP_SGT: + case CmpInst::ICMP_SGE: + case CmpInst::ICMP_SLT: + case CmpInst::ICMP_SLE: + break; + } + } + break; + case Instruction::Load: + case Instruction::Mul: + case Instruction::Ret: + case Instruction::SDiv: + case Instruction::Store: + case Instruction::Sub: + case Instruction::UDiv: + break; + } + } + } + + return true; +} + +bool +IRInterpreter::runOnFunction (lldb::ClangExpressionVariableSP &result, + const lldb_private::ConstString &result_name, + lldb_private::TypeFromParser result_type, + Function &llvm_function, + Module &llvm_module) +{ + lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS)); + + lldb_private::ClangExpressionDeclMap::TargetInfo target_info = m_decl_map.GetTargetInfo(); + + if (!target_info.IsValid()) + return false; + + lldb::addr_t alloc_min; + lldb::addr_t alloc_max; + + switch (target_info.address_byte_size) + { + default: + return false; + case 4: + alloc_min = 0x00001000llu; + alloc_max = 0x0000ffffllu; + break; + case 8: + alloc_min = 0x0000000000001000llu; + alloc_max = 0x000000000000ffffllu; + break; + } + + TargetData target_data(&llvm_module); + if (target_data.getPointerSize() != target_info.address_byte_size) + return false; + if (target_data.isLittleEndian() != (target_info.byte_order == lldb::eByteOrderLittle)) + return false; + + Memory memory(target_data, m_decl_map, alloc_min, alloc_max); + InterpreterStackFrame frame(target_data, memory, m_decl_map); + + uint32_t num_insts = 0; + + frame.Jump(llvm_function.begin()); + + while (frame.m_ii != frame.m_ie && (++num_insts < 4096)) + { + const Instruction *inst = frame.m_ii; + + if (log) + log->Printf("Interpreting %s", PrintValue(inst).c_str()); + + switch (inst->getOpcode()) + { + default: + break; + case Instruction::Add: + case Instruction::Sub: + case Instruction::Mul: + case Instruction::SDiv: + case Instruction::UDiv: + { + const BinaryOperator *bin_op = dyn_cast(inst); + + if (!bin_op) + { + if (log) + log->Printf("getOpcode() returns %s, but instruction is not a BinaryOperator", inst->getOpcodeName()); + + return false; + } + + Value *lhs = inst->getOperand(0); + Value *rhs = inst->getOperand(1); + + lldb_private::Scalar L; + lldb_private::Scalar R; + + if (!frame.EvaluateValue(L, lhs, llvm_module)) + { + if (log) + log->Printf("Couldn't evaluate %s", PrintValue(lhs).c_str()); + + return false; + } + + if (!frame.EvaluateValue(R, rhs, llvm_module)) + { + if (log) + log->Printf("Couldn't evaluate %s", PrintValue(rhs).c_str()); + + return false; + } + + lldb_private::Scalar result; + + switch (inst->getOpcode()) + { + default: + break; + case Instruction::Add: + result = L + R; + break; + case Instruction::Mul: + result = L * R; + break; + case Instruction::Sub: + result = L - R; + break; + case Instruction::SDiv: + result = L / R; + break; + case Instruction::UDiv: + result = L.GetRawBits64(0) / R.GetRawBits64(1); + break; + } + + frame.AssignValue(inst, result, llvm_module); + + if (log) + { + log->Printf("Interpreted a %s", inst->getOpcodeName()); + log->Printf(" L : %s", frame.SummarizeValue(lhs).c_str()); + log->Printf(" R : %s", frame.SummarizeValue(rhs).c_str()); + log->Printf(" = : %s", frame.SummarizeValue(inst).c_str()); + } + } + break; + case Instruction::Alloca: + { + const AllocaInst *alloca_inst = dyn_cast(inst); + + if (!alloca_inst) + { + if (log) + log->Printf("getOpcode() returns Alloca, but instruction is not an AllocaInst"); + + return false; + } + + if (alloca_inst->isArrayAllocation()) + { + if (log) + log->Printf("AllocaInsts are not handled if isArrayAllocation() is true"); + + return false; + } + + // The semantics of Alloca are: + // Create a region R of virtual memory of type T, backed by a data buffer + // Create a region P of virtual memory of type T*, backed by a data buffer + // Write the virtual address of R into P + + Type *T = alloca_inst->getAllocatedType(); + Type *Tptr = alloca_inst->getType(); + + Memory::Region R = memory.Malloc(T); + + if (R.IsInvalid()) + { + if (log) + log->Printf("Couldn't allocate memory for an AllocaInst"); + + return false; + } + + Memory::Region P = memory.Malloc(Tptr); + + if (P.IsInvalid()) + { + if (log) + log->Printf("Couldn't allocate the result pointer for an AllocaInst"); + + return false; + } + + DataEncoderSP P_encoder = memory.GetEncoder(P); + + if (P_encoder->PutAddress(0, R.m_base) == UINT32_MAX) + { + if (log) + log->Printf("Couldn't write the reseult pointer for an AllocaInst"); + + return false; + } + + frame.m_values[alloca_inst] = P; + + if (log) + { + log->Printf("Interpreted an AllocaInst"); + log->Printf(" R : %s", memory.SummarizeRegion(R).c_str()); + log->Printf(" P : %s", frame.SummarizeValue(alloca_inst).c_str()); + } + } + break; + case Instruction::BitCast: + { + const BitCastInst *bit_cast_inst = dyn_cast(inst); + + if (!bit_cast_inst) + { + if (log) + log->Printf("getOpcode() returns BitCast, but instruction is not a BitCastInst"); + + return false; + } + + Value *source = bit_cast_inst->getOperand(0); + + lldb_private::Scalar S; + + if (!frame.EvaluateValue(S, source, llvm_module)) + { + if (log) + log->Printf("Couldn't evaluate %s", PrintValue(source).c_str()); + + return false; + } + + frame.AssignValue(inst, S, llvm_module); + } + break; + case Instruction::Br: + { + const BranchInst *br_inst = dyn_cast(inst); + + if (!br_inst) + { + if (log) + log->Printf("getOpcode() returns Br, but instruction is not a BranchInst"); + + return false; + } + + if (br_inst->isConditional()) + { + Value *condition = br_inst->getCondition(); + + lldb_private::Scalar C; + + if (!frame.EvaluateValue(C, condition, llvm_module)) + { + if (log) + log->Printf("Couldn't evaluate %s", PrintValue(condition).c_str()); + + return false; + } + + if (C.GetRawBits64(0)) + frame.Jump(br_inst->getSuccessor(0)); + else + frame.Jump(br_inst->getSuccessor(1)); + + if (log) + { + log->Printf("Interpreted a BrInst with a condition"); + log->Printf(" cond : %s", frame.SummarizeValue(condition).c_str()); + } + } + else + { + frame.Jump(br_inst->getSuccessor(0)); + + if (log) + { + log->Printf("Interpreted a BrInst with no condition"); + } + } + } + continue; + case Instruction::GetElementPtr: + { + const GetElementPtrInst *gep_inst = dyn_cast(inst); + + if (!gep_inst) + { + if (log) + log->Printf("getOpcode() returns GetElementPtr, but instruction is not a GetElementPtrInst"); + + return false; + } + + const Value *pointer_operand = gep_inst->getPointerOperand(); + Type *pointer_type = pointer_operand->getType(); + + lldb_private::Scalar P; + + if (!frame.EvaluateValue(P, pointer_operand, llvm_module)) + return false; + + SmallVector indices (gep_inst->idx_begin(), + gep_inst->idx_end()); + + uint64_t offset = target_data.getIndexedOffset(pointer_type, indices); + + lldb_private::Scalar Poffset = P + offset; + + frame.AssignValue(inst, Poffset, llvm_module); + + if (log) + { + log->Printf("Interpreted a GetElementPtrInst"); + log->Printf(" P : %s", frame.SummarizeValue(pointer_operand).c_str()); + log->Printf(" Poffset : %s", frame.SummarizeValue(inst).c_str()); + } + } + break; + case Instruction::ICmp: + { + const ICmpInst *icmp_inst = dyn_cast(inst); + + if (!icmp_inst) + { + if (log) + log->Printf("getOpcode() returns ICmp, but instruction is not an ICmpInst"); + + return false; + } + + CmpInst::Predicate predicate = icmp_inst->getPredicate(); + + Value *lhs = inst->getOperand(0); + Value *rhs = inst->getOperand(1); + + lldb_private::Scalar L; + lldb_private::Scalar R; + + if (!frame.EvaluateValue(L, lhs, llvm_module)) + { + if (log) + log->Printf("Couldn't evaluate %s", PrintValue(lhs).c_str()); + + return false; + } + + if (!frame.EvaluateValue(R, rhs, llvm_module)) + { + if (log) + log->Printf("Couldn't evaluate %s", PrintValue(rhs).c_str()); + + return false; + } + + lldb_private::Scalar result; + + switch (predicate) + { + default: + return false; + case CmpInst::ICMP_EQ: + result = (L == R); + break; + case CmpInst::ICMP_NE: + result = (L != R); + break; + case CmpInst::ICMP_UGT: + result = (L.GetRawBits64(0) > R.GetRawBits64(0)); + break; + case CmpInst::ICMP_UGE: + result = (L.GetRawBits64(0) >= R.GetRawBits64(0)); + break; + case CmpInst::ICMP_ULT: + result = (L.GetRawBits64(0) < R.GetRawBits64(0)); + break; + case CmpInst::ICMP_ULE: + result = (L.GetRawBits64(0) <= R.GetRawBits64(0)); + break; + case CmpInst::ICMP_SGT: + result = (L > R); + break; + case CmpInst::ICMP_SGE: + result = (L >= R); + break; + case CmpInst::ICMP_SLT: + result = (L < R); + break; + case CmpInst::ICMP_SLE: + result = (L <= R); + break; + } + + frame.AssignValue(inst, result, llvm_module); + + if (log) + { + log->Printf("Interpreted an ICmpInst"); + log->Printf(" L : %s", frame.SummarizeValue(lhs).c_str()); + log->Printf(" R : %s", frame.SummarizeValue(rhs).c_str()); + log->Printf(" = : %s", frame.SummarizeValue(inst).c_str()); + } + } + break; + case Instruction::Load: + { + const LoadInst *load_inst = dyn_cast(inst); + + if (!load_inst) + { + if (log) + log->Printf("getOpcode() returns Load, but instruction is not a LoadInst"); + + return false; + } + + // The semantics of Load are: + // Create a region D that will contain the loaded data + // Resolve the region P containing a pointer + // Dereference P to get the region R that the data should be loaded from + // Transfer a unit of type type(D) from R to D + + const Value *pointer_operand = load_inst->getPointerOperand(); + + Type *pointer_ty = pointer_operand->getType(); + PointerType *pointer_ptr_ty = dyn_cast(pointer_ty); + if (!pointer_ptr_ty) + return false; + Type *target_ty = pointer_ptr_ty->getElementType(); + + Memory::Region D = frame.ResolveValue(load_inst, llvm_module); + Memory::Region P = frame.ResolveValue(pointer_operand, llvm_module); + + if (D.IsInvalid()) + { + if (log) + log->Printf("LoadInst's value doesn't resolve to anything"); + + return false; + } + + if (P.IsInvalid()) + { + if (log) + log->Printf("LoadInst's pointer doesn't resolve to anything"); + + return false; + } + + DataExtractorSP P_extractor(memory.GetExtractor(P)); + DataEncoderSP D_encoder(memory.GetEncoder(D)); + + uint32_t offset = 0; + lldb::addr_t pointer = P_extractor->GetAddress(&offset); + + Memory::Region R = memory.Lookup(pointer, target_ty); + + memory.Read(D_encoder->GetDataStart(), R.m_base, target_data.getTypeStoreSize(target_ty)); + + if (log) + { + log->Printf("Interpreted a LoadInst"); + log->Printf(" P : %s", frame.SummarizeValue(pointer_operand).c_str()); + log->Printf(" R : %s", memory.SummarizeRegion(R).c_str()); + log->Printf(" D : %s", frame.SummarizeValue(load_inst).c_str()); + } + } + break; + case Instruction::Ret: + { + if (result_name.IsEmpty()) + return true; + + GlobalValue *result_value = llvm_module.getNamedValue(result_name.GetCString()); + return frame.ConstructResult(result, result_value, result_name, result_type, llvm_module); + } + case Instruction::Store: + { + const StoreInst *store_inst = dyn_cast(inst); + + if (!store_inst) + { + if (log) + log->Printf("getOpcode() returns Store, but instruction is not a StoreInst"); + + return false; + } + + // The semantics of Store are: + // Resolve the region D containing the data to be stored + // Resolve the region P containing a pointer + // Dereference P to get the region R that the data should be stored in + // Transfer a unit of type type(D) from D to R + + const Value *value_operand = store_inst->getValueOperand(); + const Value *pointer_operand = store_inst->getPointerOperand(); + + Type *pointer_ty = pointer_operand->getType(); + PointerType *pointer_ptr_ty = dyn_cast(pointer_ty); + if (!pointer_ptr_ty) + return false; + Type *target_ty = pointer_ptr_ty->getElementType(); + + Memory::Region D = frame.ResolveValue(value_operand, llvm_module); + Memory::Region P = frame.ResolveValue(pointer_operand, llvm_module); + + if (D.IsInvalid()) + { + if (log) + log->Printf("StoreInst's value doesn't resolve to anything"); + + return false; + } + + if (P.IsInvalid()) + { + if (log) + log->Printf("StoreInst's pointer doesn't resolve to anything"); + + return false; + } + + DataExtractorSP P_extractor(memory.GetExtractor(P)); + DataExtractorSP D_extractor(memory.GetExtractor(D)); + + if (!P_extractor || !D_extractor) + return false; + + uint32_t offset = 0; + lldb::addr_t pointer = P_extractor->GetAddress(&offset); + + Memory::Region R = memory.Lookup(pointer, target_ty); + + if (R.IsInvalid()) + { + if (log) + log->Printf("StoreInst's pointer doesn't point to a valid target"); + + return false; + } + + memory.Write(R.m_base, D_extractor->GetDataStart(), target_data.getTypeStoreSize(target_ty)); + + if (log) + { + log->Printf("Interpreted a StoreInst"); + log->Printf(" D : %s", frame.SummarizeValue(value_operand).c_str()); + log->Printf(" P : %s", frame.SummarizeValue(pointer_operand).c_str()); + log->Printf(" R : %s", memory.SummarizeRegion(R).c_str()); + } + } + break; + } + + ++frame.m_ii; + } + + if (num_insts >= 4096) + return false; + + return false; +} \ No newline at end of file Removed: lldb/trunk/source/Expression/IRToDWARF.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/IRToDWARF.cpp?rev=139771&view=auto ============================================================================== --- lldb/trunk/source/Expression/IRToDWARF.cpp (original) +++ lldb/trunk/source/Expression/IRToDWARF.cpp (removed) @@ -1,219 +0,0 @@ -//===-- 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; - -static char ID; - -IRToDWARF::IRToDWARF(lldb_private::ClangExpressionVariableList &local_vars, - lldb_private::ClangExpressionDeclMap *decl_map, - lldb_private::StreamString &strm, - const char *func_name) : - ModulePass(ID), - m_func_name(func_name), - m_local_vars(local_vars), - 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 << relative; - - // 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(); - 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) -{ - /////////////////////////////////////// - // 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 - // - - ///////////////////////////////////////////////// - // 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::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS)); - - llvm::Function* function = M.getFunction(StringRef(m_func_name.c_str())); - - if (!function) - { - if (log) - log->Printf("Couldn't find %s() in the module", m_func_name.c_str()); - - return false; - } - - Relocator relocator; - - if (!runOnBasicBlock(function->getEntryBlock(), relocator)) - return false; - - if (log && log->GetVerbose()) - { - std::string s; - raw_string_ostream oss(s); - - M.print(oss, NULL); - - oss.flush(); - - log->Printf ("Module being translated to DWARF: \n%s", s.c_str()); - } - - // TEMPORARY: Fail in order to force execution in the target. - return false; - - return relocator.ResolveRelocations(m_strm); -} - -void -IRToDWARF::assignPassManager(PMStack &PMS, - PassManagerType T) -{ -} - -PassManagerType -IRToDWARF::getPotentialPassManagerType() const -{ - return PMT_ModulePassManager; -} Modified: lldb/trunk/source/Symbol/ClangASTImporter.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/ClangASTImporter.cpp?rev=139772&r1=139771&r2=139772&view=diff ============================================================================== --- lldb/trunk/source/Symbol/ClangASTImporter.cpp (original) +++ lldb/trunk/source/Symbol/ClangASTImporter.cpp Wed Sep 14 21:13:07 2011 @@ -117,7 +117,8 @@ { ObjCInterfaceDecl *to_interface_decl = dyn_cast(to); - to_interface_decl->setExternallyCompleted(); + if (!to_interface_decl->isForwardDecl()) + to_interface_decl->setExternallyCompleted(); } return clang::ASTImporter::Imported(from, to); Modified: lldb/trunk/source/Target/Process.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Process.cpp?rev=139772&r1=139771&r2=139772&view=diff ============================================================================== --- lldb/trunk/source/Target/Process.cpp (original) +++ lldb/trunk/source/Target/Process.cpp Wed Sep 14 21:13:07 2011 @@ -1154,7 +1154,7 @@ expr.Printf("dlopen (\"%s\", 2)", path); const char *prefix = "extern \"C\" void* dlopen (const char *path, int mode);\n"; lldb::ValueObjectSP result_valobj_sp; - ClangUserExpression::Evaluate (exe_ctx, unwind_on_error, expr.GetData(), prefix, result_valobj_sp); + ClangUserExpression::Evaluate (exe_ctx, eExecutionPolicyAlways, unwind_on_error, expr.GetData(), prefix, result_valobj_sp); error = result_valobj_sp->GetError(); if (error.Success()) { @@ -1218,7 +1218,7 @@ expr.Printf("dlclose ((void *)0x%llx)", image_addr); const char *prefix = "extern \"C\" int dlclose(void* handle);\n"; lldb::ValueObjectSP result_valobj_sp; - ClangUserExpression::Evaluate (exe_ctx, unwind_on_error, expr.GetData(), prefix, result_valobj_sp); + ClangUserExpression::Evaluate (exe_ctx, eExecutionPolicyAlways, unwind_on_error, expr.GetData(), prefix, result_valobj_sp); if (result_valobj_sp->GetError().Success()) { Scalar scalar; Modified: lldb/trunk/source/Target/StopInfo.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/StopInfo.cpp?rev=139772&r1=139771&r2=139772&view=diff ============================================================================== --- lldb/trunk/source/Target/StopInfo.cpp (original) +++ lldb/trunk/source/Target/StopInfo.cpp Wed Sep 14 21:13:07 2011 @@ -194,11 +194,12 @@ const bool discard_on_error = true; Error error; result_code = ClangUserExpression::EvaluateWithError (context.exe_ctx, - discard_on_error, - bp_loc_sp->GetConditionText(), - NULL, - result_value_sp, - error); + eExecutionPolicyAlways, + discard_on_error, + bp_loc_sp->GetConditionText(), + NULL, + result_value_sp, + error); if (result_code == eExecutionCompleted) { if (result_value_sp) Modified: lldb/trunk/source/Target/Target.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Target.cpp?rev=139772&r1=139771&r2=139772&view=diff ============================================================================== --- lldb/trunk/source/Target/Target.cpp (original) +++ lldb/trunk/source/Target/Target.cpp Wed Sep 14 21:13:07 2011 @@ -1133,6 +1133,7 @@ ( const char *expr_cstr, StackFrame *frame, + lldb_private::ExecutionPolicy execution_policy, bool unwind_on_error, bool keep_in_memory, lldb::DynamicValueType use_dynamic, @@ -1242,8 +1243,9 @@ else { const char *prefix = GetExpressionPrefixContentsAsCString(); - + execution_results = ClangUserExpression::Evaluate (exe_ctx, + execution_policy, unwind_on_error, expr_cstr, prefix, From johnny.chen at apple.com Thu Sep 15 12:17:51 2011 From: johnny.chen at apple.com (Johnny Chen) Date: Thu, 15 Sep 2011 17:17:51 -0000 Subject: [Lldb-commits] [lldb] r139800 - /lldb/trunk/tools/debugserver/source/MacOSX/MachThread.cpp Message-ID: <20110915171751.DD18F2A6C12C@llvm.org> Author: johnny Date: Thu Sep 15 12:17:51 2011 New Revision: 139800 URL: http://llvm.org/viewvc/llvm-project?rev=139800&view=rev Log: Add comment regarding method call to DNBArchProtocol::NotifyException(). Modified: lldb/trunk/tools/debugserver/source/MacOSX/MachThread.cpp Modified: lldb/trunk/tools/debugserver/source/MacOSX/MachThread.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/MacOSX/MachThread.cpp?rev=139800&r1=139799&r2=139800&view=diff ============================================================================== --- lldb/trunk/tools/debugserver/source/MacOSX/MachThread.cpp (original) +++ lldb/trunk/tools/debugserver/source/MacOSX/MachThread.cpp Thu Sep 15 12:17:51 2011 @@ -549,6 +549,7 @@ { // Allow the arch specific protocol to process (MachException::Data &)exc // first before possible reassignment of m_stop_exception with exc. + // See also MachThread::GetStopException(). bool handled = m_arch_ap->NotifyException(exc); if (m_stop_exception.IsValid()) From johnny.chen at apple.com Thu Sep 15 12:36:17 2011 From: johnny.chen at apple.com (Johnny Chen) Date: Thu, 15 Sep 2011 17:36:17 -0000 Subject: [Lldb-commits] [lldb] r139802 - /lldb/trunk/test/lang/c/global_variables/main.c Message-ID: <20110915173617.949892A6C12C@llvm.org> Author: johnny Date: Thu Sep 15 12:36:17 2011 New Revision: 139802 URL: http://llvm.org/viewvc/llvm-project?rev=139802&view=rev Log: Fixed indentation. Modified: lldb/trunk/test/lang/c/global_variables/main.c Modified: lldb/trunk/test/lang/c/global_variables/main.c URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/lang/c/global_variables/main.c?rev=139802&r1=139801&r2=139802&view=diff ============================================================================== --- lldb/trunk/test/lang/c/global_variables/main.c (original) +++ lldb/trunk/test/lang/c/global_variables/main.c Thu Sep 15 12:36:17 2011 @@ -15,7 +15,7 @@ extern int g_a; int main (int argc, char const *argv[]) { - static const char *g_func_static_cstr = "g_func_static_cstr"; - printf ("%s %s\n", g_file_global_cstr, g_file_static_cstr); + static const char *g_func_static_cstr = "g_func_static_cstr"; + printf ("%s %s\n", g_file_global_cstr, g_file_static_cstr); return g_file_global_int + g_a; // Set break point at this line. //// break $source:$line; continue; var -global g_a -global g_global_int } From scallanan at apple.com Thu Sep 15 12:43:01 2011 From: scallanan at apple.com (Sean Callanan) Date: Thu, 15 Sep 2011 17:43:01 -0000 Subject: [Lldb-commits] [lldb] r139803 - /lldb/trunk/source/Expression/ClangUserExpression.cpp Message-ID: <20110915174301.288B62A6C12C@llvm.org> Author: spyffe Date: Thu Sep 15 12:43:00 2011 New Revision: 139803 URL: http://llvm.org/viewvc/llvm-project?rev=139803&view=rev Log: Fixed a problem where the expression parser would attempt to obtain information from the process even in cases where the process isn't available. Modified: lldb/trunk/source/Expression/ClangUserExpression.cpp Modified: lldb/trunk/source/Expression/ClangUserExpression.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/ClangUserExpression.cpp?rev=139803&r1=139802&r2=139803&view=diff ============================================================================== --- lldb/trunk/source/Expression/ClangUserExpression.cpp (original) +++ lldb/trunk/source/Expression/ClangUserExpression.cpp Thu Sep 15 12:43:00 2011 @@ -614,6 +614,9 @@ return execution_results; } } + + if (exe_ctx.process == NULL) + execution_policy = eExecutionPolicyNever; if (execution_policy != eExecutionPolicyNever && !exe_ctx.process->GetDynamicCheckers()) { From scallanan at apple.com Thu Sep 15 13:41:04 2011 From: scallanan at apple.com (Sean Callanan) Date: Thu, 15 Sep 2011 18:41:04 -0000 Subject: [Lldb-commits] [lldb] r139823 - /lldb/trunk/source/Expression/ClangExpressionDeclMap.cpp Message-ID: <20110915184104.C1FEB2A6C12C@llvm.org> Author: spyffe Date: Thu Sep 15 13:41:04 2011 New Revision: 139823 URL: http://llvm.org/viewvc/llvm-project?rev=139823&view=rev Log: Fixed a problem where the symbol context was not being initialized properly in the absence of a process. Modified: lldb/trunk/source/Expression/ClangExpressionDeclMap.cpp Modified: lldb/trunk/source/Expression/ClangExpressionDeclMap.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/ClangExpressionDeclMap.cpp?rev=139823&r1=139822&r2=139823&view=diff ============================================================================== --- lldb/trunk/source/Expression/ClangExpressionDeclMap.cpp (original) +++ lldb/trunk/source/Expression/ClangExpressionDeclMap.cpp Thu Sep 15 13:41:04 2011 @@ -76,6 +76,9 @@ m_parser_vars->m_sym_ctx = exe_ctx.thread->GetStackFrameAtIndex(0)->GetSymbolContext(lldb::eSymbolContextEverything); else if (exe_ctx.process) m_parser_vars->m_sym_ctx = SymbolContext(exe_ctx.target->GetSP(), ModuleSP()); + else if (exe_ctx.target) + m_parser_vars->m_sym_ctx = SymbolContext(exe_ctx.target->GetSP(), ModuleSP()); + if (exe_ctx.target) m_parser_vars->m_persistent_vars = &exe_ctx.target->GetPersistentVariables(); From johnny.chen at apple.com Thu Sep 15 15:54:25 2011 From: johnny.chen at apple.com (Johnny Chen) Date: Thu, 15 Sep 2011 20:54:25 -0000 Subject: [Lldb-commits] [lldb] r139840 - in /lldb/trunk: include/lldb/Breakpoint/WatchpointLocationList.h source/Breakpoint/WatchpointLocationList.cpp source/Target/Target.cpp Message-ID: <20110915205425.90C0F2A6C12C@llvm.org> Author: johnny Date: Thu Sep 15 15:54:25 2011 New Revision: 139840 URL: http://llvm.org/viewvc/llvm-project?rev=139840&view=rev Log: Add cleanup of watchpoint locations during Target::DeleteCurrentProcess(). Modified: lldb/trunk/include/lldb/Breakpoint/WatchpointLocationList.h lldb/trunk/source/Breakpoint/WatchpointLocationList.cpp lldb/trunk/source/Target/Target.cpp Modified: lldb/trunk/include/lldb/Breakpoint/WatchpointLocationList.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Breakpoint/WatchpointLocationList.h?rev=139840&r1=139839&r2=139840&view=diff ============================================================================== --- lldb/trunk/include/lldb/Breakpoint/WatchpointLocationList.h (original) +++ lldb/trunk/include/lldb/Breakpoint/WatchpointLocationList.h Thu Sep 15 15:54:25 2011 @@ -174,6 +174,9 @@ GetDescription (Stream *s, lldb::DescriptionLevel level); + void + ClearAllWatchpointLocations (); + //------------------------------------------------------------------ /// Sets the passed in Locker to hold the Watchpoint Location List mutex. /// Modified: lldb/trunk/source/Breakpoint/WatchpointLocationList.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Breakpoint/WatchpointLocationList.cpp?rev=139840&r1=139839&r2=139840&view=diff ============================================================================== --- lldb/trunk/source/Breakpoint/WatchpointLocationList.cpp (original) +++ lldb/trunk/source/Breakpoint/WatchpointLocationList.cpp Thu Sep 15 15:54:25 2011 @@ -189,6 +189,16 @@ } void +WatchpointLocationList::ClearAllWatchpointLocations () +{ + Mutex::Locker locker(m_mutex); + addr_map::iterator pos, end = m_address_to_location.end(); + + for (pos = m_address_to_location.begin(); pos != end; ++pos) + m_address_to_location.erase(pos); +} + +void WatchpointLocationList::GetListMutex (Mutex::Locker &locker) { return locker.Reset (m_mutex.GetMutex()); Modified: lldb/trunk/source/Target/Target.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Target.cpp?rev=139840&r1=139839&r2=139840&view=diff ============================================================================== --- lldb/trunk/source/Target/Target.cpp (original) +++ lldb/trunk/source/Target/Target.cpp Thu Sep 15 15:54:25 2011 @@ -124,6 +124,7 @@ // clean up needs some help from the process. m_breakpoint_list.ClearAllBreakpointSites(); m_internal_breakpoint_list.ClearAllBreakpointSites(); + m_watchpoint_location_list.ClearAllWatchpointLocations(); m_process_sp.reset(); } } From johnny.chen at apple.com Thu Sep 15 16:09:59 2011 From: johnny.chen at apple.com (Johnny Chen) Date: Thu, 15 Sep 2011 21:09:59 -0000 Subject: [Lldb-commits] [lldb] r139847 - in /lldb/trunk/test: functionalities/watchpoint/ functionalities/watchpoint/hello_watchpoint/ functionalities/watchpoint/hello_watchpoint/Makefile functionalities/watchpoint/hello_watchpoint/TestMyFirstWatchpoint.py functionalities/watchpoint/hello_watchpoint/main.c lldbtest.py Message-ID: <20110915210959.B557F2A6C12C@llvm.org> Author: johnny Date: Thu Sep 15 16:09:59 2011 New Revision: 139847 URL: http://llvm.org/viewvc/llvm-project?rev=139847&view=rev Log: Add a simple watchpoint test to exercise watchpoint creation followed by watchpoint hit events. Added: lldb/trunk/test/functionalities/watchpoint/ lldb/trunk/test/functionalities/watchpoint/hello_watchpoint/ lldb/trunk/test/functionalities/watchpoint/hello_watchpoint/Makefile lldb/trunk/test/functionalities/watchpoint/hello_watchpoint/TestMyFirstWatchpoint.py lldb/trunk/test/functionalities/watchpoint/hello_watchpoint/main.c Modified: lldb/trunk/test/lldbtest.py Added: lldb/trunk/test/functionalities/watchpoint/hello_watchpoint/Makefile URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/watchpoint/hello_watchpoint/Makefile?rev=139847&view=auto ============================================================================== --- lldb/trunk/test/functionalities/watchpoint/hello_watchpoint/Makefile (added) +++ lldb/trunk/test/functionalities/watchpoint/hello_watchpoint/Makefile Thu Sep 15 16:09:59 2011 @@ -0,0 +1,5 @@ +LEVEL = ../../../make + +C_SOURCES := main.c + +include $(LEVEL)/Makefile.rules Added: lldb/trunk/test/functionalities/watchpoint/hello_watchpoint/TestMyFirstWatchpoint.py URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/watchpoint/hello_watchpoint/TestMyFirstWatchpoint.py?rev=139847&view=auto ============================================================================== --- lldb/trunk/test/functionalities/watchpoint/hello_watchpoint/TestMyFirstWatchpoint.py (added) +++ lldb/trunk/test/functionalities/watchpoint/hello_watchpoint/TestMyFirstWatchpoint.py Thu Sep 15 16:09:59 2011 @@ -0,0 +1,81 @@ +""" +Test my first lldb watchpoint. +""" + +import os, time +import unittest2 +import lldb +from lldbtest import * + +class HelloWatchpointTestCase(TestBase): + + mydir = os.path.join("functionalities", "watchpoint", "hello_watchpoint") + + @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin") + def test_hello_watchpoint_with_dsym(self): + """Test a simple sequence of watchpoint creation and watchpoint hit.""" + self.buildDsym(dictionary=self.d) + self.setTearDownCleanup(dictionary=self.d) + self.hello_watchpoint() + + def test_hello_watchpoint_with_dwarf(self): + """Test a simple sequence of watchpoint creation and watchpoint hit.""" + self.buildDwarf(dictionary=self.d) + self.setTearDownCleanup(dictionary=self.d) + self.hello_watchpoint() + + def setUp(self): + # Call super's setUp(). + TestBase.setUp(self) + # Our simple source filename. + self.source = 'main.c' + # Find the line number to break inside main(). + self.line = line_number(self.source, '// Set break point at this line.') + # Build dictionary to have unique executable names for each test method. + self.exe_name = self.testMethodName + self.d = {'C_SOURCES': self.source, 'EXE': self.exe_name} + + def hello_watchpoint(self): + """Test a simple sequence of watchpoint creation and watchpoint hit.""" + exe = os.path.join(os.getcwd(), self.exe_name) + self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) + + # Add a breakpoint to set a watchpoint when stopped on the breakpoint. + self.expect("breakpoint set -l %d" % self.line, BREAKPOINT_CREATED, + startstr = "Breakpoint created: 1: file ='%s', line = %d, locations = 1" % + (self.source, self.line)) + + # Run the program. + self.runCmd("run", RUN_SUCCEEDED) + + # We should be stopped again due to the breakpoint. + # The stop reason of the thread should be breakpoint. + self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, + substrs = ['stopped', + 'stop reason = breakpoint']) + + # Now let's set a write-type watchpoint for 'global'. + # There should be only one watchpoint hit (see main.c). + self.expect("frame variable -w write -g -L global", WATCHPOINT_CREATED, + substrs = ['Watchpoint created', 'size = 4', 'type = w']) + + self.runCmd("process continue") + + # We should be stopped again due to the watchpoint (write type), but + # only once. The stop reason of the thread should be watchpoint. + self.expect("thread list", STOPPED_DUE_TO_WATCHPOINT, + substrs = ['stopped', + 'stop reason = watchpoint']) + + self.runCmd("process continue") + # Don't expect the read of 'global' to trigger a stop exception. + # The process status should be 'exited'. + self.expect("process status", + substrs = ['exited']) + + +if __name__ == '__main__': + import atexit + lldb.SBDebugger.Initialize() + atexit.register(lambda: lldb.SBDebugger.Terminate()) + unittest2.main() Added: lldb/trunk/test/functionalities/watchpoint/hello_watchpoint/main.c URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/watchpoint/hello_watchpoint/main.c?rev=139847&view=auto ============================================================================== --- lldb/trunk/test/functionalities/watchpoint/hello_watchpoint/main.c (added) +++ lldb/trunk/test/functionalities/watchpoint/hello_watchpoint/main.c Thu Sep 15 16:09:59 2011 @@ -0,0 +1,24 @@ +//===-- main.c --------------------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +#include +#include + +int32_t global = 10; + +int main(int argc, char** argv) { + int local = 0; + printf("&global=%p\n", &global); + printf("about to write to 'global'...\n"); // Set break point at this line. + // When stopped, watch 'global' for write. + global = 20; + local += argc; + ++local; + printf("local: %d\n", local); + printf("global=%d\n", global); +} Modified: lldb/trunk/test/lldbtest.py URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/lldbtest.py?rev=139847&r1=139846&r2=139847&view=diff ============================================================================== --- lldb/trunk/test/lldbtest.py (original) +++ lldb/trunk/test/lldbtest.py Thu Sep 15 16:09:59 2011 @@ -176,6 +176,8 @@ STOPPED_DUE_TO_STEP_IN = "Process state is stopped due to step in" +STOPPED_DUE_TO_WATCHPOINT = "Process should be stopped due to watchpoint" + DATA_TYPES_DISPLAYED_CORRECTLY = "Data type(s) displayed correctly" VALID_BREAKPOINT = "Got a valid breakpoint" @@ -198,6 +200,7 @@ VARIABLES_DISPLAYED_CORRECTLY = "Variable(s) displayed correctly" +WATCHPOINT_CREATED = "Watchpoint created successfully" def CMD_MSG(str): '''A generic "Command '%s' returns successfully" message generator.''' From jingham at apple.com Thu Sep 15 16:30:02 2011 From: jingham at apple.com (Jim Ingham) Date: Thu, 15 Sep 2011 21:30:02 -0000 Subject: [Lldb-commits] [lldb] r139852 - in /lldb/trunk: include/lldb/Core/Debugger.h include/lldb/Target/Process.h tools/driver/Driver.cpp Message-ID: <20110915213002.527952A6C12C@llvm.org> Author: jingham Date: Thu Sep 15 16:30:02 2011 New Revision: 139852 URL: http://llvm.org/viewvc/llvm-project?rev=139852&view=rev Log: Track whether a process was Launched or Attached to. If Attached, the detach when the debugger is destroyed, rather than killing the process. Also added a Debugger::Clear, which gets called in Debugger::Destroy to deal with all the targets in the Debugger. Also made the Driver's main loop call Destroy on the debugger, rather than just Destroying the currently selected Target's process. Modified: lldb/trunk/include/lldb/Core/Debugger.h lldb/trunk/include/lldb/Target/Process.h lldb/trunk/tools/driver/Driver.cpp Modified: lldb/trunk/include/lldb/Core/Debugger.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/Debugger.h?rev=139852&r1=139851&r2=139852&view=diff ============================================================================== --- lldb/trunk/include/lldb/Core/Debugger.h (original) +++ lldb/trunk/include/lldb/Core/Debugger.h Thu Sep 15 16:30:02 2011 @@ -276,6 +276,8 @@ Destroy (lldb::DebuggerSP &debugger_sp); ~Debugger (); + + void Clear(); lldb::DebuggerSP GetSP (); Modified: lldb/trunk/include/lldb/Target/Process.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/Process.h?rev=139852&r1=139851&r2=139852&view=diff ============================================================================== --- lldb/trunk/include/lldb/Target/Process.h (original) +++ lldb/trunk/include/lldb/Target/Process.h Thu Sep 15 16:30:02 2011 @@ -1364,59 +1364,14 @@ virtual Error ConnectRemote (const char *remote_url); - //------------------------------------------------------------------ - /// List the processes matching the given partial name. - /// - /// FIXME: Is it too heavyweight to create an entire process object to do this? - /// The problem is for remote processes we're going to have to set up the same transport - /// to get this data as to actually attach. So we need to factor out transport - /// and process before we can do this separately from the process. - /// - /// @param[in] name - /// A partial name to match against the current process list. - /// - /// @param[out] matches - /// The list of process names matching \a name. - /// - /// @param[in] pids - /// A vector filled with the pids that correspond to the names in \a matches. - /// - /// @return - /// Returns the number of matching processes. - //------------------------------------------------------------------ -// virtual uint32_t -// ListProcessesMatchingName (const char *name, StringList &matches, std::vector &pids); - - //------------------------------------------------------------------ - /// Find the architecture of a process by pid. - /// - /// FIXME: See comment for ListProcessesMatchingName. - /// - /// @param[in] pid - /// A pid to inspect. - /// - /// @return - /// Returns the architecture of the process or an invalid architecture if the process can't be found. - //------------------------------------------------------------------ -// virtual ArchSpec -// GetArchSpecForExistingProcess (lldb::pid_t pid); + bool + AttachedToProcess() const + { + return m_attached_to_process; + } //------------------------------------------------------------------ - /// Find the architecture of a process by name. - /// - /// FIXME: See comment for ListProcessesMatchingName. - /// - /// @param[in] process_name - /// The process name to inspect. - /// - /// @return - /// Returns the architecture of the process or an invalid architecture if the process can't be found. - //------------------------------------------------------------------ -// virtual ArchSpec -// GetArchSpecForExistingProcess (const char *process_name); - - //------------------------------------------------------------------ /// Get the image information address for the current process. /// /// Some runtimes have system functions that can help dynamic @@ -2810,6 +2765,7 @@ std::string m_stdout_data; MemoryCache m_memory_cache; AllocatedMemoryCache m_allocated_memory_cache; + bool m_attached_to_process; /// Did we launch the process or attach to it? typedef std::map LanguageRuntimeCollection; LanguageRuntimeCollection m_language_runtimes; Modified: lldb/trunk/tools/driver/Driver.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/driver/Driver.cpp?rev=139852&r1=139851&r2=139852&view=diff ============================================================================== --- lldb/trunk/tools/driver/Driver.cpp (original) +++ lldb/trunk/tools/driver/Driver.cpp Thu Sep 15 16:30:02 2011 @@ -69,18 +69,33 @@ static OptionDefinition g_options[] = { - { LLDB_OPT_SET_1, true , "help" , 'h', no_argument , NULL, eArgTypeNone, "Prints out the usage information for the LLDB debugger." }, - { LLDB_OPT_SET_2, true , "version" , 'v', no_argument , NULL, eArgTypeNone, "Prints out the current version number of the LLDB debugger." }, - { LLDB_OPT_SET_3, true , "arch" , 'a', required_argument, NULL, eArgTypeArchitecture, "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, true , "file" , 'f', required_argument, NULL, eArgTypeFilename, "Tells the debugger to use the file as the program to be debugged." }, - { LLDB_OPT_SET_4, true , "attach-name" , 'n', required_argument, NULL, eArgTypeProcessName, "Tells the debugger to attach to a process with the given name." }, - { LLDB_OPT_SET_4, true , "wait-for" , 'w', no_argument , NULL, eArgTypeNone, "Tells the debugger to wait for a process with the given pid or name to launch before attaching." }, - { LLDB_OPT_SET_5, true , "attach-pid" , 'p', required_argument, NULL, eArgTypePid, "Tells the debugger to attach to a process with the given pid." }, - { LLDB_3_TO_5, false, "script-language", 'l', required_argument, NULL, eArgTypeScriptLang, "Tells the debugger to use the specified scripting language for user-defined scripts, rather than the default. Valid scripting languages that can be specified include Python, Perl, Ruby and Tcl. Currently only the Python extensions have been implemented." }, - { LLDB_3_TO_5, false, "debug" , 'd', no_argument , NULL, eArgTypeNone, "Tells the debugger to print out extra information for debugging itself." }, - { LLDB_3_TO_5, false, "source" , 's', required_argument, NULL, eArgTypeFilename, "Tells the debugger to read in and execute the file , which should contain lldb commands." }, - { LLDB_3_TO_5, false, "editor" , 'e', no_argument , NULL, eArgTypeNone, "Tells the debugger to open source files using the host's \"external editor\" mechanism." }, - { LLDB_3_TO_5, false, "no-lldbinit" , 'x', no_argument , NULL, eArgTypeNone, "Do not automatically parse any '.lldbinit' files." }, + { LLDB_OPT_SET_1, true , "help" , 'h', no_argument , NULL, eArgTypeNone, + "Prints out the usage information for the LLDB debugger." }, + { LLDB_OPT_SET_2, true , "version" , 'v', no_argument , NULL, eArgTypeNone, + "Prints out the current version number of the LLDB debugger." }, + { LLDB_OPT_SET_3, true , "arch" , 'a', required_argument, NULL, eArgTypeArchitecture, + "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, true , "file" , 'f', required_argument, NULL, eArgTypeFilename, + "Tells the debugger to use the file as the program to be debugged." }, + { LLDB_OPT_SET_4, true , "attach-name" , 'n', required_argument, NULL, eArgTypeProcessName, + "Tells the debugger to attach to a process with the given name." }, + { LLDB_OPT_SET_4, true , "wait-for" , 'w', no_argument , NULL, eArgTypeNone, + "Tells the debugger to wait for a process with the given pid or name to launch before attaching." }, + { LLDB_OPT_SET_5, true , "attach-pid" , 'p', required_argument, NULL, eArgTypePid, + "Tells the debugger to attach to a process with the given pid." }, + { LLDB_3_TO_5, false, "script-language", 'l', required_argument, NULL, eArgTypeScriptLang, + "Tells the debugger to use the specified scripting language for user-defined scripts, rather than the default. " + "Valid scripting languages that can be specified include Python, Perl, Ruby and Tcl. Currently only the Python " + "extensions have been implemented." }, + { LLDB_3_TO_5, false, "debug" , 'd', no_argument , NULL, eArgTypeNone, + "Tells the debugger to print out extra information for debugging itself." }, + { LLDB_3_TO_5, false, "source" , 's', required_argument, NULL, eArgTypeFilename, + "Tells the debugger to read in and execute the file , which should contain lldb commands." }, + { LLDB_3_TO_5, false, "editor" , 'e', no_argument , NULL, eArgTypeNone, + "Tells the debugger to open source files using the host's \"external editor\" mechanism." }, + { LLDB_3_TO_5, false, "no-lldbinit" , 'x', no_argument , NULL, eArgTypeNone, + "Do not automatically parse any '.lldbinit' files." }, { 0, false, NULL , 0 , 0 , NULL, eArgTypeNone, NULL } }; @@ -1365,9 +1380,7 @@ } } - SBProcess process = m_debugger.GetSelectedTarget().GetProcess(); - if (process.IsValid()) - process.Destroy(); + SBDebugger::Destroy (m_debugger); } } } From jingham at apple.com Thu Sep 15 16:36:42 2011 From: jingham at apple.com (Jim Ingham) Date: Thu, 15 Sep 2011 21:36:42 -0000 Subject: [Lldb-commits] [lldb] r139853 - in /lldb/trunk/source: Core/Debugger.cpp Target/Process.cpp Message-ID: <20110915213642.D93222A6C12C@llvm.org> Author: jingham Date: Thu Sep 15 16:36:42 2011 New Revision: 139853 URL: http://llvm.org/viewvc/llvm-project?rev=139853&view=rev Log: Track whether a process was Launched or Attached to. If Attached, the detach when the debugger is destroyed, rather than killing the process. Also added a Debugger::Clear, which gets called in Debugger::Destroy to deal with all the targets in the Debugger. Also made the Driver's main loop call Destroy on the debugger, rather than just Destroying the currently selected Target's process. Modified: lldb/trunk/source/Core/Debugger.cpp lldb/trunk/source/Target/Process.cpp Modified: lldb/trunk/source/Core/Debugger.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/Debugger.cpp?rev=139853&r1=139852&r2=139853&view=diff ============================================================================== --- lldb/trunk/source/Core/Debugger.cpp (original) +++ lldb/trunk/source/Core/Debugger.cpp Thu Sep 15 16:36:42 2011 @@ -157,6 +157,8 @@ if (debugger_sp.get() == NULL) return; + debugger_sp->Clear(); + Mutex::Locker locker (GetDebuggerListMutex ()); DebuggerList &debugger_list = GetDebuggerList (); DebuggerList::iterator pos, end = debugger_list.end(); @@ -168,7 +170,6 @@ return; } } - } lldb::DebuggerSP @@ -252,17 +253,28 @@ Debugger::~Debugger () { + Clear(); +} + +void +Debugger::Clear() +{ CleanUpInputReaders(); int num_targets = m_target_list.GetNumTargets(); for (int i = 0; i < num_targets; i++) { ProcessSP process_sp (m_target_list.GetTargetAtIndex (i)->GetProcessSP()); if (process_sp) - process_sp->Destroy(); + { + if (process_sp->AttachedToProcess()) + process_sp->Detach(); + else + process_sp->Destroy(); + } } DisconnectInput(); -} +} bool Debugger::GetCloseInputOnEOF () const Modified: lldb/trunk/source/Target/Process.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Process.cpp?rev=139853&r1=139852&r2=139853&view=diff ============================================================================== --- lldb/trunk/source/Target/Process.cpp (original) +++ lldb/trunk/source/Target/Process.cpp Thu Sep 15 16:36:42 2011 @@ -600,6 +600,7 @@ m_stdout_data (), m_memory_cache (*this), m_allocated_memory_cache (*this), + m_attached_to_process (false), m_next_event_action_ap() { UpdateInstanceName(); @@ -2305,6 +2306,7 @@ { // Let the process subclass figure out at much as it can about the process // before we go looking for a dynamic loader plug-in. + m_attached_to_process = true; DidAttach(); // We just attached. If we have a platform, ask it for the process architecture, and if it isn't From johnny.chen at apple.com Thu Sep 15 16:53:00 2011 From: johnny.chen at apple.com (Johnny Chen) Date: Thu, 15 Sep 2011 21:53:00 -0000 Subject: [Lldb-commits] [lldb] r139855 - /lldb/trunk/test/python_api/default-constructor/sb_debugger.py Message-ID: <20110915215300.08CE72A6C12C@llvm.org> Author: johnny Date: Thu Sep 15 16:52:59 2011 New Revision: 139855 URL: http://llvm.org/viewvc/llvm-project?rev=139855&view=rev Log: Add fuzz calls to newly added methods: GetAsync() and SetSelectedTarget(SBTarget). Modified: lldb/trunk/test/python_api/default-constructor/sb_debugger.py Modified: lldb/trunk/test/python_api/default-constructor/sb_debugger.py URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/python_api/default-constructor/sb_debugger.py?rev=139855&r1=139854&r2=139855&view=diff ============================================================================== --- lldb/trunk/test/python_api/default-constructor/sb_debugger.py (original) +++ lldb/trunk/test/python_api/default-constructor/sb_debugger.py Thu Sep 15 16:52:59 2011 @@ -8,6 +8,7 @@ def fuzz_obj(obj): obj.SetAsync(True) obj.SetAsync(False) + obj.GetAsync() obj.SkipLLDBInitFiles(True) obj.SetInputFileHandle(None, True) obj.SetOutputFileHandle(None, True) @@ -29,6 +30,7 @@ obj.GetNumTargets() obj.GetSelectedTarget() obj.GetSourceManager() + obj.SetSelectedTarget(lldb.SBTarget()) obj.SetCurrentPlatformSDKRoot("tmp/sdk-root") obj.DispatchInput(None, None, 0) obj.DispatchInputInterrupt() From johnny.chen at apple.com Thu Sep 15 16:58:36 2011 From: johnny.chen at apple.com (Johnny Chen) Date: Thu, 15 Sep 2011 21:58:36 -0000 Subject: [Lldb-commits] [lldb] r139857 - /lldb/trunk/test/python_api/default-constructor/sb_target.py Message-ID: <20110915215836.C2EC12A6C12C@llvm.org> Author: johnny Date: Thu Sep 15 16:58:36 2011 New Revision: 139857 URL: http://llvm.org/viewvc/llvm-project?rev=139857&view=rev Log: Add fuzz calls for added API methods: FindFirstType(), FindTypes(), and GetSourceManager(). Modified: lldb/trunk/test/python_api/default-constructor/sb_target.py Modified: lldb/trunk/test/python_api/default-constructor/sb_target.py URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/python_api/default-constructor/sb_target.py?rev=139857&r1=139856&r2=139857&view=diff ============================================================================== --- lldb/trunk/test/python_api/default-constructor/sb_target.py (original) +++ lldb/trunk/test/python_api/default-constructor/sb_target.py Thu Sep 15 16:58:36 2011 @@ -22,6 +22,9 @@ obj.FindModule(filespec) contextlist = lldb.SBSymbolContextList() obj.FindFunctions("the_func", 0xff, True, contextlist) + obj.FindFirstType("dont_care") + obj.FindTypes("dont_care") + obj.GetSourceManager() obj.FindGlobalVariables("my_global_var", 1) address = obj.ResolveLoadAddress(0xffff) obj.ResolveSymbolContextForAddress(address, 0) From johnny.chen at apple.com Thu Sep 15 17:05:38 2011 From: johnny.chen at apple.com (Johnny Chen) Date: Thu, 15 Sep 2011 22:05:38 -0000 Subject: [Lldb-commits] [lldb] r139862 - /lldb/trunk/scripts/Python/interface/SBData.i Message-ID: <20110915220538.B14692A6C12C@llvm.org> Author: johnny Date: Thu Sep 15 17:05:38 2011 New Revision: 139862 URL: http://llvm.org/viewvc/llvm-project?rev=139862&view=rev Log: Untabify and fix indentations. Tabs are bad. Modified: lldb/trunk/scripts/Python/interface/SBData.i Modified: lldb/trunk/scripts/Python/interface/SBData.i URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/Python/interface/SBData.i?rev=139862&r1=139861&r2=139862&view=diff ============================================================================== --- lldb/trunk/scripts/Python/interface/SBData.i (original) +++ lldb/trunk/scripts/Python/interface/SBData.i Thu Sep 15 17:05:38 2011 @@ -14,80 +14,80 @@ { public: - SBData (); + SBData (); - SBData (const SBData &rhs); + SBData (const SBData &rhs); - ~SBData (); + ~SBData (); - uint8_t - GetAddressByteSize (); + uint8_t + GetAddressByteSize (); - void - Clear (); + void + Clear (); - bool - IsValid(); + bool + IsValid(); - size_t - GetByteSize (); + size_t + GetByteSize (); - lldb::ByteOrder - GetByteOrder(); + lldb::ByteOrder + GetByteOrder(); - float - GetFloat (lldb::SBError& error, uint32_t offset); + float + GetFloat (lldb::SBError& error, uint32_t offset); - double - GetDouble (lldb::SBError& error, uint32_t offset); + double + GetDouble (lldb::SBError& error, uint32_t offset); - long double - GetLongDouble (lldb::SBError& error, uint32_t offset); + long double + GetLongDouble (lldb::SBError& error, uint32_t offset); - lldb::addr_t - GetAddress (lldb::SBError& error, uint32_t offset); + lldb::addr_t + GetAddress (lldb::SBError& error, uint32_t offset); - uint8_t - GetUnsignedInt8 (lldb::SBError& error, uint32_t offset); + uint8_t + GetUnsignedInt8 (lldb::SBError& error, uint32_t offset); - uint16_t - GetUnsignedInt16 (lldb::SBError& error, uint32_t offset); + uint16_t + GetUnsignedInt16 (lldb::SBError& error, uint32_t offset); - uint32_t - GetUnsignedInt32 (lldb::SBError& error, uint32_t offset); + uint32_t + GetUnsignedInt32 (lldb::SBError& error, uint32_t offset); - uint64_t - GetUnsignedInt64 (lldb::SBError& error, uint32_t offset); + uint64_t + GetUnsignedInt64 (lldb::SBError& error, uint32_t offset); - int8_t - GetSignedInt8 (lldb::SBError& error, uint32_t offset); + int8_t + GetSignedInt8 (lldb::SBError& error, uint32_t offset); - int16_t - GetSignedInt16 (lldb::SBError& error, uint32_t offset); + int16_t + GetSignedInt16 (lldb::SBError& error, uint32_t offset); - int32_t - GetSignedInt32 (lldb::SBError& error, uint32_t offset); + int32_t + GetSignedInt32 (lldb::SBError& error, uint32_t offset); - int64_t - GetSignedInt64 (lldb::SBError& error, uint32_t offset); + int64_t + GetSignedInt64 (lldb::SBError& error, uint32_t offset); - const char* - GetString (lldb::SBError& error, uint32_t offset); - - bool - GetDescription (lldb::SBStream &description); + const char* + GetString (lldb::SBError& error, uint32_t offset); - size_t - ReadRawData (lldb::SBError& error, - uint32_t offset, - void *buf, - size_t size); + bool + GetDescription (lldb::SBStream &description); - void - SetData(lldb::SBError& error, const void *buf, size_t size, lldb::ByteOrder endian, uint8_t addr_size); + size_t + ReadRawData (lldb::SBError& error, + uint32_t offset, + void *buf, + size_t size); - bool - Append(const SBData& rhs); + void + SetData(lldb::SBError& error, const void *buf, size_t size, lldb::ByteOrder endian, uint8_t addr_size); + + bool + Append(const SBData& rhs); }; From johnny.chen at apple.com Thu Sep 15 17:13:43 2011 From: johnny.chen at apple.com (Johnny Chen) Date: Thu, 15 Sep 2011 22:13:43 -0000 Subject: [Lldb-commits] [lldb] r139863 - /lldb/trunk/test/python_api/sbdata/TestSBData.py Message-ID: <20110915221343.B8B292A6C12C@llvm.org> Author: johnny Date: Thu Sep 15 17:13:43 2011 New Revision: 139863 URL: http://llvm.org/viewvc/llvm-project?rev=139863&view=rev Log: Fix wrong test method name. Modified: lldb/trunk/test/python_api/sbdata/TestSBData.py Modified: lldb/trunk/test/python_api/sbdata/TestSBData.py URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/python_api/sbdata/TestSBData.py?rev=139863&r1=139862&r2=139863&view=diff ============================================================================== --- lldb/trunk/test/python_api/sbdata/TestSBData.py (original) +++ lldb/trunk/test/python_api/sbdata/TestSBData.py Thu Sep 15 17:13:43 2011 @@ -19,7 +19,7 @@ self.data_api() @python_api_test - def test_with_dwarf_and_process_launch_api(self): + def test_with_dwarf_and_run_command(self): """Test the SBData APIs.""" self.buildDwarf() self.data_api() From johnny.chen at apple.com Thu Sep 15 17:25:30 2011 From: johnny.chen at apple.com (Johnny Chen) Date: Thu, 15 Sep 2011 22:25:30 -0000 Subject: [Lldb-commits] [lldb] r139867 - /lldb/trunk/include/lldb/API/SBValue.h Message-ID: <20110915222530.39DCD2A6C12C@llvm.org> Author: johnny Date: Thu Sep 15 17:25:30 2011 New Revision: 139867 URL: http://llvm.org/viewvc/llvm-project?rev=139867&view=rev Log: Untabify and fix indentation. Modified: lldb/trunk/include/lldb/API/SBValue.h Modified: lldb/trunk/include/lldb/API/SBValue.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBValue.h?rev=139867&r1=139866&r2=139867&view=diff ============================================================================== --- lldb/trunk/include/lldb/API/SBValue.h (original) +++ lldb/trunk/include/lldb/API/SBValue.h Thu Sep 15 17:25:30 2011 @@ -221,7 +221,7 @@ //------------------------------------------------------------------ lldb::SBData GetPointeeData (uint32_t item_idx = 0, - uint32_t item_count = 1); + uint32_t item_count = 1); //------------------------------------------------------------------ /// Get an SBData wrapping the contents of this SBValue. From johnny.chen at apple.com Thu Sep 15 20:04:26 2011 From: johnny.chen at apple.com (Johnny Chen) Date: Fri, 16 Sep 2011 01:04:26 -0000 Subject: [Lldb-commits] [lldb] r139896 - /lldb/trunk/test/dotest.py Message-ID: <20110916010426.A555E2A6C12C@llvm.org> Author: johnny Date: Thu Sep 15 20:04:26 2011 New Revision: 139896 URL: http://llvm.org/viewvc/llvm-project?rev=139896&view=rev Log: Add a check for the test driver to make sure that, on Mac OS X, the automatic lookup and caching of dSYMs is not turned on before running the test suite. 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=139896&r1=139895&r2=139896&view=diff ============================================================================== --- lldb/trunk/test/dotest.py (original) +++ lldb/trunk/test/dotest.py Thu Sep 15 20:04:26 2011 @@ -21,6 +21,7 @@ """ import os, signal, sys, time +import subprocess import unittest2 def is_exe(fpath): @@ -618,7 +619,6 @@ #print "The 'lldb' executable path is", lldbExec os.system('%s -v' % lldbExec) - import subprocess if os.path.isdir(os.path.join(base, '.svn')): pipe = subprocess.Popen(["svn", "info", base], stdout = subprocess.PIPE) svn_info = pipe.stdout.read() @@ -784,7 +784,6 @@ raise Exception('log enable failed (check GDB_REMOTE_LOG env variable.') def getMyCommandLine(): - import subprocess ps = subprocess.Popen(['ps', '-o', "command=CMD", str(os.getpid())], stdout=subprocess.PIPE).communicate()[0] lines = ps.split('\n') cmd_line = lines[1] @@ -796,6 +795,21 @@ # # # ======================================== # +def checkDsymForUUIDIsNotOn(): + pipe = subprocess.Popen(["defaults", "read", "com.apple.DebugSymbols"], stdout = subprocess.PIPE) + debug_symbols_output = pipe.stdout.read() + if "DBGFileMappedPaths = " in debug_symbols_output: + print "defaults read com.apple.DebugSysmbols =>" + print debug_symbols_output + print "Disable automatic lookup and caching of dSYMs before running the test suite!" + print "Exiting..." + sys.exit(0) + +# On MacOS X, check to make sure that domain for com.apple.DebugSymbols defaults +# does not exist before proceeding to running the test suite. +if sys.platform.startswith("darwin"): + checkDsymForUUIDIsNotOn() + # # Start the actions by first parsing the options while setting up the test # directories, followed by setting up the search paths for lldb utilities; @@ -1079,7 +1093,6 @@ # Terminate the test suite if ${LLDB_TESTSUITE_FORCE_FINISH} is defined. # This should not be necessary now. if ("LLDB_TESTSUITE_FORCE_FINISH" in os.environ): - import subprocess print "Terminating Test suite..." subprocess.Popen(["/bin/sh", "-c", "kill %s; exit 0" % (os.getpid())]) From jmolenda at apple.com Thu Sep 15 20:32:11 2011 From: jmolenda at apple.com (Jason Molenda) Date: Fri, 16 Sep 2011 01:32:11 -0000 Subject: [Lldb-commits] [lldb] r139897 - in /lldb/trunk/source/Plugins: Process/Utility/RegisterContextLLDB.cpp UnwindAssembly/InstEmulation/UnwindAssemblyInstEmulation.cpp Message-ID: <20110916013211.2932B2A6C12C@llvm.org> Author: jmolenda Date: Thu Sep 15 20:32:10 2011 New Revision: 139897 URL: http://llvm.org/viewvc/llvm-project?rev=139897&view=rev Log: Tighten up the 'log enable lldb unwind' printing for the arm emulate instruction unwinder so you can leave it on by default and not be overwhelmed. Set verbose mode to get the full story on how the unwindplans were created. Modified: lldb/trunk/source/Plugins/Process/Utility/RegisterContextLLDB.cpp lldb/trunk/source/Plugins/UnwindAssembly/InstEmulation/UnwindAssemblyInstEmulation.cpp Modified: lldb/trunk/source/Plugins/Process/Utility/RegisterContextLLDB.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Utility/RegisterContextLLDB.cpp?rev=139897&r1=139896&r2=139897&view=diff ============================================================================== --- lldb/trunk/source/Plugins/Process/Utility/RegisterContextLLDB.cpp (original) +++ lldb/trunk/source/Plugins/Process/Utility/RegisterContextLLDB.cpp Thu Sep 15 20:32:10 2011 @@ -886,7 +886,7 @@ if (active_row->GetRegisterInfo (row_regnum, unwindplan_regloc)) { have_unwindplan_regloc = true; - if (log && IsLogVerbose ()) + if (log) { log->Printf("%*sFrame %u supplying caller's saved reg %d's location using %s UnwindPlan", m_frame_number < 100 ? m_frame_number : 100, "", m_frame_number, @@ -906,7 +906,7 @@ const RegisterInfo *reg_info = GetRegisterInfoAtIndex(lldb_regnum); if (reg_info && abi->RegisterIsVolatile (reg_info)) { - if (log) + if (log && IsLogVerbose ()) { log->Printf("%*sFrame %u did not supply reg location for %d because it is volatile", m_frame_number < 100 ? m_frame_number : 100, "", m_frame_number, @@ -1136,7 +1136,7 @@ // If this is the 0th frame, hand this over to the live register context if (IsFrameZero ()) { - if (log) + if (log && IsLogVerbose ()) { log->Printf("%*sFrame %u passing along to the live register context for reg %d", m_frame_number < 100 ? m_frame_number : 100, "", m_frame_number, @@ -1171,7 +1171,7 @@ // If this is the 0th frame, hand this over to the live register context if (IsFrameZero ()) { - if (log) + if (log && IsLogVerbose ()) { log->Printf("%*sFrame %u passing along to the live register context for reg %d", m_frame_number < 100 ? m_frame_number : 100, "", m_frame_number, Modified: lldb/trunk/source/Plugins/UnwindAssembly/InstEmulation/UnwindAssemblyInstEmulation.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/UnwindAssembly/InstEmulation/UnwindAssemblyInstEmulation.cpp?rev=139897&r1=139896&r2=139897&view=diff ============================================================================== --- lldb/trunk/source/Plugins/UnwindAssembly/InstEmulation/UnwindAssemblyInstEmulation.cpp (original) +++ lldb/trunk/source/Plugins/UnwindAssembly/InstEmulation/UnwindAssemblyInstEmulation.cpp Thu Sep 15 20:32:10 2011 @@ -104,7 +104,7 @@ if (inst) { - if (log) + if (log && IsLogVerbose ()) { StreamString strm; inst->Dump(&strm, inst_list.GetMaxOpcocdeByteSize (), show_address, show_bytes, &exe_ctx, raw); @@ -130,7 +130,7 @@ } } - if (log) + if (log && IsLogVerbose ()) { StreamString strm; lldb::addr_t base_addr = range.GetBaseAddress().GetLoadAddress(&thread.GetProcess().GetTarget()); @@ -264,7 +264,7 @@ { LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_UNWIND)); - if (log) + if (log && IsLogVerbose ()) { StreamString strm; strm.Printf ("UnwindAssemblyInstEmulation::ReadMemory (addr = 0x%16.16llx, dst = %p, dst_len = %zu, context = ", @@ -304,7 +304,7 @@ LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_UNWIND)); - if (log) + if (log && IsLogVerbose ()) { StreamString strm; @@ -407,7 +407,7 @@ LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_UNWIND)); - if (log) + if (log && IsLogVerbose ()) { StreamString strm; @@ -437,7 +437,7 @@ { LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_UNWIND)); - if (log) + if (log && IsLogVerbose ()) { StreamString strm; From johnny.chen at apple.com Fri Sep 16 12:50:44 2011 From: johnny.chen at apple.com (Johnny Chen) Date: Fri, 16 Sep 2011 17:50:44 -0000 Subject: [Lldb-commits] [lldb] r139914 - /lldb/trunk/test/dotest.py Message-ID: <20110916175044.B03FD2A6C12C@llvm.org> Author: johnny Date: Fri Sep 16 12:50:44 2011 New Revision: 139914 URL: http://llvm.org/viewvc/llvm-project?rev=139914&view=rev Log: Rephrase the checkDsymForUUIDIsNotOn() a bit so that in the normal case where automatic lookup and cacheing of dSYMs is not enabled, the 'defaults read com.apple.DebugSymbols' output is not shown. 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=139914&r1=139913&r2=139914&view=diff ============================================================================== --- lldb/trunk/test/dotest.py (original) +++ lldb/trunk/test/dotest.py Fri Sep 16 12:50:44 2011 @@ -603,7 +603,7 @@ if not lldbExec: lldbExec = lldbHere os.environ["LLDB_BUILD_DIR"] = os.path.split(lldbExec)[0] - print os.environ["LLDB_BUILD_DIR"] + print "LLDB build dir:", os.environ["LLDB_BUILD_DIR"] # One last chance to locate the 'lldb' executable. if not lldbExec: @@ -796,11 +796,12 @@ # ======================================== # def checkDsymForUUIDIsNotOn(): - pipe = subprocess.Popen(["defaults", "read", "com.apple.DebugSymbols"], stdout = subprocess.PIPE) - debug_symbols_output = pipe.stdout.read() - if "DBGFileMappedPaths = " in debug_symbols_output: - print "defaults read com.apple.DebugSysmbols =>" - print debug_symbols_output + cmd = ["defaults", "read", "com.apple.DebugSymbols"] + pipe = subprocess.Popen(cmd, stdout = subprocess.PIPE, stderr = subprocess.STDOUT) + cmd_output = pipe.stdout.read() + if "DBGFileMappedPaths = " in cmd_output: + print "Executing: '%s' =>" % ' '.join(cmd) + print cmd_output print "Disable automatic lookup and caching of dSYMs before running the test suite!" print "Exiting..." sys.exit(0) From johnny.chen at apple.com Fri Sep 16 13:03:19 2011 From: johnny.chen at apple.com (Johnny Chen) Date: Fri, 16 Sep 2011 18:03:19 -0000 Subject: [Lldb-commits] [lldb] r139920 - /lldb/trunk/test/dotest.py Message-ID: <20110916180319.9A5582A6C12C@llvm.org> Author: johnny Date: Fri Sep 16 13:03:19 2011 New Revision: 139920 URL: http://llvm.org/viewvc/llvm-project?rev=139920&view=rev Log: To be more paranoid, check cmd_output before searching in it. 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=139920&r1=139919&r2=139920&view=diff ============================================================================== --- lldb/trunk/test/dotest.py (original) +++ lldb/trunk/test/dotest.py Fri Sep 16 13:03:19 2011 @@ -799,7 +799,7 @@ cmd = ["defaults", "read", "com.apple.DebugSymbols"] pipe = subprocess.Popen(cmd, stdout = subprocess.PIPE, stderr = subprocess.STDOUT) cmd_output = pipe.stdout.read() - if "DBGFileMappedPaths = " in cmd_output: + if cmd_output and "DBGFileMappedPaths = " in cmd_output: print "Executing: '%s' =>" % ' '.join(cmd) print cmd_output print "Disable automatic lookup and caching of dSYMs before running the test suite!" From johnny.chen at apple.com Fri Sep 16 13:09:45 2011 From: johnny.chen at apple.com (Johnny Chen) Date: Fri, 16 Sep 2011 18:09:45 -0000 Subject: [Lldb-commits] [lldb] r139924 - /lldb/trunk/test/dotest.py Message-ID: <20110916180945.7DA982A6C12C@llvm.org> Author: johnny Date: Fri Sep 16 13:09:45 2011 New Revision: 139924 URL: http://llvm.org/viewvc/llvm-project?rev=139924&view=rev Log: Minor change for output message (less is better). 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=139924&r1=139923&r2=139924&view=diff ============================================================================== --- lldb/trunk/test/dotest.py (original) +++ lldb/trunk/test/dotest.py Fri Sep 16 13:09:45 2011 @@ -800,7 +800,7 @@ pipe = subprocess.Popen(cmd, stdout = subprocess.PIPE, stderr = subprocess.STDOUT) cmd_output = pipe.stdout.read() if cmd_output and "DBGFileMappedPaths = " in cmd_output: - print "Executing: '%s' =>" % ' '.join(cmd) + print "%s =>" % ' '.join(cmd) print cmd_output print "Disable automatic lookup and caching of dSYMs before running the test suite!" print "Exiting..." From johnny.chen at apple.com Fri Sep 16 16:41:42 2011 From: johnny.chen at apple.com (Johnny Chen) Date: Fri, 16 Sep 2011 21:41:42 -0000 Subject: [Lldb-commits] [lldb] r139946 - in /lldb/trunk: include/lldb/Breakpoint/WatchpointLocation.h include/lldb/Breakpoint/WatchpointLocationList.h source/Breakpoint/WatchpointLocation.cpp source/Breakpoint/WatchpointLocationList.cpp source/Commands/CommandObjectFrame.cpp test/functionalities/watchpoint/hello_watchpoint/TestMyFirstWatchpoint.py test/functionalities/watchpoint/hello_watchpoint/main.c Message-ID: <20110916214142.E04972A6C12C@llvm.org> Author: johnny Date: Fri Sep 16 16:41:42 2011 New Revision: 139946 URL: http://llvm.org/viewvc/llvm-project?rev=139946&view=rev Log: Add a declaraion info member field to the WatchpointLocation class. Modify CommandObjectFrame.cpp to populate this field when creating a watchpoint location. Update the test case to verify that the declaration info matches the file and line number. Modified: lldb/trunk/include/lldb/Breakpoint/WatchpointLocation.h lldb/trunk/include/lldb/Breakpoint/WatchpointLocationList.h lldb/trunk/source/Breakpoint/WatchpointLocation.cpp lldb/trunk/source/Breakpoint/WatchpointLocationList.cpp lldb/trunk/source/Commands/CommandObjectFrame.cpp lldb/trunk/test/functionalities/watchpoint/hello_watchpoint/TestMyFirstWatchpoint.py lldb/trunk/test/functionalities/watchpoint/hello_watchpoint/main.c Modified: lldb/trunk/include/lldb/Breakpoint/WatchpointLocation.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Breakpoint/WatchpointLocation.h?rev=139946&r1=139945&r2=139946&view=diff ============================================================================== --- lldb/trunk/include/lldb/Breakpoint/WatchpointLocation.h (original) +++ lldb/trunk/include/lldb/Breakpoint/WatchpointLocation.h Fri Sep 16 16:41:42 2011 @@ -14,6 +14,7 @@ // C++ Includes #include +#include // Other libraries and framework includes @@ -46,8 +47,10 @@ void SetWatchpointType (uint32_t type); bool BreakpointWasHit (StoppointCallbackContext *context); bool SetCallback (WatchpointHitCallback callback, void *callback_baton); + void SetDeclInfo (std::string &str); void GetDescription (Stream *s, lldb::DescriptionLevel level); void Dump (Stream *s) const; + void DumpWithLevel (Stream *s, lldb::DescriptionLevel description_level) const; private: bool m_enabled; // Is this breakpoint enabled @@ -58,6 +61,7 @@ uint32_t m_ignore_count; // Number of times to ignore this breakpoint WatchpointHitCallback m_callback; void * m_callback_baton; // Callback user data to pass to callback + std::string m_decl_str; // Declaration information, if any. static lldb::break_id_t GetNextID(); Modified: lldb/trunk/include/lldb/Breakpoint/WatchpointLocationList.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Breakpoint/WatchpointLocationList.h?rev=139946&r1=139945&r2=139946&view=diff ============================================================================== --- lldb/trunk/include/lldb/Breakpoint/WatchpointLocationList.h (original) +++ lldb/trunk/include/lldb/Breakpoint/WatchpointLocationList.h Fri Sep 16 16:41:42 2011 @@ -67,6 +67,12 @@ Dump (Stream *s) const; //------------------------------------------------------------------ + /// Dump with lldb::DescriptionLevel. + //------------------------------------------------------------------ + void + DumpWithLevel (Stream *s, lldb::DescriptionLevel description_level) const; + + //------------------------------------------------------------------ /// Returns a shared pointer to the watchpoint location at address /// \a addr - const version. /// Modified: lldb/trunk/source/Breakpoint/WatchpointLocation.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Breakpoint/WatchpointLocation.cpp?rev=139946&r1=139945&r2=139946&view=diff ============================================================================== --- lldb/trunk/source/Breakpoint/WatchpointLocation.cpp (original) +++ lldb/trunk/source/Breakpoint/WatchpointLocation.cpp Fri Sep 16 16:41:42 2011 @@ -50,6 +50,13 @@ return true; } +void +WatchpointLocation::SetDeclInfo (std::string &str) +{ + m_decl_str = str; + return; +} + // RETURNS - true if we should stop at this breakpoint, false if we // should continue. @@ -75,27 +82,42 @@ WatchpointLocation::GetDescription (Stream *s, lldb::DescriptionLevel level) { s->Printf(" "); - Dump(s); + DumpWithLevel(s, level); return; } void WatchpointLocation::Dump(Stream *s) const { + DumpWithLevel(s, lldb::eDescriptionLevelBrief); +} + +void +WatchpointLocation::DumpWithLevel(Stream *s, lldb::DescriptionLevel description_level) const +{ if (s == NULL) return; - s->Printf("WatchpointLocation %u: addr = 0x%8.8llx size = %zu state = %s type = %s%s hit_count = %-4u ignore_count = %-4u callback = %8p baton = %8p", - GetID(), - (uint64_t)m_addr, - m_byte_size, - m_enabled ? "enabled " : "disabled", - m_watch_read ? "r" : "", - m_watch_write ? "w" : "", - GetHitCount(), - GetIgnoreCount(), - m_callback, - m_callback_baton); + assert(description_level >= lldb::eDescriptionLevelBrief && + description_level <= lldb::eDescriptionLevelVerbose); + + s->Printf("WatchpointLocation %u: addr = 0x%8.8llx size = %zu state = %s type = %s%s", + GetID(), + (uint64_t)m_addr, + m_byte_size, + m_enabled ? "enabled" : "disabled", + m_watch_read ? "r" : "", + m_watch_write ? "w" : ""); + + if (description_level >= lldb::eDescriptionLevelFull) + s->Printf("\n declare @ '%s'", m_decl_str.c_str()); + + if (description_level >= lldb::eDescriptionLevelVerbose) + s->Printf("\n hit_count = %-4u ignore_count = %-4u callback = %8p baton = %8p", + GetHitCount(), + GetIgnoreCount(), + m_callback, + m_callback_baton); } bool Modified: lldb/trunk/source/Breakpoint/WatchpointLocationList.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Breakpoint/WatchpointLocationList.cpp?rev=139946&r1=139945&r2=139946&view=diff ============================================================================== --- lldb/trunk/source/Breakpoint/WatchpointLocationList.cpp (original) +++ lldb/trunk/source/Breakpoint/WatchpointLocationList.cpp Fri Sep 16 16:41:42 2011 @@ -54,6 +54,12 @@ void WatchpointLocationList::Dump (Stream *s) const { + DumpWithLevel(s, lldb::eDescriptionLevelBrief); +} + +void +WatchpointLocationList::DumpWithLevel (Stream *s, lldb::DescriptionLevel description_level) const +{ Mutex::Locker locker (m_mutex); s->Printf("%.*p: ", (int)sizeof(void*) * 2, this); //s->Indent(); @@ -62,7 +68,7 @@ s->IndentMore(); addr_map::const_iterator pos, end = m_address_to_location.end(); for (pos = m_address_to_location.begin(); pos != end; ++pos) - pos->second->Dump(s); + pos->second->DumpWithLevel(s, description_level); s->IndentLess(); } Modified: lldb/trunk/source/Commands/CommandObjectFrame.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectFrame.cpp?rev=139946&r1=139945&r2=139946&view=diff ============================================================================== --- lldb/trunk/source/Commands/CommandObjectFrame.cpp (original) +++ lldb/trunk/source/Commands/CommandObjectFrame.cpp Fri Sep 16 16:41:42 2011 @@ -11,12 +11,14 @@ // C Includes // C++ Includes +#include // Other libraries and framework includes // Project includes #include "lldb/Core/DataVisualization.h" #include "lldb/Core/Debugger.h" #include "lldb/Core/Module.h" #include "lldb/Core/StreamFile.h" +#include "lldb/Core/StreamString.h" #include "lldb/Core/Timer.h" #include "lldb/Core/Value.h" #include "lldb/Core/ValueObject.h" @@ -535,8 +537,15 @@ exe_ctx.target->CreateWatchpointLocation(addr, size, watch_type).get(); if (wp_loc) { + if (var_sp && var_sp->GetDeclaration().GetFile()) + { + StreamString ss; + var_sp->GetDeclaration().DumpStopContext(&ss, true); + wp_loc->SetDeclInfo(ss.GetString()); + } + StreamString ss; output_stream.Printf("Watchpoint created: "); - wp_loc->GetDescription(&output_stream, lldb::eDescriptionLevelBrief); + wp_loc->GetDescription(&output_stream, lldb::eDescriptionLevelFull); output_stream.EOL(); result.SetStatus(eReturnStatusSuccessFinishResult); } Modified: lldb/trunk/test/functionalities/watchpoint/hello_watchpoint/TestMyFirstWatchpoint.py URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/watchpoint/hello_watchpoint/TestMyFirstWatchpoint.py?rev=139946&r1=139945&r2=139946&view=diff ============================================================================== --- lldb/trunk/test/functionalities/watchpoint/hello_watchpoint/TestMyFirstWatchpoint.py (original) +++ lldb/trunk/test/functionalities/watchpoint/hello_watchpoint/TestMyFirstWatchpoint.py Fri Sep 16 16:41:42 2011 @@ -31,6 +31,8 @@ self.source = 'main.c' # Find the line number to break inside main(). self.line = line_number(self.source, '// Set break point at this line.') + # And the watchpoint variable declaration line number. + self.decl = line_number(self.source, '// Watchpoint variable declaration.') # Build dictionary to have unique executable names for each test method. self.exe_name = self.testMethodName self.d = {'C_SOURCES': self.source, 'EXE': self.exe_name} @@ -57,7 +59,8 @@ # Now let's set a write-type watchpoint for 'global'. # There should be only one watchpoint hit (see main.c). self.expect("frame variable -w write -g -L global", WATCHPOINT_CREATED, - substrs = ['Watchpoint created', 'size = 4', 'type = w']) + substrs = ['Watchpoint created', 'size = 4', 'type = w', + '%s:%d' % (self.source, self.decl)]) self.runCmd("process continue") Modified: lldb/trunk/test/functionalities/watchpoint/hello_watchpoint/main.c URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/watchpoint/hello_watchpoint/main.c?rev=139946&r1=139945&r2=139946&view=diff ============================================================================== --- lldb/trunk/test/functionalities/watchpoint/hello_watchpoint/main.c (original) +++ lldb/trunk/test/functionalities/watchpoint/hello_watchpoint/main.c Fri Sep 16 16:41:42 2011 @@ -9,7 +9,7 @@ #include #include -int32_t global = 10; +int32_t global = 10; // Watchpoint variable declaration. int main(int argc, char** argv) { int local = 0; From johnny.chen at apple.com Fri Sep 16 16:44:45 2011 From: johnny.chen at apple.com (Johnny Chen) Date: Fri, 16 Sep 2011 21:44:45 -0000 Subject: [Lldb-commits] [lldb] r139947 - /lldb/trunk/source/Commands/CommandObjectFrame.cpp Message-ID: <20110916214445.B1B7F2A6C12C@llvm.org> Author: johnny Date: Fri Sep 16 16:44:45 2011 New Revision: 139947 URL: http://llvm.org/viewvc/llvm-project?rev=139947&view=rev Log: Add comment. Modified: lldb/trunk/source/Commands/CommandObjectFrame.cpp Modified: lldb/trunk/source/Commands/CommandObjectFrame.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectFrame.cpp?rev=139947&r1=139946&r2=139947&view=diff ============================================================================== --- lldb/trunk/source/Commands/CommandObjectFrame.cpp (original) +++ lldb/trunk/source/Commands/CommandObjectFrame.cpp Fri Sep 16 16:44:45 2011 @@ -540,6 +540,7 @@ if (var_sp && var_sp->GetDeclaration().GetFile()) { StreamString ss; + // True to show fullpath for declrarion file. var_sp->GetDeclaration().DumpStopContext(&ss, true); wp_loc->SetDeclInfo(ss.GetString()); } From johnny.chen at apple.com Fri Sep 16 16:46:38 2011 From: johnny.chen at apple.com (Johnny Chen) Date: Fri, 16 Sep 2011 21:46:38 -0000 Subject: [Lldb-commits] [lldb] r139948 - /lldb/trunk/source/Commands/CommandObjectFrame.cpp Message-ID: <20110916214638.2D4742A6C12C@llvm.org> Author: johnny Date: Fri Sep 16 16:46:38 2011 New Revision: 139948 URL: http://llvm.org/viewvc/llvm-project?rev=139948&view=rev Log: Fix typo. Modified: lldb/trunk/source/Commands/CommandObjectFrame.cpp Modified: lldb/trunk/source/Commands/CommandObjectFrame.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectFrame.cpp?rev=139948&r1=139947&r2=139948&view=diff ============================================================================== --- lldb/trunk/source/Commands/CommandObjectFrame.cpp (original) +++ lldb/trunk/source/Commands/CommandObjectFrame.cpp Fri Sep 16 16:46:38 2011 @@ -540,7 +540,7 @@ if (var_sp && var_sp->GetDeclaration().GetFile()) { StreamString ss; - // True to show fullpath for declrarion file. + // True to show fullpath for declaration file. var_sp->GetDeclaration().DumpStopContext(&ss, true); wp_loc->SetDeclInfo(ss.GetString()); } From johnny.chen at apple.com Fri Sep 16 20:05:03 2011 From: johnny.chen at apple.com (Johnny Chen) Date: Sat, 17 Sep 2011 01:05:03 -0000 Subject: [Lldb-commits] [lldb] r139975 - in /lldb/trunk: source/Plugins/Process/Utility/StopInfoMachException.cpp source/Plugins/Process/Utility/StopInfoMachException.h source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp tools/debugserver/source/MacOSX/i386/DNBArchImplI386.cpp tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.cpp Message-ID: <20110917010503.E30D52A6C12C@llvm.org> Author: johnny Date: Fri Sep 16 20:05:03 2011 New Revision: 139975 URL: http://llvm.org/viewvc/llvm-project?rev=139975&view=rev Log: Foe x86_64/i386, piggyback the hardware index of the fired watchpoint in the exception data sent back to the debugger. On the debugger side, use the opportunity during the StopInfoMachException::CreateStopReasonWithMachException() method to set the hardware index for the very watchpoint location. Modified: lldb/trunk/source/Plugins/Process/Utility/StopInfoMachException.cpp lldb/trunk/source/Plugins/Process/Utility/StopInfoMachException.h lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp lldb/trunk/tools/debugserver/source/MacOSX/i386/DNBArchImplI386.cpp lldb/trunk/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.cpp Modified: lldb/trunk/source/Plugins/Process/Utility/StopInfoMachException.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Utility/StopInfoMachException.cpp?rev=139975&r1=139974&r2=139975&view=diff ============================================================================== --- lldb/trunk/source/Plugins/Process/Utility/StopInfoMachException.cpp (original) +++ lldb/trunk/source/Plugins/Process/Utility/StopInfoMachException.cpp Fri Sep 16 20:05:03 2011 @@ -245,7 +245,8 @@ uint32_t exc_type, uint32_t exc_data_count, uint64_t exc_code, - uint64_t exc_sub_code + uint64_t exc_sub_code, + uint64_t exc_sub_sub_code ) { if (exc_type != 0) @@ -303,10 +304,17 @@ return StopInfo::CreateStopReasonToTrace(thread); // It's a watchpoint, then. + // The exc_sub_code indicates the data break address. lldb::WatchpointLocationSP wp_loc_sp = thread.GetProcess().GetTarget().GetWatchpointLocationList().FindByAddress((lldb::addr_t)exc_sub_code); if (wp_loc_sp) + { + // Debugserver may piggyback the hardware index of the fired watchpoint in the exception data. + // Set the hardware index if that's the case. + if (exc_data_count >=3) + wp_loc_sp->SetHardwareIndex((uint32_t)exc_sub_sub_code); return StopInfo::CreateStopReasonWithWatchpointID(thread, wp_loc_sp->GetID()); + } } else if (exc_code == 2) // EXC_I386_BPT { Modified: lldb/trunk/source/Plugins/Process/Utility/StopInfoMachException.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Utility/StopInfoMachException.h?rev=139975&r1=139974&r2=139975&view=diff ============================================================================== --- lldb/trunk/source/Plugins/Process/Utility/StopInfoMachException.h (original) +++ lldb/trunk/source/Plugins/Process/Utility/StopInfoMachException.h Fri Sep 16 20:05:03 2011 @@ -60,7 +60,8 @@ uint32_t exc_type, uint32_t exc_data_count, uint64_t exc_code, - uint64_t exc_subcode); + uint64_t exc_sub_code, + uint64_t exc_sub_sub_code); protected: uint32_t m_exc_data_count; 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=139975&r1=139974&r2=139975&view=diff ============================================================================== --- lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp (original) +++ lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp Fri Sep 16 20:05:03 2011 @@ -1228,7 +1228,8 @@ exc_type, exc_data_size, exc_data_size >= 1 ? exc_data[0] : 0, - exc_data_size >= 2 ? exc_data[1] : 0)); + exc_data_size >= 2 ? exc_data[1] : 0, + exc_data_size >= 3 ? exc_data[2] : 0)); } else { Modified: lldb/trunk/tools/debugserver/source/MacOSX/i386/DNBArchImplI386.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/MacOSX/i386/DNBArchImplI386.cpp?rev=139975&r1=139974&r2=139975&view=diff ============================================================================== --- lldb/trunk/tools/debugserver/source/MacOSX/i386/DNBArchImplI386.cpp (original) +++ lldb/trunk/tools/debugserver/source/MacOSX/i386/DNBArchImplI386.cpp Fri Sep 16 20:05:03 2011 @@ -645,7 +645,11 @@ nub_addr_t addr = 0; uint32_t hw_index = GetHardwareWatchpointHit(addr); if (hw_index != INVALID_NUB_HW_INDEX) + { exc.exc_data[1] = addr; + // Piggyback the hw_index in the exc.data. + exc.exc_data.push_back(hw_index); + } return true; } Modified: lldb/trunk/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.cpp?rev=139975&r1=139974&r2=139975&view=diff ============================================================================== --- lldb/trunk/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.cpp (original) +++ lldb/trunk/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.cpp Fri Sep 16 20:05:03 2011 @@ -574,7 +574,11 @@ nub_addr_t addr = 0; uint32_t hw_index = GetHardwareWatchpointHit(addr); if (hw_index != INVALID_NUB_HW_INDEX) + { exc.exc_data[1] = addr; + // Piggyback the hw_index in the exc.data. + exc.exc_data.push_back(hw_index); + } return true; } From gclayton at apple.com Sat Sep 17 00:45:35 2011 From: gclayton at apple.com (Greg Clayton) Date: Sat, 17 Sep 2011 05:45:35 -0000 Subject: [Lldb-commits] [lldb] r139980 - /lldb/trunk/scripts/disasm-gdb-remote.pl Message-ID: <20110917054536.0B0512A6C12C@llvm.org> Author: gclayton Date: Sat Sep 17 00:45:35 2011 New Revision: 139980 URL: http://llvm.org/viewvc/llvm-project?rev=139980&view=rev Log: Make sure to print out register names when reading registers and also be able to display 256 byte registers. Modified: lldb/trunk/scripts/disasm-gdb-remote.pl Modified: lldb/trunk/scripts/disasm-gdb-remote.pl URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/disasm-gdb-remote.pl?rev=139980&r1=139979&r2=139980&view=diff ============================================================================== --- lldb/trunk/scripts/disasm-gdb-remote.pl (original) +++ lldb/trunk/scripts/disasm-gdb-remote.pl Sat Sep 17 00:45:35 2011 @@ -20,6 +20,7 @@ our $reg64_href = { extract => \&get64, format => "0x%s" }; our $reg80_href = { extract => \&get80, format => "0x%s" }; our $reg128_href = { extract => \&get128, format => "0x%s" }; +our $reg256_href = { extract => \&get256, format => "0x%s" }; our $float32_href = { extract => \&get32, format => "0x%8.8x" }; our $float64_href = { extract => \&get64, format => "0x%s" }; our $float96_href = { extract => \&get96, format => "0x%s" }; @@ -770,9 +771,12 @@ { if ($byte_size == 4) {push @$registers_aref, { name => $reg_name, info => $reg32_href };} elsif ($byte_size == 8) {push @$registers_aref, { name => $reg_name, info => $reg64_href };} + elsif ($byte_size == 1) {push @$registers_aref, { name => $reg_name, info => $reg8_href };} + elsif ($byte_size == 2) {push @$registers_aref, { name => $reg_name, info => $reg16_href };} elsif ($byte_size == 10) {push @$registers_aref, { name => $reg_name, info => $reg80_href };} elsif ($byte_size == 12) {push @$registers_aref, { name => $reg_name, info => $float96_href };} elsif ($byte_size == 16) {push @$registers_aref, { name => $reg_name, info => $reg128_href };} + elsif ($byte_size == 32) {push @$registers_aref, { name => $reg_name, info => $reg256_href };} } } elsif ($gen_query_rsp_len == 3 and index($gen_query_rsp, 'E') == 0) @@ -964,9 +968,9 @@ sub dump_read_single_register_cmd { my $cmd = shift; - my $reg_num = get_hex(\@_); + $reg_cmd_reg = get_hex(\@_); my $thread = get_thread_from_thread_suffix (\@_); - my $reg_href = $$registers_aref[$reg_num]; + my $reg_href = $$registers_aref[$reg_cmd_reg]; if (defined $thread) { @@ -1455,7 +1459,7 @@ } else { - (@nibbles) = splice(@$arrayref, 0, 24); + (@nibbles) = splice(@$arrayref, 0, ((64/8) * 2)); } $val = join('', @nibbles); return $val; @@ -1488,7 +1492,7 @@ } else { - (@nibbles) = splice(@$arrayref, 0, 24); + (@nibbles) = splice(@$arrayref, 0, ((80/8) * 2)); } $val = join('', @nibbles); return $val; @@ -1523,7 +1527,7 @@ } else { - (@nibbles) = splice(@$arrayref, 0, 24); + (@nibbles) = splice(@$arrayref, 0, ((96/8) * 2)); } $val = join('', @nibbles); return $val; @@ -1562,7 +1566,62 @@ } else { - (@nibbles) = splice(@$arrayref, 0, 24); + (@nibbles) = splice(@$arrayref, 0, ((128/8) * 2)); + } + $val = join('', @nibbles); + return $val; +} + +#---------------------------------------------------------------------- +# Get a 256 bit hex value as a string +# +# The argument for this function needs to be a reference to an array +# that contains single character strings and the array will get +# updated by shifting characters off the front of it (no leading # "0x") +#---------------------------------------------------------------------- +sub get256 +{ + my $arrayref = shift; + my $val = ''; + my @nibbles; + if ($swap) + { + push @nibbles, splice(@$arrayref, 62, 2); + push @nibbles, splice(@$arrayref, 60, 2); + push @nibbles, splice(@$arrayref, 58, 2); + push @nibbles, splice(@$arrayref, 56, 2); + push @nibbles, splice(@$arrayref, 54, 2); + push @nibbles, splice(@$arrayref, 52, 2); + push @nibbles, splice(@$arrayref, 50, 2); + push @nibbles, splice(@$arrayref, 48, 2); + push @nibbles, splice(@$arrayref, 46, 2); + push @nibbles, splice(@$arrayref, 44, 2); + push @nibbles, splice(@$arrayref, 42, 2); + push @nibbles, splice(@$arrayref, 40, 2); + push @nibbles, splice(@$arrayref, 38, 2); + push @nibbles, splice(@$arrayref, 36, 2); + push @nibbles, splice(@$arrayref, 34, 2); + push @nibbles, splice(@$arrayref, 32, 2); + push @nibbles, splice(@$arrayref, 30, 2); + push @nibbles, splice(@$arrayref, 28, 2); + push @nibbles, splice(@$arrayref, 26, 2); + push @nibbles, splice(@$arrayref, 24, 2); + push @nibbles, splice(@$arrayref, 22, 2); + push @nibbles, splice(@$arrayref, 20, 2); + push @nibbles, splice(@$arrayref, 18, 2); + push @nibbles, splice(@$arrayref, 16, 2); + push @nibbles, splice(@$arrayref, 14, 2); + push @nibbles, splice(@$arrayref, 12, 2); + push @nibbles, splice(@$arrayref, 10, 2); + push @nibbles, splice(@$arrayref, 8, 2); + push @nibbles, splice(@$arrayref, 6, 2); + push @nibbles, splice(@$arrayref, 4, 2); + push @nibbles, splice(@$arrayref, 2, 2); + push @nibbles, splice(@$arrayref, 0, 2); + } + else + { + (@nibbles) = splice(@$arrayref, 0, ((256/8) * 2)); } $val = join('', @nibbles); return $val; From gclayton at apple.com Sat Sep 17 00:47:56 2011 From: gclayton at apple.com (Greg Clayton) Date: Sat, 17 Sep 2011 05:47:56 -0000 Subject: [Lldb-commits] [lldb] r139981 - /lldb/trunk/tools/debugserver/source/RNBRemote.cpp Message-ID: <20110917054756.1A1D92A6C12C@llvm.org> Author: gclayton Date: Sat Sep 17 00:47:55 2011 New Revision: 139981 URL: http://llvm.org/viewvc/llvm-project?rev=139981&view=rev Log: Correctly handle the when we the 'G' packet fails. There were cases where we were returning no error even though this packet was failing. Modified: lldb/trunk/tools/debugserver/source/RNBRemote.cpp Modified: lldb/trunk/tools/debugserver/source/RNBRemote.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/RNBRemote.cpp?rev=139981&r1=139980&r2=139981&view=diff ============================================================================== --- lldb/trunk/tools/debugserver/source/RNBRemote.cpp (original) +++ lldb/trunk/tools/debugserver/source/RNBRemote.cpp Sat Sep 17 00:47:55 2011 @@ -2480,7 +2480,8 @@ std::vector reg_ctx; reg_ctx.resize(reg_ctx_size); - if (packet.GetHexBytes (®_ctx[0], reg_ctx.size(), 0xcc) == reg_ctx.size()) + const nub_size_t bytes_extracted = packet.GetHexBytes (®_ctx[0], reg_ctx.size(), 0xcc); + if (bytes_extracted == reg_ctx.size()) { // Now write the register context reg_ctx_size = DNBThreadSetRegisterContext(pid, tid, reg_ctx.data(), reg_ctx.size()); @@ -2489,7 +2490,14 @@ else return SendPacket ("E55"); } + else + { + DNBLogError("RNBRemote::HandlePacket_G(%s): extracted %zu of %zu bytes, size mismatch\n", p, bytes_extracted, reg_ctx_size); + return SendPacket ("E64"); + } } + else + return SendPacket ("E65"); } From gclayton at apple.com Sat Sep 17 00:59:38 2011 From: gclayton at apple.com (Greg Clayton) Date: Sat, 17 Sep 2011 05:59:38 -0000 Subject: [Lldb-commits] [lldb] r139982 - in /lldb/trunk/tools/debugserver/source/MacOSX: i386/DNBArchImplI386.cpp i386/DNBArchImplI386.h x86_64/DNBArchImplX86_64.cpp x86_64/DNBArchImplX86_64.h Message-ID: <20110917055938.324D32A6C12C@llvm.org> Author: gclayton Date: Sat Sep 17 00:59:37 2011 New Revision: 139982 URL: http://llvm.org/viewvc/llvm-project?rev=139982&view=rev Log: Added more logging, and renamed FPR to FPU in a the register set/flavor enum. Modified: lldb/trunk/tools/debugserver/source/MacOSX/i386/DNBArchImplI386.cpp lldb/trunk/tools/debugserver/source/MacOSX/i386/DNBArchImplI386.h lldb/trunk/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.cpp lldb/trunk/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.h Modified: lldb/trunk/tools/debugserver/source/MacOSX/i386/DNBArchImplI386.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/MacOSX/i386/DNBArchImplI386.cpp?rev=139982&r1=139981&r2=139982&view=diff ============================================================================== --- lldb/trunk/tools/debugserver/source/MacOSX/i386/DNBArchImplI386.cpp (original) +++ lldb/trunk/tools/debugserver/source/MacOSX/i386/DNBArchImplI386.cpp Sat Sep 17 00:59:37 2011 @@ -463,12 +463,18 @@ if (CPUHasAVX() || FORCE_AVX_REGS) { mach_msg_type_number_t count = e_regSetWordSizeAVX; - m_state.SetError(e_regSetFPU, Read, ::thread_get_state(m_thread->ThreadID(), __i386_AVX_STATE, (thread_state_t)&m_state.context.fpu.avx, &count)); + m_state.SetError (e_regSetFPU, Read, ::thread_get_state(m_thread->ThreadID(), __i386_AVX_STATE, (thread_state_t)&m_state.context.fpu.avx, &count)); + DNBLogThreadedIf (LOG_THREAD, "::thread_get_state (0x%4.4x, %u, &avx, %u (%u passed in)) => 0x%8.8x", + m_thread->ThreadID(), __i386_AVX_STATE, count, e_regSetWordSizeAVX, + m_state.GetError(e_regSetFPU, Read)); } else { - mach_msg_type_number_t count = e_regSetWordSizeFPR; + mach_msg_type_number_t count = e_regSetWordSizeFPU; m_state.SetError(e_regSetFPU, Read, ::thread_get_state(m_thread->ThreadID(), __i386_FLOAT_STATE, (thread_state_t)&m_state.context.fpu.no_avx, &count)); + DNBLogThreadedIf (LOG_THREAD, "::thread_get_state (0x%4.4x, %u, &fpu, %u (%u passed in) => 0x%8.8x", + m_thread->ThreadID(), __i386_FLOAT_STATE, count, e_regSetWordSizeFPU, + m_state.GetError(e_regSetFPU, Read)); } } } @@ -506,7 +512,7 @@ if (CPUHasAVX() || FORCE_AVX_REGS) m_state.SetError(e_regSetFPU, Write, ::thread_set_state(m_thread->ThreadID(), __i386_AVX_STATE, (thread_state_t)&m_state.context.fpu.avx, e_regSetWordSizeAVX)); else - m_state.SetError(e_regSetFPU, Write, ::thread_set_state(m_thread->ThreadID(), __i386_FLOAT_STATE, (thread_state_t)&m_state.context.fpu.no_avx, e_regSetWordSizeFPR)); + m_state.SetError(e_regSetFPU, Write, ::thread_set_state(m_thread->ThreadID(), __i386_FLOAT_STATE, (thread_state_t)&m_state.context.fpu.no_avx, e_regSetWordSizeFPU)); return m_state.GetError(e_regSetFPU, Write); } } @@ -1448,9 +1454,27 @@ size = buf_len; bool force = false; - if (GetGPRState(force) | GetFPUState(force) | GetEXCState(force)) - return 0; - ::memcpy (buf, &m_state.context, size); + kern_return_t kret; + if ((kret = GetGPRState(force)) != KERN_SUCCESS) + { + DNBLogThreadedIf (LOG_THREAD, "DNBArchImplI386::GetRegisterContext (buf = %p, len = %zu) error: GPR regs failed to read: %u ", buf, buf_len, kret); + size = 0; + } + else if ((kret = GetFPUState(force)) != KERN_SUCCESS) + { + DNBLogThreadedIf (LOG_THREAD, "DNBArchImplI386::GetRegisterContext (buf = %p, len = %zu) error: %s regs failed to read: %u", buf, buf_len, CPUHasAVX() ? "AVX" : "FPU", kret); + size = 0; + } + else if ((kret = GetEXCState(force)) != KERN_SUCCESS) + { + DNBLogThreadedIf (LOG_THREAD, "DNBArchImplI386::GetRegisterContext (buf = %p, len = %zu) error: EXC regs failed to read: %u", buf, buf_len, kret); + size = 0; + } + else + { + // Success + ::memcpy (buf, &m_state.context, size); + } } DNBLogThreadedIf (LOG_THREAD, "DNBArchImplI386::GetRegisterContext (buf = %p, len = %zu) => %zu", buf, buf_len, size); // Return the size of the register context even if NULL was passed in @@ -1470,9 +1494,13 @@ size = buf_len; ::memcpy (&m_state.context, buf, size); - SetGPRState(); - SetFPUState(); - SetEXCState(); + kern_return_t kret; + if ((kret = SetGPRState()) != KERN_SUCCESS) + DNBLogThreadedIf (LOG_THREAD, "DNBArchImplI386::SetRegisterContext (buf = %p, len = %zu) error: GPR regs failed to write: %u", buf, buf_len, kret); + if ((kret = SetFPUState()) != KERN_SUCCESS) + DNBLogThreadedIf (LOG_THREAD, "DNBArchImplI386::SetRegisterContext (buf = %p, len = %zu) error: %s regs failed to write: %u", buf, buf_len, CPUHasAVX() ? "AVX" : "FPU", kret); + if ((kret = SetEXCState()) != KERN_SUCCESS) + DNBLogThreadedIf (LOG_THREAD, "DNBArchImplI386::SetRegisterContext (buf = %p, len = %zu) error: EXP regs failed to write: %u", buf, buf_len, kret); } DNBLogThreadedIf (LOG_THREAD, "DNBArchImplI386::SetRegisterContext (buf = %p, len = %zu) => %zu", buf, buf_len, size); return size; Modified: lldb/trunk/tools/debugserver/source/MacOSX/i386/DNBArchImplI386.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/MacOSX/i386/DNBArchImplI386.h?rev=139982&r1=139981&r2=139982&view=diff ============================================================================== --- lldb/trunk/tools/debugserver/source/MacOSX/i386/DNBArchImplI386.h (original) +++ lldb/trunk/tools/debugserver/source/MacOSX/i386/DNBArchImplI386.h Sat Sep 17 00:59:37 2011 @@ -92,7 +92,7 @@ typedef enum RegisterSetWordSizeTag { e_regSetWordSizeGPR = sizeof(GPR) / sizeof(int), - e_regSetWordSizeFPR = sizeof(FPU) / sizeof(int), + e_regSetWordSizeFPU = sizeof(FPU) / sizeof(int), e_regSetWordSizeEXC = sizeof(EXC) / sizeof(int), e_regSetWordSizeAVX = sizeof(AVX) / sizeof(int), e_regSetWordSizeDBG = sizeof(DBG) / sizeof(int) Modified: lldb/trunk/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.cpp?rev=139982&r1=139981&r2=139982&view=diff ============================================================================== --- lldb/trunk/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.cpp (original) +++ lldb/trunk/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.cpp Sat Sep 17 00:59:37 2011 @@ -369,11 +369,17 @@ { mach_msg_type_number_t count = e_regSetWordSizeAVX; m_state.SetError(e_regSetFPU, Read, ::thread_get_state(m_thread->ThreadID(), __x86_64_AVX_STATE, (thread_state_t)&m_state.context.fpu.avx, &count)); + DNBLogThreadedIf (LOG_THREAD, "::thread_get_state (0x%4.4x, %u, &avx, %u (%u passed in) carp) => 0x%8.8x", + m_thread->ThreadID(), x86_AVX_STATE64, (uint32_t)count, + e_regSetWordSizeAVX, m_state.GetError(e_regSetFPU, Read)); } else { - mach_msg_type_number_t count = e_regSetWordSizeFPR; + mach_msg_type_number_t count = e_regSetWordSizeFPU; m_state.SetError(e_regSetFPU, Read, ::thread_get_state(m_thread->ThreadID(), __x86_64_FLOAT_STATE, (thread_state_t)&m_state.context.fpu.no_avx, &count)); + DNBLogThreadedIf (LOG_THREAD, "::thread_get_state (0x%4.4x, %u, &fpu, %u (%u passed in) => 0x%8.8x", + m_thread->ThreadID(), __x86_64_FLOAT_STATE, (uint32_t)count, + e_regSetWordSizeFPU, m_state.GetError(e_regSetFPU, Read)); } } } @@ -434,7 +440,7 @@ } else { - m_state.SetError(e_regSetFPU, Write, ::thread_set_state(m_thread->ThreadID(), __x86_64_FLOAT_STATE, (thread_state_t)&m_state.context.fpu.no_avx, e_regSetWordSizeFPR)); + m_state.SetError(e_regSetFPU, Write, ::thread_set_state(m_thread->ThreadID(), __x86_64_FLOAT_STATE, (thread_state_t)&m_state.context.fpu.no_avx, e_regSetWordSizeFPU)); return m_state.GetError(e_regSetFPU, Write); } } @@ -1714,9 +1720,29 @@ size = buf_len; bool force = false; - if (GetGPRState(force) | GetFPUState(force) | GetEXCState(force)) - return 0; - ::memcpy (buf, &m_state.context, size); + kern_return_t kret; + if ((kret = GetGPRState(force)) != KERN_SUCCESS) + { + DNBLogThreadedIf (LOG_THREAD, "DNBArchImplX86_64::GetRegisterContext (buf = %p, len = %zu) error: GPR regs failed to read: %u ", buf, buf_len, kret); + size = 0; + } + else + if ((kret = GetFPUState(force)) != KERN_SUCCESS) + { + DNBLogThreadedIf (LOG_THREAD, "DNBArchImplX86_64::GetRegisterContext (buf = %p, len = %zu) error: %s regs failed to read: %u", buf, buf_len, CPUHasAVX() ? "AVX" : "FPU", kret); + size = 0; + } + else + if ((kret = GetEXCState(force)) != KERN_SUCCESS) + { + DNBLogThreadedIf (LOG_THREAD, "DNBArchImplX86_64::GetRegisterContext (buf = %p, len = %zu) error: EXC regs failed to read: %u", buf, buf_len, kret); + size = 0; + } + else + { + // Success + ::memcpy (buf, &m_state.context, size); + } } DNBLogThreadedIf (LOG_THREAD, "DNBArchImplX86_64::GetRegisterContext (buf = %p, len = %zu) => %zu", buf, buf_len, size); // Return the size of the register context even if NULL was passed in @@ -1736,9 +1762,13 @@ size = buf_len; ::memcpy (&m_state.context, buf, size); - SetGPRState(); - SetFPUState(); - SetEXCState(); + kern_return_t kret; + if ((kret = SetGPRState()) != KERN_SUCCESS) + DNBLogThreadedIf (LOG_THREAD, "DNBArchImplX86_64::SetRegisterContext (buf = %p, len = %zu) error: GPR regs failed to write: %u", buf, buf_len, kret); + if ((kret = SetFPUState()) != KERN_SUCCESS) + DNBLogThreadedIf (LOG_THREAD, "DNBArchImplX86_64::SetRegisterContext (buf = %p, len = %zu) error: %s regs failed to write: %u", buf, buf_len, CPUHasAVX() ? "AVX" : "FPU", kret); + if ((kret = SetEXCState()) != KERN_SUCCESS) + DNBLogThreadedIf (LOG_THREAD, "DNBArchImplX86_64::SetRegisterContext (buf = %p, len = %zu) error: EXP regs failed to write: %u", buf, buf_len, kret); } DNBLogThreadedIf (LOG_THREAD, "DNBArchImplX86_64::SetRegisterContext (buf = %p, len = %zu) => %zu", buf, buf_len, size); return size; Modified: lldb/trunk/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.h?rev=139982&r1=139981&r2=139982&view=diff ============================================================================== --- lldb/trunk/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.h (original) +++ lldb/trunk/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.h Sat Sep 17 00:59:37 2011 @@ -91,7 +91,7 @@ typedef enum RegisterSetWordSizeTag { e_regSetWordSizeGPR = sizeof(GPR) / sizeof(int), - e_regSetWordSizeFPR = sizeof(FPU) / sizeof(int), + e_regSetWordSizeFPU = sizeof(FPU) / sizeof(int), e_regSetWordSizeEXC = sizeof(EXC) / sizeof(int), e_regSetWordSizeAVX = sizeof(AVX) / sizeof(int), e_regSetWordSizeDBG = sizeof(DBG) / sizeof(int) From gclayton at apple.com Sat Sep 17 01:21:21 2011 From: gclayton at apple.com (Greg Clayton) Date: Sat, 17 Sep 2011 06:21:21 -0000 Subject: [Lldb-commits] [lldb] r139983 - in /lldb/trunk: include/lldb/ include/lldb/Core/ include/lldb/Symbol/ include/lldb/Utility/ lldb.xcodeproj/xcshareddata/xcschemes/ source/Commands/ source/Core/ source/Expression/ source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/ source/Symbol/ source/Utility/ tools/debugserver/source/MacOSX/i386/ tools/debugserver/source/MacOSX/x86_64/ Message-ID: <20110917062121.6629E2A6C12C@llvm.org> Author: gclayton Date: Sat Sep 17 01:21:20 2011 New Revision: 139983 URL: http://llvm.org/viewvc/llvm-project?rev=139983&view=rev Log: Convert lldb::ModuleSP to use an instrusive ref counted pointer. We had some cases where getting the shared pointer for a module from the global module list was causing a performance issue when debugging with DWARF in .o files. Now that the module uses intrusive ref counts, we can easily convert any pointer to a shared pointer. Modified: lldb/trunk/include/lldb/Core/Module.h lldb/trunk/include/lldb/Symbol/SymbolContext.h lldb/trunk/include/lldb/Utility/SharingPtr.h lldb/trunk/include/lldb/lldb-forward-rtti.h lldb/trunk/include/lldb/lldb-forward.h lldb/trunk/include/lldb/lldb-types.h lldb/trunk/lldb.xcodeproj/xcshareddata/xcschemes/lldb-tool.xcscheme lldb/trunk/source/Commands/CommandCompletions.cpp lldb/trunk/source/Core/Module.cpp lldb/trunk/source/Expression/ClangASTSource.cpp lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.h lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV1.h lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTrampolineHandler.cpp lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTrampolineHandler.h lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleThreadPlanStepThroughObjCTrampoline.cpp lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleThreadPlanStepThroughObjCTrampoline.h lldb/trunk/source/Symbol/SymbolContext.cpp lldb/trunk/source/Utility/SharingPtr.cpp lldb/trunk/tools/debugserver/source/MacOSX/i386/DNBArchImplI386.cpp lldb/trunk/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.cpp Modified: lldb/trunk/include/lldb/Core/Module.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/Module.h?rev=139983&r1=139982&r2=139983&view=diff ============================================================================== --- lldb/trunk/include/lldb/Core/Module.h (original) +++ lldb/trunk/include/lldb/Core/Module.h Sat Sep 17 01:21:20 2011 @@ -44,6 +44,7 @@ namespace lldb_private { class Module : + public ReferenceCountedBaseVirtual, public SymbolContextScope { public: Modified: lldb/trunk/include/lldb/Symbol/SymbolContext.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Symbol/SymbolContext.h?rev=139983&r1=139982&r2=139983&view=diff ============================================================================== --- lldb/trunk/include/lldb/Symbol/SymbolContext.h (original) +++ lldb/trunk/include/lldb/Symbol/SymbolContext.h Sat Sep 17 01:21:20 2011 @@ -97,6 +97,7 @@ LineEntry *line_entry = NULL, Symbol *symbol = NULL); + ~SymbolContext (); //------------------------------------------------------------------ /// Copy constructor /// @@ -294,13 +295,9 @@ } SpecificationType; // This one produces a specifier that matches everything... - SymbolContextSpecifier (lldb::TargetSP target_sp) : - m_start_line(0), - m_end_line(0) - { - m_target_sp = target_sp; - m_type = eNothingSpecified; - } + SymbolContextSpecifier (const lldb::TargetSP& target_sp); + + ~SymbolContextSpecifier(); bool AddSpecification (const char *spec_string, SpecificationType type); Modified: lldb/trunk/include/lldb/Utility/SharingPtr.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Utility/SharingPtr.h?rev=139983&r1=139982&r2=139983&view=diff ============================================================================== --- lldb/trunk/include/lldb/Utility/SharingPtr.h (original) +++ lldb/trunk/include/lldb/Utility/SharingPtr.h Sat Sep 17 01:21:20 2011 @@ -531,7 +531,282 @@ baton_ = 0; } }; + + +template +class IntrusiveSharingPtr; -} // namespace lldb +template +class ReferenceCountedBase +{ +public: + explicit ReferenceCountedBase(long refs = 0) + : shared_owners_(refs) + { + } + + void + add_shared() + { + __sync_add_and_fetch(&shared_owners_, 1); + } + void + release_shared() + { + if (__sync_add_and_fetch(&shared_owners_, -1) == -1) + delete static_cast(this); + } + + long + use_count() const + { + return shared_owners_ + 1; + } + +protected: + long shared_owners_; + + friend class IntrusiveSharingPtr; + +private: + ReferenceCountedBase(const ReferenceCountedBase&); + ReferenceCountedBase& operator=(const ReferenceCountedBase&); +}; + + +//template +//class ReferenceCountedBaseVirtual +//{ +//public: +// explicit ReferenceCountedBaseVirtual(long refs = 0) : +// shared_owners_(refs) +// { +// } +// +// void +// add_shared(); +// +// void +// release_shared(); +// +// long +// use_count() const +// { +// return shared_owners_ + 1; +// } +// +//protected: +// long shared_owners_; +// +// virtual ~ReferenceCountedBaseVirtual() {} +// +// friend class IntrusiveSharingPtr; +// +//private: +// ReferenceCountedBaseVirtual(const ReferenceCountedBaseVirtual&); +// ReferenceCountedBaseVirtual& operator=(const ReferenceCountedBaseVirtual&); +//}; +// +//template +//void +//ReferenceCountedBaseVirtual::add_shared() +//{ +// __sync_add_and_fetch(&shared_owners_, 1); +//} +// +//template +//void +//ReferenceCountedBaseVirtual::release_shared() +//{ +// if (__sync_add_and_fetch(&shared_owners_, -1) == -1) +// delete this; +//} + + +template +class ReferenceCountedBaseVirtual : public imp::shared_count +{ +public: + explicit ReferenceCountedBaseVirtual () : + imp::shared_count(-1) + { + } + + virtual + ~ReferenceCountedBaseVirtual () + { + } + + virtual void on_zero_shared (); + +}; + +template +void +ReferenceCountedBaseVirtual::on_zero_shared() +{ +} + +template +class IntrusiveSharingPtr +{ +public: + typedef T element_type; + + explicit + IntrusiveSharingPtr () : + ptr_(0) + { + } + + explicit + IntrusiveSharingPtr (T* ptr) : + ptr_(ptr) + { + add_shared(); + } + + IntrusiveSharingPtr (const IntrusiveSharingPtr& rhs) : + ptr_(rhs.ptr_) + { + add_shared(); + } + + template + IntrusiveSharingPtr (const IntrusiveSharingPtr& rhs) + : ptr_(rhs.get()) + { + add_shared(); + } + + IntrusiveSharingPtr& + operator= (const IntrusiveSharingPtr& rhs) + { + reset(rhs.get()); + return *this; + } + + template IntrusiveSharingPtr& + operator= (const IntrusiveSharingPtr& rhs) + { + reset(rhs.get()); + return *this; + } + + IntrusiveSharingPtr& + operator= (T *ptr) + { + reset(ptr); + return *this; + } + + ~IntrusiveSharingPtr() + { + release_shared(); + } + + T& + operator*() const + { + return *ptr_; + } + + T* + operator->() const + { + return ptr_; + } + + T* + get() const + { + return ptr_; + } + + operator bool() const + { + return ptr_ != 0; + } + + void + swap (IntrusiveSharingPtr& rhs) + { + std::swap(ptr_, rhs.ptr_); + } + + void + reset(T* ptr = NULL) + { + IntrusiveSharingPtr(ptr).swap(*this); + } + + long + use_count () const + { + if (ptr_) + return ptr_->use_count(); + return 0; + } + + bool + unique () const + { + return use_count () == 1; + } + +private: + element_type *ptr_; + + void + add_shared() + { + if (ptr_) + ptr_->add_shared(); + } + void + release_shared() + { + if (ptr_) + ptr_->release_shared(); + } +}; + +template +inline bool operator== (const IntrusiveSharingPtr& lhs, const IntrusiveSharingPtr& rhs) +{ + return lhs.get() == rhs.get(); +} + +template +inline bool operator!= (const IntrusiveSharingPtr& lhs, const IntrusiveSharingPtr& rhs) +{ + return lhs.get() != rhs.get(); +} + +template +inline bool operator== (const IntrusiveSharingPtr& lhs, U* rhs) +{ + return lhs.get() == rhs; +} + +template +inline bool operator!= (const IntrusiveSharingPtr& lhs, U* rhs) +{ + return lhs.get() != rhs; +} + +template +inline bool operator== (T* lhs, const IntrusiveSharingPtr& rhs) +{ + return lhs == rhs.get(); +} + +template +inline bool operator!= (T* lhs, const IntrusiveSharingPtr& rhs) +{ + return lhs != rhs.get(); +} + +} // namespace lldb_private #endif // utility_SharingPtr_h_ Modified: lldb/trunk/include/lldb/lldb-forward-rtti.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/lldb-forward-rtti.h?rev=139983&r1=139982&r2=139983&view=diff ============================================================================== --- lldb/trunk/include/lldb/lldb-forward-rtti.h (original) +++ lldb/trunk/include/lldb/lldb-forward-rtti.h Sat Sep 17 01:21:20 2011 @@ -50,7 +50,7 @@ typedef SharedPtr::Type ListenerSP; typedef SharedPtr::Type LogSP; typedef SharedPtr::Type LogChannelSP; - typedef SharedPtr::Type ModuleSP; + typedef IntrusiveSharedPtr::Type ModuleSP; typedef SharedPtr::Type OptionValueSP; typedef SharedPtr::Type PlatformSP; typedef SharedPtr::Type ProcessSP; Modified: lldb/trunk/include/lldb/lldb-forward.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/lldb-forward.h?rev=139983&r1=139982&r2=139983&view=diff ============================================================================== --- lldb/trunk/include/lldb/lldb-forward.h (original) +++ lldb/trunk/include/lldb/lldb-forward.h Sat Sep 17 01:21:20 2011 @@ -48,8 +48,10 @@ class ClangExpressionVariableList; class ClangExpressionVariableList; class ClangExpressionVariables; +class ClangFunction; class ClangPersistentVariables; class ClangUserExpression; +class ClangUtilityFunction; class CommandInterpreter; class CommandObject; class CommandReturnObject; Modified: lldb/trunk/include/lldb/lldb-types.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/lldb-types.h?rev=139983&r1=139982&r2=139983&view=diff ============================================================================== --- lldb/trunk/include/lldb/lldb-types.h (original) +++ lldb/trunk/include/lldb/lldb-types.h Sat Sep 17 01:21:20 2011 @@ -69,6 +69,12 @@ { typedef lldb_private::LoggingSharingPtr<_Tp> Type; }; + + template + struct IntrusiveSharedPtr + { + typedef lldb_private::IntrusiveSharingPtr<_Tp> Type; + }; } // namespace lldb Modified: lldb/trunk/lldb.xcodeproj/xcshareddata/xcschemes/lldb-tool.xcscheme URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/lldb.xcodeproj/xcshareddata/xcschemes/lldb-tool.xcscheme?rev=139983&r1=139982&r2=139983&view=diff ============================================================================== --- lldb/trunk/lldb.xcodeproj/xcshareddata/xcschemes/lldb-tool.xcscheme (original) +++ lldb/trunk/lldb.xcodeproj/xcshareddata/xcschemes/lldb-tool.xcscheme Sat Sep 17 01:21:20 2011 @@ -99,6 +99,12 @@ ReferencedContainer = "container:lldb.xcodeproj"> + + + + GetFileSpec().GetFilename().GetCString(); const char *cur_dir_name = context.module_sp->GetFileSpec().GetDirectory().GetCString(); Modified: lldb/trunk/source/Core/Module.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/Module.cpp?rev=139983&r1=139982&r2=139983&view=diff ============================================================================== --- lldb/trunk/source/Core/Module.cpp (original) +++ lldb/trunk/source/Core/Module.cpp Sat Sep 17 01:21:20 2011 @@ -131,7 +131,8 @@ ModuleSP Module::GetSP () const { - return ModuleList::GetModuleSP (this); + ModuleSP module_sp(const_cast(this)); + return module_sp; } const lldb_private::UUID& Modified: lldb/trunk/source/Expression/ClangASTSource.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/ClangASTSource.cpp?rev=139983&r1=139982&r2=139983&view=diff ============================================================================== --- lldb/trunk/source/Expression/ClangASTSource.cpp (original) +++ lldb/trunk/source/Expression/ClangASTSource.cpp Sat Sep 17 01:21:20 2011 @@ -10,6 +10,7 @@ #include "clang/AST/ASTContext.h" #include "lldb/Core/Log.h" +#include "lldb/Core/Module.h" #include "lldb/Expression/ClangASTSource.h" #include "lldb/Expression/ClangExpression.h" #include "lldb/Expression/ClangExpressionDeclMap.h" Modified: lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.h?rev=139983&r1=139982&r2=139983&view=diff ============================================================================== --- lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.h (original) +++ lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.h Sat Sep 17 01:21:20 2011 @@ -98,7 +98,7 @@ AppleIsModuleObjCLibrary (const lldb::ModuleSP &module_sp); static enum ObjCRuntimeVersions - GetObjCVersion (Process *process, ModuleSP &objc_module_sp); + GetObjCVersion (Process *process, lldb::ModuleSP &objc_module_sp); //------------------------------------------------------------------ // PluginInterface protocol Modified: lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV1.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV1.h?rev=139983&r1=139982&r2=139983&view=diff ============================================================================== --- lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV1.h (original) +++ lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV1.h Sat Sep 17 01:21:20 2011 @@ -15,12 +15,8 @@ // Other libraries and framework includes // Project includes #include "lldb/lldb-private.h" -#include "lldb/Target/LanguageRuntime.h" #include "lldb/Target/ObjCLanguageRuntime.h" -#include "lldb/Core/ValueObject.h" #include "AppleObjCRuntime.h" -#include "AppleObjCTrampolineHandler.h" -#include "AppleThreadPlanStepThroughObjCTrampoline.h" namespace lldb_private { Modified: lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp?rev=139983&r1=139982&r2=139983&view=diff ============================================================================== --- lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp (original) +++ lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp Sat Sep 17 01:21:20 2011 @@ -91,8 +91,9 @@ const char *AppleObjCRuntimeV2::g_objc_class_symbol_prefix = "OBJC_CLASS_$_"; const char *AppleObjCRuntimeV2::g_objc_class_data_section_name = "__objc_data"; -AppleObjCRuntimeV2::AppleObjCRuntimeV2 (Process *process, ModuleSP &objc_module_sp) : - lldb_private::AppleObjCRuntime (process), +AppleObjCRuntimeV2::AppleObjCRuntimeV2 (Process *process, + const ModuleSP &objc_module_sp) : + AppleObjCRuntime (process), m_get_class_name_args(LLDB_INVALID_ADDRESS), m_get_class_name_args_mutex(Mutex::eMutexTypeNormal), m_isa_to_name_cache(), @@ -109,7 +110,7 @@ StreamString errors; - LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP)); // FIXME - a more appropriate log channel? + LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP)); // FIXME - a more appropriate log channel? int32_t debug; if (log) @@ -417,7 +418,7 @@ //------------------------------------------------------------------ // Static Functions //------------------------------------------------------------------ -lldb_private::LanguageRuntime * +LanguageRuntime * AppleObjCRuntimeV2::CreateInstance (Process *process, lldb::LanguageType language) { // FIXME: This should be a MacOS or iOS process, and we need to look for the OBJC section to make @@ -581,7 +582,7 @@ // this code relies on the assumption that an Objective-C object always starts // with an ISA at offset 0. an ISA is effectively a pointer to an instance of // struct class_t in the ObjCv2 runtime -lldb_private::ObjCLanguageRuntime::ObjCISA +ObjCLanguageRuntime::ObjCISA AppleObjCRuntimeV2::GetISA(ValueObject& valobj) { if (ClangASTType::GetMinimumLanguage(valobj.GetClangAST(),valobj.GetClangType()) != lldb::eLanguageTypeObjC) @@ -602,7 +603,7 @@ uint8_t pointer_size = valobj.GetUpdatePoint().GetProcessSP()->GetAddressByteSize(); Error error; - lldb_private::ObjCLanguageRuntime::ObjCISA isa = + ObjCLanguageRuntime::ObjCISA isa = valobj.GetUpdatePoint().GetProcessSP()->ReadUnsignedIntegerFromMemory(isa_pointer, pointer_size, 0, @@ -613,7 +614,7 @@ // TODO: should we have a transparent_kvo parameter here to say if we // want to replace the KVO swizzled class with the actual user-level type? ConstString -AppleObjCRuntimeV2::GetActualTypeName(lldb_private::ObjCLanguageRuntime::ObjCISA isa) +AppleObjCRuntimeV2::GetActualTypeName(ObjCLanguageRuntime::ObjCISA isa) { if (!IsValidISA(isa)) return ConstString(NULL); @@ -713,8 +714,8 @@ return ConstString("unknown"); } -lldb_private::ObjCLanguageRuntime::ObjCISA -AppleObjCRuntimeV2::GetParentClass(lldb_private::ObjCLanguageRuntime::ObjCISA isa) +ObjCLanguageRuntime::ObjCISA +AppleObjCRuntimeV2::GetParentClass(ObjCLanguageRuntime::ObjCISA isa) { if (!IsValidISA(isa)) return 0; Modified: lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h?rev=139983&r1=139982&r2=139983&view=diff ============================================================================== --- lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h (original) +++ lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h Sat Sep 17 01:21:20 2011 @@ -18,12 +18,8 @@ // Other libraries and framework includes // Project includes #include "lldb/lldb-private.h" -#include "lldb/Target/LanguageRuntime.h" #include "lldb/Target/ObjCLanguageRuntime.h" -#include "lldb/Core/ValueObject.h" #include "AppleObjCRuntime.h" -#include "AppleObjCTrampolineHandler.h" -#include "AppleThreadPlanStepThroughObjCTrampoline.h" namespace lldb_private { @@ -81,7 +77,7 @@ GetByteOffsetForIvar (ClangASTType &parent_qual_type, const char *ivar_name); virtual bool - IsValidISA(ObjCISA isa) + IsValidISA (ObjCLanguageRuntime::ObjCISA isa) { return (isa != 0); } @@ -89,28 +85,29 @@ // this is not a valid ISA in the sense that no valid // class pointer can live at address 1. we use it to refer to // tagged types, where the ISA must be dynamically determined - static const ObjCISA g_objc_Tagged_ISA = 1; + static const ObjCLanguageRuntime::ObjCISA g_objc_Tagged_ISA = 1; - virtual ObjCISA + virtual ObjCLanguageRuntime::ObjCISA GetISA(ValueObject& valobj); virtual ConstString - GetActualTypeName(ObjCISA isa); + GetActualTypeName(ObjCLanguageRuntime::ObjCISA isa); - virtual ObjCISA - GetParentClass(ObjCISA isa); + virtual ObjCLanguageRuntime::ObjCISA + GetParentClass(ObjCLanguageRuntime::ObjCISA isa); protected: private: - typedef std::map ISAToNameCache; - typedef std::map ISAToParentCache; + typedef std::map ISAToNameCache; + typedef std::map ISAToParentCache; typedef ISAToNameCache::iterator ISAToNameIterator; typedef ISAToParentCache::iterator ISAToParentIterator; - AppleObjCRuntimeV2(Process *process, ModuleSP &objc_module_sp); + AppleObjCRuntimeV2 (Process *process, + const lldb::ModuleSP &objc_module_sp); bool IsTaggedPointer(lldb::addr_t ptr); Modified: lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTrampolineHandler.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTrampolineHandler.cpp?rev=139983&r1=139982&r2=139983&view=diff ============================================================================== --- lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTrampolineHandler.cpp (original) +++ lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTrampolineHandler.cpp Sat Sep 17 01:21:20 2011 @@ -22,6 +22,10 @@ #include "lldb/Core/Log.h" #include "lldb/Core/Module.h" #include "lldb/Core/Value.h" +#include "lldb/Expression/ClangExpression.h" +#include "lldb/Expression/ClangFunction.h" +#include "lldb/Expression/ClangUtilityFunction.h" + #include "lldb/Symbol/ClangASTContext.h" #include "lldb/Target/ObjCLanguageRuntime.h" #include "lldb/Target/Process.h" @@ -156,6 +160,10 @@ SetUpRegion (); } +AppleObjCTrampolineHandler::~AppleObjCTrampolineHandler() +{ +} + void AppleObjCTrampolineHandler::AppleObjCVTables::VTableRegion::SetUpRegion() { @@ -301,11 +309,12 @@ } } -AppleObjCTrampolineHandler::AppleObjCVTables::AppleObjCVTables (ProcessSP &process_sp, ModuleSP &objc_module_sp) : - m_process_sp(process_sp), - m_trampoline_header(LLDB_INVALID_ADDRESS), - m_trampolines_changed_bp_id(LLDB_INVALID_BREAK_ID), - m_objc_module_sp(objc_module_sp) +AppleObjCTrampolineHandler::AppleObjCVTables::AppleObjCVTables (const ProcessSP &process_sp, + const ModuleSP &objc_module_sp) : + m_process_sp (process_sp), + m_trampoline_header (LLDB_INVALID_ADDRESS), + m_trampolines_changed_bp_id (LLDB_INVALID_BREAK_ID), + m_objc_module_sp (objc_module_sp) { } @@ -510,7 +519,8 @@ {NULL} }; -AppleObjCTrampolineHandler::AppleObjCTrampolineHandler (ProcessSP process_sp, ModuleSP objc_module_sp) : +AppleObjCTrampolineHandler::AppleObjCTrampolineHandler (const ProcessSP &process_sp, + const ModuleSP &objc_module_sp) : m_process_sp (process_sp), m_objc_module_sp (objc_module_sp), m_impl_fn_addr (LLDB_INVALID_ADDRESS), Modified: lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTrampolineHandler.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTrampolineHandler.h?rev=139983&r1=139982&r2=139983&view=diff ============================================================================== --- lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTrampolineHandler.h (original) +++ lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTrampolineHandler.h Sat Sep 17 01:21:20 2011 @@ -13,28 +13,27 @@ // C Includes // C++ Includes #include -#include +#include // Other libraries and framework includes // Project includes -#include "lldb/Expression/ClangExpression.h" -#include "lldb/Expression/ClangFunction.h" -#include "lldb/Expression/ClangUtilityFunction.h" +#include "lldb/lldb-public.h" #include "lldb/Host/Mutex.h" namespace lldb_private { -using namespace lldb; class AppleObjCTrampolineHandler { public: - AppleObjCTrampolineHandler (ProcessSP process_sp, ModuleSP objc_module_sp); + AppleObjCTrampolineHandler (const lldb::ProcessSP &process_sp, + const lldb::ModuleSP &objc_module_sp); - ~AppleObjCTrampolineHandler() {} + ~AppleObjCTrampolineHandler(); - ThreadPlanSP - GetStepThroughDispatchPlan (Thread &thread, bool stop_others); + lldb::ThreadPlanSP + GetStepThroughDispatchPlan (Thread &thread, + bool stop_others); ClangFunction * GetLookupImplementationWrapperFunction (); @@ -80,7 +79,7 @@ private: struct VTableDescriptor { - VTableDescriptor(uint32_t in_flags, addr_t in_code_start) : + VTableDescriptor(uint32_t in_flags, lldb::addr_t in_code_start) : flags(in_flags), code_start(in_code_start) {} @@ -151,7 +150,8 @@ }; public: - AppleObjCVTables(ProcessSP &process_sp, ModuleSP &objc_module_sp); + AppleObjCVTables(const lldb::ProcessSP &process_sp, + const lldb::ModuleSP &objc_module_sp); ~AppleObjCVTables(); @@ -177,7 +177,7 @@ } private: - ProcessSP m_process_sp; + lldb::ProcessSP m_process_sp; typedef std::vector region_collection; lldb::addr_t m_trampoline_header; lldb::break_id_t m_trampolines_changed_bp_id; @@ -190,8 +190,8 @@ typedef std::map MsgsendMap; // This table maps an dispatch fn address to the index in g_dispatch_functions MsgsendMap m_msgSend_map; - ProcessSP m_process_sp; - ModuleSP m_objc_module_sp; + lldb::ProcessSP m_process_sp; + lldb::ModuleSP m_objc_module_sp; std::auto_ptr m_impl_function; std::auto_ptr m_impl_code; Mutex m_impl_function_mutex; Modified: lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleThreadPlanStepThroughObjCTrampoline.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleThreadPlanStepThroughObjCTrampoline.cpp?rev=139983&r1=139982&r2=139983&view=diff ============================================================================== --- lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleThreadPlanStepThroughObjCTrampoline.cpp (original) +++ lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleThreadPlanStepThroughObjCTrampoline.cpp Sat Sep 17 01:21:20 2011 @@ -23,6 +23,8 @@ #include "lldb/Target/ThreadPlanStepOut.h" #include "lldb/Core/Log.h" + +using namespace lldb; using namespace lldb_private; //---------------------------------------------------------------------- Modified: lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleThreadPlanStepThroughObjCTrampoline.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleThreadPlanStepThroughObjCTrampoline.h?rev=139983&r1=139982&r2=139983&view=diff ============================================================================== --- lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleThreadPlanStepThroughObjCTrampoline.h (original) +++ lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleThreadPlanStepThroughObjCTrampoline.h Sat Sep 17 01:21:20 2011 @@ -82,9 +82,9 @@ lldb::addr_t m_object_addr; // This is only for Description. lldb::addr_t m_isa_addr; // isa_addr and sel_addr are the keys we will use to cache the implementation. lldb::addr_t m_sel_addr; - ThreadPlanSP m_func_sp; // This is the function call plan. We fill it at start, then set it - // to NULL when this plan is done. That way we know to go to: - ThreadPlanSP m_run_to_sp; // The plan that runs to the target. + lldb::ThreadPlanSP m_func_sp; // This is the function call plan. We fill it at start, then set it + // to NULL when this plan is done. That way we know to go to: + lldb::ThreadPlanSP m_run_to_sp; // The plan that runs to the target. ClangFunction *m_impl_function; // This is a pointer to a impl function that // is owned by the client that pushes this plan. bool m_stop_others; Modified: lldb/trunk/source/Symbol/SymbolContext.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/SymbolContext.cpp?rev=139983&r1=139982&r2=139983&view=diff ============================================================================== --- lldb/trunk/source/Symbol/SymbolContext.cpp (original) +++ lldb/trunk/source/Symbol/SymbolContext.cpp Sat Sep 17 01:21:20 2011 @@ -82,6 +82,10 @@ sc_scope->CalculateSymbolContext (this); } +SymbolContext::~SymbolContext () +{ +} + const SymbolContext& SymbolContext::operator= (const SymbolContext& rhs) { @@ -447,7 +451,7 @@ // for methods matching name. } - if (module_sp != NULL) + if (module_sp) module_sp->FindFunctions (name, eFunctionNameTypeBase | eFunctionNameTypeFull, include_symbols, true, sc_list); if (target_sp) @@ -489,6 +493,24 @@ // //---------------------------------------------------------------------- +SymbolContextSpecifier::SymbolContextSpecifier (const TargetSP &target_sp) : + m_target_sp (target_sp), + m_module_spec (), + m_module_sp (), + m_file_spec_ap (), + m_start_line (0), + m_end_line (0), + m_function_spec (), + m_class_name (), + m_address_range_ap (), + m_type (eNothingSpecified) +{ +} + +SymbolContextSpecifier::~SymbolContextSpecifier() +{ +} + bool SymbolContextSpecifier::AddLineSpecification (uint32_t line_no, SpecificationType type) { Modified: lldb/trunk/source/Utility/SharingPtr.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Utility/SharingPtr.cpp?rev=139983&r1=139982&r2=139983&view=diff ============================================================================== --- lldb/trunk/source/Utility/SharingPtr.cpp (original) +++ lldb/trunk/source/Utility/SharingPtr.cpp Sat Sep 17 01:21:20 2011 @@ -14,40 +14,42 @@ namespace imp { -template -inline T -increment(T& t) -{ - return __sync_add_and_fetch(&t, 1); -} + template + inline T + increment(T& t) + { + return __sync_add_and_fetch(&t, 1); + } -template -inline T -decrement(T& t) -{ - return __sync_add_and_fetch(&t, -1); -} + template + inline T + decrement(T& t) + { + return __sync_add_and_fetch(&t, -1); + } -shared_count::~shared_count() -{ -} + shared_count::~shared_count() + { + } -void -shared_count::add_shared() -{ - increment(shared_owners_); -} + void + shared_count::add_shared() + { + increment(shared_owners_); + } -void -shared_count::release_shared() -{ - if (decrement(shared_owners_) == -1) + void + shared_count::release_shared() { - on_zero_shared(); - delete this; + if (decrement(shared_owners_) == -1) + { + on_zero_shared(); + delete this; + } } -} } // imp + } // namespace lldb + Modified: lldb/trunk/tools/debugserver/source/MacOSX/i386/DNBArchImplI386.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/MacOSX/i386/DNBArchImplI386.cpp?rev=139983&r1=139982&r2=139983&view=diff ============================================================================== --- lldb/trunk/tools/debugserver/source/MacOSX/i386/DNBArchImplI386.cpp (original) +++ lldb/trunk/tools/debugserver/source/MacOSX/i386/DNBArchImplI386.cpp Sat Sep 17 01:21:20 2011 @@ -252,7 +252,8 @@ gdb_ymm7 = gdb_xmm7 }; -enum DNBArchImplI386::AVXPresence DNBArchImplI386::s_has_avx = DNBArchImplI386::kAVXUnknown; +// AVX support isn't working at all from user space, so disable it for now. +enum DNBArchImplI386::AVXPresence DNBArchImplI386::s_has_avx = DNBArchImplI386::kAVXNotPresent; uint64_t DNBArchImplI386::GetPC(uint64_t failValue) Modified: lldb/trunk/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.cpp?rev=139983&r1=139982&r2=139983&view=diff ============================================================================== --- lldb/trunk/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.cpp (original) +++ lldb/trunk/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.cpp Sat Sep 17 01:21:20 2011 @@ -65,7 +65,7 @@ #define FORCE_AVX_REGS (0) #endif -enum DNBArchImplX86_64::AVXPresence DNBArchImplX86_64::s_has_avx = DNBArchImplX86_64::kAVXUnknown; +enum DNBArchImplX86_64::AVXPresence DNBArchImplX86_64::s_has_avx = DNBArchImplX86_64::kAVXNotPresent; uint64_t DNBArchImplX86_64::GetPC(uint64_t failValue) From gclayton at apple.com Sat Sep 17 02:23:18 2011 From: gclayton at apple.com (Greg Clayton) Date: Sat, 17 Sep 2011 07:23:18 -0000 Subject: [Lldb-commits] [lldb] r139984 - in /lldb/trunk: include/lldb/Core/Module.h source/API/SBAddress.cpp source/Commands/CommandObjectTarget.cpp source/Core/Address.cpp source/Core/Module.cpp source/Core/SearchFilter.cpp source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp source/Symbol/Symbol.cpp source/Target/StackFrame.cpp Message-ID: <20110917072318.590732A6C12C@llvm.org> Author: gclayton Date: Sat Sep 17 02:23:18 2011 New Revision: 139984 URL: http://llvm.org/viewvc/llvm-project?rev=139984&view=rev Log: Removed the function: ModuleSP Module::GetSP(); Since we are now using intrusive ref counts, we can easily turn any pointer to a module into a shared pointer just by assigning it. Modified: lldb/trunk/include/lldb/Core/Module.h lldb/trunk/source/API/SBAddress.cpp lldb/trunk/source/Commands/CommandObjectTarget.cpp lldb/trunk/source/Core/Address.cpp lldb/trunk/source/Core/Module.cpp lldb/trunk/source/Core/SearchFilter.cpp lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp lldb/trunk/source/Symbol/Symbol.cpp lldb/trunk/source/Target/StackFrame.cpp Modified: lldb/trunk/include/lldb/Core/Module.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/Module.h?rev=139984&r1=139983&r2=139984&view=diff ============================================================================== --- lldb/trunk/include/lldb/Core/Module.h (original) +++ lldb/trunk/include/lldb/Core/Module.h Sat Sep 17 02:23:18 2011 @@ -103,13 +103,6 @@ ~Module (); //------------------------------------------------------------------ - /// If you have an instance of Module, get its corresponding shared - /// pointer if it has one in the shared module list. - //------------------------------------------------------------------ - lldb::ModuleSP - GetSP () const; - - //------------------------------------------------------------------ /// @copydoc SymbolContextScope::CalculateSymbolContext(SymbolContext*) /// /// @see SymbolContextScope Modified: lldb/trunk/source/API/SBAddress.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBAddress.cpp?rev=139984&r1=139983&r2=139984&view=diff ============================================================================== --- lldb/trunk/source/API/SBAddress.cpp (original) +++ lldb/trunk/source/API/SBAddress.cpp Sat Sep 17 02:23:18 2011 @@ -221,9 +221,9 @@ SBModule sb_module; if (m_opaque_ap.get()) { - const Module *module = m_opaque_ap->GetModule(); + Module *module = m_opaque_ap->GetModule(); if (module) - *sb_module = module->GetSP(); + *sb_module = module; } return sb_module; } Modified: lldb/trunk/source/Commands/CommandObjectTarget.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectTarget.cpp?rev=139984&r1=139983&r2=139984&view=diff ============================================================================== --- lldb/trunk/source/Commands/CommandObjectTarget.cpp (original) +++ lldb/trunk/source/Commands/CommandObjectTarget.cpp Sat Sep 17 02:23:18 2011 @@ -2725,7 +2725,7 @@ if (use_global_module_list) { module = Module::GetAllocatedModuleAtIndex(image_idx); - module_sp = module->GetSP(); + module_sp = module; } else { Modified: lldb/trunk/source/Core/Address.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/Address.cpp?rev=139984&r1=139983&r2=139984&view=diff ============================================================================== --- lldb/trunk/source/Core/Address.cpp (original) +++ lldb/trunk/source/Core/Address.cpp Sat Sep 17 02:23:18 2011 @@ -737,7 +737,7 @@ Module *address_module = m_section->GetModule(); if (address_module) { - sc->module_sp = address_module->GetSP(); + sc->module_sp = address_module; if (sc->module_sp) return sc->module_sp->ResolveSymbolContextForAddress (*this, resolve_scope, *sc); } @@ -759,7 +759,7 @@ if (m_section) { SymbolContext sc; - sc.module_sp = m_section->GetModule()->GetSP(); + sc.module_sp = m_section->GetModule(); if (sc.module_sp) { sc.module_sp->ResolveSymbolContextForAddress (*this, eSymbolContextCompUnit, sc); @@ -775,7 +775,7 @@ if (m_section) { SymbolContext sc; - sc.module_sp = m_section->GetModule()->GetSP(); + sc.module_sp = m_section->GetModule(); if (sc.module_sp) { sc.module_sp->ResolveSymbolContextForAddress (*this, eSymbolContextFunction, sc); @@ -791,7 +791,7 @@ if (m_section) { SymbolContext sc; - sc.module_sp = m_section->GetModule()->GetSP(); + sc.module_sp = m_section->GetModule(); if (sc.module_sp) { sc.module_sp->ResolveSymbolContextForAddress (*this, eSymbolContextBlock, sc); @@ -807,7 +807,7 @@ if (m_section) { SymbolContext sc; - sc.module_sp = m_section->GetModule()->GetSP(); + sc.module_sp = m_section->GetModule(); if (sc.module_sp) { sc.module_sp->ResolveSymbolContextForAddress (*this, eSymbolContextSymbol, sc); @@ -823,7 +823,7 @@ if (m_section) { SymbolContext sc; - sc.module_sp = m_section->GetModule()->GetSP(); + sc.module_sp = m_section->GetModule(); if (sc.module_sp) { sc.module_sp->ResolveSymbolContextForAddress (*this, eSymbolContextLineEntry, sc); Modified: lldb/trunk/source/Core/Module.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/Module.cpp?rev=139984&r1=139983&r2=139984&view=diff ============================================================================== --- lldb/trunk/source/Core/Module.cpp (original) +++ lldb/trunk/source/Core/Module.cpp Sat Sep 17 02:23:18 2011 @@ -128,13 +128,6 @@ } -ModuleSP -Module::GetSP () const -{ - ModuleSP module_sp(const_cast(this)); - return module_sp; -} - const lldb_private::UUID& Module::GetUUID() { @@ -177,8 +170,8 @@ if (num_comp_units == 0) return; - TargetSP null_target; - SymbolContext sc(null_target, GetSP()); + SymbolContext sc; + sc.module_sp = this; uint32_t cu_idx; SymbolVendor *symbols = GetSymbolVendor (); @@ -212,7 +205,7 @@ void Module::CalculateSymbolContext(SymbolContext* sc) { - sc->module_sp = GetSP(); + sc->module_sp = this; } Module * @@ -282,7 +275,7 @@ { // If the section offset based address resolved itself, then this // is the right module. - sc.module_sp = GetSP(); + sc.module_sp = this; resolved_flags |= eSymbolContextModule; // Resolve the compile unit, function, block, line table or line @@ -384,7 +377,7 @@ const uint32_t start_size = sc_list.GetSize(); const uint32_t num_compile_units = GetNumCompileUnits(); SymbolContext sc; - sc.module_sp = GetSP(); + sc.module_sp = this; const bool compare_directory = path.GetDirectory(); for (uint32_t i=0; iGetImages().GetModulePointerAtIndex(i); if (FileSpec::Compare (m_module_spec, module->GetFileSpec(), false) == 0) { - SymbolContext matchingContext(m_target_sp, module->GetSP()); + SymbolContext matchingContext(m_target_sp, ModuleSP(module)); Searcher::CallbackReturn shouldContinue; shouldContinue = DoModuleIteration(matchingContext, searcher); 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=139984&r1=139983&r2=139984&view=diff ============================================================================== --- lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp (original) +++ lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp Sat Sep 17 02:23:18 2011 @@ -1664,7 +1664,7 @@ { sc.Clear(); // Check if the symbol vendor already knows about this compile unit? - sc.module_sp = m_obj_file->GetModule()->GetSP(); + sc.module_sp = m_obj_file->GetModule(); sc.comp_unit = GetCompUnitForDWARFCompUnit(curr_cu, UINT32_MAX); sc.function = sc.comp_unit->FindFunctionByUID (func_die->GetOffset()).get(); @@ -1969,7 +1969,7 @@ Index (); SymbolContext sc; - sc.module_sp = m_obj_file->GetModule()->GetSP(); + sc.module_sp = m_obj_file->GetModule(); assert (sc.module_sp); DWARFCompileUnit* dwarf_cu = NULL; @@ -2018,7 +2018,7 @@ Index (); SymbolContext sc; - sc.module_sp = m_obj_file->GetModule()->GetSP(); + sc.module_sp = m_obj_file->GetModule(); assert (sc.module_sp); DWARFCompileUnit* dwarf_cu = NULL; @@ -2057,7 +2057,7 @@ const uint32_t sc_list_initial_size = sc_list.GetSize(); SymbolContext sc; - sc.module_sp = m_obj_file->GetModule()->GetSP(); + sc.module_sp = m_obj_file->GetModule(); assert (sc.module_sp); DWARFCompileUnit* dwarf_cu = NULL; @@ -2130,7 +2130,7 @@ return; SymbolContext sc; - sc.module_sp = m_obj_file->GetModule()->GetSP(); + sc.module_sp = m_obj_file->GetModule(); assert (sc.module_sp); DWARFCompileUnit* dwarf_cu = NULL; @@ -2208,7 +2208,7 @@ return; SymbolContext sc; - sc.module_sp = m_obj_file->GetModule()->GetSP(); + sc.module_sp = m_obj_file->GetModule(); assert (sc.module_sp); DWARFCompileUnit* dwarf_cu = NULL; 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=139984&r1=139983&r2=139984&view=diff ============================================================================== --- lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp (original) +++ lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp Sat Sep 17 02:23:18 2011 @@ -168,8 +168,7 @@ FileSpec oso_file_spec(oso_symbol->GetMangled().GetName().AsCString(), true); // Don't allow cached .o files since we dress up each .o file with // new sections. We want them to be in the module list so we can - // always find a shared pointer to the module (in Module::GetSP()), - // but just don't share them. + // always find a shared pointer to the module but just don't share them. const bool always_create = true; ModuleList::GetSharedModule (oso_file_spec, m_obj_file->GetModule()->GetArchitecture(), Modified: lldb/trunk/source/Symbol/Symbol.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/Symbol.cpp?rev=139984&r1=139983&r2=139984&view=diff ============================================================================== --- lldb/trunk/source/Symbol/Symbol.cpp (original) +++ lldb/trunk/source/Symbol/Symbol.cpp Sat Sep 17 02:23:18 2011 @@ -359,7 +359,7 @@ Module *module = range->GetBaseAddress().GetModule (); if (module) { - sc->module_sp = module->GetSP(); + sc->module_sp = module; return; } } Modified: lldb/trunk/source/Target/StackFrame.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/StackFrame.cpp?rev=139984&r1=139983&r2=139984&view=diff ============================================================================== --- lldb/trunk/source/Target/StackFrame.cpp (original) +++ lldb/trunk/source/Target/StackFrame.cpp Sat Sep 17 02:23:18 2011 @@ -147,7 +147,7 @@ { if (pc_module) { - m_sc.module_sp = pc_module->GetSP(); + m_sc.module_sp = pc_module; m_flags.Set (eSymbolContextModule); } else @@ -227,7 +227,7 @@ Module *module = section->GetModule(); if (module) { - m_sc.module_sp = module->GetSP(); + m_sc.module_sp = module; if (m_sc.module_sp) m_flags.Set(eSymbolContextModule); } From gclayton at apple.com Sat Sep 17 03:33:24 2011 From: gclayton at apple.com (Greg Clayton) Date: Sat, 17 Sep 2011 08:33:24 -0000 Subject: [Lldb-commits] [lldb] r139985 - in /lldb/trunk: include/lldb/ include/lldb/Breakpoint/ include/lldb/Core/ include/lldb/Target/ include/lldb/Utility/ source/Breakpoint/ source/Commands/ source/Core/ source/Expression/ source/Interpreter/ source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/ source/Target/ source/Utility/ Message-ID: <20110917083328.7FCDA2A6C12D@llvm.org> Author: gclayton Date: Sat Sep 17 03:33:22 2011 New Revision: 139985 URL: http://llvm.org/viewvc/llvm-project?rev=139985&view=rev Log: Adopt the intrusive pointers in: lldb_private::Breakpoint lldb_private::BreakpointLocations lldb_private::BreakpointSite lldb_private::Debugger lldb_private::StackFrame lldb_private::Thread lldb_private::Target Modified: lldb/trunk/include/lldb/Breakpoint/Breakpoint.h lldb/trunk/include/lldb/Breakpoint/BreakpointLocation.h lldb/trunk/include/lldb/Breakpoint/BreakpointOptions.h lldb/trunk/include/lldb/Breakpoint/BreakpointSite.h lldb/trunk/include/lldb/Core/Debugger.h lldb/trunk/include/lldb/Core/ValueObject.h lldb/trunk/include/lldb/Target/StackFrame.h lldb/trunk/include/lldb/Target/Target.h lldb/trunk/include/lldb/Target/Thread.h lldb/trunk/include/lldb/Target/ThreadPlanTestCondition.h lldb/trunk/include/lldb/Utility/SharingPtr.h lldb/trunk/include/lldb/lldb-forward-rtti.h lldb/trunk/source/Breakpoint/Breakpoint.cpp lldb/trunk/source/Breakpoint/BreakpointLocation.cpp lldb/trunk/source/Breakpoint/BreakpointOptions.cpp lldb/trunk/source/Commands/CommandObjectBreakpoint.cpp lldb/trunk/source/Core/Debugger.cpp lldb/trunk/source/Core/SearchFilter.cpp lldb/trunk/source/Expression/ClangExpressionDeclMap.cpp lldb/trunk/source/Interpreter/Options.cpp lldb/trunk/source/Interpreter/ScriptInterpreterPython.cpp lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTrampolineHandler.cpp lldb/trunk/source/Target/Process.cpp lldb/trunk/source/Target/StackFrame.cpp lldb/trunk/source/Target/Target.cpp lldb/trunk/source/Target/Thread.cpp lldb/trunk/source/Target/ThreadPlanTestCondition.cpp lldb/trunk/source/Utility/SharingPtr.cpp Modified: lldb/trunk/include/lldb/Breakpoint/Breakpoint.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Breakpoint/Breakpoint.h?rev=139985&r1=139984&r2=139985&view=diff ============================================================================== --- lldb/trunk/include/lldb/Breakpoint/Breakpoint.h (original) +++ lldb/trunk/include/lldb/Breakpoint/Breakpoint.h Sat Sep 17 03:33:22 2011 @@ -74,6 +74,7 @@ /// not by the breakpoint. //---------------------------------------------------------------------- class Breakpoint: + public ReferenceCountedBase, public Stoppoint { public: @@ -514,21 +515,6 @@ InvokeCallback (StoppointCallbackContext *context, lldb::break_id_t bp_loc_id); - //------------------------------------------------------------------ - /// Returns the shared pointer that this breakpoint holds for the - /// breakpoint location passed in as \a bp_loc_ptr. Passing in a - /// breakpoint location that doesn't belong to this breakpoint will - /// cause an assert. - /// - /// Meant to be used by the BreakpointLocation::GetSP() function. - /// - /// @return - /// A copy of the shared pointer for the given location. - //------------------------------------------------------------------ - lldb::BreakpointLocationSP - GetLocationSP (BreakpointLocation *bp_loc_ptr); - - protected: friend class Target; //------------------------------------------------------------------ Modified: lldb/trunk/include/lldb/Breakpoint/BreakpointLocation.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Breakpoint/BreakpointLocation.h?rev=139985&r1=139984&r2=139985&view=diff ============================================================================== --- lldb/trunk/include/lldb/Breakpoint/BreakpointLocation.h (original) +++ lldb/trunk/include/lldb/Breakpoint/BreakpointLocation.h Sat Sep 17 03:33:22 2011 @@ -46,7 +46,9 @@ /// would be useful if you've set options on the locations. //---------------------------------------------------------------------- -class BreakpointLocation : public StoppointLocation +class BreakpointLocation : + public ReferenceCountedBase, + public StoppointLocation { public: Modified: lldb/trunk/include/lldb/Breakpoint/BreakpointOptions.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Breakpoint/BreakpointOptions.h?rev=139985&r1=139984&r2=139985&view=diff ============================================================================== --- lldb/trunk/include/lldb/Breakpoint/BreakpointOptions.h (original) +++ lldb/trunk/include/lldb/Breakpoint/BreakpointOptions.h Sat Sep 17 03:33:22 2011 @@ -116,7 +116,7 @@ /// A thread plan to run to test the condition, or NULL if there is no thread plan. //------------------------------------------------------------------ ThreadPlan *GetThreadPlanToTestCondition (ExecutionContext &exe_ctx, - lldb::BreakpointLocationSP break_loc_sp, + const lldb::BreakpointLocationSP& break_loc_sp, Stream &error); //------------------------------------------------------------------ Modified: lldb/trunk/include/lldb/Breakpoint/BreakpointSite.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Breakpoint/BreakpointSite.h?rev=139985&r1=139984&r2=139985&view=diff ============================================================================== --- lldb/trunk/include/lldb/Breakpoint/BreakpointSite.h (original) +++ lldb/trunk/include/lldb/Breakpoint/BreakpointSite.h Sat Sep 17 03:33:22 2011 @@ -38,7 +38,9 @@ /// site. Breakpoint sites are owned by the process. //---------------------------------------------------------------------- -class BreakpointSite : public StoppointLocation +class BreakpointSite : + public ReferenceCountedBase, + public StoppointLocation { public: Modified: lldb/trunk/include/lldb/Core/Debugger.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/Debugger.h?rev=139985&r1=139984&r2=139985&view=diff ============================================================================== --- lldb/trunk/include/lldb/Core/Debugger.h (original) +++ lldb/trunk/include/lldb/Core/Debugger.h Sat Sep 17 03:33:22 2011 @@ -220,6 +220,7 @@ class Debugger : + public ReferenceCountedBaseVirtual, public UserID, public DebuggerInstanceSettings { @@ -275,6 +276,7 @@ static void Destroy (lldb::DebuggerSP &debugger_sp); + virtual ~Debugger (); void Clear(); Modified: lldb/trunk/include/lldb/Core/ValueObject.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/ValueObject.h?rev=139985&r1=139984&r2=139985&view=diff ============================================================================== --- lldb/trunk/include/lldb/Core/ValueObject.h (original) +++ lldb/trunk/include/lldb/Core/ValueObject.h Sat Sep 17 03:33:22 2011 @@ -351,13 +351,13 @@ ExecutionContextScope * GetExecutionContextScope (); - lldb::TargetSP + const lldb::TargetSP & GetTargetSP () const { return m_target_sp; } - lldb::ProcessSP + const lldb::ProcessSP & GetProcessSP () const { return m_process_sp; Modified: lldb/trunk/include/lldb/Target/StackFrame.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/StackFrame.h?rev=139985&r1=139984&r2=139985&view=diff ============================================================================== --- lldb/trunk/include/lldb/Target/StackFrame.h (original) +++ lldb/trunk/include/lldb/Target/StackFrame.h Sat Sep 17 03:33:22 2011 @@ -27,6 +27,7 @@ namespace lldb_private { class StackFrame : + public ReferenceCountedBaseVirtual, public ExecutionContextScope { public: Modified: lldb/trunk/include/lldb/Target/Target.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/Target.h?rev=139985&r1=139984&r2=139985&view=diff ============================================================================== --- lldb/trunk/include/lldb/Target/Target.h (original) +++ lldb/trunk/include/lldb/Target/Target.h Sat Sep 17 03:33:22 2011 @@ -123,6 +123,7 @@ // Target //---------------------------------------------------------------------- class Target : + public ReferenceCountedBaseVirtual, public Broadcaster, public ExecutionContextScope, public TargetInstanceSettings Modified: lldb/trunk/include/lldb/Target/Thread.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/Thread.h?rev=139985&r1=139984&r2=139985&view=diff ============================================================================== --- lldb/trunk/include/lldb/Target/Thread.h (original) +++ lldb/trunk/include/lldb/Target/Thread.h Sat Sep 17 03:33:22 2011 @@ -85,6 +85,7 @@ }; class Thread : + public ReferenceCountedBaseVirtual, public UserID, public ExecutionContextScope, public ThreadInstanceSettings Modified: lldb/trunk/include/lldb/Target/ThreadPlanTestCondition.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/ThreadPlanTestCondition.h?rev=139985&r1=139984&r2=139985&view=diff ============================================================================== --- lldb/trunk/include/lldb/Target/ThreadPlanTestCondition.h (original) +++ lldb/trunk/include/lldb/Target/ThreadPlanTestCondition.h Sat Sep 17 03:33:22 2011 @@ -30,10 +30,10 @@ virtual ~ThreadPlanTestCondition (); ThreadPlanTestCondition (Thread &thread, - ExecutionContext &exe_ctx, - ClangUserExpression *expression, - lldb::BreakpointLocationSP break_loc_sp, - bool stop_others); + ExecutionContext &exe_ctx, + ClangUserExpression *expression, + const lldb::BreakpointLocationSP &break_loc_sp, + bool stop_others); virtual void GetDescription (Stream *s, lldb::DescriptionLevel level); virtual bool ValidatePlan (Stream *error); Modified: lldb/trunk/include/lldb/Utility/SharingPtr.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Utility/SharingPtr.h?rev=139985&r1=139984&r2=139985&view=diff ============================================================================== --- lldb/trunk/include/lldb/Utility/SharingPtr.h (original) +++ lldb/trunk/include/lldb/Utility/SharingPtr.h Sat Sep 17 03:33:22 2011 @@ -16,6 +16,20 @@ namespace lldb_private { namespace imp { + +template +inline T +increment(T& t) +{ + return __sync_add_and_fetch(&t, 1); +} + +template +inline T +decrement(T& t) +{ + return __sync_add_and_fetch(&t, -1); +} class shared_count { @@ -540,22 +554,16 @@ class ReferenceCountedBase { public: - explicit ReferenceCountedBase(long refs = 0) - : shared_owners_(refs) + explicit ReferenceCountedBase() + : shared_owners_(-1) { } void - add_shared() - { - __sync_add_and_fetch(&shared_owners_, 1); - } + add_shared(); + void - release_shared() - { - if (__sync_add_and_fetch(&shared_owners_, -1) == -1) - delete static_cast(this); - } + release_shared(); long use_count() const @@ -573,54 +581,20 @@ ReferenceCountedBase& operator=(const ReferenceCountedBase&); }; + template + void + lldb_private::ReferenceCountedBase::add_shared() + { + imp::increment(shared_owners_); + } -//template -//class ReferenceCountedBaseVirtual -//{ -//public: -// explicit ReferenceCountedBaseVirtual(long refs = 0) : -// shared_owners_(refs) -// { -// } -// -// void -// add_shared(); -// -// void -// release_shared(); -// -// long -// use_count() const -// { -// return shared_owners_ + 1; -// } -// -//protected: -// long shared_owners_; -// -// virtual ~ReferenceCountedBaseVirtual() {} -// -// friend class IntrusiveSharingPtr; -// -//private: -// ReferenceCountedBaseVirtual(const ReferenceCountedBaseVirtual&); -// ReferenceCountedBaseVirtual& operator=(const ReferenceCountedBaseVirtual&); -//}; -// -//template -//void -//ReferenceCountedBaseVirtual::add_shared() -//{ -// __sync_add_and_fetch(&shared_owners_, 1); -//} -// -//template -//void -//ReferenceCountedBaseVirtual::release_shared() -//{ -// if (__sync_add_and_fetch(&shared_owners_, -1) == -1) -// delete this; -//} + template + void + lldb_private::ReferenceCountedBase::release_shared() + { + if (imp::decrement(shared_owners_) == -1) + delete static_cast(this); + } template Modified: lldb/trunk/include/lldb/lldb-forward-rtti.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/lldb-forward-rtti.h?rev=139985&r1=139984&r2=139985&view=diff ============================================================================== --- lldb/trunk/include/lldb/lldb-forward-rtti.h (original) +++ lldb/trunk/include/lldb/lldb-forward-rtti.h Sat Sep 17 03:33:22 2011 @@ -23,9 +23,9 @@ typedef SharedPtr::Type AddressResolverSP; typedef SharedPtr::Type BatonSP; typedef SharedPtr::Type BlockSP; - typedef SharedPtr::Type BreakpointSP; - typedef SharedPtr::Type BreakpointSiteSP; - typedef SharedPtr::Type BreakpointLocationSP; + typedef IntrusiveSharedPtr::Type BreakpointSP; + typedef IntrusiveSharedPtr::Type BreakpointSiteSP; + typedef IntrusiveSharedPtr::Type BreakpointLocationSP; typedef SharedPtr::Type BreakpointResolverSP; typedef SharedPtr::Type BroadcasterSP; typedef SharedPtr::Type ClangExpressionVariableSP; @@ -35,7 +35,7 @@ typedef SharedPtr::Type CompUnitSP; typedef SharedPtr::Type DataBufferSP; typedef SharedPtr::Type DataExtractorSP; - typedef SharedPtr::Type DebuggerSP; + typedef IntrusiveSharedPtr::Type DebuggerSP; typedef SharedPtr::Type DisassemblerSP; typedef SharedPtr::Type DynamicLoaderSP; typedef SharedPtr::Type EventSP; @@ -59,7 +59,7 @@ typedef SharedPtr::Type SectionSP; typedef SharedPtr::Type SearchFilterSP; typedef SharedPtr::Type ScriptFormatSP; - typedef SharedPtr::Type StackFrameSP; + typedef IntrusiveSharedPtr::Type StackFrameSP; typedef SharedPtr::Type StackFrameListSP; typedef SharedPtr::Type StopInfoSP; typedef SharedPtr::Type StoppointLocationSP; @@ -70,8 +70,8 @@ typedef SharedPtr::Type SymbolContextSpecifierSP; typedef SharedPtr::Type SyntheticChildrenSP; typedef SharedPtr::Type SyntheticChildrenFrontEndSP; - typedef SharedPtr::Type TargetSP; - typedef SharedPtr::Type ThreadSP; + typedef IntrusiveSharedPtr::Type TargetSP; + typedef IntrusiveSharedPtr::Type ThreadSP; typedef SharedPtr::Type ThreadPlanSP; typedef SharedPtr::Type ThreadPlanTracerSP; typedef SharedPtr::Type TypeSP; Modified: lldb/trunk/source/Breakpoint/Breakpoint.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Breakpoint/Breakpoint.cpp?rev=139985&r1=139984&r2=139985&view=diff ============================================================================== --- lldb/trunk/source/Breakpoint/Breakpoint.cpp (original) +++ lldb/trunk/source/Breakpoint/Breakpoint.cpp Sat Sep 17 03:33:22 2011 @@ -124,13 +124,6 @@ return m_locations.GetByIndex(index); } -BreakpointLocationSP -Breakpoint::GetLocationSP (BreakpointLocation *bp_loc_ptr) -{ - return m_locations.FindByID(bp_loc_ptr->GetID()); -} - - // For each of the overall options we need to decide how they propagate to // the location options. This will determine the precedence of options on // the breakpoint vrs. its locations. @@ -567,5 +560,7 @@ const BreakpointSP Breakpoint::GetSP () { - return m_target.GetBreakpointList().FindBreakpointByID (GetID()); + // This object contains an instrusive ref count base class so we can + // easily make a shared pointer to this object + return BreakpointSP (this); } Modified: lldb/trunk/source/Breakpoint/BreakpointLocation.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Breakpoint/BreakpointLocation.cpp?rev=139985&r1=139984&r2=139985&view=diff ============================================================================== --- lldb/trunk/source/Breakpoint/BreakpointLocation.cpp (original) +++ lldb/trunk/source/Breakpoint/BreakpointLocation.cpp Sat Sep 17 03:33:22 2011 @@ -149,11 +149,11 @@ ThreadPlan * BreakpointLocation::GetThreadPlanToTestCondition (ExecutionContext &exe_ctx, Stream &error) { - lldb::BreakpointLocationSP my_sp(m_owner.GetLocationSP(this)); + lldb::BreakpointLocationSP this_sp(this); if (m_options_ap.get()) - return m_options_ap->GetThreadPlanToTestCondition (exe_ctx, my_sp, error); + return m_options_ap->GetThreadPlanToTestCondition (exe_ctx, this_sp, error); else - return m_owner.GetThreadPlanToTestCondition (exe_ctx, my_sp, error); + return m_owner.GetThreadPlanToTestCondition (exe_ctx, this_sp, error); } const char * @@ -259,9 +259,9 @@ if (m_owner.GetTarget().GetSectionLoadList().IsEmpty()) return false; - BreakpointLocationSP myself_sp(m_owner.GetLocationSP (this)); + BreakpointLocationSP this_sp(this); - lldb::break_id_t new_id = process->CreateBreakpointSite (myself_sp, false); + lldb::break_id_t new_id = process->CreateBreakpointSite (this_sp, false); if (new_id == LLDB_INVALID_BREAK_ID) { Modified: lldb/trunk/source/Breakpoint/BreakpointOptions.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Breakpoint/BreakpointOptions.cpp?rev=139985&r1=139984&r2=139985&view=diff ============================================================================== --- lldb/trunk/source/Breakpoint/BreakpointOptions.cpp (original) +++ lldb/trunk/source/Breakpoint/BreakpointOptions.cpp Sat Sep 17 03:33:22 2011 @@ -172,7 +172,7 @@ ThreadPlan * BreakpointOptions::GetThreadPlanToTestCondition (ExecutionContext &exe_ctx, - lldb::BreakpointLocationSP break_loc_sp, + const BreakpointLocationSP &break_loc_sp, Stream &error_stream) { // No condition means we should stop, so return NULL. Modified: lldb/trunk/source/Commands/CommandObjectBreakpoint.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectBreakpoint.cpp?rev=139985&r1=139984&r2=139985&view=diff ============================================================================== --- lldb/trunk/source/Commands/CommandObjectBreakpoint.cpp (original) +++ lldb/trunk/source/Commands/CommandObjectBreakpoint.cpp Sat Sep 17 03:33:22 2011 @@ -574,7 +574,7 @@ if (args.GetArgumentCount() == 0) { - if (target->GetLastCreatedBreakpoint() != NULL) + if (target->GetLastCreatedBreakpoint()) { valid_ids->AddBreakpointID (BreakpointID(target->GetLastCreatedBreakpoint()->GetID(), LLDB_INVALID_BREAK_ID)); result.SetStatus (eReturnStatusSuccessFinishNoResult); Modified: lldb/trunk/source/Core/Debugger.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/Debugger.cpp?rev=139985&r1=139984&r2=139985&view=diff ============================================================================== --- lldb/trunk/source/Core/Debugger.cpp (original) +++ lldb/trunk/source/Core/Debugger.cpp Sat Sep 17 03:33:22 2011 @@ -152,7 +152,7 @@ } void -Debugger::Destroy (lldb::DebuggerSP &debugger_sp) +Debugger::Destroy (DebuggerSP &debugger_sp) { if (debugger_sp.get() == NULL) return; @@ -172,29 +172,18 @@ } } -lldb::DebuggerSP +DebuggerSP Debugger::GetSP () { - 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() == this) - { - debugger_sp = *pos; - break; - } - } - return debugger_sp; + // This object contains an instrusive ref count base class so we can + // easily make a shared pointer to this object + return DebuggerSP (this); } -lldb::DebuggerSP +DebuggerSP Debugger::FindDebuggerWithInstanceName (const ConstString &instance_name) { - lldb::DebuggerSP debugger_sp; + DebuggerSP debugger_sp; Mutex::Locker locker (GetDebuggerListMutex ()); DebuggerList &debugger_list = GetDebuggerList(); @@ -214,7 +203,7 @@ TargetSP Debugger::FindTargetWithProcessID (lldb::pid_t pid) { - lldb::TargetSP target_sp; + TargetSP target_sp; Mutex::Locker locker (GetDebuggerListMutex ()); DebuggerList &debugger_list = GetDebuggerList(); DebuggerList::iterator pos, end = debugger_list.end(); @@ -350,7 +339,7 @@ ExecutionContext exe_ctx; exe_ctx.Clear(); - lldb::TargetSP target_sp = GetSelectedTarget(); + TargetSP target_sp = GetSelectedTarget(); exe_ctx.target = target_sp.get(); if (target_sp) @@ -469,7 +458,7 @@ } bool -Debugger::InputReaderIsTopReader (const lldb::InputReaderSP& reader_sp) +Debugger::InputReaderIsTopReader (const InputReaderSP& reader_sp) { InputReaderSP top_reader_sp (GetCurrentInputReader()); @@ -531,7 +520,7 @@ } bool -Debugger::PopInputReader (const lldb::InputReaderSP& pop_reader_sp) +Debugger::PopInputReader (const InputReaderSP& pop_reader_sp) { bool result = false; @@ -627,7 +616,7 @@ DebuggerSP Debugger::FindDebuggerWithID (lldb::user_id_t id) { - lldb::DebuggerSP debugger_sp; + DebuggerSP debugger_sp; Mutex::Locker locker (GetDebuggerListMutex ()); DebuggerList &debugger_list = GetDebuggerList(); @@ -710,7 +699,7 @@ const char* var_name_end, const char** var_name_final, const char** percent_position, - lldb::Format* custom_format, + Format* custom_format, ValueObject::ValueObjectRepresentationStyle* val_obj_display) { LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_TYPES)); @@ -1033,7 +1022,7 @@ if (*var_name_begin == 's') { - valobj = valobj->GetSyntheticValue(lldb::eUseSyntheticFilter).get(); + valobj = valobj->GetSyntheticValue(eUseSyntheticFilter).get(); var_name_begin++; } @@ -1053,7 +1042,7 @@ options.DontCheckDotVsArrowSyntax().DoAllowBitfieldSyntax().DoAllowFragileIVar().DoAllowSyntheticChildren(); ValueObject::ValueObjectRepresentationStyle val_obj_display = ValueObject::eDisplaySummary; ValueObject* target = NULL; - lldb::Format custom_format = eFormatInvalid; + Format custom_format = eFormatInvalid; const char* var_name_final = NULL; const char* var_name_final_if_array_range = NULL; const char* close_bracket_position = NULL; @@ -1847,7 +1836,7 @@ //-------------------------------------------------- Debugger::SettingsController::SettingsController () : - UserSettingsController ("", lldb::UserSettingsControllerSP()) + UserSettingsController ("", UserSettingsControllerSP()) { m_default_settings.reset (new DebuggerInstanceSettings (*this, false, InstanceSettings::GetDefaultName().AsCString())); @@ -1858,12 +1847,12 @@ } -lldb::InstanceSettingsSP +InstanceSettingsSP Debugger::SettingsController::CreateInstanceSettings (const char *instance_name) { DebuggerInstanceSettings *new_settings = new DebuggerInstanceSettings (*GetSettingsController(), false, instance_name); - lldb::InstanceSettingsSP new_settings_sp (new_settings); + InstanceSettingsSP new_settings_sp (new_settings); return new_settings_sp; } @@ -1900,7 +1889,7 @@ if (live_instance) { - const lldb::InstanceSettingsSP &pending_settings = m_owner.FindPendingSettings (m_instance_name); + const InstanceSettingsSP &pending_settings = m_owner.FindPendingSettings (m_instance_name); CopyInstanceSettings (pending_settings, false); } } @@ -1914,7 +1903,7 @@ m_use_external_editor (rhs.m_use_external_editor), m_auto_confirm_on(rhs.m_auto_confirm_on) { - const lldb::InstanceSettingsSP &pending_settings = m_owner.FindPendingSettings (m_instance_name); + const InstanceSettingsSP &pending_settings = m_owner.FindPendingSettings (m_instance_name); CopyInstanceSettings (pending_settings, false); m_owner.RemovePendingSettings (m_instance_name); } @@ -2082,7 +2071,7 @@ } void -DebuggerInstanceSettings::CopyInstanceSettings (const lldb::InstanceSettingsSP &new_settings, +DebuggerInstanceSettings::CopyInstanceSettings (const InstanceSettingsSP &new_settings, bool pending) { if (new_settings.get() == NULL) Modified: lldb/trunk/source/Core/SearchFilter.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/SearchFilter.cpp?rev=139985&r1=139984&r2=139985&view=diff ============================================================================== --- lldb/trunk/source/Core/SearchFilter.cpp (original) +++ lldb/trunk/source/Core/SearchFilter.cpp Sat Sep 17 03:33:22 2011 @@ -131,7 +131,7 @@ { SymbolContext empty_sc; - if (m_target_sp == NULL) + if (!m_target_sp) return; empty_sc.target_sp = m_target_sp; @@ -146,7 +146,7 @@ { SymbolContext empty_sc; - if (m_target_sp == NULL) + if (!m_target_sp) return; empty_sc.target_sp = m_target_sp; Modified: lldb/trunk/source/Expression/ClangExpressionDeclMap.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/ClangExpressionDeclMap.cpp?rev=139985&r1=139984&r2=139985&view=diff ============================================================================== --- lldb/trunk/source/Expression/ClangExpressionDeclMap.cpp (original) +++ lldb/trunk/source/Expression/ClangExpressionDeclMap.cpp Sat Sep 17 03:33:22 2011 @@ -75,9 +75,15 @@ else if (exe_ctx.thread) m_parser_vars->m_sym_ctx = exe_ctx.thread->GetStackFrameAtIndex(0)->GetSymbolContext(lldb::eSymbolContextEverything); else if (exe_ctx.process) - m_parser_vars->m_sym_ctx = SymbolContext(exe_ctx.target->GetSP(), ModuleSP()); + { + m_parser_vars->m_sym_ctx.Clear(); + m_parser_vars->m_sym_ctx.target_sp = exe_ctx.target; + } else if (exe_ctx.target) - m_parser_vars->m_sym_ctx = SymbolContext(exe_ctx.target->GetSP(), ModuleSP()); + { + m_parser_vars->m_sym_ctx.Clear(); + m_parser_vars->m_sym_ctx.target_sp = exe_ctx.target; + } if (exe_ctx.target) m_parser_vars->m_persistent_vars = &exe_ctx.target->GetPersistentVariables(); Modified: lldb/trunk/source/Interpreter/Options.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/Options.cpp?rev=139985&r1=139984&r2=139985&view=diff ============================================================================== --- lldb/trunk/source/Interpreter/Options.cpp (original) +++ lldb/trunk/source/Interpreter/Options.cpp Sat Sep 17 03:33:22 2011 @@ -886,7 +886,7 @@ FileSpec module_spec(module_name, false); lldb::TargetSP target_sp = m_interpreter.GetDebugger().GetSelectedTarget(); // Search filters require a target... - if (target_sp != NULL) + if (target_sp) filter_ap.reset (new SearchFilterByModule (target_sp, module_spec)); } break; Modified: lldb/trunk/source/Interpreter/ScriptInterpreterPython.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/ScriptInterpreterPython.cpp?rev=139985&r1=139984&r2=139985&view=diff ============================================================================== --- lldb/trunk/source/Interpreter/ScriptInterpreterPython.cpp (original) +++ lldb/trunk/source/Interpreter/ScriptInterpreterPython.cpp Sat Sep 17 03:33:22 2011 @@ -19,6 +19,7 @@ #include #include "lldb/API/SBValue.h" +#include "lldb/Breakpoint/BreakpointLocation.h" #include "lldb/Breakpoint/StoppointCallbackContext.h" #include "lldb/Core/Debugger.h" #include "lldb/Core/Timer.h" Modified: lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTrampolineHandler.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTrampolineHandler.cpp?rev=139985&r1=139984&r2=139985&view=diff ============================================================================== --- lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTrampolineHandler.cpp (original) +++ lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTrampolineHandler.cpp Sat Sep 17 03:33:22 2011 @@ -373,7 +373,7 @@ if (changed_addr != LLDB_INVALID_ADDRESS) { BreakpointSP trampolines_changed_bp_sp = target.CreateBreakpoint (changed_addr, true); - if (trampolines_changed_bp_sp != NULL) + if (trampolines_changed_bp_sp) { m_trampolines_changed_bp_id = trampolines_changed_bp_sp->GetID(); trampolines_changed_bp_sp->SetCallback (RefreshTrampolines, this, true); Modified: lldb/trunk/source/Target/Process.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Process.cpp?rev=139985&r1=139984&r2=139985&view=diff ============================================================================== --- lldb/trunk/source/Target/Process.cpp (original) +++ lldb/trunk/source/Target/Process.cpp Sat Sep 17 03:33:22 2011 @@ -1416,22 +1416,22 @@ size_t intersect_size; size_t opcode_offset; size_t idx; - BreakpointSiteSP bp; + BreakpointSiteSP bp_sp; BreakpointSiteList bp_sites_in_range; if (m_breakpoint_site_list.FindInRange (bp_addr, bp_addr + size, bp_sites_in_range)) { - for (idx = 0; (bp = bp_sites_in_range.GetByIndex(idx)) != NULL; ++idx) + for (idx = 0; (bp_sp = bp_sites_in_range.GetByIndex(idx)); ++idx) { - if (bp->GetType() == BreakpointSite::eSoftware) + if (bp_sp->GetType() == BreakpointSite::eSoftware) { - if (bp->IntersectsRange(bp_addr, size, &intersect_addr, &intersect_size, &opcode_offset)) + if (bp_sp->IntersectsRange(bp_addr, size, &intersect_addr, &intersect_size, &opcode_offset)) { assert(bp_addr <= intersect_addr && intersect_addr < bp_addr + size); assert(bp_addr < intersect_addr + intersect_size && intersect_addr + intersect_size <= bp_addr + size); - assert(opcode_offset + intersect_size <= bp->GetByteSize()); + assert(opcode_offset + intersect_size <= bp_sp->GetByteSize()); size_t buf_offset = intersect_addr - bp_addr; - ::memcpy(buf + buf_offset, bp->GetSavedOpcodeBytes() + opcode_offset, intersect_size); + ::memcpy(buf + buf_offset, bp_sp->GetSavedOpcodeBytes() + opcode_offset, intersect_size); } } } Modified: lldb/trunk/source/Target/StackFrame.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/StackFrame.cpp?rev=139985&r1=139984&r2=139985&view=diff ============================================================================== --- lldb/trunk/source/Target/StackFrame.cpp (original) +++ lldb/trunk/source/Target/StackFrame.cpp Sat Sep 17 03:33:22 2011 @@ -41,11 +41,11 @@ StackFrame::StackFrame ( - lldb::user_id_t frame_idx, - lldb::user_id_t unwind_frame_index, + user_id_t frame_idx, + user_id_t unwind_frame_index, Thread &thread, - lldb::addr_t cfa, - lldb::addr_t pc, + addr_t cfa, + addr_t pc, const SymbolContext *sc_ptr ) : m_thread (thread), @@ -71,12 +71,12 @@ StackFrame::StackFrame ( - lldb::user_id_t frame_idx, - lldb::user_id_t unwind_frame_index, + user_id_t frame_idx, + user_id_t unwind_frame_index, Thread &thread, const RegisterContextSP ®_context_sp, - lldb::addr_t cfa, - lldb::addr_t pc, + addr_t cfa, + addr_t pc, const SymbolContext *sc_ptr ) : m_thread (thread), @@ -108,11 +108,11 @@ StackFrame::StackFrame ( - lldb::user_id_t frame_idx, - lldb::user_id_t unwind_frame_index, + user_id_t frame_idx, + user_id_t unwind_frame_index, Thread &thread, const RegisterContextSP ®_context_sp, - lldb::addr_t cfa, + addr_t cfa, const Address& pc_addr, const SymbolContext *sc_ptr ) : @@ -515,9 +515,9 @@ ValueObjectSP StackFrame::GetValueForVariableExpressionPath (const char *var_expr_cstr, - lldb::DynamicValueType use_dynamic, + DynamicValueType use_dynamic, uint32_t options, - lldb::VariableSP &var_sp, + VariableSP &var_sp, Error &error) { @@ -643,7 +643,7 @@ if (!child_valobj_sp) { if (no_synth_child == false) - child_valobj_sp = valobj_sp->GetSyntheticValue(lldb::eUseSyntheticFilter)->GetChildMemberWithName (child_name, true); + child_valobj_sp = valobj_sp->GetSyntheticValue(eUseSyntheticFilter)->GetChildMemberWithName (child_name, true); if (no_synth_child || !child_valobj_sp) { @@ -667,7 +667,7 @@ } // Remove the child name from the path var_path.erase(0, child_name.GetLength()); - if (use_dynamic != lldb::eNoDynamicValues) + if (use_dynamic != eNoDynamicValues) { ValueObjectSP dynamic_value_sp(child_valobj_sp->GetDynamicValue(use_dynamic)); if (dynamic_value_sp) @@ -728,12 +728,12 @@ if (no_synth_child == false && ClangASTType::GetMinimumLanguage(valobj_sp->GetClangAST(), - valobj_sp->GetClangType()) == lldb::eLanguageTypeObjC /* is ObjC pointer */ + valobj_sp->GetClangType()) == eLanguageTypeObjC /* is ObjC pointer */ && ClangASTContext::IsPointerType(ClangASTType::GetPointeeType(valobj_sp->GetClangType())) == false /* is not double-ptr */) { // dereferencing ObjC variables is not valid.. so let's try and recur to synthetic children - lldb::ValueObjectSP synthetic = valobj_sp->GetSyntheticValue(lldb::eUseSyntheticFilter); + ValueObjectSP synthetic = valobj_sp->GetSyntheticValue(eUseSyntheticFilter); if (synthetic.get() == NULL /* no synthetic */ || synthetic == valobj_sp) /* synthetic is the same as the original object */ { @@ -805,7 +805,7 @@ } else { - lldb::ValueObjectSP synthetic = valobj_sp->GetSyntheticValue(lldb::eUseSyntheticFilter); + ValueObjectSP synthetic = valobj_sp->GetSyntheticValue(eUseSyntheticFilter); if (no_synth_child /* synthetic is forbidden */ || synthetic.get() == NULL /* no synthetic */ || synthetic == valobj_sp) /* synthetic is the same as the original object */ @@ -847,7 +847,7 @@ // %i is the array index var_path.erase(0, (end - var_path.c_str()) + 1); separator_idx = var_path.find_first_of(".-["); - if (use_dynamic != lldb::eNoDynamicValues) + if (use_dynamic != eNoDynamicValues) { ValueObjectSP dynamic_value_sp(child_valobj_sp->GetDynamicValue(use_dynamic)); if (dynamic_value_sp) @@ -948,7 +948,7 @@ // %i is the index var_path.erase(0, (real_end - var_path.c_str()) + 1); separator_idx = var_path.find_first_of(".-["); - if (use_dynamic != lldb::eNoDynamicValues) + if (use_dynamic != eNoDynamicValues) { ValueObjectSP dynamic_value_sp(child_valobj_sp->GetDynamicValue(use_dynamic)); if (dynamic_value_sp) @@ -1077,7 +1077,7 @@ ValueObjectSP -StackFrame::GetValueObjectForFrameVariable (const VariableSP &variable_sp, lldb::DynamicValueType use_dynamic) +StackFrame::GetValueObjectForFrameVariable (const VariableSP &variable_sp, DynamicValueType use_dynamic) { ValueObjectSP valobj_sp; VariableList *var_list = GetVariableList (true); @@ -1098,7 +1098,7 @@ } } } - if (use_dynamic != lldb::eNoDynamicValues && valobj_sp) + if (use_dynamic != eNoDynamicValues && valobj_sp) { ValueObjectSP dynamic_sp = valobj_sp->GetDynamicValue (use_dynamic); if (dynamic_sp) @@ -1108,7 +1108,7 @@ } ValueObjectSP -StackFrame::TrackGlobalVariable (const VariableSP &variable_sp, lldb::DynamicValueType use_dynamic) +StackFrame::TrackGlobalVariable (const VariableSP &variable_sp, DynamicValueType use_dynamic) { // Check to make sure we aren't already tracking this variable? ValueObjectSP valobj_sp (GetValueObjectForFrameVariable (variable_sp, use_dynamic)); @@ -1254,10 +1254,12 @@ return false; } -lldb::StackFrameSP +StackFrameSP StackFrame::GetSP () { - return m_thread.GetStackFrameSPForStackFramePtr (this); + // This object contains an instrusive ref count base class so we can + // easily make a shared pointer to this object + return StackFrameSP (this); } Modified: lldb/trunk/source/Target/Target.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Target.cpp?rev=139985&r1=139984&r2=139985&view=diff ============================================================================== --- lldb/trunk/source/Target/Target.cpp (original) +++ lldb/trunk/source/Target/Target.cpp Sat Sep 17 03:33:22 2011 @@ -146,7 +146,9 @@ lldb::TargetSP Target::GetSP() { - return m_debugger.GetTargetList().GetTargetSP(this); + // This object contains an instrusive ref count base class so we can + // easily make a shared pointer to this object + return TargetSP(this); } void Modified: lldb/trunk/source/Target/Thread.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Thread.cpp?rev=139985&r1=139984&r2=139985&view=diff ============================================================================== --- lldb/trunk/source/Target/Thread.cpp (original) +++ lldb/trunk/source/Target/Thread.cpp Sat Sep 17 03:33:22 2011 @@ -970,7 +970,9 @@ lldb::ThreadSP Thread::GetSP () { - return m_process.GetThreadList().GetThreadSPForThreadPtr(this); + // This object contains an instrusive ref count base class so we can + // easily make a shared pointer to this object + return ThreadSP(this); } Modified: lldb/trunk/source/Target/ThreadPlanTestCondition.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/ThreadPlanTestCondition.cpp?rev=139985&r1=139984&r2=139985&view=diff ============================================================================== --- lldb/trunk/source/Target/ThreadPlanTestCondition.cpp (original) +++ lldb/trunk/source/Target/ThreadPlanTestCondition.cpp Sat Sep 17 03:33:22 2011 @@ -37,12 +37,11 @@ // based on the value of \a type. //---------------------------------------------------------------------- -ThreadPlanTestCondition::ThreadPlanTestCondition ( - Thread& thread, - ExecutionContext &exe_ctx, - ClangUserExpression *expression, - lldb::BreakpointLocationSP break_loc_sp, - bool stop_others) : +ThreadPlanTestCondition::ThreadPlanTestCondition (Thread& thread, + ExecutionContext &exe_ctx, + ClangUserExpression *expression, + const BreakpointLocationSP &break_loc_sp, + bool stop_others) : ThreadPlan (ThreadPlan::eKindTestCondition, "test condition", thread, eVoteNoOpinion, eVoteNoOpinion), m_expression (expression), m_exe_ctx (exe_ctx), Modified: lldb/trunk/source/Utility/SharingPtr.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Utility/SharingPtr.cpp?rev=139985&r1=139984&r2=139985&view=diff ============================================================================== --- lldb/trunk/source/Utility/SharingPtr.cpp (original) +++ lldb/trunk/source/Utility/SharingPtr.cpp Sat Sep 17 03:33:22 2011 @@ -14,19 +14,6 @@ namespace imp { - template - inline T - increment(T& t) - { - return __sync_add_and_fetch(&t, 1); - } - - template - inline T - decrement(T& t) - { - return __sync_add_and_fetch(&t, -1); - } shared_count::~shared_count() { From gclayton at apple.com Sun Sep 18 13:59:15 2011 From: gclayton at apple.com (Greg Clayton) Date: Sun, 18 Sep 2011 18:59:15 -0000 Subject: [Lldb-commits] [lldb] r140002 - in /lldb/trunk: include/lldb/ include/lldb/Core/ include/lldb/Symbol/ source/API/ source/Core/ source/Plugins/ObjectContainer/BSD-Archive/ source/Plugins/ObjectContainer/Universal-Mach-O/ source/Plugins/SymbolFile/DWARF/ source/Plugins/SymbolVendor/MacOSX/ source/Symbol/ source/Target/ Message-ID: <20110918185916.1EB7B2A6C12C@llvm.org> Author: gclayton Date: Sun Sep 18 13:59:15 2011 New Revision: 140002 URL: http://llvm.org/viewvc/llvm-project?rev=140002&view=rev Log: Don't put modules for .o files into the global shared module list. We used to do this because we needed to find the shared pointer for a .o file when the .o file's module was needed in a SymbolContext since the module in a symbol context was a shared pointer. Now that we are using intrusive pointers we don't have this limitation anymore since any instrusive shared pointer can be made from a pointer to an object all on its own. Also switched over to having the Module and SymbolVendor use shared pointers to their object files as had a leak on MacOSX when the SymbolVendor's object file wasn't the same as the Module's (debug info in a stand along file (dSYM file)). Now everything will correctly clean itself up when the module goes away after an executable gets rebuilt. Now we correctly get rid of .o files that are used with the DWARF with debug map executables on subsequent runs since the only shared pointer to the object files in from the DWARF symbol file debug map parser, and when the module gets replaced, it destroys to old one along with all .o files. Also added a small optimization when using BSD archives where we will remove old BSD containers from the shared list when they are outdated. Modified: lldb/trunk/include/lldb/Core/Module.h lldb/trunk/include/lldb/Symbol/ObjectContainer.h lldb/trunk/include/lldb/Symbol/ObjectFile.h lldb/trunk/include/lldb/Symbol/SymbolVendor.h lldb/trunk/include/lldb/lldb-forward-rtti.h lldb/trunk/source/API/SBThread.cpp lldb/trunk/source/Core/Disassembler.cpp lldb/trunk/source/Core/Module.cpp lldb/trunk/source/Plugins/ObjectContainer/BSD-Archive/ObjectContainerBSDArchive.cpp lldb/trunk/source/Plugins/ObjectContainer/BSD-Archive/ObjectContainerBSDArchive.h lldb/trunk/source/Plugins/ObjectContainer/Universal-Mach-O/ObjectContainerUniversalMachO.cpp lldb/trunk/source/Plugins/ObjectContainer/Universal-Mach-O/ObjectContainerUniversalMachO.h lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp lldb/trunk/source/Plugins/SymbolVendor/MacOSX/SymbolVendorMacOSX.cpp lldb/trunk/source/Symbol/ObjectFile.cpp lldb/trunk/source/Symbol/SymbolVendor.cpp lldb/trunk/source/Target/Process.cpp Modified: lldb/trunk/include/lldb/Core/Module.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/Module.h?rev=140002&r1=140001&r2=140002&view=diff ============================================================================== --- lldb/trunk/include/lldb/Core/Module.h (original) +++ lldb/trunk/include/lldb/Core/Module.h Sun Sep 18 13:59:15 2011 @@ -654,7 +654,7 @@ FileSpec m_platform_file;///< The path to the module on the platform on which it is being debugged ConstString m_object_name; ///< The name an object within this module that is selected, or empty of the module is represented by \a m_file. uint64_t m_object_offset; - std::auto_ptr m_objfile_ap; ///< A pointer to the object file parser for this module. + lldb::ObjectFileSP m_objfile_sp; ///< A shared pointer to the object file parser for this module as it may or may not be shared with the SymbolFile std::auto_ptr m_symfile_ap; ///< A pointer to the symbol vendor for this module. ClangASTContext m_ast; ///< The AST context for this module. bool m_did_load_objfile:1, Modified: lldb/trunk/include/lldb/Symbol/ObjectContainer.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Symbol/ObjectContainer.h?rev=140002&r1=140001&r2=140002&view=diff ============================================================================== --- lldb/trunk/include/lldb/Symbol/ObjectContainer.h (original) +++ lldb/trunk/include/lldb/Symbol/ObjectContainer.h Sun Sep 18 13:59:15 2011 @@ -188,7 +188,7 @@ /// arch and optional \a name. Returns NULL of no such object /// file exists in the container. //------------------------------------------------------------------ - virtual ObjectFile * + virtual lldb::ObjectFileSP GetObjectFile (const FileSpec *file) = 0; virtual bool Modified: lldb/trunk/include/lldb/Symbol/ObjectFile.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Symbol/ObjectFile.h?rev=140002&r1=140001&r2=140002&view=diff ============================================================================== --- lldb/trunk/include/lldb/Symbol/ObjectFile.h (original) +++ lldb/trunk/include/lldb/Symbol/ObjectFile.h Sun Sep 18 13:59:15 2011 @@ -50,6 +50,7 @@ /// this abstract class. //---------------------------------------------------------------------- class ObjectFile: + public ReferenceCountedBaseVirtual, public PluginInterface, public ModuleChild { @@ -84,19 +85,11 @@ /// supplied upon construction. The at an offset within a file for /// objects that contain more than one architecture or object. //------------------------------------------------------------------ - ObjectFile (Module* module, const FileSpec *file_spec_ptr, lldb::addr_t offset, lldb::addr_t length, lldb::DataBufferSP& headerDataSP) : - ModuleChild (module), - m_file (), // This file could be different from the original module's file - m_type (eTypeInvalid), - m_strata (eStrataInvalid), - m_offset (offset), - m_length (length), - m_data (headerDataSP, lldb::endian::InlHostByteOrder(), 4), - m_unwind_table (*this) - { - if (file_spec_ptr) - m_file = *file_spec_ptr; - } + ObjectFile (Module* module, + const FileSpec *file_spec_ptr, + lldb::addr_t offset, + lldb::addr_t length, + lldb::DataBufferSP& headerDataSP); //------------------------------------------------------------------ /// Destructor. @@ -105,9 +98,10 @@ /// inherited from by the plug-in instance. //------------------------------------------------------------------ virtual - ~ObjectFile() - { - } + ~ObjectFile(); + + lldb::ObjectFileSP + GetSP (); //------------------------------------------------------------------ /// Dump a description of this object to a Stream. @@ -148,7 +142,7 @@ /// /// @see ObjectFile::ParseHeader() //------------------------------------------------------------------ - static ObjectFile* + static lldb::ObjectFileSP FindPlugin (Module* module, const FileSpec* file_spec, lldb::addr_t file_offset, Modified: lldb/trunk/include/lldb/Symbol/SymbolVendor.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Symbol/SymbolVendor.h?rev=140002&r1=140001&r2=140002&view=diff ============================================================================== --- lldb/trunk/include/lldb/Symbol/SymbolVendor.h (original) +++ lldb/trunk/include/lldb/Symbol/SymbolVendor.h Sun Sep 18 13:59:15 2011 @@ -58,7 +58,7 @@ ~SymbolVendor(); void - AddSymbolFileRepresendation(ObjectFile *obj_file); + AddSymbolFileRepresendation(const lldb::ObjectFileSP &objfile_sp); virtual void Dump(Stream *s); @@ -182,6 +182,7 @@ mutable Mutex m_mutex; TypeList m_type_list; // Uniqued types for all parsers owned by this module CompileUnits m_compile_units; // The current compile units + lldb::ObjectFileSP m_objfile_sp; // Keep a reference to the object file in case it isn't the same as the module object file (debug symbols in a separate file) std::auto_ptr m_sym_file_ap; // A single symbol file. Suclasses can add more of these if needed. private: Modified: lldb/trunk/include/lldb/lldb-forward-rtti.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/lldb-forward-rtti.h?rev=140002&r1=140001&r2=140002&view=diff ============================================================================== --- lldb/trunk/include/lldb/lldb-forward-rtti.h (original) +++ lldb/trunk/include/lldb/lldb-forward-rtti.h Sun Sep 18 13:59:15 2011 @@ -51,6 +51,7 @@ typedef SharedPtr::Type LogSP; typedef SharedPtr::Type LogChannelSP; typedef IntrusiveSharedPtr::Type ModuleSP; + typedef IntrusiveSharedPtr::Type ObjectFileSP; typedef SharedPtr::Type OptionValueSP; typedef SharedPtr::Type PlatformSP; typedef SharedPtr::Type ProcessSP; Modified: lldb/trunk/source/API/SBThread.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBThread.cpp?rev=140002&r1=140001&r2=140002&view=diff ============================================================================== --- lldb/trunk/source/API/SBThread.cpp (original) +++ lldb/trunk/source/API/SBThread.cpp Sun Sep 18 13:59:15 2011 @@ -79,7 +79,7 @@ bool SBThread::IsValid() const { - return m_opaque_sp != NULL; + return m_opaque_sp; } void Modified: lldb/trunk/source/Core/Disassembler.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/Disassembler.cpp?rev=140002&r1=140001&r2=140002&view=diff ============================================================================== --- lldb/trunk/source/Core/Disassembler.cpp (original) +++ lldb/trunk/source/Core/Disassembler.cpp Sun Sep 18 13:59:15 2011 @@ -512,7 +512,7 @@ { if (!fgets (buffer, 1023, in_file)) { - out_stream->Printf ("Instruction::ReadArray: Erroe reading file (fgets).\n"); + out_stream->Printf ("Instruction::ReadArray: Error reading file (fgets).\n"); option_value_sp.reset (); return option_value_sp; } Modified: lldb/trunk/source/Core/Module.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/Module.cpp?rev=140002&r1=140001&r2=140002&view=diff ============================================================================== --- lldb/trunk/source/Core/Module.cpp (original) +++ lldb/trunk/source/Core/Module.cpp Sun Sep 18 13:59:15 2011 @@ -68,7 +68,7 @@ m_platform_file(), m_object_name (), m_object_offset (object_offset), - m_objfile_ap (), + m_objfile_sp (), m_symfile_ap (), m_ast (), m_did_load_objfile (false), @@ -124,7 +124,7 @@ // here because symbol files can require the module object file. So we tear // down the symbol file first, then the object file. m_symfile_ap.reset(); - m_objfile_ap.reset(); + m_objfile_sp.reset(); } @@ -636,9 +636,9 @@ m_did_load_objfile = true; Timer scoped_timer(__PRETTY_FUNCTION__, "Module::GetObjectFile () module = %s", GetFileSpec().GetFilename().AsCString("")); - m_objfile_ap.reset(ObjectFile::FindPlugin(this, &m_file, m_object_offset, m_file.GetByteSize())); + m_objfile_sp = ObjectFile::FindPlugin(this, &m_file, m_object_offset, m_file.GetByteSize()); } - return m_objfile_ap.get(); + return m_objfile_sp.get(); } Modified: lldb/trunk/source/Plugins/ObjectContainer/BSD-Archive/ObjectContainerBSDArchive.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ObjectContainer/BSD-Archive/ObjectContainerBSDArchive.cpp?rev=140002&r1=140001&r2=140002&view=diff ============================================================================== --- lldb/trunk/source/Plugins/ObjectContainer/BSD-Archive/ObjectContainerBSDArchive.cpp (original) +++ lldb/trunk/source/Plugins/ObjectContainer/BSD-Archive/ObjectContainerBSDArchive.cpp Sun Sep 18 13:59:15 2011 @@ -160,14 +160,33 @@ Mutex::Locker locker(Archive::GetArchiveCacheMutex ()); shared_ptr archive_sp; Archive::Map &archive_map = Archive::GetArchiveCache (); - Archive::Map::iterator pos; - for (pos = archive_map.find (file); pos != archive_map.end() && pos->first == file; ++pos) + Archive::Map::iterator pos = archive_map.find (file); + // Don't cache a value for "archive_map.end()" below since we might + // delete an archive entry... + while (pos != archive_map.end() && pos->first == file) { - if (pos->second->GetArchitecture() == arch && - pos->second->GetModificationTime() == time) + if (pos->second->GetArchitecture() == arch) { - archive_sp = pos->second; + if (pos->second->GetModificationTime() == time) + { + return pos->second; + } + else + { + // We have a file at the same path with the same architecture + // whose modification time doesn't match. It doesn't make sense + // for us to continue to use this BSD archive since we cache only + // the object info which consists of file time info and also the + // file offset and file size of any contianed objects. Since + // this information is now out of date, we won't get the correct + // information if we go and extract the file data, so we should + // remove the old and outdated entry. + archive_map.erase (pos); + pos = archive_map.find (file); + continue; + } } + ++pos; } return archive_sp; } @@ -266,7 +285,7 @@ // Read everything since we need that in order to index all the // objects in the archive - data_sp = file->ReadFileContents(offset, length); + data_sp = file->MemoryMapFileContents (offset, length); std::auto_ptr container_ap(new ObjectContainerBSDArchive (module, data_sp, file, offset, length)); if (container_ap->ParseHeader()) @@ -363,7 +382,7 @@ s->EOL(); } -ObjectFile * +ObjectFileSP ObjectContainerBSDArchive::GetObjectFile (const FileSpec *file) { if (m_module->GetObjectName() && m_archive_sp) @@ -372,7 +391,7 @@ if (object) return ObjectFile::FindPlugin (m_module, file, m_offset + object->ar_file_offset, object->ar_file_size); } - return NULL; + return ObjectFileSP(); } Modified: lldb/trunk/source/Plugins/ObjectContainer/BSD-Archive/ObjectContainerBSDArchive.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ObjectContainer/BSD-Archive/ObjectContainerBSDArchive.h?rev=140002&r1=140001&r2=140002&view=diff ============================================================================== --- lldb/trunk/source/Plugins/ObjectContainer/BSD-Archive/ObjectContainerBSDArchive.h (original) +++ lldb/trunk/source/Plugins/ObjectContainer/BSD-Archive/ObjectContainerBSDArchive.h Sun Sep 18 13:59:15 2011 @@ -63,10 +63,17 @@ virtual bool ParseHeader (); + virtual size_t + GetNumObjects () const + { + if (m_archive_sp) + return m_archive_sp->GetNumObjects(); + return 0; + } virtual void Dump (lldb_private::Stream *s) const; - virtual lldb_private::ObjectFile * + virtual lldb::ObjectFileSP GetObjectFile (const lldb_private::FileSpec *file); //------------------------------------------------------------------ @@ -101,6 +108,7 @@ uint32_t ar_size; // size in bytes uint32_t ar_file_offset; // file offset in bytes from the beginning of the file of the object data uint32_t ar_file_size; // length of the object data + lldb::ObjectFileSP object_file_sp; typedef std::vector collection; typedef collection::iterator iterator; @@ -136,6 +144,12 @@ ~Archive (); size_t + GetNumObjects () const + { + return m_objects.size(); + } + + size_t ParseObjects (lldb_private::DataExtractor &data); Object * @@ -152,6 +166,9 @@ { return m_arch; } + + bool + HasNoExternalReferences() const; protected: Modified: lldb/trunk/source/Plugins/ObjectContainer/Universal-Mach-O/ObjectContainerUniversalMachO.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ObjectContainer/Universal-Mach-O/ObjectContainerUniversalMachO.cpp?rev=140002&r1=140001&r2=140002&view=diff ============================================================================== --- lldb/trunk/source/Plugins/ObjectContainer/Universal-Mach-O/ObjectContainerUniversalMachO.cpp (original) +++ lldb/trunk/source/Plugins/ObjectContainer/Universal-Mach-O/ObjectContainerUniversalMachO.cpp Sun Sep 18 13:59:15 2011 @@ -196,7 +196,7 @@ return false; } -ObjectFile * +ObjectFileSP ObjectContainerUniversalMachO::GetObjectFile (const FileSpec *file) { uint32_t arch_idx = 0; @@ -219,11 +219,14 @@ { if (arch == curr_arch) { - return ObjectFile::FindPlugin (m_module, file, m_offset + m_fat_archs[arch_idx].offset, m_fat_archs[arch_idx].size); + return ObjectFile::FindPlugin (m_module, + file, + m_offset + m_fat_archs[arch_idx].offset, + m_fat_archs[arch_idx].size); } } } - return NULL; + return ObjectFileSP(); } Modified: lldb/trunk/source/Plugins/ObjectContainer/Universal-Mach-O/ObjectContainerUniversalMachO.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ObjectContainer/Universal-Mach-O/ObjectContainerUniversalMachO.h?rev=140002&r1=140001&r2=140002&view=diff ============================================================================== --- lldb/trunk/source/Plugins/ObjectContainer/Universal-Mach-O/ObjectContainerUniversalMachO.h (original) +++ lldb/trunk/source/Plugins/ObjectContainer/Universal-Mach-O/ObjectContainerUniversalMachO.h Sun Sep 18 13:59:15 2011 @@ -68,7 +68,7 @@ virtual bool GetArchitectureAtIndex (uint32_t cpu_idx, lldb_private::ArchSpec& arch) const; - virtual lldb_private::ObjectFile * + virtual lldb::ObjectFileSP GetObjectFile (const lldb_private::FileSpec *file); //------------------------------------------------------------------ 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=140002&r1=140001&r2=140002&view=diff ============================================================================== --- lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp (original) +++ lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp Sun Sep 18 13:59:15 2011 @@ -166,19 +166,14 @@ if (oso_symbol) { FileSpec oso_file_spec(oso_symbol->GetMangled().GetName().AsCString(), true); - // Don't allow cached .o files since we dress up each .o file with - // new sections. We want them to be in the module list so we can - // always find a shared pointer to the module but just don't share them. - const bool always_create = true; - ModuleList::GetSharedModule (oso_file_spec, - m_obj_file->GetModule()->GetArchitecture(), - NULL, // lldb_private::UUID pointer - NULL, // object name - 0, // object offset - comp_unit_info->oso_module_sp, - NULL, - NULL, - always_create); + // Always create a new module for .o files. Why? Because we + // use the debug map, to add new sections to each .o file and + // even though a .o file might not have changed, the sections + // that get added to the .o file can change. + comp_unit_info->oso_module_sp = new Module (oso_file_spec, + m_obj_file->GetModule()->GetArchitecture(), + NULL, + 0); } } return comp_unit_info->oso_module_sp.get(); Modified: lldb/trunk/source/Plugins/SymbolVendor/MacOSX/SymbolVendorMacOSX.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolVendor/MacOSX/SymbolVendorMacOSX.cpp?rev=140002&r1=140001&r2=140002&view=diff ============================================================================== --- lldb/trunk/source/Plugins/SymbolVendor/MacOSX/SymbolVendorMacOSX.cpp (original) +++ lldb/trunk/source/Plugins/SymbolVendor/MacOSX/SymbolVendorMacOSX.cpp Sun Sep 18 13:59:15 2011 @@ -50,132 +50,6 @@ return false; } - -//ObjectFile * -//LocateDSYMMachFileInDSYMBundle (Module* module, FileSpec& dsym_fspec) -//{ -// ObjectFile *dsym_objfile = NULL; -// -// char path[PATH_MAX]; -// -// if (dsym_fspec.GetPath(path, sizeof(path))) -// { -// size_t path_len = strlen(path); -// const char *bundle_subpath = "/Contents/Resources/DWARF/"; -// if (path_len > 0) -// { -// if (path[path_len-1] == '/') -// ::strncat (path, bundle_subpath + 1, sizeof(path)); -// else -// ::strncat (path, bundle_subpath, sizeof(path)); -// ::strncat (path, dsym_fspec.GetFilename().AsCString(), sizeof(path)); -// -// path_len = strlen(path); -// -// if (::strcasecmp (&path[path_len - strlen(".dSYM")], ".dSYM") == 0) -// { -// path[path_len - ::strlen(".dSYM")] = '\0'; -// dsym_fspec.SetFile(path); -// dsym_objfile = ObjectFile::FindPlugin(module, &dsym_fspec, 0); -// } -// } -// } -// return dsym_objfile; -//} -// -//CFURLRef DBGCopyFullDSYMURLForUUID (CFUUIDRef uuid, CFURLRef exec_url) __attribute__((weak_import)); - - -//ObjectFile * -//FindDSYMUsingDebugSymbols (Module* module, FileSpec& dsym_fspec) -//{ -// Timer scoped_locate("FindDSYMUsingDebugSymbols"); -// dsym_fspec.Clear(); -// ObjectFile *dsym_objfile = NULL; -// if (module->GetUUID().IsValid()) -// { -// // Try and locate the dSYM file using DebugSymbols first -// const UInt8 *module_uuid = (const UInt8 *)module->GetUUID().GetBytes(); -// if (module_uuid != NULL) -// { -// CFUUIDRef module_uuid_ref; -// module_uuid_ref = ::CFUUIDCreateWithBytes ( NULL, -// module_uuid[0], -// module_uuid[1], -// module_uuid[2], -// module_uuid[3], -// module_uuid[4], -// module_uuid[5], -// module_uuid[6], -// module_uuid[7], -// module_uuid[8], -// module_uuid[9], -// module_uuid[10], -// module_uuid[11], -// module_uuid[12], -// module_uuid[13], -// module_uuid[14], -// module_uuid[15]); -// -// if (module_uuid_ref) -// { -// CFURLRef dsym_url = NULL; -// CFURLRef exec_url = NULL; -// -// // if (DBGCopyFullDSYMURLForUUID) -// { -// char exec_path[PATH_MAX]; -// if (module->GetFileSpec().GetPath(exec_path, sizeof(exec_path))) -// { -// exec_url = CFURLCreateFromFileSystemRepresentation ( NULL, -// (const UInt8 *)exec_path, -// strlen(exec_path), -// FALSE); -// } -// -// dsym_url = DBGCopyFullDSYMURLForUUID(module_uuid_ref, exec_url); -// } -// // else -// // { -// // dsym_url = DBGCopyDSYMURLForUUID(module_uuid_ref); -// // } -// -// if (exec_url) -// { -// ::CFRelease (exec_url); -// exec_url = NULL; -// } -// -// ::CFRelease(module_uuid_ref); -// module_uuid_ref = NULL; -// -// if (dsym_url) -// { -// char dsym_path[PATH_MAX]; -// Boolean success = CFURLGetFileSystemRepresentation (dsym_url, true, (UInt8*)dsym_path, sizeof(dsym_path)-1); -// -// ::CFRelease(dsym_url), dsym_url = NULL; -// -// if (success) -// { -// dsym_fspec.SetFile(dsym_path); -// -// // Some newer versions of DebugSymbols will return a full path into a dSYM bundle -// // that points to the correct mach file within the dSYM bundle (MH_DSYM mach file -// // type). -// dsym_objfile = ObjectFile::FindPlugin(module, &dsym_fspec, 0); -// -// // Olders versions of DebugSymbols will return a path to a dSYM bundle. -// if (dsym_objfile == NULL) -// dsym_objfile = LocateDSYMMachFileInDSYMBundle (module, dsym_fspec); -// } -// } -// } -// } -// } -// return dsym_objfile; -//} - static void ReplaceDSYMSectionsWithExecutableSections (ObjectFile *exec_objfile, ObjectFile *dsym_objfile) { @@ -266,7 +140,7 @@ module->GetFileSpec().GetFilename().AsCString()); FileSpec dsym_fspec; - std::auto_ptr dsym_objfile_ap; + ObjectFileSP dsym_objfile_sp; const FileSpec &file_spec = obj_file->GetFileSpec(); if (file_spec) { @@ -274,20 +148,20 @@ if (dsym_fspec) { - dsym_objfile_ap.reset(ObjectFile::FindPlugin(module, &dsym_fspec, 0, dsym_fspec.GetByteSize())); - if (UUIDsMatch(module, dsym_objfile_ap.get())) + dsym_objfile_sp = ObjectFile::FindPlugin(module, &dsym_fspec, 0, dsym_fspec.GetByteSize()); + if (UUIDsMatch(module, dsym_objfile_sp.get())) { - ReplaceDSYMSectionsWithExecutableSections (obj_file, dsym_objfile_ap.get()); - symbol_vendor->AddSymbolFileRepresendation(dsym_objfile_ap.release()); + ReplaceDSYMSectionsWithExecutableSections (obj_file, dsym_objfile_sp.get()); + symbol_vendor->AddSymbolFileRepresendation(dsym_objfile_sp); return symbol_vendor; } } } // Just create our symbol vendor using the current objfile as this is either - // an executable with no dSYM (that we could locate), and executable with - // a dSYM that has a UUID that doesn't match, or it is a dSYM file itself. - symbol_vendor->AddSymbolFileRepresendation(obj_file); + // an executable with no dSYM (that we could locate), an executable with + // a dSYM that has a UUID that doesn't match. + symbol_vendor->AddSymbolFileRepresendation(obj_file->GetSP()); } } return symbol_vendor; Modified: lldb/trunk/source/Symbol/ObjectFile.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/ObjectFile.cpp?rev=140002&r1=140001&r2=140002&view=diff ============================================================================== --- lldb/trunk/source/Symbol/ObjectFile.cpp (original) +++ lldb/trunk/source/Symbol/ObjectFile.cpp Sun Sep 18 13:59:15 2011 @@ -8,6 +8,8 @@ //===----------------------------------------------------------------------===// #include "lldb/lldb-private.h" +#include "lldb/lldb-private-log.h" +#include "lldb/Core/Log.h" #include "lldb/Core/Module.h" #include "lldb/Core/PluginManager.h" #include "lldb/Core/RegularExpression.h" @@ -19,15 +21,15 @@ using namespace lldb; using namespace lldb_private; -ObjectFile* -ObjectFile::FindPlugin (Module* module, const FileSpec* file, lldb::addr_t file_offset, lldb::addr_t file_size) +ObjectFileSP +ObjectFile::FindPlugin (Module* module, const FileSpec* file, addr_t file_offset, addr_t file_size) { Timer scoped_timer (__PRETTY_FUNCTION__, "ObjectFile::FindPlugin (module = %s/%s, file = %p, file_offset = 0x%z8.8x, file_size = 0x%z8.8x)", module->GetFileSpec().GetDirectory().AsCString(), module->GetFileSpec().GetFilename().AsCString(), file, file_offset, file_size); - std::auto_ptr object_file_ap; + ObjectFileSP object_file_sp; if (module != NULL) { @@ -72,9 +74,9 @@ ObjectFileCreateInstance create_object_file_callback; for (idx = 0; (create_object_file_callback = PluginManager::GetObjectFileCreateCallbackAtIndex(idx)) != NULL; ++idx) { - object_file_ap.reset (create_object_file_callback(module, file_header_data_sp, file, file_offset, file_size)); - if (object_file_ap.get()) - return object_file_ap.release(); + object_file_sp.reset (create_object_file_callback(module, file_header_data_sp, file, file_offset, file_size)); + if (object_file_sp.get()) + return object_file_sp; } // Check if this is a object container by iterating through @@ -86,14 +88,87 @@ std::auto_ptr object_container_ap(create_object_container_callback(module, file_header_data_sp, file, file_offset, file_size)); if (object_container_ap.get()) - object_file_ap.reset (object_container_ap->GetObjectFile(file)); + object_file_sp = object_container_ap->GetObjectFile(file); - if (object_file_ap.get()) - return object_file_ap.release(); + if (object_file_sp.get()) + return object_file_sp; } } } - return NULL; + // We didn't find it, so clear our shared pointer in case it + // contains anything and return an empty shared pointer + object_file_sp.reset(); + return object_file_sp; +} + +ObjectFile::ObjectFile (Module* module, + const FileSpec *file_spec_ptr, + addr_t offset, + addr_t length, + DataBufferSP& headerDataSP) : + ModuleChild (module), + m_file (), // This file could be different from the original module's file + m_type (eTypeInvalid), + m_strata (eStrataInvalid), + m_offset (offset), + m_length (length), + m_data (headerDataSP, endian::InlHostByteOrder(), 4), + m_unwind_table (*this) +{ + if (file_spec_ptr) + m_file = *file_spec_ptr; + LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT)); + if (log) + { + if (m_file) + { + log->Printf ("%p ObjectFile::ObjectFile () module = %s/%s, file = %s/%s, offset = 0x%8.8llx, size = %llu\n", + this, + m_module->GetFileSpec().GetDirectory().AsCString(), + m_module->GetFileSpec().GetFilename().AsCString(), + m_file.GetDirectory().AsCString(), + m_file.GetFilename().AsCString(), + m_offset, + m_length); + } + else + { + log->Printf ("%p ObjectFile::ObjectFile () module = %s/%s, file = , offset = 0x%8.8llx, size = %llu\n", + this, + m_module->GetFileSpec().GetDirectory().AsCString(), + m_module->GetFileSpec().GetFilename().AsCString(), + m_offset, + m_length); + } + } +} + +ObjectFile::~ObjectFile() +{ + LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT)); + if (log) + { + if (m_file) + { + log->Printf ("%p ObjectFile::~ObjectFile () module = %s/%s, file = %s/%s, offset = 0x%8.8llx, size = %llu\n", + this, + m_module->GetFileSpec().GetDirectory().AsCString(), + m_module->GetFileSpec().GetFilename().AsCString(), + m_file.GetDirectory().AsCString(), + m_file.GetFilename().AsCString(), + m_offset, + m_length); + } + else + { + log->Printf ("%p ObjectFile::~ObjectFile () module = %s/%s, file = , offset = 0x%8.8llx, size = %llu\n", + this, + m_module->GetFileSpec().GetDirectory().AsCString(), + m_module->GetFileSpec().GetFilename().AsCString(), + m_offset, + m_length); + } + } } bool @@ -103,7 +178,7 @@ } AddressClass -ObjectFile::GetAddressClass (lldb::addr_t file_addr) +ObjectFile::GetAddressClass (addr_t file_addr) { Symtab *symtab = GetSymtab(); if (symtab) @@ -188,4 +263,12 @@ return eAddressClassUnknown; } +ObjectFileSP +ObjectFile::GetSP () +{ + // This object contains an instrusive ref count base class so we can + // easily make a shared pointer to this object + return ObjectFileSP (this); +} + Modified: lldb/trunk/source/Symbol/SymbolVendor.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/SymbolVendor.cpp?rev=140002&r1=140001&r2=140002&view=diff ============================================================================== --- lldb/trunk/source/Symbol/SymbolVendor.cpp (original) +++ lldb/trunk/source/Symbol/SymbolVendor.cpp Sun Sep 18 13:59:15 2011 @@ -55,7 +55,11 @@ // file representation for the module. instance_ap.reset(new SymbolVendor(module)); if (instance_ap.get()) - instance_ap->AddSymbolFileRepresendation(module->GetObjectFile()); + { + ObjectFile *objfile = module->GetObjectFile(); + if (objfile) + instance_ap->AddSymbolFileRepresendation(objfile->GetSP()); + } return instance_ap.release(); } @@ -82,11 +86,14 @@ // Add a represantion given an object file. //---------------------------------------------------------------------- void -SymbolVendor::AddSymbolFileRepresendation(ObjectFile *obj_file) +SymbolVendor::AddSymbolFileRepresendation(const ObjectFileSP &objfile_sp) { Mutex::Locker locker(m_mutex); - if (obj_file != NULL) - m_sym_file_ap.reset(SymbolFile::FindPlugin(obj_file)); + if (objfile_sp) + { + m_objfile_sp = objfile_sp; + m_sym_file_ap.reset(SymbolFile::FindPlugin(objfile_sp.get())); + } } bool Modified: lldb/trunk/source/Target/Process.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Process.cpp?rev=140002&r1=140001&r2=140002&view=diff ============================================================================== --- lldb/trunk/source/Target/Process.cpp (original) +++ lldb/trunk/source/Target/Process.cpp Sun Sep 18 13:59:15 2011 @@ -3381,7 +3381,7 @@ uint32_t selected_tid; StackID selected_stack_id; - if (selected_thread_sp != NULL) + if (selected_thread_sp) { selected_tid = selected_thread_sp->GetIndexID(); selected_stack_id = selected_thread_sp->GetSelectedFrame()->GetStackID();