Bug 10913 - bad/misleading translator error message
Summary: bad/misleading translator error message
Status: RESOLVED FIXED
Alias: None
Product: systemtap
Classification: Unclassified
Component: translator (show other bugs)
Version: unspecified
: P2 normal
Target Milestone: ---
Assignee: Unassigned
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-11-06 19:36 UTC by David Smith
Modified: 2010-03-30 13:11 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments
Patch for 10913 (351 bytes, text/plain)
2010-03-22 19:14 UTC, Charley
Details

Note You need to log in before you can comment on or make changes to this bug.
Description David Smith 2009-11-06 19:36:27 UTC
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.
Comment 1 Josh Stone 2009-11-06 20:11:55 UTC
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...
Comment 2 Charley 2010-03-22 19:14:45 UTC
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.
Comment 3 David Smith 2010-03-22 21:01:49 UTC
(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.
Comment 4 Charley 2010-03-23 15:58:40 UTC
Pushed with the error messages above on 2010-03-23, 11:55:56

72cdb9cd5afd6936a189b26a29eb8aa23d32a4fa
Comment 5 Frank Ch. Eigler 2010-03-30 13:11:47 UTC
committed