Weird segfault on is_import_error
Reproducing this requires having a glib build with introspection and a libgirepository build against the new glib it seems, but there's something extra as the environment seems delicate. An almost identical build I had crashes in different ways sooo no real clue how to repoduce.
bash-5.2# cat foo.js
import GObject from 'gi://GObject';
bash-5.2# gdb --args gjs -m foo.js
Reading symbols from gjs...
Reading symbols from /usr/lib/debug//usr/bin/gjs-console.debug...
(gdb) r
Starting program: /usr/bin/gjs -m foo.js
warning: Error disabling address space randomization: Function not implemented
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/usr/lib/x86_64-linux-gnu/libthread_db.so.1".
[New Thread 0x7faace4c26c0 (LWP 299)]
[Thread 0x7faace4c26c0 (LWP 299) exited]
(gjs:296): GLib-GIO-DEBUG: 18:23:03.193: _g_io_module_get_default: Found default implementation local (GLocalVfs) for ?gio-vfs?
[New Thread 0x7faacdcba6c0 (LWP 300)]
[New Thread 0x7faacdabb6c0 (LWP 301)]
[New Thread 0x7faacd8bc6c0 (LWP 302)]
[New Thread 0x7faacd6bd6c0 (LWP 303)]
[New Thread 0x7faacd4be6c0 (LWP 304)]
[New Thread 0x7faacd2bf6c0 (LWP 305)]
[New Thread 0x7faacd0c06c0 (LWP 306)]
[New Thread 0x7faaccec16c0 (LWP 307)]
(gjs:296): GLib-GIO-DEBUG: 18:23:03.203: Failed to initialize portal (GMemoryMonitorPortal) for gio-memory-monitor: Not using portals
[New Thread 0x7faace4c26c0 (LWP 308)]
[New Thread 0x7faaccaa66c0 (LWP 309)]
[New Thread 0x7faac7fff6c0 (LWP 310)]
(gjs:296): GLib-GIO-DEBUG: 18:23:03.203: _g_io_module_get_default: Found default implementation dbus (GMemoryMonitorDBus) for ?gio-memory-monitor?
Thread 1 "gjs" received signal SIGSEGV, Segmentation fault.
JS_StringEqualsAscii (cx=cx@entry=0x56069cfedd90, str=0x2800000000000, asciiBytes=asciiBytes@entry=0x7faad2aa71c5 "ImportError", length=length@entry=11, match=match@entry=0x7ffdce456e47)
at /usr/lib/debug/source/sdk/mozjs.bst/js/src/jsapi.cpp:3222
3222 JSLinearString* linearStr = str->ensureLinear(cx);
(gdb)
(gdb) bt
#0 JS_StringEqualsAscii(JSContext*, JSString*, char const*, unsigned long, bool*)
(cx=cx@entry=0x56069cfedd90, str=0x2800000000000, asciiBytes=asciiBytes@entry=0x7faad2aa71c5 "ImportError", length=length@entry=11, match=match@entry=0x7ffdce456e47) at /usr/lib/debug/source/sdk/mozjs.bst/js/src/jsapi.cpp:3222
#1 0x00007faad2a4271c in JS_StringEqualsLiteral<12ul>(JSContext*, JSString*, char const (&) [12ul], bool*) (match=0x7ffdce456e47, asciiBytes=..., str=<optimized out>, cx=0x56069cfedd90) at /usr/include/mozjs-115/js/String.h:130
#2 is_import_error (thrown_value=..., cx=0x56069cfedd90) at ../gi/repo.cpp:503
#3 lookup_override_function (function=..., ns_name=..., cx=0x56069cfedd90) at ../gi/repo.cpp:538
#4 resolve_namespace_object(JSContext*, JS::HandleObject, JS::HandleId) (context=context@entry=0x56069cfedd90, repo_obj=..., repo_obj@entry=..., ns_id=ns_id@entry=...) at ../gi/repo.cpp:125
#5 0x00007faad2a428ab in repo_resolve(JSContext*, JS::HandleObject, JS::HandleId, bool*) (context=0x56069cfedd90, obj=..., id=..., resolved=0x7ffdce4570ff) at ../gi/repo.cpp:176
#6 0x00007faad1585a0f in js::CallResolveOp (propp=<synthetic pointer>, id=..., obj=..., cx=0x56069cfedd90) at /usr/lib/debug/source/sdk/mozjs.bst/build-dir/dist/include/js/RootingAPI.h:664
#7 js::NativeLookupOwnPropertyInline<(js::AllowGC)1> (propp=<synthetic pointer>, id=..., obj=..., cx=<optimized out>) at /usr/lib/debug/source/sdk/mozjs.bst/js/src/vm/NativeObject-inl.h:778
#8 NativeGetPropertyInline<(js::AllowGC)1> (vp=..., nameLookup=NotNameLookup, id=..., receiver=..., obj=..., cx=0x56069cfedd90) at /usr/lib/debug/source/sdk/mozjs.bst/js/src/vm/NativeObject.cpp:2239
#9 js::NativeGetProperty(JSContext*, JS::Handle<js::NativeObject*>, JS::Handle<JS::Value>, JS::Handle<JS::PropertyKey>, JS::MutableHandle<JS::Value>) (cx=0x56069cfedd90, obj=..., receiver=..., id=..., vp=...)
at /usr/lib/debug/source/sdk/mozjs.bst/js/src/vm/NativeObject.cpp:2287
#10 0x00007faad142b54e in js::GetProperty(JSContext*, JS::Handle<JSObject*>, JS::Handle<JS::Value>, JS::Handle<JS::PropertyKey>, JS::MutableHandle<JS::Value>) (vp=..., id=..., receiver=..., obj=..., cx=<optimized out>)
at /usr/lib/debug/source/sdk/mozjs.bst/build-dir/dist/include/js/RootingAPI.h:672
#11 js::GetObjectElementOperation (res=..., key=..., receiver=..., obj=..., op=<optimized out>, cx=<optimized out>) at /usr/lib/debug/source/sdk/mozjs.bst/js/src/vm/Interpreter-inl.h:417
#12 js::GetElementOperationWithStackIndex (res=..., rref=..., lrefIndex=<optimized out>, lref=..., cx=<optimized out>) at /usr/lib/debug/source/sdk/mozjs.bst/js/src/vm/Interpreter-inl.h:514
#13 js::Interpret(JSContext*, js::RunState&) (cx=0x56069cfedd90, state=...) at /usr/lib/debug/source/sdk/mozjs.bst/js/src/vm/Interpreter.cpp:3185
#14 0x00007faad142c373 in MaybeEnterInterpreterTrampoline (state=..., cx=0x56069cfedd90) at /usr/lib/debug/source/sdk/mozjs.bst/js/src/vm/Interpreter.cpp:400
#15 js::RunScript(JSContext*, js::RunState&) (cx=cx@entry=0x56069cfedd90, state=...) at /usr/lib/debug/source/sdk/mozjs.bst/js/src/vm/Interpreter.cpp:458
#16 0x00007faad142e829 in js::ExecuteKernel(JSContext*, JS::Handle<JSScript*>, JS::Handle<JSObject*>, js::AbstractFramePtr, JS::MutableHandle<JS::Value>) (result=..., evalInFrame=..., envChainArg=..., script=..., cx=0x56069cfedd90)
at /usr/lib/debug/source/sdk/mozjs.bst/js/src/vm/Interpreter.cpp:845
#17 js::Execute(JSContext*, JS::Handle<JSScript*>, JS::Handle<JSObject*>, JS::MutableHandle<JS::Value>) (cx=cx@entry=0x56069cfedd90, script=script@entry=..., envChain=envChain@entry=..., rval=rval@entry=...)
at /usr/lib/debug/source/sdk/mozjs.bst/js/src/vm/Interpreter.cpp:877
#18 0x00007faad148e8f1 in js::ModuleObject::execute(JSContext*, JS::Handle<js::ModuleObject*>) (cx=cx@entry=0x56069cfedd90, self=self@entry=...) at /usr/lib/debug/source/sdk/mozjs.bst/js/src/builtin/ModuleObject.cpp:1284
#19 0x00007faad1571f8b in InnerModuleEvaluation(JSContext*, JS::Handle<js::ModuleObject*>, JS::MutableHandle<JS::GCVector<js::ModuleObject*, 0, js::SystemAllocPolicy> >, size_t, size_t*)
(cx=cx@entry=0x56069cfedd90, module=module@entry=..., stack=stack@entry=..., index=<optimized out>, indexOut=indexOut@entry=0x7ffdce457848) at /usr/lib/debug/source/sdk/mozjs.bst/js/src/vm/Modules.cpp:1498
#20 0x00007faad1571dad in InnerModuleEvaluation(JSContext*, JS::Handle<js::ModuleObject*>, JS::MutableHandle<JS::GCVector<js::ModuleObject*, 0, js::SystemAllocPolicy> >, size_t, size_t*)
(cx=cx@entry=0x56069cfedd90, module=module@entry=..., stack=stack@entry=..., index=<optimized out>, index@entry=0, indexOut=indexOut@entry=0x7ffdce4578f8)
at /usr/lib/debug/source/sdk/mozjs.bst/build-dir/dist/include/js/RootingAPI.h:1219
#21 0x00007faad1572343 in js::ModuleEvaluate(JSContext*, JS::Handle<js::ModuleObject*>, JS::MutableHandle<JS::Value>) (cx=0x56069cfedd90, moduleArg=..., result=...)
at /usr/lib/debug/source/sdk/mozjs.bst/build-dir/dist/include/js/RootingAPI.h:1219
#22 0x00007faad1572644 in JS::ModuleEvaluate(JSContext*, JS::Handle<JSObject*>, JS::MutableHandle<JS::Value>) (cx=<optimized out>, moduleRecord=..., moduleRecord@entry=..., rval=..., rval@entry=...)
at /usr/lib/debug/source/sdk/mozjs.bst/js/src/vm/Modules.cpp:163
#23 0x00007faad2a56d00 in GjsContextPrivate::eval_module(char const*, unsigned char*, _GError**) (this=0x56069cfdfd00, identifier=0x56069d130190 "file:///foo.js", exit_status_p=0x7ffdce457b8b "", error=0x7ffdce457b90)
at /usr/include/mozjs-115/js/RootingAPI.h:1219
#24 0x00007faad2a5721b in gjs_context_eval_module(GjsContext*, char const*, uint8_t*, GError**) (js_context=0x56069cfdfe80 [GjsContext], identifier=0x56069d130190 "file:///foo.js", exit_code=0x7ffdce457b8b "", error=0x7ffdce457b90)
at ../gjs/context.cpp:1329
#25 0x000056069c35bb33 in define_argv_and_eval_script(_GjsContext*, int, char* const*, char const*, unsigned long, char const*)
(js_context=js_context@entry=0x56069cfdfe80 [GjsContext], argc=argc@entry=0, argv=argv@entry=0x7ffdce457eb0, script=<optimized out>, len=<optimized out>, filename=filename@entry=0x56069cfcfb10 "foo.js") at ../gjs/jsapi-util.h:163
#26 0x000056069c35b26d in main(int, char**) (argc=<optimized out>, argv=<optimized out>) at ../gjs/jsapi-util.h:157
(gdb)
Rerunning and printing some things it looks like we are not getting a string:
Thread 1 "gjs" hit Breakpoint 1, is_import_error (thrown_value=..., cx=0x5648ca9c4d90) at /usr/include/mozjs-115/js/Value.h:817
817 return asBits_ >= JSVAL_SHIFTED_TAG_OBJECT;
(gdb) p exc_name.isString()
Cannot evaluate function -- may be inlined
(gdb) call gjs_debug_value(exc_name)
$1 = "6.95305e-310"
(gdb) call gjs_debug_value(exc)
$2 = "1.2732e-313"
(gdb) c
Continuing.
Thread 1 "gjs" hit Breakpoint 1, is_import_error (thrown_value=..., cx=0x5648ca9c4d90) at /usr/include/mozjs-115/js/Value.h:817
817 return asBits_ >= JSVAL_SHIFTED_TAG_OBJECT;
(gdb) call gjs_debug_value(exc_name)
[Thread 0x7f8576fe56c0 (LWP 323) exited]
$3 = "4.12683e-311"
(gdb) call gjs_debug_value(exc)
$4 = "6.95305e-310"
(gdb) c
Continuing.
Thread 1 "gjs" received signal SIGSEGV, Segmentation fault.
JS_StringEqualsAscii (cx=cx@entry=0x5648ca9c4d90, str=0x2800000000000, asciiBytes=asciiBytes@entry=0x7f85817fc1c5 "ImportError", length=length@entry=11, match=match@entry=0x7ffe8a15e3f7)
at /usr/lib/debug/source/sdk/mozjs.bst/js/src/jsapi.cpp:3222
3222 JSLinearString* linearStr = str->ensureLinear(cx);
(gdb)
@ptomato suggested that we should either check for a string or assert.
However it's also still unclear what are we getting passed on in the first place