This is the 13th day of my participation in the August More Text Challenge.More challenges in August
This article documents other matters recorded during coredump debugging. In general, there are so many ways to debug that it’s impossible to catch them all at once. As far as I am concerned, I generally like to use print method, section annotation method, version rollback method, etc. There is no move, then use coredump file debugging. In my “numerous” experiences, programs die for a variety of reasons, such as memory leaks that cause no memory to be available, and files/sockets that are open or closed are exhausted. So the specification of programming is still very important, not only to say the coding naming style, but also the overall programming design and care, such as pointer judgment, array scope do not exceed the bounds, their own memory to remember to release, and so on.
Embedded ARM Linux Use precautions
There are many methods of debugging on embedded system. Many articles on the Internet have introduced the way of GDBServer. At the same time, codebLock can achieve the purpose of IDE debugging. Unfortunately, these are often simple cases. Practice, embedded devices running program, and driver module real-time interaction, is also closely frequent communication and network, also opened a N threads, M, a process in such a large system, once appear mistake, in addition to rely on print information, also can rely on the developer’s own experience, depend on the system of the familiar with degree of illness. Coredump, as a means of post-mortem analysis, has also been widely applied in daily work. However, embedded debugging is difficult. Because either the system used by the device is read-only or the storage medium has a very small capacity, when a large system crashes, the coredump file generated is too large to be saved on the storage medium, and much information will be lost and cannot be debugged using GDB. Another factor is the guard dog. Many systems have a watchdog mechanism that will reset the program immediately if it crashes, making it impossible to get coredump for analysis. Ulimit can be set in the program code or in the startup script, as long as it is set in the program environment. For example, if you are Telnet to the system to execute the program manually, be sure to set ulimit in the Telnet terminal before running the program. 2, the watchdog is banned or extended. Some devices can stub the pin on the motherboard to disable dogs, while others can code to disable dogs. For example, with my system, you can disable dogs by using echo. 3. Use NFS mount to store the generated Coredump file. 4. The compiler and debugger versions must correspond. Otherwise, there will be a lot of puzzling problems, which will be described in the following article.
Use BT to view functions as question marks (???)
-O2 optimizations, or binary programs after strip, will not generate debugging information, and the function name cannot be viewed with GDB. Use the -g compiler option to generate debugging information without stripping the program. 2. Incorrect library version. Either the true library version is incorrect, or the path is incorrect. If the library does not correspond, you can start GDB and use set solib-absolute-prefix and set solib-search-path to set the library path. The following is an example (based on the actual path) :
#gdb
#set solib-absolute-prefix "/home/latelee/cross/arm-linux/lib"
#set solib-search-path "/home/latelee/cross/arm-linux/lib"
#file a.out
#core-file core
Copy the code
There are articles on the Internet to do this introduction: “GDB debugging coredump file, function name is question mark”, this article will not be discussed.
Some coding tips
1, generally in the function to apply for memory, should be released in this function, if the space is not enough, it is recommended to directly use array, so as not to forget to apply for memory leakage. If you do use a second-level pointer to store the requested space within a function, note its use in the function declaration. 2. At all times, be sure to judge the validity of Pointers. Also pay special attention to the multilevel pointer case. Configuration->Multicast->Address->IPv4Address In this example, it is important to check whether Pointers are valid level by level. 3. Pay attention to parameter consistency when using printf, scanf and other functions. The default C library is checked in GCC, note that compile warnings reduce its segment error probability. But if you write your own print log function, you can’t check. 4, open resources should be released in time, especially return, break, goto these places, it is easy to forget to close. Resources include but are not limited to: sockets, ordinary file handles (file descriptors), directories, and so on. 5. It is recommended to do a code check using CPPCheck.