Build arm virtual operating environment on Ubuntu

Without development board, how to debug and run arm program?
This article mainly explains how to build an arm cross-compiling and running environment on Ubuntu.

One, install cross compilation tool chain##

Install the cross-compilation tool chain arm-linux-gnueabihf-gcc:

sudo apt-get install gcc-arm-linux-gnueabihf

After installation, you can see that so many cross-compilation tools have been added to the system:

helloworld@ubuntu:~$ arm-linux-gnueabihf-
arm-linux-gnueabihf-addr2line     arm-linux-gnueabihf-gcov-7
arm-linux-gnueabihf-ar            arm-linux-gnueabihf-gcov-dump
arm-linux-gnueabihf-as            arm-linux-gnueabihf-gcov-dump-7
arm-linux-gnueabihf-c++filt       arm-linux-gnueabihf-gcov-tool
arm-linux-gnueabihf-cpp           arm-linux-gnueabihf-gcov-tool-7
arm-linux-gnueabihf-cpp-7         arm-linux-gnueabihf-gprof
arm-linux-gnueabihf-dwp           arm-linux-gnueabihf-ld
arm-linux-gnueabihf-elfedit       arm-linux-gnueabihf-ld.bfd
arm-linux-gnueabihf-gcc           arm-linux-gnueabihf-ld.gold
arm-linux-gnueabihf-gcc-7         arm-linux-gnueabihf-nm
arm-linux-gnueabihf-gcc-ar        arm-linux-gnueabihf-objcopy
arm-linux-gnueabihf-gcc-ar-7      arm-linux-gnueabihf-objdump
arm-linux-gnueabihf-gcc-nm        arm-linux-gnueabihf-ranlib
arm-linux-gnueabihf-gcc-nm-7      arm-linux-gnueabihf-readelf
arm-linux-gnueabihf-gcc-ranlib    arm-linux-gnueabihf-size
arm-linux-gnueabihf-gcc-ranlib-7  arm-linux-gnueabihf-strings
arm-linux-gnueabihf-gcov          arm-linux-gnueabihf-strip

Execute the following code to establish a soft link, otherwise an error that the dynamic library cannot be found will be reported when executed later:

sudo ln -s /usr/arm-linux-gnueabihf/lib/libc.so.6/lib/libc.so.6
sudo ln -s /usr/arm-linux-gnueabihf/lib/ld-linux-armhf.so.3/lib/ld-linux-armhf.so.3

Write test code main.c:

# include <stdio.h>	
int main(){printf("helloworld\n");return0;}

The following command first compiles main.c to generate the executable file a.out under the arm platform, and then through the file command, you can see that a.out is the elf executable file under the arm platform:

helloworld@ubuntu:~$ arm-linux-gnueabihf-gcc main.c 
helloworld@ubuntu:~$ file a.out 
a.out: ELF 32-bit LSB shared object, ARM, EABI5 version 1(SYSV), dynamically linked, interpreter /lib/ld-,for GNU/Linux 3.2.0, BuildID[sha1]=7592a0494955ca8bb953948ea4cfbefc90b2e2e9, not stripped

Two, install the arm emulator qemu

Install arm emulator qemu:

sudo apt-get install qemu

Execute the executable file a.out of the arm platform. As you can see, the program outputs the correct result helloworld:

helloworld@ubuntu:~$ qemu-arm a.out 
helloworld

Three, debug arm program through gdb##

The principle of using gdb to debug arm programs on Ubuntu: the qemu end serves as a gdb server to start an executable program, and the other end serves as a gdb client to connect to the gdb server for local remote debugging.

  1. First install the multi-platform gdb tool:
    sudo apt-get install gdb-multiarch

  2. Recompile the sample code main.c, note that the parameter --static is added this time. After adding this parameter, the generated executable file is statically linked. **If you don't add this parameter, the single step function will be abnormal when debugging, and the symbol table will not be found. ** arm-linux-gnueabihf-gcc --static -g main.c

  3. Start the executable program a.out with the following command, the option -g specifies the listening port of gdb, here is 1234. After this command is executed, the current window will be blocked. qemu-arm -g 1234 a.out

  4. Open a new command line window, start gdb client, enter the gdb interactive interface: gdb-multiarch a.out

  5. Enter the following in the gdb interactive interface to connect to the server side: target remote localhost:1234

  6. Next, you can use the related functions of gdb to debug the program normally: (gdb) b main Breakpoint 1 at 0x102e8: file main.c, line 5. (gdb) c Continuing. Breakpoint 1, main () at main.c: 5 5 printf("helloworld\n");

Four, reference documents##

  1. Compile, run and debug ARM programs under Linux
  2. qemu related documentation
  3. CREATE DEBUG ENVIRONMENT FOR ARM ARCHITECTURE ON INTEL PROCESSOR

Recommended Posts

Build arm virtual operating environment on Ubuntu
Install Python virtual environment on Ubuntu 18.04
Build a LAMP development environment on Ubuntu 16.04
Build an Ubuntu Linux development environment on a Vmware virtual machine
Python virtual environment: Ubuntu16.04
Install ubuntu on virtual machine
ubuntu build python development environment
Ubuntu 18.04.1 build Java environment and HelloWorld
Build Nginx-RTMP live server on ubuntu
Deploy JobConverter + Ibreoffice environment on Ubuntu
Ubuntu16.04 build php5.6 Web server environment
Docker ubuntu: install python-PIL-image environment on 14.04
Build Nginx environment on Linux (CentOS)
Build a file server on ubuntu
Build Discuz forum based on ubuntu
Install Spark stand-alone environment on Spark Ubuntu18
Install Hadoop system environment on Ubuntu 18.04
How to build nfs service on ubuntu16.04
Build the C++ compilation environment under ubuntu
[PHP] Build a PHP operating environment under CentOS
Vagrant quickly builds Ubuntu virtual machine environment
Build a python development environment under Ubuntu
Install R package on UBUNTU virtual machine
Ubuntu20.04 install Python3 virtual environment tutorial detailed explanation
Build Nginx based on Centos 7 (including virtual host)
Install JDK and configure environment variables on Ubuntu 16.04
lamp on ubuntu
Ubuntu build etcd
How to use Jenkins to build automatically on Ubuntu
How to build a LAMP environment on centos7.2
Install Leanote on Ubuntu18 to build cloud notes
Ubuntu build Seafile
Embedded Linux development environment to build and configure Ubuntu
Install Ubuntu on VMware virtual machine and install using UltraISO
How to create a Python virtual environment in Ubuntu 14.04
Install and configure Mono production environment on Ubuntu Server
install vscode on ubuntu18
Install Redis on Ubuntu
ubuntu16.04 deploy GPU environment
Build k8s1.9.9 on centos7
Install R4 on ubuntu20
Install postgresql-10 on Ubuntu 18.04
Install docker on Ubuntu
CentOS6.7 build LNMP environment
Ubuntu configuration development environment
Centos7.6 build LNMP environment
Install Docker on ubuntu18.04
Install nodejs10 on Ubuntu16
Ubuntu 18.04 LTS LAMP build
Install mysql on Ubuntu 14.04
Install Django on ubuntu
Ubuntu development environment configuration
Install Python3 on Ubuntu 14.04
Jenkins build on centos
Install rJava on Ubuntu18
Ubuntu Touch environment setup
Install JDK10+ on Ubuntu
Install Python3 on Ubuntu 16.04
Ubuntu18.10 configure Java environment
ROS learning---Install ROS on Ubuntu
Install KDE on Ubuntu16.04.2