├── .github └── workflows │ └── maven.yml ├── .gitignore ├── README.md ├── agent ├── pom.xml └── src │ └── main │ └── java │ └── io │ └── javadebug │ └── agent │ ├── Agent.java │ ├── AgentClassLoader.java │ └── WeaveSpy.java ├── async-profiler ├── linux │ ├── README.md │ ├── build │ │ ├── jattach │ │ └── libasyncProfiler.so │ └── profiler.sh └── mac │ ├── README.md │ ├── build │ ├── jattach │ └── libasyncProfiler.so │ └── profiler.sh ├── bin ├── async-profiler │ ├── linux │ │ ├── README.md │ │ ├── build │ │ │ ├── jattach │ │ │ └── libasyncProfiler.so │ │ └── profiler.sh │ └── mac │ │ ├── README.md │ │ ├── build │ │ ├── jattach │ │ └── libasyncProfiler.so │ │ └── profiler.sh ├── btrace │ └── BlockingThreadCheck.java ├── hello.sh ├── javadebug-agent-attach.sh ├── javadebug-agent-launch.sh ├── javadebug-client-launch.sh ├── javadebug-cluster-launch.sh ├── javadebug-http-server.sh ├── javadebug-simple-client.sh ├── javadebug-unpack.sh ├── logo └── wrk_auto_benchmark.sh ├── blink.txt ├── core ├── pom.xml └── src │ ├── main │ ├── java │ │ └── io │ │ │ └── javadebug │ │ │ ├── com │ │ │ └── netflix │ │ │ │ └── numerus │ │ │ │ ├── LongMaxUpdater.java │ │ │ │ ├── NumerusProperty.java │ │ │ │ ├── NumerusRollingNumber.java │ │ │ │ ├── NumerusRollingNumberEvent.java │ │ │ │ ├── NumerusRollingPercentile.java │ │ │ │ └── Striped64.java │ │ │ └── core │ │ │ ├── CommandExecuteListener.java │ │ │ ├── CommandInputHandler.java │ │ │ ├── CommandRequestHandler.java │ │ │ ├── CommandServer.java │ │ │ ├── Configure.java │ │ │ ├── Constant.java │ │ │ ├── Error.java │ │ │ ├── JavaDebugClientLauncher.java │ │ │ ├── JavaDebugClusterClientLauncher.java │ │ │ ├── JavaDebugHttpServerLauncher.java │ │ │ ├── JavaDebugLauncher.java │ │ │ ├── JavaDebugToolJobExecutor.java │ │ │ ├── OptionController.java │ │ │ ├── RemoteServer.java │ │ │ ├── ServerHook.java │ │ │ ├── annotation │ │ │ ├── CommandDescribe.java │ │ │ ├── CommandDescribeUtil.java │ │ │ └── CommandType.java │ │ │ ├── claw │ │ │ ├── ArrayClawImpl.java │ │ │ ├── AutoMechanics.java │ │ │ ├── BooleanClawImpl.java │ │ │ ├── ByteClawImpl.java │ │ │ ├── CharClawImpl.java │ │ │ ├── ClawMeta.java │ │ │ ├── ClawSupportTypes.java │ │ │ ├── IntClawImpl.java │ │ │ ├── ListClawImpl.java │ │ │ ├── LongClawImpl.java │ │ │ ├── MapClawImpl.java │ │ │ ├── ObjectClawDefine.java │ │ │ ├── ObjectFieldInterpreter.java │ │ │ ├── RealClawImpl.java │ │ │ ├── SetClawImpl.java │ │ │ ├── StringClawImpl.java │ │ │ └── Transformer.java │ │ │ ├── command │ │ │ ├── AgentInfoCommand.java │ │ │ ├── AliveCommand.java │ │ │ ├── AopSupportCommand.java │ │ │ ├── BTraceCommand.java │ │ │ ├── Command.java │ │ │ ├── ExitCommand.java │ │ │ ├── FindJavaSourceCommand.java │ │ │ ├── GarbageCollectionInfoCommand.java │ │ │ ├── HelpCommand.java │ │ │ ├── ListCommand.java │ │ │ ├── LockClassCommand.java │ │ │ ├── MethodCallStackTraceCommand.java │ │ │ ├── MethodRateLimitCommand.java │ │ │ ├── MethodTraceCommand.java │ │ │ ├── MonitorCollectorCommand.java │ │ │ ├── OptionCommand.java │ │ │ ├── RedefineClassCommand.java │ │ │ ├── RollbackClassCommand.java │ │ │ ├── ThreadBlockHoundCommand.java │ │ │ ├── ThreadInfoCommand.java │ │ │ ├── evil │ │ │ │ └── EvilExecuteCommand.java │ │ │ └── perf │ │ │ │ ├── AsyncProfileCommand.java │ │ │ │ ├── CpuTimeReportStruct.java │ │ │ │ ├── CpuTimeTest.java │ │ │ │ ├── CpuTimeUsageCommand.java │ │ │ │ ├── CpuTimeWorker.java │ │ │ │ ├── GNULibC.java │ │ │ │ ├── LibcTest.java │ │ │ │ ├── LoadAvgTest.java │ │ │ │ ├── NativeCpuTime.java │ │ │ │ ├── RusageStruct.java │ │ │ │ ├── ThreadCommand.java │ │ │ │ ├── ThreadRichnessInfo.java │ │ │ │ ├── TimeInfo.java │ │ │ │ ├── TimeValStruct.java │ │ │ │ └── TmStructure.java │ │ │ ├── console │ │ │ ├── CommandSink.java │ │ │ ├── CommandSource.java │ │ │ ├── ConsoleCommandSink.java │ │ │ ├── ConsoleCommandSource.java │ │ │ ├── JLineConsole.java │ │ │ ├── MonitorCollectorCommandSource.java │ │ │ ├── ReadShellCommandSource.java │ │ │ └── WriteShellCommandSink.java │ │ │ ├── count │ │ │ └── MethodCountEvent.java │ │ │ ├── data │ │ │ ├── ClassField.java │ │ │ ├── ClassModel.java │ │ │ ├── JVMMemoryInfo.java │ │ │ ├── LRModel.java │ │ │ └── VariableModel.java │ │ │ ├── enhance │ │ │ ├── AbstractMethodTraceCommandAdvice.java │ │ │ ├── BaseMethodInvokeAdvice.java │ │ │ ├── ClassMethodWeaveConfig.java │ │ │ ├── ClassMethodWeaver.java │ │ │ ├── CommonClassFileTransformer.java │ │ │ ├── CustomInputMethodTraceAdviceImpl.java │ │ │ ├── EmptyPrintMethodAdvice.java │ │ │ ├── EnhanceResultHook.java │ │ │ ├── FullMatchMethodTraceAdviceImpl.java │ │ │ ├── InnerClassClassFilteTransformer.java │ │ │ ├── InnerClassWeaver.java │ │ │ ├── LocalVariableTable.java │ │ │ ├── MethodAdvice.java │ │ │ ├── MethodAdviceType.java │ │ │ ├── MethodDesc.java │ │ │ ├── MethodEnhanceStake.java │ │ │ ├── MethodInvokeAdvice.java │ │ │ ├── MethodInvokeAdviceFactory.java │ │ │ ├── MethodLineRangeEnhancer.java │ │ │ ├── MethodLineRangeWeaver.java │ │ │ ├── MethodTraceConverter.java │ │ │ ├── MethodTraceEnhance.java │ │ │ ├── MethodTraceFrame.java │ │ │ ├── MethodTraceListener.java │ │ │ ├── OnParamMatchMethodTraceAdviceIml.java │ │ │ ├── OnReturnMethodTraceAdviceImpl.java │ │ │ ├── OnThrowMethodTraceAdviceImpl.java │ │ │ ├── RecordCountLimitMethodTraceAdviceImpl.java │ │ │ ├── ThreadBlockHoundTransformer.java │ │ │ ├── ThreadBlockHoundWeaver.java │ │ │ └── UniqueSource.java │ │ │ ├── exception │ │ │ ├── CRC32CheckException.java │ │ │ ├── ClawScriptScanException.java │ │ │ ├── ClientAuthFailException.java │ │ │ ├── CommandExecuteWithStageException.java │ │ │ ├── CommandNotFindException.java │ │ │ ├── ConfigureErrorException.java │ │ │ ├── CouldNotFindClassByteException.java │ │ │ ├── CouldNotPassCommandPreCheckException.java │ │ │ ├── ForbidExecuteException.java │ │ │ ├── ObjectFieldInterpreterException.java │ │ │ ├── ObjectTransformerException.java │ │ │ ├── ProtocolErrorException.java │ │ │ ├── SerializationException.java │ │ │ └── ServerStartErrorException.java │ │ │ ├── handler │ │ │ ├── BaseCommandRequestHandler.java │ │ │ ├── BaseWrapClientHandler.java │ │ │ ├── ClientCommandRequestHandler.java │ │ │ ├── ClientHandler.java │ │ │ ├── CommandHandler.java │ │ │ ├── MultiRemoteClientHandler.java │ │ │ ├── ServerIdleHandler.java │ │ │ ├── StopAbleRunnable.java │ │ │ ├── WebSocketClientHandler.java │ │ │ └── WebSocketFrameHandler.java │ │ │ ├── hook │ │ │ ├── DefaultHookImpl.java │ │ │ ├── HookOperator.java │ │ │ ├── JavaDebugToolRuntimeHook.java │ │ │ ├── OnCommandInputHookImpl.java │ │ │ ├── OnCommandRespHookForMonitorCollector.java │ │ │ ├── OnCommandToUIHookImpl.java │ │ │ ├── OnErrorHookImpl.java │ │ │ └── RuntimeStage.java │ │ │ ├── http │ │ │ ├── JavaDebugToolClientDriver.java │ │ │ ├── NettyHttpServerToStandardClient.java │ │ │ ├── ReplaySubjectTest.java │ │ │ └── ShellChannelHttpServer.java │ │ │ ├── log │ │ │ ├── InternalLogger.java │ │ │ ├── InternalLoggerFactory.java │ │ │ ├── Log4jImplLogger.java │ │ │ ├── PSLogger.java │ │ │ └── StdImplLogger.java │ │ │ ├── monitor │ │ │ ├── CounterEvent.java │ │ │ ├── DefaultMonitorEventConsumer.java │ │ │ ├── MonitorCollector.java │ │ │ ├── MonitorConsume.java │ │ │ ├── MonitorEventHandler.java │ │ │ ├── MonitorHandler.java │ │ │ ├── clazz │ │ │ │ └── ClassMonitorCollector.java │ │ │ ├── cpu │ │ │ │ └── CPUCollector.java │ │ │ ├── gc │ │ │ │ └── GarbageCollectMonitorCollector.java │ │ │ ├── http │ │ │ │ └── HttpMonitorCollector.java │ │ │ ├── jetty │ │ │ │ └── JettyMonitorCollector.java │ │ │ ├── load │ │ │ │ └── LoadAverageMonitorCollector.java │ │ │ ├── mem │ │ │ │ └── MemoryMonitorCollector.java │ │ │ ├── net │ │ │ │ └── NetworkMonitorCollector.java │ │ │ ├── netty │ │ │ │ └── NettyMonitorCollector.java │ │ │ ├── runtime │ │ │ │ └── RuntimeMonitorCollector.java │ │ │ ├── sys │ │ │ │ └── SystemMonitorCollector.java │ │ │ └── thread │ │ │ │ └── ThreadMonitorCollector.java │ │ │ ├── record │ │ │ ├── InternalLoggerRecord.java │ │ │ └── Log.java │ │ │ ├── security │ │ │ ├── CRC32Utils.java │ │ │ └── ThreadSafeKeeper.java │ │ │ ├── thirdparty │ │ │ ├── ShellExecutor.java │ │ │ ├── ThirdPartyAbility.java │ │ │ ├── ThirdPartyAttribute.java │ │ │ ├── ThirdPartyRouter.java │ │ │ ├── ThirdPartySafetyController.java │ │ │ ├── ThirdPartySafetyDetective.java │ │ │ ├── asyncpprofiler │ │ │ │ └── AsyncProfilerAbility.java │ │ │ └── exception │ │ │ │ ├── ThirtPartyAbilityNotFindException.java │ │ │ │ └── ThirtyPartyExecuteException.java │ │ │ ├── transport │ │ │ ├── CDLatchTransportSubject.java │ │ │ ├── CommandCodec.java │ │ │ ├── CommandProtocol.java │ │ │ ├── Connection.java │ │ │ ├── NettyHttpTransportServer.java │ │ │ ├── NettyTransportClient.java │ │ │ ├── NettyTransportClusterClient.java │ │ │ ├── NettyTransportServer.java │ │ │ ├── NettyWebSocketTransportClient.java │ │ │ ├── NettyWebSocketTransportServer.java │ │ │ ├── RemoteCommand.java │ │ │ └── TransportSubject.java │ │ │ ├── ui │ │ │ ├── SimplePSUI.java │ │ │ └── UI.java │ │ │ └── utils │ │ │ ├── CDHelper.java │ │ │ ├── ConsoleUtils.java │ │ │ ├── FieldValueExtract.java │ │ │ ├── JacksonUtils.java │ │ │ ├── Joiner.java │ │ │ ├── MapKeyDeserializer.java │ │ │ ├── MapKeyDeserializers.java │ │ │ ├── MapKeySerializer.java │ │ │ ├── MemoryUtils.java │ │ │ ├── ObjectUtils.java │ │ │ ├── ObjectWrapper.java │ │ │ ├── Preconditions.java │ │ │ ├── Strings.java │ │ │ ├── SystemUtils.java │ │ │ ├── ThreadUtils.java │ │ │ ├── Tuple2.java │ │ │ ├── Tuple3.java │ │ │ └── UTILS.java │ ├── native │ │ ├── cputime.cpp │ │ ├── cputime.h │ │ └── pack.sh │ └── resources │ │ ├── libcputime.dylib │ │ └── libcputime.so │ └── test │ └── java │ ├── ByteStringTest.java │ ├── PatternTest.java │ ├── Test.java │ ├── UITest.java │ └── io │ └── javadebug │ └── core │ ├── JacksonUtilsTest.java │ └── transport │ └── CommandCodecTest.java ├── header ├── java-debug-tool.zip ├── oldreadme.md ├── pom.xml ├── releasenote.md ├── roadmap.md ├── script ├── hello.sh ├── javadebug-agent-attach.sh ├── javadebug-agent-launch.sh ├── javadebug-client-launch.sh ├── javadebug-cluster-launch.sh ├── javadebug-http-server.sh ├── javadebug-pack.sh ├── javadebug-simple-client.sh ├── javadebug-source-header.sh ├── javadebug-tool-install.sh ├── javadebug-unpack.sh ├── logo └── wrk_auto_benchmark.sh ├── spring ├── lib │ └── bin │ │ ├── async-profiler │ │ ├── linux │ │ │ ├── README.md │ │ │ ├── build │ │ │ │ ├── jattach │ │ │ │ └── libasyncProfiler.so │ │ │ └── profiler.sh │ │ └── mac │ │ │ ├── README.md │ │ │ ├── build │ │ │ ├── jattach │ │ │ └── libasyncProfiler.so │ │ │ └── profiler.sh │ │ ├── btrace │ │ └── BlockingThreadCheck.java │ │ ├── hello.sh │ │ ├── javadebug-agent-attach.sh │ │ ├── javadebug-agent-launch.sh │ │ ├── javadebug-client-launch.sh │ │ ├── javadebug-cluster-launch.sh │ │ ├── javadebug-http-server.sh │ │ ├── javadebug-simple-client.sh │ │ ├── javadebug-unpack.sh │ │ ├── logo │ │ └── wrk_auto_benchmark.sh ├── pom.xml └── src │ └── main │ └── java │ └── io │ └── javadebug │ └── spring │ └── JavaDebugInitializer.java ├── test ├── pom.xml └── src │ └── main │ ├── java │ ├── A.java │ ├── AplusBClass.class │ ├── AplusBClass.java │ ├── Array2Stack.java │ ├── B.java │ ├── BlockMain.java │ ├── BlockingThreadTest.java │ ├── C.java │ ├── CCT.class │ ├── CCT.java │ ├── ClassReaderTest.java │ ├── CompletableFutureTest.java │ ├── CpuBusyMock.java │ ├── DebugDemo.java │ ├── Demo.java │ ├── IFace.java │ ├── InvokeTest.java │ ├── LambdaTest$$Lambda$1.class │ ├── LambdaTest.java │ ├── ManagementFactoryTest.java │ ├── ObjectClawTest.java │ ├── ParamModel.java │ ├── R.java │ ├── RdfDemo.java │ ├── ReactorTest.java │ ├── ReturnTest.java │ ├── Runner.java │ ├── S.java │ ├── Table.java │ ├── TestCaseBase.java │ ├── Test_Fields_Extract.java │ ├── Test_Method_Trace.java │ ├── ThreeThreadsPlay.java │ ├── TryCatchFinallyTest$IntWrap.class │ ├── TryCatchFinallyTest.class │ ├── TryCatchFinallyTest.java │ ├── UnCheckedExceptionTest.class │ ├── UnCheckedExceptionTest.java │ ├── WeaveSpy.java │ ├── inner │ │ ├── InnerCalss$1.class │ │ ├── InnerCalss$InnerA.class │ │ ├── InnerCalss$InnerB.class │ │ ├── InnerCalss.class │ │ └── InnerCalss.java │ └── io │ │ └── javadebug │ │ └── test │ │ ├── TestClass.class │ │ ├── TestClass.java │ │ └── a │ │ ├── Aa.class │ │ ├── Aa.java │ │ └── Ab.java │ └── resources │ └── log4j2.xml └── usage.md /.github/workflows/maven.yml: -------------------------------------------------------------------------------- 1 | # This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time 2 | # For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-maven 3 | 4 | # This workflow uses actions that are not certified by GitHub. 5 | # They are provided by a third-party and are governed by 6 | # separate terms of service, privacy policy, and support 7 | # documentation. 8 | 9 | name: Java CI with Maven 10 | 11 | on: 12 | push: 13 | branches: [ "master" ] 14 | pull_request: 15 | branches: [ "master" ] 16 | 17 | jobs: 18 | build: 19 | 20 | runs-on: ubuntu-latest 21 | 22 | steps: 23 | - uses: actions/checkout@v3 24 | - name: Set up JDK 11 25 | uses: actions/setup-java@v3 26 | with: 27 | java-version: '11' 28 | distribution: 'temurin' 29 | cache: maven 30 | - name: Build with Maven 31 | run: mvn -B package --file pom.xml 32 | 33 | # Optional: Uploads the full dependency graph to GitHub to improve the quality of Dependabot alerts this repository can receive 34 | - name: Update dependency graph 35 | uses: advanced-security/maven-dependency-submission-action@571e99aab1055c2e71a1e2309b9691de18d6b7d6 36 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | logs 3 | out 4 | *.iml 5 | .project 6 | .classpath 7 | .settings 8 | */target 9 | */.settings 10 | */.classpath 11 | */.project 12 | */*.iml 13 | */*.ipr 14 | */*.iws 15 | */build 16 | .DS_Store 17 | */logs 18 | */scripts/*.pyc 19 | */scripts/*.*~ 20 | src/main/webapp/WEB-INF/classes 21 | src/main/webapp/META-INF/ 22 | src/test/resources/conf_path.properties 23 | target 24 | .module-cache 25 | 26 | .sass-cache 27 | src/main/webapp/static/css/**/*.css* 28 | 29 | pom.xml.versionsBackup 30 | 31 | rebel.xml 32 | *-detect.html 33 | 34 | *.log 35 | *.txt 36 | *.jar 37 | 38 | /debug-dump-dir -------------------------------------------------------------------------------- /async-profiler/linux/build/jattach: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pandening/Java-debug-tool/e12244af5c6310186ae02dce4140bd408096ba87/async-profiler/linux/build/jattach -------------------------------------------------------------------------------- /async-profiler/linux/build/libasyncProfiler.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pandening/Java-debug-tool/e12244af5c6310186ae02dce4140bd408096ba87/async-profiler/linux/build/libasyncProfiler.so -------------------------------------------------------------------------------- /async-profiler/mac/build/jattach: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pandening/Java-debug-tool/e12244af5c6310186ae02dce4140bd408096ba87/async-profiler/mac/build/jattach -------------------------------------------------------------------------------- /async-profiler/mac/build/libasyncProfiler.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pandening/Java-debug-tool/e12244af5c6310186ae02dce4140bd408096ba87/async-profiler/mac/build/libasyncProfiler.so -------------------------------------------------------------------------------- /bin/async-profiler/linux/build/jattach: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pandening/Java-debug-tool/e12244af5c6310186ae02dce4140bd408096ba87/bin/async-profiler/linux/build/jattach -------------------------------------------------------------------------------- /bin/async-profiler/linux/build/libasyncProfiler.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pandening/Java-debug-tool/e12244af5c6310186ae02dce4140bd408096ba87/bin/async-profiler/linux/build/libasyncProfiler.so -------------------------------------------------------------------------------- /bin/async-profiler/mac/build/jattach: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pandening/Java-debug-tool/e12244af5c6310186ae02dce4140bd408096ba87/bin/async-profiler/mac/build/jattach -------------------------------------------------------------------------------- /bin/async-profiler/mac/build/libasyncProfiler.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pandening/Java-debug-tool/e12244af5c6310186ae02dce4140bd408096ba87/bin/async-profiler/mac/build/libasyncProfiler.so -------------------------------------------------------------------------------- /bin/btrace/BlockingThreadCheck.java: -------------------------------------------------------------------------------- 1 | // 2 | // ======================================================================== 3 | // Copyright (c) 2018-2019 HuJian/Pandening soft collection. 4 | // ------------------------------------------------------------------------ 5 | // All rights reserved. This program and the accompanying materials 6 | // are made available under the terms of the #{license} Public License #{version} 7 | // EG: 8 | // The Eclipse Public License is available at 9 | // http://www.eclipse.org/legal/epl-v10.html 10 | // 11 | // The Apache License v2.0 is available at 12 | // http://www.opensource.org/licenses/apache2.0.php 13 | // 14 | // You may elect to redistribute this code under either of these licenses. 15 | // You should bear the consequences of using the software (named 'java-debug-tool') 16 | // and any modify must be create an new pull request and attach an text to describe 17 | // the change detail. 18 | // ======================================================================== 19 | // 20 | 21 | 22 | -------------------------------------------------------------------------------- /bin/hello.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | BASEDIR="$( cd "$( dirname "$0" )" && pwd )" 4 | 5 | # hello world 6 | echo "welcome to use java-debug-tool" 7 | 8 | cat ${BASEDIR}/logo 9 | -------------------------------------------------------------------------------- /bin/javadebug-client-launch.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Date : 2019-04-18 23:00 4 | # Auth : Hu Jian 5 | # Version : 1.0 6 | # Function : 用于调试目标JVM的客户端,请在本机启动该脚本连接远程JVM进行调试 7 | 8 | 9 | # the base dir 10 | # bin/..... 11 | EXECUTE_BASE_DIR="$( cd "$( dirname "$0" )" && pwd )" 12 | 13 | # define the default ip 14 | DEFAULT_TARGET_IP=127.0.0.1 15 | 16 | # define the default port 17 | DEFAULT_TARGET_PORT=11234 18 | 19 | function usage() { 20 | 21 | echo " 22 | java-debug-console usage: 23 | javadebug-console-launch.sh [ip:port] 24 | 25 | ip:port : the target jvm host info, optional 26 | 27 | example: 28 | ./javadebug-console-launch.sh 127.0.0.1:11234 29 | " 30 | 31 | 32 | } 33 | # parse the argument 34 | function parse_arguments() 35 | { 36 | 37 | TARGET_IP=$(echo ${1}|awk '/^[0-9]*@/;/^[^@]+:/{print "@"$1};/^[0-9]+$/'|awk -F "@|:" '{print $2}'); 38 | TARGET_PORT=$(echo ${1}|awk '/^[0-9]*@/;/^[^@]+:/{print "@"$1};/^[0-9]+$/'|awk -F ":" '{print $2}'); 39 | 40 | # # check pid 41 | # if [ -z ${TARGET_IP} ];then 42 | # echo "illegal arguments, the is required." 43 | # exit 1 44 | # fi 45 | # 46 | # # check pid 47 | # if [ -z ${TARGET_PORT} ];then 48 | # echo "illegal arguments, the is required." 49 | # exit 1 50 | # fi 51 | 52 | # set default ip 53 | [ -z ${TARGET_IP} ] && TARGET_IP=${DEFAULT_TARGET_IP} 54 | 55 | # set default port 56 | [ -z ${TARGET_PORT} ] && TARGET_PORT=${DEFAULT_TARGET_PORT} 57 | 58 | return 0 59 | 60 | } 61 | 62 | # using io.javadebug.core.TcpClient 63 | # 64 | # connect to remote jvm tcpServer to exec debug. 65 | function execConsole() { 66 | 67 | # show the usage 68 | usage 69 | 70 | echo "start to connect to remote jvm tcp server ${TARGET_IP}:${TARGET_PORT}" 71 | 72 | parse_arguments "${@}" 73 | 74 | JAVA_COMMAND="java" 75 | if [ ! -z ${JAVA_VERSION} ]; then 76 | JAVA_COMMAND="/usr/local/${JAVA_VERSION}/bin/java" 77 | fi 78 | 79 | # run tcpClient 80 | 81 | ${JAVA_COMMAND} \ 82 | -cp ${EXECUTE_BASE_DIR}/lib/debug-core.jar \ 83 | io.javadebug.core.JavaDebugClientLauncher \ 84 | -ip ${TARGET_IP} \ 85 | -port ${TARGET_PORT} 86 | 87 | } 88 | 89 | execConsole "${@}" -------------------------------------------------------------------------------- /bin/javadebug-cluster-launch.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Date : 2019-04-29 00:30 4 | # Auth : Hu Jian 5 | # Version : 1.0 6 | # Function : 用于调试多个目标JVM,前提是同一个命令向集群中的所有机器执行 7 | 8 | 9 | # the base dir 10 | # bin/..... 11 | EXECUTE_BASE_DIR="$( cd "$( dirname "$0" )" && pwd )" 12 | 13 | function usage() { 14 | 15 | echo " 16 | java-debug-cluster-console usage: 17 | javadebug-cluster-launch.sh [ip:port,ip:port,ip,port] 18 | 19 | ip:port : the target jvm host info, optional 20 | 21 | example: 22 | ./javadebug-cluster-launch.sh 127.0.0.1:11234,11235 23 | " 24 | 25 | 26 | } 27 | 28 | # using io.javadebug.core.TcpClient 29 | # 30 | # connect to remote jvm tcpServer to exec debug. 31 | function execConsole() { 32 | 33 | # show the usage 34 | usage 35 | 36 | JAVA_COMMAND="java" 37 | if [ ! -z ${JAVA_VERSION} ]; then 38 | JAVA_COMMAND="/usr/local/${JAVA_VERSION}/bin/java" 39 | fi 40 | 41 | # run tcpClient 42 | 43 | ${JAVA_COMMAND} \ 44 | -cp ${EXECUTE_BASE_DIR}/lib/debug-core.jar \ 45 | io.javadebug.core.JavaDebugClusterClientLauncher \ 46 | -p "${@}" \ 47 | 48 | } 49 | 50 | execConsole "${@}" -------------------------------------------------------------------------------- /bin/javadebug-http-server.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Date : 2019-11-24 19:31 4 | # Auth : Hu Jian 5 | # Version : 1.0 6 | # Function : 用于和目标JVM通信的http服务端,可以将命令通过http的方式进行调试 7 | 8 | # the base dir 9 | # bin/..... 10 | EXECUTE_BASE_DIR="$( cd "$( dirname "$0" )" && pwd )" 11 | 12 | REMOTE_IP="127.0.0.1" 13 | 14 | REMOTE_PORT=11234 15 | 16 | HTTP_SERVER_LISTEN_PORT=10234 17 | 18 | JAVA_COMMAND="java" 19 | 20 | 21 | # 22 | # for input some command like mt contains "#", you should 23 | # convert it to %23, the map table like this: 24 | # ======================= 25 | # character | trans 26 | # ======================= 27 | # space    %20 28 | # "        %22 29 | # #         %23 30 | # %         %25 31 | # &         %26 32 | # (         %28 33 | # )         %29 34 | # +         %2B 35 | # ,         %2C 36 | # /         %2F 37 | # :         %3A 38 | # ;         %3B 39 | # <         %3C 40 | # =         %3D 41 | # >         %3E 42 | # ?         %3F 43 | # @       %40 44 | # \         %5C 45 | # |         %7C  46 | # ======================= 47 | # 48 | 49 | # 50 | # to split the ct command's result, using grep,awk command to split the origin result 51 | # is so easy like this: 52 | # cat result.txt | grep -E ".*;.*;.*" | awk -F ';' '{print $1,$2,$3,$4}' 53 | # 54 | # 55 | 56 | # 57 | # $1 => remote ip 58 | # $2 => remote port 59 | # $3 => http server listen port 60 | # 61 | function http_server() { 62 | 63 | if [[ -n $1 ]]; then 64 | REMOTE_IP=$1 65 | fi 66 | 67 | if [[ -n $2 ]]; then 68 | REMOTE_PORT=$2 69 | fi 70 | 71 | if [[ -n $3 ]]; then 72 | HTTP_SERVER_LISTEN_PORT=$3 73 | fi 74 | 75 | echo "get the remote address : ${REMOTE_IP}:${REMOTE_PORT}, 76 | set up the http server on localhost:${HTTP_SERVER_LISTEN_PORT}, 77 | Open your web browser and navigate to 78 | http://127.0.0.1:${HTTP_SERVER_LISTEN_PORT}/java-debug-tool/shell/http/" 79 | 80 | ${JAVA_COMMAND} \ 81 | -cp ${EXECUTE_BASE_DIR}/lib/debug-core.jar \ 82 | io.javadebug.core.JavaDebugHttpServerLauncher \ 83 | ${REMOTE_IP} \ 84 | ${REMOTE_PORT} \ 85 | ${HTTP_SERVER_LISTEN_PORT} \ 86 | & 87 | 88 | } 89 | 90 | 91 | # set up the http server 92 | http_server "${@}" 93 | -------------------------------------------------------------------------------- /bin/javadebug-simple-client.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Date : 2019-04-18 23:00 4 | # Auth : Hu Jian 5 | # Version : 1.0 6 | # Function : 用于调试目标JVM的客户端,请在本机启动该脚本连接远程JVM进行调试 7 | 8 | 9 | # the base dir 10 | # bin/..... 11 | EXECUTE_BASE_DIR="$( cd "$( dirname "$0" )" && pwd )" 12 | 13 | # define the default ip 14 | DEFAULT_TARGET_IP=127.0.0.1 15 | 16 | # define the default port 17 | DEFAULT_TARGET_PORT=11234 18 | 19 | # java version 20 | JAVA_VERSION=java8 21 | 22 | function usage() { 23 | 24 | echo " 25 | java-debug-console usage: 26 | javadebug-console-launch.sh [ip:port] 27 | 28 | ip:port : the target jvm host info, optional 29 | 30 | example: 31 | ./javadebug-console-launch.sh 127.0.0.1:11234 32 | " 33 | 34 | 35 | } 36 | # parse the argument 37 | function parse_arguments() 38 | { 39 | 40 | TARGET_IP=$(echo ${1}|awk '/^[0-9]*@/;/^[^@]+:/{print "@"$1};/^[0-9]+$/'|awk -F "@|:" '{print $2}'); 41 | TARGET_PORT=$(echo ${1}|awk '/^[0-9]*@/;/^[^@]+:/{print "@"$1};/^[0-9]+$/'|awk -F ":" '{print $2}'); 42 | 43 | # # check pid 44 | # if [ -z ${TARGET_IP} ];then 45 | # echo "illegal arguments, the is required." 46 | # exit 1 47 | # fi 48 | # 49 | # # check pid 50 | # if [ -z ${TARGET_PORT} ];then 51 | # echo "illegal arguments, the is required." 52 | # exit 1 53 | # fi 54 | 55 | # set default ip 56 | [[ -z ${TARGET_IP} ]] && TARGET_IP=${DEFAULT_TARGET_IP} 57 | 58 | # set default port 59 | [[ -z ${TARGET_PORT} ]] && TARGET_PORT=${DEFAULT_TARGET_PORT} 60 | 61 | return 0 62 | 63 | } 64 | 65 | # using io.javadebug.core.TcpClient 66 | # 67 | # connect to remote jvm tcpServer to exec debug. 68 | function execConsole() { 69 | 70 | # show the usage 71 | usage 72 | 73 | echo "start to connect to remote jvm tcp server ${TARGET_IP}:${TARGET_PORT}" 74 | 75 | parse_arguments "${@}" 76 | 77 | JAVA_COMMAND="/usr/local/${JAVA_VERSION}/bin/java" 78 | 79 | # run tcpClient 80 | 81 | ${JAVA_COMMAND} \ 82 | -cp ${EXECUTE_BASE_DIR}/lib/debug-core.jar \ 83 | io.javadebug.core.JavaDebugClientLauncher \ 84 | -ip ${TARGET_IP} \ 85 | -port ${TARGET_PORT} 86 | 87 | } 88 | 89 | execConsole "${@}" -------------------------------------------------------------------------------- /bin/javadebug-unpack.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Date : 2019-04-21 22:50 4 | # Auth : Hu Jian 5 | # Version : 1.0 6 | # Function : 仅用来解压core jar包,名字不要乱改 7 | 8 | BASEDIR="$( cd "$( dirname "$0" )" && pwd )" 9 | 10 | # 11 | # 解压core jar包至指定目录 12 | # 13 | function unpack() { 14 | JAR_PATH=${BASEDIR}/../bin/lib/debug-core.jar 15 | TARGET_DIR=${BASEDIR}/../bin/jar 16 | if [ ! -f ${JAR_PATH} ]; then 17 | echo "" # do not speak 18 | else 19 | if [ ! -d ${TARGET_DIR} ]; then 20 | mkdir ${TARGET_DIR} 21 | else 22 | rm -rf ${TARGET_DIR} 23 | fi 24 | unzip ${JAR_PATH} -d ${TARGET_DIR} 25 | echo ${TARGET_DIR} 26 | fi 27 | } 28 | 29 | # unpack 30 | unpack 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /bin/logo: -------------------------------------------------------------------------------- 1 | 2 | ___ ___ 3 | ---------------------/\------\ \------------------/ /----/\--------------- 4 | \ | / \ \ \ / / / \ dynamic java debug tool 5 | | | / \ \ \ / / / \ V 2.0 6 | | | / /\ \ \ \ / / / /\ \ by H.J 7 | | | / / \ \ \ \ / / / / \ \ | 8 | | | / / \ \ \ \ / / / / \ \ | There is no bug in this project. 9 | | | / /------\ \ \ \ / / / /------\ \ | beg for this. 10 | | | / /--------\ \ \ \ / / / /--------\ \ | thanks. 11 | |\___| | / / \ \ \ \ / / / / \ \ | 12 | \_______|______/__/____________\__\______\__\/__/____/__/____________\__\______ 13 | |\______| /__/ \__\ \____/ /__/ \__\ | 14 | | (1) ./javadebug-agent-attach.sh + pid | 15 | | (2) ./javadebug-client-lanuch.sh | 16 | |______________________________________________________________________________| 17 | | | 18 | | | 19 | |>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>| 20 | | blog link : https://www.jianshu.com/u/86c421886c32 | 21 | | special post : https://mp.weixin.qq.com/s/ZlNcvwJ_swspifWTLHA92Q | 22 | | | 23 | \_____________________________________________________________________________/ 24 | -------------------------------------------------------------------------------- /core/src/main/java/io/javadebug/com/netflix/numerus/NumerusProperty.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2014 Netflix, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.javadebug.com.netflix.numerus; 17 | 18 | /** 19 | * Generic interface to represent a property value so Hystrix can consume properties without being tied to any particular backing implementation. 20 | * 21 | * @param 22 | * Type of property value 23 | */ 24 | public interface NumerusProperty { 25 | 26 | public T get(); 27 | 28 | /** 29 | * Helper methods for wrapping static values. 30 | */ 31 | public static class Factory { 32 | 33 | public static NumerusProperty asProperty(final T value) { 34 | return new NumerusProperty() { 35 | 36 | @Override 37 | public T get() { 38 | return value; 39 | } 40 | 41 | }; 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /core/src/main/java/io/javadebug/com/netflix/numerus/NumerusRollingNumberEvent.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2014 Netflix, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.javadebug.com.netflix.numerus; 17 | 18 | /** 19 | * Various states/events that can be captured in the {@link NumerusRollingNumber}. 20 | *

21 | * Note that events are defined as different types: 22 | *

    23 | *
  • Counter: isCounter() == true
  • 24 | *
  • MaxUpdater: isMaxUpdater() == true
  • 25 | *
26 | *

27 | * The Counter type events can be used with {@link NumerusRollingNumber#increment}, {@link NumerusRollingNumber#add}, {@link NumerusRollingNumber#getRollingSum} and others. 28 | *

29 | * The MaxUpdater type events can be used with {@link NumerusRollingNumber#updateRollingMax} and {@link NumerusRollingNumber#getRollingMaxValue}. 30 | */ 31 | public interface NumerusRollingNumberEvent { 32 | 33 | public boolean isCounter(); 34 | 35 | public boolean isMaxUpdater(); 36 | 37 | public NumerusRollingNumberEvent[] getValues(); 38 | 39 | public int ordinal(); 40 | 41 | public String name(); 42 | } -------------------------------------------------------------------------------- /core/src/main/java/io/javadebug/core/CommandInputHandler.java: -------------------------------------------------------------------------------- 1 | // 2 | // ======================================================================== 3 | // Copyright (c) 2018-2019 HuJian/Pandening soft collection. 4 | // ------------------------------------------------------------------------ 5 | // All rights reserved. This program and the accompanying materials 6 | // are made available under the terms of the #{license} Public License #{version} 7 | // EG: 8 | // The Eclipse Public License is available at 9 | // http://www.eclipse.org/legal/epl-v10.html 10 | // 11 | // The Apache License v2.0 is available at 12 | // http://www.opensource.org/licenses/apache2.0.php 13 | // 14 | // You may elect to redistribute this code under either of these licenses. 15 | // You should bear the consequences of using the software (named 'java-debug-tool') 16 | // and any modify must be create an new pull request and attach an text to describe 17 | // the change detail. 18 | // ======================================================================== 19 | // 20 | 21 | 22 | /** 23 | * Copyright © 2019-XXX HJ All Rights Reserved 24 | * 25 | * 26 | * 27 | * 28 | * 29 | * 30 | * 31 | * 32 | * 33 | */ 34 | // Author : HJ 35 | 36 | 37 | package io.javadebug.core; 38 | 39 | import io.javadebug.core.transport.RemoteCommand; 40 | 41 | /** 42 | * Created on 2019/4/22 23:13. 43 | * 44 | * @author HuJian 45 | */ 46 | public interface CommandInputHandler { 47 | 48 | /** 49 | * 这个方法用来实现将客户端的命令输入转换成{@link RemoteCommand}的过程 50 | * 是命令在客户端输入之后的处理 51 | * 52 | * @param args 命令参数 53 | * @param origin 客户端持有的协议对象 54 | * @return {@link RemoteCommand} 最终将被传输到服务端的命令协议 55 | * @throws Exception 处理异常 56 | */ 57 | RemoteCommand toCommand(String[] args, RemoteCommand origin) throws Exception; 58 | 59 | } 60 | -------------------------------------------------------------------------------- /core/src/main/java/io/javadebug/core/CommandRequestHandler.java: -------------------------------------------------------------------------------- 1 | // 2 | // ======================================================================== 3 | // Copyright (c) 2018-2019 HuJian/Pandening soft collection. 4 | // ------------------------------------------------------------------------ 5 | // All rights reserved. This program and the accompanying materials 6 | // are made available under the terms of the #{license} Public License #{version} 7 | // EG: 8 | // The Eclipse Public License is available at 9 | // http://www.eclipse.org/legal/epl-v10.html 10 | // 11 | // The Apache License v2.0 is available at 12 | // http://www.opensource.org/licenses/apache2.0.php 13 | // 14 | // You may elect to redistribute this code under either of these licenses. 15 | // You should bear the consequences of using the software (named 'java-debug-tool') 16 | // and any modify must be create an new pull request and attach an text to describe 17 | // the change detail. 18 | // ======================================================================== 19 | // 20 | 21 | 22 | /** 23 | * Copyright © 2019-XXX HJ All Rights Reserved 24 | * 25 | * 26 | * 27 | * 28 | * 29 | * 30 | * 31 | * 32 | * 33 | */ 34 | // Auth : HJ 35 | 36 | 37 | package io.javadebug.core; 38 | 39 | import io.javadebug.core.transport.RemoteCommand; 40 | 41 | /** 42 | * Created on 2019/4/20 16:21. 43 | * 44 | * @author HuJian 45 | */ 46 | public interface CommandRequestHandler { 47 | 48 | 49 | /** 50 | * 这个方法用来产生远程请求 51 | * 52 | * @return {@link RemoteCommand} 53 | */ 54 | RemoteCommand get(); 55 | 56 | /** 57 | * 用于监听命令请求创建的消息 58 | * 59 | * @param remoteCommand 这是一个客户端持有的命令对象,一个连接使用一个命令对象即可 60 | * @param cmd 原始输入命令 61 | * @return 如果返回false,则重新输入 62 | */ 63 | RemoteCommand onCreateRequest(String cmd, RemoteCommand remoteCommand); 64 | 65 | } 66 | -------------------------------------------------------------------------------- /core/src/main/java/io/javadebug/core/CommandServer.java: -------------------------------------------------------------------------------- 1 | // 2 | // ======================================================================== 3 | // Copyright (c) 2018-2019 HuJian/Pandening soft collection. 4 | // ------------------------------------------------------------------------ 5 | // All rights reserved. This program and the accompanying materials 6 | // are made available under the terms of the #{license} Public License #{version} 7 | // EG: 8 | // The Eclipse Public License is available at 9 | // http://www.eclipse.org/legal/epl-v10.html 10 | // 11 | // The Apache License v2.0 is available at 12 | // http://www.opensource.org/licenses/apache2.0.php 13 | // 14 | // You may elect to redistribute this code under either of these licenses. 15 | // You should bear the consequences of using the software (named 'java-debug-tool') 16 | // and any modify must be create an new pull request and attach an text to describe 17 | // the change detail. 18 | // ======================================================================== 19 | // 20 | 21 | 22 | /** 23 | * Copyright © 2019-XXX HJ All Rights Reserved 24 | * 25 | * 26 | * 27 | * 28 | * 29 | * 30 | * 31 | * 32 | * 33 | */ 34 | // Author : HJ 35 | 36 | 37 | package io.javadebug.core; 38 | 39 | import io.javadebug.core.command.Command; 40 | 41 | /** 42 | * Created on 2019/4/22 23:01. 43 | * 44 | * @author HuJian 45 | */ 46 | public interface CommandServer { 47 | 48 | /** 49 | * 根据命令名字获取到命令类型 50 | * 51 | * @param cmd 命令名字 52 | * @return 获取到的命令类型,如果没有发现,那么就是null 53 | */ 54 | Class queryCommand(String cmd); 55 | 56 | /** 57 | * 新建一个命令 58 | * 59 | * @param cmd 命令名字 60 | * @return {@link Command} 61 | */ 62 | Command newCommand(String cmd); 63 | 64 | } 65 | -------------------------------------------------------------------------------- /core/src/main/java/io/javadebug/core/Error.java: -------------------------------------------------------------------------------- 1 | // 2 | // ======================================================================== 3 | // Copyright (c) 2018-2019 HuJian/Pandening soft collection. 4 | // ------------------------------------------------------------------------ 5 | // All rights reserved. This program and the accompanying materials 6 | // are made available under the terms of the #{license} Public License #{version} 7 | // EG: 8 | // The Eclipse Public License is available at 9 | // http://www.eclipse.org/legal/epl-v10.html 10 | // 11 | // The Apache License v2.0 is available at 12 | // http://www.opensource.org/licenses/apache2.0.php 13 | // 14 | // You may elect to redistribute this code under either of these licenses. 15 | // You should bear the consequences of using the software (named 'java-debug-tool') 16 | // and any modify must be create an new pull request and attach an text to describe 17 | // the change detail. 18 | // ======================================================================== 19 | // 20 | 21 | 22 | /** 23 | * Copyright © 2019-XXX HJ All Rights Reserved 24 | * 25 | * 26 | * 27 | * 28 | * 29 | * 30 | * 31 | * 32 | * 33 | */ 34 | // Author : HJ 35 | 36 | 37 | package io.javadebug.core; 38 | 39 | public enum Error { 40 | 41 | ; 42 | 43 | private int errorCode; 44 | private String errorMsg; 45 | private String hint; 46 | 47 | @Override 48 | public String toString() { 49 | return "Error{" + 50 | "errorCode=" + errorCode + 51 | ", errorMsg='" + errorMsg + '\'' + 52 | ", hint='" + hint + '\'' + 53 | '}'; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /core/src/main/java/io/javadebug/core/JavaDebugHttpServerLauncher.java: -------------------------------------------------------------------------------- 1 | // 2 | // ======================================================================== 3 | // Copyright (c) 2018-2019 HuJian/Pandening soft collection. 4 | // ------------------------------------------------------------------------ 5 | // All rights reserved. This program and the accompanying materials 6 | // are made available under the terms of the #{license} Public License #{version} 7 | // EG: 8 | // The Eclipse Public License is available at 9 | // http://www.eclipse.org/legal/epl-v10.html 10 | // 11 | // The Apache License v2.0 is available at 12 | // http://www.opensource.org/licenses/apache2.0.php 13 | // 14 | // You may elect to redistribute this code under either of these licenses. 15 | // You should bear the consequences of using the software (named 'java-debug-tool') 16 | // and any modify must be create an new pull request and attach an text to describe 17 | // the change detail. 18 | // ======================================================================== 19 | // 20 | 21 | 22 | package io.javadebug.core; 23 | 24 | import io.javadebug.core.utils.UTILS; 25 | 26 | import static io.javadebug.core.http.ShellChannelHttpServer.SHELL_CHANNEL_HTTP_SERVER; 27 | 28 | public class JavaDebugHttpServerLauncher { 29 | 30 | public static void main(String[] args) throws InterruptedException { 31 | 32 | if (args == null || args.length != 3) { 33 | throw new IllegalArgumentException("invalid params, could not set up the http server ..."); 34 | } 35 | 36 | String ip = args[0]; 37 | String port = args[1]; 38 | String listenPort = args[2]; 39 | 40 | int portNumber = UTILS.safeParseInt(port, -1); 41 | if (portNumber <= 0) { 42 | throw new IllegalArgumentException("invalid port number :" + port); 43 | } 44 | 45 | int listenOn = UTILS.safeParseInt(listenPort, -1); 46 | if (listenOn <= 0) { 47 | throw new IllegalArgumentException("invalid http listen port : " + listenPort); 48 | } 49 | 50 | // set up the http server on 10234 51 | SHELL_CHANNEL_HTTP_SERVER.setup(ip, portNumber, listenOn); 52 | 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /core/src/main/java/io/javadebug/core/RemoteServer.java: -------------------------------------------------------------------------------- 1 | // 2 | // ======================================================================== 3 | // Copyright (c) 2018-2019 HuJian/Pandening soft collection. 4 | // ------------------------------------------------------------------------ 5 | // All rights reserved. This program and the accompanying materials 6 | // are made available under the terms of the #{license} Public License #{version} 7 | // EG: 8 | // The Eclipse Public License is available at 9 | // http://www.eclipse.org/legal/epl-v10.html 10 | // 11 | // The Apache License v2.0 is available at 12 | // http://www.opensource.org/licenses/apache2.0.php 13 | // 14 | // You may elect to redistribute this code under either of these licenses. 15 | // You should bear the consequences of using the software (named 'java-debug-tool') 16 | // and any modify must be create an new pull request and attach an text to describe 17 | // the change detail. 18 | // ======================================================================== 19 | // 20 | 21 | 22 | /** 23 | * Copyright © 2019-XXX HJ All Rights Reserved 24 | * 25 | * 26 | * 27 | * 28 | * 29 | * 30 | * 31 | * 32 | * 33 | */ 34 | // Auth : HJ 35 | 36 | 37 | package io.javadebug.core; 38 | 39 | /** 40 | * Created on 2019/4/17 16:51. 41 | * 42 | * @author HuJian 43 | */ 44 | public interface RemoteServer { 45 | 46 | /** 47 | * 判断服务端是否已经就绪了 48 | * 49 | * @return true代表服务端已经就绪,可以accept 50 | */ 51 | boolean isBind(); 52 | 53 | /** 54 | * 执行服务端bind等逻辑,不同类型的服务端初始化过程可能不一样,但是执行完该方法之后,服务端 55 | * 必须有能力处理客户端连接; 56 | * 57 | * @param configure {@link Configure} 58 | */ 59 | void start(Configure configure) throws Exception; 60 | 61 | /** 62 | * 客户端要求服务端关闭,这一般出现在最后一个debug的人发出了关闭服务端的命令,只要服务端还在 63 | * 为至少一个客户端服务,那么就不应该关闭服务端,所以服务端需要记录每一个连接,并有能力在需要 64 | * 的时候将服务端关闭; 65 | * 66 | * @param configure {@link Configure} 67 | */ 68 | void stop(Configure configure) throws Exception; 69 | 70 | /** 71 | * 关闭服务端 72 | * 73 | * @throws Exception 处理异常 74 | */ 75 | void stop() throws Exception; 76 | 77 | } 78 | -------------------------------------------------------------------------------- /core/src/main/java/io/javadebug/core/annotation/CommandType.java: -------------------------------------------------------------------------------- 1 | // 2 | // ======================================================================== 3 | // Copyright (c) 2018-2019 HuJian/Pandening soft collection. 4 | // ------------------------------------------------------------------------ 5 | // All rights reserved. This program and the accompanying materials 6 | // are made available under the terms of the #{license} Public License #{version} 7 | // EG: 8 | // The Eclipse Public License is available at 9 | // http://www.eclipse.org/legal/epl-v10.html 10 | // 11 | // The Apache License v2.0 is available at 12 | // http://www.opensource.org/licenses/apache2.0.php 13 | // 14 | // You may elect to redistribute this code under either of these licenses. 15 | // You should bear the consequences of using the software (named 'java-debug-tool') 16 | // and any modify must be create an new pull request and attach an text to describe 17 | // the change detail. 18 | // ======================================================================== 19 | // 20 | 21 | 22 | /** 23 | * Copyright © 2019-XXX HJ All Rights Reserved 24 | * 25 | * 26 | * 27 | * 28 | * 29 | * 30 | * 31 | * 32 | * 33 | */ 34 | // Author : HJ 35 | 36 | 37 | package io.javadebug.core.annotation; 38 | 39 | /** 40 | * Created on 2019/4/21 13:13. 41 | * 42 | * @author HuJian 43 | */ 44 | public enum CommandType { 45 | 46 | /// 命令的类型,分为下面几类 47 | 48 | OBSERVE, // 观察型,这类命令将会对某种事物进行观察,并进行报告 49 | COMPUTE, // 计算型,这类命令会在目标JVM上执行一些计算,并进行响应 50 | EXECUTE, // 代码执行,这类命令称为"远程代码执行",较为危险,暂不支持 51 | ENHANCE // 增强型,这类命令的特点就是对目标JVM进行字节码在增强 52 | 53 | ; 54 | } 55 | -------------------------------------------------------------------------------- /core/src/main/java/io/javadebug/core/claw/ArrayClawImpl.java: -------------------------------------------------------------------------------- 1 | // 2 | // ======================================================================== 3 | // Copyright (c) 2018-2019 HuJian/Pandening soft collection. 4 | // ------------------------------------------------------------------------ 5 | // All rights reserved. This program and the accompanying materials 6 | // are made available under the terms of the #{license} Public License #{version} 7 | // EG: 8 | // The Eclipse Public License is available at 9 | // http://www.eclipse.org/legal/epl-v10.html 10 | // 11 | // The Apache License v2.0 is available at 12 | // http://www.opensource.org/licenses/apache2.0.php 13 | // 14 | // You may elect to redistribute this code under either of these licenses. 15 | // You should bear the consequences of using the software (named 'java-debug-tool') 16 | // and any modify must be create an new pull request and attach an text to describe 17 | // the change detail. 18 | // ======================================================================== 19 | // 20 | 21 | 22 | package io.javadebug.core.claw; 23 | 24 | import java.lang.reflect.Field; 25 | 26 | public enum ArrayClawImpl implements ObjectClawDefine { 27 | ARRAY_CLAW; 28 | 29 | @Override 30 | public ObjectClawDefine set(Object originObject, Field classField, String targetVal) { 31 | return null; 32 | } 33 | 34 | @Override 35 | public void set(ClawMeta clawMeta) { 36 | 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /core/src/main/java/io/javadebug/core/claw/BooleanClawImpl.java: -------------------------------------------------------------------------------- 1 | // 2 | // ======================================================================== 3 | // Copyright (c) 2018-2019 HuJian/Pandening soft collection. 4 | // ------------------------------------------------------------------------ 5 | // All rights reserved. This program and the accompanying materials 6 | // are made available under the terms of the #{license} Public License #{version} 7 | // EG: 8 | // The Eclipse Public License is available at 9 | // http://www.eclipse.org/legal/epl-v10.html 10 | // 11 | // The Apache License v2.0 is available at 12 | // http://www.opensource.org/licenses/apache2.0.php 13 | // 14 | // You may elect to redistribute this code under either of these licenses. 15 | // You should bear the consequences of using the software (named 'java-debug-tool') 16 | // and any modify must be create an new pull request and attach an text to describe 17 | // the change detail. 18 | // ======================================================================== 19 | // 20 | 21 | 22 | package io.javadebug.core.claw; 23 | 24 | import io.javadebug.core.utils.UTILS; 25 | 26 | import java.lang.reflect.Field; 27 | 28 | public enum BooleanClawImpl implements ObjectClawDefine { 29 | BOOLEAN_CLAW; 30 | 31 | @Override 32 | public ObjectClawDefine set(Object originObject, Field classField, String targetVal) { 33 | boolean accessible = true; 34 | try { 35 | if (!classField.isAccessible()) { 36 | accessible = false; 37 | classField.setAccessible(true); 38 | } 39 | Boolean bVal = Boolean.valueOf(targetVal); 40 | classField.set(originObject, bVal); 41 | } catch (Exception e) { 42 | throw new ClassCastException(UTILS.getErrorMsg(e)); 43 | } finally { 44 | if (!accessible) { 45 | classField.setAccessible(false); 46 | } 47 | } 48 | return this; 49 | } 50 | 51 | @Override 52 | public void set(ClawMeta clawMeta) { 53 | 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /core/src/main/java/io/javadebug/core/claw/ByteClawImpl.java: -------------------------------------------------------------------------------- 1 | // 2 | // ======================================================================== 3 | // Copyright (c) 2018-2019 HuJian/Pandening soft collection. 4 | // ------------------------------------------------------------------------ 5 | // All rights reserved. This program and the accompanying materials 6 | // are made available under the terms of the #{license} Public License #{version} 7 | // EG: 8 | // The Eclipse Public License is available at 9 | // http://www.eclipse.org/legal/epl-v10.html 10 | // 11 | // The Apache License v2.0 is available at 12 | // http://www.opensource.org/licenses/apache2.0.php 13 | // 14 | // You may elect to redistribute this code under either of these licenses. 15 | // You should bear the consequences of using the software (named 'java-debug-tool') 16 | // and any modify must be create an new pull request and attach an text to describe 17 | // the change detail. 18 | // ======================================================================== 19 | // 20 | 21 | 22 | package io.javadebug.core.claw; 23 | 24 | import io.javadebug.core.utils.UTILS; 25 | 26 | import java.lang.reflect.Field; 27 | 28 | public enum ByteClawImpl implements ObjectClawDefine { 29 | BYTE_CLAW; 30 | 31 | @Override 32 | public ObjectClawDefine set(Object originObject, Field classField, String targetVal) { 33 | boolean accessible = true; 34 | try { 35 | if (!classField.isAccessible()) { 36 | accessible = false; 37 | classField.setAccessible(true); 38 | } 39 | byte bVal = Byte.valueOf(targetVal); 40 | classField.set(originObject, bVal); 41 | } catch (Exception e) { 42 | throw new ClassCastException(UTILS.getErrorMsg(e)); 43 | } finally { 44 | if (!accessible) { 45 | classField.setAccessible(false); 46 | } 47 | } 48 | return this; 49 | } 50 | 51 | @Override 52 | public void set(ClawMeta clawMeta) { 53 | 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /core/src/main/java/io/javadebug/core/claw/CharClawImpl.java: -------------------------------------------------------------------------------- 1 | // 2 | // ======================================================================== 3 | // Copyright (c) 2018-2019 HuJian/Pandening soft collection. 4 | // ------------------------------------------------------------------------ 5 | // All rights reserved. This program and the accompanying materials 6 | // are made available under the terms of the #{license} Public License #{version} 7 | // EG: 8 | // The Eclipse Public License is available at 9 | // http://www.eclipse.org/legal/epl-v10.html 10 | // 11 | // The Apache License v2.0 is available at 12 | // http://www.opensource.org/licenses/apache2.0.php 13 | // 14 | // You may elect to redistribute this code under either of these licenses. 15 | // You should bear the consequences of using the software (named 'java-debug-tool') 16 | // and any modify must be create an new pull request and attach an text to describe 17 | // the change detail. 18 | // ======================================================================== 19 | // 20 | 21 | 22 | package io.javadebug.core.claw; 23 | 24 | import io.javadebug.core.utils.UTILS; 25 | 26 | import java.lang.reflect.Field; 27 | 28 | public enum CharClawImpl implements ObjectClawDefine { 29 | CHAR_CLAW; 30 | 31 | @Override 32 | public ObjectClawDefine set(Object originObject, Field classField, String targetVal) { 33 | if (targetVal == null) { 34 | return this; 35 | } 36 | boolean accessible = true; 37 | try { 38 | if (!classField.isAccessible()) { 39 | accessible = false; 40 | classField.setAccessible(true); 41 | } 42 | 43 | if (targetVal.length() > 1) { 44 | throw new ClassCastException("[claw set value] error char value set:" + targetVal); 45 | } 46 | 47 | char bVal = targetVal.charAt(0); 48 | classField.set(originObject, bVal); 49 | } catch (Exception e) { 50 | throw new ClassCastException(UTILS.getErrorMsg(e)); 51 | } finally { 52 | if (!accessible) { 53 | classField.setAccessible(false); 54 | } 55 | } 56 | return this; 57 | } 58 | 59 | @Override 60 | public void set(ClawMeta clawMeta) { 61 | 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /core/src/main/java/io/javadebug/core/claw/ListClawImpl.java: -------------------------------------------------------------------------------- 1 | // 2 | // ======================================================================== 3 | // Copyright (c) 2018-2019 HuJian/Pandening soft collection. 4 | // ------------------------------------------------------------------------ 5 | // All rights reserved. This program and the accompanying materials 6 | // are made available under the terms of the #{license} Public License #{version} 7 | // EG: 8 | // The Eclipse Public License is available at 9 | // http://www.eclipse.org/legal/epl-v10.html 10 | // 11 | // The Apache License v2.0 is available at 12 | // http://www.opensource.org/licenses/apache2.0.php 13 | // 14 | // You may elect to redistribute this code under either of these licenses. 15 | // You should bear the consequences of using the software (named 'java-debug-tool') 16 | // and any modify must be create an new pull request and attach an text to describe 17 | // the change detail. 18 | // ======================================================================== 19 | // 20 | 21 | 22 | package io.javadebug.core.claw; 23 | 24 | import io.javadebug.core.exception.ClawScriptScanException; 25 | 26 | import java.lang.reflect.Field; 27 | 28 | @SuppressWarnings("unchecked") 29 | public enum ListClawImpl implements ObjectClawDefine { 30 | LIST_CLAW; 31 | 32 | @Override 33 | public ObjectClawDefine set(Object originObject, Field classField, String targetVal) { 34 | return null; 35 | } 36 | 37 | @Override 38 | public void set(ClawMeta clawMeta) { 39 | throw new ClawScriptScanException("[sad] un-support operation: claw list"); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /core/src/main/java/io/javadebug/core/claw/LongClawImpl.java: -------------------------------------------------------------------------------- 1 | // 2 | // ======================================================================== 3 | // Copyright (c) 2018-2019 HuJian/Pandening soft collection. 4 | // ------------------------------------------------------------------------ 5 | // All rights reserved. This program and the accompanying materials 6 | // are made available under the terms of the #{license} Public License #{version} 7 | // EG: 8 | // The Eclipse Public License is available at 9 | // http://www.eclipse.org/legal/epl-v10.html 10 | // 11 | // The Apache License v2.0 is available at 12 | // http://www.opensource.org/licenses/apache2.0.php 13 | // 14 | // You may elect to redistribute this code under either of these licenses. 15 | // You should bear the consequences of using the software (named 'java-debug-tool') 16 | // and any modify must be create an new pull request and attach an text to describe 17 | // the change detail. 18 | // ======================================================================== 19 | // 20 | 21 | 22 | package io.javadebug.core.claw; 23 | 24 | import io.javadebug.core.utils.UTILS; 25 | 26 | import java.lang.reflect.Field; 27 | 28 | public enum LongClawImpl implements ObjectClawDefine { 29 | LONG_CLAW; 30 | 31 | @Override 32 | public ObjectClawDefine set(Object originObject, Field classField, String targetVal) { 33 | boolean accessible = true; 34 | try { 35 | if (!classField.isAccessible()) { 36 | accessible = false; 37 | classField.setAccessible(true); 38 | } 39 | long lVal = Long.valueOf(targetVal); 40 | classField.set(originObject, lVal); 41 | } catch (Exception e) { 42 | throw new ClassCastException(UTILS.getErrorMsg(e)); 43 | } finally { 44 | if (!accessible) { 45 | classField.setAccessible(false); 46 | } 47 | } 48 | return this; 49 | } 50 | 51 | @Override 52 | public void set(ClawMeta clawMeta) { 53 | 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /core/src/main/java/io/javadebug/core/claw/MapClawImpl.java: -------------------------------------------------------------------------------- 1 | // 2 | // ======================================================================== 3 | // Copyright (c) 2018-2019 HuJian/Pandening soft collection. 4 | // ------------------------------------------------------------------------ 5 | // All rights reserved. This program and the accompanying materials 6 | // are made available under the terms of the #{license} Public License #{version} 7 | // EG: 8 | // The Eclipse Public License is available at 9 | // http://www.eclipse.org/legal/epl-v10.html 10 | // 11 | // The Apache License v2.0 is available at 12 | // http://www.opensource.org/licenses/apache2.0.php 13 | // 14 | // You may elect to redistribute this code under either of these licenses. 15 | // You should bear the consequences of using the software (named 'java-debug-tool') 16 | // and any modify must be create an new pull request and attach an text to describe 17 | // the change detail. 18 | // ======================================================================== 19 | // 20 | 21 | 22 | package io.javadebug.core.claw; 23 | 24 | import io.javadebug.core.exception.ClawScriptScanException; 25 | 26 | import java.lang.reflect.Field; 27 | 28 | public enum MapClawImpl implements ObjectClawDefine { 29 | MAP_CLAW; 30 | 31 | @Override 32 | public ObjectClawDefine set(Object originObject, Field classField, String targetVal) { 33 | throw new ClawScriptScanException("[sad] un-support operation: claw map"); 34 | } 35 | 36 | @Override 37 | public void set(ClawMeta clawMeta) { 38 | throw new ClawScriptScanException("[sad] un-support operation: claw map"); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /core/src/main/java/io/javadebug/core/claw/ObjectClawDefine.java: -------------------------------------------------------------------------------- 1 | // 2 | // ======================================================================== 3 | // Copyright (c) 2018-2019 HuJian/Pandening soft collection. 4 | // ------------------------------------------------------------------------ 5 | // All rights reserved. This program and the accompanying materials 6 | // are made available under the terms of the #{license} Public License #{version} 7 | // EG: 8 | // The Eclipse Public License is available at 9 | // http://www.eclipse.org/legal/epl-v10.html 10 | // 11 | // The Apache License v2.0 is available at 12 | // http://www.opensource.org/licenses/apache2.0.php 13 | // 14 | // You may elect to redistribute this code under either of these licenses. 15 | // You should bear the consequences of using the software (named 'java-debug-tool') 16 | // and any modify must be create an new pull request and attach an text to describe 17 | // the change detail. 18 | // ======================================================================== 19 | // 20 | 21 | 22 | package io.javadebug.core.claw; 23 | 24 | import java.lang.reflect.Field; 25 | 26 | public interface ObjectClawDefine { 27 | 28 | ObjectClawDefine set(Object originObject, Field classField, String targetVal); 29 | 30 | void set(ClawMeta clawMeta); 31 | 32 | class ObjectClawFactory { 33 | 34 | /** 35 | * this method will dispatch the {@link ObjectClawDefine} 36 | * also see {@link ClawSupportTypes#dispatch(Field)} 37 | * 38 | * @param classField the class Field info 39 | * @return the matched {@link ObjectClawDefine} or Null 40 | */ 41 | public static ObjectClawDefine dispatchClaw(Field classField) { 42 | return ClawSupportTypes.dispatch(classField); 43 | } 44 | 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /core/src/main/java/io/javadebug/core/claw/SetClawImpl.java: -------------------------------------------------------------------------------- 1 | // 2 | // ======================================================================== 3 | // Copyright (c) 2018-2019 HuJian/Pandening soft collection. 4 | // ------------------------------------------------------------------------ 5 | // All rights reserved. This program and the accompanying materials 6 | // are made available under the terms of the #{license} Public License #{version} 7 | // EG: 8 | // The Eclipse Public License is available at 9 | // http://www.eclipse.org/legal/epl-v10.html 10 | // 11 | // The Apache License v2.0 is available at 12 | // http://www.opensource.org/licenses/apache2.0.php 13 | // 14 | // You may elect to redistribute this code under either of these licenses. 15 | // You should bear the consequences of using the software (named 'java-debug-tool') 16 | // and any modify must be create an new pull request and attach an text to describe 17 | // the change detail. 18 | // ======================================================================== 19 | // 20 | 21 | 22 | package io.javadebug.core.claw; 23 | 24 | import io.javadebug.core.exception.ClawScriptScanException; 25 | 26 | import java.lang.reflect.Field; 27 | 28 | public enum SetClawImpl implements ObjectClawDefine { 29 | SET_CLAW; 30 | 31 | @Override 32 | public ObjectClawDefine set(Object originObject, Field classField, String targetVal) { 33 | return null; 34 | } 35 | 36 | @Override 37 | public void set(ClawMeta clawMeta) { 38 | throw new ClawScriptScanException("[sad] un-support operation: claw set"); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /core/src/main/java/io/javadebug/core/claw/StringClawImpl.java: -------------------------------------------------------------------------------- 1 | // 2 | // ======================================================================== 3 | // Copyright (c) 2018-2019 HuJian/Pandening soft collection. 4 | // ------------------------------------------------------------------------ 5 | // All rights reserved. This program and the accompanying materials 6 | // are made available under the terms of the #{license} Public License #{version} 7 | // EG: 8 | // The Eclipse Public License is available at 9 | // http://www.eclipse.org/legal/epl-v10.html 10 | // 11 | // The Apache License v2.0 is available at 12 | // http://www.opensource.org/licenses/apache2.0.php 13 | // 14 | // You may elect to redistribute this code under either of these licenses. 15 | // You should bear the consequences of using the software (named 'java-debug-tool') 16 | // and any modify must be create an new pull request and attach an text to describe 17 | // the change detail. 18 | // ======================================================================== 19 | // 20 | 21 | 22 | package io.javadebug.core.claw; 23 | 24 | import io.javadebug.core.utils.UTILS; 25 | 26 | import java.lang.reflect.Field; 27 | 28 | public enum StringClawImpl implements ObjectClawDefine { 29 | STRING_CLAW; 30 | 31 | @Override 32 | public ObjectClawDefine set(Object originObject, Field classField, String targetVal) { 33 | boolean accessible = true; 34 | try { 35 | if (!classField.isAccessible()) { 36 | accessible = false; 37 | classField.setAccessible(true); 38 | } 39 | classField.set(originObject, targetVal); 40 | } catch (Exception e) { 41 | throw new ClassCastException(UTILS.getErrorMsg(e)); 42 | } finally { 43 | if (!accessible) { 44 | classField.setAccessible(false); 45 | } 46 | } 47 | return this; 48 | } 49 | 50 | @Override 51 | public void set(ClawMeta clawMeta) { 52 | 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /core/src/main/java/io/javadebug/core/command/perf/CpuTimeReportStruct.java: -------------------------------------------------------------------------------- 1 | // 2 | // ======================================================================== 3 | // Copyright (c) 2018-2019 HuJian/Pandening soft collection. 4 | // ------------------------------------------------------------------------ 5 | // All rights reserved. This program and the accompanying materials 6 | // are made available under the terms of the #{license} Public License #{version} 7 | // EG: 8 | // The Eclipse Public License is available at 9 | // http://www.eclipse.org/legal/epl-v10.html 10 | // 11 | // The Apache License v2.0 is available at 12 | // http://www.opensource.org/licenses/apache2.0.php 13 | // 14 | // You may elect to redistribute this code under either of these licenses. 15 | // You should bear the consequences of using the software (named 'java-debug-tool') 16 | // and any modify must be create an new pull request and attach an text to describe 17 | // the change detail. 18 | // ======================================================================== 19 | // 20 | 21 | 22 | package io.javadebug.core.command.perf; 23 | 24 | import java.util.Collections; 25 | import java.util.List; 26 | 27 | public class CpuTimeReportStruct { 28 | 29 | public long startMills; // the start measure time mills; 30 | public long stopMills; // the stop measure time mills; 31 | public TimeInfo baseTimeLine; // the base time info 32 | public List timeInfoList; // the time info list 33 | public int stepMills = 100; // the distance of two point is 100ms 34 | 35 | @Override 36 | public String toString() { 37 | StringBuilder sb = new StringBuilder(); 38 | sb.append("total point :").append(timeInfoList.size()).append("\n"); 39 | for (TimeInfo tm : timeInfoList) { 40 | sb.append(tm.toString()).append("\n"); 41 | } 42 | return "stepMills: " + stepMills + " start:" + startMills + " stop:" + stopMills + " total cost:" + (stopMills - startMills) / 1000.0 + " secs \n" 43 | + "base line:" + baseTimeLine + "\n" + sb.toString(); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /core/src/main/java/io/javadebug/core/command/perf/LibcTest.java: -------------------------------------------------------------------------------- 1 | // 2 | // ======================================================================== 3 | // Copyright (c) 2018-2019 HuJian/Pandening soft collection. 4 | // ------------------------------------------------------------------------ 5 | // All rights reserved. This program and the accompanying materials 6 | // are made available under the terms of the #{license} Public License #{version} 7 | // EG: 8 | // The Eclipse Public License is available at 9 | // http://www.eclipse.org/legal/epl-v10.html 10 | // 11 | // The Apache License v2.0 is available at 12 | // http://www.opensource.org/licenses/apache2.0.php 13 | // 14 | // You may elect to redistribute this code under either of these licenses. 15 | // You should bear the consequences of using the software (named 'java-debug-tool') 16 | // and any modify must be create an new pull request and attach an text to describe 17 | // the change detail. 18 | // ======================================================================== 19 | // 20 | 21 | 22 | package io.javadebug.core.command.perf; 23 | 24 | import java.util.concurrent.TimeUnit; 25 | 26 | public class LibcTest { 27 | 28 | public static void main(String[] args) throws InterruptedException { 29 | 30 | RusageStruct start = GNULibC.GNU_LIB_C.getCurrentProcessResourceUsage(); 31 | 32 | System.out.println(start); 33 | 34 | TimeUnit.SECONDS.sleep(1); 35 | 36 | RusageStruct stop = GNULibC.GNU_LIB_C.getCurrentProcessResourceUsage();; 37 | 38 | System.out.println(stop); 39 | 40 | } 41 | 42 | 43 | } 44 | -------------------------------------------------------------------------------- /core/src/main/java/io/javadebug/core/command/perf/LoadAvgTest.java: -------------------------------------------------------------------------------- 1 | // 2 | // ======================================================================== 3 | // Copyright (c) 2018-2019 HuJian/Pandening soft collection. 4 | // ------------------------------------------------------------------------ 5 | // All rights reserved. This program and the accompanying materials 6 | // are made available under the terms of the #{license} Public License #{version} 7 | // EG: 8 | // The Eclipse Public License is available at 9 | // http://www.eclipse.org/legal/epl-v10.html 10 | // 11 | // The Apache License v2.0 is available at 12 | // http://www.opensource.org/licenses/apache2.0.php 13 | // 14 | // You may elect to redistribute this code under either of these licenses. 15 | // You should bear the consequences of using the software (named 'java-debug-tool') 16 | // and any modify must be create an new pull request and attach an text to describe 17 | // the change detail. 18 | // ======================================================================== 19 | // 20 | 21 | 22 | package io.javadebug.core.command.perf; 23 | 24 | import java.util.Arrays; 25 | import java.util.concurrent.TimeUnit; 26 | 27 | public class LoadAvgTest { 28 | 29 | public static void main(String[] args) throws InterruptedException { 30 | 31 | while (true) { 32 | double[] loadavg= GNULibC.GNU_LIB_C.getLoadAvg(); 33 | System.out.println(Arrays.toString(loadavg)); 34 | TimeUnit.SECONDS.sleep(1); 35 | } 36 | 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /core/src/main/java/io/javadebug/core/command/perf/TimeInfo.java: -------------------------------------------------------------------------------- 1 | // 2 | // ======================================================================== 3 | // Copyright (c) 2018-2019 HuJian/Pandening soft collection. 4 | // ------------------------------------------------------------------------ 5 | // All rights reserved. This program and the accompanying materials 6 | // are made available under the terms of the #{license} Public License #{version} 7 | // EG: 8 | // The Eclipse Public License is available at 9 | // http://www.eclipse.org/legal/epl-v10.html 10 | // 11 | // The Apache License v2.0 is available at 12 | // http://www.opensource.org/licenses/apache2.0.php 13 | // 14 | // You may elect to redistribute this code under either of these licenses. 15 | // You should bear the consequences of using the software (named 'java-debug-tool') 16 | // and any modify must be create an new pull request and attach an text to describe 17 | // the change detail. 18 | // ======================================================================== 19 | // 20 | 21 | 22 | package io.javadebug.core.command.perf; 23 | 24 | public class TimeInfo { 25 | 26 | public double realSecs = -1.0, systemSecs, userSecs; 27 | public long nvcsw, nivcsw; 28 | //public double[] loadavg; 29 | 30 | @Override 31 | public String toString() { 32 | return String.format("[Times: user=%3.2f sys=%3.2f real=%3.2f secs Switch: nvcsw=%d nivcsw=%d]", 33 | userSecs, systemSecs, realSecs, nvcsw, nivcsw); 34 | } 35 | 36 | @Override 37 | public boolean equals(Object obj) { 38 | if (obj == null) { 39 | return false; 40 | } 41 | if (!(obj instanceof TimeInfo)) { 42 | return false; 43 | } 44 | if (Double.compare(((TimeInfo) obj).realSecs, realSecs) != 0) { 45 | return false; 46 | } 47 | if (Double.compare(((TimeInfo) obj).systemSecs, systemSecs) != 0) { 48 | return false; 49 | } 50 | if (Double.compare(((TimeInfo) obj).userSecs, userSecs) != 0) { 51 | return false; 52 | } 53 | return true; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /core/src/main/java/io/javadebug/core/command/perf/TimeValStruct.java: -------------------------------------------------------------------------------- 1 | // 2 | // ======================================================================== 3 | // Copyright (c) 2018-2019 HuJian/Pandening soft collection. 4 | // ------------------------------------------------------------------------ 5 | // All rights reserved. This program and the accompanying materials 6 | // are made available under the terms of the #{license} Public License #{version} 7 | // EG: 8 | // The Eclipse Public License is available at 9 | // http://www.eclipse.org/legal/epl-v10.html 10 | // 11 | // The Apache License v2.0 is available at 12 | // http://www.opensource.org/licenses/apache2.0.php 13 | // 14 | // You may elect to redistribute this code under either of these licenses. 15 | // You should bear the consequences of using the software (named 'java-debug-tool') 16 | // and any modify must be create an new pull request and attach an text to describe 17 | // the change detail. 18 | // ======================================================================== 19 | // 20 | 21 | 22 | package io.javadebug.core.command.perf; 23 | 24 | import com.sun.jna.NativeLong; 25 | import com.sun.jna.Structure; 26 | 27 | import java.util.Arrays; 28 | import java.util.List; 29 | 30 | public class TimeValStruct extends Structure { 31 | 32 | public NativeLong tv_sec; /* seconds */ 33 | public int tv_usec; /* and microseconds */ 34 | 35 | public static class ByReference extends TimeValStruct implements Structure.ByReference {} 36 | public static class ByValue extends TimeValStruct implements Structure.ByValue {} 37 | 38 | @Override 39 | protected List getFieldOrder() { 40 | return Arrays.asList("tv_sec", "tv_usec"); 41 | } 42 | 43 | @Override 44 | public String toString() { 45 | return "TimeValStruct{" + 46 | "tv_sec=" + tv_sec + 47 | ", tv_usec=" + tv_usec + 48 | '}'; 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /core/src/main/java/io/javadebug/core/command/perf/TmStructure.java: -------------------------------------------------------------------------------- 1 | // 2 | // ======================================================================== 3 | // Copyright (c) 2018-2019 HuJian/Pandening soft collection. 4 | // ------------------------------------------------------------------------ 5 | // All rights reserved. This program and the accompanying materials 6 | // are made available under the terms of the #{license} Public License #{version} 7 | // EG: 8 | // The Eclipse Public License is available at 9 | // http://www.eclipse.org/legal/epl-v10.html 10 | // 11 | // The Apache License v2.0 is available at 12 | // http://www.opensource.org/licenses/apache2.0.php 13 | // 14 | // You may elect to redistribute this code under either of these licenses. 15 | // You should bear the consequences of using the software (named 'java-debug-tool') 16 | // and any modify must be create an new pull request and attach an text to describe 17 | // the change detail. 18 | // ======================================================================== 19 | // 20 | 21 | 22 | package io.javadebug.core.command.perf; 23 | 24 | import com.sun.jna.NativeLong; 25 | import com.sun.jna.Structure; 26 | 27 | import java.util.Arrays; 28 | import java.util.List; 29 | 30 | public class TmStructure extends Structure { 31 | public NativeLong tms_utime; /* [XSI] User CPU time */ 32 | public NativeLong tms_stime; /* [XSI] System CPU time */ 33 | public NativeLong tms_cutime; /* [XSI] Terminated children user CPU time */ 34 | public NativeLong tms_cstime; /* [XSI] Terminated children System CPU time */ 35 | 36 | public static class ByReference extends TmStructure implements Structure.ByReference {} 37 | public static class ByValue extends TmStructure implements Structure.ByValue {} 38 | 39 | @Override 40 | protected List getFieldOrder() { 41 | return Arrays.asList("tms_utime", "tms_stime", "tms_cutime", "tms_cstime"); 42 | } 43 | 44 | @Override 45 | public String toString() { 46 | return String.format("[Times: user=%3.2f sys=%3.2f secs]", 47 | tms_utime.longValue() / 100.0, tms_stime.longValue() / 100.0); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /core/src/main/java/io/javadebug/core/console/CommandSink.java: -------------------------------------------------------------------------------- 1 | // 2 | // ======================================================================== 3 | // Copyright (c) 2018-2019 HuJian/Pandening soft collection. 4 | // ------------------------------------------------------------------------ 5 | // All rights reserved. This program and the accompanying materials 6 | // are made available under the terms of the #{license} Public License #{version} 7 | // EG: 8 | // The Eclipse Public License is available at 9 | // http://www.eclipse.org/legal/epl-v10.html 10 | // 11 | // The Apache License v2.0 is available at 12 | // http://www.opensource.org/licenses/apache2.0.php 13 | // 14 | // You may elect to redistribute this code under either of these licenses. 15 | // You should bear the consequences of using the software (named 'java-debug-tool') 16 | // and any modify must be create an new pull request and attach an text to describe 17 | // the change detail. 18 | // ======================================================================== 19 | // 20 | 21 | 22 | /** 23 | * Copyright © 2019-XXX HJ All Rights Reserved 24 | * 25 | * 26 | * 27 | * 28 | * 29 | * 30 | * 31 | * 32 | * 33 | */ 34 | // Author : HJ 35 | 36 | 37 | package io.javadebug.core.console; 38 | 39 | import io.javadebug.core.transport.RemoteCommand; 40 | 41 | /** 42 | * Created on 2019/4/29 22:42. 43 | * 44 | * @author HuJian 45 | */ 46 | public interface CommandSink { 47 | 48 | /** 49 | * 命令执行结果出来,比如可以直接打印出来,或者写到某个队列中去 50 | * 51 | * @param remoteCommand {@link RemoteCommand} 命令执行结果 52 | * @return 是否处理成功 53 | */ 54 | boolean sink(RemoteCommand remoteCommand); 55 | 56 | } 57 | -------------------------------------------------------------------------------- /core/src/main/java/io/javadebug/core/console/CommandSource.java: -------------------------------------------------------------------------------- 1 | // 2 | // ======================================================================== 3 | // Copyright (c) 2018-2019 HuJian/Pandening soft collection. 4 | // ------------------------------------------------------------------------ 5 | // All rights reserved. This program and the accompanying materials 6 | // are made available under the terms of the #{license} Public License #{version} 7 | // EG: 8 | // The Eclipse Public License is available at 9 | // http://www.eclipse.org/legal/epl-v10.html 10 | // 11 | // The Apache License v2.0 is available at 12 | // http://www.opensource.org/licenses/apache2.0.php 13 | // 14 | // You may elect to redistribute this code under either of these licenses. 15 | // You should bear the consequences of using the software (named 'java-debug-tool') 16 | // and any modify must be create an new pull request and attach an text to describe 17 | // the change detail. 18 | // ======================================================================== 19 | // 20 | 21 | 22 | /** 23 | * Copyright © 2019-XXX HJ All Rights Reserved 24 | * 25 | * 26 | * 27 | * 28 | * 29 | * 30 | * 31 | * 32 | * 33 | */ 34 | // Author : HJ 35 | 36 | 37 | package io.javadebug.core.console; 38 | 39 | /** 40 | * Created on 2019/4/29 22:28. 41 | * 42 | * @author HuJian 43 | */ 44 | public interface CommandSource { 45 | 46 | /** 47 | * 用于生成一条命令输入,比如可以使用命令行,或者从某个队列取,只要能生成 48 | * 一条命令输入即可; 49 | * 这个source就像是一个水龙头,只要把水龙头打开,下游就会拿到水,如果你需要监听 50 | * 命令执行结果,那么可以在 {@link io.javadebug.core.transport.NettyTransportClusterClient} 51 | * 上面安装一个{@link CommandSink},sink可以安装多个,同一份结果会广播给所有安装了的sink 52 | * 53 | * @return 命令输入,比如 "fc -class String" 54 | */ 55 | String source(); 56 | 57 | } 58 | -------------------------------------------------------------------------------- /core/src/main/java/io/javadebug/core/console/ConsoleCommandSink.java: -------------------------------------------------------------------------------- 1 | // 2 | // ======================================================================== 3 | // Copyright (c) 2018-2019 HuJian/Pandening soft collection. 4 | // ------------------------------------------------------------------------ 5 | // All rights reserved. This program and the accompanying materials 6 | // are made available under the terms of the #{license} Public License #{version} 7 | // EG: 8 | // The Eclipse Public License is available at 9 | // http://www.eclipse.org/legal/epl-v10.html 10 | // 11 | // The Apache License v2.0 is available at 12 | // http://www.opensource.org/licenses/apache2.0.php 13 | // 14 | // You may elect to redistribute this code under either of these licenses. 15 | // You should bear the consequences of using the software (named 'java-debug-tool') 16 | // and any modify must be create an new pull request and attach an text to describe 17 | // the change detail. 18 | // ======================================================================== 19 | // 20 | 21 | 22 | /** 23 | * Copyright © 2019-XXX HJ All Rights Reserved 24 | * 25 | * 26 | * 27 | * 28 | * 29 | * 30 | * 31 | * 32 | * 33 | */ 34 | // Author : HJ 35 | 36 | 37 | package io.javadebug.core.console; 38 | 39 | import io.javadebug.core.log.PSLogger; 40 | import io.javadebug.core.transport.RemoteCommand; 41 | import io.javadebug.core.ui.SimplePSUI; 42 | import io.javadebug.core.ui.UI; 43 | 44 | import java.io.OutputStream; 45 | 46 | /** 47 | * Created on 2019/4/29 22:43. 48 | * 49 | * @author HuJian 50 | */ 51 | public class ConsoleCommandSink implements CommandSink { 52 | 53 | private static OutputStream os = System.out; 54 | private static final UI ui = new SimplePSUI(); 55 | 56 | /** 57 | * 命令执行结果出来,比如可以直接打印出来,或者写到某个队列中去 58 | * 59 | * @param remoteCommand {@link RemoteCommand} 命令执行结果 60 | * @return 是否处理成功 61 | */ 62 | @Override 63 | public boolean sink(RemoteCommand remoteCommand) { 64 | try { 65 | print(ui.toUI(remoteCommand), os); 66 | } catch (Exception e) { 67 | PSLogger.error("无法处理响应结果:" + remoteCommand + " :" + e); 68 | } 69 | return true; 70 | } 71 | 72 | private static void print(String msg, OutputStream os) throws Exception { 73 | os.write(("\n" + msg + "\n").getBytes()); 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /core/src/main/java/io/javadebug/core/console/ConsoleCommandSource.java: -------------------------------------------------------------------------------- 1 | // 2 | // ======================================================================== 3 | // Copyright (c) 2018-2019 HuJian/Pandening soft collection. 4 | // ------------------------------------------------------------------------ 5 | // All rights reserved. This program and the accompanying materials 6 | // are made available under the terms of the #{license} Public License #{version} 7 | // EG: 8 | // The Eclipse Public License is available at 9 | // http://www.eclipse.org/legal/epl-v10.html 10 | // 11 | // The Apache License v2.0 is available at 12 | // http://www.opensource.org/licenses/apache2.0.php 13 | // 14 | // You may elect to redistribute this code under either of these licenses. 15 | // You should bear the consequences of using the software (named 'java-debug-tool') 16 | // and any modify must be create an new pull request and attach an text to describe 17 | // the change detail. 18 | // ======================================================================== 19 | // 20 | 21 | 22 | /** 23 | * Copyright © 2019-XXX HJ All Rights Reserved 24 | * 25 | * 26 | * 27 | * 28 | * 29 | * 30 | * 31 | * 32 | * 33 | */ 34 | // Author : HJ 35 | 36 | 37 | package io.javadebug.core.console; 38 | 39 | import io.javadebug.core.log.PSLogger; 40 | 41 | import java.io.BufferedReader; 42 | import java.io.IOException; 43 | import java.io.InputStreamReader; 44 | 45 | /** 46 | * Created on 2019/4/29 22:30. 47 | * 48 | * @author HuJian 49 | */ 50 | public class ConsoleCommandSource implements CommandSource { 51 | 52 | private static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 53 | 54 | /** 55 | * 用于生成一条命令输入,比如可以使用命令行,或者从某个队列取,只要能生成 56 | * 一条命令输入即可 57 | * 58 | * @return 命令输入,比如 "fc -class String" 59 | */ 60 | @Override 61 | public String source() { 62 | try { 63 | return br.readLine(); 64 | } catch (IOException e) { 65 | PSLogger.error("error while readLine from console:" + e); 66 | return source(); 67 | } 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /core/src/main/java/io/javadebug/core/console/MonitorCollectorCommandSource.java: -------------------------------------------------------------------------------- 1 | // 2 | // ======================================================================== 3 | // Copyright (c) 2018-2019 HuJian/Pandening soft collection. 4 | // ------------------------------------------------------------------------ 5 | // All rights reserved. This program and the accompanying materials 6 | // are made available under the terms of the #{license} Public License #{version} 7 | // EG: 8 | // The Eclipse Public License is available at 9 | // http://www.eclipse.org/legal/epl-v10.html 10 | // 11 | // The Apache License v2.0 is available at 12 | // http://www.opensource.org/licenses/apache2.0.php 13 | // 14 | // You may elect to redistribute this code under either of these licenses. 15 | // You should bear the consequences of using the software (named 'java-debug-tool') 16 | // and any modify must be create an new pull request and attach an text to describe 17 | // the change detail. 18 | // ======================================================================== 19 | // 20 | 21 | 22 | package io.javadebug.core.console; 23 | 24 | public class MonitorCollectorCommandSource extends ReadShellCommandSource { 25 | 26 | /** 27 | * just wrap the {@link ReadShellCommandSource#onCommand(String)} 28 | * maybe we should use {@link ReadShellCommandSource} 29 | * 30 | * @param line the command 31 | */ 32 | public void offer(String line) { 33 | onCommand(line); 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /core/src/main/java/io/javadebug/core/console/ReadShellCommandSource.java: -------------------------------------------------------------------------------- 1 | // 2 | // ======================================================================== 3 | // Copyright (c) 2018-2019 HuJian/Pandening soft collection. 4 | // ------------------------------------------------------------------------ 5 | // All rights reserved. This program and the accompanying materials 6 | // are made available under the terms of the #{license} Public License #{version} 7 | // EG: 8 | // The Eclipse Public License is available at 9 | // http://www.eclipse.org/legal/epl-v10.html 10 | // 11 | // The Apache License v2.0 is available at 12 | // http://www.opensource.org/licenses/apache2.0.php 13 | // 14 | // You may elect to redistribute this code under either of these licenses. 15 | // You should bear the consequences of using the software (named 'java-debug-tool') 16 | // and any modify must be create an new pull request and attach an text to describe 17 | // the change detail. 18 | // ======================================================================== 19 | // 20 | 21 | 22 | package io.javadebug.core.console; 23 | 24 | import io.javadebug.core.transport.NettyTransportClusterClient; 25 | 26 | import java.util.concurrent.CountDownLatch; 27 | 28 | public class ReadShellCommandSource implements CommandSource { 29 | 30 | private String command = null; 31 | private CountDownLatch latch = new CountDownLatch(1); 32 | 33 | /** 34 | * 用于生成一条命令输入,比如可以使用命令行,或者从某个队列取,只要能生成 35 | * 一条命令输入即可; 36 | * 这个source就像是一个水龙头,只要把水龙头打开,下游就会拿到水,如果你需要监听 37 | * 命令执行结果,那么可以在 {@link NettyTransportClusterClient} 38 | * 上面安装一个{@link CommandSink},sink可以安装多个,同一份结果会广播给所有安装了的sink 39 | * 40 | * @return 命令输入,比如 "fc -class String" 41 | */ 42 | @Override 43 | public String source() { 44 | try { 45 | latch.await(); 46 | } catch (InterruptedException e) { 47 | return source(); 48 | } finally { 49 | latch = new CountDownLatch(1); 50 | } 51 | return command; 52 | } 53 | 54 | public void onCommand(String command) { 55 | this.command = command; 56 | latch.countDown(); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /core/src/main/java/io/javadebug/core/count/MethodCountEvent.java: -------------------------------------------------------------------------------- 1 | // 2 | // ======================================================================== 3 | // Copyright (c) 2018-2019 HuJian/Pandening soft collection. 4 | // ------------------------------------------------------------------------ 5 | // All rights reserved. This program and the accompanying materials 6 | // are made available under the terms of the #{license} Public License #{version} 7 | // EG: 8 | // The Eclipse Public License is available at 9 | // http://www.eclipse.org/legal/epl-v10.html 10 | // 11 | // The Apache License v2.0 is available at 12 | // http://www.opensource.org/licenses/apache2.0.php 13 | // 14 | // You may elect to redistribute this code under either of these licenses. 15 | // You should bear the consequences of using the software (named 'java-debug-tool') 16 | // and any modify must be create an new pull request and attach an text to describe 17 | // the change detail. 18 | // ======================================================================== 19 | // 20 | 21 | 22 | package io.javadebug.core.count; 23 | 24 | import io.javadebug.com.netflix.numerus.NumerusRollingNumberEvent; 25 | 26 | /** 27 | * For count the method invoke 28 | * 29 | * REQUESTS -> TPS 30 | * SUCCESS -> success invoke 31 | * ERROR -> error invoke 32 | * 33 | */ 34 | public enum MethodCountEvent implements NumerusRollingNumberEvent { 35 | REQUESTS(true), SUCCESS(true), ERROR(true); 36 | 37 | private final boolean isCounter; 38 | private final boolean isMaxUpdater; 39 | 40 | MethodCountEvent(boolean isCounter) { 41 | this.isCounter = isCounter; 42 | this.isMaxUpdater = !isCounter; 43 | } 44 | 45 | @Override 46 | public boolean isCounter() { 47 | return isCounter; 48 | } 49 | 50 | @Override 51 | public boolean isMaxUpdater() { 52 | return isMaxUpdater; 53 | } 54 | 55 | @Override 56 | public NumerusRollingNumberEvent[] getValues() { 57 | return values(); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /core/src/main/java/io/javadebug/core/data/ClassModel.java: -------------------------------------------------------------------------------- 1 | // 2 | // ======================================================================== 3 | // Copyright (c) 2018-2019 HuJian/Pandening soft collection. 4 | // ------------------------------------------------------------------------ 5 | // All rights reserved. This program and the accompanying materials 6 | // are made available under the terms of the #{license} Public License #{version} 7 | // EG: 8 | // The Eclipse Public License is available at 9 | // http://www.eclipse.org/legal/epl-v10.html 10 | // 11 | // The Apache License v2.0 is available at 12 | // http://www.opensource.org/licenses/apache2.0.php 13 | // 14 | // You may elect to redistribute this code under either of these licenses. 15 | // You should bear the consequences of using the software (named 'java-debug-tool') 16 | // and any modify must be create an new pull request and attach an text to describe 17 | // the change detail. 18 | // ======================================================================== 19 | // 20 | 21 | 22 | /** 23 | * Copyright © 2019-XXX HJ All Rights Reserved 24 | * 25 | * 26 | * 27 | * 28 | * 29 | * 30 | * 31 | * 32 | * 33 | */ 34 | // Auth : HJ 35 | 36 | 37 | package io.javadebug.core.data; 38 | 39 | /** 40 | * Created on 2019/4/19 15:00. 41 | * 42 | * @author HuJian 43 | */ 44 | public class ClassModel { 45 | 46 | private int classCompileVersion; 47 | private String className; 48 | private byte[] classBytes; 49 | 50 | public ClassModel(int classCompileVersion, String className, byte[] classBytes) { 51 | this.classCompileVersion = classCompileVersion; 52 | this.className = className; 53 | this.classBytes = classBytes; 54 | } 55 | 56 | public int getClassCompileVersion() { 57 | return classCompileVersion; 58 | } 59 | 60 | public void setClassCompileVersion(int classCompileVersion) { 61 | this.classCompileVersion = classCompileVersion; 62 | } 63 | 64 | public String getClassName() { 65 | return className; 66 | } 67 | 68 | public void setClassName(String className) { 69 | this.className = className; 70 | } 71 | 72 | public byte[] getClassBytes() { 73 | return classBytes; 74 | } 75 | 76 | public void setClassBytes(byte[] classBytes) { 77 | this.classBytes = classBytes; 78 | } 79 | 80 | } 81 | -------------------------------------------------------------------------------- /core/src/main/java/io/javadebug/core/data/LRModel.java: -------------------------------------------------------------------------------- 1 | // 2 | // ======================================================================== 3 | // Copyright (c) 2018-2019 HuJian/Pandening soft collection. 4 | // ------------------------------------------------------------------------ 5 | // All rights reserved. This program and the accompanying materials 6 | // are made available under the terms of the #{license} Public License #{version} 7 | // EG: 8 | // The Eclipse Public License is available at 9 | // http://www.eclipse.org/legal/epl-v10.html 10 | // 11 | // The Apache License v2.0 is available at 12 | // http://www.opensource.org/licenses/apache2.0.php 13 | // 14 | // You may elect to redistribute this code under either of these licenses. 15 | // You should bear the consequences of using the software (named 'java-debug-tool') 16 | // and any modify must be create an new pull request and attach an text to describe 17 | // the change detail. 18 | // ======================================================================== 19 | // 20 | 21 | 22 | package io.javadebug.core.data; 23 | 24 | public class LRModel { 25 | private int l, r; 26 | 27 | public LRModel(int l, int r) { 28 | this.l = l; 29 | this.r = r; 30 | } 31 | 32 | public int getL() { 33 | return l; 34 | } 35 | 36 | public int getR() { 37 | return r; 38 | } 39 | 40 | public void setL(int l) { 41 | this.l = l; 42 | } 43 | 44 | public void setR(int r) { 45 | this.r = r; 46 | } 47 | 48 | @Override 49 | public String toString() { 50 | return "[" + l + "," + r + "]"; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /core/src/main/java/io/javadebug/core/enhance/CommonClassFileTransformer.java: -------------------------------------------------------------------------------- 1 | // 2 | // ======================================================================== 3 | // Copyright (c) 2018-2019 HuJian/Pandening soft collection. 4 | // ------------------------------------------------------------------------ 5 | // All rights reserved. This program and the accompanying materials 6 | // are made available under the terms of the #{license} Public License #{version} 7 | // EG: 8 | // The Eclipse Public License is available at 9 | // http://www.eclipse.org/legal/epl-v10.html 10 | // 11 | // The Apache License v2.0 is available at 12 | // http://www.opensource.org/licenses/apache2.0.php 13 | // 14 | // You may elect to redistribute this code under either of these licenses. 15 | // You should bear the consequences of using the software (named 'java-debug-tool') 16 | // and any modify must be create an new pull request and attach an text to describe 17 | // the change detail. 18 | // ======================================================================== 19 | // 20 | 21 | 22 | /** 23 | * Copyright © 2019-XXX HJ All Rights Reserved 24 | * 25 | * 26 | * 27 | * 28 | * 29 | * 30 | * 31 | * 32 | * 33 | */ 34 | // Author : HJ 35 | 36 | 37 | package io.javadebug.core.enhance; 38 | 39 | import java.lang.instrument.ClassFileTransformer; 40 | 41 | public interface CommonClassFileTransformer extends ClassFileTransformer, EnhanceResultHook { 42 | 43 | } 44 | -------------------------------------------------------------------------------- /core/src/main/java/io/javadebug/core/enhance/EnhanceResultHook.java: -------------------------------------------------------------------------------- 1 | // 2 | // ======================================================================== 3 | // Copyright (c) 2018-2019 HuJian/Pandening soft collection. 4 | // ------------------------------------------------------------------------ 5 | // All rights reserved. This program and the accompanying materials 6 | // are made available under the terms of the #{license} Public License #{version} 7 | // EG: 8 | // The Eclipse Public License is available at 9 | // http://www.eclipse.org/legal/epl-v10.html 10 | // 11 | // The Apache License v2.0 is available at 12 | // http://www.opensource.org/licenses/apache2.0.php 13 | // 14 | // You may elect to redistribute this code under either of these licenses. 15 | // You should bear the consequences of using the software (named 'java-debug-tool') 16 | // and any modify must be create an new pull request and attach an text to describe 17 | // the change detail. 18 | // ======================================================================== 19 | // 20 | 21 | 22 | /** 23 | * Copyright © 2019-XXX HJ All Rights Reserved 24 | * 25 | * 26 | * 27 | * 28 | * 29 | * 30 | * 31 | * 32 | * 33 | */ 34 | // Author : HJ 35 | 36 | 37 | package io.javadebug.core.enhance; 38 | 39 | import java.lang.instrument.ClassDefinition; 40 | 41 | /** 42 | * Created on 2019/5/10 10:40. 43 | * 44 | * @author HuJian 45 | */ 46 | public interface EnhanceResultHook { 47 | 48 | /** 49 | * 仅仅是获取到命令的结果,这里玩不出什么花样 50 | * 51 | * @return 返回给client的响应结果 {@see $back-data} 52 | */ 53 | String getEnhanceResult(); 54 | 55 | /** 56 | * 获取到增强过的字节码 {@link java.lang.instrument.Instrumentation#redefineClasses(ClassDefinition...)} 57 | * 58 | * @return 增强过的字节码 59 | */ 60 | byte[] getEnhanceBytes(); 61 | 62 | } 63 | -------------------------------------------------------------------------------- /core/src/main/java/io/javadebug/core/enhance/LocalVariableTable.java: -------------------------------------------------------------------------------- 1 | // 2 | // ======================================================================== 3 | // Copyright (c) 2018-2019 HuJian/Pandening soft collection. 4 | // ------------------------------------------------------------------------ 5 | // All rights reserved. This program and the accompanying materials 6 | // are made available under the terms of the #{license} Public License #{version} 7 | // EG: 8 | // The Eclipse Public License is available at 9 | // http://www.eclipse.org/legal/epl-v10.html 10 | // 11 | // The Apache License v2.0 is available at 12 | // http://www.opensource.org/licenses/apache2.0.php 13 | // 14 | // You may elect to redistribute this code under either of these licenses. 15 | // You should bear the consequences of using the software (named 'java-debug-tool') 16 | // and any modify must be create an new pull request and attach an text to describe 17 | // the change detail. 18 | // ======================================================================== 19 | // 20 | 21 | 22 | /** 23 | * Copyright © 2019-XXX HJ All Rights Reserved 24 | * 25 | * 26 | * 27 | * 28 | * 29 | * 30 | * 31 | * 32 | * 33 | */ 34 | // Author : HJ 35 | 36 | 37 | package io.javadebug.core.enhance; 38 | 39 | /** 40 | * Created on 2019/5/11 13:40. 41 | * 42 | * @author HuJian 43 | */ 44 | public interface LocalVariableTable { 45 | 46 | /** 47 | * 这个方法用于提供根据index查询局部变量名称的服务,本身就是方法级别的,所以 48 | * 不做区分 49 | * 50 | * @param index var index 51 | * @return 变量名称,可能不准确,不要强依赖 52 | */ 53 | String valueAt(int index); 54 | 55 | } 56 | -------------------------------------------------------------------------------- /core/src/main/java/io/javadebug/core/enhance/MethodAdviceType.java: -------------------------------------------------------------------------------- 1 | // 2 | // ======================================================================== 3 | // Copyright (c) 2018-2019 HuJian/Pandening soft collection. 4 | // ------------------------------------------------------------------------ 5 | // All rights reserved. This program and the accompanying materials 6 | // are made available under the terms of the #{license} Public License #{version} 7 | // EG: 8 | // The Eclipse Public License is available at 9 | // http://www.eclipse.org/legal/epl-v10.html 10 | // 11 | // The Apache License v2.0 is available at 12 | // http://www.opensource.org/licenses/apache2.0.php 13 | // 14 | // You may elect to redistribute this code under either of these licenses. 15 | // You should bear the consequences of using the software (named 'java-debug-tool') 16 | // and any modify must be create an new pull request and attach an text to describe 17 | // the change detail. 18 | // ======================================================================== 19 | // 20 | 21 | 22 | /** 23 | * Copyright © 2019-XXX HJ All Rights Reserved 24 | * 25 | * 26 | * 27 | * 28 | * 29 | * 30 | * 31 | * 32 | * 33 | */ 34 | // Author : HJ 35 | 36 | 37 | package io.javadebug.core.enhance; 38 | 39 | public enum MethodAdviceType { 40 | 41 | ON_RETURN, // 当方法正常返回的时候 42 | ON_THROW, // 当方法抛出异常的时候 43 | ON_MATCH_PARAM, // 当方法需要匹配特定参数的时候,type=custom or type=watch的时候 44 | FULL_MATCH // 默认情况,相当于 ON_RETURN + ON_THROW 45 | 46 | } 47 | -------------------------------------------------------------------------------- /core/src/main/java/io/javadebug/core/enhance/MethodEnhanceStake.java: -------------------------------------------------------------------------------- 1 | // 2 | // ======================================================================== 3 | // Copyright (c) 2018-2019 HuJian/Pandening soft collection. 4 | // ------------------------------------------------------------------------ 5 | // All rights reserved. This program and the accompanying materials 6 | // are made available under the terms of the #{license} Public License #{version} 7 | // EG: 8 | // The Eclipse Public License is available at 9 | // http://www.eclipse.org/legal/epl-v10.html 10 | // 11 | // The Apache License v2.0 is available at 12 | // http://www.opensource.org/licenses/apache2.0.php 13 | // 14 | // You may elect to redistribute this code under either of these licenses. 15 | // You should bear the consequences of using the software (named 'java-debug-tool') 16 | // and any modify must be create an new pull request and attach an text to describe 17 | // the change detail. 18 | // ======================================================================== 19 | // 20 | 21 | 22 | /** 23 | * Copyright © 2019-XXX HJ All Rights Reserved 24 | * 25 | * 26 | * 27 | * 28 | * 29 | * 30 | * 31 | * 32 | * 33 | */ 34 | // Author : HJ 35 | 36 | 37 | package io.javadebug.core.enhance; 38 | 39 | public interface MethodEnhanceStake { 40 | 41 | 42 | 43 | } 44 | -------------------------------------------------------------------------------- /core/src/main/java/io/javadebug/core/enhance/UniqueSource.java: -------------------------------------------------------------------------------- 1 | // 2 | // ======================================================================== 3 | // Copyright (c) 2018-2019 HuJian/Pandening soft collection. 4 | // ------------------------------------------------------------------------ 5 | // All rights reserved. This program and the accompanying materials 6 | // are made available under the terms of the #{license} Public License #{version} 7 | // EG: 8 | // The Eclipse Public License is available at 9 | // http://www.eclipse.org/legal/epl-v10.html 10 | // 11 | // The Apache License v2.0 is available at 12 | // http://www.opensource.org/licenses/apache2.0.php 13 | // 14 | // You may elect to redistribute this code under either of these licenses. 15 | // You should bear the consequences of using the software (named 'java-debug-tool') 16 | // and any modify must be create an new pull request and attach an text to describe 17 | // the change detail. 18 | // ======================================================================== 19 | // 20 | 21 | 22 | /** 23 | * Copyright © 2019-XXX HJ All Rights Reserved 24 | * 25 | * 26 | * 27 | * 28 | * 29 | * 30 | * 31 | * 32 | * 33 | */ 34 | // Author : HJ 35 | 36 | 37 | package io.javadebug.core.enhance; 38 | 39 | public interface UniqueSource { 40 | 41 | /** 42 | * 在某些情况下,可能需要获取到一个区别各个client/advice的数据,比如uuid等,那 43 | * 这个方法就比较有用了 44 | * 45 | * @return 唯一数据 46 | */ 47 | T get(); 48 | 49 | } 50 | -------------------------------------------------------------------------------- /core/src/main/java/io/javadebug/core/exception/ClawScriptScanException.java: -------------------------------------------------------------------------------- 1 | // 2 | // ======================================================================== 3 | // Copyright (c) 2018-2019 HuJian/Pandening soft collection. 4 | // ------------------------------------------------------------------------ 5 | // All rights reserved. This program and the accompanying materials 6 | // are made available under the terms of the #{license} Public License #{version} 7 | // EG: 8 | // The Eclipse Public License is available at 9 | // http://www.eclipse.org/legal/epl-v10.html 10 | // 11 | // The Apache License v2.0 is available at 12 | // http://www.opensource.org/licenses/apache2.0.php 13 | // 14 | // You may elect to redistribute this code under either of these licenses. 15 | // You should bear the consequences of using the software (named 'java-debug-tool') 16 | // and any modify must be create an new pull request and attach an text to describe 17 | // the change detail. 18 | // ======================================================================== 19 | // 20 | 21 | 22 | package io.javadebug.core.exception; 23 | 24 | public class ClawScriptScanException extends RuntimeException { 25 | 26 | /** Constructs a new runtime exception with the specified detail message. 27 | * The cause is not initialized, and may subsequently be initialized by a 28 | * call to {@link #initCause}. 29 | * 30 | * @param message the detail message. The detail message is saved for 31 | * later retrieval by the {@link #getMessage()} method. 32 | */ 33 | public ClawScriptScanException(String message) { 34 | super(message); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /core/src/main/java/io/javadebug/core/exception/ObjectFieldInterpreterException.java: -------------------------------------------------------------------------------- 1 | // 2 | // ======================================================================== 3 | // Copyright (c) 2018-2019 HuJian/Pandening soft collection. 4 | // ------------------------------------------------------------------------ 5 | // All rights reserved. This program and the accompanying materials 6 | // are made available under the terms of the #{license} Public License #{version} 7 | // EG: 8 | // The Eclipse Public License is available at 9 | // http://www.eclipse.org/legal/epl-v10.html 10 | // 11 | // The Apache License v2.0 is available at 12 | // http://www.opensource.org/licenses/apache2.0.php 13 | // 14 | // You may elect to redistribute this code under either of these licenses. 15 | // You should bear the consequences of using the software (named 'java-debug-tool') 16 | // and any modify must be create an new pull request and attach an text to describe 17 | // the change detail. 18 | // ======================================================================== 19 | // 20 | 21 | 22 | package io.javadebug.core.exception; 23 | 24 | public class ObjectFieldInterpreterException extends RuntimeException { 25 | 26 | /** Constructs a new runtime exception with the specified detail message. 27 | * The cause is not initialized, and may subsequently be initialized by a 28 | * call to {@link #initCause}. 29 | * 30 | * @param message the detail message. The detail message is saved for 31 | * later retrieval by the {@link #getMessage()} method. 32 | */ 33 | public ObjectFieldInterpreterException(String message) { 34 | super(message); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /core/src/main/java/io/javadebug/core/exception/ObjectTransformerException.java: -------------------------------------------------------------------------------- 1 | // 2 | // ======================================================================== 3 | // Copyright (c) 2018-2019 HuJian/Pandening soft collection. 4 | // ------------------------------------------------------------------------ 5 | // All rights reserved. This program and the accompanying materials 6 | // are made available under the terms of the #{license} Public License #{version} 7 | // EG: 8 | // The Eclipse Public License is available at 9 | // http://www.eclipse.org/legal/epl-v10.html 10 | // 11 | // The Apache License v2.0 is available at 12 | // http://www.opensource.org/licenses/apache2.0.php 13 | // 14 | // You may elect to redistribute this code under either of these licenses. 15 | // You should bear the consequences of using the software (named 'java-debug-tool') 16 | // and any modify must be create an new pull request and attach an text to describe 17 | // the change detail. 18 | // ======================================================================== 19 | // 20 | 21 | 22 | package io.javadebug.core.exception; 23 | 24 | public class ObjectTransformerException extends RuntimeException { 25 | 26 | /** Constructs a new runtime exception with the specified detail message. 27 | * The cause is not initialized, and may subsequently be initialized by a 28 | * call to {@link #initCause}. 29 | * 30 | * @param message the detail message. The detail message is saved for 31 | * later retrieval by the {@link #getMessage()} method. 32 | */ 33 | public ObjectTransformerException(String message) { 34 | super(message); 35 | } 36 | 37 | } 38 | 39 | -------------------------------------------------------------------------------- /core/src/main/java/io/javadebug/core/handler/WebSocketFrameHandler.java: -------------------------------------------------------------------------------- 1 | // 2 | // ======================================================================== 3 | // Copyright (c) 2018-2019 HuJian/Pandening soft collection. 4 | // ------------------------------------------------------------------------ 5 | // All rights reserved. This program and the accompanying materials 6 | // are made available under the terms of the #{license} Public License #{version} 7 | // EG: 8 | // The Eclipse Public License is available at 9 | // http://www.eclipse.org/legal/epl-v10.html 10 | // 11 | // The Apache License v2.0 is available at 12 | // http://www.opensource.org/licenses/apache2.0.php 13 | // 14 | // You may elect to redistribute this code under either of these licenses. 15 | // You should bear the consequences of using the software (named 'java-debug-tool') 16 | // and any modify must be create an new pull request and attach an text to describe 17 | // the change detail. 18 | // ======================================================================== 19 | // 20 | 21 | 22 | package io.javadebug.core.handler; 23 | 24 | import io.netty.channel.ChannelHandlerContext; 25 | import io.netty.channel.SimpleChannelInboundHandler; 26 | import io.netty.handler.codec.http.websocketx.TextWebSocketFrame; 27 | import io.netty.handler.codec.http.websocketx.WebSocketFrame; 28 | 29 | import java.util.Locale; 30 | 31 | /** 32 | * Echoes uppercase content of text frames. 33 | */ 34 | public class WebSocketFrameHandler extends SimpleChannelInboundHandler { 35 | 36 | @Override 37 | protected void channelRead0(ChannelHandlerContext ctx, WebSocketFrame frame) throws Exception { 38 | // ping and pong frames already handled 39 | 40 | if (frame instanceof TextWebSocketFrame) { 41 | // handle the webSocket frame 42 | String request = ((TextWebSocketFrame) frame).text(); 43 | handleWebSocketFrame(request, ctx); 44 | } else { 45 | String message = "unsupported frame type: " + frame.getClass().getName(); 46 | throw new UnsupportedOperationException(message); 47 | } 48 | } 49 | 50 | protected void handleWebSocketFrame(String request, ChannelHandlerContext ctx) { 51 | ctx.channel().writeAndFlush(new TextWebSocketFrame(request.toUpperCase(Locale.US))); 52 | } 53 | } 54 | 55 | -------------------------------------------------------------------------------- /core/src/main/java/io/javadebug/core/hook/DefaultHookImpl.java: -------------------------------------------------------------------------------- 1 | // 2 | // ======================================================================== 3 | // Copyright (c) 2018-2019 HuJian/Pandening soft collection. 4 | // ------------------------------------------------------------------------ 5 | // All rights reserved. This program and the accompanying materials 6 | // are made available under the terms of the #{license} Public License #{version} 7 | // EG: 8 | // The Eclipse Public License is available at 9 | // http://www.eclipse.org/legal/epl-v10.html 10 | // 11 | // The Apache License v2.0 is available at 12 | // http://www.opensource.org/licenses/apache2.0.php 13 | // 14 | // You may elect to redistribute this code under either of these licenses. 15 | // You should bear the consequences of using the software (named 'java-debug-tool') 16 | // and any modify must be create an new pull request and attach an text to describe 17 | // the change detail. 18 | // ======================================================================== 19 | // 20 | 21 | 22 | package io.javadebug.core.hook; 23 | 24 | import io.javadebug.core.record.Log; 25 | import io.javadebug.core.record.InternalLoggerRecord; 26 | 27 | public interface DefaultHookImpl extends HookOperator { 28 | 29 | Log RECORD_OPERATOR_LOG = new InternalLoggerRecord(); 30 | 31 | } 32 | -------------------------------------------------------------------------------- /core/src/main/java/io/javadebug/core/hook/HookOperator.java: -------------------------------------------------------------------------------- 1 | // 2 | // ======================================================================== 3 | // Copyright (c) 2018-2019 HuJian/Pandening soft collection. 4 | // ------------------------------------------------------------------------ 5 | // All rights reserved. This program and the accompanying materials 6 | // are made available under the terms of the #{license} Public License #{version} 7 | // EG: 8 | // The Eclipse Public License is available at 9 | // http://www.eclipse.org/legal/epl-v10.html 10 | // 11 | // The Apache License v2.0 is available at 12 | // http://www.opensource.org/licenses/apache2.0.php 13 | // 14 | // You may elect to redistribute this code under either of these licenses. 15 | // You should bear the consequences of using the software (named 'java-debug-tool') 16 | // and any modify must be create an new pull request and attach an text to describe 17 | // the change detail. 18 | // ======================================================================== 19 | // 20 | 21 | 22 | package io.javadebug.core.hook; 23 | 24 | public interface HookOperator { 25 | 26 | /** 27 | * check the data before you consume it! 28 | * 29 | * @param stage the stage of current 30 | * @return true means you will consume the data, 31 | * the {@link HookOperator#apply(Object)} method will call with param {@see data} 32 | */ 33 | boolean isInterest(RuntimeStage stage); 34 | 35 | /** 36 | * Applies this function to the given argument. 37 | * 38 | * @param t the function argument 39 | * @return the function result 40 | */ 41 | R apply(T t); 42 | 43 | } 44 | -------------------------------------------------------------------------------- /core/src/main/java/io/javadebug/core/hook/OnCommandInputHookImpl.java: -------------------------------------------------------------------------------- 1 | // 2 | // ======================================================================== 3 | // Copyright (c) 2018-2019 HuJian/Pandening soft collection. 4 | // ------------------------------------------------------------------------ 5 | // All rights reserved. This program and the accompanying materials 6 | // are made available under the terms of the #{license} Public License #{version} 7 | // EG: 8 | // The Eclipse Public License is available at 9 | // http://www.eclipse.org/legal/epl-v10.html 10 | // 11 | // The Apache License v2.0 is available at 12 | // http://www.opensource.org/licenses/apache2.0.php 13 | // 14 | // You may elect to redistribute this code under either of these licenses. 15 | // You should bear the consequences of using the software (named 'java-debug-tool') 16 | // and any modify must be create an new pull request and attach an text to describe 17 | // the change detail. 18 | // ======================================================================== 19 | // 20 | 21 | 22 | package io.javadebug.core.hook; 23 | 24 | import io.javadebug.core.log.PSLogger; 25 | 26 | public class OnCommandInputHookImpl implements DefaultHookImpl { 27 | 28 | /** 29 | * Applies this function to the given argument. 30 | * 31 | * @param s the function argument 32 | * @return the function result 33 | */ 34 | @Override 35 | public Void apply(String s) { 36 | 37 | // consume it! 38 | try { 39 | RECORD_OPERATOR_LOG.write(s); 40 | } catch (Exception e) { 41 | PSLogger.error("error when consume command-input msg:" + s + " with exception : " + e); 42 | } 43 | 44 | return null; 45 | } 46 | 47 | /** 48 | * check the data before you consume it! 49 | * 50 | * @param stage the stage of current 51 | * @return true means you will consume the data, 52 | * the {@link HookOperator#apply(Object)} method will call with param {@see data} 53 | */ 54 | @Override 55 | public boolean isInterest(RuntimeStage stage) { 56 | return stage.equals(RuntimeStage.COMMAND_INPUT); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /core/src/main/java/io/javadebug/core/hook/OnCommandToUIHookImpl.java: -------------------------------------------------------------------------------- 1 | // 2 | // ======================================================================== 3 | // Copyright (c) 2018-2019 HuJian/Pandening soft collection. 4 | // ------------------------------------------------------------------------ 5 | // All rights reserved. This program and the accompanying materials 6 | // are made available under the terms of the #{license} Public License #{version} 7 | // EG: 8 | // The Eclipse Public License is available at 9 | // http://www.eclipse.org/legal/epl-v10.html 10 | // 11 | // The Apache License v2.0 is available at 12 | // http://www.opensource.org/licenses/apache2.0.php 13 | // 14 | // You may elect to redistribute this code under either of these licenses. 15 | // You should bear the consequences of using the software (named 'java-debug-tool') 16 | // and any modify must be create an new pull request and attach an text to describe 17 | // the change detail. 18 | // ======================================================================== 19 | // 20 | 21 | 22 | package io.javadebug.core.hook; 23 | 24 | import io.javadebug.core.log.PSLogger; 25 | 26 | public class OnCommandToUIHookImpl implements DefaultHookImpl { 27 | /** 28 | * Applies this function to the given argument. 29 | * 30 | * @param s the function argument 31 | * @return the function result 32 | */ 33 | @Override 34 | public Void apply(String s) { 35 | 36 | // consume it! 37 | try { 38 | RECORD_OPERATOR_LOG.write(s); 39 | } catch (Exception e) { 40 | PSLogger.error("error when consume to-ui msg:" + s + " with exception : " + e); 41 | } 42 | 43 | return null; 44 | } 45 | 46 | /** 47 | * check the data before you consume it! 48 | * 49 | * @param stage the stage of current 50 | * @return true means you will consume the data, 51 | * the {@link HookOperator#apply(Object)} method will call with param {@see data} 52 | */ 53 | @Override 54 | public boolean isInterest(RuntimeStage stage) { 55 | return stage.equals(RuntimeStage.DEBUG_COMMAND_SHOW); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /core/src/main/java/io/javadebug/core/hook/RuntimeStage.java: -------------------------------------------------------------------------------- 1 | // 2 | // ======================================================================== 3 | // Copyright (c) 2018-2019 HuJian/Pandening soft collection. 4 | // ------------------------------------------------------------------------ 5 | // All rights reserved. This program and the accompanying materials 6 | // are made available under the terms of the #{license} Public License #{version} 7 | // EG: 8 | // The Eclipse Public License is available at 9 | // http://www.eclipse.org/legal/epl-v10.html 10 | // 11 | // The Apache License v2.0 is available at 12 | // http://www.opensource.org/licenses/apache2.0.php 13 | // 14 | // You may elect to redistribute this code under either of these licenses. 15 | // You should bear the consequences of using the software (named 'java-debug-tool') 16 | // and any modify must be create an new pull request and attach an text to describe 17 | // the change detail. 18 | // ======================================================================== 19 | // 20 | 21 | 22 | package io.javadebug.core.hook; 23 | 24 | public enum RuntimeStage { 25 | 26 | COMMAND_INPUT, 27 | 28 | GENERATE_COMMAND_PROTOCOL, 29 | 30 | DEBUG_COMMAND_SENT, 31 | 32 | DEBUG_COMMAND_RESP, 33 | 34 | DEBUG_COMMAND_SHOW, 35 | 36 | ERROR 37 | 38 | ; 39 | 40 | 41 | } 42 | -------------------------------------------------------------------------------- /core/src/main/java/io/javadebug/core/http/NettyHttpServerToStandardClient.java: -------------------------------------------------------------------------------- 1 | // 2 | // ======================================================================== 3 | // Copyright (c) 2018-2019 HuJian/Pandening soft collection. 4 | // ------------------------------------------------------------------------ 5 | // All rights reserved. This program and the accompanying materials 6 | // are made available under the terms of the #{license} Public License #{version} 7 | // EG: 8 | // The Eclipse Public License is available at 9 | // http://www.eclipse.org/legal/epl-v10.html 10 | // 11 | // The Apache License v2.0 is available at 12 | // http://www.opensource.org/licenses/apache2.0.php 13 | // 14 | // You may elect to redistribute this code under either of these licenses. 15 | // You should bear the consequences of using the software (named 'java-debug-tool') 16 | // and any modify must be create an new pull request and attach an text to describe 17 | // the change detail. 18 | // ======================================================================== 19 | // 20 | 21 | 22 | package io.javadebug.core.http; 23 | 24 | public class NettyHttpServerToStandardClient { 25 | 26 | 27 | } 28 | -------------------------------------------------------------------------------- /core/src/main/java/io/javadebug/core/http/ReplaySubjectTest.java: -------------------------------------------------------------------------------- 1 | // 2 | // ======================================================================== 3 | // Copyright (c) 2018-2019 HuJian/Pandening soft collection. 4 | // ------------------------------------------------------------------------ 5 | // All rights reserved. This program and the accompanying materials 6 | // are made available under the terms of the #{license} Public License #{version} 7 | // EG: 8 | // The Eclipse Public License is available at 9 | // http://www.eclipse.org/legal/epl-v10.html 10 | // 11 | // The Apache License v2.0 is available at 12 | // http://www.opensource.org/licenses/apache2.0.php 13 | // 14 | // You may elect to redistribute this code under either of these licenses. 15 | // You should bear the consequences of using the software (named 'java-debug-tool') 16 | // and any modify must be create an new pull request and attach an text to describe 17 | // the change detail. 18 | // ======================================================================== 19 | // 20 | 21 | 22 | package io.javadebug.core.http; 23 | 24 | import rx.Observer; 25 | import rx.subjects.ReplaySubject; 26 | 27 | public class ReplaySubjectTest { 28 | 29 | public static void main(String[] args) { 30 | 31 | ReplaySubject subject = ReplaySubject.create(); 32 | 33 | subject.subscribe(new Observer() { 34 | @Override 35 | public void onCompleted() { 36 | 37 | } 38 | 39 | @Override 40 | public void onError(Throwable e) { 41 | 42 | } 43 | 44 | @Override 45 | public void onNext(String s) { 46 | System.out.println("next:" + s); 47 | } 48 | }); 49 | 50 | subject.onNext("hello"); 51 | subject.onNext("cat"); 52 | subject.onCompleted(); 53 | 54 | 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /core/src/main/java/io/javadebug/core/monitor/CounterEvent.java: -------------------------------------------------------------------------------- 1 | // 2 | // ======================================================================== 3 | // Copyright (c) 2018-2019 HuJian/Pandening soft collection. 4 | // ------------------------------------------------------------------------ 5 | // All rights reserved. This program and the accompanying materials 6 | // are made available under the terms of the #{license} Public License #{version} 7 | // EG: 8 | // The Eclipse Public License is available at 9 | // http://www.eclipse.org/legal/epl-v10.html 10 | // 11 | // The Apache License v2.0 is available at 12 | // http://www.opensource.org/licenses/apache2.0.php 13 | // 14 | // You may elect to redistribute this code under either of these licenses. 15 | // You should bear the consequences of using the software (named 'java-debug-tool') 16 | // and any modify must be create an new pull request and attach an text to describe 17 | // the change detail. 18 | // ======================================================================== 19 | // 20 | 21 | 22 | package io.javadebug.core.monitor; 23 | 24 | public interface CounterEvent { 25 | 26 | // the event type, like class / gc / jetty , etc. 27 | // the client and server must in same level for each type; 28 | String type(); 29 | 30 | /** 31 | * produce the event, the subclass will know the type of event; 32 | * 33 | * @return something express the event data, maybe just a string 34 | */ 35 | String event(); 36 | 37 | } 38 | -------------------------------------------------------------------------------- /core/src/main/java/io/javadebug/core/monitor/MonitorCollector.java: -------------------------------------------------------------------------------- 1 | // 2 | // ======================================================================== 3 | // Copyright (c) 2018-2019 HuJian/Pandening soft collection. 4 | // ------------------------------------------------------------------------ 5 | // All rights reserved. This program and the accompanying materials 6 | // are made available under the terms of the #{license} Public License #{version} 7 | // EG: 8 | // The Eclipse Public License is available at 9 | // http://www.eclipse.org/legal/epl-v10.html 10 | // 11 | // The Apache License v2.0 is available at 12 | // http://www.opensource.org/licenses/apache2.0.php 13 | // 14 | // You may elect to redistribute this code under either of these licenses. 15 | // You should bear the consequences of using the software (named 'java-debug-tool') 16 | // and any modify must be create an new pull request and attach an text to describe 17 | // the change detail. 18 | // ======================================================================== 19 | // 20 | 21 | 22 | package io.javadebug.core.monitor; 23 | 24 | public interface MonitorCollector { 25 | 26 | /** 27 | * collect the event by your way, and the implement need to response real-time, do 28 | * not do scheduler or cache something in your implement, this function will be called 29 | * by {@link MonitorHandler}, as Producer, the {@link MonitorConsume} will consume 30 | * the event produced by this method; 31 | * 32 | * @return the origin event 33 | */ 34 | CounterEvent collect(); 35 | 36 | } 37 | -------------------------------------------------------------------------------- /core/src/main/java/io/javadebug/core/monitor/MonitorConsume.java: -------------------------------------------------------------------------------- 1 | // 2 | // ======================================================================== 3 | // Copyright (c) 2018-2019 HuJian/Pandening soft collection. 4 | // ------------------------------------------------------------------------ 5 | // All rights reserved. This program and the accompanying materials 6 | // are made available under the terms of the #{license} Public License #{version} 7 | // EG: 8 | // The Eclipse Public License is available at 9 | // http://www.eclipse.org/legal/epl-v10.html 10 | // 11 | // The Apache License v2.0 is available at 12 | // http://www.opensource.org/licenses/apache2.0.php 13 | // 14 | // You may elect to redistribute this code under either of these licenses. 15 | // You should bear the consequences of using the software (named 'java-debug-tool') 16 | // and any modify must be create an new pull request and attach an text to describe 17 | // the change detail. 18 | // ======================================================================== 19 | // 20 | 21 | 22 | package io.javadebug.core.monitor; 23 | 24 | import java.util.Map; 25 | 26 | public interface MonitorConsume { 27 | 28 | /** 29 | * consume the event produce by {@link MonitorCollector} 30 | * 31 | * @param eventMap the origin event {@link CounterEvent} 32 | */ 33 | void consume(Map eventMap, T ctx); 34 | 35 | } 36 | -------------------------------------------------------------------------------- /core/src/main/java/io/javadebug/core/monitor/cpu/CPUCollector.java: -------------------------------------------------------------------------------- 1 | // 2 | // ======================================================================== 3 | // Copyright (c) 2018-2019 HuJian/Pandening soft collection. 4 | // ------------------------------------------------------------------------ 5 | // All rights reserved. This program and the accompanying materials 6 | // are made available under the terms of the #{license} Public License #{version} 7 | // EG: 8 | // The Eclipse Public License is available at 9 | // http://www.eclipse.org/legal/epl-v10.html 10 | // 11 | // The Apache License v2.0 is available at 12 | // http://www.opensource.org/licenses/apache2.0.php 13 | // 14 | // You may elect to redistribute this code under either of these licenses. 15 | // You should bear the consequences of using the software (named 'java-debug-tool') 16 | // and any modify must be create an new pull request and attach an text to describe 17 | // the change detail. 18 | // ======================================================================== 19 | // 20 | 21 | 22 | package io.javadebug.core.monitor.cpu; 23 | 24 | import io.javadebug.core.monitor.CounterEvent; 25 | import io.javadebug.core.monitor.MonitorCollector; 26 | import io.javadebug.core.monitor.MonitorConsume; 27 | import io.javadebug.core.monitor.MonitorHandler; 28 | 29 | public enum CPUCollector implements MonitorCollector { 30 | CPU_COLLECTOR 31 | ; 32 | 33 | /** 34 | * collect the event by your way, and the implement need to response real-time, do 35 | * not do scheduler or cache something in your implement, this function will be called 36 | * by {@link MonitorHandler}, as Producer, the {@link MonitorConsume} will consume 37 | * the event produced by this method; 38 | * 39 | * @return the origin event 40 | */ 41 | @Override 42 | public CounterEvent collect() { 43 | return new CounterEvent() { 44 | @Override 45 | public String type() { 46 | return "InCompletable Event Type"; 47 | } 48 | 49 | @Override 50 | public String event() { 51 | return "use 'load'/'thread' type to watch cpu\n"; 52 | } 53 | }; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /core/src/main/java/io/javadebug/core/monitor/http/HttpMonitorCollector.java: -------------------------------------------------------------------------------- 1 | // 2 | // ======================================================================== 3 | // Copyright (c) 2018-2019 HuJian/Pandening soft collection. 4 | // ------------------------------------------------------------------------ 5 | // All rights reserved. This program and the accompanying materials 6 | // are made available under the terms of the #{license} Public License #{version} 7 | // EG: 8 | // The Eclipse Public License is available at 9 | // http://www.eclipse.org/legal/epl-v10.html 10 | // 11 | // The Apache License v2.0 is available at 12 | // http://www.opensource.org/licenses/apache2.0.php 13 | // 14 | // You may elect to redistribute this code under either of these licenses. 15 | // You should bear the consequences of using the software (named 'java-debug-tool') 16 | // and any modify must be create an new pull request and attach an text to describe 17 | // the change detail. 18 | // ======================================================================== 19 | // 20 | 21 | 22 | package io.javadebug.core.monitor.http; 23 | 24 | import io.javadebug.core.monitor.CounterEvent; 25 | import io.javadebug.core.monitor.MonitorCollector; 26 | import io.javadebug.core.monitor.MonitorConsume; 27 | import io.javadebug.core.monitor.MonitorHandler; 28 | 29 | public enum HttpMonitorCollector implements MonitorCollector { 30 | HTTP_MONITOR_COLLECTOR 31 | ; 32 | 33 | /** 34 | * collect the event by your way, and the implement need to response real-time, do 35 | * not do scheduler or cache something in your implement, this function will be called 36 | * by {@link MonitorHandler}, as Producer, the {@link MonitorConsume} will consume 37 | * the event produced by this method; 38 | * 39 | * @return the origin event 40 | */ 41 | @Override 42 | public CounterEvent collect() { 43 | return null; 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /core/src/main/java/io/javadebug/core/monitor/jetty/JettyMonitorCollector.java: -------------------------------------------------------------------------------- 1 | // 2 | // ======================================================================== 3 | // Copyright (c) 2018-2019 HuJian/Pandening soft collection. 4 | // ------------------------------------------------------------------------ 5 | // All rights reserved. This program and the accompanying materials 6 | // are made available under the terms of the #{license} Public License #{version} 7 | // EG: 8 | // The Eclipse Public License is available at 9 | // http://www.eclipse.org/legal/epl-v10.html 10 | // 11 | // The Apache License v2.0 is available at 12 | // http://www.opensource.org/licenses/apache2.0.php 13 | // 14 | // You may elect to redistribute this code under either of these licenses. 15 | // You should bear the consequences of using the software (named 'java-debug-tool') 16 | // and any modify must be create an new pull request and attach an text to describe 17 | // the change detail. 18 | // ======================================================================== 19 | // 20 | 21 | 22 | package io.javadebug.core.monitor.jetty; 23 | 24 | import io.javadebug.core.monitor.CounterEvent; 25 | import io.javadebug.core.monitor.MonitorCollector; 26 | import io.javadebug.core.monitor.MonitorConsume; 27 | import io.javadebug.core.monitor.MonitorHandler; 28 | 29 | public enum JettyMonitorCollector implements MonitorCollector { 30 | JETTY_MONITOR_COLLECTOR 31 | ; 32 | 33 | /** 34 | * collect the event by your way, and the implement need to response real-time, do 35 | * not do scheduler or cache something in your implement, this function will be called 36 | * by {@link MonitorHandler}, as Producer, the {@link MonitorConsume} will consume 37 | * the event produced by this method; 38 | * 39 | * @return the origin event 40 | */ 41 | @Override 42 | public CounterEvent collect() { 43 | return null; 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /core/src/main/java/io/javadebug/core/monitor/net/NetworkMonitorCollector.java: -------------------------------------------------------------------------------- 1 | // 2 | // ======================================================================== 3 | // Copyright (c) 2018-2019 HuJian/Pandening soft collection. 4 | // ------------------------------------------------------------------------ 5 | // All rights reserved. This program and the accompanying materials 6 | // are made available under the terms of the #{license} Public License #{version} 7 | // EG: 8 | // The Eclipse Public License is available at 9 | // http://www.eclipse.org/legal/epl-v10.html 10 | // 11 | // The Apache License v2.0 is available at 12 | // http://www.opensource.org/licenses/apache2.0.php 13 | // 14 | // You may elect to redistribute this code under either of these licenses. 15 | // You should bear the consequences of using the software (named 'java-debug-tool') 16 | // and any modify must be create an new pull request and attach an text to describe 17 | // the change detail. 18 | // ======================================================================== 19 | // 20 | 21 | 22 | package io.javadebug.core.monitor.net; 23 | 24 | import io.javadebug.core.monitor.CounterEvent; 25 | import io.javadebug.core.monitor.MonitorCollector; 26 | import io.javadebug.core.monitor.MonitorConsume; 27 | import io.javadebug.core.monitor.MonitorHandler; 28 | 29 | public enum NetworkMonitorCollector implements MonitorCollector { 30 | NETWORK_MONITOR_COLLECTOR 31 | ; 32 | 33 | 34 | /** 35 | * collect the event by your way, and the implement need to response real-time, do 36 | * not do scheduler or cache something in your implement, this function will be called 37 | * by {@link MonitorHandler}, as Producer, the {@link MonitorConsume} will consume 38 | * the event produced by this method; 39 | * 40 | * @return the origin event 41 | */ 42 | @Override 43 | public CounterEvent collect() { 44 | return null; 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /core/src/main/java/io/javadebug/core/monitor/netty/NettyMonitorCollector.java: -------------------------------------------------------------------------------- 1 | // 2 | // ======================================================================== 3 | // Copyright (c) 2018-2019 HuJian/Pandening soft collection. 4 | // ------------------------------------------------------------------------ 5 | // All rights reserved. This program and the accompanying materials 6 | // are made available under the terms of the #{license} Public License #{version} 7 | // EG: 8 | // The Eclipse Public License is available at 9 | // http://www.eclipse.org/legal/epl-v10.html 10 | // 11 | // The Apache License v2.0 is available at 12 | // http://www.opensource.org/licenses/apache2.0.php 13 | // 14 | // You may elect to redistribute this code under either of these licenses. 15 | // You should bear the consequences of using the software (named 'java-debug-tool') 16 | // and any modify must be create an new pull request and attach an text to describe 17 | // the change detail. 18 | // ======================================================================== 19 | // 20 | 21 | 22 | package io.javadebug.core.monitor.netty; 23 | 24 | import io.javadebug.core.monitor.CounterEvent; 25 | import io.javadebug.core.monitor.MonitorCollector; 26 | import io.javadebug.core.monitor.MonitorConsume; 27 | import io.javadebug.core.monitor.MonitorHandler; 28 | 29 | public enum NettyMonitorCollector implements MonitorCollector { 30 | NETTY_MONITOR_COLLECTOR 31 | ; 32 | 33 | /** 34 | * collect the event by your way, and the implement need to response real-time, do 35 | * not do scheduler or cache something in your implement, this function will be called 36 | * by {@link MonitorHandler}, as Producer, the {@link MonitorConsume} will consume 37 | * the event produced by this method; 38 | * 39 | * @return the origin event 40 | */ 41 | @Override 42 | public CounterEvent collect() { 43 | return null; 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /core/src/main/java/io/javadebug/core/monitor/sys/SystemMonitorCollector.java: -------------------------------------------------------------------------------- 1 | // 2 | // ======================================================================== 3 | // Copyright (c) 2018-2019 HuJian/Pandening soft collection. 4 | // ------------------------------------------------------------------------ 5 | // All rights reserved. This program and the accompanying materials 6 | // are made available under the terms of the #{license} Public License #{version} 7 | // EG: 8 | // The Eclipse Public License is available at 9 | // http://www.eclipse.org/legal/epl-v10.html 10 | // 11 | // The Apache License v2.0 is available at 12 | // http://www.opensource.org/licenses/apache2.0.php 13 | // 14 | // You may elect to redistribute this code under either of these licenses. 15 | // You should bear the consequences of using the software (named 'java-debug-tool') 16 | // and any modify must be create an new pull request and attach an text to describe 17 | // the change detail. 18 | // ======================================================================== 19 | // 20 | 21 | 22 | package io.javadebug.core.monitor.sys; 23 | 24 | import io.javadebug.core.monitor.CounterEvent; 25 | import io.javadebug.core.monitor.MonitorCollector; 26 | import io.javadebug.core.monitor.MonitorConsume; 27 | import io.javadebug.core.monitor.MonitorHandler; 28 | 29 | public enum SystemMonitorCollector implements MonitorCollector { 30 | SYSTEM_MONITOR_COLLECTOR 31 | ; 32 | 33 | /** 34 | * collect the event by your way, and the implement need to response real-time, do 35 | * not do scheduler or cache something in your implement, this function will be called 36 | * by {@link MonitorHandler}, as Producer, the {@link MonitorConsume} will consume 37 | * the event produced by this method; 38 | * 39 | * @return the origin event 40 | */ 41 | @Override 42 | public CounterEvent collect() { 43 | return null; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /core/src/main/java/io/javadebug/core/record/InternalLoggerRecord.java: -------------------------------------------------------------------------------- 1 | // 2 | // ======================================================================== 3 | // Copyright (c) 2018-2019 HuJian/Pandening soft collection. 4 | // ------------------------------------------------------------------------ 5 | // All rights reserved. This program and the accompanying materials 6 | // are made available under the terms of the #{license} Public License #{version} 7 | // EG: 8 | // The Eclipse Public License is available at 9 | // http://www.eclipse.org/legal/epl-v10.html 10 | // 11 | // The Apache License v2.0 is available at 12 | // http://www.opensource.org/licenses/apache2.0.php 13 | // 14 | // You may elect to redistribute this code under either of these licenses. 15 | // You should bear the consequences of using the software (named 'java-debug-tool') 16 | // and any modify must be create an new pull request and attach an text to describe 17 | // the change detail. 18 | // ======================================================================== 19 | // 20 | 21 | 22 | package io.javadebug.core.record; 23 | 24 | import io.javadebug.core.log.InternalLogger; 25 | import io.javadebug.core.log.InternalLoggerFactory; 26 | 27 | public class InternalLoggerRecord implements Log { 28 | 29 | // the history logger 30 | private static final InternalLogger LOGGER = InternalLoggerFactory.getLogger("h"); 31 | 32 | /** 33 | * write the log to target output 34 | * 35 | * @param log the log data 36 | */ 37 | @Override 38 | public void write(String log) { 39 | LOGGER.info(log); 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /core/src/main/java/io/javadebug/core/record/Log.java: -------------------------------------------------------------------------------- 1 | // 2 | // ======================================================================== 3 | // Copyright (c) 2018-2019 HuJian/Pandening soft collection. 4 | // ------------------------------------------------------------------------ 5 | // All rights reserved. This program and the accompanying materials 6 | // are made available under the terms of the #{license} Public License #{version} 7 | // EG: 8 | // The Eclipse Public License is available at 9 | // http://www.eclipse.org/legal/epl-v10.html 10 | // 11 | // The Apache License v2.0 is available at 12 | // http://www.opensource.org/licenses/apache2.0.php 13 | // 14 | // You may elect to redistribute this code under either of these licenses. 15 | // You should bear the consequences of using the software (named 'java-debug-tool') 16 | // and any modify must be create an new pull request and attach an text to describe 17 | // the change detail. 18 | // ======================================================================== 19 | // 20 | 21 | 22 | package io.javadebug.core.record; 23 | 24 | public interface Log { 25 | 26 | /** 27 | * write the log to target output 28 | * 29 | * @param log the log data 30 | */ 31 | void write(String log); 32 | 33 | } 34 | -------------------------------------------------------------------------------- /core/src/main/java/io/javadebug/core/thirdparty/ThirdPartyAbility.java: -------------------------------------------------------------------------------- 1 | // 2 | // ======================================================================== 3 | // Copyright (c) 2018-2019 HuJian/Pandening soft collection. 4 | // ------------------------------------------------------------------------ 5 | // All rights reserved. This program and the accompanying materials 6 | // are made available under the terms of the #{license} Public License #{version} 7 | // EG: 8 | // The Eclipse Public License is available at 9 | // http://www.eclipse.org/legal/epl-v10.html 10 | // 11 | // The Apache License v2.0 is available at 12 | // http://www.opensource.org/licenses/apache2.0.php 13 | // 14 | // You may elect to redistribute this code under either of these licenses. 15 | // You should bear the consequences of using the software (named 'java-debug-tool') 16 | // and any modify must be create an new pull request and attach an text to describe 17 | // the change detail. 18 | // ======================================================================== 19 | // 20 | 21 | 22 | /** 23 | * Copyright © 2019-XXX HJ All Rights Reserved 24 | * 25 | * 26 | * 27 | * 28 | * 29 | * 30 | * 31 | * 32 | * 33 | */ 34 | // Author : HJ 35 | 36 | 37 | package io.javadebug.core.thirdparty; 38 | 39 | import io.javadebug.core.thirdparty.exception.ThirtPartyAbilityNotFindException; 40 | import io.javadebug.core.thirdparty.exception.ThirtyPartyExecuteException; 41 | import io.javadebug.core.transport.RemoteCommand; 42 | 43 | /** 44 | * 第三方类库的能力抽象定义,区分不同类库的性质来决定怎么实现能力抽象,参考 45 | * {@link ThirdPartyAttribute} 46 | * 47 | * @author pandening 48 | * 49 | * @since 2.0 50 | */ 51 | public interface ThirdPartyAbility { 52 | 53 | /** 54 | * 第三方类库执行命令,获取响应的入口 55 | * 56 | * @param remoteCommand Java-debug-tool协议结构体 57 | * @return 命令执行结果 58 | */ 59 | String exec(RemoteCommand remoteCommand) throws ThirtPartyAbilityNotFindException, ThirtyPartyExecuteException; 60 | 61 | /** 62 | * 某些情况下,执行某个第三方命令需要安装一个安全保障组件,这样不至于在用户输入错误或者不符合命令 63 | * 规范的情况下对系统造成影响 64 | * 65 | * @param remoteCommand 命令协议 66 | * @return {@link ThirdPartySafetyDetective} 67 | */ 68 | ThirdPartySafetyDetective detective(RemoteCommand remoteCommand); 69 | 70 | } 71 | -------------------------------------------------------------------------------- /core/src/main/java/io/javadebug/core/thirdparty/ThirdPartyAttribute.java: -------------------------------------------------------------------------------- 1 | // 2 | // ======================================================================== 3 | // Copyright (c) 2018-2019 HuJian/Pandening soft collection. 4 | // ------------------------------------------------------------------------ 5 | // All rights reserved. This program and the accompanying materials 6 | // are made available under the terms of the #{license} Public License #{version} 7 | // EG: 8 | // The Eclipse Public License is available at 9 | // http://www.eclipse.org/legal/epl-v10.html 10 | // 11 | // The Apache License v2.0 is available at 12 | // http://www.opensource.org/licenses/apache2.0.php 13 | // 14 | // You may elect to redistribute this code under either of these licenses. 15 | // You should bear the consequences of using the software (named 'java-debug-tool') 16 | // and any modify must be create an new pull request and attach an text to describe 17 | // the change detail. 18 | // ======================================================================== 19 | // 20 | 21 | 22 | /** 23 | * Copyright © 2019-XXX HJ All Rights Reserved 24 | * 25 | * 26 | * 27 | * 28 | * 29 | * 30 | * 31 | * 32 | * 33 | */ 34 | // Author : HJ 35 | 36 | 37 | package io.javadebug.core.thirdparty; 38 | 39 | public enum ThirdPartyAttribute { 40 | 41 | COMMAND_LINE_TOOL, // 命令行工具,可以直接输入命令来执行获取输出 42 | LIBRIRY // 类库,需要进行编程来实现某种功能 43 | ; 44 | 45 | } 46 | -------------------------------------------------------------------------------- /core/src/main/java/io/javadebug/core/thirdparty/ThirdPartySafetyController.java: -------------------------------------------------------------------------------- 1 | // 2 | // ======================================================================== 3 | // Copyright (c) 2018-2019 HuJian/Pandening soft collection. 4 | // ------------------------------------------------------------------------ 5 | // All rights reserved. This program and the accompanying materials 6 | // are made available under the terms of the #{license} Public License #{version} 7 | // EG: 8 | // The Eclipse Public License is available at 9 | // http://www.eclipse.org/legal/epl-v10.html 10 | // 11 | // The Apache License v2.0 is available at 12 | // http://www.opensource.org/licenses/apache2.0.php 13 | // 14 | // You may elect to redistribute this code under either of these licenses. 15 | // You should bear the consequences of using the software (named 'java-debug-tool') 16 | // and any modify must be create an new pull request and attach an text to describe 17 | // the change detail. 18 | // ======================================================================== 19 | // 20 | 21 | 22 | /** 23 | * Copyright © 2019-XXX HJ All Rights Reserved 24 | * 25 | * 26 | * 27 | * 28 | * 29 | * 30 | * 31 | * 32 | * 33 | */ 34 | // Author : HJ 35 | 36 | 37 | package io.javadebug.core.thirdparty; 38 | 39 | import io.javadebug.core.transport.RemoteCommand; 40 | import io.netty.util.HashedWheelTimer; 41 | 42 | /** 43 | * 因为第三方类库的特点,可能存在一些会让调试者遗留的工作,所以,需要有一个角色来为这种 44 | * 不愉快的操作进行收场,一个好的方式就是在进行一次第三方命令执行的时候,注册一个安全监测 45 | * 手段,这个安全操作手段有能力在用户出现操作失误、不完善的操作的情况下进行系统保护 46 | * 47 | * @author pandening 48 | * 49 | * @since 2.0 50 | */ 51 | public class ThirdPartySafetyController { 52 | 53 | /** 54 | * 55 | * 为命令注册一个检测器 56 | * 57 | * @param detective {@link ThirdPartySafetyDetective} 58 | * @param remoteCommand {@link RemoteCommand} 59 | */ 60 | public static void registerSafetyDetective(ThirdPartySafetyDetective detective, 61 | RemoteCommand remoteCommand) { 62 | HashedWheelTimer hashedWheelTimer; 63 | } 64 | 65 | } 66 | -------------------------------------------------------------------------------- /core/src/main/java/io/javadebug/core/thirdparty/ThirdPartySafetyDetective.java: -------------------------------------------------------------------------------- 1 | // 2 | // ======================================================================== 3 | // Copyright (c) 2018-2019 HuJian/Pandening soft collection. 4 | // ------------------------------------------------------------------------ 5 | // All rights reserved. This program and the accompanying materials 6 | // are made available under the terms of the #{license} Public License #{version} 7 | // EG: 8 | // The Eclipse Public License is available at 9 | // http://www.eclipse.org/legal/epl-v10.html 10 | // 11 | // The Apache License v2.0 is available at 12 | // http://www.opensource.org/licenses/apache2.0.php 13 | // 14 | // You may elect to redistribute this code under either of these licenses. 15 | // You should bear the consequences of using the software (named 'java-debug-tool') 16 | // and any modify must be create an new pull request and attach an text to describe 17 | // the change detail. 18 | // ======================================================================== 19 | // 20 | 21 | 22 | /** 23 | * Copyright © 2019-XXX HJ All Rights Reserved 24 | * 25 | * 26 | * 27 | * 28 | * 29 | * 30 | * 31 | * 32 | * 33 | */ 34 | // Author : HJ 35 | 36 | 37 | package io.javadebug.core.thirdparty; 38 | 39 | import io.javadebug.core.log.PSLogger; 40 | 41 | /** 42 | * 安全监测手段,应该运行在线程池中,定时触发监测,维护系统安全运行 43 | * 44 | * @author pandening 45 | * @since 2.0 46 | */ 47 | public abstract class ThirdPartySafetyDetective implements Runnable { 48 | 49 | /** 50 | * When an object implementing interface Runnable is used 51 | * to create a thread, starting the thread causes the object's 52 | * run method to be called in that separately executing 53 | * thread. 54 | *

55 | * The general contract of the method run is that it may 56 | * take any action whatsoever. 57 | * 58 | * @see Thread#run() 59 | */ 60 | @Override 61 | public void run() { 62 | try { 63 | doDetective(); 64 | } catch (Exception e) { 65 | PSLogger.error("could not run doDetective:" + e); 66 | } 67 | } 68 | 69 | protected abstract void doDetective(); 70 | 71 | } 72 | -------------------------------------------------------------------------------- /core/src/main/java/io/javadebug/core/ui/UI.java: -------------------------------------------------------------------------------- 1 | // 2 | // ======================================================================== 3 | // Copyright (c) 2018-2019 HuJian/Pandening soft collection. 4 | // ------------------------------------------------------------------------ 5 | // All rights reserved. This program and the accompanying materials 6 | // are made available under the terms of the #{license} Public License #{version} 7 | // EG: 8 | // The Eclipse Public License is available at 9 | // http://www.eclipse.org/legal/epl-v10.html 10 | // 11 | // The Apache License v2.0 is available at 12 | // http://www.opensource.org/licenses/apache2.0.php 13 | // 14 | // You may elect to redistribute this code under either of these licenses. 15 | // You should bear the consequences of using the software (named 'java-debug-tool') 16 | // and any modify must be create an new pull request and attach an text to describe 17 | // the change detail. 18 | // ======================================================================== 19 | // 20 | 21 | 22 | /** 23 | * Copyright © 2019-XXX HJ All Rights Reserved 24 | * 25 | * 26 | * 27 | * 28 | * 29 | * 30 | * 31 | * 32 | * 33 | */ 34 | // Author : HJ 35 | 36 | 37 | package io.javadebug.core.ui; 38 | 39 | import io.javadebug.core.transport.RemoteCommand; 40 | 41 | /** 42 | * Created on 2019/4/21 00:00. 43 | * 44 | * @author HuJian 45 | */ 46 | public interface UI { 47 | 48 | /** 49 | * 每一个命令返回结果都是一种通用模型,所以可以做一个通用UI,如果需要实现 50 | * 个性化展示样式,可以实现该方法 51 | * 52 | * @param remoteCommand {@link RemoteCommand} 53 | * @return 展示字符串 54 | */ 55 | String toUI(RemoteCommand remoteCommand); 56 | 57 | } 58 | -------------------------------------------------------------------------------- /core/src/main/java/io/javadebug/core/utils/MapKeyDeserializers.java: -------------------------------------------------------------------------------- 1 | // 2 | // ======================================================================== 3 | // Copyright (c) 2018-2019 HuJian/Pandening soft collection. 4 | // ------------------------------------------------------------------------ 5 | // All rights reserved. This program and the accompanying materials 6 | // are made available under the terms of the #{license} Public License #{version} 7 | // EG: 8 | // The Eclipse Public License is available at 9 | // http://www.eclipse.org/legal/epl-v10.html 10 | // 11 | // The Apache License v2.0 is available at 12 | // http://www.opensource.org/licenses/apache2.0.php 13 | // 14 | // You may elect to redistribute this code under either of these licenses. 15 | // You should bear the consequences of using the software (named 'java-debug-tool') 16 | // and any modify must be create an new pull request and attach an text to describe 17 | // the change detail. 18 | // ======================================================================== 19 | // 20 | 21 | 22 | /** 23 | * Copyright © 2019-XXX HJ All Rights Reserved 24 | * 25 | * 26 | * 27 | * 28 | * 29 | * 30 | * 31 | * 32 | * 33 | */ 34 | // Author : HJ 35 | 36 | 37 | package io.javadebug.core.utils; 38 | 39 | import com.fasterxml.jackson.databind.BeanDescription; 40 | import com.fasterxml.jackson.databind.DeserializationConfig; 41 | import com.fasterxml.jackson.databind.JavaType; 42 | import com.fasterxml.jackson.databind.KeyDeserializer; 43 | import com.fasterxml.jackson.databind.module.SimpleKeyDeserializers; 44 | 45 | public class MapKeyDeserializers extends SimpleKeyDeserializers { 46 | 47 | private static final KeyDeserializer DEFAULT = new MapKeyDeserializer(); 48 | 49 | @Override 50 | public KeyDeserializer findKeyDeserializer(JavaType type, DeserializationConfig config, BeanDescription beanDesc) { 51 | KeyDeserializer deserializer = super.findKeyDeserializer(type, config, beanDesc); 52 | 53 | return deserializer != null ? deserializer : DEFAULT; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /core/src/main/java/io/javadebug/core/utils/MemoryUtils.java: -------------------------------------------------------------------------------- 1 | // 2 | // ======================================================================== 3 | // Copyright (c) 2018-2019 HuJian/Pandening soft collection. 4 | // ------------------------------------------------------------------------ 5 | // All rights reserved. This program and the accompanying materials 6 | // are made available under the terms of the #{license} Public License #{version} 7 | // EG: 8 | // The Eclipse Public License is available at 9 | // http://www.eclipse.org/legal/epl-v10.html 10 | // 11 | // The Apache License v2.0 is available at 12 | // http://www.opensource.org/licenses/apache2.0.php 13 | // 14 | // You may elect to redistribute this code under either of these licenses. 15 | // You should bear the consequences of using the software (named 'java-debug-tool') 16 | // and any modify must be create an new pull request and attach an text to describe 17 | // the change detail. 18 | // ======================================================================== 19 | // 20 | 21 | 22 | package io.javadebug.core.utils; 23 | 24 | import io.javadebug.core.data.JVMMemoryInfo; 25 | 26 | public class MemoryUtils { 27 | 28 | /** 29 | * simple create an new instance of Type: {@link JVMMemoryInfo} 30 | * 31 | * @return the instance of jvm memory info 32 | */ 33 | public static JVMMemoryInfo getMemory() { 34 | return new JVMMemoryInfo(); 35 | } 36 | 37 | public static void main(String[] args) { 38 | System.out.println(getMemory()); 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /core/src/main/java/io/javadebug/core/utils/ObjectWrapper.java: -------------------------------------------------------------------------------- 1 | // 2 | // ======================================================================== 3 | // Copyright (c) 2018-2019 HuJian/Pandening soft collection. 4 | // ------------------------------------------------------------------------ 5 | // All rights reserved. This program and the accompanying materials 6 | // are made available under the terms of the #{license} Public License #{version} 7 | // EG: 8 | // The Eclipse Public License is available at 9 | // http://www.eclipse.org/legal/epl-v10.html 10 | // 11 | // The Apache License v2.0 is available at 12 | // http://www.opensource.org/licenses/apache2.0.php 13 | // 14 | // You may elect to redistribute this code under either of these licenses. 15 | // You should bear the consequences of using the software (named 'java-debug-tool') 16 | // and any modify must be create an new pull request and attach an text to describe 17 | // the change detail. 18 | // ======================================================================== 19 | // 20 | 21 | 22 | package io.javadebug.core.utils; 23 | 24 | public class ObjectWrapper { 25 | public T obj; 26 | } 27 | -------------------------------------------------------------------------------- /core/src/main/native/cputime.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by hujian on 2019/11/1. 3 | // 4 | 5 | #include 6 | #include 7 | 8 | #include "cputime.h" 9 | 10 | // just test ! 11 | static int clock_tics_per_sec = 100; 12 | 13 | // Return the real, user, and system times in seconds from an 14 | // arbitrary fixed point in the past. 15 | bool getTimesSecs(double* process_real_time, 16 | double* process_user_time, 17 | double* process_system_time) { 18 | struct tms ticks; 19 | clock_t real_ticks = times(&ticks); 20 | 21 | if (real_ticks == (clock_t) (-1)) { 22 | return false; 23 | } else { 24 | double ticks_per_second = (double) clock_tics_per_sec; 25 | *process_user_time = ((double) ticks.tms_utime) / ticks_per_second; 26 | *process_system_time = ((double) ticks.tms_stime) / ticks_per_second; 27 | *process_real_time = ((double) real_ticks) / ticks_per_second; 28 | 29 | return true; 30 | } 31 | } -------------------------------------------------------------------------------- /core/src/main/native/cputime.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by hujian on 2019/11/1. 3 | // 4 | 5 | #ifndef CPUTIME_CPUTIME_H 6 | #define CPUTIME_CPUTIME_H 7 | 8 | // Return the real, user, and system times in seconds from an 9 | // arbitrary fixed point in the past. 10 | extern "C" 11 | bool getTimesSecs(double* process_real_time, /* walk clock time */ 12 | double* process_user_time, /* User CPU time for all threads */ 13 | double* process_system_time /* System CPU time */ 14 | ); 15 | 16 | #endif //CPUTIME_CPUTIME_H 17 | -------------------------------------------------------------------------------- /core/src/main/resources/libcputime.dylib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pandening/Java-debug-tool/e12244af5c6310186ae02dce4140bd408096ba87/core/src/main/resources/libcputime.dylib -------------------------------------------------------------------------------- /core/src/main/resources/libcputime.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pandening/Java-debug-tool/e12244af5c6310186ae02dce4140bd408096ba87/core/src/main/resources/libcputime.so -------------------------------------------------------------------------------- /core/src/test/java/ByteStringTest.java: -------------------------------------------------------------------------------- 1 | // 2 | // ======================================================================== 3 | // Copyright (c) 2018-2019 HuJian/Pandening soft collection. 4 | // ------------------------------------------------------------------------ 5 | // All rights reserved. This program and the accompanying materials 6 | // are made available under the terms of the #{license} Public License #{version} 7 | // EG: 8 | // The Eclipse Public License is available at 9 | // http://www.eclipse.org/legal/epl-v10.html 10 | // 11 | // The Apache License v2.0 is available at 12 | // http://www.opensource.org/licenses/apache2.0.php 13 | // 14 | // You may elect to redistribute this code under either of these licenses. 15 | // You should bear the consequences of using the software (named 'java-debug-tool') 16 | // and any modify must be create an new pull request and attach an text to describe 17 | // the change detail. 18 | // ======================================================================== 19 | // 20 | 21 | 22 | /** 23 | * Copyright © 2019-XXX HJ All Rights Reserved 24 | * 25 | * 26 | * 27 | * 28 | * 29 | * 30 | * 31 | * 32 | * 33 | */ 34 | // Auth : HJ 35 | 36 | 37 | /** 38 | * Created on 2019/4/19 12:13. 39 | * 40 | * @author HuJian 41 | */ 42 | public class ByteStringTest { 43 | 44 | static String file = "/Users/hujian06/github/java-debug/core/target/classes/io/javadebug/core/UTILS.class"; 45 | 46 | public static void main(String[] args) throws Exception { 47 | 48 | String p = "aa aa ss aa"; 49 | for (String s : p.split(" ")) { 50 | System.out.println(s + "]"); 51 | } 52 | 53 | } 54 | 55 | 56 | } 57 | -------------------------------------------------------------------------------- /core/src/test/java/PatternTest.java: -------------------------------------------------------------------------------- 1 | // 2 | // ======================================================================== 3 | // Copyright (c) 2018-2019 HuJian/Pandening soft collection. 4 | // ------------------------------------------------------------------------ 5 | // All rights reserved. This program and the accompanying materials 6 | // are made available under the terms of the #{license} Public License #{version} 7 | // EG: 8 | // The Eclipse Public License is available at 9 | // http://www.eclipse.org/legal/epl-v10.html 10 | // 11 | // The Apache License v2.0 is available at 12 | // http://www.opensource.org/licenses/apache2.0.php 13 | // 14 | // You may elect to redistribute this code under either of these licenses. 15 | // You should bear the consequences of using the software (named 'java-debug-tool') 16 | // and any modify must be create an new pull request and attach an text to describe 17 | // the change detail. 18 | // ======================================================================== 19 | // 20 | 21 | 22 | /** 23 | * Copyright © 2019-XXX HJ All Rights Reserved 24 | * 25 | * 26 | * 27 | * 28 | * 29 | * 30 | * 31 | * 32 | * 33 | */ 34 | // Author : HJ 35 | 36 | 37 | import java.util.regex.Pattern; 38 | 39 | /** 40 | * Created on 2019/4/26 23:09. 41 | * 42 | * @author HuJian 43 | */ 44 | public class PatternTest { 45 | 46 | 47 | public static void main(String[] args) { 48 | 49 | Pattern pattern = Pattern.compile(".*String.*"); 50 | 51 | 52 | String a = "java.lang.String"; 53 | String b = "string"; 54 | String c = "String"; 55 | String d = "Strings"; 56 | String e = "string"; 57 | 58 | System.out.println(pattern.matcher(a).matches()); 59 | System.out.println(pattern.matcher(b).matches()); 60 | System.out.println(pattern.matcher(c).matches()); 61 | System.out.println(pattern.matcher(d).matches()); 62 | System.out.println(pattern.matcher(e).matches()); 63 | 64 | 65 | } 66 | 67 | } 68 | -------------------------------------------------------------------------------- /core/src/test/java/Test.java: -------------------------------------------------------------------------------- 1 | // 2 | // ======================================================================== 3 | // Copyright (c) 2018-2019 HuJian/Pandening soft collection. 4 | // ------------------------------------------------------------------------ 5 | // All rights reserved. This program and the accompanying materials 6 | // are made available under the terms of the #{license} Public License #{version} 7 | // EG: 8 | // The Eclipse Public License is available at 9 | // http://www.eclipse.org/legal/epl-v10.html 10 | // 11 | // The Apache License v2.0 is available at 12 | // http://www.opensource.org/licenses/apache2.0.php 13 | // 14 | // You may elect to redistribute this code under either of these licenses. 15 | // You should bear the consequences of using the software (named 'java-debug-tool') 16 | // and any modify must be create an new pull request and attach an text to describe 17 | // the change detail. 18 | // ======================================================================== 19 | // 20 | 21 | 22 | /** 23 | * Copyright © 2019-XXX HJ All Rights Reserved 24 | * 25 | * 26 | * 27 | * 28 | * 29 | * 30 | * 31 | * 32 | * 33 | */ 34 | // Author : HJ 35 | 36 | 37 | import java.util.HashMap; 38 | import java.util.Map; 39 | 40 | public class Test { 41 | 42 | public static void main(String[] args) { 43 | 44 | Map map = new HashMap<>(); 45 | 46 | map.put(new Integer(1), "i am hujian"); 47 | 48 | String old = map.remove(1); 49 | 50 | System.out.println(old); 51 | 52 | String cls = "io/javadebug/core/Configure"; 53 | 54 | System.out.println(cls.replaceAll("/", ".")); 55 | 56 | 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /core/src/test/java/UITest.java: -------------------------------------------------------------------------------- 1 | // 2 | // ======================================================================== 3 | // Copyright (c) 2018-2019 HuJian/Pandening soft collection. 4 | // ------------------------------------------------------------------------ 5 | // All rights reserved. This program and the accompanying materials 6 | // are made available under the terms of the #{license} Public License #{version} 7 | // EG: 8 | // The Eclipse Public License is available at 9 | // http://www.eclipse.org/legal/epl-v10.html 10 | // 11 | // The Apache License v2.0 is available at 12 | // http://www.opensource.org/licenses/apache2.0.php 13 | // 14 | // You may elect to redistribute this code under either of these licenses. 15 | // You should bear the consequences of using the software (named 'java-debug-tool') 16 | // and any modify must be create an new pull request and attach an text to describe 17 | // the change detail. 18 | // ======================================================================== 19 | // 20 | 21 | 22 | /** 23 | * Copyright © 2019-XXX HJ All Rights Reserved 24 | * 25 | * 26 | * 27 | * 28 | * 29 | * 30 | * 31 | * 32 | * 33 | */ 34 | // Author : HJ 35 | 36 | 37 | import io.javadebug.core.transport.RemoteCommand; 38 | import io.javadebug.core.ui.UI; 39 | 40 | /** 41 | * Created on 2019/4/21 11:46. 42 | * 43 | * @author HuJian 44 | */ 45 | public class UITest { 46 | 47 | // public static void main(String[] args) { 48 | // 49 | // UI ui = new Table(); 50 | // 51 | // RemoteCommand remoteCommand = new RemoteCommand(); 52 | // 53 | // remoteCommand.setTimeStamp(System.currentTimeMillis()); 54 | // remoteCommand.setCommandName("hello"); 55 | // remoteCommand.addParam("$back-data", "这里是测试,看看有没有美观的输出响应结果了"); 56 | // 57 | // String show = ui.toUI(remoteCommand); 58 | // 59 | // System.out.println(show); 60 | // } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /header: -------------------------------------------------------------------------------- 1 | // 2 | // ======================================================================== 3 | // Copyright (c) 2018-2019 HuJian/Pandening soft collection. 4 | // ------------------------------------------------------------------------ 5 | // All rights reserved. This program and the accompanying materials 6 | // are made available under the terms of the #{license} Public License #{version} 7 | // EG: 8 | // The Eclipse Public License is available at 9 | // http://www.eclipse.org/legal/epl-v10.html 10 | // 11 | // The Apache License v2.0 is available at 12 | // http://www.opensource.org/licenses/apache2.0.php 13 | // 14 | // You may elect to redistribute this code under either of these licenses. 15 | // You should bear the consequences of using the software (named 'java-debug-tool') 16 | // and any modify must be create an new pull request and attach an text to describe 17 | // the change detail. 18 | // ======================================================================== 19 | // 20 | 21 | 22 | -------------------------------------------------------------------------------- /java-debug-tool.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pandening/Java-debug-tool/e12244af5c6310186ae02dce4140bd408096ba87/java-debug-tool.zip -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | io.javadebug 8 | java-debug 9 | pom 10 | 1.0-SNAPSHOT 11 | 12 | agent 13 | core 14 | test 15 | 16 | 17 | -------------------------------------------------------------------------------- /releasenote.md: -------------------------------------------------------------------------------- 1 | ## 1.0 2 | 3 | * base function 4 | 5 | 6 | ## 2.0 7 | 8 | * easy-used -------------------------------------------------------------------------------- /roadmap.md: -------------------------------------------------------------------------------- 1 | ## 近期开发计划 2 | 3 | * debugging 4 | * 优化用户体验,精简指令 5 | * 优化代码增强模块,使得增强代码可定制 6 | * 优化代码结构,对现有代码进行重构 7 | 8 | * profiling 9 | * 增加轻量级cpu热点探测能力 10 | * 完善性能问题诊断流程 11 | 12 | * new features 13 | * 前端界面替换命令行输入输出,使得诊断过程可视化 14 | * 扩展点提取,比如探测报警,使得可以长时间运行自动发现问题发出告警 -------------------------------------------------------------------------------- /script/hello.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | BASEDIR="$( cd "$( dirname "$0" )" && pwd )" 4 | 5 | # hello world 6 | echo "welcome to use java-debug-tool" 7 | 8 | cat ${BASEDIR}/logo 9 | -------------------------------------------------------------------------------- /script/javadebug-client-launch.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Date : 2019-04-18 23:00 4 | # Auth : Hu Jian 5 | # Version : 1.0 6 | # Function : 用于调试目标JVM的客户端,请在本机启动该脚本连接远程JVM进行调试 7 | 8 | 9 | # the base dir 10 | # bin/..... 11 | EXECUTE_BASE_DIR="$( cd "$( dirname "$0" )" && pwd )" 12 | 13 | # define the default ip 14 | DEFAULT_TARGET_IP=127.0.0.1 15 | 16 | # define the default port 17 | DEFAULT_TARGET_PORT=11234 18 | 19 | function usage() { 20 | 21 | echo " 22 | java-debug-console usage: 23 | javadebug-console-launch.sh [ip:port] 24 | 25 | ip:port : the target jvm host info, optional 26 | 27 | example: 28 | ./javadebug-console-launch.sh 127.0.0.1:11234 29 | " 30 | 31 | 32 | } 33 | # parse the argument 34 | function parse_arguments() 35 | { 36 | 37 | TARGET_IP=$(echo ${1}|awk '/^[0-9]*@/;/^[^@]+:/{print "@"$1};/^[0-9]+$/'|awk -F "@|:" '{print $2}'); 38 | TARGET_PORT=$(echo ${1}|awk '/^[0-9]*@/;/^[^@]+:/{print "@"$1};/^[0-9]+$/'|awk -F ":" '{print $2}'); 39 | 40 | # # check pid 41 | # if [ -z ${TARGET_IP} ];then 42 | # echo "illegal arguments, the is required." 43 | # exit 1 44 | # fi 45 | # 46 | # # check pid 47 | # if [ -z ${TARGET_PORT} ];then 48 | # echo "illegal arguments, the is required." 49 | # exit 1 50 | # fi 51 | 52 | # set default ip 53 | [ -z ${TARGET_IP} ] && TARGET_IP=${DEFAULT_TARGET_IP} 54 | 55 | # set default port 56 | [ -z ${TARGET_PORT} ] && TARGET_PORT=${DEFAULT_TARGET_PORT} 57 | 58 | return 0 59 | 60 | } 61 | 62 | # using io.javadebug.core.TcpClient 63 | # 64 | # connect to remote jvm tcpServer to exec debug. 65 | function execConsole() { 66 | 67 | # show the usage 68 | usage 69 | 70 | echo "start to connect to remote jvm tcp server ${TARGET_IP}:${TARGET_PORT}" 71 | 72 | parse_arguments "${@}" 73 | 74 | JAVA_COMMAND="java" 75 | if [ ! -z ${JAVA_VERSION} ]; then 76 | JAVA_COMMAND="/usr/local/${JAVA_VERSION}/bin/java" 77 | fi 78 | 79 | # run tcpClient 80 | 81 | ${JAVA_COMMAND} \ 82 | -cp ${EXECUTE_BASE_DIR}/lib/debug-core.jar \ 83 | io.javadebug.core.JavaDebugClientLauncher \ 84 | -ip ${TARGET_IP} \ 85 | -port ${TARGET_PORT} 86 | 87 | } 88 | 89 | execConsole "${@}" -------------------------------------------------------------------------------- /script/javadebug-cluster-launch.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Date : 2019-04-29 00:30 4 | # Auth : Hu Jian 5 | # Version : 1.0 6 | # Function : 用于调试多个目标JVM,前提是同一个命令向集群中的所有机器执行 7 | 8 | 9 | # the base dir 10 | # bin/..... 11 | EXECUTE_BASE_DIR="$( cd "$( dirname "$0" )" && pwd )" 12 | 13 | function usage() { 14 | 15 | echo " 16 | java-debug-cluster-console usage: 17 | javadebug-cluster-launch.sh [ip:port,ip:port,ip,port] 18 | 19 | ip:port : the target jvm host info, optional 20 | 21 | example: 22 | ./javadebug-cluster-launch.sh 127.0.0.1:11234,11235 23 | " 24 | 25 | 26 | } 27 | 28 | # using io.javadebug.core.TcpClient 29 | # 30 | # connect to remote jvm tcpServer to exec debug. 31 | function execConsole() { 32 | 33 | # show the usage 34 | usage 35 | 36 | JAVA_COMMAND="java" 37 | if [ ! -z ${JAVA_VERSION} ]; then 38 | JAVA_COMMAND="/usr/local/${JAVA_VERSION}/bin/java" 39 | fi 40 | 41 | # run tcpClient 42 | 43 | ${JAVA_COMMAND} \ 44 | -cp ${EXECUTE_BASE_DIR}/lib/debug-core.jar \ 45 | io.javadebug.core.JavaDebugClusterClientLauncher \ 46 | -p "${@}" \ 47 | 48 | } 49 | 50 | execConsole "${@}" -------------------------------------------------------------------------------- /script/javadebug-http-server.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Date : 2019-11-24 19:31 4 | # Auth : Hu Jian 5 | # Version : 1.0 6 | # Function : 用于和目标JVM通信的http服务端,可以将命令通过http的方式进行调试 7 | 8 | # the base dir 9 | # bin/..... 10 | EXECUTE_BASE_DIR="$( cd "$( dirname "$0" )" && pwd )" 11 | 12 | REMOTE_IP="127.0.0.1" 13 | 14 | REMOTE_PORT=11234 15 | 16 | HTTP_SERVER_LISTEN_PORT=10234 17 | 18 | JAVA_COMMAND="java" 19 | 20 | 21 | # 22 | # for input some command like mt contains "#", you should 23 | # convert it to %23, the map table like this: 24 | # ======================= 25 | # character | trans 26 | # ======================= 27 | # space    %20 28 | # "        %22 29 | # #         %23 30 | # %         %25 31 | # &         %26 32 | # (         %28 33 | # )         %29 34 | # +         %2B 35 | # ,         %2C 36 | # /         %2F 37 | # :         %3A 38 | # ;         %3B 39 | # <         %3C 40 | # =         %3D 41 | # >         %3E 42 | # ?         %3F 43 | # @       %40 44 | # \         %5C 45 | # |         %7C  46 | # ======================= 47 | # 48 | 49 | # 50 | # to split the ct command's result, using grep,awk command to split the origin result 51 | # is so easy like this: 52 | # cat result.txt | grep -E ".*;.*;.*" | awk -F ';' '{print $1,$2,$3,$4}' 53 | # 54 | # 55 | 56 | # 57 | # $1 => remote ip 58 | # $2 => remote port 59 | # $3 => http server listen port 60 | # 61 | function http_server() { 62 | 63 | if [[ -n $1 ]]; then 64 | REMOTE_IP=$1 65 | fi 66 | 67 | if [[ -n $2 ]]; then 68 | REMOTE_PORT=$2 69 | fi 70 | 71 | if [[ -n $3 ]]; then 72 | HTTP_SERVER_LISTEN_PORT=$3 73 | fi 74 | 75 | echo "get the remote address : ${REMOTE_IP}:${REMOTE_PORT}, 76 | set up the http server on localhost:${HTTP_SERVER_LISTEN_PORT}, 77 | Open your web browser and navigate to 78 | http://127.0.0.1:${HTTP_SERVER_LISTEN_PORT}/java-debug-tool/shell/http/" 79 | 80 | ${JAVA_COMMAND} \ 81 | -cp ${EXECUTE_BASE_DIR}/lib/debug-core.jar \ 82 | io.javadebug.core.JavaDebugHttpServerLauncher \ 83 | ${REMOTE_IP} \ 84 | ${REMOTE_PORT} \ 85 | ${HTTP_SERVER_LISTEN_PORT} \ 86 | & 87 | 88 | } 89 | 90 | 91 | # set up the http server 92 | http_server "${@}" 93 | -------------------------------------------------------------------------------- /script/javadebug-simple-client.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Date : 2019-04-18 23:00 4 | # Auth : Hu Jian 5 | # Version : 1.0 6 | # Function : 用于调试目标JVM的客户端,请在本机启动该脚本连接远程JVM进行调试 7 | 8 | 9 | # the base dir 10 | # bin/..... 11 | EXECUTE_BASE_DIR="$( cd "$( dirname "$0" )" && pwd )" 12 | 13 | # define the default ip 14 | DEFAULT_TARGET_IP=127.0.0.1 15 | 16 | # define the default port 17 | DEFAULT_TARGET_PORT=11234 18 | 19 | # java version 20 | JAVA_VERSION=java8 21 | 22 | function usage() { 23 | 24 | echo " 25 | java-debug-console usage: 26 | javadebug-console-launch.sh [ip:port] 27 | 28 | ip:port : the target jvm host info, optional 29 | 30 | example: 31 | ./javadebug-console-launch.sh 127.0.0.1:11234 32 | " 33 | 34 | 35 | } 36 | # parse the argument 37 | function parse_arguments() 38 | { 39 | 40 | TARGET_IP=$(echo ${1}|awk '/^[0-9]*@/;/^[^@]+:/{print "@"$1};/^[0-9]+$/'|awk -F "@|:" '{print $2}'); 41 | TARGET_PORT=$(echo ${1}|awk '/^[0-9]*@/;/^[^@]+:/{print "@"$1};/^[0-9]+$/'|awk -F ":" '{print $2}'); 42 | 43 | # # check pid 44 | # if [ -z ${TARGET_IP} ];then 45 | # echo "illegal arguments, the is required." 46 | # exit 1 47 | # fi 48 | # 49 | # # check pid 50 | # if [ -z ${TARGET_PORT} ];then 51 | # echo "illegal arguments, the is required." 52 | # exit 1 53 | # fi 54 | 55 | # set default ip 56 | [[ -z ${TARGET_IP} ]] && TARGET_IP=${DEFAULT_TARGET_IP} 57 | 58 | # set default port 59 | [[ -z ${TARGET_PORT} ]] && TARGET_PORT=${DEFAULT_TARGET_PORT} 60 | 61 | return 0 62 | 63 | } 64 | 65 | # using io.javadebug.core.TcpClient 66 | # 67 | # connect to remote jvm tcpServer to exec debug. 68 | function execConsole() { 69 | 70 | # show the usage 71 | usage 72 | 73 | echo "start to connect to remote jvm tcp server ${TARGET_IP}:${TARGET_PORT}" 74 | 75 | parse_arguments "${@}" 76 | 77 | JAVA_COMMAND="/usr/local/${JAVA_VERSION}/bin/java" 78 | 79 | # run tcpClient 80 | 81 | ${JAVA_COMMAND} \ 82 | -cp ${EXECUTE_BASE_DIR}/lib/debug-core.jar \ 83 | io.javadebug.core.JavaDebugClientLauncher \ 84 | -ip ${TARGET_IP} \ 85 | -port ${TARGET_PORT} 86 | 87 | } 88 | 89 | execConsole "${@}" -------------------------------------------------------------------------------- /script/javadebug-source-header.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Date : 2019-04-18 23:00 4 | # Auth : Hu Jian 5 | # Version : 1.0 6 | # Function : 用于给java文件加头 7 | 8 | # 9 | # get指定的文件加上文件头 10 | function appendFileHeader() { 11 | FILE_PATH=$1 12 | if [[ -f ${FILE_PATH} ]]; then 13 | if [[ ${FILE_PATH} == *.java ]]; then 14 | if [[ `grep -c "Copyright" ${FILE_PATH}` -eq '0' ]]; then 15 | (echo '0a'; (cat ../header); echo '.'; echo 'wq') | ed -s ${FILE_PATH} 16 | fi 17 | fi 18 | else 19 | echo "the file path is empty, skip this file." 20 | fi 21 | } 22 | 23 | # 24 | # 循环遍历当前目录下的文件,给java文件加上文件头 25 | function scanJavaFileAndAppendHeader() { 26 | echo "scan:${1}" 27 | CUR_DIR=$1 28 | if [[ -f ${CUR_DIR} ]]; then 29 | # this is a file 30 | appendFileHeader ${CUR_DIR} 31 | elif [[ -d ${CUR_DIR} ]]; then 32 | # this is a directory 33 | for f in ${CUR_DIR}/* 34 | do 35 | scanJavaFileAndAppendHeader ${f} 36 | done 37 | fi 38 | } 39 | 40 | # 执行文件头替换 41 | 42 | BASE_DIR="$( cd "$( dirname "$0" )" && pwd )" 43 | 44 | # 不要重复执行 45 | 46 | time scanJavaFileAndAppendHeader ${BASE_DIR}/../ -------------------------------------------------------------------------------- /script/javadebug-tool-install.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | 4 | # java-debug-tool.zip name 5 | ZIP_NAME=java-debug-tool.zip 6 | 7 | # version 8 | JAVA_DEBUG_TOOL_VERSION=8.0 9 | 10 | # the zip url 11 | DOWNLOAD_URL=https://github.com/pandening/storm-ml/releases/download 12 | 13 | # work dir 14 | WORK_DIR=java-debug-tool 15 | 16 | function download() { 17 | #JAVA_DEBUG_TOOL_VERSION=$1 18 | 19 | echo "start to download release java-debug-tool.zip:${DOWNLOAD_URL}/${JAVA_DEBUG_TOOL_VERSION}/${ZIP_NAME}" 20 | 21 | wget ${DOWNLOAD_URL}/${JAVA_DEBUG_TOOL_VERSION}/${ZIP_NAME} 22 | 23 | # unzip 24 | echo "start to unzip the release zip" 25 | mkdir ${WORK_DIR} 26 | 27 | unzip ${ZIP_NAME} -d ${WORK_DIR} 28 | 29 | # test shell path 30 | HELLO_WORLD_SHELL_PATH=${WORK_DIR}/bin/hello.sh 31 | 32 | sh ${HELLO_WORLD_SHELL_PATH} 33 | } 34 | 35 | download 36 | 37 | -------------------------------------------------------------------------------- /script/javadebug-unpack.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Date : 2019-04-21 22:50 4 | # Auth : Hu Jian 5 | # Version : 1.0 6 | # Function : 仅用来解压core jar包,名字不要乱改 7 | 8 | BASEDIR="$( cd "$( dirname "$0" )" && pwd )" 9 | 10 | # 11 | # 解压core jar包至指定目录 12 | # 13 | function unpack() { 14 | JAR_PATH=${BASEDIR}/../bin/lib/debug-core.jar 15 | TARGET_DIR=${BASEDIR}/../bin/jar 16 | if [ ! -f ${JAR_PATH} ]; then 17 | echo "" # do not speak 18 | else 19 | if [ ! -d ${TARGET_DIR} ]; then 20 | mkdir ${TARGET_DIR} 21 | else 22 | rm -rf ${TARGET_DIR} 23 | fi 24 | unzip ${JAR_PATH} -d ${TARGET_DIR} 25 | echo ${TARGET_DIR} 26 | fi 27 | } 28 | 29 | # unpack 30 | unpack 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /script/logo: -------------------------------------------------------------------------------- 1 | 2 | ___ ___ 3 | ---------------------/\------\ \------------------/ /----/\--------------- 4 | \ | / \ \ \ / / / \ dynamic java debug tool 5 | | | / \ \ \ / / / \ V 2.0 6 | | | / /\ \ \ \ / / / /\ \ by H.J 7 | | | / / \ \ \ \ / / / / \ \ | 8 | | | / / \ \ \ \ / / / / \ \ | There is no bug in this project. 9 | | | / /------\ \ \ \ / / / /------\ \ | beg for this. 10 | | | / /--------\ \ \ \ / / / /--------\ \ | thanks. 11 | |\___| | / / \ \ \ \ / / / / \ \ | 12 | \_______|______/__/____________\__\______\__\/__/____/__/____________\__\______ 13 | |\______| /__/ \__\ \____/ /__/ \__\ | 14 | | (1) ./javadebug-agent-attach.sh + pid | 15 | | (2) ./javadebug-client-lanuch.sh | 16 | |______________________________________________________________________________| 17 | | | 18 | | | 19 | |>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>| 20 | | blog link : https://www.jianshu.com/u/86c421886c32 | 21 | | special post : https://mp.weixin.qq.com/s/ZlNcvwJ_swspifWTLHA92Q | 22 | | | 23 | \_____________________________________________________________________________/ 24 | -------------------------------------------------------------------------------- /spring/lib/bin/async-profiler/linux/build/jattach: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pandening/Java-debug-tool/e12244af5c6310186ae02dce4140bd408096ba87/spring/lib/bin/async-profiler/linux/build/jattach -------------------------------------------------------------------------------- /spring/lib/bin/async-profiler/linux/build/libasyncProfiler.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pandening/Java-debug-tool/e12244af5c6310186ae02dce4140bd408096ba87/spring/lib/bin/async-profiler/linux/build/libasyncProfiler.so -------------------------------------------------------------------------------- /spring/lib/bin/async-profiler/mac/build/jattach: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pandening/Java-debug-tool/e12244af5c6310186ae02dce4140bd408096ba87/spring/lib/bin/async-profiler/mac/build/jattach -------------------------------------------------------------------------------- /spring/lib/bin/async-profiler/mac/build/libasyncProfiler.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pandening/Java-debug-tool/e12244af5c6310186ae02dce4140bd408096ba87/spring/lib/bin/async-profiler/mac/build/libasyncProfiler.so -------------------------------------------------------------------------------- /spring/lib/bin/btrace/BlockingThreadCheck.java: -------------------------------------------------------------------------------- 1 | // 2 | // ======================================================================== 3 | // Copyright (c) 2018-2019 HuJian/Pandening soft collection. 4 | // ------------------------------------------------------------------------ 5 | // All rights reserved. This program and the accompanying materials 6 | // are made available under the terms of the #{license} Public License #{version} 7 | // EG: 8 | // The Eclipse Public License is available at 9 | // http://www.eclipse.org/legal/epl-v10.html 10 | // 11 | // The Apache License v2.0 is available at 12 | // http://www.opensource.org/licenses/apache2.0.php 13 | // 14 | // You may elect to redistribute this code under either of these licenses. 15 | // You should bear the consequences of using the software (named 'java-debug-tool') 16 | // and any modify must be create an new pull request and attach an text to describe 17 | // the change detail. 18 | // ======================================================================== 19 | // 20 | 21 | 22 | -------------------------------------------------------------------------------- /spring/lib/bin/hello.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | BASEDIR="$( cd "$( dirname "$0" )" && pwd )" 4 | 5 | # hello world 6 | echo "welcome to use java-debug-tool" 7 | 8 | cat ${BASEDIR}/logo 9 | -------------------------------------------------------------------------------- /spring/lib/bin/javadebug-client-launch.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Date : 2019-04-18 23:00 4 | # Auth : Hu Jian 5 | # Version : 1.0 6 | # Function : 用于调试目标JVM的客户端,请在本机启动该脚本连接远程JVM进行调试 7 | 8 | 9 | # the base dir 10 | # bin/..... 11 | EXECUTE_BASE_DIR="$( cd "$( dirname "$0" )" && pwd )" 12 | 13 | # define the default ip 14 | DEFAULT_TARGET_IP=127.0.0.1 15 | 16 | # define the default port 17 | DEFAULT_TARGET_PORT=11234 18 | 19 | function usage() { 20 | 21 | echo " 22 | java-debug-console usage: 23 | javadebug-console-launch.sh [ip:port] 24 | 25 | ip:port : the target jvm host info, optional 26 | 27 | example: 28 | ./javadebug-console-launch.sh 127.0.0.1:11234 29 | " 30 | 31 | 32 | } 33 | # parse the argument 34 | function parse_arguments() 35 | { 36 | 37 | TARGET_IP=$(echo ${1}|awk '/^[0-9]*@/;/^[^@]+:/{print "@"$1};/^[0-9]+$/'|awk -F "@|:" '{print $2}'); 38 | TARGET_PORT=$(echo ${1}|awk '/^[0-9]*@/;/^[^@]+:/{print "@"$1};/^[0-9]+$/'|awk -F ":" '{print $2}'); 39 | 40 | # # check pid 41 | # if [ -z ${TARGET_IP} ];then 42 | # echo "illegal arguments, the is required." 43 | # exit 1 44 | # fi 45 | # 46 | # # check pid 47 | # if [ -z ${TARGET_PORT} ];then 48 | # echo "illegal arguments, the is required." 49 | # exit 1 50 | # fi 51 | 52 | # set default ip 53 | [ -z ${TARGET_IP} ] && TARGET_IP=${DEFAULT_TARGET_IP} 54 | 55 | # set default port 56 | [ -z ${TARGET_PORT} ] && TARGET_PORT=${DEFAULT_TARGET_PORT} 57 | 58 | return 0 59 | 60 | } 61 | 62 | # using io.javadebug.core.TcpClient 63 | # 64 | # connect to remote jvm tcpServer to exec debug. 65 | function execConsole() { 66 | 67 | # show the usage 68 | usage 69 | 70 | echo "start to connect to remote jvm tcp server ${TARGET_IP}:${TARGET_PORT}" 71 | 72 | parse_arguments "${@}" 73 | 74 | JAVA_COMMAND="java" 75 | if [ ! -z ${JAVA_VERSION} ]; then 76 | JAVA_COMMAND="/usr/local/${JAVA_VERSION}/bin/java" 77 | fi 78 | 79 | # run tcpClient 80 | 81 | ${JAVA_COMMAND} \ 82 | -cp ${EXECUTE_BASE_DIR}/lib/debug-core.jar \ 83 | io.javadebug.core.JavaDebugClientLauncher \ 84 | -ip ${TARGET_IP} \ 85 | -port ${TARGET_PORT} 86 | 87 | } 88 | 89 | execConsole "${@}" -------------------------------------------------------------------------------- /spring/lib/bin/javadebug-cluster-launch.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Date : 2019-04-29 00:30 4 | # Auth : Hu Jian 5 | # Version : 1.0 6 | # Function : 用于调试多个目标JVM,前提是同一个命令向集群中的所有机器执行 7 | 8 | 9 | # the base dir 10 | # bin/..... 11 | EXECUTE_BASE_DIR="$( cd "$( dirname "$0" )" && pwd )" 12 | 13 | function usage() { 14 | 15 | echo " 16 | java-debug-cluster-console usage: 17 | javadebug-cluster-launch.sh [ip:port,ip:port,ip,port] 18 | 19 | ip:port : the target jvm host info, optional 20 | 21 | example: 22 | ./javadebug-cluster-launch.sh 127.0.0.1:11234,11235 23 | " 24 | 25 | 26 | } 27 | 28 | # using io.javadebug.core.TcpClient 29 | # 30 | # connect to remote jvm tcpServer to exec debug. 31 | function execConsole() { 32 | 33 | # show the usage 34 | usage 35 | 36 | JAVA_COMMAND="java" 37 | if [ ! -z ${JAVA_VERSION} ]; then 38 | JAVA_COMMAND="/usr/local/${JAVA_VERSION}/bin/java" 39 | fi 40 | 41 | # run tcpClient 42 | 43 | ${JAVA_COMMAND} \ 44 | -cp ${EXECUTE_BASE_DIR}/lib/debug-core.jar \ 45 | io.javadebug.core.JavaDebugClusterClientLauncher \ 46 | -p "${@}" \ 47 | 48 | } 49 | 50 | execConsole "${@}" -------------------------------------------------------------------------------- /spring/lib/bin/javadebug-http-server.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Date : 2019-11-24 19:31 4 | # Auth : Hu Jian 5 | # Version : 1.0 6 | # Function : 用于和目标JVM通信的http服务端,可以将命令通过http的方式进行调试 7 | 8 | # the base dir 9 | # bin/..... 10 | EXECUTE_BASE_DIR="$( cd "$( dirname "$0" )" && pwd )" 11 | 12 | REMOTE_IP="127.0.0.1" 13 | 14 | REMOTE_PORT=11234 15 | 16 | HTTP_SERVER_LISTEN_PORT=10234 17 | 18 | JAVA_COMMAND="java" 19 | 20 | 21 | # 22 | # for input some command like mt contains "#", you should 23 | # convert it to %23, the map table like this: 24 | # ======================= 25 | # character | trans 26 | # ======================= 27 | # space    %20 28 | # "        %22 29 | # #         %23 30 | # %         %25 31 | # &         %26 32 | # (         %28 33 | # )         %29 34 | # +         %2B 35 | # ,         %2C 36 | # /         %2F 37 | # :         %3A 38 | # ;         %3B 39 | # <         %3C 40 | # =         %3D 41 | # >         %3E 42 | # ?         %3F 43 | # @       %40 44 | # \         %5C 45 | # |         %7C  46 | # ======================= 47 | # 48 | 49 | # 50 | # to split the ct command's result, using grep,awk command to split the origin result 51 | # is so easy like this: 52 | # cat result.txt | grep -E ".*;.*;.*" | awk -F ';' '{print $1,$2,$3,$4}' 53 | # 54 | # 55 | 56 | # 57 | # $1 => remote ip 58 | # $2 => remote port 59 | # $3 => http server listen port 60 | # 61 | function http_server() { 62 | 63 | if [[ -n $1 ]]; then 64 | REMOTE_IP=$1 65 | fi 66 | 67 | if [[ -n $2 ]]; then 68 | REMOTE_PORT=$2 69 | fi 70 | 71 | if [[ -n $3 ]]; then 72 | HTTP_SERVER_LISTEN_PORT=$3 73 | fi 74 | 75 | echo "get the remote address : ${REMOTE_IP}:${REMOTE_PORT}, 76 | set up the http server on localhost:${HTTP_SERVER_LISTEN_PORT}, 77 | Open your web browser and navigate to 78 | http://127.0.0.1:${HTTP_SERVER_LISTEN_PORT}/java-debug-tool/shell/http/" 79 | 80 | ${JAVA_COMMAND} \ 81 | -cp ${EXECUTE_BASE_DIR}/lib/debug-core.jar \ 82 | io.javadebug.core.JavaDebugHttpServerLauncher \ 83 | ${REMOTE_IP} \ 84 | ${REMOTE_PORT} \ 85 | ${HTTP_SERVER_LISTEN_PORT} \ 86 | & 87 | 88 | } 89 | 90 | 91 | # set up the http server 92 | http_server "${@}" 93 | -------------------------------------------------------------------------------- /spring/lib/bin/javadebug-simple-client.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Date : 2019-04-18 23:00 4 | # Auth : Hu Jian 5 | # Version : 1.0 6 | # Function : 用于调试目标JVM的客户端,请在本机启动该脚本连接远程JVM进行调试 7 | 8 | 9 | # the base dir 10 | # bin/..... 11 | EXECUTE_BASE_DIR="$( cd "$( dirname "$0" )" && pwd )" 12 | 13 | # define the default ip 14 | DEFAULT_TARGET_IP=127.0.0.1 15 | 16 | # define the default port 17 | DEFAULT_TARGET_PORT=11234 18 | 19 | # java version 20 | JAVA_VERSION=java8 21 | 22 | function usage() { 23 | 24 | echo " 25 | java-debug-console usage: 26 | javadebug-console-launch.sh [ip:port] 27 | 28 | ip:port : the target jvm host info, optional 29 | 30 | example: 31 | ./javadebug-console-launch.sh 127.0.0.1:11234 32 | " 33 | 34 | 35 | } 36 | # parse the argument 37 | function parse_arguments() 38 | { 39 | 40 | TARGET_IP=$(echo ${1}|awk '/^[0-9]*@/;/^[^@]+:/{print "@"$1};/^[0-9]+$/'|awk -F "@|:" '{print $2}'); 41 | TARGET_PORT=$(echo ${1}|awk '/^[0-9]*@/;/^[^@]+:/{print "@"$1};/^[0-9]+$/'|awk -F ":" '{print $2}'); 42 | 43 | # # check pid 44 | # if [ -z ${TARGET_IP} ];then 45 | # echo "illegal arguments, the is required." 46 | # exit 1 47 | # fi 48 | # 49 | # # check pid 50 | # if [ -z ${TARGET_PORT} ];then 51 | # echo "illegal arguments, the is required." 52 | # exit 1 53 | # fi 54 | 55 | # set default ip 56 | [[ -z ${TARGET_IP} ]] && TARGET_IP=${DEFAULT_TARGET_IP} 57 | 58 | # set default port 59 | [[ -z ${TARGET_PORT} ]] && TARGET_PORT=${DEFAULT_TARGET_PORT} 60 | 61 | return 0 62 | 63 | } 64 | 65 | # using io.javadebug.core.TcpClient 66 | # 67 | # connect to remote jvm tcpServer to exec debug. 68 | function execConsole() { 69 | 70 | # show the usage 71 | usage 72 | 73 | echo "start to connect to remote jvm tcp server ${TARGET_IP}:${TARGET_PORT}" 74 | 75 | parse_arguments "${@}" 76 | 77 | JAVA_COMMAND="/usr/local/${JAVA_VERSION}/bin/java" 78 | 79 | # run tcpClient 80 | 81 | ${JAVA_COMMAND} \ 82 | -cp ${EXECUTE_BASE_DIR}/lib/debug-core.jar \ 83 | io.javadebug.core.JavaDebugClientLauncher \ 84 | -ip ${TARGET_IP} \ 85 | -port ${TARGET_PORT} 86 | 87 | } 88 | 89 | execConsole "${@}" -------------------------------------------------------------------------------- /spring/lib/bin/javadebug-unpack.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Date : 2019-04-21 22:50 4 | # Auth : Hu Jian 5 | # Version : 1.0 6 | # Function : 仅用来解压core jar包,名字不要乱改 7 | 8 | BASEDIR="$( cd "$( dirname "$0" )" && pwd )" 9 | 10 | # 11 | # 解压core jar包至指定目录 12 | # 13 | function unpack() { 14 | JAR_PATH=${BASEDIR}/../bin/lib/debug-core.jar 15 | TARGET_DIR=${BASEDIR}/../bin/jar 16 | if [ ! -f ${JAR_PATH} ]; then 17 | echo "" # do not speak 18 | else 19 | if [ ! -d ${TARGET_DIR} ]; then 20 | mkdir ${TARGET_DIR} 21 | else 22 | rm -rf ${TARGET_DIR} 23 | fi 24 | unzip ${JAR_PATH} -d ${TARGET_DIR} 25 | echo ${TARGET_DIR} 26 | fi 27 | } 28 | 29 | # unpack 30 | unpack 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /spring/lib/bin/logo: -------------------------------------------------------------------------------- 1 | 2 | ___ ___ 3 | ---------------------/\------\ \------------------/ /----/\ 4 | \ | / \ \ \ / / / \ dynamic java debug tool 5 | | | / \ \ \ / / / \ V 1.0 6 | | | / /\ \ \ \ / / / /\ \ by H.J 7 | | | / / \ \ \ \ / / / / \ \ 8 | | | / / \ \ \ \ / / / / \ \ 9 | | | / /------\ \ \ \ / / / /------\ \ 10 | | | / /--------\ \ \ \ / / / /--------\ \ 11 | |\___| | / / \ \ \ \ / / / / \ \ 12 | \_______|______/__/____________\__\______\__\/__/____/__/____________\__\______ 13 | |\______| /__/ \__\ \____/ /__/ \__\ | 14 | | (1) ./javadebug-agent-attach.sh + pid | 15 | | (2) ./javadebug-client-lanuch.sh | 16 | |______________________________________________________________________________| 17 | 18 | -------------------------------------------------------------------------------- /spring/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | io.javadebug 8 | spring 9 | 1.2.0-SNAPSHOT 10 | jar 11 | 12 | 13 | 14 | 15 | org.springframework 16 | spring-beans 17 | 5.3.18 18 | 19 | 20 | 21 | org.springframework 22 | spring-core 23 | 5.2.22.RELEASE 24 | 25 | 26 | 27 | 28 | 29 | 30 | lib 31 | 32 | **/*.sh 33 | **/*.jar 34 | 35 | false 36 | 37 | 38 | 39 | 40 | org.apache.maven.plugins 41 | maven-source-plugin 42 | 3.0.1 43 | 44 | 45 | attach-sources 46 | 47 | jar 48 | 49 | 50 | 51 | 52 | 53 | org.apache.maven.plugins 54 | maven-compiler-plugin 55 | 56 | 1.8 57 | 1.8 58 | 59 | 60 | 61 | 62 | 63 | 64 | -------------------------------------------------------------------------------- /test/src/main/java/A.java: -------------------------------------------------------------------------------- 1 | // 2 | // ======================================================================== 3 | // Copyright (c) 2018-2019 HuJian/Pandening soft collection. 4 | // ------------------------------------------------------------------------ 5 | // All rights reserved. This program and the accompanying materials 6 | // are made available under the terms of the #{license} Public License #{version} 7 | // EG: 8 | // The Eclipse Public License is available at 9 | // http://www.eclipse.org/legal/epl-v10.html 10 | // 11 | // The Apache License v2.0 is available at 12 | // http://www.opensource.org/licenses/apache2.0.php 13 | // 14 | // You may elect to redistribute this code under either of these licenses. 15 | // You should bear the consequences of using the software (named 'java-debug-tool') 16 | // and any modify must be create an new pull request and attach an text to describe 17 | // the change detail. 18 | // ======================================================================== 19 | // 20 | 21 | 22 | /** 23 | * Copyright © 2019-XXX HJ All Rights Reserved 24 | * 25 | * 26 | * 27 | * 28 | * 29 | * 30 | * 31 | * 32 | * 33 | */ 34 | // Author : HJ 35 | 36 | 37 | /** 38 | * Created on 2019/4/24 18:46. 39 | * 40 | * @author HuJian 41 | */ 42 | public class A { 43 | 44 | public int code() { 45 | return 321; 46 | } 47 | 48 | public static String ccc() { 49 | return "hello world~"; 50 | } 51 | 52 | public static String bbb() { 53 | return "BBB"; 54 | } 55 | 56 | public static String ddd() { 57 | return "BBB"; 58 | } 59 | 60 | public static String eee() { 61 | return "BBB"; 62 | } 63 | 64 | public static void main(String[] args) { 65 | 66 | } 67 | 68 | } 69 | -------------------------------------------------------------------------------- /test/src/main/java/AplusBClass.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pandening/Java-debug-tool/e12244af5c6310186ae02dce4140bd408096ba87/test/src/main/java/AplusBClass.class -------------------------------------------------------------------------------- /test/src/main/java/B.java: -------------------------------------------------------------------------------- 1 | // 2 | // ======================================================================== 3 | // Copyright (c) 2018-2019 HuJian/Pandening soft collection. 4 | // ------------------------------------------------------------------------ 5 | // All rights reserved. This program and the accompanying materials 6 | // are made available under the terms of the #{license} Public License #{version} 7 | // EG: 8 | // The Eclipse Public License is available at 9 | // http://www.eclipse.org/legal/epl-v10.html 10 | // 11 | // The Apache License v2.0 is available at 12 | // http://www.opensource.org/licenses/apache2.0.php 13 | // 14 | // You may elect to redistribute this code under either of these licenses. 15 | // You should bear the consequences of using the software (named 'java-debug-tool') 16 | // and any modify must be create an new pull request and attach an text to describe 17 | // the change detail. 18 | // ======================================================================== 19 | // 20 | 21 | 22 | import org.objectweb.asm.Type; 23 | 24 | public class B { 25 | private int a; 26 | private String b; 27 | private static String c = "abc"; 28 | 29 | public void readField() { 30 | receiveField(a); 31 | receiveField(b); 32 | receiveField(c); 33 | } 34 | 35 | public void call(Object p) { 36 | System.out.println(p); 37 | } 38 | 39 | public void receiveField(Object o) { 40 | System.out.println(o); 41 | } 42 | 43 | public static void main(String[] args) throws NoSuchFieldException { 44 | new B().call(1234); 45 | 46 | String desc = Type.getDescriptor(B.class.getDeclaredField("c").getType()); 47 | 48 | 49 | System.out.println(desc); 50 | 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /test/src/main/java/BlockMain.java: -------------------------------------------------------------------------------- 1 | import java.util.concurrent.TimeUnit; 2 | 3 | public class BlockMain { 4 | 5 | public static void main(String[] args) { 6 | 7 | new Thread(new Runnable() { 8 | @Override 9 | public void run() { 10 | for(;;) { 11 | try { 12 | TimeUnit.SECONDS.sleep(1); 13 | } catch (InterruptedException e) { 14 | break; 15 | } 16 | System.out.println("1 sec"); 17 | } 18 | } 19 | }, "test").start(); 20 | 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /test/src/main/java/CCT.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pandening/Java-debug-tool/e12244af5c6310186ae02dce4140bd408096ba87/test/src/main/java/CCT.class -------------------------------------------------------------------------------- /test/src/main/java/ClassReaderTest.java: -------------------------------------------------------------------------------- 1 | import jdk.internal.org.objectweb.asm.ClassReader; 2 | 3 | public class ClassReaderTest { 4 | 5 | public static void main(String[] args) throws Exception { 6 | 7 | ClassReader classReader = new ClassReader(C.class.getProtectionDomain().getCodeSource().getLocation().openStream()); 8 | System.out.println(classReader.getClassName()); 9 | } 10 | 11 | } 12 | -------------------------------------------------------------------------------- /test/src/main/java/CpuBusyMock.java: -------------------------------------------------------------------------------- 1 | // 2 | // ======================================================================== 3 | // Copyright (c) 2018-2019 HuJian/Pandening soft collection. 4 | // ------------------------------------------------------------------------ 5 | // All rights reserved. This program and the accompanying materials 6 | // are made available under the terms of the #{license} Public License #{version} 7 | // EG: 8 | // The Eclipse Public License is available at 9 | // http://www.eclipse.org/legal/epl-v10.html 10 | // 11 | // The Apache License v2.0 is available at 12 | // http://www.opensource.org/licenses/apache2.0.php 13 | // 14 | // You may elect to redistribute this code under either of these licenses. 15 | // You should bear the consequences of using the software (named 'java-debug-tool') 16 | // and any modify must be create an new pull request and attach an text to describe 17 | // the change detail. 18 | // ======================================================================== 19 | // 20 | 21 | 22 | import java.util.Arrays; 23 | import java.util.concurrent.TimeUnit; 24 | 25 | public class CpuBusyMock { 26 | 27 | public static void main(String[] args) { 28 | new Thread(new Runnable() { 29 | @Override 30 | public void run() { 31 | while (true) { 32 | int len = 1024; 33 | byte[] bytes = new byte[len]; 34 | for (int i = 0; i < len; i ++) { 35 | bytes[i] = (byte) i; 36 | } 37 | System.out.println(Arrays.toString(bytes)); 38 | try { 39 | TimeUnit.MILLISECONDS.sleep(1); 40 | } catch (InterruptedException e) { 41 | e.printStackTrace(); 42 | } 43 | } 44 | } 45 | }).start(); 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /test/src/main/java/Demo.java: -------------------------------------------------------------------------------- 1 | // 2 | // ======================================================================== 3 | // Copyright (c) 2018-2019 HuJian/Pandening soft collection. 4 | // ------------------------------------------------------------------------ 5 | // All rights reserved. This program and the accompanying materials 6 | // are made available under the terms of the #{license} Public License #{version} 7 | // EG: 8 | // The Eclipse Public License is available at 9 | // http://www.eclipse.org/legal/epl-v10.html 10 | // 11 | // The Apache License v2.0 is available at 12 | // http://www.opensource.org/licenses/apache2.0.php 13 | // 14 | // You may elect to redistribute this code under either of these licenses. 15 | // You should bear the consequences of using the software (named 'java-debug-tool') 16 | // and any modify must be create an new pull request and attach an text to describe 17 | // the change detail. 18 | // ======================================================================== 19 | // 20 | 21 | 22 | import java.util.Random; 23 | import java.util.concurrent.TimeUnit; 24 | 25 | public class Demo { 26 | 27 | private void say(String word, boolean tag, int rdm) { 28 | if (word == null) { 29 | word = "test say"; 30 | } 31 | int length = word.length(); 32 | if (tag) { 33 | length += 1; 34 | } else { 35 | length -= 1; 36 | } 37 | word += "@" + length; 38 | System.out.println(word); 39 | if (rdm > 5) { 40 | throw new IllegalStateException("test exception"); 41 | } 42 | } 43 | 44 | private static final String[] list = {"a", "ab", "abc", "abcd"}; 45 | 46 | public static void main(String[] args) { 47 | Demo demo = new Demo(); 48 | Random random = new Random(47); 49 | new Thread(new Runnable() { 50 | @Override 51 | public void run() { 52 | for(;;) { 53 | try { 54 | demo.say(list[random.nextInt(4)], random.nextBoolean(), random.nextInt(10)); 55 | TimeUnit.MILLISECONDS.sleep(100); 56 | } catch (Exception e) { 57 | e.printStackTrace(); 58 | } 59 | } 60 | } 61 | }, "demo-thread").start(); 62 | } 63 | 64 | 65 | } 66 | -------------------------------------------------------------------------------- /test/src/main/java/IFace.java: -------------------------------------------------------------------------------- 1 | // 2 | // ======================================================================== 3 | // Copyright (c) 2018-2019 HuJian/Pandening soft collection. 4 | // ------------------------------------------------------------------------ 5 | // All rights reserved. This program and the accompanying materials 6 | // are made available under the terms of the #{license} Public License #{version} 7 | // EG: 8 | // The Eclipse Public License is available at 9 | // http://www.eclipse.org/legal/epl-v10.html 10 | // 11 | // The Apache License v2.0 is available at 12 | // http://www.opensource.org/licenses/apache2.0.php 13 | // 14 | // You may elect to redistribute this code under either of these licenses. 15 | // You should bear the consequences of using the software (named 'java-debug-tool') 16 | // and any modify must be create an new pull request and attach an text to describe 17 | // the change detail. 18 | // ======================================================================== 19 | // 20 | 21 | 22 | /** 23 | * Copyright © 2019-XXX HJ All Rights Reserved 24 | * 25 | * 26 | * 27 | * 28 | * 29 | * 30 | * 31 | * 32 | * 33 | */ 34 | // Author : HJ 35 | 36 | 37 | public interface IFace { 38 | 39 | int call(int p); 40 | 41 | } 42 | -------------------------------------------------------------------------------- /test/src/main/java/LambdaTest$$Lambda$1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pandening/Java-debug-tool/e12244af5c6310186ae02dce4140bd408096ba87/test/src/main/java/LambdaTest$$Lambda$1.class -------------------------------------------------------------------------------- /test/src/main/java/LambdaTest.java: -------------------------------------------------------------------------------- 1 | // 2 | // ======================================================================== 3 | // Copyright (c) 2018-2019 HuJian/Pandening soft collection. 4 | // ------------------------------------------------------------------------ 5 | // All rights reserved. This program and the accompanying materials 6 | // are made available under the terms of the #{license} Public License #{version} 7 | // EG: 8 | // The Eclipse Public License is available at 9 | // http://www.eclipse.org/legal/epl-v10.html 10 | // 11 | // The Apache License v2.0 is available at 12 | // http://www.opensource.org/licenses/apache2.0.php 13 | // 14 | // You may elect to redistribute this code under either of these licenses. 15 | // You should bear the consequences of using the software (named 'java-debug-tool') 16 | // and any modify must be create an new pull request and attach an text to describe 17 | // the change detail. 18 | // ======================================================================== 19 | // 20 | 21 | 22 | /** 23 | * Copyright © 2019-XXX HJ All Rights Reserved 24 | * 25 | * 26 | * 27 | * 28 | * 29 | * 30 | * 31 | * 32 | * 33 | */ 34 | // Author : HJ 35 | 36 | 37 | public class LambdaTest { 38 | 39 | public static void main(String[] args) { 40 | 41 | System.out.println("ladmba test\n"); 42 | 43 | testLambda(); 44 | 45 | } 46 | 47 | private static void testLambda() { 48 | // dump the inner class 49 | System.setProperty("jdk.internal.lambda.dumpProxyClasses", "/Users/hujian06/github/java-debug-tool/test/src/main/java"); 50 | 51 | // lambda 52 | new Thread(() -> System.out.println("hello")).start(); 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /test/src/main/java/RdfDemo.java: -------------------------------------------------------------------------------- 1 | // 2 | // ======================================================================== 3 | // Copyright (c) 2018-2019 HuJian/Pandening soft collection. 4 | // ------------------------------------------------------------------------ 5 | // All rights reserved. This program and the accompanying materials 6 | // are made available under the terms of the #{license} Public License #{version} 7 | // EG: 8 | // The Eclipse Public License is available at 9 | // http://www.eclipse.org/legal/epl-v10.html 10 | // 11 | // The Apache License v2.0 is available at 12 | // http://www.opensource.org/licenses/apache2.0.php 13 | // 14 | // You may elect to redistribute this code under either of these licenses. 15 | // You should bear the consequences of using the software (named 'java-debug-tool') 16 | // and any modify must be create an new pull request and attach an text to describe 17 | // the change detail. 18 | // ======================================================================== 19 | // 20 | 21 | 22 | import java.util.Random; 23 | import java.util.concurrent.TimeUnit; 24 | 25 | /** 26 | * 27 | * rdf -p RdfDemo:/Users/hujian06/github/java-debug-tool/test/target/classes/RdfDemo.class 28 | * back -c RdfDemo 29 | * 30 | */ 31 | public class RdfDemo { 32 | 33 | public int call(int in) { 34 | //throw new UnsupportedOperationException("unSupport method call"); 35 | return in; 36 | } 37 | 38 | public static void main(String[] args) { 39 | 40 | Random random = new Random(47); 41 | RdfDemo rdfDemo = new RdfDemo(); 42 | new Thread(new Runnable() { 43 | @Override 44 | public void run() { 45 | while (true) { 46 | try { 47 | TimeUnit.SECONDS.sleep(2); 48 | int ret =rdfDemo.call(random.nextInt(10)); 49 | System.out.println(ret); 50 | } catch (Exception e) { 51 | System.out.println(e.getMessage()); 52 | } 53 | } 54 | } 55 | }).start(); 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /test/src/main/java/Runner.java: -------------------------------------------------------------------------------- 1 | // 2 | // ======================================================================== 3 | // Copyright (c) 2018-2019 HuJian/Pandening soft collection. 4 | // ------------------------------------------------------------------------ 5 | // All rights reserved. This program and the accompanying materials 6 | // are made available under the terms of the #{license} Public License #{version} 7 | // EG: 8 | // The Eclipse Public License is available at 9 | // http://www.eclipse.org/legal/epl-v10.html 10 | // 11 | // The Apache License v2.0 is available at 12 | // http://www.opensource.org/licenses/apache2.0.php 13 | // 14 | // You may elect to redistribute this code under either of these licenses. 15 | // You should bear the consequences of using the software (named 'java-debug-tool') 16 | // and any modify must be create an new pull request and attach an text to describe 17 | // the change detail. 18 | // ======================================================================== 19 | // 20 | 21 | 22 | /** 23 | * Copyright © 2019-XXX HJ All Rights Reserved 24 | * 25 | * 26 | * 27 | * 28 | * 29 | * 30 | * 31 | * 32 | * 33 | */ 34 | // Auth : HJ 35 | 36 | 37 | import java.util.concurrent.TimeUnit; 38 | 39 | /** 40 | * Created on 2019/4/13 21:10. 41 | * 42 | * @author HuJian 43 | */ 44 | public class Runner { 45 | 46 | static A a = new A(); 47 | 48 | public static void main(String[] args) { 49 | new Thread(new Runnable() { 50 | @Override 51 | public void run() { 52 | while (true) { 53 | try { 54 | TimeUnit.SECONDS.sleep(1); 55 | System.out.println("::: hello world:" + a.code() + "=>" + A.ccc()); 56 | } catch (InterruptedException e) { 57 | e.printStackTrace(); 58 | } 59 | } 60 | } 61 | }).start(); 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /test/src/main/java/TestCaseBase.java: -------------------------------------------------------------------------------- 1 | // 2 | // ======================================================================== 3 | // Copyright (c) 2018-2019 HuJian/Pandening soft collection. 4 | // ------------------------------------------------------------------------ 5 | // All rights reserved. This program and the accompanying materials 6 | // are made available under the terms of the #{license} Public License #{version} 7 | // EG: 8 | // The Eclipse Public License is available at 9 | // http://www.eclipse.org/legal/epl-v10.html 10 | // 11 | // The Apache License v2.0 is available at 12 | // http://www.opensource.org/licenses/apache2.0.php 13 | // 14 | // You may elect to redistribute this code under either of these licenses. 15 | // You should bear the consequences of using the software (named 'java-debug-tool') 16 | // and any modify must be create an new pull request and attach an text to describe 17 | // the change detail. 18 | // ======================================================================== 19 | // 20 | 21 | 22 | public interface TestCaseBase { 23 | 24 | void call(T in); 25 | 26 | } 27 | -------------------------------------------------------------------------------- /test/src/main/java/Test_Fields_Extract.java: -------------------------------------------------------------------------------- 1 | // 2 | // ======================================================================== 3 | // Copyright (c) 2018-2019 HuJian/Pandening soft collection. 4 | // ------------------------------------------------------------------------ 5 | // All rights reserved. This program and the accompanying materials 6 | // are made available under the terms of the #{license} Public License #{version} 7 | // EG: 8 | // The Eclipse Public License is available at 9 | // http://www.eclipse.org/legal/epl-v10.html 10 | // 11 | // The Apache License v2.0 is available at 12 | // http://www.opensource.org/licenses/apache2.0.php 13 | // 14 | // You may elect to redistribute this code under either of these licenses. 15 | // You should bear the consequences of using the software (named 'java-debug-tool') 16 | // and any modify must be create an new pull request and attach an text to describe 17 | // the change detail. 18 | // ======================================================================== 19 | // 20 | 21 | 22 | /** 23 | * 24 | * This class use to test the 'mt' command with -s option 25 | * -s => "fd" 26 | * "sf" 27 | * "field" 28 | * 29 | * ensure the target jvm is ok after enhance the bytecode 30 | * 31 | * 1. field extract is ok. 32 | * 2. the affect is ok. 33 | * 34 | * mt -c Test_Fields_Extract -m #{method} -t #{type} -s #{sOption} #{other options} 35 | * 36 | */ 37 | public class Test_Fields_Extract { 38 | 39 | public static void main(String[] args) { 40 | 41 | 42 | 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /test/src/main/java/Test_Method_Trace.java: -------------------------------------------------------------------------------- 1 | // 2 | // ======================================================================== 3 | // Copyright (c) 2018-2019 HuJian/Pandening soft collection. 4 | // ------------------------------------------------------------------------ 5 | // All rights reserved. This program and the accompanying materials 6 | // are made available under the terms of the #{license} Public License #{version} 7 | // EG: 8 | // The Eclipse Public License is available at 9 | // http://www.eclipse.org/legal/epl-v10.html 10 | // 11 | // The Apache License v2.0 is available at 12 | // http://www.opensource.org/licenses/apache2.0.php 13 | // 14 | // You may elect to redistribute this code under either of these licenses. 15 | // You should bear the consequences of using the software (named 'java-debug-tool') 16 | // and any modify must be create an new pull request and attach an text to describe 17 | // the change detail. 18 | // ======================================================================== 19 | // 20 | 21 | 22 | /** 23 | * 24 | * This Class use to test the 'mt' command. 25 | * 26 | * run this class, then attach java-debug-tool agent to the jvm and 27 | * execute the 'mt' command to test the function of java-debug-tool 28 | * 29 | * 1. the method trace base output must be ok. 30 | * 2. the java-debug-tool's enhance code must be safe for target jvm. 31 | * 3. the affect of java-debug-tool must be small to target jvm. 32 | * 4. test option -t 33 | * 'watch' 34 | * 'custom' 35 | * 'throw' 36 | * 'return' 37 | * 'record' 38 | * 39 | * mt -c Test_Method_Trace -m #{method} -t #{type} #{options} 40 | */ 41 | public class Test_Method_Trace { 42 | 43 | 44 | public static void main(String[] args) { 45 | 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /test/src/main/java/TryCatchFinallyTest$IntWrap.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pandening/Java-debug-tool/e12244af5c6310186ae02dce4140bd408096ba87/test/src/main/java/TryCatchFinallyTest$IntWrap.class -------------------------------------------------------------------------------- /test/src/main/java/TryCatchFinallyTest.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pandening/Java-debug-tool/e12244af5c6310186ae02dce4140bd408096ba87/test/src/main/java/TryCatchFinallyTest.class -------------------------------------------------------------------------------- /test/src/main/java/TryCatchFinallyTest.java: -------------------------------------------------------------------------------- 1 | // 2 | // ======================================================================== 3 | // Copyright (c) 2018-2019 HuJian/Pandening soft collection. 4 | // ------------------------------------------------------------------------ 5 | // All rights reserved. This program and the accompanying materials 6 | // are made available under the terms of the #{license} Public License #{version} 7 | // EG: 8 | // The Eclipse Public License is available at 9 | // http://www.eclipse.org/legal/epl-v10.html 10 | // 11 | // The Apache License v2.0 is available at 12 | // http://www.opensource.org/licenses/apache2.0.php 13 | // 14 | // You may elect to redistribute this code under either of these licenses. 15 | // You should bear the consequences of using the software (named 'java-debug-tool') 16 | // and any modify must be create an new pull request and attach an text to describe 17 | // the change detail. 18 | // ======================================================================== 19 | // 20 | 21 | 22 | import java.util.Date; 23 | 24 | public class TryCatchFinallyTest { 25 | 26 | static class IntWrap { 27 | int intVal; 28 | 29 | @Override 30 | public String toString() { 31 | return "[" + intVal + "]"; 32 | } 33 | } 34 | 35 | static IntWrap intVal() { 36 | IntWrap intWrap = new IntWrap(); 37 | try { 38 | intWrap.intVal = 10; 39 | String a = null; 40 | a.length(); 41 | return intWrap; 42 | } catch (NullPointerException e) { 43 | intWrap.intVal = 20; 44 | System.out.println("npe"); 45 | return intWrap; 46 | } finally { 47 | intWrap.intVal = 30; 48 | throw new IllegalStateException("do not reach here"); 49 | } 50 | } 51 | 52 | 53 | public static void main(String[] args) { 54 | 55 | System.out.println(intVal()); 56 | 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /test/src/main/java/UnCheckedExceptionTest.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pandening/Java-debug-tool/e12244af5c6310186ae02dce4140bd408096ba87/test/src/main/java/UnCheckedExceptionTest.class -------------------------------------------------------------------------------- /test/src/main/java/UnCheckedExceptionTest.java: -------------------------------------------------------------------------------- 1 | // 2 | // ======================================================================== 3 | // Copyright (c) 2018-2019 HuJian/Pandening soft collection. 4 | // ------------------------------------------------------------------------ 5 | // All rights reserved. This program and the accompanying materials 6 | // are made available under the terms of the #{license} Public License #{version} 7 | // EG: 8 | // The Eclipse Public License is available at 9 | // http://www.eclipse.org/legal/epl-v10.html 10 | // 11 | // The Apache License v2.0 is available at 12 | // http://www.opensource.org/licenses/apache2.0.php 13 | // 14 | // You may elect to redistribute this code under either of these licenses. 15 | // You should bear the consequences of using the software (named 'java-debug-tool') 16 | // and any modify must be create an new pull request and attach an text to describe 17 | // the change detail. 18 | // ======================================================================== 19 | // 20 | 21 | 22 | public class UnCheckedExceptionTest { 23 | 24 | 25 | static int add(int a, int b) { 26 | String nullStr = null; 27 | int len = nullStr.length(); 28 | return a + b + len; 29 | } 30 | 31 | static int addPlus(int a, int b) { 32 | if (a + b < 0) { 33 | throw new IllegalStateException("a+ b >= 0"); 34 | } 35 | return a + b; 36 | } 37 | 38 | public static void main(String[] args) { 39 | 40 | 41 | } 42 | 43 | 44 | } 45 | -------------------------------------------------------------------------------- /test/src/main/java/inner/InnerCalss$1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pandening/Java-debug-tool/e12244af5c6310186ae02dce4140bd408096ba87/test/src/main/java/inner/InnerCalss$1.class -------------------------------------------------------------------------------- /test/src/main/java/inner/InnerCalss$InnerA.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pandening/Java-debug-tool/e12244af5c6310186ae02dce4140bd408096ba87/test/src/main/java/inner/InnerCalss$InnerA.class -------------------------------------------------------------------------------- /test/src/main/java/inner/InnerCalss$InnerB.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pandening/Java-debug-tool/e12244af5c6310186ae02dce4140bd408096ba87/test/src/main/java/inner/InnerCalss$InnerB.class -------------------------------------------------------------------------------- /test/src/main/java/inner/InnerCalss.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pandening/Java-debug-tool/e12244af5c6310186ae02dce4140bd408096ba87/test/src/main/java/inner/InnerCalss.class -------------------------------------------------------------------------------- /test/src/main/java/io/javadebug/test/TestClass.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pandening/Java-debug-tool/e12244af5c6310186ae02dce4140bd408096ba87/test/src/main/java/io/javadebug/test/TestClass.class -------------------------------------------------------------------------------- /test/src/main/java/io/javadebug/test/TestClass.java: -------------------------------------------------------------------------------- 1 | // 2 | // ======================================================================== 3 | // Copyright (c) 2018-2019 HuJian/Pandening soft collection. 4 | // ------------------------------------------------------------------------ 5 | // All rights reserved. This program and the accompanying materials 6 | // are made available under the terms of the #{license} Public License #{version} 7 | // EG: 8 | // The Eclipse Public License is available at 9 | // http://www.eclipse.org/legal/epl-v10.html 10 | // 11 | // The Apache License v2.0 is available at 12 | // http://www.opensource.org/licenses/apache2.0.php 13 | // 14 | // You may elect to redistribute this code under either of these licenses. 15 | // You should bear the consequences of using the software (named 'java-debug-tool') 16 | // and any modify must be create an new pull request and attach an text to describe 17 | // the change detail. 18 | // ======================================================================== 19 | // 20 | 21 | 22 | /** 23 | * Copyright © 2019-XXX HJ All Rights Reserved 24 | * 25 | * 26 | * 27 | * 28 | * 29 | * 30 | * 31 | * 32 | * 33 | */ 34 | // Author : HJ 35 | 36 | 37 | package io.javadebug.test; 38 | 39 | import io.javadebug.test.a.Aa; 40 | 41 | public class TestClass { 42 | 43 | Aa aa = new Aa(); 44 | 45 | public int test(int in) { 46 | 47 | if (in == 5) { 48 | return 100; 49 | } 50 | String tag = "the in:" + in; 51 | if (in < 5) { 52 | in += 2; 53 | } else { 54 | in -= 1; 55 | } 56 | 57 | if (in > 5) { 58 | throw new IllegalArgumentException("must <= 5"); 59 | } 60 | if (in <= 3) { 61 | throw new NullPointerException("must >= 3"); 62 | } 63 | 64 | return in * 100; 65 | } 66 | 67 | } 68 | -------------------------------------------------------------------------------- /test/src/main/java/io/javadebug/test/a/Aa.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pandening/Java-debug-tool/e12244af5c6310186ae02dce4140bd408096ba87/test/src/main/java/io/javadebug/test/a/Aa.class -------------------------------------------------------------------------------- /test/src/main/java/io/javadebug/test/a/Aa.java: -------------------------------------------------------------------------------- 1 | // 2 | // ======================================================================== 3 | // Copyright (c) 2018-2019 HuJian/Pandening soft collection. 4 | // ------------------------------------------------------------------------ 5 | // All rights reserved. This program and the accompanying materials 6 | // are made available under the terms of the #{license} Public License #{version} 7 | // EG: 8 | // The Eclipse Public License is available at 9 | // http://www.eclipse.org/legal/epl-v10.html 10 | // 11 | // The Apache License v2.0 is available at 12 | // http://www.opensource.org/licenses/apache2.0.php 13 | // 14 | // You may elect to redistribute this code under either of these licenses. 15 | // You should bear the consequences of using the software (named 'java-debug-tool') 16 | // and any modify must be create an new pull request and attach an text to describe 17 | // the change detail. 18 | // ======================================================================== 19 | // 20 | 21 | 22 | /** 23 | * Copyright © 2019-XXX HJ All Rights Reserved 24 | * 25 | * 26 | * 27 | * 28 | * 29 | * 30 | * 31 | * 32 | * 33 | */ 34 | // Author : HJ 35 | 36 | 37 | package io.javadebug.test.a; 38 | 39 | public class Aa { 40 | 41 | int a; 42 | 43 | } 44 | -------------------------------------------------------------------------------- /test/src/main/java/io/javadebug/test/a/Ab.java: -------------------------------------------------------------------------------- 1 | // 2 | // ======================================================================== 3 | // Copyright (c) 2018-2019 HuJian/Pandening soft collection. 4 | // ------------------------------------------------------------------------ 5 | // All rights reserved. This program and the accompanying materials 6 | // are made available under the terms of the #{license} Public License #{version} 7 | // EG: 8 | // The Eclipse Public License is available at 9 | // http://www.eclipse.org/legal/epl-v10.html 10 | // 11 | // The Apache License v2.0 is available at 12 | // http://www.opensource.org/licenses/apache2.0.php 13 | // 14 | // You may elect to redistribute this code under either of these licenses. 15 | // You should bear the consequences of using the software (named 'java-debug-tool') 16 | // and any modify must be create an new pull request and attach an text to describe 17 | // the change detail. 18 | // ======================================================================== 19 | // 20 | 21 | 22 | /** 23 | * Copyright © 2019-XXX HJ All Rights Reserved 24 | * 25 | * 26 | * 27 | * 28 | * 29 | * 30 | * 31 | * 32 | * 33 | */ 34 | // Author : HJ 35 | 36 | 37 | package io.javadebug.test.a; 38 | 39 | public class Ab { 40 | 41 | public void test() { 42 | Aa aa = new Aa(); 43 | aa.a = 0; 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /test/src/main/resources/log4j2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | --------------------------------------------------------------------------------