Compare commits

...
12 Commits
Author SHA1 Message Date
Zoltan Varga 974943dcf9 Merge pull request #1476 from DavidKarlas/ignoreHiddenSeqPoints
[Sdb] Ignore hidden sequence points
2015-01-04 12:55:25 -05:00
David Karlaš d4c52c0ae0 [Sdb] Ignore hidden sequence points 2014-12-23 16:24:08 +01:00
Zoltan Varga 8fe6c1d0d1 Merge pull request #1463 from DavidKarlas/seq-points
[Sdb] Debugger stepping like .Net
2014-12-18 16:41:46 -05:00
David Karlaš f131d0cf61 [Sdb] With better mimicking of .Net debugging experience stepping out of method returns to method call instead of next statement 2014-12-18 22:21:10 +01:00
David Karlaš 4538e3e0f2 [Sdb] Fixed bug with STEP_DEPTH_MIN+STEP_SIZE_MIN which stopped on NONEMPTY_STACK sequence point in same method as it begin stepping 2014-12-18 19:03:23 +01:00
David Karlaš 615fa21dcc [Sdb] Removed exclusion of CEE_POP and CEE_NOP sequence point creation 2014-12-18 19:02:52 +01:00
David Karlaš b389278fcb [Sdb] Set filter on ss_req in ss_create because filter was never set condition "if ((ss_req->filter & STEP_FILTER_STATIC_CTOR) &&" in process_single_step_inner was nerver true 2014-12-18 19:00:37 +01:00
Zoltan Varga 0690ce6405 [sdb] Fix single stepping problems caused by missing seq point info in .mdb files. When stepping in, we have to put a single stepping breakpoint into the parent method, otherwise a missing seq point could cause the debugger to continue until it hits a method entry seq point. 2014-12-16 16:46:05 -05:00
Zoltan Varga e851dde346 [sdb] Avoid putting implicit seq points at nops followed by a sym seq point. 2014-12-15 19:10:53 -05:00
Zoltan Varga cbe8767979 [sdb] Put seq points at nop's following calls as well. 2014-12-15 17:57:08 -05:00
Zoltan Varga 8f1e376d7e [sdb] Emit an implicit sequence point after every call and newobj instruction. 2014-12-15 17:35:52 -05:00
Zoltan Varga db5eb9ff5a [sdb] Avoid using implicit sequence points for methods without debug info in images which have debug info, like auto generated property accessors. 2014-12-15 17:34:02 -05:00
7 changed files with 145 additions and 43 deletions

No files matched your search

@@ -420,6 +420,10 @@ public class DebuggerTests
e = step_out ();
assert_location (e, "single_stepping");
// Step into next line
e = step_into ();
assert_location (e, "single_stepping");
// Step into ss3_2 ()
e = step_into ();
assert_location (e, "ss3_2");
+40 -17
View File
@@ -411,12 +411,13 @@ mono_debug_symfile_lookup_location (MonoDebugMethodInfo *minfo, uint32_t offset)
}
static void
add_line (StatementMachine *stm, GPtrArray *il_offset_array, GPtrArray *line_number_array, GPtrArray *source_file_array)
add_line (StatementMachine *stm, GPtrArray *il_offset_array, GPtrArray *line_number_array, GPtrArray *source_file_array, GPtrArray *hidden_array)
{
if (stm->line > 0) {
g_ptr_array_add (il_offset_array, GUINT_TO_POINTER (stm->offset));
g_ptr_array_add (line_number_array, GUINT_TO_POINTER (stm->line));
g_ptr_array_add (source_file_array, GUINT_TO_POINTER (stm->file));
g_ptr_array_add (hidden_array, GUINT_TO_POINTER (stm->is_hidden));
}
if (!stm->is_hidden && !stm->first_file)
@@ -514,9 +515,9 @@ mono_debug_symfile_get_line_numbers_full (MonoDebugMethodInfo *minfo, char **sou
MonoSymbolFile *symfile;
const unsigned char *ptr;
StatementMachine stm;
uint32_t i;
uint32_t i, j;
LineNumberTableFlags flags;
GPtrArray *il_offset_array, *line_number_array, *source_file_array;
GPtrArray *il_offset_array, *line_number_array, *source_file_array, *hidden_array;
gboolean has_column_info, has_end_info;
gboolean column_info_read = FALSE;
@@ -549,6 +550,7 @@ mono_debug_symfile_get_line_numbers_full (MonoDebugMethodInfo *minfo, char **sou
il_offset_array = g_ptr_array_new ();
line_number_array = g_ptr_array_new ();
source_file_array = g_ptr_array_new ();
hidden_array = g_ptr_array_new();
stm.line_base = read32 (&symfile->offset_table->_line_number_table_line_base);
stm.line_range = read32 (&symfile->offset_table->_line_number_table_line_range);
@@ -596,7 +598,7 @@ mono_debug_symfile_get_line_numbers_full (MonoDebugMethodInfo *minfo, char **sou
} else if (opcode < stm.opcode_base) {
switch (opcode) {
case DW_LNS_copy:
add_line (&stm, il_offset_array, line_number_array, source_file_array);
add_line (&stm, il_offset_array, line_number_array, source_file_array, hidden_array);
break;
case DW_LNS_advance_pc:
stm.offset += read_leb128 (ptr, &ptr);
@@ -620,7 +622,7 @@ mono_debug_symfile_get_line_numbers_full (MonoDebugMethodInfo *minfo, char **sou
stm.offset += opcode / stm.line_range;
stm.line += stm.line_base + (opcode % stm.line_range);
add_line (&stm, il_offset_array, line_number_array, source_file_array);
add_line (&stm, il_offset_array, line_number_array, source_file_array, hidden_array);
}
}
@@ -662,32 +664,49 @@ mono_debug_symfile_get_line_numbers_full (MonoDebugMethodInfo *minfo, char **sou
}
}
if (n_il_offsets)
if (n_il_offsets) {
*n_il_offsets = il_offset_array->len;
for (i = 0; i < il_offset_array->len; i++) {
if (GPOINTER_TO_UINT (g_ptr_array_index (hidden_array, i))) {
(*n_il_offsets)--;
}
}
}
if (il_offsets && line_numbers) {
*il_offsets = g_malloc (il_offset_array->len * sizeof (int));
*line_numbers = g_malloc (il_offset_array->len * sizeof (int));
*il_offsets = g_malloc (*n_il_offsets * sizeof (int));
*line_numbers = g_malloc (*n_il_offsets * sizeof (int));
j = 0;
for (i = 0; i < il_offset_array->len; ++i) {
(*il_offsets) [i] = GPOINTER_TO_UINT (g_ptr_array_index (il_offset_array, i));
(*line_numbers) [i] = GPOINTER_TO_UINT (g_ptr_array_index (line_number_array, i));
if (!GPOINTER_TO_UINT (g_ptr_array_index (hidden_array, i))) {
(*il_offsets)[j] = GPOINTER_TO_UINT (g_ptr_array_index (il_offset_array, i));
(*line_numbers)[j] = GPOINTER_TO_UINT (g_ptr_array_index (line_number_array, i));
j++;
}
}
}
if (column_numbers && has_column_info) {
column_info_read = TRUE;
*column_numbers = g_malloc (il_offset_array->len * sizeof (int));
for (i = 0; i < il_offset_array->len; ++i)
(*column_numbers) [i] = read_leb128 (ptr, &ptr);
*column_numbers = g_malloc (*n_il_offsets * sizeof (int));
j = 0;
for (i = 0; i < il_offset_array->len; ++i) {
int column = read_leb128 (ptr, &ptr);
if (!GPOINTER_TO_UINT (g_ptr_array_index (hidden_array, i))) {
(*column_numbers) [j] = column;
j++;
}
}
}
if (has_end_info && end_line_numbers) {
g_assert (end_column_numbers);
*end_line_numbers = g_malloc (il_offset_array->len * sizeof (int));
*end_column_numbers = g_malloc (il_offset_array->len * sizeof (int));
*end_line_numbers = g_malloc (*n_il_offsets * sizeof (int));
*end_column_numbers = g_malloc (*n_il_offsets * sizeof (int));
if (has_column_info && !column_info_read) {
for (i = 0; i < il_offset_array->len; ++i)
read_leb128 (ptr, &ptr);
}
j = 0;
for (i = 0; i < il_offset_array->len; ++i) {
int end_row, end_column = -1;
@@ -695,14 +714,18 @@ mono_debug_symfile_get_line_numbers_full (MonoDebugMethodInfo *minfo, char **sou
if (end_row != 0xffffff) {
end_row += GPOINTER_TO_UINT (g_ptr_array_index (line_number_array, i));
end_column = read_leb128 (ptr, &ptr);
(*end_line_numbers) [i] = end_row;
(*end_column_numbers) [i] = end_column;
if (!GPOINTER_TO_UINT (g_ptr_array_index (hidden_array, i))) {
(*end_line_numbers)[j] = end_row;
(*end_column_numbers)[j] = end_column;
j++;
}
}
}
}
g_ptr_array_free (il_offset_array, TRUE);
g_ptr_array_free (line_number_array, TRUE);
g_ptr_array_free (hidden_array, TRUE);
mono_debugger_unlock ();
return;
+3
View File
@@ -161,6 +161,9 @@ mono_debug_symfile_get_line_numbers (MonoDebugMethodInfo *minfo, char **source_f
MONO_API void
mono_debug_symfile_get_line_numbers_full (MonoDebugMethodInfo *minfo, char **source_file, GPtrArray **source_file_list, int *n_il_offsets, int **il_offsets, int **line_numbers, int **column_numbers, int **source_files, int **end_line_numbers, int **end_column_numbers);
gboolean
mono_debug_image_has_debug_info (MonoImage *image);
MONO_END_DECLS
#endif /* __MONO_SYMFILE_H__ */
+36
View File
@@ -337,6 +337,42 @@ mono_debug_lookup_method (MonoMethod *method)
return minfo;
}
typedef struct
{
gboolean found;
MonoImage *image;
} LookupImageData;
static void
lookup_image_func (gpointer key, gpointer value, gpointer user_data)
{
MonoDebugHandle *handle = (MonoDebugHandle *) value;
LookupImageData *data = (LookupImageData *) user_data;
if (data->found)
return;
if (handle->image == data->image)
data->found = TRUE;
}
gboolean
mono_debug_image_has_debug_info (MonoImage *image)
{
LookupImageData data;
if (!mono_debug_handles)
return FALSE;
memset (&data, 0, sizeof (data));
data.image = image;
mono_debugger_lock ();
g_hash_table_foreach (mono_debug_handles, lookup_image_func, &data);
mono_debugger_unlock ();
return data.found;
}
static inline void
write_leb128 (guint32 value, guint8 *ptr, guint8 **rptr)
{
+52 -11
View File
@@ -577,6 +577,7 @@ typedef struct {
gpointer start_sp;
MonoMethod *last_method;
int last_line;
MonoMethod *start_method;
/* Whenever single stepping is performed using start/stop_single_stepping () */
gboolean global;
/* The list of breakpoints used to implement step-over */
@@ -800,7 +801,7 @@ static void ids_cleanup (void);
static void suspend_init (void);
static void ss_start (SingleStepReq *ss_req, MonoMethod *method, SeqPoint *sp, MonoSeqPointInfo *info, MonoContext *ctx, DebuggerTlsData *tls, gboolean step_to_catch);
static ErrorCode ss_create (MonoInternalThread *thread, StepSize size, StepDepth depth, EventRequest *req);
static ErrorCode ss_create (MonoInternalThread *thread, StepSize size, StepDepth depth, StepFilter filter, EventRequest *req);
static void ss_destroy (SingleStepReq *req);
static void start_debugger_thread (void);
@@ -4636,6 +4637,17 @@ ss_update (SingleStepReq *req, MonoJitInfo *ji, SeqPoint *sp, DebuggerTlsData *t
}
}
if (req->depth == STEP_DEPTH_INTO && req->size == STEP_SIZE_MIN && (sp->flags & MONO_SEQ_POINT_FLAG_NONEMPTY_STACK) && ss_req->start_method){
method = jinfo_get_method (ji);
if (!tls->context.valid)
mono_thread_state_init_from_monoctx (&tls->context, ctx);
compute_frame_info (tls->thread, tls);
if (ss_req->start_method == method && req->nframes && tls->frame_count == req->nframes) {//Check also frame count(could be recursion)
DEBUG (1, fprintf (log_file, "[%p] Seq point at nonempty stack %x while stepping in, continuing single stepping.\n", (gpointer)GetCurrentThreadId (), sp->il_offset));
return FALSE;
}
}
if (req->size != STEP_SIZE_LINE)
return TRUE;
@@ -4949,7 +4961,7 @@ process_single_step_inner (DebuggerTlsData *tls)
if (log_level > 0) {
ji = mini_jit_info_table_find (mono_domain_get (), (char*)ip, &domain);
DEBUG (1, fprintf (log_file, "[%p] Single step event (depth=%s) at %s (%p), sp %p, last sp %p\n", (gpointer)GetCurrentThreadId (), ss_depth_to_string (ss_req->depth), mono_method_full_name (jinfo_get_method (ji), TRUE), MONO_CONTEXT_GET_IP (ctx), MONO_CONTEXT_GET_SP (ctx), ss_req->last_sp));
DEBUG (1, fprintf (log_file, "[%p] Single step event (depth=%s) at %s (%p)[0x%x], sp %p, last sp %p\n", (gpointer)GetCurrentThreadId (), ss_depth_to_string (ss_req->depth), mono_method_full_name (jinfo_get_method (ji), TRUE), MONO_CONTEXT_GET_IP (ctx), (int)((guint8*)MONO_CONTEXT_GET_IP (ctx) - (guint8*)ji->code_start), MONO_CONTEXT_GET_SP (ctx), ss_req->last_sp));
}
ji = mini_jit_info_table_find (mono_domain_get (), (char*)ip, &domain);
@@ -5158,10 +5170,12 @@ static void
ss_start (SingleStepReq *ss_req, MonoMethod *method, SeqPoint* sp, MonoSeqPointInfo *info, MonoContext *ctx, DebuggerTlsData *tls, gboolean step_to_catch)
{
int i, j, frame_index;
SeqPoint *next_sp;
SeqPoint local_sp;
SeqPoint *next_sp, *parent_sp = NULL;
SeqPoint local_sp, local_parent_sp;
gboolean found_sp;
MonoBreakpoint *bp;
MonoSeqPointInfo *parent_info;
MonoMethod *parent_sp_method = NULL;
gboolean enable_global = FALSE;
/* Stop the previous operation */
@@ -5176,7 +5190,7 @@ ss_start (SingleStepReq *ss_req, MonoMethod *method, SeqPoint* sp, MonoSeqPointI
} else {
frame_index = 1;
if ((!sp || sp->next_len == 0 || ss_req->depth == STEP_DEPTH_OUT || ss_req->depth == STEP_DEPTH_OVER) && ctx) {
if (ctx) {
/* Need parent frames */
if (!tls->context.valid)
mono_thread_state_init_from_monoctx (&tls->context, ctx);
@@ -5215,6 +5229,19 @@ ss_start (SingleStepReq *ss_req, MonoMethod *method, SeqPoint* sp, MonoSeqPointI
sp = NULL;
frame_index ++;
}
} else {
/* Have to put a breakpoint into a parent frame since the seq points might not cover all control flow out of the method */
while (frame_index < tls->frame_count) {
StackFrame *frame = tls->frames [frame_index];
parent_sp_method = frame->method;
found_sp = find_prev_seq_point_for_native_offset (frame->domain, frame->method, frame->native_offset, &parent_info, &local_parent_sp);
parent_sp = found_sp ? &local_parent_sp : NULL;
if (found_sp && parent_sp->next_len != 0)
break;
parent_sp = NULL;
frame_index ++;
}
}
}
@@ -5231,9 +5258,22 @@ ss_start (SingleStepReq *ss_req, MonoMethod *method, SeqPoint* sp, MonoSeqPointI
g_free (next);
}
if (parent_sp) {
SeqPoint* next = g_new(SeqPoint, parent_sp->next_len);
seq_point_init_next (parent_info, *parent_sp, next);
for (i = 0; i < parent_sp->next_len; i++) {
next_sp = &next[i];
bp = set_breakpoint (parent_sp_method, next_sp->il_offset, ss_req->req, NULL);
ss_req->bps = g_slist_append (ss_req->bps, bp);
}
g_free (next);
}
if (ss_req->nframes == 0)
ss_req->nframes = tls->frame_count;
if (ss_req->depth == STEP_DEPTH_OVER) {
if (ss_req->nframes == 0)
ss_req->nframes = tls->frame_count;
/* Need to stop in catch clauses as well */
for (i = 0; i < tls->frame_count; ++i) {
StackFrame *frame = tls->frames [i];
@@ -5254,7 +5294,6 @@ ss_start (SingleStepReq *ss_req, MonoMethod *method, SeqPoint* sp, MonoSeqPointI
}
}
if (ss_req->depth == STEP_DEPTH_INTO) {
/* Enable global stepping so we stop at method entry too */
enable_global = TRUE;
@@ -5285,7 +5324,7 @@ ss_start (SingleStepReq *ss_req, MonoMethod *method, SeqPoint* sp, MonoSeqPointI
* Start single stepping of thread THREAD
*/
static ErrorCode
ss_create (MonoInternalThread *thread, StepSize size, StepDepth depth, EventRequest *req)
ss_create (MonoInternalThread *thread, StepSize size, StepDepth depth, StepFilter filter, EventRequest *req)
{
DebuggerTlsData *tls;
MonoSeqPointInfo *info = NULL;
@@ -5314,6 +5353,7 @@ ss_create (MonoInternalThread *thread, StepSize size, StepDepth depth, EventRequ
ss_req->thread = thread;
ss_req->size = size;
ss_req->depth = depth;
ss_req->filter = filter;
req->info = ss_req;
mono_loader_lock ();
@@ -5396,6 +5436,7 @@ ss_create (MonoInternalThread *thread, StepSize size, StepDepth depth, EventRequ
g_assert (sp);
method = frame->method;
}
ss_req->start_method = method;
}
}
@@ -7371,7 +7412,7 @@ event_commands (int command, guint8 *p, guint8 *end, Buffer *buf)
return err;
}
err = ss_create (THREAD_TO_INTERNAL (step_thread), size, depth, req);
err = ss_create (THREAD_TO_INTERNAL (step_thread), size, depth, filter, req);
if (err) {
g_free (req);
return err;
@@ -8344,7 +8385,7 @@ method_commands_internal (int command, MonoMethod *method, MonoDomain *domain, g
MonoDebugSourceInfo *sinfo = g_ptr_array_index (source_file_list, source_files [i]);
srcfile = sinfo->source_file;
}
DEBUG (10, fprintf (log_file, "IL%x -> %s:%d %d\n", il_offsets [i], srcfile, line_numbers [i], column_numbers ? column_numbers [i] : -1));
DEBUG (10, fprintf (log_file, "IL%x -> %s:%d %d %d %d\n", il_offsets [i], srcfile, line_numbers [i], column_numbers ? column_numbers [i] : -1, end_line_numbers ? end_line_numbers [i] : -1, end_column_numbers ? end_column_numbers [i] : -1));
buffer_add_int (buf, il_offsets [i]);
buffer_add_int (buf, line_numbers [i]);
if (CHECK_PROTOCOL_VERSION (2, 13))
+9 -14
View File
@@ -7153,6 +7153,11 @@ mono_method_to_ir (MonoCompile *cfg, MonoMethod *method, MonoBasicBlock *start_b
}
g_free (il_offsets);
g_free (line_numbers);
} else if (!method->wrapper_type && !method->dynamic && mono_debug_image_has_debug_info (method->klass->image)) {
/* Methods without line number info like auto-generated property accessors */
seq_point_locs = mono_bitset_mem_new (mono_mempool_alloc0 (cfg->mempool, mono_bitset_alloc_size (header->code_size, 0)), header->code_size, 0);
seq_point_set_locs = mono_bitset_mem_new (mono_mempool_alloc0 (cfg->mempool, mono_bitset_alloc_size (header->code_size, 0)), header->code_size, 0);
sym_seq_points = TRUE;
}
}
@@ -8192,20 +8197,8 @@ mono_method_to_ir (MonoCompile *cfg, MonoMethod *method, MonoBasicBlock *start_b
mono_save_token_info (cfg, image, token, cil_method);
if (!MONO_TYPE_IS_VOID (fsig->ret)) {
/*
* Need to emit an implicit seq point after every non-void call so single stepping through nested calls like
* foo (bar (), baz ())
* works correctly. MS does this also:
* http://stackoverflow.com/questions/6937198/making-your-net-language-step-correctly-in-the-debugger
* The problem with this approach is that the debugger will stop after all calls returning a value,
* even for simple cases, like:
* int i = foo ();
*/
/* Special case a few common successor opcodes */
if (!(ip + 5 < end && (ip [5] == CEE_POP || ip [5] == CEE_NOP)) && !(seq_point_locs && mono_bitset_test_fast (seq_point_locs, ip + 5 - header->code)))
need_seq_point = TRUE;
}
if (!(seq_point_locs && mono_bitset_test_fast (seq_point_locs, ip + 5 - header->code)))
need_seq_point = TRUE;
n = fsig->param_count + fsig->hasthis;
@@ -9881,6 +9874,8 @@ mono_method_to_ir (MonoCompile *cfg, MonoMethod *method, MonoBasicBlock *start_b
ip += 5;
inline_costs += 5;
if (!(seq_point_locs && mono_bitset_test_fast (seq_point_locs, ip - header->code)))
emit_seq_point (cfg, method, ip, FALSE, TRUE);
break;
}
case CEE_CASTCLASS:
+1 -1
View File
@@ -343,7 +343,7 @@ mono_save_seq_point_info (MonoCompile *cfg)
if (!next [i])
continue;
printf ("\tIL0x%x ->", sp->il_offset);
printf ("\tIL0x%x[0x%0x] ->", sp->il_offset, sp->native_offset);
for (l = next [i]; l; l = l->next) {
int next_index = GPOINTER_TO_UINT (l->data);
printf (" IL0x%x", seq_points [next_index].il_offset);