473,320 Members | 1,722 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

how to produce trace of C program?

kj


Is there any good way to produce a trace of a running C program
analogous to what one gets with "sh -x" or "perl -dS"? (I work on
Linux.)

I imagine that, if such trace is possible, it would have to be a
feature of the compiler, but I was not able to find anything like
it in the manpage for mine (gcc 3.0).

TIA,

kj

--
NOTE: In my address everything before the period is backwards.
Nov 14 '05 #1
4 16476
"kj" <so***@987jk.com> wrote in message
news:c9**********@reader2.panix.com...


Is there any good way to produce a trace of a running C program
analogous to what one gets with "sh -x" or "perl -dS"? (I work on
Linux.)

I imagine that, if such trace is possible, it would have to be a
feature of the compiler, but I was not able to find anything like
it in the manpage for mine (gcc 3.0).
This question is off-topic. This newsgroup deals only with the standard C
language, not specific compilers and operating systems.

However, what you're looking for is probably gdb. Compile your programs with
the -g flag to gcc, then a gdb session might look like this:

$ gdb ./program
(gdb) break main
Breakpoint 1 at 0x804925c
(gdb) run
Starting program: ./program
Breakpoint 1, 0x804925c in main ()
(gdb) next

etc.

You could also look into strace if you specifically need to attach to an
already-running program, although this will only give you details on system
calls that're being used.
TIA,

kj

--
NOTE: In my address everything before the period is backwards.

Nov 14 '05 #2
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

In comp.lang.c, kj (so***@987jk.com) wrote:
Is there any good way to produce a trace of a running C program
analogous to what one gets with "sh -x" or "perl -dS"? (I work on
Linux.)


Perhaps strace can do what you want?

Regards.

- --
My real e-mail address: chema (AT) chema.homelinux.org
http://EuropeSwPatentFree.hispalinux.es - EuropeSwPatentFree
I don't read HTML posts / No leo mensajes en HTML
Blog Overflow: http://chema.homelinux.org
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)

iD8DBQFAw22P9P6GbSlI+hkRAp7dAKCXnw54M4E8XGlCn0DLxI oWcn4u+gCgkxwv
/Oj2m0Na+aAOd4HDVBa26tI=
=DMXJ
-----END PGP SIGNATURE-----
Nov 14 '05 #3
kj wrote:
Is there any good way to produce a trace of a running C program
analogous to what one gets with "sh -x" or "perl -dS"? (I work on
Linux.)

There is a very big difference in the seemingly similar analogy that
you are making - which is that = sh and perl are interpreter , where C
is compiled.
Having said that, you have to decide what is it primarily that you
want to trace. As Kieran had pointed out already, you can use 'gdb' or
the debugger on your platform to trace the values of variables, function
stack ( bt command in gdb ) etc.
I imagine that, if such trace is possible, it would have to be a
feature of the compiler, but I was not able to find anything like
it in the manpage for mine (gcc 3.0).


The best place to look for it is the GNU Debugger manual and not the
compiler. Probably the only thing you need to take from the compiler
manual is that , you need to compile with the debugging switch on, for
the debugger to load the name symbols from the exec.

HTH
--
Karthik.
Humans please 'removeme_' for my real email.
Nov 14 '05 #4
kj wrote:

Is there any good way to produce a trace of a running C program
analogous to what one gets with "sh -x" or "perl -dS"? (I work on
Linux.)

I imagine that, if such trace is possible, it would have to be a
feature of the compiler, but I was not able to find anything like
it in the manpage for mine (gcc 3.0).


You might want to see if `ctrace' is available
on your platform...
DESCRIPTION
The ctrace command allows the user to monitor the sequential
execution of a C program as each program statement executes.
The effect is similar to executing a shell procedure with
the -x option.

...
-
Stephen
Nov 14 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Aaron | last post by:
this is what I want to do. i have an input box and a submit button. the input gets processed by my program and it returns the results. depending on the input, not all the functions in my program...
2
by: scsharma | last post by:
Hi, I am having trouble with following piece of code: Trace.Assert(args.Length >=1,"Invalid Argument list. Statement Date is mandatory input"); I expect the code to stop execution and exit...
9
by: svenn.are | last post by:
Hi, has anybody thought of / already used graphviz to convert the output of trace.py into a graph? I looked at PyUMLGraph, but 1. PyUMLGraph does not successfully create a dot file, and 2. I...
0
by: Raquel | last post by:
UDB PE 8.1 on Win XP. Per the manual: DB2 JDBC traces always begin with a header that lists important system information such as key environment variable settings, the JDK or JRE level, the...
0
by: Joerg Schoen | last post by:
Hi folks! "JSCPP" is a ANSI-C preprocessor and language parser. It can analyze or instrument C-code. The most prominent application currently is to add function trace calls to existing C...
2
by: Richard | last post by:
Hi, I'm having trouble setting up a config file based trace switch & listener. I added an application config file to my console based C# program using the "Add New Application Config File" button...
4
by: Jazz | last post by:
Hello, I have a question about trace as MSDN seems confuses me.(http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemDiagnosticsTraceClassTopic.asp). My answer...
0
by: djaquay | last post by:
I've been using trace.py to get code coverage results for my unit tests, and like it. Now I'm trying to use it for code coverage of the GUI parts of my wxPython-based program, and I realized how...
3
by: | last post by:
If this is simple, forgive my ignorance, but I'm coming from the CompactFramework where we don't use AppDomains. I did a fair bit of archive searching and couldn't find an answer and I got no...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.