Rework the breakpoint/single stepping code to get rid of mono_arch_get_ip_for_breakpoint ()/single_step (). Instead of using these functions, simply find the first seq point before/after the ip, since the single step/breakpoint code is placed around the ip saved in the seq point map.

This commit is contained in:
Zoltan Varga committed 2011-10-31 02:23:37 +01:00
1 parent 89f6fdab5f
commit 290a4a10ab
7 files changed
+38 -289

No files matched your search

+37 -129
View File
@@ -2787,33 +2787,6 @@ is_suspended (void)
return count_threads_to_wait_for () == 0;
}
/*
* find_seq_point_for_native_offset:
*
* Find the sequence point corresponding to the native offset NATIVE_OFFSET, which
* should be the location of a sequence point.
*/
static SeqPoint*
find_seq_point_for_native_offset (MonoDomain *domain, MonoMethod *method, gint32 native_offset, MonoSeqPointInfo **info)
{
MonoSeqPointInfo *seq_points;
int i;
mono_domain_lock (domain);
seq_points = g_hash_table_lookup (domain_jit_info (domain)->seq_points, method);
mono_domain_unlock (domain);
g_assert (seq_points);
*info = seq_points;
for (i = 0; i < seq_points->len; ++i) {
if (seq_points->seq_points [i].native_offset == native_offset)
return &seq_points->seq_points [i];
}
return NULL;
}
/*
* find_next_seq_point_for_native_offset:
*
@@ -2830,7 +2803,8 @@ find_next_seq_point_for_native_offset (MonoDomain *domain, MonoMethod *method, g
mono_domain_unlock (domain);
g_assert (seq_points);
*info = seq_points;
if (info)
*info = seq_points;
for (i = 0; i < seq_points->len; ++i) {
if (seq_points->seq_points [i].native_offset >= native_offset)
@@ -2856,7 +2830,8 @@ find_prev_seq_point_for_native_offset (MonoDomain *domain, MonoMethod *method, g
mono_domain_unlock (domain);
g_assert (seq_points);
*info = seq_points;
if (info)
*info = seq_points;
for (i = seq_points->len - 1; i >= 0; --i) {
if (seq_points->seq_points [i].native_offset <= native_offset)
@@ -2893,40 +2868,6 @@ find_seq_point (MonoDomain *domain, MonoMethod *method, gint32 il_offset, MonoSe
return NULL;
}
/*
* compute_il_offset:
*
* Compute the IL offset corresponding to NATIVE_OFFSET, which should be
* a location of a sequence point.
* We use this function instead of mono_debug_il_offset_from_address () etc,
* which doesn't seem to work in a lot of cases.
*/
static gint32
compute_il_offset (MonoDomain *domain, MonoMethod *method, gint32 native_offset)
{
MonoSeqPointInfo *seq_points;
int i, last_il_offset, seq_il_offset, seq_native_offset;
mono_domain_lock (domain);
seq_points = g_hash_table_lookup (domain_jit_info (domain)->seq_points, method);
mono_domain_unlock (domain);
g_assert (seq_points);
last_il_offset = -1;
/* Find the sequence point */
for (i = 0; i < seq_points->len; ++i) {
seq_il_offset = seq_points->seq_points [i].il_offset;
seq_native_offset = seq_points->seq_points [i].native_offset;
if (seq_native_offset > native_offset)
break;
last_il_offset = seq_il_offset;
}
return last_il_offset;
}
typedef struct {
DebuggerTlsData *tls;
GSList *frames;
@@ -3781,6 +3722,7 @@ typedef struct {
guint8 *ip;
MonoJitInfo *ji;
MonoDomain *domain;
SeqPoint *sp;
} BreakpointInstance;
/*
@@ -3826,18 +3768,16 @@ static void
insert_breakpoint (MonoSeqPointInfo *seq_points, MonoDomain *domain, MonoJitInfo *ji, MonoBreakpoint *bp, MonoError *error)
{
int i, count;
gint32 il_offset = -1, native_offset;
BreakpointInstance *inst;
SeqPoint *sp = NULL;
if (error)
mono_error_init (error);
native_offset = 0;
for (i = 0; i < seq_points->len; ++i) {
il_offset = seq_points->seq_points [i].il_offset;
native_offset = seq_points->seq_points [i].native_offset;
sp = &seq_points->seq_points [i];
if (il_offset == bp->il_offset)
if (sp->il_offset == bp->il_offset)
break;
}
@@ -3854,8 +3794,9 @@ insert_breakpoint (MonoSeqPointInfo *seq_points, MonoDomain *domain, MonoJitInfo
}
inst = g_new0 (BreakpointInstance, 1);
inst->native_offset = native_offset;
inst->ip = (guint8*)ji->code_start + native_offset;
inst->sp = sp;
inst->native_offset = sp->native_offset;
inst->ip = (guint8*)ji->code_start + sp->native_offset;
inst->ji = ji;
inst->domain = domain;
@@ -3875,7 +3816,7 @@ insert_breakpoint (MonoSeqPointInfo *seq_points, MonoDomain *domain, MonoJitInfo
#endif
}
DEBUG(1, fprintf (log_file, "[dbg] Inserted breakpoint at %s:0x%x.\n", mono_method_full_name (ji->method, TRUE), (int)il_offset));
DEBUG(1, fprintf (log_file, "[dbg] Inserted breakpoint at %s:0x%x.\n", mono_method_full_name (ji->method, TRUE), (int)sp->il_offset));
}
static void
@@ -4145,7 +4086,7 @@ static void
process_breakpoint_inner (DebuggerTlsData *tls)
{
MonoJitInfo *ji;
guint8 *orig_ip, *ip;
guint8 *ip;
int i, j, suspend_policy;
guint32 native_offset;
MonoBreakpoint *bp;
@@ -4154,30 +4095,27 @@ process_breakpoint_inner (DebuggerTlsData *tls)
GSList *bp_events = NULL, *ss_events = NULL, *enter_leave_events = NULL;
EventKind kind = EVENT_KIND_BREAKPOINT;
MonoContext *ctx = &tls->restore_ctx;
MonoSeqPointInfo *info;
SeqPoint *sp;
// FIXME: Speed this up
orig_ip = ip = MONO_CONTEXT_GET_IP (ctx);
ip = MONO_CONTEXT_GET_IP (ctx);
ji = mini_jit_info_table_find (mono_domain_get (), (char*)ip, NULL);
g_assert (ji);
g_assert (ji->method);
if (ji->method->wrapper_type || tls->disable_breakpoints)
return;
/* Compute the native offset of the breakpoint from the ip */
#ifdef MONO_ARCH_SOFT_DEBUG_SUPPORTED
ip = mono_arch_get_ip_for_breakpoint (ji, ctx);
native_offset = ip - (guint8*)ji->code_start;
#else
NOT_IMPLEMENTED;
#endif
/*
* Skip the instruction causing the breakpoint signal.
*/
mono_arch_skip_breakpoint (ctx);
if (ji->method->wrapper_type || tls->disable_breakpoints)
return;
bp_reqs = g_ptr_array_new ();
ss_reqs = g_ptr_array_new ();
ss_reqs_orig = g_ptr_array_new ();
@@ -4186,6 +4124,12 @@ process_breakpoint_inner (DebuggerTlsData *tls)
mono_loader_lock ();
/*
* The ip points to the instruction causing the breakpoint event, which is after
* the offset recorded in the seq point map, so find the prev seq point before ip.
*/
sp = find_prev_seq_point_for_native_offset (mono_domain_get (), ji->method, native_offset, &info);
bp = NULL;
for (i = 0; i < breakpoints->len; ++i) {
bp = g_ptr_array_index (breakpoints, i);
@@ -4195,7 +4139,7 @@ process_breakpoint_inner (DebuggerTlsData *tls)
for (j = 0; j < bp->children->len; ++j) {
inst = g_ptr_array_index (bp->children, j);
if (inst->ji == ji && inst->native_offset == native_offset) {
if (inst->ji == ji && inst->sp == sp) {
if (bp->req->event_kind == EVENT_KIND_STEP) {
g_ptr_array_add (ss_reqs_orig, bp->req);
} else {
@@ -4205,33 +4149,11 @@ process_breakpoint_inner (DebuggerTlsData *tls)
}
}
if (bp_reqs->len == 0 && ss_reqs_orig->len == 0) {
MonoSeqPointInfo *seq_points;
int seq_il_offset, seq_native_offset;
MonoDomain *domain = mono_domain_get ();
/* Maybe a method entry/exit event */
mono_domain_lock (domain);
seq_points = g_hash_table_lookup (domain_jit_info (domain)->seq_points, ji->method);
mono_domain_unlock (domain);
if (!seq_points) {
// FIXME: Generic sharing */
mono_loader_unlock ();
return;
}
g_assert (seq_points);
for (i = 0; i < seq_points->len; ++i) {
seq_il_offset = seq_points->seq_points [i].il_offset;
seq_native_offset = seq_points->seq_points [i].native_offset;
if (native_offset == seq_native_offset) {
if (seq_il_offset == METHOD_ENTRY_IL_OFFSET)
kind = EVENT_KIND_METHOD_ENTRY;
else if (seq_il_offset == METHOD_EXIT_IL_OFFSET)
kind = EVENT_KIND_METHOD_EXIT;
break;
}
}
if (sp->il_offset == METHOD_ENTRY_IL_OFFSET)
kind = EVENT_KIND_METHOD_ENTRY;
else if (sp->il_offset == METHOD_EXIT_IL_OFFSET)
kind = EVENT_KIND_METHOD_EXIT;
}
/* Process single step requests */
@@ -4239,11 +4161,6 @@ process_breakpoint_inner (DebuggerTlsData *tls)
EventRequest *req = g_ptr_array_index (ss_reqs_orig, i);
SingleStepReq *ss_req = req->info;
gboolean hit = TRUE;
MonoSeqPointInfo *info;
SeqPoint *sp;
sp = find_seq_point_for_native_offset (mono_domain_get (), ji->method, native_offset, &info);
g_assert (sp);
if (ss_req->size == STEP_SIZE_LINE) {
/* Have to check whenever a different source line was reached */
@@ -4433,6 +4350,7 @@ process_single_step_inner (DebuggerTlsData *tls)
MonoDomain *domain;
GSList *events;
MonoContext *ctx = &tls->restore_ctx;
SeqPoint *sp;
// FIXME: Speed this up
@@ -4492,24 +4410,14 @@ process_single_step_inner (DebuggerTlsData *tls)
if (ji->method->klass == mono_defaults.string_class && (!strcmp (ji->method->name, "memset") || strstr (ji->method->name, "memcpy")))
return;
/*
* The ip points to the instruction causing the single step event, convert it
* to the offset stored in seq_points.
/*
* The ip points to the instruction causing the single step event, which is before
* the offset recorded in the seq point map, so find the next seq point after ip.
*/
#ifdef MONO_ARCH_SOFT_DEBUG_SUPPORTED
ip = mono_arch_get_ip_for_single_step (ji, ctx);
#else
g_assert_not_reached ();
#endif
/*
* mono_debug_lookup_source_location () doesn't work for IL offset 0 for
* example, so do things by hand.
*/
il_offset = compute_il_offset (domain, ji->method, (guint8*)ip - (guint8*)ji->code_start);
if (il_offset == -1)
sp = find_next_seq_point_for_native_offset (domain, ji->method, (guint8*)ip - (guint8*)ji->code_start, NULL);
if (!sp)
return;
il_offset = sp->il_offset;
if (ss_req->size == STEP_SIZE_LINE) {
/* Step until a different source line is reached */
-33
View File
@@ -4294,8 +4294,6 @@ mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb)
/*
* This is the address which is saved in seq points,
* get_ip_for_single_step () / get_ip_for_breakpoint () needs to compute this
* from the address of the instruction causing the fault.
*/
mono_add_seq_point (cfg, bb, ins, code - cfg->native_code);
@@ -8547,22 +8545,6 @@ mono_arch_is_breakpoint_event (void *info, void *sigctx)
#endif
}
/*
* mono_arch_get_ip_for_breakpoint:
*
* Convert the ip in CTX to the address where a breakpoint was placed.
*/
guint8*
mono_arch_get_ip_for_breakpoint (MonoJitInfo *ji, MonoContext *ctx)
{
guint8 *ip = MONO_CONTEXT_GET_IP (ctx);
/* ip points to the instruction causing the fault */
ip -= (breakpoint_size - breakpoint_fault_size);
return ip;
}
/*
* mono_arch_skip_breakpoint:
*
@@ -8619,21 +8601,6 @@ mono_arch_is_single_step_event (void *info, void *sigctx)
#endif
}
/*
* mono_arch_get_ip_for_single_step:
*
* Convert the ip in CTX to the address stored in seq_points.
*/
guint8*
mono_arch_get_ip_for_single_step (MonoJitInfo *ji, MonoContext *ctx)
{
guint8 *ip = MONO_CONTEXT_GET_IP (ctx);
ip += single_step_fault_size;
return ip;
}
/*
* mono_arch_skip_single_step:
*
+1 -25
View File
@@ -3817,6 +3817,7 @@ mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb)
* Have to emit nops to keep the difference between the offset
* stored in seq_points and breakpoint instruction constant,
* mono_arch_get_ip_for_breakpoint () depends on this.
* FIXME: This is no longer needed.
*/
if (val & 0xFF00)
ARM_ADD_REG_IMM (code, dreg, dreg, (val & 0xFF00) >> 8, 24);
@@ -6163,31 +6164,6 @@ mono_arch_is_breakpoint_event (void *info, void *sigctx)
}
}
guint8*
mono_arch_get_ip_for_breakpoint (MonoJitInfo *ji, MonoContext *ctx)
{
guint8 *ip = MONO_CONTEXT_GET_IP (ctx);
if (ji->from_aot)
ip -= 6 * 4;
else if (mini_get_debug_options ()->soft_breakpoints)
ip -= 4;
else
ip -= 12;
return ip;
}
guint8*
mono_arch_get_ip_for_single_step (MonoJitInfo *ji, MonoContext *ctx)
{
guint8 *ip = MONO_CONTEXT_GET_IP (ctx);
ip += 4;
return ip;
}
/*
* mono_arch_skip_breakpoint:
*
-30
View File
@@ -5925,22 +5925,6 @@ mono_arch_is_breakpoint_event (void *info, void *sigctx)
return FALSE;
}
/*
* mono_arch_get_ip_for_breakpoint:
*
* See mini-amd64.c for docs.
*/
guint8*
mono_arch_get_ip_for_breakpoint (MonoJitInfo *ji, MonoContext *ctx)
{
guint8 *ip = MONO_CONTEXT_GET_IP (ctx);
/* ip points at the ldptr instruction */
ip -= PPC_LOAD_SEQUENCE_LENGTH;
return ip;
}
/*
* mono_arch_skip_breakpoint:
*
@@ -5995,20 +5979,6 @@ mono_arch_is_single_step_event (void *info, void *sigctx)
return FALSE;
}
/*
* mono_arch_get_ip_for_single_step:
*
* See mini-amd64.c for docs.
*/
guint8*
mono_arch_get_ip_for_single_step (MonoJitInfo *ji, MonoContext *ctx)
{
guint8 *ip = MONO_CONTEXT_GET_IP (ctx);
/* ip points after the ldptr instruction */
return ip;
}
/*
* mono_arch_skip_single_step:
*
-41
View File
@@ -6299,28 +6299,6 @@ mono_arch_is_breakpoint_event (void *info, void *sigctx)
/*========================= End of Function ========================*/
/*------------------------------------------------------------------*/
/* */
/* Name - mono_arch_get_ip_for_breakpoint. */
/* */
/* Function - Convert the IP in the CTX to the address where a */
/* breakpoint was placed. */
/* */
/*------------------------------------------------------------------*/
guint8*
mono_arch_get_ip_for_breakpoint (MonoJitInfo *ji, MonoContext *ctx)
{
guint8 *ip = MONO_CONTEXT_GET_IP (ctx);
/* ip points to the instruction causing the fault */
ip -= BREAKPOINT_SIZE;
return ip;
}
/*========================= End of Function ========================*/
/*------------------------------------------------------------------*/
/* */
/* Name - mono_arch_skip_breakpoint. */
@@ -6394,25 +6372,6 @@ mono_arch_is_single_step_event (void *info, void *sigctx)
/*========================= End of Function ========================*/
/*------------------------------------------------------------------*/
/* */
/* Name - mono_arch_get_ip_for_single_step. */
/* */
/* Function - Convert the IP in ctx to the address stored in */
/* seq_points. */
/* */
/*------------------------------------------------------------------*/
guint8*
mono_arch_get_ip_for_single_step (MonoJitInfo *ji, MonoContext *ctx)
{
guint8 *ip = MONO_CONTEXT_GET_IP (ctx);
return ip;
}
/*========================= End of Function ========================*/
/*------------------------------------------------------------------*/
/* */
/* Name - mono_arch_skip_single_step. */
-29
View File
@@ -6625,37 +6625,8 @@ mono_arch_is_breakpoint_event (void *info, void *sigctx)
#endif
}
/*
* mono_arch_get_ip_for_breakpoint:
*
* See mini-amd64.c for docs.
*/
guint8*
mono_arch_get_ip_for_breakpoint (MonoJitInfo *ji, MonoContext *ctx)
{
guint8 *ip = MONO_CONTEXT_GET_IP (ctx);
return ip;
}
#define BREAKPOINT_SIZE 6
/*
* mono_arch_get_ip_for_single_step:
*
* See mini-amd64.c for docs.
*/
guint8*
mono_arch_get_ip_for_single_step (MonoJitInfo *ji, MonoContext *ctx)
{
guint8 *ip = MONO_CONTEXT_GET_IP (ctx);
/* Size of x86_alu_reg_imm */
ip += 6;
return ip;
}
/*
* mono_arch_skip_breakpoint:
*
-2
View File
@@ -2080,8 +2080,6 @@ void mono_arch_start_single_stepping (void) MONO_INTERNAL;
void mono_arch_stop_single_stepping (void) MONO_INTERNAL;
gboolean mono_arch_is_single_step_event (void *info, void *sigctx) MONO_INTERNAL;
gboolean mono_arch_is_breakpoint_event (void *info, void *sigctx) MONO_INTERNAL;
guint8* mono_arch_get_ip_for_single_step (MonoJitInfo *ji, MonoContext *ctx) MONO_INTERNAL;
guint8* mono_arch_get_ip_for_breakpoint (MonoJitInfo *ji, MonoContext *ctx) MONO_INTERNAL;
void mono_arch_skip_breakpoint (MonoContext *ctx) MONO_INTERNAL;
void mono_arch_skip_single_step (MonoContext *ctx) MONO_INTERNAL;
gpointer mono_arch_get_seq_point_info (MonoDomain *domain, guint8 *code) MONO_INTERNAL;