0

Due to:

it becomes very hard to setup Eclipse to work well with gem5.

Has anyone managed to achieve a good setup? Especially interested in Linux hosts.

Ciro Santilli
  • 3,693
  • 1
  • 18
  • 44

1 Answers1

1

I have achieved a very good setup with the following horrendous hack: define the Eclipse project inside the build/ARM directory itself!

This is done by creating a "New makefile project with existing code" in the build directory. You will also want to fix the C++ standard library as mentioned at: How to solve "Unresolved inclusion: <iostream>" in a C++ file in Eclipse CDT?

This works amazingly because the way the gem5 build system works as of May 2020, the build/ARM directory contains exactly the final compilation tree, including all the source symlinks and autogenerated code,.

This setup is not perfect because there is still some C++ stuff in build/ outside of ARM, e.g. ext, but 99% of the time we don't care about those, and I can perfectly navigate key autogenerated code such as instructions and decoder.

I then just build via the command line normally with scons.

Humongous autogenerated files like exec-ns.cc.inc turn on Eclipse's large file limited mode. Notably, if you want to jump to a definition, Ctrl + click does not work for me, so I just copy the symbol of interest and Ctrl + Shift + T to go to its definition.

I don't usually bother to try GDB step debug gem5 through Eclipse and use it mostly for code navigation, since GDB Dashboard tends to work well enough for me, and I often need to do new log collection runs and I sometimes use reverse debugging when things get serious.

But I have tested step debugging through Eclipse, and it did work normally (no reason not to I guess), you just have to set it up in exactly the same was as for any other C++ application with a Makefile, i.e. basically tell eclipse the Binary name and the desired CLI on the debug configurations.

You have of course as usual to choose between a gem5.debug debug build or a gem5.opt build, where the .debug build is about 10-20x slower but gives greater debug visibility. In general, if the time to reach the point of interest in a debug build starts to annoy you however, what you tend to really want is to do use reverse debugging.

This is also mentioned at: https://cirosantilli.com/linux-kernel-module-cheat/#gem5-eclipse-configuration

Tested in Eclipse 2020-03.

Ciro Santilli
  • 3,693
  • 1
  • 18
  • 44
  • It looks great. But it feels complicated for novices. I want to connect to gem5 on the server via ssh in vscode, and then debug on vscode. It would be great if you can show it on youtobe. Thank you for providing an idea. – Gerrie Oct 18 '20 at 08:23
  • @cyj hi, can you let me know if there is any particular step that is not clear? Basically all you need to do is: 1) build 2) setup project in build directory. Everything else should be identical for any other project. Start with a hello world project and try to search for more generic questions if the problem is the non-gem5 specific part. – Ciro Santilli Oct 18 '20 at 17:05
  • Sorry, due to my shallow knowledge, I still don't understand what I should do. Can this method allow me to debug gem5 source code in vscode (single step and see the result of each statement in gem5 source code)? Do you mean scons build/X86/gem.opt in the first step of build? What should I do in the second step of setup project in build directory? – Gerrie Nov 02 '20 at 02:35
  • @cyj No worries. I only tested in Eclipse, but will likely work on vscode as well. Yes, it allows you to step debug gem5 emulator code. Yes, first do the regular `scons` build manually from CLI. The second step is just to create a project inside the build directory (`build/X86`) and add to the project every single source file found in that directory. This will automatically include both auto-generated and non auto-generated files (which scsons symlinks to the actual source files). – Ciro Santilli Nov 02 '20 at 07:51
  • @cyj Sample question of how to create a new project from existing source: https://stackoverflow.com/questions/2636201/how-to-create-a-project-from-existing-source-in-eclipse-and-then-find-it – Ciro Santilli Nov 02 '20 at 07:51
  • thank you for your reply. But I am confused about a file like gem5.opt, it seems to be an executable file. And it seems that it can only be executed through the command line. I just saw that gem5.opt has about 500M. You can create a new project in eclipse, but what type of new project should you create? java, c++ or other? vscode seems to be just an editor, can it create new projects? Moreover, in the description of the link above, all source files should be placed in one directory. Do all the source files here refer to gem5.opt or all files under build, or the entire gem5 file? – Gerrie Nov 02 '20 at 08:54
  • @cyj in Eclipse, you should create a C++ project, and only add to the project the C++ files, so that they will be parsed and definitions found. The gem5.opt, you have to point to it on the run setup menu, it does not need to be "added to the project" like the C++ files. In vscode I don't know how things work, but it should be exactly the same as the non-gem5 setup, so I would recommend trying to learn it with a minimal non-gem5 example [like this one](https://github.com/cirosantilli/ide-test-projects/tree/master/cpp) first. – Ciro Santilli Nov 02 '20 at 09:02
  • @cyj in practice, I've been doing step debug on GDB CLI, and use Eclipse just as a code browser to jump to definitions. But GDB through eclipse did work when I last tested, no reason not to. – Ciro Santilli Nov 02 '20 at 09:03
  • When debugging, my main confusion is that in non-gem5 projects, I only need to find the file where the main function is located, and then run this file, and it will stop at the breakpoint. But in the gem5 project. It started from gem5.opt. If I don't use the command line, how can I make the project run? If I use the command line, the breakpoints I set in vscode seem to be useless. When you run the gem5 project in eclipse, how did you start it, double-click gem5.opt? – Gerrie Nov 02 '20 at 09:16
  • @cyj yes, CLI debug has no UI integration, just mentioned it as a good enough solution I tend to use. Eclipse debugging of gem5 and non gem5 projects is exactly the same. gem5.opt is a C++ executable. Configs such as `config/example/fs.py` are arguments of the executable. You have to tell the IDE the path to the executable and its arguments. Related: https://stackoverflow.com/questions/3758794/how-do-i-use-gdb-in-eclipse-for-c-c-debugging/64647640#64647640 – Ciro Santilli Nov 02 '20 at 14:42