issue #82 use address of source string as sourceReference to make it unique

pull/85/head
Dibyendu Majumdar 8 years ago
parent 85958a64f3
commit 17df618b48

@ -59,7 +59,7 @@ static const char *get_string_value(json_value *js, const char *key,
return NULL;
}
static int get_int_value(json_value *js, const char *key, FILE *log,
static json_int_t get_int_value(json_value *js, const char *key, FILE *log,
int *found) {
(void)log;
*found = 0;
@ -252,12 +252,26 @@ static int vscode_parse_intarg_request(json_value *js, ProtocolMessage *msg,
json_value *args = get_object_value(js, "arguments", log);
if (args == NULL) return VSCODE_UNKNOWN_REQUEST;
int found = 0;
msg->u.Request.u.CommonIntRequest.integer =
msg->u.Request.u.CommonIntRequest.integer = (int)
get_int_value(args, key, log, &found);
msg->u.Request.request_type = msgtype;
return msgtype;
}
/* Parse VSCode request message which has an integer parameter
*/
static int vscode_parse_int64arg_request(json_value *js, ProtocolMessage *msg,
int msgtype, const char *key,
FILE *log) {
json_value *args = get_object_value(js, "arguments", log);
if (args == NULL) return VSCODE_UNKNOWN_REQUEST;
int found = 0;
msg->u.Request.u.CommonInt64Request.integer64 =
get_int_value(args, key, log, &found);
msg->u.Request.request_type = msgtype;
return msgtype;
}
/* replace back slashes with front slash
*/
static void fix_path(char *buf) {
@ -320,7 +334,7 @@ static int vscode_parse_set_breakpoints_request(json_value *js,
for (int i = 0; i < breakpoints->u.array.length && i < MAX_BREAKPOINTS; i++) {
json_value *element = breakpoints->u.array.values[i];
if (element->type != json_object) return VSCODE_UNKNOWN_REQUEST;
int line = get_int_value(element, "line", log, &found);
int line = (int) get_int_value(element, "line", log, &found);
fprintf(log, "Set breakpoint line = %d\n", line);
msg->u.Request.u.SetBreakpointsRequest.breakpoints[i].line =
found ? line : -1;
@ -335,11 +349,11 @@ static int vscode_parse_stack_trace_request(json_value *js,
json_value *args = get_object_value(js, "arguments", log);
if (args == NULL) return VSCODE_UNKNOWN_REQUEST;
int found = 0;
msg->u.Request.u.StackTraceRequest.threadId =
msg->u.Request.u.StackTraceRequest.threadId = (int)
get_int_value(args, "threadId", log, &found);
msg->u.Request.u.StackTraceRequest.levels =
msg->u.Request.u.StackTraceRequest.levels = (int)
get_int_value(args, "levels", log, &found);
msg->u.Request.u.StackTraceRequest.startFrame =
msg->u.Request.u.StackTraceRequest.startFrame = (int)
get_int_value(args, "startFrame", log, &found);
msg->u.Request.request_type = msgtype;
return msgtype;
@ -375,7 +389,7 @@ static int vscode_parse_request(json_value *js, ProtocolMessage *msg,
return vscode_parse_intarg_request(js, msg, cmdtype, "variablesReference",
log);
case VSCODE_SOURCE_REQUEST:
return vscode_parse_intarg_request(js, msg, cmdtype, "sourceReference",
return vscode_parse_int64arg_request(js, msg, cmdtype, "sourceReference",
log);
case VSCODE_LAUNCH_REQUEST:
return vscode_parse_launch_request(js, msg, cmdtype, log);
@ -404,7 +418,7 @@ int vscode_parse_message(char *buf, size_t len, ProtocolMessage *msg,
return msgtype;
}
static int seq = 1;
static int64_t seq = 1;
void vscode_make_error_response(ProtocolMessage *req, ProtocolMessage *res,
int restype, const char *errormsg) {
@ -501,8 +515,8 @@ void vscode_serialize_response(char *buf, size_t buflen, ProtocolMessage *res) {
buf[0] = 0;
if (res->type != VSCODE_RESPONSE) return;
snprintf(cp, sizeof temp - strlen(temp),
"{\"type\":\"response\",\"seq\":%d,\"command\":\"%s\",\"request_"
"seq\":%d,\"success\":%s",
"{\"type\":\"response\",\"seq\":%lld,\"command\":\"%s\",\"request_"
"seq\":%lld,\"success\":%s",
res->seq, res->u.Response.command, res->u.Response.request_seq,
res->u.Response.success ? "true" : "false");
cp = temp + strlen(temp);
@ -569,7 +583,7 @@ void vscode_serialize_response(char *buf, size_t buflen, ProtocolMessage *res) {
snprintf(
cp, sizeof temp - strlen(temp),
"{\"id\":%d,\"name\":\"%s\",\"column\":1,\"line\":%d,\"source\":"
"{\"name\":\"%s\",\"sourceReference\":%d}}",
"{\"name\":\"%s\",\"sourceReference\":%lld}}",
d, res->u.Response.u.StackTraceResponse.stackFrames[d].name,
res->u.Response.u.StackTraceResponse.stackFrames[d].line,
res->u.Response.u.StackTraceResponse.stackFrames[d].source.name,
@ -658,7 +672,7 @@ void vscode_serialize_response(char *buf, size_t buflen, ProtocolMessage *res) {
cp = temp + strlen(temp);
}
snprintf(cp, sizeof temp - strlen(temp), "}");
snprintf(buf, buflen, temp);
ravi_string_copy(buf, temp, buflen);
}
/*
@ -671,7 +685,7 @@ void vscode_serialize_event(char *buf, size_t buflen, ProtocolMessage *res) {
buf[0] = 0;
if (res->type != VSCODE_EVENT) return;
snprintf(cp, sizeof temp - strlen(temp),
"{\"type\":\"event\",\"seq\":%d,\"event\":\"%s\"", res->seq,
"{\"type\":\"event\",\"seq\":%lld,\"event\":\"%s\"", res->seq,
res->u.Event.event);
cp = temp + strlen(temp);
if (res->u.Event.event_type == VSCODE_OUTPUT_EVENT) {
@ -701,7 +715,7 @@ void vscode_serialize_event(char *buf, size_t buflen, ProtocolMessage *res) {
cp = temp + strlen(temp);
}
snprintf(cp, sizeof temp - strlen(temp), "}");
snprintf(buf, buflen, temp);
ravi_string_copy(buf, temp, buflen);
}
void vscode_send(ProtocolMessage *msg, FILE *out, FILE *log) {

@ -104,7 +104,7 @@ typedef struct {
typedef struct {
char name[NAME_LEN];
char path[PATH_LEN];
int sourceReference;
int64_t sourceReference;
} Source;
typedef struct {
@ -155,7 +155,7 @@ typedef struct {
*/
typedef struct {
int type;
int seq;
int64_t seq;
union {
struct {
@ -234,6 +234,10 @@ typedef struct {
int integer;
} CommonIntRequest;
struct {
int64_t integer64;
} CommonInt64Request;
struct {
int threadId;
} ContinueRequest;
@ -269,7 +273,7 @@ typedef struct {
} VariablesRequest;
struct {
int sourceReference;
int64_t sourceReference;
} SourceRequest;
struct {
@ -283,7 +287,7 @@ typedef struct {
struct {
int response_type;
int request_seq;
int64_t request_seq;
int success;
char command[COMMAND_LEN];
char message[TEXT_LEN];

@ -57,6 +57,11 @@ enum { VAR_TYPE_LOCALS = 1, VAR_TYPE_UPVALUES = 2, VAR_TYPE_GLOBALS = 3 };
#define EXTRACT_C(x) (((x) >> 16) & MASK)
#define EXTRACT_D(x) (((x) >> 24) & MASK)
typedef struct {
int depth;
int64_t sourceReference;
} SourceOnStack;
/*
* These statics are temporary - eventually they will be moved to
* the Lua global state; but right now while things are
@ -68,9 +73,9 @@ static int debugger_state = DEBUGGER_BIRTH;
static Breakpoint breakpoints[MAX_TOTAL_BREAKPOINTS];
static ProtocolMessage req, res;
static ProtocolMessage output_response;
static char LUA_PATH[1024];
static char LUA_CPATH[1024];
static char workingdir[1024];
static SourceOnStack sourceOnStack[MAX_STACK_FRAMES];
static int sourceOnStackCount = 0;
/*
* Generate response to InitializeRequest
@ -120,6 +125,7 @@ static void handle_stack_trace_request(ProtocolMessage *req,
lua_Debug entry;
int depth = 0;
vscode_make_success_response(req, res, VSCODE_STACK_TRACE_RESPONSE);
sourceOnStackCount = 0;
while (lua_getstack(L, depth, &entry) &&
depth < req->u.Request.u.StackTraceRequest.levels &&
depth < MAX_STACK_FRAMES) {
@ -162,7 +168,7 @@ static void handle_stack_trace_request(ProtocolMessage *req,
else if (memcmp(src, "=[C]", 4) == 0) {
/* Source is a string - send a reference to the stack frame */
res->u.Response.u.StackTraceResponse.stackFrames[depth]
.source.sourceReference = depth + 1;
.source.sourceReference = -1;
ravi_string_copy(
res->u.Response.u.StackTraceResponse.stackFrames[depth].source.name,
"<C function>",
@ -171,8 +177,16 @@ static void handle_stack_trace_request(ProtocolMessage *req,
}
else {
/* Source is a string - send a reference to the stack frame */
/* Currently (as ov VSCode 1.1 the sourceReference must be unique within
* a debug session. A cheap way of making this unique is to use the
* pointer to the source itself.
*/
int64_t sourceReference = (intptr_t)src;
/* following not range checked as already checked */
sourceOnStack[sourceOnStackCount].depth = depth;
sourceOnStack[sourceOnStackCount++].sourceReference = sourceReference;
res->u.Response.u.StackTraceResponse.stackFrames[depth]
.source.sourceReference = depth + 1;
.source.sourceReference = sourceReference;
/* name must be uniquely associated with the source else
* VSCode gets confused */
snprintf(
@ -197,7 +211,15 @@ static void handle_stack_trace_request(ProtocolMessage *req,
static void handle_source_request(ProtocolMessage *req, ProtocolMessage *res,
lua_State *L, FILE *out) {
lua_Debug entry;
int depth = req->u.Request.u.SourceRequest.sourceReference - 1;
int64_t sourceReference = req->u.Request.u.SourceRequest.sourceReference;
int depth = -1;
for (int i = 0; i < sourceOnStackCount; i++) {
if (sourceOnStack[i].sourceReference == sourceReference) {
depth = sourceOnStack[i].depth;
break;
}
}
fprintf(my_logger, "SEARCHING FOR sourceReference=%lld, found depth = %d\n", sourceReference, depth);
vscode_make_success_response(req, res, VSCODE_SOURCE_RESPONSE);
if (lua_getstack(L, depth, &entry)) {
int status = lua_getinfo(L, "Sln", &entry);

Loading…
Cancel
Save