Open ferdinandhubbard981 opened 2 years ago
Can you add the following to your launch.json and share the output in the Debug Console?
"logging": {
"engineLogging": true
}
On a side note, there is a known issue of the layout information of symbols that clang produces that GDB does not know how to visualize with its pretty printers.
Pretty printing with g++
compiled binaries should visualize strings correctly.
The problem persists. I have changed -my tasks.json file to use g++ instead of clang -my launch.json file to enable logging
screenshot of debugging:
tasks.json:
{
"version": "2.0.0",
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++ build active file",
"command": "/usr/bin/g++",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "compiler: /usr/bin/g++"
}
]
}
launch.json:
{
"version": "0.2.0",
"configurations": [
{
"name": "g++ - Build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}",
"args": [],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "C/C++: g++ build active file",
"miDebuggerPath": "/usr/bin/gdb",
"logging": {
"engineLogging": true
}
}
]
}
Debug Console output:
1: (94) LaunchOptions{"name":"clang - Build and debug active file","type":"cppdbg","request":"launch","program":"/home/ferdi/soexample/main","args":[],"stopAtEntry":false,"cwd":"/home/ferdi/soexample","environment":[],"externalConsole":false,"MIMode":"gdb","setupCommands":[{"description":"Enable pretty-printing for gdb","text":"-enable-pretty-printing","ignoreFailures":true}],"preLaunchTask":"C/C++: g++ build active file","miDebuggerPath":"/usr/bin/gdb","logging":{"engineLogging":true},"__configurationTarget":5,"__sessionId":"f54d736a-9475-4b7d-9e82-e083a426850a"}
1: (170) DbgCmd:echo $$ > /tmp/Microsoft-MIEngine-Pid-v5ey3dj2.pk4 ; cd "/home/ferdi/soexample" ; DbgTerm=`tty` ; set -o monitor ; trap 'rm "/tmp/Microsoft-MIEngine-In-2dcpefv4.tio" "/tmp/Microsoft-MIEngine-Out-hgiljpab.n25" "/tmp/Microsoft-MIEngine-Pid-v5ey3dj2.pk4" "/tmp/Microsoft-MIEngine-Cmd-ok5aw2df.0fj"' EXIT ; "/usr/bin/gdb" --interpreter=mi --tty=$DbgTerm < "/tmp/Microsoft-MIEngine-In-2dcpefv4.tio" > "/tmp/Microsoft-MIEngine-Out-hgiljpab.n25" & clear; pid=$! ; echo $pid > "/tmp/Microsoft-MIEngine-Pid-v5ey3dj2.pk4" ; wait $pid;
1: (185) Wait for connection completion.
1: (812) ->=thread-group-added,id="i1"
1: (813) ->~"GNU gdb (Ubuntu 9.2-0ubuntu1~20.04) 9.2\n"
1: (813) ->~"Copyright (C) 2020 Free Software Foundation, Inc.\n"
1: (813) ->~"License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>\nThis is free software: you are free to change and redistribute it.\nThere is NO WARRANTY, to the extent permitted by law."
1: (813) ->~"\nType \"show copying\" and \"show warranty\" for details.\n"
1: (814) ->~"This GDB was configured as \"x86_64-linux-gnu\".\n"
1: (814) ->~"Type \"show configuration\" for configuration details.\n"
1: (814) ->~"For bug reporting instructions, please see:\n"
1: (814) ->~"<http://www.gnu.org/software/gdb/bugs/>.\n"
1: (814) ->~"Find the GDB manual and other documentation resources online at:\n <http://www.gnu.org/software/gdb/documentation/>."
1: (814) ->~"\n\n"
1: (814) ->~"For help, type \"help\".\n"
1: (814) ->~"Type \"apropos word\" to search for commands related to \"word\".\n"
1: (835) ->(gdb)
1: (839) <-1001-gdb-set target-async on
1: (840) ->1001^done
1: (841) ->(gdb)
1: (844) 1001: elapsed time 6
1: (856) <-1002-enable-pretty-printing
1: (857) ->1002^done
1: (857) ->(gdb)
1: (857) 1002: elapsed time 1
1: (857) <-1003-interpreter-exec console "set pagination off"
1: (860) ->=cmd-param-changed,param="pagination",value="off"
1: (860) ->1003^done
1: (860) ->(gdb)
1: (860) 1003: elapsed time 2
1: (860) <-1004-gdb-set auto-solib-add on
1: (861) ->1004^done
1: (862) ->(gdb)
1: (862) 1004: elapsed time 1
1: (862) <-1005-gdb-set solib-search-path /home/ferdi/soexample:
1: (863) ->1005^done
1: (864) ->(gdb)
1: (864) 1005: elapsed time 1
1: (864) <-1006-gdb-set stop-on-solib-events 1
1: (865) ->1006^done
1: (865) ->(gdb)
1: (865) 1006: elapsed time 1
1: (865) <-1007-environment-cd /home/ferdi/soexample
1: (867) ->1007^done
1: (867) ->(gdb)
1: (867) 1007: elapsed time 1
1: (867) <-1008-file-exec-and-symbols /home/ferdi/soexample/main
1: (876) ->1008^done
1: (876) ->(gdb)
1: (876) 1008: elapsed time 8
1: (878) <-1009-interpreter-exec console "show architecture"
1: (880) ->~"The target architecture is set automatically (currently i386:x86-64)\n"
1: (880) ->1009^done
1: (880) ->(gdb)
1: (880) 1009: elapsed time 2
1: (882) <-1010-break-insert -f main
1: (884) ->1010^done,bkpt={number="1",type="breakpoint",disp="keep",enabled="y",addr="0x0000000000001149",func="main()",file="/home/ferdi/soexample/main.c",fullname="/home/ferdi/soexample/main.c",line="3",thread-groups=["i1"],times="0",original-location="main"}
1: (884) ->(gdb)
1: (888) 1010: elapsed time 6
1: (894) Send Event AD7EngineCreateEvent
1: (897) Send Event AD7ProgramCreateEvent
1: (926) ShellPid=1712
1: (927) DebuggerPid=1715
1: (954) <-1011-break-insert -f main.c:5
1: (955) ->1011^done,bkpt={number="2",type="breakpoint",disp="keep",enabled="y",addr="0x000000000000116f",func="main()",file="/home/ferdi/soexample/main.c",fullname="/home/ferdi/soexample/main.c",line="6",thread-groups=["i1"],times="0",original-location="main.c:5"}
1: (955) ->(gdb)
1: (956) 1011: elapsed time 1
1: (964) <-1012-symbol-list-lines /home/ferdi/soexample/main.c
1: (966) ->1012^done,lines=[{pc="0x0000000000001149",line="3"},{pc="0x0000000000001155",line="3"},{pc="0x0000000000001164",line="4"},{pc="0x000000000000116f",line="6"},{pc="0x0000000000001174",line="7"},{pc="0x000000000000118a",line="0"}]
1: (966) ->(gdb)
1: (967) 1012: elapsed time 2
1: (973) Send Event AD7BreakpointBoundEvent
1: (1026) Send Event AD7LoadCompleteEvent
=thread-group-added,id="i1"
GNU gdb (Ubuntu 9.2-0ubuntu1~20.04) 9.2
Copyright (C) 2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word".
Warning: Debuggee TargetArchitecture not detected, assuming x86_64.
=cmd-param-changed,param="pagination",value="off"
1: (1028) <-1013-exec-run
1: (1031) ->=thread-group-started,id="i1",pid="1721"
1: (1031) ->=thread-created,id="1",group-id="i1"
1: (1035) <-1014-thread-info 1
1: (1212) ->=breakpoint-modified,bkpt={number="1",type="breakpoint",disp="keep",enabled="y",addr="0x0000000008001149",func="main()",file="/home/ferdi/soexample/main.c",fullname="/home/ferdi/soexample/main.c",line="3",thread-groups=["i1"],times="0",original-location="main"}
1: (1212) ->=breakpoint-modified,bkpt={number="2",type="breakpoint",disp="keep",enabled="y",addr="0x000000000800116f",func="main()",file="/home/ferdi/soexample/main.c",fullname="/home/ferdi/soexample/main.c",line="6",thread-groups=["i1"],times="0",original-location="main.c:5"}
1: (1213) ->=library-loaded,id="/lib64/ld-linux-x86-64.so.2",target-name="/lib64/ld-linux-x86-64.so.2",host-name="/lib64/ld-linux-x86-64.so.2",symbols-loaded="0",thread-group="i1",ranges=[{from="0x00007fffff7b1100",to="0x00007fffff7d3674"}]
1: (1216) <-1015-symbol-list-lines /home/ferdi/soexample/main.c
1: (1217) ->1013^running
1: (1217) ->*running,thread-id="all"
1: (1217) ->(gdb)
1: (1217) 1013: elapsed time 189
1: (1218) ->~"Stopped due to shared library event (no libraries added or removed)\n"
1: (1218) ->*stopped,reason="solib-event",thread-id="1",stopped-threads="all",core="0"
1: (1219) ->1014^done,threads=[{id="1",target-id="process 1721",name="main",frame={level="0",addr="0x00007fffff7b3fd1",func="??",args=[],from="/lib64/ld-linux-x86-64.so.2",arch="i386:x86-64"},state="stopped",core="0"}]
1: (1219) ->(gdb)
Stopped due to shared library event (no libraries added or removed)
1: (1220) ->1015^done,lines=[{pc="0x0000000008001149",line="3"},{pc="0x0000000008001155",line="3"},{pc="0x0000000008001164",line="4"},{pc="0x000000000800116f",line="6"},{pc="0x0000000008001174",line="7"},{pc="0x000000000800118a",line="0"}]
1: (1220) ->(gdb)
1: (1223) 1014: elapsed time 187
1: (1225) Send Event AD7ProcessInfoUpdatedEvent
1: (1232) Send Event AD7ThreadCreateEvent
1: (1237) 1015: elapsed time 21
1: (1237) <-1016-interpreter-exec console "shell echo -e \\\\033c 1>&2"
1: (1239) Send Event AD7BreakpointUnboundEvent
1: (1239) Send Event AD7BreakpointBoundEvent
1: (1244) ->1016^done
1: (1245) ->(gdb)
1: (1245) 1016: elapsed time 7
1: (1245) <-1017-gdb-set stop-on-solib-events 0
1: (1246) ->1017^done
1: (1246) ->(gdb)
1: (1246) 1017: elapsed time 1
1: (1251) <-1018-interpreter-exec console "info sharedlibrary"
1: (1253) ->~"From To Syms Read Shared Object Library\n"
1: (1253) ->~"0x00007fffff7b1100 0x00007fffff7d3674 Yes /lib64/ld-linux-x86-64.so.2\n"
1: (1254) ->1018^done
1: (1254) ->(gdb)
1: (1254) 1018: elapsed time 2
1: (1256) Send Event AD7ModuleLoadEvent
Loaded '/lib64/ld-linux-x86-64.so.2'. Symbols loaded.
1: (1281) <--exec-continue
1: (1282) ->^running
1: (1282) ->*running,thread-id="all"
1: (1282) ->(gdb)
1: (1285) ->=library-loaded,id="/lib/x86_64-linux-gnu/libc.so.6",target-name="/lib/x86_64-linux-gnu/libc.so.6",host-name="/lib/x86_64-linux-gnu/libc.so.6",symbols-loaded="0",thread-group="i1",ranges=[{from="0x00007fffff5c5630",to="0x00007fffff73a20d"}]
1: (1414) ->=breakpoint-modified,bkpt={number="1",type="breakpoint",disp="keep",enabled="y",addr="0x0000000008001149",func="main()",file="/home/ferdi/soexample/main.c",fullname="/home/ferdi/soexample/main.c",line="3",thread-groups=["i1"],times="1",original-location="main"}
1: (1414) ->~"\n"
1: (1414) ->~"Breakpoint 1, main () at /home/ferdi/soexample/main.c:3\n"
Breakpoint 1, main () at /home/ferdi/soexample/main.c:3
1: (1415) ->~"3\tint main() {\n"
1: (1415) ->*stopped,reason="breakpoint-hit",disp="keep",bkptno="1",frame={addr="0x0000000008001149",func="main",args=[],file="/home/ferdi/soexample/main.c",fullname="/home/ferdi/soexample/main.c",line="3",arch="i386:x86-64"},thread-id="1",stopped-threads="all",core="0"
3 int main() {
1: (1429) <-1019-thread-info
1: (1430) ->1019^done,threads=[{id="1",target-id="process 1721",name="main",frame={level="0",addr="0x0000000008001149",func="main",args=[],file="/home/ferdi/soexample/main.c",fullname="/home/ferdi/soexample/main.c",line="3",arch="i386:x86-64"},state="stopped",core="0"}],current-thread-id="1"
1: (1430) ->(gdb)
1: (1432) 1019: elapsed time 2
1: (1435) <-1020-interpreter-exec console "info sharedlibrary"
1: (1436) ->~"From To Syms Read Shared Object Library\n"
1: (1436) ->~"0x00007fffff7b1100 0x00007fffff7d3674 Yes /lib64/ld-linux-x86-64.so.2\n"
1: (1437) ->~"0x00007fffff5c5630 0x00007fffff73a20d Yes /lib/x86_64-linux-gnu/libc.so.6\n"
1: (1437) ->1020^done
1: (1437) ->(gdb)
1: (1437) 1020: elapsed time 2
1: (1437) Send Event AD7ModuleLoadEvent
Loaded '/lib/x86_64-linux-gnu/libc.so.6'. Symbols loaded.
1: (1441) <-1021-stack-list-frames 0 1000
1: (1442) ->1021^done,stack=[frame={level="0",addr="0x0000000008001149",func="main",file="/home/ferdi/soexample/main.c",fullname="/home/ferdi/soexample/main.c",line="3",arch="i386:x86-64"}]
1: (1442) ->(gdb)
1: (1443) 1021: elapsed time 1
1: (1448) <-1022-break-delete 1
1: (1449) ->1022^done
1: (1449) ->(gdb)
1: (1449) 1022: elapsed time 1
1: (1450) Send Event AD7EntryPointEvent
1: (1452) <--exec-continue
1: (1453) ->^running
1: (1453) ->*running,thread-id="all"
1: (1453) ->(gdb)
1: (1453) ->=breakpoint-modified,bkpt={number="2",type="breakpoint",disp="keep",enabled="y",addr="0x000000000800116f",func="main()",file="/home/ferdi/soexample/main.c",fullname="/home/ferdi/soexample/main.c",line="6",thread-groups=["i1"],times="1",original-location="main.c:5"}
1: (1453) ->~"\n"
1: (1453) ->~"Breakpoint 2, main () at /home/ferdi/soexample/main.c:6\n"
1: (1454) ->~"6\t return 0;\n"
1: (1454) ->*stopped,reason="breakpoint-hit",disp="keep",bkptno="2",frame={addr="0x000000000800116f",func="main",args=[],file="/home/ferdi/soexample/main.c",fullname="/home/ferdi/soexample/main.c",line="6",arch="i386:x86-64"},thread-id="1",stopped-threads="all",core="0"
Breakpoint 2, main () at /home/ferdi/soexample/main.c:6
6 return 0;
1: (1454) <-1023-stack-list-frames 0 1000
1: (1455) ->1023^done,stack=[frame={level="0",addr="0x000000000800116f",func="main",file="/home/ferdi/soexample/main.c",fullname="/home/ferdi/soexample/main.c",line="6",arch="i386:x86-64"}]
1: (1455) ->(gdb)
1: (1455) 1023: elapsed time 1
1: (1457) Send Event AD7BreakpointEvent
Execute debugger commands using "-exec <command>", for example "-exec info registers" will list registers in use (when GDB is the debugger)
1: (1500) <-1024-stack-list-arguments 0 0 0
1: (1501) ->1024^done,stack-args=[frame={level="0",args=[]}]
1: (1501) ->(gdb)
1: (1501) 1024: elapsed time 1
1: (2119) <-1025-stack-list-variables 0
1: (2120) ->1025^done,variables=[{name="str"}]
1: (2121) ->(gdb)
1: (2122) 1025: elapsed time 2
1: (2127) <-1026-var-create - * "str"
1: (2130) ->1026^done,name="var1",numchild="5",value="[5]",type="char [5]",thread-id="1",has_more="0"
1: (2130) ->(gdb)
1: (2130) 1026: elapsed time 3
-exec info locals
1: (25820) <-1027-interpreter-exec console "info locals"
1: (25822) ->~"str = \"test\"\n"
1: (25822) ->1027^done
1: (25822) ->(gdb)
1: (25822) 1027: elapsed time 2
str = "test"
1: (279568) <-1028-var-list-children --simple-values "var1" 0 1000
1: (279571) ->1028^done,numchild="5",children=[child={name="var1.0",exp="0",numchild="0",value="116 't'",type="char",thread-id="1"},child={name="var1.1",exp="1",numchild="0",value="101 'e'",type="char",thread-id="1"},child={name="var1.2",exp="2",numchild="0",value="115 's'",type="char",thread-id="1"},child={name="var1.3",exp="3",numchild="0",value="116 't'",type="char",thread-id="1"},child={name="var1.4",exp="4",numchild="0",value="0 '\\000'",type="char",thread-id="1"}],has_more="0"
1: (279571) ->(gdb)
1: (279571) 1028: elapsed time 2
I'm also facing this issue with GDB 11.2 on Arch Linux, with Code OSS 1.66.0
hey @ferdinandhubbard981 and @rubend056 I'm facing this issue as well, did one of you guys solve it?
Hello @WardenGnaw, the issue persists in Visual Studio Code 1.83.1 from Ubuntu 23.04 Snap Store (latest/stable) with latest version of GDB from Ubuntu repository: GNU gdb (Ubuntu 13.1-2ubuntu2) 13.1. vscode-cpptools: v1.17.5 (latest stable)
hey @ferdinandhubbard981 and @rubend056 I'm facing this issue as well, did one of you guys solve it?
I'm currently working on a project that uses cmake and pretty print is working fine. I'm not sure what fixed it. Might have something to do with your environment.
hey @ferdinandhubbard981 and @rubend056 I'm facing this issue as well, did one of you guys solve it?
I'm currently working on a project that uses cmake and pretty print is working fine. I'm not sure what fixed it. Might have something to do with your environment.
Hello @ferdinandhubbard981, are you sure your new project is set up to be debugged using cppdbg in conjunction with GDB? I would doubt that it is the basic configuration shared in this bug report what is defective.
i'm also facing this issue with clang at MAC OS.
Apple clang version 15.0.0 (clang-1500.0.40.1)
Target: arm64-apple-darwin23.0.0
Thread model: posix
I found two ways to make it work on my system (Alpine Linux). It seems that the its gdb package is built without setting --with-system-gdbinit
or any variant which would allow the system to make gdb always load a couple of scripts during its initialization, scripts that could execute the commands you will see below. So you end up with two choices: create a ~.gdbinit
file or add two more gdb commands to vscode launch.json
file
using ~.gdbinit
create a file named .gdbinit
in your home dir containing the following commands, adjusting the directory to where the libstdcxx
printers.py
is located in your system. In my case they are in /usr/share/gcc-13.2.1/python/libstdcxx/v6
, so I set the directory to /usr/share/gcc-13.2.1/python
python
import sys
sys.path.insert(0, '/usr/share/gcc-13.2.1/python')
from libstdcxx.v6.printers import register_libstdcxx_printers
register_libstdcxx_printers (None)
end
editing vscode launch.json
add two extra commands to the setupCommands
entry in your launch.json
file: add-auto-load-safe-path
add-auto-load-scripts-directory
. Remember to change the directories to whatever the equivalent is in your system. It should look something like this
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
{
"description": "Set Disassembly Flavor to Intel",
"text": "-gdb-set disassembly-flavor intel",
"ignoreFailures": true
},
{
"description": "Without this, gdb won't load the scripts from this dir",
"text": "add-auto-load-safe-path /usr/share/gdb/python/auto-load"
},
{
"description": "Default directory where script that should be auto-loaded installed in my system. Without this, things like pretty-printing will not work",
"text": "add-auto-load-scripts-directory /usr/share/gdb/python/auto-load"
},
]
I believe you can also replace that script inside the ~.gdbinit
file by these two commands and it will also work.
The only thing left to do is to find a way to auto-detect the directories containing the auto-load scripts and do away with those hard-coded paths.
If I saved the day, and you are hiring, remember me. I'll work for pizza.
i'm also facing this at debian 12.
gcc (Debian 12.2.0-14) 12.2.0 Copyright (C) 2022 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
$ code --version 1.89.1 dc96b837cf6bb4af9cd736aa3af08cf8279f7685 x64
but in my case the pretty print doesn't work even if i input -exec info locals in debug console manually.
Bug type: Debugger
-GDB version: 9.2 (installed using "apt install gdb")
Description: Char arrays in c are not pretty-printed in vscode sidebar, but are pretty-printed when calling -exec info locals in the Debug Console (see at bottom of image).
Screenshot demonstrating error:![temp](https://user-images.githubusercontent.com/28741016/144596564-7d1bf766-8b04-47e2-a027-8c696e6adbd1.PNG)
To Reproduce launch.json:
tasks.json:
main.c: