본문 바로가기

카테고리 없음

Configure Launch.json Visual Studio Code For Mac C++



How have you been developing Chromium? I have often been asked what is the best tool to develop Chromium. I guess Chromium developers have been usually using vim, emacs, cscope, sublime text, eclipse, etc. And they have used GDB or console logs for debugging. But, in case of Windows, developers have used Visual Studio. Although Visual Studio supports powerful features to develop C/C++ programs, unfortunately, it couldn’t be used by other platform developers. However, recently I notice that Visual Studio Code also can support to develop Chromium with the nice editor, powerful debugging tools, and a lot of extensions. And, even it can work on Linux and Mac because it is based on Electron. Nowadays I’m developing Chromium with VS Code. I feel that VS Code is one of the very nice tools to develop Chromium. So I’d like to share my experience how to develop Chromium by using the Visual Studio Code on Ubuntu.

A C++ compiler needs to be installed in order to configure Visual Studio Code. Visual Studio Code will automatically be able to recognise various compilers like clang, mingw or gcc and automatically set things up for you. Now we have two Visual Studio versions (Visual Studio for Mac, Visual Studio Code) that can directly install on the Mac (macOS), refer to your description, it looks like you installed the Visual Studio for Mac, it is a developer environment optimized for building mobile and cloud apps with Xamarin and.NET. Visual Studio for Mac.NET. Azure DevOps. 0 [c++] Default launch.vs.json configuration keeps being added to the configurations array. Windows 10.0 visual studio 2017 rc. Edit the configuration name. Repeat Step 2. Expected: The user is taken to the edited configuration.

* https://chromium.googlesource.com/chromium/src/+/lkcr/docs/vscode.md

  1. Download VS Code
  2. Launch VS Code in chromium/src
  3. Install useful extensions
    1. Python – Linting, intellisense, code formatting, refactoring, debugging, snippets.
    2. c/c++ for visual studio code – Code formatting, debugging, Intellisense.
    3. Toggle Header/Source Toggles between .cc and .h with F4. The C/C++ extension supports this as well through Alt+O but sometimes chooses the wrong file when there are multiple files in the workspace that have the same name.
    4. you-complete-me YouCompleteMe code completion for VS Code. It works fairly well in Chromium. To install You-Complete-Me, enter these commands in a terminal:
    5. Rewrap – Wrap lines at 80 characters with Alt+Q.
  4. Setup for Chromium
    1. Chromium added the default settings files for vscode. We can move them to //src/.vscode folder.
      1. Workspace setting
        – https://cs.chromium.org/chromium/src/tools/vscode/settings.json5
      2. Task setting
        – https://cs.chromium.org/chromium/src/tools/vscode/tasks.json5
      3. Launch setting
        – https://cs.chromium.org/chromium/src/tools/vscode/launch.json5
  5. Key mapping
  6. (Optional) Color setting
    • Press Ctrl+Shift+P, color, Enter to pick a color scheme for the editor
  1. Set workspaceRoot to .bashrc. (Because it will be needed for some extensions.)
  2. Copy 3 settings files from //src/tools/vscode to //src/.vscode
    • You can find my configuration files based on the default files
  3. Set ycmd path to .vscode/settings.json
  4. Add new tasks to tasks.json in order to build Chromium by using ICECC.
    • I wrote a post about how to build Chromium by using ICECC in the previous post. Please setup it first.
    • Add buildChromiumICECC.sh Debug to the tasks.json
  1. Update “Chrome Debug” configuration in launch.json

you will see this window after finishing all settings.

  1. Run Task (Menu -> Terminal -> Run Tasks…)
  2. Select 1-build_chrome_debug_icecc. VS Code will show an integrated terminal when building Chromium as below, On the ICECC monitor, you can see that VS Code builds Chromium by using ICECC.

After completing the build, now is time to start debugging Chromium.

  1. Set a breakpoint
    1. F9 button or just click the left side of line number
  2. Launch debug
    1. Press F5 button
  3. Screen captures when debugger stopped at a breakpoint
    1. Overview
    2. Editor
    3. Call stack
    4. Variables
    5. Watch
    6. Breakpoints

Todo

In multiple processes model, VS Code can’t debug child processes yet (i.e. renderer process). According to C/C++ extension project site, they suggested us to add the below command to launch.json though, it didn’t work for Chromium when I tried.

Reference

  1. Chromium VS Code setup: https://chromium.googlesource.com/chromium/src/+/lkcr/docs/vscode.md

-->

Visual Studio knows how to run many different languages and codebases, but it doesn't know how to run everything. If you opened a code folder in Visual Studio, and Visual Studio knows how to run your code, you can run it right away without any additional configuration.

If the codebase uses custom build tools that Visual Studio doesn't recognize, you need to provide some configuration details to run and debug the code in Visual Studio. You instruct Visual Studio how to build your code by defining build tasks. You can create one or more build tasks to specify all the items a language needs to build and run its code. You can also create arbitrary tasks that can do nearly anything you want. For example, you can create a task to list the contents of a folder or to rename a file.

Customize your project-less codebase by using the following .json files:

File name Purpose
tasks.vs.json Specify custom build commands and compiler switches, and arbitrary (non-build related) tasks.
Accessed via the Solution Explorer right-click menu item Configure Tasks.
launch.vs.json Specify command-line arguments for debugging.
Accessed via the Solution Explorer right-click menu item Debug and Launch Settings.

These .json files are located in a hidden folder called .vs in the root folder of your codebase. The tasks.vs.json and launch.vs.json files are created by Visual Studio on an as-needed basis when you choose either Configure Tasks or Debug and Launch Settings on a file or folder in Solution Explorer. These .json files are hidden because users generally don't want to check them into source control. However, if you want to be able to check them into source control, drag the files into the root of your codebase, where they are visible.

Tip

To view hidden files in Visual Studio, choose the Show All Files button on the Solution Explorer toolbar.

Define tasks with tasks.vs.json

You can automate build scripts or any other external operations on the files you have in your current workspace by running them as tasks directly in the IDE. You can configure a new task by right-clicking on a file or folder and selecting Configure Tasks.

This creates (or opens) the tasks.vs.json file in the .vs folder. You can define a build task or arbitrary task in this file, and then invoke it using the name you gave it from the Solution Explorer right-click menu.

Configure

Custom tasks can be added to individual files, or to all files of a specific type. For instance, NuGet package files can be configured to have a 'Restore Packages' task, or all source files can be configured to have a static analysis task, such as a linter for all .js files.

Define custom build tasks

If your codebase uses custom build tools that Visual Studio doesn't recognize, then you cannot run and debug the code in Visual Studio until you complete some configuration steps. Visual Studio provides build tasks where you can tell Visual Studio how to build, rebuild, and clean your code. The tasks.vs.json build task file couples the Visual Studio inner development loop to the custom build tools used by your codebase.

Consider a codebase that consists of a single C# file called hello.cs. The makefile for such a codebase might look like this:

For such a makefile that contains build, clean, and rebuild targets, you can define the following tasks.vs.json file. It contains three build tasks for building, rebuilding, and cleaning the codebase, using NMAKE as the build tool.

After you define build tasks in tasks.vs.json, additional right-click menu (context menu) items are added to the corresponding files in Solution Explorer. For this example, 'build', 'rebuild', and 'clean' options are added to the context menu of any makefile files.

Note

The commands appear in the context menu under the Configure Tasks command due to their contextType settings. 'build', 'rebuild', and 'clean' are build commands, so they appear in the build section in the middle of the context menu.

When you select one of these options, the task executes. Output appears in the Output window, and build errors appear in the Error List.

Define arbitrary tasks

You can define arbitrary tasks in the tasks.vs.json file, to do just about anything you want. For example, you can define a task to display the name of the currently selected file in the Output window, or to list the files in a specified directory.

The following example shows a tasks.vs.json file that defines a single task. When invoked, the task displays the filename of the currently selected .js file.

  • taskName specifies the name that appears in the right-click menu.
  • appliesTo specifies which files the command can be performed on.
  • The command property specifies the command to invoke. In this example, the COMSPEC environment variable is used to identify the command line interpreter, typically cmd.exe.
  • The args property specifies the arguments to be passed to the invoked command.
  • The ${file} macro retrieves the selected file in Solution Explorer.

After saving tasks.vs.json, you can right-click on any .js file in the folder and choose Echo filename. The file name is displayed in the Output window.

Note

If your codebase doesn't contain a tasks.vs.json file, you can create one by choosing Configure Tasks from the right-click or context menu of a file in Solution Explorer.

The next example defines a task that lists the files and subfolders of the bin directory.

  • ${outDir} is a custom macro that is first defined before the tasks block. It is then called in the args property.

This task applies to all files. When you open the context menu on any file in Solution Explorer, the task's name List Outputs appears at the bottom of the menu. When you choose List Outputs, the contents of the bin directory are listed in the Output window in Visual Studio.

Settings scope

Multiple tasks.vs.json files can exist at the root and subdirectories of a codebase. This design enables the flexibility to have different behavior in different subdirectories of the codebase. Visual Studio aggregates or overrides settings throughout the codebase, prioritizing files in the following order:

Anaconda, the most popular Python data science platform, provides 6 million users with a streamlined Python environment on Windows, Mac or Linux. And starting today, Visual Studio Code, Microsoft’s free and cross-platform code editor, is included in the Anaconda distribution! Python programming with microsoft visual studio code for mac. Python is not presently supported in Visual Studio for Mac, but is available on Mac and Linux through Visual Studio Code (see questions and answers). To get started: Follow the installation instructions to set up the Python workload. Python in Visual Studio Code. Working with Python in Visual Studio Code, using the Microsoft Python extension, is simple, fun, and productive.The extension makes VS Code an excellent IDE, and works on any operating system with a variety of Python interpreters. Python Tools for Visual Studio is a completely free extension, developed and supported by Microsoft with contributions from the community. Visit our Github page to see or participate in PTVS development.

  • Settings files in the root folder’s .vs directory.
  • The directory where a setting is being computed.
  • The current directory’s parent directory, all the way up to the root directory.
  • Settings files in the root directory.

These aggregation rules apply to tasks.vs.json. For information on how settings in other file are aggregated, see the corresponding section for that file in this article.

Properties for tasks.vs.json

This section describes some of the properties you can specify in tasks.vs.json.

appliesTo

You can create tasks for any file or folder by specifying its name in the appliesTo field, for example 'appliesTo': 'hello.js'. The following file masks can be used as values:

'*' task is available to all files and folders in the workspace
'*/' task is available to all folders in the workspace
'*.js' task is available to all files with the extension .js in the workspace
'/*.js' task is available to all files with the extension .js in the root of the workspace
'src/*/' task is available to all subfolders of the src folder
'makefile' task is available to all makefile files in the workspace
'/makefile' task is available only to the makefile in the root of the workspace

Macros for tasks.vs.json

${env.<VARIABLE>} Specifies any environment variable (for example, ${env.PATH}, ${env.COMSPEC} and so on) that is set for the developer command prompt. For more information, see Developer command prompt for Visual Studio.
${workspaceRoot} The full path to the workspace folder (for example, C:sourceshello)
${file} The full path of the file or folder selected to run this task against (for example, C:sourceshellosrchello.js)
${relativeFile} The relative path to the file or folder (for example, srchello.js)
${fileBasename} The name of the file without path or extension (for example, hello)
${fileDirname} The full path to the file, excluding the filename (for example, C:sourceshellosrc)
${fileExtname} The extension of the selected file (for example, .js)

Configure debugging with launch.vs.json

  1. To configure your codebase for debugging, in Solution Explorer choose the Debug and Launch Settings menu item from the right-click or context menu of your executable file.

  2. In the Select a Debugger dialog box, choose an option, and then choose the Select button.

    If the launch.vs.json file doesn't already exist, it is created.

  3. Next, right-click on the executable file in Solution Explorer, and choose Set as Startup Item.

    The executable is designated as the startup item for your codebase, and the debugging Start button's title changes to reflect the name of your executable.

    When you choose F5, the debugger launches and stops at any breakpoint you may have already set. All the familiar debugger windows are available and functional.

Specify arguments for debugging

You can specify command-line arguments to pass in for debugging in the launch.vs.json file. Add the arguments in the args array, as shown in the following example:

Visual Studio Code For Linux

When you save this file, the name of the new configuration appears in the debug target drop-down list, and you can select it to start the debugger. You can create as many debug configurations as you like.

Note

The configurations array property in launch.vs.json is read from two file locations—the root directory for the codebase, and the .vs directory. If there is a conflict, priority is given to the value in .vslaunch.vs.json.

Additional settings files

In addition to the three .json files described in this topic, Visual Studio also reads settings from some additional files, if they exist in your codebase.

.vscodesettings.json

Download Visual Studio Code For Windows

Visual Studio reads limited settings from a file named settings.json, if it is in a directory named .vscode. This functionality is provided for codebases that have previously been developed in Visual Studio Code. Currently, the only setting that is read from .vscodesettings.json is files.exclude, which filters files visually in Solution Explorer and from some search tools.

You can have any number of .vscodesettings.json files in your codebase. Settings read from this file are applied to the parent directory of .vscode and all of its subdirectories.

.gitignore

.gitignore files are used to tell Git which files to ignore; that is, which files and directories you don't want to check in. .gitignore files are usually included as part of a codebase so that the settings can be shared with all developers of the codebase. Visual Studio reads patterns in .gitignore files to filter items visually and from some search tools.

Configure launch.json visual studio code for mac c++ ide

Settings read from the .gitignore file are applied to its parent directory and all subdirectories.

Visual Studio Code For Chromebook

See also