이 콘텐츠는 선택한 언어로 제공되지 않습니다.

Chapter 3. The LLDB debugger


The LLDB debugger is a command-line tool for debugging C and C++ programs. Use LLDB to inspect memory within the code being debugged, control the execution state of the code, and detect the execution of particular sections of code.

LLVM Toolset is distributed with LLDB 19.1.7.

3.1. Prerequisites

3.2. Starting a debugging session

Use LLDB to start an interactive debugging session.

Procedure

  1. Run LLDB on a program you want to debug:

    $ lldb <binary_file>
    Copy to Clipboard Toggle word wrap

    Replace <binary_file> with the name of your compiled program.

    You have started your LLDB debugging session in interactive mode. Your command-line terminal now displays the default prompt (lldb).

  2. To quit the debugging session and return to the shell prompt:

    (lldb) quit
    Copy to Clipboard Toggle word wrap

3.3. Executing your program during a debugging session

Use LLDB to execute your program during your debugging session. The execution of your program stops when the first breakpoint is reached, when an error occurs, or when the program terminates.

Procedure

  • Execute the program you are debugging:

    (lldb) run
    Copy to Clipboard Toggle word wrap

    Alternatively, execute the program you are debugging by using a specific argument:

    (lldb) run <argument>
    Copy to Clipboard Toggle word wrap

    Replace <argument> with the command-line argument you want to use.

3.4. Using breakpoints

Use breakpoints to pause the execution of your program at a set point in your source code.

Procedure

  • To set a new breakpoint on a specific line, enter:

    (lldb) breakpoint set --file <source_file_name> --line <line_number>
    Copy to Clipboard Toggle word wrap

    Replace <source_file_name> with the name of your source file and <line_number> with the line number you want to set your breakpoint at.

  • To set a breakpoint on a specific function, enter:

    (lldb) breakpoint set --name <function_name>
    Copy to Clipboard Toggle word wrap
    • Replace <function_name> with the name of the function you want to set your breakpoint at.
  • To display a list of currently set breakpoints, enter:

    (lldb) breakpoint list
    Copy to Clipboard Toggle word wrap
  • To delete a breakpoint, run:

    (lldb) breakpoint clear -f <source_file_name> -l <line_number>
    Copy to Clipboard Toggle word wrap
    • Replace <source_file_name> with the name of your source file and <line_number> with line number of the breakpoint you want to delete.
  • To resume the execution of your program after it reached a breakpoint, enter:

    (lldb) continue
    Copy to Clipboard Toggle word wrap
  • To skip a specific number of breakpoints, enter:

    (lldb) continue -i <breakpoints_to_skip>
    Copy to Clipboard Toggle word wrap
    • Replace <breakpoints_to_skip> with the number of breakpoints you want to skip. To skip a loop, set the <breakpoints_to_skip> to match the loop iteration count.

3.5. Stepping through code

You can use LLDB to step through the code of your program to execute only one line of code after the line pointer.

Procedure

  1. Set your line pointer to the line you want to execute.
  2. Enter:

    (lldb) step
    Copy to Clipboard Toggle word wrap

3.6. Listing source code

Before you run the program you are debugging, the LLDB debugger automatically displays the first 10 lines of source code. Each time the execution of the program is stopped, LLDB displays the line of source code on which it stopped and its surrounding lines. You can use LLDB to manually trigger the display of source code during your debugging session.

Procedure

  • To list the first 10 lines of the source code of the program you are debugging, enter:

    (lldb) list
    Copy to Clipboard Toggle word wrap
    (lldb) list <source_file_name>:<line_number>
    Copy to Clipboard Toggle word wrap

    Replace <source_file_name> with the name of your source file and <line_number> with the number of the line you want to display.

3.7. Displaying current program data

The LLDB debugger provides data on variables of any complexity, any valid expressions, and function call return values. You can use LLDB to display data relevant to the program state.

Procedure

  • Display the current value of a certain variable, expression, or return value:

    (lldb) print <data_name>
    Copy to Clipboard Toggle word wrap

    Replace <data_name> with data you want to display.

맨 위로 이동
Red Hat logoGithubredditYoutubeTwitter

자세한 정보

평가판, 구매 및 판매

커뮤니티

Red Hat 문서 정보

Red Hat을 사용하는 고객은 신뢰할 수 있는 콘텐츠가 포함된 제품과 서비스를 통해 혁신하고 목표를 달성할 수 있습니다. 최신 업데이트를 확인하세요.

보다 포괄적 수용을 위한 오픈 소스 용어 교체

Red Hat은 코드, 문서, 웹 속성에서 문제가 있는 언어를 교체하기 위해 최선을 다하고 있습니다. 자세한 내용은 다음을 참조하세요.Red Hat 블로그.

Red Hat 소개

Red Hat은 기업이 핵심 데이터 센터에서 네트워크 에지에 이르기까지 플랫폼과 환경 전반에서 더 쉽게 작업할 수 있도록 강화된 솔루션을 제공합니다.

Theme

© 2025 Red Hat