1) Mounting a Folder to QEMU: It is needed when you do cross-compiling! You can check this commit
Simply run in qemu:
mount_smbfs -I 10.0.2.4 -N //10.0.2.4/source_root /mnt
2) If running ~/cheri/cheribuild/cheribuild.py run-riscv64-purecap -d
results in an error indicating that the -lsbuf library cannot be found, unset your SYSROOT.
You can use this script https://ctsrd-cheri.github.io/cheri-exercises/introduction/ccc.html
. This script simplifies the compilation process for CHERI. You don’t need to set SYSROOT, or the others.
ccc riscv64-purecap print-pointer.c -o printpointer`
3) How to connect to running qemu? You can connect running qemu via ssh, find its IP address and port.
ssh root@127.0.0.1 -p portnumber
Very well-done examples is here https://github.com/capablevms/cheri-examples/
GoBolt for CHERI https://cheri-compiler-explorer.cl.cam.ac.uk/
ARM morello specifications.. https://www.google.com/url?sa=t&source=web&rct=j&opi=89978449&url=https://documentation-service.arm.com/static/61e577e1b691546d37bd38a0%3Ftoken%3D&ved=2ahUKEwjzo8zMho-FAxWQGRAIHXT6C3sQFnoECBkQAQ&usg=AOvVaw1zlS2wusJLyYE6bP0ALowC
]]>Of course, GNU Debugger (GDB) is my best friend to help me understand what is going on on the low-level side. Simply, GDB is a powerful debugger ( C and C++). Gdb can use debugging symbols that are generated by GCC ( -g) option. As usual, this is not a full tutorial. I jotted down what is important to me:)
gdb – args ./main args1 // start gdb with argument
p/x variable // hexadecimal print
x memory_address // read memory address
p/t variable // binary print
b // set a breakpoint. It can be put on a function, or specific line in a file */
watch // set a watchpoint, act on variables
finish // runs until the current function is finished
bt // backtrace
thread apply all bt // print the backtrace of all threads, it is so useful to solve deadlock problem.
info threads // print summarised version of above commands
info registers // print the register value
info all-registers rsp // print the rsp register value
i r rsp // shortage
info all-registers // print all registers
info locals // print the local variable
handle SIGSEGV nostop // don't stop the program in case of SEGFAULT. I needed to handle SIGSEGV functions, but the gdb doesn't allow me.
info breakpoint // print all breakpoint
si // step by machine instructions rather than source lines
set disable-randomization off // ASLR is disabled at default, it can be open with this command
set scheduler-locking // in multithreading application to debug just for one thread.
off == no locking (threads may preempt at any time)
on == full locking (no thread except the current thread may run)
step == scheduler locked during every single-step operation.
In this mode, no other thread may run during a step command.
Other threads may run while stepping over a function call
p $_siginfo // to print the last signal info
gdb --args env LD_PRELOAD=/usr/local/lib/libstderred.so ls -l
set exec-wrapper env 'LD_PRELOAD=../../playground/sud-library-concept/libsud.so'
Compiler Explorer Godbolt: Quite usefull for understanding the low level stuff
To remote host, target remote localhost:1234 can be used. More target subcommands are here.
// List of target subcommands:
target core - Use a core file as a target.
target exec - Use an executable file as a target.
target extended-remote - Use a remote computer via a serial line, using a gdb-specific protocol.
target native - Native process (started by the "run" command).
target record-btrace - Collect control-flow trace and provide the execution history.
target record-core - Log program while executing and replay execution from log.
target record-full - Log program while executing and replay execution from log.
target remote - Use a remote computer via a serial line, using a gdb-specific protocol.
target tfile - Use a trace file as a target.
Have a nice debugging!
Merve
]]>Example for Ubuntu
wget https://github.com/B-Lang-org/bsc/releases/download/2023.07/bsc-2023.07-ubuntu-22.04.tar.gz
cd ~/cheri/bsc-2023.07-debian-12.1
export PATH="$PATH:/home/cheri/bsc-2023.07-ubuntu-22.04/bin/
It’s likely that you will also need the Bluespec library. It took me a long time to understand what was missing. You need to install this library from the following repository:
https://github.com/B-Lang-org/bsc-contrib/tree/main
]]>