1

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.

4
  • 1
    perf mem maybe, or rr, or a recording emulator (QEMU in tracing mode)... (Just passing by, if no one else gets rounds to it I’ll write something up in more detail later.) Commented Jan 25, 2018 at 16:33
  • 1
    @Yves, you might like this one too unix.stackexchange.com/questions/419697/… Commented Jan 26, 2018 at 12:12
  • @StephenKitt What is rr? Commented Jan 26, 2018 at 12:13
  • @Rui, see the rr web site — available as rr in Debian & co. (Guess who packages it...) Commented Jan 26, 2018 at 12:27

1 Answer 1

0

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

4
  • 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. Commented Jan 25, 2018 at 13:59
  • How come tester? Commented Jan 25, 2018 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. Commented Jan 25, 2018 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. Commented Jan 25, 2018 at 14:22

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.