Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Aug 27, 2025. It is now read-only.

well-tested compiler flags essential to gain useful backtrace(3) result#518

Open
RushOnline wants to merge 1 commit into
raspberrypi:masterfrom
RushOnline:fix-backtrace
Open

well-tested compiler flags essential to gain useful backtrace(3) result#518
RushOnline wants to merge 1 commit into
raspberrypi:masterfrom
RushOnline:fix-backtrace

Conversation

@RushOnline

Copy link
Copy Markdown

without this patch call to backtrace(3) returns zero.

Tested on RPiZ without analog/digital gain control support in ThreadX API:

Output of modified raspistill -o /dev/null -awb off -awbg 1.56,1.78 -ex off -ag 1 -dg 1 -t 1 -v before and after patch:

-Obtained 0 stack frames.
+Obtained 7 stack frames.
+./raspistill(print_trace+0x1c) [0x11bcc]
+./raspistill(mmal_status_to_int+0x30) [0x12184]
+./raspistill(raspicamcontrol_set_gains+0x88) [0x1048c]
+./raspistill(raspicamcontrol_set_all_parameters+0x39c) [0xeef8]
+./raspistill() [0x1561c]
+./raspistill(main+0x228) [0x1798c]
+/lib/arm-linux-gnueabihf/libc.so.6(__libc_start_main+0x114) [0xb6c18678]
mmal: Function not implemented

raspistill modification (just for test, not included in this pull request):

diff --git a/host_applications/linux/apps/raspicam/RaspiHelpers.c b/host_applications/linux/apps/raspicam/RaspiHelpers.c
index 5c25e18..86e113e 100644
--- a/host_applications/linux/apps/raspicam/RaspiHelpers.c
+++ b/host_applications/linux/apps/raspicam/RaspiHelpers.c
@@ -33,6 +33,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 #include <unistd.h>
 #include <stdint.h>
 
+#include <execinfo.h>
 
 #include "interface/vcos/vcos.h"
 #include "interface/mmal/mmal.h"
@@ -58,6 +59,25 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 static const char *app_name;
 
+/* Obtain a backtrace and print it to stdout. */
+void print_trace (void)
+{
+  void *array[10];
+  size_t size;
+  char **strings;
+  size_t i;
+
+  size = backtrace (array, 10);
+  strings = backtrace_symbols (array, size);
+
+  printf ("Obtained %zd stack frames.\n", size);
+
+  for (i = 0; i < size; i++)
+     printf ("%s\n", strings[i]);
+
+  free (strings);
+}
+
 void print_app_details(FILE *fd)
 {
    if (!app_name)
@@ -225,6 +245,7 @@ int mmal_status_to_int(MMAL_STATUS_T status)
       return 0;
    else
    {
+         print_trace();
       switch (status)
       {
       case MMAL_ENOMEM :

@popcornmix

Copy link
Copy Markdown
Contributor

No real objections to this. @6by9 @pelwell ?

@pelwell

pelwell commented Dec 20, 2018

Copy link
Copy Markdown
Contributor

Fine by me, provided there is little overhead.

@6by9

6by9 commented Dec 24, 2018

Copy link
Copy Markdown
Contributor

It's for debug builds only, so I see little downside.
I don't know whether it needs all the debug options (-g3 vs -g), but other than library/exe size it won't do any harm, likewise -O0.

@luked99 luked99 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps "-Og" rather than "-O0" ?

And you don't need the -funwind-tables if you have debug information around somewhere (e.g. by adding "-g").

@RushOnline

Copy link
Copy Markdown
Author

And you don't need the -funwind-tables if you have debug information around somewhere (e.g. by adding "-g").

backtrace(3) without -funwind-tables returns zero for me.

@Ruffio

Ruffio commented May 3, 2020

Copy link
Copy Markdown

@RushOnline has this been resolved?

@RushOnline

Copy link
Copy Markdown
Author

@Ruffio I don't test it since I've posted this MR. May be fresh software don't have this bug.

@Ruffio

Ruffio commented May 3, 2020

Copy link
Copy Markdown

It would be nice to get this closed, if the bug doesn't persists with fresh software

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants