3

Eg:

/home/gem5/build/X86/gem5.opt --debug-flags=TLB,Cache /home/gem5/configs/example/se.py --cpu-type=DerivO3CPU --caches --mem-type=SimpleMemory -I 10000 -c out --options="1 in_16.txt out.txt" >> test2.txt

The bold part in the SE CLI for Gem5 shows my input to it. How exactly does Gem5 process this and obtain the instructions to be simulated? Which files should I be looking into for this? As far as I know, no tutorials mention this.

Razneesh
  • 1,147
  • 3
  • 13
  • 29
Febin Sunny
  • 311
  • 1
  • 13

1 Answers1

1

out is a regular ELF userland executable, e.g. a C hello world, just like the ones you would run on your Linux host.

Usage of dynamically linked executable is described at: How to run a dynamically linked executable syscall emulation mode se.py in gem5? so generally statically linking is easier.

gem5 parses the ELF format, places memory into the right locations, puts the PC in the right location, and kicks off simulation, just like the exec syscall of the Linux kernel would.

Several runnable examples are available here.

Ciro Santilli
  • 3,693
  • 1
  • 18
  • 44
  • Thanks. But I am familiar with most of the information there. BUT "gem5 parses the ELF format, places memory into the right locations, puts the PC in the right location, and kicks off simulation"-> Which file does this ? I would like to track some specific data flowing through simulation, knowing where exactly the parsing happens would hopefully help me with this. – Febin Sunny Mar 15 '20 at 09:12
  • 1
    @FebinSunny this should be easy to find by grepping for "elf" in the source and tracking how `out` is passed from Python to C++. E.g. `src/base/loader/elf_object.hh`. – Ciro Santilli Mar 15 '20 at 11:41
  • If possible can you tell me how I can distinguish between Arrays and regular variables at assemble level, while debugging ? In ELF files we can clearly see the larger size, I tried to filter them out like that in my simulations, but it doesnt seem to work. Thanks. – Febin Sunny Mar 16 '20 at 08:08
  • @FebinSunny sorry, I'm not sure I understand the question, do you mean when running gem5 through GDB? Can you give a more concrete example of what you want to do? – Ciro Santilli Mar 16 '20 at 12:29
  • Eg: mov 0x2009c8(%rip),%rax – Febin Sunny Mar 16 '20 at 12:30
  • The above line was generated by objdump from ELF. I know the example above shows a array, because I have access to the ELF file and I also have metadata info. But at simulation level, I will not have access to any of the metadata, I can track addresses, but the address within simulation and outside are different, so the only things I can access are probably the instructions and the registers involved.... I can see there are some connections here and there like offsets to registers involved in the instruction, but nothing concrete. – Febin Sunny Mar 16 '20 at 12:34
  • @FebinSunny understanding the guest from gem5 tends to be hard. I'm not sure what you want to achieve. Maybe consider asking another question with more details. Also consider the gem5 GDB stub if that may help (allows you to debug guest code with GDB from host). – Ciro Santilli Mar 16 '20 at 13:24
  • You can use the exec trace feature along with a debugger to figure out where your array is in the memory image. You will need to ensure that your executable (and/or libraries) have debug symbols. If the debug symbols are available, the exec trace should show symbol names. You can correlate these to gdb output. You should be able to figure out how to enable gdb debugging of a simulated application with a few google searches. You'll want to run the simulator and wait for a remote-gdb connection. After remote-gdb instance is connected, you'd set a breakpoint on the array and check output. – Brandon Potter Jun 10 '20 at 23:42