jscript: Print source location in backtraces.
Signed-off-by: Jacek Caban <jacek@codeweavers.com> Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
parent
cdb264e871
commit
2986821b93
@ -2236,6 +2236,20 @@ static void resolve_labels(compiler_ctx_t *ctx, unsigned off)
|
||||
ctx->labels_cnt = 0;
|
||||
}
|
||||
|
||||
unsigned get_location_line(bytecode_t *code, unsigned loc, unsigned *char_pos)
|
||||
{
|
||||
unsigned line = code->start_line;
|
||||
const WCHAR *nl, *p;
|
||||
|
||||
for(nl = p = code->source; p < code->source + loc; p++) {
|
||||
if(*p != '\n') continue;
|
||||
line++;
|
||||
nl = p + 1;
|
||||
}
|
||||
*char_pos = loc - (nl - code->source);
|
||||
return line;
|
||||
}
|
||||
|
||||
void release_bytecode(bytecode_t *code)
|
||||
{
|
||||
unsigned i;
|
||||
|
@ -2703,7 +2703,7 @@ static void pop_call_frame(script_ctx_t *ctx)
|
||||
|
||||
static void print_backtrace(script_ctx_t *ctx)
|
||||
{
|
||||
unsigned depth = 0, i;
|
||||
unsigned depth = 0, i, line, char_pos;
|
||||
call_frame_t *frame;
|
||||
|
||||
for(frame = ctx->call_ctx; frame; frame = frame->prev_frame) {
|
||||
@ -2724,7 +2724,8 @@ static void print_backtrace(script_ctx_t *ctx)
|
||||
}else {
|
||||
WARN("[detached frame]");
|
||||
}
|
||||
WARN(")\n");
|
||||
line = get_location_line(frame->bytecode, frame->bytecode->instrs[frame->ip].loc, &char_pos);
|
||||
WARN(") context %s line %u char %u\n", wine_dbgstr_longlong(frame->bytecode->source_context), line, char_pos);
|
||||
|
||||
if(!(frame->flags & EXEC_RETURN_TO_INTERP)) {
|
||||
WARN("%u\t[native code]\n", depth);
|
||||
|
@ -201,6 +201,8 @@ struct _bytecode_t {
|
||||
HRESULT compile_script(script_ctx_t*,const WCHAR*,UINT64,unsigned,const WCHAR*,const WCHAR*,BOOL,BOOL,named_item_t*,bytecode_t**) DECLSPEC_HIDDEN;
|
||||
void release_bytecode(bytecode_t*) DECLSPEC_HIDDEN;
|
||||
|
||||
unsigned get_location_line(bytecode_t *code, unsigned loc, unsigned *char_pos) DECLSPEC_HIDDEN;
|
||||
|
||||
static inline bytecode_t *bytecode_addref(bytecode_t *code)
|
||||
{
|
||||
code->ref++;
|
||||
|
@ -257,8 +257,7 @@ static HRESULT WINAPI JScriptError_GetSourcePosition(IActiveScriptError *iface,
|
||||
{
|
||||
JScriptError *This = impl_from_IActiveScriptError(iface);
|
||||
bytecode_t *code = This->ei.code;
|
||||
const WCHAR *nl, *p;
|
||||
unsigned l;
|
||||
unsigned line_pos, char_pos;
|
||||
|
||||
TRACE("(%p)->(%p %p %p)\n", This, source_context, line, character);
|
||||
|
||||
@ -272,16 +271,11 @@ static HRESULT WINAPI JScriptError_GetSourcePosition(IActiveScriptError *iface,
|
||||
if(!line && !character)
|
||||
return S_OK;
|
||||
|
||||
l = code->start_line;
|
||||
for(nl = p = code->source; p < code->source + This->ei.loc; p++) {
|
||||
if(*p != '\n') continue;
|
||||
l++;
|
||||
nl = p + 1;
|
||||
}
|
||||
line_pos = get_location_line(code, This->ei.loc, &char_pos);
|
||||
if(line)
|
||||
*line = l;
|
||||
*line = line_pos;
|
||||
if(character)
|
||||
*character = code->source + This->ei.loc - nl;
|
||||
*character = char_pos;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user