Ubuntu上构建riscv架构的Ubuntu22.04虚拟机并构建lldb
- 需求来由
- 过程
- 一、Ubuntu上构建riscv架构的Ubuntu22.04虚拟机
- 1. ubuntu上安装必要工具
- 2. download key
- 3. 构建虚拟机
- 4. 进入虚拟机
- 5. 虚拟机配置
- 二、构建riscv的lldb
- 1. 尝试直接安装
- 2.单独构建riscv架构的lldb
- 三、使用lldb定位
- 总结
- 参考
需求来由
适配openharmony4.0的riscv64架构ark编译器时,引用LLVM的接口LLVMInitializeRISCVTargetInfo() 编译生成ark_stub_compiler后,执行ark_stub_compiler再生成stub.an的二进制文件过程中报core dump错误,需要定位原因。
起初决定在llvm的库中增加相应打印,但增加打印后,编译RISCV64的LLVM过程中打印已经正常输出,但仍然编译错误,所以决定使用LLDB(对应gcc工具链的GDB)进行定位。
所以需要riscv的环境以及lldb,下文开始描述riscv的ubuntu虚拟机搭建以及构建riscv架构的lldb过程。
(请教单位中的大神终于搞定)
过程
一、Ubuntu上构建riscv架构的Ubuntu22.04虚拟机
个别过程可能需要”扶墙”。
1. ubuntu上安装必要工具
sudo apt install mmdebstrap qemu-user-static binfmt-support debian-ports-archive-keyringssudo apt install qemu-system-misc opensbi u-boot-qemu qemu-utils
2. download key
wget -O - https://www.ports.debian.org/archive_2022.key | sudo apt-key add -
3. 构建虚拟机
sudo rm -rf /mnt/debiansudo mkdir /mnt/debiansudo mmdebstrap --arch riscv64 jammy /mnt/debian https://mirrors.ustc.edu.cn/ubuntu-portssudo cp /usr/bin/qemu-riscv64-static /mnt/debian/usr/bin/
ps:需要有riscv64的QEMU!!
4. 进入虚拟机
sudo chroot /mnt/debian
5. 虚拟机配置
echo "debian-riscv64" >/etc/hostnameecho "127.0.0.1 localhost" >/etc/hostsecho "127.0.0.1 debian-riscv64" >/etc/hostsecho "nameserver 8.8.8.8" >/etc/resolv.confcp /usr/share/zoneinfo/Asia/Shanghai /etc/localtimeapt update
至此,riscv架构的Ubuntu22.04虚拟机搭建完成,可以使用
cat /etc/os-release
uname -a
等命令查看设备环境
root@znvhwd:/usr/bin# cat /etc/os-releasePRETTY_NAME="Ubuntu 22.04LTS" NAME="Ubuntu" VERSION_ID="22.04" VERSION="22.04 (JammyJellyfish)" VERSION_CODENAME=jammy ID=ubuntu ID_LIKE=debianHOME_URL="https://www.ubuntu.com/"SUPPORT_URL="https://help.ubuntu.com/"BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"UBUNTU_CODENAME=jammy root@znvhwd:/usr/bin# uname -a Linux znvhwd4.15.0-65-generic #74-Ubuntu SMP Tue Sep 17 17:06:04 UTC 2019 riscv64 riscv64 riscv64 GNU/Linux
二、构建riscv的lldb
1. 尝试直接安装
- 本以为可以直接apt-get进行安装,但并没有发现可用的安装包。
root@znvhwd:/usr/bin# apt-get install lldbReading package lists... DoneBuilding dependency tree... DoneReading state information... DoneE: Unable to locate package lldbroot@znvhwd:/usr/bin# apt updateHit:1 https://mirrors.ustc.edu.cn/ubuntu-ports jammy InReleaseReading package lists... DoneBuilding dependency tree... DoneReading state information... DoneAll packages are up to date.root@znvhwd:/usr/bin# apt search lldbSorting... DoneFull Text Search... Done
- 增加源
vim.tiny /etc/apt/sources.list
修改为如下内容
# 默认注释了源码仓库,如有需要可自行取消注释deb https://mirrors.ustc.edu.cn/ubuntu-ports/ jammy main restricted universe multiverse# deb-src https://mirrors.ustc.edu.cn/ubuntu-ports/ jammy main main restricted universe multiversedeb https://mirrors.ustc.edu.cn/ubuntu-ports/ jammy-updates main restricted universe multiverse# deb-src https://mirrors.ustc.edu.cn/ubuntu-ports/ jammy-updates main restricted universe multiversedeb https://mirrors.ustc.edu.cn/ubuntu-ports/ jammy-backports main restricted universe multiverse# deb-src https://mirrors.ustc.edu.cn/ubuntu-ports/ jammy-backports main restricted universe multiversedeb https://mirrors.ustc.edu.cn/ubuntu-ports/ jammy-security main restricted universe multiverse# deb-src https://mirrors.ustc.edu.cn/ubuntu-ports/ jammy-security main restricted universe multiverse
sudo apt update
- 再次尝试
root@znvhwd:/usr/bin# apt search lldbSorting... DoneFull Text Search... Donegolang-github-cznic-lldb-dev/jammy 1.0.1-1.1 alllow level database engineruby-activerecord-nulldb-adapter/jammy 0.8.0-1 allActiveRecord database adapters based on the Null Object patternrust-1.62-lldb/jammy-updates 1.62.1+dfsg1-1ubuntu0.22.04.1 allRust debugger (lldb)rust-lldb/jammy-updates,jammy-security 1.70.0+dfsg0ubuntu1~bpo2-0ubuntu0.22.04.2 allRust debugger (lldb)sdb/jammy 1.2-2.1 alla command line client for Mono's soft debuggervoltron/jammy 0.1.7+git20200109-2 allHacky debugger UI for hackers
去https://packages.ubuntu.com/搜索lldb也没有,至此放弃安装,决定自己构建。
2.单独构建riscv架构的lldb
- 安装依赖
sudo apt-get install -y software-properties-common sudo add-apt-repository -y universe sudo apt-get install -y build-essential \swig \python3-dev \libedit-dev \libncurses5-dev \ninja-build \cmake \screen \git
- 下载代码
root@build-lldb # cd /opt/src/root@build-lldb # git clone https://github.com/llvm/llvm-project.gitroot@build-lldb # cd /opt/buildroot@build-lldb # cmake -G Ninja -DLLVM_ENABLE_PROJECTS="clang;lldb" -DLLVM_TARGET
- 编译
time ninja lldb lldb-server
- 解决报错(增加交换块个数)
FAILED:
tools/clang/lib/Sema/CMakeFiles/obj.clangSema.dir/SemaExpr.cpp.o
/usr/bin/c++ -DGTEST_HAS_RTTI=0 -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS
-D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/opt/build/tools/clang/lib/Sema -I/opt/src/llvm-project/clang/lib/Sema -I/opt/src/llvm-project/clang/include -I/opt/build/tools/clang/include -I/opt/build/include -I/opt/src/llvm-project/llvm/include -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -fno-lifetime-dse -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wno-missing-field-initializers -pedantic -Wno-long-long -Wimplicit-fallthrough -Wno-maybe-uninitialized -Wno-nonnull -Wno-class-memaccess -Wno-redundant-move -Wno-pessimizing-move -Wno-noexcept-type -Wdelete-non-virtual-dtor -Wsuggest-override -Wno-comment -Wno-misleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -ffunction-sections -fdata-sections -fno-common -Woverloaded-virtual -fno-strict-aliasing -O3 -DNDEBUG -fno-exceptions -funwind-tables -fno-rtti -std=c++17 -MD -MT tools/clang/lib/Sema/CMakeFiles/obj.clangSema.dir/SemaExpr.cpp.o -MF
tools/clang/lib/Sema/CMakeFiles/obj.clangSema.dir/SemaExpr.cpp.o.d -o
tools/clang/lib/Sema/CMakeFiles/obj.clangSema.dir/SemaExpr.cpp.o -c
/opt/src/llvm-project/clang/lib/Sema/SemaExpr.cpp c++: fatal error:
Killed signal terminated program cc1plus
root@znvhwd:/mnt/debian# free总计 已用空闲共享缓冲/缓存可用内存: 8144460729608 27664002048 4648452 7106944交换: 2097148777628 1319520root@znvhwd:/mnt/debian# dd if=/dev/zero of=/swap bs=1G count=4记录了4+0 的读入记录了4+0 的写出4294967296字节(4.3 GB,4.0 GiB)已复制,33.7963 s,127 MB/sroot@znvhwd:/mnt/debian# mkswap /swapmkswap: /swap:不安全的权限 0644,建议使用 0600。正在设置交换空间版本 1,大小 = 4 GiB (4294963200个字节)无标签, UUID=1381cdce-0f49-495f-81b4-e1a77d79c61aroot@znvhwd:/mnt/debian# chmod 0600 /swaproot@znvhwd:/mnt/debian# swapon /swaproot@znvhwd:/mnt/debian# free总计 已用空闲共享缓冲/缓存可用内存: 8144460732968 11680722136 6243420 7103492交换: 6291448775580 5515868root@znvhwd:/mnt/debian#
编译完成,开始进行使用!
PS:编译过程很慢,请耐心等待(我编了8个小时左右)。
三、使用lldb定位
进行中,之后补充。。。
总结
学习,记录,仔细,耐心。
参考
https://gitee.com/wawanala/iscas-ohos-riscv64/issues/I8LCJN
https://dev.iachieved.it/iachievedit/compiling-lldb-on-the-risc-v-hifive-unmatched/
http://mirrors.ustc.edu.cn/help/ubuntu-ports.html
https://packages.ubuntu.com/
https://www.cnblogs.com/tangxiaosheng/p/16178586.html