Use Visual Studio to compile and remotely debug embedded Linux programs using wingdb

Source: Internet
Author: User
Tags gdb debugger

Write this articleArticleThe purpose is to helpProgramProgrammers who want to develop and debug embedded Linux programs!

Step 1, install wingdb, download location http://www.wingdb.com/, connection is http://www.wingdb.com/WinGDB-latest_trial.msi 30 days trial version uninstall after 30 days, delete all GDB-related registries, and then reinstall, it can be used for another 30 days, as shown in the installation process:

1. Select to agree to the license agreement

2. If you have installed enough vs versions on your machine, you can choose either of them. It mainly depends on the version of vs you used.

3. If you are only using remote Linux development, select the first option. If you want to develop an embedded system, select the second option. If you want to develop an embedded system, select the third option, of course we chose the third item here.

Step 2: Create a wingdb Project

1. Create a wingdb project and select multiplatform executable.

2. Select the first item for remote development. The source code is built on the remote server, and debugging is also performed on the remote host, connect to these machines through TCP/IP and use the SSH protocol.

 

3. Select the second item. GDB and the Cross-compiling environment are on one server, and remote debugging is on another machine. This machine can be ARM Linux or another machine that supports gdbserver.

4. Enter the SSH address and password of GDB and the compiling environment, and the username and password of gdbserver.

5. Check that browse selects the gdb debugger we compiled in advance. This is the gdb running on the server in the compiling environment. It is used to control gdbserver. GDB and gdbserver must correspond to each other.

 

6. Select the local source code and remote source code synchronization method. Select this method based on your needs. If you are sharing the source code, select the first item. If you need to synchronize the source code, select the second item, if no synchronization is required, select the third item,

7. Select the remote file path and local file path:

 

8. Set compilation commands and compiling directories. These directories are the directories on the Compilation server listed when you Click Browse.

9. Select the target directory for remote debugging,

10. Select additional and additional source code files and libraries. skip this step. If necessary, set them here.

11. Set the debugging startup parameters. At the same time, we recommend that you remove the stop in main to avoid stopping the main function every time you start the program.

12. The configuration is complete ,:

My configuration is as follows:

Project Build command: Make
Project rebuild command: Make clean; make
Project Clean command: Make clean
Project deploy command:
Build working directory:/root/ct/src/
Build Environment Variables: build_configuration = "debug"
Build before start debugging: build project
Deploy before start debugging: Yes
Deploy action: Transfer file to target
Deploy only if file changed: Yes
Files to deploy:/root/ct/src // emrcv4
Deploy target directory:/mnt/emrcv4/bin
Core File Path:
Working directory:/mnt/emrcv4/bin
Arguments:
Environment variables:
Stop in main (): No
Target specification:
Server Mode: Launch executable
Executable on target:/mnt/emrcv4/bin/emrcv4
Launch GDB server automatically: Yes
Launch server from sysroot: No
Path to gdbserver:/usr/bin/gdbserver
Server port: 2345
Server port is forwarded: No
Forwarded server port: 0
Executable path:/root/ct/src // emrcv4
Byte order: little endian
Initialization Script:
Additional source directories:
Debug info directory:
Sysroot on Host:
Sysroot on target:
Shared Library directories:
Visualizer profile:
Load sources from build host: No
Disable hang Reporter: No
Debugger path:/usr/bin/ARM-unknown-Linux-gnueabi-GDB
Build toolchain paths:
Intercept standard ide commands: Yes
Target type: Linux indirect debugging (SSH + remote target)
Debug host login: root@192.168.50.178: 22
Build host login: root@192.168.50.178: 22
Debug target login: root@192.168.50.58: 22

Now the project debugging and compilation configuration have been completed.

Part 3,CodeIng Configuration

The following content is output in the output window:

Transmit transfer to remote host (s )--------------------------------------------------------------------------------

Errors were encountered during preparation: no files cocould be copied.

Cocould not map the path: D: \ works \ rhy \ toll \ trunk \ SRC \ functionassembly \ Lane \ emrcv4 \ emrcv4.vcxproj to remote filesystem. use 'map source directories 'option to setup a mapping.

If yes, the Code ing window is opened.

Then add a login under and then add a ing,

The following figure shows the compilation result. Due to the compiler error level, many errors may occur during the first compilation, while errors may disappear during the second compilation,

During debugging, the following window is displayed at startup. Click OK. ignore this.

The following figure shows the debugging process. You can view the local variables of the current process and the variable values under the mouse during the running. This is the same as Vs, and can also be executed in a single step.

 

Step 4: reference the header file. You can see that many constants and functions have a red line, because vs cannot find the corresponding header file, so you need to continue to make some settings.

Open project properties, select Configuration properties, select the VC ++ directory, and add the header files in the Cross-compilation environment to the included directory, for example:

D: \ works \ Linux \ toolchain_r2_eabi \ USR \ arm-unknown-Linux-gnueabi \ sysroot \ USR \ include

Then, you need to add all the directories of all your header files here. If there are many header file directories, it will be difficult.

 

After setting, you will see that vs is parsing the header file. After setting, the effect is as follows:

Finally, if the wizard settings are incorrect or are not saved, it may be because it is not administrator permission. Therefore, you may need to check your configuration,

The method is as follows:

The general setting of DEBUG host is the same as that of build host.

Set the debugger path in the environment

In the debugging options, select the generated executable file and the application working directory on the target machine.

Debugging Objectives

Gdbserver settings

The following step is very important. It is the project generation setting. The directory generated must keep the path in the path ing; otherwise, the file location cannot be located due to an error,

In the seventh column, set the project to be generated before debugging. In the eighth item, deploy the project before debugging. In the tenth item, set the deployment operation to transfer files to the target,

The fifth option is to deploy the file when the file changes. The fifth option is to deploy the file.

 

 

Conclusion

In addition, compilation of arm-related gdbserver and GDB will be introduced in future articles! This article will not be introduced. If GDB and gdbserver are inconsistent, debugging fails.

The following is the version information of my gdbserver:

[192.168.50.58:/mnt/emrcv4/bin] # gdbserver -- version
GNU gdbserver (GDB) 7.2
Copyright (c) 2010 Free Software Foundation, Inc.
Gdbserver is free software, covered by the GNU General Public License.
This gdbserver was configured as "arm-unknown-Linux-gnueabi"
[192.168.50.58:/mnt/emrcv4/bin] #

The following is the version information of GDB.

Root @ Ubuntu:/usr/bin # arm-unknown-Linux-gnueabi-GDB
Gnu gdb 7.2
Copyright (c) 2010 Free Software Foundation, Inc.
License gplv3 +: gnu gpl Version 3 or later This is free software: You are free to change and redistribute it.
There is no warranty, to the extent permitted by law. Type "show copying"
And "show warranty" for details.
This GDB was configured as "-- Host = i686-pc-linux-gnu -- target = arm-unknown-Linux-gnueabi ".
For bug reporting instructions, please see:
<Http://www.gnu.org/software/gdb/bugs/>.

Be sure to note this GDB was configured as "-- Host = i686-pc-linux-gnu -- target = arm-unknown-Linux-gnueabi ".

If they are inconsistent, the compilation will also fail.

 

The configuration is complete now. In a few days, I will supplement and improve this article based on the actual situation. If you are interested, please stay tuned!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.