Attaching source code belonging to a shared library [duplicate] - c

In a Python project, how do you tell the built-in VSCode debugger to step into the code of functions from other libraries on execution?
I know it is possible for functions implemented in standard libraries by adding a
"debugOptions": ["DebugStdLib"]
to your configuration in launch.json as specified here, however it does not seem to be possible to force the debugger to step into the code of non-standard modules, such as the ones you have written yourself and imported into the current file.

In order to improve the accepted answer by John Smith, it is worth mentioning that now the option has been renamed again. The new option is
"justMyCode": false
and as per the documentation
When omitted or set to True (the default), restricts debugging to
user-written code only. Set to False to also enable debugging of
standard library functions.

This is done by customising your debugger.
If you haven't already, you need to initialise the debugger customisation. You can do this by opening the debugger section in the side bar and selecting create a launch.json file.
Once this is done, a launch.json file will be created in a .vscode folder in your workspace.
Edit this file. It will look something like this:
{
...,
"configurations": [
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal"
}
]
}
Add "justMyCode": false to the "Python: Current File" configuration, like this:
{
...,
"configurations": [
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"justMyCode": false
}
]
}
True as of Visual Studio Code version 1.59.0.
Reference:
https://code.visualstudio.com/docs/python/debugging

A debugger configuration with
"debugOptions": ["DebugStdLib"]
added in launch.json in fact will step into user-defined and pip-installed modules, contrary to what's written in the main question.

Most of the time, I debug unit tests rather than the running application.
If that is also the case on your side and you use:
Visual Studio Code
pytest
The Python Test Explorer for Visual Studio Code (A test runner extension (adds a debug menu and provided debug buttons above tests directly in the IDE)) https://marketplace.visualstudio.com/items?itemName=LittleFoxTeam.vscode-python-test-adapter
Then use the following launch.json as mentionned in the plugin page:
{
"version": "0.2.0",
"configurations": [
{
"name": "Debug test",
"type": "python",
"request": "attach",
"console": "externalTerminal",
"justMyCode": false,
"stopOnEntry": true,
"envFile": "${workspaceFolder}/.env.test",
"purpose": ["debug-test"]
}
]
}

For those using the standard VSCode Debugger, a little more clarification on how to configure this in VS Code might be needed
Create Your Debugger Configuration As Follows
Open up your .vscode/launch.json
Add a configuration {} to the configurations list:
"configurations": []
This one will be recognized by the built-in VSCode Debugger:
{
"name": "Python: Debug Tests",
"type": "python",
"request": "launch",
"program": "${file}",
"purpose": ["debug-test"],
"console": "integratedTerminal",
"justMyCode": false
}
Key points:
purpose should be set to ["debug-test"]
"justMyCode": should be set to false.
References: Official VSCode Docs

The configurations in launch.json file as follows work for me.
"configurations": [
{
"name": "Python: Current File",
"type": "python",
"request": "test",
"program": "${file}",
"console": "integratedTerminal",
"justMyCode": false,
"purpose": ["debug-in-terminal"]
}
]

Related

Is it possible to debug WM from VSCode?

I wanna continue update dwm (Dynamic Window Manager) for myself. Previously I just built and ran dwm on another tty via startx. But this not provide debugging via IDE.
Can I satrt dwm from VSCode with debugging?
I tried to add simply launch.json:
{
"version": "0.2.0",
"configurations": [
{
"type": "lldb",
"request": "launch",
"name": "Debug",
"program": "${workspaceFolder}/dwm",
"args": [],
"cwd": "${workspaceFolder}"
}
]
}
But when I run it I get error:
dwm: another window manager is already running

Office Add-in Debugging in Chrome

I'm trying to get debugging of Office Add-ins working through VS Code. I've installed the Microsoft Office Add-in Debugger extension as well as the Debugger for Chrome extension. I have a section in my launch.json file that has a preLaunchTask that uses start:web.
I'm confused about how this process works, currently it opens two chrome windows, which I didn't expect. It looks like only one of the windows will actually cause VS Code to break on my breakpoints.
I'd like to hard code my document URL while debugging, so I don't have to keep entering it with an inputs promptString. I guess I'm confused about how these two files work together to start debugging and where do I need to enter the URL to my Excel file in SharePoint.
launch.json
{
"name": "Office Online (Chrome)",
"type": "chrome",
"request": "launch",
"webRoot": "${workspaceFolder}",
"preLaunchTask": "Debug: Web",
"url": "https://UrlToMyTestExcelDocumentInSharePoint"
}
tasks.json
{
"label": "Debug: Web",
"type": "npm",
"script": "start:web -- --document https://UrlToMyTestExcelDocumentInSharePoint",
"presentation": {
"clear": true,
"panel": "shared",
"showReuseMessage": false
},
"problemMatcher": []
}

How to debug with VSCODE for mac (C language)

I'm trying to launch the debugger but it doesn't work.
Do you have any idea how to make it work ?
This is the error i get :
This is my code. (very simple).
This is my launch.json file.
"configurations": [
{
"name": "Launch (lldb)",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/main",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false
}
]
Thanks for your help.
Your configuration above does not contain the debugger to use. For macOS you would most likely use lldb. To make VSCode aware of your wish to use lldb you have to set
"MIMode": "lldb"
You can also use a custom path to lldb like so:
"miDebuggerPath": "/usr/local/opt/llvm/bin/lldb"
More more information see VSCode: Configuring C/C++ debugging

Setting up VS Code for C using Cygwin64 Compiler and Debugger on Windows

Would like to set up VS Code to work with Cygwin/Cygwin64.
Already have these set up:
Installed Cygwin64 on windows
Installed gcc (Compiler) and gdb (Debugger) packages from Cygwin installer
GCC and GDB are NOT in windows path.
Installed Visual Studio Code
Posting this because it took me a couple of days from multiple different sources to set this up.
This is specifically for Windows with Cygwin/Cygwin64 installed.
DISCLAIMER: I've only tested this for building single files.
Instructions here are for setting up on VS Code
Install the extension C/C++ on VS Code
Name: C/C++
Id: ms-vscode.cpptools
Description: C/C++ IntelliSense, debugging, and code browsing.
Version: 0.23.1
Publisher: Microsoft
VS Marketplace Link: https://marketplace.visualstudio.com/items?itemName=ms-vscode.cpptools
If you have a workspace already, skip this step.
Create a folder and add this folder into VS Code. Then save workspace.
Set up launch.json
Go to "Debug > Open Configurations", this should open the launch.json file. Below is my configuration. If you're testing this and unsure of what you're doing, I suggest you save your original content somewhere before replacing things.
Note: "preLaunchTask": "gcc.exe build active file" runs the task labelled "gcc.exe build active file".
{
"version": "0.2.0",
"configurations": [
{
"name": "gcc.exe build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [
{
"name": "PATH",
"value": "%PATH%;z:\\cygwin64\\bin"
}
],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "C:\\cygwin64\\bin\\gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"logging": { "engineLogging": true }, //optional
"preLaunchTask": "gcc.exe build active file"
}
]
}
Set up task.json
Go to "Terminal > Configure Tasks..." and select "gcc.exe build active file"
The various "-W" flags in "args" are meant to make the compiler more strict. You can remove them if you'd like.
{
"tasks": [
{
"type": "shell",
"label": "gcc.exe build active file",
"command": "C:\\cygwin64\\bin\\gcc.exe",
"args": [
"-g",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe",
"-Werror", // Optional
"-Wall", // Optional
"-Wextra", // Optional
"-ansi", // Optional
"-pedantic", // Optional
"${file}"
],
"options": {
"cwd": "C:\\cygwin64\\bin"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
}
},
],
"version": "2.0.0"
}
Build and Debug Active File
Go to the C file you want to build, press Ctrl+Shift+P for "Command Palette > C/C++ Build and Debug Active File > gcc.exe build active file" or if you only want to build then go to "Terminal > Run Build Task".
Cygwin64 is inefficient because it is using a medium memory model. This makes it use 64 bit absolute addresses instead of 32 bit relative addresses for static data.
I will recommend to use the Clang plugin for Visual Studio instead, unless you have a specific reason to use Cygwin64. See https://devblogs.microsoft.com/cppblog/clang-llvm-support-in-visual-studio/
You also get rid of the cygwin DLL when using the Clang plugin.

How to debug libsass library?

I have cloned libsass and sassc and compiled it manually using makefile to generate its executable. Everything works just fine But I need to debug the libsass library to do some changes. I am using VSCode in Mac.
For a simple helloworld program, when I configure launch.json to execute its executable, the breakpoint works just fine. But for sassc it is not working.
This is the launch.json file am using in VSCode. Should I make any changes in this or should I understand something else?
{
// 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": "(lldb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/sassc/bin/sassc", //sassc.exe path
"args": ["${workspaceFolder}/ex/sample.scss","${workspaceFolder}/ex/sample.css"],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "lldb"
}
]
}
Edit:
I am using Mac and as per https://social.msdn.microsoft.com/Forums/en-US/ef99e9f5-2a48-423b-b6c0-fa5617d7c63d/how-do-i-get-c-to-work-on-visual-studio-for-mac?forum=visualstudiogeneral, C/C++ project is not yet supported in Mac Visual Studio and I am not gonna use VM. So either I had to use XCode or VSCode as per my knowledge and since VSCode is lightweight and I have worked with it before, I opted for VSCode. If you have any other suggestions, let me know.

Resources