Jacek Caban : jscript: Print source location in backtraces.

Alexandre Julliard julliard at winehq.org
Wed Mar 10 14:58:46 CST 2021


Module: wine
Branch: master
Commit: 2986821b933c239b1b16def8eb87bc0df3ed1d91
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=2986821b933c239b1b16def8eb87bc0df3ed1d91

Author: Jacek Caban <jacek at codeweavers.com>
Date:   Wed Mar 10 14:59:57 2021 +0100

jscript: Print source location in backtraces.

Signed-off-by: Jacek Caban <jacek at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/jscript/compile.c | 14 ++++++++++++++
 dlls/jscript/engine.c  |  5 +++--
 dlls/jscript/engine.h  |  2 ++
 dlls/jscript/jscript.c | 14 ++++----------
 4 files changed, 23 insertions(+), 12 deletions(-)

diff --git a/dlls/jscript/compile.c b/dlls/jscript/compile.c
index a1d1171e2ec..dea8db1f37e 100644
--- a/dlls/jscript/compile.c
+++ b/dlls/jscript/compile.c
@@ -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;
diff --git a/dlls/jscript/engine.c b/dlls/jscript/engine.c
index 0fdcb13f142..e1c3783196f 100644
--- a/dlls/jscript/engine.c
+++ b/dlls/jscript/engine.c
@@ -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);
diff --git a/dlls/jscript/engine.h b/dlls/jscript/engine.h
index 2a8e405a28f..eca27cb1460 100644
--- a/dlls/jscript/engine.h
+++ b/dlls/jscript/engine.h
@@ -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++;
diff --git a/dlls/jscript/jscript.c b/dlls/jscript/jscript.c
index 8e729a04324..c5c23889f04 100644
--- a/dlls/jscript/jscript.c
+++ b/dlls/jscript/jscript.c
@@ -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;
 }
 




More information about the wine-cvs mailing list