MantisBT
Mantis Bug Tracker Workflow

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0030762Open CASCADE[OCCT] OCCT:Foundation Classespublic2019-06-03 08:062020-12-03 14:32
Reporterkgv 
Assigned Tomzernova 
PrioritynormalSeverityfeature 
StatusassignedResolutionopen 
PlatformOSOS Version
Product Version 
Target Version[OCCT] 7.6.0*Fixed in Version 
Summary0030762: Foundation Classes - include backtrace within OSD_SIGSEGV on Linux
DescriptionIt would be helpful if exceptions like OSD_SIGSEGV will include backtrace, so that it will be possible determining context without debugger.

** Exception ** 0x55b5bce52950 : OSD_SIGSEGV: SIGSEGV 'segmentation violation' detected. Address 38

/lib/x86_64-linux-gnu/libc.so.6(+0x3ef20) [0x7fd984d6ff20]
/occt/adm/qmake/Draw/DRAWEXE/../../../../lin/gcc/libd/libTKOpenGl.so.7(_ZNK14OpenGl_Texture5SizeXEv+0xc) 
[0x7fd97458dfa4]
/occt/adm/qmake/Draw/DRAWEXE/../../../../lin/gcc/libd/libTKOpenGl.so.7(_ZN11OpenGl_Font11renderGlyphERKN11opencascade6handleI14OpenGl_ContextEEDi+0xdc) 
[0x7fd97460be62]
/occt/adm/qmake/Draw/DRAWEXE/../../../../lin/gcc/libd/libTKOpenGl.so.7(_ZN11OpenGl_Font11RenderGlyphERKN11opencascade6handleI14OpenGl_ContextEEDiRNS_4TileE+0x68) 
[0x7fd97460c234]
/occt/adm/qmake/Draw/DRAWEXE/../../../../lin/gcc/libd/libTKOpenGl.so.7(_ZN18OpenGl_TextBuilder12createGlyphsERK18Font_TextFormatterRKN11opencascade6handleI14OpenGl_ContextEER11OpenGl_FontR18NCollection_VectorIjERSB_I18NCollection_HandleISB_I16NCollection_Vec2IfEEEESK_+0x2ef) 
[0x7fd97466b70d]
/occt/adm/qmake/Draw/DRAWEXE/../../../../lin/gcc/libd/libTKOpenGl.so.7(_ZN18OpenGl_TextBuilder7PerformERK18Font_TextFormatterRKN11opencascade6handleI14OpenGl_ContextEER11OpenGl_FontR18NCollection_VectorIjERSB_INS4_I19OpenGl_VertexBufferEEESH_+0xfd) 
[0x7fd97466bd6b]
/occt/adm/qmake/Draw/DRAWEXE/../../../../lin/gcc/libd/libTKOpenGl.so.7(_ZNK11OpenGl_Text6renderERKN11opencascade6handleI14OpenGl_ContextEERK14OpenGl_AspectsRK16NCollection_Vec4IfESC_j+0x2fc) 
[0x7fd9745a7aac]
/occt/adm/qmake/Draw/DRAWEXE/../../../../lin/gcc/libd/libTKOpenGl.so.7(_ZNK11OpenGl_Text6RenderERKN11opencascade6handleI16OpenGl_WorkspaceEE+0x241) 
[0x7fd9745a5bdf]
/occt/adm/qmake/Draw/DRAWEXE/../../../../lin/gcc/libd/libTKOpenGl.so.7(+0x118d03) [0x7fd97459bd03]
Steps To Reproducebugs/fclasses/bug30762
TagsNo tags attached.
Test case number
Attached Files

- Relationships

-  Notes
(0084766)
git (administrator)
2019-06-03 08:06

Branch CR30762 has been created by kgv.

SHA-1: 5c24f60d5280069ab2c8f212a11c27648e8ab050


Detailed log of new commits:

Author: kgv
Date: Mon Jun 3 08:06:24 2019 +0300

    0030762: Foundation Classes - optionally include backtrace within dangerous exceptions like OSD_SIGSEGV

Author: kgv
Date: Thu May 30 10:02:25 2019 +0300

    0028668: Point Cloud Rendering - standard selection API returns invalid values
    
    Added an argument to OpenGl_GraphicDriver::GetSharedContext() for returning only currently bound OpenGL context.
    SelectMgr_SelectingVolumeManager::GetMousePosition() - added getter returning mouse coordinates.
(0094817)
git (administrator)
2020-09-15 11:54

Branch CR30762_1 has been created by kgv.

SHA-1: 2c4e34ba95985071beb112884b929c29afc61982


Detailed log of new commits:

Author: kgv
Date: Mon Jun 3 08:06:24 2019 +0300

    0030762: Foundation Classes - include backtrace within OSD_SIGSEGV on Linux
    
    Added function Standard_Failure::BacktraceCat() appending backtrace to the string (implemented for Linux).
    SegvHandler within OSD_signal now appends backtrace to the message.
(0094820)
git (administrator)
2020-09-15 12:05

Branch CR30762_1 has been updated forcibly by kgv.

SHA-1: 538c3292da35fcf5d747c589da34536c229f667f
(0094840)
kgv (developer)
2020-09-15 15:12

Patch is ready for review
- OCCT branch: CR30762_1.

http://jenkins-test-12.nnov.opencascade.com:8080/view/CR30762_1-master-KGV [^]
(0094892)
git (administrator)
2020-09-16 00:02

Branch CR30762_2 has been created by kgv.

SHA-1: 76f46c9b23dadcc154177a7637750e35c10c1c4e


Detailed log of new commits:

Author: kgv
Date: Mon Jun 3 08:06:24 2019 +0300

    0030762: Foundation Classes - include backtrace within OSD_SIGSEGV on Linux
    
    Added function Standard_Failure::BacktraceCat() appending backtrace to the string (implemented for Linux).
    SegvHandler within OSD_signal now appends backtrace to the message.
(0095711)
abv (manager)
2020-10-05 08:50

Some remarks:

0. Since stack trace functionality per-se is not related to exceptions, and it is never used within Standard package, it would be more logical to put function BacktraceCat into OSD package (e.g. as package method).
   Besides, the name "StackTrace..." would be more intuitive.

1. On Windows, BacktraceCat() is available only if OCCT is built with undocumented macro HAVE_DBGHELP.
   To make it useful, at least this macro shall be documented (see dox/debug/debug.md).
   To be more usable, I propose that it should be made always available (on both Linux and Windows).
   This can probably require dynamic loading of DbgHelp.dll, this is to be checked...

2. On Windows, calls to DbgHelp.dll should be protected by mutex to avoid possibility of contention in multithreaded scenarios.
   See documentation of DbgHelp.dll at https://docs.microsoft.com/en-us/windows/win32/debug/about-dbghelp [^]

> Note that all DbgHelp functions are single threaded. Therefore, calls from more than one thread to this function will likely result in unexpected behavior or memory corruption. To avoid this, you must synchronize all concurrent calls from more than one thread to this function.

3. In Standard_Failure.hxx:

> //! This method relies on platform-dependent features and might be not implemented.

   It is not clear what "might be not implemented" means in practice.
   It is better to write explicitly: "if this feature is not available, the function will do nothing".
   Return success status instead of void would be helpful indeed.

4. Inclusion of stack trace info into the exception message would not always be needed.
   I propose that it should be triggered using environment variable (e.g. reusing existing CSF_DEBUG_MODE).

5. On Linux, as far as I know, signal handler is called within its own stack; that is why we have to use longjump and raise C++ exception from macro OCC_CATCH_SIGNALS on Linux.
   This means that stack trace generated in SegvHandler() would be meaningless (have you checked it?).
   I propose that generation of backtracebe moved to constructor of OSD_Exception - it will be equally useful on both Windows and Linux then.

6. Commit message is incomplete (mentions Linux only), please update.
(0097222)
git (administrator)
2020-12-01 18:36

Branch CR30762_3 has been created by mzernova.

SHA-1: b9032353defc5213909f127fb9e025a3c0040182


Detailed log of new commits:

Author: mzernova
Date: Tue Nov 24 13:14:06 2020 +0300

    Implemented dynamic loading of DbgHelp.dll
    BacktraceCat function has been renamed and moved to OSD package.

Author: kgv
Date: Mon Jun 3 08:06:24 2019 +0300

    0030762: Foundation Classes - include backtrace within OSD_SIGSEGV on Linux
    
    Added function Standard_Failure::BacktraceCat() appending backtrace to the string (implemented for Linux).
    SegvHandler within OSD_signal now appends backtrace to the message.
    
    (cherry picked from commit 2bb8f4d3a266d8e308d35ecce0d9389c1cfe77c0)
(0097227)
kgv (developer)
2020-12-01 23:18

+  OSD_Debug aDbgHelp;

This library is expected to be loaded once and globally accessed - hence should be defined as singleton.

+PVOID OSD_Debug::SymFunctionTableAccess (HANDLE hProcess, DWORD AddrBase)
+{
+  Standard_Mutex::Sentry aSentry (myMutex);

I would rather expect a global mutex to be locked once at start of OSD::StackTrace() instead of each individual function call to DbgHelp library.

+
+  // dbgHelp.dll functions
+  PFUNCTION_TABLE_ACCESS_ROUTINE64 symFunctionTableAccess64;
+  PGET_MODULE_BASE_ROUTINE64       symGetModuleBase64;
+  STACKWALK64PROC                  stackWalk64;
+  SYMCLEANUPPROC                   symCleanup;
+  SYMFROMADDRPROC                  symFromAddr;
+  SYMINITIALIZEPROC                symInitialize;
+
+private:
+
+  HMODULE myDbgHelpLib;

I don't think that OCCT should provide a public API as direct wrapper to DbgHelp library. I propose moving these details to .cxx and export the only useful utility OSD::StackTrace().

+#if defined(_WIN32) && defined(HAVE_DBGHELP)

Please remove HAVE_DBGHELP checks.

+    throw Standard_ProgramError ("OSD_Debug::loadDbgHelper(): Failed to load DbgHelp.dll");


It doesn't look useful throwing such exceptions on DbgHelp.dll unavailability or incompatibility - logging an error message will be more suitable.
(0097241)
git (administrator)
2020-12-02 15:13

Branch CR30762_3 has been updated by mzernova.

SHA-1: be6e180fc6eb990a0cd5e60d61f1f5070f4e756c


Detailed log of new commits:

Author: mzernova
Date: Wed Dec 2 14:59:59 2020 +0300

    remarks from kgv

(0097242)
git (administrator)
2020-12-02 15:13

Branch CR30762_4 has been created by mzernova.

SHA-1: bb1181025ff2ccca31a9fa106b0750fc398e04a1


Detailed log of new commits:

Author: kgv
Date: Mon Jun 3 08:06:24 2019 +0300

    0030762: Foundation Classes - include backtrace within OSD_SIGSEGV on Linux
    
    Implemented dynamic loading of DbgHelp.dll
    
    Added function OSD_Debug::StackTrace() appending backtrace to the string.
    SegvHandler within OSD_signal now appends backtrace to the message.
(0097247)
kgv (developer)
2020-12-02 15:42

Please implement the forth remark of Andrey:
> 4. Inclusion of stack trace info into the exception message would not always be needed.
> I propose that it should be triggered using environment variable (e.g. reusing existing CSF_DEBUG_MODE).
CSF_DEBUG_MODE variable can be used to put backtrace into message box.
Please also extend OSD::SetSignal() with the new flag for including stacktrace into redirected access-violation exception message, disabled by default.

--- a/src/Standard/Standard_Failure.cxx
+++ b/src/Standard/Standard_Failure.cxx
...
+#ifndef _WIN32
+  #include <execinfo.h>
+#endif

Looks like an artifact.

+Standard_Boolean OSD_Debug::StackTrace (char* theBuffer,

Please move it back to OSD::StackTrace() and drop redundant OSD_Debug.hxx header (move internal structure definition to .cxx). OSD_StackTrace.cxx would look more appropriate than OSD_Debug.cxx.

+       Standard_Failure::BacktraceCat (aMsg, (int )sizeof(aMsg));

Seems it wouldn't compile on Linux.
(0097264)
git (administrator)
2020-12-03 12:33

Branch CR30762_3 has been updated by mzernova.

SHA-1: 355e4ad9763c069e8322fadf53e49ed1a9f1ff00


Detailed log of new commits:

Author: mzernova
Date: Thu Dec 3 12:17:38 2020 +0300

    remarks from kgv

(0097265)
git (administrator)
2020-12-03 12:33

Branch CR30762_4 has been updated forcibly by mzernova.

SHA-1: cf6ecd3a752819c8eae43f758da5d5db4f4ebe78
(0097266)
git (administrator)
2020-12-03 12:51

Branch CR30762_4 has been updated forcibly by mzernova.

SHA-1: f9fe83e244be149410534cac059d666be0fab236
(0097267)
git (administrator)
2020-12-03 12:51

Branch CR30762_3 has been updated forcibly by mzernova.

SHA-1: fc9471fdacfcac95773f8185496f485ff7d77fb0

- Issue History
Date Modified Username Field Change
2019-06-03 08:06 kgv New Issue
2019-06-03 08:06 kgv Assigned To => abv
2019-06-03 08:06 git Note Added: 0084766
2019-06-03 08:11 kgv Description Updated View Revisions
2019-06-03 08:12 kgv Description Updated View Revisions
2019-09-04 15:43 abv Target Version 7.4.0 => 7.5.0
2020-09-11 16:13 utverdov Target Version 7.5.0 => 7.6.0*
2020-09-15 11:27 kgv Summary Foundation Classes - optionally include backtrace within dangerous exceptions like OSD_SIGSEGV => Foundation Classes - include backtrace within OSD_SIGSEGV on Linux
2020-09-15 11:54 git Note Added: 0094817
2020-09-15 12:05 git Note Added: 0094820
2020-09-15 15:12 kgv Note Added: 0094840
2020-09-15 15:12 kgv Status new => resolved
2020-09-15 15:12 kgv Target Version 7.6.0* => 7.5.0
2020-09-16 00:02 git Note Added: 0094892
2020-09-25 20:35 abv Target Version 7.5.0 => 7.6.0*
2020-10-05 08:50 abv Note Added: 0095711
2020-10-05 08:50 abv Assigned To abv => kgv
2020-10-05 08:50 abv Status resolved => assigned
2020-11-16 12:43 kgv Assigned To kgv => mzernova
2020-12-01 18:36 git Note Added: 0097222
2020-12-01 18:37 mzernova Assigned To mzernova => kgv
2020-12-01 18:37 mzernova Status assigned => feedback
2020-12-01 23:18 kgv Note Added: 0097227
2020-12-01 23:20 kgv Assigned To kgv => mzernova
2020-12-01 23:20 kgv Status feedback => assigned
2020-12-02 15:13 git Note Added: 0097241
2020-12-02 15:13 git Note Added: 0097242
2020-12-02 15:15 mzernova Assigned To mzernova => kgv
2020-12-02 15:15 mzernova Status assigned => resolved
2020-12-02 15:15 mzernova Steps to Reproduce Updated View Revisions
2020-12-02 15:42 kgv Note Added: 0097247
2020-12-02 15:42 kgv Assigned To kgv => mzernova
2020-12-02 15:42 kgv Status resolved => assigned
2020-12-03 12:33 git Note Added: 0097264
2020-12-03 12:33 git Note Added: 0097265
2020-12-03 12:51 git Note Added: 0097266
2020-12-03 12:51 git Note Added: 0097267
2020-12-03 13:39 mzernova Assigned To mzernova => kgv
2020-12-03 13:39 mzernova Status assigned => resolved
2020-12-03 14:32 mzernova Assigned To kgv => mzernova
2020-12-03 14:32 mzernova Status resolved => assigned


Copyright © 2000 - 2020 MantisBT Team
Powered by Mantis Bugtracker