2010-06-09 00:52:24 +08:00
|
|
|
//===-- SBBreakpoint.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/API/SBBreakpoint.h"
|
|
|
|
#include "lldb/API/SBBreakpointLocation.h"
|
|
|
|
#include "lldb/API/SBDebugger.h"
|
2010-07-24 07:33:17 +08:00
|
|
|
#include "lldb/API/SBEvent.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
#include "lldb/API/SBProcess.h"
|
|
|
|
#include "lldb/API/SBThread.h"
|
|
|
|
|
|
|
|
#include "lldb/Breakpoint/Breakpoint.h"
|
|
|
|
#include "lldb/Breakpoint/BreakpointLocation.h"
|
|
|
|
#include "lldb/Breakpoint/StoppointCallbackContext.h"
|
|
|
|
#include "lldb/Core/Address.h"
|
|
|
|
#include "lldb/Core/Stream.h"
|
|
|
|
#include "lldb/Core/StreamFile.h"
|
|
|
|
#include "lldb/Target/Process.h"
|
|
|
|
#include "lldb/Target/Target.h"
|
2010-06-18 09:47:08 +08:00
|
|
|
#include "lldb/Target/Thread.h"
|
|
|
|
#include "lldb/Target/ThreadSpec.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
|
|
|
|
#include "lldb/lldb-enumerations.h"
|
|
|
|
|
|
|
|
using namespace lldb;
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
|
|
|
struct CallbackData
|
|
|
|
{
|
|
|
|
SBBreakpoint::BreakpointHitCallback callback;
|
|
|
|
void *callback_baton;
|
|
|
|
};
|
|
|
|
|
|
|
|
class SBBreakpointCallbackBaton : public Baton
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
SBBreakpointCallbackBaton (SBBreakpoint::BreakpointHitCallback callback, void *baton) :
|
|
|
|
Baton (new CallbackData)
|
|
|
|
{
|
|
|
|
CallbackData *data = (CallbackData *)m_data;
|
|
|
|
data->callback = callback;
|
|
|
|
data->callback_baton = baton;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual ~SBBreakpointCallbackBaton()
|
|
|
|
{
|
|
|
|
CallbackData *data = (CallbackData *)m_data;
|
|
|
|
|
|
|
|
if (data)
|
|
|
|
{
|
|
|
|
delete data;
|
|
|
|
m_data = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
SBBreakpoint::SBBreakpoint () :
|
2010-06-23 09:19:29 +08:00
|
|
|
m_opaque_sp ()
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
SBBreakpoint::SBBreakpoint (const SBBreakpoint& rhs) :
|
2010-06-23 09:19:29 +08:00
|
|
|
m_opaque_sp (rhs.m_opaque_sp)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SBBreakpoint::SBBreakpoint (const lldb::BreakpointSP &bp_sp) :
|
2010-06-23 09:19:29 +08:00
|
|
|
m_opaque_sp (bp_sp)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
SBBreakpoint::~SBBreakpoint()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
const SBBreakpoint &
|
|
|
|
SBBreakpoint::operator = (const SBBreakpoint& rhs)
|
|
|
|
{
|
|
|
|
if (this != &rhs)
|
|
|
|
{
|
2010-06-23 09:19:29 +08:00
|
|
|
m_opaque_sp = rhs.m_opaque_sp;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
break_id_t
|
|
|
|
SBBreakpoint::GetID () const
|
|
|
|
{
|
2010-06-23 09:19:29 +08:00
|
|
|
if (m_opaque_sp)
|
|
|
|
return m_opaque_sp->GetID();
|
2010-06-09 00:52:24 +08:00
|
|
|
return LLDB_INVALID_BREAK_ID;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
SBBreakpoint::IsValid() const
|
|
|
|
{
|
2010-06-23 09:19:29 +08:00
|
|
|
return m_opaque_sp;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SBBreakpoint::ClearAllBreakpointSites ()
|
|
|
|
{
|
2010-06-23 09:19:29 +08:00
|
|
|
if (m_opaque_sp)
|
|
|
|
m_opaque_sp->ClearAllBreakpointSites ();
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
SBBreakpointLocation
|
|
|
|
SBBreakpoint::FindLocationByAddress (addr_t vm_addr)
|
|
|
|
{
|
|
|
|
SBBreakpointLocation sb_bp_location;
|
|
|
|
|
2010-06-23 09:19:29 +08:00
|
|
|
if (m_opaque_sp)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
if (vm_addr != LLDB_INVALID_ADDRESS)
|
|
|
|
{
|
|
|
|
Address address;
|
2010-09-15 07:36:40 +08:00
|
|
|
Target &target = m_opaque_sp->GetTarget();
|
|
|
|
if (target.GetSectionLoadList().ResolveLoadAddress (vm_addr, address) == false)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
address.SetSection (NULL);
|
|
|
|
address.SetOffset (vm_addr);
|
|
|
|
}
|
2010-06-23 09:19:29 +08:00
|
|
|
sb_bp_location.SetLocation (m_opaque_sp->FindLocationByAddress (address));
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return sb_bp_location;
|
|
|
|
}
|
|
|
|
|
|
|
|
break_id_t
|
|
|
|
SBBreakpoint::FindLocationIDByAddress (addr_t vm_addr)
|
|
|
|
{
|
|
|
|
break_id_t lldb_id = (break_id_t) 0;
|
|
|
|
|
2010-06-23 09:19:29 +08:00
|
|
|
if (m_opaque_sp)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
if (vm_addr != LLDB_INVALID_ADDRESS)
|
|
|
|
{
|
|
|
|
Address address;
|
2010-09-15 07:36:40 +08:00
|
|
|
Target &target = m_opaque_sp->GetTarget();
|
|
|
|
if (target.GetSectionLoadList().ResolveLoadAddress (vm_addr, address) == false)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
address.SetSection (NULL);
|
|
|
|
address.SetOffset (vm_addr);
|
|
|
|
}
|
2010-06-23 09:19:29 +08:00
|
|
|
lldb_id = m_opaque_sp->FindLocationIDByAddress (address);
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return lldb_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
SBBreakpointLocation
|
|
|
|
SBBreakpoint::FindLocationByID (break_id_t bp_loc_id)
|
|
|
|
{
|
|
|
|
SBBreakpointLocation sb_bp_location;
|
|
|
|
|
2010-06-23 09:19:29 +08:00
|
|
|
if (m_opaque_sp)
|
|
|
|
sb_bp_location.SetLocation (m_opaque_sp->FindLocationByID (bp_loc_id));
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
return sb_bp_location;
|
|
|
|
}
|
|
|
|
|
|
|
|
SBBreakpointLocation
|
|
|
|
SBBreakpoint::GetLocationAtIndex (uint32_t index)
|
|
|
|
{
|
|
|
|
SBBreakpointLocation sb_bp_location;
|
|
|
|
|
2010-06-23 09:19:29 +08:00
|
|
|
if (m_opaque_sp)
|
|
|
|
sb_bp_location.SetLocation (m_opaque_sp->GetLocationAtIndex (index));
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
return sb_bp_location;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SBBreakpoint::SetEnabled (bool enable)
|
|
|
|
{
|
2010-06-23 09:19:29 +08:00
|
|
|
if (m_opaque_sp)
|
|
|
|
m_opaque_sp->SetEnabled (enable);
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
SBBreakpoint::IsEnabled ()
|
|
|
|
{
|
2010-06-23 09:19:29 +08:00
|
|
|
if (m_opaque_sp)
|
|
|
|
return m_opaque_sp->IsEnabled();
|
2010-06-09 00:52:24 +08:00
|
|
|
else
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-07-10 04:39:50 +08:00
|
|
|
SBBreakpoint::SetIgnoreCount (uint32_t count)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2010-06-23 09:19:29 +08:00
|
|
|
if (m_opaque_sp)
|
|
|
|
m_opaque_sp->SetIgnoreCount (count);
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2010-07-24 07:33:17 +08:00
|
|
|
uint32_t
|
|
|
|
SBBreakpoint::GetHitCount () const
|
|
|
|
{
|
|
|
|
if (m_opaque_sp)
|
|
|
|
return m_opaque_sp->GetHitCount();
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-07-10 04:39:50 +08:00
|
|
|
uint32_t
|
2010-06-09 00:52:24 +08:00
|
|
|
SBBreakpoint::GetIgnoreCount () const
|
|
|
|
{
|
2010-06-23 09:19:29 +08:00
|
|
|
if (m_opaque_sp)
|
|
|
|
return m_opaque_sp->GetIgnoreCount();
|
2010-06-09 00:52:24 +08:00
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SBBreakpoint::SetThreadID (tid_t sb_thread_id)
|
|
|
|
{
|
2010-06-23 09:19:29 +08:00
|
|
|
if (m_opaque_sp)
|
|
|
|
m_opaque_sp->SetThreadID (sb_thread_id);
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
tid_t
|
|
|
|
SBBreakpoint::GetThreadID ()
|
|
|
|
{
|
|
|
|
tid_t lldb_thread_id = LLDB_INVALID_THREAD_ID;
|
2010-06-23 09:19:29 +08:00
|
|
|
if (m_opaque_sp)
|
|
|
|
lldb_thread_id = m_opaque_sp->GetThreadID();
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
return lldb_thread_id;
|
|
|
|
}
|
|
|
|
|
2010-06-18 09:47:08 +08:00
|
|
|
void
|
|
|
|
SBBreakpoint::SetThreadIndex (uint32_t index)
|
|
|
|
{
|
2010-06-23 09:19:29 +08:00
|
|
|
if (m_opaque_sp)
|
|
|
|
m_opaque_sp->GetOptions()->GetThreadSpec()->SetIndex (index);
|
2010-06-18 09:47:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t
|
|
|
|
SBBreakpoint::GetThreadIndex() const
|
|
|
|
{
|
2010-06-23 09:19:29 +08:00
|
|
|
if (m_opaque_sp)
|
2010-06-18 09:47:08 +08:00
|
|
|
{
|
2010-06-23 09:19:29 +08:00
|
|
|
const ThreadSpec *thread_spec = m_opaque_sp->GetOptions()->GetThreadSpec();
|
2010-06-18 09:47:08 +08:00
|
|
|
if (thread_spec == NULL)
|
|
|
|
return 0;
|
|
|
|
else
|
|
|
|
return thread_spec->GetIndex();
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
SBBreakpoint::SetThreadName (const char *thread_name)
|
|
|
|
{
|
2010-06-23 09:19:29 +08:00
|
|
|
if (m_opaque_sp)
|
|
|
|
m_opaque_sp->GetOptions()->GetThreadSpec()->SetName (thread_name);
|
2010-06-18 09:47:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
const char *
|
|
|
|
SBBreakpoint::GetThreadName () const
|
|
|
|
{
|
2010-06-23 09:19:29 +08:00
|
|
|
if (m_opaque_sp)
|
2010-06-18 09:47:08 +08:00
|
|
|
{
|
2010-06-23 09:19:29 +08:00
|
|
|
const ThreadSpec *thread_spec = m_opaque_sp->GetOptions()->GetThreadSpec();
|
2010-06-18 09:47:08 +08:00
|
|
|
if (thread_spec == NULL)
|
|
|
|
return NULL;
|
|
|
|
else
|
|
|
|
return thread_spec->GetName();
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SBBreakpoint::SetQueueName (const char *queue_name)
|
|
|
|
{
|
2010-06-23 09:19:29 +08:00
|
|
|
if (m_opaque_sp)
|
|
|
|
m_opaque_sp->GetOptions()->GetThreadSpec()->SetQueueName (queue_name);
|
2010-06-18 09:47:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
const char *
|
|
|
|
SBBreakpoint::GetQueueName () const
|
|
|
|
{
|
2010-06-23 09:19:29 +08:00
|
|
|
if (m_opaque_sp)
|
2010-06-18 09:47:08 +08:00
|
|
|
{
|
2010-06-23 09:19:29 +08:00
|
|
|
const ThreadSpec *thread_spec = m_opaque_sp->GetOptions()->GetThreadSpec();
|
2010-06-18 09:47:08 +08:00
|
|
|
if (thread_spec == NULL)
|
|
|
|
return NULL;
|
|
|
|
else
|
|
|
|
return thread_spec->GetQueueName();
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
size_t
|
|
|
|
SBBreakpoint::GetNumResolvedLocations() const
|
|
|
|
{
|
2010-06-23 09:19:29 +08:00
|
|
|
if (m_opaque_sp)
|
|
|
|
return m_opaque_sp->GetNumResolvedLocations();
|
2010-06-09 00:52:24 +08:00
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t
|
|
|
|
SBBreakpoint::GetNumLocations() const
|
|
|
|
{
|
2010-06-23 09:19:29 +08:00
|
|
|
if (m_opaque_sp)
|
|
|
|
return m_opaque_sp->GetNumLocations();
|
2010-06-09 00:52:24 +08:00
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-09-16 02:29:06 +08:00
|
|
|
SBBreakpoint::GetDescription (FILE *f, const char *description_level)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
if (f == NULL)
|
|
|
|
return;
|
|
|
|
|
2010-06-23 09:19:29 +08:00
|
|
|
if (m_opaque_sp)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
DescriptionLevel level;
|
|
|
|
if (strcmp (description_level, "brief") == 0)
|
|
|
|
level = eDescriptionLevelBrief;
|
|
|
|
else if (strcmp (description_level, "full") == 0)
|
|
|
|
level = eDescriptionLevelFull;
|
|
|
|
else if (strcmp (description_level, "verbose") == 0)
|
|
|
|
level = eDescriptionLevelVerbose;
|
|
|
|
else
|
|
|
|
level = eDescriptionLevelBrief;
|
|
|
|
|
|
|
|
StreamFile str (f);
|
|
|
|
|
2010-06-23 09:19:29 +08:00
|
|
|
m_opaque_sp->GetDescription (&str, level);
|
2010-06-09 00:52:24 +08:00
|
|
|
str.EOL();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
SBBreakpoint::PrivateBreakpointHitCallback
|
|
|
|
(
|
|
|
|
void *baton,
|
|
|
|
StoppointCallbackContext *ctx,
|
|
|
|
lldb::user_id_t break_id,
|
|
|
|
lldb::user_id_t break_loc_id
|
|
|
|
)
|
|
|
|
{
|
2010-06-23 09:19:29 +08:00
|
|
|
BreakpointSP bp_sp(ctx->exe_ctx.target->GetBreakpointList().FindBreakpointByID(break_id));
|
2010-06-09 00:52:24 +08:00
|
|
|
if (baton && bp_sp)
|
|
|
|
{
|
|
|
|
CallbackData *data = (CallbackData *)baton;
|
|
|
|
lldb_private::Breakpoint *bp = bp_sp.get();
|
|
|
|
if (bp && data->callback)
|
|
|
|
{
|
2010-06-23 09:19:29 +08:00
|
|
|
if (ctx->exe_ctx.process)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2010-06-23 09:19:29 +08:00
|
|
|
SBProcess sb_process (ctx->exe_ctx.process->GetSP());
|
2010-06-09 00:52:24 +08:00
|
|
|
SBThread sb_thread;
|
|
|
|
SBBreakpointLocation sb_location;
|
|
|
|
assert (bp_sp);
|
|
|
|
sb_location.SetLocation (bp_sp->FindLocationByID (break_loc_id));
|
2010-06-23 09:19:29 +08:00
|
|
|
if (ctx->exe_ctx.thread)
|
|
|
|
sb_thread.SetThread(ctx->exe_ctx.thread->GetSP());
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
return data->callback (data->callback_baton,
|
|
|
|
sb_process,
|
|
|
|
sb_thread,
|
|
|
|
sb_location);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true; // Return true if we should stop at this breakpoint
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SBBreakpoint::SetCallback (BreakpointHitCallback callback, void *baton)
|
|
|
|
{
|
2010-06-23 09:19:29 +08:00
|
|
|
if (m_opaque_sp.get())
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
BatonSP baton_sp(new SBBreakpointCallbackBaton (callback, baton));
|
2010-06-23 09:19:29 +08:00
|
|
|
m_opaque_sp->SetCallback (SBBreakpoint::PrivateBreakpointHitCallback, baton_sp, false);
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
lldb_private::Breakpoint *
|
|
|
|
SBBreakpoint::operator->() const
|
|
|
|
{
|
2010-06-23 09:19:29 +08:00
|
|
|
return m_opaque_sp.get();
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
lldb_private::Breakpoint *
|
|
|
|
SBBreakpoint::get() const
|
|
|
|
{
|
2010-06-23 09:19:29 +08:00
|
|
|
return m_opaque_sp.get();
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
lldb::BreakpointSP &
|
|
|
|
SBBreakpoint::operator *()
|
|
|
|
{
|
2010-06-23 09:19:29 +08:00
|
|
|
return m_opaque_sp;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
const lldb::BreakpointSP &
|
|
|
|
SBBreakpoint::operator *() const
|
|
|
|
{
|
2010-06-23 09:19:29 +08:00
|
|
|
return m_opaque_sp;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2010-07-24 07:33:17 +08:00
|
|
|
BreakpointEventType
|
|
|
|
SBBreakpoint::GetBreakpointEventTypeFromEvent (const SBEvent& event)
|
|
|
|
{
|
|
|
|
if (event.IsValid())
|
|
|
|
return Breakpoint::BreakpointEventData::GetBreakpointEventTypeFromEvent (event.GetSP());
|
|
|
|
return eBreakpointEventTypeInvalidType;
|
|
|
|
}
|
|
|
|
|
|
|
|
SBBreakpoint
|
|
|
|
SBBreakpoint::GetBreakpointFromEvent (const lldb::SBEvent& event)
|
|
|
|
{
|
|
|
|
SBBreakpoint sb_breakpoint;
|
|
|
|
if (event.IsValid())
|
|
|
|
sb_breakpoint.m_opaque_sp = Breakpoint::BreakpointEventData::GetBreakpointFromEvent (event.GetSP());
|
|
|
|
return sb_breakpoint;
|
|
|
|
}
|
|
|
|
|
|
|
|
SBBreakpointLocation
|
|
|
|
SBBreakpoint::GetBreakpointLocationAtIndexFromEvent (const lldb::SBEvent& event, uint32_t loc_idx)
|
|
|
|
{
|
|
|
|
SBBreakpointLocation sb_breakpoint_loc;
|
|
|
|
if (event.IsValid())
|
|
|
|
sb_breakpoint_loc.SetLocation (Breakpoint::BreakpointEventData::GetBreakpointLocationAtIndexFromEvent (event.GetSP(), loc_idx));
|
|
|
|
return sb_breakpoint_loc;
|
|
|
|
}
|
|
|
|
|
|
|
|
|