Segmentation fault in cdrStream::marshalString

10 個の投稿 / 0 new
最終投稿
athos
オフライン
Last seen: 6年 7ヶ月 前
登録日: 2014-07-10 17:28
Segmentation fault in cdrStream::marshalString

Dear All,

I have a simple example that tries to use the Streaming API, but segfaults.

Program received signal SIGSEGV, Segmentation fault. 0x00007ffff72af9d8 in cdrStream::marshalString (this=0x7fffffffe370, s=0x7ffff79718b4 "", bounded=0) at /usr/include/omniORB4/cdrStream.h:590 590 pd_ncs_c->marshalString(*this,pd_tcs_c,bounded,0,s);

The code (sorry, I don't see how to attach a file):
****************************************************

#include <rtm/idl/ExtendedDataTypesSkel.h> #include <rtm/idl/BasicDataTypeSkel.h> #include <iostream> #include <sstream>

using std::cout; using std::cerr; using std::endl; using std::stringstream; using std::string;

int main(int argc, char **argv) {

  // srand(123);
  RTC::TimedString data;
  // const char* c = "hu";
  // data.data = c;

  std::cout << data.data << std::endl;

  cdrMemoryStream os;
  std::cerr << "Hi" << std::endl;
  data >>= os;
  std::cerr << "Hi2" << std::endl;  
}
****************************************************

I was trying to dig deeper and debug the omniorb code, but I did not find a good way: is there any?

Thanks!

Attila

英語
gbiggs
オフライン
Last seen: 3年 7ヶ月 前
登録日: 2010-08-02 07:51
[openrtm-users 03062] Segmentation fault in cdrStream::marshalS

This segfault is probably caused by incorrect use of the CORBA string data
type.

The TimedString data type uses a CORBA (omniORB) string data type for its
"data" member. You need to be careful about ownership of memory when
putting strings into it. Usually, you use CORBA::string_dup() rather than
passing a raw pointer. See the StringIO example included with OpenRTM for
how to work with strings.

Geoff

On 15 July 2014 20:30, wrote:

> Dear All, I have a simple example that tries to use the Streaming API, but
> segfaults. Program received signal SIGSEGV, Segmentation fault.
> 0x00007ffff72af9d8 in cdrStream::marshalString (this=0x7fffffffe370,
> s=0x7ffff79718b4 "", bounded=0) at /usr/include/omniORB4/cdrStream.h:590
> 590
> pd_ncs_c->marshalString(*this,pd_tcs_c,bounded,0,s); The code (sorry, I
> don't
> see how to attach a file):
> ********************************************************** #include
> #include
> #include #include using std::cout; using std::cerr; using std::endl; using
> std::stringstream; using std::string; int main(int argc, char **argv) { //
> srand(123); RTC::TimedString data; // const char* c = "hu"; // data.data =
> c;
> std::cout << data.data << std::endl; cdrMemoryStream os; std::cerr << "Hi"
> <<
> std::endl; data >>= os; std::cerr << "Hi2" << std::endl; }
> ********************************************************** I was trying to
> dig deeper and debug the omniorb code, but I did not find a good way: is
> there any? Thanks! Attila
>
> _______________________________________________
> openrtm-users mailing list
> openrtm-users@openrtm.org
> http://www.openrtm.org/mailman/listinfo/openrtm-users
>

athos
オフライン
Last seen: 6年 7ヶ月 前
登録日: 2014-07-10 17:28
[openrtm-users 03062] Segmentation fault in cdrStream::marshalS

Dear Geoff,

Thank you for your answer.

I am not sure I understand your point: in the code I have sent I don't even initialize the data.data corba string.

Do you think of this example?: https://github.com/yosuke/OpenRTM-aist-portable/tree/master/examples/StringIO

I tried to follow what is there and modified my example:

  std::string s;
  std::cout << "Please input string: ";
  std::getline(std::cin, s);
  data.data = CORBA::string_dup(s.c_str());

I still get a segfault. What do I miss here?

Attila

athos
オフライン
Last seen: 6年 7ヶ月 前
登録日: 2014-07-10 17:28
[openrtm-users 03062] Segmentation fault in cdrStream::marshalS
Some more details:
  • I have ubuntu linux 12.04 and g++ version 4.6.3
  • I managed to recompile omniorb 4.1.5 with -g -O0 option, and it turned out that the line pd_ncs_c and pd_tcs_c both are null pointers when the segfault happens.
  • Adding a strange line (a constructor of an InPort) somehow solves this issue (there is no segfault any more at least). I include the modified code (that does not give a segfault). (Can someone tell me how to attach a file, please?)

#include <rtm/idl/ExtendedDataTypesSkel.h> #include <rtm/idl/BasicDataTypeSkel.h> #include <rtm/InPort.h>

#include <iostream> #include <sstream>

using std::cout; using std::cerr; using std::endl; using std::stringstream; using std::string;

int main(int argc, char **argv) {

  RTC::TimedString data;
  //  const char* c = "hu";
   
  // std::string s;
  // std::cout << "Please input string: ";
  // std::getline(std::cin, s);

  // data.data = CORBA::string_dup(s.c_str());
  RTC::TimedString data2;
  
  // commenting out the next line results in a segfault
  RTC::InPort<RTC::TimedString>("hi", data2);

  std::cout << data.data << std::endl;

  cdrMemoryStream os;
  std::cerr << "Hi" << std::endl;
  data >>= os;
  std::cerr << "Hi2" << std::endl;  
}

Attila

gbiggs
オフライン
Last seen: 3年 7ヶ月 前
登録日: 2010-08-02 07:51
[openrtm-users 03065] (無題)

I don't think you can attach files using the forum interface. You can
either post them in the forum interface using tags to keep the code
formatting intact, or you can use the mailing list interface and attach the
files to your email.

If you can post not just your source but all the other files you used to
compile it (i.e. any make files), it will be easier for us to test your
code to see if we have the same problem.

Geoff

On 17 July 2014 05:17, wrote:

> Some more details: - I have ubuntu linux 12.04 and g++ version 4.6.3 - I
> managed to recompile omniorb 4.1.5 with -g -O0 option, and it turned out
> that
> the line pd_ncs_c and pd_tcs_c both are null pointers when the segfault
> happens. - Adding a strange line (a constructor of an InPort) somehow
> solves
> this issue (there is no segfault any more at least). I include the modified
> code (that does not give a segfault). (Can someone tell me how to attach a
> file, please?) #include #include #include #include #include using
> std::cout;
> using std::cerr; using std::endl; using std::stringstream; using
> std::string;
> int main(int argc, char **argv) { RTC::TimedString data; // const char* c =
> "hu"; // std::string s; // std::cout << "Please input string: "; //
> std::getline(std::cin, s); // data.data = CORBA::string_dup(s.c_str());
> RTC::TimedString data2; // commenting out the next line results in a
> segfault
> RTC::InPort("hi", data2); std::cout << data.data << std::endl;
> cdrMemoryStream os; std::cerr << "Hi" << std::endl; data >>= os; std::cerr
> <<
> "Hi2" << std::endl; } Attila
>
>
> _______________________________________________
> openrtm-users mailing list
> openrtm-users@openrtm.org
> http://www.openrtm.org/mailman/listinfo/openrtm-users
>

athos
オフライン
Last seen: 6年 7ヶ月 前
登録日: 2014-07-10 17:28
[openrtm-users 03065] (無題)

Dear Geoff,

I use cmake. The OpenRTM is of version 1.1.

Contents of the file bad_test_RTMHexConverter.cpp:

  1. #include <rtm/idl/ExtendedDataTypesSkel.h>
  2. #include <rtm/idl/BasicDataTypeSkel.h>
  3. #include <rtm/InPort.h>
  4.  
  5. #include <iostream>
  6. int main(int argc, char **argv) {
  7. RTC::TimedString data;
  8.  
  9. RTC::TimedString data2;
  10. // commenting out the next line results in a segfault
  11. RTC::InPort<RTC::TimedString>("hi", data2);
  12.  
  13. std::cout << data.data << std::endl;
  14. cdrMemoryStream os;
  15. std::cerr << "Hi" << std::endl;
  16. data >>= os;
  17. std::cerr << "Hi2" << std::endl;
  18. }

Contents of the CMakeLists.txt file:

  1. cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
  2.  
  3. project(cdrStreamProba)
  4.  
  5. set(CMAKE_BUILD_TYPE Debug)
  6.  
  7. find_package(OpenRTM)
  8.  
  9. if(${OpenRTM_FOUND})
  10. MESSAGE(STATUS "OpenRTM configuration Found")
  11. else(${OpenRTM_FOUND})
  12. message(STATUS "Use cmake/Modules/FindOpenRTM.cmake in the project")
  13. list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/Modules)
  14. find_package(OpenRTM REQUIRED)
  15. endif(${OpenRTM_FOUND})
  16. if (DEFINED OPENRTM_INCLUDE_DIRS)
  17. string(REGEX REPLACE "-I" ";"
  18. OPENRTM_INCLUDE_DIRS "${OPENRTM_INCLUDE_DIRS}")
  19. string(REGEX REPLACE " ;" ";"
  20. OPENRTM_INCLUDE_DIRS "${OPENRTM_INCLUDE_DIRS}")
  21. endif (DEFINED OPENRTM_INCLUDE_DIRS)
  22. include_directories(${OPENRTM_INCLUDE_DIRS})
  23.  
  24. message("omniorb" ${OMNIORB_INCLUDE_DIRS})
  25.  
  26.  
  27. add_executable(bad_test_RTMHexConverter bad_test_RTMHexConverter.cpp)
  28. target_link_libraries(bad_test_RTMHexConverter ${OPENRTM_LIBRARIES})

Attila

gbiggs
オフライン
Last seen: 3年 7ヶ月 前
登録日: 2010-08-02 07:51
[openrtm-users 03067] (無題)

The problem with the source you have provided is that omniORB (which
provides the cdrMemoryStream implementation) has not been properly
initialised before you call it. This is why it is segfaulting.

Geoff

On 18 July 2014 05:07, wrote:

> Dear Geoff, I use cmake. The OpenRTM is of version 1.1. Contents of the
> file
> bad_test_RTMHexConverter.cpp: #include #include #include #include int
> main(int argc, char **argv) { RTC::TimedString data; RTC::TimedString
> data2;
>
> // commenting out the next line results in a segfault RTC::InPort("hi",
> data2); std::cout << data.data << std::endl; cdrMemoryStream os; std::cerr
> <<
> "Hi" << std::endl; data >>= os; std::cerr << "Hi2" << std::endl; } Contents
> of the CMakeLists.txt file: cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
> project(cdrStreamProba) set(CMAKE_BUILD_TYPE Debug) find_package(OpenRTM)
> if(${OpenRTM_FOUND}) MESSAGE(STATUS "OpenRTM configuration Found")
> else(${OpenRTM_FOUND}) message(STATUS "Use cmake/Modules/FindOpenRTM.cmake
> in
> the project") list(APPEND CMAKE_MODULE_PATH
> ${PROJECT_SOURCE_DIR}/cmake/Modules) find_package(OpenRTM REQUIRED)
> endif(${OpenRTM_FOUND}) if (DEFINED OPENRTM_INCLUDE_DIRS) string(REGEX
> REPLACE "-I" ";" OPENRTM_INCLUDE_DIRS "${OPENRTM_INCLUDE_DIRS}")
> string(REGEX
> REPLACE " ;" ";" OPENRTM_INCLUDE_DIRS "${OPENRTM_INCLUDE_DIRS}") endif
> (DEFINED OPENRTM_INCLUDE_DIRS) include_directories(${OPENRTM_
> INCLUDE_DIRS})
> message("omniorb" ${OMNIORB_INCLUDE_DIRS})
> add_executable(bad_test_RTMHexConverter bad_test_RTMHexConverter.cpp)
> target_link_libraries(bad_test_RTMHexConverter ${OPENRTM_LIBRARIES})
> Attila
>
>
> _______________________________________________
> openrtm-users mailing list
> openrtm-users@openrtm.org
> http://www.openrtm.org/mailman/listinfo/openrtm-users
>

athos
オフライン
Last seen: 6年 7ヶ月 前
登録日: 2014-07-10 17:28
[openrtm-users 03067] (無題)

Dear Geoff,

Thank you for your answer. Can you please give me some guidelines on how to properly initialize omniOrb? For example you mentioned the StringIO example earlier, which I cannot find in my openrtm distribution.

Attila

athos
オフライン
Last seen: 6年 7ヶ月 前
登録日: 2014-07-10 17:28
Segmentation fault in

Dear Geoff,

Thank you for your help. It turned out that making the explicit call to

CORBA::ORB_init();

solved this issue.

Attila

gbiggs
オフライン
Last seen: 3年 7ヶ月 前
登録日: 2010-08-02 07:51
[openrtm-users 03071] Segmentation fault in

Hi Attila,

Yes, that is the correct thing to do. omniORB uses many internal global
variables that need to be initialised before its API can be used correctly.

Geoff

On 21 July 2014 23:29, wrote:

> Dear Geoff, Thank you for your help. It turned out that making the explicit
> call to CORBA::ORB_init(); solved this issue. Attila
>
> _______________________________________________
> openrtm-users mailing list
> openrtm-users@openrtm.org
> http://www.openrtm.org/mailman/listinfo/openrtm-users
>

コメントを投稿するにはログインまたはユーザー登録を行ってください

ダウンロード

最新バージョン

初めての方へ

Windows msi(インストーラ) パッケージ (サンプルの実行ができます。)

C++,Python,Java,
Toolsを含む
1.2.1-RELEASE

RTコンポーネントを開発するためには開発環境のインストールが必要です。詳細はダウンロードページ

統計

Webサイト統計
ユーザ数:1839
プロジェクト統計
RTコンポーネント297
RTミドルウエア28
ツール22
文書・仕様書1

Choreonoid

モーションエディタ/シミュレータ

OpenHRP3

動力学シミュレータ

OpenRTP

統合開発プラットフォーム

産総研RTC集

産総研が提供するRTC集

TORK

東京オープンソースロボティクス協会

DAQ-Middleware

ネットワーク分散環境でデータ収集用ソフトウェアを容易に構築するためのソフトウェア・フレームワーク