debugging - help

K

kbc

Hi,

I am programming in C.

( You know that __FILE__ is a 'macro' which may be used to print
debug messages. )
3 questions :

a) I have 10000 functions in my project. I am interested in 100
of them.
Whenever any of them are entered, I want a message printed saying the
same. ( such as "function foo_bar entered." when entering
foo_bar )

What is the least effort way of doing this ? I hate to edit the
individual functions. They are too many.

b) Given a function address, can any compiler tricks be used to
print the associated function name ( without manually putting the
name in the
source code ) ? ( I know that map file will give it, but i am looking
for
an automatic way of doing this at runtime itself. )

c) Any good website or book for info related to debugging code
execution ??

thanks
shankar
 
X

xarax

This is likely off-topic, because a solution would
be implementation specific (like using a compiler
switch to generate instrumentation code at the
function entry/exit).
 
H

Hans-Bernhard Broeker

In comp.arch.embedded kbc said:
a) I have 10000 functions in my project. I am interested in 100 of
them. Whenever any of them are entered, I want a message printed
saying the same. ( such as "function foo_bar entered." when
entering foo_bar )
What is the least effort way of doing this ? I hate to edit the
individual functions. They are too many.

You're making it hard to help you by not mentioning what your target
platform is. Such hacks are highly platform-specific.

Get yourself a good debugger. Keep your fingers crossed that your
target platform can handle 100 breakpoints simultaneously. Set a
breakpoint at each of those 100 functions, instrumented to print that
message. Run and watch.
b) Given a function address, can any compiler tricks be used to
print the associated function name ( without manually putting the
name in the source code )?

Certainly not by _compiler_ tricks --- the compiler doesn't even know
where the function's will eventually end up being located. Only the
linker knows that.

The linker usually does offer a trick to achieve that: it's called
"debug information". But none of that is usually available at run
time, if only because debug info is invariably stripped off the image
before you actually put into the embedded device.
 
W

Walter Banks

Most of the Byte Craft compilers have a switch in them to emit break point information in the source level debug environment to track execution through the control path of the program (calls, jumps and conditionals). The execution information can be used
to validate formal execution regression tests and track performance of the system and is compatible with testing methodology of McCabe and others.

By involving the debug environment in the reporting process there is no execution overhead and the instrumented code is the same object code that is shipped with the application.

Walter Banks
Byte Craft Limited
//http:www.bytecraft.com
 
D

David Brown

kbc said:
Hi,

I am programming in C.

( You know that __FILE__ is a 'macro' which may be used to print
debug messages. )
3 questions :

a) I have 10000 functions in my project. I am interested in 100
of them.
Whenever any of them are entered, I want a message printed saying the
same. ( such as "function foo_bar entered." when entering
foo_bar )

If you are using gcc and gnu ld, then you can get ld to "wrap" all calls to
a given function. You need to write an extra module that has the wrap
functions (which would print out the function name or other information,
then call the original function). It might be a bit tedious to write 100
wrap functions, but a couple of perl/python/awk scripts and/or a text editor
with good keyboard macros can handle the donkey work.

An alternative might be to look at using profiling information to track
function calls, assuming you have a compiler that supports profiling.
 
M

Michael Str.

Hi,

I am programming in C.

( You know that __FILE__ is a 'macro' which may be used to print
debug messages. )
3 questions :

a) I have 10000 functions in my project. I am interested in 100
of them.
Whenever any of them are entered, I want a message printed saying the
same. ( such as "function foo_bar entered." when entering
foo_bar )

What is the least effort way of doing this ? I hate to edit the
individual functions. They are too many.

If i understand, you know what are these '100' functions. First of
all, if you
work with big project and have to debug it - use good Editor ( such as
CodeWrite or MultiEdit ). So, you can use regular expressions and
macro for inserting these printings.
b) Given a function address, can any compiler tricks be used to
print the associated function name ( without manually putting the
name in the
source code ) ? ( I know that map file will give it, but i am looking
for
an automatic way of doing this at runtime itself. )

Generally, as people already said, at runtime you don't know
functions' names.
Besides, here, you don't say that you want to do it when entering
function,
right ? So, without appropriate instrumentation tools, you cannot do
it.
c) Any good website or book for info related to debugging code
execution ??

Did you search it on Internet ?
 
K

kbc

thanks for all replies.

i am executing on Armulator using AXD debugger.

What i have is an array of function pointers which get periodically
filled up. I parse this array each time, calling the functions
indexed by the pointer. I would like to print the name of the function
before calling it.

I dont want to put breakpoints.

__FUNCTION__ will help only in printing from within the function.

shankar
 
H

Hans-Bernhard Broeker

In comp.arch.embedded kbc said:
thanks for all replies.
i am executing on Armulator using AXD debugger.
What i have is an array of function pointers which get periodically
filled up. I parse this array each time, calling the functions
indexed by the pointer.

Ah! Now that's a whole different situation than what your original
description sounded like. The trick is simple, in this case: make
that array store (pointers to) structures with two elements: the
function pointer and the name of the function itself. Both can easily
be generated in a single mention of the function name by use of the
preprocessor:

typedef struct named_function {
func_ptr p;
const char *name;
} named_function;

#define TABLE_ENTRY(name) { name, #name }

named_function action_table[] = {
TABLE_ENTRY(func1),
TABLE_ENTRY(func2)
};

Now all you have to do is print action_table.name just before you
call the function action_table.p.
 
K

kbc

i have no access to the entity which is filling the array. so your
method will not work. ( But i can edit the parser function which
calls the functions pointed by array-elements. )

i guess what i need is a content-addressable array to get the index
given the function address. then i can use that index to print the function
name from another array.
dont know how to do it.


Hans-Bernhard Broeker said:
In comp.arch.embedded kbc said:
thanks for all replies.
i am executing on Armulator using AXD debugger.
What i have is an array of function pointers which get periodically
filled up. I parse this array each time, calling the functions
indexed by the pointer.

Ah! Now that's a whole different situation than what your original
description sounded like. The trick is simple, in this case: make
that array store (pointers to) structures with two elements: the
function pointer and the name of the function itself. Both can easily
be generated in a single mention of the function name by use of the
preprocessor:

typedef struct named_function {
func_ptr p;
const char *name;
} named_function;

#define TABLE_ENTRY(name) { name, #name }

named_function action_table[] = {
TABLE_ENTRY(func1),
TABLE_ENTRY(func2)
};

Now all you have to do is print action_table.name just before you
call the function action_table.p.
 
H

Hans-Bernhard Broeker

In comp.arch.embedded kbc said:
i have no access to the entity which is filling the array. so your
method will not work. ( But i can edit the parser function which
calls the functions pointed by array-elements. )

But there's a global table of functions *somewhere* that lists all
functions by name that this "entity" is allowed to put into the array,
right? There really should be, if only to allow a test that there's
no utter nonsense put into the command array.

If that exists, you still are left with two possibilities:
automatically generate wrapper functions for all those functions that
just print the name of the function about to be called, then call it.
Then put those wrappers in the action table, not the actual functions
themselves.
i guess what i need is a content-addressable array to get the index
given the function address.

Just use a (pointer + stringified name) table like the one I proposed,
sort it by function pointer, and binary-search through it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,102
Messages
2,570,645
Members
47,247
Latest member
GabrieleL2

Latest Threads

Top