Here's the test script: ==== function foo:long() %{ THIS->__retvalue = 5; } probe begin ( printf("%d\n", foo()) } ==== Notice that the closing brace of the embedded-C function should be '%}', not '}'. Here's what you get when you run this script. ==== # stap -vg test.stp parse error: expected '{' saw: junk '??THIS->__retvalue = 5;?}??probe begin?(??printf("%d\n", foo())?}' at junk.stp:2:1 source: %{ ^ 1 parse error(s). Pass 1: parsed user script and 63 library script(s) using 83216virt/20040res/2396shr kb, in 150usr/50sys/201real ms. Pass 1: parse failed. Try again with another '--vp 1' option. ==== The translator's error message is completely confusing. It points at the open bracket, not at the lack of a proper closing bracket.
The problem is in the tokenizer -- it treats an entire "%{...%}" as one big tok_embedded token. If it doesn't find the closing, you instead get a tok_junk "%{...EOF". You get similar weirdness from unterminated strings: $ stap -ve 'global s = "foo' parse error: expected literal string or number saw: junk 'foo' at <input>:1:12 source: global s = "foo ^ IMO, there no use for the tokenizer to generate tok_junk -- it should just throw an error right away indicating *why* it is junk...
Created attachment 4671 [details] Patch for 10913 *Very* short patch for 10913. Would error messages like this be okay? Embedded: parse error: could not find matching '%}' to close embedded function block at: embedded-code at /home/chwang/Desktop/turnip.stp:3:1 source: %{ ^ Quotes: parse error: Could not find matching closing quote at: string 'enterprise' at <input>:1:17 source: global starship="enterprise ^ parse error: Could not find matching closing quote at: string 'turnip)}' at <input>:3:21 source: probe begin {printf("turnip)} ^ Took a look at doing something similar for '{' mismatches as well, but haven't managed to do so without accidentally wiping out other errors within the block.
(In reply to comment #2) > Created an attachment (id=4671) > Patch for 10913 > > *Very* short patch for 10913. > > Would error messages like this be okay? > > Embedded: > parse error: could not find matching '%}' to close embedded function block > at: embedded-code at /home/chwang/Desktop/turnip.stp:3:1 > source: %{ > ^ > > Quotes: > parse error: Could not find matching closing quote > at: string 'enterprise' at <input>:1:17 > source: global starship="enterprise > ^ > parse error: Could not find matching closing quote > at: string 'turnip)}' at <input>:3:21 > source: probe begin {printf("turnip)} > ^ > > Took a look at doing something similar for '{' mismatches as well, but haven't > managed to do so without accidentally wiping out other errors within the block. Your new error messages look reasonable to me.
Pushed with the error messages above on 2010-03-23, 11:55:56 72cdb9cd5afd6936a189b26a29eb8aa23d32a4fa
committed