当前位置:网站首页>How to read the source code [debug and observe the source code]
How to read the source code [debug and observe the source code]
2022-07-03 18:37:00 【1 Yile】
Welcome to Lele's blog Garden
* Compiler knowledge required for reading source code ( Compiler is eclipse As an example )
Commissioning preparations ( step :Window -> Show View -》...):
□ Open debug breakpoint Breakpoint:

□ Turn on variable monitoring

It depends on the internal details of a method , Press f5, Get into

Jump to a certain position quickly 【 Make a breakpoint at the target location 】, Then press f8

Details of the observation method ( Execute the process ), Step by step , Press f6

Remove all breakpoints ( The compiler is eclipse)

□ Pay attention to whether the execution position of the start tag is correct

f5 Enter by debugging 【
If the entry is irrelevant , Press f7 return , Press again f5 Enter once】 give an example :
User user = mapper.get(1L); // Make a breakpoint here to enter , Will enter first Long class , Because the order of execution is (1L) Execute first , So after entering it first , Re execution get Method
Press ctr and As debugged f5 The difference between : □ ctr: Is to enter “ The selected code ( class 、 Interface 、 Method )” The location of the definition of 【 The emphasis is
Definition of code】 □ f5: It is to execute the current code in the order of execution , Get into 、 Execute its internal 【 The emphasis isExecution of code】Press ctr With the mouse , You can know the next step of the code ( Press ctr Details to pay attention to :ctr The default entry is the definition of the selected code , Not an implementation process , After entering, I found that I didn't see any helpful code , return Return press and hold ctr, Selective implementation ( If there are multiple implementations ,
I don't know which one to choose , It can be debugged f5 Get into), Press the mouse again to enter .

Restart debugging details : (1) Close the last debugging (2) Click on Before commissioning , Keep the... In front of the breakpoint at the start position √, Before other breakpoints √ Remove first ( Start debugging before √ Come back )

After entering a method, learn the details of the method , Want to go back and then proceed , Press f7 return 【
Back to press f7】 Generally, after in-depth understanding of a module , You can press return , return ... Then move on to the next module
* The idea of reading source code
1、 Focus on understanding the execution logic ( The execution process can be carried out as control Enter a method or class , Understand the next step after , The cursor returns to the current position 【 Shortcut keys are alt+←】)
2、 Look at the source code process to clarify ideas , Abnormally related (error、exception、throw), The details that make the code more robust can be ignored ; Stack related stack, The bottom layer can be ignored
3、 In the code , See the selection Branch , You can observe the value of the variable ( Judge the condition ) Know which branch to enter
4、 In the code , See incomprehensible code , You can go down first , Then understand by observing the value of the variable 【 It can also be understood in combination with the official website 】
5、 Read stream 、 load resources 、 Binding namespace 、 Parameter conversion is not the point
6、 Constructing constructors is not the point , The point is to see The construction process of the constructor
7、 Constructing parsers is not the point , The point is to see The parsing process of the parser
8、 When you create a subclass, you should pay attention to : What kind of subclasses ? When a subclass has an encapsulated parent or sibling , Note what type of parent or sibling class is encapsulated ?
* How to focus on reading source code ( With mybatis The source code of )
■ 1、 The process of reading the source code , Which one should I read , Which is the key point of reading ?
Read the source code to build the source code of the session factory object , I learned that : Created a SqlSessoinFactory The session factory object is through the default SqlSessoinFactory Created , When creating, you need to pass in a configuration object 【 That is, when creating the session factory object, a configuration object is also created 】, thus , Study the creation process of configuration objects . 
Read the source code to build the source code of the session factory object , I learned that : Create a sqlSession The session object is through the default sqlSession, You need to pass in three parameters when creating , The key is to observe which ?
□ configuration Configuration object ( I learned about it when I read the source code of session factory object construction , Is not the point ) □ executor actuator ( a key , Because in return The session object was previously built executor actuator ) □ autoCommit ( Submit or not , Boolean value , Is not the point ) 
Combine to understand logic , also return The hint of , Know that the key point of reading is list The process of 
* Words to master when reading the source code
map mapping mapper mapper factory factory build structure config To configure parse analysis parser Parser parsed Has been resolved parseConfiguration Parsing configuration interceptor Interceptor plugin “ install [ enhance ]”、 plug-in unit proxy agent prepared precompiled callable Stored statment Statement object preparedStatement Precompiled statement object callableStatement Stored statement object cursor cursor instantiate Instantiation instantiateStatement Instantiate the statement object handler processor typeHandler Type processor row That's ok
● Reprint please indicate the source
边栏推荐
- 041. (2.10) talk about manpower outsourcing
- 毕业总结
- [combinatorics] dislocation problem (recursive formula | general term formula | derivation process)*
- Caddy server agent
- Unsafe类的使用
- 198. Looting - Dynamic Planning
- Class exercises
- Recent learning experience
- What London Silver Trading software supports multiple languages
- 统计图像中各像素值的数量
猜你喜欢

How to quickly view the inheritance methods of existing models in torchvision?

Kratos微服务框架下实现CQRS架构模式

Theoretical description of linear equations and summary of methods for solving linear equations by eigen

SQL injection -day16

Bidding procurement scheme management of Oracle project management system

Real time split network (continuous update)

Mysql45 lecture learning notes (II)

Su embedded training - Day10

Analysis of the reasons why enterprises build their own software development teams to use software manpower outsourcing services at the same time

Caddy server agent
随机推荐
Computer graduation design PHP campus address book telephone number inquiry system
NFT新的契机,多媒体NFT聚合平台OKALEIDO即将上线
Three gradient descent methods and code implementation
Class exercises
[combinatorics] generating function (generating function application scenario | using generating function to solve recursive equation)
Okaleido, a multimedia NFT aggregation platform, is about to go online, and a new NFT era may come
统计图像中各像素值的数量
Redis on local access server
Mysql45 lecture learning notes (II)
What does foo mean in programming?
Use of unsafe class
[combinatorics] generating function (positive integer splitting | unordered | ordered | allowed repetition | not allowed repetition | unordered not repeated splitting | unordered repeated splitting)
041. (2.10) talk about manpower outsourcing
Coordinate layer conversion tool (video)
Day-27 database
Torch learning notes (5) -- autograd
On Data Mining
2022-2028 global marking ink industry research and trend analysis report
Gao Qing, Beijing University of Aeronautics and Astronautics: CIM is a natural quantum computing platform for graph data processing
Theoretical description of linear equations and summary of methods for solving linear equations by eigen