16

When I debug my C++ project in VS Code and toggle a breakpoint, The "step into" option redirecting me to external files/libraries, but I want to step only into my code.

I tried to add "justMyCode": true option in launch.js file, but it says this property is not allowed.

What can I do to go only through source code?

P. Milev
  • 326
  • 1
  • 12
  • Not sure about VS Code, but regular Visual Studio has a way to exclude individual files from "step into" behavior. The problem is that you have to configure it for each function you don't want to step into. – Mark Ransom May 29 '20 at 20:17
  • What platform do you use vscode on? On linux you can achieve this by passing "nosharedlibrary" to GDB, or by simply removing the debugging symbols via your package manager. –  May 31 '20 at 14:54
  • The "just my code" for C++ is a relatively new feature for Visual studio, VS Code clearly doesn't support it yet, if it ever will. – Taekahn Jun 01 '20 at 01:57
  • VS Code does support "justMyCode" ... but for Python only. Maybe some day it will come to C++. – jdaz Jun 05 '20 at 08:23
  • I've had the same struggle myself, but with gdb, even though you can "skip" files with gdb I couldn't get it to work in visual studio code. Here is a GitHub feed that discusses this topic: [link](https://github.com/microsoft/vscode-cpptools/issues/5763). It looks like the issue has been upvoted many times, but the effort has yet to be considered. – bogdan_ariton May 26 '21 at 10:58

2 Answers2

0

One thing could be done for this issue. I actually tested my own test program:

std::vector<std::string> name;

std::cout << "Enter a name: ";
std::getline(std::cin, name);

nameList.push_back(name); // BREAKPOINT

When we select Step Into in the breakpoint execution, it redirects into the definition of the function where it's actually defined, it's not going to debug only for your file in this case.

Step Into Type:

Step Into Type Debugging

Rather, you must use Step Over since it doesn't tries to find the function definitions and you would able to debug your content straightforwardly.

Step Over Type:

Step Over Type Debugging

The Step Into will certainly redirect you into the function definition wherever it's defined, if you want to know the declaration and other things about the related function, it's good opportunity to use Step Into. But in case you just want to debug the line only and not considering to go in depth and don't want to get jumped into another file, you must use Step Over.

If you want to know more about Step Into and Step Over, you can go through this Stack Overflow thread. I've found this helpful too.

Rohan Bari
  • 6,523
  • 3
  • 9
  • 30
  • This is not an answer to the question nor a solution to the problem. E.g. if you wanted to debug the constructor of a custom type you need to step into push_back(), you can't just use "Step Over" as you suggest. –  May 31 '20 at 19:23
  • @para Step Into will always dig into the functions and their sub-functions as long as you Step Into them. It's just something like you wants to do B with the thing that does A. **Note:** You'll get the variables and their values on the left corner even after using Step Over. – Rohan Bari May 31 '20 at 19:24
  • And yes, if you want to debug your custom functions, classes, etc. then it's good to Step Into everywhere in your code. But if you've used something built-in, the debugger will must go to the definition. – Rohan Bari May 31 '20 at 19:31
  • The OP wants the debugger to ignore all code not written by him when he steps into a function, it is literally his question. You do not address this in your answer. The full version of Visual Studio can do this, so it is not an outlandish thing to ask. –  May 31 '20 at 19:34
  • 1
    Visual Studio and Visual Studio *Code* are different. Double-check the question. – Rohan Bari May 31 '20 at 19:35
  • 1
    This does answer the question, and imo its the proper solution since the feature he wants clearly doesn't exist. – Taekahn Jun 01 '20 at 01:58
  • 2
    This doesn't answer the question! If you want to step into a function where the argument is a built in function call you can't just step over because you will step over the whole thing! If you can't provide a solution, don't answer, you can post a comment! There are extensions for VS code that provide this functionality for other languages, it is possible for c++, maybe not implemented yet, but this can be answered properly! – mdatsev Jun 02 '20 at 18:55
-1

This is not a perfect answer,

Suppose you are debugging code this:

func_that_we_care ( func_that_we_dont_care( i)  );   <== step into this line

and you fall into 'func_that_we_dont_care', you can 'step out' there, then 'step into' again, eventually you will be able to step into 'func_that_we_care'.

grizzlybears
  • 118
  • 6
  • I guess you're talking about Step Over about which I had described in my answer. Stepping into a function will must drop you to the definition of the function or a subroutine. If you can ignore `func_that_we_dont_care(i))` statement without stepping over, then define how to do so. – Rohan Bari Jul 02 '20 at 11:00
  • This case could be solved by editing the code a bit. `auto foo = func_that_we_dont_care_about(i); /n func_that_we_care_about(foo); // step in here` Suboptimal, but effective. – Mark Storer Aug 24 '20 at 13:11