2010-11-05 02:30:59 +08:00
|
|
|
//===-- AppleObjCRuntime.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-11-05 02:30:59 +08:00
|
|
|
#include "AppleObjCRuntime.h"
|
2010-09-28 09:25:32 +08:00
|
|
|
#include "AppleObjCTrampolineHandler.h"
|
2010-09-23 10:01:19 +08:00
|
|
|
|
2010-11-04 06:19:38 +08:00
|
|
|
#include "llvm/Support/MachO.h"
|
2010-09-30 08:54:27 +08:00
|
|
|
#include "clang/AST/Type.h"
|
|
|
|
|
2010-11-04 06:19:38 +08:00
|
|
|
#include "lldb/Breakpoint/BreakpointLocation.h"
|
2010-09-23 10:01:19 +08:00
|
|
|
#include "lldb/Core/ConstString.h"
|
|
|
|
#include "lldb/Core/Error.h"
|
2010-09-28 09:25:32 +08:00
|
|
|
#include "lldb/Core/Log.h"
|
2010-09-23 10:01:19 +08:00
|
|
|
#include "lldb/Core/Module.h"
|
2010-11-05 02:30:59 +08:00
|
|
|
#include "lldb/Core/ModuleList.h"
|
2010-09-23 10:01:19 +08:00
|
|
|
#include "lldb/Core/PluginManager.h"
|
|
|
|
#include "lldb/Core/Scalar.h"
|
2010-11-05 02:30:59 +08:00
|
|
|
#include "lldb/Core/Section.h"
|
2010-09-28 09:25:32 +08:00
|
|
|
#include "lldb/Core/StreamString.h"
|
|
|
|
#include "lldb/Expression/ClangFunction.h"
|
2010-09-23 10:01:19 +08:00
|
|
|
#include "lldb/Symbol/ClangASTContext.h"
|
2010-11-05 02:30:59 +08:00
|
|
|
#include "lldb/Symbol/ObjectFile.h"
|
2010-09-28 09:25:32 +08:00
|
|
|
#include "lldb/Target/ExecutionContext.h"
|
2010-09-23 10:01:19 +08:00
|
|
|
#include "lldb/Target/Process.h"
|
|
|
|
#include "lldb/Target/RegisterContext.h"
|
2010-11-04 06:19:38 +08:00
|
|
|
#include "lldb/Target/StopInfo.h"
|
2010-09-23 10:01:19 +08:00
|
|
|
#include "lldb/Target/Target.h"
|
|
|
|
#include "lldb/Target/Thread.h"
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
using namespace lldb;
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
2010-09-28 09:25:32 +08:00
|
|
|
bool
|
2012-02-17 15:49:44 +08:00
|
|
|
AppleObjCRuntime::GetObjectDescription (Stream &str, ValueObject &valobj)
|
2010-09-28 09:25:32 +08:00
|
|
|
{
|
2011-03-18 08:05:18 +08:00
|
|
|
bool is_signed;
|
|
|
|
// ObjC objects can only be pointers, but we extend this to integer types because an expression might just
|
|
|
|
// result in an address, and we should try that to see if the address is an ObjC object.
|
|
|
|
|
2012-02-17 15:49:44 +08:00
|
|
|
if (!(valobj.IsPointerType() || valobj.IsIntegerType(is_signed)))
|
2012-05-22 16:38:06 +08:00
|
|
|
return false;
|
2010-09-30 08:54:27 +08:00
|
|
|
|
|
|
|
// Make the argument list: we pass one arg, the address of our pointer, to the print function.
|
Redesign of the interaction between Python and frozen objects:
- introduced two new classes ValueObjectConstResultChild and ValueObjectConstResultImpl: the first one is a ValueObjectChild obtained from
a ValueObjectConstResult, the second is a common implementation backend for VOCR and VOCRCh of method calls meant to read through pointers stored
in frozen objects ; now such reads transparently move from host to target as required
- as a consequence of the above, removed code that made target-memory copies of expression results in several places throughout LLDB, and also
removed code that enabled to recognize an expression result VO as such
- introduced a new GetPointeeData() method in ValueObject that lets you read a given amount of objects of type T from a VO
representing a T* or T[], and doing dereferences transparently
in private layer it returns a DataExtractor ; in public layer it returns an instance of a newly created lldb::SBData
- as GetPointeeData() does the right thing for both frozen and non-frozen ValueObject's, reimplemented ReadPointedString() to use it
en lieu of doing the raw read itself
- introduced a new GetData() method in ValueObject that lets you get a copy of the data that backs the ValueObject (for pointers,
this returns the address without any previous dereferencing steps ; for arrays it actually reads the whole chunk of memory)
in public layer this returns an SBData, just like GetPointeeData()
- introduced a new CreateValueFromData() method in SBValue that lets you create a new SBValue from a chunk of data wrapped in an SBData
the limitation to remember for this kind of SBValue is that they have no address: extracting the address-of for these objects (with any
of GetAddress(), GetLoadAddress() and AddressOf()) will return invalid values
- added several tests to check that "p"-ing objects (STL classes, char* and char[]) will do the right thing
Solved a bug where global pointers to global variables were not dereferenced correctly for display
New target setting "max-string-summary-length" gives the maximum number of characters to show in a string when summarizing it, instead of the hardcoded 128
Solved a bug where the summary for char[] and char* would not be shown if the ValueObject's were dumped via the "p" command
Removed m_pointers_point_to_load_addrs from ValueObject. Introduced a new m_address_type_of_children, which each ValueObject can set to tell the address type
of any pointers and/or references it creates. In the current codebase, this is load address most of the time (the only notable exception being file
addresses that generate file address children UNLESS we have a live process)
Updated help text for summary-string
Fixed an issue in STL formatters where std::stlcontainer::iterator would match the container's synthetic children providers
Edited the syntax and help for some commands to have proper argument types
llvm-svn: 139160
2011-09-07 03:20:51 +08:00
|
|
|
Value val;
|
2010-09-30 08:54:27 +08:00
|
|
|
|
2012-02-17 15:49:44 +08:00
|
|
|
if (!valobj.ResolveValue(val.GetScalar()))
|
2012-05-22 16:38:06 +08:00
|
|
|
return false;
|
2012-02-17 15:49:44 +08:00
|
|
|
|
|
|
|
ExecutionContext exe_ctx (valobj.GetExecutionContextRef());
|
|
|
|
return GetObjectDescription(str, val, exe_ctx.GetBestExecutionContextScope());
|
2010-09-30 08:54:27 +08:00
|
|
|
|
|
|
|
}
|
|
|
|
bool
|
Added new lldb_private::Process memory read/write functions to stop a bunch
of duplicated code from appearing all over LLDB:
lldb::addr_t
Process::ReadPointerFromMemory (lldb::addr_t vm_addr, Error &error);
bool
Process::WritePointerToMemory (lldb::addr_t vm_addr, lldb::addr_t ptr_value, Error &error);
size_t
Process::ReadScalarIntegerFromMemory (lldb::addr_t addr, uint32_t byte_size, bool is_signed, Scalar &scalar, Error &error);
size_t
Process::WriteScalarToMemory (lldb::addr_t vm_addr, const Scalar &scalar, uint32_t size, Error &error);
in lldb_private::Process the following functions were renamed:
From:
uint64_t
Process::ReadUnsignedInteger (lldb::addr_t load_addr,
size_t byte_size,
Error &error);
To:
uint64_t
Process::ReadUnsignedIntegerFromMemory (lldb::addr_t load_addr,
size_t byte_size,
uint64_t fail_value,
Error &error);
Cleaned up a lot of code that was manually doing what the above functions do
to use the functions listed above.
Added the ability to get a scalar value as a buffer that can be written down
to a process (byte swapping the Scalar value if needed):
uint32_t
Scalar::GetAsMemoryData (void *dst,
uint32_t dst_len,
lldb::ByteOrder dst_byte_order,
Error &error) const;
The "dst_len" can be smaller that the size of the scalar and the least
significant bytes will be written. "dst_len" can also be larger and the
most significant bytes will be padded with zeroes.
Centralized the code that adds or removes address bits for callable and opcode
addresses into lldb_private::Target:
lldb::addr_t
Target::GetCallableLoadAddress (lldb::addr_t load_addr, AddressClass addr_class) const;
lldb::addr_t
Target::GetOpcodeLoadAddress (lldb::addr_t load_addr, AddressClass addr_class) const;
All necessary lldb_private::Address functions now use the target versions so
changes should only need to happen in one place if anything needs updating.
Fixed up a lot of places that were calling :
addr_t
Address::GetLoadAddress(Target*);
to call the Address::GetCallableLoadAddress() or Address::GetOpcodeLoadAddress()
as needed. There were many places in the breakpoint code where things could
go wrong for ARM if these weren't used.
llvm-svn: 131878
2011-05-23 06:46:53 +08:00
|
|
|
AppleObjCRuntime::GetObjectDescription (Stream &strm, Value &value, ExecutionContextScope *exe_scope)
|
2010-09-30 08:54:27 +08:00
|
|
|
{
|
2010-09-29 00:06:31 +08:00
|
|
|
if (!m_read_objc_library)
|
|
|
|
return false;
|
|
|
|
|
2010-09-28 09:25:32 +08:00
|
|
|
ExecutionContext exe_ctx;
|
2010-10-04 09:05:56 +08:00
|
|
|
exe_scope->CalculateExecutionContext(exe_ctx);
|
2011-09-22 12:58:26 +08:00
|
|
|
Process *process = exe_ctx.GetProcessPtr();
|
|
|
|
if (!process)
|
2010-09-28 09:25:32 +08:00
|
|
|
return false;
|
|
|
|
|
|
|
|
// We need other parts of the exe_ctx, but the processes have to match.
|
2011-09-22 12:58:26 +08:00
|
|
|
assert (m_process == process);
|
2010-09-28 09:25:32 +08:00
|
|
|
|
|
|
|
// Get the function address for the print function.
|
|
|
|
const Address *function_address = GetPrintForDebuggerAddr();
|
|
|
|
if (!function_address)
|
|
|
|
return false;
|
|
|
|
|
2011-09-22 12:58:26 +08:00
|
|
|
Target *target = exe_ctx.GetTargetPtr();
|
2010-09-30 08:54:27 +08:00
|
|
|
if (value.GetClangType())
|
|
|
|
{
|
|
|
|
clang::QualType value_type = clang::QualType::getFromOpaquePtr (value.GetClangType());
|
|
|
|
if (!value_type->isObjCObjectPointerType())
|
|
|
|
{
|
Added new lldb_private::Process memory read/write functions to stop a bunch
of duplicated code from appearing all over LLDB:
lldb::addr_t
Process::ReadPointerFromMemory (lldb::addr_t vm_addr, Error &error);
bool
Process::WritePointerToMemory (lldb::addr_t vm_addr, lldb::addr_t ptr_value, Error &error);
size_t
Process::ReadScalarIntegerFromMemory (lldb::addr_t addr, uint32_t byte_size, bool is_signed, Scalar &scalar, Error &error);
size_t
Process::WriteScalarToMemory (lldb::addr_t vm_addr, const Scalar &scalar, uint32_t size, Error &error);
in lldb_private::Process the following functions were renamed:
From:
uint64_t
Process::ReadUnsignedInteger (lldb::addr_t load_addr,
size_t byte_size,
Error &error);
To:
uint64_t
Process::ReadUnsignedIntegerFromMemory (lldb::addr_t load_addr,
size_t byte_size,
uint64_t fail_value,
Error &error);
Cleaned up a lot of code that was manually doing what the above functions do
to use the functions listed above.
Added the ability to get a scalar value as a buffer that can be written down
to a process (byte swapping the Scalar value if needed):
uint32_t
Scalar::GetAsMemoryData (void *dst,
uint32_t dst_len,
lldb::ByteOrder dst_byte_order,
Error &error) const;
The "dst_len" can be smaller that the size of the scalar and the least
significant bytes will be written. "dst_len" can also be larger and the
most significant bytes will be padded with zeroes.
Centralized the code that adds or removes address bits for callable and opcode
addresses into lldb_private::Target:
lldb::addr_t
Target::GetCallableLoadAddress (lldb::addr_t load_addr, AddressClass addr_class) const;
lldb::addr_t
Target::GetOpcodeLoadAddress (lldb::addr_t load_addr, AddressClass addr_class) const;
All necessary lldb_private::Address functions now use the target versions so
changes should only need to happen in one place if anything needs updating.
Fixed up a lot of places that were calling :
addr_t
Address::GetLoadAddress(Target*);
to call the Address::GetCallableLoadAddress() or Address::GetOpcodeLoadAddress()
as needed. There were many places in the breakpoint code where things could
go wrong for ARM if these weren't used.
llvm-svn: 131878
2011-05-23 06:46:53 +08:00
|
|
|
strm.Printf ("Value doesn't point to an ObjC object.\n");
|
2010-09-30 08:54:27 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// If it is not a pointer, see if we can make it into a pointer.
|
2011-09-22 12:58:26 +08:00
|
|
|
ClangASTContext *ast_context = target->GetScratchClangASTContext();
|
2010-09-30 08:54:27 +08:00
|
|
|
void *opaque_type_ptr = ast_context->GetBuiltInType_objc_id();
|
|
|
|
if (opaque_type_ptr == NULL)
|
|
|
|
opaque_type_ptr = ast_context->GetVoidPtrType(false);
|
2010-11-13 11:52:47 +08:00
|
|
|
value.SetContext(Value::eContextTypeClangType, opaque_type_ptr);
|
2010-09-30 08:54:27 +08:00
|
|
|
}
|
|
|
|
|
2010-09-28 09:25:32 +08:00
|
|
|
ValueList arg_value_list;
|
2010-09-30 08:54:27 +08:00
|
|
|
arg_value_list.PushValue(value);
|
2010-09-28 09:25:32 +08:00
|
|
|
|
|
|
|
// This is the return value:
|
2011-09-22 12:58:26 +08:00
|
|
|
ClangASTContext *ast_context = target->GetScratchClangASTContext();
|
2010-09-28 09:25:32 +08:00
|
|
|
|
|
|
|
void *return_qualtype = ast_context->GetCStringType(true);
|
|
|
|
Value ret;
|
2010-11-13 11:52:47 +08:00
|
|
|
ret.SetContext(Value::eContextTypeClangType, return_qualtype);
|
2010-09-28 09:25:32 +08:00
|
|
|
|
2012-02-15 02:01:27 +08:00
|
|
|
if (exe_ctx.GetFramePtr() == NULL)
|
|
|
|
{
|
|
|
|
Thread *thread = exe_ctx.GetThreadPtr();
|
|
|
|
if (thread == NULL)
|
|
|
|
{
|
|
|
|
exe_ctx.SetThreadSP(process->GetThreadList().GetSelectedThread());
|
|
|
|
thread = exe_ctx.GetThreadPtr();
|
|
|
|
}
|
|
|
|
if (thread)
|
|
|
|
{
|
|
|
|
exe_ctx.SetFrameSP(thread->GetSelectedFrame());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-28 09:25:32 +08:00
|
|
|
// Now we're ready to call the function:
|
2011-03-18 04:02:56 +08:00
|
|
|
ClangFunction func (*exe_ctx.GetBestExecutionContextScope(),
|
2011-02-16 05:59:32 +08:00
|
|
|
ast_context,
|
|
|
|
return_qualtype,
|
|
|
|
*function_address,
|
|
|
|
arg_value_list);
|
|
|
|
|
2010-09-28 09:25:32 +08:00
|
|
|
StreamString error_stream;
|
|
|
|
|
|
|
|
lldb::addr_t wrapper_struct_addr = LLDB_INVALID_ADDRESS;
|
|
|
|
func.InsertFunction(exe_ctx, wrapper_struct_addr, error_stream);
|
|
|
|
|
2010-11-06 03:25:48 +08:00
|
|
|
bool unwind_on_error = true;
|
|
|
|
bool try_all_threads = true;
|
|
|
|
bool stop_others = true;
|
|
|
|
|
2010-12-14 10:59:59 +08:00
|
|
|
ExecutionResults results = func.ExecuteFunction (exe_ctx,
|
|
|
|
&wrapper_struct_addr,
|
|
|
|
error_stream,
|
|
|
|
stop_others,
|
2012-07-17 07:10:35 +08:00
|
|
|
0 /* no timeout */,
|
2010-12-14 10:59:59 +08:00
|
|
|
try_all_threads,
|
|
|
|
unwind_on_error,
|
|
|
|
ret);
|
2011-03-25 05:19:54 +08:00
|
|
|
if (results != eExecutionCompleted)
|
2010-09-28 09:25:32 +08:00
|
|
|
{
|
Added new lldb_private::Process memory read/write functions to stop a bunch
of duplicated code from appearing all over LLDB:
lldb::addr_t
Process::ReadPointerFromMemory (lldb::addr_t vm_addr, Error &error);
bool
Process::WritePointerToMemory (lldb::addr_t vm_addr, lldb::addr_t ptr_value, Error &error);
size_t
Process::ReadScalarIntegerFromMemory (lldb::addr_t addr, uint32_t byte_size, bool is_signed, Scalar &scalar, Error &error);
size_t
Process::WriteScalarToMemory (lldb::addr_t vm_addr, const Scalar &scalar, uint32_t size, Error &error);
in lldb_private::Process the following functions were renamed:
From:
uint64_t
Process::ReadUnsignedInteger (lldb::addr_t load_addr,
size_t byte_size,
Error &error);
To:
uint64_t
Process::ReadUnsignedIntegerFromMemory (lldb::addr_t load_addr,
size_t byte_size,
uint64_t fail_value,
Error &error);
Cleaned up a lot of code that was manually doing what the above functions do
to use the functions listed above.
Added the ability to get a scalar value as a buffer that can be written down
to a process (byte swapping the Scalar value if needed):
uint32_t
Scalar::GetAsMemoryData (void *dst,
uint32_t dst_len,
lldb::ByteOrder dst_byte_order,
Error &error) const;
The "dst_len" can be smaller that the size of the scalar and the least
significant bytes will be written. "dst_len" can also be larger and the
most significant bytes will be padded with zeroes.
Centralized the code that adds or removes address bits for callable and opcode
addresses into lldb_private::Target:
lldb::addr_t
Target::GetCallableLoadAddress (lldb::addr_t load_addr, AddressClass addr_class) const;
lldb::addr_t
Target::GetOpcodeLoadAddress (lldb::addr_t load_addr, AddressClass addr_class) const;
All necessary lldb_private::Address functions now use the target versions so
changes should only need to happen in one place if anything needs updating.
Fixed up a lot of places that were calling :
addr_t
Address::GetLoadAddress(Target*);
to call the Address::GetCallableLoadAddress() or Address::GetOpcodeLoadAddress()
as needed. There were many places in the breakpoint code where things could
go wrong for ARM if these weren't used.
llvm-svn: 131878
2011-05-23 06:46:53 +08:00
|
|
|
strm.Printf("Error evaluating Print Object function: %d.\n", results);
|
2010-09-28 09:25:32 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
addr_t result_ptr = ret.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
|
|
|
|
|
Added new lldb_private::Process memory read/write functions to stop a bunch
of duplicated code from appearing all over LLDB:
lldb::addr_t
Process::ReadPointerFromMemory (lldb::addr_t vm_addr, Error &error);
bool
Process::WritePointerToMemory (lldb::addr_t vm_addr, lldb::addr_t ptr_value, Error &error);
size_t
Process::ReadScalarIntegerFromMemory (lldb::addr_t addr, uint32_t byte_size, bool is_signed, Scalar &scalar, Error &error);
size_t
Process::WriteScalarToMemory (lldb::addr_t vm_addr, const Scalar &scalar, uint32_t size, Error &error);
in lldb_private::Process the following functions were renamed:
From:
uint64_t
Process::ReadUnsignedInteger (lldb::addr_t load_addr,
size_t byte_size,
Error &error);
To:
uint64_t
Process::ReadUnsignedIntegerFromMemory (lldb::addr_t load_addr,
size_t byte_size,
uint64_t fail_value,
Error &error);
Cleaned up a lot of code that was manually doing what the above functions do
to use the functions listed above.
Added the ability to get a scalar value as a buffer that can be written down
to a process (byte swapping the Scalar value if needed):
uint32_t
Scalar::GetAsMemoryData (void *dst,
uint32_t dst_len,
lldb::ByteOrder dst_byte_order,
Error &error) const;
The "dst_len" can be smaller that the size of the scalar and the least
significant bytes will be written. "dst_len" can also be larger and the
most significant bytes will be padded with zeroes.
Centralized the code that adds or removes address bits for callable and opcode
addresses into lldb_private::Target:
lldb::addr_t
Target::GetCallableLoadAddress (lldb::addr_t load_addr, AddressClass addr_class) const;
lldb::addr_t
Target::GetOpcodeLoadAddress (lldb::addr_t load_addr, AddressClass addr_class) const;
All necessary lldb_private::Address functions now use the target versions so
changes should only need to happen in one place if anything needs updating.
Fixed up a lot of places that were calling :
addr_t
Address::GetLoadAddress(Target*);
to call the Address::GetCallableLoadAddress() or Address::GetOpcodeLoadAddress()
as needed. There were many places in the breakpoint code where things could
go wrong for ARM if these weren't used.
llvm-svn: 131878
2011-05-23 06:46:53 +08:00
|
|
|
char buf[512];
|
|
|
|
size_t cstr_len = 0;
|
2011-05-25 03:08:00 +08:00
|
|
|
size_t full_buffer_len = sizeof (buf) - 1;
|
|
|
|
size_t curr_len = full_buffer_len;
|
|
|
|
while (curr_len == full_buffer_len)
|
2010-09-28 09:25:32 +08:00
|
|
|
{
|
2011-12-15 11:14:23 +08:00
|
|
|
Error error;
|
|
|
|
curr_len = process->ReadCStringFromMemory(result_ptr + cstr_len, buf, sizeof(buf), error);
|
Added new lldb_private::Process memory read/write functions to stop a bunch
of duplicated code from appearing all over LLDB:
lldb::addr_t
Process::ReadPointerFromMemory (lldb::addr_t vm_addr, Error &error);
bool
Process::WritePointerToMemory (lldb::addr_t vm_addr, lldb::addr_t ptr_value, Error &error);
size_t
Process::ReadScalarIntegerFromMemory (lldb::addr_t addr, uint32_t byte_size, bool is_signed, Scalar &scalar, Error &error);
size_t
Process::WriteScalarToMemory (lldb::addr_t vm_addr, const Scalar &scalar, uint32_t size, Error &error);
in lldb_private::Process the following functions were renamed:
From:
uint64_t
Process::ReadUnsignedInteger (lldb::addr_t load_addr,
size_t byte_size,
Error &error);
To:
uint64_t
Process::ReadUnsignedIntegerFromMemory (lldb::addr_t load_addr,
size_t byte_size,
uint64_t fail_value,
Error &error);
Cleaned up a lot of code that was manually doing what the above functions do
to use the functions listed above.
Added the ability to get a scalar value as a buffer that can be written down
to a process (byte swapping the Scalar value if needed):
uint32_t
Scalar::GetAsMemoryData (void *dst,
uint32_t dst_len,
lldb::ByteOrder dst_byte_order,
Error &error) const;
The "dst_len" can be smaller that the size of the scalar and the least
significant bytes will be written. "dst_len" can also be larger and the
most significant bytes will be padded with zeroes.
Centralized the code that adds or removes address bits for callable and opcode
addresses into lldb_private::Target:
lldb::addr_t
Target::GetCallableLoadAddress (lldb::addr_t load_addr, AddressClass addr_class) const;
lldb::addr_t
Target::GetOpcodeLoadAddress (lldb::addr_t load_addr, AddressClass addr_class) const;
All necessary lldb_private::Address functions now use the target versions so
changes should only need to happen in one place if anything needs updating.
Fixed up a lot of places that were calling :
addr_t
Address::GetLoadAddress(Target*);
to call the Address::GetCallableLoadAddress() or Address::GetOpcodeLoadAddress()
as needed. There were many places in the breakpoint code where things could
go wrong for ARM if these weren't used.
llvm-svn: 131878
2011-05-23 06:46:53 +08:00
|
|
|
strm.Write (buf, curr_len);
|
|
|
|
cstr_len += curr_len;
|
2010-09-28 09:25:32 +08:00
|
|
|
}
|
Added new lldb_private::Process memory read/write functions to stop a bunch
of duplicated code from appearing all over LLDB:
lldb::addr_t
Process::ReadPointerFromMemory (lldb::addr_t vm_addr, Error &error);
bool
Process::WritePointerToMemory (lldb::addr_t vm_addr, lldb::addr_t ptr_value, Error &error);
size_t
Process::ReadScalarIntegerFromMemory (lldb::addr_t addr, uint32_t byte_size, bool is_signed, Scalar &scalar, Error &error);
size_t
Process::WriteScalarToMemory (lldb::addr_t vm_addr, const Scalar &scalar, uint32_t size, Error &error);
in lldb_private::Process the following functions were renamed:
From:
uint64_t
Process::ReadUnsignedInteger (lldb::addr_t load_addr,
size_t byte_size,
Error &error);
To:
uint64_t
Process::ReadUnsignedIntegerFromMemory (lldb::addr_t load_addr,
size_t byte_size,
uint64_t fail_value,
Error &error);
Cleaned up a lot of code that was manually doing what the above functions do
to use the functions listed above.
Added the ability to get a scalar value as a buffer that can be written down
to a process (byte swapping the Scalar value if needed):
uint32_t
Scalar::GetAsMemoryData (void *dst,
uint32_t dst_len,
lldb::ByteOrder dst_byte_order,
Error &error) const;
The "dst_len" can be smaller that the size of the scalar and the least
significant bytes will be written. "dst_len" can also be larger and the
most significant bytes will be padded with zeroes.
Centralized the code that adds or removes address bits for callable and opcode
addresses into lldb_private::Target:
lldb::addr_t
Target::GetCallableLoadAddress (lldb::addr_t load_addr, AddressClass addr_class) const;
lldb::addr_t
Target::GetOpcodeLoadAddress (lldb::addr_t load_addr, AddressClass addr_class) const;
All necessary lldb_private::Address functions now use the target versions so
changes should only need to happen in one place if anything needs updating.
Fixed up a lot of places that were calling :
addr_t
Address::GetLoadAddress(Target*);
to call the Address::GetCallableLoadAddress() or Address::GetOpcodeLoadAddress()
as needed. There were many places in the breakpoint code where things could
go wrong for ARM if these weren't used.
llvm-svn: 131878
2011-05-23 06:46:53 +08:00
|
|
|
return cstr_len > 0;
|
2010-09-28 09:25:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Address *
|
2010-11-05 02:30:59 +08:00
|
|
|
AppleObjCRuntime::GetPrintForDebuggerAddr()
|
2010-09-28 09:25:32 +08:00
|
|
|
{
|
|
|
|
if (!m_PrintForDebugger_addr.get())
|
|
|
|
{
|
|
|
|
ModuleList &modules = m_process->GetTarget().GetImages();
|
|
|
|
|
|
|
|
SymbolContextList contexts;
|
|
|
|
SymbolContext context;
|
|
|
|
|
The implementation of categories is now synchronization safe
Code cleanup:
- The Format Manager implementation is now split between two files: FormatClasses.{h|cpp} where the
actual formatter classes (ValueFormat, SummaryFormat, ...) are implemented and
FormatManager.{h|cpp} where the infrastructure classes (FormatNavigator, FormatManager, ...)
are contained. The wrapper code always remains in Debugger.{h|cpp}
- Several leftover fields, methods and comments from previous design choices have been removed
type category subcommands (enable, disable, delete) now can take a list of category names as input
- for type category enable, saying "enable A B C" is the same as saying
enable C
enable B
enable A
(the ordering is relevant in enabling categories, and it is expected that a user typing
enable A B C wants to look into category A, then into B, then into C and not the other
way round)
- for the other two commands, the order is not really relevant (however, the same inverted ordering
is used for consistency)
llvm-svn: 135494
2011-07-20 02:03:25 +08:00
|
|
|
if ((!modules.FindSymbolsWithNameAndType(ConstString ("_NSPrintForDebugger"), eSymbolTypeCode, contexts)) &&
|
2010-09-28 09:25:32 +08:00
|
|
|
(!modules.FindSymbolsWithNameAndType(ConstString ("_CFPrintForDebugger"), eSymbolTypeCode, contexts)))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
contexts.GetContextAtIndex(0, context);
|
|
|
|
|
2012-03-08 05:03:09 +08:00
|
|
|
m_PrintForDebugger_addr.reset(new Address(context.symbol->GetAddress()));
|
2010-09-28 09:25:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return m_PrintForDebugger_addr.get();
|
|
|
|
}
|
|
|
|
|
2011-04-16 08:01:13 +08:00
|
|
|
bool
|
|
|
|
AppleObjCRuntime::CouldHaveDynamicValue (ValueObject &in_value)
|
|
|
|
{
|
2012-05-22 00:51:35 +08:00
|
|
|
return ClangASTContext::IsPossibleDynamicType(in_value.GetClangAST(), in_value.GetClangType(),
|
|
|
|
NULL,
|
|
|
|
false, // do not check C++
|
|
|
|
true); // check ObjC
|
2011-04-16 08:01:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2011-05-04 11:43:18 +08:00
|
|
|
AppleObjCRuntime::GetDynamicTypeAndAddress (ValueObject &in_value,
|
|
|
|
lldb::DynamicValueType use_dynamic,
|
|
|
|
TypeAndOrName &class_type_or_name,
|
|
|
|
Address &address)
|
2010-09-28 09:25:32 +08:00
|
|
|
{
|
2011-04-16 08:01:13 +08:00
|
|
|
return false;
|
2010-09-28 09:25:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2010-11-05 02:30:59 +08:00
|
|
|
AppleObjCRuntime::AppleIsModuleObjCLibrary (const ModuleSP &module_sp)
|
2010-09-28 09:25:32 +08:00
|
|
|
{
|
|
|
|
const FileSpec &module_file_spec = module_sp->GetFileSpec();
|
|
|
|
static ConstString ObjCName ("libobjc.A.dylib");
|
|
|
|
|
|
|
|
if (module_file_spec)
|
|
|
|
{
|
|
|
|
if (module_file_spec.GetFilename() == ObjCName)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2010-11-05 02:30:59 +08:00
|
|
|
AppleObjCRuntime::IsModuleObjCLibrary (const ModuleSP &module_sp)
|
|
|
|
{
|
|
|
|
return AppleIsModuleObjCLibrary(module_sp);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
AppleObjCRuntime::ReadObjCLibrary (const ModuleSP &module_sp)
|
2010-09-28 09:25:32 +08:00
|
|
|
{
|
|
|
|
// Maybe check here and if we have a handler already, and the UUID of this module is the same as the one in the
|
|
|
|
// current module, then we don't have to reread it?
|
2012-01-30 04:56:30 +08:00
|
|
|
m_objc_trampoline_handler_ap.reset(new AppleObjCTrampolineHandler (m_process->shared_from_this(), module_sp));
|
2010-09-28 09:25:32 +08:00
|
|
|
if (m_objc_trampoline_handler_ap.get() != NULL)
|
|
|
|
{
|
|
|
|
m_read_objc_library = true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
ThreadPlanSP
|
2010-11-05 02:30:59 +08:00
|
|
|
AppleObjCRuntime::GetStepThroughTrampolinePlan (Thread &thread, bool stop_others)
|
2010-09-28 09:25:32 +08:00
|
|
|
{
|
|
|
|
ThreadPlanSP thread_plan_sp;
|
2010-09-29 00:06:31 +08:00
|
|
|
if (m_objc_trampoline_handler_ap.get())
|
|
|
|
thread_plan_sp = m_objc_trampoline_handler_ap->GetStepThroughDispatchPlan (thread, stop_others);
|
2010-09-28 09:25:32 +08:00
|
|
|
return thread_plan_sp;
|
|
|
|
}
|
|
|
|
|
2010-09-23 10:01:19 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
// Static Functions
|
|
|
|
//------------------------------------------------------------------
|
2011-03-25 05:19:54 +08:00
|
|
|
enum ObjCRuntimeVersions
|
2010-11-05 08:57:06 +08:00
|
|
|
AppleObjCRuntime::GetObjCVersion (Process *process, ModuleSP &objc_module_sp)
|
2010-09-23 10:01:19 +08:00
|
|
|
{
|
2012-03-10 03:59:28 +08:00
|
|
|
if (!process)
|
|
|
|
return eObjC_VersionUnknown;
|
|
|
|
|
|
|
|
Target &target = process->GetTarget();
|
2012-05-30 10:19:25 +08:00
|
|
|
ModuleList &target_modules = target.GetImages();
|
|
|
|
Mutex::Locker modules_locker(target_modules.GetMutex());
|
|
|
|
|
|
|
|
size_t num_images = target_modules.GetSize();
|
2010-11-05 02:30:59 +08:00
|
|
|
for (size_t i = 0; i < num_images; i++)
|
|
|
|
{
|
2012-05-30 10:19:25 +08:00
|
|
|
ModuleSP module_sp = target_modules.GetModuleAtIndexUnlocked(i);
|
2012-03-10 03:59:28 +08:00
|
|
|
// One tricky bit here is that we might get called as part of the initial module loading, but
|
|
|
|
// before all the pre-run libraries get winnowed from the module list. So there might actually
|
|
|
|
// be an old and incorrect ObjC library sitting around in the list, and we don't want to look at that.
|
|
|
|
// That's why we call IsLoadedInTarget.
|
|
|
|
|
|
|
|
if (AppleIsModuleObjCLibrary (module_sp) && module_sp->IsLoadedInTarget(&target))
|
2010-11-05 02:30:59 +08:00
|
|
|
{
|
2010-11-05 08:57:06 +08:00
|
|
|
objc_module_sp = module_sp;
|
2010-11-05 02:30:59 +08:00
|
|
|
ObjectFile *ofile = module_sp->GetObjectFile();
|
|
|
|
if (!ofile)
|
2011-03-25 05:19:54 +08:00
|
|
|
return eObjC_VersionUnknown;
|
2010-11-05 02:30:59 +08:00
|
|
|
|
|
|
|
SectionList *sections = ofile->GetSectionList();
|
|
|
|
if (!sections)
|
2011-03-25 05:19:54 +08:00
|
|
|
return eObjC_VersionUnknown;
|
2010-11-05 02:30:59 +08:00
|
|
|
SectionSP v1_telltale_section_sp = sections->FindSectionByName(ConstString ("__OBJC"));
|
|
|
|
if (v1_telltale_section_sp)
|
|
|
|
{
|
2011-03-25 05:19:54 +08:00
|
|
|
return eAppleObjC_V1;
|
2010-11-05 02:30:59 +08:00
|
|
|
}
|
2011-03-25 05:19:54 +08:00
|
|
|
return eAppleObjC_V2;
|
2010-11-05 02:30:59 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-25 05:19:54 +08:00
|
|
|
return eObjC_VersionUnknown;
|
2010-09-23 10:01:19 +08:00
|
|
|
}
|
|
|
|
|
2012-03-03 10:05:11 +08:00
|
|
|
void
|
|
|
|
AppleObjCRuntime::SetExceptionBreakpoints ()
|
|
|
|
{
|
|
|
|
const bool catch_bp = false;
|
|
|
|
const bool throw_bp = true;
|
|
|
|
const bool is_internal = true;
|
|
|
|
|
|
|
|
if (!m_objc_exception_bp_sp)
|
2012-03-05 12:47:34 +08:00
|
|
|
m_objc_exception_bp_sp = LanguageRuntime::CreateExceptionBreakpoint (m_process->GetTarget(),
|
|
|
|
GetLanguageType(),
|
|
|
|
catch_bp,
|
|
|
|
throw_bp,
|
|
|
|
is_internal);
|
2012-03-03 10:05:11 +08:00
|
|
|
else
|
|
|
|
m_objc_exception_bp_sp->SetEnabled(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-11-04 06:19:38 +08:00
|
|
|
void
|
2010-11-05 02:30:59 +08:00
|
|
|
AppleObjCRuntime::ClearExceptionBreakpoints ()
|
2010-11-04 06:19:38 +08:00
|
|
|
{
|
|
|
|
if (!m_process)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (m_objc_exception_bp_sp.get())
|
|
|
|
{
|
2011-07-23 08:12:05 +08:00
|
|
|
m_objc_exception_bp_sp->SetEnabled (false);
|
2010-11-04 06:19:38 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2010-11-05 02:30:59 +08:00
|
|
|
AppleObjCRuntime::ExceptionBreakpointsExplainStop (lldb::StopInfoSP stop_reason)
|
2010-11-04 06:19:38 +08:00
|
|
|
{
|
|
|
|
if (!m_process)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (!stop_reason ||
|
|
|
|
stop_reason->GetStopReason() != eStopReasonBreakpoint)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
uint64_t break_site_id = stop_reason->GetValue();
|
2012-03-09 12:10:47 +08:00
|
|
|
return m_process->GetBreakpointSiteList().BreakpointSiteContainsBreakpoint (break_site_id,
|
|
|
|
m_objc_exception_bp_sp->GetID());
|
2010-11-04 06:19:38 +08:00
|
|
|
}
|
2012-03-08 10:39:03 +08:00
|
|
|
|
|
|
|
bool
|
|
|
|
AppleObjCRuntime::CalculateHasNewLiteralsAndIndexing()
|
|
|
|
{
|
|
|
|
if (!m_process)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
Target &target(m_process->GetTarget());
|
|
|
|
|
|
|
|
static ConstString s_method_signature("-[NSDictionary objectForKeyedSubscript:]");
|
2012-05-18 07:29:56 +08:00
|
|
|
static ConstString s_arclite_method_signature("__arclite_objectForKeyedSubscript");
|
2012-03-08 10:39:03 +08:00
|
|
|
|
|
|
|
SymbolContextList sc_list;
|
|
|
|
|
2012-05-18 07:29:56 +08:00
|
|
|
if (target.GetImages().FindSymbolsWithNameAndType(s_method_signature, eSymbolTypeCode, sc_list) ||
|
|
|
|
target.GetImages().FindSymbolsWithNameAndType(s_arclite_method_signature, eSymbolTypeCode, sc_list))
|
2012-03-08 10:39:03 +08:00
|
|
|
return true;
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
}
|