Education Project/Effort/Math baseline alignment/Debuging starmath

From Apache OpenOffice Wiki
Jump to: navigation, search


Current Build is m245, but m247 should work too

install it wherever ( Desktop is a good option on Mac OS X)


To trace, analyze, understand the issue and fix it, it is mandatory to debug starmath.

For that purpose, we will use the most known tool : the GNU Project debugger, aka gdb' ( included in XCode on Mac OS X ).

For the one discovering gdb, there is online gdb tutorial or another one there

What is the problem ?

all libmath are stripped by default, and you'll have to add the symbols for debugging. Thus you'll have to rebuild starmath, and symlink with the new math libs.

The problem is, since sb71 integration, use symlinks with libs is just a workaround. See [issue 83548 for more information ]

The clean solution : replace libstarmaths* in the bundle after every rebuild

Todo : write a little shell script doing the job ;-)

(workaround) A patch for linkoo

Waiting, the following patch (thanks to Kendy !! ) should allow linkoo to work as expected : patch for linkoo

(workaround) Apply the patch

Just put it in the root dir ( the one containing all sources), and do :

1) fake the patch application ( using --dry-run option )

patch --dry-run -p0 <fix-linkoo_new.diff

2) if nothing bad occurs (excepted some fuzz) apply it for true :

patch -p0 <fix-linkoo_new.diff

With this patch applied, linkoo should work as expected. Please note this is a workaround, to make linkoo work for debug purpose.


Add debug infos in starmath

1) Build adding rectangles (for baselines and co )

-> uncomment line 93 in node.cxx : all formulas will be drawn with colored lines giving all alignment information ( Top Bottom Baseline when existing ..etc ) -> See the screenshots below

(This line seems to me moved now. Corresponding SM_RECT_DEBUG is at line 59. But uncommenting wouldn't work there. Rather move this to inc/rect.hxx) -- rakesh *need to provide patch upstream later* It is here

Index: ./inc/rect.hxx
RCS file: /cvs/sw/starmath/inc/rect.hxx,v
retrieving revision 1.7
diff -u -r1.7 rect.hxx
--- ./inc/rect.hxx	24 Apr 2008 13:57:29 -0000	1.7
+++ ./inc/rect.hxx	15 Sep 2008 17:33:58 -0000
@@ -62,6 +62,7 @@
 // Note: however, italic spaces can be negative!
+#define SM_RECT_DEBUG
 // possible flags for the 'Draw' function below (just for debugging)
 #define SM_RECT_CORE	0x0001
 #define SM_RECT_ITALIC	0x0002

Rebuild starmath libs

2) Build starmath again using :

cd starmath

mv unxmacxi.pro_backup /* adapt to your architecture / OS */

build debug="something_but_not_empty"


If never done before, run linkoo. Important: one time only !!

  • Notations

BUILD_SRC_DIR is the directory containing all the sources

INSTALL_DIR is the location of the Bundle

command line

  • Go into <BUILD_SRC_DIR>/solenv/bin

cd <BUILD_SRC_DIR>/solenv/bin

  • Run linkoo ( fake command, to verify everything is ok )

--dry-run is for the simulation. don't forget it ( else you can screew your tree )

Please notice, that in our case :


BUILD_SRC_DIR =~/Desktop/SRC680_m247

Thus, the complete command line is :

./linkoo ~/Desktop/test_m247_aquavcl05/ ~/Desktop/SRC680_m247 --dry-run

  • Run linkoo for true ( using --product option )

./linkoo ~/Desktop/test_m247_aquavcl05/ ~/Desktop/SRC680_m247 --product

  • Run ooenv

To avoid strange effects, once linkoo finished, please don't forget to source ooenv before ./soffice.

ooenv is located in INSTALL_DIR/ (means ~/Desktop/test_m247_aquavcl05/ )


And then launch gdb as described below

Mac OS X Linkoo Issue

FIXME : linkoo seems to not work ( I'll have a look asap )

Workaround :

Link the new libs ( or use linkoo ) from inside the bundle.

  • Go into the Bundle :

cd ~/Desktop/test_m247_aquavcl05/

  • Remove the striped libs :

rm -f libsm680mxi.dylib libsmd680mxi.dylib

  • create symlinks for the non strippied one :

ln -s ~/Desktop/SRC680_m247/starmath/ .

ln -s ~/Desktop/SRC680_m247/starmath/ .

!! don't forget the points !!

Attach the running process to gdb

  • Launch

Should work out of the box :)

  • Find the processus number of soffice.bin

To find the correct processus number correponding to binary execution, just run the following command line in a terminal :

ps ax | grep soffice.bin | grep -v grep

For example:

ordinateur-de-eric-b-2:~ ericb$ ps ax | grep soffice.bin | grep -v grep

11666  ?? S 0:00.56 /Applications/ -psn_0_51511297

-> the processus number is 11666

  • In a terminal, run gdb

ordinateur-de-eric-b-2:~ ericb$ gdb -q


... and attach the process number corresponding to soffice.bin

(gdb) attach 11666
Attaching to process 11666.
Reading symbols for shared libraries . done
Reading symbols for shared libraries .............................................................
................................................................................ done
0x90009bf7 in mach_msg_trap ()

Complement : detach the process

Simply use detach :

(gdb) detach 
Detaching from process 11666 thread 0xd03.

Other possibility :

(gdb) q
The program is running.  Quit anyway (and detach it)? (y or n) y
Detaching from process 11666 thread 0xd03.
ordinateur-de-eric-b-2:~ ericb$

Interesting breakpoints

FIXME : non exhaustive list, to be completed with other examples asap

tracing all Arrange() methods in node.cxx

SmRectangleNode::Arrange ( starmath/source/node.cxx, line 2329 )

SmSubSupNode::Arrange ( starmath/source/node.cxx, line 1437 )

SmMathSymbolNode::Arrange ( starmath/source/node.cxx, line 2731 )

SmBinVerNode::Arrange ( starmath/source/node.cxx, line 1087 )

There are exactly 27 Arrange() methods in node.cxx, and all must be analyzed.

For the complete list, see : Arrange methods list

Other interesting breakpoints


gdb completion

As preliminary, don't forget to use gdb completion feature: it's great and very usefull when you have to choose between several possibilities, like the same but overloaded method ... etc.

Principle: write the first letters of the word you want to write, and when sure, hit TAB key ( hit it several times if needed )

  • either there is only one solution, and the word will be simply completed (nice, isn't it ? )
  • or several solution will be proposed, and you'll have to decide which one use ..

How to add breakpoints ?

A breakpoint is an extremely helpfull way to stop -repeatably and safely- the binary execution, and analyse what happens with the code, modify on the fly, test other values ..etc

Several possibilities can be used there, to add a breakpoint :

1) specify the line :

Insert a breakpoint line 1234 in node.cxx :

(gdb) b node.cxx:1234

2) specify the method:

Insert a breakpoint when a method is called :

(gdb) b 'SmBinVerNode::Arrange'

Note: when the same method is overloaded, you can add the arguments to be sure to hit the right method.

3) conditional break :

Insert a breakpoint when the condition is verified :

(gdb) b cond ( (thing == true) || (foo != 0) )


First try:

type an equation containing a^2 + b^2 , exit formula ( ESC twice ) then enter the word "text"

then create a new equation containing  %tau a^2 + b^2 and notice the difference.

First breakpoint: parse.cxx:398

When entering whatever letter, you hit a breakpoint. Just trace after it, and compare the two equations (e.g.)

Entering  %tau a^2 + b^2 , you'll see the line starmath/source/parse.cxx:770

  • FIXME* : verify what makes ( if (aTmpRes.TokenType & KParseType::IDENTNAME)) true


Issue972 tested case05.jpg

Issue972 tested case21.jpg


A lot of screenshots and more informations are available at : [Ericb's site starmath ]

Personal tools