当前位置:网站首页>All the way, I was forced to talk about C code debugging skills and remote debugging
All the way, I was forced to talk about C code debugging skills and remote debugging
2020-11-06 21:09:23 【One line code farming technology】
One : background
1. Tell a story
Every time the project is pre delivered , There will always be all kinds of wonderful flowers , I think it's necessary to sort it out and how to solve it quickly , Let the latter avoid the pit , This article will talk about what I have heard and met :
- I went to , The code of local environment runs very fast , There's something wrong with the test environment
- I went to , Provided by a third party dll Run out bug 了
Two : The solution of two big holes
1. The local environment is OK , There's something wrong with the test
I believe that many friends have similar experience with me , Clearly program code , Configuration files are the same , Move a nest and there's a problem , You say no , Now that the problem has gone wrong, how to solve it quickly ? Yes , It's just debugging , But the program is deployed in centos On , Send a visualstudio It's not realistic to go up there , What do you want to do with debugging under this constraint level ? Pretty good , It can be debugged remotely , Then we quickly found that one of the environment variables in the test machine was wrong , The whole story is clear , Next, let's see how to achieve local To centos Of Remote debugging .
1) Test code
For the convenience of demonstration , I was there Action Read from strategy environment variable .
public class HomeController : Controller
{
public IActionResult Index()
{
ViewBag.strategy = Environment.GetEnvironmentVariable("strategy");
return View();
}
}
2) install SSH
To debug remotely , It needs to be installed on the remote machine SSH, Because the process debugging is attached later With the help of SSH Get through .
yum install openssh-server unzip curl
After installation , You can see 22 Port started
[[email protected] data]# netstat -tlnp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1126/sshd
tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 3037/cupsd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1739/master
tcp6 0 0 :::22 :::* LISTEN 1126/sshd
tcp6 0 0 ::1:631 :::* LISTEN 3037/cupsd
tcp6 0 0 ::1:25 :::* LISTEN 1739/master
3) Program release configuration
Release configuration , The first thing to make sure is debug edition , The second thing to make sure is Portable mode (Portable), Here's the picture :
4) Debug with attached processes
Select... In the menu bar :Debug -> Attach To Process, Then fill in ssh All kinds of information needed , Here's the picture :
Click on Connect after , You can see the remote machine dotnet Program Process number , Select the process to attach , stay Select Code Type Choose from Nanaged (.NET Core for Unix)
that will do , Here's the picture :
5) Smooth debugging
stay Type : http://192.168.142.130/Home/Index
, You can see my C# Code hit , I also got the remote machine's environment variable , The problem is solved .
2. The third party dll Out bug 了
Debugging programs use F9 debug , I believe many friends know that breakpoints can be edited , for instance : Set expression breakpoints , Filter breakpoints , Hit number breakpoint , Action breakpoint , Here is the picture :
The first question is , These fancy breakpoints , Do you really know how to use ? Do you really use it often ?
Let me answer , I won't use it until I have to , I'd rather add test statements that are easy to debug into my code , There are three reasons :
- More flexible
That's obvious , Setting conditions in the panel is much more cumbersome than setting conditions with pure statements , Point to point , And conditional superposition , It's complicated , I don't like .
- Powerful
There are only simple and relationships on the edit panel , And the conditions are the same level , It is impossible to achieve the inclusion relation of each condition or relation and hierarchy or recursion , therefore ... Can't ...
- Easier to save
This is interesting , Right click on the breakpoint to pop up the edit panel , Click the left button to close the breakpoint , Here's the problem , Often because of cheap hands , I want to click the right button, but I click the left button .... The hard set conditions are gone ... It's really gone , From then on , The road turns black . Here's the picture :
So breakpoint editing really doesn't work ? I think it's only in debugging scenarios where you can't modify statements , For example, I met debugging factory packaged dll, ha-ha , Now that we're talking about breakpoints , I will use it. dnspy Demonstrate a few breakpoints for you to review !
1) Test code
For the convenience of demonstration , use for The circular case is the best .
public static void Main(string[] args)
{
var sum = 0;
for (int i = 0; i < 10000; i++)
{
sum += i;
}
Console.WriteLine($"sum={sum}");
}
2) I hope to sum = 1035 Hit the breakpoint
The conditional expression breakpoint is OK , It's simple , As shown below :
3) Find all that can be 1800 Divisible number , And record what happened at that time i and sum value
You can use Action Logging of breakpoints , stay for In loop iteration , There is no need to break breakpoints , Just record the current... In a specific state i and sum Value , Very helpful for debugging code , Here's the picture :
3、 ... and : summary
Generally speaking, these two experiences are also included in my step-by-step experience , It would be better if I could help you , So much for this article , See you later !
More high quality dry goods : See my GitHub: dotnetfly
版权声明
本文为[One line code farming technology]所创,转载请带上原文链接,感谢
边栏推荐
- C++ 数字、string和char*的转换
- C++学习——centos7上部署C++开发环境
- C++学习——一步步学会写Makefile
- C++学习——临时对象的产生与优化
- C++学习——对象的引用的用法
- C++编程经验(6):使用C++风格的类型转换
- Won the CKA + CKS certificate with the highest gold content in kubernetes in 31 days!
- C + + number, string and char * conversion
- C + + Learning -- capacity() and resize() in C + +
- C + + Learning -- about code performance optimization
猜你喜欢
-
C + + programming experience (6): using C + + style type conversion
-
Latest party and government work report ppt - Park ppt
-
在线身份证号码提取生日工具
-
Online ID number extraction birthday tool
-
️野指针?悬空指针?️ 一文带你搞懂!
-
Field pointer? Dangling pointer? This article will help you understand!
-
HCNA Routing&Switching之GVRP
-
GVRP of hcna Routing & Switching
-
Seq2Seq实现闲聊机器人
-
【闲聊机器人】seq2seq模型的原理
随机推荐
- LeetCode 91. 解码方法
- Seq2seq implements chat robot
- [chat robot] principle of seq2seq model
- Leetcode 91. Decoding method
- HCNA Routing&Switching之GVRP
- GVRP of hcna Routing & Switching
- HDU7016 Random Walk 2
- [Code+#1]Yazid 的新生舞会
- CF1548C The Three Little Pigs
- HDU7033 Typing Contest
- HDU7016 Random Walk 2
- [code + 1] Yazid's freshman ball
- CF1548C The Three Little Pigs
- HDU7033 Typing Contest
- Qt Creator 自动补齐变慢的解决
- HALCON 20.11:如何处理标定助手品质问题
- HALCON 20.11:标定助手使用注意事项
- Solution of QT creator's automatic replenishment slowing down
- Halcon 20.11: how to deal with the quality problem of calibration assistant
- Halcon 20.11: precautions for use of calibration assistant
- “十大科学技术问题”揭晓!|青年科学家50²论坛
- "Top ten scientific and technological issues" announced| Young scientists 50 ² forum
- 求反转链表
- Reverse linked list
- js的数据类型
- JS data type
- 记一次文件读写遇到的bug
- Remember the bug encountered in reading and writing a file
- 单例模式
- Singleton mode
- 在这个 N 多编程语言争霸的世界,C++ 究竟还有没有未来?
- In this world of N programming languages, is there a future for C + +?
- es6模板字符
- js Promise
- js 数组方法 回顾
- ES6 template characters
- js Promise
- JS array method review
- 【Golang】️走进 Go 语言️ 第一课 Hello World
- [golang] go into go language lesson 1 Hello World