2012-02-01 09:46:19 +08:00
|
|
|
//===-- ObjCLanguageRuntime.cpp ---------------------------------*- C++ -*-===//
|
2010-09-23 10:01:19 +08:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
2010-09-30 08:54:27 +08:00
|
|
|
#include "clang/AST/Type.h"
|
2010-09-23 10:01:19 +08:00
|
|
|
|
2010-09-28 09:25:32 +08:00
|
|
|
#include "lldb/Core/Log.h"
|
2013-02-14 06:56:14 +08:00
|
|
|
#include "lldb/Core/MappedHash.h"
|
<rdar://problem/11757916>
Make breakpoint setting by file and line much more efficient by only looking for inlined breakpoint locations if we are setting a breakpoint in anything but a source implementation file. Implementing this complex for a many reasons. Turns out that parsing compile units lazily had some issues with respect to how we need to do things with DWARF in .o files. So the fixes in the checkin for this makes these changes:
- Add a new setting called "target.inline-breakpoint-strategy" which can be set to "never", "always", or "headers". "never" will never try and set any inlined breakpoints (fastest). "always" always looks for inlined breakpoint locations (slowest, but most accurate). "headers", which is the default setting, will only look for inlined breakpoint locations if the breakpoint is set in what are consudered to be header files, which is realy defined as "not in an implementation source file".
- modify the breakpoint setting by file and line to check the current "target.inline-breakpoint-strategy" setting and act accordingly
- Modify compile units to be able to get their language and other info lazily. This allows us to create compile units from the debug map and not have to fill all of the details in, and then lazily discover this information as we go on debuggging. This is needed to avoid parsing all .o files when setting breakpoints in implementation only files (no inlines). Otherwise we would need to parse the .o file, the object file (mach-o in our case) and the symbol file (DWARF in the object file) just to see what the compile unit was.
- modify the "SymbolFileDWARFDebugMap" to subclass lldb_private::Module so that the virtual "GetObjectFile()" and "GetSymbolVendor()" functions can be intercepted when the .o file contenst are later lazilly needed. Prior to this fix, when we first instantiated the "SymbolFileDWARFDebugMap" class, we would also make modules, object files and symbol files for every .o file in the debug map because we needed to fix up the sections in the .o files with information that is in the executable debug map. Now we lazily do this in the DebugMapModule::GetObjectFile()
Cleaned up header includes a bit as well.
llvm-svn: 162860
2012-08-30 05:13:06 +08:00
|
|
|
#include "lldb/Core/Module.h"
|
2010-09-23 10:01:19 +08:00
|
|
|
#include "lldb/Core/PluginManager.h"
|
2013-01-30 08:18:29 +08:00
|
|
|
#include "lldb/Core/Timer.h"
|
2010-09-30 08:54:27 +08:00
|
|
|
#include "lldb/Core/ValueObject.h"
|
|
|
|
#include "lldb/Symbol/ClangASTContext.h"
|
2011-05-03 02:13:59 +08:00
|
|
|
#include "lldb/Symbol/Type.h"
|
<rdar://problem/11757916>
Make breakpoint setting by file and line much more efficient by only looking for inlined breakpoint locations if we are setting a breakpoint in anything but a source implementation file. Implementing this complex for a many reasons. Turns out that parsing compile units lazily had some issues with respect to how we need to do things with DWARF in .o files. So the fixes in the checkin for this makes these changes:
- Add a new setting called "target.inline-breakpoint-strategy" which can be set to "never", "always", or "headers". "never" will never try and set any inlined breakpoints (fastest). "always" always looks for inlined breakpoint locations (slowest, but most accurate). "headers", which is the default setting, will only look for inlined breakpoint locations if the breakpoint is set in what are consudered to be header files, which is realy defined as "not in an implementation source file".
- modify the breakpoint setting by file and line to check the current "target.inline-breakpoint-strategy" setting and act accordingly
- Modify compile units to be able to get their language and other info lazily. This allows us to create compile units from the debug map and not have to fill all of the details in, and then lazily discover this information as we go on debuggging. This is needed to avoid parsing all .o files when setting breakpoints in implementation only files (no inlines). Otherwise we would need to parse the .o file, the object file (mach-o in our case) and the symbol file (DWARF in the object file) just to see what the compile unit was.
- modify the "SymbolFileDWARFDebugMap" to subclass lldb_private::Module so that the virtual "GetObjectFile()" and "GetSymbolVendor()" functions can be intercepted when the .o file contenst are later lazilly needed. Prior to this fix, when we first instantiated the "SymbolFileDWARFDebugMap" class, we would also make modules, object files and symbol files for every .o file in the debug map because we needed to fix up the sections in the .o files with information that is in the executable debug map. Now we lazily do this in the DebugMapModule::GetObjectFile()
Cleaned up header includes a bit as well.
llvm-svn: 162860
2012-08-30 05:13:06 +08:00
|
|
|
#include "lldb/Symbol/TypeList.h"
|
2010-09-28 09:25:32 +08:00
|
|
|
#include "lldb/Target/ObjCLanguageRuntime.h"
|
2012-02-23 07:57:45 +08:00
|
|
|
#include "lldb/Target/Target.h"
|
2010-09-23 10:01:19 +08:00
|
|
|
|
2013-01-30 08:18:29 +08:00
|
|
|
#include "llvm/ADT/StringRef.h"
|
|
|
|
|
2010-09-23 10:01:19 +08:00
|
|
|
using namespace lldb;
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Destructor
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
ObjCLanguageRuntime::~ObjCLanguageRuntime()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ObjCLanguageRuntime::ObjCLanguageRuntime (Process *process) :
|
2012-03-08 10:39:03 +08:00
|
|
|
LanguageRuntime (process),
|
2012-09-15 09:05:12 +08:00
|
|
|
m_has_new_literals_and_indexing (eLazyBoolCalculate),
|
2013-02-14 06:56:14 +08:00
|
|
|
m_isa_to_descriptor(),
|
|
|
|
m_isa_to_descriptor_stop_id (UINT32_MAX)
|
2010-09-23 10:01:19 +08:00
|
|
|
{
|
|
|
|
|
2010-09-28 09:25:32 +08:00
|
|
|
}
|
|
|
|
|
2013-02-14 06:56:14 +08:00
|
|
|
bool
|
|
|
|
ObjCLanguageRuntime::AddClass (ObjCISA isa, const ClassDescriptorSP &descriptor_sp, const char *class_name)
|
|
|
|
{
|
|
|
|
if (isa != 0)
|
|
|
|
{
|
|
|
|
m_isa_to_descriptor[isa] = descriptor_sp;
|
|
|
|
// class_name is assumed to be valid
|
|
|
|
m_hash_to_isa_map.insert(std::make_pair(MappedHash::HashStringUsingDJB(class_name), isa));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-09-28 09:25:32 +08:00
|
|
|
void
|
|
|
|
ObjCLanguageRuntime::AddToMethodCache (lldb::addr_t class_addr, lldb::addr_t selector, lldb::addr_t impl_addr)
|
|
|
|
{
|
2013-03-28 07:08:40 +08:00
|
|
|
Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
|
2010-09-28 09:25:32 +08:00
|
|
|
if (log)
|
|
|
|
{
|
2012-11-30 05:49:15 +08:00
|
|
|
log->Printf ("Caching: class 0x%" PRIx64 " selector 0x%" PRIx64 " implementation 0x%" PRIx64 ".", class_addr, selector, impl_addr);
|
2010-09-28 09:25:32 +08:00
|
|
|
}
|
|
|
|
m_impl_cache.insert (std::pair<ClassAndSel,lldb::addr_t> (ClassAndSel(class_addr, selector), impl_addr));
|
|
|
|
}
|
|
|
|
|
|
|
|
lldb::addr_t
|
|
|
|
ObjCLanguageRuntime::LookupInMethodCache (lldb::addr_t class_addr, lldb::addr_t selector)
|
|
|
|
{
|
|
|
|
MsgImplMap::iterator pos, end = m_impl_cache.end();
|
|
|
|
pos = m_impl_cache.find (ClassAndSel(class_addr, selector));
|
|
|
|
if (pos != end)
|
|
|
|
return (*pos).second;
|
|
|
|
return LLDB_INVALID_ADDRESS;
|
|
|
|
}
|
2011-05-03 02:13:59 +08:00
|
|
|
|
2011-06-25 06:03:24 +08:00
|
|
|
|
2012-02-23 07:57:45 +08:00
|
|
|
lldb::TypeSP
|
|
|
|
ObjCLanguageRuntime::LookupInCompleteClassCache (ConstString &name)
|
|
|
|
{
|
|
|
|
CompleteClassMap::iterator complete_class_iter = m_complete_class_cache.find(name);
|
|
|
|
|
|
|
|
if (complete_class_iter != m_complete_class_cache.end())
|
|
|
|
{
|
2012-10-24 06:41:19 +08:00
|
|
|
// Check the weak pointer to make sure the type hasn't been unloaded
|
|
|
|
TypeSP complete_type_sp (complete_class_iter->second.lock());
|
2012-02-23 07:57:45 +08:00
|
|
|
|
2012-10-24 06:41:19 +08:00
|
|
|
if (complete_type_sp)
|
|
|
|
return complete_type_sp;
|
2012-02-23 07:57:45 +08:00
|
|
|
else
|
2012-10-24 06:41:19 +08:00
|
|
|
m_complete_class_cache.erase(name);
|
2012-02-23 07:57:45 +08:00
|
|
|
}
|
|
|
|
|
2013-04-06 02:49:06 +08:00
|
|
|
if (m_negative_complete_class_cache.count(name) > 0)
|
|
|
|
return TypeSP();
|
|
|
|
|
2012-11-08 10:22:02 +08:00
|
|
|
const ModuleList &modules = m_process->GetTarget().GetImages();
|
2012-10-24 06:41:19 +08:00
|
|
|
|
2012-02-23 07:57:45 +08:00
|
|
|
SymbolContextList sc_list;
|
2012-10-24 06:41:19 +08:00
|
|
|
const size_t matching_symbols = modules.FindSymbolsWithNameAndType (name,
|
|
|
|
eSymbolTypeObjCClass,
|
|
|
|
sc_list);
|
2012-02-23 07:57:45 +08:00
|
|
|
|
2012-10-24 06:41:19 +08:00
|
|
|
if (matching_symbols)
|
2012-02-23 07:57:45 +08:00
|
|
|
{
|
2012-10-24 06:41:19 +08:00
|
|
|
SymbolContext sc;
|
2012-02-23 07:57:45 +08:00
|
|
|
|
2012-10-24 06:41:19 +08:00
|
|
|
sc_list.GetContextAtIndex(0, sc);
|
|
|
|
|
|
|
|
ModuleSP module_sp(sc.module_sp);
|
|
|
|
|
|
|
|
if (!module_sp)
|
2012-02-23 07:57:45 +08:00
|
|
|
return TypeSP();
|
|
|
|
|
2012-10-24 06:41:19 +08:00
|
|
|
const SymbolContext null_sc;
|
|
|
|
const bool exact_match = true;
|
|
|
|
const uint32_t max_matches = UINT32_MAX;
|
|
|
|
TypeList types;
|
|
|
|
|
|
|
|
const uint32_t num_types = module_sp->FindTypes (null_sc,
|
|
|
|
name,
|
|
|
|
exact_match,
|
|
|
|
max_matches,
|
|
|
|
types);
|
|
|
|
|
|
|
|
if (num_types)
|
2012-12-20 07:05:01 +08:00
|
|
|
{
|
2012-10-24 06:41:19 +08:00
|
|
|
uint32_t i;
|
|
|
|
for (i = 0; i < num_types; ++i)
|
|
|
|
{
|
|
|
|
TypeSP type_sp (types.GetTypeAtIndex(i));
|
|
|
|
|
2013-07-12 06:46:58 +08:00
|
|
|
if (type_sp->GetClangForwardType().IsObjCObjectOrInterfaceType())
|
2012-10-24 06:41:19 +08:00
|
|
|
{
|
|
|
|
if (type_sp->IsCompleteObjCClass())
|
|
|
|
{
|
|
|
|
m_complete_class_cache[name] = type_sp;
|
|
|
|
return type_sp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-02-23 07:57:45 +08:00
|
|
|
}
|
|
|
|
}
|
2013-04-06 02:49:06 +08:00
|
|
|
m_negative_complete_class_cache.insert(name);
|
2012-02-23 07:57:45 +08:00
|
|
|
return TypeSP();
|
|
|
|
}
|
|
|
|
|
2011-06-25 06:03:24 +08:00
|
|
|
size_t
|
|
|
|
ObjCLanguageRuntime::GetByteOffsetForIvar (ClangASTType &parent_qual_type, const char *ivar_name)
|
|
|
|
{
|
|
|
|
return LLDB_INVALID_IVAR_OFFSET;
|
|
|
|
}
|
|
|
|
|
2013-01-30 08:18:29 +08:00
|
|
|
void
|
|
|
|
ObjCLanguageRuntime::MethodName::Clear()
|
|
|
|
{
|
|
|
|
m_full.Clear();
|
|
|
|
m_class.Clear();
|
|
|
|
m_category.Clear();
|
|
|
|
m_selector.Clear();
|
|
|
|
m_type = eTypeUnspecified;
|
|
|
|
m_category_is_valid = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
//bool
|
|
|
|
//ObjCLanguageRuntime::MethodName::SetName (const char *name, bool strict)
|
|
|
|
//{
|
|
|
|
// Clear();
|
|
|
|
// if (name && name[0])
|
|
|
|
// {
|
|
|
|
// // If "strict" is true. then the method must be specified with a
|
|
|
|
// // '+' or '-' at the beginning. If "strict" is false, then the '+'
|
|
|
|
// // or '-' can be omitted
|
|
|
|
// bool valid_prefix = false;
|
|
|
|
//
|
|
|
|
// if (name[0] == '+' || name[0] == '-')
|
|
|
|
// {
|
|
|
|
// valid_prefix = name[1] == '[';
|
|
|
|
// }
|
|
|
|
// else if (!strict)
|
|
|
|
// {
|
|
|
|
// // "strict" is false, the name just needs to start with '['
|
|
|
|
// valid_prefix = name[0] == '[';
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// if (valid_prefix)
|
|
|
|
// {
|
|
|
|
// static RegularExpression g_regex("^([-+]?)\\[([A-Za-z_][A-Za-z_0-9]*)(\\([A-Za-z_][A-Za-z_0-9]*\\))? ([A-Za-z_][A-Za-z_0-9:]*)\\]$");
|
|
|
|
// llvm::StringRef matches[4];
|
|
|
|
// // Since we are using a global regular expression, we must use the threadsafe version of execute
|
|
|
|
// if (g_regex.ExecuteThreadSafe(name, matches, 4))
|
|
|
|
// {
|
|
|
|
// m_full.SetCString(name);
|
|
|
|
// if (matches[0].empty())
|
|
|
|
// m_type = eTypeUnspecified;
|
|
|
|
// else if (matches[0][0] == '+')
|
|
|
|
// m_type = eTypeClassMethod;
|
|
|
|
// else
|
|
|
|
// m_type = eTypeInstanceMethod;
|
|
|
|
// m_class.SetString(matches[1]);
|
|
|
|
// m_selector.SetString(matches[3]);
|
|
|
|
// if (!matches[2].empty())
|
|
|
|
// m_category.SetString(matches[2]);
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// return IsValid(strict);
|
|
|
|
//}
|
2011-08-15 09:32:22 +08:00
|
|
|
|
2013-01-30 08:18:29 +08:00
|
|
|
bool
|
|
|
|
ObjCLanguageRuntime::MethodName::SetName (const char *name, bool strict)
|
2011-08-15 09:32:22 +08:00
|
|
|
{
|
2013-01-30 08:18:29 +08:00
|
|
|
Clear();
|
|
|
|
if (name && name[0])
|
|
|
|
{
|
|
|
|
// If "strict" is true. then the method must be specified with a
|
|
|
|
// '+' or '-' at the beginning. If "strict" is false, then the '+'
|
|
|
|
// or '-' can be omitted
|
|
|
|
bool valid_prefix = false;
|
|
|
|
|
|
|
|
if (name[0] == '+' || name[0] == '-')
|
|
|
|
{
|
|
|
|
valid_prefix = name[1] == '[';
|
|
|
|
if (name[0] == '+')
|
|
|
|
m_type = eTypeClassMethod;
|
|
|
|
else
|
|
|
|
m_type = eTypeInstanceMethod;
|
|
|
|
}
|
|
|
|
else if (!strict)
|
|
|
|
{
|
|
|
|
// "strict" is false, the name just needs to start with '['
|
|
|
|
valid_prefix = name[0] == '[';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (valid_prefix)
|
|
|
|
{
|
|
|
|
int name_len = strlen (name);
|
|
|
|
// Objective C methods must have at least:
|
|
|
|
// "-[" or "+[" prefix
|
|
|
|
// One character for a class name
|
|
|
|
// One character for the space between the class name
|
|
|
|
// One character for the method name
|
|
|
|
// "]" suffix
|
|
|
|
if (name_len >= (5 + (strict ? 1 : 0)) && name[name_len - 1] == ']')
|
|
|
|
{
|
|
|
|
m_full.SetCStringWithLength(name, name_len);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return IsValid(strict);
|
|
|
|
}
|
2012-01-19 11:24:53 +08:00
|
|
|
|
2013-01-30 08:18:29 +08:00
|
|
|
const ConstString &
|
|
|
|
ObjCLanguageRuntime::MethodName::GetClassName ()
|
|
|
|
{
|
|
|
|
if (!m_class)
|
2011-08-15 09:32:22 +08:00
|
|
|
{
|
2013-01-30 08:18:29 +08:00
|
|
|
if (IsValid(false))
|
2011-08-15 09:32:22 +08:00
|
|
|
{
|
2013-01-30 08:18:29 +08:00
|
|
|
const char *full = m_full.GetCString();
|
|
|
|
const char *class_start = (full[0] == '[' ? full + 1 : full + 2);
|
|
|
|
const char *paren_pos = strchr (class_start, '(');
|
|
|
|
if (paren_pos)
|
2011-08-15 09:32:22 +08:00
|
|
|
{
|
2013-01-30 08:18:29 +08:00
|
|
|
m_class.SetCStringWithLength (class_start, paren_pos - class_start);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// No '(' was found in the full name, we can definitively say
|
|
|
|
// that our category was valid (and empty).
|
|
|
|
m_category_is_valid = true;
|
|
|
|
const char *space_pos = strchr (full, ' ');
|
|
|
|
if (space_pos)
|
2011-08-15 09:32:22 +08:00
|
|
|
{
|
2013-01-30 08:18:29 +08:00
|
|
|
m_class.SetCStringWithLength (class_start, space_pos - class_start);
|
|
|
|
if (!m_class_category)
|
2011-08-15 09:32:22 +08:00
|
|
|
{
|
2013-01-30 08:18:29 +08:00
|
|
|
// No category in name, so we can also fill in the m_class_category
|
|
|
|
m_class_category = m_class;
|
2011-08-15 09:32:22 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-01-30 08:18:29 +08:00
|
|
|
return m_class;
|
|
|
|
}
|
|
|
|
|
|
|
|
const ConstString &
|
|
|
|
ObjCLanguageRuntime::MethodName::GetClassNameWithCategory ()
|
|
|
|
{
|
|
|
|
if (!m_class_category)
|
|
|
|
{
|
|
|
|
if (IsValid(false))
|
|
|
|
{
|
|
|
|
const char *full = m_full.GetCString();
|
|
|
|
const char *class_start = (full[0] == '[' ? full + 1 : full + 2);
|
|
|
|
const char *space_pos = strchr (full, ' ');
|
|
|
|
if (space_pos)
|
|
|
|
{
|
|
|
|
m_class_category.SetCStringWithLength (class_start, space_pos - class_start);
|
|
|
|
// If m_class hasn't been filled in and the class with category doesn't
|
|
|
|
// contain a '(', then we can also fill in the m_class
|
|
|
|
if (!m_class && strchr (m_class_category.GetCString(), '(') == NULL)
|
|
|
|
{
|
|
|
|
m_class = m_class_category;
|
|
|
|
// No '(' was found in the full name, we can definitively say
|
|
|
|
// that our category was valid (and empty).
|
|
|
|
m_category_is_valid = true;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return m_class_category;
|
|
|
|
}
|
|
|
|
|
|
|
|
const ConstString &
|
|
|
|
ObjCLanguageRuntime::MethodName::GetSelector ()
|
|
|
|
{
|
|
|
|
if (!m_selector)
|
|
|
|
{
|
|
|
|
if (IsValid(false))
|
|
|
|
{
|
|
|
|
const char *full = m_full.GetCString();
|
|
|
|
const char *space_pos = strchr (full, ' ');
|
|
|
|
if (space_pos)
|
|
|
|
{
|
|
|
|
++space_pos; // skip the space
|
|
|
|
m_selector.SetCStringWithLength (space_pos, m_full.GetLength() - (space_pos - full) - 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return m_selector;
|
|
|
|
}
|
|
|
|
|
|
|
|
const ConstString &
|
|
|
|
ObjCLanguageRuntime::MethodName::GetCategory ()
|
|
|
|
{
|
|
|
|
if (!m_category_is_valid && !m_category)
|
|
|
|
{
|
|
|
|
if (IsValid(false))
|
|
|
|
{
|
|
|
|
m_category_is_valid = true;
|
|
|
|
const char *full = m_full.GetCString();
|
|
|
|
const char *class_start = (full[0] == '[' ? full + 1 : full + 2);
|
|
|
|
const char *open_paren_pos = strchr (class_start, '(');
|
|
|
|
if (open_paren_pos)
|
|
|
|
{
|
|
|
|
++open_paren_pos; // Skip the open paren
|
|
|
|
const char *close_paren_pos = strchr (open_paren_pos, ')');
|
|
|
|
if (close_paren_pos)
|
|
|
|
m_category.SetCStringWithLength (open_paren_pos, close_paren_pos - open_paren_pos);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return m_category;
|
|
|
|
}
|
|
|
|
|
|
|
|
ConstString
|
|
|
|
ObjCLanguageRuntime::MethodName::GetFullNameWithoutCategory (bool empty_if_no_category)
|
|
|
|
{
|
|
|
|
if (IsValid(false))
|
|
|
|
{
|
|
|
|
if (HasCategory())
|
|
|
|
{
|
|
|
|
StreamString strm;
|
|
|
|
if (m_type == eTypeClassMethod)
|
|
|
|
strm.PutChar('+');
|
|
|
|
else if (m_type == eTypeInstanceMethod)
|
|
|
|
strm.PutChar('-');
|
|
|
|
strm.Printf("[%s %s]", GetClassName().GetCString(), GetSelector().GetCString());
|
|
|
|
return ConstString(strm.GetString().c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!empty_if_no_category)
|
|
|
|
{
|
|
|
|
// Just return the full name since it doesn't have a category
|
|
|
|
return GetFullName();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ConstString();
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t
|
|
|
|
ObjCLanguageRuntime::MethodName::GetFullNames (std::vector<ConstString> &names, bool append)
|
|
|
|
{
|
|
|
|
if (!append)
|
|
|
|
names.clear();
|
|
|
|
if (IsValid(false))
|
|
|
|
{
|
|
|
|
StreamString strm;
|
|
|
|
const bool is_class_method = m_type == eTypeClassMethod;
|
|
|
|
const bool is_instance_method = m_type == eTypeInstanceMethod;
|
|
|
|
const ConstString &category = GetCategory();
|
|
|
|
if (is_class_method || is_instance_method)
|
|
|
|
{
|
|
|
|
names.push_back (m_full);
|
|
|
|
if (category)
|
|
|
|
{
|
|
|
|
strm.Printf("%c[%s %s]",
|
|
|
|
is_class_method ? '+' : '-',
|
|
|
|
GetClassName().GetCString(),
|
|
|
|
GetSelector().GetCString());
|
|
|
|
names.push_back(ConstString(strm.GetString().c_str()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const ConstString &class_name = GetClassName();
|
|
|
|
const ConstString &selector = GetSelector();
|
|
|
|
strm.Printf("+[%s %s]", class_name.GetCString(), selector.GetCString());
|
|
|
|
names.push_back(ConstString(strm.GetString().c_str()));
|
|
|
|
strm.Clear();
|
|
|
|
strm.Printf("-[%s %s]", class_name.GetCString(), selector.GetCString());
|
|
|
|
names.push_back(ConstString(strm.GetString().c_str()));
|
|
|
|
strm.Clear();
|
|
|
|
if (category)
|
|
|
|
{
|
|
|
|
strm.Printf("+[%s(%s) %s]", class_name.GetCString(), category.GetCString(), selector.GetCString());
|
|
|
|
names.push_back(ConstString(strm.GetString().c_str()));
|
|
|
|
strm.Clear();
|
|
|
|
strm.Printf("-[%s(%s) %s]", class_name.GetCString(), category.GetCString(), selector.GetCString());
|
|
|
|
names.push_back(ConstString(strm.GetString().c_str()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return names.size();
|
2011-08-15 09:32:22 +08:00
|
|
|
}
|
2012-09-05 02:47:54 +08:00
|
|
|
|
2013-01-30 08:18:29 +08:00
|
|
|
|
2012-09-05 02:47:54 +08:00
|
|
|
bool
|
|
|
|
ObjCLanguageRuntime::ClassDescriptor::IsPointerValid (lldb::addr_t value,
|
|
|
|
uint32_t ptr_size,
|
|
|
|
bool allow_NULLs,
|
|
|
|
bool allow_tagged,
|
2012-10-10 01:51:53 +08:00
|
|
|
bool check_version_specific) const
|
2012-09-05 02:47:54 +08:00
|
|
|
{
|
|
|
|
if (!value)
|
|
|
|
return allow_NULLs;
|
|
|
|
if ( (value % 2) == 1 && allow_tagged)
|
|
|
|
return true;
|
|
|
|
if ((value % ptr_size) == 0)
|
|
|
|
return (check_version_specific ? CheckPointer(value,ptr_size) : true);
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-09-12 05:44:01 +08:00
|
|
|
ObjCLanguageRuntime::ObjCISA
|
|
|
|
ObjCLanguageRuntime::GetISA(const ConstString &name)
|
|
|
|
{
|
2013-02-14 06:56:14 +08:00
|
|
|
ISAToDescriptorIterator pos = GetDescriptorIterator (name);
|
|
|
|
if (pos != m_isa_to_descriptor.end())
|
|
|
|
return pos->first;
|
2012-09-12 05:44:01 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-02-14 06:56:14 +08:00
|
|
|
ObjCLanguageRuntime::ISAToDescriptorIterator
|
|
|
|
ObjCLanguageRuntime::GetDescriptorIterator (const ConstString &name)
|
|
|
|
{
|
|
|
|
ISAToDescriptorIterator end = m_isa_to_descriptor.end();
|
|
|
|
|
|
|
|
if (name)
|
|
|
|
{
|
|
|
|
UpdateISAToDescriptorMap();
|
|
|
|
if (m_hash_to_isa_map.empty())
|
|
|
|
{
|
|
|
|
// No name hashes were provided, we need to just linearly power through the
|
|
|
|
// names and find a match
|
|
|
|
for (ISAToDescriptorIterator pos = m_isa_to_descriptor.begin(); pos != end; ++pos)
|
|
|
|
{
|
|
|
|
if (pos->second->GetClassName() == name)
|
|
|
|
return pos;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Name hashes were provided, so use them to efficiently lookup name to isa/descriptor
|
|
|
|
const uint32_t name_hash = MappedHash::HashStringUsingDJB (name.GetCString());
|
|
|
|
std::pair <HashToISAIterator, HashToISAIterator> range = m_hash_to_isa_map.equal_range(name_hash);
|
|
|
|
for (HashToISAIterator range_pos = range.first; range_pos != range.second; ++range_pos)
|
|
|
|
{
|
|
|
|
ISAToDescriptorIterator pos = m_isa_to_descriptor.find (range_pos->second);
|
|
|
|
if (pos != m_isa_to_descriptor.end())
|
|
|
|
{
|
|
|
|
if (pos->second->GetClassName() == name)
|
|
|
|
return pos;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return end;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-09-05 02:47:54 +08:00
|
|
|
ObjCLanguageRuntime::ObjCISA
|
|
|
|
ObjCLanguageRuntime::GetParentClass(ObjCLanguageRuntime::ObjCISA isa)
|
|
|
|
{
|
2013-04-20 05:31:16 +08:00
|
|
|
ClassDescriptorSP objc_class_sp (GetClassDescriptorFromISA(isa));
|
2012-10-10 01:51:53 +08:00
|
|
|
if (objc_class_sp)
|
2012-09-05 02:47:54 +08:00
|
|
|
{
|
2012-10-10 01:51:53 +08:00
|
|
|
ClassDescriptorSP objc_super_class_sp (objc_class_sp->GetSuperclass());
|
|
|
|
if (objc_super_class_sp)
|
|
|
|
return objc_super_class_sp->GetISA();
|
2012-09-05 02:47:54 +08:00
|
|
|
}
|
2012-10-10 01:51:53 +08:00
|
|
|
return 0;
|
2012-09-05 02:47:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
ConstString
|
|
|
|
ObjCLanguageRuntime::GetActualTypeName(ObjCLanguageRuntime::ObjCISA isa)
|
|
|
|
{
|
2012-10-10 01:51:53 +08:00
|
|
|
ClassDescriptorSP objc_class_sp (GetNonKVOClassDescriptor(isa));
|
|
|
|
if (objc_class_sp)
|
|
|
|
return objc_class_sp->GetClassName();
|
|
|
|
return ConstString();
|
|
|
|
}
|
|
|
|
|
|
|
|
ObjCLanguageRuntime::ClassDescriptorSP
|
2013-04-20 05:31:16 +08:00
|
|
|
ObjCLanguageRuntime::GetClassDescriptorFromClassName (const ConstString &class_name)
|
2012-10-10 01:51:53 +08:00
|
|
|
{
|
2013-02-14 06:56:14 +08:00
|
|
|
ISAToDescriptorIterator pos = GetDescriptorIterator (class_name);
|
|
|
|
if (pos != m_isa_to_descriptor.end())
|
|
|
|
return pos->second;
|
2012-10-10 01:51:53 +08:00
|
|
|
return ClassDescriptorSP();
|
2012-10-12 02:07:21 +08:00
|
|
|
|
2012-10-10 01:51:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
ObjCLanguageRuntime::ClassDescriptorSP
|
2012-10-12 02:07:21 +08:00
|
|
|
ObjCLanguageRuntime::GetClassDescriptor (ValueObject& valobj)
|
2012-10-10 01:51:53 +08:00
|
|
|
{
|
|
|
|
ClassDescriptorSP objc_class_sp;
|
2012-10-12 02:07:21 +08:00
|
|
|
// if we get an invalid VO (which might still happen when playing around
|
|
|
|
// with pointers returned by the expression parser, don't consider this
|
|
|
|
// a valid ObjC object)
|
2013-07-12 06:46:58 +08:00
|
|
|
if (valobj.GetClangType().IsValid())
|
2012-10-10 01:51:53 +08:00
|
|
|
{
|
2012-10-12 02:07:21 +08:00
|
|
|
addr_t isa_pointer = valobj.GetPointerValue();
|
|
|
|
if (isa_pointer != LLDB_INVALID_ADDRESS)
|
|
|
|
{
|
|
|
|
ExecutionContext exe_ctx (valobj.GetExecutionContextRef());
|
|
|
|
|
|
|
|
Process *process = exe_ctx.GetProcessPtr();
|
|
|
|
if (process)
|
|
|
|
{
|
|
|
|
Error error;
|
|
|
|
ObjCISA isa = process->ReadPointerFromMemory(isa_pointer, error);
|
|
|
|
if (isa != LLDB_INVALID_ADDRESS)
|
2013-04-20 05:31:16 +08:00
|
|
|
objc_class_sp = GetClassDescriptorFromISA (isa);
|
2012-10-12 02:07:21 +08:00
|
|
|
}
|
|
|
|
}
|
2012-10-10 01:51:53 +08:00
|
|
|
}
|
|
|
|
return objc_class_sp;
|
|
|
|
}
|
|
|
|
|
2012-10-12 02:07:21 +08:00
|
|
|
ObjCLanguageRuntime::ClassDescriptorSP
|
|
|
|
ObjCLanguageRuntime::GetNonKVOClassDescriptor (ValueObject& valobj)
|
|
|
|
{
|
|
|
|
ObjCLanguageRuntime::ClassDescriptorSP objc_class_sp (GetClassDescriptor (valobj));
|
|
|
|
if (objc_class_sp)
|
|
|
|
{
|
|
|
|
if (!objc_class_sp->IsKVO())
|
|
|
|
return objc_class_sp;
|
|
|
|
|
|
|
|
ClassDescriptorSP non_kvo_objc_class_sp(objc_class_sp->GetSuperclass());
|
|
|
|
if (non_kvo_objc_class_sp && non_kvo_objc_class_sp->IsValid())
|
|
|
|
return non_kvo_objc_class_sp;
|
|
|
|
}
|
|
|
|
return ClassDescriptorSP();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ObjCLanguageRuntime::ClassDescriptorSP
|
2013-04-20 05:31:16 +08:00
|
|
|
ObjCLanguageRuntime::GetClassDescriptorFromISA (ObjCISA isa)
|
2012-10-12 02:07:21 +08:00
|
|
|
{
|
|
|
|
if (isa)
|
|
|
|
{
|
|
|
|
UpdateISAToDescriptorMap();
|
2013-02-14 06:56:14 +08:00
|
|
|
ObjCLanguageRuntime::ISAToDescriptorIterator pos = m_isa_to_descriptor.find(isa);
|
|
|
|
if (pos != m_isa_to_descriptor.end())
|
2012-10-12 02:07:21 +08:00
|
|
|
return pos->second;
|
|
|
|
}
|
|
|
|
return ClassDescriptorSP();
|
|
|
|
}
|
|
|
|
|
2012-10-10 01:51:53 +08:00
|
|
|
ObjCLanguageRuntime::ClassDescriptorSP
|
|
|
|
ObjCLanguageRuntime::GetNonKVOClassDescriptor (ObjCISA isa)
|
|
|
|
{
|
|
|
|
if (isa)
|
2012-09-05 02:47:54 +08:00
|
|
|
{
|
2013-04-20 05:31:16 +08:00
|
|
|
ClassDescriptorSP objc_class_sp = GetClassDescriptorFromISA (isa);
|
2012-10-10 01:51:53 +08:00
|
|
|
if (objc_class_sp && objc_class_sp->IsValid())
|
|
|
|
{
|
2012-10-12 02:07:21 +08:00
|
|
|
if (!objc_class_sp->IsKVO())
|
2012-10-10 01:51:53 +08:00
|
|
|
return objc_class_sp;
|
2012-10-12 02:07:21 +08:00
|
|
|
|
|
|
|
ClassDescriptorSP non_kvo_objc_class_sp(objc_class_sp->GetSuperclass());
|
|
|
|
if (non_kvo_objc_class_sp && non_kvo_objc_class_sp->IsValid())
|
|
|
|
return non_kvo_objc_class_sp;
|
2012-10-10 01:51:53 +08:00
|
|
|
}
|
2012-09-05 02:47:54 +08:00
|
|
|
}
|
2012-10-10 01:51:53 +08:00
|
|
|
return ClassDescriptorSP();
|
2012-09-05 02:47:54 +08:00
|
|
|
}
|
2012-10-10 01:51:53 +08:00
|
|
|
|
|
|
|
|
2014-08-20 05:46:37 +08:00
|
|
|
ClangASTType
|
|
|
|
ObjCLanguageRuntime::EncodingToType::RealizeType (const char* name, bool allow_unknownanytype)
|
|
|
|
{
|
|
|
|
if (m_scratch_ast_ctx_ap)
|
|
|
|
return RealizeType(*m_scratch_ast_ctx_ap, name, allow_unknownanytype);
|
|
|
|
return ClangASTType();
|
|
|
|
}
|
|
|
|
|
|
|
|
ClangASTType
|
|
|
|
ObjCLanguageRuntime::EncodingToType::RealizeType (ClangASTContext& ast_ctx, const char* name, bool allow_unknownanytype)
|
|
|
|
{
|
|
|
|
clang::ASTContext *clang_ast = ast_ctx.getASTContext();
|
|
|
|
if (!clang_ast)
|
|
|
|
return ClangASTType();
|
|
|
|
return RealizeType(*clang_ast, name, allow_unknownanytype);
|
|
|
|
}
|
|
|
|
|
|
|
|
ObjCLanguageRuntime::EncodingToType::~EncodingToType() {}
|
2012-10-10 01:51:53 +08:00
|
|
|
|
2014-08-20 05:46:37 +08:00
|
|
|
ObjCLanguageRuntime::EncodingToTypeSP
|
|
|
|
ObjCLanguageRuntime::GetEncodingToType ()
|
|
|
|
{
|
|
|
|
return nullptr;
|
|
|
|
}
|