Open tpoindex opened 2 years ago
Can you provide a backtrace with gdb (or some other tool, idk what MacOS has) to help narrow down what's going on when it crashes?
Sorry I didn't provide a stacktrace before, I'm not really a Mac developer, but was able to generated one with lldb.
---Version info: $ xdotool -v xdotool version 3.20211022.1
$ brew info xdotool xdotool: stable 3.20211022.1 (bottled), HEAD Fake keyboard/mouse input and window management for X https://www.semicomplete.com/projects/xdotool/ /usr/local/Cellar/xdotool/3.20211022.1 (10 files, 267.4KB) * Poured from bottle on 2022-04-20 at 09:56:03 From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/xdotool.rb License: BSD-3-Clause
------Stack trace:
$ ulimit -c unlimited $ xdotool key Backspace (core dump file in /cores/* .....)
$ lldb -c core.15864 /usr/local/bin/xdotool (lldb) target create "/usr/local/bin/xdotool" --core "core.15864" Core file '/Users/thopoi/core.15864' (x86_64) was loaded. (lldb) thread backtrace all
strtok_r + 24 frame #1: 0x000000010cf5a047 libxdo.3.dylib
_xdo_send_keysequence_window_do + 140
frame #2: 0x000000010cf5a282 libxdo.3.dylibxdo_send_keysequence_window + 51 frame #3: 0x000000010ce2d7a7 xdotool
cmd_key + 795
frame #4: 0x000000010ce2ba98 xdotoolcontext_execute + 138 frame #5: 0x000000010ce2b4a3 xdotool
xdotool_main + 391
frame #6: 0x00000001120b851e dyld`start + 462
(lldb) Here's another invocation, this time running in lldb, the error message EXC_BAD_ACCESS makes me wonder if there is a problem with the brew build, or perhaps it's a bogus message ??
$ lldb xdotool key Backspace (lldb) target create "xdotool" Current executable set to 'xdotool' (x86_64). (lldb) settings set -- target.run-args "key" "Backspace" (lldb) r Process 5121 launched: '/usr/local/bin/xdotool' (x86_64) Process 5121 stopped
strtok_r + 24 libsystem_c.dylib
strtok_r:
-> 0x7ff801df7dd1 <+24>: movb (%rax), %r8b
0x7ff801df7dd4 <+27>: movq %rsi, %rdi
0x7ff801df7dd7 <+30>: movb (%rdi), %cl
0x7ff801df7dd9 <+32>: testb %cl, %cl
Target 0: (xdotool) stopped.Btw, the brew formula is: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/xdotool.rb
Seems like this points to: https://github.com/jordansissel/xdotool/blob/735e301665e7f9b8fe850588e88a3a0973695eec/xdo.c#L1391
I found an man page for MacOS strtok_r: https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man3/strtok_r.3.html
I see in the man page example that the tokctx pointer is used to re-assign the starting string buffer pointer.
Hope this helps.
Hey, thanks for getting back with the backtrace. I'm really puzzled as to why strtok_r is failing here. I ran your examples through my xdotool latest git + valgrind on my Linux machine and I'm not seeing any invalid reads.
I grabbed the tarball from the Homebrew listing (also thanks for that btw) and ran that through valgrind, no issues.
The strtok_r's usage seems correct: It's using a cloned string, first member is set to NULL after the first pass.
Have you tried other commands to see if they give similarly strange crashes, or it is just key?
Just 'key', which is the only usage of strtok_r in xdotool.
Another data point, 'xdotool key xxxx' works fine on modern FreeBSD (12 & 13). I'm still guessing some weirdness with Apple's library implementation. The Apple strtok_r man page I listed above says "Based on the FreeBSD 3.0 implementation."
Good news is that I don't really rely on xdotool on MacOS. I discovered the problem while testing another open source program, https://github.com/ideasman42/nerd-dictation, which uses xdotool (both 'key' and 'type'). I modified that program to just output to stdout immediately, which normally 'defers' all stdout output until exit.
Feel free to close this issue if you want.
'key' (and 'keydown', 'keyup') causes a segfault on MacOS / XQuartz. This is being run inside of an xterm under XQuartz.
Other key presses cause the same issue, 'A', 'F1', 'ctrl+c' etc.
MacOS 12.3.1 (Monterey) XQuartz 2.8.1 (xorg-server 1.20.11) xdotool version 3.20211022.1 (installed via brew)
However, the 'type' command seems to work just fine