[haiku-commits] haiku: hrev51260 - src/system/libroot/os/arch/ppc

  • From: kallisti5@xxxxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Wed, 5 Jul 2017 02:28:55 +0200 (CEST)

hrev51260 adds 1 changeset to branch 'master'
old head: 021ffa56b94d223787d96a90dab4eb3416cbfa8e
new head: 144e404b2d4053f010397e43fcc99b35042e641a
overview: 
http://cgit.haiku-os.org/haiku/log/?qt=range&q=144e404b2d40+%5E021ffa56b94d

----------------------------------------------------------------------------

144e404b2d40: libroot/ppc: Add missing stack_trace

                          [ Alexander von Gluck IV <kallisti5@xxxxxxxxxxx> ]

----------------------------------------------------------------------------

Revision:    hrev51260
Commit:      144e404b2d4053f010397e43fcc99b35042e641a
URL:         http://cgit.haiku-os.org/haiku/commit/?id=144e404b2d40
Author:      Alexander von Gluck IV <kallisti5@xxxxxxxxxxx>
Date:        Wed Jul  5 00:28:13 2017 UTC

----------------------------------------------------------------------------

2 files changed, 48 insertions(+)
src/system/libroot/os/arch/ppc/Jamfile         |  1 +
src/system/libroot/os/arch/ppc/stack_trace.cpp | 47 ++++++++++++++++++++++

----------------------------------------------------------------------------

diff --git a/src/system/libroot/os/arch/ppc/Jamfile 
b/src/system/libroot/os/arch/ppc/Jamfile
index 6daef94..cdbf572 100644
--- a/src/system/libroot/os/arch/ppc/Jamfile
+++ b/src/system/libroot/os/arch/ppc/Jamfile
@@ -17,6 +17,7 @@ for architectureObject in [ MultiArchSubDirSetup ppc ] {
                        byteorder.S
                        compatibility.c # only here until the places where 
those functions
                                                        # are used are fixed
+                       stack_trace.cpp
                        stack_frame.c
 #                      systeminfo.c
                        system_time.c
diff --git a/src/system/libroot/os/arch/ppc/stack_trace.cpp 
b/src/system/libroot/os/arch/ppc/stack_trace.cpp
new file mode 100644
index 0000000..48b82ae
--- /dev/null
+++ b/src/system/libroot/os/arch/ppc/stack_trace.cpp
@@ -0,0 +1,47 @@
+/*
+ * Copyright 2015 Haiku, Inc. All rights reserved.
+ * Distributed under the terms of the MIT License.
+ *
+ * Authors:
+ *             Michael Lotz, mmlr@xxxxxxxx
+ */
+
+#include <libroot_private.h>
+
+
+/*!    Captures a stack trace (the return addresses) of the current thread.
+       \param returnAddresses The array the return address shall be written to.
+       \param maxCount The maximum number of return addresses to be captured.
+       \param skipFrames The number of stack frames that shall be skipped.
+       \param stackBase The base address of the thread stack.
+       \param stackEnd The first address past the thread stack.
+       \return The number of return addresses written to the given array.
+*/
+int32
+__arch_get_stack_trace(addr_t* returnAddresses, int32 maxCount,
+       int32 skipFrames, addr_t stackBase, addr_t stackEnd)
+{
+       int32 count = 0;
+       addr_t basePointer = (addr_t)get_stack_frame();
+
+       while (basePointer != 0 && count < maxCount) {
+               if (basePointer < stackBase || basePointer >= stackEnd)
+                       break;
+
+               struct stack_frame {
+                       addr_t  previous;
+                       addr_t  return_address;
+               };
+
+               stack_frame* frame = (stack_frame*)basePointer;
+
+               if (skipFrames <= 0)
+                       returnAddresses[count++] = frame->return_address;
+               else
+                       skipFrames--;
+
+               basePointer = frame->previous;
+       }
+
+       return count;
+}


Other related posts:

  • » [haiku-commits] haiku: hrev51260 - src/system/libroot/os/arch/ppc - kallisti5