microsoft / vscode-cpptools

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

Windows Debugging not stopping correctly against clang 6.0.0 compiled binaries #2217

Closed FancyBanana closed 6 years ago

FancyBanana commented 6 years ago

Type: Debugger

Describe the bug

I can't debug a binary compiled using clang 6.0.0 x32 with debug symbols. I tried using Windows debugger (i have VS Enterprise 15.7.4 installed). It can stop on entry, but ignores breakpoints and does not follow source code steps. Also GDB (mingw64 8.1.0 from here). Doesn't even stop on entry. LLDB also doesn't work, but i think it's mostly fault of LLVM, since in 6.0.0 lldb is build wihtout python scripting by default. (there is a corrected build, but it still does not help me).

Please include a code sample and launch.json configuration. main.cpp

#include <iostream>
using namespace std;
int main(int argc, char** argv){
    int a = 0;  
    for(int i = 0; i < 10; i++)
    {
        a = i*i - a;
        cout << a << endl; 
    }    
}

build command: clang --debug -Og -o main.exe -std=c++17 main.cpp

launch.json

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "(Windows) Launch",
            "type": "cppvsdbg",
            "request": "launch",
            "program": "${workspaceFolder}/main.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": false,
            "logging": { "engineLogging": true, "trace": true, "traceResponse": true }
        },
        {
            "name": "(gdb) Launch",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceFolder}/main.exe",
            "stopAtEntry": true,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "miDebuggerPath": "C:\\Program Files\\mingw-w64\\mingw\\mingw64\\bin\\gdb.exe",
            "logging": { "engineLogging": true, "trace": true, "traceResponse": true }
        },
        {
            "name": "(lldb) Launch",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceFolder}/main.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": true,
            "logging": { "engineLogging": true, "trace": true, "traceResponse": true },
            "MIMode": "lldb",
            "miDebuggerPath": "C:/Program Files (x86)/LLVM/bin/lldb-mi.exe",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ]
        },
    ]
}

Steps to reproduce the behavior:

  1. compile main.cpp into main.exe with --debug flag
  2. start debugger
  3. see the program complete execution without triggering any breakpoints.
  4. Bonus: it break on entry is set to true, stepping with f10 or f11 won't bring you to corresponding lines in source code.

logs for windows debugger

<- (E) {"seq":2,"type":"event","event":"output","body":{"category":"console","output":"-------------------------------------------------------------------\nYou may only use the C/C++ Extension for Visual Studio Code with\nVisual Studio Code, Visual Studio or Visual Studio for Mac software\nto help you develop and test your applications.\n-------------------------------------------------------------------\n"}}
-------------------------------------------------------------------
You may only use the C/C++ Extension for Visual Studio Code with
Visual Studio Code, Visual Studio or Visual Studio for Mac software
to help you develop and test your applications.
-------------------------------------------------------------------
<- (R) {"seq":4,"type":"response","request_seq":2,"success":true,"command":"launch"}
<- (E) {"seq":6,"type":"event","event":"initialized","body":{}}
-> (C) {"type":"response","seq":3,"command":"handshake","request_seq":1,"success":true,"body":{"signature":"714ZAuI1Y+n+uhkjLBPoUZ9sb/JHM2KGhF7i9LfIjs1zK4="}}
-> (C) {"command":"setBreakpoints","arguments":{"source":{"name":"main.cpp","path":"C:\\Users\\vharabari\\Documents\\projects\\test\\main.cpp"},"lines":[8,12,13],"breakpoints":[{"line":8},{"line":12},{"line":13}],"sourceModified":false},"type":"request","seq":4}
<- (R) {"seq":10,"type":"response","request_seq":4,"success":true,"command":"setBreakpoints","message":"","body":{"breakpoints":[{"id":1,"verified":false,"message":"The breakpoint is pending and will be resolved when debugging starts.","line":8},{"id":2,"verified":false,"message":"The breakpoint is pending and will be resolved when debugging starts.","line":12},{"id":3,"verified":false,"message":"The breakpoint is pending and will be resolved when debugging starts.","line":13}]}}
-> (C) {"command":"setFunctionBreakpoints","arguments":{"breakpoints":[]},"type":"request","seq":5}
<- (R) {"seq":13,"type":"response","request_seq":5,"success":true,"command":"setFunctionBreakpoints","message":"","body":{"breakpoints":[]}}
-> (C) {"command":"setExceptionBreakpoints","arguments":{"filters":[]},"type":"request","seq":6}
<- (R) {"seq":16,"type":"response","request_seq":6,"success":true,"command":"setExceptionBreakpoints"}
-> (C) {"command":"configurationDone","type":"request","seq":7}
<- (E) {"seq":19,"type":"event","event":"output","body":{"category":"telemetry","output":"VS/Diagnostics/Debugger/vsdbg/ProcessCreate","data":{"VS.Diagnostics.Debugger.vsdbg.OSFamily":"Windows","VS.Diagnostics.Debugger.vsdbg.Version":"15.7.20427.1 commit:cdd5a78a34de1d5c5e28f10b46390d161caca175","VS.Diagnostics.Debugger.vsdbg.WindowsVersion":"6.2.9200"}}}
<- (E) {"seq":21,"type":"event","event":"process","body":{"name":"C:\\Users\\vharabari\\Documents\\projects\\test\\main.exe","systemProcessId":12908,"startMethod":"launch"}}
<- (E) {"seq":23,"type":"event","event":"output","body":{"category":"telemetry","output":"VS/Diagnostics/Debugger/vsdbg/Launch","data":{"VS.Diagnostics.Debugger.vsdbg.OSFamily":"Windows","VS.Diagnostics.Debugger.vsdbg.Version":"15.7.20427.1 commit:cdd5a78a34de1d5c5e28f10b46390d161caca175","VS.Diagnostics.Debugger.vsdbg.VisualizerFileUsed":false,"VS.Diagnostics.Debugger.vsdbg.WindowsVersion":"6.2.9200","VS.Diagnostics.Debugger.vsdbg.AdapterId":"cppvsdbg","VS.Diagnostics.Debugger.vsdbg.SourceFileMappings":0,"VS.Diagnostics.Debugger.vsdbg.Launch.Duration":234}}}
<- (R) {"seq":25,"type":"response","request_seq":7,"success":true,"command":"configurationDone"}
<- (E) {"seq":27,"type":"event","event":"breakpoint","body":{"reason":"changed","breakpoint":{"id":1,"verified":false,"message":"No symbols have been loaded for this document.","line":8}}}
<- (E) {"seq":29,"type":"event","event":"breakpoint","body":{"reason":"changed","breakpoint":{"id":2,"verified":false,"message":"No symbols have been loaded for this document.","line":12}}}
<- (E) {"seq":31,"type":"event","event":"breakpoint","body":{"reason":"changed","breakpoint":{"id":3,"verified":false,"message":"No symbols have been loaded for this document.","line":13}}}
-> (C) {"command":"threads","type":"request","seq":8}
<- (R) {"seq":34,"type":"response","request_seq":8,"success":true,"command":"threads","message":"","body":{"threads":[]}}
Loaded 'C:\Users\vharabari\Documents\projects\test\main.exe'. Symbols loaded.
<- (E) {"seq":37,"type":"event","event":"module","body":{"reason":"new","module":{"id":"{0A45FD8F-7A99-47A0-8580-F95BFC8EAF97}","name":"main.exe","path":"C:\\Users\\vharabari\\Documents\\projects\\test\\main.exe","isUserCode":true,"symbolStatus":"Symbols loaded.","symbolFilePath":"C:\\Users\\vharabari\\Documents\\projects\\test\\main.pdb"}}}
<- (E) {"seq":39,"type":"event","event":"thread","body":{"reason":"started","threadId":1888}}
Loaded 'C:\Windows\System32\ntdll.dll'. Cannot find or open the PDB file.
<- (E) {"seq":42,"type":"event","event":"module","body":{"reason":"new","module":{"id":"{0A45FD8F-7A99-47A0-8580-F95BFC8EAFA0}","name":"ntdll.dll","path":"C:\\Windows\\System32\\ntdll.dll","isUserCode":false,"version":"10.0.17134.112 (WinBuild.160101.0800)","symbolStatus":"Cannot find or open the PDB file."}}}
<- (E) {"seq":44,"type":"event","event":"thread","body":{"reason":"started","threadId":13468}}
Loaded 'C:\Windows\System32\kernel32.dll'. Cannot find or open the PDB file.
<- (E) {"seq":47,"type":"event","event":"module","body":{"reason":"new","module":{"id":"{0A45FD8F-7A99-47A0-8580-F95BFC8EAFA4}","name":"kernel32.dll","path":"C:\\Windows\\System32\\kernel32.dll","isUserCode":false,"version":"10.0.17134.1 (WinBuild.160101.0800)","symbolStatus":"Cannot find or open the PDB file."}}}
Loaded 'C:\Windows\System32\KernelBase.dll'. Cannot find or open the PDB file.
<- (E) {"seq":50,"type":"event","event":"module","body":{"reason":"new","module":{"id":"{0A45FD8F-7A99-47A0-8580-F95BFC8EAFA6}","name":"KernelBase.dll","path":"C:\\Windows\\System32\\KernelBase.dll","isUserCode":false,"version":"10.0.17134.112 (WinBuild.160101.0800)","symbolStatus":"Cannot find or open the PDB file."}}}
The thread 13468 has exited with code 0 (0x0).
<- (E) {"seq":53,"type":"event","event":"thread","body":{"reason":"exited","threadId":13468}}
0
1
3
6
10
15
21
Loaded 'C:\Windows\System32\kernel.appcore.dll'. Cannot find or open the PDB file.
28
<- (E) {"seq":64,"type":"event","event":"module","body":{"reason":"new","module":{"id":"{0A45FD8F-7A99-47A0-8580-F95BFC8EAFB2}","name":"kernel.appcore.dll","path":"C:\\Windows\\System32\\kernel.appcore.dll","isUserCode":false,"version":"10.0.17134.112 (WinBuild.160101.0800)","symbolStatus":"Cannot find or open the PDB file."}}}
36
45
Loaded 'C:\Windows\System32\msvcrt.dll'. Cannot find or open the PDB file.
<- (E) {"seq":69,"type":"event","event":"module","body":{"reason":"new","module":{"id":"{0A45FD8F-7A99-47A0-8580-F95BFC8EAFB4}","name":"msvcrt.dll","path":"C:\\Windows\\System32\\msvcrt.dll","isUserCode":false,"version":"7.0.17134.1 (WinBuild.160101.0800)","symbolStatus":"Cannot find or open the PDB file."}}}
<- (E) {"seq":71,"type":"event","event":"thread","body":{"reason":"started","threadId":4772}}
Loaded 'C:\Windows\System32\rpcrt4.dll'. Cannot find or open the PDB file.
<- (E) {"seq":74,"type":"event","event":"module","body":{"reason":"new","module":{"id":"{0A45FD8F-7A99-47A0-8580-F95BFC8EAFB8}","name":"rpcrt4.dll","path":"C:\\Windows\\System32\\rpcrt4.dll","isUserCode":false,"version":"10.0.17134.112 (WinBuild.160101.0800)","symbolStatus":"Cannot find or open the PDB file."}}}
The thread 4772 has exited with code 0 (0x0).
<- (E) {"seq":77,"type":"event","event":"thread","body":{"reason":"exited","threadId":4772}}
The program '[12908] main.exe' has exited with code 0 (0x0).
<- (E) {"seq":80,"type":"event","event":"exited","body":{"exitCode":0}}
<- (E) {"seq":82,"type":"event","event":"terminated","body":{}}
-> (C) {"command":"disconnect","arguments":{"restart":false},"type":"request","seq":9}
<- (E) {"seq":85,"type":"event","event":"output","body":{"category":"telemetry","output":"VS/Diagnostics/Debugger/vsdbg/DebugCompleted","data":{"VS.Diagnostics.Debugger.vsdbg.OSFamily":"Windows","VS.Diagnostics.Debugger.vsdbg.Version":"15.7.20427.1 commit:cdd5a78a34de1d5c5e28f10b46390d161caca175","VS.Diagnostics.Debugger.vsdbg.WindowsVersion":"6.2.9200","VS.Diagnostics.Debugger.vsdbg.DebugCompleted.BreakCounter":0,"VS.Diagnostics.Debugger.vsdbg.AdapterId":"cppvsdbg"}}}
<- (R) {"seq":87,"type":"response","request_seq":9,"success":true,"command":"disconnect"}

logs for gdb launch

1: (274) LaunchOptions<LocalLaunchOptions xmlns='http://schemas.microsoft.com/vstudio/MDDDebuggerOptions/2014'
1: (293) LaunchOptions  ExePath='C:\Users\vharabari\Documents\projects\test\main.exe'
1: (293) LaunchOptions  WorkingDirectory='C:\Users\vharabari\Documents\projects\test'
1: (293) LaunchOptions  ExeArguments=''
1: (293) LaunchOptions MIMode='gdb'
1: (293) LaunchOptions  MIDebuggerPath='C:\Program Files\mingw-w64\mingw\mingw64\bin\gdb.exe'
1: (293) LaunchOptions  WaitDynamicLibLoad='false'
1: (293) LaunchOptions>
1: (293) LaunchOptions</LocalLaunchOptions>
1: (386) Starting: "C:\Program Files\mingw-w64\mingw\mingw64\bin\gdb.exe" --interpreter=mi
1: (398) DebuggerPid=7604
1: (776) ->=thread-group-added,id="i1"
1: (777) ->~"GNU gdb (GDB) 8.1\n"
1: (778) ->~"Copyright (C) 2018 Free Software Foundation, Inc.\n"
1: (779) ->~"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: (779) ->~"This GDB was configured as \"x86_64-w64-mingw32\".\nType \"show configuration\" for configuration details."
1: (779) ->~"\nFor bug reporting instructions, please see:\n"
1: (779) ->~"<http://www.gnu.org/software/gdb/bugs/>.\n"
1: (779) ->~"Find the GDB manual and other documentation resources online at:\n<http://www.gnu.org/software/gdb/documentation/>.\n"
1: (780) ->~"For help, type \"help\".\n"
1: (780) ->~"Type \"apropos word\" to search for commands related to \"word\".\n"
1: (809) ->(gdb)
1: (814) <-1001-gdb-set target-async on
1: (820) ->1001^done
1: (820) ->(gdb)
1: (820) ->&"\n"
1: (820) ->^done
1: (820) ->(gdb)
1: (821) 1001: elapsed time 8
1: (832) <-1002-interpreter-exec console "set pagination off"
1: (841) ->=cmd-param-changed,param="pagination",value="off"
1: (841) ->1002^done
1: (841) ->(gdb)
1: (841) ->&"\n"
1: (841) ->^done
1: (841) ->(gdb)
1: (841) 1002: elapsed time 8
1: (842) <-1003-gdb-set solib-search-path C:\\Users\\vharabari\\Documents\\projects\\test;
1: (851) ->1003^done
1: (851) ->(gdb)
1: (851) 1003: elapsed time 9
1: (851) <-1004-environment-cd C:\\Users\\vharabari\\Documents\\projects\\test
1: (851) ->&"\n"
1: (851) ->^done
1: (852) ->(gdb)
1: (852) ->1004^done
1: (852) ->(gdb)
1: (852) ->&"\n"
1: (852) ->^done
1: (852) ->(gdb)
1: (852) 1004: elapsed time 0
1: (857) <-1005-interpreter-exec console "show configuration"
1: (863) ->~"This GDB was configured as follows:\n   configure --host=x86_64-w64-mingw32 --target=x86_64-w64-mingw32\n"
1: (863) ->~"             --with-auto-load-dir=$debugdir:$datadir/auto-load\n             --with-auto-load-safe-path=$debugdir:$datadir/auto-load\n"
1: (863) ->~"             --with-expat\n"
1: (863) ->~"             --with-gdb-datadir=/c/mingw810/x86_64-810-posix-seh-rt_v6-rev0/mingw64/share/gdb (relocatable)\n"
1: (863) ->~"             --with-jit-reader-dir=/c/mingw810/x86_64-810-posix-seh-rt_v6-rev0/mingw64/lib/gdb (relocatable)\n"
1: (863) ->~"             --without-libunwind-ia64\n"
1: (863) ->~"             --without-lzma\n"
1: (863) ->~"             --with-python=/c/mingw810/x86_64-810-posix-seh-rt_v6-rev0/mingw64/opt (relocatable)\n"
1: (863) ->~"             --without-guile\n"
1: (863) ->~"             --with-separate-debug-dir=/c/mingw810/x86_64-810-posix-seh-rt_v6-rev0/mingw64/lib/debug (relocatable)\n"
1: (863) ->~"             --with-system-gdbinit=/c/mingw810/x86_64-810-posix-seh-rt_v6-rev0/mingw64/etc/gdbinit (relocatable)\n"
1: (863) ->~"             --without-babeltrace\n"
1: (863) ->~"\n(\"Relocatable\" means the directory can be moved with the GDB installation\ntree, and GDB will still find it.)\n"
1: (864) ->1005^done
1: (864) ->(gdb)
1: (864) 1005: elapsed time 6
1: (864) ->&"\n"
1: (864) ->^done
1: (864) ->(gdb)
E output: {"category":"telemetry","output":"VS/Diagnostics/Debugger/MIEngine/WindowsRuntime","data":{"VS.Diagnostics.Debugger.MIEngine.WindowsRuntime":"MinGW"},"type":"output"}
1: (877) <-1006-file-exec-and-symbols C:\\Users\\vharabari\\Documents\\projects\\test\\main.exe
1: (887) ->1006^done
1: (887) ->(gdb)
1: (887) 1006: elapsed time 10
1: (887) <-1007-interpreter-exec console "show architecture"1: (887) ->&"\n"1: (887) ->^done
1: (887) ->(gdb)$11: (887) ->~"The target architecture is set automatically (currently i386:x86-64)\n"
1: (888) ->1007^done
1: (888) ->(gdb)
1: (888) ->&"\n"
1: (888) ->^done
1: (888) ->(gdb)
1: (888) 1007: elapsed time 0
1: (890) <-1008-break-insert main
1: (898) ->1008^error,msg="No symbol table is loaded.  Use the \"file\" command."
1: (898) ->(gdb)
1: (898) ->&"\n"
1: (899) ->^done
1: (899) ->(gdb)
1: (901) 1008: elapsed time 10
E output: {"category":"telemetry","output":"VS/Diagnostics/Debugger/Launch","data":{"VS.Diagnostics.Debugger.ImplementationName":"Microsoft.MIDebugEngine","VS.Diagnostics.Debugger.EngineVersion":"14.0.50620.1","VS.Diagnostics.Debugger.HostVersion":"14.0.50620.1","VS.Diagnostics.Debugger.AdapterId":"cppdbg","VS.Diagnostics.Debugger.Launch.Duration":803,"VS.Diagnostics.Debugger.Launch.IsCoreDump":false,"VS.Diagnostics.Debugger.VisualizerFileUsed":false,"VS.Diagnostics.Debugger.SourceFileMappings":0},"type":"output"} R: {"success":true,"message":null,"request_seq":2,"command":"launch","body":null,"running":false,"refs":null,"seq":0,"type":"response"}
E initialized: {"type":"initialized"}
C setBreakpoints: {"source":{"name":"main.cpp","path":"C:\\Users\\vharabari\\Documents\\projects\\test\\main.cpp"},"lines":[8,12,13],"breakpoints":[{"line":8},{"line":12},{"line":13}],"sourceModified":false}
1: (1074) <-1009-break-insert -f main.cpp:8
1: (1078) ->&"No symbol table is loaded.  Use the \"file\" command.\n"
1: (1078) ->1009^done,bkpt={number="1",type="breakpoint",disp="keep",enabled="y",addr="<PENDING>",pending="main.cpp:8",times="0",original-location="main.cpp:8"}
1: (1078) ->(gdb)
1: (1078) ->&"\n"
1: (1078) ->^done
1: (1078) ->(gdb)
1: (1080) 1009: elapsed time 5
1: (1092) <-1010-break-insert -f main.cpp:12
1: (1099) ->&"No symbol table is loaded.  Use the \"file\" command.\n"
1: (1099) ->1010^done,bkpt={number="2",type="breakpoint",disp="keep",enabled="y",addr="<PENDING>",pending="main.cpp:12",times="0",original-location="main.cpp:12"}
1: (1099) ->(gdb)
1: (1099) 1010: elapsed time 7
1: (1099) ->&"\n"
1: (1099) ->^done
1: (1099) ->(gdb)
1: (1099) <-1011-break-insert -f main.cpp:13
1: (1109) ->&"No symbol table is loaded.  Use the \"file\" command.\n"
1: (1109) ->1011^done,bkpt={number="3",type="breakpoint",disp="keep",enabled="y",addr="<PENDING>",pending="main.cpp:13",times="0",original-location="main.cpp:13"}
1: (1109) ->(gdb)
1: (1109) ->&"\n"
1: (1109) ->^done
1: (1109) ->(gdb)
1: (1109) 1011: elapsed time 10
 R: {"success":true,"message":null,"request_seq":3,"command":"setBreakpoints","body":{"breakpoints":[{"id":1,"verified":true,"line":8,"message":null},{"id":2,"verified":true,"line":12,"message":null},{"id":3,"verified":true,"line":13,"message":null}]},"running":false,"refs":null,"seq":0,"type":"response"}
E breakpoint: {"reason":"changed","breakpoint":{"id":1,"verified":false,"line":8,"message":"Module containing this breakpoint has not yet loaded or the breakpoint address could not be obtained."},"type":"breakpoint"}
E breakpoint: {"reason":"changed","breakpoint":{"id":2,"verified":false,"line":12,"message":"Module containing this breakpoint has not yet loaded or the breakpoint address could not be obtained."},"type":"breakpoint"}
E breakpoint: {"reason":"changed","breakpoint":{"id":3,"verified":false,"line":13,"message":"Module containing this breakpoint has not yet loaded or the breakpoint address could not be obtained."},"type":"breakpoint"}
C setFunctionBreakpoints: {"breakpoints":[]} R: {"success":true,"message":null,"request_seq":4,"command":"setFunctionBreakpoints","body":{"breakpoints":[]},"running":false,"refs":null,"seq":0,"type":"response"}
C configurationDone: null
 R: {"success":true,"message":null,"request_seq":5,"command":"configurationDone","body":null,"running":false,"refs":null,"seq":0,"type":"response"}
C threads: null
 R: {"success":true,"message":null,"request_seq":6,"command":"threads","body":{"threads":[]},"running":false,"refs":null,"seq":0,"type":"response"}
E output: {"category":"stdout","output":"=thread-group-added,id=\"i1\"\nGNU gdb (GDB) 8.1\nCopyright (C) 2018 Free Software Foundation, Inc.\nLicense 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.\nThis GDB was configured as \"x86_64-w64-mingw32\".\nType \"show configuration\" for configuration details.\nFor bug reporting instructions, please see:\n<http://www.gnu.org/software/gdb/bugs/>.\nFind the GDB manual and other documentation resources online at:\n<http://www.gnu.org/software/gdb/documentation/>.\nFor help, type \"help\".\nType \"apropos word\" to search for commands related to \"word\".\nWarning: Debuggee TargetArchitecture not detected, assuming x86_64.\n=cmd-param-changed,param=\"pagination\",value=\"off\"\n","data":null,"type":"output"}
=thread-group-added,id="i1"
GNU gdb (GDB) 8.1
Copyright (C) 2018 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-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".
Warning: Debuggee TargetArchitecture not detected, assuming x86_64.
=cmd-param-changed,param="pagination",value="off"
1: (1171) <-1012-exec-run
1: (1179) ->=thread-group-started,id="i1",pid="12948"
1: (1179) ->=thread-created,id="1",group-id="i1"
1: (1179) ->~"[New Thread 12948.0x1050]\n"
1: (1190) <-1013-thread-info 1
E output: {"category":"stdout","output":"[New Thread 12948.0x1050]\n","data":null,"type":"output"}
[New Thread 12948.0x1050]
1: (1196) ->=library-loaded,id="C:\\WINDOWS\\SYSTEM32\\ntdll.dll",target-name="C:\\WINDOWS\\SYSTEM32\\ntdll.dll",host-name="C:\\WINDOWS\\SYSTEM32\\ntdll.dll",symbols-loaded="0",thread-group="i1",ranges=[{from="0x00007ffaee001000",to="0x00007ffaee1e04d8"}]
1: (1197) ->=library-loaded,id="C:\\WINDOWS\\System32\\kernel32.dll",target-name="C:\\WINDOWS\\System32\\kernel32.dll",host-name="C:\\WINDOWS\\System32\\kernel32.dll",symbols-loaded="0",thread-group="i1",ranges=[{from="0x00007ffaec771000",to="0x00007ffaec82124c"}]
1: (1199) ->=library-loaded,id="C:\\WINDOWS\\System32\\KernelBase.dll",target-name="C:\\WINDOWS\\System32\\KernelBase.dll",host-name="C:\\WINDOWS\\System32\\KernelBase.dll",symbols-loaded="0",thread-group="i1",ranges=[{from="0x00007ffaeb091000",to="0x00007ffaeb302de0"}]
1: (1235) ->1012^running
1: (1236) ->*running,thread-id="all"
1: (1236) ->(gdb)
1: (1236) 1012: elapsed time 65
1: (1237) ->0
1: (1237) ->1
1: (1237) ->3
1: (1237) ->6
1: (1237) ->10
1: (1237) ->15
1: (1237) ->21
1: (1237) ->28
1: (1237) ->36
1: (1237) ->45
E output: {"category":"stdout","output":"0\n","data":null,"type":"output"}
0
E output: {"category":"stdout","output":"1\n","data":null,"type":"output"}
1
E output: {"category":"stdout","output":"3\n","data":null,"type":"output"}
3
E output: {"category":"stdout","output":"6\n","data":null,"type":"output"}
6
E output: {"category":"stdout","output":"10\n","data":null,"type":"output"}
10
E output: {"category":"stdout","output":"15\n","data":null,"type":"output"}
15
E output: {"category":"stdout","output":"21\n","data":null,"type":"output"}
21
E output: {"category":"stdout","output":"28\n","data":null,"type":"output"}
28
E output: {"category":"stdout","output":"36\n","data":null,"type":"output"}
36
E output: {"category":"stdout","output":"45\n","data":null,"type":"output"}
45
1: (1239) ->=library-loaded,id="C:\\WINDOWS\\System32\\kernel.appcore.dll",target-name="C:\\WINDOWS\\System32\\kernel.appcore.dll",host-name="C:\\WINDOWS\\System32\\kernel.appcore.dll",symbols-loaded="0",thread-group="i1",ranges=[{from="0x00007ffaea3b1000",to="0x00007ffaea3c0090"}]
1: (1244) ->=library-loaded,id="C:\\WINDOWS\\System32\\msvcrt.dll",target-name="C:\\WINDOWS\\System32\\msvcrt.dll",host-name="C:\\WINDOWS\\System32\\msvcrt.dll",symbols-loaded="0",thread-group="i1",ranges=[{from="0x00007ffaebee1000",to="0x00007ffaebf7d4a4"}]
1: (1251) ->=thread-created,id="2",group-id="i1"
1: (1251) <-1014-thread-info 2
1: (1252) ->~"[New Thread 12948.0x3250]\n"
E output: {"category":"stdout","output":"[New Thread 12948.0x3250]\n","data":null,"type":"output"}
[New Thread 12948.0x3250]
1: (1254) ->=library-loaded,id="C:\\WINDOWS\\System32\\rpcrt4.dll",target-name="C:\\WINDOWS\\System32\\rpcrt4.dll",host-name="C:\\WINDOWS\\System32\\rpcrt4.dll",symbols-loaded="0",thread-group="i1",ranges=[{from="0x00007ffaec641000",to="0x00007ffaec763790"}]
1: (1259) ->~"[Thread 12948.0x3250 exited with code 0]\n"
E output: {"category":"stdout","output":"[Thread 12948.0x3250 exited with code 0]\n","data":null,"type":"output"}
[Thread 12948.0x3250 exited with code 0]
1: (1259) ->=thread-exited,id="2",group-id="i1"
1: (1259) ->~"[Inferior 1 (process 12948) exited normally]\n"
1: (1260) ->=thread-exited,id="1",group-id="i1"
1: (1260) ->=thread-group-exited,id="i1",exit-code="0"
1: (1261) ->*stopped,reason="exited-normally"
1: (1261) ->(gdb)
E output: {"category":"stdout","output":"[Inferior 1 (process 12948) exited normally]\n","data":null,"type":"output"}
[Inferior 1 (process 12948) exited normally]
1: (1261) ->&"\n"
1: (1261) ->^done
1: (1262) ->(gdb)
1: (1262) ->1013^done,threads=[]
1: (1262) ->(gdb)
1: (1262) ->&"\n"
1: (1262) ->^done
1: (1262) ->(gdb)
1: (1263) ->1014^done,threads=[]
1: (1263) ->(gdb)
1: (1263) ->&"\n"
1: (1263) ->^done
1: (1263) ->(gdb)
1: (1267) 1013: elapsed time 77
1: (1272) <-logout
E output: {"category":"console","output":"The program 'C:\\Users\\vharabari\\Documents\\projects\\test\\main.exe' has exited with code 0 (0x00000000).\r\n\r\n","data":null,"type":"output"}
The program 'C:\Users\vharabari\Documents\projects\test\main.exe' has exited with code 0 (0x00000000).
E exited: {"exitCode":0,"type":"exited"}
E terminated: {"type":"terminated"}
E output: {"category":"telemetry","output":"VS/Diagnostics/Debugger/DebugCompleted","data":{"VS.Diagnostics.Debugger.ImplementationName":"Microsoft.MIDebugEngine","VS.Diagnostics.Debugger.EngineVersion":"14.0.50620.1","VS.Diagnostics.Debugger.HostVersion":"14.0.50620.1","VS.Diagnostics.Debugger.AdapterId":"cppdbg","VS.Diagnostics.Debugger.DebugCompleted.BreakCounter":0},"type":"output"}
C disconnect: {"restart":false}
 R: {"success":true,"message":null,"request_seq":7,"command":"disconnect","body":null,"running":false,"refs":null,"seq":0,"type":"response"}

also logging for lldb just in case:

waiting for v8 protocol on stdin/stdoutwaiting for v8 protocol on stdin/stdout

I was really looking forward to homogenizing my cpp programming on linux and windows, and this is one little thing that spoils it...

Update: Forgot to write steps for recreating problem

pieandcakes commented 6 years ago

@FancyBanana Thank you for your report.

Bonus: it break on entry is set to true, stepping with f10 or f11 won't bring you to corresponding lines in source code.

When you say that its not bringing you to the lines of code, where do you set the breakpoints and what line is it taking you to?

FancyBanana commented 6 years ago

I had 3 breakpoints in these places:

#include <iostream>
using namespace std;
int main(int argc, char** argv){
    int a = 0;  // Breakpoint here
    for(int i = 0; i < 10; i++)
    {
        a = i*i - a; // Breakpoint here
        cout << a << endl; //Breakpoint here
    }    
}

... and what line is it taking you to?

It doesn't take me to any line at all, or any file for that matter. It's like it ignores source files completely.

pieandcakes commented 6 years ago

@FancyBanana Ok thanks. I'll take a look, but it looks like clang isn't putting the symbols in the right format as far as I can tell.

windows I don't think clang is putting the pdb information in the format that the VS Debugger recognizes. Because of this, the debugger can't load it. I don't think this is a supported scenario with the VS Debugger, but @gregg-miskelly might be able to better confirm this.

<- (E) {"seq":27,"type":"event","event":"breakpoint","body":{"reason":"changed","breakpoint":{"id":1,"verified":false,"message":"No symbols have been loaded for this document.","line":8}}}
<- (E) {"seq":29,"type":"event","event":"breakpoint","body":{"reason":"changed","breakpoint":{"id":2,"verified":false,"message":"No symbols have been loaded for this document.","line":12}}}
<- (E) {"seq":31,"type":"event","event":"breakpoint","body":{"reason":"changed","breakpoint":{"id":3,"verified":false,"message":"No symbols have been loaded for this document.","line":13}}}

gdb its showing no symbols loaded.

1: (890) <-1008-break-insert main
1: (898) ->1008^error,msg="No symbol table is loaded.  Use the \"file\" command."
FancyBanana commented 6 years ago

Could you propose a solution for that? I know that's outside of scope of your support but at this point i'm a bit frustrated because I've been fiddling couple days before addressing you.

pieandcakes commented 6 years ago

@FancyBanana I'm trying to figure out what format clang compiles into. I'm thinking the right thing to do would be to use gdb/lldb but I am also running into what you are hitting.

Unfortunately, the lldb-mi that ships with this package seems to be broken. I downloaded LLVM 6.0.0 from the LLVM site.

pieandcakes commented 6 years ago

@FancyBanana We are still investigating but I wanted to give you an update. After reading the clang documentation, I think you want to specify -g for debug symbols. I don't know what --debug does as it doesn't seem to be listed in the help file. Adding -v to the compile command shows it is using the MSVC linker so it should work with the VS Debugger.

pieandcakes commented 6 years ago

@FancyBanana It looks like the object file that is generated by clang doesn't include the .cpp source file information.

You can check this by running cvdump.exe against the .pdb file with the /sf flag. Searching inside the output, we don't see the .cpp showing up in the object file (in this case, clang generates it as a .o) so we don't know where the source is located. If you compile the same app with VS Enterprise, you will see the .cpp show up.

FancyBanana commented 6 years ago

I've found the solution: specifying -gcodeview flag worked, now i can use Windows debugger. Also -g is shorthand for --debug

pieandcakes commented 6 years ago

oh awesome! thanks for the information.

pieandcakes commented 6 years ago

After you mentioned it, I found this document.