issue #82 improve debugger use of variableReference

pull/93/merge
Dibyendu Majumdar 8 years ago
parent ce99b4927f
commit 89c219d49b

@ -1122,3 +1122,34 @@ void vscode_string_copy(char *buf, const char *src, size_t buflen) {
strncpy(buf, src, buflen);
buf[buflen - 1] = 0;
}
int64_t vscode_pack(PackedInteger *pi) {
int64_t i = 0;
assert(pi->a8 <= 0xFF);
assert(pi->b8 <= 0xFF);
assert(pi->c8 <= 0xFF);
assert(pi->d8 <= 0xFF);
assert(pi->e8 <= 0xFF);
assert(pi->f8 <= 0xFF);
assert(pi->g4 <= 0x0F);
i |= (pi->a8 & 0xFF);
i |= ((int64_t)(pi->b8 & 0xFF) << 8);
i |= ((int64_t)(pi->c8 & 0xFF) << 16);
i |= ((int64_t)(pi->d8 & 0xFF) << 24);
i |= ((int64_t)(pi->e8 & 0xFF) << 32);
i |= ((int64_t)(pi->f8 & 0xFF) << 40);
i |= ((int64_t)(pi->g4 & 0x0F) << 48);
return i;
}
void vscode_unpack(int64_t i, PackedInteger *pi) {
int64_t mask = 0xFF;
pi->a8 = (unsigned int)(i & mask); mask <<= 8;
pi->b8 = (unsigned int)((i & mask) >> 8); mask <<= 8;
pi->c8 = (unsigned int)((i & mask) >> 16); mask <<= 8;
pi->d8 = (unsigned int)((i & mask) >> 24); mask <<= 8;
pi->e8 = (unsigned int)((i & mask) >> 32); mask <<= 8;
pi->f8 = (unsigned int)((i & mask) >> 40); mask <<= 8;
pi->g4 = (unsigned int)(((i & mask) >> 48) & 0x0F);
}

@ -92,6 +92,22 @@ enum {
MAX_TOTAL_BREAKPOINTS = 20
};
/*
The max integer that can be transferred to a Javascript number (and hence JSON
number) is 2^53-1 which is equal to 9007199254740991. This takes up 53 bits.
The integer 4503599627370495 takes up 52 bits - so that means 6 8-bit values and 1
4-bit value can be accomodated.
*/
typedef struct {
unsigned int a8;
unsigned int b8;
unsigned int c8;
unsigned int d8;
unsigned int e8;
unsigned int f8;
unsigned int g4;
} PackedInteger;
typedef struct {
int id;
char format[TEXT_LEN];
@ -396,5 +412,7 @@ extern void vscode_json_stringify(const char *src, char *dest, size_t len);
/* guaranteed null termination */
extern void vscode_string_copy(char *buf, const char *src, size_t buflen);
extern int64_t vscode_pack(PackedInteger *pi);
extern void vscode_unpack(int64_t i, PackedInteger *pi);
#endif

@ -102,9 +102,57 @@ int test_membuff() {
return 0;
}
int test_intpacking() {
int64_t ix = 4503599627370495;
int64_t i1 = 9007199254740991;
double d = (double) i1;
int64_t i2 = (int64_t) d;
fprintf(stderr, "%lld, %0.15f, %lld\n", i1, d, i2);
if (i1 != i2)
return 1;
PackedInteger pi;
pi.a8 = 0xFF;
pi.b8 = 0xFF;
pi.c8 = 0xFF;
pi.d8 = 0xFF;
pi.e8 = 0xFF;
pi.f8 = 0xFF;
pi.g4 = 0x0F;
int64_t i3 = vscode_pack(&pi);
d = (double) i3;
i2 = (int64_t) d;
fprintf(stderr, "%lld, %0.15f, %lld\n", i3, d, i2);
if (i3 != ix)
return 1;
PackedInteger p2 = { 0 };
vscode_unpack(i3, &p2);
if (memcmp(&pi, &p2, sizeof(PackedInteger)) != 0)
return 1;
fprintf(stderr, "%x %x %x %x %x %x %x\n", p2.a8, p2.b8, p2.c8, p2.d8, p2.e8, p2.f8, p2.g4);
pi.a8 = 127;
pi.b8 = 212;
pi.c8 = 13;
pi.d8 = 55;
pi.e8 = 220;
pi.f8 = 0;
pi.g4 = 15;
i3 = vscode_pack(&pi);
d = (double)i3;
i2 = (int64_t)d;
fprintf(stderr, "%lld, %0.15f, %lld\n", i3, d, i2);
if (i3 != i2)
return 1;
vscode_unpack(i3, &p2);
fprintf(stderr, "%u %u %u %u %u %u %u\n", p2.a8, p2.b8, p2.c8, p2.d8, p2.e8, p2.f8, p2.g4);
if (memcmp(&pi, &p2, sizeof(PackedInteger)) != 0)
return 1;
return 0;
}
int main(void) {
setbuf(stdout, NULL);
int rc = 0;
rc += test_intpacking();
rc += test_initreq();
rc += test_json_stringify();
rc += test_membuff();

Loading…
Cancel
Save