Difference between revisions of "Developing for the new chart module"
(Just removed the unnecessary linkage against tools in the model :-)) |
(→The common steps: - removed obsolete text) |
||
Line 1: | Line 1: | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
Revision as of 17:01, 22 May 2007
Contents
Coding
the essentials
print, assert and debug helpers
When you start developping, you will certainly need to trace your program. For this, debuggers are really useful, but what is often used is to inserted functions like printf() that will send messages. How do those things work in OpenOffice.org ? Well there are quite a few ways to echo strings.
the standard functions
The first one is to use the classical "printf" and "fprintf" functions :
[cpp,N]
- include <stdio.h>
int foo() {
printf( "Foo\n" ); fprintf( stderr, "foo\n" );
}
For the ones loving C++, the second way is to use the iostreams :
[cpp,N]
- include <iostream>
int foo() {
std::cerr << "coucou" << std::endl; std::cout << "coucou" << std::endl;
}
As two ways of doing things is not enought, you will find a few macros. There are two kinds of such macros, the OSL macros and the DGB macros.
The OSL functions
The OSL_ things are intended to be used permanently, not for debugging only. I.e., when you would cassert() you should OSL_ASSERT() (or ENSURE).
- OSL_TRACE( "text" )
- OSL_ENSURE( condition, "text" )
- OSL_ASSERT( condition )
"For printf debugging you can also use OSL_TRACE( "Bla" ); On Linux, this prints to stdout (or stderr), so you should see it on the console, as long as the file was compiled with debug=t.
OSL_ASSERT( condition ) and OSL_ENSURE( condition, "text" ) also print to stderr on Linux, but they pop up a window on Windows )"
Here are some examples and how to use those three functions :
OSL_TRACE example
[cpp,N]
- ifndef _OSL_DIAGNOSE_H_
#include <osl/diagnose.h>
- endif
[...]
int foo() {
OSL_TRACE( "My first trace" );
}
And the result should look like :
$ ./myfoo Thread: 1 :My first trace
OSL_ENSURE example
[cpp,N]
- ifndef _OSL_DIAGNOSE_H_
#include <osl/diagnose.h>
- endif
[...]
int foo() {
// Will not be displayed. OSL_ENSURE( true, "here I truly gooooo!!" );
// Will be displayed. OSL_ENSURE( false, "here I gooooo!!" );
// #if OSL_DEBUG_LEVEL > 2 OSL_ENSURE( true, "here I gooooo if level is set to 3!" ); #endif
}
And the result should look like :
$ ./myfoo Error: File /home/pagalmes/workspace/chart2_m172/src680-m172/chart2/source/controller/main/ChartController.cxx, Line 1201: here I gooooo!! Backtrace: [0] /home/pagalmes/workspace/chart2_m172_exec/OpenOffice/opt/openoffice.org2.0/program/libchartcontroller680li.so: ???+0x4ac0e Backtrace: [1] /home/pagalmes/workspace/chart2_m172_exec/OpenOffice/opt/openoffice.org2.0/program/libchartcontroller680li.so: ???+0x4b73b Backtrace: [2] /home/pagalmes/workspace/chart2_m172_exec/OpenOffice/opt/openoffice.org2.0/program/libchartcontroller680li.so: ???+0x573b5 Backtrace: [3] /home/pagalmes/workspace/chart2_m172_exec/OpenOffice/opt/openoffice.org2.0/program/libchartcontroller680li.so: ???+0x43964 [...]
OSL_ASSERT example
[cpp,N]
- ifndef _OSL_DIAGNOSE_H_
#include <osl/diagnose.h>
- endif
[...]
int foo() {
bool test; test = true;
OSL_TRACE( "test is true." ); OSL_ASSERT( test );
test = false;
OSL_TRACE( "test is false." ); OSL_ASSERT( test );
}
And the result should look like :
Thread: 1 :test is true. Thread: 1 :test is false. Error: File /home/pagalmes/workspace/chart2_m172/src680-m172/chart2/source/controller/main/ChartController.cxx, Line 1202 Backtrace: [0] /home/pagalmes/workspace/chart2_m172_exec/OpenOffice/opt/openoffice.org2.0/program/libchartcontroller680li.so: ???+0x452db Backtrace: [1] /home/pagalmes/workspace/chart2_m172_exec/OpenOffice/opt/openoffice.org2.0/program/libchartcontroller680li.so: ???+0x47361 Backtrace: [2] /home/pagalmes/workspace/chart2_m172_exec/OpenOffice/opt/openoffice.org2.0/program/libchartcontroller680li.so: ???+0x56899 [...]
the DBG functions
- DBG_ASSERT()
- DBG_ERROR()
DBG_ASSERT() and DBG_ERROR() need the tools library (the tools project not the lib in chart2). Therefore I try to avoid it if a library is not linked against tools anyway.
The model lib is not linked against tools. However, for consistency, in all libraries the OSL_ functions should be used rather than the DBG_ functions.