fbpx
Wikipedia

LLDB (debugger)

The LLDB Debugger (LLDB) is the debugger component of the LLVM project. It is built as a set of reusable components which extensively use existing libraries from LLVM, such as the Clang expression parser and LLVM disassembler. LLDB is free and open-source software under the University of Illinois/NCSA Open Source License,[3] a BSD-style permissive software license. Since v9.0.0, it was relicensed to the Apache License 2.0 with LLVM Exceptions.[2]

LLDB
Developer(s)LLVM Developer Group
Stable release
15.0.7[1]  / 12 January 2023; 57 days ago (12 January 2023)
Repository
  • github.com/llvm/llvm-project
Written inC++
Operating systemmacOS i386 and x86-64, Linux, FreeBSD, NetBSD, Windows
TypeDebugger
LicenseUIUC (BSD-style)
Apache License 2.0 with LLVM Exceptions (v9.0.0 or later)[2]
Websitelldb.llvm.org

Current state

LLDB supports debugging of programs written in C, Objective-C, and C++. The Swift community maintains a version which adds support for the language. It is known to work on macOS, Linux, FreeBSD, NetBSD and Windows,[4] and supports i386, x86-64, and ARM instruction sets.[5] LLDB is the default debugger for Xcode 5 and later. Android Studio also uses LLDB for debug.[6] LLDB can be used from other IDEs, including Visual Studio Code,[7] C++Builder,[8] Eclipse,[9] and CLion.[10]

Features matrix [5]
Feature FreeBSD Linux macOS NetBSD Windows
Backtracing          
Breakpoints          
C++11         ?
Command-line lldb tool          
Core file debugging          
Debugserver (remote debugging)          
Disassembly          
Expression evaluation Works with some bugs Works with some bugs   Works with some bugs Works with some bugs
JIT debugging ? Symbolic debugging only Untested Work In Progress  
Objective-C 2.0: ?   ?

Examples of commands

lldb program Debug "program" (from the shell)
run Run the loaded program
break set -n main Set a breakpoint at the start of function "main"
bt Backtrace (in case the program crashed)
register read Dump all registers
di -n main Disassemble the function "main"

An example session

Consider the following incorrect program written in C:

#include <stdio.h> int main(void) {  char msg = "Hello, world!\n";  printf("%s", msg);  return 0; } 

Using the clang compiler on macOS, the code above can be compiled using the -g flag to include appropriate debug information on the binary generated—including the source code—making it easier to inspect it using LLDB. Assuming that the file containing the code above is named test.c, the command for the compilation could be:

$ clang -g test.c -o test 

And the binary can now be run:

$ ./test Segmentation fault 

Since the example code, when executed, generates a segmentation fault, lldb can be used to inspect the problem:

$ lldb test (lldb) target create "test" Current executable set to 'test' (x86_64). (lldb) run Process 70716 launched: '/Users/wikipedia/test' (x86_64) Process 70716 stopped * thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0xffffff90)  frame #0: 0x00007fff6c7c46f2 libsystem_platform.dylib`_platform_strlen + 18 libsystem_platform.dylib`_platform_strlen: -> 0x7fff6c7c46f2 <+18>: pcmpeqb xmm0, xmmword ptr [rdi]  0x7fff6c7c46f6 <+22>: pmovmskb esi, xmm0  0x7fff6c7c46fa <+26>: and rcx, 0xf  0x7fff6c7c46fe <+30>: or rax, -0x1 Target 0: (test) stopped. 

The problem occurs when calling the function strlen, but we can run a backtrace to identify the exact line of code that is causing the problem:

(lldb) bt * thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0xffffff90)  * frame #0: 0x00007fff6c7c46f2 libsystem_platform.dylib`_platform_strlen + 18  frame #1: 0x00007fff6c66b16a libsystem_c.dylib`__vfprintf + 8812  frame #2: 0x00007fff6c6911c3 libsystem_c.dylib`__v2printf + 475  frame #3: 0x00007fff6c668e22 libsystem_c.dylib`vfprintf_l + 54  frame #4: 0x00007fff6c666f72 libsystem_c.dylib`printf + 174  frame #5: 0x0000000100000f6d test`main at test.c:5:2  frame #6: 0x00007fff6c5dc3d5 libdyld.dylib`start + 1 (lldb) source list  3 int main(void) {  4 char msg = "Hello, world!\n";  5 printf("%s", msg);  6 return 0;  7 } 

From the line beginning with frame #5, LLDB indicates that the error is at line 5 of test.c. Running source list, we see that this refers to the call to printf. According to the exception code EXC_BAD_ACCESS from the backtrace, strlen is trying to read from a region of memory it does not have access to by dereferencing an invalid pointer.[11] Returning to the source code, we see that the variable msg is of type char but contains a string instead of a character. To fix the problem, we modify the code to indicate that msg is a pointer to a string of chars by adding the * operator:

#include <stdio.h> int main(void) {  char* msg = "Hello, world!\n";  printf("%s", msg);  return 0; } 

After recompiling and running the executable again, LLDB now gives the correct result:

(lldb) target create "test" Current executable set to 'test' (x86_64). (lldb) run Process 93319 launched: '/Users/wikipedia/test' (x86_64) Hello, world! Process 93319 exited with status = 0 (0x00000000) (lldb) 

LLDB runs the program, which prints the output of printf to the screen. After the program exits normally, LLDB indicates that the process running the program has completed, and prints its exit status.

See also

References

  1. ^ "Release 15.0.7". 12 January 2023. Retrieved 5 February 2023.
  2. ^ a b LICENSE.TXT, llvm.org, retrieved 2019-09-24
  3. ^ "LLVM Release License"
  4. ^ "LLVM Project Blog". 20 January 2015.
  5. ^ a b "LLDB Status". Retrieved January 31, 2022.
  6. ^ "Debug your app".
  7. ^ "Add a new tool named "lldb-vscode" that implements the Visual Studio Code Debug Adaptor Protocol".
  8. ^ "11.3 introduces a new LLDB-based debugger for macOS Intel and 32-bit Android. With 11.3 all non-Windows platform debuggers across Delphi and C++ have moved to LLDB architecture".
  9. ^ "CDT/Useer/FAQ".
  10. ^ "LLDB CLion Blog".
  11. ^ "Technical Note TN2151: Understanding and Analyzing Application Crash Reports". Documentation Archive. Apple Developer. Retrieved 13 February 2020.

External links

  • Official website
  • Supported LLDB Versions in Qt Creator

lldb, debugger, this, article, rely, excessively, sources, closely, associated, with, subject, potentially, preventing, article, from, being, verifiable, neutral, please, help, improve, replacing, them, with, more, appropriate, citations, reliable, independent. This article may rely excessively on sources too closely associated with the subject potentially preventing the article from being verifiable and neutral Please help improve it by replacing them with more appropriate citations to reliable independent third party sources February 2015 Learn how and when to remove this template message The LLDB Debugger LLDB is the debugger component of the LLVM project It is built as a set of reusable components which extensively use existing libraries from LLVM such as the Clang expression parser and LLVM disassembler LLDB is free and open source software under the University of Illinois NCSA Open Source License 3 a BSD style permissive software license Since v9 0 0 it was relicensed to the Apache License 2 0 with LLVM Exceptions 2 LLDBDeveloper s LLVM Developer GroupStable release15 0 7 1 12 January 2023 57 days ago 12 January 2023 Repositorygithub wbr com wbr llvm wbr llvm projectWritten inC Operating systemmacOS i386 and x86 64 Linux FreeBSD NetBSD WindowsTypeDebuggerLicenseUIUC BSD style Apache License 2 0 with LLVM Exceptions v9 0 0 or later 2 Websitelldb wbr llvm wbr org Contents 1 Current state 2 Examples of commands 3 An example session 4 See also 5 References 6 External linksCurrent state EditLLDB supports debugging of programs written in C Objective C and C The Swift community maintains a version which adds support for the language It is known to work on macOS Linux FreeBSD NetBSD and Windows 4 and supports i386 x86 64 and ARM instruction sets 5 LLDB is the default debugger for Xcode 5 and later Android Studio also uses LLDB for debug 6 LLDB can be used from other IDEs including Visual Studio Code 7 C Builder 8 Eclipse 9 and CLion 10 Features matrix 5 Feature FreeBSD Linux macOS NetBSD WindowsBacktracing Breakpoints C 11 Command line lldb tool Core file debugging Debugserver remote debugging Disassembly Expression evaluation Works with some bugs Works with some bugs Works with some bugs Works with some bugsJIT debugging Symbolic debugging only Untested Work In Progress Objective C 2 0 Examples of commands Editlldb program Debug program from the shell run Run the loaded programbreak set n main Set a breakpoint at the start of function main bt Backtrace in case the program crashed register read Dump all registersdi n main Disassemble the function main An example session EditConsider the following incorrect program written in C include lt stdio h gt int main void char msg Hello world n printf s msg return 0 Using the clang compiler on macOS the code above can be compiled using the g flag to include appropriate debug information on the binary generated including the source code making it easier to inspect it using LLDB Assuming that the file containing the code above is named test c the command for the compilation could be clang g test c o test And the binary can now be run test Segmentation fault Since the example code when executed generates a segmentation fault lldb can be used to inspect the problem lldb test lldb target create test Current executable set to test x86 64 lldb run Process 70716 launched Users wikipedia test x86 64 Process 70716 stopped thread 1 queue com apple main thread stop reason EXC BAD ACCESS code 1 address 0xffffff90 frame 0 0x00007fff6c7c46f2 libsystem platform dylib platform strlen 18 libsystem platform dylib platform strlen gt 0x7fff6c7c46f2 lt 18 gt pcmpeqb xmm0 xmmword ptr rdi 0x7fff6c7c46f6 lt 22 gt pmovmskb esi xmm0 0x7fff6c7c46fa lt 26 gt and rcx 0xf 0x7fff6c7c46fe lt 30 gt or rax 0x1 Target 0 test stopped The problem occurs when calling the function a href Strlen html strlen class mw redirect title Strlen strlen a but we can run a backtrace to identify the exact line of code that is causing the problem lldb bt thread 1 queue com apple main thread stop reason EXC BAD ACCESS code 1 address 0xffffff90 frame 0 0x00007fff6c7c46f2 libsystem platform dylib platform strlen 18 frame 1 0x00007fff6c66b16a libsystem c dylib vfprintf 8812 frame 2 0x00007fff6c6911c3 libsystem c dylib v2printf 475 frame 3 0x00007fff6c668e22 libsystem c dylib vfprintf l 54 frame 4 0x00007fff6c666f72 libsystem c dylib printf 174 frame 5 0x0000000100000f6d test main at test c 5 2 frame 6 0x00007fff6c5dc3d5 libdyld dylib start 1 lldb source list 3 int main void 4 char msg Hello world n 5 printf s msg 6 return 0 7 From the line beginning with frame 5 LLDB indicates that the error is at line 5 of test c Running source list we see that this refers to the call to printf According to the exception code EXC BAD ACCESS from the backtrace strlen is trying to read from a region of memory it does not have access to by dereferencing an invalid pointer 11 Returning to the source code we see that the variable msg is of type char but contains a string instead of a character To fix the problem we modify the code to indicate that msg is a pointer to a string of chars by adding the operator include lt stdio h gt int main void char msg Hello world n printf s msg return 0 After recompiling and running the executable again LLDB now gives the correct result lldb target create test Current executable set to test x86 64 lldb run Process 93319 launched Users wikipedia test x86 64 Hello world Process 93319 exited with status 0 0x00000000 lldb LLDB runs the program which prints the output of printf to the screen After the program exits normally LLDB indicates that the process running the program has completed and prints its exit status See also Edit Free and open source software portalGNU Debugger Microsoft Visual Studio DebuggerReferences Edit Release 15 0 7 12 January 2023 Retrieved 5 February 2023 a b LICENSE TXT llvm org retrieved 2019 09 24 LLVM Release License LLVM Project Blog 20 January 2015 a b LLDB Status Retrieved January 31 2022 Debug your app Add a new tool named lldb vscode that implements the Visual Studio Code Debug Adaptor Protocol 11 3 introduces a new LLDB based debugger for macOS Intel and 32 bit Android With 11 3 all non Windows platform debuggers across Delphi and C have moved to LLDB architecture CDT Useer FAQ LLDB CLion Blog Technical Note TN2151 Understanding and Analyzing Application Crash Reports Documentation Archive Apple Developer Retrieved 13 February 2020 External links EditOfficial website Supported LLDB Versions in Qt Creator Retrieved from https en wikipedia org w index php title LLDB debugger amp oldid 1141749541, wikipedia, wiki, book, books, library,

article

, read, download, free, free download, mp3, video, mp4, 3gp, jpg, jpeg, gif, png, picture, music, song, movie, book, game, games.