planck

Planck ClojureScript REPL
johanatan 2016-06-27T02:31:01.000539Z

@mfikes: just pushed a fix to: https://github.com/johanatan/planck/commit/788abbebb55420ee46c90f9bf3b1974804702ace but unfortunately same problem results.

johanatan 2016-06-27T02:31:23.000540Z

[just that printf'ing the buffer now produces expected results]

johanatan 2016-06-27T03:20:17.000541Z

@mfikes: btw, which debugger are you using? I just tried using gdb but am getting some strange internal gdb error:

Temporary breakpoint 1, 0x0000000100039404 in main ()
(gdb) step
Single stepping until exit from function main,
which has no line number information.
[New Thread 0x12c7 of process 78632]
[New Thread 0x1403 of process 78632]
[New Thread 0x1503 of process 78632]
[New Thread 0x1603 of process 78632]
[New Thread 0x1703 of process 78632]
[New Thread 0x1803 of process 78632]
[New Thread 0x1903 of process 78632]
[New Thread 0x1a03 of process 78632]
[New Thread 0x1b1b of process 78632]
Planck 2.0
ClojureScript 1.9.89
    Docs: (doc function-name-here)
          (find-doc "part-of-name-here")
  Source: (source function-name-here)
    Exit: Control+D or :cljs/quit or exit or quit
 Results: Stored in vars *1, *2, *3, an exception in *e

cljs.user=> [New Thread 0x13eb of process 78632]
                                                [New Thread 0x1d03 of process 78632]
                                                                                    [New Thread 0x1e03 of process 78632]
                                                                                                                        [New Thread 0x1f03 of process 78632]
                      [New Thread 0x2003 of process 78632]
                                                          [New Thread 0x2103 of process 78632]
                                                                                              [New Thread 0x2203 of process 78632]
                                                                                                                                  [New Thread 0x2303 of process 78632]
                                infrun.c:5503: internal-error: int finish_step_over(struct execution_control_state *): Assertion `ecs->event_thread->control.trap_expected' failed.
A problem internal to GDB has been detected,
further debugging may prove unreliable.
Quit this debugging session? (y or n) 

johanatan 2016-06-27T03:21:18.000542Z

Quit this debugging session? (y or n) n

This is a bug, please report it.  For instructions, see:
<http://www.gnu.org/software/gdb/bugs/>.

infrun.c:5503: internal-error: int finish_step_over(struct execution_control_state *): Assertion `ecs->event_thread->control.trap_expected' failed.
A problem internal to GDB has been detected,
further debugging may prove unreliable.
Create a core file of GDB? (y or n) 

johanatan 2016-06-27T03:23:35.000543Z

also, i doubt that gdb would end up being super useful anyway without sources and symbols setup for javascriptcore (which i'm not sure how to do)

mfikes 2016-06-27T03:23:36.000544Z

@johanatan: I compiled with -g and then used lldb. I found that Linenoise appears to interfere, so after starting lldb planck, I do run -d to put Planck in dumb-terminal mode.

johanatan 2016-06-27T03:26:30.000545Z

ok, and how do you get javascriptcore sources and symbols setup so you can actually see what the problem is (instead of random binary offsets and ASM instructions :))

johanatan 2016-06-27T03:30:05.000549Z

this is the lldb output if you can make sense of it:

cljs.user=> (require '[planck.shell])
nil
cljs.user=> (planck.shell/sh-async "ls" :dir "/Users/jonathan/Documents" :env {"blah" "blaz"} (fn [_] 9))
{:exit nil, :out nil, :err nil}
cljs.user=> 
Process 79650 stopped
* thread #19: tid = 0x9a43f6, 0x00007fff8ee337e1 JavaScriptCore`WTF::String::isolatedCopy() const & + 17, stop reason = EXC_BAD_ACCESS (code=1, address=0x3100000011)
    frame #0: 0x00007fff8ee337e1 JavaScriptCore`WTF::String::isolatedCopy() const & + 17
JavaScriptCore`WTF::String::isolatedCopy:
->  0x7fff8ee337e1 <+17>: movl   0x10(%rax), %edx
    0x7fff8ee337e4 <+20>: movl   %edx, %ecx
    0x7fff8ee337e6 <+22>: andl   $0x8, %ecx
    0x7fff8ee337e9 <+25>: testb  $0x3, %dl
(lldb) 

mfikes 2016-06-27T03:32:54.000550Z

If you type u you should move up a stack frame and d for down

mfikes 2016-06-27T03:33:16.000551Z

I can’t recall, but perhaps bt shows a backtrace

johanatan 2016-06-27T05:20:19.000552Z

ya, that doesn't give me any more info than the original stack trace i posted though.

johanatan 2016-06-27T05:21:04.000553Z

i would really need to be able to see the line of source corresponding to: JavaScriptCoreWTF::String::isolatedCopy() const & + 17`

johanatan 2016-06-27T16:58:40.000555Z

@mfikes: is there no way to hook up sources and symbols? I think trying to decipher this via disassembly is going to prove impossible

mfikes 2016-06-27T17:08:31.000556Z

@johanatan: I don’t know. It might be the case that on Linux there are debug builds of JavaScripCore, and on OS X perhaps there is a way to run the C-based project by Xcode and attach symbols, etc. I haven’t gone down that path yet.

johanatan 2016-06-27T17:24:10.000557Z

@mfikes: ok, i'll see what i can do with the disassembly and if that goes nowhere, then I'll explore the XCode option

johanatan 2016-06-27T19:50:21.000558Z

@mfikes: I think actually the best thing to do here is to build webkit from sources in debug mode and then link our C-binary against the freshly built webkit bits. Then things will "just work" (i.e., lldb will know line numbers and full paths to source files from the embedded debug info in the webkit binaries).

johanatan 2016-06-27T23:28:33.000562Z

@mfikes: after a lot of yak shaving, i got it building with a debug webkit

johanatan 2016-06-27T23:28:41.000563Z

but on startup, I get:

Jonathans-MacBook-Pro:planck-c jonathan$ ./planck 
ASSERTION FAILED: s_mainRunLoop
/Users/jonathan/Documents/SourceCode/webkit/Source/WTF/wtf/RunLoop.cpp(66) : static WTF::RunLoop &WTF::RunLoop::main()
1   0x1109f3dbd WTFCrash
2   0x110a22dfb WTF::RunLoop::main()
3   0x11041166b Inspector::SendGarbageCollectionEventsTask::SendGarbageCollectionEventsTask(Inspector::HeapFrontendDispatcher&)
4   0x11041186d Inspector::SendGarbageCollectionEventsTask::SendGarbageCollectionEventsTask(Inspector::HeapFrontendDispatcher&)
5   0x110411cb4 Inspector::InspectorHeapAgent::InspectorHeapAgent(Inspector::AgentContext&)
6   0x110411d7d Inspector::InspectorHeapAgent::InspectorHeapAgent(Inspector::AgentContext&)
7   0x11054c9a5 Inspector::JSGlobalObjectInspectorController::JSGlobalObjectInspectorController(JSC::JSGlobalObject&)
8   0x11054eebd Inspector::JSGlobalObjectInspectorController::JSGlobalObjectInspectorController(JSC::JSGlobalObject&)
9   0x11050c215 JSC::JSGlobalObject::init(JSC::VM&)
10  0x1104f3fa0 JSC::JSGlobalObject::finishCreation(JSC::VM&)
11  0x1104f359c JSC::JSGlobalObject::create(JSC::VM&, JSC::Structure*)
12  0x1104f2696 JSGlobalContextCreateInGroup
13  0x1104f2571 JSGlobalContextCreate
14  0x10f90bf1b main
15  0x7fff95e555ad start
ASAN:DEADLYSIGNAL
=================================================================
==55205==ERROR: AddressSanitizer: SEGV on unknown address 0x0000bbadbeef (pc 0x0001109f3dc4 bp 0x7fff5032a100 sp 0x7fff5032a100 T0)
    #0 0x1109f3dc3 in WTFCrash (planck+0x101123dc3)
    #1 0x110a22dfa in WTF::RunLoop::main() (planck+0x101152dfa)
    #2 0x11041166a in Inspector::SendGarbageCollectionEventsTask::SendGarbageCollectionEventsTask(Inspector::HeapFrontendDispatcher&) (planck+0x100b4166a)
    #3 0x11041186c in Inspector::SendGarbageCollectionEventsTask::SendGarbageCollectionEventsTask(Inspector::HeapFrontendDispatcher&) (planck+0x100b4186c)
    #4 0x110411cb3 in Inspector::InspectorHeapAgent::InspectorHeapAgent(Inspector::AgentContext&) (planck+0x100b41cb3)
    #5 0x110411d7c in Inspector::InspectorHeapAgent::InspectorHeapAgent(Inspector::AgentContext&) (planck+0x100b41d7c)
    #6 0x11054c9a4 in Inspector::JSGlobalObjectInspectorController::JSGlobalObjectInspectorController(JSC::JSGlobalObject&) (planck+0x100c7c9a4)
    #7 0x11054eebc in Inspector::JSGlobalObjectInspectorController::JSGlobalObjectInspectorController(JSC::JSGlobalObject&) (planck+0x100c7eebc)
    #8 0x11050c214 in JSC::JSGlobalObject::init(JSC::VM&) (planck+0x100c3c214)
    #9 0x1104f3f9f in JSC::JSGlobalObject::finishCreation(JSC::VM&) (planck+0x100c23f9f)
    #10 0x1104f359b in JSC::JSGlobalObject::create(JSC::VM&, JSC::Structure*) (planck+0x100c2359b)
    #11 0x1104f2695 in JSGlobalContextCreateInGroup (planck+0x100c22695)
    #12 0x1104f2570 in JSGlobalContextCreate (planck+0x100c22570)
    #13 0x10f90bf1a in main main.c:268
    #14 0x7fff95e555ac in start (libdyld.dylib+0x35ac)
    #15 0x0  (<unknown module>)

AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV (planck+0x101123dc3) in WTFCrash
==55205==ABORTING
Abort trap: 6

mfikes 2016-06-27T23:28:59.000564Z

Cool. Symbols 🙂

johanatan 2016-06-27T23:29:29.000565Z

Ya, it was pretty tricky with lots of trial and error but I can describe the process that finally worked

johanatan 2016-06-27T23:32:06.000568Z

basically: a) build webkit in debug mode (i.e., clone the sources and issue make debug) b) merge the object files for bmalloc, JavaScriptCore & WTF into single .o files using libtool. c) modify makefile to link directly to aforementioned .o files and change LIBFLAGS to LIBFLAGS += -framework AppKit $(shell pkg-config --libs $(DEPS)) -licucore

johanatan 2016-06-27T23:33:30.000569Z

i'm guessing that the crash above is a missing dependency (but all of those previously either caused the make to build (at compile time) or a runtime linker error like the following:

Jonathans-MacBook-Pro:planck-c jonathan$ ./planck 
dyld: Symbol not found: _OBJC_CLASS_$_EventSendingController
  Referenced from: libwebkit.dylib
  Expected in: flat namespace
 in libwebkit.dylib
Trace/BPT trap: 5

mfikes 2016-06-27T23:35:26.000571Z

@johanatan: I think JavaScriptCore can be built with and without Objective-C support. Perhaps that’s what you are seeing.

johanatan 2016-06-27T23:35:34.000572Z

ahh, yep.

johanatan 2016-06-27T23:35:37.000573Z

i bet so

johanatan 2016-06-27T23:35:51.000574Z

I will look into flags to pass to webkit's make to disable obj-c