3
0
mirror of https://github.com/pragma-/pbot.git synced 2024-12-25 20:22:37 +01:00

pbot-vm: fix occasional "illegal escape sequence" in guest-gdb

This commit is contained in:
Pragmatic Software 2022-03-15 13:53:34 -07:00
parent bf8749ff9e
commit 01cefe462f

View File

@ -142,9 +142,17 @@ sub gdb_read_result($out) {
return $output;
}
sub gdbmi_to_json($text, $makejson = 1) {
# convert gdb/mi text to hashtable, converting to JSON first if necessary
sub gdbmi_to_hash($text, $makejson = 1) {
# convert to JSON first if necessary (gdb/mi is nearly JSON already!)
$text =~ s/([\w-]+)=/"$1":/g if $makejson;
$text =~ s/\\(\d{3})/$1 >= 0x20 ? chr oct $1 : "\\$1"/ge;
# decode gdb octal escapes
# (sometimes \\123, othertimes \123 and I can't be arsed to investigate
# when and why the backslashes double up)
$text =~ s/\\+(\d{3})/$1 >= 0x20 ? chr oct $1 : "\\\\$1"/ge;
# return hashtable decoded from json
return decode_json("{$text}");
}
@ -165,7 +173,7 @@ sub parse_gdbmi_output($line) {
$text = "\"_text\":$text";
}
my $output = gdbmi_to_json($text, $makejson);
my $output = gdbmi_to_hash($text, $makejson);
if (exists $output->{_text}) {
chomp $output->{_text};