z3ntu / razer_test

An experimental replacement for OpenRazer
69 stars 10 forks source link

Error calling IOCreatePlugInInterfaceForService #12

Closed joakim closed 4 years ago

joakim commented 5 years ago

First of all, thank you for creating this! And for supporting Mac 🎉

I successfully built the project and added device data for DeathAdder Elite. When I run razer_test_bringup_util it fails with a macOS specific error.

❯ ./razer_test_bringup_util --devel
[info] razer_test (bringup util) - version 0.0.1
[info] Running in development mode and using development data files.
[critical] Error calling IOCreatePlugInInterfaceForService. kr: -536870210
[info] Initializing device: Razer DeathAdder Elite (1532:005c)
[debug] Called virtual bool RazerMatrixLED::getBrightness(uchar *)
00000000  OK
[debug] Called virtual bool RazerMatrixLED::setSpectrum()
00000000  OK
[debug] Called virtual bool RazerMatrixLED::getBrightness(uchar *)
00000000  OK
[debug] Called virtual bool RazerMatrixLED::setSpectrum()
00000000  OK
[debug] Called virtual QString RazerDevice::getSerial()
00000000  OK
[debug] Called virtual QString RazerDevice::getSerial()
[critical] Failed to register D-Bus object at "/io/github/openrazer1/devices/PM1915H04507553".
[debug] Ignored interface with number: 2
[debug] Ignored interface with number: 1
Segmentation fault: 11

The first time it was run (without verbose) I got Bus error: 10 instead of segfault.

Device added to data/devices/mouse.json (may be something wrong here):

{
    "name": "Razer DeathAdder Elite",
    "vid": "1532",
    "pid": "005c",
    "type": "mouse",
    "pclass": "matrix",
    "leds": [1, 4],
    "fx": ["off", "breathing", "breathing_dual", "breathing_random", "reactive", "spectrum", "static", "brightness"],
    "features": ["dpi", "poll_rate"],
    "quirks": ["mouse_matrix", "matrix_brightness"],
    "max_dpi": 16000
},

Any advice?

OS: Mojave 10.14.6 (18G103), haven't upgraded to Catalina yet

z3ntu commented 5 years ago

Hi and thanks for trying the project :)

So for the "[critical] Error calling IOCreatePlugInInterfaceForService. kr: -536870210" error I've found:

-536870210 is 0xE00002BE which is (from /System/Library/Frameworks/Kernel.framework/Versions/A/Headers/IOKit/IOReturn.h)

define kIOReturnNoResources iokit_common_err(0x2be) // resource shortage

But as far as I know this shouldn't be fatal and will just make hotplug not work.

Could you maybe launch the executable with lldb (or gdb but I don't think it's available on macOS), this should work:

$ lldb ./razer_test_bringup_util
(lldb) run --devel --verbose
# then it should run and crash
(lldb) bt

and send me the resulting output.

joakim commented 5 years ago

That was quick :)

Here you go.

(lldb) run --devel --verbose:

Process 75427 launched: '/[censored]/razer_test/builddir/razer_test_bringup_util' (x86_64)
[info] razer_test (bringup util) - version 0.0.1
[info] Running in development mode and using development data files.
[critical] Error calling IOCreatePlugInInterfaceForService. kr: -536870210
[debug] Ignored interface with number: 2
[info] Initializing device: Razer DeathAdder Elite (1532:005c)
[debug] Called virtual bool RazerMatrixLED::getBrightness(uchar *)
00000000  OK
[debug] Called virtual bool RazerMatrixLED::setSpectrum()
00000000  OK
[debug] Called virtual bool RazerMatrixLED::getBrightness(uchar *)
00000000  OK
[debug] Called virtual bool RazerMatrixLED::setSpectrum()
00000000  OK
[debug] Called virtual QString RazerDevice::getSerial()
00000000  OK
[debug] Called virtual QString RazerDevice::getSerial()
[critical] Failed to register D-Bus object at "/io/github/openrazer1/devices/PM1915H04507553".
[debug] Ignored interface with number: 1
Process 75427 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=2, address=0x10064f130)
    frame #0: 0x000000010064f167 QtCore`typeinfo name for QMimeData + 167
QtCore`typeinfo name for QMimeData:
->  0x10064f167 <+167>: addb   %al, (%rcx)
    0x10064f169 <+169>: addb   %al, (%rax)
    0x10064f16b <+171>: addb   %al, (%rcx)
    0x10064f16d <+173>: addb   %al, (%rax)
Target 0: (razer_test_bringup_util) stopped.

(lldb) bt:

error: src_manager_devicemanager.cpp.o DWARF DW_TAG_array_type DIE at 0x0001281a has a class/union/struct element type DIE 0x00012826 that is a forward declaration, not a complete definition.
Try compiling the source file with -fstandalone-debug or disable -gmodules
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=2, address=0x10064f130)
  * frame #0: 0x000000010064f167 QtCore`typeinfo name for QMimeData + 167
    frame #1: 0x0000000100b18650
    frame #2: 0x000000010006cd1a razer_test_bringup_util`DeviceManager::setDevices(this=0x000000010090bc90, rDevices=QVector<RazerDevice *> @ 0x00007ffeefbff2b0) at devicemanager.cpp:47:33
    frame #3: 0x000000010006cc05 razer_test_bringup_util`DeviceManager::DeviceManager(this=0x000000010090bc90, rDevices=QVector<RazerDevice *> @ 0x00007ffeefbff478) at devicemanager.cpp:25:5
    frame #4: 0x000000010006cdd5 razer_test_bringup_util`DeviceManager::DeviceManager(this=0x000000010090bc90, rDevices=<unavailable>) at devicemanager.cpp:24:1
    frame #5: 0x000000010001c668 razer_test_bringup_util`Daemon::initialize(this=0x00007ffeefbff560) at daemon.cpp:83:19
    frame #6: 0x000000010002b5af razer_test_bringup_util`main(argc=3, argv=0x00007ffeefbff730) at main.cpp:99:17
    frame #7: 0x00007fff5feb73d5 libdyld.dylib`start + 1
z3ntu commented 5 years ago

Weird... Please try applying this patch and running the lldb procedure again:

diff --git a/src/device/razerdevice.cpp b/src/device/razerdevice.cpp
index 3166836..4b533e5 100644
--- a/src/device/razerdevice.cpp
+++ b/src/device/razerdevice.cpp
@@ -156,9 +156,16 @@ bool RazerDevice::sendReport(razer_report request_report, razer_report *response
     return false;
 }

+#include <QDebug>
 QDBusObjectPath RazerDevice::getObjectPath()
 {
-    return QDBusObjectPath(QString("/io/github/openrazer1/devices/%1").arg(getSerial()));
+    QString serial = getSerial();
+    qDebug() << serial;
+    QString objPathStr = QString("/io/github/openrazer1/devices/%1").arg(serial);
+    qDebug() << objPathStr;
+    QDBusObjectPath objPath = QDBusObjectPath(objPathStr);
+    qDebug() << "constructed objectpath";
+    return objPath;
 }

 /* --------------------- DBUS METHODS --------------------- */

Also which version of Qt do you have installed?

joakim commented 5 years ago

The diff didn't make much of a difference (no pun intended).

Process 97577 launched: '/[censored]/razer_test/builddir/razer_test_bringup_util' (x86_64)
[info] razer_test (bringup util) - version 0.0.1
[info] Running in development mode and using development data files.
[critical] Error calling IOCreatePlugInInterfaceForService. kr: -536870210
[info] Initializing device: Razer DeathAdder Elite (1532:005c)
[debug] Called virtual bool RazerMatrixLED::getBrightness(uchar *)
00000000  OK
[debug] Called virtual bool RazerMatrixLED::setSpectrum()
00000000  OK
[debug] Called virtual bool RazerMatrixLED::getBrightness(uchar *)
00000000  OK
[debug] Called virtual bool RazerMatrixLED::setSpectrum()
00000000  OK
[debug] Called virtual QString RazerDevice::getSerial()
00000000  OK
[debug] Called virtual QString RazerDevice::getSerial()
[critical] Failed to register D-Bus object at "/io/github/openrazer1/devices/PM1915H04507553".
[debug] Ignored interface with number: 1
[debug] Ignored interface with number: 2
Process 97577 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=2, address=0x10064f130)
    frame #0: 0x000000010064f167 QtCore`typeinfo name for QMimeData + 167
QtCore`typeinfo name for QMimeData:
->  0x10064f167 <+167>: addb   %al, (%rcx)
    0x10064f169 <+169>: addb   %al, (%rax)
    0x10064f16b <+171>: addb   %al, (%rcx)
    0x10064f16d <+173>: addb   %al, (%rax)
Target 0: (razer_test_bringup_util) stopped.
error: src_manager_devicemanager.cpp.o DWARF DW_TAG_array_type DIE at 0x0001281a has a class/union/struct element type DIE 0x00012826 that is a forward declaration, not a complete definition.
Try compiling the source file with -fstandalone-debug or disable -gmodules
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=2, address=0x10064f130)
  * frame #0: 0x000000010064f167 QtCore`typeinfo name for QMimeData + 167
    frame #1: 0x0000000100a58bf0
    frame #2: 0x000000010006cd1a razer_test_bringup_util`DeviceManager::setDevices(this=0x0000000100a587c0, rDevices=QVector<RazerDevice *> @ 0x00007ffeefbff2c0) at devicemanager.cpp:47:33
    frame #3: 0x000000010006cc05 razer_test_bringup_util`DeviceManager::DeviceManager(this=0x0000000100a587c0, rDevices=QVector<RazerDevice *> @ 0x00007ffeefbff488) at devicemanager.cpp:25:5
    frame #4: 0x000000010006cdd5 razer_test_bringup_util`DeviceManager::DeviceManager(this=0x0000000100a587c0, rDevices=<unavailable>) at devicemanager.cpp:24:1
    frame #5: 0x000000010001c668 razer_test_bringup_util`Daemon::initialize(this=0x00007ffeefbff570) at daemon.cpp:83:19
    frame #6: 0x000000010002b5af razer_test_bringup_util`main(argc=3, argv=0x00007ffeefbff740) at main.cpp:99:17
    frame #7: 0x00007fff5feb73d5 libdyld.dylib`start + 1

From qtdiag:

Qt 5.13.1 (x86_64-little_endian-lp64 shared (dynamic) release build; by Clang 10.0.1 (clang-1001.0.46.4) (Apple)) on "cocoa"
OS: macOS Mojave (10.14) [darwin version 18.7.0]

Architecture: x86_64; features: SSE2 SSE3 SSSE3 SSE4.1 SSE4.2 AVX AVX2 RTM HLE
z3ntu commented 5 years ago
diff --git a/meson.build b/meson.build
index 2779926..396bd46 100644
--- a/meson.build
+++ b/meson.build
@@ -71,10 +71,10 @@ processed = qt5.preprocess(
 if host_machine.system() == 'linux'
   src += ['src/devnotifier/devicenotifierlinux.cpp']
   devnotifier_dep = dependency('libudev')
-elif host_machine.system() == 'darwin'
-  src += ['src/devnotifier/devicenotifiermac.cpp']
-  devnotifier_dep = dependency('appleframeworks',
-                               modules : ['CoreFoundation', 'IOKit'])
+#elif host_machine.system() == 'darwin'
+#  src += ['src/devnotifier/devicenotifiermac.cpp']
+#  devnotifier_dep = dependency('appleframeworks',
+#                               modules : ['CoreFoundation', 'IOKit'])
 else
   warning('No devicenotifier implementation for this OS. Hotplug support will be missing.')
   # Empty dependency
diff --git a/src/daemon.h b/src/daemon.h
index bb85f26..10fd76a 100644
--- a/src/daemon.h
+++ b/src/daemon.h
@@ -26,8 +26,8 @@
 #include <QObject>
 #if defined(Q_OS_LINUX)
 #include "devnotifier/devicenotifierlinux.h"
-#elif defined(Q_OS_DARWIN)
-#include "devnotifier/devicenotifiermac.h"
+//#elif defined(Q_OS_DARWIN)
+//#include "devnotifier/devicenotifiermac.h"
 #else
 #define NO_DEVNOTIFIER_IMPL
 #include "devnotifier/idevicenotifier.h"

Maybe this helps? It doesn't fix the underlying issue but it should stop the crashing hopefully.

joakim commented 5 years ago

Sorry, I didn't rebuild it correctly before testing last time! My bad.

Didn't stop it from crashing, but at least now we got debugging:

[info] razer_test (bringup util) - version 0.0.1
[info] Running in development mode and using development data files.
[debug] Ignored interface with number: 2
[info] Initializing device: Razer DeathAdder Elite (1532:005c)
[debug] Called virtual bool RazerMatrixLED::getBrightness(uchar *)
00000000  OK
[debug] Called virtual bool RazerMatrixLED::setSpectrum()
00000000  OK
[debug] Called virtual bool RazerMatrixLED::getBrightness(uchar *)
00000000  OK
[debug] Called virtual bool RazerMatrixLED::setSpectrum()
00000000  OK
[debug] Called virtual QString RazerDevice::getSerial()
00000000  OK
[debug] "PM1915H04507553"
[debug] "/io/github/openrazer1/devices/PM1915H04507553"
[debug] constructed objectpath
[debug] Called virtual QString RazerDevice::getSerial()
[debug] "PM1915H04507553"
[debug] "/io/github/openrazer1/devices/PM1915H04507553"
[debug] constructed objectpath
[critical] Failed to register D-Bus object at "/io/github/openrazer1/devices/PM1915H04507553".
[debug] Ignored interface with number: 1
Process 18236 stopped

The values look like excepted don't they?

Thanks for being patient. If this is going nowhere, I'm happy to leave it for now. But if I can help somehow, I have no problem running more tests either :)

GBrawl commented 4 years ago

@joakim I had exactly the same issue as you it seems that it couldn't get registered because it was already registered. I fixed it using the following diff:

diff --git a/src/daemon.cpp b/src/daemon.cpp
index 222c5d9..fd49dbf 100644
--- a/src/daemon.cpp
+++ b/src/daemon.cpp
@@ -325,6 +325,7 @@ bool Daemon::registerDeviceOnDBus(RazerDevice *device)
 {
     // D-Bus
     new RazerDeviceAdaptor(device);
+    connection.unregisterObject(device->getObjectPath().path());
     if (!connection.registerObject(device->getObjectPath().path(), device)) {
         qCritical("Failed to register D-Bus object at \"%s\".", qUtf8Printable(device->getObjectPath().path()));
         delete device;
@@ -332,6 +333,7 @@ bool Daemon::registerDeviceOnDBus(RazerDevice *device)
     }
     foreach (RazerLED *led, device->getLeds()) {
         new RazerLEDAdaptor(led);
+        connection.unregisterObject(led->getObjectPath().path());
         if (!connection.registerObject(led->getObjectPath().path(), led)) {
             qCritical("Failed to register D-Bus object at \"%s\".", qUtf8Printable(led->getObjectPath().path()));
             delete device;

This is probably not the best solution tho, but it works atleast

z3ntu commented 4 years ago

Closing this in favor of #13