473,748 Members | 2,417 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

debug mode

To help me debug, I am writing a lot of information into a stream which
I call debug.

However, because of the large amount of time taken to print this
information, I only want this printed while I am in debugging mode as
indicated by a preprocessor directive:

#define DEBUG

In other words, I need code which says "Whenever I write debug <<
...... I only want that command executed if I am in debug mode. "

In other words, I want code that always interprets statements of the
form:

debug << x << endl;

as #ifdef DEBUG debug << x << endl; (without typing #ifdef DEBUG
each time.)

So how do I do this? Is there some command that says "Open a stream
for debug mode only?"
Thank you,

Paul Epstein

Jan 19 '06 #1
6 3664
pa**********@at t.net wrote:
To help me debug, I am writing a lot of information into a stream
which I call debug.

However, because of the large amount of time taken to print this
information, I only want this printed while I am in debugging mode as
indicated by a preprocessor directive:

#define DEBUG

In other words, I need code which says "Whenever I write debug <<
..... I only want that command executed if I am in debug mode. "

In other words, I want code that always interprets statements of the
form:

debug << x << endl;

as #ifdef DEBUG debug << x << endl; (without typing #ifdef DEBUG
each time.)

So how do I do this? Is there some command that says "Open a stream
for debug mode only?"


You could define your 'debug' differently depending on whether the
DEBUG macro is defined or not. Something like

#ifdef DEBUG
myostream debug; // line 133
#else
nullstream debug;
#endif

I don't know what your 'debug' is in reality, that's why on line 133
'myostream' is used (I don't know what to use, you do). As to the
other, non-DEBUG portion, look "nullstream " on the Web. There is
probably a way to define a stream that simply eats everything without
any side effect.

V
Jan 19 '06 #2
"Victor Bazarov" <v.********@com Acast.net> wrote in message
news:Q6******** ************@co mcast.com
pa**********@at t.net wrote:
To help me debug, I am writing a lot of information into a stream
which I call debug.

However, because of the large amount of time taken to print this
information, I only want this printed while I am in debugging mode
as indicated by a preprocessor directive:

#define DEBUG

In other words, I need code which says "Whenever I write debug <<
..... I only want that command executed if I am in debug mode. "

In other words, I want code that always interprets statements of the
form:

debug << x << endl;

as #ifdef DEBUG debug << x << endl; (without typing #ifdef DEBUG
each time.)

So how do I do this? Is there some command that says "Open a stream
for debug mode only?"


You could define your 'debug' differently depending on whether the
DEBUG macro is defined or not. Something like

#ifdef DEBUG
myostream debug; // line 133
#else
nullstream debug;
#endif

I don't know what your 'debug' is in reality, that's why on line 133
'myostream' is used (I don't know what to use, you do). As to the
other, non-DEBUG portion, look "nullstream " on the Web. There is
probably a way to define a stream that simply eats everything without
any side effect.

V


How about this?

#include <string>

struct nullstream
{
template<class T>
nullstream & operator<<(cons t T& t)
{
return *this;
}
};
int main()
{
nullstream ns;

ns << 10 << 5.076 << "string literal" << std::string("st d::string
temp") << '\n';

return 0;
}
--
John Carson
Jan 19 '06 #3
"Victor Bazarov" <v.********@com Acast.net> wrote in message
news:Q6******** ************@co mcast.com
pa**********@at t.net wrote:
To help me debug, I am writing a lot of information into a stream
which I call debug.

However, because of the large amount of time taken to print this
information, I only want this printed while I am in debugging mode
as indicated by a preprocessor directive:

#define DEBUG

In other words, I need code which says "Whenever I write debug <<
..... I only want that command executed if I am in debug mode. "

In other words, I want code that always interprets statements of the
form:

debug << x << endl;

as #ifdef DEBUG debug << x << endl; (without typing #ifdef DEBUG
each time.)

So how do I do this? Is there some command that says "Open a stream
for debug mode only?"


You could define your 'debug' differently depending on whether the
DEBUG macro is defined or not. Something like

#ifdef DEBUG
myostream debug; // line 133
#else
nullstream debug;
#endif

I don't know what your 'debug' is in reality, that's why on line 133
'myostream' is used (I don't know what to use, you do). As to the
other, non-DEBUG portion, look "nullstream " on the Web. There is
probably a way to define a stream that simply eats everything without
any side effect.

V


To have zero runtime cost in release mode, an alternative (at the cost of
some extra typing) is:

#ifdef _DEBUG
#define D(x) x
#else
#define D(x)
#endif

int main()
{
int x = 5;
D(debug << x << endl;)
return 0;
}
--
John Carson
Jan 19 '06 #4
pa**********@at t.net wrote:
To help me debug, I am writing a lot of information into a stream which
I call debug.

However, because of the large amount of time taken to print this
information, I only want this printed while I am in debugging mode as
indicated by a preprocessor directive:

#define DEBUG

In other words, I need code which says "Whenever I write debug <<
..... I only want that command executed if I am in debug mode. "

In other words, I want code that always interprets statements of the
form:

debug << x << endl;

as #ifdef DEBUG debug << x << endl; (without typing #ifdef DEBUG
each time.)


A quick and imperfect solution is to

#ifdef DEBUG
#define debug (std::cerr)
#else
#define debug if(0) (std::cerr)
#endif

// ...
debug << "This will only be printed if DEBUG is defined".

HTH,
- J.
Jan 19 '06 #5
pa**********@at t.net wrote:
To help me debug, I am writing a lot of information into a stream
which I call debug.

However, because of the large amount of time taken to print this
information, I only want this printed while I am in debugging mode as
indicated by a preprocessor directive:

#define DEBUG

In other words, I need code which says "Whenever I write debug <<
..... I only want that command executed if I am in debug mode. "

In other words, I want code that always interprets statements of the
form:

debug << x << endl;

as #ifdef DEBUG debug << x << endl; (without typing #ifdef DEBUG
each time.)

So how do I do this? Is there some command that says "Open a stream
for debug mode only?"

One common way is to create a function-like macro that can be switched
on and off.

#ifdef DEBUG
#define DEBUG_REPORT(x) \
do {debug << x << endl} while (0)
#else
#define DEBUG_REPORT(x)
#endif
The do {} while(0) is a method to create a block on the fly that will
be terminated with a ; so you could have multiple statements within it
if you wanted.
It's used like this:
DEBUG_REPORT(va lue);
When you're not in debug, the macro is a no-op.
Brian
Jan 19 '06 #6

<pa**********@a tt.net> wrote in message
news:11******** **************@ g14g2000cwa.goo glegroups.com.. .
To help me debug, I am writing a lot of information into a stream which
I call debug.

However, because of the large amount of time taken to print this
information, I only want this printed while I am in debugging mode as
indicated by a preprocessor directive:

#define DEBUG

In other words, I need code which says "Whenever I write debug <<
..... I only want that command executed if I am in debug mode. "

In other words, I want code that always interprets statements of the
form:

debug << x << endl;

as #ifdef DEBUG debug << x << endl; (without typing #ifdef DEBUG
each time.)

So how do I do this? Is there some command that says "Open a stream
for debug mode only?"
Thank you,

Paul Epstein


This is how I handle it, although I have the extra overhead of a function
call.

void LogDebug( const std::string& Message )
{
#ifndef LOGDEBUG
return;
#endif
static std::ofstream LogDebugFile("D ebugLog.log");
if (LogDebugFile.i s_open())
{
LogDebugFile << Message << std::endl;
}
}
Jan 22 '06 #7

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

Similar topics

3
3371
by: Mike C. Fletcher | last post by:
Every few months I get to working on a Python C extension (built with distutils) and discover a pointer error or the like where I'd like to be able to step into my DLL and see where the extension is going wonky. Now, the "proper" way to debug a DLL is apparently to build Python in debug mode (i.e. with the _d form dll), then build each and every extension I depend on (in debug mode), and then build each of my own extensions in debug...
3
3524
by: Max M. Power | last post by:
How can I tell if my C# code is running in debug mode? I need to execute some extra code only when my project has been compiled in debug mode. In release mode I don't want to execute this extra code. I was looking for something simple I could test like: #if DEBUG do_extra_code #endif
12
3419
by: nospam | last post by:
All the documentation says that leaving an ASP.NET application in debug mode has a big performance hit. I can't detect any difference between debug and non-debug modes. Am I missing something or is the documentation wrong? I've been load testing an ASP.NET website (built in VS.NET 2003 in C#). I've used the ACT to generate heavy loads over several minutes. Debug or no debug produces almost identical performance results.
7
2914
by: Srinivasa Rao | last post by:
I have read in one article that when we compile the application in release mode, all the debug classes and properties will be automatically removed from the code. I tried to implement this thing by using the following code in Page_Load event handler. Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim intcount As Integer intcount = 0 For intcount = 0 To 4
3
1958
by: Rena | last post by:
Hi all, I have created a app. project and a library which will be used by the main project, however i do not know how to get into debug mode inside the library, although break point is set. is there anywhere to enable the debug mode into library class. thanks rena.
3
4034
by: Haldun ALIML | last post by:
Suppose that you have below property in some class, #if DEBUG public string DebugInfo { get { return "INDEX : " + _name + "\n" + "Index Owner : " + _owner.Name + "\n" + "Index Column Count: " + _columns.Count + "\n"; }
2
2707
by: Dave Johansen | last post by:
I just converted a solution from Visual Studio 2003 to Visual Studio 2005 and the Debug mode seems to be running just fine, but the Release mode crashes on the following code: std::ifstream in("myfile.txt"); float value; in >value; //The crash happens here in the getloc() function The above code is actually from a library built in Debug mode that is linked into the Release build of the executable. Does anyone have any
0
1739
by: =?Utf-8?B?SmVmLnB0Yw==?= | last post by:
Hi, I am currently facing exactly the same issue with Visual Studio 2005. Did you find a way to solve this problem ? "AntonioSACE" wrote:
3
3379
by: =?Utf-8?B?bG10dGFn?= | last post by:
We have developed a number of different applications (ASP.NET web site, Windows services, DLLs, Windows forms, etc.) in C# 2.0. We have developed and unit tested all these applications/components using Debug mode. Now we are ready to compile everything for release to production. However, we don’t know whether we should compile all the applications/components/assemblies using Release mode (or keep everything in Debug mode). We’ve...
0
8995
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8832
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9253
tracyyun
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8250
agi2029
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6798
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4879
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3316
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2791
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2216
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.