Saying that I have a very simple C program test.c, which just prints "hello world", its name is a.out coming from gcc test.c.

I'm thinking if it's possible to monitor exactly what happened while running the a.out. For example, I want to know exactly how many bytes are used for a.out, what is happening in each cell memory (8-bit) used by a.out etc.

Well, I just want to get a stuff like this:
at this moment, the memory of address 0X00001234 is storing 00001001;
at the next moment, the memory of address 0X00001236 is putting its value to cache...

It sounds like using GDB to execute step by step. But for me, I have only an executable binary. I need a way to test it, instead of debugging.


You can compile the program with debugging info included using the -g option. gdb will follow then the source code, and when running step-by-step with display the proper lines from the source code if the corresponding source .c file(s) are present.

The gdbinterface will also allow you to inspect the corresponding memory position of variables present on the source code.

I also would not use test for a binary name as it conflicts with pre-existing directives.

gcc -g mytest.c -o mytest 

-g tells the compiler to store symbol table information in the executable. Among other things, this includes:

  • symbol names
  • type info for symbols
  • files and line numbers where the symbols came from

see How Does The Debugging Option -g Change the Binary Executable?

see also my related answer Understanding what a Linux binary is doing

| improve this answer | |
  • 1
    I'm reading your wonderful answer. In fact I'm a tester for Linux. Normally what I get is just a binary file. I think the binary file that I get is compiled without -g. – Yves Jan 25 '18 at 13:59
  • How come tester? – Rui F Ribeiro Jan 25 '18 at 14:02
  • Well, I'm testing the performance of system while executing some executable binary file. Normally I use some commands and tools to do so such as perf. Today I'm thinking if I can test deeper than these tools... This is why I post this question. – Yves Jan 25 '18 at 14:16
  • Google Amazon, Systems Performance: Enterprise and the Cloud, Brendan Gregg. This last comment is less confusing than your question. Brendan Dtrace book is also a related good read, but sadly dtrace in Linux is a pain on the neck. – Rui F Ribeiro Jan 25 '18 at 14:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.