单声道命令执行时的异常

时间:2013-04-02 02:44:31

标签: c# c++ linux exception mono

我有一个由VC开发的C ++应用程序,编译为DLL文件。 (该DLL是访问物理电池)。我还有C#测试控制台应用程序,称为DLL文件,以获取电池参数。

它们都在Windows上顺利运行,但是当我尝试通过单声道在Ubuntu上运行它时。 首次使用mono运行时总会出现异常,并且只在第一次显示时出现。 没有在第二,第三......时间显示。

命令如下:

root @ ubuntu:/ home / user1 / Desktop / CSharpTestConsoleAppFolder #monmon ConsoleApplication1.exe

如下例外:

    mono: pthread_mutex_lock.c:312: __pthread_mutex_lock_full: Assertion `(-   (e)) != 3 || !robust' failed.
    Stacktrace:

      at (wrapper managed-to-native) MonoLibUsb.MonoUsbApi.Close (intptr) <0xffffffff>
      at MonoLibUsb.MonoUsbDeviceHandle.ReleaseHandle () <0x00063>
      at System.Runtime.InteropServices.SafeHandle.Finalize () <0x0002f>
      at (wrapper runtime-invoke) object.runtime_invoke_virtual_void__this__ (object,intptr,intptr,intptr) <0xffffffff>

    Native stacktrace:

                    mono() [0x80e0124]
                    [0x66d410]
                    /lib/tls/i686/cmov/libc.so.6(abort+0x182) [0x169ab2]
                    /lib/tls/i686/cmov/libc.so.6(__assert_fail+0xf8) [0x15f748]
                    /lib/tls/i686/cmov/libpthread.so.0(+0x7e92) [0x8d3e92]
                    /usr/local/lib/libusb-1.0.so(libusb_close+0x40) [0xe531f0]
                    [0x6fff5c]
                    [0x5efc64]
                    [0x11ac78]
                    [0x11ac01]
                    mono() [0x812ac69]
                    mono() [0x82277c4]
                    mono() [0x812aec1]
                    mono() [0x81dcc96]
                    mono() [0x81ee9cf]
                    mono() [0x8224c23]
                    /lib/tls/i686/cmov/libpthread.so.0(+0x596e) [0x8d196e]
                    /lib/tls/i686/cmov/libc.so.6(clone+0x5e) [0x20f3fe]

    Debug info from gdb:

    i=1
    Production_Date=
    Serial_Number=
    S12_FW_Verion=
    S0_FW_Verion=
    P001_System_Type=3
    P002_Battery_Status=0
    P003_Relative_State_Of_Charge=0%
    P004_Run_Time_To_Empty=0
    P005_Average_Time_To_Full=0
    P006_Input_Current=0
    P007_Output_Current=0
    P008_Output_Voltage=0
    P009_DC_DC_Voltage=0
    P010_Battery_Voltage=0
    P011_Enclosure_Temperature=0
    P012_DC_DC_Temperature=0
    P013_Battery_Capacity=0
    P014_Pack_1_Plugged_In=1
    P015_Pack_2_Plugged_In=1
    P022_Pack_1_Temperature=0
    P023_Pack_2_Temperature=0
    P030_Pack_1_Device_Chemistry=3
    P031_Pack_2_Device_Chemistry=3
    P038_Pack_1_Design_Capacity=0
    P039_Pack_2_Design_Capacity=0
    P046_Pack_1_Design_Voltage=0
    P047_Pack_2_Design_Voltage=0
    P054_Pack_1_Serial_Number=0
    P055_Pack_2_Serial_Number=0
    P062_Pack_1_Remaining_Percentage=0
    P063_Pack_2_Remaining_Percentage=0
    P070_Pack_1_Remaining_Time=0
    P071_Pack_2_Remaining_Time=0
    P078_Pack_1_Remaining_Capacity=0
    P079_Pack_2_Remaining_Capacity=0
    P086_Pack_1_Full_Charge_Capacity=0
    P087_Pack_2_Full_Charge_Capacity=0
    P094_Pack_1_Current=0
    P095_Pack_2_Current=0
    P102_Pack_1_Voltage=0
    P103_Pack_2_Voltage=0
    P110_Pack_1_Cell_1_Voltage=0
    P111_Pack_1_Cell_2_Voltage=0
    P112_Pack_1_Cell_3_Voltage=0
    P113_Pack_1_Cell_4_Voltage=0
    P114_Pack_2_Cell_1_Voltage=0
    P115_Pack_2_Cell_2_Voltage=0
    P116_Pack_2_Cell_3_Voltage=0
    P117_Pack_2_Cell_4_Voltage=0
    P158_Pack_1_State=0
    P159_Pack_2_State=0
    P166_Charger_Temperature=0
    P167_Fan_Less=0

    Mono support loaded.
    [Thread debugging using libthread_db enabled]
    [New Thread 0xb6c46b70 (LWP 3123)]
    [New Thread 0xb6d4bb70 (LWP 3116)]
    [New Thread 0xb6d70b70 (LWP 3115)]
    [New Thread 0xb6fcfb70 (LWP 3113)]
    [New Thread 0xb72b9b70 (LWP 3107)]
    0x0066d422 in __kernel_vsyscall ()
      6 Thread 0xb72b9b70 (LWP 3107)  0x0066d422 in __kernel_vsyscall ()
      5 Thread 0xb6fcfb70 (LWP 3113)  0x0066d422 in __kernel_vsyscall ()
      4 Thread 0xb6d70b70 (LWP 3115)  0x0066d422 in __kernel_vsyscall ()
      3 Thread 0xb6d4bb70 (LWP 3116)  0x0066d422 in __kernel_vsyscall ()
      2 Thread 0xb6c46b70 (LWP 3123)  0x0066d422 in __kernel_vsyscall ()
    * 1 Thread 0xb7700b40 (LWP 3106)  0x0066d422 in __kernel_vsyscall ()

    Thread 6 (Thread 0xb72b9b70 (LWP 3107)):
    #0  0x0066d422 in __kernel_vsyscall ()
    #1  0x008d8f5b in read () from /lib/tls/i686/cmov/libpthread.so.0
    #2  0x080e02ec in read (signal=6, ctx=0xb72b8abc) at /usr/include/bits/unistd.h:45
    #3  mono_handle_native_sigsegv (signal=6, ctx=0xb72b8abc) at mini-exceptions.c:2207
    #4  <signal handler called>
    #5  0x0066d422 in __kernel_vsyscall ()
    #6  0x00166681 in raise () from /lib/tls/i686/cmov/libc.so.6
    #7  0x00169ab2 in abort () from /lib/tls/i686/cmov/libc.so.6
    #8  0x0015f748 in __assert_fail () from /lib/tls/i686/cmov/libc.so.6
    #9  0x008d3e92 in __pthread_mutex_lock_full () from /lib/tls/i686/cmov/libpthread.so.0
    #10 0x00e531f0 in libusb_close (dev_handle=0xa0d1508) at core.c:1129
    #11 0x006fff5c in ?? ()
    #12 0x005efc64 in ?? ()
    #13 0x0011ac78 in ?? ()
    #14 0x0011ac01 in ?? ()
    #15 0x0812ac69 in mono_gc_run_finalize (obj=0x922e8, data=0x0) at gc.c:224
    #16 0x082277c4 in GC_invoke_finalizers () at finalize.c:787
    #17 0x0812aec1 in finalizer_thread (unused=0x0) at gc.c:1093
    #18 0x081dcc96 in start_wrapper_internal (data=0x9f9bdc8) at threads.c:783
    #19 start_wrapper (data=0x9f9bdc8) at threads.c:831
    #20 0x081ee9cf in thread_start_routine (args=0x9f8ac64) at wthreads.c:287
    #21 0x08224c23 in GC_start_routine (arg=0x61fe0) at pthread_support.c:1468
    #22 0x008d196e in start_thread () from /lib/tls/i686/cmov/libpthread.so.0
    #23 0x0020f3fe in clone () from /lib/tls/i686/cmov/libc.so.6

    Thread 5 (Thread 0xb6fcfb70 (LWP 3113)):
    #0  0x0066d422 in __kernel_vsyscall ()
    #1  0x008d6015 in pthread_cond_wait@@GLIBC_2.3.2 () from /lib/tls/i686/cmov/libpthread.so.0
    #2  0x08202f31 in _wapi_handle_timedwait_signal_handle (handle=0x411, timeout=0x0, alertable=1, poll=0) at handles.c:1654
    #3  0x08202fa4 in _wapi_handle_wait_signal_handle (handle=0x411, alertable=1) at handles.c:1597
    #4  0x081f2ee7 in WaitForSingleObjectEx (handle=0x411, timeout=4294967295, alertable=1) at wait.c:203
    #5  0x081d9593 in ves_icall_System_Threading_WaitHandle_WaitOne_internal (this=0xce2e8, handle=0x411, ms=-1, exitContext=0) at threads.c:1664
    #6  0x006ab5f4 in ?? ()
    #7  0x006ab330 in ?? ()
    #8  0x0084a2f1 in ?? ()
    #9  0x00773d1c in ?? ()
    #10 0x006acff8 in ?? ()
    #11 0x006acf89 in ?? ()
    #12 0x08062cf8 in mono_jit_runtime_invoke (method="System.Threading.ThreadStart:Invoke ()", obj=0xcf000, params=0xb6fcf2b8, exc=0x0) at mini.c:5764
    #13 0x08187200 in mono_runtime_invoke (method="System.Threading.ThreadStart:Invoke ()", obj=0xcf000, params=0xb6fcf2b8, exc=0x0) at object.c:2755
    #14 0x08187464 in mono_runtime_delegate_invoke (delegate=0xcf000, params=0xb6fcf2b8, exc=0x0) at object.c:3420
    #15 0x081dcd67 in start_wrapper_internal (data=0xa101948) at threads.c:789
    #16 start_wrapper (data=0xa101948) at threads.c:831
    #17 0x081ee9cf in thread_start_routine (args=0x9f8b2c4) at wthreads.c:287
    #18 0x08224c23 in GC_start_routine (arg=0xb1fe0) at pthread_support.c:1468
    #19 0x008d196e in start_thread () from /lib/tls/i686/cmov/libpthread.so.0
    #20 0x0020f3fe in clone () from /lib/tls/i686/cmov/libc.so.6

    Thread 4 (Thread 0xb6d70b70 (LWP 3115)):
    #0  0x0066d422 in __kernel_vsyscall ()
    #1  0x008d9736 in nanosleep () from /lib/tls/i686/cmov/libpthread.so.0
    #2  0x081ed7b0 in SleepEx (ms=500, alertable=1) at wthreads.c:1027
    #3  0x081d116f in monitor_thread (unused=0x0) at threadpool.c:777
    #4  0x081dcc96 in start_wrapper_internal (data=0xa101948) at threads.c:783
    #5  start_wrapper (data=0xa101948) at threads.c:831
    #6  0x081ee9cf in thread_start_routine (args=0x9f8b3d4) at wthreads.c:287
    #7  0x08224c23 in GC_start_routine (arg=0xb1fc0) at pthread_support.c:1468
    #8  0x008d196e in start_thread () from /lib/tls/i686/cmov/libpthread.so.0
    #9  0x0020f3fe in clone () from /lib/tls/i686/cmov/libc.so.6

    Thread 3 (Thread 0xb6d4bb70 (LWP 3116)):
    #0  0x0066d422 in __kernel_vsyscall ()
    #1  0x00206fc9 in ioctl () from /lib/tls/i686/cmov/libc.so.6
    #2  0x00e58b6d in op_set_configuration (handle=0xa10d038, config=1) at os/linux_usbfs.c:1273
    #3  0x00e522c8 in libusb_set_configuration (dev=0xa10d038, configuration=1) at core.c:1270
    #4  0x0076b4fc in ?? ()
    #5  0x0076b440 in ?? ()
    #6  0x006a36f8 in ?? ()
    #7  0x00856894 in ?? ()
    #8  0x0084e0d8 in ?? ()
    #9  0x0084d980 in ?? ()
    #10 0x0084bb94 in ?? ()
    #11 0x0084b7dc in ?? ()
    #12 0x0069ecad in ?? ()
    #13 0x08062cf8 in mono_jit_runtime_invoke (method="System.Threading.WaitCallback:Invoke ()", obj=0xcf070, params=0xb6d4b260, exc=0xb6d4b268) at mini.c:5764
    #14 0x08187200 in mono_runtime_invoke (method="System.Threading.WaitCallback:Invoke ()", obj=0xcf070, params=0xb6d4b260, exc=0xb6d4b268) at object.c:2755
    #15 0x08187464 in mono_runtime_delegate_invoke (delegate=0xcf070, params=0xb6d4b260, exc=0xb6d4b268) at object.c:3420
    #16 0x081d365c in mono_async_invoke (data=0x55be0) at threadpool.c:626
    #17 async_invoke_thread (data=0x55be0) at threadpool.c:1431
    #18 0x081dcc96 in start_wrapper_internal (data=0xa101948) at threads.c:783
    #19 start_wrapper (data=0xa101948) at threads.c:831
    #20 0x081ee9cf in thread_start_routine (args=0x9f8b45c) at wthreads.c:287
    #21 0x08224c23 in GC_start_routine (arg=0xb1fc0) at pthread_support.c:1468
    #22 0x008d196e in start_thread () from /lib/tls/i686/cmov/libpthread.so.0
    #23 0x0020f3fe in clone () from /lib/tls/i686/cmov/libc.so.6

    Thread 2 (Thread 0xb6c46b70 (LWP 3123)):
    #0  0x0066d422 in __kernel_vsyscall ()
    #1  0x00201536 in poll () from /lib/tls/i686/cmov/libc.so.6
    #2  0x00e55688 in handle_events (ctx=<value optimized out>, tv=<value optimized out>) at io.c:1888
    #3  0x00e55f17 in libusb_handle_events_timeout_completed (ctx=0xa108768, tv=0x38f74, completed=0x0) at io.c:2024
    #4  0x00e5603c in libusb_handle_events_timeout (ctx=0xa108768, tv=0x38f74) at io.c:2078
    #5  0x006ad2bc in ?? ()
    #6  0x006ad0a8 in ?? ()
    #7  0x006ad01e in ?? ()
    #8  0x006acf89 in ?? ()
    #9  0x08062cf8 in mono_jit_runtime_invoke (method="System.Threading.ThreadStart:Invoke ()", obj=0xb6b24ea8, params=0xb6c462b8, exc=0x0) at mini.c:5764
    #10 0x08187200 in mono_runtime_invoke (method="System.Threading.ThreadStart:Invoke ()", obj=0xb6b24ea8, params=0xb6c462b8, exc=0x0) at object.c:2755
    #11 0x08187464 in mono_runtime_delegate_invoke (delegate=0xb6b24ea8, params=0xb6c462b8, exc=0x0) at object.c:3420
    #12 0x081dcd67 in start_wrapper_internal (data=0xa10a270) at threads.c:789
    #13 start_wrapper (data=0xa10a270) at threads.c:831
    #14 0x081ee9cf in thread_start_routine (args=0x9f8c22c) at wthreads.c:287
    #15 0x08224c23 in GC_start_routine (arg=0x61b60) at pthread_support.c:1468
    #16 0x008d196e in start_thread () from /lib/tls/i686/cmov/libpthread.so.0
    #17 0x0020f3fe in clone () from /lib/tls/i686/cmov/libc.so.6

    Thread 1 (Thread 0xb7700b40 (LWP 3106)):
    #0  0x0066d422 in __kernel_vsyscall ()
    #1  0x008d9736 in nanosleep () from /lib/tls/i686/cmov/libpthread.so.0
    #2  0x081ed7b0 in SleepEx (ms=6000, alertable=1) at wthreads.c:1027
    #3  0x081de240 in ves_icall_System_Threading_Thread_Sleep_internal (ms=6000) at threads.c:1319
    #4  0x0084a43c in ?? ()
    #5  0x0084a3b8 in ?? ()
    #6  0x0069fbd8 in ?? ()
    #7  0x0069fcf7 in ?? ()
    #8  0x08062cf8 in mono_jit_runtime_invoke (method="ConsoleApplication1.Program:Main ()", obj=0x0, params=0xbfb8f51c, exc=0x0) at mini.c:5764
    #9  0x08187200 in mono_runtime_invoke (method="ConsoleApplication1.Program:Main ()", obj=0x0, params=0xbfb8f51c, exc=0x0) at object.c:2755
    #10 0x0818aee6 in mono_runtime_exec_main (method="ConsoleApplication1.Program:Main ()", args=0x3be00, exc=0x0) at object.c:3938
    #11 0x080bb445 in main_thread_handler (argc=2, argv=0xbfb8f704) at driver.c:1003
    #12 mono_main (argc=2, argv=0xbfb8f704) at driver.c:1855
    #13 0x0805944a in mono_main_with_options (argc=2, argv=0xbfb8f704) at main.c:66
    #14 main (argc=2, argv=0xbfb8f704) at main.c:97

    =================================================================
    Got a SIGABRT while executing native code. This usually indicates
    a fatal error in the mono runtime or one of the native libraries 
    used by your application.
    =================================================================
BTW,另一个Linux人告诉我:似乎异常发生在线程1#4 0x0084a43c中? (),“??()”是一个函数名,他告诉我需要在编译时添加-g,所以??应该更改为函数名称,这样我才能找到原因。但问题是我使用Windows VC2012进行编译,我不知道如何在编译时添加参数-g。

附加信息:如果我先运行“gdb mono”,然后运行测试控制台应用程序,则没有异常。似乎在异常消息中或运行“gdb mono”之后有消息“Mono Support Loaded”。

2 个答案:

答案 0 :(得分:0)

虽然mono是跨平台的,但C ++却不是。您将不得不使用GCC或类似的编译器在Linux上重新编译您的DLL。此外,如何从单声道代码引用DLL也很重要。我建议使用PInvoke来避免路径等任何复杂情况。

答案 1 :(得分:0)

您可能意味着托管C ++,这就是您的应用程序实际工作的原因。可能只是你(或单声道运行时)试图释放一个未初始化的指针,可能会在以后初始化 - 或者在另一个线程上,因为你的堆栈跟踪表明有许多线程正在运行(其中一个线程似乎卡在了ioctl上) ())。