[Mac][iOS] GDB - infoコマンド

2010年12月30日木曜日 | Published in | 0 コメント

このエントリーをはてなブックマークに追加

デバッグ中に使える info コマンドで使えるいくつかの便利なものについて紹介する。

info


デバッガコンソールにプロンプト "(gdb)" が出ている状態で info と打ち込むと利用可能なサブコマンドの一覧が表示される。
"info" must be followed by the name of an info command.
List of info subcommands:

info address -- Describe where symbol SYM is stored
info all-registers -- List of all registers and their contents
info args -- Argument variables of current stack frame
info auxv -- Display the inferior's auxiliary vector
info breakpoints -- Status of user-settable breakpoints
info catch -- Exceptions that can be caught in the current stack frame
info checkpoints -- Help
info classes -- All Objective-C classes
info common -- Print out the values contained in a Fortran COMMON block
info copying -- Conditions for redistributing copies of GDB
info dcache -- Print information on the dcache performance
info display -- Expressions to display when program stops
info extensions -- All filename extensions associated with a source language
info files -- Names of targets and files being debugged
info float -- Print the status of the floating point unit
info fork -- Help
info frame -- All about selected stack frame
info functions -- All function names
info gc-references -- List the garbage collectors references for a given address
info gc-roots -- List the garbage collector's shortest unique roots to a given address
info handle -- What debugger does when program gets various signals
info interpreters -- List the interpreters currently available in gdb
info line -- Core addresses of the code for a source line
info locals -- Local variables of current stack frame
info mach-port -- Get info on a specific port
info mach-ports -- Get list of ports in a task
info mach-region -- Get information on mach region at given address
info mach-regions -- Get information on all mach region for the current inferior
info mach-task -- Get info on a specific task
info mach-tasks -- Get list of tasks in system
info mach-thread -- Get info on a specific thread
info mach-threads -- Get list of threads in a task
info macro -- Show the definition of MACRO
info malloc-history -- List the stack(s) where malloc or free occurred for the address
info mem -- Memory region attributes
info pid -- Process ID of the program
info plugins -- Show current plug-ins state
info program -- Execution status of the program
info registers -- List of integer registers and their contents
info scope -- List the variables local to a scope
info selectors -- All Objective-C selectors
info set -- Show all GDB settings
info sharedlibrary -- Generic command for shlib information
info signals -- What debugger does when program gets various signals
info source -- Information about the current source file
info sources -- Source files in the program
info stack -- Backtrace of the stack
info symbol -- Describe what symbol is at location ADDR
info target -- Names of targets and files being debugged
info task -- Get information on task
info terminal -- Print inferior's saved terminal status
info thread -- Get information on thread
info threads -- IDs of currently known threads
info tracepoints -- Status of tracepoints
info trampoline -- Resolve function for DYLD trampoline stub and/or Objective-C call
info types -- All type names
info variables -- All global and static variable names
info vector -- Print the status of the vector unit
info warranty -- Various kinds of warranty you do not have
info watchpoints -- Synonym for ``info breakpoints''


info args


実行中の関数の引数情報が表示される。
(gdb) info args
self = (CustomArrayController *) 0x10061b8f0
_cmd = (struct objc_selector *) 0x100003487
objects = (NSArray *) 0x10064ab90


info malloc-history


指定したアドレスを持つオブジェクトの malloc/free された経緯(スタック)を表示する。
(gdb) info malloc-history 0x10064ab90
Alloc: Block address: 0x000000010064ab90 length: 56
Stack - pthread: 0x7fff70913ca0 number of frames: 27
    0: 0x7fff85b8ef0e in malloc_zone_malloc
    1: 0x7fff83e15e83 in __CFBasicHashRehash
    2: 0x7fff83e21e8d in __CFBasicHashAddValue
    3: 0x7fff83e29698 in CFBasicHashSetValue
    4: 0x7fff83e294b7 in CFDictionarySetValue
    5: 0x7fff849fb00a in -[NSButtonCell _coreUIBezelDrawOptionsWithFrame:inView:]
    6: 0x7fff849fa518 in -[NSButtonCell drawBezelWithFrame:inView:]
    7: 0x7fff849dfda7 in -[NSButtonCell drawWithFrame:inView:]
    8: 0x7fff849d83c8 in -[NSControl drawRect:]
    9: 0x7fff849d0c49 in -[NSView _drawRect:clip:]
   10: 0x7fff849cf8bc in -[NSView _recursiveDisplayAllDirtyWithLockFocus:visRect:]
     :

開放済みのオブジェクトへメッセージを送って落ちた時などの原因究明に使える。
-[NSSortDescriptor count]: message sent to deallocated instance 0x1f5480

なおこのコマンドを利用するには予め環境変数 MallocStackLoggingNoCompact を設定する必要がある。未設定の状態で実行すると下記のメッセ次が表示される。
(gdb) info malloc-history 0x100557600
warning: MallocStackLoggingNoCompact not set in target's environment so the malloc
 history will not be available.
Unable to enumerate stack logging records: (os/kern) failure (ox5).
設定は実行可能ファイルの情報 - 引数を開き「環境に設定される変数」へ MallocStackLoggingNoCompact, YES と設定する。
この設定を有効にしてプログラムを実行するとデバッグコンソールに関連するメッセージが起動時に表示されるようになる。
bash(94048) malloc: recording malloc stacks to disk using standard recorder
bash(94048) malloc: stack logging compaction turned off; size of log files on disk
 can increase rapidly
bash(94048) malloc: process 94034 no longer exists, stack logs deleted from
 /tmp/stack-logs.94034.ArrayControllerUndoSample.kYfauH.index
bash(94048) malloc: stack logs being written into /tmp/stack-logs.94048.bash.Bi3fK8.index
arch(94048) malloc: recording malloc stacks to disk using standard recorder
arch(94048) malloc: stack logging compaction turned off; size of log files on disk can
 increase rapidly
arch(94048) malloc: stack logs deleted from /tmp/stack-logs.94048.bash.Bi3fK8.index
arch(94048) malloc: stack logs being written into /tmp/stack-logs.94048.arch.iH8G41.index
実行中...
ArrayControllerUndoSample(94048) malloc: recording malloc stacks to disk using standard recorder
ArrayControllerUndoSample(94048) malloc: stack logging compaction turned off;
 size of log files on disk can increase rapidly
ArrayControllerUndoSample(94048) malloc: stack logs deleted from
 /tmp/stack-logs.94048.arch.iH8G41.index
ArrayControllerUndoSample(94048) malloc: stack logs being written into
 /tmp/stack-logs.94048.ArrayControllerUndoSample.psd1af.index


info stack


スタックのバックトレースを表示する。Xcodeのデバッグツールでも表示できるがコマンド実行できると何かと便利。
(gdb) info stack
#0  -[CustomArrayController _addObserverFor:] (self=0x10012d9a0, _cmd=0x100003487, 
objects=0x100557600) at /Users/hashi/Development/CustomArrayController.m:145
#1  0x0000000100002560 in -[CustomArrayController insertObject:atArrangedObjectIndex:]
 (self=0x10012d9a0, _cmd=0x7fff8500a525, object=0x1005588c0, index=0) at
 /Users/hashi/Development/ArrayControllerUndoSample/CustomArrayController.m:171
#2  0x00007fff84a5b156 in -[NSArrayController addObject:] ()
#3  0x00007fff84b779d3 in -[NSArrayController _executeAdd:didCommitSuccessfully:actionSender:] ()
#4  0x00007fff84ad6329 in _NSSendCommitEditingSelector ()
#5  0x00007fff84ad7c97 in -[NSController _controllerEditor:didCommit:contextInfo:] ()
#6  0x00007fff83e9896c in __invoking___ ()
#7  0x00007fff83e9883d in -[NSInvocation invoke] ()
#8  0x00007fff83eb4711 in -[NSInvocation invokeWithTarget:] ()
#9  0x00007fff88deb23c in __NSFireDelayedPerform ()
#10 0x00007fff83e5fbe8 in __CFRunLoopRun ()
#11 0x00007fff83e5ddbf in CFRunLoopRunSpecific ()
#12 0x00007fff86b5d91a in RunCurrentEventLoopInMode ()
#13 0x00007fff86b5d67d in ReceiveNextEventCommon ()
#14 0x00007fff86b5d5d8 in BlockUntilNextEventMatchingListInMode ()
#15 0x00007fff84913e64 in _DPSNextEvent ()
#16 0x00007fff849137a9 in -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] ()
#17 0x00007fff848d948b in -[NSApplication run] ()
#18 0x00007fff848d21a8 in NSApplicationMain ()
#19 0x0000000100001abd in main (argc=1, argv=0x7fff5fbff4d0) at
 /Users/hashi/Development/MacOSX-Sample-Code/ArrayControllerUndoSample/main.m:13

Responses

Leave a Response

人気の投稿(過去 30日間)