Here is a code to have a debug printf :
#ifdef DEBUG
#define DEBUG_printf(...)
{printf("[%s]:",__FUNCTION__);printf(__VA_ARGS__);printf("\n"); }
#else
#define DEBUG
#endif
int main () {
DEBUG_printf ("%d %s", 5, "abc");
}
Is there something similar, which can print the current stack ?
I mean some C/C++ API which can help me get any info related to the
current stack of functions.
Thats is required for debugging.
(Please do not suggest gdb... I want something similar to gdb stack
traces but that should print stack info everytime I compile with DEBUG
on) 4 11367
call_me_anything wrote:
Here is a code to have a debug printf :
#ifdef DEBUG
#define DEBUG_printf(...)
{printf("[%s]:",__FUNCTION__);printf(__VA_ARGS__);printf("\n"); }
#else
#define DEBUG
#endif
int main () {
DEBUG_printf ("%d %s", 5, "abc");
}
Is there something similar, which can print the current stack ?
I mean some C/C++ API which can help me get any info related to the
current stack of functions.
Thats is required for debugging.
(Please do not suggest gdb... I want something similar to gdb stack
traces but that should print stack info everytime I compile with DEBUG
on)
Not built in, but it's fairly easy to add:
#include <ostream>
class stack_tracer
{
public:
stack_tracer(const char *where) : where_(where), next_(top())
{
top() = this;
}
~stack_tracer()
{
top() = next_;
}
static std::ostream& dump(std::ostream& os)
{
for (stack_tracer* curr = top();
curr != NULL;
curr = curr->next_)
{
os << curr->where_ << '\n';
}
return os;
}
private:
static stack_tracer*& top()
{
static stack_tracer* top_ = 0;
return top_;
}
stack_tracer *next_;
const char *where_;
};
#define TRACE3(mark, ln, txt) stack_tracer mark ## ln ## _(txt)
#define TRACE2(ln, txt) TRACE3(st_, ln , txt)
#define TRACE(txt) TRACE2(__LINE__,txt)
#include <iostream>
int f()
{
TRACE("f");
if (true)
{
TRACE("If block in f()");
stack_tracer::dump(std::cout) << std::endl;
}
}
int main()
{
TRACE("main");
stack_tracer::dump(std::cout) << std::endl;
f();
}
call_me_anything wrote:
Here is a code to have a debug printf :
#ifdef DEBUG
#define DEBUG_printf(...)
{printf("[%s]:",__FUNCTION__);printf(__VA_ARGS__);printf("\n"); }
#else
#define DEBUG
#endif
int main () {
DEBUG_printf ("%d %s", 5, "abc");
}
Is there something similar, which can print the current stack ?
I mean some C/C++ API which can help me get any info related to the
current stack of functions.
Thats is required for debugging.
(Please do not suggest gdb... I want something similar to gdb stack
traces but that should print stack info everytime I compile with DEBUG
on)
There are platform specific mechanisms that allow you to get a stack
trace. The Austria C++ "netcabletv" alpha contains a stack trace API
that works on win32 and linux.
On Oct 16, 7:55 pm, call_me_anything <sgiitne...@gmail.comwrote:
Here is a code to have a debug printf :
#ifdef DEBUG
#define DEBUG_printf(...)
{printf("[%s]:",__FUNCTION__);printf(__VA_ARGS__);printf("\n"); }
#else
#define DEBUG
#endif
int main () {
DEBUG_printf ("%d %s", 5, "abc");
}
Is there something similar, which can print the current stack ?
I mean some C/C++ API which can help me get any info related to the
current stack of functions.
Thats is required for debugging.
(Please do not suggest gdb... I want something similar to gdb stack
traces but that should print stack info everytime I compile with DEBUG
on)
Nothing standard. In fact, any solution will be very platform
dependent. (My site has a stack trace class with
implementations for i80x86, 64 bit AMD, and 32 and 64 bit
Sparcs. But you still have to pay attention---changing the
compiler options can change it as well. Still, it might be a
start.)
--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
On Oct 16, 8:20 pm, red floyd <no.s...@here.dudewrote:
call_me_anything wrote:
[...]
Is there something similar, which can print the current stack ?
I mean some C/C++ API which can help me get any info related to the
current stack of functions.
Thats is required for debugging.
(Please do not suggest gdb... I want something similar to gdb stack
traces but that should print stack info everytime I compile with DEBUG
on)
Not built in, but it's fairly easy to add:
For what platform? Which compiler? What compile options?
It's very, very implementation dependent.
#include <ostream>
class stack_tracer
{
public:
stack_tracer(const char *where) : where_(where), next_(top())
{
top() = this;
}
~stack_tracer()
{
top() = next_;
}
static std::ostream& dump(std::ostream& os)
{
for (stack_tracer* curr = top();
curr != NULL;
curr = curr->next_)
{
os << curr->where_ << '\n';
}
return os;
}
private:
static stack_tracer*& top()
{
static stack_tracer* top_ = 0;
return top_;
}
stack_tracer *next_;
const char *where_;
};
#define TRACE3(mark, ln, txt) stack_tracer mark ## ln ## _(txt)
#define TRACE2(ln, txt) TRACE3(st_, ln , txt)
#define TRACE(txt) TRACE2(__LINE__,txt)
#include <iostream>
int f()
{
TRACE("f");
if (true)
{
TRACE("If block in f()");
stack_tracer::dump(std::cout) << std::endl;
}
}
int main()
{
TRACE("main");
stack_tracer::dump(std::cout) << std::endl;
f();
}
Your implementation has two major problems: it requires that
every function use the TRACE macro, it skips functions which
don't use the macro; and it fails radically in a multi-thread
environment.
--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Ian |
last post by:
(Sorry if I have repeated this, it did not appear the first time)
I have the following code on a button. The idea is that when this button is
clicked it prints several reports automatically then...
|
by: Robin Dindayal |
last post by:
Does anyone know how I can print a fully rendered .aspx to the
server's printer? I know that, if I wanted to print to the client's
printer it would be easy (ie. use javascript's window.print()).
...
|
by: Tessa |
last post by:
Is there any security reason why you cannot print to a network printer from
ASP.NET under IIS6 on Windows 2003 server?
I'm using ASP.NET code to print to a server print queue using...
|
by: Daniel Foster |
last post by:
I am trying the javascript window.print function to print a asp.net web page
without much success.
I keep getting the error Stack Overflow on line....
Does anyone have any ideas what might be...
|
by: PengYu.UT |
last post by:
Usually assert only print the current function. But I also need to know
which function called the current function. Is there anyway to make it
print out the whole stack?
Thanks,
Peng
|
by: joshc |
last post by:
In an interview for an embedded software position recently I was asked
to write code, in C, for printing the contents of a linked list
backwards. After a few minutes I came up with the recursive...
|
by: dspfun |
last post by:
Hi,
Is it possible to print the function name of the calling function?
For example, f1() and f2() both calls f3(), in f3() I would like to
print the name of the function calling f3() which...
|
by: JWest46088 |
last post by:
Hey everybody.
I'm having some difficulty. I know how to make a stack in Perl, but I have no idea how to get it to read from a file then print the contents backwards.
Can anybody give me any...
|
by: hank |
last post by:
I have this code here, it converts decimal numbers to binary. There is
one problem. The output is printed 'in reverse' and I have no clue at all
how to solve this problem.
Output of program:
...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |