Skip to content

Commit 39e022d

Browse files
authored
[mono][debugger] Support step over and pause multiple times in same line but different columns (#85484)
* Support step over and pause multiple times in a like like this: for (int i = 0; i < 10; i++) * Fix name on wasm code. * Adding support to new message MDBGPROT_CMD_STACK_FRAME_GET_COUNT * Changing position of create_file_to_check_memory_address function * Adding another command MDBGPROT_CMD_STACK_FRAME_GET_PARAMETERS_COUNT * Fix arguments count
1 parent 5d370f3 commit 39e022d

File tree

6 files changed

+78
-52
lines changed

6 files changed

+78
-52
lines changed

src/mono/mono/component/debugger-agent.c

Lines changed: 65 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -4724,17 +4724,19 @@ mono_ss_create_init_args (SingleStepReq *ss_req, SingleStepArgs *args)
47244724
frame = tls->frames [0];
47254725
}
47264726

4727-
if (ss_req->size == STEP_SIZE_LINE) {
4727+
if (ss_req->size == STEP_SIZE_LINE_COLUMN) {
47284728
if (frame) {
47294729
ss_req->last_method = frame->de.method;
47304730
ss_req->last_line = -1;
4731+
ss_req->last_column = -1;
47314732

47324733
minfo = mono_debug_lookup_method (frame->de.method);
47334734
if (minfo && frame->il_offset != -1) {
47344735
MonoDebugSourceLocation *loc = mono_debug_method_lookup_location (minfo, frame->il_offset);
47354736

47364737
if (loc) {
47374738
ss_req->last_line = loc->row;
4739+
ss_req->last_column = loc->column;
47384740
g_free (loc);
47394741
}
47404742
}
@@ -6907,6 +6909,44 @@ static void add_error_string (Buffer *buf, const char *str)
69076909
buffer_add_string (buf, str);
69086910
}
69096911

6912+
static void
6913+
create_file_to_check_memory_address (void)
6914+
{
6915+
if (file_check_valid_memory != -1)
6916+
return;
6917+
char *file_name = g_strdup_printf ("debugger_check_valid_memory.%d", mono_process_current_pid ());
6918+
filename_check_valid_memory = g_build_filename (g_get_tmp_dir (), file_name, (const char*)NULL);
6919+
file_check_valid_memory = open(filename_check_valid_memory, O_CREAT | O_WRONLY | O_APPEND, S_IWUSR);
6920+
g_free (file_name);
6921+
}
6922+
6923+
static gboolean
6924+
valid_memory_address (gpointer addr, gint size)
6925+
{
6926+
#ifndef _MSC_VER
6927+
gboolean ret = TRUE;
6928+
create_file_to_check_memory_address ();
6929+
if(file_check_valid_memory < 0) {
6930+
return TRUE;
6931+
}
6932+
write (file_check_valid_memory, (gpointer)addr, 1);
6933+
if (errno == EFAULT) {
6934+
ret = FALSE;
6935+
}
6936+
#else
6937+
int i = 0;
6938+
gboolean ret = FALSE;
6939+
__try {
6940+
for (i = 0; i < size; i++)
6941+
*((volatile char*)addr+i);
6942+
ret = TRUE;
6943+
} __except(1) {
6944+
return ret;
6945+
}
6946+
#endif
6947+
return ret;
6948+
}
6949+
69106950
static ErrorCode
69116951
vm_commands (int command, int id, guint8 *p, guint8 *end, Buffer *buf)
69126952
{
@@ -7252,6 +7292,8 @@ vm_commands (int command, int id, guint8 *p, guint8 *end, Buffer *buf)
72527292
case MDBGPROT_CMD_VM_READ_MEMORY: {
72537293
guint8* memory = (guint8*)GINT_TO_POINTER (decode_long (p, &p, end));
72547294
int size = decode_int (p, &p, end);
7295+
if (!valid_memory_address(memory, size))
7296+
return ERR_INVALID_ARGUMENT;
72557297
PRINT_DEBUG_MSG (1, "MDBGPROT_CMD_VM_READ_MEMORY - [%p] - size - %d\n", memory, size);
72567298
buffer_add_byte_array (buf, memory, size);
72577299
break;
@@ -9840,6 +9882,7 @@ frame_commands (int command, guint8 *p, guint8 *end, Buffer *buf)
98409882
return cmd_stack_frame_get_this (frame, sig, buf, jit);
98419883
break;
98429884
}
9885+
case MDBGPROT_CMD_STACK_FRAME_SET_VALUES_2:
98439886
case CMD_STACK_FRAME_SET_VALUES: {
98449887
guint8 *val_buf;
98459888
MonoType *t;
@@ -9852,8 +9895,9 @@ frame_commands (int command, guint8 *p, guint8 *end, Buffer *buf)
98529895

98539896
for (i = 0; i < len; ++i) {
98549897
pos = decode_int (p, &p, end);
9855-
98569898
if (pos < 0) {
9899+
if (command == MDBGPROT_CMD_STACK_FRAME_SET_VALUES_2 && sig->hasthis) //0 == this
9900+
pos++;
98579901
pos = - pos - 1;
98589902

98599903
g_assert (pos >= 0 && GINT_TO_UINT32(pos) < jit->num_params);
@@ -9943,6 +9987,19 @@ frame_commands (int command, guint8 *p, guint8 *end, Buffer *buf)
99439987
buffer_add_long (buf, (gssize)frame->frame_addr);
99449988
break;
99459989
}
9990+
case MDBGPROT_CMD_STACK_FRAME_GET_COUNT: {
9991+
MonoDebugLocalsInfo *locals;
9992+
locals = mono_debug_lookup_locals (frame->de.method);
9993+
if (locals)
9994+
buffer_add_int (buf, locals->num_locals);
9995+
else
9996+
buffer_add_int (buf, 0);
9997+
break;
9998+
}
9999+
case MDBGPROT_CMD_STACK_FRAME_GET_PARAMETERS_COUNT: {
10000+
buffer_add_int (buf, jit->num_params + (sig->hasthis ? 1 : 0));
10001+
break;
10002+
}
994610003
default:
994710004
return ERR_NOT_IMPLEMENTED;
994810005
}
@@ -10085,44 +10142,6 @@ string_commands (int command, guint8 *p, guint8 *end, Buffer *buf)
1008510142
return ERR_NONE;
1008610143
}
1008710144

10088-
static void
10089-
create_file_to_check_memory_address (void)
10090-
{
10091-
if (file_check_valid_memory != -1)
10092-
return;
10093-
char *file_name = g_strdup_printf ("debugger_check_valid_memory.%d", mono_process_current_pid ());
10094-
filename_check_valid_memory = g_build_filename (g_get_tmp_dir (), file_name, (const char*)NULL);
10095-
file_check_valid_memory = open(filename_check_valid_memory, O_CREAT | O_WRONLY | O_APPEND, S_IWUSR);
10096-
g_free (file_name);
10097-
}
10098-
10099-
static gboolean
10100-
valid_memory_address (gpointer addr, gint size)
10101-
{
10102-
#ifndef _MSC_VER
10103-
gboolean ret = TRUE;
10104-
create_file_to_check_memory_address ();
10105-
if(file_check_valid_memory < 0) {
10106-
return TRUE;
10107-
}
10108-
write (file_check_valid_memory, (gpointer)addr, 1);
10109-
if (errno == EFAULT) {
10110-
ret = FALSE;
10111-
}
10112-
#else
10113-
int i = 0;
10114-
gboolean ret = FALSE;
10115-
__try {
10116-
for (i = 0; i < size; i++)
10117-
*((volatile char*)addr+i);
10118-
ret = TRUE;
10119-
} __except(1) {
10120-
return ret;
10121-
}
10122-
#endif
10123-
return ret;
10124-
}
10125-
1012610145
static ErrorCode
1012710146
pointer_commands (int command, guint8 *p, guint8 *end, Buffer *buf)
1012810147
{
@@ -10273,11 +10292,12 @@ object_commands (int command, guint8 *p, guint8 *end, Buffer *buf)
1027310292
len = decode_int (p, &p, end);
1027410293
i = 0;
1027510294
int field_token = decode_int (p, &p, end);
10276-
gpointer iter = NULL;
10277-
10278-
while ((f = mono_class_get_fields_internal (obj_type, &iter))) {
10279-
if (mono_class_get_field_token (f) == field_token)
10280-
goto set_field_value;
10295+
for (k = obj_type; k; k = m_class_get_parent (k)) {
10296+
gpointer iter = NULL;
10297+
while ((f = mono_class_get_fields_internal (k, &iter))) {
10298+
if (mono_class_get_field_token (f) == field_token)
10299+
goto set_field_value;
10300+
}
1028110301
}
1028210302
goto invalid_fieldid;
1028310303
case CMD_OBJECT_REF_SET_VALUES:

src/mono/mono/component/debugger-engine.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -966,7 +966,7 @@ mono_de_ss_update (SingleStepReq *req, MonoJitInfo *ji, SeqPoint *sp, void *tls,
966966
mono_debug_free_method_async_debug_info (async_method);
967967
}
968968

969-
if (req->size != STEP_SIZE_LINE)
969+
if (req->size != STEP_SIZE_LINE_COLUMN)
970970
return TRUE;
971971

972972
/* Have to check whenever a different source line was reached */
@@ -979,8 +979,9 @@ mono_de_ss_update (SingleStepReq *req, MonoJitInfo *ji, SeqPoint *sp, void *tls,
979979
PRINT_DEBUG_MSG (1, "[%p] No line number info for il offset %x, don't know if it's in the same line single stepping.\n", (gpointer) (gsize) mono_native_thread_id_get (), sp->il_offset);
980980
req->last_method = method;
981981
req->last_line = -1;
982+
req->last_column = -1;
982983
return hit;
983-
} else if (loc && method == req->last_method && loc->row == req->last_line) {
984+
} else if (loc && method == req->last_method && loc->row == req->last_line && loc->column == req->last_column) {
984985
int nframes;
985986
rt_callbacks.ss_calculate_framecount (tls, ctx, FALSE, NULL, &nframes);
986987
if (nframes == req->nframes) { // If the frame has changed we're clearly not on the same source line.
@@ -992,6 +993,7 @@ mono_de_ss_update (SingleStepReq *req, MonoJitInfo *ji, SeqPoint *sp, void *tls,
992993
if (loc) {
993994
req->last_method = method;
994995
req->last_line = loc->row;
996+
req->last_column = loc->column;
995997
mono_debug_free_source_location (loc);
996998
}
997999

src/mono/mono/component/debugger-engine.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@
168168
#define STEP_DEPTH_OUT MDBGPROT_STEP_DEPTH_OUT
169169
#define STEP_DEPTH_INTO MDBGPROT_STEP_DEPTH_INTO
170170
#define STEP_SIZE_MIN MDBGPROT_STEP_SIZE_MIN
171-
#define STEP_SIZE_LINE MDBGPROT_STEP_SIZE_LINE
171+
#define STEP_SIZE_LINE_COLUMN MDBGPROT_STEP_SIZE_LINE_COLUMN
172172

173173
#define SUSPEND_POLICY_NONE MDBGPROT_SUSPEND_POLICY_NONE
174174
#define SUSPEND_POLICY_ALL MDBGPROT_SUSPEND_POLICY_ALL

src/mono/mono/component/debugger-protocol.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,10 @@ typedef enum {
226226
MDBGPROT_CMD_STACK_FRAME_SET_THIS = 5,
227227
MDBGPROT_CMD_STACK_FRAME_GET_ARGUMENT = 6,
228228
MDBGPROT_CMD_STACK_FRAME_GET_ARGUMENTS = 7,
229-
MDBGPROT_CMD_STACK_FRAME_GET_ADDRESS = 8
229+
MDBGPROT_CMD_STACK_FRAME_GET_ADDRESS = 8,
230+
MDBGPROT_CMD_STACK_FRAME_SET_VALUES_2 = 9,
231+
MDBGPROT_CMD_STACK_FRAME_GET_COUNT = 10,
232+
MDBGPROT_CMD_STACK_FRAME_GET_PARAMETERS_COUNT = 11
230233
} MdbgProtCmdStackFrame;
231234

232235
typedef enum {
@@ -335,7 +338,7 @@ typedef enum {
335338

336339
typedef enum {
337340
MDBGPROT_STEP_SIZE_MIN = 0,
338-
MDBGPROT_STEP_SIZE_LINE = 1
341+
MDBGPROT_STEP_SIZE_LINE_COLUMN = 1
339342
} MdbgProtStepSize;
340343

341344
typedef enum {

src/mono/mono/component/debugger.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ typedef struct {
9595
MonoMethod *start_method;
9696
MonoMethod *last_method;
9797
int last_line;
98+
int last_column;
9899
/* Whenever single stepping is performed using start/stop_single_stepping () */
99100
gboolean global;
100101
/* The list of breakpoints used to implement step-over */

src/mono/wasm/debugger/BrowserDebugProxy/MonoSDBHelper.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ internal enum StepFilter {
359359
internal enum StepSize
360360
{
361361
Minimal,
362-
Line
362+
LineColumn
363363
}
364364

365365
internal sealed record ArrayDimensions
@@ -1431,7 +1431,7 @@ public async Task<bool> Step(int thread_id, StepKind kind, CancellationToken tok
14311431
commandParamsWriter.Write((byte)1);
14321432
commandParamsWriter.Write((byte)ModifierKind.Step);
14331433
commandParamsWriter.Write(thread_id);
1434-
commandParamsWriter.Write((int)StepSize.Line);
1434+
commandParamsWriter.Write((int)StepSize.LineColumn);
14351435
commandParamsWriter.Write((int)kind);
14361436
commandParamsWriter.Write((int)(StepFilter.StaticCtor)); //filter
14371437
using var retDebuggerCmdReader = await SendDebuggerAgentCommand(CmdEventRequest.Set, commandParamsWriter, token, throwOnError: false);

0 commit comments

Comments
 (0)