I seek advice on what is causing a server fault in our code. I have a "generic"
part of our spreadsheet server app for connecting to the Open Office SDK
4.1.2 service. The "generic" part is represented in the code fragment below
(*Code*). We require however the XDesktop and XComponentLoader features to
work, but they are giving us problems. What have I done wrongly? How do I
get them to work or what is a better alternative?

I provide a summary and example.cxx code below before the segmentation
fault occurs.


*Summary: *

Sample application fails at the end with a segmentation violation with
backtrace:

#0  0x00007ffff489b723 in cpp_vtable_call ()
   from /opt/libreoffice5.2/program/libgcc3_uno.so
#1  0x00007ffff48a26ea in privateSnippetExecutor ()
   from /opt/libreoffice5.2/program/libgcc3_uno.so
#2  0x0000000000401ea9 in main ()

The simple example was built adapting the Libreoffice 5.2 SDK. Code and
makefile below.

The same code, embedded into a larger application, fails at the
XComponentLoader call --- with the same backtrace.

A somewhat similar example fails on the
xComponentLoader->loadComponentFromURL call (backtrace terminating on that
line; the file and directory parameters passed into that method look good
on inspection; flag is 0, property sequence is void).

We have tried this on Libreoffice 4 (as per ubuntu trusty repo) and on
headless Openoffice SDK 4.1.2, with very similar results. Despite the fact
that the simple example code runs to the end before crashing, we suspect
based on the other evidence an issue with XComponentLoader.

We have tried many different ways of compiling the source code but cannot
succeed in getting a successful built.  Any ideas about what might be
causing the problem would be gratefully appreaciated.


*Code *(ooexample.cxx)*:*

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

#include <cppuhelper/bootstrap.hxx>
#include <com/sun/star/bridge/XUnoUrlResolver.hpp>
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
#include <com/sun/star/lang/XMultiComponentFactory.hpp>
#include <com/sun/star/beans/XPropertySet.hpp>
#include <com/sun/star/frame/Desktop.hpp>
#include <com/sun/star/uno/XInterface.hpp>
#include <com/sun/star/frame/XComponentLoader.hpp>
#include <com/sun/star/container/XNameAccess.hpp>
#include <com/sun/star/document/XTypeDetection.hpp>

using namespace com::sun::star::uno;
using namespace com::sun::star::lang;
using namespace com::sun::star::bridge;
using namespace com::sun::star::beans;
using namespace com::sun::star::frame;
using namespace com::sun::star::container;
using namespace com::sun::star::document;
using namespace rtl;
using namespace cppu;

#define DIAG(s) printf("%s\n",s)
#define OOCHECKREF(x) if (!x.is()){printf("Error: "#x"\n");return 1;}

int main (int argc, char *argv[]) {
  try {
    DIAG("mComponentContext");
    Reference< XComponentContext > mComponentContext
      = defaultBootstrap_InitialComponentContext();

    DIAG("mServiceManager");
    Reference< XMultiComponentFactory > mServiceManager
      = mComponentContext->getServiceManager();

    DIAG("rResolverInstance");
    Reference< XInterface > rResolverInstance
      = mServiceManager->createInstanceWithContext (
        OUString::createFromAscii("com.sun.star.bridge.UnoUrlResolver") ,
        mComponentContext);

    DIAG("rResolver");
    Reference< XUnoUrlResolver > rResolver (rResolverInstance, UNO_QUERY);
    OOCHECKREF(rResolver)

    DIAG("rOfficeInstance");    Reference< XInterface > rOfficeInstance
      = rResolver->resolve (
        OUString::createFromAscii
("uno:socket,host=localhost,port=8199;urp;StarOffice.ServiceManager")) ;
    OOCHECKREF(rOfficeInstance)

    DIAG("rOfficeServiceManager");
    Reference< XMultiServiceFactory > rOfficeServiceManager (
      rOfficeInstance, UNO_QUERY);
    OOCHECKREF(rOfficeServiceManager)

    DIAG("xPropSet");
    Reference< XPropertySet > xPropSet (rOfficeInstance, UNO_QUERY) ;
      xPropSet->getPropertyValue
(OUString::createFromAscii("DefaultContext"))  >>= mComponentContext;

    DIAG("xMultiComponentFactoryServer");
    Reference< XMultiComponentFactory > xMultiComponentFactoryServer(
      mComponentContext->getServiceManager());

    DIAG("rDesktop");
    Reference<XInterface> rDesktop = rOfficeServiceManager->createInstance(
      OUString::createFromAscii("com.sun.star.frame.Desktop"));
    OOCHECKREF(rDesktop)

    DIAG("mComponentLoader");
    Reference< XComponentLoader > mComponentLoader (rDesktop, UNO_QUERY);
    OOCHECKREF(mComponentLoader)

    DIAG("rFiltersInt");
    Reference< XInterface > rFiltersInt =
rOfficeServiceManager->createInstance(
        OUString::createFromAscii("com.sun.star.document.FilterFactory"));
    OOCHECKREF(rFiltersInt)

    DIAG("mFilterFactory");
    Reference<XNameAccess> mFilterFactory = Reference< XNameAccess
>(rFiltersInt, UNO_QUERY);
    OOCHECKREF(mFilterFactory)

    DIAG("rTypeDetectInt");
    Reference< XInterface > rTypeDetectInt =
rOfficeServiceManager->createInstance(
        OUString::createFromAscii("com.sun.star.document.TypeDetection"));
    OOCHECKREF(rTypeDetectInt)

    DIAG("mTypeDetect");
    Reference< XTypeDetection > mTypeDetect = Reference< XTypeDetection
>(rTypeDetectInt, UNO_QUERY);
    OOCHECKREF(mTypeDetect)

    DIAG ("Connected successfully to the office - press enter to exit");
    getchar();
  } catch (Exception &e) {
    OString o = OUStringToOString (e.Message, RTL_TEXTENCODING_ASCII_US);
    printf ("Error: %s\n", o.pData->buffer);
    return 1;
  }
  return 0;
}

*Makefile:*

PRJ=../../..
SETTINGS=$(PRJ)/settings

include $(SETTINGS)/settings.mk
include $(SETTINGS)/std.mk

# Define non-platform/compiler specific settings
COMP_NAME=ooexample
COMP_IMPL_NAME=$(COMP_NAME).uno.$(SHAREDLIB_EXT)
COMP_IMPL=$(SHAREDLIB_OUT)/$(COMP_IMPL_NAME)
COMP_RDB_NAME = $(COMP_NAME).uno.rdb
COMP_RDB = $(OUT_BIN)/$(COMP_RDB_NAME)
OUT_COMP_INC = $(OUT_INC)/$(COMP_NAME)
OUT_COMP_GEN = $(OUT_MISC)/$(COMP_NAME)
OUT_COMP_OBJ = $(OUT_OBJ)/$(COMP_NAME)
OUT_COMP_SLO = $(OUT_SLO)/$(COMP_NAME)
COMP_SERVICES=$(SHAREDLIB_OUT)/ooexampleservices.rdb

ENV_EXAMPLE_TYPES=-env:URE_MORE_TYPES=$(URLPREFIX)$(COMP_RDB)
ENV_COMP_SERVICES=-env:URE_MORE_SERVICES=$(URLPREFIX)$(COMP_SERVICES)

COMP_TYPEFLAG = $(OUT_MISC)/cpp_$(COMP_NAME)_types.flag

CXXFILES = ooexample.cxx

SLOFILES = $(patsubst %.cxx,$(OUT_COMP_SLO)/%.$(OBJ_EXT),$(COMPCXXFILES))
OBJFILES = $(patsubst %.cxx,$(OUT_COMP_SLO)/%.$(OBJ_EXT),$(CXXFILES))
# Targets
.PHONY: ALL
ALL : \
        ooexample

include $(SETTINGS)/stdtarget.mk

$(OUT_COMP_GEN)/%.urd : %.idl
        -$(MKDIR) $(subst /,$(PS),$(@D))
        $(IDLC) -I. -I$(IDL_DIR) -O$(OUT_COMP_GEN) $<

# This example type library will be extended by the URE types
$(OUT_BIN)/%.rdb : $(GENURDFILES)
        -$(MKDIR) $(subst /,$(PS),$(@D))
        -$(DEL) $(subst \\,\,$(subst /,$(PS),$@))
#       $(REGMERGE) $@ /UCR $(GENURDFILES)
        $(REGMERGE) $@ / $(URE_TYPES)

$(COMP_TYPEFLAG) : $(COMP_RDB) $(SDKTYPEFLAG)
        -$(MKDIR) $(subst /,$(PS),$(@D))
        -$(DEL) $(subst \\,\,$(subst /,$(PS),$(COMP_TYPEFLAG)))
        $(CPPUMAKER) -Gc -O$(OUT_COMP_INC) $(TYPESLIST) $(COMP_RDB) -X
$(URE_TYPES)
        echo flagged > $@

$(OUT_COMP_OBJ)/%.$(OBJ_EXT) : %.cxx $(COMP_TYPEFLAG)
        -$(MKDIR) $(subst /,$(PS),$(OUT_OBJ))
        -$(MKDIR) $(subst /,$(PS),$(@D))
        $(CC) $(CC_FLAGS) $(CC_INCLUDES) -I$(OUT_COMP_INC) $(CC_DEFINES)
$(CC_OUTPUT_SWITCH)$(subst /,$(PS),$@) $<

$(OUT_COMP_SLO)/%.$(OBJ_EXT) : %.cxx $(COMP_TYPEFLAG)
        -$(MKDIR) $(subst /,$(PS),$(OUT_SLO))
        -$(MKDIR) $(subst /,$(PS),$(@D))
        $(CC) $(CC_FLAGS) $(CC_INCLUDES) -I$(OUT_COMP_INC) $(CC_DEFINES)
$(CC_OUTPUT_SWITCH)$(subst /,$(PS),$@) $<

ifeq "$(OS)" "WIN"
$(SHAREDLIB_OUT)/%.$(SHAREDLIB_EXT) : $(SLOFILES)
        -$(MKDIR) $(subst /,$(PS),$(@D))
        -$(MKDIR) $(subst /,$(PS),$(OUT_COMP_GEN))
        $(LINK) $(COMP_LINK_FLAGS) /OUT:$@ \
        /MAP:$(OUT_COMP_GEN)/$(subst $(SHAREDLIB_EXT),map,$(@F))
$(SLOFILES) \
        $(CPPUHELPERLIB) $(CPPULIB) $(SALLIB) msvcprt.lib
$(LIBO_SDK_LDFLAGS_STDLIBS)
        $(LINK_MANIFEST)
else

$(SHAREDLIB_OUT)/%.$(SHAREDLIB_EXT) : $(SLOFILES)
        -$(MKDIR) $(subst /,$(PS),$(@D))
        $(LINK) $(COMP_LINK_FLAGS) $(LINK_LIBS) -o $@ $(SLOFILES) \
        $(CPPUHELPERLIB) $(CPPULIB) $(SALLIB) $(STC++LIB)
ifeq "$(OS)" "MACOSX"
        $(INSTALL_NAME_URELIBS)  $@
endif
endif
$(OUT_BIN)/ooexample$(EXE_EXT) : $(OUT_COMP_OBJ)/ooexample.$(OBJ_EXT)
$(SHAREDLIB_OUT)/ooexample.uno.$(SHAREDLIB_EXT)

ifeq "$(OS)" "WIN"
        -$(MKDIR) $(subst /,$(PS),$(@D))
        $(LINK) $(EXE_LINK_FLAGS) /OUT:$@ /MAP:$(OUT_COMP_GEN)/$(basename
$(@F)).map \
          $< $(CPPUHELPERLIB) $(CPPULIB) $(SALHELPERLIB) $(SALLIB)
else
        -$(MKDIR) $(subst /,$(PS),$(@D))        $(LINK) $(EXE_LINK_FLAGS)
$(LINK_LIBS) -o $@ $< \
          $(CPPUHELPERLIB) $(CPPULIB) $(SALHELPERLIB) $(SALLIB) $(STDC++LIB)
endif

$(COMP_SERVICES) :
        -$(MKDIR) $(subst /,$(PS),$(@D))
        @echo $(OSEP)?xml version="$(QM)1.0$(QM)"
encoding="$(QM)UTF-8$(QM)"?$(CSEP) > $@
        @echo $(OSEP)components xmlns="$(QM)
http://openoffice.org/2010/uno-components$(QM)"$(CSEP) >> $@
        @echo $(SQM)  $(SQM)$(OSEP)component
loader="$(QM)com.sun.star.loader.SharedLibrary$(QM)"
uri="$(QM)$(COMP_IMPL_NAME)$(QM)"$(CSEP) >> $@
        @echo $(SQM)    $(SQM)$(OSEP)implementation
name="$(QM)com.sun.star.comp.example.cpp.ooexample$(QM)"$(CSEP) >> $@
        @echo $(SQM)      $(SQM)$(OSEP)service
name="$(QM)foo.ooexample$(QM)"/$(CSEP) >> $@
        @echo $(SQM)    $(SQM)$(OSEP)/implementation$(CSEP) >> $@
ooexample : $(OUT_BIN)/ooexample$(EXE_EXT) $(COMP_IMPL) $(COMP_SERVICES)
        @echo
--------------------------------------------------------------------------------
        @echo Please use the following command to execute the example!
        @echo -
        @echo $(MAKE) ooexample.run
        @echo -
        @echo NOTE: The example makes use of the URE and use the
defaultBootstrap_InitialComponentContext method.
        @echo $(SQM)      $(SQM)The additional example IDL types are
provided via the UNO environment variable -env:URE_MORE_TYPES=...
        @echo $(SQM)      $(SQM)and the example component is made available
via -env:URE_MORE_SERVICES=...
        @echo $(SQM)      $(SQM)Please check the generated
$(QM)$(COMP_SERVICES)$(QM) to see how you can specify your own components
in such an environment
        @echo $(SQM)      $(SQM)and how to use the passive UNO
registration.
        @echo
--------------------------------------------------------------------------------

%.run: $(OUT_BIN)/ooexample$(EXE_EXT) $(COMP_IMPL)



*Compile: *
export OO_SDK_HOME=../../../../sdk
export OO_SDK_URE_BIN_DIR=../../../../program
export OFFICE_PROGRAM_PATH=$OO_SDK_URE_BIN_DIR
export OO_SDK_OFFICE_LIB_DIR=../../../../sdk/lib
export OO_SDK_URE_HOME=../../../../../ure
export OO_SDK_URE_LIB_DIR=$OO_SDK_URE_HOME/lib
export PATH=$PATH:.

make ooexample.run

*Headless libreoffice instance listening:*

jenkins   2610     1  0 10:28 pts/4    00:00:00 Xvfb :95 -screen 0
1024x768x24 -extension Composite -nolisten tcp

jenkins   2657  2616  0 10:28 pts/4    00:00:00
/opt/libreoffice5.2/program/soffice.bin --headless
--accept=socket,host=127.0.0.1,port=8199,tcpNoDelay=1;urp;StarOffice.ServiceManager
--nofirststartwizard --display :95 --nologo --norestore --invisible


*Execution:*

gdb ../../../LINUXexample.out/bin/ooexample


GNU gdb (Ubuntu 7.7.1-0ubuntu5~14.04.2) 7.7.1
Copyright (C) 2014 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later
<http://gnu.org/licenses/gpl.html> <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from ../../../LINUXexample.out/bin/ooexample...(no
debugging symbols found)...done.
(gdb) r
Starting program: /opt/libreoffice5.2/sdk/LINUXexample.out/bin/ooexample
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
mComponentContext
[New Thread 0x7ffff5988700 (LWP 12125)]
mServiceManager
rResolverInstance
rResolver
rOfficeInstance
[New Thread 0x7ffff4015700 (LWP 12128)]
[New Thread 0x7ffff3814700 (LWP 12129)]
rOfficeServiceManager
xPropSet
xMultiComponentFactoryServer
rDesktop
mComponentLoader
rFiltersInt
mFilterFactory
rTypeDetectInt
mTypeDetect
Connected successfully to the office - press enter to exit
Program received signal SIGSEGV, Segmentation fault.
0x00007ffff489b723 in cpp_vtable_call ()
   from /opt/libreoffice5.2/program/libgcc3_uno.so
(gdb) bt
#0  0x00007ffff489b723 in cpp_vtable_call ()
   from /opt/libreoffice5.2/program/libgcc3_uno.so
#1  0x00007ffff48a26ea in privateSnippetExecutor ()
   from /opt/libreoffice5.2/program/libgcc3_uno.so
#2  0x0000000000401ea9 in main ()
(gdb) c
Continuing.
[Thread 0x7ffff7fc8780 (LWP 11222) exited]
[Thread 0x7ffff4015700 (LWP 11229) exited]
[Thread 0x7ffff5988700 (LWP 11226) exited]

Program terminated with signal SIGSEGV, Segmentation fault.
The program no longer exists.

Hamish

Reply via email to