4

I am going crazy with gem5. When I run a program that just outputs "Hello, world". Only set debug=Exec in gem5. I saw the operation of thousands of lines of assembly instructions. How can I only see the execution process of my own code?

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

1 Answers1

1

Is running ExecAll which enables ExecSymbol which shows the current function name good enough? E.g. with this I see the first instruction on main as:

58852000: system.cpu: A0 T0 : 0x3fffd94f70 @__end__+274871107384    :   blr   x3                 : IntAlu :  D=0x0000003fffd94f74  flags=(IsInteger|IsControl|IsIndirectControl|IsUncondControl|IsCall)
58852500: system.cpu: A0 T0 : 0x4006f0 @main    : stp 

If you really don't want to log the instructions before main, you can also do a first run that determines the timestamp of the start of main (58852500 on the above run) and then use:

gem5.opt --debug-start=58852500

I don't know any method that does not require an initial run to determine the timestamp. It would be cool to add something to gem5 that enables logging based on the symbol name, I've wanted that before.

Ciro Santilli
  • 3,693
  • 1
  • 18
  • 44
  • Thank you for your answer. That is very useful. But I feel very confused, what is the use of those instructions before the main function? Does gem5 require thousands of instructions for initialization? – Gerrie Sep 28 '20 at 03:16
  • @cyj gcc + glibc adds them to every executable by default, it is not gem5 specific, see e.g.: https://electronics.stackexchange.com/questions/258896/what-happens-before-main I don't know exactly the function of it, but it must be setting up something gcc/glibc relies on. With `-static` you get less instructions because the dynamic linker does not run, but you still get a a few hundred thousand I think. – Ciro Santilli Sep 28 '20 at 12:52
  • @cyj you can remove them with some GCC options, e.g. You can remove them in a freestanding program, e.g. https://github.com/cirosantilli/linux-kernel-module-cheat/blob/b3401b61ed052440860adad98eb8e0826cafe9d0/userland/arch/aarch64/freestanding/linux/hello.S but then I'm not sure if every glibc functionality will still work as some of its setup was removed. – Ciro Santilli Sep 28 '20 at 12:52