[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Storing a hash of the source file for debug info
- From: Thomas Jericke <tjericke@...>
- Date: Fri, 03 May 2013 08:40:08 +0200
Hi all
I am currently improving our editor/debugger (just finished painting
globals purple :-) ) and my current task is to improve the source lookup.
Currently the lookup is based on the sourcename alone. This is usually
OK but we have several cases where it is possible that different
versions of the same file is loaded in the interpreter. Or the source in
the interpreter is very old, our application can literally run for
months. The most obvious case of a source/interpreter conflict is when a
programmer mode changes/fixes without restarting the program (=
restarting the machine).
So what I like to do is to store a hash of the source file which is then
provided with the lua_Debug information. Once I am debugging a file I
can use the hash to double check if the file that the editor is showing
is really the one that the interpreter runs. I am then able to warn the
user or show a "source not found" error.
As I see it I need to add and receive the hash at exactly the same
places as the source-name that would be in the "Proto" struct field
"source". Now what I thought, as the two always go together, I could
actually store the hash inside the source variable. I would than have
the advantage of being backwards and forward compatible that is: I could
load compiled Lua code from a patched parser into an unpatched
interpreter, and I could load Lua code from an unpatched parser into a
patched interpreter.
My idea is, as a Lua string may have \0 within the string, I could just
add the hash behind the name like:
"@mysource.lua\0THEHASHGOESHERE"
As the length of the string is stored, my patched interpreter will find
out if there is a hash or not, on the other hand a old interpreter will
simply return the char* pointer of to the name, which is from a C/C++
point of view still the same as before.
It will break the comparability of old interpreters using the Lua debug
library (not the C debug API), but we are not using the Lua debug
library anyway only the API.
So what do you think? Are there any incompatibilities I don't see? I am
open to any input.
--
Thomas