72
64

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

LLDB 使い方まとめ

Last updated at Posted at 2014-12-07

微妙にgdbと違うため、メモ

LLDB 起動方法

lldb -f ./$(TARGET)

##実行

lldbプロンプトにて

(lldb)r

'r'の一文字だけでリセット&RUN

##break

(lldb)br set -n SomeFunc()

関数名などは途中入力でも[TAB]補完が効きます.

(lldb)br set -n CSome::UpdateView()
(lldb)br set -f some.c -l 113

some.cpp の113行目にbreakを打ちます.
113行目に有効なコードが存在しない場合でも、
付近の有効なコードにbreakを打ち込んでもらえます。

##break-point 一覧表示

(lldb)br li

フルスペル"break list" でも可だが、"br li" で短縮でも可。

Current breakpoints:

4: name = 'main', locations = 1, resolved = 1, hit count = 1
  4.1: where = gsh`main + 30 at gshell.cpp:545, address = 0x00000001000031ee, resolved, hit count = 1

5: name = 'Doc2Win::UpdateView()', locations = 1, resolved = 1, hit count = 0
  5.1: where = gsh`Doc2Win::UpdateView() + 12 at document2window.cpp:72, address = 0x000000010000991c, resolved, hit count = 0

Step実行

(lldb)s

's' 1文字でOK

Continue実行

(lldb)c

'c' 1文字でOK

WATCH変数の追加

(lldb)watch set var 変数名

WATCH変数の列挙

(lldb)watch list
Number of supported hardware watchpoints: 4
Current watchpoints:
Watchpoint 1: addr = 0x100046750 size = 4 state = disabled type = w
    watchpoint spec = 'pid_root'
    new value: 0

全スレッド列挙

(lldb)th list
Process 12205 stopped
* thread #1: tid = 0x46462, 0x00007fff8c76e306 libsystem_kernel.dylib`__read_nocancel + 10, queue = 'com.apple.main-thread', stop reason = signal SIGSTOP
  thread #2: tid = 0x46480, 0x00007fff8c76e486 libsystem_kernel.dylib`__semwait_signal + 10
  thread #3: tid = 0x46481, 0x00007fff8c76e486 libsystem_kernel.dylib`__semwait_signal + 10
  thread #4: tid = 0x46482, 0x00007fff8c76e486 libsystem_kernel.dylib`__semwait_signal + 10

スレッド選択

th list で表示されている #n でカレントスレッドを選択します

(lldb)th sel 2   #2を選択したい場合は2だけ。'#'は不要
* thread #2: tid = 0x46480, 0x00007fff8c76e486 libsystem_kernel.dylib`__semwait_signal + 10
    frame #0: 0x00007fff8c76e486 libsystem_kernel.dylib`__semwait_signal + 10
libsystem_kernel.dylib`__semwait_signal + 10:
-> 0x7fff8c76e486:  jae    0x7fff8c76e490            ; __semwait_signal + 20
   0x7fff8c76e488:  movq   %rax, %rdi
   0x7fff8c76e48b:  jmp    0x7fff8c769cc8            ; cerror
   0x7fff8c76e490:  retq

Frame情報出力

(lldb)fr info
frame #0: 0x00007fff8c76e306 libsystem_kernel.dylib`__read_nocancel + 10

Frame選択

(lldb)fr sel 6
frame #6: 0x0000000100004344 gsh`PromptRunLoop() + 820 at gshell.cpp:235
   232 				StrReplaceCmdLine.clear();
   233 			}
   234
-> 235 			int ch = GSHELL_Getc();
   236 			if( EOF == (s8)ch )				continue;
   237 			if( IsCR(ch) )
   238 			{

Frame内のローカル変数を全て表示

(lldb)fr va
(int) ch = 1

バックトレース

(lldb)bt

これはgdbと同じです。

* thread #1: tid = 0x43bf0, 0x000000010002dba6 gsh`Logger::Logger(this=0x0000000100200000, fname_log=0x0000000100042af2, bNoHeader=false, bDump=true) + 38 at logger.cpp:148, queue = 'com.apple.main-thread', stop reason = step in
  * frame #0: 0x000000010002dba6 gsh`Logger::Logger(this=0x0000000100200000, fname_log=0x0000000100042af2, bNoHeader=false, bDump=true) + 38 at logger.cpp:148
    frame #1: 0x000000010000321e gsh`main(argc=1, argv=0x00007fff5fbff988) + 78 at gshell.cpp:545
    frame #2: 0x00007fff88abd5c9 libdyld.dylib`start + 1
    frame #3: 0x00007fff88abd5c9 libdyld.dylib`start + 1

全てのスレッドのバックトレース

(lldb)bt all

デバッグ対象プログラムの一時中断

CTRL-C

^Cで中断させると、デバッガのプロンプトに戻ります。

終了

(lldb)quit
72
64
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
72
64

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?