Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Debugging Tcl on macOS Sierra

64 views
Skip to first unread message

EL

unread,
Jul 27, 2017, 9:10:40 AM7/27/17
to
Hello,

On mac OSX Lion 10.7 I used to debug extensions by attaching the xcode gdb to a running tclsh, and then executed the scripts that lead to breakpoints which I set in the extension code. I do the same on Linux and Windows, and it always works.

Now I tried this with recent macOS sierra, but didn't get it working so far. XCode is at version 8 and has no gdb included anymore. The default debugger lldb crashes tclsh when I try to attach to the process, before I even can load my extension. This happens with tcl 8.6 from MacPorts and ActiveTcl alike.

I tried gdb from MacPorts, which comes as /opt/local/bin/ggdb and needs code signing before use. I code signed it with a self signed certificate. It can be attached to tclsh processes - but it doesn't hit breakpoints. I've read about the DWARF flags to gcc and compiled with -gdwarf-2 -g3, and get an accompanying .SYM file to my library - but breakpoints are still not hit. This happens with both, /usr/bin/gcc (the default xcode compiler) and /opt/local/bin/gcc-m... (the gcc 7.6x from MacPorts).

Is there any trick, or do I miss something? Has anyone got this working on macOS?

TIA

--
EL

Brad Lanam

unread,
Jul 27, 2017, 10:19:43 AM7/27/17
to
AFAIK gdb isn't going to work (I haven't checked very recently -- at the time I checked MacPorts did not have the necessary patches to gdb).

lldb should work, but will ignore the DYLD_FRAMEWORK_PATH environment variable.
You have to set this yourself within lldb. That should resolve the crash.

(all one line:)
settings set target.env-vars DYLD_FRAMEWORK_PATH="/Users/bll/tcl/build/tcl/Development:/Users/bll/tcl/build/tk/Development:${DYLD_FRAMEWORK_PATH}"'

EL

unread,
Jul 27, 2017, 2:22:06 PM7/27/17
to
Am 27.07.17 um 16:19 schrieb Brad Lanam:

> AFAIK gdb isn't going to work (I haven't checked very recently -- at the time I checked MacPorts did not have the necessary patches to gdb).

Ok good to know. (I hope they get it sorted out soon)

> lldb should work, but will ignore the DYLD_FRAMEWORK_PATH environment variable.
> You have to set this yourself within lldb. That should resolve the crash.
>
> (all one line:)
> settings set target.env-vars DYLD_FRAMEWORK_PATH="/Users/bll/tcl/build/tcl/Development:/Users/bll/tcl/build/tk/Development:${DYLD_FRAMEWORK_PATH}"'
>

Hm that didn't resolve it for me. I started lldb in the Terminal, then
typed exactly:

settings set target.env-vars
DYLD_FRAMEWORK_PATH="/Users/eckhard/Workspace/tcltk/build/tcl/Development:${DYLD_FRAMEWORK_PATH}"

and then

process attach --pid <tclsh-pid>

then one "continue" and tclsh crashes. It was started in the same
directory, "Development".
Or, maybe it is not even a crash. I get a message in lldb, saying

----
Process 21754 resuming
Process 21754 exited with status = 0 (0x00000000)
----

Maybe even a regular exit with code 0, but it should not happen...
I have the complete output of my (lldb) session here:

----
(lldb) settings set target.env-vars
DYLD_FRAMEWORK_PATH="/Users/eckhard/Workspace/tcltk/build/tcl/Development:${DYLD_FRAMEWORK_PATH}"
(lldb)
(lldb) process attach --pid 21827
Process 21827 stopped
* thread #1: tid = 0xe9b4, 0x00007fffc2dff246
libsystem_kernel.dylib`read + 10, queue = 'com.apple.main-thread', stop
reason = signal SIGSTOP
frame #0: 0x00007fffc2dff246 libsystem_kernel.dylib`read + 10
libsystem_kernel.dylib`read:
-> 0x7fffc2dff246 <+10>: jae 0x7fffc2dff250 ; <+20>
0x7fffc2dff248 <+12>: movq %rax, %rdi
0x7fffc2dff24b <+15>: jmp 0x7fffc2df6cd4 ; cerror
0x7fffc2dff250 <+20>: retq

Executable module set to
"/Users/eckhard/Workspace/tcltk/build/tcl/Development/./tclsh".
Architecture set to: x86_64h-apple-macosx.
(lldb) bt
* thread #1: tid = 0xe9b4, 0x00007fffc2dff246
libsystem_kernel.dylib`read + 10, queue = 'com.apple.main-thread', stop
reason = signal SIGSTOP
* frame #0: 0x00007fffc2dff246 libsystem_kernel.dylib`read + 10
frame #1: 0x000000010ccf26db Tcl`FileInputProc + 26
frame #2: 0x000000010cca912c Tcl`ChanRead + 102
frame #3: 0x000000010ccac6a1 Tcl`GetInput + 327
frame #4: 0x000000010cca8990 Tcl`FilterInputBytes + 124
frame #5: 0x000000010cca82a6 Tcl`Tcl_GetsObj + 881
frame #6: 0x000000010ccbd032 Tcl`Tcl_MainEx + 1102
frame #7: 0x000000010cbfaa0f tclsh`main(argc=1,
argv=0x00007fff530069f8) + 63 at tclAppInit.c:84
frame #8: 0x00007fffc2ccf235 libdyld.dylib`start + 1
frame #9: 0x00007fffc2ccf235 libdyld.dylib`start + 1
(lldb) c
Process 21827 resuming
Process 21827 exited with status = 0 (0x00000000)
(lldb)
----


--
EL

Brad Lanam

unread,
Jul 27, 2017, 4:36:10 PM7/27/17
to
On Thursday, July 27, 2017 at 11:22:06 AM UTC-7, EL wrote:
> Am 27.07.17 um 16:19 schrieb Brad Lanam:
> (lldb) settings set target.env-vars
> DYLD_FRAMEWORK_PATH="/Users/eckhard/Workspace/tcltk/build/tcl/Development:${DYLD_FRAMEWORK_PATH}"
> (lldb)
> (lldb) process attach --pid 21827

I have never tried attaching to an existing process. Don't know if that works.

EL

unread,
Jul 31, 2017, 7:26:41 AM7/31/17
to
Am Donnerstag, 27. Juli 2017 22:36:10 UTC+2 schrieb Brad Lanam:

> I have never tried attaching to an existing process. Don't know if that works.

It works on Linux and Windows, with gcc and msvc respectively. On OSX it used to work also, when gcc was still an option...

But ok, at least I can debug now with lldb, when tclsh is started in lldb directly. That will do it for now :).

Thanks

--
EL
0 new messages