2010-06-09 00:52:24 +08:00
|
|
|
//===-- Address.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/Address.h"
|
|
|
|
#include "lldb/Core/Module.h"
|
|
|
|
#include "lldb/Core/Section.h"
|
|
|
|
#include "lldb/Symbol/ObjectFile.h"
|
2011-07-11 13:12:02 +08:00
|
|
|
#include "lldb/Symbol/Variable.h"
|
|
|
|
#include "lldb/Symbol/VariableList.h"
|
2010-09-15 07:36:40 +08:00
|
|
|
#include "lldb/Target/ExecutionContext.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
#include "lldb/Target/Process.h"
|
|
|
|
#include "lldb/Target/Target.h"
|
|
|
|
|
2011-05-19 06:01:49 +08:00
|
|
|
#include "llvm/ADT/Triple.h"
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
using namespace lldb;
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
|
|
|
static size_t
|
|
|
|
ReadBytes (ExecutionContextScope *exe_scope, const Address &address, void *dst, size_t dst_len)
|
|
|
|
{
|
|
|
|
if (exe_scope == NULL)
|
|
|
|
return 0;
|
|
|
|
|
2012-02-18 13:35:26 +08:00
|
|
|
TargetSP target_sp (exe_scope->CalculateTarget());
|
|
|
|
if (target_sp)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
Error error;
|
2011-01-07 09:57:07 +08:00
|
|
|
bool prefer_file_cache = false;
|
2012-02-18 13:35:26 +08:00
|
|
|
return target_sp->ReadMemory (address, prefer_file_cache, dst, dst_len, error);
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
|
|
|
GetByteOrderAndAddressSize (ExecutionContextScope *exe_scope, const Address &address, ByteOrder& byte_order, uint32_t& addr_size)
|
|
|
|
{
|
|
|
|
byte_order = eByteOrderInvalid;
|
|
|
|
addr_size = 0;
|
|
|
|
if (exe_scope == NULL)
|
|
|
|
return false;
|
|
|
|
|
2012-02-18 13:35:26 +08:00
|
|
|
TargetSP target_sp (exe_scope->CalculateTarget());
|
|
|
|
if (target_sp)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2012-02-18 13:35:26 +08:00
|
|
|
byte_order = target_sp->GetArchitecture().GetByteOrder();
|
|
|
|
addr_size = target_sp->GetArchitecture().GetAddressByteSize();
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (byte_order == eByteOrderInvalid || addr_size == 0)
|
|
|
|
{
|
2012-02-24 09:59:29 +08:00
|
|
|
ModuleSP module_sp (address.GetModule());
|
|
|
|
if (module_sp)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2012-02-24 09:59:29 +08:00
|
|
|
byte_order = module_sp->GetArchitecture().GetByteOrder();
|
|
|
|
addr_size = module_sp->GetArchitecture().GetAddressByteSize();
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return byte_order != eByteOrderInvalid && addr_size != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static uint64_t
|
|
|
|
ReadUIntMax64 (ExecutionContextScope *exe_scope, const Address &address, uint32_t byte_size, bool &success)
|
|
|
|
{
|
|
|
|
uint64_t uval64 = 0;
|
|
|
|
if (exe_scope == NULL || byte_size > sizeof(uint64_t))
|
|
|
|
{
|
|
|
|
success = false;
|
|
|
|
return 0;
|
|
|
|
}
|
2011-08-26 01:40:39 +08:00
|
|
|
uint64_t buf = 0;
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
success = ReadBytes (exe_scope, address, &buf, byte_size) == byte_size;
|
|
|
|
if (success)
|
|
|
|
{
|
|
|
|
ByteOrder byte_order = eByteOrderInvalid;
|
|
|
|
uint32_t addr_size = 0;
|
|
|
|
if (GetByteOrderAndAddressSize (exe_scope, address, byte_order, addr_size))
|
|
|
|
{
|
|
|
|
DataExtractor data (&buf, sizeof(buf), byte_order, addr_size);
|
|
|
|
uint32_t offset = 0;
|
|
|
|
uval64 = data.GetU64(&offset);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
success = false;
|
|
|
|
}
|
|
|
|
return uval64;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
|
|
|
ReadAddress (ExecutionContextScope *exe_scope, const Address &address, uint32_t pointer_size, Address &deref_so_addr)
|
|
|
|
{
|
|
|
|
if (exe_scope == NULL)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
|
|
bool success = false;
|
|
|
|
addr_t deref_addr = ReadUIntMax64 (exe_scope, address, pointer_size, success);
|
|
|
|
if (success)
|
|
|
|
{
|
2010-09-15 07:36:40 +08:00
|
|
|
ExecutionContext exe_ctx;
|
2010-10-04 09:05:56 +08:00
|
|
|
exe_scope->CalculateExecutionContext(exe_ctx);
|
2010-09-15 07:36:40 +08:00
|
|
|
// If we have any sections that are loaded, try and resolve using the
|
|
|
|
// section load list
|
2011-09-22 12:58:26 +08:00
|
|
|
Target *target = exe_ctx.GetTargetPtr();
|
|
|
|
if (target && !target->GetSectionLoadList().IsEmpty())
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2011-09-22 12:58:26 +08:00
|
|
|
if (target->GetSectionLoadList().ResolveLoadAddress (deref_addr, deref_so_addr))
|
2010-09-15 07:36:40 +08:00
|
|
|
return true;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-09-15 07:36:40 +08:00
|
|
|
// If we were not running, yet able to read an integer, we must
|
|
|
|
// have a module
|
2012-02-24 09:59:29 +08:00
|
|
|
ModuleSP module_sp (address.GetModule());
|
|
|
|
|
|
|
|
assert (module_sp);
|
|
|
|
if (module_sp->ResolveFileAddress(deref_addr, deref_so_addr))
|
2010-09-15 07:36:40 +08:00
|
|
|
return true;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
2010-09-15 07:36:40 +08:00
|
|
|
|
|
|
|
// We couldn't make "deref_addr" into a section offset value, but we were
|
|
|
|
// able to read the address, so we return a section offset address with
|
|
|
|
// no section and "deref_addr" as the offset (address).
|
2012-02-24 09:59:29 +08:00
|
|
|
deref_so_addr.SetRawAddress(deref_addr);
|
2010-06-09 00:52:24 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
|
|
|
DumpUInt (ExecutionContextScope *exe_scope, const Address &address, uint32_t byte_size, Stream* strm)
|
|
|
|
{
|
2010-07-21 06:52:08 +08:00
|
|
|
if (exe_scope == NULL || byte_size == 0)
|
2010-06-09 00:52:24 +08:00
|
|
|
return 0;
|
|
|
|
std::vector<uint8_t> buf(byte_size, 0);
|
|
|
|
|
|
|
|
if (ReadBytes (exe_scope, address, &buf[0], buf.size()) == buf.size())
|
|
|
|
{
|
|
|
|
ByteOrder byte_order = eByteOrderInvalid;
|
|
|
|
uint32_t addr_size = 0;
|
|
|
|
if (GetByteOrderAndAddressSize (exe_scope, address, byte_order, addr_size))
|
|
|
|
{
|
2010-07-21 06:52:08 +08:00
|
|
|
DataExtractor data (&buf.front(), buf.size(), byte_order, addr_size);
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
data.Dump (strm,
|
|
|
|
0, // Start offset in "data"
|
|
|
|
eFormatHex, // Print as characters
|
|
|
|
buf.size(), // Size of item
|
|
|
|
1, // Items count
|
|
|
|
UINT32_MAX, // num per line
|
|
|
|
LLDB_INVALID_ADDRESS,// base address
|
|
|
|
0, // bitfield bit size
|
|
|
|
0); // bitfield bit offset
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static size_t
|
|
|
|
ReadCStringFromMemory (ExecutionContextScope *exe_scope, const Address &address, Stream *strm)
|
|
|
|
{
|
|
|
|
if (exe_scope == NULL)
|
|
|
|
return 0;
|
|
|
|
const size_t k_buf_len = 256;
|
|
|
|
char buf[k_buf_len+1];
|
|
|
|
buf[k_buf_len] = '\0'; // NULL terminate
|
|
|
|
|
2011-01-09 04:28:42 +08:00
|
|
|
// Byte order and address size don't matter for C string dumping..
|
2011-02-01 09:31:41 +08:00
|
|
|
DataExtractor data (buf, sizeof(buf), lldb::endian::InlHostByteOrder(), 4);
|
2010-06-09 00:52:24 +08:00
|
|
|
size_t total_len = 0;
|
|
|
|
size_t bytes_read;
|
|
|
|
Address curr_address(address);
|
|
|
|
strm->PutChar ('"');
|
|
|
|
while ((bytes_read = ReadBytes (exe_scope, curr_address, buf, k_buf_len)) > 0)
|
|
|
|
{
|
|
|
|
size_t len = strlen(buf);
|
|
|
|
if (len == 0)
|
|
|
|
break;
|
|
|
|
if (len > bytes_read)
|
|
|
|
len = bytes_read;
|
|
|
|
|
|
|
|
data.Dump (strm,
|
|
|
|
0, // Start offset in "data"
|
|
|
|
eFormatChar, // Print as characters
|
|
|
|
1, // Size of item (1 byte for a char!)
|
|
|
|
len, // How many bytes to print?
|
|
|
|
UINT32_MAX, // num per line
|
|
|
|
LLDB_INVALID_ADDRESS,// base address
|
|
|
|
0, // bitfield bit size
|
|
|
|
|
|
|
|
0); // bitfield bit offset
|
|
|
|
|
|
|
|
total_len += bytes_read;
|
|
|
|
|
|
|
|
if (len < k_buf_len)
|
|
|
|
break;
|
|
|
|
curr_address.SetOffset (curr_address.GetOffset() + bytes_read);
|
|
|
|
}
|
|
|
|
strm->PutChar ('"');
|
|
|
|
return total_len;
|
|
|
|
}
|
|
|
|
|
2012-02-24 09:59:29 +08:00
|
|
|
Address::Address (lldb::addr_t abs_addr) :
|
|
|
|
m_section_wp (),
|
|
|
|
m_offset (abs_addr)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
Address::Address (addr_t address, const SectionList *section_list) :
|
|
|
|
m_section_wp (),
|
2010-06-09 00:52:24 +08:00
|
|
|
m_offset (LLDB_INVALID_ADDRESS)
|
|
|
|
{
|
2012-02-24 09:59:29 +08:00
|
|
|
ResolveAddressUsingFileSections(address, section_list);
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
const Address&
|
|
|
|
Address::operator= (const Address& rhs)
|
|
|
|
{
|
|
|
|
if (this != &rhs)
|
|
|
|
{
|
2012-02-24 09:59:29 +08:00
|
|
|
m_section_wp = rhs.m_section_wp;
|
2010-06-09 00:52:24 +08:00
|
|
|
m_offset = rhs.m_offset;
|
|
|
|
}
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2012-02-24 09:59:29 +08:00
|
|
|
Address::ResolveAddressUsingFileSections (addr_t file_addr, const SectionList *section_list)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2012-02-24 09:59:29 +08:00
|
|
|
if (section_list)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2012-02-24 09:59:29 +08:00
|
|
|
SectionSP section_sp (section_list->FindSectionContainingFileAddress(file_addr));
|
|
|
|
m_section_wp = section_sp;
|
|
|
|
if (section_sp)
|
|
|
|
{
|
|
|
|
assert( section_sp->ContainsFileAddress(file_addr) );
|
|
|
|
m_offset = file_addr - section_sp->GetFileAddress();
|
|
|
|
return true; // Successfully transformed addr into a section offset address
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
2012-02-24 09:59:29 +08:00
|
|
|
m_offset = file_addr;
|
2010-06-09 00:52:24 +08:00
|
|
|
return false; // Failed to resolve this address to a section offset value
|
|
|
|
}
|
|
|
|
|
2012-01-30 04:56:30 +08:00
|
|
|
ModuleSP
|
2012-02-24 09:59:29 +08:00
|
|
|
Address::GetModule () const
|
2012-01-30 04:56:30 +08:00
|
|
|
{
|
|
|
|
lldb::ModuleSP module_sp;
|
2012-02-24 09:59:29 +08:00
|
|
|
SectionSP section_sp (GetSection());
|
|
|
|
if (section_sp)
|
|
|
|
module_sp = section_sp->GetModule();
|
2012-01-30 04:56:30 +08:00
|
|
|
return module_sp;
|
|
|
|
}
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
addr_t
|
|
|
|
Address::GetFileAddress () const
|
|
|
|
{
|
2012-02-24 09:59:29 +08:00
|
|
|
SectionSP section_sp (GetSection());
|
|
|
|
if (section_sp)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2012-02-24 09:59:29 +08:00
|
|
|
addr_t sect_file_addr = section_sp->GetFileAddress();
|
2010-06-09 00:52:24 +08:00
|
|
|
if (sect_file_addr == LLDB_INVALID_ADDRESS)
|
|
|
|
{
|
|
|
|
// Section isn't resolved, we can't return a valid file address
|
|
|
|
return LLDB_INVALID_ADDRESS;
|
|
|
|
}
|
|
|
|
// We have a valid file range, so we can return the file based
|
|
|
|
// address by adding the file base address to our offset
|
|
|
|
return sect_file_addr + m_offset;
|
|
|
|
}
|
|
|
|
// No section, we just return the offset since it is the value in this case
|
|
|
|
return m_offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
addr_t
|
2010-09-15 07:36:40 +08:00
|
|
|
Address::GetLoadAddress (Target *target) const
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2012-02-24 09:59:29 +08:00
|
|
|
SectionSP section_sp (GetSection());
|
|
|
|
if (!section_sp)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2010-09-15 07:36:40 +08:00
|
|
|
// No section, we just return the offset since it is the value in this case
|
|
|
|
return m_offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (target)
|
|
|
|
{
|
2012-02-24 09:59:29 +08:00
|
|
|
addr_t sect_load_addr = section_sp->GetLoadBaseAddress (target);
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2010-09-15 07:36:40 +08:00
|
|
|
if (sect_load_addr != LLDB_INVALID_ADDRESS)
|
|
|
|
{
|
|
|
|
// We have a valid file range, so we can return the file based
|
|
|
|
// address by adding the file base address to our offset
|
|
|
|
return sect_load_addr + m_offset;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
}
|
2010-09-15 07:36:40 +08:00
|
|
|
// The section isn't resolved or no process was supplied so we can't
|
|
|
|
// return a valid file address.
|
|
|
|
return LLDB_INVALID_ADDRESS;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2011-05-19 06:01:49 +08:00
|
|
|
addr_t
|
|
|
|
Address::GetCallableLoadAddress (Target *target) const
|
|
|
|
{
|
|
|
|
addr_t code_addr = GetLoadAddress (target);
|
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
|
|
|
|
|
|
|
if (target)
|
|
|
|
return target->GetCallableLoadAddress (code_addr, GetAddressClass());
|
2011-05-19 06:01:49 +08:00
|
|
|
return code_addr;
|
|
|
|
}
|
|
|
|
|
2011-05-22 12:32:55 +08:00
|
|
|
bool
|
|
|
|
Address::SetCallableLoadAddress (lldb::addr_t load_addr, Target *target)
|
|
|
|
{
|
|
|
|
if (SetLoadAddress (load_addr, target))
|
|
|
|
{
|
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
|
|
|
if (target)
|
|
|
|
m_offset = target->GetCallableLoadAddress(m_offset, GetAddressClass());
|
2011-05-22 12:32:55 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-05-20 02:17:41 +08:00
|
|
|
addr_t
|
|
|
|
Address::GetOpcodeLoadAddress (Target *target) const
|
|
|
|
{
|
|
|
|
addr_t code_addr = GetLoadAddress (target);
|
|
|
|
if (code_addr != 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
|
|
|
code_addr = target->GetOpcodeLoadAddress (code_addr, GetAddressClass());
|
2011-05-20 02:17:41 +08:00
|
|
|
return code_addr;
|
|
|
|
}
|
|
|
|
|
2011-05-22 12:32:55 +08:00
|
|
|
bool
|
|
|
|
Address::SetOpcodeLoadAddress (lldb::addr_t load_addr, Target *target)
|
|
|
|
{
|
|
|
|
if (SetLoadAddress (load_addr, target))
|
|
|
|
{
|
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
|
|
|
if (target)
|
|
|
|
m_offset = target->GetOpcodeLoadAddress (m_offset, GetAddressClass());
|
2011-05-22 12:32:55 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
bool
|
2010-07-01 07:03:03 +08:00
|
|
|
Address::Dump (Stream *s, ExecutionContextScope *exe_scope, DumpStyle style, DumpStyle fallback_style, uint32_t addr_size) const
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
// If the section was NULL, only load address is going to work.
|
2012-02-24 09:59:29 +08:00
|
|
|
SectionSP section_sp (GetSection());
|
|
|
|
if (!section_sp)
|
2010-06-09 00:52:24 +08:00
|
|
|
style = DumpStyleLoadAddress;
|
|
|
|
|
2012-02-18 13:35:26 +08:00
|
|
|
ExecutionContext exe_ctx (exe_scope);
|
|
|
|
Target *target = exe_ctx.GetTargetPtr();
|
2010-07-01 07:03:03 +08:00
|
|
|
// If addr_byte_size is UINT32_MAX, then determine the correct address
|
|
|
|
// byte size for the process or default to the size of addr_t
|
|
|
|
if (addr_size == UINT32_MAX)
|
|
|
|
{
|
2012-02-18 13:35:26 +08:00
|
|
|
if (target)
|
2011-02-16 05:59:32 +08:00
|
|
|
addr_size = target->GetArchitecture().GetAddressByteSize ();
|
2010-07-01 07:03:03 +08:00
|
|
|
else
|
|
|
|
addr_size = sizeof(addr_t);
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2010-09-10 09:30:46 +08:00
|
|
|
Address so_addr;
|
2010-06-09 00:52:24 +08:00
|
|
|
switch (style)
|
|
|
|
{
|
2010-07-10 04:39:50 +08:00
|
|
|
case DumpStyleInvalid:
|
|
|
|
return false;
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
case DumpStyleSectionNameOffset:
|
2012-02-24 09:59:29 +08:00
|
|
|
if (section_sp)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2012-02-24 09:59:29 +08:00
|
|
|
section_sp->DumpName(s);
|
2010-06-09 00:52:24 +08:00
|
|
|
s->Printf (" + %llu", m_offset);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-07-01 07:03:03 +08:00
|
|
|
s->Address(m_offset, addr_size);
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DumpStyleSectionPointerOffset:
|
2012-02-24 09:59:29 +08:00
|
|
|
s->Printf("(Section *)%p + ", section_sp.get());
|
2010-07-01 07:03:03 +08:00
|
|
|
s->Address(m_offset, addr_size);
|
2010-06-09 00:52:24 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case DumpStyleModuleWithFileAddress:
|
2012-02-24 09:59:29 +08:00
|
|
|
if (section_sp)
|
|
|
|
s->Printf("%s[", section_sp->GetModule()->GetFileSpec().GetFilename().AsCString());
|
2010-06-09 00:52:24 +08:00
|
|
|
// Fall through
|
|
|
|
case DumpStyleFileAddress:
|
|
|
|
{
|
|
|
|
addr_t file_addr = GetFileAddress();
|
|
|
|
if (file_addr == LLDB_INVALID_ADDRESS)
|
|
|
|
{
|
|
|
|
if (fallback_style != DumpStyleInvalid)
|
2010-07-01 07:03:03 +08:00
|
|
|
return Dump (s, exe_scope, fallback_style, DumpStyleInvalid, addr_size);
|
2010-06-09 00:52:24 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
s->Address (file_addr, addr_size);
|
2012-02-24 09:59:29 +08:00
|
|
|
if (style == DumpStyleModuleWithFileAddress && section_sp)
|
2010-06-09 00:52:24 +08:00
|
|
|
s->PutChar(']');
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DumpStyleLoadAddress:
|
|
|
|
{
|
2010-09-15 07:36:40 +08:00
|
|
|
addr_t load_addr = GetLoadAddress (target);
|
2010-06-09 00:52:24 +08:00
|
|
|
if (load_addr == LLDB_INVALID_ADDRESS)
|
|
|
|
{
|
|
|
|
if (fallback_style != DumpStyleInvalid)
|
2010-07-01 07:03:03 +08:00
|
|
|
return Dump (s, exe_scope, fallback_style, DumpStyleInvalid, addr_size);
|
2010-06-09 00:52:24 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
s->Address (load_addr, addr_size);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DumpStyleResolvedDescription:
|
2010-07-01 09:26:43 +08:00
|
|
|
case DumpStyleResolvedDescriptionNoModule:
|
2010-06-09 00:52:24 +08:00
|
|
|
if (IsSectionOffset())
|
|
|
|
{
|
2011-03-25 05:19:54 +08:00
|
|
|
AddressType addr_type = eAddressTypeLoad;
|
2010-09-15 07:36:40 +08:00
|
|
|
addr_t addr = GetLoadAddress (target);
|
2010-06-09 00:52:24 +08:00
|
|
|
if (addr == LLDB_INVALID_ADDRESS)
|
|
|
|
{
|
|
|
|
addr = GetFileAddress();
|
|
|
|
addr_type = eAddressTypeFile;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t pointer_size = 4;
|
2012-02-24 09:59:29 +08:00
|
|
|
ModuleSP module_sp (GetModule());
|
2011-02-16 05:59:32 +08:00
|
|
|
if (target)
|
|
|
|
pointer_size = target->GetArchitecture().GetAddressByteSize();
|
2012-02-24 09:59:29 +08:00
|
|
|
else if (module_sp)
|
|
|
|
pointer_size = module_sp->GetArchitecture().GetAddressByteSize();
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
bool showed_info = false;
|
2012-02-24 09:59:29 +08:00
|
|
|
if (section_sp)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2012-02-24 09:59:29 +08:00
|
|
|
SectionType sect_type = section_sp->GetType();
|
2010-06-09 00:52:24 +08:00
|
|
|
switch (sect_type)
|
|
|
|
{
|
2010-10-08 08:21:05 +08:00
|
|
|
case eSectionTypeData:
|
2012-02-24 09:59:29 +08:00
|
|
|
if (module_sp)
|
2010-10-08 08:21:05 +08:00
|
|
|
{
|
2012-02-24 09:59:29 +08:00
|
|
|
ObjectFile *objfile = module_sp->GetObjectFile();
|
2010-10-08 08:21:05 +08:00
|
|
|
if (objfile)
|
|
|
|
{
|
|
|
|
Symtab *symtab = objfile->GetSymtab();
|
|
|
|
if (symtab)
|
|
|
|
{
|
|
|
|
const addr_t file_Addr = GetFileAddress();
|
|
|
|
Symbol *symbol = symtab->FindSymbolContainingFileAddress (file_Addr);
|
|
|
|
if (symbol)
|
|
|
|
{
|
|
|
|
const char *symbol_name = symbol->GetName().AsCString();
|
|
|
|
if (symbol_name)
|
|
|
|
{
|
|
|
|
s->PutCString(symbol_name);
|
2012-03-08 05:03:09 +08:00
|
|
|
addr_t delta = file_Addr - symbol->GetAddress().GetFileAddress();
|
2010-10-08 08:21:05 +08:00
|
|
|
if (delta)
|
|
|
|
s->Printf(" + %llu", delta);
|
|
|
|
showed_info = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
case eSectionTypeDataCString:
|
|
|
|
// Read the C string from memory and display it
|
|
|
|
showed_info = true;
|
|
|
|
ReadCStringFromMemory (exe_scope, *this, s);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case eSectionTypeDataCStringPointers:
|
|
|
|
{
|
|
|
|
if (ReadAddress (exe_scope, *this, pointer_size, so_addr))
|
|
|
|
{
|
|
|
|
#if VERBOSE_OUTPUT
|
|
|
|
s->PutCString("(char *)");
|
|
|
|
so_addr.Dump(s, exe_scope, DumpStyleLoadAddress, DumpStyleFileAddress);
|
|
|
|
s->PutCString(": ");
|
|
|
|
#endif
|
|
|
|
showed_info = true;
|
|
|
|
ReadCStringFromMemory (exe_scope, so_addr, s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case eSectionTypeDataObjCMessageRefs:
|
|
|
|
{
|
|
|
|
if (ReadAddress (exe_scope, *this, pointer_size, so_addr))
|
|
|
|
{
|
2010-07-01 09:26:43 +08:00
|
|
|
if (target && so_addr.IsSectionOffset())
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2010-09-10 09:30:46 +08:00
|
|
|
SymbolContext func_sc;
|
2010-07-01 09:26:43 +08:00
|
|
|
target->GetImages().ResolveSymbolContextForAddress (so_addr,
|
2012-02-18 13:35:26 +08:00
|
|
|
eSymbolContextEverything,
|
|
|
|
func_sc);
|
2010-06-09 00:52:24 +08:00
|
|
|
if (func_sc.function || func_sc.symbol)
|
|
|
|
{
|
|
|
|
showed_info = true;
|
|
|
|
#if VERBOSE_OUTPUT
|
|
|
|
s->PutCString ("(objc_msgref *) -> { (func*)");
|
|
|
|
so_addr.Dump(s, exe_scope, DumpStyleLoadAddress, DumpStyleFileAddress);
|
|
|
|
#else
|
|
|
|
s->PutCString ("{ ");
|
|
|
|
#endif
|
|
|
|
Address cstr_addr(*this);
|
|
|
|
cstr_addr.SetOffset(cstr_addr.GetOffset() + pointer_size);
|
2010-09-03 05:44:10 +08:00
|
|
|
func_sc.DumpStopContext(s, exe_scope, so_addr, true, true, false);
|
2010-06-09 00:52:24 +08:00
|
|
|
if (ReadAddress (exe_scope, cstr_addr, pointer_size, so_addr))
|
|
|
|
{
|
|
|
|
#if VERBOSE_OUTPUT
|
|
|
|
s->PutCString("), (char *)");
|
|
|
|
so_addr.Dump(s, exe_scope, DumpStyleLoadAddress, DumpStyleFileAddress);
|
|
|
|
s->PutCString(" (");
|
|
|
|
#else
|
|
|
|
s->PutCString(", ");
|
|
|
|
#endif
|
|
|
|
ReadCStringFromMemory (exe_scope, so_addr, s);
|
|
|
|
}
|
|
|
|
#if VERBOSE_OUTPUT
|
|
|
|
s->PutCString(") }");
|
|
|
|
#else
|
|
|
|
s->PutCString(" }");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case eSectionTypeDataObjCCFStrings:
|
|
|
|
{
|
|
|
|
Address cfstring_data_addr(*this);
|
|
|
|
cfstring_data_addr.SetOffset(cfstring_data_addr.GetOffset() + (2 * pointer_size));
|
|
|
|
if (ReadAddress (exe_scope, cfstring_data_addr, pointer_size, so_addr))
|
|
|
|
{
|
|
|
|
#if VERBOSE_OUTPUT
|
|
|
|
s->PutCString("(CFString *) ");
|
|
|
|
cfstring_data_addr.Dump(s, exe_scope, DumpStyleLoadAddress, DumpStyleFileAddress);
|
|
|
|
s->PutCString(" -> @");
|
|
|
|
#else
|
|
|
|
s->PutChar('@');
|
|
|
|
#endif
|
|
|
|
if (so_addr.Dump(s, exe_scope, DumpStyleResolvedDescription))
|
|
|
|
showed_info = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case eSectionTypeData4:
|
|
|
|
// Read the 4 byte data and display it
|
|
|
|
showed_info = true;
|
|
|
|
s->PutCString("(uint32_t) ");
|
|
|
|
DumpUInt (exe_scope, *this, 4, s);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case eSectionTypeData8:
|
|
|
|
// Read the 8 byte data and display it
|
|
|
|
showed_info = true;
|
|
|
|
s->PutCString("(uint64_t) ");
|
|
|
|
DumpUInt (exe_scope, *this, 8, s);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case eSectionTypeData16:
|
|
|
|
// Read the 16 byte data and display it
|
|
|
|
showed_info = true;
|
|
|
|
s->PutCString("(uint128_t) ");
|
|
|
|
DumpUInt (exe_scope, *this, 16, s);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case eSectionTypeDataPointers:
|
|
|
|
// Read the pointer data and display it
|
|
|
|
{
|
|
|
|
if (ReadAddress (exe_scope, *this, pointer_size, so_addr))
|
|
|
|
{
|
|
|
|
s->PutCString ("(void *)");
|
|
|
|
so_addr.Dump(s, exe_scope, DumpStyleLoadAddress, DumpStyleFileAddress);
|
|
|
|
|
|
|
|
showed_info = true;
|
|
|
|
if (so_addr.IsSectionOffset())
|
|
|
|
{
|
2010-09-10 09:30:46 +08:00
|
|
|
SymbolContext pointer_sc;
|
2010-07-01 07:03:03 +08:00
|
|
|
if (target)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2010-07-01 07:03:03 +08:00
|
|
|
target->GetImages().ResolveSymbolContextForAddress (so_addr,
|
2012-02-18 13:35:26 +08:00
|
|
|
eSymbolContextEverything,
|
|
|
|
pointer_sc);
|
2010-07-01 07:03:03 +08:00
|
|
|
if (pointer_sc.function || pointer_sc.symbol)
|
|
|
|
{
|
|
|
|
s->PutCString(": ");
|
2010-09-03 05:44:10 +08:00
|
|
|
pointer_sc.DumpStopContext(s, exe_scope, so_addr, true, false, false);
|
2010-07-01 07:03:03 +08:00
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2010-07-10 04:39:50 +08:00
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!showed_info)
|
|
|
|
{
|
2012-02-24 09:59:29 +08:00
|
|
|
if (module_sp)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2010-09-10 09:30:46 +08:00
|
|
|
SymbolContext sc;
|
2012-02-24 09:59:29 +08:00
|
|
|
module_sp->ResolveSymbolContextForAddress(*this, eSymbolContextEverything, sc);
|
2010-06-09 00:52:24 +08:00
|
|
|
if (sc.function || sc.symbol)
|
|
|
|
{
|
|
|
|
bool show_stop_context = true;
|
2010-09-08 05:56:53 +08:00
|
|
|
const bool show_module = (style == DumpStyleResolvedDescription);
|
|
|
|
const bool show_fullpaths = false;
|
2011-01-29 15:10:55 +08:00
|
|
|
const bool show_inlined_frames = true;
|
2010-06-09 00:52:24 +08:00
|
|
|
if (sc.function == NULL && sc.symbol != NULL)
|
|
|
|
{
|
|
|
|
// If we have just a symbol make sure it is in the right section
|
2012-03-08 05:03:09 +08:00
|
|
|
if (sc.symbol->ValueIsAddress())
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2012-03-08 05:03:09 +08:00
|
|
|
if (sc.symbol->GetAddress().GetSection() != GetSection())
|
2010-07-01 09:26:43 +08:00
|
|
|
{
|
|
|
|
// don't show the module if the symbol is a trampoline symbol
|
2010-06-09 00:52:24 +08:00
|
|
|
show_stop_context = false;
|
2010-07-01 09:26:43 +08:00
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (show_stop_context)
|
|
|
|
{
|
|
|
|
// We have a function or a symbol from the same
|
|
|
|
// sections as this address.
|
2010-09-08 05:56:53 +08:00
|
|
|
sc.DumpStopContext (s,
|
|
|
|
exe_scope,
|
|
|
|
*this,
|
|
|
|
show_fullpaths,
|
|
|
|
show_module,
|
|
|
|
show_inlined_frames);
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// We found a symbol but it was in a different
|
|
|
|
// section so it isn't the symbol we should be
|
|
|
|
// showing, just show the section name + offset
|
|
|
|
Dump (s, exe_scope, DumpStyleSectionNameOffset);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (fallback_style != DumpStyleInvalid)
|
2010-07-01 07:03:03 +08:00
|
|
|
return Dump (s, exe_scope, fallback_style, DumpStyleInvalid, addr_size);
|
2010-06-09 00:52:24 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
break;
|
2010-07-01 07:03:03 +08:00
|
|
|
|
|
|
|
case DumpStyleDetailedSymbolContext:
|
|
|
|
if (IsSectionOffset())
|
|
|
|
{
|
2012-02-24 09:59:29 +08:00
|
|
|
ModuleSP module_sp (GetModule());
|
|
|
|
if (module_sp)
|
2010-07-01 07:03:03 +08:00
|
|
|
{
|
2010-09-10 09:30:46 +08:00
|
|
|
SymbolContext sc;
|
2012-02-24 09:59:29 +08:00
|
|
|
module_sp->ResolveSymbolContextForAddress(*this, eSymbolContextEverything, sc);
|
2010-08-03 08:35:52 +08:00
|
|
|
if (sc.symbol)
|
2010-07-01 07:03:03 +08:00
|
|
|
{
|
2010-08-03 08:35:52 +08:00
|
|
|
// If we have just a symbol make sure it is in the same section
|
|
|
|
// as our address. If it isn't, then we might have just found
|
|
|
|
// the last symbol that came before the address that we are
|
|
|
|
// looking up that has nothing to do with our address lookup.
|
2012-03-08 05:03:09 +08:00
|
|
|
if (sc.symbol->ValueIsAddress() && sc.symbol->GetAddress().GetSection() != GetSection())
|
2010-08-03 08:35:52 +08:00
|
|
|
sc.symbol = NULL;
|
2010-07-01 07:03:03 +08:00
|
|
|
}
|
2010-09-15 07:36:40 +08:00
|
|
|
sc.GetDescription(s, eDescriptionLevelBrief, target);
|
2011-07-11 13:12:02 +08:00
|
|
|
|
|
|
|
if (sc.block)
|
|
|
|
{
|
|
|
|
bool can_create = true;
|
|
|
|
bool get_parent_variables = true;
|
|
|
|
bool stop_if_block_is_inlined_function = false;
|
|
|
|
VariableList variable_list;
|
|
|
|
sc.block->AppendVariables (can_create,
|
|
|
|
get_parent_variables,
|
|
|
|
stop_if_block_is_inlined_function,
|
|
|
|
&variable_list);
|
|
|
|
|
|
|
|
uint32_t num_variables = variable_list.GetSize();
|
|
|
|
for (uint32_t var_idx = 0; var_idx < num_variables; ++var_idx)
|
|
|
|
{
|
|
|
|
Variable *var = variable_list.GetVariableAtIndex (var_idx).get();
|
|
|
|
if (var && var->LocationIsValidForAddress (*this))
|
|
|
|
{
|
2011-10-20 02:09:39 +08:00
|
|
|
s->Printf (" Variable: id = {0x%8.8llx}, name = \"%s\", type= \"%s\", location =",
|
2011-07-11 13:12:02 +08:00
|
|
|
var->GetID(),
|
|
|
|
var->GetName().GetCString(),
|
|
|
|
var->GetType()->GetName().GetCString());
|
|
|
|
var->DumpLocationForAddress(s, *this);
|
|
|
|
s->PutCString(", decl = ");
|
|
|
|
var->GetDeclaration().DumpStopContext(s, false);
|
|
|
|
s->EOL();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-07-01 07:03:03 +08:00
|
|
|
}
|
|
|
|
}
|
2011-07-11 13:12:02 +08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
if (fallback_style != DumpStyleInvalid)
|
|
|
|
return Dump (s, exe_scope, fallback_style, DumpStyleInvalid, addr_size);
|
|
|
|
return false;
|
|
|
|
}
|
2010-07-01 07:03:03 +08:00
|
|
|
break;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-08-13 05:40:01 +08:00
|
|
|
uint32_t
|
2011-12-11 05:05:26 +08:00
|
|
|
Address::CalculateSymbolContext (SymbolContext *sc, uint32_t resolve_scope) const
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
sc->Clear();
|
|
|
|
// Absolute addresses don't have enough information to reconstruct even their target.
|
2012-02-24 09:59:29 +08:00
|
|
|
|
|
|
|
SectionSP section_sp (GetSection());
|
|
|
|
if (section_sp)
|
2011-08-13 05:40:01 +08:00
|
|
|
{
|
2012-02-24 09:59:29 +08:00
|
|
|
ModuleSP module_sp (section_sp->GetModule());
|
|
|
|
if (module_sp)
|
2011-08-13 05:40:01 +08:00
|
|
|
{
|
2012-02-24 09:59:29 +08:00
|
|
|
sc->module_sp = module_sp;
|
2011-08-13 05:40:01 +08:00
|
|
|
if (sc->module_sp)
|
|
|
|
return sc->module_sp->ResolveSymbolContextForAddress (*this, resolve_scope, *sc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-02-24 09:59:29 +08:00
|
|
|
ModuleSP
|
2011-12-11 05:05:26 +08:00
|
|
|
Address::CalculateSymbolContextModule () const
|
2011-08-13 05:40:01 +08:00
|
|
|
{
|
2012-02-24 09:59:29 +08:00
|
|
|
SectionSP section_sp (GetSection());
|
|
|
|
if (section_sp)
|
|
|
|
return section_sp->GetModule();
|
|
|
|
return ModuleSP();
|
2011-08-13 05:40:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
CompileUnit *
|
2011-12-11 05:05:26 +08:00
|
|
|
Address::CalculateSymbolContextCompileUnit () const
|
2011-08-13 05:40:01 +08:00
|
|
|
{
|
2012-02-24 09:59:29 +08:00
|
|
|
SectionSP section_sp (GetSection());
|
|
|
|
if (section_sp)
|
2011-08-13 05:40:01 +08:00
|
|
|
{
|
|
|
|
SymbolContext sc;
|
2012-02-24 09:59:29 +08:00
|
|
|
sc.module_sp = section_sp->GetModule();
|
2011-08-13 05:40:01 +08:00
|
|
|
if (sc.module_sp)
|
|
|
|
{
|
|
|
|
sc.module_sp->ResolveSymbolContextForAddress (*this, eSymbolContextCompUnit, sc);
|
|
|
|
return sc.comp_unit;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
Function *
|
2011-12-11 05:05:26 +08:00
|
|
|
Address::CalculateSymbolContextFunction () const
|
2011-08-13 05:40:01 +08:00
|
|
|
{
|
2012-02-24 09:59:29 +08:00
|
|
|
SectionSP section_sp (GetSection());
|
|
|
|
if (section_sp)
|
2011-08-13 05:40:01 +08:00
|
|
|
{
|
|
|
|
SymbolContext sc;
|
2012-02-24 09:59:29 +08:00
|
|
|
sc.module_sp = section_sp->GetModule();
|
2011-08-13 05:40:01 +08:00
|
|
|
if (sc.module_sp)
|
|
|
|
{
|
|
|
|
sc.module_sp->ResolveSymbolContextForAddress (*this, eSymbolContextFunction, sc);
|
|
|
|
return sc.function;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
Block *
|
2011-12-11 05:05:26 +08:00
|
|
|
Address::CalculateSymbolContextBlock () const
|
2011-08-13 05:40:01 +08:00
|
|
|
{
|
2012-02-24 09:59:29 +08:00
|
|
|
SectionSP section_sp (GetSection());
|
|
|
|
if (section_sp)
|
2011-08-13 05:40:01 +08:00
|
|
|
{
|
|
|
|
SymbolContext sc;
|
2012-02-24 09:59:29 +08:00
|
|
|
sc.module_sp = section_sp->GetModule();
|
2011-08-13 05:40:01 +08:00
|
|
|
if (sc.module_sp)
|
|
|
|
{
|
|
|
|
sc.module_sp->ResolveSymbolContextForAddress (*this, eSymbolContextBlock, sc);
|
|
|
|
return sc.block;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
Symbol *
|
2011-12-11 05:05:26 +08:00
|
|
|
Address::CalculateSymbolContextSymbol () const
|
2011-08-13 05:40:01 +08:00
|
|
|
{
|
2012-02-24 09:59:29 +08:00
|
|
|
SectionSP section_sp (GetSection());
|
|
|
|
if (section_sp)
|
2011-08-13 05:40:01 +08:00
|
|
|
{
|
|
|
|
SymbolContext sc;
|
2012-02-24 09:59:29 +08:00
|
|
|
sc.module_sp = section_sp->GetModule();
|
2011-08-13 05:40:01 +08:00
|
|
|
if (sc.module_sp)
|
|
|
|
{
|
|
|
|
sc.module_sp->ResolveSymbolContextForAddress (*this, eSymbolContextSymbol, sc);
|
|
|
|
return sc.symbol;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2011-08-13 05:40:01 +08:00
|
|
|
bool
|
2011-12-11 05:05:26 +08:00
|
|
|
Address::CalculateSymbolContextLineEntry (LineEntry &line_entry) const
|
2011-08-13 05:40:01 +08:00
|
|
|
{
|
2012-02-24 09:59:29 +08:00
|
|
|
SectionSP section_sp (GetSection());
|
|
|
|
if (section_sp)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2011-08-13 05:40:01 +08:00
|
|
|
SymbolContext sc;
|
2012-02-24 09:59:29 +08:00
|
|
|
sc.module_sp = section_sp->GetModule();
|
2011-08-13 05:40:01 +08:00
|
|
|
if (sc.module_sp)
|
|
|
|
{
|
|
|
|
sc.module_sp->ResolveSymbolContextForAddress (*this, eSymbolContextLineEntry, sc);
|
|
|
|
if (sc.line_entry.IsValid())
|
|
|
|
{
|
|
|
|
line_entry = sc.line_entry;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
2011-08-13 05:40:01 +08:00
|
|
|
line_entry.Clear();
|
|
|
|
return false;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
Address::CompareFileAddress (const Address& a, const Address& b)
|
|
|
|
{
|
|
|
|
addr_t a_file_addr = a.GetFileAddress();
|
|
|
|
addr_t b_file_addr = b.GetFileAddress();
|
|
|
|
if (a_file_addr < b_file_addr)
|
|
|
|
return -1;
|
|
|
|
if (a_file_addr > b_file_addr)
|
|
|
|
return +1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int
|
2010-09-15 07:36:40 +08:00
|
|
|
Address::CompareLoadAddress (const Address& a, const Address& b, Target *target)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2010-09-15 07:36:40 +08:00
|
|
|
assert (target != NULL);
|
|
|
|
addr_t a_load_addr = a.GetLoadAddress (target);
|
|
|
|
addr_t b_load_addr = b.GetLoadAddress (target);
|
2010-06-09 00:52:24 +08:00
|
|
|
if (a_load_addr < b_load_addr)
|
|
|
|
return -1;
|
|
|
|
if (a_load_addr > b_load_addr)
|
|
|
|
return +1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
Address::CompareModulePointerAndOffset (const Address& a, const Address& b)
|
|
|
|
{
|
2012-02-24 09:59:29 +08:00
|
|
|
ModuleSP a_module_sp (a.GetModule());
|
|
|
|
ModuleSP b_module_sp (b.GetModule());
|
|
|
|
Module *a_module = a_module_sp.get();
|
|
|
|
Module *b_module = b_module_sp.get();
|
2010-06-09 00:52:24 +08:00
|
|
|
if (a_module < b_module)
|
|
|
|
return -1;
|
|
|
|
if (a_module > b_module)
|
|
|
|
return +1;
|
|
|
|
// Modules are the same, just compare the file address since they should
|
|
|
|
// be unique
|
|
|
|
addr_t a_file_addr = a.GetFileAddress();
|
|
|
|
addr_t b_file_addr = b.GetFileAddress();
|
|
|
|
if (a_file_addr < b_file_addr)
|
|
|
|
return -1;
|
|
|
|
if (a_file_addr > b_file_addr)
|
|
|
|
return +1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
size_t
|
|
|
|
Address::MemorySize () const
|
|
|
|
{
|
|
|
|
// Noting special for the memory size of a single Address object,
|
|
|
|
// it is just the size of itself.
|
|
|
|
return sizeof(Address);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-08 08:05:12 +08:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// NOTE: Be careful using this operator. It can correctly compare two
|
|
|
|
// addresses from the same Module correctly. It can't compare two
|
|
|
|
// addresses from different modules in any meaningful way, but it will
|
|
|
|
// compare the module pointers.
|
|
|
|
//
|
|
|
|
// To sum things up:
|
|
|
|
// - works great for addresses within the same module
|
|
|
|
// - it works for addresses across multiple modules, but don't expect the
|
|
|
|
// address results to make much sense
|
2010-06-09 00:52:24 +08:00
|
|
|
//
|
2011-01-08 08:05:12 +08:00
|
|
|
// This basically lets Address objects be used in ordered collection
|
|
|
|
// classes.
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
bool
|
|
|
|
lldb_private::operator< (const Address& lhs, const Address& rhs)
|
|
|
|
{
|
2012-02-24 09:59:29 +08:00
|
|
|
ModuleSP lhs_module_sp (lhs.GetModule());
|
|
|
|
ModuleSP rhs_module_sp (rhs.GetModule());
|
|
|
|
Module *lhs_module = lhs_module_sp.get();
|
|
|
|
Module *rhs_module = rhs_module_sp.get();
|
2011-01-08 08:05:12 +08:00
|
|
|
if (lhs_module == rhs_module)
|
|
|
|
{
|
|
|
|
// Addresses are in the same module, just compare the file addresses
|
|
|
|
return lhs.GetFileAddress() < rhs.GetFileAddress();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// The addresses are from different modules, just use the module
|
|
|
|
// pointer value to get consistent ordering
|
|
|
|
return lhs_module < rhs_module;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
lldb_private::operator> (const Address& lhs, const Address& rhs)
|
|
|
|
{
|
2012-02-24 09:59:29 +08:00
|
|
|
ModuleSP lhs_module_sp (lhs.GetModule());
|
|
|
|
ModuleSP rhs_module_sp (rhs.GetModule());
|
|
|
|
Module *lhs_module = lhs_module_sp.get();
|
|
|
|
Module *rhs_module = rhs_module_sp.get();
|
2011-01-08 08:05:12 +08:00
|
|
|
if (lhs_module == rhs_module)
|
|
|
|
{
|
|
|
|
// Addresses are in the same module, just compare the file addresses
|
|
|
|
return lhs.GetFileAddress() > rhs.GetFileAddress();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// The addresses are from different modules, just use the module
|
|
|
|
// pointer value to get consistent ordering
|
|
|
|
return lhs_module > rhs_module;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
// The operator == checks for exact equality only (same section, same offset)
|
|
|
|
bool
|
|
|
|
lldb_private::operator== (const Address& a, const Address& rhs)
|
|
|
|
{
|
|
|
|
return a.GetSection() == rhs.GetSection() &&
|
|
|
|
a.GetOffset() == rhs.GetOffset();
|
|
|
|
}
|
|
|
|
// The operator != checks for exact inequality only (differing section, or
|
|
|
|
// different offset)
|
|
|
|
bool
|
|
|
|
lldb_private::operator!= (const Address& a, const Address& rhs)
|
|
|
|
{
|
|
|
|
return a.GetSection() != rhs.GetSection() ||
|
|
|
|
a.GetOffset() != rhs.GetOffset();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
Address::IsLinkedAddress () const
|
|
|
|
{
|
2012-02-24 09:59:29 +08:00
|
|
|
SectionSP section_sp (GetSection());
|
|
|
|
return section_sp && section_sp->GetLinkedSection();
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
Address::ResolveLinkedAddress ()
|
|
|
|
{
|
2012-02-24 09:59:29 +08:00
|
|
|
SectionSP section_sp (GetSection());
|
|
|
|
if (section_sp)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2012-02-24 09:59:29 +08:00
|
|
|
SectionSP linked_section_sp (section_sp->GetLinkedSection());
|
|
|
|
if (linked_section_sp)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2012-02-24 09:59:29 +08:00
|
|
|
m_offset += section_sp->GetLinkedOffset();
|
|
|
|
m_section_wp = linked_section_sp;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-03-19 09:12:21 +08:00
|
|
|
|
2011-03-25 05:19:54 +08:00
|
|
|
AddressClass
|
2011-03-19 09:12:21 +08:00
|
|
|
Address::GetAddressClass () const
|
|
|
|
{
|
2012-02-24 09:59:29 +08:00
|
|
|
ModuleSP module_sp (GetModule());
|
|
|
|
if (module_sp)
|
2011-03-19 09:12:21 +08:00
|
|
|
{
|
2012-02-24 09:59:29 +08:00
|
|
|
ObjectFile *obj_file = module_sp->GetObjectFile();
|
2011-03-19 09:12:21 +08:00
|
|
|
if (obj_file)
|
|
|
|
return obj_file->GetAddressClass (GetFileAddress());
|
|
|
|
}
|
|
|
|
return eAddressClassUnknown;
|
|
|
|
}
|
2011-05-18 09:58:14 +08:00
|
|
|
|
|
|
|
bool
|
|
|
|
Address::SetLoadAddress (lldb::addr_t load_addr, Target *target)
|
|
|
|
{
|
|
|
|
if (target && target->GetSectionLoadList().ResolveLoadAddress(load_addr, *this))
|
|
|
|
return true;
|
2012-02-24 09:59:29 +08:00
|
|
|
m_section_wp.reset();
|
2011-05-18 09:58:14 +08:00
|
|
|
m_offset = load_addr;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|