Implementing the debugging of embedded software in VIM

Publisher:脑洞飞扬Latest update time:2013-03-18 Source: dzscKeywords:VIM  S3C2440 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

  introduction

  GNU provides a complete set of tool chains for free, providing complete support for the development and debugging of embedded Linux programs. Its powerful gdb debugging tool can easily track and debug programs on embedded platforms; and the powerful VIM editor under Linux can not only easily call make files to compile codes, but also easily become an efficient code editing environment through script configuration. There is a saying that "there are three types of programmers in the world, one uses Emacs, one uses VIM, and the rest are others." Without debating whether this sentence is right or wrong, simply understanding it literally can also show the charm of VIM. Therefore, by implementing the debugging of embedded software in VIM, we get an efficient and stable embedded Linux development environment.

  1 gdb debugging mode for embedded software

  Many non-Linux embedded systems have been using gdb and gdb stub to perform remote "cross debugging" on the target board; however, because the Linux kernel implements the ptrace() system call, gdb stub is not required when debugging embedded applications. Instead, the gdb server provided by the gdb suite is used to debug embedded applications on the target board.

  There are two main ways for the gdb server gdbserver on the target board to communicate with the gdb debugger on the host: "cross serial connection" using serial port communication and "TCP/IP" using network port. In view of the convenience of the PC end and the limited serial port resources, especially the current notebook computers do not even have serial ports, so most of them use TCP/IP, that is, the PC host and the target board are directly connected through a network cable or the PC and the target board communicate through a router or hub to form a local area network. This debugging mode is shown in Figure 1.

  2 Debugging embedded software in VIM

  We know that although gdb is powerful, its debugging process is not intuitive because it is based on command line operations. In addition, the debugging environment under Windows integrates debugging and code editing. When a bug occurs, the source code can be easily modified. In comparison, gdb is somewhat inferior in this respect. Since VIM and gdb are so powerful, completely free, and completely suitable for the special development mode of embedded systems, is there a way to combine the two? Yes, that is vimgdb.

  vimgdb is a patch that provides an optional feature for VIM. It can provide complete gdb debugger support in the VIM editor, such as setting breakpoints, viewing variable values, gdb command completion, etc., and these operations can be displayed intuitively in VIM. The following describes the specific process of implementing embedded software debugging in VIM.

  2.1 System environment and software package versions used

  PC operating system: Ubuntu 8.10.

  PC compiler: GNU gcc4.3.1.


 

  PC debugger: GNU gdb6.8.

  Target board Linux kernel: 2.6.13.

  Target board CPU: S3C2440 (ARM9 architecture).

  Cross compiler: armlinuxgcc3.4.1.

  Cross debugger: self-compiled GNU gdb6.8.

  Target board gdb server: self-compiled GNU gdbserver6.8.

  Cross-platform development tool path: ~/buildtools/armlinux, and the system path variable has been set.

  Test code and program path: ~/test, including program code test.c and Makefile.

  The software package storage path used is: ~/down.

  Software packages used: VIM editor source code vim7.1.tar.bz2, vimgdb711.13.tar.gz, GNU gdb source code gdb6.8.tar.bz2.

  2.2 Apply vimgdb patch to VIM source code and compile and install

  ① Run the following command to decompress the VIM source code and vimgdb patch file, and patch the VIM source code:

  cd ~/down

  tar jxvf vim7.1.tar.bz2

  tar zxvf vimgdb711.13.tar.gz

  patch d vim71 backup p0 < vimgdb/vim71.diff[page]

  ② Run the following command to compile and install the VIM compiler:

  cd ~/down/vim71/src

  make

  make install

  After executing the above operations, VIM will be installed in the /usr/local path. If you want to change the installation path, you can open the 862 line installation path option of the ~/down/vim71/src/Makefile file and modify it before the above compilation and installation. If VIM is installed in the /usr path, change 862 #prefix = $(HOME) to 862 prefix = /usr.

  ③ Install the vimgdb runtime file and run the following command:

  cd ~/down/vimgdb

  tar zxfv vimgdb_runtime.tgz C /usr/share/vim/vimfiles

  2.3 Building gdb components for cross-debugging embedded software

  ① Compile the embedded gdb debugger server gdbserver and run the following command:

  cd ~/down/gdb6.8/gdb/gdbserver

  ./configure??host=armlinux ??target=armlinux

  CC=armlinuxgcc make

  Copy the gdbserver in the current directory to the /bin directory of the target board file system for cross debugging.

  ② Compile and install the cross debugger gdb, and run the following command:

  cd ~/down/gdb6.8

  ./configure ??target=armlinux ??prefix=/home/popeye/buildtools/armlinux/

  Note that the value of prefix here must be filled in with an absolute path, and "~" cannot be used to replace the user path /home/popeye, otherwise it will prompt that the prefix path assignment is wrong. Then run:

  make

  During this process, the error shown in Figure 2 may occur.

  The reason for this is that the warning option "Werror" is selected in the compilation rules. It will turn all warnings into errors, and the prompt information about the "getwd" function shows that the compiler should detect a "warning" instead of a real syntax error. Therefore, the compilation options need to be corrected:

  cd ~/down/gdb6.8/gdb

  gedit Makefile

  Note that the Makefile here is generated after executing the above make command. The original code package does not contain this file. Modify line 145 of the file and remove the assignment of WERROR_CFLAGS, that is, change "145 WERROR_CFLAGS = Werror" to "145 WERROR_CFLAGS =". Then:

  cd ~/down/gdb6.8

  make

  make install

Error message during make

  Finally, enter ~/buildtools/armlinux/bin and find that the cross debugger armlinuxgdb already exists.

  2.4 Preparation for embedded software debugging in VIM

  The usual practice in the embedded software development process is: First, compile and debug the program on the PC. If it runs normally on the PC, cross-compile. Then, port the software to the target board. If a bug occurs on the target board, debug it with the cross debugger armlinuxgdb.

  In short, the debugging process of embedded software includes two parts: debugging on the PC and debugging on the embedded platform. In this process, both the debugger gdb on the PC and the cross debugger armlinuxgdb may be used, and the corresponding two executable programs are the same source code program and running on different platforms. At the same time, it involves the conversion of two debuggers, but vimgdb can only call the system command with the string "gdb".

  Let's simplify this difficult problem:

  ① Edit the applicable Makefile to control the generation of executable programs corresponding to different platforms:

  cd ~/test

  Among them, test.c is the experimental code, Makefile is the compilation rule, and we simply write the content of Makefile as follows:

  testpc:test.c

  gcc g Wall o testpc test.c

  testem:test.c

  armlinuxgcc g Wall o testem test.C

  When the "make testpc" command is executed, an executable program that can be run on a PC will be generated; when the "make testem" command is executed, an executable program that can be run on an embedded target board will be generated. [page]

  ② Modify the shortcut key mapping script of vimgdb to easily switch between PC debugger and cross debugger in VIM.

  First, since vimgdb can only call system commands with the string "gdb", do the following:

  mv /usr/bin/gdb /usr/bin/gdbpc

  cd ~/buildtools/armlinux/bin

  ln s /usr/bin/gdbpc gdb

  Since ~/buildtools/armlinux/bin has been added to the system path, after performing the above operations, at any time when you run the "gdb" command, the debugger actually running depends on the debugger to which gdb is connected here.

  Next, edit the file /etc/vim/macros/gdb_mappings.vim. The main changes and additions are:

  a. Add the debugger conversion function and set the conversion switch to the uppercase "E" key (Shift+E):

  let s:emOS_k = 1

  nmapE: callemOS()

  function! s:emOS()

  if s:emOS_k

  let s:emOS_k = 0

  exec ":!ln sf ~/buildtools/armlinux/bin/armlinuxgdb ~/buildtools/armlinux/bin/gdb"

  echohl ErrorMsg

  echo "NOW! Gdb is ready for Embedded System!!!"

  echohl None

  else

  let s:emOS_k = 1

  exec ":!ln sf /usr/bin/gdbpc ~/buildtools/armlinux/bin/gdb"

  echohl ErrorMsg

  echo "Gdb is ready for PC,, Now"

  echohl None

  endif

  End function

  b. Add the following code below the if s:gdb_k line:

  nmap:bel 25vsplit gdbvariables

  nunmap E

  That is, after entering the debugging state, block the debugger conversion shortcut key E, and set the shortcut key F8 to display the variable value monitoring window.

  c. Add the following code below the line let s:gdb_k = 1:

  exec ":!ln sf /usr/bin/gdbpc ~/buildtools/armlinux/bin/gdb"

  nmapE: callemOS()

  That is, after exiting the debugging state, the gdb command is restored to the call of gdbpc, and the debugger switch function of "E" is restored.

  d. Add the following statement in /etc/vim/vimrc:

  run macros/gdb_mappings.vim

  After starting vim, the shortcut key mapping for calling gdb will be started in vim.

  As for other shortcut keys specifically set in gdb_mappings.vim, readers can analyze or set them by themselves.

  2.5 Debugging embedded software in VIM

  The following are the shortcut keys used for debugging embedded software on the target board: E is the debugger switch; F9 is to enter the debugging mode; F8 is to open the variable monitoring window; the space bar is to open the command line input window; the debugging mode is for the PC to input and output the embedded target board through the hyperterminal, and Ubuntu8.10 debugs the embedded software through TCP/IP; the PC Linux IP is 222.31.51.147; the target board IP is 222.31.51.180; the debugging connection port is 1234.

  ① Use VIM to open ~/test/test.c, run the command ":make testem", copy the generated testem file to the file system of the embedded platform, and run the command on the embedded platform to specify the cross debugger address waiting for connection, the connection port, and the embedded program to be debugged:

  gdbserver 222.31.51.147:1234 testem

  The embedded terminal will display a prompt message similar to the following and enter the waiting state for connection:

  Process testem created; pid = 801

  Listening on port 1234

  ② Press the capital "E" key (Shift+E) and determine the selected debugger according to the prompt information at the bottom of the VIM window.

  The prompt message is "NOW! Gdb is ready for Embedded System!!!" or "Gdb is ready for PC,, Now".

  ③ Press F9 and enter the command "file testem" in the command window that appears. The following debugging information will appear in another window in VIM:

  GNU gdb 6.8

  Copyright (C) 2008 Free Software Foundation, Inc.

  …

  This GDB was configured as "host=i686pclinuxgnu target=armlinux".

  (gdb) file testem

  Reading symbols from /home/popeye/test/testem...done.

  (gdb)

  It can be found that the cross debugger armlinuxgdb has been successfully called in VIM. For subsequent debugging commands, press the space bar first, call out the command window, enter the command, and press Enter to pass it to the debugger. [page]

  Press the spacebar and enter the command in the command window to connect to the embedded target board:

  target remote 222.31.51.180:1234

  At this point, the debugging information window in VIM displays the following information:

  (gdb) target remote 222.31.51.180:1234

  Remote debugging using 222.31.51.180:1234

  [New Thread 801]

  0x40000dd0 in ?? () from /lib/ldlinux.so.2

  (gdb)

  A prompt message appears on the embedded end:

  Process testem created; pid = 801

  Listening on port 1234

  Remote debugging from host 222.31.51.147

  At this point, the connection between the PC cross debugger and the embedded software is complete. Now you can set actions such as breakpoints for program operation in VIM; the input and output of the embedded software needs to be completed on the embedded end. Here, first set breakpoints for the code through commands, then use the continue command to continue the program (note that run is not needed here, because when the debugger is connected to the embedded end, the debugged embedded software has already started running), and use the next command to implement step debugging of the program. The VIM during the debugging process is shown in Figure 3.

VIM during debugging

  The test code in the figure is to let the user input 5 numbers, and then output them after sorting. The corresponding input and output are reflected on the embedded end. Corresponding to Figure 3, the input action needs to be performed on the embedded end at this time:

  Listening on port 1234

  Remote debugging from host 222.31.51.147

  Enter 10 numbers:

  a[0]=25

  a[1]=56

  a[2]=……

  From Figure 3, we can clearly see where the breakpoint is set and where the program is currently stepping. When the program runs to line 17 in Figure 3 for the first time, press F8 to open the variable value observation window, and then execute three commands "cr i", "cr j", and "cr a[i]" in succession. In this way, the value of the variable can be monitored in real time in the variable observation window, as shown in Figure 4.


Monitor the value of variables in real time in the variable observation window

  This debugging mode provides support for all gdb command functions, and when a bug is found, you can terminate debugging through the q command, then press F9 to exit the debugging mode, and then continue to modify the source code.

  As for the debugging of embedded software on the local PC before, the process is the same as debugging software running on embedded devices, except that there is only one remote connection process. So far, the debugging of embedded software in VIM has been realized.

  Conclusion

  The widespread application of embedded Linux systems has put forward higher requirements for the efficiency of embedded software development and debugging environments. The tool chain provided by GNU that supports cross-compilation and debugging is a good choice, especially the gdb debugging tool that fully meets the special needs of "cross-compilation" of embedded software; moreover, the powerful VIM editor can integrate the gdb debugger, thereby realizing the debugging function of embedded software in VIM. From the above examples, we can see that debugging embedded software in VIM is more intuitive and efficient, which has also led to a qualitative improvement in the development efficiency of embedded software.

Keywords:VIM  S3C2440 Reference address:Implementing the debugging of embedded software in VIM

Previous article:Detailed explanation of the zImage kernel image decompression process
Next article:NAND Flash driver design

Recommended ReadingLatest update time:2024-11-17 02:39

S3C2440 character device driver LED driver_writing and compiling (II)
app: open , read , write Driver: led_open, led_read, led_write Driver framework: 1. Write: led_open, led_read 2. How to tell the kernel? a. Define a file_operations b. Tell the kernel about this structure: register_chrdev(major,name,file_operations) c. Who calls it (register_chrdev) Driver entry func
[Microcontroller]
S3C2440 character device driver LED driver_writing and compiling (II)
ARM Linux S3C2440 Interrupt Analysis
Hardware: S3C2440 is an arm920T architecture. Let's first review the interrupt controller principles and related hardware architecture in s3c2440. Interrupt Controller: The interrupt controller of S3c2440A has 60 interrupt sources, such as DMA interrupt, UART interrupt, IIC interrupt, etc. The 60 inte
[Microcontroller]
ARM Linux S3C2440 Interrupt Analysis
s3c2440 memory device access principle
In embedded systems, the so-called memory interfaces include SDRAM interface, NORFLASH interface, DM9000 network card interface, etc. They all have one thing in common: they can directly connect to the S3C2440 memory controller, data bus, and address bus; none of these three is indispensable. Memory interfaces can d
[Microcontroller]
s3c2440 memory device access principle
S3C2440 Watchdog Analysis
The watchdog timer of S3C2440A is used to restore the controller's operation when it is disturbed by faults caused by noise and system errors. It can be used as a normal 16-bit internal timer to request interrupt service. The watchdog timer generates a reset signal of 128 PCLK cycles. That is to say, in some environme
[Microcontroller]
S3C2440 Watchdog Analysis
s3c2440 bare metal - abnormal interrupt 5 - irq timer interrupt
I have talked about the s3c2440 clock system before. After looking at the clock system and then looking at the timer interrupt, it will be better to combine and apply the knowledge points learned. S3c2440 has 2 types of timers: 1.Watchdog watchdog timer 2.PWM pulse modulated timer The following is a deta
[Microcontroller]
ARM-Linux s3c2440 UART Analysis (Part 4)
After registration is complete, how are the device and driver connected? It turns out that the device connection has been made during driver_register() registration. The serial port is a platform device. The device registration is completed in the system framework setup_arch(), and the device registration precedes t
[Microcontroller]
s3c2440 bare metal - code relocation -1- introduction of relocation
1. Introduction of relocation (why code relocation is needed) We know that the CPU of s3c2440 starts to fetch instructions from address 0. When it is started from nor, address 0 corresponds to nor. nor can be read like memory, but cannot be written like memory. We can fetch instructions from nor. Exa
[Microcontroller]
Interface Design of Handheld Digital Waveform Table Based on LabVIEW8.6 and S3C2440
The virtual instrument program designed by LabVIEW is transplanted to a portable handheld device running Windows CE. This can greatly improve the efficiency of embedded system software development. Specifically, an interface design that effectively solves the problem of alternating display of data waveforms is propo
[Microcontroller]
Interface Design of Handheld Digital Waveform Table Based on LabVIEW8.6 and S3C2440
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号