When I use vscode debug my code, how does the debugger know where to find the source code? Is the source code path recorded into the binary file when compiling? Sometimes, the debugger complains "Unknown Source", what are the rules behind this?
Related
Recently, our development team is starting to use ccache to do faster compile (the compile is done from sandbox /usr/x).
Now, when I compile from my sandbox (/usr/y), and try to set a breakpoint in the code in Eclipse (GDB (DSF) process launcher), it fails to find the file.
Further investigation shows that Eclipse gdb uses the complete path of the file to set a breakpoint (e.g. b /usr/y/untouchedFile.cpp:1234), but the actual path (in the gdb debugger) is actually /usr/x/untouchedFile.cpp.
The only thing that works is to set a breakpoint on the console by typing it, and do a source file mapping when the breakpoint is hit.
I would like to set the breakpoint by clicking on the code line (which used to work before ccache).
I was wondering if there is a way to get around this.
Thanks!
I'm trying to debug a piece of code, but GDB seems to be completely unable to read a specific single file. Any breakpoint inside that file or with content that refers to that file (like instantiating a class from that file) is skipped immediately upon reaching.
From what I could gather on Google, this is a bug that appeared first in GDB in the early 2000s, disappeared on 2005 but still happens somewhat rarely, and has no documented solution.
This is the affected file and this file and it's header(with only declarations) are the only files from this project that can not be accessed with GDB.
The project is being compiled using CMake and is using the flags -g3 -O0, so I think there are no missing debug information.
I'm using GDB via my IDE, CLion 1.0.3, but using the terminal renders the same problems.
I am currently able to set up and compile a a visual studio project using cmake however I am unable to breakpoint in source at all. Originally I was warned by VS when I tried to run with the debugger that debug symbols could not be found. To fix this I simply went to the projects properties and selected Linker->Debugging and set "Generate Debug Info" to yes. Now it generates the necessary pdb file, however if I put a break point in the source code it will hollow out and tell me that no symbols where loaded for the document.
So my question is why is it not matching the source to the pdb file and what can I do to correct this?
Thanks.
Here's a git repo with a simple example: https://github.com/Samurai336/CmakeSimple
Ok I figured out what the problem was, thanks to digging deeper into user Fraser's comment, where he asked if I set my debug information format to "/Zi or /ZI". Well it was set to Zi so to put the science back in computer science I gave /ZI a shot. The compiler yelled at me that " '/ZI' and '/02' are incompatible." So today I looked into what the /02 flag is and realized that it was max speed optimization flag and had a hunch that was why it was having issues debugging. Sure enough when I changed the flag to '/Od'(disabled) everything break pointed accordingly.
This leaves me with a one major question though: How do I set these flags for the VS compiler from cmake?
I'll probably pose this as a separate question if I don't find it already answered.
Thanks for the help everyone.
I'm currently writing a native extension for NodeJS. This is basically a dll that NodeJS will load when you ask for it.
I have VS2012 attached to the Node process. I want to debug into Node's code that does the loading.
I have the .cc and .h files for node, but there are no .pdb files that I can find. How can I set a breakpoint in the Node source?
UPDATE: I DO have a node.lib file. Can that be a replacement for a pdb?
UPDATE 2: Tangential, but for anyone specifically debugging NodeJS, Node actually DOES ship a pdb, available at http://nodejs.org/dist/v0.8.22/node.pdb (replace the version number with whatever version you're looking for).
Without a way to relate actual source code to assembly code, you cannot debug from source code. You need a pdb file.
Think of it that way: any compiler could have generated the code, and even if VS2012 compiler generated the code, there is no way VS could reverse engineer all the code generation phase to know to which source line a specific assembly command belongs. And with inlining and such, it even adds more difficulty to the task.
So any debugger cannot debug without debug symbols, it is just impossible to reverse assembly semantics into a higher level language semantics (you lose structural information during the compilation process). Otherwise, static analysis tools would be so easy to write.
Edit: .lib file does not include debug information either, just the necessary information to link against it. So you're out of luck too.
I have a solitary .cpp file, and I would very much like to debug it.
Without creating an Xcode project, is there anyway I can debug this using the Xcode debugger?
When I open the file in Xcode to edit and set breakpoints, the program doesn't stop at the break points.
You can't debug via Xcode without a project because without a project, Xcode works only as a file editor with color highlight and so one.
For debugging you need an executable compiled with debug option, which is produced via a compiler. The easy way (but in my opinion the worse) is to make a Xcode project and put the .cpp file there. There is the hard way too (and probably the best for future reference) that is to learn to do it on the terminal, using for instance the g++ (compiler) and gdb (debugger).
If noone answers you later, maybe this post will help you
I'm not a XCode developer, but I know, that to debug a process you need:
a debugger
the corresponding (!) code
the info, which stores a special debugging info, which gives the debugger an opportunity to map from binary process to your C++ (or other) code
and the process, sure :)
this link could help to understand if you have debugging info
http://www.meandmark.com/xcode3debugging.pdf
you can search words "Debug Information" and try to understand, if you have it or not
There is a way to do this without floundering through xcode, but unfortunately it is possibly more arcane.
Using cmake (https://cmake.org/) you can write a simple CMakeLists.txt to pull in your cpp file:-
cmake_minimum_required(VERSION 3.10)
project(project)
set(CMAKE_BUILD_TYPE Debug)
add_executable(project code.cpp)
To generate an xcode project type this:-
cmake -G Xcode
this will create project.xcodeproj
You can now type:-
open project.xcodeproj
and xcode will be launched.