1

ようやく libssh2 をコンパイルできましたが、EXC_BAD_ACCESSエラーが表示され続けます。

これは、libssh2 がどのように機能するか (少なくとも GUI) に関する基本的な背景です...

  1. コマンドを入力
  2. ホスト IP を入力してください
  3. ユーザー名/パスを入力してください
  4. ボタンを押して SSH コマンドを送信します

現在、次のような単純なコマンドはecho Hello World正常に機能しますが、プロジェクトとしてのこれの全体的なアイデアは、Mac をリモートで再起動できるようにすることでした。もともと、このコマンドを使用してshutdown -rもリモート マシンで何も起こらず、アプリがクラッシュしていました。open /path/to/restart.app次に、コマンドを使用して、Macを再起動するapplescriptアプリを簡単に開くことができるという考えを持っていました。これは正常に機能します。マシンが再起動します、ヤッピー!

例外として、アプリは次のエラーでクラッシュします。

Thread 1: EXC_BAD_ACCESS (code=1, address=_____)

私はobjective-cが初めてで、これを修正する方法がわかりません。Googleで調べたところ、次のことが原因であることがわかりました。

  1. メモリの問題
  2. すでに解放されているオブジェクトにメッセージが送信されています (これが何を意味するのかわかりません。何か助けはありますか?)

したがって、コマンドが SSH 経由で送信されると、コマンドは切断され、結果を表示するために疲れますが、オブジェクトは既になくなっていると思います。

これのソースコードを投稿しますが、それは多くの異なるファイルであるため、github リンクを投稿します。

https://github.com/x2on/libssh2-for-iOS

私はコードを変更していないので、誰かが私の問題を再現したい場合は、使用しているコードはそこからのものと同じです。

クラッシュログ:

Process:         libssh2-for-iOS [38153]
Path:            /Users/USER/Library/Application Support/iPhone Simulator/*/libssh2-for-iOS.app/libssh2-for-iOS
Identifier:      libssh2-for-iOS
Version:         ???
Code Type:       X86 (Native)
Parent Process:  ??? [1]
User ID:         501

Date/Time:       2012-04-18 18:32:03.883 -0400
OS Version:      Mac OS X 10.8 (12A154q)
Report Version:  10

Crashed Thread:  0

Exception Type:  EXC_BAD_ACCESS (SIGBUS)
Exception Codes: KERN_PROTECTION_FAILURE at 0x0000000000000000

External Modification Warnings:
Debugger attached to process.

VM Regions Near 0:
--> __PAGEZERO             0000000000000000-0000000000001000 [    4K] ---/--- SM=NUL  /Users/USER/Library/Application Support/iPhone Simulator/*/libssh2-for-iOS.app/libssh2-for-iOS
    __TEXT                 0000000000001000-0000000000002000 [    4K] r-x/rwx SM=COW  /Users/USER/Library/Application Support/iPhone Simulator/*/libssh2-for-iOS.app/libssh2-for-iOS

Application Specific Information:
iPhone Simulator 272, iPhone OS 5.0 (iPhone/9A334)


Thread 0 Crashed:
0   ???                             0000000000 0 + 0
1   libssh2-for-iOS                 0x00003f39 _libssh2_channel_open + 281
2   libssh2-for-iOS                 0x00004837 libssh2_channel_open_ex + 151
3   libssh2-for-iOS                 0x00003714 -[SSHWrapper executeCommand:] + 212
4   libssh2-for-iOS                 0x00002b22 -[libssh2_for_iOSAppDelegate executeCommand:] + 338
5   CoreFoundation                  0x01603ec9 -[NSObject performSelector:withObject:withObject:] + 73
6   UIKit                           0x0049e5c2 -[UIApplication sendAction:to:from:forEvent:] + 96
7   UIKit                           0x0049e55a -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 61
8   UIKit                           0x00543b76 -[UIControl sendAction:to:forEvent:] + 66
9   UIKit                           0x0054403f -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 503
10  UIKit                           0x00542e22 -[UIControl touchesBegan:withEvent:] + 264
11  UIKit                           0x004c393f -[UIWindow _sendTouchesForEvent:] + 272
12  UIKit                           0x004c3c56 -[UIWindow sendEvent:] + 273
13  UIKit                           0x004aa384 -[UIApplication sendEvent:] + 464
14  UIKit                           0x0049daa9 _UIApplicationHandleEvent + 8196
15  GraphicsServices                0x01cf8fa9 PurpleEventCallback + 1274
16  CoreFoundation                  0x015d61c5 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 53
17  CoreFoundation                  0x0153b022 __CFRunLoopDoSource1 + 146
18  CoreFoundation                  0x0153990a __CFRunLoopRun + 2218
19  CoreFoundation                  0x01538db4 CFRunLoopRunSpecific + 212
20  CoreFoundation                  0x01538ccb CFRunLoopRunInMode + 123
21  GraphicsServices                0x01cf7879 GSEventRunModal + 207
22  GraphicsServices                0x01cf793e GSEventRun + 114
23  UIKit                           0x0049ba9b UIApplicationMain + 1175
24  libssh2-for-iOS                 0x00003266 main + 134
25  libssh2-for-iOS                 0x00002955 start + 53

Thread 1:
0   libsystem_kernel.dylib          0x921059be kevent + 10
1   libdispatch.dylib               0x01c9e398 _dispatch_mgr_invoke + 918
2   libdispatch.dylib               0x01c9cc9d _dispatch_mgr_thread + 53

Thread 2:: WebThread
0   libsystem_kernel.dylib          0x921027e2 mach_msg_trap + 10
1   libsystem_kernel.dylib          0x92101cc0 mach_msg + 68
2   CoreFoundation                  0x015d613a __CFRunLoopServiceMachPort + 186
3   CoreFoundation                  0x01539605 __CFRunLoopRun + 1445
4   CoreFoundation                  0x01538db4 CFRunLoopRunSpecific + 212
5   CoreFoundation                  0x01538ccb CFRunLoopRunInMode + 123
6   WebCore                         0x03583220 RunWebThread(void*) + 560
7   libsystem_c.dylib               0x9445dd03 _pthread_start + 344
8   libsystem_c.dylib               0x944486ae thread_start + 34

Thread 0 crashed with X86 Thread State (32-bit):
  eax: 0x00000000  ebx: 0x00000007  ecx: 0x07439400  edx: 0x00000000
  edi: 0x00040000  esi: 0x00008000  ebp: 0xbfffbbc8  esp: 0xbfffbb2c
   ss: 0x00000023  efl: 0x00010286  eip: 0x00000000   cs: 0x0000001b
   ds: 0x00000023   es: 0x00000023   fs: 0x00000000   gs: 0x0000000f
  cr2: 0x00000000
Logical CPU: 1

(Binary images removed, too many characters)

External Modification Summary:
  Calls made by other processes targeting this process:
    task_for_pid: 1
    thread_create: 0
    thread_set_state: 32
  Calls made by this process:
    task_for_pid: 0
    thread_create: 0
    thread_set_state: 0
  Calls made by all processes on this machine:
    task_for_pid: 14309
    thread_create: 0
    thread_set_state: 550

VM Region Summary:
ReadOnly portion of Libraries: Total=155.0M resident=50.0M(32%) swapped_out_or_unallocated=105.0M(68%)
Writable regions: Total=36.7M written=2264K(6%) resident=9020K(24%) swapped_out=108K(0%) unallocated=27.9M(76%)

REGION TYPE                      VIRTUAL
===========                      =======
CG image                             16K
CoreAnimation                       532K
MALLOC                             21.8M
MALLOC guard page                    32K
Memory tag=35                      10.8M
SQLite page cache                   288K
Stack                              65.3M
VM_ALLOCATE                         136K
__DATA                             9660K
__LINKEDIT                         55.9M
__PAGEZERO                            4K
__TEXT                             99.1M
__UNICODE                           544K
mapped file                       237.8M
shared memory                        12K
===========                      =======
TOTAL                             501.6M
4

2 に答える 2

2

https://github.com/x2on/libssh2-for-iOSからサンプル コードをダウンロードし、libssl と libssh2 とアプリをコンパイルしました。そのアプリを実行すると、あなたと非常によく似たエラーが発生しました。

Thread 1: EXC_BAD_ACCESS (code=2, address=0x12c)

これは、何らかの理由で接続が確立されていないときに発生します。たとえば、IP アドレスを入力しない場合、または IP アドレス以外のものを入力すると、この例外が発生します。

問題は、libssh2 や libssl ではなく、x2on のアプリ内にあるようです。アプリをデバッグしたところ、接続を確立できない場合、呼び出される変数sessionが NULL であることがわかりました。したがって、パラメータが NULL ではないことが想定されているため、後の呼び出しlibssh2_channel_open_sessionはこの例外で失敗します。

次のスクリーンショットを参照してください。

例外のデバッグ

左下隅に、session変数の値が表示されます。NULL の場合、これが問題です。また、右下隅のコンソール出力ウィンドウで問題の原因を確認できます。私の場合は「接続に失敗しました!」です。

とにかく、x2on のコードは非常に悪いコードの例のようです。エラーを無視し、悪いコーディング スタイルと多くの不適切な手法 (グローバル変数、rootviewcontroller を設定しない) を使用し、その他の悪いことをしています。

于 2012-04-21T15:46:03.730 に答える
1

x2on コードには多くのエラーがあります。まず、executeCommand ルーチンを確認しましょう。

  • サーバーから返されたバッファのデータ長を完全に無視します。返されたテキストには末尾のゼロがないため、このルーチンを複数回呼び出すと、末尾のゴミが発生します。解決策: rc1 値を使用して長さを取得します (以下を参照)。

  • すべてのデータが受信されるまでループしますが、結果の文字列にそのデータが蓄積されないため、サーバーの完全な回答ではなく、受信した最新のテキストのみが取得されます。解決策: NSString の代わりに NSMutableString を使用し、それに結果を追加します。

    NSMutableString *result = [[NSMutableString alloc] initWithString: @""];
    ...
    if( rc1 > 0 ) {
        [result appendString: [[NSString alloc] initWithCString:buffer length: rc1]];
            bytecount += rc1;
        }
    
  • *結果が正しく処理されません。ルーチンを複数回呼び出すと、2 回目の呼び出しから例外が発生します。迅速な回避策:

    if (result) return result;
    else return @"Error - command failed";
    
于 2012-05-04T07:39:55.627 に答える