Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

while debuggung with gdb, custom instructions not showing #1412

Closed
RohanAhmed1 opened this issue Jan 21, 2024 · 14 comments
Closed

while debuggung with gdb, custom instructions not showing #1412

RohanAhmed1 opened this issue Jan 21, 2024 · 14 comments

Comments

@RohanAhmed1
Copy link

I added the custom instructions in toolchain. The toolchain works perfectly and my new instructions in also showing in dump file(disasmebly) with their proper naming convention but when I use gdb to debug, the hex is showing instead of the custom instruction name

@TommyMurphyTM1234
Copy link
Collaborator

You'll have to provide some detail about how exactly you modified the toolchain to add support for your custom instructions.

@RohanAhmed1
Copy link
Author

Adding custom instructions compilation support, to RISCV ... https://medium.com/@viveksgt/adding-custom-instructions-compilation-support-to-riscv-toolchain-78ce1b6efcf4

I followed these steps

@TommyMurphyTM1234
Copy link
Collaborator

Adding custom instructions compilation support, to RISCV ... https://medium.com/@viveksgt/adding-custom-instructions-compilation-support-to-riscv-toolchain-78ce1b6efcf4

I followed these steps

Did you do this?

optinally same changes can be done in
riscv-gnu-toolchain/riscv-gdb/opcodes/riscv-opc.c
riscv-gnu-toolchain/riscv-gdb/include/opcode/riscv-opc.h

@TommyMurphyTM1234
Copy link
Collaborator

This may also be relevant:

@TommyMurphyTM1234
Copy link
Collaborator

Did that help at all @RohanAhmed1 ?

@kito-cheng
Copy link
Collaborator

Just remind that: gdb and binutils are shared same code base, but they are different folder in riscv-gnu-toolchain, so you need to apply those change for gdb folder as well, generally should be same change, but may facing some minor merge conflict due to the base version mismatch, because binutils and gdb had different release schedule.

@TommyMurphyTM1234
Copy link
Collaborator

TommyMurphyTM1234 commented Jan 23, 2024

Thanks @kito-cheng - I always wondered why there were two different copies of binutils-gdb with different branches/tags pulled in by riscv-gnu-toolchain.

  • Binutils (binutils @ 49f6117)
  • GDB (gdb @ 662243d)

@TommyMurphyTM1234
Copy link
Collaborator

No update from @RohanAhmed1 for over a week so I am assuming that the issue has been explained by the need to make the relevant changes in the two copies of the binutils-gdb sources and, as such, am closing the issue. If it's still a problem then reopen it with further info.

@RohanAhmed1
Copy link
Author

Hi, apologies from my side for being late of trying suggestion of adding custom instructions in the gdb folder as well.

Let me give you all of what I have done and what issue I am facing.

Procedure and Explanation

I am adding custom instruction(vgmul.vv) in the toolchain in following path.

At gdb/opcodes/riscv-opc.c and riscv-binutils/opcodes/riscv-opc.c
{"vgmul.vv", 0, INSN_CLASS_V, "Vd,Vt", MATCH_VGMULVV, MASK_VGMULVV, match_opcode, 0 },

At riscv-binutils/include/opcode/riscv-opc.h and gdb/include/opcode/riscv-opc.h
#define MATCH_VGMULVV 0xA208A077
2586 #define MASK_VGMULVV 0xFE0FF07F

Now, I am test this instrucion by making a simple test.
...
li x11, 0x100000000
29 li x12, 0x100000040
30 li x10, 0x100000120
31 li x9, 0x100000080
32
33 vle32.v v2, (x11)
34 vle32.v v4, (x12)
36 vgmul.vv v2, v4
37
38 vse32.v v2, (x10)
39 # test ends here

Now, I build this test with the help of obj_folder of updated toolchain with;

riscv64-unknown-elf-gcc -march=rv64gv -O -g -mcmodel=medany -gdwarf-2 -c -o test.out

and create disassmebly file with

riscv64-unknown-elf-objdump -D test.o > test.dump

This dissassembly file has the vgmul.vv instruction.
...
80000002c: 12050513 addi a0,a0,288
20 800000030: 0010049b addiw s1,zero,1
21 800000034: 02049493 slli s1,s1,0x20
22 800000038: 08048493 addi s1,s1,128
23 80000003c: 0205e107 vle32.v v2,(a1)
24 800000040: 02066207 vle32.v v4,(a2)
25 800000044: a248a177 vgmul.vv v2,v4
26 800000048: 02056127 vse32.v v2,(a0)
...

It means that, my instruction is identifed by the toolchain and my test is running as well.

Issue

Now, I am debugging this with gdb of updated toolchain by:

riscv64-unknown-elf-gdb test.out

and running this command to open the debugger window of dissambly by

tui reg vector
layout next

image

As you see in this, my custom instruction is showing with .4byte instead of vgmul.vv

Am I missing some files to update?

@TommyMurphyTM1234
Copy link
Collaborator

I am adding custom instruction(vgmul.vv) in the toolchain in following path.
...

After making the relevant code changes did you make sure to do a full/clean build?
E.g.

make distclean
rm -rf <toolchain-prefix-dir>
make

BTW - your screenshot is really difficult to read - please use logs rather than screenshots for ease of readability and analysis.

@RohanAhmed1
Copy link
Author

RohanAhmed1 commented Feb 15, 2024

Yeah, I have followed this command to build except make distclean and use one more command. Let me write my steps to build.

make clean
rm -rf [toolchain-prefix-dir]
./configure -with-gcc-src=[path-to-gcc] --prefix=[toolchain-prefix-dir] --with-cmodel=medany
make.

-with-gcc-src= is used to save cloning time. Actually, It is a copy of a clone of gcc 13.0. Instead of using riscv RNU toolchain / gcc which I think was gcc 12.3 or something.

I will try this command as well and let you know. Thanks.

@TommyMurphyTM1234
Copy link
Collaborator

Yeah, I have followed this command to build except make distclean and use one more command. Let me write my steps to build.

make clean
rm -rf [toolchain-prefix-dir]
./configure -with-gcc-src=[path-to-gcc] --prefix=[toolchain-prefix-dir] --with-cmodel=medany
make

I don't think that make clean is sufficient to do a clean build.

-with-gcc-src= is used to save cloning time.

Cloning only happens the first time you do the following:

git clone https://github.com/riscv-collab/riscv-gnu-toolchain
cd riscv-gnu-toolchain
./configure ...
make

It doesn't happen thereafter.

Actually, It is a copy of a clone of gcc 13.0. Instead of using riscv RNU toolchain / gcc which I think was gcc 12.3 or something.

I don't know what "riscv RNU toolchain" is.
If you mean this repo - riscv-gnu-toolchain - then it has been GCC 13.2.0 for a while now:

@RohanAhmed1
Copy link
Author

Thanks you for your response. Yeah I mean riscv-gnu-toolchain repo.

Well I tried it out with these steps now,

make distclean
rm -rf [toolchain-prefix-dir]
./configure -with-gcc-src=[path-to-gcc] --prefix=[toolchain-prefix-dir] --with-cmodel=medany
make

The issue is still remain. What can be other thing I can try? can you suggest some?

@TommyMurphyTM1234
Copy link
Collaborator

The issue is still remain. What can be other thing I can try? can you suggest some?

Maybe ask about the issue on the GDB mailing list since this is not really a RISC-V specific issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants