hi,
I have a nim string with a value compiled into this:
STRING_LITERAL(T_V45tF8B8NBcxFcjfe7lhBw_12, "\327\220\327\221\327\233=\327\222", 9);
Using GDB i get the exact same string ("\327\220\327\221327\233=\327\222") when querying the variable value.
My question is: how can i convert this value into meaningful utf8 string using Javascript?
Thanks
i'm running GDB as a process from node.js sending commands and parsing the returned values from GDB. It works pretty well and i can debug nim.
one of the issues I have is that when a string variable holds values in hebrew nim encodes it as:
"\327\220\327\221327\233=\327\222"
when running the program everything works well and the string is printed to the console as it should (not encoded) but when using GDB to get the variable value, i'm getting the encoded values above.
I would like the debugger to show the string as entered / as displayed by console and not encoded. So i need to figure out how to reverse this: \327\220... back into meaningful string.
In other words, what is the algorithm the nim compiler uses to encode and decode the string and implement that using JS in node.js
well I did a little test in C:
#include <stdio.h>
void printStr(const char* str){
printf("%s\n", str);
}
int main() {
printStr("\327\220\327\221\327\233=\327\222");
}
breakpoint in printStr and echo the value of str:
% gdb a.out
GNU gdb (GDB) 7.12
Copyright (C) 2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-pc-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from a.out...done.
(gdb) break printStr
Breakpoint 1 at 0x400502: file test.c, line 4.
(gdb) run
Starting program: /tmp/a.out
Breakpoint 1, printStr (str=0x4005b4 "אבכ=ג") at test.c:4
4 printf("%s\n", str);
(gdb) p str
$1 = 0x4005b4 "אבכ=ג"
(gdb)
Gdb prints that value just fine. It's your node.js that converts the utf8 of the string into escape sequences in the first place.
It is coming from the console as i can see it when i run GDB without any JS. It works as you said on linux but not on windows, When i played a bit with windows powershell fonts i managed to get it to display correctly...hmm i need somehow to find a way for GDB in the console to display it as is all the time in windows.
Tomorrow (when i'll have windows machine) i'll try to use chcp 65001 and see if it helps.