8

ネットワークに接続され、/homeマウントを共有する2台の同一の64ビットCentos5マシンがあります。単純なHelloWorldプログラムを一方にコンパイルしてから、一方のマシンでgdbを使用して、もう一方のマシンで実行されているプログラムをリモートでデバッグする方法を理解しました。全員がデフォルトで64ビットネスに設定されている場合、これは正常に機能するようです。

ただし、Hello Worldを-m32でコンパイルして32ビットのバイナリを生成すると、システム全体がコンパイルされる方法で、gdbとgdbserverを正しく接続する方法がわかりません。フルアップシステムで試す前に、helloで動作させる必要があると思います。gdbとgdbserverを接続しようとする方法に応じて、不適切な形式のレジスタに関するメッセージ、アーキテクチャの不一致に関する警告、または不正なメモリ参照のいずれかが表示されます。

-m32がコンパイルにどのような影響を与えるかについてはほとんど理解しておらず、gdbとgdbserverを起動する方法や、アーキテクチャやファイルなどを指定する正しい順序についても理解していないようです。:(

64ビットLinuxボックスの32ビット(-m32)実行可能ファイルでgdbとgdbserverを使用するには何が必要ですか?

以下の例、そしてありがとう、

ジェリー

hello.cpp:

#include <iostream>
int main(int argc, char *argv[])
{
    std::cout << "Hello World." << std::endl;
    return -1;

}

これが3つの実行です:

  1. gdbで、アーキテクチャi386を設定し、gdbserverに接続します=>不正なアーキテクチャ
  2. gdbで、アーキテクチャi386 / file hello /を設定し、gdbserverに接続します=>不正なアーキテクチャ
  3. gdbで、アーキテクチャを(誤って)設定しますi386:x86-64 / filehello/次にgdbserverに接続します=>メモリにアクセスできません

またはもう少し詳しく:

==============================

実行ごとに、リモートgdbserverは次のように述べています。


    $ gdbserver --multi rdev6:2010 hello
    Process hello created; pid = 32603
    Listening on port 2010
    Remote debugging from host 134.51.26.149
    readchar: Got EOF
    Remote side has terminated connection.  GDBserver will reopen the connection.
    Listening on port 2010

そして私たちの地元で:

==============================

  • i386 32ビットであると仮定し、archiをi386に設定してから、接続します。注:gdb側では、実行可能ファイルが指定またはロードされていません。

    $ gdb
    GNU gdb Fedora (6.8-37.el5)
    his GDB was configured as "x86_64-redhat-linux-gnu".
    (gdb) set archi i386
    The target architecture is assumed to be i386
    (gdb) target extended-remote rdev6:2010
    Remote debugging using rdev6:2010
    warning: Selected architecture i386 is not compatible with reported target architecture i386:x86-64
    Remote register badly formatted: T0506:0000000000000000;07:b0dcdfff00000000;10:1018620000000000;thread:7f5b;
    here: 0000000;07:b0dcdfff00000000;10:1018620000000000;thread:7f5b;
    Try to load the executable by `file' first,
    you may also check `set/show architecture'.
    (gdb)

==============================

  • i386 32ビットであると仮定し、archiをi386に設定してから、接続します。注:gdb側では、実行可能ファイルにファイルがロードされています。

    $ gdb
    GNU gdb Fedora (6.8-37.el5)
    his GDB was configured as "x86_64-redhat-linux-gnu".
    (gdb) set archi i386
    The target architecture is assumed to be i386
    (gdb) file hello
    Reading symbols from /home/j/hello...done.
    (gdb) target extended-remote rdev6:2010
    Remote debugging using rdev6:2010
    warning: Selected architecture i386 is not compatible with reported target architecture i386:x86-64
    Remote register badly formatted: T0506:0000000000000000;07:b0dcdfff00000000;10:1018620000000000;thread:7f5b;
    here: 0000000;07:b0dcdfff00000000;10:1018620000000000;thread:7f5b;
    Try to load the executable by `file' first,
    you may also check `set/show architecture'.
    (gdb) sho archi
    The target architecture is assumed to be i386
    (gdb)

==============================

  • それがi386:x86-64であると仮定し、archiをi386:x86-64に設定してから、接続します。注:gdb側では、実行可能ファイルにファイルがロードされています。

    $ gdb
    GNU gdb Fedora (6.8-37.el5)
    This GDB was configured as "x86_64-redhat-linux-gnu".
    (gdb) set archi i386:x86-64
    The target architecture is assumed to be i386:x86-64
    (gdb) file hello
    Reading symbols from /home/j/hello...done.
    (gdb) show archi
    The target architecture is assumed to be i386:x86-64
    (gdb) target extended-remote rdev6:2010
    Remote debugging using rdev6:2010
    [New Thread 32667]
    Cannot access memory at address 0x800000008
    (gdb)
4

1 に答える 1

5

64ビットのgdb/gdbserverを使用して32ビットのプロセスをデバッグする場合は、新しいバージョンのGDBが必要です。特に、これが必要です。

gdbserver/ChangeLog:

2009-05-12  Doug Evans  <dje@google.com>

        Biarch support for i386/amd64 gdbserver.

または、次のコマンドを実行して、ソースから32ビットモードで既に持っているgdb/gdbserverをビルドすることもできます。

./configure CC='gcc -m32'

gdb32/gdbserver32を使用してプロセスをデバッグします。ただし、これを行うことの利点はわかりません。新しいバージョンのGDBには多くの修正、高速化があり、STLのきれいなプリンターは素晴らしいです。

于 2010-06-19T04:11:25.073 に答える