OpenJDK-调试jar (Idea+CLion)

准备

本次实验仍是采用java debug wire protocol来满足同时在Idea中调试java代码和在CLion中调试openjdk的代码。

jar

准备java测试代码:

package com.saleson.jdk;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * @author saleson
 * @date 2022-03-31 20:59
 */
public class Demo {

    public static void main(String[] args) throws Exception {
        int c = 0;
        AtomicInteger ac = new AtomicInteger();
        while (true) {
            c++;
            int d = ac.incrementAndGet();
            System.out.println(String.format("c:%d, ac:%d", c, d));
            System.out.println(System.currentTimeMillis());
            Thread.sleep(2000);
        }
    }
}

在pom.xml 添加plugin

     <build>
        <plugins>
            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <configuration>
                    <appendAssemblyId>false</appendAssemblyId>
                    <descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                    <archive>
                        <manifest>
                            <mainClass>com.saleson.jdk.Demo</mainClass>
                        </manifest>
                    </archive>
                </configuration>
                <executions>
                    <execution>
                        <id>make-assembly</id>
                        <phase>package</phase>
                        <goals>
                            <goal>assembly</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

执行mvn命令编译生成jar包

mvn -DskipTests assembly:assembly

具体的步骤请看OpenJDK-调试 (CLion) #调试jar

CLion 和 Idea 调试参数

在CLion中新建 Custom Build Application
在这里插入图片描述

FieldContentDescribe
Target选择前面创建好的Custom Build Target
Executable{openjdk}/build/macosx-x86_64-normal-server-slowdebug/jdk/bin/java选择编译后的openjdk目录下的java命令
Propram arguments-jar -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8080 personal-1.0-SNAPSHOT.jarjava 命令后面跟着的参数
Working directory/Users/saleson/IdeaProjects/personal/targetjar所在的目录

在Idea中新建Remote类型的Debug Configuration
在这里插入图片描述

FieldContentDescribe
Hostlocalhost调试程序的ip
Port8080jdwp开起的端口
Command line arguments for remote JVM-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:8080调试远程JVM的命令参数

效果展示

先以debug方式运行CLion 中上面新建的Custom Build Application;
再以debug方式运行Idea中新建的Remote;
在CLion和Idea中分别设置断点,运行效果如下
CLion断点
在这里插入图片描述
Idea断点
在这里插入图片描述
CLion中的输出
在这里插入图片描述

远程调试参数说明

FieldDescribe
-Xdebug通知JVM工作在debug模式下
-Xnoagent禁用默认sun.tools.debug调试器
-Djava.compiler=NONE禁止 JIT 编译器的加载
-Xrunjdwp通知JVM使用(java debug wire protocol)来运行调试环境;加载JDWP的JPDA参考执行实例
-Xrunjdwp 参数说明
FieldDescribe
transport监听Socket端口连接方式(也可以dt_shmem共享内存方式,但限于windows机器,并且服务提供端和调试端只能位于同一台机)
serverserver=y表示当前是调试服务端,=n表示当前是调试客户端
suspendsuspend=n表示启动时不中断,一般用于设置主动连接;suspend=y表示启动时就进入调试模式,一般用于被动连接

参考

https://www.jianshu.com/p/ee7e9176632c
https://segmentfault.com/a/1190000040305260
https://blog.csdn.net/weixin_32010647/article/details/114567722

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值