2010-09-23 10:01:19 +08:00
|
|
|
//===-- CPPLanguageRuntime.cpp -------------------------------------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// 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"
|
2010-09-23 10:01:19 +08:00
|
|
|
#include "lldb/Core/PluginManager.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"
|
2010-09-28 09:25:32 +08:00
|
|
|
#include "lldb/Target/ObjCLanguageRuntime.h"
|
2010-09-23 10:01:19 +08:00
|
|
|
|
|
|
|
using namespace lldb;
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Destructor
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
ObjCLanguageRuntime::~ObjCLanguageRuntime()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ObjCLanguageRuntime::ObjCLanguageRuntime (Process *process) :
|
|
|
|
LanguageRuntime (process)
|
|
|
|
{
|
|
|
|
|
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)
|
|
|
|
{
|
2010-11-06 09:53:30 +08:00
|
|
|
LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
|
2010-09-28 09:25:32 +08:00
|
|
|
if (log)
|
|
|
|
{
|
|
|
|
log->Printf ("Caching: class 0x%llx selector 0x%llx implementation 0x%llx.", class_addr, selector, impl_addr);
|
|
|
|
}
|
|
|
|
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
|
|
|
|
|
|
|
void
|
|
|
|
ObjCLanguageRuntime::AddToClassNameCache (lldb::addr_t class_addr, const char *name, lldb::TypeSP type_sp)
|
|
|
|
{
|
|
|
|
LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
|
|
|
|
if (log)
|
|
|
|
{
|
|
|
|
log->Printf ("Caching: class 0x%llx name: %s.", class_addr, name);
|
|
|
|
}
|
|
|
|
|
|
|
|
TypeAndOrName class_type_or_name;
|
|
|
|
|
2011-10-19 07:36:41 +08:00
|
|
|
if (type_sp)
|
2011-05-03 02:13:59 +08:00
|
|
|
class_type_or_name.SetTypeSP (type_sp);
|
|
|
|
else if (name && *name != '\0')
|
|
|
|
class_type_or_name.SetName (name);
|
|
|
|
else
|
|
|
|
return;
|
|
|
|
m_class_name_cache.insert (std::pair<lldb::addr_t,TypeAndOrName> (class_addr, class_type_or_name));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ObjCLanguageRuntime::AddToClassNameCache (lldb::addr_t class_addr, const TypeAndOrName &class_type_or_name)
|
|
|
|
{
|
|
|
|
LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
|
|
|
|
if (log)
|
|
|
|
{
|
|
|
|
log->Printf ("Caching: class 0x%llx name: %s.", class_addr, class_type_or_name.GetName().AsCString());
|
|
|
|
}
|
|
|
|
|
|
|
|
m_class_name_cache.insert (std::pair<lldb::addr_t,TypeAndOrName> (class_addr, class_type_or_name));
|
|
|
|
}
|
|
|
|
|
|
|
|
TypeAndOrName
|
|
|
|
ObjCLanguageRuntime::LookupInClassNameCache (lldb::addr_t class_addr)
|
|
|
|
{
|
|
|
|
ClassNameMap::iterator pos, end = m_class_name_cache.end();
|
|
|
|
pos = m_class_name_cache.find (class_addr);
|
|
|
|
if (pos != end)
|
|
|
|
return (*pos).second;
|
|
|
|
return TypeAndOrName ();
|
|
|
|
}
|
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;
|
|
|
|
}
|
|
|
|
|
2011-08-15 09:32:22 +08:00
|
|
|
|
|
|
|
bool
|
|
|
|
ObjCLanguageRuntime::ParseMethodName (const char *name,
|
|
|
|
ConstString *class_name,
|
2011-10-05 06:41:51 +08:00
|
|
|
ConstString *selector_name,
|
|
|
|
ConstString *name_sans_category)
|
2011-08-15 09:32:22 +08:00
|
|
|
{
|
|
|
|
if (class_name) { class_name->Clear(); }
|
2011-10-05 06:41:51 +08:00
|
|
|
if (selector_name) { selector_name->Clear(); }
|
|
|
|
if (name_sans_category) { name_sans_category->Clear(); }
|
2011-08-15 09:32:22 +08:00
|
|
|
|
2011-09-09 06:13:49 +08:00
|
|
|
if (IsPossibleObjCMethodName (name))
|
2011-08-15 09:32:22 +08:00
|
|
|
{
|
|
|
|
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 >= 6 && name[name_len - 1] == ']')
|
|
|
|
{
|
2011-10-05 06:41:51 +08:00
|
|
|
const char *selector_name_ptr;
|
|
|
|
selector_name_ptr = strchr (name, ' ');
|
|
|
|
if (selector_name_ptr)
|
2011-08-15 09:32:22 +08:00
|
|
|
{
|
|
|
|
if (class_name)
|
2011-10-05 06:41:51 +08:00
|
|
|
class_name->SetCStringWithLength (name + 2, selector_name_ptr - name - 2);
|
2011-08-15 09:32:22 +08:00
|
|
|
|
|
|
|
// Skip the space
|
2011-10-05 06:41:51 +08:00
|
|
|
++selector_name_ptr;
|
2011-08-15 09:32:22 +08:00
|
|
|
// Extract the objective C basename and add it to the
|
|
|
|
// accelerator tables
|
2011-10-05 06:41:51 +08:00
|
|
|
size_t selector_name_len = name_len - (selector_name_ptr - name) - 1;
|
|
|
|
if (selector_name)
|
|
|
|
selector_name->SetCStringWithLength (selector_name_ptr, selector_name_len);
|
2011-08-15 09:32:22 +08:00
|
|
|
|
|
|
|
// Also see if this is a "category" on our class. If so strip off the category name,
|
|
|
|
// and add the class name without it to the basename table.
|
|
|
|
|
2011-10-05 06:41:51 +08:00
|
|
|
if (name_sans_category)
|
2011-08-15 09:32:22 +08:00
|
|
|
{
|
2011-10-05 06:41:51 +08:00
|
|
|
const char *first_paren = (char *) memchr (name, '(', selector_name_ptr - name);
|
2011-08-15 09:32:22 +08:00
|
|
|
if (first_paren)
|
|
|
|
{
|
2011-10-05 06:41:51 +08:00
|
|
|
const char *second_paren = (char *) memchr (first_paren, ')', selector_name_ptr - first_paren);
|
2011-08-15 09:32:22 +08:00
|
|
|
if (second_paren)
|
|
|
|
{
|
|
|
|
std::string buffer (name, first_paren - name);
|
|
|
|
buffer.append (second_paren + 1);
|
2011-10-05 06:41:51 +08:00
|
|
|
name_sans_category->SetCString (buffer.c_str());
|
2011-08-15 09:32:22 +08:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
}
|