Ubuntu上构建riscv架构的Ubuntu22.04虚拟机并构建lldb

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.0riscv64架构ark编译器时,引用LLVM的接口LLVMInitializeRISCVTargetInfo() 编译生成ark_stub_compiler后,执行ark_stub_compiler再生成stub.an的二进制文件过程中报core dump错误,需要定位原因。
Ubuntu上构建riscv架构的Ubuntu22.04虚拟机并构建lldb_第1张图片
起初决定在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-keyrings
sudo 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/debian
sudo mkdir /mnt/debian
sudo mmdebstrap --arch riscv64 jammy /mnt/debian https://mirrors.ustc.edu.cn/ubuntu-ports
sudo cp /usr/bin/qemu-riscv64-static /mnt/debian/usr/bin/

ps:需要有riscv64的QEMU!!

4. 进入虚拟机

sudo chroot /mnt/debian

5. 虚拟机配置

echo "debian-riscv64" >/etc/hostname
echo "127.0.0.1 localhost" >/etc/hosts
echo "127.0.0.1 debian-riscv64" >/etc/hosts
echo "nameserver 8.8.8.8" >/etc/resolv.conf
cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
apt update

至此,riscv架构的Ubuntu22.04虚拟机搭建完成,可以使用

cat /etc/os-release
uname -a

等命令查看设备环境

root@znvhwd:/usr/bin# cat /etc/os-release  PRETTY_NAME="Ubuntu 22.04
LTS" NAME="Ubuntu" VERSION_ID="22.04" VERSION="22.04 (Jammy
Jellyfish)" VERSION_CODENAME=jammy ID=ubuntu ID_LIKE=debian
HOME_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 znvhwd
4.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 lldb
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
E: Unable to locate package lldb
root@znvhwd:/usr/bin# apt update
Hit:1 https://mirrors.ustc.edu.cn/ubuntu-ports jammy InRelease
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
All packages are up to date.
root@znvhwd:/usr/bin# apt search lldb
Sorting... Done
Full 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 multiverse
deb 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 multiverse
deb 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 multiverse
deb 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 lldb
Sorting... Done
Full Text Search... Done
golang-github-cznic-lldb-dev/jammy 1.0.1-1.1 all
  low level database engine

ruby-activerecord-nulldb-adapter/jammy 0.8.0-1 all
  ActiveRecord database adapters based on the Null Object pattern

rust-1.62-lldb/jammy-updates 1.62.1+dfsg1-1ubuntu0.22.04.1 all
  Rust debugger (lldb)

rust-lldb/jammy-updates,jammy-security 1.70.0+dfsg0ubuntu1~bpo2-0ubuntu0.22.04.2 all
  Rust debugger (lldb)

sdb/jammy 1.2-2.1 all
  a command line client for Mono's soft debugger

voltron/jammy 0.1.7+git20200109-2 all
  Hacky debugger UI for hackers

去https://packages.ubuntu.com/搜索lldb也没有,至此放弃安装,决定自己构建。

2.单独构建riscv架构的lldb

https://dev.iachieved.it/iachievedit/compiling-lldb-on-the-risc-v-hifive-unmatched/

  • 安装依赖
 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.git
root@build-lldb # cd /opt/build
root@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
              总计         已用        空闲      共享    缓冲/缓存    可用
内存:     8144460      729608     2766400        2048     4648452     7106944
交换:     2097148      777628     1319520
root@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/s
root@znvhwd:/mnt/debian# mkswap /swap
mkswap: /swap:不安全的权限 0644,建议使用 0600。
正在设置交换空间版本 1,大小 = 4 GiB (4294963200  个字节)
无标签, UUID=1381cdce-0f49-495f-81b4-e1a77d79c61a
root@znvhwd:/mnt/debian# chmod 0600 /swap
root@znvhwd:/mnt/debian# swapon /swap
root@znvhwd:/mnt/debian# free
              总计         已用        空闲      共享    缓冲/缓存    可用
内存:     8144460      732968     1168072        2136     6243420     7103492
交换:     6291448      775580     5515868
root@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

你可能感兴趣的:(openharmony,ubuntu,linux,harmonyos,risc-v)