In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
In the last blog, we learned about linkers. So this lesson we continue to learn some common operations in embedded development, today we learn is in GNU development, essential debugging sharp weapon GDB. Comrades at the bottom may have heard of GDB more or less, but they think it is always so mysterious and vague. So let's take a look at GDB today.
Let's start with its concept. What is GDB? It is the debugger (gnu debuger) in the GNU project, and its function is to track the execution of the program and restore the state of the program before it crashed. So why do we need GDB? In our daily software development, it is inevitable to write some hard-to-find bug, then these bug is a flash in the pan and will be over soon. The program crashed before we had time to respond, so we couldn't find the source of bug. So we need to debug in the process of software development, which is the origin of gdb.
Let's take a look at some regular applications of GDB, which generally include the following aspects:
1. Customize the startup mode of the program (specify the parameters that affect the running of the program)
2. Set conditional breakpoints (suspend the execution of the program when the conditions are met)
3. Backtracking check causes the program to end abnormally (Core Dump)
4. Dynamically change the program execution flow (an auxiliary way to locate the problem).
So how does GDB start up? Its startup mode can be roughly divided into two types: direct startup and dynamic connection. Direct startup can be divided into three types: gdb; gdb test.out; gdb test.out core; dynamic connection: gdb test.out pid
Let's take a look at an example of a GDB application, as follows
After introducing its startup mode, let's take a look at how to use it for breakpoint debugging. Before introducing breakpoint debugging, let's first take a look at the breakpoint types in GNU. It is divided into three types: software breakpoint, hardware breakpoint and data breakpoint. Software breakpoints are implemented by illegal instruction exceptions (that is, through software), while hardware breakpoints and data breakpoints are implemented by hardware features (the common feature is that the number is limited).
Next, let's take a look at the operations related to software breakpoints:
1. Set the breakpoint through the function name:
Such as a > break func_name [if var = value]
B > tbreak func_name [if var = value]
2. Set the breakpoint through the file name and line number:
Such as a > break func_name:line_num [if var = value]
B > tbreak func_name:line_num [if var = value]
The difference between break and tbreak above is that tbreak sets a temporary breakpoint and break sets a permanent breakpoint. Let's move on to some common commands for breakpoint operations.
After introducing the operation of the software breakpoint, let's continue to introduce the operation and application of the hardware breakpoint. So under what circumstances do we use hardware breakpoints? 1. When the contemporary code is located in read-only memory (Flash), it can only be debugged through hardware breakpoints; 2, hardware breakpoints need hardware support, and the number is limited; 3, hardware breakpoints are supported by hbreak commands in GDB; 4, hbreak and break are used in the same way.
Let's first look at data breakpoints: the setting of data breakpoints is supported in GDB, and the watch command is used to monitor whether variables have been changed (which is also hardware breakpoints in nature). The usage of the watch command: watch var_name, you can check data in any area of memory in GDB. Command syntax: X / Nuf experssion, where N is the number of units to print, u refers to the size of each unit, and f refers to the format in which the data is printed. Let's take a look at the units corresponding to the parameter u in the x command, as follows
Next let's take a look at the print format in GDB, as shown in the following figure
In this section, we can use this feature to determine the size of the system. The sample code is as follows
If this is the case above, then the system is the small end; otherwise, it is the big end. Next, look at the view of the function call stack (backtrace and frame).
Backtrace is used to view the order of function calls (function call stack information); frame N is used to switch to the context of stack number N; info frame is used to view the stack frame information called by the current function station. The stack frame information is the record of the function activity we talked about in C language earlier, as follows
Let's take a closer look at the info command, as follows
Then there are some tips in debugging, such as automatic printing at breakpoints: display / f expression, and the corresponding removal printing is: undisplay; view of symbols in the program: code view in whatis,ptype;GDB: shell operation in list,set listsize Nissan GDB: shell. Take a look at an example of breakpoint automatic printing, as follows
Examples of symbol viewing are as follows
Through today's study of GDB, the summary is as follows: 1, GDB supports the setting of data breakpoints (a type of hardware breakpoints); 2, watch is used to monitor whether variables have been changed, x is used to view data in memory; 3, GDB supports function call stack view (backtrace,info frames); 4, GDB supports run-time view of symbols in the program (whatis,ptype).
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.