DEBUG_BACKTRACE from MEM_guarded_alloc cannot resolve functions anymore in linux builds. #110971

Closed
opened 2023-08-09 17:51:14 +02:00 by Bastien Montagne · 1 comment

System Information
Operating system: Linux (gcc 13)
Graphics card: NA

Blender Version
Broken: current master
Worked: ?

Short description of error

After enabling DEBUG_BACKTRACE in mallocn_guarded_impl.c, the produced bactrace is essentially useless, since the call to backtrace_symbols in print_memhead_backtrace cannot resolve any of the return addresses in Blender code.

Exact steps for others to reproduce the error

  1. Apply this trivial patch (enables the backtrace feature and generates a dummy memleak):
diff --git a/intern/guardedalloc/intern/mallocn_guarded_impl.c b/intern/guardedalloc/intern/mallocn_guarded_impl.c
index 35fe07e22a7..6d856b4d0e4 100644
--- a/intern/guardedalloc/intern/mallocn_guarded_impl.c
+++ b/intern/guardedalloc/intern/mallocn_guarded_impl.c
@@ -44,7 +44,7 @@
* memory block was allocated and print this trace for all
* unfreed blocks.
*/
-//#define DEBUG_BACKTRACE
+#define DEBUG_BACKTRACE
 
#ifdef DEBUG_BACKTRACE
#  define BACKTRACE_SIZE 100
diff --git a/source/blender/windowmanager/intern/wm_init_exit.cc b/source/blender/windowmanager/intern/wm_init_exit.cc
index 9b0641ceeb1..7d88e2b8f37 100644
--- a/source/blender/windowmanager/intern/wm_init_exit.cc
+++ b/source/blender/windowmanager/intern/wm_init_exit.cc
@@ -220,6 +220,8 @@ void WM_init(bContext *C, int argc, const char **argv)
   BKE_sound_jack_sync_callback_set(sound_jack_sync_callback);
 }
 
+  MEM_mallocN(1024, __func__);
+
 GHOST_CreateSystemPaths();
 
 BKE_addon_pref_type_init();
  1. Run Blender from the console, with --debug-memory option.

Result will be something like that in the console:

Error: Not freed memory blocks: 1, total unfreed memory 0.000977 MB
WM_init len: 1024 0x61c0000133e0
  /lib/x86_64-linux-gnu/libasan.so.8(+0x68e81) [0x7ff162c68e81]
  /home/guest/blender/build_main_debug/bin/blender() [0x136d4dfa]
  /home/guest/blender/build_main_debug/bin/blender() [0x136d5440]
  /home/guest/blender/build_main_debug/bin/blender() [0x136d583e]
  /home/guest/blender/build_main_debug/bin/blender() [0x137a242c]
  /home/guest/blender/build_main_debug/bin/blender() [0xef8a7b6]
  /lib/x86_64-linux-gnu/libc.so.6(+0x276ca) [0x7ff1500456ca]
  /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0x85) [0x7ff150045785]
  /home/guest/blender/build_main_debug/bin/blender() [0xef89aa1]

Note that GDB does have access to the function names:

1 MEM_guarded_mallocN mallocn_guarded_impl.c 440 0x136d57ed 
2 WM_init             wm_init_exit.cc        223 0x137a242c 
3 main                creator.cc             537 0xef8a7b6  
**System Information** Operating system: Linux (gcc 13) Graphics card: NA **Blender Version** Broken: current master Worked: ? **Short description of error** After enabling `DEBUG_BACKTRACE` in `mallocn_guarded_impl.c`, the produced bactrace is essentially useless, since the call to `backtrace_symbols` in `print_memhead_backtrace` cannot resolve any of the return addresses in Blender code. **Exact steps for others to reproduce the error** 1. Apply this trivial patch (enables the backtrace feature and generates a dummy memleak): ```Diff diff --git a/intern/guardedalloc/intern/mallocn_guarded_impl.c b/intern/guardedalloc/intern/mallocn_guarded_impl.c index 35fe07e22a7..6d856b4d0e4 100644 --- a/intern/guardedalloc/intern/mallocn_guarded_impl.c +++ b/intern/guardedalloc/intern/mallocn_guarded_impl.c @@ -44,7 +44,7 @@ * memory block was allocated and print this trace for all * unfreed blocks. */ -//#define DEBUG_BACKTRACE +#define DEBUG_BACKTRACE #ifdef DEBUG_BACKTRACE # define BACKTRACE_SIZE 100 diff --git a/source/blender/windowmanager/intern/wm_init_exit.cc b/source/blender/windowmanager/intern/wm_init_exit.cc index 9b0641ceeb1..7d88e2b8f37 100644 --- a/source/blender/windowmanager/intern/wm_init_exit.cc +++ b/source/blender/windowmanager/intern/wm_init_exit.cc @@ -220,6 +220,8 @@ void WM_init(bContext *C, int argc, const char **argv) BKE_sound_jack_sync_callback_set(sound_jack_sync_callback); } + MEM_mallocN(1024, __func__); + GHOST_CreateSystemPaths(); BKE_addon_pref_type_init(); ``` 2. Run Blender from the console, with `--debug-memory` option. Result will be something like that in the console: ``` Error: Not freed memory blocks: 1, total unfreed memory 0.000977 MB WM_init len: 1024 0x61c0000133e0 /lib/x86_64-linux-gnu/libasan.so.8(+0x68e81) [0x7ff162c68e81] /home/guest/blender/build_main_debug/bin/blender() [0x136d4dfa] /home/guest/blender/build_main_debug/bin/blender() [0x136d5440] /home/guest/blender/build_main_debug/bin/blender() [0x136d583e] /home/guest/blender/build_main_debug/bin/blender() [0x137a242c] /home/guest/blender/build_main_debug/bin/blender() [0xef8a7b6] /lib/x86_64-linux-gnu/libc.so.6(+0x276ca) [0x7ff1500456ca] /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0x85) [0x7ff150045785] /home/guest/blender/build_main_debug/bin/blender() [0xef89aa1] ``` Note that GDB does have access to the function names: ``` 1 MEM_guarded_mallocN mallocn_guarded_impl.c 440 0x136d57ed 2 WM_init wm_init_exit.cc 223 0x137a242c 3 main creator.cc 537 0xef8a7b6 ```
Bastien Montagne added the
Type
Report
Priority
Normal
Status
Needs Triage
labels 2023-08-09 17:51:14 +02:00
Author
Owner

Note from an afternoon of investigations:

  • Could this be a GCC issue? I have the feeling I used this feature successfully a few months ago, however could not get it to work even in 4000 old commit on main.
  • Explored the web quite extensively, this post is the most interesting I found so far.
    ** Adding options like -rdynamic or -export-dynamic to the linker or compiler flags did not change anything.
    ** Explicitly enabling CMAKE_EXECUTABLE_ENABLE_EXPORTS did not help either.
    ** Explicitly building debug builds with -O0 flag did not solve it either.

Wondering whether we should not rather try to port guardedalloc to C++, and then try to use boost::stacktrace e.g. instead?

Note from an afternoon of investigations: * Could this be a GCC issue? I have the feeling I used this feature successfully a few months ago, however could not get it to work even in 4000 old commit on main. * Explored the web quite extensively, [this post](https://stackoverflow.com/questions/3899870/print-call-stack-in-c-or-c/69384663#69384663) is the most interesting I found so far. ** Adding options like `-rdynamic` or `-export-dynamic` to the linker or compiler flags did not change anything. ** Explicitly enabling [`CMAKE_EXECUTABLE_ENABLE_EXPORTS`](https://cmake.org/cmake/help/latest/variable/CMAKE_EXECUTABLE_ENABLE_EXPORTS.html#variable:CMAKE_EXECUTABLE_ENABLE_EXPORTS) did not help either. ** Explicitly building debug builds with `-O0` flag did not solve it either. ---------------- Wondering whether we should not rather try to port guardedalloc to C++, and then try to use boost::stacktrace e.g. instead?
Blender Bot added
Status
Resolved
and removed
Status
Confirmed
labels 2023-08-10 17:55:06 +02:00
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#110971
No description provided.