Sign in Join
Wiki copytemporary

lldb: what changed

Revision 1 to 2. Removed lines have a minus sign; added lines have a plus sign.

OldNewLine
11lldb is the Xcode (macOS) default debugger. It's available when you have installed Xcode and/or the Xcode standalone command line tools.
22
33It's still possible to build and install the gdb debugger. However, there are certain security requirements, and not everyone would like to take that approach.
44
55## LLDB and Lazarus
66
77LLDB is now the standard debugger in the Lazarus IDE for macOS. The recommended setting is "Dwarf with sets" (-gw -godwarfsets).
88
99### Crashing issues
1010
1111Sometimes the LLDB crashes when running an app from the IDE. In many cases this is caused by a corrupt bundle file. Rebuilding the bundle uses to help in these cases.
1212
1313## Creating a backtrace
1414
15151\. Open an Applications \> Utilities \> Terminal.
1616
17172\. Change to the application bundle (if you're debugging a GUI application). Example:
1818
19-` cd project1.app/Contents/MacOS/`
19+```text
20+ cd project1.app/Contents/MacOS/
21+```
2022
2123If you're debugging a command-line application, you don't need to do that.
2224
23253\. Run lldb with the program to debug. Launching a project with lldb takes longer than launching without it.
2426
25-`$ lldb project1`\
26-`(lldb) target create "project1"`\
27-`Current executable set to 'project1' (x86_64).`\
28-`(lldb) `
27+```text
28+$ lldb project1
29+(lldb) target create "project1"
30+Current executable set to 'project1' (x86_64).
31+(lldb)
32+```
2933
3034**Note** launching an application with lldb for the first time might require you have admin rights - you might be prompted for your account password. This happens only on the initial launch of lldb. However, after a reboot, the authentication might be needed again.
3135
32364\. When you see lldb is ready ("lldb" would show up in the Terminal) execute the "r" command (run). Example:
3337
34-`(lldb) r`\
35-`Process 12974 launched: '/Users/dmitry/Desktop/Cocoa/buffer/project1.app/Contents/MacOS/project1' (x86_64)`
38+```text
39+(lldb) r
40+Process 12974 launched: '/Users/dmitry/Desktop/Cocoa/buffer/project1.app/Contents/MacOS/project1' (x86_64)
41+```
3642
37435\. You should now switch back to your application and take the actions that are necessary to reproduce the crash.
3844
39456\. When the crash occurs the lldb console is available again. If debugging information and sources are available, lldb would typically show you the line of code where crash occurred.
4046
41-` Process 12974 stopped`\
42-`` * thread #1: tid = 0xd4503, 0x000000010003d9b1 project1`UNIT1$_$TFORM1_$__$$_BUTTON1CLICK$TOBJECT + 97 at unit1.pas:47, queue = 'com.apple.main-thread', stop reason = EXC_ARITHMETIC (code=EXC_I386_DIV, subcode=0x0) ``\
43-``     frame #0: 0x000000010003d9b1 project1`UNIT1$_$TFORM1_$__$$_BUTTON1CLICK$TOBJECT + 97 at unit1.pas:47 ``\
44-`   44        b:=5;`\
45-`   45        b:=b div 5;`\
46-`   46        b:=b-b;`\
47-`-> 47        writeln(a div b);`\
48-`   48      end;`\
49-`   49      `\
50-`   50      end.`\
51-`(lldb) `
47+``` pascal
48+ Process 12974 stopped
49+* thread #1: tid = 0xd4503, 0x000000010003d9b1 project1`UNIT1$_$TFORM1_$__$$_BUTTON1CLICK$TOBJECT + 97 at unit1.pas:47, queue = 'com.apple.main-thread', stop reason = EXC_ARITHMETIC (code=EXC_I386_DIV, subcode=0x0)
50+ frame #0: 0x000000010003d9b1 project1`UNIT1$_$TFORM1_$__$$_BUTTON1CLICK$TOBJECT + 97 at unit1.pas:47
51+ 44 b:=5;
52+ 45 b:=b div 5;
53+ 46 b:=b-b;
54+-> 47 writeln(a div b);
55+ 48 end;
56+ 49
57+ 50 end.
58+(lldb)
59+```
5260
53617\. Run "bt" command to get the backtrace.
5462
55-`(lldb) bt`\
56-`` * thread #1: tid = 0xd4503, 0x000000010003d9b1 project1`UNIT1$_$TFORM1_$__$$_BUTTON1CLICK$TOBJECT + 97 at unit1.pas:47, queue = 'com.apple.main-thread', stop reason = EXC_ARITHMETIC (code=EXC_I386_DIV, subcode=0x0) ``\
57-``   * frame #0: 0x000000010003d9b1 project1`UNIT1$_$TFORM1_$__$$_BUTTON1CLICK$TOBJECT + 97 at unit1.pas:47 ``\
58-``     frame #1: 0x00000001001eeb88 project1`CONTROLS$_$TCONTROL_$__$$_CLICK + 104 at control.inc:2916 ``\
59-``     frame #2: 0x00000001002588da project1`STDCTRLS$_$TBUTTONCONTROL_$__$$_CLICK + 42 at buttoncontrol.inc:55 ``\
60-``     frame #3: 0x000000010025909f project1`STDCTRLS$_$TCUSTOMBUTTON_$__$$_CLICK + 79 at buttons.inc:169 ``\
61-``     frame #4: 0x00000001002587e2 project1`STDCTRLS$_$TBUTTONCONTROL_$__$$_WMDEFAULTCLICKED$TLMESSAGE + 66 at buttoncontrol.inc:21 ``\
62-``     frame #5: 0x0000000100012103 project1`SYSTEM$_$TOBJECT_$__$$_DISPATCH$formal + 203 ``\
63-``     frame #6: 0x00000001001eda95 project1`CONTROLS$_$TCONTROL_$__$$_WNDPROC$TLMESSAGE + 517 at control.inc:2246 ``\
64-``     frame #7: 0x00000001001e0926 project1`CONTROLS$_$TWINCONTROL_$__$$_WNDPROC$TLMESSAGE + 806 at wincontrol.inc:5406 ``\
65-``     frame #8: 0x00000001001cc980 project1`LCLMESSAGEGLUE_$$_DELIVERMESSAGE$TOBJECT$formal$$INT64 + 224 at lclmessageglue.pas:112 ``\
66-``     frame #9: 0x00000001001cca8b project1`LCLMESSAGEGLUE_$$_SENDSIMPLEMESSAGE$TCONTROL$LONGWORD$$INT64 + 59 at lclmessageglue.pas:143 ``\
67-``     frame #10: 0x000000010029200a project1`COCOAWSSTDCTRLS$_$TLCLBUTTONCALLBACK_$__$$_BUTTONCLICK + 58 at cocoawsstdctrls.pp:401 ``\
68-``     frame #11: 0x00000001001b2a3f project1`-[TCocoaButton actionButtonClick:] + 87 at cocoaprivate.pp:2294 ``\
69-``     frame #12: 0x00007fffbec8dc41 libsystem_trace.dylib`_os_activity_initiate + 61 ``\
70-``     frame #13: 0x00007fffa7a5c770 AppKit`-[NSApplication(NSResponder) sendAction:to:from:] + 456 ``\
71-``     frame #14: 0x00007fffa75450d8 AppKit`-[NSControl sendAction:to:] + 86 ``\
72-``     frame #15: 0x00007fffa7545000 AppKit`__26-[NSCell _sendActionFrom:]_block_invoke + 136 ``\
73-``     frame #16: 0x00007fffbec8dc41 libsystem_trace.dylib`_os_activity_initiate + 61 ``\
74-``     frame #17: 0x00007fffa7544f58 AppKit`-[NSCell _sendActionFrom:] + 128 ``\
75-``     frame #18: 0x00007fffa75878d9 AppKit`-[NSButtonCell _sendActionFrom:] + 98 ``\
76-``     frame #19: 0x00007fffbec8dc41 libsystem_trace.dylib`_os_activity_initiate + 61 ``\
77-``     frame #20: 0x00007fffa754383c AppKit`-[NSCell trackMouse:inRect:ofView:untilMouseUp:] + 2481 ``\
78-``     frame #21: 0x00007fffa7587616 AppKit`-[NSButtonCell trackMouse:inRect:ofView:untilMouseUp:] + 798 ``\
79-``     frame #22: 0x00007fffa75421f7 AppKit`-[NSControl mouseDown:] + 832 ``\
80-``     frame #23: 0x00000001001b31ab project1`-[TCocoaButton mouseDown:] + 139 at cocoaprivate.pp:2410 ``\
81-``     frame #24: 0x00007fffa7bd291f AppKit`-[NSWindow(NSEventRouting) _handleMouseDownEvent:isDelayedEvent:] + 6341 ``\
82-``     frame #25: 0x00007fffa7bcf13c AppKit`-[NSWindow(NSEventRouting) _reallySendEvent:isDelayedEvent:] + 1942 ``\
83-``     frame #26: 0x00007fffa7bce5da AppKit`-[NSWindow(NSEventRouting) sendEvent:] + 541 ``\
84-``     frame #27: 0x00000001001b15df project1`-[TCocoaWindow sendEvent:] + 919 at cocoaprivate.pp:1943 ``\
85-``     frame #28: 0x00007fffa7a586f5 AppKit`-[NSApplication(NSEvent) sendEvent:] + 1145 ``\
86-``     frame #29: 0x00000001001a405c project1`COCOAINT$_$TCOCOAWIDGETSET_$__$$_APPPROCESSMESSAGES + 268 at cocoaobject.inc:105 ``\
87-``     frame #30: 0x000000010003733d project1`FORMS$_$TAPPLICATION_$__$$_HANDLEMESSAGE + 45 at application.inc:1276 ``\
88-``     frame #31: 0x00000001000378e1 project1`FORMS$_$TAPPLICATION_$__$$_RUNLOOP + 209 at application.inc:1419 ``\
89-``     frame #32: 0x00000001001a3d17 project1`-[TCocoaApplication run] + 71 at cocoaint.pas:368 ``\
90-``     frame #33: 0x00000001001a3f4a project1`COCOAINT$_$TCOCOAWIDGETSET_$__$$_APPRUN$TAPPLICATIONMAINLOOP + 106 at cocoaobject.inc:83 ``\
91-``     frame #34: 0x0000000100037808 project1`FORMS$_$TAPPLICATION_$__$$_RUN + 96 at application.inc:1401 ``\
92-``     frame #35: 0x0000000100001514 project1`PASCALMAIN + 92 at project1.lpr:19 ``\
93-``     frame #36: 0x0000000100020ef9 project1`FPC_SYSTEMMAIN + 41 ``\
94-``     frame #37: 0x0000000100001494 project1`start + 52 ``\
95-`(lldb)`
63+```text
64+(lldb) bt
65+* thread #1: tid = 0xd4503, 0x000000010003d9b1 project1`UNIT1$_$TFORM1_$__$$_BUTTON1CLICK$TOBJECT + 97 at unit1.pas:47, queue = 'com.apple.main-thread', stop reason = EXC_ARITHMETIC (code=EXC_I386_DIV, subcode=0x0)
66+ * frame #0: 0x000000010003d9b1 project1`UNIT1$_$TFORM1_$__$$_BUTTON1CLICK$TOBJECT + 97 at unit1.pas:47
67+ frame #1: 0x00000001001eeb88 project1`CONTROLS$_$TCONTROL_$__$$_CLICK + 104 at control.inc:2916
68+ frame #2: 0x00000001002588da project1`STDCTRLS$_$TBUTTONCONTROL_$__$$_CLICK + 42 at buttoncontrol.inc:55
69+ frame #3: 0x000000010025909f project1`STDCTRLS$_$TCUSTOMBUTTON_$__$$_CLICK + 79 at buttons.inc:169
70+ frame #4: 0x00000001002587e2 project1`STDCTRLS$_$TBUTTONCONTROL_$__$$_WMDEFAULTCLICKED$TLMESSAGE + 66 at buttoncontrol.inc:21
71+ frame #5: 0x0000000100012103 project1`SYSTEM$_$TOBJECT_$__$$_DISPATCH$formal + 203
72+ frame #6: 0x00000001001eda95 project1`CONTROLS$_$TCONTROL_$__$$_WNDPROC$TLMESSAGE + 517 at control.inc:2246
73+ frame #7: 0x00000001001e0926 project1`CONTROLS$_$TWINCONTROL_$__$$_WNDPROC$TLMESSAGE + 806 at wincontrol.inc:5406
74+ frame #8: 0x00000001001cc980 project1`LCLMESSAGEGLUE_$$_DELIVERMESSAGE$TOBJECT$formal$$INT64 + 224 at lclmessageglue.pas:112
75+ frame #9: 0x00000001001cca8b project1`LCLMESSAGEGLUE_$$_SENDSIMPLEMESSAGE$TCONTROL$LONGWORD$$INT64 + 59 at lclmessageglue.pas:143
76+ frame #10: 0x000000010029200a project1`COCOAWSSTDCTRLS$_$TLCLBUTTONCALLBACK_$__$$_BUTTONCLICK + 58 at cocoawsstdctrls.pp:401
77+ frame #11: 0x00000001001b2a3f project1`-[TCocoaButton actionButtonClick:] + 87 at cocoaprivate.pp:2294
78+ frame #12: 0x00007fffbec8dc41 libsystem_trace.dylib`_os_activity_initiate + 61
79+ frame #13: 0x00007fffa7a5c770 AppKit`-[NSApplication(NSResponder) sendAction:to:from:] + 456
80+ frame #14: 0x00007fffa75450d8 AppKit`-[NSControl sendAction:to:] + 86
81+ frame #15: 0x00007fffa7545000 AppKit`__26-[NSCell _sendActionFrom:]_block_invoke + 136
82+ frame #16: 0x00007fffbec8dc41 libsystem_trace.dylib`_os_activity_initiate + 61
83+ frame #17: 0x00007fffa7544f58 AppKit`-[NSCell _sendActionFrom:] + 128
84+ frame #18: 0x00007fffa75878d9 AppKit`-[NSButtonCell _sendActionFrom:] + 98
85+ frame #19: 0x00007fffbec8dc41 libsystem_trace.dylib`_os_activity_initiate + 61
86+ frame #20: 0x00007fffa754383c AppKit`-[NSCell trackMouse:inRect:ofView:untilMouseUp:] + 2481
87+ frame #21: 0x00007fffa7587616 AppKit`-[NSButtonCell trackMouse:inRect:ofView:untilMouseUp:] + 798
88+ frame #22: 0x00007fffa75421f7 AppKit`-[NSControl mouseDown:] + 832
89+ frame #23: 0x00000001001b31ab project1`-[TCocoaButton mouseDown:] + 139 at cocoaprivate.pp:2410
90+ frame #24: 0x00007fffa7bd291f AppKit`-[NSWindow(NSEventRouting) _handleMouseDownEvent:isDelayedEvent:] + 6341
91+ frame #25: 0x00007fffa7bcf13c AppKit`-[NSWindow(NSEventRouting) _reallySendEvent:isDelayedEvent:] + 1942
92+ frame #26: 0x00007fffa7bce5da AppKit`-[NSWindow(NSEventRouting) sendEvent:] + 541
93+ frame #27: 0x00000001001b15df project1`-[TCocoaWindow sendEvent:] + 919 at cocoaprivate.pp:1943
94+ frame #28: 0x00007fffa7a586f5 AppKit`-[NSApplication(NSEvent) sendEvent:] + 1145
95+ frame #29: 0x00000001001a405c project1`COCOAINT$_$TCOCOAWIDGETSET_$__$$_APPPROCESSMESSAGES + 268 at cocoaobject.inc:105
96+ frame #30: 0x000000010003733d project1`FORMS$_$TAPPLICATION_$__$$_HANDLEMESSAGE + 45 at application.inc:1276
97+ frame #31: 0x00000001000378e1 project1`FORMS$_$TAPPLICATION_$__$$_RUNLOOP + 209 at application.inc:1419
98+ frame #32: 0x00000001001a3d17 project1`-[TCocoaApplication run] + 71 at cocoaint.pas:368
99+ frame #33: 0x00000001001a3f4a project1`COCOAINT$_$TCOCOAWIDGETSET_$__$$_APPRUN$TAPPLICATIONMAINLOOP + 106 at cocoaobject.inc:83
100+ frame #34: 0x0000000100037808 project1`FORMS$_$TAPPLICATION_$__$$_RUN + 96 at application.inc:1401
101+ frame #35: 0x0000000100001514 project1`PASCALMAIN + 92 at project1.lpr:19
102+ frame #36: 0x0000000100020ef9 project1`FPC_SYSTEMMAIN + 41
103+ frame #37: 0x0000000100001494 project1`start + 52
104+(lldb)
105+```
96106
971078\. At this point you can give the "q" command (quit) to the debugger.
98108
99-`(lldb) q`\
100-`Quitting LLDB will kill one or more processes. Do you really want to proceed: [Y/n] y`
109+```text
110+(lldb) q
111+Quitting LLDB will kill one or more processes. Do you really want to proceed: [Y/n] y
112+```
101113
1021149 If you need to stop the application running under the debugger:
103115
104116
1051179.1 Hit Ctrl+C on the Terminal tab. This should signal to the debugger to pause the executed program.
106118
1071199.2 Give "q" command (quit) to the debugger.
108120
109121## Breakpoint issues
110122
111123Issue: There seems to be an issue starting with Xcode 11.4 (and still in Xcode 11.5). If stopped at a breakpoint within an objcclass type subclass, the “self” item is missing from the debugger. I still see the “this” for any objects descended from fpc’s TObject, so this seems to only apply to objcclass types.
112124
113125Background: At some point, lldb gained "support" for Pascal. Unfortunately, that support was barely non-existent, so rather than treating debug information in a Pascal program the same as it did in C/C++ programs like it did before, suddenly a bunch of things got broken when debugging a program whose debug information indicated it was a Pascal program.
114126
115127Possible solution: What you can try is to use the **-godwarfcpp** command line option. Then FPC will encode in the debug information that it's a C++ program which solves several of those issues.
116128
117129## DevToolsSecurity
118130
119131The `DevToolsSecurity` command line utility changes the security authorisation policies for use of the Apple-code-signed debugger and performance analysis tools on development systems.
120132
121133On normal user systems, the first time in a given login session that any such Apple code-signed debugger or performance analysis tools are used to examine one of the user's processes, the user is queried for an administrator password for authorisation. The tool changes the authorisation policies, such that a user who is a member of either the admin group or the _developer group does not need to enter an additional password to use the Apple-code-signed debugger or performance analysis tools.
122134
123135To enable, open an Applications \> Utilities \> Terminal window and execute the following command:
124136
125-`sudo DevToolsSecurity -enable`
137+```text
138+sudo DevToolsSecurity -enable
139+```
126140
127141to enable the change of security authorisation policies;
128142
129-`sudo DevToolsSecurity -disable`
143+```text
144+sudo DevToolsSecurity -disable
145+```
130146
131147to disable the change of security authorisation policies; and
132148
133-`DevToolsSecurity -status`
149+```text
150+DevToolsSecurity -status
151+```
134152
135153to check whether the change of security authorisation policies is enabled or disabled.
136154
137155## See also
138156
139157- [Apple: Appendix A: LLDB for GDB Users – Command Summary](https://developer.apple.com/library/archive/documentation/General/Conceptual/lldb-guide/chapters/A3-GDB-Summary.html)
140158- [[Creating a Backtrace with GDB]]
141159
142160---
143161*From the Free Pascal wiki, page "lldb", as it stood on 2023-04-06 after a change by Jwdietrich, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).*
144162Category: Debugging
145163Category: macOS

Back to history