Sign in Join
Wiki copytemporary

GDB Debugger Tips: what changed

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

OldNewLine
11## Introduction
22
33Lazarus comes with [[GDB]] as default debugger. From Lazarus 2.0 onwards, this default has changed to LLDB on MacOs.
44
55- This page is for Lazarus 1.0 and newer. For older versions see \[ previous version of this page\]
66- Note on GDB 7.5: GDB 7.5 is not supported by the released 1.0. Fixes to support it were made in 1.1.
77
88## See also
99
1010### Setup (GDB and LLDB)
1111
1212To get the best possible results, you must ensure that your IDE and Project are both correctly configured.
1313
1414See [[Debugger Setup]] how to set up the IDE and your project in order to use the debugger.
1515
1616[Setup Video Tutorial](http://www.youtube.com/watch?v=cf4G06k2YL8)
1717
1818### Other
1919
2020- [[Debugger Console App|Debugging console applications]]
2121- [[Debugger Status|Overview and Status of debugger-backends in Lazarus]]
2222
2323## General
2424
2525### Debug Info Type (GDB and LLDB)
2626
2727> **Note:** Those setting apply only to the project or package to which they are set. If changing settings in either project or package options, it should be ensured that this is done for **all** packages and the project.\
2828> Otherwise your project will have mixed debug info, which can lead to a degraded debug experience.\
2929> The setting can be applied to project and packages using [[IDE Window: Compiler Options|Additions and Overrides]]
3030
3131> **Note:** When compiling 32Bit apps (native or cross) FPC defaults to "Stabs" (At least on some OS). It is recommended to change your configuration to "Dwarf".
3232
3333For 64 bit applications, FPC supports only "Dwarf". (Older FPC also support "Stabs", but that is not recommended)
3434
3535### Stabs (only GDB)
3636
3737-g or -gs
3838
3939You should only use if your gdb version does not support dwarf. There are very few other cases where you need it.
4040
4141You may need it with "var param" (param by ref) procedure foo(var a: integer); However the IDE deals with this in 99% of all cases.
4242
4343The LLDB based debugger does not support Stabs
4444
4545#### Dwarf (GDB and LLDB)
4646
4747##### Dwarf 2 (-gw)
4848
4949This sets the format to Dwarf2. This is the most basic dwarf setting.
5050
5151##### Dwarf 2 with sets (-gw -godwarfsets)
5252
5353This setting adds the ability to inspect sets: "type TFoo=set of (a,b,c);". This is borrowed from the Dwarf 3 specs, but supported by most versions of GDB (any GDB from version 7 upwards should do).
5454
55-**`This is the recommended setting.`**` `
55+```text
56+This is the recommended setting.
57+```
5658
5759##### Dwarf 3 (-gw3)
5860
5961Dwarf 3 can encode additional info for some types (such as strings and arrays). It also preserves the case of identifiers in the debug info.
6062
6163However there are still issues with the produced debug info. Some info may be incorrectly encoded, and other is not understood by GDB. In some cases this can lead to gdb crashing. This setting can be used, when using the FpDebug based debugger (add on package for the IDE)
6264
6365#### Differences
6466
6567This list is in no way complete:
6668
6769- dwarf allows some properties (those directly mapped to a field)
6870- stabs (and modern gdb) can do -gp (preserve the case of symbols, instead of getting the all caps stuff).
6971- stabs has problems with some class type casts. The IDE fixes that in some cases. (Only affects gdb 7.0 and up) [1](http://bugs.freepascal.org/view.php?id=19920)
7072
7173### Inspecting data types (Watch/Hint)
7274
7375#### Strings
7476
7577GDB does not know the Pascal string data type. The type information GDB returns does not currently allow for the IDE to differentiate between a PChar (index is 0 based) or a String (index is 1 based).
7678
7779As a Result "mystring\[10\]" could be the 10th char in a string, or 11th in a PChar.
7880
7981Because the IDE cannot be sure which one applies, it will show both. The 2 results will be prefixed String/PChar.
8082
8183#### Properties
8284
8385Currently the debugger does not support any method execution. Therefore only properties that refer directly to a variable can be inspected. (This only works if using dwarf)
8486
8587``` pascal
8688TFoo = Class
8789private
8890 FBar: Integer;
8991 function GetValue: Integer;
9092public
9193 property Bar: Integer read FBar; // Can be inspected (if Dwarf is used)
9294 property Value: Integer read GetValue; // Can *not* be inspected
9395end;
9496```
9597
9698#### Nested Procedures / Function
9799
98100``` pascal
99101procedure SomeObject.Outer(NumText: string);
100102var
101103 OuterVarInScope: Integer;
102104
103105procedure Nested;
104106var
105107 I: Integer;
106108begin
107109 WriteLn(OuterVarInScope);
108110end;
109111
110112var
111113 OuterVarOutsideScope: Integer;
112114
113115begin
114116 Nested;
115117end;
116118```
117119
118120If you step into "Nested", then the IDE allows you to inspect variables from both stack frames.
119121
120122This is you can inspect: I, OuterVarInScope, NumText (without having to change the current stack frame, in the stack window)
121123
122124However there are some caveats:
123125
124126You can also inspect: OuterVarOutsideScope. That is against Pascal scoping rules. This only matters if you have several nested levels, and they all contain a variable of the same name, but the Pascal scoping would hide the variable from the middle frame. Then you get to see the wrong value.
125127
126128You cannot evaluate statements across the 2 frames: "OuterVarnScope-I" does not work.
127129
128130> **Warning:** You may see a wrong value. If there is in any other unit a global (or otherwise visible to GDB scoping rules) variable, with the same name as the local var from the outer frame, then that global var will be shown. There is no warning for that. The safe way is to explicitly select the outer stack frame in which the local var is defined, and check the value.
129131
130132#### Arrays
131133
132134``` pascal
133135array [x..y] of Integer;
134136```
135137
136138shows as chars, instead of int. Only gdb 7.2 or up seems to handle it correctly.
137139
138140Additionally there may be issues when using arrays of (unnamed) records.
139141
140142Dynamic Arrays will only show a limited amount of their data. As of Lazarus 1.1 the limit can be specified.
141143
142144If Watches/Hint values are not displaying correctly disable REGVARS. Set -OoNOREGVAR in "Custom Options".
143145
144146### Specifying GDB disassembly flavor
145147
146148GDB allows one to specify the assembly flavor (intel or AT&T style) to be used when displaying assembly code. If one wants to change to a specific flavor this can be changed in the AssemblerStyle property in Lazarus's debugger options for GDB (feature available from Lazarus 2.0). Alternatively (and the only way to achieve this from inside Lazarus in older versions before Lazarus 2.0) one can specify this option by passing the *set disassembly-flavor* instruction to [Debugger_Startup_options](/wiki-images/5/5d/Media%3ADbg_setup_options2.png). Several syntax variations can be used (depending on GDB version), a few variations are shown below:
147149
148-` -ex "set disassembly-flavor intel"`\
149-` --eval-command="set disassembly-flavor intel"`\
150-` -eval-command="set disassembly-flavor intel"`\
151-` --eval-command "set disassembly-flavor intel"`
150+```text
151+ -ex "set disassembly-flavor intel"
152+ --eval-command="set disassembly-flavor intel"
153+ -eval-command="set disassembly-flavor intel"
154+ --eval-command "set disassembly-flavor intel"
155+```
152156
153157Note that it may be necessary to reset the debugger *(Run \| Reset Debugger)* before GDB will load with the new setting.
154158
155159## Windows
156160
157161### Environment and Unicode / None-Latin based locale
158162
159163GDB in combination with Lazarus can have issues, if your environment (such as Username, or PATH, or ...) contain none Latin chars.
160164
161165This is not an issue with any particular GDB version. Rather it depends on how GDB was build. To work correctly under Lazarus GDB needs to have been build using Cygwin.
162166
163167There are several builds available provided by the Lazarus team. Some of them are build with Cygwin. For 64bit: <https://sourceforge.net/projects/lazarus/files/Lazarus%20Windows%2064%20bits/Alternative%20GDB/>
164168
165169For 32bit the builds have not yet been tested. <https://sourceforge.net/projects/lazarus/files/Lazarus%20Windows%2032%20bits/Alternative%20GDB/>
166170
167171### Console output for GUI application
168172
169173On Windows, the IDE does not have the "Debugger - Console output" window. This is because console applications open their own console window. GUI applications by default have no console. In order to have a console for a GUI application, the compiler settings must be changed (Project options / Compiler Options / Config and Target / Win32 Gui Application: -WC / -WG)
170174
171175### Debugging applications with Administrative privileges
172176
173177On Windows Vista+, in Project Options setting the manifest file permissions for the program to "as Administrator" will run the program with Administrator privileges. If your IDE is not running as Administrator, debugging will appear to start ok, the program will show in the tasklist, but its GUI will not show.
174178
175179So please be aware that you have to match privilege level between the IDE (and gdb) and the applicationt to be debugged.
176180
177181## Win 64 bit
178182
179183- Requires Lazarus 1.0+ (with FPC 2.6+)
180184- Advised to use dwarf
181185
182186### Using 32 bit Lazarus on 64 bit Windows
183187
184188Alternatively it is possible to debug applications as 32 bit applications (using the 32bit version of gdb). Once successfully debugged:
185189
186190- the app can then be cross-compiled to 64 bit, or
187191- a 2nd Lazarus installation can be used (using a different configuration --primary-config-path option from the 32 bit Lazarus)
188192
189193When installing the 32 bit Lazarus, ensure you change configuration so the correct 32 bit FPC and GDB are used.
190194
191195### More Win 64 bit problems and solutions
192196
193197See also <http://forum.lazarus.freepascal.org/index.php/topic,13188.0/topicseen.html>
194198
195199## Win CE
196200
197201### Debugger does not find any source files
198202
199203Menu: "Tools" Page: "Debugger"/"Generic" Field: "Additional search path"
200204
201205Put your the drive letter of your project directory in this field.
202206
203207## Linux
204208
205209### Known Problems
206210
207211- There might be issues on at least some CPUs when using an old version of gdb (e.g. SPARC, with gdb 6.4 as supplied by Debian "Etch"). In particular, background threads might lock up even if the program appears to run correctly standalone.
208212- If your program appears to lock up at start up, go to Tools / Options / Debugger / General and set DisableLoadSymbolsForLibraries=True
209213
210214## macOS
211215
212216With the release of macOS 10.14 (Mojave) in 2018, **gdb** was replaced by *[[lldb]]*', and is no longer supported.
213217
214218This section is a first approach to collect information about known issues and workarounds. The information provided here depends a lot on feedback from macOS users.
215219
216220From Lazarus 2.0 onwards the IDE has an LLDB based debugger. The GDB based debugger can also be used, but requires a lot of work building and code-signing the gdb binary and is not supported.
217221
218222### Known Problems (GDB)
219223
220224#### Debugging 32 bit app on 64 bit architecture
221225
222226It is possible and maybe sometime necessary to debug a 32 bit exe on a 64 bit system.
223227
224228This is only possible with Lazarus 0.9.29 rev 28640 and up.
225229
226230#### TimeOuts (64 Bit only)
227231
228232It appears that certain commands are not correctly (or incompletely) processed by gdb 6.3.50. Normally GDB finishes each command with a "\<gdb\>" prompt for the next command. But the version provided by apple sometimes fails to do this. In this case the IDE will have to use a timeout to avoid waiting forever.
229233
230234This has been observed with:
231235
232236- Certain Watch expressions (at least if the watched variable was not available in the current selected function)
233237- Handling an Exception
234238- Inserting breakpoints (past unit end / none code location)
235239
236240It cannot be guaranteed:
237241
238242- that GDB will not later return some results from such a command
239243- that GDB's internal state is still valid
240244
241245The prompt displayed for timeouts can be switched off in the debugger config.
242246
243247Warn On Timeout
244248True/False. Auto continue, after a timeout, do not show a warning.
245249
246250TimeOutForEval
247251Set in milliseconds, how long until a timeout detection is triggered (the detection itself may take some more time.)
248252
249253You may need to "RESET" the debugger after those changes are made
250254
251255More info see here:
252256
253257- [<http://bugs.freepascal.org/view.php?id=19262#c47944>](http://bugs.freepascal.org/view.php?id=19262#c47944)
254258- <http://bugs.freepascal.org/view.php?id=21653>
255259
256260An alternative solution seems to be to use a newer version of GDB (see below).
257261
258262#### Hardware exceptions under macOS
259263
260264When a hardware exception occurs under macOS, such as an invalid pointer access (SIGSEGV) or an integer division-by-zero on Intel processors, the debugger will catch this exception at the Mach level. Normally, the system translates these Mach exceptions into Unix-style signals where the FPC run time library handles them. The debugger is however unable to propagate Mach exceptions in this way.
261265
262266The practical upshot is that it is impossible under macOS to continue a program in the debugger once a hardware exception has been triggered. This is not FPC-specific, and cannot be fixed by us.
263267
264268### Using Alternative Debuggers (GDB)
265269
266270You can install GDB 7.1 (or later) using MacPorts, fink or homebrew.
267271
268272The following observations have been made:
269273
270274- GDB 7.1 seems to have issues with the stabs debug info from fpc.
271275
272276
273277Make sure you select "generate dwarf debug information (-gw)" on the linking tab of the project options
274278
275279**Watch out for the linker warnings about "unknown stabs"**
276280
277281
278282If you still have problems ensure that no code at all, is compiled with stabs. Your LCL may contain stabs, and this will end up in your app, even if you compile the app with -gw. So you may have to recompile your LCL with -gw (or without any debug info). Same for any other unit, package, rtl, .... that may have stabs
279283
280284**Even with those rules followed, GDB does not always work with fpc compiled apps.**
281285
282286Those observations may be incomplete or wrong, please update them, if you have more information.
283287
284288Lazarus Version 1.0 to 1.0.12
285289
286290In the debugger options configure
287291
288-` EncodeCurrentDirPath = gdfeNone`\
289-` EncodeExeFilename = gdfeNone`
292+```text
293+ EncodeCurrentDirPath = gdfeNone
294+ EncodeExeFilename = gdfeNone
295+```
290296
291297And you must use "run param" to specify the actual executable inside the app-bundle ( project.app/Content/MacOS/project or similar)
292298
293299In Lazarus Version 1.0.14 to 1.2 and up those steps should no longer be required.
294300
295301### Xcode 5
296302
297303Since Mavericks 10.9, Xcode 5 no longer installs gdb by default and not globally.
298304
299305- For 10.9 you can install an old Xcode 4 in parallel. This is not supported by Apple, so it might break with one of the next versions.
300306
301307- You can compile and install gdb. See [[GDB on OS X Mavericks or newer and Xcode 5 or newer]].
302308
303309Please see [issue 25157 on mantis](http://bugs.freepascal.org/view.php?id=25157)
304310
305311- <http://forum.lazarus.freepascal.org/index.php/topic,22529.0.html> - about installing Xcode 4.3
306312- <http://forum.lazarus.freepascal.org/index.php/topic,22328.0.html> - install gdb
307313
308314Thread "\[Lazarus\] Help: macOS Problems" on
309315
310316- <http://lists.lazarus.freepascal.org/pipermail/lazarus/2013-November/thread.html#84126>
311317- <http://lists.lazarus.freepascal.org/pipermail/lazarus/2013-October/thread.html#84095>
312318
313319### Frozen UI with GDB
314320
315321To start a program from the shell you need to run "open \<program1\>.app", direct access to ./program1 will not give you access to the UI. To get gdb working from inside your IDE you have to specify this path as run parameter. Choose from menu Run \> Run parameter and enter the full path at host application. For instance, /User/\<yourid\>/sources/myproject/project1.app/Content/MacOS/project1
316322
317323### Links
318324
319325- macOS comes with a lot of useful tools for debugging and profiling. Just start /Developer/Applications/Instruments.app and try them out.
320326
321327## FreeBSD
322328
323329### FreeBSD 11
324330
325331The system-provided gdb is ancient (version 6.1.1 in FreeBSD 11.4) and does not work well with Lazarus.
326332
327333You can install a newer gdb from the ports tree, e.g.
328334
329335``` bash
330336cd /usr/ports/devel/gdb
331337make -DBATCH install clean
332338```
333339
334340The new gdb is located in "/usr/local/bin/gdb".
335341
336342### FreeBSD 12
337343
338344The system-provided gdb is ancient (version 6.1.1 in FreeBSD 12.3) and it does not work well with Lazarus.
339345
340346You can install a newer gdb from the ports tree, e.g.
341347
342348``` bash
343349cd /usr/ports/devel/gdb
344350make -DBATCH install clean
345351```
346352
347353The new gdb is located in "/usr/local/bin/gdb".
348354
349355It may need the following project option ("Project Options" dialog):
350356
351357- "Use external debug symbols file" is off
352358
353359### FreeBSD 13
354360
355361FreeBSD 13.0 has removed the ancient gdb from the base system and replaced it with [[lldb]].
356362
357363You can still install a recent gdb from the ports tree.
358364
359365## Using a translated GDB (non-English responses from GDB)
360366
361367- This applies only to Lazarus *before* 1.2 or *before* 1.0.14.\
362368 This is no longer needed.
363369
364370The IDE expects responses in English. If GDB is translated this may affect how well the IDE can use it.
365371
366372In many cases it will still work, but with limits, such as:
367373
368374- No Message or Class for exceptions
369375- No live update of threads, while app is running
370376- Debugger error reported, after the app is stopped (at end of debugging)
371377- other ...
372378
373379Please read the entire thread: [[http://forum.lazarus.freepascal.org/index.php/topic,20756.msg120720 http://forum.lazarus.freepascal.org/index.php/topic,20756.msg120720]]
374380
375381Try to run lazarus with
376382
377-` export LANG=en_US.UTF-8`\
378-` lazarus`
383+```text
384+ export LANG=en_US.UTF-8
385+ lazarus
386+```
379387
380388## Known Problems / Errors reported by the IDE
381389
382390Message    
383391
384392OS
385393
386394Description
387395
388396 
389397
390398### During startup program exited normally
391399
392400 
393401
394402 
395403
396404**All**
397405
398406In rare cases the IDE displays the message "During startup program exited normally". This message appears when the debugged application is closed. If this happens no breakpoints in the app will have been triggered, and the app will have run as if no debugger was present.
399407
400408This error can happen for various reasons. There are at least 2 known:
401409
402410- certain position independent exe (PIE) : GDB fails to relocate certain breakpoints that Lazarus uses to start the exe (this is before any user breakpoints are set)
403411- certain dll/so libraries, that define the same symbols as the main exe.
404412
405413There may be more. The 2nd only happens on repeated runs of the debugger.
406414
407415The IDE tries to work around those, but it does not always succeed. It is likely that in cases where it currently fails, this must be worked around by user set config (see below).
408416
409417Even if you can work around, please consider to send a logfile: #Log_info_for_debug_session
410418
411419Ways to work around: (all on the options / debugger page)
412420
413421- In case 2 only: #gdb.exe_has_stopped_working
414422
415423Lazarus 1.2.2 and before
416424go to the debugger options and in the field "debugger_startup_options" enter:\
417425--eval-command="set auto-solib-add off"
418426
419427Lazarus 1.2.4 and higher
420428go to the debugger options and set the field "DisableLoadSymbolsForLibraries" to "True"
421429
422430This can only be used, if you do not debug within libraries (if you have not written your own lib)
423431
424432- In Case 2 only: Check "reset debugger after each run"
425433
426434It will add a very slight increase to the time it takes to start the debugger, as gdb must be reloaded each time.
427435
428436- In all cases:
429437
430438Try any of the values available for "InternalStartBreak" (in the property grid of the options)
431439
432440### SIGFPE
433441
434442 
435443
436444 
437445
438446**All**
439447
440448SIGFPE is a floating point unit exception.
441449
442450Source: [[http://forum.lazarus.freepascal.org/index.php/topic,21586.0.html forum thread]]
443451
444452SIGFPE exceptions are raised on the next FPU instruction; therefore the error line you get from Lazarus may be off/incorrect.
445453
446454Delphi, and thus Freepascal, have a non standard FPEMask. A lot of C libraries don't use exceptions to check FPU problems but inspect the FPU status.
447455
448456Workaround: try changing the mask with [SetExceptionMask](http://www.freepascal.org/docs-html/rtl/math/setexceptionmask.html) as early as possible in your program:
449457
450458``` pascal
451459uses math;
452460...
453461 SetExceptionMask([exInvalidOp, exDenormalized, exZeroDivide,
454462 exOverflow, exUnderflow, exPrecision])
455463```
456464
457465If you think there is something wrong in the FPC code, you can use the [\$SAFEFPUEXCEPTIONS](http://www.freepascal.org/docs-html/prog/progsu69.html) directive. This will add a FWAIT after every store of a FPU value to memory. Most FPC float and double operations end with storing the result somewhere in memory so the outcome is that the debugger stops on the correct FPC line. FWAIT is a nop for the FPU but will cause an exception to be raised immediately instead of somewhere down your code. It is not done per default because it slows down floating point operations a lot.
458466
459467### Error 193 (Error creating process / Exe not found)
460468
461469 
462470
463471 
464472
465473**Windows**
466474
467475For details see [here](http://bugs.freepascal.org/view.php?id=18238). This issue has been observed under Win XP and appears to be caused by Windows itself. The issue occurs if the path to your app has a space, and a 2nd path/file exists, with a name identical to the part of the path before the space, e.g.:
468476
469477
470478Your app: C:\test folder\project1.exe
471479
472480Some file: C:\test
473481
474482### SigSegV - even with new, empty application
475483
476484 
477485
478486 
479487
480488**Windows**
481489
482490Note
483491In most cases SigSegV is simply an error in your code.
484492
485493The following applies only, if you get a SigSegv, even with a new empty application (empty form, and no modifications made to unit1).
486494
487495A SigSegV sometimes can be caused by an incompatibility between GDB and some other products. It is not known if this is a GDB issue or caused by the other product. There is no indication that any of the products listed is in any way at fault. The information provided may only apply to some versions of the named products:
488496
489497Comodo firewall
490498<http://forum.lazarus.freepascal.org/index.php/topic,7065.msg60621.html#msg60621>
491499
492500BitDefender
493501enable game mode
494502
495503### SigSegV - and continue debugging
496504
497505 
498506
499507 
500508
501509**Windows**, **Mac**
502510
503511<http://sourceware.org/bugzilla/show_bug.cgi?id=10004>
504512
505513<http://forum.lazarus.freepascal.org/index.php/topic,18121.msg101798.html#msg101798>
506514
507515### On Windows Open/Save/File or System Dialog cause gdb to crash
508516
509517See next entry "gdb.exe has stopped working"
510518
511519Or download the "alternative GDB" 7.7.1 (Win32) from the Lazarus SourceForge site.
512520
513521### "Step over" steps into function (Win 64)
514522
515523 
516524
517525 
518526
519527**Windows 64**
520528
521529Sometimes pressing F8 does not step over a function, but steps into it.
522530
523531It is possible to continue with F8, and sometimes GDB will step back into the calling function, after 1 or 2 further steps (stepping over the remainder of the function).
524532
525533In Lazarus 2.0 a workaround was added, but needs to be enabled. Go to Tools \> Options \> Debugger and enable (in the property grid) "FixIncorrectStepOver".
526534
527535### gdb.exe has stopped working / SigSegv with Open/Close Dlg
528536
529537 
530538
531539 
532540
533541**Windows**
534542
535543GDB itself has crashed. This will be due to a bug in gdb, and may not be fixable in Lazarus. Still it may be worth submitting info (see section "Reporting Bugs" below). Maybe Lazarus can avoid calling the failing function.
536544
537545There is one already known situation. GDB (6.6 to 7.4 (latest at the time of testing)) may crash while your app is being started, or right after your app stopped. This happen while the libraries (DLL) for your app are loaded (watch the "[[IDE Window: Debug Output|Debug output]]" window).
538546
539547Lazarus 1.2.2 and before
540548go to the debugger options and in the field "debugger_startup_options" enter:\
541549--eval-command="set auto-solib-add off"
542550
543551Lazarus 1.2.4 and higher
544552go to the debugger options and set the field "DisableLoadSymbolsForLibraries" to "True"
545553
546554This can only be used, if you do not debug within libraries (if you have not written your own lib) ![](/wiki-images/a/a9/Gdb_start_opt_nolib.png)
547555
548556### internal-error: clear_dangling_display_expressions
549557
550558 
551559
552560 
553561
554562**Windows, maybe other**
555563
556564At the end of the debug session, the debugger reports:
557565
558-`internal-error: clear_dangling_display_expressions: `\
559-`` Assertion `objfile->pspace == solib->pspace' failed. ``
566+```text
567+internal-error: clear_dangling_display_expressions:
568+Assertion `objfile->pspace == solib->pspace' failed.
569+```
560570
561571This is an error in gdb, and sometimes solved by
562572
563573Lazarus 1.2.2 and before
564574go to the debugger options and in the field "debugger_startup_options" enter:\
565575--eval-command="set auto-solib-add off"
566576
567577Lazarus 1.2.4 and higher
568578go to the debugger options and set the field "DisableLoadSymbolsForLibraries" to "True"
569579
570580This can only be used, if you do not debug within libraries (if you have not written your own lib)
571581
572582### "PC register is not available" ("SuspendThread failed. (winerr 5)")
573583
574584 
575585
576586 
577587
578588**Windows**
579589
580590GDB may fail with this message. This is due to [<http://sourceware.org/bugzilla/show_bug.cgi?id=14018>](http://sourceware.org/bugzilla/show_bug.cgi?id=14018) If you get this issue you may want to downgrade to GDB 7.2
581591
582592### Cannot insert breakpoint
583593
584594 
585595
586596 
587597
588598**All**
589599
590600For breakpoints with negative numbers Please see: <http://forum.lazarus.freepascal.org/index.php/topic,10317.msg121818.html#msg121818>
591601
592602You may also want to try:
593603
594604Lazarus 1.2.2 and before
595605go to the debugger options and in the field "debugger_startup_options" enter:\
596606--eval-command="set auto-solib-add off"
597607
598608Lazarus 1.2.4 and higher
599609go to the debugger options and set the field "DisableLoadSymbolsForLibraries" to "True"
600610
601611This can only be used, if you do not debug within libraries (if you have not written your own lib)
602612
603613For breakpoints with positive numbers This may happen due to incorrect [[Debugger Setup]]. Ensure smart linking is disabled. It usually means that the breakpoint is in a procedure that is not called, and not included in your exe.
604614
605615On Windows, if it happens despite correct setup, then add -Xe (external linker) to the custom options.
606616
607617## Reporting Bugs
608618
609619- Did you verify your [[Debugger Setup]]?
610620- Did you try Dwarf and Stabs
611621
612622### Check existing Reports
613623
614624Please check each of the following links
615625
616626- [Search Mantis for category "debugger"](http://bugs.freepascal.org/search.php?project_id=0&category=Debugger&status_id%5B%5D=10&status_id%5B%5D=20&status_id%5B%5D=30&status_id%5B%5D=40&status_id%5B%5D=50&status_id%5B%5D=80&sticky_issues=on&sortby=last_updated&dir=DESC&per_page=250&hide_status_id=-2)
617627- [Search Mantis for text "debugger"](http://bugs.freepascal.org/search.php?project_id=1&search=debugger&category%5B%5D=-&category%5B%5D=Compiler&category%5B%5D=Converter&category%5B%5D=Custom+Drawn&category%5B%5D=Database&category%5B%5D=Database+Components&category%5B%5D=Documentation&category%5B%5D=FCL&category%5B%5D=FPSpreadsheet&category%5B%5D=FV&category%5B%5D=Free+Vision&category%5B%5D=IDE&category%5B%5D=Installer&category%5B%5D=LCL&category%5B%5D=LazDataDesktop&category%5B%5D=LazReport&category%5B%5D=Misc&category%5B%5D=OnGuard&category%5B%5D=Other&category%5B%5D=Packages&category%5B%5D=Patch&category%5B%5D=Printer&category%5B%5D=RTL&category%5B%5D=TAChart&category%5B%5D=Utilities&category%5B%5D=Virtual+Treeview&category%5B%5D=Web+site&category%5B%5D=Website&category%5B%5D=Widgetset&category%5B%5D=glscene&category%5B%5D=lNet&category%5B%5D=rx&status_id%5B%5D=10&status_id%5B%5D=20&status_id%5B%5D=30&status_id%5B%5D=40&status_id%5B%5D=50&status_id%5B%5D=80&sticky_issues=on&sortby=last_updated&dir=DESC&per_page=250&hide_status_id=-2)
618628- [Search Mantis for text "gdb"](http://bugs.freepascal.org/search.php?project_id=1&search=gdb&category%5B%5D=-&category%5B%5D=Compiler&category%5B%5D=Converter&category%5B%5D=Custom+Drawn&category%5B%5D=Database&category%5B%5D=Database+Components&category%5B%5D=Documentation&category%5B%5D=FCL&category%5B%5D=FPSpreadsheet&category%5B%5D=FV&category%5B%5D=Free+Vision&category%5B%5D=IDE&category%5B%5D=Installer&category%5B%5D=LCL&category%5B%5D=LazDataDesktop&category%5B%5D=LazReport&category%5B%5D=Misc&category%5B%5D=OnGuard&category%5B%5D=Other&category%5B%5D=Packages&category%5B%5D=Patch&category%5B%5D=Printer&category%5B%5D=RTL&category%5B%5D=TAChart&category%5B%5D=Utilities&category%5B%5D=Virtual+Treeview&category%5B%5D=Web+site&category%5B%5D=Website&category%5B%5D=Widgetset&category%5B%5D=glscene&category%5B%5D=lNet&category%5B%5D=rx&status_id%5B%5D=10&status_id%5B%5D=20&status_id%5B%5D=30&status_id%5B%5D=40&status_id%5B%5D=50&status_id%5B%5D=80&sticky_issues=on&sortby=last_updated&dir=DESC&per_page=250&hide_status_id=-2)
619629- [Search Mantis for text "dwarf"](http://bugs.freepascal.org/search.php?project_id=0&search=dwarf&category%5B%5D=-&category%5B%5D=Compiler&category%5B%5D=Converter&category%5B%5D=Custom+Drawn&category%5B%5D=Database&category%5B%5D=Database+Components&category%5B%5D=Documentation&category%5B%5D=FCL&category%5B%5D=FPSpreadsheet&category%5B%5D=FV&category%5B%5D=Free+Vision&category%5B%5D=IDE&category%5B%5D=Installer&category%5B%5D=LCL&category%5B%5D=LazDataDesktop&category%5B%5D=LazReport&category%5B%5D=Misc&category%5B%5D=OnGuard&category%5B%5D=Other&category%5B%5D=Packages&category%5B%5D=Patch&category%5B%5D=Printer&category%5B%5D=RTL&category%5B%5D=TAChart&category%5B%5D=Utilities&category%5B%5D=Virtual+Treeview&category%5B%5D=Web+site&category%5B%5D=Website&category%5B%5D=Widgetset&category%5B%5D=glscene&category%5B%5D=lNet&category%5B%5D=rx&status_id%5B%5D=10&status_id%5B%5D=20&status_id%5B%5D=30&status_id%5B%5D=40&status_id%5B%5D=50&status_id%5B%5D=80&sticky_issues=on&sortby=last_updated&dir=DESC&per_page=250&hide_status_id=-2)
620630- [Search Mantis for text "stabs"](http://bugs.freepascal.org/search.php?project_id=0&search=stabs&category%5B%5D=-&category%5B%5D=Compiler&category%5B%5D=Converter&category%5B%5D=Custom+Drawn&category%5B%5D=Database&category%5B%5D=Database+Components&category%5B%5D=Documentation&category%5B%5D=FCL&category%5B%5D=FPSpreadsheet&category%5B%5D=FV&category%5B%5D=Free+Vision&category%5B%5D=IDE&category%5B%5D=Installer&category%5B%5D=LCL&category%5B%5D=LazDataDesktop&category%5B%5D=LazReport&category%5B%5D=Misc&category%5B%5D=OnGuard&category%5B%5D=Other&category%5B%5D=Packages&category%5B%5D=Patch&category%5B%5D=Printer&category%5B%5D=RTL&category%5B%5D=TAChart&category%5B%5D=Utilities&category%5B%5D=Virtual+Treeview&category%5B%5D=Web+site&category%5B%5D=Website&category%5B%5D=Widgetset&category%5B%5D=glscene&category%5B%5D=lNet&category%5B%5D=rx&status_id%5B%5D=10&status_id%5B%5D=20&status_id%5B%5D=30&status_id%5B%5D=40&status_id%5B%5D=50&status_id%5B%5D=80&sticky_issues=on&sortby=last_updated&dir=DESC&per_page=250&hide_status_id=-2)
621631
622632### Bugs in GDB
623633
624634Description
625635
626636OS
627637
628638GDB Version(s)
629639
630640Reference
631641
632642win64 crash with bad dwarf2 symbols
633643
634644win64
635645
636646GDB 7.4 (maybe higher)
637647
638648<http://sourceware.org/bugzilla/show_bug.cgi?id=14014>
639649
640650Debuggee doesn't see environment variables set with set environment
641651
642652win
643653
644654Solved in GDB 7.4
645655
646656<http://sourceware.org/bugzilla/show_bug.cgi?id=10989>
647657
648658Win32 fails to continue with "winerr 5" (pc register not available)\
649659*apparently* not present in 7.0 to 7.2
650660
651661win
652662
653663GDB 7.3 and up (maybe 6.x too)\
654664Appears to be fixed in 7.7.1
655665
656666<http://sourceware.org/bugzilla/show_bug.cgi?id=14018>
657667
658668Wrong array index with dwarf
659669
660670*
661671
662672GDB 7.3 to 7.5 (maybe 7.6.0)\
663673fixed in 7.6.1
664674
665675<http://sourceware.org/bugzilla/show_bug.cgi?id=15102>
666676
667677GDB crashes, if trying to inspect or watch resourcestrings\
668678only tested on win32, not known for other platforms only, if using dwarf
669679
670680*
671681
672682GDB 7.0 to 7.2.xx
673683
674684Records (especially: pointer to record) may be mistaken for classes/objects\
675685The data/values appear to be displayed correct / further tests pending\
676686This also affect the ability to inspect shortstring\
677687You can workaround this by manually typecasting.
678688
679689*
680690
681691GDB 7.6.1 and up (tested and failing up to GDB 8.1)
682692
683693<https://sourceware.org/bugzilla/show_bug.cgi?id=16016>
684694
685695Object variables (Members) of the current methods class (self.xxx) cannot be watched/inspected\
686696To work around use upper case or prefix with self.
687697
688698*
689699
690700GDB 7.7 up to 7.9.0 (incl)\
691701Workaround present in Lazarus 1.4 and up
692702
693703<https://sourceware.org/bugzilla/show_bug.cgi?id=17835>
694704
695705gdb cannot continue after SIGFPE or SIGSEGV happen on windows
696706
697707win
698708
699709*
700710
701711<https://sourceware.org/bugzilla/show_bug.cgi?id=10004>
702712
703713GDB truncates values for "const x = qword(...)"
704714
705715Win 64 bit\
706716maybe others
707717
708718Fixed in GDB 7.7 and up, maybe fibed between 7.3 and 7.7
709719
710720GDB error for inspecting interfaces (IUnknown etc)
711721
712722DWARF 3
713723
714724<https://sourceware.org/bugzilla/show_bug.cgi?id=25101>
715725
716726GDB can not display structures (e.g. class) with dyn array inside
717727
718728DWARF 3
719729
720730<https://sourceware.org/bugzilla/show_bug.cgi?id=25102>
721731
722732GDB crash on ^AnsiString
723733
724734DWARF 3
725735
726736<https://sourceware.org/bugzilla/show_bug.cgi?id=25103>
727737
728738### Issues with GDB 7.5.9 or 7.6
729739
730740There are various reports (not confirmed) for different platforms about crashes in gdb 7.5.9 or 7.6.
731741
732742It is highly recommended not to use those versions.
733743
734744- <http://bugs.freepascal.org/view.php?id=24401>
735745- <http://forum.lazarus.freepascal.org/index.php/topic,20756.msg120842.html#msg120842>
736746- <http://sourceware.org/bugzilla/show_bug.cgi?id=15453>
737747
738748### Create a new Report (GDB and LLDB)
739749
740750If you have at any time in the past updated, changed, reinstalled your Lazarus then please check the "Options" dialog ("Environment" or "Tools" Menu) for the version of GDB and FPC used. They may still point to old settings.
741751
742752#### Basic Information
743753
744754- Your Operating system and Version
745755- Your CPU (Intel, Power, ...) 32 or 64 bit
746756- Version of
747757 - Lazarus (Latest Release or SVN revision) (Include setting used to recompile LCL, packages or IDE (if a custom compile Lazarus is used))
748758 - FPC, if different from default. Please check the "Options" dialog ("Environment" or "Tools" Menu)
749759 - GDB, please check the "Options" dialog ("Environment" or "Tools" Menu)
750760- Compiler Settings: (Menu: "Project", "Project Options", indicate all settings you used )
751761 - Page "Code generation"
752762
753763
754764
755765Optimization settings (-O???): Level (-O1 / ...) Other (-OR -Ou -Os) (Please always test with all optimizations disabled, and -O1)
756766
757767#### Log info for debug session
758768
759769
760770Start Lazarus with the following options:
761771
762-` --debug-log=LOG_FILE  --debug-enable=DBG_CMD_ECHO,DBG_STATE,DBG_DATA_MONITORS,DBGMI_QUEUE_DEBUG,DBGMI_TYPE_INFO,DBG_ERRORS`
772+```text
773+ --debug-log=LOG_FILE --debug-enable=DBG_CMD_ECHO,DBG_STATE,DBG_DATA_MONITORS,DBGMI_QUEUE_DEBUG,DBGMI_TYPE_INFO,DBG_ERRORS
774+```
763775
764776:;On Windows: you need to create a shortcut to the Lazarus exe (like the one on Desktop) and edit it's properties. Add " --debug-log=C:\laz.log --debug-enable=..." to the command line.
765777
766778:;On Linux: start Lazarus from a shell and append " --debug-log=/home/yourname/laz.log --debug-enable=..." to the command line
767779
768780:;On Mac/OSX:start Lazarus from a shell /path/to/lazarus/lazarus.app/Contents/MacOS/lazarus --debug-log=/path/to/yourfiles/laz.log --debug-enable=...
769781
770782Attach the log file after reproducing the error.
771783
772784If you cannot generate a log file, you may try to open the "Debug output" window (from menu "View" -\> "Ide Internals").You must open this before you run your app (F9). And then run your app. Once the error occurs, copy, zip, and attach the content of the "debug output" window.
773785
774786## Running the test-case
775787
776788If you run a different version of GDB you may want to run the test case. Please note, that not all tests have yet the correct expectations for each possible setup. Therefore some tests may fail on some systems.
777789
778790The debugger test are in the directory:
779791
780792- Lazarus 1.2.x: debugger\test\Gdbmi\\
781793- Lazarus 1.3 and up: components\lazdebuggergdbmi\test\\
782794
783795In the below the 1.3 path is used. If using 1.2.x substitute as appropriate.
784796
785797One time setup
786798
787799Create directory components\lazdebuggergdbmi\test\Logs: Optional, but helps keeping test result in one place
788800
789801Create config files: in components\lazdebuggergdbmi\test\\
790802
791803
792804copy fpclist.txt.sample to fpclist.txt
793805
794806copy gdblist.txt.sample to gdblist.txt
795807
796808open the 2 txt files and edit the path to fpc/gdb, also edit the version (the test may run different test, for different versions). It is possible to specify more than one gdb/fpc
797809
798810Running the test
799811
800812- Open project: components\lazdebuggergdbmi\test\TestGdbmi.lpi
801813- Lazarus 1.2.x only: Rebuild the IDE with option "Clean" (Menu Tools: "Configure build IDE" / Restart is not needed). If this is skipped, compilation of the project may fail. Once compilation failed, ALL *.ppu/*.o files in debugger\test must be deleted by hand.
802814- Run the project (If a test failed, you may have to delete *.exe files in components\lazdebuggergdbmi\test\TestApps
803815
804816See also [[Lazarus Debugger Implementation|Lazarus Debugger Implementation#Testcases (Backend)]]
805817
806818## Links
807819
808820### External Links
809821
810822- [Official GDB site](https://www.gnu.org/software/gdb/)
811823
812824### Experimental Debuggers in Pascal
813825
814826Those are work in progress:
815827
816828- <http://sourceforge.net/projects/duby/>
817829- <https://github.com/graemeg/fpdebug>
818830- [[FpDebug]] in Lazarus/components/fpdebug and debugger/components/fpgdbmidebugger [blog](http://lazarus-dev.blogspot.co.uk/2014/05/de-bug-wars-new-hope.html) [[FpGdbmiDebugger]], LazDebuggerFpLldb and LazDebuggerFP
819831
820832- <http://forum.lazarus.freepascal.org/index.php/topic,22252.0.html>
821833
822834### Related forum topics
823835
824836- [Issues (crash) with gdb 7.6.2 on arch linux](http://forum.lazarus.freepascal.org/index.php/topic,23221.0.html)
825837- [About the LLDB based debugger](https://forum.lazarus.freepascal.org/index.php/topic,42869.0.html)
826838
827839---
828840*From the Free Pascal wiki, page "GDB Debugger Tips", as it stood on 2022-05-28 after a change by Trev, 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).*
829841Category: Debugging

Back to history