New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GetCallStack reports wrong line numbers #281
Comments
Sounds probable, the 'PC' in the internal data structures is always for the next instuction to execute. I'll take a look at this in a bit. |
Yep, the issue is here: https://github.com/svaarala/duktape/blob/master/src/duk_debugger.c#L1154. Line numbers are interesting: for the current PC/line people (me included) expect the debugger to point to the next instruction which is not yet executed. However, for the callstack below us it's usually expected that the line points to the current instruction because it's still conceptually in progress. So when dumping the callstack, should the pc/line for the topmost activation reflect the next instruction and for others the current instruction? |
Error |
Ah, actually no. When the tracedata is collected, PCs are decremented by one so that in |
Ok, so to summarize:
|
Yes, for activations other than the topmost one the correct value isn't really in question: The only logical instruction to call out is the function call currently in progress. For the callstack top while the debugger is paused, the bytecode executor is logically between instructions, however I wouldn't say either side is equally plausible: I would intuitively expect that clicking the current call in a stack view would highlight the exact same line highlighted when execution was first paused--i.e. the one which will be executed if a StepOver is performed. This matches, e.g. MSVC's behavior. For |
Just to verify, I can fix this locally by simply subtracting 1 from |
Yes, but you need to check pc isn't zero (it can be for native functions and probably in some corner cases) before subtracting. And also value stack top may need different handling. I'll work up a fix branch for this. Thanks for bringing this up, it was a clear oversight. |
Here's the branch: https://github.com/svaarala/duktape/compare/debugger-callstack-line-gh281 Here's a snapshot if you want to try it out: http://duktape.org/snapshots/duktape-1.2.99-20150815144710-v1.2.0-349-gb2b8784.tar.xz |
It looks like quite a bit was changed in the branch, so I'll try the snapshot out later today and let you know the results. |
I only changed the GetCallStack handling of PC/line and some comments. |
Okay, yeah, I see it now, you rewrote a few comments to make them more descriptive. That's one thing that's always impressed me with Duktape, how well documented the code is. :) |
Out of curiosity, when is the stack trace for errors created? When the Error is constructed, or when it is actually thrown? In most cases this is done in one statement, but sometimes the constructed error object might be manipulated first, in which case the construction and the throw could be on different lines. |
It's created when an Error instance is constructed, here: https://github.com/svaarala/duktape/blob/master/src/duk_api_call.c#L391-L399 It seems like a bit of an odd place (at least for my intuition) but augmenting an error at throw time would sometimes be incorrect - and an error can actually be thrown multiple times which would then be somewhat confusing. |
The snapshot works great, all lower stack entries report the line number of the function call-in-progress. :) |
Okay, merged to master. Thanks! |
No problem, always glad to help! On a somewhat related note, how are native functions reported in a stack dump? If possible I'd like to be able to differentiate any non-JS calls when populating a callstack window. |
So it doesn't look like this was actually merged? Either that or just not pushed to GitHub yet... |
Fix debugger GetCallStack line number semantics so that for value stack entries below the topmost entry PC/line will reflect the opcode in progress rather than the opcode following that (GH-281).
Forgot the push, it's now in. |
Regression: Latest master now reports previous instruction for top of callstack (it doesn't match Status) |
Okay, did some digging, and I'm thinking the bug is here: if (i != curr_thr->callstack_top && pc > 0) { Shouldn't that be |
Yeah, that looks wrong. Fixed in master. |
Here's a snapshot from master with the fix: http://duktape.org/snapshots/duktape-1.2.99-20150822123309-v1.2.0-367-gc44072c.tar.xz |
That snapshot fixed it, thanks. I noticed this one right away because my debugger actually bases the line to highlight on the callstack now instead of the status notification (I have my reasons for this. 😉). |
The GetCallStack debug command appears to suffer from the same issue as described for
Duktape.act()
in #143: The line number is for the instruction AFTER the call, rather than the call itself. I'm presuming it's the same root cause.The text was updated successfully, but these errors were encountered: