Problems using LLDB to remotely debug a RISCV program running on QEMU

I’m having 2 issues with remote debugging RISCV code using LLDB(version 16.0.0) and QEMU(version 7.0.0) :

  • After gdb-remote, the frame address is an invalid value.

  • Set a breakpoint, however, you cannot stop at the breakpoint.

Are these two problems caused by my configuration problem?

The relevant details are as follows:

Starting QEMU:

qemu-system-riscv32 -nographic -smp 1 -gdb tcp::23450 -m 1G -bios ../tests/c_code/test_gdbstub_riscv32 -S

LLDB command and output as follow:

$ lldb -d ../tests/c_code/test_gdbstub_riscv32
(lldb) target create "../tests/c_code/test_gdbstub_riscv32"
Current executable set to '../tests/c_code/test_gdbstub_riscv32' (riscv32).
(lldb) gdb-remote localhost:23450
(lldb) Process 1 stopped
* thread #1, stop reason = signal SIGTRAP
    frame #0: 0xffffffffffffffff 
b main
Breakpoint 1: where = test_gdbstub_riscv32`main + 8 at test_gdbstub.c:31:15, address = 0x800001a2
(lldb) c
Process 1 resuming
(lldb) list main
File: tests/c_code/test_gdbstub.c
   24          static const int cc = 3;
   26          return actual_calc(ca, cb+cc);
   27      }
   29      int main(void)
   30      {
   31          const int ma = 13;
   32          const int mb = 0;
   34          result = calc(ma, mb);
(lldb) c
error: Process is running.  Use 'process interrupt' to pause execution.

LLDB version:

lldb version 16.0.0git ( revision fcfa9c7fcdbab22c42ef74d3975ecede5b912f6b)
  clang revision fcfa9c7fcdbab22c42ef74d3975ecede5b912f6b
  llvm revision fcfa9c7fcdbab22c42ef74d3975ecede5b912f6b

build QEMU:

mkdir build
cd build
../configure --target-list=riscv32-softmmu,riscv32-linux-user

The command to generate test_gdbstub is:

riscv32-unknown-elf-gcc -gdwarf-4 -Wall -Wextra test_gdbstub.c -o test_gdbstub_riscv32

The version of riscv32-unknown-elf-gcc is:

riscv32-unknown-elf-gcc (g5964b5cd727) 11.1.0
Copyright (C) 2021 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO

Source code for test is:

 * test_gdbstub.c
 * Copyright (c) 2022. All rights reserved.
 * Date: 2022-09-14
 * @author Zhao Shaowei

static int result;

static int actual_calc(int aa, int ab)
    int ac;

    ac = aa / ab;

    return ac;

static int calc(int ca, int cb)
    static const int cc = 3;

    return actual_calc(ca, cb+cc);

int main(void)
    const int ma = 13;
    const int mb = 0;

    result = calc(ma, mb);

    return 0;

I’m not sure what the state of RISCV support in lldb 16.0 is - but this is telling you that it doesn’t know the pc value where you’re stopped in qemu, that value is LLDB_INVALID_ADDRESS. Top of tree lldb still doesn’t have an ABI plugin for RISCV yet ⚙ D132510 [RISCV][LLDB] Add initial SysV ABI support let alone LLDB 16.0; I doubt you’ll be able to debug a riscv target without at least that being present.

Thanks for the quick response. I take a closer look at this link.

Enough support should be in the main branch for debugging RISCV programs. I was able to successfully debug with DebugServer2 (GitHub - compnerd/ds2: Debug server for lldb.).