Subj : Re: JSErrorReport->linebuf .. Help!! To : j From : Brendan Eich Date : Mon Feb 21 2005 10:43 am j@j.jp wrote: > Hello, > > I have two questions that have plagued me for the past 2 years of > working on Spidermonkey.. Please, help! > > > In my error handler, I have always had this section of code: > > .. > if(report->linebuf) { > addDebugLog( "%s\n", (char > *)report->linebuf ); You shouldn't need to cast to (char *) there. > .. > } > > However, it never fires off! linebuf is NEVER valid.. Only for syntax errors will linebuf be valid. For instance, (gdb) b my_ErrorReporter Breakpoint 1 at 0x804c14b: file js.c, line 1917. (gdb) r Starting program: /home/brendan/src/phoenix/mozilla/js/src-e4x/Linux_All_DBG.OBJ/js js> rewui Breakpoint 1, my_ErrorReporter (cx=0x9e96158, message=0x9eac7e8 "ReferenceError: rewui is not defined", report=0x9eaea60) at js.c:1917 1917 if (!report) { (gdb) p report $1 = (JSErrorReport *) 0x9eaea60 (gdb) p *$ $2 = {filename = 0x9eaea90 "typein", lineno = 1, linebuf = 0x0, tokenptr = 0x0, uclinebuf = 0x0, uctokenptr = 0x0, flags = 2, errorNumber = 1, ucmessage = 0x9eaeaa0, messageArgs = 0x9eaead0} (gdb) c Continuing. typein:1: ReferenceError: rewui is not defined js> @$#@ Breakpoint 1, my_ErrorReporter (cx=0x9e96158, message=0x9e95f50 "SyntaxError: illegal character", report=0x9e95990) at js.c:1917 1917 if (!report) { (gdb) p *report $3 = {filename = 0x9e959c0 "typein", lineno = 2, linebuf = 0x9e958e8 "@$#@\n", tokenptr = 0x9e958e8 "@$#@\n", uclinebuf = 0x9e959d0, uctokenptr = 0x9e959d0, flags = 2, errorNumber = 144, ucmessage = 0x9e95d18, messageArgs = 0x0} The first error is a run-time ReferenceError, where rewui is not defined. The second error is a syntax (lexical syntax) error, so linebuf and uclinebuf are set in the report structure. > I was reading > the docs for JSErrorReport ( > http://www.mozilla.org/js/spidermonkey/apidoc/gen/api-JSErrorReport.html > ), and they report: > > "linebuf is a pointer to a user-defined buffer into which JS copies > the offending line of the script." > > User defined... > > "To use JSErrorReport, your application must define a variable of type > JSErrorReport and allocate a buffer to hold the text that generated > the error condition. Set linebuf to point at the buffer before your > application executes a script." Sorry, the docs lie (yet again). This was never true, the writer just made it up AFAICT. Patches welcome (http://lxr.mozilla.org/mozilla/source/js/docs/). > My other question.. When using the js callback to step through a > script, is it possible to get each line of source code that is > executed, so I can create some sort of debug dump? (not compiled > opcode, but the actual source line being executed) I'm not sure what you mean by js callback, but the JS debugger, venkman, can show you which line you're on as you single-step, so yes: this is all possible. See jsdbgapi.h and the mozilla/js/jsd/ directory that layers a higher-level API on top of jsdbgapi. /be .