microsoft / vscode-cpptools

Official repository for the Microsoft C/C++ extension for VS Code.
Other
5.51k stars 1.55k forks source link

when i use vscode,if i use <vector> ,i can't debug the program #1372

Closed dreamtomb closed 6 years ago

dreamtomb commented 6 years ago

hello,when i use vscode,if i use vector ,i can't debug the program . i use windows 10, i use vscode 1.19.1,c/c++0.14.5, here is my launch.json: { "version": "0.2.0", "configurations": [ { "name": "(gdb) Launch", "type": "cppdbg", "request": "launch", "program": "${file}.exe", "args": [], "stopAtEntry": false, "cwd": "${fileDirname}", "environment": [], "externalConsole": true, "MIMode": "gdb", "miDebuggerPath": "C:/MinGW/bin/gdb.exe", "setupCommands": [ { "description": "Enable pretty-printing for gdb", "text": "-enable-pretty-printing", "ignoreFailures": true } ], "preLaunchTask": "task1" } ] }
and here is my tasks.json: { "version": "2.0.0", "tasks": [ { "label": "task1", "type": "shell", "command": "g++", "args": [ "-g","-Wall","-std=c++11","${file}","-o","${file}.exe" ], "group": { "kind": "build", "isDefault": true } } ] } and here is my program: `#include

include

using namespace std; int main(){ vector v; for(int i=0;i<10;i++){ v.push_back(i); } for(int i=0;i<10;i++){ cout<<v.at(i)<<endl; } system("pause"); }`

then only when i use vector and press F5,i can't debug. what should i do?thank you very much!

pieandcakes commented 6 years ago

@dreamtomb Are you saying that if you remove vector<int> v and the references to v, it will run? Are you sure that your compilation step isn't failing?

dreamtomb commented 6 years ago

@pieandcakes thank you for your reply。 That was almost right.I mean that if i don't use Vector ,my program can run and the cmd window is displayed normally,but if i use Vector(or stack),the program can't run and the cmd window appear and disappear soon .And it shows that =thread-group-added,id="i1" GNU gdb (GDB) 7.6.1 Copyright (C) 2013 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 "mingw32". For bug reporting instructions, please see: <http://www.gnu.org/software/gdb/bugs/>. =cmd-param-changed,param="pagination",value="off" [New Thread 10920.0x2f9c] [New Thread 10920.0x3fe8] [New Thread 10920.0x116c] [New Thread 10920.0x1c90] ERROR: During startup program exited with code 0xc0000139. Do you know what should i do?Thank you sincerely。

pieandcakes commented 6 years ago

can you see if compilation generated an error?

pieandcakes commented 6 years ago

Also, which version of mingw are you using?

dreamtomb commented 6 years ago

@pieandcakes sorry,what should i do for your first question? And this is my mingw version : gcc version 6.3.0 (MinGW.org GCC-6.3.0-1)

pieandcakes commented 6 years ago

@dreamtomb can you see if you can get a newer version of MinGW? I can't duplicate your problem so i'm wondering if it is a toolset version issue:

g++ --version g++ (x86_64-posix-seh-rev0, Built by MinGW-W64 project) 7.1.0 Copyright (C) 2017 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.

gdb --version GNU gdb (GDB) 7.11.1 Copyright (C) 2016 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later http://gnu.org/licenses/gpl.html

dreamtomb commented 6 years ago

@pieandcakes sorry,this time i update the mingw,and it didn't help. it shows : =thread-group-added,id="i1" GNU gdb (GDB) 8.0.1 Copyright (C) 2017 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 "i686-w64-mingw32". 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". =cmd-param-changed,param="pagination",value="off" [New Thread 9952.0x3588] [New Thread 9952.0x2ca4] [New Thread 9952.0x44b8] [New Thread 9952.0x14bc] [Thread 9952.0x44b8 exited with code 3221225785] [Thread 9952.0x14bc exited with code 3221225785] ERROR: Unable to start debugging. GDB exited unexpectedly.

pieandcakes commented 6 years ago

After you update, did you recompile? Can you enable logging and see if we get more information? Add "logging": { "engineLogging": true } to your launch.json

dreamtomb commented 6 years ago

@pieandcakes it shows this: 1: (171) LaunchOptions<LocalLaunchOptions xmlns='http://schemas.microsoft.com/vstudio/MDDDebuggerOptions/2014' 1: (182) LaunchOptions ExePath='f:\c_plusplus_project\PAT_and_postgraduate\PAT\B_level\1002\main.cpp.exe' 1: (182) LaunchOptions WorkingDirectory='f:\c_plusplus_project\PAT_and_postgraduate\PAT\B_level\1002' 1: (182) LaunchOptions ExeArguments='' 1: (182) LaunchOptions MIMode='gdb' 1: (182) LaunchOptions MIDebuggerPath='C:/MinGW/mingw32/bin/gdb.exe' 1: (182) LaunchOptions WaitDynamicLibLoad='false' 1: (182) LaunchOptions ExternalConsole='true' 1: (182) LaunchOptions> 1: (182) LaunchOptions 1: (182) LaunchOptions -enable-pretty-printing 1: (182) LaunchOptions 1: (182) LaunchOptions 1: (227) Starting: "C:/MinGW/mingw32/bin/gdb.exe" --interpreter=mi 1: (242) DebuggerPid=12972 1: (433) ->=thread-group-added,id="i1" 1: (436) ->~"GNU gdb (GDB) 8.0.1\n" 1: (436) ->~"Copyright (C) 2017 Free Software Foundation, Inc.\n" 1: (436) ->~"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. Type \"show copying\"\nand \"show warranty\" for details.\n" 1: (436) ->~"This GDB was configured as \"i686-w64-mingw32\".\nType \"show configuration\" for configuration details." 1: (436) ->~"\nFor bug reporting instructions, please see:\n" 1: (436) ->~"http://www.gnu.org/software/gdb/bugs/.\n" 1: (436) ->~"Find the GDB manual and other documentation resources online at:\nhttp://www.gnu.org/software/gdb/documentation/.\n" 1: (470) ->^done 1: (470) ->(gdb) 1: (471) 1001: elapsed time 10 1: (481) <-1002-enable-pretty-printing 1: (491) ->1002^done 1: (491) ->(gdb) 1: (491) 1002: elapsed time 10 1: (491) <-1003-interpreter-exec console "set pagination off" 1: (491) ->&"\n" 1: (491) ->^done 1: (491) ->(gdb) 1: (501) ->=cmd-param-changed,param="pagination",value="off" 1: (501) ->1003^done 1: (501) 1003: elapsed time 10 1: (501) ->(gdb) 1: (501) ->&"\n" 1: (501) ->^done 1: (501) ->(gdb) 1: (501) <-1004-gdb-set solib-search-path f:\c_plusplus_project\PAT_and_postgraduate\PAT\B_level\1002; 1: (511) ->1004^done 1: (511) ->(gdb) 1: (511) 1004: elapsed time 10 1: (511) ->&"\n" 1: (511) ->^done 1: (511) ->(gdb) 1: (511) <-1005-environment-cd f:\c_plusplus_project\PAT_and_postgraduate\PAT\B_level\1002 1: (522) ->1005^done 1: (522) ->(gdb) 1: (522) 1005: elapsed time 10 1: (522) <-1006-gdb-set new-console on 1: (523) ->&"\n" 1: (523) ->^done 1: (523) ->(gdb) 1: (524) ->1006^done 1: (524) ->(gdb) 1: (524) ->&"\n" 1: (524) ->^done 1: (524) ->(gdb) 1: (524) 1006: elapsed time 2 1: (529) <-1007-interpreter-exec console "show configuration" 1: (534) ->~"This GDB was configured as follows:\n configure --host=i686-w64-mingw32 --target=i686-w64-mingw32\n" 1: (534) ->~" --with-auto-load-dir=$debugdir:$datadir/auto-load\n --with-auto-load-safe-path=$debugdir:$datadir/auto-load\n" 1: (534) ->~" --with-expat\n" 1: (534) ->~" --with-gdb-datadir=/c/mingw720/i686-720-posix-dwarf-rt_v5-rev1/mingw32/share/gdb (relocatable)\n" 1: (534) ->~" --with-jit-reader-dir=/c/mingw720/i686-720-posix-dwarf-rt_v5-rev1/mingw32/lib/gdb (relocatable)\n" 1: (535) ->~" --without-libunwind-ia64\n" 1: (535) ->~" --without-lzma\n" 1: (535) ->~" --with-python=/c/mingw720/i686-720-posix-dwarf-rt_v5-rev1/mingw32/opt (relocatable)\n" 1: (535) ->~" --without-guile\n" 1: (535) ->~" --with-separate-debug-dir=/c/mingw720/i686-720-posix-dwarf-rt_v5-rev1/mingw32/lib/debug (relocatable)\n" 1: (535) ->~" --with-system-gdbinit=/c/mingw720/i686-720-posix-dwarf-rt_v5-rev1/mingw32/etc/gdbinit (relocatable)\n" 1: (535) ->~" --without-babeltrace\n" 1: (535) ->~"\n(\"Relocatable\" means the directory can be moved with the GDB installation\ntree, and GDB will still find it.)\n" 1: (535) ->1007^done 1: (535) ->(gdb) 1: (535) 1007: elapsed time 6 1: (535) ->&"\n" 1: (535) ->^done 1: (535) ->(gdb) 1: (541) <-1008-file-exec-and-symbols f:\c_plusplus_project\PAT_and_postgraduate\PAT\B_level\1002\main.cpp.exe 1: (556) ->1008^done 1: (556) ->(gdb) 1: (556) 1008: elapsed time 15 1: (556) <-1009-interpreter-exec console "show architecture" 1: (556) ->&"\n" 1: (556) ->^done 1: (556) ->(gdb) 1: (557) ->~"The target architecture is set automatically (currently i386)\n" 1: (557) ->1009^done 1: (557) ->(gdb) 1: (557) 1009: elapsed time 1 1: (557) ->&"\n" 1: (557) ->^done 1: (557) ->(gdb) 1: (558) <-1010-break-insert main 1: (567) ->1010^done,bkpt={number="1",type="breakpoint",disp="keep",enabled="y",addr="0x00401617",func="main()",file="f:\c_plusplus_project\PAT_and_postgraduate\PAT\B_level\1002\main.cpp",fullname="f:\c_plusplus_project\PAT_and_postgraduate\PAT\B_level\1002\main.cpp",line="24",thread-groups=["i1"],times="0",original-location="main"} 1: (567) ->(gdb) 1: (568) ->&"\n" 1: (568) ->^done 1: (568) ->(gdb) 1: (573) 1010: elapsed time 15 =thread-group-added,id="i1" GNU gdb (GDB) 8.0.1 Copyright (C) 2017 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 "i686-w64-mingw32". 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". =cmd-param-changed,param="pagination",value="off" 1: (1019) <-1011-exec-run 1: (1052) ->=thread-group-started,id="i1",pid="15220" 1: (1053) ->=thread-created,id="1",group-id="i1" 1: (1053) ->~"[New Thread 15220.0x17a8]\n" 1: (1064) <-1012-thread-info 1 [New Thread 15220.0x17a8] 1: (1148) ->=thread-created,id="2",group-id="i1" 1: (1148) <-1013-thread-info 2 1: (1149) ->~"[New Thread 15220.0x28d0]\n" [New Thread 15220.0x28d0] 1: (1149) ->=thread-created,id="3",group-id="i1" 1: (1150) <-1014-thread-info 3 1: (1150) ->~"[New Thread 15220.0x2e78]\n" 1: (1150) ->=thread-created,id="4",group-id="i1" 1: (1150) ->~"[New Thread 15220.0x39cc]\n" [New Thread 15220.0x2e78] 1: (1150) <-1015-thread-info 4 [New Thread 15220.0x39cc] 1: (1154) ->~"[Thread 15220.0x2e78 exited with code 3221225785]\n" [Thread 15220.0x2e78 exited with code 3221225785] 1: (1154) ->=thread-exited,id="3",group-id="i1" 1: (1154) ->~"[Thread 15220.0x39cc exited with code 3221225785]\n" 1: (1154) ->=thread-exited,id="4",group-id="i1" [Thread 15220.0x39cc exited with code 3221225785] 1: (1165) ->=thread-exited,id="1",group-id="i1" 1: (1165) ->=thread-exited,id="2",group-id="i1" 1: (1165) ->=thread-group-exited,id="i1" 1: (1171) ->1011^error,msg="During startup program exited with code 0xc0000139." 1: (1171) ->(gdb) 1: (1201) ->&"\n" 1: (1202) ->^done 1: (1202) ->(gdb) 1: (1202) ->1012^done,threads=[] 1: (1202) ->(gdb) 1: (1202) ->&"\n" 1: (1203) ->^done 1: (1203) ->(gdb) 1: (1203) ->1013^done,threads=[] 1: (1203) ->(gdb) 1: (1203) ->&"\n" 1: (1203) ->^done 1: (1203) ->(gdb) 1: (1203) ->1014^done,threads=[] 1: (1203) ->(gdb) 1: (1203) ->&"\n" 1: (1203) ->^done 1: (1203) ->(gdb) 1: (1204) ->1015^done,threads=[] 1: (1204) ->(gdb) 1: (1204) ->&"\n" 1: (1204) ->^done 1: (1204) ->(gdb) 1: (1208) <-logout ERROR: Unable to start debugging. GDB exited unexpectedly. The program 'f:\c_plusplus_project\PAT_and_postgraduate\PAT\B_level\1002\main.cpp.exe' has exited with code 0 (0x00000000).

ERROR: During startup program exited with code 0xc0000139. 1: (1266) <--gdb-exit

pieandcakes commented 6 years ago

I see gdb gives us: 1: (1171) ->1011^error,msg="During startup program exited with code 0xc0000139."

Searching online, it shows that gdb can't find the entrypoint of some library code which seems to be an issue where your compiler doesn't match your debugger. If you are using MinGW's gdb to compile, you need to make 100% sure you are also using the same g++ to compile your code, else it looks like you get this message.

dreamtomb commented 6 years ago

@pieandcakes sorry,i am a beginner,and i just tried a simple loop,and i find that it can run and debug.so what should i do to make my gdb and g++ same?

pieandcakes commented 6 years ago

Did you recompile after you updated MinGW using specifically the g++ that is in the MinGW toolset? Provide the full path to g++ when you are compiling. Can you make sure you can run the app from the command line after you have done that and make sure it will run? Then try again.

dreamtomb commented 6 years ago

Thank you for your help.

pieandcakes commented 6 years ago

Did that work?

dreamtomb commented 6 years ago

@pieandcakes yes,it finally works.Thank you very much.

TheTomer commented 3 years ago

I'm having a similar issue to the one reported in this thread, but not only with vector, but also with string or map for example.

I've made sure that I'm compiling and debugging g++ and gdb of the same mingw version, but the program would still not debug whenever I try to use one of these standard libraries... any advice?

tasks.json:

{ "version": "2.0.0", "tasks": [ { "type": "shell", "label": "C/C++: g++.exe build active file", "command": "C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\bin\g++.exe", "args": [ "-g", "${file}", "-o", "${fileDirname}\${fileBasenameNoExtension}.exe" ], "options": { "cwd": "${workspaceFolder}" }, "problemMatcher": [ "$gcc" ], "group": { "kind": "build", "isDefault": true } } ] }

launch.json:

{ // Use IntelliSense to learn about possible attributes. // Hover to view descriptions of existing attributes. // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ { "name": "g++.exe - Build and debug active file", "type": "cppdbg", "request": "launch", "program": "${fileDirname}\${fileBasenameNoExtension}.exe", "args": [], "stopAtEntry": false, "cwd": "${workspaceFolder}", "environment": [], "externalConsole": false, "MIMode": "gdb", "miDebuggerPath": "C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\bin\gdb.exe", "setupCommands": [ { "description": "Enable pretty-printing for gdb", "text": "-enable-pretty-printing", "ignoreFailures": true } ], "preLaunchTask": "C/C++: g++.exe build active file", // "logging": { "engineLogging": true } } ] }

kaushikkumarbora commented 3 years ago

If anyone is still searching for a solution, follow this guide. It solved all debugging problems for me.

ualibek commented 1 year ago

For me creating a new workspace worked somehow.