CentOS 8.1 install Visual Studio Code Debugging OpenJDK

Compile the latest OpenJDK

Following the article " the Java engineer early adopters: compiling the latest the OpenJDK "
After that, the heart is still very confused: Compile a JDK too simple, it seems that there is no technical content herein, this work continues after compiling, debugging, step by step to build a JDK environment .

Preparing the Environment

Environment Description

project version Explanation
VMware 15.5 Prerequisites to install Linux on Windows
operating system CentOS 8.1 CentOS latest version of the open source community
JDK basis 13.0.2 Running java program needs and compile the latest JDK
Visual Studio Code 1.43.2 for Linux Debugging tool chain required
Linux user login peterchen When using a $ {user} Alternatively, refers to the current logged-on user name

Installation Environment

VMware installation

Download:
https://my.vmware.com/en/web/vmware/info/slug/desktop_end_user_computing/vmware_workstation_pro/15_0?wd=&eqid=95cf61ac00012630000000065e8ad569
installation steps:
Please check Baidu experience:
https://jingyan.baidu. com / article / e2284b2ba81236e2e6118d89.html

Visual Studio Code Installation

Tutorial official website address:
https://code.visualstudio.com/docs/setup/linux#_rhel-fedora-and-centos-based-distributions
Installation Step
1. Open the terminal
Here Insert Picture Description
2. Switch user
switches from the current user to root

su -

Then root password
Here Insert Picture Description
Configuration source dnf

sudo rpm --import https://packages.microsoft.com/keys/microsoft.asc
sudo sh -c 'echo -e "[code]\nname=Visual Studio Code\nbaseurl=https://packages.microsoft.com/yumrepos/vscode\nenabled=1\ngpgcheck=1\ngpgkey=https://packages.microsoft.com/keys/microsoft.asc" > /etc/yum.repos.d/vscode.repo'

4. installation
if a network interruption problems like him to try several times

cd /opt
sudo dnf check-update
sudo dnf install code

5. Create a desktop shortcut
to view the installation directory

whereis code

Here Insert Picture Description
Note that this directory: / usr / share / code
additional visual studio code icon file in: / usr / share / code / resources / app / resources / linux directory

Create Shortcut

vim /usr/share/applications/VSCode.desktop

Add the following:

[Desktop Entry]
Name=Visual Studio Code
Comment=Multi-platform code editor for Linux
Exec=/usr/share/code/bin/code
Icon=/usr/share/code/resources/app/resources/linux/code.png
Type=Application
StartupNotify=true
Categories=TextEditor;
MimeType=text/plain;

:! wq to save and exit
to copy the shortcut to the desktop of the currently logged on with:

cp /usr/share/applications/VSCode.desktop /home/${user}/Desktop

Here Insert Picture Description
Modify permissions

chown ${user} /home/${user}/Desktop/VSCode.desktop

Shortcut setting allows execution
Here Insert Picture Description
If this step did not see Allow Launching you need to select Rename to rename, delete the .desktop behind the name, and then set the executable, after the success of the following effects:
Here Insert Picture Description
this in Visual Studio Code CentOS 8.1 is installed successfully.

Other installation

Other necessary installation can Baidu, OpenJDK compiled please refer to: " the Java engineer early adopters: compiling the latest the OpenJDK "

Official commissioning

Construction of VS Engineering

CentOS open root system handover user terminal, and it has been successfully compiled into the root OpenJDK (author is placed in openjdk14)

cd /opt/openjdk/
make vscode-project

Here Insert Picture Description

Importing VS project

Open Visaul Studio Code Click File -> Open Workspace ...
Here Insert Picture Description
to enter the directory after step execution make vscode-project success output, click on OPEN to import a project:
Here Insert Picture Description
Here Insert Picture Description
After you import will be a warning that the meaning is currently open Visual Studio Code the workspace file has exceeded the limit too, need to do some configuration, we click on the blue button (instuctions) to jump to the official website to find a solution:
Here Insert Picture Description
the solution is to view the current document in a terminal limit the number and modify its settings:

cat /proc/sys/fs/inotify/max_user_watches

Here Insert Picture Description
The default file handle limit of 8192, modified by the following command:

vim /etc/sysctl.conf

In the end of the file add the following:
fs.inotify.max_user_watches = 524288

Then: wq save and exit, and then execute the following commands to validate the configuration:

sudo sysctl -p

Installation C / C ++ compiler plug-in
Here Insert Picture Description
installed plug-Code Runner
Here Insert Picture Description
restart Visual Studio Code, we see the full source code and compile jdk file structure:
Here Insert Picture Description

Debugging OpenJDK

Click VScode the debug button, we can see the following:
Here Insert Picture Description
In the "2. Click on the drop-down box" We see two options that can be performed
gtestLauncher
the Java

This is the jdk source code debugging two entrances, let's use the default gtestLauncher, then click on the gear on the right, VScode luanch.json will open a configuration file, its contents are:

{
    "version": "0.2.0",     
    "configurations": [
        {
            "name": "gtestLauncher",  // 配置名称,将会在启动配置的下拉菜单中显示
            "type": "cppdbg",  // 配置类型,cppdbg对应cpptools提供的调试功能;可以认为此处只能是cppdbg
            "request": "launch",  // 请求配置类型,可以为launch(启动)或attach(附加)
            "program": "/opt/openjdk14/build/linux-x86_64-server-release/hotspot/variant-server/libjvm/gtest/gtestLauncher",  // 将要进行调试的程序的路径
            "args": ["-jdk:/opt/openjdk14/build/linux-x86_64-server-release/jdk"],  // 程序调试时传递给程序的命令行参数
            "stopAtEntry": false,  // 设为true时程序将暂停在程序入口处,相当于在main上打断点
            "cwd": "/opt/openjdk14", // 调试程序时的工作目录,此为工作区文件夹;改成${fileDirname}可变为文件所在目录
            "environment": [], // 环境变量
            "externalConsole": false, // 为true时使用单独的cmd窗口,与其它IDE一致;18年10月后设为false可调用VSC内置终端TERMINAL
            "preLaunchTask": "Make 'exploded-image'", 
            "osx": {
                "MIMode": "lldb",
                "internalConsoleOptions": "openOnSessionStart",
                "args": ["--gtest_color=no", "-jdk:/opt/openjdk14/build/linux-x86_64-server-release/jdk"]
            },
            "linux": {
                "MIMode": "gdb",  // 指定连接的调试器,可以为gdb或lldb,linux下默认使用gdb
                "setupCommands": [
                    {
                        "text": "handle SIGSEGV noprint nostop",
                        "description": "Disable stopping on signals handled by the JVM"
                    }
                ]
            }
        },
        {
            "name": "java",
            "type": "cppdbg",
            "request": "launch",
            "program": "/opt/openjdk14/build/linux-x86_64-server-release/jdk/bin/java",
            "stopAtEntry": false,
            "cwd": "/opt/openjdk14",
            "environment": [],
            "externalConsole": false,
            "preLaunchTask": "Make 'exploded-image'",
            "osx": {
                "MIMode": "lldb",
                "internalConsoleOptions": "openOnSessionStart",
            },
            "linux": {
                "MIMode": "gdb",
                "setupCommands": [
                    {
                        "text": "handle SIGSEGV noprint nostop",
                        "description": "Disable stopping on signals handled by the JVM"
                    }
                ]
            }
        }
    ]
}

We find debugging entrance according to the configuration file: / opt / openjdk14 / build / linux-x86_64-server-release / hotspot / variant-server / libjvm / gtest / gtestLauncher
But this is so binary file, under the corresponding cpp file in the source directory we will luanch.json the "stopAtEntry" changed to true, let him break in the main function at the start, so that we can quickly find the corresponding source file, and the revised click the arrow next to the startup RUN debug:
Here Insert Picture Description
very the program will soon enter the main function of the breakpoint:
Here Insert Picture Description
VSCode will automatically debug the source gtestLuancher.cpp entrance open, and the breakpoint in the main function. So that we can be happy debugging, commonly used shortcut keys are:

F5: Run to the next breakpoint
F10: execution line by line, and if a line is to call a function, do not enter the function
F11: execution line by line, and if a line is a function call, enter the function
shift + F11: method out
Ctrl + F10: perform a cursor

Published 12 original articles · won praise 26 · views 3425

Guess you like

Origin blog.csdn.net/baidu_23747517/article/details/105344769