Debugging - GDB tricks: what changed
Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.
Title: Debugging - GDB tricks
| Old | New | Line | |
|---|---|---|---|
| 1 | + | # General tricks | |
| 2 | + | ||
| 3 | + | - Some pascal specific patches were accepted into [[GDB]], so if possible set language to pascal "set language pascal" | |
| 4 | + | - To get help, use "help \<command\>" or "help" to see a category list. | |
| 5 | + | - To view datastructures in their raw form, use the "x" command (see "help x") | |
| 6 | + | ||
| 7 | + | ## Examining Type Info | |
| 8 | + | ||
| 9 | + | - Q: What function should I use for dumping the type info? | |
| 10 | + | - A: Run x/100c in gdb until it frames. then use 'frame \<framenr\>' to jump to the correct frame | |
| 11 | + | ||
| 12 | + | ## Inspecting an ansistring | |
| 13 | + | ||
| 14 | + | - Q: How do I examine an ansistring? | |
| 15 | + | - A: "x/s \<stringname\>" | |
| 16 | + | ||
| 17 | + | ## Stop debugger on exception | |
| 18 | + | ||
| 19 | + | - Q: How to stop gdb on exception? | |
| 20 | + | - A: b fpc_raiseexception | |
| 21 | + | ||
| 22 | + | - Q: How to stop gdb on assert, and have a backtrace? | |
| 23 | + | - A: b fpc_assert | |
| 24 | + | ||
| 25 | + | - Q: How to show call stack/backtrace? | |
| 26 | + | - A: bt | |
| 27 | + | ||
| 28 | + | ## Work with breakpoints | |
| 29 | + | ||
| 30 | + | - Add: b TObject__Method or b filename.pas:123 | |
| 31 | + | - Show: inf b | |
| 32 | + | - Disable: dis 1 | |
| 33 | + | - Enble: en 1 | |
| 34 | + | - Delete: d 1 | |
| 35 | + | - Delete all: d b | |
| 36 | + | ||
| 37 | + | ## Pointer | |
| 38 | + | ||
| 39 | + | When you print the value of a pointer gdb will say something like: | |
| 40 | + | ||
| 41 | + | ` $0 = (MYPTR) 0x0202` | |
| 42 | + | ||
| 43 | + | If MYPTR is the correct type, you can just use | |
| 44 | + | ||
| 45 | + | ` p ptrvar^` | |
| 46 | + | ||
| 47 | + | if it's not the correct type, you can typecast it: | |
| 48 | + | ||
| 49 | + | ` p realptrtype(ptrvar)^` | |
| 50 | + | ||
| 51 | + | If you do not have a separate type for the actual pointer type, but only a type for what it points to, then the syntax is somewhat awkward because the gdb parser is still showing its C heritage in that case: | |
| 52 | + | ||
| 53 | + | ` p ^myvartype(ptrvar)^` | |
| 54 | + | ||
| 55 | + | ## Accessing a symbol in a specific unit unitname.identifier | |
| 56 | + | ||
| 57 | + | If you have several global variables of the same name in different units, GDB will *not* follow pascal scoping rules, but pick whatever it finds first. So you need to specify which one you want. | |
| 58 | + | ||
| 59 | + | GDB does not know the unitname.ident syntax. But it can instead take the filename of a unit. (filenames with a dot must be in single quotes) | |
| 60 | + | ||
| 61 | + | `'unit1.pas'::form1` | |
| 62 | + | ||
| 63 | + | --- | |
| 64 | + | *From the Free Pascal wiki, page "Debugging - GDB tricks", as it stood on 2020-08-20 after a change by Mnalis, 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).* | |
| 65 | + | Category: Debugging |
