Skip to content

Commit

Permalink
[wasm-ep] diagnostic server IPC fixups (#72859)
Browse files Browse the repository at this point in the history
* [wasm-ep] Trim trailing nul when parsing IPC command strings

The protocol spec says there's a length and a nul terminator, but sending that literal UTF-16 nul to ep_enable_2 means we use an incorrect name when looking for the provider.

* [wasm-ep] Fix formating of event pipe provider strings

   convert the 64-bit "keywords" mask into a hex string properly by padding both halves with zeroes after calling the JS Number.toString() method

* use Array splice instead of String substring

* Address review feedback
  • Loading branch information
lambdageek authored Jul 29, 2022
1 parent 7ca4d6f commit c734a8e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
</PropertyGroup>

<PropertyGroup>
<MonoDiagnosticsMock Condition="'$(MonoDiagnosticsMock)' == ''">false</MonoDiagnosticsMock>
<MonoDiagnosticsMock Condition="('$(MonoDiagnosticsMock)' == '') and ('$(Configuration)' == 'Debug')">true</MonoDiagnosticsMock>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,19 @@ const Parser = {
result[i] = (buf[j + 2 * i + 1] << 8) | buf[j + 2 * i];
}
advancePos(pos, length * 2);

/* Trim trailing nul character(s) that are added by the protocol */
let trailingNulStart = -1;
for (let i = result.length - 1; i >= 0; i--) {
if (result[i] === 0) {
trailingNulStart = i;
} else {
break;
}
}
if (trailingNulStart >= 0)
result.splice(trailingNulStart);

return String.fromCharCode.apply(null, result);
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,17 @@ function providersStringFromObject(providers: EventPipeCollectTracingCommandProv
function keywordsToHexString(k: [number, number]): string {
const lo = k[0];
const hi = k[1];
const lo_hex = lo.toString(16);
const hi_hex = hi.toString(16);
const lo_hex = leftPad(lo.toString(16), "0", 8);
const hi_hex = leftPad(hi.toString(16), "0", 8);
return hi_hex + lo_hex;
}

function leftPad(s: string, fill: string, width: number): string {
if (s.length >= width)
return s;
const prefix = fill.repeat(width - s.length);
return prefix + s;
}
}


Expand Down

0 comments on commit c734a8e

Please sign in to comment.