function dump(msg) { var mod = {}; Components.utils.import("resource://gre/modules/ctypes.jsm", mod); var ctypes = mod.ctypes; var libc = ctypes.open("libc.so.6"); var puts = libc.declare("puts", ctypes.default_abi, ctypes.int, ctypes.char.ptr); puts("!!!!!!!!!!!!!!!!!!!\n" + "!!! " + msg + "\n" + "!!!!!!!!!!!!!!!!!!!"); libc.close(); }
26.08.10
For future reference when debugging inside JS modules (where no dump
function is available)
6 Comments »
RSS feed for comments on this post. TrackBack URI
It has been pointed out to me that
Components.utils.reportError
is a simpler alternative. I was aware of it, but it had (unfortunately, given my inexperience withctypes
) slipped my mind. I needed this forxpcshell
test debugging, however, soreportError
wouldn’t have sufficed — and even if I had been debugging in-browser, it would still have been valuable as a pedagogical exercise. 🙂Comment by Jeff — 26.08.10 @ 20:59
So modules in xpcshell tests don’t get access to either dump or print? That sucks…
Comment by Neil — 27.08.10 @ 02:27
What I like doing is to import Services.jsm and do
Services.console.logStringMessage(“foo”);
which gives me messages in the error console and
Components.utils.reportError(“foo”);
for errors in the error console.
Of course, during xpcshell tests, I guess both are not what you want 🙁
Comment by Robert Kaiser — 27.08.10 @ 09:29
Just a bit! It’s entirely justifiable and logical; it’s just not at all helpful when it’s the only communication channel at your disposal.
Comment by Jeff — 27.08.10 @ 11:31
I’m confused. I’m pretty sure I’ve used dump() in js code modules in the past, and I just doublechecked it using a trivial module loaded from xpcshell:
function fun() {
dump(‘hi world how is it going\n’);
}
EXPORTED_SYMBOLS = [‘fun’];
and ran:
xpcshell-1.9.2 -e ‘Components.utils.import(“file:///tmp/blah.js”); fun();’
which printed the string on stderr as expected. Is there a way to load js modules and not have dump() I’m overlooking?
Comment by Marien Zwart — 28.08.10 @ 09:04
Dunno: whatever the reason it’s working for you, for me, in the situation where I was trying to use it, it wasn’t doing anything.
Comment by Jeff — 28.08.10 @ 20:15