21

GDB では、コマンド:

list function

関数のすべてのソースを一覧表示します。

関数名を手動で入力する必要なく、現在使用している関数のすべてのソースを一覧表示するコマンドはありますか?

4

4 に答える 4

14
(gdb) help list
List specified function or line.
With no argument, lists ten more lines after or around previous listing.
"list -" lists the ten lines before a previous ten-line listing.
One argument specifies a line, and ten lines are listed around that line.
Two arguments with comma between specify starting and ending lines to list.
Lines can be specified in these ways:
  LINENUM, to list around that line in current file,
  FILE:LINENUM, to list around that line in that file,
  FUNCTION, to list around beginning of that function,
  FILE:FUNCTION, to distinguish among like-named static functions.
  *ADDRESS, to list around the line containing that address.
With two args if one is empty it stands for ten lines away from the other arg.

*ADDRESS面白いのはそこです。

x86/x64 では、現在のポインターはripレジスターにあるため、次のようになります。

(gdb) list *$pc
0x7ffff7b018a0 is at ../sysdeps/unix/syscall-template.S:82.
77  in ../sysdeps/unix/syscall-template.S

cat手元にデバッグ情報が何もないため、例はコマンドからのものです。

于 2012-10-10T20:47:53.027 に答える
5

バックトレース用の関数型btで停止した場合。Backtrace は現在のスタックを一覧表示します。一番上の要素 #0 は通常、関心のある関数であり、ソース ファイルと行番号も表示されます。

例えば:

(gdb) bt
#0  myClass::EntityTypeStruct::readAttributes (this=0x7fffd00066e0, buf=0x7fffd0006020 "", len=48)
    at /team/project/src/EntityTypeStruct.cc:55
#1  0x000000000044ca86 in workerThread (ts=0x7fffea71dcc0)
    at /team/project/src/threads/workerThread.cc:219
#2  0x00007ffff775e9d1 in start_thread () from /lib64/libpthread.so.0
#3  0x00007ffff6c07b5d in clone () from /lib64/libc.so.6

詳細については、 http://www.chemie.fu-berlin.de/chemnet/use/info/gdb/gdb_7.html#SEC42を参照してください。

また、ブレークポイントを設定すると、そのブレークポイントに到達するたびに実行されるコマンドを指定できます。http://www.chemie.fu-berlin.de/chemnet/use/info/gdb/gdb_6.html#SEC35を参照してください。

したがって、関数の行数がわかっている場合は、関数のすべてのソース行を一覧表示するコマンドを設定できます。

(gdb) break myClass::EntityTypeStruct::readAttributes
Breakpoint 1 at 0x61ec3b: file /team/project/src/EntityTypeStruct.cc, line 38.
(gdb) commands 1
list 38,104
end
于 2014-06-17T16:22:30.357 に答える
4

gdbtui は、デバッグ中にソースを表示するのに役立ちます。

于 2012-10-10T17:13:56.447 に答える