《Java程序设计》第一周学习记录(2)
使用JDB调试程序
JDB是JDK自带的基于命令行的调试程序。我们先来man一下吧(说到这里,我之前在翻娄老师的博客的时候看到一篇文章:做中学之提升英语口语很真实,虽然我六级不好不坏589,但是口语只有C+。平时看文档虽然认真看能看懂,但是还是喜欢偷懒去网上翻译。看来要走的路还很多,可能选走更困难一点的路是更正确的选择吧,这个话题以后再说)
jdb(1) Basic Tools jdb(1)
NAME
jdb - Finds and fixes bugs in Java platform programs.
SYNOPSIS
jdb [options] [classname] [arguments]
BASIC JDB COMMANDS
The following is a list of the basic jdb commands. The JDB supports other commands that you can list with the -help option.
help or ?
The help or ? commands display the list of recognized commands with a brief description.
不会就help咯
run After you start JDB and set breakpoints, you can use the run command to execute the debugged application. The run command is available only when the jdb command starts the debugged application as opposed to attaching to an existing JVM.
在你启动JDB并且设置断电以后,你可以使用run命令去执行被调试程序。run命令只有在jdb命令启动被调试程序以后才 可以使用,而不是附加到现存的JVM上
cont Continues execution of the debugged application after a breakpoint, exception, or step.
在断点、exception、step后继续执行被调试程序
print Displays Java objects and primitive values. For variables or fields of primitive types, the actual value is printed. For objects, a short description is printed. See the dump command to find out how to get more information about an object.
显示Java对象和原始值。打印原始类型的变量或者字段。打印对象的简短描述。查看dump命令以了解如何获取更多的对象信息
dump For primitive values, the dump command is identical to the print command. For objects, the dump command prints the current value of each field defined in the object. Static and instance fields are included. The dump command supports the same set of expressions as the print command.
对于基本类型,dump命令和print命令一样。对于对象,dump命令打印对象里定义的每一个字段的当前值。静态和实例字段包括在内。dump命令支持和print命令一样的表达式
threads
List the threads that are currently running. For each thread, its name and current status are printed and an index that can be used in other commands.
列出现在正在运行的线程。打印每个线程的名字、当前状态和能在其他命令里使用的索引
In this example, the thread index is 4, the thread is an instance of java.lang.Thread, the thread name is main, and it is currently running.
4. (java.lang.Thread)0x1 main running
thread Select a thread to be the current thread. Many jdb commands are based on the setting of the current thread. The thread is specified with the thread index described in the threads command.
选择一个线程作为当前线程。许多jdb命令基于当前线程的设定。线程由在threads命令里给的索引来指定
where The where command with no arguments dumps the stack of the current thread. The whereall command dumps the stack of all threads in the current thread group. The wherethreadindex command dumps the stack of the specified thread.
没有参数的where命令转储当前线程的堆栈。
If the current thread is suspended either through an event such as a breakpoint or through the suspend command, then local variables and fields can be displayed with the print and dump commands. The up and down commands select which stack frame is the current stack frame.
如果当前线程被中止,例如断点或者suspend命令,那么本地变量和字段可以被print和dump命令显示。up和down命令选择哪个堆栈帧是当前堆栈帧
BREAKPOINTS
Breakpoints can be set in JDB at line numbers or at the first instruction of a method, for example:
断点可以在JDB中按行号或者方法里的第一个指令设置
· The command stop at MyClass:22 sets a breakpoint at the first instruction for line 22 of the source
file containing MyClass.
· The command stop in java.lang.String.length sets a breakpoint at the beginning of the method
java.lang.String.length.
· The command stop in MyClass.<clinit> uses <clinit> to identify the static initialization code for
MyClass.
接下来就来试试吧。先打开三个标签页方便调试
按理来说现在是可以用Alt+数字来切换标签页,这样会很方便,但是不知道为什么,我的ubuntu在按Alt+1的时候切换不了,而是会出现(arg:1),希望有大神能告诉我怎么办。然后我们用jdb开始调试,用stop in
来设置断点,run
运行到断点初停下,用locals
来查看变量,step
单步执行。要注意step
和next
都是下一步,但是step
会进入方法体,next
不会
使用list
可以查看代码运行到哪里
stop at
在行号处设置断点,clear
打印设置的断点
更新:我知道为什么alt+数字没法切换标签页了,因为我根本就不是打开了三个标签页,而是打开了三个窗口。Ctrl+Alt+T是新建终端窗口,Ctrl+Shift+T是新建标签页!
系统文件被覆盖的挽救
在运行statistics.sh代码的时候,我一开始有点蒙,不知道要把这个脚本放到哪个文件夹下面去,然后做出了一个巨蠢无比的事
我不知道当时是怎么想的,想把脚本放到/bin目录下,结果不行,我居然还用管理员权限强行执行了命令,结果就是,不仅脚本运行不了,好像系统也出了点问题
虽然感觉没有什么大影响,但是指不定哪天就出问题了呢。。。。不行,我得修好啊。所以问题出在哪了呢?我首先要搞懂我刚刚干了什么
/bin/sh是一个链接文件,看看里面是什么
诶,这不是statistics.sh里的内容吗,也就是说,我强行把系统文件的内容覆盖了?!那要修复的话,只要把文件改回来就行了,好想要一个撤销键啊。。。我一开始想去网上百度一下有没有这个文件的内容直接复制进去算了,但是好像没有。那就只能从别的同学那里拷了。。。。等等!我突然想起来我
之前为了保险起见,用过VMware的快照功能,那我可以先拍下现在的快照,然后回到之前的快照,把完好的sh文件拷到共享文件夹,再回到现在的快照把sh文件改回来
回到过去,看看sh到底是什么玩意
。。。。。。。不管了,就是他了,拷到共享文件夹,再回到现在,改回来,看看行不行
搞定!
以后还是要小心一点,不要玩坏了虚拟机,而且要养成及时备份的习惯。
初学者的一点学习经过,如有错误或可以改进的地方,请不吝赐教!
参考资料
《Java程序设计》第一周学习记录(2)的更多相关文章
- 201521044152<java程序设计>第一周学习总结
本周学习总结 java开发时间虽然很短,但是发展迅速,已成为现在非常流行的一门语言,很开心能有幸学习java.第一周学习了java的平台,运行环境jdk以及jrt等等新名词,还了解了eclipse的基 ...
- 201621123007 Java程序设计第一周 学习总结
第一周-Java基本概念 201621123007 <Java程序设计> 第一周学习总结 1. 本周学习总结 java是面向对象的一类语言,三大特征:封装性,继承性,多态性. jdk jr ...
- 20145304 刘钦令 Java程序设计第一周学习总结
20145304<Java程序设计>第1周学习总结 教材学习内容总结 1995年5月23日,是公认的Java的诞生日,Java正式由Oak改名为Java. Java的三大平台是:Java ...
- 201871010106-丁宣元 《面向对象程序设计(java)》第一周学习总结
丁宣元 <面向对象程序设计(java)>第一周学习总结 正文开头 项目 内容 这个作业属于哪个课程 https://www.cnblogs.com/nwnu-daizh/ 这个作业的要求在 ...
- 扎西平措 201571030332《面向对象程序设计 Java 》第一周学习总结
<面向对象程序设计(java)>第一周学习总结 正文开头: 项目 内容 这个作业属于哪个课程 https://www.cnblogs.com/nwnu-daizh/ 这个作业的要求在哪里 ...
- 201871010135 张玉晶 《面向对象程序设计(java)》 第一周学习总结
项目 内容 这个作业属于哪个课程 https://www.cnblogs.com/nwnu-daizh/ 这个作业的要求在哪里 https://www.cnblogs.com/wyt0455820/ ...
- 杨其菊201771010134《面向对象程序设计(java)》第一周学习总结
第一部分:课程准备部分 填写课程学习 平台注册账号, 平台名称 注册账号 博客园:www.cnblogs.com 安迪儿 程序设计评测:https://pintia.cn/ 迷路的麋鹿回不来家了 代码 ...
- 201871010124 王生涛《面向对象程序设计JAVA》第一周学习总结
项目 内容 这个作业属于哪个课程 https://www.cnblogs.com/nwnu-daizh/ 这个作业的要求在哪里 https://edu.cnblogs.com/campus/xbsf/ ...
- 201871010126 王亚涛 《面向对象程序设计(java)》 第一周学习总结
项目 内容 这个作业属于哪个课程 https://www.cnblogs.com/nwnu-daizh/ 这个作业的要求在哪里 https://www.cnblogs.com/wyt0455820/ ...
- 201871010132-张潇潇《面向对象程序设计(java)》第一周学习总结
面向对象程序设计(Java) 博文正文开头 项目 内容 这个作业属于哪个课程 https://www.cnblogs.com/nwnu-daizh/ 这个作业的要求在哪里 https://www.cn ...
随机推荐
- 《Thinkphp5使用Socket服务》 入门篇
上车啦!!! 今天来说一下thinkphp5.0下使用wokerman的socket服务. 安装: composer的安装方法,Windows下直接下个composer的应用程序,双击安装,环境变量同 ...
- [Asp.net]绝对路径和相对路径
目录 绝对路径 相对路径 总结 绝对路径 绝对路径就是你的主页上的文件或目录在硬盘上真正的路径.比如:E:\新概念英语\新版新概念英语第二册课文PDF.pdf.以Web 站点根目录为参考基础的目录路径 ...
- Flask web开发之路十三
g对象 ### 保存全局变量的g属性:g:global1. g对象是专门用来保存用户的数据的.2. g对象在一次请求中的所有的代码的地方,都是可以使用的. 项目结构: g_demo.py文件代码: f ...
- ELK之使用filebeat收集java运行日志
安装filebeat修改配置文件/etc/filebeat/filebeat.yml filebeat.prospectors: - type: log enabled: true #日志路径 pat ...
- 2018ACM-ICPC南京区域赛M---Mediocre String Problem【exKMP】【Manacher】
这题就单独写个题解吧.想了两天了,刚刚问了一个大佬思路基本上有了. 题意: 一个串$S$,一个串$T$,在$S$中选一段子串$S[i,j]$,在$T$中选一段前缀$T[1,k]$使得$S[i,j]T[ ...
- [No0000162]如何不靠运气致富|来自硅谷著名天使投资人的40条致富经
1. Seek wealth, not money or status. Wealth is having assets that earn while you sleep. Money is how ...
- 设置shell脚本静默方式输入密码方法
stty命令是一个终端处理工具.我们可以通过它来实现静默方式输入密码,脚本如下 #!/bin/sh echo –e “enter password:” stty –echo ...
- zabbix客户端自动注册
1. 概述 上一篇内容<zabbix自动发现配置>,大概内容是zabbix server去扫描一个网段,把在线的主机添加到Host列表中.我们本篇内容与上篇相反,这次是Active age ...
- LeetCode 922 Sort Array By Parity II 解题报告
题目要求 Given an array A of non-negative integers, half of the integers in A are odd, and half of the i ...
- LeetCode 700 Search in a Binary Search Tree 解题报告
题目要求 Given the root node of a binary search tree (BST) and a value. You need to find the node in the ...