Find the answer to your Linux question:
Results 1 to 6 of 6
Like Tree1Likes
  • 1 Post By drl
HI Friends! I would like to know if there is a tool to know the trace of instructions of a program once it has finished. I know I can debug ...
  1. #1
    Just Joined!
    Join Date
    Nov 2009
    Posts
    72

    trace of instructions of a C program

    HI Friends!

    I would like to know if there is a tool to know the trace of instructions of a program once it has finished. I know I can debug with gdb as the program is executing, but I am using ncurses and it is very difficult.

    Thank you very much!

  2. #2
    Trusted Penguin Cabhan's Avatar
    Join Date
    Jan 2005
    Location
    Seattle, WA, USA
    Posts
    3,230
    It depends on what you mean by "trace of instructions".

    You can have your programs produce a core dump file if they crash, and feed this into gdb to see what their state was when they crashed.

    If you're only interested in system calls, you can use strace to get a log of all the system calls made by a program.
    DISTRO=Arch
    Registered Linux User #388732

  3. #3
    Just Joined!
    Join Date
    Nov 2009
    Posts
    72
    HI Cabhan! Thanks for reply.

    I am not interested in system calls. I want to know the trace of instructions of a C program, once it has finished, regardless the program crashes or not.

    Maybe there is a way to save the executed instructions in a file, but I don't know how to do it.

    Thank you very much!!!

  4. #4
    Just Joined! pieman's Avatar
    Join Date
    Jan 2012
    Location
    Sunny Yorkshire
    Posts
    11
    Do you mean you want to produce log information to show what functions have been called and it what order etc.? If so, you probably want to look at syslog.

    For more info, look at "man 3 syslog"
    Last edited by pieman; 01-25-2012 at 09:12 PM. Reason: Added man page

  5. #5
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
    Posts
    8,974
    This is not a built-in C/C++ programming feature. You have to create/utilize appropriate trace functions/macros yourself. I have done this for major software systems that run most of the semi-conductor fabs in the world. You want to enable different levels of tracing, depending upon the situation (too high a level will seriously impact performance), by seeing a system variable at runtime. If you are using C++, then you can add the appropriate macro at the entrance to a function for the enter-trace, and when the function exits, scoping will cause the exit-trace to be emitted as necessary. This is very useful for complex systems, but unfortunately there are no standards for this behavior... It is a "do it as you need" scenario...
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  6. #6
    drl
    drl is offline
    Linux Engineer drl's Avatar
    Join Date
    Apr 2006
    Location
    Saint Paul, MN, USA / CentOS, Debian, Solaris, SuSE
    Posts
    1,117
    Hi.
    Quote Originally Posted by jesusitoLinux View Post
    ... I am not interested in system calls. I want to know the trace of instructions of a C program, once it has finished, regardless the program crashes or not ...
    Just so we understand, you run the executable from a C code, and for every instruction that is executed in user-space, you want that instruction written to a disk file, is that correct?

    You don't want any register data, just the instruction.

    I think the only way to do this is with an emulator, which will essentially interpret the code, and write data to your trace file as it happens.

    Right off-hand, that sounds like a very long disk file will be created, and the execution will be very slow. I suppose there might be some hardware instruction to interrupt at each instruction so that a trap routine could be called, but I don't know enough of the X86 hardware to be able to confirm that.

    Perhaps you should step back and tell us what it is that you are trying to do, and why you think you need this trace file ... cheers, drl
    Rubberman likes this.
    Welcome - get the most out of the forum by reading forum basics and guidelines: click here.
    90% of questions can be answered by using man pages, Quick Search, Advanced Search, Google search, Wikipedia.
    We look forward to helping you with the challenge of the other 10%.
    ( Mn, 2.6.n, AMD-64 3000+, ASUS A8V Deluxe, 1 GB, SATA + IDE, Matrox G400 AGP )

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...